Hottest Free Downloads - DownloadPipe.com Over 197,000 downloads! Bookmark Now!
DownloadPipe.com - New Downloads Every Minute
 SEARCH:
FAQFAQ    SearchSearch      ProfileProfile    Private MessagesPrivate Messages   Log inLog in

overriding keyboard driver in a module

 
   Linux (Home) -> Kernel RSS
Next:  USB OOPS 2.6.12  
Author Message
Genadz Batsyan

External


Since: Jul 07, 2005
Posts: 1



(Msg. 1) Posted: Thu Jul 07, 2005 3:50 am
Post subject: overriding keyboard driver in a module
Archived from groups: linux>kernel (more info?)

I'm writing a little tool to allow intercepting keyboard events and
substituting them with other events / swallowing events / emitting additional
events on a low level before normal processing by kernel.
http://kbd-mangler.sourceforge.net/

Currently to have precedense over the keyboard driver I'm using a patch
against drivers/input/keyboard/atkbd.c

Well, I guess, patching kernel is unthinkable for most linux users, so I
thought, maybe there is a way to do it without the kernel patch.
Is it possible to write a kernel module to intercept keyboard events
and have precedense over the kernel driver?

If anyone is interested, below is my patch.
I know it's damn dirty (especially the last_dev thingy Smile
but take it easy, it's my first kernel undertaking, a product of a few days,
and most importantly - it works.

Any kind of suggestions would be appreciated a lot.

-----------------------

--- linux-2.6.11.6-orig/drivers/input/keyboard/atkbd.c 2005-03-26
04:28:48.000000000 +0100
+++ linux-2.6.11.6-patched/drivers/input/keyboard/atkbd.c 2005-07-01
22:15:52.000000000 +0200
@@ -34,6 +34,10 @@
MODULE_DESCRIPTION(DRIVER_DESC);
MODULE_LICENSE("GPL");

+
+#define CONFIG_KBD_INTERCEPTOR 1
+
+
static int atkbd_set = 2;
module_param_named(set, atkbd_set, int, 0);
MODULE_PARM_DESC(set, "Select keyboard code set (2 = default, 3 = PS/2
native)");
@@ -229,18 +233,79 @@
ATKBD_DEFINE_ATTR(softraw);


-static void atkbd_report_key(struct input_dev *dev, struct pt_regs *regs, int
code, int value)
+
+
+
+#ifdef CONFIG_KBD_INTERCEPTOR
+
+typedef int (*KBD_INTERCEPTOR)(int *, int *);
+
+static KBD_INTERCEPTOR kbd_interceptor;
+static struct input_dev *last_dev;
+
+#endif
+
+
+
+
+static void _atkbd_report_key(struct input_dev *dev, int code, int value)
{
- input_regs(dev, regs);
if (value == 3) {
input_report_key(dev, code, 1);
input_sync(dev);
input_report_key(dev, code, 0);
} else
input_event(dev, EV_KEY, code, value);
+}
+
+static void atkbd_report_key(struct input_dev *dev, struct pt_regs *regs, int
code, int value)
+{
+ input_regs(dev, regs);
+
+#ifdef CONFIG_KBD_INTERCEPTOR
+ if (kbd_interceptor && kbd_interceptor(&code, &value))
+ {
+ return;
+ }
+#endif
+ _atkbd_report_key(dev, code, value);
input_sync(dev);
}

+#ifdef CONFIG_KBD_INTERCEPTOR
+KBD_INTERCEPTOR kbd_set_interceptor(KBD_INTERCEPTOR interceptor)
+{
+ KBD_INTERCEPTOR old = kbd_interceptor;
+ kbd_interceptor = interceptor;
+ return old;
+}
+
+void kbd_emit_key(int code, int down)
+{
+ if (last_dev)
+ _atkbd_report_key(last_dev, code, down);
+ else
+ printk("kbd_emit_key: input_dev not set\n");
+}
+void kbd_emit_sync()
+{
+ if (last_dev)
+ input_sync(last_dev);
+ else
+ printk("kbd_emit_key: input_dev not set\n");
+}
+
+
+EXPORT_SYMBOL(kbd_set_interceptor);
+EXPORT_SYMBOL(kbd_emit_key);
+EXPORT_SYMBOL(kbd_emit_sync);
+
+#endif
+
+
+
+
+
/*
* atkbd_interrupt(). Here takes place processing of data received from
* the keyboard into events.
@@ -660,6 +725,10 @@
{
struct atkbd *atkbd = serio->private;

+#ifdef CONFIG_KBD_INTERCEPTOR
+ last_dev = NULL;
+#endif
+
atkbd_disable(atkbd);

/* make sure we don't have a command in flight */
@@ -847,6 +916,10 @@

