More AVR32 achitecture ports.
[pub/USBasp.git] / LUFA / Drivers / USB / Class / Common / MassStorage.h
1 /*
2 LUFA Library
3 Copyright (C) Dean Camera, 2010.
4
5 dean [at] fourwalledcubicle [dot] com
6 www.fourwalledcubicle.com
7 */
8
9 /*
10 Copyright 2010 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 disclaim 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 /** \ingroup Group_USBClassMS
32 * @defgroup Group_USBClassMSCommon Common Class Definitions
33 *
34 * \section Module Description
35 * Constants, Types and Enum definitions that are common to both Device and Host modes for the USB
36 * Mass Storage Class.
37 *
38 * @{
39 */
40
41 #ifndef _MS_CLASS_COMMON_H_
42 #define _MS_CLASS_COMMON_H_
43
44 /* Includes: */
45 #include "../../USB.h"
46
47 #include <string.h>
48
49 /* Enable C linkage for C++ Compilers: */
50 #if defined(__cplusplus)
51 extern "C" {
52 #endif
53
54 /* Preprocessor Checks: */
55 #if !defined(__INCLUDE_FROM_MS_DRIVER)
56 #error Do not include this file directly. Include LUFA/Drivers/Class/MassStorage.h instead.
57 #endif
58
59 /* Macros: */
60 /** Mass Storage Class specific request to reset the Mass Storage interface, ready for the next command. */
61 #define REQ_MassStorageReset 0xFF
62
63 /** Mass Storage Class specific request to retrieve the total number of Logical Units (drives) in the SCSI device. */
64 #define REQ_GetMaxLUN 0xFE
65
66 /** Magic signature for a Command Block Wrapper used in the Mass Storage Bulk-Only transport protocol. */
67 #define MS_CBW_SIGNATURE 0x43425355UL
68
69 /** Magic signature for a Command Status Wrapper used in the Mass Storage Bulk-Only transport protocol. */
70 #define MS_CSW_SIGNATURE 0x53425355UL
71
72 /** Mask for a Command Block Wrapper's flags attribute to specify a command with data sent from host-to-device. */
73 #define MS_COMMAND_DIR_DATA_OUT (0 << 7)
74
75 /** Mask for a Command Block Wrapper's flags attribute to specify a command with data sent from device-to-host. */
76 #define MS_COMMAND_DIR_DATA_IN (1 << 7)
77
78 /** SCSI Command Code for an INQUIRY command. */
79 #define SCSI_CMD_INQUIRY 0x12
80
81 /** SCSI Command Code for a REQUEST SENSE command. */
82 #define SCSI_CMD_REQUEST_SENSE 0x03
83
84 /** SCSI Command Code for a TEST UNIT READY command. */
85 #define SCSI_CMD_TEST_UNIT_READY 0x00
86
87 /** SCSI Command Code for a READ CAPACITY (10) command. */
88 #define SCSI_CMD_READ_CAPACITY_10 0x25
89
90 /** SCSI Command Code for a SEND DIAGNOSTIC command. */
91 #define SCSI_CMD_SEND_DIAGNOSTIC 0x1D
92
93 /** SCSI Command Code for a PREVENT ALLOW MEDIUM REMOVAL command. */
94 #define SCSI_CMD_PREVENT_ALLOW_MEDIUM_REMOVAL 0x1E
95
96 /** SCSI Command Code for a WRITE (10) command. */
97 #define SCSI_CMD_WRITE_10 0x2A
98
99 /** SCSI Command Code for a READ (10) command. */
100 #define SCSI_CMD_READ_10 0x28
101
102 /** SCSI Command Code for a WRITE (6) command. */
103 #define SCSI_CMD_WRITE_6 0x0A
104
105 /** SCSI Command Code for a READ (6) command. */
106 #define SCSI_CMD_READ_6 0x08
107
108 /** SCSI Command Code for a VERIFY (10) command. */
109 #define SCSI_CMD_VERIFY_10 0x2F
110
111 /** SCSI Command Code for a MODE SENSE (6) command. */
112 #define SCSI_CMD_MODE_SENSE_6 0x1A
113
114 /** SCSI Command Code for a MODE SENSE (10) command. */
115 #define SCSI_CMD_MODE_SENSE_10 0x5A
116
117 /** SCSI Sense Code to indicate no error has occurred. */
118 #define SCSI_SENSE_KEY_GOOD 0x00
119
120 /** SCSI Sense Code to indicate that the device has recovered from an error. */
121 #define SCSI_SENSE_KEY_RECOVERED_ERROR 0x01
122
123 /** SCSI Sense Code to indicate that the device is not ready for a new command. */
124 #define SCSI_SENSE_KEY_NOT_READY 0x02
125
126 /** SCSI Sense Code to indicate an error whilst accessing the medium. */
127 #define SCSI_SENSE_KEY_MEDIUM_ERROR 0x03
128
129 /** SCSI Sense Code to indicate a hardware has occurred. */
130 #define SCSI_SENSE_KEY_HARDWARE_ERROR 0x04
131
132 /** SCSI Sense Code to indicate that an illegal request has been issued. */
133 #define SCSI_SENSE_KEY_ILLEGAL_REQUEST 0x05
134
135 /** SCSI Sense Code to indicate that the unit requires attention from the host to indicate
136 * a reset event, medium removal or other condition.
137 */
138 #define SCSI_SENSE_KEY_UNIT_ATTENTION 0x06
139
140 /** SCSI Sense Code to indicate that a write attempt on a protected block has been made. */
141 #define SCSI_SENSE_KEY_DATA_PROTECT 0x07
142
143 /** SCSI Sense Code to indicate an error while trying to write to a write-once medium. */
144 #define SCSI_SENSE_KEY_BLANK_CHECK 0x08
145
146 /** SCSI Sense Code to indicate a vendor specific error has occurred. */
147 #define SCSI_SENSE_KEY_VENDOR_SPECIFIC 0x09
148
149 /** SCSI Sense Code to indicate that an EXTENDED COPY command has aborted due to an error. */
150 #define SCSI_SENSE_KEY_COPY_ABORTED 0x0A
151
152 /** SCSI Sense Code to indicate that the device has aborted the issued command. */
153 #define SCSI_SENSE_KEY_ABORTED_COMMAND 0x0B
154
155 /** SCSI Sense Code to indicate an attempt to write past the end of a partition has been made. */
156 #define SCSI_SENSE_KEY_VOLUME_OVERFLOW 0x0D
157
158 /** SCSI Sense Code to indicate that the source data did not match the data read from the medium. */
159 #define SCSI_SENSE_KEY_MISCOMPARE 0x0E
160
161 /** SCSI Additional Sense Code to indicate no additional sense information is available. */
162 #define SCSI_ASENSE_NO_ADDITIONAL_INFORMATION 0x00
163
164 /** SCSI Additional Sense Code to indicate that the logical unit (LUN) addressed is not ready. */
165 #define SCSI_ASENSE_LOGICAL_UNIT_NOT_READY 0x04
166
167 /** SCSI Additional Sense Code to indicate an invalid field was encountered while processing the issued command. */
168 #define SCSI_ASENSE_INVALID_FIELD_IN_CDB 0x24
169
170 /** SCSI Additional Sense Code to indicate that an attempt to write to a protected area was made. */
171 #define SCSI_ASENSE_WRITE_PROTECTED 0x27
172
173 /** SCSI Additional Sense Code to indicate an error whilst formatting the device medium. */
174 #define SCSI_ASENSE_FORMAT_ERROR 0x31
175
176 /** SCSI Additional Sense Code to indicate an invalid command was issued. */
177 #define SCSI_ASENSE_INVALID_COMMAND 0x20
178
179 /** SCSI Additional Sense Code to indicate a write to a block out outside of the medium's range was issued. */
180 #define SCSI_ASENSE_LOGICAL_BLOCK_ADDRESS_OUT_OF_RANGE 0x21
181
182 /** SCSI Additional Sense Code to indicate that no removable medium is inserted into the device. */
183 #define SCSI_ASENSE_MEDIUM_NOT_PRESENT 0x3A
184
185 /** SCSI Additional Sense Qualifier Code to indicate no additional sense qualifier information is available. */
186 #define SCSI_ASENSEQ_NO_QUALIFIER 0x00
187
188 /** SCSI Additional Sense Qualifier Code to indicate that a medium format command failed to complete. */
189 #define SCSI_ASENSEQ_FORMAT_COMMAND_FAILED 0x01
190
191 /** SCSI Additional Sense Qualifier Code to indicate that an initializing command must be issued before the issued
192 * command can be executed.
193 */
194 #define SCSI_ASENSEQ_INITIALIZING_COMMAND_REQUIRED 0x02
195
196 /** SCSI Additional Sense Qualifier Code to indicate that an operation is currently in progress. */
197 #define SCSI_ASENSEQ_OPERATION_IN_PROGRESS 0x07
198
199 /* Type defines: */
200 /** Type define for a Command Block Wrapper, used in the Mass Storage Bulk-Only Transport protocol. */
201 typedef struct
202 {
203 uint32_t Signature; /**< Command block signature, must be CBW_SIGNATURE to indicate a valid Command Block */
204 uint32_t Tag; /**< Unique command ID value, to associate a command block wrapper with its command status wrapper */
205 uint32_t DataTransferLength; /** Length of the optional data portion of the issued command, in bytes */
206 uint8_t Flags; /**< Command block flags, indicating command data direction */
207 uint8_t LUN; /**< Logical Unit number this command is issued to */
208 uint8_t SCSICommandLength; /**< Length of the issued SCSI command within the SCSI command data array */
209 uint8_t SCSICommandData[16]; /**< Issued SCSI command in the Command Block */
210 } MS_CommandBlockWrapper_t;
211
212 /** Type define for a Command Status Wrapper, used in the Mass Storage Bulk-Only Transport protocol. */
213 typedef struct
214 {
215 uint32_t Signature; /**< Status block signature, must be CSW_SIGNATURE to indicate a valid Command Status */
216 uint32_t Tag; /**< Unique command ID value, to associate a command block wrapper with its command status wrapper */
217 uint32_t DataTransferResidue; /**< Number of bytes of data not processed in the SCSI command */
218 uint8_t Status; /**< Status code of the issued command - a value from the MassStorage_CommandStatusCodes_t enum */
219 } MS_CommandStatusWrapper_t;
220
221 /** Type define for a SCSI Sense structure. Structures of this type are filled out by the
222 * device via the MassStore_RequestSense() function, indicating the current sense data of the
223 * device (giving explicit error codes for the last issued command). For details of the
224 * structure contents, refer to the SCSI specifications.
225 */
226 typedef struct
227 {
228 uint8_t ResponseCode;
229
230 uint8_t SegmentNumber;
231
232 unsigned char SenseKey : 4;
233 unsigned char _RESERVED1 : 1;
234 unsigned char ILI : 1;
235 unsigned char EOM : 1;
236 unsigned char FileMark : 1;
237
238 uint8_t Information[4];
239 uint8_t AdditionalLength;
240 uint8_t CmdSpecificInformation[4];
241 uint8_t AdditionalSenseCode;
242 uint8_t AdditionalSenseQualifier;
243 uint8_t FieldReplaceableUnitCode;
244 uint8_t SenseKeySpecific[3];
245 } SCSI_Request_Sense_Response_t;
246
247 /** Type define for a SCSI Inquiry structure. Structures of this type are filled out by the
248 * device via the MassStore_Inquiry() function, retrieving the attached device's information.
249 * For details of the structure contents, refer to the SCSI specifications.
250 */
251 typedef struct
252 {
253 unsigned char DeviceType : 5;
254 unsigned char PeripheralQualifier : 3;
255
256 unsigned char _RESERVED1 : 7;
257 unsigned char Removable : 1;
258
259 uint8_t Version;
260
261 unsigned char ResponseDataFormat : 4;
262 unsigned char _RESERVED2 : 1;
263 unsigned char NormACA : 1;
264 unsigned char TrmTsk : 1;
265 unsigned char AERC : 1;
266
267 uint8_t AdditionalLength;
268 uint8_t _RESERVED3[2];
269
270 unsigned char SoftReset : 1;
271 unsigned char CmdQue : 1;
272 unsigned char _RESERVED4 : 1;
273 unsigned char Linked : 1;
274 unsigned char Sync : 1;
275 unsigned char WideBus16Bit : 1;
276 unsigned char WideBus32Bit : 1;
277 unsigned char RelAddr : 1;
278
279 uint8_t VendorID[8];
280 uint8_t ProductID[16];
281 uint8_t RevisionID[4];
282 } SCSI_Inquiry_Response_t;
283
284 /* Enums: */
285 /** Enum for the possible command status wrapper return status codes. */
286 enum MassStorage_CommandStatusCodes_t
287 {
288 SCSI_Command_Pass = 0, /**< Command completed with no error */
289 SCSI_Command_Fail = 1, /**< Command failed to complete - host may check the exact error via a SCSI REQUEST SENSE command */
290 SCSI_Phase_Error = 2 /**< Command failed due to being invalid in the current phase */
291 };
292
293 /* Disable C linkage for C++ Compilers: */
294 #if defined(__cplusplus)
295 }
296 #endif
297
298 #endif
299
300 /** @} */