From 11a2146c5da78bd7a7dead1216646b4b18d5c701 Mon Sep 17 00:00:00 2001 From: DoHyun Pyun Date: Tue, 21 Jul 2020 10:18:12 +0900 Subject: [PATCH] Handle bluetooth-meshd life cycle Change-Id: I09abb6a7d647bc1462bb60eb273e7e1a0b58c254 Signed-off-by: DoHyun Pyun --- bt-api/bt-mesh.c | 29 ++++++++ bt-service/CMakeLists.txt | 2 + .../services/adapter/bt-service-core-adapter.c | 4 -- bt-service/services/bt-request-handler.c | 77 +++++++++++++--------- bt-service/services/mesh/bt-service-mesh-main.c | 21 ++++++ include/bt-internal-types.h | 4 +- 6 files changed, 100 insertions(+), 37 deletions(-) diff --git a/bt-api/bt-mesh.c b/bt-api/bt-mesh.c index 69c1c0b..de10cc3 100644 --- a/bt-api/bt-mesh.c +++ b/bt-api/bt-mesh.c @@ -38,6 +38,20 @@ BT_EXPORT_API int bluetooth_mesh_init(mesh_cb_func_ptr cb, BT_ERR("callback is NULL"); return BLUETOOTH_ERROR_INVALID_PARAM; } + + BT_INIT_PARAMS(); + BT_ALLOC_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param); + + ret = _bt_send_request(BT_BLUEZ_SERVICE, BT_MESH_INIT, + in_param1, in_param2, in_param3, in_param4, &out_param); + + BT_FREE_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param); + + if (ret != BLUETOOTH_ERROR_NONE) { + BT_ERR("Fail to init the mesh in bt-service"); + return ret; + } + ret = _bt_init_event_handler(); if (ret != BLUETOOTH_ERROR_NONE && @@ -62,9 +76,24 @@ BT_EXPORT_API int bluetooth_mesh_init(mesh_cb_func_ptr cb, BT_EXPORT_API int bluetooth_mesh_deinit(void) { + int ret; + _bt_unregister_event(BT_MESH_EVENT); _bt_set_user_data(BT_MESH, NULL, NULL); + BT_INIT_PARAMS(); + BT_ALLOC_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param); + + ret = _bt_send_request(BT_BLUEZ_SERVICE, BT_MESH_DEINIT, + in_param1, in_param2, in_param3, in_param4, &out_param); + + BT_FREE_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param); + + if (ret != BLUETOOTH_ERROR_NONE) { + BT_ERR("Fail to init the mesh in bt-service"); + return ret; + } + return BLUETOOTH_ERROR_NONE; } diff --git a/bt-service/CMakeLists.txt b/bt-service/CMakeLists.txt index 82a5f39..80848cc 100644 --- a/bt-service/CMakeLists.txt +++ b/bt-service/CMakeLists.txt @@ -101,6 +101,7 @@ SET(PKG_MODULES capi-system-info libsystemd-daemon bincfg + libactd ) ELSE() SET(PKG_MODULES @@ -118,6 +119,7 @@ SET(PKG_MODULES storage capi-system-info libsystemd-daemon + libactd ) ENDIF() diff --git a/bt-service/services/adapter/bt-service-core-adapter.c b/bt-service/services/adapter/bt-service-core-adapter.c index ecf4aca..be37d45 100644 --- a/bt-service/services/adapter/bt-service-core-adapter.c +++ b/bt-service/services/adapter/bt-service-core-adapter.c @@ -1308,10 +1308,6 @@ int _bt_init_profiles() if (ret != BLUETOOTH_ERROR_NONE) BT_ERR("_bt_audio_initialize(BT_HFP_MODULE) Failed"); - /* Mesh Init */ - ret = _bt_mesh_init(); - if (ret != BLUETOOTH_ERROR_NONE) - BT_ERR("Mesh Initialization Failed!!"); return BLUETOOTH_ERROR_NONE; } diff --git a/bt-service/services/bt-request-handler.c b/bt-service/services/bt-request-handler.c index 89cc960..7a9f62c 100644 --- a/bt-service/services/bt-request-handler.c +++ b/bt-service/services/bt-request-handler.c @@ -41,6 +41,7 @@ #include "bt-service-avrcp-tg.h" #include "bt-service-avrcp-ctrl.h" #include "bt-service-gatt.h" +#include "bt-service-mesh-main.h" #include "bt-service-mesh-util.h" #include "bt-service-mesh-network.h" #include "bt-service-mesh-config-client.h" @@ -3364,6 +3365,15 @@ normal: break; } + + case BT_MESH_INIT: + result = _bt_mesh_init(); + break; + + case BT_MESH_DEINIT: + result = _bt_mesh_deinit(); + break; + case BT_MESH_NETWORK_CREATE: { bluetooth_mesh_node_t node; GSList *model_list = NULL; @@ -4908,38 +4918,6 @@ gboolean __bt_service_check_privilege(int function_name, case BT_PBAP_PHONEBOOK_SEARCH: case BT_RFCOMM_LISTEN_AND_ACCEPT: - case BT_MESH_NETWORK_CREATE: - case BT_MESH_NETWORK_LOAD: - case BT_MESH_NETWORK_SCAN: - case BT_MESH_NETWORK_CANCEL_SCAN: - case BT_MESH_NETWORK_SET_CAPABILITIES: - case BT_MESH_NETWORK_PROVISION_DEVICE: - case BT_MESH_AUTHENTICATION_REPLY: - case BT_MESH_NETWORK_SET_NAME: - case BT_MESH_NETWORK_ADD_NETKEY: - case BT_MESH_NETWORK_DELETE_NETKEY: - case BT_MESH_NETWORK_UPDATE_NETKEY: - case BT_MESH_NETWORK_ADD_APPKEY: - case BT_MESH_NETWORK_DELETE_APPKEY: - case BT_MESH_NETWORK_UPDATE_APPKEY: - case BT_MESH_NETWORK_GET_NETKEYS: - case BT_MESH_NETWORK_GET_APPKEYS: - case BT_MESH_NETWORK_GET_NODES: - case BT_MESH_ELEMENT_GET_MODELS: - case BT_MESH_NODE_BROWSE: - case BT_MESH_NODE_GET_VENDOR_FEATURES: - case BT_MESH_NODE_CONFIGURE_KEY: - case BT_MESH_NODE_TTL_EXECUTE: - case BT_MESH_NODE_GET_NETKEYS: - case BT_MESH_NODE_GET_APPKEYS: - case BT_MESH_MODEL_CONFIGURE_APPKEY: - case BT_MESH_MODEL_GET_APPKEY_LIST: - case BT_MESH_NETWORK_CREATE_GROUP: - case BT_MESH_MODEL_CONFIG_GROUP_SUB: - case BT_MESH_MODEL_CONFIG_VIRTUAL_GROUP_SUB: - case BT_MESH_MODEL_SET_PUBLICATION: - case BT_MESH_MODEL_GET_PUBLICATION: - case BT_MESH_NETWORK_GET_GROUPS: ret_val = cynara_check(p_cynara, client_creds, client_session, user_creds, BT_PRIVILEGE_PUBLIC); @@ -5052,6 +5030,41 @@ gboolean __bt_service_check_privilege(int function_name, case BT_MAP_PUSH_MESSAGE: case BT_MAP_GET_MESSAGE: + case BT_MESH_INIT: + case BT_MESH_DEINIT: + case BT_MESH_NETWORK_CREATE: + case BT_MESH_NETWORK_LOAD: + case BT_MESH_NETWORK_SCAN: + case BT_MESH_NETWORK_CANCEL_SCAN: + case BT_MESH_NETWORK_SET_CAPABILITIES: + case BT_MESH_NETWORK_PROVISION_DEVICE: + case BT_MESH_AUTHENTICATION_REPLY: + case BT_MESH_NETWORK_SET_NAME: + case BT_MESH_NETWORK_ADD_NETKEY: + case BT_MESH_NETWORK_DELETE_NETKEY: + case BT_MESH_NETWORK_UPDATE_NETKEY: + case BT_MESH_NETWORK_ADD_APPKEY: + case BT_MESH_NETWORK_DELETE_APPKEY: + case BT_MESH_NETWORK_UPDATE_APPKEY: + case BT_MESH_NETWORK_GET_NETKEYS: + case BT_MESH_NETWORK_GET_APPKEYS: + case BT_MESH_NETWORK_GET_NODES: + case BT_MESH_ELEMENT_GET_MODELS: + case BT_MESH_NODE_BROWSE: + case BT_MESH_NODE_GET_VENDOR_FEATURES: + case BT_MESH_NODE_CONFIGURE_KEY: + case BT_MESH_NODE_TTL_EXECUTE: + case BT_MESH_NODE_GET_NETKEYS: + case BT_MESH_NODE_GET_APPKEYS: + case BT_MESH_MODEL_CONFIGURE_APPKEY: + case BT_MESH_MODEL_GET_APPKEY_LIST: + case BT_MESH_NETWORK_CREATE_GROUP: + case BT_MESH_MODEL_CONFIG_GROUP_SUB: + case BT_MESH_MODEL_CONFIG_VIRTUAL_GROUP_SUB: + case BT_MESH_MODEL_SET_PUBLICATION: + case BT_MESH_MODEL_GET_PUBLICATION: + case BT_MESH_NETWORK_GET_GROUPS: + ret_val = cynara_check(p_cynara, client_creds, client_session, user_creds, BT_PRIVILEGE_PLATFORM); diff --git a/bt-service/services/mesh/bt-service-mesh-main.c b/bt-service/services/mesh/bt-service-mesh-main.c index b7969bf..167b3ba 100644 --- a/bt-service/services/mesh/bt-service-mesh-main.c +++ b/bt-service/services/mesh/bt-service-mesh-main.c @@ -29,6 +29,7 @@ #include #include #include +#include #include "bluetooth-api.h" #include "bt-internal-types.h" @@ -44,6 +45,8 @@ #include +#define MESH_SYSTEMD_SERVICE_NAME "bluetooth-mesh.service" + /* Event handlers */ static void __bt_mesh_handle_pending_request_info(int result, int service_function, void *param, @@ -668,8 +671,18 @@ static void __handle_mesh_events(int event_type, int _bt_mesh_init(void) { + int ret = UNIT_CONTROL_OK; oal_status_t status = OAL_STATUS_SUCCESS; + /* Launch bluetooth-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; + } + status = mesh_enable(); if (OAL_STATUS_SUCCESS != status) { BT_ERR("Mesh: Failed to initialize Mesh profile, status: %d", @@ -688,6 +701,14 @@ int _bt_mesh_init(void) int _bt_mesh_deinit(void) { oal_status_t status = OAL_STATUS_SUCCESS; + int ret = UNIT_CONTROL_OK; + + /* 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) { diff --git a/include/bt-internal-types.h b/include/bt-internal-types.h index 723bd73..f8e577a 100644 --- a/include/bt-internal-types.h +++ b/include/bt-internal-types.h @@ -474,7 +474,9 @@ typedef enum { BT_LE_OTC_CONNECT, BT_LE_OTC_DISCONNECT, /* BT Mesh */ - BT_MESH_NETWORK_CREATE = BT_FUNC_MESH_BASE, + BT_MESH_INIT = BT_FUNC_MESH_BASE, + BT_MESH_DEINIT, + BT_MESH_NETWORK_CREATE, BT_MESH_NETWORK_LOAD, BT_MESH_NETWORK_SCAN, BT_MESH_NETWORK_CANCEL_SCAN, -- 2.7.4