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

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

Device Descriptor

Offset Field Size Value Description
0 bLength 1 Number 以字节为单位的描述符大小
1 bDescriptorType 1 Constant 设备描述符类型
2 bcdUSB 2 BCD USB规范版本号
4 bDeviceClass 1 Class 类码
5 bDeviceSubClass 1 SubClass 子类码
6 bDeviceProtocol 1 Protocol 协议码
7 bMaxPacketSize0 1 Number 端点0的最大包大小
8 idVendor 2 ID 厂商ID
10 idProduct 2 ID 产品ID
12 bcdDevice 2 BCD 设备版本号
14 iManufacturer 1 Index 制造商字符串描述符索引
15 iProduct 1 Index 产品的字符串描述符索引
16 iSerialNumber 1 Index 设备序列号的字符串描述符索引
17 bNumConfigurations 1 Number 可能的配置数目

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。

bDeviceClass Description
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 的值是作为2bMaxPacketSize02^{bMaxPacketSize0}2bMaxPacketSize0的指数,端点0的最大包大小等于2bMaxPacketSize02^{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 Descriptor Value
bmRequestType 0x80
  bmRequestType.Recipient 0b00000(Device)
  bmRequestType.Type 0b00(Standard)
  bmRequestType.Direction 0b1(Device-to-Host)
bRequest 0x06(Get Descriptor)
wValue 0x0100(Device#0)
wIndex 0x0000
wLength 0x???

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

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

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

再展开看到详细的过程:

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

一开始的setup包过程:

setup data:

IN包过程:

OUT包过程:

完成整个设备描述符Device Descriptor的获取。


描述符示例

这里举例一个带有该描述符的示例设备,这是一个键盘Keyboard的完整描述符信息。

Device Descriptor

Offset Field Size Value Description
0 bLength 1 0x12
1 bDescriptorType 1 0x01 DEVICE
2 bcdUSB 2 0x0110 1.10
4 bDeviceClass 1 0x00
5 bDeviceSubClass 1 0x00
6 bDeviceProtocol 1 0x00
7 bMaxPacketSize0 1 0x08
8 idVendor 2 0x046d
10 idProduct 2 0xc31c
12 bcdDevice 2 0x6400 64.00
14 iManufacturer 1 0x01
15 iProduct 1 0x02
16 iSerialNumber 1 0x00
17 bNumConfigurations 1 0x01

Configuration Descriptor

Offset Field Size Value Description
0 bLength 1 0x09
1 bDescriptorType 1 0x02 CONFIGURATION
2 wTotalLength 2 0x003b
4 bNumInterfaces 1 0x02
5 bConfigurationValue 1 0x01
6 iConfiguration 1 0x03
7 bmAttributes 1 0xa0
8 bMaxPower 1 0x2d

Interface Descriptor

Offset Field Size Value Description
0 bLength 1 0x09
1 bDescriptorType 1 0x04 INTERFACE
2 bInterfaceNumber 1 0x00
3 bAlternateSetting 1 0x00
4 bNumEndpoints 1 0x01
5 bInterfaceClass 1 0x03 Human Interface Device
6 bInterfaceSubClass 1 0x01 Boot Interface
7 bInterfaceProtocol 1 0x01 Keyboard
8 iInterface 1 0x02

HID Descriptor

Offset Field Size Value Description
0 bLength 1 0x09
1 bDescriptorType 1 0x21 HID
2 bcdHID 2 0x0110 1.10
4 bCountryCode 1 0x00
5 bNumDescriptors 1 0x01
6 bDescriptorType 1 0x22 REPORT
7 wDescriptorLength 2 0x0041

Endpoint Descriptor

Offset Field Size Value Description
0 bLength 1 0x07
1 bDescriptorType 1 0x05 ENDPOINT
2 bEndpointAddress 1 0x81 1 IN
3 bmAttributes 1 0x03 Interrupt
4 wMaxPacketSize 2 0x0008
6 bInterval 1 0x0a

Interface Descriptor

Offset Field Size Value Description
0 bLength 1 0x09
1 bDescriptorType 1 0x04 INTERFACE
2 bInterfaceNumber 1 0x01
3 bAlternateSetting 1 0x00
4 bNumEndpoints 1 0x01
5 bInterfaceClass 1 0x03 Human Interface Device
6 bInterfaceSubClass 1 0x00
7 bInterfaceProtocol 1 0x00
8 iInterface 1 0x02

HID Descriptor

Offset Field Size Value Description
0 bLength 1 0x09
1 bDescriptorType 1 0x21 HID
2 bcdHID 2 0x0110 1.10
4 bCountryCode 1 0x00
5 bNumDescriptors 1 0x01
6 bDescriptorType 1 0x22 REPORT
7 wDescriptorLength 2 0x009f

Endpoint Descriptor

Offset Field Size Value Description
0 bLength 1 0x07
1 bDescriptorType 1 0x05 ENDPOINT
2 bEndpointAddress 1 0x82 2 IN
3 bmAttributes 1 0x03 Interrupt
4 wMaxPacketSize 2 0x0004
6 bInterval 1 0xff

附录

USB1.x/USB 2.0 Device Descriptor

Offset Field Size Value Description
0 bLength 1 Number Size of this descriptor in bytes
1 bDescriptorType 1 Constant DEVICE Descriptor Type
2 bcdUSB 2 BCD USB 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.
4 bDeviceClass 1 Class Class 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.
5 bDeviceSubClass 1 SubClass Subclass 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.
6 bDeviceProtocol 1 Protocol Protocol 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.
7 bMaxPacketSize0 1 Number Maximum packet size for endpoint zero (only 8, 16, 32, or 64 are valid)
8 idVendor 2 ID Vendor ID (assigned by the USB-IF)
10 idProduct 2 ID Product ID (assigned by the manufacturer)
12 bcdDevice 2 BCD Device release number in binary-coded decimal
14 iManufacturer 1 Index Index of string descriptor describing manufacturer
15 iProduct 1 Index Index of string descriptor describing product
16 iSerialNumber 1 Index Index of string descriptor describing the device’s serial number
17 bNumConfigurations 1 Number Number of possible configurations

USB 3.x Device Descriptor

Offset Field Size Value Description
0 bLength 1 Number Size of this descriptor in bytes
1 bDescriptorType 1 Constant DEVICE Descriptor Type
2 bcdUSB 2 BCD USB 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.
4 bDeviceClass 1 Class Class 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.
5 bDeviceSubClass 1 SubClass Subclass 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.
6 bDeviceProtocol 1 Protocol Protocol 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.
7 bMaxPacketSize0 1 Number Maximum packet size for endpoint zero. The bMaxPacketSize0 value is used as the exponent for a 2bMaxPacketSize02^{bMaxPacketSize0}2bMaxPacketSize0 value; e.g., a bMaxPacketSize0 of 4 means a Max Packet size of 16 (242^424 → 16).
09H is the only valid value in this field when operating at Gen X speed.
8 idVendor 2 ID Vendor ID (assigned by the USB-IF)
10 idProduct 2 ID Product ID (assigned by the manufacturer)
12 bcdDevice 2 BCD Device release number in binary-coded decimal
14 iManufacturer 1 Index Index of string descriptor describing manufacturer
15 iProduct 1 Index Index of string descriptor describing product
16 iSerialNumber 1 Index Index of string descriptor describing the device’s serial number
17 bNumConfigurations 1 Number Number 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

【USB笔记】 设备描述符Device Descriptor相关推荐

  1. USB声卡驱动(二):USB音频设备描述符

    USB声卡驱动(二)USB音频设备描述符 本篇笔记,分两部分,第一部分,是基本知识的记录.第二部分是一个实际的例子. 一.基本知识 一个音频设备(Audio Device)含有多个音频功能(Audio ...

  2. 未知USB设备(设备描述符请求失败)是什么?

    未知USB 设备(设备描述符请求失败)是什么? 参考解决方案:Win10一个USB设备描述符请求失败解决方法 恕我直言,对我们没有什么用,我们需要的是不用插拔usb也能让错误消失

  3. CH330显示未知USB设备(设备描述符请求失败)

    CH330接上电脑后显示未知USB设备(设备描述符请求失败),原因是:VCC脚的0.1uF退耦电容一定必不可少!!

  4. USB各类设备描述符(usb device enumeration descriptors)

    0. RealtekUSB网卡dongle czl@czl-VirtualBox:~/WorkSpace$ lsusb -d 0bda:8176 -vBus 001 Device 003: ID 0b ...

  5. USB标准设备描述符

    USB标准设备的描述符包括设备描述符.配置描述符.接口描述符.端点描述符.字符串描述符.设备限定描述符和其他速率配置描述符. USB 标准描述符的类型值及所占字节数 设备描述符类型           ...

  6. Windows10神州网信版的USB故障处理(设备描述符请求失败)

    给一台计算机安装了Windows的神州网信版,在安装打印机时遭遇奇葩的故障. USB设备描述符请求失败. 开始安装完Windows10的神州网信版操作系统以及其他软件,安装HP LaserJet MF ...

  7. CH343PT库使用<二>USB转串口设备描述符配置

    文章目录 前言 一.配置EEPROM接口函数介绍 1.1 芯片功能信息结构体 1.2 USB串口芯片配置EEPROM结构体 1.3 进入芯片配置模式和退出芯片配置模式 1.4 读取和写入芯片EEPRO ...

  8. 未知USB设备(设备描述符请求失败)伴随笔记本蓝牙消失

    本人使用的笔记本电脑已经两次遇到这种情况了,第一次遇到的时候是因为发现电脑开机之后蓝牙消失了.第二次也是一样的结果,当然第二次有经验了,很快就解决了. 首先呢,蓝牙消失的同时,设备管理器中会出黄色感叹 ...

  9. win10检查更新后,蓝牙没了,卸载usb也没有用,蓝牙 未知usb设备 设备描述符请求失败

    最后解决方案: 长按电源键30s放电: 将bios的所有设置恢复默认 然后就有了蓝牙

最新文章

  1. CodedStereo:大尺度景深双目视觉的相位掩模学习(CVPR2021)
  2. vue 点击事件传递多个参数_vue传事件参数
  3. sysctl: 深入使用Linux的必经之路
  4. Mustache.js使用笔记(内容属于转载总结)
  5. CentOS7查看开放端口命令
  6. java获取对象的子_java – 如何根据子对象字段获取父对象
  7. Hystrix面试 - 深入 Hystrix 执行时内部原理
  8. java 将数据库中的每一条数据取出放入数组或者List中
  9. Linux之atime,ctime,mtime的区别
  10. Linux CentOS 7.2 安装 Tomcat 8 服务器
  11. 【路径规划】基于matlab A_star算法机器人走迷宫路径规划【含Matlab源码 1389期】
  12. 《研磨设计模式》抽象工厂模式与简单工厂模式的比较(golang)
  13. 极光IM简单代码(代码比较清晰)
  14. 鄙视那些把爬虫当作AI的SB,清华学霸尹成大哥的历史上最强大的爬虫视频
  15. 密码学中的各类密码汇总(一)
  16. Linux下卸载anaconda3
  17. 博士申请 | 美国达特茅斯学院杨耀青老师招收深度学习方向全奖博士生
  18. sam卡和sim卡区别_SAM卡
  19. PHP实现给图片加文字水印
  20. 多线程实现 qq 群聊的服务端和客户端

热门文章

  1. 每周学一点 egret(4):EUI
  2. 商越科技联合阿里云打造数字化综合解决方案,共创智慧采购新生态
  3. 欧几里得、扩展欧几里得、同余
  4. 【读过的书】《愿有人陪你颠沛流离》
  5. 萌新学习的第一天-浅谈梳理自己对硬件局面的看法
  6. 【Android组件化】app壳工程
  7. faster rcnn的理解
  8. python 百分号使用
  9. 活动报名丨英伟达AI Lab科学家、GET3D一作高俊:从图像中学习3D对象的生成建模...
  10. 2021-2025年中国耳用绷带行业市场供需与战略研究报告