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