Path: blob/master/drivers/hid/bpf/progs/IOGEAR__Kaliber-MMOmentum.bpf.c
26285 views
// SPDX-License-Identifier: GPL-2.0-only1/* Copyright (c) 2023 Benjamin Tissoires2*/34#include "vmlinux.h"5#include "hid_bpf.h"6#include "hid_bpf_helpers.h"7#include <bpf/bpf_tracing.h>89#define VID_IOGEAR 0x258A /* VID is shared with SinoWealth and Glorious and prob others */10#define PID_MOMENTUM 0x00271112HID_BPF_CONFIG(13HID_DEVICE(BUS_USB, HID_GROUP_GENERIC, VID_IOGEAR, PID_MOMENTUM)14);1516/*17* The IOGear Kaliber Gaming MMOmentum Pro mouse has multiple buttons (12)18* but only 5 are accessible out of the box because the report descriptor19* marks the other buttons as constants.20* We just fix the report descriptor to enable those missing 7 buttons.21*/2223SEC(HID_BPF_RDESC_FIXUP)24int BPF_PROG(hid_fix_rdesc, struct hid_bpf_ctx *hctx)25{26const u8 offsets[] = {84, 112, 140};27__u8 *data = hid_bpf_get_data(hctx, 0 /* offset */, 4096 /* size */);2829if (!data)30return 0; /* EPERM check */3132/* if not Keyboard */33if (data[3] != 0x06)34return 0;3536for (int idx = 0; idx < ARRAY_SIZE(offsets); idx++) {37u8 offset = offsets[idx];3839/* if Input (Cnst,Var,Abs) , make it Input (Data,Var,Abs) */40if (data[offset] == 0x81 && data[offset + 1] == 0x03)41data[offset + 1] = 0x02;42}4344return 0;45}4647HID_BPF_OPS(iogear_kaliber_momentum) = {48.hid_rdesc_fixup = (void *)hid_fix_rdesc,49};5051SEC("syscall")52int probe(struct hid_bpf_probe_args *ctx)53{54/* only bind to the keyboard interface */55ctx->retval = ctx->rdesc_size != 213;56if (ctx->retval)57ctx->retval = -EINVAL;5859return 0;60}6162char _license[] SEC("license") = "GPL";636465