STRUCT HID_BPF_OPS(9)
π NAME π
okay so this is struct hid_bpf_ops(9) β straight from the Kernel API Manual, bestie β and it's literally a BPF struct_ops of callbacks allowing to attach HID-BPF programs to a HID device. no cap, that's the whole vibe. π¦
β¨ SYNOPSIS β¨
here's the exact shape of the struct, no cap:
struct hid_bpf_ops {
int hid_id;
u32 flags;
int (*hid_device_event)(struct hid_bpf_ctx *ctx, enum
hid_report_type report_type, u64 source);
int (*hid_rdesc_fixup)(struct hid_bpf_ctx *ctx);
int (*hid_hw_request)(struct hid_bpf_ctx *ctx, unsigned char
reportnum, enum hid_report_type rtype, enum hid_class_request reqtype,
u64 source);
int (*hid_hw_output_report)(struct hid_bpf_ctx *ctx, u64 source);
};
π Members π
πΈ hid_id πΈ
the HID uniq ID to attach to. This is writeable before load, and cannot be changed after. periodt. π
π flags π
flags used while attaching the struct_ops to the device. Currently only available value is 0 or BPF_F_BEFORE. Writeable only before load. so yeah, set it before load or it's not happening π
π«Ά hid_device_event π«Ά
called whenever an event is coming in from the device. π
It has the following arguments:
ctx: The HID-BPF context asstruct hid_bpf_ctx.- Return:
0on success and keep processing; a positive value to change the incoming size buffer; a negative error code to interrupt the processing of this event. - Context: Interrupt context. β‘
π§ hid_rdesc_fixup π§
called when the probe function parses the report descriptor of the HID device. π¦
It has the following arguments:
ctx: The HID-BPF context asstruct hid_bpf_ctx.- Return:
0on success and keep processing; a positive value to change the incoming size buffer; a negative error code to interrupt the processing of this device.
π₯ hid_hw_request π₯
called whenever a hid_hw_raw_request call is emitted on the HID device.
It has the following arguments:
ctx: The HID-BPF context asstruct hid_bpf_ctx.reportnum: the report number, as inhid_hw_raw_request.rtype: the report type (HID_INPUT_REPORT,HID_FEATURE_REPORT,HID_OUTPUT_REPORT).reqtype: the request.source: au64referring to a uniq but identifiable source. If0, the kernel itself emitted that call. For hidraw,sourceis set to the associatedstruct file *.- Return:
0to keep processing the request by hid-core; any other value stops hid-core from processing that event. A positive value should be returned with the number of bytes returned in the incoming buffer; a negative error code interrupts the processing of this call.
π hid_hw_output_report π
called whenever a hid_hw_output_report call is emitted on the HID device.
It has the following arguments:
ctx: The HID-BPF context asstruct hid_bpf_ctx.source: au64referring to a uniq but identifiable source. If0, the kernel itself emitted that call. For hidraw,sourceis set to the associatedstruct file *.- Return:
0to keep processing the request by hid-core; any other value stops hid-core from processing that event. A positive value should be returned with the number of bytes written to the device; a negative error code interrupts the processing of this call.
π SEE ALSO π
check out the kernel file ./include/linux/hid_bpf.h and struct hid_bpf_ctx(9) β that's the whole family, iykyk. π
mwah π β source/version ./include/linux, date October 2026, and this iconic page is struct hid_bpf_ops(9).
π¦ where this page comes from
- nixpkgs unstable: linux-manual 7.3.1
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms