Remove wrong dependency in the systemd service file
[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 #if TODO_40
1148                 ret = bluetooth_gatt_init();
1149                 if (ret < 0)
1150                         TC_PRT("gatt init failed with [0x%04x]", ret);
1151 #endif
1152                 break;
1153         }
1154
1155         case 93:
1156         {
1157 #if TODO_40
1158                 ret = bluetooth_gatt_deinit();
1159                 if (ret < 0)
1160                         TC_PRT("gatt deinit failed with [0x%04x]", ret);
1161 #endif
1162                 break;
1163         }
1164
1165         case 94:
1166         {
1167 #if TODO_40
1168                 char *service_uuid = g_strdup("00001802-0000-1000-8000-00805f9b34fb");
1169
1170                 ret = bluetooth_gatt_add_service(service_uuid,
1171                         &svc_obj_path);
1172
1173                 TC_PRT("service obj_path is %s", svc_obj_path);
1174 #endif
1175                 break;
1176         }
1177
1178         case 95:
1179         {
1180 #if TODO_40
1181                 /* testing with dummy values*/
1182                 char *char_uuid = g_strdup("00002a06-0000-1000-8000-00805f9b34fb");
1183                 bt_gatt_permission_t perms = 0;
1184                 bt_gatt_characteristic_property_t props = BLUETOOTH_GATT_CHARACTERISTIC_PROPERTY_READ |
1185                                 BLUETOOTH_GATT_CHARACTERISTIC_PROPERTY_WRITE |
1186                                 BLUETOOTH_GATT_CHARACTERISTIC_PROPERTY_NOTIFY |
1187                                 BLUETOOTH_GATT_CHARACTERISTIC_PROPERTY_INDICATE;
1188
1189                 ret = bluetooth_gatt_add_new_characteristic(
1190                         svc_obj_path, char_uuid,
1191                         perms, props, &char_obj_path);
1192
1193                 TC_PRT("characteristic obj_path is %s", char_obj_path);
1194 #endif
1195                 break;
1196         }
1197
1198         case 96: {
1199 #if TODO_40
1200                 char *desc_uuid = g_strdup("000026ff-0000-1000-8000-00805f9b34fb");
1201                 bt_gatt_permission_t perms = BLUETOOTH_GATT_PERMISSION_READ |
1202                                 BLUETOOTH_GATT_PERMISSION_WRITE;
1203
1204                 ret = bluetooth_gatt_add_descriptor(char_obj_path,
1205                         desc_uuid, perms, &desc_obj_path);
1206                 TC_PRT("add descriptor error is %d", ret);
1207 #endif
1208                 break;
1209         }
1210
1211         case 97: {
1212 #if TODO_40
1213                 ret = bluetooth_gatt_register_service(svc_obj_path);
1214                 TC_PRT("register service error is %d", ret);
1215 #endif
1216                 break;
1217         }
1218
1219         case 98: {
1220 #if TODO_40
1221                 ret = bluetooth_gatt_register_application();
1222
1223                 TC_PRT("register service error is %d", ret);
1224 #endif
1225                 break;
1226         }
1227
1228         case 99: {
1229 #if TODO_40
1230                 char char_data[4] = {10, 20, 30, 40};
1231                 int char_length = 4;
1232                 ret = bluetooth_gatt_update_characteristic(char_obj_path,
1233                                         char_data, char_length);
1234
1235                 TC_PRT("update_characteristic error is %d", ret);
1236 #endif
1237                 break;
1238         }
1239
1240         case 100: {
1241 #if TODO_40
1242                 ret = bluetooth_gatt_unregister_service(svc_obj_path);
1243                 TC_PRT("service removed with error is %d", ret);
1244 #endif
1245                 break;
1246         }
1247
1248         case 101:
1249 #if TODO_40
1250                 ret = bluetooth_gatt_delete_services();
1251                 TC_PRT("services deleted with error is %d", ret);
1252 #endif
1253                 break;
1254
1255         default:
1256                 break;
1257         }
1258         return 0;
1259 }
1260
1261 void startup()
1262 {
1263         TC_PRT("bluetooth framework TC startup");
1264
1265         main_loop = g_main_loop_new(NULL, FALSE);
1266 }
1267
1268 void cleanup()
1269 {
1270         TC_PRT("bluetooth framework TC cleanup");
1271         if (main_loop != NULL)
1272                 g_main_loop_unref(main_loop);
1273 }
1274
1275 void bt_hid_event_callback(int event, hid_event_param_t* param, void *user_data)
1276 {
1277         TC_PRT(">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>");
1278         TC_PRT("bt event callback 0x%04x", event);
1279 }
1280
1281 void bt_audio_event_callback(int event, bt_audio_event_param_t* param, void *user_data)
1282 {
1283         TC_PRT(">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>");
1284         TC_PRT("bt event callback 0x%04x", event);
1285
1286
1287
1288 }
1289
1290 void bt_event_callback(int event, bluetooth_event_param_t* param, void *user_data)
1291 {
1292         TC_PRT(">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>");
1293         TC_PRT("bt event callback 0x%04x", event);
1294         switch (event) {
1295         case BLUETOOTH_EVENT_ENABLED:
1296                 TC_PRT("BLUETOOTH_EVENT_ENABLED, result [0x%04x]", param->result);
1297                 break;
1298
1299         case BLUETOOTH_EVENT_DISABLED:
1300                 TC_PRT("BLUETOOTH_EVENT_DISABLED, result [0x%04x]", param->result);
1301                 break;
1302
1303         case BLUETOOTH_EVENT_LOCAL_NAME_CHANGED:
1304                 TC_PRT("BLUETOOTH_EVENT_LOCAL_NAME_CHANGED, result [0x%04x]", param->result);
1305                 if (param->result == BLUETOOTH_ERROR_NONE) {
1306                         bluetooth_device_name_t *local_name = (bluetooth_device_name_t *)param->param_data;
1307                         tc_result(TC_PASS, 6);
1308                         TC_PRT("Changed Name : [%s]", local_name->name);
1309                 } else {
1310                         tc_result(TC_FAIL, 6);
1311                 }
1312                 break;
1313
1314         case BLUETOOTH_EVENT_DISCOVERY_STARTED:
1315                 TC_PRT("BLUETOOTH_EVENT_DISCOVERY_STARTED, result [0x%04x]", param->result);
1316                 break;
1317
1318         case BLUETOOTH_EVENT_REMOTE_DEVICE_FOUND:
1319         {
1320                 bluetooth_device_info_t *device_info = NULL;
1321                 TC_PRT("BLUETOOTH_EVENT_REMOTE_DEVICE_FOUND, result [0x%04x]", param->result);
1322                 device_info  = (bluetooth_device_info_t *)param->param_data;
1323                 memcpy(&searched_device, &device_info->device_address, sizeof(bluetooth_device_address_t));
1324                 TC_PRT("dev [%2.2X:%2.2X:%2.2X:%2.2X:%2.2X:%2.2X]", \
1325                         device_info->device_address.addr[0], device_info->device_address.addr[1], device_info->device_address.addr[2], \
1326                         device_info->device_address.addr[3], device_info->device_address.addr[4], device_info->device_address.addr[5]);
1327                 break;
1328         }
1329
1330         case BLUETOOTH_EVENT_REMOTE_LE_DEVICE_FOUND:
1331         {
1332                 int i;
1333                 bluetooth_le_device_info_t *le_device_info = NULL;
1334                 TC_PRT("BLUETOOTH_EVENT_REMOTE_LE_DEVICE_FOUND, result [0x%04x]", param->result);
1335                 le_device_info  = (bluetooth_le_device_info_t *)param->param_data;
1336                 TC_PRT("dev[%2.2X:%2.2X:%2.2X:%2.2X:%2.2X:%2.2X]", \
1337                         le_device_info->device_address.addr[0], le_device_info->device_address.addr[1], le_device_info->device_address.addr[2], \
1338                         le_device_info->device_address.addr[3], le_device_info->device_address.addr[4], le_device_info->device_address.addr[5]);
1339                 TC_PRT("addr_type : %d", le_device_info->addr_type);
1340                 TC_PRT("rssi : %d", le_device_info->rssi);
1341                 TC_PRT("adv_ind_data_len :%d" , le_device_info->adv_ind_data.data_len);
1342                 TC_PRT("scan_resp_data_len :%d" , le_device_info->scan_resp_data.data_len);
1343                 for (i = 0; i < le_device_info->adv_ind_data.data_len; i++)
1344                         TC_PRT("adv_ind_data[%d] : [0x%x]", i, le_device_info->adv_ind_data.data.data[i]);
1345                 for (i = 0; i < le_device_info->scan_resp_data.data_len; i++)
1346                         TC_PRT("scan_resp_data[%d] : [0x%x]", i, le_device_info->scan_resp_data.data.data[i]);
1347                 break;
1348         }
1349
1350         case BLUETOOTH_EVENT_REMOTE_DEVICE_NAME_UPDATED:
1351         {
1352                 bluetooth_device_info_t *device_info = NULL;
1353                 TC_PRT("BLUETOOTH_EVENT_REMOTE_DEVICE_NAME_UPDATED, result [0x%04x]", param->result);
1354                 device_info  = (bluetooth_device_info_t *)param->param_data;
1355                 memcpy(&searched_device, &device_info->device_address, sizeof(bluetooth_device_address_t));
1356                 TC_PRT("dev [%s] [%2.2X:%2.2X:%2.2X:%2.2X:%2.2X:%2.2X]", device_info->device_name.name, \
1357                         device_info->device_address.addr[0], device_info->device_address.addr[1], device_info->device_address.addr[2], \
1358                         device_info->device_address.addr[3], device_info->device_address.addr[4], device_info->device_address.addr[5]);
1359                 break;
1360         }
1361
1362         case BLUETOOTH_EVENT_DISCOVERY_FINISHED:
1363                 TC_PRT("BLUETOOTH_EVENT_DISCOVERY_FINISHED, result [0x%04x]", param->result);
1364                 break;
1365
1366         case BLUETOOTH_EVENT_DISCOVERABLE_MODE_CHANGED:
1367         {
1368                 int *mode = (int *)param->param_data;
1369                 TC_PRT("BT_DISCOVERABLE_MODE_CHANGED, result [0x%04x]", param->result);
1370                 TC_PRT("mode [%d]", *mode);
1371                 break;
1372         }
1373
1374         case BLUETOOTH_EVENT_DISCOVERABLE_TIMEOUT_CHANGED:
1375         {
1376                 int *timeout = (int *)param->param_data;
1377                 TC_PRT("BLUETOOTH_EVENT_DISCOVERABLE_TIMEOUT_CHANGED, result [0x%04x]", param->result);
1378                 TC_PRT("timeout [%d]", *timeout);
1379                 break;
1380         }
1381
1382         case BLUETOOTH_EVENT_BONDING_FINISHED:
1383         {
1384                 TC_PRT("BLUETOOTH_EVENT_BONDING_FINISHED, result [0x%04x]", param->result);
1385                 if (param->result >= BLUETOOTH_ERROR_NONE) {
1386                         bluetooth_device_info_t *device_info = NULL;
1387                         tc_result(TC_PASS, 12);
1388                         device_info = (bluetooth_device_info_t *)param->param_data;
1389                 if (device_info == NULL)
1390                         break;
1391                         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, \
1392                                 device_info->device_address.addr[0], device_info->device_address.addr[1], device_info->device_address.addr[2], \
1393                                 device_info->device_address.addr[3], device_info->device_address.addr[4], device_info->device_address.addr[5], \
1394                                 device_info->device_class.major_class, device_info->device_class.minor_class, device_info->device_class.service_class);
1395                 } else {
1396                         tc_result(TC_FAIL, 12);
1397                 }
1398                         break;
1399         }
1400
1401         case BLUETOOTH_EVENT_BONDED_DEVICE_FOUND:
1402         {
1403                 // bluetooth_get_bonded_device_list is changed as synchronous API. This event is not used any more.
1404                 // 2011.01.06
1405 #if 0
1406 //              int i = 0;
1407                 TC_PRT("BLUETOOTH_EVENT_BONDED_DEVICE_FOUND, result [0x%04x]", param->result);
1408                 if (param->result >= BLUETOOTH_ERROR_NONE) {
1409                         ///tc_result(TC_PASS, 15);
1410                         bluetooth_device_info_t * bt_dev_info = (bluetooth_device_info_t*)param->param_data;
1411                                 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,
1412                                 bt_dev_info->device_address.addr[0], bt_dev_info->device_address.addr[1], bt_dev_info->device_address.addr[2], \
1413                                 bt_dev_info->device_address.addr[3], bt_dev_info->device_address.addr[4], bt_dev_info->device_address.addr[5], \
1414                                 bt_dev_info->device_class.major_class, bt_dev_info->device_class.minor_class, bt_dev_info->device_class.service_class);
1415
1416                 } else if (param->result == BLUETOOTH_ERROR_END_OF_DEVICE_LIST) /*End of the Device found indication*/ {
1417                         tc_result(TC_PASS, 15);
1418                         TC_PRT("*****<<No more BLUETOOTH_EVENT_BONDED_DEVICE_FOUND indication>>***** ");
1419                 } else {
1420                         tc_result(TC_FAIL, 15);
1421                         TC_PRT("*****API failed ***** ");
1422                 }
1423 #endif
1424                 break;
1425         }
1426
1427         case BLUETOOTH_EVENT_SERVICE_SEARCHED:
1428         {
1429                 int i = 0;
1430                 TC_PRT("BLUETOOTH_EVENT_SERVICE_SEARCHED, result [0x%04x]", param->result);
1431                 if (param->result >= BLUETOOTH_ERROR_NONE) {
1432                         tc_result(TC_PASS, 18);
1433                         bt_sdp_info_t *bt_sdp_info = param->param_data;
1434
1435                         TC_PRT("Dev add = %2.2X:%2.2X:%2.2X:%2.2X:%2.2X:%2.2X\n",
1436                                 bt_sdp_info->device_addr.addr[0], bt_sdp_info->device_addr.addr[1], bt_sdp_info->device_addr.addr[2], \
1437                                 bt_sdp_info->device_addr.addr[3], bt_sdp_info->device_addr.addr[4], bt_sdp_info->device_addr.addr[5]);
1438
1439                                 TC_PRT("Supported service list:\n");
1440                                 for (i = 0; i < bt_sdp_info->service_index; i++)
1441                                         TC_PRT("[%#x]\n", bt_sdp_info->service_list_array[i]);
1442
1443                 } else {
1444                         tc_result(TC_FAIL, 18);
1445                 }
1446                 break;
1447         }
1448
1449         case BLUETOOTH_EVENT_RFCOMM_DATA_RECEIVED:
1450         {
1451                 TC_PRT("BLUETOOTH_EVENT_RFCOMM_DATA_RECEIVED, result [0x%04x]", param->result);
1452                 bluetooth_rfcomm_received_data_t *rx_data = param->param_data;
1453                 printf("\n FD = %d \nBuffer len = %d ", rx_data->socket_fd, rx_data->buffer_size);
1454                 if (rx_data->buffer_size < sizeof(oob_data_t))
1455                         TC_PRT("Complete oob data is not recivedn");
1456                 else
1457                         memcpy(&g_remote_oob_data, rx_data->buffer, sizeof(oob_data_t));
1458                 //tc_result(TC_PASS, 21);
1459                 break;
1460         }
1461
1462         case BLUETOOTH_EVENT_RFCOMM_CONNECTED:
1463         {
1464                 bluetooth_rfcomm_connection_t *con_ind = (bluetooth_rfcomm_connection_t *)param->param_data;
1465                 TC_PRT("BLUETOOTH_EVENT_RFCOMM_CONNECTED, result [0x%04x], fd = %d, device add = 0x%X:%X:%X:%X:%X:%X, Role = %s", param->result,
1466                                                         con_ind->socket_fd,
1467                                                         con_ind->device_addr.addr[0], con_ind->device_addr.addr[1], con_ind->device_addr.addr[2],
1468                                                         con_ind->device_addr.addr[3], con_ind->device_addr.addr[4], con_ind->device_addr.addr[5],
1469                                                         (con_ind->device_role == RFCOMM_ROLE_SERVER) ? "SERVER" : "CLIENT");
1470                 //tc_result(TC_PASS, 22);
1471                 if ((con_ind->device_role == RFCOMM_ROLE_CLIENT) && (con_ind->socket_fd > 0))
1472                         g_ret_client_fd1 = con_ind->socket_fd;
1473
1474                 if ((con_ind->device_role == RFCOMM_ROLE_SERVER) && (con_ind->socket_fd > 0))
1475                         client_fd = con_ind->socket_fd;
1476
1477                 break;
1478         }
1479
1480         case BLUETOOTH_EVENT_RFCOMM_DISCONNECTED:
1481         {
1482                 bluetooth_rfcomm_disconnection_t *disconnection_ind = (bluetooth_rfcomm_disconnection_t *)param->param_data;;
1483                 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,
1484                                                                                                         disconnection_ind->device_addr.addr[0], disconnection_ind->device_addr.addr[1], disconnection_ind->device_addr.addr[2],
1485                                                                                                         disconnection_ind->device_addr.addr[3], disconnection_ind->device_addr.addr[4], disconnection_ind->device_addr.addr[5]);
1486                 //tc_result(TC_PASS, 22);
1487                 break;
1488         }
1489
1490         case BLUETOOTH_EVENT_NETWORK_SERVER_CONNECTED:
1491         {
1492                 bluetooth_network_device_info_t *dev_info = (bluetooth_network_device_info_t *)param->param_data;
1493
1494                 TC_PRT("BLUETOOTH_EVENT_RFCOMM_DISCONNECTED, result [0x%04x]", param->result);
1495                 TC_PRT("interface name: %s", dev_info->interface_name);
1496
1497                 TC_PRT("device add = %2.2X:%2.2X:%2.2X:%2.2X:%2.2X:%2.2X\n",
1498                                                         dev_info->device_address.addr[0], dev_info->device_address.addr[1], dev_info->device_address.addr[2],
1499                                                         dev_info->device_address.addr[3], dev_info->device_address.addr[4], dev_info->device_address.addr[5]);
1500                 break;
1501         }
1502
1503         case BLUETOOTH_EVENT_NETWORK_SERVER_DISCONNECTED:
1504         {
1505                 bluetooth_network_device_info_t *dev_info = (bluetooth_network_device_info_t *)param->param_data;
1506
1507                 TC_PRT("BLUETOOTH_EVENT_RFCOMM_DISCONNECTED, result [0x%04x]", param->result);
1508                 TC_PRT("interface name: %s", dev_info->interface_name);
1509
1510                 TC_PRT("device add = %2.2X:%2.2X:%2.2X:%2.2X:%2.2X:%2.2X\n",
1511                                                         dev_info->device_address.addr[0], dev_info->device_address.addr[1], dev_info->device_address.addr[2],
1512                                                         dev_info->device_address.addr[3], dev_info->device_address.addr[4], dev_info->device_address.addr[5]);
1513                 break;
1514         }
1515
1516         case BLUETOOTH_EVENT_HDP_CONNECTED:
1517         {
1518                 bt_hdp_connected_t *conn_ind = (bt_hdp_connected_t *)param->param_data;
1519
1520                 TC_PRT("BLUETOOTH_EVENT_HDP_CONNECTED, Result = %s\n", (param->result == 0) ? "BLUETOOTH_ERROR_NONE" : "BLUETOOTH_ERROR_XXXX");
1521                 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");
1522                 TC_PRT("device add = %2.2X:%2.2X:%2.2X:%2.2X:%2.2X:%2.2X\n",
1523                                                         conn_ind->device_address.addr[0], conn_ind->device_address.addr[1], conn_ind->device_address.addr[2],
1524                                                         conn_ind->device_address.addr[3], conn_ind->device_address.addr[4], conn_ind->device_address.addr[5]);
1525
1526                 g_ret_client_fd1 = conn_ind->channel_id;
1527                 break;
1528         }
1529
1530         case BLUETOOTH_EVENT_HDP_DISCONNECTED:
1531         {
1532                 bt_hdp_disconnected_t *dis_ind = (bt_hdp_disconnected_t *)param->param_data;
1533
1534                 TC_PRT("BLUETOOTH_EVENT_HDP_DISCONNECTED, Result = %s\n", (param->result == 0) ? "BLUETOOTH_ERROR_NONE" : "BLUETOOTH_ERROR_XXXX");
1535                 TC_PRT("Channel = %d, Add = device add = %2.2X:%2.2X:%2.2X:%2.2X:%2.2X:%2.2X\n", dis_ind->channel_id,
1536                                                         dis_ind->device_address.addr[0], dis_ind->device_address.addr[1], dis_ind->device_address.addr[2],
1537                                                         dis_ind->device_address.addr[3], dis_ind->device_address.addr[4], dis_ind->device_address.addr[5]);
1538                 break;
1539         }
1540
1541         case BLUETOOTH_EVENT_HDP_DATA_RECEIVED:
1542         {
1543                 bt_hdp_data_ind_t *data_ind = (bt_hdp_data_ind_t *)param->param_data;
1544
1545                 TC_PRT("BLUETOOTH_EVENT_HDP_DATA_RECEIVED, Result = %s\n", (param->result == 0) ? "BLUETOOTH_ERROR_NONE" : "BLUETOOTH_ERROR_XXXX");
1546                 TC_PRT("Data received from channel id = %d and  size =%d, buff =[%s]\n",  data_ind->channel_id, data_ind->size, data_ind->buffer);
1547
1548                 break;
1549         }
1550
1551         case BLUETOOTH_EVENT_OPC_CONNECTED:
1552                 TC_PRT("BLUETOOTH_EVENT_OPC_CONNECTED");
1553                 break;
1554
1555         case BLUETOOTH_EVENT_OPC_DISCONNECTED:
1556                 TC_PRT("BLUETOOTH_EVENT_OPC_DISCONNECTED");
1557                 break;
1558         case BLUETOOTH_EVENT_OPC_TRANSFER_STARTED:
1559         {
1560                 TC_PRT("BLUETOOTH_EVENT_OPC_TRANSFER_STARTED");
1561                 if (param->param_data) {
1562                         bt_opc_transfer_info_t *info = param->param_data;
1563                         TC_PRT("file %s", info->filename);
1564                         TC_PRT("size %ld", info->size);
1565                 }
1566                 break;
1567         }
1568         case BLUETOOTH_EVENT_OPC_TRANSFER_PROGRESS:
1569         {
1570                 TC_PRT("BLUETOOTH_EVENT_OPC_TRANSFER_PROGRESS");
1571                 break;
1572         }
1573         case BLUETOOTH_EVENT_OPC_TRANSFER_COMPLETE:
1574         {
1575                 TC_PRT("BLUETOOTH_EVENT_OPC_TRANSFER_COMPLETE");
1576                 bt_opc_transfer_info_t *info = param->param_data;
1577                 TC_PRT("file %s", info->filename);
1578                 TC_PRT("size %ld", info->size);
1579                 break;
1580         }
1581
1582         case BLUETOOTH_EVENT_OBEX_SERVER_TRANSFER_AUTHORIZE:
1583                 TC_PRT("BLUETOOTH_EVENT_OBEX_SERVER_TRANSFER_AUTHORIZE");
1584                 break;
1585
1586         case BLUETOOTH_EVENT_OBEX_SERVER_CONNECTION_AUTHORIZE:
1587                 TC_PRT("BLUETOOTH_EVENT_OBEX_SERVER_CONNECTION_AUTHORIZE");
1588                 break;
1589
1590         case BLUETOOTH_EVENT_OBEX_SERVER_TRANSFER_STARTED:
1591                 TC_PRT("BLUETOOTH_EVENT_OBEX_SERVER_TRANSFER_STARTED");
1592                 bt_obex_server_transfer_info_t *info = param->param_data;
1593                 current_transfer_id = info->transfer_id;
1594                 break;
1595
1596         case BLUETOOTH_EVENT_OBEX_SERVER_TRANSFER_PROGRESS:
1597                 TC_PRT("BLUETOOTH_EVENT_OBEX_SERVER_TRANSFER_PROGRESS");
1598                 break;
1599
1600         case BLUETOOTH_EVENT_OBEX_SERVER_TRANSFER_COMPLETED:
1601                 TC_PRT("BLUETOOTH_EVENT_OBEX_SERVER_TRANSFER_COMPLETED");
1602                 break;
1603         case BLUETOOTH_EVENT_MANUFACTURER_DATA_CHANGED:
1604         {       TC_PRT("BLUETOOTH_EVENT_MANUFACTURER_DATA_CHANGED");
1605                 break;
1606         }
1607 #if 0
1608         case BLUETOOTH_EVENT_GATT_PRIM_SVC_DISCOVERED:
1609         {
1610                 TC_PRT("BLUETOOTH_EVENT_GATT_PRIM_SVC_DISCOVERED");
1611                 bt_gatt_handle_info_t *prim_svc = param->param_data;
1612                 int i;
1613
1614                 if (prim_svc == NULL) {
1615                         TC_PRT("prim_svc is NULL");
1616                         break;
1617                 }
1618
1619                 for (i = 0; i < prim_svc->count; i++)
1620                         TC_PRT("prim_svc[%d] = %s\n", i, prim_svc->handle[i]);
1621
1622                 break;
1623         }
1624
1625         case BLUETOOTH_EVENT_GATT_SVC_CHAR_DISCOVERED:
1626         {
1627                 TC_PRT("BLUETOOTH_EVENT_GATT_SVC_CHAR_DISCOVERED");
1628                 bt_gatt_discovered_char_t *svc_char = param->param_data;
1629                 int i = 0;
1630
1631                 if (svc_char == NULL) {
1632                         TC_PRT("svc_char is NULL");
1633                         break;
1634                 }
1635
1636                 if (svc_char->service_handle != NULL)
1637                         TC_PRT("svc_char->service_handle %s \n", svc_char->service_handle);
1638
1639                 for (i = 0; i < svc_char->handle_info.count; i++)
1640                         TC_PRT("svc_char.handle_info.handle[%d] = %s\n", i, svc_char->handle_info.handle[i]);
1641
1642                 break;
1643         }
1644
1645         case BLUETOOTH_EVENT_GATT_SVC_PROP_RECEIVED:
1646         {
1647                 TC_PRT("BLUETOOTH_EVENT_GATT_SVC_PROP_RECEIVED");
1648                 bt_gatt_service_property_t *svc_pty = param->param_data;
1649                 int i;
1650
1651                 if (svc_pty == NULL) {
1652                         TC_PRT("char_pty is NULL \n");
1653                         break;
1654                 }
1655
1656                 if (svc_pty->service_handle != NULL)
1657                         TC_PRT("svc_pty->service_handle %s \n", svc_pty->service_handle);
1658
1659                 if (svc_pty->uuid != NULL)
1660                         TC_PRT("svc_pty->uuid %s \n", svc_pty->uuid);
1661
1662                 for (i = 0; i < svc_pty->handle_info.count; i++)
1663                         TC_PRT("svc_char[%d] = %s\n", i, svc_pty->handle_info.handle[i]);
1664
1665                 break;
1666         }
1667
1668         case BLUETOOTH_EVENT_GATT_CHAR_PROP_RECEIVED:
1669         {
1670                 TC_PRT("BLUETOOTH_EVENT_GATT_CHAR_PROP_RECEIVED");
1671                 bt_gatt_char_property_t *char_pty = param->param_data;
1672                 int i = 0;
1673
1674                 if (char_pty->char_handle != NULL)
1675                         TC_PRT("char_pty->char_handle %s \n", char_pty->char_handle);
1676
1677                 if (char_pty->uuid != NULL)
1678                         TC_PRT("char_pty->uuid %s \n", char_pty->uuid);
1679
1680                 if (char_pty == NULL) {
1681                         TC_PRT("char_pty is NULL \n");
1682                         break;
1683                 }
1684
1685                 if (char_pty->name != NULL)
1686                         TC_PRT("char_pty->name %s \n", char_pty->name);
1687
1688                 if (char_pty->description != NULL)
1689                         TC_PRT("char_pty->description %s \n", char_pty->description);
1690
1691                 if (char_pty->val != NULL) {
1692                         TC_PRT("char_pty->val_len %d \n", char_pty->val_len);
1693
1694                         for (i = 0; i < char_pty->val_len; i++)
1695                                 TC_PRT("char_pty->val %02x \n", char_pty->val[i]);
1696                 }
1697
1698                 break;
1699         }
1700 #endif
1701         case BLUETOOTH_EVENT_KEYBOARD_PASSKEY_DISPLAY:
1702         {
1703                 bluetooth_authentication_request_info_t *auth_info = param->param_data;
1704
1705                 TC_PRT("BLUETOOTH_EVENT_KEYBOARD_PASSKEY_DISPLAY");
1706                 TC_PRT("Device Address: [%2.2X:%2.2X:%2.2X:%2.2X:%2.2X:%2.2X]",
1707                         auth_info->device_address.addr[0], auth_info->device_address.addr[1],
1708                         auth_info->device_address.addr[2], auth_info->device_address.addr[3],
1709                         auth_info->device_address.addr[4], auth_info->device_address.addr[5]);
1710                 TC_PRT("Device Name : [%s]", auth_info->device_name.name);
1711                 TC_PRT("Passkey: [%s]", auth_info->str_passkey);
1712                 break;
1713         }
1714         case BLUETOOTH_EVENT_PIN_REQUEST:
1715         {
1716                 bluetooth_authentication_request_info_t *auth_info = param->param_data;
1717
1718                 TC_PRT("BLUETOOTH_EVENT_PIN_REQUEST");
1719                 TC_PRT("Device Address: [%2.2X:%2.2X:%2.2X:%2.2X:%2.2X:%2.2X]",
1720                         auth_info->device_address.addr[0], auth_info->device_address.addr[1],
1721                         auth_info->device_address.addr[2], auth_info->device_address.addr[3],
1722                         auth_info->device_address.addr[4], auth_info->device_address.addr[5]);
1723                 TC_PRT("Device Name : [%s]", auth_info->device_name.name);
1724
1725                 TC_PRT("bluetooth_passkey_reply(\"0000\", TRUE)");
1726                 bluetooth_passkey_reply("0000", TRUE);
1727                 break;
1728         }
1729         case BLUETOOTH_EVENT_PASSKEY_REQUEST:
1730         {
1731                 bluetooth_authentication_request_info_t *auth_info = param->param_data;
1732
1733                 TC_PRT("BLUETOOTH_EVENT_PASSKEY_REQUEST");
1734                 TC_PRT("Device Address: [%2.2X:%2.2X:%2.2X:%2.2X:%2.2X:%2.2X]",
1735                         auth_info->device_address.addr[0], auth_info->device_address.addr[1],
1736                         auth_info->device_address.addr[2], auth_info->device_address.addr[3],
1737                         auth_info->device_address.addr[4], auth_info->device_address.addr[5]);
1738                 TC_PRT("Device Name : [%s]", auth_info->device_name.name);
1739
1740                 TC_PRT("bluetooth_passkey_reply(\"0000\", TRUE)");
1741                 bluetooth_passkey_reply("0000", TRUE);
1742                 break;
1743         }
1744         case BLUETOOTH_EVENT_PASSKEY_CONFIRM_REQUEST:
1745         {
1746                 bluetooth_authentication_request_info_t *auth_info = param->param_data;
1747
1748                 TC_PRT("BLUETOOTH_EVENT_PASSKEY_CONFIRM_REQUEST");
1749                 TC_PRT("Device Address: [%2.2X:%2.2X:%2.2X:%2.2X:%2.2X:%2.2X]",
1750                         auth_info->device_address.addr[0], auth_info->device_address.addr[1],
1751                         auth_info->device_address.addr[2], auth_info->device_address.addr[3],
1752                         auth_info->device_address.addr[4], auth_info->device_address.addr[5]);
1753                 TC_PRT("Device Name : [%s]", auth_info->device_name.name);
1754                 TC_PRT("Passkey: [%s]", auth_info->str_passkey);
1755
1756                 TC_PRT("bluetooth_passkey_confirmation_reply: TRUE");
1757                 bluetooth_passkey_confirmation_reply(TRUE);
1758                 break;
1759         }
1760         default:
1761                 TC_PRT("received event [0x%04x]", event);
1762                 break;
1763         }
1764         TC_PRT("<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<");
1765 }
1766
1767 static gboolean key_event_cb(GIOChannel * chan, GIOCondition cond , gpointer data)
1768 {
1769         char buf[49] = {0};
1770
1771 #ifdef ARCH64
1772         unsigned long len = 0;
1773 #else
1774         unsigned int len = 0;
1775 #endif
1776         int test_id;
1777         memset(buf, 0, sizeof(buf));
1778
1779         if (g_io_channel_read_chars(chan, buf, sizeof(buf),
1780                                 &len, NULL) == G_IO_STATUS_ERROR) {
1781                 TC_PRT("IO Channel read error");
1782                 return FALSE;
1783         }
1784
1785         printf("%s\n", buf);
1786         tc_usage_print();
1787
1788         test_id = atoi(buf);
1789
1790 #ifdef ARCH64
1791         g_idle_add(test_input_callback, (void *)(uintptr_t)test_id);
1792 #else
1793         g_idle_add(test_input_callback, (void *)test_id);
1794 #endif
1795
1796         return TRUE;
1797 }
1798
1799 int main(void)
1800 {
1801         startup();
1802
1803         GIOChannel *key_io;
1804         key_io = g_io_channel_unix_new(fileno(stdin));
1805
1806         g_io_channel_set_encoding(key_io, NULL, NULL);
1807         g_io_channel_set_flags(key_io, G_IO_FLAG_NONBLOCK, NULL);
1808
1809         g_io_add_watch(key_io, G_IO_IN | G_IO_HUP | G_IO_ERR | G_IO_NVAL,
1810                         key_event_cb, NULL);
1811         g_io_channel_unref(key_io);
1812
1813         g_main_loop_run(main_loop);
1814
1815         cleanup();
1816         return 0;
1817 }
1818