【USB笔记】接口描述符Interface Descriptor

USB笔记 接口描述符 (Interface Descriptor)

接口描述符(Interface Descriptor)描述了配置中一个特定的接口。配置提供了一个或多个接口,每个接口都含有类(Class),子类(SubClass)和协议(Protocol)的信息,以及接口所使用的端点(Endpoint)数目。

接口描述符(Interface Descriptor)总是作为配置描述符的一部分返回,不能直接用Get Descriptor或者Set Descriptor请求访问。

一个配置可含有多个同时活跃的接口。这些接口可能联合于某个功能,也可能并不相关。

每个接口都有它自己的接口描述符(Interface Descriptor)和附属描述符(subordinate descriptor)。

所有这些接口也都可拥有一个或多个替代的接口设置(alternate interface settings)。这些设置是相互排他的,每次只能有一个被激活。每个设置含有一个接口描述符(Interface Descriptor)及所的附属描述符(subordinate descriptor)。使用等时传输(isochronous transfers)的设备必须有替代接口设置(alternate interface settings),因为缺省的接口不能请求等时带宽(isochronous bandwidth)。

Interface Descriptor

OffsetFieldSizeValueDescription
0bLength1Number以字节为单位的描述符大小
1bDescriptorType1Constant接口描述符类型
2bInterfaceNumber1Number接口的编号
3bAlternateSetting1Number用来确认bInterfaceNumber的替代设置的编号
4bNumEndpoints1Number接口使用的端点数量
5bInterfaceClass1Class类码
6bInterfaceSubClass1SubClass子类码
7bInterfaceProtocol1Protocol协议码
8iInterface1Index接口字符串描述符的索引

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

bDescriptorType接口描述符类型,为INTERFACE(0x04)。

bInterfaceNumber接口的编号。表示该配置同时支持的接口序列索引。编号的值从0开始,缺省值为0x00。每个接口描述符中,该字段取值必须唯一。在组合设备(composite device )的配置中拥有多个同时活动的接口。

bAlternateSetting用来确认bInterfaceNumber的替代设置的编号。对于每个bInterfaceNumber ,设备将提供一个bAlternateSetting 字段为0x00的接口描述字,这是缺省的设置。替代设置的描述符bInterfaceNumber字段与缺省设备的值是相同的,但是bAlternateSetting的值不同,然后替代设置的描述符的最后5个字节的取值也会根据实际情况而不同。

对于每个bInterfaceNumber,每次只有一个bAlternateSetting 可被激活。替代设置可使主机能够请求带有不同带宽或其他要求和性能的接口。Get Interface请求会取得当前被激活的bAlternateSettingSet Interface请求可选择特定bInterfaceNumber所应当使用的bAlternateSetting

bNumEndpoints这个接口使用的端点数量(不包括端点0)。如果这个值为0,那么这个接口使用默认的控制管道(Control Pipe),既只使用端点0。

bInterfaceClass类码(Class code),这个类码(Class code)由USB-IF分配。除了用于由接口规定的设备外,其他与设备描述符(Device Descriptor)中bDeviceClass 字段相同。

值0x00为保留值,从0x01 – 0xFE的值保留给USB定义的类,0xFF作为厂商定义的类。

Class CodeDescription
0x00保留(Reserved)
0x01音频(Audio)
0x02通讯设备:通讯接口(Communications device: communication interface)
0x03人机接口设备(Human interface device)
0x05物理(Physical)
0x06图像(Image)
bInterfaceSubclass = 0x01
bInterfaceProtocol = 0x01: Imaging device
0x07打印机(Printer)
0x08大容量存储(Mass storage)
0x09集线器(Hub) (还必须在设备描述符(device descriptor)中声明 )
0x0A通讯设备:数据接口(Communications device: data interface)
0x0B智能卡(Smart Card)
0x0D内容安全(Content Security)
bInterfaceSubclass = 0x01
bInterfaceProtocol = 0x01: Content security device
0x0E视频(Video)
0x0F个人健康设备(Personal healthcare device) (can instead be declared at the device level)
0x10Audio/Video (AV):
bInterfaceSubclass = 0x01
bInterfaceProtocol = 0x00: AVControl Interface
bInterfaceSubclass = 0x02
bInterfaceProtocol = 0x00: AVData Video Streaming Interface
bInterfaceSubclass = 0x03
bInterfaceProtocol = 0x00: AVData Audio Streaming Interface
0xDC诊断设备Diagnostic device (can instead be declared at the device level)
bInterfaceSubclass= 0x01
bInterfaceProtocol = 0x01: USB2 compliance device
0xE0无线控制器Wireless controller
bInterfaceSubclass = 0x01
bInterfaceProtocol = 0x01: Bluetooth programming interface (should also be
declared at the device level)
bInterfaceProtocol = 0x02: UWB Radio control interface (Wireless USB)
bInterfaceProtocol = 0x03: RNDIS
bInterfaceProtocol = 0x04: Bluetooth AMP controller (should also be declared at the device level)
bInterfaceSubclass = 0x02: Host and device wire adapters (Wireless USB)
bInterfaceProtocol = 0x01: Host wire adapter control/data interface
bInterfaceProtocol = 0x02: Device wire adapter control/data interface
bInterfaceProtocol = 0x03: Device wire adapter isochronous interface
0xEF各种各样的Miscellaneous
bInterfaceSubclass = 0x01
bInterfaceProtocol = 0x01: active sync
bInterfaceProtocol = 0x02: Palm sync
bInterfaceSubclass = 0x02
bInterfaceProtocol = 0x01: Interface Association Descriptor
bInterfaceProtocol = 0x02: Wire Adapter Multifunction Peripheral programming
interface
bInterfaceSubclass = 0x03: Cable based association framework (Wireless USB)
bInterfaceProtocol = 0x01: Cable based association framework device
bInterfaceSubclass = 0x04
bInterfaceProtocol = 0x01: RNDIS over Ethernet
bInterfaceProtocol = 0x02: RNDIS over WiFi
bInterfaceProtocol = 0x03: RNDIS over Maxim
bInterfaceProtocol = 0x04: RNDIS over WWAN
bInterfaceProtocol = 0x05: RNDIS for Raw IPv4
bInterfaceProtocol = 0x06: RNDIS for Raw IPv6
bInterfaceProtocol = 0x07: RNDIS for GPRS
bInterfaceSubclass = 0x05: Machine vision device (USB3 Vision)
bInterfaceProtocol = 0x00: USB3 Vision Control Interface
bInterfaceProtocol = 0x01: USB0 Vision Event Interface
bInterfaceProtocol = 0x02: USB3 Vision Streaming Interface
0xFE应用程序专属Application specific
bInterfaceSubclass = 0x01: Device firmware upgrade
bInterfaceSubclass = 0x02: IrDA bridge
bInterfaceSubclass = 0x03: Test and measurement (USBTMC)
bInterfaceProtocol = 0x00: Complies with USBTMC spec
bInterfaceProtocol = 0x01: Complies with USBTMC USB488 subclass
0xFF厂商专属Vendor specific (can instead be declared at the device level)

