From owner-p4-projects@FreeBSD.ORG Thu May 28 17:28:27 2009 Return-Path: Delivered-To: p4-projects@freebsd.org Received: by hub.freebsd.org (Postfix, from userid 32767) id E5E3F10656B5; Thu, 28 May 2009 17:28:26 +0000 (UTC) Delivered-To: perforce@FreeBSD.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 94E2610656A6 for ; Thu, 28 May 2009 17:28:26 +0000 (UTC) (envelope-from syl@FreeBSD.org) Received: from repoman.freebsd.org (repoman.freebsd.org [IPv6:2001:4f8:fff6::29]) by mx1.freebsd.org (Postfix) with ESMTP id 7C6388FC26 for ; Thu, 28 May 2009 17:28:26 +0000 (UTC) (envelope-from syl@FreeBSD.org) Received: from repoman.freebsd.org (localhost [127.0.0.1]) by repoman.freebsd.org (8.14.3/8.14.3) with ESMTP id n4SHSQwq073403 for ; Thu, 28 May 2009 17:28:26 GMT (envelope-from syl@FreeBSD.org) Received: (from perforce@localhost) by repoman.freebsd.org (8.14.3/8.14.3/Submit) id n4SHSQ0t073401 for perforce@freebsd.org; Thu, 28 May 2009 17:28:26 GMT (envelope-from syl@FreeBSD.org) Date: Thu, 28 May 2009 17:28:26 GMT Message-Id: <200905281728.n4SHSQ0t073401@repoman.freebsd.org> X-Authentication-Warning: repoman.freebsd.org: perforce set sender to syl@FreeBSD.org using -f From: Sylvestre Gallon To: Perforce Change Reviews Cc: Subject: PERFORCE change 162951 for review X-BeenThere: p4-projects@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: p4 projects tree changes List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 28 May 2009 17:28:28 -0000 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;