From e9f64eb1c3b600c5075a2296783513b89d3853aa Mon Sep 17 00:00:00 2001 From: lly Date: Sat, 4 Apr 2020 16:45:40 +0800 Subject: [PATCH] ble_mesh: Fix mesh node device role restore Old version of BLE Mesh has no device role storage, because previously we only support storing mesh node info. If the binary of the node is upgraded from old version to a new version (support storing provisioner info), the mesh info of the node will not be restored because mesh role does not exist in the flash. --- components/bt/esp_ble_mesh/Kconfig.in | 23 +++++++++++++++++++ .../bt/esp_ble_mesh/mesh_core/settings.c | 7 ++++++ 2 files changed, 30 insertions(+) diff --git a/components/bt/esp_ble_mesh/Kconfig.in b/components/bt/esp_ble_mesh/Kconfig.in index 0ca4b6be8..999aaa279 100644 --- a/components/bt/esp_ble_mesh/Kconfig.in +++ b/components/bt/esp_ble_mesh/Kconfig.in @@ -285,6 +285,29 @@ if BLE_MESH introduce message replay attacks and system security will be in a vulnerable state. + config BLE_MESH_SETTINGS_BACKWARD_COMPATIBILITY + bool "A specific option for settings backward compatibility" + depends on BLE_MESH_NODE + default n + help + This option is created to solve the issue of failure in recovering + node information after mesh stack updates. In the old version mesh + stack, there is no key of "mesh/role" in nvs. In the new version + mesh stack, key of "mesh/role" is added in nvs, recovering node + information needs to check "mesh/role" key in nvs and implements + selective recovery of mesh node information. Therefore, there may + be failure in recovering node information during node restarting + after OTA. + + The new version mesh stack adds the option of "mesh/role" because + we have added the support of storing Provisioner information, while + the old version only supports storing node information. + + If users are updating their nodes from old version to new version, + we recommend enabling this option, so that system could set the flag + in advance before recovering node information and make sure the node + information recovering could work as expected. + endif # if BLE_MESH_SETTINGS config BLE_MESH_SUBNET_COUNT diff --git a/components/bt/esp_ble_mesh/mesh_core/settings.c b/components/bt/esp_ble_mesh/mesh_core/settings.c index a7f564024..dfdac940a 100644 --- a/components/bt/esp_ble_mesh/mesh_core/settings.c +++ b/components/bt/esp_ble_mesh/mesh_core/settings.c @@ -183,7 +183,14 @@ static int role_set(const char *name) } if (exist == false) { +#if CONFIG_BLE_MESH_SETTINGS_BACKWARD_COMPATIBILITY + if (IS_ENABLED(CONFIG_BLE_MESH_NODE) && + !IS_ENABLED(CONFIG_BLE_MESH_PROVISIONER)) { + bt_mesh_atomic_set_bit(bt_mesh.flags, BLE_MESH_NODE); + } +#else return 0; +#endif } return 0;