| 1 | // SPDX-License-Identifier: GPL-2.0-only |
| 2 | /* Copyright (c) 2023 Benjamin Tissoires |
| 3 | */ |
| 4 | |
| 5 | #include "vmlinux.h" |
| 6 | #include "hid_bpf.h" |
| 7 | #include "hid_bpf_helpers.h" |
| 8 | #include <bpf/bpf_tracing.h> |
| 9 | |
| 10 | #define VID_HP 0x03F0 |
| 11 | #define PID_ELITE_PRESENTER 0x464A |
| 12 | |
| 13 | HID_BPF_CONFIG( |
| 14 | HID_DEVICE(BUS_BLUETOOTH, HID_GROUP_GENERIC, VID_HP, PID_ELITE_PRESENTER) |
| 15 | ); |
| 16 | |
| 17 | /* |
| 18 | * Already fixed as of commit 0db117359e47 ("HID: add quirk for 03f0:464a |
| 19 | * HP Elite Presenter Mouse") in the kernel, but this is a slightly better |
| 20 | * fix. |
| 21 | * |
| 22 | * The HP Elite Presenter Mouse HID Record Descriptor shows |
| 23 | * two mice (Report ID 0x1 and 0x2), one keypad (Report ID 0x5), |
| 24 | * two Consumer Controls (Report IDs 0x6 and 0x3). |
| 25 | * Prior to these fixes it registers one mouse, one keypad |
| 26 | * and one Consumer Control, and it was usable only as a |
| 27 | * digital laser pointer (one of the two mouses). |
| 28 | * We replace the second mouse collection with a pointer collection, |
| 29 | * allowing to use the device both as a mouse and a digital laser |
| 30 | * pointer. |
| 31 | */ |
| 32 | |
| 33 | SEC(HID_BPF_RDESC_FIXUP) |
| 34 | int BPF_PROG(hid_fix_rdesc, struct hid_bpf_ctx *hctx) |
| 35 | { |
| 36 | __u8 *data = hid_bpf_get_data(hctx, 0 /* offset */, 4096 /* size */); |
| 37 | |
| 38 | if (!data) |
| 39 | return 0; /* EPERM check */ |
| 40 | |
| 41 | /* replace application mouse by application pointer on the second collection */ |
| 42 | if (data[79] == 0x02) |
| 43 | data[79] = 0x01; |
| 44 | |
| 45 | return 0; |
| 46 | } |
| 47 | |
| 48 | HID_BPF_OPS(hp_elite_presenter) = { |
| 49 | .hid_rdesc_fixup = (void *)hid_fix_rdesc, |
| 50 | }; |
| 51 | |
| 52 | SEC("syscall" ) |
| 53 | int probe(struct hid_bpf_probe_args *ctx) |
| 54 | { |
| 55 | ctx->retval = ctx->rdesc_size != 264; |
| 56 | if (ctx->retval) |
| 57 | ctx->retval = -EINVAL; |
| 58 | |
| 59 | return 0; |
| 60 | } |
| 61 | |
| 62 | char _license[] SEC("license" ) = "GPL" ; |
| 63 | |