Tizen 2.1 base
[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
645                 case 29:
646                 {
647                         TC_PRT("TC : %s", tc_table[28].tc_name);
648
649                         ret = bluetooth_audio_init(bt_audio_event_callback, NULL);
650                         if (ret < 0)
651                                 TC_PRT("%s failed with [0x%04x]", tc_table[28].tc_name, ret);
652                         break;
653                 }
654                 case 30:
655                 {
656                         TC_PRT("TC : %s", tc_table[29].tc_name);
657
658                         ret = bluetooth_audio_deinit();
659                         if (ret < 0)
660                                 TC_PRT("%s failed with [0x%04x]", tc_table[29].tc_name, ret);
661                         break;
662                 }
663                 case 31:
664                 {
665                         /* MW600 */
666                         //bluetooth_device_address_t device_address={{0x58,0x17,0x0C,0xEC,0x6A,0xF3}};
667                         bluetooth_device_address_t device_address={{0x00,0x0D,0xFD,0x24,0x5E,0xFF}}; /* Motorola S9 */
668
669                         TC_PRT("TC : %s", tc_table[30].tc_name);
670
671                         ret = bluetooth_audio_connect(&device_address);
672                         if (ret < 0)
673                                 TC_PRT("%s failed with [0x%04x]", tc_table[30].tc_name, ret);
674                         break;
675                 }
676                 case 32:
677                 {
678                         /* MW600 */
679                         //bluetooth_device_address_t device_address={{0x58,0x17,0x0C,0xEC,0x6A,0xF3}};
680                         bluetooth_device_address_t device_address={{0x00,0x0D,0xFD,0x24,0x5E,0xFF}}; /* Motorola S9 */
681
682                         TC_PRT("TC : %s", tc_table[31].tc_name);
683
684                         ret = bluetooth_audio_disconnect(&device_address);
685                         if (ret < 0)
686                                 TC_PRT("%s failed with [0x%04x]", tc_table[31].tc_name, ret);
687                         break;
688                 }
689                 case 33:
690                 {
691                         /* MW600 */
692                         bluetooth_device_address_t device_address={{0x58,0x17,0x0C,0xEC,0x6A,0xF3}};
693
694                         TC_PRT("TC : %s", tc_table[32].tc_name);
695
696                         ret = bluetooth_ag_connect(&device_address);
697                         if (ret < 0)
698                                 TC_PRT("%s failed with [0x%04x]", tc_table[32].tc_name, ret);
699                         break;
700                 }
701                 case 34:
702                 {
703                         /* MW600 */
704                         bluetooth_device_address_t device_address={{0x58,0x17,0x0C,0xEC,0x6A,0xF3}};
705
706                         TC_PRT("TC : %s", tc_table[33].tc_name);
707
708                         ret = bluetooth_ag_disconnect(&device_address);
709                         if (ret < 0)
710                                 TC_PRT("%s failed with [0x%04x]", tc_table[33].tc_name, ret);
711                         break;
712                 }
713                 case 35:
714                 {
715                         /* MW600 */
716                         bluetooth_device_address_t device_address={{0x58,0x17,0x0C,0xEC,0x6A,0xF3}};
717
718                         TC_PRT("TC : %s", tc_table[34].tc_name);
719
720                         ret = bluetooth_av_connect(&device_address);
721                         if (ret < 0)
722                                 TC_PRT("%s failed with [0x%04x]", tc_table[34].tc_name, ret);
723                         break;
724                 }
725                 case 36:
726                 {
727                         /* MW600 */
728                         bluetooth_device_address_t device_address={{0x58,0x17,0x0C,0xEC,0x6A,0xF3}};
729
730                         TC_PRT("TC : %s", tc_table[35].tc_name);
731
732                         ret = bluetooth_av_disconnect(&device_address);
733                         if (ret < 0)
734                                 TC_PRT("%s failed with [0x%04x]", tc_table[35].tc_name, ret);
735                         break;
736                 }
737                 case 37:
738                 {
739                         unsigned int volume = 0;
740
741                         ret = bluetooth_ag_get_headset_volume(&volume);
742                         if (ret < 0)
743                                 TC_PRT("failed with [0x%04x]", ret);
744
745                         TC_PRT("volume: %d", volume);
746                         break;
747                 }
748                 case 38:
749                 {
750                         ret = bluetooth_ag_set_speaker_gain(10);
751                         if (ret < 0)
752                                 TC_PRT("failed with [0x%04x]", ret);
753                         break;
754                 }
755
756                 case 39:
757                 {
758                         if (bluetooth_oob_read_local_data(&g_local_oob_data.oob_data))
759                                 TC_PRT("ERROR in bluetooth_oob_read_local_data\n");
760                         else {
761                                 TC_PRT("SUCESS in bluetooth_oob_read_local_data\n");
762                                 TC_PRT("hash = [%2.2X:%2.2X:%2.2X:%2.2X:%2.2X:%2.2X:%2.2X:%2.2X"
763                                         "%2.2X:%2.2X:%2.2X:%2.2X:%2.2X:%2.2X:%2.2X:%2.2X]\n",
764                                         g_local_oob_data.oob_data.hash[0],
765                                         g_local_oob_data.oob_data.hash[1],
766                                         g_local_oob_data.oob_data.hash[2],
767                                         g_local_oob_data.oob_data.hash[3],
768                                         g_local_oob_data.oob_data.hash[4],
769                                         g_local_oob_data.oob_data.hash[5],
770                                         g_local_oob_data.oob_data.hash[6],
771                                         g_local_oob_data.oob_data.hash[7],
772                                         g_local_oob_data.oob_data.hash[8],
773                                         g_local_oob_data.oob_data.hash[9],
774                                         g_local_oob_data.oob_data.hash[10],
775                                         g_local_oob_data.oob_data.hash[11],
776                                         g_local_oob_data.oob_data.hash[12],
777                                         g_local_oob_data.oob_data.hash[13],
778                                         g_local_oob_data.oob_data.hash[14],
779                                         g_local_oob_data.oob_data.hash[15]);
780
781                                 TC_PRT("randomizer = [%2.2X:%2.2X:%2.2X:%2.2X:%2.2X:%2.2X:%2.2X:%2.2X"
782                                         "%2.2X:%2.2X:%2.2X:%2.2X:%2.2X:%2.2X:%2.2X:%2.2X]\n",
783                                         g_local_oob_data.oob_data.randomizer[0],
784                                         g_local_oob_data.oob_data.randomizer[1],
785                                         g_local_oob_data.oob_data.randomizer[2],
786                                         g_local_oob_data.oob_data.randomizer[3],
787                                         g_local_oob_data.oob_data.randomizer[4],
788                                         g_local_oob_data.oob_data.randomizer[5],
789                                         g_local_oob_data.oob_data.randomizer[6],
790                                         g_local_oob_data.oob_data.randomizer[7],
791                                         g_local_oob_data.oob_data.randomizer[8],
792                                         g_local_oob_data.oob_data.randomizer[9],
793                                         g_local_oob_data.oob_data.randomizer[10],
794                                         g_local_oob_data.oob_data.randomizer[11],
795                                         g_local_oob_data.oob_data.randomizer[12],
796                                         g_local_oob_data.oob_data.randomizer[13],
797                                         g_local_oob_data.oob_data.randomizer[14],
798                                         g_local_oob_data.oob_data.randomizer[15]);
799
800                                 TC_PRT("hash_len: %d\n", g_local_oob_data.oob_data.hash_len);
801                                 TC_PRT("randomizer_len: %d\n", g_local_oob_data.oob_data.randomizer_len);
802                         }
803                         break;
804                 }
805                 case 40:
806                 {
807                         TC_PRT("hash_len: %d\n", g_local_oob_data.oob_data.hash_len);
808                         TC_PRT("randomizer_len: %d\n", g_local_oob_data.oob_data.randomizer_len);
809
810                         if (bluetooth_oob_add_remote_data(&g_local_oob_data.address,
811                                 &g_local_oob_data.oob_data))
812                                 TC_PRT("ERROR in bluetooth_oob_add_remote_data\n");
813                         else
814                                 TC_PRT(" bluetooth_oob_add_remote_data SUCCESS\n");
815                         break;
816                 }
817
818                 case 41:
819                 {
820                         if (bluetooth_oob_remove_remote_data(&g_local_oob_data.address))
821                                 TC_PRT("ERROR in bluetooth_oob_remove_remote_data\n");
822                         else
823                                 TC_PRT(" bluetooth_oob_remove_remote_data SUCCESS\n");
824                         break;
825                 }
826                 case 42:
827                 {
828                         bluetooth_opc_init();
829                         break;
830                 }
831                 case 43:
832                 {
833                         bluetooth_opc_deinit();
834                         break;
835                 }
836                 case 44:
837                 {
838                         bluetooth_device_address_t remote_address = {{0}};
839
840                         /* Grey dongle */
841                         remote_address.addr[0] = 0x00; remote_address.addr[1] = 0x02; remote_address.addr[2] = 0x70;
842                         remote_address.addr[3] = 0x2B; remote_address.addr[4] = 0xD3;  remote_address.addr[5]= 0xAF;
843
844                         char *files[5] = {NULL};
845
846                         files[0] = "/opt/media/Images/image1.jpg";
847 //                      files[1] = "/opt/media/Images/image2.jpg";
848 //                      files[2] = "/opt/media/Images/image3.jpg";
849                         bluetooth_opc_push_files(&remote_address, files);
850                         break;
851                 }
852                 case 45:
853                 {
854                         bluetooth_opc_cancel_push();
855                         break;
856                 }
857                 case 46:
858                 {
859                         gboolean exist;
860                         exist = bluetooth_opc_session_is_exist();
861                         TC_PRT("exist: %d", exist);
862                         break;
863                 }
864                 case 47:
865                 {
866                         bluetooth_network_activate_server();
867                         break;
868                 }
869                 case 48:
870                 {
871                         bluetooth_network_deactivate_server();
872                         break;
873                 }
874                 case 49:
875                 {
876                         bluetooth_device_address_t device_address = {{0x00, 0x02, 0xA2, 0x14, 0x40, 0x51}};
877                         bluetooth_network_connect(&device_address, BLUETOOTH_NETWORK_NAP_ROLE, NULL);
878                         break;
879                 }
880                 case 50:
881                 {
882                         bluetooth_device_address_t device_address = {{0x00, 0x02, 0xA2, 0x14, 0x40, 0x51}};
883                         bluetooth_network_disconnect(&device_address);
884                         break;
885                 }
886                 case 51:
887                 {
888                         bluetooth_obex_server_init("/opt/media/Downloads");
889                         break;
890                 }
891                 case 52:
892                 {
893                         bluetooth_obex_server_deinit();
894                         break;
895                 }
896                 case 53:
897                 {
898                         bluetooth_obex_server_init_without_agent("/opt/media/Downloads");
899                         break;
900                 }
901                 case 54:
902                 {
903                         bluetooth_obex_server_deinit_without_agent();
904                         break;
905                 }
906                 case 55:
907                 {
908                         bluetooth_obex_server_is_activated();
909                         break;
910                 }
911                 case 56:
912                 {
913                         bluetooth_obex_server_accept_connection();
914                         TC_PRT(" bluetooth_obex_server_accept_connection SUCCESS\n");
915                         break;
916                 }
917                 case 57:
918                 {
919                         bluetooth_obex_server_reject_connection();
920                         break;
921                 }
922                 case 58:
923                 {
924                         bluetooth_obex_server_accept_authorize("abc");
925                         break;
926                 }
927                 case 59:
928                 {
929                         bluetooth_obex_server_reject_authorize();
930                         break;
931                 }
932                 case 60:
933                 {
934                         bluetooth_obex_server_set_destination_path("/opt/media");
935                         break;
936                 }
937                 case 61:
938                 {
939                         bluetooth_obex_server_set_root("/opt/media");
940                         break;
941                 }
942                 case 62:
943                 {
944                         bluetooth_obex_server_cancel_transfer(0);
945                         break;
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                         break;
959                 }
960                 case 66:
961                 {
962                         ret = bluetooth_hid_deinit();
963                         if (ret < 0)
964                                 TC_PRT("Failed with [0x%04x]", ret);
965                         break;
966                 }
967                 case 67:
968                 {
969                         /* Apple wireless keyboard */
970                         hid_device_address_t device_address={{0xE8,0x06,0x88,0x3B,0x18,0xBA}};
971
972                         ret = bluetooth_hid_connect(&device_address);
973                         if (ret < 0)
974                                 TC_PRT("Failed with [0x%04x]", ret);
975                         break;
976                 }
977                 case 68:
978                 {
979                         /* Apple wireless keyboard */
980                         hid_device_address_t device_address={{0xE8,0x06,0x88,0x3B,0x18,0xBA}};
981
982                         ret = bluetooth_hid_disconnect(&device_address);
983                         if (ret < 0)
984                                 TC_PRT("Failed with [0x%04x]", ret);
985                         break;
986                 }
987
988                 case 70:
989                 {
990                         bluetooth_device_address_t device_address = {{0x00, 0x02, 0x2F, 0x92, 0x7B, 0xF5}};
991
992                         ret = bluetooth_rfcomm_connect(&device_address, rfcomm_test_uuid_spp);
993                         //ret = bluetooth_rfcomm_connect(&device_address, "1");
994
995                         if (ret < 0)
996                                 TC_PRT("Failed with [0x%04x]", ret);
997                         break;
998                 }
999                 case 71:
1000                 {
1001                         ret = bluetooth_rfcomm_disconnect(-1);
1002
1003                         if (ret < 0)
1004                                 TC_PRT("Failed with [0x%04x]", ret);
1005                         break;
1006                 }
1007                 case 72:
1008                 {
1009                         ret = bluetooth_rfcomm_disconnect(g_ret_client_fd1);
1010
1011                         if (ret < 0)
1012                                 TC_PRT("Failed with [0x%04x]", ret);
1013                         break;
1014                 }
1015                 case 73:
1016                 {
1017                         ret = bluetooth_rfcomm_write(g_ret_client_fd1, "123456789 12345", 20);
1018
1019                         if (ret < 0)
1020                                 TC_PRT("Failed with [0x%04x]", ret);
1021                         break;
1022                 }
1023                 case 74:
1024                 {
1025                         gboolean is_connected;
1026
1027                         is_connected = bluetooth_rfcomm_is_client_connected();
1028
1029                         TC_PRT("Connected: %d", is_connected);
1030                         break;
1031                 }
1032                 case 80:
1033                 {
1034                         ret = bluetooth_rfcomm_create_socket(rfcomm_test_uuid_spp);
1035                         if (ret < 0)
1036                                 TC_PRT("Failed with [0x%04x]", ret);
1037
1038                         TC_PRT("Returned FD = %d", ret);
1039                         server_fd = ret;
1040                         break;
1041                 }
1042                 case 81:
1043                 {
1044                         ret = bluetooth_rfcomm_create_socket(rfcomm_test_uuid_custom);
1045                         if (ret < 0)
1046                                 TC_PRT("Failed with [0x%04x]", ret);
1047
1048                         TC_PRT("Returned FD = %d", ret);
1049                         server_fd = ret;
1050                         break;
1051                 }
1052                 case 82:
1053                 {
1054                         ret = bluetooth_rfcomm_remove_socket(server_fd);
1055                         if (ret < 0)
1056                                 TC_PRT("Failed with [0x%04x]", ret);
1057                         break;
1058                 }
1059                 case 83: /*Listen and accept */
1060                 {
1061
1062                         ret = bluetooth_rfcomm_listen_and_accept(server_fd, 1);
1063                         if (ret < 0)
1064                                 TC_PRT("Failed with [0x%04x]", ret);
1065
1066                         TC_PRT("result = %d", ret);
1067                         break;
1068                 }
1069                 case 84: /*Listen */
1070                 {
1071
1072                         ret = bluetooth_rfcomm_listen(server_fd, 1);
1073                         if (ret < 0)
1074                                 TC_PRT("Failed with [0x%04x]", ret);
1075
1076                         TC_PRT("result = %d", ret);
1077                         break;
1078                 }
1079                 case 85:
1080                 {
1081                         ret = bluetooth_rfcomm_server_disconnect(client_fd);
1082                         if (ret < 0)
1083                                 TC_PRT("Failed with [0x%04x]", ret);
1084                         break;
1085                 }
1086                 case 86:
1087                 {
1088                         gboolean available;
1089
1090                         available = bluetooth_rfcomm_is_server_uuid_available(rfcomm_test_uuid_spp);
1091
1092                         TC_PRT("available: %d", available);
1093                         break;
1094                 }
1095                 case 87:
1096                 {
1097                         ret = bluetooth_rfcomm_accept_connection(server_fd, &client_fd);
1098                         if (ret < 0)
1099                                 TC_PRT("Failed with [0x%04x]", ret);
1100                         TC_PRT("client fd: %d", client_fd);
1101                         break;
1102                 }
1103                 case 88:
1104                 {
1105                         ret = bluetooth_rfcomm_reject_connection(server_fd);
1106                         if (ret < 0)
1107                                 TC_PRT("Failed with [0x%04x]", ret);
1108                         break;
1109                 }
1110                 default:
1111                         break;
1112         }
1113
1114         return 0;
1115 }
1116
1117 void startup()
1118 {
1119         TC_PRT("bluetooth framework TC startup");
1120
1121         if(!g_thread_supported())
1122         {
1123                 g_thread_init(NULL);
1124         }
1125
1126         dbus_g_thread_init();
1127
1128         g_type_init();
1129         main_loop = g_main_loop_new(NULL, FALSE);
1130 }
1131
1132 void cleanup()
1133 {
1134         TC_PRT("bluetooth framework TC cleanup");
1135         if( main_loop!= NULL)
1136         {
1137                 g_main_loop_unref(main_loop);
1138         }
1139 }
1140
1141 int timeout_callback(void *data)
1142 {
1143         TC_PRT("timeout callback");
1144         timeout_status = -1;
1145
1146         g_main_loop_quit(main_loop);
1147
1148         return FALSE;
1149 }
1150
1151
1152 void bt_hid_event_callback(int event, hid_event_param_t* param, void *user_data)
1153 {
1154         TC_PRT(">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>");
1155         TC_PRT("bt event callback 0x%04x", event);
1156
1157
1158
1159 }
1160
1161 void bt_audio_event_callback(int event, bt_audio_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_event_callback(int event, bluetooth_event_param_t* param, void *user_data)
1171 {
1172         TC_PRT(">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>");
1173         TC_PRT("bt event callback 0x%04x", event);
1174         switch(event)
1175         {
1176                 case BLUETOOTH_EVENT_ENABLED:
1177                         TC_PRT("BLUETOOTH_EVENT_ENABLED, result [0x%04x]", param->result);
1178                         break;
1179
1180                 case BLUETOOTH_EVENT_DISABLED:
1181                         TC_PRT("BLUETOOTH_EVENT_DISABLED, result [0x%04x]", param->result);
1182                         break;
1183
1184                 case BLUETOOTH_EVENT_LOCAL_NAME_CHANGED:
1185                         TC_PRT("BLUETOOTH_EVENT_LOCAL_NAME_CHANGED, result [0x%04x]", param->result);
1186                         if (param->result == BLUETOOTH_ERROR_NONE)
1187                         {
1188                                 bluetooth_device_name_t *local_name = (bluetooth_device_name_t *)param->param_data;
1189                                 tc_result(TC_PASS, 6);
1190                                 TC_PRT("Changed Name : [%s]", local_name->name);
1191                         }
1192                         else
1193                         {
1194                                 tc_result(TC_FAIL, 6);
1195                         }
1196                         break;
1197
1198
1199                 case BLUETOOTH_EVENT_DISCOVERY_STARTED:
1200                         TC_PRT("BLUETOOTH_EVENT_DISCOVERY_STARTED, result [0x%04x]", param->result);
1201                         break;
1202
1203                 case BLUETOOTH_EVENT_REMOTE_DEVICE_FOUND:
1204                 {
1205                         bluetooth_device_info_t *device_info = NULL;
1206                         TC_PRT("BLUETOOTH_EVENT_REMOTE_DEVICE_FOUND, result [0x%04x]", param->result);
1207                         device_info  = (bluetooth_device_info_t *)param->param_data;
1208                         memcpy(&searched_device, &device_info->device_address, sizeof(bluetooth_device_address_t));
1209                         TC_PRT("dev [%2.2X:%2.2X:%2.2X:%2.2X:%2.2X:%2.2X]", \
1210                                 device_info->device_address.addr[0], device_info->device_address.addr[1], device_info->device_address.addr[2], \
1211                                 device_info->device_address.addr[3], device_info->device_address.addr[4], device_info->device_address.addr[5]);
1212                         break;
1213                 }
1214
1215                 case BLUETOOTH_EVENT_REMOTE_DEVICE_NAME_UPDATED:
1216                 {
1217                         bluetooth_device_info_t *device_info = NULL;
1218                         TC_PRT("BLUETOOTH_EVENT_REMOTE_DEVICE_NAME_UPDATED, result [0x%04x]", param->result);
1219                         device_info  = (bluetooth_device_info_t *)param->param_data;
1220                         memcpy(&searched_device, &device_info->device_address, sizeof(bluetooth_device_address_t));
1221                         TC_PRT("dev [%s] [%2.2X:%2.2X:%2.2X:%2.2X:%2.2X:%2.2X]", device_info->device_name.name, \
1222                                 device_info->device_address.addr[0], device_info->device_address.addr[1], device_info->device_address.addr[2], \
1223                                 device_info->device_address.addr[3], device_info->device_address.addr[4], device_info->device_address.addr[5]);
1224                         break;
1225                 }
1226
1227                 case BLUETOOTH_EVENT_DISCOVERY_FINISHED:
1228                         TC_PRT("BLUETOOTH_EVENT_DISCOVERY_FINISHED, result [0x%04x]", param->result);
1229                         break;
1230
1231                 case BLUETOOTH_EVENT_DISCOVERABLE_MODE_CHANGED:
1232                 {
1233                         int *mode = (int *)param->param_data;
1234                         TC_PRT("BT_DISCOVERABLE_MODE_CHANGED, result [0x%04x]", param->result);
1235                         TC_PRT("mode [%d]", *mode);
1236                         break;
1237                 }
1238                 case BLUETOOTH_EVENT_DISCOVERABLE_TIMEOUT_CHANGED:
1239                 {
1240                         int *timeout = (int *)param->param_data;
1241                         TC_PRT("BLUETOOTH_EVENT_DISCOVERABLE_TIMEOUT_CHANGED, result [0x%04x]", param->result);
1242                         TC_PRT("timeout [%d]", *timeout);
1243                         break;
1244                 }
1245                 case BLUETOOTH_EVENT_BONDING_FINISHED:
1246                 {
1247                         TC_PRT("BLUETOOTH_EVENT_BONDING_FINISHED, result [0x%04x]", param->result);
1248                         if (param->result >= BLUETOOTH_ERROR_NONE)
1249                         {
1250                                 bluetooth_device_info_t *device_info = NULL;
1251                                 tc_result(TC_PASS, 12);
1252                                 device_info  = (bluetooth_device_info_t *)param->param_data;
1253                                 if (device_info == NULL)
1254                                         break;
1255
1256                                 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, \
1257                                         device_info->device_address.addr[0], device_info->device_address.addr[1], device_info->device_address.addr[2], \
1258                                         device_info->device_address.addr[3], device_info->device_address.addr[4], device_info->device_address.addr[5], \
1259                                         device_info->device_class.major_class, device_info->device_class.minor_class, device_info->device_class.service_class);
1260                         }
1261                         else
1262                         {
1263                                 tc_result(TC_FAIL, 12);
1264                         }
1265                         break;
1266                 }
1267
1268                 case BLUETOOTH_EVENT_BONDED_DEVICE_FOUND:
1269                 {
1270                         // bluetooth_get_bonded_device_list is changed as synchronous API. This event is not used any more.
1271                         // 2011.01.06
1272 #if 0
1273 //                      int i = 0;
1274                         TC_PRT("BLUETOOTH_EVENT_BONDED_DEVICE_FOUND, result [0x%04x]", param->result);
1275                         if (param->result >= BLUETOOTH_ERROR_NONE)
1276                         {
1277                                 ///tc_result(TC_PASS, 15);
1278                                 bluetooth_device_info_t * bt_dev_info= (bluetooth_device_info_t*)param->param_data;
1279
1280                                 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,
1281                                         bt_dev_info->device_address.addr[0], bt_dev_info->device_address.addr[1], bt_dev_info->device_address.addr[2], \
1282                                         bt_dev_info->device_address.addr[3], bt_dev_info->device_address.addr[4], bt_dev_info->device_address.addr[5], \
1283                                         bt_dev_info->device_class.major_class, bt_dev_info->device_class.minor_class, bt_dev_info->device_class.service_class);
1284
1285                         }
1286                         else
1287                         if(param->result == BLUETOOTH_ERROR_END_OF_DEVICE_LIST) /*End of the Device found indication*/
1288                         {
1289                                 tc_result(TC_PASS, 15);
1290                                 TC_PRT("*****<<No more BLUETOOTH_EVENT_BONDED_DEVICE_FOUND indication>>***** ");
1291                         }
1292                         else
1293                         {
1294                                 tc_result(TC_FAIL, 15);
1295                                 TC_PRT("*****API failed ***** ");
1296                         }
1297                         break;
1298 #endif
1299                 }
1300                 case BLUETOOTH_EVENT_SERVICE_SEARCHED:
1301                 {
1302                         int i = 0;
1303                         TC_PRT("BLUETOOTH_EVENT_SERVICE_SEARCHED, result [0x%04x]", param->result);
1304                         if (param->result >= BLUETOOTH_ERROR_NONE)
1305                         {
1306                                 tc_result(TC_PASS, 18);
1307                                 bt_sdp_info_t * bt_sdp_info=param->param_data;
1308
1309                                 TC_PRT("Dev add = %2.2X:%2.2X:%2.2X:%2.2X:%2.2X:%2.2X\n",
1310                                         bt_sdp_info->device_addr.addr[0], bt_sdp_info->device_addr.addr[1], bt_sdp_info->device_addr.addr[2], \
1311                                         bt_sdp_info->device_addr.addr[3], bt_sdp_info->device_addr.addr[4], bt_sdp_info->device_addr.addr[5]);
1312
1313                                         TC_PRT("Supported service list:\n");
1314                                         for(i=0; i<bt_sdp_info->service_index; i++)
1315                                                 TC_PRT("[%#x]\n", bt_sdp_info->service_list_array[i]);
1316
1317                         }
1318                         else
1319                         {
1320                                 tc_result(TC_FAIL, 18);
1321                         }
1322                         break;
1323                 }
1324                 case BLUETOOTH_EVENT_RFCOMM_DATA_RECEIVED:
1325                 {
1326                         TC_PRT("BLUETOOTH_EVENT_RFCOMM_DATA_RECEIVED, result [0x%04x]", param->result);
1327                         bluetooth_rfcomm_received_data_t *rx_data = param->param_data;
1328                         printf("\n FD = %d \nBuffer len = %d ", rx_data->socket_fd, rx_data->buffer_size);
1329                         if (rx_data->buffer_size < sizeof(oob_data_t))
1330                                 TC_PRT("Complete oob data is not recivedn");
1331                         else
1332                                 memcpy(&g_remote_oob_data,rx_data->buffer, sizeof(oob_data_t));
1333                         //tc_result(TC_PASS, 21);
1334                         break;
1335                 }
1336                 case BLUETOOTH_EVENT_RFCOMM_CONNECTED:
1337                 {
1338                         bluetooth_rfcomm_connection_t *con_ind = (bluetooth_rfcomm_connection_t *)param->param_data;
1339                         TC_PRT("BLUETOOTH_EVENT_RFCOMM_CONNECTED, result [0x%04x], fd = %d, device add = 0x%X:%X:%X:%X:%X:%X, Role = %s", param->result,
1340                                                                 con_ind->socket_fd,
1341                                                                 con_ind->device_addr.addr[0], con_ind->device_addr.addr[1], con_ind->device_addr.addr[2],
1342                                                                 con_ind->device_addr.addr[3], con_ind->device_addr.addr[4], con_ind->device_addr.addr[5],
1343                                                                 (con_ind->device_role == RFCOMM_ROLE_SERVER)? "SERVER":"CLIENT");
1344                         //tc_result(TC_PASS, 22);
1345                         if((con_ind->device_role == RFCOMM_ROLE_CLIENT) && (con_ind->socket_fd > 0))
1346                         {
1347                                 g_ret_client_fd1 = con_ind->socket_fd;
1348                         }
1349
1350                         if((con_ind->device_role == RFCOMM_ROLE_SERVER) && (con_ind->socket_fd > 0))
1351                         {
1352                                 client_fd = con_ind->socket_fd;
1353                         }
1354
1355                         break;
1356                 }
1357                 case BLUETOOTH_EVENT_RFCOMM_DISCONNECTED:
1358                 {
1359                         bluetooth_rfcomm_disconnection_t *disconnection_ind = (bluetooth_rfcomm_disconnection_t *)param->param_data;;
1360                         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,
1361                                                                                                                 disconnection_ind->device_addr.addr[0], disconnection_ind->device_addr.addr[1], disconnection_ind->device_addr.addr[2],
1362                                                                                                                 disconnection_ind->device_addr.addr[3], disconnection_ind->device_addr.addr[4], disconnection_ind->device_addr.addr[5] );
1363                         //tc_result(TC_PASS, 22);
1364                         break;
1365                 }
1366                 case BLUETOOTH_EVENT_NETWORK_SERVER_CONNECTED:
1367                 {
1368                         bluetooth_network_device_info_t *dev_info = (bluetooth_network_device_info_t *)param->param_data;
1369
1370                         TC_PRT("BLUETOOTH_EVENT_RFCOMM_DISCONNECTED, result [0x%04x]", param->result);
1371                         TC_PRT("interface name: %s", dev_info->interface_name);
1372
1373                         TC_PRT("device add = %2.2X:%2.2X:%2.2X:%2.2X:%2.2X:%2.2X\n",
1374                                                                 dev_info->device_address.addr[0], dev_info->device_address.addr[1], dev_info->device_address.addr[2],
1375                                                                 dev_info->device_address.addr[3], dev_info->device_address.addr[4], dev_info->device_address.addr[5] );
1376                         break;
1377                 }
1378                 case BLUETOOTH_EVENT_NETWORK_SERVER_DISCONNECTED:
1379                 {
1380                         bluetooth_network_device_info_t *dev_info = (bluetooth_network_device_info_t *)param->param_data;
1381
1382                         TC_PRT("BLUETOOTH_EVENT_RFCOMM_DISCONNECTED, result [0x%04x]", param->result);
1383                         TC_PRT("interface name: %s", dev_info->interface_name);
1384
1385                         TC_PRT("device add = %2.2X:%2.2X:%2.2X:%2.2X:%2.2X:%2.2X\n",
1386                                                                 dev_info->device_address.addr[0], dev_info->device_address.addr[1], dev_info->device_address.addr[2],
1387                                                                 dev_info->device_address.addr[3], dev_info->device_address.addr[4], dev_info->device_address.addr[5] );
1388                         break;
1389                 }
1390
1391                 case BLUETOOTH_EVENT_HDP_CONNECTED:
1392                 {
1393                         bt_hdp_connected_t *conn_ind = (bt_hdp_connected_t *)param->param_data;
1394
1395                         TC_PRT("BLUETOOTH_EVENT_HDP_CONNECTED, Result = %s\n", (param->result == 0)? "BLUETOOTH_ERROR_NONE": "BLUETOOTH_ERROR_XXXX");
1396                         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");
1397                         TC_PRT("device add = %2.2X:%2.2X:%2.2X:%2.2X:%2.2X:%2.2X\n",
1398                                                                 conn_ind->device_address.addr[0], conn_ind->device_address.addr[1], conn_ind->device_address.addr[2],
1399                                                                 conn_ind->device_address.addr[3], conn_ind->device_address.addr[4], conn_ind->device_address.addr[5] );
1400
1401                         g_ret_client_fd1 = conn_ind->channel_id;
1402                         break;
1403                 }
1404
1405                 case BLUETOOTH_EVENT_HDP_DISCONNECTED:
1406                 {
1407                         bt_hdp_disconnected_t *dis_ind = (bt_hdp_disconnected_t *)param->param_data;
1408
1409                         TC_PRT("BLUETOOTH_EVENT_HDP_DISCONNECTED, Result = %s\n", (param->result == 0)? "BLUETOOTH_ERROR_NONE": "BLUETOOTH_ERROR_XXXX");
1410                         TC_PRT("Channel = %d, Add = device add = %2.2X:%2.2X:%2.2X:%2.2X:%2.2X:%2.2X\n", dis_ind->channel_id,
1411                                                                 dis_ind->device_address.addr[0], dis_ind->device_address.addr[1], dis_ind->device_address.addr[2],
1412                                                                 dis_ind->device_address.addr[3], dis_ind->device_address.addr[4], dis_ind->device_address.addr[5]);
1413                         break;
1414                 }
1415
1416                 case BLUETOOTH_EVENT_HDP_DATA_RECEIVED:
1417                 {
1418                         bt_hdp_data_ind_t *data_ind = (bt_hdp_data_ind_t *)param->param_data;
1419
1420                         TC_PRT("BLUETOOTH_EVENT_HDP_DATA_RECEIVED, Result = %s\n", (param->result == 0)? "BLUETOOTH_ERROR_NONE": "BLUETOOTH_ERROR_XXXX");
1421                         TC_PRT("Data received from channel id = %d and  size =%d, buff =[%s]\n",  data_ind->channel_id, data_ind->size, data_ind->buffer);
1422
1423                         break;
1424                 }
1425
1426                 case BLUETOOTH_EVENT_OPC_CONNECTED:
1427                         TC_PRT("BLUETOOTH_EVENT_OPC_CONNECTED");
1428                         break;
1429
1430                 case BLUETOOTH_EVENT_OPC_DISCONNECTED:
1431                         TC_PRT("BLUETOOTH_EVENT_OPC_DISCONNECTED");
1432                         break;
1433                 case BLUETOOTH_EVENT_OPC_TRANSFER_STARTED:
1434                 {
1435                         TC_PRT("BLUETOOTH_EVENT_OPC_TRANSFER_STARTED");
1436                         if (param->param_data) {
1437                                 bt_opc_transfer_info_t *info = param->param_data;
1438                                 TC_PRT("file %s", info->filename);
1439                                 TC_PRT("size %ld", info->size);
1440                         }
1441                         break;
1442                 }
1443                 case BLUETOOTH_EVENT_OPC_TRANSFER_PROGRESS:
1444                 {
1445                         TC_PRT("BLUETOOTH_EVENT_OPC_TRANSFER_PROGRESS");
1446                         break;
1447                 }
1448                 case BLUETOOTH_EVENT_OPC_TRANSFER_COMPLETE:
1449                 {
1450                         TC_PRT("BLUETOOTH_EVENT_OPC_TRANSFER_COMPLETE");
1451                         bt_opc_transfer_info_t *info = param->param_data;
1452                         TC_PRT("file %s", info->filename);
1453                         TC_PRT("size %ld", info->size);
1454                         break;
1455                 }
1456
1457                 case BLUETOOTH_EVENT_OBEX_SERVER_TRANSFER_AUTHORIZE:
1458                         TC_PRT("BLUETOOTH_EVENT_OBEX_SERVER_TRANSFER_AUTHORIZE");
1459                         break;
1460
1461                 case BLUETOOTH_EVENT_OBEX_SERVER_CONNECTION_AUTHORIZE:
1462                         TC_PRT("BLUETOOTH_EVENT_OBEX_SERVER_CONNECTION_AUTHORIZE");
1463                         break;
1464
1465                 case BLUETOOTH_EVENT_OBEX_SERVER_TRANSFER_STARTED:
1466                         TC_PRT("BLUETOOTH_EVENT_OBEX_SERVER_TRANSFER_STARTED");
1467                         bt_obex_server_transfer_info_t *info = param->param_data;
1468                         current_transfer_id = info->transfer_id;
1469                         break;
1470
1471                 case BLUETOOTH_EVENT_OBEX_SERVER_TRANSFER_PROGRESS:
1472                         TC_PRT("BLUETOOTH_EVENT_OBEX_SERVER_TRANSFER_PROGRESS");
1473                         break;
1474
1475                 case BLUETOOTH_EVENT_OBEX_SERVER_TRANSFER_COMPLETED:
1476                         TC_PRT("BLUETOOTH_EVENT_OBEX_SERVER_TRANSFER_COMPLETED");
1477                         break;
1478
1479 #if 0
1480                 case BLUETOOTH_EVENT_GATT_PRIM_SVC_DISCOVERED:
1481                 {
1482                         TC_PRT("BLUETOOTH_EVENT_GATT_PRIM_SVC_DISCOVERED");
1483                         bt_gatt_handle_info_t *prim_svc = param->param_data;
1484                         int i;
1485
1486                         if (prim_svc == NULL) {
1487                                 TC_PRT("prim_svc is NULL");
1488                                 break;
1489                         }
1490
1491                         for (i = 0; i < prim_svc->count; i++) {
1492                                 TC_PRT("prim_svc[%d] = %s\n", i, prim_svc->handle[i]);
1493                         }
1494
1495                         break;
1496                 }
1497
1498                 case BLUETOOTH_EVENT_GATT_SVC_CHAR_DISCOVERED:
1499                 {
1500                         TC_PRT("BLUETOOTH_EVENT_GATT_SVC_CHAR_DISCOVERED");
1501                         bt_gatt_discovered_char_t *svc_char = param->param_data;
1502                         int i = 0;
1503
1504                         if (svc_char == NULL) {
1505                                 TC_PRT("svc_char is NULL");
1506                                 break;
1507                         }
1508
1509                         if (svc_char->service_handle != NULL) {
1510                                 TC_PRT("svc_char->service_handle %s \n", svc_char->service_handle);
1511                         }
1512
1513                         for (i = 0; i < svc_char->handle_info.count; i++) {
1514                                 TC_PRT("svc_char.handle_info.handle[%d] = %s\n", i, svc_char->handle_info.handle[i]);
1515                         }
1516
1517                         break;
1518                 }
1519
1520                 case BLUETOOTH_EVENT_GATT_SVC_PROP_RECEIVED:
1521                 {
1522                         TC_PRT("BLUETOOTH_EVENT_GATT_SVC_PROP_RECEIVED");
1523                         bt_gatt_service_property_t *svc_pty = param->param_data;
1524                         int i;
1525
1526                         if (svc_pty == NULL) {
1527                                 TC_PRT("char_pty is NULL \n");
1528                                 break;
1529                         }
1530
1531                         if (svc_pty->service_handle != NULL) {
1532                                 TC_PRT("svc_pty->service_handle %s \n", svc_pty->service_handle);
1533                         }
1534
1535                         if (svc_pty->uuid != NULL) {
1536                                 TC_PRT("svc_pty->uuid %s \n", svc_pty->uuid);
1537                         }
1538
1539                         for (i = 0; i < svc_pty->handle_info.count; i++) {
1540                                 TC_PRT("svc_char[%d] = %s\n", i, svc_pty->handle_info.handle[i]);
1541                         }
1542
1543                         break;
1544                 }
1545
1546                 case BLUETOOTH_EVENT_GATT_CHAR_PROP_RECEIVED:
1547                 {
1548                         TC_PRT("BLUETOOTH_EVENT_GATT_CHAR_PROP_RECEIVED");
1549                         bt_gatt_char_property_t *char_pty = param->param_data;
1550                         int i = 0;
1551
1552                         if (char_pty->char_handle != NULL) {
1553                                 TC_PRT("char_pty->char_handle %s \n", char_pty->char_handle);
1554                         }
1555
1556                         if (char_pty->uuid != NULL) {
1557                                 TC_PRT("char_pty->uuid %s \n", char_pty->uuid);
1558                         }
1559
1560                         if (char_pty == NULL) {
1561                                 TC_PRT("char_pty is NULL \n");
1562                                 break;
1563                         }
1564
1565                         if (char_pty->name != NULL) {
1566                                 TC_PRT("char_pty->name %s \n", char_pty->name);
1567                         }
1568
1569                         if (char_pty->description != NULL) {
1570                                 TC_PRT("char_pty->description %s \n", char_pty->description);
1571                         }
1572
1573                         if (char_pty->val != NULL) {
1574                                 TC_PRT("char_pty->val_len %d \n", char_pty->val_len);
1575
1576                                 for (i = 0; i < char_pty->val_len; i ++)
1577                                         TC_PRT("char_pty->val %02x \n", char_pty->val[i]);
1578                         }
1579
1580                         break;
1581                 }
1582 #endif
1583                 default:
1584                         TC_PRT("received event [0x%04x]", event);
1585                         break;
1586         }
1587         TC_PRT("<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<");
1588 }
1589
1590 static gboolean key_event_cb(GIOChannel * chan, GIOCondition cond , gpointer data)
1591 {
1592         char buf[10] = {0};
1593
1594         unsigned int len=0;
1595         int test_id;
1596         memset(buf, 0, sizeof(buf));
1597
1598         if(g_io_channel_read_chars(chan, buf, sizeof(buf),
1599                                 &len, NULL) == G_IO_STATUS_ERROR) {
1600                 TC_PRT("IO Channel read error");
1601                 return FALSE;
1602         }
1603
1604         printf("%s\n",buf);
1605         tc_usage_print();
1606
1607         test_id=atoi(buf);
1608
1609         if(test_id)
1610                 g_idle_add(test_input_callback, (void*)test_id);
1611
1612         return TRUE;
1613 }
1614
1615 int main(void)
1616 {
1617         startup();
1618
1619         GIOChannel *key_io;
1620         key_io=g_io_channel_unix_new(fileno(stdin));
1621
1622         g_io_channel_set_encoding(key_io, NULL, NULL);
1623         g_io_channel_set_flags(key_io, G_IO_FLAG_NONBLOCK, NULL);
1624
1625         g_io_add_watch(key_io, G_IO_IN | G_IO_HUP | G_IO_ERR | G_IO_NVAL,
1626                         key_event_cb, NULL);
1627         g_io_channel_unref(key_io);
1628
1629         g_main_loop_run(main_loop);
1630
1631         cleanup();
1632         return 0;
1633 }
1634