Paparazzi UAS  v5.14.0_stable-0-g3f680d1
Paparazzi is a free software Unmanned Aircraft System.
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
usb_msd.c File Reference
+ Include dependency graph for usb_msd.c:

Go to the source code of this file.

Data Structures

struct  PACK_STRUCT_STRUCT
 Response to a READ_CAPACITY_10 SCSI command. More...
 
struct  PACK_STRUCT_STRUCT
 Response to a READ_CAPACITY_10 SCSI command. More...
 

Macros

#define MSD_REQ_RESET   0xFF
 
#define MSD_GET_MAX_LUN   0xFE
 
#define MSD_CBW_SIGNATURE   0x43425355
 
#define MSD_CSW_SIGNATURE   0x53425355
 
#define MSD_SETUP_WORD(setup, index)   (uint16_t)(((uint16_t)setup[index + 1] << 8) | (setup[index] & 0x00FF))
 
#define MSD_SETUP_VALUE(setup)   MSD_SETUP_WORD(setup, 2)
 
#define MSD_SETUP_INDEX(setup)   MSD_SETUP_WORD(setup, 4)
 
#define MSD_SETUP_LENGTH(setup)   MSD_SETUP_WORD(setup, 6)
 
#define MSD_COMMAND_PASSED   0x00
 
#define MSD_COMMAND_FAILED   0x01
 
#define MSD_COMMAND_PHASE_ERROR   0x02
 
#define SCSI_CMD_TEST_UNIT_READY   0x00
 
#define SCSI_CMD_REQUEST_SENSE   0x03
 
#define SCSI_CMD_FORMAT_UNIT   0x04
 
#define SCSI_CMD_INQUIRY   0x12
 
#define SCSI_CMD_MODE_SENSE_6   0x1A
 
#define SCSI_CMD_START_STOP_UNIT   0x1B
 
#define SCSI_CMD_SEND_DIAGNOSTIC   0x1D
 
#define SCSI_CMD_PREVENT_ALLOW_MEDIUM_REMOVAL   0x1E
 
#define SCSI_CMD_READ_FORMAT_CAPACITIES   0x23
 
#define SCSI_CMD_READ_CAPACITY_10   0x25
 
#define SCSI_CMD_READ_10   0x28
 
#define SCSI_CMD_WRITE_10   0x2A
 
#define SCSI_CMD_VERIFY_10   0x2F
 
#define SCSI_SENSE_KEY_GOOD   0x00
 
#define SCSI_SENSE_KEY_RECOVERED_ERROR   0x01
 
#define SCSI_SENSE_KEY_NOT_READY   0x02
 
#define SCSI_SENSE_KEY_MEDIUM_ERROR   0x03
 
#define SCSI_SENSE_KEY_HARDWARE_ERROR   0x04
 
#define SCSI_SENSE_KEY_ILLEGAL_REQUEST   0x05
 
#define SCSI_SENSE_KEY_UNIT_ATTENTION   0x06
 
#define SCSI_SENSE_KEY_DATA_PROTECT   0x07
 
#define SCSI_SENSE_KEY_BLANK_CHECK   0x08
 
#define SCSI_SENSE_KEY_VENDOR_SPECIFIC   0x09
 
#define SCSI_SENSE_KEY_COPY_ABORTED   0x0A
 
#define SCSI_SENSE_KEY_ABORTED_COMMAND   0x0B
 
#define SCSI_SENSE_KEY_VOLUME_OVERFLOW   0x0D
 
#define SCSI_SENSE_KEY_MISCOMPARE   0x0E
 
#define SCSI_ASENSE_NO_ADDITIONAL_INFORMATION   0x00
 
#define SCSI_ASENSE_WRITE_FAULT   0x03
 
#define SCSI_ASENSE_LOGICAL_UNIT_NOT_READY   0x04
 
#define SCSI_ASENSE_READ_ERROR   0x11
 
#define SCSI_ASENSE_INVALID_COMMAND   0x20
 
#define SCSI_ASENSE_LOGICAL_BLOCK_ADDRESS_OUT_OF_RANGE   0x21
 
#define SCSI_ASENSE_INVALID_FIELD_IN_CDB   0x24
 
#define SCSI_ASENSE_WRITE_PROTECTED   0x27
 
#define SCSI_ASENSE_NOT_READY_TO_READY_CHANGE   0x28
 
#define SCSI_ASENSE_FORMAT_ERROR   0x31
 
#define SCSI_ASENSE_MEDIUM_NOT_PRESENT   0x3A
 
#define SCSI_ASENSEQ_NO_QUALIFIER   0x00
 
#define SCSI_ASENSEQ_FORMAT_COMMAND_FAILED   0x01
 
