Correct PPTP server firewall rules chain.
[tomato/davidwu.git] / release / src / router / libusb / examples / testlibusb.c
blob4ca0b59e8d268e86b549ea7f28abce4c2731e946
1 /*
2 * testlibusb.c
4 * Test suite program
5 */
7 #include <stdio.h>
8 #include <string.h>
9 #include <usb.h>
11 int verbose = 0;
13 void print_endpoint(struct usb_endpoint_descriptor *endpoint)
15 printf(" bEndpointAddress: %02xh\n", endpoint->bEndpointAddress);
16 printf(" bmAttributes: %02xh\n", endpoint->bmAttributes);
17 printf(" wMaxPacketSize: %d\n", endpoint->wMaxPacketSize);
18 printf(" bInterval: %d\n", endpoint->bInterval);
19 printf(" bRefresh: %d\n", endpoint->bRefresh);
20 printf(" bSynchAddress: %d\n", endpoint->bSynchAddress);
23 void print_altsetting(struct usb_interface_descriptor *interface)
25 int i;
27 printf(" bInterfaceNumber: %d\n", interface->bInterfaceNumber);
28 printf(" bAlternateSetting: %d\n", interface->bAlternateSetting);
29 printf(" bNumEndpoints: %d\n", interface->bNumEndpoints);
30 printf(" bInterfaceClass: %d\n", interface->bInterfaceClass);
31 printf(" bInterfaceSubClass: %d\n", interface->bInterfaceSubClass);
32 printf(" bInterfaceProtocol: %d\n", interface->bInterfaceProtocol);
33 printf(" iInterface: %d\n", interface->iInterface);
35 for (i = 0; i < interface->bNumEndpoints; i++)
36 print_endpoint(&interface->endpoint[i]);
39 void print_interface(struct usb_interface *interface)
41 int i;
43 for (i = 0; i < interface->num_altsetting; i++)
44 print_altsetting(&interface->altsetting[i]);
47 void print_configuration(struct usb_config_descriptor *config)
49 int i;
51 printf(" wTotalLength: %d\n", config->wTotalLength);
52 printf(" bNumInterfaces: %d\n", config->bNumInterfaces);
53 printf(" bConfigurationValue: %d\n", config->bConfigurationValue);
54 printf(" iConfiguration: %d\n", config->iConfiguration);
55 printf(" bmAttributes: %02xh\n", config->bmAttributes);
56 printf(" MaxPower: %d\n", config->MaxPower);
58 for (i = 0; i < config->bNumInterfaces; i++)
59 print_interface(&config->interface[i]);
62 int print_device(struct usb_device *dev, int level)
64 usb_dev_handle *udev;
65 char description[256];
66 char string[256];
67 int ret, i;
69 udev = usb_open(dev);
70 if (udev) {
71 if (dev->descriptor.iManufacturer) {
72 ret = usb_get_string_simple(udev, dev->descriptor.iManufacturer, string, sizeof(string));
73 if (ret > 0)
74 snprintf(description, sizeof(description), "%s - ", string);
75 else
76 snprintf(description, sizeof(description), "%04X - ",
77 dev->descriptor.idVendor);
78 } else
79 snprintf(description, sizeof(description), "%04X - ",
80 dev->descriptor.idVendor);
82 if (dev->descriptor.iProduct) {
83 ret = usb_get_string_simple(udev, dev->descriptor.iProduct, string, sizeof(string));
84 if (ret > 0)
85 snprintf(description + strlen(description), sizeof(description) -
86 strlen(description), "%s", string);
87 else
88 snprintf(description + strlen(description), sizeof(description) -
89 strlen(description), "%04X", dev->descriptor.idProduct);
90 } else
91 snprintf(description + strlen(description), sizeof(description) -
92 strlen(description), "%04X", dev->descriptor.idProduct);
94 } else
95 snprintf(description, sizeof(description), "%04X - %04X",
96 dev->descriptor.idVendor, dev->descriptor.idProduct);
98 printf("%.*sDev #%d: %s\n", level * 2, " ", dev->devnum,
99 description);
101 if (udev && verbose) {
102 if (dev->descriptor.iSerialNumber) {
103 ret = usb_get_string_simple(udev, dev->descriptor.iSerialNumber, string, sizeof(string));
104 if (ret > 0)
105 printf("%.*s - Serial Number: %s\n", level * 2,
106 " ", string);
110 if (udev)
111 usb_close(udev);
113 if (verbose) {
114 if (!dev->config) {
115 printf(" Couldn't retrieve descriptors\n");
116 return 0;
119 for (i = 0; i < dev->descriptor.bNumConfigurations; i++)
120 print_configuration(&dev->config[i]);
121 } else {
122 for (i = 0; i < dev->num_children; i++)
123 print_device(dev->children[i], level + 1);
126 return 0;
129 int main(int argc, char *argv[])
131 struct usb_bus *bus;
133 if (argc > 1 && !strcmp(argv[1], "-v"))
134 verbose = 1;
136 usb_init();
138 usb_find_busses();
139 usb_find_devices();
141 for (bus = usb_busses; bus; bus = bus->next) {
142 if (bus->root_dev && !verbose)
143 print_device(bus->root_dev, 0);
144 else {
145 struct usb_device *dev;
147 for (dev = bus->devices; dev; dev = dev->next)
148 print_device(dev, 0);
152 return 0;