c - 在设备固件中支持 WinUSB

标签 c windows winusb

我正在尝试设置一个 USB 设备,使其在连接到 Windows 8 机器时自动使用 WinUSB 作为驱动程序,如所述 here .

它说:

In order for the USB driver stack to know that the device supports extended feature descriptors, the device must define an OS string descriptor that is stored at string index 0xEE.

我的意思是我需要在内存位置 0xEE 处创建一个包含描述符的结构。我将如何在 C 中解决这个问题?

这是我尝试过的:

// The struct definition
typedef struct {
    uint8_t bLength;
    uint8_t bDescriptorType;
    uint8_t qwSignature[14];
    uint8_t bMS_VendorCode;
    uint8_t bPad;
} usb_os_str_desc_t;

// Create a pointer to a struct located at 0xEE
volatile usb_os_str_desc_t* const extended_feature_support = (usb_os_str_desc_t*) 0xEE;

// Create a new struct at the location specified in "extended_feature_support"
(*extended_feature_support) = {
    .bLength = 0x12,
    .bDescriptorType = 0x03,
    .qwSignature = "MSFT100",
    .bMS_VendorCode = 0x04,
    .bPad = 0x00
};

但是编译器不喜欢这样,提示数据定义没有类型。 有没有办法在 C 中做到这一点?我对这篇文章的理解正确吗?

如有任何帮助,我们将不胜感激。

最佳答案

这根本不是它在说什么。您必须响应 USB 请求,而不是将结构放置在嵌入式系统内存的特定位置。

Windows 将在第一次看到 VID:PID:Serial 时请求索引 0xee 处的操作系统字符串描述符。设备必须响应与您显示的结构格式匹配的数据包。如果返回的描述符中的所有内容都是正确的(您的示例看起来不错),Windows 将发出设备供应商请求,并将 bReq 设置为您在字符串描述符响应中提供的 MS_VendorCode(您的示例中为 0x04)。

如果您的设备使用正确的操作系统功能描述符进行响应,那么奇迹就会发生。人们通常想要的魔法是让他们的设备在不提供 .inf 文件的情况下使用 winusb 驱动程序。

请注意,此请求只会发生一次。如果你正在开发一个设备,你通常会想做很多很多次。为此,您必须从设备管理器中卸载设备,然后在注册表编辑器中,在 HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\usbflags 下查找您的 VIDPIDRELEASE 并将其删除。现在,当您再次插入设备时,它将再次执行此操作系统字符串描述符请求。

请引用https://github.com/pbatard/libwdi/wiki/WCID-Devices有关更多信息,它比 MS 提供的文档更清晰。

关于c - 在设备固件中支持 WinUSB,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17666006/

相关文章:

windows - 如何在安装程序 cab 的 Windows Mobile 程序菜单上放置快捷方式?

windows - WinUSB 在非开发计算机上失败

windows - 我可以将 WinUSB 与内置 HID 驱动程序一起使用吗?

c - setsockopt 异常错误, "Protocol not available"

c - 高效的C/C++多线程程序可对数据进行分区和处理

windows - 无法连接到运行 IIS 的服务器上的 Localhost

c++ - #include <WinUsb.h> 在 MFC 应用程序中产生编译器错误

C套接字编程: Invalid argument error on connect()

c++ - 如何以编程方式在 C/C++ 中导致核心转储

Python 脚本使用 while 循环来不断更新作业脚本并多处理队列中的任务