34#ifdef USB_GLOBAL_INCLUDE_FILE
35#include USB_GLOBAL_INCLUDE_FILE
37#include <sys/stdint.h>
38#include <sys/stddef.h>
43#include <sys/kernel.h>
45#include <sys/module.h>
48#include <sys/condvar.h>
49#include <sys/sysctl.h>
51#include <sys/unistd.h>
52#include <sys/callout.h>
53#include <sys/malloc.h>
70#define USB_DEBUG_VAR usb_debug
118SYSCTL_NODE(_hw_usb, OID_AUTO, templates, CTLFLAG_RW | CTLFLAG_MPSAFE, 0,
119 "USB device side templates");
121 CTLTYPE_INT | CTLFLAG_RWTUN | CTLFLAG_MPSAFE,
123 "I",
"USB bus power consumption in mA at 5V");
134 if (
error != 0 ||
req->newptr == NULL)
137 if (val < 0 || val > 500)
160 for (i = 0; i < buflen - 1 && i < (sd->
bLength / 2) - 1; i++)
177 size_t len, sdlen = arg2;
182 error = sysctl_handle_string(oidp, buf,
sizeof(buf),
req);
183 if (
error != 0 ||
req->newptr == NULL)
278 old_size = temp->
size;
285 temp->
size +=
sizeof(*ed) + 2;
287 temp->
size +=
sizeof(*ed);
386 old_size = temp->
size;
387 temp->
size +=
sizeof(*id);
427 id->bLength =
sizeof(*id);
457 old_size = temp->
size;
458 temp->
size +=
sizeof(*cd);
482 old_size = temp->
size - old_size;
521 old_size = temp->
size;
522 temp->
size +=
sizeof(*utd);
613 uint8_t ep_type, uint8_t ep_dir_in)
617 return (
pf->support_control);
619 if ((
pf->support_in && ep_dir_in) ||
620 (
pf->support_out && !ep_dir_in)) {
623 (
pf->support_bulk && (ep_type ==
UE_BULK))) {
647 uint16_t max_frame_size;
680 if (dir_in ||
pf->is_simplex) {
687 if (dir_out ||
pf->is_simplex) {
705 max_frame_size =
pf->max_in_frame_size;
707 max_frame_size =
pf->max_out_frame_size;
712 if (distance > temp) {
756 uint8_t ep_type, uint8_t is_complete)
785 if (
id->bAlternateSetting == 0) {
797 goto handle_endpoint_desc;
806 if (temp == ep_type) {
807 if (ep_curr == ep_end) {
834 DPRINTFN(0,
"Endpoint profile %u "
835 "does not exist\n", ep_no);
846 DPRINTFN(0,
"Endpoint profile %u "
847 "has too small buffer\n", ep_no);
854 DPRINTFN(0,
"Endpoint profile %u "
855 "has too small buffer\n", ep_no);
862 DPRINTFN(0,
"Endpoint profile %u "
863 "has too small buffer\n", ep_no);
867 }
else if (is_complete) {
900 if (ep_max < ep_curr) {
949 DPRINTFN(0,
"Endpoint 0 does not "
950 "support control\n");
961 if (
pf->max_in_frame_size >= mps) {
981 if (
pf->max_in_frame_size < mps) {
994 memset(ues, 0,
sizeof(*ues));
1007 DPRINTFN(0,
"Could not get needs\n");
1010 for (ep = ues->
ep; ep != ues->
ep_max; ep++) {
1018 DPRINTFN(0,
"Could not find match\n");
1032 DPRINTFN(0,
"Could not update endpoint address\n");
1109 uint16_t *pLength, uint8_t index)
1172 uint16_t lang_id, uint8_t string_index)
1207 const void **pPtr, uint16_t *pLength)
1215 switch (
req->bmRequestType) {
1217 switch (
req->bRequest) {
1219 goto tr_handle_get_descriptor;
1224 switch (
req->bRequest) {
1226 goto tr_handle_get_class_descriptor;
1234tr_handle_get_descriptor:
1235 switch (
req->wValue[1]) {
1237 if (
req->wValue[0]) {
1246 if (
req->wValue[0]) {
1267tr_handle_get_class_descriptor:
1268 if (
req->wValue[0]) {
1324 memset(uts, 0,
sizeof(*uts));
1338 if (uts->
size == 0) {
1349 if (uts->
buf == NULL) {
1375 DPRINTFN(0,
"Could not resolve endpoints for "
1376 "Device Descriptor, error = %s\n",
1387 DPRINTFN(0,
"Could not resolve endpoints for "
1388 "Config Descriptor %u, error = %s\n",
n,
void(* get_hw_ep_profile)(struct usb_device *udev, const struct usb_hw_ep_profile **ppf, uint8_t ep_addr)
const struct usb_bus_methods * methods
uByte bConfigurationValue
union usb_device_scratch scratch
struct usb_temp_data * usb_template_ptr
struct usb_device_flags flags
const struct usb_hw_ep_profile * pf
struct usb_hw_ep_scratch_sub ep[USB_EP_MAX]
struct usb_config_descriptor * cd
const struct usb_bus_methods * methods
uint8_t bmInAlloc[(USB_EP_MAX+15)/16]
uint8_t bmOutAlloc[(USB_EP_MAX+15)/16]
struct usb_hw_ep_scratch_sub * ep_max
const struct usb_temp_interface_desc ** ppIfaceDesc
struct usb_device_descriptor udd
const struct usb_temp_device_desc * tdd
struct usb_device_qualifier udq
usb_temp_get_string_desc_t * getStringDesc
const struct usb_temp_config_desc ** ppConfigDesc
usb_temp_get_vendor_desc_t * getVendorDesc
const struct usb_temp_packet_size * pPacketSize
const struct usb_temp_interval * pIntervals
const struct usb_temp_endpoint_desc ** ppEndpoints
uint8_t bInterfaceProtocol
uint8_t bInterfaceSubClass
uint8_t bInterval[USB_SPEED_MAX]
uint16_t mps[USB_SPEED_MAX]
uint8_t bAlternateSetting
enum usb_dev_speed usb_speed
uint8_t bConfigurationValue
struct usb_temp_setup temp_setup[1]
struct usb_hw_ep_scratch hw_ep_scratch[1]
#define UDESC_IFACE_ASSOC
#define UDESC_DEVICE_QUALIFIER
#define UDESC_OTHER_SPEED_CONFIGURATION
#define UT_READ_CLASS_DEVICE
#define UDESC_CS_INTERFACE
#define UR_GET_DESCRIPTOR
#define UDESCSUB_CDC_UNION
#define USB_ADD_BYTES(ptr, size)
enum usb_dev_speed usbd_get_speed(struct usb_device *udev)
uint8_t usbd_ctrl_lock(struct usb_device *udev)
void usbd_ctrl_unlock(struct usb_device *udev)
struct usb_endpoint_descriptor desc
void usb_temp_unload(void *arg)
usb_temp_unsetup_t * usb_temp_unsetup_p
usb_temp_setup_by_index_t * usb_temp_setup_by_index_p
usb_handle_req_t * usb_temp_get_desc_p
const char * usbd_errstr(usb_error_t err)
struct usb_descriptor * usb_desc_foreach(struct usb_config_descriptor *cd, struct usb_descriptor *_desc)
void * usbd_alloc_config_desc(struct usb_device *udev, uint32_t size)
void usbd_free_config_desc(struct usb_device *udev, void *ptr)
static const struct usb_temp_device_desc * usb_temp_get_tdd(struct usb_device *)
static usb_error_t usb_hw_ep_resolve(struct usb_device *, struct usb_descriptor *)
static const void * usb_temp_get_hub_desc(struct usb_device *)
static void * usb_temp_get_config_desc(struct usb_device *, uint16_t *, uint8_t)
static void usb_temp_init(void *)
void usb_temp_unsetup(struct usb_device *udev)
static usb_error_t usb_temp_setup_by_index(struct usb_device *, uint16_t index)
static void usb_make_endpoint_desc(struct usb_temp_setup *, const struct usb_temp_endpoint_desc *)
static uint8_t usb_hw_ep_find_match(struct usb_hw_ep_scratch *, struct usb_hw_ep_scratch_sub *, uint8_t)
static void * usb_temp_get_qualifier_desc(struct usb_device *)
static uint8_t usb_hw_ep_match(const struct usb_hw_ep_profile *, uint8_t, uint8_t)
static uint8_t usb_hw_ep_get_needs(struct usb_hw_ep_scratch *, uint8_t, uint8_t)
static void * usb_temp_get_device_desc(struct usb_device *)
SYSCTL_PROC(_hw_usb, OID_AUTO, template_power, CTLTYPE_INT|CTLFLAG_RWTUN|CTLFLAG_MPSAFE, NULL, 0, sysctl_hw_usb_template_power, "I", "USB bus power consumption in mA at 5V")
static void usb_make_device_desc(struct usb_temp_setup *, const struct usb_temp_device_desc *)
MODULE_DEPEND(usb_template, usb, 1, 1, 1)
static const void * usb_temp_get_string_desc(struct usb_device *, uint16_t, uint8_t)
SYSUNINIT(usb_temp_unload, SI_SUB_LOCK, SI_ORDER_ANY, usb_temp_unload, NULL)
static void usb_make_raw_desc(struct usb_temp_setup *, const uint8_t *)
SYSINIT(usb_temp_init, SI_SUB_LOCK, SI_ORDER_FIRST, usb_temp_init, NULL)
int usb_temp_sysctl(SYSCTL_HANDLER_ARGS)
MODULE_VERSION(usb_template, 1)
static int sysctl_hw_usb_template_power(SYSCTL_HANDLER_ARGS)
void usb_decode_str_desc(struct usb_string_descriptor *sd, char *buf, size_t buflen)
static void usb_make_interface_desc(struct usb_temp_setup *, const struct usb_temp_interface_desc *)
static usb_error_t usb_temp_get_desc(struct usb_device *, struct usb_device_request *, const void **, uint16_t *)
SYSCTL_NODE(_hw_usb, OID_AUTO, templates, CTLFLAG_RW|CTLFLAG_MPSAFE, 0, "USB device side templates")
static void usb_make_config_desc(struct usb_temp_setup *, const struct usb_temp_config_desc *)
static int usb_template_power
usb_error_t usb_temp_setup(struct usb_device *udev, const struct usb_temp_device_desc *tdd)
static const void * usb_temp_get_vendor_desc(struct usb_device *, const struct usb_device_request *, uint16_t *plen)
struct usb_temp_device_desc usb_template_cdceem
struct usb_temp_device_desc usb_template_mtp
struct usb_temp_device_desc usb_template_mouse
struct usb_temp_device_desc usb_template_modem
struct usb_temp_device_desc usb_template_audio
struct usb_temp_device_desc usb_template_multi
struct usb_temp_device_desc usb_template_phone
struct usb_temp_device_desc usb_template_serialnet
struct usb_temp_device_desc usb_template_msc
struct usb_temp_device_desc usb_template_midi
struct usb_temp_device_desc usb_template_kbd
struct usb_temp_device_desc usb_template_cdce
uint8_t usb_make_str_desc(void *ptr, uint16_t max_len, const char *s)