-
-
Notifications
You must be signed in to change notification settings - Fork 350
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
drivers/libusb{0,1}.c: reset driver parameters while enumerating #2611
drivers/libusb{0,1}.c: reset driver parameters while enumerating #2611
Conversation
Hey, so per the commit date I've been sitting on this one for a while. I saw that a new parameter was added in e1fc248 and so modified the new function to set that back to the default as well. I also saw 66c4e10 was added in the interim; I think this should still play nicely with it. Some background, here is what happens without the patch with an Arduino Leonardo compatible board attached along with the CyberPower UPS (
And with the patch, things enumerate as expected:
|
0d53e8d
to
8ee298d
Compare
Eh, looking more closely at 66c4e10 I think I might need to now change this slightly to avoid stepping on user-defined values. I could copy the values after they're parsed e.g. after
|
What about wrapping each assignment back to defaults with
|
Sounds right, thanks! Note there's also some USB work brewing in PR #2604, including some (static) method renaming into a common style with Also, would be consistent to have a similar fix in libusb0.c (if applicable), in case some platforms would require to use it as long as we ship it. And a |
(This should probably be discussed in a Discussion item, sorry for hi-jacking) EDIT: |
Something to think of (after merging this) is to rename nut's LIBUSB_* macros. "LIBUSB_" is kind of libusb's own namespace, so by including "libusb.h" there will be various LIBUSB_* macros defined there. The nut macros could be renamed to e.g. NUT_LIBUSB_* to avoid any future trouble. |
One of these recent USB discussions (can't find quickly via phone) also asked how much data is shared and in what scope - I guess global vars were picked by those before us as a sufficiently little evil for the model that every driver process is independent, even when copies of the same driver are used for different attached devices, or even same device (e.g. SNMP UPS watched via different MIBs). |
@tofurky : I was wondering if we can |
8ee298d
to
93e0b39
Compare
I just tested/pushed the change to call |
057ee77
to
4ecac8e
Compare
I added a note to NEWS.adoc; I think it mostly captures the gist of the what and why for this change. I will look into building against libusb0. Presently I'm just plopping the |
I've rebuiilt against libusb0 (with no changes to libusb0.c) and I'm not seeing the issue:
Running with |
With an Arduino Leonardo compatible board attached alongside a CyberPower CP1500PFCLCD, usbhid-ups would incorrectly conclude that there was no kernel driver attached to the UPS and then fail subsequent steps accordingly. The cause is the global usb_communication_subdriver_t struct; when a subdriver (e.g. arduino-hid) sets different values during the enumeration loop, they're not set back to defaults afterwards, causing issues with other subdrivers (e.g. cps-hid). So, if a subdriver doesn't match, set a selection of fields back to their default values using the newly added nut_usb_subdriver_defaults() before the next attempt. Signed-off-by: Matt Merhar <[email protected]>
401599a
to
fc7ffa7
Compare
I rebased on master and force-pushed an identical change to libusb0.c. This was compile and runtime tested, but not confirmed to fix the issue since I can't repro. I intentionally set a wrong
|
With an Arduino Leonardo compatible board attached alongside a CyberPower CP1500PFCLCD, usbhid-ups would incorrectly conclude that there was no kernel driver attached to the UPS and then fail subsequent steps accordingly. The cause is the global usb_communication_subdriver_t struct; when a subdriver (e.g. arduino-hid) sets different values during the enumeration loop, they're not set back to defaults afterwards, causing issues with other subdrivers (e.g. cps-hid). So, if a subdriver doesn't match, set a selection of fields back to their default values using the newly added nut_usb_subdriver_defaults() before the next attempt. // tofurky Signed-off-by: Jim Klimov <[email protected]>
…on style [networkupstools#2611] Signed-off-by: Jim Klimov <[email protected]>
With an Arduino Leonardo compatible board attached alongside a CyberPower CP1500PFCLCD, usbhid-ups would incorrectly conclude that there was no kernel driver attached to the UPS and then fail subsequent steps accordingly.
The cause is the global usb_communication_subdriver_t struct; when a subdriver (e.g. arduino-hid) sets different values during the enumeration loop, they're not set back to defaults afterwards, causing issues with other subdrivers (e.g. cps-hid).
So, if a subdriver doesn't match, set a selection of fields back to their default values using the newly added nut_usb_subdriver_defaults() before the next attempt.
General points
Described the changes in the PR submission or a separate issue, e.g.
known published or discovered protocols, applicable hardware (expected
compatible and actually tested/developed against), limitations, etc.
There may be multiple commits in the PR, aligned and commented with
a functional change. Notably, coding style changes better belong in a
separate PR, but certainly in a dedicated commit to simplify reviews
of "real" changes in the other commits. Similarly for typo fixes in
comments or text documents.
Please star NUT on GitHub, this helps with sponsorships! ;)
Frequent "underwater rocks" for driver addition/update PRs
Revised existing driver families and added a sub-driver if applicable
(
nutdrv_qx
,usbhid-ups
...) or added a brand new driver in the othercase.
Did not extend obsoleted drivers with new hardware support features
(notably
blazer
and other single-device family drivers for Qx protocols,except the new
nutdrv_qx
which should cover them all).For updated existing device drivers, bumped the
DRIVER_VERSION
macroor its equivalent.
For USB devices (HID or not), revised that the driver uses unique
VID/PID combinations, or raised discussions when this is not the case
(several vendors do use same interface chips for unrelated protocols).
For new USB devices, built and committed the changes for the
scripts/upower/95-upower-hid.hwdb
fileProposed NUT data mapping is aligned with existing
docs/nut-names.txt
file. If the device exposes useful data points not listed in the file, the
experimental.*
namespace can be used as documented there, and discussionshould be raised on the NUT Developers mailing list to standardize the new
concept.
Updated
data/driver.list.in
if applicable (new tested device info)Frequent "underwater rocks" for general C code PRs
structure layout and alignment in memory, endianness (layout of bytes and
bits in memory for multi-byte numeric types), or use of generic
int
wherelanguage or libraries dictate the use of
size_t
(orssize_t
sometimes).Progress and errors are handled with
upsdebugx()
,upslogx()
,fatalx()
and related methods, not with directprintf()
orexit()
.Similarly, NUT helpers are used for error-checked memory allocation and
string operations (except where customized error handling is needed,
such as unlocking device ports, etc.)
Coding style (including whitespace for indentations) follows precedent
in the code of the file, and examples/guide in
docs/developers.txt
file.For newly added files, the
Makefile.am
recipes were updated and themake distcheck
target passes.General documentation updates
Updated
docs/acknowledgements.txt
(for vendor-backed device support)Added or updated manual page information in
docs/man/*.txt
filesand corresponding recipe lists in
docs/man/Makefile.am
for new pagesPassed
make spellcheck
, updated spell-checking dictionary in thedocs/nut.dict
file if needed (did not remove any words -- themake
rule printout in case of changes suggests how to maintain it).
Additional work may be needed after posting this PR
Propose a PR for NUT DDL with detailed device data dumps from tests
against real hardware (the more models, the better).
Address NUT CI farm build failures for the PR: testing on numerous
platforms and toolkits can expose issues not seen on just one system.
the changed codebase.