Solved Nut 2.8.0 - generic ups - blazer_usb - Can't claim USB device

Hi!
Today I connected a generic ups to a FreeBSD server (13.2-RELEASE-p4 FreeBSD 13.2-RELEASE-p4 GENERIC amd64)
The USB is detected but the service fails to start. I've checked the permission in /dev/usb and there a device using the nut group.

Code:
[freebsd:/usr/local/etc/devd $]> ls -al /dev/usb
total 2
dr-xr-xr-x   2 root  wheel       512 Oct 27 13:27 .
dr-xr-xr-x  14 root  wheel       512 Oct 27 10:27 ..
crw-------   1 root  operator   0x30 Oct 27 13:27 0.1.0
crw-------   1 root  operator   0x55 Oct 27 13:27 0.1.1
crw-------   1 root  operator   0x85 Oct 27 13:27 0.2.0
crw-------   1 root  operator   0x87 Oct 27 13:27 0.2.1
crw-rw----   1 root  nut       0x10a Oct 27 15:30 0.3.0
crw-------   1 root  operator  0x10c Oct 27 15:30 0.3.1

I unplugged and replugged the usb cable. dmesg -a:
Code:
ugen0.3: <vendor 0x0001 MEC0003> at usbus0 (disconnected)
uhid0: at uhub0, port 13, addr 2 (disconnected)
uhid0: detached
ugen0.3: <vendor 0x0001 MEC0003> at usbus0
uhid0 on uhub0
uhid0: <vendor 0x0001 MEC0003, class 0/0, rev 1.10/1.00, addr 3> on usbus0

When I try to start the nut service with service nut start I get the following error:
Code:
/usr/local/etc/rc.d/nut: WARNING: failed precmd routine for nut

Then I try to debug it (sudo /usr/local/libexec/nut/blazer_usb -a atomlux -DDDD) and I get:
Code:
[freebsd:/var/db $]> sudo /usr/local/libexec/nut/blazer_usb -a atomlux -DDDD
Password:
Network UPS Tools - Megatec/Q1 protocol USB driver 0.14 (2.8.0)
   0.000000     [D1] debug level is '4'
   0.000229     [D2] Checking device 1 of 1 (0001/0000)
   9.911004     [D1] nut_libusb_open get iManufacturer failed, retrying...
  19.808704     [D1] nut_libusb_open get iManufacturer failed, retrying...
  29.729264     [D1] nut_libusb_open get iManufacturer failed, retrying...
  29.731692     [D2] - VendorID: 0001
  29.731701     [D2] - ProductID: 0000
  29.731706     [D2] - Manufacturer: unknown
  29.731711     [D2] - Product: MEC0003
  29.731714     [D2] - Serial Number: unknown
  29.731718     [D2] - Bus: 000
  29.731722     [D2] - Device: unknown
  29.731725     [D2] - Device release number: 0100
  29.731729     [D2] Trying to match device
  29.731733     [D3] match_function_regex: matching a device...
  29.731738     [D2] Device matches
  29.731742     [D2] Reading first configuration descriptor
  29.731782     [D3] libusb_kernel_driver_active() returned 1 (driver active)
  29.731788     [D2] successfully set kernel driver auto-detach flag
  29.731797     [D2] failed to claim USB device: Other error
  29.731803     [D1] failed to detach kernel driver from USB device: Other error
  29.731808     [D2] failed to claim USB device: Other error
  29.731813     [D1] failed to detach kernel driver from USB device: Other error
  29.731818     [D2] failed to claim USB device: Other error
  29.731822     [D1] failed to detach kernel driver from USB device: Other error
  29.731827     [D2] failed to claim USB device: Other error
  29.731831     [D1] failed to detach kernel driver from USB device: Other error
  29.731839     Can't claim USB device [0001:0000]@0/0: Other error

The "atomlux" usb is defined in /usr/local/etc/ups.conf
Code:
[atomlux]
        driver = blazer_usb
        port = auto
        desc = "Atomlux 3500VA"
        default.battery.voltage.low = 10
        default.battery.voltage.high = 55.2
        runtimecal = 1200,100,2400,50

Any ideas?
 
