Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using Linux virtual mouse driver

I am trying to implement a virtual mouse driver according to the Essential Linux device Drivers book. There is a user space application, which generates coordinates as well as a kernel module.

See: Virtual mouse driver and userspace application code and also a step by step on how to use this driver.

1.) I compile the code of the user space application and driver.

2.) Next i checked dmesg output and have,

input: Unspecified device as /class/input/input32
Virtual Mouse Driver Initialized

3.) The sysfs node was created properly during initialization (found in /sys/devices/platform/vms/coordinates)

4.) I know that the virtual mouse driver (input32 ) is linked to event5 by checking the following:

$ cat /proc/bus/input/devices
I: Bus=0000 Vendor=0000 Product=0000 Version=0000
N: Name=""
P: Phys=
S: Sysfs=/devices/virtual/input/input32
U: Uniq=
H: Handlers=event5
B: EV=5
B: REL=3

5.) Next i attach a GPM server to the event interface: gpm -m /dev/input/event5 -t evdev

6.) Run the user space application to generate random coordinates for virtual mouse and observe generated coordinates using od -x /dev/input/event5.

And nothing happens. Why? Also here author mentioned that gdm should be stopped, using /etc/init.d/gdm stop, but i get "no such service" when stopping gdm.

Here is my complete script for building and runing virtual mouse:

make -C /usr/src/kernel/2.6.35.6-45.fc14.i686/ SUBDIRS=$PWD modules
gcc -o app_userspace app_userspace.c
insmod app.ko
gpm -m /dev/input-event5 -t evdev
./app_userspace

Makefile:

obj-m+=app.o

Kernel version: 2.6.35.6


As i said before i can recieve the result through od, but i received it through your program echo 9 19 > /sys/devices/platform/virmouse/vmevent

gives:

time 1368284298.207654 type 2 code 0 value 9

time 1368284298.207657 type 2 code 1 value 19

time 1368284298.207662 type 0 code 0 value 0

So now the question is: what is wrong with X11? I would like to stress, that i tried this code under two different distributions Ubuntu 11.04 and Fedora 14.


Maybe this will help: in Xorg.0.log i see the following:

[ 21.022] (II) No input driver/identifier specified (ignoring)

[ 272.987] (II) config/udev: Adding input device (/dev/input/event5)

[ 272.987] (II) No input driver/identifier specified (ignoring)

[ 666.521] (II) config/udev: Adding input device (/dev/input/event5)

[ 666.521] (II) No input driver/identifier specified (ignoring)

like image 460
Alex Hoppus Avatar asked May 10 '13 12:05

Alex Hoppus


2 Answers

I spent a huge amount of time, resolving this issue, and i would like to help other people, who run in this problem. I think some outer X11 features interfered my module work. After disabling GDM it now works fine (runlevel 3). Working code you can find here http://fred-zone.blogspot.ru/2010/01/mouse-linux-kernel-driver.html working distro ubuntu 11.04 (gdm disabled)

like image 198
Alex Hoppus Avatar answered Sep 21 '22 04:09

Alex Hoppus


Try replacing the below lines of code in the input device driver

set_bit(EV_REL, vms_input_dev->evbit);
set_bit(REL_X, vms_input_dev->relbit);
set_bit(REL_Y, vms_input_dev->relbit);

with

vms_input_dev->name = "Virtual Mouse";
vms_input_dev->phys = "vmd/input0"; // "vmd" is the driver's name
vms_input_dev->id.bustype = BUS_VIRTUAL;
vms_input_dev->id.vendor  = 0x0000;
vms_input_dev->id.product = 0x0000;
vms_input_dev->id.version = 0x0000;

vms_input_dev->evbit[0] = BIT_MASK(EV_KEY) | BIT_MASK(EV_REL);
vms_input_dev->keybit[BIT_WORD(BTN_MOUSE)] = BIT_MASK(BTN_LEFT) | BIT_MASK(BTN_RIGHT) | BIT_MASK(BTN_MIDDLE);
vms_input_dev->relbit[0] = BIT_MASK(REL_X) | BIT_MASK(REL_Y);
vms_input_dev->keybit[BIT_WORD(BTN_MOUSE)] |= BIT_MASK(BTN_SIDE) | BIT_MASK(BTN_EXTRA);
vms_input_dev->relbit[0] |= BIT_MASK(REL_WHEEL);

It worked for me on ubuntu 12.04

like image 35
Sowjanya Avatar answered Sep 18 '22 04:09

Sowjanya