mesh: Allow only one app attachment per node
authorInga Stotland <inga.stotland@intel.com>
Mon, 22 Apr 2019 04:51:11 +0000 (21:51 -0700)
committerAnupam Roy <anupam.r@samsung.com>
Tue, 17 Dec 2019 14:19:23 +0000 (19:49 +0530)
If a node is already attached to an application process,
disallow another appication to attach to the same node.
This means that an Attach() method called with the token
identifying a node that is already in use, returns an error
org.bluez.mesh.Error.AlreadyExists

Change-Id: Ifde6a2c13ed5d0c044086c58bbb5013fe9f8eb59
Signed-off-by: Anupam Roy <anupam.r@samsung.com>
doc/mesh-api.txt
mesh/node.c

index 0b341a0..0fc0896 100644 (file)
@@ -98,6 +98,7 @@ Methods:
                PossibleErrors:
                        org.bluez.mesh.Error.InvalidArguments
                        org.bluez.mesh.Error.NotFound,
+                       org.bluez.mesh.Error.AlreadyExists,
                        org.bluez.mesh.Error.Failed
 
        void Leave(uint64 token)
index dae9a4b..820aeb4 100644 (file)
@@ -1146,9 +1146,13 @@ int node_attach(const char *app_path, const char *sender, uint64_t token,
        if (!node)
                return MESH_ERROR_NOT_FOUND;
 
-       /* TODO: decide what to do if previous node->app_path is not NULL */
-       node->app_path = l_strdup(app_path);
+       /* Check if the node is already in use */
+       if (node->owner) {
+               l_warn("The node is already in use");
+               return MESH_ERROR_ALREADY_EXISTS;
+       }
 
+       node->app_path = l_strdup(app_path);
        node->owner = l_strdup(sender);
 
        req = l_new(struct attach_obj_request, 1);