I've sent the following information to the libusb-devel list, so my apologies to
anyone that's reading both and has to suffer this twice.  I wasn't getting much
of a response there, so I figured I'd try here.

I'm running a recent Linux 2.6 kernel.  I have a HID device that 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.

libhid seems to force the disconnect from the usbhid driver, so I don't think
that'll work for what I want.  The only other thing I could find reference to
was possibly using the hiddev interface to send a control message, but for some
reason, my kernel isn't creating the /dev/usb/hiddev* files when I plug in the
device.  Is this the route I need to be taking?  Perhaps I need something even
lower level?

Thanks for any suggestions that anyone can offer.

-Brian

Program output (as root, so no permissions issues):

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");
              }
          }
      }
  }
}


----------------------------------------------------------------
This message was sent using IMP, the Internet Messaging Program.


-------------------------------------------------------
This SF.Net email is sponsored by Oracle Space Sweepstakes
Want to be the first software developer in space?
Enter now for the Oracle Space Sweepstakes!
http://ads.osdn.com/?ad_id=7412&alloc_id=16344&op=click
_______________________________________________
[email protected]
To unsubscribe, use the last form field at:
https://lists.sourceforge.net/lists/listinfo/linux-usb-devel

Reply via email to