【问题标题】:libusb device descriptor: bcdUSB possible valueslibusb 设备描述符:bcdUSB 可能值
【发布时间】:2019-07-17 10:17:46
【问题描述】:

我正在使用 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);

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

bcdUSB: 0401

我不明白这个值的确切含义。

在 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;

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

【问题讨论】:

    标签: c linux usb libusb libusb-1.0


    【解决方案1】:

    我不知道有任何文档描述了 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
    };
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2021-10-24
      • 2019-10-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多