From 85f6c8a0c0250469bf0c15f50857aea4c87cbf43 Mon Sep 17 00:00:00 2001 From: Matthias Ringwald Date: Thu, 4 Jul 2019 12:24:56 +0200 Subject: [PATCH] mesh: use mesh_subnet_setup_for_netkey_index only on start and for tests --- src/mesh/mesh_network.c | 28 ++++++++++------------------ src/mesh/mesh_network.h | 4 ++-- test/mesh/mesh.c | 2 +- test/mesh/mesh_access.c | 2 +- test/mesh/mesh_message_test.c | 6 +++--- 5 files changed, 17 insertions(+), 25 deletions(-) diff --git a/src/mesh/mesh_network.c b/src/mesh/mesh_network.c index 8827ad05d..1860ae812 100644 --- a/src/mesh/mesh_network.c +++ b/src/mesh/mesh_network.c @@ -1096,9 +1096,12 @@ mesh_network_key_t * mesh_subnet_get_outgoing_network_key(mesh_subnet_t * subnet } /** - * @brief Update subnet for given netkey index + * @brief Setup subnet for given netkey index */ -void mesh_subnet_update_for_netkey_index(uint16_t netkey_index){ +void mesh_subnet_setup_for_netkey_index(uint16_t netkey_index){ + mesh_subnet_t * subnet = mesh_subnet_get_by_netkey_index(netkey_index); + if (subnet != NULL) return; + // find old / new keys mesh_network_key_t * old_key = NULL; mesh_network_key_t * new_key = NULL; @@ -1120,20 +1123,11 @@ void mesh_subnet_update_for_netkey_index(uint16_t netkey_index){ } } - // get subnet - mesh_subnet_t * subnet = mesh_subnet_get_by_netkey_index(netkey_index); - - // ignore if no key or no subnet - if (old_key == NULL) return; + // create subnet for netkey index + subnet = btstack_memory_mesh_subnet_get(); if (subnet == NULL) return; - - // create subnet for netkey index if needed - if (subnet == NULL){ - subnet = btstack_memory_mesh_subnet_get(); - if (subnet == NULL) return; - subnet->netkey_index = netkey_index; - mesh_subnet_add(subnet); - } + subnet->netkey_index = netkey_index; + mesh_subnet_add(subnet); // set keys subnet->old_key = old_key; @@ -1146,8 +1140,6 @@ void mesh_subnet_update_for_netkey_index(uint16_t netkey_index){ } else { // two keys -> at least phase 1 - if (subnet->key_refresh == MESH_KEY_REFRESH_NOT_ACTIVE){ - subnet->key_refresh = MESH_KEY_REFRESH_FIRST_PHASE; - } + subnet->key_refresh = MESH_KEY_REFRESH_FIRST_PHASE; } } diff --git a/src/mesh/mesh_network.h b/src/mesh/mesh_network.h index cd4b50d98..27fd56a56 100644 --- a/src/mesh/mesh_network.h +++ b/src/mesh/mesh_network.h @@ -330,9 +330,9 @@ int mesh_subnet_iterator_has_more(mesh_subnet_iterator_t *it); mesh_subnet_t * mesh_subnet_iterator_get_next(mesh_subnet_iterator_t *it); /** - * @brief Update subnet for given netkey index + * @brief Setup subnet for given netkey index */ -void mesh_subnet_update_for_netkey_index(uint16_t netkey_index); +void mesh_subnet_setup_for_netkey_index(uint16_t netkey_index); /** diff --git a/test/mesh/mesh.c b/test/mesh/mesh.c index 7ce86c220..98773c3eb 100644 --- a/test/mesh/mesh.c +++ b/test/mesh/mesh.c @@ -409,7 +409,7 @@ static void mesh_provisioning_message_handler (uint8_t packet_type, uint16_t cha mesh_network_key_add(primary_network_key); // setup primary network - mesh_subnet_update_for_netkey_index(primary_network_key->netkey_index); + mesh_subnet_setup_for_netkey_index(primary_network_key->netkey_index); // store provisioning data and primary network key in TLV btstack_tlv_singleton_impl->store_tag(btstack_tlv_singleton_context, 'PROV', (uint8_t *) &provisioning_data, sizeof(mesh_provisioning_data_t)); diff --git a/test/mesh/mesh_access.c b/test/mesh/mesh_access.c index 75e2b3e1c..4481da0bd 100644 --- a/test/mesh/mesh_access.c +++ b/test/mesh/mesh_access.c @@ -978,7 +978,7 @@ void mesh_load_network_keys(void){ mesh_network_key_add(network_key); - mesh_subnet_update_for_netkey_index(network_key->netkey_index); + mesh_subnet_setup_for_netkey_index(network_key->netkey_index); printf("- internal index 0x%x, NetKey Index 0x%06x, NID %02x: ", network_key->internal_index, network_key->netkey_index, network_key->nid); printf_hexdump(network_key->net_key, 16); diff --git a/test/mesh/mesh_message_test.c b/test/mesh/mesh_message_test.c index 1047a4792..e98ecace3 100644 --- a/test/mesh/mesh_message_test.c +++ b/test/mesh/mesh_message_test.c @@ -161,7 +161,7 @@ static void load_network_key_nid_68(void){ btstack_parse_hex("0953fa93e7caac9638f58820220a398e", 16, network_key->encryption_key); btstack_parse_hex("8b84eedec100067d670971dd2aa700cf", 16, network_key->privacy_key); mesh_network_key_add(network_key); - mesh_subnet_update_for_netkey_index(network_key->netkey_index); + mesh_subnet_setup_for_netkey_index(network_key->netkey_index); } static void load_network_key_nid_5e(void){ @@ -170,7 +170,7 @@ static void load_network_key_nid_5e(void){ btstack_parse_hex("be635105434859f484fc798e043ce40e", 16, network_key->encryption_key); btstack_parse_hex("5d396d4b54d3cbafe943e051fe9a4eb8", 16, network_key->privacy_key); mesh_network_key_add(network_key); - mesh_subnet_update_for_netkey_index(network_key->netkey_index); + mesh_subnet_setup_for_netkey_index(network_key->netkey_index); } static void load_network_key_nid_10(void){ @@ -179,7 +179,7 @@ static void load_network_key_nid_10(void){ btstack_parse_hex("3a4fe84a6cc2c6a766ea93f1084d4039", 16, network_key->encryption_key); btstack_parse_hex("f695fcce709ccface4d8b7a1e6e39d25", 16, network_key->privacy_key); mesh_network_key_add(network_key); - mesh_subnet_update_for_netkey_index(network_key->netkey_index); + mesh_subnet_setup_for_netkey_index(network_key->netkey_index); } static void load_provisioning_data_test_message(void){