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-telephony-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 "9986008917"
53 tc_table_t tc_table[] = {
54 /*Telephony Application*/
55 {"bluetooth_telephony_init", 70},
56 {"bluetooth_telephony_deinit", 71},
57 {"Indicate Outgoing call", 72},
58 {"Indicate Incoming call", 73},
59 {"Speaker to Headphone", 74},
60 {"Headphone to Speaker ", 75},
61 {"Call End/Release", 76},
63 {"bluetooth_telephony_call_remote_ringing", 78},
67 {"Is SCO channel connected", 82},
68 {"Voice Recognition Start", 83},
69 {"Voice Recognition Stop", 84},
72 {"Vendor dep AT CMD [+XSAT: 11,DUAL,DUAL]", 87},
74 /* -----------------------------------------*/
80 #define tc_result(success, tc_index) \
81 TC_PRT("Test case [%d - %s] %s", tc_table[tc_index].tc_code, \
82 tc_table[tc_index].tc_name, \
83 ((success == TC_PASS) ? "Success" : "Failed"));
85 void tc_usage_print(void)
89 while (tc_table[i].tc_name) {
90 if (tc_table[i].tc_code != 0x00ff) {
91 TC_PRT("Key %d : usage %s", tc_table[i].tc_code,
94 TC_PRT("Key %d : usage %s\n\n", 0x00ff,
102 void telephony_event_handler(int event, void *data, void *user_data)
104 telephony_event_param_t *bt_event;
110 TC_PRT("AG event : [0x%04x]", event);
113 case BLUETOOTH_EVENT_TELEPHONY_ANSWER_CALL:
114 TC_PRT("BLUETOOTH_EVENT_TELEPHONY_ANSWER_CALL");
115 bluetooth_telephony_call_answered(DEFAULT_CALL_ID, TRUE);
118 case BLUETOOTH_EVENT_TELEPHONY_RELEASE_CALL:
119 TC_PRT("BLUETOOTH_EVENT_TELEPHONY_RELEASE_CALL");
120 bluetooth_telephony_call_end(DEFAULT_CALL_ID);
123 case BLUETOOTH_EVENT_TELEPHONY_REJECT_CALL:
124 bluetooth_telephony_call_end(DEFAULT_CALL_ID);
127 case BLUETOOTH_EVENT_TELEPHONY_CHLD_0_RELEASE_ALL_HELD_CALL:
128 TC_PRT("BLUETOOTH_EVENT_TELEPHONY_CHLD_0_RELEASE_ALL_HELD_CALL");
131 case BLUETOOTH_EVENT_TELEPHONY_CHLD_1_RELEASE_ALL_ACTIVE_CALL:
132 TC_PRT("BLUETOOTH_EVENT_TELEPHONY_CHLD_1_RELEASE_ALL_ACTIVE_CALL");
135 case BLUETOOTH_EVENT_TELEPHONY_CHLD_3_MERGE_CALL:
136 TC_PRT("BLUETOOTH_EVENT_TELEPHONY_CHLD_3_MERGE_CALL");
139 case BLUETOOTH_EVENT_TELEPHONY_CHLD_2_ACTIVE_HELD_CALL:
140 TC_PRT("BLUETOOTH_EVENT_TELEPHONY_CHLD_2_ACTIVE_HELD_CALL");
143 case BLUETOOTH_EVENT_TELEPHONY_SEND_DTMF:
144 TC_PRT("BLUETOOTH_EVENT_TELEPHONY_SEND_DTMF");
147 case BLUETOOTH_EVENT_TELEPHONY_CHLD_4_EXPLICIT_CALL_TRANSFER:
148 TC_PRT("BLUETOOTH_EVENT_TELEPHONY_CHLD_4_EXPLICIT_CALL_TRANSFER");
151 case BLUETOOTH_EVENT_TELEPHONY_NREC_CHANGED: {
153 TC_PRT("BLUETOOTH_EVENT_TELEPHONY_NREC_CHANGED");
154 nrec = bt_event->param_data;
155 TC_PRT("NREC status = [%d]", *nrec);
157 case BLUETOOTH_EVENT_TELEPHONY_VENDOR_AT_CMD:
158 TC_PRT("BLUETOOTH_EVENT_TELEPHONY_VENDOR_AT_CMD %s", bt_event->param_data);
167 int test_input_callback(void *data)
169 int test_id = (int)data;
174 g_main_loop_quit(main_loop);
178 bluetooth_telephony_init(telephony_event_handler, NULL);
181 bluetooth_telephony_deinit();
185 bluetooth_telephony_indicate_outgoing_call(
186 TEST_NUMBER, DEFAULT_CALL_ID, TRUE);
189 bluetooth_telephony_indicate_incoming_call(
193 bluetooth_telephony_audio_open();
196 bluetooth_telephony_audio_close();
199 bluetooth_telephony_call_end(DEFAULT_CALL_ID);
202 bluetooth_telephony_call_held(DEFAULT_CALL_ID);
205 bluetooth_telephony_call_remote_ringing(
209 TC_PRT("bluetooth_telephony_call_swapped \n");
212 bluetooth_telephony_call_answered(
213 DEFAULT_CALL_ID, FALSE);
216 bluetooth_telephony_call_answered(
217 DEFAULT_CALL_ID, TRUE);
223 state = bluetooth_telephony_is_sco_connected();
225 TC_PRT("State = %d \n", state);
232 TC_PRT("**********************\n");
233 TC_PRT(" PLEASE SPEAK \n");
234 TC_PRT("**********************\n");
236 ret = bluetooth_telephony_start_voice_recognition();
238 if (ret == BLUETOOTH_TELEPHONY_ERROR_NONE) {
239 TC_PRT("No error\n");
240 bluetooth_telephony_audio_open();
246 TC_PRT("Rcognition finished \n");
247 bluetooth_telephony_audio_close();
248 bluetooth_telephony_stop_voice_recognition();
254 gboolean status = FALSE;
256 ret = bluetooth_telephony_is_nrec_enabled(&status);
258 if (ret != BLUETOOTH_TELEPHONY_ERROR_NONE)
259 TC_PRT("Error getting NREC Status\n");
261 TC_PRT("NREC status = %d\n", status);
267 gboolean status = FALSE;
269 ret = bluetooth_telephony_is_wbs_mode(&status);
271 if (ret != BLUETOOTH_TELEPHONY_ERROR_NONE)
272 TC_PRT("Error getting WBS Status\n");
274 TC_PRT("WBS status = %d\n", status);
280 TC_PRT("Vendor dependent AT Command\n");
282 ret = bluetooth_telephony_send_vendor_cmd("+XSAT: 11,DUAL,DUAL");
284 if (ret == BLUETOOTH_TELEPHONY_ERROR_NONE) {
285 TC_PRT("No error\n");
298 TC_PRT("bluetooth framework TC startup");
300 dbus_threads_init_default();
303 main_loop = g_main_loop_new(NULL, FALSE);
308 TC_PRT("bluetooth framework TC cleanup");
309 if (main_loop != NULL) {
310 g_main_loop_unref(main_loop);
314 static gboolean key_event_cb(GIOChannel *chan, GIOCondition cond ,
319 unsigned int len = 0;
321 memset(buf, 0, sizeof(buf));
323 if (g_io_channel_read(chan, buf, sizeof(buf), &len) !=
326 printf("IO Channel read error");
336 g_idle_add(test_input_callback, (void *)test_id);
346 key_io = g_io_channel_unix_new(fileno(stdin));
348 g_io_add_watch(key_io, G_IO_IN | G_IO_HUP | G_IO_ERR | G_IO_NVAL,
350 g_io_channel_unref(key_io);
353 g_main_loop_run(main_loop);