USB mass storage driver
[USB]

USB driver for mass storage devices (bulk-only protocol). More...


Files

file  cmds.h
 USB mass storage commands.
file  inquiry.c
 Main routines of USB mass storage driver.
file  main.c
 Main routines of USB mass storage driver.
file  mast.c
 Generic functions for USB mass storage (implementation).
file  mast.h
 Generic functions for USB mass storage.
file  scsi.h
 SCSI related structures.

Data Structures

struct  scsi_cmd_inquiry_t
struct  usb_massstor_cbw_t
struct  usb_massstor_csw_t
struct  usb_massstor_inquiry_result_t
 Result of SCSI INQUIRY command. More...

Defines

#define BITS_GET(type, number, bitcount, offset)   ((type)( (number) & (BITS_GET_MID_MASK(type, bitcount, offset)) ) >> (offset))
#define BITS_GET_MASK(type, bitcount)   (((type)(1 << (bitcount)))-1)
#define BITS_GET_MID_MASK(type, bitcount, offset)   ((type)( BITS_GET_MASK(type, (bitcount) + (offset)) - BITS_GET_MASK(type, bitcount) ))
#define BULK_IN_EP   0
#define BULK_OUT_EP   1
#define GET_BULK_IN(dev)   ((dev)->pipes[BULK_IN_EP].pipe)
#define GET_BULK_OUT(dev)   ((dev)->pipes[BULK_OUT_EP].pipe)
#define INQUIRY_RESPONSE_LENGTH   36
#define MASTLOG(format,)
#define NAME   "usbmast"
#define str_peripheral_device_types_count   (sizeof(str_peripheral_device_types)/sizeof(str_peripheral_device_types[0]))
#define STR_UNKNOWN   "<unknown>"

Functions

int main (int argc, char *argv[])
 Main entry point.
static void trim_trailing_spaces (char *name)
 Trim trailing spaces from a string (rewrite with string terminator).
static void usb_massstor_cbw_prepare (usb_massstor_cbw_t *cbw, uint32_t tag, uint32_t transfer_length, usb_direction_t dir, uint8_t lun, uint8_t cmd_len, uint8_t *cmd)
int usb_massstor_data_in (usb_device_t *dev, size_t bulk_in_pipe_index, size_t bulk_out_pipe_index, uint32_t tag, uint8_t lun, void *cmd, size_t cmd_size, void *in_buffer, size_t in_buffer_size, size_t *received_size)
 Request data from mass storage device.
int usb_massstor_get_max_lun (usb_device_t *dev)
 Get max LUN of a mass storage device.
int usb_massstor_inquiry (usb_device_t *dev, size_t bulk_in_idx, size_t bulk_out_idx, usb_massstor_inquiry_result_t *inquiry_result)
 Perform SCSI INQUIRY command on USB mass storage device.
int usb_massstor_reset (usb_device_t *dev)
 Perform bulk-only mass storage reset.
void usb_massstor_reset_recovery (usb_device_t *dev, size_t bulk_in_idx, size_t bulk_out_idx)
 Perform complete reset recovery of bulk-only mass storage.
size_t usb_masstor_get_lun_count (usb_device_t *dev)
 Get number of LUNs supported by mass storage device.
const char * usb_str_masstor_scsi_peripheral_device_type (int type)
 Get string representation for SCSI peripheral device type.
static int usbmast_add_device (usb_device_t *dev)
 Callback when new device is attached and recognized as a mass storage.

Variables

static usb_endpoint_description_t bulk_in_ep
static usb_endpoint_description_t bulk_out_ep
usb_endpoint_description_tmast_endpoints []
static const char * str_peripheral_device_types []
 String constants for SCSI peripheral device types.
bool usb_mast_verbose = true
static usb_driver_t usbmast_driver
 USB mass storage driver.
static usb_driver_ops_t usbmast_driver_ops
 USB mass storage driver ops.

Detailed Description

USB driver for mass storage devices (bulk-only protocol).

This driver is a only a stub and is currently used only for testing that bulk transfers work.


Function Documentation

