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-telephony-test.c
26 * @brief This is the source file for bluetooth telephony test suite.
32 #include <dbus/dbus-glib.h>
35 #include "bluetooth-audio-api.h"
36 #include "bluetooth-api.h"
38 #define PRT(format, args...) printf("%s:%d() "format, \
39 __FUNCTION__, __LINE__, ##args)
40 #define TC_PRT(format, args...) PRT(format"\n", ##args)
42 GMainLoop *main_loop = NULL;
43 static int timeout_status = 0;
44 #define DEFAULT_CALL_ID 1
45 /*Change this number with Testing SIM*/
46 #define TEST_NUMBER "9980785507"
47 #define BLUETOOTH_HF_SPEAKER_GAIN 2
54 tc_table_t tc_table[] = {
56 {"bluetooth_hf_init", 1},
57 {"bluetooth_hf_deinit", 2},
59 {"Terminate Call", 4},
61 {"Last number Redial ", 6},
62 {"(PTS) Connect last bonded device", 7},
64 {"(PTS) Voice Recognition Enable", 9},
65 {"Voice RecognitionDisable", 10},
66 {"SCO disconnect", 11},
68 {"Dual Tone mulitple frequency", 13},
69 {"Send AT+XSAT=appid command", 14},
70 {"Release All Call(CHLD=0)", 15},
71 {"Release and Accept(CHLD=1)", 16},
72 {"Swap call (CHLD=2)", 17},
73 {"Join Call (CHLD=3)", 18},
74 {"(PTS) Initiate Codec based SCO", 19},
75 {"(PTS) Unbond all devices", 20},
76 {"Get Current Codec", 21},
77 {"Get Call List", 22},
78 {"Get Audio Connected Status", 23},
79 {"Is Handsfree Connected?", 24},
81 /* -----------------------------------------*/
87 #define tc_result(success, tc_index) \
88 TC_PRT("Test case [%d - %s] %s", tc_table[tc_index].tc_code, \
89 tc_table[tc_index].tc_name, \
90 ((success == TC_PASS) ? "Success" : "Failed"));
92 void tc_usage_print(void)
96 while (tc_table[i].tc_name) {
97 if (tc_table[i].tc_code != 0x00ff) {
98 TC_PRT("Key %d : usage %s", tc_table[i].tc_code,
101 TC_PRT("Key %d : usage %s\n\n", 0x00ff,
102 tc_table[i].tc_name);
108 void bt_event_callback(int event, bluetooth_event_param_t *param, void *user_data)
110 GMainLoop *main_loop = (GMainLoop*) user_data;
114 // Code for each event
120 void hf_event_handler(int event, void *data, void *user_data)
122 bt_hf_event_param_t *hf_event;
128 TC_PRT("HF event : [0x%04x]", event);
131 case BLUETOOTH_EVENT_HF_CONNECTED:
132 TC_PRT("BLUETOOTH_EVENT_HF_CONNECTED");
135 case BLUETOOTH_EVENT_HF_DISCONNECTED:
136 TC_PRT("BLUETOOTH_EVENT_HF_DISCONNECTED");
139 case BLUETOOTH_EVENT_HF_AUDIO_CONNECTED:
140 TC_PRT("BLUETOOTH_EVENT_HF_AUDIO_CONNECTED");
143 case BLUETOOTH_EVENT_HF_AUDIO_DISCONNECTED:
144 TC_PRT("BLUETOOTH_EVENT_HF_AUDIO_DISCONNECTED");
147 case BLUETOOTH_EVENT_HF_RING_INDICATOR:
148 TC_PRT("BLUETOOTH_EVENT_HF_RING_INDICATOR");
149 if (hf_event->param_data)
150 TC_PRT("Phone number %s", hf_event->param_data);
153 case BLUETOOTH_EVENT_HF_CALL_WAITING:
154 TC_PRT("BLUETOOTH_EVENT_HF_CALL_WAITING");
155 if (hf_event->param_data)
156 TC_PRT("Waiting Phone number %s", hf_event->param_data);
159 case BLUETOOTH_EVENT_HF_CALL_TERMINATED:
160 TC_PRT("BLUETOOTH_EVENT_HF_CALL_TERMINATED");
163 case BLUETOOTH_EVENT_HF_CALL_STARTED:
164 TC_PRT("BLUETOOTH_EVENT_HF_CALL_STARTED");
167 case BLUETOOTH_EVENT_HF_CALL_ENDED:
168 TC_PRT("BLUETOOTH_EVENT_HF_CALL_ENDED");
171 case BLUETOOTH_EVENT_HF_CALL_UNHOLD:
172 TC_PRT("BLUETOOTH_EVENT_HF_CALL_UNHOLD");
175 case BLUETOOTH_EVENT_HF_CALL_SWAPPED:
176 TC_PRT("BLUETOOTH_EVENT_HF_CALL_SWAPPED");
179 case BLUETOOTH_EVENT_HF_CALL_ON_HOLD:
180 TC_PRT("BLUETOOTH_EVENT_HF_CALL_ON_HOLD");
183 case BLUETOOTH_EVENT_HF_CALL_STATUS:
185 TC_PRT("BLUETOOTH_EVENT_HF_CALL_STATUS");
187 bt_hf_call_list_s * call_list = hf_event->param_data;
188 bt_hf_call_status_info_t **call_info;
189 TC_PRT("call_list length : %d ", call_list->count);
190 call_info = g_malloc0(sizeof(bt_hf_call_status_info_t *) *
192 bluetooth_hf_get_call_list(call_list->list, call_info);
194 for (i= 0; i < call_list->count; i++) {
195 TC_PRT("Phone Number : %s ", call_info[i]->number);
196 TC_PRT("Direction (in -1, out 0 : %d ", call_info[i]->direction);
197 TC_PRT("Call status : %d ", call_info[i]->status);
198 TC_PRT("MultyParty : %d ", call_info[i]->mpart);
199 TC_PRT("Call ID : %d ", call_info[i]->idx);
204 case BLUETOOTH_EVENT_HF_VOICE_RECOGNITION_ENABLED:
205 TC_PRT("BLUETOOTH_EVENT_HF_VOICE_RECOGNITION_ENABLED");
208 case BLUETOOTH_EVENT_HF_VOICE_RECOGNITION_DISABLED:
209 TC_PRT("BLUETOOTH_EVENT_HF_VOICE_RECOGNITION_DISABLED");
212 case BLUETOOTH_EVENT_HF_VOLUME_SPEAKER:
215 value = hf_event->param_data;
216 TC_PRT("BLUETOOTH_EVENT_HF_VOLUME_SPEAKER - value = %d", *value);
219 case BLUETOOTH_EVENT_HF_VENDOR_DEP_CMD:
221 bluetooth_vendor_dep_at_cmd_t *cmd = hf_event->param_data;
222 TC_PRT("BLUETOOTH_EVENT_HF_VENDOR_DEP_CMD - appid = %d, msg = %s",
223 cmd->app_id, cmd->message);
232 static int __bt_unbond_all_bonded_devices(void)
236 bluetooth_device_info_t *ptr;
238 GPtrArray *dev_list = NULL;
239 dev_list = g_ptr_array_new();
240 TC_PRT("g pointer arrary count : [%d]", dev_list->len);
242 ret = bluetooth_get_bonded_device_list(&dev_list);
244 TC_PRT("failed bluetooth_get_bonded_device_list");
245 g_ptr_array_free(dev_list, TRUE);
248 TC_PRT("g pointer arrary count : [%d]", dev_list->len);
250 if (dev_list->len == 0) {
251 TC_PRT("No paired device found");
252 g_ptr_array_free(dev_list, TRUE);
256 for (i = 0; i < dev_list->len; i++) {
257 ptr = g_ptr_array_index(dev_list, i);
260 TC_PRT("[%d] Unbond %2.2X:%2.2X:%2.2X:%2.2X:%2.2X:%2.2X", i + 1,
261 ptr->device_address.addr[0], ptr->device_address.addr[1],
262 ptr->device_address.addr[2], ptr->device_address.addr[3],
263 ptr->device_address.addr[4], ptr->device_address.addr[5]);
264 bluetooth_unbond_device(&ptr->device_address);
267 g_ptr_array_foreach(dev_list, (GFunc)g_free, NULL);
268 g_ptr_array_free(dev_list, TRUE);
272 static int __bt_get_last_bonded_device(bluetooth_device_address_t *device_address)
276 bluetooth_device_info_t *ptr;
278 GPtrArray *dev_list = NULL;
279 dev_list = g_ptr_array_new();
280 TC_PRT("g pointer arrary count : [%d]", dev_list->len);
282 ret = bluetooth_get_bonded_device_list(&dev_list);
284 TC_PRT("failed bluetooth_get_bonded_device_list");
285 g_ptr_array_free(dev_list, TRUE);
288 TC_PRT("g pointer arrary count : [%d]", dev_list->len);
290 if (dev_list->len == 0) {
291 TC_PRT("No paired device found");
292 g_ptr_array_free(dev_list, TRUE);
296 for (i = 0; i < dev_list->len; i++) {
297 ptr = g_ptr_array_index(dev_list, i);
300 TC_PRT("[%d] %2.2X:%2.2X:%2.2X:%2.2X:%2.2X:%2.2X", i + 1,
301 ptr->device_address.addr[0], ptr->device_address.addr[1],
302 ptr->device_address.addr[2], ptr->device_address.addr[3],
303 ptr->device_address.addr[4], ptr->device_address.addr[5]);
304 memcpy(device_address->addr, ptr->device_address.addr,
305 sizeof(bluetooth_device_address_t));
307 g_ptr_array_foreach(dev_list, (GFunc)g_free, NULL);
308 g_ptr_array_free(dev_list, TRUE);
313 int test_input_callback(void *data)
316 int test_id = (int)data;
321 g_main_loop_quit(main_loop);
325 bluetooth_hf_init(hf_event_handler, NULL);
328 bluetooth_hf_deinit();
331 bluetooth_hf_answer_call();
334 bluetooth_hf_terminate_call();
337 ret = bluetooth_hf_initiate_call(TEST_NUMBER);
338 TC_PRT("ret = %d", ret);
341 bluetooth_hf_initiate_call(NULL);
344 { bluetooth_device_address_t device_address = { {0} };
345 ret = __bt_get_last_bonded_device(&device_address);
347 TC_PRT("Error in getting last bonded device.....");
351 bluetooth_hf_connect(&device_address);
356 bluetooth_device_address_t device_address = { {0} };
357 ret = __bt_get_last_bonded_device(&device_address);
359 TC_PRT("Error in getting last bonded device.....");
363 bluetooth_hf_disconnect(&device_address);
367 bluetooth_hf_voice_recognition(1);
371 bluetooth_hf_voice_recognition(0);
374 bluetooth_hf_audio_disconnect();
377 bluetooth_hf_set_speaker_gain(BLUETOOTH_HF_SPEAKER_GAIN);
380 bluetooth_hf_send_dtmf("1");
383 /* get the Call Time from AG for DC lauch */
384 bluetooth_hf_send_xsat_cmd(11, "Q_CT,1,01025561613");
387 bluetooth_hf_release_all_call();
390 bluetooth_hf_release_and_accept();
393 bluetooth_hf_swap_call();
396 bluetooth_hf_join_call();
399 system("dbus-send --system --print-reply --dest=org.bluez.hf_agent /org/bluez/handsfree_agent org.tizen.HfApp.SendAtCmd string:AT+BCC");
403 ret = bluetooth_register_callback(bt_event_callback, NULL);
404 ret = __bt_unbond_all_bonded_devices();
406 TC_PRT("Error in getting last bonded device.....");
414 unsigned int current_codec;
415 bluetooth_hf_get_codec(¤t_codec);
416 if (current_codec == BLUETOOTH_CODEC_ID_CVSD)
417 TC_PRT("current_codec is CVSD");
419 TC_PRT("current_codec is. MSBC");
425 bt_hf_call_list_s * call_list = NULL;
426 bt_hf_call_status_info_t **call_info = NULL;
427 bluetooth_hf_request_call_list(&call_list);
428 if(call_list == NULL) {
429 TC_PRT("call_list is NULL");
432 TC_PRT("call_list length : %d ", call_list->count);
433 call_info = g_malloc0(sizeof(bt_hf_call_status_info_t *) *
435 bluetooth_hf_get_call_list(call_list->list, call_info);
437 for (i= 0; i < call_list->count; i++) {
438 TC_PRT("Phone Number : %s ", call_info[i]->number);
439 TC_PRT("Direction (in -1, out 0 : %d ", call_info[i]->direction);
440 TC_PRT("Call status : %d ", call_info[i]->status);
441 TC_PRT("MultyParty : %d ", call_info[i]->mpart);
442 TC_PRT("Call ID : %d ", call_info[i]->idx);
445 bluetooth_hf_free_call_list(call_list);
450 unsigned int sco_audio_connected;
451 bluetooth_hf_get_audio_connected(&sco_audio_connected);
452 if (sco_audio_connected == BLUETOOTH_HF_AUDIO_CONNECTED)
453 TC_PRT("SCO Audio is connected");
455 TC_PRT("SCO Audio is disconnected");
460 gboolean hf_connected;
461 bluetooth_hf_is_hf_connected(&hf_connected);
462 if (hf_connected == BLUETOOTH_HF_AUDIO_CONNECTED)
463 TC_PRT("HF is connected");
465 TC_PRT("HF is disconnected");
477 TC_PRT("bluetooth framework TC startup");
479 if (!g_thread_supported()) {
483 dbus_g_thread_init();
486 main_loop = g_main_loop_new(NULL, FALSE);
491 TC_PRT("bluetooth framework TC cleanup");
492 if (main_loop != NULL) {
493 g_main_loop_unref(main_loop);
497 static gboolean key_event_cb(GIOChannel *chan, GIOCondition cond ,
502 unsigned int len = 0;
504 memset(buf, 0, sizeof(buf));
506 if (g_io_channel_read(chan, buf, sizeof(buf), &len) !=
509 printf("IO Channel read error");
519 g_idle_add(test_input_callback, (void *)test_id);
529 key_io = g_io_channel_unix_new(fileno(stdin));
531 g_io_add_watch(key_io, G_IO_IN | G_IO_HUP | G_IO_ERR | G_IO_NVAL,
533 g_io_channel_unref(key_io);
536 g_main_loop_run(main_loop);