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

Add rules for accessing HID devices with libusb #6

Merged
merged 1 commit into from
Jan 13, 2025

Conversation

robin-nitrokey
Copy link
Member

@robin-nitrokey robin-nitrokey commented Dec 16, 2024

HID devices can be accessed with libusb or with hidraw. So far, we have mostly been using hidraw and our udev rules only apply to hidraw devices. This patch adds rules for access with libusb as recommended by the hidapi developers:

https://github.com/libusb/hidapi/blob/ff67c77daddbd8e61ad3873ac16f8edc005f943f/udev/69-hid.rules


You can use the following code for testing:

import hid

devices = hid.enumerate()
print("paths: ")
print([d["path"] for d in devices])

for device in devices:
    if device["vendor_id"] == 0x20a0 and device["product_id"] == 0x42dd:
        h = hid.device()
        h.open_path(device["path"])
        h.close()

With hidapi v0.14.0 and v0.14.0.post4, this uses libusb. With hidapi v0.14.0.post1 to v0.14.0.post3, this uses hidraw. (This only applies if hidapi is installed from the PyPI wheels – packaged versions or manual builds may behave differently.) From my experience, a reboot is required to properly apply the new rules.

@jjakob
Copy link

jjakob commented Jan 3, 2025

The rules work fine for me using hidapi v0.14.0.post4. Checked with getfacl /dev/bus/usb/... (path to NK 3A) it shows my user as rw-.

@sosthene-nitrokey
Copy link

Tested and works.

@robin-nitrokey
Copy link
Member Author

Successfully tested on NixOS 24.11.

Overlay
    (final: prev: {
      nitrokey-udev-rules = prev.nitrokey-udev-rules.overrideAttrs (finalAttrs: prevAttrs: {
        src = pkgs.fetchFromGitHub {
          owner = "Nitrokey";
          repo = "nitrokey-udev-rules";
          rev = "5ffac5d0d9dc776f241a9553be5e92656585bd53";
          hash = "sha256-ZALVjSiIGRK+DlFscOhbnZJbjXP15bfgV+ZOqQQ6h7A=";
        };
        dontBuild = true;
        doCheck = false;
      });
    })

HID devices can be accessed with libusb or with hidraw.  So far, we have
mostly been using hidraw and our udev rules only apply to hidraw
devices.  This patch adds rules for access with libusb as recommended by
the hidapi developers:

https://github.com/libusb/hidapi/blob/ff67c77daddbd8e61ad3873ac16f8edc005f943f/udev/69-hid.rules
@robin-nitrokey robin-nitrokey merged commit 0f459f5 into main Jan 13, 2025
4 checks passed
@robin-nitrokey robin-nitrokey deleted the hidapi-libusb branch January 13, 2025 22:03
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

Successfully merging this pull request may close these issues.

4 participants