开发者

How to differentiate between USB device types?

Having read up on this question regarding working with USB devices, I got to wondering what method is being used by the operating system to differentiate between types of USB device?

For example, I can plug in a USB mouse and the computer "just knows" it's a mouse. If I plug in my 1GB USB drive it "just knows" it's 1GB's worth of removable storage.

What sort of code is being used by the device to 'announce' what type it is? Or is the operating system polling the device and getting some st开发者_如何学编程andardised response?

How would I program a device to identify itself as, say, a keyboard?


In order to build a device that works over USB, you will almost certainly have to read the USB specification available from http://www.usb.org/developers/docs/

In regards to your specific question, there are GET methods associated with various standard USB variables. These are stored in the firmware of the device and provided when requested. Eg, GET_DESCRIPTOR, GET_STATUS etc are request types that can be sent to the device.

USB has its own set of protocols that would be quite a task to implement in their entirety, so most device manufacturers buy a USB controller chip from some third party.

If you're just interested in hacking something together, then I think the specification will be enough to get you sending a few packets.

The only other option I can think of may not be suitable for your project; wire-tap a real keyboard, let the keyboard to all the complicated address resolution and device identification etc, then just have your device push data onto the wires as and when.

This is something I have managed before when I build a keyboard black-box for password sniffing at high-school, the black-box stored keypresses then regurgitated them onto the wires as if it were a keyboard. Once it had stored a few passwords, and I retrieved it, I had to plug it in attached to the keyboard, then unplug the keyboard before setting it to output the keypresses (with a handy gedit window open :P) otherwise the keyboard would interrupt the transmission with its own data.


The type (or rather, the device class) is determined by reading the device's class from the device's device and interface descriptors. You may want to read this segment about USB device descriptors from USB in a Nutshell for information. (I also recommend reading the whole thing, if you're interested)


In Device Manager open the properties of a device and select the Details tab. The various values give the information (or rather is generated from the information from the device and its driver).

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