tinyusb  0.4
Click here to lend your support to tinyusb donation and make a donation at pledgie.com
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Groups Pages
msc.h
Go to the documentation of this file.
1 /**************************************************************************/
37 /**************************************************************************/
38 
46 #ifndef _TUSB_MSC_H_
47 #define _TUSB_MSC_H_
48 
49 #include "common/common.h"
50 
51 #ifdef __cplusplus
52  extern "C" {
53 #endif
54 
55 //--------------------------------------------------------------------+
56 // Mass Storage Class Constant
57 //--------------------------------------------------------------------+
59 typedef enum {
67 
68 enum {
69  MSC_CBW_SIGNATURE = 0x43425355,
70  MSC_CSW_SIGNATURE = 0x53425355
71 };
72 
75 typedef enum {
80 
82 typedef enum {
86 
90 typedef enum {
95 
97 typedef ATTR_PACKED_STRUCT(struct) {
98  uint32_t signature ;
99  uint32_t tag ;
100  uint32_t xfer_bytes ;
101  uint8_t dir ;
102  uint8_t lun ;
103  uint8_t cmd_len ;
104  uint8_t command[16] ;
106 
107 STATIC_ASSERT(sizeof(msc_cmd_block_wrapper_t) == 31, "size is not correct");
108 
110 typedef ATTR_PACKED_STRUCT(struct) {
111  uint32_t signature ;
112  uint32_t tag ;
113  uint32_t data_residue ;
114  uint8_t status ;
116 
117 STATIC_ASSERT(sizeof(msc_cmd_status_wrapper_t) == 13, "size is not correct");
118 
119 //--------------------------------------------------------------------+
120 // SCSI Constant
121 //--------------------------------------------------------------------+
122 
124 typedef enum {
129  SCSI_CMD_PREVENT_ALLOW_MEDIUM_REMOVAL = 0x1E,
136 
138 typedef enum {
153 
154 //--------------------------------------------------------------------+
155 // SCSI Primary Command (SPC-4)
156 //--------------------------------------------------------------------+
157 
159 typedef ATTR_PACKED_STRUCT(struct) {
160  uint8_t cmd_code ;
161  uint8_t lun ;
162  uint8_t reserved[3] ;
163  uint8_t control ;
165 
166 STATIC_ASSERT(sizeof(scsi_test_unit_ready_t) == 6, "size is not correct");
167 
169 typedef ATTR_PACKED_STRUCT(struct) {
170  uint8_t cmd_code ;
171  uint8_t reserved1 ;
172  uint8_t page_code ;
173  uint8_t reserved2 ;
174  uint8_t alloc_length ;
175  uint8_t control ;
177 
178 STATIC_ASSERT(sizeof(scsi_inquiry_t) == 6, "size is not correct");
179 
181 typedef ATTR_PACKED_STRUCT(struct)
182 {
183  uint8_t peripheral_device_type : 5;
184  uint8_t peripheral_qualifier : 3;
185 
186  uint8_t : 7;
187  uint8_t is_removable : 1;
188 
189  uint8_t version;
190 
191  uint8_t response_data_format : 4;
192  uint8_t hierarchical_support : 1;
193  uint8_t normal_aca : 1;
194  uint8_t : 2;
195 
196  uint8_t additional_length;
197 
198  uint8_t protect : 1;
199  uint8_t : 2;
200  uint8_t third_party_copy : 1;
201  uint8_t target_port_group_support : 2;
202  uint8_t access_control_coordinator : 1;
203  uint8_t scc_support : 1;
204 
205  uint8_t addr16 : 1;
206  uint8_t : 3;
207  uint8_t multi_port : 1;
208  uint8_t : 1; // vendor specific
209  uint8_t enclosure_service : 1;
210  uint8_t : 1;
211 
212  uint8_t : 1; // vendor specific
213  uint8_t cmd_que : 1;
214  uint8_t : 2;
215  uint8_t sync : 1;
216  uint8_t wbus16 : 1;
217  uint8_t : 2;
218 
219  uint8_t vendor_id[8] ;
220  uint8_t product_id[16] ;
221  uint8_t product_revision[4] ;
223 
224 STATIC_ASSERT(sizeof(scsi_inquiry_data_t) == 36, "size is not correct");
225 
226 
227 typedef ATTR_PACKED_STRUCT(struct) {
228  uint8_t response_code : 7;
229  uint8_t valid : 1;
230 
231  uint8_t reserved;
232 
233  uint8_t sense_key : 4;
234  uint8_t : 1;
235  uint8_t incorrect_len_idicatior : 1;
236  uint8_t end_of_medium : 1;
237  uint8_t filemark : 1;
238 
239  uint32_t information;
240  uint8_t additional_sense_len;
241  uint32_t command_specific_info;
242  uint8_t additional_sense_code;
243  uint8_t additional_sense_qualifier;
244  uint8_t field_replaceable_unit_code;
245 
246  uint8_t sense_key_specific[3];
247 
249 
250 STATIC_ASSERT(sizeof(scsi_sense_fixed_data_t) == 18, "size is not correct");
251 
252 typedef ATTR_PACKED_STRUCT(struct) {
253  uint8_t cmd_code ;
254 
255  uint8_t : 3;
256  uint8_t disable_block_descriptor : 1;
257  uint8_t : 0;
258 
259  uint8_t page_code : 6;
260  uint8_t page_control : 2;
261 
262  uint8_t subpage_code;
263  uint8_t alloc_length;
264  uint8_t control;
266 
267 STATIC_ASSERT( sizeof(scsi_mode_sense_6_t) == 6, "size is not correct");
268 
269 typedef ATTR_PACKED_STRUCT(struct) {
270  uint8_t mode_data_length;
271  uint8_t medium_type;
272  uint8_t device_specific_para;
273  uint8_t block_descriptor_length;
275 
276 STATIC_ASSERT( sizeof(scsi_mode_parameters_t) == 4, "size is not correct");
277 
278 typedef ATTR_PACKED_STRUCT(struct) {
279  uint8_t cmd_code;
280  uint8_t reserved[3];
281  uint8_t prohibit_removal;
282  uint8_t control;
284 
285 STATIC_ASSERT( sizeof(scsi_prevent_allow_medium_removal_t) == 6, "size is not correct");
286 
287 //--------------------------------------------------------------------+
288 // SCSI MMC
289 //--------------------------------------------------------------------+
291 typedef ATTR_PACKED_STRUCT(struct) {
292  uint8_t cmd_code;
293  uint8_t reserved[6];
294  uint16_t alloc_length;
295  uint8_t control;
297 
298 STATIC_ASSERT( sizeof(scsi_read_format_capacity_t) == 10, "size is not correct");
299 
300 typedef ATTR_PACKED_STRUCT(struct){
301  uint8_t reserved[3];
302  uint8_t list_length;
303 
304  uint32_t block_num;
305  uint8_t descriptor_type; // 00: reserved, 01 unformatted media , 10 Formatted media, 11 No media present
306 
307  uint8_t reserved2;
308  uint16_t block_size_u16;
309 
311 
312 STATIC_ASSERT( sizeof(scsi_read_format_capacity_data_t) == 12, "size is not correct");
313 
314 //--------------------------------------------------------------------+
315 // SCSI Block Command (SBC-3)
316 // NOTE: All data in SCSI command are in Big Endian
317 //--------------------------------------------------------------------+
318 
320 typedef ATTR_PACKED_STRUCT(struct) {
321  uint8_t cmd_code ;
322  uint8_t reserved1 ;
323  uint32_t lba ;
324  uint16_t reserved2 ;
325  uint8_t partial_medium_indicator ;
326  uint8_t control ;
328 
329 STATIC_ASSERT(sizeof(scsi_read_capacity10_t) == 10, "size is not correct");
330 
332 typedef struct {
333  uint32_t last_lba ;
334  uint32_t block_size ;
336 
337 STATIC_ASSERT(sizeof(scsi_read_capacity10_data_t) == 8, "size is not correct");
338 
340 typedef ATTR_PACKED_STRUCT(struct) {
341  uint8_t cmd_code ;
342  uint8_t reserved ; // has LUN according to wiki
343  uint32_t lba ;
344  uint8_t reserved2 ;
345  uint16_t block_count ;
346  uint8_t control ;
348 
349 STATIC_ASSERT(sizeof(scsi_read10_t) == 10, "size is not correct");
350 STATIC_ASSERT(sizeof(scsi_write10_t) == 10, "size is not correct");
351 
352 #ifdef __cplusplus
353  }
354 #endif
355 
356 #endif /* _TUSB_MSC_H_ */
357 
msc_request_type_t
MassStorage Class-Specific Control Request.
Definition: msc.h:82
uint8_t cmd_code
SCSI OpCode for SCSI_CMD_MODE_SENSE_6.
Definition: msc.h:253
SCSI Read Capacity 10 Command: Read Capacity.
Definition: msc.h:320
uint32_t xfer_bytes
The number of bytes of data that the host expects to transfer on the Bulk-In or Bulk-Out endpoint (as...
Definition: msc.h:100
SCSI Read 10 Command.
Definition: msc.h:340
uint32_t tag
The device shall set this field to the value received in the dCBWTag of the associated CBW...
Definition: msc.h:112
QIC-157. Typically used by a tape device.
Definition: msc.h:62
uint32_t data_residue
For Data-Out the device shall report in the dCSWDataResiduethe difference between the amount of data ...
Definition: msc.h:113
The SCSI Test Unit Ready command is used to determine if a device is ready to transfer data (read/wri...
Definition: msc.h:125
MSC_CSW_STATUS_FAILED.
Definition: msc.h:92
Constant value of 43425355h (little endian)
Definition: msc.h:69
Constant value of 53425355h (little endian)
Definition: msc.h:70
uint8_t lun
The device Logical Unit Number (LUN) to which the command block is being sent. For devices that suppo...
Definition: msc.h:102
provides a means for the application client to specify medium, logical unit, or peripheral device par...
Definition: msc.h:127
uint32_t signature
Signature that helps identify this data packet as a CBW. The signature field shall contain the value ...
Definition: msc.h:98
provides a means for a device server to report parameters to an application client. It is a complementary command to the MODE SELECT(6) command. Device servers that implement the MODE SENSE(6) command shall also implement the MODE SELECT(6) command.
Definition: msc.h:128
The WRITE (10) command requests thatthe device server transfer the specified logical block(s) from th...
Definition: msc.h:134
uint8_t cmd_code
SCSI OpCode for SCSI_CMD_INQUIRY.
Definition: msc.h:170
SFF-8070i. Can be used by Floppy Disk Drive (FDD) device.
Definition: msc.h:64
uint8_t cmd_code
SCSI OpCode.
Definition: msc.h:341
The SCSI Request Sense command is part of the SCSI computer protocol standard. This command is used t...
Definition: msc.h:131
Bulk-Only Transport.
Definition: msc.h:78
Indicates the disc drive aborted the command.
Definition: msc.h:148
Control/Bulk/Interrupt protocol (with command completion interrupt)
Definition: msc.h:76
MSC_CSW_STATUS_PHASE_ERROR.
Definition: msc.h:93
SCSI Read Format Capacity: Write Capacity.
Definition: msc.h:291
The READ (10) command requests that the device server read the specified logical block(s) and transfe...
Definition: msc.h:133
The SCSI Inquiry command is used to obtain basic information from a target device.
Definition: msc.h:126
SCSI Read Capacity 10 Response Data.
Definition: msc.h:332
The command allows the Host to request a list of the possible format capacities for an installed writ...
Definition: msc.h:132
uint16_t block_count
Number of Blocks used by this command.
Definition: msc.h:345
uint32_t lba
The first Logical Block Address (LBA) accessed by this command.
Definition: msc.h:343
MSC_CSW_STATUS_PASSED.
Definition: msc.h:91
SCSI Inquiry Response Data.
Definition: msc.h:181
uint8_t reserved
Obsolete.
Definition: msc.h:231
uint8_t lun
Logical Unit.
Definition: msc.h:161
uint8_t cmd_code
SCSI OpCode for SCSI_CMD_READ_CAPACITY_10.
Definition: msc.h:321
msc_subclass_type_t
MassStorage Subclass.
Definition: msc.h:59
scsi_sense_key_type_t
SCSI Sense Key.
Definition: msc.h:138
Indicates the command terminated with a non-recovered error condition.
Definition: msc.h:142
Indicates a buffered peripheral device has reached the end of medium partition and data remains in th...
Definition: msc.h:150
uint32_t block_num
must be 8*n, length in bytes of formattable capacity descriptor followed it.
Definition: msc.h:304
uint32_t last_lba
The last Logical Block Address of the device.
Definition: msc.h:333
This request is used to reset the mass storage device and its associated interface. This class-specific request shall ready the device for the next CBW from the host.
Definition: msc.h:84
uint32_t tag
Tag sent by the host. The device shall echo the contents of this field back to the host in the dCSWTa...
Definition: msc.h:99
uint8_t cmd_len
The valid length of the CBWCBin bytes. This defines the valid length of the command block...
Definition: msc.h:103
Control/Bulk/Interrupt protocol (without command completion interrupt)
Definition: msc.h:77
uint8_t alloc_length
specifies the maximum number of bytes that USB host has allocated in the Data-In Buffer. An allocation length of zero specifies that no data shall be transferred.
Definition: msc.h:174
The Get Max LUN device request is used to determine the number of logical units supported by the devi...
Definition: msc.h:83
Indicates the disc drive detected a nonrecoverable hardware failure while performing the command or d...
Definition: msc.h:143
Indicates that a command that reads or writes the medium was attempted on a block that is protected f...
Definition: msc.h:146
uint8_t dir
Bit 7 of this field define transfer direction - 0 : Data-Out from host to the device. - 1 : Data-In from the device to the host.
Definition: msc.h:101
Indicates a SEARCH DATA command has satisfied an equal comparison.
Definition: msc.h:149
msc_csw_status_t
Command Block Status Values.
Definition: msc.h:90
Command Status Wrapper.
Definition: msc.h:110
scsi_cmd_type_t
SCSI Command Operation Code.
Definition: msc.h:124
Indicates an illegal parameter in the command descriptor block or in the additional parameters...
Definition: msc.h:144
UFI. Typically used by Floppy Disk Drive (FDD) device.
Definition: msc.h:63
uint8_t descriptor_type
Number of Logical Blocks.
Definition: msc.h:305
uint8_t cmd_code
SCSI OpCode for SCSI_CMD_PREVENT_ALLOW_MEDIUM_REMOVAL.
Definition: msc.h:279
ndicates that the source data did not match the data read from the medium.
Definition: msc.h:151
no specific Sense Key. This would be the case for a successful command
Definition: msc.h:139
The SCSI Read Capacity command is used to obtain data capacity information from a target device...
Definition: msc.h:130
Command Block Wrapper.
Definition: msc.h:97
SCSI transparent command set.
Definition: msc.h:65
Reduced Block Commands (RBC) T10 Project 1240-D.
Definition: msc.h:60
uint8_t cmd_code
SCSI OpCode for SCSI_CMD_TEST_UNIT_READY.
Definition: msc.h:160
uint32_t signature
Signature that helps identify this data packet as a CSW. The signature field shall contain the value ...
Definition: msc.h:111
uint8_t status
indicates the success or failure of the command. Values from msc_csw_status_t
Definition: msc.h:114
uint32_t lba
The first Logical Block Address (LBA) accessed by this command.
Definition: msc.h:323
Indicates the logical unit addressed cannot be accessed.
Definition: msc.h:141
uint32_t block_size
Block size in bytes.
Definition: msc.h:334
ndicates the last command completed successfully with some recovery action performed by the disc driv...
Definition: msc.h:140
Vendor specific sense key.
Definition: msc.h:147
msc_protocol_type_t
MassStorage Protocol.
Definition: msc.h:75
SCSI Test Unit Ready Command.
Definition: msc.h:159
SFF-8020i, MMC-2 (ATAPI). Typically used by a CD/DVD device.
Definition: msc.h:61
SCSI Inquiry Command.
Definition: msc.h:169
Indicates the disc drive may have been reset.
Definition: msc.h:145