From eaeb4657670bada712f073571174d9413b58caa1 Mon Sep 17 00:00:00 2001 From: lly Date: Wed, 29 Apr 2020 19:03:19 +0800 Subject: [PATCH] ble_mesh: Fix node not erase info completely Previously only mesh node info is supported to be stored in flash. So when trying to reset the node, we only need to judge if the BLE_MESH_VALID flag is set. Currently we support storing both node & Provisioner info in flash, when trying to erase the node info from flash, the BLE_MESH_NODE flag will be checked. So we need to set bt_mesh.flags to 0 when all the erase operations are done. --- components/bt/esp_ble_mesh/btc/btc_ble_mesh_prov.c | 2 +- components/bt/esp_ble_mesh/mesh_core/cfg_srv.c | 2 +- components/bt/esp_ble_mesh/mesh_core/include/mesh_main.h | 2 +- components/bt/esp_ble_mesh/mesh_core/main.c | 9 ++++++--- components/bt/esp_ble_mesh/mesh_core/settings.c | 5 ++--- 5 files changed, 11 insertions(+), 9 deletions(-) diff --git a/components/bt/esp_ble_mesh/btc/btc_ble_mesh_prov.c b/components/bt/esp_ble_mesh/btc/btc_ble_mesh_prov.c index 62e6cfefdc..f136b615ad 100644 --- a/components/bt/esp_ble_mesh/btc/btc_ble_mesh_prov.c +++ b/components/bt/esp_ble_mesh/btc/btc_ble_mesh_prov.c @@ -1574,7 +1574,7 @@ void btc_ble_mesh_prov_call_handler(btc_msg_t *msg) break; case BTC_BLE_MESH_ACT_NODE_RESET: BT_DBG("%s, BTC_BLE_MESH_ACT_NODE_RESET", __func__); - bt_mesh_reset(); + bt_mesh_node_reset(); return; case BTC_BLE_MESH_ACT_SET_OOB_PUB_KEY: act = ESP_BLE_MESH_NODE_PROV_SET_OOB_PUB_KEY_COMP_EVT; diff --git a/components/bt/esp_ble_mesh/mesh_core/cfg_srv.c b/components/bt/esp_ble_mesh/mesh_core/cfg_srv.c index dbd31dd297..56a906debf 100644 --- a/components/bt/esp_ble_mesh/mesh_core/cfg_srv.c +++ b/components/bt/esp_ble_mesh/mesh_core/cfg_srv.c @@ -2746,7 +2746,7 @@ static void node_reset(struct bt_mesh_model *model, } if (IS_ENABLED(CONFIG_BLE_MESH_NODE)) { - bt_mesh_reset(); + bt_mesh_node_reset(); } } diff --git a/components/bt/esp_ble_mesh/mesh_core/include/mesh_main.h b/components/bt/esp_ble_mesh/mesh_core/include/mesh_main.h index 672d9817c6..362c0bec66 100644 --- a/components/bt/esp_ble_mesh/mesh_core/include/mesh_main.h +++ b/components/bt/esp_ble_mesh/mesh_core/include/mesh_main.h @@ -502,7 +502,7 @@ int bt_mesh_deinit(struct bt_mesh_deinit_param *param); * to enable unprovisioned advertising on one or more provisioning bearers. * */ -void bt_mesh_reset(void); +void bt_mesh_node_reset(void); /** @brief Suspend the Mesh network temporarily. * diff --git a/components/bt/esp_ble_mesh/mesh_core/main.c b/components/bt/esp_ble_mesh/mesh_core/main.c index 5ba76744c2..f293a68d32 100644 --- a/components/bt/esp_ble_mesh/mesh_core/main.c +++ b/components/bt/esp_ble_mesh/mesh_core/main.c @@ -93,9 +93,9 @@ int bt_mesh_provision(const u8_t net_key[16], u16_t net_idx, return 0; } -void bt_mesh_reset(void) +void bt_mesh_node_reset(void) { - if (!bt_mesh_atomic_test_bit(bt_mesh.flags, BLE_MESH_VALID)) { + if (!bt_mesh_is_provisioned()) { BT_WARN("%s, Not provisioned", __func__); return; } @@ -103,7 +103,7 @@ void bt_mesh_reset(void) bt_mesh.iv_index = 0U; bt_mesh.seq = 0U; - memset(bt_mesh.flags, 0, sizeof(bt_mesh.flags)); + bt_mesh_atomic_clear_bit(bt_mesh.flags, BLE_MESH_VALID); k_delayed_work_cancel(&bt_mesh.ivu_timer); @@ -136,9 +136,12 @@ void bt_mesh_reset(void) bt_mesh_comp_unprovision(); if (IS_ENABLED(CONFIG_BLE_MESH_SETTINGS)) { + bt_mesh_clear_seq(); bt_mesh_clear_role(); } + memset(bt_mesh.flags, 0, sizeof(bt_mesh.flags)); + if (IS_ENABLED(CONFIG_BLE_MESH_PROV)) { bt_mesh_prov_reset(); } diff --git a/components/bt/esp_ble_mesh/mesh_core/settings.c b/components/bt/esp_ble_mesh/mesh_core/settings.c index 3dfafffa1f..81ae7ca77d 100644 --- a/components/bt/esp_ble_mesh/mesh_core/settings.c +++ b/components/bt/esp_ble_mesh/mesh_core/settings.c @@ -1438,8 +1438,7 @@ static void schedule_store(int flag) timeout = K_NO_WAIT; } else if (bt_mesh_atomic_test_bit(bt_mesh.flags, BLE_MESH_RPL_PENDING) && (!(bt_mesh_atomic_get(bt_mesh.flags) & GENERIC_PENDING_BITS) || - (CONFIG_BLE_MESH_RPL_STORE_TIMEOUT < - CONFIG_BLE_MESH_STORE_TIMEOUT))) { + (CONFIG_BLE_MESH_RPL_STORE_TIMEOUT < CONFIG_BLE_MESH_STORE_TIMEOUT))) { timeout = K_SECONDS(CONFIG_BLE_MESH_RPL_STORE_TIMEOUT); } else { timeout = K_SECONDS(CONFIG_BLE_MESH_STORE_TIMEOUT); @@ -1451,7 +1450,7 @@ static void schedule_store(int flag) return; } - BT_DBG("Waiting %d seconds", timeout / MSEC_PER_SEC); + BT_INFO("Waiting %d seconds", timeout / MSEC_PER_SEC); if (timeout) { k_delayed_work_submit(&pending_store, timeout);