【USB筆記】配置描述符Configuration Descriptor

dadalaohua發表於2020-11-08

USB筆記 配置描述符(Configuration Descriptor)

配置描述符(Configuration Descriptor)說明了一個特定配置的相關資訊。取得裝置描述符(Device Descriptor)後,主機就可以繼續去獲取裝置的配置、介面和端點描述符。當主機請求配置描述符(Configuration Descriptor)時,返回的是所有相關的介面和端點描述符。

一個USB裝置有一個或多個配置描述符(Configuration Descriptor)。配置描述符描述了配置所提供的介面數量。每個介面可以獨立操作。每種配置有一個或多個介面,而且每個介面有零個或多個端點。在一個配置中,介面不會共享一個端點,除非端點被相同介面的備用設定使用。沒有這一限制、屬於不同配置的介面可以共享端點。

配置描述符(Configuration Descriptor)規定了裝置的特徵和能力。典型地,單個配置已經足夠了,但在驅動程式的支援下,帶有多應用或多電源選擇的裝置可支援多重配置。且每次只有一個配置被啟用。每個配置需要一個配置描述符,其中含有關於裝置電源使用及所支援介面數的資訊。每個配置描述符都有附屬描述符,包括一個或多個介面描述符以及可選的端點描述符。

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.

bLength以位元組為單位的描述符大小。

bDescriptorType配置描述符型別,為CONFIGURATION (0x02)。

wTotalLength該配置返回的資料總長度。包括該配置返回的所有描述符(配置、介面、端點、和專用的型別或者專用的廠商描述符)的總長度。

bNumInterfaces這個配置支援的介面數量,其最小值為0x01。

bConfigurationValue確認Get Configuration 和Set Configuration請求的配置,且必須為0x01或者更高值。取值為0的Set Configuration請求會使裝置進入未配置狀態(Not Configured state )。

iConfiguration描述這個配置的字串描述符索引。若沒有字串描述符,此值為0。

bmAttributes是配置特性。如果bit 6 = 1,此時裝置是自供電(selfpowered )的;若由匯流排供電,則設為0。如果裝置支援遠端喚起特性(remote wakeup feature ),Bit 5 = 1。這種特性使被掛起的USB裝置能將想要通訊的願望通知給主機。
此欄位中的其他位元位未被使用。Bits 4…0必須是0。為了與USB1.0相容,Bit 7必須等於1。

bMaxPower當裝置完全執行時,特定配置的USB裝置從匯流排取得的最大功耗。對於usb2.0,bMaxPower 以2mA為單位。如果裝置要求200ma,則bMaxPower = 100 (0x64)。對於超高速應用,bMaxPower 以8mA為單位。裝置可請求的最大匯流排電流是:對於USB2.0為500mA;對於超高速應用為900mA。若所請求的電流不可用,主機將拒絕對裝置進行配置。然後,如果有代替的配置可用,驅動程式將發出請求。
當裝置和主機支援USB Power Delivery Rev. 2.0, v1.0,主機可以從另一個描述符檢索裝置的電源需求。

獲取配置描述符

主機通過傳送Get Descriptor請求,且使設定事務中wvalue 欄位的高位元組等於0x02、wLength 欄位等於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的獲取。

[參考資料]

Universal Serial Bus Specification Revision 2.0

Universal Serial Bus 3.0 Specification

Universal Serial Bus 3.1 Specification

USB Complete, 5th Edition

USB開發大全

USB2.0與OTG規範及開發指南

相關文章