# solved: USB UPS, udev, and nut with kernel 2.6.22

## gocantor

Hi all,

Here's a brief history of my adventure: I purchased a CyberPower 685AVR and decided to connect it through USB to my Gentoo machine. While the device was detected properly and added to /dev, it was added with the wrong permissions (gid was set to 'usb' instead of 'nut', as implied by the rules under /etc/udev/rules.d/70-nut-usbups.rules). Worse, it was improperly setup only during udev coldplug, whereas hotplug worked fine. Finally, when I recompiled the kernel without CONFIG_USB_DEVICE_CLASS (which is marked DEPRECATED as of 2.6.22), it constantly added the device with the wrong gid...

After spending many hours, I managed to find a hint to the solution: the default udev rules that are installed with nut assume that, as far as the kernel event, SUBSYSTEM needs to be 'usb_device'. Nonetheless, this is only the case with kernels up to 2.6.21, or newer kernels compiled with CONFIG_USB_DEVICE_CLASS. (Also, I suspect that with the latter, SUBSYSTEM is set to 'usb_device' only during hotplug, which will explain my weird situation above.)  However, with the recent kernel the SUBSYSTEM is set to 'usb', but udev default rules (/etc/udev/rules.d/50-udev.rules) set the variable ENV{DEVTYPE} to be 'usb_device'; this is in fact explicitly stated in a comment in 50-udev.rules.  My fix to the nut rules is the following:

```

@@ -1,7 +1,10 @@

 # udev rules for the NUT USB drivers

 

-SUBSYSTEM!="usb_device", GOTO="nut-usbups_rules_end"

 ACTION!="add", GOTO="nut-usbups_rules_end"

+ENV{DEVTYPE}=="usb_device", GOTO="nut-usbups_rules_no-device-class"

+SUBSYSTEM!="usb_device", GOTO="nut-usbups_rules_end"

+

+LABEL="nut-usbups_rules_no-device-class"

 

 # MGE UPS SYSTEMS - usbhid-ups

 SYSFS{idVendor}=="0463", SYSFS{idProduct}=="ffff", MODE="664", GROUP="nut"

```

In English: proper matching will be performed if either ENV{DEVTYPE} is set to 'usb_device' (i.e. new kernel without CONFIG_USB_DEVICE_CLASS, or a coldplug event), or if SUBSYSTEM value is 'usb_device' (i.e. old kernel, or new kernel with CONFIG_USB_DEVICE_CLASS, in a hotplug event). I believe this is better than working around permissions in other ways, and solves the problem in a safe manner.

Question: how can this fix be incorporated into the appropriate Gentoo ebuild? (either nut or udev, whichever installs the nut rules...)

Many thanks, and hope this helps.

--Gilad

----------

## dstutz97

I don't know if you've already done this...but https://bugs.gentoo.org/ is where you want to go.  Just open a bug against nut.  I've had pretty good results myself with the devs fixing a couple problems with ebuilds for me.

Dave

----------

## gocantor

Hi Dave, thanks for the reply.

After posting here I went on and posted on the nut-dev mailing list. It appears that by this time a fix is already committed to the nut repository, so it should appear on the next release of nut. Let me know if you still think I should post a Gentoo-specific bug report.

Gilad

----------

