写一些东西到Linux的隐藏设备? [英] Write something to linux hid device?

查看:81
本文介绍了写一些东西到Linux的隐藏设备?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在学习linux hid驱动程序编程,我知道如何从hid设备读取消息
但是,我不知道如何向设备写入内容?例如USB隐藏键盘,我可以使用 xset或其他程序来控制键盘的led,该如何存档?请提供任何提示!
谢谢你.

I am learning linux hid driver programming, i know how to read a message from hid device
but, i am puzzled how to write something to the device ? such as usb hid keyboard, i can use xset or some other program to control the leds of the keyboard, how to archive that? Any tips please!
thanks advance.

推荐答案

USB HID设备主要是输入设备,因此它们通常不提供OUT端点(HID规范允许它们使用,但我从未见过这样的设备) ).如果未提供OUT端点,则通过控制端点(EP0)发送输出报告. URB应该是这样的:

USB HID devices are mostly input devices, so they don't usually provide an OUT endpoint (they are allowed by the HID specification but I've never seen one). If an OUT endpoint is not provided, then output reports are sent through the control endpoint (EP0). The URB should be something like this:

bmRequestType = 0x21     (To class interface)
bRequest = 0x09          (SET_REPORT)
wValue = 0x02 <report_code>
wIndex = <interface>     (Usually 0x0001)
wLength = <Data length>
Data = <report_code> <data>...

自然地,有一些功能可以做到这一点.在内核中,您可以查看hiddev_lookup_report/usbhid_submit_report.从userland,如果您使用/dev/usb/hiddev?您可以尝试HIDIOCSREPORT ioctl,如果使用/dev/hidraw?您只需将()写入其中.

Naturally, there are functions that do just that. From kernel, you may look at hiddev_lookup_report/usbhid_submit_report. From userland, if you use /dev/usb/hiddev? you may try the HIDIOCSREPORT ioctl, and if you use /dev/hidraw? you simply write() into it.

HID还定义了功能",这是一种输出控制机制,但我从未使用过它们.

HID also defines "Features", that are an output control mechanism, but I've never used them.

这篇关于写一些东西到Linux的隐藏设备?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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