#define SCSI_ASENSEQ_INITIALIZING_COMMAND_REQUIRED   0x02
 
#define SCSI_ASENSEQ_OPERATION_IN_PROGRESS   0x07
 

Typedefs

typedef uint32_t DWORD
 
typedef uint16_t WORD
 

Functions

static THD_WORKING_AREA (mass_storage_thread_wa, 1024)
 
static void mass_storage_thread (void *arg)
 Mass storage thread that processes commands. More...
 
void debug_snd_evt_i (eventmask_t evt)
 
void debug_snd_evt_inl (eventmask_t evt)
 
void debug_snd_evt_nl (eventmask_t evt)
 
static uint8_t IN_DMA_SECTION_CLEAR (rw_buf[2][512])
 Read-write buffers (TODO: need a way of specifying the size of this) More...
 
static DWORD swap_uint32 (const DWORD val)
 Byte-swap a 32 bits unsigned integer. More...
 
static WORD swap_uint16 (const WORD val)
 Byte-swap a 16 bits unsigned integer. More...
 
static void msd_handle_end_point_notification (USBDriver *usbp, usbep_t ep)
 Called when data can be read or written on the endpoint – wakes the thread up. More...
 
void msdConfigureHookI (USBMassStorageDriver *msdp)
 USB device configured handler. More...
 
bool msdRequestsHook (USBDriver *usbp)
 Default requests hook. More...
 
static void msd_wait_for_isr (USBMassStorageDriver *msdp)
 Wait until the end-point interrupt handler has been called. More...
 
static void msd_start_transmit (USBMassStorageDriver *msdp, const uint8_t *buffer, size_t size)
 Starts sending data. More...
 
static void msd_start_receive (USBMassStorageDriver *msdp, uint8_t *buffer, size_t size)
 Starts receiving data. More...
 
static void msd_scsi_set_sense (USBMassStorageDriver *msdp, uint8_t key, uint8_t acode, uint8_t aqual)
 Changes the SCSI sense information. More...
 
bool msd_scsi_process_inquiry (USBMassStorageDriver *msdp)
 Processes an INQUIRY SCSI command. More...
 
bool msd_scsi_process_request_sense (USBMassStorageDriver *msdp)
 Processes a REQUEST_SENSE SCSI command. More...
 
bool msd_scsi_process_read_capacity_10 (USBMassStorageDriver *msdp)
 Processes a READ_CAPACITY_10 SCSI command. More...
 
bool msd_scsi_process_send_diagnostic (USBMassStorageDriver *msdp)
 Processes a SEND_DIAGNOSTIC SCSI command. More...
 
bool msd_scsi_process_start_read_write_10 (USBMassStorageDriver *msdp)
 Processes a READ_WRITE_10 SCSI command. More...
 
bool msd_scsi_process_start_stop_unit (USBMassStorageDriver *msdp)
 Processes a START_STOP_UNIT SCSI command. More...
 
bool msd_scsi_process_mode_sense_6 (USBMassStorageDriver *msdp)
 Processes a MODE_SENSE_6 SCSI command. More...
 
bool msd_scsi_process_read_format_capacities (USBMassStorageDriver *msdp)
 Processes a READ_FORMAT_CAPACITIES SCSI command. More...
 
bool msd_scsi_process_test_unit_ready (USBMassStorageDriver *msdp)
 Processes a TEST_UNIT_READY SCSI command. More...
 
bool msd_wait_for_command_block (USBMassStorageDriver *msdp)
 Waits for a new command block. More...
 
bool msd_read_command_block (USBMassStorageDriver *msdp)
 Reads a newly received command block. More...
 
void msdInit (USBMassStorageDriver *msdp)
 Initializse a USB mass storage driver. More...
 
void msdStart (USBMassStorageDriver *msdp, const USBMassStorageConfig *config)
 Starts a USB mass storage driver. More...
 
void msdStop (USBMassStorageDriver *msdp)
 Stops a USB mass storage driver. More...
 
static void usbEvent (USBDriver *usbp, usbevent_t event)
 
static const USBDescriptor * getDescriptor (USBDriver *usbp, uint8_t type, uint8_t index, uint16_t lang)
 
void deinit_msd_driver (void)
 
void init_msd_driver (void *dbgThreadPtr, USBMassStorageConfig *msdConfig)
 
void msd_register_evt_connected (event_listener_t *elp, eventmask_t mask)
 register connected event source in local event mask More...
 
void msd_register_evt_ejected (event_listener_t *elp, eventmask_t mask)
 register ejected event source in local event mask More...
 

Variables

static USBMassStorageDriver UMSD
 
