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(guint16);
531 for (i = 0; i < size; i++) {
533 uint32_t *model_ptr = NULL;
535 model_obj = g_array_index(out_param,
538 model_ptr = g_memdup(&model_obj, sizeof(guint32));
539 g_ptr_array_add(*models, (gpointer)model_ptr);
544 BT_FREE_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
549 BT_EXPORT_API int bluetooth_mesh_node_browse_vendor_features(
550 bluetooth_mesh_node_features_t *req)
553 bt_user_info_t *user_info;
555 BT_CHECK_PARAMETER(req, return);
557 user_info = _bt_get_user_data(BT_MESH);
558 retv_if(user_info->cb == NULL, BLUETOOTH_ERROR_INTERNAL);
561 BT_ALLOC_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
563 g_array_append_vals(in_param1, req, sizeof(bluetooth_mesh_node_features_t));
565 BT_INFO("Mesh: Browse Vendor features of Node");
566 result = _bt_send_request_async(BT_BLUEZ_SERVICE, BT_MESH_NODE_GET_VENDOR_FEATURES,
567 in_param1, in_param2, in_param3, in_param4,
568 user_info->cb, user_info->user_data);
570 BT_FREE_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
575 BT_EXPORT_API int bluetooth_mesh_browse_remote_node(
576 bluetooth_mesh_node_discover_t *req)
579 bt_user_info_t *user_info;
581 BT_CHECK_PARAMETER(req, return);
583 user_info = _bt_get_user_data(BT_MESH);
584 retv_if(user_info->cb == NULL, BLUETOOTH_ERROR_INTERNAL);
587 BT_ALLOC_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
589 g_array_append_vals(in_param1, req, sizeof(bluetooth_mesh_node_discover_t));
591 BT_INFO("Mesh: Browse remote Node");
592 result = _bt_send_request_async(BT_BLUEZ_SERVICE, BT_MESH_NODE_BROWSE,
593 in_param1, in_param2, in_param3, in_param4,
594 user_info->cb, user_info->user_data);
596 BT_FREE_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
601 BT_EXPORT_API int bluetooth_mesh_node_ttl_execute(
602 bluetooth_mesh_node_ttl_info_t *req)
605 bt_user_info_t *user_info;
607 BT_CHECK_PARAMETER(req, return);
609 user_info = _bt_get_user_data(BT_MESH);
610 retv_if(user_info->cb == NULL, BLUETOOTH_ERROR_INTERNAL);
613 BT_ALLOC_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
615 g_array_append_vals(in_param1, req, sizeof(bluetooth_mesh_node_ttl_info_t));
617 BT_INFO("Mesh: Node TTL Execute");
618 result = _bt_send_request_async(BT_BLUEZ_SERVICE, BT_MESH_NODE_TTL_EXECUTE,
619 in_param1, in_param2, in_param3, in_param4,
620 user_info->cb, user_info->user_data);
622 BT_FREE_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
627 BT_EXPORT_API int bluetooth_mesh_model_configure_appkey(
628 bluetooth_mesh_model_configure_t *req)
631 bt_user_info_t *user_info;
633 BT_CHECK_PARAMETER(req, return);
635 user_info = _bt_get_user_data(BT_MESH);
636 retv_if(user_info->cb == NULL, BLUETOOTH_ERROR_INTERNAL);
639 BT_ALLOC_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
641 g_array_append_vals(in_param1, req, sizeof(bluetooth_mesh_model_configure_t));
643 BT_INFO("Mesh: Node Model Configure AppKey");
644 result = _bt_send_request_async(BT_BLUEZ_SERVICE, BT_MESH_MODEL_CONFIGURE_APPKEY,
645 in_param1, in_param2, in_param3, in_param4,
646 user_info->cb, user_info->user_data);
648 BT_FREE_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
653 BT_EXPORT_API int bluetooth_mesh_node_configure_key(
654 bluetooth_mesh_key_configure_t *req)
657 bt_user_info_t *user_info;
659 BT_CHECK_PARAMETER(req, return);
661 user_info = _bt_get_user_data(BT_MESH);
662 retv_if(user_info->cb == NULL, BLUETOOTH_ERROR_INTERNAL);
665 BT_ALLOC_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
667 g_array_append_vals(in_param1, req, sizeof(bluetooth_mesh_key_configure_t));
669 BT_INFO("Mesh:BTAPI: Node Key Configure");
670 result = _bt_send_request_async(BT_BLUEZ_SERVICE, BT_MESH_NODE_CONFIGURE_KEY,
671 in_param1, in_param2, in_param3, in_param4,
672 user_info->cb, user_info->user_data);
674 BT_FREE_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
679 BT_EXPORT_API int bluetooth_mesh_network_get_all_groups(
680 bluetooth_mesh_network_t *network,
683 int result = BLUETOOTH_ERROR_NONE;
684 bluetooth_mesh_network_group_info_t *info;
688 BT_CHECK_PARAMETER(network, return);
689 BT_CHECK_PARAMETER(groups, return);
692 BT_ALLOC_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
694 g_array_append_vals(in_param1, network, sizeof(bluetooth_mesh_network_t));
696 result = _bt_send_request(BT_BLUEZ_SERVICE, BT_MESH_NETWORK_GET_GROUPS,
697 in_param1, in_param2, in_param3, in_param4, &out_param);
699 if (result == BLUETOOTH_ERROR_NONE) {
700 if (out_param == NULL) {
701 BT_ERR("Mesh: out_param is NULL");
702 result = BLUETOOTH_ERROR_INTERNAL;
704 size = (out_param->len) / sizeof(bluetooth_mesh_network_group_info_t);
707 BT_INFO("Mesh: No Groups created for the network");
710 BT_INFO("Mesh: Total groups [%d]", size);
711 for (i = 0; i < size; i++) {
712 bluetooth_mesh_network_group_info_t *grp_info = NULL;
714 info = &g_array_index(out_param,
715 bluetooth_mesh_network_group_info_t, i);
716 BT_INFO("Mesh: Group addr [0x%2.2x]", info->group_addr);
717 BT_INFO("Mesh: Group is Virtual [%s]", info->is_virtual? "YES":"NO");
718 BT_INFO("Mesh: Group net UUID[%s]", info->net_uuid);
719 if (info->is_virtual)
720 BT_INFO("Mesh: Virual Label UUID [%s]", info->label_uuid);
721 grp_info = g_memdup(info,
722 sizeof(bluetooth_mesh_network_group_info_t));
723 g_ptr_array_add(*groups, (gpointer)grp_info);
728 BT_FREE_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
733 BT_EXPORT_API int bluetooth_mesh_network_get_all_netkey(
734 bluetooth_mesh_network_t *network,
737 int result = BLUETOOTH_ERROR_NONE;
741 BT_CHECK_PARAMETER(network, return);
742 BT_CHECK_PARAMETER(netkeys, return);
745 BT_ALLOC_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
747 g_array_append_vals(in_param1, network, sizeof(bluetooth_mesh_network_t));
749 result = _bt_send_request(BT_BLUEZ_SERVICE, BT_MESH_NETWORK_GET_NETKEYS,
750 in_param1, in_param2, in_param3, in_param4, &out_param);
752 if (result == BLUETOOTH_ERROR_NONE) {
753 if (out_param == NULL) {
754 BT_ERR("Mesh: out_param is NULL");
755 result = BLUETOOTH_ERROR_INTERNAL;
757 size = (out_param->len) / sizeof(guint16);
760 BT_ERR("Mesh: No netkeys created for the network");
761 result = BLUETOOTH_ERROR_NOT_FOUND;
764 for (i = 0; i < size; i++) {
765 uint16_t netkey_index;
766 uint16_t *netkey_idx = NULL;
768 netkey_index = g_array_index(out_param,
771 netkey_idx = g_memdup(&netkey_index, sizeof(guint16));
772 g_ptr_array_add(*netkeys, (gpointer)netkey_idx);
777 BT_FREE_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
782 BT_EXPORT_API int bluetooth_mesh_netkey_get_all_appkey(
783 bluetooth_mesh_network_t *network,
787 int result = BLUETOOTH_ERROR_NONE;
791 BT_CHECK_PARAMETER(network, return);
792 BT_CHECK_PARAMETER(appkeys, return);
795 BT_ALLOC_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
797 g_array_append_vals(in_param1, network, sizeof(bluetooth_mesh_network_t));
798 g_array_append_vals(in_param2, &netkey_idx, sizeof(guint16));
800 result = _bt_send_request(BT_BLUEZ_SERVICE, BT_MESH_NETWORK_GET_APPKEYS,
801 in_param1, in_param2, in_param3, in_param4, &out_param);
803 if (result == BLUETOOTH_ERROR_NONE) {
804 if (out_param == NULL) {
805 BT_ERR("Mesh: out_param is NULL");
806 result = BLUETOOTH_ERROR_INTERNAL;
808 size = (out_param->len) / sizeof(guint16);
811 BT_ERR("Mesh: No Appkeys created for the NetKey in the network");
814 for (i = 0; i < size; i++) {
815 uint16_t appkey_index;
816 uint16_t *appkey_idx = NULL;
818 appkey_index = g_array_index(out_param,
821 appkey_idx = g_memdup(&appkey_index, sizeof(guint16));
822 g_ptr_array_add(*appkeys, (gpointer)appkey_idx);
827 BT_FREE_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
832 BT_EXPORT_API int bluetooth_mesh_node_get_all_netkeys(
833 bluetooth_mesh_node_discover_t *node,
836 int result = BLUETOOTH_ERROR_NONE;
840 BT_CHECK_PARAMETER(node, return);
841 BT_CHECK_PARAMETER(netkeys, return);
844 BT_ALLOC_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
846 g_array_append_vals(in_param1, node, sizeof(bluetooth_mesh_node_discover_t));
848 result = _bt_send_request(BT_BLUEZ_SERVICE, BT_MESH_NODE_GET_NETKEYS,
849 in_param1, in_param2, in_param3, in_param4, &out_param);
851 if (result == BLUETOOTH_ERROR_NONE) {
852 if (out_param == NULL) {
853 BT_ERR("Mesh: out_param is NULL");
854 result = BLUETOOTH_ERROR_INTERNAL;
856 size = (out_param->len) / sizeof(guint16);
858 for (i = 0; i < size; i++) {
859 uint16_t netkey_index;
860 uint16_t *netkey_idx = NULL;
862 netkey_index = g_array_index(out_param,
865 netkey_idx = g_memdup(&netkey_index, sizeof(guint16));
866 g_ptr_array_add(*netkeys, (gpointer)netkey_idx);
871 BT_FREE_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
876 BT_EXPORT_API int bluetooth_mesh_node_get_all_appkeys(
877 bluetooth_mesh_node_discover_t *req, GPtrArray **appkeys)
879 int result = BLUETOOTH_ERROR_NONE;
883 BT_CHECK_PARAMETER(req, return);
884 BT_CHECK_PARAMETER(appkeys, return);
887 BT_ALLOC_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
889 g_array_append_vals(in_param1, req, sizeof(bluetooth_mesh_node_discover_t));
891 result = _bt_send_request(BT_BLUEZ_SERVICE, BT_MESH_NODE_GET_APPKEYS,
892 in_param1, in_param2, in_param3, in_param4, &out_param);
894 if (result == BLUETOOTH_ERROR_NONE) {
895 if (out_param == NULL) {
896 BT_ERR("Mesh: out_param is NULL");
897 result = BLUETOOTH_ERROR_INTERNAL;
899 size = (out_param->len) / sizeof(guint16);
901 for (i = 0; i < size; i++) {
902 uint16_t appkey_index;
903 uint16_t *appkey_idx = NULL;
905 appkey_index = g_array_index(out_param,
908 appkey_idx = g_memdup(&appkey_index, sizeof(guint16));
909 g_ptr_array_add(*appkeys, (gpointer)appkey_idx);
914 BT_FREE_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
919 BT_EXPORT_API int bluetooth_mesh_model_get_all_appkeys(
920 bluetooth_mesh_model_configure_t *req)
923 bt_user_info_t *user_info;
925 BT_CHECK_PARAMETER(req, return);
927 user_info = _bt_get_user_data(BT_MESH);
928 retv_if(user_info->cb == NULL, BLUETOOTH_ERROR_INTERNAL);
931 BT_ALLOC_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
933 g_array_append_vals(in_param1, req, sizeof(bluetooth_mesh_model_configure_t));
935 BT_INFO("Mesh:Node Model Get AppKey List ");
936 result = _bt_send_request_async(BT_BLUEZ_SERVICE, BT_MESH_MODEL_GET_APPKEY_LIST,
937 in_param1, in_param2, in_param3, in_param4,
938 user_info->cb, user_info->user_data);
940 BT_FREE_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
944 BT_EXPORT_API int bluetooth_mesh_model_set_publication(
945 bluetooth_mesh_model_configure_t *req)
948 bt_user_info_t *user_info;
950 BT_CHECK_PARAMETER(req, return);
952 user_info = _bt_get_user_data(BT_MESH);
953 retv_if(user_info->cb == NULL, BLUETOOTH_ERROR_INTERNAL);
956 BT_ALLOC_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
958 g_array_append_vals(in_param1, req, sizeof(bluetooth_mesh_model_configure_t));
960 BT_INFO("Mesh: Model Set Publication");
961 result = _bt_send_request_async(BT_BLUEZ_SERVICE, BT_MESH_MODEL_SET_PUBLICATION,
962 in_param1, in_param2, in_param3, in_param4,
963 user_info->cb, user_info->user_data);
965 BT_FREE_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
969 BT_EXPORT_API int bluetooth_mesh_model_get_publication(
970 bluetooth_mesh_model_configure_t *req)
973 bt_user_info_t *user_info;
975 BT_CHECK_PARAMETER(req, return);
977 user_info = _bt_get_user_data(BT_MESH);
978 retv_if(user_info->cb == NULL, BLUETOOTH_ERROR_INTERNAL);
981 BT_ALLOC_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
983 g_array_append_vals(in_param1, req, sizeof(bluetooth_mesh_model_configure_t));
985 BT_INFO("Mesh:BTAPI: Model Get Publication");
986 result = _bt_send_request_async(BT_BLUEZ_SERVICE, BT_MESH_MODEL_GET_PUBLICATION,
987 in_param1, in_param2, in_param3, in_param4,
988 user_info->cb, user_info->user_data);
990 BT_FREE_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
994 BT_EXPORT_API int bluetooth_mesh_model_get_subscriptopn_list(
995 bluetooth_mesh_model_configure_t *req)
998 bt_user_info_t *user_info;
1000 BT_CHECK_PARAMETER(req, return);
1002 user_info = _bt_get_user_data(BT_MESH);
1003 retv_if(user_info->cb == NULL, BLUETOOTH_ERROR_INTERNAL);
1006 BT_ALLOC_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
1008 g_array_append_vals(in_param1, req, sizeof(bluetooth_mesh_model_configure_t));
1010 BT_INFO("Mesh:BTAPI: Model Get Subscription List ");
1011 result = _bt_send_request_async(BT_BLUEZ_SERVICE, BT_MESH_MODEL_GET_SUBSCRIPTION_LIST,
1012 in_param1, in_param2, in_param3, in_param4,
1013 user_info->cb, user_info->user_data);
1015 BT_FREE_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
1019 BT_EXPORT_API int bluetooth_mesh_network_remove_group(
1020 bluetooth_mesh_network_t *network,
1021 bluetooth_mesh_network_group_info_t *req)
1025 BT_CHECK_PARAMETER(network, return);
1026 BT_CHECK_PARAMETER(req, return);
1029 BT_ALLOC_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
1031 g_array_append_vals(in_param1, network, sizeof(bluetooth_mesh_network_t));
1032 g_array_append_vals(in_param2, req, sizeof(bluetooth_mesh_network_group_info_t));
1034 BT_INFO("Mesh: Remove Group Request");
1035 result = _bt_send_request(BT_BLUEZ_SERVICE, BT_MESH_NETWORK_REMOVE_GROUP,
1036 in_param1, in_param2, in_param3, in_param4, &out_param);
1038 BT_FREE_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
1043 BT_EXPORT_API int bluetooth_mesh_network_create_group(
1044 bluetooth_mesh_network_t *network, bool is_virtual,
1045 uint16_t grp_addr, bluetooth_mesh_network_group_info_t *info)
1049 BT_CHECK_PARAMETER(network, return);
1050 BT_CHECK_PARAMETER(info, return);
1053 BT_ALLOC_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
1055 g_array_append_vals(in_param1, network, sizeof(bluetooth_mesh_network_t));
1056 g_array_append_vals(in_param2, &is_virtual, sizeof(gboolean));
1057 g_array_append_vals(in_param3, &grp_addr, sizeof(guint16));
1059 BT_INFO("Mesh: Create Group Request");
1060 result = _bt_send_request(BT_BLUEZ_SERVICE, BT_MESH_NETWORK_CREATE_GROUP,
1061 in_param1, in_param2, in_param3, in_param4, &out_param);
1063 if (result == BLUETOOTH_ERROR_NONE) {
1064 *info = g_array_index(out_param,
1065 bluetooth_mesh_network_group_info_t, 0);
1067 BT_FREE_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
1072 BT_EXPORT_API int bluetooth_mesh_model_configure_group_sub(
1073 bluetooth_mesh_model_configure_t *req)
1076 bt_user_info_t *user_info;
1078 BT_CHECK_PARAMETER(req, return);
1080 user_info = _bt_get_user_data(BT_MESH);
1081 retv_if(user_info->cb == NULL, BLUETOOTH_ERROR_INTERNAL);
1084 BT_ALLOC_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
1086 g_array_append_vals(in_param1, req, sizeof(bluetooth_mesh_model_configure_t));
1088 BT_INFO("Mesh:Model Group Subscription Request");
1089 result = _bt_send_request_async(BT_BLUEZ_SERVICE, BT_MESH_MODEL_CONFIG_GROUP_SUB,
1090 in_param1, in_param2, in_param3, in_param4,
1091 user_info->cb, user_info->user_data);
1093 BT_FREE_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
1097 BT_EXPORT_API int bluetooth_mesh_model_configure_virtual_group_sub(
1098 bluetooth_mesh_model_configure_t *req)
1101 bt_user_info_t *user_info;
1103 BT_CHECK_PARAMETER(req, return);
1105 user_info = _bt_get_user_data(BT_MESH);
1106 retv_if(user_info->cb == NULL, BLUETOOTH_ERROR_INTERNAL);
1109 BT_ALLOC_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
1111 g_array_append_vals(in_param1, req, sizeof(bluetooth_mesh_model_configure_t));
1113 BT_INFO("Mesh: Model Virtual Group Subscription Request");
1114 result = _bt_send_request_async(BT_BLUEZ_SERVICE,
1115 BT_MESH_MODEL_CONFIG_VIRTUAL_GROUP_SUB,
1116 in_param1, in_param2, in_param3, in_param4,
1117 user_info->cb, user_info->user_data);
1119 BT_FREE_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);