Diff between b52543ae3df53f9cb82a2d7b1a6509f013daa8ac and 6f0b95a2a41912ec34283008d70d8bb34550e9cc

Changed Files

File Additions Deletions Status
mesh/mesh.c +13 -7 modified

Full Patch

diff --git a/mesh/mesh.c b/mesh/mesh.c
index 881b6ed..e49653e 100644
--- a/mesh/mesh.c
+++ b/mesh/mesh.c
@@ -304,7 +304,7 @@ bool mesh_init(uint16_t index, const char *config_dir)
 	if (initialized)
 		return true;
 
-	if (!init_mgmt()) {
+	if (index == MGMT_INDEX_NONE && !init_mgmt()) {
 		l_error("Failed to initialize mesh management");
 		return false;
 	}
@@ -326,12 +326,18 @@ bool mesh_init(uint16_t index, const char *config_dir)
 	if (!storage_load_nodes(config_dir))
 		return false;
 
-	l_debug("send read index_list");
-	if (mgmt_send(mgmt_mesh, MGMT_OP_READ_INDEX_LIST,
-				MGMT_INDEX_NONE, 0, NULL,
-				read_index_list_cb, NULL, NULL) <= 0)
-		return false;
-
+	if (index == MGMT_INDEX_NONE) {
+		/* Use MGMT to find a candidate controller */
+		l_debug("send read index_list");
+		if (mgmt_send(mgmt_mesh, MGMT_OP_READ_INDEX_LIST,
+					MGMT_INDEX_NONE, 0, NULL,
+					read_index_list_cb, NULL, NULL) <= 0)
+			return false;
+	} else {
+		/* Open specified controller without searching */
+		start_io(mesh.req_index);
+		return mesh.io != NULL;
+	}
 	return true;
 }