0

I have a kernel module that reads usb keyboard input specifically from /dev/input/event2 and /dev/input/event3.

On some devices the keyboard doesn't get assigned event2 and event3, it gets assigned /dev/input/event3 and /dev/input/event4 which of course causes the module to miss input.

I have pored over the udev rules and examples, but I cannot seem to find a way to force udev to assign a specific event# character device. I can get it to assign additional whatever else such as, /dev/input/mydevice, etc, but that doesn't help in this case. Is this possible?

As a further complication, the plugged in device isn't really a keyboard, it's a wireless presenter and it assigns a mouse to event2, the volume up/down button to event3, and the forward back buttons to event4. Like the following:

drwxr-xr-x 160 Apr  1 00:05 .
drwxr-xr-x 240 Apr  1 00:05 ..
*lrwxrwxrwxroot  9 Apr  1 00:05 platform-fsl-ehci.0-usb-0:1:1.0-event-mouse -> ../event2
lrwxrwxrwx 9 Apr  1 00:05 platform-fsl-ehci.0-usb-0:1:1.0-mouse -> ../mouse0
*lrwxrwxrwx 9 Apr  1 00:05 platform-fsl-ehci.0-usb-0:1:1.1-event-kbd -> ../event3
*lrwxrwxrwx 9 Apr  1 00:05 platform-fsl-ehci.0-usb-0:1:1.2-event-kbd -> ../event4
lrwxrwxrwx 9 Apr  1 00:00 platform-imx-i2c.0-platform-max77696-onkey.0-event -> ../event0
lrwxrwxrwx 9 Apr  1 00:00 platform-imx-i2c.1-event -> ../event1

And I need it to look like this:

drwxr-xr-x 160 Apr  1 00:05 .
drwxr-xr-x 240 Apr  1 00:05 ..
*lrwxrwxrwxroot  9 Apr  1 00:05 platform-fsl-ehci.0-usb-0:1:1.0-event-mouse -> ../event4
lrwxrwxrwx 9 Apr  1 00:05 platform-fsl-ehci.0-usb-0:1:1.0-mouse -> ../mouse0
*lrwxrwxrwx 9 Apr  1 00:05 platform-fsl-ehci.0-usb-0:1:1.1-event-kbd -> ../event3
*lrwxrwxrwx 9 Apr  1 00:05 platform-fsl-ehci.0-usb-0:1:1.2-event-kbd -> ../event2
lrwxrwxrwx 9 Apr  1 00:00 platform-imx-i2c.0-platform-max77696-onkey.0-event -> ../event0
lrwxrwxrwx 9 Apr  1 00:00 platform-imx-i2c.1-event -> ../event1

The value I think to need to change is the "KERNEL" value. Using udevadm info on the mouse device I get the following results.

[root@kin input]# udevadm info -a -p $(udevadm info -q path -n /dev/input/by- path/platform-fsl-ehci.0-usb-0:1:1.0-event-mouse

looking at device '/devices/platform/fsl-ehci.0/usb1/1-1/1-1:1.0/input/input26/event2':
    KERNEL=="event2"
    SUBSYSTEM=="input"
    DRIVER==""

  looking at parent device '/devices/platform/fsl-ehci.0/usb1/1-1/1-1:1.0/input/input26':
    KERNELS=="input26"
    SUBSYSTEMS=="input"
    DRIVERS==""
    ATTRS{name}=="Genius Wireless Mouse"
    ATTRS{phys}=="usb-fsl-ehci.0-1/input0"
    ATTRS{uniq}==""
    ATTRS{modalias}=="input:b0003v0458p0189e0101-e0,1,2,4,k110,111,112,113,114,r0,1,6,8,am4,lsfw"
ATTRS{properties}=="0"
  • 1
    That's a FAQ. You don't assign numbers for anything created in /dev. Instead, you create symlinks with known names to specific devices (like your kernel module), and then use the symlinks instead of /dev/input/event2 etc. And no, it doesn't work the other way round (forcing specific numbers), even if you think it should. – dirkt Feb 22 at 14:21
  • As I said in my post, I can create symlinks just fine and that is useless to me because the kernel module is hard coded to use event2/3. I have no opinion on how it should work. It sounds like you don't know any way to solve this issue, hopefully someone else does. – Eru007 Feb 22 at 15:12
  • A kernel module that reads events by opening specific files instead of using the kernel API to get events is quite unusual, to put it mildly. The way I would solve this is to use dd or a hexeditor to patch the kernel module to use some other paths instead, them create those paths as symlinks with udev. – dirkt Feb 23 at 16:37
  • 1
    Ok now we're talking! I hadn't thought of patching the module like that. I tried erasing event2 and recreating it with mknod with the major,minor numbers I needed, and it worked. I got the keyboard output previously on event4 on event2, but the module was not aware of the change. I'll look into how to patch the module directly. Thank you for your assistance! – Eru007 Feb 25 at 6:36
  • dirkt for the win! I edited the file with a hex editor and voila, it's working. Thank you so much. Shoulda just asked here first...woulda saved me about 20 some hours. – Eru007 Feb 25 at 10:05
1

A kernel module that reads events by opening specific files instead of using the kernel API to get events is quite unusual, to put it mildly.

The way I would solve this is to use dd or a hexeditor to patch the kernel module to use some other paths instead, them create those paths as symlinks with udev.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.