ble_mesh: stack: Store kr phase after value changed [Zephyr]

This commit is contained in:
lly 2020-09-30 14:46:43 +08:00
parent 3e61d519c1
commit 18cc96d188
2 changed files with 22 additions and 3 deletions

View File

@ -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);
}

View File

@ -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;
}
}