diff --git a/src/mesh/mesh_network.c b/src/mesh/mesh_network.c index e3a106de6..408fc872b 100644 --- a/src/mesh/mesh_network.c +++ b/src/mesh/mesh_network.c @@ -994,6 +994,12 @@ void mesh_trigger_iv_update(void){ global_iv_index++; } +void mesh_iv_update_completed(void){ + if (!global_iv_update_active) return; + // set Normal mode + global_iv_update_active = 0; +} + // Network PDU Getter uint8_t mesh_network_nid(mesh_network_pdu_t * network_pdu){ return network_pdu->data[0] & 0x7f; diff --git a/src/mesh/mesh_network.h b/src/mesh/mesh_network.h index 05cd91577..fc45fd20d 100644 --- a/src/mesh/mesh_network.h +++ b/src/mesh/mesh_network.h @@ -379,6 +379,7 @@ uint32_t mesh_get_iv_index_for_tx(void); int mesh_iv_update_active(void); void mesh_trigger_iv_update(void); +void mesh_iv_update_completed(void); // Testing only void mesh_network_received_message(const uint8_t * pdu_data, uint8_t pdu_len, uint8_t flags); diff --git a/test/mesh/mesh_access.c b/test/mesh/mesh_access.c index 1ca4e8a75..b2be117a0 100644 --- a/test/mesh/mesh_access.c +++ b/test/mesh/mesh_access.c @@ -1404,10 +1404,12 @@ static void mesh_access_secure_network_beacon_handler(uint8_t packet_type, uint1 } if (subnet == NULL) return; + uint8_t flags = packet[1]; + // Key refresh via secure network beacons that are authenticated with new netkey if (new_key){ // either first or second phase (in phase 0, new key is not set) - int key_refresh_flag = packet[1] & 1; + int key_refresh_flag = flags & 1; if (key_refresh_flag){ // transition to phase 3 from either phase 1 or 2 switch (subnet->key_refresh){ @@ -1432,5 +1434,19 @@ static void mesh_access_secure_network_beacon_handler(uint8_t packet_type, uint1 } } - // TODO: IV Update + // IV Update + + // TODO: validate IV index w.r.t. local index + + int iv_update_active_flag = flags & 2; + + if (mesh_iv_update_active()){ + if (iv_update_active_flag){ + mesh_trigger_iv_update(); + } + } else { + if (iv_update_active_flag == 0){ + mesh_iv_update_completed(); + } + } }