From: Brian N. <br...@tw...> - 2005-05-23 00:17:53
|
Still having the same issues, here's a little more detail: I'm running a recent Linux 2.6 kernel. I have a HID device, shows up as a joystick (which it should). I need to send a short two-byte control message to the device for configuration. The problem I'm having is the usb_claim_interface call fails because it's already claimed by the usbhid driver. I can disconnect it from the driver and the code works fine, but that's not what I want to do, because I want to maintain the joystick functionality that I already have. I've attached my code and the output from it below. Is this going to be possible? Do I need to investigate other methods of communicating with the device, like hiddev or perhaps something on an even lower level? I haven't done a ton of research, but I understand it might be possible to write to the device directly thorough the /proc/bus/usb/XXX/YYY file? This process works fine under Windows, so I'm not sure where to go from here under Linux. Thanks for any suggestions that anyone can offer. -Brian Program output (as root): usb_set_debug: Setting debugging level to 8 (on) usb_os_find_busses: Found 004 usb_os_find_busses: Found 003 usb_os_find_busses: Found 002 usb_os_find_busses: Found 001 usb_os_find_busses: Skipping non bus directory devices usb_os_find_devices: Found 001 on 004 usb_os_find_devices: Found 001 on 003 usb_os_find_devices: Found 001 on 002 usb_os_find_devices: Found 002 on 001 skipped 1 class/vendor specific interface descriptors usb_os_find_devices: Found 001 on 001 Check that you have permissions to write to 001/002 and, if you don't, that you set up hotplug (http://linux-hotplug.sourceforge.net/) correctly. USB error: could not claim interface 0: Device or resource busy USB error: error sending control message: Device or resource busy usb_claim_interface error: could not claim interface 0: Device or resource busy msg return: -16 | error sending control message: Device or resource busy The code: #include <usb.h> int main(void) { struct usb_bus *busses; struct usb_bus *bus; struct usb_device *dev; usb_dev_handle *usb_handle; int ret; unsigned char command[2] = {0xCC, 0x03}; usb_init(); usb_set_debug(8); usb_find_busses(); usb_find_devices(); busses = usb_get_busses(); for (bus = busses; bus; bus = bus->next) { for (dev = bus->devices; dev; dev = dev->next) { if (dev->descriptor.idVendor == 0xFAFA) { usb_handle = usb_open(dev); if(usb_handle) { if (usb_set_configuration(usb_handle, dev->config->bConfigurationValue)) { printf("usb_set_configuration error: %s\n", usb_strerror()); } usb_set_altinterface(usb_handle, 0); if (usb_claim_interface(usb_handle, 0) < 0) { printf("usb_claim_interface error: %s\n", usb_strerror()); } ret = usb_control_msg(usb_handle, 0x21, // Set_Report request (page 52 HID Spec) 0x09, // SET_REPORT (Top Remarks page 51) 0x200, // (Bottom Remarks section page 51) 0x00, // Interface 0 command, // Buffer for characters to transmit 0x02, // Size of message 10); // Milliseconds of timeout printf("msg return: %d | %s\n", ret, ret < 0 ? usb_strerror() : "<no error>"); usb_close(usb_handle); } else { printf("Error opening device.\n"); } } } } } |
From: Charles L. <cl...@gm...> - 2005-05-23 02:34:43
|
On 5/22/05, Brian Nelson <br...@tw...> wrote: > The problem I'm having is the usb_claim_interface call fails because > it's already claimed by the usbhid driver. I can disconnect it from the > driver and the code works fine, but that's not what I want to do, > because I want to maintain the joystick functionality that I already have= . Unfortunately, while the kernel provides a "detach driver" call, it does not offer a corresponding "reattach driver" call. There are a couple of hooks in the kernel HID driver to handle odd devices, but your situation might require a nontrivial patch. The other option is to "fly blind" and just issue your command without claiming the interface. The kernel should queue your control message such that it will not be mixed up with other control message/response pairs from the HID driver, but there are no guarantees with that method. --=20 - Charles Lepple |
From: Brian N. <br...@tw...> - 2005-05-23 04:15:35
|
Charles Lepple wrote: >On 5/22/05, Brian Nelson <br...@tw...> wrote: > > >>The problem I'm having is the usb_claim_interface call fails because >>it's already claimed by the usbhid driver. I can disconnect it from the >>driver and the code works fine, but that's not what I want to do, >>because I want to maintain the joystick functionality that I already have. >> >> > >Unfortunately, while the kernel provides a "detach driver" call, it >does not offer a corresponding "reattach driver" call. > >There are a couple of hooks in the kernel HID driver to handle odd >devices, but your situation might require a nontrivial patch. > >The other option is to "fly blind" and just issue your command without >claiming the interface. The kernel should queue your control message >such that it will not be mixed up with other control message/response >pairs from the HID driver, but there are no guarantees with that >method. > > > By "flying blind," are you saying I should try just calling usb_control_msg without calling usb_claim_interface first? I think I've done that, and usb_control_msg just returns an error. If you're not talking about that (perhaps something outside of libusb?), can you give me a pointer in the right direction? Thanks! -Brian |
From: Charles L. <cl...@gm...> - 2005-05-23 04:24:51
|
On 5/23/05, Brian Nelson <br...@tw...> wrote: > Charles Lepple wrote: >=20 [...] > >The other option is to "fly blind" and just issue your command without > >claiming the interface. The kernel should queue your control message > >such that it will not be mixed up with other control message/response > >pairs from the HID driver, but there are no guarantees with that > >method. > > > > > > > By "flying blind," are you saying I should try just calling > usb_control_msg without calling usb_claim_interface first? yes > I think I've done that, and usb_control_msg just returns an error. I thought you could get away with that in Linux, but maybe it's only on OS = X. --=20 - Charles Lepple |