Skip to content

Commit d67b5c9

Browse files
Be-ingYouw
authored andcommitted
implement hid_get_input_report for Linux hidraw backend
Fixes libusb/hidapi#259
1 parent b66d7c2 commit d67b5c9

File tree

1 file changed

+14
-5
lines changed

1 file changed

+14
-5
lines changed

linux/hid.c

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,13 @@
6262
#endif
6363

6464

65+
// HIDIOCGINPUT is not defined in Linux kernel headers < 5.11.
66+
// This definition is from hidraw.h in Linux >= 5.11.
67+
// https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=f43d3870cafa2a0f3854c1819c8385733db8f9ae
68+
#ifndef HIDIOCGINPUT
69+
#define HIDIOCGINPUT(len) _IOC(_IOC_WRITE|_IOC_READ, 'H', 0x0A, len)
70+
#endif
71+
6572
/* USB HID device property names */
6673
const char *device_string_names[] = {
6774
"manufacturer",
@@ -1065,13 +1072,15 @@ int HID_API_EXPORT hid_get_feature_report(hid_device *dev, unsigned char *data,
10651072
return res;
10661073
}
10671074

1068-
// Not supported by Linux HidRaw yet
10691075
int HID_API_EXPORT HID_API_CALL hid_get_input_report(hid_device *dev, unsigned char *data, size_t length)
10701076
{
1071-
(void)dev;
1072-
(void)data;
1073-
(void)length;
1074-
return -1;
1077+
int res;
1078+
1079+
res = ioctl(dev->device_handle, HIDIOCGINPUT(length), data);
1080+
if (res < 0)
1081+
register_device_error_format(dev, "ioctl (GINPUT): %s", strerror(errno));
1082+
1083+
return res;
10751084
}
10761085

10771086
void HID_API_EXPORT hid_close(hid_device *dev)

0 commit comments

Comments
 (0)