Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

I have a USB rocket launcher that I wish to experiment with through libusb. However, libusb cannot claim the interface; presumably because the output of usb-devices lists 'usbhid' as the driver for the device.

From reading around on the internet, I've only come to the conclusion that I need to detach this driver from the device so I can use it with libusb. However, I have not found a single definitive way to do that, only several different ideas and bug reports.

So, is there a way to detach the usbhid driver from a device that would be relevant with the kernel and tools supplied with Ubuntu 11.04?

EDIT:

I tried creating the file

/etc/udev/rules.d/10-usbhid.rules

and writing the following:

ATTRS{idVendor}=="0a81", ATTRS{idProduct}=="0701", OPTIONS=="ignore_device"

Saving, then rebooting. The file is still there, but it doesn't appear to be working at all.

EDIT:

Okay, I tried this:

sudo -i
echo -n "0003:0A81:0701.0006" > /sys/bus/hid/drivers/generic-usb/unbind

After that, navigating to /sys/bus/hid/devices/0003:0A81:0701.0006 and ls yields:

drwxr-xr-x 2 root root    0 2011-05-29 15:46 power
lrwxrwxrwx 1 root root    0 2011-05-29 13:19 subsystem ->       ../../../../../../../../../bus/hid
-rw-r--r-- 1 root root 4096 2011-05-29 13:19 uevent

It no longer lists a "driver" symlink like it did before, so I would assume that it unbound it. However, all evidence seems to suggest that the driver is still usbhid. For example usb-devices yields:

T:  Bus=02 Lev=03 Prnt=07 Port=00 Cnt=01 Dev#=  9 Spd=1.5 MxCh= 0
D:  Ver= 1.10 Cls=00(>ifc ) Sub=00 Prot=00 MxPS= 8 #Cfgs=  1
P:  Vendor=0a81 ProdID=0701 Rev=00.01
S:  Manufacturer=Dream Link
S:  Product=USB Missile Launcher v1.0
C:  #Ifs= 1 Cfg#= 1 Atr=a0 MxPwr=100mA
I:  If#= 0 Alt= 0 #EPs= 1 Cls=03(HID  ) Sub=00 Prot=00 Driver=usbhid

libusb still retuns -1 on usb_claim_interface()....

share|improve this question

3 Answers 3

up vote 4 down vote accepted

If you simply run the libusb program as root,

usb_detach_kernel_driver_np()

actually works as expected.

share|improve this answer
    
This worked for me; thanks. –  Mark Dominus Aug 12 '12 at 2:38

I think you will need to add the device id to udev's blacklist so that no module, including usbhid, gets attached to it.

share|improve this answer
    
How exactly would I go about that? Pardon my lack of experience, but this link wiki.archlinux.org/index.php/Blacklisting, that I got to by following a page on udev, does not appear to be specifically associated with udev, and does not actually tell me how to blacklist a particular device with vendor product id. –  Chase Meadors May 28 '11 at 18:15
    
That page is about blacklisting a module from loading. You don't want to do that because you need the module for your keyboard and mouse! What you want is to stop that particular device from associating with it. I'm sorry I don't know the udev rule off hand. If I get a change to look it up I'll add it to my answer but I thought I'd point you in the direction first. –  Caleb May 28 '11 at 18:18

I think that the following udev rule will do what you want:

SUBSYSTEM=="usb", ATTRS{idVendor}=="0a81", ATTRS{idProduct}=="0701", MODE="0660", GROUP="plugdev", RUN="/bin/sh -c 'echo -n $id:1.0 > /sys/bus/usb/drivers/usbhid/unbind'"

Your user will need to be a member of the plugdev group to gain access. There's no need to run as root with this rule in place.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.