thread_t * dbg_printer = NULL
 
static USBInEndpointState ep1_in_state
 IN end-point 1 state. More...
 
static USBOutEndpointState ep1_out_state
 OUT end-point 1 state. More...
 
static const USBEndpointConfig ep_data_config
 End-point 1 initialization structure. More...
 
static const uint8_t deviceDescriptorData []
 
static const USBDescriptor deviceDescriptor
 
static const uint8_t configurationDescriptorData []
 
static const USBDescriptor configurationDescriptor
 
static const uint8_t languageDescriptorData []
 
static const USBDescriptor languageDescriptor
 
static const uint8_t vendorDescriptorData []
 
static const USBDescriptor vendorDescriptor
 
static const uint8_t productDescriptorData []
 
static const USBDescriptor productDescriptor
 
static const uint8_t serialNumberDescriptorData []
 
static const USBDescriptor serialNumberDescriptor
 
static const USBConfig usbConfig
 

Data Structure Documentation

struct PACK_STRUCT_STRUCT

Response to a READ_CAPACITY_10 SCSI command.

structure holding the data to reply to an INQUIRY SCSI command

Structure holding sense data (status/error information)

Command Status Wrapper structure.

Command Block Wrapper structure.

Response to a READ_FORMAT_CAPACITIES SCSI command.

Definition at line 113 of file usb_msd.c.

Data Fields
uint8_t additional_length
uint32_t block_count
uint32_t block_size
uint8_t bqueetc
uint8_t byte[18]
uint8_t capacity_list_length
uint8_t cmdque
uint32_t data_len
uint32_t data_residue
uint32_t desc_and_block_length
uint8_t flags
uint32_t last_block_addr
uint8_t lun
uint8_t peripheral
uint8_t product_id[16]
uint8_t product_rev[4]
uint8_t removable
uint8_t reserved[3]
uint8_t response_data_format
uint8_t sccstp
uint8_t scsi_cmd_data[16]
uint8_t scsi_cmd_len
uint32_t signature
uint8_t status
uint32_t tag
uint8_t vendor_id[8]
uint8_t version
struct PACK_STRUCT_STRUCT

Response to a READ_CAPACITY_10 SCSI command.

structure holding the data to reply to an INQUIRY SCSI command

Structure holding sense data (status/error information)

Command Status Wrapper structure.

Command Block Wrapper structure.

Response to a READ_FORMAT_CAPACITIES SCSI command.

Definition at line 113 of file usb_msd.c.

Data Fields
uint8_t additional_length
uint32_t block_count
uint32_t block_size
uint8_t bqueetc
uint8_t byte[18]
uint8_t capacity_list_length
uint8_t cmdque
uint32_t data_len
uint32_t data_residue
uint32_t desc_and_block_length
uint8_t flags
uint32_t last_block_addr
uint8_t lun
uint8_t peripheral
uint8_t product_id[16]
uint8_t product_rev[4]
uint8_t removable
uint8_t reserved[3]
uint8_t response_data_format
uint8_t sccstp
uint8_t scsi_cmd_data[16]
uint8_t scsi_cmd_len
uint32_t signature
uint8_t status
uint32_t tag
uint8_t vendor_id[8]
uint8_t version

Macro Definition Documentation

#define MSD_CBW_SIGNATURE   0x43425355

Definition at line 39 of file usb_msd.c.

Referenced by msd_read_command_block().

#define MSD_COMMAND_FAILED   0x01

Definition at line 50 of file usb_msd.c.

Referenced by msd_read_command_block().

#define MSD_COMMAND_PASSED   0x00

Definition at line 49 of file usb_msd.c.

Referenced by msd_read_command_block().

#define MSD_COMMAND_PHASE_ERROR   0x02

Definition at line 51 of file usb_msd.c.

#define MSD_CSW_SIGNATURE   0x53425355

Definition at line 40 of file usb_msd.c.

Referenced by msd_read_command_block().

#define MSD_GET_MAX_LUN   0xFE

Definition at line 36 of file usb_msd.c.

Referenced by msdRequestsHook().

#define MSD_REQ_RESET   0xFF

Definition at line 35 of file usb_msd.c.

Referenced by msdRequestsHook().

#define MSD_SETUP_INDEX (   setup)    MSD_SETUP_WORD(setup, 4)

Definition at line 45 of file usb_msd.c.

Referenced by msdRequestsHook().

#define MSD_SETUP_LENGTH (   setup)    MSD_SETUP_WORD(setup, 6)

Definition at line 46 of file usb_msd.c.

Referenced by msdRequestsHook().

#define MSD_SETUP_VALUE (   setup)    MSD_SETUP_WORD(setup, 2)

