libopencm3
A free/libre/open-source firmware library for various ARM Cortex-M3 microcontrollers.
|
#include <stdint.h>
#include <stdlib.h>
#include <string.h>
#include <libopencm3/cm3/common.h>
#include <libopencm3/usb/usbd.h>
#include <libopencm3/usb/msc.h>
#include "usb_private.h"
Go to the source code of this file.
Data Structures | |
struct | usb_msc_cbw |
struct | usb_msc_csw |
struct | sbc_sense_info |
struct | usb_msc_trans |
struct | _usbd_mass_storage |
Macros | |
#define | CBW_SIGNATURE 0x43425355 |
#define | CBW_STATUS_SUCCESS 0 |
#define | CBW_STATUS_FAILED 1 |
#define | CBW_STATUS_PHASE_ERROR 2 |
#define | CSW_SIGNATURE 0x53425355 |
#define | CSW_STATUS_SUCCESS 0 |
#define | CSW_STATUS_FAILED 1 |
#define | CSW_STATUS_PHASE_ERROR 2 |
#define | SCSI_TEST_UNIT_READY 0x00 |
#define | SCSI_REQUEST_SENSE 0x03 |
#define | SCSI_FORMAT_UNIT 0x04 |
#define | SCSI_READ_6 0x08 |
#define | SCSI_WRITE_6 0x0A |
#define | SCSI_INQUIRY 0x12 |
#define | SCSI_MODE_SENSE_6 0x1A |
#define | SCSI_SEND_DIAGNOSTIC 0x1D |
#define | SCSI_READ_CAPACITY 0x25 |
#define | SCSI_READ_10 0x28 |
#define | SCSI_REPORT_LUNS 0xA0 |
#define | SCSI_PREVENT_ALLOW_MEDIUM_REMOVAL 0x1E |
#define | SCSI_MODE_SELECT_6 0x15 |
#define | SCSI_MODE_SELECT_10 0x55 |
#define | SCSI_MODE_SENSE_10 0x5A |
#define | SCSI_READ_12 0xA8 |
#define | SCSI_READ_FORMAT_CAPACITIES 0x23 |
#define | SCSI_READ_TOC_PMA_ATIP 0x43 |
#define | SCSI_START_STOP_UNIT 0x1B |
#define | SCSI_SYNCHRONIZE_CACHE 0x35 |
#define | SCSI_VERIFY 0x2F |
#define | SCSI_WRITE_10 0x2A |
#define | SCSI_WRITE_12 0xAA |
Functions | |
static void | set_sbc_status (usbd_mass_storage *ms, enum sbc_sense_key key, enum sbc_asc asc, enum sbc_ascq ascq) |
static void | set_sbc_status_good (usbd_mass_storage *ms) |
static uint8_t * | get_cbw_buf (struct usb_msc_trans *trans) |
static void | scsi_read_6 (usbd_mass_storage *ms, struct usb_msc_trans *trans, enum trans_event event) |
static void | scsi_write_6 (usbd_mass_storage *ms, struct usb_msc_trans *trans, enum trans_event event) |
static void | scsi_write_10 (usbd_mass_storage *ms, struct usb_msc_trans *trans, enum trans_event event) |
static void | scsi_read_10 (usbd_mass_storage *ms, struct usb_msc_trans *trans, enum trans_event event) |
static void | scsi_read_capacity (usbd_mass_storage *ms, struct usb_msc_trans *trans, enum trans_event event) |
static void | scsi_format_unit (usbd_mass_storage *ms, struct usb_msc_trans *trans, enum trans_event event) |
static void | scsi_request_sense (usbd_mass_storage *ms, struct usb_msc_trans *trans, enum trans_event event) |
static void | scsi_mode_sense_6 (usbd_mass_storage *ms, struct usb_msc_trans *trans, enum trans_event event) |
static void | scsi_inquiry (usbd_mass_storage *ms, struct usb_msc_trans *trans, enum trans_event event) |
static void | scsi_command (usbd_mass_storage *ms, struct usb_msc_trans *trans, enum trans_event event) |
static void | msc_data_rx_cb (usbd_device *usbd_dev, uint8_t ep) |
Handle the USB 'OUT' requests. More... | |
static void | msc_data_tx_cb (usbd_device *usbd_dev, uint8_t ep) |
Handle the USB 'IN' requests. More... | |
static enum usbd_request_return_codes | msc_control_request (usbd_device *usbd_dev, struct usb_setup_data *req, uint8_t **buf, uint16_t *len, usbd_control_complete_callback *complete) |
Handle various control requests related to the msc storage interface. More... | |
static void | msc_set_config (usbd_device *usbd_dev, uint16_t wValue) |
Setup the endpoints to be bulk & register the callbacks. More... | |
usbd_mass_storage * | usb_msc_init (usbd_device *usbd_dev, uint8_t ep_in, uint8_t ep_in_size, uint8_t ep_out, uint8_t ep_out_size, const char *vendor_id, const char *product_id, const char *product_revision_level, const uint32_t block_count, int(*read_block)(uint32_t lba, uint8_t *copy_to), int(*write_block)(uint32_t lba, const uint8_t *copy_from)) |
Initializes the USB Mass Storage subsystem. More... | |
Variables | |
static usbd_mass_storage | _mass_storage |
static const uint8_t | _spc3_inquiry_response [36] |
static const uint8_t | _spc3_request_sense [18] |
enum sbc_asc |
enum sbc_ascq |
enum sbc_sense_key |
enum trans_event |
|
static |
Definition at line 254 of file usb_msc.c.
References usb_msc_trans::cbw, and usb_msc_cbw::CBWCB.
Referenced by scsi_inquiry(), scsi_read_10(), scsi_read_6(), scsi_write_10(), and scsi_write_6().
|
static |
Handle various control requests related to the msc storage interface.
Definition at line 737 of file usb_msc.c.
References usb_setup_data::bRequest, USB_MSC_REQ_BULK_ONLY_RESET, USB_MSC_REQ_GET_MAX_LUN, USBD_REQ_HANDLED, and USBD_REQ_NOTSUPP.
Referenced by msc_set_config().
|
static |
Handle the USB 'OUT' requests.
Definition at line 544 of file usb_msc.c.
References _mass_storage, usb_msc_trans::block_count, usb_msc_trans::byte_count, usb_msc_trans::bytes_to_read, usb_msc_trans::bytes_to_write, usb_msc_trans::cbw, usb_msc_trans::cbw_cnt, usb_msc_trans::csw_valid, usb_msc_trans::current_block, _usbd_mass_storage::ep_in, _usbd_mass_storage::ep_out_size, EVENT_CBW_VALID, EVENT_NEED_STATUS, usb_msc_trans::lba_start, _usbd_mass_storage::lock, usb_msc_trans::msd_buf, _usbd_mass_storage::read_block, scsi_command(), _usbd_mass_storage::trans, _usbd_mass_storage::unlock, usbd_ep_read_packet(), usbd_ep_write_packet(), and _usbd_mass_storage::write_block.
Referenced by msc_set_config().
|
static |
Handle the USB 'IN' requests.
Definition at line 669 of file usb_msc.c.
References _mass_storage, usb_msc_trans::block_count, usb_msc_trans::byte_count, usb_msc_trans::bytes_to_write, usb_msc_trans::csw_valid, usb_msc_trans::current_block, _usbd_mass_storage::ep_out_size, EVENT_NEED_STATUS, usb_msc_trans::lba_start, usb_msc_trans::msd_buf, _usbd_mass_storage::read_block, scsi_command(), _usbd_mass_storage::trans, _usbd_mass_storage::unlock, and usbd_ep_write_packet().
Referenced by msc_set_config().
|
static |
Setup the endpoints to be bulk & register the callbacks.
Definition at line 759 of file usb_msc.c.
References _mass_storage, _usbd_mass_storage::ep_in, _usbd_mass_storage::ep_in_size, _usbd_mass_storage::ep_out, _usbd_mass_storage::ep_out_size, msc_control_request(), msc_data_rx_cb(), msc_data_tx_cb(), USB_ENDPOINT_ATTR_BULK, USB_REQ_TYPE_CLASS, USB_REQ_TYPE_INTERFACE, USB_REQ_TYPE_RECIPIENT, USB_REQ_TYPE_TYPE, usbd_ep_setup(), and usbd_register_control_callback().
Referenced by usb_msc_init().
|
static |
Definition at line 479 of file usb_msc.c.
References usb_msc_csw::bCSWStatus, usb_msc_trans::byte_count, usb_msc_trans::bytes_to_read, usb_msc_trans::bytes_to_write, usb_msc_trans::cbw, usb_msc_cbw::CBWCB, usb_msc_trans::csw, usb_msc_trans::csw_sent, CSW_SIGNATURE, CSW_STATUS_FAILED, CSW_STATUS_SUCCESS, usb_msc_cbw::dCBWTag, usb_msc_csw::dCSWDataResidue, usb_msc_csw::dCSWSignature, usb_msc_csw::dCSWTag, EVENT_CBW_VALID, SBC_ASC_INVALID_COMMAND_OPERATION_CODE, SBC_ASCQ_NA, SBC_SENSE_KEY_ILLEGAL_REQUEST, SCSI_FORMAT_UNIT, scsi_format_unit(), SCSI_INQUIRY, scsi_inquiry(), SCSI_MODE_SENSE_6, scsi_mode_sense_6(), SCSI_READ_10, scsi_read_10(), SCSI_READ_6, scsi_read_6(), SCSI_READ_CAPACITY, scsi_read_capacity(), SCSI_REQUEST_SENSE, scsi_request_sense(), SCSI_SEND_DIAGNOSTIC, SCSI_TEST_UNIT_READY, SCSI_WRITE_10, scsi_write_10(), SCSI_WRITE_6, scsi_write_6(), set_sbc_status(), and set_sbc_status_good().
Referenced by msc_data_rx_cb(), and msc_data_tx_cb().
|
static |
Definition at line 363 of file usb_msc.c.
References _usbd_mass_storage::block_count, EVENT_CBW_VALID, usb_msc_trans::msd_buf, set_sbc_status_good(), and _usbd_mass_storage::write_block.
Referenced by scsi_command().
|
static |
Definition at line 438 of file usb_msc.c.
References _spc3_inquiry_response, usb_msc_trans::bytes_to_write, usb_msc_trans::csw, usb_msc_csw::dCSWDataResidue, EVENT_CBW_VALID, get_cbw_buf(), usb_msc_trans::msd_buf, _usbd_mass_storage::product_id, _usbd_mass_storage::product_revision_level, set_sbc_status_good(), and _usbd_mass_storage::vendor_id.
Referenced by scsi_command().
|
static |
Definition at line 399 of file usb_msc.c.
References usb_msc_csw::bCSWStatus, usb_msc_trans::bytes_to_write, usb_msc_trans::cbw, usb_msc_cbw::CBWCB, usb_msc_trans::csw, CSW_STATUS_FAILED, usb_msc_csw::dCSWDataResidue, EVENT_CBW_VALID, usb_msc_trans::msd_buf, SBC_ASC_INVALID_FIELD_IN_CDB, SBC_ASCQ_NA, SBC_SENSE_KEY_ILLEGAL_REQUEST, and set_sbc_status().
Referenced by scsi_command().
|
static |
Definition at line 321 of file usb_msc.c.
References usb_msc_trans::block_count, usb_msc_trans::bytes_to_write, EVENT_CBW_VALID, get_cbw_buf(), usb_msc_trans::lba_start, and set_sbc_status_good().
Referenced by scsi_command().
|
static |
Definition at line 259 of file usb_msc.c.
References usb_msc_trans::block_count, usb_msc_trans::bytes_to_write, usb_msc_trans::current_block, EVENT_CBW_VALID, get_cbw_buf(), usb_msc_trans::lba_start, and set_sbc_status_good().
Referenced by scsi_command().
|
static |
Definition at line 343 of file usb_msc.c.
References _usbd_mass_storage::block_count, usb_msc_trans::bytes_to_write, EVENT_CBW_VALID, usb_msc_trans::msd_buf, and set_sbc_status_good().
Referenced by scsi_command().
|
static |
Definition at line 380 of file usb_msc.c.
References _spc3_request_sense, sbc_sense_info::asc, sbc_sense_info::ascq, usb_msc_trans::bytes_to_write, usb_msc_trans::cbw, usb_msc_cbw::CBWCB, EVENT_CBW_VALID, sbc_sense_info::key, usb_msc_trans::msd_buf, and _usbd_mass_storage::sense.
Referenced by scsi_command().
|
static |
Definition at line 301 of file usb_msc.c.
References usb_msc_trans::block_count, usb_msc_trans::bytes_to_read, usb_msc_trans::current_block, EVENT_CBW_VALID, get_cbw_buf(), and usb_msc_trans::lba_start.
Referenced by scsi_command().
|
static |
Definition at line 281 of file usb_msc.c.
References usb_msc_trans::block_count, usb_msc_trans::bytes_to_read, usb_msc_trans::current_block, EVENT_CBW_VALID, get_cbw_buf(), and usb_msc_trans::lba_start.
Referenced by scsi_command().
|
static |
Definition at line 236 of file usb_msc.c.
References sbc_sense_info::asc, sbc_sense_info::ascq, sbc_sense_info::key, and _usbd_mass_storage::sense.
Referenced by scsi_command(), scsi_mode_sense_6(), and set_sbc_status_good().
|
static |
Definition at line 246 of file usb_msc.c.
References SBC_ASC_NO_ADDITIONAL_SENSE_INFORMATION, SBC_ASCQ_NA, SBC_SENSE_KEY_NO_SENSE, and set_sbc_status().
Referenced by scsi_command(), scsi_format_unit(), scsi_inquiry(), scsi_read_10(), scsi_read_6(), scsi_read_capacity(), and usb_msc_init().
|
static |
Definition at line 195 of file usb_msc.c.
Referenced by msc_data_rx_cb(), msc_data_tx_cb(), msc_set_config(), and usb_msc_init().
|
static |
Definition at line 199 of file usb_msc.c.
Referenced by scsi_inquiry().
|
static |
Definition at line 217 of file usb_msc.c.
Referenced by scsi_request_sense().