Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added support for Get Input Report to linux, mac, windows and libusb. #59

Merged
merged 13 commits into from
Nov 15, 2019

Conversation

DanielVanNoord
Copy link
Contributor

This was tested for all operating systems and each worked identically.

@Youw Youw added the don't_merge Don't merge this PR as is label Aug 1, 2019
Copy link
Member

@Youw Youw left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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_report before #3

hidraw implementation does not respect length parameter, which may lead to memory corruption

libusb implementation seems fine to me


Thanks!
I was going to have it implemented for some while, this is a good start.

Some notes:

  1. This is a major change (new API), we should update version too
  2. Along with new version, I think it makes sense add a way to determine library version in compile/run-time.

hidapi/hidapi.h Outdated Show resolved Hide resolved
linux/hid.c Outdated Show resolved Hide resolved
DanielVanNoord and others added 3 commits August 1, 2019 13:37
Co-Authored-By: Ihor Dutchak <ihor.youw@gmail.com>
@DanielVanNoord
Copy link
Contributor Author

Windows 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.

@Youw
Copy link
Member

Youw commented Aug 1, 2019

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 length bytes of that data to data

@Youw
Copy link
Member

Youw commented Aug 1, 2019

regarding mac and #60 - lets wait for comments of other maintainers/users

linux/hid.c Outdated Show resolved Hide resolved
@Youw
Copy link
Member

Youw commented Aug 1, 2019

something doesn't adds up in hidraw implementation: if I understand how ioctl works, as per HIDIOCGREPORT definition, its argument can only be struct hiddev_report_info, not some user data

I'll spend more time investigating it a bit later

@DanielVanNoord
Copy link
Contributor Author

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.

@Youw Youw self-assigned this Aug 1, 2019
Copy link
Member

@Qbicz Qbicz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me, with a few minor comments.

hidapi/hidapi.h Outdated Show resolved Hide resolved
linux/hid.c Outdated Show resolved Hide resolved
windows/hid.c Show resolved Hide resolved
windows/hid.c Outdated Show resolved Hide resolved
@DavidCNelson
Copy link

DavidCNelson commented Aug 5, 2019

regarding mac and #60 - lets wait for comments of other maintainers/users

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_report in 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 for hid_get_feature_report and hid_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.

@Youw
Copy link
Member

Youw commented Aug 5, 2019

HID Spec v1.11 in section 5.6 also specifies how to know if a device is using numbered reports:

A Report ID item tag assigns a 1-byte identification prefix to each report transfer. If no Report ID item tags are present in the Report descriptor, it can be assumed that only one Input, Output, and Feature report structure exists and together they represent all of the device’s data.

@DanielVanNoord, @DavidCNelson can you confirm, that your devices defines corresponding Report IDs tags in the Report descriptor?

@DavidCNelson
Copy link

HID Spec v1.11 in section 5.6 also specifies how to know if a device is using numbered reports:

A Report ID item tag assigns a 1-byte identification prefix to each report transfer. If no Report ID item tags are present in the Report descriptor, it can be assumed that only one Input, Output, and Feature report structure exists and together they represent all of the device’s data.

@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.

@DanielVanNoord
Copy link
Contributor Author

Same here, the device I am working on uses report IDs in the descriptors for all transfers.

linux/hid.c Outdated Show resolved Hide resolved
linux/hid.c Outdated Show resolved Hide resolved
Co-Authored-By: Ihor Dutchak <ihor.youw@gmail.com>
@Youw Youw removed the don't_merge Don't merge this PR as is label Sep 24, 2019
Copy link
Member

@Youw Youw left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@DanielVanNoord please resolve merge conflict, and:

@DanielVanNoord
Copy link
Contributor Author

@Youw Should be taken care of now

linux/hid.c Outdated Show resolved Hide resolved
windows/hid.c Outdated Show resolved Hide resolved
@Youw Youw requested a review from Qbicz November 10, 2019 12:21
@Youw Youw merged commit 083223e into libusb:master Nov 15, 2019
@mcuee mcuee added Core Related to common codes like hidapi.h hidraw Related to Linux/hidraw backend libusb Related to libusb backend macOS Related to macOS backend Windows Related to Windows backend labels Jul 18, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Core Related to common codes like hidapi.h hidraw Related to Linux/hidraw backend libusb Related to libusb backend macOS Related to macOS backend Windows Related to Windows backend
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants