Changeset View
Changeset View
Standalone View
Standalone View
sys/dev/usb/template/usb_template.c
Show First 20 Lines • Show All 59 Lines • ▼ Show 20 Lines | |||||
#include "usbdevs.h" | #include "usbdevs.h" | ||||
#include <dev/usb/usb_cdc.h> | #include <dev/usb/usb_cdc.h> | ||||
#include <dev/usb/usb_core.h> | #include <dev/usb/usb_core.h> | ||||
#include <dev/usb/usb_dynamic.h> | #include <dev/usb/usb_dynamic.h> | ||||
#include <dev/usb/usb_busdma.h> | #include <dev/usb/usb_busdma.h> | ||||
#include <dev/usb/usb_process.h> | #include <dev/usb/usb_process.h> | ||||
#include <dev/usb/usb_device.h> | #include <dev/usb/usb_device.h> | ||||
#include <dev/usb/usb_util.h> | |||||
#define USB_DEBUG_VAR usb_debug | #define USB_DEBUG_VAR usb_debug | ||||
#include <dev/usb/usb_debug.h> | #include <dev/usb/usb_debug.h> | ||||
#include <dev/usb/usb_controller.h> | #include <dev/usb/usb_controller.h> | ||||
#include <dev/usb/usb_bus.h> | #include <dev/usb/usb_bus.h> | ||||
#include <dev/usb/usb_request.h> | #include <dev/usb/usb_request.h> | ||||
#include <dev/usb/template/usb_template.h> | #include <dev/usb/template/usb_template.h> | ||||
#endif /* USB_GLOBAL_INCLUDE_FILE */ | #endif /* USB_GLOBAL_INCLUDE_FILE */ | ||||
SYSCTL_NODE(_hw_usb, OID_AUTO, templates, CTLFLAG_RW, 0, | |||||
"USB device side templates"); | |||||
MODULE_DEPEND(usb_template, usb, 1, 1, 1); | MODULE_DEPEND(usb_template, usb, 1, 1, 1); | ||||
MODULE_VERSION(usb_template, 1); | MODULE_VERSION(usb_template, 1); | ||||
/* function prototypes */ | /* function prototypes */ | ||||
static void usb_make_raw_desc(struct usb_temp_setup *, const uint8_t *); | static void usb_make_raw_desc(struct usb_temp_setup *, const uint8_t *); | ||||
static void usb_make_endpoint_desc(struct usb_temp_setup *, | static void usb_make_endpoint_desc(struct usb_temp_setup *, | ||||
const struct usb_temp_endpoint_desc *); | const struct usb_temp_endpoint_desc *); | ||||
Show All 21 Lines | |||||
static const void *usb_temp_get_vendor_desc(struct usb_device *, | static const void *usb_temp_get_vendor_desc(struct usb_device *, | ||||
const struct usb_device_request *, uint16_t *plen); | const struct usb_device_request *, uint16_t *plen); | ||||
static const void *usb_temp_get_hub_desc(struct usb_device *); | static const void *usb_temp_get_hub_desc(struct usb_device *); | ||||
static usb_error_t usb_temp_get_desc(struct usb_device *, | static usb_error_t usb_temp_get_desc(struct usb_device *, | ||||
struct usb_device_request *, const void **, uint16_t *); | struct usb_device_request *, const void **, uint16_t *); | ||||
static usb_error_t usb_temp_setup_by_index(struct usb_device *, | static usb_error_t usb_temp_setup_by_index(struct usb_device *, | ||||
uint16_t index); | uint16_t index); | ||||
static void usb_temp_init(void *); | static void usb_temp_init(void *); | ||||
/*------------------------------------------------------------------------* | |||||
* usb_decode_str_desc | |||||
* | |||||
* Helper function to decode string descriptors into a C string. | |||||
*------------------------------------------------------------------------*/ | |||||
void | |||||
usb_decode_str_desc(struct usb_string_descriptor *sd, char *buf, size_t buflen) | |||||
{ | |||||
size_t i; | |||||
for (i = 0; i < buflen - 1 && i < sd->bLength / 2; i++) | |||||
buf[i] = UGETW(sd->bString[i]); | |||||
buf[i] = '\0'; | |||||
hselasky: I think this "i++" is wrong - not needed. | |||||
Done Inline Actionstechnically "size_t i;" ?? hselasky: technically "size_t i;" ?? | |||||
Not Done Inline ActionsHuh, you're right; not sure why I put it there. Seems to work fine without it. trasz: Huh, you're right; not sure why I put it there. Seems to work fine without it. | |||||
} | |||||
/*------------------------------------------------------------------------* | |||||
* usb_temp_sysctl | |||||
* | |||||
* Callback for SYSCTL_PROC(9), to set and retrieve template string | |||||
* descriptors. | |||||
*------------------------------------------------------------------------*/ | |||||
int | |||||
usb_temp_sysctl(SYSCTL_HANDLER_ARGS) | |||||
{ | |||||
char buf[128]; | |||||
struct usb_string_descriptor *sd = arg1; | |||||
size_t len, sdlen = arg2; | |||||
int error; | |||||
usb_decode_str_desc(sd, buf, sizeof(buf)); | |||||
error = sysctl_handle_string(oidp, buf, sizeof(buf), req); | |||||
if (error != 0 || req->newptr == NULL) | |||||
return (error); | |||||
len = usb_make_str_desc(sd, sdlen, buf); | |||||
if (len == 0) | |||||
return (EINVAL); | |||||
return (0); | |||||
} | |||||
/*------------------------------------------------------------------------* | /*------------------------------------------------------------------------* | ||||
* usb_make_raw_desc | * usb_make_raw_desc | ||||
* | * | ||||
* This function will insert a raw USB descriptor into the generated | * This function will insert a raw USB descriptor into the generated | ||||
* USB configuration. | * USB configuration. | ||||
*------------------------------------------------------------------------*/ | *------------------------------------------------------------------------*/ | ||||
static void | static void | ||||
▲ Show 20 Lines • Show All 1,277 Lines • Show Last 20 Lines |
I think this "i++" is wrong - not needed.