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 GSList *networks;
41 static bool need_to_set_params = false;
42 static int g_test_id = -1;
43 static tc_params_t g_test_param = {0,};
45 static bt_mesh_node_h local_node = NULL;
46 static bt_mesh_node_h g_node;
47 static bt_mesh_network_h network;
48 static bt_mesh_element_h g_element;
49 static bt_mesh_model_h g_model;
50 static bt_mesh_model_h g_model_onoff_srv;
51 static GSList *unprov_dev_list;
52 static GSList *prov_dev_list;
53 static GSList *srv_model_list;
54 static char *g_device_uuid;
55 static bool call_success = false;
58 static int max_try = 10;
60 static bt_mesh_netkey_h g_netkey;
61 static bt_mesh_appkey_h g_appkey;
62 static bt_mesh_group_h g_group;
65 static bt_mesh_authentication_type_e request_type = BT_MESH_AUTH_ALPHANUMERIC_DISPLAY;
67 GMainLoop *main_loop = NULL;
68 GMainLoop *mainloop = NULL;
70 static void wait_for_async_over()
73 g_main_loop_quit(mainloop);
76 static void wait_for_async()
78 TC_PRT("Wait for operation...\n");
79 mainloop = g_main_loop_new(NULL, FALSE);
80 g_main_loop_run(mainloop);
83 tc_table_t tc_control[] = {
85 , BT_MESH_UNIT_TEST_FUNCTION_BACK},
86 {"bt_mesh_model_send_msg"
87 , BT_MESH_UNIT_TEST_FUNCTION_MODEL_SEND_MSG},
88 {"bt_mesh_group_send_msg"
89 , BT_MESH_UNIT_TEST_FUNCTION_GROUP_SEND_MSG},
90 {"select this menu to set parameters and then select the function again"
91 , BT_MESH_UNIT_TEST_FUNCTION_ACTIVATE_FLAG_TO_SET_PARAMETERS},
95 tc_table_t tc_configuration[] = {
97 , BT_MESH_UNIT_TEST_FUNCTION_BACK},
98 {"bt_mesh_network_discover_node"
99 , BT_MESH_UNIT_TEST_FUNCTION_MESH_NETWORK_DISCOVER_NODE},
100 {"bt_mesh_node_reset"
101 , BT_MESH_UNIT_TEST_FUNCTION_NODE_RESET},
102 {"bt_mesh_node_get_features"
103 , BT_MESH_UNIT_TEST_FUNCTION_NODE_GET_FEATURES},
104 {"bt_mesh_node_foreach_netkeys"
105 , BT_MESH_UNIT_TEST_FUNCTION_NODE_GET_NETKEYS},
106 {"bt_mesh_node_foreach_appkeys"
107 , BT_MESH_UNIT_TEST_FUNCTION_NODE_GET_APPKEYS},
108 {"bt_mesh_node_get_ttl"
109 , BT_MESH_UNIT_TEST_FUNCTION_NODE_GET_TTL},
110 {"bt_mesh_node_set_ttl"
111 , BT_MESH_UNIT_TEST_FUNCTION_NODE_SET_TTL},
112 {"bt_mesh_node_configure_netkey"
113 , BT_MESH_UNIT_TEST_FUNCTION_NODE_CONFIGURE_NETKEY},
114 {"bt_mesh_node_configure_appkey"
115 , BT_MESH_UNIT_TEST_FUNCTION_NODE_CONFIGURE_APPKEY},
116 {"bt_mesh_model_bind_appkey"
117 , BT_MESH_UNIT_TEST_FUNCTION_MODEL_BIND_APPKEY},
118 {"bt_mesh_model_unbind_appkey"
119 , BT_MESH_UNIT_TEST_FUNCTION_MODEL_UNBIND_APPKEY},
120 {"bt_mesh_model_get_appkey_list"
121 , BT_MESH_UNIT_TEST_FUNCTION_MODEL_GET_APPKEY_LIST},
122 {"bt_mesh_model_configure_group_subscription"
123 , BT_MESH_UNIT_TEST_FUNCTION_MODEL_CONFIGURE_GROUP_SUBSCRIPTION},
124 {"bt_mesh_model_configure_virtual_group_subscription"
125 , BT_MESH_UNIT_TEST_FUNCTION_MODEL_CONFIGURE_VIRTUAL_GROUP_SUBSCRIPTION},
126 {"bt_mesh_model_get_subscription_list"
127 , BT_MESH_UNIT_TEST_FUNCTION_MODEL_GET_SUBSCRIPTION_LIST},
128 {"bt_mesh_model_set_publication"
129 , BT_MESH_UNIT_TEST_FUNCTION_MODEL_SET_PUBLICATION},
130 {"bt_mesh_model_get_publication"
131 , BT_MESH_UNIT_TEST_FUNCTION_MODEL_GET_PUBLICATION},
132 {"bt_mesh_appkey_get_netkey"
133 , BT_MESH_UNIT_TEST_FUNCTION_APPKEY_GET_NETKEY},
134 {"select this menu to set parameters and then select the function again"
135 , BT_MESH_UNIT_TEST_FUNCTION_ACTIVATE_FLAG_TO_SET_PARAMETERS},
139 tc_table_t tc_network[] = {
141 , BT_MESH_UNIT_TEST_FUNCTION_BACK},
142 {"bt_mesh_node_create"
143 , BT_MESH_UNIT_TEST_FUNCTION_NODE_CREATE},
144 {"bt_mesh_node_destroy"
145 , BT_MESH_UNIT_TEST_FUNCTION_NODE_DESTROY},
146 {"bt_mesh_node_create_element"
147 , BT_MESH_UNIT_TEST_FUNCTION_NODE_CREATE_ELEMENT},
148 {"bt_mesh_node_get_network"
149 , BT_MESH_UNIT_TEST_FUNCTION_NODE_GET_NETWORK},
150 {"bt_mesh_element_create_model"
151 , BT_MESH_UNIT_TEST_FUNCTION_ELEMENT_CREATE_MODEL},
152 {"bt_mesh_model_get_id"
153 , BT_MESH_UNIT_TEST_FUNCTION_MODEL_GET_ID},
154 {"bt_mesh_model_destroy"
155 , BT_MESH_UNIT_TEST_FUNCTION_MODEL_DESTROY},
156 {"bt_mesh_model_get_element"
157 , BT_MESH_UNIT_TEST_FUNCTION_MODEL_GET_ELEMENT},
158 {"bt_mesh_element_destroy"
159 , BT_MESH_UNIT_TEST_FUNCTION_ELEMENT_DESTROY},
160 {"bt_mesh_element_get_node"
161 , BT_MESH_UNIT_TEST_FUNCTION_ELEMENT_GET_NODE},
162 {"bt_mesh_node_foreach_element"
163 , BT_MESH_UNIT_TEST_FUNCTION_NODE_FOREACH_ELEMENTS},
164 {"bt_mesh_element_foreach_models"
165 , BT_MESH_UNIT_TEST_FUNCTION_ELEMENT_FOREACH_MODELS},
166 {"bt_mesh_network_create"
167 , BT_MESH_UNIT_TEST_FUNCTION_NETWORK_CREATE},
168 {"bt_mesh_network_destroy"
169 , BT_MESH_UNIT_TEST_FUNCTION_NETWORK_DESTROY},
170 {"bt_mesh_network_create_in_loop"
171 , BT_MESH_UNIT_TEST_FUNCTION_NETWORK_CREATE_IN_LOOP},
172 {"bt_mesh_network_destroy_all_networks"
173 , BT_MESH_UNIT_TEST_FUNCTION_NETWORK_DESTROY_ALL_NETWORKS},
174 {"bt_mesh_network_create_and_destroy_in_loop"
175 , BT_MESH_UNIT_TEST_FUNCTION_NETWORK_CREATE_AND_DESTROY_IN_LOOP},
176 {"bt_mesh_network_init_deinit_in_loop"
177 , BT_MESH_UNIT_TEST_FUNCTION_NETWORK_INIT_AND_DEINIT_IN_LOOP},
178 {"bt_mesh_network_load"
179 , BT_MESH_UNIT_TEST_FUNCTION_NETWORK_LOAD},
180 {"bt_mesh_network_set_name"
181 , BT_MESH_UNIT_TEST_FUNCTION_NETWORK_SET_NAME},
182 {"bt_mesh_network_get_name"
183 , BT_MESH_UNIT_TEST_FUNCTION_NETWORK_GET_NAME},
184 {"bt_mesh_network_add_netkey"
185 , BT_MESH_UNIT_TEST_FUNCTION_NETWORK_ADD_NETKEY},
186 {"bt_mesh_network_foreach_netkeys"
187 , BT_MESH_UNIT_TEST_FUNCTION_NETWORK_FOREACH_NETKEYS},
188 {"bt_mesh_netkey_get_index"
189 , BT_MESH_UNIT_TEST_FUNCTION_NETKEY_GET_INDEX},
190 {"bt_mesh_netkey_update"
191 , BT_MESH_UNIT_TEST_FUNCTION_NETKEY_UPDATE},
192 {"bt_mesh_netkey_delete"
193 , BT_MESH_UNIT_TEST_FUNCTION_NETKEY_DELETE},
194 {"bt_mesh_netkey_add_appkey"
195 , BT_MESH_UNIT_TEST_FUNCTION_NETKEY_ADD_APPKEY},
196 {"bt_mesh_netkey_foreach_appkeys"
197 , BT_MESH_UNIT_TEST_FUNCTION_NETKEY_FOREACH_APPKEYS},
198 {"bt_mesh_appkey_get_index"
199 , BT_MESH_UNIT_TEST_FUNCTION_APPKEY_GET_INDEX},
200 {"bt_mesh_appkey_update"
201 , BT_MESH_UNIT_TEST_FUNCTION_APPKEY_UPDATE},
202 {"bt_mesh_appkey_delete"
203 , BT_MESH_UNIT_TEST_FUNCTION_APPKEY_DELETE},
204 {"bt_mesh_network_foreach_devices"
205 , BT_MESH_UNIT_TEST_FUNCTION_NETWORK_FOREACH_DEVICES},
206 {"bt_mesh_network_create_group"
207 , BT_MESH_UNIT_TEST_FUNCTION_NETWORK_CREATE_GROUP},
208 {"bt_mesh_network_create_virtual_group"
209 , BT_MESH_UNIT_TEST_FUNCTION_NETWORK_CREATE_VIRTUAL_GROUP},
210 {"bt_mesh_network_remove_group"
211 , BT_MESH_UNIT_TEST_FUNCTION_NETWORK_REMOVE_GROUP},
212 {"bt_mesh_network_foreach_groups"
213 , BT_MESH_UNIT_TEST_FUNCTION_NETWORK_FOREACH_GROUPS},
214 {"bt_mesh_network_unprovisioned_device_scan"
215 , BT_MESH_UNIT_TEST_FUNCTION_NETWORK_UNPROVISIONED_DEVICE_SCAN},
216 {"bt_mesh_stop_unprovisioned_device_scan"
217 , BT_MESH_UNIT_TEST_FUNCTION_STOP_UNPROVISIONED_DEVICE_SCAN},
218 {"bt_mesh_network_provision_device"
219 , BT_MESH_UNIT_TEST_FUNCTION_NETWORK_PROVISION_DEVICE},
220 {"bt_mesh_authentication_set_request_cb"
221 , BT_MESH_UNIT_TEST_FUNCTION_NETWORK_AUTHENTICATION_SET_REQUEST_CB},
222 {"bt_mesh_authentication_reply"
223 , BT_MESH_UNIT_TEST_FUNCTION_MESH_AUTHENTICATION_REPLY},
224 {"bt_mesh_network_set_provisioning_capabilities"
225 , BT_MESH_UNIT_TEST_FUNCTION_NETWORK_SET_PROVISIONING_CAPABILITIES},
226 {"bt_mesh_network_get_provisioning_capabilities"
227 , BT_MESH_UNIT_TEST_FUNCTION_NETWORK_GET_PROVISIONING_CAPABILITIES},
228 {"select this menu to set parameters and then select the function again"
229 , BT_MESH_UNIT_TEST_FUNCTION_ACTIVATE_FLAG_TO_SET_PARAMETERS},
233 tc_table_t tc_scenario[] = {
235 , BT_MESH_UNIT_TEST_FUNCTION_BACK},
236 {"bt_mesh_scenario_network_create"
237 , BT_MESH_UNIT_TEST_SCENARIO_NETWORK_CREATE},
238 {"bt_mesh_scenario_unprovisioned_scan"
239 , BT_MESH_UNIT_TEST_SCENARIO_UNPROVISIONED_SCAN},
240 {"bt_mesh_scenario_provision_device"
241 , BT_MESH_UNIT_TEST_SCENARIO_PROVISION_DEVICE},
242 {"bt_mesh_scenario_node_reset"
243 , BT_MESH_UNIT_TEST_SCENARIO_NODE_RESET},
244 {"bt_mesh_scenario_node_configure_key"
245 , BT_MESH_UNIT_TEST_SCENARIO_NODE_CONFIGURE_KEY},
246 {"bt_mesh_scenario_model_generic_onoff_set_on"
247 , BT_MESH_UNIT_TEST_SCENARIO_MODEL_GENERIC_ONOFF_SET_ON},
248 {"bt_mesh_scenario_model_generic_onoff_set_off"
249 , BT_MESH_UNIT_TEST_SCENARIO_MODEL_GENERIC_ONOFF_SET_OFF},
250 {"bt_mesh_scenario_group_generic_onoff_set_on"
251 , BT_MESH_UNIT_TEST_SCENARIO_GROUP_GENERIC_ONOFF_SET_ON},
252 {"bt_mesh_scenario_group_generic_onoff_set_off"
253 , BT_MESH_UNIT_TEST_SCENARIO_GROUP_GENERIC_ONOFF_SET_OFF},
254 {"select this menu to set parameters and then select the function again"
255 , BT_MESH_UNIT_TEST_FUNCTION_ACTIVATE_FLAG_TO_SET_PARAMETERS},
259 tc_table_t tc_main[] = {
260 {"bt_mesh_initialize"
261 , BT_MESH_UNIT_TEST_FUNCTION_INITIALIZE},
262 {"bt_mesh_deinitialize"
263 , BT_MESH_UNIT_TEST_FUNCTION_DEINITIALIZE},
265 , BT_MESH_UNIT_TEST_TABLE_NETWORK},
267 , BT_MESH_UNIT_TEST_TABLE_CONFIGURATION},
269 , BT_MESH_UNIT_TEST_TABLE_CONTROL},
271 , BT_MESH_UNIT_TEST_TABLE_SCENARIO},
273 , BT_MESH_UNIT_TEST_TABLE_FINISH},
277 static void __bt_free_test_param(tc_params_t *param)
281 for (i = 0; i < param->param_count; i++)
282 g_free(param->params[i]);
283 g_free(param->params);
284 param->params = NULL;
285 param->param_count = 0;
288 void tc_usage_print(void){
290 tc_table_t *tc_table = NULL;
291 switch (current_tc_table) {
292 case BT_MESH_UNIT_TEST_TABLE_NETWORK:
293 tc_table = tc_network;
295 case BT_MESH_UNIT_TEST_TABLE_CONFIGURATION:
296 tc_table = tc_configuration;
298 case BT_MESH_UNIT_TEST_TABLE_CONTROL:
299 tc_table = tc_control;
301 case BT_MESH_UNIT_TEST_TABLE_SCENARIO:
302 tc_table = tc_scenario;
308 while (tc_table[i].tc_name) {
309 TC_PRT("Key %d : usage %s", tc_table[i].tc_code, tc_table[i].tc_name);
314 static const char *__bt_get_error_message(bt_error_e err)
316 const char *err_str = NULL;
320 err_str = "BT_ERROR_NONE";
322 case BT_ERROR_CANCELLED:
323 err_str = "BT_ERROR_CANCELLED";
325 case BT_ERROR_INVALID_PARAMETER:
326 err_str = "BT_ERROR_INVALID_PARAMETER";
328 case BT_ERROR_OUT_OF_MEMORY:
329 err_str = "BT_ERROR_OUT_OF_MEMORY";
331 case BT_ERROR_RESOURCE_BUSY:
332 err_str = "BT_ERROR_RESOURCE_BUSY";
334 case BT_ERROR_TIMED_OUT:
335 err_str = "BT_ERROR_TIMED_OUT";
337 case BT_ERROR_NOW_IN_PROGRESS:
338 err_str = "BT_ERROR_NOW_IN_PROGRESS";
340 case BT_ERROR_NOT_INITIALIZED:
341 err_str = "BT_ERROR_NOT_INITIALIZED";
343 case BT_ERROR_NOT_ENABLED:
344 err_str = "BT_ERROR_NOT_ENABLED";
346 case BT_ERROR_ALREADY_DONE:
347 err_str = "BT_ERROR_ALREADY_DONE";
349 case BT_ERROR_OPERATION_FAILED:
350 err_str = "BT_ERROR_OPERATION_FAILED";
352 case BT_ERROR_NOT_IN_PROGRESS:
353 err_str = "BT_ERROR_NOT_IN_PROGRESS";
356 err_str = "NOT defined";
362 void print_network_handle(bt_mesh_network_h network)
366 bt_mesh_network_s* net = (bt_mesh_network_s*) network;
367 TC_PRT("network_handle = [%p]", (void*)net);
368 TC_PRT("net->is_local [%d]", net->is_local);
369 TC_PRT("net->is_discovered [%d]", net->is_discovered);
370 TC_PRT("net->uuid [%s]", net->uuid);
371 TC_PRT("net->token [%s]", net->token);
372 TC_PRT("net->name [%s]", net->name);
373 TC_PRT("net->num_nodes [%d]", net->num_nodes);
376 void print_node_handle(bt_mesh_node_h node)
380 bt_mesh_node_s* node_info = (bt_mesh_node_s*) node;
381 TC_PRT("node_handle = [%p]", (void*)node_info);
382 TC_PRT("node->is_local [%d]", node_info->is_local);
383 TC_PRT("node->is_attached [%d]", node_info->is_attached);
384 if (node_info->is_attached) {
385 TC_PRT("node->parent_network [%s]", node_info->parent->name);
386 TC_PRT("node->uuid [%s]", node_info->uuid);
387 TC_PRT("node->unicast [%d]", node_info->unicast);
392 void print_element_handle(bt_mesh_element_h element)
396 bt_mesh_element_s* element_info = (bt_mesh_element_s*) element;
397 TC_PRT("element_handle = [%p]", (void*)element_info);
398 TC_PRT("element->is_local [%d]", element_info->is_local);
399 TC_PRT("element->index [%d]", element_info->index);
402 void print_model_handle(bt_mesh_model_h model)
406 bt_mesh_model_s* model_info = (bt_mesh_model_s*) model;
407 TC_PRT("model_handle = [%p]", (void*)model_info);
408 TC_PRT("model->is_local [%d]", model_info->is_local);
409 TC_PRT("model->id [0x%4.4x]", model_info->id);
410 TC_PRT("model->pub_addr [0x%2.2x]", model_info->pub_addr);
413 void print_netkey_handle(bt_mesh_netkey_h netkey)
417 bt_mesh_netkey_s* netkey_info = (bt_mesh_netkey_s*) netkey;
418 TC_PRT("netkey_handle = [%p]", (void*)netkey_info);
419 TC_PRT("Parent network_name [%s]", netkey_info->parent->name);
420 TC_PRT("Netkey_index [%d]", netkey_info->netkey_index);
423 void print_appkey_handle(bt_mesh_appkey_h appkey)
427 bt_mesh_appkey_s* appkey_info = (bt_mesh_appkey_s*) appkey;
428 TC_PRT("appkey_handle = [%p]", (void*)appkey_info);
429 TC_PRT("Parent netkey_index [%d]", appkey_info->parent->netkey_index);
430 TC_PRT("appkey_index [%d]", appkey_info->appkey_index);
433 void print_group_handle(bt_mesh_group_h group)
437 bt_mesh_group_s* group_info = (bt_mesh_group_s*) group;
438 TC_PRT("group_handle = [%p]", (void*)group_info);
439 TC_PRT("group Parent Network Name [%s]", group_info->parent->name);
440 TC_PRT("group Address [0x%2.2x]", group_info->addr);
441 TC_PRT("group Label UUID [%s]", group_info->label_uuid);
442 TC_PRT("group Is Virtual ? [%s]", group_info->is_virtual ? "YES" : "NO");
445 bool __bt_mesh_network_device_info_cb(int result, bt_mesh_network_h network, int total,
446 const char *dev_uuid, uint16_t primary_unicast, void *user_data)
448 TC_PRT("bt_mesh_network_device_info_cb");
449 TC_PRT("Total number of Devices in network [%d]", total);
451 TC_PRT("result: %s", __bt_get_error_message(result));
452 TC_PRT("primary unicast address is [%d]", primary_unicast);
453 TC_PRT("Device UUID [%s]", dev_uuid);
457 bool __bt_mesh_network_group_info_cb(int result, bt_mesh_network_h network, int total,
458 bt_mesh_group_h group, void *user_data)
460 bt_mesh_group_s* grp = (bt_mesh_group_s*) group;
461 TC_PRT("bt_mesh_network_group_info_cb: Total groups present in network [%d]", total);
462 TC_PRT("result: %s", __bt_get_error_message(result));
464 if (result == BT_ERROR_NONE) {
465 print_group_handle(grp);
471 void __bt_mesh_node_discover_status_cb(int result, bt_mesh_network_h network, bt_mesh_node_h node_param,
474 TC_PRT("bt_mesh_node_discover_status_cb result: %s", __bt_get_error_message(result));
475 //print_network_handle(network);
476 print_node_handle(node_param);
477 if (result == BT_ERROR_NONE) {
481 wait_for_async_over();
484 static gint __compare_model_handle(gconstpointer data, gconstpointer user_data)
488 if (NULL == user_data)
490 if ((void*) data == (void*) user_data)
497 static bool __bt_mesh_elem_foreach_model_cb(int result, bt_mesh_element_h element, int total,
498 bt_mesh_model_h model, bt_mesh_model_id_s *model_id, void *user_data)
500 TC_PRT("result: %s", __bt_get_error_message(result));
502 if (result == BT_ERROR_NONE) {
503 TC_PRT("Total number of Models in the element [%d]", total);
504 print_element_handle(element);
506 print_model_handle(model);
507 TC_PRT("Model Comp ID [0x%2.2x] Model ID [0x%2.2x]",
508 model_id->company_id, model_id->model_id);
509 /* Update generic onoff server model list */
510 if (model_id->model_id == BT_MESH_MODEL_ID_GEN_ONOFF_SRV) {
511 g_model_onoff_srv = model;
512 l = g_slist_find_custom(srv_model_list, model, __compare_model_handle);
514 srv_model_list = g_slist_append(srv_model_list, model);
523 static bool __bt_mesh_node_foreach_elem_cb(int result, bt_mesh_node_h node, int total,
524 bt_mesh_element_h element, int elem_index, uint16_t element_addr, void *user_data)
526 TC_PRT("result: %s", __bt_get_error_message(result));
528 if (result == BT_ERROR_NONE) {
529 TC_PRT("Total number of elements in the node [%d]", total);
530 print_node_handle(node);
532 print_element_handle(element);
533 TC_PRT("Element address [0x%2.2x]", element_addr);
534 TC_PRT("Element index [%d]", elem_index);
542 static void __bt_mesh_node_configure_netkey_cb(int result, bt_mesh_node_key_configuration_e op,
543 bt_mesh_node_h node, bt_mesh_netkey_h netkey, void *user_data)
545 TC_PRT("result: %s", __bt_get_error_message(result));
547 if (result == BT_ERROR_NONE) {
548 print_node_handle(node);
549 if (op == BT_MESH_NODE_KEY_ADD)
550 TC_PRT("NetKey Added!");
551 else if (op == BT_MESH_NODE_KEY_UPDATE)
552 TC_PRT("NetKey Updated!");
554 TC_PRT("NetKey Deleted!");
555 print_netkey_handle(netkey);
559 static void __bt_mesh_node_configure_appkey_cb(int result, bt_mesh_node_key_configuration_e op,
560 bt_mesh_node_h node, bt_mesh_netkey_h netkey,
561 bt_mesh_appkey_h appkey, void *user_data)
563 TC_PRT("result: %s", __bt_get_error_message(result));
564 if (result == BT_ERROR_NONE) {
566 //print_node_handle(node);
567 if (op == BT_MESH_NODE_KEY_ADD)
568 TC_PRT("AppKey Added!");
569 else if (op == BT_MESH_NODE_KEY_UPDATE)
570 TC_PRT("AppKey Updated!");
572 TC_PRT("AppKey Deleted!");
573 print_netkey_handle(netkey);
574 print_appkey_handle(appkey);
576 wait_for_async_over();
579 static void __bt_mesh_node_features_cb(int result, bt_mesh_node_h node,
580 bt_mesh_node_features_s *features, void *user_data)
582 TC_PRT("result: %s", __bt_get_error_message(result));
584 if (result == BT_ERROR_NONE) {
585 print_node_handle(node);
586 TC_PRT("CID [0x%2.2x]\n", features->cid);
587 TC_PRT("PID [0x%2.2x]\n", features->pid);
588 TC_PRT("VID [0x%2.2x]\n", features->vid);
589 TC_PRT("CRPL [0x%2.2x]\n", features->crpl);
591 if (features->features & BT_MESH_FEATURE_RELAY)
592 TC_PRT("Features: RELAY Supported");
593 if (features->features & BT_MESH_FEATURE_PROXY)
594 TC_PRT("Features: PROXY Supported");
595 if (features->features & BT_MESH_FEATURE_FRIEND)
596 TC_PRT("Features: FRIEND Supported");
597 if (features->features & BT_MESH_FEATURE_LOWPOWER)
598 TC_PRT("Features: LOW POWER Supported\n");
602 static bool __bt_mesh_node_foreach_netkeys_cb(int result, bt_mesh_node_h node, int total,
603 bt_mesh_netkey_h netkey,
604 uint16_t netkey_index, void *user_data)
606 if (result == BT_ERROR_NONE) {
607 TC_PRT("Total Netkeys in node [%d]", total);
608 //print_node_handle(node);
609 print_netkey_handle(netkey);
613 TC_PRT("__bt_mesh_node_foreach_netkeys_cb result: %s", __bt_get_error_message(result));
618 static bool __bt_mesh_node_foreach_appkeys_cb(int result, bt_mesh_node_h node, int total,
619 bt_mesh_netkey_h netkey, bt_mesh_appkey_h appkey,
620 uint16_t appkey_index, void *user_data)
622 TC_PRT("result: %s", __bt_get_error_message(result));
624 if (result == BT_ERROR_NONE) {
625 TC_PRT("Total Appkeys in node [%d]", total);
626 print_netkey_handle(netkey);
627 print_appkey_handle(appkey);
633 void __bt_mesh_node_ttl_cb(int result, bt_mesh_node_h node,
634 bt_mesh_node_ttl_operation_e ttl_op, uint8_t ttl, void *user_data)
636 TC_PRT("result: %s", __bt_get_error_message(result));
638 if (result == BT_ERROR_NONE) {
639 print_node_handle(node);
640 TC_PRT("ttl_op is [%s]", ttl_op ? "TTL Set" : "TTL Get");
641 TC_PRT("ttl value is [%d]", ttl);
645 void __bt_mesh_model_bind_cb(int result, bt_mesh_model_h model, bt_mesh_appkey_h appkey,
648 TC_PRT("result: %s", __bt_get_error_message(result));
649 if (result == BT_ERROR_NONE) {
651 print_model_handle(model);
652 print_appkey_handle(appkey);
654 wait_for_async_over();
657 void __bt_mesh_model_msg_cb(int result, bt_mesh_element_h element, bt_mesh_appkey_h appkey,
658 bt_mesh_model_msg_params_s *msg, void *user_data)
660 TC_PRT("result: %s", __bt_get_error_message(result));
661 if (result == BT_ERROR_NONE) {
663 TC_PRT("opcode: 0X%2.2X", msg->opcode);
664 TC_PRT("msg: %s", msg->data);
665 print_element_handle(element);
666 print_appkey_handle(appkey);
668 wait_for_async_over();
671 void __bt_mesh_model_unbind_cb(int result, bt_mesh_model_h model, bt_mesh_appkey_h appkey,
674 TC_PRT("result: %s", __bt_get_error_message(result));
675 if (result == BT_ERROR_NONE) {
676 print_model_handle(model);
677 print_appkey_handle(appkey);
681 void __bt_mesh_model_appkey_list_cb(int result, bt_mesh_model_h model, int total, const GSList *appkeylist,
685 TC_PRT("result: %s", __bt_get_error_message(result));
687 if (result == BT_ERROR_NONE) {
688 TC_PRT("Total number of AppKeys bound to the model [%d]", total);
689 print_model_handle(model);
691 for (l = appkeylist; l != NULL; l = l->next) {
692 bt_mesh_appkey_h appkey = (bt_mesh_appkey_h) l->data;
693 print_appkey_handle(appkey);
698 void __bt_mesh_model_subscription_op_cb(int result, bt_mesh_model_subscription_op_e op,
699 bt_mesh_model_h model, bt_mesh_group_h group, void *user_data)
701 TC_PRT("result: %s", __bt_get_error_message(result));
702 if (result == BT_ERROR_NONE) {
706 TC_PRT("Model Subscription Operation is ADD");
709 TC_PRT("Model Subscription Operation is DELETE");
712 TC_PRT("Model Subscription Operation is DELETE ALL");
715 TC_PRT("Model Subscription Operation is OVERWRITE");
718 TC_PRT("Invalid Model Subscription Operation");
721 print_model_handle(model);
722 print_group_handle(group);
724 wait_for_async_over();
727 bool __bt_mesh_model_subscription_list_cb(int result, bt_mesh_model_h model, int total, const GSList *sub_addr,
731 TC_PRT("result: %s", __bt_get_error_message(result));
732 if (result == BT_ERROR_NONE) {
733 TC_PRT("Total number of AppKeys bound to the model [%d]", total);
734 print_model_handle(model);
736 for (l = sub_addr; l != NULL; l = l->next) {
737 bt_mesh_group_h group = (bt_mesh_group_h) l->data;
738 print_group_handle(group);
744 void __bt_mesh_model_publication_status_cb(int result, bt_mesh_model_h model, bt_mesh_group_h group,
745 bt_mesh_appkey_h appkey, void *user_data)
747 TC_PRT("result: %s", __bt_get_error_message(result));
749 if (result == BT_ERROR_NONE) {
750 print_model_handle(model);
751 print_group_handle(group);
752 print_appkey_handle(appkey);
756 void __bt_mesh_network_create_cb(int result, bt_mesh_network_h network, const char *network_name, void *user_data)
758 TC_PRT("result: %s", __bt_get_error_message(result));
759 print_network_handle(network);
762 bool __bt_mesh_appkey_info_cb(int result, bt_mesh_network_h network, int total,
763 bt_mesh_netkey_h netkey, bt_mesh_appkey_h appkey, uint16_t appkey_index, void *user_data)
765 TC_PRT("result: %s", __bt_get_error_message(result));
766 print_appkey_handle(appkey);
767 TC_PRT("Total appkeys are [%d]", total);
771 bool __bt_mesh_network_netkey_info_cb(int result, bt_mesh_network_h network, int total,
772 bt_mesh_netkey_h netkey, uint16_t netkey_index, void *user_data)
774 TC_PRT("result: %s", __bt_get_error_message(result));
775 TC_PRT("Total netkeys are [%d]", total);
776 if (result == BT_ERROR_NONE && netkey_index == 0) {
777 TC_PRT("Attempt to delete Primary Subnet");
778 result = bt_mesh_netkey_delete(netkey);
779 TC_PRT("return %s\n", __bt_get_error_message(result));
780 if (result == BT_ERROR_NONE)
781 TC_PRT("Primary netkey is deleted");
783 TC_PRT("Primary NetKey deletion failed");
788 static gint __compare_dev_uuid(gconstpointer data, gconstpointer user_data)
790 const char *uuid1 = data;
791 const char *uuid2 = user_data;
798 return g_strcmp0(uuid1, uuid2);
801 void __bt_mesh_network_scan_unprovisioned_device_result_cb(int result, bt_mesh_network_h network,
802 bt_mesh_scanning_state_e state, bt_mesh_scan_result_s *scan_res, void *user_data)
804 TC_PRT("result: %s", __bt_get_error_message(result));
805 if (state == BT_MESH_SCANNING_STARTED) {
806 TC_PRT("The scanning state is: STARTED");
807 print_network_handle(network);
808 } else if (state == BT_MESH_SCANNING_FINISHED) {
809 TC_PRT("The scanning state is: STOPPED");
810 print_network_handle(network);
811 wait_for_async_over();
814 char *duuid = g_strdup(scan_res->uuid);
815 l = g_slist_find_custom(unprov_dev_list, duuid, __compare_dev_uuid);
817 unprov_dev_list = g_slist_append(unprov_dev_list, duuid);
818 TC_PRT("New unprov Dev UUID %s", duuid);
819 TC_PRT("RSSI values is %d", scan_res->rssi);
820 TC_PRT("OOB Info 0x%x", scan_res->oob_info);
827 void __bt_mesh_network_device_provision_cb(int result, bt_mesh_network_h network,
828 const char* dev_uuid, void* user_data)
830 TC_PRT("result: %s", __bt_get_error_message(result));
831 if (dev_uuid == NULL)
832 TC_PRT("Provisioned dev_uuid is NULL");
835 TC_PRT("Provisioned device_uuid [%s]", dev_uuid);
836 char *duuid = g_strdup(dev_uuid);
837 l = g_slist_find_custom(prov_dev_list, duuid, __compare_dev_uuid);
839 prov_dev_list = g_slist_append(prov_dev_list, duuid);
841 wait_for_async_over();
844 void __bt_mesh_authentication_request_cb(int result, bt_mesh_authentication_type_e auth_type,
845 char *auth_value, void *user_data)
847 TC_PRT("result: %s", __bt_get_error_message(result));
848 TC_PRT("auth_value is [%s]", auth_value);
849 TC_PRT("auth_type is [%d]", auth_type);
850 request_type = auth_type;
853 int __bt_mesh_model_send_msg(bt_mesh_model_h model,
854 bt_mesh_appkey_h appkey, bt_mesh_model_msg_params_s *msg_params,
855 bt_mesh_model_msg_cb callback, void *user_data)
857 int ret = BT_ERROR_NONE;
858 call_success = false;
861 while (!call_success && try < max_try) {
863 ret = bt_mesh_model_send_msg(model, appkey, msg_params,
864 callback, user_data);
865 if (ret != BT_ERROR_NONE)
866 TC_PRT("return %s\n", __bt_get_error_message(ret));
873 int __bt_mesh_group_send_msg(bt_mesh_group_h group,
874 bt_mesh_appkey_h appkey, bt_mesh_model_msg_params_s *msg_params,
875 bt_mesh_model_msg_cb callback, void *user_data)
877 int ret = BT_ERROR_NONE;
878 call_success = false;
881 while (!call_success && try < max_try) {
883 ret = bt_mesh_group_send_msg(group, appkey, msg_params,
884 callback, user_data);
885 if (ret != BT_ERROR_NONE)
886 TC_PRT("return %s\n", __bt_get_error_message(ret));
893 int test_set_params(int test_id, char *param)
895 static int param_index = 0;
898 if (param_index > 0 && param_index == g_test_param.param_count)
900 switch (current_tc_table) {
901 case BT_MESH_UNIT_TEST_TABLE_NETWORK: {
903 case BT_MESH_UNIT_TEST_FUNCTION_NETWORK_CREATE:
905 switch (param_index) {
907 TC_PRT("Input param(%d) (network_name)\n", param_index + 1);
910 TC_PRT("Input param(%d) (Node Handle)\n", param_index + 1);
914 case BT_MESH_UNIT_TEST_FUNCTION_NETWORK_DESTROY:
916 TC_PRT("Input param(%d) (network_handle)\n", param_index + 1);
918 case BT_MESH_UNIT_TEST_FUNCTION_NETWORK_CREATE_AND_DESTROY_IN_LOOP:
920 TC_PRT("Input param(%d) (Num networks to create & destroy)\n", param_index + 1);
922 case BT_MESH_UNIT_TEST_FUNCTION_NETWORK_CREATE_IN_LOOP:
924 TC_PRT("Input param(%d) (Number of networks)\n", param_index + 1);
926 case BT_MESH_UNIT_TEST_FUNCTION_NETWORK_INIT_AND_DEINIT_IN_LOOP:
928 TC_PRT("Input param(%d) (Number of networks)\n", param_index + 1);
930 case BT_MESH_UNIT_TEST_FUNCTION_NODE_DESTROY:
932 TC_PRT("Input param(%d) (node Handle)\n", param_index + 1);
934 case BT_MESH_UNIT_TEST_FUNCTION_NODE_GET_NETWORK:
936 TC_PRT("Input param(%d) (node Handle)\n", param_index + 1);
938 case BT_MESH_UNIT_TEST_FUNCTION_NODE_CREATE_ELEMENT:
940 TC_PRT("Input param(%d) (node Handle)\n", param_index + 1);
942 case BT_MESH_UNIT_TEST_FUNCTION_ELEMENT_CREATE_MODEL:
944 switch (param_index) {
946 TC_PRT("Input param(%d) (Element Handle)\n", param_index + 1);
949 TC_PRT("Input param(%d) (Model ID)\n", param_index + 1);
953 case BT_MESH_UNIT_TEST_FUNCTION_ELEMENT_GET_NODE:
955 TC_PRT("Input param(%d) (Element Handle)\n", param_index + 1);
957 case BT_MESH_UNIT_TEST_FUNCTION_MODEL_GET_ID:
959 TC_PRT("Input param(%d) (Model Handle)\n", param_index + 1);
961 case BT_MESH_UNIT_TEST_FUNCTION_MODEL_DESTROY:
963 TC_PRT("Input param(%d) (Model Handle)\n", param_index + 1);
965 case BT_MESH_UNIT_TEST_FUNCTION_MODEL_GET_ELEMENT:
967 TC_PRT("Input param(%d) (Model Handle)\n", param_index + 1);
969 case BT_MESH_UNIT_TEST_FUNCTION_ELEMENT_DESTROY:
971 TC_PRT("Input param(%d) (Element Handle)\n", param_index + 1);
973 case BT_MESH_UNIT_TEST_FUNCTION_NODE_FOREACH_ELEMENTS:
975 TC_PRT("Input param(%d) (Node Handle)", param_index + 1);
977 case BT_MESH_UNIT_TEST_FUNCTION_ELEMENT_FOREACH_MODELS:
979 TC_PRT("Input param(%d) (Element Handle)", param_index + 1);
981 case BT_MESH_UNIT_TEST_FUNCTION_NETWORK_CREATE_GROUP:
983 TC_PRT("Input param(%d) (group address)\n", param_index + 1);
985 case BT_MESH_UNIT_TEST_FUNCTION_NETWORK_REMOVE_GROUP:
987 TC_PRT("Input param(%d) (group handle)\n", param_index + 1);
989 case BT_MESH_UNIT_TEST_FUNCTION_NETWORK_UNPROVISIONED_DEVICE_SCAN:
991 TC_PRT("Input param(%d) (Seconds)\n" , param_index + 1);
993 case BT_MESH_UNIT_TEST_FUNCTION_NETWORK_PROVISION_DEVICE:
995 TC_PRT("Input param(%d) (device_uuid)\n", param_index+1);
997 case BT_MESH_UNIT_TEST_FUNCTION_NETWORK_SET_NAME:
999 TC_PRT("Input param(%d) (network_name)", param_index + 1);
1001 case BT_MESH_UNIT_TEST_FUNCTION_NETWORK_LOAD:
1003 TC_PRT("Input param(%d) (network Token)", param_index + 1);
1005 case BT_MESH_UNIT_TEST_FUNCTION_MESH_AUTHENTICATION_REPLY:
1007 switch (param_index) {
1009 TC_PRT("Input param(%d) (auth_value)\n", param_index +1);
1012 TC_PRT("Input param(%d) (auth_reply)\n", param_index + 1);
1013 TC_PRT("0: false, 1: true");
1017 case BT_MESH_UNIT_TEST_FUNCTION_NETWORK_SET_PROVISIONING_CAPABILITIES:
1019 switch (param_index) {
1021 TC_PRT("\nInput param(%d) is_public_oob", param_index + 1);
1022 TC_PRT("0: false, 1: true\n");
1025 TC_PRT("\nInput param(%d) is_static_oob", param_index + 1);
1026 TC_PRT("0: false, 1 : true\n");
1029 TC_PRT("\nInput param(%d) output_oob", param_index + 1);
1030 TC_PRT("BT_MESH_OUT_OOB_METHOD_BLINK = 0x01");
1031 TC_PRT("BT_MESH_OUT_OOB_METHOD_BEEP = 0x02");
1032 TC_PRT("BT_MESH_OUT_OOB_METHOD_VIBRATE = 0x04");
1033 TC_PRT("BT_MESH_OUT_OOB_METHOD_NUMERIC = 0x08");
1034 TC_PRT("BT_MESH_OUT_OOB_METHOD_ALPHANUMERIC = 0x10\n");
1037 TC_PRT("\nInput param(%d) input_oob", param_index + 1);
1038 TC_PRT("BT_MESH_IN_OOB_METHOD_PUSH = 0x01");
1039 TC_PRT("BT_MESH_IN_OOB_METHOD_TWIST = 0x02");
1040 TC_PRT("BT_MESH_IN_OOB_METHOD_NUMERIC = 0x04");
1041 TC_PRT("BT_MESH_IN_OOB_METHOD_ALPHANUMERIC = 0x08\n");
1045 case BT_MESH_UNIT_TEST_FUNCTION_NETKEY_GET_INDEX:
1047 TC_PRT("Input param(%d) (NetKey Handle)", param_index + 1);
1049 case BT_MESH_UNIT_TEST_FUNCTION_NETKEY_UPDATE:
1051 TC_PRT("Input param(%d) (NetKey Handle)", param_index + 1);
1053 case BT_MESH_UNIT_TEST_FUNCTION_NETKEY_DELETE:
1055 TC_PRT("Input param(%d) (NetKey Handle)", param_index + 1);
1057 case BT_MESH_UNIT_TEST_FUNCTION_NETKEY_ADD_APPKEY:
1059 TC_PRT("Input param(%d) (NetKey Handle)", param_index + 1);
1061 case BT_MESH_UNIT_TEST_FUNCTION_NETKEY_FOREACH_APPKEYS:
1063 TC_PRT("Input param(%d) (NetKey Handle)", param_index + 1);
1065 case BT_MESH_UNIT_TEST_FUNCTION_APPKEY_GET_INDEX:
1067 TC_PRT("Input param(%d) (AppKey Handle)", param_index + 1);
1069 case BT_MESH_UNIT_TEST_FUNCTION_APPKEY_UPDATE:
1071 TC_PRT("Input param(%d) (AppKey Handle)", param_index + 1);
1073 case BT_MESH_UNIT_TEST_FUNCTION_APPKEY_DELETE:
1075 TC_PRT("Input param(%d) (AppKey Handle)", param_index + 1);
1077 case BT_MESH_UNIT_TEST_FUNCTION_ACTIVATE_FLAG_TO_SET_PARAMETERS:
1078 need_to_set_params = true;
1079 TC_PRT("\nSelect the function again\n");
1082 TC_PRT("There is no parameter to set\n");
1087 case BT_MESH_UNIT_TEST_TABLE_SCENARIO: {
1089 case BT_MESH_UNIT_TEST_SCENARIO_PROVISION_DEVICE:
1091 TC_PRT("Input param(%d) (device_uuid)\n", param_index+1);
1093 case BT_MESH_UNIT_TEST_SCENARIO_NODE_RESET:
1095 TC_PRT("Input param(%d) (node handle)\n", param_index+1);
1097 case BT_MESH_UNIT_TEST_SCENARIO_NODE_CONFIGURE_KEY:
1099 TC_PRT("Input param(%d) (node handle)\n", param_index+1);
1101 case BT_MESH_UNIT_TEST_SCENARIO_MODEL_GENERIC_ONOFF_SET_ON:
1103 TC_PRT("Input param(%d) (model handle)\n", param_index+1);
1105 case BT_MESH_UNIT_TEST_SCENARIO_MODEL_GENERIC_ONOFF_SET_OFF:
1107 TC_PRT("Input param(%d) (model handle)\n", param_index+1);
1109 case BT_MESH_UNIT_TEST_SCENARIO_GROUP_GENERIC_ONOFF_SET_ON:
1111 TC_PRT("Input param(%d) (group handle)\n", param_index+1);
1113 case BT_MESH_UNIT_TEST_SCENARIO_GROUP_GENERIC_ONOFF_SET_OFF:
1115 TC_PRT("Input param(%d) (group handle)\n", param_index+1);
1117 case BT_MESH_UNIT_TEST_FUNCTION_ACTIVATE_FLAG_TO_SET_PARAMETERS:
1118 need_to_set_params = true;
1119 TC_PRT("\nSelect the function again\n");
1122 TC_PRT("There is no parameter to set\n");
1127 case BT_MESH_UNIT_TEST_TABLE_CONFIGURATION: {
1129 case BT_MESH_UNIT_TEST_FUNCTION_MESH_NETWORK_DISCOVER_NODE:
1131 TC_PRT("Input param(%d) (device_uuid)", param_index + 1);
1133 case BT_MESH_UNIT_TEST_FUNCTION_NODE_RESET:
1135 TC_PRT("Input param(%d) (Node Handle)", param_index + 1);
1137 case BT_MESH_UNIT_TEST_FUNCTION_NODE_GET_FEATURES:
1139 TC_PRT("Input param(%d) (Node Handle)", param_index + 1);
1141 case BT_MESH_UNIT_TEST_FUNCTION_NODE_GET_NETKEYS:
1143 TC_PRT("Input param(%d) (Node Handle)", param_index + 1);
1145 case BT_MESH_UNIT_TEST_FUNCTION_NODE_GET_APPKEYS:
1147 switch (param_index) {
1149 TC_PRT("Input param(%d) (Node Handle)", param_index + 1);
1152 TC_PRT("Input param(%d) (Netkey Handle)\n", param_index + 1);
1156 case BT_MESH_UNIT_TEST_FUNCTION_APPKEY_GET_NETKEY:
1158 TC_PRT("Input param(%d) (AppKey Handle)\n", param_index + 1);
1160 case BT_MESH_UNIT_TEST_FUNCTION_MODEL_GET_PUBLICATION:
1162 TC_PRT("Input param(%d) (Model Handle)\n", param_index + 1);
1164 case BT_MESH_UNIT_TEST_FUNCTION_MODEL_SET_PUBLICATION:
1166 switch (param_index) {
1168 TC_PRT("\nInput param(%d) Model handle\n", param_index + 1);
1171 TC_PRT("\nInput param(%d) AppKey handle\n", param_index + 1);
1174 TC_PRT("\nInput param(%d) Group Handle\n", param_index + 1);
1178 case BT_MESH_UNIT_TEST_FUNCTION_MODEL_GET_SUBSCRIPTION_LIST:
1180 TC_PRT("Input param(%d) (Model Handle)\n", param_index + 1);
1182 case BT_MESH_UNIT_TEST_FUNCTION_MODEL_CONFIGURE_GROUP_SUBSCRIPTION:
1183 case BT_MESH_UNIT_TEST_FUNCTION_MODEL_CONFIGURE_VIRTUAL_GROUP_SUBSCRIPTION:
1185 switch (param_index) {
1187 TC_PRT("\nInput param(%d) Model handle\n", param_index + 1);
1190 TC_PRT("\nInput param(%d) Model operation", param_index + 1);
1191 TC_PRT("BT_MESH_MODEL_SUBSCRIPTION_ADD = 0");
1192 TC_PRT("BT_MESH_MODEL_SUBSCRIPTION_DELETE = 1");
1193 TC_PRT("BT_MESH_MODEL_SUBSCRIPTION_DELETE_ALL = 2");
1194 TC_PRT("BT_MESH_MODEL_SUBSCRIPTION_OVERWRITE = 3\n");
1197 TC_PRT("\nInput param(%d) Group Handle\n", param_index + 1);
1201 case BT_MESH_UNIT_TEST_FUNCTION_MODEL_GET_APPKEY_LIST:
1203 TC_PRT("Input param(%d) (Model Handle)\n", param_index + 1);
1205 case BT_MESH_UNIT_TEST_FUNCTION_MODEL_BIND_APPKEY:
1206 case BT_MESH_UNIT_TEST_FUNCTION_MODEL_UNBIND_APPKEY:
1208 switch (param_index) {
1210 TC_PRT("\nInput param(%d) Model Handle\n", param_index + 1);
1213 TC_PRT("\nInput param(%d) AppKey handle\n", param_index + 1);
1217 case BT_MESH_UNIT_TEST_FUNCTION_NODE_CONFIGURE_NETKEY:
1218 case BT_MESH_UNIT_TEST_FUNCTION_NODE_CONFIGURE_APPKEY:
1220 switch (param_index) {
1222 TC_PRT("\nInput param(%d) Node Handle\n", param_index + 1);
1225 TC_PRT("\nInput param(%d) Key Handle\n", param_index + 1);
1228 TC_PRT("\nInput param(%d) Key Config Option", param_index + 1);
1229 TC_PRT("BT_MESH_NODE_KEY_ADD = 0");
1230 TC_PRT("BT_MESH_NODE_KEY_UPDATE = 1");
1231 TC_PRT("BT_MESH_NODE_KEY_DELETE = 2\n");
1235 case BT_MESH_UNIT_TEST_FUNCTION_NODE_GET_TTL:
1237 TC_PRT("\nInput param(%d) Node Handle\n", param_index + 1);
1239 case BT_MESH_UNIT_TEST_FUNCTION_NODE_SET_TTL:
1241 switch (param_index) {
1243 TC_PRT("\nInput param(%d) Node Handle\n", param_index + 1);
1246 TC_PRT("\nInput param(%d) TTL value\n", param_index + 1);
1251 TC_PRT("There is no parameter to set\n");
1256 case BT_MESH_UNIT_TEST_TABLE_CONTROL: {
1258 case BT_MESH_UNIT_TEST_FUNCTION_MODEL_SEND_MSG:
1260 switch (param_index) {
1262 TC_PRT("Input param(%d) (Model Handle)\n", param_index + 1);
1265 TC_PRT("Input param(%d) (Appkey Handle)\n", param_index + 1);
1268 TC_PRT("Input param(%d) (opcode)\n", param_index + 1);
1271 TC_PRT("Input param(%d) (Message)\n", param_index + 1);
1275 case BT_MESH_UNIT_TEST_FUNCTION_GROUP_SEND_MSG:
1277 switch (param_index) {
1279 TC_PRT("Input param(%d) (Group Handle)\n", param_index + 1);
1282 TC_PRT("Input param(%d) (Appkey Handle)\n", param_index + 1);
1285 TC_PRT("Input param(%d) (opcode)\n", param_index + 1);
1288 TC_PRT("Input param(%d) (Message)\n", param_index + 1);
1293 TC_PRT("There is no parameter to set\n");
1299 TC_PRT("There is no parameter to set\n");
1300 need_to_set_params = false;
1305 if (need_to_set_params) {
1306 if (param_index == 0) {
1307 g_test_param.param_count = param_count;
1308 g_test_param.params = g_malloc0(sizeof(char*) * g_test_param.param_count);
1311 if (param_index > 0) {
1312 int len = strlen(param);
1313 param[len - 1] = '\0';
1314 g_test_param.params[param_index - 1] = g_strdup(param);
1317 if (param_index == g_test_param.param_count) {
1318 need_to_set_params = false;
1320 test_input_callback((void *)(uintptr_t)test_id);
1322 test_input_callback((void *)test_id);
1334 int test_input_callback(void *data)
1338 int test_id = (uintptr_t)data;
1340 int test_id = (int)data;
1343 switch (current_tc_table) {
1344 case BT_MESH_UNIT_TEST_TABLE_MAIN: {
1347 TC_PRT("Finished\n");
1348 g_main_loop_quit(main_loop);
1350 case BT_MESH_UNIT_TEST_FUNCTION_INITIALIZE:
1351 ret = bt_mesh_initialize();
1352 TC_PRT("return %s\n", __bt_get_error_message(ret));
1354 case BT_MESH_UNIT_TEST_FUNCTION_DEINITIALIZE:
1355 ret = bt_mesh_deinitialize();
1356 TC_PRT("return %s\n", __bt_get_error_message(ret));
1363 case BT_MESH_UNIT_TEST_TABLE_NETWORK:{
1365 case BT_MESH_UNIT_TEST_FUNCTION_NODE_CREATE:{
1366 bt_mesh_node_features_s features;
1367 features.cid = 0x00aa;
1368 features.pid = 0x00ab;
1369 features.vid = 0x00ac;
1370 features.crpl = 0x7fff;
1371 features.features = BT_MESH_FEATURE_RELAY;
1372 features.features |= BT_MESH_FEATURE_LOWPOWER;
1374 ret = bt_mesh_node_create(&features, &local_node);
1375 TC_PRT("return %s\n", __bt_get_error_message(ret));
1376 if (ret == BT_ERROR_NONE)
1377 print_node_handle(local_node);
1380 case BT_MESH_UNIT_TEST_FUNCTION_NODE_DESTROY: {
1381 bt_mesh_node_h node_h;
1382 if (g_test_param.param_count != 1) {
1383 TC_PRT("Enter parameters first!");
1386 node_h = GUINT_TO_POINTER(strtoul(g_test_param.params[0], NULL, 16));
1387 ret = bt_mesh_node_destroy(node_h);
1388 TC_PRT("return %s\n", __bt_get_error_message(ret));
1391 case BT_MESH_UNIT_TEST_FUNCTION_NODE_GET_NETWORK: {
1392 bt_mesh_network_h net_h;
1393 bt_mesh_node_h node_h;
1394 if (g_test_param.param_count != 1) {
1395 TC_PRT("Enter parameters first!");
1398 node_h = GUINT_TO_POINTER(strtoul(g_test_param.params[0], NULL, 16));
1399 ret = bt_mesh_node_get_network(node_h, &net_h);
1400 TC_PRT("return %s\n", __bt_get_error_message(ret));
1401 if (ret == BT_ERROR_NONE)
1402 print_network_handle(net_h);
1405 case BT_MESH_UNIT_TEST_FUNCTION_NODE_CREATE_ELEMENT: {
1406 bt_mesh_element_h elem_h;
1407 bt_mesh_node_h node_h;
1408 if (g_test_param.param_count != 1) {
1409 TC_PRT("Enter parameters first!");
1412 node_h = GUINT_TO_POINTER(strtoul(g_test_param.params[0], NULL, 16));
1413 ret = bt_mesh_node_create_element(node_h, &elem_h);
1414 TC_PRT("return %s\n", __bt_get_error_message(ret));
1415 if (ret == BT_ERROR_NONE)
1416 print_element_handle(elem_h);
1419 case BT_MESH_UNIT_TEST_FUNCTION_ELEMENT_CREATE_MODEL: {
1420 bt_mesh_element_h elem_h;
1421 bt_mesh_model_h model_h;
1422 bt_mesh_model_id_s mod_id;
1423 memset(&mod_id, 0x00, sizeof(bt_mesh_model_id_s));
1425 if (g_test_param.param_count != 2) {
1426 TC_PRT("Enter parameters first!");
1429 elem_h = GUINT_TO_POINTER(strtoul(g_test_param.params[0], NULL, 16));
1430 mod_id.model_id = strtoul(g_test_param.params[1], NULL, 16);
1431 mod_id.company_id = 0xFFFF;
1432 TC_PRT("The model_id is [0x%2.2x]\n", mod_id.model_id);
1433 ret = bt_mesh_element_create_model(elem_h, &mod_id, &model_h);
1434 TC_PRT("return %s\n", __bt_get_error_message(ret));
1435 if (ret == BT_ERROR_NONE)
1436 print_model_handle(model_h);
1439 case BT_MESH_UNIT_TEST_FUNCTION_ELEMENT_GET_NODE: {
1440 bt_mesh_element_h elem_h;
1441 bt_mesh_node_h node_h;
1442 if (g_test_param.param_count != 1) {
1443 TC_PRT("Enter parameter first!");
1446 elem_h = GUINT_TO_POINTER(strtoul(g_test_param.params[0], NULL, 16));
1447 ret = bt_mesh_element_get_node(elem_h, &node_h);
1448 TC_PRT("return %s\n", __bt_get_error_message(ret));
1450 if (ret == BT_ERROR_NONE)
1451 print_node_handle(node_h);
1454 case BT_MESH_UNIT_TEST_FUNCTION_MODEL_GET_ID: {
1455 bt_mesh_model_id_s model_id;
1456 memset(&model_id, 0x00, sizeof(bt_mesh_model_id_s));
1457 bt_mesh_model_h mod_h;
1458 if (g_test_param.param_count != 1) {
1459 TC_PRT("Enter parameter first!");
1462 mod_h = GUINT_TO_POINTER(strtoul(g_test_param.params[0], NULL, 16));
1463 ret = bt_mesh_model_get_id(mod_h, &model_id);
1464 TC_PRT("return %s\n", __bt_get_error_message(ret));
1465 if (ret == BT_ERROR_NONE) {
1466 TC_PRT("The Model ID is [0x%2.2x]", model_id.model_id);
1467 TC_PRT("The Company ID is [0x%2.2x]", model_id.company_id);
1471 case BT_MESH_UNIT_TEST_FUNCTION_MODEL_DESTROY: {
1472 bt_mesh_model_h mod_h;
1473 if (g_test_param.param_count != 1) {
1474 TC_PRT("Enter parameter first!");
1477 mod_h = GUINT_TO_POINTER(strtoul(g_test_param.params[0], NULL, 16));
1478 ret = bt_mesh_model_destroy(mod_h);
1479 TC_PRT("return %s\n", __bt_get_error_message(ret));
1482 case BT_MESH_UNIT_TEST_FUNCTION_MODEL_GET_ELEMENT: {
1483 bt_mesh_model_h mod_h;
1484 bt_mesh_element_h elem_h;
1485 if (g_test_param.param_count != 1) {
1486 TC_PRT("Enter parameter first!");
1489 mod_h = GUINT_TO_POINTER(strtoul(g_test_param.params[0], NULL, 16));
1490 ret = bt_mesh_model_get_element(mod_h, &elem_h);
1491 TC_PRT("return %s\n", __bt_get_error_message(ret));
1492 if (ret == BT_ERROR_NONE)
1493 print_element_handle(elem_h);
1496 case BT_MESH_UNIT_TEST_FUNCTION_ELEMENT_DESTROY: {
1497 bt_mesh_element_h elem_h;
1498 if (g_test_param.param_count != 1) {
1499 TC_PRT("Enter parameter first!");
1502 elem_h = GUINT_TO_POINTER(strtoul(g_test_param.params[0], NULL, 16));
1503 ret = bt_mesh_element_destroy(elem_h);
1504 TC_PRT("return %s\n", __bt_get_error_message(ret));
1507 case BT_MESH_UNIT_TEST_FUNCTION_NODE_FOREACH_ELEMENTS: {
1508 bt_mesh_node_h node_h = 0;
1509 if (g_test_param.param_count != 1) {
1510 TC_PRT("Enter Input parameter first.\n");
1513 node_h = GUINT_TO_POINTER(strtoul(g_test_param.params[0], NULL, 16));
1514 ret = bt_mesh_node_foreach_element(node_h, __bt_mesh_node_foreach_elem_cb, NULL);
1515 TC_PRT("return %s\n", __bt_get_error_message(ret));
1518 case BT_MESH_UNIT_TEST_FUNCTION_ELEMENT_FOREACH_MODELS: {
1519 bt_mesh_element_h element_h = 0;
1520 if (g_test_param.param_count != 1) {
1521 TC_PRT("Enter Input parameter first.\n");
1524 element_h = GUINT_TO_POINTER(strtoul(g_test_param.params[0], NULL, 16));
1525 ret = bt_mesh_element_foreach_models(element_h, __bt_mesh_elem_foreach_model_cb, NULL);
1526 TC_PRT("return %s\n", __bt_get_error_message(ret));
1529 case BT_MESH_UNIT_TEST_FUNCTION_NETWORK_CREATE: {
1530 char* network_name = "Mesh Test Network";
1531 bt_mesh_node_h node_h;
1532 if (g_test_param.param_count != 2) {
1533 TC_PRT("Enter Input parameter first.\n");
1536 network_name = g_strdup(g_test_param.params[0]);
1537 node_h = GUINT_TO_POINTER(strtoul(g_test_param.params[1], NULL, 16));
1538 ret = bt_mesh_network_create(node_h, (const char*)network_name, &network, &token);
1539 TC_PRT("return %s\n", __bt_get_error_message(ret));
1540 if (ret == BT_ERROR_NONE) {
1541 TC_PRT("Network Created, token [%s]", token);
1542 print_network_handle(network);
1544 g_free(network_name);
1547 case BT_MESH_UNIT_TEST_FUNCTION_NETWORK_DESTROY: {
1548 bt_mesh_network_h network_h;
1549 if (g_test_param.param_count != 1) {
1550 TC_PRT("Enter parameters first!");
1553 network_h = GUINT_TO_POINTER(strtoul(g_test_param.params[0], NULL, 16));
1554 ret = bt_mesh_network_destroy(network_h);
1555 TC_PRT("return %s\n", __bt_get_error_message(ret));
1558 case BT_MESH_UNIT_TEST_FUNCTION_NETWORK_CREATE_IN_LOOP: {
1559 char* network_name = "Mesh Test Network";
1561 if (g_test_param.param_count != 1) {
1562 TC_PRT("Enter Input parameter first.\n");
1566 int num = atoi(g_test_param.params[0]);
1568 if (num < 0 || num > INT_MAX) {
1569 TC_PRT("Input Number out of bounds \n");
1573 TC_PRT("Create [%d] Networks", num);
1574 for (int i = 0; i < num; i++) {
1577 bt_mesh_node_h node_h;
1578 bt_mesh_node_features_s features;
1579 memset(&features, 0x00, sizeof(bt_mesh_node_features_s));
1580 features.cid = 0x00aa;
1581 features.vid = 0x00bb;
1582 features.pid = 0x00cc;
1583 features.crpl = 0x00dd;
1584 features.features = BT_MESH_FEATURE_RELAY;
1585 features.features |= BT_MESH_FEATURE_LOWPOWER;
1586 features.features |= BT_MESH_FEATURE_FRIEND;
1588 ret = bt_mesh_node_create(&features, &node_h);
1589 TC_PRT("return %s\n", __bt_get_error_message(ret));
1590 if (ret == BT_ERROR_NONE) {
1592 TC_PRT("Node Creation Failed!");
1596 /* Create Element */
1597 bt_mesh_element_h elem_h;
1598 ret = bt_mesh_node_create_element(node_h, &elem_h);
1599 TC_PRT("return %s\n", __bt_get_error_message(ret));
1600 if (ret == BT_ERROR_NONE) {
1602 TC_PRT("Element Creation Failed!");
1607 bt_mesh_model_h model_h;
1608 bt_mesh_model_id_s mod_id;
1609 memset(&mod_id, 0x00, sizeof(bt_mesh_model_id_s));
1611 mod_id.model_id = 0x0003;
1612 mod_id.company_id = 0xFFFF;
1613 ret = bt_mesh_element_create_model(elem_h, &mod_id, &model_h);
1614 TC_PRT("return %s\n", __bt_get_error_message(ret));
1615 if (ret == BT_ERROR_NONE) {
1617 TC_PRT("Model Creation Failed!");
1621 /* Create Network */
1622 network_name = g_strdup_printf("TestMeshNet%d", i);
1623 bt_mesh_network_h net_h;
1625 ret = bt_mesh_network_create(node_h, (const char*)network_name, &net_h, &token);
1626 TC_PRT("return %s\n", __bt_get_error_message(ret));
1627 if (ret == BT_ERROR_NONE) {
1628 TC_PRT("Network Created, token [%s] Network Number[%d]", token, i);
1629 networks = g_slist_append(networks, net_h);
1631 TC_PRT("Network Creation Failed!");
1634 g_free(network_name);
1639 case BT_MESH_UNIT_TEST_FUNCTION_NETWORK_DESTROY_ALL_NETWORKS: {
1640 bt_mesh_network_h net_h;
1642 TC_PRT("Mesh: Destroy ALL networks : total [%d]",
1643 g_slist_length(networks));
1645 /* Destroy Network */
1646 for (l = networks; l != NULL;) {
1648 l = g_slist_next(l);
1649 networks = g_slist_remove(networks, net_h);
1651 ret = bt_mesh_network_destroy(net_h);
1652 TC_PRT("return %s\n", __bt_get_error_message(ret));
1653 if (ret == BT_ERROR_NONE) {
1654 TC_PRT("Network Destroyed Successfully!");
1656 TC_PRT("Network Destroy Failed!!....break out");
1662 case BT_MESH_UNIT_TEST_FUNCTION_NETWORK_CREATE_AND_DESTROY_IN_LOOP: {
1663 char* network_name = "Mesh Test Network";
1665 if (g_test_param.param_count != 1) {
1666 TC_PRT("Enter Input parameter first.\n");
1669 int num = atoi(g_test_param.params[0]);
1671 if (num < 0 || num > INT_MAX) {
1672 TC_PRT("Input Number out of bounds \n");
1676 TC_PRT("Create [%d] Networks", num);
1677 for (int i = 0; i < num; i++) {
1680 bt_mesh_node_h node_h;
1681 bt_mesh_node_features_s features;
1682 features.features = BT_MESH_FEATURE_RELAY;
1683 features.features |= BT_MESH_FEATURE_LOWPOWER;
1685 ret = bt_mesh_node_create(&features, &node_h);
1686 TC_PRT("return %s\n", __bt_get_error_message(ret));
1687 if (ret == BT_ERROR_NONE) {
1689 TC_PRT("Node Creation Failed!");
1693 /* Create Element */
1694 bt_mesh_element_h elem_h;
1695 ret = bt_mesh_node_create_element(node_h, &elem_h);
1696 TC_PRT("return %s\n", __bt_get_error_message(ret));
1697 if (ret == BT_ERROR_NONE) {
1699 TC_PRT("Element Creation Failed!");
1704 bt_mesh_model_h model_h;
1705 bt_mesh_model_id_s mod_id;
1706 memset(&mod_id, 0x00, sizeof(bt_mesh_model_id_s));
1708 mod_id.model_id = 0x0003;
1709 mod_id.company_id = 0xFFFF;
1710 ret = bt_mesh_element_create_model(elem_h, &mod_id, &model_h);
1711 TC_PRT("return %s\n", __bt_get_error_message(ret));
1712 if (ret == BT_ERROR_NONE) {
1714 TC_PRT("Model Creation Failed!");
1717 /* Create Network */
1718 network_name = g_strdup_printf("TestMeshNet%d", i);
1719 bt_mesh_network_h net_h;
1721 ret = bt_mesh_network_create(node_h, (const char*)network_name, &net_h, &token);
1722 TC_PRT("return %s\n", __bt_get_error_message(ret));
1723 if (ret == BT_ERROR_NONE) {
1724 TC_PRT("Network Created, token [%s] Network Number[%d]", token, i);
1726 TC_PRT("Network Creation Failed!");
1729 g_free(network_name);
1731 /* Destroy Network */
1732 ret = bt_mesh_network_destroy(net_h);
1733 TC_PRT("return %s\n", __bt_get_error_message(ret));
1734 if (ret == BT_ERROR_NONE) {
1735 TC_PRT("Network Destroyed Successfully!");
1737 TC_PRT("Network Destroy Failed!!....break out");
1743 case BT_MESH_UNIT_TEST_FUNCTION_NETWORK_INIT_AND_DEINIT_IN_LOOP: {
1744 char* network_name = "Mesh Test Network";
1746 if (g_test_param.param_count != 1) {
1747 TC_PRT("Enter Input parameter first.\n");
1750 int num = atoi(g_test_param.params[0]);
1752 if (num < 0 || num > INT_MAX) {
1753 TC_PRT("Input Number out of bounds \n");
1757 TC_PRT("Create [%d] Networks", num);
1758 for (int i = 0; i < num; i++) {
1761 ret = bt_mesh_initialize();
1762 if (ret == BT_ERROR_NONE) {
1763 TC_PRT("Mesh init Passed!");
1765 TC_PRT("Mesh init failed!");
1770 bt_mesh_node_h node_h;
1771 bt_mesh_node_features_s features;
1772 features.features = BT_MESH_FEATURE_RELAY;
1773 features.features |= BT_MESH_FEATURE_LOWPOWER;
1775 ret = bt_mesh_node_create(&features, &node_h);
1776 TC_PRT("return %s\n", __bt_get_error_message(ret));
1777 if (ret == BT_ERROR_NONE) {
1779 TC_PRT("Node Creation Failed!");
1783 /* Create Element */
1784 bt_mesh_element_h elem_h;
1785 ret = bt_mesh_node_create_element(node_h, &elem_h);
1786 TC_PRT("return %s\n", __bt_get_error_message(ret));
1787 if (ret == BT_ERROR_NONE) {
1789 TC_PRT("Element Creation Failed!");
1794 bt_mesh_model_h model_h;
1795 bt_mesh_model_id_s mod_id;
1796 memset(&mod_id, 0x00, sizeof(bt_mesh_model_id_s));
1798 mod_id.model_id = 0x0003;
1799 mod_id.company_id = 0xFFFF;
1800 ret = bt_mesh_element_create_model(elem_h, &mod_id, &model_h);
1801 TC_PRT("return %s\n", __bt_get_error_message(ret));
1802 if (ret == BT_ERROR_NONE) {
1804 TC_PRT("Model Creation Failed!");
1809 * System-d has start-limit on number of process to be started in given time
1810 * Sleep for 2000 msec
1814 /* Create Network */
1815 network_name = g_strdup_printf("TestMeshNet%d", i);
1816 bt_mesh_network_h net_h;
1818 ret = bt_mesh_network_create(node_h, (const char*)network_name, &net_h, &token);
1819 TC_PRT("return %s\n", __bt_get_error_message(ret));
1820 if (ret == BT_ERROR_NONE) {
1821 TC_PRT("Network Created, token [%s] Network Number[%d]", token, i);
1823 TC_PRT("Network Creation Failed!");
1826 g_free(network_name);
1829 ret = bt_mesh_deinitialize();
1830 if (ret == BT_ERROR_NONE)
1831 TC_PRT("Mesh De-init Passed!");
1833 TC_PRT("Mesh De-init failed!");
1837 case BT_MESH_UNIT_TEST_FUNCTION_NETWORK_LOAD: {
1839 if (g_test_param.param_count != 1) {
1840 TC_PRT("Enter parameter first!");
1843 token_str = g_strdup(g_test_param.params[0]);
1844 ret = bt_mesh_network_load(token_str, &network);
1845 TC_PRT("return %s\n", __bt_get_error_message(ret));
1846 if (ret == BT_ERROR_NONE)
1847 print_network_handle(network);
1851 case BT_MESH_UNIT_TEST_FUNCTION_NETWORK_SET_NAME: {
1852 char* network_name = "tempName";
1853 if (g_test_param.param_count != 1) {
1854 TC_PRT("Enter parameter first!");
1857 network_name = g_strdup(g_test_param.params[0]);
1858 ret = bt_mesh_network_set_name(network, (const char*)network_name);
1859 TC_PRT("return %s\n", __bt_get_error_message(ret));
1860 g_free(network_name);
1863 case BT_MESH_UNIT_TEST_FUNCTION_NETWORK_GET_NAME: {
1865 ret = bt_mesh_network_get_name(network, &network_name);
1866 TC_PRT("return %s\n", __bt_get_error_message(ret));
1867 if (ret == BT_ERROR_NONE)
1868 TC_PRT("network name is [%s]", network_name);
1871 case BT_MESH_UNIT_TEST_FUNCTION_NETWORK_ADD_NETKEY: {
1873 bt_mesh_netkey_h n_h;
1874 ret = bt_mesh_network_add_netkey(network, &n_h);
1875 TC_PRT("return %s\n", __bt_get_error_message(ret));
1876 if (ret == BT_ERROR_NONE)
1877 print_netkey_handle(n_h);
1880 case BT_MESH_UNIT_TEST_FUNCTION_NETWORK_FOREACH_NETKEYS: {
1881 ret = bt_mesh_network_foreach_netkeys(network,
1882 __bt_mesh_network_netkey_info_cb, NULL);
1883 TC_PRT("return %s\n", __bt_get_error_message(ret));
1886 case BT_MESH_UNIT_TEST_FUNCTION_NETKEY_GET_INDEX: {
1887 uint16_t index = 0xFFFF;
1888 bt_mesh_netkey_h netkey_h;
1890 if (g_test_param.param_count != 1) {
1891 TC_PRT("Set parameter first!");
1894 netkey_h = GUINT_TO_POINTER(strtoul(g_test_param.params[0], NULL, 16));
1895 /* Get index for netkey 1 */
1896 ret = bt_mesh_netkey_get_index(netkey_h, &index);
1897 TC_PRT("return %s\n", __bt_get_error_message(ret));
1898 if (ret == BT_ERROR_NONE)
1899 TC_PRT("The index of the netkey is: [%d]", index);
1903 case BT_MESH_UNIT_TEST_FUNCTION_NETKEY_UPDATE: {
1904 bt_mesh_netkey_h netkey_h;
1906 if (g_test_param.param_count != 1) {
1907 TC_PRT("Set parameter first!");
1910 netkey_h = GUINT_TO_POINTER(strtoul(g_test_param.params[0], NULL, 16));
1911 ret = bt_mesh_netkey_update(netkey_h);
1912 TC_PRT("return %s\n", __bt_get_error_message(ret));
1915 case BT_MESH_UNIT_TEST_FUNCTION_NETKEY_DELETE: {
1916 bt_mesh_netkey_h netkey_h;
1918 if (g_test_param.param_count != 1) {
1919 TC_PRT("Set parameter first!");
1922 netkey_h = GUINT_TO_POINTER(strtoul(g_test_param.params[0], NULL, 16));
1923 ret = bt_mesh_netkey_delete(netkey_h);
1924 TC_PRT("return %s\n", __bt_get_error_message(ret));
1925 if (ret == BT_ERROR_NONE)
1926 TC_PRT("netkey is deleted");
1929 case BT_MESH_UNIT_TEST_FUNCTION_NETKEY_ADD_APPKEY: {
1930 bt_mesh_netkey_h netkey_h;
1931 bt_mesh_appkey_h appkey_h;
1933 if (g_test_param.param_count != 1) {
1934 TC_PRT("Set parameter first!");
1937 netkey_h = GUINT_TO_POINTER(strtoul(g_test_param.params[0], NULL, 16));
1938 ret = bt_mesh_netkey_add_appkey(netkey_h, &appkey_h);
1939 TC_PRT("return %s\n", __bt_get_error_message(ret));
1940 if (ret == BT_ERROR_NONE)
1941 print_appkey_handle(appkey_h);
1944 case BT_MESH_UNIT_TEST_FUNCTION_NETKEY_FOREACH_APPKEYS: {
1945 /* Get all appkeys for NetKey 1 */
1946 bt_mesh_netkey_h netkey_h;
1948 if (g_test_param.param_count != 1) {
1949 TC_PRT("Set parameter first!");
1952 netkey_h = GUINT_TO_POINTER(strtoul(g_test_param.params[0], NULL, 16));
1953 ret = bt_mesh_netkey_foreach_appkeys(netkey_h, __bt_mesh_appkey_info_cb, NULL);
1954 TC_PRT("return %s\n", __bt_get_error_message(ret));
1958 case BT_MESH_UNIT_TEST_FUNCTION_APPKEY_GET_INDEX: {
1959 uint16_t index = 0xFFFF;
1960 bt_mesh_appkey_h appkey_h;
1962 if (g_test_param.param_count != 1) {
1963 TC_PRT("Set parameter first!");
1966 appkey_h = GUINT_TO_POINTER(strtoul(g_test_param.params[0], NULL, 16));
1967 /* Get appkey index for appkey 1 */
1968 ret = bt_mesh_appkey_get_index(appkey_h, &index);
1969 TC_PRT("return %s\n", __bt_get_error_message(ret));
1970 if (ret == BT_ERROR_NONE)
1971 TC_PRT("The index of the appkey is: [%d]", index);
1974 case BT_MESH_UNIT_TEST_FUNCTION_APPKEY_UPDATE: {
1975 bt_mesh_appkey_h appkey_h;
1977 if (g_test_param.param_count != 1) {
1978 TC_PRT("Set parameter first!");
1981 appkey_h = GUINT_TO_POINTER(strtoul(g_test_param.params[0], NULL, 16));
1982 ret = bt_mesh_appkey_update(appkey_h);
1983 TC_PRT("return %s\n", __bt_get_error_message(ret));
1986 case BT_MESH_UNIT_TEST_FUNCTION_APPKEY_DELETE: {
1987 bt_mesh_appkey_h appkey_h;
1989 if (g_test_param.param_count != 1) {
1990 TC_PRT("Set parameter first!");
1993 appkey_h = GUINT_TO_POINTER(strtoul(g_test_param.params[0], NULL, 16));
1994 ret = bt_mesh_appkey_delete(appkey_h);
1995 TC_PRT("return %s\n", __bt_get_error_message(ret));
1996 if (ret == BT_ERROR_NONE)
1997 TC_PRT("appkey is deleted");
2000 case BT_MESH_UNIT_TEST_FUNCTION_NETWORK_FOREACH_DEVICES: {
2001 ret = bt_mesh_network_foreach_devices(network, __bt_mesh_network_device_info_cb, NULL);
2002 TC_PRT("return %s\n", __bt_get_error_message(ret));
2005 case BT_MESH_UNIT_TEST_FUNCTION_NETWORK_CREATE_GROUP: {
2006 uint16_t group_addr = 0xc001;
2007 bt_mesh_group_h group_h;
2008 if (g_test_param.param_count != 1) {
2009 TC_PRT("Enter parameter first!!\n");
2012 group_addr = strtoul(g_test_param.params[0], NULL, 16);
2013 TC_PRT("Group addrrss [0x%2.2x]", group_addr);
2014 ret = bt_mesh_network_create_group(network, group_addr, &group_h);
2015 TC_PRT("return %s\n", __bt_get_error_message(ret));
2016 if (ret == BT_ERROR_NONE)
2017 print_group_handle(group_h);
2020 case BT_MESH_UNIT_TEST_FUNCTION_NETWORK_CREATE_VIRTUAL_GROUP: {
2021 bt_mesh_group_h group_h;
2022 ret = bt_mesh_network_create_virtual_group(network, &group_h);
2023 TC_PRT("return %s\n", __bt_get_error_message(ret));
2024 if (ret == BT_ERROR_NONE)
2025 print_group_handle(group_h);
2028 case BT_MESH_UNIT_TEST_FUNCTION_NETWORK_REMOVE_GROUP: {
2029 bt_mesh_group_h group_h;
2030 if (g_test_param.param_count != 1) {
2031 TC_PRT("Enter parameter first!!\n");
2034 group_h = GUINT_TO_POINTER(strtoul(g_test_param.params[0], NULL, 16));
2035 ret = bt_mesh_network_remove_group(group_h);
2036 TC_PRT("return %s\n", __bt_get_error_message(ret));
2039 case BT_MESH_UNIT_TEST_FUNCTION_NETWORK_FOREACH_GROUPS: {
2040 ret = bt_mesh_network_foreach_groups(network,
2041 __bt_mesh_network_group_info_cb, NULL);
2042 TC_PRT("return %s\n", __bt_get_error_message(ret));
2045 case BT_MESH_UNIT_TEST_FUNCTION_NETWORK_UNPROVISIONED_DEVICE_SCAN: {
2046 unprov_dev_list = NULL;
2047 bt_mesh_scan_params_s scan_params;
2048 memset(&scan_params, 0x00, sizeof(bt_mesh_scan_params_s));
2049 if (g_test_param.param_count != 1) {
2050 TC_PRT("Enter Input parameter first.\n");
2053 scan_params.seconds = strtoul(g_test_param.params[0], NULL, 16);
2054 TC_PRT("The scan is set for [%u] seconds", scan_params.seconds);
2055 ret = bt_mesh_network_unprovisioned_device_scan(network, &scan_params,
2056 __bt_mesh_network_scan_unprovisioned_device_result_cb, NULL);
2057 TC_PRT("return %s\n", __bt_get_error_message(ret));
2060 case BT_MESH_UNIT_TEST_FUNCTION_STOP_UNPROVISIONED_DEVICE_SCAN: {
2061 ret = bt_mesh_stop_unprovisioned_device_scan(network);
2062 TC_PRT("return %s\n", __bt_get_error_message(ret));
2063 if (ret == BT_ERROR_NONE)
2064 TC_PRT("Device SCAN : STOPPED");
2067 case BT_MESH_UNIT_TEST_FUNCTION_NETWORK_PROVISION_DEVICE: {
2068 const char *dev_uuid = "abababababababababababababababab";
2069 if (g_test_param.param_count != 1) {
2070 TC_PRT("Enter Input parameter first.\n");
2073 dev_uuid = g_test_param.params[0];
2074 TC_PRT("The dev_uuid is [%s]\n", dev_uuid);
2075 ret = bt_mesh_network_provision_device(network, dev_uuid,
2076 __bt_mesh_network_device_provision_cb, NULL);
2077 TC_PRT("return %s\n", __bt_get_error_message(ret));
2080 case BT_MESH_UNIT_TEST_FUNCTION_NETWORK_AUTHENTICATION_SET_REQUEST_CB: {
2081 ret = bt_mesh_authentication_set_request_cb(
2082 __bt_mesh_authentication_request_cb, NULL);
2083 TC_PRT("return %s\n", __bt_get_error_message(ret));
2086 case BT_MESH_UNIT_TEST_FUNCTION_MESH_AUTHENTICATION_REPLY: {
2090 if (g_test_param.param_count != 2) {
2091 TC_PRT("Enter Input parameter first.\n");
2094 len = strlen(g_test_param.params[0]);
2095 value = g_malloc0(len+1);
2096 g_strlcpy(value, g_test_param.params[0], len+1);
2097 auth_reply = atoi(g_test_param.params[1]);
2098 TC_PRT("\nauth_value is [%s]\n", value);
2099 TC_PRT("auth_reply is [%d]\n", auth_reply);
2100 TC_PRT("auth_type is [%d]\n", request_type);
2101 ret = bt_mesh_authentication_reply(request_type, (const char*)value, auth_reply);
2102 TC_PRT("return %s\n", __bt_get_error_message(ret));
2105 case BT_MESH_UNIT_TEST_FUNCTION_NETWORK_SET_PROVISIONING_CAPABILITIES: {
2106 bt_mesh_provisioner_capabilities_s capabilities;
2107 if (g_test_param.param_count != 4) {
2108 TC_PRT("Enter Input parameter first.");
2111 capabilities.public_oob = atoi(g_test_param.params[0]);
2112 capabilities.static_oob = atoi(g_test_param.params[1]);
2113 capabilities.out_oob = (int)strtol(g_test_param.params[2], NULL, 16);
2114 capabilities.in_oob = (int)strtol(g_test_param.params[3], NULL, 16);
2115 TC_PRT("CAP: PUBLIC OOB [%d]", capabilities.public_oob);
2116 TC_PRT("CAP: STATIC OOB [%d]", capabilities.static_oob);
2117 TC_PRT("CAP: OUT OOB [%d]", capabilities.out_oob);
2118 TC_PRT("CAP: IN OOB [%d]", capabilities.in_oob);
2119 ret = bt_mesh_network_set_provisioning_capabilities(network, &capabilities);
2120 TC_PRT("return %s\n", __bt_get_error_message(ret));
2123 case BT_MESH_UNIT_TEST_FUNCTION_NETWORK_GET_PROVISIONING_CAPABILITIES: {
2124 // TODO: need to implement
2127 case BT_MESH_UNIT_TEST_FUNCTION_ACTIVATE_FLAG_TO_SET_PARAMETERS: {
2128 need_to_set_params = true;
2129 TC_PRT("Select the function again");
2135 __bt_free_test_param(&g_test_param);
2138 case BT_MESH_UNIT_TEST_TABLE_CONFIGURATION: {
2140 case BT_MESH_UNIT_TEST_FUNCTION_MESH_NETWORK_DISCOVER_NODE: {
2141 char* dev_uu = "tempName";
2142 if (g_test_param.param_count > 0) {
2143 dev_uu = g_strdup(g_test_param.params[0]);
2145 TC_PRT("Set Input parameter first!");
2148 ret = bt_mesh_network_discover_node(network, (const char*)dev_uu,
2149 __bt_mesh_node_discover_status_cb, NULL);
2150 TC_PRT("return %s\n", __bt_get_error_message(ret));
2153 case BT_MESH_UNIT_TEST_FUNCTION_NODE_RESET: {
2154 bt_mesh_node_h node_h = 0;
2155 if (g_test_param.param_count != 1) {
2156 TC_PRT("Set Input parameter first!");
2159 node_h = GUINT_TO_POINTER(strtoul(g_test_param.params[0], NULL, 16));
2160 ret = bt_mesh_node_reset(node_h);
2161 TC_PRT("return %s\n", __bt_get_error_message(ret));
2164 case BT_MESH_UNIT_TEST_FUNCTION_NODE_GET_FEATURES: {
2165 bt_mesh_node_h node_h = 0;
2166 if (g_test_param.param_count != 1) {
2167 TC_PRT("Set Input parameter first!");
2170 node_h = GUINT_TO_POINTER(strtoul(g_test_param.params[0], NULL, 16));
2171 ret = bt_mesh_node_get_features(node_h, __bt_mesh_node_features_cb, NULL);
2172 TC_PRT("return %s\n", __bt_get_error_message(ret));
2175 case BT_MESH_UNIT_TEST_FUNCTION_NODE_GET_NETKEYS: {
2176 bt_mesh_node_h node_h = 0;
2177 if (g_test_param.param_count != 1) {
2178 TC_PRT("Set Input parameter first!");
2181 node_h = GUINT_TO_POINTER(strtoul(g_test_param.params[0], NULL, 16));
2182 ret = bt_mesh_node_foreach_netkeys(node_h, __bt_mesh_node_foreach_netkeys_cb, NULL);
2183 TC_PRT("return %s\n", __bt_get_error_message(ret));
2186 case BT_MESH_UNIT_TEST_FUNCTION_NODE_GET_APPKEYS: {
2187 bt_mesh_node_h node_h = 0;
2188 bt_mesh_netkey_h netkey_h = 0;
2189 if (g_test_param.param_count != 2) {
2190 TC_PRT("Set Input parameter first!");
2193 node_h = GUINT_TO_POINTER(strtoul(g_test_param.params[0], NULL, 16));
2194 netkey_h = GUINT_TO_POINTER(strtoul(g_test_param.params[1], NULL, 16));
2196 ret = bt_mesh_node_foreach_appkeys(node_h, netkey_h,
2197 __bt_mesh_node_foreach_appkeys_cb, NULL);
2198 TC_PRT("return %s\n", __bt_get_error_message(ret));
2201 case BT_MESH_UNIT_TEST_FUNCTION_NODE_GET_TTL: {
2202 bt_mesh_node_h node_h = 0;
2203 if (g_test_param.param_count != 1) {
2204 TC_PRT("Set Input parameter first!");
2207 node_h = GUINT_TO_POINTER(strtoul(g_test_param.params[0], NULL, 16));
2208 ret = bt_mesh_node_get_ttl(node_h, __bt_mesh_node_ttl_cb, NULL);
2209 TC_PRT("return %s\n", __bt_get_error_message(ret));
2212 case BT_MESH_UNIT_TEST_FUNCTION_NODE_SET_TTL: {
2213 bt_mesh_node_h node_h = 0;
2215 if (g_test_param.param_count != 2) {
2216 TC_PRT("Set Input parameter first!");
2219 node_h = GUINT_TO_POINTER(strtoul(g_test_param.params[0], NULL, 16));
2220 ttl = atoi(g_test_param.params[1]);
2222 ret = bt_mesh_node_set_ttl(node_h, (uint8_t) ttl, __bt_mesh_node_ttl_cb, NULL);
2223 TC_PRT("return %s\n", __bt_get_error_message(ret));
2226 case BT_MESH_UNIT_TEST_FUNCTION_NODE_CONFIGURE_NETKEY: {
2227 bt_mesh_node_h node_h = 0;
2228 bt_mesh_netkey_h netkey_h = 0;
2229 bt_mesh_node_key_configuration_e config = 0;
2230 if (g_test_param.param_count != 3) {
2231 TC_PRT("Set Input parameter first!");
2234 node_h = GUINT_TO_POINTER(strtoul(g_test_param.params[0], NULL, 16));
2235 netkey_h = GUINT_TO_POINTER(strtoul(g_test_param.params[1], NULL, 16));
2236 config = atoi(g_test_param.params[2]);
2238 ret = bt_mesh_node_configure_netkey(node_h, config, netkey_h,
2239 __bt_mesh_node_configure_netkey_cb, NULL);
2240 TC_PRT("return %s\n", __bt_get_error_message(ret));
2243 case BT_MESH_UNIT_TEST_FUNCTION_NODE_CONFIGURE_APPKEY: {
2244 bt_mesh_node_h node_h = 0;
2245 bt_mesh_appkey_h appkey_h = 0;
2246 bt_mesh_node_key_configuration_e config = 0;
2247 if (g_test_param.param_count != 3) {
2248 TC_PRT("Set Input parameter first!");
2251 node_h = GUINT_TO_POINTER(strtoul(g_test_param.params[0], NULL, 16));
2252 appkey_h = GUINT_TO_POINTER(strtoul(g_test_param.params[1], NULL, 16));
2253 config = atoi(g_test_param.params[2]);
2255 ret = bt_mesh_node_configure_appkey(node_h, config, appkey_h,
2256 __bt_mesh_node_configure_appkey_cb, NULL);
2257 TC_PRT("return %s\n", __bt_get_error_message(ret));
2260 case BT_MESH_UNIT_TEST_FUNCTION_MODEL_BIND_APPKEY: {
2261 bt_mesh_model_h model_h = 0;
2262 bt_mesh_appkey_h appkey_h = 0;
2263 if (g_test_param.param_count != 2) {
2264 TC_PRT("Set Input parameter first!");
2267 model_h = GUINT_TO_POINTER(strtoul(g_test_param.params[0], NULL, 16));
2268 appkey_h = GUINT_TO_POINTER(strtoul(g_test_param.params[1], NULL, 16));
2270 ret = bt_mesh_model_bind_appkey(model_h, appkey_h, __bt_mesh_model_bind_cb, NULL);
2271 TC_PRT("return %s\n", __bt_get_error_message(ret));
2274 case BT_MESH_UNIT_TEST_FUNCTION_MODEL_UNBIND_APPKEY: {
2275 bt_mesh_model_h model_h = 0;
2276 bt_mesh_appkey_h appkey_h = 0;
2277 if (g_test_param.param_count != 2) {
2278 TC_PRT("Set Input parameter first!");
2281 model_h = GUINT_TO_POINTER(strtoul(g_test_param.params[0], NULL, 16));
2282 appkey_h = GUINT_TO_POINTER(strtoul(g_test_param.params[1], NULL, 16));
2284 ret = bt_mesh_model_unbind_appkey(model_h, appkey_h, __bt_mesh_model_unbind_cb, NULL);
2285 TC_PRT("return %s\n", __bt_get_error_message(ret));
2288 case BT_MESH_UNIT_TEST_FUNCTION_MODEL_GET_APPKEY_LIST: {
2289 bt_mesh_model_h model_h = 0;
2290 if (g_test_param.param_count != 1) {
2291 TC_PRT("Set Input parameter first!");
2294 model_h = GUINT_TO_POINTER(strtoul(g_test_param.params[0], NULL, 16));
2296 ret = bt_mesh_model_get_appkey_list(model_h, __bt_mesh_model_appkey_list_cb, NULL);
2297 TC_PRT("return %s\n", __bt_get_error_message(ret));
2300 case BT_MESH_UNIT_TEST_FUNCTION_MODEL_CONFIGURE_GROUP_SUBSCRIPTION: {
2301 bt_mesh_model_h model_h = 0;
2302 bt_mesh_group_h group_h = 0;
2303 bt_mesh_model_subscription_op_e op = BT_MESH_MODEL_SUBSCRIPTION_ADD;
2305 if (g_test_param.param_count != 3) {
2306 TC_PRT("Set Input parameter first!");
2309 model_h = GUINT_TO_POINTER(strtoul(g_test_param.params[0], NULL, 16));
2310 op = atoi(g_test_param.params[1]);
2311 group_h = GUINT_TO_POINTER(strtoul(g_test_param.params[2], NULL, 16));
2313 ret = bt_mesh_model_configure_group_subscription(op, model_h, group_h,
2314 __bt_mesh_model_subscription_op_cb, NULL);
2315 TC_PRT("return %s\n", __bt_get_error_message(ret));
2318 case BT_MESH_UNIT_TEST_FUNCTION_MODEL_CONFIGURE_VIRTUAL_GROUP_SUBSCRIPTION: {
2319 bt_mesh_model_h model_h = 0;
2320 bt_mesh_group_h group_h = 0;
2321 bt_mesh_model_subscription_op_e op = BT_MESH_MODEL_SUBSCRIPTION_ADD;
2323 if (g_test_param.param_count != 3) {
2324 TC_PRT("Set Input parameter first!");
2327 model_h = GUINT_TO_POINTER(strtoul(g_test_param.params[0], NULL, 16));
2328 op = atoi(g_test_param.params[1]);
2329 group_h = GUINT_TO_POINTER(strtoul(g_test_param.params[2], NULL, 16));
2331 ret = bt_mesh_model_configure_virtual_group_subscription(op, model_h, group_h,
2332 __bt_mesh_model_subscription_op_cb, NULL);
2333 TC_PRT("return %s\n", __bt_get_error_message(ret));
2336 case BT_MESH_UNIT_TEST_FUNCTION_MODEL_GET_SUBSCRIPTION_LIST: {
2337 bt_mesh_model_h model_h = 0;
2339 if (g_test_param.param_count != 1) {
2340 TC_PRT("Set Input parameter first!");
2343 model_h = GUINT_TO_POINTER(strtoul(g_test_param.params[0], NULL, 16));
2345 ret = bt_mesh_model_get_subscription_list(model_h, __bt_mesh_model_subscription_list_cb, NULL);
2346 TC_PRT("return %s\n", __bt_get_error_message(ret));
2349 case BT_MESH_UNIT_TEST_FUNCTION_MODEL_SET_PUBLICATION: {
2350 bt_mesh_model_h model_h = 0;
2351 bt_mesh_model_h appkey_h = 0;
2352 bt_mesh_group_h group_h = 0;
2353 bt_mesh_model_pub_params_s param;
2355 memset(¶m, 0x00, sizeof(bt_mesh_model_pub_params_s));
2357 if (g_test_param.param_count != 3) {
2358 TC_PRT("Set Input parameter first!");
2361 model_h = GUINT_TO_POINTER(strtoul(g_test_param.params[0], NULL, 16));
2362 appkey_h = GUINT_TO_POINTER(strtoul(g_test_param.params[1], NULL, 16));
2363 group_h = GUINT_TO_POINTER(strtoul(g_test_param.params[2], NULL, 16));
2366 param.num_steps = 10;
2367 param.per_res = BT_MESH_PUBLICATION_STEP_RES_1_SECOND;
2368 param.retrans_cnt = BT_MESH_MAX_PUBISH_RETRANSMIT_COUNT;
2369 param.retrans_step = BT_MESH_MAX_PUBISH_RETRANSMIT_INTERVAL_STEPS;
2371 ret = bt_mesh_model_set_publication(model_h, appkey_h, group_h, ¶m,
2372 __bt_mesh_model_publication_status_cb, NULL);
2373 TC_PRT("return %s\n", __bt_get_error_message(ret));
2376 case BT_MESH_UNIT_TEST_FUNCTION_MODEL_GET_PUBLICATION: {
2377 bt_mesh_model_h model_h = 0;
2379 if (g_test_param.param_count != 1) {
2380 TC_PRT("Set Input parameter first!");
2383 model_h = GUINT_TO_POINTER(strtoul(g_test_param.params[0], NULL, 16));
2385 ret = bt_mesh_model_get_publication(model_h, __bt_mesh_model_publication_status_cb, NULL);
2386 TC_PRT("return %s\n", __bt_get_error_message(ret));
2389 case BT_MESH_UNIT_TEST_FUNCTION_APPKEY_GET_NETKEY: {
2390 bt_mesh_appkey_h appkey_h = 0;
2391 bt_mesh_netkey_h netkey_h;
2393 if (g_test_param.param_count != 1) {
2394 TC_PRT("Set Input parameter first!");
2397 appkey_h = GUINT_TO_POINTER(strtoul(g_test_param.params[0], NULL, 16));
2399 ret = bt_mesh_appkey_get_netkey(appkey_h, &netkey_h);
2400 TC_PRT("return %s\n", __bt_get_error_message(ret));
2401 if (ret == BT_ERROR_NONE)
2402 print_netkey_handle(netkey_h);
2405 case BT_MESH_UNIT_TEST_FUNCTION_ACTIVATE_FLAG_TO_SET_PARAMETERS: {
2406 need_to_set_params = true;
2407 TC_PRT("Select the function again");
2413 __bt_free_test_param(&g_test_param);
2416 case BT_MESH_UNIT_TEST_TABLE_CONTROL: {
2418 case BT_MESH_UNIT_TEST_FUNCTION_MODEL_SEND_MSG: {
2419 bt_mesh_model_h model_h = NULL;
2420 bt_mesh_appkey_h appkey_h = NULL;
2421 bt_mesh_model_msg_params_s *msg_params = NULL;
2423 if (g_test_param.param_count != 4) {
2424 TC_PRT("Set Input parameter first!");
2428 /* Get input parameter */
2429 model_h = GUINT_TO_POINTER(strtoul(g_test_param.params[0], NULL, 16));
2430 appkey_h = GUINT_TO_POINTER(strtoul(g_test_param.params[1], NULL, 16));
2432 msg_params = g_malloc0(sizeof(bt_mesh_model_msg_params_s));
2433 msg_params->opcode = strtoul(g_test_param.params[2], NULL, 16);
2434 msg_params->data = "0101010101010101010101010100101010";
2435 msg_params->data = g_strdup(g_test_param.params[3]);
2437 TC_PRT("Input parameters");
2438 print_model_handle(model_h);
2439 print_appkey_handle(appkey_h);
2440 TC_PRT("opcode 0X%4.4X", msg_params->opcode);
2441 TC_PRT("Message to be sent %s", msg_params->data);
2443 ret = bt_mesh_model_send_msg(model_h, appkey_h, msg_params,
2444 __bt_mesh_model_msg_cb, NULL);
2445 TC_PRT("return %s\n", __bt_get_error_message(ret));
2449 case BT_MESH_UNIT_TEST_FUNCTION_GROUP_SEND_MSG: {
2450 bt_mesh_group_h group_h = NULL;
2451 bt_mesh_appkey_h appkey_h = NULL;
2452 bt_mesh_model_msg_params_s *msg_params = NULL;
2454 if (g_test_param.param_count != 4) {
2455 TC_PRT("Set Input parameter first!");
2459 /* Get input parameter */
2460 group_h = GUINT_TO_POINTER(strtoul(g_test_param.params[0], NULL, 16));
2461 appkey_h = GUINT_TO_POINTER(strtoul(g_test_param.params[1], NULL, 16));
2463 msg_params = g_malloc0(sizeof(bt_mesh_model_msg_params_s));
2464 msg_params->data = "0101010101010101010101010100101010";
2466 msg_params->opcode = strtoul(g_test_param.params[2], NULL, 16);
2467 msg_params->data = g_strdup(g_test_param.params[3]);
2469 TC_PRT("Input parameters");
2470 print_group_handle(group_h);
2471 print_appkey_handle(appkey_h);
2472 TC_PRT("opcode 0X%4.4X", msg_params->opcode);
2473 TC_PRT("Message to be sent %s", msg_params->data);
2475 ret = bt_mesh_group_send_msg(group_h, appkey_h, msg_params,
2476 __bt_mesh_model_msg_cb, NULL);
2477 TC_PRT("return %s\n", __bt_get_error_message(ret));
2481 case BT_MESH_UNIT_TEST_FUNCTION_ACTIVATE_FLAG_TO_SET_PARAMETERS: {
2482 need_to_set_params = true;
2483 TC_PRT("Select the function again");
2489 __bt_free_test_param(&g_test_param);
2492 case BT_MESH_UNIT_TEST_TABLE_SCENARIO:{
2494 case BT_MESH_UNIT_TEST_SCENARIO_NETWORK_CREATE: {
2495 bt_mesh_element_h element_sh;
2496 bt_mesh_model_h model_sh1, model_sh2, model_sh3, model_sh4;
2497 bt_mesh_model_id_s mod_id1, mod_id2, mod_id3, mod_id4;
2498 bt_mesh_appkey_h appkey_h = 0;
2499 bt_mesh_node_key_configuration_e config;
2500 char* network_name = "[Scenerio] Mesh Test Network";
2501 bt_mesh_node_features_s features;
2502 features.features = BT_MESH_FEATURE_RELAY;
2503 features.features |= BT_MESH_FEATURE_LOWPOWER;
2504 uint16_t group_addr = 0xc001;
2505 bt_mesh_group_h group_h;
2508 ret = bt_mesh_node_create(&features, &local_node);
2509 if (ret != BT_ERROR_NONE)
2510 TC_PRT("bt_mesh_node_create return %s\n", __bt_get_error_message(ret));
2512 /* create element */
2513 ret = bt_mesh_node_create_element(local_node, &element_sh);
2514 if (ret != BT_ERROR_NONE)
2515 TC_PRT("bt_mesh_node_create_element return %s\n", __bt_get_error_message(ret));
2518 /* Add configuration client and server */
2519 memset(&mod_id1, 0x00, sizeof(bt_mesh_model_id_s));
2520 mod_id1.model_id = BT_MESH_MODEL_ID_CFG_SRV;
2521 mod_id1.company_id = 0xFFFF;
2522 if (ret != BT_ERROR_NONE)
2523 TC_PRT("The model_id is [0x%2.2X]\n", mod_id1.model_id);
2524 ret = bt_mesh_element_create_model(element_sh, &mod_id1, &model_sh1);
2525 if (ret != BT_ERROR_NONE)
2526 TC_PRT("bt_mesh_element_create_model return %s\n", __bt_get_error_message(ret));
2528 memset(&mod_id2, 0x00, sizeof(bt_mesh_model_id_s));
2529 mod_id2.model_id = BT_MESH_MODEL_ID_CFG_CLIENT;
2530 mod_id2.company_id = 0xFFFF;
2531 ret = bt_mesh_element_create_model(element_sh, &mod_id2, &model_sh2);
2532 if (ret != BT_ERROR_NONE)
2533 TC_PRT("bt_mesh_element_create_model return %s\n", __bt_get_error_message(ret));
2535 /* Add Generic on-off client and server */
2536 memset(&mod_id3, 0x00, sizeof(bt_mesh_model_id_s));
2537 mod_id3.model_id = BT_MESH_MODEL_ID_GEN_ONOFF_SRV;
2538 mod_id3.company_id = 0xFFFF;
2539 ret = bt_mesh_element_create_model(element_sh, &mod_id3, &model_sh3);
2540 if (ret != BT_ERROR_NONE)
2541 TC_PRT("bt_mesh_element_create_model return %s\n", __bt_get_error_message(ret));
2543 memset(&mod_id4, 0x00, sizeof(bt_mesh_model_id_s));
2544 mod_id4.model_id = BT_MESH_MODEL_ID_GEN_ONOFF_CLIENT;
2545 mod_id4.company_id = 0xFFFF;
2546 ret = bt_mesh_element_create_model(element_sh, &mod_id4, &model_sh4);
2547 if (ret != BT_ERROR_NONE)
2548 TC_PRT("bt_mesh_element_create_model return %s\n", __bt_get_error_message(ret));
2550 /* create network */
2551 ret = bt_mesh_network_create(local_node, (const char*)network_name, &network, &token);
2552 if (ret != BT_ERROR_NONE)
2553 TC_PRT("bt_mesh_network_create return %s", __bt_get_error_message(ret));
2554 if (ret != BT_ERROR_NONE) break;
2557 ret = bt_mesh_network_create_group(network, group_addr, &group_h);
2558 if (ret != BT_ERROR_NONE) {
2559 TC_PRT("return %s\n", __bt_get_error_message(ret));
2561 print_group_handle(group_h);
2566 ret = bt_mesh_node_foreach_netkeys(local_node, __bt_mesh_node_foreach_netkeys_cb, NULL);
2567 if (ret != BT_ERROR_NONE)
2568 TC_PRT("return %s\n", __bt_get_error_message(ret));
2570 /* Add Appkey in netkey */
2571 ret = bt_mesh_netkey_add_appkey(g_netkey, &appkey_h);
2572 if (ret != BT_ERROR_NONE)
2573 TC_PRT("return %s\n", __bt_get_error_message(ret));
2574 g_appkey = appkey_h;
2576 /* Add appkey in local node */
2577 config = BT_MESH_NODE_KEY_ADD;
2578 ret = bt_mesh_node_configure_appkey(local_node, config, appkey_h,
2579 __bt_mesh_node_configure_appkey_cb, NULL);
2580 if (ret != BT_ERROR_NONE)
2581 TC_PRT("return %s\n", __bt_get_error_message(ret));
2584 /* Bind local models */
2585 ret = bt_mesh_model_bind_appkey(model_sh1, appkey_h, __bt_mesh_model_bind_cb, NULL);
2586 if (ret != BT_ERROR_NONE)
2587 TC_PRT("return %s\n", __bt_get_error_message(ret));
2589 ret = bt_mesh_model_bind_appkey(model_sh2, appkey_h, __bt_mesh_model_bind_cb, NULL);
2590 if (ret != BT_ERROR_NONE)
2591 TC_PRT("return %s\n", __bt_get_error_message(ret));
2593 ret = bt_mesh_model_bind_appkey(model_sh3, appkey_h, __bt_mesh_model_bind_cb, NULL);
2594 if (ret != BT_ERROR_NONE)
2595 TC_PRT("return %s\n", __bt_get_error_message(ret));
2597 ret = bt_mesh_model_bind_appkey(model_sh4, appkey_h, __bt_mesh_model_bind_cb, NULL);
2598 if (ret != BT_ERROR_NONE)
2599 TC_PRT("return %s\n", __bt_get_error_message(ret));
2603 case BT_MESH_UNIT_TEST_SCENARIO_UNPROVISIONED_SCAN: {
2604 unprov_dev_list = NULL;
2605 bt_mesh_scan_params_s scan_params;
2606 memset(&scan_params, 0x00, sizeof(bt_mesh_scan_params_s));
2607 scan_params.seconds = 20;
2609 /* Stop any ongoing scan */
2610 ret = bt_mesh_stop_unprovisioned_device_scan(network);
2611 if (ret == BT_ERROR_NONE)
2615 TC_PRT("The scan is set for [%u] seconds", scan_params.seconds);
2616 ret = bt_mesh_network_unprovisioned_device_scan(network, &scan_params,
2617 __bt_mesh_network_scan_unprovisioned_device_result_cb, NULL);
2618 if (ret != BT_ERROR_NONE)
2619 TC_PRT("return %s\n", __bt_get_error_message(ret));
2622 case BT_MESH_UNIT_TEST_SCENARIO_PROVISION_DEVICE: {
2623 const char *dev_uuid = "c2a6ff31ed00427d27a53698cca89029";
2625 if (g_test_param.param_count > 0)
2626 dev_uuid = g_test_param.params[0];
2628 g_device_uuid = g_strdup(dev_uuid);
2629 TC_PRT("The dev_uuid is [%s]\n", g_device_uuid);
2631 /* Stop any ongoing scan */
2632 ret = bt_mesh_stop_unprovisioned_device_scan(network);
2633 if (ret == BT_ERROR_NONE)
2636 /* Provision device */
2637 ret = bt_mesh_network_provision_device(network, g_device_uuid,
2638 __bt_mesh_network_device_provision_cb, NULL);
2639 if (ret != BT_ERROR_NONE)
2640 TC_PRT("return %s\n", __bt_get_error_message(ret));
2644 /* Try to discover provisioned device */
2645 if (ret == BT_ERROR_NONE) {
2646 call_success = false;
2648 while (!call_success && try < max_try) {
2650 ret = bt_mesh_network_discover_node(network, (const char*)g_device_uuid,
2651 __bt_mesh_node_discover_status_cb, NULL);
2652 if (ret != BT_ERROR_NONE)
2653 TC_PRT("return %s\n", __bt_get_error_message(ret));
2660 case BT_MESH_UNIT_TEST_SCENARIO_NODE_RESET: {
2661 bt_mesh_node_h node_h = g_node;
2662 if (g_test_param.param_count > 0)
2663 node_h = GUINT_TO_POINTER(strtoul(g_test_param.params[0], NULL, 16));
2665 ret = bt_mesh_node_reset(node_h);
2666 TC_PRT("return %s\n", __bt_get_error_message(ret));
2669 case BT_MESH_UNIT_TEST_SCENARIO_NODE_CONFIGURE_KEY: {
2670 bt_mesh_node_h node_h = g_node;
2671 bt_mesh_appkey_h appkey_h = g_appkey;
2672 bt_mesh_element_h element_h = g_element;
2673 bt_mesh_model_h model_h = g_model;
2674 bt_mesh_group_h group_h = g_group;
2675 bt_mesh_node_key_configuration_e config = BT_MESH_NODE_KEY_ADD;
2676 bt_mesh_model_subscription_op_e op = BT_MESH_MODEL_SUBSCRIPTION_ADD;
2678 if (g_test_param.param_count > 0)
2679 node_h = GUINT_TO_POINTER(strtoul(g_test_param.params[0], NULL, 16));
2681 /* Get remote node */
2682 ret = bt_mesh_node_foreach_element(node_h, __bt_mesh_node_foreach_elem_cb, NULL);
2683 if (ret != BT_ERROR_NONE)
2684 TC_PRT("return %s\n", __bt_get_error_message(ret));
2685 element_h = g_element;
2686 ret = bt_mesh_element_foreach_models(element_h, __bt_mesh_elem_foreach_model_cb, NULL);
2687 if (ret != BT_ERROR_NONE)
2688 TC_PRT("return %s\n", __bt_get_error_message(ret));
2690 /* Add appkey in remote node*/
2691 call_success = false;
2693 if (ret == BT_ERROR_NONE) {
2694 while (!call_success && try < max_try) {
2696 ret = bt_mesh_node_configure_appkey(node_h, config, appkey_h,
2697 __bt_mesh_node_configure_appkey_cb, NULL);
2698 if (ret != BT_ERROR_NONE)
2699 TC_PRT("return %s\n", __bt_get_error_message(ret));
2705 /* Bind appkey in on-off server*/
2706 call_success = false;
2708 model_h = g_model_onoff_srv;
2709 if (ret == BT_ERROR_NONE) {
2710 while (!call_success && try < max_try) {
2712 ret = bt_mesh_model_bind_appkey(model_h, appkey_h,
2713 __bt_mesh_model_bind_cb, NULL);
2714 if (ret != BT_ERROR_NONE)
2715 TC_PRT("return %s\n", __bt_get_error_message(ret));
2722 * Configure group subscription
2723 * Subscribe remote OnOff server model to Group with address c000
2726 call_success = false;
2728 model_h = g_model_onoff_srv;
2729 if (ret == BT_ERROR_NONE) {
2730 while (!call_success && try < max_try) {
2732 ret = bt_mesh_model_configure_group_subscription(op, model_h,
2733 group_h, __bt_mesh_model_subscription_op_cb, NULL);
2734 if (ret != BT_ERROR_NONE)
2735 TC_PRT("return %s\n", __bt_get_error_message(ret));
2743 case BT_MESH_UNIT_TEST_SCENARIO_MODEL_GENERIC_ONOFF_SET_ON: {
2744 bt_mesh_model_h model_h = g_model_onoff_srv;
2745 bt_mesh_appkey_h appkey_h = g_appkey;
2746 bt_mesh_model_msg_params_s msg_params;
2748 if (g_test_param.param_count > 0)
2749 model_h = GUINT_TO_POINTER(strtoul(g_test_param.params[0], NULL, 16));
2751 const char *msg_s = "01010000";
2752 msg_params.opcode = 0x8202;
2753 msg_params.data = g_strdup(msg_s);
2754 ret = __bt_mesh_model_send_msg(model_h, appkey_h, &msg_params,
2755 __bt_mesh_model_msg_cb, NULL);
2756 if (ret != BT_ERROR_NONE)
2757 TC_PRT("return %s\n", __bt_get_error_message(ret));
2760 case BT_MESH_UNIT_TEST_SCENARIO_MODEL_GENERIC_ONOFF_SET_OFF: {
2761 bt_mesh_model_h model_h = g_model_onoff_srv;
2762 bt_mesh_appkey_h appkey_h = g_appkey;
2763 bt_mesh_model_msg_params_s msg_params;
2765 if (g_test_param.param_count > 0)
2766 model_h = GUINT_TO_POINTER(strtoul(g_test_param.params[0], NULL, 16));
2768 const char *msg_s = "00010000";
2769 msg_params.opcode = 0x8202;
2770 msg_params.data = g_strdup(msg_s);
2771 ret = __bt_mesh_model_send_msg(model_h, appkey_h, &msg_params,
2772 __bt_mesh_model_msg_cb, NULL);
2773 if (ret != BT_ERROR_NONE)
2774 TC_PRT("return %s\n", __bt_get_error_message(ret));
2777 case BT_MESH_UNIT_TEST_SCENARIO_GROUP_GENERIC_ONOFF_SET_ON: {
2778 bt_mesh_model_h group_h = g_group;
2779 bt_mesh_appkey_h appkey_h = g_appkey;
2780 bt_mesh_model_msg_params_s msg_params;
2782 if (g_test_param.param_count > 0)
2783 group_h = GUINT_TO_POINTER(strtoul(g_test_param.params[0], NULL, 16));
2785 const char *msg_s = "01010000";
2786 msg_params.opcode = 0x8202;
2787 msg_params.data = g_strdup(msg_s);
2788 ret = __bt_mesh_group_send_msg(group_h, appkey_h, &msg_params,
2789 __bt_mesh_model_msg_cb, NULL);
2790 if (ret != BT_ERROR_NONE)
2791 TC_PRT("return %s\n", __bt_get_error_message(ret));
2794 case BT_MESH_UNIT_TEST_SCENARIO_GROUP_GENERIC_ONOFF_SET_OFF: {
2795 bt_mesh_model_h group_h = g_group;
2796 bt_mesh_appkey_h appkey_h = g_appkey;
2797 bt_mesh_model_msg_params_s msg_params;
2799 if (g_test_param.param_count > 0)
2800 group_h = GUINT_TO_POINTER(strtoul(g_test_param.params[0], NULL, 16));
2802 const char *msg_s = "00010000";
2803 msg_params.opcode = 0x8202;
2804 msg_params.data = g_strdup(msg_s);
2805 ret = __bt_mesh_group_send_msg(group_h, appkey_h, &msg_params,
2806 __bt_mesh_model_msg_cb, NULL);
2807 if (ret != BT_ERROR_NONE)
2808 TC_PRT("return %s\n", __bt_get_error_message(ret));
2811 case BT_MESH_UNIT_TEST_FUNCTION_ACTIVATE_FLAG_TO_SET_PARAMETERS: {
2812 need_to_set_params = true;
2813 TC_PRT("Select the function again");
2819 __bt_free_test_param(&g_test_param);
2829 static gboolean key_event_cb(GIOChannel *chan,
2833 char buf[BUFFER_LEN] = { 0 };
2836 unsigned long len = 0;
2838 unsigned int len = 0;
2841 bool is_call_api = false;
2843 memset(buf, 0, sizeof(buf));
2845 if (g_io_channel_read_chars(chan, buf, sizeof(buf),
2846 &len, NULL) == G_IO_STATUS_ERROR) {
2847 TC_PRT("IO Channel read error");
2851 if (need_to_set_params == true) {
2852 if (g_test_id == -1) {
2853 test_id = atoi(buf);
2854 g_test_id = test_id;
2856 test_set_params(g_test_id, buf);
2860 test_id = atoi(buf);
2863 need_to_set_params = false;
2866 if (current_tc_table == BT_MESH_UNIT_TEST_TABLE_MAIN) {
2868 current_tc_table = BT_MESH_UNIT_TEST_TABLE_MAIN;
2869 else if (test_id >= BT_MESH_UNIT_TEST_TABLE_NETWORK
2870 && test_id <= BT_MESH_UNIT_TEST_TABLE_SCENARIO) {
2871 current_tc_table = test_id;
2872 } else if (test_id > BT_MESH_UNIT_TEST_TABLE_CONTROL
2873 && test_id < BT_MESH_UNIT_TEST_TABLE_FINISH) {
2874 current_tc_table = BT_MESH_UNIT_TEST_TABLE_MAIN;
2881 if (buf[0] == '0' && buf[2] == 0)
2882 current_tc_table = BT_MESH_UNIT_TEST_TABLE_MAIN;
2888 if (test_id && is_call_api) {
2890 g_idle_add(test_input_callback, (void *)(uintptr_t)test_id);
2892 g_idle_add(test_input_callback, (void *)test_id);
2898 void sig_handler(int signo)
2900 if (signo == SIGINT) {
2901 bt_mesh_deinitialize();
2910 current_tc_table = BT_MESH_UNIT_TEST_TABLE_MAIN;
2912 key_io = g_io_channel_unix_new(fileno(stdin));
2914 g_io_channel_set_encoding(key_io, NULL, NULL);
2915 g_io_channel_set_flags(key_io, G_IO_FLAG_NONBLOCK, NULL);
2917 g_io_add_watch(key_io, G_IO_IN | G_IO_HUP | G_IO_ERR | G_IO_NVAL,
2918 key_event_cb, NULL);
2920 g_io_channel_unref(key_io);
2922 main_loop = g_main_loop_new(NULL, FALSE);
2924 if (signal(SIGINT, sig_handler) == SIG_ERR)
2925 TC_PRT("\n can't catch SIGINT\n");
2927 g_main_loop_run(main_loop);
2929 bt_mesh_deinitialize();