USB协议学习(二)大容量存储设备枚举过程分析

笔者来聊聊大容量存储设备枚举过程分析.。

1、USB2.0 标准设备请求

标准设备的请求命令主要有以下几条:

  • Get Configureation :获取设备配置信息
  • Set Configureation:设置设备配置信息
  • Get Descriptor:获取描述符
  • Set Descriptor:设置描述符
  • Set Address:设置设备的地址
  • Get Interface:获取特定接口的设置
  • Set Interface:配置特定接口的设置

比较常用的就是:设置地址,获取描述,设置/获取配置。
设备请求的编码如下:
所以设置地址(05),获取描述(06),设置/获取配置(09/08)。
在这里插入图片描述

1.1 设置地址

在这里插入图片描述
上述命令简单,wValue填写实际分配的地址即可。

  • 观察下面逻辑分析仪抓的数据,就可以看到命令码是05,设置的地址是0x40,所以后面的地址就是40。
  • 观察下面的USB分析仪抓的数据,可以更清晰的看出来Host 与 Device的交互。
  • 过程基本都是三个阶段,详情见USB2.0协议介绍
    在这里插入图片描述
    在这里插入图片描述

1.2 获取描述符

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

  • ReuestType:06
  • wValue:2Byte,分成两个字节使用,低字节:index,高字节:描述符类型,如下面表格所示。
  • wIndex:Language ID

在这里插入图片描述

  • 首先获取Device类型,主要是USB版本,USB类以及子类等。
    在这里插入图片描述
offsetFieldSizevalueDescriptionexample
0bLength1NumberSize of this descriptor in bytes,字节数0x12
1bDescriptionType1NumberDEVICE Descriptor Type,描述类编码值0x1
2bcdUSB2BCDUSB Specification Release Number in Binary-Coded Decimal (i.e., 2.10 is 210H),USB版本0x0210
4bDeviceClass1ClassClass code,USB类编码0x00
5bDeviceSubClass1ClassSubClass code,USB子类编码0x00
6bDeviceProtocol1ProtocolProtocol code,协议编码0x00
7bMaxPacketSize01NumberMaximum packet size for endpoint zero(only 8, 16, 32, or 64 are valid)0x40
8idVendor2IDVendor ID,厂商ID0x090C
10idProduct2IDProduct ID,厂商里面的设备iD0x8381
12bcdDevice2BCDDevice release number in binary-codeddecimal0x1100
14iManufacturer1IndexIndex of string descriptor type describing manufacturer,获取厂商的描述,Get Descripor 请求类型0x01
15iProduct1IndexIndex of string descriptor type describing product,获取产品的描述0x02
16iSerialNumber1IndexIndex of string descriptor type describing the device’s serial number,获取序列号的描述,0x03
17bNumConfigurations1NumberNumber of possible configurations ,0x01

多看几种设备比如USB转串口:USB 2.0版本
在这里插入图片描述下面这个是USB1.1版本,相对比较老,
在这里插入图片描述
ST的STM32 USB大容量存储设备,USB发布版本 USB2.0。
在这里插入图片描述
闪迪U盘,USB2.1版本。
在这里插入图片描述

  • 获取配置信息,编码是02,其实会把接口描述符,和端点描述符都获取上来

在这里插入图片描述
在这里插入图片描述
配置描述符,

offsetFieldSizevalueDescriptionexample
0bLength1NumberSize of this descriptor in bytes,字节数0x09
1bDescriptionType1ConstantCONFIGURATION Descriptor Type ,配置类别type0x02
2wTotalLength2NumberTotal length of data returned for this configuration,配置的总长度,包含了其他描述符0x0020
4bNumInterfaces1NumberNumber of interfaces supported by this configuration0x01
5bConfigurationValue1NumberValue to use as an argument to the SetConfiguration() request to select this configuration0x01
6iConfiguration1IndexIndex of string descriptor describing this configuration0x04
7bmAttributes1BitmapConfiguration characteristics0xC0
8bMaxPower2mAMaximum power consumption of the USBdevice,1 value 代表2ma,0x32

接口描述符的说明,可以获得USB的类以及子类等信息

