FreeBSD kernel usb device Code
usb_template_msc.c File Reference
#include <sys/stdint.h>
#include <sys/stddef.h>
#include <sys/param.h>
#include <sys/queue.h>
#include <sys/types.h>
#include <sys/systm.h>
#include <sys/kernel.h>
#include <sys/bus.h>
#include <sys/module.h>
#include <sys/lock.h>
#include <sys/mutex.h>
#include <sys/condvar.h>
#include <sys/sysctl.h>
#include <sys/sx.h>
#include <sys/unistd.h>
#include <sys/callout.h>
#include <sys/malloc.h>
#include <sys/priv.h>
#include <dev/usb/usb.h>
#include <dev/usb/usbdi.h>
#include <dev/usb/usb_core.h>
#include <dev/usb/usb_ioctl.h>
#include <dev/usb/usb_util.h>
#include <dev/usb/template/usb_template.h>
Include dependency graph for usb_template_msc.c:

Go to the source code of this file.

Macros

#define MSC_DEFAULT_VENDOR_ID   USB_TEMPLATE_VENDOR
 
#define MSC_DEFAULT_PRODUCT_ID   0x27df
 
#define MSC_DEFAULT_INTERFACE   "USB Mass Storage Interface"
 
#define MSC_DEFAULT_CONFIGURATION   "Default Config"
 
#define MSC_DEFAULT_MANUFACTURER   USB_TEMPLATE_MANUFACTURER
 
#define MSC_DEFAULT_PRODUCT   "USB Memory Stick"
 
#define MSC_DEFAULT_SERIAL_NUMBER   "March 2008"
 

Enumerations

enum  {
  MSC_LANG_INDEX , MSC_INTERFACE_INDEX , MSC_CONFIGURATION_INDEX , MSC_MANUFACTURER_INDEX ,
  MSC_PRODUCT_INDEX , MSC_SERIAL_NUMBER_INDEX , MSC_MAX_INDEX
}
 

Functions

static const void * msc_get_string_desc (uint16_t lang_id, uint8_t string_index)
 
static void msc_init (void *arg __unused)
 
static void msc_uninit (void *arg __unused)
 
 SYSINIT (msc_init, SI_SUB_LOCK, SI_ORDER_FIRST, msc_init, NULL)
 
 SYSUNINIT (msc_uninit, SI_SUB_LOCK, SI_ORDER_FIRST, msc_uninit, NULL)
 

Variables

static struct usb_string_descriptor msc_interface
 
static struct usb_string_descriptor msc_configuration
 
static struct usb_string_descriptor msc_manufacturer
 
static struct usb_string_descriptor msc_product
 
static struct usb_string_descriptor msc_serial_number
 
static struct sysctl_ctx_list msc_ctx_list
 
static usb_temp_get_string_desc_t msc_get_string_desc
 
static const struct usb_temp_packet_size bulk_mps
 
static const struct usb_temp_endpoint_desc bulk_in_ep
 
static const struct usb_temp_endpoint_desc bulk_out_ep
 
static const struct usb_temp_endpoint_descmsc_data_endpoints []
 
static const struct usb_temp_interface_desc msc_data_interface
 
static const struct usb_temp_interface_descmsc_interfaces []
 
static const struct usb_temp_config_desc msc_config_desc
 
static const struct usb_temp_config_descmsc_configs []
 
struct usb_temp_device_desc usb_template_msc
 

Macro Definition Documentation

◆ MSC_DEFAULT_CONFIGURATION

#define MSC_DEFAULT_CONFIGURATION   "Default Config"

Definition at line 82 of file usb_template_msc.c.

◆ MSC_DEFAULT_INTERFACE

#define MSC_DEFAULT_INTERFACE   "USB Mass Storage Interface"

Definition at line 81 of file usb_template_msc.c.

◆ MSC_DEFAULT_MANUFACTURER

#define MSC_DEFAULT_MANUFACTURER   USB_TEMPLATE_MANUFACTURER

