如何区分USB设备类型?
阅读了有关使用 USB 设备的 这个问题后,我想知道操作系统使用什么方法来区分 USB 设备类型?
例如,我可以插入 USB 鼠标,计算机“就知道”它是鼠标。如果我插入 1GB USB 驱动器,它“就知道”它是 1GB 的可移动存储。
设备使用什么类型的代码来“宣布”它是什么类型?或者操作系统正在轮询设备并获得一些标准化响应?
我如何对设备进行编程以将其自身标识为键盘?
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 standardised response?
How would I program a device to identify itself as, say, a keyboard?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
为了构建通过 USB 工作的设备,您几乎肯定必须阅读 http 中提供的 USB 规范://www.usb.org/developers/docs/
关于您的具体问题,有与各种标准 USB 变量关联的 GET 方法。这些存储在设备的固件中并在请求时提供。例如,GET_DESCRIPTOR、GET_STATUS 等是可以发送到设备的请求类型。
USB 有自己的一套协议,要完整实现这些协议将是一项艰巨的任务,因此大多数设备制造商都会从第三方购买 USB 控制器芯片。
如果您只是对一起破解某些东西感兴趣,那么我认为该规范足以让您发送一些数据包。
我能想到的唯一其他选择可能不适合您的项目;窃听真正的键盘,让键盘进行所有复杂的地址解析和设备识别等,然后让您的设备随时将数据推送到电线上。
这是我之前在高中构建一个用于密码嗅探的键盘黑匣子时所管理过的事情,黑匣子存储的按键然后将它们返回到电线上,就像它是键盘一样。一旦它存储了一些密码,并且我检索了它,我必须将其插入键盘,然后拔下键盘,然后将其设置为输出按键(打开一个方便的 gedit 窗口:P),否则键盘会中断传输有自己的数据。
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.
类型(或者更确切地说,设备类)是通过从设备的设备和接口描述符中读取设备的类来确定的。您可能想阅读 这段关于 USB 设备描述符的内容,来自 USB 简介 了解信息。 (如果您有兴趣,我还建议您阅读全文)
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).