Skip to content

Fix common USB matching options for riello_usb (richcomm and nutdrv_atcl too, but reverted)#1763

Merged
jimklimov merged 5 commits intonetworkupstools:masterfrom
jimklimov:issue-1754-riello-device
Jan 4, 2023
Merged

Fix common USB matching options for riello_usb (richcomm and nutdrv_atcl too, but reverted)#1763
jimklimov merged 5 commits intonetworkupstools:masterfrom
jimklimov:issue-1754-riello-device

Conversation

@jimklimov
Copy link
Member

@jimklimov jimklimov commented Jan 4, 2023

Should fix (or at least provide a way for possible fix) #1754 and #1744 among other issues. This might not completely remove the need for #1756 but should alleviate the problem of monitoring multiple related devices of certain vendors/protocols where we can individually discern them by device/bus/serial fields.

Thanks to @shgubar for convincing me that the bug is there (many drivers solved it long ago), and to trace the code with more attention.

Note: "bcmxcp_usb" driver suffers a similar problem but was not easy to fix in a similar fashion (conflicts with symbols in the built LIBUSB_IMPL of the day, and impacts nut-scanner build per different dependency chain), so attempt to fix it along with others was shelved.

A side note from debugging: the regex-matching in usb-common.c is not logged in full detail because array elements are not interactively useful (precompiled regexes, not original strings).

@jimklimov jimklimov added bug USB Riello Riello UPS devices (serial, usb), usually with a variant of Qx protocol labels Jan 4, 2023
@jimklimov jimklimov added this to the 2.8.1 milestone Jan 4, 2023
@jimklimov jimklimov requested a review from aquette January 4, 2023 02:15
@jimklimov jimklimov merged commit 9a7138c into networkupstools:master Jan 4, 2023
@jimklimov jimklimov deleted the issue-1754-riello-device branch January 4, 2023 08:47
@jimklimov jimklimov added the USB-duplicate-devices Track bugs and issues about monitoring several devices that seem identical to NUT or libusb label Jan 4, 2023
jimklimov added a commit to jimklimov/nut that referenced this pull request Jan 4, 2023
@jimklimov
Copy link
Member Author

jimklimov commented Jan 4, 2023

UPDATE: Reverted the change to nutdrv_atcl_usb in #1766 since it uses a custom tailored matcher method.

