From 9a470f7ba0784e2196ce0e9ef3c35c3c5213f880 Mon Sep 17 00:00:00 2001 From: Matthias Ringwald Date: Tue, 2 Jul 2019 18:33:41 +0200 Subject: [PATCH] mesh: make mesh_subnet_get_outgoing_network_key public --- src/mesh/mesh_network.c | 13 +++++++++---- src/mesh/mesh_network.h | 5 +++++ 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/src/mesh/mesh_network.c b/src/mesh/mesh_network.c index eb594a7cb..c6b321289 100644 --- a/src/mesh/mesh_network.c +++ b/src/mesh/mesh_network.c @@ -133,7 +133,6 @@ static int mesh_network_cache_index; static void mesh_network_run(void); static void process_network_pdu_validate(mesh_network_pdu_t * network_pdu); -static mesh_network_key_t * mesh_subnet_get_outgoing_network_key(mesh_subnet_t * subnet); // network caching static uint32_t mesh_network_cache_hash(mesh_network_pdu_t * network_pdu){ @@ -1085,9 +1084,15 @@ mesh_subnet_t * mesh_subnet_iterator_get_next(mesh_subnet_iterator_t *it){ return (mesh_subnet_t *) btstack_linked_list_iterator_next(&it->it); } -static mesh_network_key_t * mesh_subnet_get_outgoing_network_key(mesh_subnet_t * subnet){ - // TODO: old vs. new depends on key resfresh - return subnet->old_key; +mesh_network_key_t * mesh_subnet_get_outgoing_network_key(mesh_subnet_t * subnet){ + switch (subnet->key_refresh){ + case MESH_KEY_REFRESH_SECOND_PHASE: + return subnet->new_key; + case MESH_KEY_REFRESH_NOT_ACTIVE: + case MESH_KEY_REFRESH_FIRST_PHASE: + default: + return subnet->old_key; + } } /** diff --git a/src/mesh/mesh_network.h b/src/mesh/mesh_network.h index 04deb1e83..cd4b50d98 100644 --- a/src/mesh/mesh_network.h +++ b/src/mesh/mesh_network.h @@ -335,6 +335,11 @@ mesh_subnet_t * mesh_subnet_iterator_get_next(mesh_subnet_iterator_t *it); void mesh_subnet_update_for_netkey_index(uint16_t netkey_index); +/** + * @brief Get outgoing network key for subnet based on key refresh phase + */ +mesh_network_key_t * mesh_subnet_get_outgoing_network_key(mesh_subnet_t * subnet); + // buffer pool mesh_network_pdu_t * mesh_network_pdu_get(void); void mesh_network_pdu_free(mesh_network_pdu_t * network_pdu);