[PATCH 0/9] HID++ (Logitech Unifying) protocol fixes

2013-08-07 Thread Peter Wu
Hi, After upgrading to 0.9.21 on Arch Linux, I found the following log messages in my journal: UPower-Linux-WARNING **: failed to coldplug unifying device: invalid response from device: 7 It turns out that the current implementation is very naive when reading messages. The hidraw responses

[PATCH 3/9] hidpp: clear message queue before initiating new requests

2013-08-07 Thread Peter Wu
This prevents the use of responses from other HID++ applications (such as Solaar and ltunify). Signed-off-by: Peter Wu --- src/linux/hidpp-device.c | 21 + 1 file changed, 21 insertions(+) diff --git a/src/linux/hidpp-device.c b/src/linux/hidpp-device.c index 6d02bf1..2d4e55

[PATCH 6/9] hidpp: support battery register 0x07

2013-08-07 Thread Peter Wu
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 --- src/linux/hidpp-device.c | 56 +

[PATCH 7/9] hidpp: test only once for d7 register

2013-08-07 Thread Peter Wu
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 --- src/linux/hidpp-device.c | 31 ++- 1 file changed, 18 insertions(+), 13 deletions(-) diff --git a/src/lin

[PATCH 9/9] hidpp: pick up devices that just got paired

2013-08-07 Thread Peter Wu
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 --- src/linux/up-device-unifyi

[PATCH 8/9] hidpp: assume HID++ 1.0 for unreachable devices

2013-08-07 Thread Peter Wu
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 ex

[PATCH 2/9] hidpp: validate messages, retry if invalid

2013-08-07 Thread Peter Wu
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 --- src/linux/hidpp-device.c | 108 +-- 1 file changed

[PATCH 4/9] hidpp: recognise HID++ 1.0 ping response again

2013-08-07 Thread Peter Wu
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 --- src/linux/hidpp-device.c | 31 --- 1 file changed, 28 insertions(+), 3 deletions(-) diff --git a/src/linux/hidpp-device

[PATCH 1/9] hidpp: refactor to introduce structure in protocol

2013-08-07 Thread Peter Wu
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

[PATCH 5/9] hidpp: do not print warnings if device is offline

2013-08-07 Thread Peter Wu
This reduces spam in stderr (which is logged to the systemd journal). Signed-off-by: Peter Wu --- src/linux/hidpp-device.c | 7 +++ src/linux/up-device-unifying.c | 16 ++-- 2 files changed, 17 insertions(+), 6 deletions(-) diff --git a/src/linux/hidpp-device.c b/src/linu