Fix svace 2.2 version issues
[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 <dbus/dbus-glib.h>
27 #include <pthread.h>
28 #include <dbus/dbus.h>
29 #include <stdint.h>
30
31 #include "bluetooth-api.h"
32 #include "bluetooth-hid-api.h"
33 #include "bluetooth-audio-api.h"
34
35
36 bluetooth_device_address_t searched_device = { {0} };
37
38 #define TC_TIMEOUT      30000
39
40 #define BT_DEFAULT_DEV_NAME "SLP-BT-TEST-TARGET"
41 #define DISCOVER_TIMEOUT 20
42 #define DISCOVER_CANCEL_INTERVAL 3
43
44 #define PRT(format, args...) printf("%s:() "format, __FUNCTION__, ##args)
45 #define TC_PRT(format, args...) PRT(format"\n", ##args)
46
47 #define TC_PASS 1
48 #define TC_FAIL 0
49 int client_fd = 0;
50 int server_fd = 0;
51 int g_ret_client_fd1 = -1, g_ret_client_fd2 = -1;
52 const char *g_hdp_app_handle1 =  NULL;
53 const char *g_hdp_app_handle2 =  NULL;
54
55 char *svc_obj_path = NULL;
56 char *char_obj_path = NULL;
57 char *desc_obj_path = NULL;
58
59 int selection;
60 int hdp_manual_mode =  1;
61 const char *rfcomm_test_uuid_spp = "00001101-0000-1000-8000-00805F9B34FB";
62 const char *rfcomm_test_uuid_dun = "00001103-0000-1000-8000-00805F9B34FB";
63 const char *rfcomm_test_uuid_custom = "26b2831b-2c2d-4f9c-914a-c0ab142351b7";
64
65
66 GMainLoop *main_loop = NULL;
67
68 int current_transfer_id = 0;
69
70 typedef struct {
71         bluetooth_device_address_t address;
72         bt_oob_data_t oob_data;
73 } oob_data_t;
74
75 oob_data_t g_local_oob_data;
76 oob_data_t g_remote_oob_data;
77
78
79 typedef struct {
80         const char *tc_name;
81         int tc_code;
82 } tc_table_t;
83
84 void bt_event_callback(int event, bluetooth_event_param_t* param, void *user_data);
85 void bt_hid_event_callback(int event, hid_event_param_t* param, void *user_data);
86 void bt_audio_event_callback(int event, bt_audio_event_param_t* param, void *user_data);
87
88
89 tc_table_t tc_table[] = {
90         {"bluetooth_register_callback"          , 1},
91         {"bluetooth_unregister_callback"        , 2},
92         {"bluetooth_enable_adapter"             , 3},
93         {"bluetooth_disable_adapter"            , 4},
94         {"bluetooth_check_adapter"              , 5},
95         {"bluetooth_get_local_address"          , 6},
96         {"bluetooth_get_local_name"             , 7},
97         {"bluetooth_set_local_name"             , 8},
98         {"bluetooth_get_local_version"          , 90},
99         {"bluetooth_is_service_used"            , 9},
100         {"bluetooth_get_discoverable_mode"      , 10},
101         {"bluetooth_set_discoverable_mode(CONNECTABLE)"                 , 11},
102         {"bluetooth_set_discoverable_mode(GENERAL_DISCOVERABLE)"        , 12},
103         {"bluetooth_set_discoverable_mode(TIME_LIMITED_DISCOVERABLE)"   , 13},
104         {"bluetooth_start_discovery"            , 14},
105         {"bluetooth_cancel_discovery"           , 15},
106         {"bluetooth_is_discovering"             , 16},
107         {"bluetooth_get_bonded_device_list"     , 17},
108         {"bluetooth_bond_device"                , 18},
109         {"bluetooth_cancel_bonding"             , 19},
110         {"bluetooth_unbond_device"      , 20},
111         {"bluetooth_get_bonded_device"  , 21},
112         {"bluetooth_set_alias"  , 22},
113         {"bluetooth_authorize_device (TRUE)"    , 23},
114         {"bluetooth_authorize_device (FALSE)"   , 24},
115         {"bluetooth_search_service"     , 25},
116         {"bluetooth_cancel_service_search"      , 26},
117         {"bluetooth_is_device_connected"        , 27},
118         {"bluetooth_reset_adapter"              , 28},
119         {"bluetooth_set_manufacturer_data" , 91},
120
121         {"bluetooth_audio_init" , 29},
122         {"bluetooth_audio_deinit" , 30},
123         {"bluetooth_audio_connect"      , 31},
124         {"bluetooth_audio_disconnect"   , 32},
125         {"bluetooth_ag_connect" , 33},
126         {"bluetooth_ag_disconnect" , 34},
127         {"bluetooth_av_connect" , 35},
128         {"bluetooth_av_disconnect"      , 36},
129         {"bluetooth_ag_get_headset_volume" , 37},
130         {"bluetooth_ag_set_speaker_gain" , 38},
131
132         {"bluetooth_oob_read_local_data"        , 39},
133         {"bluetooth_oob_add_remote_data" , 40},
134         {"bluetooth_oob_remove_remote_data" , 41},
135
136         {"bluetooth_opc_init"   , 42},
137         {"bluetooth_opc_deinit" , 43},
138         {"bluetooth_opc_push_files" , 44},
139         {"bluetooth_opc_cancel_push" , 45},
140         {"bluetooth_opc_session_is_exist" , 46},
141
142         {"bluetooth_network_activate_server"    , 47},
143         {"bluetooth_network_deactivate_server" , 48},
144         {"bluetooth_network_connect" , 49},
145         {"bluetooth_network_disconnect" , 50},
146
147         {"bluetooth_obex_server_init"   , 51},
148         {"bluetooth_obex_server_deinit" , 52},
149         {"bluetooth_obex_server_init_without_agent"     , 53},
150         {"bluetooth_obex_server_deinit_without_agent"   , 54},
151         {"bluetooth_obex_server_is_activated"   , 55},
152         {"bluetooth_obex_server_accept_connection"      , 56},
153         {"bluetooth_obex_server_reject_connection"      , 57},
154         {"bluetooth_obex_server_accept_authorize"       , 58},
155         {"bluetooth_obex_server_reject_authorize"       , 59},
156         {"bluetooth_obex_server_set_destination_path"   , 60},
157         {"bluetooth_obex_server_set_root"               , 61},
158         {"bluetooth_obex_server_cancel_transfer"        , 62},
159         {"bluetooth_obex_server_cancel_all_transfers"   , 63},
160
161         {"bluetooth_hid_init"   , 65},
162         {"bluetooth_hid_deinit" , 66},
163         {"bluetooth_hid_connect"        , 67},
164         {"bluetooth_hid_disconnect"     , 68},
165
166         {"bluetooth_rfcomm_connect"     , 70},
167         {"bluetooth_rfcomm_disconnect (cancel)" , 71},
168         {"bluetooth_rfcomm_disconnect"  , 72},
169         {"bluetooth_rfcomm_write"       , 73},
170         {"bluetooth_rfcomm_is_client_connected" , 74},
171
172         {"bluetooth_rfcomm_create_socket"       , 80},
173         {"bluetooth_rfcomm_create_socket (Custom UUID)" , 81},
174         {"bluetooth_rfcomm_remove_socket"       , 82},
175         {"bluetooth_rfcomm_listen_and_accept"   , 83},
176         {"bluetooth_rfcomm_listen (OSP)"        , 84},
177         {"bluetooth_rfcomm_server_disconnect"   , 85},
178         {"bluetooth_rfcomm_is_server_uuid_available"    , 86},
179         {"bluetooth_rfcomm_accept_connection"   , 87},
180         {"bluetooth_rfcomm_reject_connection"   , 88},
181         {"bluetooth_start_custom_discovery"     , 89},
182
183         {"bluetooth_gatt_init", 92},
184         {"bluetooth_gatt_deinit", 93},
185         {"bluetooth_gatt_add_service", 94},
186         {"bluetooth_gatt_add_characteristics", 95},
187         {"bluetooth_gatt_add_descriptor", 96},
188         {"bluetooth_gatt_register_service", 97},
189         {"bluetooth_gatt_update_characteristic", 98},
190         {"bluetooth_gatt_unregister_service", 99},
191         {"bluetooth_gatt_delete_services", 100},
192
193 #if 0
194         {"bluetooth_rfcomm_is_server_uuid_available"    , 26},
195
196         {"bluetooth_hdp_activate"       , 30},
197         {"bluetooth_hdp_deactivate"     , 31},
198         {"bluetooth_hdp_connect"        , 32},
199         {"bluetooth_hdp_disconnect"     , 33},
200         {"bluetooth_hdp_send_data"      , 34},
201
202         {"bluetooth_opc_init"           , 35},
203         {"bluetooth_opc_push_file"      , 36},
204         {"bluetooth_opc_cancel_push"    , 37},
205         {"bluetooth_opc_deinit"         , 38},
206         {"bluetooth_obex_server_init"   , 39},
207         {"bluetooth_obex_server_deinit" , 40},
208         {"bluetooth_obex_server_accept_authorize"       , 41},
209         {"bluetooth_obex_server_reject_authorize"       , 42},
210         {"bluetooth_is_supported"       , 43},
211         {"bluetooth_opc_session_is_exist"       , 46},
212         {"bluetooth_obex_server_is_activated"   , 47},
213         {"bluetooth_obex_server_cancel_transfer"        , 48},
214
215         {"bluetooth_oob_read_local_data"        , 50},
216         {"bluetooth_oob_add_remote_data"        , 51},
217         {"bluetooth_oob_remove_remote_data"     , 52},
218
219         {"bluetooth_network_activate_server"    , 60},
220         {"bluetooth_network_deactivate_server"  , 61},
221         {"bluetooth_network_connect"    , 62},
222         {"bluetooth_network_disconnect" , 63},
223
224         {"bluetooth_gatt_discover_primary_services", 64},
225         {"bluetooth_gatt_discover_service_characteristics",     65},
226         {"bluetooth_gatt_get_service_property",         66},
227         {"bluetooth_gatt_get_characteristics_value",    67},
228         {"bluetooth_gatt_set_characteristics_value",    68},
229 #endif
230         /* -----------------------------------------*/
231         {"Finish"                                                       , 0x00ff},
232         {NULL                                                           , 0x0000},
233
234 };
235
236 #if 0
237 #define tc_result(success, tc_index) \
238         TC_PRT("Test case [%d - %s] %s", tc_table[tc_index].tc_code, tc_table[tc_index].tc_name, ((success == TC_PASS) ? "Success" : "Failed"));
239 #else
240 #define tc_result(success, tc_index)
241 #endif
242
243 bluetooth_device_info_t bond_dev;
244 int is_bond_device = FALSE;
245
246 void tc_usage_print(void)
247 {
248         int i = 0;
249
250         while (tc_table[i].tc_name) {
251                 if (tc_table[i].tc_code != 0x00ff)
252                         TC_PRT("Key %d : usage %s", tc_table[i].tc_code, tc_table[i].tc_name);
253                 else
254                         TC_PRT("Key %d : usage %s\n\n", 0x00ff, tc_table[i].tc_name);
255
256                 i++;
257         }
258 }
259
260 int find_tc_number(int input)
261 {
262         int i = 0;
263
264         while (tc_table[i].tc_code != 0x0000) {
265                 if (tc_table[i].tc_code == input)
266                         return i;
267                 i++;
268         }
269
270         return -1;
271 }
272
273 int test_input_callback(void *data)
274 {
275         int ret = 0;
276         int test_id;
277
278 #ifdef ARCH64
279         test_id = find_tc_number((uintptr_t)data);
280 #else
281         test_id = find_tc_number((int)data);
282 #endif
283         if (test_id == -1)
284                 return 0;
285
286         TC_PRT("TC : %s[%d]", tc_table[test_id].tc_name, tc_table[test_id].tc_code);
287
288         switch (tc_table[test_id].tc_code) {
289         case 0x00ff:
290                 TC_PRT("Finished");
291                 g_main_loop_quit(main_loop);
292                 break;
293
294         case 1:
295                 ret = bluetooth_register_callback(bt_event_callback, NULL);
296                 if (ret < 0) {
297                         TC_PRT("%s failed with [0x%04x]", tc_table[0].tc_name, ret);
298                         tc_result(TC_FAIL, 1);
299                 }
300                 break;
301
302         case 2:
303                 ret = bluetooth_unregister_callback();
304                 if (ret < 0) {
305                         TC_PRT("%s failed with [0x%04x]", tc_table[1].tc_name, ret);
306                         tc_result(TC_FAIL, 1);
307                 }
308                 break;
309
310         case 3:
311         ret = bluetooth_enable_adapter();
312         if (ret < 0) {
313                         TC_PRT("%s failed with [0x%04x]", tc_table[2].tc_name, ret);
314                         tc_result(TC_FAIL, 1);
315                 }
316                 break;
317
318         case 4:
319                 ret = bluetooth_disable_adapter();
320                 if (ret < 0) {
321                         TC_PRT("%s failed with [0x%04x]", tc_table[3].tc_name, ret);
322                         tc_result(TC_FAIL, 2);
323                 }
324                 break;
325
326         case 5:
327         {
328                 ret = bluetooth_check_adapter();
329                 TC_PRT("state: %d", ret);
330                 break;
331         }
332
333         case 6:
334         {
335                 bluetooth_device_address_t address = { {0} };
336                 ret = bluetooth_get_local_address(&address);
337                 if (ret < 0) {
338                         TC_PRT("%s failed with [0x%04x]", tc_table[5].tc_name, ret);
339                 } else {
340                         TC_PRT("dev [%2.2X:%2.2X:%2.2X:%2.2X:%2.2X:%2.2X]", \
341                                 address.addr[0], address.addr[1], address.addr[2], \
342                                 address.addr[3], address.addr[4], address.addr[5]);
343                 }
344                 break;
345         }
346
347         case 7:
348         {
349                 bluetooth_device_name_t local_name = { {0} };
350                         ret = bluetooth_get_local_name(&local_name);
351                 if (ret < 0)
352                         TC_PRT("%s failed with [0x%04x]", tc_table[6].tc_name, ret);
353                 else
354                         TC_PRT("name: %s", local_name.name);
355
356                 break;
357         }
358
359         case 8:
360         {
361                 bluetooth_device_name_t local_name = { {0} };
362                 snprintf(local_name.name, sizeof(local_name.name),
363                         "bt-frwk-pid-%d", getpid());
364                 ret = bluetooth_set_local_name(&local_name);
365                 if (ret < 0)
366                         TC_PRT("%s failed with [0x%04x]", tc_table[7].tc_name, ret);
367
368                 break;
369         }
370
371         case 90:
372         {
373                 bluetooth_version_t local_version = { {0} };
374                 snprintf(local_version.version, sizeof(local_version.version),
375                                 "version%d", getpid());
376                         ret = bluetooth_get_local_version(&local_version);
377                 if (ret < 0)
378                         TC_PRT("%s failed with [0x%04x]", tc_table[89].tc_name, ret);
379                 else
380                         TC_PRT("version: %s", local_version.version);
381                 break;
382         }
383
384         case 9:
385         {
386                 gboolean used = FALSE;
387                         ret = bluetooth_is_service_used(rfcomm_test_uuid_spp, &used);
388                 if (ret < 0)
389                         TC_PRT("%s failed with [0x%04x]", tc_table[8].tc_name, ret);
390                 else
391                         TC_PRT("used: %d", used);
392                 break;
393         }
394
395         case 10:
396         {
397                 bluetooth_discoverable_mode_t mode;
398                 ret = bluetooth_get_discoverable_mode(&mode);
399                 if (ret < 0)
400                         TC_PRT("%s failed with [0x%04x]", tc_table[9].tc_name, ret);
401                 else
402                         TC_PRT("BT Get Discoverable mode [%d]", mode);
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                         TC_PRT("%s failed with [0x%04x]", tc_table[10].tc_name, ret);
412                 else
413                         TC_PRT("BT Set Discoverable mode [%d]", mode);
414                 break;
415         }
416
417         case 12:
418         {
419                 bluetooth_discoverable_mode_t mode = BLUETOOTH_DISCOVERABLE_MODE_GENERAL_DISCOVERABLE;
420                 ret = bluetooth_set_discoverable_mode(mode, 0);
421                 if (ret < 0)
422                         TC_PRT("%s failed with [0x%04x]", tc_table[11].tc_name, ret);
423                 else
424                         TC_PRT("BT Set Discoverable mode [%d]", mode);
425                 break;
426         }
427
428         case 13:
429         {
430                 bluetooth_discoverable_mode_t mode = BLUETOOTH_DISCOVERABLE_MODE_TIME_LIMITED_DISCOVERABLE;
431                 ret = bluetooth_set_discoverable_mode(mode, 5);
432                 if (ret < 0)
433                         TC_PRT("%s failed with [0x%04x]", tc_table[12].tc_name, ret);
434                 else
435                         TC_PRT("BT Set Discoverable mode [%d]", mode);
436                 break;
437         }
438
439         case 14:
440                 ret = bluetooth_start_discovery(0, 0, 0);
441                 if (ret < 0)
442                         TC_PRT("%s failed with [0x%04x]", tc_table[13].tc_name, ret);
443                 break;
444
445         case 15:
446                 ret = bluetooth_cancel_discovery();
447                 if (ret < 0)
448                         TC_PRT("%s failed with [0x%04x]", tc_table[14].tc_name, ret);
449                 break;
450
451         case 16:
452         {
453                 ret = bluetooth_is_discovering();
454                 if (ret < 0)
455                         TC_PRT("%s failed with [0x%04x]", tc_table[15].tc_name, ret);
456                 else
457                         TC_PRT("Discovering [%d]", ret);
458                 break;
459         }
460
461         case 17: /*Get paired device list */
462         {
463                 GPtrArray *devinfo = NULL;
464                 devinfo = g_ptr_array_new();
465                 TC_PRT("g pointer arrary count : [%d]", devinfo->len);
466
467                 ret = bluetooth_get_bonded_device_list(&devinfo);
468                 if (ret < 0) {
469                         TC_PRT("%s failed with [0x%04x]", tc_table[16].tc_name, ret);
470                 } else {
471                         int i;
472                         bluetooth_device_info_t *ptr;
473                         TC_PRT("g pointer arrary count : [%d]", devinfo->len);
474                                 for (i = 0; i < devinfo->len; i++) {
475                                 ptr = g_ptr_array_index(devinfo, i);
476                                 if (ptr != NULL) {
477                                         TC_PRT("Name [%s]", ptr->device_name.name);
478                                         TC_PRT("Major Class [%d]", ptr->device_class.major_class);
479                                         TC_PRT("Minor Class [%d]", ptr->device_class.minor_class);
480                                         TC_PRT("Service Class [%d]", ptr->device_class.service_class);
481                                         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]);
482                                         TC_PRT("\n");
483                                 }
484                         }
485                 }
486                 g_ptr_array_free(devinfo, TRUE);
487
488                 break;
489         }
490
491         case 18:
492         {
493                 bluetooth_device_address_t device_address = { {0xDC, 0x2C, 0x26, 0xD0, 0xF3, 0xC1} }; /* BT Keyboard */
494                         TC_PRT("dev [%2.2X:%2.2X:%2.2X:%2.2X:%2.2X:%2.2X]", \
495                         device_address.addr[0], device_address.addr[1], device_address.addr[2], \
496                         device_address.addr[3], device_address.addr[4], device_address.addr[5]);
497                         ret = bluetooth_bond_device(&device_address);
498                 if (ret < 0)
499                         TC_PRT("%s failed with [0x%04x]", tc_table[17].tc_name, ret);
500                         break;
501         }
502
503         case 19: /*Cancel bonding */
504         {
505                 ret = bluetooth_cancel_bonding();
506                 if (ret < 0)
507                         TC_PRT("%s failed with [0x%04x]", tc_table[18].tc_name, ret);
508                         break;
509         }
510
511         case 20: /*unbonding */
512         {
513                 bluetooth_device_address_t device_address = { {0x00, 0x19, 0x0E, 0x01, 0x61, 0x17} }; /* DO-DH79-PYUN04 */
514                 ret = bluetooth_unbond_device(&device_address);
515                 if (ret < 0)
516                         TC_PRT("%s failed with [0x%04x]", tc_table[19].tc_name, ret);
517                         break;
518         }
519
520         case 21: /*Get paired device */
521         {
522                 bluetooth_device_info_t devinfo;
523                 bluetooth_device_address_t device_address = { {0x00, 0x16, 0x38, 0xC3, 0x1F, 0xD2} };
524                         memset(&devinfo, 0x00, sizeof(bluetooth_device_info_t));
525                         ret = bluetooth_get_bonded_device(&device_address, &devinfo);
526                 if (ret != BLUETOOTH_ERROR_NONE) {
527                         TC_PRT("bluetooth_get_bonded_device failed with [%d]", ret);
528                 } else {
529                         TC_PRT("Name [%s]", devinfo.device_name.name);
530                         TC_PRT("Major Class [%d]", devinfo.device_class.major_class);
531                         TC_PRT("Minor Class [%d]", devinfo.device_class.minor_class);
532                         TC_PRT("Service Class [%d]", devinfo.device_class.service_class);
533                         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]);
534                 }
535
536                 break;
537         }
538
539         case 22: /*set alias for bonded device */
540         {
541                 bluetooth_device_address_t device_address = { {0x00, 0x16, 0x38, 0xC3, 0x1F, 0xD2} };
542
543                 ret = bluetooth_set_alias(&device_address, "Renamed device");
544                 if (ret < 0)
545                         TC_PRT("%s failed with [0x%04x]", tc_table[21].tc_name, ret);
546
547                 break;
548         }
549
550         case 23:
551         {
552                 bluetooth_device_address_t device_address = { {0x00, 0x16, 0x38, 0xC3, 0x1F, 0xD2} };
553                 ret = bluetooth_authorize_device(&device_address, TRUE);
554                 if (ret < 0)
555                         TC_PRT("%s failed with [0x%04x]", tc_table[22].tc_name, ret);
556
557                 break;
558         }
559
560         case 24:
561         {
562                 bluetooth_device_address_t device_address = { {0x00, 0x16, 0x38, 0xC3, 0x1F, 0xD2} };
563                 ret = bluetooth_authorize_device(&device_address, FALSE);
564                 if (ret < 0)
565                         TC_PRT("%s failed with [0x%04x]", tc_table[23].tc_name, ret);
566                         break;
567         }
568         case 25:
569         {
570                 bluetooth_device_address_t device_address = { {0x00, 0x16, 0x38, 0xC3, 0x1F, 0xD2} };
571
572                 ret = bluetooth_search_service(&device_address);
573                 if (ret < 0)
574                         TC_PRT("%s failed with [0x%04x]", tc_table[24].tc_name, ret);
575
576                 break;
577         }
578
579         case 26:
580         {
581                 ret = bluetooth_cancel_service_search();
582                 if (ret < 0)
583                         TC_PRT("%s failed with [0x%04x]", tc_table[24].tc_name, ret);
584                 break;
585         }
586
587         case 27:
588         {
589                 gboolean connected = FALSE;
590                 bluetooth_device_address_t device_address = { {0x00, 0x1B, 0x66, 0x01, 0x23, 0x1C} }; /* Gennheiser PX210BT */
591
592                 ret = bluetooth_is_device_connected(&device_address, BLUETOOTH_A2DP_SERVICE, &connected);
593                 if (ret < 0) {
594                         TC_PRT("%s failed with [0x%04x]", tc_table[24].tc_name, ret);
595                         TC_PRT("connected : %d", connected);
596                 }
597
598                 break;
599         }
600
601         case 28:
602         {
603                 ret = bluetooth_reset_adapter();
604                 if (ret < 0)
605                         TC_PRT("%s failed with [0x%04x]", tc_table[27].tc_name, ret);
606
607                 break;
608         }
609
610         case 91:
611         {
612                 bluetooth_manufacturer_data_t m_data;
613                 guint8 data[6]  = {0x05, 0xFF, 0x02, 0x03, 0x04, 0x05};
614                 TC_PRT("%x %x %x %x %x %x", data[0], data[1], data[2], data[3],
615                                 data[4], data[5]);
616
617                 memcpy(m_data.data, data, sizeof(data));
618                 m_data.data_len = sizeof(data) - 2;
619                 ret = bluetooth_set_manufacturer_data(&m_data);
620                 if (ret < 0)
621                         TC_PRT("%s failed with [0x%04x]", tc_table[90].tc_name, ret);
622                 break;
623         }
624
625         case 29:
626         {
627                 ret = bluetooth_audio_init(bt_audio_event_callback, NULL);
628                 if (ret < 0)
629                         TC_PRT("%s failed with [0x%04x]", tc_table[28].tc_name, ret);
630
631                 break;
632         }
633
634         case 30:
635         {
636                 ret = bluetooth_audio_deinit();
637                 if (ret < 0)
638                         TC_PRT("%s failed with [0x%04x]", tc_table[29].tc_name, ret);
639
640                 break;
641         }
642
643         case 31:
644         {
645                 bluetooth_device_address_t device_address = { {0x00, 0x0D, 0xFD, 0x24, 0x5E, 0xFF} }; /* Motorola S9 */
646
647                 ret = bluetooth_audio_connect(&device_address);
648                 if (ret < 0)
649                         TC_PRT("%s failed with [0x%04x]", tc_table[30].tc_name, ret);
650
651                 break;
652         }
653
654         case 32:
655         {
656                 bluetooth_device_address_t device_address = { {0x00, 0x0D, 0xFD, 0x24, 0x5E, 0xFF} }; /* Motorola S9 */
657
658                 ret = bluetooth_audio_disconnect(&device_address);
659                 if (ret < 0)
660                         TC_PRT("%s failed with [0x%04x]", tc_table[31].tc_name, ret);
661                 break;
662         }
663
664         case 33:
665         {
666                 /* MW600 */
667                 bluetooth_device_address_t device_address = { {0x58, 0x17, 0x0C, 0xEC, 0x6A, 0xF3} };
668
669                 ret = bluetooth_ag_connect(&device_address);
670                 if (ret < 0)
671                         TC_PRT("%s failed with [0x%04x]", tc_table[32].tc_name, ret);
672                 break;
673         }
674         case 34:
675         {
676                 /* MW600 */
677                 bluetooth_device_address_t device_address = { {0x58, 0x17, 0x0C, 0xEC, 0x6A, 0xF3} };
678
679                 ret = bluetooth_ag_disconnect(&device_address);
680                 if (ret < 0)
681                         TC_PRT("%s failed with [0x%04x]", tc_table[33].tc_name, ret);
682                 break;
683         }
684
685         case 35:
686         {
687                 /* MW600 */
688                 bluetooth_device_address_t device_address = { {0x58, 0x17, 0x0C, 0xEC, 0x6A, 0xF3} };
689
690                 ret = bluetooth_av_connect(&device_address);
691                 if (ret < 0)
692                         TC_PRT("%s failed with [0x%04x]", tc_table[34].tc_name, ret);
693                 break;
694         }
695
696         case 36:
697         {
698                 /* MW600 */
699                 bluetooth_device_address_t device_address = { {0x58, 0x17, 0x0C, 0xEC, 0x6A, 0xF3} };
700
701                 ret = bluetooth_av_disconnect(&device_address);
702                 if (ret < 0)
703                         TC_PRT("%s failed with [0x%04x]", tc_table[35].tc_name, ret);
704
705                 break;
706         }
707
708         case 37:
709         {
710                 unsigned int volume = 0;
711
712                 ret = bluetooth_ag_get_headset_volume(&volume);
713                 if (ret < 0) {
714                         TC_PRT("failed with [0x%04x]", ret);
715                         TC_PRT("volume: %d", volume);
716                 }
717
718                 break;
719         }
720
721         case 38:
722         {
723                 ret = bluetooth_ag_set_speaker_gain(10);
724                 if (ret < 0)
725                         TC_PRT("failed with [0x%04x]", ret);
726
727                 break;
728         }
729
730         case 39:
731         {
732                 if (bluetooth_oob_read_local_data(&g_local_oob_data.oob_data)) {
733                         TC_PRT("ERROR in bluetooth_oob_read_local_data\n");
734                 } else {
735                         TC_PRT("SUCESS in bluetooth_oob_read_local_data\n");
736                         TC_PRT("hash = [%2.2X:%2.2X:%2.2X:%2.2X:%2.2X:%2.2X:%2.2X:%2.2X"
737                                 "%2.2X:%2.2X:%2.2X:%2.2X:%2.2X:%2.2X:%2.2X:%2.2X]\n",
738                                 g_local_oob_data.oob_data.hash[0],
739                                 g_local_oob_data.oob_data.hash[1],
740                                 g_local_oob_data.oob_data.hash[2],
741                                 g_local_oob_data.oob_data.hash[3],
742                                 g_local_oob_data.oob_data.hash[4],
743                                 g_local_oob_data.oob_data.hash[5],
744                                 g_local_oob_data.oob_data.hash[6],
745                                 g_local_oob_data.oob_data.hash[7],
746                                 g_local_oob_data.oob_data.hash[8],
747                                 g_local_oob_data.oob_data.hash[9],
748                                 g_local_oob_data.oob_data.hash[10],
749                                 g_local_oob_data.oob_data.hash[11],
750                                 g_local_oob_data.oob_data.hash[12],
751                                 g_local_oob_data.oob_data.hash[13],
752                                 g_local_oob_data.oob_data.hash[14],
753                                 g_local_oob_data.oob_data.hash[15]);
754
755                         TC_PRT("randomizer = [%2.2X:%2.2X:%2.2X:%2.2X:%2.2X:%2.2X:%2.2X:%2.2X"
756                                 "%2.2X:%2.2X:%2.2X:%2.2X:%2.2X:%2.2X:%2.2X:%2.2X]\n",
757                                 g_local_oob_data.oob_data.randomizer[0],
758                                 g_local_oob_data.oob_data.randomizer[1],
759                                 g_local_oob_data.oob_data.randomizer[2],
760                                 g_local_oob_data.oob_data.randomizer[3],
761                                 g_local_oob_data.oob_data.randomizer[4],
762                                 g_local_oob_data.oob_data.randomizer[5],
763                                 g_local_oob_data.oob_data.randomizer[6],
764                                 g_local_oob_data.oob_data.randomizer[7],
765                                 g_local_oob_data.oob_data.randomizer[8],
766                                 g_local_oob_data.oob_data.randomizer[9],
767                                 g_local_oob_data.oob_data.randomizer[10],
768                                 g_local_oob_data.oob_data.randomizer[11],
769                                 g_local_oob_data.oob_data.randomizer[12],
770                                 g_local_oob_data.oob_data.randomizer[13],
771                                 g_local_oob_data.oob_data.randomizer[14],
772                                 g_local_oob_data.oob_data.randomizer[15]);
773
774                         TC_PRT("hash_len: %d\n", g_local_oob_data.oob_data.hash_len);
775                         TC_PRT("randomizer_len: %d\n", g_local_oob_data.oob_data.randomizer_len);
776                 }
777
778                 break;
779         }
780
781         case 40:
782         {
783                 ret = bluetooth_get_local_address(&g_local_oob_data.address);
784                 TC_PRT("hash_len: %d\n", g_local_oob_data.oob_data.hash_len);
785                 TC_PRT("randomizer_len: %d\n", g_local_oob_data.oob_data.randomizer_len);
786
787                 if (bluetooth_oob_add_remote_data(&g_local_oob_data.address,
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                 break;
1172         }
1173
1174         case 95:
1175         {
1176                 /* testing with dummy values*/
1177                 char *char_uuid = g_strdup("00002a06-0000-1000-8000-00805f9b34fb");
1178                 bt_gatt_permission_t perms = 0;
1179                 bt_gatt_characteristic_property_t props = BLUETOOTH_GATT_CHARACTERISTIC_PROPERTY_READ |
1180                                 BLUETOOTH_GATT_CHARACTERISTIC_PROPERTY_WRITE |
1181                                 BLUETOOTH_GATT_CHARACTERISTIC_PROPERTY_NOTIFY |
1182                                 BLUETOOTH_GATT_CHARACTERISTIC_PROPERTY_INDICATE;
1183
1184                 ret = bluetooth_gatt_add_new_characteristic(
1185                         svc_obj_path, char_uuid,
1186                         perms, props, &char_obj_path);
1187
1188                 TC_PRT("characteristic obj_path is %s", char_obj_path);
1189
1190                 break;
1191         }
1192
1193         case 96: {
1194                 char *desc_uuid = g_strdup("000026ff-0000-1000-8000-00805f9b34fb");
1195                 bt_gatt_permission_t perms = BLUETOOTH_GATT_PERMISSION_READ |
1196                                 BLUETOOTH_GATT_PERMISSION_WRITE;
1197
1198                 ret = bluetooth_gatt_add_descriptor(char_obj_path,
1199                         desc_uuid, perms, &desc_obj_path);
1200                 TC_PRT("add descriptor error is %d", ret);
1201
1202                 break;
1203         }
1204
1205         case 97: {
1206                 ret = bluetooth_gatt_register_service(svc_obj_path);
1207                 TC_PRT("register service error is %d", ret);
1208
1209                 break;
1210         }
1211
1212         case 98: {
1213                 ret = bluetooth_gatt_register_application();
1214
1215                 TC_PRT("register service error is %d", ret);
1216
1217                 break;
1218         }
1219
1220         case 99: {
1221                 char char_data[4] = {10, 20, 30, 40};
1222                 int char_length = 4;
1223                 ret = bluetooth_gatt_update_characteristic(char_obj_path,
1224                                         char_data, char_length);
1225
1226                 TC_PRT("update_characteristic error is %d", ret);
1227
1228                 break;
1229         }
1230
1231         case 100: {
1232                 ret = bluetooth_gatt_unregister_service(svc_obj_path);
1233                 TC_PRT("service removed with error is %d", ret);
1234
1235                 break;
1236         }
1237
1238         case 101:
1239                 ret = bluetooth_gatt_delete_services();
1240                 TC_PRT("services deleted with error is %d", ret);
1241
1242                 break;
1243
1244         default:
1245                 break;
1246         }
1247         return 0;
1248 }
1249
1250 void startup()
1251 {
1252         TC_PRT("bluetooth framework TC startup");
1253
1254         dbus_threads_init_default();
1255
1256         main_loop = g_main_loop_new(NULL, FALSE);
1257 }
1258
1259 void cleanup()
1260 {
1261         TC_PRT("bluetooth framework TC cleanup");
1262         if (main_loop != NULL)
1263                 g_main_loop_unref(main_loop);
1264 }
1265
1266 void bt_hid_event_callback(int event, hid_event_param_t* param, void *user_data)
1267 {
1268         TC_PRT(">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>");
1269         TC_PRT("bt event callback 0x%04x", event);
1270 }
1271
1272 void bt_audio_event_callback(int event, bt_audio_event_param_t* param, void *user_data)
1273 {
1274         TC_PRT(">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>");
1275         TC_PRT("bt event callback 0x%04x", event);
1276
1277
1278
1279 }
1280
1281 void bt_event_callback(int event, bluetooth_event_param_t* param, void *user_data)
1282 {
1283         TC_PRT(">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>");
1284         TC_PRT("bt event callback 0x%04x", event);
1285         switch (event) {
1286         case BLUETOOTH_EVENT_ENABLED:
1287                 TC_PRT("BLUETOOTH_EVENT_ENABLED, result [0x%04x]", param->result);
1288                 break;
1289
1290         case BLUETOOTH_EVENT_DISABLED:
1291                 TC_PRT("BLUETOOTH_EVENT_DISABLED, result [0x%04x]", param->result);
1292                 break;
1293
1294         case BLUETOOTH_EVENT_LOCAL_NAME_CHANGED:
1295                 TC_PRT("BLUETOOTH_EVENT_LOCAL_NAME_CHANGED, result [0x%04x]", param->result);
1296                 if (param->result == BLUETOOTH_ERROR_NONE) {
1297                         bluetooth_device_name_t *local_name = (bluetooth_device_name_t *)param->param_data;
1298                         tc_result(TC_PASS, 6);
1299                         TC_PRT("Changed Name : [%s]", local_name->name);
1300                 } else {
1301                         tc_result(TC_FAIL, 6);
1302                 }
1303                 break;
1304
1305         case BLUETOOTH_EVENT_DISCOVERY_STARTED:
1306                 TC_PRT("BLUETOOTH_EVENT_DISCOVERY_STARTED, result [0x%04x]", param->result);
1307                 break;
1308
1309         case BLUETOOTH_EVENT_REMOTE_DEVICE_FOUND:
1310         {
1311                 bluetooth_device_info_t *device_info = NULL;
1312                 TC_PRT("BLUETOOTH_EVENT_REMOTE_DEVICE_FOUND, result [0x%04x]", param->result);
1313                 device_info  = (bluetooth_device_info_t *)param->param_data;
1314                 memcpy(&searched_device, &device_info->device_address, sizeof(bluetooth_device_address_t));
1315                 TC_PRT("dev [%2.2X:%2.2X:%2.2X:%2.2X:%2.2X:%2.2X]", \
1316                         device_info->device_address.addr[0], device_info->device_address.addr[1], device_info->device_address.addr[2], \
1317                         device_info->device_address.addr[3], device_info->device_address.addr[4], device_info->device_address.addr[5]);
1318                 break;
1319         }
1320
1321         case BLUETOOTH_EVENT_REMOTE_LE_DEVICE_FOUND:
1322         {
1323                 int i;
1324                 bluetooth_le_device_info_t *le_device_info = NULL;
1325                 TC_PRT("BLUETOOTH_EVENT_REMOTE_LE_DEVICE_FOUND, result [0x%04x]", param->result);
1326                 le_device_info  = (bluetooth_le_device_info_t *)param->param_data;
1327                 TC_PRT("dev[%2.2X:%2.2X:%2.2X:%2.2X:%2.2X:%2.2X]", \
1328                         le_device_info->device_address.addr[0], le_device_info->device_address.addr[1], le_device_info->device_address.addr[2], \
1329                         le_device_info->device_address.addr[3], le_device_info->device_address.addr[4], le_device_info->device_address.addr[5]);
1330                 TC_PRT("addr_type : %d", le_device_info->addr_type);
1331                 TC_PRT("rssi : %d", le_device_info->rssi);
1332                 TC_PRT("adv_ind_data_len :%d" , le_device_info->adv_ind_data.data_len);
1333                 TC_PRT("scan_resp_data_len :%d" , le_device_info->scan_resp_data.data_len);
1334                 for (i = 0; i < le_device_info->adv_ind_data.data_len; i++)
1335                         TC_PRT("adv_ind_data[%d] : [0x%x]", i, le_device_info->adv_ind_data.data.data[i]);
1336                 for (i = 0; i < le_device_info->scan_resp_data.data_len; i++)
1337                         TC_PRT("scan_resp_data[%d] : [0x%x]", i, le_device_info->scan_resp_data.data.data[i]);
1338                 break;
1339         }
1340
1341         case BLUETOOTH_EVENT_REMOTE_DEVICE_NAME_UPDATED:
1342         {
1343                 bluetooth_device_info_t *device_info = NULL;
1344                 TC_PRT("BLUETOOTH_EVENT_REMOTE_DEVICE_NAME_UPDATED, result [0x%04x]", param->result);
1345                 device_info  = (bluetooth_device_info_t *)param->param_data;
1346                 memcpy(&searched_device, &device_info->device_address, sizeof(bluetooth_device_address_t));
1347                 TC_PRT("dev [%s] [%2.2X:%2.2X:%2.2X:%2.2X:%2.2X:%2.2X]", device_info->device_name.name, \
1348                         device_info->device_address.addr[0], device_info->device_address.addr[1], device_info->device_address.addr[2], \
1349                         device_info->device_address.addr[3], device_info->device_address.addr[4], device_info->device_address.addr[5]);
1350                 break;
1351         }
1352
1353         case BLUETOOTH_EVENT_DISCOVERY_FINISHED:
1354                 TC_PRT("BLUETOOTH_EVENT_DISCOVERY_FINISHED, result [0x%04x]", param->result);
1355                 break;
1356
1357         case BLUETOOTH_EVENT_DISCOVERABLE_MODE_CHANGED:
1358         {
1359                 int *mode = (int *)param->param_data;
1360                 TC_PRT("BT_DISCOVERABLE_MODE_CHANGED, result [0x%04x]", param->result);
1361                 TC_PRT("mode [%d]", *mode);
1362                 break;
1363         }
1364
1365         case BLUETOOTH_EVENT_DISCOVERABLE_TIMEOUT_CHANGED:
1366         {
1367                 int *timeout = (int *)param->param_data;
1368                 TC_PRT("BLUETOOTH_EVENT_DISCOVERABLE_TIMEOUT_CHANGED, result [0x%04x]", param->result);
1369                 TC_PRT("timeout [%d]", *timeout);
1370                 break;
1371         }
1372
1373         case BLUETOOTH_EVENT_BONDING_FINISHED:
1374         {
1375                 TC_PRT("BLUETOOTH_EVENT_BONDING_FINISHED, result [0x%04x]", param->result);
1376                 if (param->result >= BLUETOOTH_ERROR_NONE) {
1377                         bluetooth_device_info_t *device_info = NULL;
1378                         tc_result(TC_PASS, 12);
1379                         device_info = (bluetooth_device_info_t *)param->param_data;
1380                 if (device_info == NULL)
1381                         break;
1382                         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, \
1383                                 device_info->device_address.addr[0], device_info->device_address.addr[1], device_info->device_address.addr[2], \
1384                                 device_info->device_address.addr[3], device_info->device_address.addr[4], device_info->device_address.addr[5], \
1385                                 device_info->device_class.major_class, device_info->device_class.minor_class, device_info->device_class.service_class);
1386                 } else {
1387                         tc_result(TC_FAIL, 12);
1388                 }
1389                         break;
1390         }
1391
1392         case BLUETOOTH_EVENT_BONDED_DEVICE_FOUND:
1393         {
1394                 // bluetooth_get_bonded_device_list is changed as synchronous API. This event is not used any more.
1395                 // 2011.01.06
1396 #if 0
1397 //              int i = 0;
1398                 TC_PRT("BLUETOOTH_EVENT_BONDED_DEVICE_FOUND, result [0x%04x]", param->result);
1399                 if (param->result >= BLUETOOTH_ERROR_NONE) {
1400                         ///tc_result(TC_PASS, 15);
1401                         bluetooth_device_info_t * bt_dev_info = (bluetooth_device_info_t*)param->param_data;
1402                                 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,
1403                                 bt_dev_info->device_address.addr[0], bt_dev_info->device_address.addr[1], bt_dev_info->device_address.addr[2], \
1404                                 bt_dev_info->device_address.addr[3], bt_dev_info->device_address.addr[4], bt_dev_info->device_address.addr[5], \
1405                                 bt_dev_info->device_class.major_class, bt_dev_info->device_class.minor_class, bt_dev_info->device_class.service_class);
1406
1407                 } else if (param->result == BLUETOOTH_ERROR_END_OF_DEVICE_LIST) /*End of the Device found indication*/ {
1408                         tc_result(TC_PASS, 15);
1409                         TC_PRT("*****<<No more BLUETOOTH_EVENT_BONDED_DEVICE_FOUND indication>>***** ");
1410                 } else {
1411                         tc_result(TC_FAIL, 15);
1412                         TC_PRT("*****API failed ***** ");
1413                 }
1414 #endif
1415                 break;
1416         }
1417
1418         case BLUETOOTH_EVENT_SERVICE_SEARCHED:
1419         {
1420                 int i = 0;
1421                 TC_PRT("BLUETOOTH_EVENT_SERVICE_SEARCHED, result [0x%04x]", param->result);
1422                 if (param->result >= BLUETOOTH_ERROR_NONE) {
1423                         tc_result(TC_PASS, 18);
1424                         bt_sdp_info_t *bt_sdp_info = param->param_data;
1425
1426                         TC_PRT("Dev add = %2.2X:%2.2X:%2.2X:%2.2X:%2.2X:%2.2X\n",
1427                                 bt_sdp_info->device_addr.addr[0], bt_sdp_info->device_addr.addr[1], bt_sdp_info->device_addr.addr[2], \
1428                                 bt_sdp_info->device_addr.addr[3], bt_sdp_info->device_addr.addr[4], bt_sdp_info->device_addr.addr[5]);
1429
1430                                 TC_PRT("Supported service list:\n");
1431                                 for (i = 0; i < bt_sdp_info->service_index; i++)
1432                                         TC_PRT("[%#x]\n", bt_sdp_info->service_list_array[i]);
1433
1434                 } else {
1435                         tc_result(TC_FAIL, 18);
1436                 }
1437                 break;
1438         }
1439
1440         case BLUETOOTH_EVENT_RFCOMM_DATA_RECEIVED:
1441         {
1442                 TC_PRT("BLUETOOTH_EVENT_RFCOMM_DATA_RECEIVED, result [0x%04x]", param->result);
1443                 bluetooth_rfcomm_received_data_t *rx_data = param->param_data;
1444                 printf("\n FD = %d \nBuffer len = %d ", rx_data->socket_fd, rx_data->buffer_size);
1445                 if (rx_data->buffer_size < sizeof(oob_data_t))
1446                         TC_PRT("Complete oob data is not recivedn");
1447                 else
1448                         memcpy(&g_remote_oob_data, rx_data->buffer, sizeof(oob_data_t));
1449                 //tc_result(TC_PASS, 21);
1450                 break;
1451         }
1452
1453         case BLUETOOTH_EVENT_RFCOMM_CONNECTED:
1454         {
1455                 bluetooth_rfcomm_connection_t *con_ind = (bluetooth_rfcomm_connection_t *)param->param_data;
1456                 TC_PRT("BLUETOOTH_EVENT_RFCOMM_CONNECTED, result [0x%04x], fd = %d, device add = 0x%X:%X:%X:%X:%X:%X, Role = %s", param->result,
1457                                                         con_ind->socket_fd,
1458                                                         con_ind->device_addr.addr[0], con_ind->device_addr.addr[1], con_ind->device_addr.addr[2],
1459                                                         con_ind->device_addr.addr[3], con_ind->device_addr.addr[4], con_ind->device_addr.addr[5],
1460                                                         (con_ind->device_role == RFCOMM_ROLE_SERVER) ? "SERVER" : "CLIENT");
1461                 //tc_result(TC_PASS, 22);
1462                 if ((con_ind->device_role == RFCOMM_ROLE_CLIENT) && (con_ind->socket_fd > 0))
1463                         g_ret_client_fd1 = con_ind->socket_fd;
1464
1465                 if ((con_ind->device_role == RFCOMM_ROLE_SERVER) && (con_ind->socket_fd > 0))
1466                         client_fd = con_ind->socket_fd;
1467
1468                 break;
1469         }
1470
1471         case BLUETOOTH_EVENT_RFCOMM_DISCONNECTED:
1472         {
1473                 bluetooth_rfcomm_disconnection_t *disconnection_ind = (bluetooth_rfcomm_disconnection_t *)param->param_data;;
1474                 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,
1475                                                                                                         disconnection_ind->device_addr.addr[0], disconnection_ind->device_addr.addr[1], disconnection_ind->device_addr.addr[2],
1476                                                                                                         disconnection_ind->device_addr.addr[3], disconnection_ind->device_addr.addr[4], disconnection_ind->device_addr.addr[5]);
1477                 //tc_result(TC_PASS, 22);
1478                 break;
1479         }
1480
1481         case BLUETOOTH_EVENT_NETWORK_SERVER_CONNECTED:
1482         {
1483                 bluetooth_network_device_info_t *dev_info = (bluetooth_network_device_info_t *)param->param_data;
1484
1485                 TC_PRT("BLUETOOTH_EVENT_RFCOMM_DISCONNECTED, result [0x%04x]", param->result);
1486                 TC_PRT("interface name: %s", dev_info->interface_name);
1487
1488                 TC_PRT("device add = %2.2X:%2.2X:%2.2X:%2.2X:%2.2X:%2.2X\n",
1489                                                         dev_info->device_address.addr[0], dev_info->device_address.addr[1], dev_info->device_address.addr[2],
1490                                                         dev_info->device_address.addr[3], dev_info->device_address.addr[4], dev_info->device_address.addr[5]);
1491                 break;
1492         }
1493
1494         case BLUETOOTH_EVENT_NETWORK_SERVER_DISCONNECTED:
1495         {
1496                 bluetooth_network_device_info_t *dev_info = (bluetooth_network_device_info_t *)param->param_data;
1497
1498                 TC_PRT("BLUETOOTH_EVENT_RFCOMM_DISCONNECTED, result [0x%04x]", param->result);
1499                 TC_PRT("interface name: %s", dev_info->interface_name);
1500
1501                 TC_PRT("device add = %2.2X:%2.2X:%2.2X:%2.2X:%2.2X:%2.2X\n",
1502                                                         dev_info->device_address.addr[0], dev_info->device_address.addr[1], dev_info->device_address.addr[2],
1503                                                         dev_info->device_address.addr[3], dev_info->device_address.addr[4], dev_info->device_address.addr[5]);
1504                 break;
1505         }
1506
1507         case BLUETOOTH_EVENT_HDP_CONNECTED:
1508         {
1509                 bt_hdp_connected_t *conn_ind = (bt_hdp_connected_t *)param->param_data;
1510
1511                 TC_PRT("BLUETOOTH_EVENT_HDP_CONNECTED, Result = %s\n", (param->result == 0) ? "BLUETOOTH_ERROR_NONE" : "BLUETOOTH_ERROR_XXXX");
1512                 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");
1513                 TC_PRT("device add = %2.2X:%2.2X:%2.2X:%2.2X:%2.2X:%2.2X\n",
1514                                                         conn_ind->device_address.addr[0], conn_ind->device_address.addr[1], conn_ind->device_address.addr[2],
1515                                                         conn_ind->device_address.addr[3], conn_ind->device_address.addr[4], conn_ind->device_address.addr[5]);
1516
1517                 g_ret_client_fd1 = conn_ind->channel_id;
1518                 break;
1519         }
1520
1521         case BLUETOOTH_EVENT_HDP_DISCONNECTED:
1522         {
1523                 bt_hdp_disconnected_t *dis_ind = (bt_hdp_disconnected_t *)param->param_data;
1524
1525                 TC_PRT("BLUETOOTH_EVENT_HDP_DISCONNECTED, Result = %s\n", (param->result == 0) ? "BLUETOOTH_ERROR_NONE" : "BLUETOOTH_ERROR_XXXX");
1526                 TC_PRT("Channel = %d, Add = device add = %2.2X:%2.2X:%2.2X:%2.2X:%2.2X:%2.2X\n", dis_ind->channel_id,
1527                                                         dis_ind->device_address.addr[0], dis_ind->device_address.addr[1], dis_ind->device_address.addr[2],
1528                                                         dis_ind->device_address.addr[3], dis_ind->device_address.addr[4], dis_ind->device_address.addr[5]);
1529                 break;
1530         }
1531
1532         case BLUETOOTH_EVENT_HDP_DATA_RECEIVED:
1533         {
1534                 bt_hdp_data_ind_t *data_ind = (bt_hdp_data_ind_t *)param->param_data;
1535
1536                 TC_PRT("BLUETOOTH_EVENT_HDP_DATA_RECEIVED, Result = %s\n", (param->result == 0) ? "BLUETOOTH_ERROR_NONE" : "BLUETOOTH_ERROR_XXXX");
1537                 TC_PRT("Data received from channel id = %d and  size =%d, buff =[%s]\n",  data_ind->channel_id, data_ind->size, data_ind->buffer);
1538
1539                 break;
1540         }
1541
1542         case BLUETOOTH_EVENT_OPC_CONNECTED:
1543                 TC_PRT("BLUETOOTH_EVENT_OPC_CONNECTED");
1544                 break;
1545
1546         case BLUETOOTH_EVENT_OPC_DISCONNECTED:
1547                 TC_PRT("BLUETOOTH_EVENT_OPC_DISCONNECTED");
1548                 break;
1549         case BLUETOOTH_EVENT_OPC_TRANSFER_STARTED:
1550         {
1551                 TC_PRT("BLUETOOTH_EVENT_OPC_TRANSFER_STARTED");
1552                 if (param->param_data) {
1553                         bt_opc_transfer_info_t *info = param->param_data;
1554                         TC_PRT("file %s", info->filename);
1555                         TC_PRT("size %ld", info->size);
1556                 }
1557                 break;
1558         }
1559         case BLUETOOTH_EVENT_OPC_TRANSFER_PROGRESS:
1560         {
1561                 TC_PRT("BLUETOOTH_EVENT_OPC_TRANSFER_PROGRESS");
1562                 break;
1563         }
1564         case BLUETOOTH_EVENT_OPC_TRANSFER_COMPLETE:
1565         {
1566                 TC_PRT("BLUETOOTH_EVENT_OPC_TRANSFER_COMPLETE");
1567                 bt_opc_transfer_info_t *info = param->param_data;
1568                 TC_PRT("file %s", info->filename);
1569                 TC_PRT("size %ld", info->size);
1570                 break;
1571         }
1572
1573         case BLUETOOTH_EVENT_OBEX_SERVER_TRANSFER_AUTHORIZE:
1574                 TC_PRT("BLUETOOTH_EVENT_OBEX_SERVER_TRANSFER_AUTHORIZE");
1575                 break;
1576
1577         case BLUETOOTH_EVENT_OBEX_SERVER_CONNECTION_AUTHORIZE:
1578                 TC_PRT("BLUETOOTH_EVENT_OBEX_SERVER_CONNECTION_AUTHORIZE");
1579                 break;
1580
1581         case BLUETOOTH_EVENT_OBEX_SERVER_TRANSFER_STARTED:
1582                 TC_PRT("BLUETOOTH_EVENT_OBEX_SERVER_TRANSFER_STARTED");
1583                 bt_obex_server_transfer_info_t *info = param->param_data;
1584                 current_transfer_id = info->transfer_id;
1585                 break;
1586
1587         case BLUETOOTH_EVENT_OBEX_SERVER_TRANSFER_PROGRESS:
1588                 TC_PRT("BLUETOOTH_EVENT_OBEX_SERVER_TRANSFER_PROGRESS");
1589                 break;
1590
1591         case BLUETOOTH_EVENT_OBEX_SERVER_TRANSFER_COMPLETED:
1592                 TC_PRT("BLUETOOTH_EVENT_OBEX_SERVER_TRANSFER_COMPLETED");
1593                 break;
1594         case BLUETOOTH_EVENT_MANUFACTURER_DATA_CHANGED:
1595         {       TC_PRT("BLUETOOTH_EVENT_MANUFACTURER_DATA_CHANGED");
1596                 break;
1597         }
1598 #if 0
1599         case BLUETOOTH_EVENT_GATT_PRIM_SVC_DISCOVERED:
1600         {
1601                 TC_PRT("BLUETOOTH_EVENT_GATT_PRIM_SVC_DISCOVERED");
1602                 bt_gatt_handle_info_t *prim_svc = param->param_data;
1603                 int i;
1604
1605                 if (prim_svc == NULL) {
1606                         TC_PRT("prim_svc is NULL");
1607                         break;
1608                 }
1609
1610                 for (i = 0; i < prim_svc->count; i++)
1611                         TC_PRT("prim_svc[%d] = %s\n", i, prim_svc->handle[i]);
1612
1613                 break;
1614         }
1615
1616         case BLUETOOTH_EVENT_GATT_SVC_CHAR_DISCOVERED:
1617         {
1618                 TC_PRT("BLUETOOTH_EVENT_GATT_SVC_CHAR_DISCOVERED");
1619                 bt_gatt_discovered_char_t *svc_char = param->param_data;
1620                 int i = 0;
1621
1622                 if (svc_char == NULL) {
1623                         TC_PRT("svc_char is NULL");
1624                         break;
1625                 }
1626
1627                 if (svc_char->service_handle != NULL)
1628                         TC_PRT("svc_char->service_handle %s \n", svc_char->service_handle);
1629
1630                 for (i = 0; i < svc_char->handle_info.count; i++)
1631                         TC_PRT("svc_char.handle_info.handle[%d] = %s\n", i, svc_char->handle_info.handle[i]);
1632
1633                 break;
1634         }
1635
1636         case BLUETOOTH_EVENT_GATT_SVC_PROP_RECEIVED:
1637         {
1638                 TC_PRT("BLUETOOTH_EVENT_GATT_SVC_PROP_RECEIVED");
1639                 bt_gatt_service_property_t *svc_pty = param->param_data;
1640                 int i;
1641
1642                 if (svc_pty == NULL) {
1643                         TC_PRT("char_pty is NULL \n");
1644                         break;
1645                 }
1646
1647                 if (svc_pty->service_handle != NULL)
1648                         TC_PRT("svc_pty->service_handle %s \n", svc_pty->service_handle);
1649
1650                 if (svc_pty->uuid != NULL)
1651                         TC_PRT("svc_pty->uuid %s \n", svc_pty->uuid);
1652
1653                 for (i = 0; i < svc_pty->handle_info.count; i++)
1654                         TC_PRT("svc_char[%d] = %s\n", i, svc_pty->handle_info.handle[i]);
1655
1656                 break;
1657         }
1658
1659         case BLUETOOTH_EVENT_GATT_CHAR_PROP_RECEIVED:
1660         {
1661                 TC_PRT("BLUETOOTH_EVENT_GATT_CHAR_PROP_RECEIVED");
1662                 bt_gatt_char_property_t *char_pty = param->param_data;
1663                 int i = 0;
1664
1665                 if (char_pty->char_handle != NULL)
1666                         TC_PRT("char_pty->char_handle %s \n", char_pty->char_handle);
1667
1668                 if (char_pty->uuid != NULL)
1669                         TC_PRT("char_pty->uuid %s \n", char_pty->uuid);
1670
1671                 if (char_pty == NULL) {
1672                         TC_PRT("char_pty is NULL \n");
1673                         break;
1674                 }
1675
1676                 if (char_pty->name != NULL)
1677                         TC_PRT("char_pty->name %s \n", char_pty->name);
1678
1679                 if (char_pty->description != NULL)
1680                         TC_PRT("char_pty->description %s \n", char_pty->description);
1681
1682                 if (char_pty->val != NULL) {
1683                         TC_PRT("char_pty->val_len %d \n", char_pty->val_len);
1684
1685                         for (i = 0; i < char_pty->val_len; i++)
1686                                 TC_PRT("char_pty->val %02x \n", char_pty->val[i]);
1687                 }
1688
1689                 break;
1690         }
1691 #endif
1692         case BLUETOOTH_EVENT_KEYBOARD_PASSKEY_DISPLAY:
1693         {
1694                 bluetooth_authentication_request_info_t *auth_info = param->param_data;
1695
1696                 TC_PRT("BLUETOOTH_EVENT_KEYBOARD_PASSKEY_DISPLAY");
1697                 TC_PRT("Device Address: [%2.2X:%2.2X:%2.2X:%2.2X:%2.2X:%2.2X]",
1698                         auth_info->device_address.addr[0], auth_info->device_address.addr[1],
1699                         auth_info->device_address.addr[2], auth_info->device_address.addr[3],
1700                         auth_info->device_address.addr[4], auth_info->device_address.addr[5]);
1701                 TC_PRT("Device Name : [%s]", auth_info->device_name.name);
1702                 TC_PRT("Passkey: [%s]", auth_info->str_passkey);
1703                 break;
1704         }
1705         case BLUETOOTH_EVENT_PIN_REQUEST:
1706         {
1707                 bluetooth_authentication_request_info_t *auth_info = param->param_data;
1708
1709                 TC_PRT("BLUETOOTH_EVENT_PIN_REQUEST");
1710                 TC_PRT("Device Address: [%2.2X:%2.2X:%2.2X:%2.2X:%2.2X:%2.2X]",
1711                         auth_info->device_address.addr[0], auth_info->device_address.addr[1],
1712                         auth_info->device_address.addr[2], auth_info->device_address.addr[3],
1713                         auth_info->device_address.addr[4], auth_info->device_address.addr[5]);
1714                 TC_PRT("Device Name : [%s]", auth_info->device_name.name);
1715
1716                 TC_PRT("bluetooth_passkey_reply(\"0000\", TRUE)");
1717                 bluetooth_passkey_reply("0000", TRUE);
1718                 break;
1719         }
1720         case BLUETOOTH_EVENT_PASSKEY_REQUEST:
1721         {
1722                 bluetooth_authentication_request_info_t *auth_info = param->param_data;
1723
1724                 TC_PRT("BLUETOOTH_EVENT_PASSKEY_REQUEST");
1725                 TC_PRT("Device Address: [%2.2X:%2.2X:%2.2X:%2.2X:%2.2X:%2.2X]",
1726                         auth_info->device_address.addr[0], auth_info->device_address.addr[1],
1727                         auth_info->device_address.addr[2], auth_info->device_address.addr[3],
1728                         auth_info->device_address.addr[4], auth_info->device_address.addr[5]);
1729                 TC_PRT("Device Name : [%s]", auth_info->device_name.name);
1730
1731                 TC_PRT("bluetooth_passkey_reply(\"0000\", TRUE)");
1732                 bluetooth_passkey_reply("0000", TRUE);
1733                 break;
1734         }
1735         case BLUETOOTH_EVENT_PASSKEY_CONFIRM_REQUEST:
1736         {
1737                 bluetooth_authentication_request_info_t *auth_info = param->param_data;
1738
1739                 TC_PRT("BLUETOOTH_EVENT_PASSKEY_CONFIRM_REQUEST");
1740                 TC_PRT("Device Address: [%2.2X:%2.2X:%2.2X:%2.2X:%2.2X:%2.2X]",
1741                         auth_info->device_address.addr[0], auth_info->device_address.addr[1],
1742                         auth_info->device_address.addr[2], auth_info->device_address.addr[3],
1743                         auth_info->device_address.addr[4], auth_info->device_address.addr[5]);
1744                 TC_PRT("Device Name : [%s]", auth_info->device_name.name);
1745                 TC_PRT("Passkey: [%s]", auth_info->str_passkey);
1746
1747                 TC_PRT("bluetooth_passkey_confirmation_reply: TRUE");
1748                 bluetooth_passkey_confirmation_reply(TRUE);
1749                 break;
1750         }
1751         default:
1752                 TC_PRT("received event [0x%04x]", event);
1753                 break;
1754         }
1755         TC_PRT("<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<");
1756 }
1757
1758 static gboolean key_event_cb(GIOChannel * chan, GIOCondition cond , gpointer data)
1759 {
1760         char buf[49] = {0};
1761
1762 #ifdef ARCH64
1763         unsigned long len = 0;
1764 #else
1765         unsigned int len = 0;
1766 #endif
1767         int test_id;
1768         memset(buf, 0, sizeof(buf));
1769
1770         if (g_io_channel_read_chars(chan, buf, sizeof(buf),
1771                                 &len, NULL) == G_IO_STATUS_ERROR) {
1772                 TC_PRT("IO Channel read error");
1773                 return FALSE;
1774         }
1775
1776         printf("%s\n", buf);
1777         tc_usage_print();
1778
1779         test_id = atoi(buf);
1780
1781 #ifdef ARCH64
1782         g_idle_add(test_input_callback, (void *)(uintptr_t)test_id);
1783 #else
1784         g_idle_add(test_input_callback, (void *)test_id);
1785 #endif
1786
1787         return TRUE;
1788 }
1789
1790 int main(void)
1791 {
1792         startup();
1793
1794         GIOChannel *key_io;
1795         key_io = g_io_channel_unix_new(fileno(stdin));
1796
1797         g_io_channel_set_encoding(key_io, NULL, NULL);
1798         g_io_channel_set_flags(key_io, G_IO_FLAG_NONBLOCK, NULL);
1799
1800         g_io_add_watch(key_io, G_IO_IN | G_IO_HUP | G_IO_ERR | G_IO_NVAL,
1801                         key_event_cb, NULL);
1802         g_io_channel_unref(key_io);
1803
1804         g_main_loop_run(main_loop);
1805
1806         cleanup();
1807         return 0;
1808 }
1809