Date: Thu, 28 May 2009 17:28:26 GMT From: Sylvestre Gallon <syl@FreeBSD.org> To: Perforce Change Reviews <perforce@FreeBSD.org> Subject: PERFORCE change 162951 for review Message-ID: <200905281728.n4SHSQ0t073401@repoman.freebsd.org>
next in thread | raw e-mail | index | archive | help
http://perforce.freebsd.org/chv.cgi?CH=162951 Change 162951 by syl@syl_rincewind on 2009/05/28 17:27:36 - Finish test2. test2 will dump the active configuration descriptors for each usb device. - Fix libusb_get_active_config_descriptor. - Fix libusb_get_config_descriptor. - use 16*4 instead of 16*2 for transfer_max (spotted by Hans Petter Selasky). Affected files ... .. //depot/projects/soc2009/syl_usb/libusb-tests/descriptors/test2/test2.c#3 edit .. //depot/projects/soc2009/syl_usb/src/lib/libusb/libusb10.c#15 edit .. //depot/projects/soc2009/syl_usb/src/lib/libusb/libusb10_desc.c#10 edit Differences ... ==== //depot/projects/soc2009/syl_usb/libusb-tests/descriptors/test2/test2.c#3 (text+ko) ==== @@ -8,53 +8,80 @@ int main(int ac, const char *av[]) { + libusb_device **devs_list; libusb_config_descriptor *cdesc; - libusb_device **devs_list; + libusb_interface_descriptor *idesc; + libusb_endpoint_descriptor *edesc; + int nb; int ret; - int i, j; + int i, j, k, l; printf("This program will dump the device" " active config descriptor for all the" " present devices.\n"); - cdesc = malloc(sizeof(libusb_config_descriptor)); - if (cdesc == NULL) { - perror("test1"); - return (EXIT_FAILURE); - } - if (libusb_init(&ctx) != 0) { fprintf(stderr, "libusb_init failed\n"); return (EXIT_FAILURE); } - if ((ret = libusb_get_device_list(ctx, &devs_list)) < 0) { + if ((nb = libusb_get_device_list(ctx, &devs_list)) < 0) { fprintf(stderr, "libusb_get_device_list failed with 0x%x error code\n", - ret); + nb); return (EXIT_FAILURE); } - if (ret == 0) { + if (nb == 0) { fprintf(stderr, "No device match or lack of permissions.\n"); return (EXIT_SUCCESS); } printf("\nThere are %i devices\n\n", ret); - for (i = 0 ; i < ret ; i++) { - printf("|-- device number = %i\n", i); - libusb_get_active_config_descriptor(devs_list[i], &cdesc); - printf("toto\n"); - if (libusb_get_active_config_descriptor == LIBUSB_SUCCESS) { - printf("|----\tbLength : 0x%.2x\n", cdesc->bLength); - printf("|----\tbDescriptorType : 0x%.2x\n", cdesc->bDescriptorType); - printf("|----\twTotalLength : 0x%.2x\n", cdesc->wTotalLength); - printf("|----\tbNumInterfaces : 0x%.2x\n", cdesc->bNumInterfaces); - printf("|----\tbConfigurationValue : 0x%.2x\n", cdesc->bConfigurationValue); - printf("|----\tiConfiguration : 0x%.2x\n", cdesc->iConfiguration); - printf("|----\tbmAttributes : 0x%.2x\n", cdesc->bmAttributes); - printf("|----\tMaxPower : 0x%.2x\n", cdesc->MaxPower); + for (i = 0 ; i < nb ; i++) { + printf("|-- device number = %i\n|\n", i); + ret = libusb_get_active_config_descriptor(devs_list[i], &cdesc); + if (ret == LIBUSB_SUCCESS) { + printf("|---- CONFIG :\n"); + printf("|---- bLength : 0x%.2x\n", cdesc->bLength); + printf("|---- bDescriptorType : 0x%.2x\n", cdesc->bDescriptorType); + printf("|---- wTotalLength : 0x%.2x\n", cdesc->wTotalLength); + printf("|---- bNumInterfaces : 0x%.2x\n", cdesc->bNumInterfaces); + printf("|---- bConfigurationValue : 0x%.2x\n", cdesc->bConfigurationValue); + printf("|---- iConfiguration : 0x%.2x\n", cdesc->iConfiguration); + printf("|---- bmAttributes : 0x%.2x\n", cdesc->bmAttributes); + printf("|---- MaxPower : 0x%.2x\n|\n", cdesc->MaxPower); + for (j = 0 ; j < cdesc->bNumInterfaces ; j++) { + for (k = 0 ; k < cdesc->interface[j].num_altsetting ; k++) { + idesc = &cdesc->interface[j].altsetting[k]; + printf("|------ INTERFACE :\n"); + printf("|------ Interface %i%i\n", j, k); + printf("|------ bLength 0x%.2x\n", idesc->bLength); + printf("|------ bDescriptorType 0x%.2x\n", idesc->bDescriptorType); + printf("|------ bInterfaceNumber 0x%.2x\n", idesc->bInterfaceNumber); + printf("|------ bAlternateSetting 0x%.2x\n", idesc->bAlternateSetting); + printf("|------ bNumEndpoints 0x%.2x\n", idesc->bNumEndpoints); + printf("|------ bInterfaceClass 0x%.2x\n", idesc->bInterfaceClass); + printf("|------ bInterfaceSubClass 0x%.2x\n", idesc->bInterfaceSubClass); + printf("|------ bInterfaceProtocol 0x%.2x\n", idesc->bInterfaceProtocol); + printf("|------ iInterface 0x%.2x\n|\n", idesc->iInterface); + for (l = 0 ; l < idesc->bNumEndpoints ; l++) { + edesc = &idesc->endpoint[l]; + printf("|-------- DESCRIPTOR :\n"); + printf("|-------- bLength 0x%.2x\n", edesc->bLength); + printf("|-------- bDescriptorType 0x%.2x\n", edesc->bDescriptorType); + printf("|-------- bEndpointAddress 0x%.2x\n", edesc->bEndpointAddress); + printf("|-------- bmAttributes 0x%.2x\n", edesc->bmAttributes); + printf("|-------- wMaxPacketSize 0x%.4x\n", edesc->wMaxPacketSize); + printf("|-------- bInterval 0x%.2x\n", edesc->bInterval); + printf("|-------- bRefresh 0x%.2x\n", edesc->bRefresh); + printf("|-------- bSynchAddress 0x%.2x\n|\n", edesc->bSynchAddress); + } + } + } } else { fprintf(stderr, "libusb_get_active_config_descriptor failed\n"); + return (EXIT_FAILURE); } + libusb_free_config_descriptor(cdesc); } return (EXIT_SUCCESS); } ==== //depot/projects/soc2009/syl_usb/src/lib/libusb/libusb10.c#15 (text+ko) ==== @@ -420,7 +420,7 @@ if (hdl == NULL) return (LIBUSB_ERROR_NO_MEM); - err = libusb20_dev_open(pdev, 16 * 2 /* number of endpoints */ ); + err = libusb20_dev_open(pdev, 16 * 4 /* number of endpoints */ ); if (err) { free(hdl); return (LIBUSB_ERROR_NO_MEM); ==== //depot/projects/soc2009/syl_usb/src/lib/libusb/libusb10_desc.c#10 (text+ko) ==== @@ -73,6 +73,7 @@ struct libusb20_device *pdev; uint8_t idx; + pdev = dev->os_priv; idx = libusb20_dev_get_config_index(pdev); return (libusb_get_config_descriptor(dev, idx, config)); @@ -92,7 +93,8 @@ struct libusb20_endpoint *pend; libusb_interface_descriptor *ifd; libusb_endpoint_descriptor *endd; - uint8_t nif, nend, nalt, i, j; + uint8_t nif, nend, nalt, i, j, k; + uint32_t if_idx, endp_idx; if (dev == NULL || config == NULL) return (LIBUSB_ERROR_INVALID_PARAM); @@ -125,6 +127,35 @@ return (LIBUSB_ERROR_NO_MEM); } + (*config)->interface = (libusb_interface *)(*config + + sizeof(libusb_config_descriptor)); + for ( i = if_idx = endp_idx = 0 ; i < nif ; if_idx, i++) { + (*config)->interface[i].altsetting = (libusb_interface_descriptor *) + (*config + sizeof(libusb_config_descriptor) + + (nif * sizeof(libusb_interface)) + + (if_idx * sizeof(libusb_interface_descriptor))); + (*config)->interface[i].altsetting[0].endpoint = + (libusb_endpoint_descriptor *) (*config + + sizeof(libusb_config_descriptor) + + (nif * sizeof(libusb_interface)) + + (nalt * sizeof(libusb_interface_descriptor)) + + (endp_idx * sizeof(libusb_endpoint_descriptor))); + endp_idx += pconf->interface[i].num_endpoints; + + if (pconf->interface[i].num_altsetting > 0) + { + for ( j = 0 ; j < pconf->interface[i].num_altsetting ; j++, if_idx++) { + (*config)->interface[i].altsetting[j + 1].endpoint = + (libusb_endpoint_descriptor *) (*config + + sizeof(libusb_config_descriptor) + + (nif * sizeof(libusb_interface)) + + (nalt * sizeof(libusb_interface_descriptor)) + + (endp_idx * sizeof(libusb_endpoint_descriptor))); + endp_idx += pconf->interface[i].altsetting[j].num_endpoints; + } + } + } + (*config)->bLength = pconf->desc.bLength; (*config)->bDescriptorType = pconf->desc.bDescriptorType; (*config)->wTotalLength = pconf->desc.wTotalLength;
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200905281728.n4SHSQ0t073401>