summaryrefslogtreecommitdiffstats
path: root/src/usb-device.c
diff options
context:
space:
mode:
authorPali Rohár <pali.rohar@gmail.com>2012-08-11 14:40:56 +0200
committerPali Rohár <pali.rohar@gmail.com>2012-08-11 14:40:56 +0200
commit8e2c83043349e360c77491a89b4c6e688912c39f (patch)
treea7e75b451455dd5019489f3330844999c91620a0 /src/usb-device.c
parent868bee04138924aabb4d9fbafe457f7ded62cf73 (diff)
download0xFFFF-8e2c83043349e360c77491a89b4c6e688912c39f.tar.bz2
usb-device: Show USB device descriptor info
Diffstat (limited to 'src/usb-device.c')
-rw-r--r--src/usb-device.c38
1 files changed, 37 insertions, 1 deletions
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;