Definition at line 44 of file usb_msd.c.

Referenced by msdRequestsHook().

#define MSD_SETUP_WORD (   setup,
  index 
)    (uint16_t)(((uint16_t)setup[index + 1] << 8) | (setup[index] & 0x00FF))

Definition at line 43 of file usb_msd.c.

#define SCSI_ASENSE_FORMAT_ERROR   0x31

Definition at line 93 of file usb_msd.c.

#define SCSI_ASENSE_INVALID_COMMAND   0x20

Definition at line 88 of file usb_msd.c.

Referenced by msd_read_command_block().

#define SCSI_ASENSE_INVALID_FIELD_IN_CDB   0x24
#define SCSI_ASENSE_LOGICAL_BLOCK_ADDRESS_OUT_OF_RANGE   0x21

Definition at line 89 of file usb_msd.c.

Referenced by msd_scsi_process_start_read_write_10().

#define SCSI_ASENSE_LOGICAL_UNIT_NOT_READY   0x04

Definition at line 86 of file usb_msd.c.

#define SCSI_ASENSE_MEDIUM_NOT_PRESENT   0x3A

Definition at line 94 of file usb_msd.c.

Referenced by msd_scsi_process_test_unit_ready().

#define SCSI_ASENSE_NO_ADDITIONAL_INFORMATION   0x00
#define SCSI_ASENSE_NOT_READY_TO_READY_CHANGE   0x28

Definition at line 92 of file usb_msd.c.

#define SCSI_ASENSE_READ_ERROR   0x11

Definition at line 87 of file usb_msd.c.

Referenced by msd_scsi_process_start_read_write_10().

#define SCSI_ASENSE_WRITE_FAULT   0x03

Definition at line 85 of file usb_msd.c.

Referenced by msd_scsi_process_start_read_write_10().

#define SCSI_ASENSE_WRITE_PROTECTED   0x27

Definition at line 91 of file usb_msd.c.

Referenced by msd_scsi_process_start_read_write_10().

#define SCSI_ASENSEQ_FORMAT_COMMAND_FAILED   0x01

Definition at line 97 of file usb_msd.c.

#define SCSI_ASENSEQ_INITIALIZING_COMMAND_REQUIRED   0x02

Definition at line 98 of file usb_msd.c.

#define SCSI_ASENSEQ_OPERATION_IN_PROGRESS   0x07

Definition at line 99 of file usb_msd.c.

#define SCSI_CMD_FORMAT_UNIT   0x04

Definition at line 56 of file usb_msd.c.

Referenced by msd_read_command_block().

#define SCSI_CMD_INQUIRY   0x12

Definition at line 57 of file usb_msd.c.

Referenced by msd_read_command_block().

#define SCSI_CMD_MODE_SENSE_6   0x1A

Definition at line 58 of file usb_msd.c.

Referenced by msd_read_command_block().

#define SCSI_CMD_PREVENT_ALLOW_MEDIUM_REMOVAL   0x1E

Definition at line 61 of file usb_msd.c.

Referenced by msd_read_command_block().

#define SCSI_CMD_READ_10   0x28

Definition at line 64 of file usb_msd.c.

Referenced by msd_read_command_block().

#define SCSI_CMD_READ_CAPACITY_10   0x25

Definition at line 63 of file usb_msd.c.

Referenced by msd_read_command_block().

#define SCSI_CMD_READ_FORMAT_CAPACITIES   0x23

Definition at line 62 of file usb_msd.c.

Referenced by msd_read_command_block().

#define SCSI_CMD_REQUEST_SENSE   0x03

Definition at line 55 of file usb_msd.c.

Referenced by msd_read_command_block().

#define SCSI_CMD_SEND_DIAGNOSTIC   0x1D

Definition at line 60 of file usb_msd.c.

Referenced by msd_read_command_block().

#define SCSI_CMD_START_STOP_UNIT   0x1B

Definition at line 59 of file usb_msd.c.

Referenced by msd_read_command_block().

#define SCSI_CMD_TEST_UNIT_READY   0x00

Definition at line 54 of file usb_msd.c.

Referenced by msd_read_command_block().

#define SCSI_CMD_VERIFY_10   0x2F

Definition at line 66 of file usb_msd.c.

Referenced by msd_read_command_block().

#define SCSI_CMD_WRITE_10   0x2A

Definition at line 65 of file usb_msd.c.

Referenced by msd_read_command_block(), and msd_scsi_process_start_read_write_10().

#define SCSI_SENSE_KEY_ABORTED_COMMAND   0x0B

Definition at line 80 of file usb_msd.c.

#define SCSI_SENSE_KEY_BLANK_CHECK   0x08

