Skip to content

Commit

Permalink
tools/nut-scanner/scan_usb.c: do not actively suggest vendor(id), pro…
Browse files Browse the repository at this point in the history
…duct(id), and serial options for bcmxcp_usb, richcomm_usb, nutdrv_atcl_usb [networkupstools#1763, networkupstools#1764, networkupstools#1768, networkupstools#2580]

Signed-off-by: Jim Klimov <[email protected]>
  • Loading branch information
jimklimov committed Aug 10, 2024
1 parent f421426 commit 5bfbc3e
Show file tree
Hide file tree
Showing 5 changed files with 85 additions and 25 deletions.
3 changes: 3 additions & 0 deletions NEWS.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,9 @@ during a NUT build.
all supported buses with `-m auto` takes unbearably long. [#2523]
* bumped version of `libnutscan` to 2.6.0, it now includes a few more
methods and symbols from `libcommon`. [issue #2244, PR #2509]
* do not actively suggest `vendor(id)`, `product(id)`, and `serial` options
for `bcmxcp_usb`, `richcomm_usb` and `nutdrv_atcl_usb` drivers for now
[#1763, #1764, #1768, #2580]
- common code:
* introduced a `NUT_DEBUG_SYSLOG` environment variable to tweak activation
Expand Down
4 changes: 4 additions & 0 deletions drivers/bcmxcp.c
Original file line number Diff line number Diff line change
Expand Up @@ -2218,6 +2218,10 @@ void upsdrv_help(void)
/* list flags and values that you want to receive via -x */
void upsdrv_makevartable(void)
{
/* NOTE: The USB variant of this driver currently does not
* involve nut_usb_addvars() method like others do. When
* fixing, see also tools/nut-scanner/scan_usb.c "exceptions".
*/
addvar(VAR_VALUE, "shutdown_delay", "Specify shutdown delay (seconds)");
addvar(VAR_VALUE, "baud_rate", "Specify communication speed (ex: 9600)");
}
Expand Down
1 change: 1 addition & 0 deletions drivers/nutdrv_atcl_usb.c
Original file line number Diff line number Diff line change
Expand Up @@ -689,6 +689,7 @@ void upsdrv_makevartable(void)
{
/* NOTE: This driver uses a very custom device matching method,
* so does not involve nut_usb_addvars() method like others do.
* When fixing, see also tools/nut-scanner/scan_usb.c "exceptions".
*/
addvar(VAR_VALUE, "vendor", "USB vendor string (or NULL if none)");
}
3 changes: 2 additions & 1 deletion drivers/richcomm_usb.c
Original file line number Diff line number Diff line change
Expand Up @@ -746,6 +746,7 @@ void upsdrv_makevartable(void)
{
/* allow -x vendor=X, vendorid=X, product=X, productid=X, serial=X */
/* TODO: Uncomment while addressing https://github.com/networkupstools/nut/issues/1768
nut_usb_addvars();
* When fixing, see also tools/nut-scanner/scan_usb.c "exceptions".
* nut_usb_addvars();
*/
}
99 changes: 75 additions & 24 deletions tools/nut-scanner/scan_usb.c
Original file line number Diff line number Diff line change
Expand Up @@ -602,36 +602,87 @@ nutscan_device_t * nutscan_scan_usb(nutscan_usb_t * scanopts)
}
nut_dev->port = strdup("auto");

sprintf(string, "%04X", VendorID);
nutscan_add_option_to_device(nut_dev,
"vendorid",
string);

sprintf(string, "%04X", ProductID);
nutscan_add_option_to_device(nut_dev,
"productid",
string);

if (device_name) {
/* FIXME: https://github.com/networkupstools/nut/pull/1763
* and linked issues: some drivers do not use
* the common nut_usb_addvars() method, and
* do not otherwise support these options:
*/
if (strncmp(driver_name, "bcmxcp_usb", 10)
&& strncmp(driver_name, "richcomm_usb", 12)
&& strncmp(driver_name, "nutdrv_atcl_usb", 15)
) {
sprintf(string, "%04X", VendorID);
nutscan_add_option_to_device(nut_dev,
"product",
device_name);
free(device_name);
device_name = NULL;
}
"vendorid",
string);

if (serialnumber) {
sprintf(string, "%04X", ProductID);
nutscan_add_option_to_device(nut_dev,
"serial",
serialnumber);
free(serialnumber);
serialnumber = NULL;
"productid",
string);

if (device_name) {
nutscan_add_option_to_device(nut_dev,
"product",
device_name);
free(device_name);
device_name = NULL;
}

if (serialnumber) {
nutscan_add_option_to_device(nut_dev,
"serial",
serialnumber);
free(serialnumber);
serialnumber = NULL;
}
} else {
sprintf(string, "%04X", VendorID);
nutscan_add_commented_option_to_device(nut_dev,
"vendorid",
string,
"");

sprintf(string, "%04X", ProductID);
nutscan_add_commented_option_to_device(nut_dev,
"productid",
string,
"");

if (device_name) {
nutscan_add_commented_option_to_device(nut_dev,
"product",
device_name,
"");
free(device_name);
device_name = NULL;
}

if (serialnumber) {
nutscan_add_commented_option_to_device(nut_dev,
"serial",
serialnumber,
"");
free(serialnumber);
serialnumber = NULL;
}
}

if (vendor_name) {
nutscan_add_option_to_device(nut_dev,
"vendor",
vendor_name);
/* NOTE: nutdrv_atcl_usb recognizes
* "vendor" but not other opts */
if (strncmp(driver_name, "bcmxcp_usb", 10)
&& strncmp(driver_name, "richcomm_usb", 12)
) {
nutscan_add_option_to_device(nut_dev,
"vendor",
vendor_name);
} else {
nutscan_add_commented_option_to_device(nut_dev,
"vendor",
vendor_name,
"");
}
free(vendor_name);
vendor_name = NULL;
}
Expand Down

0 comments on commit 5bfbc3e

Please sign in to comment.