Article 6GGFR modify input events before it gets to user space, not working.

modify input events before it gets to user space, not working.

by
myst�re
from LinuxQuestions.org on (#6GGFR)
Hello,

I'm learning Linux kernel development and am currently experimenting with writing a kernel module. I was wondering how I could process events using my kernel module before it gets to user-space, like cancelling a key press, modifying the pressed key... etc.

I tried multiple approaches that failed and crashed the kernel, and here is the latest code I tried as of for now. Using the kernel even callback, I intercept any input event and am trying to cancel the KEY_A event in this code.

I don't understand what's going wrong and why the kernel requests a hardware restart, as well as why it is not blocking the registration on the user-space.

Code:/**
* @brief Gets called whenever an input device event is reported
* @param handle Handle to the input device
* @param type Event type (see: <linux/input-event-codes.h>)
* @param code Event code (see: <linux/input-event-codes.h>)
* @param value Event value (see: <linux/input-event-codes.h>)
*/
void my_module_event_callback(struct input_handle *handle, unsigned int type, unsigned int code, int value)
{
if (type == EV_KEY) {
pr_info("my_module: event: type=%u, code=%u, value=%d, dev=%s, phys=%s\n", type, code, value, handle->dev->name, handle->dev->phys);
}

if (type == EV_KEY && code == KEY_A && value == 1) {
input_reset_device(handle->dev);
}
}
External Content
Source RSS or Atom Feed
Feed Location https://feeds.feedburner.com/linuxquestions/latest
Feed Title LinuxQuestions.org
Feed Link https://www.linuxquestions.org/questions/
Reply 0 comments