I need to be able to identify a plugged USB device (USB3 and/or USB2) and which port is connected to in the hub from a C program. I'm working on a embedded Linux system Yocto based.
I'm able to get this info from the command line with lsusb. E.g. I've got connected two USB cameras, one USB3 and the other USB2 and if I run lsusb -t
I can see the port connections tree:
/: Bus 02.Port 1: Dev 1, Class=root_hub, Driver=xhci-hcd/1p, 5000M
|__ Port 1: Dev 3, If 0, Class=Hub, Driver=hub/4p, 5000M
|__ Port 4: Dev 6, If 0, Class=Miscellaneous Device, Driver=, 5000M
/: Bus 01.Port 1: Dev 1, Class=root_hub, Driver=xhci-hcd/1p, 480M
|__ Port 1: Dev 2, If 0, Class=Hub, Driver=hub/4p, 480M
|__ Port 3: Dev 3, If 0, Class=Video, Driver=uvcvideo, 480M
|__ Port 3: Dev 3, If 1, Class=Video, Driver=uvcvideo, 480M
|__ Port 3: Dev 3, If 2, Class=Human Interface Device, Driver=usbhid, 480M
With this I know easily that the USB3 camera is connected to Port 4 and the USB2 one to Port 3 (using a 4 ports HUB). If I run only lsusb
got the IDs and names:
Bus 002 Device 006: ID 20f7:3001 USB3 Camera with CMOS sensor [MQ]
Bus 001 Device 003: ID 0403:de37 Future Technology Devices International, Ltd
Bus 001 Device 002: ID 04b4:650a Cypress Semiconductor Corp.
Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
Bus 002 Device 003: ID 04b4:6508 Cypress Semiconductor Corp.
Bus 002 Device 001: ID 1d6b:0003 Linux Foundation 3.0 root hub
How could I easily scan the hub ports and see what device (name or ID) is connected where (hub port number) from a C application?
Apologise if this already answer somewhere but I couldn't find a specific answer.
Thanks in advance.
libusb
libraries on your Yocto image. A quick google search shows that there are available recipes for these libraries. If you want to generate an output similar tolsusb -t
and get hub ports numbers, you may want to installlibusb1
, otherwiselibusb-compat
should do the job – Storm