9.6.2 Configuration
The configuration descriptor describes information about a specific device configuration. The descriptor contains a bConfigurationValue field with a value that, when used as a parameter to the SetConfiguration() request, causes the device to assume the described configuration.
The descriptor describes the number of interfaces provided by the configuration. Each interface may operate independently. For example, an ISDN device might be configured with two interfaces, each providing 64kB/s bi-directional channels that have separate data sources or sinks on the host. Another configuration might present the ISDN device as a single interface, bonding the two channels into one 128kB/s bi-directional channel.
When the host requests the configuration descriptor, all related interface and endpoint descriptors are returned (refer to Section 9.4.2).
A USB device has one or more configuration descriptors. Each configuration has one or more interfaces and each interface has zero or more endpoints. An endpoint is not shared among interfaces within a single configuration unless the endpoint is used by alternate settings of the same interface. Endpoints may be shared among interfaces that are part of different configurations without this restriction.
Once configured, devices may support limited adjustments to the configuration. If a particular interface has alternate settings, an alternate may be selected after configuration. Table 9-8 shows the standard configuration descriptor.
9.6.2 配置
配置描述符描述了特定设备配置的信息。该描述符包含一个 bConfigurationValue 字段,当将此字段的值作为参数传递给 SetConfiguration() 请求时,将使设备采用所描述的配置。
该描述符说明了此配置所提供的接口数量。每个接口可以独立运行。例如,一个 ISDN 设备可能被配置为两个接口,每个接口提供 64 kB/s 的双向通道,这些通道在主机上具有独立的数据源或接收器。另一种配置可能将 ISDN 设备呈现为单个接口,将两个通道绑定为一个 128 kB/s 的双向通道。
当主机请求配置描述符时,所有相关的接口和端点描述符都将被返回(参见第 9.4.2 节)。
一个 USB 设备拥有一个或多个配置描述符。每个配置拥有一个或多个接口,每个接口拥有零个或多个端点。在一个配置内,端点不能在多个接口之间共享,除非该端点被同一接口的不同备用设置所使用。端点可以在属于不同配置的接口之间共享,不受此限制。
设备一旦完成配置,可能支持对配置进行有限的调整。如果某个特定接口具有备用设置,则可以在配置之后选择备用设置。表 9-8 显示了标准的配置描述符。
表 9-8. 标准配置描述符
| 偏移量 | 字段 | 大小 | 值类型 | 描述 | 
|---|---|---|---|---|
| 0 | bLength | 1 | 数字 | 本描述符的大小(以字节为单位) | 
| 1 | bDescriptorType | 1 | 常量 | 配置描述符类型 | 
| 2 | wTotalLength | 2 | 数字 | 此配置返回的数据总长度。包括为此配置返回的所有描述符(配置、接口、端点、类特定或厂商特定)的组合长度。 | 
| 4 | bNumInterfaces | 1 | 数字 | 此配置支持的接口数量 | 
| 5 | bConfigurationValue | 1 | 数字 | 作为 SetConfiguration() 请求的参数值,以选择此配置 | 
| 6 | iConfiguration | 1 | 索引 | 描述此配置的字符串描述符的索引 | 
| 7 | bmAttributes | 1 | 位图 | 配置特性  D7: 保留(设置为1) D6: 自供电 D5: 远程唤醒 D4…0: 保留(复位为零) 由于历史原因,D7 是保留位且必须设置为1。 一个既使用总线电源又使用本地电源的设备配置,应在 MaxPower 字段报告一个非零值以指示所需的总线功率,并设置 D6。运行时的实际电源可以使用 GetStatus(DEVICE) 请求来确定(参见第 9.4.5 节)。 如果设备配置支持远程唤醒,则 D5 设置为1。  | 
| 8 | MaxPower | 1 | 毫安 | USB 设备在此特定配置下完全运行时从总线获取的最大功耗。 以 2mA 为单位表示(例如,50 = 100mA)。  注意:设备配置会报告该配置是总线供电还是自供电。设备状态则报告设备当前是否是自供电。如果设备与其外部电源断开,它会更新设备状态以指示其不再是自供电。 当设备失去外部电源时,其从总线汲取的功率不得超过其配置所报告的数值。 如果设备在断开外部电源后仍能继续运行,它将继续这样做。如果设备无法继续运行,则它将停止其无法再支持的操作。USB 系统软件可以通过检查状态并注意设备电源的丢失来确定故障原因。  | 
