根据USB版本判断USB速率
2021-08-30
944
0
USBIP驱动层中有一段代码,是通过USB的版本来判断当前USB的速率。判断的标准是以USB设备描述符bcdUSB字段来判断的。
static const struct speed_string speed_strings[] = {
{ USB_SPEED_UNKNOWN, "unknown", "Unknown Speed"},
{ USB_SPEED_LOW, "1.5", "Low Speed(1.5Mbps)" },
{ USB_SPEED_FULL, "12", "Full Speed(12Mbps)" },
{ USB_SPEED_HIGH, "480", "High Speed(480Mbps)" },
{ USB_SPEED_WIRELESS, "53.3-480", "Wireless" },
{ USB_SPEED_SUPER, "5000", "Super Speed(5000Mbps)" },
{ 0, NULL, NULL }
};
enum usb_device_speed {
USB_SPEED_UNKNOWN = 0, /* enumerating */
USB_SPEED_LOW, USB_SPEED_FULL, /* usb 1.1 */
USB_SPEED_HIGH, /* usb 2.0 */
USB_SPEED_WIRELESS, /* wireless (usb 2.5) */
USB_SPEED_SUPER, /* usb 3.0 */
USB_SPEED_SUPER_PLUS /* usb 3.1 */
};
UCHAR get_speed_from_bcdUSB(USHORT bcdUSB)
{
switch (bcdUSB) {
case 0x0100:
return USB_SPEED_LOW;
case 0x0110:
return USB_SPEED_FULL;
case 0x0200:
return USB_SPEED_HIGH;
case 0x0250:
return USB_SPEED_WIRELESS;
case 0x0300:
return USB_SPEED_SUPER;
case 0x0310:
return USB_SPEED_SUPER_PLUS;
default:
return USB_SPEED_UNKNOWN;
}
}
测试程序是:
devinfo->vendor = desc.idVendor;
devinfo->product = desc.idProduct;
devinfo->speed = get_speed_from_bcdUSB(desc.bcdUSB);
devinfo->class = desc.bDeviceClass;
devinfo->subclass = desc.bDeviceSubClass;
devinfo->protocol = desc.bDeviceProtocol;
HID人机交互QQ群:564808376
UAC音频QQ群:218581009
UVC相机QQ群:331552032
BOT&UASP大容量存储QQ群:258159197
STC-USB单片机QQ群:315457461
USB技术交流QQ群2:580684376
USB技术交流QQ群:952873936