How can i get USB device file path correctly in Linux.
I used command: find / -iname "usb" and got the result as below:
/dev/bus/usb
/sys/bus/usb
/sys/bus/usb/drivers/usb
/sys/kernel/debug/usb
Under /dev/bus/usb i see:
001 002 003 004 005 006
But I think they aren't files as i need.
Under /sys/bus/usb/devices/:
sh-3.2# ls /sys/bus/usb/devices/
1-0:1.0 1-1:1.0 3-0:1.0 5-0:1.0 usb1 usb3 usb5
1-1 2-0:1.0 4-0:1.0 6-0:1.0 usb2 usb4 usb6
And Under /sys/bus/scsi/devices/ when i pluged an USB i see:
2:0:0:0 host0 host2 target2:0:0
And when i removed USB i see:
sh-3.2# ls
host0
So which device file is used for USB? How can i indentify it? I need to make a C program with USB device file...
Further more, could you explain to me the number 1-1:1.0? What does it mean?
Thank you.
So which device file is used for USB? How can i indentify it?
What you see behind /sys/ is mainly configuration/information about devices. /dev/bus/usb is what you are looking for. I think that the following article can help you
http://www.linuxjournal.com/article/7466?page=0,0
Is quite old, but still it can help you. (In the article they speak about /proc/bus/usb, today we have /dev/bus/usb)
Further more, could you explain to me the number 1-1:1.0? What does it mean?
The generic form is
X-Y.Z:A.B
Each field identify the connection point of your device. The first two field are mandatory:
X is the USB bus of your motherboard where is connected the USB system.
Y is the port in use on the bus system
So the USB device identified with the string 3-3 is the device connected on the port 3 of the bus 3.
If you connect an USB hub, you are extending the connection capability of a single USB port. The Linux kernel identify this situation by appending the Z field.
Z is the port is use on an hub
So, the USB device identified with the string 1-2.5 is the device connected on the port 5 of the hub connected on the port 2 of the bus 1.
USB specification allow you to connect in cascade more then one USB hub, so the Linux kernel continue to append the port in use on the different hubs. So, the USB device identified with the string 1-2.1.1 is the device connected on the port 1 of the hub connected on the port 1 of the hub connected to the port 2 of the bus 1.
A fast way to retrieve these information is to read the kernel messages (if you can).
$ dmesg | grep usb
[... snip ...]
[ 2.047950] usb 4-1: new full-speed USB device number 2 using ohci_hcd
[ 2.202628] usb 4-1: New USB device found, idVendor=046d, idProduct=c318
[ 2.202638] usb 4-1: New USB device strings: Mfr=1, Product=2, SerialNumber=0
[ 2.202643] usb 4-1: Product: Logitech Illuminated Keyboard
[ 2.202648] usb 4-1: Manufacturer: Logitech
[... snip ...]
Then, the last two fields of the pattern (after colon) identify an internal section of an USB device :
A is the configuration number of the device
B is the interface number of a configuration
So, the string 4-1:1.1 means: the interface 1, on configuration 1 that is connected on the port 1 of the bus 4.
You can retrieve these information with the command lsusb.
Related
I have 2 USB devices connected to raspberry pi,
CP2108 USB to serial converter which has 4 ports, when I connect to usb I get 4 ttyUSBx
EC25 GSM modem, for this also same case. when I connect I get 4 ports.
How do I assign a static name to all of them?
I have used bellow method but no result.
SUBSYSTEM=="tty", ATTRS{idVendor}=="2c7c", ATTRS{idProduct}=="0125", SYMLINK+="ttyUSB_EC25_Modem_%s{devpath}"
SUBSYSTEM=="tty", ATTRS{idVendor}=="10c4", ATTRS{idProduct}=="ea71", SYMLINK+="ttyUSB_CP2108X_%s{devpath}"
Connect the devices and look under /dev/serial/by-id/. You should have symlinks to these ttyUSBx devices with longer and more descriptive names. No need to use udev rules.
I recently got hands on an workout device which has a USB to PC interface and logs workouts on a lousy Windows Application. My intention is to read out the USB and build a custom application for presenting that data.
When connected to a linux machine the device registers in /dev/ttyUSB0, can be seen with lsusb and stty reports the baudrate among other information. I fire up minicom with the stty settings and as soon as the workout is initiated the device sends a series of 41 bytes
I assume that those bytes represent an announcement to the the PC interface.
What I would like to do is to imitate the workout device and send those 41 bytes to the PC interface myself in order to see what the PC side does upon initiation. Is there a way to imitate the device so that the PC software will recognize it?
if the device is /dev/ttyUSB0 it is very likel implementing a virtual COM port, this is USB Communication Device class CDC (ACM).
the operating system knows what driver / kernel module it has to load because when you plug in the device in USB protocol descriptors are exchanged ( the device sends its device descriptor to the host, according to this the host loads the driver / kernel module ), you can see this information with lsusb -v. Specifically the device sends the following descriptors to the host : device descriptor, configuration descriptor, interface descriptor, endpoint descriptor : http://www.beyondlogic.org/usbnutshell/usb1.shtml
for imitating a device you have to write a firmware on a MCU with exaclty these descriptors and additionally with identic VID ( vendor id ) and PID ( product id )
the 41 bytes you receive flow over the virtual COM port and so in RS-232 protocol ( you are able to receive them with minicom ) and so they are above USB level, however they are part of the payload in USB packets. if you have a proprietary driver in windows of your device in windows these 41 bytes are very likely addressed to the driver ( whichs source code you very likely do not have ...). this is very common there are multimeters with RS-232 interface and one has to send a D = 44 (hex) = 01000100 (bin) to receive any data
so you can try to sniff the virtual COM port ( RS-232 protocol ) directly using a RS-232 sniffer, i.e. https://www.eltima.com/rs232-sniffer.html
alternatively you can try is to sniff the underlying USB traffic with wireshark ( or usbmon in linux ) and extract the payload from the USB packets to record the communication between the windows driver and ther device
https://ask.wireshark.org/question/36/how-to-capture-usb-packets-please/
https://www.youtube.com/watch?v=EfkC7kmIMt8 ( USB in Wireshark )
https://www.kernel.org/doc/Documentation/usb/usbmon.txt
( https://www.kernel.org/doc/html/v4.13/driver-api/usb/URB.html )
i wanted to ask you guys, if it is possible to use the Raspberry Pi as a transmitter from a audio source, lets say a TV for example.
I want to send the sound from the TV to the Raspberry Pi via audio Jack and then send the sound via Bluetooth to a wireless speaker. So the Rasberry should act like a bridge between TV and the speaker.
It should look like this in the end:
TV --Sound via audio jack--> Raspberry Pi ~~Sound via Bluetooth~~>
speaker
So, if there is a way, how can i do this ? Thanks in advance
RPi doen't have audio input. You need one of these adapter like this (http://raspberry-projects.com/pi/pi-hardware/audio-input) and connect input to TV and RPi output to wireless / bluetooth speakers. I haven't tried it yet. Let me your feedback.
Since a web search might bring others here as it did me, here's how I did this connecting my record player through a Raspberry Pi 3 to a Bose Portable Home/Smart Speaker.
Get an audio input into the Pi
I used a cheap USB soundcard bought on Adafruit
Identify your new PulseAudio input/source and note name
This can be done by calling pactl list sources (mine was identifiable from its name and description)
$ pactl list sources
...
Source #2
State: RUNNING
Name: alsa_input.usb-GeneralPlus_USB_Audio_Device-00.mono-fallback
Description: USB Audio Device Mono
...
Connect your Pi to your bluetooth speaker
Run sudo bluetoothctl (running this without sudo resulted in settings being forgotten upon reboot) and enter the commands below
(Optional) Give your Pi an alias when connecting over bluetooth: [bluetooth]# system-alias 'Your New BT Alias'
Enter scanning mode [bluetooth]# scan on
Put your speaker in pairing mode and wait for it to be listed in the rolling output. E.g.
[NEW] Device AA:AA:AA:AA:AA:AA AA-AA-AA-AA-AA-AA
[NEW] Device BB:BB:BB:BB:BB:BB BB-BB-BB-BB-BB-BB
[NEW] Device CC:CC:CC:CC:CC:CC My speaker's name
Pair with it referencing its address:
[bluetooth]# pair CC:CC:CC:CC:CC:CC
Attempting to pair with CC:CC:CC:CC:CC:CC
[CHG] Device CC:CC:CC:CC:CC:CC Connected: yes
Request confirmation
[agent] Confirm passkey 123456 (yes/no): yes
Connect to the speaker now
[bluetooth]# connect CC:CC:CC:CC:CC:CC
Attempting to connect to CC:CC:CC:CC:CC:CC
[CHG] Device CC:CC:CC:CC:CC:CC Connected: yes
Connection successful
Trust the speaker so it is automatically connected to when available
[My speaker's name]# trust CC:CC:CC:CC:CC:CC
[CHG] Device CC:CC:CC:CC:CC:CC Trusted: yes
Changing CC:CC:CC:CC:CC:CC trust succeeded
Note your bluetooth speaker's associated PulseAudio output/sink name
This can be done by calling pactl list sinks (again, should be identifiable by name and description)
$ pactl list sinks
...
Sink #2
State: RUNNING
Name: bluez_sink.CC_CC_CC_CC_CC_CC.a2dp_sink
Description: My speaker's name
...
Set up PulseAudio defaults
Identify a good volume level for your input so distortion is minimal. E.g.
pactl set-source-volume alsa_input.usb-GeneralPlus_USB_Audio_Device-00.mono-fallback 16000
Add your version of the following lines to /etc/pulse/default.pa to set up an audio loopback and ensure the correct devices (based on the names you noted above) are used by default:
### Make some devices default
set-default-sink bluez_sink.60_AB_D2_57_42_A9.a2dp_sink
set-default-source alsa_input.usb-GeneralPlus_USB_Audio_Device-00.mono-fallback
# Set up loopback
load-module module-loopback latency_msec=1
# Set input volume
set-source-volume alsa_input.usb-GeneralPlus_USB_Audio_Device-00.mono-fallback 16000
I'm using two Bluetooth adaptors with BlueZ, both are the same device but with different types of antenna, is there any method to find out which usb port the identifier on BlueZ (hci0/hci1) is referring to?
I can discover the MAC address of the device through hcitool dev, so if there was a way to discover which USB port the adaptor with that MAC address was connected to, that would also solve my problem.
As both the adaptors are the same model, lsusb does not provide any identifying information I can use.
Using Ubuntu 16.04. I am looking for a solution in any form, whether it is a shell command or java/C/python/etc.
This answer should point you in the right direction, though doesn't give you a complete solution.
You should be able to use the contents of the "sys" filesystem, under /sys/class/bluetooth:
$ ls -lA /sys/class/bluetooth/
total 0
lrwxrwxrwx 1 root root 0 Dec 8 09:35 hci0 -> ../../devices/platform/soc/3f980000.usb/usb1/1-1/1-1.3/1-1.3:1.0/bluetooth/hci0
lrwxrwxrwx 1 root root 0 Dec 8 09:35 hci1 -> ../../devices/platform/soc/3f201000.serial/tty/ttyAMA0/hci1
That's from my Raspberry Pi, with a builtin adapter on the /dev/ttyAMA0 UART interface, and an added Bluetooth adapter on USB. The information in the symlink target technically tells you which physical port the adapter is plugged into.
If you're not familiar with the convention for USB device numbering (which forms a tree of nodes, since a port can have a USB hub with multiple additional ports, etc), look under /sys/bus/usb/devices, and match that up with the "lsusb" output and you should figure it out. In my case, "lsusb" shows that adapter as "Bus 001 Device 004: ID 0a5c:21e8 Broadcom Corp. BCM20702A0 Bluetooth 4.0", which if I recall corresponds to the "1-3" stuff in the /sys/class/bluetooth path (where unfortunately it appears the bus value uses index origin 1, while the device number uses index origin 0 so the 4 turns into a 3 there).
If you experiment with moving your USB adapter around to different physical ports, you should be able to work out the pattern.
I don't know if this is what you need, but you should find detailed information about the devices attached through the following command:-
hciconfig -a
This will give you enough details to identify the specific devices. You can add this in a shell script and use some string manipulation and conditionals to figure out your devices.
In my case, I have one BT dongle connected, and running hciconfig -a give the following output:-
hci0: Type: BR/EDR Bus: USB
BD Address: 00:16:A4:06:AC:E6 ACL MTU: 310:10 SCO MTU: 64:8
UP RUNNING
RX bytes:670 acl:0 sco:0 events:46 errors:0
TX bytes:2495 acl:0 sco:0 commands:46 errors:0
Features: 0xff 0xff 0xcf 0xfe 0xdb 0xff 0x5b 0x87
Packet type: DM1 DM3 DM5 DH1 DH3 DH5 HV1 HV2 HV3
Link policy: RSWITCH HOLD SNIFF PARK
Link mode: SLAVE ACCEPT
Name: 'youssif'
Class: 0x0c0000
Service Classes: Rendering, Capturing
Device Class: Miscellaneous,
HCI Version: 4.0 (0x6) Revision: 0x22bb
LMP Version: 4.0 (0x6) Subversion: 0x22bb
Manufacturer: Cambridge Silicon Radio (10)
If this is not sufficient, you can use also use a combination of lsusb and hciconfig commands to figure out which device is connected to what port.
I have connected two data cards in my server. One is connected in port dev/ttyUSB2. I want to find the other's port.
There are four ports
ttyUSB0,
ttyUSB1,
ttyUSB2,
ttyUSB3.
I already tried lsusb -vv and found out this:
Bus 001 Device 005: ID 19d2:2003
You can look it up in dmesg logs
dmesg|less