offsetFieldSizevalueDescriptionexample
0bLength1NumberSize of this descriptor in bytes,字节数0x09
1bDescriptionType1ConstantINTERFACE Descriptor Type ,接口描述符类别0x04
2bInterfaceNumber1NumberNumber of this interface ,接口个数0x00
3bAlternateSetting1NumberValue used to select this alternate setting for the interface identified in the prior field ,0x00
4bNumEndpoints1NumberNumber of endpoints used by this interface (excluding endpoint zero).0x02
5bInterfaceClass1ClassClass code0x08,代表大容量存储设备
6bInterfaceSubClass1SubClassSubClass code ,设备子类,06代表U盘,0x06
7bInterfaceProtocol1ProtocolProtocol code ,0x50代表批量传输0x50
8iInterface1IndexIndex of string descriptor describing this interface0x05

端点描述符:编码05,

offsetFieldSizevalueDescriptionexample
0bLength1NumberSize of this descriptor in bytes,字节数0x07
1bDescriptionType1ConstantINTERFACE Descriptor Type ,接口描述符类别0x05
2bEndpointAddress1NumberThe address of the endpoint on the USB device described by this descriptor ,0x81
3bmAttributes1NumberThis field describes the endpoint’s attributes when it is configured using the bConfigurationValue, 00:控制传输,01 同步传输,02 批量传输,03 中断传输0x02
4wMaxPacketSize2NumberMaximum packet size this endpoint0x0040
6bInterval1NumberInterval for polling endpoint for data transfers.0x00
  • 获取字符信息,编码是03,可以获取序列号,厂商以及产品描述。

  • 获取序列号
    在这里插入图片描述

  • 获取设备信息
    在这里插入图片描述

  • 获取厂商描述信息
    在这里插入图片描述

  • 获取接口描述信息
    在这里插入图片描述

  • 获取编码
    在这里插入图片描述

offsetFieldSizevalueDescriptionexample
0bLength1NumberSize of this descriptor in bytes,字节数0x1A
1bDescriptionType1ConstantSTRING Descriptor Type ,接口描述符类别0x03
2bString1NumberUNICODE encoded string ,string
  • 04 是接口信息:MSC Config (大容量接口配置)
  • 03 是序列号:3A0941884250
  • 02 设备信息:Mass Storage in FS Mode
  • 01 厂商信息:STMicroelectronics(意法半导体公司)
  • 00 获取语言编码:language ID 0904

在这里插入图片描述

1.3 获取Max Lun

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

2、大容量存储设备上电过程

USB2.0 示例

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

  • 首先上电,根据上电可以知道是低速还是高速设备
  • 设置地址信息
  • 获取描述符
  • 设置配置信息
  • 获取最大的逻辑单元数(如果是大容量存储设备 )
    在这里插入图片描述
  • USB协议分析来看一下
  1. 首先设置地址,0x1B=27,通过Setup和IN 设置设备信息。
    在这里插入图片描述
  2. 获取设备描述符,配置信息,VID:0781 (SanDisk) PID:55A9 ,U盘系列
    在这里插入图片描述
    在这里插入图片描述
    在这里插入图片描述
  3. 设备信息是:Dual Drive
    在这里插入图片描述
  4. 设备序列号是:0101xxxx,总共0xF2=242个字符。
    在这里插入图片描述
  • 逻辑分析仪看一下
    同上面分析
  • BusHound 分析仪一下
    a. 没有看到设备地址设置信息
    b. 获取设备描述符 , VID=0x0781 PID=0x558a
    在这里插入图片描述
    c. 获取设备名字信息和厂商信息:Ultra 以及SanDisk。
    在这里插入图片描述

d. 获取序列号:4C534001620603120390
在这里插入图片描述
e.设置config信息
在这里插入图片描述
f.获取最大的逻辑单元数:0
在这里插入图片描述

USB3.1 示例

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

  • 设置地址
  • 获取描述符,设备类别
  • 获取描述符,配置信息
  • 获取描述符,字符串信息
  • Set ISOCH Dealy
  • Set Feature
  • 设置配置信息
  • 获取最大的逻辑单元数(如果是大容量存储设备 )
    在这里插入图片描述
    继续总结。
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

张一西

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值