Blub / netevent

Input-Event device cloning utility. Use it together with ssh/netcat/... to share input devices among different machines.
GNU General Public License v2.0
148 stars 14 forks source link

protocol error: struct user_input_dev size mismatch #3

Closed graytron closed 6 years ago

graytron commented 6 years ago

I am trying to share laptop keyboard and touchpad with Raspberry Pi. On the laptop I have Debian jessie running Linux kernel 3.16.0-5-686-pae. On the Raspberry Pi I have Rasbian stretch running Linux kernel 4.14.31+.

I have created a file /etc/netevent.conf which contains these lines:

device add mymouse /dev/input/by-path/platform-i8042-serio-1-event-mouse
device add mykbd /dev/input/by-path/platform-i8042-serio-0-event-kbd
hotkey add mykbd key:69:1 grab toggle
hotkey add mykbd key:69:0 nop
output add myremote exec:ssh pi@pi netevent create
use myremote

To test this configuration I run following command:

$ netevent daemon -s /etc/netevent.conf /tmp/netevent-command.sock

The output of the command is this:

added device mymouse
added device mykbd
added hotkey 1:69:1 for device 1
added hotkey 1:69:0 for device 1
added output myremote
error: protocol error: struct user_input_dev size mismatch
interrupted

Running ./configure gives me this:

Checking for rst2man.../usr/bin/rst2man
Checking for UI_DEV_SETUP (kernel >= 4.4)....cfgtest.cpp: In function ‘int main()’:
.cfgtest.cpp:4:12: error: ‘UI_DEV_SETUP’ was not declared in this scope
   ioctl(0, UI_DEV_SETUP);
            ^
.cfgtest.cpp:5:12: error: ‘UI_ABS_SETUP’ was not declared in this scope
   ioctl(0, UI_ABS_SETUP);
            ^
no (disabling)

Does all this mean that my current laptop kernel does not support netevent 2 compatible protocol and I should use netevent 1 compatible protocol instead? If yes, then could you be so kind to provide some tips on how to convert my configuration to legacy? Just by adding --legacy option after netevent create didn't do it, since obviously it only changes the protocol used on the Raspberry Pi.

I managed to share the keyboard by using netevent cat --legacy with netcat through ssh tunnel, but I couldn't get the hotkey to work.

PS. This is a very nice tool and project! I'm surprised it isn't more popular. netevent could be a standard tool on every Linux distribution. Good job!

Blub commented 6 years ago

Ah right, I forgot about the sizes there (in v1 someone actually made a pull request for that very issue...), silly me. As for the protocol - the output of the configure script doesn't affect it, that's only the interface to the kernel. For cat mode, hotkeys aren't implemented yet. I'll try to fix some of this up tomorrow.

Blub commented 6 years ago

Actually, struct uinput_user_dev shouldn't be differently sized AFAICT on arm systems, I'm gonna have to investigate this more.

graytron commented 6 years ago

I managed to share keyboard and mouse of a Debian stretch amd64 system with the same Raspberry Pi and same build on the Raspberry Pi, using protocol 2, so the problem is probably with my old Debian jessie i386 laptop, or i386 architecture itself having different size. It is running an old Intel Atom N280 CPU.

Blub commented 6 years ago

Tested with a jessie container. Looks like I forgot to pack the packet struct. Fixing this unfortunately breaks the protocol so you'll need to rebuild on all machines. Can you please test?

PS: I could also pad the struct to keep it compatible, but I also want to add a kind of handshake "hello" packet to get better error messages in cases like this one. The change is in the packing-fix branch. Once this is working I'll probably create a tag for a first 2.0 release and update the Arch & Debian build files.

graytron commented 6 years ago

packing-fix branch fixed the protocol error: struct user_input_dev size mismatch issue with Debian jessie i386. It also didn't break keyboard sharing on Debian stretch amd64. I tested sharing with both RPi 1B (armv6l) and RPI 3B (armv7l), both running Raspbian stretch.

Rebuilt was done on all 4 machines and building was cleaner than before; ./configure didn't spew error messages any more.

However, when I said "I managed to share keyboard and mouse of a Debian stretch amd64 system" earlier, it turns out that mouse sharing wasn't actually working. Mouse was just being grabbed and evtest on RPi shows events. Only now I noticed that the mouse cursor isn't actually moving at all after launching Xorg. Do you want a separate issue for this?

packing-fix branch doesn't grab the mouse of my Debian jessie i386 laptop and it gives the following error message: ERROR: failed to grab input device: Device or resource busy. Do you want a separate issue for this?

Blub commented 6 years ago

For the mouse events being transferred but not producing movement on the other side - was that a touchpad? I was able to reproduce this with my laptop's touchpad. This is probably due to some information I'm not yet including in the setup code (mostly because I wasn't sure what to test with, didn't expect a touchpad to be an issue tbh ;-), eg. there's also no force-feedback support for game controllers either, since this requires some additional data uploaded via ioctls). This should probably be be a separate issue

As for the EBUSY - can you check with fuser which programs are also already using the device? Usually it's just Xorg which doesn't grab it (the error happens when someone's already grabbing the device). Oh and yeah a separate issue would make this easier to track. Then I can merge the packing-fix branch which already contains a tag to close this one.

graytron commented 6 years ago

protocol error: struct user_input_dev size mismatch issue was fixed with packing-fix branch, so this issue #3 can be closed once merged. Thanks a lot for the fix! Keyboard sharing works for me now!

I'll create separate issues for the other issues with answers to your questions there.