You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I was curious about the pragmatics of supporting various BSDs. There seems to be a fairly common API for HID over USB on most common BSDs called usbhid which is intended to be used with the uhid kernel driver for generic HID devices. Support for this is likely a necessity because several BSD ports of libusb cannot be used with USB devices already reserved by a kernel driver.
I'm too unfamiliar with HID myself to work on this at present, but is there anyone else willing to put in the effort to add this as a hidapi backend?
I am not so sure if there is any interest to have the uhid backend for FreeBSD as the existing libusb backedn works fine (libusb is part of FreeBSD now, and it is using FreeBSD's own libusb implementation with BSD license). So you can arguably call it native for FreeBD as well. hidraw backend seems to be more interesting for FreeBSD.
But I agree that it will be good to have uhid backend for NetBSD and OpenBSD, if it is possible. HIDAPI libusb backend for NetBSD/OpenBSD require rebuilding the kernel last time I checked, so it is not really that useful.
Instead of linking against uhidusbhid HIDAPI could load it dynamically - that way we avoid symbol conflict.
Also, for HIDAPI v1 I think hid_init will be renamed to hidapi_initialize (and it will become context-specific initialisation, similar to what libusb uses).
What I was referring to it the optional high level library usbhid
Excuse me for confusion, I really meant usbhid.
Is there even an API in hidapi to handle this?
In the case of a device with multiple report IDs being split across multiple devices, how should I approach this?
This is an interesting problem.
As per current HIDAPI design, each hid_device is only as unique as VID/PID/SerialNumber/UsagePage/Usage combination (and it is not even always true for the UsagePage/Usage part - but that's a different story).
HIDAPI doesn't support "device-per-report" abstraction as it assumes that a single device may support multiple reports (that's why a report ID is explicitly passed as part of data payload).
To support the uhid abstraction, the HIDAPI implementation would have to do it under the hood:
parse the report descriptor;
find a list of reports supported by the device;
first time a report is tried to read/write - open a corresponding per-report uhid device and use it to send/receive data.
I believe opening all devices at once would be overkill, if even possible (what about exclusive/shared access, read/write permissions, etc.?). Lookup table - yes, plus lazy device opening, only if/when needed.
@Youw Does the libusb backend on FreeBSD have to completely disable the HID kernel driver to work? I was considering that in some niche situations it may be good to have the option to use the native kernel interface since devices in some cases will expose multiple HID interfaces.
No. That is the beauty of FreeBSD USB stack. It exposes ugen driver along with uhid for generic USB HID devices, so that you can use libusb backend out of box.
Unfortunately Hans Petter Selasky passed away recently. If not I would ask him to explain how it works.
I see. How unfortunate. I think I will just work on OpenBSD backend and consider uhid work complete. I have an idea for how to make it work. It won't be ideal but it is still an improvement due to how limited libusb on OpenBSD is. Notable limitations would be that it would not be possible to enumerate uhid devices that are already in use.
Having a uhid backend for OpenBSD will be great. Thanks. As you mentioned, it will still be much better than libusb backend.
In fact I consider HIDAPI libusb backend not so useful (in fact kind of useless) for NetBSD/OpenBSD users.
Activity
Youw commentedon Aug 12, 2023
Duplicate of #543 ?
[-]BSD Support[/-][+]Native BSD backend[/+]Youw commentedon Aug 12, 2023
For those who potentially want to start implementing this but don't know where to start (from HIDAPI POV) - here is an example me adding an experimental WinRT backend: https://github.com/libusb/hidapi/compare/winrt
[-]Native BSD backend[/-][+]Native BSD backend using uhid[/+]mcuee commentedon Aug 13, 2023
I am not so sure if there is any interest to have the uhid backend for FreeBSD as the existing libusb backedn works fine (libusb is part of FreeBSD now, and it is using FreeBSD's own libusb implementation with BSD license). So you can arguably call it native for FreeBD as well. hidraw backend seems to be more interesting for FreeBSD.
But I agree that it will be good to have uhid backend for NetBSD and OpenBSD, if it is possible. HIDAPI libusb backend for NetBSD/OpenBSD require rebuilding the kernel last time I checked, so it is not really that useful.
Youw commentedon Aug 13, 2023
Instead of linking against
uhidusbhidHIDAPI could load it dynamically - that way we avoid symbol conflict.Also, for HIDAPI v1 I think
hid_initwill be renamed tohidapi_initialize(and it will become context-specific initialisation, similar to whatlibusbuses).Youw commentedon Aug 15, 2023
Excuse me for confusion, I really meant
usbhid.This is an interesting problem.
As per current HIDAPI design, each
hid_deviceis only as unique as VID/PID/SerialNumber/UsagePage/Usage combination (and it is not even always true for the UsagePage/Usage part - but that's a different story).HIDAPI doesn't support "device-per-report" abstraction as it assumes that a single device may support multiple reports (that's why a report ID is explicitly passed as part of data payload).
To support the
uhidabstraction, the HIDAPI implementation would have to do it under the hood:uhiddevice and use it to send/receive data.I don't see any better way.
Youw commentedon Aug 15, 2023
I believe opening all devices at once would be overkill, if even possible (what about exclusive/shared access, read/write permissions, etc.?). Lookup table - yes, plus lazy device opening, only if/when needed.
Youw commentedon Aug 16, 2023
Nevertheless thanks for great investigation.
No one has check it this deep in context of HIDAPI.
I'll keep this ticket open for now. Maybe there will be more findings/details.
mcuee commentedon Aug 27, 2023
No. That is the beauty of FreeBSD USB stack. It exposes ugen driver along with uhid for generic USB HID devices, so that you can use libusb backend out of box.
Unfortunately Hans Petter Selasky passed away recently. If not I would ask him to explain how it works.
mcuee commentedon Aug 27, 2023
Having a uhid backend for OpenBSD will be great. Thanks. As you mentioned, it will still be much better than libusb backend.
In fact I consider HIDAPI libusb backend not so useful (in fact kind of useless) for NetBSD/OpenBSD users.
mcuee commentedon Mar 28, 2025
Youw commentedon Mar 28, 2025
Right, closing