【USB笔记】配置描述符Configuration Descriptor

USB笔记 配置描述符(Configuration Descriptor)

配置描述符(Configuration Descriptor)说明了一个特定配置的相关信息。取得设备描述符(Device Descriptor)后,主机就可以继续去获取设备的配置、接口和端点描述符。当主机请求配置描述符(Configuration Descriptor)时,返回的是所有相关的接口和端点描述符。

一个USB设备有一个或多个配置描述符(Configuration Descriptor)。配置描述符描述了配置所提供的接口数量。每个接口可以独立操作。每种配置有一个或多个接口,而且每个接口有零个或多个端点。在一个配置中,接口不会共享一个端点,除非端点被相同接口的备用设置使用。没有这一限制、属于不同配置的接口可以共享端点。

配置描述符(Configuration Descriptor)规定了设备的特征和能力。一般单个配置已经足够了,但在驱动程序的支持下,带有多应用或多电源选择的设备可支持多重配置。且每次只有一个配置被激活。每个配置需要一个配置描述符,其中含有关于设备电源使用及所支持接口数的信息。每个配置描述符都有附属描述符(subordinate descriptor),包括一个或多个接口描述符(Interface Descriptor)以及可选的端点描述符(Endpoint Descriptor)。

Configuration Descriptor

OffsetFieldSizeValueDescription
0bLength1Number以字节为单位的描述符大小
1bDescriptorType1Constant配置描述符类型
2wTotalLength2Number配置返回的数据总长度
4bNumInterfaces1Number配置支持的接口数量
5bConfigurationValue1NumberGet Configuration 和Set Configuration请求的配置值
6iConfiguration1Index字符串描述符索引
7bmAttributes1Bitmap配置特性
8bMaxPower1mA设备从总线获取的最大功耗

bLength以字节为单位的描述符大小(0x09)。

bDescriptorType配置描述符类型,为CONFIGURATION (0x02)。

wTotalLength配置返回的数据总长度。包括该配置返回的所有描述符(配置、接口、端点、和专用的类型或者专用的厂商描述符)的总长度。

bNumInterfaces这个配置支持的接口数量,最小值为0x01。

bConfigurationValue确认Get Configuration 和Set Configuration请求的配置,且必须为0x01或者更高值。取值为0的Set Configuration请求会使设备进入未配置状态(Not Configured state)。

iConfiguration描述这个配置的字符串描述符索引。若没有字符串描述符,这个字段的值为0。

bmAttributes配置特性。

Bit 7:USB1.0协议中表示总线供电(Bus Powered),设置Bit 7 = 1表示由总线供电(Bus Powered)。其他协议该位保留(Reserved),必须设置为1。

Bit 6:自供电(Self-powered)。如果Bits 6 = 1,设备是自供电(Self-powered)的。

Bit 5 :远程唤醒(Remote Wakeup)。如果Bit 5 = 1,设备支持远程唤醒。

Bits 4…0:未使用,保留,必须为0。

bMaxPower当设备完全运行时,特定配置的USB设备从总线取得的最大功耗。

对于usb2.0,bMaxPower 以2mA为单位。如果设备要求200ma,则bMaxPower = 100 (0x64)。设备可请求的最大总线电流500mA。

对于增强型超高速(Enhanced SuperSpeed)设备,bMaxPower以8mA为单位。如果设备要求200ma,则bMaxPower = 25(0x19)。设备可请求的最大总线电流900mA。

当设备和主机支持USB Power Delivery Rev. 2.0,主机可以从PD Class Specific Descriptors检索设备的电源需求。

获取配置描述符

主机通过发送Get Descriptor请求,取得配置描述符及其附属描述符。

Get DescriptorValue
bmRequestType0x80
  bmRequestType.Recipient0b00000(Device)
  bmRequestType.Type0b00(Standard)
  bmRequestType.Direction0b1(Device-to-Host)