input_register_device(&atkbd->dev);

+#ifdef CONFIG_KBD_INTERCEPTOR
+ last_dev = &atkbd->dev;
+#endif
+
device_create_file(&serio->dev, &atkbd_attr_extra);
device_create_file(&serio->dev, &atkbd_attr_scroll);
device_create_file(&serio->dev, &atkbd_attr_set);
@@ -1097,6 +1170,9 @@

int __init atkbd_init(void)
{
+#ifdef CONFIG_KBD_INTERCEPTOR
+ last_dev = NULL;
+#endif
serio_register_driver(&atkbd_drv);
return 0;
}



-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo RemoveThis @vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
Back to top
Login to vote
Dmitry Torokhov

External


Since: Jul 07, 2005
Posts: 41



(Msg. 2) Posted: Thu Jul 07, 2005 7:30 am
Post subject: Re: overriding keyboard driver in a module [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

Genadz Batsyan <gbatyan.DeleteThis@gmx.net> wrote:
> I'm writing a little tool to allow intercepting keyboard events and
> substituting them with other events / swallowing events / emitting
> additional
> events on a low level before normal processing by kernel.
> http://kbd-mangler.sourceforge.net/
>
> Currently to have precedense over the keyboard driver I'm using a patch
> against drivers/input/keyboard/atkbd.c
>
> Well, I guess, patching kernel is unthinkable for most linux users, so I
> thought, maybe there is a way to do it without the kernel patch.
> Is it possible to write a kernel module to intercept keyboard events
> and have precedense over the kernel driver?
>

You can try opening corresponding event device (/dev/input/eventX),
grabbing it so nobody except for your process would get any events
from the corresponding keyboard (EVIOCGRAB ioctl), and then read
events, mangle them and inject them back into kernel through uinput
driver.

As an additional plus it should work for any keyboard (or rather any
input device), not only PS/2 keyboard.

--
Dmitry
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo.DeleteThis@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
Back to top
Login to vote
Display posts from previous:   
Related Topics:
function to zero out module ref count so module can be unl.. - In 2.4 kernel one could check MOD_IN_USE and repeatedly call MOD_DEC_USE_COUNT until the ref count drops to zero. Is there a function in 2.6 kernel that would zero out the ref count so that module can be unloaded ? Need to implement ioctl for a driver....

2.6.9 Kernel + 3780 Keyboard - I’m doing some work on attempting to get an old 3780 keyboard (yes those old 34 function key IBM/AT keyboards are still wondering around) working on a 2.6.9 kernel system. The keyboard of course use to work on 2.4.x system, as long as we forced the..

Stripping in module - Hi, at the moment I am packaging a Linux module as an RPM archive. Therefor I would like to remove some of the not exported/needed symbols (like e.g. static functions or constants) from the Linux module. What is the best way to do this with v2.6. I..

[BUG] module ns558 - Hello dear Kernel People, I have a problem with my gameport, it uses the ns558 driver, the module gets loaded via hotplug/udev at boot, but the gameport gets deactivated somehow. I have this Problem for a long time now, and my solution always was rmmod...

I can not build a new kernel image with a assembly module - Hi I had added an assembly program to the networking section of kernel linux 2.2.16 without any problem. But when I add it to kerenel 2.4.1 I could build that kernel, but I faced with kernel panic error when I boot system with new builded image. I use..
       Linux (Home) -> Kernel All times are: Pacific Time (US & Canada) (change)
Page 1 of 1

 
You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
Categories:
 Windows Forums
 Game Forums
  Linux Forums
 Mac Forums
 PDA Forums
 Mobile Forums
  Top  |  Store  |  RSS Feeds RSS  |  Data Feeds  |  Advertise  |  Submit  |  Bookmark  |  Newsletter  |  Contact