Commit | Line | Data |
---|---|---|
4e6d2a29 BT |
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("fmod_ret/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 | SEC("syscall") | |
49 | int probe(struct hid_bpf_probe_args *ctx) | |
50 | { | |
51 | ctx->retval = ctx->rdesc_size != 264; | |
52 | if (ctx->retval) | |
53 | ctx->retval = -EINVAL; | |
54 | ||
55 | return 0; | |
56 | } | |
57 | ||
58 | char _license[] SEC("license") = "GPL"; |