Path: blob/master/drivers/hid/bpf/progs/Generic__touchpad.bpf.c
170956 views
// SPDX-License-Identifier: GPL-2.0-only1/* Copyright (c) 2025 Benjamin Tissoires2*/34#include "vmlinux.h"5#include "hid_bpf.h"6#include "hid_bpf_helpers.h"7#include "hid_report_helpers.h"8#include "hid_usages.h"9#include <bpf/bpf_tracing.h>1011HID_BPF_CONFIG(12HID_DEVICE(BUS_ANY, HID_GROUP_MULTITOUCH_WIN_8, HID_VID_ANY, HID_PID_ANY),13);1415EXPORT_UDEV_PROP(HID_DIGITIZER_PAD_TYPE, 32);1617__u8 hw_req_buf[1024];1819/* to be filled by udev-hid-bpf */20struct hid_rdesc_descriptor HID_REPORT_DESCRIPTOR;2122SEC("syscall")23int probe(struct hid_bpf_probe_args *ctx)24{25struct hid_rdesc_report *pad_type_feature = NULL;26struct hid_rdesc_field *pad_type = NULL;27struct hid_rdesc_report *feature;28struct hid_bpf_ctx *hid_ctx;29char *pad_type_str = "";30int ret;3132hid_bpf_for_each_feature_report(&HID_REPORT_DESCRIPTOR, feature) {33struct hid_rdesc_field *field;3435hid_bpf_for_each_field(feature, field) {36if (field->usage_page == HidUsagePage_Digitizers &&37field->usage_id == HidUsage_Dig_PadType) {38pad_type = field;39pad_type_feature = feature;40break;41}42}43if (pad_type)44break;45}4647if (!pad_type || !pad_type_feature) {48ctx->retval = -EINVAL;49return 0;50}5152hid_ctx = hid_bpf_allocate_context(ctx->hid);5354if (!hid_ctx)55return -1; /* EPERM check */5657hw_req_buf[0] = pad_type_feature->report_id;5859ret = hid_bpf_hw_request(hid_ctx, hw_req_buf, sizeof(hw_req_buf),60HID_FEATURE_REPORT, HID_REQ_GET_REPORT);61hid_bpf_release_context(hid_ctx);6263if (ret < 0) {64ctx->retval = ret;65return 0;66}6768ctx->retval = 0;6970switch (EXTRACT_BITS(hw_req_buf, pad_type)) {71case 0:72pad_type_str = "Clickpad";73break;74case 1:75pad_type_str = "Pressurepad";76break;77case 2:78pad_type_str = "Discrete";79break;80default:81pad_type_str = "Unknown";82}8384UDEV_PROP_SPRINTF(HID_DIGITIZER_PAD_TYPE, "%s", pad_type_str);8586return 0;87}8889char _license[] SEC("license") = "GPL";909192