Repository navigation
Conversation
|
This needs testing as it could be FW problem as well. |
|
Have you tested with hidapi? libusb project recommends HIDAPI for HID device. |
…into winusb_hid_truncation_fix
|
In paticular you can use hidapitester to test your device. Make sure you build it with latest hidapi version (0.14.0 release). Example output: If hidapitester gives expected results but libusb does not, please post your test codes and output. If hidapitester does not give the expected results, then most likely your device has a problem under Windows. Please post the HID report descriptor as well. |
|
Thanks @mcuee, I will try this out. |
|
I have tested using hidapitester on both Windows and Linux, compiled against hidapi 0.14.0 as requested. On Windows: I have deliberately sent 3 read-feature requests because the response I am expecting is the one ending with Given that the device does not use Report IDs, and that my understanding of hidapitester is that it inserts Now I do not consider myself an expert in USB by any means, but according to my reading of the HID specification (https://www.usb.org/sites/default/files/hid1_11.pdf) the device is behaving exactly as it should in this case:
I hope that this will help prove that there is a problem in libusb. However, having reviewed my current proposed fix, I don't believe it to be completely adequate, and will submit a further commit shortly which I believe addresses the issue in a better way. |
|
Edit: I was not correct. Please ignore this comment.
But I will double check again. |
|
I can see hidapitester deals with feature report differently from Input report. So your device seems to behave okay in terms of feature report. Just tested Jan Axelson's generic HID example here. libusb-1.0.26 version works with the device using my test code. libusb git does not work with control transfer for the Feature Report loopback. |
|
@tormodvolden and @kleinerm We may need to deal with Interrupt Transfer (mainly INPUT report, but also possible with OUTPUT report) and Control Transfer (All Feature Report, and also Input/Output report). |
|
I am not so sure if this PR deals with all situations or not. I will carry out more tests later. In any case, I will recommend you to switch to HIDAPI for your HID device, especially under Windows. We were discussing whether to remove Windows HID backend or not last time. The decidion was to make it due to the potentail trouble of removing the HID backend. However, we will strongly encourage users to switch to HIDAPI for HID device. |
The output looks correct as far as I can tell. |
|
Relevant old discussion in hidapi: |
|
Relevant hidapi discussion |
This PR does not work either with Feature Report loopback, for the above device without Report ID. |
|
For now I will suggest we revert PR #1217 as it causes regression. Take note libusb 1.0.26 works fine. |
|
For the other test device with report ID. libusb-1.0.26 release works fine, git works fine as well. PR #1285 also works in this case. libusb 1.0.26 works as expected (report ID will not loop back, the next two bytes will loop back, the extra last byte should not loop back) git works fine as well. This PR works fine too. hidapitester results for reference. |
…out report IDs" This reverts commit 69e4ee6. In the commit (from #1217) it was wrongly assumed what the transfer length actually includes, and the change caused wrong values for Output Report and Feature Report. See also #1285 where the regression was first analyzed. More discussion about lengths reported from HIDAPI point of view: libusb/hidapi#589 References #1217 References #1285
|
I have reverted the commit from PR 1217 so git master should now behave like 1.0.26 again. |
|
I will close this PR for now. |
This change fixes an issue I was experiencing while using libusb on Windows to communicate with a Yubikey device (firmware version 5.1.2). I am working in Rust and using the yubico_manager crate, which ultimately relies on libusb. This was performing SET_REPORT requests with 8-byte outgoing payloads and GET_REPORT requests with 8-byte incoming payloads.
I discovered that the SET_REPORT operations were failing because libusb reported that 7 bytes were transmitted rather than the expected 8. Furthermore, the GET_REPORT operations would fail to fill the final byte of the received buffer. Analysing the actual packets using USBPcap and Wireshark, these were all correctly transmitted over the wire, which indicated that the problem lay in the libusb logic.
Observing that, in both cases, the resultant lengths were off by one, I found two places within the
hid_copy_transfer_datafunction which did decrement the length. This occurred only when the initial byte of the buffer was set to 0, which was interpreted as having been set to compensate for a missing ReportID in functionhid_submit_bulk_transfer. However, this does not consider the possibiltity that the initial byte might have been set to 0 for other reasons which appears to be what happened within the Yubikey protocol.The length was decremented here: #1217
I have attempted to fix the issue by reusing the logic that was used to add the ReportID byte within the
hid_submit_bulk_transferfunction, by using the previously-initialisedpriv->hid->uses_report_idsvalues.I can confirm that this addresses the issue with the Yubikey. Unfortunately I am not entirely familiar with the libusb codebase, nor do I have access to other test devices, so cannot say with confidence that this will break other use cases including that which was addressed in PR 1217.