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 -------------------------------------- diff --git a/drivers/bcmxcp.c b/drivers/bcmxcp.c index efb108f3dd..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 @@ -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*); @@ -2226,15 +2226,16 @@ void upsdrv_tweak_prognames(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) { /* 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)"); } int setvar (const char *varname, const char *val) 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_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 959ac847ac..08f26c8446 100644 --- a/drivers/bcmxcp_ser.c +++ b/drivers/bcmxcp_ser.c @@ -6,10 +6,10 @@ #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 comm_upsdrv_info = { +upsdrv_info_t bcmxcp_comm_upsdrv_info = { SUBDRIVER_NAME, SUBDRIVER_VERSION, NULL, @@ -410,6 +410,13 @@ static void pw_comm_setup(const char *port) # pragma GCC diagnostic pop #endif +void upsdrv_makevartable(void) +{ + bcmxcp_makevartable(); + + addvar(VAR_VALUE, "baud_rate", "Specify communication speed (ex: 9600)"); +} + void upsdrv_initups(void) { upsfd = ser_open(device_path); diff --git a/drivers/bcmxcp_usb.c b/drivers/bcmxcp_usb.c index aed7f22842..dea3b5af90 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,10 +12,13 @@ #include #define SUBDRIVER_NAME "USB communication subdriver" -#define SUBDRIVER_VERSION "0.28" +#define SUBDRIVER_VERSION "0.29" -/* 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, @@ -367,6 +371,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/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; } diff --git a/tools/nut-scanner/Makefile.am b/tools/nut-scanner/Makefile.am index de6e57af10..b119ddddd1 100644 --- a/tools/nut-scanner/Makefile.am +++ b/tools/nut-scanner/Makefile.am @@ -89,6 +89,23 @@ lib_LTLIBRARIES = include_HEADERS = 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 +serial.c: $(top_srcdir)/drivers/serial.c + test -s "$@" || ln -s -f "$(top_srcdir)/drivers/serial.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) + # Note: we only build nut-scanner, and its library, if libltdl was found (required ATM!) if WITH_NUT_SCANNER bin_PROGRAMS += nut-scanner 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) ******************************************************************************/