1 // SPDX-License-Identifier: GPL-2.0
2 /* Copyright (c) 2022 Red hat */
3 #include "vmlinux.h"
4 #include <bpf/bpf_helpers.h>
5 #include <bpf/bpf_tracing.h>
6 #include "hid_bpf_helpers.h"
7 
8 char _license[] SEC("license") = "GPL";
9 
10 struct attach_prog_args {
11 	int prog_fd;
12 	unsigned int hid;
13 	int retval;
14 };
15 
16 __u64 callback_check = 52;
17 __u64 callback2_check = 52;
18 
19 SEC("?fmod_ret/hid_bpf_device_event")
20 int BPF_PROG(hid_first_event, struct hid_bpf_ctx *hid_ctx)
21 {
22 	__u8 *rw_data = hid_bpf_get_data(hid_ctx, 0 /* offset */, 3 /* size */);
23 
24 	if (!rw_data)
25 		return 0; /* EPERM check */
26 
27 	callback_check = rw_data[1];
28 
29 	rw_data[2] = rw_data[1] + 5;
30 
31 	return 0;
32 }
33 
34 SEC("syscall")
35 int attach_prog(struct attach_prog_args *ctx)
36 {
37 	ctx->retval = hid_bpf_attach_prog(ctx->hid,
38 					  ctx->prog_fd,
39 					  0);
40 	return 0;
41 }
42