Seva Alekseyev
Seva Alekseyev

Reputation: 61388

Diagnosing chrome.usb.claimInterface() error

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?

Upvotes: 0

Views: 907

Answers (2)

ralf htp
ralf htp

Reputation: 9422

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

Upvotes: 0

ralf htp
ralf htp

Reputation: 9422

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...

Upvotes: 1

Related Questions