libusb 设备描述符:bcdUSB 可能值

Kal*_*mar 5 c linux usb libusb libusb-1.0

我正在使用 libusb-1.0 开发一个 C 应用程序。我想获取一些与USB设备相关的配置参数。我的问题与 bcdUSB 参数有关。我的代码如下:

libusb_device *dev;
struct libusb_device_descriptor desc;

....

ret = libusb_get_device_descriptor(dev, &desc);

if (ret<0) {
    fprintf(stderr, "error in getting device descriptor\n");
    return 1;
}

printf("bcdUSB: %04x\n", desc.bcdUSB);
Run Code Online (Sandbox Code Playgroud)

对于某些设备,我得到 0401 值:

bcdUSB: 0401
Run Code Online (Sandbox Code Playgroud)

我不明白这个值的具体含义是什么。

在libusb代码中,我在libusb_device_descriptor结构代码中找到了这个注释:

/** USB specification release number in binary-coded decimal. A value of
 * 0x0200 indicates USB 2.0, 0x0110 indicates USB 1.1, etc. */
uint16_t bcdUSB;
Run Code Online (Sandbox Code Playgroud)

它仅指定 0200 和 0110 值的含义。是否有包含 0401 在内的 bcdUSB 所有可能值的文档?

Bor*_*itz 2

我不知道有任何文档描述了 bcdUSB 的所有可能值,但不得不提一件事。没有什么可以阻止 USB 设备发送无效的设备描述符内容。虽然我没有对任何东西进行精确测试,但在我看来,操作系统很可能会忽略错误的 bcdUSB,而设备继续按预期运行。

确保有一些合理的默认值,以防遇到无效值。

只是为了演示,这就是在设备端定义设备描述符的方式。几乎是“硬编码”。是的,这是来自实际库的实际代码,在实际设备上运行。

/*-----------------------------------------------------------------------------+
| Device Descriptor 
|-----------------------------------------------------------------------------*/
uint8_t const abromDeviceDescriptor[SIZEOF_DEVICE_DESCRIPTOR] = {
    SIZEOF_DEVICE_DESCRIPTOR,               // Length of this descriptor
    DESC_TYPE_DEVICE,                       // Type code of this descriptor
    0x00, 0x02,                             // Release of USB spec
    0x02,                                   // Device's base class code
    0x00,                                   // Device's sub class code
    0x00,                                   // Device's protocol type code
    EP0_PACKET_SIZE,                        // End point 0's packet size
    USB_VID&0xFF, USB_VID>>8,               // Vendor ID for device, TI=0x0451
                                            // You can order your own VID at www.usb.org"
    USB_PID&0xFF, USB_PID>>8,               // Product ID for device,
                                            // this ID is to only with this example
    VER_FW_L, VER_FW_H,                     // Revision level of device
    1,                                      // Index of manufacturer name string desc
    2,                                      // Index of product name string desc
    USB_STR_INDEX_SERNUM,                   // Index of serial number string desc
    1                                       //  Number of configurations supported
};
Run Code Online (Sandbox Code Playgroud)