drivers/hid/bpf/progs/Huion__Kamvas16Gen3.bpf.c

Source file repositories/reference/linux-study-clean/drivers/hid/bpf/progs/Huion__Kamvas16Gen3.bpf.c

File Facts

System
Linux kernel
Corpus path
drivers/hid/bpf/progs/Huion__Kamvas16Gen3.bpf.c
Extension
.c
Size
35521 bytes
Lines
725
Domain
Driver Families
Bucket
drivers/hid
Inferred role
Driver Families: implementation source
Status
source implementation candidate

Why This File Exists

Repeatable hardware-adapter layer. Deep compatibility for every driver is out of scope; this atlas records patterns, probe lifecycles, bus glue, IRQ/DMA usage, and links back to core abstractions.

Dependency Surface

Detected Declarations

Annotated Snippet

struct pad_report {
			__u8 report_id;
			__u8 btn_stylus:1;
			__u8 padding:7;
			__u8 x;
			__u8 y;
			__u8 buttons;
			__s8 top_wheel;
			__s8 bottom_wheel;
		} __attribute__((packed)) *pad_report;

		__s8 top_wheel = 0;
		__s8 bottom_wheel = 0;

		switch (report_subtype) {
		case VENDOR_REPORT_SUBTYPE_WHEELS:
			/*
			 * The wheel direction byte is 1 for clockwise rotation
			 * and 2 for counter-clockwise.
			 * Change it to 1 and -1, respectively.
			 */
			switch (data[3]) {
			case 1:
				top_wheel = (data[5] == 1) ? 1 : -1;
				break;
			case 2:
				bottom_wheel = (data[5] == 1) ? 1 : -1;
				break;
			}
			break;

		case VENDOR_REPORT_SUBTYPE_BUTTONS:
			/*
			 * If a button is already being held, ignore any new
			 * button event unless it's a release.
			 *
			 * The tablet only cleanly handles one button being held
			 * at a time, and trying to hold multiple buttons
			 * (particularly wheel+pad buttons) can result in sequences
			 * of reports that look like imaginary presses and releases.
			 *
			 * This is an imperfect way to filter out some of these
			 * reports.
			 */
			if (last_button_state != 0x00 && data[4] != 0x00)
				break;

			last_button_state = data[4];
			break;
		}

		pad_report = (struct pad_report *)data;

		pad_report->report_id = CUSTOM_PAD_REPORT_ID;
		pad_report->btn_stylus = 0;
		pad_report->x = 0;
		pad_report->y = 0;
		pad_report->buttons = last_button_state;
		pad_report->top_wheel = top_wheel;
		pad_report->bottom_wheel = bottom_wheel;

		return sizeof(struct pad_report);
	}

	return 0;
}

HID_BPF_OPS(huion_kamvas16_gen3) = {
	.hid_device_event = (void *)hid_fix_event_huion_kamvas16_gen3,
	.hid_rdesc_fixup = (void *)hid_fix_rdesc_huion_kamvas16_gen3,
};

SEC("syscall")
int probe(struct hid_bpf_probe_args *ctx)
{
	switch (ctx->rdesc_size) {
	case VENDOR_DESCRIPTOR_LENGTH:
	case TABLET_DESCRIPTOR_LENGTH:
	case WHEEL_DESCRIPTOR_LENGTH:
		ctx->retval = 0;
		break;
	default:
		ctx->retval = -EINVAL;
	}

	return 0;
}

char _license[] SEC("license") = "GPL";

Annotation

Implementation Notes