2 * Copyright (c) 2020 Samsung Electronics Co., Ltd All Rights Reserved
4 * @author: Anupam Roy <anupam.r@samsung.com>
6 * Licensed under the Apache License, Version 2.0 (the "License");
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
10 * http://www.apache.org/licenses/LICENSE-2.0
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
20 #include "bluetooth-api.h"
21 #include "bt-internal-types.h"
23 #include "bt-common.h"
24 #include "bt-request-sender.h"
25 #include "bt-event-handler.h"
27 #include "bluetooth-mesh-api.h"
29 #define BLUETOOTH_MESH_NETWORK_NAME_STRING_MAX 100
30 #define BLUETOOTH_MESH_TOKEN_STRING_MAX 100
32 BT_EXPORT_API int bluetooth_mesh_init(mesh_cb_func_ptr cb,
38 BT_ERR("callback is NULL");
39 return BLUETOOTH_ERROR_INVALID_PARAM;
43 BT_ALLOC_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
45 ret = _bt_send_request(BT_BLUEZ_SERVICE, BT_MESH_INIT,
46 in_param1, in_param2, in_param3, in_param4, &out_param);
48 BT_FREE_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
50 if (ret != BLUETOOTH_ERROR_NONE) {
51 BT_ERR("Fail to init the mesh in bt-service");
55 ret = _bt_init_event_handler();
57 if (ret != BLUETOOTH_ERROR_NONE &&
58 ret != BLUETOOTH_ERROR_ALREADY_INITIALIZED) {
59 BT_ERR("Fail to init the event handler");
63 _bt_set_user_data(BT_MESH, (void *)cb, user_data);
65 /* Register All events */
66 ret = _bt_register_event(BT_MESH_EVENT, (void *)cb, user_data);
67 if (ret != BLUETOOTH_ERROR_NONE &&
68 ret != BLUETOOTH_ERROR_ALREADY_INITIALIZED) {
69 _bt_deinit_event_handler();
73 BT_INFO("Mesh: Event registsred");
74 return BLUETOOTH_ERROR_NONE;
77 BT_EXPORT_API int bluetooth_mesh_deinit(void)
81 _bt_unregister_event(BT_MESH_EVENT);
82 _bt_set_user_data(BT_MESH, NULL, NULL);
85 BT_ALLOC_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
87 ret = _bt_send_request(BT_BLUEZ_SERVICE, BT_MESH_DEINIT,
88 in_param1, in_param2, in_param3, in_param4, &out_param);
90 BT_FREE_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
92 if (ret != BLUETOOTH_ERROR_NONE) {
93 BT_ERR("Fail to init the mesh in bt-service");
97 return BLUETOOTH_ERROR_NONE;
100 BT_EXPORT_API int bluetooth_mesh_network_create(
101 const char *net_name, bluetooth_mesh_node_t *node,
102 uint16_t total_models, bluetooth_mesh_model_t **models,
103 bluetooth_mesh_network_t *network)
106 char network_name[BLUETOOTH_MESH_NETWORK_NAME_STRING_MAX+1];
108 BT_CHECK_PARAMETER(net_name, return);
109 BT_CHECK_PARAMETER(node, return);
110 BT_CHECK_PARAMETER(models, return);
113 BT_ALLOC_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
115 g_array_append_vals(in_param1, node, sizeof(bluetooth_mesh_node_t));
117 g_strlcpy(network_name, net_name, sizeof(network_name));
118 g_array_append_vals(in_param2, network_name,
119 BLUETOOTH_MESH_NETWORK_NAME_STRING_MAX);
121 for (int i = 0; i < total_models; i++)
122 g_array_append_vals(in_param3, models[i],
123 sizeof(bluetooth_mesh_model_t));
125 result = _bt_send_request(BT_BLUEZ_SERVICE,
126 BT_MESH_NETWORK_CREATE,
127 in_param1, in_param2, in_param3,
128 in_param4, &out_param);
130 if (result == BLUETOOTH_ERROR_NONE) {
131 *network = g_array_index(out_param,
132 bluetooth_mesh_network_t, 0);
135 BT_FREE_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
140 BT_EXPORT_API int bluetooth_mesh_network_load(
142 bluetooth_mesh_network_t *network)
145 char token_string[BLUETOOTH_MESH_TOKEN_STRING_MAX + 1];
147 BT_CHECK_PARAMETER(token, return);
148 BT_CHECK_PARAMETER(network, return);
151 BT_ALLOC_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
153 g_strlcpy(token_string, token, sizeof(token_string));
154 g_array_append_vals(in_param1, token_string, BLUETOOTH_MESH_TOKEN_STRING_MAX);
156 result = _bt_send_request(BT_BLUEZ_SERVICE, BT_MESH_NETWORK_LOAD,
157 in_param1, in_param2, in_param3, in_param4, &out_param);
159 if (result == BLUETOOTH_ERROR_NONE) {
160 *network = g_array_index(out_param,
161 bluetooth_mesh_network_t, 0);
164 BT_FREE_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
169 BT_EXPORT_API int bluetooth_mesh_network_scan(
170 bluetooth_mesh_network_t *network,
171 bluetooth_mesh_scan_param_t *scan_param)
175 BT_CHECK_PARAMETER(network, return);
176 BT_CHECK_PARAMETER(scan_param, return);
179 BT_ALLOC_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
181 g_array_append_vals(in_param1, network, sizeof(bluetooth_mesh_network_t));
183 g_array_append_vals(in_param2, scan_param, sizeof(bluetooth_mesh_scan_param_t));
185 BT_INFO("Mesh:Start Scan, time [%u]", scan_param->scan_time);
186 result = _bt_send_request(BT_BLUEZ_SERVICE, BT_MESH_NETWORK_SCAN,
187 in_param1, in_param2, in_param3, in_param4, &out_param);
188 BT_FREE_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
193 BT_EXPORT_API int bluetooth_mesh_network_cancel_scan(
194 bluetooth_mesh_network_t *network)
198 BT_CHECK_PARAMETER(network, return);
201 BT_ALLOC_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
203 g_array_append_vals(in_param1, network, sizeof(bluetooth_mesh_network_t));
205 BT_INFO("Mesh: Cancel Scan");
206 result = _bt_send_request(BT_BLUEZ_SERVICE, BT_MESH_NETWORK_CANCEL_SCAN,
207 in_param1, in_param2, in_param3, in_param4, &out_param);
208 BT_FREE_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
213 BT_EXPORT_API int bluetooth_mesh_network_set_capabilities(
214 bluetooth_mesh_network_t *network,
215 bluetooth_mesh_provisioner_caps_t *caps)
219 BT_CHECK_PARAMETER(network, return);
220 BT_CHECK_PARAMETER(caps, return);
223 BT_ALLOC_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
225 g_array_append_vals(in_param1, network, sizeof(bluetooth_mesh_network_t));
227 g_array_append_vals(in_param2, caps, sizeof(bluetooth_mesh_provisioner_caps_t));
229 BT_INFO("Mesh: Set Provisioner capabilities");
230 result = _bt_send_request(BT_BLUEZ_SERVICE, BT_MESH_NETWORK_SET_CAPABILITIES,
231 in_param1, in_param2, in_param3, in_param4, &out_param);
232 BT_FREE_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
237 BT_EXPORT_API int bluetooth_mesh_network_provision_device(
238 bluetooth_mesh_provisioning_request_t *req)
241 bt_user_info_t *user_info;
243 BT_CHECK_PARAMETER(req, return);
245 user_info = _bt_get_user_data(BT_MESH);
246 retv_if(user_info->cb == NULL, BLUETOOTH_ERROR_INTERNAL);
249 BT_ALLOC_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
251 g_array_append_vals(in_param1, req,
252 sizeof(bluetooth_mesh_provisioning_request_t));
254 BT_INFO("Mesh: Set Provision Device");
255 result = _bt_send_request_async(BT_BLUEZ_SERVICE,
256 BT_MESH_NETWORK_PROVISION_DEVICE,
257 in_param1, in_param2, in_param3, in_param4,
258 user_info->cb, user_info->user_data);
260 BT_FREE_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
265 BT_EXPORT_API int bluetooth_mesh_authentication_reply(int auth_type,
266 const char *auth_val, gboolean reply)
270 char auth_string[BLUETOOTH_MESH_AUTH_VALUE_LENGTH_MAX];
272 BT_CHECK_PARAMETER(auth_val, return);
275 BT_ALLOC_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
277 g_strlcpy(auth_string, auth_val,
278 sizeof(auth_string));
279 g_array_append_vals(in_param1,
280 &auth_type, sizeof(int));
281 g_array_append_vals(in_param2, auth_string,
282 BLUETOOTH_MESH_AUTH_VALUE_LENGTH_MAX);
283 g_array_append_vals(in_param3, &reply, sizeof(gboolean));
285 BT_INFO("Mesh: Set Provisioner Authentication Reply");
286 result = _bt_send_request(BT_BLUEZ_SERVICE, BT_MESH_AUTHENTICATION_REPLY,
287 in_param1, in_param2, in_param3, in_param4, &out_param);
289 BT_FREE_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
294 BT_EXPORT_API int bluetooth_mesh_network_set_name(
295 bluetooth_mesh_network_t *network)
299 BT_CHECK_PARAMETER(network, return);
302 BT_ALLOC_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
304 g_array_append_vals(in_param1, network, sizeof(bluetooth_mesh_network_t));
306 BT_INFO("Mesh:Set Network Name");
307 result = _bt_send_request(BT_BLUEZ_SERVICE, BT_MESH_NETWORK_SET_NAME,
308 in_param1, in_param2, in_param3, in_param4, &out_param);
309 BT_FREE_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
314 BT_EXPORT_API int bluetooth_mesh_network_add_netkey(
315 bluetooth_mesh_network_t *network,
316 uint16_t *netkey_idx)
320 BT_CHECK_PARAMETER(network, return);
321 BT_CHECK_PARAMETER(netkey_idx, return);
324 BT_ALLOC_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
326 g_array_append_vals(in_param1, network, sizeof(bluetooth_mesh_network_t));
328 BT_INFO("Mesh:Set Create Subnetwork key");
329 result = _bt_send_request(BT_BLUEZ_SERVICE, BT_MESH_NETWORK_ADD_NETKEY,
330 in_param1, in_param2, in_param3, in_param4, &out_param);
331 if (result == BLUETOOTH_ERROR_NONE)
332 *netkey_idx = g_array_index(out_param, guint16, 0);
333 BT_FREE_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
338 BT_EXPORT_API int bluetooth_mesh_network_delete_netkey(
339 bluetooth_mesh_network_t *network,
344 BT_CHECK_PARAMETER(network, return);
347 BT_ALLOC_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
349 g_array_append_vals(in_param1, network, sizeof(bluetooth_mesh_network_t));
350 g_array_append_vals(in_param2, &netkey_idx, sizeof(guint16));
352 BT_INFO("Mesh: Delete Subnetwork key");
353 result = _bt_send_request(BT_BLUEZ_SERVICE, BT_MESH_NETWORK_DELETE_NETKEY,
354 in_param1, in_param2, in_param3, in_param4, &out_param);
355 BT_FREE_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
360 BT_EXPORT_API int bluetooth_mesh_network_update_netkey(
361 bluetooth_mesh_network_t *network,
366 BT_CHECK_PARAMETER(network, return);
369 BT_ALLOC_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
371 g_array_append_vals(in_param1, network, sizeof(bluetooth_mesh_network_t));
372 g_array_append_vals(in_param2, &netkey_idx, sizeof(guint16));
374 BT_INFO("Mesh: Update Subnetwork key");
375 result = _bt_send_request(BT_BLUEZ_SERVICE, BT_MESH_NETWORK_UPDATE_NETKEY,
376 in_param1, in_param2, in_param3, in_param4, &out_param);
377 BT_FREE_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
382 BT_EXPORT_API int bluetooth_mesh_network_add_appkey(
383 bluetooth_mesh_network_t *network,
384 uint16_t netkey_index,
385 uint16_t *appkey_index)
389 BT_CHECK_PARAMETER(network, return);
390 BT_CHECK_PARAMETER(appkey_index, return);
393 BT_ALLOC_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
395 g_array_append_vals(in_param1, network, sizeof(bluetooth_mesh_network_t));
396 g_array_append_vals(in_param2, &netkey_index, sizeof(guint16));
398 BT_INFO("Mesh: Create AppKey");
399 result = _bt_send_request(BT_BLUEZ_SERVICE, BT_MESH_NETWORK_ADD_APPKEY,
400 in_param1, in_param2, in_param3, in_param4, &out_param);
402 if (result == BLUETOOTH_ERROR_NONE)
403 *appkey_index = g_array_index(out_param, guint16, 0);
404 BT_FREE_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
409 BT_EXPORT_API int bluetooth_mesh_network_update_appkey(
410 bluetooth_mesh_network_t *network,
411 uint16_t netkey_index, uint16_t appkey_index)
415 BT_CHECK_PARAMETER(network, return);
418 BT_ALLOC_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
420 g_array_append_vals(in_param1, network, sizeof(bluetooth_mesh_network_t));
421 g_array_append_vals(in_param2, &netkey_index, sizeof(guint16));
422 g_array_append_vals(in_param3, &appkey_index, sizeof(guint16));
424 BT_INFO("Mesh:BTAPI: Update AppKey");
425 result = _bt_send_request(BT_BLUEZ_SERVICE, BT_MESH_NETWORK_UPDATE_APPKEY,
426 in_param1, in_param2, in_param3, in_param4, &out_param);
428 BT_FREE_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
433 BT_EXPORT_API int bluetooth_mesh_network_delete_appkey(bluetooth_mesh_network_t *network,
434 uint16_t netkey_index, uint16_t appkey_index)
438 BT_CHECK_PARAMETER(network, return);
441 BT_ALLOC_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
443 g_array_append_vals(in_param1, network, sizeof(bluetooth_mesh_network_t));
444 g_array_append_vals(in_param2, &netkey_index, sizeof(guint16));
445 g_array_append_vals(in_param3, &appkey_index, sizeof(guint16));
447 BT_INFO("Mesh: Delete AppKey");
448 result = _bt_send_request(BT_BLUEZ_SERVICE, BT_MESH_NETWORK_DELETE_APPKEY,
449 in_param1, in_param2, in_param3, in_param4, &out_param);
451 BT_FREE_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
456 BT_EXPORT_API int bluetooth_mesh_network_get_all_nodes(
457 bluetooth_mesh_network_t *network,
460 int result = BLUETOOTH_ERROR_NONE;
463 bluetooth_mesh_node_info_t *info;
465 BT_CHECK_PARAMETER(network, return);
466 BT_CHECK_PARAMETER(nodes, return);
469 BT_ALLOC_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
471 g_array_append_vals(in_param1, network, sizeof(bluetooth_mesh_network_t));
473 result = _bt_send_request(BT_BLUEZ_SERVICE, BT_MESH_NETWORK_GET_NODES,
474 in_param1, in_param2, in_param3, in_param4, &out_param);
476 if (result == BLUETOOTH_ERROR_NONE) {
477 if (out_param == NULL) {
478 BT_ERR("Mesh: out_param is NULL");
479 result = BLUETOOTH_ERROR_INTERNAL;
481 size = (out_param->len) / sizeof(bluetooth_mesh_node_info_t);
483 for (i = 0; i < size; i++) {
484 bluetooth_mesh_node_info_t *data;
486 info = &g_array_index(out_param,
487 bluetooth_mesh_node_info_t, i);
489 data = g_memdup(info, sizeof(bluetooth_mesh_node_info_t));
490 g_ptr_array_add(*nodes, (gpointer)data);
495 BT_FREE_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
500 BT_EXPORT_API int bluetooth_mesh_element_get_all_models(
501 bluetooth_mesh_network_t *network,
502 uint16_t node_addr, int elem_idx,
505 int result = BLUETOOTH_ERROR_NONE;
509 BT_CHECK_PARAMETER(network, return);
510 BT_CHECK_PARAMETER(models, return);
513 BT_ALLOC_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
515 g_array_append_vals(in_param1, network, sizeof(bluetooth_mesh_network_t));
516 g_array_append_vals(in_param2, &node_addr, sizeof(guint16));
517 g_array_append_vals(in_param3, &elem_idx, sizeof(int));
519 result = _bt_send_request(BT_BLUEZ_SERVICE, BT_MESH_ELEMENT_GET_MODELS,
520 in_param1, in_param2, in_param3, in_param4, &out_param);
522 if (result == BLUETOOTH_ERROR_NONE) {
523 if (out_param == NULL) {
524 BT_ERR("Mesh: out_param is NULL");
525 result = BLUETOOTH_ERROR_INTERNAL;
527 size = (out_param->len) / sizeof(guint32);
528 BT_INFO("Mesh: Total Models found in Element [%d]", size);
530 for (i = 0; i < size; i++) {
532 uint32_t *model_ptr = NULL;
534 model_obj = g_array_index(out_param,
537 model_ptr = g_memdup(&model_obj, sizeof(guint32));
538 g_ptr_array_add(*models, (gpointer)model_ptr);
543 BT_FREE_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
548 BT_EXPORT_API int bluetooth_mesh_node_browse_vendor_features(
549 bluetooth_mesh_node_features_t *req)
552 bt_user_info_t *user_info;
554 BT_CHECK_PARAMETER(req, return);
556 user_info = _bt_get_user_data(BT_MESH);
557 retv_if(user_info->cb == NULL, BLUETOOTH_ERROR_INTERNAL);
560 BT_ALLOC_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
562 g_array_append_vals(in_param1, req, sizeof(bluetooth_mesh_node_features_t));
564 BT_INFO("Mesh: Browse Vendor features of Node");
565 result = _bt_send_request_async(BT_BLUEZ_SERVICE, BT_MESH_NODE_GET_VENDOR_FEATURES,
566 in_param1, in_param2, in_param3, in_param4,
567 user_info->cb, user_info->user_data);
569 BT_FREE_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
574 BT_EXPORT_API int bluetooth_mesh_browse_remote_node(
575 bluetooth_mesh_node_discover_t *req)
578 bt_user_info_t *user_info;
580 BT_CHECK_PARAMETER(req, return);
582 user_info = _bt_get_user_data(BT_MESH);
583 retv_if(user_info->cb == NULL, BLUETOOTH_ERROR_INTERNAL);
586 BT_ALLOC_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
588 g_array_append_vals(in_param1, req, sizeof(bluetooth_mesh_node_discover_t));
590 BT_INFO("Mesh: Browse remote Node");
591 result = _bt_send_request_async(BT_BLUEZ_SERVICE, BT_MESH_NODE_BROWSE,
592 in_param1, in_param2, in_param3, in_param4,
593 user_info->cb, user_info->user_data);
595 BT_FREE_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
600 BT_EXPORT_API int bluetooth_mesh_node_ttl_execute(
601 bluetooth_mesh_node_ttl_info_t *req)
604 bt_user_info_t *user_info;
606 BT_CHECK_PARAMETER(req, return);
608 user_info = _bt_get_user_data(BT_MESH);
609 retv_if(user_info->cb == NULL, BLUETOOTH_ERROR_INTERNAL);
612 BT_ALLOC_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
614 g_array_append_vals(in_param1, req, sizeof(bluetooth_mesh_node_ttl_info_t));
616 BT_INFO("Mesh: Node TTL Execute");
617 result = _bt_send_request_async(BT_BLUEZ_SERVICE, BT_MESH_NODE_TTL_EXECUTE,
618 in_param1, in_param2, in_param3, in_param4,
619 user_info->cb, user_info->user_data);
621 BT_FREE_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
626 BT_EXPORT_API int bluetooth_mesh_model_configure_appkey(
627 bluetooth_mesh_model_configure_t *req)
630 bt_user_info_t *user_info;
632 BT_CHECK_PARAMETER(req, return);
634 user_info = _bt_get_user_data(BT_MESH);
635 retv_if(user_info->cb == NULL, BLUETOOTH_ERROR_INTERNAL);
638 BT_ALLOC_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
640 g_array_append_vals(in_param1, req, sizeof(bluetooth_mesh_model_configure_t));
642 BT_INFO("Mesh: Node Model Configure AppKey");
643 result = _bt_send_request_async(BT_BLUEZ_SERVICE, BT_MESH_MODEL_CONFIGURE_APPKEY,
644 in_param1, in_param2, in_param3, in_param4,
645 user_info->cb, user_info->user_data);
647 BT_FREE_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
652 BT_EXPORT_API int bluetooth_mesh_model_send_msg(
653 bluetooth_mesh_model_msg_t *req)
656 bt_user_info_t *user_info;
658 BT_CHECK_PARAMETER(req, return);
660 user_info = _bt_get_user_data(BT_MESH);
661 retv_if(user_info->cb == NULL, BLUETOOTH_ERROR_INTERNAL);
664 BT_ALLOC_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
666 g_array_append_vals(in_param1, req, sizeof(bluetooth_mesh_model_msg_t));
668 BT_INFO("Mesh: Node Model Send Msg");
669 result = _bt_send_request_async(BT_BLUEZ_SERVICE, BT_MESH_MODEL_EXECUTE_MSG,
670 in_param1, in_param2, in_param3, in_param4,
671 user_info->cb, user_info->user_data);
673 BT_FREE_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
678 BT_EXPORT_API int bluetooth_mesh_node_configure_key(
679 bluetooth_mesh_key_configure_t *req)
682 bt_user_info_t *user_info;
684 BT_CHECK_PARAMETER(req, return);
686 user_info = _bt_get_user_data(BT_MESH);
687 retv_if(user_info->cb == NULL, BLUETOOTH_ERROR_INTERNAL);
690 BT_ALLOC_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
692 g_array_append_vals(in_param1, req, sizeof(bluetooth_mesh_key_configure_t));
694 BT_INFO("Mesh:BTAPI: Node Key Configure");
695 result = _bt_send_request_async(BT_BLUEZ_SERVICE, BT_MESH_NODE_CONFIGURE_KEY,
696 in_param1, in_param2, in_param3, in_param4,
697 user_info->cb, user_info->user_data);
699 BT_FREE_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
704 BT_EXPORT_API int bluetooth_mesh_network_get_all_groups(
705 bluetooth_mesh_network_t *network,
708 int result = BLUETOOTH_ERROR_NONE;
709 bluetooth_mesh_network_group_info_t *info;
713 BT_CHECK_PARAMETER(network, return);
714 BT_CHECK_PARAMETER(groups, return);
717 BT_ALLOC_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
719 g_array_append_vals(in_param1, network, sizeof(bluetooth_mesh_network_t));
721 result = _bt_send_request(BT_BLUEZ_SERVICE, BT_MESH_NETWORK_GET_GROUPS,
722 in_param1, in_param2, in_param3, in_param4, &out_param);
724 if (result == BLUETOOTH_ERROR_NONE) {
725 if (out_param == NULL) {
726 BT_ERR("Mesh: out_param is NULL");
727 result = BLUETOOTH_ERROR_INTERNAL;
729 size = (out_param->len) / sizeof(bluetooth_mesh_network_group_info_t);
732 BT_INFO("Mesh: No Groups created for the network");
734 BT_INFO("Mesh: Total groups [%d]", size);
735 for (i = 0; i < size; i++) {
736 bluetooth_mesh_network_group_info_t *grp_info = NULL;
738 info = &g_array_index(out_param,
739 bluetooth_mesh_network_group_info_t, i);
740 BT_INFO("Mesh: Group addr [0x%2.2x]", info->group_addr);
741 BT_INFO("Mesh: Group is Virtual [%s]", info->is_virtual ? "YES" : "NO");
742 BT_INFO("Mesh: Group net UUID[%s]", info->net_uuid);
743 if (info->is_virtual)
744 BT_INFO("Mesh: Virual Label UUID [%s]", info->label_uuid);
745 grp_info = g_memdup(info,
746 sizeof(bluetooth_mesh_network_group_info_t));
747 g_ptr_array_add(*groups, (gpointer)grp_info);
752 BT_FREE_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
757 BT_EXPORT_API int bluetooth_mesh_network_get_all_netkey(
758 bluetooth_mesh_network_t *network,
761 int result = BLUETOOTH_ERROR_NONE;
765 BT_CHECK_PARAMETER(network, return);
766 BT_CHECK_PARAMETER(netkeys, return);
769 BT_ALLOC_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
771 g_array_append_vals(in_param1, network, sizeof(bluetooth_mesh_network_t));
773 result = _bt_send_request(BT_BLUEZ_SERVICE, BT_MESH_NETWORK_GET_NETKEYS,
774 in_param1, in_param2, in_param3, in_param4, &out_param);
776 if (result == BLUETOOTH_ERROR_NONE) {
777 if (out_param == NULL) {
778 BT_ERR("Mesh: out_param is NULL");
779 result = BLUETOOTH_ERROR_INTERNAL;
781 size = (out_param->len) / sizeof(guint16);
784 BT_ERR("Mesh: No netkeys created for the network");
785 result = BLUETOOTH_ERROR_NOT_FOUND;
788 for (i = 0; i < size; i++) {
789 uint16_t netkey_index;
790 uint16_t *netkey_idx = NULL;
792 netkey_index = g_array_index(out_param,
795 netkey_idx = g_memdup(&netkey_index, sizeof(guint16));
796 g_ptr_array_add(*netkeys, (gpointer)netkey_idx);
801 BT_FREE_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
806 BT_EXPORT_API int bluetooth_mesh_netkey_get_all_appkey(
807 bluetooth_mesh_network_t *network,
811 int result = BLUETOOTH_ERROR_NONE;
815 BT_CHECK_PARAMETER(network, return);
816 BT_CHECK_PARAMETER(appkeys, return);
819 BT_ALLOC_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
821 g_array_append_vals(in_param1, network, sizeof(bluetooth_mesh_network_t));
822 g_array_append_vals(in_param2, &netkey_idx, sizeof(guint16));
824 result = _bt_send_request(BT_BLUEZ_SERVICE, BT_MESH_NETWORK_GET_APPKEYS,
825 in_param1, in_param2, in_param3, in_param4, &out_param);
827 if (result == BLUETOOTH_ERROR_NONE) {
828 if (out_param == NULL) {
829 BT_ERR("Mesh: out_param is NULL");
830 result = BLUETOOTH_ERROR_INTERNAL;
832 size = (out_param->len) / sizeof(guint16);
835 BT_ERR("Mesh: No Appkeys created for the NetKey in the network");
837 for (i = 0; i < size; i++) {
838 uint16_t appkey_index;
839 uint16_t *appkey_idx = NULL;
841 appkey_index = g_array_index(out_param,
844 appkey_idx = g_memdup(&appkey_index, sizeof(guint16));
845 g_ptr_array_add(*appkeys, (gpointer)appkey_idx);
850 BT_FREE_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
855 BT_EXPORT_API int bluetooth_mesh_node_get_all_netkeys(
856 bluetooth_mesh_node_discover_t *node,
859 int result = BLUETOOTH_ERROR_NONE;
863 BT_CHECK_PARAMETER(node, return);
864 BT_CHECK_PARAMETER(netkeys, return);
867 BT_ALLOC_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
869 g_array_append_vals(in_param1, node, sizeof(bluetooth_mesh_node_discover_t));
871 result = _bt_send_request(BT_BLUEZ_SERVICE, BT_MESH_NODE_GET_NETKEYS,
872 in_param1, in_param2, in_param3, in_param4, &out_param);
874 if (result == BLUETOOTH_ERROR_NONE) {
875 if (out_param == NULL) {
876 BT_ERR("Mesh: out_param is NULL");
877 result = BLUETOOTH_ERROR_INTERNAL;
879 size = (out_param->len) / sizeof(guint16);
881 for (i = 0; i < size; i++) {
882 uint16_t netkey_index;
883 uint16_t *netkey_idx = NULL;
885 netkey_index = g_array_index(out_param,
888 netkey_idx = g_memdup(&netkey_index, sizeof(guint16));
889 g_ptr_array_add(*netkeys, (gpointer)netkey_idx);
894 BT_FREE_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
899 BT_EXPORT_API int bluetooth_mesh_node_get_all_appkeys(
900 bluetooth_mesh_node_discover_t *req, GPtrArray **appkeys)
902 int result = BLUETOOTH_ERROR_NONE;
906 BT_CHECK_PARAMETER(req, return);
907 BT_CHECK_PARAMETER(appkeys, return);
910 BT_ALLOC_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
912 g_array_append_vals(in_param1, req, sizeof(bluetooth_mesh_node_discover_t));
914 result = _bt_send_request(BT_BLUEZ_SERVICE, BT_MESH_NODE_GET_APPKEYS,
915 in_param1, in_param2, in_param3, in_param4, &out_param);
917 if (result == BLUETOOTH_ERROR_NONE) {
918 if (out_param == NULL) {
919 BT_ERR("Mesh: out_param is NULL");
920 result = BLUETOOTH_ERROR_INTERNAL;
922 size = (out_param->len) / sizeof(guint16);
924 for (i = 0; i < size; i++) {
925 uint16_t appkey_index;
926 uint16_t *appkey_idx = NULL;
928 appkey_index = g_array_index(out_param,
931 appkey_idx = g_memdup(&appkey_index, sizeof(guint16));
932 g_ptr_array_add(*appkeys, (gpointer)appkey_idx);
937 BT_FREE_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
942 BT_EXPORT_API int bluetooth_mesh_model_get_all_appkeys(
943 bluetooth_mesh_model_configure_t *req)
946 bt_user_info_t *user_info;
948 BT_CHECK_PARAMETER(req, return);
950 user_info = _bt_get_user_data(BT_MESH);
951 retv_if(user_info->cb == NULL, BLUETOOTH_ERROR_INTERNAL);
954 BT_ALLOC_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
956 g_array_append_vals(in_param1, req, sizeof(bluetooth_mesh_model_configure_t));
958 BT_INFO("Mesh:Node Model Get AppKey List ");
959 result = _bt_send_request_async(BT_BLUEZ_SERVICE, BT_MESH_MODEL_GET_APPKEY_LIST,
960 in_param1, in_param2, in_param3, in_param4,
961 user_info->cb, user_info->user_data);
963 BT_FREE_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
967 BT_EXPORT_API int bluetooth_mesh_model_set_publication(
968 bluetooth_mesh_model_configure_t *req)
971 bt_user_info_t *user_info;
973 BT_CHECK_PARAMETER(req, return);
975 user_info = _bt_get_user_data(BT_MESH);
976 retv_if(user_info->cb == NULL, BLUETOOTH_ERROR_INTERNAL);
979 BT_ALLOC_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
981 g_array_append_vals(in_param1, req, sizeof(bluetooth_mesh_model_configure_t));
983 BT_INFO("Mesh: Model Set Publication");
984 result = _bt_send_request_async(BT_BLUEZ_SERVICE, BT_MESH_MODEL_SET_PUBLICATION,
985 in_param1, in_param2, in_param3, in_param4,
986 user_info->cb, user_info->user_data);
988 BT_FREE_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
992 BT_EXPORT_API int bluetooth_mesh_model_get_publication(
993 bluetooth_mesh_model_configure_t *req)
996 bt_user_info_t *user_info;
998 BT_CHECK_PARAMETER(req, return);
1000 user_info = _bt_get_user_data(BT_MESH);
1001 retv_if(user_info->cb == NULL, BLUETOOTH_ERROR_INTERNAL);
1004 BT_ALLOC_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
1006 g_array_append_vals(in_param1, req, sizeof(bluetooth_mesh_model_configure_t));
1008 BT_INFO("Mesh:BTAPI: Model Get Publication");
1009 result = _bt_send_request_async(BT_BLUEZ_SERVICE, BT_MESH_MODEL_GET_PUBLICATION,
1010 in_param1, in_param2, in_param3, in_param4,
1011 user_info->cb, user_info->user_data);
1013 BT_FREE_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
1017 BT_EXPORT_API int bluetooth_mesh_model_get_subscriptopn_list(
1018 bluetooth_mesh_model_configure_t *req)
1021 bt_user_info_t *user_info;
1023 BT_CHECK_PARAMETER(req, return);
1025 user_info = _bt_get_user_data(BT_MESH);
1026 retv_if(user_info->cb == NULL, BLUETOOTH_ERROR_INTERNAL);
1029 BT_ALLOC_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
1031 g_array_append_vals(in_param1, req, sizeof(bluetooth_mesh_model_configure_t));
1033 BT_INFO("Mesh:BTAPI: Model Get Subscription List ");
1034 result = _bt_send_request_async(BT_BLUEZ_SERVICE, BT_MESH_MODEL_GET_SUBSCRIPTION_LIST,
1035 in_param1, in_param2, in_param3, in_param4,
1036 user_info->cb, user_info->user_data);
1038 BT_FREE_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
1042 BT_EXPORT_API int bluetooth_mesh_network_remove_group(
1043 bluetooth_mesh_network_t *network,
1044 bluetooth_mesh_network_group_info_t *req)
1048 BT_CHECK_PARAMETER(network, return);
1049 BT_CHECK_PARAMETER(req, return);
1052 BT_ALLOC_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
1054 g_array_append_vals(in_param1, network, sizeof(bluetooth_mesh_network_t));
1055 g_array_append_vals(in_param2, req, sizeof(bluetooth_mesh_network_group_info_t));
1057 BT_INFO("Mesh: Remove Group Request");
1058 result = _bt_send_request(BT_BLUEZ_SERVICE, BT_MESH_NETWORK_REMOVE_GROUP,
1059 in_param1, in_param2, in_param3, in_param4, &out_param);
1061 BT_FREE_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
1066 BT_EXPORT_API int bluetooth_mesh_network_create_group(
1067 bluetooth_mesh_network_t *network, bool is_virtual,
1068 uint16_t grp_addr, bluetooth_mesh_network_group_info_t *info)
1072 BT_CHECK_PARAMETER(network, return);
1073 BT_CHECK_PARAMETER(info, return);
1076 BT_ALLOC_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
1078 g_array_append_vals(in_param1, network, sizeof(bluetooth_mesh_network_t));
1079 g_array_append_vals(in_param2, &is_virtual, sizeof(gboolean));
1080 g_array_append_vals(in_param3, &grp_addr, sizeof(guint16));
1082 BT_INFO("Mesh: Create Group Request");
1083 result = _bt_send_request(BT_BLUEZ_SERVICE, BT_MESH_NETWORK_CREATE_GROUP,
1084 in_param1, in_param2, in_param3, in_param4, &out_param);
1086 if (result == BLUETOOTH_ERROR_NONE) {
1087 *info = g_array_index(out_param,
1088 bluetooth_mesh_network_group_info_t, 0);
1090 BT_FREE_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
1095 BT_EXPORT_API int bluetooth_mesh_model_configure_group_sub(
1096 bluetooth_mesh_model_configure_t *req)
1099 bt_user_info_t *user_info;
1101 BT_CHECK_PARAMETER(req, return);
1103 user_info = _bt_get_user_data(BT_MESH);
1104 retv_if(user_info->cb == NULL, BLUETOOTH_ERROR_INTERNAL);
1107 BT_ALLOC_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
1109 g_array_append_vals(in_param1, req, sizeof(bluetooth_mesh_model_configure_t));
1111 BT_INFO("Mesh:Model Group Subscription Request");
1112 result = _bt_send_request_async(BT_BLUEZ_SERVICE, BT_MESH_MODEL_CONFIG_GROUP_SUB,
1113 in_param1, in_param2, in_param3, in_param4,
1114 user_info->cb, user_info->user_data);
1116 BT_FREE_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
1120 BT_EXPORT_API int bluetooth_mesh_model_configure_virtual_group_sub(
1121 bluetooth_mesh_model_configure_t *req)
1124 bt_user_info_t *user_info;
1126 BT_CHECK_PARAMETER(req, return);
1128 user_info = _bt_get_user_data(BT_MESH);
1129 retv_if(user_info->cb == NULL, BLUETOOTH_ERROR_INTERNAL);
1132 BT_ALLOC_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
1134 g_array_append_vals(in_param1, req, sizeof(bluetooth_mesh_model_configure_t));
1136 BT_INFO("Mesh: Model Virtual Group Subscription Request");
1137 result = _bt_send_request_async(BT_BLUEZ_SERVICE,
1138 BT_MESH_MODEL_CONFIG_VIRTUAL_GROUP_SUB,
1139 in_param1, in_param2, in_param3, in_param4,
1140 user_info->cb, user_info->user_data);
1142 BT_FREE_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);