1 // SPDX-License-Identifier: GPL-2.0-or-later
2 /* Copyright (c) 2025 TUXEDO Computers GmbH
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 HID_BPF_CONFIG(
11 	HID_DEVICE(BUS_USB, HID_GROUP_GENERIC, 0x048D, 0x8910)
12 );
13 
SEC(HID_BPF_DEVICE_EVENT)14 SEC(HID_BPF_DEVICE_EVENT)
15 int BPF_PROG(ignore_key_fix_event, struct hid_bpf_ctx *hid_ctx)
16 {
17 	const int expected_length = 37;
18 	const int expected_report_id = 1;
19 	__u8 *data;
20 	int i;
21 
22 	if (hid_ctx->size < expected_length)
23 		return 0;
24 
25 	data = hid_bpf_get_data(hid_ctx, 0, expected_length);
26 	if (!data || data[0] != expected_report_id)
27 		return 0;
28 
29 	// Zero out F13 (HID usage ID: 0x68) key press.
30 	// The first 6 parallel key presses (excluding modifier keys) are
31 	// encoded in an array containing usage IDs.
32 	for (i = 3; i < 9; ++i)
33 		if (data[i] == 0x68)
34 			data[i] = 0x00;
35 	// Additional parallel key presses starting with the 7th (excluding
36 	// modifier keys) are encoded as a bit flag with the offset being
37 	// the usage ID.
38 	data[22] &= 0xfe;
39 
40 	return 0;
41 }
42 
43 HID_BPF_OPS(ignore_button) = {
44 	.hid_device_event = (void *)ignore_key_fix_event,
45 };
46 
47 char _license[] SEC("license") = "GPL";
48