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);
334 BT_FREE_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
339 BT_EXPORT_API int bluetooth_mesh_network_delete_netkey(
340 bluetooth_mesh_network_t *network,
345 BT_CHECK_PARAMETER(network, return);
348 BT_ALLOC_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
350 g_array_append_vals(in_param1, network, sizeof(bluetooth_mesh_network_t));
351 g_array_append_vals(in_param2, &netkey_idx, sizeof(guint16));
353 BT_INFO("Mesh: Delete Subnetwork key");
354 result = _bt_send_request(BT_BLUEZ_SERVICE, BT_MESH_NETWORK_DELETE_NETKEY,
355 in_param1, in_param2, in_param3, in_param4, &out_param);
356 BT_FREE_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
361 BT_EXPORT_API int bluetooth_mesh_network_update_netkey(
362 bluetooth_mesh_network_t *network,
367 BT_CHECK_PARAMETER(network, return);
370 BT_ALLOC_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
372 g_array_append_vals(in_param1, network, sizeof(bluetooth_mesh_network_t));
373 g_array_append_vals(in_param2, &netkey_idx, sizeof(guint16));
375 BT_INFO("Mesh: Update Subnetwork key");
376 result = _bt_send_request(BT_BLUEZ_SERVICE, BT_MESH_NETWORK_UPDATE_NETKEY,
377 in_param1, in_param2, in_param3, in_param4, &out_param);
378 BT_FREE_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
383 BT_EXPORT_API int bluetooth_mesh_network_add_appkey(
384 bluetooth_mesh_network_t *network,
385 uint16_t netkey_index,
386 uint16_t *appkey_index)
390 BT_CHECK_PARAMETER(network, return);
391 BT_CHECK_PARAMETER(appkey_index, return);
394 BT_ALLOC_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
396 g_array_append_vals(in_param1, network, sizeof(bluetooth_mesh_network_t));
397 g_array_append_vals(in_param2, &netkey_index, sizeof(guint16));
399 BT_INFO("Mesh: Create AppKey");
400 result = _bt_send_request(BT_BLUEZ_SERVICE, BT_MESH_NETWORK_ADD_APPKEY,
401 in_param1, in_param2, in_param3, in_param4, &out_param);
403 if (result == BLUETOOTH_ERROR_NONE) {
404 *appkey_index = g_array_index(out_param, guint16, 0);
406 BT_FREE_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
411 BT_EXPORT_API int bluetooth_mesh_network_update_appkey(
412 bluetooth_mesh_network_t *network,
413 uint16_t netkey_index, uint16_t appkey_index)
417 BT_CHECK_PARAMETER(network, return);
420 BT_ALLOC_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
422 g_array_append_vals(in_param1, network, sizeof(bluetooth_mesh_network_t));
423 g_array_append_vals(in_param2, &netkey_index, sizeof(guint16));
424 g_array_append_vals(in_param3, &appkey_index, sizeof(guint16));
426 BT_INFO("Mesh:BTAPI: Update AppKey");
427 result = _bt_send_request(BT_BLUEZ_SERVICE, BT_MESH_NETWORK_UPDATE_APPKEY,
428 in_param1, in_param2, in_param3, in_param4, &out_param);
430 BT_FREE_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
435 BT_EXPORT_API int bluetooth_mesh_network_delete_appkey(bluetooth_mesh_network_t *network,
436 uint16_t netkey_index, uint16_t appkey_index)
440 BT_CHECK_PARAMETER(network, return);
443 BT_ALLOC_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
445 g_array_append_vals(in_param1, network, sizeof(bluetooth_mesh_network_t));
446 g_array_append_vals(in_param2, &netkey_index, sizeof(guint16));
447 g_array_append_vals(in_param3, &appkey_index, sizeof(guint16));
449 BT_INFO("Mesh: Delete AppKey");
450 result = _bt_send_request(BT_BLUEZ_SERVICE, BT_MESH_NETWORK_DELETE_APPKEY,
451 in_param1, in_param2, in_param3, in_param4, &out_param);
453 BT_FREE_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
458 BT_EXPORT_API int bluetooth_mesh_network_get_all_nodes(
459 bluetooth_mesh_network_t *network,
462 int result = BLUETOOTH_ERROR_NONE;
465 bluetooth_mesh_node_info_t *info;
467 BT_CHECK_PARAMETER(network, return);
468 BT_CHECK_PARAMETER(nodes, return);
471 BT_ALLOC_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
473 g_array_append_vals(in_param1, network, sizeof(bluetooth_mesh_network_t));
475 result = _bt_send_request(BT_BLUEZ_SERVICE, BT_MESH_NETWORK_GET_NODES,
476 in_param1, in_param2, in_param3, in_param4, &out_param);
478 if (result == BLUETOOTH_ERROR_NONE) {
479 if (out_param == NULL) {
480 BT_ERR("Mesh: out_param is NULL");
481 result = BLUETOOTH_ERROR_INTERNAL;
483 size = (out_param->len) / sizeof(bluetooth_mesh_node_info_t);
485 for (i = 0; i < size; i++) {
486 bluetooth_mesh_node_info_t *data;
488 info = &g_array_index(out_param,
489 bluetooth_mesh_node_info_t, i);
491 data= g_memdup(info, sizeof(bluetooth_mesh_node_info_t));
492 g_ptr_array_add(*nodes, (gpointer)data);
497 BT_FREE_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
502 BT_EXPORT_API int bluetooth_mesh_element_get_all_models(
503 bluetooth_mesh_network_t *network,
504 uint16_t node_addr, int elem_idx,
507 int result = BLUETOOTH_ERROR_NONE;
511 BT_CHECK_PARAMETER(network, return);
512 BT_CHECK_PARAMETER(models, return);
515 BT_ALLOC_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
517 g_array_append_vals(in_param1, network, sizeof(bluetooth_mesh_network_t));
518 g_array_append_vals(in_param2, &node_addr, sizeof(guint16));
519 g_array_append_vals(in_param3, &elem_idx, sizeof(int));
521 result = _bt_send_request(BT_BLUEZ_SERVICE, BT_MESH_ELEMENT_GET_MODELS,
522 in_param1, in_param2, in_param3, in_param4, &out_param);
524 if (result == BLUETOOTH_ERROR_NONE) {
525 if (out_param == NULL) {
526 BT_ERR("Mesh: out_param is NULL");
527 result = BLUETOOTH_ERROR_INTERNAL;
529 size = (out_param->len) / sizeof(guint32);
530 BT_INFO("Mesh: Total Models found in Element [%d]", size);
532 for (i = 0; i < size; i++) {
534 uint32_t *model_ptr = NULL;
536 model_obj = g_array_index(out_param,
539 model_ptr = g_memdup(&model_obj, sizeof(guint32));
540 g_ptr_array_add(*models, (gpointer)model_ptr);
545 BT_FREE_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
550 BT_EXPORT_API int bluetooth_mesh_node_browse_vendor_features(
551 bluetooth_mesh_node_features_t *req)
554 bt_user_info_t *user_info;
556 BT_CHECK_PARAMETER(req, return);
558 user_info = _bt_get_user_data(BT_MESH);
559 retv_if(user_info->cb == NULL, BLUETOOTH_ERROR_INTERNAL);
562 BT_ALLOC_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
564 g_array_append_vals(in_param1, req, sizeof(bluetooth_mesh_node_features_t));
566 BT_INFO("Mesh: Browse Vendor features of Node");
567 result = _bt_send_request_async(BT_BLUEZ_SERVICE, BT_MESH_NODE_GET_VENDOR_FEATURES,
568 in_param1, in_param2, in_param3, in_param4,
569 user_info->cb, user_info->user_data);
571 BT_FREE_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
576 BT_EXPORT_API int bluetooth_mesh_browse_remote_node(
577 bluetooth_mesh_node_discover_t *req)
580 bt_user_info_t *user_info;
582 BT_CHECK_PARAMETER(req, return);
584 user_info = _bt_get_user_data(BT_MESH);
585 retv_if(user_info->cb == NULL, BLUETOOTH_ERROR_INTERNAL);
588 BT_ALLOC_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
590 g_array_append_vals(in_param1, req, sizeof(bluetooth_mesh_node_discover_t));
592 BT_INFO("Mesh: Browse remote Node");
593 result = _bt_send_request_async(BT_BLUEZ_SERVICE, BT_MESH_NODE_BROWSE,
594 in_param1, in_param2, in_param3, in_param4,
595 user_info->cb, user_info->user_data);
597 BT_FREE_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
602 BT_EXPORT_API int bluetooth_mesh_node_ttl_execute(
603 bluetooth_mesh_node_ttl_info_t *req)
606 bt_user_info_t *user_info;
608 BT_CHECK_PARAMETER(req, return);
610 user_info = _bt_get_user_data(BT_MESH);
611 retv_if(user_info->cb == NULL, BLUETOOTH_ERROR_INTERNAL);
614 BT_ALLOC_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
616 g_array_append_vals(in_param1, req, sizeof(bluetooth_mesh_node_ttl_info_t));
618 BT_INFO("Mesh: Node TTL Execute");
619 result = _bt_send_request_async(BT_BLUEZ_SERVICE, BT_MESH_NODE_TTL_EXECUTE,
620 in_param1, in_param2, in_param3, in_param4,
621 user_info->cb, user_info->user_data);
623 BT_FREE_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
628 BT_EXPORT_API int bluetooth_mesh_model_configure_appkey(
629 bluetooth_mesh_model_configure_t *req)
632 bt_user_info_t *user_info;
634 BT_CHECK_PARAMETER(req, return);
636 user_info = _bt_get_user_data(BT_MESH);
637 retv_if(user_info->cb == NULL, BLUETOOTH_ERROR_INTERNAL);
640 BT_ALLOC_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
642 g_array_append_vals(in_param1, req, sizeof(bluetooth_mesh_model_configure_t));
644 BT_INFO("Mesh: Node Model Configure AppKey");
645 result = _bt_send_request_async(BT_BLUEZ_SERVICE, BT_MESH_MODEL_CONFIGURE_APPKEY,
646 in_param1, in_param2, in_param3, in_param4,
647 user_info->cb, user_info->user_data);
649 BT_FREE_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
654 BT_EXPORT_API int bluetooth_mesh_node_configure_key(
655 bluetooth_mesh_key_configure_t *req)
658 bt_user_info_t *user_info;
660 BT_CHECK_PARAMETER(req, return);
662 user_info = _bt_get_user_data(BT_MESH);
663 retv_if(user_info->cb == NULL, BLUETOOTH_ERROR_INTERNAL);
666 BT_ALLOC_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
668 g_array_append_vals(in_param1, req, sizeof(bluetooth_mesh_key_configure_t));
670 BT_INFO("Mesh:BTAPI: Node Key Configure");
671 result = _bt_send_request_async(BT_BLUEZ_SERVICE, BT_MESH_NODE_CONFIGURE_KEY,
672 in_param1, in_param2, in_param3, in_param4,
673 user_info->cb, user_info->user_data);
675 BT_FREE_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
680 BT_EXPORT_API int bluetooth_mesh_network_get_all_groups(
681 bluetooth_mesh_network_t *network,
684 int result = BLUETOOTH_ERROR_NONE;
685 bluetooth_mesh_network_group_info_t *info;
689 BT_CHECK_PARAMETER(network, return);
690 BT_CHECK_PARAMETER(groups, return);
693 BT_ALLOC_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
695 g_array_append_vals(in_param1, network, sizeof(bluetooth_mesh_network_t));
697 result = _bt_send_request(BT_BLUEZ_SERVICE, BT_MESH_NETWORK_GET_GROUPS,
698 in_param1, in_param2, in_param3, in_param4, &out_param);
700 if (result == BLUETOOTH_ERROR_NONE) {
701 if (out_param == NULL) {
702 BT_ERR("Mesh: out_param is NULL");
703 result = BLUETOOTH_ERROR_INTERNAL;
705 size = (out_param->len) / sizeof(bluetooth_mesh_network_group_info_t);
708 BT_INFO("Mesh: No Groups created for the network");
711 BT_INFO("Mesh: Total groups [%d]", size);
712 for (i = 0; i < size; i++) {
713 bluetooth_mesh_network_group_info_t *grp_info = NULL;
715 info = &g_array_index(out_param,
716 bluetooth_mesh_network_group_info_t, i);
717 BT_INFO("Mesh: Group addr [0x%2.2x]", info->group_addr);
718 BT_INFO("Mesh: Group is Virtual [%s]", info->is_virtual? "YES":"NO");
719 BT_INFO("Mesh: Group net UUID[%s]", info->net_uuid);
720 if (info->is_virtual)
721 BT_INFO("Mesh: Virual Label UUID [%s]", info->label_uuid);
722 grp_info = g_memdup(info,
723 sizeof(bluetooth_mesh_network_group_info_t));
724 g_ptr_array_add(*groups, (gpointer)grp_info);
729 BT_FREE_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
734 BT_EXPORT_API int bluetooth_mesh_network_get_all_netkey(
735 bluetooth_mesh_network_t *network,
738 int result = BLUETOOTH_ERROR_NONE;
742 BT_CHECK_PARAMETER(network, return);
743 BT_CHECK_PARAMETER(netkeys, return);
746 BT_ALLOC_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
748 g_array_append_vals(in_param1, network, sizeof(bluetooth_mesh_network_t));
750 result = _bt_send_request(BT_BLUEZ_SERVICE, BT_MESH_NETWORK_GET_NETKEYS,
751 in_param1, in_param2, in_param3, in_param4, &out_param);
753 if (result == BLUETOOTH_ERROR_NONE) {
754 if (out_param == NULL) {
755 BT_ERR("Mesh: out_param is NULL");
756 result = BLUETOOTH_ERROR_INTERNAL;
758 size = (out_param->len) / sizeof(guint16);
761 BT_ERR("Mesh: No netkeys created for the network");
762 result = BLUETOOTH_ERROR_NOT_FOUND;
765 for (i = 0; i < size; i++) {
766 uint16_t netkey_index;
767 uint16_t *netkey_idx = NULL;
769 netkey_index = g_array_index(out_param,
772 netkey_idx = g_memdup(&netkey_index, sizeof(guint16));
773 g_ptr_array_add(*netkeys, (gpointer)netkey_idx);
778 BT_FREE_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
783 BT_EXPORT_API int bluetooth_mesh_netkey_get_all_appkey(
784 bluetooth_mesh_network_t *network,
788 int result = BLUETOOTH_ERROR_NONE;
792 BT_CHECK_PARAMETER(network, return);
793 BT_CHECK_PARAMETER(appkeys, return);
796 BT_ALLOC_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
798 g_array_append_vals(in_param1, network, sizeof(bluetooth_mesh_network_t));
799 g_array_append_vals(in_param2, &netkey_idx, sizeof(guint16));
801 result = _bt_send_request(BT_BLUEZ_SERVICE, BT_MESH_NETWORK_GET_APPKEYS,
802 in_param1, in_param2, in_param3, in_param4, &out_param);
804 if (result == BLUETOOTH_ERROR_NONE) {
805 if (out_param == NULL) {
806 BT_ERR("Mesh: out_param is NULL");
807 result = BLUETOOTH_ERROR_INTERNAL;
809 size = (out_param->len) / sizeof(guint16);
812 BT_ERR("Mesh: No Appkeys created for the NetKey in the network");
815 for (i = 0; i < size; i++) {
816 uint16_t appkey_index;
817 uint16_t *appkey_idx = NULL;
819 appkey_index = g_array_index(out_param,
822 appkey_idx = g_memdup(&appkey_index, sizeof(guint16));
823 g_ptr_array_add(*appkeys, (gpointer)appkey_idx);
828 BT_FREE_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
833 BT_EXPORT_API int bluetooth_mesh_node_get_all_netkeys(
834 bluetooth_mesh_node_discover_t *node,
837 int result = BLUETOOTH_ERROR_NONE;
841 BT_CHECK_PARAMETER(node, return);
842 BT_CHECK_PARAMETER(netkeys, return);
845 BT_ALLOC_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
847 g_array_append_vals(in_param1, node, sizeof(bluetooth_mesh_node_discover_t));
849 result = _bt_send_request(BT_BLUEZ_SERVICE, BT_MESH_NODE_GET_NETKEYS,
850 in_param1, in_param2, in_param3, in_param4, &out_param);
852 if (result == BLUETOOTH_ERROR_NONE) {
853 if (out_param == NULL) {
854 BT_ERR("Mesh: out_param is NULL");
855 result = BLUETOOTH_ERROR_INTERNAL;
857 size = (out_param->len) / sizeof(guint16);
859 for (i = 0; i < size; i++) {
860 uint16_t netkey_index;
861 uint16_t *netkey_idx = NULL;
863 netkey_index = g_array_index(out_param,
866 netkey_idx = g_memdup(&netkey_index, sizeof(guint16));
867 g_ptr_array_add(*netkeys, (gpointer)netkey_idx);
872 BT_FREE_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
877 BT_EXPORT_API int bluetooth_mesh_node_get_all_appkeys(
878 bluetooth_mesh_node_discover_t *req, GPtrArray **appkeys)
880 int result = BLUETOOTH_ERROR_NONE;
884 BT_CHECK_PARAMETER(req, return);
885 BT_CHECK_PARAMETER(appkeys, return);
888 BT_ALLOC_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
890 g_array_append_vals(in_param1, req, sizeof(bluetooth_mesh_node_discover_t));
892 result = _bt_send_request(BT_BLUEZ_SERVICE, BT_MESH_NODE_GET_APPKEYS,
893 in_param1, in_param2, in_param3, in_param4, &out_param);
895 if (result == BLUETOOTH_ERROR_NONE) {
896 if (out_param == NULL) {
897 BT_ERR("Mesh: out_param is NULL");
898 result = BLUETOOTH_ERROR_INTERNAL;
900 size = (out_param->len) / sizeof(guint16);
902 for (i = 0; i < size; i++) {
903 uint16_t appkey_index;
904 uint16_t *appkey_idx = NULL;
906 appkey_index = g_array_index(out_param,
909 appkey_idx = g_memdup(&appkey_index, sizeof(guint16));
910 g_ptr_array_add(*appkeys, (gpointer)appkey_idx);
915 BT_FREE_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
920 BT_EXPORT_API int bluetooth_mesh_model_get_all_appkeys(
921 bluetooth_mesh_model_configure_t *req)
924 bt_user_info_t *user_info;
926 BT_CHECK_PARAMETER(req, return);
928 user_info = _bt_get_user_data(BT_MESH);
929 retv_if(user_info->cb == NULL, BLUETOOTH_ERROR_INTERNAL);
932 BT_ALLOC_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
934 g_array_append_vals(in_param1, req, sizeof(bluetooth_mesh_model_configure_t));
936 BT_INFO("Mesh:Node Model Get AppKey List ");
937 result = _bt_send_request_async(BT_BLUEZ_SERVICE, BT_MESH_MODEL_GET_APPKEY_LIST,
938 in_param1, in_param2, in_param3, in_param4,
939 user_info->cb, user_info->user_data);
941 BT_FREE_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
945 BT_EXPORT_API int bluetooth_mesh_model_set_publication(
946 bluetooth_mesh_model_configure_t *req)
949 bt_user_info_t *user_info;
951 BT_CHECK_PARAMETER(req, return);
953 user_info = _bt_get_user_data(BT_MESH);
954 retv_if(user_info->cb == NULL, BLUETOOTH_ERROR_INTERNAL);
957 BT_ALLOC_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
959 g_array_append_vals(in_param1, req, sizeof(bluetooth_mesh_model_configure_t));
961 BT_INFO("Mesh: Model Set Publication");
962 result = _bt_send_request_async(BT_BLUEZ_SERVICE, BT_MESH_MODEL_SET_PUBLICATION,
963 in_param1, in_param2, in_param3, in_param4,
964 user_info->cb, user_info->user_data);
966 BT_FREE_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
970 BT_EXPORT_API int bluetooth_mesh_model_get_publication(
971 bluetooth_mesh_model_configure_t *req)
974 bt_user_info_t *user_info;
976 BT_CHECK_PARAMETER(req, return);
978 user_info = _bt_get_user_data(BT_MESH);
979 retv_if(user_info->cb == NULL, BLUETOOTH_ERROR_INTERNAL);
982 BT_ALLOC_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
984 g_array_append_vals(in_param1, req, sizeof(bluetooth_mesh_model_configure_t));
986 BT_INFO("Mesh:BTAPI: Model Get Publication");
987 result = _bt_send_request_async(BT_BLUEZ_SERVICE, BT_MESH_MODEL_GET_PUBLICATION,
988 in_param1, in_param2, in_param3, in_param4,
989 user_info->cb, user_info->user_data);
991 BT_FREE_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
995 BT_EXPORT_API int bluetooth_mesh_model_get_subscriptopn_list(
996 bluetooth_mesh_model_configure_t *req)
999 bt_user_info_t *user_info;
1001 BT_CHECK_PARAMETER(req, return);
1003 user_info = _bt_get_user_data(BT_MESH);
1004 retv_if(user_info->cb == NULL, BLUETOOTH_ERROR_INTERNAL);
1007 BT_ALLOC_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
1009 g_array_append_vals(in_param1, req, sizeof(bluetooth_mesh_model_configure_t));
1011 BT_INFO("Mesh:BTAPI: Model Get Subscription List ");
1012 result = _bt_send_request_async(BT_BLUEZ_SERVICE, BT_MESH_MODEL_GET_SUBSCRIPTION_LIST,
1013 in_param1, in_param2, in_param3, in_param4,
1014 user_info->cb, user_info->user_data);
1016 BT_FREE_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
1020 BT_EXPORT_API int bluetooth_mesh_network_remove_group(
1021 bluetooth_mesh_network_t *network,
1022 bluetooth_mesh_network_group_info_t *req)
1026 BT_CHECK_PARAMETER(network, return);
1027 BT_CHECK_PARAMETER(req, return);
1030 BT_ALLOC_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
1032 g_array_append_vals(in_param1, network, sizeof(bluetooth_mesh_network_t));
1033 g_array_append_vals(in_param2, req, sizeof(bluetooth_mesh_network_group_info_t));
1035 BT_INFO("Mesh: Remove Group Request");
1036 result = _bt_send_request(BT_BLUEZ_SERVICE, BT_MESH_NETWORK_REMOVE_GROUP,
1037 in_param1, in_param2, in_param3, in_param4, &out_param);
1039 BT_FREE_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
1044 BT_EXPORT_API int bluetooth_mesh_network_create_group(
1045 bluetooth_mesh_network_t *network, bool is_virtual,
1046 uint16_t grp_addr, bluetooth_mesh_network_group_info_t *info)
1050 BT_CHECK_PARAMETER(network, return);
1051 BT_CHECK_PARAMETER(info, return);
1054 BT_ALLOC_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
1056 g_array_append_vals(in_param1, network, sizeof(bluetooth_mesh_network_t));
1057 g_array_append_vals(in_param2, &is_virtual, sizeof(gboolean));
1058 g_array_append_vals(in_param3, &grp_addr, sizeof(guint16));
1060 BT_INFO("Mesh: Create Group Request");
1061 result = _bt_send_request(BT_BLUEZ_SERVICE, BT_MESH_NETWORK_CREATE_GROUP,
1062 in_param1, in_param2, in_param3, in_param4, &out_param);
1064 if (result == BLUETOOTH_ERROR_NONE) {
1065 *info = g_array_index(out_param,
1066 bluetooth_mesh_network_group_info_t, 0);
1068 BT_FREE_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
1073 BT_EXPORT_API int bluetooth_mesh_model_configure_group_sub(
1074 bluetooth_mesh_model_configure_t *req)
1077 bt_user_info_t *user_info;
1079 BT_CHECK_PARAMETER(req, return);
1081 user_info = _bt_get_user_data(BT_MESH);
1082 retv_if(user_info->cb == NULL, BLUETOOTH_ERROR_INTERNAL);
1085 BT_ALLOC_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
1087 g_array_append_vals(in_param1, req, sizeof(bluetooth_mesh_model_configure_t));
1089 BT_INFO("Mesh:Model Group Subscription Request");
1090 result = _bt_send_request_async(BT_BLUEZ_SERVICE, BT_MESH_MODEL_CONFIG_GROUP_SUB,
1091 in_param1, in_param2, in_param3, in_param4,
1092 user_info->cb, user_info->user_data);
1094 BT_FREE_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
1098 BT_EXPORT_API int bluetooth_mesh_model_configure_virtual_group_sub(
1099 bluetooth_mesh_model_configure_t *req)
1102 bt_user_info_t *user_info;
1104 BT_CHECK_PARAMETER(req, return);
1106 user_info = _bt_get_user_data(BT_MESH);
1107 retv_if(user_info->cb == NULL, BLUETOOTH_ERROR_INTERNAL);
1110 BT_ALLOC_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
1112 g_array_append_vals(in_param1, req, sizeof(bluetooth_mesh_model_configure_t));
1114 BT_INFO("Mesh: Model Virtual Group Subscription Request");
1115 result = _bt_send_request_async(BT_BLUEZ_SERVICE,
1116 BT_MESH_MODEL_CONFIG_VIRTUAL_GROUP_SUB,
1117 in_param1, in_param2, in_param3, in_param4,
1118 user_info->cb, user_info->user_data);
1120 BT_FREE_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);