From: Daniel Drake usbutils: print descriptor even if usb_open() fails lsusb refuses to dump descriptors if usb_open() failed, whereas the core of the information that is printed is available without a device handle at all. With libusb-0.1, if the device can only be opened for read access, "lsusb -v" still prints descriptor info along with some error messages for the failed control messages and so on. With libusb-compat-0.1, usb_open() fails here and lsusb simply prints "Couldn't open device" This patch makes it print the same available descriptor info even if usb_open() fails. With libusb-compat-0.1, usb_open() will fail if you do not have write access to the device. I regard it as a bug that libusb-0.1 succeeds and returns a device handle in this situation, because the handle is effectively useless unless you have write access (all handle-based operations will fail). It's unfortunate that this means new compat layer is diverging a little from libusb-0.1 behaviour, but I don't think it's worth trying to clone this behaviour. Please consider this for the next usbutils release. Index: usbutils-0.73/ChangeLog =================================================================== --- usbutils-0.73.orig/ChangeLog +++ usbutils-0.73/ChangeLog @@ -1,3 +1,8 @@ +2008-06-13 Daniel Drake + * lsusb.c: Dump descriptor information even if we don't get a + device handle. Improves compatibility with + libusb-1.0 and libusb-compat-0.1. + 2007-10-23 David Brownell * lsusb.c: Stop hiding unrecognized/misplaced class specific descriptors. Don't require compressed format for usb.ids Index: usbutils-0.73/lsusb.c =================================================================== --- usbutils-0.73.orig/lsusb.c +++ usbutils-0.73/lsusb.c @@ -139,6 +139,11 @@ static int get_string(struct usb_dev_han { int ret; + if (!dev) { + buf[0] = 0; + return 0; + } + if (id) { ret = usb_get_string_simple(dev, id, buf, size); if (ret <= 0) { @@ -2069,6 +2074,12 @@ static void dump_hid_device(struct usb_d if (!do_report_desc) return; + if (!dev) { + printf( " Report Descriptors: \n" + " ** UNAVAILABLE **\n"); + return; + } + for (i = 0; i < buf[5]; i++) { /* we are just interested in report descriptors*/ if (buf[6+3*i] != USB_DT_REPORT) @@ -2648,28 +2659,31 @@ static void dumpdev(struct usb_device *d otg = wireless = 0; udev = usb_open(dev); - if (udev) { - dump_device(udev, &dev->descriptor); - if (dev->descriptor.bcdUSB >= 0x0250) - wireless = do_wireless(udev); - if (dev->config) { - otg = do_otg(&dev->config[0]) || otg; - for (i = 0; i < dev->descriptor.bNumConfigurations; - i++) { - dump_config(udev, &dev->config[i]); - } - } - if (dev->descriptor.bDeviceClass == USB_CLASS_HUB) - do_hub(udev, dev->descriptor.bDeviceProtocol); - if (dev->descriptor.bcdUSB >= 0x0200) { - do_dualspeed(udev); - do_debug(udev); - } + if (!udev) + fprintf(stderr, "Couldn't open device, some information " + "will be missing\n"); + + dump_device(udev, &dev->descriptor); + if (dev->descriptor.bcdUSB >= 0x0250) + wireless = do_wireless(udev); + if (dev->config) { + otg = do_otg(&dev->config[0]) || otg; + for (i = 0; i < dev->descriptor.bNumConfigurations; + i++) { + dump_config(udev, &dev->config[i]); + } + } + if (udev && dev->descriptor.bDeviceClass == USB_CLASS_HUB) + do_hub(udev, dev->descriptor.bDeviceProtocol); + if (udev && dev->descriptor.bcdUSB >= 0x0200) { + do_dualspeed(udev); + do_debug(udev); + } + if (udev) dump_device_status(udev, otg, wireless); + + if (udev) usb_close(udev); - } - else - fprintf(stderr, "Couldn't open device\n"); } /* ---------------------------------------------------------------------- */