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