FwUpdate: transfer session id; binary chunks of another session are dropped
This commit is contained in:
1 parent
3a7140fd51
commit
b4d2601c8f
2 files changed
+20
-8
No files matched your search
@@ -521,12 +521,15 @@ 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 >= 7 && req[1] == 'w') {
|
||||
if (len >= 9 && req[1] == 'w') {
|
||||
// the payload arrives padded to the AES block: trust the length byte, not len
|
||||
uint16_t sid;
|
||||
uint32_t off;
|
||||
memcpy(&off, &req[2], 4);
|
||||
int n = req[6];
|
||||
if (7 + n <= len) writeAt(off, &req[7], n); // errors show in the next 'm'
|
||||
memcpy(&sid, &req[2], 2);
|
||||
memcpy(&off, &req[4], 4);
|
||||
int n = req[8];
|
||||
if (_state != RECEIVING || sid != _sid) return 0; // another (stale) transfer
|
||||
if (9 + n <= len) writeAt(off, &req[9], n); // errors show in the next 'm'
|
||||
return 0;
|
||||
}
|
||||
if (len >= 2 && req[1] == 'm' && reply_max >= 5) {
|
||||
@@ -646,7 +649,9 @@ void FwUpdate::cmdStatus(char *reply) {
|
||||
}
|
||||
|
||||
void FwUpdate::cmdBegin(const char *arg, char *reply) {
|
||||
uint32_t total = strtoul(arg, NULL, 10);
|
||||
char *rest;
|
||||
uint32_t total = strtoul(arg, &rest, 10);
|
||||
uint32_t sid = strtoul(rest, NULL, 10); // optional transfer session (binary chunks)
|
||||
// small = delta: top of the free flash, out of reach of the in-place shift;
|
||||
// big = full image: right above the running one, as before
|
||||
uint32_t stage = total <= FW_OTA_PATCH_AREA ? PATCH_LO : (imageEnd() + PAGE - 1) & ~(PAGE - 1);
|
||||
@@ -668,6 +673,7 @@ void FwUpdate::cmdBegin(const char *arg, char *reply) {
|
||||
_job = JOB_NONE;
|
||||
_flash_diff = false;
|
||||
memset(_mani, 0xFF, sizeof(_mani));
|
||||
_sid = (uint16_t)sid;
|
||||
_apply_at = 0;
|
||||
sprintf(reply, "OK %lu chunks of %u at %05lX", (unsigned long)((total + FW_OTA_CHUNK - 1) / FW_OTA_CHUNK),
|
||||
FW_OTA_CHUNK, (unsigned long)stage);
|
||||
|
||||
Reference in new issue
Block a user