0

I'm using chrome.usb API from a Chrome app to interact with a USB device, a smart card reader. I can open the device and pull the configuration. Yet when I call claimInterface() to start exchanging data, I get an error with message: "Error claiming interface." and no other diagnostics.

Any pointers how to deal with that, please? Can I somehow enable diagnostic logging from the API, for example?

Seva Alekseyev
  • 59,826
  • 25
  • 160
  • 281
  • [Apparently](https://code.google.com/p/chromium/codesearch#chromium/src/device/usb/usb_device_handle_impl.cc&sq=package:chromium&type=cs&l=733&rcl=1447771613) the error info should be present in `chrome://device-log/` – wOxxOm Nov 20 '15 at 02:22
  • Good find. Yet I don't see anything there; after numerous runs of the offending code, there's not a single record in the recent time. Is this kind of logging on per-window basis, maybe? – Seva Alekseyev Nov 20 '15 at 03:01
  • See [How to enable logging](https://www.chromium.org/for-testers/enable-logging) – wOxxOm Nov 20 '15 at 03:11
  • Got something: Access denied (insufficient permissions). Make an answer, I'll accept. But it required Sawbuck to see. chrome://device-log didn't capture those messages. – Seva Alekseyev Nov 20 '15 at 03:28
  • I haven't tried it myself. I think it would make more sense if you add an answer. – wOxxOm Nov 20 '15 at 03:38
  • The credit is yours :) – Seva Alekseyev Nov 20 '15 at 13:35
  • I mean to post an answer I would have to reproduce the whole thing and it's somewhat more than I want. – wOxxOm Nov 20 '15 at 13:36
  • It's two lines: run Chrome with `--enable-logging --v=1`; download and run Sawbuck (link). – Seva Alekseyev Nov 20 '15 at 13:55
  • No, maybe some other time. – wOxxOm Nov 20 '15 at 13:56

2 Answers2

1

in this thread is discussed a similar problem: Error message 'Interface not claimed' from libusb

here follows a copy

Just had the same problem with libusb-1.0; I originally had this sequence:

libusb_init
libusb_open_device_with_vid_pid
libusb_reset_device
libusb_get_device
libusb_reset_device
libusb_set_configuration
libusb_claim_interface
libusb_set_interface_alt_setting 
libusb_get_device_descriptor
libusb_get_bus_number 
libusb_get_device_address
libusb_get_string_descriptor_ascii
if(libusb_kernel_driver_active.. ) 
  if(libusb_detach_kernel_driver.. ) 
libusb_bulk_transfer
...

... and for it, the "interface not claimed" was generated when the first libusb_bulk_transfer executed (but not subsequent ones, not shown above), which I confirmed by stepping in gdb. (btw, that error message comes from /linux/drivers/usb/core/devio.c)

This page: USB Hid Issue · Yubico/yubikey-personalization Wiki · GitHub refers to a fix for libusb-0.1 which called the corresponding "detach_driver" function; so I started moving the "detach_driver" part around in my code too - and finally this sequence seems to get rid of the "interface not claimed" message:

libusb_init
libusb_open_device_with_vid_pid
if(libusb_kernel_driver_active.. ) 
  if(libusb_detach_kernel_driver.. ) 
libusb_reset_device
libusb_get_device
libusb_set_configuration
libusb_claim_interface
libusb_set_interface_alt_setting 
libusb_get_device_descriptor
libusb_get_bus_number
libusb_get_device_address
libusb_get_string_descriptor_ascii
libusb_bulk_transfer
...

Apparently, if the driver is first detached, and then interface is claimed - then no errors are generated. But that is also what you have in OP there - so I think, the trick for OP would be to have detach, then set configuration, and after that claim interface...

Community
  • 1
  • 1
ralf htp
  • 9,149
  • 4
  • 22
  • 34
0

i always had problems with libusb on windows. you can use the WDK (Win10) or DDK (earlier Win) but this is complicated. here are the libusb error codes:

http://libusb.org/static/api-1.0/group__misc.html yours is LIBUSB_ERROR_ACCESS

this seems to be a problem of the OS security. i am not familiar with windows and libusb

ralf htp
  • 9,149
  • 4
  • 22
  • 34