|
|
@@ -194,10 +194,27 @@ int bt_mesh_prov_enable(bt_mesh_prov_bearer_t bearers)
|
|
|
return -EINVAL;
|
|
|
}
|
|
|
|
|
|
- bt_mesh_atomic_set_bit(bt_mesh.flags, BLE_MESH_NODE);
|
|
|
-
|
|
|
- if (IS_ENABLED(CONFIG_BLE_MESH_SETTINGS)) {
|
|
|
- bt_mesh_store_role();
|
|
|
+ /* Add this judgement here in case the device worked as a
|
|
|
+ * Provisioner previously. Before the corresponding info
|
|
|
+ * of Provisioner is erased from flash, users try to use
|
|
|
+ * the device as a node, which will cause the information
|
|
|
+ * in NVS been handled incorrectly.
|
|
|
+ */
|
|
|
+ u8_t role = bt_mesh_atomic_get(bt_mesh.flags) & BLE_MESH_SETTINGS_ROLE_BIT_MASK;
|
|
|
+ if (role != BLE_MESH_SETTINGS_ROLE_NONE &&
|
|
|
+ role != BLE_MESH_SETTINGS_ROLE_NODE) {
|
|
|
+ BT_ERR("%s, Mismatch role %u", __func__, role);
|
|
|
+ return -EIO;
|
|
|
+ }
|
|
|
+
|
|
|
+ if (role == BLE_MESH_SETTINGS_ROLE_NONE) {
|
|
|
+ bt_mesh_atomic_set_bit(bt_mesh.flags, BLE_MESH_NODE);
|
|
|
+ }
|
|
|
+ if (IS_ENABLED(CONFIG_BLE_MESH_SETTINGS_BACKWARD_COMPATIBILITY) ||
|
|
|
+ role == BLE_MESH_SETTINGS_ROLE_NONE) {
|
|
|
+ if (IS_ENABLED(CONFIG_BLE_MESH_SETTINGS)) {
|
|
|
+ bt_mesh_store_role();
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
if (IS_ENABLED(CONFIG_BLE_MESH_PB_ADV) &&
|
|
|
@@ -220,6 +237,7 @@ int bt_mesh_prov_enable(bt_mesh_prov_bearer_t bearers)
|
|
|
int bt_mesh_prov_disable(bt_mesh_prov_bearer_t bearers)
|
|
|
{
|
|
|
if (bt_mesh_is_provisioned()) {
|
|
|
+ BT_WARN("%s, Already provisioned", __func__);
|
|
|
return -EALREADY;
|
|
|
}
|
|
|
|
|
|
@@ -527,6 +545,27 @@ int bt_mesh_provisioner_enable(bt_mesh_prov_bearer_t bearers)
|
|
|
return -EINVAL;
|
|
|
}
|
|
|
|
|
|
+ /* Add this judgement here in case the device worked as a
|
|
|
+ * node previously. Before the corresponding information
|
|
|
+ * of the node is erased from flash, users try to use the
|
|
|
+ * device as a Provisioner, which will cause the information
|
|
|
+ * in NVS been handled incorrectly.
|
|
|
+ */
|
|
|
+ u8_t role = bt_mesh_atomic_get(bt_mesh.flags) & BLE_MESH_SETTINGS_ROLE_BIT_MASK;
|
|
|
+ if (role != BLE_MESH_SETTINGS_ROLE_NONE &&
|
|
|
+ role != BLE_MESH_SETTINGS_ROLE_PROV) {
|
|
|
+ BT_ERR("%s, Mismatch role %u", __func__, role);
|
|
|
+ return -EIO;
|
|
|
+ }
|
|
|
+
|
|
|
+ if (role == BLE_MESH_SETTINGS_ROLE_NONE) {
|
|
|
+ bt_mesh_atomic_set_bit(bt_mesh.flags, BLE_MESH_PROVISIONER);
|
|
|
+
|
|
|
+ if (IS_ENABLED(CONFIG_BLE_MESH_SETTINGS)) {
|
|
|
+ bt_mesh_store_role();
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
err = bt_mesh_provisioner_net_create();
|
|
|
if (err) {
|
|
|
BT_ERR("Failed to create network");
|
|
|
@@ -543,12 +582,6 @@ int bt_mesh_provisioner_enable(bt_mesh_prov_bearer_t bearers)
|
|
|
|
|
|
bt_mesh_comp_provision(bt_mesh_provisioner_get_primary_elem_addr());
|
|
|
|
|
|
- bt_mesh_atomic_set_bit(bt_mesh.flags, BLE_MESH_PROVISIONER);
|
|
|
-
|
|
|
- if (IS_ENABLED(CONFIG_BLE_MESH_SETTINGS)) {
|
|
|
- bt_mesh_store_role();
|
|
|
- }
|
|
|
-
|
|
|
#if defined(CONFIG_BLE_MESH_USE_DUPLICATE_SCAN)
|
|
|
if (IS_ENABLED(CONFIG_BLE_MESH_PB_ADV) &&
|
|
|
(bearers & BLE_MESH_PROV_ADV)) {
|