|
4 | 4 | *
|
5 | 5 | * @author Copyright (C) 2016 Eaton
|
6 | 6 | * Copyright (C) 2016 Arnaud Quette <[email protected]>
|
7 |
| - * Copyright (C) 2021 Jim Klimov <[email protected]> |
| 7 | + * Copyright (C) 2021-2024 Jim Klimov <[email protected]> |
8 | 8 | *
|
9 | 9 | * The logic of this file is ripped from mge-shut driver (also from
|
10 | 10 | * Arnaud Quette), which is a "HID over serial link" UPS driver for
|
|
33 | 33 | #include "nut_stdint.h"
|
34 | 34 |
|
35 | 35 | #define USB_DRIVER_NAME "USB communication driver (libusb 1.0)"
|
36 |
| -#define USB_DRIVER_VERSION "0.47" |
| 36 | +#define USB_DRIVER_VERSION "0.48" |
37 | 37 |
|
38 | 38 | /* driver description structure */
|
39 | 39 | upsdrv_info_t comm_upsdrv_info = {
|
@@ -872,6 +872,7 @@ static int nut_libusb_strerror(const int ret, const char *desc)
|
872 | 872 | return 0;
|
873 | 873 | #endif /* WIN32 */
|
874 | 874 |
|
| 875 | + case LIBUSB_SUCCESS: /** TOTHINK: Should this be quiet? */ |
875 | 876 | case LIBUSB_ERROR_OTHER: /** Other error */
|
876 | 877 | default: /** Undetermined, log only */
|
877 | 878 | upslogx(LOG_DEBUG, "%s: %s", desc, libusb_strerror((enum libusb_error)ret));
|
@@ -1022,6 +1023,18 @@ static int nut_libusb_get_string(
|
1022 | 1023 | ret = libusb_get_string_descriptor_ascii(udev, (uint8_t)StringIdx,
|
1023 | 1024 | (unsigned char*)buf, (int)buflen);
|
1024 | 1025 |
|
| 1026 | + /** 0 can be seen as an empty string, or as LIBUSB_SUCCESS for |
| 1027 | + * logging below - also tends to happen */ |
| 1028 | + if (ret == 0) { |
| 1029 | + size_t len = strlen(buf); |
| 1030 | + upsdebugx(2, "%s: libusb_get_string_descriptor_ascii() returned " |
| 1031 | + "0 (might be just LIBUSB_SUCCESS code), " |
| 1032 | + "actual buf length is %" PRIuSIZE, __func__, len); |
| 1033 | + /* if (len) */ |
| 1034 | + return len; |
| 1035 | + /* else may log "nut_libusb_get_string: Success" and return 0 below */ |
| 1036 | + } |
| 1037 | + |
1025 | 1038 | return nut_libusb_strerror(ret, __func__);
|
1026 | 1039 | }
|
1027 | 1040 |
|
|
0 commit comments