// SPDX-License-Identifier: GPL-2.0-only
/* Copyright (c) 2024 José Expósito
*/
#include "vmlinux.h"
#include "hid_bpf.h"
#include "hid_bpf_helpers.h"
#include <bpf/bpf_tracing.h>
#define VID_RAPOO 0 x24AE
#define PID_M50 0 x2015
#define RDESC_SIZE 186
HID_BPF_CONFIG(
HID_DEVICE(BUS_USB, HID_GROUP_GENERIC, VID_RAPOO, PID_M50)
);
/*
* The Rapoo M50 Plus Silent mouse has 2 side buttons in addition to the left ,
* right and middle buttons . However , its original HID descriptor has a Usage
* Maximum of 3 , preventing the side buttons to work . This HID - BPF driver
* changes that usage to 5 .
*
* For reference , this is the original report descriptor :
*
* 0 x05 , 0 x01 , // Usage Page (Generic Desktop) 0
* 0 x09 , 0 x02 , // Usage (Mouse) 2
* 0 xa1 , 0 x01 , // Collection (Application) 4
* 0 x85 , 0 x01 , // Report ID (1) 6
* 0 x09 , 0 x01 , // Usage (Pointer) 8
* 0 xa1 , 0 x00 , // Collection (Physical) 10
* 0 x05 , 0 x09 , // Usage Page (Button) 12
* 0 x19 , 0 x01 , // Usage Minimum (1) 14
* 0 x29 , 0 x03 , // Usage Maximum (3) 16 <- change to 0x05
* 0 x15 , 0 x00 , // Logical Minimum (0) 18
* 0 x25 , 0 x01 , // Logical Maximum (1) 20
* 0 x75 , 0 x01 , // Report Size (1) 22
* 0 x95 , 0 x05 , // Report Count (5) 24
* 0 x81 , 0 x02 , // Input (Data,Var,Abs) 26
* 0 x75 , 0 x03 , // Report Size (3) 28
* 0 x95 , 0 x01 , // Report Count (1) 30
* 0 x81 , 0 x01 , // Input (Cnst,Arr,Abs) 32
* 0 x05 , 0 x01 , // Usage Page (Generic Desktop) 34
* 0 x09 , 0 x30 , // Usage (X) 36
* 0 x09 , 0 x31 , // Usage (Y) 38
* 0 x16 , 0 x01 , 0 x80 , // Logical Minimum (-32767) 40
* 0 x26 , 0 xff , 0 x7f , // Logical Maximum (32767) 43
* 0 x75 , 0 x10 , // Report Size (16) 46
* 0 x95 , 0 x02 , // Report Count (2) 48
* 0 x81 , 0 x06 , // Input (Data,Var,Rel) 50
* 0 x09 , 0 x38 , // Usage (Wheel) 52
* 0 x15 , 0 x81 , // Logical Minimum (-127) 54
* 0 x25 , 0 x7f , // Logical Maximum (127) 56
* 0 x75 , 0 x08 , // Report Size (8) 58
* 0 x95 , 0 x01 , // Report Count (1) 60
* 0 x81 , 0 x06 , // Input (Data,Var,Rel) 62
* 0 xc0 , // End Collection 64
* 0 xc0 , // End Collection 65
* 0 x05 , 0 x0c , // Usage Page (Consumer Devices) 66
* 0 x09 , 0 x01 , // Usage (Consumer Control) 68
* 0 xa1 , 0 x01 , // Collection (Application) 70
* 0 x85 , 0 x02 , // Report ID (2) 72
* 0 x75 , 0 x10 , // Report Size (16) 74
* 0 x95 , 0 x01 , // Report Count (1) 76
* 0 x15 , 0 x01 , // Logical Minimum (1) 78
* 0 x26 , 0 x8c , 0 x02 , // Logical Maximum (652) 80
* 0 x19 , 0 x01 , // Usage Minimum (1) 83
* 0 x2a , 0 x8c , 0 x02 , // Usage Maximum (652) 85
* 0 x81 , 0 x00 , // Input (Data,Arr,Abs) 88
* 0 xc0 , // End Collection 90
* 0 x05 , 0 x01 , // Usage Page (Generic Desktop) 91
* 0 x09 , 0 x80 , // Usage (System Control) 93
* 0 xa1 , 0 x01 , // Collection (Application) 95
* 0 x85 , 0 x03 , // Report ID (3) 97
* 0 x09 , 0 x82 , // Usage (System Sleep) 99
* 0 x09 , 0 x81 , // Usage (System Power Down) 101
* 0 x09 , 0 x83 , // Usage (System Wake Up) 103
* 0 x15 , 0 x00 , // Logical Minimum (0) 105
* 0 x25 , 0 x01 , // Logical Maximum (1) 107
* 0 x19 , 0 x01 , // Usage Minimum (1) 109
* 0 x29 , 0 x03 , // Usage Maximum (3) 111
* 0 x75 , 0 x01 , // Report Size (1) 113
* 0 x95 , 0 x03 , // Report Count (3) 115
* 0 x81 , 0 x02 , // Input (Data,Var,Abs) 117
* 0 x95 , 0 x05 , // Report Count (5) 119
* 0 x81 , 0 x01 , // Input (Cnst,Arr,Abs) 121
* 0 xc0 , // End Collection 123
* 0 x05 , 0 x01 , // Usage Page (Generic Desktop) 124
* 0 x09 , 0 x00 , // Usage (Undefined) 126
* 0 xa1 , 0 x01 , // Collection (Application) 128
* 0 x85 , 0 x05 , // Report ID (5) 130
* 0 x06 , 0 x00 , 0 xff , // Usage Page (Vendor Defined Page 1) 132
* 0 x09 , 0 x01 , // Usage (Vendor Usage 1) 135
* 0 x15 , 0 x81 , // Logical Minimum (-127) 137
* 0 x25 , 0 x7f , // Logical Maximum (127) 139
* 0 x75 , 0 x08 , // Report Size (8) 141
* 0 x95 , 0 x07 , // Report Count (7) 143
* 0 xb1 , 0 x02 , // Feature (Data,Var,Abs) 145
* 0 xc0 , // End Collection 147
* 0 x06 , 0 x00 , 0 xff , // Usage Page (Vendor Defined Page 1) 148
* 0 x09 , 0 x0e , // Usage (Vendor Usage 0x0e) 151
* 0 xa1 , 0 x01 , // Collection (Application) 153
* 0 x85 , 0 xba , // Report ID (186) 155
* 0 x95 , 0 x1f , // Report Count (31) 157
* 0 x75 , 0 x08 , // Report Size (8) 159
* 0 x26 , 0 xff , 0 x00 , // Logical Maximum (255) 161
* 0 x15 , 0 x00 , // Logical Minimum (0) 164
* 0 x09 , 0 x01 , // Usage (Vendor Usage 1) 166
* 0 x91 , 0 x02 , // Output (Data,Var,Abs) 168
* 0 x85 , 0 xba , // Report ID (186) 170
* 0 x95 , 0 x1f , // Report Count (31) 172
* 0 x75 , 0 x08 , // Report Size (8) 174
* 0 x26 , 0 xff , 0 x00 , // Logical Maximum (255) 176
* 0 x15 , 0 x00 , // Logical Minimum (0) 179
* 0 x09 , 0 x01 , // Usage (Vendor Usage 1) 181
* 0 x81 , 0 x02 , // Input (Data,Var,Abs) 183
* 0 xc0 , // End Collection 185
*/
SEC(HID_BPF_RDESC_FIXUP)
int BPF_PROG(hid_rdesc_fixup_rapoo_m50, struct hid_bpf_ctx *hctx)
{
__u8 *data = hid_bpf_get_data(hctx, 0 , HID_MAX_DESCRIPTOR_SIZE);
if (!data)
return 0 ; /* EPERM check */
if (data[17 ] == 0 x03)
data[17 ] = 0 x05;
return 0 ;
}
HID_BPF_OPS(rapoo_m50) = {
.hid_rdesc_fixup = (void *)hid_rdesc_fixup_rapoo_m50,
};
SEC("syscall" )
int probe(struct hid_bpf_probe_args *ctx)
{
ctx->retval = ctx->rdesc_size != RDESC_SIZE;
if (ctx->retval)
ctx->retval = -EINVAL;
return 0 ;
}
char _license[] SEC("license" ) = "GPL" ;
Messung V0.5 in Prozent C=36 H=100 G=74
¤ Dauer der Verarbeitung: 0.13 Sekunden
(vorverarbeitet am 2026-09-28)
¤
*© Formatika GbR, Deutschland