Missing one byte feature report read under Windows for devices without report id #328

Closed
opened 2021-08-30 09:46:22 -05:00 by mcuee · 10 comments
mcuee commented 2021-08-30 09:46:22 -05:00 (Migrated from github.com)

Reference here:
https://github.com/libusb/hidapi/issues/285

Now I start to question the commit github.com/libusb/hidapi@6fcb0bb228 which I proposed in #232 with regard to feature report. It seems to be correct when the report id is not zero. However, it seems to report one less byte when there is no report id. It seems to me for Windows, we may need to report one more byte for reading of feature report when the report id is zero.

Reference here: https://github.com/libusb/hidapi/issues/285 Now I start to question the commit https://github.com/libusb/hidapi/commit/6fcb0bb2282dbb505561a53689eba0c0536570d9 which I proposed in #232 with regard to feature report. It seems to be correct when the report id is not zero. However, it seems to report one less byte when there is no report id. It seems to me for Windows, we may need to report one more byte for reading of feature report when the report id is zero.
mcuee commented 2021-08-30 09:47:37 -05:00 (Migrated from github.com)

https://github.com/libusb/hidapi/issues/285#issuecomment-907570047

Just tried hidapitester with hidapi-0.10.1 release and hidapi git head, with regard to input report, the result is the same since it is using hid_read_timeout(). So #232 does not matter in that case.
https://github.com/todbot/hidapitester/blob/master/hidapitester.c#L379

With regard to feature report, then the result will be different as it uses hid_get_feature_report(). So commit github.com/libusb/hidapi@6fcb0bb228 does matter for getting the feature report. In this particular case without report id (report id zero), it seems to me the commit is not correct.
https://github.com/todbot/hidapitester/blob/master/hidapitester.c#L403

$ ./hidapitester_release0101.exe --vidpid=0925:7001 --open --send-feature 0,0x40,0x41 --read-feature 0
Opening device, vid/pid: 0x0925/0x7001
Writing 64-byte feature report...wrote 64 bytes:
 00 40 41 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
Reading 64-byte feature report, report_id 0...read 3 bytes:
 00 40 41 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
Closing device

$ ./hidapitester_git4d63a50.exe --vidpid=0925:7001 --open --send-feature 0,0x40,0x41 --read-feature 0
Opening device, vid/pid: 0x0925/0x7001
Writing 64-byte feature report...wrote 64 bytes:
 00 40 41 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
Reading 64-byte feature report, report_id 0...read 2 bytes:
 00 40 41 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
Closing device
https://github.com/libusb/hidapi/issues/285#issuecomment-907570047 Just tried hidapitester with hidapi-0.10.1 release and hidapi git head, with regard to input report, the result is the same since it is using hid_read_timeout(). So #232 does not matter in that case. https://github.com/todbot/hidapitester/blob/master/hidapitester.c#L379 With regard to feature report, then the result will be different as it uses hid_get_feature_report(). So commit https://github.com/libusb/hidapi/commit/6fcb0bb2282dbb505561a53689eba0c0536570d9 does matter for getting the feature report. In this particular case without report id (report id zero), it seems to me the commit is not correct. https://github.com/todbot/hidapitester/blob/master/hidapitester.c#L403 ``` $ ./hidapitester_release0101.exe --vidpid=0925:7001 --open --send-feature 0,0x40,0x41 --read-feature 0 Opening device, vid/pid: 0x0925/0x7001 Writing 64-byte feature report...wrote 64 bytes: 00 40 41 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 Reading 64-byte feature report, report_id 0...read 3 bytes: 00 40 41 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 Closing device $ ./hidapitester_git4d63a50.exe --vidpid=0925:7001 --open --send-feature 0,0x40,0x41 --read-feature 0 Opening device, vid/pid: 0x0925/0x7001 Writing 64-byte feature report...wrote 64 bytes: 00 40 41 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 Reading 64-byte feature report, report_id 0...read 2 bytes: 00 40 41 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 Closing device ```
Youw commented 2021-09-04 10:24:09 -05:00 (Migrated from github.com)

Do you think we need to do the same as we do for macOS?

