|
From: Tim R. <ti...@pr...> - 2008-06-10 17:30:20
|
Serge A. Zaitsev wrote:
> Hi!
> I'm trying to get HID interface descriptor, but with no success.
> As far as I understand, I should use LIBUSB_DT_REPORT descriptor type
> while calling libusb_get_descriptor().
> The following is the example of how I try to get descriptor from
> microsoft mouse:
>
> #include <stdio.h>
> #include <libusb-1.0/libusb.h>
>
> int main()
> {
> int res, i;
> char buf[256];
> struct libusb_device **devs;
> struct libusb_device *dev;
> struct libusb_device_handle *devh;
> struct libusb_device_descriptor descr;
> struct libusb_config_descriptor *cdescr;
>
> libusb_init();
> devh = libusb_open_device_with_vid_pid(0x045e, 0x0040); // MS
> mouse VID/PID
> dev = libusb_get_device(devh);
>
> res = libusb_detach_kernel_driver(devh, 0);
> printf("Res: %d\n", res);
>
> res = libusb_claim_interface(devh, 0);
> printf("Res: %d\n", res);
>
> memset(buf, 0, sizeof(buf));
> res = libusb_get_descriptor(devh, LIBUSB_DT_REPORT, 0, buf,
> sizeof(buf));
> printf("Res: %d\n", res);
>
libusb_get_descriptor makes standard GET_DESCRIPTOR requests, where the
bmRequestType field is 0x80. The DT_REPORT descriptor request must
indicate that the recipient is an interface, which requires
bmRequestType to be 0x81.
You have two good choices. The report descriptors are all included in
the configuration descriptor, so you should be able to fetch the whole
configuration descriptor en masse and parse it to extract the report
descriptors.
Alternatively, libusb_get_descriptor is a very thin layer over
libusb_control_transfer, so you could just expand it by hand:
res = libusb_control_transfer( devh, LIBUSB_ENDPOINT_IN |
LIBUSB_RECIPIENT_INTERFACE,
LIBUSB_REQUEST_GET_DESCRIPTOR, (LIBUSB_DT_REPORT << 8) | 0, 0, buf,
sizeof(buf), 1000);
--
Tim Roberts, ti...@pr...
Providenza & Boekelheide, Inc.
|