// SPDX-License-Identifier: GPL-2.0-only
/* Copyright (c) 2024 Benjamin Tissoires
*/
#include "vmlinux.h"
#include "hid_bpf.h"
#include "hid_bpf_helpers.h"
#include <bpf/bpf_tracing.h>
#define VID_BETOP_2185PC 0 x11C0
#define PID_RAPTOR_MACH_2 0 x5606
HID_BPF_CONFIG(
HID_DEVICE(BUS_USB, HID_GROUP_GENERIC, VID_BETOP_2185PC, PID_RAPTOR_MACH_2),
);
/*
* For reference , this is the fixed report descriptor
*
* static const _ _ u8 fixed_rdesc [ ] = {
* 0 x05 , 0 x01 , // Usage Page (Generic Desktop) 0
* 0 x09 , 0 x04 , // Usage (Joystick) 2
* 0 xa1 , 0 x01 , // Collection (Application) 4
* 0 x05 , 0 x01 , // Usage Page (Generic Desktop) 6
* 0 x85 , 0 x01 , // Report ID (1) 8
* 0 x05 , 0 x01 , // Usage Page (Generic Desktop) 10
* 0 x09 , 0 x30 , // Usage (X) 12
* 0 x75 , 0 x10 , // Report Size (16) 14
* 0 x95 , 0 x01 , // Report Count (1) 16
* 0 x15 , 0 x00 , // Logical Minimum (0) 18
* 0 x26 , 0 xff , 0 x07 , // Logical Maximum (2047) 20
* 0 x46 , 0 xff , 0 x07 , // Physical Maximum (2047) 23
* 0 x81 , 0 x02 , // Input (Data,Var,Abs) 26
* 0 x05 , 0 x01 , // Usage Page (Generic Desktop) 28
* 0 x09 , 0 x31 , // Usage (Y) 30
* 0 x75 , 0 x10 , // Report Size (16) 32
* 0 x95 , 0 x01 , // Report Count (1) 34
* 0 x15 , 0 x00 , // Logical Minimum (0) 36
* 0 x26 , 0 xff , 0 x07 , // Logical Maximum (2047) 38
* 0 x46 , 0 xff , 0 x07 , // Physical Maximum (2047) 41
* 0 x81 , 0 x02 , // Input (Data,Var,Abs) 44
* 0 x05 , 0 x01 , // Usage Page (Generic Desktop) 46
* 0 x09 , 0 x33 , // Usage (Rx) 48
* 0 x75 , 0 x10 , // Report Size (16) 50
* 0 x95 , 0 x01 , // Report Count (1) 52
* 0 x15 , 0 x00 , // Logical Minimum (0) 54
* 0 x26 , 0 xff , 0 x03 , // Logical Maximum (1023) 56
* 0 x46 , 0 xff , 0 x03 , // Physical Maximum (1023) 59
* 0 x81 , 0 x02 , // Input (Data,Var,Abs) 62
* 0 x05 , 0 x00 , // Usage Page (Undefined) 64
* 0 x09 , 0 x00 , // Usage (Undefined) 66
* 0 x75 , 0 x10 , // Report Size (16) 68
* 0 x95 , 0 x01 , // Report Count (1) 70
* 0 x15 , 0 x00 , // Logical Minimum (0) 72
* 0 x26 , 0 xff , 0 x03 , // Logical Maximum (1023) 74
* 0 x46 , 0 xff , 0 x03 , // Physical Maximum (1023) 77
* 0 x81 , 0 x02 , // Input (Data,Var,Abs) 80
* 0 x05 , 0 x01 , // Usage Page (Generic Desktop) 82
* 0 x09 , 0 x32 , // Usage (Z) 84
* 0 x75 , 0 x10 , // Report Size (16) 86
* 0 x95 , 0 x01 , // Report Count (1) 88
* 0 x15 , 0 x00 , // Logical Minimum (0) 90
* 0 x26 , 0 xff , 0 x03 , // Logical Maximum (1023) 92
* 0 x46 , 0 xff , 0 x03 , // Physical Maximum (1023) 95
* 0 x81 , 0 x02 , // Input (Data,Var,Abs) 98
* 0 x05 , 0 x01 , // Usage Page (Generic Desktop) 100
* 0 x09 , 0 x35 , // Usage (Rz) 102
* 0 x75 , 0 x10 , // Report Size (16) 104
* 0 x95 , 0 x01 , // Report Count (1) 106
* 0 x15 , 0 x00 , // Logical Minimum (0) 108
* 0 x26 , 0 xff , 0 x03 , // Logical Maximum (1023) 110
* 0 x46 , 0 xff , 0 x03 , // Physical Maximum (1023) 113
* 0 x81 , 0 x02 , // Input (Data,Var,Abs) 116
* 0 x05 , 0 x01 , // Usage Page (Generic Desktop) 118
* 0 x09 , 0 x34 , // Usage (Ry) 120
* 0 x75 , 0 x10 , // Report Size (16) 122
* 0 x95 , 0 x01 , // Report Count (1) 124
* 0 x15 , 0 x00 , // Logical Minimum (0) 126
* 0 x26 , 0 xff , 0 x07 , // Logical Maximum (2047) 128
* 0 x46 , 0 xff , 0 x07 , // Physical Maximum (2047) 131
* 0 x81 , 0 x02 , // Input (Data,Var,Abs) 134
* 0 x05 , 0 x01 , // Usage Page (Generic Desktop) 136
* 0 x09 , 0 x36 , // Usage (Slider) 138
* 0 x75 , 0 x10 , // Report Size (16) 140
* 0 x95 , 0 x01 , // Report Count (1) 142
* 0 x15 , 0 x00 , // Logical Minimum (0) 144
* 0 x26 , 0 xff , 0 x03 , // Logical Maximum (1023) 146
* 0 x46 , 0 xff , 0 x03 , // Physical Maximum (1023) 149
* 0 x81 , 0 x02 , // Input (Data,Var,Abs) 152
* 0 x05 , 0 x09 , // Usage Page (Button) 154
* 0 x19 , 0 x01 , // Usage Minimum (1) 156
* 0 x2a , 0 x1d , 0 x00 , // Usage Maximum (29) 158
* 0 x15 , 0 x00 , // Logical Minimum (0) 161
* 0 x25 , 0 x01 , // Logical Maximum (1) 163
* 0 x75 , 0 x01 , // Report Size (1) 165
* 0 x96 , 0 x80 , 0 x00 , // Report Count (128) 167
* 0 x81 , 0 x02 , // Input (Data,Var,Abs) 170
* 0 x05 , 0 x01 , // Usage Page (Generic Desktop) 172
* 0 x09 , 0 x39 , // Usage (Hat switch) 174
* 0 x26 , 0 x07 , 0 x00 , // Logical Maximum (7) 176 // changed (was 239)
* 0 x46 , 0 x68 , 0 x01 , // Physical Maximum (360) 179
* 0 x65 , 0 x14 , // Unit (EnglishRotation: deg) 182
* 0 x75 , 0 x10 , // Report Size (16) 184
* 0 x95 , 0 x01 , // Report Count (1) 186
* 0 x81 , 0 x42 , // Input (Data,Var,Abs,Null) 188
* 0 x05 , 0 x01 , // Usage Page (Generic Desktop) 190
* 0 x09 , 0 x00 , // Usage (Undefined) 192
* 0 x75 , 0 x08 , // Report Size (8) 194
* 0 x95 , 0 x1d , // Report Count (29) 196
* 0 x81 , 0 x01 , // Input (Cnst,Arr,Abs) 198
* 0 x15 , 0 x00 , // Logical Minimum (0) 200
* 0 x26 , 0 xef , 0 x00 , // Logical Maximum (239) 202
* 0 x85 , 0 x58 , // Report ID (88) 205
* 0 x26 , 0 xff , 0 x00 , // Logical Maximum (255) 207
* 0 x46 , 0 xff , 0 x00 , // Physical Maximum (255) 210
* 0 x75 , 0 x08 , // Report Size (8) 213
* 0 x95 , 0 x3f , // Report Count (63) 215
* 0 x09 , 0 x00 , // Usage (Undefined) 217
* 0 x91 , 0 x02 , // Output (Data,Var,Abs) 219
* 0 x85 , 0 x59 , // Report ID (89) 221
* 0 x75 , 0 x08 , // Report Size (8) 223
* 0 x95 , 0 x80 , // Report Count (128) 225
* 0 x09 , 0 x00 , // Usage (Undefined) 227
* 0 xb1 , 0 x02 , // Feature (Data,Var,Abs) 229
* 0 xc0 , // End Collection 231
* } ;
*/
/*
* We need to amend the report descriptor for the following :
* - the joystick sends its hat_switch data between 0 and 239 but
* the kernel expects the logical max to stick into a signed 8 bits
* integer . We thus divide it by 30 to match what other joysticks are
* doing
*/
SEC(HID_BPF_RDESC_FIXUP)
int BPF_PROG(hid_fix_rdesc_raptor_mach_2, struct hid_bpf_ctx *hctx)
{
__u8 *data = hid_bpf_get_data(hctx, 0 /* offset */, HID_MAX_DESCRIPTOR_SIZE /* size */);
if (!data)
return 0 ; /* EPERM check */
data[177 ] = 0 x07;
return 0 ;
}
/*
* The hat_switch value at offsets 33 and 34 ( 16 bits ) needs
* to be reduced to a single 8 bit signed integer . So we
* divide it by 30 .
* Byte 34 is always null , so it is ignored .
*/
SEC(HID_BPF_DEVICE_EVENT)
int BPF_PROG(raptor_mach_2_fix_hat_switch, struct hid_bpf_ctx *hctx)
{
__u8 *data = hid_bpf_get_data(hctx, 0 /* offset */, 64 /* size */);
if (!data)
return 0 ; /* EPERM check */
if (data[0 ] != 0 x01) /* not the joystick report ID */
return 0 ;
data[33 ] /= 30 ;
return 0 ;
}
HID_BPF_OPS(raptor_mach_2) = {
.hid_rdesc_fixup = (void *)hid_fix_rdesc_raptor_mach_2,
.hid_device_event = (void *)raptor_mach_2_fix_hat_switch,
};
SEC("syscall" )
int probe(struct hid_bpf_probe_args *ctx)
{
ctx->retval = ctx->rdesc_size != 232 ;
if (ctx->retval)
ctx->retval = -EINVAL;
/* ensure the kernel isn't fixed already */
if (ctx->rdesc[177 ] != 0 xef) /* Logical Max of 239 */
ctx->retval = -EINVAL;
return 0 ;
}
char _license[] SEC("license" ) = "GPL" ;
Messung V0.5 in Prozent C=40 H=100 G=76
¤ Dauer der Verarbeitung: 0.14 Sekunden
(vorverarbeitet am 2026-10-01)
¤
*© Formatika GbR, Deutschland