From 826cba5a5b112ace19a19af6054f109bb6fe41f8 Mon Sep 17 00:00:00 2001 From: Inga Stotland Date: Thu, 9 Jan 2020 17:41:44 -0800 Subject: [PATCH] mesh: Fix logic in AppKey deletion When deleting an AppKey from a node, call mesh_config_app_key_del() only from appkey level (i.e., keep it contained in appkey.c and remove the duplicate call in node.c) Also, simplify the node_app_key_delete() argument list. Change-Id: I9f04abdaeeae2e791b02afafec565d1fcbbb6931 Signed-off-by: Abhay Agarwal --- mesh/appkey.c | 6 +++--- mesh/node.c | 29 ++--------------------------- mesh/node.h | 4 ++-- 3 files changed, 7 insertions(+), 32 deletions(-) diff --git a/mesh/appkey.c b/mesh/appkey.c index b061ec9..0024b0e 100644 --- a/mesh/appkey.c +++ b/mesh/appkey.c @@ -418,13 +418,13 @@ int appkey_key_delete(struct mesh_net *net, uint16_t net_idx, if (key->net_idx != net_idx) return MESH_STATUS_INVALID_NETKEY; - node_app_key_delete(net, mesh_net_get_address(net), net_idx, app_idx); + node = mesh_net_node_get(net); + + node_app_key_delete(node, net_idx, app_idx); l_queue_remove(app_keys, key); appkey_key_free(key); - node = mesh_net_node_get(net); - if (!mesh_config_app_key_del(node_config_get(node), net_idx, app_idx)) return MESH_STATUS_STORAGE_FAIL; diff --git a/mesh/node.c b/mesh/node.c index 54d3cb6..f26b5ab 100644 --- a/mesh/node.c +++ b/mesh/node.c @@ -135,15 +135,6 @@ struct managed_obj_request { static struct l_queue *nodes; -static bool match_node_unicast(const void *a, const void *b) -{ - const struct mesh_node *node = a; - uint16_t dst = L_PTR_TO_UINT(b); - - return (dst >= node->primary && - dst <= (node->primary + node->num_ele - 1)); -} - static bool match_device_uuid(const void *a, const void *b) { const struct mesh_node *node = a; @@ -216,15 +207,6 @@ static int compare_model_id(const void *a, const void *b, void *user_data) return 0; } - -struct mesh_node *node_find_by_addr(uint16_t addr) -{ - if (!IS_UNICAST(addr)) - return NULL; - - return l_queue_find(nodes, match_node_unicast, L_UINT_TO_PTR(addr)); -} - struct mesh_node *node_find_by_uuid(uint8_t uuid[16]) { return l_queue_find(nodes, match_device_uuid, uuid); @@ -627,24 +609,17 @@ bool node_is_provisioned(struct mesh_node *node) return (!IS_UNASSIGNED(node->primary)); } -bool node_app_key_delete(struct mesh_net *net, uint16_t addr, - uint16_t net_idx, uint16_t app_idx) +void node_app_key_delete(struct mesh_node *node, uint16_t net_idx, + uint16_t app_idx) { - struct mesh_node *node; const struct l_queue_entry *entry; - node = node_find_by_addr(addr); - if (!node) - return false; - entry = l_queue_get_entries(node->elements); for (; entry; entry = entry->next) { struct node_element *ele = entry->data; mesh_model_app_key_delete(node, ele->models, app_idx); } - - return mesh_config_app_key_del(node->cfg, net_idx, app_idx); } uint16_t node_get_primary(struct mesh_node *node) diff --git a/mesh/node.h b/mesh/node.h index c718c03..a6bc4a2 100644 --- a/mesh/node.h +++ b/mesh/node.h @@ -40,8 +40,8 @@ struct mesh_node *node_find_by_uuid(uint8_t uuid[16]); struct mesh_node *node_find_by_token(uint64_t token); bool node_is_provisioner(struct mesh_node *node); bool node_is_provisioned(struct mesh_node *node); -bool node_app_key_delete(struct mesh_net *net, uint16_t addr, - uint16_t net_idx, uint16_t idx); +void node_app_key_delete(struct mesh_node *node, uint16_t net_idx, + uint16_t app_idx); uint16_t node_get_primary(struct mesh_node *node); uint16_t node_get_primary_net_idx(struct mesh_node *node); void node_set_token(struct mesh_node *node, uint8_t token[8]); -- 2.7.4