From b1dda141415ad4743ceb62fac9fe97b12ba62ae9 Mon Sep 17 00:00:00 2001 From: Matthias Ringwald Date: Tue, 2 Jul 2019 17:17:31 +0200 Subject: [PATCH] mesh: remove subnet without keys, set key refresh idle if only single key --- src/mesh/mesh_network.c | 23 +++++++++++++++++------ 1 file changed, 17 insertions(+), 6 deletions(-) diff --git a/src/mesh/mesh_network.c b/src/mesh/mesh_network.c index d77feb610..e27236132 100644 --- a/src/mesh/mesh_network.c +++ b/src/mesh/mesh_network.c @@ -1106,11 +1106,17 @@ void mesh_subnet_update_for_netkey_index(uint16_t netkey_index){ } } - // no keys? - if (old_key == NULL) return; - - // get/create subnet for netkey index + // get subnet mesh_subnet_t * subnet = mesh_subnet_get_by_netkey_index(netkey_index); + + // no keys -> no subnet + if (old_key == NULL) { + if (subnet == NULL) return; + mesh_subnet_remove(subnet); + return; + } + + // create subnet for netkey index if needed if (subnet == NULL){ subnet = btstack_memory_mesh_subnet_get(); if (subnet == NULL) return; @@ -1122,13 +1128,18 @@ void mesh_subnet_update_for_netkey_index(uint16_t netkey_index){ subnet->new_key = new_key; // key refresh - if (new_key != NULL){ + if (new_key == NULL){ + // single key -> key refresh not active + subnet->key_refresh = MESH_KEY_REFRESH_NOT_ACTIVE; + } + else { + // two keys -> at least phase 1 if (subnet->key_refresh == MESH_KEY_REFRESH_NOT_ACTIVE){ - // approximation: at least phase 1 subnet->key_refresh = MESH_KEY_REFRESH_FIRST_PHASE; } } + // TODO: advertisement using node id active // TODO: advertisement using network id (used by proxy) // TODO: secure network beacons