Skip to content
Closed
Changes from 3 commits
Commits
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
31 changes: 21 additions & 10 deletions libusb/hid.c
Original file line number Diff line number Diff line change
Expand Up @@ -478,19 +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];
snprintf(str, sizeof(str), "%04x:%04x:%02x",
libusb_get_bus_number(dev),
libusb_get_device_address(dev),
interface_number);
str[sizeof(str)-1] = '\0';

return strdup(str);
// 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};
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) {
Expand Down