FwUpdate: fw bin -- the binary mesh protocol over the USB console (bench)
This commit is contained in:
1 parent
dc13c5b286
commit
232c2bb791
1 file changed
+25
-1
@@ -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 <base64>");
|
||||
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;
|
||||
|
||||
Reference in new issue
Block a user