Virtual USB HID device

hidusbvirtual machine

I'm developing an application that will communicate with attached USB HID device. The problem is that there is no real device yet (it is under development by another part of our team), so, I'd really like to have some way to emulate it.

The ideal utility which I can think of should look like this: a kernel module, that, when loaded, creates two device nodes in the system:

  • a virtual usb-hid device, which is indistinguishable from any real usb-hid device node, probably /dev/hidraw0; and of course this device should be seen by whatever usb-hid libraries I'd use, for example, hidapi.
  • a service device node, like /dev/virtual_hid_1.

So, when anyone writes to /dev/virtual_hid_1, this data should be literally read from /dev/hidraw0, and vice versa.

This way, I can write some debug app in any language I want, be it python or whatever; it should merely write and read to and from /dev/virtual_hid_1. It would be very convenient for development.

Is there something like this?

Best Answer

You're probably looking for uhid kernel module. See documentation in kernel sources:

With UHID, a user-space transport driver can create kernel hid-devices for each device connected to the user-space controlled bus. The UHID API defines the I/O events provided from the kernel to user-space and vice versa.

There is an example user-space application in ./samples/uhid/uhid-example.c

Related Question