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_destroy(bluetooth_mesh_network_t *network)
104 BT_CHECK_PARAMETER(network, return);
107 BT_ALLOC_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
109 g_array_append_vals(in_param1, network, sizeof(bluetooth_mesh_network_t));
111 BT_INFO("Mesh: Network Destroy");
112 result = _bt_send_request(BT_BLUEZ_SERVICE, BT_MESH_NETWORK_DESTROY,
113 in_param1, in_param2, in_param3, in_param4, &out_param);
114 BT_FREE_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
119 BT_EXPORT_API int bluetooth_mesh_node_reset(bluetooth_mesh_node_info_t *node)
123 BT_CHECK_PARAMETER(node, return);
126 BT_ALLOC_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
128 g_array_append_vals(in_param1, node, sizeof(bluetooth_mesh_node_info_t));
130 BT_INFO("Mesh: Reset the Node");
131 result = _bt_send_request(BT_BLUEZ_SERVICE, BT_MESH_NODE_RESET,
132 in_param1, in_param2, in_param3, in_param4, &out_param);
133 BT_FREE_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
138 BT_EXPORT_API int bluetooth_mesh_network_create(
139 const char *net_name, bluetooth_mesh_node_t *node,
140 uint16_t total_models, bluetooth_mesh_model_t **models,
141 bluetooth_mesh_network_t *network)
144 char network_name[BLUETOOTH_MESH_NETWORK_NAME_STRING_MAX+1];
146 BT_CHECK_PARAMETER(net_name, return);
147 BT_CHECK_PARAMETER(node, return);
148 BT_CHECK_PARAMETER(models, return);
151 BT_ALLOC_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
153 g_array_append_vals(in_param1, node, sizeof(bluetooth_mesh_node_t));
155 g_strlcpy(network_name, net_name, sizeof(network_name));
156 g_array_append_vals(in_param2, network_name,
157 BLUETOOTH_MESH_NETWORK_NAME_STRING_MAX);
159 for (int i = 0; i < total_models; i++)
160 g_array_append_vals(in_param3, models[i],
161 sizeof(bluetooth_mesh_model_t));
163 result = _bt_send_request(BT_BLUEZ_SERVICE,
164 BT_MESH_NETWORK_CREATE,
165 in_param1, in_param2, in_param3,
166 in_param4, &out_param);
168 if (result == BLUETOOTH_ERROR_NONE) {
169 *network = g_array_index(out_param,
170 bluetooth_mesh_network_t, 0);
173 BT_FREE_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
178 BT_EXPORT_API int bluetooth_mesh_network_load(
180 bluetooth_mesh_network_t *network)
183 char token_string[BLUETOOTH_MESH_TOKEN_STRING_MAX + 1];
185 BT_CHECK_PARAMETER(token, return);
186 BT_CHECK_PARAMETER(network, return);
189 BT_ALLOC_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
191 g_strlcpy(token_string, token, sizeof(token_string));
192 g_array_append_vals(in_param1, token_string, BLUETOOTH_MESH_TOKEN_STRING_MAX);
194 result = _bt_send_request(BT_BLUEZ_SERVICE, BT_MESH_NETWORK_LOAD,
195 in_param1, in_param2, in_param3, in_param4, &out_param);
197 if (result == BLUETOOTH_ERROR_NONE) {
198 *network = g_array_index(out_param,
199 bluetooth_mesh_network_t, 0);
202 BT_FREE_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
207 BT_EXPORT_API int bluetooth_mesh_network_scan(
208 bluetooth_mesh_network_t *network,
209 bluetooth_mesh_scan_param_t *scan_param)
213 BT_CHECK_PARAMETER(network, return);
214 BT_CHECK_PARAMETER(scan_param, return);
217 BT_ALLOC_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
219 g_array_append_vals(in_param1, network, sizeof(bluetooth_mesh_network_t));
221 g_array_append_vals(in_param2, scan_param, sizeof(bluetooth_mesh_scan_param_t));
223 BT_INFO("Mesh:Start Scan, time [%u]", scan_param->scan_time);
224 result = _bt_send_request(BT_BLUEZ_SERVICE, BT_MESH_NETWORK_SCAN,
225 in_param1, in_param2, in_param3, in_param4, &out_param);
226 BT_FREE_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
231 BT_EXPORT_API int bluetooth_mesh_network_cancel_scan(
232 bluetooth_mesh_network_t *network)
236 BT_CHECK_PARAMETER(network, return);
239 BT_ALLOC_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
241 g_array_append_vals(in_param1, network, sizeof(bluetooth_mesh_network_t));
243 BT_INFO("Mesh: Cancel Scan");
244 result = _bt_send_request(BT_BLUEZ_SERVICE, BT_MESH_NETWORK_CANCEL_SCAN,
245 in_param1, in_param2, in_param3, in_param4, &out_param);
246 BT_FREE_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
251 BT_EXPORT_API int bluetooth_mesh_network_set_capabilities(
252 bluetooth_mesh_network_t *network,
253 bluetooth_mesh_provisioner_caps_t *caps)
257 BT_CHECK_PARAMETER(network, return);
258 BT_CHECK_PARAMETER(caps, return);
261 BT_ALLOC_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
263 g_array_append_vals(in_param1, network, sizeof(bluetooth_mesh_network_t));
265 g_array_append_vals(in_param2, caps, sizeof(bluetooth_mesh_provisioner_caps_t));
267 BT_INFO("Mesh: Set Provisioner capabilities");
268 result = _bt_send_request(BT_BLUEZ_SERVICE, BT_MESH_NETWORK_SET_CAPABILITIES,
269 in_param1, in_param2, in_param3, in_param4, &out_param);
270 BT_FREE_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
275 BT_EXPORT_API int bluetooth_mesh_network_provision_device(
276 bluetooth_mesh_provisioning_request_t *req)
279 bt_user_info_t *user_info;
281 BT_CHECK_PARAMETER(req, return);
283 user_info = _bt_get_user_data(BT_MESH);
284 retv_if(user_info->cb == NULL, BLUETOOTH_ERROR_INTERNAL);
287 BT_ALLOC_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
289 g_array_append_vals(in_param1, req,
290 sizeof(bluetooth_mesh_provisioning_request_t));
292 BT_INFO("Mesh: Set Provision Device");
293 result = _bt_send_request_async(BT_BLUEZ_SERVICE,
294 BT_MESH_NETWORK_PROVISION_DEVICE,
295 in_param1, in_param2, in_param3, in_param4,
296 user_info->cb, user_info->user_data);
298 BT_FREE_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
303 BT_EXPORT_API int bluetooth_mesh_authentication_reply(int auth_type,
304 const char *auth_val, gboolean reply)
308 char auth_string[BLUETOOTH_MESH_AUTH_VALUE_LENGTH_MAX];
310 BT_CHECK_PARAMETER(auth_val, return);
313 BT_ALLOC_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
315 g_strlcpy(auth_string, auth_val,
316 sizeof(auth_string));
317 g_array_append_vals(in_param1,
318 &auth_type, sizeof(int));
319 g_array_append_vals(in_param2, auth_string,
320 BLUETOOTH_MESH_AUTH_VALUE_LENGTH_MAX);
321 g_array_append_vals(in_param3, &reply, sizeof(gboolean));
323 BT_INFO("Mesh: Set Provisioner Authentication Reply");
324 result = _bt_send_request(BT_BLUEZ_SERVICE, BT_MESH_AUTHENTICATION_REPLY,
325 in_param1, in_param2, in_param3, in_param4, &out_param);
327 BT_FREE_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
332 BT_EXPORT_API int bluetooth_mesh_network_set_name(
333 bluetooth_mesh_network_t *network)
337 BT_CHECK_PARAMETER(network, return);
340 BT_ALLOC_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
342 g_array_append_vals(in_param1, network, sizeof(bluetooth_mesh_network_t));
344 BT_INFO("Mesh:Set Network Name");
345 result = _bt_send_request(BT_BLUEZ_SERVICE, BT_MESH_NETWORK_SET_NAME,
346 in_param1, in_param2, in_param3, in_param4, &out_param);
347 BT_FREE_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
352 BT_EXPORT_API int bluetooth_mesh_network_add_netkey(
353 bluetooth_mesh_network_t *network,
354 uint16_t *netkey_idx)
358 BT_CHECK_PARAMETER(network, return);
359 BT_CHECK_PARAMETER(netkey_idx, return);
362 BT_ALLOC_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
364 g_array_append_vals(in_param1, network, sizeof(bluetooth_mesh_network_t));
366 BT_INFO("Mesh:Set Create Subnetwork key");
367 result = _bt_send_request(BT_BLUEZ_SERVICE, BT_MESH_NETWORK_ADD_NETKEY,
368 in_param1, in_param2, in_param3, in_param4, &out_param);
369 if (result == BLUETOOTH_ERROR_NONE)
370 *netkey_idx = g_array_index(out_param, guint16, 0);
371 BT_FREE_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
376 BT_EXPORT_API int bluetooth_mesh_network_delete_netkey(
377 bluetooth_mesh_network_t *network,
382 BT_CHECK_PARAMETER(network, return);
385 BT_ALLOC_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
387 g_array_append_vals(in_param1, network, sizeof(bluetooth_mesh_network_t));
388 g_array_append_vals(in_param2, &netkey_idx, sizeof(guint16));
390 BT_INFO("Mesh: Delete Subnetwork key");
391 result = _bt_send_request(BT_BLUEZ_SERVICE, BT_MESH_NETWORK_DELETE_NETKEY,
392 in_param1, in_param2, in_param3, in_param4, &out_param);
393 BT_FREE_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
398 BT_EXPORT_API int bluetooth_mesh_network_update_netkey(
399 bluetooth_mesh_network_t *network,
404 BT_CHECK_PARAMETER(network, return);
407 BT_ALLOC_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
409 g_array_append_vals(in_param1, network, sizeof(bluetooth_mesh_network_t));
410 g_array_append_vals(in_param2, &netkey_idx, sizeof(guint16));
412 BT_INFO("Mesh: Update Subnetwork key");
413 result = _bt_send_request(BT_BLUEZ_SERVICE, BT_MESH_NETWORK_UPDATE_NETKEY,
414 in_param1, in_param2, in_param3, in_param4, &out_param);
415 BT_FREE_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
420 BT_EXPORT_API int bluetooth_mesh_network_add_appkey(
421 bluetooth_mesh_network_t *network,
422 uint16_t netkey_index,
423 uint16_t *appkey_index)
427 BT_CHECK_PARAMETER(network, return);
428 BT_CHECK_PARAMETER(appkey_index, return);
431 BT_ALLOC_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
433 g_array_append_vals(in_param1, network, sizeof(bluetooth_mesh_network_t));
434 g_array_append_vals(in_param2, &netkey_index, sizeof(guint16));
436 BT_INFO("Mesh: Create AppKey");
437 result = _bt_send_request(BT_BLUEZ_SERVICE, BT_MESH_NETWORK_ADD_APPKEY,
438 in_param1, in_param2, in_param3, in_param4, &out_param);
440 if (result == BLUETOOTH_ERROR_NONE)
441 *appkey_index = g_array_index(out_param, guint16, 0);
442 BT_FREE_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
447 BT_EXPORT_API int bluetooth_mesh_network_update_appkey(
448 bluetooth_mesh_network_t *network,
449 uint16_t netkey_index, uint16_t appkey_index)
453 BT_CHECK_PARAMETER(network, return);
456 BT_ALLOC_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
458 g_array_append_vals(in_param1, network, sizeof(bluetooth_mesh_network_t));
459 g_array_append_vals(in_param2, &netkey_index, sizeof(guint16));
460 g_array_append_vals(in_param3, &appkey_index, sizeof(guint16));
462 BT_INFO("Mesh:BTAPI: Update AppKey");
463 result = _bt_send_request(BT_BLUEZ_SERVICE, BT_MESH_NETWORK_UPDATE_APPKEY,
464 in_param1, in_param2, in_param3, in_param4, &out_param);
466 BT_FREE_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
471 BT_EXPORT_API int bluetooth_mesh_network_delete_appkey(bluetooth_mesh_network_t *network,
472 uint16_t netkey_index, uint16_t appkey_index)
476 BT_CHECK_PARAMETER(network, return);
479 BT_ALLOC_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
481 g_array_append_vals(in_param1, network, sizeof(bluetooth_mesh_network_t));
482 g_array_append_vals(in_param2, &netkey_index, sizeof(guint16));
483 g_array_append_vals(in_param3, &appkey_index, sizeof(guint16));
485 BT_INFO("Mesh: Delete AppKey");
486 result = _bt_send_request(BT_BLUEZ_SERVICE, BT_MESH_NETWORK_DELETE_APPKEY,
487 in_param1, in_param2, in_param3, in_param4, &out_param);
489 BT_FREE_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
494 BT_EXPORT_API int bluetooth_mesh_network_get_all_nodes(
495 bluetooth_mesh_network_t *network,
498 int result = BLUETOOTH_ERROR_NONE;
501 bluetooth_mesh_node_info_t *info;
503 BT_CHECK_PARAMETER(network, return);
504 BT_CHECK_PARAMETER(nodes, return);
507 BT_ALLOC_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
509 g_array_append_vals(in_param1, network, sizeof(bluetooth_mesh_network_t));
511 result = _bt_send_request(BT_BLUEZ_SERVICE, BT_MESH_NETWORK_GET_NODES,
512 in_param1, in_param2, in_param3, in_param4, &out_param);
514 if (result == BLUETOOTH_ERROR_NONE) {
515 if (out_param == NULL) {
516 BT_ERR("Mesh: out_param is NULL");
517 result = BLUETOOTH_ERROR_INTERNAL;
519 size = (out_param->len) / sizeof(bluetooth_mesh_node_info_t);
521 for (i = 0; i < size; i++) {
522 bluetooth_mesh_node_info_t *data;
524 info = &g_array_index(out_param,
525 bluetooth_mesh_node_info_t, i);
527 data = g_memdup(info, sizeof(bluetooth_mesh_node_info_t));
528 g_ptr_array_add(*nodes, (gpointer)data);
533 BT_FREE_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
538 BT_EXPORT_API int bluetooth_mesh_element_get_all_models(
539 bluetooth_mesh_network_t *network,
540 uint16_t node_addr, int elem_idx,
543 int result = BLUETOOTH_ERROR_NONE;
547 BT_CHECK_PARAMETER(network, return);
548 BT_CHECK_PARAMETER(models, return);
551 BT_ALLOC_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
553 g_array_append_vals(in_param1, network, sizeof(bluetooth_mesh_network_t));
554 g_array_append_vals(in_param2, &node_addr, sizeof(guint16));
555 g_array_append_vals(in_param3, &elem_idx, sizeof(int));
557 result = _bt_send_request(BT_BLUEZ_SERVICE, BT_MESH_ELEMENT_GET_MODELS,
558 in_param1, in_param2, in_param3, in_param4, &out_param);
560 if (result == BLUETOOTH_ERROR_NONE) {
561 if (out_param == NULL) {
562 BT_ERR("Mesh: out_param is NULL");
563 result = BLUETOOTH_ERROR_INTERNAL;
565 size = (out_param->len) / sizeof(guint32);
566 BT_INFO("Mesh: Total Models found in Element [%d]", size);
568 for (i = 0; i < size; i++) {
570 uint32_t *model_ptr = NULL;
572 model_obj = g_array_index(out_param,
575 model_ptr = g_memdup(&model_obj, sizeof(guint32));
576 g_ptr_array_add(*models, (gpointer)model_ptr);
581 BT_FREE_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
586 BT_EXPORT_API int bluetooth_mesh_node_browse_vendor_features(
587 bluetooth_mesh_node_features_t *req)
590 bt_user_info_t *user_info;
592 BT_CHECK_PARAMETER(req, return);
594 user_info = _bt_get_user_data(BT_MESH);
595 retv_if(user_info->cb == NULL, BLUETOOTH_ERROR_INTERNAL);
598 BT_ALLOC_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
600 g_array_append_vals(in_param1, req, sizeof(bluetooth_mesh_node_features_t));
602 BT_INFO("Mesh: Browse Vendor features of Node");
603 result = _bt_send_request_async(BT_BLUEZ_SERVICE, BT_MESH_NODE_GET_VENDOR_FEATURES,
604 in_param1, in_param2, in_param3, in_param4,
605 user_info->cb, user_info->user_data);
607 BT_FREE_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
612 BT_EXPORT_API int bluetooth_mesh_browse_remote_node(
613 bluetooth_mesh_node_discover_t *req)
616 bt_user_info_t *user_info;
618 BT_CHECK_PARAMETER(req, return);
620 user_info = _bt_get_user_data(BT_MESH);
621 retv_if(user_info->cb == NULL, BLUETOOTH_ERROR_INTERNAL);
624 BT_ALLOC_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
626 g_array_append_vals(in_param1, req, sizeof(bluetooth_mesh_node_discover_t));
628 BT_INFO("Mesh: Browse remote Node");
629 result = _bt_send_request_async(BT_BLUEZ_SERVICE, BT_MESH_NODE_BROWSE,
630 in_param1, in_param2, in_param3, in_param4,
631 user_info->cb, user_info->user_data);
633 BT_FREE_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
638 BT_EXPORT_API int bluetooth_mesh_node_ttl_execute(
639 bluetooth_mesh_node_ttl_info_t *req)
642 bt_user_info_t *user_info;
644 BT_CHECK_PARAMETER(req, return);
646 user_info = _bt_get_user_data(BT_MESH);
647 retv_if(user_info->cb == NULL, BLUETOOTH_ERROR_INTERNAL);
650 BT_ALLOC_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
652 g_array_append_vals(in_param1, req, sizeof(bluetooth_mesh_node_ttl_info_t));
654 BT_INFO("Mesh: Node TTL Execute");
655 result = _bt_send_request_async(BT_BLUEZ_SERVICE, BT_MESH_NODE_TTL_EXECUTE,
656 in_param1, in_param2, in_param3, in_param4,
657 user_info->cb, user_info->user_data);
659 BT_FREE_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
664 BT_EXPORT_API int bluetooth_mesh_model_configure_appkey(
665 bluetooth_mesh_model_configure_t *req)
668 bt_user_info_t *user_info;
670 BT_CHECK_PARAMETER(req, return);
672 user_info = _bt_get_user_data(BT_MESH);
673 retv_if(user_info->cb == NULL, BLUETOOTH_ERROR_INTERNAL);
676 BT_ALLOC_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
678 g_array_append_vals(in_param1, req, sizeof(bluetooth_mesh_model_configure_t));
680 BT_INFO("Mesh: Node Model Configure AppKey");
681 result = _bt_send_request_async(BT_BLUEZ_SERVICE, BT_MESH_MODEL_CONFIGURE_APPKEY,
682 in_param1, in_param2, in_param3, in_param4,
683 user_info->cb, user_info->user_data);
685 BT_FREE_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
690 BT_EXPORT_API int bluetooth_mesh_model_send_msg(
691 bluetooth_mesh_model_msg_t *req)
694 bt_user_info_t *user_info;
696 BT_CHECK_PARAMETER(req, return);
698 user_info = _bt_get_user_data(BT_MESH);
699 retv_if(user_info->cb == NULL, BLUETOOTH_ERROR_INTERNAL);
702 BT_ALLOC_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
704 g_array_append_vals(in_param1, req, sizeof(bluetooth_mesh_model_msg_t));
706 BT_INFO("Mesh: Node Model Send Msg");
707 result = _bt_send_request_async(BT_BLUEZ_SERVICE, BT_MESH_MODEL_EXECUTE_MSG,
708 in_param1, in_param2, in_param3, in_param4,
709 user_info->cb, user_info->user_data);
711 BT_FREE_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
716 BT_EXPORT_API int bluetooth_mesh_node_configure_key(
717 bluetooth_mesh_key_configure_t *req)
720 bt_user_info_t *user_info;
722 BT_CHECK_PARAMETER(req, return);
724 user_info = _bt_get_user_data(BT_MESH);
725 retv_if(user_info->cb == NULL, BLUETOOTH_ERROR_INTERNAL);
728 BT_ALLOC_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
730 g_array_append_vals(in_param1, req, sizeof(bluetooth_mesh_key_configure_t));
732 BT_INFO("Mesh:BTAPI: Node Key Configure");
733 result = _bt_send_request_async(BT_BLUEZ_SERVICE, BT_MESH_NODE_CONFIGURE_KEY,
734 in_param1, in_param2, in_param3, in_param4,
735 user_info->cb, user_info->user_data);
737 BT_FREE_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
742 BT_EXPORT_API int bluetooth_mesh_network_get_all_groups(
743 bluetooth_mesh_network_t *network,
746 int result = BLUETOOTH_ERROR_NONE;
747 bluetooth_mesh_network_group_info_t *info;
751 BT_CHECK_PARAMETER(network, return);
752 BT_CHECK_PARAMETER(groups, return);
755 BT_ALLOC_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
757 g_array_append_vals(in_param1, network, sizeof(bluetooth_mesh_network_t));
759 result = _bt_send_request(BT_BLUEZ_SERVICE, BT_MESH_NETWORK_GET_GROUPS,
760 in_param1, in_param2, in_param3, in_param4, &out_param);
762 if (result == BLUETOOTH_ERROR_NONE) {
763 if (out_param == NULL) {
764 BT_ERR("Mesh: out_param is NULL");
765 result = BLUETOOTH_ERROR_INTERNAL;
767 size = (out_param->len) / sizeof(bluetooth_mesh_network_group_info_t);
770 BT_INFO("Mesh: No Groups created for the network");
772 BT_INFO("Mesh: Total groups [%d]", size);
773 for (i = 0; i < size; i++) {
774 bluetooth_mesh_network_group_info_t *grp_info = NULL;
776 info = &g_array_index(out_param,
777 bluetooth_mesh_network_group_info_t, i);
778 BT_INFO("Mesh: Group addr [0x%2.2x]", info->group_addr);
779 BT_INFO("Mesh: Group is Virtual [%s]", info->is_virtual ? "YES" : "NO");
780 BT_INFO("Mesh: Group net UUID[%s]", info->net_uuid);
781 if (info->is_virtual)
782 BT_INFO("Mesh: Virual Label UUID [%s]", info->label_uuid);
783 grp_info = g_memdup(info,
784 sizeof(bluetooth_mesh_network_group_info_t));
785 g_ptr_array_add(*groups, (gpointer)grp_info);
790 BT_FREE_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
795 BT_EXPORT_API int bluetooth_mesh_network_get_all_netkey(
796 bluetooth_mesh_network_t *network,
799 int result = BLUETOOTH_ERROR_NONE;
803 BT_CHECK_PARAMETER(network, return);
804 BT_CHECK_PARAMETER(netkeys, return);
807 BT_ALLOC_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
809 g_array_append_vals(in_param1, network, sizeof(bluetooth_mesh_network_t));
811 result = _bt_send_request(BT_BLUEZ_SERVICE, BT_MESH_NETWORK_GET_NETKEYS,
812 in_param1, in_param2, in_param3, in_param4, &out_param);
814 if (result == BLUETOOTH_ERROR_NONE) {
815 if (out_param == NULL) {
816 BT_ERR("Mesh: out_param is NULL");
817 result = BLUETOOTH_ERROR_INTERNAL;
819 size = (out_param->len) / sizeof(guint16);
822 BT_ERR("Mesh: No netkeys created for the network");
823 result = BLUETOOTH_ERROR_NOT_FOUND;
826 for (i = 0; i < size; i++) {
827 uint16_t netkey_index;
828 uint16_t *netkey_idx = NULL;
830 netkey_index = g_array_index(out_param,
833 netkey_idx = g_memdup(&netkey_index, sizeof(guint16));
834 g_ptr_array_add(*netkeys, (gpointer)netkey_idx);
839 BT_FREE_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
844 BT_EXPORT_API int bluetooth_mesh_netkey_get_all_appkey(
845 bluetooth_mesh_network_t *network,
849 int result = BLUETOOTH_ERROR_NONE;
853 BT_CHECK_PARAMETER(network, return);
854 BT_CHECK_PARAMETER(appkeys, return);
857 BT_ALLOC_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
859 g_array_append_vals(in_param1, network, sizeof(bluetooth_mesh_network_t));
860 g_array_append_vals(in_param2, &netkey_idx, sizeof(guint16));
862 result = _bt_send_request(BT_BLUEZ_SERVICE, BT_MESH_NETWORK_GET_APPKEYS,
863 in_param1, in_param2, in_param3, in_param4, &out_param);
865 if (result == BLUETOOTH_ERROR_NONE) {
866 if (out_param == NULL) {
867 BT_ERR("Mesh: out_param is NULL");
868 result = BLUETOOTH_ERROR_INTERNAL;
870 size = (out_param->len) / sizeof(guint16);
873 BT_ERR("Mesh: No Appkeys created for the NetKey in the network");
875 for (i = 0; i < size; i++) {
876 uint16_t appkey_index;
877 uint16_t *appkey_idx = NULL;
879 appkey_index = g_array_index(out_param,
882 appkey_idx = g_memdup(&appkey_index, sizeof(guint16));
883 g_ptr_array_add(*appkeys, (gpointer)appkey_idx);
888 BT_FREE_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
893 BT_EXPORT_API int bluetooth_mesh_node_get_all_netkeys(
894 bluetooth_mesh_node_discover_t *node,
897 int result = BLUETOOTH_ERROR_NONE;
901 BT_CHECK_PARAMETER(node, return);
902 BT_CHECK_PARAMETER(netkeys, return);
905 BT_ALLOC_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
907 g_array_append_vals(in_param1, node, sizeof(bluetooth_mesh_node_discover_t));
909 result = _bt_send_request(BT_BLUEZ_SERVICE, BT_MESH_NODE_GET_NETKEYS,
910 in_param1, in_param2, in_param3, in_param4, &out_param);
912 if (result == BLUETOOTH_ERROR_NONE) {
913 if (out_param == NULL) {
914 BT_ERR("Mesh: out_param is NULL");
915 result = BLUETOOTH_ERROR_INTERNAL;
917 size = (out_param->len) / sizeof(guint16);
919 for (i = 0; i < size; i++) {
920 uint16_t netkey_index;
921 uint16_t *netkey_idx = NULL;
923 netkey_index = g_array_index(out_param,
926 netkey_idx = g_memdup(&netkey_index, sizeof(guint16));
927 g_ptr_array_add(*netkeys, (gpointer)netkey_idx);
932 BT_FREE_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
937 BT_EXPORT_API int bluetooth_mesh_node_get_all_appkeys(
938 bluetooth_mesh_node_discover_t *req, GPtrArray **appkeys)
940 int result = BLUETOOTH_ERROR_NONE;
944 BT_CHECK_PARAMETER(req, return);
945 BT_CHECK_PARAMETER(appkeys, return);
948 BT_ALLOC_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
950 g_array_append_vals(in_param1, req, sizeof(bluetooth_mesh_node_discover_t));
952 result = _bt_send_request(BT_BLUEZ_SERVICE, BT_MESH_NODE_GET_APPKEYS,
953 in_param1, in_param2, in_param3, in_param4, &out_param);
955 if (result == BLUETOOTH_ERROR_NONE) {
956 if (out_param == NULL) {
957 BT_ERR("Mesh: out_param is NULL");
958 result = BLUETOOTH_ERROR_INTERNAL;
960 size = (out_param->len) / sizeof(guint16);
962 for (i = 0; i < size; i++) {
963 uint16_t appkey_index;
964 uint16_t *appkey_idx = NULL;
966 appkey_index = g_array_index(out_param,
969 appkey_idx = g_memdup(&appkey_index, sizeof(guint16));
970 g_ptr_array_add(*appkeys, (gpointer)appkey_idx);
975 BT_FREE_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
980 BT_EXPORT_API int bluetooth_mesh_model_get_all_appkeys(
981 bluetooth_mesh_model_configure_t *req)
984 bt_user_info_t *user_info;
986 BT_CHECK_PARAMETER(req, return);
988 user_info = _bt_get_user_data(BT_MESH);
989 retv_if(user_info->cb == NULL, BLUETOOTH_ERROR_INTERNAL);
992 BT_ALLOC_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
994 g_array_append_vals(in_param1, req, sizeof(bluetooth_mesh_model_configure_t));
996 BT_INFO("Mesh:Node Model Get AppKey List ");
997 result = _bt_send_request_async(BT_BLUEZ_SERVICE, BT_MESH_MODEL_GET_APPKEY_LIST,
998 in_param1, in_param2, in_param3, in_param4,
999 user_info->cb, user_info->user_data);
1001 BT_FREE_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
1005 BT_EXPORT_API int bluetooth_mesh_model_set_publication(
1006 bluetooth_mesh_model_configure_t *req)
1009 bt_user_info_t *user_info;
1011 BT_CHECK_PARAMETER(req, return);
1013 user_info = _bt_get_user_data(BT_MESH);
1014 retv_if(user_info->cb == NULL, BLUETOOTH_ERROR_INTERNAL);
1017 BT_ALLOC_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
1019 g_array_append_vals(in_param1, req, sizeof(bluetooth_mesh_model_configure_t));
1021 BT_INFO("Mesh: Model Set Publication");
1022 result = _bt_send_request_async(BT_BLUEZ_SERVICE, BT_MESH_MODEL_SET_PUBLICATION,
1023 in_param1, in_param2, in_param3, in_param4,
1024 user_info->cb, user_info->user_data);
1026 BT_FREE_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
1030 BT_EXPORT_API int bluetooth_mesh_model_get_publication(
1031 bluetooth_mesh_model_configure_t *req)
1034 bt_user_info_t *user_info;
1036 BT_CHECK_PARAMETER(req, return);
1038 user_info = _bt_get_user_data(BT_MESH);
1039 retv_if(user_info->cb == NULL, BLUETOOTH_ERROR_INTERNAL);
1042 BT_ALLOC_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
1044 g_array_append_vals(in_param1, req, sizeof(bluetooth_mesh_model_configure_t));
1046 BT_INFO("Mesh:BTAPI: Model Get Publication");
1047 result = _bt_send_request_async(BT_BLUEZ_SERVICE, BT_MESH_MODEL_GET_PUBLICATION,
1048 in_param1, in_param2, in_param3, in_param4,
1049 user_info->cb, user_info->user_data);
1051 BT_FREE_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
1055 BT_EXPORT_API int bluetooth_mesh_model_get_subscriptopn_list(
1056 bluetooth_mesh_model_configure_t *req)
1059 bt_user_info_t *user_info;
1061 BT_CHECK_PARAMETER(req, return);
1063 user_info = _bt_get_user_data(BT_MESH);
1064 retv_if(user_info->cb == NULL, BLUETOOTH_ERROR_INTERNAL);
1067 BT_ALLOC_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
1069 g_array_append_vals(in_param1, req, sizeof(bluetooth_mesh_model_configure_t));
1071 BT_INFO("Mesh:BTAPI: Model Get Subscription List ");
1072 result = _bt_send_request_async(BT_BLUEZ_SERVICE, BT_MESH_MODEL_GET_SUBSCRIPTION_LIST,
1073 in_param1, in_param2, in_param3, in_param4,
1074 user_info->cb, user_info->user_data);
1076 BT_FREE_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
1080 BT_EXPORT_API int bluetooth_mesh_network_remove_group(
1081 bluetooth_mesh_network_t *network,
1082 bluetooth_mesh_network_group_info_t *req)
1086 BT_CHECK_PARAMETER(network, return);
1087 BT_CHECK_PARAMETER(req, return);
1090 BT_ALLOC_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
1092 g_array_append_vals(in_param1, network, sizeof(bluetooth_mesh_network_t));
1093 g_array_append_vals(in_param2, req, sizeof(bluetooth_mesh_network_group_info_t));
1095 BT_INFO("Mesh: Remove Group Request");
1096 result = _bt_send_request(BT_BLUEZ_SERVICE, BT_MESH_NETWORK_REMOVE_GROUP,
1097 in_param1, in_param2, in_param3, in_param4, &out_param);
1099 BT_FREE_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
1104 BT_EXPORT_API int bluetooth_mesh_network_create_group(
1105 bluetooth_mesh_network_t *network, bool is_virtual,
1106 uint16_t grp_addr, bluetooth_mesh_network_group_info_t *info)
1110 BT_CHECK_PARAMETER(network, return);
1111 BT_CHECK_PARAMETER(info, return);
1114 BT_ALLOC_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
1116 g_array_append_vals(in_param1, network, sizeof(bluetooth_mesh_network_t));
1117 g_array_append_vals(in_param2, &is_virtual, sizeof(gboolean));
1118 g_array_append_vals(in_param3, &grp_addr, sizeof(guint16));
1120 BT_INFO("Mesh: Create Group Request");
1121 result = _bt_send_request(BT_BLUEZ_SERVICE, BT_MESH_NETWORK_CREATE_GROUP,
1122 in_param1, in_param2, in_param3, in_param4, &out_param);
1124 if (result == BLUETOOTH_ERROR_NONE) {
1125 *info = g_array_index(out_param,
1126 bluetooth_mesh_network_group_info_t, 0);
1128 BT_FREE_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
1133 BT_EXPORT_API int bluetooth_mesh_model_configure_group_sub(
1134 bluetooth_mesh_model_configure_t *req)
1137 bt_user_info_t *user_info;
1139 BT_CHECK_PARAMETER(req, return);
1141 user_info = _bt_get_user_data(BT_MESH);
1142 retv_if(user_info->cb == NULL, BLUETOOTH_ERROR_INTERNAL);
1145 BT_ALLOC_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
1147 g_array_append_vals(in_param1, req, sizeof(bluetooth_mesh_model_configure_t));
1149 BT_INFO("Mesh:Model Group Subscription Request");
1150 result = _bt_send_request_async(BT_BLUEZ_SERVICE, BT_MESH_MODEL_CONFIG_GROUP_SUB,
1151 in_param1, in_param2, in_param3, in_param4,
1152 user_info->cb, user_info->user_data);
1154 BT_FREE_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
1158 BT_EXPORT_API int bluetooth_mesh_model_configure_virtual_group_sub(
1159 bluetooth_mesh_model_configure_t *req)
1162 bt_user_info_t *user_info;
1164 BT_CHECK_PARAMETER(req, return);
1166 user_info = _bt_get_user_data(BT_MESH);
1167 retv_if(user_info->cb == NULL, BLUETOOTH_ERROR_INTERNAL);
1170 BT_ALLOC_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
1172 g_array_append_vals(in_param1, req, sizeof(bluetooth_mesh_model_configure_t));
1174 BT_INFO("Mesh: Model Virtual Group Subscription Request");
1175 result = _bt_send_request_async(BT_BLUEZ_SERVICE,
1176 BT_MESH_MODEL_CONFIG_VIRTUAL_GROUP_SUB,
1177 in_param1, in_param2, in_param3, in_param4,
1178 user_info->cb, user_info->user_data);
1180 BT_FREE_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);