当前位置: 首页 > news >正文

MCU_WireShark USB抓包内容解析

WireShark是个非常不错的工具,现在的版本已经集成了测试USB抓包的工具USBPcap,该工具官网在,

https://desowin.org/usbpcap/

抓包的格式在这里有说明

https://desowin.org/usbpcap/captureformat.html

具体内容我附在后面,方便查找。

重点要注意的是,USBPcap pseudoheader(伪头)不属于发送内容部分,是USBPcap控制程序的部分,这个Pseudoheader后面的部分,才是真正要发送或接收到的内容。这也是很多人刚开始抓包的时候,主要让人迷糊的地方。

例子如下,

 

这个例子里面,USB URB 就是这个Pseudoheader,占0x1C=28个字节,后面的80060001 00001200才是真正发送的内容,也就是URB setup。

同样,下面这个例子里面,

 

前面28个字节也是Pesudoheader,不属于发送内容(称之为控制相关信息是否更恰当?),真正从USB-device接收到的内容是后在的18个字节。这个内容就不解释了,USB规范2.0表(Table 9-8. Standard Device Descriptor)中已有详细规定,下载地址在这里,

https://usb.org/sites/default/files/usb_20_20190524.zip

如果你对这些包的内容的发送与解析感兴趣,建议参考

https://docs.microsoft.com/en-us/windows-hardware/drivers/usbcon/usb-control-transfer

例如TOKEN   PACKET的格式是这样的,

注意:(1) 一般(如HANDSHAKE PACKET/TOKEN PACKET/DATA PACKET)的包中的某些信息SYN/PID/EOP等等信息,一般情况下在硬件底层会自动处理掉,不会涉及到操作系统的层次,在我们用单片机编程时,一般也不会涉及。

(2) USB的传输方式(USB transfer types)有四种类型:bulk, isochronous, interrupt, control, 相关知识点太多,这里就不展开了,图文并茂的解释大致如下图所示,

附上一些参考

USBPcap Capture format specification.

https://desowin.org/usbpcap/captureformat.html

Following document describes the LINKTYPE_USBPCAP used in USBPcap. This merely describes the packet data mentioned in pcap file format.

General notes

The types presented below are described in Windows DDK 7.1.0. Short description:

  • UCHAR - 8 bit unsigned value

  • USHORT - 16 bit unsigned value

  • UINT32 - 32 bit unsigned value

  • UINT64 - 64 bit unsigned value

  • ULONG - 64 bit unsigned value

  • USBD_STATUS - 32 bit unsigned value

All multi-byte values are LITTLE-ENDIAN.

Base packet header

The USBPCAP_BUFFER_PACKET_HEADER as defined in USBPcapBuffer.h:

#pragma pack(1)
typedef struct
{
    USHORT       headerLen; /* This header length */
    UINT64       irpId;     /* I/O Request packet ID */
    USBD_STATUS  status;    /* USB status code
                               (on return from host controller) */
    USHORT       function;  /* URB Function */
    UCHAR        info;      /* I/O Request info */
​
    USHORT       bus;       /* bus (RootHub) number */
    USHORT       device;    /* device address */
    UCHAR        endpoint;  /* endpoint number and transfer direction */
    UCHAR        transfer;  /* transfer type */
​
    UINT32       dataLength;/* Data length */
} USBPCAP_BUFFER_PACKET_HEADER, *PUSBPCAP_BUFFER_PACKET_HEADER;
  • headerLen (offset 0) describes the total length, in bytes, of the header (including all transfer-specific header data).

  • irpId (offset 2) is merely a pointer to IRP casted to the UINT64. This value can be used to match the request with respons.

  • status (offset 10) is valid only on return from host-controller. This field corrensponds to the Status member of _URB_HEADER

  • function (offset 14) corrensponds to the Function member of _URB_HEADER

  • info (offset 16) is descibed on the bit-field basis. Currently only the least significant bit (USBPCAP_INFO_PDO_TO_FDO) is defined: it is 0 when IRP goes from FDO to PDO, 1 the other way round. The remaining bits are reserved and must be set to 0.

  • bus (offset 17) is the root hub identifier used to distingush between multiple root hubs.

  • device (offset 19) is USB device number. This field is, contary to the USB specification, 16-bit because the Windows uses 16-bits value for that matter. Check DeviceAddress field of USB_NODE_CONNECTION_INFORMATION

  • endpoint (offset 21) is the endpoint number used on the USB bus (the MSB describes transfer direction)

  • transfer (offset 22) determines the transfer type and thus the header type. See below for details.

  • dataLength (offset 23) specifies the total length of transfer data to follow directly after the header (at offset headerLen).

