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 ret != BLUETOOTH_ERROR_ALREADY_INITIALIZED) {
52 BT_ERR("Fail to init the mesh in bt-service");
56 ret = _bt_init_event_handler();
58 if (ret != BLUETOOTH_ERROR_NONE &&
59 ret != BLUETOOTH_ERROR_ALREADY_INITIALIZED) {
60 BT_ERR("Fail to init the event handler");
64 _bt_set_user_data(BT_MESH, (void *)cb, user_data);
66 /* Register All events */
67 ret = _bt_register_event(BT_MESH_EVENT, (void *)cb, user_data);
68 if (ret != BLUETOOTH_ERROR_NONE &&
69 ret != BLUETOOTH_ERROR_ALREADY_INITIALIZED) {
70 _bt_deinit_event_handler();
74 BT_INFO("Mesh: Event registsred");
75 return BLUETOOTH_ERROR_NONE;
78 BT_EXPORT_API int bluetooth_mesh_deinit(void)
82 _bt_unregister_event(BT_MESH_EVENT);
83 _bt_set_user_data(BT_MESH, NULL, NULL);
86 BT_ALLOC_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
88 ret = _bt_send_request(BT_BLUEZ_SERVICE, BT_MESH_DEINIT,
89 in_param1, in_param2, in_param3, in_param4, &out_param);
91 BT_FREE_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
93 if (ret != BLUETOOTH_ERROR_NONE) {
94 BT_ERR("Fail to init the mesh in bt-service");
98 return BLUETOOTH_ERROR_NONE;
101 BT_EXPORT_API int bluetooth_mesh_network_destroy(bluetooth_mesh_network_t *network)
105 BT_CHECK_PARAMETER(network, return);
108 BT_ALLOC_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
110 g_array_append_vals(in_param1, network, sizeof(bluetooth_mesh_network_t));
112 BT_INFO("Mesh: Network Destroy");
113 result = _bt_send_request(BT_BLUEZ_SERVICE, BT_MESH_NETWORK_DESTROY,
114 in_param1, in_param2, in_param3, in_param4, &out_param);
115 BT_FREE_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
120 BT_EXPORT_API int bluetooth_mesh_node_reset(bluetooth_mesh_node_info_t *node)
124 BT_CHECK_PARAMETER(node, return);
127 BT_ALLOC_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
129 g_array_append_vals(in_param1, node, sizeof(bluetooth_mesh_node_info_t));
131 BT_INFO("Mesh: Reset the Node");
132 result = _bt_send_request(BT_BLUEZ_SERVICE, BT_MESH_NODE_RESET,
133 in_param1, in_param2, in_param3, in_param4, &out_param);
134 BT_FREE_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
139 BT_EXPORT_API int bluetooth_mesh_network_create(
140 const char *net_name, bluetooth_mesh_node_t *node,
141 uint16_t total_models, bluetooth_mesh_model_t **models,
142 bluetooth_mesh_network_t *network)
145 char network_name[BLUETOOTH_MESH_NETWORK_NAME_STRING_MAX+1];
147 BT_CHECK_PARAMETER(net_name, return);
148 BT_CHECK_PARAMETER(node, return);
149 BT_CHECK_PARAMETER(models, return);
152 BT_ALLOC_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
154 g_array_append_vals(in_param1, node, sizeof(bluetooth_mesh_node_t));
156 g_strlcpy(network_name, net_name, sizeof(network_name));
157 g_array_append_vals(in_param2, network_name,
158 BLUETOOTH_MESH_NETWORK_NAME_STRING_MAX);
160 for (int i = 0; i < total_models; i++)
161 g_array_append_vals(in_param3, models[i],
162 sizeof(bluetooth_mesh_model_t));
164 result = _bt_send_request(BT_BLUEZ_SERVICE,
165 BT_MESH_NETWORK_CREATE,
166 in_param1, in_param2, in_param3,
167 in_param4, &out_param);
169 if (result == BLUETOOTH_ERROR_NONE) {
170 *network = g_array_index(out_param,
171 bluetooth_mesh_network_t, 0);
174 BT_FREE_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
179 BT_EXPORT_API int bluetooth_mesh_network_load(
181 bluetooth_mesh_network_t *network)
184 char token_string[BLUETOOTH_MESH_TOKEN_STRING_MAX + 1];
186 BT_CHECK_PARAMETER(token, return);
187 BT_CHECK_PARAMETER(network, return);
190 BT_ALLOC_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
192 g_strlcpy(token_string, token, sizeof(token_string));
193 g_array_append_vals(in_param1, token_string, BLUETOOTH_MESH_TOKEN_STRING_MAX);
195 result = _bt_send_request(BT_BLUEZ_SERVICE, BT_MESH_NETWORK_LOAD,
196 in_param1, in_param2, in_param3, in_param4, &out_param);
198 if (result == BLUETOOTH_ERROR_NONE) {
199 *network = g_array_index(out_param,
200 bluetooth_mesh_network_t, 0);
203 BT_FREE_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
208 BT_EXPORT_API int bluetooth_mesh_network_scan(
209 bluetooth_mesh_network_t *network,
210 bluetooth_mesh_scan_param_t *scan_param)
214 BT_CHECK_PARAMETER(network, return);
215 BT_CHECK_PARAMETER(scan_param, return);
218 BT_ALLOC_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
220 g_array_append_vals(in_param1, network, sizeof(bluetooth_mesh_network_t));
222 g_array_append_vals(in_param2, scan_param, sizeof(bluetooth_mesh_scan_param_t));
224 BT_INFO("Mesh:Start Scan, time [%u]", scan_param->scan_time);
225 result = _bt_send_request(BT_BLUEZ_SERVICE, BT_MESH_NETWORK_SCAN,
226 in_param1, in_param2, in_param3, in_param4, &out_param);
227 BT_FREE_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
232 BT_EXPORT_API int bluetooth_mesh_network_cancel_scan(
233 bluetooth_mesh_network_t *network)
237 BT_CHECK_PARAMETER(network, return);
240 BT_ALLOC_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
242 g_array_append_vals(in_param1, network, sizeof(bluetooth_mesh_network_t));
244 BT_INFO("Mesh: Cancel Scan");
245 result = _bt_send_request(BT_BLUEZ_SERVICE, BT_MESH_NETWORK_CANCEL_SCAN,
246 in_param1, in_param2, in_param3, in_param4, &out_param);
247 BT_FREE_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
252 BT_EXPORT_API int bluetooth_mesh_network_set_capabilities(
253 bluetooth_mesh_network_t *network,
254 bluetooth_mesh_provisioner_caps_t *caps)
258 BT_CHECK_PARAMETER(network, return);
259 BT_CHECK_PARAMETER(caps, return);
262 BT_ALLOC_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
264 g_array_append_vals(in_param1, network, sizeof(bluetooth_mesh_network_t));
266 g_array_append_vals(in_param2, caps, sizeof(bluetooth_mesh_provisioner_caps_t));
268 BT_INFO("Mesh: Set Provisioner capabilities");
269 result = _bt_send_request(BT_BLUEZ_SERVICE, BT_MESH_NETWORK_SET_CAPABILITIES,
270 in_param1, in_param2, in_param3, in_param4, &out_param);
271 BT_FREE_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
276 BT_EXPORT_API int bluetooth_mesh_network_provision_device(
277 bluetooth_mesh_provisioning_request_t *req)
280 bt_user_info_t *user_info;
282 BT_CHECK_PARAMETER(req, return);
284 user_info = _bt_get_user_data(BT_MESH);
285 retv_if(user_info->cb == NULL, BLUETOOTH_ERROR_INTERNAL);
288 BT_ALLOC_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
290 g_array_append_vals(in_param1, req,
291 sizeof(bluetooth_mesh_provisioning_request_t));
293 BT_INFO("Mesh: Set Provision Device");
294 result = _bt_send_request_async(BT_BLUEZ_SERVICE,
295 BT_MESH_NETWORK_PROVISION_DEVICE,
296 in_param1, in_param2, in_param3, in_param4,
297 user_info->cb, user_info->user_data);
299 BT_FREE_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
304 BT_EXPORT_API int bluetooth_mesh_authentication_reply(int auth_type,
305 const char *auth_val, gboolean reply)
309 char auth_string[BLUETOOTH_MESH_AUTH_VALUE_LENGTH_MAX];
311 BT_CHECK_PARAMETER(auth_val, return);
314 BT_ALLOC_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
316 g_strlcpy(auth_string, auth_val,
317 sizeof(auth_string));
318 g_array_append_vals(in_param1,
319 &auth_type, sizeof(int));
320 g_array_append_vals(in_param2, auth_string,
321 BLUETOOTH_MESH_AUTH_VALUE_LENGTH_MAX);
322 g_array_append_vals(in_param3, &reply, sizeof(gboolean));
324 BT_INFO("Mesh: Set Provisioner Authentication Reply");
325 result = _bt_send_request(BT_BLUEZ_SERVICE, BT_MESH_AUTHENTICATION_REPLY,
326 in_param1, in_param2, in_param3, in_param4, &out_param);
328 BT_FREE_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
333 BT_EXPORT_API int bluetooth_mesh_network_set_name(
334 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));
345 BT_INFO("Mesh:Set Network Name");
346 result = _bt_send_request(BT_BLUEZ_SERVICE, BT_MESH_NETWORK_SET_NAME,
347 in_param1, in_param2, in_param3, in_param4, &out_param);
348 BT_FREE_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
353 BT_EXPORT_API int bluetooth_mesh_network_add_netkey(
354 bluetooth_mesh_network_t *network,
355 uint16_t *netkey_idx)
359 BT_CHECK_PARAMETER(network, return);
360 BT_CHECK_PARAMETER(netkey_idx, return);
363 BT_ALLOC_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
365 g_array_append_vals(in_param1, network, sizeof(bluetooth_mesh_network_t));
367 BT_INFO("Mesh:Set Create Subnetwork key");
368 result = _bt_send_request(BT_BLUEZ_SERVICE, BT_MESH_NETWORK_ADD_NETKEY,
369 in_param1, in_param2, in_param3, in_param4, &out_param);
370 if (result == BLUETOOTH_ERROR_NONE)
371 *netkey_idx = g_array_index(out_param, guint16, 0);
372 BT_FREE_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
377 BT_EXPORT_API int bluetooth_mesh_network_delete_netkey(
378 bluetooth_mesh_network_t *network,
383 BT_CHECK_PARAMETER(network, return);
386 BT_ALLOC_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
388 g_array_append_vals(in_param1, network, sizeof(bluetooth_mesh_network_t));
389 g_array_append_vals(in_param2, &netkey_idx, sizeof(guint16));
391 BT_INFO("Mesh: Delete Subnetwork key");
392 result = _bt_send_request(BT_BLUEZ_SERVICE, BT_MESH_NETWORK_DELETE_NETKEY,
393 in_param1, in_param2, in_param3, in_param4, &out_param);
394 BT_FREE_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
399 BT_EXPORT_API int bluetooth_mesh_network_update_netkey(
400 bluetooth_mesh_network_t *network,
405 BT_CHECK_PARAMETER(network, return);
408 BT_ALLOC_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
410 g_array_append_vals(in_param1, network, sizeof(bluetooth_mesh_network_t));
411 g_array_append_vals(in_param2, &netkey_idx, sizeof(guint16));
413 BT_INFO("Mesh: Update Subnetwork key");
414 result = _bt_send_request(BT_BLUEZ_SERVICE, BT_MESH_NETWORK_UPDATE_NETKEY,
415 in_param1, in_param2, in_param3, in_param4, &out_param);
416 BT_FREE_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
421 BT_EXPORT_API int bluetooth_mesh_network_add_appkey(
422 bluetooth_mesh_network_t *network,
423 uint16_t netkey_index,
424 uint16_t *appkey_index)
428 BT_CHECK_PARAMETER(network, return);
429 BT_CHECK_PARAMETER(appkey_index, return);
432 BT_ALLOC_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
434 g_array_append_vals(in_param1, network, sizeof(bluetooth_mesh_network_t));
435 g_array_append_vals(in_param2, &netkey_index, sizeof(guint16));
437 BT_INFO("Mesh: Create AppKey");
438 result = _bt_send_request(BT_BLUEZ_SERVICE, BT_MESH_NETWORK_ADD_APPKEY,
439 in_param1, in_param2, in_param3, in_param4, &out_param);
441 if (result == BLUETOOTH_ERROR_NONE)
442 *appkey_index = g_array_index(out_param, guint16, 0);
443 BT_FREE_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
448 BT_EXPORT_API int bluetooth_mesh_network_update_appkey(
449 bluetooth_mesh_network_t *network,
450 uint16_t netkey_index, uint16_t appkey_index)
454 BT_CHECK_PARAMETER(network, return);
457 BT_ALLOC_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
459 g_array_append_vals(in_param1, network, sizeof(bluetooth_mesh_network_t));
460 g_array_append_vals(in_param2, &netkey_index, sizeof(guint16));
461 g_array_append_vals(in_param3, &appkey_index, sizeof(guint16));
463 BT_INFO("Mesh:BTAPI: Update AppKey");
464 result = _bt_send_request(BT_BLUEZ_SERVICE, BT_MESH_NETWORK_UPDATE_APPKEY,
465 in_param1, in_param2, in_param3, in_param4, &out_param);
467 BT_FREE_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
472 BT_EXPORT_API int bluetooth_mesh_network_delete_appkey(bluetooth_mesh_network_t *network,
473 uint16_t netkey_index, uint16_t appkey_index)
477 BT_CHECK_PARAMETER(network, return);
480 BT_ALLOC_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
482 g_array_append_vals(in_param1, network, sizeof(bluetooth_mesh_network_t));
483 g_array_append_vals(in_param2, &netkey_index, sizeof(guint16));
484 g_array_append_vals(in_param3, &appkey_index, sizeof(guint16));
486 BT_INFO("Mesh: Delete AppKey");
487 result = _bt_send_request(BT_BLUEZ_SERVICE, BT_MESH_NETWORK_DELETE_APPKEY,
488 in_param1, in_param2, in_param3, in_param4, &out_param);
490 BT_FREE_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
495 BT_EXPORT_API int bluetooth_mesh_network_get_all_nodes(
496 bluetooth_mesh_network_t *network,
499 int result = BLUETOOTH_ERROR_NONE;
502 bluetooth_mesh_node_info_t *info;
504 BT_CHECK_PARAMETER(network, return);
505 BT_CHECK_PARAMETER(nodes, return);
508 BT_ALLOC_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
510 g_array_append_vals(in_param1, network, sizeof(bluetooth_mesh_network_t));
512 result = _bt_send_request(BT_BLUEZ_SERVICE, BT_MESH_NETWORK_GET_NODES,
513 in_param1, in_param2, in_param3, in_param4, &out_param);
515 if (result == BLUETOOTH_ERROR_NONE) {
516 if (out_param == NULL) {
517 BT_ERR("Mesh: out_param is NULL");
518 result = BLUETOOTH_ERROR_INTERNAL;
520 size = (out_param->len) / sizeof(bluetooth_mesh_node_info_t);
522 for (i = 0; i < size; i++) {
523 bluetooth_mesh_node_info_t *data;
525 info = &g_array_index(out_param,
526 bluetooth_mesh_node_info_t, i);
528 data = g_memdup(info, sizeof(bluetooth_mesh_node_info_t));
529 g_ptr_array_add(*nodes, (gpointer)data);
534 BT_FREE_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
539 BT_EXPORT_API int bluetooth_mesh_element_get_all_models(
540 bluetooth_mesh_network_t *network,
541 uint16_t node_addr, int elem_idx,
544 int result = BLUETOOTH_ERROR_NONE;
548 BT_CHECK_PARAMETER(network, return);
549 BT_CHECK_PARAMETER(models, return);
552 BT_ALLOC_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
554 g_array_append_vals(in_param1, network, sizeof(bluetooth_mesh_network_t));
555 g_array_append_vals(in_param2, &node_addr, sizeof(guint16));
556 g_array_append_vals(in_param3, &elem_idx, sizeof(int));
558 result = _bt_send_request(BT_BLUEZ_SERVICE, BT_MESH_ELEMENT_GET_MODELS,
559 in_param1, in_param2, in_param3, in_param4, &out_param);
561 if (result == BLUETOOTH_ERROR_NONE) {
562 if (out_param == NULL) {
563 BT_ERR("Mesh: out_param is NULL");
564 result = BLUETOOTH_ERROR_INTERNAL;
566 size = (out_param->len) / sizeof(guint32);
567 BT_INFO("Mesh: Total Models found in Element [%d]", size);
569 for (i = 0; i < size; i++) {
571 uint32_t *model_ptr = NULL;
573 model_obj = g_array_index(out_param,
576 model_ptr = g_memdup(&model_obj, sizeof(guint32));
577 g_ptr_array_add(*models, (gpointer)model_ptr);
582 BT_FREE_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
587 BT_EXPORT_API int bluetooth_mesh_node_browse_vendor_features(
588 bluetooth_mesh_node_features_t *req)
591 bt_user_info_t *user_info;
593 BT_CHECK_PARAMETER(req, return);
595 user_info = _bt_get_user_data(BT_MESH);
596 retv_if(user_info->cb == NULL, BLUETOOTH_ERROR_INTERNAL);
599 BT_ALLOC_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
601 g_array_append_vals(in_param1, req, sizeof(bluetooth_mesh_node_features_t));
603 BT_INFO("Mesh: Browse Vendor features of Node");
604 result = _bt_send_request_async(BT_BLUEZ_SERVICE, BT_MESH_NODE_GET_VENDOR_FEATURES,
605 in_param1, in_param2, in_param3, in_param4,
606 user_info->cb, user_info->user_data);
608 BT_FREE_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
613 BT_EXPORT_API int bluetooth_mesh_browse_remote_node(
614 bluetooth_mesh_node_discover_t *req)
617 bt_user_info_t *user_info;
619 BT_CHECK_PARAMETER(req, return);
621 user_info = _bt_get_user_data(BT_MESH);
622 retv_if(user_info->cb == NULL, BLUETOOTH_ERROR_INTERNAL);
625 BT_ALLOC_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
627 g_array_append_vals(in_param1, req, sizeof(bluetooth_mesh_node_discover_t));
629 BT_INFO("Mesh: Browse remote Node");
630 result = _bt_send_request_async(BT_BLUEZ_SERVICE, BT_MESH_NODE_BROWSE,
631 in_param1, in_param2, in_param3, in_param4,
632 user_info->cb, user_info->user_data);
634 BT_FREE_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
639 BT_EXPORT_API int bluetooth_mesh_node_ttl_execute(
640 bluetooth_mesh_node_ttl_info_t *req)
643 bt_user_info_t *user_info;
645 BT_CHECK_PARAMETER(req, return);
647 user_info = _bt_get_user_data(BT_MESH);
648 retv_if(user_info->cb == NULL, BLUETOOTH_ERROR_INTERNAL);
651 BT_ALLOC_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
653 g_array_append_vals(in_param1, req, sizeof(bluetooth_mesh_node_ttl_info_t));
655 BT_INFO("Mesh: Node TTL Execute");
656 result = _bt_send_request_async(BT_BLUEZ_SERVICE, BT_MESH_NODE_TTL_EXECUTE,
657 in_param1, in_param2, in_param3, in_param4,
658 user_info->cb, user_info->user_data);
660 BT_FREE_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
665 BT_EXPORT_API int bluetooth_mesh_model_configure_appkey(
666 bluetooth_mesh_model_configure_t *req)
669 bt_user_info_t *user_info;
671 BT_CHECK_PARAMETER(req, return);
673 user_info = _bt_get_user_data(BT_MESH);
674 retv_if(user_info->cb == NULL, BLUETOOTH_ERROR_INTERNAL);
677 BT_ALLOC_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
679 g_array_append_vals(in_param1, req, sizeof(bluetooth_mesh_model_configure_t));
681 BT_INFO("Mesh: Node Model Configure AppKey");
682 result = _bt_send_request_async(BT_BLUEZ_SERVICE, BT_MESH_MODEL_CONFIGURE_APPKEY,
683 in_param1, in_param2, in_param3, in_param4,
684 user_info->cb, user_info->user_data);
686 BT_FREE_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
691 BT_EXPORT_API int bluetooth_mesh_model_send_msg(
692 bluetooth_mesh_model_msg_t *req)
695 bt_user_info_t *user_info;
697 BT_CHECK_PARAMETER(req, return);
699 user_info = _bt_get_user_data(BT_MESH);
700 retv_if(user_info->cb == NULL, BLUETOOTH_ERROR_INTERNAL);
703 BT_ALLOC_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
705 g_array_append_vals(in_param1, req, sizeof(bluetooth_mesh_model_msg_t));
707 BT_INFO("Mesh: Node Model Send Msg");
708 result = _bt_send_request_async(BT_BLUEZ_SERVICE, BT_MESH_MODEL_EXECUTE_MSG,
709 in_param1, in_param2, in_param3, in_param4,
710 user_info->cb, user_info->user_data);
712 BT_FREE_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
717 BT_EXPORT_API int bluetooth_mesh_node_configure_key(
718 bluetooth_mesh_key_configure_t *req)
721 bt_user_info_t *user_info;
723 BT_CHECK_PARAMETER(req, return);
725 user_info = _bt_get_user_data(BT_MESH);
726 retv_if(user_info->cb == NULL, BLUETOOTH_ERROR_INTERNAL);
729 BT_ALLOC_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
731 g_array_append_vals(in_param1, req, sizeof(bluetooth_mesh_key_configure_t));
733 BT_INFO("Mesh:BTAPI: Node Key Configure");
734 result = _bt_send_request_async(BT_BLUEZ_SERVICE, BT_MESH_NODE_CONFIGURE_KEY,
735 in_param1, in_param2, in_param3, in_param4,
736 user_info->cb, user_info->user_data);
738 BT_FREE_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
743 BT_EXPORT_API int bluetooth_mesh_network_get_all_groups(
744 bluetooth_mesh_network_t *network,
747 int result = BLUETOOTH_ERROR_NONE;
748 bluetooth_mesh_network_group_info_t *info;
752 BT_CHECK_PARAMETER(network, return);
753 BT_CHECK_PARAMETER(groups, return);
756 BT_ALLOC_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
758 g_array_append_vals(in_param1, network, sizeof(bluetooth_mesh_network_t));
760 result = _bt_send_request(BT_BLUEZ_SERVICE, BT_MESH_NETWORK_GET_GROUPS,
761 in_param1, in_param2, in_param3, in_param4, &out_param);
763 if (result == BLUETOOTH_ERROR_NONE) {
764 if (out_param == NULL) {
765 BT_ERR("Mesh: out_param is NULL");
766 result = BLUETOOTH_ERROR_INTERNAL;
768 size = (out_param->len) / sizeof(bluetooth_mesh_network_group_info_t);
771 BT_INFO("Mesh: No Groups created for the network");
773 BT_INFO("Mesh: Total groups [%d]", size);
774 for (i = 0; i < size; i++) {
775 bluetooth_mesh_network_group_info_t *grp_info = NULL;
777 info = &g_array_index(out_param,
778 bluetooth_mesh_network_group_info_t, i);
779 BT_INFO("Mesh: Group addr [0x%2.2x]", info->group_addr);
780 BT_INFO("Mesh: Group is Virtual [%s]", info->is_virtual ? "YES" : "NO");
781 BT_INFO("Mesh: Group net UUID[%s]", info->net_uuid);
782 if (info->is_virtual)
783 BT_INFO("Mesh: Virual Label UUID [%s]", info->label_uuid);
784 grp_info = g_memdup(info,
785 sizeof(bluetooth_mesh_network_group_info_t));
786 g_ptr_array_add(*groups, (gpointer)grp_info);
791 BT_FREE_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
796 BT_EXPORT_API int bluetooth_mesh_network_get_all_netkey(
797 bluetooth_mesh_network_t *network,
800 int result = BLUETOOTH_ERROR_NONE;
804 BT_CHECK_PARAMETER(network, return);
805 BT_CHECK_PARAMETER(netkeys, return);
808 BT_ALLOC_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
810 g_array_append_vals(in_param1, network, sizeof(bluetooth_mesh_network_t));
812 result = _bt_send_request(BT_BLUEZ_SERVICE, BT_MESH_NETWORK_GET_NETKEYS,
813 in_param1, in_param2, in_param3, in_param4, &out_param);
815 if (result == BLUETOOTH_ERROR_NONE) {
816 if (out_param == NULL) {
817 BT_ERR("Mesh: out_param is NULL");
818 result = BLUETOOTH_ERROR_INTERNAL;
820 size = (out_param->len) / sizeof(guint16);
823 BT_ERR("Mesh: No netkeys created for the network");
824 result = BLUETOOTH_ERROR_NOT_FOUND;
827 for (i = 0; i < size; i++) {
828 uint16_t netkey_index;
829 uint16_t *netkey_idx = NULL;
831 netkey_index = g_array_index(out_param,
834 netkey_idx = g_memdup(&netkey_index, sizeof(guint16));
835 g_ptr_array_add(*netkeys, (gpointer)netkey_idx);
840 BT_FREE_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
845 BT_EXPORT_API int bluetooth_mesh_netkey_get_all_appkey(
846 bluetooth_mesh_network_t *network,
850 int result = BLUETOOTH_ERROR_NONE;
854 BT_CHECK_PARAMETER(network, return);
855 BT_CHECK_PARAMETER(appkeys, return);
858 BT_ALLOC_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
860 g_array_append_vals(in_param1, network, sizeof(bluetooth_mesh_network_t));
861 g_array_append_vals(in_param2, &netkey_idx, sizeof(guint16));
863 result = _bt_send_request(BT_BLUEZ_SERVICE, BT_MESH_NETWORK_GET_APPKEYS,
864 in_param1, in_param2, in_param3, in_param4, &out_param);
866 if (result == BLUETOOTH_ERROR_NONE) {
867 if (out_param == NULL) {
868 BT_ERR("Mesh: out_param is NULL");
869 result = BLUETOOTH_ERROR_INTERNAL;
871 size = (out_param->len) / sizeof(guint16);
874 BT_ERR("Mesh: No Appkeys created for the NetKey in the network");
876 for (i = 0; i < size; i++) {
877 uint16_t appkey_index;
878 uint16_t *appkey_idx = NULL;
880 appkey_index = g_array_index(out_param,
883 appkey_idx = g_memdup(&appkey_index, sizeof(guint16));
884 g_ptr_array_add(*appkeys, (gpointer)appkey_idx);
889 BT_FREE_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
894 BT_EXPORT_API int bluetooth_mesh_node_get_all_netkeys(
895 bluetooth_mesh_node_discover_t *node,
898 int result = BLUETOOTH_ERROR_NONE;
902 BT_CHECK_PARAMETER(node, return);
903 BT_CHECK_PARAMETER(netkeys, return);
906 BT_ALLOC_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
908 g_array_append_vals(in_param1, node, sizeof(bluetooth_mesh_node_discover_t));
910 result = _bt_send_request(BT_BLUEZ_SERVICE, BT_MESH_NODE_GET_NETKEYS,
911 in_param1, in_param2, in_param3, in_param4, &out_param);
913 if (result == BLUETOOTH_ERROR_NONE) {
914 if (out_param == NULL) {
915 BT_ERR("Mesh: out_param is NULL");
916 result = BLUETOOTH_ERROR_INTERNAL;
918 size = (out_param->len) / sizeof(guint16);
920 for (i = 0; i < size; i++) {
921 uint16_t netkey_index;
922 uint16_t *netkey_idx = NULL;
924 netkey_index = g_array_index(out_param,
927 netkey_idx = g_memdup(&netkey_index, sizeof(guint16));
928 g_ptr_array_add(*netkeys, (gpointer)netkey_idx);
933 BT_FREE_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
938 BT_EXPORT_API int bluetooth_mesh_node_get_all_appkeys(
939 bluetooth_mesh_node_discover_t *req, GPtrArray **appkeys)
941 int result = BLUETOOTH_ERROR_NONE;
945 BT_CHECK_PARAMETER(req, return);
946 BT_CHECK_PARAMETER(appkeys, return);
949 BT_ALLOC_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
951 g_array_append_vals(in_param1, req, sizeof(bluetooth_mesh_node_discover_t));
953 result = _bt_send_request(BT_BLUEZ_SERVICE, BT_MESH_NODE_GET_APPKEYS,
954 in_param1, in_param2, in_param3, in_param4, &out_param);
956 if (result == BLUETOOTH_ERROR_NONE) {
957 if (out_param == NULL) {
958 BT_ERR("Mesh: out_param is NULL");
959 result = BLUETOOTH_ERROR_INTERNAL;
961 size = (out_param->len) / sizeof(guint16);
963 for (i = 0; i < size; i++) {
964 uint16_t appkey_index;
965 uint16_t *appkey_idx = NULL;
967 appkey_index = g_array_index(out_param,
970 appkey_idx = g_memdup(&appkey_index, sizeof(guint16));
971 g_ptr_array_add(*appkeys, (gpointer)appkey_idx);
976 BT_FREE_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
981 BT_EXPORT_API int bluetooth_mesh_model_get_all_appkeys(
982 bluetooth_mesh_model_configure_t *req)
985 bt_user_info_t *user_info;
987 BT_CHECK_PARAMETER(req, return);
989 user_info = _bt_get_user_data(BT_MESH);
990 retv_if(user_info->cb == NULL, BLUETOOTH_ERROR_INTERNAL);
993 BT_ALLOC_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
995 g_array_append_vals(in_param1, req, sizeof(bluetooth_mesh_model_configure_t));
997 BT_INFO("Mesh:Node Model Get AppKey List ");
998 result = _bt_send_request_async(BT_BLUEZ_SERVICE, BT_MESH_MODEL_GET_APPKEY_LIST,
999 in_param1, in_param2, in_param3, in_param4,
1000 user_info->cb, user_info->user_data);
1002 BT_FREE_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
1006 BT_EXPORT_API int bluetooth_mesh_model_set_publication(
1007 bluetooth_mesh_model_configure_t *req)
1010 bt_user_info_t *user_info;
1012 BT_CHECK_PARAMETER(req, return);
1014 user_info = _bt_get_user_data(BT_MESH);
1015 retv_if(user_info->cb == NULL, BLUETOOTH_ERROR_INTERNAL);
1018 BT_ALLOC_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
1020 g_array_append_vals(in_param1, req, sizeof(bluetooth_mesh_model_configure_t));
1022 BT_INFO("Mesh: Model Set Publication");
1023 result = _bt_send_request_async(BT_BLUEZ_SERVICE, BT_MESH_MODEL_SET_PUBLICATION,
1024 in_param1, in_param2, in_param3, in_param4,
1025 user_info->cb, user_info->user_data);
1027 BT_FREE_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
1031 BT_EXPORT_API int bluetooth_mesh_model_get_publication(
1032 bluetooth_mesh_model_configure_t *req)
1035 bt_user_info_t *user_info;
1037 BT_CHECK_PARAMETER(req, return);
1039 user_info = _bt_get_user_data(BT_MESH);
1040 retv_if(user_info->cb == NULL, BLUETOOTH_ERROR_INTERNAL);
1043 BT_ALLOC_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
1045 g_array_append_vals(in_param1, req, sizeof(bluetooth_mesh_model_configure_t));
1047 BT_INFO("Mesh:BTAPI: Model Get Publication");
1048 result = _bt_send_request_async(BT_BLUEZ_SERVICE, BT_MESH_MODEL_GET_PUBLICATION,
1049 in_param1, in_param2, in_param3, in_param4,
1050 user_info->cb, user_info->user_data);
1052 BT_FREE_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
1056 BT_EXPORT_API int bluetooth_mesh_model_get_subscriptopn_list(
1057 bluetooth_mesh_model_configure_t *req)
1060 bt_user_info_t *user_info;
1062 BT_CHECK_PARAMETER(req, return);
1064 user_info = _bt_get_user_data(BT_MESH);
1065 retv_if(user_info->cb == NULL, BLUETOOTH_ERROR_INTERNAL);
1068 BT_ALLOC_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
1070 g_array_append_vals(in_param1, req, sizeof(bluetooth_mesh_model_configure_t));
1072 BT_INFO("Mesh:BTAPI: Model Get Subscription List ");
1073 result = _bt_send_request_async(BT_BLUEZ_SERVICE, BT_MESH_MODEL_GET_SUBSCRIPTION_LIST,
1074 in_param1, in_param2, in_param3, in_param4,
1075 user_info->cb, user_info->user_data);
1077 BT_FREE_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
1081 BT_EXPORT_API int bluetooth_mesh_network_remove_group(
1082 bluetooth_mesh_network_t *network,
1083 bluetooth_mesh_network_group_info_t *req)
1087 BT_CHECK_PARAMETER(network, return);
1088 BT_CHECK_PARAMETER(req, return);
1091 BT_ALLOC_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
1093 g_array_append_vals(in_param1, network, sizeof(bluetooth_mesh_network_t));
1094 g_array_append_vals(in_param2, req, sizeof(bluetooth_mesh_network_group_info_t));
1096 BT_INFO("Mesh: Remove Group Request");
1097 result = _bt_send_request(BT_BLUEZ_SERVICE, BT_MESH_NETWORK_REMOVE_GROUP,
1098 in_param1, in_param2, in_param3, in_param4, &out_param);
1100 BT_FREE_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
1105 BT_EXPORT_API int bluetooth_mesh_network_create_group(
1106 bluetooth_mesh_network_t *network, bool is_virtual,
1107 uint16_t grp_addr, bluetooth_mesh_network_group_info_t *info)
1111 BT_CHECK_PARAMETER(network, return);
1112 BT_CHECK_PARAMETER(info, return);
1115 BT_ALLOC_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
1117 g_array_append_vals(in_param1, network, sizeof(bluetooth_mesh_network_t));
1118 g_array_append_vals(in_param2, &is_virtual, sizeof(gboolean));
1119 g_array_append_vals(in_param3, &grp_addr, sizeof(guint16));
1121 BT_INFO("Mesh: Create Group Request");
1122 result = _bt_send_request(BT_BLUEZ_SERVICE, BT_MESH_NETWORK_CREATE_GROUP,
1123 in_param1, in_param2, in_param3, in_param4, &out_param);
1125 if (result == BLUETOOTH_ERROR_NONE) {
1126 *info = g_array_index(out_param,
1127 bluetooth_mesh_network_group_info_t, 0);
1129 BT_FREE_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
1134 BT_EXPORT_API int bluetooth_mesh_model_configure_group_sub(
1135 bluetooth_mesh_model_configure_t *req)
1138 bt_user_info_t *user_info;
1140 BT_CHECK_PARAMETER(req, return);
1142 user_info = _bt_get_user_data(BT_MESH);
1143 retv_if(user_info->cb == NULL, BLUETOOTH_ERROR_INTERNAL);
1146 BT_ALLOC_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
1148 g_array_append_vals(in_param1, req, sizeof(bluetooth_mesh_model_configure_t));
1150 BT_INFO("Mesh:Model Group Subscription Request");
1151 result = _bt_send_request_async(BT_BLUEZ_SERVICE, BT_MESH_MODEL_CONFIG_GROUP_SUB,
1152 in_param1, in_param2, in_param3, in_param4,
1153 user_info->cb, user_info->user_data);
1155 BT_FREE_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
1159 BT_EXPORT_API int bluetooth_mesh_model_configure_virtual_group_sub(
1160 bluetooth_mesh_model_configure_t *req)
1163 bt_user_info_t *user_info;
1165 BT_CHECK_PARAMETER(req, return);
1167 user_info = _bt_get_user_data(BT_MESH);
1168 retv_if(user_info->cb == NULL, BLUETOOTH_ERROR_INTERNAL);
1171 BT_ALLOC_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
1173 g_array_append_vals(in_param1, req, sizeof(bluetooth_mesh_model_configure_t));
1175 BT_INFO("Mesh: Model Virtual Group Subscription Request");
1176 result = _bt_send_request_async(BT_BLUEZ_SERVICE,
1177 BT_MESH_MODEL_CONFIG_VIRTUAL_GROUP_SUB,
1178 in_param1, in_param2, in_param3, in_param4,
1179 user_info->cb, user_info->user_data);
1181 BT_FREE_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);