Mesh: Fix coding style issue
[platform/core/api/bluetooth.git] / tests / test / bt_mesh_unit_test.c
1 /*
2  * Copyright (c) 2020 Samsung Electronics Co., Ltd All Rights Reserved *
3  *
4  * @author: Anupam Roy <anupam.r@samsung.com>
5  * @author: Himanshu <h.himanshu@samsung.com>
6  *
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
10  *
11  * http://www.apache.org/licenses/LICENSE-2.0
12  *
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.
18  */
19
20 #include <stdio.h>
21 #include <string.h>
22 #include <fcntl.h>
23 #include <unistd.h>
24 #include <glib.h>
25 #include <ctype.h>
26 #ifdef ARCH64
27 #include <stdint.h>
28 #endif
29 #include <sys/types.h>
30
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"
36
37 static bt_mesh_unit_test_table_e current_tc_table;
38
39 static GSList *networks;
40
41 static bool need_to_set_params = false;
42 static int g_test_id = -1;
43 static tc_params_t g_test_param = {0,};
44
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;
56
57 static int try = 0;
58 static int max_try = 10;
59
60 static bt_mesh_netkey_h g_netkey;
61 static bt_mesh_appkey_h g_appkey;
62 static bt_mesh_group_h g_group;
63
64 static char *token;
65 static bt_mesh_authentication_type_e request_type = BT_MESH_AUTH_ALPHANUMERIC_DISPLAY;
66
67 GMainLoop *main_loop = NULL;
68 GMainLoop *mainloop = NULL;
69
70 static void wait_for_async_over()
71 {
72         if (mainloop)
73                 g_main_loop_quit(mainloop);
74 }
75
76 static void wait_for_async()
77 {
78         TC_PRT("Wait for operation...\n");
79         mainloop = g_main_loop_new(NULL, FALSE);
80         g_main_loop_run(mainloop);
81 }
82
83 tc_table_t tc_control[] = {
84         {"Back"
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},
92         {NULL                                           , 0X0000},
93 };
94
95 tc_table_t tc_configuration[] = {
96         {"Back"
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},
136         {NULL                                           , 0X0000},
137 };
138
139 tc_table_t tc_network[] = {
140         {"Back"
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},
230         {NULL                                           , 0X0000},
231 };
232
233 tc_table_t tc_scenario[] = {
234         {"Back"
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},
256         {NULL                                           , 0X0000},
257 };
258
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},
264         {"Network"
265                 , BT_MESH_UNIT_TEST_TABLE_NETWORK},
266         {"Configuration"
267                 , BT_MESH_UNIT_TEST_TABLE_CONFIGURATION},
268         {"Control"
269                 , BT_MESH_UNIT_TEST_TABLE_CONTROL},
270         {"Scenerio"
271                 , BT_MESH_UNIT_TEST_TABLE_SCENARIO},
272         {"Finish"
273                 , BT_MESH_UNIT_TEST_TABLE_FINISH},
274         {NULL                                           , 0x0000},
275 };
276
277 static void __bt_free_test_param(tc_params_t *param)
278 {
279         int i = 0;
280
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;
286 }
287
288 void tc_usage_print(void){
289         int i = 0;
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;
294                 break;
295         case BT_MESH_UNIT_TEST_TABLE_CONFIGURATION:
296                 tc_table = tc_configuration;
297                 break;
298         case BT_MESH_UNIT_TEST_TABLE_CONTROL:
299                 tc_table = tc_control;
300                 break;
301         case BT_MESH_UNIT_TEST_TABLE_SCENARIO:
302                 tc_table = tc_scenario;
303                 break;
304         default:
305                 tc_table = tc_main;
306                 break;
307         }
308         while (tc_table[i].tc_name) {
309                 TC_PRT("Key %d : usage %s", tc_table[i].tc_code, tc_table[i].tc_name);
310                 i++;
311         }
312 }
313
314 static const char *__bt_get_error_message(bt_error_e err)
315 {
316         const char *err_str = NULL;
317
318         switch (err) {
319         case BT_ERROR_NONE:
320                 err_str = "BT_ERROR_NONE";
321                 break;
322         case BT_ERROR_CANCELLED:
323                 err_str = "BT_ERROR_CANCELLED";
324                 break;
325         case BT_ERROR_INVALID_PARAMETER:
326                 err_str = "BT_ERROR_INVALID_PARAMETER";
327                 break;
328         case BT_ERROR_OUT_OF_MEMORY:
329                 err_str = "BT_ERROR_OUT_OF_MEMORY";
330                 break;
331         case BT_ERROR_RESOURCE_BUSY:
332                 err_str = "BT_ERROR_RESOURCE_BUSY";
333                 break;
334         case BT_ERROR_TIMED_OUT:
335                 err_str = "BT_ERROR_TIMED_OUT";
336                 break;
337         case BT_ERROR_NOW_IN_PROGRESS:
338                 err_str = "BT_ERROR_NOW_IN_PROGRESS";
339                 break;
340         case BT_ERROR_NOT_INITIALIZED:
341                 err_str = "BT_ERROR_NOT_INITIALIZED";
342                 break;
343         case BT_ERROR_NOT_ENABLED:
344                 err_str = "BT_ERROR_NOT_ENABLED";
345                 break;
346         case BT_ERROR_ALREADY_DONE:
347                 err_str = "BT_ERROR_ALREADY_DONE";
348                 break;
349         case BT_ERROR_OPERATION_FAILED:
350                 err_str = "BT_ERROR_OPERATION_FAILED";
351                 break;
352         case BT_ERROR_NOT_IN_PROGRESS:
353                 err_str = "BT_ERROR_NOT_IN_PROGRESS";
354                 break;
355         default:
356                 err_str = "NOT defined";
357                 break;
358                 }
359         return err_str;
360 }
361
362 void print_network_handle(bt_mesh_network_h network)
363 {
364         if (network == NULL)
365                 return;
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);
374 }
375
376 void print_node_handle(bt_mesh_node_h node)
377 {
378         if (node == NULL)
379                 return;
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);
388         }
389
390 }
391
392 void print_element_handle(bt_mesh_element_h element)
393 {
394         if (element == NULL)
395                 return;
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);
400 }
401
402 void print_model_handle(bt_mesh_model_h model)
403 {
404         if (model == NULL)
405                 return;
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);
411 }
412
413 void print_netkey_handle(bt_mesh_netkey_h netkey)
414 {
415         if (netkey == NULL)
416                 return;
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);
421 }
422
423 void print_appkey_handle(bt_mesh_appkey_h appkey)
424 {
425         if (appkey == NULL)
426                 return;
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);
431 }
432
433 void print_group_handle(bt_mesh_group_h group)
434 {
435         if (group == NULL)
436                 return;
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");
443 }
444
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)
447 {
448         TC_PRT("bt_mesh_network_device_info_cb");
449         TC_PRT("Total number of Devices in network [%d]", total);
450
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);
454         return true;
455 }
456
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)
459 {
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));
463
464         if (result == BT_ERROR_NONE) {
465                 print_group_handle(grp);
466                 return true;
467         } else
468                 return false;
469 }
470
471 void __bt_mesh_node_discover_status_cb(int result, bt_mesh_network_h network, bt_mesh_node_h node_param,
472                 void *user_data)
473 {
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) {
478                 g_node = node_param;
479                 call_success = true;
480         }
481         wait_for_async_over();
482 }
483
484 static gint __compare_model_handle(gconstpointer data, gconstpointer user_data)
485 {
486         if (NULL == data)
487                 return -1;
488         if (NULL == user_data)
489                 return -1;
490         if ((void*) data == (void*) user_data)
491                 return 0;
492         else
493                 return -1;
494 }
495
496
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)
499 {
500         TC_PRT("result: %s", __bt_get_error_message(result));
501         GSList *l;
502         if (result == BT_ERROR_NONE) {
503                 TC_PRT("Total number of Models in the element [%d]", total);
504                 print_element_handle(element);
505                 if (total) {
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);
513                                 if (!l)
514                                         srv_model_list = g_slist_append(srv_model_list, model);
515                         }
516                         g_model = model;
517                 }
518                 return true;
519         } else
520                 return false;
521 }
522
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)
525 {
526         TC_PRT("result: %s", __bt_get_error_message(result));
527
528         if (result == BT_ERROR_NONE) {
529                 TC_PRT("Total number of elements in the node [%d]", total);
530                 print_node_handle(node);
531                 if (total) {
532                         print_element_handle(element);
533                         TC_PRT("Element address [0x%2.2x]", element_addr);
534                         TC_PRT("Element index  [%d]", elem_index);
535                         g_element = element;
536                 }
537                 return true;
538         } else
539                 return false;
540 }
541
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)
544 {
545         TC_PRT("result: %s", __bt_get_error_message(result));
546
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!");
553                 else
554                         TC_PRT("NetKey Deleted!");
555                 print_netkey_handle(netkey);
556         }
557 }
558
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)
562 {
563         TC_PRT("result: %s", __bt_get_error_message(result));
564         if (result == BT_ERROR_NONE) {
565                 call_success = true;
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!");
571                 else
572                         TC_PRT("AppKey Deleted!");
573                 print_netkey_handle(netkey);
574                 print_appkey_handle(appkey);
575         }
576         wait_for_async_over();
577 }
578
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)
581 {
582         TC_PRT("result: %s", __bt_get_error_message(result));
583
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);
590
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");
599         }
600 }
601
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)
605 {
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);
610                 g_netkey = netkey;
611                 return true;
612         } else {
613                 TC_PRT("__bt_mesh_node_foreach_netkeys_cb result: %s", __bt_get_error_message(result));
614         }
615         return false;
616 }
617
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)
621 {
622         TC_PRT("result: %s", __bt_get_error_message(result));
623
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);
628                 return true;
629         }
630         return false;
631 }
632
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)
635 {
636         TC_PRT("result: %s", __bt_get_error_message(result));
637
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);
642         }
643 }
644
645 void __bt_mesh_model_bind_cb(int result, bt_mesh_model_h model, bt_mesh_appkey_h appkey,
646                 void *user_data)
647 {
648         TC_PRT("result: %s", __bt_get_error_message(result));
649         if (result == BT_ERROR_NONE) {
650                 call_success = true;
651                 print_model_handle(model);
652                 print_appkey_handle(appkey);
653         }
654         wait_for_async_over();
655 }
656
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)
659 {
660         TC_PRT("result: %s", __bt_get_error_message(result));
661         if (result == BT_ERROR_NONE) {
662                 call_success = true;
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);
667         }
668         wait_for_async_over();
669 }
670
671 void __bt_mesh_model_unbind_cb(int result, bt_mesh_model_h model, bt_mesh_appkey_h appkey,
672                 void *user_data)
673 {
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);
678         }
679 }
680
681 void __bt_mesh_model_appkey_list_cb(int result, bt_mesh_model_h model, int total,  const GSList *appkeylist,
682                 void *user_data)
683 {
684         const GSList *l;
685         TC_PRT("result: %s", __bt_get_error_message(result));
686
687         if (result == BT_ERROR_NONE) {
688                 TC_PRT("Total number of AppKeys bound to the model [%d]", total);
689                 print_model_handle(model);
690
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);
694                 }
695         }
696 }
697
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)
700 {
701         TC_PRT("result: %s", __bt_get_error_message(result));
702         if (result == BT_ERROR_NONE) {
703                 call_success = true;
704                 switch (op) {
705                 case 0:
706                         TC_PRT("Model Subscription Operation is ADD");
707                         break;
708                 case 1:
709                         TC_PRT("Model Subscription Operation is DELETE");
710                         break;
711                 case 2:
712                         TC_PRT("Model Subscription Operation is DELETE ALL");
713                         break;
714                 case 3:
715                         TC_PRT("Model Subscription Operation is OVERWRITE");
716                         break;
717                 default:
718                         TC_PRT("Invalid Model Subscription Operation");
719                         break;
720                 }
721                 print_model_handle(model);
722                 print_group_handle(group);
723         }
724         wait_for_async_over();
725 }
726
727 bool __bt_mesh_model_subscription_list_cb(int result, bt_mesh_model_h model, int total, const GSList *sub_addr,
728                 void *user_data)
729 {
730         const GSList *l;
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);
735
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);
739                 }
740         }
741         return true;
742 }
743
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)
746 {
747         TC_PRT("result: %s", __bt_get_error_message(result));
748
749         if (result == BT_ERROR_NONE) {
750                 print_model_handle(model);
751                 print_group_handle(group);
752                 print_appkey_handle(appkey);
753         }
754 }
755
756 void __bt_mesh_network_create_cb(int result, bt_mesh_network_h network, const char *network_name, void *user_data)
757 {
758         TC_PRT("result: %s", __bt_get_error_message(result));
759         print_network_handle(network);
760 }
761
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)
764 {
765         TC_PRT("result: %s", __bt_get_error_message(result));
766         print_appkey_handle(appkey);
767         TC_PRT("Total appkeys are [%d]", total);
768         return true;
769 }
770
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)
773 {
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");
782                 else
783                         TC_PRT("Primary NetKey deletion failed");
784         }
785         return true;
786 }
787
788 static gint __compare_dev_uuid(gconstpointer data, gconstpointer user_data)
789 {
790         const char *uuid1 = data;
791         const char *uuid2 = user_data;
792
793         if (NULL == uuid1)
794                 return -1;
795         if (NULL == uuid2)
796                 return -1;
797
798         return g_strcmp0(uuid1, uuid2);
799 }
800
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)
803 {
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();
812         } else {
813                 GSList *l;
814                 char *duuid = g_strdup(scan_res->uuid);
815                 l = g_slist_find_custom(unprov_dev_list, duuid, __compare_dev_uuid);
816                 if (!l) {
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);
821                 } else {
822                         g_free(duuid);
823                 }
824         }
825 }
826
827 void __bt_mesh_network_device_provision_cb(int result, bt_mesh_network_h network,
828                         const char* dev_uuid, void* user_data)
829 {
830         TC_PRT("result: %s", __bt_get_error_message(result));
831         if (dev_uuid == NULL)
832                 TC_PRT("Provisioned dev_uuid is NULL");
833         else {
834                 GSList *l;
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);
838                 if (!l)
839                         prov_dev_list = g_slist_append(prov_dev_list, duuid);
840         }
841         wait_for_async_over();
842 }
843
844 void __bt_mesh_authentication_request_cb(int result, bt_mesh_authentication_type_e auth_type,
845                 char *auth_value, void *user_data)
846 {
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;
851 }
852
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)
856 {
857         int ret = BT_ERROR_NONE;
858         call_success = false;
859         try = 0;
860
861         while (!call_success && try < max_try) {
862                 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));
867                 else
868                         wait_for_async();
869         }
870         return ret;
871 }
872
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)
876 {
877         int ret = BT_ERROR_NONE;
878         call_success = false;
879         try = 0;
880
881         while (!call_success && try < max_try) {
882                 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));
887                 else
888                         wait_for_async();
889         }
890         return ret;
891 }
892
893 int test_set_params(int test_id, char *param)
894 {
895         static int param_index = 0;
896         int param_count = 0;
897
898         if (param_index > 0 && param_index == g_test_param.param_count)
899                 goto done;
900         switch (current_tc_table) {
901         case BT_MESH_UNIT_TEST_TABLE_NETWORK: {
902                 switch (test_id) {
903                 case BT_MESH_UNIT_TEST_FUNCTION_NETWORK_CREATE:
904                         param_count = 2;
905                         switch (param_index) {
906                         case 0:
907                                 TC_PRT("Input param(%d) (network_name)\n", param_index + 1);
908                                 break;
909                         case 1:
910                                 TC_PRT("Input param(%d) (Node Handle)\n", param_index + 1);
911                                 break;
912                         }
913                         break;
914                 case BT_MESH_UNIT_TEST_FUNCTION_NETWORK_DESTROY:
915                         param_count = 1;
916                         TC_PRT("Input param(%d) (network_handle)\n", param_index + 1);
917                         break;
918                 case BT_MESH_UNIT_TEST_FUNCTION_NETWORK_CREATE_AND_DESTROY_IN_LOOP:
919                         param_count = 1;
920                         TC_PRT("Input param(%d) (Num networks to create & destroy)\n", param_index + 1);
921                         break;
922                 case BT_MESH_UNIT_TEST_FUNCTION_NETWORK_CREATE_IN_LOOP:
923                         param_count = 1;
924                         TC_PRT("Input param(%d) (Number of networks)\n", param_index + 1);
925                         break;
926                 case BT_MESH_UNIT_TEST_FUNCTION_NETWORK_INIT_AND_DEINIT_IN_LOOP:
927                         param_count = 1;
928                         TC_PRT("Input param(%d) (Number of networks)\n", param_index + 1);
929                         break;
930                 case BT_MESH_UNIT_TEST_FUNCTION_NODE_DESTROY:
931                         param_count = 1;
932                         TC_PRT("Input param(%d) (node Handle)\n", param_index + 1);
933                         break;
934                 case BT_MESH_UNIT_TEST_FUNCTION_NODE_GET_NETWORK:
935                         param_count = 1;
936                         TC_PRT("Input param(%d) (node Handle)\n", param_index + 1);
937                         break;
938                 case BT_MESH_UNIT_TEST_FUNCTION_NODE_CREATE_ELEMENT:
939                         param_count = 1;
940                         TC_PRT("Input param(%d) (node Handle)\n", param_index + 1);
941                         break;
942                 case BT_MESH_UNIT_TEST_FUNCTION_ELEMENT_CREATE_MODEL:
943                         param_count = 2;
944                         switch (param_index) {
945                         case 0:
946                                 TC_PRT("Input param(%d) (Element Handle)\n", param_index + 1);
947                                 break;
948                         case 1:
949                                 TC_PRT("Input param(%d) (Model ID)\n", param_index + 1);
950                                 break;
951                         }
952                         break;
953                 case BT_MESH_UNIT_TEST_FUNCTION_ELEMENT_GET_NODE:
954                         param_count = 1;
955                         TC_PRT("Input param(%d) (Element Handle)\n", param_index + 1);
956                         break;
957                 case BT_MESH_UNIT_TEST_FUNCTION_MODEL_GET_ID:
958                         param_count = 1;
959                         TC_PRT("Input param(%d) (Model Handle)\n", param_index + 1);
960                         break;
961                 case BT_MESH_UNIT_TEST_FUNCTION_MODEL_DESTROY:
962                         param_count = 1;
963                         TC_PRT("Input param(%d) (Model Handle)\n", param_index + 1);
964                         break;
965                 case BT_MESH_UNIT_TEST_FUNCTION_MODEL_GET_ELEMENT:
966                         param_count = 1;
967                         TC_PRT("Input param(%d) (Model Handle)\n", param_index + 1);
968                         break;
969                 case BT_MESH_UNIT_TEST_FUNCTION_ELEMENT_DESTROY:
970                         param_count = 1;
971                         TC_PRT("Input param(%d) (Element Handle)\n", param_index + 1);
972                         break;
973                 case BT_MESH_UNIT_TEST_FUNCTION_NODE_FOREACH_ELEMENTS:
974                         param_count = 1;
975                         TC_PRT("Input param(%d) (Node Handle)", param_index + 1);
976                         break;
977                 case BT_MESH_UNIT_TEST_FUNCTION_ELEMENT_FOREACH_MODELS:
978                         param_count = 1;
979                         TC_PRT("Input param(%d) (Element Handle)", param_index + 1);
980                         break;
981                 case BT_MESH_UNIT_TEST_FUNCTION_NETWORK_CREATE_GROUP:
982                         param_count = 1;
983                         TC_PRT("Input param(%d) (group address)\n", param_index + 1);
984                         break;
985                 case BT_MESH_UNIT_TEST_FUNCTION_NETWORK_REMOVE_GROUP:
986                         param_count = 1;
987                         TC_PRT("Input param(%d) (group handle)\n", param_index + 1);
988                         break;
989                 case BT_MESH_UNIT_TEST_FUNCTION_NETWORK_UNPROVISIONED_DEVICE_SCAN:
990                         param_count = 1;
991                         TC_PRT("Input param(%d) (Seconds)\n" , param_index + 1);
992                         break;
993                 case BT_MESH_UNIT_TEST_FUNCTION_NETWORK_PROVISION_DEVICE:
994                         param_count = 1;
995                         TC_PRT("Input param(%d) (device_uuid)\n", param_index+1);
996                         break;
997                 case BT_MESH_UNIT_TEST_FUNCTION_NETWORK_SET_NAME:
998                         param_count = 1;
999                         TC_PRT("Input param(%d) (network_name)", param_index + 1);
1000                         break;
1001                 case BT_MESH_UNIT_TEST_FUNCTION_NETWORK_LOAD:
1002                         param_count = 1;
1003                         TC_PRT("Input param(%d) (network Token)", param_index + 1);
1004                         break;
1005                 case BT_MESH_UNIT_TEST_FUNCTION_MESH_AUTHENTICATION_REPLY:
1006                         param_count = 2;
1007                         switch (param_index) {
1008                         case 0:
1009                                 TC_PRT("Input param(%d) (auth_value)\n", param_index +1);
1010                                 break;
1011                         case 1:
1012                                 TC_PRT("Input param(%d) (auth_reply)\n", param_index + 1);
1013                                 TC_PRT("0: false,  1: true");
1014                                 break;
1015                         }
1016                         break;
1017                 case BT_MESH_UNIT_TEST_FUNCTION_NETWORK_SET_PROVISIONING_CAPABILITIES:
1018                         param_count = 4;
1019                         switch (param_index) {
1020                         case 0:
1021                                 TC_PRT("\nInput param(%d) is_public_oob", param_index + 1);
1022                                 TC_PRT("0: false, 1: true\n");
1023                                 break;
1024                         case 1:
1025                                 TC_PRT("\nInput param(%d) is_static_oob", param_index + 1);
1026                                 TC_PRT("0: false, 1 : true\n");
1027                                 break;
1028                         case 2:
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");
1035                                 break;
1036                         case 3:
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");
1042                                 break;
1043                         }
1044                         break;
1045                 case BT_MESH_UNIT_TEST_FUNCTION_NETKEY_GET_INDEX:
1046                         param_count = 1;
1047                         TC_PRT("Input param(%d) (NetKey Handle)", param_index + 1);
1048                         break;
1049                 case BT_MESH_UNIT_TEST_FUNCTION_NETKEY_UPDATE:
1050                         param_count = 1;
1051                         TC_PRT("Input param(%d) (NetKey Handle)", param_index + 1);
1052                         break;
1053                 case BT_MESH_UNIT_TEST_FUNCTION_NETKEY_DELETE:
1054                         param_count = 1;
1055                         TC_PRT("Input param(%d) (NetKey Handle)", param_index + 1);
1056                         break;
1057                 case BT_MESH_UNIT_TEST_FUNCTION_NETKEY_ADD_APPKEY:
1058                         param_count = 1;
1059                         TC_PRT("Input param(%d) (NetKey Handle)", param_index + 1);
1060                         break;
1061                 case BT_MESH_UNIT_TEST_FUNCTION_NETKEY_FOREACH_APPKEYS:
1062                         param_count = 1;
1063                         TC_PRT("Input param(%d) (NetKey Handle)", param_index + 1);
1064                         break;
1065                 case BT_MESH_UNIT_TEST_FUNCTION_APPKEY_GET_INDEX:
1066                         param_count = 1;
1067                         TC_PRT("Input param(%d) (AppKey Handle)", param_index + 1);
1068                         break;
1069                 case BT_MESH_UNIT_TEST_FUNCTION_APPKEY_UPDATE:
1070                         param_count = 1;
1071                         TC_PRT("Input param(%d) (AppKey Handle)", param_index + 1);
1072                         break;
1073                 case BT_MESH_UNIT_TEST_FUNCTION_APPKEY_DELETE:
1074                         param_count = 1;
1075                         TC_PRT("Input param(%d) (AppKey Handle)", param_index + 1);
1076                         break;
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");
1080                         break;
1081                 default:
1082                         TC_PRT("There is no parameter to set\n");
1083                         break;
1084                 }
1085                 break;
1086         }
1087         case BT_MESH_UNIT_TEST_TABLE_SCENARIO: {
1088                 switch (test_id) {
1089                 case BT_MESH_UNIT_TEST_SCENARIO_PROVISION_DEVICE:
1090                         param_count = 1;
1091                         TC_PRT("Input param(%d) (device_uuid)\n", param_index+1);
1092                         break;
1093                 case BT_MESH_UNIT_TEST_SCENARIO_NODE_RESET:
1094                         param_count = 1;
1095                         TC_PRT("Input param(%d) (node handle)\n", param_index+1);
1096                         break;
1097                 case BT_MESH_UNIT_TEST_SCENARIO_NODE_CONFIGURE_KEY:
1098                         param_count = 1;
1099                         TC_PRT("Input param(%d) (node handle)\n", param_index+1);
1100                         break;
1101                 case BT_MESH_UNIT_TEST_SCENARIO_MODEL_GENERIC_ONOFF_SET_ON:
1102                         param_count = 1;
1103                         TC_PRT("Input param(%d) (model handle)\n", param_index+1);
1104                         break;
1105                 case BT_MESH_UNIT_TEST_SCENARIO_MODEL_GENERIC_ONOFF_SET_OFF:
1106                         param_count = 1;
1107                         TC_PRT("Input param(%d) (model handle)\n", param_index+1);
1108                         break;
1109                 case BT_MESH_UNIT_TEST_SCENARIO_GROUP_GENERIC_ONOFF_SET_ON:
1110                         param_count = 1;
1111                         TC_PRT("Input param(%d) (group handle)\n", param_index+1);
1112                         break;
1113                 case BT_MESH_UNIT_TEST_SCENARIO_GROUP_GENERIC_ONOFF_SET_OFF:
1114                         param_count = 1;
1115                         TC_PRT("Input param(%d) (group handle)\n", param_index+1);
1116                         break;
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");
1120                         break;
1121                 default:
1122                         TC_PRT("There is no parameter to set\n");
1123                         break;
1124                 }
1125                 break;
1126         }
1127         case BT_MESH_UNIT_TEST_TABLE_CONFIGURATION: {
1128                 switch (test_id) {
1129                 case BT_MESH_UNIT_TEST_FUNCTION_MESH_NETWORK_DISCOVER_NODE:
1130                         param_count = 1;
1131                         TC_PRT("Input param(%d) (device_uuid)", param_index + 1);
1132                         break;
1133                 case BT_MESH_UNIT_TEST_FUNCTION_NODE_RESET:
1134                         param_count = 1;
1135                         TC_PRT("Input param(%d) (Node Handle)", param_index + 1);
1136                         break;
1137                 case BT_MESH_UNIT_TEST_FUNCTION_NODE_GET_FEATURES:
1138                         param_count = 1;
1139                         TC_PRT("Input param(%d) (Node Handle)", param_index + 1);
1140                         break;
1141                 case BT_MESH_UNIT_TEST_FUNCTION_NODE_GET_NETKEYS:
1142                         param_count = 1;
1143                         TC_PRT("Input param(%d) (Node Handle)", param_index + 1);
1144                         break;
1145                 case BT_MESH_UNIT_TEST_FUNCTION_NODE_GET_APPKEYS:
1146                         param_count = 2;
1147                         switch (param_index) {
1148                         case 0:
1149                                 TC_PRT("Input param(%d) (Node Handle)", param_index + 1);
1150                                 break;
1151                         case 1:
1152                                 TC_PRT("Input param(%d) (Netkey Handle)\n", param_index + 1);
1153                                 break;
1154                         }
1155                         break;
1156                 case BT_MESH_UNIT_TEST_FUNCTION_APPKEY_GET_NETKEY:
1157                         param_count = 1;
1158                         TC_PRT("Input param(%d) (AppKey Handle)\n", param_index + 1);
1159                         break;
1160                 case BT_MESH_UNIT_TEST_FUNCTION_MODEL_GET_PUBLICATION:
1161                         param_count = 1;
1162                         TC_PRT("Input param(%d) (Model Handle)\n", param_index + 1);
1163                         break;
1164                 case BT_MESH_UNIT_TEST_FUNCTION_MODEL_SET_PUBLICATION:
1165                         param_count = 3;
1166                         switch (param_index) {
1167                         case 0:
1168                                 TC_PRT("\nInput param(%d) Model handle\n", param_index + 1);
1169                                 break;
1170                         case 1:
1171                                 TC_PRT("\nInput param(%d) AppKey handle\n", param_index + 1);
1172                                 break;
1173                         case 2:
1174                                 TC_PRT("\nInput param(%d) Group Handle\n", param_index + 1);
1175                                 break;
1176                         }
1177                         break;
1178                 case BT_MESH_UNIT_TEST_FUNCTION_MODEL_GET_SUBSCRIPTION_LIST:
1179                         param_count = 1;
1180                         TC_PRT("Input param(%d) (Model Handle)\n", param_index + 1);
1181                         break;
1182                 case BT_MESH_UNIT_TEST_FUNCTION_MODEL_CONFIGURE_GROUP_SUBSCRIPTION:
1183                 case BT_MESH_UNIT_TEST_FUNCTION_MODEL_CONFIGURE_VIRTUAL_GROUP_SUBSCRIPTION:
1184                         param_count = 3;
1185                         switch (param_index) {
1186                         case 0:
1187                                 TC_PRT("\nInput param(%d) Model handle\n", param_index + 1);
1188                                 break;
1189                         case 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");
1195                                 break;
1196                         case 2:
1197                                 TC_PRT("\nInput param(%d) Group Handle\n", param_index + 1);
1198                                 break;
1199                         }
1200                         break;
1201                 case BT_MESH_UNIT_TEST_FUNCTION_MODEL_GET_APPKEY_LIST:
1202                         param_count = 1;
1203                         TC_PRT("Input param(%d) (Model Handle)\n", param_index + 1);
1204                         break;
1205                 case BT_MESH_UNIT_TEST_FUNCTION_MODEL_BIND_APPKEY:
1206                 case BT_MESH_UNIT_TEST_FUNCTION_MODEL_UNBIND_APPKEY:
1207                         param_count = 2;
1208                         switch (param_index) {
1209                         case 0:
1210                                 TC_PRT("\nInput param(%d) Model Handle\n", param_index + 1);
1211                                 break;
1212                         case 1:
1213                                 TC_PRT("\nInput param(%d) AppKey handle\n", param_index + 1);
1214                                 break;
1215                         }
1216                         break;
1217                 case BT_MESH_UNIT_TEST_FUNCTION_NODE_CONFIGURE_NETKEY:
1218                 case BT_MESH_UNIT_TEST_FUNCTION_NODE_CONFIGURE_APPKEY:
1219                         param_count = 3;
1220                         switch (param_index) {
1221                         case 0:
1222                                 TC_PRT("\nInput param(%d) Node Handle\n", param_index + 1);
1223                                 break;
1224                         case 1:
1225                                 TC_PRT("\nInput param(%d) Key Handle\n", param_index + 1);
1226                                 break;
1227                         case 2:
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");
1232                                 break;
1233                         }
1234                         break;
1235                 case BT_MESH_UNIT_TEST_FUNCTION_NODE_GET_TTL:
1236                         param_count = 1;
1237                         TC_PRT("\nInput param(%d) Node Handle\n", param_index + 1);
1238                         break;
1239                 case BT_MESH_UNIT_TEST_FUNCTION_NODE_SET_TTL:
1240                         param_count = 2;
1241                         switch (param_index) {
1242                         case 0:
1243                                 TC_PRT("\nInput param(%d) Node Handle\n", param_index + 1);
1244                                 break;
1245                         case 1:
1246                                 TC_PRT("\nInput param(%d) TTL value\n", param_index + 1);
1247                                 break;
1248                         }
1249                         break;
1250                 default:
1251                         TC_PRT("There is no parameter to set\n");
1252                         break;
1253                 }
1254                 break;
1255         }
1256         case BT_MESH_UNIT_TEST_TABLE_CONTROL: {
1257                 switch (test_id) {
1258                 case BT_MESH_UNIT_TEST_FUNCTION_MODEL_SEND_MSG:
1259                         param_count = 4;
1260                         switch (param_index) {
1261                         case 0:
1262                                 TC_PRT("Input param(%d) (Model Handle)\n", param_index + 1);
1263                                 break;
1264                         case 1:
1265                                 TC_PRT("Input param(%d) (Appkey Handle)\n", param_index + 1);
1266                                 break;
1267                         case 2:
1268                                 TC_PRT("Input param(%d) (opcode)\n", param_index + 1);
1269                                 break;
1270                         case 3:
1271                                 TC_PRT("Input param(%d) (Message)\n", param_index + 1);
1272                                 break;
1273                         }
1274                         break;
1275                 case BT_MESH_UNIT_TEST_FUNCTION_GROUP_SEND_MSG:
1276                         param_count = 4;
1277                         switch (param_index) {
1278                         case 0:
1279                                 TC_PRT("Input param(%d) (Group Handle)\n", param_index + 1);
1280                                 break;
1281                         case 1:
1282                                 TC_PRT("Input param(%d) (Appkey Handle)\n", param_index + 1);
1283                                 break;
1284                         case 2:
1285                                 TC_PRT("Input param(%d) (opcode)\n", param_index + 1);
1286                                 break;
1287                         case 3:
1288                                 TC_PRT("Input param(%d) (Message)\n", param_index + 1);
1289                                 break;
1290                         }
1291                         break;
1292                 default:
1293                         TC_PRT("There is no parameter to set\n");
1294                         break;
1295                 }
1296                 break;
1297         }
1298         default:
1299                 TC_PRT("There is no parameter to set\n");
1300                 need_to_set_params = false;
1301                 break;
1302         }
1303
1304 done:
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);
1309                 }
1310
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);
1315                 }
1316
1317                 if (param_index  == g_test_param.param_count) {
1318                         need_to_set_params = false;
1319 #ifdef ARCH64
1320                         test_input_callback((void *)(uintptr_t)test_id);
1321 #else
1322                         test_input_callback((void *)test_id);
1323 #endif
1324                         param_index = 0;
1325                         return 0;
1326                 }
1327
1328                 param_index++;
1329         }
1330
1331         return 0;
1332 }
1333
1334 int test_input_callback(void *data)
1335 {
1336                 int ret = 0;
1337 #ifdef ARCH64
1338         int test_id = (uintptr_t)data;
1339 #else
1340         int test_id = (int)data;
1341 #endif
1342
1343         switch (current_tc_table) {
1344         case BT_MESH_UNIT_TEST_TABLE_MAIN: {
1345                 switch (test_id) {
1346                 case 0x00ff:
1347                         TC_PRT("Finished\n");
1348                         g_main_loop_quit(main_loop);
1349                         break;
1350                 case BT_MESH_UNIT_TEST_FUNCTION_INITIALIZE:
1351                         ret = bt_mesh_initialize();
1352                         TC_PRT("return %s\n", __bt_get_error_message(ret));
1353                         break;
1354                 case BT_MESH_UNIT_TEST_FUNCTION_DEINITIALIZE:
1355                         ret = bt_mesh_deinitialize();
1356                         TC_PRT("return %s\n", __bt_get_error_message(ret));
1357                         break;
1358                 default:
1359                         break;
1360                 }
1361                 break;
1362         }
1363         case BT_MESH_UNIT_TEST_TABLE_NETWORK:{
1364                 switch (test_id) {
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;
1373
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);
1378                         break;
1379                 }
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!");
1384                                 break;
1385                         }
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));
1389                         break;
1390                 }
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!");
1396                                 break;
1397                         }
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);
1403                         break;
1404                 }
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!");
1410                                 break;
1411                         }
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);
1417                         break;
1418                 }
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));
1424
1425                         if (g_test_param.param_count != 2) {
1426                                 TC_PRT("Enter parameters first!");
1427                                 break;
1428                         }
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);
1437                         break;
1438                 }
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!");
1444                                 break;
1445                         }
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));
1449
1450                         if (ret == BT_ERROR_NONE)
1451                                 print_node_handle(node_h);
1452                         break;
1453                 }
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!");
1460                                 break;
1461                         }
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);
1468                         }
1469                         break;
1470                 }
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!");
1475                                 break;
1476                         }
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));
1480                         break;
1481                 }
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!");
1487                                 break;
1488                         }
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);
1494                         break;
1495                 }
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!");
1500                                 break;
1501                         }
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));
1505                         break;
1506                 }
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");
1511                                 break;
1512                         }
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));
1516                         break;
1517                 }
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");
1522                                 break;
1523                         }
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));
1527                         break;
1528                 }
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");
1534                                 break;
1535                         }
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);
1543                         }
1544                         g_free(network_name);
1545                         break;
1546                 }
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!");
1551                                 break;
1552                         }
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));
1556                         break;
1557                 }
1558                 case BT_MESH_UNIT_TEST_FUNCTION_NETWORK_CREATE_IN_LOOP: {
1559                         char* network_name = "Mesh Test Network";
1560
1561                         if (g_test_param.param_count != 1) {
1562                                 TC_PRT("Enter Input parameter first.\n");
1563                                 break;
1564                         }
1565
1566                         int num = atoi(g_test_param.params[0]);
1567
1568                         if (num < 0 || num > INT_MAX) {
1569                                 TC_PRT("Input Number out of bounds \n");
1570                                 break;
1571                         }
1572
1573                         TC_PRT("Create [%d] Networks", num);
1574                         for (int i = 0; i < num; i++) {
1575
1576                                 /* Create Node */
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;
1587
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) {
1591                                 } else {
1592                                         TC_PRT("Node Creation Failed!");
1593                                         break;
1594                                 }
1595
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) {
1601                                 } else {
1602                                         TC_PRT("Element Creation Failed!");
1603                                         break;
1604                                 }
1605
1606                                 /* Create Model */
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));
1610
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) {
1616                                 } else {
1617                                         TC_PRT("Model Creation Failed!");
1618                                         break;
1619                                 }
1620
1621                                 /* Create Network */
1622                                 network_name = g_strdup_printf("TestMeshNet%d", i);
1623                                 bt_mesh_network_h net_h;
1624                                 char *token;
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);
1630                                 } else {
1631                                         TC_PRT("Network Creation Failed!");
1632                                         break;
1633                                 }
1634                                 g_free(network_name);
1635
1636                         }
1637                         break;
1638                 }
1639                 case BT_MESH_UNIT_TEST_FUNCTION_NETWORK_DESTROY_ALL_NETWORKS: {
1640                         bt_mesh_network_h net_h;
1641                         GSList *l;
1642                         TC_PRT("Mesh: Destroy ALL networks : total [%d]",
1643                                         g_slist_length(networks));
1644
1645                         /* Destroy Network */
1646                         for (l = networks; l != NULL;) {
1647                                 net_h = l->data;
1648                                 l = g_slist_next(l);
1649                                 networks = g_slist_remove(networks, net_h);
1650
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!");
1655                                 } else {
1656                                         TC_PRT("Network Destroy Failed!!....break out");
1657                                         break;
1658                                 }
1659                         }
1660                         break;
1661                 }
1662                 case BT_MESH_UNIT_TEST_FUNCTION_NETWORK_CREATE_AND_DESTROY_IN_LOOP: {
1663                         char* network_name = "Mesh Test Network";
1664
1665                         if (g_test_param.param_count != 1) {
1666                                 TC_PRT("Enter Input parameter first.\n");
1667                                 break;
1668                         }
1669                         int num = atoi(g_test_param.params[0]);
1670
1671                         if (num < 0 || num > INT_MAX) {
1672                                 TC_PRT("Input Number out of bounds \n");
1673                                 break;
1674                         }
1675
1676                         TC_PRT("Create [%d] Networks", num);
1677                         for (int i = 0; i < num; i++) {
1678
1679                                 /* Create Node */
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;
1684
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) {
1688                                 } else {
1689                                         TC_PRT("Node Creation Failed!");
1690                                         break;
1691                                 }
1692
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) {
1698                                 } else {
1699                                         TC_PRT("Element Creation Failed!");
1700                                         break;
1701                                 }
1702
1703                                 /* Create Model */
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));
1707
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) {
1713                                 } else {
1714                                         TC_PRT("Model Creation Failed!");
1715                                         break;
1716                                 }
1717                                 /* Create Network */
1718                                 network_name = g_strdup_printf("TestMeshNet%d", i);
1719                                 bt_mesh_network_h net_h;
1720                                 char *token;
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);
1725                                 } else {
1726                                         TC_PRT("Network Creation Failed!");
1727                                         break;
1728                                 }
1729                                 g_free(network_name);
1730
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!");
1736                                 } else {
1737                                         TC_PRT("Network Destroy Failed!!....break out");
1738                                         break;
1739                                 }
1740                         }
1741                         break;
1742                 }
1743                 case BT_MESH_UNIT_TEST_FUNCTION_NETWORK_INIT_AND_DEINIT_IN_LOOP: {
1744                         char* network_name = "Mesh Test Network";
1745
1746                         if (g_test_param.param_count != 1) {
1747                                 TC_PRT("Enter Input parameter first.\n");
1748                                 break;
1749                         }
1750                         int num = atoi(g_test_param.params[0]);
1751
1752                         if (num < 0 || num > INT_MAX) {
1753                                 TC_PRT("Input Number out of bounds \n");
1754                                 break;
1755                         }
1756
1757                         TC_PRT("Create [%d] Networks", num);
1758                         for (int i = 0; i < num; i++) {
1759
1760                                 /* Mesh Init */
1761                                 ret = bt_mesh_initialize();
1762                                 if (ret == BT_ERROR_NONE) {
1763                                         TC_PRT("Mesh init Passed!");
1764                                 } else {
1765                                         TC_PRT("Mesh init failed!");
1766                                         continue;
1767                                 }
1768
1769                                 /* Create Node */
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;
1774
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) {
1778                                 } else {
1779                                         TC_PRT("Node Creation Failed!");
1780                                         break;
1781                                 }
1782
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) {
1788                                 } else {
1789                                         TC_PRT("Element Creation Failed!");
1790                                         break;
1791                                 }
1792
1793                                 /* Create Model */
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));
1797
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) {
1803                                 } else {
1804                                         TC_PRT("Model Creation Failed!");
1805                                         break;
1806                                 }
1807
1808                                 /*
1809                                  * System-d has start-limit on number of process to be started in given time
1810                                  * Sleep for 2000 msec
1811                                  */
1812                                 usleep(2000);
1813
1814                                 /* Create Network */
1815                                 network_name = g_strdup_printf("TestMeshNet%d", i);
1816                                 bt_mesh_network_h net_h;
1817                                 char *token;
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);
1822                                 } else {
1823                                         TC_PRT("Network Creation Failed!");
1824                                         break;
1825                                 }
1826                                 g_free(network_name);
1827
1828                                 /* Mesh De-Init */
1829                                 ret = bt_mesh_deinitialize();
1830                                 if (ret == BT_ERROR_NONE)
1831                                         TC_PRT("Mesh De-init Passed!");
1832                                 else
1833                                         TC_PRT("Mesh De-init failed!");
1834                         }
1835                         break;
1836                 }
1837                 case BT_MESH_UNIT_TEST_FUNCTION_NETWORK_LOAD: {
1838                         char *token_str;
1839                         if (g_test_param.param_count != 1) {
1840                                 TC_PRT("Enter parameter first!");
1841                                 break;
1842                         }
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);
1848                         g_free(token_str);
1849                         break;
1850                 }
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!");
1855                                 break;
1856                         }
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);
1861                         break;
1862                 }
1863                 case BT_MESH_UNIT_TEST_FUNCTION_NETWORK_GET_NAME: {
1864                         char* network_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);
1869                         break;
1870                 }
1871                 case BT_MESH_UNIT_TEST_FUNCTION_NETWORK_ADD_NETKEY: {
1872                         /* netkey 1*/
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);
1878                         break;
1879                 }
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));
1884                         break;
1885                 }
1886                 case BT_MESH_UNIT_TEST_FUNCTION_NETKEY_GET_INDEX: {
1887                         uint16_t index = 0xFFFF;
1888                         bt_mesh_netkey_h netkey_h;
1889
1890                         if (g_test_param.param_count != 1) {
1891                                 TC_PRT("Set parameter first!");
1892                                 break;
1893                         }
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);
1900
1901                         break;
1902                 }
1903                 case BT_MESH_UNIT_TEST_FUNCTION_NETKEY_UPDATE: {
1904                         bt_mesh_netkey_h netkey_h;
1905
1906                         if (g_test_param.param_count != 1) {
1907                                 TC_PRT("Set parameter first!");
1908                                 break;
1909                         }
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));
1913                         break;
1914                 }
1915                 case BT_MESH_UNIT_TEST_FUNCTION_NETKEY_DELETE: {
1916                         bt_mesh_netkey_h netkey_h;
1917
1918                         if (g_test_param.param_count != 1) {
1919                                 TC_PRT("Set parameter first!");
1920                                 break;
1921                         }
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");
1927                         break;
1928                 }
1929                 case BT_MESH_UNIT_TEST_FUNCTION_NETKEY_ADD_APPKEY: {
1930                         bt_mesh_netkey_h netkey_h;
1931                         bt_mesh_appkey_h appkey_h;
1932
1933                         if (g_test_param.param_count != 1) {
1934                                 TC_PRT("Set parameter first!");
1935                                 break;
1936                         }
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);
1942                         break;
1943                 }
1944                 case BT_MESH_UNIT_TEST_FUNCTION_NETKEY_FOREACH_APPKEYS: {
1945                         /* Get all appkeys for NetKey 1 */
1946                         bt_mesh_netkey_h netkey_h;
1947
1948                         if (g_test_param.param_count != 1) {
1949                                 TC_PRT("Set parameter first!");
1950                                 break;
1951                         }
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));
1955
1956                         break;
1957                 }
1958                 case BT_MESH_UNIT_TEST_FUNCTION_APPKEY_GET_INDEX: {
1959                         uint16_t index = 0xFFFF;
1960                         bt_mesh_appkey_h appkey_h;
1961
1962                         if (g_test_param.param_count != 1) {
1963                                 TC_PRT("Set parameter first!");
1964                                 break;
1965                         }
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);
1972                         break;
1973                 }
1974                 case BT_MESH_UNIT_TEST_FUNCTION_APPKEY_UPDATE: {
1975                         bt_mesh_appkey_h appkey_h;
1976
1977                         if (g_test_param.param_count != 1) {
1978                                 TC_PRT("Set parameter first!");
1979                                 break;
1980                         }
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));
1984                         break;
1985                 }
1986                 case BT_MESH_UNIT_TEST_FUNCTION_APPKEY_DELETE: {
1987                         bt_mesh_appkey_h appkey_h;
1988
1989                         if (g_test_param.param_count != 1) {
1990                                 TC_PRT("Set parameter first!");
1991                                 break;
1992                         }
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");
1998                         break;
1999                 }
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));
2003                         break;
2004                 }
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");
2010                                 break;
2011                         }
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);
2018                         break;
2019                 }
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);
2026                         break;
2027                 }
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");
2032                                 break;
2033                         }
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));
2037                         break;
2038                 }
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));
2043                         break;
2044                 }
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");
2051                                 break;
2052                         }
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));
2058                         break;
2059                 }
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");
2065                         break;
2066                 }
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");
2071                                 break;
2072                         }
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));
2078                         break;
2079                 }
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));
2084                         break;
2085                 }
2086                 case  BT_MESH_UNIT_TEST_FUNCTION_MESH_AUTHENTICATION_REPLY: {
2087                         char* value;
2088                         int len;
2089                         bool auth_reply;
2090                         if (g_test_param.param_count != 2) {
2091                                 TC_PRT("Enter Input parameter first.\n");
2092                                 break;
2093                         }
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));
2103                         break;
2104                 }
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.");
2109                                 break;
2110                         }
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));
2121                         break;
2122                 }
2123                 case BT_MESH_UNIT_TEST_FUNCTION_NETWORK_GET_PROVISIONING_CAPABILITIES: {
2124                         // TODO: need to implement
2125                         break;
2126                 }
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");
2130                         break;
2131                 }
2132                 default:
2133                         break;
2134                 }
2135                         __bt_free_test_param(&g_test_param);
2136                 break;
2137         }
2138         case BT_MESH_UNIT_TEST_TABLE_CONFIGURATION: {
2139                 switch (test_id) {
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]);
2144                         } else {
2145                                 TC_PRT("Set Input parameter first!");
2146                                 break;
2147                         }
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));
2151                         break;
2152                 }
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!");
2157                                 break;
2158                         }
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));
2162                         break;
2163                 }
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!");
2168                                 break;
2169                         }
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));
2173                         break;
2174                 }
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!");
2179                                 break;
2180                         }
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));
2184                         break;
2185                 }
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!");
2191                                 break;
2192                         }
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));
2195
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));
2199                         break;
2200                 }
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!");
2205                                 break;
2206                         }
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));
2210                         break;
2211                 }
2212                 case BT_MESH_UNIT_TEST_FUNCTION_NODE_SET_TTL: {
2213                         bt_mesh_node_h node_h = 0;
2214                         int ttl = 120;
2215                         if (g_test_param.param_count != 2) {
2216                                 TC_PRT("Set Input parameter first!");
2217                                 break;
2218                         }
2219                         node_h = GUINT_TO_POINTER(strtoul(g_test_param.params[0], NULL, 16));
2220                         ttl = atoi(g_test_param.params[1]);
2221
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));
2224                         break;
2225                 }
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!");
2232                                 break;
2233                         }
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]);
2237
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));
2241                         break;
2242                 }
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!");
2249                                 break;
2250                         }
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]);
2254
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));
2258                         break;
2259                 }
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!");
2265                                 break;
2266                         }
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));
2269
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));
2272                         break;
2273                 }
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!");
2279                                 break;
2280                         }
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));
2283
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));
2286                         break;
2287                 }
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!");
2292                                 break;
2293                         }
2294                         model_h = GUINT_TO_POINTER(strtoul(g_test_param.params[0], NULL, 16));
2295
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));
2298                         break;
2299                 }
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;
2304
2305                         if (g_test_param.param_count != 3) {
2306                                 TC_PRT("Set Input parameter first!");
2307                                 break;
2308                         }
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));
2312
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));
2316                         break;
2317                 }
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;
2322
2323                         if (g_test_param.param_count != 3) {
2324                                 TC_PRT("Set Input parameter first!");
2325                                 break;
2326                         }
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));
2330
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));
2334                         break;
2335                 }
2336                 case BT_MESH_UNIT_TEST_FUNCTION_MODEL_GET_SUBSCRIPTION_LIST: {
2337                         bt_mesh_model_h model_h = 0;
2338
2339                         if (g_test_param.param_count != 1) {
2340                                 TC_PRT("Set Input parameter first!");
2341                                 break;
2342                         }
2343                         model_h = GUINT_TO_POINTER(strtoul(g_test_param.params[0], NULL, 16));
2344
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));
2347                         break;
2348                 }
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;
2354
2355                         memset(&param, 0x00, sizeof(bt_mesh_model_pub_params_s));
2356
2357                         if (g_test_param.param_count != 3) {
2358                                 TC_PRT("Set Input parameter first!");
2359                                 break;
2360                         }
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));
2364
2365                         param.ttl = 120;
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;
2370
2371                         ret = bt_mesh_model_set_publication(model_h, appkey_h, group_h, &param,
2372                                                         __bt_mesh_model_publication_status_cb, NULL);
2373                         TC_PRT("return %s\n", __bt_get_error_message(ret));
2374                         break;
2375                 }
2376                 case BT_MESH_UNIT_TEST_FUNCTION_MODEL_GET_PUBLICATION: {
2377                         bt_mesh_model_h model_h = 0;
2378
2379                         if (g_test_param.param_count != 1) {
2380                                 TC_PRT("Set Input parameter first!");
2381                                 break;
2382                         }
2383                         model_h = GUINT_TO_POINTER(strtoul(g_test_param.params[0], NULL, 16));
2384
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));
2387                         break;
2388                 }
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;
2392
2393                         if (g_test_param.param_count != 1) {
2394                                 TC_PRT("Set Input parameter first!");
2395                                 break;
2396                         }
2397                         appkey_h = GUINT_TO_POINTER(strtoul(g_test_param.params[0], NULL, 16));
2398
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);
2403                         break;
2404                 }
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");
2408                         break;
2409                 }
2410                 default:
2411                         break;
2412                 }
2413                         __bt_free_test_param(&g_test_param);
2414                 break;
2415         }
2416         case BT_MESH_UNIT_TEST_TABLE_CONTROL: {
2417                 switch (test_id) {
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;
2422
2423                         if (g_test_param.param_count != 4) {
2424                                 TC_PRT("Set Input parameter first!");
2425                                 break;
2426                         }
2427
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));
2431
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]);
2436
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);
2442
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));
2446
2447                         break;
2448                 }
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;
2453
2454                         if (g_test_param.param_count != 4) {
2455                                 TC_PRT("Set Input parameter first!");
2456                                 break;
2457                         }
2458
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));
2462
2463                         msg_params = g_malloc0(sizeof(bt_mesh_model_msg_params_s));
2464                         msg_params->data = "0101010101010101010101010100101010";
2465
2466                         msg_params->opcode = strtoul(g_test_param.params[2], NULL, 16);
2467                         msg_params->data = g_strdup(g_test_param.params[3]);
2468
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);
2474
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));
2478
2479                         break;
2480                 }
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");
2484                         break;
2485                 }
2486                 default:
2487                         break;
2488                 }
2489                         __bt_free_test_param(&g_test_param);
2490                 break;
2491         }
2492         case BT_MESH_UNIT_TEST_TABLE_SCENARIO:{
2493                 switch (test_id) {
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;
2506
2507                         /* create node */
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));
2511
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));
2516
2517                         /* create models */
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));
2527
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));
2534
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));
2542
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));
2549
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;
2555
2556                         /* Create Group */
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));
2560                         } else {
2561                                 print_group_handle(group_h);
2562                                 g_group = group_h;
2563                         }
2564
2565                         /* Get net keys */
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));
2569
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;
2575
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));
2582                         wait_for_async();
2583
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));
2588                         wait_for_async();
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));
2592                         wait_for_async();
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));
2596                         wait_for_async();
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));
2600
2601                                 break;
2602                 }
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;
2608
2609                         /* Stop any ongoing scan */
2610                         ret = bt_mesh_stop_unprovisioned_device_scan(network);
2611                         if (ret == BT_ERROR_NONE)
2612                                 wait_for_async();
2613
2614                         /* Start scan */
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));
2620                         break;
2621                 }
2622                 case BT_MESH_UNIT_TEST_SCENARIO_PROVISION_DEVICE: {
2623                         const char *dev_uuid = "c2a6ff31ed00427d27a53698cca89029";
2624
2625                         if (g_test_param.param_count > 0)
2626                                 dev_uuid = g_test_param.params[0];
2627
2628                         g_device_uuid = g_strdup(dev_uuid);
2629                         TC_PRT("The dev_uuid is [%s]\n", g_device_uuid);
2630
2631                         /* Stop any ongoing scan */
2632                         ret = bt_mesh_stop_unprovisioned_device_scan(network);
2633                         if (ret == BT_ERROR_NONE)
2634                                 wait_for_async();
2635
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));
2641                         else
2642                                 wait_for_async();
2643
2644                         /* Try to discover provisioned device */
2645                         if (ret == BT_ERROR_NONE) {
2646                                 call_success = false;
2647                                 try = 0;
2648                                 while (!call_success && try < max_try) {
2649                                         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));
2654                                         else
2655                                                 wait_for_async();
2656                                 }
2657                         }
2658                         break;
2659                 }
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));
2664
2665                         ret = bt_mesh_node_reset(node_h);
2666                         TC_PRT("return %s\n", __bt_get_error_message(ret));
2667                         break;
2668                 }
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;
2677
2678                         if (g_test_param.param_count > 0)
2679                                 node_h = GUINT_TO_POINTER(strtoul(g_test_param.params[0], NULL, 16));
2680
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));
2689
2690                         /* Add appkey in remote node*/
2691                         call_success = false;
2692                         try = 0;
2693                         if (ret == BT_ERROR_NONE) {
2694                                 while (!call_success && try < max_try) {
2695                                         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));
2700                                         else
2701                                                 wait_for_async();
2702                                 }
2703                         }
2704
2705                         /* Bind appkey in on-off server*/
2706                         call_success = false;
2707                         try = 0;
2708                         model_h = g_model_onoff_srv;
2709                         if (ret == BT_ERROR_NONE) {
2710                                 while (!call_success && try < max_try) {
2711                                         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));
2716                                         else
2717                                                 wait_for_async();
2718                                 }
2719                         }
2720
2721                         /*
2722                          * Configure group subscription
2723                          * Subscribe remote OnOff server model to Group with address c000
2724                          */
2725                         group_h = g_group;
2726                         call_success = false;
2727                         try = 0;
2728                         model_h = g_model_onoff_srv;
2729                         if (ret == BT_ERROR_NONE) {
2730                                 while (!call_success && try < max_try) {
2731                                         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));
2736                                         else
2737                                                 wait_for_async();
2738                                 }
2739                         }
2740
2741                         break;
2742                 }
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;
2747
2748                         if (g_test_param.param_count > 0)
2749                                 model_h = GUINT_TO_POINTER(strtoul(g_test_param.params[0], NULL, 16));
2750
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));
2758                         break;
2759                 }
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;
2764
2765                         if (g_test_param.param_count > 0)
2766                                 model_h = GUINT_TO_POINTER(strtoul(g_test_param.params[0], NULL, 16));
2767
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));
2775                         break;
2776                 }
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;
2781
2782                         if (g_test_param.param_count > 0)
2783                                 group_h = GUINT_TO_POINTER(strtoul(g_test_param.params[0], NULL, 16));
2784
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));
2792                         break;
2793                 }
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;
2798
2799                         if (g_test_param.param_count > 0)
2800                                 group_h = GUINT_TO_POINTER(strtoul(g_test_param.params[0], NULL, 16));
2801
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));
2809                         break;
2810                 }
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");
2814                         break;
2815                 }
2816                 default:
2817                         break;
2818                 }
2819                         __bt_free_test_param(&g_test_param);
2820                 break;
2821         }
2822         default:
2823                 break;
2824         }
2825         return 0;
2826 }
2827
2828
2829 static gboolean key_event_cb(GIOChannel *chan,
2830                 GIOCondition cond,
2831                 gpointer data)
2832 {
2833         char buf[BUFFER_LEN] = { 0 };
2834
2835 #ifdef ARCH64
2836         unsigned long len = 0;
2837 #else
2838         unsigned int len = 0;
2839 #endif
2840         int test_id;
2841         bool is_call_api = false;
2842
2843         memset(buf, 0, sizeof(buf));
2844
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");
2848                 return FALSE;
2849         }
2850
2851         if (need_to_set_params == true) {
2852                 if (g_test_id == -1) {
2853                         test_id = atoi(buf);
2854                         g_test_id = test_id;
2855                 }
2856                 test_set_params(g_test_id, buf);
2857                 return TRUE;
2858         } else {
2859                 TC_PRT("%s", buf);
2860                 test_id = atoi(buf);
2861
2862                 g_test_id = -1;
2863                 need_to_set_params = false;
2864         }
2865
2866         if (current_tc_table == BT_MESH_UNIT_TEST_TABLE_MAIN) {
2867                 if (test_id == 0)
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;
2875                 } else {
2876                         is_call_api = true;
2877                 }
2878         }
2879
2880         else {
2881                 if (buf[0] == '0' && buf[2] == 0)
2882                         current_tc_table = BT_MESH_UNIT_TEST_TABLE_MAIN;
2883                 else
2884                         is_call_api = true;
2885         }
2886
2887         tc_usage_print();
2888         if (test_id && is_call_api) {
2889 #ifdef ARCH64
2890                 g_idle_add(test_input_callback, (void *)(uintptr_t)test_id);
2891 #else
2892                 g_idle_add(test_input_callback, (void *)test_id);
2893 #endif
2894         }
2895         return TRUE;
2896 }
2897
2898 void sig_handler(int signo)
2899 {
2900         if (signo == SIGINT) {
2901                 bt_mesh_deinitialize();
2902                 exit(0);
2903         }
2904 }
2905
2906 int main()
2907 {
2908         GIOChannel *key_io;
2909
2910         current_tc_table = BT_MESH_UNIT_TEST_TABLE_MAIN;
2911
2912         key_io = g_io_channel_unix_new(fileno(stdin));
2913
2914         g_io_channel_set_encoding(key_io, NULL, NULL);
2915         g_io_channel_set_flags(key_io, G_IO_FLAG_NONBLOCK, NULL);
2916
2917         g_io_add_watch(key_io, G_IO_IN | G_IO_HUP | G_IO_ERR | G_IO_NVAL,
2918                         key_event_cb, NULL);
2919
2920         g_io_channel_unref(key_io);
2921
2922         main_loop = g_main_loop_new(NULL, FALSE);
2923
2924         if (signal(SIGINT, sig_handler) == SIG_ERR)
2925                 TC_PRT("\n can't catch SIGINT\n");
2926
2927         g_main_loop_run(main_loop);
2928
2929         bt_mesh_deinitialize();
2930
2931         return 0;
2932 }