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

Fightwarn libusb 1.0+0.1 rebased part1 #1244

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
59 commits
Select commit Hold shift + click to select a range
8bd0050
Move "additional USB-related checks" from configure.ac to m4/nut_chec…
jimklimov Nov 15, 2021
6a0210e
configure.ac: regroup some NUT_ARG_WITH() closer to their NUT_CHECK_*…
jimklimov Dec 7, 2021
68e2952
configure.ac: drop duplicate NUT_CHECK_LIBNETSNMP
jimklimov Dec 7, 2021
36ddfc9
m4/nut_check_libusb.m4 + configure.ac: port newer solution for libusb…
jimklimov Dec 24, 2021
caed361
configure.ac et al: drop the extra --with-libusb-version and handle i…
jimklimov Dec 7, 2021
28500b7
m4/nut_check_libusb.m4: always AC_DEFINE the WITH_LIBUSB_1_0 and WITH…
jimklimov Dec 8, 2021
aca0b7d
m4/nut_check_libusb.m4: (hidden) debug before AC_DEFINE
jimklimov Dec 8, 2021
72c5586
configure.ac + m4/nut_check_libusb.m4: rectify WITH_LIBUSB_x_y defini…
jimklimov Dec 9, 2021
d69ce0c
drivers/Makefile.am: define SHUT_MODE=1 (with a value) so #if is pred…
jimklimov Dec 8, 2021
1b16045
Convert C code from "#ifdef WITH_LIBUSB_x_y" to "#if" tests for defin…
jimklimov Dec 8, 2021
e1f305b
Convert C code from "#ifdef WITH_LIBUSB_x_y" to "#if" tests for defin…
jimklimov Dec 24, 2021
e3daf23
drivers/libusb1.c: HAVE_LIBUSB_DETACH_KERNEL_DRIVER needs "#ifdef" no…
jimklimov Dec 24, 2021
cff486f
drivers/nut_libusb.h: sanity check that exactly one version of WITH_L…
jimklimov Dec 8, 2021
73bed50
drivers/bcmxcp_usb.c: sanity check that exactly one version of WITH_L…
jimklimov Dec 9, 2021
64c026f
drivers/usb-common.h: sanity check that exactly one version of WITH_L…
jimklimov Dec 9, 2021
01b827c
tools/nut-usbinfo.pl: sanity check that exactly one version of WITH_L…
jimklimov Dec 9, 2021
5d04357
drivers/bcmxcp_usb.c: range-check and cast args for usb_control_msg()…
jimklimov Dec 10, 2021
8376307
drivers/nut_libusb.h already includes "usb-common.h" so no need to pu…
jimklimov Dec 10, 2021
75f5c99
drivers/usb-common.h: consolidate libusb-0.1 vs 1.0 data/func mapping…
jimklimov Dec 10, 2021
df22f5d
drivers/usb-common.h: mark "static inline" functions with HAVE_PRAGMA…
jimklimov Dec 10, 2021
2b70b19
drivers/usb-common.h: convert usb_get_string{_simple}() from macro al…
jimklimov Dec 10, 2021
2eaf526
drivers/riello.h: do not define duplicate USB_ENDPOINT_IN/USB_ENDPOIN…
jimklimov Dec 10, 2021
8da949e
drivers/riello_usb.c: adapt to usb-common.h and (usb_ctrl_char) casting
jimklimov Dec 10, 2021
71b58da
drivers/riello_usb.c: fix whitespace (break long lines)
jimklimov Dec 20, 2021
62d27f2
drivers/richcomm_usb.c: fix whitespace (break long lines)
jimklimov Dec 20, 2021
691d397
drivers/nutdrv_atcl_usb.c: adapt to usb-common.h and (usb_ctrl_char) …
jimklimov Dec 10, 2021
0913c8d
drivers/bcmxcp_usb.c: adapt to usb-common.h and (usb_ctrl_char) casting
jimklimov Dec 10, 2021
64b9625
drivers/nutdrv_qx.c: adapt to usb-common.h and (usb_ctrl_char) casting
jimklimov Dec 10, 2021
58076f0
drivers/usbhid-ups.c: current use of SHUT_MODE relies on defined/not-…
jimklimov Dec 10, 2021
b4a1b1a
drivers/nut_libusb.h, libshut.h: whitespace fixes (align "version")
jimklimov Dec 13, 2021
c2029ec
USB: Rename typedef usb_ctrl_char to usb_ctrl_charbuf to avoid confsi…
jimklimov Dec 13, 2021
c498c8a
drivers/bcmxcp_usb.c: comment FIXME for possible uses of usb_ctrl_* t…
jimklimov Dec 20, 2021
aef977a
drivers/usb-common.h + nut_libusb.h: typedef more usb_ctrl_* tokens t…
jimklimov Dec 15, 2021
4e6bdb6
drivers/libshut.c: braces fix
jimklimov Dec 15, 2021
240ed66
drivers/libshut.c: range-check and cast ints to struct members and li…
jimklimov Dec 15, 2021
7575f9b
drivers/libshut.c: shut_control_msg(): range-check data_size before s…
jimklimov Dec 15, 2021
5b17ec5
drivers/libshut.c: shut_control_msg(): data_size is a "short int" (no…
jimklimov Dec 24, 2021
fdafe61
drivers/usb-common.h: update heading comment and (C) for libusb-1.0 r…
jimklimov Dec 16, 2021
8c17853
drivers/usb-common.h: update heading comment with references to diffe…
jimklimov Dec 16, 2021
577a08b
drivers/usb-common.h: note the arg type for libusb_strerror() in comm…
jimklimov Dec 16, 2021
ecbde45
drivers/usb-common.h: comment which API version each endif is for
jimklimov Dec 16, 2021
ba3b133
drivers/nut_libusb.h: comment the practical mess around hid_rep_index
jimklimov Dec 16, 2021
47f4e51
drivers/usb-common.h: update comment about mapping from libusb-0.1 to…
jimklimov Dec 16, 2021
17d72c0
drivers/usb-common.h: clarify that libusb timeouts are in millisecond…
jimklimov Dec 16, 2021
5c816d9
drivers/usb-common.h: define PRI_NUT_USB_CTRL_CHARBUFSIZE, usb_ctrl_m…
jimklimov Dec 16, 2021
620c1fc
drivers/usb-common.h: include "common.h"
jimklimov Dec 21, 2021
1bcd3b2
drivers/usb-common.h: whitespace-separate definitions of ERROR_ACCESS…
jimklimov Dec 20, 2021
516095c
m4/nut_check_libusb.m4: make sure (missing) methods from another API …
jimklimov Dec 19, 2021
8854934
m4/nut_check_libusb.m4: update comments
jimklimov Dec 20, 2021
f968ed3
drivers/nutdrv_atcl_usb.c: drop local libusb-0.1 vs 1.0 definitions n…
jimklimov Dec 20, 2021
8ec7bd6
tools/nut-scanner/scan_usb.c: fix whitespace (indentation etc)
jimklimov Dec 20, 2021
a904ede
tools/nut-scanner/scan_usb.c: comment "#else WITH_LIBUSB_..." in long…
jimklimov Dec 24, 2021
45c470b
tools/nut-scanner/scan_usb.c: missed whitespace fixes
jimklimov Dec 24, 2021
9cbd3e0
drivers/riello_usb.c, richcomm_usb.c, nutdrv_atcl_usb.c: fix remainin…
jimklimov Dec 24, 2021
80d30c4
drivers/libusb1.c: some more whitespace and comment fixes
jimklimov Dec 24, 2021
e71bc60
configure.ac: update "clang-medium" warnings pre-set with -Wno-incomp…
jimklimov Dec 24, 2021
377c438
drivers/usb-common.h: map libusb_detach_kernel_driver_np (1.0) as usb…
jimklimov Dec 25, 2021
777406a
m4/nut_check_libusb.m4, drivers/libusb1.c + nutdrv_atcl_usb.c + richc…
jimklimov Dec 25, 2021
abb01ed
m4/nut_check_libusb.m4, drivers/usb-common.h + nutdrv_atcl_usb.c + ri…
jimklimov Dec 25, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
70 changes: 24 additions & 46 deletions configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -387,12 +387,13 @@ AC_ARG_WITH(all,

dnl ----------------------------------------------------------------------
dnl declare a number of --with-FEATURE options. Do this early, so that
dnl they are listed near the top by "./configure --help"
dnl they are listed near the top by "./configure --help"; however,
dnl note that options with further investigation methods are listed
dnl a bit below to be grouped with their additional with/enable help.

NUT_ARG_WITH([dev], [build and install the development files], [no])
NUT_ARG_WITH([serial], [build and install serial drivers], [yes])
NUT_ARG_WITH([usb], [build and install USB drivers], [auto])
NUT_ARG_WITH([avahi], [build and install Avahi support], [auto])

dnl The NUT legacy option was --with-doc; however to simplify configuration
dnl in some common packaging frameworks, we also allow --with-docs as
dnl a second-class citizen (if both are set, the old option name wins).
Expand All @@ -401,6 +402,7 @@ dnl of the "make distcheck", but it was reduced to "man=auto" so that
dnl the usual builds can pass by default on systems without asciidoc.
NUT_ARG_WITH([docs], [build and install documentation (alias to --with-doc)], [man=auto])
NUT_ARG_WITH([doc], [build and install documentation (see docs/configure.txt for many variants of the option)], [${nut_with_docs}])

NUT_ARG_ENABLE([warnings], [enable warning presets that were picked as useful in maintainership and CI practice (variants include gcc-minimal, gcc-medium, gcc-hard, clang-minimal, clang-medium, clang-hard, all; auto-choosers: hard, medium, minimal, yes=auto='gcc or clang or all at hardcoded default difficulty')], [legacy])
NUT_ARG_ENABLE([Werror], [fail the build if compiler emits any warnings (treat them as errors)], [no])

Expand All @@ -411,15 +413,23 @@ dnl These checks are performed unconditionally, even if the corresponding
dnl --with-* options are not given. This is because we cannot predict
dnl what will be in the --with-drivers argument.

NUT_CHECK_LIBNETSNMP
NUT_ARG_WITH([usb], [build and install USB drivers, optionally require build with specified version of libusb library and API: (auto|libusb-0.1|libusb-1.0)], [auto])
nut_usb_lib=""
NUT_CHECK_LIBUSB

NUT_ARG_WITH([snmp], [build and install SNMP drivers], [auto])
NUT_CHECK_LIBNETSNMP

NUT_ARG_WITH([neon], [build and install neon based XML/HTTP driver], [auto])
NUT_CHECK_LIBNEON

NUT_ARG_WITH([powerman], [build and install Powerman PDU client driver], [auto])
NUT_CHECK_LIBPOWERMAN

NUT_ARG_WITH([modbus], [build and install modbus drivers], [auto])
NUT_CHECK_LIBMODBUS

NUT_ARG_WITH([avahi], [build and install Avahi support], [auto])
NUT_CHECK_LIBAVAHI

dnl ----------------------------------------------------------------------
Expand Down Expand Up @@ -505,52 +515,15 @@ NUT_REPORT_FEATURE([build serial drivers], [${nut_with_serial}], [],
[WITH_SERIAL], [Define to enable serial support])

dnl ----------------------------------------------------------------------
dnl checks related to --with-usb
dnl checks related to --with-usb are in its m4 file and NUT_CHECK_LIBUSB() called above

nut_usb_lib=""

if test "${nut_with_usb}" != "no"; then
if test "${nut_with_usb}" = "libusb-1.0" -o "${nut_with_usb}" = "libusb-0.1"; then
NUT_CHECK_LIBUSB([${nut_with_usb}])
dnl Explicitly choosing a library implies 'yes' (i.e. fail if not found), not 'auto'.
nut_with_usb=yes
else
NUT_CHECK_LIBUSB
fi
dnl Any other value not implying 'yes' is treated as 'auto'.
if test "${nut_with_usb}" = "yes" -a "${nut_have_libusb}" != "yes"; then
AC_MSG_ERROR([USB drivers requested, but libusb not found.])
fi
nut_with_usb="${nut_have_libusb}"
fi

AM_CONDITIONAL(WITH_LIBUSB_0_1, test "${nut_usb_lib}" = "(libusb-0.1)")
dnl Note: there is no libusb-config script (and variable) for libusb-1.0
AM_CONDITIONAL(WITH_LIBUSB_1_0, test "${nut_usb_lib}" = "(libusb-1.0)")
AM_CONDITIONAL(WITH_LIBUSB_0_1, test "${nut_usb_lib}" = "(libusb-0.1)" -o "${nut_usb_lib}" = "(libusb-0.1-config)")

NUT_REPORT_FEATURE([build USB drivers], [${nut_with_usb}], [${nut_usb_lib}],
[WITH_USB], [Define to enable USB support])


dnl ----------------------------------------------------------------------
dnl additional USB-related checks

dnl Solaris 10/11 USB handling (need librt and libusb runtime path)
dnl HPUX, since v11, needs an explicit activation of pthreads
case ${target_os} in
solaris2.1* )
AC_MSG_CHECKING([for Solaris 10 / 11 specific configuration for usb drivers])
AC_SEARCH_LIBS(nanosleep, rt)
LIBUSB_LIBS="-R/usr/sfw/lib ${LIBUSB_LIBS}"
dnl FIXME: Sun's libusb doesn't support timeout (so blocks notification)
dnl and need to call libusb close upon reconnection
AC_DEFINE(SUN_LIBUSB, 1, [Define to 1 for Sun version of the libusb.])
SUN_LIBUSB=1
AC_MSG_RESULT([${LIBUSB_LIBS}])
;;
hpux11*)
CFLAGS="${CFLAGS} -lpthread"
;;
esac

