Mesh: Add Stack event handlers 46/237446/3
authorAnupam Roy <anupam.r@samsung.com>
Sat, 27 Jun 2020 06:15:17 +0000 (11:45 +0530)
committerAnupam Roy <anupam.r@samsung.com>
Fri, 17 Jul 2020 10:37:07 +0000 (16:07 +0530)
This patch adds following
- Handles Mesh OAL events
- Completes DBUS invocation contexts
- Sends Mesh events to application

TODO:
- Handle Network Key(Subnet & Application) events
- Handle DevKey cofigruation events

Change-Id: Idda1b4c2e248c598aa82f53ec4738acde514d65a
Signed-off-by: Anupam Roy <anupam.r@samsung.com>
bt-service-adaptation/CMakeLists.txt
bt-service-adaptation/services/include/bt-service-event-receiver.h
bt-service-adaptation/services/mesh/bt-service-mesh-main.c [new file with mode: 0644]

index 6769adc..e3d5ed7 100644 (file)
@@ -35,6 +35,7 @@ SET(SRCS
 ./services/mesh/bt-service-mesh-cdb.c
 ./services/mesh/bt-service-mesh-nodes.c
 ./services/mesh/bt-service-mesh-network.c
+./services/mesh/bt-service-mesh-main.c
 )
 
 IF("$ENV{CFLAGS}" MATCHES "-DTIZEN_FEATURE_BT_OBEX")
index c4c48d5..17c8ce8 100644 (file)
@@ -46,6 +46,7 @@ typedef enum {
        BT_AVRCP_CTRL_MODULE,
        BT_ADAPTER_LE_MODULE,
        BT_GATT_MODULE,
+       BT_MESH_MODULE,
 } bt_service_module_t;
 
 void _bt_service_oal_event_receiver(int event_type, gpointer event_data, gsize len);
