Allocate the usb serial, manufacturer and product strings rather than use char

arrays in the usb_device struct. This also eliminates USB_HAVE_STRINGS.
This commit is contained in:
thompsa 2009-05-27 23:12:02 +00:00
parent 536e43cd2e
commit 3d7b880e84
6 changed files with 52 additions and 125 deletions

View File

@ -56,14 +56,6 @@
#define USB_HAVE_UGEN 1 #define USB_HAVE_UGEN 1
#endif #endif
/*
* The following macro defines if the code shall support any forms of
* ASCII strings.
*/
#ifndef USB_HAVE_STRINGS
#define USB_HAVE_STRINGS 1
#endif
/* /*
* The following macro defines if the code shall support BUS-DMA. * The following macro defines if the code shall support BUS-DMA.
*/ */

View File

@ -71,9 +71,7 @@ static void usb2_suspend_resume_sub(struct usb2_device *, device_t,
uint8_t); uint8_t);
static void usb2_clear_stall_proc(struct usb2_proc_msg *_pm); static void usb2_clear_stall_proc(struct usb2_proc_msg *_pm);
usb2_error_t usb2_config_parse(struct usb2_device *, uint8_t, uint8_t); usb2_error_t usb2_config_parse(struct usb2_device *, uint8_t, uint8_t);
#if USB_HAVE_STRINGS static void usb2_set_device_strings(struct usb2_device *);
static void usb2_check_strings(struct usb2_device *);
#endif
#if USB_HAVE_UGEN #if USB_HAVE_UGEN
static void usb2_notify_addq(const char *type, struct usb2_device *); static void usb2_notify_addq(const char *type, struct usb2_device *);
static void usb2_fifo_free_wrap(struct usb2_device *, uint8_t, uint8_t); static void usb2_fifo_free_wrap(struct usb2_device *, uint8_t, uint8_t);
@ -1676,32 +1674,8 @@ usb2_alloc_device(device_t parent_dev, struct usb2_bus *bus,
/* assume 100mA bus powered for now. Changed when configured. */ /* assume 100mA bus powered for now. Changed when configured. */
udev->power = USB_MIN_POWER; udev->power = USB_MIN_POWER;
/* fetch the vendor and product strings from the device */
#if USB_HAVE_STRINGS usb2_set_device_strings(udev);
/* get serial number string */
err = usb2_req_get_string_any
(udev, NULL, (char *)scratch_ptr,
scratch_size, udev->ddesc.iSerialNumber);
strlcpy(udev->serial, (char *)scratch_ptr, sizeof(udev->serial));
/* get manufacturer string */
err = usb2_req_get_string_any
(udev, NULL, (char *)scratch_ptr,
scratch_size, udev->ddesc.iManufacturer);
strlcpy(udev->manufacturer, (char *)scratch_ptr, sizeof(udev->manufacturer));
/* get product string */
err = usb2_req_get_string_any
(udev, NULL, (char *)scratch_ptr,
scratch_size, udev->ddesc.iProduct);
strlcpy(udev->product, (char *)scratch_ptr, sizeof(udev->product));
/* finish up all the strings */
usb2_check_strings(udev);
#endif
if (udev->flags.usb_mode == USB_MODE_HOST) { if (udev->flags.usb_mode == USB_MODE_HOST) {
uint8_t config_index; uint8_t config_index;
@ -2113,11 +2087,7 @@ usb2_devinfo(struct usb2_device *udev, char *dst_ptr, uint16_t dst_len)
if (udd->bDeviceClass != 0xFF) { if (udd->bDeviceClass != 0xFF) {
snprintf(dst_ptr, dst_len, "%s %s, class %d/%d, rev %x.%02x/" snprintf(dst_ptr, dst_len, "%s %s, class %d/%d, rev %x.%02x/"
"%x.%02x, addr %d", "%x.%02x, addr %d",
#if USB_HAVE_STRINGS
udev->manufacturer, udev->product, udev->manufacturer, udev->product,
#else
"-", "-",
#endif
udd->bDeviceClass, udd->bDeviceSubClass, udd->bDeviceClass, udd->bDeviceSubClass,
(bcdUSB >> 8), bcdUSB & 0xFF, (bcdUSB >> 8), bcdUSB & 0xFF,
(bcdDevice >> 8), bcdDevice & 0xFF, (bcdDevice >> 8), bcdDevice & 0xFF,
@ -2125,18 +2095,13 @@ usb2_devinfo(struct usb2_device *udev, char *dst_ptr, uint16_t dst_len)
} else { } else {
snprintf(dst_ptr, dst_len, "%s %s, rev %x.%02x/" snprintf(dst_ptr, dst_len, "%s %s, rev %x.%02x/"
"%x.%02x, addr %d", "%x.%02x, addr %d",
#if USB_HAVE_STRINGS
udev->manufacturer, udev->product, udev->manufacturer, udev->product,
#else
"-", "-",
#endif
(bcdUSB >> 8), bcdUSB & 0xFF, (bcdUSB >> 8), bcdUSB & 0xFF,
(bcdDevice >> 8), bcdDevice & 0xFF, (bcdDevice >> 8), bcdDevice & 0xFF,
udev->address); udev->address);
} }
} }
#if USB_HAVE_STRINGS
#if USB_VERBOSE #if USB_VERBOSE
/* /*
* Descriptions of of known vendors and devices ("products"). * Descriptions of of known vendors and devices ("products").
@ -2155,85 +2120,74 @@ struct usb_knowndev {
#include "usbdevs_data.h" #include "usbdevs_data.h"
#endif /* USB_VERBOSE */ #endif /* USB_VERBOSE */
/*------------------------------------------------------------------------*
* usb2_check_strings
*
* This function checks the manufacturer and product strings and will
* fill in defaults for missing strings.
*------------------------------------------------------------------------*/
static void static void
usb2_check_strings(struct usb2_device *udev) usb2_set_device_strings(struct usb2_device *udev)
{ {
struct usb2_device_descriptor *udd = &udev->ddesc; struct usb2_device_descriptor *udd = &udev->ddesc;
const char *vendor;
const char *product;
#if USB_VERBOSE #if USB_VERBOSE
const struct usb_knowndev *kdp; const struct usb_knowndev *kdp;
#endif #endif
char temp[64];
uint16_t vendor_id; uint16_t vendor_id;
uint16_t product_id; uint16_t product_id;
usb2_trim_spaces(udev->manufacturer);
usb2_trim_spaces(udev->product);
if (udev->manufacturer[0]) {
vendor = udev->manufacturer;
} else {
vendor = NULL;
}
if (udev->product[0]) {
product = udev->product;
} else {
product = NULL;
}
vendor_id = UGETW(udd->idVendor); vendor_id = UGETW(udd->idVendor);
product_id = UGETW(udd->idProduct); product_id = UGETW(udd->idProduct);
#if USB_VERBOSE /* get serial number string */
if (vendor == NULL || product == NULL) { bzero(temp, sizeof(temp));
usb2_req_get_string_any(udev, NULL, temp, sizeof(temp),
udev->ddesc.iSerialNumber);
udev->serial = strdup(temp, M_USB);
for (kdp = usb_knowndevs; /* get manufacturer string */
kdp->vendorname != NULL; bzero(temp, sizeof(temp));
kdp++) { usb2_req_get_string_any(udev, NULL, temp, sizeof(temp),
udev->ddesc.iManufacturer);
usb2_trim_spaces(temp);
if (temp[0] != '\0')
udev->manufacturer = strdup(temp, M_USB);
/* get product string */
bzero(temp, sizeof(temp));
usb2_req_get_string_any(udev, NULL, temp, sizeof(temp),
udev->ddesc.iProduct);
usb2_trim_spaces(temp);
if (temp[0] != '\0')
udev->product = strdup(temp, M_USB);
#if USB_VERBOSE
if (udev->manufacturer == NULL || udev->product == NULL) {
for (kdp = usb_knowndevs; kdp->vendorname != NULL; kdp++) {
if (kdp->vendor == vendor_id && if (kdp->vendor == vendor_id &&
(kdp->product == product_id || (kdp->product == product_id ||
(kdp->flags & USB_KNOWNDEV_NOPROD) != 0)) (kdp->flags & USB_KNOWNDEV_NOPROD) != 0))
break; break;
} }
if (kdp->vendorname != NULL) { if (kdp->vendorname != NULL) {
if (vendor == NULL) /* XXX should use pointer to knowndevs string */
vendor = kdp->vendorname; if (udev->manufacturer == NULL) {
if (product == NULL) udev->manufacturer = strdup(kdp->vendorname,
product = (kdp->flags & USB_KNOWNDEV_NOPROD) == 0 ? M_USB);
kdp->productname : NULL; }
if (udev->product == NULL &&
(kdp->flags & USB_KNOWNDEV_NOPROD) == 0) {
udev->product = strdup(kdp->productname,
M_USB);
}
} }
} }
#endif #endif
if (vendor && *vendor) { /* Provide default strings if none were found */
if (udev->manufacturer != vendor) { if (udev->manufacturer == NULL) {
strlcpy(udev->manufacturer, vendor, snprintf(temp, sizeof(temp), "vendor 0x%04x", vendor_id);
sizeof(udev->manufacturer)); udev->manufacturer = strdup(temp, M_USB);
}
} else {
snprintf(udev->manufacturer,
sizeof(udev->manufacturer), "vendor 0x%04x", vendor_id);
} }
if (udev->product == NULL) {
if (product && *product) { snprintf(temp, sizeof(temp), "product 0x%04x", product_id);
if (udev->product != product) { udev->product = strdup(temp, M_USB);
strlcpy(udev->product, product,
sizeof(udev->product));
}
} else {
snprintf(udev->product,
sizeof(udev->product), "product 0x%04x", product_id);
} }
} }
#endif
/* /*
* Returns: * Returns:
@ -2367,11 +2321,7 @@ usb2_notify_addq(const char *type, struct usb2_device *udev)
UGETW(udev->ddesc.idProduct), UGETW(udev->ddesc.idProduct),
udev->ddesc.bDeviceClass, udev->ddesc.bDeviceClass,
udev->ddesc.bDeviceSubClass, udev->ddesc.bDeviceSubClass,
#if USB_HAVE_STRINGS
udev->serial, udev->serial,
#else
"",
#endif
udev->port_no, udev->port_no,
udev->parent_hub != NULL ? udev->parent_hub != NULL ?
udev->parent_hub->ugen_name : udev->parent_hub->ugen_name :

View File

@ -174,11 +174,9 @@ struct usb2_device {
struct usb2_endpoint_descriptor default_ep_desc; /* for pipe 0 */ struct usb2_endpoint_descriptor default_ep_desc; /* for pipe 0 */
struct usb2_device_descriptor ddesc; /* device descriptor */ struct usb2_device_descriptor ddesc; /* device descriptor */
#if USB_HAVE_STRINGS char *serial; /* serial number */
char serial[64]; /* serial number */ char *manufacturer; /* manufacturer string */
char manufacturer[64]; /* manufacturer string */ char *product; /* product string */
char product[64]; /* product string */
#endif
}; };
/* globals */ /* globals */

View File

@ -801,14 +801,9 @@ usb2_gen_fill_deviceinfo(struct usb2_fifo *f, struct usb2_device_info *di)
di->udi_bus = device_get_unit(udev->bus->bdev); di->udi_bus = device_get_unit(udev->bus->bdev);
di->udi_addr = udev->address; di->udi_addr = udev->address;
di->udi_index = udev->device_index; di->udi_index = udev->device_index;
#if USB_HAVE_STRINGS strlcpy(di->udi_serial, udev->serial, sizeof(di->udi_serial));
strlcpy(di->udi_serial, udev->serial, strlcpy(di->udi_vendor, udev->manufacturer, sizeof(di->udi_vendor));
sizeof(di->udi_serial)); strlcpy(di->udi_product, udev->product, sizeof(di->udi_product));
strlcpy(di->udi_vendor, udev->manufacturer,
sizeof(di->udi_vendor));
strlcpy(di->udi_product, udev->product,
sizeof(di->udi_product));
#endif
usb2_printBCD(di->udi_release, sizeof(di->udi_release), usb2_printBCD(di->udi_release, sizeof(di->udi_release),
UGETW(udev->ddesc.bcdDevice)); UGETW(udev->ddesc.bcdDevice));
di->udi_vendorNo = UGETW(udev->ddesc.idVendor); di->udi_vendorNo = UGETW(udev->ddesc.idVendor);

View File

@ -1006,11 +1006,7 @@ uhub_child_pnpinfo_string(device_t parent, device_t child,
UGETW(res.udev->ddesc.idProduct), UGETW(res.udev->ddesc.idProduct),
res.udev->ddesc.bDeviceClass, res.udev->ddesc.bDeviceClass,
res.udev->ddesc.bDeviceSubClass, res.udev->ddesc.bDeviceSubClass,
#if USB_HAVE_STRINGS
res.udev->serial, res.udev->serial,
#else
"",
#endif
iface->idesc->bInterfaceClass, iface->idesc->bInterfaceClass,
iface->idesc->bInterfaceSubClass); iface->idesc->bInterfaceSubClass);
} else { } else {

View File

@ -78,7 +78,6 @@ device_delete_all_children(device_t dev)
void void
device_set_usb2_desc(device_t dev) device_set_usb2_desc(device_t dev)
{ {
#if USB_HAVE_STRINGS
struct usb2_attach_arg *uaa; struct usb2_attach_arg *uaa;
struct usb2_device *udev; struct usb2_device *udev;
struct usb2_interface *iface; struct usb2_interface *iface;
@ -121,7 +120,6 @@ device_set_usb2_desc(device_t dev)
device_set_desc_copy(dev, temp_p); device_set_desc_copy(dev, temp_p);
device_printf(dev, "<%s> on %s\n", temp_p, device_printf(dev, "<%s> on %s\n", temp_p,
device_get_nameunit(udev->bus->bdev)); device_get_nameunit(udev->bus->bdev));
#endif
} }
/*------------------------------------------------------------------------* /*------------------------------------------------------------------------*
@ -181,7 +179,6 @@ usb2_printBCD(char *p, uint16_t p_len, uint16_t bcd)
* This function removes spaces at the beginning and the end of the string * This function removes spaces at the beginning and the end of the string
* pointed to by the "p" argument. * pointed to by the "p" argument.
*------------------------------------------------------------------------*/ *------------------------------------------------------------------------*/
#if USB_HAVE_STRINGS
void void
usb2_trim_spaces(char *p) usb2_trim_spaces(char *p)
{ {
@ -198,7 +195,6 @@ usb2_trim_spaces(char *p)
e = p; e = p;
*e = 0; /* kill trailing spaces */ *e = 0; /* kill trailing spaces */
} }
#endif
/*------------------------------------------------------------------------* /*------------------------------------------------------------------------*
* usb2_make_str_desc - convert an ASCII string into a UNICODE string * usb2_make_str_desc - convert an ASCII string into a UNICODE string