From 8e2c83043349e360c77491a89b4c6e688912c39f Mon Sep 17 00:00:00 2001 From: Pali Rohár Date: Sat, 11 Aug 2012 14:40:56 +0200 Subject: usb-device: Show USB device descriptor info --- src/usb-device.c | 38 +++++++++++++++++++++++++++++++++++++- 1 file changed, 37 insertions(+), 1 deletion(-) (limited to 'src/usb-device.c') diff --git a/src/usb-device.c b/src/usb-device.c index 160b36e..e33cac0 100644 --- a/src/usb-device.c +++ b/src/usb-device.c @@ -59,7 +59,7 @@ static void usb_flash_device_info_print(const struct usb_flash_device * dev) { int i; - PRINTF_ADD("USB device %s", device_to_string(dev->devices[0])); + PRINTF_ADD("USB device: %s", device_to_string(dev->devices[0])); for ( i = 1; dev->devices[i]; ++i ) PRINTF_ADD("/%s", device_to_string(dev->devices[i])); @@ -68,6 +68,36 @@ static void usb_flash_device_info_print(const struct usb_flash_device * dev) { } +static void usb_descriptor_info_print(usb_dev_handle * udev, struct usb_device * dev) { + + char buf[1024]; + char buf2[1024]; + unsigned int x; + int ret; + int i; + + buf[0] = 0; + usb_get_string_simple(udev, dev->descriptor.iProduct, buf, sizeof(buf)); + PRINTF_LINE("USB device product string: %s", buf[0] ? buf : "(not detected)"); + PRINTF_END(); + + buf[0] = 0; + buf2[0] = 0; + ret = usb_get_string_simple(udev, dev->descriptor.iSerialNumber, buf, sizeof(buf)); + for ( i = 0; i < ret; i+=2 ) { + sscanf(buf+i, "%2x", &x); + if ( x > 32 && x < 128 ) + buf2[i/2] = x; + else { + buf2[0] = 0; + break; + } + } + PRINTF_LINE("USB device serial number string: %s", buf2[0] ? buf2 : "(not detected)"); + PRINTF_END(); + +} + static struct usb_device_info * usb_device_is_valid(struct usb_device * dev) { int i; @@ -90,6 +120,8 @@ static struct usb_device_info * usb_device_is_valid(struct usb_device * dev) { return NULL; } + usb_descriptor_info_print(udev, dev); + #if defined(LIBUSB_HAS_GET_DRIVER_NP) && defined(LIBUSB_HAS_DETACH_KERNEL_DRIVER_NP) PRINTF_LINE("Detaching kernel from USB interface..."); usb_detach_kernel_driver_np(udev, usb_devices[i].interface); @@ -171,6 +203,9 @@ struct usb_device_info * usb_open_and_wait_for_device(void) { usb_init(); usb_find_busses(); + PRINTF_BACK(); + printf("\n"); + while ( 1 ) { PRINTF_LINE("Waiting for USB device... %c", progress[++i%sizeof(progress)]); @@ -203,6 +238,7 @@ struct usb_device_info * usb_open_and_wait_for_device(void) { } PRINTF_BACK(); + printf("\n"); if ( ! ret ) return NULL; -- cgit v1.2.3