hid_mouse.bpf.c (9a87ffc99ec8eb8d35eed7c4f816d75f5cc9662e) hid_mouse.bpf.c (e342d6f6f7d82b48c4540b947d8032a3b7b3e6f8)
1// SPDX-License-Identifier: GPL-2.0
2
3#include "vmlinux.h"
4#include <bpf/bpf_helpers.h>
5#include <bpf/bpf_tracing.h>
6#include "hid_bpf_helpers.h"
7
1// SPDX-License-Identifier: GPL-2.0
2
3#include "vmlinux.h"
4#include <bpf/bpf_helpers.h>
5#include <bpf/bpf_tracing.h>
6#include "hid_bpf_helpers.h"
7
8SEC("fmod_ret/hid_bpf_device_event")
9int BPF_PROG(hid_y_event, struct hid_bpf_ctx *hctx)
8static int hid_y_event(struct hid_bpf_ctx *hctx)
10{
11 s16 y;
12 __u8 *data = hid_bpf_get_data(hctx, 0 /* offset */, 9 /* size */);
13
14 if (!data)
15 return 0; /* EPERM check */
16
17 bpf_printk("event: size: %d", hctx->size);

--- 28 unchanged lines hidden (view full) ---

46 bpf_printk(" %02x %02x %02x",
47 data[6],
48 data[7],
49 data[8]);
50
51 return 0;
52}
53
9{
10 s16 y;
11 __u8 *data = hid_bpf_get_data(hctx, 0 /* offset */, 9 /* size */);
12
13 if (!data)
14 return 0; /* EPERM check */
15
16 bpf_printk("event: size: %d", hctx->size);

--- 28 unchanged lines hidden (view full) ---

45 bpf_printk(" %02x %02x %02x",
46 data[6],
47 data[7],
48 data[8]);
49
50 return 0;
51}
52
54SEC("fmod_ret/hid_bpf_device_event")
55int BPF_PROG(hid_x_event, struct hid_bpf_ctx *hctx)
53static int hid_x_event(struct hid_bpf_ctx *hctx)
56{
57 s16 x;
58 __u8 *data = hid_bpf_get_data(hctx, 0 /* offset */, 9 /* size */);
59
60 if (!data)
61 return 0; /* EPERM check */
62
63 x = data[1] | (data[2] << 8);
64
65 x = -x;
66
67 data[1] = x & 0xFF;
68 data[2] = (x >> 8) & 0xFF;
69 return 0;
70}
71
54{
55 s16 x;
56 __u8 *data = hid_bpf_get_data(hctx, 0 /* offset */, 9 /* size */);
57
58 if (!data)
59 return 0; /* EPERM check */
60
61 x = data[1] | (data[2] << 8);
62
63 x = -x;
64
65 data[1] = x & 0xFF;
66 data[2] = (x >> 8) & 0xFF;
67 return 0;
68}
69
72SEC("fmod_ret/hid_bpf_rdesc_fixup")
70SEC("struct_ops/device_event")
71int BPF_PROG(hid_event, struct hid_bpf_ctx *hctx, enum hid_report_type type)
72{
73 int ret = hid_y_event(hctx);
74
75 if (ret)
76 return ret;
77
78 return hid_x_event(hctx);
79}
80
81
82SEC("struct_ops/rdesc_fixup")
73int BPF_PROG(hid_rdesc_fixup, struct hid_bpf_ctx *hctx)
74{
75 __u8 *data = hid_bpf_get_data(hctx, 0 /* offset */, 4096 /* size */);
76
77 if (!data)
78 return 0; /* EPERM check */
79
80 bpf_printk("rdesc: %02x %02x %02x",

--- 23 unchanged lines hidden (view full) ---

104 * We simply swap the axes here.
105 */
106 data[39] = 0x31;
107 data[41] = 0x30;
108
109 return 0;
110}
111
83int BPF_PROG(hid_rdesc_fixup, struct hid_bpf_ctx *hctx)
84{
85 __u8 *data = hid_bpf_get_data(hctx, 0 /* offset */, 4096 /* size */);
86
87 if (!data)
88 return 0; /* EPERM check */
89
90 bpf_printk("rdesc: %02x %02x %02x",

--- 23 unchanged lines hidden (view full) ---

114 * We simply swap the axes here.
115 */
116 data[39] = 0x31;
117 data[41] = 0x30;
118
119 return 0;
120}
121
122SEC(".struct_ops.link")
123struct hid_bpf_ops mouse_invert = {
124 .rdesc_fixup = (void *)hid_rdesc_fixup,
125 .device_event = (void *)hid_event,
126};
127
112char _license[] SEC("license") = "GPL";
128char _license[] SEC("license") = "GPL";