dnl ----------------------------------------------------------------------
dnl checks related to --with-neon

Expand Down Expand Up @@ -2290,6 +2263,11 @@ dnl # signatures differ between dependency releases; sometimes they just
dnl # happened too hard to unravel cleanly and add more warnings.
dnl # This exclusion may be removed after common warnings are solved,
dnl # to allow progress on rectifying these cases next.
dnl # -Wno-incompatible-pointer-types-discards-qualifiers -- our code often
dnl # defines (char*) as the type for struct fields and method arguments,
dnl # but initializes/passes (char[]) variables or fixed strings.
dnl # This makes at least clang-3.4 quite upset and noisy (seems newer
dnl # versions care less about this situation).
AS_CASE(["${nut_enable_warnings}"],
[all], [
CFLAGS="${CFLAGS} -Wall"
Expand All @@ -2300,7 +2278,7 @@ AS_CASE(["${nut_enable_warnings}"],
CXXFLAGS="${CXXFLAGS} -ferror-limit=0 -Wall -Wextra -Weverything -Wno-unused-macros -Wno-reserved-id-macro -Wno-padded -Wno-documentation -Wno-cast-qual -Wno-c++98-compat-pedantic -Wno-c++98-compat"
],
[clang-medium], [
CFLAGS="${CFLAGS} -ferror-limit=0 -Wall -Wextra -Weverything -Wno-unused-macros -Wno-reserved-id-macro -Wno-padded -Wno-documentation -Wno-cast-qual -pedantic -Wno-float-conversion -Wno-double-promotion -Wno-implicit-float-conversion"
CFLAGS="${CFLAGS} -ferror-limit=0 -Wall -Wextra -Weverything -Wno-unused-macros -Wno-reserved-id-macro -Wno-padded -Wno-documentation -Wno-cast-qual -pedantic -Wno-float-conversion -Wno-double-promotion -Wno-implicit-float-conversion -Wno-incompatible-pointer-types-discards-qualifiers"
CXXFLAGS="${CXXFLAGS} -ferror-limit=0 -Wall -Wextra -Weverything -Wno-unused-macros -Wno-reserved-id-macro -Wno-padded -Wno-documentation -Wno-cast-qual -Wno-c++98-compat-pedantic -Wno-c++98-compat"
],
[clang-minimal], [
Expand Down
13 changes: 8 additions & 5 deletions docs/configure.txt
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,14 @@ Build and install the serial drivers (default: yes)
--with-usb

Build and install the USB drivers (default: auto-detect)
Note that you need to install the libusb development package or files, and that
both libusb 0.1 and 1.0 are supported. In case both are available, libusb 1.0
takes precedence, and will be used. It is however possible to override this
default choice by explicitly calling '--with-usb=libusb-0.1' or
'--with-usb=libusb-1.0'.
Note that you need to install the libusb development package or files,
and that both libusb 0.1 and 1.0 are supported. In case both are
available, libusb 1.0 takes precedence, and will be used by default.
It is however possible to override this default choice by explicitly
calling `--with-usb=libusb-0.1` or `--with-usb=libusb-1.0`.
If you do specify the version to use (or `yes` for auto-detection),
this option would fail if requested (or any) libusb version was not
found. The default `auto` value would not fail in such case.

--with-snmp

Expand Down
2 changes: 1 addition & 1 deletion drivers/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ riello_usb_LDADD = $(LDADD_DRIVERS) $(LIBUSB_LIBS) -lm
# HID-over-serial
mge_shut_SOURCES = usbhid-ups.c libshut.c libhid.c hidparser.c mge-hid.c
# per-target CFLAGS are necessary here
mge_shut_CFLAGS = $(AM_CFLAGS) -DSHUT_MODE
mge_shut_CFLAGS = $(AM_CFLAGS) -DSHUT_MODE=1
mge_shut_LDADD = $(LDADD) -lm

# SNMP
Expand Down
47 changes: 7 additions & 40 deletions drivers/bcmxcp_usb.c
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,6 @@
#include <sys/file.h>
#include <sys/types.h>
#include <unistd.h>
/* libusb header file */
#ifdef WITH_LIBUSB_1_0
#include <libusb.h>
#endif
#ifdef WITH_LIBUSB_0_1
#include <usb.h>
#endif

#define SUBDRIVER_NAME "USB communication subdriver"
#define SUBDRIVER_VERSION "0.26"
Expand All @@ -42,35 +35,6 @@ upsdrv_info_t comm_upsdrv_info = {

static USBDevice_t curDevice;

#ifdef WITH_LIBUSB_1_0
/* Simply remap libusb functions/structures from 0.1 to 1.0 */
/* Structures */
#define usb_dev_handle libusb_device_handle
/* defines */
#define USB_DT_STRING LIBUSB_DT_STRING
#define USB_ENDPOINT_OUT LIBUSB_ENDPOINT_OUT
#define USB_REQ_SET_DESCRIPTOR LIBUSB_REQUEST_SET_DESCRIPTOR
#define USB_CLASS_PER_INTERFACE LIBUSB_CLASS_PER_INTERFACE
/* Functions */
#define usb_control_msg libusb_control_transfer
static inline int usb_interrupt_read(usb_dev_handle *dev, int ep,
char *bytes, int size, int timeout)
{
int ret = libusb_interrupt_transfer(dev, ep, (unsigned char *) bytes,
size, &size, timeout);
/* In case of success, return the operation size, as done with libusb 0.1 */
return (ret == LIBUSB_SUCCESS)?size:ret;
}

#define usb_claim_interface libusb_claim_interface
#define usb_release_interface libusb_release_interface
#define usb_reset libusb_reset_device
#define usb_clear_halt libusb_clear_halt
#define nut_usb_strerror(a) libusb_strerror(a)
#else
#define nut_usb_strerror(a) usb_strerror()
#endif /* #ifdef WITH_LIBUSB_1_0 */

/* USB functions */
usb_dev_handle *nutusb_open(const char *port);
int nutusb_close(usb_dev_handle *dev_h, const char *port);
Expand All @@ -79,10 +43,12 @@ void nutusb_comm_fail(const char *fmt, ...)
__attribute__ ((__format__ (__printf__, 1, 2)));
void nutusb_comm_good(void);
/* function pointer, set depending on which device is used */
/* FIXME? Use usb_ctrl_* typedefs*/
static int (*usb_set_descriptor)(usb_dev_handle *udev, unsigned char type,
unsigned char index, void *buf, size_t size);

/* usb_set_descriptor() for Powerware devices */
/* FIXME? Use usb_ctrl_* typedefs*/
static int usb_set_powerware(usb_dev_handle *udev, unsigned char type, unsigned char index, void *buf, size_t size)
{
assert (size < INT_MAX);
Expand All @@ -96,6 +62,7 @@ static void *powerware_ups(USBDevice_t *device) {
}

/* usb_set_descriptor() for Phoenixtec devices */
/* FIXME? Use usb_ctrl_* typedefs*/
static int usb_set_phoenixtec(usb_dev_handle *udev, unsigned char type, unsigned char index, void *buf, size_t size)
{
NUT_UNUSED_VARIABLE(index);
Expand Down Expand Up @@ -210,7 +177,7 @@ ssize_t get_answer(unsigned char *data, unsigned char command)
if (need_data > 0) {
res = usb_interrupt_read(upsdev,
0x81,
(char *) buf + bytes_read,
(usb_ctrl_charbuf) buf + bytes_read,
128,
(int)(XCP_USB_TIMEOUT - elapsed_time));

Expand Down Expand Up @@ -428,7 +395,7 @@ static void nutusb_open_error(const char *port)
/* FIXME: this part of the opening can go into common... */
static usb_dev_handle *open_powerware_usb(void)
{
#ifdef WITH_LIBUSB_1_0
#if WITH_LIBUSB_1_0
libusb_device **devlist;
ssize_t devcount = 0;
libusb_device_handle *udev;
Expand Down Expand Up @@ -517,7 +484,7 @@ usb_dev_handle *nutusb_open(const char *port)
upsdebugx(1, "entering nutusb_open()");

/* Initialize Libusb */
#ifdef WITH_LIBUSB_1_0
#if WITH_LIBUSB_1_0
if (libusb_init(NULL) < 0) {
libusb_exit(NULL);
fatal_with_errno(EXIT_FAILURE, "Failed to init libusb 1.0");
Expand Down Expand Up @@ -597,7 +564,7 @@ int nutusb_close(usb_dev_handle *dev_h, const char *port)
if (dev_h)
{
usb_release_interface(dev_h, 0);
#ifdef WITH_LIBUSB_1_0
#if WITH_LIBUSB_1_0
libusb_close(dev_h);
libusb_exit(NULL);
#else
Expand Down
Loading