Analyzing Serial data over USB on Linux - linux

I have a USB to RS232 adapter which I'm currently using to communicate with a legacy device. I want to analyze the data going to and from the legacy device from my Ubuntu machine over USB. The adapter is getting detected automatically without installing any driver as shown in lsusb output below:
Bus 006 Device 002: ID 0403:6001 Future Technology Devices International, Ltd FT232 USB-Serial (UART) IC
I tried using the USB packet capture in Wireshark, but it shows a bunch of URB_CONTROL, URB_BULK packets which is not showing anything meaningful. So if there are any better utilities available which can capture the USB2Serial data for a Linux system, please let me know. TIA!

After trying various methods, I finally got what I needed using strace. The following command helped me capture all the termios settings for the serial port and also all the IOCTL calls after doing some greps on the file handle of the serial port:
sudo strace -p <pid> -t -v -o dump.txt
This will dump all the system calls that your application makes on Linux into the file dump.txt.

Related

Why doesn't Zaber device show up in dev directory?

My Zaber device is X-MCB2, which is connected to my computer through USB. Command lsusb can show its information as below, but cannot find it in /dev directory.
Bus 003 Device 023: ID 2939:495b
There is another Arduino device connected to my computer as well. Unlike Zaber device, this Arduino device works well, its name in /dev is ttyACM0.
Even if I plugged out the Arduino device, the Zaber device still does NOT show up in /dev directory.
My linux kernel is 2.6.32, and this Zaber device shouldn't need additional driver.
I resolved this issue according to the following link: https://github.com/arduino/Arduino/issues/1389.
echo "0x2939 0x495b" > /sys/bus/usb/drivers/cdc_acm/new_id
Thanks for posting your answer Jeff.
The likely cause of the issue is that Zaber controllers implement USB using CDC ACM, and set 0 for the Protocol field of the USB interface descriptor (indicating that the device doesn't accept AT commands).
In Linux 2.6.32, the CDC ACM kernel driver, which should handle devices
of this type, is written in such a way that it doesn’t take control of
devices whose Protocol field is 0 (instead it has a specific list of
Protocol numbers which it accepts, but that list does not include 0). Instead, you must manually attach it as in the posted solution.
This issue was fixed in kernel 2.6.36.
Here are a list of the commands that will manually attach the Zaber controllers with USB:
X-MCB2:
echo "0x2939 0x495b" > /sys/bus/usb/drivers/cdc_acm/new_id
X-MCB1:
echo "0x2939 0x495a" > /sys/bus/usb/drivers/cdc_acm/new_id
A-MCB2:
echo "0x2939 0x459" > /sys/bus/usb/drivers/cdc_acm/new_id

Enumerate commands available for a usb chip in fedora 24

I am learning to program a USB device (iBall 3.5g USB Dongle) using libusb.h header library.
Until now I am able to identify my device using the Vendor ID and also open the device for operation.
As a next step I would like to know the available commands (or the controls) for example : command to scan the surroundings for available GSM networks.
Obviously I will have to talk to the devices' firmware to extract the necessary information.
I tried to search for the technical datasheet for the 3g dongle, but couldn't find any.
The dongle is powered by a Qualcomm chip
Do you know any of the methods in which I can get the control commands for a usb device ?
Thanks in advance.
There is no simple procedure for figuring out what commands a USB device has. You need to use a combination of looking at the descriptors reported by the device, seeing if the device supports any particular USB device class, reading the USB specification, and maybe doing some reverse engineering using a protocol analyzer.
A good first step would be for you to use lsusb -v to print human-readable descriptions of the device's USB descriptors.

Print TTY Stream to Terminal

I have a usb device. The driver for said device (a generic USB to UART driver for that chipset) sets up a ttyUSB0 stream for interfacing with the device. I am trying to understand how the data from this device is formatted. Is it possible to display that stream, live, on my terminal (something like piping to stdout)?
This device is running on a limited embedded system. The system uses a Linux 2.6 kernel and busybox shell, so I can't simply install applications like a serial terminal, and many cli programs which are default on most distros (such as screen) aren't available on my system.
Use cat.
cat /dev/ttyUSB0
If it's not setup correctly, do it with stty. For example to set baud rate:
stty -F /dev/ttyUSB0 115200

How do I intercept messages from a USB device on Linux?

I have a popular drawing tablet that I connect to my PC with USB. Once connected, the tablet detects hand movements and manipulates the pointer accordingly. Somewhere, the tablet is transmitting this data to my computer.
My goal is to intercept these transmissions and manipulate the mouse after I process the data. The buzzwords I have found are: device drivers and HID, but I haven't been able to piece together much more than that.
Assuming this is possible, I have a few questions:
How is this done if the data format is known?
How is this done if the data format is unknown/proprietary?
My computer is running Ubuntu (but answers related to any form of a Linux OS are greatly appreciated!).
Note: This question is similar but intended for Windows.
Actually you missed a buzzword "USB sniffing". ;-)
Here are a few tutorials on USB sniffing on Linux, to get you started.
Official Wireshark wiki for USB monitoring
biot.com/blog/usb-sniffing-on-linux (InternetArchive)
tjworld.net/wiki/Linux/Ubuntu/USBmonitoring
Essentially you use the usbmon Linux kernel module to capture the USB-packets and Wireshark as a front-end to display and analyse the captured USB stream.
To add another useful resource: Kernel manual for usbmon
You can use the following commands on Debian Linux to view debug log for usbmon in text format using usbmon Kernel's built in usb monitoring:
$sudo -i to use root
#modprobe usbmon
#ls /sys/kernel/debug/usb/usbmon to view bus sockets
#cat /sys/kernel/debug/usb/devices to view devices at each bus socket
#cat /sys/kernel/debug/usb/usbmon/<bus socket> to view or you can route stdout to a file using >

How can I figure out which tty file points to which USB-to-Serial device?

I have two legacy machines connected to a Linux box with USB using the ftdi_sio driver, to /dev/ttyUSB0 and /dev/ttyUSB1. The Linux box is relaying and analyzing the traffic between the machines. When the Linux box boots up, the machines are connected to the files pretty much randomly. The problem is to know which one is which.
I could just ask the devices, of course, but I'd like to avoid the risk of malfunction due to sending wrong data to the wrong device. Is there a way to figure out, for example, the id of the device connected to a tty file?
Check this Using Linux USB page.
/proc/bus/usb/devices lists information about the devices currently attached to the USB bus. This is very useful when trying to figure out if the device is correctly enumerated.
Maybe you can use the output from lsusb -v and look at iProduct + iSerial to determine the order the devices are attached.

Resources