Mesh: Add cases in unit test
[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 bool need_to_set_params = false;
40 static int g_test_id = -1;
41 static tc_params_t g_test_param = {0,};
42
43 static bt_mesh_node_h local_node = NULL;
44 static bt_mesh_node_h g_node;
45 static bt_mesh_network_h network;
46 static char *device_uuid;
47
48 static char *token;
49 static bt_mesh_authentication_type_e request_type = BT_MESH_AUTH_ALPHANUMERIC_DISPLAY;
50
51 GMainLoop *main_loop = NULL;
52
53 tc_table_t tc_configuration[] = {
54         {"Back"
55                 , BT_MESH_UNIT_TEST_FUNCTION_BACK},
56         {"bt_mesh_network_discover_node"
57                 , BT_MESH_UNIT_TEST_FUNCTION_MESH_NETWORK_DISCOVER_NODE},
58         {"bt_mesh_node_reset"
59                 , BT_MESH_UNIT_TEST_FUNCTION_NODE_RESET},
60         {"bt_mesh_node_get_features"
61                 , BT_MESH_UNIT_TEST_FUNCTION_NODE_GET_FEATURES},
62         {"bt_mesh_node_foreach_netkeys"
63                 , BT_MESH_UNIT_TEST_FUNCTION_NODE_GET_NETKEYS},
64         {"bt_mesh_node_foreach_appkeys"
65                 , BT_MESH_UNIT_TEST_FUNCTION_NODE_GET_APPKEYS},
66         {"bt_mesh_node_get_ttl"
67                 , BT_MESH_UNIT_TEST_FUNCTION_NODE_GET_TTL},
68         {"bt_mesh_node_set_ttl"
69                 , BT_MESH_UNIT_TEST_FUNCTION_NODE_SET_TTL},
70         {"bt_mesh_node_configure_netkey"
71                 , BT_MESH_UNIT_TEST_FUNCTION_NODE_CONFIGURE_NETKEY},
72         {"bt_mesh_node_configure_appkey"
73                 , BT_MESH_UNIT_TEST_FUNCTION_NODE_CONFIGURE_APPKEY},
74         {"bt_mesh_model_bind_appkey"
75                 , BT_MESH_UNIT_TEST_FUNCTION_MODEL_BIND_APPKEY},
76         {"bt_mesh_model_unbind_appkey"
77                 , BT_MESH_UNIT_TEST_FUNCTION_MODEL_UNBIND_APPKEY},
78         {"bt_mesh_model_get_appkey_list"
79                 , BT_MESH_UNIT_TEST_FUNCTION_MODEL_GET_APPKEY_LIST},
80         {"bt_mesh_model_configure_group_subscription"
81                 , BT_MESH_UNIT_TEST_FUNCTION_MODEL_CONFIGURE_GROUP_SUBSCRIPTION},
82         {"bt_mesh_model_configure_virtual_group_subscription"
83                 , BT_MESH_UNIT_TEST_FUNCTION_MODEL_CONFIGURE_VIRTUAL_GROUP_SUBSCRIPTION},
84         {"bt_mesh_model_get_subscription_list"
85                 , BT_MESH_UNIT_TEST_FUNCTION_MODEL_GET_SUBSCRIPTION_LIST},
86         {"bt_mesh_model_set_publication"
87                 , BT_MESH_UNIT_TEST_FUNCTION_MODEL_SET_PUBLICATION},
88         {"bt_mesh_model_get_publication"
89                 , BT_MESH_UNIT_TEST_FUNCTION_MODEL_GET_PUBLICATION},
90         {"bt_mesh_model_send_msg"
91                 , BT_MESH_UNIT_TEST_FUNCTION_MODEL_SEND_MSG},
92         {"bt_mesh_appkey_get_netkey"
93                 , BT_MESH_UNIT_TEST_FUNCTION_APPKEY_GET_NETKEY},
94         {"select this menu to set parameters and then select the function again"
95                 , BT_MESH_UNIT_TEST_FUNCTION_ACTIVATE_FLAG_TO_SET_PARAMETERS},
96         {NULL                                           , 0X0000},
97 };
98
99 tc_table_t tc_network[] = {
100         {"Back"
101                 , BT_MESH_UNIT_TEST_FUNCTION_BACK},
102         {"bt_mesh_node_create"
103                 , BT_MESH_UNIT_TEST_FUNCTION_NODE_CREATE},
104         {"bt_mesh_node_destroy"
105                 , BT_MESH_UNIT_TEST_FUNCTION_NODE_DESTROY},
106         {"bt_mesh_node_create_element"
107                 , BT_MESH_UNIT_TEST_FUNCTION_NODE_CREATE_ELEMENT},
108         {"bt_mesh_node_get_network"
109                 , BT_MESH_UNIT_TEST_FUNCTION_NODE_GET_NETWORK},
110         {"bt_mesh_element_create_model"
111                 , BT_MESH_UNIT_TEST_FUNCTION_ELEMENT_CREATE_MODEL},
112         {"bt_mesh_model_get_id"
113                 , BT_MESH_UNIT_TEST_FUNCTION_MODEL_GET_ID},
114         {"bt_mesh_model_destroy"
115                 , BT_MESH_UNIT_TEST_FUNCTION_MODEL_DESTROY},
116         {"bt_mesh_model_get_element"
117                 , BT_MESH_UNIT_TEST_FUNCTION_MODEL_GET_ELEMENT},
118         {"bt_mesh_element_destroy"
119                 , BT_MESH_UNIT_TEST_FUNCTION_ELEMENT_DESTROY},
120         {"bt_mesh_element_get_node"
121                 , BT_MESH_UNIT_TEST_FUNCTION_ELEMENT_GET_NODE},
122         {"bt_mesh_node_foreach_element"
123                 , BT_MESH_UNIT_TEST_FUNCTION_NODE_FOREACH_ELEMENTS},
124         {"bt_mesh_element_foreach_models"
125                 , BT_MESH_UNIT_TEST_FUNCTION_ELEMENT_FOREACH_MODELS},
126         {"bt_mesh_network_create"
127                 , BT_MESH_UNIT_TEST_FUNCTION_NETWORK_CREATE},
128         {"bt_mesh_network_create_in_loop"
129                 , BT_MESH_UNIT_TEST_FUNCTION_NETWORK_CREATE_IN_LOOP},
130         {"bt_mesh_network_destroy"
131                 , BT_MESH_UNIT_TEST_FUNCTION_NETWORK_DESTROY},
132         {"bt_mesh_network_load"
133                 , BT_MESH_UNIT_TEST_FUNCTION_NETWORK_LOAD},
134         {"bt_mesh_network_set_name"
135                 , BT_MESH_UNIT_TEST_FUNCTION_NETWORK_SET_NAME},
136         {"bt_mesh_network_get_name"
137                 , BT_MESH_UNIT_TEST_FUNCTION_NETWORK_GET_NAME},
138         {"bt_mesh_network_add_netkey"
139                 , BT_MESH_UNIT_TEST_FUNCTION_NETWORK_ADD_NETKEY},
140         {"bt_mesh_network_foreach_netkeys"
141                 , BT_MESH_UNIT_TEST_FUNCTION_NETWORK_FOREACH_NETKEYS},
142         {"bt_mesh_netkey_get_index"
143                 , BT_MESH_UNIT_TEST_FUNCTION_NETKEY_GET_INDEX},
144         {"bt_mesh_netkey_update"
145                 , BT_MESH_UNIT_TEST_FUNCTION_NETKEY_UPDATE},
146         {"bt_mesh_netkey_delete"
147                 , BT_MESH_UNIT_TEST_FUNCTION_NETKEY_DELETE},
148         {"bt_mesh_netkey_add_appkey"
149                 , BT_MESH_UNIT_TEST_FUNCTION_NETKEY_ADD_APPKEY},
150         {"bt_mesh_netkey_foreach_appkeys"
151                 , BT_MESH_UNIT_TEST_FUNCTION_NETKEY_FOREACH_APPKEYS},
152         {"bt_mesh_appkey_get_index"
153                 , BT_MESH_UNIT_TEST_FUNCTION_APPKEY_GET_INDEX},
154         {"bt_mesh_appkey_update"
155                 , BT_MESH_UNIT_TEST_FUNCTION_APPKEY_UPDATE},
156         {"bt_mesh_appkey_delete"
157                 , BT_MESH_UNIT_TEST_FUNCTION_APPKEY_DELETE},
158         {"bt_mesh_network_foreach_devices"
159                 , BT_MESH_UNIT_TEST_FUNCTION_NETWORK_FOREACH_DEVICES},
160         {"bt_mesh_network_create_group"
161                 , BT_MESH_UNIT_TEST_FUNCTION_NETWORK_CREATE_GROUP},
162         {"bt_mesh_network_create_virtual_group"
163                 , BT_MESH_UNIT_TEST_FUNCTION_NETWORK_CREATE_VIRTUAL_GROUP},
164         {"bt_mesh_network_remove_group"
165                 ,  BT_MESH_UNIT_TEST_FUNCTION_NETWORK_REMOVE_GROUP},
166         {"bt_mesh_network_foreach_groups"
167                 , BT_MESH_UNIT_TEST_FUNCTION_NETWORK_FOREACH_GROUPS},
168         {"bt_mesh_network_unprovisioned_device_scan"
169                 , BT_MESH_UNIT_TEST_FUNCTION_NETWORK_UNPROVISIONED_DEVICE_SCAN},
170         {"bt_mesh_stop_unprovisioned_device_scan"
171                 , BT_MESH_UNIT_TEST_FUNCTION_STOP_UNPROVISIONED_DEVICE_SCAN},
172         {"bt_mesh_network_provision_device"
173                 , BT_MESH_UNIT_TEST_FUNCTION_NETWORK_PROVISION_DEVICE},
174         {"bt_mesh_authentication_set_request_cb"
175                 , BT_MESH_UNIT_TEST_FUNCTION_NETWORK_AUTHENTICATION_SET_REQUEST_CB},
176         {"bt_mesh_authentication_reply"
177                 , BT_MESH_UNIT_TEST_FUNCTION_MESH_AUTHENTICATION_REPLY},
178         {"bt_mesh_network_set_provisioning_capabilities"
179                 , BT_MESH_UNIT_TEST_FUNCTION_NETWORK_SET_PROVISIONING_CAPABILITIES},
180         {"bt_mesh_network_get_provisioning_capabilities"
181                 , BT_MESH_UNIT_TEST_FUNCTION_NETWORK_GET_PROVISIONING_CAPABILITIES},
182         {"select this menu to set parameters and then select the function again"
183                 , BT_MESH_UNIT_TEST_FUNCTION_ACTIVATE_FLAG_TO_SET_PARAMETERS},
184         {NULL                                           , 0X0000},
185 };
186
187 tc_table_t tc_main[] = {
188         {"bt_mesh_initialize"
189                 , BT_MESH_UNIT_TEST_FUNCTION_INITIALIZE},
190         {"bt_mesh_deinitialize"
191                 , BT_MESH_UNIT_TEST_FUNCTION_DEINITIALIZE},
192         {"Network"
193                 , BT_MESH_UNIT_TEST_TABLE_NETWORK},
194         {"Configuration"
195                 , BT_MESH_UNIT_TEST_TABLE_CONFIGURATION},
196         {"Finish"
197                 , BT_MESH_UNIT_TEST_TABLE_FINISH},
198         {NULL                                           , 0x0000},
199 };
200
201 static void __bt_free_test_param(tc_params_t *param)
202 {
203         int i = 0;
204
205         for (i = 0; i < param->param_count; i++)
206                 g_free(param->params[i]);
207         g_free(param->params);
208         param->params = NULL;
209         param->param_count = 0;
210 }
211
212 void tc_usage_print(void){
213         int i=0;
214         tc_table_t *tc_table = NULL;
215         switch (current_tc_table) {
216         case BT_MESH_UNIT_TEST_TABLE_NETWORK:
217                 tc_table = tc_network;
218                 break;
219         case BT_MESH_UNIT_TEST_TABLE_CONFIGURATION:
220                 tc_table = tc_configuration;
221                 break;
222         default:
223                 tc_table = tc_main;
224                 break;
225         }
226         while (tc_table[i].tc_name) {
227                 TC_PRT("Key %d : usage %s", tc_table[i].tc_code,tc_table[i].tc_name);
228                 i++;
229         }
230 }
231
232 static const char *__bt_get_error_message(bt_error_e err)
233 {
234         const char *err_str = NULL;
235
236         switch (err) {
237         case BT_ERROR_NONE:
238                 err_str = "BT_ERROR_NONE";
239                 break;
240         case BT_ERROR_CANCELLED:
241                 err_str = "BT_ERROR_CANCELLED";
242                 break;
243         case BT_ERROR_INVALID_PARAMETER:
244                 err_str = "BT_ERROR_INVALID_PARAMETER";
245                 break;
246         case BT_ERROR_OUT_OF_MEMORY:
247                 err_str = "BT_ERROR_OUT_OF_MEMORY";
248                 break;
249         case BT_ERROR_RESOURCE_BUSY:
250                 err_str = "BT_ERROR_RESOURCE_BUSY";
251                 break;
252         case BT_ERROR_TIMED_OUT:
253                 err_str = "BT_ERROR_TIMED_OUT";
254                 break;
255         case BT_ERROR_NOW_IN_PROGRESS:
256                 err_str = "BT_ERROR_NOW_IN_PROGRESS";
257                 break;
258         case BT_ERROR_NOT_INITIALIZED:
259                 err_str = "BT_ERROR_NOT_INITIALIZED";
260                 break;
261         case BT_ERROR_NOT_ENABLED:
262                 err_str = "BT_ERROR_NOT_ENABLED";
263                 break;
264         case BT_ERROR_ALREADY_DONE:
265                 err_str = "BT_ERROR_ALREADY_DONE";
266                 break;
267         case BT_ERROR_OPERATION_FAILED:
268                 err_str = "BT_ERROR_OPERATION_FAILED";
269                 break;
270         case BT_ERROR_NOT_IN_PROGRESS:
271                 err_str = "BT_ERROR_NOT_IN_PROGRESS";
272                 break;
273         default:
274                 err_str = "NOT defined";
275                 break;
276                 }
277         return err_str;
278 }
279
280 void print_network_handle(bt_mesh_network_h network)
281 {
282         if(network == NULL)
283                 return;
284         bt_mesh_network_s* net  = (bt_mesh_network_s*) network;
285         TC_PRT("network_handle = [%p]", (void*)net);
286         TC_PRT("net->is_local      [%d]", net->is_local);
287         TC_PRT("net->is_discovered [%d]", net->is_discovered);
288         TC_PRT("net->uuid          [%s]", net->uuid);
289         TC_PRT("net->token         [%s]", net->token);
290         TC_PRT("net->name          [%s]", net->name);
291         TC_PRT("net->num_nodes     [%d]", net->num_nodes);
292 }
293
294 void print_node_handle(bt_mesh_node_h node)
295 {
296         if(node == NULL)
297                 return;
298         bt_mesh_node_s* node_info = (bt_mesh_node_s*) node;
299         TC_PRT("node_handle = [%p]",(void*)node_info);
300         TC_PRT("node->is_local       [%d]", node_info->is_local);
301         TC_PRT("node->is_attached    [%d]", node_info->is_attached);
302         if (node_info->is_attached) {
303                 TC_PRT("node->parent_network [%s]", node_info->parent->name);
304                 TC_PRT("node->uuid [%s]", node_info->uuid);
305                 TC_PRT("node->unicast        [%d]", node_info->unicast);
306         }
307
308 }
309
310 void print_element_handle(bt_mesh_element_h element)
311 {
312         if(element == NULL)
313                 return;
314         bt_mesh_element_s* element_info = (bt_mesh_element_s*) element;
315         TC_PRT("element_handle = [%p]", (void*)element_info);
316         TC_PRT("element->is_local    [%d]", element_info->is_local);
317         TC_PRT("element->index       [%d]", element_info->index);
318 }
319
320 void print_model_handle(bt_mesh_model_h model)
321 {
322         if(model == NULL)
323                 return;
324         bt_mesh_model_s* model_info = (bt_mesh_model_s*) model;
325         TC_PRT("model_handle = [%p]", (void*)model_info);
326         TC_PRT("model->is_local      [%d]", model_info->is_local);
327         TC_PRT("model->id            [0x%4.4x]", model_info->id);
328         TC_PRT("model->pub_addr      [0x%2.2x]", model_info->pub_addr);
329 }
330
331 void print_netkey_handle(bt_mesh_netkey_h netkey)
332 {
333         if(netkey == NULL)
334                 return;
335         bt_mesh_netkey_s* netkey_info = (bt_mesh_netkey_s*) netkey;
336         TC_PRT("netkey_handle = [%p]", (void*)netkey_info);
337         TC_PRT("Parent network_name [%s]", netkey_info->parent->name);
338         TC_PRT("Netkey_index        [%d]", netkey_info->netkey_index);
339 }
340
341 void print_appkey_handle(bt_mesh_appkey_h appkey)
342 {
343         if(appkey == NULL)
344                 return;
345         bt_mesh_appkey_s* appkey_info = (bt_mesh_appkey_s*) appkey;
346         TC_PRT("appkey_handle = [%p]", (void*)appkey_info);
347         TC_PRT("Parent netkey_index [%d]", appkey_info->parent->netkey_index);
348         TC_PRT("appkey_index         [%d]", appkey_info->appkey_index);
349 }
350
351 void print_group_handle(bt_mesh_group_h group)
352 {
353         if(group == NULL)
354                 return;
355         bt_mesh_group_s* group_info = (bt_mesh_group_s*) group;
356         TC_PRT("group_handle = [%p]", (void*)group_info);
357         TC_PRT("group Parent Network Name  [%s]", group_info->parent->name);
358         TC_PRT("group Address              [0x%2.2x]", group_info->addr);
359         TC_PRT("group Label UUID           [%s]", group_info->label_uuid);
360         TC_PRT("group Is Virtual ? [%s]", group_info->is_virtual ? "YES" : "NO");
361 }
362
363 bool __bt_mesh_network_device_info_cb(int result, bt_mesh_network_h network, int total,
364                 const char *dev_uuid, uint16_t primary_unicast, void *user_data)
365 {
366         TC_PRT("bt_mesh_network_device_info_cb");
367         TC_PRT("Total number of Devices in network [%d]", total);
368
369         TC_PRT("result: %s", __bt_get_error_message(result));
370         TC_PRT("primary unicast address is [%d]",primary_unicast);
371         TC_PRT("Device UUID [%s]", dev_uuid);
372         return true;
373 }
374
375 bool __bt_mesh_network_group_info_cb(int result, bt_mesh_network_h network, int total,
376                 bt_mesh_group_h group, void *user_data)
377 {
378         bt_mesh_group_s* grp = (bt_mesh_group_s*) group;
379         TC_PRT("bt_mesh_network_group_info_cb: Total groups present in network [%d]", total);
380         TC_PRT("result: %s", __bt_get_error_message(result));
381
382         if (result == BT_ERROR_NONE) {
383                 print_group_handle(grp);
384                 return true;
385         } else
386                 return false;
387 }
388
389 void __bt_mesh_node_discover_status_cb(int result, bt_mesh_network_h network, bt_mesh_node_h node_param,
390                 void *user_data)
391 {
392         TC_PRT("bt_mesh_node_discover_status_cb");
393         TC_PRT("result: %s", __bt_get_error_message(result));
394         //print_network_handle(network);
395         print_node_handle(node_param);
396         if (result == BT_ERROR_NONE)
397                 g_node = node_param;
398 }
399
400 static bool __bt_mesh_elem_foreach_model_cb(int result, bt_mesh_element_h element, int total,
401                 bt_mesh_model_h model, bt_mesh_model_id_s *model_id, void *user_data)
402 {
403         TC_PRT("__bt_mesh_elem_foreach_model_cb");
404         TC_PRT("result: %s", __bt_get_error_message(result));
405
406         if (result == BT_ERROR_NONE) {
407                 TC_PRT("Total number of Models in the element [%d]", total);
408                 print_element_handle(element);
409                 if (total) {
410                         print_model_handle(model);
411                         TC_PRT("Model Comp ID [0x%2.2x] Model ID [0x%2.2x]",
412                                         model_id->company_id, model_id->model_id);
413                 }
414                 return true;
415         } else
416                 return false;
417 }
418
419 static bool __bt_mesh_node_foreach_elem_cb(int result, bt_mesh_node_h node, int total,
420         bt_mesh_element_h element, int elem_index, uint16_t element_addr, void *user_data)
421 {
422         TC_PRT("__bt_mesh_node_foreach_elem_cb");
423         TC_PRT("result: %s", __bt_get_error_message(result));
424
425         if (result == BT_ERROR_NONE) {
426                 TC_PRT("Total number of elements in the node [%d]", total);
427                 print_node_handle(node);
428                 if (total) {
429                         print_element_handle(element);
430                         TC_PRT("Element address [0x%2.2x]", element_addr);
431                         TC_PRT("Element index  [%d]", elem_index);
432                 }
433                 return true;
434         } else
435                 return false;
436 }
437
438 static void __bt_mesh_node_configure_netkey_cb(int result, bt_mesh_node_key_configuration_e op,
439                 bt_mesh_node_h node, bt_mesh_netkey_h netkey, void *user_data)
440 {
441         TC_PRT("__bt_mesh_node_configure_netkey_cb");
442         TC_PRT("result: %s", __bt_get_error_message(result));
443
444         if (result == BT_ERROR_NONE) {
445                 print_node_handle(node);
446                 if (op == BT_MESH_NODE_KEY_ADD)
447                         TC_PRT("NetKey Added!");
448                 else if (op == BT_MESH_NODE_KEY_UPDATE)
449                         TC_PRT("NetKey Updated!");
450                 else
451                         TC_PRT("NetKey Deleted!");
452                 print_netkey_handle(netkey);
453         }
454 }
455
456 static void __bt_mesh_node_configure_appkey_cb(int result, bt_mesh_node_key_configuration_e op,
457                         bt_mesh_node_h node, bt_mesh_netkey_h netkey,
458                                 bt_mesh_appkey_h appkey, void *user_data)
459 {
460         TC_PRT("__bt_mesh_node_configure_netkey_cb");
461         TC_PRT("result: %s", __bt_get_error_message(result));
462
463         if (result == BT_ERROR_NONE) {
464                 print_node_handle(node);
465                 if (op == BT_MESH_NODE_KEY_ADD)
466                         TC_PRT("AppKey Added!");
467                 else if (op == BT_MESH_NODE_KEY_UPDATE)
468                         TC_PRT("AppKey Updated!");
469                 else
470                         TC_PRT("AppKey Deleted!");
471                 print_netkey_handle(netkey);
472                 print_appkey_handle(appkey);
473         }
474 }
475
476 static void __bt_mesh_node_features_cb(int result, bt_mesh_node_h node,
477                         bt_mesh_node_features_s *features, void *user_data)
478 {
479         TC_PRT("__bt_mesh_node_features_cb");
480         TC_PRT("result: %s", __bt_get_error_message(result));
481
482         if (result == BT_ERROR_NONE) {
483                 print_node_handle(node);
484                 TC_PRT("CID [0x%2.2x]\n", features->cid);
485                 TC_PRT("PID [0x%2.2x]\n", features->pid);
486                 TC_PRT("VID [0x%2.2x]\n", features->vid);
487                 TC_PRT("CRPL [0x%2.2x]\n", features->crpl);
488
489                 if (features->features & BT_MESH_FEATURE_RELAY)
490                         TC_PRT("Features: RELAY Supported");
491                 if (features->features & BT_MESH_FEATURE_PROXY)
492                         TC_PRT("Features: PROXY Supported");
493                 if (features->features & BT_MESH_FEATURE_FRIEND)
494                         TC_PRT("Features: FRIEND Supported");
495                 if (features->features & BT_MESH_FEATURE_LOWPOWER)
496                         TC_PRT("Features: LOW POWER Supported\n");
497         }
498 }
499
500 static bool __bt_mesh_node_foreach_netkeys_cb(int result, bt_mesh_node_h node, int total,
501                                 bt_mesh_netkey_h netkey,
502                                         uint16_t netkey_index, void *user_data)
503 {
504         TC_PRT("__bt_mesh_node_foreach_netkeys_cb");
505         TC_PRT("result: %s", __bt_get_error_message(result));
506
507         if (result == BT_ERROR_NONE) {
508                 TC_PRT("Total Netkeys in node [%d]", total);
509                 print_node_handle(node);
510                 print_netkey_handle(netkey);
511                 return true;
512         }
513         return false;
514 }
515
516 static bool __bt_mesh_node_foreach_appkeys_cb(int result, bt_mesh_node_h node, int total,
517                                 bt_mesh_netkey_h netkey, bt_mesh_appkey_h appkey,
518                                         uint16_t appkey_index, void *user_data)
519 {
520         TC_PRT("__bt_mesh_node_foreach_appkeys_cb");
521         TC_PRT("result: %s", __bt_get_error_message(result));
522
523         if (result == BT_ERROR_NONE) {
524                 TC_PRT("Total Appkeys in node [%d]", total);
525                 print_netkey_handle(netkey);
526                 print_appkey_handle(appkey);
527                 return true;
528         }
529         return false;
530 }
531
532 void __bt_mesh_node_ttl_cb(int result, bt_mesh_node_h node,
533                 bt_mesh_node_ttl_operation_e ttl_op, uint8_t ttl, void *user_data)
534 {
535         TC_PRT("bt_mesh_node_ttl_cb");
536         TC_PRT("result: %s", __bt_get_error_message(result));
537
538         if (result == BT_ERROR_NONE) {
539                 print_node_handle(node);
540                 TC_PRT("ttl_op is [%s]", ttl_op? "TTL Set" : "TTL Get");
541                 TC_PRT("ttl value is [%d]",ttl);
542         }
543 }
544
545 void __bt_mesh_model_bind_cb(int result, bt_mesh_model_h model, bt_mesh_appkey_h appkey,
546                 void *user_data)
547 {
548         TC_PRT("bt_mesh_model_bind_cb");
549         TC_PRT("result: %s", __bt_get_error_message(result));
550         if (result == BT_ERROR_NONE) {
551                 print_model_handle(model);
552                 print_appkey_handle(appkey);
553         }
554 }
555
556 void __bt_mesh_model_msg_cb(int result, bt_mesh_element_h element, bt_mesh_appkey_h appkey,
557                 bt_mesh_model_msg_params_s *msg, void *user_data)
558 {
559         TC_PRT("bt_mesh_model_msg_cb");
560         TC_PRT("result: %s", __bt_get_error_message(result));
561         if (result == BT_ERROR_NONE) {
562                 TC_PRT("opcode: 0X%2.2X", msg->opcode);
563                 TC_PRT("msg: %s", msg->data);
564                 print_element_handle(element);
565                 print_appkey_handle(appkey);
566         }
567 }
568
569 void __bt_mesh_model_unbind_cb(int result, bt_mesh_model_h model, bt_mesh_appkey_h appkey,
570                 void *user_data)
571 {
572         TC_PRT("bt_mesh_model_unbind_cb");
573         TC_PRT("result: %s", __bt_get_error_message(result));
574         if (result == BT_ERROR_NONE) {
575                 print_model_handle(model);
576                 print_appkey_handle(appkey);
577         }
578 }
579
580 void __bt_mesh_model_appkey_list_cb(int result, bt_mesh_model_h model, int total,  const GSList *appkeylist,
581                 void *user_data)
582 {
583         TC_PRT("bt_mesh_model_appkey_list_cb");
584         const GSList *l;
585
586         TC_PRT("result: %s", __bt_get_error_message(result));
587         if (result == BT_ERROR_NONE) {
588                 TC_PRT("Total number of AppKeys bound to the model [%d]", total);
589                 print_model_handle(model);
590
591                 for (l = appkeylist; l != NULL; l = l->next) {
592                         bt_mesh_appkey_h appkey = (bt_mesh_appkey_h) l->data;
593                         print_appkey_handle(appkey);
594                 }
595         }
596 }
597
598 void __bt_mesh_model_subscription_op_cb(int result, bt_mesh_model_subscription_op_e op,
599                 bt_mesh_model_h model, bt_mesh_group_h group, void *user_data)
600 {
601         TC_PRT("bt_mesh_model_subscription_op_cb");
602         TC_PRT("result: %s", __bt_get_error_message(result));
603
604         if (result == BT_ERROR_NONE) {
605                 switch(op) {
606                 case 0:
607                         TC_PRT("Model Subscription Operation is ADD");
608                         break;
609                 case 1:
610                         TC_PRT("Model Subscription Operation is DELETE");
611                         break;
612                 case 2:
613                         TC_PRT("Model Subscription Operation is DELETE ALL");
614                         break;
615                 case 3:
616                         TC_PRT("Model Subscription Operation is OVERWRITE");
617                         break;
618                 default:
619                         TC_PRT("Invalid Model Subscription Operation");
620                         break;
621                 }
622                 print_model_handle(model);
623                 print_group_handle(group);
624         }
625 }
626
627 bool __bt_mesh_model_subscription_list_cb(int result, bt_mesh_model_h model, int total, const GSList *sub_addr,
628                 void *user_data)
629 {
630         const GSList *l;
631         TC_PRT("bt_mesh_model_subscription_list_cb");
632         TC_PRT("result: %s", __bt_get_error_message(result));
633         if (result == BT_ERROR_NONE) {
634                 TC_PRT("Total number of AppKeys bound to the model [%d]", total);
635                 print_model_handle(model);
636
637                 for (l = sub_addr; l != NULL; l = l->next) {
638                         bt_mesh_group_h group = (bt_mesh_group_h) l->data;
639                         print_group_handle(group);
640                 }
641         }
642         return true;
643 }
644
645 void __bt_mesh_model_publication_status_cb(int result, bt_mesh_model_h model, bt_mesh_group_h group,
646                 bt_mesh_appkey_h appkey, void *user_data)
647 {
648         TC_PRT("bt_mesh_model_publication_status_cb");
649         TC_PRT("result: %s", __bt_get_error_message(result));
650
651         if (result == BT_ERROR_NONE) {
652                 print_model_handle(model);
653                 print_group_handle(group);
654                 print_appkey_handle(appkey);
655         }
656 }
657
658 void __bt_mesh_network_create_cb(int result, bt_mesh_network_h network, const char *network_name, void *user_data)
659 {
660         TC_PRT("bt_mesh_network_create_cb");
661         TC_PRT("result: %s", __bt_get_error_message(result));
662         print_network_handle(network);
663 }
664
665 bool __bt_mesh_appkey_info_cb(int result, bt_mesh_network_h network, int total,
666                 bt_mesh_netkey_h netkey, bt_mesh_appkey_h appkey, uint16_t appkey_index, void *user_data)
667 {
668         TC_PRT("bt_mesh_network_appkey_info_cb");
669         TC_PRT("result: %s", __bt_get_error_message(result));
670         //print_network_handle(network);
671         //print_netkey_handle(netkey);
672         print_appkey_handle(appkey);
673         TC_PRT("Total appkeys are [%d]",total);
674         return true;
675 }
676
677 bool  __bt_mesh_network_netkey_info_cb(int result, bt_mesh_network_h network, int total,
678                 bt_mesh_netkey_h netkey, uint16_t netkey_index, void *user_data)
679 {
680         TC_PRT("bt_mesh_network_netkey_info_cb");
681         TC_PRT("result: %s", __bt_get_error_message(result));
682         //print_network_handle(network);
683         print_netkey_handle(netkey);
684         TC_PRT("Total netkeys are [%d]",total);
685         if (result == BT_ERROR_NONE && netkey_index == 0) {
686                 TC_PRT("Attempt to delete Primary Subnet");
687                 result = bt_mesh_netkey_delete(netkey);
688                 TC_PRT("return %s\n", __bt_get_error_message(result));
689                 if (result == BT_ERROR_NONE)
690                         TC_PRT("Primary netkey is deleted");
691                 else
692                         TC_PRT("Primary NetKey deletion failed");
693         }
694         return true;
695 }
696
697 void __bt_mesh_network_scan_unprovisioned_device_result_cb(int result, bt_mesh_network_h network,
698                         bt_mesh_scanning_state_e state, bt_mesh_scan_result_s *scan_res, void *user_data)
699 {
700         TC_PRT("bt_mesh_network_scan_unprovisioned_device_result_cb");
701         TC_PRT("result: %s", __bt_get_error_message(result));
702         if (state == BT_MESH_SCANNING_STARTED) {
703                 TC_PRT("The scanning state is: STARTED");
704                 print_network_handle(network);
705         }
706         else if (state == BT_MESH_SCANNING_FINISHED) {
707                 TC_PRT("The scanning state is: STOPPED");
708                 print_network_handle(network);
709         }
710         else {
711                 TC_PRT("Scan Result found");
712                 TC_PRT("Device UUID is %s\n", scan_res->uuid);
713                 TC_PRT("RSSI values is %d\n", scan_res->rssi);
714                 TC_PRT("OOB Info 0x%x\n", scan_res->oob_info);
715         }
716 }
717
718 void __bt_mesh_network_device_provision_cb(int result, bt_mesh_network_h network,
719                         const char* dev_uuid, void* user_data)
720 {
721         TC_PRT("bt_mesh_network_device_provision_cb");
722         TC_PRT("result: %s", __bt_get_error_message(result));
723         print_network_handle(network);
724         if(dev_uuid == NULL)
725                 TC_PRT("dev_uuid is NULL");
726         else {
727                 TC_PRT("The device_uuid is [%s]", dev_uuid);
728                 device_uuid = g_strdup(dev_uuid);
729         }
730 }
731
732 void __bt_mesh_authentication_request_cb(int result, bt_mesh_authentication_type_e auth_type,
733                 char *auth_value, void *user_data)
734 {
735         TC_PRT("bt_mesh_authentication_request_cb");
736         TC_PRT("result: %s", __bt_get_error_message(result));
737         TC_PRT("auth_value is [%s]", auth_value);
738         TC_PRT("auth_type is [%d]", auth_type);
739         request_type = auth_type;
740 }
741
742 int test_set_params(int test_id, char *param){
743         static int param_index = 0;
744         int param_count = 0;
745
746         if (param_index > 0 && param_index == g_test_param.param_count)
747                 goto done;
748         switch (current_tc_table) {
749         case BT_MESH_UNIT_TEST_TABLE_NETWORK: {
750                 switch(test_id) {
751                 case BT_MESH_UNIT_TEST_FUNCTION_NETWORK_CREATE:
752                         param_count = 2;
753                         switch(param_index) {
754                         case 0:
755                                 TC_PRT("Input param(%d) (network_name)\n",param_index + 1);
756                                 break;
757                         case 1:
758                                 TC_PRT("Input param(%d) (Node Handle)\n",param_index + 1);
759                                 break;
760                         }
761                         break;
762                 case BT_MESH_UNIT_TEST_FUNCTION_NETWORK_CREATE_IN_LOOP:
763                         param_count = 1;
764                         TC_PRT("Input param(%d) (Number of networks)\n",param_index + 1);
765                         break;
766                 case BT_MESH_UNIT_TEST_FUNCTION_NETWORK_DESTROY:
767                         param_count = 1;
768                         TC_PRT("Input param(%d) (network_handle)\n",param_index + 1);
769                         break;
770                 case BT_MESH_UNIT_TEST_FUNCTION_NODE_DESTROY:
771                         param_count = 1;
772                         TC_PRT("Input param(%d) (node Handle)\n",param_index + 1);
773                         break;
774                 case BT_MESH_UNIT_TEST_FUNCTION_NODE_GET_NETWORK:
775                         param_count = 1;
776                         TC_PRT("Input param(%d) (node Handle)\n",param_index + 1);
777                         break;
778                 case BT_MESH_UNIT_TEST_FUNCTION_NODE_CREATE_ELEMENT:
779                         param_count = 1;
780                         TC_PRT("Input param(%d) (node Handle)\n",param_index + 1);
781                         break;
782                 case BT_MESH_UNIT_TEST_FUNCTION_ELEMENT_CREATE_MODEL:
783                         param_count = 2;
784                         switch(param_index) {
785                         case 0:
786                                 TC_PRT("Input param(%d) (Element Handle)\n" ,param_index + 1);
787                                 break;
788                         case 1:
789                                 TC_PRT("Input param(%d) (Model ID)\n",param_index + 1);
790                                 break;
791                         }
792                         break;
793                 case BT_MESH_UNIT_TEST_FUNCTION_ELEMENT_GET_NODE:
794                         param_count=1;
795                         TC_PRT("Input param(%d) (Element Handle)\n",param_index + 1);
796                         break;
797                 case BT_MESH_UNIT_TEST_FUNCTION_MODEL_GET_ID:
798                         param_count=1;
799                         TC_PRT("Input param(%d) (Model Handle)\n",param_index + 1);
800                         break;
801                 case BT_MESH_UNIT_TEST_FUNCTION_MODEL_DESTROY:
802                         param_count=1;
803                         TC_PRT("Input param(%d) (Model Handle)\n",param_index + 1);
804                         break;
805                 case BT_MESH_UNIT_TEST_FUNCTION_MODEL_GET_ELEMENT:
806                         param_count=1;
807                         TC_PRT("Input param(%d) (Model Handle)\n",param_index + 1);
808                         break;
809                 case BT_MESH_UNIT_TEST_FUNCTION_ELEMENT_DESTROY:
810                         param_count=1;
811                         TC_PRT("Input param(%d) (Element Handle)\n",param_index + 1);
812                         break;
813                 case BT_MESH_UNIT_TEST_FUNCTION_NODE_FOREACH_ELEMENTS:
814                         param_count = 1;
815                         TC_PRT("Input param(%d) (Node Handle)", param_index + 1);
816                         break;
817                 case BT_MESH_UNIT_TEST_FUNCTION_ELEMENT_FOREACH_MODELS:
818                         param_count = 1;
819                         TC_PRT("Input param(%d) (Element Handle)", param_index + 1);
820                         break;
821                 case BT_MESH_UNIT_TEST_FUNCTION_NETWORK_CREATE_GROUP:
822                         param_count = 1;
823                         TC_PRT("Input param(%d) (group address)\n" ,param_index + 1);
824                         break;
825                 case BT_MESH_UNIT_TEST_FUNCTION_NETWORK_REMOVE_GROUP:
826                         param_count = 1;
827                         TC_PRT("Input param(%d) (group handle)\n" ,param_index + 1);
828                         break;
829                 case BT_MESH_UNIT_TEST_FUNCTION_NETWORK_UNPROVISIONED_DEVICE_SCAN:
830                         param_count = 1;
831                         TC_PRT("Input param(%d) (Seconds)\n" ,param_index + 1);
832                         break;
833                 case BT_MESH_UNIT_TEST_FUNCTION_NETWORK_PROVISION_DEVICE:
834                         param_count = 1;
835                         TC_PRT("Input param(%d) (device_uuid)\n",param_index+1);
836                         break;
837                 case BT_MESH_UNIT_TEST_FUNCTION_NETWORK_SET_NAME:
838                         param_count=1;
839                         TC_PRT("Input param(%d) (network_name)",param_index + 1);
840                         break;
841                 case BT_MESH_UNIT_TEST_FUNCTION_MESH_AUTHENTICATION_REPLY:
842                         param_count=2;
843                         switch(param_index) {
844                         case 0:
845                                 TC_PRT("Input param(%d) (auth_value)\n",param_index +1);
846                                 break;
847                         case 1:
848                                 TC_PRT("Input param(%d) (auth_reply)\n",param_index + 1);
849                                 TC_PRT("0: false,  1: true");
850                                 break;
851                         }
852                         break;
853                 case BT_MESH_UNIT_TEST_FUNCTION_NETWORK_SET_PROVISIONING_CAPABILITIES:
854                         param_count = 4;
855                         switch(param_index) {
856                         case 0:
857                                 TC_PRT("\nInput param(%d) is_public_oob",param_index + 1);
858                                 TC_PRT("0: false, 1: true\n");
859                                 break;
860                         case 1:
861                                 TC_PRT("\nInput param(%d) is_static_oob",param_index + 1);
862                                 TC_PRT("0: false, 1 : true\n");
863                                 break;
864                         case 2:
865                                 TC_PRT("\nInput param(%d) output_oob",param_index + 1);
866                                 TC_PRT("BT_MESH_OUT_OOB_METHOD_BLINK            = 0x01");
867                                 TC_PRT("BT_MESH_OUT_OOB_METHOD_BEEP             = 0x02");
868                                 TC_PRT("BT_MESH_OUT_OOB_METHOD_VIBRATE          = 0x04");
869                                 TC_PRT("BT_MESH_OUT_OOB_METHOD_NUMERIC          = 0x08");
870                                 TC_PRT("BT_MESH_OUT_OOB_METHOD_ALPHANUMERIC     = 0x10\n");
871                                 break;
872                         case 3:
873                                 TC_PRT("\nInput param(%d) input_oob",param_index + 1);
874                                 TC_PRT("BT_MESH_IN_OOB_METHOD_PUSH              = 0x01");
875                                 TC_PRT("BT_MESH_IN_OOB_METHOD_TWIST             = 0x02");
876                                 TC_PRT("BT_MESH_IN_OOB_METHOD_NUMERIC           = 0x04");
877                                 TC_PRT("BT_MESH_IN_OOB_METHOD_ALPHANUMERIC      = 0x08\n");
878                                 break;
879                         }
880                         break;
881                 case BT_MESH_UNIT_TEST_FUNCTION_NETKEY_GET_INDEX:
882                         param_count = 1;
883                         TC_PRT("Input param(%d) (NetKey Handle)", param_index + 1);
884                         break;
885                 case BT_MESH_UNIT_TEST_FUNCTION_NETKEY_UPDATE:
886                         param_count = 1;
887                         TC_PRT("Input param(%d) (NetKey Handle)", param_index + 1);
888                         break;
889                 case BT_MESH_UNIT_TEST_FUNCTION_NETKEY_DELETE:
890                         param_count = 1;
891                         TC_PRT("Input param(%d) (NetKey Handle)", param_index + 1);
892                         break;
893                 case BT_MESH_UNIT_TEST_FUNCTION_NETKEY_ADD_APPKEY:
894                         param_count = 1;
895                         TC_PRT("Input param(%d) (NetKey Handle)", param_index + 1);
896                         break;
897                 case BT_MESH_UNIT_TEST_FUNCTION_NETKEY_FOREACH_APPKEYS:
898                         param_count = 1;
899                         TC_PRT("Input param(%d) (NetKey Handle)", param_index + 1);
900                         break;
901                 case BT_MESH_UNIT_TEST_FUNCTION_APPKEY_GET_INDEX:
902                         param_count = 1;
903                         TC_PRT("Input param(%d) (AppKey Handle)", param_index + 1);
904                         break;
905                 case BT_MESH_UNIT_TEST_FUNCTION_APPKEY_UPDATE:
906                         param_count = 1;
907                         TC_PRT("Input param(%d) (AppKey Handle)", param_index + 1);
908                         break;
909                 case BT_MESH_UNIT_TEST_FUNCTION_APPKEY_DELETE:
910                         param_count = 1;
911                         TC_PRT("Input param(%d) (AppKey Handle)", param_index + 1);
912                         break;
913                 case BT_MESH_UNIT_TEST_FUNCTION_ACTIVATE_FLAG_TO_SET_PARAMETERS:
914                         need_to_set_params = true;
915                         TC_PRT("\nSelect the function again\n");
916                         break;
917                 default:
918                         TC_PRT("There is no parameter to set\n");
919                         break;
920                 }
921                 break;
922         }
923         case BT_MESH_UNIT_TEST_TABLE_CONFIGURATION: {
924                 switch(test_id) {
925                 case BT_MESH_UNIT_TEST_FUNCTION_MESH_NETWORK_DISCOVER_NODE:
926                         param_count = 1;
927                         TC_PRT("Input param(%d) (device_uuid)", param_index + 1);
928                         break;
929                 case BT_MESH_UNIT_TEST_FUNCTION_NODE_GET_FEATURES:
930                         param_count = 1;
931                         TC_PRT("Input param(%d) (Node Handle)", param_index + 1);
932                         break;
933                 case BT_MESH_UNIT_TEST_FUNCTION_NODE_GET_NETKEYS:
934                         param_count = 1;
935                         TC_PRT("Input param(%d) (Node Handle)", param_index + 1);
936                         break;
937                 case BT_MESH_UNIT_TEST_FUNCTION_NODE_GET_APPKEYS:
938                         param_count = 2;
939                         switch(param_index) {
940                         case 0:
941                                 TC_PRT("Input param(%d) (Node Handle)", param_index + 1);
942                                 break;
943                         case 1:
944                                 TC_PRT("Input param(%d) (Netkey Handle)\n", param_index + 1);
945                                 break;
946                         }
947                         break;
948                 case BT_MESH_UNIT_TEST_FUNCTION_APPKEY_GET_NETKEY:
949                         param_count = 1;
950                         TC_PRT("Input param(%d) (AppKey Handle)\n", param_index + 1);
951                         break;
952                 case BT_MESH_UNIT_TEST_FUNCTION_MODEL_GET_PUBLICATION:
953                         param_count = 1;
954                         TC_PRT("Input param(%d) (Model Handle)\n", param_index + 1);
955                         break;
956                 case BT_MESH_UNIT_TEST_FUNCTION_MODEL_SEND_MSG:
957                         param_count = 4;
958                         switch(param_index) {
959                         case 0:
960                                 TC_PRT("Input param(%d) (Model Handle)\n", param_index + 1);
961                                 break;
962                         case 1:
963                                 TC_PRT("Input param(%d) (Appkey Handle)\n", param_index + 1);
964                                 break;
965                         case 2:
966                                 TC_PRT("Input param(%d) (opcode)\n", param_index + 1);
967                                 break;
968                         case 3:
969                                 TC_PRT("Input param(%d) (Message)\n", param_index + 1);
970                                 break;
971                         }
972                         break;
973                 case BT_MESH_UNIT_TEST_FUNCTION_MODEL_SET_PUBLICATION:
974                         param_count = 3;
975                         switch(param_index) {
976                         case 0:
977                                 TC_PRT("\nInput param(%d) Model handle\n", param_index + 1);
978                                 break;
979                         case 1:
980                                 TC_PRT("\nInput param(%d) AppKey handle\n", param_index + 1);
981                                 break;
982                         case 2:
983                                 TC_PRT("\nInput param(%d) Group Handle\n", param_index + 1);
984                                 break;
985                         }
986                         break;
987                 case BT_MESH_UNIT_TEST_FUNCTION_MODEL_GET_SUBSCRIPTION_LIST:
988                         param_count = 1;
989                         TC_PRT("Input param(%d) (Model Handle)\n", param_index + 1);
990                         break;
991                 case BT_MESH_UNIT_TEST_FUNCTION_MODEL_CONFIGURE_GROUP_SUBSCRIPTION:
992                 case BT_MESH_UNIT_TEST_FUNCTION_MODEL_CONFIGURE_VIRTUAL_GROUP_SUBSCRIPTION:
993                         param_count = 3;
994                         switch(param_index) {
995                         case 0:
996                                 TC_PRT("\nInput param(%d) Model handle\n", param_index + 1);
997                                 break;
998                         case 1:
999                                 TC_PRT("\nInput param(%d) Model operation", param_index + 1);
1000                                 TC_PRT("BT_MESH_MODEL_SUBSCRIPTION_ADD = 0");
1001                                 TC_PRT("BT_MESH_MODEL_SUBSCRIPTION_DELETE = 1");
1002                                 TC_PRT("BT_MESH_MODEL_SUBSCRIPTION_DELETE_ALL = 2");
1003                                 TC_PRT("BT_MESH_MODEL_SUBSCRIPTION_OVERWRITE = 3\n");
1004                                 break;
1005                         case 2:
1006                                 TC_PRT("\nInput param(%d) Group Handle\n", param_index + 1);
1007                                 break;
1008                         }
1009                         break;
1010                 case BT_MESH_UNIT_TEST_FUNCTION_MODEL_GET_APPKEY_LIST:
1011                         param_count = 1;
1012                         TC_PRT("Input param(%d) (Model Handle)\n", param_index + 1);
1013                         break;
1014                 case BT_MESH_UNIT_TEST_FUNCTION_MODEL_BIND_APPKEY:
1015                 case BT_MESH_UNIT_TEST_FUNCTION_MODEL_UNBIND_APPKEY:
1016                         param_count = 2;
1017                         switch(param_index) {
1018                         case 0:
1019                                 TC_PRT("\nInput param(%d) Model Handle\n", param_index + 1);
1020                                 break;
1021                         case 1:
1022                                 TC_PRT("\nInput param(%d) AppKey handle\n", param_index + 1);
1023                                 break;
1024                         }
1025                         break;
1026                 case BT_MESH_UNIT_TEST_FUNCTION_NODE_CONFIGURE_NETKEY:
1027                 case BT_MESH_UNIT_TEST_FUNCTION_NODE_CONFIGURE_APPKEY:
1028                         param_count = 3;
1029                         switch(param_index) {
1030                         case 0:
1031                                 TC_PRT("\nInput param(%d) Node Handle\n", param_index + 1);
1032                                 break;
1033                         case 1:
1034                                 TC_PRT("\nInput param(%d) Key Handle\n", param_index + 1);
1035                                 break;
1036                         case 2:
1037                                 TC_PRT("\nInput param(%d) Key Config Option", param_index + 1);
1038                                 TC_PRT("BT_MESH_NODE_KEY_ADD = 0");
1039                                 TC_PRT("BT_MESH_NODE_KEY_UPDATE = 1");
1040                                 TC_PRT("BT_MESH_NODE_KEY_DELETE = 2\n");
1041                                 break;
1042                         }
1043                         break;
1044                 case BT_MESH_UNIT_TEST_FUNCTION_NODE_GET_TTL:
1045                         param_count=1;
1046                         TC_PRT("\nInput param(%d) Node Handle\n", param_index + 1);
1047                         break;
1048                 case BT_MESH_UNIT_TEST_FUNCTION_NODE_SET_TTL:
1049                         param_count = 2;
1050                         switch(param_index) {
1051                         case 0:
1052                                 TC_PRT("\nInput param(%d) Node Handle\n", param_index + 1);
1053                                 break;
1054                         case 1:
1055                                 TC_PRT("\nInput param(%d) TTL value\n", param_index + 1);
1056                                 break;
1057                         }
1058                         break;
1059                 default:
1060                         TC_PRT("There is no parameter to set\n");
1061                         break;
1062                 }
1063                 break;
1064         }
1065         default:
1066                 TC_PRT("There is no parameter to set\n");
1067                 need_to_set_params = false;
1068                 break;
1069         }
1070         done:
1071         if (need_to_set_params) {
1072                 if (param_index == 0) {
1073                         g_test_param.param_count = param_count;
1074                         g_test_param.params = g_malloc0(sizeof(char*) * g_test_param.param_count);
1075                 }
1076
1077                 if (param_index > 0) {
1078                         int len = strlen(param);
1079                         param[len - 1] = '\0';
1080                         g_test_param.params[param_index - 1] = g_strdup(param);
1081                 }
1082
1083                 if (param_index  == g_test_param.param_count) {
1084                         need_to_set_params = false;
1085 #ifdef ARCH64
1086                         test_input_callback((void *)(uintptr_t)test_id);
1087 #else
1088                         test_input_callback((void *)test_id);
1089 #endif
1090                         param_index = 0;
1091                         return 0;
1092                 }
1093
1094                 param_index++;
1095         }
1096
1097         return 0;
1098 }
1099
1100 int test_input_callback(void *data)
1101 {
1102                 int ret = 0;
1103 #ifdef ARCH64
1104         int test_id = (uintptr_t)data;
1105 #else
1106         int test_id = (int)data;
1107 #endif
1108
1109         switch (current_tc_table) {
1110         case BT_MESH_UNIT_TEST_TABLE_MAIN: {
1111                 switch (test_id) {
1112                 case 0x00ff:
1113                         TC_PRT("Finished\n");
1114                         g_main_loop_quit(main_loop);
1115                         break;
1116                 case BT_MESH_UNIT_TEST_FUNCTION_INITIALIZE:
1117                         ret = bt_mesh_initialize();
1118                         TC_PRT("return %s\n", __bt_get_error_message(ret));
1119                         break;
1120                 case BT_MESH_UNIT_TEST_FUNCTION_DEINITIALIZE:
1121                         ret = bt_mesh_deinitialize();
1122                         TC_PRT("return %s\n", __bt_get_error_message(ret));
1123                         break;
1124                 default:
1125                         break;
1126                 }
1127                 break;
1128         }
1129         case BT_MESH_UNIT_TEST_TABLE_NETWORK:{
1130                 switch (test_id) {
1131                 case BT_MESH_UNIT_TEST_FUNCTION_NODE_CREATE:{
1132                         bt_mesh_node_features_s features;
1133                         features.features = BT_MESH_FEATURE_RELAY;
1134                         features.features |= BT_MESH_FEATURE_LOWPOWER;
1135
1136                         ret = bt_mesh_node_create(&features, &local_node);
1137                         TC_PRT("return %s\n", __bt_get_error_message(ret));
1138                         if (ret == BT_ERROR_NONE)
1139                                 print_node_handle(local_node);
1140                         break;
1141                 }
1142                 case BT_MESH_UNIT_TEST_FUNCTION_NODE_DESTROY: {
1143                         bt_mesh_node_h node_h;
1144                         if (g_test_param.param_count != 1) {
1145                                 TC_PRT("Enter parameters first!");
1146                                 break;
1147                         }
1148                         node_h = GUINT_TO_POINTER(strtoul(g_test_param.params[0], NULL, 16));
1149                         ret = bt_mesh_node_destroy(node_h);
1150                         TC_PRT("return %s\n", __bt_get_error_message(ret));
1151                         break;
1152                 }
1153                 case BT_MESH_UNIT_TEST_FUNCTION_NODE_GET_NETWORK: {
1154                         bt_mesh_network_h net_h;
1155                         bt_mesh_node_h node_h;
1156                         if (g_test_param.param_count != 1) {
1157                                 TC_PRT("Enter parameters first!");
1158                                 break;
1159                         }
1160                         node_h = GUINT_TO_POINTER(strtoul(g_test_param.params[0], NULL, 16));
1161                         ret  = bt_mesh_node_get_network(node_h, &net_h);
1162                         TC_PRT("return %s\n", __bt_get_error_message(ret));
1163                         if (ret == BT_ERROR_NONE)
1164                                 print_network_handle(net_h);
1165                         break;
1166                 }
1167                 case BT_MESH_UNIT_TEST_FUNCTION_NODE_CREATE_ELEMENT: {
1168                         bt_mesh_element_h elem_h;
1169                         bt_mesh_node_h node_h;
1170                         if (g_test_param.param_count != 1) {
1171                                 TC_PRT("Enter parameters first!");
1172                                 break;
1173                         }
1174                         node_h = GUINT_TO_POINTER(strtoul(g_test_param.params[0], NULL, 16));
1175                         ret = bt_mesh_node_create_element(node_h, &elem_h);
1176                         TC_PRT("return %s\n", __bt_get_error_message(ret));
1177                         if (ret == BT_ERROR_NONE)
1178                                 print_element_handle(elem_h);
1179                         break;
1180                 }
1181                 case BT_MESH_UNIT_TEST_FUNCTION_ELEMENT_CREATE_MODEL: {
1182                         bt_mesh_element_h elem_h;
1183                         bt_mesh_model_h model_h;
1184                         bt_mesh_model_id_s mod_id;
1185                         memset(&mod_id, 0x00, sizeof(bt_mesh_model_id_s));
1186
1187                         if (g_test_param.param_count != 2) {
1188                                 TC_PRT("Enter parameters first!");
1189                                 break;
1190                         }
1191                         elem_h = GUINT_TO_POINTER(strtoul(g_test_param.params[0], NULL, 16));
1192                         mod_id.model_id = strtoul(g_test_param.params[1], NULL, 16);
1193                         mod_id.company_id = 0xFFFF;
1194                         TC_PRT("The model_id is [0x%2.2x]\n", mod_id.model_id);
1195                         ret = bt_mesh_element_create_model(elem_h, &mod_id, &model_h);
1196                         TC_PRT("return %s\n", __bt_get_error_message(ret));
1197                         if (ret == BT_ERROR_NONE)
1198                                 print_model_handle(model_h);
1199                         break;
1200                 }
1201                 case BT_MESH_UNIT_TEST_FUNCTION_ELEMENT_GET_NODE: {
1202                         bt_mesh_element_h elem_h;
1203                         bt_mesh_node_h node_h;
1204                         if (g_test_param.param_count != 1) {
1205                                 TC_PRT("Enter parameter first!");
1206                                 break;
1207                         }
1208                         elem_h = GUINT_TO_POINTER(strtoul(g_test_param.params[0], NULL, 16));
1209                         ret = bt_mesh_element_get_node(elem_h, &node_h);
1210                         TC_PRT("return %s\n", __bt_get_error_message(ret));
1211
1212                         if (ret == BT_ERROR_NONE)
1213                                 print_node_handle(node_h);
1214                         break;
1215                 }
1216                 case BT_MESH_UNIT_TEST_FUNCTION_MODEL_GET_ID: {
1217                         bt_mesh_model_id_s model_id;
1218                         memset(&model_id, 0x00, sizeof(bt_mesh_model_id_s));
1219                         bt_mesh_model_h mod_h;
1220                         if (g_test_param.param_count != 1) {
1221                                 TC_PRT("Enter parameter first!");
1222                                 break;
1223                         }
1224                         mod_h = GUINT_TO_POINTER(strtoul(g_test_param.params[0], NULL, 16));
1225                         ret = bt_mesh_model_get_id(mod_h, &model_id);
1226                         TC_PRT("return %s\n", __bt_get_error_message(ret));
1227                         if (ret == BT_ERROR_NONE) {
1228                                 TC_PRT("The Model ID is [0x%2.2x]", model_id.model_id);
1229                                 TC_PRT("The Company ID is [0x%2.2x]", model_id.company_id);
1230                         }
1231                         break;
1232                 }
1233                 case BT_MESH_UNIT_TEST_FUNCTION_MODEL_DESTROY: {
1234                         bt_mesh_model_h mod_h;
1235                         if (g_test_param.param_count != 1) {
1236                                 TC_PRT("Enter parameter first!");
1237                                 break;
1238                         }
1239                         mod_h = GUINT_TO_POINTER(strtoul(g_test_param.params[0], NULL, 16));
1240                         ret = bt_mesh_model_destroy(mod_h);
1241                         TC_PRT("return %s\n", __bt_get_error_message(ret));
1242                         break;
1243                 }
1244                 case BT_MESH_UNIT_TEST_FUNCTION_MODEL_GET_ELEMENT: {
1245                         bt_mesh_model_h mod_h;
1246                         bt_mesh_element_h elem_h;
1247                         if (g_test_param.param_count != 1) {
1248                                 TC_PRT("Enter parameter first!");
1249                                 break;
1250                         }
1251                         mod_h = GUINT_TO_POINTER(strtoul(g_test_param.params[0], NULL, 16));
1252                         ret = bt_mesh_model_get_element(mod_h, &elem_h);
1253                         TC_PRT("return %s\n", __bt_get_error_message(ret));
1254                         if (ret == BT_ERROR_NONE)
1255                                 print_element_handle(elem_h);
1256                         break;
1257                 }
1258                 case BT_MESH_UNIT_TEST_FUNCTION_ELEMENT_DESTROY: {
1259                         bt_mesh_element_h elem_h;
1260                         if (g_test_param.param_count != 1) {
1261                                 TC_PRT("Enter parameter first!");
1262                                 break;
1263                         }
1264                         elem_h = GUINT_TO_POINTER(strtoul(g_test_param.params[0], NULL, 16));
1265                         ret = bt_mesh_element_destroy(elem_h);
1266                         TC_PRT("return %s\n", __bt_get_error_message(ret));
1267                         break;
1268                 }
1269                 case BT_MESH_UNIT_TEST_FUNCTION_NODE_FOREACH_ELEMENTS: {
1270                         bt_mesh_node_h node_h = 0;
1271                         if (g_test_param.param_count != 1){
1272                                 TC_PRT("Enter Input parameter first.\n");
1273                                 break;
1274                         }
1275                         node_h = GUINT_TO_POINTER(strtoul(g_test_param.params[0], NULL, 16));
1276                         ret  = bt_mesh_node_foreach_element(node_h, __bt_mesh_node_foreach_elem_cb, NULL);
1277                         TC_PRT("return %s\n", __bt_get_error_message(ret));
1278                         break;
1279                 }
1280                 case BT_MESH_UNIT_TEST_FUNCTION_ELEMENT_FOREACH_MODELS: {
1281                         bt_mesh_element_h element_h = 0;
1282                         if (g_test_param.param_count != 1){
1283                                 TC_PRT("Enter Input parameter first.\n");
1284                                 break;
1285                         }
1286                         element_h = GUINT_TO_POINTER(strtoul(g_test_param.params[0], NULL, 16));
1287                         ret  = bt_mesh_element_foreach_models(element_h, __bt_mesh_elem_foreach_model_cb, NULL);
1288                         TC_PRT("return %s\n", __bt_get_error_message(ret));
1289                         break;
1290                 }
1291                 case BT_MESH_UNIT_TEST_FUNCTION_NETWORK_CREATE: {
1292                         char* network_name = "Mesh Test Network";
1293                         bt_mesh_node_h node_h;
1294                         if (g_test_param.param_count != 2) {
1295                                 TC_PRT("Enter Input parameter first.\n");
1296                                 break;
1297                         }
1298                         network_name = g_strdup(g_test_param.params[0]);
1299                         node_h = GUINT_TO_POINTER(strtoul(g_test_param.params[1], NULL, 16));
1300                         ret = bt_mesh_network_create(node_h, (const char*)network_name, &network, &token);
1301                         TC_PRT("return %s\n", __bt_get_error_message(ret));
1302                         if (ret == BT_ERROR_NONE) {
1303                                 TC_PRT("Network Created, token [%s]", token);
1304                                 print_network_handle(network);
1305                         }
1306                         g_free(network_name);
1307                         break;
1308                 }
1309                 case BT_MESH_UNIT_TEST_FUNCTION_NETWORK_CREATE_IN_LOOP: {
1310                         char* network_name = "Mesh Test Network";
1311
1312                         if (g_test_param.param_count != 1) {
1313                                 TC_PRT("Enter Input parameter first.\n");
1314                                 break;
1315                         }
1316                         int num = atoi(g_test_param.params[0]);
1317                         TC_PRT("Create [%d] Networks", num);
1318                         for (int i = 0; i < num; i++) {
1319                                 /* Create Node */
1320                                 bt_mesh_node_h node_h;
1321                                 bt_mesh_node_features_s features;
1322                                 features.features = BT_MESH_FEATURE_RELAY;
1323                                 features.features |= BT_MESH_FEATURE_LOWPOWER;
1324
1325                                 ret = bt_mesh_node_create(&features, &node_h);
1326                                 TC_PRT("return %s\n", __bt_get_error_message(ret));
1327                                 if (ret == BT_ERROR_NONE) {
1328                                         print_node_handle(node_h);
1329                                 } else {
1330                                         TC_PRT("Node Creation Failed!");
1331                                         break;
1332                                 }
1333
1334                                 /* Create Element */
1335                                 bt_mesh_element_h elem_h;
1336                                 ret = bt_mesh_node_create_element(node_h, &elem_h);
1337                                 TC_PRT("return %s\n", __bt_get_error_message(ret));
1338                                 if (ret == BT_ERROR_NONE) {
1339                                         print_element_handle(elem_h);
1340                                 } else {
1341                                         TC_PRT("Element Creation Failed!");
1342                                         break;
1343                                 }
1344
1345                                 /* Create Model */
1346                                 bt_mesh_model_h model_h;
1347                                 bt_mesh_model_id_s mod_id;
1348                                 memset(&mod_id, 0x00, sizeof(bt_mesh_model_id_s));
1349
1350                                 mod_id.model_id = 0x0003;
1351                                 mod_id.company_id = 0xFFFF;
1352                                 TC_PRT("The model_id is [0x%2.2x]\n", mod_id.model_id);
1353                                 ret = bt_mesh_element_create_model(elem_h, &mod_id, &model_h);
1354                                 TC_PRT("return %s\n", __bt_get_error_message(ret));
1355                                 if (ret == BT_ERROR_NONE) {
1356                                         print_model_handle(model_h);
1357                                 } else {
1358                                         TC_PRT("Model Creation Failed!");
1359                                         break;
1360                                 }
1361
1362                                 /* Create Network */
1363                                 network_name = g_strdup_printf("TestMeshNet%d", i);
1364                                 bt_mesh_network_h net_h;
1365                                 char *token;
1366                                 ret = bt_mesh_network_create(node_h, (const char*)network_name, &net_h, &token);
1367                                 TC_PRT("return %s\n", __bt_get_error_message(ret));
1368                                 if (ret == BT_ERROR_NONE) {
1369                                         TC_PRT("Network Created, token [%s] Network Number[%d]", token, i);
1370                                         print_network_handle(network);
1371                                 } else {
1372                                         TC_PRT("Network Creation Failed!");
1373                                         break;
1374                                 }
1375                                 g_free(network_name);
1376
1377                                 /* Destroy Network */
1378                                 ret = bt_mesh_network_destroy(net_h);
1379                                 TC_PRT("return %s\n", __bt_get_error_message(ret));
1380                                 if (ret == BT_ERROR_NONE) {
1381                                         TC_PRT("Network Destroyed Successfully!");
1382                                 } else {
1383                                         TC_PRT("Network Destroy Failed!!....break out");
1384                                         break;
1385                                 }
1386                         }
1387                         break;
1388                 }
1389                 case BT_MESH_UNIT_TEST_FUNCTION_NETWORK_DESTROY: {
1390                         bt_mesh_network_h network_h;
1391                         if (g_test_param.param_count != 1) {
1392                                 TC_PRT("Enter parameters first!");
1393                                 break;
1394                         }
1395                         network_h = GUINT_TO_POINTER(strtoul(g_test_param.params[0], NULL, 16));
1396                         ret = bt_mesh_network_destroy(network_h);
1397                         TC_PRT("return %s\n", __bt_get_error_message(ret));
1398                         break;
1399                 }
1400                 case BT_MESH_UNIT_TEST_FUNCTION_NETWORK_LOAD: {
1401                         char *token_str;
1402                         if (g_test_param.param_count != 1) {
1403                                 TC_PRT("Enter parameter first!");
1404                                 break;
1405                         }
1406                         token_str = g_strdup(g_test_param.params[0]);
1407                         ret = bt_mesh_network_load(token_str, &network);
1408                         TC_PRT("return %s\n", __bt_get_error_message(ret));
1409                         if (ret == BT_ERROR_NONE)
1410                                 print_network_handle(network);
1411                         g_free(token_str);
1412                         break;
1413                 }
1414                 case BT_MESH_UNIT_TEST_FUNCTION_NETWORK_SET_NAME: {
1415                         char* network_name="tempName";
1416                         if (g_test_param.param_count != 1) {
1417                                 TC_PRT("Enter parameter first!");
1418                                 break;
1419                         }
1420                         network_name = g_strdup(g_test_param.params[0]);
1421                         ret = bt_mesh_network_set_name(network,(const char*)network_name);
1422                         TC_PRT("return %s\n", __bt_get_error_message(ret));
1423                         g_free(network_name);
1424                         break;
1425                 }
1426                 case BT_MESH_UNIT_TEST_FUNCTION_NETWORK_GET_NAME: {
1427                         char* network_name;
1428                         ret = bt_mesh_network_get_name(network, &network_name);
1429                         TC_PRT("return %s\n", __bt_get_error_message(ret));
1430                         if (ret == BT_ERROR_NONE)
1431                                 TC_PRT("network name is [%s]", network_name);
1432                         break;
1433                 }
1434                 case BT_MESH_UNIT_TEST_FUNCTION_NETWORK_ADD_NETKEY: {
1435                         /* netkey 1*/
1436                         bt_mesh_netkey_h n_h;
1437                         ret = bt_mesh_network_add_netkey(network, &n_h);
1438                         TC_PRT("return %s\n", __bt_get_error_message(ret));
1439                         if (ret == BT_ERROR_NONE)
1440                                  print_netkey_handle(n_h);
1441                         break;
1442                 }
1443                 case BT_MESH_UNIT_TEST_FUNCTION_NETWORK_FOREACH_NETKEYS: {
1444                         ret = bt_mesh_network_foreach_netkeys(network,
1445                                         __bt_mesh_network_netkey_info_cb, NULL);
1446                         TC_PRT("return %s\n", __bt_get_error_message(ret));
1447                         break;
1448                 }
1449                 case BT_MESH_UNIT_TEST_FUNCTION_NETKEY_GET_INDEX: {
1450                         uint16_t index = 0xFFFF;
1451                         bt_mesh_netkey_h netkey_h;
1452
1453                         if (g_test_param.param_count != 1) {
1454                                 TC_PRT("Set parameter first!");
1455                                 break;
1456                         }
1457                         netkey_h = GUINT_TO_POINTER(strtoul(g_test_param.params[0], NULL, 16));
1458                         /* Get index for netkey 1 */
1459                         ret = bt_mesh_netkey_get_index(netkey_h, &index);
1460                         TC_PRT("return %s\n", __bt_get_error_message(ret));
1461                         if (ret == BT_ERROR_NONE)
1462                                 TC_PRT("The index of the netkey is: [%d]", index);
1463
1464                         break;
1465                 }
1466                 case BT_MESH_UNIT_TEST_FUNCTION_NETKEY_UPDATE: {
1467                         bt_mesh_netkey_h netkey_h;
1468
1469                         if (g_test_param.param_count != 1) {
1470                                 TC_PRT("Set parameter first!");
1471                                 break;
1472                         }
1473                         netkey_h = GUINT_TO_POINTER(strtoul(g_test_param.params[0], NULL, 16));
1474                         ret = bt_mesh_netkey_update(netkey_h);
1475                         TC_PRT("return %s\n", __bt_get_error_message(ret));
1476                         break;
1477                 }
1478                 case BT_MESH_UNIT_TEST_FUNCTION_NETKEY_DELETE: {
1479                         bt_mesh_netkey_h netkey_h;
1480
1481                         if (g_test_param.param_count != 1) {
1482                                 TC_PRT("Set parameter first!");
1483                                 break;
1484                         }
1485                         netkey_h = GUINT_TO_POINTER(strtoul(g_test_param.params[0], NULL, 16));
1486                         ret = bt_mesh_netkey_delete(netkey_h);
1487                         TC_PRT("return %s\n", __bt_get_error_message(ret));
1488                         if (ret == BT_ERROR_NONE)
1489                                 TC_PRT("netkey is deleted");
1490                         break;
1491                 }
1492                 case BT_MESH_UNIT_TEST_FUNCTION_NETKEY_ADD_APPKEY: {
1493                         bt_mesh_netkey_h netkey_h;
1494                         bt_mesh_appkey_h appkey_h;
1495
1496                         if (g_test_param.param_count != 1) {
1497                                 TC_PRT("Set parameter first!");
1498                                 break;
1499                         }
1500                         netkey_h = GUINT_TO_POINTER(strtoul(g_test_param.params[0], NULL, 16));
1501                         ret = bt_mesh_netkey_add_appkey(netkey_h, &appkey_h);
1502                         TC_PRT("return %s\n", __bt_get_error_message(ret));
1503                         if (ret == BT_ERROR_NONE)
1504                                 print_appkey_handle(appkey_h);
1505                         break;
1506                 }
1507                 case BT_MESH_UNIT_TEST_FUNCTION_NETKEY_FOREACH_APPKEYS: {
1508                         /* Get all appkeys for NetKey 1 */
1509                         bt_mesh_netkey_h netkey_h;
1510
1511                         if (g_test_param.param_count != 1) {
1512                                 TC_PRT("Set parameter first!");
1513                                 break;
1514                         }
1515                         netkey_h = GUINT_TO_POINTER(strtoul(g_test_param.params[0], NULL, 16));
1516                         ret = bt_mesh_netkey_foreach_appkeys(netkey_h, __bt_mesh_appkey_info_cb, NULL);
1517                         TC_PRT("return %s\n", __bt_get_error_message(ret));
1518
1519                         break;
1520                 }
1521                 case BT_MESH_UNIT_TEST_FUNCTION_APPKEY_GET_INDEX: {
1522                         uint16_t index = 0xFFFF;
1523                         bt_mesh_appkey_h appkey_h;
1524
1525                         if (g_test_param.param_count != 1) {
1526                                 TC_PRT("Set parameter first!");
1527                                 break;
1528                         }
1529                         appkey_h = GUINT_TO_POINTER(strtoul(g_test_param.params[0], NULL, 16));
1530                         /* Get appkey index for appkey 1 */
1531                         ret = bt_mesh_appkey_get_index(appkey_h, &index);
1532                         TC_PRT("return %s\n", __bt_get_error_message(ret));
1533                         if (ret == BT_ERROR_NONE)
1534                                 TC_PRT("The index of the appkey is: [%d]", index);
1535                         break;
1536                 }
1537                 case BT_MESH_UNIT_TEST_FUNCTION_APPKEY_UPDATE: {
1538                         bt_mesh_appkey_h appkey_h;
1539
1540                         if (g_test_param.param_count != 1) {
1541                                 TC_PRT("Set parameter first!");
1542                                 break;
1543                         }
1544                         appkey_h = GUINT_TO_POINTER(strtoul(g_test_param.params[0], NULL, 16));
1545                         ret = bt_mesh_appkey_update(appkey_h);
1546                         TC_PRT("return %s\n", __bt_get_error_message(ret));
1547                         break;
1548                 }
1549                 case BT_MESH_UNIT_TEST_FUNCTION_APPKEY_DELETE: {
1550                         bt_mesh_appkey_h appkey_h;
1551
1552                         if (g_test_param.param_count != 1) {
1553                                 TC_PRT("Set parameter first!");
1554                                 break;
1555                         }
1556                         appkey_h = GUINT_TO_POINTER(strtoul(g_test_param.params[0], NULL, 16));
1557                         ret = bt_mesh_appkey_delete(appkey_h);
1558                         TC_PRT("return %s\n", __bt_get_error_message(ret));
1559                         if (ret == BT_ERROR_NONE)
1560                                 TC_PRT("appkey is deleted");
1561                         break;
1562                 }
1563                 case BT_MESH_UNIT_TEST_FUNCTION_NETWORK_FOREACH_DEVICES: {
1564                         ret = bt_mesh_network_foreach_devices(network, __bt_mesh_network_device_info_cb, NULL);
1565                         TC_PRT("return %s\n", __bt_get_error_message(ret));
1566                         break;
1567                 }
1568                 case BT_MESH_UNIT_TEST_FUNCTION_NETWORK_CREATE_GROUP: {
1569                         uint16_t group_addr = 0xc001;
1570                         bt_mesh_group_h group_h;
1571                         if (g_test_param.param_count != 1) {
1572                                 TC_PRT("Enter parameter first!!\n");
1573                                 break;
1574                         }
1575                         group_addr = strtoul(g_test_param.params[0], NULL, 16);
1576                         TC_PRT("Group addrrss [0x%2.2x]", group_addr);
1577                         ret = bt_mesh_network_create_group(network, group_addr, &group_h);
1578                         TC_PRT("return %s\n", __bt_get_error_message(ret));
1579                         if (ret == BT_ERROR_NONE)
1580                                 print_group_handle(group_h);
1581                         break;
1582                 }
1583                 case BT_MESH_UNIT_TEST_FUNCTION_NETWORK_CREATE_VIRTUAL_GROUP: {
1584                         bt_mesh_group_h group_h;
1585                         ret = bt_mesh_network_create_virtual_group(network, &group_h);
1586                         TC_PRT("return %s\n", __bt_get_error_message(ret));
1587                         if (ret == BT_ERROR_NONE)
1588                                 print_group_handle(group_h);
1589                         break;
1590                 }
1591                 case BT_MESH_UNIT_TEST_FUNCTION_NETWORK_REMOVE_GROUP: {
1592                         bt_mesh_group_h group_h;
1593                         if (g_test_param.param_count != 1) {
1594                                 TC_PRT("Enter parameter first!!\n");
1595                                 break;
1596                         }
1597                         group_h = GUINT_TO_POINTER(strtoul(g_test_param.params[0], NULL, 16));
1598                         ret = bt_mesh_network_remove_group(group_h);
1599                         TC_PRT("return %s\n", __bt_get_error_message(ret));
1600                         break;
1601                 }
1602                 case BT_MESH_UNIT_TEST_FUNCTION_NETWORK_FOREACH_GROUPS: {
1603                         ret = bt_mesh_network_foreach_groups(network,
1604                                         __bt_mesh_network_group_info_cb, NULL);
1605                         TC_PRT("return %s\n", __bt_get_error_message(ret));
1606                         break;
1607                 }
1608                 case BT_MESH_UNIT_TEST_FUNCTION_NETWORK_UNPROVISIONED_DEVICE_SCAN: {
1609                         bt_mesh_scan_params_s scan_params;
1610                         memset(&scan_params, 0x00, sizeof(bt_mesh_scan_params_s));
1611                         if(g_test_param.param_count != 1) {
1612                                 TC_PRT("Enter Input parameter first.\n");
1613                                 break;
1614                         }
1615                         scan_params.seconds = strtoul(g_test_param.params[0], NULL, 16);
1616                         TC_PRT("The scan is set for [%u] seconds", scan_params.seconds);
1617                         ret = bt_mesh_network_unprovisioned_device_scan(network, &scan_params,
1618                                 __bt_mesh_network_scan_unprovisioned_device_result_cb, NULL);
1619                         TC_PRT("return %s\n", __bt_get_error_message(ret));
1620                         break;
1621                 }
1622                 case BT_MESH_UNIT_TEST_FUNCTION_STOP_UNPROVISIONED_DEVICE_SCAN: {
1623                         ret = bt_mesh_stop_unprovisioned_device_scan(network);
1624                         TC_PRT("return %s\n", __bt_get_error_message(ret));
1625                         if (ret == BT_ERROR_NONE)
1626                                 TC_PRT("Device SCAN : STOPPED");
1627                         break;
1628                 }
1629                 case BT_MESH_UNIT_TEST_FUNCTION_NETWORK_PROVISION_DEVICE: {
1630                         const char *dev_uuid = "abababababababababababababababab";
1631                         if(g_test_param.param_count != 1) {
1632                                 TC_PRT("Enter Input parameter first.\n");
1633                                 break;
1634                         }
1635                                 dev_uuid = g_test_param.params[0];
1636                         TC_PRT("The dev_uuid is [%s]\n",dev_uuid);
1637                         ret = bt_mesh_network_provision_device(network, dev_uuid,
1638                                 __bt_mesh_network_device_provision_cb, NULL);
1639                         TC_PRT("return %s\n", __bt_get_error_message(ret));
1640                         break;
1641                 }
1642                 case BT_MESH_UNIT_TEST_FUNCTION_NETWORK_AUTHENTICATION_SET_REQUEST_CB: {
1643                         ret =  bt_mesh_authentication_set_request_cb(
1644                                         __bt_mesh_authentication_request_cb, NULL);
1645                         TC_PRT("return %s\n", __bt_get_error_message(ret));
1646                         break;
1647                 }
1648                 case  BT_MESH_UNIT_TEST_FUNCTION_MESH_AUTHENTICATION_REPLY: {
1649                         char* value;
1650                         int len;
1651                         bool auth_reply;
1652                         if(g_test_param.param_count !=2){
1653                                 TC_PRT("Enter Input parameter first.\n");
1654                                 break;
1655                         }
1656                         len = strlen(g_test_param.params[0]);
1657                         value = g_malloc0(len+1);
1658                         g_strlcpy(value, g_test_param.params[0], len+1);
1659                         auth_reply = atoi(g_test_param.params[1]);
1660                         TC_PRT("\nauth_value is [%s]\n", value);
1661                         TC_PRT("auth_reply is [%d]\n", auth_reply);
1662                         TC_PRT("auth_type is [%d]\n", request_type);
1663                         ret = bt_mesh_authentication_reply(request_type, (const char*)value, auth_reply);
1664                         TC_PRT("return %s\n", __bt_get_error_message(ret));
1665                         break;
1666                 }
1667                 case BT_MESH_UNIT_TEST_FUNCTION_NETWORK_SET_PROVISIONING_CAPABILITIES: {
1668                         bt_mesh_provisioner_capabilities_s capabilities;
1669                         if(g_test_param.param_count !=4) {
1670                                 TC_PRT("Enter Input parameter first.");
1671                                 break;
1672                         }
1673                         capabilities.public_oob = atoi(g_test_param.params[0]);
1674                         capabilities.static_oob = atoi(g_test_param.params[1]);
1675                         capabilities.out_oob = (int)strtol(g_test_param.params[2], NULL, 16);
1676                         capabilities.in_oob = (int)strtol(g_test_param.params[3], NULL, 16);
1677                         TC_PRT("CAP: PUBLIC OOB [%d]", capabilities.public_oob);
1678                         TC_PRT("CAP: STATIC OOB [%d]", capabilities.static_oob);
1679                         TC_PRT("CAP: OUT OOB [%d]", capabilities.out_oob);
1680                         TC_PRT("CAP: IN OOB [%d]", capabilities.in_oob);
1681                         ret = bt_mesh_network_set_provisioning_capabilities(network, &capabilities);
1682                         TC_PRT("return %s\n", __bt_get_error_message(ret));
1683                         break;
1684                 }
1685                 case BT_MESH_UNIT_TEST_FUNCTION_NETWORK_GET_PROVISIONING_CAPABILITIES: {
1686                         // TODO: need to implement
1687                         break;
1688                 }
1689                 case BT_MESH_UNIT_TEST_FUNCTION_ACTIVATE_FLAG_TO_SET_PARAMETERS: {
1690                         need_to_set_params = true;
1691                         TC_PRT("Select the function again");
1692                         break;
1693                 }
1694                 default:
1695                         break;
1696                 }
1697                         __bt_free_test_param(&g_test_param);
1698                 break;
1699         }
1700         case BT_MESH_UNIT_TEST_TABLE_CONFIGURATION: {
1701                 switch (test_id) {
1702                 case BT_MESH_UNIT_TEST_FUNCTION_MESH_NETWORK_DISCOVER_NODE: {
1703                         char* dev_uu = "tempName";
1704                         if (g_test_param.param_count > 0) {
1705                                 dev_uu = g_strdup(g_test_param.params[0]);
1706                         } else {
1707                                 TC_PRT("Set Input parameter first!");
1708                                 break;
1709                         }
1710                         ret = bt_mesh_network_discover_node(network, (const char*)dev_uu,
1711                                         __bt_mesh_node_discover_status_cb, NULL);
1712                         TC_PRT("return %s\n", __bt_get_error_message(ret));
1713                         break;
1714                 }
1715                 case BT_MESH_UNIT_TEST_FUNCTION_NODE_RESET: {
1716                         // TODO: need to implement
1717                         break;
1718                 }
1719                 case BT_MESH_UNIT_TEST_FUNCTION_NODE_GET_FEATURES: {
1720                         bt_mesh_node_h node_h = 0;
1721                         if (g_test_param.param_count != 1) {
1722                                 TC_PRT("Set Input parameter first!");
1723                                 break;
1724                         }
1725                         node_h = GUINT_TO_POINTER(strtoul(g_test_param.params[0], NULL, 16));
1726                         ret = bt_mesh_node_get_features(node_h, __bt_mesh_node_features_cb, NULL);
1727                         TC_PRT("return %s\n", __bt_get_error_message(ret));
1728                         break;
1729                 }
1730                 case BT_MESH_UNIT_TEST_FUNCTION_NODE_GET_NETKEYS: {
1731                         bt_mesh_node_h node_h = 0;
1732                         if (g_test_param.param_count != 1) {
1733                                 TC_PRT("Set Input parameter first!");
1734                                 break;
1735                         }
1736                         node_h = GUINT_TO_POINTER(strtoul(g_test_param.params[0], NULL, 16));
1737                         ret = bt_mesh_node_foreach_netkeys(node_h, __bt_mesh_node_foreach_netkeys_cb, NULL);
1738                         TC_PRT("return %s\n", __bt_get_error_message(ret));
1739                         break;
1740                 }
1741                 case BT_MESH_UNIT_TEST_FUNCTION_NODE_GET_APPKEYS: {
1742                         bt_mesh_node_h node_h = 0;
1743                         bt_mesh_netkey_h netkey_h = 0;
1744                         if (g_test_param.param_count != 2) {
1745                                 TC_PRT("Set Input parameter first!");
1746                                 break;
1747                         }
1748                         node_h = GUINT_TO_POINTER(strtoul(g_test_param.params[0], NULL, 16));
1749                         netkey_h = GUINT_TO_POINTER(strtoul(g_test_param.params[1], NULL, 16));
1750
1751                         ret = bt_mesh_node_foreach_appkeys(node_h, netkey_h,
1752                                         __bt_mesh_node_foreach_appkeys_cb, NULL);
1753                         TC_PRT("return %s\n", __bt_get_error_message(ret));
1754                         break;
1755                 }
1756                 case BT_MESH_UNIT_TEST_FUNCTION_NODE_GET_TTL: {
1757                         bt_mesh_node_h node_h = 0;
1758                         if (g_test_param.param_count != 1) {
1759                                 TC_PRT("Set Input parameter first!");
1760                                 break;
1761                         }
1762                         node_h = GUINT_TO_POINTER(strtoul(g_test_param.params[0], NULL, 16));
1763                         ret = bt_mesh_node_get_ttl(node_h, __bt_mesh_node_ttl_cb, NULL);
1764                         TC_PRT("return %s\n", __bt_get_error_message(ret));
1765                         break;
1766                 }
1767                 case BT_MESH_UNIT_TEST_FUNCTION_NODE_SET_TTL: {
1768                         bt_mesh_node_h node_h = 0;
1769                         int ttl = 120;
1770                         if (g_test_param.param_count != 2) {
1771                                 TC_PRT("Set Input parameter first!");
1772                                 break;
1773                         }
1774                         node_h = GUINT_TO_POINTER(strtoul(g_test_param.params[0], NULL, 16));
1775                         ttl = atoi(g_test_param.params[1]);
1776
1777                         ret = bt_mesh_node_set_ttl(node_h, (uint8_t) ttl, __bt_mesh_node_ttl_cb, NULL);
1778                         TC_PRT("return %s\n", __bt_get_error_message(ret));
1779                         break;
1780                 }
1781                 case BT_MESH_UNIT_TEST_FUNCTION_NODE_CONFIGURE_NETKEY: {
1782                         bt_mesh_node_h node_h = 0;
1783                         bt_mesh_netkey_h netkey_h = 0;
1784                         bt_mesh_node_key_configuration_e config = 0;
1785                         if (g_test_param.param_count != 3) {
1786                                 TC_PRT("Set Input parameter first!");
1787                                 break;
1788                         }
1789                         node_h = GUINT_TO_POINTER(strtoul(g_test_param.params[0], NULL, 16));
1790                         netkey_h = GUINT_TO_POINTER(strtoul(g_test_param.params[1], NULL, 16));
1791                         config = atoi(g_test_param.params[2]);
1792
1793                         ret = bt_mesh_node_configure_netkey(node_h, config, netkey_h,
1794                                 __bt_mesh_node_configure_netkey_cb, NULL);
1795                         TC_PRT("return %s\n", __bt_get_error_message(ret));
1796                         break;
1797                 }
1798                 case BT_MESH_UNIT_TEST_FUNCTION_NODE_CONFIGURE_APPKEY: {
1799                         bt_mesh_node_h node_h = 0;
1800                         bt_mesh_appkey_h appkey_h = 0;
1801                         bt_mesh_node_key_configuration_e config = 0;
1802                         if (g_test_param.param_count != 3) {
1803                                 TC_PRT("Set Input parameter first!");
1804                                 break;
1805                         }
1806                         node_h = GUINT_TO_POINTER(strtoul(g_test_param.params[0], NULL, 16));
1807                         appkey_h = GUINT_TO_POINTER(strtoul(g_test_param.params[1], NULL, 16));
1808                         config = atoi(g_test_param.params[2]);
1809
1810                         ret = bt_mesh_node_configure_appkey(node_h, config, appkey_h,
1811                                 __bt_mesh_node_configure_appkey_cb, NULL);
1812                         TC_PRT("return %s\n", __bt_get_error_message(ret));
1813                         break;
1814                 }
1815                 case BT_MESH_UNIT_TEST_FUNCTION_MODEL_BIND_APPKEY: {
1816                         bt_mesh_model_h model_h = 0;
1817                         bt_mesh_appkey_h appkey_h = 0;
1818                         if (g_test_param.param_count != 2) {
1819                                 TC_PRT("Set Input parameter first!");
1820                                 break;
1821                         }
1822                         model_h = GUINT_TO_POINTER(strtoul(g_test_param.params[0], NULL, 16));
1823                         appkey_h = GUINT_TO_POINTER(strtoul(g_test_param.params[1], NULL, 16));
1824
1825                         ret = bt_mesh_model_bind_appkey(model_h, appkey_h, __bt_mesh_model_bind_cb, NULL);
1826                         TC_PRT("return %s\n", __bt_get_error_message(ret));
1827                         break;
1828                 }
1829                 case BT_MESH_UNIT_TEST_FUNCTION_MODEL_UNBIND_APPKEY: {
1830                         bt_mesh_model_h model_h = 0;
1831                         bt_mesh_appkey_h appkey_h = 0;
1832                         if (g_test_param.param_count != 2) {
1833                                 TC_PRT("Set Input parameter first!");
1834                                 break;
1835                         }
1836                         model_h = GUINT_TO_POINTER(strtoul(g_test_param.params[0], NULL, 16));
1837                         appkey_h = GUINT_TO_POINTER(strtoul(g_test_param.params[1], NULL, 16));
1838
1839                         ret = bt_mesh_model_unbind_appkey(model_h, appkey_h, __bt_mesh_model_unbind_cb, NULL);
1840                         TC_PRT("return %s\n", __bt_get_error_message(ret));
1841                         break;
1842                 }
1843                 case BT_MESH_UNIT_TEST_FUNCTION_MODEL_GET_APPKEY_LIST: {
1844                         bt_mesh_model_h model_h = 0;
1845                         if (g_test_param.param_count != 1) {
1846                                 TC_PRT("Set Input parameter first!");
1847                                 break;
1848                         }
1849                         model_h = GUINT_TO_POINTER(strtoul(g_test_param.params[0], NULL, 16));
1850
1851                         ret = bt_mesh_model_get_appkey_list(model_h, __bt_mesh_model_appkey_list_cb, NULL);
1852                         TC_PRT("return %s\n", __bt_get_error_message(ret));
1853                         break;
1854                 }
1855                 case BT_MESH_UNIT_TEST_FUNCTION_MODEL_CONFIGURE_GROUP_SUBSCRIPTION: {
1856                         bt_mesh_model_h model_h = 0;
1857                         bt_mesh_group_h group_h = 0;
1858                         bt_mesh_model_subscription_op_e op = BT_MESH_MODEL_SUBSCRIPTION_ADD;
1859
1860                         if (g_test_param.param_count != 3) {
1861                                 TC_PRT("Set Input parameter first!");
1862                                 break;
1863                         }
1864                         model_h = GUINT_TO_POINTER(strtoul(g_test_param.params[0], NULL, 16));
1865                         op = atoi(g_test_param.params[1]);
1866                         group_h = GUINT_TO_POINTER(strtoul(g_test_param.params[2], NULL, 16));
1867
1868                         ret = bt_mesh_model_configure_group_subscription(op, model_h, group_h,
1869                                                                 __bt_mesh_model_subscription_op_cb, NULL);
1870                         TC_PRT("return %s\n", __bt_get_error_message(ret));
1871                         break;
1872                 }
1873                 case BT_MESH_UNIT_TEST_FUNCTION_MODEL_CONFIGURE_VIRTUAL_GROUP_SUBSCRIPTION: {
1874                         bt_mesh_model_h model_h = 0;
1875                         bt_mesh_group_h group_h = 0;
1876                         bt_mesh_model_subscription_op_e op = BT_MESH_MODEL_SUBSCRIPTION_ADD;
1877
1878                         if (g_test_param.param_count != 3) {
1879                                 TC_PRT("Set Input parameter first!");
1880                                 break;
1881                         }
1882                         model_h = GUINT_TO_POINTER(strtoul(g_test_param.params[0], NULL, 16));
1883                         op = atoi(g_test_param.params[1]);
1884                         group_h = GUINT_TO_POINTER(strtoul(g_test_param.params[2], NULL, 16));
1885
1886                         ret = bt_mesh_model_configure_virtual_group_subscription(op, model_h, group_h,
1887                                         __bt_mesh_model_subscription_op_cb, NULL);
1888                         TC_PRT("return %s\n", __bt_get_error_message(ret));
1889                         break;
1890                 }
1891                 case BT_MESH_UNIT_TEST_FUNCTION_MODEL_GET_SUBSCRIPTION_LIST: {
1892                         bt_mesh_model_h model_h = 0;
1893
1894                         if (g_test_param.param_count != 1) {
1895                                 TC_PRT("Set Input parameter first!");
1896                                 break;
1897                         }
1898                         model_h = GUINT_TO_POINTER(strtoul(g_test_param.params[0], NULL, 16));
1899
1900                         ret = bt_mesh_model_get_subscription_list(model_h, __bt_mesh_model_subscription_list_cb, NULL);
1901                         TC_PRT("return %s\n", __bt_get_error_message(ret));
1902                         break;
1903                 }
1904                 case BT_MESH_UNIT_TEST_FUNCTION_MODEL_SET_PUBLICATION: {
1905                         bt_mesh_model_h model_h = 0;
1906                         bt_mesh_model_h appkey_h = 0;
1907                         bt_mesh_group_h group_h = 0;
1908                         bt_mesh_model_pub_params_s param;
1909
1910                         memset(&param, 0x00, sizeof(bt_mesh_model_pub_params_s));
1911
1912                         if (g_test_param.param_count != 3) {
1913                                 TC_PRT("Set Input parameter first!");
1914                                 break;
1915                         }
1916                         model_h = GUINT_TO_POINTER(strtoul(g_test_param.params[0], NULL, 16));
1917                         appkey_h = GUINT_TO_POINTER(strtoul(g_test_param.params[1], NULL, 16));
1918                         group_h = GUINT_TO_POINTER(strtoul(g_test_param.params[2], NULL, 16));
1919
1920                         param.ttl = 120;
1921                         param.num_steps =  10;
1922                         param.per_res = BT_MESH_PUBLICATION_STEP_RES_1_SECOND;
1923                         param.retrans_cnt = BT_MESH_MAX_PUBISH_RETRANSMIT_COUNT;
1924                         param.retrans_step = BT_MESH_MAX_PUBISH_RETRANSMIT_INTERVAL_STEPS;
1925
1926                         ret = bt_mesh_model_set_publication(model_h, appkey_h, group_h, &param,
1927                                                         __bt_mesh_model_publication_status_cb, NULL);
1928                         TC_PRT("return %s\n", __bt_get_error_message(ret));
1929                         break;
1930                 }
1931                 case BT_MESH_UNIT_TEST_FUNCTION_MODEL_GET_PUBLICATION: {
1932                         bt_mesh_model_h model_h = 0;
1933
1934                         if (g_test_param.param_count != 1) {
1935                                 TC_PRT("Set Input parameter first!");
1936                                 break;
1937                         }
1938                         model_h = GUINT_TO_POINTER(strtoul(g_test_param.params[0], NULL, 16));
1939
1940                         ret = bt_mesh_model_get_publication(model_h, __bt_mesh_model_publication_status_cb,  NULL);
1941                         TC_PRT("return %s\n", __bt_get_error_message(ret));
1942                         break;
1943                 }
1944                 case BT_MESH_UNIT_TEST_FUNCTION_MODEL_SEND_MSG: {
1945                         bt_mesh_model_h model_h = NULL;
1946                         bt_mesh_appkey_h appkey_h = NULL;
1947                         bt_mesh_model_msg_params_s *msg_params = NULL;
1948                         if (g_test_param.param_count != 4) {
1949                                 TC_PRT("Set Input parameter first!");
1950                                 break;
1951                         }
1952                         model_h = GUINT_TO_POINTER(strtoul(g_test_param.params[0], NULL, 16));
1953                         appkey_h = GUINT_TO_POINTER(strtoul(g_test_param.params[1], NULL, 16));
1954                         msg_params = g_malloc0(sizeof(bt_mesh_model_msg_params_s));
1955                         msg_params->opcode = strtoul(g_test_param.params[2], NULL, 16);
1956                         msg_params->data = "0101010101010101010101010100101010";
1957                         msg_params->data = g_strdup(g_test_param.params[3]);
1958                         TC_PRT("Input parameters");
1959                         print_model_handle(model_h);
1960                         print_appkey_handle(appkey_h);
1961                         TC_PRT("opcode 0X%4.4X", msg_params->opcode);
1962                         TC_PRT("Message to be sent %s", msg_params->data);
1963                         ret = bt_mesh_model_send_msg(model_h, appkey_h, msg_params,
1964                                 __bt_mesh_model_msg_cb, NULL);
1965                         TC_PRT("return %s\n", __bt_get_error_message(ret));
1966                         break;
1967                 }
1968                 case BT_MESH_UNIT_TEST_FUNCTION_APPKEY_GET_NETKEY: {
1969                         bt_mesh_appkey_h appkey_h = 0;
1970                         bt_mesh_netkey_h netkey_h;
1971
1972                         if (g_test_param.param_count != 1) {
1973                                 TC_PRT("Set Input parameter first!");
1974                                 break;
1975                         }
1976                         appkey_h = GUINT_TO_POINTER(strtoul(g_test_param.params[0], NULL, 16));
1977
1978                         ret = bt_mesh_appkey_get_netkey(appkey_h, &netkey_h);
1979                         TC_PRT("return %s\n", __bt_get_error_message(ret));
1980                         if (ret == BT_ERROR_NONE)
1981                                 print_netkey_handle(netkey_h);
1982                         break;
1983                 }
1984                 case BT_MESH_UNIT_TEST_FUNCTION_ACTIVATE_FLAG_TO_SET_PARAMETERS: {
1985                         need_to_set_params = true;
1986                         TC_PRT("Select the function again");
1987                         break;
1988                 }
1989                 default:
1990                         break;
1991                 }
1992                         __bt_free_test_param(&g_test_param);
1993                 break;
1994         }
1995         default:
1996                 break;
1997         }
1998         return 0;
1999 }
2000
2001
2002 static gboolean key_event_cb(GIOChannel *chan,
2003                 GIOCondition cond,
2004                 gpointer data)
2005 {
2006         char buf[BUFFER_LEN] = { 0 };
2007
2008 #ifdef ARCH64
2009         unsigned long len = 0;
2010 #else
2011         unsigned int len = 0;
2012 #endif
2013         int test_id;
2014         bool is_call_api = false;
2015
2016         memset(buf, 0, sizeof(buf));
2017
2018         if (g_io_channel_read_chars(chan, buf, sizeof(buf),
2019                                 &len, NULL) == G_IO_STATUS_ERROR) {
2020                 TC_PRT("IO Channel read error");
2021                 return FALSE;
2022         }
2023
2024         if (need_to_set_params == true) {
2025                 if (g_test_id == -1) {
2026                         test_id = atoi(buf);
2027                         g_test_id = test_id;
2028                 }
2029                 test_set_params(g_test_id, buf);
2030                 return TRUE;
2031         } else {
2032                 TC_PRT("%s", buf);
2033                 test_id = atoi(buf);
2034
2035                 g_test_id = -1;
2036                 need_to_set_params = false;
2037         }
2038
2039         if (current_tc_table == BT_MESH_UNIT_TEST_TABLE_MAIN) {
2040                 if (test_id == 0)
2041                         current_tc_table = BT_MESH_UNIT_TEST_TABLE_MAIN;
2042                 else if(test_id >= BT_MESH_UNIT_TEST_TABLE_NETWORK
2043                         && test_id <= BT_MESH_UNIT_TEST_TABLE_CONFIGURATION) {
2044                         current_tc_table = test_id;
2045                 } else if (test_id > BT_MESH_UNIT_TEST_TABLE_CONFIGURATION
2046                         && test_id < BT_MESH_UNIT_TEST_TABLE_FINISH) {
2047                         current_tc_table = BT_MESH_UNIT_TEST_TABLE_MAIN;
2048                 } else {
2049                         is_call_api = true;
2050                 }
2051         }
2052
2053         else {
2054                 if (buf[0] == '0' && buf[2] == 0) {
2055                         current_tc_table = BT_MESH_UNIT_TEST_TABLE_MAIN;
2056                 }
2057 #if 0
2058                 if(test_id == 0) {
2059                         current_tc_table = BT_MESH_UNIT_TEST_TABLE_MAIN;
2060                 }
2061 #endif
2062                 else {
2063                         is_call_api = true;
2064                 }
2065         }
2066
2067         tc_usage_print();
2068         if (test_id && is_call_api) {
2069 #ifdef ARCH64
2070                 g_idle_add(test_input_callback, (void *)(uintptr_t)test_id);
2071 #else
2072                 g_idle_add(test_input_callback, (void *)test_id);
2073 #endif
2074         }
2075         return TRUE;
2076 }
2077
2078 void sig_handler(int signo)
2079 {
2080         if (signo == SIGINT) {
2081                 bt_mesh_deinitialize();
2082                 exit(0);
2083         }
2084 }
2085
2086 int main()
2087 {
2088         GIOChannel *key_io;
2089
2090         current_tc_table = BT_MESH_UNIT_TEST_TABLE_MAIN;
2091
2092         key_io = g_io_channel_unix_new(fileno(stdin));
2093
2094         g_io_channel_set_encoding(key_io, NULL, NULL);
2095         g_io_channel_set_flags(key_io, G_IO_FLAG_NONBLOCK, NULL);
2096
2097         g_io_add_watch(key_io, G_IO_IN | G_IO_HUP | G_IO_ERR | G_IO_NVAL,
2098                         key_event_cb, NULL);
2099
2100         g_io_channel_unref(key_io);
2101
2102         main_loop = g_main_loop_new(NULL, FALSE);
2103
2104         if (signal(SIGINT, sig_handler) == SIG_ERR)
2105                 TC_PRT("\n can't catch SIGINT\n");
2106
2107         g_main_loop_run(main_loop);
2108
2109         bt_mesh_deinitialize();
2110
2111         return 0;
2112 }