9.6.3 Interface
This descriptor describes a specific interface within a configuration. A configuration provides one or more interfaces, each with zero or more endpoint descriptors describing a unique set of endpoints within the configuration. When a configuration supports more than one interface, the endpoints for a particular interface follow the interface descriptor in the data returned by the GetConfiguration() request. An interface descriptor is always returned as part of a configuration descriptor. Interface descriptors cannot be directly accessed with a GetDescriptor() or SetDescriptor() request.
An interface may include alternate settings that allow the endpoints and/or their characteristics to be varied after the device has been configured. The default setting for an interface is always alternate setting zero. The SetInterface() request is used to select an alternate setting or to return to the default setting. The GetInterface() request returns the selected alternate setting.
Alternate settings allow a portion of the device configuration to be varied while other interfaces remain in operation. If a configuration has alternate settings for one or more of its interfaces, a separate interface descriptor and its associated endpoints are included for each setting.
If a device configuration supported a single interface with two alternate settings, the configuration descriptor would be followed by an interface descriptor with the bInterfaceNumber and bAlternateSetting fields set to zero and then the endpoint descriptors for that setting, followed by another interface descriptor and its associated endpoint descriptors. The second interface descriptor’s bInterfaceNumber field would also be set to zero, but the bAlternateSetting field of the second interface descriptor would be set to one.
If an interface uses only endpoint zero, no endpoint descriptors follow the interface descriptor and the interface identifies a request interface that uses the default pipe attached to endpoint zero. In this case, the bNumEndpoints field shall be set to zero.
An interface descriptor never includes endpoint zero in the number of endpoints. Table 9-9 shows the standard interface descriptor.
9.6.3 接口
此描述符描述了某个配置内的一个特定接口。一个配置提供一个或多个接口,每个接口有零个或多个端点描述符,用于描述该配置内一组唯一的端点。当一个配置支持多个接口时,特定接口的端点描述符在 GetConfiguration() 请求返回的数据中紧随其接口描述符之后。接口描述符总是作为配置描述符的一部分被返回。不能使用 GetDescriptor() 或 SetDescriptor() 请求直接访问接口描述符。
一个接口可以包含备用设置,允许在设备配置完成后更改端点或其特性。接口的默认设置始终是备用设置零。SetInterface() 请求用于选择备用设置或返回到默认设置。GetInterface() 请求返回当前选中的备用设置。
备用设置允许在设备其他接口保持运行的同时,更改设备配置的一部分。如果一个配置为其一个或多个接口提供了备用设置,则每个设置都包含一个单独的接口描述符及其相关的端点描述符。
如果一个设备配置支持一个具有两个备用设置的接口,则配置描述符后面将跟随一个 bInterfaceNumber 和 bAlternateSetting 字段均设置为零的接口描述符,然后是针对该设置的端点描述符,之后再跟随另一个接口描述符及其相关的端点描述符。第二个接口描述符的 bInterfaceNumber 字段也将设置为零,但其 bAlternateSetting 字段将设置为一。
如果一个接口仅使用端点零,则接口描述符后面没有端点描述符,并且该接口标识了一个使用连接到端点零的默认管道的请求接口。在这种情况下,bNumEndpoints 字段应设置为零。
接口描述符在端点数量中从不包含端点零。表 9-9 显示了标准的接口描述符。
表 9-9. 标准接口描述符
| 偏移量 | 字段 | 大小 | 值类型 | 描述 | 
|---|---|---|---|---|
| 0 | bLength | 1 | 数字 | 本描述符的大小(以字节为单位) | 
| 1 | bDescriptorType | 1 | 常量 | 接口描述符类型 | 
| 2 | bInterfaceNumber | 1 | 数字 | 接口编号。基于零的数值,用于标识此配置所支持的并发接口数组中的索引。 | 
| 3 | bAlternateSetting | 1 | 数字 | 用于为前述字段标识的接口选择备用设置的值 | 
| 4 | bNumEndpoints | 1 | 数字 | 此接口使用的端点数量(不包括端点零)。如果此值为零,则该接口仅使用默认控制管道。 | 
| 5 | bInterfaceClass | 1 | 类 | 类代码(由 USB 分配)。值为零保留供未来标准化使用。如果此字段设置为 FFH,则表示该接口类是厂商特定的。所有其他值均保留由 USB 分配。 | 
| 6 | bInterfaceSubClass | 1 | 子类 | 子类代码(由 USB 分配)。这些代码由 bInterfaceClass 字段的值限定。如果 bInterfaceClass 字段重置为零,则此字段也必须重置为零。如果 bInterfaceClass 字段未设置为 FFH,则所有值均保留由 USB 分配。 | 
| 7 | bInterfaceProtocol | 1 | 协议代码 | 协议代码(由 USB 分配)。 这些代码由 bInterfaceClass 和 bInterfaceSubClass 字段的值限定。如果接口支持特定于类的请求,此代码标识了设备所使用的、由设备类规范定义的协议。 如果此字段重置为零,则表示设备在此接口上不使用特定于类的协议。 如果此字段设置为 FFH,则表示设备在此接口上使用厂商特定的协议。  | 
| 8 | iInterface | 1 | 索引 | 描述此接口的字符串描述符的索引。 | 
