Date: Sun, 31 May 2009 13:12:10 GMT From: Sylvestre Gallon <syl@FreeBSD.org> To: Perforce Change Reviews <perforce@FreeBSD.org> Subject: PERFORCE change 163164 for review Message-ID: <200905311312.n4VDCA55075343@repoman.freebsd.org>
next in thread | raw e-mail | index | archive | help
http://perforce.freebsd.org/chv.cgi?CH=163164 Change 163164 by syl@syl_rincewind on 2009/05/31 13:11:38 Implement last test for libusb-1.0 descriptors. This test dump the config descriptor with bConfigurationValue == 1. The descriptors emulation for libusb-1.0 seems to works fine. Affected files ... .. //depot/projects/soc2009/syl_usb/libusb-tests/descriptors/test4/test4.c#2 edit Differences ... ==== //depot/projects/soc2009/syl_usb/libusb-tests/descriptors/test4/test4.c#2 (text+ko) ==== @@ -3,8 +3,85 @@ #include <stdio.h> #include <libusb.h> +libusb_context *ctx; + int main(int ac, const char *av[]) { + libusb_device **devs_list; + libusb_config_descriptor *cdesc; + libusb_interface_descriptor *idesc; + libusb_endpoint_descriptor *edesc; + int nb; + int ret; + int i, j, k, l; + + printf("This program will dump the device" + " config descriptor with bConfiguartion == 1 for all the" + " present devices.\n"); + + if (libusb_init(&ctx) != 0) { + fprintf(stderr, "libusb_init failed\n"); + return (EXIT_FAILURE); + } + + if ((nb = libusb_get_device_list(ctx, &devs_list)) < 0) { + fprintf(stderr, "libusb_get_device_list failed with 0x%x error code\n", + nb); + return (EXIT_FAILURE); + } + + 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 < nb ; i++) { + printf("|-- device number = %i\n|\n", i); + ret = libusb_get_config_descriptor_by_value(devs_list[i], 1, &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_config_descriptor_by_value failed\n"); + return (EXIT_FAILURE); + } + libusb_free_config_descriptor(cdesc); + } return (EXIT_SUCCESS); }
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200905311312.n4VDCA55075343>