summaryrefslogtreecommitdiff
AgeCommit message (Collapse)AuthorFilesLines
2013-09-03hidpp: try harder not to report 0% batteryhidpp-reworkPeter Wu1-1/+6
(1) If the K800 keyboard is charging via the USB cable, it will report itself as Charging, but with a discharge level of 0 (which means "unknown". In this case, the previous known value (before connecting the cable) is always a better approximation than using zero. (2) When the K800 has fully charged (but with the cable still plugged in), it will still report 0 as discharge level. "Full" is 100% by definition, so let's fallback to that value. Signed-off-by: Peter Wu <lekensteyn@gmail.com>
2013-09-02hidpp: simplify setting model and serialPeter Wu1-9/+2
I previously followed the model example for copying part of the string, but there is a much simpler way to build the name string using g_strdup_printf. Note that a simple strdup() is not sufficient for model since it does not have to be NUL terminated. Reported-by: Martin Pitt <martin.pitt@ubuntu.com> Signed-off-by: Peter Wu <lekensteyn@gmail.com>
2013-09-02hidpp: drop read_msg, print correct bufferPeter Wu1-12/+9
Since "hidpp: split request read/write functions", the request buffer is not used anymore while reading the response. Therefore the additional buffer read_msg that was used for preserving the request buffer can be discarded. This patch also fixes printing the wrong response buffer (response would always yield zeroes until the functions exits). Reported-by: Martin Pitt <martin.pitt@ubuntu.com> Signed-off-by: Peter Wu <lekensteyn@gmail.com>
2013-09-02hidpp: ignore remaining garbage for debug printPeter Wu1-2/+4
HidppMessage is currently of size 20 ("long message"). Since short messages are always of size 7, do not bother printing the remaining 13 bytes. This code path is currently only used by hidpp-test (not installed). Reported-by: Martin Pitt <martin.pitt@ubuntu.com> Signed-off-by: Peter Wu <lekensteyn@gmail.com>
2013-09-02hidpp: fix K750 battery and luminosity propertiesPeter Wu3-4/+40
Since commit b1f12feb1fd4535255f04c91bef90ae11ce57311 ("Factor out the Logitech Unifying support to support other devices"), the battery status would always be reported as 1% for the K750 keyboard. Besides that, the luminosity level was removed. This patch fixes the battery level and re-adds the luminosity level. To avoid negativity issues when reading light level into a double type, make the HidppMessage params unsigned. Signed-off-by: Peter Wu <lekensteyn@gmail.com>
2013-09-02hidpp: move timeout checking before readingPeter Wu1-10/+10
When no report matches the report type or device, the previous code did not terminate the loop early enough because the check was missed. Now the timeout is always checked before attempting to poll. Signed-off-by: Peter Wu <lekensteyn@gmail.com>
2013-09-02hidpp: split request read/write functionsPeter Wu1-24/+58
In preparation for reading notifications; the device index is now also validated before using a message, this avoid matching the wrong report. Signed-off-by: Peter Wu <lekensteyn@gmail.com>
2013-09-02hidpp: retry when read or g_poll is interruptedPeter Wu1-0/+6
Signed-off-by: Peter Wu <lekensteyn@gmail.com>
2013-09-02hidpp: more useful error messagesPeter Wu1-8/+19
If read, wait or g_poll failed, it would return -1. This information is not really useful, so print the error string instead where applicable. Signed-off-by: Peter Wu <lekensteyn@gmail.com>
2013-09-02hidpp: fix memleak while coldpluggingPeter Wu1-11/+21
The device returned by g_udev_device_get_parent must be freed by the caller. Signed-off-by: Peter Wu <lekensteyn@gmail.com>
2013-08-22hidpp: fix fd leakPeter Wu1-0/+3
Upon unplugging the USB receiver, the file descriptor of /dev/hidrawX is not closed. With commit "HID: hidraw: correctly deallocate memory on device disconnect"[1] (queued for 3.12), this missing close() causes a /dev/hidrawX devuce to persist until UPower is restarted. On earlier kernels, never remove your USB receiver or you will experience random errors resulting from data structures corruption[2] (which occurs because UPower tries to poll() or read() an hidraw device while the kernel has already released the memory for it). Not UPowers fault, but UPower makes this bug more likely since it runs as daemon. [1]: http://lkml.org/lkml/2013/7/22/248 [2]: http://lkml.org/lkml/2013/8/6/457 Signed-off-by: Peter Wu <lekensteyn@gmail.com>
2013-08-22hidpp: retrieve serial number for devices (v2)Peter Wu3-1/+42
Before this, history files were saved as history-rate-M525.dat. Since multiple devices of the same model might be connected, this name is not unique enough. The serial number gives a more reliable path for the history files and allows clients to distinguish their devices (an object path like /org/freedesktop/UPower/devices/mouse_0003o046DoC52Bx0018 does not stay the same). Note: if a serial number cannot be read, instead of reverting this patch, consider splitting the serial refresh from the version, kind and model refresh. - v2: Fix invalid return value when an invalid parameter is passed to hidpp_device_get_serial. Signed-off-by: Peter Wu <lekensteyn@gmail.com>
2013-08-22hidpp: remove unnecessary HID++ 2.0 codePeter Wu1-74/+5
The device name and type can be queried from the receiver which does not mind if a paired device is using HID++ 2.0 or 1.0. Therefore remove the hidpp20-specific code which also removes indirection of an uninitialised "map" variable. The following code was buggy: msg.feature_idx = map->idx; ... map = ...; if (map != NULL) { ... } ... priv->model = ...; It should have become: map = ...; if (map != NULL) { ... priv->model = ...; } ... but since the HID++ 2.0 code is not necessary, just remove it. Signed-off-by: Peter Wu <lekensteyn@gmail.com>
2013-08-22hidpp: fix properties for unreachable devices (v2)Peter Wu3-12/+45
This includes "is-present" and "state" (which will be marked "unknown"). "percentage" is not touched since it is still an indication of the battery level, changing it to zero is not helpful. Previously, properties were never updated because the refresh would fail when the battery refresh request failed. - v2: fix invalid return value when an invalid parameter is passed to hidpp_device_is_reachable. Signed-off-by: Peter Wu <lekensteyn@gmail.com>
2013-08-22hidpp: improve HID++ version detection, fix uninit varPeter Wu2-11/+27
Do not assume HID++ 1.0 when device is unreachable. This allows up_device_unifying_refresh() to be optimized to stop sending a ping message at every refresh for HID++ 1.0 devices. priv->version will now always contain 0 when the real HID++ version of a device is not (yet) known, comments are updated to reflect this. Also fix an uninitialised msg variable that might confuse the error handler in hidpp_device_refresh. Signed-off-by: Peter Wu <lekensteyn@gmail.com>
2013-08-22hidpp: pick up devices that just got pairedPeter Wu1-0/+3
When sending a ping request right after a device got paired, the ping message gets lost (there is no response). Work around that by delaying the initial packet exchange. 10 milliseconds seems to work, but let's choose 30 ms to be fully safe. Signed-off-by: Peter Wu <lekensteyn@gmail.com>
2013-08-22hidpp: assume HID++ 1.0 for unreachable devicesPeter Wu1-1/+5
When the USB receiver is just plugged in, devices may not be active ("unreachable") and therefore return RESOURCE_ERROR on requests. This causes upower to fail on picking up new devices. As a workaround, assume that all discovered devices will eventually become reachable (even if they don't, for example if the device was paired to another computer while the computer carrying the receiver was powered off). Actual removal of unpaired devices is done by the Logitech HID driver, that should remove sysfs entries which can be detected by upower. Signed-off-by: Peter Wu <lekensteyn@gmail.com>
2013-08-22hidpp: test only once for d7 registerPeter Wu1-13/+18
The d7 battery register does not magically re-appear, therefore skip this register once it is detected that the register is unusable. Signed-off-by: Peter Wu <lekensteyn@gmail.com>
2013-08-22hidpp: support battery register 0x07Peter Wu1-2/+54
The HID++ 1.0 Illuminated Keyboard K800 does not support the d7 register, instead is uses 07. Its observed behaviour is documented in the ltunify repository[1]. [1]: https://git.lekensteyn.nl/ltunify/tree/registers.txt Signed-off-by: Peter Wu <lekensteyn@gmail.com>
2013-08-22hidpp: do not print warnings if device is offlinePeter Wu2-6/+17
This reduces spam in stderr (which is logged to the systemd journal). Signed-off-by: Peter Wu <lekensteyn@gmail.com>
2013-08-22hidpp: recognise HID++ 1.0 ping response againPeter Wu1-3/+28
Removed while refactoring hidpp_device_cmd, now that the message validation is in place, introduce the 1.0 check again. Signed-off-by: Peter Wu <lekensteyn@gmail.com>
2013-08-22hidpp: clear message queue before initiating new requests (v2)Peter Wu1-0/+25
This prevents the use of responses from other HID++ applications (such as Solaar and ltunify). - v2: do not hang in a loop when read() fails, e.g. when it returns EIO because the device was unplugged. Signed-off-by: Peter Wu <lekensteyn@gmail.com>
2013-08-07hidpp: validate messages, retry if invalidPeter Wu1-32/+76
This prevents matching the wrong response packet, for example when a mouse is moved while a packet is read. As a result, the reads are more reliable and log spam is reduced. Signed-off-by: Peter Wu <lekensteyn@gmail.com>
2013-08-06hidpp: refactor to introduce structure in protocolPeter Wu1-157/+154
Before this patch, there was no structure at all in the messages that were passed around. Some issues: - (debug) Every message of length 7 was considered a request (and length 20 were seen as responses). This is not the case for HID++ 1.0. - The length of the message payload (ignoring the header) is fixed to 7 or 20, this was not considered in the previous code. - The hidpp_device_cmd function contained special-case code for a HID++ 1.0 response on a HID++ 2.0 ping request. After this patch, the protocol message structure should be more explicit. To be done: - Test for HID++ 1.0 ping response (removed/broken by this patch). - Validate responses, retry read if needed. Signed-off-by: Peter Wu <lekensteyn@gmail.com>
2013-07-26trivial: post release version bumpRichard Hughes2-5/+5
2013-07-26Released UPower 0.9.21Richard Hughes2-1/+17
2013-05-07build: detect udev rules dirTom Gundersen2-8/+5
Udev rules may live in either /lib/udev/rules.d or /usr/lib/udev/rules.d depending on the distro. Remove the heuristic for deciding the dir, use pkgconfig to detect the location and allow it to be set manually. v2: fix specifying --with-udevrulesdir Signed-off-by: Richard Hughes <richard@hughsie.com>
2013-05-07trivial: Fix the gitignore filesRichard Hughes2-14/+15
2013-05-07Use PIE to better secure installed tools and also use full RELRO in the daemonRichard Hughes5-1/+164
2013-05-07Update the upower man page with all the current optionsRichard Hughes1-1/+5
2013-04-24Allow clients to call org.freedesktop.DBus.PeerRichard Hughes1-0/+2
This fixes Ping() and GetMachineId() which is needed by systemd.
2013-03-28Locate non-unifying receiver by looking for hidraw with hiddev exposed.Arkadiusz Miśkiewicz1-2/+23
For non unifying receiver we were trying to locate receiver hiddraw device by looking into INTERFACES property. This doesn't work well for non-unifying devices from keyboard+mouse sets (which use single dongle for 2 devices but are still non-unifying). The only thing that's different between hiddraw receiver and other devices (mouse, keyboard etc) is that receiver also exposes hiddev interface. Use that fact to reliably locate receiver. Signed-off-by: Arkadiusz Miśkiewicz <arekm@maven.pl> Signed-off-by: Richard Hughes <richard@hughsie.com>
2013-03-28hid++v1 detection for unreachable devices and features upgradeArkadiusz Miśkiewicz2-51/+39
We are back to using HIDPP_FEATURE_ROOT_FN_PING for detecting protocol since it's the official way described in [1]. Unfortunately unreachable devices ("disconnected" in logitech terminology) don't respond to this v1 ping query as described in docs. Seems that docs cover only reachable state reply for version checking. Thus we have to consider HIDPP_ERROR_CODE_UNSUPPORTED to also be v1 (since we actually got some v1 valid answer - error reply). Introduce HIDPP_REFRESH_FLAGS_FEATURES for checking features provided by v2 device. This recheck is triggered when we upgrade from any protocol to v2 in HIDPP_REFRESH_FLAGS_VERSION. This allows us to properly upgrade from v0/v1 to v2 and also we don't send v2 queries when we know that the device is v1. [1] logitech_hidpp10_specification_for_Unifying_Receivers.doc Signed-off-by: Arkadiusz Miśkiewicz <arekm@maven.pl> Signed-off-by: Richard Hughes <richard@hughsie.com>
2013-03-22Better method of figuring out v1 vs v2 protocol version.Arkadiusz Miśkiewicz2-10/+42
Protocol version detection isn't very reliable (especially for hid++ v1). Version 1 checking was potentially happening in every hidpp_device_cmd() call and not only when requested. Improve that to do version checking and priv->version manipulation only when requested by using HIDPP_REFRESH_FLAGS_VERSION. When doing version checking first try v2 protocol command and if it succeeds assume version 2 device. Otherwise try v1 protocol query and if that successds assume version 1 device. v2 devices in unreachable/sleep mode seem to do not respond to v2 queries but they respond to v1 queries! Still we want best protocol possible. To do that we are rechecking version when current protocol version is below 2 and we are doing up_device_unifying_refresh() and if recheck succeeds we upgrade protocol to v2. Signed-off-by: Arkadiusz Miśkiewicz <arekm@maven.pl> Signed-off-by: Richard Hughes <richard@hughsie.com>
2013-03-22Add support for Logitech Wireless (NonUnifying) devicesArkadiusz Miśkiewicz2-10/+25
There are Logitech Wireless devices similar to Unifying ones with the difference that device is paired with single dongle and dongle doesn't support pairing multiple devices. Add support for these. Tested with Wireless Mouse M187 and M185/M225. Signed-off-by: Arkadiusz Miśkiewicz <arekm@maven.pl> Signed-off-by: Richard Hughes <richard@hughsie.com>
2013-03-22Repair vendor handling for Logitech Unifying devicesArkadiusz Miśkiewicz2-1/+7
Set proper vendor via udev rules for unifying devices and handle that in code. Signed-off-by: Arkadiusz Miśkiewicz <arekm@maven.pl> Signed-off-by: Richard Hughes <richard@hughsie.com>
2013-03-22Add support for HIDPP_REFRESH_FLAGS_MODEL in hid++ v1Arkadiusz Miśkiewicz1-19/+40
Add support for checking device model name for hid++ v1 protocol version. Signed-off-by: Arkadiusz Miśkiewicz <arekm@maven.pl> Signed-off-by: Richard Hughes <richard@hughsie.com>
2013-03-21Invalid request/response for HIDPP_REFRESH_FLAGS_BATTERY in hid++1Arkadiusz Miśkiewicz1-8/+6
Version 1 hid++ HIDPP_REFRESH_FLAGS_BATTERY packets were incorrect. Response packets were incorrectly thrown away as invalid. These packets have HIDPP_HEADER_REQUEST (and not HIDPP_HEADER_RESPONSE as code expexted). Fix that by allowing both types. Signed-off-by: Arkadiusz Miśkiewicz <arekm@maven.pl> Signed-off-by: Richard Hughes <richard@hughsie.com>
2013-03-21Buffer for HIDPP_REFRESH_FLAGS_KIND not big enoughArkadiusz Miśkiewicz1-1/+1
HIDPP_REFRESH_FLAGS_KIND action puts result into 7 bytes buffer and later tries to access 8th element (with index 7). Make buffer bigger, so 8th element will fit. Signed-off-by: Arkadiusz Miśkiewicz <arekm@maven.pl> Signed-off-by: Richard Hughes <richard@hughsie.com>
2013-03-21Detection of version 1 hid++ is not returned to the callerArkadiusz Miśkiewicz1-2/+2
HID++ version 1 was properly detected but that information wasn't reaching caller. Signed-off-by: Arkadiusz Miśkiewicz <arekm@maven.pl> Signed-off-by: Richard Hughes <richard@hughsie.com>
2013-03-21Find hidraw devices correctly with systemd udev >= v196.Arkadiusz Miśkiewicz1-1/+1
udev v196 libraries changed behaviour of g_udev_device_get_sysfs_attr() by stopping following symlinks for "device" attribute [1]. That change broke hiddev finding for unifying devices. Fix that by getting sysfs path from parent hiddev device. 1. http://cgit.freedesktop.org/systemd/systemd/commit/?id=5ae18ddc0d86673520c0dd6b59ccac8afc8aa605 Signed-off-by: Arkadiusz Miśkiewicz <arekm@maven.pl> Signed-off-by: Richard Hughes <richard@hughsie.com>
2013-03-21Drop --enable-systemd and linking to libsystemd-daemonMartin Pitt3-35/+3
logind is now being detected at runtime (see previous commit ff39d23), so we do not need to link against libsystemd-daemon any more. Drop --enable-systemd configure option as well.
2013-03-21Fix test for logind availabilityMartin Pitt1-18/+9
sd_booted() is not an appropriate check for whether we should talk to logind, test for /run/systemd/seats/ instead. For details, see: <https://mail.gnome.org/archives/desktop-devel-list/2013-March/msg00092.html>
2013-03-18trivial: post release version bumpRichard Hughes2-5/+5
2013-03-18Released UPower 0.9.20Richard Hughes2-2/+24
2013-02-20up-self-test.c: Drop usage of up_daemon_set_bus_type()Martin Pitt1-8/+0
This is now gone since the previous commit.
2013-02-20Revert "Add option to run daemon on the session bus for testing"Martin Pitt7-28/+6
This reverts commit eddcf0ef3d0b8445618e368328d7e110a83b69b3. We don't need the --test option any more now that we always run tests on a (fake) system D-BUS.
2013-02-20integration-test: Always run on a fake system busMartin Pitt2-22/+15
Drop the two modes depending on whether or not the test gets run as root or not. Set up a fake system bus and always use that. This also eliminates the need for upowerd's --test option. Drop usage of dbus-launch, as this leaves dbus-daemon running after the tests. Use GioTestDBus instead, which cleans up properly.
2013-02-20integration-test: Move to using umockdevMartin Pitt1-130/+86
Setting $SYSFS_PATH does not work any more with recent libudev versions, our homwbrew sysfs sandbox building limits us to coldplug tests only. umockdev works with both old and new libudevs and can also emulate uevents for future hotplugging tests. Skip the test if umockdev is not available, so that check and distcheck don't bail out.
2013-02-12Also deprecate running the powersave scriptsRichard Hughes3-4/+14
Over the years we've moved all the quirks to the kernel (and fixed most of the issues properly) so on Fedora we've not actually been shipping any rules in pm-utils for a couple of releaes now. Dropping this functionality allows us to finally drop the pm-utils dep for upower.