Added support for Get Input Report to linux, mac, windows and libusb. #59
Labels
No labels
3rdparty
Android
API
Author does not respond
bsd
bug
build system/CI
ci-virtual-device
CMake
Contributions Welcome
Core
dependencies
device-specific
documentation
don't_merge
duplicate
enhancement
Example
Haiku
hidraw
hotplug
info required
invalid
libusb
macOS
Misc
Not an issue
question
Release
Test
Test GUI
Windows
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
gh-libusb/hidapi!59
Loading…
Reference in a new issue
No description provided.
Delete branch "master"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
This was tested for all operating systems and each worked identically.
Windows implementation better be same as for
hid_send_feature_report, to return actual length(tested in my projects)
mac implementation sends report ID as part of data, as it was in
hid_get_feature_reportbefore #3hidraw implementation does not respect
lengthparameter, which may lead to memory corruptionlibusb implementation seems fine to me
Thanks!
I was going to have it implemented for some while, this is a good start.
Some notes:
@ -334,6 +334,31 @@ extern "C" {*/@ -790,6 +790,11 @@ int HID_API_EXPORT hid_get_feature_report(hid_device *dev, unsigned char *data,return res;}use
register_device_error_formatsame way as inhid_get_feature_reportdoesWindows implementation better be same as for hid_send_feature_report, to return actual length
(tested in my projects)
I converted it over to use this method.
mac implementation sends report ID as part of data, as it was in hid_get_feature_report before #3
See my open issue /issues/60, this works (for me) the other way does not. It is possible that my device is out of spec. But it seems really odd that all the other platforms work and mac, when implemented to spec, does not.
hidraw implementation does not respect length parameter, which may lead to memory corruption
Not sure how to fix this one. The linux api that I am using does not appear to have an option for length.
pass pointer to stack-allocated data that is guaranteed to be large enough for the API, and then copy up to
lengthbytes of that data todataregarding mac and #60 - lets wait for comments of other maintainers/users
@ -790,6 +790,11 @@ int HID_API_EXPORT hid_get_feature_report(hid_device *dev, unsigned char *data,return res;}In the log message it should be
GREPORTas that's the ioctl constant being usedsomething doesn't adds up in hidraw implementation: if I understand how
ioctlworks, as perHIDIOCGREPORTdefinition, its argument can only bestruct hiddev_report_info, not some user dataI'll spend more time investigating it a bit later
It is possible, I wrote (and studied) the windows, mac and libusb implementations. Another developer that I worked with wrote the Linux one (I saw your issue at signal11/hidapi and am trying to up-stream now). I simply verified that it worked with both test boards that I have.
Looks good to me, with a few minor comments.
@ -334,6 +334,31 @@ extern "C" {*/@ -790,6 +790,11 @@ int HID_API_EXPORT hid_get_feature_report(hid_device *dev, unsigned char *data,return res;}Empty line not needed here
@ -818,6 +822,55 @@ int HID_API_EXPORT HID_API_CALL hid_get_feature_report(hid_device *dev, unsigned#endif@ -821,0 +857,4 @@hid_get_feature_report() synchronous. */res = GetOverlappedResult(dev->device_handle, &ol, &bytes_returned, TRUE/*wait*/);if (!res) {/* The operation failed. */Does it make sense to keep this disabled code? I know it is the same way in
hid_get_feature_report(), but what purpose does this code section serve?I am working on a new device with HID and also on the host side. This pull request is rather timely for me as the day it was created was the same day I was getting ready to implement the same functionality.
The issue seems to be the question if there is a report ID at the beginning of the data transfer. The HID Spec v1.11 in section 5.6 describes that if the HID device defines report IDs in the descriptor, then the report ID must be sent as the first byte of all data transfers. If the device does not define report IDs(appears as
report ID == 0), then the non-existent report id is not included in the data transfer.Consider the code in
set_reportin mac/hid.c at lines 774-785. If the report id is 0, it does not send the report ID as part of the data. If the report ID is non-zero, then the whole buffer is sent. A similar thing needs to happen forhid_get_feature_reportandhid_get_input_report. If the report ID is 0, then the received data will not have a report ID, so the data should be read into the buffer starting with the second byte of the buffer. If the report ID is non-zero, the data received should start with the report ID, so you can fill the buffer starting with the first byte.Depending on the device one is using, #3 fixes an issue or, as #60 points out, it is a regression.
HID Spec v1.11 in section 5.6 also specifies how to know if a device is using numbered reports:
@DanielVanNoord, @DavidCNelson can you confirm, that your devices defines corresponding Report IDs tags in the Report descriptor?
Yes, the device I'm working with does define report IDs in the descriptor, and so we do use report IDs for all transfers.
@ -821,0 +857,4 @@hid_get_feature_report() synchronous. */res = GetOverlappedResult(dev->device_handle, &ol, &bytes_returned, TRUE/*wait*/);if (!res) {/* The operation failed. */hid_get_feature_report had it so I included it as well. The only benefit I can think of is that it shows that the other way is known and wrong, even though it is much shorter.
Same here, the device I am working on uses report IDs in the descriptors for all transfers.
@ -790,6 +790,11 @@ int HID_API_EXPORT hid_get_feature_report(hid_device *dev, unsigned char *data,return res;}HIDIOCGREPORTexpects ahiddev_report_info, which is declared here.This differs from
HIDIOCGFEATUREwhich takes in the first byte as a report ID.I'm also not sure that this is a valid
ioctlforhidraw-- this looks like it is forhiddev!@ -790,6 +790,11 @@ int HID_API_EXPORT hid_get_feature_report(hid_device *dev, unsigned char *data,return res;}also, I don't see support of Input/Output Reports by hidraw at all
@ -790,6 +790,11 @@ int HID_API_EXPORT hid_get_feature_report(hid_device *dev, unsigned char *data,return res;}Nope, there is none
@ -790,6 +790,11 @@ int HID_API_EXPORT hid_get_feature_report(hid_device *dev, unsigned char *data,return res;}@DanielVanNoord please resolve merge conflict, and:
@Youw Should be taken care of now
remove
@ -109,6 +110,7 @@ extern "C" {typedef BOOLEAN (__stdcall *HidD_GetProductString_)(HANDLE handle, PVOID buffer, ULONG buffer_len);