Do you think we need to do the same as we do for [macOS](https://github.com/libusb/hidapi/blob/4d63a5085ac6e6a5be6f0f29a42a4e739da30881/mac/hid.c#L940)?
mcuee commented 2021-09-04 20:45:02 -05:00 (Migrated from github.com)

Do you think we need to do the same as we do for macOS?

Yes I think that will fix this issue.

> Do you think we need to do the same as we do for [macOS](https://github.com/libusb/hidapi/blob/4d63a5085ac6e6a5be6f0f29a42a4e739da30881/mac/hid.c#L940)? Yes I think that will fix this issue.
Youw commented 2021-09-22 08:35:51 -05:00 (Migrated from github.com)

I think this one is worth fixing before releasing v0.11.0

I think this one is worth fixing before releasing v0.11.0
Youw commented 2021-09-22 08:59:27 -05:00 (Migrated from github.com)

After reading the documentation for IOCTL_HID_GET_INPUT_REPORT and IOCTL_HID_GET_FEATURE one more time, combined with your test results, I believe input_report is as broken as feature_report

After reading the documentation for `IOCTL_HID_GET_INPUT_REPORT` and `IOCTL_HID_GET_FEATURE` one more time, combined with your test results, I believe `input_report` is as broken as `feature_report`
mcuee commented 2021-09-22 21:11:52 -05:00 (Migrated from github.com)

After reading the documentation for IOCTL_HID_GET_INPUT_REPORT and IOCTL_HID_GET_FEATURE one more time, combined with your test results, I believe input_report is as broken as feature_report

Let me test out #334 over the weekend.

> After reading the documentation for `IOCTL_HID_GET_INPUT_REPORT` and `IOCTL_HID_GET_FEATURE` one more time, combined with your test results, I believe `input_report` is as broken as `feature_report` Let me test out #334 over the weekend.
mcuee commented 2021-09-27 02:04:48 -05:00 (Migrated from github.com)

Firstly for feature report for device without report ID.

I think #334 is correct since it reports reading 3 bytes. Release 0.10.1 is actually correct but then github.com/libusb/hidapi@6fcb0bb228 introduced the regression. #334 fixes the issue in the current master.

$ ./hidapitester_release0101.exe --vidpid=0925:7001 --open --send-feature 0,0x40,0x41 --read-feature 0
Opening device, vid/pid: 0x0925/0x7001
Writing 64-byte feature report...wrote 64 bytes:
 00 40 41 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
Reading 64-byte feature report, report_id 0...read 3 bytes:
 00 40 41 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
Closing device

$ ./hidapitester_hidapi_master.exe --vidpid=0925:7001 --open --send-feature 0,0x40,0x41 --read-feature 0
Opening device, vid/pid: 0x0925/0x7001
Writing 64-byte feature report...wrote 64 bytes:
 00 40 41 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
Reading 64-byte feature report, report_id 0...read 2 bytes:
 00 40 41 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
Closing device

$ ./hidapitester_hidapi_fix_feature.exe --vidpid=0925:7001 --open --send-feature 0,0x40,0x41 --read-feature 0
Opening device, vid/pid: 0x0925/0x7001
Writing 64-byte feature report...wrote 64 bytes:
 00 40 41 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
Reading 64-byte feature report, report_id 0...read 3 bytes:
 00 40 41 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
Closing device

Firstly for feature report for device without report ID. I think #334 is correct since it reports reading 3 bytes. Release 0.10.1 is actually correct but then https://github.com/libusb/hidapi/commit/6fcb0bb2282dbb505561a53689eba0c0536570d9 introduced the regression. #334 fixes the issue in the current master. ``` $ ./hidapitester_release0101.exe --vidpid=0925:7001 --open --send-feature 0,0x40,0x41 --read-feature 0 Opening device, vid/pid: 0x0925/0x7001 Writing 64-byte feature report...wrote 64 bytes: 00 40 41 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 Reading 64-byte feature report, report_id 0...read 3 bytes: 00 40 41 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 Closing device $ ./hidapitester_hidapi_master.exe --vidpid=0925:7001 --open --send-feature 0,0x40,0x41 --read-feature 0 Opening device, vid/pid: 0x0925/0x7001 Writing 64-byte feature report...wrote 64 bytes: 00 40 41 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 Reading 64-byte feature report, report_id 0...read 2 bytes: 00 40 41 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 Closing device $ ./hidapitester_hidapi_fix_feature.exe --vidpid=0925:7001 --open --send-feature 0,0x40,0x41 --read-feature 0 Opening device, vid/pid: 0x0925/0x7001 Writing 64-byte feature report...wrote 64 bytes: 00 40 41 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 Reading 64-byte feature report, report_id 0...read 3 bytes: 00 40 41 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 Closing device ```
mcuee commented 2021-09-27 02:13:52 -05:00 (Migrated from github.com)

Secondly for devices with report ID. No regression from the current master. Release 0.10.1 is not correct and it was fixed by github.com/libusb/hidapi@6fcb0bb228 .

$ ./hidapitester_release0101.exe --vidpid=0925:7001 --open --send-feature 3,0x40,0x41 --read-feature 4
Opening device, vid/pid: 0x0925/0x7001
Writing 64-byte feature report...wrote 64 bytes:
 03 40 41 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
Reading 64-byte feature report, report_id 4...read 4 bytes:
 04 40 41 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
Closing device

$ ./hidapitester_hidapi_master.exe --vidpid=0925:7001 --open --send-feature 3,0x40,0x41 --read-feature 4
Opening device, vid/pid: 0x0925/0x7001
Writing 64-byte feature report...wrote 64 bytes:
 03 40 41 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
Reading 64-byte feature report, report_id 4...read 3 bytes:
 04 40 41 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
Closing device

$ ./hidapitester_hidapi_fix_feature.exe --vidpid=0925:7001 --open --send-feature 3,0x40,0x41 --read-feature 4
Opening device, vid/pid: 0x0925/0x7001
Writing 64-byte feature report...wrote 64 bytes:
 03 40 41 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
Reading 64-byte feature report, report_id 4...read 3 bytes:
 04 40 41 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
Closing device

Secondly for devices with report ID. No regression from the current master. Release 0.10.1 is not correct and it was fixed by https://github.com/libusb/hidapi/commit/6fcb0bb2282dbb505561a53689eba0c0536570d9 . ``` $ ./hidapitester_release0101.exe --vidpid=0925:7001 --open --send-feature 3,0x40,0x41 --read-feature 4 Opening device, vid/pid: 0x0925/0x7001 Writing 64-byte feature report...wrote 64 bytes: 03 40 41 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 Reading 64-byte feature report, report_id 4...read 4 bytes: 04 40 41 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 Closing device $ ./hidapitester_hidapi_master.exe --vidpid=0925:7001 --open --send-feature 3,0x40,0x41 --read-feature 4 Opening device, vid/pid: 0x0925/0x7001 Writing 64-byte feature report...wrote 64 bytes: 03 40 41 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 Reading 64-byte feature report, report_id 4...read 3 bytes: 04 40 41 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 Closing device $ ./hidapitester_hidapi_fix_feature.exe --vidpid=0925:7001 --open --send-feature 3,0x40,0x41 --read-feature 4 Opening device, vid/pid: 0x0925/0x7001 Writing 64-byte feature report...wrote 64 bytes: 03 40 41 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 Reading 64-byte feature report, report_id 4...read 3 bytes: 04 40 41 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 Closing device ```
mcuee commented 2021-09-27 02:21:19 -05:00 (Migrated from github.com)

hdiapitester can not be used to test #334 though as it uses hid_read_timeout().
https://github.com/libusb/hidapi/issues/285#issuecomment-907570047

hdiapitester can not be used to test #334 though as it uses hid_read_timeout(). https://github.com/libusb/hidapi/issues/285#issuecomment-907570047
mcuee commented 2021-09-27 02:24:49 -05:00 (Migrated from github.com)

After reading the documentation for IOCTL_HID_GET_INPUT_REPORT and IOCTL_HID_GET_FEATURE one more time, combined with your test results, I believe input_report is as broken as feature_report

Even though I can not use hidapitester to test the input report, but I agree with you after reading the documentation one more time.

https://docs.microsoft.com/en-us/windows-hardware/drivers/ddi/hidclass/ni-hidclass-ioctl_hid_get_feature
https://docs.microsoft.com/en-us/windows-hardware/drivers/ddi/hidclass/ni-hidclass-ioctl_hid_get_input_report

> After reading the documentation for `IOCTL_HID_GET_INPUT_REPORT` and `IOCTL_HID_GET_FEATURE` one more time, combined with your test results, I believe `input_report` is as broken as `feature_report` Even though I can not use hidapitester to test the input report, but I agree with you after reading the documentation one more time. https://docs.microsoft.com/en-us/windows-hardware/drivers/ddi/hidclass/ni-hidclass-ioctl_hid_get_feature https://docs.microsoft.com/en-us/windows-hardware/drivers/ddi/hidclass/ni-hidclass-ioctl_hid_get_input_report
Sign in to join this conversation.
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
gh-libusb/hidapi#328
No description provided.