简体   繁体   中英

How to catch exact USB-HID device interaction from a software and reimplement it in my own code

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?)

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

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.

看看HIDClass支持例程( http://msdn.microsoft.com/en-us/library/ff538865%28v=vs.85%29.aspx ),它们将为您提供所有相关的HID ioctl ...它可能类似于特征报告(HidD_SetFeature)。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM