From 410da30fb9718d08c9b9c791b36360ce5acb7b3f Mon Sep 17 00:00:00 2001 From: Jim Klimov Date: Wed, 4 Jan 2023 02:33:56 +0100 Subject: [PATCH 1/9] drivers/bcmxcp*: refactor with common bcmxcp_makevartable() to sneak in nut_usb_addvars() where needed [#1754] --- drivers/Makefile.am | 2 +- drivers/bcmxcp.c | 6 ++++-- drivers/bcmxcp.h | 2 ++ drivers/bcmxcp_ser.c | 5 +++++ drivers/bcmxcp_usb.c | 11 ++++++++++- tools/nut-scanner/Makefile.am | 5 ++++- 6 files changed, 26 insertions(+), 5 deletions(-) diff --git a/drivers/Makefile.am b/drivers/Makefile.am index 6d842dcd41..6c99eeba26 100644 --- a/drivers/Makefile.am +++ b/drivers/Makefile.am @@ -229,7 +229,7 @@ usbhid_ups_LDADD = $(LDADD_DRIVERS) $(LIBUSB_LIBS) -lm tripplite_usb_SOURCES = tripplite_usb.c $(LIBUSB_IMPL) usb-common.c tripplite_usb_LDADD = $(LDADD_DRIVERS) $(LIBUSB_LIBS) -lm -bcmxcp_usb_SOURCES = bcmxcp_usb.c bcmxcp.c usb-common.c +bcmxcp_usb_SOURCES = bcmxcp_usb.c bcmxcp.c $(LIBUSB_IMPL) usb-common.c bcmxcp_usb_LDADD = $(LDADD_DRIVERS) $(LIBUSB_LIBS) -lm blazer_usb_SOURCES = blazer.c blazer_usb.c $(LIBUSB_IMPL) usb-common.c diff --git a/drivers/bcmxcp.c b/drivers/bcmxcp.c index fd6676ff9a..86c2dcc2d4 100644 --- a/drivers/bcmxcp.c +++ b/drivers/bcmxcp.c @@ -2213,8 +2213,10 @@ void upsdrv_help(void) { } -/* list flags and values that you want to receive via -x */ -void upsdrv_makevartable(void) +/* list flags and values that you want to receive via -x + * or ups.conf to all bcmxcp* family of drivers + */ +void bcmxcp_makevartable(void) { addvar(VAR_VALUE, "shutdown_delay", "Specify shutdown delay (seconds)"); addvar(VAR_VALUE, "baud_rate", "Specify communication speed (ex: 9600)"); diff --git a/drivers/bcmxcp.h b/drivers/bcmxcp.h index 054dce2466..e3a235c25f 100644 --- a/drivers/bcmxcp.h +++ b/drivers/bcmxcp.h @@ -622,4 +622,6 @@ typedef enum ebool { FALSE, TRUE } bool_t; typedef int bool_t; #endif +void bcmxcp_makevartable(void); + #endif /* NUT_BCMXCP_H_SEEN */ diff --git a/drivers/bcmxcp_ser.c b/drivers/bcmxcp_ser.c index c11f987e84..1d87a9c892 100644 --- a/drivers/bcmxcp_ser.c +++ b/drivers/bcmxcp_ser.c @@ -410,6 +410,11 @@ static void pw_comm_setup(const char *port) # pragma GCC diagnostic pop #endif +void upsdrv_makevartable(void) +{ + bcmxcp_makevartable(); +} + void upsdrv_initups(void) { upsfd = ser_open(device_path); diff --git a/drivers/bcmxcp_usb.c b/drivers/bcmxcp_usb.c index 9b66aef8e0..4004776999 100644 --- a/drivers/bcmxcp_usb.c +++ b/drivers/bcmxcp_usb.c @@ -2,6 +2,7 @@ #include "bcmxcp.h" #include "bcmxcp_io.h" #include "common.h" +#include "nut_libusb.h" #include "usb-common.h" #include "timehead.h" #include "nut_stdint.h" /* for uint16_t */ @@ -11,7 +12,7 @@ #include #define SUBDRIVER_NAME "USB communication subdriver" -#define SUBDRIVER_VERSION "0.27" +#define SUBDRIVER_VERSION "0.28" /* communication driver description structure */ upsdrv_info_t comm_upsdrv_info = { @@ -367,6 +368,14 @@ void upsdrv_comm_good(void) nutusb_comm_good(); } +void upsdrv_makevartable(void) +{ + bcmxcp_makevartable(); + + /* allow -x vendor=X, vendorid=X, product=X, productid=X, serial=X */ + nut_usb_addvars(); +} + void upsdrv_initups(void) { upsdev = nutusb_open("USB"); diff --git a/tools/nut-scanner/Makefile.am b/tools/nut-scanner/Makefile.am index 9c7d01fbd6..e7dc01cf6c 100644 --- a/tools/nut-scanner/Makefile.am +++ b/tools/nut-scanner/Makefile.am @@ -46,10 +46,13 @@ LINKED_SOURCE_FILES += serial.c serial.c: $(top_srcdir)/drivers/serial.c test -s "$@" || ln -s -f "$(top_srcdir)/drivers/serial.c" "$@" -LINKED_SOURCE_FILES += bcmxcp_ser.c +LINKED_SOURCE_FILES += bcmxcp_ser.c bcmxcp.c bcmxcp_ser.c: $(top_srcdir)/drivers/bcmxcp_ser.c test -s "$@" || ln -s -f "$(top_srcdir)/drivers/bcmxcp_ser.c" "$@" +bcmxcp.c: $(top_srcdir)/drivers/bcmxcp.c + test -s "$@" || ln -s -f "$(top_srcdir)/drivers/bcmxcp.c" "$@" + CLEANFILES += $(LINKED_SOURCE_FILES) BUILT_SOURCES += $(LINKED_SOURCE_FILES) From cfaf66276b99668af6d9c7f9bafdd99f2b52f9f3 Mon Sep 17 00:00:00 2001 From: Jim Klimov Date: Fri, 25 Apr 2025 10:27:08 +0200 Subject: [PATCH 2/9] tools/nut-scanner/Makefile.am: typo fix Signed-off-by: Jim Klimov --- tools/nut-scanner/Makefile.am | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/nut-scanner/Makefile.am b/tools/nut-scanner/Makefile.am index 96be1fceba..0fe9697918 100644 --- a/tools/nut-scanner/Makefile.am +++ b/tools/nut-scanner/Makefile.am @@ -56,7 +56,7 @@ dist_noinst_HEADERS = # Separate the .deps of other dirs from this one # NOTE: Not using "$<" due to a legacy Sun/illumos dmake bug with resolver # of dynamic vars, see e.g. https://man.omnios.org/man1/make#BUGS -LINKED_SOURCE_FILES += serial.c +LINKED_SOURCE_FILES = serial.c serial.c: $(top_srcdir)/drivers/serial.c test -s "$@" || ln -s -f "$(top_srcdir)/drivers/serial.c" "$@" From 7574223a19bd168dae5af113e6b56481b25d8013 Mon Sep 17 00:00:00 2001 From: Jim Klimov Date: Tue, 27 Jan 2026 16:00:48 +0100 Subject: [PATCH 3/9] drivers/bcmxcp_ser.c: baud_rate does not apply to BOTH bcmxcp variants [#2270] Signed-off-by: Jim Klimov --- drivers/bcmxcp_ser.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/drivers/bcmxcp_ser.c b/drivers/bcmxcp_ser.c index cda68cbede..6088ee5590 100644 --- a/drivers/bcmxcp_ser.c +++ b/drivers/bcmxcp_ser.c @@ -413,6 +413,8 @@ static void pw_comm_setup(const char *port) void upsdrv_makevartable(void) { bcmxcp_makevartable(); + + addvar(VAR_VALUE, "baud_rate", "Specify communication speed (ex: 9600)"); } void upsdrv_initups(void) From 7606648ec9aa21d4bcaefbec5a5e73aac90940e4 Mon Sep 17 00:00:00 2001 From: Jim Klimov Date: Tue, 27 Jan 2026 16:19:00 +0100 Subject: [PATCH 4/9] tools/nut-scanner/Makefile.am: drop duplicate nut_version.h recipe from PR #2270 Signed-off-by: Jim Klimov --- tools/nut-scanner/Makefile.am | 3 --- 1 file changed, 3 deletions(-) diff --git a/tools/nut-scanner/Makefile.am b/tools/nut-scanner/Makefile.am index 785a5ec3fd..b119ddddd1 100644 --- a/tools/nut-scanner/Makefile.am +++ b/tools/nut-scanner/Makefile.am @@ -106,9 +106,6 @@ bcmxcp.c: $(top_srcdir)/drivers/bcmxcp.c CLEANFILES += $(LINKED_SOURCE_FILES) BUILT_SOURCES += $(LINKED_SOURCE_FILES) -$(top_builddir)/include/nut_version.h: - @cd $(@D) && $(MAKE) $(AM_MAKEFLAGS) $(@F) - # Note: we only build nut-scanner, and its library, if libltdl was found (required ATM!) if WITH_NUT_SCANNER bin_PROGRAMS += nut-scanner From 1aae54b65d90a07ebae207ee714062408bd8b8e1 Mon Sep 17 00:00:00 2001 From: Jim Klimov Date: Tue, 27 Jan 2026 17:11:16 +0100 Subject: [PATCH 5/9] tools/nut-scanner/scan_eaton_serial.c: fix build against updated bcmxcp sources [#2270] Signed-off-by: Jim Klimov --- tools/nut-scanner/scan_eaton_serial.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/tools/nut-scanner/scan_eaton_serial.c b/tools/nut-scanner/scan_eaton_serial.c index 1401dd42ac..a803490d7c 100644 --- a/tools/nut-scanner/scan_eaton_serial.c +++ b/tools/nut-scanner/scan_eaton_serial.c @@ -127,6 +127,14 @@ unsigned char calc_checksum(const unsigned char *buf) return c; } +void addvar(int vartype, const char *name, const char *desc) { + NUT_UNUSED_VARIABLE(vartype); + NUT_UNUSED_VARIABLE(name); + NUT_UNUSED_VARIABLE(desc); +} + +void bcmxcp_makevartable(void) {} + /******************************************************************************* * SHUT functions (MGE legacy, but Eaton path forward) ******************************************************************************/ From b30a0344450554a681ec1ac308b7a26d5dd402ae Mon Sep 17 00:00:00 2001 From: Jim Klimov Date: Tue, 27 Jan 2026 17:16:19 +0100 Subject: [PATCH 6/9] drivers/bcmxcp*: rename comm_upsdrv_info => bcmxcp_comm_upsdrv_info to avoid linker conflict with libusb{0,1}.c [#2270] Signed-off-by: Jim Klimov --- drivers/bcmxcp.c | 2 +- drivers/bcmxcp_io.h | 2 +- drivers/bcmxcp_ser.c | 2 +- drivers/bcmxcp_usb.c | 7 +++++-- 4 files changed, 8 insertions(+), 5 deletions(-) diff --git a/drivers/bcmxcp.c b/drivers/bcmxcp.c index 04efb63385..3b3a670fcd 100644 --- a/drivers/bcmxcp.c +++ b/drivers/bcmxcp.c @@ -135,7 +135,7 @@ upsdrv_info_t upsdrv_info = { "Alf Høgemark \n" \ "Gavrilov Igor", DRV_STABLE, - { &comm_upsdrv_info, NULL } + { &bcmxcp_comm_upsdrv_info, NULL } }; static uint16_t get_word(const unsigned char*); diff --git a/drivers/bcmxcp_io.h b/drivers/bcmxcp_io.h index 5293e0500a..bd8200ff93 100644 --- a/drivers/bcmxcp_io.h +++ b/drivers/bcmxcp_io.h @@ -17,6 +17,6 @@ void upsdrv_cleanup(void); void upsdrv_reconnect(void); void upsdrv_comm_good(void); -extern upsdrv_info_t comm_upsdrv_info; +extern upsdrv_info_t bcmxcp_comm_upsdrv_info; #endif /* BCMXCP_IO__ */ diff --git a/drivers/bcmxcp_ser.c b/drivers/bcmxcp_ser.c index 6088ee5590..6a20cbdc59 100644 --- a/drivers/bcmxcp_ser.c +++ b/drivers/bcmxcp_ser.c @@ -9,7 +9,7 @@ #define SUBDRIVER_VERSION "0.22" /* communication driver description structure */ -upsdrv_info_t comm_upsdrv_info = { +upsdrv_info_t bcmxcp_comm_upsdrv_info = { SUBDRIVER_NAME, SUBDRIVER_VERSION, NULL, diff --git a/drivers/bcmxcp_usb.c b/drivers/bcmxcp_usb.c index ff3ef3ba17..7115a98363 100644 --- a/drivers/bcmxcp_usb.c +++ b/drivers/bcmxcp_usb.c @@ -14,8 +14,11 @@ #define SUBDRIVER_NAME "USB communication subdriver" #define SUBDRIVER_VERSION "0.28" -/* communication driver description structure */ -upsdrv_info_t comm_upsdrv_info = { +/* communication driver description structure + * NOTE: Renamed from comm_upsdrv_info to avoid conflict + * with that defined in libusb{0,1}.c + */ +upsdrv_info_t bcmxcp_comm_upsdrv_info = { SUBDRIVER_NAME, SUBDRIVER_VERSION, NULL, From fdd0f24c5b43dae06494aca45b20de949d4238f4 Mon Sep 17 00:00:00 2001 From: Jim Klimov Date: Tue, 27 Jan 2026 17:18:10 +0100 Subject: [PATCH 7/9] drivers/bcmxcp*.c: bump {SUB,}DRIVER_VERSION due to PR #2270 Signed-off-by: Jim Klimov --- drivers/bcmxcp.c | 2 +- drivers/bcmxcp_ser.c | 2 +- drivers/bcmxcp_usb.c | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/drivers/bcmxcp.c b/drivers/bcmxcp.c index 3b3a670fcd..15d7a2e8a0 100644 --- a/drivers/bcmxcp.c +++ b/drivers/bcmxcp.c @@ -116,7 +116,7 @@ TODO List: #include "bcmxcp.h" #define DRIVER_NAME "BCMXCP UPS driver" -#define DRIVER_VERSION "0.39" +#define DRIVER_VERSION "0.40" #define MAX_NUT_NAME_LENGTH 128 #define NUT_OUTLET_POSITION 7 diff --git a/drivers/bcmxcp_ser.c b/drivers/bcmxcp_ser.c index 6a20cbdc59..08f26c8446 100644 --- a/drivers/bcmxcp_ser.c +++ b/drivers/bcmxcp_ser.c @@ -6,7 +6,7 @@ #include "nut_stdint.h" #define SUBDRIVER_NAME "RS-232 communication subdriver" -#define SUBDRIVER_VERSION "0.22" +#define SUBDRIVER_VERSION "0.23" /* communication driver description structure */ upsdrv_info_t bcmxcp_comm_upsdrv_info = { diff --git a/drivers/bcmxcp_usb.c b/drivers/bcmxcp_usb.c index 7115a98363..dea3b5af90 100644 --- a/drivers/bcmxcp_usb.c +++ b/drivers/bcmxcp_usb.c @@ -12,7 +12,7 @@ #include #define SUBDRIVER_NAME "USB communication subdriver" -#define SUBDRIVER_VERSION "0.28" +#define SUBDRIVER_VERSION "0.29" /* communication driver description structure * NOTE: Renamed from comm_upsdrv_info to avoid conflict From 2af874bc1667e44436683193cf59505aabf30ce9 Mon Sep 17 00:00:00 2001 From: Jim Klimov Date: Tue, 27 Jan 2026 17:27:25 +0100 Subject: [PATCH 8/9] docs/man/bcmxcp_usb.txt: uncomment include::nut_usb_addvars.txt [#2270, #1764] Signed-off-by: Jim Klimov --- docs/man/bcmxcp_usb.txt | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/docs/man/bcmxcp_usb.txt b/docs/man/bcmxcp_usb.txt index 1581f51dd4..87670d6178 100644 --- a/docs/man/bcmxcp_usb.txt +++ b/docs/man/bcmxcp_usb.txt @@ -38,20 +38,10 @@ linkman:ups.conf[5]. The number of seconds that the UPS should wait between receiving the shutdown command and actually shutting off. -NOTE: This driver does not currently support USB-matching settings common -to other drivers, such as *vendor*, *vendorid*, *product*, *productid*, -*serial*, *device* or *bus*. - -//////// -The note above may be addressed by -https://github.com/networkupstools/nut/issues/1764 -When that happens, replace it by the following lines: - USB INTERFACE ONLY ~~~~~~~~~~~~~~~~~~ include::nut_usb_addvars.txt[] -//////// DEFAULT VALUES FOR THE EXTRA ARGUMENTS -------------------------------------- From 023906d2e4ae8efab5674e96c752cb0e7db9a058 Mon Sep 17 00:00:00 2001 From: Jim Klimov Date: Tue, 27 Jan 2026 17:47:50 +0100 Subject: [PATCH 9/9] drivers/usb-common.c: add debug tracing [#2270] Signed-off-by: Jim Klimov --- drivers/usb-common.c | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/drivers/usb-common.c b/drivers/usb-common.c index 4834714cc8..7a7051c02e 100644 --- a/drivers/usb-common.c +++ b/drivers/usb-common.c @@ -26,26 +26,39 @@ int is_usb_device_supported(usb_device_id_t *usb_device_id_list, USBDevice_t *de int retval = NOT_SUPPORTED; usb_device_id_t *usbdev; + upsdebugx(3, "%s: checking if this driver can support USB device VID:PID 0x%04X:0x%04X", + __func__, (unsigned int)device->VendorID, (unsigned int)device->ProductID); + for (usbdev = usb_device_id_list; (usbdev->vendorID != 0 || usbdev->productID != 0 || usbdev->fun != NULL); usbdev++ ) { + upsdebugx(4, "%s: checking table entry for VID:PID 0x%04X:0x%04X " + "(custom init handler is%s available)", + __func__, (unsigned int)usbdev->vendorID, + (unsigned int)usbdev->productID, + (usbdev->fun == NULL ? " NOT" : "")); + if (usbdev->vendorID != device->VendorID) { + upsdebugx(4, "%s: NOT_SUPPORTED: vendor ID mismatch", __func__); continue; } /* flag as possibly supported if we see a known vendor */ retval = POSSIBLY_SUPPORTED; + upsdebugx(4, "%s: POSSIBLY_SUPPORTED: known vendor ID at least", __func__); if (usbdev->productID != device->ProductID) { continue; } /* call the specific handler, if it exists */ if (usbdev->fun != NULL) { + upsdebugx(4, "%s: call the custom init handler", __func__); (*usbdev->fun)(device); } + upsdebugx(4, "%s: SUPPORTED: known vendor and product IDs", __func__); return SUPPORTED; }