static guint launch_timer = 0;
static guint mesh_app_ref_count;
+struct l_timeout *wait_timer;
static GSList *apps;
+static int __bt_meshd_launch()
+{
+ int ret = UNIT_CONTROL_OK;
+ BT_INFO("Mesh: Launch Meshd");
+ ret = actd_start_unit(UNIT_CONTROL_BUS_TYPE_SYSTEM,
+ MESH_SYSTEMD_SERVICE_NAME, 5000);
+
+ if (ret != UNIT_CONTROL_OK) {
+ BT_ERR("Failed to call systemact service: %d", ret);
+ return BLUETOOTH_ERROR_INTERNAL;
+ }
+ BT_INFO("Mesh: Launch Meshd successful");
+
+ return BLUETOOTH_ERROR_NONE;
+}
+
+static void __bt_meshd_terminate()
+{
+ int ret = UNIT_CONTROL_OK;
+ BT_INFO("Mesh: Stop Meshd");
+
+ ret = actd_stop_unit(UNIT_CONTROL_BUS_TYPE_SYSTEM,
+ MESH_SYSTEMD_SERVICE_NAME, 5000);
+ if (ret != UNIT_CONTROL_OK) {
+ BT_ERR("Failed to call systemact service: %d", ret);
+ return;
+ }
+
+ BT_INFO("Mesh: Meshd stop successful");
+}
+
+static void __bt_mesh_terminate()
+{
+ oal_status_t status = OAL_STATUS_SUCCESS;
+
+ /* Terminate bluetooth-meshd */
+ __bt_meshd_terminate();
+
+ /* Reset states */
+ _bt_mesh_set_scanning_state(false);
+ _bt_mesh_set_provisioning_state(false);
+
+ status = mesh_disable();
+ if (OAL_STATUS_SUCCESS != status) {
+ BT_ERR("Mesh: Failed to de-initialize Mesh profile, status: %d",
+ status);
+ return;
+ }
+
+ /* Un-Register Mesh event handler */
+ _bt_service_unregister_event_handler_callback(BT_MESH_MODULE);
+}
+
/* Event handlers */
static void __bt_mesh_handle_pending_request_info(int result,
int service_function, void *param,
/* Increase mesh app ref count */
mesh_app_ref_count++;
+ l_timeout_remove(wait_timer);
+ } else {
+ /* Init failed - Terminate bluetooth-mesh */
+ __bt_mesh_terminate();
}
out_param = g_array_new(FALSE, FALSE, sizeof(gchar));
}
}
-static int __bt_meshd_launch()
-{
- int ret = UNIT_CONTROL_OK;
- BT_INFO("Mesh: Launch Meshd");
- ret = actd_start_unit(UNIT_CONTROL_BUS_TYPE_SYSTEM,
- MESH_SYSTEMD_SERVICE_NAME, 5000);
-
- if (ret != UNIT_CONTROL_OK) {
- 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;
return FALSE;
}
+static void __bt_mesh_init_wait_response_timeout(
+ struct l_timeout *timeout, void *user_data)
+{
+ int result = BLUETOOTH_ERROR_TIMEOUT;
+
+ /* Handle DBUS Context return */
+ BT_INFO("Mesh: Handle DBUS Context return");
+ __bt_mesh_handle_pending_request_info(result,
+ BT_MESH_INIT,
+ NULL, 0);
+ l_timeout_remove(wait_timer);
+}
+
int _bt_mesh_init(const char *sender)
{
int ret = BLUETOOTH_ERROR_NONE;
launch_timer = g_timeout_add(MESH_LAUNCH_DELAY,
(GSourceFunc)__bt_mesh_launch_timer_expired_cb,
NULL);
-
BT_INFO("Mesh: Timer ID [%u]", launch_timer);
+
+ /* Add mesh init request timeout */
+ wait_timer = l_timeout_create(MESH_DEFAULT_RESPONSE_TIMEOUT,
+ __bt_mesh_init_wait_response_timeout, NULL, NULL);
+
return ret;
}
{
GSList *l = NULL;
char *owner = NULL;
- oal_status_t status = OAL_STATUS_SUCCESS;
- int ret = UNIT_CONTROL_OK;
BT_INFO("Mesh: Deinit Request from App [%s]", sender);
BT_INFO("Mesh: Total Apps available in list [%d]",
if (mesh_app_ref_count == 1) {
BT_INFO("Mesh: Only one app using Mesh Stack: Unload & reduce ref count");
- /* Reset states */
- _bt_mesh_set_scanning_state(false);
- _bt_mesh_set_provisioning_state(false);
-
- /* Terminate bluetooth-meshd */
- ret = actd_stop_unit(UNIT_CONTROL_BUS_TYPE_SYSTEM,
- MESH_SYSTEMD_SERVICE_NAME, 5000);
-
- if (ret != UNIT_CONTROL_OK)
- BT_ERR("Failed to call systemact service: %d", ret);
-
- status = mesh_disable();
- if (OAL_STATUS_SUCCESS != status) {
- BT_ERR("Mesh: Failed to de-initialize Mesh profile, status: %d",
- status);
- return BLUETOOTH_ERROR_INTERNAL;
- }
-
- /* Un-Register Mesh event handler */
- _bt_service_unregister_event_handler_callback(BT_MESH_MODULE);
+ /* Terminate bluetooth-mesh */
+ __bt_mesh_terminate();
}
/* Decrease mesh app ref count */