app_usbd_msc_scsi.h 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329
  1. /**
  2. * Copyright (c) 2016 - 2020, Nordic Semiconductor ASA
  3. *
  4. * All rights reserved.
  5. *
  6. * Redistribution and use in source and binary forms, with or without modification,
  7. * are permitted provided that the following conditions are met:
  8. *
  9. * 1. Redistributions of source code must retain the above copyright notice, this
  10. * list of conditions and the following disclaimer.
  11. *
  12. * 2. Redistributions in binary form, except as embedded into a Nordic
  13. * Semiconductor ASA integrated circuit in a product or a software update for
  14. * such product, must reproduce the above copyright notice, this list of
  15. * conditions and the following disclaimer in the documentation and/or other
  16. * materials provided with the distribution.
  17. *
  18. * 3. Neither the name of Nordic Semiconductor ASA nor the names of its
  19. * contributors may be used to endorse or promote products derived from this
  20. * software without specific prior written permission.
  21. *
  22. * 4. This software, with or without modification, must only be used with a
  23. * Nordic Semiconductor ASA integrated circuit.
  24. *
  25. * 5. Any software provided in binary form under this license must not be reverse
  26. * engineered, decompiled, modified and/or disassembled.
  27. *
  28. * THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS
  29. * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
  30. * OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE
  31. * DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE
  32. * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
  33. * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
  34. * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  35. * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  36. * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
  37. * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  38. *
  39. */
  40. #ifndef APP_USBD_MSC_SCSI_H__
  41. #define APP_USBD_MSC_SCSI_H__
  42. #include "app_util.h"
  43. #ifdef __cplusplus
  44. extern "C" {
  45. #endif
  46. /**
  47. * @defgroup app_usbd_msc_scsi USB MSC SCSI data structures
  48. * @ingroup app_usbd_msc
  49. *
  50. * @brief @tagAPI52840 USB MSC SCSI data structures.
  51. *
  52. * @details Reference specifications:
  53. * - "Reduced Block Commands (Revision 10a)" American National Standard
  54. * for Information Technology, August 18, 1999
  55. * - "SCSI Primary Commands - 4 (SPC-4)," American National Standard
  56. * for Information Technology, July 19, 2008
  57. * - "SCSI Block Commands -2 (SBC-2)," American National Standard
  58. * for Information Technology, November 13, 2004
  59. * - NuttX source code - Real-time Operating System: http://nuttx.org/
  60. * Gregory Nutt <gnutt@nuttx.org>
  61. *
  62. * @{
  63. */
  64. /**
  65. * @brief SCSI command set.
  66. *
  67. * Mandatory (and some optional) commands required by SBC-2.
  68. *
  69. */
  70. typedef enum {
  71. APP_USBD_SCSI_CMD_TESTUNITREADY = 0x00, /**< Test unit ready. */
  72. APP_USBD_SCSI_CMD_REQUESTSENSE = 0x03, /**< Request sense. */
  73. APP_USBD_SCSI_CMD_FORMAT_UNIT = 0x04, /**< Format unit. */
  74. APP_USBD_SCSI_CMD_READ6 = 0x08, /**< Read 6. */
  75. APP_USBD_SCSI_CMD_WRITE6 = 0x0A, /**< Write 6. */
  76. APP_USBD_SCSI_CMD_INQUIRY = 0x12, /**< Inquiry. */
  77. APP_USBD_SCSI_CMD_MODESELECT6 = 0x15, /**< Mode select 6. */
  78. APP_USBD_SCSI_CMD_MODESENSE6 = 0x1A, /**< Mode sense 6. */
  79. APP_USBD_SCSI_CMD_STARTSTOPUNIT = 0x1B, /**< Start/stop unit. */
  80. APP_USBD_SCSI_CMD_SENDDIAGNOSTIC = 0x1D, /**< Send diagnostic. */
  81. APP_USBD_SCSI_CMD_PREVENTMEDIAREMOVAL = 0x1E, /**< Prevent media removal. */
  82. APP_USBD_SCSI_CMD_READCAPACITY10 = 0x25, /**< Read capacity 10. */
  83. APP_USBD_SCSI_CMD_READ10 = 0x28, /**< Read 10. */
  84. APP_USBD_SCSI_CMD_WRITE10 = 0x2A, /**< Write 10. */
  85. APP_USBD_SCSI_CMD_MODESELECT10 = 0x55, /**< Mode select 10. */
  86. APP_USBD_SCSI_CMD_MODESENSE10 = 0x5A, /**< Mode sense 10. */
  87. } app_usbd_scsi_cmd_t;
  88. #pragma pack(push, 1)
  89. /**
  90. * @brief Payload of @ref APP_USBD_SCSI_CMD_REQUESTSENSE command.
  91. */
  92. typedef struct {
  93. uint8_t opcode; //!< @ref APP_USBD_SCSI_CMD_REQUESTSENSE
  94. uint8_t flags; //!< Flags
  95. uint8_t reserved[2]; //!< Reserved
  96. uint8_t alloclen; //!< Allocation length
  97. uint8_t control; //!< Control
  98. } app_usbd_scsi_cmd_requestsense_t;
  99. #define APP_USBD_SCSI_CMD_REQSENSE_CODE_VALID 0x80 /**< @ref app_usbd_scsi_cmd_requestsense_resp_t::code */
  100. #define APP_USBD_SCSI_CMD_REQSENSE_CODE_CURRENT 0x70 /**< @ref app_usbd_scsi_cmd_requestsense_resp_t::code */
  101. #define APP_USBD_SCSI_CMD_REQSENSE_CODE_DEFERRED 0x71 /**< @ref app_usbd_scsi_cmd_requestsense_resp_t::code */
  102. #define APP_USBD_SCSI_CMD_REQSENSE_CODE_CURRENTDESC 0x72 /**< @ref app_usbd_scsi_cmd_requestsense_resp_t::code */
  103. #define APP_USBD_SCSI_CMD_REQSENSE_CODE_DEFERREDDESC 0x73 /**< @ref app_usbd_scsi_cmd_requestsense_resp_t::code */
  104. #define APP_USBD_SCSI_CMD_REQSENSE_FLAG_FILEMARK 0x80 /**< Bits 7 @ref app_usbd_scsi_cmd_requestsense_resp_t::flags */
  105. #define APP_USBD_SCSI_CMD_REQSENSE_FLAG_EOM 0x40 /**< Bits 6 @ref app_usbd_scsi_cmd_requestsense_resp_t::flags */
  106. #define APP_USBD_SCSI_CMD_REQSENSE_FLAG_ILI 0x20 /**< Bits 5 @ref app_usbd_scsi_cmd_requestsense_resp_t::flags */
  107. #define APP_USBD_SCSI_CMD_REQSENSE_FLAG_RESERVED 0x10 /**< Bits 4 @ref app_usbd_scsi_cmd_requestsense_resp_t::flags */
  108. #define APP_USBD_SCSI_CMD_REQSENSE_FLAG_NOSENSE 0x00 /**< Bits 3...0 @ref app_usbd_scsi_cmd_requestsense_resp_t::flags */
  109. #define APP_USBD_SCSI_CMD_REQSENSE_FLAG_RECOVEREDERROR 0x01 /**< Bits 3...0 @ref app_usbd_scsi_cmd_requestsense_resp_t::flags */
  110. #define APP_USBD_SCSI_CMD_REQSENSE_FLAG_NOTREADY 0x02 /**< Bits 3...0 @ref app_usbd_scsi_cmd_requestsense_resp_t::flags */
  111. #define APP_USBD_SCSI_CMD_REQSENSE_FLAG_MEDIUMERROR 0x03 /**< Bits 3...0 @ref app_usbd_scsi_cmd_requestsense_resp_t::flags */
  112. #define APP_USBD_SCSI_CMD_REQSENSE_FLAG_HARDWAREERROR 0x04 /**< Bits 3...0 @ref app_usbd_scsi_cmd_requestsense_resp_t::flags */
  113. #define APP_USBD_SCSI_CMD_REQSENSE_FLAG_ILLEGALREQUEST 0x05 /**< Bits 3...0 @ref app_usbd_scsi_cmd_requestsense_resp_t::flags */
  114. #define APP_USBD_SCSI_CMD_REQSENSE_FLAG_UNITATTENTION 0x06 /**< Bits 3...0 @ref app_usbd_scsi_cmd_requestsense_resp_t::flags */
  115. #define APP_USBD_SCSI_CMD_REQSENSE_FLAG_DATAPROTECT 0x07 /**< Bits 3...0 @ref app_usbd_scsi_cmd_requestsense_resp_t::flags */
  116. #define APP_USBD_SCSI_CMD_REQSENSE_FLAG_BLANKCHECK 0x08 /**< Bits 3...0 @ref app_usbd_scsi_cmd_requestsense_resp_t::flags */
  117. #define APP_USBD_SCSI_CMD_REQSENSE_FLAG_VENDORSPECIFIC 0x09 /**< Bits 3...0 @ref app_usbd_scsi_cmd_requestsense_resp_t::flags */
  118. #define APP_USBD_SCSI_CMD_REQSENSE_FLAG_ABORTEDCOMMAND 0x0B /**< Bits 3...0 @ref app_usbd_scsi_cmd_requestsense_resp_t::flags */
  119. #define APP_USBD_SCSI_CMD_TESTUNITREADY_LEN 6 /**< @ref APP_USBD_SCSI_CMD_TESTUNITREADY command length*/
  120. /**
  121. * @brief Payload of @ref APP_USBD_SCSI_CMD_REQUESTSENSE response.
  122. */
  123. typedef struct {
  124. uint8_t code; //!< Response code: APP_USBD_SCSI_CMD_REQSENSE_CODE_*
  125. uint8_t obsolete; //!< Obsolete
  126. uint8_t flags; //!< APP_USBD_SCSI_CMD_REQSENSE_FLAG_*
  127. uint8_t info[4]; //!< Information
  128. uint8_t len; //!< Additional length
  129. uint8_t cmdinfo[4]; //!< Command-specific information
  130. uint8_t code2; //!< Additional sense code
  131. uint8_t qual2; //!< Additional sense code qualifier
  132. uint8_t fru; //!< Field replacement unit code
  133. uint8_t key[3]; //!< Sense key specific
  134. } app_usbd_scsi_cmd_requestsense_resp_t;
  135. /**
  136. * @brief Payload of @ref APP_USBD_SCSI_CMD_INQUIRY command.
  137. */
  138. typedef struct {
  139. uint8_t opcode; //!< @ref APP_USBD_SCSI_CMD_INQUIRY
  140. uint8_t flags; //!< Command flags
  141. uint8_t pagecode; //!< Page code
  142. uint8_t alloclen[2]; //!< Allocation length
  143. uint8_t control; //!< Control
  144. } app_usbd_scsi_cmd_inquiry_t;
  145. #define APP_USBD_MSC_SCSI_INQ_QUAL_CONNECTED 0x00 /**< Peripheral connected */
  146. #define APP_USBD_MSC_SCSI_INQ_QUAL_NOT_CONN 0x20 /**< Peripheral not connected */
  147. #define APP_USBD_MSC_SCSI_INQ_QUAL_NOT_SUPP 0x60 /**< Peripheral not supported */
  148. #define APP_USBD_MSC_SCSI_INQ_TYPE_DIR_ACCESS 0x00 /**< Direct Access (SBC) */
  149. #define APP_USBD_MSC_SCSI_INQ_TYPE_SEQ_ACCESS 0x01 /**< Sequential Access */
  150. #define APP_USBD_MSC_SCSI_INQ_TYPE_PRINTER 0x02 /**< Printer */
  151. #define APP_USBD_MSC_SCSI_INQ_TYPE_PROCESSOR 0x03 /**< Processor device */
  152. #define APP_USBD_MSC_SCSI_INQ_TYPE_WRITE_ONCE 0x04 /**< Write-once device */
  153. #define APP_USBD_MSC_SCSI_INQ_TYPE_CD_DVD 0x05 /**< CD/DVD device */
  154. #define APP_USBD_MSC_SCSI_INQ_TYPE_OPTICAL 0x07 /**< Optical Memory */
  155. #define APP_USBD_MSC_SCSI_INQ_TYPE_MC 0x08 /**< Medium Changer */
  156. #define APP_USBD_MSC_SCSI_INQ_TYPE_ARRAY 0x0C /**< Storage Array Controller */
  157. #define APP_USBD_MSC_SCSI_INQ_TYPE_ENCLOSURE 0x0D /**< Enclosure Services */
  158. #define APP_USBD_MSC_SCSI_INQ_TYPE_RBC 0x0E /**< Simplified Direct Access */
  159. #define APP_USBD_MSC_SCSI_INQ_TYPE_OCRW 0x0F /**< Optical card reader/writer */
  160. #define APP_USBD_MSC_SCSI_INQ_TYPE_BCC 0x10 /**< Bridge Controller Commands */
  161. #define APP_USBD_MSC_SCSI_INQ_TYPE_OSD 0x11 /**< Object-based Storage */
  162. #define APP_USBD_MSC_SCSI_INQ_TYPE_NONE 0x1F /**< No Peripheral */
  163. #define APP_USBD_MSC_SCSI_INQ_FLAG1_RMB 0x80 /**< Removable Medium */
  164. #define APP_USBD_SCSI_INQ_VER_NONE 0x00 /**< No standards conformance */
  165. #define APP_USBD_SCSI_INQ_VER_SPC 0x03 /**< SCSI Primary Commands (link to SBC) */
  166. #define APP_USBD_SCSI_INQ_VER_SPC2 0x04 /**< SCSI Primary Commands - 2 (link to SBC-2)*/
  167. #define APP_USBD_SCSI_INQ_VER_SPC3 0x05 /**< SCSI Primary Commands - 3 (link to SBC-2)*/
  168. #define APP_USBD_SCSI_INQ_VER_SPC4 0x06 /**< SCSI Primary Commands - 4 (link to SBC-3)*/
  169. #define APP_USBD_MSC_SCSI_INQ_FLAG2_NORMACA 0x20 /**< Normal ACA Supported */
  170. #define APP_USBD_MSC_SCSI_INQ_FLAG2_HISUP 0x10 /**< Hierarchal LUN addressing */
  171. #define APP_USBD_MSC_SCSI_INQ_FLAG2_RSP_SPC2 0x02 /**< SPC-2 / SPC-3 response format*/
  172. /**
  173. * @brief Payload of @ref APP_USBD_SCSI_CMD_INQUIRY response.
  174. */
  175. typedef struct {
  176. uint8_t qualtype; //!< Bits 5-7: Peripheral qualifier; Bits 0-4: Peripheral device type
  177. uint8_t flags1; //!< Flags 1
  178. uint8_t version; //!< Version
  179. uint8_t flags2; //!< Flags 2
  180. uint8_t len; //!< Additional length
  181. uint8_t flags3; //!< Flags 3
  182. uint8_t flags4; //!< Flags 4
  183. uint8_t flags5; //!< Flags 5
  184. uint8_t vendorid[8]; //!< T10 Vendor Identification
  185. uint8_t productid[16]; //!< Product Identification
  186. uint8_t revision[4]; //!< Product Revision Level
  187. } app_usbd_scsi_cmd_inquiry_resp_t;
  188. /**
  189. * @brief Payload of @ref APP_USBD_SCSI_CMD_READ6 command.
  190. */
  191. typedef struct {
  192. uint8_t opcode; //!< @ref APP_USBD_SCSI_CMD_READ6
  193. uint8_t mslba; //!< Bits 5-7: reserved; Bits 0-6: MS Logical Block Address (LBA)
  194. uint8_t lslba[2]; //!< LS Logical Block Address (LBA)
  195. uint8_t xfrlen; //!< Transfer length (in contiguous logical blocks)
  196. uint8_t control; //!< Control
  197. } app_usbd_scsi_cmd_read6_t;
  198. /**
  199. * @brief Payload of @ref APP_USBD_SCSI_CMD_WRITE6 command.
  200. */
  201. typedef struct {
  202. uint8_t opcode; //!< @ref APP_USBD_SCSI_CMD_WRITE6
  203. uint8_t mslba; //!< Bits 5-7: reserved; Bits 0-6: MS Logical Block Address (LBA)
  204. uint8_t lslba[2]; //!< LS Logical Block Address (LBA)
  205. uint8_t xfrlen; //!< Transfer length (in contiguous logical blocks)
  206. uint8_t control; //!< Control
  207. } app_usbd_scsi_cmd_write6_t;
  208. /**
  209. * @brief Payload of @ref APP_USBD_SCSI_CMD_MODESENSE6 command.
  210. */
  211. typedef struct {
  212. uint8_t opcode; //!<* @ref APP_USBD_SCSI_CMD_MODESENSE6
  213. uint8_t flags; //!<* Flags
  214. uint8_t pcpgcode; //!<* Bits 6-7: PC, bits 0-5: page code
  215. uint8_t subpgcode; //!<* subpage code
  216. uint8_t alloclen; //!<* Allocation length
  217. uint8_t control; //!<* Control
  218. } app_usbd_scsi_cmd_modesense6_t;
  219. /**
  220. * @brief Payload of @ref APP_USBD_SCSI_CMD_MODESENSE6 response.
  221. */
  222. typedef struct {
  223. uint8_t mdlen; //!< Mode data length
  224. uint8_t type; //!< Medium type
  225. uint8_t param; //!< Device-specific parameter
  226. uint8_t bdlen; //!< Block descriptor length
  227. } app_usbd_scsi_cmd_modesense6_resp_t;
  228. /**
  229. * @brief Payload of @ref APP_USBD_SCSI_CMD_READCAPACITY10 command.
  230. */
  231. typedef struct {
  232. uint8_t opcode; //!< @ref APP_USBD_SCSI_CMD_READCAPACITY10
  233. uint8_t reserved1; //!< Reserved field
  234. uint8_t lba[4]; //!< Logical block address (LBA)
  235. uint8_t reserved2[2]; //!< Reserved field
  236. uint8_t pmi; //!< Bits 1-7 Reserved; Bit 0: PMI
  237. uint8_t control; //!< Control
  238. } app_usbd_scsi_cmd_readcapacity10_t;
  239. /**
  240. * @brief Payload of @ref APP_USBD_SCSI_CMD_READCAPACITY10 response.
  241. */
  242. typedef struct {
  243. uint8_t lba[4]; //!< Returned logical block address (LBA)
  244. uint8_t blklen[4]; //!< Logical block length (in bytes)
  245. } app_usbd_scsi_cmd_readcapacity10_resp_t;
  246. /**
  247. * @brief Payload of @ref APP_USBD_SCSI_CMD_READ10 command.
  248. */
  249. typedef struct {
  250. uint8_t opcode; //!< @ref APP_USBD_SCSI_CMD_READ10
  251. uint8_t flags; //!< Command flags
  252. uint8_t lba[4]; //!< Logical Block Address (LBA)
  253. uint8_t groupno; //!< Bits 5-7: reserved; Bits 0-6: group number
  254. uint8_t xfrlen[2]; //!< Transfer length (in contiguous logical blocks)
  255. uint8_t control; //!< Control
  256. } app_usbd_scsi_cmd_read10_t;
  257. /**
  258. * @brief Payload of @ref APP_USBD_SCSI_CMD_WRITE10 command.
  259. */
  260. typedef struct {
  261. uint8_t opcode; //!< @ref APP_USBD_SCSI_CMD_WRITE10
  262. uint8_t flags; //!< Command flags
  263. uint8_t lba[4]; //!< Logical Block Address (LBA)
  264. uint8_t groupno; //!< Bits 5-7: reserved; Bits 0-6: group number
  265. uint8_t xfrlen[2]; //!< Transfer length (in contiguous logical blocks)
  266. uint8_t control; //!< Control
  267. } app_usbd_scsi_cmd_write10_t;
  268. /**
  269. * @brief Payload of @ref APP_USBD_SCSI_CMD_MODESENSE10 command.
  270. */
  271. typedef struct {
  272. uint8_t opcode; //!< @ref APP_USBD_SCSI_CMD_MODESENSE10
  273. uint8_t flags; //!< Flags
  274. uint8_t pcpgcode; //!< Bits 6-7: PC, bits 0-5: page code
  275. uint8_t subpgcode; //!< Subpage code
  276. uint8_t reserved[3]; //!< Reserved
  277. uint8_t alloclen[2]; //!< Allocation length
  278. uint8_t control; //!< Control
  279. } app_usbd_scsi_cmd_modesense10_t;
  280. /**
  281. * @brief Payload of @ref APP_USBD_SCSI_CMD_MODESENSE10 response.
  282. */
  283. typedef struct {
  284. uint8_t mdlen[2]; //!< Mode data length
  285. uint8_t type; //!< Medium type
  286. uint8_t param; //!< Device-specific parameter
  287. uint8_t reserved[2]; //!< Reserved
  288. uint8_t bdlen[2]; //!< Block descriptor length
  289. } app_usbd_scsi_cmd_modesense10_resp_t;
  290. #pragma pack(pop)
  291. /** @} */
  292. #ifdef __cplusplus
  293. }
  294. #endif
  295. #endif /* APP_USBD_MSC_SCSI_H__ */