Definition at line 77 of file usb_msd.c.

#define SCSI_SENSE_KEY_COPY_ABORTED   0x0A

Definition at line 79 of file usb_msd.c.

#define SCSI_SENSE_KEY_DATA_PROTECT   0x07

Definition at line 76 of file usb_msd.c.

Referenced by msd_scsi_process_start_read_write_10().

#define SCSI_SENSE_KEY_GOOD   0x00

Definition at line 69 of file usb_msd.c.

Referenced by mass_storage_thread(), and msd_read_command_block().

#define SCSI_SENSE_KEY_HARDWARE_ERROR   0x04

Definition at line 73 of file usb_msd.c.

#define SCSI_SENSE_KEY_ILLEGAL_REQUEST   0x05
#define SCSI_SENSE_KEY_MEDIUM_ERROR   0x03

Definition at line 72 of file usb_msd.c.

Referenced by msd_scsi_process_start_read_write_10().

#define SCSI_SENSE_KEY_MISCOMPARE   0x0E

Definition at line 82 of file usb_msd.c.

#define SCSI_SENSE_KEY_NOT_READY   0x02

Definition at line 71 of file usb_msd.c.

Referenced by msd_scsi_process_test_unit_ready().

#define SCSI_SENSE_KEY_RECOVERED_ERROR   0x01

Definition at line 70 of file usb_msd.c.

Referenced by msd_scsi_process_test_unit_ready().

#define SCSI_SENSE_KEY_UNIT_ATTENTION   0x06

Definition at line 75 of file usb_msd.c.

#define SCSI_SENSE_KEY_VENDOR_SPECIFIC   0x09

Definition at line 78 of file usb_msd.c.

#define SCSI_SENSE_KEY_VOLUME_OVERFLOW   0x0D

Definition at line 81 of file usb_msd.c.

Typedef Documentation

typedef uint32_t DWORD

Definition at line 133 of file usb_msd.c.

typedef uint16_t WORD

Definition at line 133 of file usb_msd.c.

Function Documentation

void debug_snd_evt_i ( eventmask_t  evt)

Definition at line 921 of file usb_msd.c.

References dbg_printer.

Referenced by msdInit(), msdRequestsHook(), and usbEvent().

+ Here is the caller graph for this function:

void debug_snd_evt_inl ( eventmask_t  evt)

Definition at line 930 of file usb_msd.c.

References dbg_printer.

Referenced by msd_wait_for_isr(), and msdConfigureHookI().

+ Here is the caller graph for this function:

void deinit_msd_driver ( void  )

Definition at line 1121 of file usb_msd.c.

References msdStop().

Referenced by thdUsbStorage().

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

static const USBDescriptor* getDescriptor ( USBDriver *  usbp,
uint8_t  type,
uint8_t  index,
uint16_t  lang 
)
static
static uint8_t IN_DMA_SECTION_CLEAR ( rw_buf  [2][512])
static

Read-write buffers (TODO: need a way of specifying the size of this)

void init_msd_driver ( void *  dbgThreadPtr,
USBMassStorageConfig msdConfig 
)

Definition at line 1126 of file usb_msd.c.

References dbg_printer, msdInit(), msdStart(), and USBD.

Referenced by thdUsbStorage().

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

static void msd_handle_end_point_notification ( USBDriver *  usbp,
usbep_t  ep 
)
static

Called when data can be read or written on the endpoint – wakes the thread up.

Definition at line 298 of file usb_msd.c.

References SEM_RELEASED.

bool msd_read_command_block ( USBMassStorageDriver msdp)
void msd_register_evt_connected ( event_listener_t *  elp,
eventmask_t  mask 
)

register connected event source in local event mask

This function is a stub to chEvtRegisterMask

Definition at line 1142 of file usb_msd.c.

References USBMassStorageDriver::evt_connected.

Referenced by thdUsbStorage().

+ Here is the caller graph for this function:

void msd_register_evt_ejected ( event_listener_t *  elp,
eventmask_t  mask 
)

register ejected event source in local event mask

This function is a stub to chEvtRegisterMask ejected event is a logical event : when host unmount the filesystem, not a physical event (event is not sent in case of unplugged usb wire)

Definition at line 1147 of file usb_msd.c.

References USBMassStorageDriver::evt_ejected.

bool msd_scsi_process_inquiry ( USBMassStorageDriver msdp)

Processes an INQUIRY SCSI command.

Definition at line 349 of file usb_msd.c.

