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