diff options
author | kaiw <kaiw@FreeBSD.org> | 2010-03-27 08:00:16 +0000 |
---|---|---|
committer | kaiw <kaiw@FreeBSD.org> | 2010-03-27 08:00:16 +0000 |
commit | 28e4fb3b8eecda12e4029af4c17969a7f0225097 (patch) | |
tree | 01d412e25de933a44f1fd9357069f5038f049229 /lib/libusbhid/descr.c | |
parent | 35f33c0a98437a396b859cba0c8478a55dccb5e6 (diff) | |
download | FreeBSD-src-28e4fb3b8eecda12e4029af4c17969a7f0225097.zip FreeBSD-src-28e4fb3b8eecda12e4029af4c17969a7f0225097.tar.gz |
Merge improvements from kernel HID parser to the userland usbhid(3)
parser. This merge does not change any API and should not break any
native or thirdparty applications.
Changes include:
* Merge multiple report ID support and other improvements from kernel
HID parser.
* Ignore rid argument in hid_start_parser, parse all the report items since
we now support multiple report ID.
* Skip report ID byte in hid_get_data() and set report ID byte in
hid_set_data(), if report ID is non-zero.
* Reimplement hid_get_report_id: instead get report id from uhid device
(which is always 0), try parsing the report descriptor and return the
first report ID encountered.
Reviewed by: hps
Silent on: -usb mailing list
Diffstat (limited to 'lib/libusbhid/descr.c')
-rw-r--r-- | lib/libusbhid/descr.c | 22 |
1 files changed, 21 insertions, 1 deletions
diff --git a/lib/libusbhid/descr.c b/lib/libusbhid/descr.c index 2ce1bf0..a5c033a 100644 --- a/lib/libusbhid/descr.c +++ b/lib/libusbhid/descr.c @@ -38,7 +38,6 @@ __FBSDID("$FreeBSD$"); #include <unistd.h> #include <sys/time.h> #include <sys/ioctl.h> - #include <dev/usb/usb_ioctl.h> #include "usbhid.h" @@ -59,9 +58,30 @@ hid_set_immed(int fd, int enable) int hid_get_report_id(int fd) { + report_desc_t rep; + hid_data_t d; + hid_item_t h; + int kindset; int temp = -1; int ret; + if ((rep = hid_get_report_desc(fd)) == NULL) + goto use_ioctl; + kindset = 1 << hid_input | 1 << hid_output | 1 << hid_feature; + for (d = hid_start_parse(rep, kindset, 0); hid_get_item(d, &h); ) { + /* Return the first report ID we met. */ + if (h.report_ID != 0) { + temp = h.report_ID; + break; + } + } + hid_end_parse(d); + hid_dispose_report_desc(rep); + + if (temp > 0) + return (temp); + +use_ioctl: ret = ioctl(fd, USB_GET_REPORT_ID, &temp); #ifdef HID_COMPAT7 if (ret < 0) |