I maintain the NUT package for pfSense and have run into an issue with USB permissions for some UPS models. NB: My testing is against nut-2.8.0_13, but I haven't seen anything suggesting that the issue is resolved in later port revisions. The permission problem arrises from the fact that the kernel attaches a driver to the device during initialization, and this subsequently prevents the device from being opened by usbhid-ups. The error reported is "Can't claim USB device" The following demonstrates the specifics: ----- [23.01-RELEASE][root@fw]/root: usbconfig -d ugen0.2 show_ifdrv ugen0.2: <American Power Conversion Smart-UPS1000 FW:UPS 16.0 / ID1047> at usbus0, cfg=0 md=HOST spd=FULL (12Mbps) pwr=ON (10mA) ugen0.2.0: uhid0: <American Power Conversion Smart-UPS1000 FW:UPS 16.0 / ID1047, class 0/0, rev 2.00/0.01, addr 4> [23.01-RELEASE][root@fw]/root: /usr/local/libexec/nut/usbhid-ups -a ups Network UPS Tools - Generic HID driver 0.47 (2.8.0) USB communication driver (libusb 1.0) 0.43 interrupt pipe disabled (add 'pollonly' flag to 'ups.conf' to get rid of this message) Can't claim USB device [051d:0003]@0/0: Other error [23.01-RELEASE][root@fw]/root: usbconfig -d ugen0.2 detach_kernel_driver [23.01-RELEASE][root@fw]/root: usbconfig -d ugen0.2 show_ifdrv ugen0.2: <American Power Conversion Smart-UPS1000 FW:UPS 16.0 / ID1047> at usbus0, cfg=0 md=HOST spd=FULL (12Mbps) pwr=ON (10mA) [23.01-RELEASE][root@fw]/root: /usr/local/libexec/nut/usbhid-ups -a ups Network UPS Tools - Generic HID driver 0.47 (2.8.0) USB communication driver (libusb 1.0) 0.43 interrupt pipe disabled (add 'pollonly' flag to 'ups.conf' to get rid of this message) Using subdriver: APC HID 0.98 [23.01-RELEASE][root@fw]/root: ----- As you would expect, if the "-u root" option is added to usbhid-ups then it will succeed even if the kernel driver is currently attached. I note that this permission issue is also present in the truss outputs in bug #267144
Looks like it is indeed a missing quirk definition in the kernel. As noted previously, newer APC UPSs use product id 0x0003 rather than 0x0002. I'll get a PR up.
Created attachment 240309 [details] APC Smart-UPS1000 patch Can you try this, please.
(In reply to Cy Schubert from comment #2) Hi Cy, thank you for your reply. Unfortunately I am not able to directly produce a kernel build for pfSense, so I don't have a mechanism to directly try the patch. However, if the patch results in the same quirk as this command usbconfig add_dev_quirk_vlph 0x051d 0x0003 0x0000 0xffff UQ_HID_IGNORE then it should work. I'm expecting to see this as the quirk list for APC: [23.01-RELEASE][root@fw]/root: usbconfig dump_device_quirks | grep 0x051d VID=0x051d PID=0x0002 REVLO=0x0000 REVHI=0xffff QUIRK=UQ_HID_IGNORE VID=0x051d PID=0x0003 REVLO=0x0000 REVHI=0xffff QUIRK=UQ_HID_IGNORE [23.01-RELEASE][root@fw]/root: Thanks, Denny
(In reply to Denny Page from comment #3) The patch wasn't intended to add a quirk. It added a USB device recognition entry. Do you have any documentation about the device to tell us which quirk bits to set?
(In reply to Cy Schubert from comment #4) > The patch wasn't intended to add a quirk. It added a USB device recognition entry. Apologies, I didn't understand what to do with it then. > Do you have any documentation about the device to tell us which quirk bits to set? Exactly the same as the prior generation devices. The devices are just the newer generation of APC UPSs. Last year or two. The only quirk necessary (at least in my testing) is that the device should be ignored by the hid class. This is exactly the same as the prior generation of APC UPS devices. In this example [23.01-RELEASE][root@fw]/root: usbconfig dump_device_quirks | grep 0x051d VID=0x051d PID=0x0002 REVLO=0x0000 REVHI=0xffff QUIRK=UQ_HID_IGNORE VID=0x051d PID=0x0003 REVLO=0x0000 REVHI=0xffff QUIRK=UQ_HID_IGNORE [23.01-RELEASE][root@fw]/root: The first quirk is for the prior generation UPS devices, and the second quirk is for the new generation of devices. Does this make sense?
Created attachment 240317 [details] Add uhid ignore quirk for APC UPS1000 Try this patch,
Comment on attachment 240317 [details] Add uhid ignore quirk for APC UPS1000 I believe the second patch should be adjusted like so: -- diff --git a/sys/dev/usb/usbdevs b/sys/dev/usb/usbdevs index 5a369cdb9df4..1b20d1821c7e 100644 --- a/sys/dev/usb/usbdevs +++ b/sys/dev/usb/usbdevs @@ -1097,6 +1097,9 @@ product AMOI H02 0x0802 H02 3G modem /* American Power Conversion products */ product APC UPS 0x0002 Uninterruptible Power Supply +/* American Power Conversion products */ +product APC UPS1000 0x0003 Uninterruptible Power Supply + /* Ambit Microsystems products */ product AMBIT WLAN 0x0302 WLAN product AMBIT NTL_250 0x6098 NTL 250 cable modem -- I.E. 0x0003 instead of 0x0002 for the product.
Created attachment 240318 [details] Correct patch (In reply to Denny Page from comment #7) Oops. Thanks for catching that.
(In reply to Cy Schubert from comment #8) I believe those patches will work. Thanks.
A commit in branch main references this bug: URL: https://cgit.FreeBSD.org/src/commit/?id=8866ea619a1f91616ba7e002a3ad10dfb10148c9 commit 8866ea619a1f91616ba7e002a3ad10dfb10148c9 Author: Cy Schubert <cy@FreeBSD.org> AuthorDate: 2023-02-22 02:38:16 +0000 Commit: Cy Schubert <cy@FreeBSD.org> CommitDate: 2023-02-28 13:46:00 +0000 usb: Add HID_IGNORE quirk for APC Smart-UPS1000 Without the HID_IGNORE quirk enabled it will appear to be a uhid device. PR: 269729 MFC after: 1 week sys/dev/usb/quirk/usb_quirk.c | 1 + 1 file changed, 1 insertion(+)
A commit in branch stable/13 references this bug: URL: https://cgit.FreeBSD.org/src/commit/?id=c6ee35809ad3a23d0aa9c9a3f3bab717d46432da commit c6ee35809ad3a23d0aa9c9a3f3bab717d46432da Author: Cy Schubert <cy@FreeBSD.org> AuthorDate: 2023-02-22 02:38:16 +0000 Commit: Cy Schubert <cy@FreeBSD.org> CommitDate: 2023-03-08 14:30:43 +0000 usb: Add HID_IGNORE quirk for APC Smart-UPS1000 Without the HID_IGNORE quirk enabled it will appear to be a uhid device. PR: 269729 (cherry picked from commit 8866ea619a1f91616ba7e002a3ad10dfb10148c9) sys/dev/usb/quirk/usb_quirk.c | 1 + 1 file changed, 1 insertion(+)
A commit in branch stable/12 references this bug: URL: https://cgit.FreeBSD.org/src/commit/?id=4e16ea3de70ecc355a0c10adb8515a5bba27ae03 commit 4e16ea3de70ecc355a0c10adb8515a5bba27ae03 Author: Cy Schubert <cy@FreeBSD.org> AuthorDate: 2023-02-22 02:38:16 +0000 Commit: Cy Schubert <cy@FreeBSD.org> CommitDate: 2023-03-08 14:32:17 +0000 usb: Add HID_IGNORE quirk for APC Smart-UPS1000 Without the HID_IGNORE quirk enabled it will appear to be a uhid device. PR: 269729 (cherry picked from commit 8866ea619a1f91616ba7e002a3ad10dfb10148c9) sys/dev/usb/quirk/usb_quirk.c | 1 + 1 file changed, 1 insertion(+)
Fixed.
*** Bug 275659 has been marked as a duplicate of this bug. ***