// 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_UGEE 0 x28BD
#define PID_DECO_MINI_4 0 x0929
#define RDESC_SIZE_PAD 177
#define RDESC_SIZE_PEN 109
#define PAD_REPORT_ID 0 x06
/*
* XP - Pen devices return a descriptor with the values the driver should use when
* one of its interfaces is queried . For this device the descriptor is :
*
* 0 E 03 60 4 F 88 3 B 06 00 FF 1 F D8 13
* - - - - - - - - - - - - - - - - - - - -
* | | | |
* | | | ` - Resolution : 5080 ( 13 d8 )
* | | ` - Maximum pressure : 8191 ( 1 FFF )
* | ` - Logical maximum Y : 15240 ( 3 B88 )
* ` - Logical maximum X : 20320 ( 4 F60 )
*
* The physical maximum is calculated as ( logical_max * 1000 ) / resolution .
*/
#define LOGICAL_MAX_X 0 x60, 0 x4F
#define LOGICAL_MAX_Y 0 x88, 0 x3B
#define PHYSICAL_MAX_X 0 xA0, 0 x0F
#define PHYSICAL_MAX_Y 0 xB8, 0 x0B
#define PRESSURE_MAX 0 xFF, 0 x1F
HID_BPF_CONFIG(
HID_DEVICE(BUS_USB, HID_GROUP_GENERIC, VID_UGEE, PID_DECO_MINI_4)
);
/*
* The tablet send these values when the pad buttons are pressed individually :
*
* Buttons released : 06 00 00 00 00 00 00 00
* Button 1 : 06 00 05 00 00 00 00 00 - > b
* Button 2 : 06 00 08 00 00 00 00 00 - > e
* Button 3 : 06 04 00 00 00 00 00 00 - > LAlt
* Button 4 : 06 00 2 c 00 00 00 00 00 - > Space
* Button 5 : 06 01 16 00 00 00 00 00 - > LControl + s
* Button 6 : 06 01 1 d 00 00 00 00 00 - > LControl + z
*
* When multiple buttons are pressed at the same time , the values used to
* identify the buttons are identical , but they appear in different bytes of the
* record . For example , when button 2 ( 0 x08 ) and button 1 ( 0 x05 ) are pressed ,
* this is the report :
*
* Buttons 2 and 1 : 06 00 08 05 00 00 00 00 - > e + b
*
* Buttons 1 , 2 , 4 , 5 and 6 can be matched by finding their values in the
* report .
*
* Button 3 is pressed when the 3 rd bit is 1 . For example , pressing buttons 3
* and 5 generates this report :
*
* Buttons 3 and 5 : 06 05 16 00 00 00 00 00 - > LControl + LAlt + s
* - - - -
* | |
* | ` - Button 5 ( 0 x16 )
* ` - 0 x05 = 0101 . Button 3 is pressed
* ^
*
* pad_buttons contains a list of buttons that can be matched in
* HID_BPF_DEVICE_EVENT . Button 3 as it has a dedicated bit .
*/
static const __u8 pad_buttons[] = { 0 x05, 0 x08, 0 x00, 0 x2C, 0 x16, 0 x1D };
static const __u8 fixed_pad_rdesc[] = {
0 x05, 0 x01, /* Usage Page (Desktop), */
0 x09, 0 x07, /* Usage (Keypad), */
0 xA1, 0 x01, /* Collection (Application), */
0 x85, 0 x06, /* Report ID (6), */
0 x05, 0 x0D, /* Usage Page (Digitizer), */
0 x09, 0 x39, /* Usage (Tablet Function Keys), */
0 xA0, /* Collection (Physical), */
0 x05, 0 x09, /* Usage Page (Button), */
0 x75, 0 x01, /* Report Size (1), */
0 x95, 0 x06, /* Report Count (6), */
0 x19, 0 x01, /* Usage Minimum (01h), */
0 x29, 0 x06, /* Usage Maximum (06h), */
0 x14, /* Logical Minimum (0), */
0 x25, 0 x01, /* Logical Maximum (1), */
0 x81, 0 x02, /* Input (Variable), */
0 x95, 0 x32, /* Report Count (50), */
0 x81, 0 x01, /* Input (Constant), */
0 xC0, /* End Collection, */
0 xC0 /* End Collection */
};
static const __u8 fixed_pen_rdesc[] = {
0 x05, 0 x0d, /* Usage Page (Digitizers), */
0 x09, 0 x01, /* Usage (Digitizer), */
0 xa1, 0 x01, /* Collection (Application), */
0 x85, 0 x07, /* Report ID (7), */
0 x09, 0 x20, /* Usage (Stylus), */
0 xa1, 0 x00, /* Collection (Physical), */
0 x09, 0 x42, /* Usage (Tip Switch), */
0 x09, 0 x44, /* Usage (Barrel Switch), */
0 x09, 0 x46, /* Usage (Tablet Pick), */
0 x75, 0 x01, /* Report Size (1), */
0 x95, 0 x03, /* Report Count (3), */
0 x14, /* Logical Minimum (0), */
0 x25, 0 x01, /* Logical Maximum (1), */
0 x81, 0 x02, /* Input (Variable), */
0 x95, 0 x02, /* Report Count (2), */
0 x81, 0 x03, /* Input (Constant, Variable), */
0 x09, 0 x32, /* Usage (In Range), */
0 x95, 0 x01, /* Report Count (1), */
0 x81, 0 x02, /* Input (Variable), */
0 x95, 0 x02, /* Report Count (2), */
0 x81, 0 x03, /* Input (Constant, Variable), */
0 x75, 0 x10, /* Report Size (16), */
0 x95, 0 x01, /* Report Count (1), */
0 x35, 0 x00, /* Physical Minimum (0), */
0 xa4, /* Push, */
0 x05, 0 x01, /* Usage Page (Desktop), */
0 x09, 0 x30, /* Usage (X), */
0 x65, 0 x13, /* Unit (Inch), */
0 x55, 0 x0d, /* Unit Exponent (-3), */
0 x26, LOGICAL_MAX_X, /* Logical Maximum, */
0 x46, PHYSICAL_MAX_X, /* Physical Maximum, */
0 x81, 0 x02, /* Input (Variable), */
0 x09, 0 x31, /* Usage (Y), */
0 x26, LOGICAL_MAX_Y, /* Logical Maximum, */
0 x46, PHYSICAL_MAX_Y, /* Physical Maximum, */
0 x81, 0 x02, /* Input (Variable), */
0 xb4, /* Pop, */
0 x09, 0 x30, /* Usage (Tip Pressure), */
0 x45, 0 x00, /* Physical Maximum (0), */
0 x26, PRESSURE_MAX, /* Logical Maximum, */
0 x75, 0 x0D, /* Report Size (13), */
0 x95, 0 x01, /* Report Count (1), */
0 x81, 0 x02, /* Input (Variable), */
0 x75, 0 x01, /* Report Size (1), */
0 x95, 0 x13, /* Report Count (19), */
0 x81, 0 x01, /* Input (Constant), */
0 xc0, /* End Collection, */
0 xc0, /* End Collection */
};
static const size_t fixed_pad_rdesc_size = sizeof (fixed_pad_rdesc);
static const size_t fixed_pen_rdesc_size = sizeof (fixed_pen_rdesc);
SEC(HID_BPF_RDESC_FIXUP)
int BPF_PROG(hid_rdesc_fixup_xppen_deco_mini_4, struct hid_bpf_ctx *hctx)
{
__u8 *data = hid_bpf_get_data(hctx, 0 , HID_MAX_DESCRIPTOR_SIZE);
if (!data)
return 0 ; /* EPERM check */
if (hctx->size == RDESC_SIZE_PAD) {
__builtin_memcpy(data, fixed_pad_rdesc, fixed_pad_rdesc_size);
return fixed_pad_rdesc_size;
} else if (hctx->size == RDESC_SIZE_PEN) {
__builtin_memcpy(data, fixed_pen_rdesc, fixed_pen_rdesc_size);
return fixed_pen_rdesc_size;
}
return 0 ;
}
SEC(HID_BPF_DEVICE_EVENT)
int BPF_PROG(hid_device_event_xppen_deco_mini_4, struct hid_bpf_ctx *hctx)
{
__u8 *data = hid_bpf_get_data(hctx, 0 /* offset */, 8 /* size */);
__u8 button_mask = 0 ;
int d, b;
if (!data)
return 0 ; /* EPERM check */
if (data[0 ] != PAD_REPORT_ID)
return 0 ;
/* data[1] stores the status of BTN_2 in the 3rd bit*/
if (data[1 ] & BIT(2 ))
button_mask |= BIT(2 );
/* The rest of the descriptor stores the buttons as in pad_buttons */
for (d = 2 ; d < 8 ; d++) {
for (b = 0 ; b < sizeof (pad_buttons); b++) {
if (data[d] != 0 && data[d] == pad_buttons[b])
button_mask |= BIT(b);
}
}
__u8 report[8 ] = {PAD_REPORT_ID, button_mask, 0 x00};
__builtin_memcpy(data, report, sizeof (report));
return 0 ;
}
HID_BPF_OPS(deco_mini_4) = {
.hid_device_event = (void *)hid_device_event_xppen_deco_mini_4,
.hid_rdesc_fixup = (void *)hid_rdesc_fixup_xppen_deco_mini_4,
};
SEC("syscall" )
int probe(struct hid_bpf_probe_args *ctx)
{
/*
* The device has 2 modes : The compatibility mode , enabled by default ,
* and the raw mode , that can be activated by sending a buffer of magic
* data to a certain USB endpoint .
*
* Depending on the mode , different interfaces of the device are used :
* - First interface : Pad in compatibility mode
* - Second interface : Pen in compatibility mode
* - Third interface : Only used in raw mode
*
* We ' ll use the device in compatibility mode .
*/
ctx->retval = ctx->rdesc_size != RDESC_SIZE_PAD &&
ctx->rdesc_size != RDESC_SIZE_PEN;
if (ctx->retval)
ctx->retval = -EINVAL;
return 0 ;
}
char _license[] SEC("license" ) = "GPL" ;
Messung V0.5 in Prozent C=77 H=95 G=86
¤ Dauer der Verarbeitung: 0.2 Sekunden
(vorverarbeitet am 2026-09-28)
¤
*© Formatika GbR, Deutschland