From 2e275db96ee0bf75e36eefb507c3d9c515b3cdcc Mon Sep 17 00:00:00 2001 From: Derek Atkins Date: Thu, 23 Aug 2018 10:40:46 -0400 Subject: [PATCH] Stabilize path for libusb devices --- libusb/hid.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/libusb/hid.c b/libusb/hid.c index 3c6d877f..c2965093 100644 --- a/libusb/hid.c +++ b/libusb/hid.c @@ -480,9 +480,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';