FwUpdate binary: explicit chunk length (the node sees the payload padded to 16 B)

This commit is contained in:
tth committed 2026-11-13 01:18:27 +01:00
1 parent 4813340a69
commit d1e893f692
2 files changed
+8 -4

No files matched your search

+4 -2
View File
@@ -516,10 +516,12 @@ const char *FwUpdate::writeAt(uint32_t off, const uint8_t *buf, int len) {
}
int FwUpdate::handleBinary(const uint8_t *req, int len, uint8_t *reply, int reply_max) {
if (len >= 6 && req[1] == 'w') {
if (len >= 7 && req[1] == 'w') {
// the payload arrives padded to the AES block: trust the length byte, not len
uint32_t off;
memcpy(&off, &req[2], 4);
writeAt(off, &req[6], len - 6); // errors show in the next 'm'
int n = req[6];
if (7 + n <= len) writeAt(off, &req[7], n); // errors show in the next 'm'
return 0;
}
if (len >= 2 && req[1] == 'm' && reply_max >= 5) {
+4 -2
View File
@@ -35,11 +35,13 @@
// Received data is tracked in units of FW_OTA_UNIT bytes, so text chunks (96 B)
// and binary chunks (FW_OTA_BCHUNK) can both land in it.
#define FW_OTA_UNIT 32
#define FW_OTA_BCHUNK 160 // binary chunk: 5 units, fits one encrypted REQ (166 B max)
#define FW_OTA_BCHUNK 128 // binary chunk: 4 units; the companion host frame (176 B) limits it
// 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'][offset u32 LE][data] chunk, no reply (fire and forget)
// [0xF0]['w'][offset u32 LE][len u8][data] chunk, no reply. The length is
// explicit: the node only sees the
// decrypted size padded to 16 B.
// [0xF0]['m'] reply: [state][units u16][count u16]
// [missing unit index u16 ...]
// state: 0 idle, 1 receiving, 2 ready, 3 failed, 4 busy (manifest/verify)