4 * Copyright (c) 2020 Samsung Electronics Co., Ltd.
6 * @author: Anupam Roy <anupam.r@samsung.com>
8 * Licensed under the Apache License, Version 2.0 (the "License");
9 * you may not use this file except in compliance with the License.
10 * You may obtain a copy of the License at
12 * http://www.apache.org/licenses/LICENSE-2.0
14 * Unless required by applicable law or agreed to in writing, software
15 * distributed under the License is distributed on an "AS IS" BASIS,
16 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 * See the License for the specific language governing permissions and
18 * limitations under the License.
33 #include "bluetooth-api.h"
34 #include "bt-internal-types.h"
35 #include "bt-service-common.h"
36 #include "bt-service-event.h"
37 #include "bt-service-event-receiver.h"
38 #include "bt-service-util.h"
40 #include "bt-service-mesh-util.h"
41 #include "bt-service-mesh-network.h"
42 #include "bt-service-mesh-nodes.h"
43 #include "bt-service-mesh-config-client.h"
48 static void __bt_mesh_handle_pending_request_info(int result,
49 int service_function, void *param,
54 invocation_info_t *req_info = NULL;
56 for (l = _bt_get_invocation_list(); l != NULL; ) {
59 if (req_info == NULL ||
60 req_info->service_function != service_function)
63 switch (service_function) {
64 case BT_MESH_NETWORK_CREATE: {
65 char uuid_str[BLUETOOTH_MESH_NETWORK_UUID_STRING_LENGTH + 1];
66 bluetooth_mesh_node_t *node;
67 bluetooth_mesh_network_t *network;
68 ret_if(param == NULL);
69 BT_INFO("Mesh: Request: BT_MESH_NETWORK_CREATE Sender: [%s] result[%d]",
70 req_info->sender, result);
72 node = (bluetooth_mesh_node_t*) param;
73 network = (bluetooth_mesh_network_t*)req_info->user_data;
75 _bt_mesh_util_convert_hex_to_string(
76 (uint8_t *) node->uuid, 16, uuid_str,
77 BLUETOOTH_MESH_NETWORK_UUID_STRING_LENGTH + 1);
79 BT_INFO("Mesh: Network UUID from event [%s] Netw UUID from req [%s]",
80 uuid_str, network->uuid);
82 if (!g_strcmp0(network->uuid, uuid_str)) {
83 BT_INFO("Mesh: BT_MESH_NETWORK_CREATE Request found uuid [%s]",
85 if (BLUETOOTH_ERROR_NONE != _bt_mesh_network_create_cdb(
86 result, req_info->sender,
87 network->app_cred, node->uuid,
88 node->token.u8, network->name.name)) {
89 result = BLUETOOTH_ERROR_INTERNAL;
90 BT_ERR("!!Mesh: BT_MESH_NETWORK_CREATE Failed!!");
93 _bt_mesh_util_convert_hex_to_string(
94 (uint8_t *) node->token.u8, 8,
96 BLUETOOTH_MESH_NETWORK_TOKEN_STRING_LENGTH + 1);
98 out_param = g_array_new(FALSE, FALSE, sizeof(gchar));
99 g_array_append_vals(out_param, network,
100 sizeof(bluetooth_mesh_network_t));
101 _bt_service_method_return(req_info->context,
103 _bt_free_info_from_invocation_list(req_info);
104 g_free(req_info->user_data);
105 g_array_free(out_param, TRUE);
109 case BT_MESH_NETWORK_LOAD: {
110 char token_str[BLUETOOTH_MESH_NETWORK_TOKEN_STRING_LENGTH + 1];
111 bluetooth_mesh_node_t *node;
112 bluetooth_mesh_network_t *network;
113 ret_if(param == NULL);
114 BT_INFO("Mesh: Request: BT_MESH_NETWORK_LOAD Sender: [%s]",
117 node = (bluetooth_mesh_node_t*) param;
118 network = (bluetooth_mesh_network_t*)req_info->user_data;
120 _bt_mesh_util_convert_hex_to_string(
121 (uint8_t *) node->token.u8, 8, token_str,
122 BLUETOOTH_MESH_NETWORK_TOKEN_STRING_LENGTH + 1);
124 if (!g_strcmp0(network->token.token, token_str)) {
125 char *network_name = NULL;
126 BT_INFO("Mesh: BT_MESH_NETWORK_LOAD Request found Token [%s]",
129 /* Send request to mesh-network to load keys and Nodes for the network */
130 if (BLUETOOTH_ERROR_NONE == _bt_mesh_network_load_cdb(
131 result, req_info->sender, network->app_cred,
132 node->uuid, node->token.u8, &network_name)) {
133 g_strlcpy(network->name.name, network_name, strlen(network_name));
135 BT_ERR("!!Mesh: BT_MESH_NETWORK_LOAD Failed!!");
137 _bt_mesh_util_convert_hex_to_string((uint8_t *) node->uuid, 16, network->uuid,
138 BLUETOOTH_MESH_NETWORK_UUID_STRING_LENGTH + 1);
140 out_param = g_array_new(FALSE, FALSE, sizeof(gchar));
141 g_array_append_vals(out_param, network, sizeof(bluetooth_mesh_network_t));
142 _bt_service_method_return(req_info->context, out_param, result);
143 _bt_free_info_from_invocation_list(req_info);
144 g_free(req_info->user_data);
145 g_array_free(out_param, TRUE);
149 case BT_MESH_NETWORK_SCAN: {
150 bluetooth_mesh_network_t *network;
151 event_mesh_scan_status_t *event;
152 char net_uuid[BLUETOOTH_MESH_NETWORK_UUID_STRING_LENGTH + 1];
154 event = (event_mesh_scan_status_t*) param;
155 network = (bluetooth_mesh_network_t*)req_info->user_data;
156 _bt_mesh_util_convert_hex_to_string(
157 (uint8_t *) event->net_uuid.uuid, 16, net_uuid,
158 BLUETOOTH_MESH_NETWORK_UUID_STRING_LENGTH + 1);
160 BT_DBG("Request Sender: [%s]", req_info->sender);
161 if (!g_strcmp0(network->uuid, net_uuid)) {
162 out_param = g_array_new(FALSE, FALSE, sizeof(gchar));
163 g_array_append_vals(out_param,
164 network, sizeof(bluetooth_mesh_network_t));
165 _bt_service_method_return(req_info->context,
167 _bt_free_info_from_invocation_list(req_info);
168 g_free(req_info->user_data);
169 g_array_free(out_param, TRUE);
173 case BT_MESH_NETWORK_PROVISION_DEVICE: {
174 bluetooth_mesh_provisioning_request_t *req_data;
175 bluetooth_mesh_provisioning_request_t status_data;
176 event_mesh_provisioning_status_t *event;
178 0x00, sizeof(bluetooth_mesh_provisioning_request_t));
180 event = (event_mesh_provisioning_status_t*) param;
181 req_data = (bluetooth_mesh_provisioning_request_t*) req_info->user_data;
183 _bt_mesh_util_convert_hex_to_string(
184 (uint8_t *) event->net_uuid.uuid, 16, status_data.net_uuid,
185 BLUETOOTH_MESH_NETWORK_UUID_STRING_LENGTH + 1);
187 _bt_mesh_util_convert_hex_to_string(
188 (uint8_t *) event->dev_uuid.uuid, 16, status_data.dev_uuid,
189 BLUETOOTH_MESH_NETWORK_UUID_STRING_LENGTH + 1);
191 BT_DBG("Request Sender: [%s]", req_info->sender);
192 if (!g_strcmp0(req_data->net_uuid, status_data.net_uuid)) {
193 out_param = g_array_new(FALSE, FALSE, sizeof(gchar));
194 g_array_append_vals(out_param, &status_data,
195 sizeof(bluetooth_mesh_provisioning_request_t));
196 _bt_service_method_return(req_info->context, out_param, result);
197 _bt_free_info_from_invocation_list(req_info);
198 g_free(req_info->user_data);
199 g_array_free(out_param, TRUE);
204 case BT_MESH_NETWORK_DELETE_NETKEY:
205 case BT_MESH_NETWORK_UPDATE_NETKEY:
206 case BT_MESH_NETWORK_ADD_NETKEY: {
207 bluetooth_mesh_network_t *network;
208 event_mesh_netkey_operation_t *event;
209 char net_uuid[BLUETOOTH_MESH_NETWORK_UUID_STRING_LENGTH + 1];
211 event = (event_mesh_netkey_operation_t*) param;
212 network = (bluetooth_mesh_network_t*)req_info->user_data;
213 _bt_mesh_util_convert_hex_to_string(
214 (uint8_t *) event->net_uuid.uuid, 16, net_uuid,
215 BLUETOOTH_MESH_NETWORK_UUID_STRING_LENGTH + 1);
217 BT_DBG("Request Sender: [%s]", req_info->sender);
218 if (!g_strcmp0(network->uuid, net_uuid)) {
219 out_param = g_array_new(FALSE, FALSE, sizeof(gchar));
220 g_array_append_vals(out_param, &event->key_idx, sizeof(guint16));
221 _bt_service_method_return(req_info->context, out_param, result);
222 _bt_free_info_from_invocation_list(req_info);
223 g_free(req_info->user_data);
224 g_array_free(out_param, TRUE);
229 case BT_MESH_NETWORK_DELETE_APPKEY:
230 case BT_MESH_NETWORK_UPDATE_APPKEY:
231 case BT_MESH_NETWORK_ADD_APPKEY: {
232 bluetooth_mesh_network_t *network;
233 event_mesh_appkey_operation_t *event;
234 char net_uuid[BLUETOOTH_MESH_NETWORK_UUID_STRING_LENGTH + 1];
236 event = (event_mesh_appkey_operation_t*) param;
237 network = (bluetooth_mesh_network_t*)req_info->user_data;
238 _bt_mesh_util_convert_hex_to_string((uint8_t *) event->net_uuid.uuid, 16, net_uuid,
239 BLUETOOTH_MESH_NETWORK_UUID_STRING_LENGTH + 1);
241 BT_DBG("Request Sender: [%s]", req_info->sender);
242 if (!g_strcmp0(network->uuid, net_uuid)) {
243 out_param = g_array_new(FALSE, FALSE, sizeof(gchar));
244 g_array_append_vals(out_param, &event->app_idx, sizeof(guint16));
245 _bt_service_method_return(req_info->context, out_param, result);
246 _bt_free_info_from_invocation_list(req_info);
247 g_free(req_info->user_data);
248 g_array_free(out_param, TRUE);
253 BT_DBG("Unknown function(%d)", service_function);
259 static void __handle_mesh_network_subnet_operation_event(
260 event_mesh_netkey_operation_t *event)
262 int result = BLUETOOTH_ERROR_NONE;
264 if (event->status != OAL_STATUS_SUCCESS)
265 result = BLUETOOTH_ERROR_INTERNAL;
267 /* Handle DBUS Context return */
268 if (event->op == OAL_MESH_KEY_ADD) {
269 if (result == BLUETOOTH_ERROR_NONE)
270 _bt_mesh_network_handle_netkey_added(event->net_uuid.uuid, event->key_idx);
272 __bt_mesh_handle_pending_request_info(result, BT_MESH_NETWORK_ADD_NETKEY,
273 event, sizeof(event_mesh_netkey_operation_t));
274 } else if (event->op == OAL_MESH_KEY_DELETE) {
275 if (result == BLUETOOTH_ERROR_NONE)
276 _bt_mesh_network_handle_netkey_deleted(event->net_uuid.uuid, event->key_idx);
278 __bt_mesh_handle_pending_request_info(result, BT_MESH_NETWORK_DELETE_NETKEY,
279 event, sizeof(event_mesh_netkey_operation_t));
280 } else if (event->op == OAL_MESH_KEY_UPDATE) {
281 _bt_mesh_network_handle_netkey_updated(event->net_uuid.uuid, event->key_idx);
283 __bt_mesh_handle_pending_request_info(result, BT_MESH_NETWORK_UPDATE_NETKEY,
284 event, sizeof(event_mesh_netkey_operation_t));
288 static void __handle_mesh_network_appkey_operation_event(
289 event_mesh_appkey_operation_t *event)
291 int result = BLUETOOTH_ERROR_NONE;
293 if (event->status != OAL_STATUS_SUCCESS)
294 result = BLUETOOTH_ERROR_INTERNAL;
296 /* Handle DBUS Context return */
297 if (event->op == OAL_MESH_KEY_ADD) {
298 if (result == BLUETOOTH_ERROR_NONE)
299 _bt_mesh_network_handle_appkey_added(
300 event->net_uuid.uuid, event->net_idx, event->app_idx);
302 __bt_mesh_handle_pending_request_info(result, BT_MESH_NETWORK_ADD_APPKEY,
303 event, sizeof(event_mesh_netkey_operation_t));
304 } else if (event->op == OAL_MESH_KEY_DELETE) {
305 if (result == BLUETOOTH_ERROR_NONE)
306 _bt_mesh_network_handle_appkey_deleted(
307 event->net_uuid.uuid, event->net_idx, event->app_idx);
309 __bt_mesh_handle_pending_request_info(result, BT_MESH_NETWORK_DELETE_APPKEY,
310 event, sizeof(event_mesh_netkey_operation_t));
311 } else if (event->op == OAL_MESH_KEY_UPDATE) {
312 __bt_mesh_handle_pending_request_info(result, BT_MESH_NETWORK_UPDATE_APPKEY,
313 event, sizeof(event_mesh_netkey_operation_t));
317 static void __handle_mesh_devkey_message_received_event(
318 event_mesh_devkey_message_t *event)
320 _bt_mesh_config_client_devkey_msg_handler(event);
323 static void __handle_mesh_network_attached_event(
324 event_mesh_network_attached_t *event)
326 int result = BLUETOOTH_ERROR_NONE;
327 bluetooth_mesh_node_t node;
329 if (event->status != OAL_STATUS_SUCCESS)
330 result = BLUETOOTH_ERROR_INTERNAL;
332 memset(&node, 0x00, sizeof(bluetooth_mesh_node_t));
334 memcpy(node.uuid, event->uuid.uuid, 16);
335 memcpy(node.token.u8, event->token, 8);
337 __bt_mesh_handle_pending_request_info(result,
338 BT_MESH_NETWORK_CREATE,
339 &node, sizeof(bluetooth_mesh_node_t));
340 __bt_mesh_handle_pending_request_info(result,
341 BT_MESH_NETWORK_LOAD,
342 &node, sizeof(bluetooth_mesh_node_t));
345 static void __handle_mesh_network_scan_started_event(
346 event_mesh_scan_status_t *event)
348 GVariant *out_var = NULL, *param = NULL;
350 bluetooth_mesh_network_t network;
352 int result = BLUETOOTH_ERROR_NONE;
353 if (event->status != OAL_STATUS_SUCCESS) {
354 result = BLUETOOTH_ERROR_INTERNAL;
355 _bt_mesh_set_scanning_state(false);
357 _bt_mesh_set_scanning_state(true);
359 /* Handle DBUS Context return */
360 __bt_mesh_handle_pending_request_info(result,
361 BT_MESH_NETWORK_SCAN,
362 event, sizeof(event_mesh_scan_status_t));
364 /* Handle Scan started event */
365 if (result == BLUETOOTH_ERROR_NONE) {
366 memset(&network, 0x00, sizeof(bluetooth_mesh_network_t));
367 _bt_mesh_util_convert_hex_to_string(
368 (uint8_t *) event->net_uuid.uuid, 16, network.uuid,
369 BLUETOOTH_MESH_NETWORK_UUID_STRING_LENGTH + 1);
371 info = g_array_new(FALSE, FALSE, sizeof(gchar));
372 g_array_append_vals(info, &network,
373 sizeof(bluetooth_mesh_network_t));
375 out_var = g_variant_new_from_data((const GVariantType *)"ay",
376 info->data, info->len,
379 param = g_variant_new("(iv)", result, out_var);
380 _bt_send_event(BT_MESH_EVENT,
381 BLUETOOTH_EVENT_MESH_SCAN_STARTED,
386 static void __handle_mesh_network_scan_finished_event(
387 event_mesh_scan_status_t *event)
389 GVariant *out_var = NULL, *param = NULL;
391 bluetooth_mesh_network_t network;
393 int result = BLUETOOTH_ERROR_NONE;
394 if (event->status != OAL_STATUS_SUCCESS)
395 result = BLUETOOTH_ERROR_INTERNAL;
398 /* Handle Scan finsihed event */
399 if (result == BLUETOOTH_ERROR_NONE) {
400 memset(&network, 0x00, sizeof(bluetooth_mesh_network_t));
401 _bt_mesh_util_convert_hex_to_string(
402 (uint8_t *) event->net_uuid.uuid, 16, network.uuid,
403 BLUETOOTH_MESH_NETWORK_UUID_STRING_LENGTH + 1);
405 info = g_array_new(FALSE, FALSE, sizeof(gchar));
406 g_array_append_vals(info, &network,
407 sizeof(bluetooth_mesh_network_t));
409 out_var = g_variant_new_from_data((const GVariantType *)"ay",
410 info->data, info->len,
413 param = g_variant_new("(iv)", result, out_var);
414 _bt_send_event(BT_MESH_EVENT,
415 BLUETOOTH_EVENT_MESH_SCAN_FINISHED,
417 _bt_mesh_set_scanning_state(false);
421 static void __handle_mesh_network_provisioning_started_event(
422 event_mesh_provisioning_status_t *status)
424 int result = BLUETOOTH_ERROR_NONE;
426 __bt_mesh_handle_pending_request_info(result,
427 BT_MESH_NETWORK_PROVISION_DEVICE,
428 status, sizeof(event_mesh_scan_status_t));
430 _bt_mesh_set_provisioning_state(true);
433 static void __handle_mesh_network_provisioning_failed_event(
434 event_mesh_provisioning_status_t *status)
436 int result = BLUETOOTH_ERROR_INTERNAL;
438 __bt_mesh_handle_pending_request_info(result,
439 BT_MESH_NETWORK_PROVISION_DEVICE,
440 status, sizeof(event_mesh_scan_status_t));
442 _bt_mesh_set_provisioning_state(false);
445 static void __handle_mesh_network_provisioning_finished_event(
446 event_mesh_provisioning_finished_t *event)
448 GVariant *out_var = NULL, *param = NULL;
450 bluetooth_mesh_provisioning_result_t prov_result;
452 memset(&prov_result, 0x00,
453 sizeof(bluetooth_mesh_provisioning_result_t));
455 if (event->status != OAL_STATUS_SUCCESS)
456 prov_result.result = BLUETOOTH_ERROR_INTERNAL;
457 prov_result.result = BLUETOOTH_ERROR_NONE;
459 prov_result.reason = event->reason;
460 prov_result.unicast = event->unicast;
461 prov_result.count = event->count;
463 _bt_mesh_util_convert_hex_to_string(
464 (uint8_t *) event->net_uuid.uuid, 16, prov_result.net_uuid,
465 BLUETOOTH_MESH_NETWORK_UUID_STRING_LENGTH + 1);
467 _bt_mesh_util_convert_hex_to_string(
468 (uint8_t *) event->dev_uuid.uuid, 16, prov_result.dev_uuid,
469 BLUETOOTH_MESH_NETWORK_UUID_STRING_LENGTH + 1);
471 info = g_array_new(FALSE, FALSE, sizeof(gchar));
472 g_array_append_vals(info, &prov_result,
473 sizeof(bluetooth_mesh_provisioning_result_t));
475 out_var = g_variant_new_from_data((const GVariantType *)"ay",
476 info->data, info->len,
479 param = g_variant_new("(iv)", prov_result.result, out_var);
480 _bt_send_event(BT_MESH_EVENT,
481 BLUETOOTH_EVENT_MESH_PROVISIONING_FINISHED,
484 /* Add Remote Node entry in Local CDB */
485 if (event->status == OAL_STATUS_SUCCESS) {
486 _bt_mesh_network_add_remote_node(
487 event->net_uuid.uuid, event->dev_uuid.uuid,
488 event->unicast, event->count);
492 static void __handle_mesh_network_provisioning_data_requested_event(
493 event_mesh_provisioning_data_requested_t *event)
495 _bt_mesh_network_request_provisioning_data_request(
496 event->net_uuid.uuid, event->count);
499 static void __handle_mesh_network_authentication_requested_event(
500 event_mesh_authentication_requested_t *event)
502 GVariant *out_var = NULL, *param = NULL;
504 bluetooth_mesh_authentication_request_t auth_req;
506 memset(&auth_req, 0x00,
507 sizeof(bluetooth_mesh_authentication_request_t));
509 auth_req.auth_type = event->auth_type;
510 g_strlcpy(auth_req.auth_value, event->auth_value,
511 sizeof(auth_req.auth_value));
513 _bt_mesh_util_convert_hex_to_string(
514 (uint8_t *) event->net_uuid.uuid, 16, auth_req.net_uuid,
515 BLUETOOTH_MESH_NETWORK_UUID_STRING_LENGTH + 1);
517 info = g_array_new(FALSE, FALSE, sizeof(gchar));
518 g_array_append_vals(info, &auth_req,
519 sizeof(bluetooth_mesh_authentication_request_t));
521 out_var = g_variant_new_from_data((const GVariantType *)"ay",
522 info->data, info->len,
525 param = g_variant_new("(iv)", BLUETOOTH_ERROR_NONE, out_var);
526 _bt_send_event(BT_MESH_EVENT,
527 BLUETOOTH_EVENT_MESH_AUTHENTICATION_REQUEST,
531 static void __handle_mesh_network_scan_result_event(
532 event_mesh_scan_result_t *event)
534 GVariant *out_var = NULL, *param = NULL;
536 bluetooth_mesh_scan_result_t data;
537 int result = BLUETOOTH_ERROR_NONE;
539 memset(&data, 0x00, sizeof(bluetooth_mesh_scan_result_t));
541 /* Fill Network UUID */
542 _bt_mesh_util_convert_hex_to_string(
543 (uint8_t *) event->net_uuid.uuid, 16, data.net_uuid,
544 BLUETOOTH_MESH_NETWORK_UUID_STRING_LENGTH + 1);
546 /* Fill Device UUID */
547 _bt_mesh_util_convert_hex_to_string(
548 (uint8_t *) event->result.dev_uuid.uuid, 16, data.dev_uuid,
549 BLUETOOTH_MESH_NETWORK_UUID_STRING_LENGTH + 1);
552 data.rssi = event->result.rssi;
555 memcpy(&data.oob_info, event->result.oob_info, 2);
557 /* Fill URI Hash Info */
558 memcpy(&data.uri_hash, event->result.uri_hash, 4);
560 if (event->status != OAL_STATUS_SUCCESS)
561 result = BLUETOOTH_ERROR_INTERNAL;
564 info = g_array_new(FALSE, FALSE, sizeof(gchar));
565 g_array_append_vals(info, &data,
566 sizeof(bluetooth_mesh_scan_result_t));
568 out_var = g_variant_new_from_data((const GVariantType *)"ay",
569 info->data, info->len,
572 param = g_variant_new("(iv)", result, out_var);
573 _bt_send_event(BT_MESH_EVENT,
574 BLUETOOTH_EVENT_MESH_SCAN_RESULT,
578 static void __handle_mesh_events(int event_type,
581 switch (event_type) {
582 case OAL_EVENT_MESH_NETWORK_ATTACHED:
583 __handle_mesh_network_attached_event(
584 (event_mesh_network_attached_t*)event_data);
585 BT_PERMANENT_LOG("Mesh: Network attached!!");
587 case OAL_EVENT_MESH_SCAN_STARTED:
588 __handle_mesh_network_scan_started_event(
589 (event_mesh_scan_status_t*)event_data);
590 BT_PERMANENT_LOG("Mesh: Network Scan Stated!!");
592 case OAL_EVENT_MESH_SCAN_FINISHED:
593 __handle_mesh_network_scan_finished_event(
594 (event_mesh_scan_status_t*)event_data);
595 BT_PERMANENT_LOG("Mesh: Network Scan Finished!!");
597 case OAL_EVENT_MESH_SCAN_RESULT:
598 __handle_mesh_network_scan_result_event(
599 (event_mesh_scan_result_t*)event_data);
600 BT_PERMANENT_LOG("Mesh: Network Scan Result!!");
602 case OAL_EVENT_MESH_PROVISIONING_STARTED:
603 __handle_mesh_network_provisioning_started_event(
604 (event_mesh_provisioning_status_t*)event_data);
605 BT_PERMANENT_LOG("Mesh: Network Provisioning Started");
607 case OAL_EVENT_MESH_PROVISIONING_FAILED:
608 __handle_mesh_network_provisioning_failed_event(
609 (event_mesh_provisioning_status_t*)event_data);
610 BT_PERMANENT_LOG("Mesh: Network Provisioning Failed");
612 case OAL_EVENT_MESH_PROVISIONING_FINISHED:
613 __handle_mesh_network_provisioning_finished_event(
614 (event_mesh_provisioning_finished_t*)event_data);
615 BT_PERMANENT_LOG("Mesh: Network Provisioning Finished");
617 case OAL_EVENT_MESH_PROVISIONING_DATA_REQUESTED:
618 __handle_mesh_network_provisioning_data_requested_event(
619 (event_mesh_provisioning_data_requested_t*)event_data);
620 BT_PERMANENT_LOG("Mesh: Network Provisioning Data Requested");
622 case OAL_EVENT_MESH_AUTHENTICATION_REQUESTED:
623 __handle_mesh_network_authentication_requested_event(
624 (event_mesh_authentication_requested_t*)event_data);
625 BT_PERMANENT_LOG("Mesh: Network Authentication Requested");
627 case OAL_EVENT_MESH_NETKEY_EXECUTE_EVENT:
628 __handle_mesh_network_subnet_operation_event(
629 (event_mesh_netkey_operation_t*)event_data);
630 BT_PERMANENT_LOG("Mesh: Network Subnet operation event");
632 case OAL_EVENT_MESH_APPKEY_EXECUTE_EVENT:
633 __handle_mesh_network_appkey_operation_event(
634 (event_mesh_appkey_operation_t*)event_data);
635 BT_PERMANENT_LOG("Mesh: AppKey operation event");
637 case OAL_EVENT_MESH_DEVKEY_MESSAGE_RECEIVED:
638 __handle_mesh_devkey_message_received_event(
639 (event_mesh_devkey_message_t*)event_data);
640 BT_PERMANENT_LOG("Mesh: DevKey Message Received event");
647 int _bt_mesh_init(void)
649 oal_status_t status = OAL_STATUS_SUCCESS;
651 status = mesh_enable();
652 if (OAL_STATUS_SUCCESS != status) {
653 BT_ERR("Mesh: Failed to initialize Mesh profile, status: %d",
655 return BLUETOOTH_ERROR_INTERNAL;
657 BT_INFO("Mesh: Stack Initialization Done successfully");
659 /* Register MESH event handler */
660 _bt_service_register_event_handler_callback(BT_MESH_MODULE,
661 __handle_mesh_events);
663 return BLUETOOTH_ERROR_NONE;
666 int _bt_mesh_deinit(void)
668 oal_status_t status = OAL_STATUS_SUCCESS;
670 status = mesh_disable();
671 if (OAL_STATUS_SUCCESS != status) {
672 BT_ERR("Mesh: Failed to de-initialize Mesh profile, status: %d",
674 return BLUETOOTH_ERROR_INTERNAL;
677 /* Register AVRCP target event handler */
678 _bt_service_unregister_event_handler_callback(BT_MESH_MODULE);
680 return BLUETOOTH_ERROR_NONE;