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 e5db4550fc..ad67bc7592 100644 --- a/components/bt/esp_ble_mesh/mesh_core/cfg_srv.c +++ b/components/bt/esp_ble_mesh/mesh_core/cfg_srv.c @@ -2912,17 +2912,25 @@ static void krp_set(struct bt_mesh_model *model, struct bt_mesh_msg_ctx *ctx, phase == BLE_MESH_KR_PHASE_2) { sub->kr_phase = BLE_MESH_KR_PHASE_2; sub->kr_flag = 1; + + if (IS_ENABLED(CONFIG_BLE_MESH_SETTINGS)) { + BT_DBG("Storing kr phase persistently"); + bt_mesh_store_subnet(sub); + } + bt_mesh_net_beacon_update(sub); } else if ((sub->kr_phase == BLE_MESH_KR_PHASE_1 || sub->kr_phase == BLE_MESH_KR_PHASE_2) && phase == BLE_MESH_KR_PHASE_3) { + sub->kr_phase = BLE_MESH_KR_NORMAL; + sub->kr_flag = 0; bt_mesh_net_revoke_keys(sub); + if (IS_ENABLED(CONFIG_BLE_MESH_LOW_POWER) || IS_ENABLED(CONFIG_BLE_MESH_FRIEND)) { friend_cred_refresh(ctx->net_idx); } - sub->kr_phase = BLE_MESH_KR_NORMAL; - sub->kr_flag = 0; + bt_mesh_net_beacon_update(sub); } diff --git a/components/bt/esp_ble_mesh/mesh_core/net.c b/components/bt/esp_ble_mesh/mesh_core/net.c index 1c313a38c9..c01fbc75e1 100644 --- a/components/bt/esp_ble_mesh/mesh_core/net.c +++ b/components/bt/esp_ble_mesh/mesh_core/net.c @@ -501,6 +501,7 @@ void bt_mesh_net_revoke_keys(struct bt_mesh_subnet *sub) BT_DBG("idx 0x%04x", sub->net_idx); memcpy(&sub->keys[0], &sub->keys[1], sizeof(sub->keys[0])); + if (IS_ENABLED(CONFIG_BLE_MESH_SETTINGS)) { BT_DBG("Store updated NetKey persistently"); bt_mesh_store_subnet(sub); @@ -515,6 +516,7 @@ void bt_mesh_net_revoke_keys(struct bt_mesh_subnet *sub) memcpy(&key->keys[0], &key->keys[1], sizeof(key->keys[0])); key->updated = false; + if (IS_ENABLED(CONFIG_BLE_MESH_SETTINGS)) { BT_DBG("Store updated AppKey persistently"); bt_mesh_store_app_key(key); @@ -535,6 +537,12 @@ bool bt_mesh_kr_update(struct bt_mesh_subnet *sub, u8_t new_kr, bool new_key) if (sub->kr_phase == BLE_MESH_KR_PHASE_1) { BT_INFO("Phase 1 -> Phase 2"); sub->kr_phase = BLE_MESH_KR_PHASE_2; + + if (IS_ENABLED(CONFIG_BLE_MESH_SETTINGS)) { + BT_DBG("Storing kr phase persistently"); + bt_mesh_store_subnet(sub); + } + return true; } } else { @@ -553,12 +561,15 @@ bool bt_mesh_kr_update(struct bt_mesh_subnet *sub, u8_t new_kr, bool new_key) */ case BLE_MESH_KR_PHASE_2: BT_INFO("KR Phase 0x%02x -> Normal", sub->kr_phase); + + sub->kr_phase = BLE_MESH_KR_NORMAL; bt_mesh_net_revoke_keys(sub); + if (IS_ENABLED(CONFIG_BLE_MESH_LOW_POWER) || IS_ENABLED(CONFIG_BLE_MESH_FRIEND)) { friend_cred_refresh(sub->net_idx); } - sub->kr_phase = BLE_MESH_KR_NORMAL; + return true; } }