Keyboard firmwares for Atmel AVR and Cortex-M
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.

MassStorageClassCommon.h 15KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368
  1. /*
  2. LUFA Library
  3. Copyright (C) Dean Camera, 2014.
  4. dean [at] fourwalledcubicle [dot] com
  5. www.lufa-lib.org
  6. */
  7. /*
  8. Copyright 2014 Dean Camera (dean [at] fourwalledcubicle [dot] com)
  9. Permission to use, copy, modify, distribute, and sell this
  10. software and its documentation for any purpose is hereby granted
  11. without fee, provided that the above copyright notice appear in
  12. all copies and that both that the copyright notice and this
  13. permission notice and warranty disclaimer appear in supporting
  14. documentation, and that the name of the author not be used in
  15. advertising or publicity pertaining to distribution of the
  16. software without specific, written prior permission.
  17. The author disclaims all warranties with regard to this
  18. software, including all implied warranties of merchantability
  19. and fitness. In no event shall the author be liable for any
  20. special, indirect or consequential damages or any damages
  21. whatsoever resulting from loss of use, data or profits, whether
  22. in an action of contract, negligence or other tortious action,
  23. arising out of or in connection with the use or performance of
  24. this software.
  25. */
  26. /** \file
  27. * \brief Common definitions and declarations for the library USB Mass Storage Class driver.
  28. *
  29. * Common definitions and declarations for the library USB Mass Storage Class driver.
  30. *
  31. * \note This file should not be included directly. It is automatically included as needed by the USB module driver
  32. * dispatch header located in LUFA/Drivers/USB.h.
  33. */
  34. /** \ingroup Group_USBClassMS
  35. * \defgroup Group_USBClassMSCommon Common Class Definitions
  36. *
  37. * \section Sec_USBClassMSCommon_ModDescription Module Description
  38. * Constants, Types and Enum definitions that are common to both Device and Host modes for the USB
  39. * Mass Storage Class.
  40. *
  41. * @{
  42. */
  43. #ifndef _MS_CLASS_COMMON_H_
  44. #define _MS_CLASS_COMMON_H_
  45. /* Includes: */
  46. #include "../../Core/StdDescriptors.h"
  47. /* Enable C linkage for C++ Compilers: */
  48. #if defined(__cplusplus)
  49. extern "C" {
  50. #endif
  51. /* Preprocessor Checks: */
  52. #if !defined(__INCLUDE_FROM_MS_DRIVER)
  53. #error Do not include this file directly. Include LUFA/Drivers/USB.h instead.
  54. #endif
  55. /* Macros: */
  56. /** Magic signature for a Command Block Wrapper used in the Mass Storage Bulk-Only transport protocol. */
  57. #define MS_CBW_SIGNATURE 0x43425355UL
  58. /** Magic signature for a Command Status Wrapper used in the Mass Storage Bulk-Only transport protocol. */
  59. #define MS_CSW_SIGNATURE 0x53425355UL
  60. /** Mask for a Command Block Wrapper's flags attribute to specify a command with data sent from host-to-device. */
  61. #define MS_COMMAND_DIR_DATA_OUT (0 << 7)
  62. /** Mask for a Command Block Wrapper's flags attribute to specify a command with data sent from device-to-host. */
  63. #define MS_COMMAND_DIR_DATA_IN (1 << 7)
  64. /** \name SCSI Commands*/
  65. //@{
  66. /** SCSI Command Code for an INQUIRY command. */
  67. #define SCSI_CMD_INQUIRY 0x12
  68. /** SCSI Command Code for a REQUEST SENSE command. */
  69. #define SCSI_CMD_REQUEST_SENSE 0x03
  70. /** SCSI Command Code for a TEST UNIT READY command. */
  71. #define SCSI_CMD_TEST_UNIT_READY 0x00
  72. /** SCSI Command Code for a READ CAPACITY (10) command. */
  73. #define SCSI_CMD_READ_CAPACITY_10 0x25
  74. /** SCSI Command Code for a START STOP UNIT command. */
  75. #define SCSI_CMD_START_STOP_UNIT 0x1B
  76. /** SCSI Command Code for a SEND DIAGNOSTIC command. */
  77. #define SCSI_CMD_SEND_DIAGNOSTIC 0x1D
  78. /** SCSI Command Code for a PREVENT ALLOW MEDIUM REMOVAL command. */
  79. #define SCSI_CMD_PREVENT_ALLOW_MEDIUM_REMOVAL 0x1E
  80. /** SCSI Command Code for a WRITE (10) command. */
  81. #define SCSI_CMD_WRITE_10 0x2A
  82. /** SCSI Command Code for a READ (10) command. */
  83. #define SCSI_CMD_READ_10 0x28
  84. /** SCSI Command Code for a WRITE (6) command. */
  85. #define SCSI_CMD_WRITE_6 0x0A
  86. /** SCSI Command Code for a READ (6) command. */
  87. #define SCSI_CMD_READ_6 0x08
  88. /** SCSI Command Code for a VERIFY (10) command. */
  89. #define SCSI_CMD_VERIFY_10 0x2F
  90. /** SCSI Command Code for a MODE SENSE (6) command. */
  91. #define SCSI_CMD_MODE_SENSE_6 0x1A
  92. /** SCSI Command Code for a MODE SENSE (10) command. */
  93. #define SCSI_CMD_MODE_SENSE_10 0x5A
  94. //@}
  95. /** \name SCSI Sense Key Values */
  96. //@{
  97. /** SCSI Sense Code to indicate no error has occurred. */
  98. #define SCSI_SENSE_KEY_GOOD 0x00
  99. /** SCSI Sense Code to indicate that the device has recovered from an error. */
  100. #define SCSI_SENSE_KEY_RECOVERED_ERROR 0x01
  101. /** SCSI Sense Code to indicate that the device is not ready for a new command. */
  102. #define SCSI_SENSE_KEY_NOT_READY 0x02
  103. /** SCSI Sense Code to indicate an error whilst accessing the medium. */
  104. #define SCSI_SENSE_KEY_MEDIUM_ERROR 0x03
  105. /** SCSI Sense Code to indicate a hardware error has occurred. */
  106. #define SCSI_SENSE_KEY_HARDWARE_ERROR 0x04
  107. /** SCSI Sense Code to indicate that an illegal request has been issued. */
  108. #define SCSI_SENSE_KEY_ILLEGAL_REQUEST 0x05
  109. /** SCSI Sense Code to indicate that the unit requires attention from the host to indicate
  110. * a reset event, medium removal or other condition.
  111. */
  112. #define SCSI_SENSE_KEY_UNIT_ATTENTION 0x06
  113. /** SCSI Sense Code to indicate that a write attempt on a protected block has been made. */
  114. #define SCSI_SENSE_KEY_DATA_PROTECT 0x07
  115. /** SCSI Sense Code to indicate an error while trying to write to a write-once medium. */
  116. #define SCSI_SENSE_KEY_BLANK_CHECK 0x08
  117. /** SCSI Sense Code to indicate a vendor specific error has occurred. */
  118. #define SCSI_SENSE_KEY_VENDOR_SPECIFIC 0x09
  119. /** SCSI Sense Code to indicate that an EXTENDED COPY command has aborted due to an error. */
  120. #define SCSI_SENSE_KEY_COPY_ABORTED 0x0A
  121. /** SCSI Sense Code to indicate that the device has aborted the issued command. */
  122. #define SCSI_SENSE_KEY_ABORTED_COMMAND 0x0B
  123. /** SCSI Sense Code to indicate an attempt to write past the end of a partition has been made. */
  124. #define SCSI_SENSE_KEY_VOLUME_OVERFLOW 0x0D
  125. /** SCSI Sense Code to indicate that the source data did not match the data read from the medium. */
  126. #define SCSI_SENSE_KEY_MISCOMPARE 0x0E
  127. //@}
  128. /** \name SCSI Additional Sense Codes */
  129. //@{
  130. /** SCSI Additional Sense Code to indicate no additional sense information is available. */
  131. #define SCSI_ASENSE_NO_ADDITIONAL_INFORMATION 0x00
  132. /** SCSI Additional Sense Code to indicate that the logical unit (LUN) addressed is not ready. */
  133. #define SCSI_ASENSE_LOGICAL_UNIT_NOT_READY 0x04
  134. /** SCSI Additional Sense Code to indicate an invalid field was encountered while processing the issued command. */
  135. #define SCSI_ASENSE_INVALID_FIELD_IN_CDB 0x24
  136. /** SCSI Additional Sense Code to indicate that a medium that was previously indicated as not ready has now
  137. * become ready for use.
  138. */
  139. #define SCSI_ASENSE_NOT_READY_TO_READY_CHANGE 0x28
  140. /** SCSI Additional Sense Code to indicate that an attempt to write to a protected area was made. */
  141. #define SCSI_ASENSE_WRITE_PROTECTED 0x27
  142. /** SCSI Additional Sense Code to indicate an error whilst formatting the device medium. */
  143. #define SCSI_ASENSE_FORMAT_ERROR 0x31
  144. /** SCSI Additional Sense Code to indicate an invalid command was issued. */
  145. #define SCSI_ASENSE_INVALID_COMMAND 0x20
  146. /** SCSI Additional Sense Code to indicate a write to a block out outside of the medium's range was issued. */
  147. #define SCSI_ASENSE_LOGICAL_BLOCK_ADDRESS_OUT_OF_RANGE 0x21
  148. /** SCSI Additional Sense Code to indicate that no removable medium is inserted into the device. */
  149. #define SCSI_ASENSE_MEDIUM_NOT_PRESENT 0x3A
  150. //@}
  151. /** \name SCSI Additional Sense Key Code Qualifiers */
  152. //@{
  153. /** SCSI Additional Sense Qualifier Code to indicate no additional sense qualifier information is available. */
  154. #define SCSI_ASENSEQ_NO_QUALIFIER 0x00
  155. /** SCSI Additional Sense Qualifier Code to indicate that a medium format command failed to complete. */
  156. #define SCSI_ASENSEQ_FORMAT_COMMAND_FAILED 0x01
  157. /** SCSI Additional Sense Qualifier Code to indicate that an initializing command must be issued before the issued
  158. * command can be executed.
  159. */
  160. #define SCSI_ASENSEQ_INITIALIZING_COMMAND_REQUIRED 0x02
  161. /** SCSI Additional Sense Qualifier Code to indicate that an operation is currently in progress. */
  162. #define SCSI_ASENSEQ_OPERATION_IN_PROGRESS 0x07
  163. //@}
  164. /* Enums: */
  165. /** Enum for possible Class, Subclass and Protocol values of device and interface descriptors relating to the Mass
  166. * Storage device class.
  167. */
  168. enum MS_Descriptor_ClassSubclassProtocol_t
  169. {
  170. MS_CSCP_MassStorageClass = 0x08, /**< Descriptor Class value indicating that the device or interface
  171. * belongs to the Mass Storage class.
  172. */
  173. MS_CSCP_SCSITransparentSubclass = 0x06, /**< Descriptor Subclass value indicating that the device or interface
  174. * belongs to the SCSI Transparent Command Set subclass of the Mass
  175. * storage class.
  176. */
  177. MS_CSCP_BulkOnlyTransportProtocol = 0x50, /**< Descriptor Protocol value indicating that the device or interface
  178. * belongs to the Bulk Only Transport protocol of the Mass Storage class.
  179. */
  180. };
  181. /** Enum for the Mass Storage class specific control requests that can be issued by the USB bus host. */
  182. enum MS_ClassRequests_t
  183. {
  184. MS_REQ_GetMaxLUN = 0xFE, /**< Mass Storage class-specific request to retrieve the total number of Logical
  185. * Units (drives) in the SCSI device.
  186. */
  187. MS_REQ_MassStorageReset = 0xFF, /**< Mass Storage class-specific request to reset the Mass Storage interface,
  188. * ready for the next command.
  189. */
  190. };
  191. /** Enum for the possible command status wrapper return status codes. */
  192. enum MS_CommandStatusCodes_t
  193. {
  194. MS_SCSI_COMMAND_Pass = 0, /**< Command completed with no error */
  195. MS_SCSI_COMMAND_Fail = 1, /**< Command failed to complete - host may check the exact error via a
  196. * SCSI REQUEST SENSE command.
  197. */
  198. MS_SCSI_COMMAND_PhaseError = 2, /**< Command failed due to being invalid in the current phase. */
  199. };
  200. /* Type Defines: */
  201. /** \brief Mass Storage Class Command Block Wrapper.
  202. *
  203. * Type define for a Command Block Wrapper, used in the Mass Storage Bulk-Only Transport protocol.
  204. *
  205. * \note Regardless of CPU architecture, these values should be stored as little endian.
  206. */
  207. typedef struct
  208. {
  209. uint32_t Signature; /**< Command block signature, must be \ref MS_CBW_SIGNATURE to indicate a valid Command Block. */
  210. uint32_t Tag; /**< Unique command ID value, to associate a command block wrapper with its command status wrapper. */
  211. uint32_t DataTransferLength; /**< Length of the optional data portion of the issued command, in bytes. */
  212. uint8_t Flags; /**< Command block flags, indicating command data direction. */
  213. uint8_t LUN; /**< Logical Unit number this command is issued to. */
  214. uint8_t SCSICommandLength; /**< Length of the issued SCSI command within the SCSI command data array. */
  215. uint8_t SCSICommandData[16]; /**< Issued SCSI command in the Command Block. */
  216. } ATTR_PACKED MS_CommandBlockWrapper_t;
  217. /** \brief Mass Storage Class Command Status Wrapper.
  218. *
  219. * Type define for a Command Status Wrapper, used in the Mass Storage Bulk-Only Transport protocol.
  220. *
  221. * \note Regardless of CPU architecture, these values should be stored as little endian.
  222. */
  223. typedef struct
  224. {
  225. uint32_t Signature; /**< Status block signature, must be \ref MS_CSW_SIGNATURE to indicate a valid Command Status. */
  226. uint32_t Tag; /**< Unique command ID value, to associate a command block wrapper with its command status wrapper. */
  227. uint32_t DataTransferResidue; /**< Number of bytes of data not processed in the SCSI command. */
  228. uint8_t Status; /**< Status code of the issued command - a value from the \ref MS_CommandStatusCodes_t enum. */
  229. } ATTR_PACKED MS_CommandStatusWrapper_t;
  230. /** \brief Mass Storage Class SCSI Sense Structure
  231. *
  232. * Type define for a SCSI Sense structure. Structures of this type are filled out by the
  233. * device via the \ref MS_Host_RequestSense() function, indicating the current sense data of the
  234. * device (giving explicit error codes for the last issued command). For details of the
  235. * structure contents, refer to the SCSI specifications.
  236. */
  237. typedef struct
  238. {
  239. uint8_t ResponseCode;
  240. uint8_t SegmentNumber;
  241. unsigned SenseKey : 4;
  242. unsigned Reserved : 1;
  243. unsigned ILI : 1;
  244. unsigned EOM : 1;
  245. unsigned FileMark : 1;
  246. uint8_t Information[4];
  247. uint8_t AdditionalLength;
  248. uint8_t CmdSpecificInformation[4];
  249. uint8_t AdditionalSenseCode;
  250. uint8_t AdditionalSenseQualifier;
  251. uint8_t FieldReplaceableUnitCode;
  252. uint8_t SenseKeySpecific[3];
  253. } ATTR_PACKED SCSI_Request_Sense_Response_t;
  254. /** \brief Mass Storage Class SCSI Inquiry Structure.
  255. *
  256. * Type define for a SCSI Inquiry structure. Structures of this type are filled out by the
  257. * device via the \ref MS_Host_GetInquiryData() function, retrieving the attached device's
  258. * information.
  259. *
  260. * For details of the structure contents, refer to the SCSI specifications.
  261. */
  262. typedef struct
  263. {
  264. unsigned DeviceType : 5;
  265. unsigned PeripheralQualifier : 3;
  266. unsigned Reserved : 7;
  267. unsigned Removable : 1;
  268. uint8_t Version;
  269. unsigned ResponseDataFormat : 4;
  270. unsigned Reserved2 : 1;
  271. unsigned NormACA : 1;
  272. unsigned TrmTsk : 1;
  273. unsigned AERC : 1;
  274. uint8_t AdditionalLength;
  275. uint8_t Reserved3[2];
  276. unsigned SoftReset : 1;
  277. unsigned CmdQue : 1;
  278. unsigned Reserved4 : 1;
  279. unsigned Linked : 1;
  280. unsigned Sync : 1;
  281. unsigned WideBus16Bit : 1;
  282. unsigned WideBus32Bit : 1;
  283. unsigned RelAddr : 1;
  284. uint8_t VendorID[8];
  285. uint8_t ProductID[16];
  286. uint8_t RevisionID[4];
  287. } ATTR_PACKED SCSI_Inquiry_Response_t;
  288. /* Disable C linkage for C++ Compilers: */
  289. #if defined(__cplusplus)
  290. }
  291. #endif
  292. #endif
  293. /** @} */