I found this thread https://forum.opnsense.org/index.php?topic=28695.0 and detached the usb device with
Code:
usbconfig -d ugen0.3 detach_kernel_driver

##### log
Oct 27 17:52:27 freebsd kernel: uhid0: at uhub0, port 13, addr 3 (disconnected)
Oct 27 17:52:27 freebsd kernel: uhid0: detached
Oct 27 17:53:23 freebsd upsd[17534]: /usr/local/etc/nut/upsd.conf is world readable
Oct 27 17:53:23 freebsd upsd[17534]: /usr/local/etc/nut/upsd.users is world readable
Now the service starts. I will follow the steps mentioned in the link to add the values in bootloader.conf. Why might be the kernel not releasing the device?
 
Can you list uname -a, please?

Can you also provide a verbose usbconfig listing, please.

A quirk was added and MFCed to stable that avoids the kernel from considering some unknown until then UPS devices from being considered HID devices.
 
Can you list uname -a, please?

Can you also provide a verbose usbconfig listing, please.

A quirk was added and MFCed to stable that avoids the kernel from considering some unknown until then UPS devices from being considered HID devices.
Here you have:
Code:
[freebsd:~ $]> sudo usbconfig -v ; uname -a
ugen0.1: <Intel XHCI root HUB> at usbus0, cfg=0 md=HOST spd=SUPER (5.0Gbps) pwr=SAVE (0mA)
ugen0.1.0: uhub0: <Intel XHCI root HUB, class 9/0, rev 3.00/1.00, addr 1>

  bLength = 0x0012
  bDescriptorType = 0x0001
  bcdUSB = 0x0300
  bDeviceClass = 0x0009  <HUB>
  bDeviceSubClass = 0x0000
  bDeviceProtocol = 0x0003
  bMaxPacketSize0 = 0x0009
  idVendor = 0x0000
  idProduct = 0x0000
  bcdDevice = 0x0100
  iManufacturer = 0x0001  <Intel>
  iProduct = 0x0002  <XHCI root HUB>
  iSerialNumber = 0x0000  <no string>
  bNumConfigurations = 0x0001


 Configuration index 0

    bLength = 0x0009
    bDescriptorType = 0x0002
    wTotalLength = 0x001f
    bNumInterfaces = 0x0001
    bConfigurationValue = 0x0001
    iConfiguration = 0x0000  <no string>
    bmAttributes = 0x0040
    bMaxPower = 0x0000

    Interface 0
      bLength = 0x0009
      bDescriptorType = 0x0004
      bInterfaceNumber = 0x0000
      bAlternateSetting = 0x0000
      bNumEndpoints = 0x0001
      bInterfaceClass = 0x0009  <HUB>
      bInterfaceSubClass = 0x0000
      bInterfaceProtocol = 0x0000
      iInterface = 0x0000  <no string>

     Endpoint 0
        bLength = 0x0007
        bDescriptorType = 0x0005
        bEndpointAddress = 0x0081  <IN>
        bmAttributes = 0x0003  <INTERRUPT>
        wMaxPacketSize = 0x0002
        bInterval = 0x00ff
        bRefresh = 0x0000
        bSynchAddress = 0x0000

      Additional Descriptor

      bLength = 0x06
      bDescriptorType = 0x30
      bDescriptorSubType = 0x00
       RAW dump:
       0x00 | 0x06, 0x30, 0x00, 0x00, 0x00, 0x00




