Loading...
Searching...
No Matches
scsi.h
Go to the documentation of this file.
1/*
2 * Copyright (C) 2019-2021 Mesotic SAS
3 *
4 * This file is subject to the terms and conditions of the GNU Lesser General
5 * Public License v2.1. See the file LICENSE in the top level directory for
6 * more details.
7 */
8
20#ifndef USB_USBUS_MSC_SCSI_H
21#define USB_USBUS_MSC_SCSI_H
22
23#include "byteorder.h"
24
25#ifdef __cplusplus
26extern "C" {
27#endif
28
29#ifndef USBUS_MSC_VENDOR_ID
30#define USBUS_MSC_VENDOR_ID "RIOT-OS"
31#endif /* USBUS_MSC_VENDOR_ID */
32
33#ifndef USBUS_MSC_PRODUCT_ID
34#define USBUS_MSC_PRODUCT_ID "RIOT_MSC_DISK "
35#endif /* USBUS_MSC_PRODUCT_ID */
36
37#ifndef USBUS_MSC_PRODUCT_REV
38#define USBUS_MSC_PRODUCT_REV " 1.0"
39#endif /* USBUS_MSC_PRODUCT_REV */
40
48#define SCSI_TEST_UNIT_READY 0x00
49#define SCSI_REQUEST_SENSE 0x03
50#define SCSI_FORMAT_UNIT 0x04
51#define SCSI_INQUIRY 0x12
52#define SCSI_MODE_SELECT6 0x15
53#define SCSI_MODE_SENSE6 0x1A
54#define SCSI_START_STOP_UNIT 0x1B
55#define SCSI_MEDIA_REMOVAL 0x1E
56#define SCSI_READ_FORMAT_CAPACITIES 0x23
57#define SCSI_READ_CAPACITY 0x25
58#define SCSI_READ10 0x28
59#define SCCI_READ12 0xA8
60#define SCSI_WRITE10 0x2A
61#define SCSI_WRITE12 0xAA
62#define SCSI_SEEK 0x2B
63#define SCSI_WRITE_AND_VERIFY 0x2E
64#define SCSI_VERIFY10 0x2F
65#define SCSI_MODE_SELECT10 0x55
66#define SCSI_MODE_SENSE10 0x5A
72#define SCSI_CBW_SIGNATURE 0x43425355
73
77#define SCSI_CSW_SIGNATURE 0x53425355
78
83#define SCSI_VERSION_NONE 0x0000
84#define SCSI_VERSION_SCSI1 0x0001
85#define SCSI_VERSION_SCSI2 0x0002
94#define SCSI_READ_FMT_CAPA_TYPE_RESERVED 0x00
95#define SCSI_READ_FMT_CAPA_TYPE_UNFORMATTED 0x01
96#define SCSI_READ_FMT_CAPA_TYPE_FORMATTED 0x02
97#define SCSI_READ_FMT_CAPA_TYPE_NO_MEDIA 0x03
103#define SCSI_REQUEST_SENSE_ERROR 0x70
104
110#define SCSI_SENSE_KEY_NO_SENSE 0x00
111#define SCSI_SENSE_KEY_RECOVERED_ERROR 0x01
112#define SCSI_SENSE_KEY_NOT_READY 0x02
113#define SCSI_SENSE_KEY_MEDIUM_ERROR 0x03
114#define SCSI_SENSE_KEY_HARDWARE_ERROR 0x04
115#define SCSI_SENSE_KEY_ILLEGAL_REQUEST 0x05
116#define SCSI_SENSE_KEY_UNIT_ATTENTION 0x06
117#define SCSI_SENSE_KEY_DATA_PROTECT 0x07
118#define SCSI_SENSE_KEY_BLANK_CHECK 0x08
119#define SCSI_SENSE_KEY_VENDOR_SPECIFIC 0x09
120#define SCSI_SENSE_KEY_ABORTED_COMMAND 0x0B
121#define SCSI_SENSE_KEY_VOLUME_OVERFLOW 0x0D
122#define SCSI_SENSE_KEY_MISCOMPARE 0x0E
130typedef struct __attribute__((packed)) {
131 uint8_t type;
132 uint8_t logical_unit;
133 uint8_t reserved[10];
135
142typedef struct __attribute__((packed)) {
144 uint8_t medium_type;
145 uint8_t flags;
148
157typedef struct __attribute__((packed)) {
158 uint8_t opcode;
159 uint8_t flags;
161 uint8_t group_number;
164
173typedef struct __attribute__((packed)) {
174 uint8_t type;
175 uint8_t reserved1 : 7;
176 uint8_t removable : 1;
177 uint8_t version;
178 uint8_t response_format : 4;
179 uint8_t reserved3 : 4;
180 uint8_t length;
181 uint8_t flags[3];
182 uint8_t vendor_id[8];
183 uint8_t product_id[16];
184 uint8_t product_rev[4];
186
193typedef struct __attribute__((packed)) {
194 uint8_t reserved1[3];
195 uint8_t list_length;
197 uint8_t type;
198 uint8_t blk_len[3];
200
205typedef struct __attribute__((packed)) {
206 uint8_t error_code;
207 uint8_t reserved1;
208 uint8_t sense_key;
209 uint8_t reserved2[4];
210 uint8_t add_len;
211 uint8_t reserved3[4];
212 uint8_t asc;
213 uint8_t ascq;
214 uint8_t fruc;
215 uint16_t sk_spec;
217
226typedef struct __attribute__((packed)) {
230
237typedef struct __attribute__((packed)) {
238 uint32_t signature;
239 uint32_t tag;
240 uint32_t data_len;
241 uint8_t flags;
242 uint8_t lun;
243 uint8_t cb_len;
244 uint8_t cb[16];
246
253typedef struct __attribute__((packed)) {
254 uint32_t signature;
255 uint32_t tag;
256 uint32_t data_left;
257 uint8_t status;
259
264typedef struct {
265 uint32_t tag;
266 size_t len;
267 uint8_t status;
268 uint8_t lun;
269} cbw_info_t;
270
280 size_t len);
281
289
290#ifdef __cplusplus
291}
292#endif
293
294#endif /* USB_USBUS_MSC_SCSI_H */
Functions to work with different byte orders.
void usbus_msc_scsi_process_cmd(usbus_t *usbus, usbus_handler_t *handler, usbdev_ep_t *ep, size_t len)
Process incoming Command Block Wrapper buffer.
void scsi_gen_csw(usbus_handler_t *handler, cbw_info_t *cmd)
Generate Command Status Wrapper and send it to the host.
USBUS Command Block Wrapper information.
Definition scsi.h:264
uint8_t status
Status of the current operation.
Definition scsi.h:267
size_t len
Remaining bytes to handle.
Definition scsi.h:266
uint8_t lun
Store LUN from CBW.
Definition scsi.h:268
uint32_t tag
Store tag information from CBW.
Definition scsi.h:265
Command Block Wrapper packet structure.
Definition scsi.h:237
uint32_t tag
ID for the current command.
Definition scsi.h:239
uint32_t signature
CBW signature (SCSI_CBW_SIGNATURE)
Definition scsi.h:238
uint8_t lun
Target Logical Unit Number.
Definition scsi.h:242
uint32_t data_len
Number of bytes host expects to transfer from/to.
Definition scsi.h:240
uint8_t flags
Command block flags.
Definition scsi.h:241
uint8_t cb_len
Length of the block in bytes (max: 16 bytes)
Definition scsi.h:243
CBW Packet structure for (SCSI_READ10) and (SCSI_WRITE10) requests.
Definition scsi.h:157
uint8_t group_number
Group number.
Definition scsi.h:161
uint8_t flags
Miscellaneous flags.
Definition scsi.h:159
be_uint32_t blk_addr
Block address.
Definition scsi.h:160
be_uint16_t xfer_len
Transfer length in bytes.
Definition scsi.h:162
uint8_t opcode
Operation code.
Definition scsi.h:158
Command Status Wrapper packet structure.
Definition scsi.h:253
uint32_t signature
CSW signature (SCSI_CSW_SIGNATURE)
Definition scsi.h:254
uint8_t status
Status of the command.
Definition scsi.h:257
uint32_t tag
ID for the answered CBW.
Definition scsi.h:255
uint32_t data_left
Indicate how many bytes from the CBW were not processed.
Definition scsi.h:256
Packet structure to answer (SCSI_INQUIRY) request.
Definition scsi.h:173
uint8_t length
Byte 4 Additional Length (n-4)
Definition scsi.h:180
uint8_t removable
Byte 1 [B7] Removable device flag.
Definition scsi.h:176
uint8_t type
Byte 0 Peripheral type.
Definition scsi.h:174
uint8_t reserved1
Byte 1 [B6..B0] Reserved.
Definition scsi.h:175
uint8_t reserved3
Byte 3 [B7..B4] Reserved.
Definition scsi.h:179
uint8_t response_format
Byte 3 [B3..B0] Response Data Format.
Definition scsi.h:178
uint8_t version
Byte 2 SCSI Version.
Definition scsi.h:177
Packet structure to answer (SCSI_MODE_SELECT6) and (SCSI_MODE_SENSE6) requests.
Definition scsi.h:142
uint8_t medium_type
Type of medium.
Definition scsi.h:144
uint8_t mode_data_len
Size of the whole packet.
Definition scsi.h:143
uint8_t flags
Miscellaneous flags.
Definition scsi.h:145
uint8_t block_desc_len
Length of block descriptor.
Definition scsi.h:146
Packet structure to answer (SCSI_READ_CAPACITY) request.
Definition scsi.h:226
be_uint32_t last_blk
Indicate last block number.
Definition scsi.h:227
be_uint32_t blk_len
Total size of a block in bytes.
Definition scsi.h:228
Packet structure to answer (SCSI_READ_FORMAT_CAPACITIES) request.
Definition scsi.h:193
uint8_t type
Byte 8 Descriptor type.
Definition scsi.h:197
be_uint32_t blk_nb
Byte 7..4 Number of blocks.
Definition scsi.h:196
uint8_t list_length
Byte 3 Capacity list length.
Definition scsi.h:195
Packet structure to answer (SCSI_REQUEST_SENSE) request.
Definition scsi.h:205
uint16_t sk_spec
Byte 16..15 Sense Key Specific.
Definition scsi.h:215
uint8_t fruc
Byte 14 Field Replaceable Unit Code.
Definition scsi.h:214
uint8_t asc
Byte 12 Additional Sense Code.
Definition scsi.h:212
uint8_t ascq
Byte 13 Additional Sense Code Qualifier.
Definition scsi.h:213
uint8_t sense_key
Byte 2 Sense key.
Definition scsi.h:208
uint8_t reserved1
Reserved.
Definition scsi.h:207
uint8_t error_code
Byte 0 Error code.
Definition scsi.h:206
uint8_t add_len
Byte 7 Additional sense length.
Definition scsi.h:210
Packet structure to answer (SCSI_TEST_UNIT_READY) request.
Definition scsi.h:130
uint8_t type
type of device
Definition scsi.h:131
uint8_t logical_unit
Selected LUN.
Definition scsi.h:132
usbdev endpoint descriptor
Definition usbdev.h:259
USBUS handler struct.
Definition usbus.h:436
USBUS context struct.
Definition usbus.h:448
A 16 bit integer in big endian aka network byte order.
Definition byteorder.h:74
A 32 bit integer in big endian aka network byte order.
Definition byteorder.h:84