Transfer-specific headers

All transfer-specific headers inherit the USBPCAP_BUFFER_PACKET_HEADER, so first there is the USBPCAP_BUFFER_PACKET_HEADER, then (if any) additional transfer-specific header data and then the transfer data.

USBPCAP_TRANSFER_ISOCHRONOUS

When transfer is equal to USBPCAP_TRANSFER_ISOCHRONOUS (0) the header type is USBPCAP_BUFFER_ISOCH_HEADER

/* Note about isochronous packets:
 *   packet[x].length, packet[x].status and errorCount are only relevant
 *   when USBPCAP_INFO_PDO_TO_FDO is set
 *
 *   packet[x].length is not used for isochronous OUT transfers.
 *
 * Buffer data is attached to:
 *   * for isochronous OUT transactions (write to device)
 *       Requests (USBPCAP_INFO_PDO_TO_FDO is not set)
 *   * for isochronous IN transactions (read from device)
 *       Responses (USBPCAP_INFO_PDO_TO_FDO is set)
 */
#pragma pack(1)
typedef struct
{
    ULONG        offset;
    ULONG        length;
    USBD_STATUS  status;
} USBPCAP_BUFFER_ISO_PACKET, *PUSBPCAP_BUFFER_ISO_PACKET;
​
#pragma pack(1)
typedef struct
{
    USBPCAP_BUFFER_PACKET_HEADER  header;
    ULONG                         startFrame;
    ULONG                         numberOfPackets;
    ULONG                         errorCount;
    USBPCAP_BUFFER_ISO_PACKET     packet[1];
} USBPCAP_BUFFER_ISOCH_HEADER, *PUSBPCAP_BUFFER_ISOCH_HEADER;

USBPCAP_TRANSFER_INTERRUPT

When transfer is equal to USBPCAP_TRANSFER_INTERRUPT (1) the header type is USBPCAP_BUFFER_PACKET_HEADER

USBPCAP_TRANSFER_CONTROL

When transfer is equal to USBPCAP_TRANSFER_CONTROL (2) the header type is USBPCAP_BUFFER_CONTROL_HEADER

/* USBPcap versions before 1.5.0.0 recorded control transactions as two
 * or three pcap packets:
 *   * USBPCAP_CONTROL_STAGE_SETUP with 8 bytes USB SETUP data
 *   * Optional USBPCAP_CONTROL_STAGE_DATA with either DATA OUT or IN
 *   * USBPCAP_CONTROL_STAGE_STATUS without data on IRP completion
 *
 * Such capture was considered unnecessary complex. Due to that, since
 * USBPcap 1.5.0.0, the control transactions are recorded as two packets:
 *   * USBPCAP_CONTROL_STAGE_SETUP with 8 bytes USB SETUP data and
 *     optional DATA OUT
 *   * USBPCAP_CONTROL_STAGE_COMPLETE without payload or with the DATA IN
 *
 * The merit behind this change was that Wireshark dissector, since the
 * very first time when Wireshark understood USBPcap format, was really
 * expecting the USBPCAP_CONTROL_STAGE_SETUP to contain SETUP + DATA OUT.
 * Even if Wireshark version doesn't recognize USBPCAP_CONTROL_STAGE_COMPLETE
 * it will still process the payload correctly.
 */
#define USBPCAP_CONTROL_STAGE_SETUP    0
#define USBPCAP_CONTROL_STAGE_DATA     1
#define USBPCAP_CONTROL_STAGE_STATUS   2
#define USBPCAP_CONTROL_STAGE_COMPLETE 3
​
#pragma pack(1)
typedef struct
{
    USBPCAP_BUFFER_PACKET_HEADER  header;
    UCHAR                         stage;
} USBPCAP_BUFFER_CONTROL_HEADER, *PUSBPCAP_BUFFER_CONTROL_HEADER;

Where stage determines the control transfer stage.

