FTDI USB串行转换器创建的监视(嗅探)/dev/ttyUSB0 [英] Monitoring (Sniffing) /dev/ttyUSB0 created by FTDI USB Serial Converter

查看:511
本文介绍了FTDI USB串行转换器创建的监视(嗅探)/dev/ttyUSB0的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想监视(嗅探)由FTDI USB串行转换器创建的/dev/ttyUSB0的流量.我已经在Windows中编写了自己的应用程序,现在尝试将其移植到linux并使用/dev/tty/USB0.我想调试实际发生的通信.

I want to monitor (sniff) the traffic of my /dev/ttyUSB0 which is created by FTDI USB Serial Converter. I've written my own application in Windows and now I try to port it to linux and use /dev/tty/USB0. I want to debug the communication that actually happens.

我无法选择strace软件,因为它仅显示对ioctl的系统调用.

The software strace is not an option for me because it only shows the syscalls to ioctl.

使用Windows软件"Free Serial Port Monitor"通过嗅探COM1来做到这一点.

Using Windows the software "Free Serial Port Monitor" did it by sniffing COM1.

dmesg的输出:

[16975.000221] usb 7-1: new full-speed USB device number 5 using  uhci_hcd
[16975.193543] usb 7-1: New USB device found, idVendor=0403, idProduct=6001
[16975.193548] usb 7-1: New USB device strings: Mfr=1, Product=2, SerialNumber=3
[16975.193552] usb 7-1: Product: FT232R USB UART
[16975.193555] usb 7-1: Manufacturer: FTDI
[16975.193558] usb 7-1: SerialNumber: A400BJII
[16975.200550] ftdi_sio 7-1:1.0: FTDI USB Serial Device converter detected
[16975.200599] usb 7-1: Detected FT232RL
[16975.202604] usb 7-1: FTDI USB Serial Device converter now attached to ttyUSB0

但是,我尝试使用moserial来执行此操作,并尝试使用命令"echo foobar>/dev/ttyUSB0"进行验证,是否可以正常使用.另外,我的软件没有创建moserial的输出.

However I tried moserial to do this and the command "echo foobar > /dev/ttyUSB0" to verify, if it works. Also my software doesn't create an output to moserial.

更新:

了解了如何直接监视USB的方法,现在我需要将USB数据包转换为RS-232(FTDI的基本作用).

Found out how to monitor usb directly, now I need to convert USB packets to RS-232 (what FTDI basically does).

  1. 设置usbmon

  1. Setup usbmon

1.1对于2.6.23之前的Linux内核,您还需要运行此命令

1.1 With Linux kernels prior to 2.6.23, you will also need to run this command

usbmon0将监视从所有usbmon0到usbmonX的任何流量 2.1.找到正确的USB设备

usbmon0 will monitor any traffic from all usbmon0 to usbmonX 2.1. Find the correct usb device

T:  Bus=07 Lev=01 Prnt=01 Port=00 Cnt=01 Dev#= 12 Spd=12   MxCh= 0
D:  Ver= 2.00 Cls=00(>ifc ) Sub=00 Prot=00 MxPS= 8 #Cfgs=  1
P:  Vendor=0403 ProdID=6001 Rev= 6.00
S:  Manufacturer=FTDI
S:  Product=FT232R USB UART
S:  SerialNumber=A400BJII
C:* #Ifs= 1 Cfg#= 1 Atr=a0 MxPwr= 90mA
I:* If#= 0 Alt= 0 #EPs= 2 Cls=ff(vend.) Sub=ff Prot=ff Driver=ftdi_sio
E:  Ad=81(I) Atr=02(Bulk) MxPS=  64 Ivl=0ms
E:  Ad=02(O) Atr=02(Bulk) MxPS=  64 Ivl=0ms

2.2.注意端口的总线号(Bus = 07),因此要监视的usbmon将是usbmon7

2.2. Note Bus number of the port (Bus=07), so usbmon to monitor will be usbmon7

2.3.使用wireshark捕获usbmon7界面,或使用以下命令将输出输出到控制台(stdout)...将数字替换为bus-id

2.3. Use wireshark to capture the usbmon7 interface or use following command to get output to the console (stdout) ... replace the number with bus-id

"u"是什么意思? https://www.kernel.org/doc/Documentation/usb/usbmon. txt

What means 'u'? https://www.kernel.org/doc/Documentation/usb/usbmon.txt

当前支持两种格式:原始格式(即"1t"格式)和"1u"格式.内核2.6.21中不赞成使用"1t"格式. '1u'格式添加了一些字段,例如ISO帧描述符,间隔等.它会产生稍长的行,但否则是'1t'格式的完美超集.

Two formats are supported currently: the original, or '1t' format, and the '1u' format. The '1t' format is deprecated in kernel 2.6.21. The '1u' format adds a few fields, such as ISO frame descriptors, interval, etc. It produces slightly longer lines, but otherwise is a perfect superset of '1t' format.

如何将USB捕获转换为RS-232捕获? 我不知道... TODO

How do I convert the USB capture to RS-232 capture? I don't know it ... TODO

推荐答案

有了您的提示,我设法解决了我的问题,所以最后一点是我的提示:

With your hint I managed to solve my problem, so there it is my hint for the last point:

  1. 使用Wireshark,打开usbmon0并使用此过滤器

  1. Using Wireshark, open usbmon0 and use this filter

usb.capdata or at

发出两次命令echo asd > /dev/ttyUSB0会在Wireshark中产生以下结果

Issuing two times the command echo asd > /dev/ttyUSB0 produces the result below in Wireshark

您可以使用tshark从捕获文件中提取整个剩余的捕获数据:

You can extract the whole Leftover Capture Data from a capture file using tshark:

tshark -r capture.pcapng -T fields -e usb.capdata

这篇关于FTDI USB串行转换器创建的监视(嗅探)/dev/ttyUSB0的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