c - libusb 设备描述符 : bcdUSB possible values

标签 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);

对于某些设备,我得到 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 值的含义。是否有 bcdUSB 所有可能值的文档,包括 0401 ?

最佳答案

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

关于c - libusb 设备描述符 : bcdUSB possible values,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57073590/

相关文章:

c - 将 “pointer to pointer” 和 “address of pointer” 传递给函数之间的区别

c++ - C/C++ - 检查今天是否是本月的第一个星期一

c - gcc 中的 -ffreestanding 选项是什么?

regex - awk/sed 在两个模式之间插入行

c++ - 国际 UTF-32 字符串输出到 Linux 中的控制台

C++ 从外部设备读取数据 - 连接 : OPTO-USB

C:内存中的循环、条件、结构

linux - 将 -rdynamic 链接器选项添加到 gcc/g++ 会影响性能吗?

c++ - 在 windows xp 中获取所有已注册的 usb hid 设备的列表

linux - USB HID OUT 报告 - 哪个端点是正确的?