|
|
@@ -19,6 +19,7 @@
|
|
|
#include "cfg_srv.h"
|
|
|
#include "mesh_common.h"
|
|
|
#include "settings_nvs.h"
|
|
|
+#include "settings.h"
|
|
|
#include "provisioner_main.h"
|
|
|
#include "provisioner_prov.h"
|
|
|
|
|
|
@@ -167,7 +168,29 @@ struct node_info {
|
|
|
u8_t dev_key[16];
|
|
|
} __packed;
|
|
|
|
|
|
-#define DEVICE_ROLE_BITS (BIT(BLE_MESH_NODE) | BIT(BLE_MESH_PROVISIONER))
|
|
|
+static bt_mesh_mutex_t settings_lock;
|
|
|
+
|
|
|
+static void bt_mesh_settings_mutex_new(void)
|
|
|
+{
|
|
|
+ if (settings_lock.mutex == NULL) {
|
|
|
+ bt_mesh_mutex_create(&settings_lock);
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+static void bt_mesh_settings_mutex_free(void)
|
|
|
+{
|
|
|
+ bt_mesh_mutex_free(&settings_lock);
|
|
|
+}
|
|
|
+
|
|
|
+void bt_mesh_settings_lock(void)
|
|
|
+{
|
|
|
+ bt_mesh_mutex_lock(&settings_lock);
|
|
|
+}
|
|
|
+
|
|
|
+void bt_mesh_settings_unlock(void)
|
|
|
+{
|
|
|
+ bt_mesh_mutex_unlock(&settings_lock);
|
|
|
+}
|
|
|
|
|
|
static int role_set(const char *name)
|
|
|
{
|
|
|
@@ -340,13 +363,18 @@ static int rpl_set(const char *name)
|
|
|
|
|
|
for (i = 0; i < length / SETTINGS_ITEM_SIZE; i++) {
|
|
|
u16_t src = net_buf_simple_pull_le16(buf);
|
|
|
+
|
|
|
+ if (!BLE_MESH_ADDR_IS_UNICAST(src)) {
|
|
|
+ BT_ERR("Invalid source address 0x%04x", src);
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+
|
|
|
sprintf(get, "mesh/rpl/%04x", src);
|
|
|
|
|
|
err = bt_mesh_load_core_settings(get, (u8_t *)&rpl, sizeof(rpl), &exist);
|
|
|
if (err) {
|
|
|
BT_ERR("Failed to load RPL entry 0x%04x", src);
|
|
|
- bt_mesh_rpl_reset();
|
|
|
- goto free;
|
|
|
+ continue;
|
|
|
}
|
|
|
|
|
|
if (exist == false) {
|
|
|
@@ -363,10 +391,11 @@ static int rpl_set(const char *name)
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- BT_INFO("Restored RPL entry 0x%04x: seq 0x%06x, old_iv %u", src, rpl.seq, rpl.old_iv);
|
|
|
entry->src = src;
|
|
|
entry->seq = rpl.seq;
|
|
|
entry->old_iv = rpl.old_iv;
|
|
|
+
|
|
|
+ BT_INFO("Restored RPL entry 0x%04x: seq 0x%06x, old_iv %u", src, rpl.seq, rpl.old_iv);
|
|
|
}
|
|
|
|
|
|
free:
|
|
|
@@ -415,7 +444,7 @@ static int net_key_set(const char *name)
|
|
|
err = bt_mesh_load_core_settings(get, (u8_t *)&key, sizeof(key), &exist);
|
|
|
if (err) {
|
|
|
BT_ERR("Failed to load NetKey 0x%03x", net_idx);
|
|
|
- goto free;
|
|
|
+ continue;
|
|
|
}
|
|
|
|
|
|
if (exist == false) {
|
|
|
@@ -475,7 +504,7 @@ static int app_key_set(const char *name)
|
|
|
err = bt_mesh_load_core_settings(get, (u8_t *)&key, sizeof(key), &exist);
|
|
|
if (err) {
|
|
|
BT_ERR("Failed to load AppKey 0x%03x", app_idx);
|
|
|
- goto free;
|
|
|
+ continue;
|
|
|
}
|
|
|
|
|
|
if (exist == false) {
|
|
|
@@ -485,8 +514,7 @@ static int app_key_set(const char *name)
|
|
|
sub = bt_mesh_subnet_get(key.net_idx);
|
|
|
if (!sub) {
|
|
|
BT_ERR("Failed to find subnet 0x%03x", key.net_idx);
|
|
|
- err = -ENOENT;
|
|
|
- goto free;
|
|
|
+ continue;
|
|
|
}
|
|
|
|
|
|
app = bt_mesh_app_key_find(app_idx);
|
|
|
@@ -527,13 +555,13 @@ static int hb_pub_set(const char *name)
|
|
|
BT_DBG("%s", __func__);
|
|
|
|
|
|
if (!hb_pub) {
|
|
|
- BT_ERR("Invalid heartbeat pub");
|
|
|
+ BT_ERR("Invalid heartbeat publication");
|
|
|
return -EINVAL;
|
|
|
}
|
|
|
|
|
|
err = bt_mesh_load_core_settings(name, (u8_t *)&hb_val, sizeof(hb_val), &exist);
|
|
|
if (err) {
|
|
|
- BT_ERR("Failed to load heartbeat pub");
|
|
|
+ BT_ERR("Failed to load heartbeat publication");
|
|
|
hb_pub->dst = BLE_MESH_ADDR_UNASSIGNED;
|
|
|
hb_pub->count = 0U;
|
|
|
hb_pub->ttl = 0U;
|
|
|
@@ -557,7 +585,8 @@ static int hb_pub_set(const char *name)
|
|
|
hb_pub->count = 0U;
|
|
|
}
|
|
|
|
|
|
- BT_INFO("Restored Heartbeat Publication, dst 0x%04x", hb_pub->dst);
|
|
|
+ BT_INFO("Restored Heartbeat Publication, dst 0x%04x, period %d, net_idx 0x%03x",
|
|
|
+ hb_pub->dst, hb_pub->period, hb_pub->net_idx);
|
|
|
|
|
|
return 0;
|
|
|
}
|
|
|
@@ -590,7 +619,10 @@ static int cfg_set(const char *name)
|
|
|
|
|
|
memcpy(&stored_cfg.cfg, &val, sizeof(val));
|
|
|
stored_cfg.valid = true;
|
|
|
- BT_INFO("Restored Configuration State");
|
|
|
+
|
|
|
+ BT_INFO("Restored Configuration, ttl %d, transmit 0x%02x, retransmit 0x%02x",
|
|
|
+ val.default_ttl, val.net_transmit, val.relay_retransmit);
|
|
|
+
|
|
|
return 0;
|
|
|
}
|
|
|
|
|
|
@@ -613,6 +645,10 @@ static int model_set_bind(bool vnd, struct bt_mesh_model *model, u16_t model_key
|
|
|
return -EIO;
|
|
|
}
|
|
|
|
|
|
+ if (exist == true) {
|
|
|
+ BT_INFO("Restored Model Bound AppKey, index %s", bt_hex(model->keys, sizeof(model->keys)));
|
|
|
+ }
|
|
|
+
|
|
|
return 0;
|
|
|
}
|
|
|
|
|
|
@@ -635,6 +671,10 @@ static int model_set_sub(bool vnd, struct bt_mesh_model *model, u16_t model_key)
|
|
|
return -EIO;
|
|
|
}
|
|
|
|
|
|
+ if (exist == true) {
|
|
|
+ BT_INFO("Restored Model Subscription, address %s", bt_hex(model->groups, sizeof(model->groups)));
|
|
|
+ }
|
|
|
+
|
|
|
return 0;
|
|
|
}
|
|
|
|
|
|
@@ -662,7 +702,7 @@ static int model_set_pub(bool vnd, struct bt_mesh_model *model, u16_t model_key)
|
|
|
model->pub->period = 0U;
|
|
|
model->pub->retransmit = 0U;
|
|
|
model->pub->count = 0U;
|
|
|
- return 0;
|
|
|
+ return -EIO;
|
|
|
}
|
|
|
|
|
|
if (exist == false) {
|
|
|
@@ -677,8 +717,7 @@ static int model_set_pub(bool vnd, struct bt_mesh_model *model, u16_t model_key)
|
|
|
model->pub->retransmit = pub.retransmit;
|
|
|
model->pub->count = 0U;
|
|
|
|
|
|
- BT_INFO("Restored Model Publication, address 0x%04x, app_idx 0x%03x",
|
|
|
- pub.addr, pub.key);
|
|
|
+ BT_INFO("Restored Model Publication, address 0x%04x, app_idx 0x%03x", pub.addr, pub.key);
|
|
|
|
|
|
return 0;
|
|
|
}
|
|
|
@@ -689,7 +728,6 @@ static int model_set(bool vnd, const char *name)
|
|
|
struct net_buf_simple *buf = NULL;
|
|
|
u8_t elem_idx = 0U, model_idx = 0U;
|
|
|
size_t length = 0U;
|
|
|
- int err = 0;
|
|
|
int i;
|
|
|
|
|
|
BT_DBG("%s", __func__);
|
|
|
@@ -703,6 +741,7 @@ static int model_set(bool vnd, const char *name)
|
|
|
|
|
|
for (i = 0; i < length / SETTINGS_ITEM_SIZE; i++) {
|
|
|
u16_t model_key = net_buf_simple_pull_le16(buf);
|
|
|
+
|
|
|
elem_idx = BLE_MESH_GET_ELEM_IDX(model_key);
|
|
|
model_idx = BLE_MESH_GET_MODEL_IDX(model_key);
|
|
|
|
|
|
@@ -710,29 +749,16 @@ static int model_set(bool vnd, const char *name)
|
|
|
if (!model) {
|
|
|
BT_ERR("%s model not found, elem_idx %u, model_idx %u",
|
|
|
vnd ? "vnd" : "sig", elem_idx, model_idx);
|
|
|
- err = -ENOENT;
|
|
|
- goto free;
|
|
|
- }
|
|
|
-
|
|
|
- err = model_set_bind(vnd, model, model_key);
|
|
|
- if (err) {
|
|
|
- goto free;
|
|
|
- }
|
|
|
-
|
|
|
- err = model_set_sub(vnd, model, model_key);
|
|
|
- if (err) {
|
|
|
- goto free;
|
|
|
+ continue;
|
|
|
}
|
|
|
|
|
|
- err = model_set_pub(vnd, model, model_key);
|
|
|
- if (err) {
|
|
|
- goto free;
|
|
|
- }
|
|
|
+ model_set_bind(vnd, model, model_key);
|
|
|
+ model_set_sub(vnd, model, model_key);
|
|
|
+ model_set_pub(vnd, model, model_key);
|
|
|
}
|
|
|
|
|
|
-free:
|
|
|
bt_mesh_free_buf(buf);
|
|
|
- return err;
|
|
|
+ return 0;
|
|
|
}
|
|
|
|
|
|
static int sig_mod_set(const char *name)
|
|
|
@@ -773,7 +799,7 @@ static int va_set(const char *name)
|
|
|
err = bt_mesh_load_core_settings(get, (u8_t *)&va, sizeof(va), &exist);
|
|
|
if (err) {
|
|
|
BT_ERR("Failed to load virtual address 0x%04x", index);
|
|
|
- goto free;
|
|
|
+ continue;
|
|
|
}
|
|
|
|
|
|
if (exist == false) {
|
|
|
@@ -782,7 +808,7 @@ static int va_set(const char *name)
|
|
|
|
|
|
if (va.ref == 0) {
|
|
|
BT_DBG("Ignore virtual address %s with ref = 0", get);
|
|
|
- goto free;
|
|
|
+ continue;
|
|
|
}
|
|
|
|
|
|
lab = get_label(index);
|
|
|
@@ -947,7 +973,7 @@ static int p_net_key_set(const char *name)
|
|
|
err = bt_mesh_load_core_settings(get, (u8_t *)&key, sizeof(key), &exist);
|
|
|
if (err) {
|
|
|
BT_ERR("Failed to load NetKey 0x%03x", net_idx);
|
|
|
- goto free;
|
|
|
+ continue;
|
|
|
}
|
|
|
|
|
|
if (exist == false) {
|
|
|
@@ -1007,7 +1033,7 @@ static int p_app_key_set(const char *name)
|
|
|
err = bt_mesh_load_core_settings(get, (u8_t *)&key, sizeof(key), &exist);
|
|
|
if (err) {
|
|
|
BT_ERR("Failed to load AppKey 0x%03x", app_idx);
|
|
|
- goto free;
|
|
|
+ continue;
|
|
|
}
|
|
|
|
|
|
if (exist == false) {
|
|
|
@@ -1017,8 +1043,7 @@ static int p_app_key_set(const char *name)
|
|
|
sub = bt_mesh_provisioner_subnet_get(key.net_idx);
|
|
|
if (!sub) {
|
|
|
BT_ERR("Failed to find subnet 0x%03x", key.net_idx);
|
|
|
- err = -ENOENT;
|
|
|
- goto free;
|
|
|
+ continue;
|
|
|
}
|
|
|
|
|
|
app = bt_mesh_provisioner_app_key_find(app_idx);
|
|
|
@@ -1188,43 +1213,44 @@ const struct bt_mesh_setting {
|
|
|
const char *name;
|
|
|
int (*func)(const char *name);
|
|
|
} settings[] = {
|
|
|
- { "mesh/role", role_set },
|
|
|
- { "mesh/net", net_set },
|
|
|
- { "mesh/iv", iv_set },
|
|
|
- { "mesh/seq", seq_set },
|
|
|
- { "mesh/rpl", rpl_set },
|
|
|
- { "mesh/netkey", net_key_set },
|
|
|
- { "mesh/appkey", app_key_set },
|
|
|
- { "mesh/hb_pub", hb_pub_set },
|
|
|
- { "mesh/cfg", cfg_set },
|
|
|
- { "mesh/sig", sig_mod_set },
|
|
|
- { "mesh/vnd", vnd_mod_set },
|
|
|
+ { "mesh/role", role_set }, /* For Node & Provisioner */
|
|
|
+ { "mesh/net", net_set }, /* For Node */
|
|
|
+ { "mesh/iv", iv_set }, /* For Node & Provisioner */
|
|
|
+ { "mesh/seq", seq_set }, /* For Node & Provisioner */
|
|
|
+ { "mesh/rpl", rpl_set }, /* For Node & Provisioner */
|
|
|
+ { "mesh/netkey", net_key_set }, /* For Node */
|
|
|
+ { "mesh/appkey", app_key_set }, /* For Node */
|
|
|
+ { "mesh/hb_pub", hb_pub_set }, /* For Node */
|
|
|
+ { "mesh/cfg", cfg_set }, /* For Node */
|
|
|
+ { "mesh/sig", sig_mod_set }, /* For Node & Provisioner */
|
|
|
+ { "mesh/vnd", vnd_mod_set }, /* For Node & Provisioner */
|
|
|
#if CONFIG_BLE_MESH_LABEL_COUNT > 0
|
|
|
- { "mesh/vaddr", va_set },
|
|
|
+ { "mesh/vaddr", va_set }, /* For Node */
|
|
|
#endif
|
|
|
#if CONFIG_BLE_MESH_PROVISIONER
|
|
|
- { "mesh/p_prov", p_prov_set },
|
|
|
- { "mesh/p_netidx", p_net_idx_set },
|
|
|
- { "mesh/p_appidx", p_app_idx_set },
|
|
|
- { "mesh/p_netkey", p_net_key_set },
|
|
|
- { "mesh/p_appkey", p_app_key_set },
|
|
|
- { "mesh/p_node", p_node_set },
|
|
|
+ { "mesh/p_prov", p_prov_set }, /* For Provisioner */
|
|
|
+ { "mesh/p_netidx", p_net_idx_set }, /* For Provisioner */
|
|
|
+ { "mesh/p_appidx", p_app_idx_set }, /* For Provisioner */
|
|
|
+ { "mesh/p_netkey", p_net_key_set }, /* For Provisioner */
|
|
|
+ { "mesh/p_appkey", p_app_key_set }, /* For Provisioner */
|
|
|
+ { "mesh/p_node", p_node_set }, /* For Provisioner */
|
|
|
#endif
|
|
|
};
|
|
|
|
|
|
/**
|
|
|
* For Provisioner, the load operation needs the following actions:
|
|
|
+ * role_set: Need, restore the device role
|
|
|
* net_set: Not needed
|
|
|
- * iv_set: Need, although Provisioner will do some initialization of IV Index
|
|
|
- * during startup, but we need to restore the last IV Index status
|
|
|
+ * iv_set: Need, restore the last IV Index status
|
|
|
* seq_set: Need, restore the previous sequence number
|
|
|
* rpl_set: Need, restore the previous Replay Protection List
|
|
|
- * net_key_set: Need, restore the previous network keys
|
|
|
- * app_key_set: Need, restore the previous application keys
|
|
|
+ * net_key_set: Not needed
|
|
|
+ * app_key_set: Not needed
|
|
|
* hb_pub_set: Not needed currently
|
|
|
* cfg_set: Not needed currently
|
|
|
* sig_mod_set: Need, restore SIG models related info (app, sub, pub)
|
|
|
* vnd_mod_set: Need, restore vendor models related info (app, sub, pub)
|
|
|
+ * va_set: Not needed currently
|
|
|
*/
|
|
|
int settings_core_load(void)
|
|
|
{
|
|
|
@@ -1237,7 +1263,8 @@ int settings_core_load(void)
|
|
|
!strcmp(settings[i].name, "mesh/netkey") ||
|
|
|
!strcmp(settings[i].name, "mesh/appkey") ||
|
|
|
!strcmp(settings[i].name, "mesh/hb_pub") ||
|
|
|
- !strcmp(settings[i].name, "mesh/cfg")) &&
|
|
|
+ !strcmp(settings[i].name, "mesh/cfg") ||
|
|
|
+ !strcmp(settings[i].name, "mesh/vaddr")) &&
|
|
|
(!IS_ENABLED(CONFIG_BLE_MESH_NODE) || bt_mesh_is_provisioner())) {
|
|
|
BT_DBG("Not restoring %s for Provisioner", settings[i].name);
|
|
|
continue;
|
|
|
@@ -1257,15 +1284,15 @@ int settings_core_load(void)
|
|
|
settings[i].func(settings[i].name);
|
|
|
|
|
|
if (!strcmp(settings[i].name, "mesh/role")) {
|
|
|
- u8_t role = bt_mesh_atomic_get(bt_mesh.flags) & DEVICE_ROLE_BITS;
|
|
|
+ u8_t role = bt_mesh_atomic_get(bt_mesh.flags) & BLE_MESH_SETTINGS_ROLE_BIT_MASK;
|
|
|
switch (role) {
|
|
|
- case 0U:
|
|
|
+ case BLE_MESH_SETTINGS_ROLE_NONE:
|
|
|
BT_INFO("Mesh device just starts up, no restore");
|
|
|
return 0;
|
|
|
- case BIT(BLE_MESH_NODE):
|
|
|
+ case BLE_MESH_SETTINGS_ROLE_NODE:
|
|
|
BT_INFO("Restored mesh device role: Node");
|
|
|
break;
|
|
|
- case BIT(BLE_MESH_PROVISIONER):
|
|
|
+ case BLE_MESH_SETTINGS_ROLE_PROV:
|
|
|
BT_INFO("Restored mesh device role: Provisioner");
|
|
|
break;
|
|
|
default:
|
|
|
@@ -1330,13 +1357,13 @@ int settings_core_commit(void)
|
|
|
|
|
|
#if defined(CONFIG_BLE_MESH_NODE)
|
|
|
if (bt_mesh_is_node()) {
|
|
|
- BT_INFO("sub[0].net_idx 0x%03x", bt_mesh.sub[0].net_idx);
|
|
|
-
|
|
|
if (bt_mesh.sub[0].net_idx == BLE_MESH_KEY_UNUSED) {
|
|
|
/* Nothing to do since we're not yet provisioned */
|
|
|
return 0;
|
|
|
}
|
|
|
|
|
|
+ BT_INFO("Settings commit, sub[0].net_idx 0x%03x", bt_mesh.sub[0].net_idx);
|
|
|
+
|
|
|
if (IS_ENABLED(CONFIG_BLE_MESH_PB_GATT)) {
|
|
|
bt_mesh_proxy_server_prov_disable(true);
|
|
|
}
|
|
|
@@ -1363,7 +1390,7 @@ int settings_core_commit(void)
|
|
|
return 0;
|
|
|
}
|
|
|
|
|
|
- BT_INFO("p_sub[0]->net_idx 0x%03x", bt_mesh.p_sub[0]->net_idx);
|
|
|
+ BT_INFO("Settings commit, p_sub[0]->net_idx 0x%03x", bt_mesh.p_sub[0]->net_idx);
|
|
|
|
|
|
for (i = 0; i < ARRAY_SIZE(bt_mesh.p_sub); i++) {
|
|
|
sub = bt_mesh.p_sub[i];
|
|
|
@@ -1380,11 +1407,13 @@ int settings_core_commit(void)
|
|
|
}
|
|
|
#endif /* CONFIG_BLE_MESH_PROVISIONER */
|
|
|
|
|
|
- if (bt_mesh.ivu_duration < BLE_MESH_IVU_MIN_HOURS) {
|
|
|
- k_delayed_work_submit(&bt_mesh.ivu_timer, BLE_MESH_IVU_TIMEOUT);
|
|
|
- }
|
|
|
+ if (bt_mesh_is_node() || bt_mesh_is_provisioner()) {
|
|
|
+ if (bt_mesh.ivu_duration < BLE_MESH_IVU_MIN_HOURS) {
|
|
|
+ k_delayed_work_submit(&bt_mesh.ivu_timer, BLE_MESH_IVU_TIMEOUT);
|
|
|
+ }
|
|
|
|
|
|
- bt_mesh_model_foreach(commit_model, NULL);
|
|
|
+ bt_mesh_model_foreach(commit_model, NULL);
|
|
|
+ }
|
|
|
|
|
|
#if defined(CONFIG_BLE_MESH_NODE)
|
|
|
if (bt_mesh_is_node()) {
|
|
|
@@ -1450,7 +1479,7 @@ static void schedule_store(int flag)
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
- BT_INFO("Waiting %d seconds", timeout / MSEC_PER_SEC);
|
|
|
+ BT_INFO("Settings store, waiting %d seconds", timeout / MSEC_PER_SEC);
|
|
|
|
|
|
if (timeout) {
|
|
|
k_delayed_work_submit(&pending_store, timeout);
|
|
|
@@ -1459,16 +1488,10 @@ static void schedule_store(int flag)
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-static void clear_iv(void)
|
|
|
-{
|
|
|
- BT_DBG("Clearing IV");
|
|
|
- bt_mesh_save_core_settings("mesh/iv", NULL, 0);
|
|
|
-}
|
|
|
-
|
|
|
static void clear_net(void)
|
|
|
{
|
|
|
BT_DBG("Clearing Network");
|
|
|
- bt_mesh_save_core_settings("mesh/net", NULL, 0);
|
|
|
+ bt_mesh_erase_core_settings("mesh/net");
|
|
|
}
|
|
|
|
|
|
static void store_pending_net(void)
|
|
|
@@ -1486,7 +1509,7 @@ static void store_pending_net(void)
|
|
|
|
|
|
void bt_mesh_store_role(void)
|
|
|
{
|
|
|
- BT_DBG("Store, device role %lu", bt_mesh_atomic_get(bt_mesh.flags) & DEVICE_ROLE_BITS);
|
|
|
+ BT_DBG("Store, device role %lu", bt_mesh_atomic_get(bt_mesh.flags) & BLE_MESH_SETTINGS_ROLE_BIT_MASK);
|
|
|
|
|
|
bt_mesh_save_core_settings("mesh/role", (const u8_t *)bt_mesh.flags, sizeof(bt_mesh.flags));
|
|
|
}
|
|
|
@@ -1519,7 +1542,8 @@ void bt_mesh_store_iv(bool only_duration)
|
|
|
|
|
|
void bt_mesh_clear_iv(void)
|
|
|
{
|
|
|
- clear_iv();
|
|
|
+ BT_DBG("Clearing IV");
|
|
|
+ bt_mesh_erase_core_settings("mesh/iv");
|
|
|
}
|
|
|
|
|
|
static void store_pending_seq(void)
|
|
|
@@ -1543,7 +1567,8 @@ void bt_mesh_store_seq(void)
|
|
|
|
|
|
void bt_mesh_clear_seq(void)
|
|
|
{
|
|
|
- bt_mesh_save_core_settings("mesh/seq", NULL, 0);
|
|
|
+ BT_DBG("Clearing Seq");
|
|
|
+ bt_mesh_erase_core_settings("mesh/seq");
|
|
|
}
|
|
|
|
|
|
static void store_rpl(struct bt_mesh_rpl *entry)
|
|
|
@@ -1582,11 +1607,9 @@ static void clear_rpl(void)
|
|
|
|
|
|
BT_DBG("%s", __func__);
|
|
|
|
|
|
- bt_mesh_rpl_clear();
|
|
|
-
|
|
|
buf = bt_mesh_get_core_settings_item("mesh/rpl");
|
|
|
if (!buf) {
|
|
|
- bt_mesh_save_core_settings("mesh/rpl", NULL, 0);
|
|
|
+ bt_mesh_erase_core_settings("mesh/rpl");
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
@@ -1594,11 +1617,17 @@ static void clear_rpl(void)
|
|
|
|
|
|
for (i = 0; i < length / SETTINGS_ITEM_SIZE; i++) {
|
|
|
src = net_buf_simple_pull_le16(buf);
|
|
|
+
|
|
|
+ if (!BLE_MESH_ADDR_IS_UNICAST(src)) {
|
|
|
+ BT_ERR("Invalid source address 0x%04x", src);
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+
|
|
|
sprintf(name, "mesh/rpl/%04x", src);
|
|
|
- bt_mesh_save_core_settings(name, NULL, 0);
|
|
|
+ bt_mesh_erase_core_settings(name);
|
|
|
}
|
|
|
|
|
|
- bt_mesh_save_core_settings("mesh/rpl", NULL, 0);
|
|
|
+ bt_mesh_erase_core_settings("mesh/rpl");
|
|
|
|
|
|
bt_mesh_free_buf(buf);
|
|
|
return;
|
|
|
@@ -1626,7 +1655,7 @@ static void store_pending_hb_pub(void)
|
|
|
struct hb_pub_val val = {0};
|
|
|
|
|
|
if (!hb_pub) {
|
|
|
- BT_WARN("NULL heartbeat publication");
|
|
|
+ BT_ERR("Invalid heartbeat publication");
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
@@ -1640,6 +1669,12 @@ static void store_pending_hb_pub(void)
|
|
|
bt_mesh_save_core_settings("mesh/hb_pub", (const u8_t *)&val, sizeof(val));
|
|
|
}
|
|
|
|
|
|
+static void clear_hb_pub(void)
|
|
|
+{
|
|
|
+ BT_DBG("Clear heartbeat publication");
|
|
|
+ bt_mesh_erase_core_settings("mesh/hb_pub");
|
|
|
+}
|
|
|
+
|
|
|
static void store_pending_cfg(void)
|
|
|
{
|
|
|
struct bt_mesh_cfg_srv *cfg = bt_mesh_cfg_get();
|
|
|
@@ -1664,7 +1699,7 @@ static void store_pending_cfg(void)
|
|
|
static void clear_cfg(void)
|
|
|
{
|
|
|
BT_DBG("Clearing configuration");
|
|
|
- bt_mesh_save_core_settings("mesh/cfg", NULL, 0);
|
|
|
+ bt_mesh_erase_core_settings("mesh/cfg");
|
|
|
}
|
|
|
|
|
|
static void clear_app_key(u16_t app_idx)
|
|
|
@@ -1675,7 +1710,7 @@ static void clear_app_key(u16_t app_idx)
|
|
|
BT_DBG("AppKeyIndex 0x%03x", app_idx);
|
|
|
|
|
|
sprintf(name, "mesh/ak/%04x", app_idx);
|
|
|
- bt_mesh_save_core_settings(name, NULL, 0);
|
|
|
+ bt_mesh_erase_core_settings(name);
|
|
|
|
|
|
err = bt_mesh_remove_core_settings_item("mesh/appkey", app_idx);
|
|
|
if (err) {
|
|
|
@@ -1693,7 +1728,7 @@ static void clear_net_key(u16_t net_idx)
|
|
|
BT_DBG("NetKeyIndex 0x%03x", net_idx);
|
|
|
|
|
|
sprintf(name, "mesh/nk/%04x", net_idx);
|
|
|
- bt_mesh_save_core_settings(name, NULL, 0);
|
|
|
+ bt_mesh_erase_core_settings(name);
|
|
|
|
|
|
err = bt_mesh_remove_core_settings_item("mesh/netkey", net_idx);
|
|
|
if (err) {
|
|
|
@@ -1806,15 +1841,8 @@ static void store_pending_mod_bind(struct bt_mesh_model *model, bool vnd)
|
|
|
int err = 0;
|
|
|
|
|
|
model_key = BLE_MESH_GET_MODEL_KEY(model->elem_idx, model->model_idx);
|
|
|
-
|
|
|
sprintf(name, "mesh/%s/%04x/b", vnd ? "v" : "s", model_key);
|
|
|
|
|
|
- if (IS_ENABLED(CONFIG_BLE_MESH_NODE) && bt_mesh_is_node() &&
|
|
|
- !bt_mesh_is_provisioned()) {
|
|
|
- bt_mesh_save_core_settings(name, NULL, 0);
|
|
|
- return;
|
|
|
- }
|
|
|
-
|
|
|
err = bt_mesh_save_core_settings(name, (const u8_t *)model->keys, sizeof(model->keys));
|
|
|
if (err) {
|
|
|
BT_ERR("Failed to store %s", name);
|
|
|
@@ -1837,15 +1865,8 @@ static void store_pending_mod_sub(struct bt_mesh_model *model, bool vnd)
|
|
|
int err = 0;
|
|
|
|
|
|
model_key = BLE_MESH_GET_MODEL_KEY(model->elem_idx, model->model_idx);
|
|
|
-
|
|
|
sprintf(name, "mesh/%s/%04x/s", vnd ? "v" : "s", model_key);
|
|
|
|
|
|
- if (IS_ENABLED(CONFIG_BLE_MESH_NODE) && bt_mesh_is_node() &&
|
|
|
- !bt_mesh_is_provisioned()) {
|
|
|
- bt_mesh_save_core_settings(name, NULL, 0);
|
|
|
- return;
|
|
|
- }
|
|
|
-
|
|
|
err = bt_mesh_save_core_settings(name, (const u8_t *)model->groups, sizeof(model->groups));
|
|
|
if (err) {
|
|
|
BT_ERR("Failed to store %s", name);
|
|
|
@@ -1873,6 +1894,9 @@ static void store_pending_mod_pub(struct bt_mesh_model *model, bool vnd)
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
+ model_key = BLE_MESH_GET_MODEL_KEY(model->elem_idx, model->model_idx);
|
|
|
+ sprintf(name, "mesh/%s/%04x/p", vnd ? "v" : "s", model_key);
|
|
|
+
|
|
|
pub.addr = model->pub->addr;
|
|
|
pub.key = model->pub->key;
|
|
|
pub.ttl = model->pub->ttl;
|
|
|
@@ -1881,16 +1905,6 @@ static void store_pending_mod_pub(struct bt_mesh_model *model, bool vnd)
|
|
|
pub.period_div = model->pub->period_div;
|
|
|
pub.cred = model->pub->cred;
|
|
|
|
|
|
- model_key = BLE_MESH_GET_MODEL_KEY(model->elem_idx, model->model_idx);
|
|
|
-
|
|
|
- sprintf(name, "mesh/%s/%04x/p", vnd ? "v" : "s", model_key);
|
|
|
-
|
|
|
- if (IS_ENABLED(CONFIG_BLE_MESH_NODE) && bt_mesh_is_node() &&
|
|
|
- !bt_mesh_is_provisioned()) {
|
|
|
- bt_mesh_save_core_settings(name, NULL, 0);
|
|
|
- return;
|
|
|
- }
|
|
|
-
|
|
|
err = bt_mesh_save_core_settings(name, (const u8_t *)&pub, sizeof(pub));
|
|
|
if (err) {
|
|
|
BT_ERR("Failed to store %s", name);
|
|
|
@@ -1930,6 +1944,66 @@ static void store_pending_mod(struct bt_mesh_model *model,
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+static void clear_mod_bind(struct bt_mesh_model *model, bool vnd)
|
|
|
+{
|
|
|
+ char name[16] = {'\0'};
|
|
|
+ u16_t model_key = 0U;
|
|
|
+
|
|
|
+ model_key = BLE_MESH_GET_MODEL_KEY(model->elem_idx, model->model_idx);
|
|
|
+ sprintf(name, "mesh/%s/%04x/b", vnd ? "v" : "s", model_key);
|
|
|
+
|
|
|
+ bt_mesh_erase_core_settings(name);
|
|
|
+ bt_mesh_remove_core_settings_item(vnd ? "mesh/vnd" : "mesh/sig", model_key);
|
|
|
+}
|
|
|
+
|
|
|
+static void clear_mod_sub(struct bt_mesh_model *model, bool vnd)
|
|
|
+{
|
|
|
+ char name[16] = {'\0'};
|
|
|
+ u16_t model_key = 0U;
|
|
|
+
|
|
|
+ model_key = BLE_MESH_GET_MODEL_KEY(model->elem_idx, model->model_idx);
|
|
|
+ sprintf(name, "mesh/%s/%04x/s", vnd ? "v" : "s", model_key);
|
|
|
+
|
|
|
+ bt_mesh_erase_core_settings(name);
|
|
|
+ bt_mesh_remove_core_settings_item(vnd ? "mesh/vnd" : "mesh/sig", model_key);
|
|
|
+}
|
|
|
+
|
|
|
+static void clear_mod_pub(struct bt_mesh_model *model, bool vnd)
|
|
|
+{
|
|
|
+ char name[16] = {'\0'};
|
|
|
+ u16_t model_key = 0U;
|
|
|
+
|
|
|
+ model_key = BLE_MESH_GET_MODEL_KEY(model->elem_idx, model->model_idx);
|
|
|
+ sprintf(name, "mesh/%s/%04x/p", vnd ? "v" : "s", model_key);
|
|
|
+
|
|
|
+ bt_mesh_erase_core_settings(name);
|
|
|
+ bt_mesh_remove_core_settings_item(vnd ? "mesh/vnd" : "mesh/sig", model_key);
|
|
|
+}
|
|
|
+
|
|
|
+static void clear_pending_mod(struct bt_mesh_model *model,
|
|
|
+ struct bt_mesh_elem *elem, bool vnd,
|
|
|
+ bool primary, void *user_data)
|
|
|
+{
|
|
|
+ if (!model->flags) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ if (model->flags & BLE_MESH_MOD_BIND_PENDING) {
|
|
|
+ model->flags &= ~BLE_MESH_MOD_BIND_PENDING;
|
|
|
+ clear_mod_bind(model, vnd);
|
|
|
+ }
|
|
|
+
|
|
|
+ if (model->flags & BLE_MESH_MOD_SUB_PENDING) {
|
|
|
+ model->flags &= ~BLE_MESH_MOD_SUB_PENDING;
|
|
|
+ clear_mod_sub(model, vnd);
|
|
|
+ }
|
|
|
+
|
|
|
+ if (model->flags & BLE_MESH_MOD_PUB_PENDING) {
|
|
|
+ model->flags &= ~BLE_MESH_MOD_PUB_PENDING;
|
|
|
+ clear_mod_pub(model, vnd);
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
#define IS_VA_DEL(_label) ((_label)->ref == 0)
|
|
|
static void store_pending_va(void)
|
|
|
{
|
|
|
@@ -1948,7 +2022,7 @@ static void store_pending_va(void)
|
|
|
sprintf(name, "mesh/va/%04x", i);
|
|
|
|
|
|
if (IS_VA_DEL(lab)) {
|
|
|
- err = bt_mesh_save_core_settings(name, NULL, 0);
|
|
|
+ err = bt_mesh_erase_core_settings(name);
|
|
|
} else {
|
|
|
va.ref = lab->ref;
|
|
|
va.addr = lab->addr;
|
|
|
@@ -1981,7 +2055,7 @@ static void store_pending(struct k_work *work)
|
|
|
BT_DBG("%s", __func__);
|
|
|
|
|
|
if (bt_mesh_atomic_test_and_clear_bit(bt_mesh.flags, BLE_MESH_RPL_PENDING)) {
|
|
|
- if (!IS_ENABLED(CONFIG_BLE_MESH_NODE) || bt_mesh_is_provisioned()) {
|
|
|
+ if (bt_mesh_is_provisioned() || bt_mesh_is_provisioner_en()) {
|
|
|
store_pending_rpl();
|
|
|
} else {
|
|
|
clear_rpl();
|
|
|
@@ -2003,20 +2077,28 @@ static void store_pending(struct k_work *work)
|
|
|
}
|
|
|
|
|
|
if (bt_mesh_atomic_test_and_clear_bit(bt_mesh.flags, BLE_MESH_IV_PENDING)) {
|
|
|
- if (!IS_ENABLED(CONFIG_BLE_MESH_NODE) || bt_mesh_is_provisioned()) {
|
|
|
+ if (bt_mesh_is_provisioned() || bt_mesh_is_provisioner_en()) {
|
|
|
store_pending_iv();
|
|
|
} else {
|
|
|
- clear_iv();
|
|
|
+ bt_mesh_clear_iv();
|
|
|
}
|
|
|
}
|
|
|
|
|
|
if (bt_mesh_atomic_test_and_clear_bit(bt_mesh.flags, BLE_MESH_SEQ_PENDING)) {
|
|
|
- store_pending_seq();
|
|
|
+ if (bt_mesh_is_provisioned() || bt_mesh_is_provisioner_en()) {
|
|
|
+ store_pending_seq();
|
|
|
+ } else {
|
|
|
+ bt_mesh_clear_seq();
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
if (IS_ENABLED(CONFIG_BLE_MESH_NODE) && bt_mesh_is_node() &&
|
|
|
bt_mesh_atomic_test_and_clear_bit(bt_mesh.flags, BLE_MESH_HB_PUB_PENDING)) {
|
|
|
- store_pending_hb_pub();
|
|
|
+ if (bt_mesh_is_provisioned()) {
|
|
|
+ store_pending_hb_pub();
|
|
|
+ } else {
|
|
|
+ clear_hb_pub();
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
if (IS_ENABLED(CONFIG_BLE_MESH_NODE) && bt_mesh_is_node() &&
|
|
|
@@ -2029,15 +2111,17 @@ static void store_pending(struct k_work *work)
|
|
|
}
|
|
|
|
|
|
if (bt_mesh_atomic_test_and_clear_bit(bt_mesh.flags, BLE_MESH_MOD_PENDING)) {
|
|
|
- bt_mesh_model_foreach(store_pending_mod, NULL);
|
|
|
- if (IS_ENABLED(CONFIG_BLE_MESH_NODE) && bt_mesh_is_node() &&
|
|
|
- !bt_mesh_is_provisioned()) {
|
|
|
- bt_mesh_save_core_settings("mesh/sig", NULL, 0);
|
|
|
- bt_mesh_save_core_settings("mesh/vnd", NULL, 0);
|
|
|
+ if (bt_mesh_is_provisioned() || bt_mesh_is_provisioner_en()) {
|
|
|
+ bt_mesh_model_foreach(store_pending_mod, NULL);
|
|
|
+ } else {
|
|
|
+ bt_mesh_model_foreach(clear_pending_mod, NULL);
|
|
|
+ bt_mesh_erase_core_settings("mesh/sig");
|
|
|
+ bt_mesh_erase_core_settings("mesh/vnd");
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- if (bt_mesh_atomic_test_and_clear_bit(bt_mesh.flags, BLE_MESH_VA_PENDING)) {
|
|
|
+ if (IS_ENABLED(CONFIG_BLE_MESH_NODE) && bt_mesh_is_node() &&
|
|
|
+ bt_mesh_atomic_test_and_clear_bit(bt_mesh.flags, BLE_MESH_VA_PENDING)) {
|
|
|
store_pending_va();
|
|
|
}
|
|
|
}
|
|
|
@@ -2143,7 +2227,7 @@ void bt_mesh_store_cfg(void)
|
|
|
void bt_mesh_clear_role(void)
|
|
|
{
|
|
|
BT_DBG("Clear device role");
|
|
|
- bt_mesh_save_core_settings("mesh/role", NULL, 0);
|
|
|
+ bt_mesh_erase_core_settings("mesh/role");
|
|
|
}
|
|
|
|
|
|
void bt_mesh_clear_net(void)
|
|
|
@@ -2263,35 +2347,8 @@ void bt_mesh_store_prov_info(u16_t primary_addr, u16_t alloc_addr)
|
|
|
|
|
|
void bt_mesh_clear_prov_info(void)
|
|
|
{
|
|
|
- bt_mesh_save_core_settings("mesh/p_prov", NULL, 0);
|
|
|
-}
|
|
|
-
|
|
|
-static void clear_p_net_key(u16_t net_idx)
|
|
|
-{
|
|
|
- char name[16] = {'\0'};
|
|
|
- int err = 0;
|
|
|
-
|
|
|
- sprintf(name, "mesh/pnk/%04x", net_idx);
|
|
|
- bt_mesh_save_core_settings(name, NULL, 0);
|
|
|
-
|
|
|
- err = bt_mesh_remove_core_settings_item("mesh/p_netkey", net_idx);
|
|
|
- if (err) {
|
|
|
- BT_ERR("Failed to remove 0x%03x from mesh/p_netkey", net_idx);
|
|
|
- }
|
|
|
-}
|
|
|
-
|
|
|
-static void clear_p_app_key(u16_t app_idx)
|
|
|
-{
|
|
|
- char name[16] = {'\0'};
|
|
|
- int err = 0;
|
|
|
-
|
|
|
- sprintf(name, "mesh/pak/%04x", app_idx);
|
|
|
- bt_mesh_save_core_settings(name, NULL, 0);
|
|
|
-
|
|
|
- err = bt_mesh_remove_core_settings_item("mesh/p_appkey", app_idx);
|
|
|
- if (err) {
|
|
|
- BT_ERR("Failed to remove 0x%03x from mesh/p_appkey", app_idx);
|
|
|
- }
|
|
|
+ BT_DBG("Clearing prov info");
|
|
|
+ bt_mesh_erase_core_settings("mesh/p_prov");
|
|
|
}
|
|
|
|
|
|
static void store_p_net_key(struct bt_mesh_subnet *sub)
|
|
|
@@ -2344,7 +2401,7 @@ static void store_p_app_key(struct bt_mesh_app_key *app)
|
|
|
|
|
|
void bt_mesh_store_p_net_idx(void)
|
|
|
{
|
|
|
- BT_DBG("p_net_idx_next 0x%03x", bt_mesh.p_net_idx_next);
|
|
|
+ BT_DBG("Store, p_net_idx_next 0x%03x", bt_mesh.p_net_idx_next);
|
|
|
|
|
|
bt_mesh_save_core_settings("mesh/p_netidx",
|
|
|
(const u8_t *)&bt_mesh.p_net_idx_next, sizeof(bt_mesh.p_net_idx_next));
|
|
|
@@ -2352,12 +2409,13 @@ void bt_mesh_store_p_net_idx(void)
|
|
|
|
|
|
void bt_mesh_clear_p_net_idx(void)
|
|
|
{
|
|
|
- bt_mesh_save_core_settings("mesh/p_netidx", NULL, 0);
|
|
|
+ BT_DBG("Clearing NetKey Index");
|
|
|
+ bt_mesh_erase_core_settings("mesh/p_netidx");
|
|
|
}
|
|
|
|
|
|
void bt_mesh_store_p_app_idx(void)
|
|
|
{
|
|
|
- BT_DBG("p_app_idx_next 0x%03x", bt_mesh.p_app_idx_next);
|
|
|
+ BT_DBG("Store, p_app_idx_next 0x%03x", bt_mesh.p_app_idx_next);
|
|
|
|
|
|
bt_mesh_save_core_settings("mesh/p_appidx",
|
|
|
(const u8_t *)&bt_mesh.p_app_idx_next, sizeof(bt_mesh.p_app_idx_next));
|
|
|
@@ -2365,7 +2423,8 @@ void bt_mesh_store_p_app_idx(void)
|
|
|
|
|
|
void bt_mesh_clear_p_app_idx(void)
|
|
|
{
|
|
|
- bt_mesh_save_core_settings("mesh/p_appidx", NULL, 0);
|
|
|
+ BT_DBG("Clearing AppKey Index");
|
|
|
+ bt_mesh_erase_core_settings("mesh/p_appidx");
|
|
|
}
|
|
|
|
|
|
void bt_mesh_store_p_subnet(struct bt_mesh_subnet *sub)
|
|
|
@@ -2394,28 +2453,36 @@ void bt_mesh_store_p_app_key(struct bt_mesh_app_key *key)
|
|
|
store_p_app_key(key);
|
|
|
}
|
|
|
|
|
|
-void bt_mesh_clear_p_subnet(struct bt_mesh_subnet *sub)
|
|
|
+void bt_mesh_clear_p_subnet(u16_t net_idx)
|
|
|
{
|
|
|
- if (sub == NULL) {
|
|
|
- BT_ERR("Invalid subnet");
|
|
|
- return;
|
|
|
- }
|
|
|
+ char name[16] = {'\0'};
|
|
|
+ int err = 0;
|
|
|
|
|
|
- BT_DBG("NetKeyIndex 0x%03x", sub->net_idx);
|
|
|
+ BT_DBG("NetKeyIndex 0x%03x", net_idx);
|
|
|
|
|
|
- clear_p_net_key(sub->net_idx);
|
|
|
+ sprintf(name, "mesh/pnk/%04x", net_idx);
|
|
|
+ bt_mesh_erase_core_settings(name);
|
|
|
+
|
|
|
+ err = bt_mesh_remove_core_settings_item("mesh/p_netkey", net_idx);
|
|
|
+ if (err) {
|
|
|
+ BT_ERR("Failed to remove 0x%04x from mesh/p_netkey", net_idx);
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
-void bt_mesh_clear_p_app_key(struct bt_mesh_app_key *key)
|
|
|
+void bt_mesh_clear_p_app_key(u16_t app_idx)
|
|
|
{
|
|
|
- if (key == NULL) {
|
|
|
- BT_ERR("Invalid AppKey");
|
|
|
- return;
|
|
|
- }
|
|
|
+ char name[16] = {'\0'};
|
|
|
+ int err = 0;
|
|
|
|
|
|
- BT_DBG("AppKeyIndex 0x%03x", key->app_idx);
|
|
|
+ BT_DBG("AppKeyIndex 0x%03x", app_idx);
|
|
|
+
|
|
|
+ sprintf(name, "mesh/pak/%04x", app_idx);
|
|
|
+ bt_mesh_erase_core_settings(name);
|
|
|
|
|
|
- clear_p_app_key(key->app_idx);
|
|
|
+ err = bt_mesh_remove_core_settings_item("mesh/p_appkey", app_idx);
|
|
|
+ if (err) {
|
|
|
+ BT_ERR("Failed to remove 0x%04x from mesh/p_appkey", app_idx);
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
void bt_mesh_clear_rpl_single(u16_t src)
|
|
|
@@ -2429,7 +2496,7 @@ void bt_mesh_clear_rpl_single(u16_t src)
|
|
|
}
|
|
|
|
|
|
sprintf(name, "mesh/rpl/%04x", src);
|
|
|
- bt_mesh_save_core_settings(name, NULL, 0);
|
|
|
+ bt_mesh_erase_core_settings(name);
|
|
|
|
|
|
err = bt_mesh_remove_core_settings_item("mesh/rpl", src);
|
|
|
if (err) {
|
|
|
@@ -2479,15 +2546,15 @@ static void clear_node(u16_t addr)
|
|
|
|
|
|
/* Clear node information */
|
|
|
sprintf(name, "mesh/pn/%04x/i", addr);
|
|
|
- bt_mesh_save_core_settings(name, NULL, 0);
|
|
|
+ bt_mesh_erase_core_settings(name);
|
|
|
|
|
|
/* Clear node name */
|
|
|
sprintf(name, "mesh/pn/%04x/n", addr);
|
|
|
- bt_mesh_save_core_settings(name, NULL, 0);
|
|
|
+ bt_mesh_erase_core_settings(name);
|
|
|
|
|
|
/* Clear node composition data */
|
|
|
sprintf(name, "mesh/pn/%04x/c", addr);
|
|
|
- bt_mesh_save_core_settings(name, NULL, 0);
|
|
|
+ bt_mesh_erase_core_settings(name);
|
|
|
|
|
|
err = bt_mesh_remove_core_settings_item("mesh/p_node", addr);
|
|
|
if (err) {
|
|
|
@@ -2547,33 +2614,34 @@ void bt_mesh_store_node_comp_data(struct bt_mesh_node *node)
|
|
|
|
|
|
int settings_core_init(void)
|
|
|
{
|
|
|
- BT_DBG("%s", __func__);
|
|
|
-
|
|
|
k_delayed_work_init(&pending_store, store_pending);
|
|
|
-
|
|
|
return 0;
|
|
|
}
|
|
|
|
|
|
-int bt_mesh_settings_init(void)
|
|
|
+int settings_core_deinit(void)
|
|
|
{
|
|
|
- BT_DBG("%s", __func__);
|
|
|
-
|
|
|
- bt_mesh_settings_foreach();
|
|
|
-
|
|
|
+ k_delayed_work_free(&pending_store);
|
|
|
return 0;
|
|
|
}
|
|
|
|
|
|
-int settings_core_deinit(void)
|
|
|
+int settings_core_erase(void)
|
|
|
{
|
|
|
- k_delayed_work_free(&pending_store);
|
|
|
-
|
|
|
+ /* Erase here must not use the pending_store timer. */
|
|
|
+ bt_mesh_clear_role();
|
|
|
return 0;
|
|
|
}
|
|
|
|
|
|
-int bt_mesh_settings_deinit(void)
|
|
|
+int bt_mesh_settings_init(void)
|
|
|
{
|
|
|
- bt_mesh_settings_deforeach();
|
|
|
+ bt_mesh_settings_mutex_new();
|
|
|
+ bt_mesh_settings_init_foreach();
|
|
|
+ return 0;
|
|
|
+}
|
|
|
|
|
|
+int bt_mesh_settings_deinit(bool erase)
|
|
|
+{
|
|
|
+ bt_mesh_settings_deinit_foreach(erase);
|
|
|
+ bt_mesh_settings_mutex_free();
|
|
|
return 0;
|
|
|
}
|
|
|
|