USB笔记 设备限定描述符(Device Qualifier Descriptor)
设备限定描述符(Device Qualifier Descriptor)说明了能进行高速操作的设备在其他速度时产生的变化信息。例如,如果设备当前在全速下操作,设备限定描述符返回它如何在高速运行的信息。
如果设备既支持全速状态又支持高速状态,那么就必须含有设备限定描述符(Device Qualifier Descriptor)。设备限定描述符(Device Qualifier Descriptor)中含有当前没有使用的速度下这些字段的取值。
设备限定描述符(Device Qualifier Descriptor)不包含标准设备描述符中的厂商、产品、设备、制造厂商、产品和序列号场,因为在所有支持的速度下设备的这些信息都是常数。这个描述符的版本号至少是2.0(0200H)。
如果只能进行全速(full-speed)操作的设备(设备描述符的版本号等于0200H)接收到请求设备限定符的Get Descriptor请求,它必须用请求错误响应,回复STALL来响应。
主机端只能在成功取得设备限定描述符(Device Qualifier Descriptor)之后,才能请求其他速度配置(other_speed_configuration)描述符。
Device Qualifier Descriptor
Offset | Field | Size | Value | Description |
---|---|---|---|---|
0 | bLength | 1 | Number | 以字节为单位的描述符大小 |
1 | bDescriptorType | 1 | Constant | 设备限定描述符类型 |
2 | bcdUSB | 2 | BCD | USB规范发布的版本号 |
4 | bDeviceClass | 1 | Class | 类码 |
5 | bDeviceSubClass | 1 | SubClass | 子类码 |
6 | bDeviceProtocol | 1 | Protocol | 协议码 |
7 | bMaxPacketSize0 | 1 | Number | 其他速度的端点0最大包大小 |
8 | bNumConfigurations | 1 | Number | 其他速度配置的数量 |
9 | bReserved | 1 | Zero | 保留 |
bLength以字节为单位的描述符大小(0x0a)。
bDescriptorType设备限定描述符类型,为DEVICE_QUALIFIER (0x06)。
bcdUSB是设备所符合的USB规范的版本号,该值采用BCD(用二进制编码的十进制数)格式。如果要将这个数值转化为十进制数的话,,前面的1字节(8位)代表整数部分,接下来的4位代表十分位,最后4位代表百分位。USB 2.0是0x0200;USB 2.1是0x0210。
bDeviceClass类码。这个字段为那些在设备层次定义功能的设备规定了它们所属的类。
bDeviceSubClass子类码。这个字段规定一个类的子类
bDeviceProtocol协议码。这个字段为所选的类和子类规定一个协议。
bMaxPacketSize0为其他速度(Other-speed)的端点0最大包大小。
bNumConfigurations为其他速度(Other-speed)配置的数量。
bReserved保留到以后使用,必须为0。
获取设备限定描述符
主机会通过发送Get Descriptor
请求,取得设备限定描述符(Device Qualifier 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 | 0x0600(Configuration #0) |
wIndex | 0x0000 |
wLength | 0x000a |
下面举例说明一个获取设备限定描述符Device Qualifier Descriptor的过程。使用USB分析仪抓包,软件Total Phase Data Center。
设备限定描述符Device Qualifier Descriptor如下所示:
使用USB分析仪抓包可以看到,获取设备限定描述符Device Qualifier Descriptor:
设备限定描述符的获取过程如下:
再展开看到详细的过程:
接下来详细看整个获取过程的各个字段含义:
一开始的setup包过程:
setup data:
IN包过程:
OUT包过程:
完成整个设备限定描述符Device Qualifier Descriptor的获取。
不支持设备限定描述符的情况
如果设备不支持获取设备限定描述符,需要回复STALL来响应不支持的请求。
下面举例说明下不支持的情况如何正确响应:
如果不支持的话,使用USB分析仪抓包显示如下:
再展开看到详细的过程:
过程就只有IN包回复不同,看下IN包的详细回复过程,可以与上面的正常过程进行对比:
对比如下:
描述符示例
这里举例一个带有该描述符的示例设备。
Device Descriptor
Offset | Field | Size | Value | Description |
---|---|---|---|---|
0 | bLength | 1 | 0x12 | |
1 | bDescriptorType | 1 | 0x01 | DEVICE |
2 | bcdUSB | 2 | 0x0200 | 2.00 |
4 | bDeviceClass | 1 | 0x00 | |
5 | bDeviceSubClass | 1 | 0x00 | |
6 | bDeviceProtocol | 1 | 0x00 | |
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 | 0x03 | |
17 | bNumConfigurations | 1 | 0x01 |
Device Qualifier Descriptor
Offset | Field | Size | Value | Description |
---|---|---|---|---|
0 | bLength | 1 | 0x0a | |
1 | bDescriptorType | 1 | 0x06 | DEVICE_QUALIFIER |
2 | bcdUSB | 2 | 0x0200 | 2.00 |
4 | bDeviceClass | 1 | 0x00 | |
5 | bDeviceSubClass | 1 | 0x00 | |
6 | bDeviceProtocol | 1 | 0x00 | |
7 | bMaxPacketSize0 | 1 | 0x40 | |
8 | bNumConfigurations | 1 | 0x01 | |
9 | bReserved | 1 | 0x00 |
Configuration Descriptor
Offset | Field | Size | Value | Description |
---|---|---|---|---|
0 | bLength | 1 | 0x09 | |
1 | bDescriptorType | 1 | 0x02 | CONFIGURATION |
2 | wTotalLength | 2 | 0x00b1 | |
4 | bNumInterfaces | 1 | 0x04 | |
5 | bConfigurationValue | 1 | 0x01 | |
6 | iConfiguration | 1 | 0x00 | |
7 | bmAttributes | 1 | 0xC0 | |
8 | bMaxPower | 1 | 0x01 |
Interface Descriptor
Offset | Field | Size | Value | Description |
---|---|---|---|---|
0 | bLength | 1 | 0x09 | |
1 | bDescriptorType | 1 | 0x04 | INTERFACE |
… | … | … | … | … |
Endpoint Descriptor
Offset | Field | Size | Value | Description |
---|---|---|---|---|
0 | bLength | 1 | 0x07 | |
1 | bDescriptorType | 1 | 0x05 | ENDPOINT |
… | … | … | … | … |
省略中间的描述符。
Other_Speed_Configuration Descriptor
Offset | Field | Size | Value | Description |
---|---|---|---|---|
0 | bLength | 1 | 0x09 | |
1 | bDescriptorType | 1 | 0x07 | OTHER_SPEED_CONFIGURATION |
2 | wTotalLength | 2 | 0x00b1 | |
4 | bNumInterfaces | 1 | 0x04 | |
5 | bConfigurationValue | 1 | 0x01 | |
6 | iConfiguration | 1 | 0x00 | |
7 | bmAttributes | 1 | 0xC0 | |
8 | bMaxPower | 1 | 0x01 |
Interface Descriptor
Offset | Field | Size | Value | Description |
---|---|---|---|---|
0 | bLength | 1 | 0x09 | |
1 | bDescriptorType | 1 | 0x04 | INTERFACE |
… | … | … | … | … |
Endpoint Descriptor
Offset | Field | Size | Value | Description |
---|---|---|---|---|
0 | bLength | 1 | 0x07 | |
1 | bDescriptorType | 1 | 0x05 | ENDPOINT |
… | … | … | … | … |
后续描述符省略。
附录
USB2.0 Device Qualifier Descriptor
Offset | Field | Size | Value | Description |
---|---|---|---|---|
0 | bLength | 1 | Number | Size of descriptor |
1 | bDescriptorType | 1 | Constant | Device Qualifier Type |
2 | bcdUSB | 2 | BCD | USB specification version number (e.g.,0200H for V2.00 ) |
4 | bDeviceClass | 1 | Class | Class Code |
5 | bDeviceSubClass | 1 | SubClass | SubClass Code |
6 | bDeviceProtocol | 1 | Protocol | Protocol Code |
7 | bMaxPacketSize0 | 1 | Number | Maximum packet size for other speed |
8 | bNumConfigurations | 1 | Number | Number of Other-speed Configurations |
9 | bReserved | 1 | Zero | Reserved for future use, must be zero |
[参考资料]
Universal Serial Bus Specification Revision 2.0
USB Complete, 5th Edition
USB开发大全
USB2.0与OTG规范及开发指南