hc
2024-02-20 102a0743326a03cd1a1202ceda21e175b7d3575c
kernel/tools/testing/selftests/bpf/test_lirc_mode2_user.c
....@@ -29,6 +29,7 @@
2929
3030 #include <linux/bpf.h>
3131 #include <linux/lirc.h>
32
+#include <linux/input.h>
3233 #include <errno.h>
3334 #include <stdio.h>
3435 #include <stdlib.h>
....@@ -47,12 +48,13 @@
4748 int main(int argc, char **argv)
4849 {
4950 struct bpf_object *obj;
50
- int ret, lircfd, progfd, mode;
51
- int testir = 0x1dead;
51
+ int ret, lircfd, progfd, inputfd;
52
+ int testir1 = 0x1dead;
53
+ int testir2 = 0x20101;
5254 u32 prog_ids[10], prog_flags[10], prog_cnt;
5355
54
- if (argc != 2) {
55
- printf("Usage: %s /dev/lircN\n", argv[0]);
56
+ if (argc != 3) {
57
+ printf("Usage: %s /dev/lircN /dev/input/eventM\n", argv[0]);
5658 return 2;
5759 }
5860
....@@ -76,9 +78,9 @@
7678 return 1;
7779 }
7880
79
- mode = LIRC_MODE_SCANCODE;
80
- if (ioctl(lircfd, LIRC_SET_REC_MODE, &mode)) {
81
- printf("failed to set rec mode: %m\n");
81
+ inputfd = open(argv[2], O_RDONLY | O_NONBLOCK);
82
+ if (inputfd == -1) {
83
+ printf("failed to open input device %s: %m\n", argv[1]);
8284 return 1;
8385 }
8486
....@@ -102,27 +104,52 @@
102104 }
103105
104106 /* Write raw IR */
105
- ret = write(lircfd, &testir, sizeof(testir));
106
- if (ret != sizeof(testir)) {
107
+ ret = write(lircfd, &testir1, sizeof(testir1));
108
+ if (ret != sizeof(testir1)) {
107109 printf("Failed to send test IR message: %m\n");
108110 return 1;
109111 }
110112
111
- struct pollfd pfd = { .fd = lircfd, .events = POLLIN };
112
- struct lirc_scancode lsc;
113
+ struct pollfd pfd = { .fd = inputfd, .events = POLLIN };
114
+ struct input_event event;
113115
114
- poll(&pfd, 1, 100);
116
+ for (;;) {
117
+ poll(&pfd, 1, 100);
115118
116
- /* Read decoded IR */
117
- ret = read(lircfd, &lsc, sizeof(lsc));
118
- if (ret != sizeof(lsc)) {
119
- printf("Failed to read decoded IR: %m\n");
119
+ /* Read decoded IR */
120
+ ret = read(inputfd, &event, sizeof(event));
121
+ if (ret != sizeof(event)) {
122
+ printf("Failed to read decoded IR: %m\n");
123
+ return 1;
124
+ }
125
+
126
+ if (event.type == EV_MSC && event.code == MSC_SCAN &&
127
+ event.value == 0xdead) {
128
+ break;
129
+ }
130
+ }
131
+
132
+ /* Write raw IR */
133
+ ret = write(lircfd, &testir2, sizeof(testir2));
134
+ if (ret != sizeof(testir2)) {
135
+ printf("Failed to send test IR message: %m\n");
120136 return 1;
121137 }
122138
123
- if (lsc.scancode != 0xdead || lsc.rc_proto != 64) {
124
- printf("Incorrect scancode decoded\n");
125
- return 1;
139
+ for (;;) {
140
+ poll(&pfd, 1, 100);
141
+
142
+ /* Read decoded IR */
143
+ ret = read(inputfd, &event, sizeof(event));
144
+ if (ret != sizeof(event)) {
145
+ printf("Failed to read decoded IR: %m\n");
146
+ return 1;
147
+ }
148
+
149
+ if (event.type == EV_REL && event.code == REL_Y &&
150
+ event.value == 1 ) {
151
+ break;
152
+ }
126153 }
127154
128155 prog_cnt = 10;