【USB笔记】字符串描述符String Descriptor

USB笔记 字符串描述符(String Descriptor)

字符串描述符(String Descriptor)规定了所支持的语言或者存储文本字符串。部分描述符含有字符串索引,用于描述相关信息。字符串描述符是可选的。如果不支持字符串描述符,需要将相关的描述符中的字符串索引设置为0。

String Descriptor 0, 指定设备支持的语言(String Descriptor Zero, Specifying Languages Supported by the Device)

OffsetFieldSizeValueDescription
0bLength1N+2以字节为单位的描述符大小
1bDescriptorType1Constant字符串描述符类型
2wLANGID[0]2NumberLANGID 码 0
NwLANGID[x]2NumberLANGID 码 x

bLength 以字节为单位的描述符大小。

bDescriptorType 字符串描述符类型,为String(0x03)。

wLANGID[0 - x] 语言ID。只对String Descriptor 0有效。字段含有USB-IF定义的16-bit语言ID,表明了字符串的可用语言。wLANGID必须有效,才能使其他的字符串有效。对于不支持字符串描述符的设备,也不能返回语言ID。USB-IF语言ID的定义可以查看文档Universal Serial Bus (USB) Language Identifiers (LANGIDs) Version 1.0。最常用的语言ID是0x0409(English (United States))。LANGID码数组不以NULL结束。数组的大小由描述符第一个字节的值减2计算出。

UNICODE String Descriptor

OffsetFieldSizeValueDescription
0bLength1Number以字节为单位的描述符大小
1bDescriptorType1Constant字符串描述符类型
2bStringNNumberUNICODE 编码字符串

bLength 以字节为单位的描述符大小。

bDescriptorType 字符串描述符类型,为String(0x03)。

bString UNICODE 编码的字符串。对String Descriptor 0x01和更高的值有效。字段含有Unicode UTF-16LE 格式的字符串。编码定义于《The Unicode Standard, Worldwide Character Encoding》。UNICODE 字符串描述符不以NULL结束。字符串的大小由描述符第一个字节的值减2计算出。

获取字符串描述符

主机通过发送Get Descriptor请求,来取得字符串描述符(String Descriptor)。wValue的低字节是索引值。取0的索引值表示请求语言ID(LANGID),其他索引值表示请求字符串。

Get DescriptorValue
bmRequestType0x80
  bmRequestType.Recipient0b00000(Device)
  bmRequestType.Type0b00(Standard)
  bmRequestType.Direction0b1(Device-to-Host)
bRequest0x06(Get Descriptor)
wValue0x03??(String #?)
wIndex0x???
wLength0x???

下面举例说明一个获取字符串描述符String Descriptor的过程。使用USB分析仪抓包,软件Total Phase Data Center。

获取一个键盘的字符串描述符,该键盘的字符串描述符如下所示:
1.String Descriptor Zero, Specifying Languages Supported by the Device
0
2.UNICODE String Descriptor1

使用USB分析仪抓包可以看到,获取字符串描述符String Descriptor:
2

字符串描述符String Descriptor的获取过程如下:
3

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

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

一开始的setup包过程:
1.String Descriptor Zero, Specifying Languages Supported by the Device
6
2.UNICODE String Descriptor7

setup data:
1.String Descriptor Zero, Specifying Languages Supported by the Device
8
2.UNICODE String Descriptor
9

IN包过程:10

OUT包过程:
11

完成整个字符串描述符String Descriptor的获取。


描述符示例

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

String Descriptor Zero, Specifying Languages Supported by the Device

OffsetFieldSizeValueDescription
0bLength10x04
1bDescriptorType10x03STRING
2bString20x0409English (United States)

UNICODE String Descriptor

OffsetFieldSizeValueDescription
0bLength10x1A
1bDescriptorType10x03STRING
2bString[0]10x55‘U’
3bString[1]10x00
4bString[2]10x53‘S’
5bString[3]10x00
6bString[4]10x42‘B’
7bString[5]10x00
8bString[6]10x20’ ’
9bString[7]10x00
10bString[8]10x4B‘K’
11bString[9]10x00
12bString[10]10x65‘e’
13bString[11]10x00
14bString[12]10x79‘y’
15bString[13]10x00
16bString[14]10x62‘b’
17bString[15]10x00
18bString[16]10x6F‘o’
19bString[17]10x00
20bString[18]10x61‘a’
21bString[19]10x00
22bString[20]10x72‘r’
23bString[21]10x00
24bString[22]10x64‘d’
25bString[23]10x00

附录

USB 1.x/USB 2.0/USB 3.x String Descriptor Zero, Specifying Languages Supported by the Device

OffsetFieldSizeValueDescription
0bLength1N+2Size of this descriptor in bytes
1bDescriptorType1ConstantSTRING Descriptor Type
2wLANGID[0]2NumberLANGID code zero
NwLANGID[x]2NumberLANGID code x

USB 1.1/USB 2.0/USB 3.x UNICODE String Descriptor

OffsetFieldSizeValueDescription
0bLength1NumberSize of this descriptor in bytes
1bDescriptorType1ConstantSTRING Descriptor Type
2bStringNNumberUNICODE encoded string

[参考资料]

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

Universal Serial Bus (USB) Language Identifiers (LANGIDs) Version 1.0

USB Complete, 5th Edition

USB开发大全

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


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

  • 3
    点赞
  • 12
    收藏
    觉得还不错? 一键收藏
  • 4
    评论
评论 4
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值