Definition at line 83 of file usb_template_msc.c.

◆ MSC_DEFAULT_PRODUCT

#define MSC_DEFAULT_PRODUCT   "USB Memory Stick"

Definition at line 84 of file usb_template_msc.c.

◆ MSC_DEFAULT_PRODUCT_ID

#define MSC_DEFAULT_PRODUCT_ID   0x27df

Definition at line 80 of file usb_template_msc.c.

◆ MSC_DEFAULT_SERIAL_NUMBER

#define MSC_DEFAULT_SERIAL_NUMBER   "March 2008"

Definition at line 85 of file usb_template_msc.c.

◆ MSC_DEFAULT_VENDOR_ID

#define MSC_DEFAULT_VENDOR_ID   USB_TEMPLATE_VENDOR

Definition at line 79 of file usb_template_msc.c.

Enumeration Type Documentation

◆ anonymous enum

anonymous enum
Enumerator
MSC_LANG_INDEX 
MSC_INTERFACE_INDEX 
MSC_CONFIGURATION_INDEX 
MSC_MANUFACTURER_INDEX 
MSC_PRODUCT_INDEX 
MSC_SERIAL_NUMBER_INDEX 
MSC_MAX_INDEX 

Definition at line 69 of file usb_template_msc.c.

Function Documentation

◆ msc_get_string_desc()

static const void * msc_get_string_desc ( uint16_t  lang_id,
uint8_t  string_index 
)
static

◆ msc_init()

◆ msc_uninit()

static void msc_uninit ( void *arg  __unused)
static

Definition at line 255 of file usb_template_msc.c.

References msc_ctx_list.

◆ SYSINIT()

SYSINIT ( msc_init  ,
SI_SUB_LOCK  ,
SI_ORDER_FIRST  ,
msc_init  ,
NULL   
)

◆ SYSUNINIT()

SYSUNINIT ( msc_uninit  ,
SI_SUB_LOCK  ,
SI_ORDER_FIRST  ,
msc_uninit  ,
NULL   
)

Variable Documentation

◆ bulk_in_ep

const struct usb_temp_endpoint_desc bulk_in_ep
static
Initial value:
= {
.pPacketSize = &bulk_mps,
.bEndpointAddress = UE_DIR_IN,
.bmAttributes = UE_BULK,
}
#define UE_BULK
Definition: usb.h:543
#define UE_DIR_IN
Definition: usb.h:531
static const struct usb_temp_packet_size bulk_mps

Definition at line 104 of file usb_template_msc.c.

◆ bulk_mps

const struct usb_temp_packet_size bulk_mps
static
Initial value:
= {
.mps[USB_SPEED_FULL] = 64,
.mps[USB_SPEED_HIGH] = 512,
}
@ USB_SPEED_FULL
Definition: usb.h:754
@ USB_SPEED_HIGH
Definition: usb.h:755

Definition at line 99 of file usb_template_msc.c.

◆ bulk_out_ep

const struct usb_temp_endpoint_desc bulk_out_ep
static
Initial value:
= {
.pPacketSize = &bulk_mps,
.bEndpointAddress = UE_DIR_OUT,
.bmAttributes = UE_BULK,
}
#define UE_DIR_OUT
Definition: usb.h:532

Definition at line 114 of file usb_template_msc.c.

◆ msc_config_desc

const struct usb_temp_config_desc msc_config_desc
static
Initial value:
= {
.ppIfaceDesc = msc_interfaces,
.bmAttributes = 0,
.bMaxPower = 0,
.iConfiguration = MSC_CONFIGURATION_INDEX,
}
static const struct usb_temp_interface_desc * msc_interfaces[]
@ MSC_CONFIGURATION_INDEX

Definition at line 143 of file usb_template_msc.c.

◆ msc_configs

const struct usb_temp_config_desc* msc_configs[]
static
Initial value:
= {
NULL,
}
static const struct usb_temp_config_desc msc_config_desc

