mesh: Add MGMT bypass when specifying controller
authorBrian Gix <brian.gix@intel.com>
Thu, 31 Jan 2019 20:50:22 +0000 (12:50 -0800)
committerAnupam Roy <anupam.r@samsung.com>
Tue, 17 Dec 2019 14:02:24 +0000 (19:32 +0530)
If Daemon is started with an explicit controller specified, the
MGMT search for an unused shared controller is bypassed, and
the controller is opened directly.

Change-Id: I204b0db6ff185fade58bc9bd4d4fb6556920e22b
Signed-off-by: Anupam Roy <anupam.r@samsung.com>
mesh/mesh.c

index cfdb490..e56570c 100644 (file)
@@ -303,7 +303,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;
        }
@@ -325,12 +325,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;
 }