如何区分 USB 设备类型? [英] How to differentiate between USB device types?

查看:65
本文介绍了如何区分 USB 设备类型?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在阅读关于使用 USB 设备的这个问题后,我想知道操作系统使用什么方法来区分 USB 设备的类型?

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?

例如,我可以插入一个 USB 鼠标,而计算机只知道"这是一个鼠标.如果我插入我的 1GB USB 驱动器,它就知道"它有 1GB 的可移动存储空间.

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 standardised response?

我将如何对设备进行编程以将其识别为键盘?

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

推荐答案

为了构建可通过 USB 工作的设备,您几乎肯定必须阅读 http://www.usb.org/developers/docs/

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/

关于您的具体问题,有与各种标准 USB 变量相关联的 GET 方法.这些存储在设备的固件中,并在需要时提供.例如,GET_DESCRIPTOR、GET_STATUS 等是可以发送到设备的请求类型.

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 有自己的一套协议,要全面实施这些协议是一项艰巨的任务,因此大多数设备制造商会从第三方购买 USB 控制器芯片.

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.

这是我以前在高中时构建用于密码嗅探的键盘黑匣子时管理的事情,黑匣子存储的按键然后将它们反流到电线上,就好像它是键盘一样.一旦它存储了一些密码,并且我检索了它,我必须将它插入连接到键盘,然后在将其设置为输出按键之前拔下键盘(打开一个方便的 gedit 窗口:P)否则键盘会中断用自己的数据传输.

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.

这篇关于如何区分 USB 设备类型?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