ugen0.2: <no manufacturer Gadget USB HUB> at usbus0, cfg=0 md=HOST spd=HIGH (480Mbps) pwr=SAVE (100mA)
ugen0.2.0: uhub1: <no manufacturer Gadget USB HUB, class 9/0, rev 2.00/0.00, addr 1>

  bLength = 0x0012
  bDescriptorType = 0x0001
  bcdUSB = 0x0200
  bDeviceClass = 0x0009  <HUB>
  bDeviceSubClass = 0x0000
  bDeviceProtocol = 0x0000
  bMaxPacketSize0 = 0x0040
  idVendor = 0x413c
  idProduct = 0xa001
  bcdDevice = 0x0000
  iManufacturer = 0x0001  <no manufacturer>
  iProduct = 0x0002  <Gadget USB HUB>
  iSerialNumber = 0x0003  <0123456789>
  bNumConfigurations = 0x0001


 Configuration index 0

    bLength = 0x0009
    bDescriptorType = 0x0002
    wTotalLength = 0x0019
    bNumInterfaces = 0x0001
    bConfigurationValue = 0x0001
    iConfiguration = 0x0000  <no string>
    bmAttributes = 0x00e0
    bMaxPower = 0x0032

    Interface 0
      bLength = 0x0009
      bDescriptorType = 0x0004
      bInterfaceNumber = 0x0000
      bAlternateSetting = 0x0000
      bNumEndpoints = 0x0001
      bInterfaceClass = 0x0009  <HUB>
      bInterfaceSubClass = 0x0000
      bInterfaceProtocol = 0x0000
      iInterface = 0x0000  <no string>

     Endpoint 0
        bLength = 0x0007
        bDescriptorType = 0x0005
        bEndpointAddress = 0x0081  <IN>
        bmAttributes = 0x0003  <INTERRUPT>
        wMaxPacketSize = 0x0001
        bInterval = 0x000c
        bRefresh = 0x0000
        bSynchAddress = 0x0000



ugen0.3: <vendor 0x0001 MEC0003> at usbus0, cfg=0 md=HOST spd=LOW (1.5Mbps) pwr=ON (100mA)

  bLength = 0x0012
  bDescriptorType = 0x0001
  bcdUSB = 0x0110
  bDeviceClass = 0x0000  <Probed by interface class>
  bDeviceSubClass = 0x0000
  bDeviceProtocol = 0x0000
  bMaxPacketSize0 = 0x0008
  idVendor = 0x0001
  idProduct = 0x0000
  bcdDevice = 0x0100
  iManufacturer = 0x0001  <retrieving string failed>
  iProduct = 0x0002  <MEC0003>
  iSerialNumber = 0x0000  <no string>
  bNumConfigurations = 0x0001


 Configuration index 0

    bLength = 0x0009
    bDescriptorType = 0x0002
    wTotalLength = 0x0022
    bNumInterfaces = 0x0001
    bConfigurationValue = 0x0001
    iConfiguration = 0x0000  <no string>
    bmAttributes = 0x0080
    bMaxPower = 0x0032

    Interface 0
      bLength = 0x0009
      bDescriptorType = 0x0004
      bInterfaceNumber = 0x0000
      bAlternateSetting = 0x0000
      bNumEndpoints = 0x0001
      bInterfaceClass = 0x0003  <HID device>
      bInterfaceSubClass = 0x0000
      bInterfaceProtocol = 0x0000
      iInterface = 0x0000  <no string>

      Additional Descriptor

      bLength = 0x09
      bDescriptorType = 0x21
      bDescriptorSubType = 0x00
       RAW dump:
       0x00 | 0x09, 0x21, 0x00, 0x01, 0x00, 0x01, 0x22, 0x70,
       0x08 | 0x02

     Endpoint 0
        bLength = 0x0007
        bDescriptorType = 0x0005
        bEndpointAddress = 0x0081  <IN>
        bmAttributes = 0x0003  <INTERRUPT>
        wMaxPacketSize = 0x0008
        bInterval = 0x000a
        bRefresh = 0x0000
        bSynchAddress = 0x0000



FreeBSD freebsd.mydomain.local 13.2-RELEASE-p4 FreeBSD 13.2-RELEASE-p4 GENERIC amd64
/CODE]
 
Your MEC0003 is passing bad identifier data:

idVendor = 0x0001
idProduct = 0x0000

This is invalid.

If your UPS is like mine, it will connect and disconnect from the USB bus every five seconds (until something, like the nut USB driver, opens it for I/O). You may be able to retrieve correct data from it by reissuing usbconfig a few times. If you don't see any difference in outputs, your UPS is likely unable to be identified by probing it.

You should see something like the data your Gadget USB HUB is returning.

FreeBSD identifies USB devices by their vendor ID plus product ID.
 
Your MEC0003 is passing bad identifier data:

idVendor = 0x0001
idProduct = 0x0000

This is invalid.

If your UPS is like mine, it will connect and disconnect from the USB bus every five seconds (until something, like the nut USB driver, opens it for I/O). You may be able to retrieve correct data from it by reissuing usbconfig a few times. If you don't see any difference in outputs, your UPS is likely unable to be identified by probing it.

You should see something like the data your Gadget USB HUB is returning.

FreeBSD identifies USB devices by their vendor ID plus product ID.
I connected an APC UPS and now I get this messages, almost sure theres a problem with the USB cable however are these the errors you mentiones above about the disconnect? These aren't every 5 seconds.
Code:
Oct 31 11:36:48 freebsd kernel: ugen0.4: <American Power Conversion Smart-UPS 1000 XL FW:681.18.I USB FW:11.03> at usbus0
Oct 31 11:36:49 freebsd kernel: ugen0.4: <American Power Conversion Smart-UPS 1000 XL FW:681.18.I USB FW:11.03> at usbus0 (disconnected)
Oct 31 11:37:19 freebsd kernel: ugen0.4: <American Power Conversion Smart-UPS 1000 XL FW:681.18.I USB FW:11.03> at usbus0
Oct 31 11:37:20 freebsd kernel: ugen0.4: <American Power Conversion Smart-UPS 1000 XL FW:681.18.I USB FW:11.03> at usbus0 (disconnected)
Oct 31 12:32:32 freebsd kernel: ugen0.4: <American Power Conversion Smart-UPS 1000 XL FW:681.18.I USB FW:11.03> at usbus0
Oct 31 12:32:32 freebsd kernel: ugen0.4: <American Power Conversion Smart-UPS 1000 XL FW:681.18.I USB FW:11.03> at usbus0 (disconnected)
Oct 31 12:32:33 freebsd kernel: uhub_reattach_port: giving up port 10 reset - device vanished: change 0x1 status 0x6a0
Oct 31 12:32:34 freebsd kernel: ugen0.4: <American Power Conversion Smart-UPS 1000 XL FW:681.18.I USB FW:11.03> at usbus0
Oct 31 12:33:00 freebsd kernel: ugen0.4: <American Power Conversion Smart-UPS 1000 XL FW:681.18.I USB FW:11.03> at usbus0 (disconnected)
 
Your APC UPS is doing the same thing my CPS is. It connects/disconnects every five seconds. Nut handles this nicely (most of the time).

Replace the cable if you suspect it's faulty.

I added an ignore quirk for APC Smart-UPS1000 in February of this year. Ignore quirks avoid the kernel attaching it to a HID (Human Interface Driver - like a mouse or keyboard). It was MFCed a week later and would be in any 12/13-RELEASE that was released after that time. Sadly 13.2-RELEASE was released before my commit made it to HEAD (and obviously before it made it to stable/13).

Attached is the patch to force the kernel to ignore considering your APC UPS1000 an HID. Apply the patch and rebuild and reinstall your kernel. If you cannot do this you will need to wait for 13.3-RELEASE or 14.0-RELEASE.
 

Attachments

  • APC-UPS1000.diff.txt
    1.9 KB · Views: 58
Your APC UPS is doing the same thing my CPS is. It connects/disconnects every five seconds. Nut handles this nicely (most of the time).

Replace the cable if you suspect it's faulty.

I added an ignore quirk for APC Smart-UPS1000 in February of this year. Ignore quirks avoid the kernel attaching it to a HID (Human Interface Driver - like a mouse or keyboard). It was MFCed a week later and would be in any 12/13-RELEASE that was released after that time. Sadly 13.2-RELEASE was released before my commit made it to HEAD (and obviously before it made it to stable/13).

Attached is the patch to force the kernel to ignore considering your APC UPS1000 an HID. Apply the patch and rebuild and reinstall your kernel. If you cannot do this you will need to wait for 13.3-RELEASE or 14.0-RELEASE.
It was the cable the problem of the APC UPS. Right now I've both upss connected and running. I'm dealing with nut_upslog handling multiple log files via de -m flag.

I will set this thread as solved.
 
  • Like
Reactions: cy@
Back
Top