2 * Copyright (c) 2020 Samsung Electronics Co., Ltd All Rights Reserved *
4 * @author: Anupam Roy <anupam.r@samsung.com>
5 * @author: Himanshu <h.himanshu@samsung.com>
7 * Licensed under the Apache License, Version 2.0 (the License);
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an AS IS BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
29 #include <sys/types.h>
31 #include "bluetooth.h"
32 #include "bluetooth_type_internal.h"
33 #include "bluetooth_internal.h"
34 #include "bluetooth_private.h"
35 #include "bt_mesh_unit_test.h"
37 static bt_mesh_unit_test_table_e current_tc_table;
39 static bool need_to_set_params = false;
40 static int g_test_id = -1;
41 static tc_params_t g_test_param = {0,};
43 static bt_mesh_node_h local_node = NULL;
44 static bt_mesh_node_h g_node;
45 static bt_mesh_network_h network;
46 static char *device_uuid;
49 static bt_mesh_authentication_type_e request_type = BT_MESH_AUTH_ALPHANUMERIC_DISPLAY;
51 GMainLoop *main_loop = NULL;
53 tc_table_t tc_configuration[] = {
55 , BT_MESH_UNIT_TEST_FUNCTION_BACK},
56 {"bt_mesh_network_discover_node"
57 , BT_MESH_UNIT_TEST_FUNCTION_MESH_NETWORK_DISCOVER_NODE},
59 , BT_MESH_UNIT_TEST_FUNCTION_NODE_RESET},
60 {"bt_mesh_node_get_features"
61 , BT_MESH_UNIT_TEST_FUNCTION_NODE_GET_FEATURES},
62 {"bt_mesh_node_foreach_netkeys"
63 , BT_MESH_UNIT_TEST_FUNCTION_NODE_GET_NETKEYS},
64 {"bt_mesh_node_foreach_appkeys"
65 , BT_MESH_UNIT_TEST_FUNCTION_NODE_GET_APPKEYS},
66 {"bt_mesh_node_get_ttl"
67 , BT_MESH_UNIT_TEST_FUNCTION_NODE_GET_TTL},
68 {"bt_mesh_node_set_ttl"
69 , BT_MESH_UNIT_TEST_FUNCTION_NODE_SET_TTL},
70 {"bt_mesh_node_configure_netkey"
71 , BT_MESH_UNIT_TEST_FUNCTION_NODE_CONFIGURE_NETKEY},
72 {"bt_mesh_node_configure_appkey"
73 , BT_MESH_UNIT_TEST_FUNCTION_NODE_CONFIGURE_APPKEY},
74 {"bt_mesh_model_bind_appkey"
75 , BT_MESH_UNIT_TEST_FUNCTION_MODEL_BIND_APPKEY},
76 {"bt_mesh_model_unbind_appkey"
77 , BT_MESH_UNIT_TEST_FUNCTION_MODEL_UNBIND_APPKEY},
78 {"bt_mesh_model_get_appkey_list"
79 , BT_MESH_UNIT_TEST_FUNCTION_MODEL_GET_APPKEY_LIST},
80 {"bt_mesh_model_configure_group_subscription"
81 , BT_MESH_UNIT_TEST_FUNCTION_MODEL_CONFIGURE_GROUP_SUBSCRIPTION},
82 {"bt_mesh_model_configure_virtual_group_subscription"
83 , BT_MESH_UNIT_TEST_FUNCTION_MODEL_CONFIGURE_VIRTUAL_GROUP_SUBSCRIPTION},
84 {"bt_mesh_model_get_subscription_list"
85 , BT_MESH_UNIT_TEST_FUNCTION_MODEL_GET_SUBSCRIPTION_LIST},
86 {"bt_mesh_model_set_publication"
87 , BT_MESH_UNIT_TEST_FUNCTION_MODEL_SET_PUBLICATION},
88 {"bt_mesh_model_get_publication"
89 , BT_MESH_UNIT_TEST_FUNCTION_MODEL_GET_PUBLICATION},
90 {"bt_mesh_model_send_msg"
91 , BT_MESH_UNIT_TEST_FUNCTION_MODEL_SEND_MSG},
92 {"bt_mesh_appkey_get_netkey"
93 , BT_MESH_UNIT_TEST_FUNCTION_APPKEY_GET_NETKEY},
94 {"select this menu to set parameters and then select the function again"
95 , BT_MESH_UNIT_TEST_FUNCTION_ACTIVATE_FLAG_TO_SET_PARAMETERS},
99 tc_table_t tc_network[] = {
101 , BT_MESH_UNIT_TEST_FUNCTION_BACK},
102 {"bt_mesh_node_create"
103 , BT_MESH_UNIT_TEST_FUNCTION_NODE_CREATE},
104 {"bt_mesh_node_destroy"
105 , BT_MESH_UNIT_TEST_FUNCTION_NODE_DESTROY},
106 {"bt_mesh_node_create_element"
107 , BT_MESH_UNIT_TEST_FUNCTION_NODE_CREATE_ELEMENT},
108 {"bt_mesh_node_get_network"
109 , BT_MESH_UNIT_TEST_FUNCTION_NODE_GET_NETWORK},
110 {"bt_mesh_element_create_model"
111 , BT_MESH_UNIT_TEST_FUNCTION_ELEMENT_CREATE_MODEL},
112 {"bt_mesh_model_get_id"
113 , BT_MESH_UNIT_TEST_FUNCTION_MODEL_GET_ID},
114 {"bt_mesh_model_destroy"
115 , BT_MESH_UNIT_TEST_FUNCTION_MODEL_DESTROY},
116 {"bt_mesh_model_get_element"
117 , BT_MESH_UNIT_TEST_FUNCTION_MODEL_GET_ELEMENT},
118 {"bt_mesh_element_destroy"
119 , BT_MESH_UNIT_TEST_FUNCTION_ELEMENT_DESTROY},
120 {"bt_mesh_element_get_node"
121 , BT_MESH_UNIT_TEST_FUNCTION_ELEMENT_GET_NODE},
122 {"bt_mesh_node_foreach_element"
123 , BT_MESH_UNIT_TEST_FUNCTION_NODE_FOREACH_ELEMENTS},
124 {"bt_mesh_element_foreach_models"
125 , BT_MESH_UNIT_TEST_FUNCTION_ELEMENT_FOREACH_MODELS},
126 {"bt_mesh_network_create"
127 , BT_MESH_UNIT_TEST_FUNCTION_NETWORK_CREATE},
128 {"bt_mesh_network_create_in_loop"
129 , BT_MESH_UNIT_TEST_FUNCTION_NETWORK_CREATE_IN_LOOP},
130 {"bt_mesh_network_destroy"
131 , BT_MESH_UNIT_TEST_FUNCTION_NETWORK_DESTROY},
132 {"bt_mesh_network_load"
133 , BT_MESH_UNIT_TEST_FUNCTION_NETWORK_LOAD},
134 {"bt_mesh_network_set_name"
135 , BT_MESH_UNIT_TEST_FUNCTION_NETWORK_SET_NAME},
136 {"bt_mesh_network_get_name"
137 , BT_MESH_UNIT_TEST_FUNCTION_NETWORK_GET_NAME},
138 {"bt_mesh_network_add_netkey"
139 , BT_MESH_UNIT_TEST_FUNCTION_NETWORK_ADD_NETKEY},
140 {"bt_mesh_network_foreach_netkeys"
141 , BT_MESH_UNIT_TEST_FUNCTION_NETWORK_FOREACH_NETKEYS},
142 {"bt_mesh_netkey_get_index"
143 , BT_MESH_UNIT_TEST_FUNCTION_NETKEY_GET_INDEX},
144 {"bt_mesh_netkey_update"
145 , BT_MESH_UNIT_TEST_FUNCTION_NETKEY_UPDATE},
146 {"bt_mesh_netkey_delete"
147 , BT_MESH_UNIT_TEST_FUNCTION_NETKEY_DELETE},
148 {"bt_mesh_netkey_add_appkey"
149 , BT_MESH_UNIT_TEST_FUNCTION_NETKEY_ADD_APPKEY},
150 {"bt_mesh_netkey_foreach_appkeys"
151 , BT_MESH_UNIT_TEST_FUNCTION_NETKEY_FOREACH_APPKEYS},
152 {"bt_mesh_appkey_get_index"
153 , BT_MESH_UNIT_TEST_FUNCTION_APPKEY_GET_INDEX},
154 {"bt_mesh_appkey_update"
155 , BT_MESH_UNIT_TEST_FUNCTION_APPKEY_UPDATE},
156 {"bt_mesh_appkey_delete"
157 , BT_MESH_UNIT_TEST_FUNCTION_APPKEY_DELETE},
158 {"bt_mesh_network_foreach_devices"
159 , BT_MESH_UNIT_TEST_FUNCTION_NETWORK_FOREACH_DEVICES},
160 {"bt_mesh_network_create_group"
161 , BT_MESH_UNIT_TEST_FUNCTION_NETWORK_CREATE_GROUP},
162 {"bt_mesh_network_create_virtual_group"
163 , BT_MESH_UNIT_TEST_FUNCTION_NETWORK_CREATE_VIRTUAL_GROUP},
164 {"bt_mesh_network_remove_group"
165 , BT_MESH_UNIT_TEST_FUNCTION_NETWORK_REMOVE_GROUP},
166 {"bt_mesh_network_foreach_groups"
167 , BT_MESH_UNIT_TEST_FUNCTION_NETWORK_FOREACH_GROUPS},
168 {"bt_mesh_network_unprovisioned_device_scan"
169 , BT_MESH_UNIT_TEST_FUNCTION_NETWORK_UNPROVISIONED_DEVICE_SCAN},
170 {"bt_mesh_stop_unprovisioned_device_scan"
171 , BT_MESH_UNIT_TEST_FUNCTION_STOP_UNPROVISIONED_DEVICE_SCAN},
172 {"bt_mesh_network_provision_device"
173 , BT_MESH_UNIT_TEST_FUNCTION_NETWORK_PROVISION_DEVICE},
174 {"bt_mesh_authentication_set_request_cb"
175 , BT_MESH_UNIT_TEST_FUNCTION_NETWORK_AUTHENTICATION_SET_REQUEST_CB},
176 {"bt_mesh_authentication_reply"
177 , BT_MESH_UNIT_TEST_FUNCTION_MESH_AUTHENTICATION_REPLY},
178 {"bt_mesh_network_set_provisioning_capabilities"
179 , BT_MESH_UNIT_TEST_FUNCTION_NETWORK_SET_PROVISIONING_CAPABILITIES},
180 {"bt_mesh_network_get_provisioning_capabilities"
181 , BT_MESH_UNIT_TEST_FUNCTION_NETWORK_GET_PROVISIONING_CAPABILITIES},
182 {"select this menu to set parameters and then select the function again"
183 , BT_MESH_UNIT_TEST_FUNCTION_ACTIVATE_FLAG_TO_SET_PARAMETERS},
187 tc_table_t tc_main[] = {
188 {"bt_mesh_initialize"
189 , BT_MESH_UNIT_TEST_FUNCTION_INITIALIZE},
190 {"bt_mesh_deinitialize"
191 , BT_MESH_UNIT_TEST_FUNCTION_DEINITIALIZE},
193 , BT_MESH_UNIT_TEST_TABLE_NETWORK},
195 , BT_MESH_UNIT_TEST_TABLE_CONFIGURATION},
197 , BT_MESH_UNIT_TEST_TABLE_FINISH},
201 static void __bt_free_test_param(tc_params_t *param)
205 for (i = 0; i < param->param_count; i++)
206 g_free(param->params[i]);
207 g_free(param->params);
208 param->params = NULL;
209 param->param_count = 0;
212 void tc_usage_print(void){
214 tc_table_t *tc_table = NULL;
215 switch (current_tc_table) {
216 case BT_MESH_UNIT_TEST_TABLE_NETWORK:
217 tc_table = tc_network;
219 case BT_MESH_UNIT_TEST_TABLE_CONFIGURATION:
220 tc_table = tc_configuration;
226 while (tc_table[i].tc_name) {
227 TC_PRT("Key %d : usage %s", tc_table[i].tc_code,tc_table[i].tc_name);
232 static const char *__bt_get_error_message(bt_error_e err)
234 const char *err_str = NULL;
238 err_str = "BT_ERROR_NONE";
240 case BT_ERROR_CANCELLED:
241 err_str = "BT_ERROR_CANCELLED";
243 case BT_ERROR_INVALID_PARAMETER:
244 err_str = "BT_ERROR_INVALID_PARAMETER";
246 case BT_ERROR_OUT_OF_MEMORY:
247 err_str = "BT_ERROR_OUT_OF_MEMORY";
249 case BT_ERROR_RESOURCE_BUSY:
250 err_str = "BT_ERROR_RESOURCE_BUSY";
252 case BT_ERROR_TIMED_OUT:
253 err_str = "BT_ERROR_TIMED_OUT";
255 case BT_ERROR_NOW_IN_PROGRESS:
256 err_str = "BT_ERROR_NOW_IN_PROGRESS";
258 case BT_ERROR_NOT_INITIALIZED:
259 err_str = "BT_ERROR_NOT_INITIALIZED";
261 case BT_ERROR_NOT_ENABLED:
262 err_str = "BT_ERROR_NOT_ENABLED";
264 case BT_ERROR_ALREADY_DONE:
265 err_str = "BT_ERROR_ALREADY_DONE";
267 case BT_ERROR_OPERATION_FAILED:
268 err_str = "BT_ERROR_OPERATION_FAILED";
270 case BT_ERROR_NOT_IN_PROGRESS:
271 err_str = "BT_ERROR_NOT_IN_PROGRESS";
274 err_str = "NOT defined";
280 void print_network_handle(bt_mesh_network_h network)
284 bt_mesh_network_s* net = (bt_mesh_network_s*) network;
285 TC_PRT("network_handle = [%p]", (void*)net);
286 TC_PRT("net->is_local [%d]", net->is_local);
287 TC_PRT("net->is_discovered [%d]", net->is_discovered);
288 TC_PRT("net->uuid [%s]", net->uuid);
289 TC_PRT("net->token [%s]", net->token);
290 TC_PRT("net->name [%s]", net->name);
291 TC_PRT("net->num_nodes [%d]", net->num_nodes);
294 void print_node_handle(bt_mesh_node_h node)
298 bt_mesh_node_s* node_info = (bt_mesh_node_s*) node;
299 TC_PRT("node_handle = [%p]",(void*)node_info);
300 TC_PRT("node->is_local [%d]", node_info->is_local);
301 TC_PRT("node->is_attached [%d]", node_info->is_attached);
302 if (node_info->is_attached) {
303 TC_PRT("node->parent_network [%s]", node_info->parent->name);
304 TC_PRT("node->uuid [%s]", node_info->uuid);
305 TC_PRT("node->unicast [%d]", node_info->unicast);
310 void print_element_handle(bt_mesh_element_h element)
314 bt_mesh_element_s* element_info = (bt_mesh_element_s*) element;
315 TC_PRT("element_handle = [%p]", (void*)element_info);
316 TC_PRT("element->is_local [%d]", element_info->is_local);
317 TC_PRT("element->index [%d]", element_info->index);
320 void print_model_handle(bt_mesh_model_h model)
324 bt_mesh_model_s* model_info = (bt_mesh_model_s*) model;
325 TC_PRT("model_handle = [%p]", (void*)model_info);
326 TC_PRT("model->is_local [%d]", model_info->is_local);
327 TC_PRT("model->id [0x%4.4x]", model_info->id);
328 TC_PRT("model->pub_addr [0x%2.2x]", model_info->pub_addr);
331 void print_netkey_handle(bt_mesh_netkey_h netkey)
335 bt_mesh_netkey_s* netkey_info = (bt_mesh_netkey_s*) netkey;
336 TC_PRT("netkey_handle = [%p]", (void*)netkey_info);
337 TC_PRT("Parent network_name [%s]", netkey_info->parent->name);
338 TC_PRT("Netkey_index [%d]", netkey_info->netkey_index);
341 void print_appkey_handle(bt_mesh_appkey_h appkey)
345 bt_mesh_appkey_s* appkey_info = (bt_mesh_appkey_s*) appkey;
346 TC_PRT("appkey_handle = [%p]", (void*)appkey_info);
347 TC_PRT("Parent netkey_index [%d]", appkey_info->parent->netkey_index);
348 TC_PRT("appkey_index [%d]", appkey_info->appkey_index);
351 void print_group_handle(bt_mesh_group_h group)
355 bt_mesh_group_s* group_info = (bt_mesh_group_s*) group;
356 TC_PRT("group_handle = [%p]", (void*)group_info);
357 TC_PRT("group Parent Network Name [%s]", group_info->parent->name);
358 TC_PRT("group Address [0x%2.2x]", group_info->addr);
359 TC_PRT("group Label UUID [%s]", group_info->label_uuid);
360 TC_PRT("group Is Virtual ? [%s]", group_info->is_virtual ? "YES" : "NO");
363 bool __bt_mesh_network_device_info_cb(int result, bt_mesh_network_h network, int total,
364 const char *dev_uuid, uint16_t primary_unicast, void *user_data)
366 TC_PRT("bt_mesh_network_device_info_cb");
367 TC_PRT("Total number of Devices in network [%d]", total);
369 TC_PRT("result: %s", __bt_get_error_message(result));
370 TC_PRT("primary unicast address is [%d]",primary_unicast);
371 TC_PRT("Device UUID [%s]", dev_uuid);
375 bool __bt_mesh_network_group_info_cb(int result, bt_mesh_network_h network, int total,
376 bt_mesh_group_h group, void *user_data)
378 bt_mesh_group_s* grp = (bt_mesh_group_s*) group;
379 TC_PRT("bt_mesh_network_group_info_cb: Total groups present in network [%d]", total);
380 TC_PRT("result: %s", __bt_get_error_message(result));
382 if (result == BT_ERROR_NONE) {
383 print_group_handle(grp);
389 void __bt_mesh_node_discover_status_cb(int result, bt_mesh_network_h network, bt_mesh_node_h node_param,
392 TC_PRT("bt_mesh_node_discover_status_cb");
393 TC_PRT("result: %s", __bt_get_error_message(result));
394 //print_network_handle(network);
395 print_node_handle(node_param);
396 if (result == BT_ERROR_NONE)
400 static bool __bt_mesh_elem_foreach_model_cb(int result, bt_mesh_element_h element, int total,
401 bt_mesh_model_h model, bt_mesh_model_id_s *model_id, void *user_data)
403 TC_PRT("__bt_mesh_elem_foreach_model_cb");
404 TC_PRT("result: %s", __bt_get_error_message(result));
406 if (result == BT_ERROR_NONE) {
407 TC_PRT("Total number of Models in the element [%d]", total);
408 print_element_handle(element);
410 print_model_handle(model);
411 TC_PRT("Model Comp ID [0x%2.2x] Model ID [0x%2.2x]",
412 model_id->company_id, model_id->model_id);
419 static bool __bt_mesh_node_foreach_elem_cb(int result, bt_mesh_node_h node, int total,
420 bt_mesh_element_h element, int elem_index, uint16_t element_addr, void *user_data)
422 TC_PRT("__bt_mesh_node_foreach_elem_cb");
423 TC_PRT("result: %s", __bt_get_error_message(result));
425 if (result == BT_ERROR_NONE) {
426 TC_PRT("Total number of elements in the node [%d]", total);
427 print_node_handle(node);
429 print_element_handle(element);
430 TC_PRT("Element address [0x%2.2x]", element_addr);
431 TC_PRT("Element index [%d]", elem_index);
438 static void __bt_mesh_node_configure_netkey_cb(int result, bt_mesh_node_key_configuration_e op,
439 bt_mesh_node_h node, bt_mesh_netkey_h netkey, void *user_data)
441 TC_PRT("__bt_mesh_node_configure_netkey_cb");
442 TC_PRT("result: %s", __bt_get_error_message(result));
444 if (result == BT_ERROR_NONE) {
445 print_node_handle(node);
446 if (op == BT_MESH_NODE_KEY_ADD)
447 TC_PRT("NetKey Added!");
448 else if (op == BT_MESH_NODE_KEY_UPDATE)
449 TC_PRT("NetKey Updated!");
451 TC_PRT("NetKey Deleted!");
452 print_netkey_handle(netkey);
456 static void __bt_mesh_node_configure_appkey_cb(int result, bt_mesh_node_key_configuration_e op,
457 bt_mesh_node_h node, bt_mesh_netkey_h netkey,
458 bt_mesh_appkey_h appkey, void *user_data)
460 TC_PRT("__bt_mesh_node_configure_netkey_cb");
461 TC_PRT("result: %s", __bt_get_error_message(result));
463 if (result == BT_ERROR_NONE) {
464 print_node_handle(node);
465 if (op == BT_MESH_NODE_KEY_ADD)
466 TC_PRT("AppKey Added!");
467 else if (op == BT_MESH_NODE_KEY_UPDATE)
468 TC_PRT("AppKey Updated!");
470 TC_PRT("AppKey Deleted!");
471 print_netkey_handle(netkey);
472 print_appkey_handle(appkey);
476 static void __bt_mesh_node_features_cb(int result, bt_mesh_node_h node,
477 bt_mesh_node_features_s *features, void *user_data)
479 TC_PRT("__bt_mesh_node_features_cb");
480 TC_PRT("result: %s", __bt_get_error_message(result));
482 if (result == BT_ERROR_NONE) {
483 print_node_handle(node);
484 TC_PRT("CID [0x%2.2x]\n", features->cid);
485 TC_PRT("PID [0x%2.2x]\n", features->pid);
486 TC_PRT("VID [0x%2.2x]\n", features->vid);
487 TC_PRT("CRPL [0x%2.2x]\n", features->crpl);
489 if (features->features & BT_MESH_FEATURE_RELAY)
490 TC_PRT("Features: RELAY Supported");
491 if (features->features & BT_MESH_FEATURE_PROXY)
492 TC_PRT("Features: PROXY Supported");
493 if (features->features & BT_MESH_FEATURE_FRIEND)
494 TC_PRT("Features: FRIEND Supported");
495 if (features->features & BT_MESH_FEATURE_LOWPOWER)
496 TC_PRT("Features: LOW POWER Supported\n");
500 static bool __bt_mesh_node_foreach_netkeys_cb(int result, bt_mesh_node_h node, int total,
501 bt_mesh_netkey_h netkey,
502 uint16_t netkey_index, void *user_data)
504 TC_PRT("__bt_mesh_node_foreach_netkeys_cb");
505 TC_PRT("result: %s", __bt_get_error_message(result));
507 if (result == BT_ERROR_NONE) {
508 TC_PRT("Total Netkeys in node [%d]", total);
509 print_node_handle(node);
510 print_netkey_handle(netkey);
516 static bool __bt_mesh_node_foreach_appkeys_cb(int result, bt_mesh_node_h node, int total,
517 bt_mesh_netkey_h netkey, bt_mesh_appkey_h appkey,
518 uint16_t appkey_index, void *user_data)
520 TC_PRT("__bt_mesh_node_foreach_appkeys_cb");
521 TC_PRT("result: %s", __bt_get_error_message(result));
523 if (result == BT_ERROR_NONE) {
524 TC_PRT("Total Appkeys in node [%d]", total);
525 print_netkey_handle(netkey);
526 print_appkey_handle(appkey);
532 void __bt_mesh_node_ttl_cb(int result, bt_mesh_node_h node,
533 bt_mesh_node_ttl_operation_e ttl_op, uint8_t ttl, void *user_data)
535 TC_PRT("bt_mesh_node_ttl_cb");
536 TC_PRT("result: %s", __bt_get_error_message(result));
538 if (result == BT_ERROR_NONE) {
539 print_node_handle(node);
540 TC_PRT("ttl_op is [%s]", ttl_op? "TTL Set" : "TTL Get");
541 TC_PRT("ttl value is [%d]",ttl);
545 void __bt_mesh_model_bind_cb(int result, bt_mesh_model_h model, bt_mesh_appkey_h appkey,
548 TC_PRT("bt_mesh_model_bind_cb");
549 TC_PRT("result: %s", __bt_get_error_message(result));
550 if (result == BT_ERROR_NONE) {
551 print_model_handle(model);
552 print_appkey_handle(appkey);
556 void __bt_mesh_model_msg_cb(int result, bt_mesh_element_h element, bt_mesh_appkey_h appkey,
557 bt_mesh_model_msg_params_s *msg, void *user_data)
559 TC_PRT("bt_mesh_model_msg_cb");
560 TC_PRT("result: %s", __bt_get_error_message(result));
561 if (result == BT_ERROR_NONE) {
562 TC_PRT("opcode: 0X%2.2X", msg->opcode);
563 TC_PRT("msg: %s", msg->data);
564 print_element_handle(element);
565 print_appkey_handle(appkey);
569 void __bt_mesh_model_unbind_cb(int result, bt_mesh_model_h model, bt_mesh_appkey_h appkey,
572 TC_PRT("bt_mesh_model_unbind_cb");
573 TC_PRT("result: %s", __bt_get_error_message(result));
574 if (result == BT_ERROR_NONE) {
575 print_model_handle(model);
576 print_appkey_handle(appkey);
580 void __bt_mesh_model_appkey_list_cb(int result, bt_mesh_model_h model, int total, const GSList *appkeylist,
583 TC_PRT("bt_mesh_model_appkey_list_cb");
586 TC_PRT("result: %s", __bt_get_error_message(result));
587 if (result == BT_ERROR_NONE) {
588 TC_PRT("Total number of AppKeys bound to the model [%d]", total);
589 print_model_handle(model);
591 for (l = appkeylist; l != NULL; l = l->next) {
592 bt_mesh_appkey_h appkey = (bt_mesh_appkey_h) l->data;
593 print_appkey_handle(appkey);
598 void __bt_mesh_model_subscription_op_cb(int result, bt_mesh_model_subscription_op_e op,
599 bt_mesh_model_h model, bt_mesh_group_h group, void *user_data)
601 TC_PRT("bt_mesh_model_subscription_op_cb");
602 TC_PRT("result: %s", __bt_get_error_message(result));
604 if (result == BT_ERROR_NONE) {
607 TC_PRT("Model Subscription Operation is ADD");
610 TC_PRT("Model Subscription Operation is DELETE");
613 TC_PRT("Model Subscription Operation is DELETE ALL");
616 TC_PRT("Model Subscription Operation is OVERWRITE");
619 TC_PRT("Invalid Model Subscription Operation");
622 print_model_handle(model);
623 print_group_handle(group);
627 bool __bt_mesh_model_subscription_list_cb(int result, bt_mesh_model_h model, int total, const GSList *sub_addr,
631 TC_PRT("bt_mesh_model_subscription_list_cb");
632 TC_PRT("result: %s", __bt_get_error_message(result));
633 if (result == BT_ERROR_NONE) {
634 TC_PRT("Total number of AppKeys bound to the model [%d]", total);
635 print_model_handle(model);
637 for (l = sub_addr; l != NULL; l = l->next) {
638 bt_mesh_group_h group = (bt_mesh_group_h) l->data;
639 print_group_handle(group);
645 void __bt_mesh_model_publication_status_cb(int result, bt_mesh_model_h model, bt_mesh_group_h group,
646 bt_mesh_appkey_h appkey, void *user_data)
648 TC_PRT("bt_mesh_model_publication_status_cb");
649 TC_PRT("result: %s", __bt_get_error_message(result));
651 if (result == BT_ERROR_NONE) {
652 print_model_handle(model);
653 print_group_handle(group);
654 print_appkey_handle(appkey);
658 void __bt_mesh_network_create_cb(int result, bt_mesh_network_h network, const char *network_name, void *user_data)
660 TC_PRT("bt_mesh_network_create_cb");
661 TC_PRT("result: %s", __bt_get_error_message(result));
662 print_network_handle(network);
665 bool __bt_mesh_appkey_info_cb(int result, bt_mesh_network_h network, int total,
666 bt_mesh_netkey_h netkey, bt_mesh_appkey_h appkey, uint16_t appkey_index, void *user_data)
668 TC_PRT("bt_mesh_network_appkey_info_cb");
669 TC_PRT("result: %s", __bt_get_error_message(result));
670 //print_network_handle(network);
671 //print_netkey_handle(netkey);
672 print_appkey_handle(appkey);
673 TC_PRT("Total appkeys are [%d]",total);
677 bool __bt_mesh_network_netkey_info_cb(int result, bt_mesh_network_h network, int total,
678 bt_mesh_netkey_h netkey, uint16_t netkey_index, void *user_data)
680 TC_PRT("bt_mesh_network_netkey_info_cb");
681 TC_PRT("result: %s", __bt_get_error_message(result));
682 //print_network_handle(network);
683 print_netkey_handle(netkey);
684 TC_PRT("Total netkeys are [%d]",total);
685 if (result == BT_ERROR_NONE && netkey_index == 0) {
686 TC_PRT("Attempt to delete Primary Subnet");
687 result = bt_mesh_netkey_delete(netkey);
688 TC_PRT("return %s\n", __bt_get_error_message(result));
689 if (result == BT_ERROR_NONE)
690 TC_PRT("Primary netkey is deleted");
692 TC_PRT("Primary NetKey deletion failed");
697 void __bt_mesh_network_scan_unprovisioned_device_result_cb(int result, bt_mesh_network_h network,
698 bt_mesh_scanning_state_e state, bt_mesh_scan_result_s *scan_res, void *user_data)
700 TC_PRT("bt_mesh_network_scan_unprovisioned_device_result_cb");
701 TC_PRT("result: %s", __bt_get_error_message(result));
702 if (state == BT_MESH_SCANNING_STARTED) {
703 TC_PRT("The scanning state is: STARTED");
704 print_network_handle(network);
706 else if (state == BT_MESH_SCANNING_FINISHED) {
707 TC_PRT("The scanning state is: STOPPED");
708 print_network_handle(network);
711 TC_PRT("Scan Result found");
712 TC_PRT("Device UUID is %s\n", scan_res->uuid);
713 TC_PRT("RSSI values is %d\n", scan_res->rssi);
714 TC_PRT("OOB Info 0x%x\n", scan_res->oob_info);
718 void __bt_mesh_network_device_provision_cb(int result, bt_mesh_network_h network,
719 const char* dev_uuid, void* user_data)
721 TC_PRT("bt_mesh_network_device_provision_cb");
722 TC_PRT("result: %s", __bt_get_error_message(result));
723 print_network_handle(network);
725 TC_PRT("dev_uuid is NULL");
727 TC_PRT("The device_uuid is [%s]", dev_uuid);
728 device_uuid = g_strdup(dev_uuid);
732 void __bt_mesh_authentication_request_cb(int result, bt_mesh_authentication_type_e auth_type,
733 char *auth_value, void *user_data)
735 TC_PRT("bt_mesh_authentication_request_cb");
736 TC_PRT("result: %s", __bt_get_error_message(result));
737 TC_PRT("auth_value is [%s]", auth_value);
738 TC_PRT("auth_type is [%d]", auth_type);
739 request_type = auth_type;
742 int test_set_params(int test_id, char *param){
743 static int param_index = 0;
746 if (param_index > 0 && param_index == g_test_param.param_count)
748 switch (current_tc_table) {
749 case BT_MESH_UNIT_TEST_TABLE_NETWORK: {
751 case BT_MESH_UNIT_TEST_FUNCTION_NETWORK_CREATE:
753 switch(param_index) {
755 TC_PRT("Input param(%d) (network_name)\n",param_index + 1);
758 TC_PRT("Input param(%d) (Node Handle)\n",param_index + 1);
762 case BT_MESH_UNIT_TEST_FUNCTION_NETWORK_CREATE_IN_LOOP:
764 TC_PRT("Input param(%d) (Number of networks)\n",param_index + 1);
766 case BT_MESH_UNIT_TEST_FUNCTION_NETWORK_DESTROY:
768 TC_PRT("Input param(%d) (network_handle)\n",param_index + 1);
770 case BT_MESH_UNIT_TEST_FUNCTION_NODE_DESTROY:
772 TC_PRT("Input param(%d) (node Handle)\n",param_index + 1);
774 case BT_MESH_UNIT_TEST_FUNCTION_NODE_GET_NETWORK:
776 TC_PRT("Input param(%d) (node Handle)\n",param_index + 1);
778 case BT_MESH_UNIT_TEST_FUNCTION_NODE_CREATE_ELEMENT:
780 TC_PRT("Input param(%d) (node Handle)\n",param_index + 1);
782 case BT_MESH_UNIT_TEST_FUNCTION_ELEMENT_CREATE_MODEL:
784 switch(param_index) {
786 TC_PRT("Input param(%d) (Element Handle)\n" ,param_index + 1);
789 TC_PRT("Input param(%d) (Model ID)\n",param_index + 1);
793 case BT_MESH_UNIT_TEST_FUNCTION_ELEMENT_GET_NODE:
795 TC_PRT("Input param(%d) (Element Handle)\n",param_index + 1);
797 case BT_MESH_UNIT_TEST_FUNCTION_MODEL_GET_ID:
799 TC_PRT("Input param(%d) (Model Handle)\n",param_index + 1);
801 case BT_MESH_UNIT_TEST_FUNCTION_MODEL_DESTROY:
803 TC_PRT("Input param(%d) (Model Handle)\n",param_index + 1);
805 case BT_MESH_UNIT_TEST_FUNCTION_MODEL_GET_ELEMENT:
807 TC_PRT("Input param(%d) (Model Handle)\n",param_index + 1);
809 case BT_MESH_UNIT_TEST_FUNCTION_ELEMENT_DESTROY:
811 TC_PRT("Input param(%d) (Element Handle)\n",param_index + 1);
813 case BT_MESH_UNIT_TEST_FUNCTION_NODE_FOREACH_ELEMENTS:
815 TC_PRT("Input param(%d) (Node Handle)", param_index + 1);
817 case BT_MESH_UNIT_TEST_FUNCTION_ELEMENT_FOREACH_MODELS:
819 TC_PRT("Input param(%d) (Element Handle)", param_index + 1);
821 case BT_MESH_UNIT_TEST_FUNCTION_NETWORK_CREATE_GROUP:
823 TC_PRT("Input param(%d) (group address)\n" ,param_index + 1);
825 case BT_MESH_UNIT_TEST_FUNCTION_NETWORK_REMOVE_GROUP:
827 TC_PRT("Input param(%d) (group handle)\n" ,param_index + 1);
829 case BT_MESH_UNIT_TEST_FUNCTION_NETWORK_UNPROVISIONED_DEVICE_SCAN:
831 TC_PRT("Input param(%d) (Seconds)\n" ,param_index + 1);
833 case BT_MESH_UNIT_TEST_FUNCTION_NETWORK_PROVISION_DEVICE:
835 TC_PRT("Input param(%d) (device_uuid)\n",param_index+1);
837 case BT_MESH_UNIT_TEST_FUNCTION_NETWORK_SET_NAME:
839 TC_PRT("Input param(%d) (network_name)",param_index + 1);
841 case BT_MESH_UNIT_TEST_FUNCTION_MESH_AUTHENTICATION_REPLY:
843 switch(param_index) {
845 TC_PRT("Input param(%d) (auth_value)\n",param_index +1);
848 TC_PRT("Input param(%d) (auth_reply)\n",param_index + 1);
849 TC_PRT("0: false, 1: true");
853 case BT_MESH_UNIT_TEST_FUNCTION_NETWORK_SET_PROVISIONING_CAPABILITIES:
855 switch(param_index) {
857 TC_PRT("\nInput param(%d) is_public_oob",param_index + 1);
858 TC_PRT("0: false, 1: true\n");
861 TC_PRT("\nInput param(%d) is_static_oob",param_index + 1);
862 TC_PRT("0: false, 1 : true\n");
865 TC_PRT("\nInput param(%d) output_oob",param_index + 1);
866 TC_PRT("BT_MESH_OUT_OOB_METHOD_BLINK = 0x01");
867 TC_PRT("BT_MESH_OUT_OOB_METHOD_BEEP = 0x02");
868 TC_PRT("BT_MESH_OUT_OOB_METHOD_VIBRATE = 0x04");
869 TC_PRT("BT_MESH_OUT_OOB_METHOD_NUMERIC = 0x08");
870 TC_PRT("BT_MESH_OUT_OOB_METHOD_ALPHANUMERIC = 0x10\n");
873 TC_PRT("\nInput param(%d) input_oob",param_index + 1);
874 TC_PRT("BT_MESH_IN_OOB_METHOD_PUSH = 0x01");
875 TC_PRT("BT_MESH_IN_OOB_METHOD_TWIST = 0x02");
876 TC_PRT("BT_MESH_IN_OOB_METHOD_NUMERIC = 0x04");
877 TC_PRT("BT_MESH_IN_OOB_METHOD_ALPHANUMERIC = 0x08\n");
881 case BT_MESH_UNIT_TEST_FUNCTION_NETKEY_GET_INDEX:
883 TC_PRT("Input param(%d) (NetKey Handle)", param_index + 1);
885 case BT_MESH_UNIT_TEST_FUNCTION_NETKEY_UPDATE:
887 TC_PRT("Input param(%d) (NetKey Handle)", param_index + 1);
889 case BT_MESH_UNIT_TEST_FUNCTION_NETKEY_DELETE:
891 TC_PRT("Input param(%d) (NetKey Handle)", param_index + 1);
893 case BT_MESH_UNIT_TEST_FUNCTION_NETKEY_ADD_APPKEY:
895 TC_PRT("Input param(%d) (NetKey Handle)", param_index + 1);
897 case BT_MESH_UNIT_TEST_FUNCTION_NETKEY_FOREACH_APPKEYS:
899 TC_PRT("Input param(%d) (NetKey Handle)", param_index + 1);
901 case BT_MESH_UNIT_TEST_FUNCTION_APPKEY_GET_INDEX:
903 TC_PRT("Input param(%d) (AppKey Handle)", param_index + 1);
905 case BT_MESH_UNIT_TEST_FUNCTION_APPKEY_UPDATE:
907 TC_PRT("Input param(%d) (AppKey Handle)", param_index + 1);
909 case BT_MESH_UNIT_TEST_FUNCTION_APPKEY_DELETE:
911 TC_PRT("Input param(%d) (AppKey Handle)", param_index + 1);
913 case BT_MESH_UNIT_TEST_FUNCTION_ACTIVATE_FLAG_TO_SET_PARAMETERS:
914 need_to_set_params = true;
915 TC_PRT("\nSelect the function again\n");
918 TC_PRT("There is no parameter to set\n");
923 case BT_MESH_UNIT_TEST_TABLE_CONFIGURATION: {
925 case BT_MESH_UNIT_TEST_FUNCTION_MESH_NETWORK_DISCOVER_NODE:
927 TC_PRT("Input param(%d) (device_uuid)", param_index + 1);
929 case BT_MESH_UNIT_TEST_FUNCTION_NODE_GET_FEATURES:
931 TC_PRT("Input param(%d) (Node Handle)", param_index + 1);
933 case BT_MESH_UNIT_TEST_FUNCTION_NODE_GET_NETKEYS:
935 TC_PRT("Input param(%d) (Node Handle)", param_index + 1);
937 case BT_MESH_UNIT_TEST_FUNCTION_NODE_GET_APPKEYS:
939 switch(param_index) {
941 TC_PRT("Input param(%d) (Node Handle)", param_index + 1);
944 TC_PRT("Input param(%d) (Netkey Handle)\n", param_index + 1);
948 case BT_MESH_UNIT_TEST_FUNCTION_APPKEY_GET_NETKEY:
950 TC_PRT("Input param(%d) (AppKey Handle)\n", param_index + 1);
952 case BT_MESH_UNIT_TEST_FUNCTION_MODEL_GET_PUBLICATION:
954 TC_PRT("Input param(%d) (Model Handle)\n", param_index + 1);
956 case BT_MESH_UNIT_TEST_FUNCTION_MODEL_SEND_MSG:
958 switch(param_index) {
960 TC_PRT("Input param(%d) (Model Handle)\n", param_index + 1);
963 TC_PRT("Input param(%d) (Appkey Handle)\n", param_index + 1);
966 TC_PRT("Input param(%d) (opcode)\n", param_index + 1);
969 TC_PRT("Input param(%d) (Message)\n", param_index + 1);
973 case BT_MESH_UNIT_TEST_FUNCTION_MODEL_SET_PUBLICATION:
975 switch(param_index) {
977 TC_PRT("\nInput param(%d) Model handle\n", param_index + 1);
980 TC_PRT("\nInput param(%d) AppKey handle\n", param_index + 1);
983 TC_PRT("\nInput param(%d) Group Handle\n", param_index + 1);
987 case BT_MESH_UNIT_TEST_FUNCTION_MODEL_GET_SUBSCRIPTION_LIST:
989 TC_PRT("Input param(%d) (Model Handle)\n", param_index + 1);
991 case BT_MESH_UNIT_TEST_FUNCTION_MODEL_CONFIGURE_GROUP_SUBSCRIPTION:
992 case BT_MESH_UNIT_TEST_FUNCTION_MODEL_CONFIGURE_VIRTUAL_GROUP_SUBSCRIPTION:
994 switch(param_index) {
996 TC_PRT("\nInput param(%d) Model handle\n", param_index + 1);
999 TC_PRT("\nInput param(%d) Model operation", param_index + 1);
1000 TC_PRT("BT_MESH_MODEL_SUBSCRIPTION_ADD = 0");
1001 TC_PRT("BT_MESH_MODEL_SUBSCRIPTION_DELETE = 1");
1002 TC_PRT("BT_MESH_MODEL_SUBSCRIPTION_DELETE_ALL = 2");
1003 TC_PRT("BT_MESH_MODEL_SUBSCRIPTION_OVERWRITE = 3\n");
1006 TC_PRT("\nInput param(%d) Group Handle\n", param_index + 1);
1010 case BT_MESH_UNIT_TEST_FUNCTION_MODEL_GET_APPKEY_LIST:
1012 TC_PRT("Input param(%d) (Model Handle)\n", param_index + 1);
1014 case BT_MESH_UNIT_TEST_FUNCTION_MODEL_BIND_APPKEY:
1015 case BT_MESH_UNIT_TEST_FUNCTION_MODEL_UNBIND_APPKEY:
1017 switch(param_index) {
1019 TC_PRT("\nInput param(%d) Model Handle\n", param_index + 1);
1022 TC_PRT("\nInput param(%d) AppKey handle\n", param_index + 1);
1026 case BT_MESH_UNIT_TEST_FUNCTION_NODE_CONFIGURE_NETKEY:
1027 case BT_MESH_UNIT_TEST_FUNCTION_NODE_CONFIGURE_APPKEY:
1029 switch(param_index) {
1031 TC_PRT("\nInput param(%d) Node Handle\n", param_index + 1);
1034 TC_PRT("\nInput param(%d) Key Handle\n", param_index + 1);
1037 TC_PRT("\nInput param(%d) Key Config Option", param_index + 1);
1038 TC_PRT("BT_MESH_NODE_KEY_ADD = 0");
1039 TC_PRT("BT_MESH_NODE_KEY_UPDATE = 1");
1040 TC_PRT("BT_MESH_NODE_KEY_DELETE = 2\n");
1044 case BT_MESH_UNIT_TEST_FUNCTION_NODE_GET_TTL:
1046 TC_PRT("\nInput param(%d) Node Handle\n", param_index + 1);
1048 case BT_MESH_UNIT_TEST_FUNCTION_NODE_SET_TTL:
1050 switch(param_index) {
1052 TC_PRT("\nInput param(%d) Node Handle\n", param_index + 1);
1055 TC_PRT("\nInput param(%d) TTL value\n", param_index + 1);
1060 TC_PRT("There is no parameter to set\n");
1066 TC_PRT("There is no parameter to set\n");
1067 need_to_set_params = false;
1071 if (need_to_set_params) {
1072 if (param_index == 0) {
1073 g_test_param.param_count = param_count;
1074 g_test_param.params = g_malloc0(sizeof(char*) * g_test_param.param_count);
1077 if (param_index > 0) {
1078 int len = strlen(param);
1079 param[len - 1] = '\0';
1080 g_test_param.params[param_index - 1] = g_strdup(param);
1083 if (param_index == g_test_param.param_count) {
1084 need_to_set_params = false;
1086 test_input_callback((void *)(uintptr_t)test_id);
1088 test_input_callback((void *)test_id);
1100 int test_input_callback(void *data)
1104 int test_id = (uintptr_t)data;
1106 int test_id = (int)data;
1109 switch (current_tc_table) {
1110 case BT_MESH_UNIT_TEST_TABLE_MAIN: {
1113 TC_PRT("Finished\n");
1114 g_main_loop_quit(main_loop);
1116 case BT_MESH_UNIT_TEST_FUNCTION_INITIALIZE:
1117 ret = bt_mesh_initialize();
1118 TC_PRT("return %s\n", __bt_get_error_message(ret));
1120 case BT_MESH_UNIT_TEST_FUNCTION_DEINITIALIZE:
1121 ret = bt_mesh_deinitialize();
1122 TC_PRT("return %s\n", __bt_get_error_message(ret));
1129 case BT_MESH_UNIT_TEST_TABLE_NETWORK:{
1131 case BT_MESH_UNIT_TEST_FUNCTION_NODE_CREATE:{
1132 bt_mesh_node_features_s features;
1133 features.features = BT_MESH_FEATURE_RELAY;
1134 features.features |= BT_MESH_FEATURE_LOWPOWER;
1136 ret = bt_mesh_node_create(&features, &local_node);
1137 TC_PRT("return %s\n", __bt_get_error_message(ret));
1138 if (ret == BT_ERROR_NONE)
1139 print_node_handle(local_node);
1142 case BT_MESH_UNIT_TEST_FUNCTION_NODE_DESTROY: {
1143 bt_mesh_node_h node_h;
1144 if (g_test_param.param_count != 1) {
1145 TC_PRT("Enter parameters first!");
1148 node_h = GUINT_TO_POINTER(strtoul(g_test_param.params[0], NULL, 16));
1149 ret = bt_mesh_node_destroy(node_h);
1150 TC_PRT("return %s\n", __bt_get_error_message(ret));
1153 case BT_MESH_UNIT_TEST_FUNCTION_NODE_GET_NETWORK: {
1154 bt_mesh_network_h net_h;
1155 bt_mesh_node_h node_h;
1156 if (g_test_param.param_count != 1) {
1157 TC_PRT("Enter parameters first!");
1160 node_h = GUINT_TO_POINTER(strtoul(g_test_param.params[0], NULL, 16));
1161 ret = bt_mesh_node_get_network(node_h, &net_h);
1162 TC_PRT("return %s\n", __bt_get_error_message(ret));
1163 if (ret == BT_ERROR_NONE)
1164 print_network_handle(net_h);
1167 case BT_MESH_UNIT_TEST_FUNCTION_NODE_CREATE_ELEMENT: {
1168 bt_mesh_element_h elem_h;
1169 bt_mesh_node_h node_h;
1170 if (g_test_param.param_count != 1) {
1171 TC_PRT("Enter parameters first!");
1174 node_h = GUINT_TO_POINTER(strtoul(g_test_param.params[0], NULL, 16));
1175 ret = bt_mesh_node_create_element(node_h, &elem_h);
1176 TC_PRT("return %s\n", __bt_get_error_message(ret));
1177 if (ret == BT_ERROR_NONE)
1178 print_element_handle(elem_h);
1181 case BT_MESH_UNIT_TEST_FUNCTION_ELEMENT_CREATE_MODEL: {
1182 bt_mesh_element_h elem_h;
1183 bt_mesh_model_h model_h;
1184 bt_mesh_model_id_s mod_id;
1185 memset(&mod_id, 0x00, sizeof(bt_mesh_model_id_s));
1187 if (g_test_param.param_count != 2) {
1188 TC_PRT("Enter parameters first!");
1191 elem_h = GUINT_TO_POINTER(strtoul(g_test_param.params[0], NULL, 16));
1192 mod_id.model_id = strtoul(g_test_param.params[1], NULL, 16);
1193 mod_id.company_id = 0xFFFF;
1194 TC_PRT("The model_id is [0x%2.2x]\n", mod_id.model_id);
1195 ret = bt_mesh_element_create_model(elem_h, &mod_id, &model_h);
1196 TC_PRT("return %s\n", __bt_get_error_message(ret));
1197 if (ret == BT_ERROR_NONE)
1198 print_model_handle(model_h);
1201 case BT_MESH_UNIT_TEST_FUNCTION_ELEMENT_GET_NODE: {
1202 bt_mesh_element_h elem_h;
1203 bt_mesh_node_h node_h;
1204 if (g_test_param.param_count != 1) {
1205 TC_PRT("Enter parameter first!");
1208 elem_h = GUINT_TO_POINTER(strtoul(g_test_param.params[0], NULL, 16));
1209 ret = bt_mesh_element_get_node(elem_h, &node_h);
1210 TC_PRT("return %s\n", __bt_get_error_message(ret));
1212 if (ret == BT_ERROR_NONE)
1213 print_node_handle(node_h);
1216 case BT_MESH_UNIT_TEST_FUNCTION_MODEL_GET_ID: {
1217 bt_mesh_model_id_s model_id;
1218 memset(&model_id, 0x00, sizeof(bt_mesh_model_id_s));
1219 bt_mesh_model_h mod_h;
1220 if (g_test_param.param_count != 1) {
1221 TC_PRT("Enter parameter first!");
1224 mod_h = GUINT_TO_POINTER(strtoul(g_test_param.params[0], NULL, 16));
1225 ret = bt_mesh_model_get_id(mod_h, &model_id);
1226 TC_PRT("return %s\n", __bt_get_error_message(ret));
1227 if (ret == BT_ERROR_NONE) {
1228 TC_PRT("The Model ID is [0x%2.2x]", model_id.model_id);
1229 TC_PRT("The Company ID is [0x%2.2x]", model_id.company_id);
1233 case BT_MESH_UNIT_TEST_FUNCTION_MODEL_DESTROY: {
1234 bt_mesh_model_h mod_h;
1235 if (g_test_param.param_count != 1) {
1236 TC_PRT("Enter parameter first!");
1239 mod_h = GUINT_TO_POINTER(strtoul(g_test_param.params[0], NULL, 16));
1240 ret = bt_mesh_model_destroy(mod_h);
1241 TC_PRT("return %s\n", __bt_get_error_message(ret));
1244 case BT_MESH_UNIT_TEST_FUNCTION_MODEL_GET_ELEMENT: {
1245 bt_mesh_model_h mod_h;
1246 bt_mesh_element_h elem_h;
1247 if (g_test_param.param_count != 1) {
1248 TC_PRT("Enter parameter first!");
1251 mod_h = GUINT_TO_POINTER(strtoul(g_test_param.params[0], NULL, 16));
1252 ret = bt_mesh_model_get_element(mod_h, &elem_h);
1253 TC_PRT("return %s\n", __bt_get_error_message(ret));
1254 if (ret == BT_ERROR_NONE)
1255 print_element_handle(elem_h);
1258 case BT_MESH_UNIT_TEST_FUNCTION_ELEMENT_DESTROY: {
1259 bt_mesh_element_h elem_h;
1260 if (g_test_param.param_count != 1) {
1261 TC_PRT("Enter parameter first!");
1264 elem_h = GUINT_TO_POINTER(strtoul(g_test_param.params[0], NULL, 16));
1265 ret = bt_mesh_element_destroy(elem_h);
1266 TC_PRT("return %s\n", __bt_get_error_message(ret));
1269 case BT_MESH_UNIT_TEST_FUNCTION_NODE_FOREACH_ELEMENTS: {
1270 bt_mesh_node_h node_h = 0;
1271 if (g_test_param.param_count != 1){
1272 TC_PRT("Enter Input parameter first.\n");
1275 node_h = GUINT_TO_POINTER(strtoul(g_test_param.params[0], NULL, 16));
1276 ret = bt_mesh_node_foreach_element(node_h, __bt_mesh_node_foreach_elem_cb, NULL);
1277 TC_PRT("return %s\n", __bt_get_error_message(ret));
1280 case BT_MESH_UNIT_TEST_FUNCTION_ELEMENT_FOREACH_MODELS: {
1281 bt_mesh_element_h element_h = 0;
1282 if (g_test_param.param_count != 1){
1283 TC_PRT("Enter Input parameter first.\n");
1286 element_h = GUINT_TO_POINTER(strtoul(g_test_param.params[0], NULL, 16));
1287 ret = bt_mesh_element_foreach_models(element_h, __bt_mesh_elem_foreach_model_cb, NULL);
1288 TC_PRT("return %s\n", __bt_get_error_message(ret));
1291 case BT_MESH_UNIT_TEST_FUNCTION_NETWORK_CREATE: {
1292 char* network_name = "Mesh Test Network";
1293 bt_mesh_node_h node_h;
1294 if (g_test_param.param_count != 2) {
1295 TC_PRT("Enter Input parameter first.\n");
1298 network_name = g_strdup(g_test_param.params[0]);
1299 node_h = GUINT_TO_POINTER(strtoul(g_test_param.params[1], NULL, 16));
1300 ret = bt_mesh_network_create(node_h, (const char*)network_name, &network, &token);
1301 TC_PRT("return %s\n", __bt_get_error_message(ret));
1302 if (ret == BT_ERROR_NONE) {
1303 TC_PRT("Network Created, token [%s]", token);
1304 print_network_handle(network);
1306 g_free(network_name);
1309 case BT_MESH_UNIT_TEST_FUNCTION_NETWORK_CREATE_IN_LOOP: {
1310 char* network_name = "Mesh Test Network";
1312 if (g_test_param.param_count != 1) {
1313 TC_PRT("Enter Input parameter first.\n");
1316 int num = atoi(g_test_param.params[0]);
1317 TC_PRT("Create [%d] Networks", num);
1318 for (int i = 0; i < num; i++) {
1320 bt_mesh_node_h node_h;
1321 bt_mesh_node_features_s features;
1322 features.features = BT_MESH_FEATURE_RELAY;
1323 features.features |= BT_MESH_FEATURE_LOWPOWER;
1325 ret = bt_mesh_node_create(&features, &node_h);
1326 TC_PRT("return %s\n", __bt_get_error_message(ret));
1327 if (ret == BT_ERROR_NONE) {
1328 print_node_handle(node_h);
1330 TC_PRT("Node Creation Failed!");
1334 /* Create Element */
1335 bt_mesh_element_h elem_h;
1336 ret = bt_mesh_node_create_element(node_h, &elem_h);
1337 TC_PRT("return %s\n", __bt_get_error_message(ret));
1338 if (ret == BT_ERROR_NONE) {
1339 print_element_handle(elem_h);
1341 TC_PRT("Element Creation Failed!");
1346 bt_mesh_model_h model_h;
1347 bt_mesh_model_id_s mod_id;
1348 memset(&mod_id, 0x00, sizeof(bt_mesh_model_id_s));
1350 mod_id.model_id = 0x0003;
1351 mod_id.company_id = 0xFFFF;
1352 TC_PRT("The model_id is [0x%2.2x]\n", mod_id.model_id);
1353 ret = bt_mesh_element_create_model(elem_h, &mod_id, &model_h);
1354 TC_PRT("return %s\n", __bt_get_error_message(ret));
1355 if (ret == BT_ERROR_NONE) {
1356 print_model_handle(model_h);
1358 TC_PRT("Model Creation Failed!");
1362 /* Create Network */
1363 network_name = g_strdup_printf("TestMeshNet%d", i);
1364 bt_mesh_network_h net_h;
1366 ret = bt_mesh_network_create(node_h, (const char*)network_name, &net_h, &token);
1367 TC_PRT("return %s\n", __bt_get_error_message(ret));
1368 if (ret == BT_ERROR_NONE) {
1369 TC_PRT("Network Created, token [%s] Network Number[%d]", token, i);
1370 print_network_handle(network);
1372 TC_PRT("Network Creation Failed!");
1375 g_free(network_name);
1377 /* Destroy Network */
1378 ret = bt_mesh_network_destroy(net_h);
1379 TC_PRT("return %s\n", __bt_get_error_message(ret));
1380 if (ret == BT_ERROR_NONE) {
1381 TC_PRT("Network Destroyed Successfully!");
1383 TC_PRT("Network Destroy Failed!!....break out");
1389 case BT_MESH_UNIT_TEST_FUNCTION_NETWORK_DESTROY: {
1390 bt_mesh_network_h network_h;
1391 if (g_test_param.param_count != 1) {
1392 TC_PRT("Enter parameters first!");
1395 network_h = GUINT_TO_POINTER(strtoul(g_test_param.params[0], NULL, 16));
1396 ret = bt_mesh_network_destroy(network_h);
1397 TC_PRT("return %s\n", __bt_get_error_message(ret));
1400 case BT_MESH_UNIT_TEST_FUNCTION_NETWORK_LOAD: {
1402 if (g_test_param.param_count != 1) {
1403 TC_PRT("Enter parameter first!");
1406 token_str = g_strdup(g_test_param.params[0]);
1407 ret = bt_mesh_network_load(token_str, &network);
1408 TC_PRT("return %s\n", __bt_get_error_message(ret));
1409 if (ret == BT_ERROR_NONE)
1410 print_network_handle(network);
1414 case BT_MESH_UNIT_TEST_FUNCTION_NETWORK_SET_NAME: {
1415 char* network_name="tempName";
1416 if (g_test_param.param_count != 1) {
1417 TC_PRT("Enter parameter first!");
1420 network_name = g_strdup(g_test_param.params[0]);
1421 ret = bt_mesh_network_set_name(network,(const char*)network_name);
1422 TC_PRT("return %s\n", __bt_get_error_message(ret));
1423 g_free(network_name);
1426 case BT_MESH_UNIT_TEST_FUNCTION_NETWORK_GET_NAME: {
1428 ret = bt_mesh_network_get_name(network, &network_name);
1429 TC_PRT("return %s\n", __bt_get_error_message(ret));
1430 if (ret == BT_ERROR_NONE)
1431 TC_PRT("network name is [%s]", network_name);
1434 case BT_MESH_UNIT_TEST_FUNCTION_NETWORK_ADD_NETKEY: {
1436 bt_mesh_netkey_h n_h;
1437 ret = bt_mesh_network_add_netkey(network, &n_h);
1438 TC_PRT("return %s\n", __bt_get_error_message(ret));
1439 if (ret == BT_ERROR_NONE)
1440 print_netkey_handle(n_h);
1443 case BT_MESH_UNIT_TEST_FUNCTION_NETWORK_FOREACH_NETKEYS: {
1444 ret = bt_mesh_network_foreach_netkeys(network,
1445 __bt_mesh_network_netkey_info_cb, NULL);
1446 TC_PRT("return %s\n", __bt_get_error_message(ret));
1449 case BT_MESH_UNIT_TEST_FUNCTION_NETKEY_GET_INDEX: {
1450 uint16_t index = 0xFFFF;
1451 bt_mesh_netkey_h netkey_h;
1453 if (g_test_param.param_count != 1) {
1454 TC_PRT("Set parameter first!");
1457 netkey_h = GUINT_TO_POINTER(strtoul(g_test_param.params[0], NULL, 16));
1458 /* Get index for netkey 1 */
1459 ret = bt_mesh_netkey_get_index(netkey_h, &index);
1460 TC_PRT("return %s\n", __bt_get_error_message(ret));
1461 if (ret == BT_ERROR_NONE)
1462 TC_PRT("The index of the netkey is: [%d]", index);
1466 case BT_MESH_UNIT_TEST_FUNCTION_NETKEY_UPDATE: {
1467 bt_mesh_netkey_h netkey_h;
1469 if (g_test_param.param_count != 1) {
1470 TC_PRT("Set parameter first!");
1473 netkey_h = GUINT_TO_POINTER(strtoul(g_test_param.params[0], NULL, 16));
1474 ret = bt_mesh_netkey_update(netkey_h);
1475 TC_PRT("return %s\n", __bt_get_error_message(ret));
1478 case BT_MESH_UNIT_TEST_FUNCTION_NETKEY_DELETE: {
1479 bt_mesh_netkey_h netkey_h;
1481 if (g_test_param.param_count != 1) {
1482 TC_PRT("Set parameter first!");
1485 netkey_h = GUINT_TO_POINTER(strtoul(g_test_param.params[0], NULL, 16));
1486 ret = bt_mesh_netkey_delete(netkey_h);
1487 TC_PRT("return %s\n", __bt_get_error_message(ret));
1488 if (ret == BT_ERROR_NONE)
1489 TC_PRT("netkey is deleted");
1492 case BT_MESH_UNIT_TEST_FUNCTION_NETKEY_ADD_APPKEY: {
1493 bt_mesh_netkey_h netkey_h;
1494 bt_mesh_appkey_h appkey_h;
1496 if (g_test_param.param_count != 1) {
1497 TC_PRT("Set parameter first!");
1500 netkey_h = GUINT_TO_POINTER(strtoul(g_test_param.params[0], NULL, 16));
1501 ret = bt_mesh_netkey_add_appkey(netkey_h, &appkey_h);
1502 TC_PRT("return %s\n", __bt_get_error_message(ret));
1503 if (ret == BT_ERROR_NONE)
1504 print_appkey_handle(appkey_h);
1507 case BT_MESH_UNIT_TEST_FUNCTION_NETKEY_FOREACH_APPKEYS: {
1508 /* Get all appkeys for NetKey 1 */
1509 bt_mesh_netkey_h netkey_h;
1511 if (g_test_param.param_count != 1) {
1512 TC_PRT("Set parameter first!");
1515 netkey_h = GUINT_TO_POINTER(strtoul(g_test_param.params[0], NULL, 16));
1516 ret = bt_mesh_netkey_foreach_appkeys(netkey_h, __bt_mesh_appkey_info_cb, NULL);
1517 TC_PRT("return %s\n", __bt_get_error_message(ret));
1521 case BT_MESH_UNIT_TEST_FUNCTION_APPKEY_GET_INDEX: {
1522 uint16_t index = 0xFFFF;
1523 bt_mesh_appkey_h appkey_h;
1525 if (g_test_param.param_count != 1) {
1526 TC_PRT("Set parameter first!");
1529 appkey_h = GUINT_TO_POINTER(strtoul(g_test_param.params[0], NULL, 16));
1530 /* Get appkey index for appkey 1 */
1531 ret = bt_mesh_appkey_get_index(appkey_h, &index);
1532 TC_PRT("return %s\n", __bt_get_error_message(ret));
1533 if (ret == BT_ERROR_NONE)
1534 TC_PRT("The index of the appkey is: [%d]", index);
1537 case BT_MESH_UNIT_TEST_FUNCTION_APPKEY_UPDATE: {
1538 bt_mesh_appkey_h appkey_h;
1540 if (g_test_param.param_count != 1) {
1541 TC_PRT("Set parameter first!");
1544 appkey_h = GUINT_TO_POINTER(strtoul(g_test_param.params[0], NULL, 16));
1545 ret = bt_mesh_appkey_update(appkey_h);
1546 TC_PRT("return %s\n", __bt_get_error_message(ret));
1549 case BT_MESH_UNIT_TEST_FUNCTION_APPKEY_DELETE: {
1550 bt_mesh_appkey_h appkey_h;
1552 if (g_test_param.param_count != 1) {
1553 TC_PRT("Set parameter first!");
1556 appkey_h = GUINT_TO_POINTER(strtoul(g_test_param.params[0], NULL, 16));
1557 ret = bt_mesh_appkey_delete(appkey_h);
1558 TC_PRT("return %s\n", __bt_get_error_message(ret));
1559 if (ret == BT_ERROR_NONE)
1560 TC_PRT("appkey is deleted");
1563 case BT_MESH_UNIT_TEST_FUNCTION_NETWORK_FOREACH_DEVICES: {
1564 ret = bt_mesh_network_foreach_devices(network, __bt_mesh_network_device_info_cb, NULL);
1565 TC_PRT("return %s\n", __bt_get_error_message(ret));
1568 case BT_MESH_UNIT_TEST_FUNCTION_NETWORK_CREATE_GROUP: {
1569 uint16_t group_addr = 0xc001;
1570 bt_mesh_group_h group_h;
1571 if (g_test_param.param_count != 1) {
1572 TC_PRT("Enter parameter first!!\n");
1575 group_addr = strtoul(g_test_param.params[0], NULL, 16);
1576 TC_PRT("Group addrrss [0x%2.2x]", group_addr);
1577 ret = bt_mesh_network_create_group(network, group_addr, &group_h);
1578 TC_PRT("return %s\n", __bt_get_error_message(ret));
1579 if (ret == BT_ERROR_NONE)
1580 print_group_handle(group_h);
1583 case BT_MESH_UNIT_TEST_FUNCTION_NETWORK_CREATE_VIRTUAL_GROUP: {
1584 bt_mesh_group_h group_h;
1585 ret = bt_mesh_network_create_virtual_group(network, &group_h);
1586 TC_PRT("return %s\n", __bt_get_error_message(ret));
1587 if (ret == BT_ERROR_NONE)
1588 print_group_handle(group_h);
1591 case BT_MESH_UNIT_TEST_FUNCTION_NETWORK_REMOVE_GROUP: {
1592 bt_mesh_group_h group_h;
1593 if (g_test_param.param_count != 1) {
1594 TC_PRT("Enter parameter first!!\n");
1597 group_h = GUINT_TO_POINTER(strtoul(g_test_param.params[0], NULL, 16));
1598 ret = bt_mesh_network_remove_group(group_h);
1599 TC_PRT("return %s\n", __bt_get_error_message(ret));
1602 case BT_MESH_UNIT_TEST_FUNCTION_NETWORK_FOREACH_GROUPS: {
1603 ret = bt_mesh_network_foreach_groups(network,
1604 __bt_mesh_network_group_info_cb, NULL);
1605 TC_PRT("return %s\n", __bt_get_error_message(ret));
1608 case BT_MESH_UNIT_TEST_FUNCTION_NETWORK_UNPROVISIONED_DEVICE_SCAN: {
1609 bt_mesh_scan_params_s scan_params;
1610 memset(&scan_params, 0x00, sizeof(bt_mesh_scan_params_s));
1611 if(g_test_param.param_count != 1) {
1612 TC_PRT("Enter Input parameter first.\n");
1615 scan_params.seconds = strtoul(g_test_param.params[0], NULL, 16);
1616 TC_PRT("The scan is set for [%u] seconds", scan_params.seconds);
1617 ret = bt_mesh_network_unprovisioned_device_scan(network, &scan_params,
1618 __bt_mesh_network_scan_unprovisioned_device_result_cb, NULL);
1619 TC_PRT("return %s\n", __bt_get_error_message(ret));
1622 case BT_MESH_UNIT_TEST_FUNCTION_STOP_UNPROVISIONED_DEVICE_SCAN: {
1623 ret = bt_mesh_stop_unprovisioned_device_scan(network);
1624 TC_PRT("return %s\n", __bt_get_error_message(ret));
1625 if (ret == BT_ERROR_NONE)
1626 TC_PRT("Device SCAN : STOPPED");
1629 case BT_MESH_UNIT_TEST_FUNCTION_NETWORK_PROVISION_DEVICE: {
1630 const char *dev_uuid = "abababababababababababababababab";
1631 if(g_test_param.param_count != 1) {
1632 TC_PRT("Enter Input parameter first.\n");
1635 dev_uuid = g_test_param.params[0];
1636 TC_PRT("The dev_uuid is [%s]\n",dev_uuid);
1637 ret = bt_mesh_network_provision_device(network, dev_uuid,
1638 __bt_mesh_network_device_provision_cb, NULL);
1639 TC_PRT("return %s\n", __bt_get_error_message(ret));
1642 case BT_MESH_UNIT_TEST_FUNCTION_NETWORK_AUTHENTICATION_SET_REQUEST_CB: {
1643 ret = bt_mesh_authentication_set_request_cb(
1644 __bt_mesh_authentication_request_cb, NULL);
1645 TC_PRT("return %s\n", __bt_get_error_message(ret));
1648 case BT_MESH_UNIT_TEST_FUNCTION_MESH_AUTHENTICATION_REPLY: {
1652 if(g_test_param.param_count !=2){
1653 TC_PRT("Enter Input parameter first.\n");
1656 len = strlen(g_test_param.params[0]);
1657 value = g_malloc0(len+1);
1658 g_strlcpy(value, g_test_param.params[0], len+1);
1659 auth_reply = atoi(g_test_param.params[1]);
1660 TC_PRT("\nauth_value is [%s]\n", value);
1661 TC_PRT("auth_reply is [%d]\n", auth_reply);
1662 TC_PRT("auth_type is [%d]\n", request_type);
1663 ret = bt_mesh_authentication_reply(request_type, (const char*)value, auth_reply);
1664 TC_PRT("return %s\n", __bt_get_error_message(ret));
1667 case BT_MESH_UNIT_TEST_FUNCTION_NETWORK_SET_PROVISIONING_CAPABILITIES: {
1668 bt_mesh_provisioner_capabilities_s capabilities;
1669 if(g_test_param.param_count !=4) {
1670 TC_PRT("Enter Input parameter first.");
1673 capabilities.public_oob = atoi(g_test_param.params[0]);
1674 capabilities.static_oob = atoi(g_test_param.params[1]);
1675 capabilities.out_oob = (int)strtol(g_test_param.params[2], NULL, 16);
1676 capabilities.in_oob = (int)strtol(g_test_param.params[3], NULL, 16);
1677 TC_PRT("CAP: PUBLIC OOB [%d]", capabilities.public_oob);
1678 TC_PRT("CAP: STATIC OOB [%d]", capabilities.static_oob);
1679 TC_PRT("CAP: OUT OOB [%d]", capabilities.out_oob);
1680 TC_PRT("CAP: IN OOB [%d]", capabilities.in_oob);
1681 ret = bt_mesh_network_set_provisioning_capabilities(network, &capabilities);
1682 TC_PRT("return %s\n", __bt_get_error_message(ret));
1685 case BT_MESH_UNIT_TEST_FUNCTION_NETWORK_GET_PROVISIONING_CAPABILITIES: {
1686 // TODO: need to implement
1689 case BT_MESH_UNIT_TEST_FUNCTION_ACTIVATE_FLAG_TO_SET_PARAMETERS: {
1690 need_to_set_params = true;
1691 TC_PRT("Select the function again");
1697 __bt_free_test_param(&g_test_param);
1700 case BT_MESH_UNIT_TEST_TABLE_CONFIGURATION: {
1702 case BT_MESH_UNIT_TEST_FUNCTION_MESH_NETWORK_DISCOVER_NODE: {
1703 char* dev_uu = "tempName";
1704 if (g_test_param.param_count > 0) {
1705 dev_uu = g_strdup(g_test_param.params[0]);
1707 TC_PRT("Set Input parameter first!");
1710 ret = bt_mesh_network_discover_node(network, (const char*)dev_uu,
1711 __bt_mesh_node_discover_status_cb, NULL);
1712 TC_PRT("return %s\n", __bt_get_error_message(ret));
1715 case BT_MESH_UNIT_TEST_FUNCTION_NODE_RESET: {
1716 // TODO: need to implement
1719 case BT_MESH_UNIT_TEST_FUNCTION_NODE_GET_FEATURES: {
1720 bt_mesh_node_h node_h = 0;
1721 if (g_test_param.param_count != 1) {
1722 TC_PRT("Set Input parameter first!");
1725 node_h = GUINT_TO_POINTER(strtoul(g_test_param.params[0], NULL, 16));
1726 ret = bt_mesh_node_get_features(node_h, __bt_mesh_node_features_cb, NULL);
1727 TC_PRT("return %s\n", __bt_get_error_message(ret));
1730 case BT_MESH_UNIT_TEST_FUNCTION_NODE_GET_NETKEYS: {
1731 bt_mesh_node_h node_h = 0;
1732 if (g_test_param.param_count != 1) {
1733 TC_PRT("Set Input parameter first!");
1736 node_h = GUINT_TO_POINTER(strtoul(g_test_param.params[0], NULL, 16));
1737 ret = bt_mesh_node_foreach_netkeys(node_h, __bt_mesh_node_foreach_netkeys_cb, NULL);
1738 TC_PRT("return %s\n", __bt_get_error_message(ret));
1741 case BT_MESH_UNIT_TEST_FUNCTION_NODE_GET_APPKEYS: {
1742 bt_mesh_node_h node_h = 0;
1743 bt_mesh_netkey_h netkey_h = 0;
1744 if (g_test_param.param_count != 2) {
1745 TC_PRT("Set Input parameter first!");
1748 node_h = GUINT_TO_POINTER(strtoul(g_test_param.params[0], NULL, 16));
1749 netkey_h = GUINT_TO_POINTER(strtoul(g_test_param.params[1], NULL, 16));
1751 ret = bt_mesh_node_foreach_appkeys(node_h, netkey_h,
1752 __bt_mesh_node_foreach_appkeys_cb, NULL);
1753 TC_PRT("return %s\n", __bt_get_error_message(ret));
1756 case BT_MESH_UNIT_TEST_FUNCTION_NODE_GET_TTL: {
1757 bt_mesh_node_h node_h = 0;
1758 if (g_test_param.param_count != 1) {
1759 TC_PRT("Set Input parameter first!");
1762 node_h = GUINT_TO_POINTER(strtoul(g_test_param.params[0], NULL, 16));
1763 ret = bt_mesh_node_get_ttl(node_h, __bt_mesh_node_ttl_cb, NULL);
1764 TC_PRT("return %s\n", __bt_get_error_message(ret));
1767 case BT_MESH_UNIT_TEST_FUNCTION_NODE_SET_TTL: {
1768 bt_mesh_node_h node_h = 0;
1770 if (g_test_param.param_count != 2) {
1771 TC_PRT("Set Input parameter first!");
1774 node_h = GUINT_TO_POINTER(strtoul(g_test_param.params[0], NULL, 16));
1775 ttl = atoi(g_test_param.params[1]);
1777 ret = bt_mesh_node_set_ttl(node_h, (uint8_t) ttl, __bt_mesh_node_ttl_cb, NULL);
1778 TC_PRT("return %s\n", __bt_get_error_message(ret));
1781 case BT_MESH_UNIT_TEST_FUNCTION_NODE_CONFIGURE_NETKEY: {
1782 bt_mesh_node_h node_h = 0;
1783 bt_mesh_netkey_h netkey_h = 0;
1784 bt_mesh_node_key_configuration_e config = 0;
1785 if (g_test_param.param_count != 3) {
1786 TC_PRT("Set Input parameter first!");
1789 node_h = GUINT_TO_POINTER(strtoul(g_test_param.params[0], NULL, 16));
1790 netkey_h = GUINT_TO_POINTER(strtoul(g_test_param.params[1], NULL, 16));
1791 config = atoi(g_test_param.params[2]);
1793 ret = bt_mesh_node_configure_netkey(node_h, config, netkey_h,
1794 __bt_mesh_node_configure_netkey_cb, NULL);
1795 TC_PRT("return %s\n", __bt_get_error_message(ret));
1798 case BT_MESH_UNIT_TEST_FUNCTION_NODE_CONFIGURE_APPKEY: {
1799 bt_mesh_node_h node_h = 0;
1800 bt_mesh_appkey_h appkey_h = 0;
1801 bt_mesh_node_key_configuration_e config = 0;
1802 if (g_test_param.param_count != 3) {
1803 TC_PRT("Set Input parameter first!");
1806 node_h = GUINT_TO_POINTER(strtoul(g_test_param.params[0], NULL, 16));
1807 appkey_h = GUINT_TO_POINTER(strtoul(g_test_param.params[1], NULL, 16));
1808 config = atoi(g_test_param.params[2]);
1810 ret = bt_mesh_node_configure_appkey(node_h, config, appkey_h,
1811 __bt_mesh_node_configure_appkey_cb, NULL);
1812 TC_PRT("return %s\n", __bt_get_error_message(ret));
1815 case BT_MESH_UNIT_TEST_FUNCTION_MODEL_BIND_APPKEY: {
1816 bt_mesh_model_h model_h = 0;
1817 bt_mesh_appkey_h appkey_h = 0;
1818 if (g_test_param.param_count != 2) {
1819 TC_PRT("Set Input parameter first!");
1822 model_h = GUINT_TO_POINTER(strtoul(g_test_param.params[0], NULL, 16));
1823 appkey_h = GUINT_TO_POINTER(strtoul(g_test_param.params[1], NULL, 16));
1825 ret = bt_mesh_model_bind_appkey(model_h, appkey_h, __bt_mesh_model_bind_cb, NULL);
1826 TC_PRT("return %s\n", __bt_get_error_message(ret));
1829 case BT_MESH_UNIT_TEST_FUNCTION_MODEL_UNBIND_APPKEY: {
1830 bt_mesh_model_h model_h = 0;
1831 bt_mesh_appkey_h appkey_h = 0;
1832 if (g_test_param.param_count != 2) {
1833 TC_PRT("Set Input parameter first!");
1836 model_h = GUINT_TO_POINTER(strtoul(g_test_param.params[0], NULL, 16));
1837 appkey_h = GUINT_TO_POINTER(strtoul(g_test_param.params[1], NULL, 16));
1839 ret = bt_mesh_model_unbind_appkey(model_h, appkey_h, __bt_mesh_model_unbind_cb, NULL);
1840 TC_PRT("return %s\n", __bt_get_error_message(ret));
1843 case BT_MESH_UNIT_TEST_FUNCTION_MODEL_GET_APPKEY_LIST: {
1844 bt_mesh_model_h model_h = 0;
1845 if (g_test_param.param_count != 1) {
1846 TC_PRT("Set Input parameter first!");
1849 model_h = GUINT_TO_POINTER(strtoul(g_test_param.params[0], NULL, 16));
1851 ret = bt_mesh_model_get_appkey_list(model_h, __bt_mesh_model_appkey_list_cb, NULL);
1852 TC_PRT("return %s\n", __bt_get_error_message(ret));
1855 case BT_MESH_UNIT_TEST_FUNCTION_MODEL_CONFIGURE_GROUP_SUBSCRIPTION: {
1856 bt_mesh_model_h model_h = 0;
1857 bt_mesh_group_h group_h = 0;
1858 bt_mesh_model_subscription_op_e op = BT_MESH_MODEL_SUBSCRIPTION_ADD;
1860 if (g_test_param.param_count != 3) {
1861 TC_PRT("Set Input parameter first!");
1864 model_h = GUINT_TO_POINTER(strtoul(g_test_param.params[0], NULL, 16));
1865 op = atoi(g_test_param.params[1]);
1866 group_h = GUINT_TO_POINTER(strtoul(g_test_param.params[2], NULL, 16));
1868 ret = bt_mesh_model_configure_group_subscription(op, model_h, group_h,
1869 __bt_mesh_model_subscription_op_cb, NULL);
1870 TC_PRT("return %s\n", __bt_get_error_message(ret));
1873 case BT_MESH_UNIT_TEST_FUNCTION_MODEL_CONFIGURE_VIRTUAL_GROUP_SUBSCRIPTION: {
1874 bt_mesh_model_h model_h = 0;
1875 bt_mesh_group_h group_h = 0;
1876 bt_mesh_model_subscription_op_e op = BT_MESH_MODEL_SUBSCRIPTION_ADD;
1878 if (g_test_param.param_count != 3) {
1879 TC_PRT("Set Input parameter first!");
1882 model_h = GUINT_TO_POINTER(strtoul(g_test_param.params[0], NULL, 16));
1883 op = atoi(g_test_param.params[1]);
1884 group_h = GUINT_TO_POINTER(strtoul(g_test_param.params[2], NULL, 16));
1886 ret = bt_mesh_model_configure_virtual_group_subscription(op, model_h, group_h,
1887 __bt_mesh_model_subscription_op_cb, NULL);
1888 TC_PRT("return %s\n", __bt_get_error_message(ret));
1891 case BT_MESH_UNIT_TEST_FUNCTION_MODEL_GET_SUBSCRIPTION_LIST: {
1892 bt_mesh_model_h model_h = 0;
1894 if (g_test_param.param_count != 1) {
1895 TC_PRT("Set Input parameter first!");
1898 model_h = GUINT_TO_POINTER(strtoul(g_test_param.params[0], NULL, 16));
1900 ret = bt_mesh_model_get_subscription_list(model_h, __bt_mesh_model_subscription_list_cb, NULL);
1901 TC_PRT("return %s\n", __bt_get_error_message(ret));
1904 case BT_MESH_UNIT_TEST_FUNCTION_MODEL_SET_PUBLICATION: {
1905 bt_mesh_model_h model_h = 0;
1906 bt_mesh_model_h appkey_h = 0;
1907 bt_mesh_group_h group_h = 0;
1908 bt_mesh_model_pub_params_s param;
1910 memset(¶m, 0x00, sizeof(bt_mesh_model_pub_params_s));
1912 if (g_test_param.param_count != 3) {
1913 TC_PRT("Set Input parameter first!");
1916 model_h = GUINT_TO_POINTER(strtoul(g_test_param.params[0], NULL, 16));
1917 appkey_h = GUINT_TO_POINTER(strtoul(g_test_param.params[1], NULL, 16));
1918 group_h = GUINT_TO_POINTER(strtoul(g_test_param.params[2], NULL, 16));
1921 param.num_steps = 10;
1922 param.per_res = BT_MESH_PUBLICATION_STEP_RES_1_SECOND;
1923 param.retrans_cnt = BT_MESH_MAX_PUBISH_RETRANSMIT_COUNT;
1924 param.retrans_step = BT_MESH_MAX_PUBISH_RETRANSMIT_INTERVAL_STEPS;
1926 ret = bt_mesh_model_set_publication(model_h, appkey_h, group_h, ¶m,
1927 __bt_mesh_model_publication_status_cb, NULL);
1928 TC_PRT("return %s\n", __bt_get_error_message(ret));
1931 case BT_MESH_UNIT_TEST_FUNCTION_MODEL_GET_PUBLICATION: {
1932 bt_mesh_model_h model_h = 0;
1934 if (g_test_param.param_count != 1) {
1935 TC_PRT("Set Input parameter first!");
1938 model_h = GUINT_TO_POINTER(strtoul(g_test_param.params[0], NULL, 16));
1940 ret = bt_mesh_model_get_publication(model_h, __bt_mesh_model_publication_status_cb, NULL);
1941 TC_PRT("return %s\n", __bt_get_error_message(ret));
1944 case BT_MESH_UNIT_TEST_FUNCTION_MODEL_SEND_MSG: {
1945 bt_mesh_model_h model_h = NULL;
1946 bt_mesh_appkey_h appkey_h = NULL;
1947 bt_mesh_model_msg_params_s *msg_params = NULL;
1948 if (g_test_param.param_count != 4) {
1949 TC_PRT("Set Input parameter first!");
1952 model_h = GUINT_TO_POINTER(strtoul(g_test_param.params[0], NULL, 16));
1953 appkey_h = GUINT_TO_POINTER(strtoul(g_test_param.params[1], NULL, 16));
1954 msg_params = g_malloc0(sizeof(bt_mesh_model_msg_params_s));
1955 msg_params->opcode = strtoul(g_test_param.params[2], NULL, 16);
1956 msg_params->data = "0101010101010101010101010100101010";
1957 msg_params->data = g_strdup(g_test_param.params[3]);
1958 TC_PRT("Input parameters");
1959 print_model_handle(model_h);
1960 print_appkey_handle(appkey_h);
1961 TC_PRT("opcode 0X%4.4X", msg_params->opcode);
1962 TC_PRT("Message to be sent %s", msg_params->data);
1963 ret = bt_mesh_model_send_msg(model_h, appkey_h, msg_params,
1964 __bt_mesh_model_msg_cb, NULL);
1965 TC_PRT("return %s\n", __bt_get_error_message(ret));
1968 case BT_MESH_UNIT_TEST_FUNCTION_APPKEY_GET_NETKEY: {
1969 bt_mesh_appkey_h appkey_h = 0;
1970 bt_mesh_netkey_h netkey_h;
1972 if (g_test_param.param_count != 1) {
1973 TC_PRT("Set Input parameter first!");
1976 appkey_h = GUINT_TO_POINTER(strtoul(g_test_param.params[0], NULL, 16));
1978 ret = bt_mesh_appkey_get_netkey(appkey_h, &netkey_h);
1979 TC_PRT("return %s\n", __bt_get_error_message(ret));
1980 if (ret == BT_ERROR_NONE)
1981 print_netkey_handle(netkey_h);
1984 case BT_MESH_UNIT_TEST_FUNCTION_ACTIVATE_FLAG_TO_SET_PARAMETERS: {
1985 need_to_set_params = true;
1986 TC_PRT("Select the function again");
1992 __bt_free_test_param(&g_test_param);
2002 static gboolean key_event_cb(GIOChannel *chan,
2006 char buf[BUFFER_LEN] = { 0 };
2009 unsigned long len = 0;
2011 unsigned int len = 0;
2014 bool is_call_api = false;
2016 memset(buf, 0, sizeof(buf));
2018 if (g_io_channel_read_chars(chan, buf, sizeof(buf),
2019 &len, NULL) == G_IO_STATUS_ERROR) {
2020 TC_PRT("IO Channel read error");
2024 if (need_to_set_params == true) {
2025 if (g_test_id == -1) {
2026 test_id = atoi(buf);
2027 g_test_id = test_id;
2029 test_set_params(g_test_id, buf);
2033 test_id = atoi(buf);
2036 need_to_set_params = false;
2039 if (current_tc_table == BT_MESH_UNIT_TEST_TABLE_MAIN) {
2041 current_tc_table = BT_MESH_UNIT_TEST_TABLE_MAIN;
2042 else if(test_id >= BT_MESH_UNIT_TEST_TABLE_NETWORK
2043 && test_id <= BT_MESH_UNIT_TEST_TABLE_CONFIGURATION) {
2044 current_tc_table = test_id;
2045 } else if (test_id > BT_MESH_UNIT_TEST_TABLE_CONFIGURATION
2046 && test_id < BT_MESH_UNIT_TEST_TABLE_FINISH) {
2047 current_tc_table = BT_MESH_UNIT_TEST_TABLE_MAIN;
2054 if (buf[0] == '0' && buf[2] == 0) {
2055 current_tc_table = BT_MESH_UNIT_TEST_TABLE_MAIN;
2059 current_tc_table = BT_MESH_UNIT_TEST_TABLE_MAIN;
2068 if (test_id && is_call_api) {
2070 g_idle_add(test_input_callback, (void *)(uintptr_t)test_id);
2072 g_idle_add(test_input_callback, (void *)test_id);
2078 void sig_handler(int signo)
2080 if (signo == SIGINT) {
2081 bt_mesh_deinitialize();
2090 current_tc_table = BT_MESH_UNIT_TEST_TABLE_MAIN;
2092 key_io = g_io_channel_unix_new(fileno(stdin));
2094 g_io_channel_set_encoding(key_io, NULL, NULL);
2095 g_io_channel_set_flags(key_io, G_IO_FLAG_NONBLOCK, NULL);
2097 g_io_add_watch(key_io, G_IO_IN | G_IO_HUP | G_IO_ERR | G_IO_NVAL,
2098 key_event_cb, NULL);
2100 g_io_channel_unref(key_io);
2102 main_loop = g_main_loop_new(NULL, FALSE);
2104 if (signal(SIGINT, sig_handler) == SIG_ERR)
2105 TC_PRT("\n can't catch SIGINT\n");
2107 g_main_loop_run(main_loop);
2109 bt_mesh_deinitialize();