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;
41 ret = _bt_init_event_handler();
43 if (ret != BLUETOOTH_ERROR_NONE &&
44 ret != BLUETOOTH_ERROR_ALREADY_INITIALIZED) {
45 BT_ERR("Fail to init the event handler");
49 _bt_set_user_data(BT_MESH, (void *)cb, user_data);
51 /* Register All events */
52 ret = _bt_register_event(BT_MESH_EVENT, (void *)cb, user_data);
53 if (ret != BLUETOOTH_ERROR_NONE &&
54 ret != BLUETOOTH_ERROR_ALREADY_INITIALIZED) {
55 _bt_deinit_event_handler();
59 BT_INFO("Mesh: Event registsred");
60 return BLUETOOTH_ERROR_NONE;
63 BT_EXPORT_API int bluetooth_mesh_deinit(void)
65 _bt_unregister_event(BT_MESH_EVENT);
66 _bt_set_user_data(BT_MESH, NULL, NULL);
68 return BLUETOOTH_ERROR_NONE;
71 BT_EXPORT_API int bluetooth_mesh_network_create(
72 const char *net_name, bluetooth_mesh_node_t *node,
73 uint16_t total_models, bluetooth_mesh_model_t **models,
74 bluetooth_mesh_network_t *network)
77 char network_name[BLUETOOTH_MESH_NETWORK_NAME_STRING_MAX+1];
79 BT_CHECK_PARAMETER(net_name, return);
80 BT_CHECK_PARAMETER(node, return);
81 BT_CHECK_PARAMETER(models, return);
84 BT_ALLOC_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
86 g_array_append_vals(in_param1, node, sizeof(bluetooth_mesh_node_t));
88 g_strlcpy(network_name, net_name, sizeof(network_name));
89 g_array_append_vals(in_param2, network_name,
90 BLUETOOTH_MESH_NETWORK_NAME_STRING_MAX);
92 for(int i = 0; i < total_models; i++)
93 g_array_append_vals(in_param3, models[i],
94 sizeof(bluetooth_mesh_model_t));
96 result = _bt_send_request(BT_BLUEZ_SERVICE,
97 BT_MESH_NETWORK_CREATE,
98 in_param1, in_param2, in_param3,
99 in_param4, &out_param);
101 if (result == BLUETOOTH_ERROR_NONE) {
102 *network = g_array_index(out_param,
103 bluetooth_mesh_network_t, 0);
106 BT_FREE_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
111 BT_EXPORT_API int bluetooth_mesh_network_load(
113 bluetooth_mesh_network_t *network)
116 char token_string[BLUETOOTH_MESH_TOKEN_STRING_MAX + 1];
118 BT_CHECK_PARAMETER(token, return);
119 BT_CHECK_PARAMETER(network, return);
122 BT_ALLOC_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
124 g_strlcpy(token_string, token, sizeof(token_string));
125 g_array_append_vals(in_param1, token_string, BLUETOOTH_MESH_TOKEN_STRING_MAX);
127 result = _bt_send_request(BT_BLUEZ_SERVICE, BT_MESH_NETWORK_LOAD,
128 in_param1, in_param2, in_param3, 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_scan(
141 bluetooth_mesh_network_t *network,
142 bluetooth_mesh_scan_param_t *scan_param)
146 BT_CHECK_PARAMETER(network, return);
147 BT_CHECK_PARAMETER(scan_param, return);
150 BT_ALLOC_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
152 g_array_append_vals(in_param1, network, sizeof(bluetooth_mesh_network_t));
154 g_array_append_vals(in_param2, scan_param, sizeof(bluetooth_mesh_scan_param_t));
156 BT_INFO("Mesh:Start Scan, time [%u]", scan_param->scan_time);
157 result = _bt_send_request(BT_BLUEZ_SERVICE, BT_MESH_NETWORK_SCAN,
158 in_param1, in_param2, in_param3, in_param4, &out_param);
159 BT_FREE_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
164 BT_EXPORT_API int bluetooth_mesh_network_cancel_scan(
165 bluetooth_mesh_network_t *network)
169 BT_CHECK_PARAMETER(network, return);
172 BT_ALLOC_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
174 g_array_append_vals(in_param1, network, sizeof(bluetooth_mesh_network_t));
176 BT_INFO("Mesh: Cancel Scan");
177 result = _bt_send_request(BT_BLUEZ_SERVICE, BT_MESH_NETWORK_CANCEL_SCAN,
178 in_param1, in_param2, in_param3, in_param4, &out_param);
179 BT_FREE_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
184 BT_EXPORT_API int bluetooth_mesh_network_set_capabilities(
185 bluetooth_mesh_network_t *network,
186 bluetooth_mesh_provisioner_caps_t *caps)
190 BT_CHECK_PARAMETER(network, return);
191 BT_CHECK_PARAMETER(caps, return);
194 BT_ALLOC_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
196 g_array_append_vals(in_param1, network, sizeof(bluetooth_mesh_network_t));
198 g_array_append_vals(in_param2, caps, sizeof(bluetooth_mesh_provisioner_caps_t));
200 BT_INFO("Mesh: Set Provisioner capabilities");
201 result = _bt_send_request(BT_BLUEZ_SERVICE, BT_MESH_NETWORK_SET_CAPABILITIES,
202 in_param1, in_param2, in_param3, in_param4, &out_param);
203 BT_FREE_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
208 BT_EXPORT_API int bluetooth_mesh_network_provision_device(
209 bluetooth_mesh_provisioning_request_t *req)
212 bt_user_info_t *user_info;
214 BT_CHECK_PARAMETER(req, return);
216 user_info = _bt_get_user_data(BT_MESH);
217 retv_if(user_info->cb == NULL, BLUETOOTH_ERROR_INTERNAL);
220 BT_ALLOC_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
222 g_array_append_vals(in_param1, req,
223 sizeof(bluetooth_mesh_provisioning_request_t));
225 BT_INFO("Mesh: Set Provision Device");
226 result = _bt_send_request_async(BT_BLUEZ_SERVICE,
227 BT_MESH_NETWORK_PROVISION_DEVICE,
228 in_param1, in_param2, in_param3, in_param4,
229 user_info->cb, user_info->user_data);
231 BT_FREE_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
236 BT_EXPORT_API int bluetooth_mesh_authentication_reply(int auth_type,
237 const char *auth_val, gboolean reply)
241 char auth_string[BLUETOOTH_MESH_AUTH_VALUE_LENGTH_MAX];
243 BT_CHECK_PARAMETER(auth_val, return);
246 BT_ALLOC_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
248 g_strlcpy(auth_string, auth_val,
249 sizeof(auth_string));
250 g_array_append_vals(in_param1,
251 &auth_type, sizeof(int));
252 g_array_append_vals(in_param2, auth_string,
253 BLUETOOTH_MESH_AUTH_VALUE_LENGTH_MAX);
254 g_array_append_vals(in_param3, &reply, sizeof(gboolean));
256 BT_INFO("Mesh: Set Provisioner Authentication Reply");
257 result = _bt_send_request(BT_BLUEZ_SERVICE, BT_MESH_AUTHENTICATION_REPLY,
258 in_param1, in_param2, in_param3, in_param4, &out_param);
260 BT_FREE_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
265 BT_EXPORT_API int bluetooth_mesh_network_set_name(
266 bluetooth_mesh_network_t *network)
270 BT_CHECK_PARAMETER(network, return);
273 BT_ALLOC_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
275 g_array_append_vals(in_param1, network, sizeof(bluetooth_mesh_network_t));
277 BT_INFO("Mesh:Set Network Name");
278 result = _bt_send_request(BT_BLUEZ_SERVICE, BT_MESH_NETWORK_SET_NAME,
279 in_param1, in_param2, in_param3, in_param4, &out_param);
280 BT_FREE_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
285 BT_EXPORT_API int bluetooth_mesh_network_add_netkey(
286 bluetooth_mesh_network_t *network,
287 uint16_t *netkey_idx)
291 BT_CHECK_PARAMETER(network, return);
292 BT_CHECK_PARAMETER(netkey_idx, return);
295 BT_ALLOC_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
297 g_array_append_vals(in_param1, network, sizeof(bluetooth_mesh_network_t));
299 BT_INFO("Mesh:Set Create Subnetwork key");
300 result = _bt_send_request(BT_BLUEZ_SERVICE, BT_MESH_NETWORK_ADD_NETKEY,
301 in_param1, in_param2, in_param3, in_param4, &out_param);
302 if (result == BLUETOOTH_ERROR_NONE) {
303 *netkey_idx = g_array_index(out_param, guint16, 0);
305 BT_FREE_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
310 BT_EXPORT_API int bluetooth_mesh_network_delete_netkey(
311 bluetooth_mesh_network_t *network,
316 BT_CHECK_PARAMETER(network, return);
319 BT_ALLOC_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
321 g_array_append_vals(in_param1, network, sizeof(bluetooth_mesh_network_t));
322 g_array_append_vals(in_param2, &netkey_idx, sizeof(guint16));
324 BT_INFO("Mesh: Delete Subnetwork key");
325 result = _bt_send_request(BT_BLUEZ_SERVICE, BT_MESH_NETWORK_DELETE_NETKEY,
326 in_param1, in_param2, in_param3, in_param4, &out_param);
327 BT_FREE_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
332 BT_EXPORT_API int bluetooth_mesh_network_update_netkey(
333 bluetooth_mesh_network_t *network,
338 BT_CHECK_PARAMETER(network, return);
341 BT_ALLOC_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
343 g_array_append_vals(in_param1, network, sizeof(bluetooth_mesh_network_t));
344 g_array_append_vals(in_param2, &netkey_idx, sizeof(guint16));
346 BT_INFO("Mesh: Update Subnetwork key");
347 result = _bt_send_request(BT_BLUEZ_SERVICE, BT_MESH_NETWORK_UPDATE_NETKEY,
348 in_param1, in_param2, in_param3, in_param4, &out_param);
349 BT_FREE_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
354 BT_EXPORT_API int bluetooth_mesh_network_add_appkey(
355 bluetooth_mesh_network_t *network,
356 uint16_t netkey_index,
357 uint16_t *appkey_index)
361 BT_CHECK_PARAMETER(network, return);
362 BT_CHECK_PARAMETER(appkey_index, return);
365 BT_ALLOC_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
367 g_array_append_vals(in_param1, network, sizeof(bluetooth_mesh_network_t));
368 g_array_append_vals(in_param2, &netkey_index, sizeof(guint16));
370 BT_INFO("Mesh: Create AppKey");
371 result = _bt_send_request(BT_BLUEZ_SERVICE, BT_MESH_NETWORK_ADD_APPKEY,
372 in_param1, in_param2, in_param3, in_param4, &out_param);
374 if (result == BLUETOOTH_ERROR_NONE) {
375 *appkey_index = g_array_index(out_param, guint16, 0);
377 BT_FREE_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
382 BT_EXPORT_API int bluetooth_mesh_network_update_appkey(
383 bluetooth_mesh_network_t *network,
384 uint16_t netkey_index, uint16_t appkey_index)
388 BT_CHECK_PARAMETER(network, return);
391 BT_ALLOC_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
393 g_array_append_vals(in_param1, network, sizeof(bluetooth_mesh_network_t));
394 g_array_append_vals(in_param2, &netkey_index, sizeof(guint16));
395 g_array_append_vals(in_param3, &appkey_index, sizeof(guint16));
397 BT_INFO("Mesh:BTAPI: Update AppKey");
398 result = _bt_send_request(BT_BLUEZ_SERVICE, BT_MESH_NETWORK_UPDATE_APPKEY,
399 in_param1, in_param2, in_param3, in_param4, &out_param);
401 BT_FREE_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
406 BT_EXPORT_API int bluetooth_mesh_network_delete_appkey(bluetooth_mesh_network_t *network,
407 uint16_t netkey_index, uint16_t appkey_index)
411 BT_CHECK_PARAMETER(network, return);
414 BT_ALLOC_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
416 g_array_append_vals(in_param1, network, sizeof(bluetooth_mesh_network_t));
417 g_array_append_vals(in_param2, &netkey_index, sizeof(guint16));
418 g_array_append_vals(in_param3, &appkey_index, sizeof(guint16));
420 BT_INFO("Mesh: Delete AppKey");
421 result = _bt_send_request(BT_BLUEZ_SERVICE, BT_MESH_NETWORK_DELETE_APPKEY,
422 in_param1, in_param2, in_param3, in_param4, &out_param);
424 BT_FREE_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
429 BT_EXPORT_API int bluetooth_mesh_network_get_all_nodes(
430 bluetooth_mesh_network_t *network,
433 int result = BLUETOOTH_ERROR_NONE;
436 bluetooth_mesh_node_info_t *info;
438 BT_CHECK_PARAMETER(network, return);
439 BT_CHECK_PARAMETER(nodes, return);
442 BT_ALLOC_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
444 g_array_append_vals(in_param1, network, sizeof(bluetooth_mesh_network_t));
446 result = _bt_send_request(BT_BLUEZ_SERVICE, BT_MESH_NETWORK_GET_NODES,
447 in_param1, in_param2, in_param3, in_param4, &out_param);
449 if (result == BLUETOOTH_ERROR_NONE) {
450 if (out_param == NULL) {
451 BT_ERR("Mesh: out_param is NULL");
452 result = BLUETOOTH_ERROR_INTERNAL;
454 size = (out_param->len) / sizeof(bluetooth_mesh_node_info_t);
456 for (i = 0; i < size; i++) {
457 bluetooth_mesh_node_info_t *data;
459 info = &g_array_index(out_param,
460 bluetooth_mesh_node_info_t, i);
462 data= g_memdup(info, sizeof(bluetooth_mesh_node_info_t));
463 g_ptr_array_add(*nodes, (gpointer)data);
468 BT_FREE_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
473 BT_EXPORT_API int bluetooth_mesh_element_get_all_models(
474 bluetooth_mesh_network_t *network,
475 uint16_t node_addr, int elem_idx,
478 int result = BLUETOOTH_ERROR_NONE;
482 BT_CHECK_PARAMETER(network, return);
483 BT_CHECK_PARAMETER(models, return);
486 BT_ALLOC_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
488 g_array_append_vals(in_param1, network, sizeof(bluetooth_mesh_network_t));
489 g_array_append_vals(in_param2, &node_addr, sizeof(guint16));
490 g_array_append_vals(in_param3, &elem_idx, sizeof(int));
492 result = _bt_send_request(BT_BLUEZ_SERVICE, BT_MESH_ELEMENT_GET_MODELS,
493 in_param1, in_param2, in_param3, in_param4, &out_param);
495 if (result == BLUETOOTH_ERROR_NONE) {
496 if (out_param == NULL) {
497 BT_ERR("Mesh: out_param is NULL");
498 result = BLUETOOTH_ERROR_INTERNAL;
500 size = (out_param->len) / sizeof(guint16);
502 for (i = 0; i < size; i++) {
504 uint32_t *model_ptr = NULL;
506 model_obj = g_array_index(out_param,
509 model_ptr = g_memdup(&model_obj, sizeof(guint32));
510 g_ptr_array_add(*models, (gpointer)model_ptr);
515 BT_FREE_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
520 BT_EXPORT_API int bluetooth_mesh_node_browse_vendor_features(
521 bluetooth_mesh_node_features_t *req)
524 bt_user_info_t *user_info;
526 BT_CHECK_PARAMETER(req, return);
528 user_info = _bt_get_user_data(BT_MESH);
529 retv_if(user_info->cb == NULL, BLUETOOTH_ERROR_INTERNAL);
532 BT_ALLOC_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
534 g_array_append_vals(in_param1, req, sizeof(bluetooth_mesh_node_features_t));
536 BT_INFO("Mesh: Browse Vendor features of Node");
537 result = _bt_send_request_async(BT_BLUEZ_SERVICE, BT_MESH_NODE_GET_VENDOR_FEATURES,
538 in_param1, in_param2, in_param3, in_param4,
539 user_info->cb, user_info->user_data);
541 BT_FREE_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
546 BT_EXPORT_API int bluetooth_mesh_browse_remote_node(
547 bluetooth_mesh_node_discover_t *req)
550 bt_user_info_t *user_info;
552 BT_CHECK_PARAMETER(req, return);
554 user_info = _bt_get_user_data(BT_MESH);
555 retv_if(user_info->cb == NULL, BLUETOOTH_ERROR_INTERNAL);
558 BT_ALLOC_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
560 g_array_append_vals(in_param1, req, sizeof(bluetooth_mesh_node_discover_t));
562 BT_INFO("Mesh: Browse remote Node");
563 result = _bt_send_request_async(BT_BLUEZ_SERVICE, BT_MESH_NODE_BROWSE,
564 in_param1, in_param2, in_param3, in_param4,
565 user_info->cb, user_info->user_data);
567 BT_FREE_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
572 BT_EXPORT_API int bluetooth_mesh_node_ttl_execute(
573 bluetooth_mesh_node_ttl_info_t *req)
576 bt_user_info_t *user_info;
578 BT_CHECK_PARAMETER(req, return);
580 user_info = _bt_get_user_data(BT_MESH);
581 retv_if(user_info->cb == NULL, BLUETOOTH_ERROR_INTERNAL);
584 BT_ALLOC_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
586 g_array_append_vals(in_param1, req, sizeof(bluetooth_mesh_node_ttl_info_t));
588 BT_INFO("Mesh: Node TTL Execute");
589 result = _bt_send_request_async(BT_BLUEZ_SERVICE, BT_MESH_NODE_TTL_EXECUTE,
590 in_param1, in_param2, in_param3, in_param4,
591 user_info->cb, user_info->user_data);
593 BT_FREE_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
598 BT_EXPORT_API int bluetooth_mesh_model_configure_appkey(
599 bluetooth_mesh_model_configure_t *req)
602 bt_user_info_t *user_info;
604 BT_CHECK_PARAMETER(req, return);
606 user_info = _bt_get_user_data(BT_MESH);
607 retv_if(user_info->cb == NULL, BLUETOOTH_ERROR_INTERNAL);
610 BT_ALLOC_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
612 g_array_append_vals(in_param1, req, sizeof(bluetooth_mesh_model_configure_t));
614 BT_INFO("Mesh: Node Model Configure AppKey");
615 result = _bt_send_request_async(BT_BLUEZ_SERVICE, BT_MESH_MODEL_CONFIGURE_APPKEY,
616 in_param1, in_param2, in_param3, in_param4,
617 user_info->cb, user_info->user_data);
619 BT_FREE_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
624 BT_EXPORT_API int bluetooth_mesh_node_configure_key(
625 bluetooth_mesh_key_configure_t *req)
628 bt_user_info_t *user_info;
630 BT_CHECK_PARAMETER(req, return);
632 user_info = _bt_get_user_data(BT_MESH);
633 retv_if(user_info->cb == NULL, BLUETOOTH_ERROR_INTERNAL);
636 BT_ALLOC_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
638 g_array_append_vals(in_param1, req, sizeof(bluetooth_mesh_key_configure_t));
640 BT_INFO("Mesh:BTAPI: Node Key Configure");
641 result = _bt_send_request_async(BT_BLUEZ_SERVICE, BT_MESH_NODE_CONFIGURE_KEY,
642 in_param1, in_param2, in_param3, in_param4,
643 user_info->cb, user_info->user_data);
645 BT_FREE_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
650 BT_EXPORT_API int bluetooth_mesh_network_get_all_groups(
651 bluetooth_mesh_network_t *network,
654 int result = BLUETOOTH_ERROR_NONE;
658 BT_CHECK_PARAMETER(network, return);
659 BT_CHECK_PARAMETER(groups, return);
662 BT_ALLOC_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
664 g_array_append_vals(in_param1, network, sizeof(bluetooth_mesh_network_t));
666 result = _bt_send_request(BT_BLUEZ_SERVICE, BT_MESH_NETWORK_GET_GROUPS,
667 in_param1, in_param2, in_param3, in_param4, &out_param);
669 if (result == BLUETOOTH_ERROR_NONE) {
670 if (out_param == NULL) {
671 BT_ERR("Mesh: out_param is NULL");
672 result = BLUETOOTH_ERROR_INTERNAL;
674 size = (out_param->len) / sizeof(guint16);
677 BT_INFO("Mesh: No Groups created for the network");
680 for (i = 0; i < size; i++) {
682 uint16_t *group_ptr = NULL;
684 group_addr = g_array_index(out_param,
687 group_ptr = g_memdup(&group_addr, sizeof(guint16));
688 g_ptr_array_add(*groups, (gpointer)group_ptr);
693 BT_FREE_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
698 BT_EXPORT_API int bluetooth_mesh_network_get_all_netkey(
699 bluetooth_mesh_network_t *network,
702 int result = BLUETOOTH_ERROR_NONE;
706 BT_CHECK_PARAMETER(network, return);
707 BT_CHECK_PARAMETER(netkeys, return);
710 BT_ALLOC_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
712 g_array_append_vals(in_param1, network, sizeof(bluetooth_mesh_network_t));
714 result = _bt_send_request(BT_BLUEZ_SERVICE, BT_MESH_NETWORK_GET_NETKEYS,
715 in_param1, in_param2, in_param3, in_param4, &out_param);
717 if (result == BLUETOOTH_ERROR_NONE) {
718 if (out_param == NULL) {
719 BT_ERR("Mesh: out_param is NULL");
720 result = BLUETOOTH_ERROR_INTERNAL;
722 size = (out_param->len) / sizeof(guint16);
725 BT_ERR("Mesh: No netkeys created for the network");
726 result = BLUETOOTH_ERROR_NOT_FOUND;
729 for (i = 0; i < size; i++) {
730 uint16_t netkey_index;
731 uint16_t *netkey_idx = NULL;
733 netkey_index = g_array_index(out_param,
736 netkey_idx = g_memdup(&netkey_index, sizeof(guint16));
737 g_ptr_array_add(*netkeys, (gpointer)netkey_idx);
742 BT_FREE_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
747 BT_EXPORT_API int bluetooth_mesh_netkey_get_all_appkey(
748 bluetooth_mesh_network_t *network,
752 int result = BLUETOOTH_ERROR_NONE;
756 BT_CHECK_PARAMETER(network, return);
757 BT_CHECK_PARAMETER(appkeys, return);
760 BT_ALLOC_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
762 g_array_append_vals(in_param1, network, sizeof(bluetooth_mesh_network_t));
763 g_array_append_vals(in_param2, &netkey_idx, sizeof(guint16));
765 result = _bt_send_request(BT_BLUEZ_SERVICE, BT_MESH_NETWORK_GET_APPKEYS,
766 in_param1, in_param2, in_param3, in_param4, &out_param);
768 if (result == BLUETOOTH_ERROR_NONE) {
769 if (out_param == NULL) {
770 BT_ERR("Mesh: out_param is NULL");
771 result = BLUETOOTH_ERROR_INTERNAL;
773 size = (out_param->len) / sizeof(guint16);
776 BT_ERR("Mesh: No Appkeys created for the NetKey in the network");
779 for (i = 0; i < size; i++) {
780 uint16_t appkey_index;
781 uint16_t *appkey_idx = NULL;
783 appkey_index = g_array_index(out_param,
786 appkey_idx = g_memdup(&appkey_index, sizeof(guint16));
787 g_ptr_array_add(*appkeys, (gpointer)appkey_idx);
792 BT_FREE_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
797 BT_EXPORT_API int bluetooth_mesh_node_get_all_netkeys(
798 bluetooth_mesh_node_discover_t *node,
801 int result = BLUETOOTH_ERROR_NONE;
805 BT_CHECK_PARAMETER(node, return);
806 BT_CHECK_PARAMETER(netkeys, return);
809 BT_ALLOC_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
811 g_array_append_vals(in_param1, node, sizeof(bluetooth_mesh_node_discover_t));
813 result = _bt_send_request(BT_BLUEZ_SERVICE, BT_MESH_NODE_GET_NETKEYS,
814 in_param1, in_param2, in_param3, in_param4, &out_param);
816 if (result == BLUETOOTH_ERROR_NONE) {
817 if (out_param == NULL) {
818 BT_ERR("Mesh: out_param is NULL");
819 result = BLUETOOTH_ERROR_INTERNAL;
821 size = (out_param->len) / sizeof(guint16);
823 for (i = 0; i < size; i++) {
824 uint16_t netkey_index;
825 uint16_t *netkey_idx = NULL;
827 netkey_index = g_array_index(out_param,
830 netkey_idx = g_memdup(&netkey_index, sizeof(guint16));
831 g_ptr_array_add(*netkeys, (gpointer)netkey_idx);
836 BT_FREE_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
841 BT_EXPORT_API int bluetooth_mesh_node_get_all_appkeys(
842 bluetooth_mesh_node_discover_t *req, GPtrArray **appkeys)
844 int result = BLUETOOTH_ERROR_NONE;
848 BT_CHECK_PARAMETER(req, return);
849 BT_CHECK_PARAMETER(appkeys, return);
852 BT_ALLOC_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
854 g_array_append_vals(in_param1, req, sizeof(bluetooth_mesh_node_discover_t));
856 result = _bt_send_request(BT_BLUEZ_SERVICE, BT_MESH_NODE_GET_APPKEYS,
857 in_param1, in_param2, in_param3, in_param4, &out_param);
859 if (result == BLUETOOTH_ERROR_NONE) {
860 if (out_param == NULL) {
861 BT_ERR("Mesh: out_param is NULL");
862 result = BLUETOOTH_ERROR_INTERNAL;
864 size = (out_param->len) / sizeof(guint16);
866 for (i = 0; i < size; i++) {
867 uint16_t appkey_index;
868 uint16_t *appkey_idx = NULL;
870 appkey_index = g_array_index(out_param,
873 appkey_idx = g_memdup(&appkey_index, sizeof(guint16));
874 g_ptr_array_add(*appkeys, (gpointer)appkey_idx);
879 BT_FREE_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
884 BT_EXPORT_API int bluetooth_mesh_model_get_all_appkeys(
885 bluetooth_mesh_model_configure_t *req)
888 bt_user_info_t *user_info;
890 BT_CHECK_PARAMETER(req, return);
892 user_info = _bt_get_user_data(BT_MESH);
893 retv_if(user_info->cb == NULL, BLUETOOTH_ERROR_INTERNAL);
896 BT_ALLOC_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
898 g_array_append_vals(in_param1, req, sizeof(bluetooth_mesh_model_configure_t));
900 BT_INFO("Mesh:Node Model Get AppKey List ");
901 result = _bt_send_request_async(BT_BLUEZ_SERVICE, BT_MESH_MODEL_GET_APPKEY_LIST,
902 in_param1, in_param2, in_param3, in_param4,
903 user_info->cb, user_info->user_data);
905 BT_FREE_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
909 BT_EXPORT_API int bluetooth_mesh_model_set_publication(
910 bluetooth_mesh_model_configure_t *req)
913 bt_user_info_t *user_info;
915 BT_CHECK_PARAMETER(req, return);
917 user_info = _bt_get_user_data(BT_MESH);
918 retv_if(user_info->cb == NULL, BLUETOOTH_ERROR_INTERNAL);
921 BT_ALLOC_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
923 g_array_append_vals(in_param1, req, sizeof(bluetooth_mesh_model_configure_t));
925 BT_INFO("Mesh: Model Set Publication");
926 result = _bt_send_request_async(BT_BLUEZ_SERVICE, BT_MESH_MODEL_SET_PUBLICATION,
927 in_param1, in_param2, in_param3, in_param4,
928 user_info->cb, user_info->user_data);
930 BT_FREE_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
934 BT_EXPORT_API int bluetooth_mesh_model_get_publication(
935 bluetooth_mesh_model_configure_t *req)
938 bt_user_info_t *user_info;
940 BT_CHECK_PARAMETER(req, return);
942 user_info = _bt_get_user_data(BT_MESH);
943 retv_if(user_info->cb == NULL, BLUETOOTH_ERROR_INTERNAL);
946 BT_ALLOC_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
948 g_array_append_vals(in_param1, req, sizeof(bluetooth_mesh_model_configure_t));
950 BT_INFO("Mesh:BTAPI: Model Get Publication");
951 result = _bt_send_request_async(BT_BLUEZ_SERVICE, BT_MESH_MODEL_GET_PUBLICATION,
952 in_param1, in_param2, in_param3, in_param4,
953 user_info->cb, user_info->user_data);
955 BT_FREE_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
959 BT_EXPORT_API int bluetooth_mesh_model_get_subscriptopn_list(
960 bluetooth_mesh_model_configure_t *req)
963 bt_user_info_t *user_info;
965 BT_CHECK_PARAMETER(req, return);
967 user_info = _bt_get_user_data(BT_MESH);
968 retv_if(user_info->cb == NULL, BLUETOOTH_ERROR_INTERNAL);
971 BT_ALLOC_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
973 g_array_append_vals(in_param1, req, sizeof(bluetooth_mesh_model_configure_t));
975 BT_INFO("Mesh:BTAPI: Model Get Subscription List ");
976 result = _bt_send_request_async(BT_BLUEZ_SERVICE, BT_MESH_MODEL_GET_SUBSCRIPTION_LIST,
977 in_param1, in_param2, in_param3, in_param4,
978 user_info->cb, user_info->user_data);
980 BT_FREE_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
984 BT_EXPORT_API int bluetooth_mesh_network_create_group(
985 bluetooth_mesh_network_t *network, bool is_virtual,
986 uint16_t grp_addr, bluetooth_mesh_network_group_info_t *info)
990 BT_CHECK_PARAMETER(network, return);
991 BT_CHECK_PARAMETER(info, return);
994 BT_ALLOC_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
996 g_array_append_vals(in_param1, network, sizeof(bluetooth_mesh_network_t));
997 g_array_append_vals(in_param2, &is_virtual, sizeof(gboolean));
998 g_array_append_vals(in_param3, &grp_addr, sizeof(guint16));
1000 BT_INFO("Mesh: Create Group Request");
1001 result = _bt_send_request(BT_BLUEZ_SERVICE, BT_MESH_NETWORK_CREATE_GROUP,
1002 in_param1, in_param2, in_param3, in_param4, &out_param);
1004 if (result == BLUETOOTH_ERROR_NONE) {
1005 *info = g_array_index(out_param,
1006 bluetooth_mesh_network_group_info_t, 0);
1008 BT_FREE_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
1013 BT_EXPORT_API int bluetooth_mesh_model_configure_group_sub(
1014 bluetooth_mesh_model_configure_t *req)
1017 bt_user_info_t *user_info;
1019 BT_CHECK_PARAMETER(req, return);
1021 user_info = _bt_get_user_data(BT_MESH);
1022 retv_if(user_info->cb == NULL, BLUETOOTH_ERROR_INTERNAL);
1025 BT_ALLOC_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
1027 g_array_append_vals(in_param1, req, sizeof(bluetooth_mesh_model_configure_t));
1029 BT_INFO("Mesh:Model Group Subscription Request");
1030 result = _bt_send_request_async(BT_BLUEZ_SERVICE, BT_MESH_MODEL_CONFIG_GROUP_SUB,
1031 in_param1, in_param2, in_param3, in_param4,
1032 user_info->cb, user_info->user_data);
1034 BT_FREE_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
1038 BT_EXPORT_API int bluetooth_mesh_model_configure_virtual_group_sub(
1039 bluetooth_mesh_model_configure_t *req)
1042 bt_user_info_t *user_info;
1044 BT_CHECK_PARAMETER(req, return);
1046 user_info = _bt_get_user_data(BT_MESH);
1047 retv_if(user_info->cb == NULL, BLUETOOTH_ERROR_INTERNAL);
1050 BT_ALLOC_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
1052 g_array_append_vals(in_param1, req, sizeof(bluetooth_mesh_model_configure_t));
1054 BT_INFO("Mesh: Model Virtual Group Subscription Request");
1055 result = _bt_send_request_async(BT_BLUEZ_SERVICE,
1056 BT_MESH_MODEL_CONFIG_VIRTUAL_GROUP_SUB,
1057 in_param1, in_param2, in_param3, in_param4,
1058 user_info->cb, user_info->user_data);
1060 BT_FREE_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);