1 // SPDX-License-Identifier: GPL-2.0
4 #include <bpf/bpf_helpers.h>
5 #include <bpf/bpf_tracing.h>
6 #include "hid_bpf_helpers.h"
8 SEC("fmod_ret/hid_bpf_device_event")
9 int BPF_PROG(hid_y_event, struct hid_bpf_ctx *hctx)
12 __u8 *data = hid_bpf_get_data(hctx, 0 /* offset */, 9 /* size */);
15 return 0; /* EPERM check */
17 bpf_printk("event: size: %d", hctx->size);
18 bpf_printk("incoming event: %02x %02x %02x",
22 bpf_printk(" %02x %02x %02x",
26 bpf_printk(" %02x %02x %02x",
31 y = data[3] | (data[4] << 8);
36 data[4] = (y >> 8) & 0xFF;
38 bpf_printk("modified event: %02x %02x %02x",
42 bpf_printk(" %02x %02x %02x",
46 bpf_printk(" %02x %02x %02x",
54 SEC("fmod_ret/hid_bpf_device_event")
55 int BPF_PROG(hid_x_event, struct hid_bpf_ctx *hctx)
58 __u8 *data = hid_bpf_get_data(hctx, 0 /* offset */, 9 /* size */);
61 return 0; /* EPERM check */
63 x = data[1] | (data[2] << 8);
68 data[2] = (x >> 8) & 0xFF;
72 SEC("fmod_ret/hid_bpf_rdesc_fixup")
73 int BPF_PROG(hid_rdesc_fixup, struct hid_bpf_ctx *hctx)
75 __u8 *data = hid_bpf_get_data(hctx, 0 /* offset */, 4096 /* size */);
78 return 0; /* EPERM check */
80 bpf_printk("rdesc: %02x %02x %02x",
84 bpf_printk(" %02x %02x %02x",
88 bpf_printk(" %02x %02x %02x ...",
94 * The original report descriptor contains:
96 * 0x05, 0x01, // Usage Page (Generic Desktop) 30
97 * 0x16, 0x01, 0x80, // Logical Minimum (-32767) 32
98 * 0x26, 0xff, 0x7f, // Logical Maximum (32767) 35
99 * 0x09, 0x30, // Usage (X) 38
100 * 0x09, 0x31, // Usage (Y) 40
102 * So byte 39 contains Usage X and byte 41 Usage Y.
104 * We simply swap the axes here.
112 char _license[] SEC("license") = "GPL";