#include "vmlinux.h"
#include "hid_bpf.h"
#include "hid_bpf_helpers.h"
#include <bpf/bpf_tracing.h>
#define VID_HUION 0x256C
#define PID_INSPIROY_FREGO_M 0x8251
#define PID_L610 0x2012
#define PEN_RDESC_SIZE 125
#define SECONDARY_SWITCH_OFFSET 17
HID_BPF_CONFIG(
HID_DEVICE(BUS_BLUETOOTH, HID_GROUP_GENERIC, VID_HUION, PID_INSPIROY_FREGO_M),
HID_DEVICE(BUS_USB, HID_GROUP_GENERIC, VID_HUION, PID_L610)
);
SEC(HID_BPF_RDESC_FIXUP)
int BPF_PROG(fix_secondary_barrel_rdesc, struct hid_bpf_ctx *hctx)
{
__u8 *data = hid_bpf_get_data(hctx, 0 , HID_MAX_DESCRIPTOR_SIZE );
if (!data)
return 0;
if (hctx->size != PEN_RDESC_SIZE)
return 0;
if (data[0] != 0x05 || data[1] != 0x0d ||
data[2] != 0x09 || data[3] != 0x02 ||
data[16] != 0x09 ||
data[SECONDARY_SWITCH_OFFSET] != 0x43)
return 0;
data[SECONDARY_SWITCH_OFFSET] = 0x5a;
return 0;
}
HID_BPF_OPS(fix_secondary_barrel) = {
.hid_rdesc_fixup = (void *)fix_secondary_barrel_rdesc,
};
SEC("syscall")
int probe(struct hid_bpf_probe_args *ctx)
{
ctx->retval = ctx->rdesc_size != PEN_RDESC_SIZE;
if (ctx->retval) {
ctx->retval = -EINVAL;
return 0;
}
if (ctx->rdesc[0] != 0x05 || ctx->rdesc[1] != 0x0d ||
ctx->rdesc[2] != 0x09 || ctx->rdesc[3] != 0x02 ||
ctx->rdesc[16] != 0x09 ||
ctx->rdesc[SECONDARY_SWITCH_OFFSET] != 0x43) {
ctx->retval = -EINVAL;
return 0;
}
ctx->retval = 0;
return 0;
}
char _license[] SEC("license") = "GPL";