fdee8912921a149db05b42b7f9d1dce01a26243f
[platform/core/connectivity/bluetooth-frwk.git] / test / bluetooth-frwk-test.c
1 /*
2  * Bluetooth-frwk
3  *
4  * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
5  *
6  * Contact:  Hocheol Seo <hocheol.seo@samsung.com>
7  *               Girishashok Joshi <girish.joshi@samsung.com>
8  *               Chanyeol Park <chanyeol.park@samsung.com>
9  *
10  * Licensed under the Apache License, Version 2.0 (the "License");
11  * you may not use this file except in compliance with the License.
12  * You may obtain a copy of the License at
13  *
14  *              http://www.apache.org/licenses/LICENSE-2.0
15  *
16  * Unless required by applicable law or agreed to in writing, software
17  * distributed under the License is distributed on an "AS IS" BASIS,
18  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
19  * See the License for the specific language governing permissions and
20  * limitations under the License.
21  *
22  */
23
24 /**
25  * @file       bluetooth-frwk-test.c
26  * @brief      This is the source file for bluetooth framework test suite.
27  */
28
29 #include <stdio.h>
30 #include <string.h>
31 #include <glib.h>
32 #include <dbus/dbus-glib.h>
33 #include <pthread.h>
34
35 #include "bluetooth-api.h"
36 #include "bluetooth-hid-api.h"
37 #include "bluetooth-audio-api.h"
38
39
40 bluetooth_device_address_t searched_device = {{0}};
41
42 #define TC_TIMEOUT      30000
43
44 #define BT_DEFAULT_DEV_NAME "SLP-BT-TEST-TARGET"
45 #define DISCOVER_TIMEOUT 20
46 #define DISCOVER_CANCEL_INTERVAL 3
47
48 #define PRT(format, args...) printf("%s:%d() "format, __FUNCTION__, __LINE__, ##args)
49 #define TC_PRT(format, args...) PRT(format"\n", ##args)
50
51 #define TC_PASS 1
52 #define TC_FAIL 0
53 int client_fd = 0;
54 int server_fd = 0;
55 int g_ret_client_fd1 = -1, g_ret_client_fd2 = -1;
56 const char *g_hdp_app_handle1 =  NULL;
57 const char *g_hdp_app_handle2 =  NULL;
58
59 char *svc_obj_path = NULL;
60 char *char_obj_path = NULL;
61 char *desc_obj_path = NULL;
62
63 int selection;
64 int hdp_manual_mode =  1;
65 const char * rfcomm_test_uuid_spp ="00001101-0000-1000-8000-00805F9B34FB";
66 const char * rfcomm_test_uuid_dun = "00001103-0000-1000-8000-00805F9B34FB";
67 const char * rfcomm_test_uuid_custom ="26b2831b-2c2d-4f9c-914a-c0ab142351b7";
68
69
70 GMainLoop *main_loop = NULL;
71 static int timeout_status = 0;
72
73 int current_transfer_id = 0;
74
75 typedef struct {
76         bluetooth_device_address_t address;
77         bt_oob_data_t oob_data;
78 } oob_data_t;
79
80 oob_data_t g_local_oob_data;
81 oob_data_t g_remote_oob_data;
82
83
84 typedef struct
85 {
86         const char *tc_name;
87         int tc_code;
88 } tc_table_t;
89
90 void bt_event_callback(int event, bluetooth_event_param_t* param, void *user_data);
91 void bt_hid_event_callback(int event, hid_event_param_t* param, void *user_data);
92 void bt_audio_event_callback(int event, bt_audio_event_param_t* param, void *user_data);
93
94
95 tc_table_t tc_table[] =
96 {
97         {"bluetooth_register_callback"          , 1},
98         {"bluetooth_unregister_callback"        , 2},
99         {"bluetooth_enable_adapter"             , 3},
100         {"bluetooth_disable_adapter"            , 4},
101         {"bluetooth_check_adapter"              , 5},
102         {"bluetooth_get_local_address"          , 6},
103         {"bluetooth_get_local_name"             , 7},
104         {"bluetooth_set_local_name"             , 8},
105         {"bluetooth_get_local_version"          , 90},
106         {"bluetooth_is_service_used"            , 9},
107         {"bluetooth_get_discoverable_mode"      , 10},
108         {"bluetooth_set_discoverable_mode(CONNECTABLE)"                 , 11},
109         {"bluetooth_set_discoverable_mode(GENERAL_DISCOVERABLE)"        , 12},
110         {"bluetooth_set_discoverable_mode(TIME_LIMITED_DISCOVERABLE)"   , 13},
111         {"bluetooth_start_discovery"            , 14},
112         {"bluetooth_cancel_discovery"           , 15},
113         {"bluetooth_is_discovering"             , 16},
114         {"bluetooth_get_bonded_device_list"     , 17},
115         {"bluetooth_bond_device"                , 18},
116         {"bluetooth_cancel_bonding"             , 19},
117         {"bluetooth_unbond_device"      , 20},
118         {"bluetooth_get_bonded_device"  , 21},
119         {"bluetooth_set_alias"  , 22},
120         {"bluetooth_authorize_device (TRUE)"    , 23},
121         {"bluetooth_authorize_device (FALSE)"   , 24},
122         {"bluetooth_search_service"     , 25},
123         {"bluetooth_cancel_service_search"      , 26},
124         {"bluetooth_is_device_connected"        , 27},
125         {"bluetooth_reset_adapter"              , 28},
126         {"bluetooth_set_manufacturer_data" , 91},
127
128         {"bluetooth_audio_init" , 29},
129         {"bluetooth_audio_deinit" , 30},
130         {"bluetooth_audio_connect"      , 31},
131         {"bluetooth_audio_disconnect"   , 32},
132         {"bluetooth_ag_connect" , 33},
133         {"bluetooth_ag_disconnect" , 34},
134         {"bluetooth_av_connect" , 35},
135         {"bluetooth_av_disconnect"      , 36},
136         {"bluetooth_ag_get_headset_volume" , 37},
137         {"bluetooth_ag_set_speaker_gain" , 38},
138
139         {"bluetooth_oob_read_local_data"        , 39},
140         {"bluetooth_oob_add_remote_data" , 40},
141         {"bluetooth_oob_remove_remote_data" , 41},
142
143         {"bluetooth_opc_init"   , 42},
144         {"bluetooth_opc_deinit" , 43},
145         {"bluetooth_opc_push_files" , 44},
146         {"bluetooth_opc_cancel_push" , 45},
147         {"bluetooth_opc_session_is_exist" , 46},
148
149         {"bluetooth_network_activate_server"    , 47},
150         {"bluetooth_network_deactivate_server" , 48},
151         {"bluetooth_network_connect" , 49},
152         {"bluetooth_network_disconnect" , 50},
153
154         {"bluetooth_obex_server_init"   , 51},
155         {"bluetooth_obex_server_deinit" , 52},
156         {"bluetooth_obex_server_init_without_agent"     , 53},
157         {"bluetooth_obex_server_deinit_without_agent"   , 54},
158         {"bluetooth_obex_server_is_activated"   , 55},
159         {"bluetooth_obex_server_accept_connection"      , 56},
160         {"bluetooth_obex_server_reject_connection"      , 57},
161         {"bluetooth_obex_server_accept_authorize"       , 58},
162         {"bluetooth_obex_server_reject_authorize"       , 59},
163         {"bluetooth_obex_server_set_destination_path"   , 60},
164         {"bluetooth_obex_server_set_root"               , 61},
165         {"bluetooth_obex_server_cancel_transfer"        , 62},
166         {"bluetooth_obex_server_cancel_all_transfers"   , 63},
167
168         {"bluetooth_hid_init"   , 65},
169         {"bluetooth_hid_deinit" , 66},
170         {"bluetooth_hid_connect"        , 67},
171         {"bluetooth_hid_disconnect"     , 68},
172
173         {"bluetooth_rfcomm_connect"     , 70},
174         {"bluetooth_rfcomm_disconnect (cancel)" , 71},
175         {"bluetooth_rfcomm_disconnect"  , 72},
176         {"bluetooth_rfcomm_write"       , 73},
177         {"bluetooth_rfcomm_is_client_connected" , 74},
178
179         {"bluetooth_rfcomm_create_socket"       , 80},
180         {"bluetooth_rfcomm_create_socket (Custom UUID)" , 81},
181         {"bluetooth_rfcomm_remove_socket"       , 82},
182         {"bluetooth_rfcomm_listen_and_accept"   , 83},
183         {"bluetooth_rfcomm_listen (OSP)"        , 84},
184         {"bluetooth_rfcomm_server_disconnect"   , 85},
185         {"bluetooth_rfcomm_is_server_uuid_available"    , 86},
186         {"bluetooth_rfcomm_accept_connection"   , 87},
187         {"bluetooth_rfcomm_reject_connection"   , 88},
188         {"bluetooth_start_custom_discovery"     , 89},
189
190         {"bluetooth_gatt_init", 92},
191         {"bluetooth_gatt_deinit", 93},
192         {"bluetooth_gatt_add_service", 94},
193         {"bluetooth_gatt_add_characteristics", 95},
194         {"bluetooth_gatt_add_descriptor", 96},
195         {"bluetooth_gatt_register_service", 97},
196         {"bluetooth_gatt_update_characteristic", 98},
197         {"bluetooth_gatt_unregister_service", 99},
198         {"bluetooth_gatt_delete_services", 100},
199
200 #if 0
201         {"bluetooth_rfcomm_is_server_uuid_available"    , 26},
202
203         {"bluetooth_hdp_activate"       , 30},
204         {"bluetooth_hdp_deactivate"     , 31},
205         {"bluetooth_hdp_connect"        , 32},
206         {"bluetooth_hdp_disconnect"     , 33},
207         {"bluetooth_hdp_send_data"      , 34},
208
209         {"bluetooth_opc_init"           , 35},
210         {"bluetooth_opc_push_file"      , 36},
211         {"bluetooth_opc_cancel_push"    , 37},
212         {"bluetooth_opc_deinit"         , 38},
213         {"bluetooth_obex_server_init"   , 39},
214         {"bluetooth_obex_server_deinit" , 40},
215         {"bluetooth_obex_server_accept_authorize"       , 41},
216         {"bluetooth_obex_server_reject_authorize"       , 42},
217         {"bluetooth_is_supported"       , 43},
218         {"bluetooth_opc_session_is_exist"       , 46},
219         {"bluetooth_obex_server_is_activated"   , 47},
220         {"bluetooth_obex_server_cancel_transfer"        , 48},
221
222         {"bluetooth_oob_read_local_data"        , 50},
223         {"bluetooth_oob_add_remote_data"        , 51},
224         {"bluetooth_oob_remove_remote_data"     , 52},
225
226         {"bluetooth_network_activate_server"    , 60},
227         {"bluetooth_network_deactivate_server"  , 61},
228         {"bluetooth_network_connect"    , 62},
229         {"bluetooth_network_disconnect" , 63},
230
231         {"bluetooth_gatt_discover_primary_services", 64},
232         {"bluetooth_gatt_discover_service_characteristics",     65},
233         {"bluetooth_gatt_get_service_property",         66},
234         {"bluetooth_gatt_get_characteristics_value",    67},
235         {"bluetooth_gatt_set_characteristics_value",    68},
236 #endif
237         /* -----------------------------------------*/
238         {"Finish"                                                       , 0x00ff},
239         {NULL                                                           , 0x0000},
240
241 };
242
243 #define tc_result(success, tc_index) \
244         TC_PRT("Test case [%d - %s] %s", tc_table[tc_index].tc_code, tc_table[tc_index].tc_name, ((success == TC_PASS)?"Success":"Failed"));
245
246 bluetooth_device_info_t bond_dev;
247 int is_bond_device = FALSE;
248
249 void tc_usage_print(void)
250 {
251         int i = 0;
252
253         while (tc_table[i].tc_name) {
254                 if (tc_table[i].tc_code != 0x00ff) {
255                         TC_PRT("Key %d : usage %s", tc_table[i].tc_code, tc_table[i].tc_name);
256                 } else {
257                         TC_PRT("Key %d : usage %s\n\n", 0x00ff, tc_table[i].tc_name);
258                 }
259
260                 i++;
261         }
262 }
263
264 int test_input_callback(void *data)
265 {
266         int ret = 0;
267         int test_id = (int)data;
268
269         TC_PRT("TC : %s", tc_table[test_id - 1].tc_name);
270         switch (test_id)
271         {
272                 case 0x00ff:
273                         TC_PRT("Finished");
274                         g_main_loop_quit(main_loop);
275                         break;
276
277                 case 1:
278                         bluetooth_register_callback(bt_event_callback, NULL);
279                         if (ret < 0)
280                         {
281                                 TC_PRT("%s failed with [0x%04x]", tc_table[0].tc_name, ret);
282                                 tc_result(TC_FAIL, 1);
283                         }
284                         break;
285
286                 case 2:
287                         bluetooth_unregister_callback();
288                         if (ret < 0)
289                         {
290                                 TC_PRT("%s failed with [0x%04x]", tc_table[1].tc_name, ret);
291                                 tc_result(TC_FAIL, 1);
292                         }
293                         break;
294
295                 case 3:
296                         ret = bluetooth_enable_adapter();
297                         if (ret < 0)
298                         {
299                                 TC_PRT("%s failed with [0x%04x]", tc_table[2].tc_name, ret);
300                                 tc_result(TC_FAIL, 1);
301                         }
302                         break;
303
304                 case 4:
305                         ret = bluetooth_disable_adapter();
306                         if (ret < 0)
307                         {
308                                 TC_PRT("%s failed with [0x%04x]", tc_table[3].tc_name, ret);
309                                 tc_result(TC_FAIL, 2);
310                         }
311                         break;
312
313                 case 5:
314                 {
315                         ret = bluetooth_check_adapter();
316                         TC_PRT("state: %d", ret);
317                         break;
318                 }
319
320                 case 6:
321                 {
322                         bluetooth_device_address_t address = {{0}};
323                         ret = bluetooth_get_local_address(&address);
324                         if (ret < 0)
325                         {
326                                 TC_PRT("%s failed with [0x%04x]", tc_table[5].tc_name, ret);
327                         } else {
328                                 TC_PRT("dev [%2.2X:%2.2X:%2.2X:%2.2X:%2.2X:%2.2X]", \
329                                         address.addr[0], address.addr[1], address.addr[2], \
330                                         address.addr[3], address.addr[4], address.addr[5]);
331                         }
332                         break;
333                 }
334
335                 case 7:
336                 {
337                         bluetooth_device_name_t local_name = {{0}};
338
339                         ret = bluetooth_get_local_name(&local_name);
340                         if (ret < 0)
341                         {
342                                 TC_PRT("%s failed with [0x%04x]", tc_table[6].tc_name, ret);
343                         } else {
344                                 TC_PRT("name: %s", local_name.name);
345                         }
346                         break;
347                 }
348
349                 case 8:
350                 {
351                         bluetooth_device_name_t local_name = {{0}};
352                         snprintf(local_name.name, sizeof(local_name.name),
353                                         "bt-frwk-pid-%d", getpid());
354
355                         ret = bluetooth_set_local_name(&local_name);
356                         if (ret < 0)
357                         {
358                                 TC_PRT("%s failed with [0x%04x]", tc_table[7].tc_name, ret);
359                         }
360                         break;
361                 }
362
363                 case 90:
364                 {
365                         bluetooth_version_t local_version = {{0}};
366                         snprintf(local_version.version, sizeof(local_version.version),
367                                         "version%d", getpid());
368
369                         ret = bluetooth_get_local_version(&local_version);
370                         if (ret < 0)
371                                 TC_PRT("%s failed with [0x%04x]", tc_table[89].tc_name, ret);
372                         else
373                                 TC_PRT("version: %s", local_version.version);
374                         break;
375                 }
376
377                 case 9:
378                 {
379                         gboolean used = FALSE;
380
381                         ret = bluetooth_is_service_used(rfcomm_test_uuid_spp, &used);
382                         if (ret < 0)
383                         {
384                                 TC_PRT("%s failed with [0x%04x]", tc_table[8].tc_name, ret);
385                         } else {
386                                 TC_PRT("used: %d", used);
387                         }
388                         break;
389                 }
390
391                 case 10:
392                 {
393                         bluetooth_discoverable_mode_t mode;
394                         ret = bluetooth_get_discoverable_mode(&mode);
395                         if (ret < 0)
396                         {
397                                 TC_PRT("%s failed with [0x%04x]", tc_table[9].tc_name, ret);
398                         }
399                         else
400                         {
401                                 TC_PRT("BT Get Discoverable mode [%d]", mode);
402                         }
403                         break;
404                 }
405
406                 case 11:
407                 {
408                         bluetooth_discoverable_mode_t mode = BLUETOOTH_DISCOVERABLE_MODE_CONNECTABLE;
409                         ret = bluetooth_set_discoverable_mode(mode, 0);
410                         if (ret < 0)
411                         {
412                                 TC_PRT("%s failed with [0x%04x]", tc_table[10].tc_name, ret);
413                         }
414                         else
415                         {
416                                 TC_PRT("BT Set Discoverable mode [%d]", mode);
417                         }
418                         break;
419                 }
420
421                 case 12:
422                 {
423                         bluetooth_discoverable_mode_t mode = BLUETOOTH_DISCOVERABLE_MODE_GENERAL_DISCOVERABLE;
424                         ret = bluetooth_set_discoverable_mode(mode, 0);
425                         if (ret < 0)
426                         {
427                                 TC_PRT("%s failed with [0x%04x]", tc_table[11].tc_name, ret);
428                         }
429                         else
430                         {
431                                 TC_PRT("BT Set Discoverable mode [%d]", mode);
432                         }
433                         break;
434                 }
435
436                 case 13:
437                 {
438                         bluetooth_discoverable_mode_t mode = BLUETOOTH_DISCOVERABLE_MODE_TIME_LIMITED_DISCOVERABLE;
439                         ret = bluetooth_set_discoverable_mode(mode, 5);
440                         if (ret < 0)
441                         {
442                                 TC_PRT("%s failed with [0x%04x]", tc_table[12].tc_name, ret);
443                         }
444                         else
445                         {
446                                 TC_PRT("BT Set Discoverable mode [%d]", mode);
447                         }
448                         break;
449                 }
450
451                 case 14:
452                         ret = bluetooth_start_discovery(0,0,0);
453                         if (ret < 0)
454                         {
455                                 TC_PRT("%s failed with [0x%04x]", tc_table[13].tc_name, ret);
456                         }
457                         break;
458
459                 case 15:
460                         ret = bluetooth_cancel_discovery();
461                         if (ret < 0)
462                         {
463                                 TC_PRT("%s failed with [0x%04x]", tc_table[14].tc_name, ret);
464                         }
465                         break;
466
467                 case 16:
468                 {
469                         ret = bluetooth_is_discovering();
470                         if (ret < 0)
471                         {
472                                 TC_PRT("%s failed with [0x%04x]", tc_table[15].tc_name, ret);
473                         }
474                         else
475                         {
476                                 TC_PRT("Discovering [%d]", ret);
477                         }
478                         break;
479                 }
480
481                 case 17: /*Get paired device list */
482                 {
483                         GPtrArray *devinfo = NULL;
484                         devinfo = g_ptr_array_new();
485                         TC_PRT("g pointer arrary count : [%d]", devinfo->len);
486
487                         ret = bluetooth_get_bonded_device_list(&devinfo);
488                         if (ret < 0)
489                         {
490                                 TC_PRT("%s failed with [0x%04x]", tc_table[16].tc_name, ret);
491                         }
492                         else
493                         {
494                                 int i;
495                                 bluetooth_device_info_t *ptr;
496                                 TC_PRT("g pointer arrary count : [%d]", devinfo->len);
497
498                                 for(i=0; i<devinfo->len;i++)
499                                 {
500                                         ptr = g_ptr_array_index(devinfo, i);
501                                         if(ptr != NULL)
502                                         {
503                                                 TC_PRT("Name [%s]", ptr->device_name.name);
504                                                 TC_PRT("Major Class [%d]", ptr->device_class.major_class);
505                                                 TC_PRT("Minor Class [%d]", ptr->device_class.minor_class);
506                                                 TC_PRT("Service Class [%d]", ptr->device_class.service_class);
507                                                 TC_PRT("%2.2X:%2.2X:%2.2X:%2.2X:%2.2X:%2.2X", ptr->device_address.addr[0], ptr->device_address.addr[1], ptr->device_address.addr[2], ptr->device_address.addr[3], ptr->device_address.addr[4], ptr->device_address.addr[5]);
508                                                 TC_PRT("\n");
509                                         }
510                                 }
511                         }
512                         g_ptr_array_free(devinfo, TRUE);
513
514                         break;
515                 }
516
517                 case 18:
518                 {
519                         /* Apple wireless keyboard */
520                         //bluetooth_device_address_t device_address={{0xE8,0x06,0x88,0x3B,0x18,0xBA}};
521                         //bluetooth_device_address_t device_address={{0x00,0x19,0x0E,0x01,0x61,0x17}}; /* DO-DH79-PYUN04 */
522                         //bluetooth_device_address_t device_address={{0x00,0x16,0x38,0xC3,0x1F,0xD2}}; /* DO-DH79-PYUN03 */
523                         //bluetooth_device_address_t device_address={{0x58,0x17,0x0C,0xEC,0x6A,0xF3}}; /* MW600 */
524                         bluetooth_device_address_t device_address={{0x00,0x0D,0xFD,0x24,0x5E,0xFF}}; /* Motorola S9 */
525
526                         TC_PRT("dev [%2.2X:%2.2X:%2.2X:%2.2X:%2.2X:%2.2X]", \
527                                 device_address.addr[0], device_address.addr[1], device_address.addr[2], \
528                                 device_address.addr[3], device_address.addr[4], device_address.addr[5]);
529
530                         ret = bluetooth_bond_device(&device_address);
531                         if (ret < 0)
532                         {
533                                 TC_PRT("%s failed with [0x%04x]", tc_table[17].tc_name, ret);
534                         }
535                         break;
536                 }
537
538
539                 case 19: /*Cancel bonding */
540                 {
541                         ret = bluetooth_cancel_bonding();
542                         if (ret < 0)
543                         {
544                                 TC_PRT("%s failed with [0x%04x]", tc_table[18].tc_name, ret);
545                         }
546
547                         break;
548                 }
549
550                 case 20: /*unbonding */
551                 {
552                         bluetooth_device_address_t device_address={{0x00,0x19,0x0E,0x01,0x61,0x17}}; /* DO-DH79-PYUN04 */
553                         //bluetooth_device_address_t device_address={{0x00,0x16,0x38,0xC3,0x1F,0xD2}};
554                         ret = bluetooth_unbond_device(&device_address);
555                         if (ret < 0)
556                         {
557                                 TC_PRT("%s failed with [0x%04x]", tc_table[19].tc_name, ret);
558                         }
559
560                         break;
561                 }
562
563                 case 21: /*Get paired device */
564                 {
565                         bluetooth_device_info_t devinfo;
566                         bluetooth_device_address_t device_address={{0x00,0x16,0x38,0xC3,0x1F,0xD2}};
567
568                         memset(&devinfo, 0x00, sizeof(bluetooth_device_info_t));
569
570                         ret = bluetooth_get_bonded_device(&device_address, &devinfo);
571                         if (ret != BLUETOOTH_ERROR_NONE)
572                         {
573                                 TC_PRT("bluetooth_get_bonded_device failed with [%d]",ret);
574                         }
575                         else
576                         {
577                                 TC_PRT("Name [%s]", devinfo.device_name.name);
578                                 TC_PRT("Major Class [%d]", devinfo.device_class.major_class);
579                                 TC_PRT("Minor Class [%d]", devinfo.device_class.minor_class);
580                                 TC_PRT("Service Class [%d]", devinfo.device_class.service_class);
581                                 TC_PRT("%2.2X:%2.2X:%2.2X:%2.2X:%2.2X:%2.2X", devinfo.device_address.addr[0], devinfo.device_address.addr[1], devinfo.device_address.addr[2], devinfo.device_address.addr[3], devinfo.device_address.addr[4], devinfo.device_address.addr[5]);
582                         }
583
584                         break;
585                 }
586
587                 case 22: /*set alias for bonded device */
588                 {
589                         bluetooth_device_address_t device_address={{0x00,0x16,0x38,0xC3,0x1F,0xD2}};
590
591                         ret = bluetooth_set_alias(&device_address, "Renamed device");
592                         if (ret < 0)
593                                 TC_PRT("%s failed with [0x%04x]", tc_table[21].tc_name, ret);
594                         break;
595                 }
596
597                 case 23:
598                 {
599                         bluetooth_device_address_t device_address={{0x00,0x16,0x38,0xC3,0x1F,0xD2}};
600
601                         ret = bluetooth_authorize_device(&device_address, TRUE);
602                         if (ret < 0)
603                                 TC_PRT("%s failed with [0x%04x]", tc_table[22].tc_name, ret);
604                         break;
605                 }
606                 case 24:
607                 {
608                         bluetooth_device_address_t device_address={{0x00,0x16,0x38,0xC3,0x1F,0xD2}};
609
610                         ret = bluetooth_authorize_device(&device_address, FALSE);
611                         if (ret < 0)
612                                 TC_PRT("%s failed with [0x%04x]", tc_table[23].tc_name, ret);
613                         break;
614                 }
615                 case 25:
616                 {
617                         bluetooth_device_address_t device_address={{0x00,0x19,0x0E,0x01,0x61,0x17}}; /* DO-DH79-PYUN04 */
618
619                         ret = bluetooth_search_service(&device_address);
620                         if (ret < 0)
621                                 TC_PRT("%s failed with [0x%04x]", tc_table[24].tc_name, ret);
622                         break;
623                 }
624                 case 26:
625                 {
626                         ret = bluetooth_cancel_service_search();
627                         if (ret < 0)
628                                 TC_PRT("%s failed with [0x%04x]", tc_table[24].tc_name, ret);
629                         break;
630                 }
631                 case 27:
632                 {
633                         gboolean connected = FALSE;
634                         bluetooth_device_address_t device_address={{0x00,0x1B,0x66,0x01,0x23,0x1C}}; /* Gennheiser PX210BT */
635
636                         ret = bluetooth_is_device_connected(&device_address, BLUETOOTH_A2DP_SERVICE, &connected);
637                         if (ret < 0)
638                                 TC_PRT("%s failed with [0x%04x]", tc_table[24].tc_name, ret);
639
640                         TC_PRT("connected : %d", connected);
641                         break;
642                 }
643                 case 28:
644                 {
645                         ret = bluetooth_reset_adapter();
646                         if (ret < 0)
647                                 TC_PRT("%s failed with [0x%04x]", tc_table[27].tc_name, ret);
648                         break;
649                 }
650                 case 91:
651                 {
652                         bluetooth_manufacturer_data_t m_data;
653                         guint8 data[6]  = {0x05, 0xFF, 0x02, 0x03, 0x04, 0x05};
654
655                         TC_PRT("%x %x %x %x %x %x", data[0], data[1], data[2], data[3],
656                                         data[4], data[5]);
657                         memcpy(m_data.data, data, sizeof(data));
658                         m_data.data_len = sizeof(data) - 2;
659                         ret = bluetooth_set_manufacturer_data(&m_data);
660                         if (ret < 0)
661                                 TC_PRT("%s failed with [0x%04x]", tc_table[90].tc_name, ret);
662                         break;
663                 }
664                 case 29:
665                 {
666                         ret = bluetooth_audio_init(bt_audio_event_callback, NULL);
667                         if (ret < 0)
668                                 TC_PRT("%s failed with [0x%04x]", tc_table[28].tc_name, ret);
669                         break;
670                 }
671                 case 30:
672                 {
673                         ret = bluetooth_audio_deinit();
674                         if (ret < 0)
675                                 TC_PRT("%s failed with [0x%04x]", tc_table[29].tc_name, ret);
676                         break;
677                 }
678                 case 31:
679                 {
680                         /* MW600 */
681                         //bluetooth_device_address_t device_address={{0x58,0x17,0x0C,0xEC,0x6A,0xF3}};
682                         bluetooth_device_address_t device_address={{0x00,0x0D,0xFD,0x24,0x5E,0xFF}}; /* Motorola S9 */
683
684                         ret = bluetooth_audio_connect(&device_address);
685                         if (ret < 0)
686                                 TC_PRT("%s failed with [0x%04x]", tc_table[30].tc_name, ret);
687                         break;
688                 }
689                 case 32:
690                 {
691                         /* MW600 */
692                         //bluetooth_device_address_t device_address={{0x58,0x17,0x0C,0xEC,0x6A,0xF3}};
693                         bluetooth_device_address_t device_address={{0x00,0x0D,0xFD,0x24,0x5E,0xFF}}; /* Motorola S9 */
694
695                         ret = bluetooth_audio_disconnect(&device_address);
696                         if (ret < 0)
697                                 TC_PRT("%s failed with [0x%04x]", tc_table[31].tc_name, ret);
698                         break;
699                 }
700                 case 33:
701                 {
702                         /* MW600 */
703                         bluetooth_device_address_t device_address={{0x58,0x17,0x0C,0xEC,0x6A,0xF3}};
704
705                         ret = bluetooth_ag_connect(&device_address);
706                         if (ret < 0)
707                                 TC_PRT("%s failed with [0x%04x]", tc_table[32].tc_name, ret);
708                         break;
709                 }
710                 case 34:
711                 {
712                         /* MW600 */
713                         bluetooth_device_address_t device_address={{0x58,0x17,0x0C,0xEC,0x6A,0xF3}};
714
715                         ret = bluetooth_ag_disconnect(&device_address);
716                         if (ret < 0)
717                                 TC_PRT("%s failed with [0x%04x]", tc_table[33].tc_name, ret);
718                         break;
719                 }
720                 case 35:
721                 {
722                         /* MW600 */
723                         bluetooth_device_address_t device_address={{0x58,0x17,0x0C,0xEC,0x6A,0xF3}};
724
725                         ret = bluetooth_av_connect(&device_address);
726                         if (ret < 0)
727                                 TC_PRT("%s failed with [0x%04x]", tc_table[34].tc_name, ret);
728                         break;
729                 }
730                 case 36:
731                 {
732                         /* MW600 */
733                         bluetooth_device_address_t device_address={{0x58,0x17,0x0C,0xEC,0x6A,0xF3}};
734
735                         ret = bluetooth_av_disconnect(&device_address);
736                         if (ret < 0)
737                                 TC_PRT("%s failed with [0x%04x]", tc_table[35].tc_name, ret);
738                         break;
739                 }
740                 case 37:
741                 {
742                         unsigned int volume = 0;
743
744                         ret = bluetooth_ag_get_headset_volume(&volume);
745                         if (ret < 0)
746                                 TC_PRT("failed with [0x%04x]", ret);
747
748                         TC_PRT("volume: %u", volume);
749                         break;
750                 }
751                 case 38:
752                 {
753                         ret = bluetooth_ag_set_speaker_gain(10);
754                         if (ret < 0)
755                                 TC_PRT("failed with [0x%04x]", ret);
756                         break;
757                 }
758
759                 case 39:
760                 {
761                         if (bluetooth_oob_read_local_data(&g_local_oob_data.oob_data))
762                                 TC_PRT("ERROR in bluetooth_oob_read_local_data\n");
763                         else {
764                                 TC_PRT("SUCESS in bluetooth_oob_read_local_data\n");
765                                 TC_PRT("hash = [%2.2X:%2.2X:%2.2X:%2.2X:%2.2X:%2.2X:%2.2X:%2.2X"
766                                         "%2.2X:%2.2X:%2.2X:%2.2X:%2.2X:%2.2X:%2.2X:%2.2X]\n",
767                                         g_local_oob_data.oob_data.hash[0],
768                                         g_local_oob_data.oob_data.hash[1],
769                                         g_local_oob_data.oob_data.hash[2],
770                                         g_local_oob_data.oob_data.hash[3],
771                                         g_local_oob_data.oob_data.hash[4],
772                                         g_local_oob_data.oob_data.hash[5],
773                                         g_local_oob_data.oob_data.hash[6],
774                                         g_local_oob_data.oob_data.hash[7],
775                                         g_local_oob_data.oob_data.hash[8],
776                                         g_local_oob_data.oob_data.hash[9],
777                                         g_local_oob_data.oob_data.hash[10],
778                                         g_local_oob_data.oob_data.hash[11],
779                                         g_local_oob_data.oob_data.hash[12],
780                                         g_local_oob_data.oob_data.hash[13],
781                                         g_local_oob_data.oob_data.hash[14],
782                                         g_local_oob_data.oob_data.hash[15]);
783
784                                 TC_PRT("randomizer = [%2.2X:%2.2X:%2.2X:%2.2X:%2.2X:%2.2X:%2.2X:%2.2X"
785                                         "%2.2X:%2.2X:%2.2X:%2.2X:%2.2X:%2.2X:%2.2X:%2.2X]\n",
786                                         g_local_oob_data.oob_data.randomizer[0],
787                                         g_local_oob_data.oob_data.randomizer[1],
788                                         g_local_oob_data.oob_data.randomizer[2],
789                                         g_local_oob_data.oob_data.randomizer[3],
790                                         g_local_oob_data.oob_data.randomizer[4],
791                                         g_local_oob_data.oob_data.randomizer[5],
792                                         g_local_oob_data.oob_data.randomizer[6],
793                                         g_local_oob_data.oob_data.randomizer[7],
794                                         g_local_oob_data.oob_data.randomizer[8],
795                                         g_local_oob_data.oob_data.randomizer[9],
796                                         g_local_oob_data.oob_data.randomizer[10],
797                                         g_local_oob_data.oob_data.randomizer[11],
798                                         g_local_oob_data.oob_data.randomizer[12],
799                                         g_local_oob_data.oob_data.randomizer[13],
800                                         g_local_oob_data.oob_data.randomizer[14],
801                                         g_local_oob_data.oob_data.randomizer[15]);
802
803                                 TC_PRT("hash_len: %d\n", g_local_oob_data.oob_data.hash_len);
804                                 TC_PRT("randomizer_len: %d\n", g_local_oob_data.oob_data.randomizer_len);
805                         }
806                         break;
807                 }
808                 case 40:
809                 {
810                         ret = bluetooth_get_local_address(&g_local_oob_data.address);
811                         TC_PRT("hash_len: %d\n", g_local_oob_data.oob_data.hash_len);
812                         TC_PRT("randomizer_len: %d\n", g_local_oob_data.oob_data.randomizer_len);
813
814                         if (bluetooth_oob_add_remote_data(&g_local_oob_data.address,
815                                 &g_local_oob_data.oob_data))
816                                 TC_PRT("ERROR in bluetooth_oob_add_remote_data\n");
817                         else
818                                 TC_PRT(" bluetooth_oob_add_remote_data SUCCESS\n");
819                         break;
820                 }
821
822                 case 41:
823                 {
824                         if (bluetooth_oob_remove_remote_data(&g_local_oob_data.address))
825                                 TC_PRT("ERROR in bluetooth_oob_remove_remote_data\n");
826                         else
827                                 TC_PRT(" bluetooth_oob_remove_remote_data SUCCESS\n");
828                         break;
829                 }
830                 case 42:
831                 {
832                         bluetooth_opc_init();
833                         break;
834                 }
835                 case 43:
836                 {
837                         bluetooth_opc_deinit();
838                         break;
839                 }
840                 case 44:
841                 {
842                         bluetooth_device_address_t remote_address = {{0}};
843
844                         /* Grey dongle */
845                         remote_address.addr[0] = 0x00; remote_address.addr[1] = 0x02; remote_address.addr[2] = 0x70;
846                         remote_address.addr[3] = 0x2B; remote_address.addr[4] = 0xD3;  remote_address.addr[5]= 0xAF;
847
848                         char *files[5] = {NULL};
849
850                         files[0] = "/opt/media/Images/image1.jpg";
851 //                      files[1] = "/opt/media/Images/image2.jpg";
852 //                      files[2] = "/opt/media/Images/image3.jpg";
853                         bluetooth_opc_push_files(&remote_address, files);
854                         break;
855                 }
856                 case 45:
857                 {
858                         bluetooth_opc_cancel_push();
859                         break;
860                 }
861                 case 46:
862                 {
863                         gboolean exist;
864                         exist = bluetooth_opc_session_is_exist();
865                         TC_PRT("exist: %d", exist);
866                         break;
867                 }
868                 case 47:
869                 {
870                         bluetooth_network_activate_server();
871                         break;
872                 }
873                 case 48:
874                 {
875                         bluetooth_network_deactivate_server();
876                         break;
877                 }
878                 case 49:
879                 {
880                         bluetooth_device_address_t device_address = {{0x00, 0x02, 0xA2, 0x14, 0x40, 0x51}};
881                         bluetooth_network_connect(&device_address, BLUETOOTH_NETWORK_NAP_ROLE, NULL);
882                         break;
883                 }
884                 case 50:
885                 {
886                         bluetooth_device_address_t device_address = {{0x00, 0x02, 0xA2, 0x14, 0x40, 0x51}};
887                         bluetooth_network_disconnect(&device_address);
888                         break;
889                 }
890                 case 51:
891                 {
892                         bluetooth_obex_server_init("/opt/media/Downloads");
893                         break;
894                 }
895                 case 52:
896                 {
897                         bluetooth_obex_server_deinit();
898                         break;
899                 }
900                 case 53:
901                 {
902                         bluetooth_obex_server_init_without_agent("/opt/media/Downloads");
903                         break;
904                 }
905                 case 54:
906                 {
907                         bluetooth_obex_server_deinit_without_agent();
908                         break;
909                 }
910                 case 55:
911                 {
912                         bluetooth_obex_server_is_activated();
913                         break;
914                 }
915                 case 56:
916                 {
917                         bluetooth_obex_server_accept_connection();
918                         TC_PRT(" bluetooth_obex_server_accept_connection SUCCESS\n");
919                         break;
920                 }
921                 case 57:
922                 {
923                         bluetooth_obex_server_reject_connection();
924                         break;
925                 }
926                 case 58:
927                 {
928                         bluetooth_obex_server_accept_authorize("abc");
929                         break;
930                 }
931                 case 59:
932                 {
933                         bluetooth_obex_server_reject_authorize();
934                         break;
935                 }
936                 case 60:
937                 {
938                         bluetooth_obex_server_set_destination_path("/opt/media");
939                         break;
940                 }
941                 case 61:
942                 {
943                         bluetooth_obex_server_set_root("/opt/media");
944                         break;
945                 }
946                 case 62:
947                 {
948                         bluetooth_obex_server_cancel_transfer(0);
949                         break;
950                 }
951                 case 63:
952                 {
953                         bluetooth_obex_server_cancel_all_transfers();
954                         break;
955                 }
956
957                 case 65:
958                 {
959                         ret = bluetooth_hid_init(bt_hid_event_callback, NULL);
960                         if (ret < 0)
961                                 TC_PRT("Failed with [0x%04x]", ret);
962                         break;
963                 }
964                 case 66:
965                 {
966                         ret = bluetooth_hid_deinit();
967                         if (ret < 0)
968                                 TC_PRT("Failed with [0x%04x]", ret);
969                         break;
970                 }
971                 case 67:
972                 {
973                         /* Apple wireless keyboard */
974                         hid_device_address_t device_address={{0xE8,0x06,0x88,0x3B,0x18,0xBA}};
975
976                         ret = bluetooth_hid_connect(&device_address);
977                         if (ret < 0)
978                                 TC_PRT("Failed with [0x%04x]", ret);
979                         break;
980                 }
981                 case 68:
982                 {
983                         /* Apple wireless keyboard */
984                         hid_device_address_t device_address={{0xE8,0x06,0x88,0x3B,0x18,0xBA}};
985
986                         ret = bluetooth_hid_disconnect(&device_address);
987                         if (ret < 0)
988                                 TC_PRT("Failed with [0x%04x]", ret);
989                         break;
990                 }
991
992                 case 70:
993                 {
994                         bluetooth_device_address_t device_address = {{0x00, 0x02, 0x2F, 0x92, 0x7B, 0xF5}};
995
996                         ret = bluetooth_rfcomm_connect(&device_address, rfcomm_test_uuid_spp);
997                         //ret = bluetooth_rfcomm_connect(&device_address, "1");
998
999                         if (ret < 0)
1000                                 TC_PRT("Failed with [0x%04x]", ret);
1001                         break;
1002                 }
1003                 case 71:
1004                 {
1005                         ret = bluetooth_rfcomm_disconnect(-1);
1006
1007                         if (ret < 0)
1008                                 TC_PRT("Failed with [0x%04x]", ret);
1009                         break;
1010                 }
1011                 case 72:
1012                 {
1013                         ret = bluetooth_rfcomm_disconnect(g_ret_client_fd1);
1014
1015                         if (ret < 0)
1016                                 TC_PRT("Failed with [0x%04x]", ret);
1017                         break;
1018                 }
1019                 case 73:
1020                 {
1021                         const char rd_data[] = "123456789 12345";
1022                         ret = bluetooth_rfcomm_write(g_ret_client_fd1, rd_data, sizeof(rd_data));
1023
1024                         if (ret < 0)
1025                                 TC_PRT("Failed with [0x%04x]", ret);
1026                         break;
1027                 }
1028                 case 74:
1029                 {
1030                         gboolean is_connected;
1031
1032                         is_connected = bluetooth_rfcomm_is_client_connected();
1033
1034                         TC_PRT("Connected: %d", is_connected);
1035                         break;
1036                 }
1037                 case 80:
1038                 {
1039                         ret = bluetooth_rfcomm_create_socket(rfcomm_test_uuid_spp);
1040                         if (ret < 0)
1041                                 TC_PRT("Failed with [0x%04x]", ret);
1042
1043                         TC_PRT("Returned FD = %d", ret);
1044                         server_fd = ret;
1045                         break;
1046                 }
1047                 case 81:
1048                 {
1049                         ret = bluetooth_rfcomm_create_socket(rfcomm_test_uuid_custom);
1050                         if (ret < 0)
1051                                 TC_PRT("Failed with [0x%04x]", ret);
1052
1053                         TC_PRT("Returned FD = %d", ret);
1054                         server_fd = ret;
1055                         break;
1056                 }
1057                 case 82:
1058                 {
1059                         ret = bluetooth_rfcomm_remove_socket(server_fd);
1060                         if (ret < 0)
1061                                 TC_PRT("Failed with [0x%04x]", ret);
1062                         break;
1063                 }
1064                 case 83: /*Listen and accept */
1065                 {
1066
1067                         ret = bluetooth_rfcomm_listen_and_accept(server_fd, 1);
1068                         if (ret < 0)
1069                                 TC_PRT("Failed with [0x%04x]", ret);
1070
1071                         TC_PRT("result = %d", ret);
1072                         break;
1073                 }
1074                 case 84: /*Listen */
1075                 {
1076
1077                         ret = bluetooth_rfcomm_listen(server_fd, 1);
1078                         if (ret < 0)
1079                                 TC_PRT("Failed with [0x%04x]", ret);
1080
1081                         TC_PRT("result = %d", ret);
1082                         break;
1083                 }
1084                 case 85:
1085                 {
1086                         ret = bluetooth_rfcomm_server_disconnect(client_fd);
1087                         if (ret < 0)
1088                                 TC_PRT("Failed with [0x%04x]", ret);
1089                         break;
1090                 }
1091                 case 86:
1092                 {
1093                         gboolean available;
1094
1095                         available = bluetooth_rfcomm_is_server_uuid_available(rfcomm_test_uuid_spp);
1096
1097                         TC_PRT("available: %d", available);
1098                         break;
1099                 }
1100                 case 87:
1101                 {
1102                         ret = bluetooth_rfcomm_accept_connection(server_fd, &client_fd);
1103                         if (ret < 0)
1104                                 TC_PRT("Failed with [0x%04x]", ret);
1105                         TC_PRT("client fd: %d", client_fd);
1106                         break;
1107                 }
1108                 case 88:
1109                 {
1110                         ret = bluetooth_rfcomm_reject_connection(server_fd);
1111                         if (ret < 0)
1112                                 TC_PRT("Failed with [0x%04x]", ret);
1113                         break;
1114                 }
1115                 case 89:
1116                         ret = bluetooth_start_custom_discovery(DISCOVERY_ROLE_LE,
1117                                                                         0,0,0);
1118                         if (ret < 0)
1119                         {
1120                                 TC_PRT("failed with [0x%04x]", ret);
1121                         }
1122                         break;
1123                 case 92: {
1124                         ret = bluetooth_gatt_init();
1125                         if (ret < 0)
1126                         {
1127                                 TC_PRT("gatt init failed with [0x%04x]", ret);
1128                         }
1129                         break;
1130                 }
1131                 case 93: {
1132                         ret = bluetooth_gatt_deinit();
1133                         if (ret < 0)
1134                         {
1135                                 TC_PRT("gatt deinit failed with [0x%04x]", ret);
1136                         }
1137                         break;
1138                 }
1139                 case 94: {
1140                         char *service_uuid = g_strdup("00001802-0000-1000-8000-00805f9b34fb");
1141
1142                         ret = bluetooth_gatt_add_service(service_uuid,
1143                                 &svc_obj_path);
1144                         g_free(service_uuid);
1145
1146                         TC_PRT("service obj_path is %s", svc_obj_path);
1147                         }
1148                         break;
1149
1150                 case 95: {
1151                         /* testing with dummy values*/
1152                         char *char_uuid = g_strdup("00002a06-0000-1000-8000-00805f9b34fb");
1153                         bt_gatt_characteristic_property_t props = BLUETOOTH_GATT_CHARACTERISTIC_PROPERTY_READ |
1154                                         BLUETOOTH_GATT_CHARACTERISTIC_PROPERTY_WRITE |
1155                                         BLUETOOTH_GATT_CHARACTERISTIC_PROPERTY_NOTIFY |
1156                                         BLUETOOTH_GATT_CHARACTERISTIC_PROPERTY_INDICATE;
1157
1158                         ret = bluetooth_gatt_add_new_characteristic(
1159                                 svc_obj_path, char_uuid,
1160                                 props, &char_obj_path);
1161                         g_free(char_uuid);
1162
1163                         TC_PRT("characteristic obj_path is %s", char_obj_path);
1164
1165                         break;
1166                 }
1167
1168                 case 96: {
1169                         char *desc_uuid = g_strdup("000026ff-0000-1000-8000-00805f9b34fb");
1170
1171                         ret = bluetooth_gatt_add_descriptor(char_obj_path,
1172                                 desc_uuid, &desc_obj_path);
1173
1174                         TC_PRT("add descriptor error is %d", ret);
1175                         g_free(desc_uuid);
1176
1177                         break;
1178                 }
1179                 case 97: {
1180                         ret = bluetooth_gatt_register_service(svc_obj_path);
1181
1182                         TC_PRT("register service error is %d", ret);
1183
1184                         break;
1185                 }
1186                 case 98: {
1187                         char char_data[4] = {10, 20, 30, 40};
1188                         int char_length = 4;
1189                         ret = bluetooth_gatt_update_characteristic(char_obj_path,
1190                                                 char_data, char_length);
1191
1192                         TC_PRT("update_characteristic error is %d", ret);
1193
1194                         break;
1195                 }
1196                 case 99: {
1197                         ret = bluetooth_gatt_unregister_service(svc_obj_path);
1198
1199                         TC_PRT("service removed with error is %d", ret);
1200
1201                         break;
1202                 }
1203                 case 100: {
1204                         ret = bluetooth_gatt_delete_services();
1205
1206                         TC_PRT("services deleted with error is %d", ret);
1207
1208                         break;
1209                 }
1210                 default:
1211                         break;
1212         }
1213
1214         return 0;
1215 }
1216
1217 void startup()
1218 {
1219         TC_PRT("bluetooth framework TC startup");
1220
1221         if(!g_thread_supported())
1222         {
1223                 g_thread_init(NULL);
1224         }
1225
1226         dbus_g_thread_init();
1227
1228         g_type_init();
1229         main_loop = g_main_loop_new(NULL, FALSE);
1230 }
1231
1232 void cleanup()
1233 {
1234         TC_PRT("bluetooth framework TC cleanup");
1235         if( main_loop!= NULL)
1236         {
1237                 g_main_loop_unref(main_loop);
1238         }
1239 }
1240
1241 int timeout_callback(void *data)
1242 {
1243         TC_PRT("timeout callback");
1244         timeout_status = -1;
1245
1246         g_main_loop_quit(main_loop);
1247
1248         return FALSE;
1249 }
1250
1251
1252 void bt_hid_event_callback(int event, hid_event_param_t* param, void *user_data)
1253 {
1254         TC_PRT(">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>");
1255         TC_PRT("bt event callback 0x%04x", event);
1256
1257
1258
1259 }
1260
1261 void bt_audio_event_callback(int event, bt_audio_event_param_t* param, void *user_data)
1262 {
1263         TC_PRT(">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>");
1264         TC_PRT("bt event callback 0x%04x", event);
1265
1266
1267
1268 }
1269
1270 void bt_event_callback(int event, bluetooth_event_param_t* param, void *user_data)
1271 {
1272         TC_PRT(">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>");
1273         TC_PRT("bt event callback 0x%04x", event);
1274         switch(event)
1275         {
1276                 case BLUETOOTH_EVENT_ENABLED:
1277                         TC_PRT("BLUETOOTH_EVENT_ENABLED, result [0x%04x]", param->result);
1278                         break;
1279
1280                 case BLUETOOTH_EVENT_DISABLED:
1281                         TC_PRT("BLUETOOTH_EVENT_DISABLED, result [0x%04x]", param->result);
1282                         break;
1283
1284                 case BLUETOOTH_EVENT_LOCAL_NAME_CHANGED:
1285                         TC_PRT("BLUETOOTH_EVENT_LOCAL_NAME_CHANGED, result [0x%04x]", param->result);
1286                         if (param->result == BLUETOOTH_ERROR_NONE)
1287                         {
1288                                 bluetooth_device_name_t *local_name = (bluetooth_device_name_t *)param->param_data;
1289                                 tc_result(TC_PASS, 6);
1290                                 TC_PRT("Changed Name : [%s]", local_name->name);
1291                         }
1292                         else
1293                         {
1294                                 tc_result(TC_FAIL, 6);
1295                         }
1296                         break;
1297
1298
1299                 case BLUETOOTH_EVENT_DISCOVERY_STARTED:
1300                         TC_PRT("BLUETOOTH_EVENT_DISCOVERY_STARTED, result [0x%04x]", param->result);
1301                         break;
1302
1303                 case BLUETOOTH_EVENT_REMOTE_DEVICE_FOUND:
1304                 {
1305                         bluetooth_device_info_t *device_info = NULL;
1306                         TC_PRT("BLUETOOTH_EVENT_REMOTE_DEVICE_FOUND, result [0x%04x]", param->result);
1307                         device_info  = (bluetooth_device_info_t *)param->param_data;
1308                         memcpy(&searched_device, &device_info->device_address, sizeof(bluetooth_device_address_t));
1309                         TC_PRT("dev [%2.2X:%2.2X:%2.2X:%2.2X:%2.2X:%2.2X]", \
1310                                 device_info->device_address.addr[0], device_info->device_address.addr[1], device_info->device_address.addr[2], \
1311                                 device_info->device_address.addr[3], device_info->device_address.addr[4], device_info->device_address.addr[5]);
1312                         break;
1313                 }
1314
1315                 case BLUETOOTH_EVENT_REMOTE_LE_DEVICE_FOUND:
1316                 {
1317                         int i;
1318                         bluetooth_le_device_info_t *le_device_info = NULL;
1319                         TC_PRT("BLUETOOTH_EVENT_REMOTE_LE_DEVICE_FOUND, result [0x%04x]", param->result);
1320                         le_device_info  = (bluetooth_le_device_info_t *)param->param_data;
1321                         TC_PRT("dev[%2.2X:%2.2X:%2.2X:%2.2X:%2.2X:%2.2X]", \
1322                                 le_device_info->device_address.addr[0], le_device_info->device_address.addr[1], le_device_info->device_address.addr[2], \
1323                                 le_device_info->device_address.addr[3], le_device_info->device_address.addr[4], le_device_info->device_address.addr[5]);
1324                         TC_PRT("addr_type : %d", le_device_info->addr_type);
1325                         TC_PRT("rssi : %d", le_device_info->rssi);
1326                         TC_PRT("adv_ind_data_len :%d" , le_device_info->adv_ind_data.data_len);
1327                         TC_PRT("scan_resp_data_len :%d" , le_device_info->scan_resp_data.data_len);
1328
1329                         for (i=0; i<le_device_info->adv_ind_data.data_len; i++)
1330                                 TC_PRT("adv_ind_data[%d] : [0x%x]",i ,le_device_info->adv_ind_data.data.data[i]);
1331                         for (i=0; i<le_device_info->scan_resp_data.data_len; i++)
1332                                 TC_PRT("scan_resp_data[%d] : [0x%x]",i ,le_device_info->scan_resp_data.data.data[i]);
1333                         break;
1334                 }
1335
1336                 case BLUETOOTH_EVENT_REMOTE_DEVICE_NAME_UPDATED:
1337                 {
1338                         bluetooth_device_info_t *device_info = NULL;
1339                         TC_PRT("BLUETOOTH_EVENT_REMOTE_DEVICE_NAME_UPDATED, result [0x%04x]", param->result);
1340                         device_info  = (bluetooth_device_info_t *)param->param_data;
1341                         memcpy(&searched_device, &device_info->device_address, sizeof(bluetooth_device_address_t));
1342                         TC_PRT("dev [%s] [%2.2X:%2.2X:%2.2X:%2.2X:%2.2X:%2.2X]", device_info->device_name.name, \
1343                                 device_info->device_address.addr[0], device_info->device_address.addr[1], device_info->device_address.addr[2], \
1344                                 device_info->device_address.addr[3], device_info->device_address.addr[4], device_info->device_address.addr[5]);
1345                         break;
1346                 }
1347
1348                 case BLUETOOTH_EVENT_DISCOVERY_FINISHED:
1349                         TC_PRT("BLUETOOTH_EVENT_DISCOVERY_FINISHED, result [0x%04x]", param->result);
1350                         break;
1351
1352                 case BLUETOOTH_EVENT_DISCOVERABLE_MODE_CHANGED:
1353                 {
1354                         int *mode = (int *)param->param_data;
1355                         TC_PRT("BT_DISCOVERABLE_MODE_CHANGED, result [0x%04x]", param->result);
1356                         TC_PRT("mode [%d]", *mode);
1357                         break;
1358                 }
1359                 case BLUETOOTH_EVENT_DISCOVERABLE_TIMEOUT_CHANGED:
1360                 {
1361                         int *timeout = (int *)param->param_data;
1362                         TC_PRT("BLUETOOTH_EVENT_DISCOVERABLE_TIMEOUT_CHANGED, result [0x%04x]", param->result);
1363                         TC_PRT("timeout [%d]", *timeout);
1364                         break;
1365                 }
1366                 case BLUETOOTH_EVENT_BONDING_FINISHED:
1367                 {
1368                         TC_PRT("BLUETOOTH_EVENT_BONDING_FINISHED, result [0x%04x]", param->result);
1369                         if (param->result >= BLUETOOTH_ERROR_NONE)
1370                         {
1371                                 bluetooth_device_info_t *device_info = NULL;
1372                                 tc_result(TC_PASS, 12);
1373                                 device_info  = (bluetooth_device_info_t *)param->param_data;
1374                                 if (device_info == NULL)
1375                                         break;
1376
1377                                 TC_PRT("dev [%s] [%2.2X:%2.2X:%2.2X:%2.2X:%2.2X:%2.2X] mjr[%#x] min[%#x] srv[%#x]", device_info->device_name.name, \
1378                                         device_info->device_address.addr[0], device_info->device_address.addr[1], device_info->device_address.addr[2], \
1379                                         device_info->device_address.addr[3], device_info->device_address.addr[4], device_info->device_address.addr[5], \
1380                                         device_info->device_class.major_class, device_info->device_class.minor_class, device_info->device_class.service_class);
1381                         }
1382                         else
1383                         {
1384                                 tc_result(TC_FAIL, 12);
1385                         }
1386                         break;
1387                 }
1388
1389                 case BLUETOOTH_EVENT_BONDED_DEVICE_FOUND:
1390                 {
1391                         // bluetooth_get_bonded_device_list is changed as synchronous API. This event is not used any more.
1392                         // 2011.01.06
1393 #if 0
1394 //                      int i = 0;
1395                         TC_PRT("BLUETOOTH_EVENT_BONDED_DEVICE_FOUND, result [0x%04x]", param->result);
1396                         if (param->result >= BLUETOOTH_ERROR_NONE)
1397                         {
1398                                 ///tc_result(TC_PASS, 15);
1399                                 bluetooth_device_info_t * bt_dev_info= (bluetooth_device_info_t*)param->param_data;
1400
1401                                 TC_PRT("Dev Name = %s, Dev add = %2.2X:%2.2X:%2.2X:%2.2X:%2.2X:%2.2X, COD (major,minor,service)= 0x%x:%x:%x\n", bt_dev_info->device_name.name,
1402                                         bt_dev_info->device_address.addr[0], bt_dev_info->device_address.addr[1], bt_dev_info->device_address.addr[2], \
1403                                         bt_dev_info->device_address.addr[3], bt_dev_info->device_address.addr[4], bt_dev_info->device_address.addr[5], \
1404                                         bt_dev_info->device_class.major_class, bt_dev_info->device_class.minor_class, bt_dev_info->device_class.service_class);
1405
1406                         }
1407                         else
1408                         if(param->result == BLUETOOTH_ERROR_END_OF_DEVICE_LIST) /*End of the Device found indication*/
1409                         {
1410                                 tc_result(TC_PASS, 15);
1411                                 TC_PRT("*****<<No more BLUETOOTH_EVENT_BONDED_DEVICE_FOUND indication>>***** ");
1412                         }
1413                         else
1414                         {
1415                                 tc_result(TC_FAIL, 15);
1416                                 TC_PRT("*****API failed ***** ");
1417                         }
1418                         break;
1419 #endif
1420                 }
1421                 case BLUETOOTH_EVENT_SERVICE_SEARCHED:
1422                 {
1423                         int i = 0;
1424                         TC_PRT("BLUETOOTH_EVENT_SERVICE_SEARCHED, result [0x%04x]", param->result);
1425                         if (param->result >= BLUETOOTH_ERROR_NONE)
1426                         {
1427                                 tc_result(TC_PASS, 18);
1428                                 bt_sdp_info_t * bt_sdp_info=param->param_data;
1429
1430                                 TC_PRT("Dev add = %2.2X:%2.2X:%2.2X:%2.2X:%2.2X:%2.2X\n",
1431                                         bt_sdp_info->device_addr.addr[0], bt_sdp_info->device_addr.addr[1], bt_sdp_info->device_addr.addr[2], \
1432                                         bt_sdp_info->device_addr.addr[3], bt_sdp_info->device_addr.addr[4], bt_sdp_info->device_addr.addr[5]);
1433
1434                                         TC_PRT("Supported service list:\n");
1435                                         for(i=0; i<bt_sdp_info->service_index; i++)
1436                                                 TC_PRT("[%#x]\n", bt_sdp_info->service_list_array[i]);
1437
1438                         }
1439                         else
1440                         {
1441                                 tc_result(TC_FAIL, 18);
1442                         }
1443                         break;
1444                 }
1445                 case BLUETOOTH_EVENT_RFCOMM_DATA_RECEIVED:
1446                 {
1447                         TC_PRT("BLUETOOTH_EVENT_RFCOMM_DATA_RECEIVED, result [0x%04x]", param->result);
1448                         bluetooth_rfcomm_received_data_t *rx_data = param->param_data;
1449                         printf("\n FD = %d \nBuffer len = %d ", rx_data->socket_fd, rx_data->buffer_size);
1450                         if (rx_data->buffer_size < sizeof(oob_data_t))
1451                                 TC_PRT("Complete oob data is not recivedn");
1452                         else
1453                                 memcpy(&g_remote_oob_data,rx_data->buffer, sizeof(oob_data_t));
1454                         //tc_result(TC_PASS, 21);
1455                         break;
1456                 }
1457                 case BLUETOOTH_EVENT_RFCOMM_CONNECTED:
1458                 {
1459                         bluetooth_rfcomm_connection_t *con_ind = (bluetooth_rfcomm_connection_t *)param->param_data;
1460                         TC_PRT("BLUETOOTH_EVENT_RFCOMM_CONNECTED, result [0x%04x], fd = %d, device add = 0x%X:%X:%X:%X:%X:%X, Role = %s", param->result,
1461                                                                 con_ind->socket_fd,
1462                                                                 con_ind->device_addr.addr[0], con_ind->device_addr.addr[1], con_ind->device_addr.addr[2],
1463                                                                 con_ind->device_addr.addr[3], con_ind->device_addr.addr[4], con_ind->device_addr.addr[5],
1464                                                                 (con_ind->device_role == RFCOMM_ROLE_SERVER)? "SERVER":"CLIENT");
1465                         //tc_result(TC_PASS, 22);
1466                         if((con_ind->device_role == RFCOMM_ROLE_CLIENT) && (con_ind->socket_fd > 0))
1467                         {
1468                                 g_ret_client_fd1 = con_ind->socket_fd;
1469                         }
1470
1471                         if((con_ind->device_role == RFCOMM_ROLE_SERVER) && (con_ind->socket_fd > 0))
1472                         {
1473                                 client_fd = con_ind->socket_fd;
1474                         }
1475
1476                         break;
1477                 }
1478                 case BLUETOOTH_EVENT_RFCOMM_DISCONNECTED:
1479                 {
1480                         bluetooth_rfcomm_disconnection_t *disconnection_ind = (bluetooth_rfcomm_disconnection_t *)param->param_data;;
1481                         TC_PRT("BLUETOOTH_EVENT_RFCOMM_DISCONNECTED, result [0x%04x] Fd = %d, device add = 0x%X:%X:%X:%X:%X:%X\n", param->result, disconnection_ind->socket_fd,
1482                                                                                                                 disconnection_ind->device_addr.addr[0], disconnection_ind->device_addr.addr[1], disconnection_ind->device_addr.addr[2],
1483                                                                                                                 disconnection_ind->device_addr.addr[3], disconnection_ind->device_addr.addr[4], disconnection_ind->device_addr.addr[5] );
1484                         //tc_result(TC_PASS, 22);
1485                         break;
1486                 }
1487                 case BLUETOOTH_EVENT_NETWORK_SERVER_CONNECTED:
1488                 {
1489                         bluetooth_network_device_info_t *dev_info = (bluetooth_network_device_info_t *)param->param_data;
1490
1491                         TC_PRT("BLUETOOTH_EVENT_RFCOMM_DISCONNECTED, result [0x%04x]", param->result);
1492                         TC_PRT("interface name: %s", dev_info->interface_name);
1493
1494                         TC_PRT("device add = %2.2X:%2.2X:%2.2X:%2.2X:%2.2X:%2.2X\n",
1495                                                                 dev_info->device_address.addr[0], dev_info->device_address.addr[1], dev_info->device_address.addr[2],
1496                                                                 dev_info->device_address.addr[3], dev_info->device_address.addr[4], dev_info->device_address.addr[5] );
1497                         break;
1498                 }
1499                 case BLUETOOTH_EVENT_NETWORK_SERVER_DISCONNECTED:
1500                 {
1501                         bluetooth_network_device_info_t *dev_info = (bluetooth_network_device_info_t *)param->param_data;
1502
1503                         TC_PRT("BLUETOOTH_EVENT_RFCOMM_DISCONNECTED, result [0x%04x]", param->result);
1504                         TC_PRT("interface name: %s", dev_info->interface_name);
1505
1506                         TC_PRT("device add = %2.2X:%2.2X:%2.2X:%2.2X:%2.2X:%2.2X\n",
1507                                                                 dev_info->device_address.addr[0], dev_info->device_address.addr[1], dev_info->device_address.addr[2],
1508                                                                 dev_info->device_address.addr[3], dev_info->device_address.addr[4], dev_info->device_address.addr[5] );
1509                         break;
1510                 }
1511
1512                 case BLUETOOTH_EVENT_HDP_CONNECTED:
1513                 {
1514                         bt_hdp_connected_t *conn_ind = (bt_hdp_connected_t *)param->param_data;
1515
1516                         TC_PRT("BLUETOOTH_EVENT_HDP_CONNECTED, Result = %s\n", (param->result == 0)? "BLUETOOTH_ERROR_NONE": "BLUETOOTH_ERROR_XXXX");
1517                         TC_PRT("App handler = %s, channel id = %d, type = %s", conn_ind->app_handle, conn_ind->channel_id, (conn_ind->type == HDP_QOS_RELIABLE)? "Reliable":"Streaming");
1518                         TC_PRT("device add = %2.2X:%2.2X:%2.2X:%2.2X:%2.2X:%2.2X\n",
1519                                                                 conn_ind->device_address.addr[0], conn_ind->device_address.addr[1], conn_ind->device_address.addr[2],
1520                                                                 conn_ind->device_address.addr[3], conn_ind->device_address.addr[4], conn_ind->device_address.addr[5] );
1521
1522                         g_ret_client_fd1 = conn_ind->channel_id;
1523                         break;
1524                 }
1525
1526                 case BLUETOOTH_EVENT_HDP_DISCONNECTED:
1527                 {
1528                         bt_hdp_disconnected_t *dis_ind = (bt_hdp_disconnected_t *)param->param_data;
1529
1530                         TC_PRT("BLUETOOTH_EVENT_HDP_DISCONNECTED, Result = %s\n", (param->result == 0)? "BLUETOOTH_ERROR_NONE": "BLUETOOTH_ERROR_XXXX");
1531                         TC_PRT("Channel = %d, Add = device add = %2.2X:%2.2X:%2.2X:%2.2X:%2.2X:%2.2X\n", dis_ind->channel_id,
1532                                                                 dis_ind->device_address.addr[0], dis_ind->device_address.addr[1], dis_ind->device_address.addr[2],
1533                                                                 dis_ind->device_address.addr[3], dis_ind->device_address.addr[4], dis_ind->device_address.addr[5]);
1534                         break;
1535                 }
1536
1537                 case BLUETOOTH_EVENT_HDP_DATA_RECEIVED:
1538                 {
1539                         bt_hdp_data_ind_t *data_ind = (bt_hdp_data_ind_t *)param->param_data;
1540
1541                         TC_PRT("BLUETOOTH_EVENT_HDP_DATA_RECEIVED, Result = %s\n", (param->result == 0)? "BLUETOOTH_ERROR_NONE": "BLUETOOTH_ERROR_XXXX");
1542                         TC_PRT("Data received from channel id = %d and  size =%d, buff =[%s]\n",  data_ind->channel_id, data_ind->size, data_ind->buffer);
1543
1544                         break;
1545                 }
1546
1547                 case BLUETOOTH_EVENT_OPC_CONNECTED:
1548                         TC_PRT("BLUETOOTH_EVENT_OPC_CONNECTED");
1549                         break;
1550
1551                 case BLUETOOTH_EVENT_OPC_DISCONNECTED:
1552                         TC_PRT("BLUETOOTH_EVENT_OPC_DISCONNECTED");
1553                         break;
1554                 case BLUETOOTH_EVENT_OPC_TRANSFER_STARTED:
1555                 {
1556                         TC_PRT("BLUETOOTH_EVENT_OPC_TRANSFER_STARTED");
1557                         if (param->param_data) {
1558                                 bt_opc_transfer_info_t *info = param->param_data;
1559                                 TC_PRT("file %s", info->filename);
1560                                 TC_PRT("size %ld", info->size);
1561                         }
1562                         break;
1563                 }
1564                 case BLUETOOTH_EVENT_OPC_TRANSFER_PROGRESS:
1565                 {
1566                         TC_PRT("BLUETOOTH_EVENT_OPC_TRANSFER_PROGRESS");
1567                         break;
1568                 }
1569                 case BLUETOOTH_EVENT_OPC_TRANSFER_COMPLETE:
1570                 {
1571                         TC_PRT("BLUETOOTH_EVENT_OPC_TRANSFER_COMPLETE");
1572                         bt_opc_transfer_info_t *info = param->param_data;
1573                         TC_PRT("file %s", info->filename);
1574                         TC_PRT("size %ld", info->size);
1575                         break;
1576                 }
1577
1578                 case BLUETOOTH_EVENT_OBEX_SERVER_TRANSFER_AUTHORIZE:
1579                         TC_PRT("BLUETOOTH_EVENT_OBEX_SERVER_TRANSFER_AUTHORIZE");
1580                         break;
1581
1582                 case BLUETOOTH_EVENT_OBEX_SERVER_CONNECTION_AUTHORIZE:
1583                         TC_PRT("BLUETOOTH_EVENT_OBEX_SERVER_CONNECTION_AUTHORIZE");
1584                         break;
1585
1586                 case BLUETOOTH_EVENT_OBEX_SERVER_TRANSFER_STARTED:
1587                         TC_PRT("BLUETOOTH_EVENT_OBEX_SERVER_TRANSFER_STARTED");
1588                         bt_obex_server_transfer_info_t *info = param->param_data;
1589                         current_transfer_id = info->transfer_id;
1590                         break;
1591
1592                 case BLUETOOTH_EVENT_OBEX_SERVER_TRANSFER_PROGRESS:
1593                         TC_PRT("BLUETOOTH_EVENT_OBEX_SERVER_TRANSFER_PROGRESS");
1594                         break;
1595
1596                 case BLUETOOTH_EVENT_OBEX_SERVER_TRANSFER_COMPLETED:
1597                         TC_PRT("BLUETOOTH_EVENT_OBEX_SERVER_TRANSFER_COMPLETED");
1598                         break;
1599                 case BLUETOOTH_EVENT_MANUFACTURER_DATA_CHANGED:
1600                 {       TC_PRT("BLUETOOTH_EVENT_MANUFACTURER_DATA_CHANGED");
1601                         break;
1602                 }
1603 #if 0
1604                 case BLUETOOTH_EVENT_GATT_PRIM_SVC_DISCOVERED:
1605                 {
1606                         TC_PRT("BLUETOOTH_EVENT_GATT_PRIM_SVC_DISCOVERED");
1607                         bt_gatt_handle_info_t *prim_svc = param->param_data;
1608                         int i;
1609
1610                         if (prim_svc == NULL) {
1611                                 TC_PRT("prim_svc is NULL");
1612                                 break;
1613                         }
1614
1615                         for (i = 0; i < prim_svc->count; i++) {
1616                                 TC_PRT("prim_svc[%d] = %s\n", i, prim_svc->handle[i]);
1617                         }
1618
1619                         break;
1620                 }
1621
1622                 case BLUETOOTH_EVENT_GATT_SVC_CHAR_DISCOVERED:
1623                 {
1624                         TC_PRT("BLUETOOTH_EVENT_GATT_SVC_CHAR_DISCOVERED");
1625                         bt_gatt_discovered_char_t *svc_char = param->param_data;
1626                         int i = 0;
1627
1628                         if (svc_char == NULL) {
1629                                 TC_PRT("svc_char is NULL");
1630                                 break;
1631                         }
1632
1633                         if (svc_char->service_handle != NULL) {
1634                                 TC_PRT("svc_char->service_handle %s \n", svc_char->service_handle);
1635                         }
1636
1637                         for (i = 0; i < svc_char->handle_info.count; i++) {
1638                                 TC_PRT("svc_char.handle_info.handle[%d] = %s\n", i, svc_char->handle_info.handle[i]);
1639                         }
1640
1641                         break;
1642                 }
1643
1644                 case BLUETOOTH_EVENT_GATT_SVC_PROP_RECEIVED:
1645                 {
1646                         TC_PRT("BLUETOOTH_EVENT_GATT_SVC_PROP_RECEIVED");
1647                         bt_gatt_service_property_t *svc_pty = param->param_data;
1648                         int i;
1649
1650                         if (svc_pty == NULL) {
1651                                 TC_PRT("char_pty is NULL \n");
1652                                 break;
1653                         }
1654
1655                         if (svc_pty->service_handle != NULL) {
1656                                 TC_PRT("svc_pty->service_handle %s \n", svc_pty->service_handle);
1657                         }
1658
1659                         if (svc_pty->uuid != NULL) {
1660                                 TC_PRT("svc_pty->uuid %s \n", svc_pty->uuid);
1661                         }
1662
1663                         for (i = 0; i < svc_pty->handle_info.count; i++) {
1664                                 TC_PRT("svc_char[%d] = %s\n", i, svc_pty->handle_info.handle[i]);
1665                         }
1666
1667                         break;
1668                 }
1669
1670                 case BLUETOOTH_EVENT_GATT_CHAR_PROP_RECEIVED:
1671                 {
1672                         TC_PRT("BLUETOOTH_EVENT_GATT_CHAR_PROP_RECEIVED");
1673                         bt_gatt_char_property_t *char_pty = param->param_data;
1674                         int i = 0;
1675
1676                         if (char_pty->char_handle != NULL) {
1677                                 TC_PRT("char_pty->char_handle %s \n", char_pty->char_handle);
1678                         }
1679
1680                         if (char_pty->uuid != NULL) {
1681                                 TC_PRT("char_pty->uuid %s \n", char_pty->uuid);
1682                         }
1683
1684                         if (char_pty == NULL) {
1685                                 TC_PRT("char_pty is NULL \n");
1686                                 break;
1687                         }
1688
1689                         if (char_pty->name != NULL) {
1690                                 TC_PRT("char_pty->name %s \n", char_pty->name);
1691                         }
1692
1693                         if (char_pty->description != NULL) {
1694                                 TC_PRT("char_pty->description %s \n", char_pty->description);
1695                         }
1696
1697                         if (char_pty->val != NULL) {
1698                                 TC_PRT("char_pty->val_len %d \n", char_pty->val_len);
1699
1700                                 for (i = 0; i < char_pty->val_len; i ++)
1701                                         TC_PRT("char_pty->val %02x \n", char_pty->val[i]);
1702                         }
1703
1704                         break;
1705                 }
1706 #endif
1707                 default:
1708                         TC_PRT("received event [0x%04x]", event);
1709                         break;
1710         }
1711         TC_PRT("<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<");
1712 }
1713
1714 static gboolean key_event_cb(GIOChannel * chan, GIOCondition cond , gpointer data)
1715 {
1716         char buf[10] = {0};
1717
1718         unsigned int len=0;
1719         int test_id;
1720         memset(buf, 0, sizeof(buf));
1721
1722         if(g_io_channel_read_chars(chan, buf, sizeof(buf),
1723                                 &len, NULL) == G_IO_STATUS_ERROR) {
1724                 TC_PRT("IO Channel read error");
1725                 return FALSE;
1726         }
1727
1728         printf("%s\n",buf);
1729         tc_usage_print();
1730
1731         test_id=atoi(buf);
1732
1733         if(test_id)
1734                 g_idle_add(test_input_callback, (void*)test_id);
1735
1736         return TRUE;
1737 }
1738
1739 int main(void)
1740 {
1741         startup();
1742
1743         GIOChannel *key_io;
1744         key_io=g_io_channel_unix_new(fileno(stdin));
1745
1746         g_io_channel_set_encoding(key_io, NULL, NULL);
1747         g_io_channel_set_flags(key_io, G_IO_FLAG_NONBLOCK, NULL);
1748
1749         g_io_add_watch(key_io, G_IO_IN | G_IO_HUP | G_IO_ERR | G_IO_NVAL,
1750                         key_event_cb, NULL);
1751         g_io_channel_unref(key_io);
1752
1753         g_main_loop_run(main_loop);
1754
1755         cleanup();
1756         return 0;
1757 }
1758