USB笔记 端点描述符 (Endpoint Descriptor)
端点描述符 (Endpoint Descriptor)描述了USB规范定义的端点信息,包含有端点的带宽等信息。每一个端点都有自己的端点描述符。主机端获取端点描述符 (Endpoint Descriptor),总是作为配置描述符(Configuration Descriptor)的一部分返回,不能直接用Get Descriptor
或者Set Descriptor
请求访问。
Endpoint Descriptor
Offset | Field | Size | Value | Description |
---|---|---|---|---|
0 | bLength | 1 | Number | 以字节为单位的描述符大小 |
1 | bDescriptorType | 1 | Constant | 端点描述符类型 |
2 | bEndpointAddress | 1 | Endpoint | 设备的端点地址 |
3 | bmAttributes | 1 | Bitmap | 端点的属性 |
4 | wMaxPacketSize | 2 | Number | 端点能发送或接收的最大数据包大小 |
6 | bInterval | 1 | Number | 查询端点进行数据传输的间隔 |
bLength以字节为单位的描述符大小 (0x07)。
bDescriptorType端点描述符类型,为ENDPOINT (0x05)。
bEndpointAddress 设备的端点地址。
Bits 3…0是端点号,低速设备(Low-speed devices)最多拥有3个端点号(0–2),其他设备则最多拥有16个端点号(0–15)。
Bits 6…4 未使用,保留,必须为0。
Bit 7是方向,OUT = 0 ,IN = 1,控制端点(control endpoints)忽略这个位。
bmAttributes端点的属性。
Bits 1…0表示传输类型,00b表示控制(control),01b表示等时(isochronous), 10b表示批量(bulk),11b表示中断(interrupt)。
Bits 7…6 未使用,保留,必须为0。
Bits 5…2的功能会随端点的类型和速度而改变:
如果是等时端点(isochronous endpoint),Bits 5…2表示同步类型和数据或反馈的使用类型:
Bits 3…2 同步类型(Synchronization Type),00b表示非同步(No Synchronization),01b表示异步(Asynchronous), 10b表示自适应(Adaptive),11b表示同步(Synchronous)。
Bits 5…4 使用类型(Usage Type),00b表示数据端点(Data endpoint),01b表示反馈端点(Feedback endpoint), 10b表示隐式反馈数据端点(Implicit feedback Data endpoint),11b保留(Reserved)。
如果Bits 5…4等于01b,是反馈端点(Feedback endpoint),那么Bits 1…0的传输类型必须为01b,设为等时(isochronous),Bits 3…2的同步类型(Synchronization Type)必须为00b,设为非同步(No Synchronization)。如果是增强型超高速中断端点(Enhanced SuperSpeed interrupt endpoint),Bits 5…2表示使用类型(Usage Type):
Bits 3…2未使用,保留。
Bits 5…4 使用类型(Usage Type),00b表示周期(Periodic),01b表示通知(Notification), 10b和11b保留(Reserved)。如果是其他端点,Bits 5…2未使用,保留,必须为0。
wMaxPacketSize端点能发送或接收的最大数据包大小。不同的速度与传输类型,值的含义不同。
在USB2.0协议中,bits 10…0规定了最大数据包大小,范围0–1024。
对于高速(high-speed)等时(isochronous)和中断(interrupt)端点,Bits 12…11表示每个微帧(microframe)所支持的额外事务数目,00b表明没有额外事务(每个微帧1个事务),01b表示有1个额外事务(每个微帧2个事务),10b表示2个额外事务(每个微帧3个事务),11b表示保留。
其他传输速度与传输类型端点,Bits 12…11未使用。
Bits 15…13未使用,保留,必须为0。
在USB1.x协议中,范围是0–1023。
Bits 12…11保留且必须为0。
Bits 15…13未使用,保留,必须为0。
在USB3.x协议中,对于增强型超高速传输(Enhanced SuperSpeed)
对于控制端点(control endpoints),这个字段必须设为512。
对于批量端点(bulk endpoint),这个字段必须设为1024。
对于中断(interrupt)和等时端点(isochronous endpoints),这个字段的值的大小决定于超高速端点伙伴描述符(SuperSpeed Endpoint Companion Descriptor)中bMaxBurst 的值。如果bMaxBurst 大于0,那么这个字段的值为1024。如果bMaxBurst 等于0,那么对于等时端点 (isochronous endpoint),取值范围是0-1024,对于中断端点(interrupt endpoint),取值范围是1-1024。
bInterval查询端点进行数据传输的间隔。不同的速度与传输类型,值的含义不同。
这个间隔周期以帧(frames)或者微型帧(microframes)为单位进行表示,也就是单位为1ms或者125us。
对于中断端点(interrupt endpoints),在这个间隔周期里面,主机必须安排端点事务。
对于全速(full-speed)/低速(low-speed)中断端点,该字段为最大等待时间,主机必须在这个周期里安排端点事务。单位为ms,取值范围是1-255。全速端点速度限定为1ms-255ms,低速端点速度限定为10ms-255ms。
对于高速(high-speed)中断端点,这个字段bInterval 的值是作为2bInterval−12^{bInterval – 1}2bInterval−1的指数,例如bInterval是4,那就表示周期为8(24−12^{4 – 1}24−1),8个微型帧(microframes),也就是125us×8=1ms。这个值的取值范围为1-16。
对于等时端点(isochronous endpoints),在这个间隔周期里面,主机必须安排端点事务。这个字段bInterval 的值是作为2bInterval−12^{bInterval – 1}2bInterval−1的指数,例如bInterval是4,那就表示周期为8(24−12^{4 – 1}24−1)。
对于全速(full-speed)/高速(high-speed)/增强型超高速端点(Enhanced SuperSpeed endpoints)等时端点,这个值的取值范围为1-16。全速端点的时间范围是1ms-32.768s,高速和超高速端点的时间范围是125us-4.096s
对于USB1.x的等时端点,这个值必须为1。
对于高速(high-speed)批量和控制(bulk/control)OUT端点,此字段表示最大NAK速率,传输中要符合这个字段的要求。值为0表示端点从不发出NAK;其他值表示在用NAK响应OUT处理之后,下一次重试是在bInterval个微型帧之后。这个值的范围为0-255。设备通常设置为0。
对于其他批量和控制端点,此值未使用,被保留。
获取端点描述符
主机通过发送Get Descriptor
请求,取得配置描述符,接口描述符,端点描述符及其附属描述符。端点描述符 (Endpoint 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 | 0x0200(Configuration #0) |
wIndex | 0x0000 |
wLength | 0x???(wTotalLength) |
下面举例说明一个获取端点描述符的过程。
获取一个键盘的端点描述符,该键盘的端点描述符如下所示:
使用USB分析仪抓包可以看到,获取配置描述符Configuration Descriptor,而端点描述符Endpoint Descriptor就包含在其中:
端点描述符Endpoint Descriptor的获取过程如下:
完成整个端点描述符Endpoint 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 |
附录
USB 2.0 Endpoint Descriptor
Offset | Field | Size | Value | Description |
---|---|---|---|---|
0 | bLength | 1 | Number | Size of this descriptor in bytes |
1 | bDescriptorType | 1 | Constant | ENDPOINT Descriptor Type |
2 | bEndpointAddress | 1 | Endpoint | The address of the endpoint on the USB device described by this descriptor. The address is encoded as follows: Bit 3…0: The endpoint number Bit 6…4: Reserved, reset to zero Bit 7: Direction, ignored for control endpoints 0 = OUT endpoint 1 = IN endpoint |
3 | bmAttributes | 1 | Bitmap | This field describes the endpoint’s attributes when it is configured using the bConfigurationValue. Bits 1…0: Transfer Type 00 = Control 01 = Isochronous 10 = Bulk 11 = Interrupt If not an isochronous endpoint, bits 5…2 are reserved and must be set to zero. If isochronous, they are defined as follows: Bits 5…4: Usage Type All other bits are reserved and must be reset to zero. |
4 | wMaxPacketSize | 2 | Number | Maximum packet size this endpoint is capable of sending or receiving when this configuration is selected. For isochronous endpoints, this value is used to reserve the bus time in the schedule, required for the per-(micro)frame data payloads. The pipe may, on an ongoing basis, actually use less bandwidth than that reserved. The device reports, if necessary, the actual bandwidth used via its normal, non-USB defined mechanisms. For all endpoints, bits 10…0 specify the maximum packet size (in bytes). For high-speed isochronous and interrupt endpoints: Bits 12…11 specify the number of additional transaction opportunities per microframe: 00 = None (1 transaction per microframe) 01 = 1 additional (2 per microframe) 10 = 2 additional (3 per microframe) 11 = Reserved Bits 15…13 are reserved and must be set to zero. |
6 | bInterval | 1 | Number | Interval for polling endpoint for data transfers. Expressed in frames or microframes depending on the device operating speed (i.e., either 1 millisecond or 125 µs units). For full-/high-speed isochronous endpoints, this value must be in the range from 1 to 16. The bInterval value is used as the exponent for a 2bInterval−12^{bInterval-1}2bInterval−1 value; e.g., a bInterval of 4 means a period of 8 (24−12^{4-1}24−1). For full-/low-speed interrupt endpoints, the value of this field may be from 1 to 255. For high-speed interrupt endpoints, the bInterval value is used as the exponent for a 2bInterval−12^{bInterval-1}2bInterval−1 value; e.g., a bInterval of 4 means a period of 8 (24−12^{4-1}24−1). This value must be from 1 to 16. For high-speed bulk/control OUT endpoints, the bInterval must specify the maximum NAK rate of the endpoint. A value of 0 indicates the endpoint never NAKs. Other values indicate at most 1 NAK each bInterval number of microframes. This value must be in the range from 0 to 255. |
USB 3.x Endpoint Descriptor
Offset | Field | Size | Value | Description |
---|---|---|---|---|
0 | bLength | 1 | Number | Size of this descriptor in bytes |
1 | bDescriptorType | 1 | Constant | ENDPOINT Descriptor Type |
2 | bEndpointAddress | 1 | Endpoint | The address of the endpoint on the USB device described by this descriptor. The address is encoded as follows: Bit 3…0: The endpoint number Bit 6…4: Reserved, reset to zero Bit 7: Direction, ignored for control endpoints 0 = OUT endpoint 1 = IN endpoint |
3 | bmAttributes | 1 | Bitmap | This field describes the endpoint’s attributes when it is configured using the bConfigurationValue. Bits 1…0: Transfer Type 00 = Control 01 = Isochronous 10 = Bulk 11 = Interrupt If an interrupt endpoint, bits 5…2 are defined as follows: Bits 5…4: Usage Type If not an isochronous or interrupt endpoint, bits 5…2 are reserved and shall be set to zero. |
4 | wMaxPacketSize | 2 | Number | Maximum packet size this endpoint is capable of sending or receiving when this configuration is selected. For control endpoints this field shall be set to 512. For bulk endpoint types this field shall be set to 1024. For interrupt and isochronous endpoints this field shall be set to 1024 if this endpoint defines a value in the bMaxBurst field greater than zero. If the value in the bMaxBurst field is set to zero then this field can have any value from 0 to 1024 for an isochronous endpoint and 1 to 1024 for an interrupt endpoint. |
6 | bInterval | 1 | Number | Interval for servicing the endpoint for data transfers. Expressed in 125-µs units. For Enhanced SuperSpeed isochronous and interrupt endpoints, this value shall be in the range from 1 to 16. However, the valid ranges are 8 to 16 for Notification type Interrupt endpoints. The bInterval value is used as the exponent for a KaTeX parse error: Expected 'EOF', got '}' at position 18: …{}(bInterval-1)}̲ value; e.g., a bInterval of 4 means a period of 8 (2(4−1)2^{(4-1)}2(4−1) → 232^323 → 8). This field is reserved and shall not be used for Enhanced SuperSpeed bulk or control endpoints. |
USB 1.x Endpoint Descriptor
Offset | Field | Size | Value | Description |
---|---|---|---|---|
0 | bLength | 1 | Number | Size of this descriptor in bytes |
1 | bDescriptorType | 1 | Constant | ENDPOINT Descriptor Type |
2 | bEndpointAddress | 1 | Endpoint | The address of the endpoint on the USB device described by this descriptor. The address is encoded as follows: Bit 3…0: The endpoint number Bit 6…4: Reserved, reset to zero Bit 7: Direction, ignored for control endpoints 0 = OUT endpoint 1 = IN endpoint |
3 | bmAttributes | 1 | Bitmap | This field describes the endpoint’s attributes when it is configured using the bConfigurationValue. Bits 1…0: Transfer Type 00 = Control 01 = Isochronous 10 = Bulk 11 = Interrupt All other bits are reserved. |
4 | wMaxPacketSize | 2 | Number | Maximum packet size this endpoint is capable of sending or receiving when this configuration is selected. For isochronous endpoints, this value is used to reserve the bus time in the schedule, required for the per-frame data payloads. The pipe may, on an ongoing basis, actually use less bandwidth than that reserved. The device reports, if necessary, the actual bandwidth used via its normal, non-USB defined mechanisms. For interrupt, bulk, and control endpoints, smaller data payloads may be sent, but will terminate the transfer and may or may not require intervention to restart. |
6 | bInterval | 1 | Number | Interval for polling endpoint for data transfers. Expressed in milliseconds. This field is ignored for bulk and control endpoints. For isochronous endpoints this field must be set to 1. For interrupt endpoints, this field may range from 1 to 255. |
[参考资料]
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
USB Complete, 5th Edition
USB开发大全
USB2.0与OTG规范及开发指南
本文链接:https://blog.csdn.net/u012028275/article/details/109689169