Definition at line 150 of file usb_template_msc.c.

◆ msc_configuration

struct usb_string_descriptor msc_configuration
static

Definition at line 88 of file usb_template_msc.c.

Referenced by msc_get_string_desc(), and msc_init().

◆ msc_ctx_list

struct sysctl_ctx_list msc_ctx_list
static

Definition at line 93 of file usb_template_msc.c.

Referenced by msc_init(), and msc_uninit().

◆ msc_data_endpoints

const struct usb_temp_endpoint_desc* msc_data_endpoints[]
static
Initial value:
= {
NULL,
}
static const struct usb_temp_endpoint_desc bulk_out_ep
static const struct usb_temp_endpoint_desc bulk_in_ep

Definition at line 124 of file usb_template_msc.c.

◆ msc_data_interface

const struct usb_temp_interface_desc msc_data_interface
static
Initial value:
= {
.ppEndpoints = msc_data_endpoints,
.bInterfaceClass = UICLASS_MASS,
.bInterfaceSubClass = UISUBCLASS_SCSI,
.bInterfaceProtocol = UIPROTO_MASS_BBB,
.iInterface = MSC_INTERFACE_INDEX,
}
#define UIPROTO_MASS_BBB
Definition: usb.h:477
#define UISUBCLASS_SCSI
Definition: usb.h:473
#define UICLASS_MASS
Definition: usb.h:467
@ MSC_INTERFACE_INDEX
static const struct usb_temp_endpoint_desc * msc_data_endpoints[]

Definition at line 130 of file usb_template_msc.c.

◆ msc_get_string_desc

usb_temp_get_string_desc_t msc_get_string_desc
static

Definition at line 97 of file usb_template_msc.c.

◆ msc_interface

struct usb_string_descriptor msc_interface
static

Definition at line 87 of file usb_template_msc.c.

Referenced by msc_get_string_desc(), and msc_init().

◆ msc_interfaces

const struct usb_temp_interface_desc* msc_interfaces[]
static
Initial value:
= {
NULL,
}
static const struct usb_temp_interface_desc msc_data_interface

Definition at line 138 of file usb_template_msc.c.

◆ msc_manufacturer

struct usb_string_descriptor msc_manufacturer
static

Definition at line 89 of file usb_template_msc.c.

Referenced by msc_get_string_desc(), and msc_init().

◆ msc_product

struct usb_string_descriptor msc_product
static

Definition at line 90 of file usb_template_msc.c.

Referenced by msc_get_string_desc(), and msc_init().

◆ msc_serial_number

struct usb_string_descriptor msc_serial_number
static

Definition at line 91 of file usb_template_msc.c.

Referenced by msc_get_string_desc(), and msc_init().

◆ usb_template_msc

struct usb_temp_device_desc usb_template_msc
Initial value:
= {
.getStringDesc = &msc_get_string_desc,
.ppConfigDesc = msc_configs,
.idVendor = MSC_DEFAULT_VENDOR_ID,
.idProduct = MSC_DEFAULT_PRODUCT_ID,
.bcdDevice = 0x0100,
.bDeviceClass = UDCLASS_COMM,
.bDeviceSubClass = 0,
.bDeviceProtocol = 0,
.iManufacturer = MSC_MANUFACTURER_INDEX,
.iProduct = MSC_PRODUCT_INDEX,
.iSerialNumber = MSC_SERIAL_NUMBER_INDEX,
}
#define UDCLASS_COMM
Definition: usb.h:372
#define MSC_DEFAULT_VENDOR_ID
static const struct usb_temp_config_desc * msc_configs[]
@ MSC_SERIAL_NUMBER_INDEX
@ MSC_MANUFACTURER_INDEX
@ MSC_PRODUCT_INDEX
#define MSC_DEFAULT_PRODUCT_ID
static usb_temp_get_string_desc_t msc_get_string_desc

Definition at line 155 of file usb_template_msc.c.

Referenced by msc_init(), and usb_temp_setup_by_index().