bRequest0x06(Get Descriptor)
wValue0x0200(Configuration #0)
wIndex0x0000
wLength0x???(wTotalLength)

下面举例说明一个获取配置描述符Configuration Descriptor的过程。使用USB分析仪抓包,软件Total Phase Data Center。
配置描述符Configuration Descriptor如下所示:
0

使用USB分析仪抓包可以看到,获取配置描述符Configuration Descriptor:
1

配置描述符Configuration Descriptor的获取过程如下:

2

再展开看到详细的过程:
3

接下来详细看整个获取过程的各个字段含义:
4
一开始的setup包过程:
5

setup data:
6

IN包过程
7

OUT包过程:
8

完成整个配置描述符Configuration Descriptor的获取。


描述符示例

这里举例一个带有该描述符的示例设备,这是一个键盘Keyboard的完整描述符信息。

Device Descriptor

OffsetFieldSizeValueDescription
0bLength10x12
1bDescriptorType10x01DEVICE
2bcdUSB20x01101.10
4bDeviceClass10x00
5bDeviceSubClass10x00
6bDeviceProtocol10x00
7bMaxPacketSize010x08
8idVendor20x046d
10idProduct20xc31c
12bcdDevice20x640064.00
14iManufacturer10x01
15iProduct10x02
16iSerialNumber10x00
17bNumConfigurations10x01

Configuration Descriptor

OffsetFieldSizeValueDescription
0bLength10x09
1bDescriptorType10x02CONFIGURATION
2wTotalLength20x003b
4bNumInterfaces10x02
5bConfigurationValue10x01
6iConfiguration10x03
7bmAttributes10xa0
8bMaxPower10x2d

Interface Descriptor

OffsetFieldSizeValueDescription
0bLength10x09
1bDescriptorType10x04INTERFACE
2bInterfaceNumber10x00
3bAlternateSetting10x00
4bNumEndpoints10x01
5bInterfaceClass10x03Human Interface Device
6bInterfaceSubClass10x01Boot Interface
7bInterfaceProtocol10x01Keyboard
8iInterface10x02

HID Descriptor

OffsetFieldSizeValueDescription
0bLength10x09
1bDescriptorType10x21HID
2bcdHID20x01101.10
4bCountryCode10x00
5bNumDescriptors10x01
6bDescriptorType10x22REPORT
7wDescriptorLength20x0041

Endpoint Descriptor

OffsetFieldSizeValueDescription
0bLength10x07
1bDescriptorType10x05ENDPOINT
2bEndpointAddress10x811 IN
3bmAttributes10x03Interrupt
4wMaxPacketSize20x0008
6bInterval10x0a

Interface Descriptor

OffsetFieldSizeValueDescription
0bLength10x09
1bDescriptorType10x04INTERFACE
2bInterfaceNumber10x01
3bAlternateSetting10x00
4bNumEndpoints10x01
5bInterfaceClass10x03Human Interface Device
6bInterfaceSubClass10x00
7bInterfaceProtocol10x00
8iInterface10x02

HID Descriptor

OffsetFieldSizeValueDescription
0bLength10x09
1bDescriptorType10x21HID
2bcdHID20x01101.10
4bCountryCode10x00
5bNumDescriptors10x01
6bDescriptorType10x22REPORT
7wDescriptorLength20x009f

Endpoint Descriptor

OffsetFieldSizeValueDescription
0bLength10x07
1bDescriptorType10x05ENDPOINT
2bEndpointAddress10x822 IN
3bmAttributes10x03Interrupt
4wMaxPacketSize20x0004
6bInterval10xff

附录

USB1.1/USB 2.0 Configuration Descriptor

OffsetFieldSizeValueDescription
0bLength1NumberSize of this descriptor in bytes
1bDescriptorType1ConstantCONFIGURATION Descriptor Type
2wTotalLength2NumberTotal length of data returned for this configuration. Includes the combined length of all descriptors (configuration, interface,endpoint, and class- or vendor-specific)returned for this configuration.
4bNumInterfaces1NumberNumber of interfaces supported by this configuration
5bConfigurationValue1NumberValue to use as an argument to the SetConfiguration() request to select this configuration
6iConfiguration1IndexIndex of string descriptor describing this configuration
7bmAttributes1BitmapConfiguration characteristics
D7: Reserved (set to one)
D6: Self-powered
D5: Remote Wakeup
D4…0: Reserved (reset to zero)
D7 is reserved and must be set to one for
historical reasons.
A device configuration that uses power from the bus and a local source reports a non-zero value in bMaxPower to indicate the amount of bus power required and sets D6. The actual power source at runtime may be determined using the GetStatus(DEVICE) request (see Section 9.4.5).
If a device configuration supports remote wakeup, D5 is set to one.
8bMaxPower1mAMaximum power consumption of the USB device from the bus in this specific configuration when the device is fully operational. Expressed in 2 mA units (i.e., 50 = 100 mA).
Note: A device configuration reports whether the configuration is bus-powered or self-powered. Device status reports whether the device is currently self-powered. If a device is disconnected from its external power source, it updates device status to indicate that it is no longer self-powered.
A device may not increase its power draw from the bus, when it loses its external power source, beyond the amount reported by its configuration.
If a device can continue to operate when disconnected from its external power source, it continues to do so. If the device cannot continue to operate, it fails operations it can no longer support. The USB System Software may determine the cause of the failure by checking the status and noting the loss of the device’s power source.

USB 3.x Configuration Descriptor

OffsetFieldSizeValueDescription
0bLength1NumberSize of this descriptor in bytes
1bDescriptorType1ConstantCONFIGURATION Descriptor Type
2wTotalLength2NumberTotal length of data returned for this configuration. Includes the combined length of all descriptors (configuration, interface,endpoint, and class- or vendor-specific)returned for this configuration.
4bNumInterfaces1NumberNumber of interfaces supported by this configuration
5bConfigurationValue1NumberValue to use as an argument to the SetConfiguration() request to select this configuration
6iConfiguration1IndexIndex of string descriptor describing this configuration
7bmAttributes1BitmapConfiguration characteristics
D7: Reserved (set to one)
D6: Self-powered
D5: Remote Wakeup
D4…0: Reserved (reset to zero)
D7 is reserved and must be set to one for historical reasons.
A device configuration that uses power from the bus and a local source reports a non-zero value in bMaxPower to indicate the amount of bus power required and sets D6. The actual power source at runtime may be determined using the GetStatus(DEVICE) request (see Section 9.4.5).
If a device configuration supports remote wakeup, D5 is set to one.
8bMaxPower1mAMaximum power consumption of the device from the bus in this specific configuration when the device is fully operational. Expressed in 2-mA units when the device is operating in high-speed mode and in 8-mA units when operating at Gen X speed.(i.e., 50 = 100 mA when operating at high-speed and 50 = 400 mA when operating at Gen X speed).
Note: A device configuration reports whether the configuration is bus-powered or self-powered.
Device status reports whether the device is currently self-powered. If a device is disconnected from its external power source, it updates device status to indicate that it is no longer self-powered.
A device may not increase its power draw from the bus, when it loses its external power source, beyond the amount reported by its configuration.
If a device can continue to operate when disconnected from its external power source, it continues to do so. If the device cannot continue to operate, it shall return to the Powered state.

USB1.0 Configuration Descriptor

OffsetFieldSizeValueDescription
0bLength1NumberSize of this descriptor in bytes
1bDescriptorType1ConstantCONFIGURATION
2wTotalLength2NumberTotal length of data returned for this configuration. Includes the combined length of all descriptors (configuration, interface, endpoint, and class or vendor specific) returned for this configuration.
4bNumInterfaces1NumberNumber of interfaces supported by this configuration
5bConfigurationValue1NumberValue to use as an argument to Set Configuration to select this configuration
6iConfiguration1IndexIndex of string descriptor describing this configuration
7bmAttributes1BitmapConfiguration characteristics
D7 Bus Powered
D6 Self Powered
D5 Remote Wakeup
D4…0 Reserved (reset to 0)
A device configuration that uses power from the bus and a local source sets both D7 and D6. The actual power source at runtime may be determined using the Get Status device request.
If a device configuration supports remote wakeup, D5 is set to 1.
8bMaxPower1mAMaximum power consumption of USB device from the bus in this specific configuration when the device is fully operational.
Expressed in 2 mA units (i.e., 50 = 100 mA).
Note: A device configuration reports whether the configuration is bus-powered or self-powered. Device status reports whether the device is currently self-powered. If a device is disconnected from its external power source, it updates device status to indicate that it is no longer self-powered.
A device may not increase its power draw from the bus, when it loses its external power source, beyond the amount reported by its configuration.
If a device can continue to operate when disconnected from its external power source, it continues to do so. If the device cannot continue to operate, it fails operations it can no longer support. Host software may determine the cause of the failure by checking the status and noting the loss of the device’s power source.

[参考资料]

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

Universal Serial Bus Power Delivery Specification Revision 2.0, V1.2

USB Complete, 5th Edition

USB开发大全

USB2.0与OTG规范及开发指南


https://blog.csdn.net/u012028275/article/details/109280001

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值