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