Open FFBoard
Open source force feedback firmware
msc.h
Go to the documentation of this file.
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{
61 MSC_PROTOCOL_BOT = 0x50
63
65typedef enum
66{
68 MSC_REQ_RESET = 255
70
74typedef enum
75{
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 ;
103
104TU_VERIFY_STATIC(sizeof(msc_csw_t) == 13, "size is not correct");
105
106//--------------------------------------------------------------------+
107// SCSI Constant
108//--------------------------------------------------------------------+
109
111typedef enum
112{
125
127typedef enum
128{
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{
177
178 uint8_t : 7;
179 uint8_t is_removable : 1;
180
181 uint8_t version;
182
185 uint8_t normal_aca : 1;
186 uint8_t : 2;
187
189
190 uint8_t protect : 1;
191 uint8_t : 2;
192 uint8_t third_party_copy : 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;
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;
251 uint8_t : 4;
252
253 uint8_t page_code : 6;
254 uint8_t page_control : 2;
255
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;
271
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];
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
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];
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;
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 ;
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 ;
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_ */
msc_protocol_type_t
MassStorage Protocol.
Definition: msc.h:58
@ MSC_PROTOCOL_BOT
Bulk-Only Transport.
Definition: msc.h:61
@ MSC_PROTOCOL_CBI_NO_INTERRUPT
Control/Bulk/Interrupt protocol (without command completion interrupt)
Definition: msc.h:60
@ MSC_PROTOCOL_CBI
Control/Bulk/Interrupt protocol (with command completion interrupt)
Definition: msc.h:59
TU_VERIFY_STATIC(sizeof(msc_cbw_t)==31, "size is not correct")
struct TU_ATTR_PACKED scsi_read_capacity10_t
SCSI Read Capacity 10 Command: Read Capacity.
struct TU_ATTR_PACKED scsi_inquiry_resp_t
SCSI Inquiry Response Data.
struct TU_ATTR_PACKED scsi_request_sense_t
struct TU_ATTR_PACKED scsi_inquiry_t
SCSI Inquiry Command.
struct TU_ATTR_PACKED scsi_mode_sense6_resp_t
struct TU_ATTR_PACKED scsi_start_stop_unit_t
struct TU_ATTR_PACKED msc_cbw_t
Command Block Wrapper.
struct TU_ATTR_PACKED scsi_read10_t
SCSI Read 10 Command.
scsi_sense_key_type_t
SCSI Sense Key.
Definition: msc.h:128
@ SCSI_SENSE_HARDWARE_ERROR
Indicates the disc drive detected a nonrecoverable hardware failure while performing the command or d...
Definition: msc.h:133
@ SCSI_SENSE_FIRMWARE_ERROR
Vendor specific sense key.
Definition: msc.h:137
@ SCSI_SENSE_VOLUME_OVERFLOW
Indicates a buffered peripheral device has reached the end of medium partition and data remains in th...
Definition: msc.h:140
@ SCSI_SENSE_RECOVERED_ERROR
Indicates the last command completed successfully with some recovery action performed by the disc dri...
Definition: msc.h:130
@ SCSI_SENSE_ILLEGAL_REQUEST
Indicates an illegal parameter in the command descriptor block or in the additional parameters.
Definition: msc.h:134
@ SCSI_SENSE_UNIT_ATTENTION
Indicates the disc drive may have been reset.
Definition: msc.h:135
@ SCSI_SENSE_NOT_READY
Indicates the logical unit addressed cannot be accessed.
Definition: msc.h:131
@ SCSI_SENSE_MISCOMPARE
Indicates that the source data did not match the data read from the medium.
Definition: msc.h:141
@ SCSI_SENSE_EQUAL
Indicates a SEARCH DATA command has satisfied an equal comparison.
Definition: msc.h:139
@ SCSI_SENSE_DATA_PROTECT
Indicates that a command that reads or writes the medium was attempted on a block that is protected f...
Definition: msc.h:136
@ SCSI_SENSE_NONE
no specific Sense Key. This would be the case for a successful command
Definition: msc.h:129
@ SCSI_SENSE_MEDIUM_ERROR
Indicates the command terminated with a non-recovered error condition.
Definition: msc.h:132
@ SCSI_SENSE_ABORTED_COMMAND
Indicates the disc drive aborted the command.
Definition: msc.h:138
struct TU_ATTR_PACKED scsi_write10_t
struct TU_ATTR_PACKED scsi_prevent_allow_medium_removal_t
struct TU_ATTR_PACKED scsi_read_format_capacity_data_t
@ MSC_CBW_SIGNATURE
Constant value of 43425355h (little endian)
Definition: msc.h:51
@ MSC_CSW_SIGNATURE
Constant value of 53425355h (little endian)
Definition: msc.h:52
msc_csw_status_t
Command Block Status Values.
Definition: msc.h:75
@ MSC_CSW_STATUS_FAILED
MSC_CSW_STATUS_FAILED.
Definition: msc.h:77
@ MSC_CSW_STATUS_PHASE_ERROR
MSC_CSW_STATUS_PHASE_ERROR.
Definition: msc.h:78
@ MSC_CSW_STATUS_PASSED
MSC_CSW_STATUS_PASSED.
Definition: msc.h:76
struct TU_ATTR_PACKED scsi_sense_fixed_resp_t
struct TU_ATTR_PACKED scsi_test_unit_ready_t
SCSI Test Unit Ready Command.
scsi_cmd_type_t
SCSI Command Operation Code.
Definition: msc.h:112
@ SCSI_CMD_TEST_UNIT_READY
The SCSI Test Unit Ready command is used to determine if a device is ready to transfer data (read/wri...
Definition: msc.h:113
@ SCSI_CMD_READ_FORMAT_CAPACITY
The command allows the Host to request a list of the possible format capacities for an installed writ...
Definition: msc.h:121
@ SCSI_CMD_PREVENT_ALLOW_MEDIUM_REMOVAL
Definition: msc.h:118
@ SCSI_CMD_REQUEST_SENSE
The SCSI Request Sense command is part of the SCSI computer protocol standard. This command is used t...
Definition: msc.h:120
@ SCSI_CMD_WRITE_10
The WRITE (10) command requests that the device server transfer the specified logical block(s) from t...
Definition: msc.h:123
@ SCSI_CMD_MODE_SELECT_6
provides a means for the application client to specify medium, logical unit, or peripheral device par...
Definition: msc.h:115
@ SCSI_CMD_READ_CAPACITY_10
The SCSI Read Capacity command is used to obtain data capacity information from a target device.
Definition: msc.h:119
@ SCSI_CMD_START_STOP_UNIT
Definition: msc.h:117
@ SCSI_CMD_READ_10
The READ (10) command requests that the device server read the specified logical block(s) and transfe...
Definition: msc.h:122
@ SCSI_CMD_MODE_SENSE_6
provides a means for a device server to report parameters to an application client....
Definition: msc.h:116
@ SCSI_CMD_INQUIRY
The SCSI Inquiry command is used to obtain basic information from a target device.
Definition: msc.h:114
struct TU_ATTR_PACKED msc_csw_t
Command Status Wrapper.
struct TU_ATTR_PACKED scsi_read_format_capacity_t
SCSI Read Format Capacity: Write Capacity.
struct TU_ATTR_PACKED scsi_mode_sense6_t
msc_request_type_t
MassStorage Class-Specific Control Request.
Definition: msc.h:66
@ MSC_REQ_RESET
This request is used to reset the mass storage device and its associated interface....
Definition: msc.h:68
@ MSC_REQ_GET_MAX_LUN
The Get Max LUN device request is used to determine the number of logical units supported by the devi...
Definition: msc.h:67
AUDIO Channel Cluster Descriptor (4.1)
Definition: audio.h:647
uint8_t end_of_medium
Definition: msc.h:229
uint8_t filemark
Definition: msc.h:230
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 peripheral_device_type
Definition: msc.h:175
uint8_t cmd_que
Definition: msc.h:205
uint8_t product_rev[4]
4 bytes of ASCII data defined by the vendor.
Definition: msc.h:213
bool write_protected
Definition: msc.h:270
uint8_t add_sense_len
Definition: msc.h:233
uint8_t start
Definition: msc.h:299
uint8_t multi_port
Definition: msc.h:199
uint8_t no_flush
Definition: msc.h:301
uint32_t information
Definition: msc.h:232
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 data_len
Definition: msc.h:266
uint32_t command_specific_info
Definition: msc.h:234
uint8_t medium_type
Definition: msc.h:267
uint8_t immded
Definition: msc.h:291
uint8_t prohibit_removal
Definition: msc.h:281
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 list_length
Definition: msc.h:326
uint8_t reserved1
Definition: msc.h:163
uint8_t normal_aca
Definition: msc.h:185
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 power_condition_mod
Definition: msc.h:296
uint8_t block_descriptor_len
Definition: msc.h:272
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 wbus16
Definition: msc.h:208
uint8_t dir
Bit 7 of this field define transfer direction - 0 : Data-Out from host to the device....
Definition: msc.h:87
uint8_t add_sense_qualifier
Definition: msc.h:236
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
uint8_t additional_length
Definition: msc.h:188
uint32_t block_num
must be 8*n, length in bytes of formattable capacity descriptor followed it.
Definition: msc.h:328
uint8_t disable_block_descriptor
Definition: msc.h:250
uint16_t block_size_u16
Definition: msc.h:332
uint8_t power_condition
Definition: msc.h:303
uint8_t valid
Definition: msc.h:222
uint8_t scc_support
Definition: msc.h:195
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 sense_key
Definition: msc.h:226
uint8_t page_code
Definition: msc.h:164
volatile uint16_t
Definition: hcd_rusb2.c:58
uint8_t control
Definition: msc.h:154
uint8_t descriptor_type
Number of Logical Blocks.
Definition: msc.h:329
uint8_t response_data_format
Definition: msc.h:183
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
uint8_t page_control
Definition: msc.h:254
uint8_t target_port_group_support
Definition: msc.h:193
uint16_t block_count
Number of Blocks used by this command.
Definition: msc.h:371
uint8_t reserved2
Definition: msc.h:165
uint8_t access_control_coordinator
Definition: msc.h:194
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 third_party_copy
Definition: msc.h:192
uint8_t response_code
70h - current errors, Fixed Format 71h - deferred errors, Fixed Format
Definition: msc.h:221
uint8_t subpage_code
Definition: msc.h:256
uint8_t add_sense_code
Definition: msc.h:235
uint16_t reserved2
Definition: msc.h:349
uint8_t protect
Definition: msc.h:190
uint8_t enclosure_service
Definition: msc.h:201
uint8_t field_replaceable_unit_code
Definition: msc.h:237
uint8_t reserved
Definition: hid.h:338
uint8_t TU_RESERVED
Definition: cdc.h:295
uint8_t partial_medium_indicator
Definition: msc.h:350
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
uint8_t hierarchical_support
Definition: msc.h:184
uint8_t addr16
Definition: msc.h:197
uint8_t sync
Definition: msc.h:207
uint16_t alloc_length
Definition: msc.h:318
uint8_t is_removable
Definition: msc.h:179
uint32_t lba
The first Logical Block Address (LBA) accessed by this command.
Definition: msc.h:348
uint8_t peripheral_qualifier
Definition: msc.h:176
uint8_t version
Definition: msc.h:181
uint8_t load_eject
Definition: msc.h:300
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