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_array_free(out_param, TRUE);
108 case BT_MESH_NETWORK_LOAD: {
109 char token_str[BLUETOOTH_MESH_NETWORK_TOKEN_STRING_LENGTH + 1];
110 bluetooth_mesh_node_t *node;
111 bluetooth_mesh_network_t *network;
112 ret_if(param == NULL);
113 BT_INFO("Mesh: Request: BT_MESH_NETWORK_LOAD Sender: [%s]",
116 node = (bluetooth_mesh_node_t*) param;
117 network = (bluetooth_mesh_network_t*)req_info->user_data;
119 _bt_mesh_util_convert_hex_to_string(
120 (uint8_t *) node->token.u8, 8, token_str,
121 BLUETOOTH_MESH_NETWORK_TOKEN_STRING_LENGTH + 1);
123 if (!g_strcmp0(network->token.token, token_str)) {
124 char *network_name = NULL;
125 BT_INFO("Mesh: BT_MESH_NETWORK_LOAD Request found Token [%s]",
128 /* Send request to mesh-network to load keys and Nodes for the network */
129 if (BLUETOOTH_ERROR_NONE == _bt_mesh_network_load_cdb(
130 result, req_info->sender, network->app_cred,
131 node->uuid, node->token.u8, &network_name)) {
132 g_strlcpy(network->name.name, network_name, strlen(network_name));
134 BT_ERR("!!Mesh: BT_MESH_NETWORK_LOAD Failed!!");
136 _bt_mesh_util_convert_hex_to_string((uint8_t *) node->uuid, 16, network->uuid,
137 BLUETOOTH_MESH_NETWORK_UUID_STRING_LENGTH + 1);
139 out_param = g_array_new(FALSE, FALSE, sizeof(gchar));
140 g_array_append_vals(out_param, network, sizeof(bluetooth_mesh_network_t));
141 _bt_service_method_return(req_info->context, out_param, result);
142 _bt_free_info_from_invocation_list(req_info);
143 g_array_free(out_param, TRUE);
147 case BT_MESH_NETWORK_SCAN: {
148 bluetooth_mesh_network_t *network;
149 event_mesh_scan_status_t *event;
150 char net_uuid[BLUETOOTH_MESH_NETWORK_UUID_STRING_LENGTH + 1];
152 event = (event_mesh_scan_status_t*) param;
153 network = (bluetooth_mesh_network_t*)req_info->user_data;
154 _bt_mesh_util_convert_hex_to_string(
155 (uint8_t *) event->net_uuid.uuid, 16, net_uuid,
156 BLUETOOTH_MESH_NETWORK_UUID_STRING_LENGTH + 1);
158 BT_DBG("Request Sender: [%s]", req_info->sender);
159 if (!g_strcmp0(network->uuid, net_uuid)) {
160 out_param = g_array_new(FALSE, FALSE, sizeof(gchar));
161 g_array_append_vals(out_param,
162 network, sizeof(bluetooth_mesh_network_t));
163 _bt_service_method_return(req_info->context,
165 _bt_free_info_from_invocation_list(req_info);
166 g_array_free(out_param, TRUE);
170 case BT_MESH_NETWORK_PROVISION_DEVICE: {
171 bluetooth_mesh_provisioning_request_t *req_data;
172 bluetooth_mesh_provisioning_request_t status_data;
173 event_mesh_provisioning_status_t *event;
175 0x00, sizeof(bluetooth_mesh_provisioning_request_t));
177 event = (event_mesh_provisioning_status_t*) param;
178 req_data = (bluetooth_mesh_provisioning_request_t*) req_info->user_data;
180 _bt_mesh_util_convert_hex_to_string(
181 (uint8_t *) event->net_uuid.uuid, 16, status_data.net_uuid,
182 BLUETOOTH_MESH_NETWORK_UUID_STRING_LENGTH + 1);
184 _bt_mesh_util_convert_hex_to_string(
185 (uint8_t *) event->dev_uuid.uuid, 16, status_data.dev_uuid,
186 BLUETOOTH_MESH_NETWORK_UUID_STRING_LENGTH + 1);
187 BT_INFO("Mesh: Provision Status: Device UUID [%s]", status_data.dev_uuid);
188 BT_INFO("Mesh: Provision Status: Net UUID [%s]", status_data.net_uuid);
189 BT_INFO("Mesh: Provision Status: Result [%d]", event->status);
190 if (event->status == OAL_STATUS_SUCCESS)
191 BT_INFO("Mesh: Provisioning status : SUCCESS");
193 BT_INFO("Mesh: Provisioning status : FAIL");
195 BT_DBG("Request Sender: [%s]", req_info->sender);
196 if (!g_strcmp0(req_data->net_uuid, status_data.net_uuid)) {
197 out_param = g_array_new(FALSE, FALSE, sizeof(gchar));
198 g_array_append_vals(out_param, &status_data,
199 sizeof(bluetooth_mesh_provisioning_request_t));
200 _bt_service_method_return(req_info->context, out_param, result);
201 _bt_free_info_from_invocation_list(req_info);
202 g_array_free(out_param, TRUE);
207 case BT_MESH_NETWORK_DELETE_NETKEY:
208 case BT_MESH_NETWORK_UPDATE_NETKEY:
209 case BT_MESH_NETWORK_ADD_NETKEY: {
210 bluetooth_mesh_network_t *network;
211 event_mesh_netkey_operation_t *event;
212 char net_uuid[BLUETOOTH_MESH_NETWORK_UUID_STRING_LENGTH + 1];
214 event = (event_mesh_netkey_operation_t*) param;
215 network = (bluetooth_mesh_network_t*)req_info->user_data;
216 _bt_mesh_util_convert_hex_to_string(
217 (uint8_t *) event->net_uuid.uuid, 16, net_uuid,
218 BLUETOOTH_MESH_NETWORK_UUID_STRING_LENGTH + 1);
220 BT_DBG("Request Sender: [%s]", req_info->sender);
221 if (!g_strcmp0(network->uuid, net_uuid)) {
222 out_param = g_array_new(FALSE, FALSE, sizeof(gchar));
223 g_array_append_vals(out_param, &event->key_idx, sizeof(guint16));
224 _bt_service_method_return(req_info->context, out_param, result);
225 _bt_free_info_from_invocation_list(req_info);
226 g_array_free(out_param, TRUE);
231 case BT_MESH_NETWORK_DELETE_APPKEY:
232 case BT_MESH_NETWORK_UPDATE_APPKEY:
233 case BT_MESH_NETWORK_ADD_APPKEY: {
234 bluetooth_mesh_network_t *network;
235 event_mesh_appkey_operation_t *event;
236 char net_uuid[BLUETOOTH_MESH_NETWORK_UUID_STRING_LENGTH + 1];
238 event = (event_mesh_appkey_operation_t*) param;
239 network = (bluetooth_mesh_network_t*)req_info->user_data;
240 _bt_mesh_util_convert_hex_to_string((uint8_t *) event->net_uuid.uuid, 16, net_uuid,
241 BLUETOOTH_MESH_NETWORK_UUID_STRING_LENGTH + 1);
243 BT_DBG("Request Sender: [%s]", req_info->sender);
244 if (!g_strcmp0(network->uuid, net_uuid)) {
245 out_param = g_array_new(FALSE, FALSE, sizeof(gchar));
246 g_array_append_vals(out_param, &event->app_idx, sizeof(guint16));
247 _bt_service_method_return(req_info->context, out_param, result);
248 _bt_free_info_from_invocation_list(req_info);
249 g_array_free(out_param, TRUE);
254 BT_DBG("Unknown function(%d)", service_function);
260 static void __handle_mesh_network_subnet_operation_event(
261 event_mesh_netkey_operation_t *event)
263 int result = BLUETOOTH_ERROR_NONE;
265 if (event->status != OAL_STATUS_SUCCESS)
266 result = BLUETOOTH_ERROR_INTERNAL;
268 /* Handle DBUS Context return */
269 if (event->op == OAL_MESH_KEY_ADD) {
270 if (result == BLUETOOTH_ERROR_NONE)
271 _bt_mesh_network_handle_netkey_added(event->net_uuid.uuid, event->key_idx);
273 __bt_mesh_handle_pending_request_info(result, BT_MESH_NETWORK_ADD_NETKEY,
274 event, sizeof(event_mesh_netkey_operation_t));
275 } else if (event->op == OAL_MESH_KEY_DELETE) {
276 if (result == BLUETOOTH_ERROR_NONE)
277 _bt_mesh_network_handle_netkey_deleted(event->net_uuid.uuid, event->key_idx);
279 __bt_mesh_handle_pending_request_info(result, BT_MESH_NETWORK_DELETE_NETKEY,
280 event, sizeof(event_mesh_netkey_operation_t));
281 } else if (event->op == OAL_MESH_KEY_UPDATE) {
282 _bt_mesh_network_handle_netkey_updated(event->net_uuid.uuid, event->key_idx);
284 __bt_mesh_handle_pending_request_info(result, BT_MESH_NETWORK_UPDATE_NETKEY,
285 event, sizeof(event_mesh_netkey_operation_t));
289 static void __handle_mesh_network_appkey_operation_event(
290 event_mesh_appkey_operation_t *event)
292 int result = BLUETOOTH_ERROR_NONE;
294 if (event->status != OAL_STATUS_SUCCESS)
295 result = BLUETOOTH_ERROR_INTERNAL;
296 /* Handle DBUS Context return */
297 if (event->op == OAL_MESH_KEY_ADD) {
298 BT_INFO("Mesh: Appkey Add event");
299 if (result == BLUETOOTH_ERROR_NONE)
300 _bt_mesh_network_handle_appkey_added(
301 event->net_uuid.uuid, event->net_idx, event->app_idx);
303 __bt_mesh_handle_pending_request_info(result, BT_MESH_NETWORK_ADD_APPKEY,
304 event, sizeof(event_mesh_netkey_operation_t));
305 } else if (event->op == OAL_MESH_KEY_DELETE) {
306 BT_INFO("Mesh: Appkey Delete event");
307 if (result == BLUETOOTH_ERROR_NONE)
308 _bt_mesh_network_handle_appkey_deleted(
309 event->net_uuid.uuid, event->net_idx, event->app_idx);
311 __bt_mesh_handle_pending_request_info(result, BT_MESH_NETWORK_DELETE_APPKEY,
312 event, sizeof(event_mesh_netkey_operation_t));
313 } else if (event->op == OAL_MESH_KEY_UPDATE) {
314 BT_INFO("Mesh: Appkey Update event");
315 __bt_mesh_handle_pending_request_info(result, BT_MESH_NETWORK_UPDATE_APPKEY,
316 event, sizeof(event_mesh_netkey_operation_t));
320 static void __handle_mesh_devkey_message_received_event(
321 event_mesh_devkey_message_t *event)
323 _bt_mesh_config_client_devkey_msg_handler(event);
326 static void __handle_mesh_network_attached_event(
327 event_mesh_network_attached_t *event)
329 int result = BLUETOOTH_ERROR_NONE;
330 bluetooth_mesh_node_t node;
332 if (event->status != OAL_STATUS_SUCCESS)
333 result = BLUETOOTH_ERROR_INTERNAL;
335 memset(&node, 0x00, sizeof(bluetooth_mesh_node_t));
337 memcpy(node.uuid, event->uuid.uuid, 16);
338 memcpy(node.token.u8, event->token, 8);
340 __bt_mesh_handle_pending_request_info(result,
341 BT_MESH_NETWORK_CREATE,
342 &node, sizeof(bluetooth_mesh_node_t));
343 __bt_mesh_handle_pending_request_info(result,
344 BT_MESH_NETWORK_LOAD,
345 &node, sizeof(bluetooth_mesh_node_t));
348 static void __handle_mesh_network_scan_started_event(
349 event_mesh_scan_status_t *event)
351 GVariant *out_var = NULL, *param = NULL;
353 bluetooth_mesh_network_t network;
355 int result = BLUETOOTH_ERROR_NONE;
356 if (event->status != OAL_STATUS_SUCCESS) {
357 result = BLUETOOTH_ERROR_INTERNAL;
358 _bt_mesh_set_scanning_state(false);
360 _bt_mesh_set_scanning_state(true);
362 /* Handle DBUS Context return */
363 __bt_mesh_handle_pending_request_info(result,
364 BT_MESH_NETWORK_SCAN,
365 event, sizeof(event_mesh_scan_status_t));
367 /* Handle Scan started event */
368 if (result == BLUETOOTH_ERROR_NONE) {
369 memset(&network, 0x00, sizeof(bluetooth_mesh_network_t));
370 _bt_mesh_util_convert_hex_to_string(
371 (uint8_t *) event->net_uuid.uuid, 16, network.uuid,
372 BLUETOOTH_MESH_NETWORK_UUID_STRING_LENGTH + 1);
374 info = g_array_new(FALSE, FALSE, sizeof(gchar));
375 g_array_append_vals(info, &network,
376 sizeof(bluetooth_mesh_network_t));
378 out_var = g_variant_new_from_data((const GVariantType *)"ay",
379 info->data, info->len,
382 param = g_variant_new("(iv)", result, out_var);
383 _bt_send_event(BT_MESH_EVENT,
384 BLUETOOTH_EVENT_MESH_SCAN_STARTED,
389 static void __handle_mesh_network_scan_finished_event(
390 event_mesh_scan_status_t *event)
392 GVariant *out_var = NULL, *param = NULL;
394 bluetooth_mesh_network_t network;
395 int result = BLUETOOTH_ERROR_NONE;
396 if (event->status != OAL_STATUS_SUCCESS) {
397 BT_INFO("Mesh: Scan Finished: status:: FAILED!");
398 result = BLUETOOTH_ERROR_INTERNAL;
400 BT_INFO("Mesh: Scan Finished: status:: SUCCESS!");
402 /* Handle Scan finsihed event */
403 if (result == BLUETOOTH_ERROR_NONE) {
404 memset(&network, 0x00, sizeof(bluetooth_mesh_network_t));
405 _bt_mesh_util_convert_hex_to_string(
406 (uint8_t *) event->net_uuid.uuid, 16, network.uuid,
407 BLUETOOTH_MESH_NETWORK_UUID_STRING_LENGTH + 1);
409 info = g_array_new(FALSE, FALSE, sizeof(gchar));
410 g_array_append_vals(info, &network,
411 sizeof(bluetooth_mesh_network_t));
413 out_var = g_variant_new_from_data((const GVariantType *)"ay",
414 info->data, info->len,
417 param = g_variant_new("(iv)", result, out_var);
418 _bt_send_event(BT_MESH_EVENT,
419 BLUETOOTH_EVENT_MESH_SCAN_FINISHED,
421 _bt_mesh_set_scanning_state(false);
425 static void __handle_mesh_network_provisioning_started_event(
426 event_mesh_provisioning_status_t *status)
428 int result = BLUETOOTH_ERROR_NONE;
429 BT_INFO("Mesh: Provisioning started");
431 __bt_mesh_handle_pending_request_info(result,
432 BT_MESH_NETWORK_PROVISION_DEVICE,
433 status, sizeof(event_mesh_provisioning_status_t));
435 _bt_mesh_set_provisioning_state(true);
438 static void __handle_mesh_network_provisioning_failed_event(
439 event_mesh_provisioning_status_t *status)
441 int result = BLUETOOTH_ERROR_INTERNAL;
442 BT_INFO("Mesh: Provisioning failed!!");
443 __bt_mesh_handle_pending_request_info(result,
444 BT_MESH_NETWORK_PROVISION_DEVICE,
445 status, sizeof(event_mesh_provisioning_status_t));
447 _bt_mesh_set_provisioning_state(false);
450 static void __handle_mesh_network_provisioning_finished_event(
451 event_mesh_provisioning_finished_t *event)
453 GVariant *out_var = NULL, *param = NULL;
455 bluetooth_mesh_provisioning_result_t prov_result;
456 BT_INFO("Mesh: Provisioning Finished!");
458 memset(&prov_result, 0x00,
459 sizeof(bluetooth_mesh_provisioning_result_t));
461 if (event->status != OAL_STATUS_SUCCESS)
462 prov_result.result = BLUETOOTH_ERROR_INTERNAL;
464 prov_result.result = BLUETOOTH_ERROR_NONE;
466 prov_result.reason = event->reason;
467 prov_result.unicast = event->unicast;
468 prov_result.count = event->count;
470 _bt_mesh_util_convert_hex_to_string(
471 (uint8_t *) event->net_uuid.uuid, 16, prov_result.net_uuid,
472 BLUETOOTH_MESH_NETWORK_UUID_STRING_LENGTH + 1);
474 _bt_mesh_util_convert_hex_to_string(
475 (uint8_t *) event->dev_uuid.uuid, 16, prov_result.dev_uuid,
476 BLUETOOTH_MESH_NETWORK_UUID_STRING_LENGTH + 1);
478 info = g_array_new(FALSE, FALSE, sizeof(gchar));
479 g_array_append_vals(info, &prov_result,
480 sizeof(bluetooth_mesh_provisioning_result_t));
482 out_var = g_variant_new_from_data((const GVariantType *)"ay",
483 info->data, info->len,
486 param = g_variant_new("(iv)", prov_result.result, out_var);
487 _bt_send_event(BT_MESH_EVENT,
488 BLUETOOTH_EVENT_MESH_PROVISIONING_FINISHED,
491 /* Add Remote Node entry in Local CDB */
492 if (event->status == OAL_STATUS_SUCCESS) {
493 BT_INFO("Mesh: Provisioning done, add node to Network");
494 BT_INFO("Mesh: Node UUID [%s]", prov_result.dev_uuid);
495 BT_INFO("Mesh: Node Unicast[0x%2.2x] Element Count [%d]",
496 event->unicast, event->count);
498 _bt_mesh_network_add_remote_node(
499 event->net_uuid.uuid, event->dev_uuid.uuid,
500 event->unicast, event->count);
502 /* Unset provisioning state */
503 _bt_mesh_set_provisioning_state(false);
506 static void __handle_mesh_network_provisioning_data_requested_event(
507 event_mesh_provisioning_data_requested_t *event)
509 _bt_mesh_network_request_provisioning_data_request(
510 event->net_uuid.uuid, event->count);
513 static void __handle_mesh_network_authentication_requested_event(
514 event_mesh_authentication_requested_t *event)
516 GVariant *out_var = NULL, *param = NULL;
518 bluetooth_mesh_authentication_request_t auth_req;
520 memset(&auth_req, 0x00,
521 sizeof(bluetooth_mesh_authentication_request_t));
523 auth_req.auth_type = event->auth_type;
524 g_strlcpy(auth_req.auth_value, event->auth_value,
525 sizeof(auth_req.auth_value));
527 _bt_mesh_util_convert_hex_to_string(
528 (uint8_t *) event->net_uuid.uuid, 16, auth_req.net_uuid,
529 BLUETOOTH_MESH_NETWORK_UUID_STRING_LENGTH + 1);
531 BT_INFO("Mesh: Authentication Requested by Device: Network [%s]",
533 info = g_array_new(FALSE, FALSE, sizeof(gchar));
534 g_array_append_vals(info, &auth_req,
535 sizeof(bluetooth_mesh_authentication_request_t));
537 out_var = g_variant_new_from_data((const GVariantType *)"ay",
538 info->data, info->len,
541 param = g_variant_new("(iv)", BLUETOOTH_ERROR_NONE, out_var);
542 _bt_send_event(BT_MESH_EVENT,
543 BLUETOOTH_EVENT_MESH_AUTHENTICATION_REQUEST,
547 static void __handle_mesh_network_scan_result_event(
548 event_mesh_scan_result_t *event)
550 GVariant *out_var = NULL, *param = NULL;
552 bluetooth_mesh_scan_result_t data;
553 int result = BLUETOOTH_ERROR_NONE;
555 memset(&data, 0x00, sizeof(bluetooth_mesh_scan_result_t));
557 /* Fill Network UUID */
558 _bt_mesh_util_convert_hex_to_string(
559 (uint8_t *) event->net_uuid.uuid, 16, data.net_uuid,
560 BLUETOOTH_MESH_NETWORK_UUID_STRING_LENGTH + 1);
562 /* Fill Device UUID */
563 _bt_mesh_util_convert_hex_to_string(
564 (uint8_t *) event->result.dev_uuid.uuid, 16, data.dev_uuid,
565 BLUETOOTH_MESH_NETWORK_UUID_STRING_LENGTH + 1);
568 data.rssi = event->result.rssi;
571 memcpy(&data.oob_info, event->result.oob_info, 2);
573 /* Fill URI Hash Info */
574 memcpy(&data.uri_hash, event->result.uri_hash, 4);
576 if (event->status != OAL_STATUS_SUCCESS)
577 result = BLUETOOTH_ERROR_INTERNAL;
580 info = g_array_new(FALSE, FALSE, sizeof(gchar));
581 g_array_append_vals(info, &data,
582 sizeof(bluetooth_mesh_scan_result_t));
584 out_var = g_variant_new_from_data((const GVariantType *)"ay",
585 info->data, info->len,
588 param = g_variant_new("(iv)", result, out_var);
589 _bt_send_event(BT_MESH_EVENT,
590 BLUETOOTH_EVENT_MESH_SCAN_RESULT,
594 static void __handle_mesh_events(int event_type,
597 BT_INFO("Mesh: Got Mesh event!!! event type [%d]", event_type);
598 if (event_type == OAL_EVENT_MESH_PROVISIONING_STARTED)
599 BT_INFO("Mesh: Provisioning started event");
601 switch (event_type) {
602 case OAL_EVENT_MESH_NETWORK_ATTACHED:
603 __handle_mesh_network_attached_event(
604 (event_mesh_network_attached_t*)event_data);
605 BT_PERMANENT_LOG("Mesh: Network attached!!");
607 case OAL_EVENT_MESH_SCAN_STARTED:
608 __handle_mesh_network_scan_started_event(
609 (event_mesh_scan_status_t*)event_data);
610 BT_PERMANENT_LOG("Mesh: Network Scan Stated!!");
612 case OAL_EVENT_MESH_SCAN_FINISHED:
613 __handle_mesh_network_scan_finished_event(
614 (event_mesh_scan_status_t*)event_data);
615 BT_PERMANENT_LOG("Mesh: Network Scan Finished!!");
617 case OAL_EVENT_MESH_SCAN_RESULT:
618 __handle_mesh_network_scan_result_event(
619 (event_mesh_scan_result_t*)event_data);
620 BT_PERMANENT_LOG("Mesh: Network Scan Result!!");
622 case OAL_EVENT_MESH_PROVISIONING_STARTED:
623 BT_INFO("Mesh: Network Provisioning Started");
624 __handle_mesh_network_provisioning_started_event(
625 (event_mesh_provisioning_status_t*)event_data);
626 BT_PERMANENT_LOG("Mesh: Network Provisioning Started");
628 case OAL_EVENT_MESH_PROVISIONING_FAILED:
629 BT_INFO("Mesh: Network Provisioning Failed!!!!");
630 __handle_mesh_network_provisioning_failed_event(
631 (event_mesh_provisioning_status_t*)event_data);
632 BT_PERMANENT_LOG("Mesh: Network Provisioning Failed");
634 case OAL_EVENT_MESH_PROVISIONING_FINISHED:
635 __handle_mesh_network_provisioning_finished_event(
636 (event_mesh_provisioning_finished_t*)event_data);
637 BT_PERMANENT_LOG("Mesh: Network Provisioning Finished");
639 case OAL_EVENT_MESH_PROVISIONING_DATA_REQUESTED:
640 __handle_mesh_network_provisioning_data_requested_event(
641 (event_mesh_provisioning_data_requested_t*)event_data);
642 BT_PERMANENT_LOG("Mesh: Network Provisioning Data Requested");
644 case OAL_EVENT_MESH_AUTHENTICATION_REQUESTED:
645 __handle_mesh_network_authentication_requested_event(
646 (event_mesh_authentication_requested_t*)event_data);
647 BT_PERMANENT_LOG("Mesh: Network Authentication Requested");
649 case OAL_EVENT_MESH_NETKEY_EXECUTE_EVENT:
650 __handle_mesh_network_subnet_operation_event(
651 (event_mesh_netkey_operation_t*)event_data);
652 BT_PERMANENT_LOG("Mesh: Network Subnet operation event");
654 case OAL_EVENT_MESH_APPKEY_EXECUTE_EVENT:
655 __handle_mesh_network_appkey_operation_event(
656 (event_mesh_appkey_operation_t*)event_data);
657 BT_PERMANENT_LOG("Mesh: AppKey operation event");
659 case OAL_EVENT_MESH_DEVKEY_MESSAGE_RECEIVED:
660 __handle_mesh_devkey_message_received_event(
661 (event_mesh_devkey_message_t*)event_data);
662 BT_PERMANENT_LOG("Mesh: DevKey Message Received event");
669 int _bt_mesh_init(void)
671 oal_status_t status = OAL_STATUS_SUCCESS;
673 status = mesh_enable();
674 if (OAL_STATUS_SUCCESS != status) {
675 BT_ERR("Mesh: Failed to initialize Mesh profile, status: %d",
677 return BLUETOOTH_ERROR_INTERNAL;
679 BT_INFO("Mesh: Stack Initialization Done successfully");
681 /* Register MESH event handler */
682 _bt_service_register_event_handler_callback(BT_MESH_MODULE,
683 __handle_mesh_events);
685 return BLUETOOTH_ERROR_NONE;
688 int _bt_mesh_deinit(void)
690 oal_status_t status = OAL_STATUS_SUCCESS;
692 status = mesh_disable();
693 if (OAL_STATUS_SUCCESS != status) {
694 BT_ERR("Mesh: Failed to de-initialize Mesh profile, status: %d",
696 return BLUETOOTH_ERROR_INTERNAL;
699 /* Register AVRCP target event handler */
700 _bt_service_unregister_event_handler_callback(BT_MESH_MODULE);
702 return BLUETOOTH_ERROR_NONE;