Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enhance USB device and subdriver matching in usbhid-ups to be on par with nutdrv_qx #2058

Merged
merged 16 commits into from
Sep 19, 2023

Conversation

jimklimov
Copy link
Member

@jimklimov jimklimov commented Sep 17, 2023

Closes: #1369

By side effect, moves detection of libregex build parameters (if any are needed) into a separate m4 script, and creates automake and C macros to shield about their presence. Generic regex helper methods (not intimate to USB) moved to common.c/h. Also, found that clients/* were built by default with libcommon.la (not libcommonclient.la) and pulled extra dependencies like -lsystemd that (most of) the clients should not care about - also addressed.

Example testing outcome: this change allows poking an Eaton device with a "not-its" (Tripplite) subdriver, even getting a bit of info as seen below.

Unlike nutdrv_qx, for the iteration shown below I did not constrain this feature to require at least a specified vendorid and productid in configuration, but makes sense to add it. As seen in the "screenshot", the driver opened the first device it had FS-level permission to access.

# Full built-in name:
:; ./drivers/usbhid-ups -DD -s test -x port=auto -x subdriver='TrippLite HID 0.85' -d1
...
   0.002171     [D2] Checking device 4 of 9 (1D6B/0003)
   0.002175     [D1] Failed to open device (1D6B/0003), skipping: Access denied (insufficient permissions)
   0.002177     [D2] Checking device 5 of 9 (0463/FFFF)
   0.424708     [D2] - VendorID: 0463
   0.424724     [D2] - ProductID: ffff
   0.424730     [D2] - Manufacturer: EATON
   0.424734     [D2] - Product: Ellipse ECO
   0.424739     [D2] - Serial Number: 000000000
   0.424750     [D2] - Bus: 003
   0.424756     [D2] - Bus Port: 002
   0.424761     [D2] - Device: 007
   0.424764     [D2] - Device release number: 0100
   0.424768     [D2] Trying to match device
   0.424773     [D2] match_function_subdriver_name: matching a subdriver by explicit name/regex: 'TrippLite HID 0.85'...
   0.424779     [D2] match_function_subdriver_name: found a match: TrippLite HID 0.85
   0.424783     [D2] Device matches
   0.424787     [D2] Reading first configuration descriptor
   0.424810     [D2] Claimed interface 0 successfully
...

Similarly by substring regex which is a more likely use-case:

:; ./drivers/usbhid-ups -DD -s test -x port=auto -x subdriver='tripplite' -d1
...
   0.003256     [D2] Checking device 4 of 9 (1D6B/0003)
   0.003261     [D1] Failed to open device (1D6B/0003), skipping: Access denied (insufficient permissions)
   0.003264     [D2] Checking device 5 of 9 (0463/FFFF)
   0.424078     [D2] - VendorID: 0463
   0.424092     [D2] - ProductID: ffff
   0.424097     [D2] - Manufacturer: EATON
   0.424100     [D2] - Product: Ellipse ECO
   0.424103     [D2] - Serial Number: 000000000
   0.424107     [D2] - Bus: 003
   0.424111     [D2] - Bus Port: 002
   0.424115     [D2] - Device: 007
   0.424119     [D2] - Device release number: 0100
   0.424122     [D2] Trying to match device
   0.424127     [D2] match_function_subdriver_name: matching a subdriver by explicit name/regex: 'tripplite'...
   0.424138     [D2] match_function_subdriver_name: retry matching by regex 'as is'
   0.424228     [D2] match_function_subdriver_name: retry matching by regex with added '.*'
   0.424259     [D2] match_function_subdriver_name: found a match: TrippLite HID 0.85
   0.424263     [D2] Device matches
   0.424266     [D2] Reading first configuration descriptor
   0.424302     [D2] Claimed interface 0 successfully
   0.491079     [D2] Retrieved HID descriptor (expected 9, got 9)
   0.491091     [D2] HID descriptor length 909
   3.661073     [D2] Report Descriptor size = 909
   3.661117     [D2] match_function_subdriver_name: matching a subdriver by explicit name/regex: 'tripplite'...
   3.661122     [D2] match_function_subdriver_name: retry matching by regex 'as is'
   3.661156     [D2] match_function_subdriver_name: retry matching by regex with added '.*'
   3.661170     [D2] match_function_subdriver_name: found a match: TrippLite HID 0.85
   3.661172     Using subdriver: TrippLite HID 0.85
   3.661175     [D1] 94 HID objects found
   3.703060     [D1] Path: UPS.BatterySystem.Battery.AudibleAlarmControl, Type: Feature, ReportID: 0x20, Offset: 0, Size: 8, Value: 1
...
   6.551087     [D1] upsdrv_updateinfo...
   7.301215     [D2] nut_libusb_get_interrupt: Connection timed out
   7.301236     [D1] Got 0 HID objects...
   7.301245     [D1] Quick update...
   7.301255     [D2] Path: UPS.PowerSummary.PresentStatus.ACPresent, Type: Feature, ReportID: 0x01, Offset: 0, Size: 1, Value: 1
   7.301262     [D2] Path: UPS.PowerSummary.PresentStatus.BelowRemainingCapacityLimit, Type: Feature, ReportID: 0x01, Offset: 1, Size: 1, Value: 0
   7.301270     [D2] Path: UPS.PowerSummary.PresentStatus.Charging, Type: Feature, ReportID: 0x01, Offset: 2, Size: 1, Value: 1
   7.301279     [D2] Path: UPS.PowerSummary.PresentStatus.Discharging, Type: Feature, ReportID: 0x01, Offset: 4, Size: 1, Value: 0
battery.charge: 100
battery.charge.low: 20
battery.runtime: 1312
battery.type: PbAc
device.mfr: EATON
device.model: Ellipse ECO
device.serial: 000000000
device.type: ups
driver.debug: 2
driver.flag.allow_killpower: 0
driver.name: usbhid-ups
driver.parameter.pollfreq: 30
driver.parameter.pollinterval: 2
driver.parameter.port: auto
driver.parameter.subdriver: tripplite
driver.parameter.synchronous: auto
driver.state: dumping
driver.version: 2.8.0-2497-gc83ad2e3f
driver.version.data: TrippLite HID 0.85
driver.version.internal: 0.52
driver.version.usb: libusb-1.0.24 (API: 0x1000108)
input.transfer.high: 264.0
input.transfer.low: 161.0
output.voltage: 230.0
ups.beeper.status: enabled
ups.mfr: EATON
ups.model: Ellipse ECO
ups.productid: ffff
ups.serial: 000000000
ups.status: OL CHRG
ups.vendorid: 0463
   7.301370     [D1] upsdrv_cleanup...

Example of standard matching options still being honoured (using locally-absent vendorid):

# ./drivers/usbhid-ups -DDD -s test -x port=auto -x subdriver='tripplite' -d1 -x vendorid=1234
Network UPS Tools - Generic HID driver 0.52 (2.8.0-2497-gc83ad2e3f)
USB communication driver (libusb 1.0) 0.46
   0.000000     [D3] main_arg: var='port' val='auto'
   0.000012     [D3] main_arg: var='subdriver' val='tripplite'
   0.000020     [D3] main_arg: var='vendorid' val='1234'
   0.000027     [D1] Network UPS Tools version 2.8.0-2497-gc83ad2e3f (release/snapshot of 2.8.0.1) built with gcc (Debian 10.2.1-6) 10.2.1 20210110 and configured with flags: --with-user=nut --with-group=nut --with-all --with-docs=man --sysconfdir=/etc/nut --enable-silent-rules
   0.000033     [D1] debug level is '3'
   0.000618     [D1] Succeeded to become_user(nut): now UID=77 GID=77
   0.000631     [D1] upsdrv_initups (non-SHUT)...
   0.000635     [D2] Initializing an USB-connected UPS with library libusb-1.0.24 (API: 0x1000108) (NUT subdriver name='USB communication driver (libusb 1.0)' ver='0.46')
   0.004118     [D2] Checking device 1 of 9 (1D6B/0003)
   0.004140     [D1] Failed to open device (1D6B/0003), skipping: Access denied (insufficient permissions)
   0.004145     [D2] Checking device 2 of 9 (03F0/0D4A)
   0.004152     [D1] Failed to open device (03F0/0D4A), skipping: Access denied (insufficient permissions)
   0.004156     [D2] Checking device 3 of 9 (1D6B/0002)
   0.004162     [D1] Failed to open device (1D6B/0002), skipping: Access denied (insufficient permissions)
   0.004165     [D2] Checking device 4 of 9 (1D6B/0003)
   0.004171     [D1] Failed to open device (1D6B/0003), skipping: Access denied (insufficient permissions)
   0.004174     [D2] Checking device 5 of 9 (0463/FFFF)
   0.428129     [D2] - VendorID: 0463
   0.428143     [D2] - ProductID: ffff
   0.428148     [D2] - Manufacturer: EATON
   0.428154     [D2] - Product: Ellipse ECO
   0.428161     [D2] - Serial Number: 000000000
   0.428165     [D2] - Bus: 003
   0.428168     [D2] - Bus Port: 002
   0.428171     [D2] - Device: 007
   0.428175     [D2] - Device release number: 0100
   0.428178     [D2] Trying to match device
   0.428183     [D2] match_function_subdriver_name: matching a subdriver by explicit name/regex: 'tripplite'...
   0.428194     [D2] match_function_subdriver_name: retry matching by regex 'as is'
   0.428253     [D2] match_function_subdriver_name: retry matching by regex with added '.*'
   0.428285     [D2] match_function_subdriver_name: found a match: TrippLite HID 0.85
   0.428289     [D3] match_function_regex: matching a device...
   0.428293     [D2] match_function_regex: failed match of VendorID:  463
   0.428297     [D2] Device does not match - skipping
   0.428308     [D2] Checking device 6 of 9 (1D6B/0002)
   0.428322     [D1] Failed to open device (1D6B/0002), skipping: Access denied (insufficient permissions)
   0.428325     [D2] Checking device 7 of 9 (1D6B/0003)
   0.428332     [D1] Failed to open device (1D6B/0003), skipping: Access denied (insufficient permissions)
   0.428336     [D2] Checking device 8 of 9 (048D/5702)
   0.428342     [D1] Failed to open device (048D/5702), skipping: Access denied (insufficient permissions)
   0.428345     [D2] Checking device 9 of 9 (1D6B/0002)
   0.428351     [D1] Failed to open device (1D6B/0002), skipping: Access denied (insufficient permissions)
   0.428356     [D2] libusb1: No appropriate HID device found
   0.428361     libusb1: Could not open any HID devices: insufficient permissions on everything
   0.428365     No matching HID UPS found

Also fixes some issues with nut-scanner reporting of suspect serial numbers, and quiesces some warnings for new clang versions (which we can't do much about in practice => CC #823 "fightwarn" effort).

@jimklimov jimklimov added this to the 2.8.1 milestone Sep 17, 2023
@jimklimov
Copy link
Member Author

With the requirement of IDs added, it behaves like this:

:; ./drivers/usbhid-ups -DDD -s test -x port=auto -x subdriver='tripplite' -d1 -x vendorid=1234
Network UPS Tools - Generic HID driver 0.52 (2.8.0-2498-g05b522ebd)
USB communication driver (libusb 1.0) 0.46
   0.000000     [D3] main_arg: var='port' val='auto'
   0.000014     [D3] main_arg: var='subdriver' val='tripplite'
   0.000027     [D3] main_arg: var='vendorid' val='1234'
   0.000034     [D1] Network UPS Tools version 2.8.0-2498-g05b522ebd (release/snapshot of 2.8.0.1) built with gcc (Debian 10.2.1-6) 10.2.1 20210110 and configured with flags: --with-user=nut --with-group=nut --with-all --with-docs=man --sysconfdir=/etc/nut --enable-silent-rules
   0.000040     [D1] debug level is '3'
   0.000723     [D1] Succeeded to become_user(nut): now UID=77 GID=77
   0.000760     [D1] upsdrv_initups (non-SHUT)...
   0.000768     [D2] Initializing an USB-connected UPS with library libusb-1.0.24 (API: 0x1000108) (NUT subdriver name='USB communication driver (libusb 1.0)' ver='0.46')
   0.004320     [D2] Checking device 1 of 9 (1D6B/0003)
   0.004339     [D1] Failed to open device (1D6B/0003), skipping: Access denied (insufficient permissions)
   0.004344     [D2] Checking device 2 of 9 (03F0/0D4A)
   0.004352     [D1] Failed to open device (03F0/0D4A), skipping: Access denied (insufficient permissions)
   0.004356     [D2] Checking device 3 of 9 (1D6B/0002)
   0.004362     [D1] Failed to open device (1D6B/0002), skipping: Access denied (insufficient permissions)
   0.004366     [D2] Checking device 4 of 9 (1D6B/0003)
   0.004372     [D1] Failed to open device (1D6B/0003), skipping: Access denied (insufficient permissions)
   0.004375     [D2] Checking device 5 of 9 (0463/FFFF)
   0.426457     [D2] - VendorID: 0463
   0.426470     [D2] - ProductID: ffff
   0.426475     [D2] - Manufacturer: EATON
   0.426479     [D2] - Product: Ellipse ECO
   0.426483     [D2] - Serial Number: 000000000
   0.426487     [D2] - Bus: 003
   0.426490     [D2] - Bus Port: 002
   0.426494     [D2] - Device: 007
   0.426498     [D2] - Device release number: 0100
   0.426501     [D2] Trying to match device
   0.426538     [D2] match_function_subdriver_name: matching a subdriver by explicit name/regex: 'tripplite'...
   0.426568     [D2] match_function_subdriver_name: retry matching by regex 'as is'
   0.426628     [D2] match_function_subdriver_name: retry matching by regex with added '.*'
   0.426655     [D2] match_function_subdriver_name: found a match: TrippLite HID 0.85
   0.426659     When specifying a subdriver, 'vendorid' and 'productid' are mandatory.

Subdriver confirmed matched (exists), but then aborts due to lack of both VID and PID (only one is given) before even checking them.

@jimklimov jimklimov added nut-scanner CI Entries related to continuous integration infrastructure (historically also recipes like Makefiles) portability We want NUT to build and run everywhere possible labels Sep 18, 2023
jimklimov and others added 16 commits September 18, 2023 22:11
… adapt configure.ac and */Makefile.am accordingly

