Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

219 lines
5.4 KiB

  1. /*++
  2. Copyright (c) 1995 Microsoft Corporation
  3. Module Name:
  4. spt.h
  5. Abstract:
  6. SCSI_PASS_THROUGH header for user-mode apps
  7. Environment:
  8. User mode only
  9. Revision History:
  10. 4/10/2000 - created
  11. --*/
  12. #ifndef __SPTLIB_H__
  13. #define __SPTLIB_H__
  14. #pragma warning(push)
  15. #pragma warning(disable:4200) // array[0] is not a warning for this file
  16. #include <windows.h> // sdk
  17. #include <devioctl.h> // sdk
  18. #include <ntddscsi.h> // sdk
  19. #define _NTSRB_ // allow user-mode scsi.h
  20. #include <scsi.h> // ddk
  21. #undef _NTSRB_
  22. #define SPT_DEFAULT_TIMEOUT 60 // one minute timeout is default
  23. #define SPT_MODE_SENSE_TIMEOUT 10 // more than this is not likely
  24. typedef enum _SPT_MODE_PAGE_TYPE {
  25. SptModePageTypeCurrent = 0x00,
  26. SptModePageTypeChangable = 0x40,
  27. SptModePageTypeDefault = 0x80,
  28. SptModePageTypeSaved = 0xc0
  29. } SPT_MODE_PAGE_TYPE, *PSPT_MODE_PAGE_TYPE;
  30. //
  31. // this simplified and speeds processing of MODE_SENSE
  32. // and MODE_SELECT commands
  33. //
  34. struct _SPT_MODE_PAGE_INFO;
  35. typedef struct _SPT_MODE_PAGE_INFO
  36. SPT_MODE_PAGE_INFO,
  37. *PSPT_MODE_PAGE_INFO;
  38. #define SPT_NOT_READY_RETRY_INTERVAL 100 // 10 seconds
  39. #define MAXIMUM_DEFAULT_RETRIES 5 // 5 retries
  40. /*++
  41. Routine Description:
  42. Validates the CDB length matches the opcode's command group.
  43. Arguments:
  44. Return Value:
  45. TRUE if size is correct or cannot be verified.
  46. FALSE if size is mismatched.
  47. --*/
  48. BOOL
  49. SptUtilValidateCdbLength(
  50. IN PCDB Cdb,
  51. IN UCHAR CdbSize
  52. );
  53. /*++
  54. Routine Description:
  55. Simplistic way to send a command to a device.
  56. Arguments:
  57. DeviceHandle - handle to device to send command to
  58. Cdb - command to send to the device
  59. CdbSize - size of the cdb
  60. Buffer - Buffer to send to/get from the device
  61. BufferSize - Size of available buffer on input.
  62. Size of returned data when routine completes
  63. iff GetDataFromDevice is TRUE
  64. GetDataFromDevice - TRUE if getting data from device
  65. FALSE if sending data to the device
  66. Return Value:
  67. TRUE if the command completed successfully
  68. --*/
  69. BOOL
  70. SptSendCdbToDevice(
  71. IN HANDLE DeviceHandle,
  72. IN PCDB Cdb,
  73. IN UCHAR CdbSize,
  74. IN PUCHAR Buffer,
  75. IN OUT PDWORD BufferSize,
  76. IN BOOLEAN GetDataFromDevice
  77. );
  78. /*++
  79. Routine Description:
  80. Arguments:
  81. DeviceHandle - handle to device to send command to
  82. Cdb - command to send to the device
  83. CdbSize - size of the cdb
  84. Buffer - Buffer to send to/get from the device
  85. BufferSize - Size of available buffer on input.
  86. Size of returned data when routine completes
  87. iff GetDataFromDevice is TRUE
  88. SenseData - Optional buffer to store sense data on errors.
  89. Must be NULL if SenseDataSize is zero.
  90. Must be non-NULL if SenseDataSize is non-zero.
  91. SenseDataSize - Size of sense data to return to host.
  92. Must be zero if SenseData is NULL.
  93. Must be non-zero if SenseData is non-NULL.
  94. GetDataFromDevice - TRUE if getting data from device
  95. FALSE if sending data to the device
  96. TimeOut - Number of seconds before the command should timeout
  97. Return Value:
  98. TRUE if the command completed successfully.
  99. FALSE if the command encountered an error
  100. Data will also be transferred (check *BufferSize) if there is sense
  101. data, but validity is not guaranteed.
  102. SenseData may be valid, and may report ERROR_SUCCESS, meaning that
  103. the resulting data is valid. (call SptUtilInterpretSenseInfo)
  104. --*/
  105. BOOL
  106. SptSendCdbToDeviceEx(
  107. IN HANDLE DeviceHandle,
  108. IN PCDB Cdb,
  109. IN UCHAR CdbSize,
  110. IN OUT PUCHAR Buffer,
  111. IN OUT PDWORD BufferSize,
  112. OUT PSENSE_DATA SenseData, // if non-null, size must be non-zero
  113. IN UCHAR SenseDataSize,
  114. IN BOOLEAN GetDataFromDevice, // true = receive data
  115. IN DWORD TimeOut // in seconds
  116. );
  117. /*++
  118. Routine Description:
  119. This is a user-mode translation of ClassInterpretSenseInfo()
  120. from classpnp.sys. The ErrorValue is deduced based upon the
  121. sense data, as well as whether the command should be retried or
  122. not (and in approximately how long).
  123. NOTE: we default to RETRY==TRUE except for known error classes
  124. Arguments:
  125. SenseData - pointer to the sense data
  126. SenseDataSize - size of sense data
  127. ErrorValue - pointer to location to store resulting error value.
  128. NOTE: may return ERROR_SUCCESS
  129. SuggestedRetry - pointer to location to store if the command should
  130. be retried. it is the responsibility of the caller to limit the
  131. number of retries.
  132. SuggestedRetryDelay - pointer to location to store how long the caller
  133. should delay (in 1/10 second increments) before retrying the command
  134. if SuggestedRetry ends up being set to TRUE.
  135. Return Value:
  136. None
  137. --*/
  138. VOID
  139. SptUtilInterpretSenseInfo(
  140. IN PSENSE_DATA SenseData,
  141. IN UCHAR SenseDataSize,
  142. OUT PDWORD ErrorValue, // from WinError.h
  143. OUT PBOOLEAN SuggestRetry OPTIONAL,
  144. OUT PDWORD SuggestRetryDelay OPTIONAL
  145. );
  146. #pragma warning(pop)
  147. #endif // __SPTLIB_H__