ble_mesh: stack: Use settings_core_erase when deinit

This commit is contained in:
lly 2020-05-29 10:06:34 +08:00
parent 3940ab80a3
commit b4c3c87c75
5 changed files with 47 additions and 39 deletions

View File

@ -522,10 +522,7 @@ int bt_mesh_deinit(struct bt_mesh_deinit_param *param)
bt_mesh_comp_unprovision();
if (IS_ENABLED(CONFIG_BLE_MESH_SETTINGS)) {
if (param->erase) {
bt_mesh_clear_role();
}
bt_mesh_settings_deinit();
bt_mesh_settings_deinit(param->erase);
}
bt_mesh_timer_deinit();

View File

@ -585,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;
}
@ -618,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;
}
@ -641,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;
}
@ -663,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;
}
@ -1467,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);
@ -2602,35 +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)
{
BT_DBG("%s", __func__);
bt_mesh_settings_mutex_new();
bt_mesh_settings_init_foreach();
return 0;
}
int settings_core_deinit(void)
{
k_delayed_work_free(&pending_store);
return 0;
}
int bt_mesh_settings_deinit(void)
int settings_core_erase(void)
{
bt_mesh_settings_deinit_foreach();
bt_mesh_settings_mutex_free();
/* Erase here must not use the pending_store timer. */
bt_mesh_clear_role();
return 0;
}
int bt_mesh_settings_init(void)
{
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;
}

View File

@ -19,11 +19,6 @@ extern "C" {
#define BLE_MESH_SETTINGS_ROLE_PROV (BIT(BLE_MESH_PROVISIONER))
#define BLE_MESH_SETTINGS_ROLE_BIT_MASK (BIT(BLE_MESH_NODE) | BIT(BLE_MESH_PROVISIONER))
int settings_core_init(void);
int settings_core_load(void);
int settings_core_commit(void);
int settings_core_deinit(void);
void bt_mesh_store_role(void);
void bt_mesh_store_net(void);
void bt_mesh_store_iv(bool only_duration);
@ -67,8 +62,14 @@ void bt_mesh_store_node_comp_data(struct bt_mesh_node *node);
void bt_mesh_settings_lock(void);
void bt_mesh_settings_unlock(void);
int settings_core_init(void);
int settings_core_load(void);
int settings_core_commit(void);
int settings_core_deinit(void);
int settings_core_erase(void);
int bt_mesh_settings_init(void);
int bt_mesh_settings_deinit(void);
int bt_mesh_settings_deinit(bool erase);
#ifdef __cplusplus
}

View File

@ -23,7 +23,6 @@
enum settings_type {
SETTINGS_CORE,
SETTINGS_SERVER,
};
struct settings_context {
@ -44,12 +43,7 @@ static struct settings_context settings_ctx[] = {
.settings_load = settings_core_load,
.settings_commit = settings_core_commit,
.settings_deinit = settings_core_deinit,
},
[SETTINGS_SERVER] = {
.nvs_name = "mesh_server",
.settings_init = NULL,
.settings_load = NULL,
.settings_commit = NULL,
.settings_erase = settings_core_erase,
},
};
@ -98,7 +92,7 @@ void bt_mesh_settings_init_foreach(void)
}
}
void bt_mesh_settings_deinit_foreach(void)
void bt_mesh_settings_deinit_foreach(bool erase)
{
int i;
@ -110,6 +104,11 @@ void bt_mesh_settings_deinit_foreach(void)
continue;
}
if (erase && ctx->settings_erase && ctx->settings_erase()) {
BT_ERR("Erase settings failed, name %s", ctx->nvs_name);
continue;
}
nvs_close(ctx->handle);
}

View File

@ -31,7 +31,7 @@ typedef nvs_handle bt_mesh_nvs_handle_t;
#define BLE_MESH_GET_MODEL_KEY(a, b) ((u16_t)(((u16_t)((a) << 8)) | (b)))
void bt_mesh_settings_init_foreach(void);
void bt_mesh_settings_deinit_foreach(void);
void bt_mesh_settings_deinit_foreach(bool erase);
int bt_mesh_save_settings(bt_mesh_nvs_handle_t handle, const char *key,
const u8_t *val, size_t len);