References USBMassStorageDriver::cbw, debug_snd_evt_nl(), EVT_SCSI_PROC_INQ, USBMassStorageDriver::inquiry, msd_scsi_set_sense(), msd_start_transmit(), USBMassStorageDriver::result, SCSI_ASENSE_INVALID_FIELD_IN_CDB, SCSI_ASENSEQ_NO_QUALIFIER, and SCSI_SENSE_KEY_ILLEGAL_REQUEST.

Referenced by msd_read_command_block().

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

bool msd_scsi_process_mode_sense_6 ( USBMassStorageDriver msdp)

Processes a MODE_SENSE_6 SCSI command.

Definition at line 588 of file usb_msd.c.

References debug_snd_evt_nl(), EVT_SCSI_REQ_SENSE6, msd_start_transmit(), and USBMassStorageDriver::result.

Referenced by msd_read_command_block().

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

bool msd_scsi_process_read_capacity_10 ( USBMassStorageDriver msdp)

Processes a READ_CAPACITY_10 SCSI command.

Definition at line 407 of file usb_msd.c.

References USBMassStorageDriver::block_dev_info, debug_snd_evt_nl(), EVT_SCSI_REQ_READ_CAP10, msd_start_transmit(), USBMassStorageDriver::result, and swap_uint32().

Referenced by msd_read_command_block().

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

bool msd_scsi_process_read_format_capacities ( USBMassStorageDriver msdp)

Processes a READ_FORMAT_CAPACITIES SCSI command.

Definition at line 608 of file usb_msd.c.

References USBMassStorageDriver::block_dev_info, debug_snd_evt_nl(), EVT_SCSI_REQ_READ_FMT_CAP, msd_start_transmit(), USBMassStorageDriver::result, and swap_uint32().

Referenced by msd_read_command_block().

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

bool msd_scsi_process_request_sense ( USBMassStorageDriver msdp)

Processes a REQUEST_SENSE SCSI command.

Definition at line 391 of file usb_msd.c.

References msd_start_transmit(), msd_wait_for_isr(), USBMassStorageDriver::result, and USBMassStorageDriver::sense.

Referenced by msd_read_command_block().

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

bool msd_scsi_process_send_diagnostic ( USBMassStorageDriver msdp)

Processes a SEND_DIAGNOSTIC SCSI command.

Definition at line 425 of file usb_msd.c.

References USBMassStorageDriver::cbw, msd_scsi_set_sense(), USBMassStorageDriver::result, SCSI_ASENSE_INVALID_FIELD_IN_CDB, SCSI_ASENSEQ_NO_QUALIFIER, and SCSI_SENSE_KEY_ILLEGAL_REQUEST.

Referenced by msd_read_command_block().

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

bool msd_scsi_process_start_stop_unit ( USBMassStorageDriver msdp)

Processes a START_STOP_UNIT SCSI command.

Definition at line 570 of file usb_msd.c.

References USBMassStorageDriver::cbw, USBMassStorageDriver::evt_ejected, MSD_EJECTED, USBMassStorageDriver::result, and USBMassStorageDriver::state.

Referenced by msd_read_command_block().

+ Here is the caller graph for this function:

bool msd_scsi_process_test_unit_ready ( USBMassStorageDriver msdp)
static void msd_scsi_set_sense ( USBMassStorageDriver msdp,
uint8_t  key,
uint8_t  acode,
uint8_t  aqual 
)
inlinestatic

Changes the SCSI sense information.

Definition at line 339 of file usb_msd.c.

References USBMassStorageDriver::sense.

Referenced by mass_storage_thread(), msd_read_command_block(), msd_scsi_process_inquiry(), msd_scsi_process_send_diagnostic(), msd_scsi_process_start_read_write_10(), and msd_scsi_process_test_unit_ready().

+ Here is the caller graph for this function:

static void msd_start_receive ( USBMassStorageDriver msdp,
uint8_t buffer,
size_t  size 
)
static

Starts receiving data.

Definition at line 325 of file usb_msd.c.

References USBMassStorageDriver::bot_reset, USBMassStorageConfig::bulk_ep, USBMassStorageDriver::config, and USBMassStorageConfig::usbp.

Referenced by msd_scsi_process_start_read_write_10(), and msd_wait_for_command_block().

+ Here is the caller graph for this function:

bool msd_wait_for_command_block ( USBMassStorageDriver msdp)

Waits for a new command block.

Definition at line 654 of file usb_msd.c.

References USBMassStorageDriver::cbw, debug_snd_evt_nl(), EVT_WAIT_FOR_COMMAND_BLOCK, MSD_READ_COMMAND_BLOCK, msd_start_receive(), and USBMassStorageDriver::state.

Referenced by mass_storage_thread().

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

static void msd_wait_for_isr ( USBMassStorageDriver msdp)
static

Wait until the end-point interrupt handler has been called.