bInterfaceSubClass子类码(SubClass code),这个子类码(SubClass code)由USB-IF分配。这个值由bInterfaceClass字段所限定。除了带有由接口定义的类的设备之外,此字段与设备描述符(Device Descriptor)中的bDeviceSubClass字段相同。如果bInterfaceClass等于0x00,则bInterfaceSubClass也必须等于0x00。如果bIntefaceClass是0x01–0xFE范围的值,则bInterfaceSubClass等于0x00或等于一个为接口的类定义的码。0xFF表明为厂商定义的子类(SubClass)。

bInterfaceProtocol协议码(Protocol code),这个协议码(Protocol code)由USB-IF分配。这个值由bInterfaceClass字段和bInterfaceSubClass字段所限定。如果接口支持专用的类型请求,这个协议码能识别出由协议类型规范定义、设备使用的协议。如果bInterfaceClass等于0x00,设备在这个接口不使用专门的类协议。如果为0xFF,设备在这个接口使用专用的厂商协议。除了带有由接口定义的类的设备之外,此字段与设备描述符(Device Descriptor)中的bDeviceProtocol字段相同。如果bIntefaceClass 是0x01–0xFE范围的值,则bInterfaceProtocol 等于0x00或等于一个为接口的类定义的码。

iInterface描述这个接口的字符串描述符的索引。如果没有字符串描述符的话则此值为0。

获取接口描述符

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

接口描述符(Interface Descriptor)总是作为配置描述符Configuration Descriptor的一部分返回,不能单独获取。

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

下面举例说明一个获取接口描述符的过程。
获取一个键盘的接口描述符,该键盘的接口描述符如下所示:
0

使用USB分析仪抓包可以看到,获取配置描述符Configuration Descriptor,而接口描述符Interface Descriptor就包含在其中:
1

接口描述符Interface Descriptor的获取过程如下:
2

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

接下来详细看整个获取过程的各个字段含义:
4

一开始的setup包过程:
5

setup data:
6

IN包过程
7

OUT包过程:
8

完成整个接口描述符Interface 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.x/USB 2.0/USB 3.x Interface Descriptor

OffsetFieldSizeValueDescription
0bLength1NumberSize of this descriptor in bytes
1bDescriptorType1ConstantINTERFACE Descriptor Type
2bInterfaceNumber1NumberNumber of this interface. Zero-based value identifying the index in the array of concurrent interfaces supported by this configuration.
3bAlternateSetting1NumberValue used to select this alternate setting for the interface identified in the prior field.
4bNumEndpoints1NumberNumber of endpoints used by this interface (excluding endpoint zero). If this value is zero, this interface only uses the Default Control Pipe.
5bInterfaceClass1ClassClass code (assigned by the USB-IF).
A value of zero is reserved for future standardization.
If this field is set to FFH, the interface class is vendor-specific.
All other values are reserved for assignment by the USB-IF.
6bInterfaceSubClass1SubClassSubclass code (assigned by the USB-IF).
These codes are qualified by the value of the bInterfaceClass field.
If the bInterfaceClass field is reset to zero, this field must also be reset to zero.
If the bInterfaceClass field is not set to FFH, all values are reserved for assignment by the USB-IF.
7bInterfaceProtocol1ProtocolProtocol code (assigned by the USB).
These codes are qualified by the value of the bInterfaceClass and the bInterfaceSubClass fields. If an interface supports class-specific requests, this code identifies the protocols that the device uses as defined by the specification of the device class.
If this field is reset to zero, the device does not use a class-specific protocol on this interface.
If this field is set to FFH, the device uses a vendor-specific protocol for this interface.
8iInterface1IndexIndex of string descriptor describing this interface.

[参考资料]

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

USB Complete, 5th Edition

USB开发大全

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


本文链接:https://blog.csdn.net/u012028275/article/details/109567196

  • 6
    点赞
  • 46
    收藏
    觉得还不错? 一键收藏
  • 6
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 6
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值