Linux ioctl() with a virtual device

294 views Asked by At

I want to create a virtual device on my Linux system. I am using libevdev. The first thing I do is to mirror an existing device. The new virtual device with all the same event types, event codes etc. is created:

libevdev* dev = nullptr;
int fd = open("/dev/input/event16", O_RDONLY);
libevdev_new_from_fd(fd, &dev);

libevdev_uinput* uidev = nullptr;
int uifd = open("/dev/uinput", O_RDWR);
err = libevdev_uinput_create_from_device(dev, uifd, &uidev);

After above lines of code a new file event17 is created in a directory /dev/input.

The next thing I want to do is to call ioctl():

int fd = open("/dev/input/event17", O_RDWR);
ioctl(fd, REQUEST_VALUE, &data);

but ioctl ends up with a connection timeout.

So the question is: how to invoke ioctl() on the virtual devices? Is it even possible? Is there any functionality on Linux kernel which allows virtual devices to behave as they were real devices?

0

There are 0 answers