From: Prathyusha N <prathyusha.n@xxxxxxxxxxx> Switch to phase 3 when updated net key index is same as beacon key id. Switch beaconing key in phase 2 and phase 3. --- mesh/net.c | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/mesh/net.c b/mesh/net.c index ec05b6be9..3b6c8365f 100644 --- a/mesh/net.c +++ b/mesh/net.c @@ -2598,6 +2598,14 @@ static int key_refresh_phase_two(struct mesh_net *net, uint16_t idx) */ subnet->kr_phase = KEY_REFRESH_PHASE_TWO; refresh_beacon(subnet, net); + + /* send snb with updated net key id in phase 2 */ + if (net->beacon_enable) { + /* Switch beaconing key */ + net_key_beacon_disable(subnet->net_key_cur); + net_key_beacon_enable(subnet->net_key_upd); + } + queue_friend_update(net); l_queue_foreach(net->friends, frnd_kr_phase2, net); @@ -2625,6 +2633,13 @@ static int key_refresh_finish(struct mesh_net *net, uint16_t idx) l_info("Key refresh phase 3: use new keys only, discard old ones"); + /* required when skipping phase 2 */ + if (net->beacon_enable) { + /* Switch beaconing key */ + net_key_beacon_disable(subnet->net_key_cur); + net_key_beacon_enable(subnet->net_key_upd); + } + /* Switch to using new keys, discard old ones */ net_key_unref(subnet->net_key_cur); subnet->net_key_tx = subnet->net_key_cur = subnet->net_key_upd; @@ -2755,7 +2770,8 @@ static void process_beacon(void *net_ptr, void *user_data) ivi != net->iv_index || ivu != net->iv_update) update_iv_ivu_state(net, ivi, ivu); - if (kr != local_kr) + if (kr != local_kr || (subnet->kr_phase == KEY_REFRESH_PHASE_ONE && + subnet->net_key_upd == beacon_data->key_id)) update_kr_state(subnet, kr, beacon_data->key_id); net_key_beacon_refresh(beacon_data->key_id, net->iv_index, -- 2.17.1