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

Bug: the report ID is only prepended on Windows. It should be prepended for macOS/linux as well. #30

Open
benma opened this issue Oct 24, 2022 · 0 comments

Comments

@benma
Copy link

benma commented Oct 24, 2022

Hi

Here, the report ID is prepended, but only for Windows:

usb/hid_enabled.go

Lines 126 to 128 in 87927bb

if runtime.GOOS == "windows" {
report = append([]byte{0x00}, b...)
} else {

The same issue exists in the hid repo, where I commented about the same issue in 2018: karalabe/hid#7 (comment)

Since the first byte after the report ID can legitimately be a zero byte (a USB packet that starts with a zero byte), this code is broken on linux/macOS, where one has to manually prepend that zero byte report ID. Without prepending the zero byte report ID for linux/macOS, the lower level library will strip the the first byte if it is zero (see below), corrupting the packet:

usb/hidapi/libusb/hid.c

Lines 1003 to 1007 in 87927bb

if (report_number == 0x0) {
data++;
length--;
skipped_report_id = 1;
}

This is a hard issue to find, as it can be a rare event that a packet starts with a zero byte (after the report ID).

See e.g. this PR which implements this workaround: https://github.com/digitalbitbox/bitbox02-api-go/pull/73/files

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant