【USB笔记】 设备描述符Device Descriptor

USB笔记 设备描述符(Device Descriptor)

设备描述符(Device Descriptor)说明了USB设备的通用信息,包含应用到全部设备和所有设备配置的信息。USB设备只有一个设备描述符(Device Descriptor)。设备描述符是在设备连接时主机读取的第一个描述符。设备描述符所含的信息,被主机用来取得设备的额外内容。设备描述符(Device Descriptor)提供了关于设备、设备的配置以及任何设备所归属的类的信息。

Device Descriptor

OffsetFieldSizeValueDescription
0bLength1Number以字节为单位的描述符大小
1bDescriptorType1Constant设备描述符类型
2bcdUSB2BCDUSB规范版本号
4bDeviceClass1Class类码
5bDeviceSubClass1SubClass子类码
6bDeviceProtocol1Protocol协议码
7bMaxPacketSize01Number端点0的最大包大小
8idVendor2ID厂商ID
10idProduct2ID产品ID
12bcdDevice2BCD设备版本号
14iManufacturer1Index制造商字符串描述符索引
15iProduct1Index产品的字符串描述符索引
16iSerialNumber1Index设备序列号的字符串描述符索引
17bNumConfigurations1Number可能的配置数目

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

bDescriptorType设备描述符类型,为DEVICE (0x01)。

bcdUSB以BCD码表示的USB规范发布版本编号。这个字段确定了设备及其描述符所遵循的USB规范发布版本。

该字段的值采用BCD(用二进制编码的十进制数)格式。bcdUSB字段的值为0xJJMN (JJ–主版本号(major version number),M–次版本号(minor version number),N–子次版本号(sub-minor version number)),例如,版本2.1.3用值0213H表示,版本3.0用值0300H表示。 如果要将这个数值转化为十进制数的话,前面的1字节(8位)代表整数部分,接下来的4位代表十分位,最后4位代表百分位。

USB 1.1: 0x0110

USB 2.0: 0x0200

USB 2.1: 0x0210

USB 2.5: 0x0250

USB 3.0: 0x0300

USB 3.1: 0x0310

USB 3.2: 0x0320

支持BOS descriptor的设备的bcdUSB值必须是0201H或更大的值。
符合Wireless USB specification的设备的bcdUSB值必须是0250H。

bDeviceClass类码(Class code)。这个字段为那些在设备层次定义功能的设备规定了它们所属的类。从0x01到0xFE的值是留给那些被USB规范定义的类。厂商定义的类使用0xFF。大多数设备在接口描述符中规定了它们的类。对于这些设备,若其功能不使用接口关联描述符(interface association descriptor),则设备描述符中的bDeviceClass 将等于0x00;若其功能使用接口关联描述符(interface association descriptor),bDeviceClass 就等于0xEF。

bDeviceClassDescription
0x00接口描述符(interface descriptor)规定了类和功能不使用接口联合描述符(interface association descriptor)
0x02通信设备(可以改为在接口层次声明)
0x09集线器Hub
bDeviceSubclass = 0x00
bDeviceProtocol = 0x00: Full speed
bDeviceProtocol = 0x01: High speed with single Transaction Translator
bDeviceProtocol = 0x02: High speed with multiple Transaction Translators
bDeviceProtocol = 0x03: SuperSpeed/SuperSpeedPlus
0x0F个人健康设备Personal healthcare device(首选在接口层次声明)
0xDC诊断设备Diagnostic device(可以改为在接口层次声明)
bDeviceSubclass = 0x01
bDeviceProtocol = 0x01: USB2 Compliance Device
0xE0无线控制器Wireless Controller (只限蓝牙(Bluetooth)。 所有其他协议必须在接口层次声明。)
bDeviceSubclass = 0x01
bDeviceProtocol = 0x01: Bluetooth programming interface (也应该在接口层次声明)
bDeviceSubclass = 0x04: Bluetooth AMP controller (也应该在接口层次声明)
0xEF各种各样的(Miscellaneous)
bDeviceSubclass = 0x01
bDeviceProtocol = 0x01: active sync
bDeviceProtocol = 0x02: Palm sync
bDeviceSubclass = 0x02
bDeviceProtocol = 0x01: interface association descriptor
bDeviceProtocol = 0x01: wire adapter multifunction peripheral
(Wireless USB)
0xFF厂商专属Vendor-specific (可以改为在接口层次声明)

bDeviceSubClass 子类码(Subclass code)。这个字段可规定一个类的子类。子类可增加对由类中的一组功能所共享的额外特性和功能的支持。如果bDeviceClass是0x00,则bDeviceSubClass也必须为0x00。如果bDeviceClass在0x01到0xFE范围内,则bDeviceSubClass等于0x00或等于为设备的类所定义的代码。标准类(standard classes)中,制造商定义的子类使用0xFF 。

bDeviceProtocol 协议码(Protocol code)。这个字段可为所选的类和子类规定一个协议。例如,USB2.0集线器就使用此字段来表明是否当前集线器支持高速模式,如果支持,则进一步表明集线器是支持一个还是多个事务转换器(transaction translators)。如果bDeviceClass 在0x01到0xFE的范围内,协议就等于0x00或由设备类所定义的代码。

bMaxPacketSize0 端点0的最大包大小。主机会在对设备描述符(Device Descriptor)进行请求之后跟着的那个请求中使用这一信息。

对于USB2.0/USB1.x,最大包大小等于此字段的值。

对于低速(low speed)必须是8。

对于全速(full speed)只能是8、16、32或64。

对于高速(high speed)只能是64。

对于增强型超高速状态(Enhanced SuperSpeed),bMaxPacketSize0 的值是作为 2 b M a x P a c k e t S i z e 0 2^{bMaxPacketSize0} 2bMaxPacketSize0的指数,端点0的最大包大小等于 2 b M a x P a c k e t S i z e 0 2^{bMaxPacketSize0} 2bMaxPacketSize0。bMaxPacketSize0必须等于9,端点0的最大包大小要为512。

idVendor 厂商ID。这个字段的值由USB-IF分配给其成员和其他缴纳了管理费的用户。主机可能会含有INF文件,其中就含有此值;且如果有,Windows 操作系统可使用此值来为设备选择驱动程序。除了内部使用(由用户负责防止冲突)的设备外,每个设备描述符必须在这个字段上拥有一个有效的厂商ID。

idProduct 产品ID。这个字段是表明厂商设备的产品ID。厂商ID的拥有者指定了产品ID。设备描述符和主机上设备的NF文件都可能含有此值,如果有,Windows 操作系统可能会使用这个值来帮助为设备选择驱动程序。对于厂商ID来说,每个产品ID都是唯一的,因此多个制造商可使用同一产品ID却不会引起冲突。

bcdDevice BCD格式表示的设备版本号。厂商指定这个值。主机可能会使用这个值来为设备选择驱动程序。

iManufacturer指向描述制造商的字符串描述符的索引。如果没有制造商描述符,此值即为0。

iProduct 指向一个描述产品的字符串描述符的索引。如果没有字符串描述符,此值为0。

iSeriaINumber指向含有设备序列号的字符串描述符的索引。如果没有序列号,此值为0。若用户在总线上拥有多个相同的设备,且即使在重启之后主机仍需要将它们区分开,这种情况下序列号十分有用。序列号还可使主机能够确定设备是与之前所使用的相同,还是一个新安装的有相同制造商ID和产品ID的设备。带有同样制造商ID、产品ID和设备版本号的设备,就不能再共享序列号了。使用批量专属协议的大容量存储设备必须含有序列号。

bNumConfigurations是当前运行速度下设备所支持的配置数目。其他运行速度下的配置数目不包含在其中。

获取设备描述符

主机通过发送Get Descriptor请求,来取得一个设备描述符(Device Descriptor)。

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

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

使用USB分析仪抓包可以看到,设备第一个获取的描述符就是设备描述符:
0

设备描述符的获取过程如下:
1

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

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

一开始的setup包过程:
4

setup data:
4-1

IN包过程:
5

OUT包过程:
6
完成整个设备描述符Device 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 Device Descriptor

