mikroSDK Reference Manual
msc.h
1/*
2 * The MIT License (MIT)
3 *
4 * Copyright (c) 2019 Ha Thach (tinyusb.org)
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining a copy
7 * of this software and associated documentation files (the "Software"), to deal
8 * in the Software without restriction, including without limitation the rights
9 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 * copies of the Software, and to permit persons to whom the Software is
11 * furnished to do so, subject to the following conditions:
12 *
13 * The above copyright notice and this permission notice shall be included in
14 * all copies or substantial portions of the Software.
15 *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22 * THE SOFTWARE.
23 *
24 * This file is part of the TinyUSB stack.
25 */
26
27#ifndef _TUSB_MSC_H_
28#define _TUSB_MSC_H_
29
30#include "common/tusb_common.h"
31
32#ifdef __cplusplus
33 extern "C" {
34#endif
35
36//--------------------------------------------------------------------+
37// Mass Storage Class Constant
38//--------------------------------------------------------------------+
40typedef enum
41{
42 MSC_SUBCLASS_RBC = 1 ,
43 MSC_SUBCLASS_SFF_MMC ,
44 MSC_SUBCLASS_QIC ,
45 MSC_SUBCLASS_UFI ,
46 MSC_SUBCLASS_SFF ,
47 MSC_SUBCLASS_SCSI
48}msc_subclass_type_t;
49
50enum {
51 MSC_CBW_SIGNATURE = 0x43425355,
52 MSC_CSW_SIGNATURE = 0x53425355
53};
54
57typedef enum
58{
59 MSC_PROTOCOL_CBI = 0 ,
60 MSC_PROTOCOL_CBI_NO_INTERRUPT = 1 ,
61 MSC_PROTOCOL_BOT = 0x50
62}msc_protocol_type_t;
63
65typedef enum
66{
67 MSC_REQ_GET_MAX_LUN = 254,
68 MSC_REQ_RESET = 255
69}msc_request_type_t;
70
74typedef enum
75{
76 MSC_CSW_STATUS_PASSED = 0 ,
77 MSC_CSW_STATUS_FAILED ,
78 MSC_CSW_STATUS_PHASE_ERROR
79}msc_csw_status_t;
80
82typedef struct TU_ATTR_PACKED
83{
84 uint32_t signature;
85 uint32_t tag;
86 uint32_t total_bytes;
87 uint8_t dir;
88 uint8_t lun;
89 uint8_t cmd_len;
90 uint8_t command[16];
92
93TU_VERIFY_STATIC(sizeof(msc_cbw_t) == 31, "size is not correct");
94
96typedef struct TU_ATTR_PACKED
97{
98 uint32_t signature ;
99 uint32_t tag ;
100 uint32_t data_residue ;
101 uint8_t status ;
102}msc_csw_t;
103
104TU_VERIFY_STATIC(sizeof(msc_csw_t) == 13, "size is not correct");
105
106//--------------------------------------------------------------------+
107// SCSI Constant
108//--------------------------------------------------------------------+
109
111typedef enum
112{
113 SCSI_CMD_TEST_UNIT_READY = 0x00,
114 SCSI_CMD_INQUIRY = 0x12,
115 SCSI_CMD_MODE_SELECT_6 = 0x15,
116 SCSI_CMD_MODE_SENSE_6 = 0x1A,
117 SCSI_CMD_START_STOP_UNIT = 0x1B,
118 SCSI_CMD_PREVENT_ALLOW_MEDIUM_REMOVAL = 0x1E,
119 SCSI_CMD_READ_CAPACITY_10 = 0x25,
120 SCSI_CMD_REQUEST_SENSE = 0x03,
121 SCSI_CMD_READ_FORMAT_CAPACITY = 0x23,
122 SCSI_CMD_READ_10 = 0x28,
123 SCSI_CMD_WRITE_10 = 0x2A,
124}scsi_cmd_type_t;
125
127typedef enum
128{
129 SCSI_SENSE_NONE = 0x00,
130 SCSI_SENSE_RECOVERED_ERROR = 0x01,
131 SCSI_SENSE_NOT_READY = 0x02,
132 SCSI_SENSE_MEDIUM_ERROR = 0x03,
133 SCSI_SENSE_HARDWARE_ERROR = 0x04,
134 SCSI_SENSE_ILLEGAL_REQUEST = 0x05,
135 SCSI_SENSE_UNIT_ATTENTION = 0x06,
136 SCSI_SENSE_DATA_PROTECT = 0x07,
137 SCSI_SENSE_FIRMWARE_ERROR = 0x08,
138 SCSI_SENSE_ABORTED_COMMAND = 0x0b,
139 SCSI_SENSE_EQUAL = 0x0c,
140 SCSI_SENSE_VOLUME_OVERFLOW = 0x0d,
141 SCSI_SENSE_MISCOMPARE = 0x0e
142}scsi_sense_key_type_t;
143
144//--------------------------------------------------------------------+
145// SCSI Primary Command (SPC-4)
146//--------------------------------------------------------------------+
147
149typedef struct TU_ATTR_PACKED
150{
151 uint8_t cmd_code ;
152 uint8_t lun ;
153 uint8_t reserved[3] ;
154 uint8_t control ;
156
157TU_VERIFY_STATIC(sizeof(scsi_test_unit_ready_t) == 6, "size is not correct");
158
160typedef struct TU_ATTR_PACKED
161{
162 uint8_t cmd_code ;
163 uint8_t reserved1 ;
164 uint8_t page_code ;
165 uint8_t reserved2 ;
166 uint8_t alloc_length ;
167 uint8_t control ;
169
170TU_VERIFY_STATIC(sizeof(scsi_inquiry_t) == 6, "size is not correct");
171
173typedef struct TU_ATTR_PACKED
174{
175 uint8_t peripheral_device_type : 5;
176 uint8_t peripheral_qualifier : 3;
177
178 uint8_t : 7;
179 uint8_t is_removable : 1;
180
181 uint8_t version;
182
183 uint8_t response_data_format : 4;
184 uint8_t hierarchical_support : 1;
185 uint8_t normal_aca : 1;
186 uint8_t : 2;
187
188 uint8_t additional_length;
189
190 uint8_t protect : 1;
191 uint8_t : 2;
192 uint8_t third_party_copy : 1;
193 uint8_t target_port_group_support : 2;
194 uint8_t access_control_coordinator : 1;
195 uint8_t scc_support : 1;
196
197 uint8_t addr16 : 1;
198 uint8_t : 3;
199 uint8_t multi_port : 1;
200 uint8_t : 1; // vendor specific
201 uint8_t enclosure_service : 1;
202 uint8_t : 1;
203
204 uint8_t : 1; // vendor specific
205 uint8_t cmd_que : 1;
206 uint8_t : 2;
207 uint8_t sync : 1;
208 uint8_t wbus16 : 1;
209 uint8_t : 2;
210
211 uint8_t vendor_id[8] ;
212 uint8_t product_id[16];
213 uint8_t product_rev[4];
215
216TU_VERIFY_STATIC(sizeof(scsi_inquiry_resp_t) == 36, "size is not correct");
217
218
219typedef struct TU_ATTR_PACKED
220{
221 uint8_t response_code : 7;
222 uint8_t valid : 1;
223
224 uint8_t reserved;
225
226 uint8_t sense_key : 4;
227 uint8_t : 1;
228 uint8_t ili : 1;
229 uint8_t end_of_medium : 1;
230 uint8_t filemark : 1;
231
232 uint32_t information;
233 uint8_t add_sense_len;
234 uint32_t command_specific_info;
235 uint8_t add_sense_code;
236 uint8_t add_sense_qualifier;
237 uint8_t field_replaceable_unit_code;
238
240
242
243TU_VERIFY_STATIC(sizeof(scsi_sense_fixed_resp_t) == 18, "size is not correct");
244
245typedef struct TU_ATTR_PACKED
246{
247 uint8_t cmd_code ;
248
249 uint8_t : 3;
250 uint8_t disable_block_descriptor : 1;
251 uint8_t : 4;
252
253 uint8_t page_code : 6;
254 uint8_t page_control : 2;
255
256 uint8_t subpage_code;
257 uint8_t alloc_length;
258 uint8_t control;
260
261TU_VERIFY_STATIC( sizeof(scsi_mode_sense6_t) == 6, "size is not correct");
262
263// This is only a Mode parameter header(6).
264typedef struct TU_ATTR_PACKED
265{
266 uint8_t data_len;
267 uint8_t medium_type;
268
269 uint8_t reserved : 7;
270 bool write_protected : 1;
271
272 uint8_t block_descriptor_len;
274
275TU_VERIFY_STATIC( sizeof(scsi_mode_sense6_resp_t) == 4, "size is not correct");
276
277typedef struct TU_ATTR_PACKED
278{
279 uint8_t cmd_code;
280 uint8_t reserved[3];
281 uint8_t prohibit_removal;
282 uint8_t control;
284
285TU_VERIFY_STATIC( sizeof(scsi_prevent_allow_medium_removal_t) == 6, "size is not correct");
286
287typedef struct TU_ATTR_PACKED
288{
289 uint8_t cmd_code;
290
291 uint8_t immded : 1;
292 uint8_t : 7;
293
294 uint8_t TU_RESERVED;
295
296 uint8_t power_condition_mod : 4;
297 uint8_t : 4;
298
299 uint8_t start : 1;
300 uint8_t load_eject : 1;
301 uint8_t no_flush : 1;
302 uint8_t : 1;
303 uint8_t power_condition : 4;
304
305 uint8_t control;
307
308TU_VERIFY_STATIC( sizeof(scsi_start_stop_unit_t) == 6, "size is not correct");
309
310//--------------------------------------------------------------------+
311// SCSI MMC
312//--------------------------------------------------------------------+
314typedef struct TU_ATTR_PACKED
315{
316 uint8_t cmd_code;
317 uint8_t reserved[6];
318 uint16_t alloc_length;
319 uint8_t control;
321
322TU_VERIFY_STATIC( sizeof(scsi_read_format_capacity_t) == 10, "size is not correct");
323
324typedef struct TU_ATTR_PACKED{
325 uint8_t reserved[3];
326 uint8_t list_length;
327
328 uint32_t block_num;
329 uint8_t descriptor_type; // 00: reserved, 01 unformatted media , 10 Formatted media, 11 No media present
330
331 uint8_t reserved2;
332 uint16_t block_size_u16;
333
335
336TU_VERIFY_STATIC( sizeof(scsi_read_format_capacity_data_t) == 12, "size is not correct");
337
338//--------------------------------------------------------------------+
339// SCSI Block Command (SBC-3)
340// NOTE: All data in SCSI command are in Big Endian
341//--------------------------------------------------------------------+
342
344typedef struct TU_ATTR_PACKED
345{
346 uint8_t cmd_code ;
347 uint8_t reserved1 ;
348 uint32_t lba ;
349 uint16_t reserved2 ;
350 uint8_t partial_medium_indicator ;
351 uint8_t control ;
353
354TU_VERIFY_STATIC(sizeof(scsi_read_capacity10_t) == 10, "size is not correct");
355
357typedef struct {
358 uint32_t last_lba ;
359 uint32_t block_size ;
361
362TU_VERIFY_STATIC(sizeof(scsi_read_capacity10_resp_t) == 8, "size is not correct");
363
365typedef struct TU_ATTR_PACKED
366{
367 uint8_t cmd_code ;
368 uint8_t reserved ; // has LUN according to wiki
369 uint32_t lba ;
370 uint8_t reserved2 ;
371 uint16_t block_count ;
372 uint8_t control ;
374
375TU_VERIFY_STATIC(sizeof(scsi_read10_t) == 10, "size is not correct");
376TU_VERIFY_STATIC(sizeof(scsi_write10_t) == 10, "size is not correct");
377
378#ifdef __cplusplus
379 }
380#endif
381
382#endif /* _TUSB_MSC_H_ */
AUDIO Channel Cluster Descriptor (4.1)
Definition audio.h:647
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:85
uint8_t product_rev[4]
4 bytes of ASCII data defined by the vendor.
Definition msc.h:213
uint8_t cmd_code
SCSI OpCode for SCSI_CMD_TEST_UNIT_READY.
Definition msc.h:151
uint8_t status
indicates the success or failure of the command. Values from msc_csw_status_t
Definition msc.h:101
uint8_t alloc_length
specifies the maximum number of bytes that USB host has allocated in the Data-In Buffer....
Definition msc.h:166
uint8_t sense_key_specific[3]
sense key specific valid bit is bit 7 of key[0], aka MSB in Big Endian layout
Definition msc.h:239
uint8_t lun
The device Logical Unit Number (LUN) to which the command block is being sent. For devices that suppo...
Definition msc.h:88
uint8_t cmd_len
The valid length of the CBWCBin bytes. This defines the valid length of the command block....
Definition msc.h:89
uint8_t dir
Bit 7 of this field define transfer direction - 0 : Data-Out from host to the device....
Definition msc.h:87
uint32_t signature
Signature that helps identify this data packet as a CBW. The signature field shall contain the value ...
Definition msc.h:84
uint8_t product_id[16]
16 bytes of ASCII data defined by the vendor.
Definition msc.h:212
uint32_t block_num
must be 8*n, length in bytes of formattable capacity descriptor followed it.
Definition msc.h:328
uint8_t vendor_id[8]
8 bytes of ASCII data identifying the vendor of the product.
Definition msc.h:211
uint8_t ili
Incorrect length indicator.
Definition msc.h:228
uint8_t descriptor_type
Number of Logical Blocks.
Definition msc.h:329
uint32_t data_residue
For Data-Out the device shall report in the dCSWDataResidue the difference between the amount of data...
Definition msc.h:100
uint16_t block_count
Number of Blocks used by this command.
Definition msc.h:371
uint8_t command[16]
The command block to be executed by the device. The device shall interpret the first cmd_len bytes in...
Definition msc.h:90
uint8_t response_code
70h - current errors, Fixed Format 71h - deferred errors, Fixed Format
Definition msc.h:221
uint8_t reserved
Definition hid.h:325
uint32_t total_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:86
uint32_t lba
The first Logical Block Address (LBA) accessed by this command.
Definition msc.h:348
SCSI Read Capacity 10 Response Data.
Definition msc.h:357
uint32_t last_lba
The last Logical Block Address of the device.
Definition msc.h:358
uint32_t block_size
Block size in bytes.
Definition msc.h:359