如何从软件捕获精确的 USB-HID 设备交互并在我自己的代码中重新实现它

发布于 2024-10-08 21:52:54 字数 1104 浏览 0 评论 0原文

我正在尝试使用一些 USB HID 设备。
我有可以与设备交互的专有软件(来自设备供应商)。但我需要写自己的一个。
在嗅探器工具的帮助下,我捕获了主机和设备之间的流量。此工具是BusDog
然后,我能够通过 WriteFile 使用从 CreateFile 获取的设备句柄(对于从 setupapi.dll API 获取的路径)重现相同的流量。 但设备不会对我的命令做出反应(在 USB/HID 世界中称为“请求”)。

然后我又拿了另一个工具——HHD Device Monitoring Studio。 该工具不仅显示“中断传输”,还显示各种传输。 我可以看到以下日志:

008852: Class-Specific Request (DOWN), 20.12.2010 18:58:10.242 +0.031
Destination: Interface, Index 0
Reserved Bits: 34
Request: 0x9
Value: 0x30d
Send 0x8 bytes to the device

 0D 01 01 00 00 00 00 00                           ........
008853: Control Transfer (UP), 20.12.2010 18:58:10.242 +0.0. Status: 0x00000000
Pipe Handle: 0x8638c5c8

 0D 01 01 00 00 00 00 00                           ........
Setup Packet
 21 09 0D 03 00 00 08 00                           !.......
Recipient: Interface
Request Type: Class
Direction: Host->Device
Request: 0x9 (Unknown)
Value: 0x30d
Index: 0x0
Length: 0x8

我的问题是如何在我自己的代码中重新实现这种传输?以及如何将这些东西解析为适当函数的参数(是DeviceIoControl?)

ps我使用的是C#,但实际上这并不重要,我可以理解C/C++。

I'm trying to work with some USB HID device.
I have proprietary software (from the device's vendor) which can interact with the device. But I need to write my own one.
With help of a sniffer tool I've catched traffic between the host and the device. This tool is BusDog.
Then I was able to reproduce the same traffic via WriteFile with device's handle which I get from CreateFile (for path got from setupapi.dll APIs).
But the device doesn't react on my commands ("requests" as they're called in USB/HID world).

Then I took another tool - HHD Device Monitoring Studio.
This tool shows not only "interrupt transfer" but also all kinds of transfers.
I can see the following log:

008852: Class-Specific Request (DOWN), 20.12.2010 18:58:10.242 +0.031
Destination: Interface, Index 0
Reserved Bits: 34
Request: 0x9
Value: 0x30d
Send 0x8 bytes to the device

 0D 01 01 00 00 00 00 00                           ........
008853: Control Transfer (UP), 20.12.2010 18:58:10.242 +0.0. Status: 0x00000000
Pipe Handle: 0x8638c5c8

 0D 01 01 00 00 00 00 00                           ........
Setup Packet
 21 09 0D 03 00 00 08 00                           !.......
Recipient: Interface
Request Type: Class
Direction: Host->Device
Request: 0x9 (Unknown)
Value: 0x30d
Index: 0x0
Length: 0x8

My question is how to reimplement this kind transfer in my own code? And how to parse this stuff to parameters of appropriate function (is the DeviceIoControl?)

p.s. I'm using C#, but actually it doesn't matter much, I can understand C/C++.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

梦言归人 2024-10-15 21:52:54

查看 HIDClass 支持例程 (http: //msdn.microsoft.com/en-us/library/ff538865%28v=vs.85%29.aspx) 为您封装了所有相关的 HID ioctl...它可能类似于一个功能报告(HidD_SetFeature)。

Have a look at the HIDClass Support Routines (http://msdn.microsoft.com/en-us/library/ff538865%28v=vs.85%29.aspx) which wrap up all the relevant HID ioctls for you... it might be something like a feature report (HidD_SetFeature).

两仪 2024-10-15 21:52:54

我在此答案<中详细介绍了此类事情< /a>.但我会总结一些要点。

首先,您必须找到设备的供应商和产品 ID。 (这些都是独一无二的。)与设备通信的过程很简单。枚举连接的设备,选择与您要查找的 ID 匹配的设备,然后使用类似 libusb< 的库/a> 从设备读取/写入。我链接到的上述堆栈答案的最底部有一个详细的示例。

I detail this kind of thing in a detailed overview in this answer. But I'll summarize some of the main points.

First off, you have to find out the Vendor and Product IDs for the device. (These are unique.) The process of communicating with the device is simple. Enumerate the attached devices, pick the one that matches the IDs you are looking for, then use a library like libusb to read/write from/to the device. There is a detailed example at the very bottom of the above stack answer I linked to.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文