Date: Mon, 27 Apr 2009 20:27:54 GMT From: Sylvestre Gallon <syl@FreeBSD.org> To: Perforce Change Reviews <perforce@FreeBSD.org> Subject: PERFORCE change 161208 for review Message-ID: <200904272027.n3RKRsEf087765@repoman.freebsd.org>
next in thread | raw e-mail | index | archive | help
http://perforce.freebsd.org/chv.cgi?CH=161208 Change 161208 by syl@syl_atuin on 2009/04/27 20:27:13 Add support for libusb10 descriptors. Affected files ... .. //depot/projects/soc2009/syl_usb/src/lib/libusb/libusb.h#2 edit .. //depot/projects/soc2009/syl_usb/src/lib/libusb/libusb10_desc.c#2 edit Differences ... ==== //depot/projects/soc2009/syl_usb/src/lib/libusb/libusb.h#2 (text+ko) ==== @@ -260,7 +260,7 @@ uint8_t bInterval; uint8_t bRefresh; uint8_t bSynchAddress; - const unsigned char *extra; + unsigned char *extra; int extra_length; } libusb_endpoint_descriptor; @@ -274,13 +274,13 @@ uint8_t bInterfaceSubClass; uint8_t bInterfaceProtocol; uint8_t iInterface; - const struct libusb_endpoint_descriptor *endpoint; - const unsigned char *extra; + struct libusb_endpoint_descriptor *endpoint; + unsigned char *extra; int extra_length; } libusb_interface_descriptor; typedef struct libusb_interface { - const struct libusb_interface_descriptor *altsetting; + struct libusb_interface_descriptor *altsetting; int num_altsetting; } libusb_interface; @@ -293,8 +293,8 @@ uint8_t iConfiguration; uint8_t bmAttributes; uint8_t MaxPower; - const struct libusb_interface *interface; - const unsigned char *extra; + struct libusb_interface *interface; + unsigned char *extra; int extra_length; } libusb_config_descriptor; ==== //depot/projects/soc2009/syl_usb/src/lib/libusb/libusb10_desc.c#2 (text+ko) ==== @@ -39,6 +39,30 @@ libusb_get_device_descriptor(libusb_device * dev, struct libusb_device_descriptor *desc) { + struct LIBUSB20_DEVICE_DESC_DECODED *pdesc; + struct libusb20_device *pdev; + + if ((dev == NULL) || (desc == NULL)) + return (LIBUSB_ERROR_NO_MEM); + + pdev = dev->os_priv; + pdesc = libusb20_dev_get_device_desc(pdev); + + desc->bLength = pdesc->bLength; + desc->bDescriptorType = pdesc->bDescriptorType; + desc->bcdUSB = pdesc->bcdUSB; + desc->bDeviceClass = pdesc->bDeviceClass; + desc->bDeviceSubClass = pdesc->bDeviceSubClass; + desc->bDeviceProtocol = pdesc->bDeviceProtocol; + desc->bMaxPacketSize0 = pdesc->bMaxPacketSize0; + desc->idVendor = pdesc->idVendor; + desc->idProduct = pdesc->idProduct; + desc->bcdDevice = pdesc->bcdDevice; + desc->iManufacturer = pdesc->iManufacturer; + desc->iProduct = desc->iProduct; + desc->iSerialNumber = desc->iSerialNumber; + desc->bNumConfigurations = desc->bNumConfigurations; + return (0); } @@ -46,13 +70,101 @@ libusb_get_active_config_descriptor(libusb_device * dev, struct libusb_config_descriptor **config) { - return (0); + struct libusb20_device *pdev; + uint8_t idx; + + idx = libusb20_dev_get_config_index(pdev); + + return (libusb_get_config_descriptor(dev, idx, config)); } + +/* + * Need rework, this function is pretty ugly now ... + */ int libusb_get_config_descriptor(libusb_device * dev, uint8_t config_index, struct libusb_config_descriptor **config) { + struct LIBUSB20_CONFIG_DESC_DECODED *pdesc; + struct LIBUSB20_INTERFACE_DESC_DECODED *pint; + struct LIBUSB20_ENDPOINT_DESC_DECODED *pend; + libusb_config_descriptor *conf; + libusb_interface_descriptor *ifdesc; + libusb_endpoint_descriptor *enddesc; + const char *rawdesc; + struct libusb20_device *pdev; + int i, j; + + if ((dev == NULL) || (config == NULL)) + return (LIBUSB_ERROR_NO_MEM); + + *config = conf = malloc(sizeof(struct libusb_config_descriptor)); + if (conf == NULL) + return (LIBUSB_ERROR_NO_MEM); + + if (config_index > dev->num_configurations) + return (LIBUSB_ERROR_NOT_FOUND); + + pdev = dev->os_priv; + rawdesc = libusb20_dev_get_desc(pdev); + + j = 0x12; + for (i = 0 ; i < dev->num_configurations && i != config_index ; i++) { + pdesc = (struct LIBUSB20_CONFIG_DESC_DECODED *) + &rawdesc[j]; + j += pdesc->wTotalLength; + } + + conf->bLength = pdesc->bLength; + conf->bDescriptorType = pdesc->bDescriptorType; + conf->wTotalLength = pdesc->wTotalLength; + conf->bNumInterfaces = pdesc->bNumInterfaces; + conf->bConfigurationValue = pdesc->bConfigurationValue; + conf->iConfiguration = pdesc->iConfiguration; + conf->bmAttributes = pdesc->bmAttributes; + conf->MaxPower = pdesc->bMaxPower; + + conf->interface = malloc(pdesc->bNumInterfaces * sizeof(*(conf->interface))); + pint = (struct LIBUSB20_INTERFACE_DESC_DECODED *) + ((uint32_t)pdesc + (uint32_t)pdesc->bLength); + + for (i = 0 ; i < conf->bNumInterfaces ; i++) { + conf->interface[i].num_altsetting = pdesc->bNumInterfaces; + ifdesc = malloc(sizeof(*(conf->interface[i].altsetting))); + conf->interface[i].altsetting = ifdesc; + + ifdesc->bLength = (uint8_t)pint->bLength; + ifdesc->bDescriptorType = pint->bDescriptorType; + ifdesc->bInterfaceNumber = pint->bInterfaceNumber; + ifdesc->bAlternateSetting = pint->bAlternateSetting; + ifdesc->bNumEndpoints = pint->bNumEndpoints; + ifdesc->bInterfaceClass = pint->bInterfaceClass; + ifdesc->bInterfaceSubClass = pint->bInterfaceSubClass; + ifdesc->bInterfaceProtocol = pint->bInterfaceProtocol; + ifdesc->iInterface = pint->iInterface; + + ifdesc->endpoint = malloc(pint->bNumEndpoints * + sizeof(struct libusb_endpoint_descriptor)); + pend = (struct LIBUSB20_ENDPOINT_DESC_DECODED *) + ((uint32_t)pint + (uint32_t)ifdesc->bLength); + + for (j = 0 ; j < pint->bNumEndpoints ; j++) { + enddesc = &(ifdesc->endpoint[j]); + enddesc->bLength = pend->bLength; + enddesc->bDescriptorType = pend->bDescriptorType; + enddesc->bEndpointAddress = pend->bEndpointAddress; + enddesc->bmAttributes = pend->bmAttributes; + enddesc->wMaxPacketSize = pend->wMaxPacketSize; + enddesc->bInterval = pend->bInterval; + enddesc->bRefresh = pend->bRefresh; + enddesc->bSynchAddress = pend->bSynchAddress; + pend = (struct LIBUSB20_ENDPOINT_DESC_DECODED *) + ((uint32_t)pend + (uint32_t)pend->bLength); + } + pint = (struct LIBUSB20_INTERFACE_DESC_DECODED*)pend; + /* XXX need Check on libusb10 for extra field */ + } return (0); } @@ -60,32 +172,62 @@ libusb_get_config_descriptor_by_value(libusb_device * dev, uint8_t bConfigurationValue, struct libusb_config_descriptor **config) { - return (0); + struct LIBUSB20_CONFIG_DESC_DECODED *pdesc; + struct libusb20_device *pdev; + const char *rawdesc; + int i, j; + + if (dev == NULL || config == NULL) + return (LIBUSB_ERROR_NO_MEM); + + pdev = dev->os_priv; + rawdesc = libusb20_dev_get_desc(pdev); + + j = 0x12; + for (i = 0 ; i < dev->num_configurations ; i++) { + pdesc = (struct LIBUSB20_CONFIG_DESC_DECODED *) + &rawdesc[j]; + j += pdesc->wTotalLength; + if (pdesc->bConfigurationValue == bConfigurationValue) + return (libusb_get_config_descriptor(dev, i, config)); + } + + return (LIBUSB_ERROR_NOT_FOUND); } void libusb_free_config_descriptor(struct libusb_config_descriptor *config) { - return; + int i, j; + + for (i = 0 ; i < config->bNumInterfaces ; i++) { + for (j = 0 ; j < config->interface[i].altsetting->bNumEndpoints ; j++) { + free((void *)config->interface[i].altsetting->endpoint[j].extra); + } + free((void *)config->interface[i].altsetting->endpoint); + free((void *)config->interface[i].altsetting->extra); + free((void *)config->interface[i].altsetting); + } + free((void *)config->interface); + free(config); } +/* + * Perhaps need a fix, because this function need to return + * the size of string on success and not 0 + */ + int libusb_get_string_descriptor_ascii(libusb_device_handle * dev, uint8_t desc_index, unsigned char *data, int length) { - return (0); -} + struct libusb20_device *pdev; + int ret; -static int -libusb_get_descriptor(libusb_device_handle * dev, uint8_t desc_type, - uint8_t desc_index, unsigned char *data, int length) -{ - return (0); -} + if (dev == NULL || data == NULL) + return (LIBUSB20_ERROR_NO_MEM); -static int -libusb_get_string_descriptor(libusb_device_handle * dev, uint8_t desc_index, - uint16_t langid, unsigned char *data, int length) -{ - return (0); + pdev = dev->os_priv; + return (libusb20_dev_req_string_simple_sync(pdev, desc_index, + data, length)); }
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200904272027.n3RKRsEf087765>