From: Inga Stotland Date: Wed, 10 Jun 2020 17:11:21 +0000 (-0700) Subject: mesh: Add "node is busy" check for Leave() & Attach() X-Git-Tag: accepted/tizen/unified/20210128.132355~2^2~76 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=987dc0a369538df1e13d35408089841fc73980e4;p=platform%2Fupstream%2Fbluez.git mesh: Add "node is busy" check for Leave() & Attach() This introduces the following behavior change for those methods on Network interface that specify node token as an input parameter Leave() method: If Leave method is called for a node that is being processed as a result of a Create, Import, Join or Attach method calls in progress, node removal is not allowed and org.bluez.mesh.Error.Busy error is returned. Attach() method: If Attach method is called for a node that is being processed as a result of a Create, Import or Join method calls in progress, node attachment is not allowed and org.bluez.mesh.Error.Busy error is returned. Change-Id: I994d81ef27eb6e7e2423a6504fcf3396ea039a15 Signed-off-by: anuj.bhumiya --- diff --git a/doc/mesh-api.txt b/doc/mesh-api.txt index 107599a..36b0d64 100644 --- a/doc/mesh-api.txt +++ b/doc/mesh-api.txt @@ -116,6 +116,7 @@ Methods: org.bluez.mesh.Error.InvalidArguments org.bluez.mesh.Error.NotFound, org.bluez.mesh.Error.AlreadyExists, + org.bluez.mesh.Error.Busy, org.bluez.mesh.Error.Failed void Leave(uint64 token) @@ -138,6 +139,7 @@ Methods: PossibleErrors: org.bluez.mesh.Error.InvalidArguments, org.bluez.mesh.Error.NotFound + org.bluez.mesh.Error.Busy void CreateNetwork(object app_root, array{byte}[16] uuid) diff --git a/mesh/mesh.c b/mesh/mesh.c index 7a13f40..525ae55 100644 --- a/mesh/mesh.c +++ b/mesh/mesh.c @@ -654,13 +654,21 @@ static struct l_dbus_message *leave_call(struct l_dbus *dbus, void *user_data) { uint64_t token; + struct mesh_node *node; l_debug("Leave"); if (!l_dbus_message_get_arguments(msg, "t", &token)) return dbus_error(msg, MESH_ERROR_INVALID_ARGS, NULL); - node_remove(node_find_by_token(token)); + node = node_find_by_token(token); + if (!node) + return dbus_error(msg, MESH_ERROR_NOT_FOUND, NULL); + + if (node_is_busy(node)) + return dbus_error(msg, MESH_ERROR_BUSY, NULL); + + node_remove(node); return l_dbus_message_new_method_return(msg); } diff --git a/mesh/node.c b/mesh/node.c index 3a9b341..85dc623 100644 --- a/mesh/node.c +++ b/mesh/node.c @@ -88,6 +88,7 @@ struct mesh_node { char *storage_dir; uint32_t disc_watch; uint32_t seq_number; + bool busy; bool provisioner; uint16_t primary; struct node_composition comp; @@ -614,6 +615,11 @@ bool node_is_provisioner(struct mesh_node *node) return node->provisioner; } +bool node_is_busy(struct mesh_node *node) +{ + return node->busy; +} + void node_app_key_delete(struct mesh_node *node, uint16_t net_idx, uint16_t app_idx) { @@ -1368,6 +1374,8 @@ static bool add_local_node(struct mesh_node *node, uint16_t unicast, bool kr, /* Initialize configuration server model */ cfgmod_server_init(node, PRIMARY_ELE_IDX); + node->busy = true; + return true; } @@ -1475,6 +1483,9 @@ static void get_managed_objects_cb(struct l_dbus_message *msg, void *user_data) struct keyring_net_key net_key; uint8_t dev_key[16]; + if (req->type == REQUEST_TYPE_ATTACH) + req->attach->busy = false; + if (!msg || l_dbus_message_is_error(msg)) { l_error("Failed to get app's dbus objects"); goto fail; @@ -1670,6 +1681,12 @@ void node_attach(const char *app_root, const char *sender, uint64_t token, return; } + /* Check if there is a pending request associated with this node */ + if (node->busy) { + cb(user_data, MESH_ERROR_BUSY, NULL); + return; + } + /* Check if the node is already in use */ if (node->owner) { l_warn("The node is already in use"); @@ -1690,6 +1707,8 @@ void node_attach(const char *app_root, const char *sender, uint64_t token, req->attach = node; req->type = REQUEST_TYPE_ATTACH; + node->busy = true; + l_dbus_method_call(dbus_get_bus(), sender, app_root, L_DBUS_INTERFACE_OBJECT_MANAGER, "GetManagedObjects", NULL, @@ -2367,6 +2386,8 @@ void node_finalize_new_node(struct mesh_node *node, struct mesh_io *io) free_node_dbus_resources(node); mesh_agent_remove(node->agent); + node->busy = false; + /* Register callback for the node's io */ attach_io(node, io); } diff --git a/mesh/node.h b/mesh/node.h index ace1215..fcbd553 100644 --- a/mesh/node.h +++ b/mesh/node.h @@ -42,6 +42,7 @@ struct mesh_node *node_find_by_addr(uint16_t addr); 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_busy(struct mesh_node *node); 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); diff --git a/test/test-mesh b/test/test-mesh index 66055e2..bbedb6a 100755 --- a/test/test-mesh +++ b/test/test-mesh @@ -410,8 +410,6 @@ class Application(dbus.service.Object): token = value have_token = True - if attached == False: - attach(token) @dbus.service.method(MESH_APPLICATION_IFACE, in_signature="s", out_signature="")