brintos

brintos / linux-shallow public Read only

0
0
Text · 1.6 KiB · c2413fa Raw
63 lines · c
1// SPDX-License-Identifier: GPL-2.0-only2/* Copyright (c) 2023 Benjamin Tissoires3 */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 0x03F011#define PID_ELITE_PRESENTER 0x464A12 13HID_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:464a19 * HP Elite Presenter Mouse") in the kernel, but this is a slightly better20 * fix.21 *22 * The HP Elite Presenter Mouse HID Record Descriptor shows23 * 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 keypad26 * and one Consumer Control, and it was usable only as a27 * 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 laser30 * pointer.31 */32 33SEC(HID_BPF_RDESC_FIXUP)34int 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 48HID_BPF_OPS(hp_elite_presenter) = {49	.hid_rdesc_fixup = (void *)hid_fix_rdesc,50};51 52SEC("syscall")53int 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 62char _license[] SEC("license") = "GPL";63