Skip to content

Commit 23b57b3

Browse files
lmaciejonczykrlubos
authored andcommitted
[nrf fromtree] net: openthread: align otPlatSettingsSet with new interface contract
The new interface contract guarantees that OpenThread stack uses otPlatSettingsSet only for aKey which has at most one value at time. This implies the simplification for key name used by settings subsystem and decreases the count of records written each time when the value for specific key is updated. In result non-volatile memory can be used more efficiently. It relates to zephyrproject-rtos/openthread commit: ed665e9 . We still need to make sure that old entries are being removed for the case with DFU. Signed-off-by: Lukasz Maciejonczyk <[email protected]> (cherry picked from commit 80eca5f)
1 parent b3bb546 commit 23b57b3

File tree

1 file changed

+14
-7
lines changed

1 file changed

+14
-7
lines changed

subsys/net/lib/openthread/platform/settings.c

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,9 @@ struct ot_setting_delete_ctx {
3030

3131
/* Operation result. */
3232
int status;
33+
34+
/* Indicates if delete subtree root. */
35+
bool delete_subtree_root;
3336
};
3437

3538
static int ot_setting_delete_cb(const char *key, size_t len,
@@ -50,6 +53,10 @@ static int ot_setting_delete_cb(const char *key, size_t len,
5053
return 0;
5154
}
5255

56+
if (key == NULL && ctx->delete_subtree_root == false) {
57+
return 0;
58+
}
59+
5360
ret = snprintk(path, sizeof(path), "%s%s%s", ctx->subtree,
5461
key ? "/" : "", key ? key : "");
5562
__ASSERT(ret < sizeof(path), "Setting path buffer too small.");
@@ -75,14 +82,15 @@ static int ot_setting_delete_cb(const char *key, size_t len,
7582
return 0;
7683
}
7784

78-
static int ot_setting_delete_subtree(int key, int index)
85+
static int ot_setting_delete_subtree(int key, int index, bool delete_subtree_root)
7986
{
8087
int ret;
8188
char subtree[OT_SETTINGS_MAX_PATH_LEN];
8289
struct ot_setting_delete_ctx delete_ctx = {
8390
.subtree = subtree,
8491
.status = -ENOENT,
85-
.target_index = index
92+
.target_index = index,
93+
.delete_subtree_root = delete_subtree_root,
8694
};
8795

8896
if (key == -1) {
@@ -252,10 +260,9 @@ otError otPlatSettingsSet(otInstance *aInstance, uint16_t aKey,
252260

253261
LOG_DBG("%s Entry aKey %u", __func__, aKey);
254262

255-
(void)ot_setting_delete_subtree(aKey, -1);
263+
(void)ot_setting_delete_subtree(aKey, -1, false);
256264

257-
ret = snprintk(path, sizeof(path), "%s/%x/%08x", OT_SETTINGS_ROOT_KEY,
258-
aKey, sys_rand32_get());
265+
ret = snprintk(path, sizeof(path), "%s/%x", OT_SETTINGS_ROOT_KEY, aKey);
259266
__ASSERT(ret < sizeof(path), "Setting path buffer too small.");
260267

261268
ret = settings_save_one(path, aValue, aValueLength);
@@ -300,7 +307,7 @@ otError otPlatSettingsDelete(otInstance *aInstance, uint16_t aKey, int aIndex)
300307

301308
LOG_DBG("%s Entry aKey %u aIndex %d", __func__, aKey, aIndex);
302309

303-
ret = ot_setting_delete_subtree(aKey, aIndex);
310+
ret = ot_setting_delete_subtree(aKey, aIndex, true);
304311
if (ret != 0) {
305312
LOG_DBG("Entry not found aKey %u aIndex %d", aKey, aIndex);
306313
return OT_ERROR_NOT_FOUND;
@@ -313,7 +320,7 @@ void otPlatSettingsWipe(otInstance *aInstance)
313320
{
314321
ARG_UNUSED(aInstance);
315322

316-
(void)ot_setting_delete_subtree(-1, -1);
323+
(void)ot_setting_delete_subtree(-1, -1, true);
317324
}
318325

319326
void otPlatSettingsDeinit(otInstance *aInstance)

0 commit comments

Comments
 (0)