And for richcomm, see why below (desired fix is now tracked in #1768).

@jimklimov
Copy link
Member Author

jimklimov commented Jan 4, 2023

"Screenshots":

  • De-facto these variables are consulted in the following driver sources:
# git grep 'getval("device")'
drivers/blazer_usb.c:   regex_array[6] = getval("device");
drivers/nutdrv_qx.c:            regex_array[6] = getval("device");
drivers/riello_usb.c:   regex_array[6] = getval("device");
drivers/tripplite_usb.c:        regex_array[6] = getval("device");
drivers/usbhid-ups.c:   regex_array[6] = getval("device");
# NUT_STATEPATH=/tmp ./drivers/riello_usb -s test -DDDDDD -x port=auto -x device=000 -x vendorid=0463 -u nut
Network UPS Tools - Riello USB driver 0.08 (2.8.0-Windows-259-ge23192718)
Warning: This is an experimental driver.
Some features may not function correctly.

   0.000000     [D3] main_arg: var='port' val='auto'
   0.000012     [D5] send_to_all: SETINFO driver.parameter.port "auto"
   0.000015     [D3] main_arg: var='device' val='000'
   0.000019     [D5] send_to_all: SETINFO driver.parameter.device "000"
...
   0.003605     [D2] Checking device 4 of 9 (1D6B/0003)
   0.003610     [D1] Failed to open device (1D6B/0003), skipping: Access denied (insufficient permissions)
   0.003613     [D2] Checking device 5 of 9 (0463/FFFF)
   0.426708     [D2] - VendorID: 0463
   0.426721     [D2] - ProductID: ffff
   0.426724     [D2] - Manufacturer: EATON
   0.426726     [D2] - Product: Ellipse ECO
   0.426732     [D2] - Serial Number: 000000000
   0.426734     [D2] - Bus: 003
   0.426737     [D2] - Device: unknown
   0.426739     [D2] - Device release number: 0100
   0.426742     [D2] Trying to match device
   0.426745     [D3] match_function_regex: matching a device...
   0.426781     [D2] match_function_regex: failed match of Device: (null)
   0.426784     [D2] Device does not match - skipping
...
   0.426832     [D2] libusb1: No appropriate HID device found
   0.426835     libusb1: Could not open any HID devices: insufficient permissions on everything
   0.426838     No supported devices found. Please check your device availability with 'lsusb'
and make sure you have an up-to-date version of NUT. If this does not help,
try running the driver with at least 'subdriver', 'vendorid' and 'productid'
options specified. Please refer to the man page for details about these options
(man 8 riello_usb).
  • Same experiment, but with a wrong bus number:
# NUT_STATEPATH=/tmp ./drivers/riello_usb -s test -DDDDDD -x port=auto -x bus=000 -x vendorid=0463 -u nut
...
   0.005062     [D2] Checking device 5 of 9 (0463/FFFF)
   0.423977     [D2] - VendorID: 0463
   0.423995     [D2] - ProductID: ffff
   0.424002     [D2] - Manufacturer: EATON
   0.424009     [D2] - Product: Ellipse ECO
   0.424017     [D2] - Serial Number: 000000000
   0.424024     [D2] - Bus: 003
   0.424030     [D2] - Device: unknown
   0.424034     [D2] - Device release number: 0100
   0.424038     [D2] Trying to match device
   0.424041     [D3] match_function_regex: matching a device...
   0.424088     [D2] match_function_regex: failed match of Bus: 003
   0.424092     [D2] Device does not match - skipping
...

@jimklimov
Copy link
Member Author

Trying same with richcomm looked worse, especially at the end:

# NUT_STATEPATH=/tmp ./drivers/richcomm_usb -s test -DDDDDD -x port=auto -x bus=000 -x vendorid=0463 -u nut
Network UPS Tools - Richcomm dry-contact to USB driver 0.11 (2.8.0-Windows-259-ge23192718)
Warning: This is an experimental driver.
Some features may not function correctly.

   0.000000     [D3] main_arg: var='port' val='auto'
   0.000030     [D5] send_to_all: SETINFO driver.parameter.port "auto"
   0.000038     [D3] main_arg: var='bus' val='000'
   0.000048     [D5] send_to_all: SETINFO driver.parameter.bus "000"
   0.000055     [D3] main_arg: var='vendorid' val='0463'
   0.000065     [D5] send_to_all: SETINFO driver.parameter.vendorid "0463"
   0.000072     [D1] Built-in default or configured user for drivers 'nobody' was ignored due to 'nut' specified on command line
   0.000081     [D1] debug level is '6'
   0.000716     [D1] Succeeded to become_user(nut): now UID=77 GID=77
   0.000737     [D5] send_to_all: SETINFO device.type "ups"
   0.003895     [D4] Failed to open USB device, skipping: Access denied (insufficient permissions)
   0.003910     [D4] Failed to open USB device, skipping: Access denied (insufficient permissions)
   0.003922     [D4] Failed to open USB device, skipping: Access denied (insufficient permissions)
   0.003936     [D4] Failed to open USB device, skipping: Access denied (insufficient permissions)
   0.425563     [D4] - VendorID     : 0463
   0.425574     [D4] - ProductID    : ffff
   0.425577     [D4] - Manufacturer : EATON
   0.425579     [D4] - Product      : Ellipse ECO
   0.425582     [D4] - Serial Number: 000000000
   0.425584     [D4] - Bus          : 003
   0.425587     [D4] Device does not match - skipping
   0.425619     [D4] - VendorID     : 1d6b
   0.425626     [D4] - ProductID    : 0002
   0.425632     [D4] - Manufacturer : unknown
   0.425637     [D4] - Product      : unknown
   0.425643     [D4] - Serial Number: unknown
   0.425649     [D4] - Bus          : 003
   0.425655     [D4] Device does not match - skipping
Segmentation fault

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Riello Riello UPS devices (serial, usb), usually with a variant of Qx protocol USB USB-duplicate-devices Track bugs and issues about monitoring several devices that seem identical to NUT or libusb

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant