Skip to content

Commit fa84da5

Browse files
mlaschcarlescufi
authored andcommitted
net: lib: lwm2m: Cancel firmware DOWNLOADED state with NULL byte
Allow to cancel a firmware update in DOWNLOADED state by writing a NULL byte as described in the Firmware Update object version 1.1 (urn:oma:lwm2m:oma:5:1.1). Keep object version 1.0 mechanism with an `empty string`. Signed-off-by: Marc Lasch <[email protected]>
1 parent f7f0889 commit fa84da5

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

subsys/net/lib/lwm2m/lwm2m_obj_firmware.c

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -239,14 +239,17 @@ static int package_write_cb(uint16_t obj_inst_id, uint16_t res_id,
239239
* make sure it fail after timeout
240240
*/
241241
lwm2m_firmware_set_update_state_inst(obj_inst_id, STATE_DOWNLOADING);
242-
} else if (state != STATE_DOWNLOADING) {
243-
if (data_len == 0U && state == STATE_DOWNLOADED) {
242+
} else if (state == STATE_DOWNLOADED) {
243+
if (data_len == 0U || (data_len == 1U && data[0] == '\0')) {
244244
/* reset to state idle and result default */
245245
lwm2m_firmware_set_update_result_inst(obj_inst_id, RESULT_DEFAULT);
246+
LOG_DBG("Update canceled by writing %d bytes", data_len);
246247
return 0;
247248
}
248-
249-
LOG_DBG("Cannot download: state = %d", state);
249+
LOG_WRN("Download has already completed");
250+
return -EPERM;
251+
} else if (state != STATE_DOWNLOADING) {
252+
LOG_WRN("Cannot download: state = %d", state);
250253
return -EPERM;
251254
}
252255

0 commit comments

Comments
 (0)