根据USB版本判断USB速率

14 0 2021-06-24 本文地址:http://www.usbzh.com/fun/detail-29.html

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;
取消
感谢您的支持,我会继续努力的!
扫码支持
扫码打赏,你说多少就多少

打开支付宝扫一扫,即可进行扫码打赏哦

您的支持,是我们前进的动力!