Remove the trust logic in the Robot profile
[platform/core/connectivity/bluetooth-frwk.git] / bt-oal / oal-mesh.c
1 /*
2  * Open Adaptation Layer (OAL)
3  *
4  * Copyright (c) 2020 Samsung Electronics Co., Ltd.
5  *
6  * @author: Anupam Roy <anupam.r@samsung.com>
7  *
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
11  *
12  *              http://www.apache.org/licenses/LICENSE-2.0
13  *
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.
19  *
20  */
21 #include <dlog.h>
22 #include <bluetooth.h>
23 #include "bt_mesh.h"
24
25 #include "oal-event.h"
26 #include "oal-internal.h"
27 #include "oal-manager.h"
28 #include "oal-adapter-mgr.h"
29 #include "oal-utils.h"
30 #include "oal-mesh.h"
31 #include "oal-common.h"
32
33
34 static const bt_interface_t *blued_api;
35 static const btmesh_interface_t *mesh_api;
36
37 #define CHECK_OAL_MESH_ENABLED() \
38         do { \
39                 if (mesh_api == NULL) { \
40                         BT_ERR("Mesh Not Enabled"); \
41                         return OAL_STATUS_NOT_READY; \
42                 } \
43         } while (0)
44
45 /* Forward declaration: Callbacks from HAL */
46 static void mesh_network_proxy_added_callback(bt_status_t status);
47 static void mesh_network_attached_callback(bt_status_t status,
48                 bool is_prov, bt_mesh_token_t *token, bt_uuid_t *uuid);
49 static void mesh_network_destroyed_callback(bt_status_t status,
50                 bt_mesh_token_t *token, bt_uuid_t *uuid);
51 static void mesh_network_scan_status_callback(bt_mesh_scan_state_t scan_state,
52                 bt_status_t status, bt_uuid_t *net_uuid);
53 static void mesh_network_scan_result_callback(bt_status_t status,
54                 bt_uuid_t *net_uuid, bt_mesh_scan_result_t *result);
55 static void mesh_network_provisioning_status_callback(bt_status_t status,
56                 bt_uuid_t *net_uuid, bt_uuid_t *dev_uuid);
57 static void mesh_network_provisioning_finished_callback(bt_status_t status,
58                 int reason, bt_uuid_t *net_uuid,
59                         bt_uuid_t *dev_uuid, uint16_t unicast, uint8_t count);
60 static void mesh_network_provisioning_data_requested_callback(
61                 bt_uuid_t *net_uuid, uint8_t count);
62 static void mesh_network_authentication_requested_callback(bt_uuid_t *net_uuid,
63                 bt_hal_mesh_auth_variant_e auth_type, char auth_value[]);
64 static void mesh_network_netkey_execute_callback(bt_status_t status,
65                 bt_uuid_t *net_uuid, uint8_t key_event, uint16_t netkey_idx);
66 static void mesh_network_appkey_execute_callback(bt_status_t status,
67                 bt_uuid_t *net_uuid, uint8_t key_event, uint16_t netkey_idx, uint16_t appkey_idx);
68 static void mesh_network_appkey_execute_callback(bt_status_t status,
69                 bt_uuid_t *net_uuid, uint8_t key_event, uint16_t netkey_idx, uint16_t appkey_idx);
70 static void mesh_devkey_message_received_callback(bt_uuid_t *net_uuid,
71                 uint16_t source_addr, bool is_remote_devkey,
72                         uint16_t netkey_idx, uint16_t ata_len, uint8_t *data);
73 static void mesh_message_received_callback(bt_uuid_t *net_uuid, bool is_prov,
74                 uint16_t source_addr, uint16_t dest_addr,
75                         uint16_t key_idx, uint16_t data_len, uint8_t *data);
76
77
78 static btmesh_callbacks_t sBluetoothMeshCallbacks = {
79         .size = sizeof(sBluetoothMeshCallbacks),
80         .network_proxy_added_cb = mesh_network_proxy_added_callback,
81         .network_attached_cb = mesh_network_attached_callback,
82         .network_destroyed_cb = mesh_network_destroyed_callback,
83         .scan_status_cb = mesh_network_scan_status_callback,
84         .scan_result_cb = mesh_network_scan_result_callback,
85         .provisioning_status_cb = mesh_network_provisioning_status_callback,
86         .provisioning_finished_cb = mesh_network_provisioning_finished_callback,
87         .provisioning_data_requested_cb = mesh_network_provisioning_data_requested_callback,
88         .authentication_requested_cb = mesh_network_authentication_requested_callback,
89         .netkey_execute_cb = mesh_network_netkey_execute_callback,
90         .appkey_execute_cb = mesh_network_appkey_execute_callback,
91         .devkey_msg_cb = mesh_devkey_message_received_callback,
92         .msg_cb = mesh_message_received_callback,
93 };
94
95 /* Mesh HAL event handlers */
96 static void mesh_network_proxy_added_callback(bt_status_t status)
97 {
98         event_mesh_network_proxy_added_t *event = g_new0(event_mesh_network_proxy_added_t, 1);
99
100         event->status = convert_to_oal_status(status);
101         BT_INFO("Mesh Event: Network Proxy Added, status: [%s]",
102                 status2string(status));
103
104         send_event_bda_trace(OAL_EVENT_MESH_NETWORK_PROXY_ADDED,
105                 event, sizeof(event_mesh_network_proxy_added_t), NULL);
106 }
107
108 static void mesh_network_attached_callback(bt_status_t status, bool is_prov,
109                 bt_mesh_token_t *token, bt_uuid_t *uuid)
110 {
111         event_mesh_network_attached_t *event = g_new0(event_mesh_network_attached_t, 1);
112
113         event->status = convert_to_oal_status(status);
114         BT_INFO("Mesh Event: Network Attached, status: [%s]",
115                 status2string(status));
116
117         memcpy(event->token, token->token, sizeof(bt_mesh_token_t));
118         memcpy(event->uuid.uuid, uuid->uu, sizeof(bt_uuid_t));
119         event->is_prov = is_prov;
120
121         send_event_bda_trace(OAL_EVENT_MESH_NETWORK_ATTACHED,
122                 event, sizeof(event_mesh_network_attached_t), NULL);
123 }
124
125 static void mesh_network_destroyed_callback(bt_status_t status,
126                 bt_mesh_token_t *token, bt_uuid_t *uuid)
127 {
128         event_mesh_network_attached_t *event = g_new0(event_mesh_network_attached_t, 1);
129
130         event->status = convert_to_oal_status(status);
131         BT_INFO("Mesh Event: Network Destroyed, status: [%s]",
132                         status2string(status));
133
134         memcpy(event->token, token->token, sizeof(bt_mesh_token_t));
135         memcpy(event->uuid.uuid, uuid->uu, sizeof(bt_uuid_t));
136
137         send_event_bda_trace(OAL_EVENT_MESH_NETWORK_DESTROYED,
138                         event, sizeof(event_mesh_network_destroyed_t), NULL);
139 }
140
141 static void mesh_network_scan_status_callback(bt_mesh_scan_state_t scan_state,
142                 bt_status_t status, bt_uuid_t *net_uuid)
143 {
144         event_mesh_scan_status_t *event_data = g_new0(event_mesh_scan_status_t, 1);
145         oal_event_t event;
146
147         event_data->status = convert_to_oal_status(status);
148         BT_INFO("Mesh Event: Scan status: [%s] state [%d]",
149                 status2string(status), scan_state);
150
151         memcpy(event_data->net_uuid.uuid, net_uuid->uu, sizeof(bt_uuid_t));
152
153         event = (BT_MESH_SCAN_STARTED == scan_state) ? \
154                 OAL_EVENT_MESH_SCAN_STARTED : OAL_EVENT_MESH_SCAN_FINISHED;
155         send_event_bda_trace(event, event_data,
156                 sizeof(event_mesh_scan_status_t), NULL);
157 }
158
159 static void mesh_network_provisioning_status_callback(bt_status_t status,
160                 bt_uuid_t *net_uuid, bt_uuid_t *dev_uuid)
161 {
162         event_mesh_provisioning_status_t *event = g_new0(event_mesh_provisioning_status_t, 1);
163
164         event->status = convert_to_oal_status(status);
165         BT_INFO("Mesh Event: Provisioning status: [%s]",
166                 status2string(status));
167
168         memcpy(event->net_uuid.uuid, net_uuid->uu, sizeof(bt_uuid_t));
169         memcpy(event->dev_uuid.uuid, dev_uuid->uu, sizeof(bt_uuid_t));
170
171         if (event->status == OAL_STATUS_SUCCESS)
172                 send_event_bda_trace(OAL_EVENT_MESH_PROVISIONING_STARTED,
173                         event, sizeof(event_mesh_provisioning_status_t), NULL);
174         else
175                 send_event_bda_trace(OAL_EVENT_MESH_PROVISIONING_FAILED,
176                         event, sizeof(event_mesh_provisioning_status_t), NULL);
177 }
178
179 static void mesh_network_provisioning_finished_callback(bt_status_t status,
180                 int reason, bt_uuid_t *net_uuid,
181                         bt_uuid_t *dev_uuid, uint16_t unicast, uint8_t count)
182 {
183         event_mesh_provisioning_finished_t *event = \
184                 g_new0(event_mesh_provisioning_finished_t, 1);
185
186         event->status = convert_to_oal_status(status);
187         event->reason = reason;
188         BT_INFO("Mesh Event: Provisioning Completed Result: [%s]",
189                 status2string(status));
190
191         memcpy(event->net_uuid.uuid, net_uuid->uu, sizeof(bt_uuid_t));
192         memcpy(event->dev_uuid.uuid, dev_uuid->uu, sizeof(bt_uuid_t));
193         event->unicast = unicast;
194         event->count = count;
195
196         send_event_bda_trace(OAL_EVENT_MESH_PROVISIONING_FINISHED,
197                 event, sizeof(event_mesh_provisioning_finished_t), NULL);
198 }
199
200 static void mesh_network_provisioning_data_requested_callback(
201                 bt_uuid_t *net_uuid, uint8_t count)
202 {
203         event_mesh_provisioning_data_requested_t *event = \
204                 g_new0(event_mesh_provisioning_data_requested_t, 1);
205
206         BT_INFO("Mesh Event: Provisioning Data requested");
207
208         memcpy(event->net_uuid.uuid, net_uuid->uu, sizeof(bt_uuid_t));
209         event->count = count;
210
211         send_event_bda_trace(OAL_EVENT_MESH_PROVISIONING_DATA_REQUESTED,
212                 event, sizeof(event_mesh_provisioning_data_requested_t), NULL);
213 }
214
215 static void mesh_network_authentication_requested_callback(bt_uuid_t *net_uuid,
216                 bt_hal_mesh_auth_variant_e auth_type,
217                         char auth_value[])
218 {
219         event_mesh_authentication_requested_t *event = \
220                 g_new0(event_mesh_authentication_requested_t, 1);
221
222         BT_INFO("Mesh Event: Authentication requested");
223
224         memcpy(event->net_uuid.uuid, net_uuid->uu, sizeof(bt_uuid_t));
225         event->auth_type = auth_type;
226         g_strlcpy(event->auth_value, auth_value, sizeof(event->auth_value));
227
228         send_event_bda_trace(OAL_EVENT_MESH_AUTHENTICATION_REQUESTED,
229                 event, sizeof(event_mesh_provisioning_data_requested_t), NULL);
230 }
231
232 static void mesh_network_netkey_execute_callback(bt_status_t status,
233                 bt_uuid_t *net_uuid, uint8_t key_event, uint16_t index)
234 {
235         event_mesh_netkey_operation_t *event = \
236                 g_new0(event_mesh_netkey_operation_t, 1);
237
238         event->status = convert_to_oal_status(status);
239         BT_INFO("Mesh Event: NetKey Execute Event");
240
241         memcpy(event->net_uuid.uuid, net_uuid->uu, sizeof(bt_uuid_t));
242         event->op = (oal_mesh_key_op_e)key_event;
243         event->key_idx = index;
244
245         send_event_bda_trace(OAL_EVENT_MESH_NETKEY_EXECUTE_EVENT,
246                 event, sizeof(event_mesh_netkey_operation_t), NULL);
247 }
248
249 static void mesh_network_appkey_execute_callback(bt_status_t status,
250                 bt_uuid_t *net_uuid, uint8_t key_event,
251                         uint16_t net_idx, uint16_t app_idx)
252 {
253         event_mesh_appkey_operation_t *event = \
254                 g_new0(event_mesh_appkey_operation_t, 1);
255
256         event->status = convert_to_oal_status(status);
257         BT_INFO("Mesh Event: AppKey Execute Event");
258
259         memcpy(event->net_uuid.uuid, net_uuid->uu, sizeof(bt_uuid_t));
260         event->op = (oal_mesh_key_op_e)key_event;
261         event->net_idx = net_idx;
262         event->app_idx = app_idx;
263
264         send_event_bda_trace(OAL_EVENT_MESH_APPKEY_EXECUTE_EVENT,
265                 event, sizeof(event_mesh_appkey_operation_t), NULL);
266 }
267
268 static void mesh_network_scan_result_callback(bt_status_t status,
269                 bt_uuid_t *net_uuid, bt_mesh_scan_result_t *result)
270 {
271         event_mesh_scan_result_t *event = g_new0(event_mesh_scan_result_t, 1);
272
273         event->status = convert_to_oal_status(status);
274         BT_INFO("Mesh Event: Scan Result status: [%s]",
275                 status2string(status));
276
277         memcpy(event->net_uuid.uuid, net_uuid->uu, sizeof(bt_uuid_t));
278         memcpy(&event->result, result, sizeof(bt_mesh_scan_result_t));
279
280         send_event_bda_trace(OAL_EVENT_MESH_SCAN_RESULT,
281                 event, sizeof(event_mesh_scan_result_t), NULL);
282 }
283
284 static void mesh_devkey_message_received_callback(bt_uuid_t *net_uuid,
285                 uint16_t source_addr,
286                         bool is_remote_devkey, uint16_t netkey_idx,
287                                 uint16_t data_len, uint8_t *data)
288 {
289         event_mesh_devkey_message_t *event = g_new0(event_mesh_devkey_message_t, 1);
290
291         BT_INFO("Mesh Event: Dev Key Message Received");
292         event->source = source_addr;
293         event->remote = is_remote_devkey;
294         event->subnet = netkey_idx;
295         event->data_len = data_len;
296         memcpy(event->net_uuid.uuid, net_uuid->uu, sizeof(bt_uuid_t));
297         memcpy(event->data, data, data_len);
298
299         send_event_bda_trace(OAL_EVENT_MESH_DEVKEY_MESSAGE_RECEIVED, event,
300                 sizeof(event_mesh_devkey_message_t), NULL);
301 }
302
303 static void mesh_message_received_callback(bt_uuid_t *net_uuid, bool is_prov,
304                 uint16_t source_addr, uint16_t dest_addr, uint16_t key_idx,
305                                 uint16_t data_len, uint8_t *data)
306 {
307         event_mesh_message_t *event = g_new0(event_mesh_message_t, 1);
308
309         BT_INFO("Mesh Event: Model Message Received");
310         event->source = source_addr;
311         event->is_prov = is_prov;
312         event->dest = dest_addr;
313         event->key_idx = key_idx;
314         event->data_len = data_len;
315         memcpy(event->net_uuid.uuid, net_uuid->uu, sizeof(bt_uuid_t));
316         memcpy(event->data, data, data_len);
317
318         send_event_bda_trace(OAL_EVENT_MESH_MODEL_MESSAGE_RECEIVED, event,
319                 sizeof(event_mesh_message_t), NULL);
320 }
321
322 oal_status_t mesh_enable(void)
323 {
324         int ret;
325         API_TRACE();
326
327         /* Get stack interface */
328         blued_api = (const bt_interface_t *) adapter_get_stack_interface();
329
330         if (blued_api == NULL) {
331                 BT_ERR("Stack is not initialized");
332                 return OAL_STATUS_NOT_READY;
333         }
334
335         if (mesh_api) {
336                 BT_WARN("MESH Interface is already initialized...");
337                 return OAL_STATUS_ALREADY_DONE;
338         }
339
340         mesh_api = (const btmesh_interface_t *)blued_api->get_profile_interface(BT_PROFILE_MESH_ID);
341         if (mesh_api == NULL) {
342                 BT_ERR("MESH interface failed");
343                 return OAL_STATUS_INTERNAL_ERROR;
344         }
345
346         if ((ret = mesh_api->init(&sBluetoothMeshCallbacks)) != BT_STATUS_SUCCESS) {
347                 BT_ERR("Error: Unable to initialise MESH :%s", status2string(ret));
348                 mesh_api->cleanup();
349                 mesh_api = NULL;
350                 return convert_to_oal_status(ret);
351         }
352
353         BT_INFO("MESH successfully initialized");
354         return OAL_STATUS_SUCCESS;
355 }
356
357 oal_status_t mesh_disable(void)
358 {
359         API_TRACE();
360         CHECK_OAL_MESH_ENABLED();
361
362         mesh_api->cleanup();
363
364         mesh_api = NULL;
365         return OAL_STATUS_SUCCESS;
366 }
367
368 oal_status_t mesh_register_node(oal_mesh_node_t *node,
369                 GSList *model_list, bool is_provisioner)
370 {
371         int ret = BT_STATUS_SUCCESS;
372         API_TRACE();
373         CHECK_OAL_MESH_ENABLED();
374
375         if (is_provisioner) {
376                 BT_INFO("Mesh: Send create network request to stack");
377                 ret = mesh_api->create((bt_hal_mesh_node_t*)node, model_list, is_provisioner);
378                 if (ret != BT_STATUS_SUCCESS) {
379                         BT_ERR("MESH: Create Network failed :failed: %s", status2string(ret));
380                         return convert_to_oal_status(ret);
381                 }
382         } else {
383                 BT_INFO("Mesh: Send join network request to stack");
384                 ret = mesh_api->join((bt_hal_mesh_node_t*)node, model_list);
385                 if (ret != BT_STATUS_SUCCESS) {
386                         return convert_to_oal_status(ret);
387                 }
388         }
389
390         BT_INFO("Mesh: Request sent to stack");
391         return OAL_STATUS_SUCCESS;
392 }
393
394 oal_status_t mesh_cancel_join(oal_uuid_t* node_uuid)
395 {
396         int ret = BT_STATUS_SUCCESS;
397         API_TRACE();
398         CHECK_OAL_MESH_ENABLED();
399
400         BT_INFO("Mesh: Send cancel join request to stack");
401         ret = mesh_api->cancel((bt_uuid_t*)node_uuid);
402         if (ret != BT_STATUS_SUCCESS) {
403                  BT_ERR("MESH: cancel join failed: %s", status2string(ret));
404                  return convert_to_oal_status(ret);
405         }
406
407         return OAL_STATUS_SUCCESS;
408 }
409
410 oal_status_t mesh_network_release(oal_uuid_t* network_uuid)
411 {
412         int ret = BT_STATUS_SUCCESS;
413         API_TRACE();
414         CHECK_OAL_MESH_ENABLED();
415
416         BT_INFO("Mesh: Send Release Network request to stack");
417         ret = mesh_api->release((bt_uuid_t*)network_uuid);
418         if (ret != BT_STATUS_SUCCESS) {
419                 BT_ERR("MESH: Network Leave failed: %s", status2string(ret));
420                 return convert_to_oal_status(ret);
421         }
422
423         return OAL_STATUS_SUCCESS;
424 }
425
426 oal_status_t mesh_network_destroy(oal_uuid_t* network_uuid)
427 {
428         int ret = BT_STATUS_SUCCESS;
429         API_TRACE();
430         CHECK_OAL_MESH_ENABLED();
431
432         ret = mesh_api->destroy((bt_uuid_t*)network_uuid);
433         if (ret != BT_STATUS_SUCCESS) {
434                 BT_ERR("MESH: Network Leave failed: %s", status2string(ret));
435                 return convert_to_oal_status(ret);
436         }
437
438         return OAL_STATUS_SUCCESS;
439 }
440
441 oal_status_t mesh_delete_remote_node(oal_uuid_t* network_uuid,
442                 uint16_t unicast, uint16_t num_elements)
443 {
444         int ret = BT_STATUS_SUCCESS;
445         API_TRACE();
446         CHECK_OAL_MESH_ENABLED();
447
448         ret = mesh_api->delete_node((bt_uuid_t*)network_uuid, unicast, num_elements);
449         if (ret != BT_STATUS_SUCCESS) {
450                 BT_ERR("Mesh: Remote Node Deletion failed: %s", status2string(ret));
451                 return convert_to_oal_status(ret);
452         }
453
454         return OAL_STATUS_SUCCESS;
455 }
456
457 oal_status_t mesh_network_start_scan(oal_uuid_t* network_uuid,
458                 oal_mesh_scan_params_t *params)
459 {
460         int ret = BT_STATUS_SUCCESS;
461         API_TRACE();
462         CHECK_OAL_MESH_ENABLED();
463
464         ret = mesh_api->scan((bt_uuid_t*)network_uuid,
465                 (bt_hal_mesh_scan_param_t*)params);
466         if (ret != BT_STATUS_SUCCESS) {
467                 BT_ERR("MESH: Start Scan failed: %s", status2string(ret));
468                 return convert_to_oal_status(ret);
469         }
470
471         return OAL_STATUS_SUCCESS;
472 }
473
474 oal_status_t mesh_network_scan_cancel(oal_uuid_t* network_uuid)
475 {
476         int ret = BT_STATUS_SUCCESS;
477         API_TRACE();
478         CHECK_OAL_MESH_ENABLED();
479
480         ret = mesh_api->scan_cancel((bt_uuid_t*)network_uuid);
481         if (ret != BT_STATUS_SUCCESS) {
482                 BT_ERR("MESH: Scan Cancel failed: %s", status2string(ret));
483                 return convert_to_oal_status(ret);
484         }
485
486         return OAL_STATUS_SUCCESS;
487 }
488
489 oal_status_t mesh_network_set_provisioning_capabilities(
490                 oal_uuid_t *network_uuid,
491                          oal_mesh_capabilities_t *caps)
492 {
493         int ret = BT_STATUS_SUCCESS;
494         API_TRACE();
495         CHECK_OAL_MESH_ENABLED();
496
497         ret = mesh_api->capability((bt_uuid_t*)network_uuid,
498                 (bt_hal_mesh_prov_caps_t*)caps);
499         if (ret != BT_STATUS_SUCCESS) {
500                 BT_ERR("MESH: Set Provisioning capabilities :failed: %s",
501                         status2string(ret));
502                 return convert_to_oal_status(ret);
503         }
504
505         return OAL_STATUS_SUCCESS;
506 }
507
508 oal_status_t mesh_conf_send_message(oal_uuid_t *network_uuid,
509                 uint16_t dest, bool is_devkey_remote,
510                         uint16_t netkey_idx, uint8_t *buf, int len)
511 {
512         int ret = BT_STATUS_SUCCESS;
513         API_TRACE();
514         CHECK_OAL_MESH_ENABLED();
515
516         ret = mesh_api->config_send((bt_uuid_t*)network_uuid,
517                         dest, is_devkey_remote, netkey_idx, buf, len);
518         if (ret != BT_STATUS_SUCCESS) {
519                 BT_ERR("MESH: Configuration Message sending failed: %s",
520                         status2string(ret));
521                 return convert_to_oal_status(ret);
522         }
523
524         return OAL_STATUS_SUCCESS;
525 }
526
527 oal_status_t mesh_conf_send_key_message(oal_uuid_t *network_uuid,
528                 uint16_t dest, bool is_netkey,
529                         bool is_update, int key_idx, int netkey_idx)
530 {
531         int ret = BT_STATUS_SUCCESS;
532         API_TRACE();
533         CHECK_OAL_MESH_ENABLED();
534
535         ret = mesh_api->key_send((bt_uuid_t*)network_uuid, dest,
536                         is_netkey, is_update, key_idx, netkey_idx);
537         if (ret != BT_STATUS_SUCCESS) {
538                 BT_ERR("MESH: Key Configuration Message sending failed: %s",
539                         status2string(ret));
540                 return convert_to_oal_status(ret);
541         }
542
543         return OAL_STATUS_SUCCESS;
544 }
545
546 oal_status_t mesh_model_send_message(oal_uuid_t *network_uuid,
547                 uint16_t dest, uint16_t appkey_idx,
548                 uint8_t *buf, int len)
549 {
550         int ret = BT_STATUS_SUCCESS;
551         API_TRACE();
552         CHECK_OAL_MESH_ENABLED();
553
554         ret = mesh_api->msg_execute((bt_uuid_t*)network_uuid,
555                         dest, appkey_idx, buf, len);
556         if (ret != BT_STATUS_SUCCESS) {
557                 BT_ERR("MESH: Model Message sending failed: %s",
558                         status2string(ret));
559                 return convert_to_oal_status(ret);
560         }
561
562         return OAL_STATUS_SUCCESS;
563 }
564
565 oal_status_t mesh_network_provision_device(oal_uuid_t* network_uuid,
566                 oal_uuid_t *dev_uuid)
567 {
568         int ret = BT_STATUS_SUCCESS;
569         API_TRACE();
570         CHECK_OAL_MESH_ENABLED();
571
572         ret = mesh_api->provision((bt_uuid_t*)network_uuid, (bt_uuid_t *)dev_uuid);
573         if (ret != BT_STATUS_SUCCESS) {
574                 BT_ERR("MESH: Device Provisioning :failed: %s",
575                         status2string(ret));
576                 return convert_to_oal_status(ret);
577         }
578
579         return OAL_STATUS_SUCCESS;
580 }
581
582 oal_status_t mesh_network_send_provisioning_data(oal_uuid_t* network_uuid,
583                 uint16_t netkey_idx, uint16_t unicast)
584 {
585         int ret = BT_STATUS_SUCCESS;
586         API_TRACE();
587         CHECK_OAL_MESH_ENABLED();
588
589         ret = mesh_api->provision_data((bt_uuid_t*)network_uuid, netkey_idx, unicast);
590         if (ret != BT_STATUS_SUCCESS) {
591                 BT_ERR("MESH: Device Provisioning :failed: %s",
592                         status2string(ret));
593                 return convert_to_oal_status(ret);
594         }
595
596         return OAL_STATUS_SUCCESS;
597 }
598
599 oal_status_t mesh_network_subnet_execute(oal_uuid_t* network_uuid,
600                 oal_mesh_key_op_e operation, uint16_t net_index)
601 {
602         int ret = BT_STATUS_SUCCESS;
603         API_TRACE();
604         CHECK_OAL_MESH_ENABLED();
605
606         ret = mesh_api->subnet_execute((bt_uuid_t*)network_uuid,
607                 (bt_mesh_key_op_e)operation, net_index);
608         if (ret != BT_STATUS_SUCCESS) {
609                 BT_ERR("MESH: Create Subnet :failed: %s", status2string(ret));
610                 return convert_to_oal_status(ret);
611         }
612
613         return OAL_STATUS_SUCCESS;
614 }
615
616 oal_status_t mesh_network_appkey_execute(oal_uuid_t* network_uuid,
617                 oal_mesh_key_op_e operation,
618                         uint16_t net_index, uint16_t app_index)
619 {
620         int ret = BT_STATUS_SUCCESS;
621         API_TRACE();
622         CHECK_OAL_MESH_ENABLED();
623
624         ret = mesh_api->appkey_execute((bt_uuid_t*)network_uuid,
625                 (bt_mesh_key_op_e)operation,
626                         net_index, app_index);
627         if (ret != BT_STATUS_SUCCESS) {
628                 BT_ERR("MESH: Create Subnet :failed: %s",
629                         status2string(ret));
630                 return convert_to_oal_status(ret);
631         }
632
633         return OAL_STATUS_SUCCESS;
634 }
635
636 oal_status_t mesh_authentication_reply(
637                 oal_mesh_variant_authentication_e auth_type,
638                         const char* auth_value)
639 {
640         int ret = BT_STATUS_SUCCESS;
641         API_TRACE();
642         CHECK_OAL_MESH_ENABLED();
643
644         ret = mesh_api->auth_reply((bt_hal_mesh_auth_variant_e)auth_type,
645                         auth_value);
646         if (ret != BT_STATUS_SUCCESS) {
647                 BT_ERR("MESH: Device Provisioning :failed: %s",
648                         status2string(ret));
649                 return convert_to_oal_status(ret);
650         }
651
652         return OAL_STATUS_SUCCESS;
653 }