mesh: Allow Key refresh to skip Phase 2
authorIsak Westin <isak.westin@loytec.com>
Thu, 29 Sep 2022 11:03:43 +0000 (13:03 +0200)
committerAyush Garg <ayush.garg@samsung.com>
Mon, 15 May 2023 09:25:55 +0000 (14:55 +0530)
If we are in Key Refresh Phase 1, and receive a Secure Network beacon
using the new NetKey and with KR flag set to 0, Phase 2 should be
skipped. See MshPRFv1.0.1 section 3.10.4.1.

Signed-off-by: Manika Shrivastava <manika.sh@samsung.com>
Signed-off-by: Ayush Garg <ayush.garg@samsung.com>
mesh/net.c

index eb949d2..a19575a 100644 (file)
@@ -2611,7 +2611,8 @@ static bool update_kr_state(struct mesh_subnet *subnet, bool kr, uint32_t id)
 {
        /* Figure out the key refresh phase */
        if (kr) {
-               if (id == subnet->net_key_upd) {
+               if (subnet->kr_phase == KEY_REFRESH_PHASE_ONE &&
+                                               id == subnet->net_key_upd) {
                        l_debug("Beacon based KR phase 2 change");
                        return (key_refresh_phase_two(subnet->net, subnet->idx)
                                                        == MESH_STATUS_SUCCESS);
@@ -2752,7 +2753,7 @@ static void process_beacon(void *net_ptr, void *user_data)
                                                        ivu != net->iv_update)
                updated |= update_iv_ivu_state(net, ivi, ivu);
 
-       if (kr != local_kr)
+       if (kr != local_kr || beacon_data->net_key_id != subnet->net_key_cur)
                updated |= update_kr_state(subnet, kr, beacon_data->net_key_id);
 
        if (updated)