HID: asus: ignore declared dummy usages
authorMatjaz Hegedic <matjaz.hegedic@gmail.com>
Wed, 8 Mar 2017 23:31:14 +0000 (00:31 +0100)
committerJiri Kosina <jkosina@suse.cz>
Thu, 30 Mar 2017 09:16:53 +0000 (11:16 +0200)
Keyboards handled by hid-asus declare special key functions
using a vendor-specific page, however, alongside legitimate
key functions, dummy usages with seemingly arbitrary values
are also declared and can lead to keyboards being detected
as pointer devices by some software (such as X.org).

In addition, for the I2C keyboard volume controls are
separately declared in a Consumer Usage page, with the same
dummy usage problem.

The fix in 1989dada7ce0 ("HID: input: ignore System Control
application usages if not System Controls") does not mitigate
the problem described above, therefore dummy usages need to
be ignored in the driver itself.

This fix properly ignores dummy usages and introduces a quirk
for custom handling of the Consumer Usages on the I2C keyboard.

Signed-off-by: Matjaz Hegedic <matjaz.hegedic@gmail.com>
Reviewed-by: Benjamin Tissoires <benjamin.tissoires@redhat.com>
Signed-off-by: Jiri Kosina <jkosina@suse.cz>
drivers/hid/hid-asus.c

index 20fe97fb9bbcac1ebd155a95d047b1c4a77df4c8..e0de54b4f499dcf92e08fb5696ddb56d58d27630 100644 (file)
@@ -63,9 +63,11 @@ MODULE_DESCRIPTION("Asus HID Keyboard and TouchPad");
 #define QUIRK_NO_INIT_REPORTS          BIT(1)
 #define QUIRK_SKIP_INPUT_MAPPING       BIT(2)
 #define QUIRK_IS_MULTITOUCH            BIT(3)
+#define QUIRK_NO_CONSUMER_USAGES       BIT(4)
 
 #define I2C_KEYBOARD_QUIRKS                    (QUIRK_FIX_NOTEBOOK_REPORT | \
-                                                QUIRK_NO_INIT_REPORTS)
+                                                QUIRK_NO_INIT_REPORTS | \
+                                                QUIRK_NO_CONSUMER_USAGES)
 #define I2C_TOUCHPAD_QUIRKS                    (QUIRK_NO_INIT_REPORTS | \
                                                 QUIRK_SKIP_INPUT_MAPPING | \
                                                 QUIRK_IS_MULTITOUCH)
@@ -242,11 +244,28 @@ static int asus_input_mapping(struct hid_device *hdev,
                case 0x5c: asus_map_key_clear(KEY_PROG3);               break;
 
                default:
-                       return 0;
+                       /* ASUS lazily declares 256 usages, ignore the rest,
+                        * as some make the keyboard appear as a pointer device. */
+                       return -1;
                }
                return 1;
        }
 
+       if (drvdata->quirks & QUIRK_NO_CONSUMER_USAGES &&
+               (usage->hid & HID_USAGE_PAGE) == HID_UP_CONSUMER) {
+               switch (usage->hid & HID_USAGE) {
+               case 0xe2: /* Mute */
+               case 0xe9: /* Volume up */
+               case 0xea: /* Volume down */
+                       return 0;
+               default:
+                       /* Ignore dummy Consumer usages which make the
+                        * keyboard incorrectly appear as a pointer device.
+                        */
+                       return -1;
+               }
+       }
+
        return 0;
 }