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