USBPCAP_TRANSFER_BULK

When transfer is equal to USBPCAP_TRANSFER_BULK (3) the header type is USBPCAP_BUFFER_PACKET_HEADER

相关文章:

  • MCU_Wireshark USB 抓包过滤(抓特定端口地址)
  • STM32F4xx usb库源码详解 custom HID
  • STM32F4xx usb库源码详解:HAL_PCDEx_SetRxFiFo 和 HAL_PCDEx_SetTxFiFo
  • Libuv 1.34.2 源码详解 ---- 以uvCat为例讲解
  • 步进电机的细分驱动中1-2相, W1-2相, 2W1-2相, 4W1-2相 表示什么意思?
  • MCU_关于STM32Fxxx中断EXTI产生时多次(两次)进入中断的原因
  • MCU_通过windows串口API控制RTS和DTR
  • MCU_STM32的HAL库中的宏DMA_FLAG_TCIF0_4/DMA_FLAG_TCIF1_5/DMA_FLAG_TCIF2_6/DMA_FLAG_TCIF3_7
  • LWIP_TCP如何理解数据发送,何时使用tcp_recved函数
  • MCU_使用STM32CUBEMX配置STM32F107/407 RMII-ETHERNET要注意的细节:PHY Address和MCO时钟
  • MCU_STM32CUBEMX v5.5.0的一个BUG:ethernetif_input引起进入HardFault_Handler
  • MCU_STM32CUBEMX配置生成CAN2的初始化代码的修改
  • MCU_STM32F4xx使用CCM RAM
  • MCU_C语言中 数组型指针 的应用 -- char (*stringp)[]
  • Anaconda 安装yaml
  • const let
  • Object.assign方法不能实现深复制
  • 二维平面内的碰撞检测【一】
  • 分布式任务队列Celery
  • 给初学者:JavaScript 中数组操作注意点
  • 给新手的新浪微博 SDK 集成教程【一】
  • 极限编程 (Extreme Programming) - 发布计划 (Release Planning)
  • 将回调地狱按在地上摩擦的Promise
  • 每天一个设计模式之命令模式
  • 爬虫进阶 -- 神级程序员:让你的爬虫就像人类的用户行为!
  • 手机端车牌号码键盘的vue组件
  • 温故知新之javascript面向对象
  • 一个SAP顾问在美国的这些年
  • 关于Kubernetes Dashboard漏洞CVE-2018-18264的修复公告
  • 继 XDL 之后,阿里妈妈开源大规模分布式图表征学习框架 Euler ...
  • 树莓派用上kodexplorer也能玩成私有网盘
  • # 执行时间 统计mysql_一文说尽 MySQL 优化原理
  • #宝哥教你#查看jquery绑定的事件函数
  • #每日一题合集#牛客JZ23-JZ33
  • #我与Java虚拟机的故事#连载07:我放弃了对JVM的进一步学习
  • (2)STM32单片机上位机
  • (3)选择元素——(17)练习(Exercises)
  • (C#)一个最简单的链表类
  • (C语言版)链表(三)——实现双向链表创建、删除、插入、释放内存等简单操作...
  • (done) NLP “bag-of-words“ 方法 (带有二元分类和多元分类两个例子)词袋模型、BoW
  • (iPhone/iPad开发)在UIWebView中自定义菜单栏
  • (八十八)VFL语言初步 - 实现布局
  • (笔试题)分解质因式
  • (第9篇)大数据的的超级应用——数据挖掘-推荐系统
  • (简单有案例)前端实现主题切换、动态换肤的两种简单方式
  • (三) diretfbrc详解
  • (四)linux文件内容查看
  • (提供数据集下载)基于大语言模型LangChain与ChatGLM3-6B本地知识库调优:数据集优化、参数调整、Prompt提示词优化实战
  • (幽默漫画)有个程序员老公,是怎样的体验?
  • (转)Sublime Text3配置Lua运行环境
  • (转)大型网站的系统架构
  • ./indexer: error while loading shared libraries: libmysqlclient.so.18: cannot open shared object fil
  • .[backups@airmail.cc].faust勒索病毒的最新威胁:如何恢复您的数据?
  • .NET WebClient 类下载部分文件会错误?可能是解压缩的锅
  • .NET 药厂业务系统 CPU爆高分析