OffsetFieldSizeValueDescription
0bLength1NumberSize of this descriptor in bytes
1bDescriptorType1ConstantDEVICE Descriptor Type
2bcdUSB2BCDUSB Specification Release Number in Binary-Coded Decimal (i.e., 2.10 is 210H).
This field identifies the release of the USB Specification with which the device and its descriptors are compliant.
4bDeviceClass1ClassClass code (assigned by the USB-IF).
If this field is reset to zero, each interface within a configuration specifies its own class information and the various interfaces operate independently.
If this field is set to a value between 1 and FEH, the device supports different class specifications on different interfaces and the interfaces may not operate independently. This value identifies the class definition used for the aggregate interfaces.
If this field is set to FFH, the device class is vendor-specific.
5bDeviceSubClass1SubClassSubclass code (assigned by the USB-IF).
These codes are qualified by the value of the bDeviceClass field.
If the bDeviceClass field is reset to zero, this field must also be reset to zero.
If the bDeviceClass field is not set to FFH, all values are reserved for assignment by the USB-IF.
6bDeviceProtocol1ProtocolProtocol code (assigned by the USB-IF). These codes are qualified by the value of the bDeviceClass and the bDeviceSubClass fields. If a device supports class-specific protocols on a device basis as opposed to an interface basis, 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 class-specific protocols on a device basis. However, it may use class-specific protocols on an interface basis.
If this field is set to FFH, the device uses a vendor-specific protocol on a device basis.
7bMaxPacketSize01NumberMaximum packet size for endpoint zero (only 8, 16, 32, or 64 are valid)
8idVendor2IDVendor ID (assigned by the USB-IF)
10idProduct2IDProduct ID (assigned by the manufacturer)
12bcdDevice2BCDDevice release number in binary-coded decimal
14iManufacturer1IndexIndex of string descriptor describing manufacturer
15iProduct1IndexIndex of string descriptor describing product
16iSerialNumber1IndexIndex of string descriptor describing the device’s serial number
17bNumConfigurations1NumberNumber of possible configurations

USB 3.x Device Descriptor

OffsetFieldSizeValueDescription
0bLength1NumberSize of this descriptor in bytes
1bDescriptorType1ConstantDEVICE Descriptor Type
2bcdUSB2BCDUSB Specification Release Number in Binary-Coded Decimal (i.e., 2.10 is 210H).
This field identifies the release of the USB Specification with which the device and its descriptors are compliant.
4bDeviceClass1ClassClass code (assigned by the USB-IF).
If this field is reset to zero, each interface within a configuration specifies its own class information and the various interfaces operate independently.
If this field is set to a value between 1 and FEH, the device supports different class specifications on different interfaces and the interfaces may not operate independently. This value identifies the class definition used for the aggregate interfaces.
If this field is set to FFH, the device class is vendor-specific.
5bDeviceSubClass1SubClassSubclass code (assigned by the USB-IF).
These codes are qualified by the value of the bDeviceClass field.
If the bDeviceClass field is reset to zero, this field must also be reset to zero.
If the bDeviceClass field is not set to FFH, all values are reserved for assignment by the USB-IF.
6bDeviceProtocol1ProtocolProtocol code (assigned by the USB-IF). These codes are qualified by the value of the bDeviceClass and the bDeviceSubClass fields. If a device supports class-specific protocols on a device basis as opposed to an interface basis, 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 class-specific protocols on a device basis. However, it may use class-specific protocols on an interface basis.
If this field is set to FFH, the device uses a vendor-specific protocol on a device basis.
7bMaxPacketSize01NumberMaximum packet size for endpoint zero. The bMaxPacketSize0 value is used as the exponent for a 2 b M a x P a c k e t S i z e 0 2^{bMaxPacketSize0} 2bMaxPacketSize0 value; e.g., a bMaxPacketSize0 of 4 means a Max Packet size of 16 ( 2 4 2^4 24 → 16).
09H is the only valid value in this field when operating at Gen X speed.
8idVendor2IDVendor ID (assigned by the USB-IF)
10idProduct2IDProduct ID (assigned by the manufacturer)
12bcdDevice2BCDDevice release number in binary-coded decimal
14iManufacturer1IndexIndex of string descriptor describing manufacturer
15iProduct1IndexIndex of string descriptor describing product
16iSerialNumber1IndexIndex of string descriptor describing the device’s serial number
17bNumConfigurations1NumberNumber of possible configurations

[参考资料]

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

Wireless Universal Serial Bus Specification Revision 1.0

Wireless Universal Serial Bus Specification Revision 1.1

USB 2.0 ECN: Link Power Management (LPM)

USB Complete, 5th Edition

USB开发大全

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


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

  • 13
    点赞
  • 77
    收藏
    觉得还不错? 一键收藏
  • 2
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值