Skip to content
This repository has been archived by the owner on Mar 7, 2023. It is now read-only.

feat: [linux] expose devnum and busnum #149

Merged
Merged
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
8 changes: 4 additions & 4 deletions src/detection_linux.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -168,8 +168,8 @@ static ListResultItem_t* GetProperties(struct udev_device* dev, ListResultItem_t
}
item->vendorId = strtol(udev_device_get_sysattr_value(dev,"idVendor"), NULL, 16);
item->productId = strtol(udev_device_get_sysattr_value(dev,"idProduct"), NULL, 16);
item->deviceAddress = 0;
item->locationId = 0;
item->deviceAddress = strtol(udev_device_get_sysattr_value(dev,"devnum"), NULL, 10);
item->locationId = strtol(udev_device_get_sysattr_value(dev,"busnum"), NULL, 10);
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reference to others doing something similar, https://github.com/OpenXT/vusb-daemon/blob/ed721b3caa4b0fc93a54fac6b86cad17228ce842/src/udev.c#L383-L387

It's using 10 because the devnum and busnum are base 10 vs the others are base 16

What:		/sys/bus/usb/devices/usbX/busnum
Description:
		Number of the bus.

[...]

What:		/sys/bus/usb/devices/usbX/devnum
Description:
		USB interface device number, in decimal.

[...]

What:		/sys/bus/usb/devices/usbX/idProduct
Description:
		Product ID, in hexadecimal.

What:		/sys/bus/usb/devices/usbX/idVendor
Description:
		Vendor ID, in hexadecimal.

-- https://www.kernel.org/doc/Documentation/ABI/testing/sysfs-bus-usb


return item;
}
Expand Down Expand Up @@ -317,8 +317,8 @@ static void BuildInitialDeviceList() {
if(udev_device_get_sysattr_value(dev,"serial") != NULL) {
item->deviceParams.serialNumber = udev_device_get_sysattr_value(dev, "serial");
}
item->deviceParams.deviceAddress = 0;
item->deviceParams.locationId = 0;
item->deviceParams.deviceAddress = strtol(udev_device_get_sysattr_value(dev,"devnum"), NULL, 10);
item->deviceParams.locationId = strtol(udev_device_get_sysattr_value(dev,"busnum"), NULL, 10);

item->deviceState = DeviceState_Connect;

Expand Down