Date: Fri, 1 May 2009 16:41:51 GMT From: Sylvestre Gallon <syl@FreeBSD.org> To: Perforce Change Reviews <perforce@FreeBSD.org> Subject: PERFORCE change 161437 for review Message-ID: <200905011641.n41GfpGD076429@repoman.freebsd.org>
next in thread | raw e-mail | index | archive | help
http://perforce.freebsd.org/chv.cgi?CH=161437 Change 161437 by syl@syl_atuin on 2009/05/01 16:41:34 - Adding strlen to string descriptor func following Hans Petter Selasky fix. - Adding altsetting handling to get_config. - Implementing libusb_get_max_packet_size. - Implementing libusb_alloc_transfer. - Implementing libusb_free_transfer. Affected files ... .. //depot/projects/soc2009/syl_usb/src/lib/libusb/libusb.h#4 edit .. //depot/projects/soc2009/syl_usb/src/lib/libusb/libusb10.c#2 edit .. //depot/projects/soc2009/syl_usb/src/lib/libusb/libusb10_desc.c#6 edit Differences ... ==== //depot/projects/soc2009/syl_usb/src/lib/libusb/libusb.h#4 (text+ko) ==== @@ -310,7 +310,7 @@ unsigned int length; unsigned int actual_length; enum libusb_transfer_status status; -} libusb_iso_packet_descriptor; +} libusb_iso_packet_descriptor __aligned(sizeof(void *)); struct libusb_transfer; @@ -330,7 +330,7 @@ unsigned char *buffer; int num_iso_packets; struct libusb_iso_packet_descriptor iso_packet_desc[0]; -} libusb_transfer; +} libusb_transfer __aligned(sizeof(void *)); typedef struct libusb_pollfd { int fd; ==== //depot/projects/soc2009/syl_usb/src/lib/libusb/libusb10.c#2 (text+ko) ==== @@ -186,9 +186,35 @@ } int -libusb_get_max_packet_size(libusb_device * dev, unsigned char endpoint) +libusb_get_max_packet_size(libusb_device *dev, unsigned char endpoint) { - return (0); + struct libusb_config_descriptor *pdconf; + struct libusb_interface *pinf; + struct libusb_interface_descriptor *pdinf; + struct libusb_endpoint_descriptor *pdend; + int i, j, k, ret; + + if (libusb_get_active_config_descriptor(dev, &pdconf) < 0) + return (LIBUSB_ERROR_OTHER); + + ret = LIBUSB_ERROR_NOT_FOUND; + for (i = 0 ; i < pdconf->bNumInterfaces ; i++) { + pinf = &pdconf->interface[i]; + for (j = 0 ; j < pinf->num_altsetting ; j++) { + pdinf = &pinf->altsetting[j]; + for (k = 0 ; k < pdinf->bNumEndpoints ; k++) { + pdend = &pdinf->endpoint[k]; + if (pdend->bEndpointAddress == endpoint) { + ret = pdend->wMaxPacketSize; + goto out; + } + } + } + } + +out: + libusb_free_config_descriptor(pdconf); + return (ret); } libusb_device * @@ -425,12 +451,33 @@ struct libusb_transfer * libusb_alloc_transfer(int iso_packets) { - return (NULL); + struct libusb_transfer *tr; + int len; + + len = sizeof(libusb_transfer) + + (iso_packets * sizeof(libusb_iso_packet_descriptor)); + + tr = malloc(len); + if (tr == NULL) + return (NULL); + + memset(tr, 0, len); + + return (tr); } void libusb_free_transfer(struct libusb_transfer *transfer) { + if (transfer == NULL) + return ; + + if (transfer->buffer) + free(transfer->buffer); + if (transfer->user_data) + free(transfer->user_data); + + free (transfer); return; } int ==== //depot/projects/soc2009/syl_usb/src/lib/libusb/libusb10_desc.c#6 (text+ko) ==== @@ -78,6 +78,10 @@ return (libusb_get_config_descriptor(dev, idx, config)); } +/* + * XXX Need to check if extra need a dup because + * XXX free pconf could free this char * + */ int libusb_get_config_descriptor(libusb_device * dev, uint8_t config_index, struct libusb_config_descriptor **config) @@ -88,7 +92,7 @@ struct libusb20_endpoint *pend; libusb_interface_descriptor *ifd; libusb_endpoint_descriptor *endd; - uint8_t nif, nend, i, j; + uint8_t nif, nend, nalt, i, j; if (dev == NULL || config == NULL) return (LIBUSB_ERROR_NO_MEM); @@ -99,14 +103,22 @@ if (pconf == NULL) return (LIBUSB_ERROR_NOT_FOUND); - nif = pconf->num_interface; + nalt = nif = pconf->num_interface; nend = 0; - for (i = 0 ; i < nif ; i++) + for (i = 0 ; i < nif ; i++) { + if (pconf->interface[i].num_altsetting > 1) + { + nalt += pconf->interface[i].num_altsetting; + for (j = 0 ; j < nalt ; j++) { + nend += pconf->interface[i].altsetting[j].num_endpoints; + } + } nend += pconf->interface[i].num_endpoints; + } *config = malloc(sizeof(libusb_config_descriptor) + (nif * sizeof(libusb_interface)) + - (nif * sizeof(libusb_interface_descriptor)) + + (nalt * sizeof(libusb_interface_descriptor)) + (nend * sizeof(libusb_endpoint_descriptor))); if (*config == NULL) { free(pconf); @@ -127,36 +139,39 @@ for ( i = 0 ; i < nif ; i++) { pinf = &pconf->interface[i]; - (*config)->interface[i].num_altsetting = pinf->num_altsetting; - ifd = (*config)->interface[i].altsetting; - ifd->bLength = pinf->desc.bLength; - ifd->bDescriptorType = pinf->desc.bDescriptorType; - ifd->bInterfaceNumber = pinf->desc.bInterfaceNumber; - ifd->bAlternateSetting = pinf->desc.bAlternateSetting; - ifd->bNumEndpoints = pinf->desc.bNumEndpoints; - ifd->bInterfaceClass = pinf->desc.bInterfaceClass; - ifd->bInterfaceSubClass = pinf->desc.bInterfaceSubClass; - ifd->bInterfaceProtocol = pinf->desc.bInterfaceProtocol; - ifd->iInterface = pinf->desc.iInterface; - ifd->extra_length = pinf->extra.len; - if (ifd->extra_length != 0) - ifd->extra = pinf->extra.ptr; - - for (j = 0 ; j < pinf->num_endpoints ; j++) { - pend = &pconf->interface[i].endpoints[j]; - endd = &ifd->endpoint[j]; - endd->bLength = pend->desc.bLength; - endd->bDescriptorType = pend->desc.bDescriptorType; - endd->bEndpointAddress = pend->desc.bEndpointAddress; - endd->bmAttributes = pend->desc.bmAttributes; - endd->wMaxPacketSize = pend->desc.wMaxPacketSize; - endd->bInterval = pend->desc.bInterval; - endd->bRefresh = pend->desc.bRefresh; - endd->bSynchAddress = pend->desc.bSynchAddress; - endd->extra_length = pend->extra.len; - if (endd->extra_length != 0) - endd->extra = pend->extra.ptr; - } + (*config)->interface[i].num_altsetting = pinf->num_altsetting + 1; + for (j = 0 ; j <= pinf->num_altsetting ; j++) { + if (j != 0) + pinf = &pconf->interface[i].altsetting[j]; + ifd = &(*config)->interface[i].altsetting[j]; + ifd->bLength = pinf->desc.bLength; + ifd->bDescriptorType = pinf->desc.bDescriptorType; + ifd->bInterfaceNumber = pinf->desc.bInterfaceNumber; + ifd->bAlternateSetting = pinf->desc.bAlternateSetting; + ifd->bNumEndpoints = pinf->desc.bNumEndpoints; + ifd->bInterfaceClass = pinf->desc.bInterfaceClass; + ifd->bInterfaceSubClass = pinf->desc.bInterfaceSubClass; + ifd->bInterfaceProtocol = pinf->desc.bInterfaceProtocol; + ifd->iInterface = pinf->desc.iInterface; + ifd->extra_length = pinf->extra.len; + if (ifd->extra_length != 0) + ifd->extra = pinf->extra.ptr; + for (j = 0 ; j < pinf->num_endpoints ; j++) { + pend = &pinf->endpoints[j]; + endd = &ifd->endpoint[j]; + endd->bLength = pend->desc.bLength; + endd->bDescriptorType = pend->desc.bDescriptorType; + endd->bEndpointAddress = pend->desc.bEndpointAddress; + endd->bmAttributes = pend->desc.bmAttributes; + endd->wMaxPacketSize = pend->desc.wMaxPacketSize; + endd->bInterval = pend->desc.bInterval; + endd->bRefresh = pend->desc.bRefresh; + endd->bSynchAddress = pend->desc.bSynchAddress; + endd->extra_length = pend->extra.len; + if (endd->extra_length != 0) + endd->extra = pend->extra.ptr; + } + } } free(pconf); @@ -210,6 +225,6 @@ pdev = dev->os_priv; if (libusb20_dev_req_string_simple_sync(pdev, desc_index, data, length) == 0) - return (length); + return (strlen(data)); return (LIBUSB_ERROR_OTHER); }
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200905011641.n41GfpGD076429>