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_load"
129 , BT_MESH_UNIT_TEST_FUNCTION_NETWORK_LOAD},
130 {"bt_mesh_network_set_name"
131 , BT_MESH_UNIT_TEST_FUNCTION_NETWORK_SET_NAME},
132 {"bt_mesh_network_get_name"
133 , BT_MESH_UNIT_TEST_FUNCTION_NETWORK_GET_NAME},
134 {"bt_mesh_network_add_netkey"
135 , BT_MESH_UNIT_TEST_FUNCTION_NETWORK_ADD_NETKEY},
136 {"bt_mesh_network_foreach_netkeys"
137 , BT_MESH_UNIT_TEST_FUNCTION_NETWORK_FOREACH_NETKEYS},
138 {"bt_mesh_netkey_get_index"
139 , BT_MESH_UNIT_TEST_FUNCTION_NETKEY_GET_INDEX},
140 {"bt_mesh_netkey_update"
141 , BT_MESH_UNIT_TEST_FUNCTION_NETKEY_UPDATE},
142 {"bt_mesh_netkey_delete"
143 , BT_MESH_UNIT_TEST_FUNCTION_NETKEY_DELETE},
144 {"bt_mesh_netkey_add_appkey"
145 , BT_MESH_UNIT_TEST_FUNCTION_NETKEY_ADD_APPKEY},
146 {"bt_mesh_netkey_foreach_appkeys"
147 , BT_MESH_UNIT_TEST_FUNCTION_NETKEY_FOREACH_APPKEYS},
148 {"bt_mesh_appkey_get_index"
149 , BT_MESH_UNIT_TEST_FUNCTION_APPKEY_GET_INDEX},
150 {"bt_mesh_appkey_update"
151 , BT_MESH_UNIT_TEST_FUNCTION_APPKEY_UPDATE},
152 {"bt_mesh_appkey_delete"
153 , BT_MESH_UNIT_TEST_FUNCTION_APPKEY_DELETE},
154 {"bt_mesh_network_foreach_devices"
155 , BT_MESH_UNIT_TEST_FUNCTION_NETWORK_FOREACH_DEVICES},
156 {"bt_mesh_network_create_group"
157 , BT_MESH_UNIT_TEST_FUNCTION_NETWORK_CREATE_GROUP},
158 {"bt_mesh_network_create_virtual_group"
159 , BT_MESH_UNIT_TEST_FUNCTION_NETWORK_CREATE_VIRTUAL_GROUP},
160 {"bt_mesh_network_remove_group"
161 , BT_MESH_UNIT_TEST_FUNCTION_NETWORK_REMOVE_GROUP},
162 {"bt_mesh_network_foreach_groups"
163 , BT_MESH_UNIT_TEST_FUNCTION_NETWORK_FOREACH_GROUPS},
164 {"bt_mesh_network_unprovisioned_device_scan"
165 , BT_MESH_UNIT_TEST_FUNCTION_NETWORK_UNPROVISIONED_DEVICE_SCAN},
166 {"bt_mesh_stop_unprovisioned_device_scan"
167 , BT_MESH_UNIT_TEST_FUNCTION_STOP_UNPROVISIONED_DEVICE_SCAN},
168 {"bt_mesh_network_provision_device"
169 , BT_MESH_UNIT_TEST_FUNCTION_NETWORK_PROVISION_DEVICE},
170 {"bt_mesh_authentication_set_request_cb"
171 , BT_MESH_UNIT_TEST_FUNCTION_NETWORK_AUTHENTICATION_SET_REQUEST_CB},
172 {"bt_mesh_authentication_reply"
173 , BT_MESH_UNIT_TEST_FUNCTION_MESH_AUTHENTICATION_REPLY},
174 {"bt_mesh_network_set_provisioning_capabilities"
175 , BT_MESH_UNIT_TEST_FUNCTION_NETWORK_SET_PROVISIONING_CAPABILITIES},
176 {"bt_mesh_network_get_provisioning_capabilities"
177 , BT_MESH_UNIT_TEST_FUNCTION_NETWORK_GET_PROVISIONING_CAPABILITIES},
178 {"select this menu to set parameters and then select the function again"
179 , BT_MESH_UNIT_TEST_FUNCTION_ACTIVATE_FLAG_TO_SET_PARAMETERS},
183 tc_table_t tc_main[] = {
184 {"bt_mesh_initialize"
185 , BT_MESH_UNIT_TEST_FUNCTION_INITIALIZE},
186 {"bt_mesh_deinitialize"
187 , BT_MESH_UNIT_TEST_FUNCTION_DEINITIALIZE},
189 , BT_MESH_UNIT_TEST_TABLE_NETWORK},
191 , BT_MESH_UNIT_TEST_TABLE_CONFIGURATION},
193 , BT_MESH_UNIT_TEST_TABLE_FINISH},
197 static void __bt_free_test_param(tc_params_t *param)
201 for (i = 0; i < param->param_count; i++)
202 g_free(param->params[i]);
203 g_free(param->params);
204 param->params = NULL;
205 param->param_count = 0;
208 void tc_usage_print(void){
210 tc_table_t *tc_table = NULL;
211 switch (current_tc_table) {
212 case BT_MESH_UNIT_TEST_TABLE_NETWORK:
213 tc_table = tc_network;
215 case BT_MESH_UNIT_TEST_TABLE_CONFIGURATION:
216 tc_table = tc_configuration;
222 while (tc_table[i].tc_name) {
223 TC_PRT("Key %d : usage %s", tc_table[i].tc_code,tc_table[i].tc_name);
228 static const char *__bt_get_error_message(bt_error_e err)
230 const char *err_str = NULL;
234 err_str = "BT_ERROR_NONE";
236 case BT_ERROR_CANCELLED:
237 err_str = "BT_ERROR_CANCELLED";
239 case BT_ERROR_INVALID_PARAMETER:
240 err_str = "BT_ERROR_INVALID_PARAMETER";
242 case BT_ERROR_OUT_OF_MEMORY:
243 err_str = "BT_ERROR_OUT_OF_MEMORY";
245 case BT_ERROR_RESOURCE_BUSY:
246 err_str = "BT_ERROR_RESOURCE_BUSY";
248 case BT_ERROR_TIMED_OUT:
249 err_str = "BT_ERROR_TIMED_OUT";
251 case BT_ERROR_NOW_IN_PROGRESS:
252 err_str = "BT_ERROR_NOW_IN_PROGRESS";
254 case BT_ERROR_NOT_INITIALIZED:
255 err_str = "BT_ERROR_NOT_INITIALIZED";
257 case BT_ERROR_NOT_ENABLED:
258 err_str = "BT_ERROR_NOT_ENABLED";
260 case BT_ERROR_ALREADY_DONE:
261 err_str = "BT_ERROR_ALREADY_DONE";
263 case BT_ERROR_OPERATION_FAILED:
264 err_str = "BT_ERROR_OPERATION_FAILED";
266 case BT_ERROR_NOT_IN_PROGRESS:
267 err_str = "BT_ERROR_NOT_IN_PROGRESS";
270 err_str = "NOT defined";
276 void print_network_handle(bt_mesh_network_h network)
280 bt_mesh_network_s* net = (bt_mesh_network_s*) network;
281 TC_PRT("network_handle = [%p]", (void*)net);
282 TC_PRT("net->is_local [%d]", net->is_local);
283 TC_PRT("net->is_discovered [%d]", net->is_discovered);
284 TC_PRT("net->uuid [%s]", net->uuid);
285 TC_PRT("net->token [%s]", net->token);
286 TC_PRT("net->name [%s]", net->name);
287 TC_PRT("net->num_nodes [%d]", net->num_nodes);
290 void print_node_handle(bt_mesh_node_h node)
294 bt_mesh_node_s* node_info = (bt_mesh_node_s*) node;
295 TC_PRT("node_handle = [%p]",(void*)node_info);
296 TC_PRT("node->is_local [%d]", node_info->is_local);
297 TC_PRT("node->is_attached [%d]", node_info->is_attached);
298 if (node_info->is_attached) {
299 TC_PRT("node->parent_network [%s]", node_info->parent->name);
300 TC_PRT("node->uuid [%s]", node_info->uuid);
301 TC_PRT("node->unicast [%d]", node_info->unicast);
306 void print_element_handle(bt_mesh_element_h element)
310 bt_mesh_element_s* element_info = (bt_mesh_element_s*) element;
311 TC_PRT("element_handle = [%p]", (void*)element_info);
312 TC_PRT("element->is_local [%d]", element_info->is_local);
313 TC_PRT("element->index [%d]", element_info->index);
316 void print_model_handle(bt_mesh_model_h model)
320 bt_mesh_model_s* model_info = (bt_mesh_model_s*) model;
321 TC_PRT("model_handle = [%p]", (void*)model_info);
322 TC_PRT("model->is_local [%d]", model_info->is_local);
323 TC_PRT("model->id [0x%4.4x]", model_info->id);
324 TC_PRT("model->pub_addr [0x%2.2x]", model_info->pub_addr);
327 void print_netkey_handle(bt_mesh_netkey_h netkey)
331 bt_mesh_netkey_s* netkey_info = (bt_mesh_netkey_s*) netkey;
332 TC_PRT("netkey_handle = [%p]", (void*)netkey_info);
333 TC_PRT("Parent network_name [%s]", netkey_info->parent->name);
334 TC_PRT("Netkey_index [%d]", netkey_info->netkey_index);
337 void print_appkey_handle(bt_mesh_appkey_h appkey)
341 bt_mesh_appkey_s* appkey_info = (bt_mesh_appkey_s*) appkey;
342 TC_PRT("appkey_handle = [%p]", (void*)appkey_info);
343 TC_PRT("Parent netkey_index [%d]", appkey_info->parent->netkey_index);
344 TC_PRT("appkey_index [%d]", appkey_info->appkey_index);
347 void print_group_handle(bt_mesh_group_h group)
351 bt_mesh_group_s* group_info = (bt_mesh_group_s*) group;
352 TC_PRT("group_handle = [%p]", (void*)group_info);
353 TC_PRT("group Parent Network Name [%s]", group_info->parent->name);
354 TC_PRT("group Address [0x%2.2x]", group_info->addr);
355 TC_PRT("group Label UUID [%s]", group_info->label_uuid);
356 TC_PRT("group Is Virtual ? [%s]", group_info->is_virtual ? "YES" : "NO");
359 bool __bt_mesh_network_device_info_cb(int result, bt_mesh_network_h network, int total,
360 const char *dev_uuid, uint16_t primary_unicast, void *user_data)
362 TC_PRT("bt_mesh_network_device_info_cb");
363 TC_PRT("Total number of Devices in network [%d]", total);
365 TC_PRT("result: %s", __bt_get_error_message(result));
366 TC_PRT("primary unicast address is [%d]",primary_unicast);
367 TC_PRT("Device UUID [%s]", dev_uuid);
371 bool __bt_mesh_network_group_info_cb(int result, bt_mesh_network_h network, int total,
372 bt_mesh_group_h group, void *user_data)
374 bt_mesh_group_s* grp = (bt_mesh_group_s*) group;
375 TC_PRT("bt_mesh_network_group_info_cb: Total groups present in network [%d]", total);
376 TC_PRT("result: %s", __bt_get_error_message(result));
378 if (result == BT_ERROR_NONE) {
379 print_group_handle(grp);
385 void __bt_mesh_node_discover_status_cb(int result, bt_mesh_network_h network, bt_mesh_node_h node_param,
388 TC_PRT("bt_mesh_node_discover_status_cb");
389 TC_PRT("result: %s", __bt_get_error_message(result));
390 //print_network_handle(network);
391 print_node_handle(node_param);
392 if (result == BT_ERROR_NONE)
396 static bool __bt_mesh_elem_foreach_model_cb(int result, bt_mesh_element_h element, int total,
397 bt_mesh_model_h model, bt_mesh_model_id_s *model_id, void *user_data)
399 TC_PRT("__bt_mesh_elem_foreach_model_cb");
400 TC_PRT("result: %s", __bt_get_error_message(result));
402 if (result == BT_ERROR_NONE) {
403 TC_PRT("Total number of Models in the element [%d]", total);
404 print_element_handle(element);
406 print_model_handle(model);
407 TC_PRT("Model Comp ID [0x%2.2x] Model ID [0x%2.2x]",
408 model_id->company_id, model_id->model_id);
415 static bool __bt_mesh_node_foreach_elem_cb(int result, bt_mesh_node_h node, int total,
416 bt_mesh_element_h element, int elem_index, uint16_t element_addr, void *user_data)
418 TC_PRT("__bt_mesh_node_foreach_elem_cb");
419 TC_PRT("result: %s", __bt_get_error_message(result));
421 if (result == BT_ERROR_NONE) {
422 TC_PRT("Total number of elements in the node [%d]", total);
423 print_node_handle(node);
425 print_element_handle(element);
426 TC_PRT("Element address [0x%2.2x]", element_addr);
427 TC_PRT("Element index [%d]", elem_index);
434 static void __bt_mesh_node_configure_netkey_cb(int result, bt_mesh_node_key_configuration_e op,
435 bt_mesh_node_h node, bt_mesh_netkey_h netkey, void *user_data)
437 TC_PRT("__bt_mesh_node_configure_netkey_cb");
438 TC_PRT("result: %s", __bt_get_error_message(result));
440 if (result == BT_ERROR_NONE) {
441 print_node_handle(node);
442 if (op == BT_MESH_NODE_KEY_ADD)
443 TC_PRT("NetKey Added!");
444 else if (op == BT_MESH_NODE_KEY_UPDATE)
445 TC_PRT("NetKey Updated!");
447 TC_PRT("NetKey Deleted!");
448 print_netkey_handle(netkey);
452 static void __bt_mesh_node_configure_appkey_cb(int result, bt_mesh_node_key_configuration_e op,
453 bt_mesh_node_h node, bt_mesh_netkey_h netkey,
454 bt_mesh_appkey_h appkey, void *user_data)
456 TC_PRT("__bt_mesh_node_configure_netkey_cb");
457 TC_PRT("result: %s", __bt_get_error_message(result));
459 if (result == BT_ERROR_NONE) {
460 print_node_handle(node);
461 if (op == BT_MESH_NODE_KEY_ADD)
462 TC_PRT("AppKey Added!");
463 else if (op == BT_MESH_NODE_KEY_UPDATE)
464 TC_PRT("AppKey Updated!");
466 TC_PRT("AppKey Deleted!");
467 print_netkey_handle(netkey);
468 print_appkey_handle(appkey);
472 static void __bt_mesh_node_features_cb(int result, bt_mesh_node_h node,
473 bt_mesh_node_features_s *features, void *user_data)
475 TC_PRT("__bt_mesh_node_features_cb");
476 TC_PRT("result: %s", __bt_get_error_message(result));
478 if (result == BT_ERROR_NONE) {
479 print_node_handle(node);
480 TC_PRT("CID [0x%2.2x]\n", features->cid);
481 TC_PRT("PID [0x%2.2x]\n", features->pid);
482 TC_PRT("VID [0x%2.2x]\n", features->vid);
483 TC_PRT("CRPL [0x%2.2x]\n", features->crpl);
485 if (features->features & BT_MESH_FEATURE_RELAY)
486 TC_PRT("Features: RELAY Supported");
487 if (features->features & BT_MESH_FEATURE_PROXY)
488 TC_PRT("Features: PROXY Supported");
489 if (features->features & BT_MESH_FEATURE_FRIEND)
490 TC_PRT("Features: FRIEND Supported");
491 if (features->features & BT_MESH_FEATURE_LOWPOWER)
492 TC_PRT("Features: LOW POWER Supported\n");
496 static bool __bt_mesh_node_foreach_netkeys_cb(int result, bt_mesh_node_h node, int total,
497 bt_mesh_netkey_h netkey,
498 uint16_t netkey_index, void *user_data)
500 TC_PRT("__bt_mesh_node_foreach_netkeys_cb");
501 TC_PRT("result: %s", __bt_get_error_message(result));
503 if (result == BT_ERROR_NONE) {
504 TC_PRT("Total Netkeys in node [%d]", total);
505 print_node_handle(node);
506 print_netkey_handle(netkey);
512 static bool __bt_mesh_node_foreach_appkeys_cb(int result, bt_mesh_node_h node, int total,
513 bt_mesh_netkey_h netkey, bt_mesh_appkey_h appkey,
514 uint16_t appkey_index, void *user_data)
516 TC_PRT("__bt_mesh_node_foreach_appkeys_cb");
517 TC_PRT("result: %s", __bt_get_error_message(result));
519 if (result == BT_ERROR_NONE) {
520 TC_PRT("Total Appkeys in node [%d]", total);
521 print_netkey_handle(netkey);
522 print_appkey_handle(appkey);
528 void __bt_mesh_node_ttl_cb(int result, bt_mesh_node_h node,
529 bt_mesh_node_ttl_operation_e ttl_op, uint8_t ttl, void *user_data)
531 TC_PRT("bt_mesh_node_ttl_cb");
532 TC_PRT("result: %s", __bt_get_error_message(result));
534 if (result == BT_ERROR_NONE) {
535 print_node_handle(node);
536 TC_PRT("ttl_op is [%s]", ttl_op? "TTL Set" : "TTL Get");
537 TC_PRT("ttl value is [%d]",ttl);
541 void __bt_mesh_model_bind_cb(int result, bt_mesh_model_h model, bt_mesh_appkey_h appkey,
544 TC_PRT("bt_mesh_model_bind_cb");
545 TC_PRT("result: %s", __bt_get_error_message(result));
546 if (result == BT_ERROR_NONE) {
547 print_model_handle(model);
548 print_appkey_handle(appkey);
552 void __bt_mesh_model_msg_cb(int result, bt_mesh_element_h element, bt_mesh_appkey_h appkey,
553 bt_mesh_model_msg_params_s *msg, void *user_data)
555 TC_PRT("bt_mesh_model_msg_cb");
556 TC_PRT("result: %s", __bt_get_error_message(result));
557 if (result == BT_ERROR_NONE) {
558 TC_PRT("opcode: 0X%2.2X", msg->opcode);
559 TC_PRT("msg: %s", msg->data);
560 print_element_handle(element);
561 print_appkey_handle(appkey);
565 void __bt_mesh_model_unbind_cb(int result, bt_mesh_model_h model, bt_mesh_appkey_h appkey,
568 TC_PRT("bt_mesh_model_unbind_cb");
569 TC_PRT("result: %s", __bt_get_error_message(result));
570 if (result == BT_ERROR_NONE) {
571 print_model_handle(model);
572 print_appkey_handle(appkey);
576 void __bt_mesh_model_appkey_list_cb(int result, bt_mesh_model_h model, int total, const GSList *appkeylist,
579 TC_PRT("bt_mesh_model_appkey_list_cb");
582 TC_PRT("result: %s", __bt_get_error_message(result));
583 if (result == BT_ERROR_NONE) {
584 TC_PRT("Total number of AppKeys bound to the model [%d]", total);
585 print_model_handle(model);
587 for (l = appkeylist; l != NULL; l = l->next) {
588 bt_mesh_appkey_h appkey = (bt_mesh_appkey_h) l->data;
589 print_appkey_handle(appkey);
594 void __bt_mesh_model_subscription_op_cb(int result, bt_mesh_model_subscription_op_e op,
595 bt_mesh_model_h model, bt_mesh_group_h group, void *user_data)
597 TC_PRT("bt_mesh_model_subscription_op_cb");
598 TC_PRT("result: %s", __bt_get_error_message(result));
600 if (result == BT_ERROR_NONE) {
603 TC_PRT("Model Subscription Operation is ADD");
606 TC_PRT("Model Subscription Operation is DELETE");
609 TC_PRT("Model Subscription Operation is DELETE ALL");
612 TC_PRT("Model Subscription Operation is OVERWRITE");
615 TC_PRT("Invalid Model Subscription Operation");
618 print_model_handle(model);
619 print_group_handle(group);
623 bool __bt_mesh_model_subscription_list_cb(int result, bt_mesh_model_h model, int total, const GSList *sub_addr,
627 TC_PRT("bt_mesh_model_subscription_list_cb");
628 TC_PRT("result: %s", __bt_get_error_message(result));
629 if (result == BT_ERROR_NONE) {
630 TC_PRT("Total number of AppKeys bound to the model [%d]", total);
631 print_model_handle(model);
633 for (l = sub_addr; l != NULL; l = l->next) {
634 bt_mesh_group_h group = (bt_mesh_group_h) l->data;
635 print_group_handle(group);
641 void __bt_mesh_model_publication_status_cb(int result, bt_mesh_model_h model, bt_mesh_group_h group,
642 bt_mesh_appkey_h appkey, void *user_data)
644 TC_PRT("bt_mesh_model_publication_status_cb");
645 TC_PRT("result: %s", __bt_get_error_message(result));
647 if (result == BT_ERROR_NONE) {
648 print_model_handle(model);
649 print_group_handle(group);
650 print_appkey_handle(appkey);
654 void __bt_mesh_network_create_cb(int result, bt_mesh_network_h network, const char *network_name, void *user_data)
656 TC_PRT("bt_mesh_network_create_cb");
657 TC_PRT("result: %s", __bt_get_error_message(result));
658 print_network_handle(network);
661 bool __bt_mesh_appkey_info_cb(int result, bt_mesh_network_h network, int total,
662 bt_mesh_netkey_h netkey, bt_mesh_appkey_h appkey, uint16_t appkey_index, void *user_data)
664 TC_PRT("bt_mesh_network_appkey_info_cb");
665 TC_PRT("result: %s", __bt_get_error_message(result));
666 //print_network_handle(network);
667 //print_netkey_handle(netkey);
668 print_appkey_handle(appkey);
669 TC_PRT("Total appkeys are [%d]",total);
673 bool __bt_mesh_network_netkey_info_cb(int result, bt_mesh_network_h network, int total,
674 bt_mesh_netkey_h netkey, uint16_t netkey_index, void *user_data)
676 TC_PRT("bt_mesh_network_netkey_info_cb");
677 TC_PRT("result: %s", __bt_get_error_message(result));
678 //print_network_handle(network);
679 print_netkey_handle(netkey);
680 TC_PRT("Total netkeys are [%d]",total);
681 if (result == BT_ERROR_NONE && netkey_index == 0) {
682 TC_PRT("Attempt to delete Primary Subnet");
683 result = bt_mesh_netkey_delete(netkey);
684 TC_PRT("return %s\n", __bt_get_error_message(result));
685 if (result == BT_ERROR_NONE)
686 TC_PRT("Primary netkey is deleted");
688 TC_PRT("Primary NetKey deletion failed");
693 void __bt_mesh_network_scan_unprovisioned_device_result_cb(int result, bt_mesh_network_h network,
694 bt_mesh_scanning_state_e state, bt_mesh_scan_result_s *scan_res, void *user_data)
696 TC_PRT("bt_mesh_network_scan_unprovisioned_device_result_cb");
697 TC_PRT("result: %s", __bt_get_error_message(result));
698 if (state == BT_MESH_SCANNING_STARTED) {
699 TC_PRT("The scanning state is: STARTED");
700 print_network_handle(network);
702 else if (state == BT_MESH_SCANNING_FINISHED) {
703 TC_PRT("The scanning state is: STOPPED");
704 print_network_handle(network);
707 TC_PRT("Scan Result found");
708 TC_PRT("Device UUID is %s\n", scan_res->uuid);
709 TC_PRT("RSSI values is %d\n", scan_res->rssi);
710 TC_PRT("OOB Info 0x%x\n", scan_res->oob_info);
714 void __bt_mesh_network_device_provision_cb(int result, bt_mesh_network_h network,
715 const char* dev_uuid, void* user_data)
717 TC_PRT("bt_mesh_network_device_provision_cb");
718 TC_PRT("result: %s", __bt_get_error_message(result));
719 print_network_handle(network);
721 TC_PRT("dev_uuid is NULL");
723 TC_PRT("The device_uuid is [%s]", dev_uuid);
724 device_uuid = g_strdup(dev_uuid);
728 void __bt_mesh_authentication_request_cb(int result, bt_mesh_authentication_type_e auth_type,
729 char *auth_value, void *user_data)
731 TC_PRT("bt_mesh_authentication_request_cb");
732 TC_PRT("result: %s", __bt_get_error_message(result));
733 TC_PRT("auth_value is [%s]", auth_value);
734 TC_PRT("auth_type is [%d]", auth_type);
735 request_type = auth_type;
738 int test_set_params(int test_id, char *param){
739 static int param_index = 0;
742 if (param_index > 0 && param_index == g_test_param.param_count)
744 switch (current_tc_table) {
745 case BT_MESH_UNIT_TEST_TABLE_NETWORK: {
747 case BT_MESH_UNIT_TEST_FUNCTION_NETWORK_CREATE:
749 switch(param_index) {
751 TC_PRT("Input param(%d) (network_name)\n",param_index + 1);
754 TC_PRT("Input param(%d) (Node Handle)\n",param_index + 1);
758 case BT_MESH_UNIT_TEST_FUNCTION_NODE_DESTROY:
760 TC_PRT("Input param(%d) (node Handle)\n",param_index + 1);
762 case BT_MESH_UNIT_TEST_FUNCTION_NODE_GET_NETWORK:
764 TC_PRT("Input param(%d) (node Handle)\n",param_index + 1);
766 case BT_MESH_UNIT_TEST_FUNCTION_NODE_CREATE_ELEMENT:
768 TC_PRT("Input param(%d) (node Handle)\n",param_index + 1);
770 case BT_MESH_UNIT_TEST_FUNCTION_ELEMENT_CREATE_MODEL:
772 switch(param_index) {
774 TC_PRT("Input param(%d) (Element Handle)\n" ,param_index + 1);
777 TC_PRT("Input param(%d) (Model ID)\n",param_index + 1);
781 case BT_MESH_UNIT_TEST_FUNCTION_ELEMENT_GET_NODE:
783 TC_PRT("Input param(%d) (Element Handle)\n",param_index + 1);
785 case BT_MESH_UNIT_TEST_FUNCTION_MODEL_GET_ID:
787 TC_PRT("Input param(%d) (Model Handle)\n",param_index + 1);
789 case BT_MESH_UNIT_TEST_FUNCTION_MODEL_DESTROY:
791 TC_PRT("Input param(%d) (Model Handle)\n",param_index + 1);
793 case BT_MESH_UNIT_TEST_FUNCTION_MODEL_GET_ELEMENT:
795 TC_PRT("Input param(%d) (Model Handle)\n",param_index + 1);
797 case BT_MESH_UNIT_TEST_FUNCTION_ELEMENT_DESTROY:
799 TC_PRT("Input param(%d) (Element Handle)\n",param_index + 1);
801 case BT_MESH_UNIT_TEST_FUNCTION_NODE_FOREACH_ELEMENTS:
803 TC_PRT("Input param(%d) (Node Handle)", param_index + 1);
805 case BT_MESH_UNIT_TEST_FUNCTION_ELEMENT_FOREACH_MODELS:
807 TC_PRT("Input param(%d) (Element Handle)", param_index + 1);
809 case BT_MESH_UNIT_TEST_FUNCTION_NETWORK_CREATE_GROUP:
811 TC_PRT("Input param(%d) (group address)\n" ,param_index + 1);
813 case BT_MESH_UNIT_TEST_FUNCTION_NETWORK_REMOVE_GROUP:
815 TC_PRT("Input param(%d) (group handle)\n" ,param_index + 1);
817 case BT_MESH_UNIT_TEST_FUNCTION_NETWORK_UNPROVISIONED_DEVICE_SCAN:
819 TC_PRT("Input param(%d) (Seconds)\n" ,param_index + 1);
821 case BT_MESH_UNIT_TEST_FUNCTION_NETWORK_PROVISION_DEVICE:
823 TC_PRT("Input param(%d) (device_uuid)\n",param_index+1);
825 case BT_MESH_UNIT_TEST_FUNCTION_NETWORK_SET_NAME:
827 TC_PRT("Input param(%d) (network_name)",param_index + 1);
829 case BT_MESH_UNIT_TEST_FUNCTION_MESH_AUTHENTICATION_REPLY:
831 switch(param_index) {
833 TC_PRT("Input param(%d) (auth_value)\n",param_index +1);
836 TC_PRT("Input param(%d) (auth_reply)\n",param_index + 1);
837 TC_PRT("0: false, 1: true");
841 case BT_MESH_UNIT_TEST_FUNCTION_NETWORK_SET_PROVISIONING_CAPABILITIES:
843 switch(param_index) {
845 TC_PRT("\nInput param(%d) is_public_oob",param_index + 1);
846 TC_PRT("0: false, 1: true\n");
849 TC_PRT("\nInput param(%d) is_static_oob",param_index + 1);
850 TC_PRT("0: false, 1 : true\n");
853 TC_PRT("\nInput param(%d) output_oob",param_index + 1);
854 TC_PRT("BT_MESH_OUT_OOB_METHOD_BLINK = 0x01");
855 TC_PRT("BT_MESH_OUT_OOB_METHOD_BEEP = 0x02");
856 TC_PRT("BT_MESH_OUT_OOB_METHOD_VIBRATE = 0x04");
857 TC_PRT("BT_MESH_OUT_OOB_METHOD_NUMERIC = 0x08");
858 TC_PRT("BT_MESH_OUT_OOB_METHOD_ALPHANUMERIC = 0x10\n");
861 TC_PRT("\nInput param(%d) input_oob",param_index + 1);
862 TC_PRT("BT_MESH_IN_OOB_METHOD_PUSH = 0x01");
863 TC_PRT("BT_MESH_IN_OOB_METHOD_TWIST = 0x02");
864 TC_PRT("BT_MESH_IN_OOB_METHOD_NUMERIC = 0x04");
865 TC_PRT("BT_MESH_IN_OOB_METHOD_ALPHANUMERIC = 0x08\n");
869 case BT_MESH_UNIT_TEST_FUNCTION_NETKEY_GET_INDEX:
871 TC_PRT("Input param(%d) (NetKey Handle)", param_index + 1);
873 case BT_MESH_UNIT_TEST_FUNCTION_NETKEY_UPDATE:
875 TC_PRT("Input param(%d) (NetKey Handle)", param_index + 1);
877 case BT_MESH_UNIT_TEST_FUNCTION_NETKEY_DELETE:
879 TC_PRT("Input param(%d) (NetKey Handle)", param_index + 1);
881 case BT_MESH_UNIT_TEST_FUNCTION_NETKEY_ADD_APPKEY:
883 TC_PRT("Input param(%d) (NetKey Handle)", param_index + 1);
885 case BT_MESH_UNIT_TEST_FUNCTION_NETKEY_FOREACH_APPKEYS:
887 TC_PRT("Input param(%d) (NetKey Handle)", param_index + 1);
889 case BT_MESH_UNIT_TEST_FUNCTION_APPKEY_GET_INDEX:
891 TC_PRT("Input param(%d) (AppKey Handle)", param_index + 1);
893 case BT_MESH_UNIT_TEST_FUNCTION_APPKEY_UPDATE:
895 TC_PRT("Input param(%d) (AppKey Handle)", param_index + 1);
897 case BT_MESH_UNIT_TEST_FUNCTION_APPKEY_DELETE:
899 TC_PRT("Input param(%d) (AppKey Handle)", param_index + 1);
901 case BT_MESH_UNIT_TEST_FUNCTION_ACTIVATE_FLAG_TO_SET_PARAMETERS:
902 need_to_set_params = true;
903 TC_PRT("\nSelect the function again\n");
906 TC_PRT("There is no parameter to set\n");
911 case BT_MESH_UNIT_TEST_TABLE_CONFIGURATION: {
913 case BT_MESH_UNIT_TEST_FUNCTION_MESH_NETWORK_DISCOVER_NODE:
915 TC_PRT("Input param(%d) (device_uuid)", param_index + 1);
917 case BT_MESH_UNIT_TEST_FUNCTION_NODE_GET_FEATURES:
919 TC_PRT("Input param(%d) (Node Handle)", param_index + 1);
921 case BT_MESH_UNIT_TEST_FUNCTION_NODE_GET_NETKEYS:
923 TC_PRT("Input param(%d) (Node Handle)", param_index + 1);
925 case BT_MESH_UNIT_TEST_FUNCTION_NODE_GET_APPKEYS:
927 switch(param_index) {
929 TC_PRT("Input param(%d) (Node Handle)", param_index + 1);
932 TC_PRT("Input param(%d) (Netkey Handle)\n", param_index + 1);
936 case BT_MESH_UNIT_TEST_FUNCTION_APPKEY_GET_NETKEY:
938 TC_PRT("Input param(%d) (AppKey Handle)\n", param_index + 1);
940 case BT_MESH_UNIT_TEST_FUNCTION_MODEL_GET_PUBLICATION:
942 TC_PRT("Input param(%d) (Model Handle)\n", param_index + 1);
944 case BT_MESH_UNIT_TEST_FUNCTION_MODEL_SEND_MSG:
946 switch(param_index) {
948 TC_PRT("Input param(%d) (Model Handle)\n", param_index + 1);
951 TC_PRT("Input param(%d) (Appkey Handle)\n", param_index + 1);
954 TC_PRT("Input param(%d) (opcode)\n", param_index + 1);
957 TC_PRT("Input param(%d) (Message)\n", param_index + 1);
961 case BT_MESH_UNIT_TEST_FUNCTION_MODEL_SET_PUBLICATION:
963 switch(param_index) {
965 TC_PRT("\nInput param(%d) Model handle\n", param_index + 1);
968 TC_PRT("\nInput param(%d) AppKey handle\n", param_index + 1);
971 TC_PRT("\nInput param(%d) Group Handle\n", param_index + 1);
975 case BT_MESH_UNIT_TEST_FUNCTION_MODEL_GET_SUBSCRIPTION_LIST:
977 TC_PRT("Input param(%d) (Model Handle)\n", param_index + 1);
979 case BT_MESH_UNIT_TEST_FUNCTION_MODEL_CONFIGURE_GROUP_SUBSCRIPTION:
980 case BT_MESH_UNIT_TEST_FUNCTION_MODEL_CONFIGURE_VIRTUAL_GROUP_SUBSCRIPTION:
982 switch(param_index) {
984 TC_PRT("\nInput param(%d) Model handle\n", param_index + 1);
987 TC_PRT("\nInput param(%d) Model operation", param_index + 1);
988 TC_PRT("BT_MESH_MODEL_SUBSCRIPTION_ADD = 0");
989 TC_PRT("BT_MESH_MODEL_SUBSCRIPTION_DELETE = 1");
990 TC_PRT("BT_MESH_MODEL_SUBSCRIPTION_DELETE_ALL = 2");
991 TC_PRT("BT_MESH_MODEL_SUBSCRIPTION_OVERWRITE = 3\n");
994 TC_PRT("\nInput param(%d) Group Handle\n", param_index + 1);
998 case BT_MESH_UNIT_TEST_FUNCTION_MODEL_GET_APPKEY_LIST:
1000 TC_PRT("Input param(%d) (Model Handle)\n", param_index + 1);
1002 case BT_MESH_UNIT_TEST_FUNCTION_MODEL_BIND_APPKEY:
1003 case BT_MESH_UNIT_TEST_FUNCTION_MODEL_UNBIND_APPKEY:
1005 switch(param_index) {
1007 TC_PRT("\nInput param(%d) Model Handle\n", param_index + 1);
1010 TC_PRT("\nInput param(%d) AppKey handle\n", param_index + 1);
1014 case BT_MESH_UNIT_TEST_FUNCTION_NODE_CONFIGURE_NETKEY:
1015 case BT_MESH_UNIT_TEST_FUNCTION_NODE_CONFIGURE_APPKEY:
1017 switch(param_index) {
1019 TC_PRT("\nInput param(%d) Node Handle\n", param_index + 1);
1022 TC_PRT("\nInput param(%d) Key Handle\n", param_index + 1);
1025 TC_PRT("\nInput param(%d) Key Config Option", param_index + 1);
1026 TC_PRT("BT_MESH_NODE_KEY_ADD = 0");
1027 TC_PRT("BT_MESH_NODE_KEY_UPDATE = 1");
1028 TC_PRT("BT_MESH_NODE_KEY_DELETE = 2\n");
1032 case BT_MESH_UNIT_TEST_FUNCTION_NODE_GET_TTL:
1034 TC_PRT("\nInput param(%d) Node Handle\n", param_index + 1);
1036 case BT_MESH_UNIT_TEST_FUNCTION_NODE_SET_TTL:
1038 switch(param_index) {
1040 TC_PRT("\nInput param(%d) Node Handle\n", param_index + 1);
1043 TC_PRT("\nInput param(%d) TTL value\n", param_index + 1);
1048 TC_PRT("There is no parameter to set\n");
1054 TC_PRT("There is no parameter to set\n");
1055 need_to_set_params = false;
1059 if (need_to_set_params) {
1060 if (param_index == 0) {
1061 g_test_param.param_count = param_count;
1062 g_test_param.params = g_malloc0(sizeof(char*) * g_test_param.param_count);
1065 if (param_index > 0) {
1066 int len = strlen(param);
1067 param[len - 1] = '\0';
1068 g_test_param.params[param_index - 1] = g_strdup(param);
1071 if (param_index == g_test_param.param_count) {
1072 need_to_set_params = false;
1074 test_input_callback((void *)(uintptr_t)test_id);
1076 test_input_callback((void *)test_id);
1088 int test_input_callback(void *data)
1092 int test_id = (uintptr_t)data;
1094 int test_id = (int)data;
1097 switch (current_tc_table) {
1098 case BT_MESH_UNIT_TEST_TABLE_MAIN: {
1101 TC_PRT("Finished\n");
1102 g_main_loop_quit(main_loop);
1104 case BT_MESH_UNIT_TEST_FUNCTION_INITIALIZE:
1105 ret = bt_mesh_initialize();
1106 TC_PRT("return %s\n", __bt_get_error_message(ret));
1108 case BT_MESH_UNIT_TEST_FUNCTION_DEINITIALIZE:
1109 ret = bt_mesh_deinitialize();
1110 TC_PRT("return %s\n", __bt_get_error_message(ret));
1117 case BT_MESH_UNIT_TEST_TABLE_NETWORK:{
1119 case BT_MESH_UNIT_TEST_FUNCTION_NODE_CREATE:{
1120 bt_mesh_node_features_s features;
1121 features.features = BT_MESH_FEATURE_RELAY;
1122 features.features |= BT_MESH_FEATURE_LOWPOWER;
1124 ret = bt_mesh_node_create(&features, &local_node);
1125 TC_PRT("return %s\n", __bt_get_error_message(ret));
1126 if (ret == BT_ERROR_NONE)
1127 print_node_handle(local_node);
1130 case BT_MESH_UNIT_TEST_FUNCTION_NODE_DESTROY: {
1131 bt_mesh_node_h node_h;
1132 if (g_test_param.param_count != 1) {
1133 TC_PRT("Enter parameters first!");
1136 node_h = GUINT_TO_POINTER(strtoul(g_test_param.params[0], NULL, 16));
1137 ret = bt_mesh_node_destroy(node_h);
1138 TC_PRT("return %s\n", __bt_get_error_message(ret));
1141 case BT_MESH_UNIT_TEST_FUNCTION_NODE_GET_NETWORK: {
1142 bt_mesh_network_h net_h;
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_get_network(node_h, &net_h);
1150 TC_PRT("return %s\n", __bt_get_error_message(ret));
1151 if (ret == BT_ERROR_NONE)
1152 print_network_handle(net_h);
1155 case BT_MESH_UNIT_TEST_FUNCTION_NODE_CREATE_ELEMENT: {
1156 bt_mesh_element_h elem_h;
1157 bt_mesh_node_h node_h;
1158 if (g_test_param.param_count != 1) {
1159 TC_PRT("Enter parameters first!");
1162 node_h = GUINT_TO_POINTER(strtoul(g_test_param.params[0], NULL, 16));
1163 ret = bt_mesh_node_create_element(node_h, &elem_h);
1164 TC_PRT("return %s\n", __bt_get_error_message(ret));
1165 if (ret == BT_ERROR_NONE)
1166 print_element_handle(elem_h);
1169 case BT_MESH_UNIT_TEST_FUNCTION_ELEMENT_CREATE_MODEL: {
1170 bt_mesh_element_h elem_h;
1171 bt_mesh_model_h model_h;
1172 bt_mesh_model_id_s mod_id;
1173 memset(&mod_id, 0x00, sizeof(bt_mesh_model_id_s));
1175 if (g_test_param.param_count != 2) {
1176 TC_PRT("Enter parameters first!");
1179 elem_h = GUINT_TO_POINTER(strtoul(g_test_param.params[0], NULL, 16));
1180 mod_id.model_id = strtoul(g_test_param.params[1], NULL, 16);
1181 mod_id.company_id = 0xFFFF;
1182 TC_PRT("The model_id is [0x%2.2x]\n", mod_id.model_id);
1183 ret = bt_mesh_element_create_model(elem_h, &mod_id, &model_h);
1184 TC_PRT("return %s\n", __bt_get_error_message(ret));
1185 if (ret == BT_ERROR_NONE)
1186 print_model_handle(model_h);
1189 case BT_MESH_UNIT_TEST_FUNCTION_ELEMENT_GET_NODE: {
1190 bt_mesh_element_h elem_h;
1191 bt_mesh_node_h node_h;
1192 if (g_test_param.param_count != 1) {
1193 TC_PRT("Enter parameter first!");
1196 elem_h = GUINT_TO_POINTER(strtoul(g_test_param.params[0], NULL, 16));
1197 ret = bt_mesh_element_get_node(elem_h, &node_h);
1198 TC_PRT("return %s\n", __bt_get_error_message(ret));
1200 if (ret == BT_ERROR_NONE)
1201 print_node_handle(node_h);
1204 case BT_MESH_UNIT_TEST_FUNCTION_MODEL_GET_ID: {
1205 bt_mesh_model_id_s model_id;
1206 memset(&model_id, 0x00, sizeof(bt_mesh_model_id_s));
1207 bt_mesh_model_h mod_h;
1208 if (g_test_param.param_count != 1) {
1209 TC_PRT("Enter parameter first!");
1212 mod_h = GUINT_TO_POINTER(strtoul(g_test_param.params[0], NULL, 16));
1213 ret = bt_mesh_model_get_id(mod_h, &model_id);
1214 TC_PRT("return %s\n", __bt_get_error_message(ret));
1215 if (ret == BT_ERROR_NONE) {
1216 TC_PRT("The Model ID is [0x%2.2x]", model_id.model_id);
1217 TC_PRT("The Company ID is [0x%2.2x]", model_id.company_id);
1221 case BT_MESH_UNIT_TEST_FUNCTION_MODEL_DESTROY: {
1222 bt_mesh_model_h mod_h;
1223 if (g_test_param.param_count != 1) {
1224 TC_PRT("Enter parameter first!");
1227 mod_h = GUINT_TO_POINTER(strtoul(g_test_param.params[0], NULL, 16));
1228 ret = bt_mesh_model_destroy(mod_h);
1229 TC_PRT("return %s\n", __bt_get_error_message(ret));
1232 case BT_MESH_UNIT_TEST_FUNCTION_MODEL_GET_ELEMENT: {
1233 bt_mesh_model_h mod_h;
1234 bt_mesh_element_h elem_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_get_element(mod_h, &elem_h);
1241 TC_PRT("return %s\n", __bt_get_error_message(ret));
1242 if (ret == BT_ERROR_NONE)
1243 print_element_handle(elem_h);
1246 case BT_MESH_UNIT_TEST_FUNCTION_ELEMENT_DESTROY: {
1247 bt_mesh_element_h elem_h;
1248 if (g_test_param.param_count != 1) {
1249 TC_PRT("Enter parameter first!");
1252 elem_h = GUINT_TO_POINTER(strtoul(g_test_param.params[0], NULL, 16));
1253 ret = bt_mesh_element_destroy(elem_h);
1254 TC_PRT("return %s\n", __bt_get_error_message(ret));
1257 case BT_MESH_UNIT_TEST_FUNCTION_NODE_FOREACH_ELEMENTS: {
1258 bt_mesh_node_h node_h = 0;
1259 if (g_test_param.param_count != 1){
1260 TC_PRT("Enter Input parameter first.\n");
1263 node_h = GUINT_TO_POINTER(strtoul(g_test_param.params[0], NULL, 16));
1264 ret = bt_mesh_node_foreach_element(node_h, __bt_mesh_node_foreach_elem_cb, NULL);
1265 TC_PRT("return %s\n", __bt_get_error_message(ret));
1268 case BT_MESH_UNIT_TEST_FUNCTION_ELEMENT_FOREACH_MODELS: {
1269 bt_mesh_element_h element_h = 0;
1270 if (g_test_param.param_count != 1){
1271 TC_PRT("Enter Input parameter first.\n");
1274 element_h = GUINT_TO_POINTER(strtoul(g_test_param.params[0], NULL, 16));
1275 ret = bt_mesh_element_foreach_models(element_h, __bt_mesh_elem_foreach_model_cb, NULL);
1276 TC_PRT("return %s\n", __bt_get_error_message(ret));
1279 case BT_MESH_UNIT_TEST_FUNCTION_NETWORK_CREATE: {
1280 char* network_name = "Mesh Test Network";
1281 bt_mesh_node_h node_h;
1282 if (g_test_param.param_count != 2) {
1283 TC_PRT("Enter Input parameter first.\n");
1286 network_name = g_strdup(g_test_param.params[0]);
1287 node_h = GUINT_TO_POINTER(strtoul(g_test_param.params[1], NULL, 16));
1288 ret = bt_mesh_network_create(node_h, (const char*)network_name, &network, &token);
1289 TC_PRT("return %s\n", __bt_get_error_message(ret));
1290 if (ret == BT_ERROR_NONE) {
1291 TC_PRT("Network Created, token [%s]", token);
1292 print_network_handle(network);
1294 g_free(network_name);
1297 case BT_MESH_UNIT_TEST_FUNCTION_NETWORK_LOAD: {
1299 if (g_test_param.param_count != 1) {
1300 TC_PRT("Enter parameter first!");
1303 token_str = g_strdup(g_test_param.params[0]);
1304 ret = bt_mesh_network_load(token_str, &network);
1305 TC_PRT("return %s\n", __bt_get_error_message(ret));
1306 if (ret == BT_ERROR_NONE)
1307 print_network_handle(network);
1311 case BT_MESH_UNIT_TEST_FUNCTION_NETWORK_SET_NAME: {
1312 char* network_name="tempName";
1313 if (g_test_param.param_count != 1) {
1314 TC_PRT("Enter parameter first!");
1317 network_name = g_strdup(g_test_param.params[0]);
1318 ret = bt_mesh_network_set_name(network,(const char*)network_name);
1319 TC_PRT("return %s\n", __bt_get_error_message(ret));
1320 g_free(network_name);
1323 case BT_MESH_UNIT_TEST_FUNCTION_NETWORK_GET_NAME: {
1325 ret = bt_mesh_network_get_name(network, &network_name);
1326 TC_PRT("return %s\n", __bt_get_error_message(ret));
1327 if (ret == BT_ERROR_NONE)
1328 TC_PRT("network name is [%s]", network_name);
1331 case BT_MESH_UNIT_TEST_FUNCTION_NETWORK_ADD_NETKEY: {
1333 bt_mesh_netkey_h n_h;
1334 ret = bt_mesh_network_add_netkey(network, &n_h);
1335 TC_PRT("return %s\n", __bt_get_error_message(ret));
1336 if (ret == BT_ERROR_NONE)
1337 print_netkey_handle(n_h);
1340 case BT_MESH_UNIT_TEST_FUNCTION_NETWORK_FOREACH_NETKEYS: {
1341 ret = bt_mesh_network_foreach_netkeys(network,
1342 __bt_mesh_network_netkey_info_cb, NULL);
1343 TC_PRT("return %s\n", __bt_get_error_message(ret));
1346 case BT_MESH_UNIT_TEST_FUNCTION_NETKEY_GET_INDEX: {
1347 uint16_t index = 0xFFFF;
1348 bt_mesh_netkey_h netkey_h;
1350 if (g_test_param.param_count != 1) {
1351 TC_PRT("Set parameter first!");
1354 netkey_h = GUINT_TO_POINTER(strtoul(g_test_param.params[0], NULL, 16));
1355 /* Get index for netkey 1 */
1356 ret = bt_mesh_netkey_get_index(netkey_h, &index);
1357 TC_PRT("return %s\n", __bt_get_error_message(ret));
1358 if (ret == BT_ERROR_NONE)
1359 TC_PRT("The index of the netkey is: [%d]", index);
1363 case BT_MESH_UNIT_TEST_FUNCTION_NETKEY_UPDATE: {
1364 bt_mesh_netkey_h netkey_h;
1366 if (g_test_param.param_count != 1) {
1367 TC_PRT("Set parameter first!");
1370 netkey_h = GUINT_TO_POINTER(strtoul(g_test_param.params[0], NULL, 16));
1371 ret = bt_mesh_netkey_update(netkey_h);
1372 TC_PRT("return %s\n", __bt_get_error_message(ret));
1375 case BT_MESH_UNIT_TEST_FUNCTION_NETKEY_DELETE: {
1376 bt_mesh_netkey_h netkey_h;
1378 if (g_test_param.param_count != 1) {
1379 TC_PRT("Set parameter first!");
1382 netkey_h = GUINT_TO_POINTER(strtoul(g_test_param.params[0], NULL, 16));
1383 ret = bt_mesh_netkey_delete(netkey_h);
1384 TC_PRT("return %s\n", __bt_get_error_message(ret));
1385 if (ret == BT_ERROR_NONE)
1386 TC_PRT("netkey is deleted");
1389 case BT_MESH_UNIT_TEST_FUNCTION_NETKEY_ADD_APPKEY: {
1390 bt_mesh_netkey_h netkey_h;
1391 bt_mesh_appkey_h appkey_h;
1393 if (g_test_param.param_count != 1) {
1394 TC_PRT("Set parameter first!");
1397 netkey_h = GUINT_TO_POINTER(strtoul(g_test_param.params[0], NULL, 16));
1398 ret = bt_mesh_netkey_add_appkey(netkey_h, &appkey_h);
1399 TC_PRT("return %s\n", __bt_get_error_message(ret));
1400 if (ret == BT_ERROR_NONE)
1401 print_appkey_handle(appkey_h);
1404 case BT_MESH_UNIT_TEST_FUNCTION_NETKEY_FOREACH_APPKEYS: {
1405 /* Get all appkeys for NetKey 1 */
1406 bt_mesh_netkey_h netkey_h;
1408 if (g_test_param.param_count != 1) {
1409 TC_PRT("Set parameter first!");
1412 netkey_h = GUINT_TO_POINTER(strtoul(g_test_param.params[0], NULL, 16));
1413 ret = bt_mesh_netkey_foreach_appkeys(netkey_h, __bt_mesh_appkey_info_cb, NULL);
1414 TC_PRT("return %s\n", __bt_get_error_message(ret));
1418 case BT_MESH_UNIT_TEST_FUNCTION_APPKEY_GET_INDEX: {
1419 uint16_t index = 0xFFFF;
1420 bt_mesh_appkey_h appkey_h;
1422 if (g_test_param.param_count != 1) {
1423 TC_PRT("Set parameter first!");
1426 appkey_h = GUINT_TO_POINTER(strtoul(g_test_param.params[0], NULL, 16));
1427 /* Get appkey index for appkey 1 */
1428 ret = bt_mesh_appkey_get_index(appkey_h, &index);
1429 TC_PRT("return %s\n", __bt_get_error_message(ret));
1430 if (ret == BT_ERROR_NONE)
1431 TC_PRT("The index of the appkey is: [%d]", index);
1434 case BT_MESH_UNIT_TEST_FUNCTION_APPKEY_UPDATE: {
1435 bt_mesh_appkey_h appkey_h;
1437 if (g_test_param.param_count != 1) {
1438 TC_PRT("Set parameter first!");
1441 appkey_h = GUINT_TO_POINTER(strtoul(g_test_param.params[0], NULL, 16));
1442 ret = bt_mesh_appkey_update(appkey_h);
1443 TC_PRT("return %s\n", __bt_get_error_message(ret));
1446 case BT_MESH_UNIT_TEST_FUNCTION_APPKEY_DELETE: {
1447 bt_mesh_appkey_h appkey_h;
1449 if (g_test_param.param_count != 1) {
1450 TC_PRT("Set parameter first!");
1453 appkey_h = GUINT_TO_POINTER(strtoul(g_test_param.params[0], NULL, 16));
1454 ret = bt_mesh_appkey_delete(appkey_h);
1455 TC_PRT("return %s\n", __bt_get_error_message(ret));
1456 if (ret == BT_ERROR_NONE)
1457 TC_PRT("appkey is deleted");
1460 case BT_MESH_UNIT_TEST_FUNCTION_NETWORK_FOREACH_DEVICES: {
1461 ret = bt_mesh_network_foreach_devices(network, __bt_mesh_network_device_info_cb, NULL);
1462 TC_PRT("return %s\n", __bt_get_error_message(ret));
1465 case BT_MESH_UNIT_TEST_FUNCTION_NETWORK_CREATE_GROUP: {
1466 uint16_t group_addr = 0xc001;
1467 bt_mesh_group_h group_h;
1468 if (g_test_param.param_count != 1) {
1469 TC_PRT("Enter parameter first!!\n");
1472 group_addr = strtoul(g_test_param.params[0], NULL, 16);
1473 TC_PRT("Group addrrss [0x%2.2x]", group_addr);
1474 ret = bt_mesh_network_create_group(network, group_addr, &group_h);
1475 TC_PRT("return %s\n", __bt_get_error_message(ret));
1476 if (ret == BT_ERROR_NONE)
1477 print_group_handle(group_h);
1480 case BT_MESH_UNIT_TEST_FUNCTION_NETWORK_CREATE_VIRTUAL_GROUP: {
1481 bt_mesh_group_h group_h;
1482 ret = bt_mesh_network_create_virtual_group(network, &group_h);
1483 TC_PRT("return %s\n", __bt_get_error_message(ret));
1484 if (ret == BT_ERROR_NONE)
1485 print_group_handle(group_h);
1488 case BT_MESH_UNIT_TEST_FUNCTION_NETWORK_REMOVE_GROUP: {
1489 bt_mesh_group_h group_h;
1490 if (g_test_param.param_count != 1) {
1491 TC_PRT("Enter parameter first!!\n");
1494 group_h = GUINT_TO_POINTER(strtoul(g_test_param.params[0], NULL, 16));
1495 ret = bt_mesh_network_remove_group(group_h);
1496 TC_PRT("return %s\n", __bt_get_error_message(ret));
1499 case BT_MESH_UNIT_TEST_FUNCTION_NETWORK_FOREACH_GROUPS: {
1500 ret = bt_mesh_network_foreach_groups(network,
1501 __bt_mesh_network_group_info_cb, NULL);
1502 TC_PRT("return %s\n", __bt_get_error_message(ret));
1505 case BT_MESH_UNIT_TEST_FUNCTION_NETWORK_UNPROVISIONED_DEVICE_SCAN: {
1506 bt_mesh_scan_params_s scan_params;
1507 memset(&scan_params, 0x00, sizeof(bt_mesh_scan_params_s));
1508 if(g_test_param.param_count != 1) {
1509 TC_PRT("Enter Input parameter first.\n");
1512 scan_params.seconds = strtoul(g_test_param.params[0], NULL, 16);
1513 TC_PRT("The scan is set for [%u] seconds", scan_params.seconds);
1514 ret = bt_mesh_network_unprovisioned_device_scan(network, &scan_params,
1515 __bt_mesh_network_scan_unprovisioned_device_result_cb, NULL);
1516 TC_PRT("return %s\n", __bt_get_error_message(ret));
1519 case BT_MESH_UNIT_TEST_FUNCTION_STOP_UNPROVISIONED_DEVICE_SCAN: {
1520 ret = bt_mesh_stop_unprovisioned_device_scan(network);
1521 TC_PRT("return %s\n", __bt_get_error_message(ret));
1522 if (ret == BT_ERROR_NONE)
1523 TC_PRT("Device SCAN : STOPPED");
1526 case BT_MESH_UNIT_TEST_FUNCTION_NETWORK_PROVISION_DEVICE: {
1527 const char *dev_uuid = "abababababababababababababababab";
1528 if(g_test_param.param_count != 1) {
1529 TC_PRT("Enter Input parameter first.\n");
1532 dev_uuid = g_test_param.params[0];
1533 TC_PRT("The dev_uuid is [%s]\n",dev_uuid);
1534 ret = bt_mesh_network_provision_device(network, dev_uuid,
1535 __bt_mesh_network_device_provision_cb, NULL);
1536 TC_PRT("return %s\n", __bt_get_error_message(ret));
1539 case BT_MESH_UNIT_TEST_FUNCTION_NETWORK_AUTHENTICATION_SET_REQUEST_CB: {
1540 ret = bt_mesh_authentication_set_request_cb(
1541 __bt_mesh_authentication_request_cb, NULL);
1542 TC_PRT("return %s\n", __bt_get_error_message(ret));
1545 case BT_MESH_UNIT_TEST_FUNCTION_MESH_AUTHENTICATION_REPLY: {
1549 if(g_test_param.param_count !=2){
1550 TC_PRT("Enter Input parameter first.\n");
1553 len = strlen(g_test_param.params[0]);
1554 value = g_malloc0(len+1);
1555 g_strlcpy(value, g_test_param.params[0], len+1);
1556 auth_reply = atoi(g_test_param.params[1]);
1557 TC_PRT("\nauth_value is [%s]\n", value);
1558 TC_PRT("auth_reply is [%d]\n", auth_reply);
1559 TC_PRT("auth_type is [%d]\n", request_type);
1560 ret = bt_mesh_authentication_reply(request_type, (const char*)value, auth_reply);
1561 TC_PRT("return %s\n", __bt_get_error_message(ret));
1564 case BT_MESH_UNIT_TEST_FUNCTION_NETWORK_SET_PROVISIONING_CAPABILITIES: {
1565 bt_mesh_provisioner_capabilities_s capabilities;
1566 if(g_test_param.param_count !=4) {
1567 TC_PRT("Enter Input parameter first.");
1570 capabilities.public_oob = atoi(g_test_param.params[0]);
1571 capabilities.static_oob = atoi(g_test_param.params[1]);
1572 capabilities.out_oob = (int)strtol(g_test_param.params[2], NULL, 16);
1573 capabilities.in_oob = (int)strtol(g_test_param.params[3], NULL, 16);
1574 TC_PRT("CAP: PUBLIC OOB [%d]", capabilities.public_oob);
1575 TC_PRT("CAP: STATIC OOB [%d]", capabilities.static_oob);
1576 TC_PRT("CAP: OUT OOB [%d]", capabilities.out_oob);
1577 TC_PRT("CAP: IN OOB [%d]", capabilities.in_oob);
1578 ret = bt_mesh_network_set_provisioning_capabilities(network, &capabilities);
1579 TC_PRT("return %s\n", __bt_get_error_message(ret));
1582 case BT_MESH_UNIT_TEST_FUNCTION_NETWORK_GET_PROVISIONING_CAPABILITIES: {
1583 // TODO: need to implement
1586 case BT_MESH_UNIT_TEST_FUNCTION_ACTIVATE_FLAG_TO_SET_PARAMETERS: {
1587 need_to_set_params = true;
1588 TC_PRT("Select the function again");
1594 __bt_free_test_param(&g_test_param);
1597 case BT_MESH_UNIT_TEST_TABLE_CONFIGURATION: {
1599 case BT_MESH_UNIT_TEST_FUNCTION_MESH_NETWORK_DISCOVER_NODE: {
1600 char* dev_uu = "tempName";
1601 if (g_test_param.param_count > 0) {
1602 dev_uu = g_strdup(g_test_param.params[0]);
1604 TC_PRT("Set Input parameter first!");
1607 ret = bt_mesh_network_discover_node(network, (const char*)dev_uu,
1608 __bt_mesh_node_discover_status_cb, NULL);
1609 TC_PRT("return %s\n", __bt_get_error_message(ret));
1612 case BT_MESH_UNIT_TEST_FUNCTION_NODE_RESET: {
1613 // TODO: need to implement
1616 case BT_MESH_UNIT_TEST_FUNCTION_NODE_GET_FEATURES: {
1617 bt_mesh_node_h node_h = 0;
1618 if (g_test_param.param_count != 1) {
1619 TC_PRT("Set Input parameter first!");
1622 node_h = GUINT_TO_POINTER(strtoul(g_test_param.params[0], NULL, 16));
1623 ret = bt_mesh_node_get_features(node_h, __bt_mesh_node_features_cb, NULL);
1624 TC_PRT("return %s\n", __bt_get_error_message(ret));
1627 case BT_MESH_UNIT_TEST_FUNCTION_NODE_GET_NETKEYS: {
1628 bt_mesh_node_h node_h = 0;
1629 if (g_test_param.param_count != 1) {
1630 TC_PRT("Set Input parameter first!");
1633 node_h = GUINT_TO_POINTER(strtoul(g_test_param.params[0], NULL, 16));
1634 ret = bt_mesh_node_foreach_netkeys(node_h, __bt_mesh_node_foreach_netkeys_cb, NULL);
1635 TC_PRT("return %s\n", __bt_get_error_message(ret));
1638 case BT_MESH_UNIT_TEST_FUNCTION_NODE_GET_APPKEYS: {
1639 bt_mesh_node_h node_h = 0;
1640 bt_mesh_netkey_h netkey_h = 0;
1641 if (g_test_param.param_count != 2) {
1642 TC_PRT("Set Input parameter first!");
1645 node_h = GUINT_TO_POINTER(strtoul(g_test_param.params[0], NULL, 16));
1646 netkey_h = GUINT_TO_POINTER(strtoul(g_test_param.params[1], NULL, 16));
1648 ret = bt_mesh_node_foreach_appkeys(node_h, netkey_h,
1649 __bt_mesh_node_foreach_appkeys_cb, NULL);
1650 TC_PRT("return %s\n", __bt_get_error_message(ret));
1653 case BT_MESH_UNIT_TEST_FUNCTION_NODE_GET_TTL: {
1654 bt_mesh_node_h node_h = 0;
1655 if (g_test_param.param_count != 1) {
1656 TC_PRT("Set Input parameter first!");
1659 node_h = GUINT_TO_POINTER(strtoul(g_test_param.params[0], NULL, 16));
1660 ret = bt_mesh_node_get_ttl(node_h, __bt_mesh_node_ttl_cb, NULL);
1661 TC_PRT("return %s\n", __bt_get_error_message(ret));
1664 case BT_MESH_UNIT_TEST_FUNCTION_NODE_SET_TTL: {
1665 bt_mesh_node_h node_h = 0;
1667 if (g_test_param.param_count != 2) {
1668 TC_PRT("Set Input parameter first!");
1671 node_h = GUINT_TO_POINTER(strtoul(g_test_param.params[0], NULL, 16));
1672 ttl = atoi(g_test_param.params[1]);
1674 ret = bt_mesh_node_set_ttl(node_h, (uint8_t) ttl, __bt_mesh_node_ttl_cb, NULL);
1675 TC_PRT("return %s\n", __bt_get_error_message(ret));
1678 case BT_MESH_UNIT_TEST_FUNCTION_NODE_CONFIGURE_NETKEY: {
1679 bt_mesh_node_h node_h = 0;
1680 bt_mesh_netkey_h netkey_h = 0;
1681 bt_mesh_node_key_configuration_e config = 0;
1682 if (g_test_param.param_count != 3) {
1683 TC_PRT("Set Input parameter first!");
1686 node_h = GUINT_TO_POINTER(strtoul(g_test_param.params[0], NULL, 16));
1687 netkey_h = GUINT_TO_POINTER(strtoul(g_test_param.params[1], NULL, 16));
1688 config = atoi(g_test_param.params[2]);
1690 ret = bt_mesh_node_configure_netkey(node_h, config, netkey_h,
1691 __bt_mesh_node_configure_netkey_cb, NULL);
1692 TC_PRT("return %s\n", __bt_get_error_message(ret));
1695 case BT_MESH_UNIT_TEST_FUNCTION_NODE_CONFIGURE_APPKEY: {
1696 bt_mesh_node_h node_h = 0;
1697 bt_mesh_appkey_h appkey_h = 0;
1698 bt_mesh_node_key_configuration_e config = 0;
1699 if (g_test_param.param_count != 3) {
1700 TC_PRT("Set Input parameter first!");
1703 node_h = GUINT_TO_POINTER(strtoul(g_test_param.params[0], NULL, 16));
1704 appkey_h = GUINT_TO_POINTER(strtoul(g_test_param.params[1], NULL, 16));
1705 config = atoi(g_test_param.params[2]);
1707 ret = bt_mesh_node_configure_appkey(node_h, config, appkey_h,
1708 __bt_mesh_node_configure_appkey_cb, NULL);
1709 TC_PRT("return %s\n", __bt_get_error_message(ret));
1712 case BT_MESH_UNIT_TEST_FUNCTION_MODEL_BIND_APPKEY: {
1713 bt_mesh_model_h model_h = 0;
1714 bt_mesh_appkey_h appkey_h = 0;
1715 if (g_test_param.param_count != 2) {
1716 TC_PRT("Set Input parameter first!");
1719 model_h = GUINT_TO_POINTER(strtoul(g_test_param.params[0], NULL, 16));
1720 appkey_h = GUINT_TO_POINTER(strtoul(g_test_param.params[1], NULL, 16));
1722 ret = bt_mesh_model_bind_appkey(model_h, appkey_h, __bt_mesh_model_bind_cb, NULL);
1723 TC_PRT("return %s\n", __bt_get_error_message(ret));
1726 case BT_MESH_UNIT_TEST_FUNCTION_MODEL_UNBIND_APPKEY: {
1727 bt_mesh_model_h model_h = 0;
1728 bt_mesh_appkey_h appkey_h = 0;
1729 if (g_test_param.param_count != 2) {
1730 TC_PRT("Set Input parameter first!");
1733 model_h = GUINT_TO_POINTER(strtoul(g_test_param.params[0], NULL, 16));
1734 appkey_h = GUINT_TO_POINTER(strtoul(g_test_param.params[1], NULL, 16));
1736 ret = bt_mesh_model_unbind_appkey(model_h, appkey_h, __bt_mesh_model_unbind_cb, NULL);
1737 TC_PRT("return %s\n", __bt_get_error_message(ret));
1740 case BT_MESH_UNIT_TEST_FUNCTION_MODEL_GET_APPKEY_LIST: {
1741 bt_mesh_model_h model_h = 0;
1742 if (g_test_param.param_count != 1) {
1743 TC_PRT("Set Input parameter first!");
1746 model_h = GUINT_TO_POINTER(strtoul(g_test_param.params[0], NULL, 16));
1748 ret = bt_mesh_model_get_appkey_list(model_h, __bt_mesh_model_appkey_list_cb, NULL);
1749 TC_PRT("return %s\n", __bt_get_error_message(ret));
1752 case BT_MESH_UNIT_TEST_FUNCTION_MODEL_CONFIGURE_GROUP_SUBSCRIPTION: {
1753 bt_mesh_model_h model_h = 0;
1754 bt_mesh_group_h group_h = 0;
1755 bt_mesh_model_subscription_op_e op = BT_MESH_MODEL_SUBSCRIPTION_ADD;
1757 if (g_test_param.param_count != 3) {
1758 TC_PRT("Set Input parameter first!");
1761 model_h = GUINT_TO_POINTER(strtoul(g_test_param.params[0], NULL, 16));
1762 op = atoi(g_test_param.params[1]);
1763 group_h = GUINT_TO_POINTER(strtoul(g_test_param.params[2], NULL, 16));
1765 ret = bt_mesh_model_configure_group_subscription(op, model_h, group_h,
1766 __bt_mesh_model_subscription_op_cb, NULL);
1767 TC_PRT("return %s\n", __bt_get_error_message(ret));
1770 case BT_MESH_UNIT_TEST_FUNCTION_MODEL_CONFIGURE_VIRTUAL_GROUP_SUBSCRIPTION: {
1771 bt_mesh_model_h model_h = 0;
1772 bt_mesh_group_h group_h = 0;
1773 bt_mesh_model_subscription_op_e op = BT_MESH_MODEL_SUBSCRIPTION_ADD;
1775 if (g_test_param.param_count != 3) {
1776 TC_PRT("Set Input parameter first!");
1779 model_h = GUINT_TO_POINTER(strtoul(g_test_param.params[0], NULL, 16));
1780 op = atoi(g_test_param.params[1]);
1781 group_h = GUINT_TO_POINTER(strtoul(g_test_param.params[2], NULL, 16));
1783 ret = bt_mesh_model_configure_virtual_group_subscription(op, model_h, group_h,
1784 __bt_mesh_model_subscription_op_cb, NULL);
1785 TC_PRT("return %s\n", __bt_get_error_message(ret));
1788 case BT_MESH_UNIT_TEST_FUNCTION_MODEL_GET_SUBSCRIPTION_LIST: {
1789 bt_mesh_model_h model_h = 0;
1791 if (g_test_param.param_count != 1) {
1792 TC_PRT("Set Input parameter first!");
1795 model_h = GUINT_TO_POINTER(strtoul(g_test_param.params[0], NULL, 16));
1797 ret = bt_mesh_model_get_subscription_list(model_h, __bt_mesh_model_subscription_list_cb, NULL);
1798 TC_PRT("return %s\n", __bt_get_error_message(ret));
1801 case BT_MESH_UNIT_TEST_FUNCTION_MODEL_SET_PUBLICATION: {
1802 bt_mesh_model_h model_h = 0;
1803 bt_mesh_model_h appkey_h = 0;
1804 bt_mesh_group_h group_h = 0;
1805 bt_mesh_model_pub_params_s param;
1807 memset(¶m, 0x00, sizeof(bt_mesh_model_pub_params_s));
1809 if (g_test_param.param_count != 3) {
1810 TC_PRT("Set Input parameter first!");
1813 model_h = GUINT_TO_POINTER(strtoul(g_test_param.params[0], NULL, 16));
1814 appkey_h = GUINT_TO_POINTER(strtoul(g_test_param.params[1], NULL, 16));
1815 group_h = GUINT_TO_POINTER(strtoul(g_test_param.params[2], NULL, 16));
1818 param.num_steps = 10;
1819 param.per_res = BT_MESH_PUBLICATION_STEP_RES_1_SECOND;
1820 param.retrans_cnt = BT_MESH_MAX_PUBISH_RETRANSMIT_COUNT;
1821 param.retrans_step = BT_MESH_MAX_PUBISH_RETRANSMIT_INTERVAL_STEPS;
1823 ret = bt_mesh_model_set_publication(model_h, appkey_h, group_h, ¶m,
1824 __bt_mesh_model_publication_status_cb, NULL);
1825 TC_PRT("return %s\n", __bt_get_error_message(ret));
1828 case BT_MESH_UNIT_TEST_FUNCTION_MODEL_GET_PUBLICATION: {
1829 bt_mesh_model_h model_h = 0;
1831 if (g_test_param.param_count != 1) {
1832 TC_PRT("Set Input parameter first!");
1835 model_h = GUINT_TO_POINTER(strtoul(g_test_param.params[0], NULL, 16));
1837 ret = bt_mesh_model_get_publication(model_h, __bt_mesh_model_publication_status_cb, NULL);
1838 TC_PRT("return %s\n", __bt_get_error_message(ret));
1841 case BT_MESH_UNIT_TEST_FUNCTION_MODEL_SEND_MSG: {
1842 bt_mesh_model_h model_h = NULL;
1843 bt_mesh_appkey_h appkey_h = NULL;
1844 bt_mesh_model_msg_params_s *msg_params = NULL;
1845 if (g_test_param.param_count != 4) {
1846 TC_PRT("Set Input parameter first!");
1849 model_h = GUINT_TO_POINTER(strtoul(g_test_param.params[0], NULL, 16));
1850 appkey_h = GUINT_TO_POINTER(strtoul(g_test_param.params[1], NULL, 16));
1851 msg_params = g_malloc0(sizeof(bt_mesh_model_msg_params_s));
1852 msg_params->opcode = strtoul(g_test_param.params[2], NULL, 16);
1853 msg_params->data = "0101010101010101010101010100101010";
1854 msg_params->data = g_strdup(g_test_param.params[3]);
1855 TC_PRT("Input parameters");
1856 print_model_handle(model_h);
1857 print_appkey_handle(appkey_h);
1858 TC_PRT("opcode 0X%4.4X", msg_params->opcode);
1859 TC_PRT("Message to be sent %s", msg_params->data);
1860 ret = bt_mesh_model_send_msg(model_h, appkey_h, msg_params,
1861 __bt_mesh_model_msg_cb, NULL);
1862 TC_PRT("return %s\n", __bt_get_error_message(ret));
1865 case BT_MESH_UNIT_TEST_FUNCTION_APPKEY_GET_NETKEY: {
1866 bt_mesh_appkey_h appkey_h = 0;
1867 bt_mesh_netkey_h netkey_h;
1869 if (g_test_param.param_count != 1) {
1870 TC_PRT("Set Input parameter first!");
1873 appkey_h = GUINT_TO_POINTER(strtoul(g_test_param.params[0], NULL, 16));
1875 ret = bt_mesh_appkey_get_netkey(appkey_h, &netkey_h);
1876 TC_PRT("return %s\n", __bt_get_error_message(ret));
1877 if (ret == BT_ERROR_NONE)
1878 print_netkey_handle(netkey_h);
1881 case BT_MESH_UNIT_TEST_FUNCTION_ACTIVATE_FLAG_TO_SET_PARAMETERS: {
1882 need_to_set_params = true;
1883 TC_PRT("Select the function again");
1889 __bt_free_test_param(&g_test_param);
1899 static gboolean key_event_cb(GIOChannel *chan,
1903 char buf[BUFFER_LEN] = { 0 };
1906 unsigned long len = 0;
1908 unsigned int len = 0;
1911 bool is_call_api = false;
1913 memset(buf, 0, sizeof(buf));
1915 if (g_io_channel_read_chars(chan, buf, sizeof(buf),
1916 &len, NULL) == G_IO_STATUS_ERROR) {
1917 TC_PRT("IO Channel read error");
1921 if (need_to_set_params == true) {
1922 if (g_test_id == -1) {
1923 test_id = atoi(buf);
1924 g_test_id = test_id;
1926 test_set_params(g_test_id, buf);
1930 test_id = atoi(buf);
1933 need_to_set_params = false;
1936 if (current_tc_table == BT_MESH_UNIT_TEST_TABLE_MAIN) {
1938 current_tc_table = BT_MESH_UNIT_TEST_TABLE_MAIN;
1939 else if(test_id >= BT_MESH_UNIT_TEST_TABLE_NETWORK
1940 && test_id <= BT_MESH_UNIT_TEST_TABLE_CONFIGURATION) {
1941 current_tc_table = test_id;
1942 } else if (test_id > BT_MESH_UNIT_TEST_TABLE_CONFIGURATION
1943 && test_id < BT_MESH_UNIT_TEST_TABLE_FINISH) {
1944 current_tc_table = BT_MESH_UNIT_TEST_TABLE_MAIN;
1951 if (buf[0] == '0' && buf[2] == 0) {
1952 current_tc_table = BT_MESH_UNIT_TEST_TABLE_MAIN;
1956 current_tc_table = BT_MESH_UNIT_TEST_TABLE_MAIN;
1965 if (test_id && is_call_api) {
1967 g_idle_add(test_input_callback, (void *)(uintptr_t)test_id);
1969 g_idle_add(test_input_callback, (void *)test_id);
1975 void sig_handler(int signo)
1977 if (signo == SIGINT) {
1978 bt_mesh_deinitialize();
1987 current_tc_table = BT_MESH_UNIT_TEST_TABLE_MAIN;
1989 key_io = g_io_channel_unix_new(fileno(stdin));
1991 g_io_channel_set_encoding(key_io, NULL, NULL);
1992 g_io_channel_set_flags(key_io, G_IO_FLAG_NONBLOCK, NULL);
1994 g_io_add_watch(key_io, G_IO_IN | G_IO_HUP | G_IO_ERR | G_IO_NVAL,
1995 key_event_cb, NULL);
1997 g_io_channel_unref(key_io);
1999 main_loop = g_main_loop_new(NULL, FALSE);
2001 if (signal(SIGINT, sig_handler) == SIG_ERR)
2002 TC_PRT("\n can't catch SIGINT\n");
2004 g_main_loop_run(main_loop);
2006 bt_mesh_deinitialize();