1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
49
50
54
55
56
57
58
63
64
65
66
70
71
72
73
74
75
80
81
82
83
92
93
94
95
96
97
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
/* ... */
#ifndef _TUSB_MSC_H_
#define _TUSB_MSC_H_
#include "common/tusb_common.h"
#ifdef __cplusplus
extern "C" {
#endif
typedef enum
{
MSC_SUBCLASS_RBC = 1 ,
MSC_SUBCLASS_SFF_MMC ,
MSC_SUBCLASS_QIC ,
MSC_SUBCLASS_UFI ,
MSC_SUBCLASS_SFF ,
MSC_SUBCLASS_SCSI
...}msc_subclass_type_t;
enum {
MSC_CBW_SIGNATURE = 0x43425355,
MSC_CSW_SIGNATURE = 0x53425355
...};
typedef enum
{
MSC_PROTOCOL_CBI = 0 ,
MSC_PROTOCOL_CBI_NO_INTERRUPT = 1 ,
MSC_PROTOCOL_BOT = 0x50
...}msc_protocol_type_t;
typedef enum
{
MSC_REQ_GET_MAX_LUN = 254,
MSC_REQ_RESET = 255
...}msc_request_type_t;
typedef enum
{
MSC_CSW_STATUS_PASSED = 0 ,
MSC_CSW_STATUS_FAILED ,
MSC_CSW_STATUS_PHASE_ERROR
...}msc_csw_status_t;
typedef struct TU_ATTR_PACKED
{
uint32_t signature;
uint32_t tag;
uint32_t total_bytes;
uint8_t dir;
uint8_t lun;
uint8_t cmd_len;
uint8_t command[16];
...}msc_cbw_t;
TU_VERIFY_STATIC(sizeof(msc_cbw_t) == 31, "size is not correct");
typedef struct TU_ATTR_PACKED
{
uint32_t signature ;
uint32_t tag ;
uint32_t data_residue ;
uint8_t status ;
...}msc_csw_t;
TU_VERIFY_STATIC(sizeof(msc_csw_t) == 13, "size is not correct");
typedef enum
{
SCSI_CMD_TEST_UNIT_READY = 0x00,
SCSI_CMD_INQUIRY = 0x12,
SCSI_CMD_MODE_SELECT_6 = 0x15,
SCSI_CMD_MODE_SENSE_6 = 0x1A,
SCSI_CMD_START_STOP_UNIT = 0x1B,
SCSI_CMD_PREVENT_ALLOW_MEDIUM_REMOVAL = 0x1E,
SCSI_CMD_READ_CAPACITY_10 = 0x25,
SCSI_CMD_REQUEST_SENSE = 0x03,
SCSI_CMD_READ_FORMAT_CAPACITY = 0x23,
SCSI_CMD_READ_10 = 0x28,
SCSI_CMD_WRITE_10 = 0x2A,
...}scsi_cmd_type_t;
typedef enum
{
SCSI_SENSE_NONE = 0x00,
SCSI_SENSE_RECOVERED_ERROR = 0x01,
SCSI_SENSE_NOT_READY = 0x02,
SCSI_SENSE_MEDIUM_ERROR = 0x03,
SCSI_SENSE_HARDWARE_ERROR = 0x04,
SCSI_SENSE_ILLEGAL_REQUEST = 0x05,
SCSI_SENSE_UNIT_ATTENTION = 0x06,
SCSI_SENSE_DATA_PROTECT = 0x07,
SCSI_SENSE_FIRMWARE_ERROR = 0x08,
SCSI_SENSE_ABORTED_COMMAND = 0x0b,
SCSI_SENSE_EQUAL = 0x0c,
SCSI_SENSE_VOLUME_OVERFLOW = 0x0d,
SCSI_SENSE_MISCOMPARE = 0x0e
...}scsi_sense_key_type_t;
typedef struct TU_ATTR_PACKED
{
uint8_t cmd_code ;
uint8_t lun ;
uint8_t reserved[3] ;
uint8_t control ;
...} scsi_test_unit_ready_t;
TU_VERIFY_STATIC(sizeof(scsi_test_unit_ready_t) == 6, "size is not correct");
typedef struct TU_ATTR_PACKED
{
uint8_t cmd_code ;
uint8_t reserved1 ;
uint8_t page_code ;
uint8_t reserved2 ;
uint8_t alloc_length ;
uint8_t control ;
...} scsi_inquiry_t, scsi_request_sense_t;
TU_VERIFY_STATIC(sizeof(scsi_inquiry_t) == 6, "size is not correct");
typedef struct TU_ATTR_PACKED
{
uint8_t peripheral_device_type : 5;
uint8_t peripheral_qualifier : 3;
uint8_t : 7;
uint8_t is_removable : 1;
uint8_t version;
uint8_t response_data_format : 4;
uint8_t hierarchical_support : 1;
uint8_t normal_aca : 1;
uint8_t : 2;
uint8_t additional_length;
uint8_t protect : 1;
uint8_t : 2;
uint8_t third_party_copy : 1;
uint8_t target_port_group_support : 2;
uint8_t access_control_coordinator : 1;
uint8_t scc_support : 1;
uint8_t addr16 : 1;
uint8_t : 3;
uint8_t multi_port : 1;
uint8_t : 1;
uint8_t enclosure_service : 1;
uint8_t : 1;
uint8_t : 1;
uint8_t cmd_que : 1;
uint8_t : 2;
uint8_t sync : 1;
uint8_t wbus16 : 1;
uint8_t : 2;
uint8_t vendor_id[8] ;
uint8_t product_id[16];
uint8_t product_rev[4];
...} scsi_inquiry_resp_t;
TU_VERIFY_STATIC(sizeof(scsi_inquiry_resp_t) == 36, "size is not correct");
typedef struct TU_ATTR_PACKED
{
uint8_t response_code : 7;
uint8_t valid : 1;
uint8_t reserved;
uint8_t sense_key : 4;
uint8_t : 1;
uint8_t ili : 1;
uint8_t end_of_medium : 1;
uint8_t filemark : 1;
uint32_t information;
uint8_t add_sense_len;
uint32_t command_specific_info;
uint8_t add_sense_code;
uint8_t add_sense_qualifier;
uint8_t field_replaceable_unit_code;
uint8_t sense_key_specific[3];
...} scsi_sense_fixed_resp_t;
TU_VERIFY_STATIC(sizeof(scsi_sense_fixed_resp_t) == 18, "size is not correct");
typedef struct TU_ATTR_PACKED
{
uint8_t cmd_code ;
uint8_t : 3;
uint8_t disable_block_descriptor : 1;
uint8_t : 4;
uint8_t page_code : 6;
uint8_t page_control : 2;
uint8_t subpage_code;
uint8_t alloc_length;
uint8_t control;
...} scsi_mode_sense6_t;
TU_VERIFY_STATIC( sizeof(scsi_mode_sense6_t) == 6, "size is not correct");
typedef struct TU_ATTR_PACKED
{
uint8_t data_len;
uint8_t medium_type;
uint8_t reserved : 7;
bool write_protected : 1;
uint8_t block_descriptor_len;
...} scsi_mode_sense6_resp_t;
TU_VERIFY_STATIC( sizeof(scsi_mode_sense6_resp_t) == 4, "size is not correct");
typedef struct TU_ATTR_PACKED
{
uint8_t cmd_code;
uint8_t reserved[3];
uint8_t prohibit_removal;
uint8_t control;
...} scsi_prevent_allow_medium_removal_t;
TU_VERIFY_STATIC( sizeof(scsi_prevent_allow_medium_removal_t) == 6, "size is not correct");
typedef struct TU_ATTR_PACKED
{
uint8_t cmd_code;
uint8_t immded : 1;
uint8_t : 7;
uint8_t TU_RESERVED;
uint8_t power_condition_mod : 4;
uint8_t : 4;
uint8_t start : 1;
uint8_t load_eject : 1;
uint8_t no_flush : 1;
uint8_t : 1;
uint8_t power_condition : 4;
uint8_t control;
...} scsi_start_stop_unit_t;
TU_VERIFY_STATIC( sizeof(scsi_start_stop_unit_t) == 6, "size is not correct");
typedef struct TU_ATTR_PACKED
{
uint8_t cmd_code;
uint8_t reserved[6];
uint16_t alloc_length;
uint8_t control;
...} scsi_read_format_capacity_t;
TU_VERIFY_STATIC( sizeof(scsi_read_format_capacity_t) == 10, "size is not correct");
typedef struct TU_ATTR_PACKED{
uint8_t reserved[3];
uint8_t list_length;
uint32_t block_num;
uint8_t descriptor_type;
uint8_t reserved2;
uint16_t block_size_u16;
...} scsi_read_format_capacity_data_t;
TU_VERIFY_STATIC( sizeof(scsi_read_format_capacity_data_t) == 12, "size is not correct");
typedef struct TU_ATTR_PACKED
{
uint8_t cmd_code ;
uint8_t reserved1 ;
uint32_t lba ;
uint16_t reserved2 ;
uint8_t partial_medium_indicator ;
uint8_t control ;
...} scsi_read_capacity10_t;
TU_VERIFY_STATIC(sizeof(scsi_read_capacity10_t) == 10, "size is not correct");
typedef struct {
uint32_t last_lba ;
uint32_t block_size ;
...} scsi_read_capacity10_resp_t;
TU_VERIFY_STATIC(sizeof(scsi_read_capacity10_resp_t) == 8, "size is not correct");
typedef struct TU_ATTR_PACKED
{
uint8_t cmd_code ;
uint8_t reserved ;
uint32_t lba ;
uint8_t reserved2 ;
uint16_t block_count ;
uint8_t control ;
...} scsi_read10_t, scsi_write10_t;
TU_VERIFY_STATIC(sizeof(scsi_read10_t) == 10, "size is not correct");
TU_VERIFY_STATIC(sizeof(scsi_write10_t) == 10, "size is not correct");
#ifdef __cplusplus
}extern "C" { ... }
#endif
/* ... */
#endif