diff --git a/subsys/net/lib/lwm2m/CMakeLists.txt b/subsys/net/lib/lwm2m/CMakeLists.txt index 7246ff7099..9971283cff 100644 --- a/subsys/net/lib/lwm2m/CMakeLists.txt +++ b/subsys/net/lib/lwm2m/CMakeLists.txt @@ -2,6 +2,8 @@ zephyr_library() +zephyr_library_compile_definitions(_POSIX_C_SOURCE=200809L) + zephyr_include_directories(.) zephyr_library_sources( diff --git a/subsys/net/lib/lwm2m/lwm2m_obj_firmware.c b/subsys/net/lib/lwm2m/lwm2m_obj_firmware.c index 082197c83a..ad31316354 100644 --- a/subsys/net/lib/lwm2m/lwm2m_obj_firmware.c +++ b/subsys/net/lib/lwm2m/lwm2m_obj_firmware.c @@ -305,13 +305,14 @@ static int package_uri_write_cb(uint16_t obj_inst_id, uint16_t res_id, #ifdef CONFIG_LWM2M_FIRMWARE_UPDATE_PULL_SUPPORT uint8_t state = lwm2m_firmware_get_update_state_inst(obj_inst_id); + bool empty_uri = data_len == 0 || strnlen(data, data_len) == 0; if (state == STATE_IDLE) { - if (data_len > 0) { + if (!empty_uri) { lwm2m_firmware_set_update_state_inst(obj_inst_id, STATE_DOWNLOADING); lwm2m_firmware_start_transfer(obj_inst_id, package_uri[obj_inst_id]); } - } else if (state == STATE_DOWNLOADED && data_len == 0U) { + } else if (state == STATE_DOWNLOADED && empty_uri) { /* reset to state idle and result default */ lwm2m_firmware_set_update_result_inst(obj_inst_id, RESULT_DEFAULT); }