int main ( int  argc,
char *  argv[] 
)

Main entry point.

Parameters:
[in] argc Nmber of arguments in argv vector (ignored).
[in] argv Cmdline argument vector (ignored).
Returns:
Error code.
Driver debug level is set here.

Definition at line 142 of file main.c.

static void trim_trailing_spaces ( char *  name  )  [static]

Trim trailing spaces from a string (rewrite with string terminator).

Parameters:
name String to be trimmed (in-out parameter).

Definition at line 117 of file inquiry.c.

int usb_massstor_data_in ( usb_device_t dev,
size_t  bulk_in_pipe_index,
size_t  bulk_out_pipe_index,
uint32_t  tag,
uint8_t  lun,
void *  cmd,
size_t  cmd_size,
void *  in_buffer,
size_t  in_buffer_size,
size_t received_size 
)

Request data from mass storage device.

Parameters:
bulk_in_pipe Bulk in pipe to the device.
bulk_out_pipe Bulk out pipe to the device.
tag Command block wrapper tag (automatically compared with answer).
lun LUN index.
cmd SCSI command buffer (in SCSI endianness).
cmd_size Length of SCSI command cmd in bytes.
in_buffer Buffer where to store the answer (CSW is not returned).
in_buffer_size Size of the buffer (size of the request to the device).
received_size Number of actually received bytes.
Returns:
Error code.

Definition at line 66 of file mast.c.

int usb_massstor_get_max_lun ( usb_device_t dev  ) 

Get max LUN of a mass storage device.

See also:
usb_masstor_get_lun_count
Warning:
Error from this command does not necessarily indicate malfunction of the device. Device does not need to support this request. You shall rather use usb_masstor_get_lun_count.
Parameters:
dev Mass storage device.
Returns:
Error code of maximum LUN (index, not count).

Definition at line 184 of file mast.c.

int usb_massstor_inquiry ( usb_device_t dev,
size_t  bulk_in_idx,
size_t  bulk_out_idx,
usb_massstor_inquiry_result_t inquiry_result 
)

Perform SCSI INQUIRY command on USB mass storage device.

Parameters:
dev USB device.
bulk_in_idx Index (in dev->pipes) of bulk in pipe.
bulk_out_idx Index of bulk out pipe.
inquiry_result Where to store parsed inquiry result.
Returns:
Error code.

Definition at line 134 of file inquiry.c.

int usb_massstor_reset ( usb_device_t dev  ) 

Perform bulk-only mass storage reset.

Parameters:
dev Device to be reseted.
Returns:
Error code.

Definition at line 146 of file mast.c.

void usb_massstor_reset_recovery ( usb_device_t dev,
size_t  bulk_in_idx,
size_t  bulk_out_idx 
)

Perform complete reset recovery of bulk-only mass storage.

Notice that no error is reported because if this fails, the error would reappear on next transaction somehow.

Parameters:
dev Device to be reseted.
bulk_in_idx Index of bulk in pipe.
bulk_out_idx Index of bulk out pipe.

Definition at line 162 of file mast.c.

size_t usb_masstor_get_lun_count ( usb_device_t dev  ) 

Get number of LUNs supported by mass storage device.

Warning:
This function hides any error during the request (typically that shall not be a problem).
Parameters:
dev Mass storage device.
Returns:
Number of LUNs.

Definition at line 208 of file mast.c.

const char * usb_str_masstor_scsi_peripheral_device_type ( int  type  ) 

Get string representation for SCSI peripheral device type.

See for example here for a list http://en.wikipedia.org/wiki/SCSI_Peripheral_Device_Type.

Parameters:
type SCSI peripheral device type code.
Returns:
String representation.

Definition at line 104 of file inquiry.c.

static int usbmast_add_device ( usb_device_t dev  )  [static]

Callback when new device is attached and recognized as a mass storage.

Parameters:
dev Representation of a the USB device.
Returns:
Error code.

Definition at line 82 of file main.c.


Generated on Thu Jun 2 07:45:56 2011 for HelenOS/USB by  doxygen 1.4.7