USB笔记 接口描述符 (Interface Descriptor)
接口描述符(Interface Descriptor)描述了配置中一个特定的接口。配置提供了一个或多个接口,每个接口都含有类(Class),子类(SubClass)和协议(Protocol)的信息,以及接口所使用的端点(Endpoint)数目。
接口描述符(Interface Descriptor)总是作为配置描述符的一部分返回,不能直接用Get Descriptor
或者Set Descriptor
请求访问。
一个配置可含有多个同时活跃的接口。这些接口可能联合于某个功能,也可能并不相关。
每个接口都有它自己的接口描述符(Interface Descriptor)和附属描述符(subordinate descriptor)。
所有这些接口也都可拥有一个或多个替代的接口设置(alternate interface settings)。这些设置是相互排他的,每次只能有一个被激活。每个设置含有一个接口描述符(Interface Descriptor)及所的附属描述符(subordinate descriptor)。使用等时传输(isochronous transfers)的设备必须有替代接口设置(alternate interface settings),因为缺省的接口不能请求等时带宽(isochronous bandwidth)。
Interface Descriptor
Offset | Field | Size | Value | Description |
---|---|---|---|---|
0 | bLength | 1 | Number | 以字节为单位的描述符大小 |
1 | bDescriptorType | 1 | Constant | 接口描述符类型 |
2 | bInterfaceNumber | 1 | Number | 接口的编号 |
3 | bAlternateSetting | 1 | Number | 用来确认bInterfaceNumber的替代设置的编号 |
4 | bNumEndpoints | 1 | Number | 接口使用的端点数量 |
5 | bInterfaceClass | 1 | Class | 类码 |
6 | bInterfaceSubClass | 1 | SubClass | 子类码 |
7 | bInterfaceProtocol | 1 | Protocol | 协议码 |
8 | iInterface | 1 | Index | 接口字符串描述符的索引 |
bLength以字节为单位的描述符大小(0x09)。
bDescriptorType接口描述符类型,为INTERFACE(0x04)。
bInterfaceNumber接口的编号。表示该配置同时支持的接口序列索引。编号的值从0开始,缺省值为0x00。每个接口描述符中,该字段取值必须唯一。在组合设备(composite device )的配置中拥有多个同时活动的接口。
bAlternateSetting用来确认bInterfaceNumber的替代设置的编号。对于每个bInterfaceNumber ,设备将提供一个bAlternateSetting 字段为0x00的接口描述字,这是缺省的设置。替代设置的描述符bInterfaceNumber
字段与缺省设备的值是相同的,但是bAlternateSetting
的值不同,然后替代设置的描述符的最后5个字节的取值也会根据实际情况而不同。
对于每个bInterfaceNumber
,每次只有一个bAlternateSetting
可被激活。替代设置可使主机能够请求带有不同带宽或其他要求和性能的接口。Get Interface
请求会取得当前被激活的bAlternateSetting
。Set Interface
请求可选择特定bInterfaceNumber
所应当使用的bAlternateSetting
。
bNumEndpoints这个接口使用的端点数量(不包括端点0)。如果这个值为0,那么这个接口使用默认的控制管道(Control Pipe),既只使用端点0。
bInterfaceClass类码(Class code),这个类码(Class code)由USB-IF分配。除了用于由接口规定的设备外,其他与设备描述符(Device Descriptor)中bDeviceClass 字段相同。
值0x00为保留值,从0x01 – 0xFE的值保留给USB定义的类,0xFF作为厂商定义的类。
Class Code | Description |
---|---|
0x00 | 保留(Reserved) |
0x01 | 音频(Audio) |
0x02 | 通讯设备:通讯接口(Communications device: communication interface) |
0x03 | 人机接口设备(Human interface device) |
0x05 | 物理(Physical) |
0x06 | 图像(Image) bInterfaceSubclass = 0x01 bInterfaceProtocol = 0x01: Imaging device |
0x07 | 打印机(Printer) |
0x08 | 大容量存储(Mass storage) |
0x09 | 集线器(Hub) (还必须在设备描述符(device descriptor)中声明 ) |
0x0A | 通讯设备:数据接口(Communications device: data interface) |
0x0B | 智能卡(Smart Card) |
0x0D | 内容安全(Content Security) bInterfaceSubclass = 0x01 bInterfaceProtocol = 0x01: Content security device |
0x0E | 视频(Video) |
0x0F | 个人健康设备(Personal healthcare device) (can instead be declared at the device level) |
0x10 | Audio/Video (AV): bInterfaceSubclass = 0x01 bInterfaceProtocol = 0x00: AVControl Interface bInterfaceSubclass = 0x02 bInterfaceProtocol = 0x00: AVData Video Streaming Interface bInterfaceSubclass = 0x03 bInterfaceProtocol = 0x00: AVData Audio Streaming Interface |
0xDC | 诊断设备Diagnostic device (can instead be declared at the device level) bInterfaceSubclass= 0x01 bInterfaceProtocol = 0x01: USB2 compliance device |
0xE0 | 无线控制器Wireless controller bInterfaceSubclass = 0x01 bInterfaceProtocol = 0x01: Bluetooth programming interface (should also be declared at the device level) bInterfaceProtocol = 0x02: UWB Radio control interface (Wireless USB) bInterfaceProtocol = 0x03: RNDIS bInterfaceProtocol = 0x04: Bluetooth AMP controller (should also be declared at the device level) bInterfaceSubclass = 0x02: Host and device wire adapters (Wireless USB) bInterfaceProtocol = 0x01: Host wire adapter control/data interface bInterfaceProtocol = 0x02: Device wire adapter control/data interface bInterfaceProtocol = 0x03: Device wire adapter isochronous interface |
0xEF | 各种各样的Miscellaneous bInterfaceSubclass = 0x01 bInterfaceProtocol = 0x01: active sync bInterfaceProtocol = 0x02: Palm sync bInterfaceSubclass = 0x02 bInterfaceProtocol = 0x01: Interface Association Descriptor bInterfaceProtocol = 0x02: Wire Adapter Multifunction Peripheral programming interface bInterfaceSubclass = 0x03: Cable based association framework (Wireless USB) bInterfaceProtocol = 0x01: Cable based association framework device bInterfaceSubclass = 0x04 bInterfaceProtocol = 0x01: RNDIS over Ethernet bInterfaceProtocol = 0x02: RNDIS over WiFi bInterfaceProtocol = 0x03: RNDIS over Maxim bInterfaceProtocol = 0x04: RNDIS over WWAN bInterfaceProtocol = 0x05: RNDIS for Raw IPv4 bInterfaceProtocol = 0x06: RNDIS for Raw IPv6 bInterfaceProtocol = 0x07: RNDIS for GPRS bInterfaceSubclass = 0x05: Machine vision device (USB3 Vision) bInterfaceProtocol = 0x00: USB3 Vision Control Interface bInterfaceProtocol = 0x01: USB0 Vision Event Interface bInterfaceProtocol = 0x02: USB3 Vision Streaming Interface |
0xFE | 应用程序专属Application specific bInterfaceSubclass = 0x01: Device firmware upgrade bInterfaceSubclass = 0x02: IrDA bridge bInterfaceSubclass = 0x03: Test and measurement (USBTMC) bInterfaceProtocol = 0x00: Complies with USBTMC spec bInterfaceProtocol = 0x01: Complies with USBTMC USB488 subclass |
0xFF | 厂商专属Vendor specific (can instead be declared at the device level) |
bInterfaceSubClass子类码(SubClass code),这个子类码(SubClass code)由USB-IF分配。这个值由bInterfaceClass
字段所限定。除了带有由接口定义的类的设备之外,此字段与设备描述符(Device Descriptor)中的bDeviceSubClass字段相同。如果bInterfaceClass
等于0x00,则bInterfaceSubClass也必须等于0x00。如果bIntefaceClass
是0x01–0xFE范围的值,则bInterfaceSubClass等于0x00或等于一个为接口的类定义的码。0xFF表明为厂商定义的子类(SubClass)。
bInterfaceProtocol协议码(Protocol code),这个协议码(Protocol code)由USB-IF分配。这个值由bInterfaceClass
字段和bInterfaceSubClass
字段所限定。如果接口支持专用的类型请求,这个协议码能识别出由协议类型规范定义、设备使用的协议。如果bInterfaceClass
等于0x00,设备在这个接口不使用专门的类协议。如果为0xFF,设备在这个接口使用专用的厂商协议。除了带有由接口定义的类的设备之外,此字段与设备描述符(Device Descriptor)中的bDeviceProtocol
字段相同。如果bIntefaceClass
是0x01–0xFE范围的值,则bInterfaceProtocol 等于0x00或等于一个为接口的类定义的码。
iInterface描述这个接口的字符串描述符的索引。如果没有字符串描述符的话则此值为0。
获取接口描述符
主机通过发送Get Descriptor
请求,取得配置描述符,接口描述符,端点描述符及其附属描述符。
接口描述符(Interface Descriptor)总是作为配置描述符Configuration 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) |
下面举例说明一个获取接口描述符的过程。
获取一个键盘的接口描述符,该键盘的接口描述符如下所示:
使用USB分析仪抓包可以看到,获取配置描述符Configuration Descriptor,而接口描述符Interface Descriptor就包含在其中:
接口描述符Interface Descriptor的获取过程如下:
再展开看到详细的过程:
接下来详细看整个获取过程的各个字段含义:
一开始的setup包过程:
setup data:
IN包过程
OUT包过程:
完成整个接口描述符Interface Descriptor的获取。
描述符示例
这里举例一个带有该描述符的示例设备,这是一个键盘Keyboard的完整描述符信息。
Device Descriptor
Offset | Field | Size | Value | Description |
---|---|---|---|---|
0 | bLength | 1 | 0x12 | |
1 | bDescriptorType | 1 | 0x01 | DEVICE |
2 | bcdUSB | 2 | 0x0110 | 1.10 |
4 | bDeviceClass | 1 | 0x00 | |
5 | bDeviceSubClass | 1 | 0x00 | |
6 | bDeviceProtocol | 1 | 0x00 | |
7 | bMaxPacketSize0 | 1 | 0x08 | |
8 | idVendor | 2 | 0x046d | |
10 | idProduct | 2 | 0xc31c | |
12 | bcdDevice | 2 | 0x6400 | 64.00 |
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 | 0x003b | |
4 | bNumInterfaces | 1 | 0x02 | |
5 | bConfigurationValue | 1 | 0x01 | |
6 | iConfiguration | 1 | 0x03 | |
7 | bmAttributes | 1 | 0xa0 | |
8 | bMaxPower | 1 | 0x2d |
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 | 0x03 | Human Interface Device |
6 | bInterfaceSubClass | 1 | 0x01 | Boot Interface |
7 | bInterfaceProtocol | 1 | 0x01 | Keyboard |
8 | iInterface | 1 | 0x02 |
HID Descriptor
Offset | Field | Size | Value | Description |
---|---|---|---|---|
0 | bLength | 1 | 0x09 | |
1 | bDescriptorType | 1 | 0x21 | HID |
2 | bcdHID | 2 | 0x0110 | 1.10 |
4 | bCountryCode | 1 | 0x00 | |
5 | bNumDescriptors | 1 | 0x01 | |
6 | bDescriptorType | 1 | 0x22 | REPORT |
7 | wDescriptorLength | 2 | 0x0041 |
Endpoint Descriptor
Offset | Field | Size | Value | Description |
---|---|---|---|---|
0 | bLength | 1 | 0x07 | |
1 | bDescriptorType | 1 | 0x05 | ENDPOINT |
2 | bEndpointAddress | 1 | 0x81 | 1 IN |
3 | bmAttributes | 1 | 0x03 | Interrupt |
4 | wMaxPacketSize | 2 | 0x0008 | |
6 | bInterval | 1 | 0x0a |
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 | 0x01 | |
5 | bInterfaceClass | 1 | 0x03 | Human Interface Device |
6 | bInterfaceSubClass | 1 | 0x00 | |
7 | bInterfaceProtocol | 1 | 0x00 | |
8 | iInterface | 1 | 0x02 |
HID Descriptor
Offset | Field | Size | Value | Description |
---|---|---|---|---|
0 | bLength | 1 | 0x09 | |
1 | bDescriptorType | 1 | 0x21 | HID |
2 | bcdHID | 2 | 0x0110 | 1.10 |
4 | bCountryCode | 1 | 0x00 | |
5 | bNumDescriptors | 1 | 0x01 | |
6 | bDescriptorType | 1 | 0x22 | REPORT |
7 | wDescriptorLength | 2 | 0x009f |
Endpoint Descriptor
Offset | Field | Size | Value | Description |
---|---|---|---|---|
0 | bLength | 1 | 0x07 | |
1 | bDescriptorType | 1 | 0x05 | ENDPOINT |
2 | bEndpointAddress | 1 | 0x82 | 2 IN |
3 | bmAttributes | 1 | 0x03 | Interrupt |
4 | wMaxPacketSize | 2 | 0x0004 | |
6 | bInterval | 1 | 0xff |
附录
USB1.x/USB 2.0/USB 3.x Interface Descriptor
Offset | Field | Size | Value | Description |
---|---|---|---|---|
0 | bLength | 1 | Number | Size of this descriptor in bytes |
1 | bDescriptorType | 1 | Constant | INTERFACE Descriptor Type |
2 | bInterfaceNumber | 1 | Number | Number of this interface. Zero-based value identifying the index in the array of concurrent interfaces supported by this configuration. |
3 | bAlternateSetting | 1 | Number | Value used to select this alternate setting for the interface identified in the prior field. |
4 | bNumEndpoints | 1 | Number | Number of endpoints used by this interface (excluding endpoint zero). If this value is zero, this interface only uses the Default Control Pipe. |
5 | bInterfaceClass | 1 | Class | Class code (assigned by the USB-IF). A value of zero is reserved for future standardization. If this field is set to FFH, the interface class is vendor-specific. All other values are reserved for assignment by the USB-IF. |
6 | bInterfaceSubClass | 1 | SubClass | Subclass code (assigned by the USB-IF). These codes are qualified by the value of the bInterfaceClass field. If the bInterfaceClass field is reset to zero, this field must also be reset to zero. If the bInterfaceClass field is not set to FFH, all values are reserved for assignment by the USB-IF. |
7 | bInterfaceProtocol | 1 | Protocol | Protocol code (assigned by the USB). These codes are qualified by the value of the bInterfaceClass and the bInterfaceSubClass fields. If an interface supports class-specific requests, this code identifies the protocols that the device uses as defined by the specification of the device class. If this field is reset to zero, the device does not use a class-specific protocol on this interface. If this field is set to FFH, the device uses a vendor-specific protocol for this interface. |
8 | iInterface | 1 | Index | Index of string descriptor describing this interface. |
[参考资料]
Universal Serial Bus Specification Revision 1.0
Universal Serial Bus Specification Revision 1.1
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 Complete, 5th Edition
USB开发大全
USB2.0与OTG规范及开发指南
本文链接:https://blog.csdn.net/u012028275/article/details/109567196