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.
As pointed the answer is libusb, and I found the complete answer with an example in this question.
Also the API for libusb is defined here.
Related
I'm studying DPDK and trying to create a simple application, however it can't see a NIC bound to DPDK.
Here is a list of network devices I have on my machine
$ dpdk-devbind.py --status-dev net
Network devices using kernel driver
===================================
0000:01:00.0 'RTL8111/8168/8411 PCI Express Gigabit Ethernet Controller 8168' if=enp1s0 drv=r8169 unused=vfio-pci *Active*
0000:02:00.0 'RTL8822BE 802.11a/b/g/n/ac WiFi adapter b822' if=wlp2s0 drv=rtw_8822be unused=rtw88_8822be,vfio-pci *Active*
I disable my ethernet NIC (it can't be bound to DPDK while it is active) and bind it to vfio-pci driver successfully
$ ip link set enp1s0 down
$ dpdk-devbind.py -b vfio-pci enp1s0
Now dpdk-devbind.py shows that the NIC is using DPDK-compatible driver
$ dpdk-devbind.py --status-dev net
Network devices using DPDK-compatible driver
============================================
0000:01:00.0 'RTL8111/8168/8411 PCI Express Gigabit Ethernet Controller 8168' drv=vfio-pci unused=r8169
Network devices using kernel driver
===================================
0000:02:00.0 'RTL8822BE 802.11a/b/g/n/ac WiFi adapter b822' if=wlp2s0 drv=rtw_8822be unused=rtw88_8822be,vfio-pci *Active*
However when I run any example DPDK application it says that there are no available NIC ports. For instance I wrote a simple application
int main(int argc, char *argv[])
{
int ret;
int total_ports, avail_ports;
ret = rte_eal_init(argc, argv);
if( ret < 0 )
rte_exit(EXIT_FAILURE, "EAL initialization failed\n");
total_ports = rte_eth_dev_count_total();
avail_ports = rte_eth_dev_count_avail();
printf("ETH PORTS %d %d\n", total_ports, avail_ports);
rte_eal_cleanup();
return 0;
}
and both rte_eth_dev_count_total() and rte_eth_dev_count_avail() return 0.
What am I doing wrong?
The main reason why DPDK ports are not identified in your environment is because the NIC in use is not having a supported vendor Poll Mode Driver. Please refer to list of supported NIC from various vendor Realtek is not among them.
Work around: you can use PCAP PMD to solve the problem. Please follow the steps for your environment as
ensure your ethernet port is linked to kernel driver r8169
isntall libpacp-dev for your enviorment (linux/bsd)
rebuild dpdk with PCAP support.
start your application with following args --no-pci --vdev=net_pcap0,iface=enp1s0
This will use libpcap PMD as wrapper for RX and TX over non supported NIC
I use DELL Precision 3541.
After rebooting my laptop, I am getting "No Wifi adaptor found". So I tried few solutions mentioned in stackoverflow. But when I hit sudo lshw -C network
I am getting this in response
description: Network controller
product: Wireless-AC 9560 [Jefferson Peak]
vendor: Intel Corporation
physical id: 14.3
bus info: pci#0000:00:14.3
version: 10
width: 64 bits
clock: 33MHz
capabilities: pm msi pciexpress msix bus_master cap_list
configuration: driver=iwlwifi latency=0
resources: irq:16 memory:ed43c000-ed43ffff
*-network:1
description: Ethernet interface
product: Ethernet Connection (7) I219-V
vendor: Intel Corporation
physical id: 1f.6
bus info: pci#0000:00:1f.6
logical name: eno2
version: 10
serial: 34:48:ed:03:b3:22
capacity: 1Gbit/s
width: 32 bits
clock: 33MHz
capabilities: pm msi bus_master cap_list ethernet physical tp 10bt 10bt-fd 100bt 100bt-fd 1000bt-fd autonegotiation
configuration: autonegotiation=on broadcast=yes driver=e1000e driverversion=3.2.6-k firmware=0.5-4 latency=0 link=no multicast=yes port=twisted pair
resources: irq:172 memory:ed400000-ed41ffff
There is no logical name for my wifi adaptor.
Is there any way I can enable the wifi adaptor on my laptop?
I tried something random. Dont know how it worked for me. Just followed the steps.
1.Restarted my Laptop.
2.Entered BOIS setup (F12).
3.Then inside the wireless section, I completely disabled WLAN.
4.When it booted up successfully, Restarted Laptop again.
5.Entered BOIS setup and enabled the WLAN.
Finally, when the laptop turned on, everything was working fine again.
In my case I installed ubuntu 20.04 and wifi was not working, message was same as "No wifi adaptor found".
I had onboard wifi adaptor.
Using command sudo lshw -C network, I got
*-network
description: Wireless interface
product: Wi-Fi 6 AX200
vendor: Intel Corporation
I knew that my wifi adaptor is of Intel® and now I found that Wi-Fi 6 AX200 160MHz is the actual adaptor.
After doing hours of googling, I went on intel official site and found this link Linux* Support for Intel® Wireless Adapters
I found that my adaptor was listed there under Intel® Wi-Fi 6 AX200 160MHz
I downloaded iwlwifi-cc-46.3cfab8da.0.tgz and extracted it under the directory /lib/firmware as mentioned on intel site.
wooooooooooooo, ubuntu was able to detect the adaptor and my wifi connections were listed under wifi settings.
You may need to restart the system, though in my case it worked as soon as I extracted the files in /lib/firmware.
I have troubles to connect to arduino UNO via Arduino IDE on Ubuntu
Of course ports are greyed out, but I set it up manually.
When I try to upload I get following information:
java.lang.NullPointerException thrown while loading
gnu.io.RXTXCommDriver processing.app.SerialNotFoundException: Serial
port '/dev/ttyACM0' not found. Did you select the right one from the
Tools > Serial Port menu?
Installed packages:
$ apt list --installed |grep arduino
arduino/bionic,bionic,now 2:1.0.5+dfsg2-4.1 all [installed]
arduino-core/bionic,bionic,now 2:1.0.5+dfsg2-4.1 all [installed]
arduino-mk/bionic,bionic,now 1.5.2-1 all [installed]
$
I am member of dialout group:
$ cat /etc/group |grep marcin
uucp:x:10:marcin
dialout:x:20:marcin
fax:x:21:marcin
audio:x:29:pulse,marcin,timidity
dip:x:30:marcin,marcin
video:x:44:marcin
plugdev:x:46:marcin
marcin:x:1001:
Port /dev/ttyACM0 is the proper one:
$ ls -l /dev/ttyACM0
crw-rw---- 1 root dialout 166, 0 paź 12 20:54 /dev/ttyACM0
$
dmesg output:
[ 1033.897893] usb 1-1: new full-speed USB device number 4 using xhci_hcd
[ 1034.051751] usb 1-1: New USB device found, idVendor=2341, idProduct=0043, bcdDevice= 0.01
[ 1034.051768] usb 1-1: New USB device strings: Mfr=1, Product=2, SerialNumber=220
[ 1034.051780] usb 1-1: Manufacturer: Arduino (www.arduino.cc)
[ 1034.051789] usb 1-1: SerialNumber: 9573xxxxxxxxxxxx
[ 1034.112081] cdc_acm 1-1:1.0: ttyACM0: USB ACM device
[ 1034.114359] usbcore: registered new interface driver cdc_acm
[ 1034.114363] cdc_acm: USB Abstract Control Model driver for USB modems and ISDN adapters
Arduino preferences files related to port:
$ cat .arduino/preferences.txt |grep serial
serial.databits=8
serial.debug_rate=9600
serial.parity=N
serial.port=/dev/ttyACM0
serial.stopbits=1
$
USB devices:
$ lsusb
Bus 002 Device 001: ID 1d6b:0003 Linux Foundation 3.0 root hub
Bus 001 Device 003: ID 058f:5608 Alcor Micro Corp.
Bus 001 Device 002: ID 258a:000c
Bus 001 Device 004: ID 2341:0043 Arduino SA Uno R3 (CDC ACM)
Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
$
Computer has been restarted, USB cable was pluged in and out several times with IDE turned on and off, No more ideas on how to move forward.
Any help will be appreciated. Thanks.
I followed the bug pointed by NPE and it solved the issue.
I installed librxtx-java package from bionic-proposed repository
$ sudo apt-get install librxtx-java/bionic-proposed
Now connection works smoothly. Thank you!
I have a Cypress PSoC4 kit that I want to be able to debug. I do have an STM32F4-Discovery, so I unplugged the target part of the discovery and plugged it to the cypress kit.
I have some troubles configuring OpenOCD to make it understand my configuration. I created a file:
maquette:openocd nraynaud$ cat /usr/local/share/openocd/scripts/board/psoc_4_stlink.cfg
source [find interface/stlink-v2.cfg]
transport select hla_swd
source [find target/psoc4.cfg]
and I launch openocd + GDB I get that:
maquette:openocd nraynaud$ openocd -f board/psoc_4_stlink.cfg
Open On-Chip Debugger 0.9.0-rc1-dev-00001-gabd7ad0 (2015-05-05-01:34)
Licensed under GNU GPL v2
For bug reports, read
http://openocd.org/doc/doxygen/bugs.html
Info : The selected transport took over low-level target control. The results might differ compared to plain JTAG/SWD
adapter speed: 1500 kHz
ocd_process_reset_inner
Info : Unable to match requested speed 1500 kHz, using 1200 kHz
Info : Unable to match requested speed 1500 kHz, using 1200 kHz
Info : clock speed 1200 kHz
Info : STLINK v2 JTAG v14 API v2 SWIM v0 VID 0x0483 PID 0x3748
Info : using stlink api v2
Info : Target voltage: 2.892416
Info : psoc4.cpu: hardware has 4 breakpoints, 2 watchpoints
I plugged gdb here, and openOCD gave me that:
Info : accepting 'gdb' connection on tcp/3333
Error: Target not halted
Error: auto_probe failed
Error: Connect failed. Consider setting up a gdb-attach event for the target to prepare target for GDB connect, or use 'gdb_memory_map disable'.
Error: attempted 'gdb' connection rejected
With google, I can find some messages on the topic of halting on this MCU, but I don't know how to act on them: http://permalink.gmane.org/gmane.comp.debugging.openocd.devel/25478
I am trying to port eCos on an i386 PC.
I have downloaded prebuilt redboot.bin from
http://ecos.sourceware.org/ecos/boards/redbootbins/x86pc/
I boot it onto usb disk, using
dd conv=sync if/redboot.bin of=/dev/sdb1
After booting target from usb, I get "IA2!" string on the target monitor always, and on serial port on 38400 8n1 configurations, I receive nothing.
I tried using i386-elf-gdb, but it is not able to connect to the target and starts printing "Ignoring error packet, Continuing..."
I also tried to build redboot using configtool for i386, but it is only able to build library, when I try Tests, It gives ERROR: multiple definition of cyg_start()
I am very new to eCos, and I don't know what I am doing wrong!!.
Ok, I figured out how to boot Redboot on a target i386 pc with RealteK RTL8139 ehternet card.
install grub on usb stick,
mkdir /mnt/USB && mount /dev/sdx1 /mnt/USB
grub-install --force --no-floppy --boot-directory=/mnt/USB/boot /dev/sdx
Build Redboot using ecosconfig, make sure the number of pci bus are less than 8 or more, if more, then need to increase the pci bus range from from 8 inside pci.h, I had my realtek ethernet card on bus 10 dev 10, I had to increase the bus to 11, so that redboot finds realtek card on bootup.
ecosconfig new pc redboot
configtool ecos.ecc
add common ethernet support
Build Library
copy redboot.elf on usb.
on grub startup menu,
insmod multiboot
multiboot /redboot.elf
boot
Thats it, redboot will use BOOTP and provide IP Address, then I can test redboot commands like ip_address, reset, ping, version etc.