-
Notifications
You must be signed in to change notification settings - Fork 425
Add hidraw backend for FreeBSD #730
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
base: master
Are you sure you want to change the base?
Conversation
Currently, some stuff like the Report Descriptor parser and error registry routine are copied from Linux and I think they are platform independent. Can we create a common directory or hidraw directory in code then put them inside? Have tested by the hidtest program. |
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.
No more comments
49a7a62
to
6e7a25a
Compare
Thanks for @Youw your review:). Then, What is your opinion about this?
|
I thinjk that is a good idea, but I don't think it really is nesessary to do so in scope of this PR. |
Nice. This will address the following issue. |
Oops. I forget we have udev-devd stuff. Maybe we should use udev also? |
I lost context here. What for? Seem like you have all the functionality implemented already. Aren't you? |
Yes, all functionality is fully implemented. I am just thinking if we should use libudev make hidapi more portable. |
First test under FreeBSD 14.1 Release, under a physical machine (Chuwi mini PC, Intel J4125 CPU, 8GB RAM, 256GB SSD) There are a few compiler warnings.
|
Fix it:). Forget to fix the warning. |
Somehow hidtest-hidraw will seg fault with the Microchip Simple HID example.
|
Thanks. The compiler warnings are gone. The Segfault issue is still there though. |
63cde91
to
26e3444
Compare
|
||
num_devs = libusb_get_device_list(global_usb_context, &list); | ||
if (num_devs < 0) { | ||
register_global_error_format("hid_find_device_handle_by_bus_and_port: %s", libusb_strerror(errno)); |
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.
register_global_error_format("hid_find_device_handle_by_bus_and_port: %s", libusb_strerror(errno)); | |
register_global_error_format("hid_find_device_handle_by_bus_and_port: %s", libusb_strerror(error)); |
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.
updated my comment: should be error
not errno
ignore Archlinux failure and revert your CI changes - not related to this PR - master is failing as well, I'll check |
I am stupid. The get report and set report should return the actual length. @mcuee could you please help me test again? |
Somehow it still does not work.
|
return -1; | ||
} | ||
|
||
bytes_written = write(dev->device_handle, data, length); |
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.
Strip leading zero for unnumbered reports. See write
section of FreeBSD hidraw(4) man.
Don't forget to account for this byte in return value.
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.
HIDRAW_GET_REPORT and HIDRAW_SET_REPORT callers should strip leading zero for unnumbered reports too
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.
@wulf7 are you sure?
I believe this entire implementation should be about hidraw
, not uhid
, and according to https://man.freebsd.org/cgi/man.cgi?hidraw(4)
In the hidraw mode, the first byte should be set to 0 and the report data itself should begin at the second byte.
I.e. - no strip.
if (hid_get_name_from_mib(mib, items, name_buffer, sizeof(name_buffer)) == 0) | ||
return -1; | ||
|
||
return sscanf(name_buffer, "dev.hidraw.%d", &result) == 1 ? result : -1; |
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.
you may add "dev.uhid.%d" nodes here too as they are compatible with hidraw(4) in uhid mode on binary level.
FreeBSD support hidraw in Kernel from 13.0. By using libusb only, we can only see the HID device from usb. To address this, we implement hidraw backend for FreeBSD. Just like Linux use libudev to handle usb specified HID stuff (like Manufacture), we use libusb to handle it. Sponsored-by: FreeBSD Foundation Sponsored-by: Framework Laptop. Inc
Sorry about the confusing code. I would like to clarify first that I think using hidraw mode is better for supporting non-usb hid device (e.g. iichid). I clean up the code so that there is hidraw mode only. |
uhid mode supports non-USB HID devices too. Both modes are comparable. |
If they are compatible, then what point of using both? HIDAPI is intended to be as thin wrapper as possible for HID device drivers (libusb backend is a different story, of course), with uniform API across platforms. Do I miss something about uhid worth mentioning in this scope? |
They are comparable but not compatible. uhid API may be used with old uhid(4) driver. FreeBSD hidraw(4) supports both. Choose one you prefer but do not mix them. |
Now after switching to hidraw mode, it is better to replace all remaining HIDRAW_* ioctls with HIDIOC* ones. |
Ooops. FreeBSD hidraw API is outdated. It misses HIDIOCSOUTPUT and HIDIOCGINPUT ioctls. |
Hmm, what about FreeBSD 15.0-Current? Does it have the two IOCTLs you mentioned? @aokblast is indeed using FreeBSD 15.0-Current for testing. |
Not yet. I made a patch with both ioctls(). It is only compile tested. I'll commit after one has tested it. |
FreeBSD support hidraw in Kernel from 13.0.
By using libusb only, we can only see the HID device from usb. To address this, we implement hidraw backend for FreeBSD.
Just like Linux use libudev to handle usb specified HID stuff (like Manufacture), we use libusb to handle it.
Sponsored-by: FreeBSD Foundation