4 * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
6 * Contact: Hocheol Seo <hocheol.seo@samsung.com>
7 * Girishashok Joshi <girish.joshi@samsung.com>
8 * Chanyeol Park <chanyeol.park@samsung.com>
10 * Licensed under the Apache License, Version 2.0 (the "License");
11 * you may not use this file except in compliance with the License.
12 * You may obtain a copy of the License at
14 * http://www.apache.org/licenses/LICENSE-2.0
16 * Unless required by applicable law or agreed to in writing, software
17 * distributed under the License is distributed on an "AS IS" BASIS,
18 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
19 * See the License for the specific language governing permissions and
20 * limitations under the License.
25 * @file bluetooth-frwk-test.c
26 * @brief This is the source file for bluetooth framework test suite.
32 #include <dbus/dbus-glib.h>
35 #include "bluetooth-api.h"
36 #include "bluetooth-hid-api.h"
37 #include "bluetooth-audio-api.h"
40 bluetooth_device_address_t searched_device = {{0}};
42 #define TC_TIMEOUT 30000
44 #define BT_DEFAULT_DEV_NAME "SLP-BT-TEST-TARGET"
45 #define DISCOVER_TIMEOUT 20
46 #define DISCOVER_CANCEL_INTERVAL 3
48 #define PRT(format, args...) printf("%s:%d() "format, __FUNCTION__, __LINE__, ##args)
49 #define TC_PRT(format, args...) PRT(format"\n", ##args)
55 int g_ret_client_fd1 = -1, g_ret_client_fd2 = -1;
56 const char *g_hdp_app_handle1 = NULL;
57 const char *g_hdp_app_handle2 = NULL;
59 char *svc_obj_path = NULL;
60 char *char_obj_path = NULL;
61 char *desc_obj_path = NULL;
64 int hdp_manual_mode = 1;
65 const char * rfcomm_test_uuid_spp ="00001101-0000-1000-8000-00805F9B34FB";
66 const char * rfcomm_test_uuid_dun = "00001103-0000-1000-8000-00805F9B34FB";
67 const char * rfcomm_test_uuid_custom ="26b2831b-2c2d-4f9c-914a-c0ab142351b7";
70 GMainLoop *main_loop = NULL;
71 static int timeout_status = 0;
73 int current_transfer_id = 0;
76 bluetooth_device_address_t address;
77 bt_oob_data_t oob_data;
80 oob_data_t g_local_oob_data;
81 oob_data_t g_remote_oob_data;
90 void bt_event_callback(int event, bluetooth_event_param_t* param, void *user_data);
91 void bt_hid_event_callback(int event, hid_event_param_t* param, void *user_data);
92 void bt_audio_event_callback(int event, bt_audio_event_param_t* param, void *user_data);
95 tc_table_t tc_table[] =
97 {"bluetooth_register_callback" , 1},
98 {"bluetooth_unregister_callback" , 2},
99 {"bluetooth_enable_adapter" , 3},
100 {"bluetooth_disable_adapter" , 4},
101 {"bluetooth_check_adapter" , 5},
102 {"bluetooth_get_local_address" , 6},
103 {"bluetooth_get_local_name" , 7},
104 {"bluetooth_set_local_name" , 8},
105 {"bluetooth_get_local_version" , 90},
106 {"bluetooth_is_service_used" , 9},
107 {"bluetooth_get_discoverable_mode" , 10},
108 {"bluetooth_set_discoverable_mode(CONNECTABLE)" , 11},
109 {"bluetooth_set_discoverable_mode(GENERAL_DISCOVERABLE)" , 12},
110 {"bluetooth_set_discoverable_mode(TIME_LIMITED_DISCOVERABLE)" , 13},
111 {"bluetooth_start_discovery" , 14},
112 {"bluetooth_cancel_discovery" , 15},
113 {"bluetooth_is_discovering" , 16},
114 {"bluetooth_get_bonded_device_list" , 17},
115 {"bluetooth_bond_device" , 18},
116 {"bluetooth_cancel_bonding" , 19},
117 {"bluetooth_unbond_device" , 20},
118 {"bluetooth_get_bonded_device" , 21},
119 {"bluetooth_set_alias" , 22},
120 {"bluetooth_authorize_device (TRUE)" , 23},
121 {"bluetooth_authorize_device (FALSE)" , 24},
122 {"bluetooth_search_service" , 25},
123 {"bluetooth_cancel_service_search" , 26},
124 {"bluetooth_is_device_connected" , 27},
125 {"bluetooth_reset_adapter" , 28},
126 {"bluetooth_set_manufacturer_data" , 91},
128 {"bluetooth_audio_init" , 29},
129 {"bluetooth_audio_deinit" , 30},
130 {"bluetooth_audio_connect" , 31},
131 {"bluetooth_audio_disconnect" , 32},
132 {"bluetooth_ag_connect" , 33},
133 {"bluetooth_ag_disconnect" , 34},
134 {"bluetooth_av_connect" , 35},
135 {"bluetooth_av_disconnect" , 36},
136 {"bluetooth_ag_get_headset_volume" , 37},
137 {"bluetooth_ag_set_speaker_gain" , 38},
139 {"bluetooth_oob_read_local_data" , 39},
140 {"bluetooth_oob_add_remote_data" , 40},
141 {"bluetooth_oob_remove_remote_data" , 41},
143 {"bluetooth_opc_init" , 42},
144 {"bluetooth_opc_deinit" , 43},
145 {"bluetooth_opc_push_files" , 44},
146 {"bluetooth_opc_cancel_push" , 45},
147 {"bluetooth_opc_session_is_exist" , 46},
149 {"bluetooth_network_activate_server" , 47},
150 {"bluetooth_network_deactivate_server" , 48},
151 {"bluetooth_network_connect" , 49},
152 {"bluetooth_network_disconnect" , 50},
154 {"bluetooth_obex_server_init" , 51},
155 {"bluetooth_obex_server_deinit" , 52},
156 {"bluetooth_obex_server_init_without_agent" , 53},
157 {"bluetooth_obex_server_deinit_without_agent" , 54},
158 {"bluetooth_obex_server_is_activated" , 55},
159 {"bluetooth_obex_server_accept_connection" , 56},
160 {"bluetooth_obex_server_reject_connection" , 57},
161 {"bluetooth_obex_server_accept_authorize" , 58},
162 {"bluetooth_obex_server_reject_authorize" , 59},
163 {"bluetooth_obex_server_set_destination_path" , 60},
164 {"bluetooth_obex_server_set_root" , 61},
165 {"bluetooth_obex_server_cancel_transfer" , 62},
166 {"bluetooth_obex_server_cancel_all_transfers" , 63},
168 {"bluetooth_hid_init" , 65},
169 {"bluetooth_hid_deinit" , 66},
170 {"bluetooth_hid_connect" , 67},
171 {"bluetooth_hid_disconnect" , 68},
173 {"bluetooth_rfcomm_connect" , 70},
174 {"bluetooth_rfcomm_disconnect (cancel)" , 71},
175 {"bluetooth_rfcomm_disconnect" , 72},
176 {"bluetooth_rfcomm_write" , 73},
177 {"bluetooth_rfcomm_is_client_connected" , 74},
179 {"bluetooth_rfcomm_create_socket" , 80},
180 {"bluetooth_rfcomm_create_socket (Custom UUID)" , 81},
181 {"bluetooth_rfcomm_remove_socket" , 82},
182 {"bluetooth_rfcomm_listen_and_accept" , 83},
183 {"bluetooth_rfcomm_listen (OSP)" , 84},
184 {"bluetooth_rfcomm_server_disconnect" , 85},
185 {"bluetooth_rfcomm_is_server_uuid_available" , 86},
186 {"bluetooth_rfcomm_accept_connection" , 87},
187 {"bluetooth_rfcomm_reject_connection" , 88},
188 {"bluetooth_start_custom_discovery" , 89},
190 {"bluetooth_gatt_init", 92},
191 {"bluetooth_gatt_deinit", 93},
192 {"bluetooth_gatt_add_service", 94},
193 {"bluetooth_gatt_add_characteristics", 95},
194 {"bluetooth_gatt_add_descriptor", 96},
195 {"bluetooth_gatt_register_service", 97},
196 {"bluetooth_gatt_update_characteristic", 98},
197 {"bluetooth_gatt_unregister_service", 99},
198 {"bluetooth_gatt_delete_services", 100},
201 {"bluetooth_rfcomm_is_server_uuid_available" , 26},
203 {"bluetooth_hdp_activate" , 30},
204 {"bluetooth_hdp_deactivate" , 31},
205 {"bluetooth_hdp_connect" , 32},
206 {"bluetooth_hdp_disconnect" , 33},
207 {"bluetooth_hdp_send_data" , 34},
209 {"bluetooth_opc_init" , 35},
210 {"bluetooth_opc_push_file" , 36},
211 {"bluetooth_opc_cancel_push" , 37},
212 {"bluetooth_opc_deinit" , 38},
213 {"bluetooth_obex_server_init" , 39},
214 {"bluetooth_obex_server_deinit" , 40},
215 {"bluetooth_obex_server_accept_authorize" , 41},
216 {"bluetooth_obex_server_reject_authorize" , 42},
217 {"bluetooth_is_supported" , 43},
218 {"bluetooth_opc_session_is_exist" , 46},
219 {"bluetooth_obex_server_is_activated" , 47},
220 {"bluetooth_obex_server_cancel_transfer" , 48},
222 {"bluetooth_oob_read_local_data" , 50},
223 {"bluetooth_oob_add_remote_data" , 51},
224 {"bluetooth_oob_remove_remote_data" , 52},
226 {"bluetooth_network_activate_server" , 60},
227 {"bluetooth_network_deactivate_server" , 61},
228 {"bluetooth_network_connect" , 62},
229 {"bluetooth_network_disconnect" , 63},
231 {"bluetooth_gatt_discover_primary_services", 64},
232 {"bluetooth_gatt_discover_service_characteristics", 65},
233 {"bluetooth_gatt_get_service_property", 66},
234 {"bluetooth_gatt_get_characteristics_value", 67},
235 {"bluetooth_gatt_set_characteristics_value", 68},
237 /* -----------------------------------------*/
243 #define tc_result(success, tc_index) \
244 TC_PRT("Test case [%d - %s] %s", tc_table[tc_index].tc_code, tc_table[tc_index].tc_name, ((success == TC_PASS)?"Success":"Failed"));
246 bluetooth_device_info_t bond_dev;
247 int is_bond_device = FALSE;
249 void tc_usage_print(void)
253 while (tc_table[i].tc_name) {
254 if (tc_table[i].tc_code != 0x00ff) {
255 TC_PRT("Key %d : usage %s", tc_table[i].tc_code, tc_table[i].tc_name);
257 TC_PRT("Key %d : usage %s\n\n", 0x00ff, tc_table[i].tc_name);
264 int test_input_callback(void *data)
267 int test_id = (int)data;
269 TC_PRT("TC : %s", tc_table[test_id - 1].tc_name);
274 g_main_loop_quit(main_loop);
278 bluetooth_register_callback(bt_event_callback, NULL);
281 TC_PRT("%s failed with [0x%04x]", tc_table[0].tc_name, ret);
282 tc_result(TC_FAIL, 1);
287 bluetooth_unregister_callback();
290 TC_PRT("%s failed with [0x%04x]", tc_table[1].tc_name, ret);
291 tc_result(TC_FAIL, 1);
296 ret = bluetooth_enable_adapter();
299 TC_PRT("%s failed with [0x%04x]", tc_table[2].tc_name, ret);
300 tc_result(TC_FAIL, 1);
305 ret = bluetooth_disable_adapter();
308 TC_PRT("%s failed with [0x%04x]", tc_table[3].tc_name, ret);
309 tc_result(TC_FAIL, 2);
315 ret = bluetooth_check_adapter();
316 TC_PRT("state: %d", ret);
322 bluetooth_device_address_t address = {{0}};
323 ret = bluetooth_get_local_address(&address);
326 TC_PRT("%s failed with [0x%04x]", tc_table[5].tc_name, ret);
328 TC_PRT("dev [%2.2X:%2.2X:%2.2X:%2.2X:%2.2X:%2.2X]", \
329 address.addr[0], address.addr[1], address.addr[2], \
330 address.addr[3], address.addr[4], address.addr[5]);
337 bluetooth_device_name_t local_name = {{0}};
339 ret = bluetooth_get_local_name(&local_name);
342 TC_PRT("%s failed with [0x%04x]", tc_table[6].tc_name, ret);
344 TC_PRT("name: %s", local_name.name);
351 bluetooth_device_name_t local_name = {{0}};
352 snprintf(local_name.name, sizeof(local_name.name),
353 "bt-frwk-pid-%d", getpid());
355 ret = bluetooth_set_local_name(&local_name);
358 TC_PRT("%s failed with [0x%04x]", tc_table[7].tc_name, ret);
365 bluetooth_version_t local_version = {{0}};
366 snprintf(local_version.version, sizeof(local_version.version),
367 "version%d", getpid());
369 ret = bluetooth_get_local_version(&local_version);
371 TC_PRT("%s failed with [0x%04x]", tc_table[89].tc_name, ret);
373 TC_PRT("version: %s", local_version.version);
379 gboolean used = FALSE;
381 ret = bluetooth_is_service_used(rfcomm_test_uuid_spp, &used);
384 TC_PRT("%s failed with [0x%04x]", tc_table[8].tc_name, ret);
386 TC_PRT("used: %d", used);
393 bluetooth_discoverable_mode_t mode;
394 ret = bluetooth_get_discoverable_mode(&mode);
397 TC_PRT("%s failed with [0x%04x]", tc_table[9].tc_name, ret);
401 TC_PRT("BT Get Discoverable mode [%d]", mode);
408 bluetooth_discoverable_mode_t mode = BLUETOOTH_DISCOVERABLE_MODE_CONNECTABLE;
409 ret = bluetooth_set_discoverable_mode(mode, 0);
412 TC_PRT("%s failed with [0x%04x]", tc_table[10].tc_name, ret);
416 TC_PRT("BT Set Discoverable mode [%d]", mode);
423 bluetooth_discoverable_mode_t mode = BLUETOOTH_DISCOVERABLE_MODE_GENERAL_DISCOVERABLE;
424 ret = bluetooth_set_discoverable_mode(mode, 0);
427 TC_PRT("%s failed with [0x%04x]", tc_table[11].tc_name, ret);
431 TC_PRT("BT Set Discoverable mode [%d]", mode);
438 bluetooth_discoverable_mode_t mode = BLUETOOTH_DISCOVERABLE_MODE_TIME_LIMITED_DISCOVERABLE;
439 ret = bluetooth_set_discoverable_mode(mode, 5);
442 TC_PRT("%s failed with [0x%04x]", tc_table[12].tc_name, ret);
446 TC_PRT("BT Set Discoverable mode [%d]", mode);
452 ret = bluetooth_start_discovery(0,0,0);
455 TC_PRT("%s failed with [0x%04x]", tc_table[13].tc_name, ret);
460 ret = bluetooth_cancel_discovery();
463 TC_PRT("%s failed with [0x%04x]", tc_table[14].tc_name, ret);
469 ret = bluetooth_is_discovering();
472 TC_PRT("%s failed with [0x%04x]", tc_table[15].tc_name, ret);
476 TC_PRT("Discovering [%d]", ret);
481 case 17: /*Get paired device list */
483 GPtrArray *devinfo = NULL;
484 devinfo = g_ptr_array_new();
485 TC_PRT("g pointer arrary count : [%d]", devinfo->len);
487 ret = bluetooth_get_bonded_device_list(&devinfo);
490 TC_PRT("%s failed with [0x%04x]", tc_table[16].tc_name, ret);
495 bluetooth_device_info_t *ptr;
496 TC_PRT("g pointer arrary count : [%d]", devinfo->len);
498 for(i=0; i<devinfo->len;i++)
500 ptr = g_ptr_array_index(devinfo, i);
503 TC_PRT("Name [%s]", ptr->device_name.name);
504 TC_PRT("Major Class [%d]", ptr->device_class.major_class);
505 TC_PRT("Minor Class [%d]", ptr->device_class.minor_class);
506 TC_PRT("Service Class [%d]", ptr->device_class.service_class);
507 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]);
512 g_ptr_array_free(devinfo, TRUE);
519 /* Apple wireless keyboard */
520 //bluetooth_device_address_t device_address={{0xE8,0x06,0x88,0x3B,0x18,0xBA}};
521 //bluetooth_device_address_t device_address={{0x00,0x19,0x0E,0x01,0x61,0x17}}; /* DO-DH79-PYUN04 */
522 //bluetooth_device_address_t device_address={{0x00,0x16,0x38,0xC3,0x1F,0xD2}}; /* DO-DH79-PYUN03 */
523 //bluetooth_device_address_t device_address={{0x58,0x17,0x0C,0xEC,0x6A,0xF3}}; /* MW600 */
524 bluetooth_device_address_t device_address={{0x00,0x0D,0xFD,0x24,0x5E,0xFF}}; /* Motorola S9 */
526 TC_PRT("dev [%2.2X:%2.2X:%2.2X:%2.2X:%2.2X:%2.2X]", \
527 device_address.addr[0], device_address.addr[1], device_address.addr[2], \
528 device_address.addr[3], device_address.addr[4], device_address.addr[5]);
530 ret = bluetooth_bond_device(&device_address);
533 TC_PRT("%s failed with [0x%04x]", tc_table[17].tc_name, ret);
539 case 19: /*Cancel bonding */
541 ret = bluetooth_cancel_bonding();
544 TC_PRT("%s failed with [0x%04x]", tc_table[18].tc_name, ret);
550 case 20: /*unbonding */
552 bluetooth_device_address_t device_address={{0x00,0x19,0x0E,0x01,0x61,0x17}}; /* DO-DH79-PYUN04 */
553 //bluetooth_device_address_t device_address={{0x00,0x16,0x38,0xC3,0x1F,0xD2}};
554 ret = bluetooth_unbond_device(&device_address);
557 TC_PRT("%s failed with [0x%04x]", tc_table[19].tc_name, ret);
563 case 21: /*Get paired device */
565 bluetooth_device_info_t devinfo;
566 bluetooth_device_address_t device_address={{0x00,0x16,0x38,0xC3,0x1F,0xD2}};
568 memset(&devinfo, 0x00, sizeof(bluetooth_device_info_t));
570 ret = bluetooth_get_bonded_device(&device_address, &devinfo);
571 if (ret != BLUETOOTH_ERROR_NONE)
573 TC_PRT("bluetooth_get_bonded_device failed with [%d]",ret);
577 TC_PRT("Name [%s]", devinfo.device_name.name);
578 TC_PRT("Major Class [%d]", devinfo.device_class.major_class);
579 TC_PRT("Minor Class [%d]", devinfo.device_class.minor_class);
580 TC_PRT("Service Class [%d]", devinfo.device_class.service_class);
581 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]);
587 case 22: /*set alias for bonded device */
589 bluetooth_device_address_t device_address={{0x00,0x16,0x38,0xC3,0x1F,0xD2}};
591 ret = bluetooth_set_alias(&device_address, "Renamed device");
593 TC_PRT("%s failed with [0x%04x]", tc_table[21].tc_name, ret);
599 bluetooth_device_address_t device_address={{0x00,0x16,0x38,0xC3,0x1F,0xD2}};
601 ret = bluetooth_authorize_device(&device_address, TRUE);
603 TC_PRT("%s failed with [0x%04x]", tc_table[22].tc_name, ret);
608 bluetooth_device_address_t device_address={{0x00,0x16,0x38,0xC3,0x1F,0xD2}};
610 ret = bluetooth_authorize_device(&device_address, FALSE);
612 TC_PRT("%s failed with [0x%04x]", tc_table[23].tc_name, ret);
617 bluetooth_device_address_t device_address={{0x00,0x19,0x0E,0x01,0x61,0x17}}; /* DO-DH79-PYUN04 */
619 ret = bluetooth_search_service(&device_address);
621 TC_PRT("%s failed with [0x%04x]", tc_table[24].tc_name, ret);
626 ret = bluetooth_cancel_service_search();
628 TC_PRT("%s failed with [0x%04x]", tc_table[24].tc_name, ret);
633 gboolean connected = FALSE;
634 bluetooth_device_address_t device_address={{0x00,0x1B,0x66,0x01,0x23,0x1C}}; /* Gennheiser PX210BT */
636 ret = bluetooth_is_device_connected(&device_address, BLUETOOTH_A2DP_SERVICE, &connected);
638 TC_PRT("%s failed with [0x%04x]", tc_table[24].tc_name, ret);
640 TC_PRT("connected : %d", connected);
645 ret = bluetooth_reset_adapter();
647 TC_PRT("%s failed with [0x%04x]", tc_table[27].tc_name, ret);
652 bluetooth_manufacturer_data_t m_data;
653 guint8 data[6] = {0x05, 0xFF, 0x02, 0x03, 0x04, 0x05};
655 TC_PRT("%x %x %x %x %x %x", data[0], data[1], data[2], data[3],
657 memcpy(m_data.data, data, sizeof(data));
658 m_data.data_len = sizeof(data) - 2;
659 ret = bluetooth_set_manufacturer_data(&m_data);
661 TC_PRT("%s failed with [0x%04x]", tc_table[90].tc_name, ret);
666 ret = bluetooth_audio_init(bt_audio_event_callback, NULL);
668 TC_PRT("%s failed with [0x%04x]", tc_table[28].tc_name, ret);
673 ret = bluetooth_audio_deinit();
675 TC_PRT("%s failed with [0x%04x]", tc_table[29].tc_name, ret);
681 //bluetooth_device_address_t device_address={{0x58,0x17,0x0C,0xEC,0x6A,0xF3}};
682 bluetooth_device_address_t device_address={{0x00,0x0D,0xFD,0x24,0x5E,0xFF}}; /* Motorola S9 */
684 ret = bluetooth_audio_connect(&device_address);
686 TC_PRT("%s failed with [0x%04x]", tc_table[30].tc_name, ret);
692 //bluetooth_device_address_t device_address={{0x58,0x17,0x0C,0xEC,0x6A,0xF3}};
693 bluetooth_device_address_t device_address={{0x00,0x0D,0xFD,0x24,0x5E,0xFF}}; /* Motorola S9 */
695 ret = bluetooth_audio_disconnect(&device_address);
697 TC_PRT("%s failed with [0x%04x]", tc_table[31].tc_name, ret);
703 bluetooth_device_address_t device_address={{0x58,0x17,0x0C,0xEC,0x6A,0xF3}};
705 ret = bluetooth_ag_connect(&device_address);
707 TC_PRT("%s failed with [0x%04x]", tc_table[32].tc_name, ret);
713 bluetooth_device_address_t device_address={{0x58,0x17,0x0C,0xEC,0x6A,0xF3}};
715 ret = bluetooth_ag_disconnect(&device_address);
717 TC_PRT("%s failed with [0x%04x]", tc_table[33].tc_name, ret);
723 bluetooth_device_address_t device_address={{0x58,0x17,0x0C,0xEC,0x6A,0xF3}};
725 ret = bluetooth_av_connect(&device_address);
727 TC_PRT("%s failed with [0x%04x]", tc_table[34].tc_name, ret);
733 bluetooth_device_address_t device_address={{0x58,0x17,0x0C,0xEC,0x6A,0xF3}};
735 ret = bluetooth_av_disconnect(&device_address);
737 TC_PRT("%s failed with [0x%04x]", tc_table[35].tc_name, ret);
742 unsigned int volume = 0;
744 ret = bluetooth_ag_get_headset_volume(&volume);
746 TC_PRT("failed with [0x%04x]", ret);
748 TC_PRT("volume: %u", volume);
753 ret = bluetooth_ag_set_speaker_gain(10);
755 TC_PRT("failed with [0x%04x]", ret);
761 if (bluetooth_oob_read_local_data(&g_local_oob_data.oob_data))
762 TC_PRT("ERROR in bluetooth_oob_read_local_data\n");
764 TC_PRT("SUCESS in bluetooth_oob_read_local_data\n");
765 TC_PRT("hash = [%2.2X:%2.2X:%2.2X:%2.2X:%2.2X:%2.2X:%2.2X:%2.2X"
766 "%2.2X:%2.2X:%2.2X:%2.2X:%2.2X:%2.2X:%2.2X:%2.2X]\n",
767 g_local_oob_data.oob_data.hash[0],
768 g_local_oob_data.oob_data.hash[1],
769 g_local_oob_data.oob_data.hash[2],
770 g_local_oob_data.oob_data.hash[3],
771 g_local_oob_data.oob_data.hash[4],
772 g_local_oob_data.oob_data.hash[5],
773 g_local_oob_data.oob_data.hash[6],
774 g_local_oob_data.oob_data.hash[7],
775 g_local_oob_data.oob_data.hash[8],
776 g_local_oob_data.oob_data.hash[9],
777 g_local_oob_data.oob_data.hash[10],
778 g_local_oob_data.oob_data.hash[11],
779 g_local_oob_data.oob_data.hash[12],
780 g_local_oob_data.oob_data.hash[13],
781 g_local_oob_data.oob_data.hash[14],
782 g_local_oob_data.oob_data.hash[15]);
784 TC_PRT("randomizer = [%2.2X:%2.2X:%2.2X:%2.2X:%2.2X:%2.2X:%2.2X:%2.2X"
785 "%2.2X:%2.2X:%2.2X:%2.2X:%2.2X:%2.2X:%2.2X:%2.2X]\n",
786 g_local_oob_data.oob_data.randomizer[0],
787 g_local_oob_data.oob_data.randomizer[1],
788 g_local_oob_data.oob_data.randomizer[2],
789 g_local_oob_data.oob_data.randomizer[3],
790 g_local_oob_data.oob_data.randomizer[4],
791 g_local_oob_data.oob_data.randomizer[5],
792 g_local_oob_data.oob_data.randomizer[6],
793 g_local_oob_data.oob_data.randomizer[7],
794 g_local_oob_data.oob_data.randomizer[8],
795 g_local_oob_data.oob_data.randomizer[9],
796 g_local_oob_data.oob_data.randomizer[10],
797 g_local_oob_data.oob_data.randomizer[11],
798 g_local_oob_data.oob_data.randomizer[12],
799 g_local_oob_data.oob_data.randomizer[13],
800 g_local_oob_data.oob_data.randomizer[14],
801 g_local_oob_data.oob_data.randomizer[15]);
803 TC_PRT("hash_len: %d\n", g_local_oob_data.oob_data.hash_len);
804 TC_PRT("randomizer_len: %d\n", g_local_oob_data.oob_data.randomizer_len);
810 ret = bluetooth_get_local_address(&g_local_oob_data.address);
811 TC_PRT("hash_len: %d\n", g_local_oob_data.oob_data.hash_len);
812 TC_PRT("randomizer_len: %d\n", g_local_oob_data.oob_data.randomizer_len);
814 if (bluetooth_oob_add_remote_data(&g_local_oob_data.address,
815 &g_local_oob_data.oob_data))
816 TC_PRT("ERROR in bluetooth_oob_add_remote_data\n");
818 TC_PRT(" bluetooth_oob_add_remote_data SUCCESS\n");
824 if (bluetooth_oob_remove_remote_data(&g_local_oob_data.address))
825 TC_PRT("ERROR in bluetooth_oob_remove_remote_data\n");
827 TC_PRT(" bluetooth_oob_remove_remote_data SUCCESS\n");
832 bluetooth_opc_init();
837 bluetooth_opc_deinit();
842 bluetooth_device_address_t remote_address = {{0}};
845 remote_address.addr[0] = 0x00; remote_address.addr[1] = 0x02; remote_address.addr[2] = 0x70;
846 remote_address.addr[3] = 0x2B; remote_address.addr[4] = 0xD3; remote_address.addr[5]= 0xAF;
848 char *files[5] = {NULL};
850 files[0] = "/opt/media/Images/image1.jpg";
851 // files[1] = "/opt/media/Images/image2.jpg";
852 // files[2] = "/opt/media/Images/image3.jpg";
853 bluetooth_opc_push_files(&remote_address, files);
858 bluetooth_opc_cancel_push();
864 exist = bluetooth_opc_session_is_exist();
865 TC_PRT("exist: %d", exist);
870 bluetooth_network_activate_server();
875 bluetooth_network_deactivate_server();
880 bluetooth_device_address_t device_address = {{0x00, 0x02, 0xA2, 0x14, 0x40, 0x51}};
881 bluetooth_network_connect(&device_address, BLUETOOTH_NETWORK_NAP_ROLE, NULL);
886 bluetooth_device_address_t device_address = {{0x00, 0x02, 0xA2, 0x14, 0x40, 0x51}};
887 bluetooth_network_disconnect(&device_address);
892 bluetooth_obex_server_init("/opt/media/Downloads");
897 bluetooth_obex_server_deinit();
902 bluetooth_obex_server_init_without_agent("/opt/media/Downloads");
907 bluetooth_obex_server_deinit_without_agent();
912 bluetooth_obex_server_is_activated();
917 bluetooth_obex_server_accept_connection();
918 TC_PRT(" bluetooth_obex_server_accept_connection SUCCESS\n");
923 bluetooth_obex_server_reject_connection();
928 bluetooth_obex_server_accept_authorize("abc");
933 bluetooth_obex_server_reject_authorize();
938 bluetooth_obex_server_set_destination_path("/opt/media");
943 bluetooth_obex_server_set_root("/opt/media");
948 bluetooth_obex_server_cancel_transfer(0);
953 bluetooth_obex_server_cancel_all_transfers();
959 ret = bluetooth_hid_init(bt_hid_event_callback, NULL);
961 TC_PRT("Failed with [0x%04x]", ret);
966 ret = bluetooth_hid_deinit();
968 TC_PRT("Failed with [0x%04x]", ret);
973 /* Apple wireless keyboard */
974 hid_device_address_t device_address={{0xE8,0x06,0x88,0x3B,0x18,0xBA}};
976 ret = bluetooth_hid_connect(&device_address);
978 TC_PRT("Failed with [0x%04x]", ret);
983 /* Apple wireless keyboard */
984 hid_device_address_t device_address={{0xE8,0x06,0x88,0x3B,0x18,0xBA}};
986 ret = bluetooth_hid_disconnect(&device_address);
988 TC_PRT("Failed with [0x%04x]", ret);
994 bluetooth_device_address_t device_address = {{0x00, 0x02, 0x2F, 0x92, 0x7B, 0xF5}};
996 ret = bluetooth_rfcomm_connect(&device_address, rfcomm_test_uuid_spp);
997 //ret = bluetooth_rfcomm_connect(&device_address, "1");
1000 TC_PRT("Failed with [0x%04x]", ret);
1005 ret = bluetooth_rfcomm_disconnect(-1);
1008 TC_PRT("Failed with [0x%04x]", ret);
1013 ret = bluetooth_rfcomm_disconnect(g_ret_client_fd1);
1016 TC_PRT("Failed with [0x%04x]", ret);
1021 const char rd_data[] = "123456789 12345";
1022 ret = bluetooth_rfcomm_write(g_ret_client_fd1, rd_data, sizeof(rd_data));
1025 TC_PRT("Failed with [0x%04x]", ret);
1030 gboolean is_connected;
1032 is_connected = bluetooth_rfcomm_is_client_connected();
1034 TC_PRT("Connected: %d", is_connected);
1039 ret = bluetooth_rfcomm_create_socket(rfcomm_test_uuid_spp);
1041 TC_PRT("Failed with [0x%04x]", ret);
1043 TC_PRT("Returned FD = %d", ret);
1049 ret = bluetooth_rfcomm_create_socket(rfcomm_test_uuid_custom);
1051 TC_PRT("Failed with [0x%04x]", ret);
1053 TC_PRT("Returned FD = %d", ret);
1059 ret = bluetooth_rfcomm_remove_socket(server_fd);
1061 TC_PRT("Failed with [0x%04x]", ret);
1064 case 83: /*Listen and accept */
1067 ret = bluetooth_rfcomm_listen_and_accept(server_fd, 1);
1069 TC_PRT("Failed with [0x%04x]", ret);
1071 TC_PRT("result = %d", ret);
1074 case 84: /*Listen */
1077 ret = bluetooth_rfcomm_listen(server_fd, 1);
1079 TC_PRT("Failed with [0x%04x]", ret);
1081 TC_PRT("result = %d", ret);
1086 ret = bluetooth_rfcomm_server_disconnect(client_fd);
1088 TC_PRT("Failed with [0x%04x]", ret);
1095 available = bluetooth_rfcomm_is_server_uuid_available(rfcomm_test_uuid_spp);
1097 TC_PRT("available: %d", available);
1102 ret = bluetooth_rfcomm_accept_connection(server_fd, &client_fd);
1104 TC_PRT("Failed with [0x%04x]", ret);
1105 TC_PRT("client fd: %d", client_fd);
1110 ret = bluetooth_rfcomm_reject_connection(server_fd);
1112 TC_PRT("Failed with [0x%04x]", ret);
1116 ret = bluetooth_start_custom_discovery(DISCOVERY_ROLE_LE,
1120 TC_PRT("failed with [0x%04x]", ret);
1124 ret = bluetooth_gatt_init();
1127 TC_PRT("gatt init failed with [0x%04x]", ret);
1132 ret = bluetooth_gatt_deinit();
1135 TC_PRT("gatt deinit failed with [0x%04x]", ret);
1140 char *service_uuid = g_strdup("00001802-0000-1000-8000-00805f9b34fb");
1142 ret = bluetooth_gatt_add_service(service_uuid,
1144 g_free(service_uuid);
1146 TC_PRT("service obj_path is %s", svc_obj_path);
1151 /* testing with dummy values*/
1152 char *char_uuid = g_strdup("00002a06-0000-1000-8000-00805f9b34fb");
1153 bt_gatt_characteristic_property_t props = BLUETOOTH_GATT_CHARACTERISTIC_PROPERTY_READ |
1154 BLUETOOTH_GATT_CHARACTERISTIC_PROPERTY_WRITE |
1155 BLUETOOTH_GATT_CHARACTERISTIC_PROPERTY_NOTIFY |
1156 BLUETOOTH_GATT_CHARACTERISTIC_PROPERTY_INDICATE;
1158 ret = bluetooth_gatt_add_new_characteristic(
1159 svc_obj_path, char_uuid,
1160 props, &char_obj_path);
1163 TC_PRT("characteristic obj_path is %s", char_obj_path);
1169 char *desc_uuid = g_strdup("000026ff-0000-1000-8000-00805f9b34fb");
1171 ret = bluetooth_gatt_add_descriptor(char_obj_path,
1172 desc_uuid, &desc_obj_path);
1174 TC_PRT("add descriptor error is %d", ret);
1180 ret = bluetooth_gatt_register_service(svc_obj_path);
1182 TC_PRT("register service error is %d", ret);
1187 char char_data[4] = {10, 20, 30, 40};
1188 int char_length = 4;
1189 ret = bluetooth_gatt_update_characteristic(char_obj_path,
1190 char_data, char_length);
1192 TC_PRT("update_characteristic error is %d", ret);
1197 ret = bluetooth_gatt_unregister_service(svc_obj_path);
1199 TC_PRT("service removed with error is %d", ret);
1204 ret = bluetooth_gatt_delete_services();
1206 TC_PRT("services deleted with error is %d", ret);
1219 TC_PRT("bluetooth framework TC startup");
1221 if(!g_thread_supported())
1223 g_thread_init(NULL);
1226 dbus_g_thread_init();
1229 main_loop = g_main_loop_new(NULL, FALSE);
1234 TC_PRT("bluetooth framework TC cleanup");
1235 if( main_loop!= NULL)
1237 g_main_loop_unref(main_loop);
1241 int timeout_callback(void *data)
1243 TC_PRT("timeout callback");
1244 timeout_status = -1;
1246 g_main_loop_quit(main_loop);
1252 void bt_hid_event_callback(int event, hid_event_param_t* param, void *user_data)
1254 TC_PRT(">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>");
1255 TC_PRT("bt event callback 0x%04x", event);
1261 void bt_audio_event_callback(int event, bt_audio_event_param_t* param, void *user_data)
1263 TC_PRT(">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>");
1264 TC_PRT("bt event callback 0x%04x", event);
1270 void bt_event_callback(int event, bluetooth_event_param_t* param, void *user_data)
1272 TC_PRT(">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>");
1273 TC_PRT("bt event callback 0x%04x", event);
1276 case BLUETOOTH_EVENT_ENABLED:
1277 TC_PRT("BLUETOOTH_EVENT_ENABLED, result [0x%04x]", param->result);
1280 case BLUETOOTH_EVENT_DISABLED:
1281 TC_PRT("BLUETOOTH_EVENT_DISABLED, result [0x%04x]", param->result);
1284 case BLUETOOTH_EVENT_LOCAL_NAME_CHANGED:
1285 TC_PRT("BLUETOOTH_EVENT_LOCAL_NAME_CHANGED, result [0x%04x]", param->result);
1286 if (param->result == BLUETOOTH_ERROR_NONE)
1288 bluetooth_device_name_t *local_name = (bluetooth_device_name_t *)param->param_data;
1289 tc_result(TC_PASS, 6);
1290 TC_PRT("Changed Name : [%s]", local_name->name);
1294 tc_result(TC_FAIL, 6);
1299 case BLUETOOTH_EVENT_DISCOVERY_STARTED:
1300 TC_PRT("BLUETOOTH_EVENT_DISCOVERY_STARTED, result [0x%04x]", param->result);
1303 case BLUETOOTH_EVENT_REMOTE_DEVICE_FOUND:
1305 bluetooth_device_info_t *device_info = NULL;
1306 TC_PRT("BLUETOOTH_EVENT_REMOTE_DEVICE_FOUND, result [0x%04x]", param->result);
1307 device_info = (bluetooth_device_info_t *)param->param_data;
1308 memcpy(&searched_device, &device_info->device_address, sizeof(bluetooth_device_address_t));
1309 TC_PRT("dev [%2.2X:%2.2X:%2.2X:%2.2X:%2.2X:%2.2X]", \
1310 device_info->device_address.addr[0], device_info->device_address.addr[1], device_info->device_address.addr[2], \
1311 device_info->device_address.addr[3], device_info->device_address.addr[4], device_info->device_address.addr[5]);
1315 case BLUETOOTH_EVENT_REMOTE_LE_DEVICE_FOUND:
1318 bluetooth_le_device_info_t *le_device_info = NULL;
1319 TC_PRT("BLUETOOTH_EVENT_REMOTE_LE_DEVICE_FOUND, result [0x%04x]", param->result);
1320 le_device_info = (bluetooth_le_device_info_t *)param->param_data;
1321 TC_PRT("dev[%2.2X:%2.2X:%2.2X:%2.2X:%2.2X:%2.2X]", \
1322 le_device_info->device_address.addr[0], le_device_info->device_address.addr[1], le_device_info->device_address.addr[2], \
1323 le_device_info->device_address.addr[3], le_device_info->device_address.addr[4], le_device_info->device_address.addr[5]);
1324 TC_PRT("addr_type : %d", le_device_info->addr_type);
1325 TC_PRT("rssi : %d", le_device_info->rssi);
1326 TC_PRT("adv_ind_data_len :%d" , le_device_info->adv_ind_data.data_len);
1327 TC_PRT("scan_resp_data_len :%d" , le_device_info->scan_resp_data.data_len);
1329 for (i=0; i<le_device_info->adv_ind_data.data_len; i++)
1330 TC_PRT("adv_ind_data[%d] : [0x%x]",i ,le_device_info->adv_ind_data.data.data[i]);
1331 for (i=0; i<le_device_info->scan_resp_data.data_len; i++)
1332 TC_PRT("scan_resp_data[%d] : [0x%x]",i ,le_device_info->scan_resp_data.data.data[i]);
1336 case BLUETOOTH_EVENT_REMOTE_DEVICE_NAME_UPDATED:
1338 bluetooth_device_info_t *device_info = NULL;
1339 TC_PRT("BLUETOOTH_EVENT_REMOTE_DEVICE_NAME_UPDATED, result [0x%04x]", param->result);
1340 device_info = (bluetooth_device_info_t *)param->param_data;
1341 memcpy(&searched_device, &device_info->device_address, sizeof(bluetooth_device_address_t));
1342 TC_PRT("dev [%s] [%2.2X:%2.2X:%2.2X:%2.2X:%2.2X:%2.2X]", device_info->device_name.name, \
1343 device_info->device_address.addr[0], device_info->device_address.addr[1], device_info->device_address.addr[2], \
1344 device_info->device_address.addr[3], device_info->device_address.addr[4], device_info->device_address.addr[5]);
1348 case BLUETOOTH_EVENT_DISCOVERY_FINISHED:
1349 TC_PRT("BLUETOOTH_EVENT_DISCOVERY_FINISHED, result [0x%04x]", param->result);
1352 case BLUETOOTH_EVENT_DISCOVERABLE_MODE_CHANGED:
1354 int *mode = (int *)param->param_data;
1355 TC_PRT("BT_DISCOVERABLE_MODE_CHANGED, result [0x%04x]", param->result);
1356 TC_PRT("mode [%d]", *mode);
1359 case BLUETOOTH_EVENT_DISCOVERABLE_TIMEOUT_CHANGED:
1361 int *timeout = (int *)param->param_data;
1362 TC_PRT("BLUETOOTH_EVENT_DISCOVERABLE_TIMEOUT_CHANGED, result [0x%04x]", param->result);
1363 TC_PRT("timeout [%d]", *timeout);
1366 case BLUETOOTH_EVENT_BONDING_FINISHED:
1368 TC_PRT("BLUETOOTH_EVENT_BONDING_FINISHED, result [0x%04x]", param->result);
1369 if (param->result >= BLUETOOTH_ERROR_NONE)
1371 bluetooth_device_info_t *device_info = NULL;
1372 tc_result(TC_PASS, 12);
1373 device_info = (bluetooth_device_info_t *)param->param_data;
1374 if (device_info == NULL)
1377 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, \
1378 device_info->device_address.addr[0], device_info->device_address.addr[1], device_info->device_address.addr[2], \
1379 device_info->device_address.addr[3], device_info->device_address.addr[4], device_info->device_address.addr[5], \
1380 device_info->device_class.major_class, device_info->device_class.minor_class, device_info->device_class.service_class);
1384 tc_result(TC_FAIL, 12);
1389 case BLUETOOTH_EVENT_BONDED_DEVICE_FOUND:
1391 // bluetooth_get_bonded_device_list is changed as synchronous API. This event is not used any more.
1395 TC_PRT("BLUETOOTH_EVENT_BONDED_DEVICE_FOUND, result [0x%04x]", param->result);
1396 if (param->result >= BLUETOOTH_ERROR_NONE)
1398 ///tc_result(TC_PASS, 15);
1399 bluetooth_device_info_t * bt_dev_info= (bluetooth_device_info_t*)param->param_data;
1401 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,
1402 bt_dev_info->device_address.addr[0], bt_dev_info->device_address.addr[1], bt_dev_info->device_address.addr[2], \
1403 bt_dev_info->device_address.addr[3], bt_dev_info->device_address.addr[4], bt_dev_info->device_address.addr[5], \
1404 bt_dev_info->device_class.major_class, bt_dev_info->device_class.minor_class, bt_dev_info->device_class.service_class);
1408 if(param->result == BLUETOOTH_ERROR_END_OF_DEVICE_LIST) /*End of the Device found indication*/
1410 tc_result(TC_PASS, 15);
1411 TC_PRT("*****<<No more BLUETOOTH_EVENT_BONDED_DEVICE_FOUND indication>>***** ");
1415 tc_result(TC_FAIL, 15);
1416 TC_PRT("*****API failed ***** ");
1421 case BLUETOOTH_EVENT_SERVICE_SEARCHED:
1424 TC_PRT("BLUETOOTH_EVENT_SERVICE_SEARCHED, result [0x%04x]", param->result);
1425 if (param->result >= BLUETOOTH_ERROR_NONE)
1427 tc_result(TC_PASS, 18);
1428 bt_sdp_info_t * bt_sdp_info=param->param_data;
1430 TC_PRT("Dev add = %2.2X:%2.2X:%2.2X:%2.2X:%2.2X:%2.2X\n",
1431 bt_sdp_info->device_addr.addr[0], bt_sdp_info->device_addr.addr[1], bt_sdp_info->device_addr.addr[2], \
1432 bt_sdp_info->device_addr.addr[3], bt_sdp_info->device_addr.addr[4], bt_sdp_info->device_addr.addr[5]);
1434 TC_PRT("Supported service list:\n");
1435 for(i=0; i<bt_sdp_info->service_index; i++)
1436 TC_PRT("[%#x]\n", bt_sdp_info->service_list_array[i]);
1441 tc_result(TC_FAIL, 18);
1445 case BLUETOOTH_EVENT_RFCOMM_DATA_RECEIVED:
1447 TC_PRT("BLUETOOTH_EVENT_RFCOMM_DATA_RECEIVED, result [0x%04x]", param->result);
1448 bluetooth_rfcomm_received_data_t *rx_data = param->param_data;
1449 printf("\n FD = %d \nBuffer len = %d ", rx_data->socket_fd, rx_data->buffer_size);
1450 if (rx_data->buffer_size < sizeof(oob_data_t))
1451 TC_PRT("Complete oob data is not recivedn");
1453 memcpy(&g_remote_oob_data,rx_data->buffer, sizeof(oob_data_t));
1454 //tc_result(TC_PASS, 21);
1457 case BLUETOOTH_EVENT_RFCOMM_CONNECTED:
1459 bluetooth_rfcomm_connection_t *con_ind = (bluetooth_rfcomm_connection_t *)param->param_data;
1460 TC_PRT("BLUETOOTH_EVENT_RFCOMM_CONNECTED, result [0x%04x], fd = %d, device add = 0x%X:%X:%X:%X:%X:%X, Role = %s", param->result,
1462 con_ind->device_addr.addr[0], con_ind->device_addr.addr[1], con_ind->device_addr.addr[2],
1463 con_ind->device_addr.addr[3], con_ind->device_addr.addr[4], con_ind->device_addr.addr[5],
1464 (con_ind->device_role == RFCOMM_ROLE_SERVER)? "SERVER":"CLIENT");
1465 //tc_result(TC_PASS, 22);
1466 if((con_ind->device_role == RFCOMM_ROLE_CLIENT) && (con_ind->socket_fd > 0))
1468 g_ret_client_fd1 = con_ind->socket_fd;
1471 if((con_ind->device_role == RFCOMM_ROLE_SERVER) && (con_ind->socket_fd > 0))
1473 client_fd = con_ind->socket_fd;
1478 case BLUETOOTH_EVENT_RFCOMM_DISCONNECTED:
1480 bluetooth_rfcomm_disconnection_t *disconnection_ind = (bluetooth_rfcomm_disconnection_t *)param->param_data;;
1481 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,
1482 disconnection_ind->device_addr.addr[0], disconnection_ind->device_addr.addr[1], disconnection_ind->device_addr.addr[2],
1483 disconnection_ind->device_addr.addr[3], disconnection_ind->device_addr.addr[4], disconnection_ind->device_addr.addr[5] );
1484 //tc_result(TC_PASS, 22);
1487 case BLUETOOTH_EVENT_NETWORK_SERVER_CONNECTED:
1489 bluetooth_network_device_info_t *dev_info = (bluetooth_network_device_info_t *)param->param_data;
1491 TC_PRT("BLUETOOTH_EVENT_RFCOMM_DISCONNECTED, result [0x%04x]", param->result);
1492 TC_PRT("interface name: %s", dev_info->interface_name);
1494 TC_PRT("device add = %2.2X:%2.2X:%2.2X:%2.2X:%2.2X:%2.2X\n",
1495 dev_info->device_address.addr[0], dev_info->device_address.addr[1], dev_info->device_address.addr[2],
1496 dev_info->device_address.addr[3], dev_info->device_address.addr[4], dev_info->device_address.addr[5] );
1499 case BLUETOOTH_EVENT_NETWORK_SERVER_DISCONNECTED:
1501 bluetooth_network_device_info_t *dev_info = (bluetooth_network_device_info_t *)param->param_data;
1503 TC_PRT("BLUETOOTH_EVENT_RFCOMM_DISCONNECTED, result [0x%04x]", param->result);
1504 TC_PRT("interface name: %s", dev_info->interface_name);
1506 TC_PRT("device add = %2.2X:%2.2X:%2.2X:%2.2X:%2.2X:%2.2X\n",
1507 dev_info->device_address.addr[0], dev_info->device_address.addr[1], dev_info->device_address.addr[2],
1508 dev_info->device_address.addr[3], dev_info->device_address.addr[4], dev_info->device_address.addr[5] );
1512 case BLUETOOTH_EVENT_HDP_CONNECTED:
1514 bt_hdp_connected_t *conn_ind = (bt_hdp_connected_t *)param->param_data;
1516 TC_PRT("BLUETOOTH_EVENT_HDP_CONNECTED, Result = %s\n", (param->result == 0)? "BLUETOOTH_ERROR_NONE": "BLUETOOTH_ERROR_XXXX");
1517 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");
1518 TC_PRT("device add = %2.2X:%2.2X:%2.2X:%2.2X:%2.2X:%2.2X\n",
1519 conn_ind->device_address.addr[0], conn_ind->device_address.addr[1], conn_ind->device_address.addr[2],
1520 conn_ind->device_address.addr[3], conn_ind->device_address.addr[4], conn_ind->device_address.addr[5] );
1522 g_ret_client_fd1 = conn_ind->channel_id;
1526 case BLUETOOTH_EVENT_HDP_DISCONNECTED:
1528 bt_hdp_disconnected_t *dis_ind = (bt_hdp_disconnected_t *)param->param_data;
1530 TC_PRT("BLUETOOTH_EVENT_HDP_DISCONNECTED, Result = %s\n", (param->result == 0)? "BLUETOOTH_ERROR_NONE": "BLUETOOTH_ERROR_XXXX");
1531 TC_PRT("Channel = %d, Add = device add = %2.2X:%2.2X:%2.2X:%2.2X:%2.2X:%2.2X\n", dis_ind->channel_id,
1532 dis_ind->device_address.addr[0], dis_ind->device_address.addr[1], dis_ind->device_address.addr[2],
1533 dis_ind->device_address.addr[3], dis_ind->device_address.addr[4], dis_ind->device_address.addr[5]);
1537 case BLUETOOTH_EVENT_HDP_DATA_RECEIVED:
1539 bt_hdp_data_ind_t *data_ind = (bt_hdp_data_ind_t *)param->param_data;
1541 TC_PRT("BLUETOOTH_EVENT_HDP_DATA_RECEIVED, Result = %s\n", (param->result == 0)? "BLUETOOTH_ERROR_NONE": "BLUETOOTH_ERROR_XXXX");
1542 TC_PRT("Data received from channel id = %d and size =%d, buff =[%s]\n", data_ind->channel_id, data_ind->size, data_ind->buffer);
1547 case BLUETOOTH_EVENT_OPC_CONNECTED:
1548 TC_PRT("BLUETOOTH_EVENT_OPC_CONNECTED");
1551 case BLUETOOTH_EVENT_OPC_DISCONNECTED:
1552 TC_PRT("BLUETOOTH_EVENT_OPC_DISCONNECTED");
1554 case BLUETOOTH_EVENT_OPC_TRANSFER_STARTED:
1556 TC_PRT("BLUETOOTH_EVENT_OPC_TRANSFER_STARTED");
1557 if (param->param_data) {
1558 bt_opc_transfer_info_t *info = param->param_data;
1559 TC_PRT("file %s", info->filename);
1560 TC_PRT("size %ld", info->size);
1564 case BLUETOOTH_EVENT_OPC_TRANSFER_PROGRESS:
1566 TC_PRT("BLUETOOTH_EVENT_OPC_TRANSFER_PROGRESS");
1569 case BLUETOOTH_EVENT_OPC_TRANSFER_COMPLETE:
1571 TC_PRT("BLUETOOTH_EVENT_OPC_TRANSFER_COMPLETE");
1572 bt_opc_transfer_info_t *info = param->param_data;
1573 TC_PRT("file %s", info->filename);
1574 TC_PRT("size %ld", info->size);
1578 case BLUETOOTH_EVENT_OBEX_SERVER_TRANSFER_AUTHORIZE:
1579 TC_PRT("BLUETOOTH_EVENT_OBEX_SERVER_TRANSFER_AUTHORIZE");
1582 case BLUETOOTH_EVENT_OBEX_SERVER_CONNECTION_AUTHORIZE:
1583 TC_PRT("BLUETOOTH_EVENT_OBEX_SERVER_CONNECTION_AUTHORIZE");
1586 case BLUETOOTH_EVENT_OBEX_SERVER_TRANSFER_STARTED:
1587 TC_PRT("BLUETOOTH_EVENT_OBEX_SERVER_TRANSFER_STARTED");
1588 bt_obex_server_transfer_info_t *info = param->param_data;
1589 current_transfer_id = info->transfer_id;
1592 case BLUETOOTH_EVENT_OBEX_SERVER_TRANSFER_PROGRESS:
1593 TC_PRT("BLUETOOTH_EVENT_OBEX_SERVER_TRANSFER_PROGRESS");
1596 case BLUETOOTH_EVENT_OBEX_SERVER_TRANSFER_COMPLETED:
1597 TC_PRT("BLUETOOTH_EVENT_OBEX_SERVER_TRANSFER_COMPLETED");
1599 case BLUETOOTH_EVENT_MANUFACTURER_DATA_CHANGED:
1600 { TC_PRT("BLUETOOTH_EVENT_MANUFACTURER_DATA_CHANGED");
1604 case BLUETOOTH_EVENT_GATT_PRIM_SVC_DISCOVERED:
1606 TC_PRT("BLUETOOTH_EVENT_GATT_PRIM_SVC_DISCOVERED");
1607 bt_gatt_handle_info_t *prim_svc = param->param_data;
1610 if (prim_svc == NULL) {
1611 TC_PRT("prim_svc is NULL");
1615 for (i = 0; i < prim_svc->count; i++) {
1616 TC_PRT("prim_svc[%d] = %s\n", i, prim_svc->handle[i]);
1622 case BLUETOOTH_EVENT_GATT_SVC_CHAR_DISCOVERED:
1624 TC_PRT("BLUETOOTH_EVENT_GATT_SVC_CHAR_DISCOVERED");
1625 bt_gatt_discovered_char_t *svc_char = param->param_data;
1628 if (svc_char == NULL) {
1629 TC_PRT("svc_char is NULL");
1633 if (svc_char->service_handle != NULL) {
1634 TC_PRT("svc_char->service_handle %s \n", svc_char->service_handle);
1637 for (i = 0; i < svc_char->handle_info.count; i++) {
1638 TC_PRT("svc_char.handle_info.handle[%d] = %s\n", i, svc_char->handle_info.handle[i]);
1644 case BLUETOOTH_EVENT_GATT_SVC_PROP_RECEIVED:
1646 TC_PRT("BLUETOOTH_EVENT_GATT_SVC_PROP_RECEIVED");
1647 bt_gatt_service_property_t *svc_pty = param->param_data;
1650 if (svc_pty == NULL) {
1651 TC_PRT("char_pty is NULL \n");
1655 if (svc_pty->service_handle != NULL) {
1656 TC_PRT("svc_pty->service_handle %s \n", svc_pty->service_handle);
1659 if (svc_pty->uuid != NULL) {
1660 TC_PRT("svc_pty->uuid %s \n", svc_pty->uuid);
1663 for (i = 0; i < svc_pty->handle_info.count; i++) {
1664 TC_PRT("svc_char[%d] = %s\n", i, svc_pty->handle_info.handle[i]);
1670 case BLUETOOTH_EVENT_GATT_CHAR_PROP_RECEIVED:
1672 TC_PRT("BLUETOOTH_EVENT_GATT_CHAR_PROP_RECEIVED");
1673 bt_gatt_char_property_t *char_pty = param->param_data;
1676 if (char_pty->char_handle != NULL) {
1677 TC_PRT("char_pty->char_handle %s \n", char_pty->char_handle);
1680 if (char_pty->uuid != NULL) {
1681 TC_PRT("char_pty->uuid %s \n", char_pty->uuid);
1684 if (char_pty == NULL) {
1685 TC_PRT("char_pty is NULL \n");
1689 if (char_pty->name != NULL) {
1690 TC_PRT("char_pty->name %s \n", char_pty->name);
1693 if (char_pty->description != NULL) {
1694 TC_PRT("char_pty->description %s \n", char_pty->description);
1697 if (char_pty->val != NULL) {
1698 TC_PRT("char_pty->val_len %d \n", char_pty->val_len);
1700 for (i = 0; i < char_pty->val_len; i ++)
1701 TC_PRT("char_pty->val %02x \n", char_pty->val[i]);
1708 TC_PRT("received event [0x%04x]", event);
1711 TC_PRT("<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<");
1714 static gboolean key_event_cb(GIOChannel * chan, GIOCondition cond , gpointer data)
1720 memset(buf, 0, sizeof(buf));
1722 if(g_io_channel_read_chars(chan, buf, sizeof(buf),
1723 &len, NULL) == G_IO_STATUS_ERROR) {
1724 TC_PRT("IO Channel read error");
1734 g_idle_add(test_input_callback, (void*)test_id);
1744 key_io=g_io_channel_unix_new(fileno(stdin));
1746 g_io_channel_set_encoding(key_io, NULL, NULL);
1747 g_io_channel_set_flags(key_io, G_IO_FLAG_NONBLOCK, NULL);
1749 g_io_add_watch(key_io, G_IO_IN | G_IO_HUP | G_IO_ERR | G_IO_NVAL,
1750 key_event_cb, NULL);
1751 g_io_channel_unref(key_io);
1753 g_main_loop_run(main_loop);