UAC扬声器同步传输URB数据结构USBD_ISO_PACKET_DESCRIPTOR成员StartFrame
凡是USB的数据设备的数据传输,都是通过URB实现的。
在Windows系统中,凡是同步传输,都是通过URB_ISOCH_TRANSFER实现的。
当然,本站也提供了一个USB同步传输X64 URB数据在线分析工具:https://www.usbzh.com/tool/urb-iso.html
URB_ISOCH_TRANSFER的结构体定义如下:
struct _URB_ISOCH_TRANSFER {
struct _URB_HEADER Hdr;
USBD_PIPE_HANDLE PipeHandle;
ULONG TransferFlags;
ULONG TransferBufferLength;
PVOID TransferBuffer;
PMDL TransferBufferMDL;
struct _URB *UrbLink;
struct _URB_HCD_AREA hca;
ULONG StartFrame;
ULONG NumberOfPackets;
ULONG ErrorCount;
USBD_ISO_PACKET_DESCRIPTOR IsoPacket[1];
};
这个对构体的成员相对来说,都比较容易理解。但StartFrame成员总有一个模糊不清。
StartFrame官方的解释如下:
Specifies the frame number that the transfer should begin on. This variable must be within a system-defined range of the current frame. The range is specified by the constant USBD_ISO_START_FRAME_RANGE.
If START_ISO_TRANSFER_ASAP is set in TransferFlags, this member contains the frame number that the transfer began on, when the request is returned by the host controller driver. Otherwise, this member must contain the frame number that this transfer begins on.
可见StartFrame指定了数据传输开始的frame numbe,前且必须当前帧的系统定义范围内。数据范围在USBD_ISO_START_FRAME_RANGE之内。
#define USBD_ISO_START_FRAME_RANGE 1024
另外,如果TransferFlags中设置了START_ISO_TRANSFER_ASAP,那么表示的是传输的开始编号。https://docs.microsoft.com/en-us/windows-hardware/drivers/usbcon/transfer-data-to-isochronous-endpoints
#define USBD_SHORT_TRANSFER_OK 0x00000002
#define USBD_START_ISO_TRANSFER_ASAP 0x00000004
#define USBD_DEFAULT_PIPE_TRANSFER 0x00000008
这里我们通过BUSHOUND来抓包进行原始数据分析:
27.0 URB 88 00 08 00 00 00 00 00 98 f3 d4 14 fd 3e 00 00 00 00 00 00 00 00 00 00 c0 4c 98 f2 02 c1 ff ff
0a 00 00 00 03 00 00 00 38 6b ff 9b 03 f5 ff ff 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
04 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 02 00 00 00 01 00 00 00 a8 8a a0 fa 02 c1 ff ff
a8 8a a0 fa 02 c1 ff ff 88 53 4f ec 02 c1 ff ff 18 8a a0 fa 02 c1 ff ff 00 00 00 00 00 00 00 00
22 01 00 01 02 00 03 00
27.2 192 ISOC 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00
27.2 URB a4 00 0a 00 00 00 00 00 98 f3 d4 14 fd 3e 00 00 00 00 00 00 00 00 00 00 90 8c 29 ed 02 c1 ff ff
04 00 00 00 c0 00 00 00 30 9a 34 ef 02 c1 ff ff 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
02 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
53 b0 3c 01 01 00 00 00 00 00 00 00
27.2 1920 ISOC 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00
27.2 URB 10 01 0a 00 00 00 00 00 98 f3 d4 14 fd 3e 00 00 00 00 00 00 00 00 00 00 90 8c 29 ed 02 c1 ff ff
04 00 00 00 80 07 00 00 90 f0 78 72 81 95 ff ff 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
02 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
54 b0 3c 01 0a 00 00 00 00 00 00 00
27.2 1920 ISOC 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00
从一个USB扬声器来看,其打开的时候,第一个音频数据的长度为192字节,其只有1ms的数据量,其StartFrame为53 b0 3c 01。我们做个表格来分析:
包 | 数据长度 | StartFrame |
---|---|---|
1 | 192 | 53 b0 3c 01 |
2 | 1920 | 54 b0 3c 01 |
3 | 920 | 5e b0 3c 01 |
4 | 920 | 68 b0 3c 01 |
5 | 1920 | 72 b0 3c 01 |
可以看到,这个StatFrame变成了NumberOfPackets的计数了。
而过一段时间之后。我们停止该扬声器的工作,过一段时间之间,再次打开,发现StartFrame又从另一个计数:
f9 25 42 01开始计数。
所以从这里来看,StartFrame又像是一个系统的时间计数。
其实我在虚拟MIC的时候,重新打开MIC的时候,将第一包的StartFrame清0开始,也是可以的。所以最后我想说的是,我信你个鬼,你个糟老头子坏地很。