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

Stabilize path for libusb devices #406

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all 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
12 changes: 10 additions & 2 deletions libusb/hid.c
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand Down