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
9#pragma once
10
21
22#include "byteorder.h"
23
24#ifdef __cplusplus
25extern "C" {
26#endif
27
28#ifndef USBUS_MSC_VENDOR_ID
29#define USBUS_MSC_VENDOR_ID "RIOT-OS"
30#endif /* USBUS_MSC_VENDOR_ID */
31
32#ifndef USBUS_MSC_PRODUCT_ID
33#define USBUS_MSC_PRODUCT_ID "RIOT_MSC_DISK "
34#endif /* USBUS_MSC_PRODUCT_ID */
35
36#ifndef USBUS_MSC_PRODUCT_REV
37#define USBUS_MSC_PRODUCT_REV " 1.0"
38#endif /* USBUS_MSC_PRODUCT_REV */
39
47#define SCSI_TEST_UNIT_READY 0x00
48#define SCSI_REQUEST_SENSE 0x03
49#define SCSI_FORMAT_UNIT 0x04
50#define SCSI_INQUIRY 0x12
51#define SCSI_MODE_SELECT6 0x15
52#define SCSI_MODE_SENSE6 0x1A
53#define SCSI_START_STOP_UNIT 0x1B
54#define SCSI_MEDIA_REMOVAL 0x1E
55#define SCSI_READ_FORMAT_CAPACITIES 0x23
56#define SCSI_READ_CAPACITY 0x25
57#define SCSI_READ10 0x28
58#define SCCI_READ12 0xA8
59#define SCSI_WRITE10 0x2A
60#define SCSI_WRITE12 0xAA
61#define SCSI_SEEK 0x2B
62#define SCSI_WRITE_AND_VERIFY 0x2E
63#define SCSI_VERIFY10 0x2F
64#define SCSI_MODE_SELECT10 0x55
65#define SCSI_MODE_SENSE10 0x5A
67
71#define SCSI_CBW_SIGNATURE 0x43425355
72
76#define SCSI_CSW_SIGNATURE 0x53425355
77
82#define SCSI_VERSION_NONE 0x0000
83#define SCSI_VERSION_SCSI1 0x0001
84#define SCSI_VERSION_SCSI2 0x0002
86
93#define SCSI_READ_FMT_CAPA_TYPE_RESERVED 0x00
94#define SCSI_READ_FMT_CAPA_TYPE_UNFORMATTED 0x01
95#define SCSI_READ_FMT_CAPA_TYPE_FORMATTED 0x02
96#define SCSI_READ_FMT_CAPA_TYPE_NO_MEDIA 0x03
98
102#define SCSI_REQUEST_SENSE_ERROR 0x70
103
109#define SCSI_SENSE_KEY_NO_SENSE 0x00
110#define SCSI_SENSE_KEY_RECOVERED_ERROR 0x01
111#define SCSI_SENSE_KEY_NOT_READY 0x02
112#define SCSI_SENSE_KEY_MEDIUM_ERROR 0x03
113#define SCSI_SENSE_KEY_HARDWARE_ERROR 0x04
114#define SCSI_SENSE_KEY_ILLEGAL_REQUEST 0x05
115#define SCSI_SENSE_KEY_UNIT_ATTENTION 0x06
116#define SCSI_SENSE_KEY_DATA_PROTECT 0x07
117#define SCSI_SENSE_KEY_BLANK_CHECK 0x08
118#define SCSI_SENSE_KEY_VENDOR_SPECIFIC 0x09
119#define SCSI_SENSE_KEY_ABORTED_COMMAND 0x0B
120#define SCSI_SENSE_KEY_VOLUME_OVERFLOW 0x0D
121#define SCSI_SENSE_KEY_MISCOMPARE 0x0E
123
129typedef struct __attribute__((packed)) {
130 uint8_t type;
131 uint8_t logical_unit;
132 uint8_t reserved[10];
134
141typedef struct __attribute__((packed)) {
143 uint8_t medium_type;
144 uint8_t flags;
147
156typedef struct __attribute__((packed)) {
157 uint8_t opcode;
158 uint8_t flags;
160 uint8_t group_number;
163
172typedef struct __attribute__((packed)) {
173 uint8_t type;
174 uint8_t reserved1 : 7;
175 uint8_t removable : 1;
176 uint8_t version;
177 uint8_t response_format : 4;
178 uint8_t reserved3 : 4;
179 uint8_t length;
180 uint8_t flags[3];
181 uint8_t vendor_id[8];
182 uint8_t product_id[16];
183 uint8_t product_rev[4];
185
192typedef struct __attribute__((packed)) {
193 uint8_t reserved1[3];
194 uint8_t list_length;
196 uint8_t type;
197 uint8_t blk_len[3];
199
204typedef struct __attribute__((packed)) {
205 uint8_t error_code;
206 uint8_t reserved1;
207 uint8_t sense_key;
208 uint8_t reserved2[4];
209 uint8_t add_len;
210 uint8_t reserved3[4];
211 uint8_t asc;
212 uint8_t ascq;
213 uint8_t fruc;
214 uint16_t sk_spec;
216
225typedef struct __attribute__((packed)) {
229
236typedef struct __attribute__((packed)) {
237 uint32_t signature;
238 uint32_t tag;
239 uint32_t data_len;
240 uint8_t flags;
241 uint8_t lun;
242 uint8_t cb_len;
243 uint8_t cb[16];
245
252typedef struct __attribute__((packed)) {
253 uint32_t signature;
254 uint32_t tag;
255 uint32_t data_left;
256 uint8_t status;
258
263typedef struct {
264 uint32_t tag;
265 size_t len;
266 uint8_t status;
267 uint8_t lun;
268} cbw_info_t;
269
279 size_t len);
280
288
289#ifdef __cplusplus
290}
291#endif
292
Functions to work with different byte orders.
struct usbdev_ep usbdev_ep_t
usbdev_ep_t forward declaration
Definition usbdev.h:99
struct usbus_handler usbus_handler_t
USBUS event handler forward declaration.
Definition usbus.h:223
struct usbus usbus_t
USBUS context forward declaration.
Definition usbus.h:218
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:263
uint8_t status
Status of the current operation.
Definition scsi.h:266
size_t len
Remaining bytes to handle.
Definition scsi.h:265
uint8_t lun
Store LUN from CBW.
Definition scsi.h:267
uint32_t tag
Store tag information from CBW.
Definition scsi.h:264
Command Block Wrapper packet structure.
Definition scsi.h:236
uint32_t tag
ID for the current command.
Definition scsi.h:238
uint32_t signature
CBW signature (SCSI_CBW_SIGNATURE)
Definition scsi.h:237
uint8_t lun
Target Logical Unit Number.
Definition scsi.h:241
uint32_t data_len
Number of bytes host expects to transfer from/to.
Definition scsi.h:239
uint8_t cb[16]
Command block buffer.
Definition scsi.h:243
uint8_t flags
Command block flags.
Definition scsi.h:240
uint8_t cb_len
Length of the block in bytes (max: 16 bytes)
Definition scsi.h:242
CBW Packet structure for (SCSI_READ10) and (SCSI_WRITE10) requests.
Definition scsi.h:156
uint8_t group_number
Group number.
Definition scsi.h:160
uint8_t flags
Miscellaneous flags.
Definition scsi.h:158
be_uint32_t blk_addr
Block address.
Definition scsi.h:159
be_uint16_t xfer_len
Transfer length in bytes.
Definition scsi.h:161
uint8_t opcode
Operation code.
Definition scsi.h:157
Command Status Wrapper packet structure.
Definition scsi.h:252
uint32_t signature
CSW signature (SCSI_CSW_SIGNATURE)
Definition scsi.h:253
uint8_t status
Status of the command.
Definition scsi.h:256
uint32_t tag
ID for the answered CBW.
Definition scsi.h:254
uint32_t data_left
Indicate how many bytes from the CBW were not processed.
Definition scsi.h:255
Packet structure to answer (SCSI_INQUIRY) request.
Definition scsi.h:172
uint8_t product_rev[4]
Byte 35..32 Product Revision.
Definition scsi.h:183
uint8_t vendor_id[8]
Byte 15..8 Vendor Identification.
Definition scsi.h:181
uint8_t length
Byte 4 Additional Length (n-4)
Definition scsi.h:179
uint8_t removable
Byte 1 [B7] Removable device flag.
Definition scsi.h:175
uint8_t product_id[16]
Byte 31..16 Product Identification.
Definition scsi.h:182
uint8_t type
Byte 0 Peripheral type.
Definition scsi.h:173
uint8_t reserved1
Byte 1 [B6..B0] Reserved.
Definition scsi.h:174
uint8_t flags[3]
Byte 7..5 Miscellaneous flags UNUSED BY USBUS ONLY.
Definition scsi.h:180
uint8_t reserved3
Byte 3 [B7..B4] Reserved.
Definition scsi.h:178
uint8_t response_format
Byte 3 [B3..B0] Response Data Format.
Definition scsi.h:177
uint8_t version
Byte 2 SCSI Version.
Definition scsi.h:176
Packet structure to answer (SCSI_MODE_SELECT6) and (SCSI_MODE_SENSE6) requests.
Definition scsi.h:141
uint8_t medium_type
Type of medium.
Definition scsi.h:143
uint8_t mode_data_len
Size of the whole packet.
Definition scsi.h:142
uint8_t flags
Miscellaneous flags.
Definition scsi.h:144
uint8_t block_desc_len
Length of block descriptor.
Definition scsi.h:145
Packet structure to answer (SCSI_READ_CAPACITY) request.
Definition scsi.h:225
be_uint32_t last_blk
Indicate last block number.
Definition scsi.h:226
be_uint32_t blk_len
Total size of a block in bytes.
Definition scsi.h:227
Packet structure to answer (SCSI_READ_FORMAT_CAPACITIES) request.
Definition scsi.h:192
uint8_t type
Byte 8 Descriptor type.
Definition scsi.h:196
uint8_t blk_len[3]
Byte 11..9 Block length.
Definition scsi.h:197
uint8_t reserved1[3]
Byte 2..0 reserved.
Definition scsi.h:193
be_uint32_t blk_nb
Byte 7..4 Number of blocks.
Definition scsi.h:195
uint8_t list_length
Byte 3 Capacity list length.
Definition scsi.h:194
Packet structure to answer (SCSI_REQUEST_SENSE) request.
Definition scsi.h:204
uint8_t reserved2[4]
Byte 6..3 Information.
Definition scsi.h:208
uint16_t sk_spec
Byte 16..15 Sense Key Specific.
Definition scsi.h:214
uint8_t fruc
Byte 14 Field Replaceable Unit Code.
Definition scsi.h:213
uint8_t asc
Byte 12 Additional Sense Code.
Definition scsi.h:211
uint8_t ascq
Byte 13 Additional Sense Code Qualifier.
Definition scsi.h:212
uint8_t sense_key
Byte 2 Sense key.
Definition scsi.h:207
uint8_t reserved1
Reserved.
Definition scsi.h:206
uint8_t reserved3[4]
Byte 11..8 Vendor specific.
Definition scsi.h:210
uint8_t error_code
Byte 0 Error code.
Definition scsi.h:205
uint8_t add_len
Byte 7 Additional sense length.
Definition scsi.h:209
Packet structure to answer (SCSI_TEST_UNIT_READY) request.
Definition scsi.h:129
uint8_t reserved[10]
Reserved.
Definition scsi.h:132
uint8_t type
type of device
Definition scsi.h:130
uint8_t logical_unit
Selected LUN.
Definition scsi.h:131
USBUS context struct.
Definition usbus.h:447
A 16 bit integer in big endian aka network byte order.
Definition byteorder.h:73
A 32 bit integer in big endian aka network byte order.
Definition byteorder.h:83