Skip to content

Use HID_ID to match devices instead of USB specific sysfs attributes#912

Closed
hadess wants to merge 3 commits intonetworkupstools:masterfrom
hadess:wip/hadess/hid-id
Closed

Use HID_ID to match devices instead of USB specific sysfs attributes#912
hadess wants to merge 3 commits intonetworkupstools:masterfrom
hadess:wip/hadess/hid-id

Conversation

@hadess
Copy link
Copy Markdown
Contributor

@hadess hadess commented Nov 26, 2020

This should make it possible to use hid-recorder and hid-replay to emulate UPSes.

See https://gitlab.freedesktop.org/libevdev/hid-tools/-/issues/25

@bentiss, does this look correct to you?

(I haven't tested this beyond checking that the generated files look correct)

See https://lwn.net/Articles/837033/ for an in-depth explanation of how
"bind" events should be handled in udev rules.

In short:
"
The ACTION line causes the entire file to be skipped for anything other than
ADD or CHANGE events; in particular, that is what will happen with BIND
events. That will cause properties associated with those events to be
lost — and the device in question to be set up improperly (if at all).
"
@hadess
Copy link
Copy Markdown
Contributor Author

hadess commented Nov 26, 2020

(This definitely doesn't work, I'll do some more debugging in a bit, at least the matching isn't right...)

Instead of matching on the USB device. This makes it easier to use
hid-record and hid-replay to emulate HID UPS devices.
Why "!= usb" when we're already checking for usb and other values
above? Always go to the end label if we didn't already jump to the
section containing the actual rules.
@hadess
Copy link
Copy Markdown
Contributor Author

hadess commented Nov 26, 2020

And now it should work once https://gitlab.freedesktop.org/libevdev/hid-tools/-/issues/25 gets fixed. The hiddev device isn't getting instantiated right now.

@hadess
Copy link
Copy Markdown
Contributor Author

hadess commented Nov 26, 2020

I've split off the fixes I made in #913

This MR should have been about using HID_ID for matching so hid-replay could be used to mock UPSes, but NUT (and upower) use hiddev, which is only available if the transport is USB, not for uhid/hid.

Ideally, the NUT code would be migrated to use hidraw, so the codepath would be the same for USB UPSes, and "replayed" devices. That's not the case as of now though, and I don't have the bandwidth to work on that right now.

@hadess hadess closed this Nov 26, 2020
@jimklimov
Copy link
Copy Markdown
Member

Thanks for giving this a try! If you get the bandwidth for this later, possibly after we choose and merge one of the libusb-1.x integration branches, seems like it would be a useful to a higher-level dummy-ups.

@clepple
Copy link
Copy Markdown
Member

clepple commented Dec 13, 2020

This MR should have been about using HID_ID for matching so hid-replay could be used to mock UPSes, but NUT (and upower) use hiddev, which is only available if the transport is USB, not for uhid/hid.

For future reference: I haven't looked at upower, but NUT (primarily the usbhid-ups driver) is not actually using hiddev - it is using libusb after detaching the kernel drivers (e.g. hiddev). This was an early design decision, since the original Linux hiddev API did not allow NUT to distinguish between two "Voltage" Usage IDs, say if one was nested under "Battery" and the other under the collection for line power. A user-space HID parsing library was written that used libusb, with the advantage that it still works on non-Linux systems. To mock an UPS, it doesn't seem too farfetched to replay USB pcaps into libusb.

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.

3 participants