summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMikhail Burakov <mburakov@mailbox.org>2023-07-08 15:37:48 +0200
committerMikhail Burakov <mburakov@mailbox.org>2023-07-08 15:37:48 +0200
commit96840adcdc592d82a55f62c947786f0117fbcd67 (patch)
treeb5f89ab3c9caa5b81ca13d99411775f53caba34b
parentfb859712f36254ca9c34773b82618a09626c8cd9 (diff)
Reply to incoming ping messages
-rw-r--r--input.c22
1 files changed, 22 insertions, 0 deletions
diff --git a/input.c b/input.c
index 6add38d..7b35442 100644
--- a/input.c
+++ b/input.c
@@ -21,11 +21,13 @@
#include <fcntl.h>
#include <linux/uhid.h>
#include <stddef.h>
+#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
+#include "proto.h"
#include "toolbox/buffer.h"
#include "toolbox/utils.h"
@@ -90,6 +92,26 @@ bool InputHandlerHandle(struct InputHandler* input_handler, int fd) {
return true;
}
+ if (event->type == ~0u) {
+ // mburakov: Special case, a ping message.
+ size_t size = sizeof(event->type) + sizeof(uint64_t);
+ if (input_handler->buffer.size < size) {
+ // mburakov: Payload of ping message is not yet available.
+ return true;
+ }
+ char buffer[sizeof(struct Proto) + sizeof(uint64_t)];
+ struct Proto* proto = (void*)buffer;
+ proto->size = sizeof(uint64_t);
+ proto->type = PROTO_TYPE_MISC;
+ memcpy(proto->data, &event->u, sizeof(uint64_t));
+ if (write(fd, buffer, sizeof(buffer)) != sizeof(buffer)) {
+ LOG("Failed to write pong message (%s)", strerror(errno));
+ return false;
+ }
+ BufferDiscard(&input_handler->buffer, size);
+ continue;
+ }
+
size_t size;
switch (event->type) {
case UHID_CREATE2: