From 232c2bb791f9c8bf010083216fde7b73e81cce2f Mon Sep 17 00:00:00 2001 From: TeTeHacko Date: Fri, 13 Nov 2026 01:30:14 +0100 Subject: [PATCH] FwUpdate: fw bin -- the binary mesh protocol over the USB console (bench) --- src/helpers/FwUpdate.cpp | 26 +++++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/src/helpers/FwUpdate.cpp b/src/helpers/FwUpdate.cpp index 8aa86edf..0d1441f0 100644 --- a/src/helpers/FwUpdate.cpp +++ b/src/helpers/FwUpdate.cpp @@ -971,7 +971,31 @@ bool FwUpdate::handleCommand(uint32_t sender_timestamp, const char *command, cha strcpy(reply, "OK"); } else if (strcmp(arg, "bl") == 0) cmdBootloader(reply); - else if (strcmp(arg, "base") == 0) { + else if (strncmp(arg, "bin ", 4) == 0) { + // Bench: feed a binary REQ_TYPE_FW_OTA payload (base64) through the same + // handler the mesh uses -- padded to the AES block exactly as the node sees + // a decrypted request -- and print the reply. Local console only. + if (sender_timestamp != 0) { + strcpy(reply, "ERR: local only"); + return true; + } + uint8_t req[176], out[150]; + memset(req, 0, sizeof(req)); + int n = b64decode(arg + 4, req, 160); + if (n <= 0) { + strcpy(reply, "ERR: fw bin "); + return true; + } + int padded = ((4 + n + 15) / 16) * 16 - 4; // timestamp + payload, AES-padded + int r = handleBinary(req, padded, out, sizeof(out)); + if (r <= 0) { + strcpy(reply, "> -"); + return true; + } + int pos = sprintf(reply, "> "); + for (int i = 0; i < r && pos < 150; i++) + pos += sprintf(reply + pos, "%02x", out[i]); + } else if (strcmp(arg, "base") == 0) { // full sha256 of the running image: the cached value and a fresh one uint8_t fresh[32]; SHA256 sha;