Skip to contentSkip to conversation

mesh: Allow only one app attachment per node

PATCH New Inga Stotland 1 participant 1 message Apr 22, 2019 Bluetooth drivers

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 mesh: Allow only one app attachment per node

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

---
 doc/mesh-api.txt | 1 +
 mesh/node.c      | 8 ++++++--
 2 files changed, 7 insertions(+), 2 deletions(-)
doc/mesh-api.txt +1 -0
index f034bc900..698e7ca4e 100644
@@ -99,6 +99,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)
mesh/node.c +6 -2
index 5431a9e9c..e7016ce75 100644
@@ -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);
Signature · 1 line
2.17.2