Path: blob/master/drivers/hid/bpf/progs/Rapoo__M50-Plus-Silent.bpf.c
26285 views
// SPDX-License-Identifier: GPL-2.0-only1/* Copyright (c) 2024 José Expósito2*/34#include "vmlinux.h"5#include "hid_bpf.h"6#include "hid_bpf_helpers.h"7#include <bpf/bpf_tracing.h>89#define VID_RAPOO 0x24AE10#define PID_M50 0x201511#define RDESC_SIZE 1861213HID_BPF_CONFIG(14HID_DEVICE(BUS_USB, HID_GROUP_GENERIC, VID_RAPOO, PID_M50)15);1617/*18* The Rapoo M50 Plus Silent mouse has 2 side buttons in addition to the left,19* right and middle buttons. However, its original HID descriptor has a Usage20* Maximum of 3, preventing the side buttons to work. This HID-BPF driver21* changes that usage to 5.22*23* For reference, this is the original report descriptor:24*25* 0x05, 0x01, // Usage Page (Generic Desktop) 026* 0x09, 0x02, // Usage (Mouse) 227* 0xa1, 0x01, // Collection (Application) 428* 0x85, 0x01, // Report ID (1) 629* 0x09, 0x01, // Usage (Pointer) 830* 0xa1, 0x00, // Collection (Physical) 1031* 0x05, 0x09, // Usage Page (Button) 1232* 0x19, 0x01, // Usage Minimum (1) 1433* 0x29, 0x03, // Usage Maximum (3) 16 <- change to 0x0534* 0x15, 0x00, // Logical Minimum (0) 1835* 0x25, 0x01, // Logical Maximum (1) 2036* 0x75, 0x01, // Report Size (1) 2237* 0x95, 0x05, // Report Count (5) 2438* 0x81, 0x02, // Input (Data,Var,Abs) 2639* 0x75, 0x03, // Report Size (3) 2840* 0x95, 0x01, // Report Count (1) 3041* 0x81, 0x01, // Input (Cnst,Arr,Abs) 3242* 0x05, 0x01, // Usage Page (Generic Desktop) 3443* 0x09, 0x30, // Usage (X) 3644* 0x09, 0x31, // Usage (Y) 3845* 0x16, 0x01, 0x80, // Logical Minimum (-32767) 4046* 0x26, 0xff, 0x7f, // Logical Maximum (32767) 4347* 0x75, 0x10, // Report Size (16) 4648* 0x95, 0x02, // Report Count (2) 4849* 0x81, 0x06, // Input (Data,Var,Rel) 5050* 0x09, 0x38, // Usage (Wheel) 5251* 0x15, 0x81, // Logical Minimum (-127) 5452* 0x25, 0x7f, // Logical Maximum (127) 5653* 0x75, 0x08, // Report Size (8) 5854* 0x95, 0x01, // Report Count (1) 6055* 0x81, 0x06, // Input (Data,Var,Rel) 6256* 0xc0, // End Collection 6457* 0xc0, // End Collection 6558* 0x05, 0x0c, // Usage Page (Consumer Devices) 6659* 0x09, 0x01, // Usage (Consumer Control) 6860* 0xa1, 0x01, // Collection (Application) 7061* 0x85, 0x02, // Report ID (2) 7262* 0x75, 0x10, // Report Size (16) 7463* 0x95, 0x01, // Report Count (1) 7664* 0x15, 0x01, // Logical Minimum (1) 7865* 0x26, 0x8c, 0x02, // Logical Maximum (652) 8066* 0x19, 0x01, // Usage Minimum (1) 8367* 0x2a, 0x8c, 0x02, // Usage Maximum (652) 8568* 0x81, 0x00, // Input (Data,Arr,Abs) 8869* 0xc0, // End Collection 9070* 0x05, 0x01, // Usage Page (Generic Desktop) 9171* 0x09, 0x80, // Usage (System Control) 9372* 0xa1, 0x01, // Collection (Application) 9573* 0x85, 0x03, // Report ID (3) 9774* 0x09, 0x82, // Usage (System Sleep) 9975* 0x09, 0x81, // Usage (System Power Down) 10176* 0x09, 0x83, // Usage (System Wake Up) 10377* 0x15, 0x00, // Logical Minimum (0) 10578* 0x25, 0x01, // Logical Maximum (1) 10779* 0x19, 0x01, // Usage Minimum (1) 10980* 0x29, 0x03, // Usage Maximum (3) 11181* 0x75, 0x01, // Report Size (1) 11382* 0x95, 0x03, // Report Count (3) 11583* 0x81, 0x02, // Input (Data,Var,Abs) 11784* 0x95, 0x05, // Report Count (5) 11985* 0x81, 0x01, // Input (Cnst,Arr,Abs) 12186* 0xc0, // End Collection 12387* 0x05, 0x01, // Usage Page (Generic Desktop) 12488* 0x09, 0x00, // Usage (Undefined) 12689* 0xa1, 0x01, // Collection (Application) 12890* 0x85, 0x05, // Report ID (5) 13091* 0x06, 0x00, 0xff, // Usage Page (Vendor Defined Page 1) 13292* 0x09, 0x01, // Usage (Vendor Usage 1) 13593* 0x15, 0x81, // Logical Minimum (-127) 13794* 0x25, 0x7f, // Logical Maximum (127) 13995* 0x75, 0x08, // Report Size (8) 14196* 0x95, 0x07, // Report Count (7) 14397* 0xb1, 0x02, // Feature (Data,Var,Abs) 14598* 0xc0, // End Collection 14799* 0x06, 0x00, 0xff, // Usage Page (Vendor Defined Page 1) 148100* 0x09, 0x0e, // Usage (Vendor Usage 0x0e) 151101* 0xa1, 0x01, // Collection (Application) 153102* 0x85, 0xba, // Report ID (186) 155103* 0x95, 0x1f, // Report Count (31) 157104* 0x75, 0x08, // Report Size (8) 159105* 0x26, 0xff, 0x00, // Logical Maximum (255) 161106* 0x15, 0x00, // Logical Minimum (0) 164107* 0x09, 0x01, // Usage (Vendor Usage 1) 166108* 0x91, 0x02, // Output (Data,Var,Abs) 168109* 0x85, 0xba, // Report ID (186) 170110* 0x95, 0x1f, // Report Count (31) 172111* 0x75, 0x08, // Report Size (8) 174112* 0x26, 0xff, 0x00, // Logical Maximum (255) 176113* 0x15, 0x00, // Logical Minimum (0) 179114* 0x09, 0x01, // Usage (Vendor Usage 1) 181115* 0x81, 0x02, // Input (Data,Var,Abs) 183116* 0xc0, // End Collection 185117*/118119SEC(HID_BPF_RDESC_FIXUP)120int BPF_PROG(hid_rdesc_fixup_rapoo_m50, struct hid_bpf_ctx *hctx)121{122__u8 *data = hid_bpf_get_data(hctx, 0, HID_MAX_DESCRIPTOR_SIZE);123124if (!data)125return 0; /* EPERM check */126127if (data[17] == 0x03)128data[17] = 0x05;129130return 0;131}132133HID_BPF_OPS(rapoo_m50) = {134.hid_rdesc_fixup = (void *)hid_rdesc_fixup_rapoo_m50,135};136137SEC("syscall")138int probe(struct hid_bpf_probe_args *ctx)139{140ctx->retval = ctx->rdesc_size != RDESC_SIZE;141if (ctx->retval)142ctx->retval = -EINVAL;143144return 0;145}146147char _license[] SEC("license") = "GPL";148149150