From 96840adcdc592d82a55f62c947786f0117fbcd67 Mon Sep 17 00:00:00 2001 From: Mikhail Burakov Date: Sat, 8 Jul 2023 15:37:48 +0200 Subject: Reply to incoming ping messages --- input.c | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) (limited to 'input.c') diff --git a/input.c b/input.c index 6add38d..7b35442 100644 --- a/input.c +++ b/input.c @@ -21,11 +21,13 @@ #include #include #include +#include #include #include #include #include +#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: -- cgit v1.2.3