20#ifndef USB_USBUS_MSC_SCSI_H
21#define USB_USBUS_MSC_SCSI_H
29#ifndef USBUS_MSC_VENDOR_ID
30#define USBUS_MSC_VENDOR_ID "RIOT-OS"
33#ifndef USBUS_MSC_PRODUCT_ID
34#define USBUS_MSC_PRODUCT_ID "RIOT_MSC_DISK "
37#ifndef USBUS_MSC_PRODUCT_REV
38#define USBUS_MSC_PRODUCT_REV " 1.0"
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
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
77#define SCSI_CSW_SIGNATURE 0x53425355
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
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)) {
133 uint8_t reserved[10];
142typedef struct __attribute__((packed)) {
157typedef struct __attribute__((packed)) {
173typedef struct __attribute__((packed)) {
182 uint8_t vendor_id[8];
183 uint8_t product_id[16];
184 uint8_t product_rev[4];
193typedef struct __attribute__((packed)) {
194 uint8_t reserved1[3];
205typedef struct __attribute__((packed)) {
209 uint8_t reserved2[4];
211 uint8_t reserved3[4];
226typedef struct __attribute__((packed)) {
237typedef struct __attribute__((packed)) {
253typedef struct __attribute__((packed)) {
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.
uint8_t status
Status of the current operation.
size_t len
Remaining bytes to handle.
uint8_t lun
Store LUN from CBW.
uint32_t tag
Store tag information from CBW.
Command Block Wrapper packet structure.
uint32_t tag
ID for the current command.
uint32_t signature
CBW signature (SCSI_CBW_SIGNATURE)
uint8_t lun
Target Logical Unit Number.
uint32_t data_len
Number of bytes host expects to transfer from/to.
uint8_t flags
Command block flags.
uint8_t cb_len
Length of the block in bytes (max: 16 bytes)
CBW Packet structure for (SCSI_READ10) and (SCSI_WRITE10) requests.
uint8_t group_number
Group number.
uint8_t flags
Miscellaneous flags.
be_uint32_t blk_addr
Block address.
be_uint16_t xfer_len
Transfer length in bytes.
uint8_t opcode
Operation code.
Command Status Wrapper packet structure.
uint32_t signature
CSW signature (SCSI_CSW_SIGNATURE)
uint8_t status
Status of the command.
uint32_t tag
ID for the answered CBW.
uint32_t data_left
Indicate how many bytes from the CBW were not processed.
Packet structure to answer (SCSI_INQUIRY) request.
uint8_t length
Byte 4 Additional Length (n-4)
uint8_t removable
Byte 1 [B7] Removable device flag.
uint8_t type
Byte 0 Peripheral type.
uint8_t reserved1
Byte 1 [B6..B0] Reserved.
uint8_t reserved3
Byte 3 [B7..B4] Reserved.
uint8_t response_format
Byte 3 [B3..B0] Response Data Format.
uint8_t version
Byte 2 SCSI Version.
Packet structure to answer (SCSI_MODE_SELECT6) and (SCSI_MODE_SENSE6) requests.
uint8_t medium_type
Type of medium.
uint8_t mode_data_len
Size of the whole packet.
uint8_t flags
Miscellaneous flags.
uint8_t block_desc_len
Length of block descriptor.
Packet structure to answer (SCSI_READ_CAPACITY) request.
be_uint32_t last_blk
Indicate last block number.
be_uint32_t blk_len
Total size of a block in bytes.
Packet structure to answer (SCSI_READ_FORMAT_CAPACITIES) request.
uint8_t type
Byte 8 Descriptor type.
be_uint32_t blk_nb
Byte 7..4 Number of blocks.
uint8_t list_length
Byte 3 Capacity list length.
Packet structure to answer (SCSI_REQUEST_SENSE) request.
uint16_t sk_spec
Byte 16..15 Sense Key Specific.
uint8_t fruc
Byte 14 Field Replaceable Unit Code.
uint8_t asc
Byte 12 Additional Sense Code.
uint8_t ascq
Byte 13 Additional Sense Code Qualifier.
uint8_t sense_key
Byte 2 Sense key.
uint8_t reserved1
Reserved.
uint8_t error_code
Byte 0 Error code.
uint8_t add_len
Byte 7 Additional sense length.
Packet structure to answer (SCSI_TEST_UNIT_READY) request.
uint8_t type
type of device
uint8_t logical_unit
Selected LUN.
usbdev endpoint descriptor
A 16 bit integer in big endian aka network byte order.
A 32 bit integer in big endian aka network byte order.