Definition at line 285 of file usb_msd.c.

References USBMassStorageDriver::bsem, debug_snd_evt_inl(), EVT_SEM_TAKEN, and SEM_TAKEN.

Referenced by mass_storage_thread(), msd_read_command_block(), msd_scsi_process_request_sense(), and msd_scsi_process_start_read_write_10().

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void msdConfigureHookI ( USBMassStorageDriver msdp)

USB device configured handler.

Parameters
[in]msdppointer to the USBMassStorageDriver object

Definition at line 188 of file usb_msd.c.

References USBMassStorageDriver::bsem, USBMassStorageConfig::bulk_ep, USBMassStorageDriver::config, debug_snd_evt_inl(), USBMassStorageDriver::evt_connected, EVT_SEM_RELEASED, SEM_RELEASED, and USBMassStorageConfig::usbp.

Referenced by usbEvent().

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void msdInit ( USBMassStorageDriver msdp)
bool msdRequestsHook ( USBDriver *  usbp)

Default requests hook.

Parameters
[in]usbppointer to the USBDriver object
Returns
The hook status.
Return values
trueMessage handled internally.
falseMessage not handled.

Definition at line 205 of file usb_msd.c.

References USBMassStorageDriver::bot_reset, USBMassStorageDriver::bsem, USBMassStorageConfig::bulk_ep, USBMassStorageDriver::config, debug_snd_evt_i(), EVT_BOT_RESET, MSD_BOT_RESET, MSD_GET_MAX_LUN, MSD_REQ_RESET, MSD_SETUP_INDEX, MSD_SETUP_LENGTH, MSD_SETUP_VALUE, USBMassStorageDriver::state, and USBMassStorageConfig::usbp.

+ Here is the call graph for this function:

void msdStart ( USBMassStorageDriver msdp,
const USBMassStorageConfig config 
)

Starts a USB mass storage driver.

This function is sufficient to have USB mass storage running, it internally runs a thread that handles USB requests and transfers. The block device must be connected but no file system must be mounted, everything is handled by the host system.

Definition at line 855 of file usb_msd.c.

References USBMassStorageConfig::bbdp, USBMassStorageDriver::block_dev_info, USBMassStorageConfig::bulk_ep, config, USBMassStorageDriver::config, USBMassStorageDriver::inquiry, mass_storage_thread(), MSD_IDLE, USBMassStorageConfig::short_product_id, USBMassStorageConfig::short_product_version, USBMassStorageConfig::short_vendor_id, USBMassStorageDriver::state, USBMassStorageDriver::thread, and USBMassStorageConfig::usbp.

Referenced by init_msd_driver().

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void msdStop ( USBMassStorageDriver msdp)

Stops a USB mass storage driver.

This function waits for current tasks to be finished, if any, and then stops the mass storage thread.

Definition at line 900 of file usb_msd.c.

References USBMassStorageDriver::bsem, USBMassStorageConfig::bulk_ep, USBMassStorageDriver::config, USBMassStorageDriver::thread, and USBMassStorageConfig::usbp.

Referenced by deinit_msd_driver().

+ Here is the caller graph for this function:

static WORD swap_uint16 ( const WORD  val)
inlinestatic

Byte-swap a 16 bits unsigned integer.

Definition at line 149 of file usb_msd.c.

Referenced by msd_scsi_process_start_read_write_10().

+ Here is the caller graph for this function:

static DWORD swap_uint32 ( const DWORD  val)
inlinestatic

Byte-swap a 32 bits unsigned integer.

Definition at line 140 of file usb_msd.c.

Referenced by msd_scsi_process_read_capacity_10(), msd_scsi_process_read_format_capacities(), and msd_scsi_process_start_read_write_10().

+ Here is the caller graph for this function:

static THD_WORKING_AREA ( mass_storage_thread_wa  ,
1024   
)
static
static void usbEvent ( USBDriver *  usbp,
usbevent_t  event 
)
static

Definition at line 945 of file usb_msd.c.

References debug_snd_evt_i(), EVT_USB_RESET, msdConfigureHookI(), and USBMassStorageDriver::reconfigured_or_reset_event.

+ Here is the call graph for this function:

Variable Documentation

const USBDescriptor configurationDescriptor
static
Initial value:
= {
}
static const uint8_t configurationDescriptorData[]
Definition: usb_msd.c:994

Definition at line 1036 of file usb_msd.c.

Referenced by getDescriptor().

const uint8_t configurationDescriptorData[]
static

Definition at line 994 of file usb_msd.c.

thread_t* dbg_printer = NULL

Definition at line 109 of file usb_msd.c.

Referenced by debug_snd_evt_i(), debug_snd_evt_inl(), debug_snd_evt_nl(), and init_msd_driver().

