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