From owner-p4-projects@FreeBSD.ORG Thu May 28 19:40:48 2009 Return-Path: Delivered-To: p4-projects@freebsd.org Received: by hub.freebsd.org (Postfix, from userid 32767) id 67D1910656CC; Thu, 28 May 2009 19:40:48 +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 05F0410656C9 for ; Thu, 28 May 2009 19:40:48 +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 DD5658FC0C for ; Thu, 28 May 2009 19:40:47 +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 n4SJelvG087481 for ; Thu, 28 May 2009 19:40:47 GMT (envelope-from syl@FreeBSD.org) Received: (from perforce@localhost) by repoman.freebsd.org (8.14.3/8.14.3/Submit) id n4SJelvi087479 for perforce@freebsd.org; Thu, 28 May 2009 19:40:47 GMT (envelope-from syl@FreeBSD.org) Date: Thu, 28 May 2009 19:40:47 GMT Message-Id: <200905281940.n4SJelvi087479@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 162964 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 19:40:50 -0000 http://perforce.freebsd.org/chv.cgi?CH=162964 Change 162964 by syl@syl_rincewind on 2009/05/28 19:40:06 Add test for libusb_get_config_descriptor. Affected files ... .. //depot/projects/soc2009/syl_usb/libusb-tests/descriptors/test3/test3.c#2 edit Differences ... ==== //depot/projects/soc2009/syl_usb/libusb-tests/descriptors/test3/test3.c#2 (text+ko) ==== @@ -3,8 +3,95 @@ #include #include +libusb_context *ctx; + int main(int ac, const char *av[]) { + libusb_device **devs_list; + libusb_device_descriptor *ddesc; + libusb_config_descriptor *cdesc; + libusb_interface_descriptor *idesc; + libusb_endpoint_descriptor *edesc; + int nb; + int ret; + int i, j, k, l, m; + + printf("This program will dump all the device" + " configurations descriptor for all the" + " present devices.\n"); + + ddesc = malloc(sizeof(libusb_device_descriptor)); + if (ddesc == NULL) { + perror("test1"); + return (EXIT_FAILURE); + } + + 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++) { + libusb_get_device_descriptor(devs_list[i], ddesc); + for (m = 0 ; m < ddesc->bNumConfigurations ; m++) { + printf("|-- device number = %i config %i\n|\n", i, m); + ret = libusb_get_config_descriptor(devs_list[i], m, &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); }