From a029863d6649889b729e9ac971e8532061f87e97 Mon Sep 17 00:00:00 2001 From: TeTeHacko Date: Fri, 13 Nov 2026 02:11:00 +0100 Subject: [PATCH] FwUpdate binary: the chunk crc covers sid, offset and length too --- src/helpers/FwUpdate.cpp | 5 ++++- src/helpers/FwUpdate.h | 2 +- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/src/helpers/FwUpdate.cpp b/src/helpers/FwUpdate.cpp index 028edd16..414b9583 100644 --- a/src/helpers/FwUpdate.cpp +++ b/src/helpers/FwUpdate.cpp @@ -535,7 +535,10 @@ int FwUpdate::handleBinary(const uint8_t *req, int len, uint8_t *reply, int repl _w_drop++; return 0; } - if (11 + n > len || crc16_update(0xFFFF, &req[11], n) != crc) { + // crc over sid, offset, length AND data: seen on the bench, a fresh header + // with the previous transfer's chunk (data and its crc) behind it + uint16_t want = crc16_update(crc16_update(0xFFFF, &req[2], 7), &req[11], 11 + n <= len ? n : 0); + if (11 + n > len || want != crc) { // the data got mangled on the way (seen: a fresh header with the previous // chunk's data behind it) -- drop it, the bitmap asks for it again _w_bad++; diff --git a/src/helpers/FwUpdate.h b/src/helpers/FwUpdate.h index 2634c494..134491b7 100644 --- a/src/helpers/FwUpdate.h +++ b/src/helpers/FwUpdate.h @@ -39,7 +39,7 @@ // Binary request carrying firmware data (over the mesh, admin only). Upstream // request types are 0x01..0x07; 0xF0 is far from them on purpose. -// [0xF0]['w'][sid u16][offset u32 LE][len u8][crc16 of data][data] chunk, +// [0xF0]['w'][sid u16][offset u32 LE][len u8][crc16 of sid..len + data][data] chunk, // no reply; a bad crc is dropped. The // length is explicit (the node only sees // the decrypted size padded to 16 B); sid