From ef47a144e7dc56b221304a379e5da94952b35fed Mon Sep 17 00:00:00 2001 From: Abhay Agarwal Date: Mon, 10 Aug 2020 18:37:25 +0530 Subject: [PATCH] Mesh: Fix network proxy issue This patch fix an issue of proxy added callback not being called for network interface due to simultaeneous operations to register proxy callback and to launch bluetooth-meshd. Change-Id: Ibab370d9200ba3563e09f5396c4e0e3434a532ed Signed-off-by: Abhay Agarwal --- bt-service/services/bt-request-handler.c | 9 ++++ bt-service/services/mesh/bt-service-mesh-main.c | 68 +++++++++++++++++++++++-- 2 files changed, 72 insertions(+), 5 deletions(-) diff --git a/bt-service/services/bt-request-handler.c b/bt-service/services/bt-request-handler.c index 8ac2903..8e17a47 100644 --- a/bt-service/services/bt-request-handler.c +++ b/bt-service/services/bt-request-handler.c @@ -228,6 +228,7 @@ static gboolean __bt_is_sync_function(int service_function) || service_function == BT_GATT_ACQUIRE_WRITE || service_function == BT_AUDIO_SELECT_ROLE /* Mesh API's */ + || service_function == BT_MESH_INIT || service_function == BT_MESH_NETWORK_CREATE || service_function == BT_MESH_NETWORK_DESTROY || service_function == BT_MESH_NETWORK_LOAD @@ -3356,6 +3357,14 @@ normal: case BT_MESH_INIT: result = _bt_mesh_init(); + /* Save invocation */ + if (result == BLUETOOTH_ERROR_NONE) { + BT_INFO("Mesh: Save Invoation"); + sender = (char*)g_dbus_method_invocation_get_sender(context); + _bt_save_invocation_context(context, + result, sender, + function_name, NULL); + } break; case BT_MESH_DEINIT: diff --git a/bt-service/services/mesh/bt-service-mesh-main.c b/bt-service/services/mesh/bt-service-mesh-main.c index f3dc1e5..a5313c5 100644 --- a/bt-service/services/mesh/bt-service-mesh-main.c +++ b/bt-service/services/mesh/bt-service-mesh-main.c @@ -47,6 +47,9 @@ #include #define MESH_SYSTEMD_SERVICE_NAME "bluetooth-mesh.service" +#define MESH_LAUNCH_DELAY 500 + +static guint launch_timer = 0; /* Event handlers */ static void __bt_mesh_handle_pending_request_info(int result, @@ -65,6 +68,15 @@ static void __bt_mesh_handle_pending_request_info(int result, continue; switch (service_function) { + case BT_MESH_INIT: { + BT_INFO("Mesh: Request: BT_MESH_INIT Sender: [%s] result[%d]", + req_info->sender, result); + out_param = g_array_new(FALSE, FALSE, sizeof(gchar)); + _bt_service_method_return(req_info->context, + out_param, result); + _bt_free_info_from_invocation_list(req_info); + break; + } case BT_MESH_NETWORK_CREATE: { char uuid_str[BLUETOOTH_MESH_NETWORK_UUID_STRING_LENGTH + 1]; bluetooth_mesh_node_t *node; @@ -742,12 +754,10 @@ static void __handle_mesh_events(int event_type, } } -int _bt_mesh_init(void) +static int __bt_meshd_launch() { int ret = UNIT_CONTROL_OK; - oal_status_t status = OAL_STATUS_SUCCESS; - - /* Launch bluetooth-meshd */ + BT_INFO("Mesh: Launch Meshd"); ret = actd_start_unit(UNIT_CONTROL_BUS_TYPE_SYSTEM, MESH_SYSTEMD_SERVICE_NAME, 5000); @@ -755,10 +765,18 @@ int _bt_mesh_init(void) BT_ERR("Failed to call systemact service: %d", ret); return BLUETOOTH_ERROR_INTERNAL; } + BT_INFO("Mesh: Launch Meshd successful"); + return BLUETOOTH_ERROR_NONE; +} + +static int __bt_mesh_enable() +{ + oal_status_t status = OAL_STATUS_SUCCESS; + BT_INFO("Mesh: Set dbus callbacks"); status = mesh_enable(); if (OAL_STATUS_SUCCESS != status) { - BT_ERR("Mesh: Failed to initialize Mesh profile, status: %d", + BT_ERR("Mesh: Failed to enable mesh interface, status: %d", status); return BLUETOOTH_ERROR_INTERNAL; } @@ -771,6 +789,46 @@ int _bt_mesh_init(void) return BLUETOOTH_ERROR_NONE; } +static gboolean __bt_mesh_launch_timer_expired_cb(gpointer data) +{ + BT_INFO("Mesh: Enable Mesh dbus"); + int ret = BLUETOOTH_ERROR_NONE; + ret = __bt_mesh_enable(); + if (BLUETOOTH_ERROR_NONE != ret) + BT_ERR("Mesh: Mesh enable failed: %d", ret); + + /* Handle DBUS Context return */ + BT_INFO("Mesh: Handle DBUS Context return"); + __bt_mesh_handle_pending_request_info(ret, + BT_MESH_INIT, + NULL, 0); + return FALSE; +} + +int _bt_mesh_init(void) +{ + int ret = BLUETOOTH_ERROR_NONE; + + if (launch_timer > 0) { + BT_INFO("Mesh: BT_MESH_INIT in progress"); + return ret; + } + + /* Launch bluetooth-meshd */ + ret = __bt_meshd_launch(); + if (BLUETOOTH_ERROR_NONE != ret) { + BT_ERR("Mesh: Meshd launch failed: %d", ret); + return ret; + } + + /* wait for half a second*/ + launch_timer = g_timeout_add(MESH_LAUNCH_DELAY, + (GSourceFunc)__bt_mesh_launch_timer_expired_cb, + NULL); + + return ret; +} + int _bt_mesh_deinit(void) { oal_status_t status = OAL_STATUS_SUCCESS; -- 2.7.4