Write Something to Linux Hid Device

Write something to linux hid device?

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>...

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 also defines "Features", that are an output control mechanism, but I've never used them.

How can I capture raw HID input on Linux?

You'll want uinput. You'll listen on your /dev/usb/hiddev0 and then create new events that you'll send out on /dev/input/uinput.

This explains it and gives a little tutorial:
Using uinput driver in Linux- 2.6.x to send user input {This is the EInfochips' "Dashboard" publication issue January 2007 "Tip of the Month" article mentioned on this archived page}.

Writing to HID keyboard works on Linux but not on Windows

Alright, so I managed to finally get it working!
Basically, I switched from the Java HIDAPI to hid4java, modified the code to do the same thing, and it worked like a charm ! (On Windows)

I also removed the first byte in the buffer, and used it as the reportId parameter in hid4java's HidDevice.sendFeatureReport function. This shifted all the bytes over by 1, but this was easily fixed by subtracting 1 at the index when a value in the buffer was to be set. (Not shown in the example of my question.)

I haven't yet tested this on Linux though, but I'd assume it would still work.



Related Topics



Leave a reply



Submit