笔者来聊聊大容量存储设备枚举过程分析.。
标准设备的请求命令主要有以下几条:
比较常用的就是:设置地址,获取描述,设置/获取配置。
设备请求的编码如下:
所以设置地址(05),获取描述(06),设置/获取配置(09/08)。


上述命令简单,wValue填写实际分配的地址即可。


获取描述符的协议定义如下:通过参数不同,可以获取多个不同类型的描述符数据。



| offset | Field | Size | value | Description | example |
|---|---|---|---|---|---|
| 0 | bLength | 1 | Number | Size of this descriptor in bytes,字节数 | 0x12 |
| 1 | bDescriptionType | 1 | Number | DEVICE Descriptor Type,描述类编码值 | 0x1 |
| 2 | bcdUSB | 2 | BCD | USB Specification Release Number in Binary-Coded Decimal (i.e., 2.10 is 210H),USB版本 | 0x0210 |
| 4 | bDeviceClass | 1 | Class | Class code,USB类编码 | 0x00 |
| 5 | bDeviceSubClass | 1 | Class | SubClass code,USB子类编码 | 0x00 |
| 6 | bDeviceProtocol | 1 | Protocol | Protocol code,协议编码 | 0x00 |
| 7 | bMaxPacketSize0 | 1 | Number | Maximum packet size for endpoint zero(only 8, 16, 32, or 64 are valid) | 0x40 |
| 8 | idVendor | 2 | ID | Vendor ID,厂商ID | 0x090C |
| 10 | idProduct | 2 | ID | Product ID,厂商里面的设备iD | 0x8381 |
| 12 | bcdDevice | 2 | BCD | Device release number in binary-codeddecimal | 0x1100 |
| 14 | iManufacturer | 1 | Index | Index of string descriptor type describing manufacturer,获取厂商的描述,Get Descripor 请求类型 | 0x01 |
| 15 | iProduct | 1 | Index | Index of string descriptor type describing product,获取产品的描述 | 0x02 |
| 16 | iSerialNumber | 1 | Index | Index of string descriptor type describing the device’s serial number,获取序列号的描述, | 0x03 |
| 17 | bNumConfigurations | 1 | Number | Number of possible configurations , | 0x01 |
多看几种设备比如USB转串口:USB 2.0版本
下面这个是USB1.1版本,相对比较老,

ST的STM32 USB大容量存储设备,USB发布版本 USB2.0。

闪迪U盘,USB2.1版本。



配置描述符,
| offset | Field | Size | value | Description | example |
|---|---|---|---|---|---|
| 0 | bLength | 1 | Number | Size of this descriptor in bytes,字节数 | 0x09 |
| 1 | bDescriptionType | 1 | Constant | CONFIGURATION Descriptor Type ,配置类别type | 0x02 |
| 2 | wTotalLength | 2 | Number | Total length of data returned for this configuration,配置的总长度,包含了其他描述符 | 0x0020 |
| 4 | bNumInterfaces | 1 | Number | Number of interfaces supported by this configuration | 0x01 |
| 5 | bConfigurationValue | 1 | Number | Value to use as an argument to the SetConfiguration() request to select this configuration | 0x01 |
| 6 | iConfiguration | 1 | Index | Index of string descriptor describing this configuration | 0x04 |
| 7 | bmAttributes | 1 | Bitmap | Configuration characteristics | 0xC0 |
| 8 | bMaxPower | 2 | mA | Maximum power consumption of the USBdevice,1 value 代表2ma, | 0x32 |
接口描述符的说明,可以获得USB的类以及子类等信息
| offset | Field | Size | value | Description | example |
|---|---|---|---|---|---|
| 0 | bLength | 1 | Number | Size of this descriptor in bytes,字节数 | 0x09 |
| 1 | bDescriptionType | 1 | Constant | INTERFACE Descriptor Type ,接口描述符类别 | 0x04 |
| 2 | bInterfaceNumber | 1 | Number | Number of this interface ,接口个数 | 0x00 |
| 3 | bAlternateSetting | 1 | Number | Value used to select this alternate setting for the interface identified in the prior field , | 0x00 |
| 4 | bNumEndpoints | 1 | Number | Number of endpoints used by this interface (excluding endpoint zero). | 0x02 |
| 5 | bInterfaceClass | 1 | Class | Class code | 0x08,代表大容量存储设备 |
| 6 | bInterfaceSubClass | 1 | SubClass | SubClass code ,设备子类,06代表U盘, | 0x06 |
| 7 | bInterfaceProtocol | 1 | Protocol | Protocol code ,0x50代表批量传输 | 0x50 |
| 8 | iInterface | 1 | Index | Index of string descriptor describing this interface | 0x05 |
端点描述符:编码05,
| offset | Field | Size | value | Description | example |
|---|---|---|---|---|---|
| 0 | bLength | 1 | Number | Size of this descriptor in bytes,字节数 | 0x07 |
| 1 | bDescriptionType | 1 | Constant | INTERFACE Descriptor Type ,接口描述符类别 | 0x05 |
| 2 | bEndpointAddress | 1 | Number | The address of the endpoint on the USB device described by this descriptor , | 0x81 |
| 3 | bmAttributes | 1 | Number | This field describes the endpoint’s attributes when it is configured using the bConfigurationValue, 00:控制传输,01 同步传输,02 批量传输,03 中断传输 | 0x02 |
| 4 | wMaxPacketSize | 2 | Number | Maximum packet size this endpoint | 0x0040 |
| 6 | bInterval | 1 | Number | Interval for polling endpoint for data transfers. | 0x00 |
获取字符信息,编码是03,可以获取序列号,厂商以及产品描述。
获取序列号

获取设备信息

获取厂商描述信息

获取接口描述信息

获取编码

| offset | Field | Size | value | Description | example |
|---|---|---|---|---|---|
| 0 | bLength | 1 | Number | Size of this descriptor in bytes,字节数 | 0x1A |
| 1 | bDescriptionType | 1 | Constant | STRING Descriptor Type ,接口描述符类别 | 0x03 |
| 2 | bString | 1 | Number | UNICODE encoded string , | string |

获取最大的逻辑单元数,可以理解为有多少个存储介质设备。返回值就1个字节,lun的个数=返回值+1。


可以看到是HS ,高速设备,如果是FS,则是全速设备。









d. 获取序列号:4C534001620603120390

e.设置config信息

f.获取最大的逻辑单元数:0

可以看到是USB G1.,就是USB3.1 ,
