Skip site navigation (1)Skip section navigation (2)
Date:      Thu, 28 May 2009 08:29:09 GMT
From:      Sylvestre Gallon <syl@FreeBSD.org>
To:        Perforce Change Reviews <perforce@FreeBSD.org>
Subject:   PERFORCE change 162933 for review
Message-ID:  <200905280829.n4S8T9RQ074802@repoman.freebsd.org>

next in thread | raw e-mail | index | archive | help
http://perforce.freebsd.org/chv.cgi?CH=162933

Change 162933 by syl@syl_rincewind on 2009/05/28 08:29:09

	test of libusb_get_active_config_desscriptor.

Affected files ...

.. //depot/projects/soc2009/syl_usb/libusb-tests/descriptors/test2/test2.c#2 edit

Differences ...

==== //depot/projects/soc2009/syl_usb/libusb-tests/descriptors/test2/test2.c#2 (text+ko) ====

@@ -3,8 +3,58 @@
 #include <stdio.h>
 #include <libusb.h>
 	
+libusb_context *ctx;
+
 int
 main(int ac, const char *av[])
 {
+	libusb_config_descriptor *cdesc;
+	libusb_device **devs_list;	
+	int ret;
+	int i, j;
+
+	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) {
+		fprintf(stderr, "libusb_get_device_list failed with 0x%x error code\n",
+		    ret);
+		return (EXIT_FAILURE);
+	}
+	
+	if (ret == 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);
+		} else {
+			fprintf(stderr, "libusb_get_active_config_descriptor failed\n");
+		}
+	}
 	return (EXIT_SUCCESS);
 }



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200905280829.n4S8T9RQ074802>