const USBDescriptor deviceDescriptor
static
Initial value:
= {
}
static const uint8_t deviceDescriptorData[]
Definition: usb_msd.c:971

Definition at line 988 of file usb_msd.c.

Referenced by getDescriptor().

const uint8_t deviceDescriptorData[]
static
Initial value:
= {
USB_DESC_DEVICE
(
0x0200,
0x00,
0x00,
0x00,
64,
0x0483,
0xBABE,
0x0100,
1,
2,
3,
1
)
}

Definition at line 971 of file usb_msd.c.

USBInEndpointState ep1_in_state
static

IN end-point 1 state.

Definition at line 158 of file usb_msd.c.

USBOutEndpointState ep1_out_state
static

OUT end-point 1 state.

Definition at line 163 of file usb_msd.c.

const USBEndpointConfig ep_data_config
static
Initial value:
= {
USB_EP_MODE_TYPE_BULK,
NULL,
64,
64,
1,
NULL
}
static void msd_handle_end_point_notification(USBDriver *usbp, usbep_t ep)
Called when data can be read or written on the endpoint – wakes the thread up.
Definition: usb_msd.c:298
static USBOutEndpointState ep1_out_state
OUT end-point 1 state.
Definition: usb_msd.c:163
static USBInEndpointState ep1_in_state
IN end-point 1 state.
Definition: usb_msd.c:158

End-point 1 initialization structure.

Definition at line 168 of file usb_msd.c.

Referenced by mass_storage_thread().

const USBDescriptor languageDescriptor
static
Initial value:
= {
}
static const uint8_t languageDescriptorData[]
Definition: usb_msd.c:1042

Definition at line 1047 of file usb_msd.c.

Referenced by getDescriptor().

const uint8_t languageDescriptorData[]
static
Initial value:
= {
USB_DESC_BYTE(4),
USB_DESC_BYTE(USB_DESCRIPTOR_STRING),
USB_DESC_WORD(0x0409)
}

Definition at line 1042 of file usb_msd.c.

const USBDescriptor productDescriptor
static
Initial value:
= {
}
static const uint8_t productDescriptorData[]
Definition: usb_msd.c:1064

Definition at line 1069 of file usb_msd.c.

Referenced by getDescriptor().

const uint8_t productDescriptorData[]
static
Initial value:
= {
USB_DESC_BYTE(24),
USB_DESC_BYTE(USB_DESCRIPTOR_STRING),
'M', 0, 'S', 0, 'D', 0, ' ', 0, 'E', 0, 'x', 0, 'a', 0, 'm', 0, 'p', 0, 'l', 0, 'e', 0
}

Definition at line 1064 of file usb_msd.c.

const USBDescriptor serialNumberDescriptor
static
Initial value:
= {
}
static const uint8_t serialNumberDescriptorData[]
Definition: usb_msd.c:1075

Definition at line 1080 of file usb_msd.c.

Referenced by getDescriptor().

const uint8_t serialNumberDescriptorData[]
static
Initial value:
= {
USB_DESC_BYTE(26),
USB_DESC_BYTE(USB_DESCRIPTOR_STRING),
'0', 0, '1', 0, '4', 0, '2', 0, '3', 0, '0', 0, 'F', 0, 'K', 0, '0', 0, '0', 0, '0', 0, '1', 0
}

Definition at line 1075 of file usb_msd.c.

USBMassStorageDriver UMSD
static

Definition at line 33 of file usb_msd.c.

const USBConfig usbConfig
static
Initial value:
= {
0
}
static void usbEvent(USBDriver *usbp, usbevent_t event)
Definition: usb_msd.c:945
static const USBDescriptor * getDescriptor(USBDriver *usbp, uint8_t type, uint8_t index, uint16_t lang)
Definition: usb_msd.c:1087
bool msdRequestsHook(USBDriver *usbp)
Default requests hook.
Definition: usb_msd.c:205

Definition at line 1112 of file usb_msd.c.

const USBDescriptor vendorDescriptor
static
Initial value:
= {
}
static const uint8_t vendorDescriptorData[]
Definition: usb_msd.c:1053

Definition at line 1058 of file usb_msd.c.

Referenced by getDescriptor().

const uint8_t vendorDescriptorData[]
static
Initial value:
= {
USB_DESC_BYTE(22),
USB_DESC_BYTE(USB_DESCRIPTOR_STRING),
'S', 0, 'T', 0, 'M', 0, 'i', 0, 'c', 0, 'r', 0, 'o', 0, 'M', 0, 'S', 0, 'D', 0
}

Definition at line 1053 of file usb_msd.c.