Skip to content

Commit cdbcdac

Browse files
committed
net: lwm2m_client_utils: Don't rewrite settings during load
When lwm2m_firmware.c is loading settings from flash, it should block the write function that is triggered when changing values from LwM2M registry. Signed-off-by: Seppo Takalo <[email protected]>
1 parent d48178a commit cdbcdac

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

subsys/net/lib/lwm2m_client_utils/lwm2m/lwm2m_firmware.c

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ static int application_obj_id;
8585
static int modem_obj_id;
8686
static int smp_obj_id;
8787
static int target_image_type[FOTA_INSTANCE_COUNT];
88+
static bool loading_settings;
8889

8990

9091
static void dfu_target_cb(enum dfu_target_evt_id evt);
@@ -251,6 +252,7 @@ static int set(const char *key, size_t len_rd, settings_read_cb read_cb, void *c
251252
}
252253

253254
LOG_DBG("Loading \"%s\"", key);
255+
loading_settings = true;
254256

255257
ret = lwm2m_string_to_path(key, &path, '/');
256258
if (ret) {
@@ -285,9 +287,16 @@ static int set(const char *key, size_t len_rd, settings_read_cb read_cb, void *c
285287
return 0;
286288
}
287289

290+
static int commit(void)
291+
{
292+
loading_settings = false;
293+
return 0;
294+
}
295+
288296
static struct settings_handler lwm2m_firm_settings = {
289297
.name = LWM2M_FIRM_PREFIX,
290298
.h_set = set,
299+
.h_commit = commit,
291300
};
292301

293302
static int write_resource_to_settings(uint16_t inst, uint16_t res, uint8_t *data, uint16_t data_len)
@@ -298,6 +307,10 @@ static int write_resource_to_settings(uint16_t inst, uint16_t res, uint8_t *data
298307
return -EINVAL;
299308
}
300309

310+
if (loading_settings) {
311+
return 0;
312+
}
313+
301314
snprintk(path, sizeof(path), SETTINGS_FIRM_PATH_FMT,
302315
(uint16_t)ENABLED_LWM2M_FIRMWARE_OBJECT, inst, res);
303316
if (settings_save_one(path, data, data_len)) {
@@ -311,6 +324,10 @@ static int write_image_type_to_settings(uint16_t inst, int img_type)
311324
{
312325
char path[SETTINGS_FIRM_PATH_LEN];
313326

327+
if (loading_settings) {
328+
return 0;
329+
}
330+
314331
snprintk(path, sizeof(path), SETTINGS_FIRM_INSTANCE_PATH_FMT,
315332
(uint16_t)ENABLED_LWM2M_FIRMWARE_OBJECT, inst);
316333
if (settings_save_one(path, &img_type, sizeof(int))) {

0 commit comments

Comments
 (0)