tools/mesh-cfgclient: Disallow sending a non-existing key
PATCH 1/1 tools/mesh-cfgclient: Disallow sending a non-existing key
Prior to sending either NetKeyAdd or AppKeyAdd message to a remote node, check if the key exists locally.
--- tools/mesh-cfgclient.c | 14 +++++++++++++- tools/mesh/keys.c | 8 ++++++++ tools/mesh/keys.h | 1 + 3 files changed, 22 insertions(+), 1 deletion(-)
tools/mesh-cfgclient.c +13 -1
@@ -316,8 +316,20 @@ static bool send_key(void *user_data, uint16_t dst, uint16_t key_idx,const char *method_name = (!is_appkey) ?"AddNetKey" :"AddAppKey" ; net_idx =remote_get_subnet_idx (dst); -if (net_idx ==NET_IDX_INVALID ) +if (net_idx ==NET_IDX_INVALID ) { +bt_shell_printf ("Node %4.4x not found\n" , dst);return false; + } + +if (!is_appkey && !keys_subnet_exists (key_idx)) { +bt_shell_printf ("Local NetKey %u not found\n" , key_idx); +return false; + } + +if (is_appkey && (keys_get_bound_key (key_idx) ==NET_IDX_INVALID )) { +bt_shell_printf ("Local AppKey %u not found\n" , key_idx); +return false; + } req = l_new(struct key_data, 1); req->ele_path = user_data;
tools/mesh/keys.c +8 -0
@@ -173,3 +173,11 @@ void keys_print_keys(void) {l_queue_foreach (net_keys, print_netkey,NULL ); } + +bool keys_subnet_exists (uint16_t idx) +{ +if (!l_queue_find (net_keys, net_idx_match,L_UINT_TO_PTR (idx))) +return false; + +return true; +}
tools/mesh/keys.h +1 -0
@@ -23,4 +23,5 @@ void keys_del_net_key(uint16_t net_idx);void keys_add_app_key (uint16_t net_idx,uint16_t app_idx);void keys_del_app_key (uint16_t app_idx);uint16_t keys_get_bound_key (uint16_t app_idx); +bool keys_subnet_exists (uint16_t idx);void keys_print_keys (void );
Signature · 1 line
2.21.0
Please ignore. Will send an updated version.
Quoted 60 lines · Inga Stotland
Prior to sending either NetKeyAdd or AppKeyAdd message to a remote node, check if the key exists locally.
--- tools/mesh-cfgclient.c | 14 +++++++++++++- tools/mesh/keys.c | 8 ++++++++ tools/mesh/keys.h | 1 + 3 files changed, 22 insertions(+), 1 deletion(-)tools/mesh-cfgclient.c +13
-1@@ -316,8 +316,20 @@ static bool send_key(void *user_data, uint16_t dst, uint16_t key_idx,const char *method_name = (!is_appkey) ?"AddNetKey" :"AddAppKey" ; net_idx =remote_get_subnet_idx (dst); -if (net_idx ==NET_IDX_INVALID ) +if (net_idx ==NET_IDX_INVALID ) { +bt_shell_printf ("Node %4.4x not found\n" , dst);return false; + } + +if (!is_appkey && !keys_subnet_exists (key_idx)) { +bt_shell_printf ("Local NetKey %u not found\n" , key_idx); +return false; + } + +if (is_appkey && (keys_get_bound_key (key_idx) ==NET_IDX_INVALID )) { +bt_shell_printf ("Local AppKey %u not found\n" , key_idx); +return false; + } req = l_new(struct key_data, 1); req->ele_path = user_data;tools/mesh/keys.c +8
-0@@ -173,3 +173,11 @@ void keys_print_keys(void) {l_queue_foreach (net_keys, print_netkey,NULL ); } + +bool keys_subnet_exists (uint16_t idx) +{ +if (!l_queue_find (net_keys, net_idx_match,L_UINT_TO_PTR (idx))) +return false; + +return true; +}tools/mesh/keys.h +1
-0@@ -23,4 +23,5 @@ void keys_del_net_key(uint16_t net_idx);void keys_add_app_key (uint16_t net_idx,uint16_t app_idx);void keys_del_app_key (uint16_t app_idx);uint16_t keys_get_bound_key (uint16_t app_idx); +bool keys_subnet_exists (uint16_t idx);void keys_print_keys (void );