Remote node reset implementation
cover Remote node reset implementation
This set of patches provides complete implementation of sending and processing of Config Node Reset and Config Node Reset Status messages
Inga Stotland (2):
tools/mesh-cfgclient: Implement node-reset command
mesh: Fix processing of Config Node Reset message
mesh/cfgmod-server.c | 14 ++++---- tools/mesh-cfgclient.c | 77 ++++++++++++++++-------------------------- tools/mesh/cfgcli.c | 60 ++++++++++++++++++++++++++++---- tools/mesh/cfgcli.h | 4 ++- tools/mesh/mesh-db.c | 39 +++++++++++++++++++++ tools/mesh/remote.c | 20 +++++++++++ tools/mesh/remote.h | 1 + 7 files changed, 154 insertions(+), 61 deletions(-)
Signature · 1 line
2.21.1
PATCH 1/2 tools/mesh-cfgclient: Implement node-reset command
This implements one-pass removal oa a remote node from a mesh network by issuing a node-reset command from config menu. The following actions are performed:
- Config Node Reset message is sent to a remote node
- Upon either receiving Config Node Reset Status or response timeout, node record is removed from configuration client's database and, by calling DeleteRemoteNode() method on mesh.Management interface
node-delete command from the main menu is removed.
--- tools/mesh-cfgclient.c | 77 ++++++++++++++++-------------------------- tools/mesh/cfgcli.c | 60 ++++++++++++++++++++++++++++---- tools/mesh/cfgcli.h | 4 ++- tools/mesh/mesh-db.c | 39 +++++++++++++++++++++ tools/mesh/remote.c | 20 +++++++++++ tools/mesh/remote.h | 1 + 6 files changed, 147 insertions(+), 54 deletions(-)
tools/mesh-cfgclient.c +30 -47
@@ -342,9 +342,38 @@ static bool send_key(void *user_data, uint16_t dst, uint16_t key_idx, send_key_setup, NULL, req, l_free) != 0; } +static void delete_node_setup (struct l_dbus_message *msg,void *user_data) +{ +struct generic_request *req = user_data; +uint16_t primary; +uint8_t ele_cnt; + + primary = (uint16_t ) req->arg1; + ele_cnt = (uint8_t ) req->arg2; + +l_dbus_message_set_arguments (msg,"qy" , primary, ele_cnt); +} + +static void delete_node (uint16_t primary,uint8_t ele_cnt) +{ +struct generic_request *req; + +if (!local || !local->proxy || !local->mgmt_proxy) { +bt_shell_printf ("Node is not attached\n" ); +return ; + } + + req = l_new(struct generic_request, 1); + req->arg1 = primary; + req->arg2 = ele_cnt; + +l_dbus_proxy_method_call (local->mgmt_proxy,"DeleteRemoteNode" , + delete_node_setup,NULL , req, l_free); +} +static void client_init (void ) { - cfgcli =cfgcli_init (send_key, (void *) app.ele.path); + cfgcli =cfgcli_init (send_key, delete_node, (void *) app.ele.path); cfgcli->ops.set_send_func (send_msg, (void *) app.ele.path); }
@@ -801,50 +830,6 @@ static void free_generic_request(void *data)l_free (req); } -static void delete_node_setup (struct l_dbus_message *msg,void *user_data) -{ -struct generic_request *req = user_data; -uint16_t primary; -uint8_t ele_cnt; - - primary = (uint16_t ) req->arg1; - ele_cnt = (uint8_t ) req->arg2; - -l_dbus_message_set_arguments (msg,"qy" , primary, ele_cnt); -} - -static void cmd_delete_node (int argc,char *argv[]) -{ -struct generic_request *req; - -if (!local || !local->proxy || !local->mgmt_proxy) { -bt_shell_printf ("Node is not attached\n" ); -return ; - } - -if (argc <3 ) { -bt_shell_printf ("Unicast and element count are required\n" ); -return ; - } - - req = l_new(struct generic_request, 1); - -if (sscanf (argv[1 ],"%04x" , &req->arg1) !=1 ) - goto fail; - -if (sscanf (argv[2 ],"%u" , &req->arg2) !=1 ) - goto fail; - -l_dbus_proxy_method_call (local->mgmt_proxy,"DeleteRemoteNode" , - delete_node_setup,NULL , req, l_free); - -/* TODO:: Delete node from configuration */ -return ; - -fail: -l_free (req); -} -static void import_node_reply (struct l_dbus_proxy *proxy,struct l_dbus_message *msg,void *user_data) {
@@ -1359,8 +1344,6 @@ static const struct bt_shell_menu main_menu = { {"node-import" ,"<uuid> <net_idx> <primary> <ele_count> <dev_key>" , cmd_import_node, "Import an externally provisioned remote node"}, - { "node-delete", "<primary> <ele_count>", cmd_delete_node, - "Delete a remote node"}, { "list-nodes", NULL, cmd_list_nodes, "List remote mesh nodes"}, { "keys", NULL, cmd_keys,
tools/mesh/cfgcli.c +54 -6
103 lines not on this page · raw message
tools/mesh/cfgcli.h +3 -1
@@ -25,6 +25,8 @@ struct mesh_group {typedef bool (*key_send_func_t ) (void *user_data,uint16_t dst,uint16_t idx,bool is_appkey,bool update); +typedef void (*delete_remote_func_t ) (uint16_t primary,uint8_t ele_cnt); -struct model_info *cfgcli_init (key_send_func_t key_func,void *user_data); +struct model_info *cfgcli_init (key_send_func_t key_func, +delete_remote_func_t del_node,void *user_data);void cfgcli_cleanup (void );
tools/mesh/mesh-db.c +39 -0
@@ -845,6 +845,45 @@ fail:return false; } +bool mesh_db_del_node (uint16_t unicast) +{ +json_object *jarray; +int i, sz; + +if (!json_object_object_get_ex (cfg->jcfg,"nodes" , &jarray)) +return false; + +if (!jarray ||json_object_get_type (jarray) != json_type_array) +return false; + + sz =json_object_array_length (jarray); + +for (i =0 ; i < sz; ++i) { +json_object *jentry, *jval; +uint16_t addr; +const char *str; + + jentry =json_object_array_get_idx (jarray, i); +if (!json_object_object_get_ex (jentry,"unicastAddress" , + &jval)) +continue ; + + str =json_object_get_string (jval); +if (sscanf (str,"%04hx" , &addr) !=1 ) +continue ; + +if (addr == unicast) +break ; + } + +if (i == sz) +return true; + +json_object_array_del_idx (jarray, i,1 ); + +return mesh_config_save ((struct mesh_config *) cfg, true,NULL ,NULL ); +} +bool mesh_db_get_token (uint8_t token[8 ]) {if (!cfg || !cfg->jcfg)
tools/mesh/remote.c +20 -0
@@ -89,6 +89,26 @@ static bool match_bound_key(const void *a, const void *b)return (net_idx ==keys_get_bound_key (app_idx)); } +uint8_t remote_del_node (uint16_t unicast) +{ +struct remote_node *rmt; +uint8_t num_ele; + + rmt =l_queue_remove_if (nodes, match_node_addr,L_UINT_TO_PTR (unicast)); +if (!rmt) +return 0 ; + + num_ele = rmt->num_ele; + +l_queue_destroy (rmt->net_keys,NULL ); +l_queue_destroy (rmt->app_keys,NULL ); +l_free (rmt); + +mesh_db_del_node (unicast); + +return num_ele; +} +bool remote_add_node (const uint8_t uuid[16 ],uint16_t unicast,uint8_t ele_cnt,uint16_t net_idx) {
tools/mesh/remote.h +1 -0
@@ -19,6 +19,7 @@bool remote_add_node (const uint8_t uuid[16 ],uint16_t unicast,uint8_t ele_cnt,uint16_t net_idx); +uint8_t remote_del_node (uint16_t unicast);uint16_t remote_get_next_unicast (uint16_t low,uint16_t high,uint8_t ele_cnt);bool remote_add_net_key (uint16_t addr,uint16_t net_idx);bool remote_del_net_key (uint16_t addr,uint16_t net_idx);
Signature · 1 line
2.21.1
PATCH 2/2 mesh: Fix processing of Config Node Reset message
In reply to Inga StotlandThis fixes a condition when a node continues processing messages after it has been reset by a remote configuration client. Upon receiving Config Node Reset message, a node deregisters it's message receive callbacks and a complete node removal happens after a grace interval to allow sending of Config Node Reset Status reply.
--- mesh/cfgmod-server.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-)
mesh/cfgmod-server.c +7 -7
@@ -1223,20 +1223,20 @@ static bool cfg_srv_pkt(uint16_t src, uint16_t dst, uint16_t app_idx,case OP_NODE_RESET : n =mesh_model_opcode_set (OP_NODE_RESET_STATUS , msg); -/* -* Delay node removal to give it a chance to send back the -* status -*/ + +/* After reset, node is not processing any incoming messages */ +mesh_net_detach (net); + +/* Delay node removal to give it a chance to send the status */ l_timeout_create (1 , node_reset, node,NULL );break ; } -if (n) { -/* print_packet("App Tx", long_msg ? long_msg : msg, n); */ +if (n)mesh_model_send (node, dst, src,APP_IDX_DEV_LOCAL , net_idx,DEFAULT_TTL , long_msg ? long_msg : msg, n); - } +l_free (long_msg);return true;
Signature · 1 line
2.21.1