-
-
Notifications
You must be signed in to change notification settings - Fork 39.8k
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
Return USB HID GET_REPORT requests #14814
Conversation
|
I wonder whether this could be done in a more generic way somehow — we have some more optional HID interfaces ( |
tmk_core/protocol/chibios/usb_main.c
Outdated
default: | ||
usbSetupTransfer(usbp, NULL, 0, NULL); | ||
return TRUE; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure whether replying with zero-length data is a proper way to handle an HID_GET_REPORT
with some unexpected parameters. Looks like the underlying ChibiOS code might not be handling this case properly: https://github.com/qmk/ChibiOS/blob/413e39c5681d181720440f2a8b7391f581788d7b/os/hal/src/hal_usb.c#L828-L849 (it will go directly to USB_EP0_OUT_WAITING_STS
and wait for the OUT
packet from the host, but actually the host will send IN
packets, expecting the requested data). So a better solution might be return FALSE
, which will stall the endpoint and fail the control transfer. This needs some actual testing on various host OS versions though.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this is the core of the problem here - returning false like this does address the issue as well, so that is an option. Do you know if usbSetupTransfer(usbp, NULL, 0, NULL);
is appropriate in the other contexts it's used in here?
Co-authored-by: Sergey Vlasov <sigprof@gmail.com>
Co-authored-by: Sergey Vlasov <sigprof@gmail.com>
Thank you for your contribution! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Replying with at least an empty report will probably solve the timeout issues that some people see (although a 100% correct solution would probably be to actually store the last sent report of each type, I'm not sure whether any real HID host actually uses the GET_REPORT
request outside of the device initialization). The only remaining issue is handling of some definitely wrong requests (someone may claim that it's a security issue, because technically it could allow someone to read a limited amount of RAM contents that happened to be located after universal_report_blank
).
default: | ||
usbSetupTransfer(usbp, NULL, 0, NULL); | ||
universal_report_blank.report_id = usbp->setup[2]; | ||
usbSetupTransfer(usbp, (uint8_t *)&universal_report_blank, usbp->setup[6], NULL); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we guard against an attempt to read the MCU RAM beyond sizeof(universal_report_blank)
here? Either clamp the size, or just return FALSE
on a bad value (probably should not care much about the particular kind of error if the host definitely tries to do something wrong).
I had flashed my Preonic v3 with a test build that @tzarc provided and that solved the problem of going into the Preonic becoming non responsive after using layers. I am using the latest available version of Mint Linux (20.3 "Una") where when using a layer key will almost always make the keyboard non-responsive until it's unplugged and reconnected. |
Thank you for your contribution! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's get this in and iron out the details over the rest of the develop cycle.
Co-authored-by: Sergey Vlasov <sigprof@gmail.com> Co-authored-by: Nick Brassel <nick@tzarc.org>
The keyboard can still detect NKRO but the HID report limits that to 6KRO. Causes slow start up on Linux. Probably be related to: - qmk/qmk_firmware#8733 - qmk/qmk_firmware#14814 - qmk/qmk_firmware#19372 Signed-off-by: Daniel Schaefer <dhs@frame.work>
Description
This adds the responses to GET_REPORT that the USB HID spec requires. Some of this got removed in #3951, but it's necessary to return the GET_REPORT requests for the keyboard to work in a timely fashion - otherwise it can take up to 20s to start working on Linux (specifically Debian on arm). Other features that have their own interfaces may require the same sort of treatment. My understanding of this is the host queries these interfaces as soon as it gets the USB configuration and descriptors, so if it's in there, it needs to be handled.
SET_REPORT needs some similar handling for NKRO, but it's optional there, whereas GET_REPORT is required.
Wireshark may be useful in figuring out which systems query which interfaces/reports - that's how I could tell they weren't being responded to.
Types of Changes
Issues Fixed or Closed by This PR
Checklist