2 * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
19 * @file bluetooth-frwk-test.c
20 * @brief This is the source file for bluetooth framework test suite.
30 #include "bluetooth-api.h"
31 #include "bluetooth-hid-api.h"
32 #include "bluetooth-audio-api.h"
35 bluetooth_device_address_t searched_device = { {0} };
37 #define TC_TIMEOUT 30000
39 #define BT_DEFAULT_DEV_NAME "SLP-BT-TEST-TARGET"
40 #define DISCOVER_TIMEOUT 20
41 #define DISCOVER_CANCEL_INTERVAL 3
43 #define PRT(format, args...) printf("%s:() "format, __FUNCTION__, ##args)
44 #define TC_PRT(format, args...) PRT(format"\n", ##args)
50 int g_ret_client_fd1 = -1, g_ret_client_fd2 = -1;
51 const char *g_hdp_app_handle1 = NULL;
52 const char *g_hdp_app_handle2 = NULL;
54 char *svc_obj_path = NULL;
55 char *char_obj_path = NULL;
56 char *desc_obj_path = NULL;
59 int hdp_manual_mode = 1;
60 const char *rfcomm_test_uuid_spp = "00001101-0000-1000-8000-00805F9B34FB";
61 const char *rfcomm_test_uuid_dun = "00001103-0000-1000-8000-00805F9B34FB";
62 const char *rfcomm_test_uuid_custom = "26b2831b-2c2d-4f9c-914a-c0ab142351b7";
65 GMainLoop *main_loop = NULL;
67 int current_transfer_id = 0;
70 bluetooth_device_address_t address;
71 bt_oob_data_t oob_data;
74 oob_data_t g_local_oob_data;
75 oob_data_t g_remote_oob_data;
83 void bt_event_callback(int event, bluetooth_event_param_t* param, void *user_data);
84 void bt_hid_event_callback(int event, hid_event_param_t* param, void *user_data);
85 void bt_audio_event_callback(int event, bt_audio_event_param_t* param, void *user_data);
88 tc_table_t tc_table[] = {
89 {"bluetooth_register_callback" , 1},
90 {"bluetooth_unregister_callback" , 2},
91 {"bluetooth_enable_adapter" , 3},
92 {"bluetooth_disable_adapter" , 4},
93 {"bluetooth_check_adapter" , 5},
94 {"bluetooth_get_local_address" , 6},
95 {"bluetooth_get_local_name" , 7},
96 {"bluetooth_set_local_name" , 8},
97 {"bluetooth_get_local_version" , 90},
98 {"bluetooth_is_service_used" , 9},
99 {"bluetooth_get_discoverable_mode" , 10},
100 {"bluetooth_set_discoverable_mode(CONNECTABLE)" , 11},
101 {"bluetooth_set_discoverable_mode(GENERAL_DISCOVERABLE)" , 12},
102 {"bluetooth_set_discoverable_mode(TIME_LIMITED_DISCOVERABLE)" , 13},
103 {"bluetooth_start_discovery" , 14},
104 {"bluetooth_cancel_discovery" , 15},
105 {"bluetooth_is_discovering" , 16},
106 {"bluetooth_get_bonded_device_list" , 17},
107 {"bluetooth_bond_device" , 18},
108 {"bluetooth_cancel_bonding" , 19},
109 {"bluetooth_unbond_device" , 20},
110 {"bluetooth_get_bonded_device" , 21},
111 {"bluetooth_set_alias" , 22},
112 {"bluetooth_authorize_device (TRUE)" , 23},
113 {"bluetooth_authorize_device (FALSE)" , 24},
114 {"bluetooth_search_service" , 25},
115 {"bluetooth_cancel_service_search" , 26},
116 {"bluetooth_is_device_connected" , 27},
117 {"bluetooth_reset_adapter" , 28},
118 {"bluetooth_set_manufacturer_data" , 91},
120 {"bluetooth_audio_init" , 29},
121 {"bluetooth_audio_deinit" , 30},
122 {"bluetooth_audio_connect" , 31},
123 {"bluetooth_audio_disconnect" , 32},
124 {"bluetooth_ag_connect" , 33},
125 {"bluetooth_ag_disconnect" , 34},
126 {"bluetooth_av_connect" , 35},
127 {"bluetooth_av_disconnect" , 36},
128 {"bluetooth_ag_get_headset_volume" , 37},
129 {"bluetooth_ag_set_speaker_gain" , 38},
131 {"bluetooth_oob_read_local_data" , 39},
132 {"bluetooth_oob_add_remote_data" , 40},
133 {"bluetooth_oob_remove_remote_data" , 41},
135 {"bluetooth_opc_init" , 42},
136 {"bluetooth_opc_deinit" , 43},
137 {"bluetooth_opc_push_files" , 44},
138 {"bluetooth_opc_cancel_push" , 45},
139 {"bluetooth_opc_session_is_exist" , 46},
141 {"bluetooth_network_activate_server" , 47},
142 {"bluetooth_network_deactivate_server" , 48},
143 {"bluetooth_network_connect" , 49},
144 {"bluetooth_network_disconnect" , 50},
146 {"bluetooth_obex_server_init" , 51},
147 {"bluetooth_obex_server_deinit" , 52},
148 {"bluetooth_obex_server_init_without_agent" , 53},
149 {"bluetooth_obex_server_deinit_without_agent" , 54},
150 {"bluetooth_obex_server_is_activated" , 55},
151 {"bluetooth_obex_server_accept_connection" , 56},
152 {"bluetooth_obex_server_reject_connection" , 57},
153 {"bluetooth_obex_server_accept_authorize" , 58},
154 {"bluetooth_obex_server_reject_authorize" , 59},
155 {"bluetooth_obex_server_set_destination_path" , 60},
156 {"bluetooth_obex_server_set_root" , 61},
157 {"bluetooth_obex_server_cancel_transfer" , 62},
158 {"bluetooth_obex_server_cancel_all_transfers" , 63},
160 {"bluetooth_hid_init" , 65},
161 {"bluetooth_hid_deinit" , 66},
162 {"bluetooth_hid_connect" , 67},
163 {"bluetooth_hid_disconnect" , 68},
165 {"bluetooth_rfcomm_connect" , 70},
166 {"bluetooth_rfcomm_disconnect (cancel)" , 71},
167 {"bluetooth_rfcomm_disconnect" , 72},
168 {"bluetooth_rfcomm_write" , 73},
169 {"bluetooth_rfcomm_is_client_connected" , 74},
171 {"bluetooth_rfcomm_create_socket" , 80},
172 {"bluetooth_rfcomm_create_socket (Custom UUID)" , 81},
173 {"bluetooth_rfcomm_remove_socket" , 82},
174 {"bluetooth_rfcomm_listen_and_accept" , 83},
175 {"bluetooth_rfcomm_listen (OSP)" , 84},
176 {"bluetooth_rfcomm_server_disconnect" , 85},
177 {"bluetooth_rfcomm_is_server_uuid_available" , 86},
178 {"bluetooth_rfcomm_accept_connection" , 87},
179 {"bluetooth_rfcomm_reject_connection" , 88},
180 {"bluetooth_start_custom_discovery" , 89},
182 {"bluetooth_gatt_init", 92},
183 {"bluetooth_gatt_deinit", 93},
184 {"bluetooth_gatt_add_service", 94},
185 {"bluetooth_gatt_add_characteristics", 95},
186 {"bluetooth_gatt_add_descriptor", 96},
187 {"bluetooth_gatt_register_service", 97},
188 {"bluetooth_gatt_update_characteristic", 98},
189 {"bluetooth_gatt_unregister_service", 99},
190 {"bluetooth_gatt_delete_services", 100},
193 {"bluetooth_rfcomm_is_server_uuid_available" , 26},
195 {"bluetooth_hdp_activate" , 30},
196 {"bluetooth_hdp_deactivate" , 31},
197 {"bluetooth_hdp_connect" , 32},
198 {"bluetooth_hdp_disconnect" , 33},
199 {"bluetooth_hdp_send_data" , 34},
201 {"bluetooth_opc_init" , 35},
202 {"bluetooth_opc_push_file" , 36},
203 {"bluetooth_opc_cancel_push" , 37},
204 {"bluetooth_opc_deinit" , 38},
205 {"bluetooth_obex_server_init" , 39},
206 {"bluetooth_obex_server_deinit" , 40},
207 {"bluetooth_obex_server_accept_authorize" , 41},
208 {"bluetooth_obex_server_reject_authorize" , 42},
209 {"bluetooth_is_supported" , 43},
210 {"bluetooth_opc_session_is_exist" , 46},
211 {"bluetooth_obex_server_is_activated" , 47},
212 {"bluetooth_obex_server_cancel_transfer" , 48},
214 {"bluetooth_oob_read_local_data" , 50},
215 {"bluetooth_oob_add_remote_data" , 51},
216 {"bluetooth_oob_remove_remote_data" , 52},
218 {"bluetooth_network_activate_server" , 60},
219 {"bluetooth_network_deactivate_server" , 61},
220 {"bluetooth_network_connect" , 62},
221 {"bluetooth_network_disconnect" , 63},
223 {"bluetooth_gatt_discover_primary_services", 64},
224 {"bluetooth_gatt_discover_service_characteristics", 65},
225 {"bluetooth_gatt_get_service_property", 66},
226 {"bluetooth_gatt_get_characteristics_value", 67},
227 {"bluetooth_gatt_set_characteristics_value", 68},
229 /* -----------------------------------------*/
236 #define tc_result(success, tc_index) \
237 TC_PRT("Test case [%d - %s] %s", tc_table[tc_index].tc_code, tc_table[tc_index].tc_name, ((success == TC_PASS) ? "Success" : "Failed"));
239 #define tc_result(success, tc_index)
242 bluetooth_device_info_t bond_dev;
243 int is_bond_device = FALSE;
245 void tc_usage_print(void)
249 while (tc_table[i].tc_name) {
250 if (tc_table[i].tc_code != 0x00ff)
251 TC_PRT("Key %d : usage %s", tc_table[i].tc_code, tc_table[i].tc_name);
253 TC_PRT("Key %d : usage %s\n\n", 0x00ff, tc_table[i].tc_name);
259 int find_tc_number(int input)
263 while (tc_table[i].tc_code != 0x0000) {
264 if (tc_table[i].tc_code == input)
272 int test_input_callback(void *data)
278 test_id = find_tc_number((uintptr_t)data);
280 test_id = find_tc_number((int)data);
285 TC_PRT("TC : %s[%d]", tc_table[test_id].tc_name, tc_table[test_id].tc_code);
287 switch (tc_table[test_id].tc_code) {
290 g_main_loop_quit(main_loop);
294 ret = bluetooth_register_callback(bt_event_callback, NULL);
296 TC_PRT("%s failed with [0x%04x]", tc_table[0].tc_name, ret);
297 tc_result(TC_FAIL, 1);
302 ret = bluetooth_unregister_callback();
304 TC_PRT("%s failed with [0x%04x]", tc_table[1].tc_name, ret);
305 tc_result(TC_FAIL, 1);
310 ret = bluetooth_enable_adapter();
312 TC_PRT("%s failed with [0x%04x]", tc_table[2].tc_name, ret);
313 tc_result(TC_FAIL, 1);
318 ret = bluetooth_disable_adapter();
320 TC_PRT("%s failed with [0x%04x]", tc_table[3].tc_name, ret);
321 tc_result(TC_FAIL, 2);
327 ret = bluetooth_check_adapter();
328 TC_PRT("state: %d", ret);
334 bluetooth_device_address_t address = { {0} };
335 ret = bluetooth_get_local_address(&address);
337 TC_PRT("%s failed with [0x%04x]", tc_table[5].tc_name, ret);
339 TC_PRT("dev [%2.2X:%2.2X:%2.2X:%2.2X:%2.2X:%2.2X]", \
340 address.addr[0], address.addr[1], address.addr[2], \
341 address.addr[3], address.addr[4], address.addr[5]);
348 bluetooth_device_name_t local_name = { {0} };
349 ret = bluetooth_get_local_name(&local_name);
351 TC_PRT("%s failed with [0x%04x]", tc_table[6].tc_name, ret);
353 TC_PRT("name: %s", local_name.name);
360 bluetooth_device_name_t local_name = { {0} };
361 snprintf(local_name.name, sizeof(local_name.name),
362 "bt-frwk-pid-%d", getpid());
363 ret = bluetooth_set_local_name(&local_name);
365 TC_PRT("%s failed with [0x%04x]", tc_table[7].tc_name, ret);
372 bluetooth_version_t local_version = { {0} };
373 snprintf(local_version.version, sizeof(local_version.version),
374 "version%d", getpid());
375 ret = bluetooth_get_local_version(&local_version);
377 TC_PRT("%s failed with [0x%04x]", tc_table[89].tc_name, ret);
379 TC_PRT("version: %s", local_version.version);
385 gboolean used = FALSE;
386 ret = bluetooth_is_service_used(rfcomm_test_uuid_spp, &used);
388 TC_PRT("%s failed with [0x%04x]", tc_table[8].tc_name, ret);
390 TC_PRT("used: %d", used);
396 bluetooth_discoverable_mode_t mode;
397 ret = bluetooth_get_discoverable_mode(&mode);
399 TC_PRT("%s failed with [0x%04x]", tc_table[9].tc_name, ret);
401 TC_PRT("BT Get Discoverable mode [%d]", mode);
407 bluetooth_discoverable_mode_t mode = BLUETOOTH_DISCOVERABLE_MODE_CONNECTABLE;
408 ret = bluetooth_set_discoverable_mode(mode, 0);
410 TC_PRT("%s failed with [0x%04x]", tc_table[10].tc_name, ret);
412 TC_PRT("BT Set Discoverable mode [%d]", mode);
418 bluetooth_discoverable_mode_t mode = BLUETOOTH_DISCOVERABLE_MODE_GENERAL_DISCOVERABLE;
419 ret = bluetooth_set_discoverable_mode(mode, 0);
421 TC_PRT("%s failed with [0x%04x]", tc_table[11].tc_name, ret);
423 TC_PRT("BT Set Discoverable mode [%d]", mode);
429 bluetooth_discoverable_mode_t mode = BLUETOOTH_DISCOVERABLE_MODE_TIME_LIMITED_DISCOVERABLE;
430 ret = bluetooth_set_discoverable_mode(mode, 5);
432 TC_PRT("%s failed with [0x%04x]", tc_table[12].tc_name, ret);
434 TC_PRT("BT Set Discoverable mode [%d]", mode);
439 ret = bluetooth_start_discovery(0, 0, 0);
441 TC_PRT("%s failed with [0x%04x]", tc_table[13].tc_name, ret);
445 ret = bluetooth_cancel_discovery();
447 TC_PRT("%s failed with [0x%04x]", tc_table[14].tc_name, ret);
452 ret = bluetooth_is_discovering();
454 TC_PRT("%s failed with [0x%04x]", tc_table[15].tc_name, ret);
456 TC_PRT("Discovering [%d]", ret);
460 case 17: /*Get paired device list */
462 GPtrArray *devinfo = NULL;
463 devinfo = g_ptr_array_new();
464 TC_PRT("g pointer arrary count : [%d]", devinfo->len);
466 ret = bluetooth_get_bonded_device_list(&devinfo);
468 TC_PRT("%s failed with [0x%04x]", tc_table[16].tc_name, ret);
471 bluetooth_device_info_t *ptr;
472 TC_PRT("g pointer arrary count : [%d]", devinfo->len);
473 for (i = 0; i < devinfo->len; i++) {
474 ptr = g_ptr_array_index(devinfo, i);
476 TC_PRT("Name [%s]", ptr->device_name.name);
477 TC_PRT("Major Class [%d]", ptr->device_class.major_class);
478 TC_PRT("Minor Class [%d]", ptr->device_class.minor_class);
479 TC_PRT("Service Class [%d]", ptr->device_class.service_class);
480 TC_PRT("%2.2X:%2.2X:%2.2X:%2.2X:%2.2X:%2.2X", ptr->device_address.addr[0], ptr->device_address.addr[1], ptr->device_address.addr[2], ptr->device_address.addr[3], ptr->device_address.addr[4], ptr->device_address.addr[5]);
485 g_ptr_array_free(devinfo, TRUE);
492 bluetooth_device_address_t device_address = { {0xDC, 0x2C, 0x26, 0xD0, 0xF3, 0xC1} }; /* BT Keyboard */
493 TC_PRT("dev [%2.2X:%2.2X:%2.2X:%2.2X:%2.2X:%2.2X]", \
494 device_address.addr[0], device_address.addr[1], device_address.addr[2], \
495 device_address.addr[3], device_address.addr[4], device_address.addr[5]);
496 ret = bluetooth_bond_device(&device_address);
498 TC_PRT("%s failed with [0x%04x]", tc_table[17].tc_name, ret);
502 case 19: /*Cancel bonding */
504 ret = bluetooth_cancel_bonding();
506 TC_PRT("%s failed with [0x%04x]", tc_table[18].tc_name, ret);
510 case 20: /*unbonding */
512 bluetooth_device_address_t device_address = { {0x00, 0x19, 0x0E, 0x01, 0x61, 0x17} }; /* DO-DH79-PYUN04 */
513 ret = bluetooth_unbond_device(&device_address);
515 TC_PRT("%s failed with [0x%04x]", tc_table[19].tc_name, ret);
519 case 21: /*Get paired device */
521 bluetooth_device_info_t devinfo;
522 bluetooth_device_address_t device_address = { {0x00, 0x16, 0x38, 0xC3, 0x1F, 0xD2} };
523 memset(&devinfo, 0x00, sizeof(bluetooth_device_info_t));
524 ret = bluetooth_get_bonded_device(&device_address, &devinfo);
525 if (ret != BLUETOOTH_ERROR_NONE) {
526 TC_PRT("bluetooth_get_bonded_device failed with [%d]", ret);
528 TC_PRT("Name [%s]", devinfo.device_name.name);
529 TC_PRT("Major Class [%d]", devinfo.device_class.major_class);
530 TC_PRT("Minor Class [%d]", devinfo.device_class.minor_class);
531 TC_PRT("Service Class [%d]", devinfo.device_class.service_class);
532 TC_PRT("%2.2X:%2.2X:%2.2X:%2.2X:%2.2X:%2.2X", devinfo.device_address.addr[0], devinfo.device_address.addr[1], devinfo.device_address.addr[2], devinfo.device_address.addr[3], devinfo.device_address.addr[4], devinfo.device_address.addr[5]);
538 case 22: /*set alias for bonded device */
540 bluetooth_device_address_t device_address = { {0x00, 0x16, 0x38, 0xC3, 0x1F, 0xD2} };
542 ret = bluetooth_set_alias(&device_address, "Renamed device");
544 TC_PRT("%s failed with [0x%04x]", tc_table[21].tc_name, ret);
551 bluetooth_device_address_t device_address = { {0x00, 0x16, 0x38, 0xC3, 0x1F, 0xD2} };
552 ret = bluetooth_authorize_device(&device_address, TRUE);
554 TC_PRT("%s failed with [0x%04x]", tc_table[22].tc_name, ret);
561 bluetooth_device_address_t device_address = { {0x00, 0x16, 0x38, 0xC3, 0x1F, 0xD2} };
562 ret = bluetooth_authorize_device(&device_address, FALSE);
564 TC_PRT("%s failed with [0x%04x]", tc_table[23].tc_name, ret);
569 bluetooth_device_address_t device_address = { {0x00, 0x16, 0x38, 0xC3, 0x1F, 0xD2} };
571 ret = bluetooth_search_service(&device_address);
573 TC_PRT("%s failed with [0x%04x]", tc_table[24].tc_name, ret);
580 ret = bluetooth_cancel_service_search();
582 TC_PRT("%s failed with [0x%04x]", tc_table[24].tc_name, ret);
588 gboolean connected = FALSE;
589 bluetooth_device_address_t device_address = { {0x00, 0x1B, 0x66, 0x01, 0x23, 0x1C} }; /* Gennheiser PX210BT */
591 ret = bluetooth_is_device_connected(&device_address, BLUETOOTH_A2DP_SERVICE, &connected);
593 TC_PRT("%s failed with [0x%04x]", tc_table[24].tc_name, ret);
594 TC_PRT("connected : %d", connected);
602 ret = bluetooth_reset_adapter();
604 TC_PRT("%s failed with [0x%04x]", tc_table[27].tc_name, ret);
611 bluetooth_manufacturer_data_t m_data;
612 guint8 data[6] = {0x05, 0xFF, 0x02, 0x03, 0x04, 0x05};
613 TC_PRT("%x %x %x %x %x %x", data[0], data[1], data[2], data[3],
616 memcpy(m_data.data, data, sizeof(data));
617 m_data.data_len = sizeof(data) - 2;
618 ret = bluetooth_set_manufacturer_data(&m_data);
620 TC_PRT("%s failed with [0x%04x]", tc_table[90].tc_name, ret);
626 ret = bluetooth_audio_init(bt_audio_event_callback, NULL);
628 TC_PRT("%s failed with [0x%04x]", tc_table[28].tc_name, ret);
635 ret = bluetooth_audio_deinit();
637 TC_PRT("%s failed with [0x%04x]", tc_table[29].tc_name, ret);
644 bluetooth_device_address_t device_address = { {0x00, 0x0D, 0xFD, 0x24, 0x5E, 0xFF} }; /* Motorola S9 */
646 ret = bluetooth_audio_connect(&device_address);
648 TC_PRT("%s failed with [0x%04x]", tc_table[30].tc_name, ret);
655 bluetooth_device_address_t device_address = { {0x00, 0x0D, 0xFD, 0x24, 0x5E, 0xFF} }; /* Motorola S9 */
657 ret = bluetooth_audio_disconnect(&device_address);
659 TC_PRT("%s failed with [0x%04x]", tc_table[31].tc_name, ret);
666 bluetooth_device_address_t device_address = { {0x58, 0x17, 0x0C, 0xEC, 0x6A, 0xF3} };
668 ret = bluetooth_ag_connect(&device_address);
670 TC_PRT("%s failed with [0x%04x]", tc_table[32].tc_name, ret);
676 bluetooth_device_address_t device_address = { {0x58, 0x17, 0x0C, 0xEC, 0x6A, 0xF3} };
678 ret = bluetooth_ag_disconnect(&device_address);
680 TC_PRT("%s failed with [0x%04x]", tc_table[33].tc_name, ret);
687 bluetooth_device_address_t device_address = { {0x58, 0x17, 0x0C, 0xEC, 0x6A, 0xF3} };
689 ret = bluetooth_av_connect(&device_address);
691 TC_PRT("%s failed with [0x%04x]", tc_table[34].tc_name, ret);
698 bluetooth_device_address_t device_address = { {0x58, 0x17, 0x0C, 0xEC, 0x6A, 0xF3} };
700 ret = bluetooth_av_disconnect(&device_address);
702 TC_PRT("%s failed with [0x%04x]", tc_table[35].tc_name, ret);
709 unsigned int volume = 0;
711 ret = bluetooth_ag_get_headset_volume(&volume);
713 TC_PRT("failed with [0x%04x]", ret);
714 TC_PRT("volume: %d", volume);
722 ret = bluetooth_ag_set_speaker_gain(10);
724 TC_PRT("failed with [0x%04x]", ret);
731 if (bluetooth_oob_read_local_data(&g_local_oob_data.oob_data)) {
732 TC_PRT("ERROR in bluetooth_oob_read_local_data\n");
734 TC_PRT("SUCESS in bluetooth_oob_read_local_data\n");
735 TC_PRT("hash = [%2.2X:%2.2X:%2.2X:%2.2X:%2.2X:%2.2X:%2.2X:%2.2X"
736 "%2.2X:%2.2X:%2.2X:%2.2X:%2.2X:%2.2X:%2.2X:%2.2X]\n",
737 g_local_oob_data.oob_data.hash[0],
738 g_local_oob_data.oob_data.hash[1],
739 g_local_oob_data.oob_data.hash[2],
740 g_local_oob_data.oob_data.hash[3],
741 g_local_oob_data.oob_data.hash[4],
742 g_local_oob_data.oob_data.hash[5],
743 g_local_oob_data.oob_data.hash[6],
744 g_local_oob_data.oob_data.hash[7],
745 g_local_oob_data.oob_data.hash[8],
746 g_local_oob_data.oob_data.hash[9],
747 g_local_oob_data.oob_data.hash[10],
748 g_local_oob_data.oob_data.hash[11],
749 g_local_oob_data.oob_data.hash[12],
750 g_local_oob_data.oob_data.hash[13],
751 g_local_oob_data.oob_data.hash[14],
752 g_local_oob_data.oob_data.hash[15]);
754 TC_PRT("randomizer = [%2.2X:%2.2X:%2.2X:%2.2X:%2.2X:%2.2X:%2.2X:%2.2X"
755 "%2.2X:%2.2X:%2.2X:%2.2X:%2.2X:%2.2X:%2.2X:%2.2X]\n",
756 g_local_oob_data.oob_data.randomizer[0],
757 g_local_oob_data.oob_data.randomizer[1],
758 g_local_oob_data.oob_data.randomizer[2],
759 g_local_oob_data.oob_data.randomizer[3],
760 g_local_oob_data.oob_data.randomizer[4],
761 g_local_oob_data.oob_data.randomizer[5],
762 g_local_oob_data.oob_data.randomizer[6],
763 g_local_oob_data.oob_data.randomizer[7],
764 g_local_oob_data.oob_data.randomizer[8],
765 g_local_oob_data.oob_data.randomizer[9],
766 g_local_oob_data.oob_data.randomizer[10],
767 g_local_oob_data.oob_data.randomizer[11],
768 g_local_oob_data.oob_data.randomizer[12],
769 g_local_oob_data.oob_data.randomizer[13],
770 g_local_oob_data.oob_data.randomizer[14],
771 g_local_oob_data.oob_data.randomizer[15]);
773 TC_PRT("hash_len: %d\n", g_local_oob_data.oob_data.hash_len);
774 TC_PRT("randomizer_len: %d\n", g_local_oob_data.oob_data.randomizer_len);
782 ret = bluetooth_get_local_address(&g_local_oob_data.address);
783 TC_PRT("hash_len: %d\n", g_local_oob_data.oob_data.hash_len);
784 TC_PRT("randomizer_len: %d\n", g_local_oob_data.oob_data.randomizer_len);
786 if (bluetooth_oob_add_remote_data(&g_local_oob_data.address,
787 BLUETOOTH_BDADDR_BREDR,
788 &g_local_oob_data.oob_data))
789 TC_PRT("ERROR in bluetooth_oob_add_remote_data\n");
791 TC_PRT(" bluetooth_oob_add_remote_data SUCCESS\n");
798 if (bluetooth_oob_remove_remote_data(&g_local_oob_data.address))
799 TC_PRT("ERROR in bluetooth_oob_remove_remote_data\n");
801 TC_PRT(" bluetooth_oob_remove_remote_data SUCCESS\n");
807 bluetooth_opc_init();
813 bluetooth_opc_deinit();
819 bluetooth_device_address_t remote_address = { {0} };
822 remote_address.addr[0] = 0x00; remote_address.addr[1] = 0x02; remote_address.addr[2] = 0x70;
823 remote_address.addr[3] = 0x2B; remote_address.addr[4] = 0xD3; remote_address.addr[5] = 0xAF;
825 char *files[5] = {NULL};
827 files[0] = "/opt/media/Images/image1.jpg";
828 // files[1] = "/opt/media/Images/image2.jpg";
829 // files[2] = "/opt/media/Images/image3.jpg";
830 bluetooth_opc_push_files(&remote_address, files);
836 bluetooth_opc_cancel_push();
843 exist = bluetooth_opc_session_is_exist();
844 TC_PRT("exist: %d", exist);
850 bluetooth_network_activate_server();
856 bluetooth_network_deactivate_server();
862 bluetooth_device_address_t device_address = { {0x00, 0x02, 0xA2, 0x14, 0x40, 0x51} };
863 bluetooth_network_connect(&device_address, BLUETOOTH_NETWORK_NAP_ROLE, NULL);
869 bluetooth_device_address_t device_address = { {0x00, 0x02, 0xA2, 0x14, 0x40, 0x51} };
870 bluetooth_network_disconnect(&device_address);
876 bluetooth_obex_server_init("/opt/media/Downloads");
882 bluetooth_obex_server_deinit();
888 bluetooth_obex_server_init_without_agent("/opt/media/Downloads");
894 bluetooth_obex_server_deinit_without_agent();
900 bluetooth_obex_server_is_activated();
906 bluetooth_obex_server_accept_connection();
907 TC_PRT(" bluetooth_obex_server_accept_connection SUCCESS\n");
913 bluetooth_obex_server_reject_connection();
919 bluetooth_obex_server_accept_authorize("abc");
925 bluetooth_obex_server_reject_authorize();
931 bluetooth_obex_server_set_destination_path("/opt/media");
937 bluetooth_obex_server_set_root("/opt/media");
943 bluetooth_obex_server_cancel_transfer(0);
949 bluetooth_obex_server_cancel_all_transfers();
955 ret = bluetooth_hid_init(bt_hid_event_callback, NULL);
957 TC_PRT("Failed with [0x%04x]", ret);
964 ret = bluetooth_hid_deinit();
966 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);
985 /* Apple wireless keyboard */
986 hid_device_address_t device_address = { {0xE8, 0x06, 0x88, 0x3B, 0x18, 0xBA} };
988 ret = bluetooth_hid_disconnect(&device_address);
990 TC_PRT("Failed with [0x%04x]", ret);
997 bluetooth_device_address_t device_address = { {0x00, 0x02, 0x2F, 0x92, 0x7B, 0xF5} };
999 ret = bluetooth_rfcomm_connect(&device_address, rfcomm_test_uuid_spp);
1000 //ret = bluetooth_rfcomm_connect(&device_address, "1");
1003 TC_PRT("Failed with [0x%04x]", ret);
1010 ret = bluetooth_rfcomm_disconnect(-1);
1012 TC_PRT("Failed with [0x%04x]", ret);
1019 ret = bluetooth_rfcomm_disconnect(g_ret_client_fd1);
1021 TC_PRT("Failed with [0x%04x]", ret);
1028 const char rd_data[] = "123456789 12345";
1029 ret = bluetooth_rfcomm_write(g_ret_client_fd1, rd_data, sizeof(rd_data));
1031 TC_PRT("Failed with [0x%04x]", ret);
1038 gboolean is_connected;
1039 is_connected = bluetooth_rfcomm_is_client_connected();
1040 TC_PRT("Connected: %d", is_connected);
1047 ret = bluetooth_rfcomm_create_socket(rfcomm_test_uuid_spp);
1049 TC_PRT("Failed with [0x%04x]", ret);
1050 TC_PRT("Returned FD = %d", ret);
1059 ret = bluetooth_rfcomm_create_socket(rfcomm_test_uuid_custom);
1061 TC_PRT("Failed with [0x%04x]", ret);
1062 TC_PRT("Returned FD = %d", ret);
1071 ret = bluetooth_rfcomm_remove_socket(server_fd);
1073 TC_PRT("Failed with [0x%04x]", ret);
1078 case 83: /*Listen and accept */
1080 ret = bluetooth_rfcomm_listen_and_accept(server_fd, 1);
1082 TC_PRT("Failed with [0x%04x]", ret);
1083 TC_PRT("result = %d", ret);
1089 case 84: /*Listen */
1091 ret = bluetooth_rfcomm_listen(server_fd, 1);
1093 TC_PRT("Failed with [0x%04x]", ret);
1094 TC_PRT("result = %d", ret);
1102 ret = bluetooth_rfcomm_server_disconnect(client_fd);
1104 TC_PRT("Failed with [0x%04x]", ret);
1112 available = bluetooth_rfcomm_is_server_uuid_available(rfcomm_test_uuid_spp);
1113 TC_PRT("available: %d", available);
1120 ret = bluetooth_rfcomm_accept_connection(server_fd);
1122 TC_PRT("Failed with [0x%04x]", ret);
1123 TC_PRT("client fd: %d", client_fd);
1131 ret = bluetooth_rfcomm_reject_connection(server_fd);
1133 TC_PRT("Failed with [0x%04x]", ret);
1138 ret = bluetooth_start_custom_discovery(DISCOVERY_ROLE_LE,
1141 TC_PRT("failed with [0x%04x]", ret);
1148 ret = bluetooth_gatt_init();
1150 TC_PRT("gatt init failed with [0x%04x]", ret);
1158 ret = bluetooth_gatt_deinit();
1160 TC_PRT("gatt deinit failed with [0x%04x]", ret);
1168 char *service_uuid = g_strdup("00001802-0000-1000-8000-00805f9b34fb");
1170 ret = bluetooth_gatt_add_service(service_uuid,
1173 TC_PRT("service obj_path is %s", svc_obj_path);
1181 /* testing with dummy values*/
1182 char *char_uuid = g_strdup("00002a06-0000-1000-8000-00805f9b34fb");
1183 bt_gatt_permission_t perms = 0;
1184 bt_gatt_characteristic_property_t props = BLUETOOTH_GATT_CHARACTERISTIC_PROPERTY_READ |
1185 BLUETOOTH_GATT_CHARACTERISTIC_PROPERTY_WRITE |
1186 BLUETOOTH_GATT_CHARACTERISTIC_PROPERTY_NOTIFY |
1187 BLUETOOTH_GATT_CHARACTERISTIC_PROPERTY_INDICATE;
1189 ret = bluetooth_gatt_add_new_characteristic(
1190 svc_obj_path, char_uuid,
1191 perms, props, &char_obj_path);
1193 TC_PRT("characteristic obj_path is %s", char_obj_path);
1200 char *desc_uuid = g_strdup("000026ff-0000-1000-8000-00805f9b34fb");
1201 bt_gatt_permission_t perms = BLUETOOTH_GATT_PERMISSION_READ |
1202 BLUETOOTH_GATT_PERMISSION_WRITE;
1204 ret = bluetooth_gatt_add_descriptor(char_obj_path,
1205 desc_uuid, perms, &desc_obj_path);
1206 TC_PRT("add descriptor error is %d", ret);
1213 ret = bluetooth_gatt_register_service(svc_obj_path);
1214 TC_PRT("register service error is %d", ret);
1221 ret = bluetooth_gatt_register_application();
1223 TC_PRT("register service error is %d", ret);
1230 char char_data[4] = {10, 20, 30, 40};
1231 int char_length = 4;
1232 ret = bluetooth_gatt_update_characteristic(char_obj_path,
1233 char_data, char_length);
1235 TC_PRT("update_characteristic error is %d", ret);
1242 ret = bluetooth_gatt_unregister_service(svc_obj_path);
1243 TC_PRT("service removed with error is %d", ret);
1250 ret = bluetooth_gatt_delete_services();
1251 TC_PRT("services deleted with error is %d", ret);
1263 TC_PRT("bluetooth framework TC startup");
1265 main_loop = g_main_loop_new(NULL, FALSE);
1270 TC_PRT("bluetooth framework TC cleanup");
1271 if (main_loop != NULL)
1272 g_main_loop_unref(main_loop);
1275 void bt_hid_event_callback(int event, hid_event_param_t* param, void *user_data)
1277 TC_PRT(">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>");
1278 TC_PRT("bt event callback 0x%04x", event);
1281 void bt_audio_event_callback(int event, bt_audio_event_param_t* param, void *user_data)
1283 TC_PRT(">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>");
1284 TC_PRT("bt event callback 0x%04x", event);
1290 void bt_event_callback(int event, bluetooth_event_param_t* param, void *user_data)
1292 TC_PRT(">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>");
1293 TC_PRT("bt event callback 0x%04x", event);
1295 case BLUETOOTH_EVENT_ENABLED:
1296 TC_PRT("BLUETOOTH_EVENT_ENABLED, result [0x%04x]", param->result);
1299 case BLUETOOTH_EVENT_DISABLED:
1300 TC_PRT("BLUETOOTH_EVENT_DISABLED, result [0x%04x]", param->result);
1303 case BLUETOOTH_EVENT_LOCAL_NAME_CHANGED:
1304 TC_PRT("BLUETOOTH_EVENT_LOCAL_NAME_CHANGED, result [0x%04x]", param->result);
1305 if (param->result == BLUETOOTH_ERROR_NONE) {
1306 bluetooth_device_name_t *local_name = (bluetooth_device_name_t *)param->param_data;
1307 tc_result(TC_PASS, 6);
1308 TC_PRT("Changed Name : [%s]", local_name->name);
1310 tc_result(TC_FAIL, 6);
1314 case BLUETOOTH_EVENT_DISCOVERY_STARTED:
1315 TC_PRT("BLUETOOTH_EVENT_DISCOVERY_STARTED, result [0x%04x]", param->result);
1318 case BLUETOOTH_EVENT_REMOTE_DEVICE_FOUND:
1320 bluetooth_device_info_t *device_info = NULL;
1321 TC_PRT("BLUETOOTH_EVENT_REMOTE_DEVICE_FOUND, result [0x%04x]", param->result);
1322 device_info = (bluetooth_device_info_t *)param->param_data;
1323 memcpy(&searched_device, &device_info->device_address, sizeof(bluetooth_device_address_t));
1324 TC_PRT("dev [%2.2X:%2.2X:%2.2X:%2.2X:%2.2X:%2.2X]", \
1325 device_info->device_address.addr[0], device_info->device_address.addr[1], device_info->device_address.addr[2], \
1326 device_info->device_address.addr[3], device_info->device_address.addr[4], device_info->device_address.addr[5]);
1330 case BLUETOOTH_EVENT_REMOTE_LE_DEVICE_FOUND:
1333 bluetooth_le_device_info_t *le_device_info = NULL;
1334 TC_PRT("BLUETOOTH_EVENT_REMOTE_LE_DEVICE_FOUND, result [0x%04x]", param->result);
1335 le_device_info = (bluetooth_le_device_info_t *)param->param_data;
1336 TC_PRT("dev[%2.2X:%2.2X:%2.2X:%2.2X:%2.2X:%2.2X]", \
1337 le_device_info->device_address.addr[0], le_device_info->device_address.addr[1], le_device_info->device_address.addr[2], \
1338 le_device_info->device_address.addr[3], le_device_info->device_address.addr[4], le_device_info->device_address.addr[5]);
1339 TC_PRT("addr_type : %d", le_device_info->addr_type);
1340 TC_PRT("rssi : %d", le_device_info->rssi);
1341 TC_PRT("adv_ind_data_len :%d" , le_device_info->adv_ind_data.data_len);
1342 TC_PRT("scan_resp_data_len :%d" , le_device_info->scan_resp_data.data_len);
1343 for (i = 0; i < le_device_info->adv_ind_data.data_len; i++)
1344 TC_PRT("adv_ind_data[%d] : [0x%x]", i, le_device_info->adv_ind_data.data.data[i]);
1345 for (i = 0; i < le_device_info->scan_resp_data.data_len; i++)
1346 TC_PRT("scan_resp_data[%d] : [0x%x]", i, le_device_info->scan_resp_data.data.data[i]);
1350 case BLUETOOTH_EVENT_REMOTE_DEVICE_NAME_UPDATED:
1352 bluetooth_device_info_t *device_info = NULL;
1353 TC_PRT("BLUETOOTH_EVENT_REMOTE_DEVICE_NAME_UPDATED, result [0x%04x]", param->result);
1354 device_info = (bluetooth_device_info_t *)param->param_data;
1355 memcpy(&searched_device, &device_info->device_address, sizeof(bluetooth_device_address_t));
1356 TC_PRT("dev [%s] [%2.2X:%2.2X:%2.2X:%2.2X:%2.2X:%2.2X]", device_info->device_name.name, \
1357 device_info->device_address.addr[0], device_info->device_address.addr[1], device_info->device_address.addr[2], \
1358 device_info->device_address.addr[3], device_info->device_address.addr[4], device_info->device_address.addr[5]);
1362 case BLUETOOTH_EVENT_DISCOVERY_FINISHED:
1363 TC_PRT("BLUETOOTH_EVENT_DISCOVERY_FINISHED, result [0x%04x]", param->result);
1366 case BLUETOOTH_EVENT_DISCOVERABLE_MODE_CHANGED:
1368 int *mode = (int *)param->param_data;
1369 TC_PRT("BT_DISCOVERABLE_MODE_CHANGED, result [0x%04x]", param->result);
1370 TC_PRT("mode [%d]", *mode);
1374 case BLUETOOTH_EVENT_DISCOVERABLE_TIMEOUT_CHANGED:
1376 int *timeout = (int *)param->param_data;
1377 TC_PRT("BLUETOOTH_EVENT_DISCOVERABLE_TIMEOUT_CHANGED, result [0x%04x]", param->result);
1378 TC_PRT("timeout [%d]", *timeout);
1382 case BLUETOOTH_EVENT_BONDING_FINISHED:
1384 TC_PRT("BLUETOOTH_EVENT_BONDING_FINISHED, result [0x%04x]", param->result);
1385 if (param->result >= BLUETOOTH_ERROR_NONE) {
1386 bluetooth_device_info_t *device_info = NULL;
1387 tc_result(TC_PASS, 12);
1388 device_info = (bluetooth_device_info_t *)param->param_data;
1389 if (device_info == NULL)
1391 TC_PRT("dev [%s] [%2.2X:%2.2X:%2.2X:%2.2X:%2.2X:%2.2X] mjr[%#x] min[%#x] srv[%#x]", device_info->device_name.name, \
1392 device_info->device_address.addr[0], device_info->device_address.addr[1], device_info->device_address.addr[2], \
1393 device_info->device_address.addr[3], device_info->device_address.addr[4], device_info->device_address.addr[5], \
1394 device_info->device_class.major_class, device_info->device_class.minor_class, device_info->device_class.service_class);
1396 tc_result(TC_FAIL, 12);
1401 case BLUETOOTH_EVENT_BONDED_DEVICE_FOUND:
1403 // bluetooth_get_bonded_device_list is changed as synchronous API. This event is not used any more.
1407 TC_PRT("BLUETOOTH_EVENT_BONDED_DEVICE_FOUND, result [0x%04x]", param->result);
1408 if (param->result >= BLUETOOTH_ERROR_NONE) {
1409 ///tc_result(TC_PASS, 15);
1410 bluetooth_device_info_t * bt_dev_info = (bluetooth_device_info_t*)param->param_data;
1411 TC_PRT("Dev Name = %s, Dev add = %2.2X:%2.2X:%2.2X:%2.2X:%2.2X:%2.2X, COD (major,minor,service)= 0x%x:%x:%x\n", bt_dev_info->device_name.name,
1412 bt_dev_info->device_address.addr[0], bt_dev_info->device_address.addr[1], bt_dev_info->device_address.addr[2], \
1413 bt_dev_info->device_address.addr[3], bt_dev_info->device_address.addr[4], bt_dev_info->device_address.addr[5], \
1414 bt_dev_info->device_class.major_class, bt_dev_info->device_class.minor_class, bt_dev_info->device_class.service_class);
1416 } else if (param->result == BLUETOOTH_ERROR_END_OF_DEVICE_LIST) /*End of the Device found indication*/ {
1417 tc_result(TC_PASS, 15);
1418 TC_PRT("*****<<No more BLUETOOTH_EVENT_BONDED_DEVICE_FOUND indication>>***** ");
1420 tc_result(TC_FAIL, 15);
1421 TC_PRT("*****API failed ***** ");
1427 case BLUETOOTH_EVENT_SERVICE_SEARCHED:
1430 TC_PRT("BLUETOOTH_EVENT_SERVICE_SEARCHED, result [0x%04x]", param->result);
1431 if (param->result >= BLUETOOTH_ERROR_NONE) {
1432 tc_result(TC_PASS, 18);
1433 bt_sdp_info_t *bt_sdp_info = param->param_data;
1435 TC_PRT("Dev add = %2.2X:%2.2X:%2.2X:%2.2X:%2.2X:%2.2X\n",
1436 bt_sdp_info->device_addr.addr[0], bt_sdp_info->device_addr.addr[1], bt_sdp_info->device_addr.addr[2], \
1437 bt_sdp_info->device_addr.addr[3], bt_sdp_info->device_addr.addr[4], bt_sdp_info->device_addr.addr[5]);
1439 TC_PRT("Supported service list:\n");
1440 for (i = 0; i < bt_sdp_info->service_index; i++)
1441 TC_PRT("[%#x]\n", bt_sdp_info->service_list_array[i]);
1444 tc_result(TC_FAIL, 18);
1449 case BLUETOOTH_EVENT_RFCOMM_DATA_RECEIVED:
1451 TC_PRT("BLUETOOTH_EVENT_RFCOMM_DATA_RECEIVED, result [0x%04x]", param->result);
1452 bluetooth_rfcomm_received_data_t *rx_data = param->param_data;
1453 printf("\n FD = %d \nBuffer len = %d ", rx_data->socket_fd, rx_data->buffer_size);
1454 if (rx_data->buffer_size < sizeof(oob_data_t))
1455 TC_PRT("Complete oob data is not recivedn");
1457 memcpy(&g_remote_oob_data, rx_data->buffer, sizeof(oob_data_t));
1458 //tc_result(TC_PASS, 21);
1462 case BLUETOOTH_EVENT_RFCOMM_CONNECTED:
1464 bluetooth_rfcomm_connection_t *con_ind = (bluetooth_rfcomm_connection_t *)param->param_data;
1465 TC_PRT("BLUETOOTH_EVENT_RFCOMM_CONNECTED, result [0x%04x], fd = %d, device add = 0x%X:%X:%X:%X:%X:%X, Role = %s", param->result,
1467 con_ind->device_addr.addr[0], con_ind->device_addr.addr[1], con_ind->device_addr.addr[2],
1468 con_ind->device_addr.addr[3], con_ind->device_addr.addr[4], con_ind->device_addr.addr[5],
1469 (con_ind->device_role == RFCOMM_ROLE_SERVER) ? "SERVER" : "CLIENT");
1470 //tc_result(TC_PASS, 22);
1471 if ((con_ind->device_role == RFCOMM_ROLE_CLIENT) && (con_ind->socket_fd > 0))
1472 g_ret_client_fd1 = con_ind->socket_fd;
1474 if ((con_ind->device_role == RFCOMM_ROLE_SERVER) && (con_ind->socket_fd > 0))
1475 client_fd = con_ind->socket_fd;
1480 case BLUETOOTH_EVENT_RFCOMM_DISCONNECTED:
1482 bluetooth_rfcomm_disconnection_t *disconnection_ind = (bluetooth_rfcomm_disconnection_t *)param->param_data;;
1483 TC_PRT("BLUETOOTH_EVENT_RFCOMM_DISCONNECTED, result [0x%04x] Fd = %d, device add = 0x%X:%X:%X:%X:%X:%X\n", param->result, disconnection_ind->socket_fd,
1484 disconnection_ind->device_addr.addr[0], disconnection_ind->device_addr.addr[1], disconnection_ind->device_addr.addr[2],
1485 disconnection_ind->device_addr.addr[3], disconnection_ind->device_addr.addr[4], disconnection_ind->device_addr.addr[5]);
1486 //tc_result(TC_PASS, 22);
1490 case BLUETOOTH_EVENT_NETWORK_SERVER_CONNECTED:
1492 bluetooth_network_device_info_t *dev_info = (bluetooth_network_device_info_t *)param->param_data;
1494 TC_PRT("BLUETOOTH_EVENT_RFCOMM_DISCONNECTED, result [0x%04x]", param->result);
1495 TC_PRT("interface name: %s", dev_info->interface_name);
1497 TC_PRT("device add = %2.2X:%2.2X:%2.2X:%2.2X:%2.2X:%2.2X\n",
1498 dev_info->device_address.addr[0], dev_info->device_address.addr[1], dev_info->device_address.addr[2],
1499 dev_info->device_address.addr[3], dev_info->device_address.addr[4], dev_info->device_address.addr[5]);
1503 case BLUETOOTH_EVENT_NETWORK_SERVER_DISCONNECTED:
1505 bluetooth_network_device_info_t *dev_info = (bluetooth_network_device_info_t *)param->param_data;
1507 TC_PRT("BLUETOOTH_EVENT_RFCOMM_DISCONNECTED, result [0x%04x]", param->result);
1508 TC_PRT("interface name: %s", dev_info->interface_name);
1510 TC_PRT("device add = %2.2X:%2.2X:%2.2X:%2.2X:%2.2X:%2.2X\n",
1511 dev_info->device_address.addr[0], dev_info->device_address.addr[1], dev_info->device_address.addr[2],
1512 dev_info->device_address.addr[3], dev_info->device_address.addr[4], dev_info->device_address.addr[5]);
1516 case BLUETOOTH_EVENT_HDP_CONNECTED:
1518 bt_hdp_connected_t *conn_ind = (bt_hdp_connected_t *)param->param_data;
1520 TC_PRT("BLUETOOTH_EVENT_HDP_CONNECTED, Result = %s\n", (param->result == 0) ? "BLUETOOTH_ERROR_NONE" : "BLUETOOTH_ERROR_XXXX");
1521 TC_PRT("App handler = %s, channel id = %d, type = %s", conn_ind->app_handle, conn_ind->channel_id, (conn_ind->type == HDP_QOS_RELIABLE) ? "Reliable" : "Streaming");
1522 TC_PRT("device add = %2.2X:%2.2X:%2.2X:%2.2X:%2.2X:%2.2X\n",
1523 conn_ind->device_address.addr[0], conn_ind->device_address.addr[1], conn_ind->device_address.addr[2],
1524 conn_ind->device_address.addr[3], conn_ind->device_address.addr[4], conn_ind->device_address.addr[5]);
1526 g_ret_client_fd1 = conn_ind->channel_id;
1530 case BLUETOOTH_EVENT_HDP_DISCONNECTED:
1532 bt_hdp_disconnected_t *dis_ind = (bt_hdp_disconnected_t *)param->param_data;
1534 TC_PRT("BLUETOOTH_EVENT_HDP_DISCONNECTED, Result = %s\n", (param->result == 0) ? "BLUETOOTH_ERROR_NONE" : "BLUETOOTH_ERROR_XXXX");
1535 TC_PRT("Channel = %d, Add = device add = %2.2X:%2.2X:%2.2X:%2.2X:%2.2X:%2.2X\n", dis_ind->channel_id,
1536 dis_ind->device_address.addr[0], dis_ind->device_address.addr[1], dis_ind->device_address.addr[2],
1537 dis_ind->device_address.addr[3], dis_ind->device_address.addr[4], dis_ind->device_address.addr[5]);
1541 case BLUETOOTH_EVENT_HDP_DATA_RECEIVED:
1543 bt_hdp_data_ind_t *data_ind = (bt_hdp_data_ind_t *)param->param_data;
1545 TC_PRT("BLUETOOTH_EVENT_HDP_DATA_RECEIVED, Result = %s\n", (param->result == 0) ? "BLUETOOTH_ERROR_NONE" : "BLUETOOTH_ERROR_XXXX");
1546 TC_PRT("Data received from channel id = %d and size =%d, buff =[%s]\n", data_ind->channel_id, data_ind->size, data_ind->buffer);
1551 case BLUETOOTH_EVENT_OPC_CONNECTED:
1552 TC_PRT("BLUETOOTH_EVENT_OPC_CONNECTED");
1555 case BLUETOOTH_EVENT_OPC_DISCONNECTED:
1556 TC_PRT("BLUETOOTH_EVENT_OPC_DISCONNECTED");
1558 case BLUETOOTH_EVENT_OPC_TRANSFER_STARTED:
1560 TC_PRT("BLUETOOTH_EVENT_OPC_TRANSFER_STARTED");
1561 if (param->param_data) {
1562 bt_opc_transfer_info_t *info = param->param_data;
1563 TC_PRT("file %s", info->filename);
1564 TC_PRT("size %ld", info->size);
1568 case BLUETOOTH_EVENT_OPC_TRANSFER_PROGRESS:
1570 TC_PRT("BLUETOOTH_EVENT_OPC_TRANSFER_PROGRESS");
1573 case BLUETOOTH_EVENT_OPC_TRANSFER_COMPLETE:
1575 TC_PRT("BLUETOOTH_EVENT_OPC_TRANSFER_COMPLETE");
1576 bt_opc_transfer_info_t *info = param->param_data;
1577 TC_PRT("file %s", info->filename);
1578 TC_PRT("size %ld", info->size);
1582 case BLUETOOTH_EVENT_OBEX_SERVER_TRANSFER_AUTHORIZE:
1583 TC_PRT("BLUETOOTH_EVENT_OBEX_SERVER_TRANSFER_AUTHORIZE");
1586 case BLUETOOTH_EVENT_OBEX_SERVER_CONNECTION_AUTHORIZE:
1587 TC_PRT("BLUETOOTH_EVENT_OBEX_SERVER_CONNECTION_AUTHORIZE");
1590 case BLUETOOTH_EVENT_OBEX_SERVER_TRANSFER_STARTED:
1591 TC_PRT("BLUETOOTH_EVENT_OBEX_SERVER_TRANSFER_STARTED");
1592 bt_obex_server_transfer_info_t *info = param->param_data;
1593 current_transfer_id = info->transfer_id;
1596 case BLUETOOTH_EVENT_OBEX_SERVER_TRANSFER_PROGRESS:
1597 TC_PRT("BLUETOOTH_EVENT_OBEX_SERVER_TRANSFER_PROGRESS");
1600 case BLUETOOTH_EVENT_OBEX_SERVER_TRANSFER_COMPLETED:
1601 TC_PRT("BLUETOOTH_EVENT_OBEX_SERVER_TRANSFER_COMPLETED");
1603 case BLUETOOTH_EVENT_MANUFACTURER_DATA_CHANGED:
1604 { TC_PRT("BLUETOOTH_EVENT_MANUFACTURER_DATA_CHANGED");
1608 case BLUETOOTH_EVENT_GATT_PRIM_SVC_DISCOVERED:
1610 TC_PRT("BLUETOOTH_EVENT_GATT_PRIM_SVC_DISCOVERED");
1611 bt_gatt_handle_info_t *prim_svc = param->param_data;
1614 if (prim_svc == NULL) {
1615 TC_PRT("prim_svc is NULL");
1619 for (i = 0; i < prim_svc->count; i++)
1620 TC_PRT("prim_svc[%d] = %s\n", i, prim_svc->handle[i]);
1625 case BLUETOOTH_EVENT_GATT_SVC_CHAR_DISCOVERED:
1627 TC_PRT("BLUETOOTH_EVENT_GATT_SVC_CHAR_DISCOVERED");
1628 bt_gatt_discovered_char_t *svc_char = param->param_data;
1631 if (svc_char == NULL) {
1632 TC_PRT("svc_char is NULL");
1636 if (svc_char->service_handle != NULL)
1637 TC_PRT("svc_char->service_handle %s \n", svc_char->service_handle);
1639 for (i = 0; i < svc_char->handle_info.count; i++)
1640 TC_PRT("svc_char.handle_info.handle[%d] = %s\n", i, svc_char->handle_info.handle[i]);
1645 case BLUETOOTH_EVENT_GATT_SVC_PROP_RECEIVED:
1647 TC_PRT("BLUETOOTH_EVENT_GATT_SVC_PROP_RECEIVED");
1648 bt_gatt_service_property_t *svc_pty = param->param_data;
1651 if (svc_pty == NULL) {
1652 TC_PRT("char_pty is NULL \n");
1656 if (svc_pty->service_handle != NULL)
1657 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);
1662 for (i = 0; i < svc_pty->handle_info.count; i++)
1663 TC_PRT("svc_char[%d] = %s\n", i, svc_pty->handle_info.handle[i]);
1668 case BLUETOOTH_EVENT_GATT_CHAR_PROP_RECEIVED:
1670 TC_PRT("BLUETOOTH_EVENT_GATT_CHAR_PROP_RECEIVED");
1671 bt_gatt_char_property_t *char_pty = param->param_data;
1674 if (char_pty->char_handle != NULL)
1675 TC_PRT("char_pty->char_handle %s \n", char_pty->char_handle);
1677 if (char_pty->uuid != NULL)
1678 TC_PRT("char_pty->uuid %s \n", char_pty->uuid);
1680 if (char_pty == NULL) {
1681 TC_PRT("char_pty is NULL \n");
1685 if (char_pty->name != NULL)
1686 TC_PRT("char_pty->name %s \n", char_pty->name);
1688 if (char_pty->description != NULL)
1689 TC_PRT("char_pty->description %s \n", char_pty->description);
1691 if (char_pty->val != NULL) {
1692 TC_PRT("char_pty->val_len %d \n", char_pty->val_len);
1694 for (i = 0; i < char_pty->val_len; i++)
1695 TC_PRT("char_pty->val %02x \n", char_pty->val[i]);
1701 case BLUETOOTH_EVENT_KEYBOARD_PASSKEY_DISPLAY:
1703 bluetooth_authentication_request_info_t *auth_info = param->param_data;
1705 TC_PRT("BLUETOOTH_EVENT_KEYBOARD_PASSKEY_DISPLAY");
1706 TC_PRT("Device Address: [%2.2X:%2.2X:%2.2X:%2.2X:%2.2X:%2.2X]",
1707 auth_info->device_address.addr[0], auth_info->device_address.addr[1],
1708 auth_info->device_address.addr[2], auth_info->device_address.addr[3],
1709 auth_info->device_address.addr[4], auth_info->device_address.addr[5]);
1710 TC_PRT("Device Name : [%s]", auth_info->device_name.name);
1711 TC_PRT("Passkey: [%s]", auth_info->str_passkey);
1714 case BLUETOOTH_EVENT_PIN_REQUEST:
1716 bluetooth_authentication_request_info_t *auth_info = param->param_data;
1718 TC_PRT("BLUETOOTH_EVENT_PIN_REQUEST");
1719 TC_PRT("Device Address: [%2.2X:%2.2X:%2.2X:%2.2X:%2.2X:%2.2X]",
1720 auth_info->device_address.addr[0], auth_info->device_address.addr[1],
1721 auth_info->device_address.addr[2], auth_info->device_address.addr[3],
1722 auth_info->device_address.addr[4], auth_info->device_address.addr[5]);
1723 TC_PRT("Device Name : [%s]", auth_info->device_name.name);
1725 TC_PRT("bluetooth_passkey_reply(\"0000\", TRUE)");
1726 bluetooth_passkey_reply("0000", TRUE);
1729 case BLUETOOTH_EVENT_PASSKEY_REQUEST:
1731 bluetooth_authentication_request_info_t *auth_info = param->param_data;
1733 TC_PRT("BLUETOOTH_EVENT_PASSKEY_REQUEST");
1734 TC_PRT("Device Address: [%2.2X:%2.2X:%2.2X:%2.2X:%2.2X:%2.2X]",
1735 auth_info->device_address.addr[0], auth_info->device_address.addr[1],
1736 auth_info->device_address.addr[2], auth_info->device_address.addr[3],
1737 auth_info->device_address.addr[4], auth_info->device_address.addr[5]);
1738 TC_PRT("Device Name : [%s]", auth_info->device_name.name);
1740 TC_PRT("bluetooth_passkey_reply(\"0000\", TRUE)");
1741 bluetooth_passkey_reply("0000", TRUE);
1744 case BLUETOOTH_EVENT_PASSKEY_CONFIRM_REQUEST:
1746 bluetooth_authentication_request_info_t *auth_info = param->param_data;
1748 TC_PRT("BLUETOOTH_EVENT_PASSKEY_CONFIRM_REQUEST");
1749 TC_PRT("Device Address: [%2.2X:%2.2X:%2.2X:%2.2X:%2.2X:%2.2X]",
1750 auth_info->device_address.addr[0], auth_info->device_address.addr[1],
1751 auth_info->device_address.addr[2], auth_info->device_address.addr[3],
1752 auth_info->device_address.addr[4], auth_info->device_address.addr[5]);
1753 TC_PRT("Device Name : [%s]", auth_info->device_name.name);
1754 TC_PRT("Passkey: [%s]", auth_info->str_passkey);
1756 TC_PRT("bluetooth_passkey_confirmation_reply: TRUE");
1757 bluetooth_passkey_confirmation_reply(TRUE);
1761 TC_PRT("received event [0x%04x]", event);
1764 TC_PRT("<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<");
1767 static gboolean key_event_cb(GIOChannel * chan, GIOCondition cond , gpointer data)
1772 unsigned long len = 0;
1774 unsigned int len = 0;
1777 memset(buf, 0, sizeof(buf));
1779 if (g_io_channel_read_chars(chan, buf, sizeof(buf),
1780 &len, NULL) == G_IO_STATUS_ERROR) {
1781 TC_PRT("IO Channel read error");
1785 printf("%s\n", buf);
1788 test_id = atoi(buf);
1791 g_idle_add(test_input_callback, (void *)(uintptr_t)test_id);
1793 g_idle_add(test_input_callback, (void *)test_id);
1804 key_io = g_io_channel_unix_new(fileno(stdin));
1806 g_io_channel_set_encoding(key_io, NULL, NULL);
1807 g_io_channel_set_flags(key_io, G_IO_FLAG_NONBLOCK, NULL);
1809 g_io_add_watch(key_io, G_IO_IN | G_IO_HUP | G_IO_ERR | G_IO_NVAL,
1810 key_event_cb, NULL);
1811 g_io_channel_unref(key_io);
1813 g_main_loop_run(main_loop);