diff --git a/bt-service-adaptation/services/mesh/bt-service-mesh-main.c b/bt-service-adaptation/services/mesh/bt-service-mesh-main.c
new file mode 100644 (file)
index 0000000..3ba340e
--- /dev/null
@@ -0,0 +1,604 @@
+/*
+ * Bluetooth-frwk
+ *
+ * Copyright (c) 2020 Samsung Electronics Co., Ltd.
+ *
+ * @author: Anupam Roy <anupam.r@samsung.com>
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *              http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+#include <dirent.h>
+#include <ftw.h>
+#include <unistd.h>
+#include <stdio.h>
+
+#include <glib.h>
+#include <dlog.h>
+#include <limits.h>
+#include <time.h>
+#include <sys/time.h>
+#include <ell/ell.h>
+
+#include "bluetooth-api.h"
+#include "bt-internal-types.h"
+#include "bt-service-common.h"
+#include "bt-service-event.h"
+#include "bt-service-event-receiver.h"
+#include "bt-service-util.h"
+
+#include "bt-service-mesh-util.h"
+#include "bt-service-mesh-network.h"
+#include "bt-service-mesh-nodes.h"
+//#include "bt-service-mesh-config-client.h"
+
+#include <oal-mesh.h>
+
+/* Event handlers */
+static void __bt_mesh_handle_pending_request_info(int result,
+               int service_function, void *param,
+                       unsigned int size)
+{
+       GSList *l;
+       GArray *out_param;
+       invocation_info_t *req_info = NULL;
+
+       for (l = _bt_get_invocation_list(); l != NULL; ) {
+               req_info = l->data;
+               l = g_slist_next(l);
+               if (req_info == NULL ||
+                       req_info->service_function != service_function)
+                       continue;
+
+               switch (service_function) {
+               case BT_MESH_NETWORK_CREATE: {
+                       char uuid_str[BLUETOOTH_MESH_NETWORK_UUID_STRING_LENGTH + 1];
+                       bluetooth_mesh_node_t *node;
+                       bluetooth_mesh_network_t *network;
+                       ret_if(param == NULL);
+                       BT_INFO("Mesh: Request: BT_MESH_NETWORK_CREATE Sender: [%s] result[%d]",
+                                       req_info->sender, result);
+
+                       node = (bluetooth_mesh_node_t*) param;
+                       network = (bluetooth_mesh_network_t*)req_info->user_data;
+
+                       _bt_mesh_util_convert_hex_to_string(
+                               (uint8_t *) node->uuid, 16, uuid_str,
+                                       BLUETOOTH_MESH_NETWORK_UUID_STRING_LENGTH + 1);
+
+                       BT_INFO("Mesh: Network UUID from event [%s] Netw UUID from req [%s]",
+                                       uuid_str, network->uuid);
+
+                       if (!g_strcmp0(network->uuid, uuid_str)) {
+                               BT_INFO("Mesh: BT_MESH_NETWORK_CREATE Request found uuid [%s]",
+                                       network->uuid);
+                               if (BLUETOOTH_ERROR_NONE != _bt_mesh_network_create_cdb(
+                                       result, req_info->sender,
+                                       network->app_cred, node->uuid,
+                                               node->token.u8, network->name.name)) {
+                                       result = BLUETOOTH_ERROR_INTERNAL;
+                                       BT_ERR("!!Mesh: BT_MESH_NETWORK_CREATE Failed!!");
+                               }
+
+                               _bt_mesh_util_convert_hex_to_string(
+                                       (uint8_t *) node->token.u8, 8,
+                                               network->token.token,
+                                               BLUETOOTH_MESH_NETWORK_TOKEN_STRING_LENGTH + 1);
+
+                               out_param = g_array_new(FALSE, FALSE, sizeof(gchar));
+                               g_array_append_vals(out_param, network,
+                                       sizeof(bluetooth_mesh_network_t));
+                               _bt_service_method_return(req_info->context,
+                                       out_param, result);
+                               _bt_free_info_from_invocation_list(req_info);
+                               g_free(req_info->user_data);
+                               g_array_free(out_param, TRUE);
+                       }
+                       break;
+               }
+               case BT_MESH_NETWORK_LOAD: {
+                       char token_str[BLUETOOTH_MESH_NETWORK_TOKEN_STRING_LENGTH + 1];
+                       bluetooth_mesh_node_t *node;
+                       bluetooth_mesh_network_t *network;
+                       ret_if(param == NULL);
+                       BT_INFO("Mesh: Request: BT_MESH_NETWORK_LOAD Sender: [%s]",
+                               req_info->sender);
+
+                       node = (bluetooth_mesh_node_t*) param;
+                       network = (bluetooth_mesh_network_t*)req_info->user_data;
+
+                       _bt_mesh_util_convert_hex_to_string(
+                               (uint8_t *) node->token.u8, 8, token_str,
+                                       BLUETOOTH_MESH_NETWORK_TOKEN_STRING_LENGTH + 1);
+
+                       if (!g_strcmp0(network->token.token, token_str)) {
+
+                               BT_INFO("Mesh: BT_MESH_NETWORK_LOAD Request found Token [%s]",
+                                       token_str);
+
+                               /* TODO: Handle Meh Network Load CDB */
+                               /* Send request to mesh-network to load keys and Nodes for the network */
+                       }
+                       break;
+               }
+               case BT_MESH_NETWORK_SCAN: {
+                       bluetooth_mesh_network_t *network;
+                       event_mesh_scan_status_t *event;
+                       char net_uuid[BLUETOOTH_MESH_NETWORK_UUID_STRING_LENGTH + 1];
+
+                       event = (event_mesh_scan_status_t*) param;
+                       network = (bluetooth_mesh_network_t*)req_info->user_data;
+                       _bt_mesh_util_convert_hex_to_string(
+                               (uint8_t *) event->net_uuid.uuid, 16, net_uuid,
+                               BLUETOOTH_MESH_NETWORK_UUID_STRING_LENGTH + 1);
+
+                       BT_DBG("Request Sender: [%s]", req_info->sender);
+                       if (!g_strcmp0(network->uuid, net_uuid)) {
+                               out_param = g_array_new(FALSE, FALSE, sizeof(gchar));
+                               g_array_append_vals(out_param,
+                                       network, sizeof(bluetooth_mesh_network_t));
+                               _bt_service_method_return(req_info->context,
+                                       out_param, result);
+                               _bt_free_info_from_invocation_list(req_info);
+                               g_free(req_info->user_data);
+                               g_array_free(out_param, TRUE);
+                       }
+                       break;
+               }
+               case BT_MESH_NETWORK_PROVISION_DEVICE: {
+                       bluetooth_mesh_provisioning_request_t *req_data;
+                       bluetooth_mesh_provisioning_request_t status_data;
+                       event_mesh_provisioning_status_t *event;
+                       memset(&status_data,
+                               0x00, sizeof(bluetooth_mesh_provisioning_request_t));
+
+                       event = (event_mesh_provisioning_status_t*) param;
+                       req_data = (bluetooth_mesh_provisioning_request_t*) req_info->user_data;
+
+                       _bt_mesh_util_convert_hex_to_string(
+                               (uint8_t *) event->net_uuid.uuid, 16, status_data.net_uuid,
+                                       BLUETOOTH_MESH_NETWORK_UUID_STRING_LENGTH + 1);
+
+                       _bt_mesh_util_convert_hex_to_string(
+                               (uint8_t *) event->dev_uuid.uuid, 16, status_data.dev_uuid,
+                                       BLUETOOTH_MESH_NETWORK_UUID_STRING_LENGTH + 1);
+
+                       BT_DBG("Request Sender: [%s]", req_info->sender);
+                       if (!g_strcmp0(req_data->net_uuid, status_data.net_uuid)) {
+                               out_param = g_array_new(FALSE, FALSE, sizeof(gchar));
+                               g_array_append_vals(out_param, &status_data,
+                                       sizeof(bluetooth_mesh_provisioning_request_t));
+                               _bt_service_method_return(req_info->context, out_param, result);
+                               _bt_free_info_from_invocation_list(req_info);
+                               g_free(req_info->user_data);
+                               g_array_free(out_param, TRUE);
+                       }
+                       break;
+               }
+               /* Fall through */
+               case BT_MESH_NETWORK_DELETE_NETKEY:
+               case BT_MESH_NETWORK_UPDATE_NETKEY:
+               case BT_MESH_NETWORK_ADD_NETKEY: {
+                       bluetooth_mesh_network_t *network;
+                       event_mesh_netkey_operation_t *event;
+                       char net_uuid[BLUETOOTH_MESH_NETWORK_UUID_STRING_LENGTH + 1];
+
+                       event = (event_mesh_netkey_operation_t*) param;
+                       network = (bluetooth_mesh_network_t*)req_info->user_data;
+                       _bt_mesh_util_convert_hex_to_string(
+                               (uint8_t *) event->net_uuid.uuid, 16, net_uuid,
+                                       BLUETOOTH_MESH_NETWORK_UUID_STRING_LENGTH + 1);
+
+                       BT_DBG("Request Sender: [%s]", req_info->sender);
+                       if (!g_strcmp0(network->uuid, net_uuid)) {
+                               out_param = g_array_new(FALSE, FALSE, sizeof(gchar));
+                               g_array_append_vals(out_param, &event->key_idx, sizeof(guint16));
+                               _bt_service_method_return(req_info->context, out_param, result);
+                               _bt_free_info_from_invocation_list(req_info);
+                               g_free(req_info->user_data);
+                               g_array_free(out_param, TRUE);
+                       }
+                       break;
+               }
+               /* Fall through */
+               case BT_MESH_NETWORK_DELETE_APPKEY:
+               case BT_MESH_NETWORK_UPDATE_APPKEY:
+               case BT_MESH_NETWORK_ADD_APPKEY: {
+                       bluetooth_mesh_network_t *network;
+                       event_mesh_appkey_operation_t *event;
+                       char net_uuid[BLUETOOTH_MESH_NETWORK_UUID_STRING_LENGTH + 1];
+
+                       event = (event_mesh_appkey_operation_t*) param;
+                       network = (bluetooth_mesh_network_t*)req_info->user_data;
+                       _bt_mesh_util_convert_hex_to_string(
+                               (uint8_t *) event->net_uuid.uuid, 16, net_uuid,
+                                       BLUETOOTH_MESH_NETWORK_UUID_STRING_LENGTH + 1);
+
+                       BT_DBG("Request Sender: [%s]", req_info->sender);
+                       if (!g_strcmp0(network->uuid, net_uuid)) {
+                               out_param = g_array_new(FALSE, FALSE, sizeof(gchar));
+                               g_array_append_vals(out_param,
+                                       &event->app_idx, sizeof(guint16));
+                               _bt_service_method_return(req_info->context, out_param, result);
+                               _bt_free_info_from_invocation_list(req_info);
+                               g_free(req_info->user_data);
+                               g_array_free(out_param, TRUE);
+                       }
+                       break;
+               }
+               default:
+                       BT_DBG("Unknown function(%d)", service_function);
+                       break;
+               }
+       }
+}
+
+static void  __handle_mesh_devkey_message_received_event(
+               event_mesh_devkey_message_t *event)
+{
+       /* TODO Handle Devkey message Handler */
+}
+
+static void __handle_mesh_network_attached_event(
+               event_mesh_network_attached_t *event)
+{
+       int result = BLUETOOTH_ERROR_NONE;
+       bluetooth_mesh_node_t node;
+
+       if (event->status != OAL_STATUS_SUCCESS)
+               result = BLUETOOTH_ERROR_INTERNAL;
+
+       memset(&node, 0x00, sizeof(bluetooth_mesh_node_t));
+
+       memcpy(node.uuid, event->uuid.uuid, 16);
+       memcpy(node.token.u8, event->token, 8);
+
+       __bt_mesh_handle_pending_request_info(result,
+                       BT_MESH_NETWORK_CREATE,
+                       &node, sizeof(bluetooth_mesh_node_t));
+       __bt_mesh_handle_pending_request_info(result,
+                       BT_MESH_NETWORK_LOAD,
+                       &node, sizeof(bluetooth_mesh_node_t));
+}
+
+static void __handle_mesh_network_scan_started_event(
+       event_mesh_scan_status_t *event)
+{
+       GVariant *out_var = NULL, *param = NULL;
+       GArray *info = NULL;
+       bluetooth_mesh_network_t network;
+
+       int result = BLUETOOTH_ERROR_NONE;
+       if (event->status != OAL_STATUS_SUCCESS) {
+               result = BLUETOOTH_ERROR_INTERNAL;
+               _bt_mesh_set_scanning_state(false);
+       } else
+               _bt_mesh_set_scanning_state(true);
+
+       /* Handle DBUS Context return */
+       __bt_mesh_handle_pending_request_info(result,
+                       BT_MESH_NETWORK_SCAN,
+                       event, sizeof(event_mesh_scan_status_t));
+
+       /* Handle Scan started event */
+       if (result == BLUETOOTH_ERROR_NONE) {
+               memset(&network, 0x00, sizeof(bluetooth_mesh_network_t));
+               _bt_mesh_util_convert_hex_to_string(
+                       (uint8_t *) event->net_uuid.uuid, 16, network.uuid,
+                       BLUETOOTH_MESH_NETWORK_UUID_STRING_LENGTH + 1);
+
+               info = g_array_new(FALSE, FALSE, sizeof(gchar));
+               g_array_append_vals(info, &network,
+                       sizeof(bluetooth_mesh_network_t));
+
+               out_var = g_variant_new_from_data((const GVariantType *)"ay",
+                       info->data, info->len,
+                       TRUE, NULL, NULL);
+
+               param = g_variant_new("(iv)", result, out_var);
+               _bt_send_event(BT_MESH_EVENT,
+                       BLUETOOTH_EVENT_MESH_SCAN_STARTED,
+                       param);
+       }
+}
+
+static void __handle_mesh_network_scan_finished_event(
+       event_mesh_scan_status_t *event)
+{
+       GVariant *out_var = NULL, *param = NULL;
+       GArray *info = NULL;
+       bluetooth_mesh_network_t network;
+
+       int result = BLUETOOTH_ERROR_NONE;
+       if (event->status != OAL_STATUS_SUCCESS)
+               result = BLUETOOTH_ERROR_INTERNAL;
+
+
+       /* Handle Scan finsihed event */
+       if (result == BLUETOOTH_ERROR_NONE) {
+               memset(&network, 0x00, sizeof(bluetooth_mesh_network_t));
+               _bt_mesh_util_convert_hex_to_string(
+                       (uint8_t *) event->net_uuid.uuid, 16, network.uuid,
+                       BLUETOOTH_MESH_NETWORK_UUID_STRING_LENGTH + 1);
+
+               info = g_array_new(FALSE, FALSE, sizeof(gchar));
+               g_array_append_vals(info, &network,
+                       sizeof(bluetooth_mesh_network_t));
+
+               out_var = g_variant_new_from_data((const GVariantType *)"ay",
+                       info->data, info->len,
+                       TRUE, NULL, NULL);
+
+               param = g_variant_new("(iv)", result, out_var);
+               _bt_send_event(BT_MESH_EVENT,
+                       BLUETOOTH_EVENT_MESH_SCAN_FINISHED,
+                       param);
+               _bt_mesh_set_scanning_state(false);
+       }
+}
+
+static void __handle_mesh_network_provisioning_started_event(
+               event_mesh_provisioning_status_t *status)
+{
+       int result = BLUETOOTH_ERROR_NONE;
+
+       __bt_mesh_handle_pending_request_info(result,
+                       BT_MESH_NETWORK_PROVISION_DEVICE,
+                       status, sizeof(event_mesh_scan_status_t));
+
+       _bt_mesh_set_provisioning_state(true);
+}
+
+static void __handle_mesh_network_provisioning_failed_event(
+               event_mesh_provisioning_status_t *status)
+{
+       int result = BLUETOOTH_ERROR_INTERNAL;
+
+       __bt_mesh_handle_pending_request_info(result,
+                       BT_MESH_NETWORK_PROVISION_DEVICE,
+                       status, sizeof(event_mesh_scan_status_t));
+
+       _bt_mesh_set_provisioning_state(false);
+}
+
+static void __handle_mesh_network_provisioning_finished_event(
+               event_mesh_provisioning_finished_t *event)
+{
+       GVariant *out_var = NULL, *param = NULL;
+       GArray *info = NULL;
+       bluetooth_mesh_provisioning_result_t prov_result;
+
+       memset(&prov_result, 0x00,
+                       sizeof(bluetooth_mesh_provisioning_result_t));
+
+       if (event->status != OAL_STATUS_SUCCESS)
+               prov_result.result = BLUETOOTH_ERROR_INTERNAL;
+       prov_result.result = BLUETOOTH_ERROR_NONE;
+
+       prov_result.reason = event->reason;
+       prov_result.unicast = event->unicast;
+       prov_result.count = event->count;
+
+       _bt_mesh_util_convert_hex_to_string(
+                       (uint8_t *) event->net_uuid.uuid, 16, prov_result.net_uuid,
+                       BLUETOOTH_MESH_NETWORK_UUID_STRING_LENGTH + 1);
+
+       _bt_mesh_util_convert_hex_to_string(
+                       (uint8_t *) event->dev_uuid.uuid, 16, prov_result.dev_uuid,
+                       BLUETOOTH_MESH_NETWORK_UUID_STRING_LENGTH + 1);
+
+       info = g_array_new(FALSE, FALSE, sizeof(gchar));
+       g_array_append_vals(info, &prov_result,
+                       sizeof(bluetooth_mesh_provisioning_result_t));
+
+       out_var = g_variant_new_from_data((const GVariantType *)"ay",
+                       info->data, info->len,
+                       TRUE, NULL, NULL);
+
+       param = g_variant_new("(iv)", prov_result.result, out_var);
+       _bt_send_event(BT_MESH_EVENT,
+                       BLUETOOTH_EVENT_MESH_PROVISIONING_FINISHED,
+                       param);
+
+       /* TODO Add newly provisioned Node info in Node Manager */
+       /* Add Remote Node entry in Local CDB */
+}
+
+static void __handle_mesh_network_provisioning_data_requested_event(
+       event_mesh_provisioning_data_requested_t *event)
+{
+       _bt_mesh_network_request_provisioning_data_request(
+                       event->net_uuid.uuid, event->count);
+}
+
+static void __handle_mesh_network_authentication_requested_event(
+               event_mesh_authentication_requested_t *event)
+{
+       GVariant *out_var = NULL, *param = NULL;
+       GArray *info = NULL;
+       bluetooth_mesh_authentication_request_t auth_req;
+
+       memset(&auth_req, 0x00,
+                       sizeof(bluetooth_mesh_authentication_request_t));
+
+       auth_req.auth_type = event->auth_type;
+       g_strlcpy(auth_req.auth_value, event->auth_value,
+                       sizeof(auth_req.auth_value));
+
+       _bt_mesh_util_convert_hex_to_string(
+                       (uint8_t *) event->net_uuid.uuid, 16, auth_req.net_uuid,
+                       BLUETOOTH_MESH_NETWORK_UUID_STRING_LENGTH + 1);
+
+       info = g_array_new(FALSE, FALSE, sizeof(gchar));
+       g_array_append_vals(info, &auth_req,
+                       sizeof(bluetooth_mesh_authentication_request_t));
+
+       out_var = g_variant_new_from_data((const GVariantType *)"ay",
+                       info->data, info->len,
+                       TRUE, NULL, NULL);
+
+       param = g_variant_new("(iv)", BLUETOOTH_ERROR_NONE, out_var);
+       _bt_send_event(BT_MESH_EVENT,
+                       BLUETOOTH_EVENT_MESH_AUTHENTICATION_REQUEST,
+                       param);
+}
+
+static void __handle_mesh_network_scan_result_event(
+               event_mesh_scan_result_t *event)
+{
+       GVariant *out_var = NULL, *param = NULL;
+       GArray *info = NULL;
+       bluetooth_mesh_scan_result_t data;
+       int result = BLUETOOTH_ERROR_NONE;
+
+       memset(&data, 0x00, sizeof(bluetooth_mesh_scan_result_t));
+
+       /* Fill Network UUID */
+       _bt_mesh_util_convert_hex_to_string(
+               (uint8_t *) event->net_uuid.uuid, 16, data.net_uuid,
+                       BLUETOOTH_MESH_NETWORK_UUID_STRING_LENGTH + 1);
+
+       /* Fill Device UUID */
+       _bt_mesh_util_convert_hex_to_string(
+               (uint8_t *) event->result.dev_uuid.uuid, 16, data.dev_uuid,
+                       BLUETOOTH_MESH_NETWORK_UUID_STRING_LENGTH + 1);
+
+       /* Fill RSSI */
+       data.rssi = event->result.rssi;
+
+       /* Fill OOB Info */
+       memcpy(&data.oob_info, event->result.oob_info, 2);
+
+       /* Fill URI Hash Info */
+       memcpy(&data.uri_hash, event->result.uri_hash, 4);
+
+       if (event->status != OAL_STATUS_SUCCESS)
+               result = BLUETOOTH_ERROR_INTERNAL;
+
+       /* Fill Data */
+       info = g_array_new(FALSE, FALSE, sizeof(gchar));
+       g_array_append_vals(info, &data,
+               sizeof(bluetooth_mesh_scan_result_t));
+
+       out_var = g_variant_new_from_data((const GVariantType *)"ay",
+                       info->data, info->len,
+                       TRUE, NULL, NULL);
+
+       param = g_variant_new("(iv)", result, out_var);
+       _bt_send_event(BT_MESH_EVENT,
+                       BLUETOOTH_EVENT_MESH_SCAN_RESULT,
+                       param);
+}
+
+static void __handle_mesh_events(int event_type,
+               gpointer event_data)
+{
+       switch (event_type) {
+       case OAL_EVENT_MESH_NETWORK_ATTACHED:
+               __handle_mesh_network_attached_event(
+                       (event_mesh_network_attached_t*)event_data);
+               BT_PERMANENT_LOG("Mesh: Network attached!!");
+               break;
+       case OAL_EVENT_MESH_SCAN_STARTED:
+               __handle_mesh_network_scan_started_event(
+                       (event_mesh_scan_status_t*)event_data);
+               BT_PERMANENT_LOG("Mesh: Network Scan Stated!!");
+               break;
+       case OAL_EVENT_MESH_SCAN_FINISHED:
+               __handle_mesh_network_scan_finished_event(
+                       (event_mesh_scan_status_t*)event_data);
+               BT_PERMANENT_LOG("Mesh: Network Scan Finished!!");
+               break;
+       case OAL_EVENT_MESH_SCAN_RESULT:
+               __handle_mesh_network_scan_result_event(
+                       (event_mesh_scan_result_t*)event_data);
+               BT_PERMANENT_LOG("Mesh: Network Scan Result!!");
+               break;
+       case OAL_EVENT_MESH_PROVISIONING_STARTED:
+               __handle_mesh_network_provisioning_started_event(
+                       (event_mesh_provisioning_status_t*)event_data);
+               BT_PERMANENT_LOG("Mesh: Network Provisioning Started");
+       break;
+       case OAL_EVENT_MESH_PROVISIONING_FAILED:
+               __handle_mesh_network_provisioning_failed_event(
+                       (event_mesh_provisioning_status_t*)event_data);
+               BT_PERMANENT_LOG("Mesh: Network Provisioning Failed");
+               break;
+       case OAL_EVENT_MESH_PROVISIONING_FINISHED:
+               __handle_mesh_network_provisioning_finished_event(
+                       (event_mesh_provisioning_finished_t*)event_data);
+               BT_PERMANENT_LOG("Mesh: Network Provisioning Finished");
+               break;
+       case OAL_EVENT_MESH_PROVISIONING_DATA_REQUESTED:
+               __handle_mesh_network_provisioning_data_requested_event(
+                       (event_mesh_provisioning_data_requested_t*)event_data);
+               BT_PERMANENT_LOG("Mesh: Network Provisioning Data Requested");
+               break;
+       case OAL_EVENT_MESH_AUTHENTICATION_REQUESTED:
+               __handle_mesh_network_authentication_requested_event(
+                       (event_mesh_authentication_requested_t*)event_data);
+               BT_PERMANENT_LOG("Mesh: Network Authentication Requested");
+               break;
+       case OAL_EVENT_MESH_NETKEY_EXECUTE_EVENT:
+               /* TODO: Handle Netkey key DBUS Handler & event */
+               BT_PERMANENT_LOG("Mesh: Network Subnet operation event");
+               break;
+       case OAL_EVENT_MESH_APPKEY_EXECUTE_EVENT:
+               /* TODO: Handle Netkey key DBUS Handler & event */
+               BT_PERMANENT_LOG("Mesh: AppKey operation event");
+               break;
+       case OAL_EVENT_MESH_DEVKEY_MESSAGE_RECEIVED:
+               __handle_mesh_devkey_message_received_event(
+                       (event_mesh_devkey_message_t*)event_data);
+               BT_PERMANENT_LOG("Mesh: DevKey Message Received event");
+               break;
+       default:
+       break;
+       }
+}
+
+int _bt_mesh_init(void)
+{
+       oal_status_t status = OAL_STATUS_SUCCESS;
+
+       status = mesh_enable();
+       if (OAL_STATUS_SUCCESS != status) {
+               BT_ERR("Mesh: Failed to initialize Mesh profile, status: %d",
+                               status);
+               return BLUETOOTH_ERROR_INTERNAL;
+       }
+       BT_INFO("Mesh: Stack Initialization Done successfully");
+
+       /* Register MESH event handler */
+       _bt_service_register_event_handler_callback(BT_MESH_MODULE,
+                       __handle_mesh_events);
+
+       return BLUETOOTH_ERROR_NONE;
+}
+
+int _bt_mesh_deinit(void)
+{
+       oal_status_t status = OAL_STATUS_SUCCESS;
+
+       status = mesh_disable();
+       if (OAL_STATUS_SUCCESS != status) {
+               BT_ERR("Mesh: Failed to de-initialize Mesh profile, status: %d",
+                               status);
+               return BLUETOOTH_ERROR_INTERNAL;
+       }
+
+       /* Register AVRCP target event handler */
+       _bt_service_unregister_event_handler_callback(BT_MESH_MODULE);
+
+       return BLUETOOTH_ERROR_NONE;
+}