From a4c407a131464e093386338ce0d90e29245ae250 Mon Sep 17 00:00:00 2001 From: John Harrington Date: Wed, 13 Nov 2019 13:16:51 -0500 Subject: [PATCH 1/4] Changes from PR406 in signal11 repo --- libusb/hid.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/libusb/hid.c b/libusb/hid.c index 57aca5564..b3107fd1a 100644 --- a/libusb/hid.c +++ b/libusb/hid.c @@ -481,9 +481,17 @@ static wchar_t *get_usb_string(libusb_device_handle *dev, uint8_t idx) static char *make_path(libusb_device *dev, int interface_number) { char str[64]; - snprintf(str, sizeof(str), "%04x:%04x:%02x", + uint8_t port_numbers[8] = { 0,0,0,0,0,0,0,0 }; + int num_ports; + // Note that USB3 port count limit is 7; use 8 here for alignment + + num_ports = libusb_get_port_numbers(dev, port_numbers, 8); + snprintf(str, sizeof(str), "%04x:%04x:%04x:%04x:%04x:%02x", libusb_get_bus_number(dev), - libusb_get_device_address(dev), + *(uint16_t*)(&port_numbers[0]), + *(uint16_t*)(&port_numbers[2]), + *(uint16_t*)(&port_numbers[4]), + *(uint16_t*)(&port_numbers[6]), interface_number); str[sizeof(str)-1] = '\0'; From 660ef697f619d89d6afe96e3a32e25b1f8f71105 Mon Sep 17 00:00:00 2001 From: Gavin Date: Wed, 13 Nov 2019 13:23:37 -0500 Subject: [PATCH 2/4] Tested on Ubuntu 18.04 using DYMO M25 scales with cython-hidapi wrapper From 6203c6b49bd1199b6e85e41e4195c33d5ac4e665 Mon Sep 17 00:00:00 2001 From: Gavin Date: Wed, 20 Nov 2019 10:20:12 -0500 Subject: [PATCH 3/4] make_path check results for errors --- libusb/hid.c | 37 ++++++++++++++++++++----------------- 1 file changed, 20 insertions(+), 17 deletions(-) diff --git a/libusb/hid.c b/libusb/hid.c index b3107fd1a..7a629a9f3 100644 --- a/libusb/hid.c +++ b/libusb/hid.c @@ -478,27 +478,30 @@ static wchar_t *get_usb_string(libusb_device_handle *dev, uint8_t idx) return str; } -static char *make_path(libusb_device *dev, int interface_number) -{ +static char *make_path(libusb_device *dev, int interface_number) { char str[64]; - uint8_t port_numbers[8] = { 0,0,0,0,0,0,0,0 }; - int num_ports; // Note that USB3 port count limit is 7; use 8 here for alignment - - num_ports = libusb_get_port_numbers(dev, port_numbers, 8); - snprintf(str, sizeof(str), "%04x:%04x:%04x:%04x:%04x:%02x", - libusb_get_bus_number(dev), - *(uint16_t*)(&port_numbers[0]), - *(uint16_t*)(&port_numbers[2]), - *(uint16_t*)(&port_numbers[4]), - *(uint16_t*)(&port_numbers[6]), - interface_number); - str[sizeof(str)-1] = '\0'; - - return strdup(str); + uint8_t port_numbers[8] = {0, 0, 0, 0, 0, 0, 0, 0}; + int num_ports = libusb_get_port_numbers(dev, port_numbers, 8); + + if (num_ports > 0) { + snprintf(str, sizeof(str), "%04x:%04x:%04x:%04x:%04x:%02x", + libusb_get_bus_number(dev), *(uint16_t *)(&port_numbers[0]), + *(uint16_t *)(&port_numbers[2]), *(uint16_t *)(&port_numbers[4]), + *(uint16_t *)(&port_numbers[6]), interface_number); + str[sizeof(str) - 1] = '\0'; + } else { + // USB3.0 specs limit number of ports to 7 and buffer size here is 8 + if (num_ports == LIBUSB_ERROR_OVERFLOW) { + LOG("make_path() failed. buffer overflow error\n"); + } else { + LOG("make_path() failed. unknown error\n"); + } + str[0] = '\0'; + } + return strdup(str); } - int HID_API_EXPORT hid_init(void) { if (!usb_context) { From fefe20cff5c779b2e3600cb699407a9f4c482a48 Mon Sep 17 00:00:00 2001 From: Barnabas Gavin Cangan Date: Wed, 20 Nov 2019 12:10:46 -0500 Subject: [PATCH 4/4] Update libusb/hid.c Co-Authored-By: Ihor Dutchak --- libusb/hid.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/libusb/hid.c b/libusb/hid.c index 7a629a9f3..c870ecefd 100644 --- a/libusb/hid.c +++ b/libusb/hid.c @@ -478,7 +478,8 @@ static wchar_t *get_usb_string(libusb_device_handle *dev, uint8_t idx) return str; } -static char *make_path(libusb_device *dev, int interface_number) { +static char *make_path(libusb_device *dev, int interface_number) +{ char str[64]; // Note that USB3 port count limit is 7; use 8 here for alignment uint8_t port_numbers[8] = {0, 0, 0, 0, 0, 0, 0, 0};