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.
32 #include <actd/unit_control.h>
34 #include "bluetooth-api.h"
35 #include "bt-internal-types.h"
36 #include "bt-service-common.h"
37 #include "bt-service-event.h"
38 #include "bt-service-event-receiver.h"
39 #include "bt-service-util.h"
41 #include "bt-service-mesh-util.h"
42 #include "bt-service-mesh-network.h"
43 #include "bt-service-mesh-nodes.h"
44 #include "bt-service-mesh-config-client.h"
48 #define MESH_SYSTEMD_SERVICE_NAME "bluetooth-mesh.service"
51 static void __bt_mesh_handle_pending_request_info(int result,
52 int service_function, void *param,
57 invocation_info_t *req_info = NULL;
59 for (l = _bt_get_invocation_list(); l != NULL; ) {
62 if (req_info == NULL ||
63 req_info->service_function != service_function)
66 switch (service_function) {
67 case BT_MESH_NETWORK_CREATE: {
68 char uuid_str[BLUETOOTH_MESH_NETWORK_UUID_STRING_LENGTH + 1];
69 bluetooth_mesh_node_t *node;
70 bluetooth_mesh_network_t *network;
71 ret_if(param == NULL);
72 BT_INFO("Mesh: Request: BT_MESH_NETWORK_CREATE Sender: [%s] result[%d]",
73 req_info->sender, result);
75 node = (bluetooth_mesh_node_t*) param;
76 network = (bluetooth_mesh_network_t*)req_info->user_data;
78 _bt_mesh_util_convert_hex_to_string(
79 (uint8_t *) node->uuid, 16, uuid_str,
80 BLUETOOTH_MESH_NETWORK_UUID_STRING_LENGTH + 1);
82 BT_INFO("Mesh: Network UUID from event [%s] Netw UUID from req [%s]",
83 uuid_str, network->uuid);
85 if (!g_strcmp0(network->uuid, uuid_str)) {
86 BT_INFO("Mesh: BT_MESH_NETWORK_CREATE Request found uuid [%s]",
88 if (BLUETOOTH_ERROR_NONE != _bt_mesh_network_create_cdb(
89 result, req_info->sender,
90 network->app_cred, node->uuid,
91 node->token.u8, network->name.name)) {
92 result = BLUETOOTH_ERROR_INTERNAL;
93 BT_ERR("!!Mesh: BT_MESH_NETWORK_CREATE Failed!!");
96 _bt_mesh_util_convert_hex_to_string(
97 (uint8_t *) node->token.u8, 8,
99 BLUETOOTH_MESH_NETWORK_TOKEN_STRING_LENGTH + 1);
101 out_param = g_array_new(FALSE, FALSE, sizeof(gchar));
102 g_array_append_vals(out_param, network,
103 sizeof(bluetooth_mesh_network_t));
104 _bt_service_method_return(req_info->context,
106 _bt_free_info_from_invocation_list(req_info);
107 g_array_free(out_param, TRUE);
111 case BT_MESH_NETWORK_LOAD: {
112 char token_str[BLUETOOTH_MESH_NETWORK_TOKEN_STRING_LENGTH + 1];
113 bluetooth_mesh_node_t *node;
114 bluetooth_mesh_network_t *network;
115 ret_if(param == NULL);
116 BT_INFO("Mesh: Request: BT_MESH_NETWORK_LOAD Sender: [%s]",
119 node = (bluetooth_mesh_node_t*) param;
120 network = (bluetooth_mesh_network_t*)req_info->user_data;
122 _bt_mesh_util_convert_hex_to_string(
123 (uint8_t *) node->token.u8, 8, token_str,
124 BLUETOOTH_MESH_NETWORK_TOKEN_STRING_LENGTH + 1);
126 if (!g_strcmp0(network->token.token, token_str)) {
127 char *network_name = NULL;
128 BT_INFO("Mesh: BT_MESH_NETWORK_LOAD Request found Token [%s]",
131 /* Send request to mesh-network to load keys and Nodes for the network */
132 if (BLUETOOTH_ERROR_NONE == _bt_mesh_network_load_cdb(
133 result, req_info->sender, network->app_cred,
134 node->uuid, node->token.u8, &network_name)) {
135 g_strlcpy(network->name.name, network_name, strlen(network_name));
137 BT_ERR("!!Mesh: BT_MESH_NETWORK_LOAD Failed!!");
139 _bt_mesh_util_convert_hex_to_string((uint8_t *) node->uuid, 16, network->uuid,
140 BLUETOOTH_MESH_NETWORK_UUID_STRING_LENGTH + 1);
142 out_param = g_array_new(FALSE, FALSE, sizeof(gchar));
143 g_array_append_vals(out_param, network, sizeof(bluetooth_mesh_network_t));
144 _bt_service_method_return(req_info->context, out_param, result);
145 _bt_free_info_from_invocation_list(req_info);
146 g_array_free(out_param, TRUE);
150 case BT_MESH_NETWORK_SCAN: {
151 bluetooth_mesh_network_t *network;
152 event_mesh_scan_status_t *event;
153 char net_uuid[BLUETOOTH_MESH_NETWORK_UUID_STRING_LENGTH + 1];
155 event = (event_mesh_scan_status_t*) param;
156 network = (bluetooth_mesh_network_t*)req_info->user_data;
157 _bt_mesh_util_convert_hex_to_string(
158 (uint8_t *) event->net_uuid.uuid, 16, net_uuid,
159 BLUETOOTH_MESH_NETWORK_UUID_STRING_LENGTH + 1);
161 BT_DBG("Request Sender: [%s]", req_info->sender);
162 if (!g_strcmp0(network->uuid, net_uuid)) {
163 out_param = g_array_new(FALSE, FALSE, sizeof(gchar));
164 g_array_append_vals(out_param,
165 network, sizeof(bluetooth_mesh_network_t));
166 _bt_service_method_return(req_info->context,
168 _bt_free_info_from_invocation_list(req_info);
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);
190 BT_INFO("Mesh: Provision Status: Device UUID [%s]", status_data.dev_uuid);
191 BT_INFO("Mesh: Provision Status: Net UUID [%s]", status_data.net_uuid);
192 BT_INFO("Mesh: Provision Status: Result [%d]", event->status);
193 if (event->status == OAL_STATUS_SUCCESS)
194 BT_INFO("Mesh: Provisioning status : SUCCESS");
196 BT_INFO("Mesh: Provisioning status : FAIL");
198 BT_DBG("Request Sender: [%s]", req_info->sender);
199 if (!g_strcmp0(req_data->net_uuid, status_data.net_uuid)) {
200 out_param = g_array_new(FALSE, FALSE, sizeof(gchar));
201 g_array_append_vals(out_param, &status_data,
202 sizeof(bluetooth_mesh_provisioning_request_t));
203 _bt_service_method_return(req_info->context, out_param, result);
204 _bt_free_info_from_invocation_list(req_info);
205 g_array_free(out_param, TRUE);
210 case BT_MESH_NETWORK_DELETE_NETKEY:
211 case BT_MESH_NETWORK_UPDATE_NETKEY:
212 case BT_MESH_NETWORK_ADD_NETKEY: {
213 bluetooth_mesh_network_t *network;
214 event_mesh_netkey_operation_t *event;
215 char net_uuid[BLUETOOTH_MESH_NETWORK_UUID_STRING_LENGTH + 1];
217 event = (event_mesh_netkey_operation_t*) param;
218 network = (bluetooth_mesh_network_t*)req_info->user_data;
219 _bt_mesh_util_convert_hex_to_string(
220 (uint8_t *) event->net_uuid.uuid, 16, net_uuid,
221 BLUETOOTH_MESH_NETWORK_UUID_STRING_LENGTH + 1);
223 BT_DBG("Request Sender: [%s]", req_info->sender);
224 if (!g_strcmp0(network->uuid, net_uuid)) {
225 out_param = g_array_new(FALSE, FALSE, sizeof(gchar));
226 g_array_append_vals(out_param, &event->key_idx, sizeof(guint16));
227 _bt_service_method_return(req_info->context, out_param, result);
228 _bt_free_info_from_invocation_list(req_info);
229 g_array_free(out_param, TRUE);
234 case BT_MESH_NETWORK_DELETE_APPKEY:
235 case BT_MESH_NETWORK_UPDATE_APPKEY:
236 case BT_MESH_NETWORK_ADD_APPKEY: {
237 bluetooth_mesh_network_t *network;
238 event_mesh_appkey_operation_t *event;
239 char net_uuid[BLUETOOTH_MESH_NETWORK_UUID_STRING_LENGTH + 1];
241 event = (event_mesh_appkey_operation_t*) param;
242 network = (bluetooth_mesh_network_t*)req_info->user_data;
243 _bt_mesh_util_convert_hex_to_string((uint8_t *) event->net_uuid.uuid, 16, net_uuid,
244 BLUETOOTH_MESH_NETWORK_UUID_STRING_LENGTH + 1);
246 BT_DBG("Request Sender: [%s]", req_info->sender);
247 if (!g_strcmp0(network->uuid, net_uuid)) {
248 out_param = g_array_new(FALSE, FALSE, sizeof(gchar));
249 g_array_append_vals(out_param, &event->app_idx, sizeof(guint16));
250 _bt_service_method_return(req_info->context, out_param, result);
251 _bt_free_info_from_invocation_list(req_info);
252 g_array_free(out_param, TRUE);
257 BT_DBG("Unknown function(%d)", service_function);
263 static void __handle_mesh_network_subnet_operation_event(
264 event_mesh_netkey_operation_t *event)
266 int result = BLUETOOTH_ERROR_NONE;
268 if (event->status != OAL_STATUS_SUCCESS)
269 result = BLUETOOTH_ERROR_INTERNAL;
271 /* Handle DBUS Context return */
272 if (event->op == OAL_MESH_KEY_ADD) {
273 if (result == BLUETOOTH_ERROR_NONE)
274 _bt_mesh_network_handle_netkey_added(event->net_uuid.uuid, event->key_idx);
276 __bt_mesh_handle_pending_request_info(result, BT_MESH_NETWORK_ADD_NETKEY,
277 event, sizeof(event_mesh_netkey_operation_t));
278 } else if (event->op == OAL_MESH_KEY_DELETE) {
279 if (result == BLUETOOTH_ERROR_NONE)
280 _bt_mesh_network_handle_netkey_deleted(event->net_uuid.uuid, event->key_idx);
282 __bt_mesh_handle_pending_request_info(result, BT_MESH_NETWORK_DELETE_NETKEY,
283 event, sizeof(event_mesh_netkey_operation_t));
284 } else if (event->op == OAL_MESH_KEY_UPDATE) {
285 _bt_mesh_network_handle_netkey_updated(event->net_uuid.uuid, event->key_idx);
287 __bt_mesh_handle_pending_request_info(result, BT_MESH_NETWORK_UPDATE_NETKEY,
288 event, sizeof(event_mesh_netkey_operation_t));
292 static void __handle_mesh_network_appkey_operation_event(
293 event_mesh_appkey_operation_t *event)
295 int result = BLUETOOTH_ERROR_NONE;
297 if (event->status != OAL_STATUS_SUCCESS)
298 result = BLUETOOTH_ERROR_INTERNAL;
299 /* Handle DBUS Context return */
300 if (event->op == OAL_MESH_KEY_ADD) {
301 BT_INFO("Mesh: Appkey Add event");
302 if (result == BLUETOOTH_ERROR_NONE)
303 _bt_mesh_network_handle_appkey_added(
304 event->net_uuid.uuid, event->net_idx, event->app_idx);
306 __bt_mesh_handle_pending_request_info(result, BT_MESH_NETWORK_ADD_APPKEY,
307 event, sizeof(event_mesh_netkey_operation_t));
308 } else if (event->op == OAL_MESH_KEY_DELETE) {
309 BT_INFO("Mesh: Appkey Delete event");
310 if (result == BLUETOOTH_ERROR_NONE)
311 _bt_mesh_network_handle_appkey_deleted(
312 event->net_uuid.uuid, event->net_idx, event->app_idx);
314 __bt_mesh_handle_pending_request_info(result, BT_MESH_NETWORK_DELETE_APPKEY,
315 event, sizeof(event_mesh_netkey_operation_t));
316 } else if (event->op == OAL_MESH_KEY_UPDATE) {
317 BT_INFO("Mesh: Appkey Update event");
318 __bt_mesh_handle_pending_request_info(result, BT_MESH_NETWORK_UPDATE_APPKEY,
319 event, sizeof(event_mesh_netkey_operation_t));
323 static void __handle_mesh_devkey_message_received_event(
324 event_mesh_devkey_message_t *event)
326 _bt_mesh_config_client_devkey_msg_handler(event);
329 static void __handle_mesh_network_attached_event(
330 event_mesh_network_attached_t *event)
332 int result = BLUETOOTH_ERROR_NONE;
333 bluetooth_mesh_node_t node;
335 if (event->status != OAL_STATUS_SUCCESS)
336 result = BLUETOOTH_ERROR_INTERNAL;
338 memset(&node, 0x00, sizeof(bluetooth_mesh_node_t));
340 memcpy(node.uuid, event->uuid.uuid, 16);
341 memcpy(node.token.u8, event->token, 8);
343 __bt_mesh_handle_pending_request_info(result,
344 BT_MESH_NETWORK_CREATE,
345 &node, sizeof(bluetooth_mesh_node_t));
346 __bt_mesh_handle_pending_request_info(result,
347 BT_MESH_NETWORK_LOAD,
348 &node, sizeof(bluetooth_mesh_node_t));
351 static void __handle_mesh_network_scan_started_event(
352 event_mesh_scan_status_t *event)
354 GVariant *out_var = NULL, *param = NULL;
356 bluetooth_mesh_network_t network;
358 int result = BLUETOOTH_ERROR_NONE;
359 if (event->status != OAL_STATUS_SUCCESS) {
360 result = BLUETOOTH_ERROR_INTERNAL;
361 _bt_mesh_set_scanning_state(false);
363 _bt_mesh_set_scanning_state(true);
365 /* Handle DBUS Context return */
366 __bt_mesh_handle_pending_request_info(result,
367 BT_MESH_NETWORK_SCAN,
368 event, sizeof(event_mesh_scan_status_t));
370 /* Handle Scan started event */
371 if (result == BLUETOOTH_ERROR_NONE) {
372 memset(&network, 0x00, sizeof(bluetooth_mesh_network_t));
373 _bt_mesh_util_convert_hex_to_string(
374 (uint8_t *) event->net_uuid.uuid, 16, network.uuid,
375 BLUETOOTH_MESH_NETWORK_UUID_STRING_LENGTH + 1);
377 info = g_array_new(FALSE, FALSE, sizeof(gchar));
378 g_array_append_vals(info, &network,
379 sizeof(bluetooth_mesh_network_t));
381 out_var = g_variant_new_from_data((const GVariantType *)"ay",
382 info->data, info->len,
385 param = g_variant_new("(iv)", result, out_var);
386 _bt_send_event(BT_MESH_EVENT,
387 BLUETOOTH_EVENT_MESH_SCAN_STARTED,
392 static void __handle_mesh_network_scan_finished_event(
393 event_mesh_scan_status_t *event)
395 GVariant *out_var = NULL, *param = NULL;
397 bluetooth_mesh_network_t network;
398 int result = BLUETOOTH_ERROR_NONE;
399 if (event->status != OAL_STATUS_SUCCESS) {
400 BT_INFO("Mesh: Scan Finished: status:: FAILED!");
401 result = BLUETOOTH_ERROR_INTERNAL;
403 BT_INFO("Mesh: Scan Finished: status:: SUCCESS!");
405 /* Handle Scan finsihed event */
406 if (result == BLUETOOTH_ERROR_NONE) {
407 memset(&network, 0x00, sizeof(bluetooth_mesh_network_t));
408 _bt_mesh_util_convert_hex_to_string(
409 (uint8_t *) event->net_uuid.uuid, 16, network.uuid,
410 BLUETOOTH_MESH_NETWORK_UUID_STRING_LENGTH + 1);
412 info = g_array_new(FALSE, FALSE, sizeof(gchar));
413 g_array_append_vals(info, &network,
414 sizeof(bluetooth_mesh_network_t));
416 out_var = g_variant_new_from_data((const GVariantType *)"ay",
417 info->data, info->len,
420 param = g_variant_new("(iv)", result, out_var);
421 _bt_send_event(BT_MESH_EVENT,
422 BLUETOOTH_EVENT_MESH_SCAN_FINISHED,
424 _bt_mesh_set_scanning_state(false);
428 static void __handle_mesh_network_provisioning_started_event(
429 event_mesh_provisioning_status_t *status)
431 int result = BLUETOOTH_ERROR_NONE;
432 BT_INFO("Mesh: Provisioning started");
434 __bt_mesh_handle_pending_request_info(result,
435 BT_MESH_NETWORK_PROVISION_DEVICE,
436 status, sizeof(event_mesh_provisioning_status_t));
438 _bt_mesh_set_provisioning_state(true);
441 static void __handle_mesh_network_provisioning_failed_event(
442 event_mesh_provisioning_status_t *status)
444 int result = BLUETOOTH_ERROR_INTERNAL;
445 BT_INFO("Mesh: Provisioning failed!!");
446 __bt_mesh_handle_pending_request_info(result,
447 BT_MESH_NETWORK_PROVISION_DEVICE,
448 status, sizeof(event_mesh_provisioning_status_t));
450 _bt_mesh_set_provisioning_state(false);
453 static void __handle_mesh_network_provisioning_finished_event(
454 event_mesh_provisioning_finished_t *event)
456 GVariant *out_var = NULL, *param = NULL;
458 bluetooth_mesh_provisioning_result_t prov_result;
459 BT_INFO("Mesh: Provisioning Finished!");
461 memset(&prov_result, 0x00,
462 sizeof(bluetooth_mesh_provisioning_result_t));
464 if (event->status != OAL_STATUS_SUCCESS)
465 prov_result.result = BLUETOOTH_ERROR_INTERNAL;
467 prov_result.result = BLUETOOTH_ERROR_NONE;
469 prov_result.reason = event->reason;
470 prov_result.unicast = event->unicast;
471 prov_result.count = event->count;
473 _bt_mesh_util_convert_hex_to_string(
474 (uint8_t *) event->net_uuid.uuid, 16, prov_result.net_uuid,
475 BLUETOOTH_MESH_NETWORK_UUID_STRING_LENGTH + 1);
477 _bt_mesh_util_convert_hex_to_string(
478 (uint8_t *) event->dev_uuid.uuid, 16, prov_result.dev_uuid,
479 BLUETOOTH_MESH_NETWORK_UUID_STRING_LENGTH + 1);
481 info = g_array_new(FALSE, FALSE, sizeof(gchar));
482 g_array_append_vals(info, &prov_result,
483 sizeof(bluetooth_mesh_provisioning_result_t));
485 out_var = g_variant_new_from_data((const GVariantType *)"ay",
486 info->data, info->len,
489 param = g_variant_new("(iv)", prov_result.result, out_var);
490 _bt_send_event(BT_MESH_EVENT,
491 BLUETOOTH_EVENT_MESH_PROVISIONING_FINISHED,
494 /* Add Remote Node entry in Local CDB */
495 if (event->status == OAL_STATUS_SUCCESS) {
496 BT_INFO("Mesh: Provisioning done, add node to Network");
497 BT_INFO("Mesh: Node UUID [%s]", prov_result.dev_uuid);
498 BT_INFO("Mesh: Node Unicast[0x%2.2x] Element Count [%d]",
499 event->unicast, event->count);
501 _bt_mesh_network_add_remote_node(
502 event->net_uuid.uuid, event->dev_uuid.uuid,
503 event->unicast, event->count);
505 /* Unset provisioning state */
506 _bt_mesh_set_provisioning_state(false);
509 static void __handle_mesh_network_provisioning_data_requested_event(
510 event_mesh_provisioning_data_requested_t *event)
512 _bt_mesh_network_request_provisioning_data_request(
513 event->net_uuid.uuid, event->count);
516 static void __handle_mesh_network_authentication_requested_event(
517 event_mesh_authentication_requested_t *event)
519 GVariant *out_var = NULL, *param = NULL;
521 bluetooth_mesh_authentication_request_t auth_req;
523 memset(&auth_req, 0x00,
524 sizeof(bluetooth_mesh_authentication_request_t));
526 auth_req.auth_type = event->auth_type;
527 g_strlcpy(auth_req.auth_value, event->auth_value,
528 sizeof(auth_req.auth_value));
530 _bt_mesh_util_convert_hex_to_string(
531 (uint8_t *) event->net_uuid.uuid, 16, auth_req.net_uuid,
532 BLUETOOTH_MESH_NETWORK_UUID_STRING_LENGTH + 1);
534 BT_INFO("Mesh: Authentication Requested by Device: Network [%s]",
536 info = g_array_new(FALSE, FALSE, sizeof(gchar));
537 g_array_append_vals(info, &auth_req,
538 sizeof(bluetooth_mesh_authentication_request_t));
540 out_var = g_variant_new_from_data((const GVariantType *)"ay",
541 info->data, info->len,
544 param = g_variant_new("(iv)", BLUETOOTH_ERROR_NONE, out_var);
545 _bt_send_event(BT_MESH_EVENT,
546 BLUETOOTH_EVENT_MESH_AUTHENTICATION_REQUEST,
550 static void __handle_mesh_network_scan_result_event(
551 event_mesh_scan_result_t *event)
553 GVariant *out_var = NULL, *param = NULL;
555 bluetooth_mesh_scan_result_t data;
556 int result = BLUETOOTH_ERROR_NONE;
558 memset(&data, 0x00, sizeof(bluetooth_mesh_scan_result_t));
560 /* Fill Network UUID */
561 _bt_mesh_util_convert_hex_to_string(
562 (uint8_t *) event->net_uuid.uuid, 16, data.net_uuid,
563 BLUETOOTH_MESH_NETWORK_UUID_STRING_LENGTH + 1);
565 /* Fill Device UUID */
566 _bt_mesh_util_convert_hex_to_string(
567 (uint8_t *) event->result.dev_uuid.uuid, 16, data.dev_uuid,
568 BLUETOOTH_MESH_NETWORK_UUID_STRING_LENGTH + 1);
571 data.rssi = event->result.rssi;
574 memcpy(&data.oob_info, event->result.oob_info, 2);
576 /* Fill URI Hash Info */
577 memcpy(&data.uri_hash, event->result.uri_hash, 4);
579 if (event->status != OAL_STATUS_SUCCESS)
580 result = BLUETOOTH_ERROR_INTERNAL;
583 info = g_array_new(FALSE, FALSE, sizeof(gchar));
584 g_array_append_vals(info, &data,
585 sizeof(bluetooth_mesh_scan_result_t));
587 out_var = g_variant_new_from_data((const GVariantType *)"ay",
588 info->data, info->len,
591 param = g_variant_new("(iv)", result, out_var);
592 _bt_send_event(BT_MESH_EVENT,
593 BLUETOOTH_EVENT_MESH_SCAN_RESULT,
597 static void __handle_mesh_events(int event_type,
600 BT_INFO("Mesh: Got Mesh event!!! event type [%d]", event_type);
601 if (event_type == OAL_EVENT_MESH_PROVISIONING_STARTED)
602 BT_INFO("Mesh: Provisioning started event");
604 switch (event_type) {
605 case OAL_EVENT_MESH_NETWORK_ATTACHED:
606 __handle_mesh_network_attached_event(
607 (event_mesh_network_attached_t*)event_data);
608 BT_PERMANENT_LOG("Mesh: Network attached!!");
610 case OAL_EVENT_MESH_SCAN_STARTED:
611 __handle_mesh_network_scan_started_event(
612 (event_mesh_scan_status_t*)event_data);
613 BT_PERMANENT_LOG("Mesh: Network Scan Stated!!");
615 case OAL_EVENT_MESH_SCAN_FINISHED:
616 __handle_mesh_network_scan_finished_event(
617 (event_mesh_scan_status_t*)event_data);
618 BT_PERMANENT_LOG("Mesh: Network Scan Finished!!");
620 case OAL_EVENT_MESH_SCAN_RESULT:
621 __handle_mesh_network_scan_result_event(
622 (event_mesh_scan_result_t*)event_data);
623 BT_PERMANENT_LOG("Mesh: Network Scan Result!!");
625 case OAL_EVENT_MESH_PROVISIONING_STARTED:
626 BT_INFO("Mesh: Network Provisioning Started");
627 __handle_mesh_network_provisioning_started_event(
628 (event_mesh_provisioning_status_t*)event_data);
629 BT_PERMANENT_LOG("Mesh: Network Provisioning Started");
631 case OAL_EVENT_MESH_PROVISIONING_FAILED:
632 BT_INFO("Mesh: Network Provisioning Failed!!!!");
633 __handle_mesh_network_provisioning_failed_event(
634 (event_mesh_provisioning_status_t*)event_data);
635 BT_PERMANENT_LOG("Mesh: Network Provisioning Failed");
637 case OAL_EVENT_MESH_PROVISIONING_FINISHED:
638 __handle_mesh_network_provisioning_finished_event(
639 (event_mesh_provisioning_finished_t*)event_data);
640 BT_PERMANENT_LOG("Mesh: Network Provisioning Finished");
642 case OAL_EVENT_MESH_PROVISIONING_DATA_REQUESTED:
643 __handle_mesh_network_provisioning_data_requested_event(
644 (event_mesh_provisioning_data_requested_t*)event_data);
645 BT_PERMANENT_LOG("Mesh: Network Provisioning Data Requested");
647 case OAL_EVENT_MESH_AUTHENTICATION_REQUESTED:
648 __handle_mesh_network_authentication_requested_event(
649 (event_mesh_authentication_requested_t*)event_data);
650 BT_PERMANENT_LOG("Mesh: Network Authentication Requested");
652 case OAL_EVENT_MESH_NETKEY_EXECUTE_EVENT:
653 __handle_mesh_network_subnet_operation_event(
654 (event_mesh_netkey_operation_t*)event_data);
655 BT_PERMANENT_LOG("Mesh: Network Subnet operation event");
657 case OAL_EVENT_MESH_APPKEY_EXECUTE_EVENT:
658 __handle_mesh_network_appkey_operation_event(
659 (event_mesh_appkey_operation_t*)event_data);
660 BT_PERMANENT_LOG("Mesh: AppKey operation event");
662 case OAL_EVENT_MESH_DEVKEY_MESSAGE_RECEIVED:
663 __handle_mesh_devkey_message_received_event(
664 (event_mesh_devkey_message_t*)event_data);
665 BT_PERMANENT_LOG("Mesh: DevKey Message Received event");
672 int _bt_mesh_init(void)
674 int ret = UNIT_CONTROL_OK;
675 oal_status_t status = OAL_STATUS_SUCCESS;
677 /* Launch bluetooth-meshd */
678 ret = actd_start_unit(UNIT_CONTROL_BUS_TYPE_SYSTEM,
679 MESH_SYSTEMD_SERVICE_NAME, 5000);
681 if (ret != UNIT_CONTROL_OK) {
682 BT_ERR("Failed to call systemact service: %d", ret);
683 return BLUETOOTH_ERROR_INTERNAL;
686 status = mesh_enable();
687 if (OAL_STATUS_SUCCESS != status) {
688 BT_ERR("Mesh: Failed to initialize Mesh profile, status: %d",
690 return BLUETOOTH_ERROR_INTERNAL;
692 BT_INFO("Mesh: Stack Initialization Done successfully");
694 /* Register MESH event handler */
695 _bt_service_register_event_handler_callback(BT_MESH_MODULE,
696 __handle_mesh_events);
698 return BLUETOOTH_ERROR_NONE;
701 int _bt_mesh_deinit(void)
703 oal_status_t status = OAL_STATUS_SUCCESS;
704 int ret = UNIT_CONTROL_OK;
706 /* Terminate bluetooth-meshd */
707 ret = actd_stop_unit(UNIT_CONTROL_BUS_TYPE_SYSTEM,
708 MESH_SYSTEMD_SERVICE_NAME, 5000);
710 if (ret != UNIT_CONTROL_OK)
711 BT_ERR("Failed to call systemact service: %d", ret);
713 status = mesh_disable();
714 if (OAL_STATUS_SUCCESS != status) {
715 BT_ERR("Mesh: Failed to de-initialize Mesh profile, status: %d",
717 return BLUETOOTH_ERROR_INTERNAL;
720 /* Register AVRCP target event handler */
721 _bt_service_unregister_event_handler_callback(BT_MESH_MODULE);
723 return BLUETOOTH_ERROR_NONE;