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
)
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
)
43 for (i
= 0; i
< interface
->num_altsetting
; i
++)
44 print_altsetting(&interface
->altsetting
[i
]);
47 void print_configuration(struct usb_config_descriptor
*config
)
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
)
65 char description
[256];
71 if (dev
->descriptor
.iManufacturer
) {
72 ret
= usb_get_string_simple(udev
, dev
->descriptor
.iManufacturer
, string
, sizeof(string
));
74 snprintf(description
, sizeof(description
), "%s - ", string
);
76 snprintf(description
, sizeof(description
), "%04X - ",
77 dev
->descriptor
.idVendor
);
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
));
85 snprintf(description
+ strlen(description
), sizeof(description
) -
86 strlen(description
), "%s", string
);
88 snprintf(description
+ strlen(description
), sizeof(description
) -
89 strlen(description
), "%04X", dev
->descriptor
.idProduct
);
91 snprintf(description
+ strlen(description
), sizeof(description
) -
92 strlen(description
), "%04X", dev
->descriptor
.idProduct
);
95 snprintf(description
, sizeof(description
), "%04X - %04X",
96 dev
->descriptor
.idVendor
, dev
->descriptor
.idProduct
);
98 printf("%.*sDev #%d: %s\n", level
* 2, " ", dev
->devnum
,
101 if (udev
&& verbose
) {
102 if (dev
->descriptor
.iSerialNumber
) {
103 ret
= usb_get_string_simple(udev
, dev
->descriptor
.iSerialNumber
, string
, sizeof(string
));
105 printf("%.*s - Serial Number: %s\n", level
* 2,
115 printf(" Couldn't retrieve descriptors\n");
119 for (i
= 0; i
< dev
->descriptor
.bNumConfigurations
; i
++)
120 print_configuration(&dev
->config
[i
]);
122 for (i
= 0; i
< dev
->num_children
; i
++)
123 print_device(dev
->children
[i
], level
+ 1);
129 int main(int argc
, char *argv
[])
133 if (argc
> 1 && !strcmp(argv
[1], "-v"))
141 for (bus
= usb_busses
; bus
; bus
= bus
->next
) {
142 if (bus
->root_dev
&& !verbose
)
143 print_device(bus
->root_dev
, 0);
145 struct usb_device
*dev
;
147 for (dev
= bus
->devices
; dev
; dev
= dev
->next
)
148 print_device(dev
, 0);