summaryrefslogtreecommitdiff
path: root/libevdev/libevdev.c
Commit message (Collapse)AuthorAgeFilesLines
* Fix invalid absinfo range values reported by certain mtk socAndreas Pokorny2015-08-241-0/+23
| | | | | | | | | | | | | | This change will only affect certain touch screens, for which the driver integration code does not provide meaningful values for the allowed range of ABS_MT_TRACKING_IDs. The reported range [0, 0] will be overwritten with [-1, 0xFFFF] Signed-off-by: Andreas Pokorny <andreas.pokorny@canonical.com> [Changed from INT_MAX to 0xFFFF to match the kernel, add device name to log message] Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
* Accept LIBEVDEV_READ_FLAG_BLOCKING as valid flagPeter Hutterer2015-04-081-1/+5
| | | | | | | https://bugs.freedesktop.org/show_bug.cgi?id=89798 Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net> Reviewed-by: Benjamin Tissoires <benjamin.tissoires@gmail.com>
* ABS_MAX counts as MT axis for the event queuePeter Hutterer2015-03-231-1/+1
| | | | Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
* cosmetic: fix a commentPeter Hutterer2015-03-231-1/+1
| | | | Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
* cosmetic: fix a couple of duplicate/missing empty linesPeter Hutterer2015-03-041-4/+0
| | | | Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
* Remove superfluous linebreak in an error messagePeter Hutterer2014-11-181-1/+1
| | | | Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
* Fix a confusing commentPeter Hutterer2014-11-171-1/+1
| | | | Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
* Rename symbols leaking from static library to avoid name clashesPeter Hutterer2014-08-201-5/+5
| | | | | | | | The static library currently leaks log_msg and log_priority. Both are too generic, so rename them, with a leading underscore to hint they're supposed to be private. Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
* Add per-device log handlersPeter Hutterer2014-06-051-26/+74
| | | | | | | | | | | | | | | | | | | | | | The global log handler isn't a good choice for a low-level library. In the caser of the X server, both evdev and synaptics are now using the libevdev but are loaded from the same server process. Thus, there's only one log handler, but evdev and synaptics don't talk to each other (a bit childish, I know). Add a per-device log handler that overrides the global log handler, and fall back to the global log handler if no device log handler is set. The log macros take care of that automatically, especially as we can't do per-device log handlers for the uinput code. Note that we use the same struct for the global and device logging, so in each instance one of the two function pointers is NULL. Suicide triggers are in place in case we mess that up. This also makes libevdev_new_from_fd() a bit less useful since we can't set the log handler beforehand. Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net> Reviewed-by: David Herrmann <dh.herrmann@gmail.com>
* Drain all events before synchronizing after SYN_DROPPEDPeter Hutterer2014-04-241-20/+38
| | | | | | | | | | | | | | | | | | | | The kernel ring buffer drops all events on SYN_DROPPED, but then continues to fill up again. So by the time we read the events, the kernel's client buffer is essentially like this: SYN_DROPPED, ev1, ev2, ev3, ...., evN The kernel's device state represents the device after evN, and that is what the ioctls return. For EV_KEY, EV_SND, EV_LED and EV_SW the kernel removes potential duplicates from the client buffer [1], it doesn't do so for EV_ABS. So we can't actually sync while there are events on the wire because the events represent an earlier state. So simply discard all events in the kernel buffer, synchronize, and then start processing again. We lose some granularity but at least the events are correct. [1] http://git.kernel.org/cgit/linux/kernel/git/torvalds/linux.git/commit/drivers/input/evdev.c?id=483180281f0ac60d1138710eb21f4b9961901294 Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
* Move read_more_events() up in the filePeter Hutterer2014-04-241-25/+25
| | | | | | | No functional change Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net> Reviewed-by: Benjamin Tissoires <benjamin.tissoires@gmail.com>
* Actually make the min queue size a minimumPeter Hutterer2014-04-101-1/+1
| | | | | Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net> Reviewed-by: Benjamin Tissoires <benjamin.tissoires@gmail.com>
* Drop invalid ABS_MT_TRACKING_ID changesPeter Hutterer2014-04-031-11/+36
| | | | | | | | | | | | | | | | | | | | | | Follow-up to commit 41334b5b40cd5456f5f584b55d8888aaafa1f26e Author: Peter Hutterer <peter.hutterer@who-t.net> Date: Thu Mar 6 11:54:00 2014 +1000 If the tracking ID changes during SYN_DROPPED, terminate the touch first In normal mode, we may get double tracking ID events in the same slot, but only if we either have a user-generated event sequence (uinput) or a malicious device that tries to send data on a slot > dev->num_slots. Since the client is unlikely to be able to handle these events, discard the ABS_MT_TRACKING_ID completely. This is a bug somewhere in the stack, so complain and hobble on along. Note: the kernel doesn't allow that, but we cap to num_slots anyway, see 66fee1bec4c4b021e1b54adcd775cf6e2aa84869. Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net> Reviewed-by: Benjamin Tissoires <benjamin.tissoires@gmail.com>
* Move slot-related initialization downPeter Hutterer2014-04-031-30/+33
| | | | | | | No real effects, but improves readability Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net> Reviewed-by: Benjamin Tissoires <benjamin.tissoires@gmail.com>
* Drop hardcoded MAX_SLOTS in favour of pre-allocated memoryPeter Hutterer2014-04-031-15/+35
| | | | | | | | | | | | | | | | | | | | | We can't allocate in sync_mt_state since it may be called in the signal handler. So pre-allocate based on the device's number of slots, store that in the libevdev struct and use it for the sync process. This fixes a remaining bug with the handling of ABS_MT_TRACKING_ID. If a device had > MAX_SLOTS and a slot above that limit would start or stop during a SYN_DROPPED event, the slot would not be synced, and a subsequent touch in that slot may double-terminate or double-open a touchpoint in the client. For the effects of that see commit 41334b5b40cd5456f5f584b55d8888aaafa1f26e Author: Peter Hutterer <peter.hutterer@who-t.net> Date: Thu Mar 6 11:54:00 2014 +1000 If the tracking ID changes during SYN_DROPPED, terminate the touch first Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net> Reviewed-by: Benjamin Tissoires <benjamin.tissoires@gmail.com>
* Only sync the initial MT state for Protocol B devicesPeter Hutterer2014-04-031-1/+3
| | | | | | | | For protocol A devices we won't get the information from the kernel anyway and we expect all axes to be updated in the next event. Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net> Reviewed-by: Benjamin Tissoires <benjamin.tissoires@gmail.com>
* Drop unnecessary memsetPeter Hutterer2014-04-031-1/+0
| | | | | | | | | | The EVICOCGMTSLOTS ioctl returns all slot values for the requested code or an error code, it doesn't return the number of bytes successfully transferred. Thus all values in the input array are always defined (on success), we don't need to memset it. Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net> Reviewed-by: Benjamin Tissoires <benjamin.tissoires@gmail.com>
* Use libevdev_reset from libevdev_freePeter Hutterer2014-04-021-4/+1
| | | | | Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net> Reviewed-by: Benjamin Tissoires <benjamin.tissoires@gmail.com>
* Add quote around device name during error messagePeter Hutterer2014-04-021-1/+1
| | | | Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
* Fix indentationPeter Hutterer2014-04-011-1/+1
| | | | Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
* Shut up another warningPeter Hutterer2014-03-191-1/+1
| | | | | | | | | | | Triggered with -O3 ../libevdev/libevdev.c: In function ‘libevdev_get_event_value’: ../libevdev/libevdev.c:1112:6: warning: ‘value’ may be used uninitialized in this function [-Wmaybe-uninitialized] Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net> Reviewed-by: Benjamin Tissoires <benjamin.tissoires@gmail.com>
* Shut up compiler warningPeter Hutterer2014-03-191-1/+1
| | | | | | | | | | | | | | Triggered with -O ../libevdev/libevdev.c: In function ‘libevdev_has_event_code’: ../libevdev/libevdev-util.h:58:20: warning: ‘mask’ may be used uninitialized in this function [-Wmaybe-uninitialized] Optimisation clearly shuffles things around here: in the code, if no max is found, we return -1 and bail out before we access mask. Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net> Reviewed-by: Benjamin Tissoires <benjamin.tissoires@gmail.com>
* Sanitize events when we're skipping sync as wellPeter Hutterer2014-03-191-0/+1
| | | | | | | | If a client doesn't sync expliciltly, make sure we sanitize the events when we update the internal library state. Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net> Reviewed-by: Benjamin Tissoires <benjamin.tissoires@gmail.com>
* If the tracking ID changes during SYN_DROPPED, terminate the touch firstPeter Hutterer2014-03-071-0/+26
| | | | | | | | | | Most clients can't deal with tracking ID changes unless a -1 is sent first. So if we notice that the tracking ID has changed during the sync process, send a set of ABS_MT_TRACKING_ID -1 events for each of those, then send the rest of the events. Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net> Reviewed-by: Benjamin Tissoires <benjamin.tissoires@gmail.com>
* Send an extra ABS_MT_SLOT event to sync the client up with the current slotBenjamin Tissoires2014-03-071-2/+23
| | | | | | | | | If multiple slots have changed during the sync handling, the client must be re-set to the current slot before continuing with normal events. Signed-off-by: Benjamin Tissoires <btissoir@redhat.com> Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net> Reviewed-by: Benjamin Tissoires <benjamin.tissoires@gmail.com>
* Don't sync the MT state for fake MT devicesPeter Hutterer2014-03-061-2/+3
| | | | | | | | | | | | | Devices with ABS_MT_SLOT-1 are fake MT devices, they merely overlap the axis range but don't actually provide slots. The EVIOCGABS ioctl won't work to retrieve the current value - the kernel does not store values for those axes and the return value is always 0. Thus, simply ignore those axes for fake MT devices and instead rely on the next event to update the caller with the correct state for each axis. Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net> Reviewed-by: Benjamin Tissoires <benjamin.tissoires@gmail.com>
* Cap slot values to the announced maximumPeter Hutterer2014-03-061-0/+24
| | | | | | | | | | | | | | A malicious device may announce N slots but then send a slot index >= N. The slot state is almost always allocated (definitely the case in libevdev and true for most callers), so providing a slot number higher than the announced maximum is likely to lead to invalid dereferences. Don't allow that. Likewise, don't allow negative slot numbers. Note that the kernel filters these events anyway, the only way to trigger this is to change the device fd to something outside the kernel's control. Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net> Reviewed-by: Benjamin Tissoires <benjamin.tissoires@gmail.com>
* Reduce memory requirement for MT syncingPeter Hutterer2014-03-061-29/+39
| | | | | | | | | | | | | | | | | | | | | | | Changes the algorithm: before we'd ioctl all axes for all slots, then generate events for all slots one-by-one. Now we ioctl the slot state for each axis, copy the new event value into the device and mark a bitfield that we've updated the value. Then loop through the slots and generate events where changed. Side-effect: this makes it easy to check if anything in the slot has updated, so we can skip empty slot events during sync. Min memory requirement for the state storage was: MAX_SLOTS * (ABS_MT_CNT + 1) * sizeof(int) = 1980 Min memory requirement now: (ABS_MT_CNT + 1) * sizeof(int) + NLONGS((MAX_SLOTS * ABS_MT_CNT) bits) = 544 This is sigsafe code, so this was stack memory. Reducing the requirement allows us to up MAX_SLOTS in the future if we need to. Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net> Reviewed-by: Benjamin Tissoires <benjamin.tissoires@gmail.com>
* Dynamically allocate the slot valuesPeter Hutterer2014-03-061-10/+31
| | | | | | | | Instead of relying on a static MAX_SLOTS array, allocated it based on the number of slots we have on the device. The previous checks for MAX_SLOTS were incomplete, causing out-of-bound reads. Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
* Don't sync past MAX_SLOTS slotsPeter Hutterer2014-03-061-1/+1
| | | | | | | | | | If a device has more than MAX_SLOTS slots, we'd run out-of-bounds on the sync array. This function is sig-safe, so we can't alloc here, merely limit the access. Reported-by: Jonas Ådahl <jadahl@gmail.com> Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net> Reviewed-by: Benjamin Tissoires <benjamin.tissoires@gmail.com>
* Plug a memory leak for name, uniq, physPeter Hutterer2014-02-271-1/+4
| | | | | | | | | | If a device is assigned a name, uniq and/or phys before calling libevdev_set_fd(), those values would leak. Change the default alloc to calloc, so name, uniq, and phys are initialized to zero before we call libevdev_reset Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
* Replace hardcoded 0 with the enum for itPeter Hutterer2014-02-251-1/+1
| | | | Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
* Actually filter by log priorityPeter Hutterer2014-02-131-1/+1
| | | | | | | | If a message is higher than the current priority, filter it. And add a few tests that the priority is handled the way it should. Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net> Reviewed-by: David Herrmann <dh.herrmann@gmail.com>
* Warn about a SYN_DROPPED right after finishing a syncPeter Hutterer2014-01-221-3/+8
| | | | | | | | | | | | If the first event after a completed device sync is a SYN_DROPPED, warn the user that they're not fast enough handling this device. The test for this is rather complicated since we can't write SYN_DROPPED through uinput so we have to juggle the device fd and a pipe and switch between the two at the right time (taking into account that libevdev will read events from the fd whenever it can). Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
* Count the number of events needed for a full syncPeter Hutterer2014-01-221-4/+30
| | | | | | | | | Make sure we have a queue that is at least large enough to do a full sync after a SYN_DROPPED, plus store a few extra events in case some came in after the sync. Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net> Reviewed-by: David Herrmann <dh.herrmann@gmail.com>
* Don't treat devices with (ABS_MT_SLOT - 1) as multitouch devicesPeter Hutterer2013-12-101-2/+7
| | | | | | | | | | | | | Some devices (PS3 sixaxis controller) merely have a bunch of axes, without the semantic information that linux/input.h requires. For those, the ABS_MT range may be merely another axis, not the special range that we need to treat it with. Use a simple heuristic: if ABS_MT_SLOT - 1 is enabled, don't treat ABS_MT as multitouch axes. The ABS_MT_SLOT - 1 axis is not used for a real axis. Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net> Reviewed-by: David Herrmann <dh.herrmann@gmail.com>
* Support EV_REP values through libevdev_get_event_valuePeter Hutterer2013-12-091-0/+13
| | | | | | | | | We shouldn't have a separate API for that, the whole point of libevdev is to abstract the quirkyness of the ioctls into a common interface. So let's export the two EV_REP values through libevdev_get_event_value. Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net> Reviewed-by: David Herrmann <dh.herrmann@gmail.com>
* Constify libevdev_get_repeatPeter Hutterer2013-12-091-1/+1
| | | | Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
* Drop some leftover deprecated constants.Peter Hutterer2013-11-281-6/+0
| | | | Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
* Drop semicolons after getter/setter macrosPeter Hutterer2013-11-221-16/+16
| | | | | | | | libevdev.c:921:134: warning: ISO C does not allow extra ';' outside of a function [-Wpedantic] Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net> Reviewed-by: David Herrmann <dh.herrmann@gmail.com>
* Drop deprecated functionsPeter Hutterer2013-11-221-49/+0
| | | | | Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net> Reviewed-by: David Herrmann <dh.herrmann@gmail.com>
* Check max to see if an event type is validPeter Hutterer2013-10-241-2/+14
| | | | | | | | There's a gap in the range between EV_SW and EV_LED. Trying to enable one of those bits will segfault. Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net> Reviewed-by: David Herrmann <dh.herrmann@gmail.com>
* Make sure EV_SYN is always setPeter Hutterer2013-10-241-1/+2
| | | | | | | | Set the bit during device reset and make sure that if we're checking for the event type we always return true for EV_SYN. Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net> Reviewed-by: David Herrmann <dh.herrmann@gmail.com>
* Disallow disabling EV_SYN event codesPeter Hutterer2013-10-241-1/+1
| | | | | | | The documentation already says that, make it happen. Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net> Reviewed-by: David Herrmann <dh.herrmann@gmail.com>
* Reset the struct on set_fdPeter Hutterer2013-10-231-7/+19
| | | | | | | | | | | libevdev_set_fd may fail at a number of points. If it does, it errors out but does nothing otherwise. Thus, a client may call set_fd again for the same struct but on a different fd and have it succeed. Depending on when set_fd bailed out the first time, some fields may already be set. Thus, reset the whole struct at set_fd time to make sure we're nulled out appropriately. Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net> Reviewed-by: David Herrmann <dh.herrmann@gmail.com>
* Work around missing EVIOCGMTSLOTS ioctlPeter Hutterer2013-10-231-2/+12
| | | | Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
* When running against a kernel without properties, continue as usualPeter Hutterer2013-10-231-1/+5
| | | | | | Missing out on properties is not fatal. Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
* Don't allow a negative fd in libevdev_set_fdPeter Hutterer2013-10-141-1/+2
| | | | | | Everything else responds with -EBADF, let's do so here as well. Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
* Allow -1 as valid fd in libevdev_change_fdPeter Hutterer2013-10-141-14/+23
| | | | | | | | | | | Add a new flag for "initialized" and separate that from the fd logic. This way, we can call libevdev_change_fd(dev, -1) to signal that the current fd should be dropped. Otherwise libevdev can't be told to release the fd and always keeps a reference to it. Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
* Print an error on an invalid log priorityPeter Hutterer2013-09-181-0/+1
| | | | Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>