USB笔记 接口关联描述符 (Interface Association Descriptor)
接口关联描述符 (Interface Association Descriptor)(IAD),简称IAD,用于描述与同一功能相关联的两个或多个接口。
关联(association)
包括两个或多个接口及其所有备用设置接口。设备必须对需要多个接口的每个设备功能使用接口关联描述符 (Interface Association Descriptor)。接口关联描述符(Interface Association Descriptor)总是通过GetDescriptor(Configuration) 请求,作为配置信息的一部分返回。接口关联描述符 (Interface Association Descriptor)不能直接通过 GetDescriptor()或SetDescriptor()请求进行访问。接口关联描述符必须位于与其关联的接口的接口描述符集(包括所有备用设置接口)之前。所有关联接口集的接口号必须是连续的。
接口关联描述符包括功能类(Class)、子类(SubClass)和协议(Protocol)字段。这些字段中的值可以与任何关联接口的接口类(Class)、子类(SubClass)和协议(Protocol)的值相同。对于现有的设备类,首选实现是使用关联接口列表中第一个接口的接口类(Class)、子类(SubClass)和协议(Protocol)字段的值。
通过使用多个接口来管理单个设备功能的设备必须支持接口关联描述符 (Interface Association Descriptor)。早于Interface Association Descriptor(IAD)之前定义的类规范可以没有这个描述符。所有带有多个接口的超高速设备(Enhanced SuperSpeed devices),都必须使用IAD。
使用了IAD的设备,设备描述符中类(Class)、子类(SubClass)和协议(Protocol)的值必须定义成如下数值:
bDeviceClass = 0xEF (miscellaneous device class)
bDeviceSubClass = 0x02 (common class)
bDeviceProtocol = 0x01 (interface association descriptor)
USB2.0规范(The Universal Serial Bus Specification, revision 2.0)没有支持该描述符,不支持将设备的多个接口分组到单个设备功能中。该描述符是由USB-IF发布工程更改通知Engineering Change Notification (ECN),《USB ECN : Interface Association Descriptor》定义了该描述符与功能。
Windows系统从Microsoft Windows XP Service Pack 2 (SP2)版本开始支持IAD。
Interface Association Descriptor(IAD)
Offset | Field | Size | Value | Description |
---|---|---|---|---|
0 | bLength | 1 | Number | 以字节为单位的描述符大小 |
1 | bDescriptorType | 1 | Constant | 接口关联描述符类型 |
2 | bFirstInterface | 1 | Number | 与该功能关联的第一个接口的接口号 |
3 | bInterfaceCount | 1 | Number | 与该功能关联的连续接口的数量 |
4 | bFunctionClass | 1 | Class | 类码 |
5 | bFunctionSubClass | 1 | SubClass | 子类码 |
6 | bFunctionProtocol | 1 | Protocol | 协议码 |
7 | iFunction | 1 | Index | 字符串描述符索引 |
bLength以字节为单位的描述符大小 (0x08)。
bDescriptorType端点描述符类型,为INTERFACE_ASSOCIATION(0x0B)。
bFirstInterface 与该功能关联的第一个接口的接口号。接口号是接口描述符(Interface Descriptor)中bInterfaceNumber的值。 关联接口的接口号必须是连续的。
bInterfaceCount 与该功能关联的连续接口的数量。
bFunctionClass 类码(Class code),这个类码(Class code)由USB-IF分配。这个字段的值不能为0。如果这个字段的值为FFH,则功能类是厂商专属。其他所有值保留,由USB-IF分配。对于没有规定使用值的类,首选值是第一个关联接口的描述符中的bInterfaceClass的值。
bFunctionSubClass 子类码(SubClass code),这个子类码(SubClass code)由USB-IF分配。如果bFunctionClass值不是FFH,则表示其他所有值保留,由USB-IF分配。对于没有规定使用值的类,首选值是第一个关联接口的描述符中的bInterfaceSubClass的值。
bFunctionProtocol 协议码(Protocol code),这个协议码(Protocol code)由USB-IF分配。这个值受到bFunctionClass和bFunctionSubClass字段的限制。对于没有规定使用值的类,首选值是第一个关联接口的描述符中的bInterfaceProtocol的值。
iFunction 描述该功能的字符串描述符索引。若没有字符串描述符,这个字段的值为0。
获取接口关联描述符
主机通过发送Get Descriptor
请求,取得配置描述符,接口关联描述符,接口描述符,端点描述符及其附属描述符。接口关联描述符 (Interface Association Descriptor)总是作为配置描述符的一部分返回。
Get Descriptor | Value |
---|---|
bmRequestType | 0x80 |
bmRequestType.Recipient | 0b00000(Device) |
bmRequestType.Type | 0b00(Standard) |
bmRequestType.Direction | 0b1(Device-to-Host) |
bRequest | 0x06(Get Descriptor) |
wValue | 0x0200(Configuration #0) |
wIndex | 0x0000 |
wLength | 0x???(wTotalLength) |
下面举例说明一个获取接口关联描述符 (Interface Association Descriptor)的过程。使用USB分析仪抓包,软件Total Phase Data Center。
示例接口关联描述符 (Interface Association Descriptor)如下:
使用USB分析仪抓包可以看到,获取配置描述符Configuration Descriptor,而接口关联描述符 (Interface Association Descriptor)就包含在其中:
接口关联描述符 (Interface Association Descriptor)的获取过程如下:
再展开看到详细的过程:
完成整个接口关联描述符 (Interface Association Descriptor)的获取。
描述符示例
这里举例一个带有该描述符的示例设备。
Device Descriptor
Offset | Field | Size | Value | Description |
---|---|---|---|---|
0 | bLength | 1 | 0x12 | |
1 | bDescriptorType | 1 | 0x01 | DEVICE |
2 | bcdUSB | 2 | 0x0210 | 2.10 |
4 | bDeviceClass | 1 | 0xef | Miscellaneous |
5 | bDeviceSubClass | 1 | 0x02 | Common |
6 | bDeviceProtocol | 1 | 0x01 | Interface Association Descriptor |
7 | bMaxPacketSize0 | 1 | 0x40 | |
8 | idVendor | 2 | 0x046d | |
10 | idProduct | 2 | 0xc31c | |
12 | bcdDevice | 2 | 0x0001 | 0.01 |
14 | iManufacturer | 1 | 0x01 | |
15 | iProduct | 1 | 0x02 | |
16 | iSerialNumber | 1 | 0x00 | |
17 | bNumConfigurations | 1 | 0x01 |
Configuration Descriptor
Offset | Field | Size | Value | Description |
---|---|---|---|---|
0 | bLength | 1 | 0x09 | |
1 | bDescriptorType | 1 | 0x02 | CONFIGURATION |
2 | wTotalLength | 2 | 0x017d | |
4 | bNumInterfaces | 1 | 0x05 | |
5 | bConfigurationValue | 1 | 0x01 | |
6 | iConfiguration | 1 | 0x00 | |
7 | bmAttributes | 1 | 0x80 | |
8 | bMaxPower | 1 | 0xfa |
Interface Association Descriptor(IAD)
Offset | Field | Size | Value | Description |
---|---|---|---|---|
0 | bLength | 1 | 0x08 | |
1 | bDescriptorType | 1 | 0x0b | |
2 | bFirstInterface | 1 | 0x00 | |
3 | bInterfaceCount | 1 | 0x02 | |
4 | bFunctionClass | 1 | 0x0e | Video |
5 | bFunctionSubClass | 1 | 0x03 | Video Interface Collection |
6 | bFunctionProtocol | 1 | 0x00 | |
7 | iFunction | 1 | 0x00 |
Interface Descriptor
Offset | Field | Size | Value | Description |
---|---|---|---|---|
0 | bLength | 1 | 0x09 | |
1 | bDescriptorType | 1 | 0x04 | INTERFACE |
2 | bInterfaceNumber | 1 | 0x00 | |
3 | bAlternateSetting | 1 | 0x00 | |
4 | bNumEndpoints | 1 | 0x01 | |
5 | bInterfaceClass | 1 | 0x0e | Video |
6 | bInterfaceSubClass | 1 | 0x01 | Video Control |
7 | bInterfaceProtocol | 1 | 0x00 | |
8 | iInterface | 1 | 0x00 |
Video Interface Header Descriptor
Offset | Field | Size | Value | Description |
---|---|---|---|---|
0 | bLength | 1 | 0x0d | |
… | … | … | … | … |
省略中间的Video类描述符。
Interface Descriptor
Offset | Field | Size | Value | Description |
---|---|---|---|---|
0 | bLength | 1 | 0x09 | |
1 | bDescriptorType | 1 | 0x04 | INTERFACE |
2 | bInterfaceNumber | 1 | 0x01 | |
3 | bAlternateSetting | 1 | 0x00 | |
4 | bNumEndpoints | 1 | 0x00 | |
5 | bInterfaceClass | 1 | 0x0e | Video |
6 | bInterfaceSubClass | 1 | 0x02 | Video Streaming |
7 | bInterfaceProtocol | 1 | 0x00 | |
8 | iInterface | 1 | 0x00 |
Video Input Header Descriptor
Offset | Field | Size | Value | Description |
---|---|---|---|---|
0 | bLength | 1 | 0x0e | |
… | … | … | … | … |
后续描述符省略。
附录
USB2.0/USB3.x Interface Association Descriptor
Offset | Field | Size | Value | Description |
---|---|---|---|---|
0 | bLength | 1 | Number | Size of this descriptor in bytes. |
1 | bDescriptorType | 1 | Constant | INTERFACE ASSOCIATION Descriptor. |
2 | bFirstInterface | 1 | Number | Interface number of the first interface that is associated with this function. |
3 | bInterfaceCount | 1 | Number | Number of contiguous interfaces that are associated with this function. |
4 | bFunctionClass | 1 | Class | Class code (assigned by USB-IF). A value of zero is not allowed in this descriptor. If this field is FFH, the function class is vendor-specific. All other values are reserved for assignment by the USB-IF. |
5 | bFunctionSubClass | 1 | SubClass | Subclass code (assigned by USB-IF). If the bFunctionClass field is not set to FFH all values are reserved for assignment by the USB-IF. |
6 | bFunctionProtocol | 1 | Protocol | Protocol code (assigned by USB-IF). These codes are qualified by the values of the bFunctionClass and bFunctionSubClass fields. |
7 | iFunction | 1 | Index | Index of string descriptor describing this function. |
Example Device Descriptor Using Class Codes for IAD
Offset | Field | Size | Value | Description |
---|---|---|---|---|
0 | bLength | 1 | Number | Size of this descriptor in bytes |
1 | bDescriptorType | 1 | Constant | See Table 9-8, USB Specification, Revision 2.0 |
2 | bcdUSB | 2 | BCD | See Table 9-8, USB Specification, Revision 2.0 |
4 | bDeviceClass | 1 | EFH | Miscellaneous Device Class |
5 | bDeviceSubClass | 1 | 02H | Common Class |
6 | bDeviceProtocol | 1 | 01H | Interface Association Descriptor |
7 | bMaxPacketSize0 | 1 | Number | See Table 9-8, USB Specification, Revision 2.0 |
8 | idVendor | 2 | ID | See Table 9-8, USB Specification, Revision 2.0 |
10 | idProduct | 2 | ID | See Table 9-8, USB Specification, Revision 2.0 |
12 | bcdDevice | 2 | BCD | See Table 9-8, USB Specification, Revision 2.0 |
14 | iManufacturer | 1 | Index | See Table 9-8, USB Specification, Revision 2.0 |
15 | iProduct | 1 | Index | See Table 9-8, USB Specification, Revision 2.0 |
16 | iSerialNumber | 1 | Index | See Table 9-8, USB Specification, Revision 2.0 |
17 | bNumConfigurations | 1 | Number | See Table 9-8, USB Specification, Revision 2.0 |
Example Device Framework Using Interface Association Descriptors
[参考资料]
Universal Serial Bus Specification Revision 2.0
Universal Serial Bus 3.0 Specification
Universal Serial Bus 3.1 Specification
Universal Serial Bus 3.2 Specification
USB ECN : Interface Association Descriptor
USB Interface Association Descriptor Device Class Code and Use Model
USB Complete, 5th Edition
USB开发大全
USB2.0与OTG规范及开发指南
Microsoft USB Interface Association Descriptor
本文链接:https://blog.csdn.net/u012028275/article/details/109790166