Signed-off-by: Jim Klimov <jimklimov+nut@gmail.com>
…-common.{c,h} [networkupstools#1369]

Signed-off-by: Jim Klimov <jimklimov+nut@gmail.com>
…link and run-time deps pulled), not libcommon.la

Signed-off-by: Jim Klimov <jimklimov+nut@gmail.com>
…subdriver" matching option; update docs about it [networkupstools#1369]

Signed-off-by: Jim Klimov <jimklimov+nut@gmail.com>
…f regex "somename.*" [networkupstools#1369]

Signed-off-by: Jim Klimov <jimklimov+nut@gmail.com>
…e of found USB HID subdriver [networkupstools#1369]

Signed-off-by: Jim Klimov <jimklimov+nut@gmail.com>
…commend) vendorid/productid [networkupstools#1369]

Signed-off-by: Jim Klimov <jimklimov+nut@gmail.com>
…arnings that we can not really address [networkupstools#2055, networkupstools#823]

Signed-off-by: Jim Klimov <jimklimov@gmail.com>
… numbers

Signed-off-by: Jim Klimov <jimklimov@gmail.com>
…(non-NULL) report, let all complaints be known

Signed-off-by: Jim Klimov <jimklimov@gmail.com>
…ifferent devices"

Signed-off-by: Jim Klimov <jimklimov@gmail.com>
Steamline use of LIBREGEX_CFLAGS via AM_CFLAGS, same as others.

Signed-off-by: Jim Klimov <jimklimov+nut@gmail.com>
…rary name, when checking for -lregex

Signed-off-by: Jim Klimov <jimklimov+nut@gmail.com>
…s about subdriver settings [networkupstools#1369]

Signed-off-by: Jim Klimov <jimklimov+nut@gmail.com>
…ver" setting values in command-line usage request (--help) [networkupstools#1369]

Signed-off-by: Jim Klimov <jimklimov+nut@gmail.com>
…" setting values in command-line usage request (--help) [networkupstools#1369]

Signed-off-by: Jim Klimov <jimklimov+nut@gmail.com>
@jimklimov jimklimov added documentation Qx protocol driver Driver based on Megatec Q<number> such as new nutdrv_qx, or obsoleted blazer and some others labels Sep 18, 2023
@jimklimov jimklimov merged commit 5a2f719 into networkupstools:master Sep 19, 2023
45 of 48 checks passed
@jimklimov jimklimov deleted the issue-1369 branch September 19, 2023 06:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CI Entries related to continuous integration infrastructure (historically also recipes like Makefiles) documentation enhancement nut-scanner portability We want NUT to build and run everywhere possible Qx protocol driver Driver based on Megatec Q<number> such as new nutdrv_qx, or obsoleted blazer and some others USB
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Enhance USB device and subdriver matching in usbhid-ups to be on par with nutdrv_qx
1 participant