Path: blob/master/drivers/hid/bpf/progs/Thrustmaster__TCA-Yoke-Boeing.bpf.c
26285 views
// SPDX-License-Identifier: GPL-2.0-only1/* Copyright (c) 2024 Kumar Swarnam Iyer ([email protected])2*/34#include "vmlinux.h"5#include "hid_bpf.h"6#include "hid_bpf_helpers.h"7#include <bpf/bpf_tracing.h>89#define VID_THRUSTMASTER 0x044F10#define PID_TCA_YOKE_BOEING 0x04091112HID_BPF_CONFIG(13HID_DEVICE(BUS_USB, HID_GROUP_GENERIC, VID_THRUSTMASTER, PID_TCA_YOKE_BOEING)14);1516/* The original HID descriptor of the Thrustmaster TCA Yoke Boeing joystick contains17* an Input field that shows up as an axis, ABS_MISC in Linux. But it is not possible18* to assign an actual physical control to this axis as they're all taken up. There19* are 2 vendor-defined inputs where the Input type appears to be defined wrongly.20* This bpf attempts to fix this by changing the Inputs so that it doesn't show up in21* Linux at all.22* This version is the short version fix that only changes 2 fields in the descriptor23* instead of the whole report descriptor.24* For reference, this is the original report descriptor:25*26* 0x05, 0x01, // Usage Page (Generic Desktop) 027* 0x09, 0x04, // Usage (Joystick) 228* 0xa1, 0x01, // Collection (Application) 429* 0x85, 0x01, // Report ID (1) 630* 0x09, 0x39, // Usage (Hat switch) 831* 0x15, 0x00, // Logical Minimum (0) 1032* 0x25, 0x07, // Logical Maximum (7) 1233* 0x35, 0x00, // Physical Minimum (0) 1434* 0x46, 0x3b, 0x01, // Physical Maximum (315) 1635* 0x65, 0x14, // Unit (EnglishRotation: deg) 1936* 0x75, 0x04, // Report Size (4) 2137* 0x95, 0x01, // Report Count (1) 2338* 0x81, 0x42, // Input (Data,Var,Abs,Null) 2539* 0x65, 0x00, // Unit (None) 2740* 0x05, 0x09, // Usage Page (Button) 2941* 0x19, 0x01, // Usage Minimum (1) 3142* 0x29, 0x12, // Usage Maximum (18) 3343* 0x15, 0x00, // Logical Minimum (0) 3544* 0x25, 0x01, // Logical Maximum (1) 3745* 0x75, 0x01, // Report Size (1) 3946* 0x95, 0x12, // Report Count (18) 4147* 0x81, 0x02, // Input (Data,Var,Abs) 4348* 0x95, 0x02, // Report Count (2) 4549* 0x81, 0x03, // Input (Cnst,Var,Abs) 4750* 0x05, 0x01, // Usage Page (Generic Desktop) 4951* 0x09, 0x31, // Usage (Y) 5152* 0x09, 0x30, // Usage (X) 5353* 0x09, 0x32, // Usage (Z) 5554* 0x09, 0x34, // Usage (Ry) 5755* 0x09, 0x33, // Usage (Rx) 5956* 0x09, 0x35, // Usage (Rz) 6157* 0x15, 0x00, // Logical Minimum (0) 6358* 0x27, 0xff, 0xff, 0x00, 0x00, // Logical Maximum (65535) 6559* 0x75, 0x10, // Report Size (16) 7060* 0x95, 0x06, // Report Count (6) 7261* 0x81, 0x02, // Input (Data,Var,Abs) 7462* 0x06, 0xf0, 0xff, // Usage Page (Vendor Usage Page 0xfff0) 7663* 0x09, 0x59, // Usage (Vendor Usage 0x59) 7964* 0x15, 0x00, // Logical Minimum (0) 8165* 0x26, 0xff, 0x00, // Logical Maximum (255) 8366* 0x75, 0x08, // Report Size (8) 8667* 0x95, 0x01, // Report Count (1) 8868* 0x81, 0x02, // Input (Data,Var,Abs) 90 --> Needs to be changed69* 0x09, 0x51, // Usage (Vendor Usage 0x51) 9270* 0x15, 0x00, // Logical Minimum (0) 9471* 0x26, 0xff, 0x00, // Logical Maximum (255) 9672* 0x75, 0x08, // Report Size (8) 9973* 0x95, 0x20, // Report Count (32) 101 --> Needs to be changed74* 0x81, 0x02, // Input (Data,Var,Abs) 10375* 0x09, 0x50, // Usage (Vendor Usage 0x50) 10576* 0x15, 0x00, // Logical Minimum (0) 10777* 0x26, 0xff, 0x00, // Logical Maximum (255) 10978* 0x75, 0x08, // Report Size (8) 11279* 0x95, 0x0f, // Report Count (15) 11480* 0x81, 0x03, // Input (Cnst,Var,Abs) 11681* 0x09, 0x47, // Usage (Vendor Usage 0x47) 11882* 0x85, 0xf2, // Report ID (242) 12083* 0x15, 0x00, // Logical Minimum (0) 12284* 0x26, 0xff, 0x00, // Logical Maximum (255) 12485* 0x75, 0x08, // Report Size (8) 12786* 0x95, 0x3f, // Report Count (63) 12987* 0xb1, 0x02, // Feature (Data,Var,Abs) 13188* 0x09, 0x48, // Usage (Vendor Usage 0x48) 13389* 0x85, 0xf3, // Report ID (243) 13590* 0x15, 0x00, // Logical Minimum (0) 13791* 0x26, 0xff, 0x00, // Logical Maximum (255) 13992* 0x75, 0x08, // Report Size (8) 14293* 0x95, 0x3f, // Report Count (63) 14494* 0xb1, 0x02, // Feature (Data,Var,Abs) 14695* 0xc0, // End Collection 14896*/9798SEC(HID_BPF_RDESC_FIXUP)99int BPF_PROG(hid_fix_rdesc_tca_yoke, struct hid_bpf_ctx *hctx)100{101const int expected_length = 148;102103if (hctx->size != expected_length)104return 0;105106__u8 *data = hid_bpf_get_data(hctx, 0 /* offset */, HID_MAX_DESCRIPTOR_SIZE /* size */);107108if (!data)109return 0; /* EPERM */110111/* Safety check, our probe() should take care of this though */112if (data[1] != 0x01 /* Generic Desktop */ || data[3] != 0x04 /* Joystick */)113return 0;114115/* The report descriptor sets incorrect Input items in 2 places, resulting in a116* non-existing axis showing up.117* This change sets the correct Input which prevents the axis from showing up in Linux.118*/119120if (data[90] == 0x81 && /* Input */121data[103] == 0x81) { /* Input */122data[91] = 0x03; /* Input set to 0x03 Constant, Variable Absolute */123data[104] = 0x03; /* Input set to 0X03 Constant, Variable Absolute */124}125126return 0;127}128129HID_BPF_OPS(tca_yoke) = {130.hid_rdesc_fixup = (void *)hid_fix_rdesc_tca_yoke,131};132133SEC("syscall")134int probe(struct hid_bpf_probe_args *ctx)135{136/* ensure the kernel isn't fixed already */137if (ctx->rdesc[91] != 0x02) /* Input for 0x59 Usage type has changed */138ctx->retval = -EINVAL;139140return 0;141}142143char _license[] SEC("license") = "GPL";144145146