Make TIZEN 2.0
[apps/home/call.git] / call-engine / voice-call-core.c
1 /*
2  * Copyright 2012  Samsung Electronics Co., Ltd
3  *
4  * Licensed under the Flora License, Version 1.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
7  *
8  * http://www.tizenopensource.org/license
9  *
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.
15  */
16
17
18 #include <msg.h>
19
20 #include "vc-core-util.h"
21 #include "vc-core-engine-types.h"
22 #include "vc-core-callagent.h"
23 #include "vc-core-engine.h"
24 #include "vc-core-error.h"
25 #include "voice-call-core.h"
26 #include "voice-call-dbus.h"
27 #include "voice-call-engine-msg.h"
28 #include "voice-call-service.h"
29 #include "voice-call-device.h"
30 #include "voice-call-sound.h"
31
32 #include "voice-call-bt.h"
33 #include "phone-misc.h"
34 #include "vc-core-engine.h"
35
36 #include "voice-call-engine.h"
37
38 #define MO_REDIAL_COUNT_MAX 10
39 #define MO_REDIAL_TIMER_INTERVAL_FIRST  3000    /**< MO Redial Timer Interva; - 5 Secs*/
40 #define MO_REDIAL_TIMER_INTERVAL_SECOND         3000    /**< MO Redial Timer Interva; - 1 Minute*/
41 #define MO_REDIAL_TIMER_INTERVAL_THIRD  3000    /**< MO Redial Timer Interva; - 3 Minutes*/
42
43 #define MINUTE_MINDER_TIMEOUT_VALUE     60000
44
45 #define DTMF_PAUSE_TIMER_INTERVAL_FIRST         3000    /*3 Seconds */
46 #define DTMF_PAUSE_TIMER_INTERVAL_REST                  3000    /*3 Seconds */
47 #define DTMF_PAUSE_TIMER_INTERVAL_GCF_FIRST     800     /*0.8 Second */
48 #define DTMF_PAUSE_TIMER_INTERVAL_GCF_REST              3300    /*3 Seconds */
49
50 gboolean mo_redial_timer_cb(void *data);
51
52 #define SET_PATH_TIMER_VALUE    50
53 static guint g_set_path_timer_handler = 0;
54 static gboolean __voicecall_core_set_path_timer_cb(gpointer puser_data);
55
56 /* For Debug Information, Call Engine Event name string constant */
57 char *gszcall_engine_event[VC_ENGINE_EVENT_MAX] = {
58         "VC_CALL_INCOM",
59         "VC_CALL_OUTGOING",
60         "VC_CALL_OUTGOING_ORIG",
61         "VC_CALL_OUTGOING_ALERT",
62         "VC_CALL_CONNECTED",
63         "VC_CALL_NORMAL_END",
64         "VC_CALL_INCOM_END",
65         "VC_CALL_INCOM_DROPPED",
66         "VC_CALL_REJECTED_END",
67         "VC_CALL_OUTGOING_END", /* 10 */
68
69         "VC_CALL_OUTGOING_ABORTED",
70         "VC_CALL_DTMF_ACK",
71         "VC_CALL_AUTO_REDIAL_CHECK",
72         "VC_CALL_ANSWER_CNF",
73         "VC_CALL_SS_HELD",
74         "VC_CALL_SS_RETREIVED",
75         "VC_CALL_SS_SWAP",
76         "VC_CALL_SS_SETUP_CONF",
77         "VC_CALL_SS_SPLIT_CONF",
78         "VC_CALL_SS_TRANSFERRED",       /* 20 */
79
80         "VC_CALL_SS_CONNECT_LINE_IND",
81         "VC_CALL_IND_FORWARD",
82         "VC_CALL_IND_ACTIVATE",
83         "VC_CALL_IND_HOLD",
84         "VC_CALL_IND_TRANSFER",
85         "VC_CALL_IND_SETUPCONFERENCE",
86         "VC_CALL_IND_BARRING",
87         "VC_CALL_IND_WAITING",
88         "VC_CALL_IND_CUGINFO",
89         "VC_CALL_IND_SSNOTIFY", /* 30 */
90
91         "VC_CALL_IND_CALLINGNAMEINFO",
92         "VC_CALL_IND_REDIRECT_CNF",
93         "VC_CALL_IND_ACTIVATECCBS_CNF",
94         "VC_CALL_IND_ACTIVATECCBS_USERINFO",
95         "VC_CALL_IND_AOC",
96         "VC_ERROR_OCCURED",
97         "VC_ACTION_INCOM_FORCE",
98         "VC_ACTION_SAT_REQUEST",
99         "VC_ACTION_SAT_RESPONSE",
100         "VC_ACTION_CALL_END_HELD_RETREIVED",    /* 40 */
101
102         "VC_ACTION_NO_ACTIVE_TASK",
103         "VC_CALL_GET_VOLUME_RESP"
104 };
105
106 static gboolean __vc_core_is_answermode_enabled_from_testmode(void);
107 static gboolean __vc_core_is_answermode_enabled(void);
108 static void __voicecall_core_start_auto_answer(call_vc_core_state_t *pcall_core, gboolean isTestMode);
109 static void __voicecall_core_cancel_auto_answer(call_vc_core_state_t *pcall_core);
110 /*static void __voicecall_core_check_headset_earjack_status(call_vc_core_state_t *pcall_core);*/
111 static void __vc_core_set_auto_redial_count(call_vc_core_state_t *pcall_core, int auto_redial_count);
112 /*static gboolean __voicecall_core_callstatus_set_timer_cb(gpointer puser_data);*/
113
114 static int __voicecall_core_get_string_id_by_errorcode(int error_code);
115 static void __voicecall_core_mocall_reset_engine_state(voicecall_engine_t *pcall_engine);
116 static gboolean __voicecall_core_is_redial_cuase(int end_cause);
117
118 static gboolean __voicecall_core_queue_dtmf_string(call_vc_core_state_t *pcall_core, char *dtmf_string, gboolean bsat_dtmf);
119 static gboolean __voicecall_core_handle_dtmf_ack(call_vc_core_state_t *pcall_core, gboolean success);
120
121 /**
122  * This function puts the currently active call on hold
123  *
124  * @return              Returns TRUE on success or FALSE on failure
125  * @param[in]           pcall_engine            Handle to voicecall engine
126  */
127 inline gboolean voicecall_core_hold_call(voicecall_engine_t *pcall_engine)
128 {
129
130         voicecall_error_t error_code = ERROR_VOICECALL_NONE;
131
132         error_code = _vc_core_engine_hold_call(pcall_engine);
133
134         CALL_ENG_DEBUG(ENG_DEBUG, "Error Code : %d", error_code);
135         return (ERROR_VOICECALL_NONE == error_code || ERROR_VOICECALL_PREVIOUS_REQUEST_IN_PROGRESS == error_code) ? TRUE : FALSE;
136 }
137
138 /**
139  * This function retreives the currently held call
140  *
141  * @return              Returns TRUE on success or FALSE on failure
142  * @param[in]           pcall_engine            Handle to voicecall engine
143  */
144 inline gboolean voicecall_core_retrieve_call(voicecall_engine_t *pcall_engine)
145 {
146         voicecall_error_t error_code = ERROR_VOICECALL_NONE;
147
148         error_code = _vc_core_engine_retrieve_call(pcall_engine);
149
150         CALL_ENG_DEBUG(ENG_DEBUG, "Error Code : %d", error_code);
151         return (ERROR_VOICECALL_NONE == error_code || ERROR_VOICECALL_PREVIOUS_REQUEST_IN_PROGRESS == error_code) ? TRUE : FALSE;
152 }
153
154 /**
155  * This function swaps the currently available active and held calls
156  *
157  * @return              Returns TRUE on success or FALSE on failure
158  * @param[in]           pcall_engine            Handle to voicecall engine
159  */
160 inline gboolean voicecall_core_swap_calls(voicecall_engine_t *pcall_engine)
161 {
162         voicecall_error_t error_code = ERROR_VOICECALL_NONE;
163
164         error_code = _vc_core_engine_swap_calls(pcall_engine);
165
166         CALL_ENG_DEBUG(ENG_DEBUG, "Error Code : %d", error_code);
167         return (ERROR_VOICECALL_NONE == error_code || ERROR_VOICECALL_PREVIOUS_REQUEST_IN_PROGRESS == error_code) ? TRUE : FALSE;
168 }
169
170 /**
171  * This function clears the MO Call Details
172  *
173  * @return              Returns TRUE on success or FALSE on failure
174  * @param[in]           pcall_engine            Handle to voicecall engine
175  */
176 inline gboolean voicecall_core_clear_mo_call(voicecall_engine_t *pcall_engine)
177 {
178         return (ERROR_VOICECALL_NONE == _vc_core_engine_finalize_call(pcall_engine, VC_OUTGOING_CALL, -1)) ? TRUE : FALSE;
179 }
180
181 /**
182  * This function clears the Connected Call Details
183  *
184  * @return              Returns TRUE on success or FALSE on failure
185  * @param[in]           pcall_engine            Handle to voicecall engine
186  * @param[in]           call_handle             Handle of the Connected Call to be cleared
187  */
188 inline gboolean voicecall_core_clear_connected_call(voicecall_engine_t *pcall_engine, int call_handle)
189 {
190         return (ERROR_VOICECALL_NONE == _vc_core_engine_finalize_call(pcall_engine, VC_CONNECTED_CALL, call_handle)) ? TRUE : FALSE;
191 }
192
193 /**
194  * This function changes the voicecall engine's state
195  *
196  * @return              Returns TRUE on success or FALSE on failure
197  * @param[in]           pcall_engine            Handle to voicecall engine
198  * @param[in]           eng_state               Engine State to be changed
199  */
200 inline gboolean voicecall_core_change_engine_state(voicecall_engine_t *pcall_engine, int eng_state)
201 {
202         return (ERROR_VOICECALL_NONE == _vc_core_engine_change_engine_iostate(pcall_engine, eng_state)) ? TRUE : FALSE;
203 }
204
205 /**
206  * This function ends an Outgoing Call
207  *
208  * @return              Returns TRUE on success or FALSE on failure
209  * @param[in]           pcall_engine            Handle to voicecall engine
210  */
211 inline gboolean voicecall_core_end_mo_call(voicecall_engine_t *pcall_engine)
212 {
213         return (ERROR_VOICECALL_NONE == _vc_core_engine_end_call(pcall_engine, VC_END_OUTGOING_CALL)) ? TRUE : FALSE;
214 }
215
216 /**
217  * This function retreives the Voicecall Engine's State
218  *
219  * @return              Returns TRUE on success or FALSE on failure
220  * @param[in]           pcall_engine            Handle to voicecall engine
221  * @param[out]  io_state                        Voicecall Engine InOut State
222  */
223 inline gboolean voicecall_core_get_engine_state(voicecall_engine_t *pcall_engine, int *eng_state)
224 {
225         return (ERROR_VOICECALL_NONE == _vc_core_engine_status_get_engine_iostate(pcall_engine, eng_state)) ? TRUE : FALSE;
226 }
227
228 /**
229  * This function checks whether any call exists
230  *
231  * @return              Returns TRUE on success or FALSE on failure
232  * @param[in]           pcall_engine            Handle to voicecall engine
233  * @param[out]  active_calls            TRUE - If active call exists or FALSE If active call doesn't exists
234  * @param[out]  held_calls              TRUE - If held call exists or FALSE If held call doesn't exists
235  */
236 inline gboolean voicecall_core_is_call_exists(voicecall_engine_t *pcall_engine, gboolean *active_calls, gboolean *held_calls)
237 {
238         return (ERROR_VOICECALL_NONE == _vc_core_engine_status_isexists_any_call(pcall_engine, active_calls, held_calls)) ? TRUE : FALSE;
239 }
240
241 /**
242  * This function checks whether incoming call exists or not
243  *
244  * @return              Returns TRUE if incoming call exists or FALSE on failure
245  * @param[in]           pcall_engine            Handle to voicecall engine
246  */
247 inline gboolean voicecall_core_is_incoming_call_exists(voicecall_engine_t *pcall_engine)
248 {
249         gboolean bmtcall_exists = FALSE;
250
251         _vc_core_engine_status_isexists_call_bytype(pcall_engine, VC_INCOMING_CALL, &bmtcall_exists);
252         return bmtcall_exists;
253 }
254
255 /**
256  * This function checks whether outgoing call exists or not
257  *
258  * @return              Returns TRUE if outgoing call exists or FALSE on failure
259  * @param[in]           pcall_engine            Handle to voicecall engine
260  */
261 inline gboolean voicecall_core_is_outgoing_call_exists(voicecall_engine_t *pcall_engine)
262 {
263         gboolean bmocall_exists = FALSE;
264
265         _vc_core_engine_status_isexists_call_bytype(pcall_engine, VC_OUTGOING_CALL, &bmocall_exists);
266         return bmocall_exists;
267 }
268
269 /**
270  * This function checks whether any connexcted call exists or not
271  *
272  * @return              Returns TRUE if connected call exists or FALSE on failure
273  * @param[in]           pcall_engine            Handle to voicecall engine
274  */
275 inline gboolean voicecall_core_is_connected_call_exist(voicecall_engine_t *pcall_engine)
276 {
277         gboolean bcall_exists = FALSE;
278
279         _vc_core_engine_status_isexists_call_bytype(pcall_engine, VC_CONNECTED_CALL, &bcall_exists);
280         return bcall_exists;
281 }
282
283 /**
284  * This function checks whether any connexcted call exists or not in the given group
285  *
286  * @return              Returns TRUE if connected call exists or FALSE on failure
287  * @param[in]           pcall_engine            Handle to voicecall engine
288  * @param[in]           group_index             Group Index to be searhced
289  */
290 inline gboolean voicecall_core_is_connected_call_exist_in_group(voicecall_engine_t *pcall_engine, int group_index)
291 {
292         gboolean bcall_exists = FALSE;
293         voicecall_error_t error_code = ERROR_VOICECALL_NONE;
294
295         if (ERROR_VOICECALL_NONE != _vc_core_engine_group_isexists_connected_call_ingroup(pcall_engine, group_index, &bcall_exists)) {
296                 CALL_ENG_DEBUG(ENG_DEBUG, "Error_code %d", error_code);
297
298         }
299
300         return bcall_exists;
301 }
302
303 /**
304  * This function checks whether any call exists
305  *
306  * @return              Returns TRUE if connected call exists or FALSE on failure
307  * @param[in]           pcall_engine            Handle to voicecall engine
308  */
309 inline gboolean voicecall_core_is_any_call_exists(voicecall_engine_t *pcall_engine)
310 {
311         gboolean bcall_exists = FALSE;
312
313         _vc_core_engine_status_isexists_call_bytype(pcall_engine, VC_INCOMING_CALL, &bcall_exists);
314         CALL_ENG_DEBUG(ENG_DEBUG, "Incoming Call = [%d]", bcall_exists);
315
316         if (FALSE == bcall_exists) {
317                 _vc_core_engine_status_isexists_call_bytype(pcall_engine, VC_OUTGOING_CALL, &bcall_exists);
318         }
319         CALL_ENG_DEBUG(ENG_DEBUG, "Outgoing Call = [%d]", bcall_exists);
320
321         if (FALSE == bcall_exists) {
322                 _vc_core_engine_status_isexists_call_bytype(pcall_engine, VC_CONNECTED_CALL, &bcall_exists);
323         }
324         CALL_ENG_DEBUG(ENG_DEBUG, "Connected Call = [%d]", bcall_exists);
325
326         return bcall_exists;
327 }
328
329 /**
330  * This function retreives the totally number of availavle calls including connected, MO and MT Calls
331  *
332  * @return              Returns TRUE if success or FALSE on failure
333  * @param[in]           pcall_engine            Handle to voicecall engine
334  * @param[out]  ptotal_call_member      number of avialble calls
335  */
336 inline gboolean voicecall_core_get_total_call_member(voicecall_engine_t *pcall_engine, int *ptotal_call_member)
337 {
338         return (ERROR_VOICECALL_NONE == _vc_core_engine_status_get_call_member_count(pcall_engine, ptotal_call_member)) ? TRUE : FALSE;
339 }
340
341 /**
342  * This function checks whether voicecall engine's call agent is idle or not
343  *
344  * @return              Returns TRUE if call agent is idle or FALSE on failure
345  * @param[in]           pcall_engine            Handle to voicecall engine
346  */
347 inline gboolean voicecall_core_is_callagent_idle(voicecall_engine_t *pcall_engine)
348 {
349         gboolean bcallagent_idle = FALSE;
350
351         _vc_core_engine_status_is_engine_busy(pcall_engine, &bcallagent_idle);
352         CALL_ENG_DEBUG(ENG_DEBUG, "Call Agent Busy State : %d", bcallagent_idle);
353
354         return !bcallagent_idle;
355 }
356
357 /**
358 * This function checks the current call status and engine status
359 *
360 * @return               TRUE, if connected calls available and engine is in idle, FALSE otherwise
361  * @param[in]           pcall_engine            Handle to voicecall engine
362 */
363 inline gboolean voicecall_core_is_incall_request_possible(voicecall_engine_t *pcall_engine)
364 {
365         int eng_state = VC_INOUT_STATE_NONE;
366         int member_num_0 = 0;
367         int member_num_1 = 0;
368
369         _vc_core_engine_group_get_connected_member_count(pcall_engine, 0, &member_num_0);
370         _vc_core_engine_group_get_connected_member_count(pcall_engine, 1, &member_num_1);
371         voicecall_core_get_engine_state(pcall_engine, &eng_state);
372         if (!(voicecall_core_is_callagent_idle(pcall_engine) && ((member_num_1 + member_num_0) > 0)
373               && (eng_state == VC_INOUT_STATE_NONE))) {
374                 CALL_ENG_DEBUG(ENG_DEBUG, "Engine Busy, Cannot complete Request,mem_0:%d,mem_1:%d,eng_state:%d ", member_num_0, member_num_1, eng_state);
375                 return FALSE;
376         }
377
378         return TRUE;
379 }
380
381 /**
382  * This function changes the modem call audio path
383  *
384  * @return              TRUE sucess, FALSE otherwise
385  * @param[in]           pcall_engine            Handle to voicecall engine
386  * @param[in]           audio_path              audio path to be changed
387  */
388 inline gboolean voicecall_core_change_audio_path(voicecall_engine_t *pcall_engine, voicecall_audio_path_t audio_path, gboolean bextra_volume)
389 {
390         return (ERROR_VOICECALL_NONE == _vc_core_engine_change_audio_path(pcall_engine, audio_path, bextra_volume)) ? TRUE : FALSE;
391 }
392
393 /**
394  * This function sets the voice call audio volume for the given audio path type
395  *
396  * @return              returns TRUE in success , FALSE otherwise
397  * @param[in]           pcall_engine            Handle to voicecall engine
398  * @param[in]           tapi_snd_path           audio path for the volume to be set
399  * @param[in]           vol_level                       volume level
400  */
401 inline gboolean voicecall_core_set_audio_volume(voicecall_engine_t *pcall_engine, voicecall_audio_path_t tapi_snd_path, int vol_level)
402 {
403         return (ERROR_VOICECALL_NONE == _vc_core_engine_set_audio_volume(pcall_engine, tapi_snd_path, (voicecall_audio_volume_t) vol_level)) ? TRUE : FALSE;
404 }
405
406 /**
407  * This function retreives the voice call audio volume for the given audio path type
408  *
409  * @return              returns TRUE in success , FALSE otherwise
410  * @param[in]           pcall_engine                    Handle to voicecall engine
411  * @param[in]           audio_path_type         audio path for the volume to be retreived
412  */
413 inline gboolean voicecall_core_get_audio_volume(voicecall_engine_t *pcall_engine, voicecall_audio_path_t audio_path_type)
414 {
415         return (ERROR_VOICECALL_NONE == _vc_core_engine_get_audio_volume(pcall_engine, audio_path_type)) ? TRUE : FALSE;
416 }
417
418 /**
419  * This function set the voice call audio mute status
420  *
421  * @return              returns TRUE in success , FALSE otherwise
422  * @param[in]           pcall_engine                    Handle to voicecall engine
423  * @param[in]           bvoice_mute                     mute status
424  */
425 inline gboolean voicecall_core_set_audio_mute_status(voicecall_engine_t *pcall_engine, gboolean bvoice_mute)
426 {
427         return (ERROR_VOICECALL_NONE == _vc_core_engine_set_audio_mute(pcall_engine, bvoice_mute)) ? TRUE : FALSE;
428 }
429
430 /**
431  * This function retreives the first active call among the available active calls
432  *
433  * @return              Returns TRUE if success or FALSE on failure
434  * @param[in]           pcall_engine                    Handle to voicecall engine
435  * @param[out]  pcall_handle            call handle of the active call
436  */
437 inline gboolean voicecall_core_get_zuhause(voicecall_engine_t *pcall_engine, gboolean * bzuhause)
438 {
439         return (ERROR_VOICECALL_NONE == _vc_core_engine_status_is_zuhause_area(pcall_engine, bzuhause)) ? TRUE : FALSE;
440 }
441
442 /**
443  * This function retreives the Voicecall Engine's State
444  *
445  * @return              Returns TRUE on success or FALSE on failure
446  * @param[in]   pcall_engine    Handle to voicecall engine
447  * @param[in]   call_handle     Call handle of the call for which the call object is retrieved
448  * @param[out]  pcall_object    Pointer to the retrived call object info
449  */
450 inline gboolean voicecall_core_get_call_object(voicecall_engine_t *pcall_engine, int call_handle, call_vc_call_objectinfo_t * pcall_object)
451 {
452         return (ERROR_VOICECALL_NONE == _vc_core_engine_status_get_call_object(pcall_engine, call_handle, pcall_object)) ? TRUE : FALSE;
453 }
454
455 /**
456  * This function sends response to sat engine
457  *
458  * @return              Returns TRUE If transfer call can be made or FALSE if not
459  * @param[in]   pcall_engine    Handle to voicecall engine
460  * @param[in]           sat_rqst_resp_type sat rqst/resp type to be set by the client
461  * @param[in]           sat_response_type sat response type to be sent to sat
462  */
463 inline gboolean voicecall_core_send_sat_response(voicecall_engine_t *pcall_engine, voicecall_engine_sat_rqst_resp_type sat_rqst_resp_type, call_vc_sat_reponse_type_t sat_response_type)
464 {
465         voicecall_error_t error_code = 0;
466         error_code = _vc_core_engine_send_sat_response(pcall_engine, sat_rqst_resp_type, sat_response_type);
467         CALL_ENG_DEBUG(ENG_DEBUG, "error_code:[%d] ", error_code);
468         return (ERROR_VOICECALL_NONE == error_code) ? TRUE : FALSE;
469 }
470
471 /**
472  * This function retreives the number of active call members
473  *
474  * @return              Returns TRUE if success or FALSE on failure
475  * @param[in]           pcall_core              Handle to voicecall core
476  * @param[out]  pactive_member_num      number of active call members available
477  */
478 inline gboolean voicecall_core_get_active_call_member(call_vc_core_state_t *pcall_core, int *pactive_member_num)
479 {
480         *pactive_member_num = 0;
481         return (ERROR_VOICECALL_NONE == _vc_core_engine_status_get_call_member_info(pcall_core->pcall_engine, VC_ACTIVE_CALL, pactive_member_num)) ? TRUE : FALSE;
482 }
483
484 /**
485  * This function checks whether possible to make conference call
486  *
487  * @return              Returns TRUE If Conference call can be made or FALSE if not
488  * @param[in]           papp_document   Handle to Application Document
489  */
490 inline gboolean voicecall_core_is_conf_call_possible(call_vc_core_state_t *pcall_core)
491 {
492         gboolean bconf_call = FALSE;
493
494         _vc_core_engine_status_is_conf_call_possible(pcall_core->pcall_engine, &bconf_call);
495
496         return bconf_call;
497 }
498
499 /**
500  * This function checks whether possible to transfer call
501  *
502  * @return              Returns TRUE If transfer call can be made or FALSE if not
503  * @param[in]           pcall_core              Handle to voicecall core
504  */
505 inline gboolean voicecall_core_is_transfer_call_possible(call_vc_core_state_t *pcall_core)
506 {
507         gboolean btransfer_call = FALSE;
508
509         _vc_core_engine_status_is_transfer_call_possible(pcall_core->pcall_engine, &btransfer_call);
510
511         return btransfer_call;
512 }
513
514 /**
515  * This function checks whether the given code is a valid Supplementary Services Code
516  *
517  * @return              Returns TRUE on success or FALSE on failure
518  * @param[in]           pcall_core              Handle to voicecall core
519  * @param[in]           pszInput                        Number to be verified
520  */
521 inline gboolean voicecall_core_is_valid_sscode(call_vc_core_state_t *pcall_core, const char *pszInput)
522 {
523         gboolean bsscode = FALSE;
524
525         _vc_core_engine_status_isvalid_ss_code(pcall_core->pcall_engine, pszInput, &bsscode);
526
527         return bsscode;
528 }
529
530 #ifdef _CPHS_DEFINED_
531 /**
532  * This function gets the cphs status from the engine
533  *
534  * @return              TRUE if queried status is enabled, FALSE otherwise
535  * @param[in]           pcall_core              Handle to voicecall core
536  * @param[in]           csp_service             csp service to be queried
537  */
538 inline gboolean voicecall_core_get_cphs_csp_status(call_vc_core_state_t *pcall_core, voicecall_cphs_csp_service csp_service)
539 {
540         gboolean bcsp_status = FALSE;
541
542         _vc_core_engine_status_get_cphs_csp_status(pcall_core->pcall_engine, csp_service, &bcsp_status);
543         return bcsp_status;
544 }
545 #endif
546
547 /**
548  * This function informs the Voicecall Engine that current SS operation has been completed
549  *
550  * @return              Returns TRUE if all the calls are ended or FALSE on failure
551  * @param[in]           pcall_core              Handle to voicecall core
552  */
553 inline gboolean voicecall_core_set_check_ss_on_end(call_vc_core_state_t *pcall_core)
554 {
555         return (ERROR_VOICECALL_NONE == _vc_core_engine_status_set_end_flag(pcall_core->pcall_engine, VC_RETREIVE_CALL_ON_MOCALL_END)) ? TRUE : FALSE;
556 }
557
558 /**
559  * This function extracts vaild phone number
560  *
561  * @return              void
562  * @param[in]
563  */
564 inline void voicecall_core_extract_phone_number(const char *source_tel_number, char *phone_number, const int buf_size)
565 {
566         _vc_core_engine_extract_phone_number(source_tel_number, phone_number, buf_size);
567 }
568
569 /************************
570 *  inline function END
571 **************************/
572 void voicecall_core_set_status(call_vc_core_state_t *pcall_core, call_vc_core_flags_t core_flags, gboolean bstatus)
573 {
574         CALL_ENG_DEBUG(ENG_DEBUG, "core flags:[0x%x], Set status:[%d] ", core_flags, bstatus);
575
576         if (CALL_VC_CORE_FLAG_NONE == core_flags) {
577                 /*Set the document flag to defaults */
578                 pcall_core->core_status = CALL_VC_CORE_FLAG_NONE;
579                 return;
580         }
581
582         if (TRUE == bstatus) {
583                 /*Set Flag */
584                 pcall_core->core_status |= core_flags;
585         } else {
586                 /*Remove bit field only if it is already set/ otherwise ignore it */
587                 if ((pcall_core->core_status & core_flags) == core_flags) {
588                         pcall_core->core_status = (pcall_core->core_status ^ core_flags);
589                 }
590         }
591
592         CALL_ENG_DEBUG(ENG_DEBUG, "After SET, core_status:[0x%x]", pcall_core->core_status);
593
594 }
595
596 gboolean voicecall_core_get_status(call_vc_core_state_t *pcall_core, call_vc_core_flags_t core_flags)
597 {
598         CALL_ENG_DEBUG(ENG_DEBUG, "core_flags:[0x%x]", core_flags);
599         CALL_ENG_DEBUG(ENG_DEBUG, "Before Get, core_status:[0x%x]", pcall_core->core_status);
600
601         if ((pcall_core->core_status & core_flags) == core_flags) {
602                 CALL_ENG_DEBUG(ENG_DEBUG, "Flag [0x%x] is available", core_flags);
603                 return TRUE;
604         }
605
606         CALL_ENG_DEBUG(ENG_DEBUG, "Flag [0x%x] is not available", core_flags);
607         return FALSE;
608 }
609
610 static gboolean __voicecall_core_minute_minder(gpointer puser_data)
611 {
612         CALL_ENG_DEBUG(ENG_DEBUG, "..");
613         call_vc_core_state_t *pcall_core = (call_vc_core_state_t *)puser_data;
614
615         if ((voicecall_core_is_incoming_call_exists(pcall_core->pcall_engine) == FALSE)
616             && (voicecall_core_is_outgoing_call_exists(pcall_core->pcall_engine) == FALSE)
617             && (voicecall_core_is_connected_call_exist(pcall_core->pcall_engine) == TRUE)) {
618                 voicecall_snd_play_effect_tone(pcall_core->papp_snd, VOICE_CALL_SND_EFFECT_CALL_MINUTE_MINDER);
619         }
620
621         return TRUE;
622 }
623
624 static gboolean __voicecall_core_set_path_timer_cb(gpointer puser_data)
625 {
626         CALL_ENG_DEBUG(ENG_DEBUG, "..");
627         VOICECALL_RETURN_FALSE_IF_FAIL(puser_data != NULL);
628         call_vc_core_state_t *pcall_core = (call_vc_core_state_t *)puser_data;
629
630         voicecall_snd_change_path(pcall_core->papp_snd);
631
632         if (g_set_path_timer_handler > 0) {
633                 g_source_remove(g_set_path_timer_handler);
634                 g_set_path_timer_handler = 0;
635         }
636
637         return FALSE;
638 }
639
640 static gboolean __voicecall_core_handle_call_end_on_silent_reject(call_vc_core_state_t *pcall_core, int call_handle)
641 {
642         CALL_ENG_DEBUG(ENG_DEBUG, "call_handle = %d", call_handle);
643
644         if ((pcall_core->mtcall_silent_reject_handle == call_handle)) {
645                 /*Call rejected due to lawmo lock */
646                 if (FALSE == voicecall_core_is_connected_call_exist(pcall_core->pcall_engine)) {
647                         /*Connected calls need to be checked, Connected emergency calls may be avaialble */
648                         voicecall_core_set_to_default(pcall_core);
649                 } else {
650                         CALL_ENG_DEBUG(ENG_ERR, "Connected calls available");
651                         _vc_core_engine_status_dump_call_details(pcall_core->pcall_engine);
652                 }
653                 pcall_core->mtcall_silent_reject_handle = -1;
654                 return TRUE;
655         }
656
657         return FALSE;
658 }
659
660 static gboolean __voicecall_core_silent_reject_mt(call_vc_core_state_t *pcall_core, int call_handle)
661 {
662         CALL_ENG_DEBUG(ENG_DEBUG, "call_handle = %d", call_handle);
663
664         voicecall_error_t error_code = ERROR_VOICECALL_NONE;
665
666         pcall_core->mtcall_silent_reject_handle = call_handle;
667
668         /*Reject the call */
669         error_code = _vc_core_engine_reject_call(pcall_core->pcall_engine, FALSE);
670
671         if (ERROR_VOICECALL_NONE != error_code) {
672                 CALL_ENG_DEBUG(ENG_ERR, "_vc_core_engine_reject_call Failed, error_code = %d", error_code);
673         }
674
675         return TRUE;
676 }
677
678 static void __voicecall_core_processing_mo_cancel(call_vc_core_state_t *pcall_core)
679 {
680         voicecall_engine_t *pcall_engine = pcall_core->pcall_engine;
681         int total_call_member;
682
683         CALL_ENG_DEBUG(ENG_DEBUG, "..");
684
685         if (TRUE == voicecall_snd_is_signal_playing(pcall_core->papp_snd)) {
686                 CALL_ENG_DEBUG(ENG_DEBUG, "Signal is playing, skipping cancel timer");
687                 return;
688         }
689
690         vc_engine_outgoing_end_type event_data;
691
692         /* normal outgong end */
693         CALL_ENG_DEBUG(ENG_DEBUG, "It is normal outgong end case.");
694         CALL_ENG_DEBUG(ENG_DEBUG, "call_handle:[%d],end_cause_type:[%d]", pcall_core->mo_end_call_handle, pcall_core->mo_end_cause_type);
695
696         memset(&event_data, 0, sizeof(event_data));
697         event_data.call_handle = pcall_core->mo_end_call_handle;
698         event_data.end_cause_type = pcall_core->mo_end_cause_type;
699         vcall_engine_send_event_to_client(VC_ENGINE_MSG_OUTGOING_END_TO_UI, (void *)&event_data);
700
701         _vc_bt_send_response_to_bt(pcall_core, BT_AG_RES_CALL_END, pcall_core->mo_end_call_handle, NULL);
702
703         __vc_core_set_auto_redial_count(pcall_core, 0);
704         voicecall_core_clear_mo_call(pcall_engine);
705
706         __voicecall_core_mocall_reset_engine_state(pcall_engine);
707
708         /* __vcui_app_view_mo_finish_call() start */
709         voicecall_snd_stop_signal(pcall_core->papp_snd);
710
711         voicecall_core_get_total_call_member(pcall_engine, &total_call_member);
712         /* If No Connected Calls End the UI */
713         if (total_call_member == 0) {
714                 /*Reset voice call core to default values */
715                 voicecall_core_set_to_default(pcall_core);
716         } else {
717                 voicecall_snd_change_path(pcall_core->papp_snd);
718         }
719         /* __vcui_app_view_mo_finish_call() end */
720
721 }
722
723 static void __voicecall_core_mocall_signal_play_end_cb(gpointer pdata)
724 {
725         call_vc_core_state_t *pcall_core = (call_vc_core_state_t *)pdata;
726
727         CALL_ENG_DEBUG(ENG_DEBUG, "..");
728
729         if (FALSE == voicecall_core_is_connected_call_exist(pcall_core->pcall_engine)) {
730                 CALL_ENG_DEBUG(ENG_DEBUG, "No More calls, resetting path");
731                 _vc_core_util_set_call_status(VCONFKEY_CALL_OFF);
732         }
733
734         if (TRUE == voicecall_core_is_outgoing_call_exists(pcall_core->pcall_engine)) {
735                 CALL_ENG_DEBUG(ENG_DEBUG, "Updating MO UI on signal end");
736                 __voicecall_core_processing_mo_cancel(pcall_core);
737         }
738 }
739
740 static voicecall_snd_signal_type_t __voicecall_core_get_signal_type_from_endcause(int end_cause)
741 {
742         int signal_type = 0;
743
744         CALL_ENG_DEBUG(ENG_DEBUG, "End end_cause_type: %d", end_cause);
745
746         switch (end_cause) {
747         case VC_ENDCAUSE_USER_BUSY:
748         case VC_ENDCAUSE_USER_DOESNOT_RESPOND:
749         case VC_ENDCAUSE_USER_UNAVAILABLE:
750         case VC_ENDCAUSE_NO_ANSWER:
751                 {
752                         signal_type = VOICE_CALL_SIGNAL_USER_BUSY_TONE;
753                 }
754                 break;
755         default:
756                 signal_type = VOICE_CALL_SIGNAL_NONE;
757                 break;
758         }
759
760         CALL_ENG_DEBUG(ENG_DEBUG, "Signal Type: %d", signal_type);
761
762         return signal_type;
763 }
764
765 static void __voicecall_core_handle_normal_end(call_vc_core_state_t *pcall_core, int call_handle, voice_call_end_cause_type_t end_cause)
766 {
767         int total_call_member = 0;
768         voicecall_engine_t *pcall_engine = pcall_core->pcall_engine;
769
770         /*Set the callstatus to OFF before processing the End Event Animation */
771         if (TRUE == voicecall_core_is_connected_call_exist(pcall_engine)) {
772                 _vc_core_util_set_call_status(VCONFKEY_CALL_VOICE_ACTIVE);
773         } else if ((TRUE == voicecall_core_is_incoming_call_exists(pcall_engine)) || (TRUE == voicecall_core_is_outgoing_call_exists(pcall_engine))) {
774                 _vc_core_util_set_call_status(VCONFKEY_CALL_VOICE_CONNECTING);
775         } else {
776                 /*Reset the Path Actual path must be closed when modem path closed!! */
777                 _vc_core_util_set_call_status(VCONFKEY_CALL_OFF);
778         }
779
780         if (FALSE == voicecall_snd_play_effect_tone(pcall_core->papp_snd, VOICE_CALL_SND_EFFECT_CALL_DISCONNECT)) {
781                 CALL_ENG_DEBUG(ENG_DEBUG, "Effect tone not played, check and play busy tone");
782         }
783         if ((FALSE == voicecall_core_is_connected_call_exist(pcall_engine))
784             && (TRUE == voicecall_core_is_incoming_call_exists(pcall_engine))
785             && (voicecall_snd_get_path_status(pcall_core->papp_snd) == VOICE_CALL_SND_PATH_SPEAKER)) {
786                 CALL_ENG_DEBUG(ENG_DEBUG, "Incoming Call: TRUE,Connected Call:FALSE, Speaker: TRUE. So change path to normal");
787                 voicecall_snd_set_path_status(pcall_core->papp_snd, VOICE_CALL_SND_PATH_RECEIVER_EARJACK);
788                 voicecall_snd_change_path(pcall_core->papp_snd);
789         }
790
791         voicecall_core_clear_connected_call(pcall_engine, call_handle);
792
793         voicecall_core_get_total_call_member(pcall_engine, &total_call_member);
794         if (0 == total_call_member) {
795                 voicecall_core_set_to_default(pcall_core);
796         }
797
798 }
799
800 static gboolean __voicecall_core_handle_rejected_call_end(call_vc_core_state_t *pcall_core, int call_handle)
801 {
802         voicecall_engine_t *pcall_engine = pcall_core->pcall_engine;
803
804         voicecall_snd_stop_alert(pcall_core->papp_snd);
805
806         /*Send Incoming call End Event to Blue Tooth */
807         _vc_bt_send_response_to_bt(pcall_core, BT_AG_RES_CALL_END, call_handle, NULL);
808
809         if (FALSE == voicecall_core_is_connected_call_exist(pcall_engine)) {
810                 CALL_ENG_DEBUG(ENG_DEBUG, "No More Calls");
811                 voicecall_core_set_to_default(pcall_core);
812         } else {
813                 CALL_ENG_DEBUG(ENG_DEBUG, "Setting Path for Voicecall");
814                 /*Change Path to Call, when the incomging call is cancelled. */
815                 voicecall_snd_change_path(pcall_core->papp_snd);
816                 _vc_core_util_set_call_status(VCONFKEY_CALL_VOICE_ACTIVE);
817         }
818
819         CALL_ENG_DEBUG(ENG_DEBUG, "Reject Call End Processed");
820         return TRUE;
821 }
822
823 static void __voicecall_core_handle_outgoingcall_end(call_vc_core_state_t *pcall_core, int call_handle, voice_call_end_cause_type_t end_cause_type)
824 {
825         gboolean bsignal_play = FALSE;
826         voicecall_engine_t *pcall_engine = pcall_core->pcall_engine;
827
828         CALL_ENG_DEBUG(ENG_DEBUG, "call_handle=:%d,end_cause=%d", call_handle, end_cause_type);
829         pcall_core->mo_end_call_handle = call_handle;
830         pcall_core->mo_end_cause_type = end_cause_type;
831
832         if (FALSE == voicecall_core_is_connected_call_exist(pcall_engine)) {
833                 voicecall_snd_signal_type_t end_signal_type = VOICE_CALL_SIGNAL_NONE;
834                 /*Play Signal Tone only when the connected calls are not exists */
835                 end_signal_type = __voicecall_core_get_signal_type_from_endcause(end_cause_type);
836
837                 if (end_signal_type != VOICE_CALL_SIGNAL_NONE) {
838                         voicecall_snd_set_signal_type(pcall_core->papp_snd, end_signal_type);
839                         voicecall_snd_play_signal(pcall_core->papp_snd, __voicecall_core_mocall_signal_play_end_cb, pcall_core);
840                         bsignal_play = TRUE;
841
842                         /* signal tone play case : just end string updated */
843                         {
844                                 vc_engine_outgoing_end_signal_play_type event_data;
845
846                                 /* normal outgong end */
847                                 CALL_ENG_DEBUG(ENG_DEBUG, "It is normal outgong end case.");
848                                 CALL_ENG_DEBUG(ENG_DEBUG, "call_handle:[%d],end_cause_type:[%d]", call_handle, pcall_core->mo_end_cause_type);
849
850                                 memset(&event_data, 0, sizeof(event_data));
851                                 event_data.call_handle = call_handle;
852                                 event_data.end_cause_type = pcall_core->mo_end_cause_type;
853                                 vcall_engine_send_event_to_client(VC_ENGINE_MSG_OUTGOING_END_SIGNAL_PLAY_TO_UI, (void *)&event_data);
854                         }
855
856                 }
857         } else {
858                 CALL_ENG_DEBUG(ENG_DEBUG, "Connected call exists, not playing signal tone");
859         }
860         if (TRUE == voicecall_core_is_connected_call_exist(pcall_engine)) {
861                 /* Set phonestatus value */
862                 _vc_core_util_set_call_status(VCONFKEY_CALL_VOICE_ACTIVE);
863         } else if (FALSE == bsignal_play) {
864                 /*Reset the Path Actual path must be closed when modem path closed!! */
865                 _vc_core_util_set_call_status(VCONFKEY_CALL_OFF);
866         } else {
867                 /* othing to do. */
868         }
869         __voicecall_core_processing_mo_cancel(pcall_core);
870
871 }
872
873 static gboolean __voicecall_core_handle_incoming_call_end(call_vc_core_state_t *pcall_core, int call_handle)
874 {
875         voicecall_engine_t *pcall_engine = pcall_core->pcall_engine;
876
877         voicecall_snd_stop_alert(pcall_core->papp_snd);
878
879         /*Send Incoming call End Event to Blue Tooth */
880         _vc_bt_send_response_to_bt(pcall_core, BT_AG_RES_CALL_END, call_handle, NULL);
881
882         if (FALSE == voicecall_core_is_connected_call_exist(pcall_engine)) {
883                 CALL_ENG_DEBUG(ENG_DEBUG, "No More Calls");
884                 voicecall_core_set_to_default(pcall_core);
885         } else {
886                 CALL_ENG_DEBUG(ENG_DEBUG, "Setting Path for Voicecall");
887                 /*Change Path to Call, when the incomging call is cancelled. */
888                 voicecall_snd_change_path(pcall_core->papp_snd);
889                 _vc_core_util_set_call_status(VCONFKEY_CALL_VOICE_ACTIVE);
890         }
891
892         CALL_ENG_DEBUG(ENG_DEBUG, "Incoming Call End Processed");
893         return TRUE;
894 }
895
896 static gboolean voicecall_core_cb(int event, int param1, int param2, void *param3, void *puser_data)
897 {
898         CALL_ENG_DEBUG(ENG_WARN, " Engine Event: %s(%d)", gszcall_engine_event[event], event);
899
900         call_vc_core_state_t *pcall_core = (call_vc_core_state_t *)puser_data;
901         voicecall_engine_t *pcall_engine = pcall_core->pcall_engine;
902
903         CALL_VC_DUMP_CALLDETAILS(&pcall_engine->call_manager);
904
905         switch (event) {
906         case VC_CALL_INCOM:
907                 {
908                         int call_handle = param1;
909                         char tel_number[VC_PHONE_NUMBER_LENGTH_MAX];
910                         gboolean bauto_reject = FALSE;
911                         gboolean bauto_reject_unknown = FALSE;
912                         gboolean restricted = FALSE;
913                         gboolean bcalling_namemode = FALSE;
914                         gboolean brejected_number = FALSE;
915                         vc_engine_incoming_type event_data;
916
917                         memset(&event_data, 0, sizeof(event_data));
918                         event_data.bday_remaining_days = -1;
919
920                         CALL_ENG_DEBUG(ENG_DEBUG, "tel_number:[%s]", (char *)param3);
921                         _vc_core_util_strcpy(tel_number, sizeof(tel_number), (char *)param3);
922
923                         /*Changing the path to headset/phone will be decided by user accept action.
924                            This will apply for second incoming call, if the first call was accpeted by BT Headset
925                            and the path was changed to BT headset, then the path will be in headset for second call by default
926                            So reset the headset flag for second call so the path will not
927                            be automatically changed to headset, it will be decided by user action.
928                            If this requirement fits only for first incoming call then comment this fix. */
929                         /* vcui_app_snd_set_status(papp_document->papp_snd, VCUI_APP_AUDIO_HEADSET, FALSE); */
930
931                         /*Will be set based on user action */
932                         voicecall_core_set_status(pcall_core, CALL_VC_CORE_FLAG_ACCEPT_BY_BT, FALSE);
933
934                         if (_vc_core_util_check_video_call_status() == TRUE) {
935                                 /*Check for Lawmo Lock */
936                                 if (TRUE == __voicecall_core_silent_reject_mt(pcall_core, call_handle)) {
937                                         CALL_ENG_DEBUG(ENG_DEBUG, "Call rejected due to silent reject");
938                                         return TRUE;
939                                 }
940                         }
941
942                         /* Check for Restricted Mode */
943                         _vc_core_engine_status_isrestricted_call(pcall_engine, call_handle, &restricted);
944                         _vc_core_engine_status_get_calling_namemode(pcall_engine, call_handle, &bcalling_namemode);
945                         if (TRUE == bcalling_namemode) {
946                                 call_vc_call_objectinfo_t call_object;
947
948                                 voicecall_core_get_call_object(pcall_engine, call_handle, &call_object);
949                                 CALL_ENG_DEBUG(ENG_DEBUG, "call_object.calling_name:[%s]", call_object.calling_name);
950
951                                 _vc_core_util_strcpy(event_data.call_name, sizeof(event_data.call_name), call_object.calling_name);
952                         } else if (TRUE == restricted) {
953                                 call_vc_call_objectinfo_t call_object;
954
955                                 voicecall_core_get_call_object(pcall_engine, call_handle, &call_object);
956                                 CALL_ENG_DEBUG(ENG_DEBUG, "call_object.name_mode:[%s]", call_object.name_mode);
957
958                                 event_data.brestricted = TRUE;
959                                 if (call_object.name_mode == CALL_VC_NAME_MODE_PAYPHONE) {
960                                         event_data.bpayphone = TRUE;
961                                 } else {
962                                         event_data.bpayphone = FALSE;
963
964                                 }
965                                 event_data.contact_index = -1;
966                                 event_data.phone_type = -1;
967                         } else {
968                                 voicecall_contact_info_t ct_info;
969                                 memset(&ct_info, 0, sizeof(ct_info));
970                                 ct_info.ct_index = -1;
971
972                                 voicecall_service_contact_info_by_number(tel_number, &ct_info);
973
974                                 _vc_core_util_strcpy(event_data.call_name, sizeof(event_data.call_name), ct_info.display_name);
975                                 _vc_core_util_strcpy(event_data.call_file_path, sizeof(event_data.call_file_path), ct_info.caller_id_path);
976                                 _vc_core_util_strcpy(event_data.call_full_file_path, sizeof(event_data.call_full_file_path), ct_info.caller_full_id_path);
977                                 event_data.contact_index = ct_info.ct_index;
978                                 event_data.phone_type = ct_info.phone_type;
979                                 event_data.bday_remaining_days = ct_info.bday_remaining_days;
980
981                                 voicecall_snd_mgr_t *papp_snd = pcall_core->papp_snd;
982                                 char ringtone_path[VOICE_CALL_SND_RINGTONE_PATH_LEN] = { 0, };
983                                 memset(papp_snd->ring_tone, 0, VOICE_CALL_SND_RINGTONE_PATH_LEN);
984                                 if (TRUE == g_file_test(ct_info.ring_tone, G_FILE_TEST_EXISTS)) {
985                                         snprintf(ringtone_path, sizeof(ringtone_path), "file://%s", ct_info.ring_tone);
986                                         _vc_core_util_strcpy(papp_snd->ring_tone, VOICE_CALL_SND_RINGTONE_PATH_LEN, ringtone_path);
987                                         CALL_ENG_DEBUG(ENG_DEBUG, "From Contact Ringtone: %s", papp_snd->ring_tone);
988                                 } else {
989                                         /*Get Ringtone File From Settings */
990                                         CALL_ENG_DEBUG(ENG_DEBUG, "Invalid Ringtone from Contact: %s", ct_info.ring_tone);
991                                 }
992                         }
993
994                         /*Auto Reject Check */
995                         if (vconf_get_bool(VCONFKEY_CISSAPPL_AUTO_REJECT_BOOL, &bauto_reject)) {
996                                 CALL_ENG_DEBUG(ENG_ERR, "vconf_get_bool failed.");
997                         }
998
999                         if (bauto_reject) {
1000                                 CALL_ENG_DEBUG(ENG_DEBUG, "** Auto Reject Enabled. **");
1001
1002                                 if (vconf_get_bool(VCONFKEY_CISSAPPL_AUTO_REJECT_UNKNOWN_BOOL, &bauto_reject_unknown)) {
1003                                         CALL_ENG_DEBUG(ENG_ERR, "vconf_get_bool failed.");
1004                                 }
1005                                 CALL_ENG_DEBUG(ENG_DEBUG, "bauto_reject_unknown:[%d]", bauto_reject_unknown);
1006
1007                                 if ((0 == strlen(tel_number)) && (TRUE == bauto_reject_unknown)) {
1008                                         brejected_number = 1;
1009                                         CALL_ENG_DEBUG(ENG_DEBUG, "Unknwon Rejected.");
1010                                 } else {
1011                                         phone_misc_h *handle = NULL;
1012
1013                                         handle = phone_misc_connect();
1014                                         if (handle == NULL) {
1015                                                 CALL_ENG_DEBUG(ENG_ERR, "misc connect fail");
1016                                                 brejected_number = FALSE;
1017                                         } else {
1018                                                 int ret = phone_misc_block_check(handle, tel_number);
1019                                                 if (ret > 0) {
1020                                                                 brejected_number = TRUE;
1021                                                 } else {
1022                                                         brejected_number = FALSE;
1023                                                 }
1024                                                 phone_misc_disconnect(handle);
1025                                                 handle = NULL;
1026                                         }
1027                                         CALL_ENG_DEBUG(ENG_DEBUG, "Call Log DB rejected:[%d]", brejected_number);
1028                                 }
1029                         }
1030
1031                         /* send to ui */
1032                         event_data.call_handle = call_handle;
1033                         event_data.brejected = brejected_number;
1034                         _vc_core_util_strcpy(event_data.call_num, sizeof(event_data.call_num), tel_number);
1035
1036                         vcall_engine_send_event_to_client(VC_ENGINE_MSG_INCOM_TO_UI, (void *)&event_data);
1037
1038                         {
1039                                 /* in case of rejected number, sound & callstatus is not processed */
1040                                 if (!brejected_number) {
1041                                         gboolean benabledTestMode = FALSE;
1042                                         voicecall_snd_register_cm(pcall_core->papp_snd);
1043
1044                                         /*Send Incoming Call Event to Blue Tooth */
1045                                         _vc_bt_send_response_to_bt(pcall_core, BT_AG_RES_CALL_INCOM, call_handle, tel_number);
1046
1047                                         _vc_core_util_set_call_status(VCONFKEY_CALL_VOICE_CONNECTING);
1048
1049                                         benabledTestMode = __vc_core_is_answermode_enabled_from_testmode();
1050                                         if ((TRUE == __vc_core_is_answermode_enabled()) || (TRUE == benabledTestMode)) {
1051                                                 CALL_ENG_DEBUG(ENG_DEBUG, "auto answer mode is enabled.");
1052                                                 __voicecall_core_start_auto_answer(pcall_core, benabledTestMode);
1053                                         }
1054
1055                                         CALL_ENG_DEBUG(ENG_DEBUG, "Preparing Sound ");
1056                                         voicecall_snd_prepare_alert(pcall_core->papp_snd, call_handle);
1057                                         if (FALSE == voicecall_core_is_connected_call_exist(pcall_core->pcall_engine)) {
1058                                                 CALL_ENG_DEBUG(ENG_DEBUG, "Changing MM Path just before playing the ring tone");
1059                                                 sound_manager_call_session_set_mode(pcall_core->papp_snd->psnd_session, SOUND_CALL_SESSION_MODE_RINGTONE);
1060                                         } else {
1061                                                 CALL_ENG_DEBUG(ENG_DEBUG, "2nd MT call alert.");
1062                                         }
1063                                         voicecall_snd_play_alert(pcall_core->papp_snd);
1064                                 }
1065                         }
1066                 }
1067                 break;
1068
1069         case VC_CALL_OUTGOING:
1070                 {
1071                         int call_handle = param1;
1072                         vc_engine_common_with_handle_type event_data;
1073                         memset(&event_data, 0, sizeof(event_data));
1074
1075                         CALL_ENG_DEBUG(ENG_DEBUG, "MO Call Start: Call handle %d", call_handle);
1076                 }
1077                 break;
1078
1079         case VC_CALL_OUTGOING_ORIG:
1080                 {
1081                         int call_handle = param1;
1082                         vc_engine_outgoing_orig_type event_data;
1083                         call_vc_call_objectinfo_t callobject_info;
1084
1085                         memset(&event_data, 0, sizeof(event_data));
1086                         event_data.call_handle = call_handle;
1087                         if (pcall_core->call_setup_info.call_type == VC_CALL_ORIG_TYPE_EMERGENCY) {
1088                                 event_data.bemergency = TRUE;
1089                         } else {
1090                                 event_data.bemergency = FALSE;
1091                         }
1092
1093                         CALL_ENG_DEBUG(ENG_DEBUG, "Call Handle = %d, bemergency:[%d]", event_data.call_handle, event_data.bemergency);
1094                         vcall_engine_send_event_to_client(VC_ENGINE_MSG_OUTGOING_ORIG_TO_UI, (void *)&event_data);
1095
1096                         g_set_path_timer_handler = g_timeout_add(SET_PATH_TIMER_VALUE, __voicecall_core_set_path_timer_cb, pcall_core);
1097
1098                         /*Send Event to Blue Tooth */
1099                         voicecall_core_get_call_object(pcall_engine, call_handle, &callobject_info);
1100                         _vc_bt_send_response_to_bt(pcall_core, BT_AG_RES_CALL_ORIG, call_handle, callobject_info.tel_number);
1101                 }
1102                 break;
1103
1104         case VC_CALL_OUTGOING_ALERT:
1105                 {
1106                         int call_handle = param1;
1107                         vc_engine_common_with_handle_type event_data;
1108
1109                         memset(&event_data, 0, sizeof(event_data));
1110
1111                         event_data.call_handle = call_handle;
1112
1113                         vcall_engine_send_event_to_client(VC_ENGINE_MSG_OUTGOING_ALERT_TO_UI, (void *)&event_data);
1114
1115                         /*Play Connected Effect Tone */
1116                         CALL_ENG_KPI("voicecall_snd_play_effect_tone start");
1117                         if (FALSE == voicecall_snd_play_effect_tone(pcall_core->papp_snd, VOICE_CALL_SND_EFFECT_CALL_CONNECT)) {
1118                                 CALL_ENG_DEBUG(ENG_DEBUG, "voicecall_snd_play_effect_tone return value is FALSE");
1119                                 voicecall_snd_change_path(pcall_core->papp_snd);
1120                         }
1121                         CALL_ENG_KPI("voicecall_snd_play_effect_tone done");
1122
1123                         CALL_ENG_KPI("_vc_bt_send_response_to_bt start");
1124                         _vc_bt_send_response_to_bt(pcall_core, BT_AG_RES_CALL_REMOTE_RINGING, call_handle, NULL);
1125                         CALL_ENG_KPI("_vc_bt_send_response_to_bt done");
1126                 }
1127                 break;
1128
1129         case VC_CALL_ANSWER_CNF:
1130                 {
1131                         CALL_ENG_DEBUG(ENG_DEBUG, "Answer confirm");
1132                         if (_vc_core_cm_get_call_member_count(&(pcall_engine->call_manager)) == 1) {
1133                                 CALL_ENG_DEBUG(ENG_DEBUG, "single call state");
1134                                 voicecall_snd_change_path(pcall_core->papp_snd);
1135                         }
1136                 }
1137                 break;
1138
1139         case VC_CALL_CONNECTED:
1140                 {
1141                         int call_handle = param1;
1142                         vc_engine_connected_type event_data;
1143                         int bstatus = FALSE;
1144
1145                         memset(&event_data, 0, sizeof(event_data));
1146
1147                         CALL_ENG_DEBUG(ENG_DEBUG, "Connected Call Handle : %d", call_handle);
1148
1149                         event_data.call_handle = call_handle;
1150                         event_data.bt_status = (int)_vc_bt_get_bt_status();
1151
1152                         vcall_engine_send_event_to_client(VC_ENGINE_MSG_CONNECTED_TO_UI, (void *)&event_data);
1153                         voicecall_snd_stop_alert(pcall_core->papp_snd); /* To stop alert in case of call accept by AT command */
1154                         voicecall_snd_change_path(pcall_core->papp_snd);
1155
1156                         /* Set phone-status value */
1157                         _vc_core_util_set_call_status(VCONFKEY_CALL_VOICE_ACTIVE);
1158
1159                         /* check minute minder */
1160                         if (vconf_get_bool(VCONFKEY_CISSAPPL_MINUTE_MINDER_BOOL, &bstatus)) {
1161                                 CALL_ENG_DEBUG(ENG_ERR, "vconf_get_bool failed.");
1162                         }
1163                         if (bstatus) {
1164                                 if (pcall_core->minute_minder_timer == 0) {
1165                                         pcall_core->minute_minder_timer = g_timeout_add(MINUTE_MINDER_TIMEOUT_VALUE, __voicecall_core_minute_minder, pcall_core);
1166                                 }
1167                         }
1168
1169                         /*Send Event to Blue Tooth */
1170                         _vc_bt_send_response_to_bt(pcall_core, BT_AG_RES_CALL_CONNECT, call_handle, NULL);
1171
1172                         /*Call is accepted, reset the flag */
1173                         voicecall_core_set_status(pcall_core, CALL_VC_CORE_FLAG_ACCEPT_BY_BT, FALSE);
1174
1175
1176                 }
1177                 break;
1178
1179         case VC_CALL_NORMAL_END:
1180                 {
1181                         int call_handle = param1;
1182                         voice_call_end_cause_type_t end_cause = param2;
1183                         vc_engine_normal_end_type event_data;
1184
1185                         memset(&event_data, 0, sizeof(event_data));
1186
1187                         CALL_ENG_DEBUG(ENG_DEBUG, "Normal End Call Handle : %d,End Cause=%d", call_handle, end_cause);
1188
1189                         event_data.call_handle = call_handle;
1190                         event_data.end_cause_type = end_cause;
1191
1192                         __voicecall_core_handle_normal_end(pcall_core, call_handle, end_cause);
1193
1194                         vcall_engine_send_event_to_client(VC_ENGINE_MSG_NORMAL_END_TO_UI, (void *)&event_data);
1195
1196                         /*Send Event to Blue Tooth */
1197                         _vc_bt_send_response_to_bt(pcall_core, BT_AG_RES_CALL_END, call_handle, NULL);
1198                 }
1199                 break;
1200
1201         case VC_CALL_INCOM_END:
1202                 {
1203                         int call_handle = param1;
1204                         vc_engine_common_with_handle_type event_data;
1205
1206                         memset(&event_data, 0, sizeof(event_data));
1207
1208                         CALL_ENG_DEBUG(ENG_DEBUG, "Incoming call End Call Handle: %d", call_handle);
1209
1210                         voicecall_core_set_status(pcall_core, CALL_VC_CORE_FLAG_ACCEPT_BY_BT, FALSE);
1211
1212                         if (TRUE == __voicecall_core_handle_call_end_on_silent_reject(pcall_core, call_handle)) {
1213                                 CALL_ENG_DEBUG(ENG_DEBUG, "Call end processed for silent reject:");
1214                                 return TRUE;
1215                         }
1216
1217                         event_data.call_handle = call_handle;
1218
1219                         __voicecall_core_handle_incoming_call_end(pcall_core, call_handle);
1220
1221                         vcall_engine_send_event_to_client(VC_ENGINE_MSG_INCOM_END_TO_UI, (void *)&event_data);
1222                 }
1223                 break;
1224
1225         case VC_CALL_INCOM_DROPPED:
1226                 {
1227                         CALL_ENG_DEBUG(ENG_DEBUG, "Check it. Not used");
1228                 }
1229                 break;
1230
1231         case VC_CALL_REJECTED_END:
1232                 {
1233                         int call_handle = param1;
1234                         vc_engine_common_with_handle_type event_data;
1235
1236                         memset(&event_data, 0, sizeof(event_data));
1237
1238                         CALL_ENG_DEBUG(ENG_DEBUG, "Rejected call End Call Handle: %d", call_handle);
1239
1240                         event_data.call_handle = call_handle;
1241
1242                         voicecall_core_set_status(pcall_core, CALL_VC_CORE_FLAG_ACCEPT_BY_BT, FALSE);
1243
1244                         __voicecall_core_handle_rejected_call_end(pcall_core, call_handle);
1245
1246                         vcall_engine_send_event_to_client(VC_ENGINE_MSG_REJECTED_END_TO_UI, (void *)&event_data);
1247                 }
1248                 break;
1249
1250         case VC_CALL_OUTGOING_END:
1251                 {
1252                         int call_handle = param1;
1253                         int end_cause_type = param2;
1254                         int bauto_redial = -1;
1255
1256                         CALL_ENG_DEBUG(ENG_DEBUG, "end cause type :[%d]", end_cause_type);
1257                         CALL_ENG_DEBUG(ENG_DEBUG, "bauto_redial:[%d]", bauto_redial);
1258
1259                         if ((TRUE == bauto_redial) && (FALSE == voicecall_core_is_connected_call_exist(pcall_engine))
1260                             && (FALSE == voicecall_core_get_status(pcall_core, CALL_VC_CORE_FLAG_MOCALL_END_BY_USER))
1261                             && (TRUE == __voicecall_core_is_redial_cuase(end_cause_type))) {
1262                                 /* auto redial */
1263                                 CALL_ENG_DEBUG(ENG_DEBUG, "It is auto redial case.");
1264
1265                                 _vc_core_util_set_call_status(VCONFKEY_CALL_OFF);
1266
1267                                 vc_engine_outgoing_end_type event_data;
1268
1269                                 memset(&event_data, 0, sizeof(event_data));
1270                                 event_data.call_handle = call_handle;
1271                                 event_data.end_cause_type = end_cause_type;
1272                                 event_data.bauto_redial = TRUE;
1273                                 vcall_engine_send_event_to_client(VC_ENGINE_MSG_OUTGOING_END_TO_UI, (void *)&event_data);
1274                         } else {
1275                                 __voicecall_core_handle_outgoingcall_end(pcall_core, call_handle, end_cause_type);
1276                         }
1277                 }
1278                 break;
1279
1280         case VC_CALL_OUTGOING_ABORTED:
1281                 {
1282                         vc_engine_common_type event_data;
1283
1284                         memset(&event_data, 0, sizeof(event_data));
1285
1286                         vcall_engine_send_event_to_client(VC_ENGINE_MSG_OUTGOING_ABORTED_TO_UI, (void *)&event_data);
1287                 }
1288                 break;
1289
1290         case VC_CALL_DTMF_ACK:
1291                 {
1292                         gboolean bsuccess = param1;
1293                         CALL_ENG_DEBUG(ENG_DEBUG, "bsuccess:[%d]", bsuccess);
1294                         __voicecall_core_handle_dtmf_ack(pcall_core, bsuccess);
1295                 }
1296                 break;
1297
1298         case VC_CALL_AUTO_REDIAL_CHECK:
1299                 {
1300                         CALL_ENG_DEBUG(ENG_DEBUG, "Check it. Not used");
1301                 }
1302                 break;
1303
1304         case VC_CALL_SS_HELD:
1305                 {
1306                         int call_handle = param1;
1307                         vc_engine_common_type event_data;
1308
1309                         /*  held popup shold not be displayed on outgoing popup */
1310                         memset(&event_data, 0, sizeof(event_data));
1311
1312                         vcall_engine_send_event_to_client(VC_ENGINE_MSG_SS_HELD_TO_UI, (void *)&event_data);
1313
1314                         /*Send Event to Blue Tooth */
1315                         _vc_bt_send_response_to_bt(pcall_core, BT_AG_RES_CALL_HOLD, call_handle, NULL);
1316                 }
1317                 break;
1318
1319         case VC_CALL_SS_RETREIVED:
1320                 {
1321                         int call_handle = param1;
1322                         vc_engine_common_type event_data;
1323
1324                         /*  held popup shold not be displayed on outgoing popup */
1325                         memset(&event_data, 0, sizeof(event_data));
1326                         vcall_engine_send_event_to_client(VC_ENGINE_MSG_SS_RETREIVED_TO_UI, (void *)&event_data);
1327
1328                         /*Send Event to Blue Tooth */
1329                         _vc_bt_send_response_to_bt(pcall_core, BT_AG_RES_CALL_RETRIEVE, call_handle, NULL);
1330                 }
1331                 break;
1332
1333         case VC_CALL_SS_SWAP:
1334                 {
1335                         vc_engine_common_type event_data;
1336
1337                         int call_handle = param1;
1338
1339                         memset(&event_data, 0, sizeof(event_data));
1340
1341                         /* Show Call Swapped Message Box */
1342                         vcall_engine_send_event_to_client(VC_ENGINE_MSG_SS_SWAP_TO_UI, (void *)&event_data);
1343
1344                         _vc_bt_send_response_to_bt(pcall_core, BT_AG_RES_CALL_SWAPPED, call_handle, NULL);
1345                 }
1346                 break;
1347
1348         case VC_CALL_SS_SETUP_CONF:
1349                 {
1350                         vc_engine_common_type event_data;
1351
1352                         memset(&event_data, 0, sizeof(event_data));
1353
1354                         /* Show Call Joined Message Box */
1355                         vcall_engine_send_event_to_client(VC_ENGINE_MSG_SS_SETUP_CONF_TO_UI, (void *)&event_data);
1356
1357                         _vc_bt_send_response_to_bt(pcall_core, BT_AG_RES_CALL_JOINED, 0, NULL);
1358                 }
1359                 break;
1360
1361         case VC_CALL_SS_SPLIT_CONF:
1362                 {
1363                         vc_engine_common_with_handle_type event_data;
1364                         int call_handle = param1;
1365                         CALL_ENG_DEBUG(ENG_DEBUG, "The handle to be split is %d", call_handle);
1366
1367                         memset(&event_data, 0, sizeof(event_data));
1368                         event_data.call_handle = call_handle;
1369
1370                         /* Show Private Call Message Box */
1371                         vcall_engine_send_event_to_client(VC_ENGINE_MSG_SS_SPLIT_CONF_TO_UI, (void *)&event_data);
1372                 }
1373                 break;
1374
1375         case VC_CALL_SS_TRANSFERRED:
1376                 {
1377                         vc_engine_common_type event_data;
1378
1379                         memset(&event_data, 0, sizeof(event_data));
1380
1381                         vcall_engine_send_event_to_client(VC_ENGINE_MSG_SS_TRANSFERRED_TO_UI, (void *)&event_data);
1382                 }
1383                 break;
1384
1385         case VC_CALL_SS_CONNECT_LINE_IND:
1386                 {
1387                         int call_handle = param1;
1388                         char *pconnected_number = (char *)param3;
1389                         vc_engine_msg_box_type event_data;
1390
1391                         CALL_ENG_DEBUG(ENG_DEBUG, "call_handle : [%d]", call_handle);
1392
1393                         /* check whether Call Info for recevice Call Handle exists or not. */
1394
1395                         if ((pconnected_number != NULL) && (strlen(pconnected_number) > 0)) {
1396                                 CALL_ENG_DEBUG(ENG_DEBUG, "connected line ind : [%s]", pconnected_number);
1397
1398                                 memset(&event_data, 0, sizeof(event_data));
1399
1400                                 event_data.string_id = IDS_CALL_POP_CALL_IS_DIVERTED;
1401                                 _vc_core_util_strcpy(event_data.diverted_num, sizeof(event_data.diverted_num), pconnected_number);
1402                         } else {
1403                                 CALL_ENG_DEBUG(ENG_DEBUG, "No conneccted info");
1404                         }
1405
1406                 }
1407                 break;
1408
1409         case VC_CALL_IND_FORWARD:
1410                 {
1411                         vc_engine_ind_forward_type event_data;
1412                         int fwd_type = param1;
1413
1414                         memset(&event_data, 0, sizeof(event_data));
1415                         event_data.fwd_type = fwd_type;
1416
1417                         vcall_engine_send_event_to_client(VC_ENGINE_MSG_IND_FORWARD_TO_UI, (void *)&event_data);
1418                 }
1419                 break;
1420
1421         case VC_CALL_IND_ACTIVATE:
1422                 {
1423                         vc_engine_common_type event_data;
1424
1425                         memset(&event_data, 0, sizeof(event_data));
1426
1427                         vcall_engine_send_event_to_client(VC_ENGINE_MSG_IND_ACTIVATE_TO_UI, (void *)&event_data);
1428                 }
1429                 break;
1430
1431         case VC_CALL_IND_HOLD:
1432                 {
1433                         vc_engine_common_type event_data;
1434                         int call_handle = param1;
1435
1436                         memset(&event_data, 0, sizeof(event_data));
1437
1438                         vcall_engine_send_event_to_client(VC_ENGINE_MSG_IND_HOLD_TO_UI, (void *)&event_data);
1439
1440                         /*Send Event to Blue Tooth */
1441                         _vc_bt_send_response_to_bt(pcall_core, BT_AG_RES_CALL_HOLD, call_handle, NULL);
1442                 }
1443                 break;
1444
1445         case VC_CALL_IND_TRANSFER:
1446                 {
1447                         CALL_ENG_DEBUG(ENG_DEBUG, "Not used.");
1448                 }
1449                 break;
1450
1451         case VC_CALL_IND_SETUPCONFERENCE:
1452                 {
1453                         CALL_ENG_DEBUG(ENG_DEBUG, "Not used.");
1454                 }
1455                 break;
1456
1457         case VC_CALL_IND_BARRING:
1458                 {
1459                         vc_engine_common_type event_data;
1460
1461                         memset(&event_data, 0, sizeof(event_data));
1462
1463                         vcall_engine_send_event_to_client(VC_ENGINE_MSG_IND_BARRING_TO_UI, (void *)&event_data);
1464                 }
1465                 break;
1466
1467         case VC_CALL_IND_WAITING:
1468                 {
1469                         vc_engine_common_type event_data;
1470
1471                         memset(&event_data, 0, sizeof(event_data));
1472
1473                         vcall_engine_send_event_to_client(VC_ENGINE_MSG_IND_WAITING_TO_UI, (void *)&event_data);
1474                 }
1475                 break;
1476
1477         case VC_CALL_IND_CUGINFO:
1478                 {
1479                         CALL_ENG_DEBUG(ENG_DEBUG, "Not used.");
1480                 }
1481                 break;
1482
1483         case VC_CALL_IND_SSNOTIFY:
1484                 {
1485                         vc_engine_ind_ssnotify_type event_data;
1486                         int ss_type = param1;
1487
1488                         memset(&event_data, 0, sizeof(event_data));
1489                         event_data.ss_type = ss_type;
1490
1491                         vcall_engine_send_event_to_client(VC_ENGINE_MSG_IND_SSNOTIFY_TO_UI, (void *)&event_data);
1492                 }
1493                 break;
1494
1495         case VC_CALL_IND_CALLINGNAMEINFO:
1496                 {
1497                         CALL_ENG_DEBUG(ENG_DEBUG, "Not used.");
1498                 }
1499                 break;
1500         case VC_CALL_IND_ACTIVATECCBS_CNF:
1501                 {
1502                         CALL_ENG_DEBUG(ENG_DEBUG, "Not used.");
1503                 }
1504                 break;
1505
1506         case VC_CALL_IND_ACTIVATECCBS_USERINFO:
1507                 {
1508                         CALL_ENG_DEBUG(ENG_DEBUG, "Not used.");
1509                 }
1510                 break;
1511
1512         case VC_CALL_IND_AOC:
1513                 {
1514                         CALL_ENG_DEBUG(ENG_DEBUG, "Not yet.");
1515                 }
1516                 break;
1517
1518         case VC_ERROR_OCCURED:
1519                 {
1520                         int error_code = param1;
1521
1522                         CALL_ENG_DEBUG(ENG_DEBUG, "error code:[%d]", error_code);
1523                         switch (error_code) {
1524                         case ERROR_VOICECALL_INVALID_DTMF_CHAR:
1525                         case ERROR_VOICECALL_DTMF_FAILED:
1526                                 {
1527                                         vc_engine_error_occured_type event_data;
1528
1529                                         memset(&event_data, 0, sizeof(event_data));
1530                                         event_data.error_code = error_code;
1531
1532                                         vcall_engine_send_event_to_client(VC_ENGINE_MSG_ERROR_OCCURED_TO_UI, (void *)&event_data);
1533                                 }
1534                                 break;
1535                         default:
1536                                 {
1537                                         vc_engine_msg_box_type event_data;
1538                                         int string_id = -1;
1539
1540                                         string_id = __voicecall_core_get_string_id_by_errorcode(error_code);
1541
1542                                         memset(&event_data, 0, sizeof(event_data));
1543                                         event_data.string_id = __voicecall_core_get_string_id_by_errorcode(error_code);
1544
1545                                         vcall_engine_send_event_to_client(VC_ENGINE_MSG_MESSAGE_BOX_TO_UI, (void *)&event_data);
1546                                 }
1547                                 break;
1548                         }
1549                 }
1550                 break;
1551
1552         case VC_ACTION_INCOM_FORCE:
1553                 {
1554                         int call_handle = param1;
1555                         vc_engine_common_with_handle_type event_data;
1556
1557                         CALL_ENG_DEBUG(ENG_DEBUG, "Call Handle = %d", call_handle);
1558
1559                         memset(&event_data, 0, sizeof(event_data));
1560                         event_data.call_handle = call_handle;
1561
1562                         vcall_engine_send_event_to_client(VC_ENGINE_MSG_ACTION_INCOM_FORCE_TO_UI, (void *)&event_data);
1563                 }
1564                 break;
1565
1566         case VC_ACTION_SAT_REQUEST:
1567                 {
1568                         if (SAT_RQST_SETUP_CALL == param1) {
1569                                 voicecall_sat_callinfo_t *psat_callinfo = (voicecall_sat_callinfo_t *) param3;
1570                                 vc_engine_outgoing_type event_data;
1571
1572                                 if (psat_callinfo == NULL) {
1573                                         CALL_ENG_DEBUG(ENG_ERR, "psat_callinfo is NULL..");
1574                                         assert(psat_callinfo != NULL);
1575                                 } else {
1576                                         CALL_ENG_DEBUG(ENG_DEBUG, "VC_ACTION_SAT_REQUEST is received by Voice call.");
1577                                         pcall_core->call_setup_info.call_setup_by = VC_CALL_SETUP_BY_SAT;
1578                                         pcall_core->call_setup_info.call_type = VC_CALL_ORIG_TYPE_SAT;
1579
1580                                         /*Phone Number */
1581                                         _vc_core_util_strcpy(pcall_core->call_setup_info.source_tel_number, VC_PHONE_NUMBER_LENGTH_MAX, psat_callinfo->call_number);
1582                                         _vc_core_engine_extract_phone_number(pcall_core->call_setup_info.source_tel_number, pcall_core->call_setup_info.tel_number, VC_PHONE_NUMBER_LENGTH_MAX);
1583
1584                                         /*Name */
1585                                         CALL_ENG_DEBUG(ENG_ERR, "psat_callinfo->disp_text:[%s]", psat_callinfo->disp_text);
1586
1587                                         memset(&event_data, 0, sizeof(event_data));
1588                                         _vc_core_util_strcpy(event_data.call_num, sizeof(event_data.call_num), pcall_core->call_setup_info.tel_number);
1589                                         event_data.contact_index = -1;
1590                                         event_data.phone_type = -1;
1591                                         event_data.bday_remaining_days = -1;
1592                                         _vc_core_util_strcpy(event_data.call_num, sizeof(event_data.call_num), psat_callinfo->disp_text);
1593
1594                                         vcall_engine_send_event_to_client(VC_ENGINE_MSG_OUTGOING_TO_UI, (void *)&event_data);
1595
1596                                         /*Get Icon Information */
1597                                         if (TRUE == psat_callinfo->bicon_present) {     /*bicon_present is TRUE when SAT icon info available and when GCF is enabled */
1598                                                 CALL_ENG_DEBUG(ENG_ERR, "SAT icon available.");
1599                                         }
1600
1601                                         /* Prepare and Make Call with the Give Information */
1602                                         if (FALSE == voicecall_core_setup_call(pcall_core, FALSE)) {
1603                                                 /*Send Response to SAT Engine */
1604                                                 voicecall_core_send_sat_response(pcall_core->pcall_engine, SAT_RQST_SETUP_CALL, CALL_VC_ME_UNABLE_TO_PROCESS_COMMAND);
1605                                         }
1606                                 }
1607                         } else if (SAT_RQST_SEND_DTMF == param1) {
1608                                 voicecall_sat_callinfo_t *psat_callinfo = (voicecall_sat_callinfo_t *) param3;
1609
1610                                 CALL_ENG_DEBUG(ENG_DEBUG, "SAT Send DTMF Number: %s, hidden: %d", psat_callinfo->call_number, psat_callinfo->bsat_hidden);
1611                                 __voicecall_core_queue_dtmf_string(pcall_core, psat_callinfo->call_number, TRUE);
1612                         } else {
1613                                 CALL_ENG_DEBUG(ENG_ERR, "Invalid SAT Request Type: %d", param2);
1614                         }
1615                 }
1616                 break;
1617
1618         case VC_ACTION_SAT_RESPONSE:
1619                 {
1620                         if (SAT_RESP_SETUP_CALL == param1) {
1621                                 voicecall_sat_callinfo_t *psat_call_info = (voicecall_sat_callinfo_t *) param3;
1622
1623                                 CALL_ENG_DEBUG(ENG_DEBUG, "sat_mo_call_ctrl_res = %d", psat_call_info->sat_mo_call_ctrl_res);
1624
1625                                 if (CALL_NOT_ALLOWED == psat_call_info->sat_mo_call_ctrl_res) {
1626                                         vc_engine_msg_box_type event_data;
1627
1628                                         memset(&event_data, 0, sizeof(event_data));
1629                                         event_data.string_id = IDS_CALL_POP_CALLNOTCALLOWED;
1630                                         vcall_engine_send_event_to_client(VC_ENGINE_MSG_MESSAGE_BOX_TO_UI, (void *)&event_data);
1631                                 } else if (CALL_ALLOWED_WITH_MOD == psat_call_info->sat_mo_call_ctrl_res) {
1632                                         CALL_ENG_DEBUG(ENG_DEBUG, "psat_call_info->call_number = [%s]", psat_call_info->call_number);
1633                                         CALL_ENG_DEBUG(ENG_DEBUG, "psat_call_info->disp_text = [%s]", psat_call_info->disp_text);
1634 #ifdef _OLD_SAT_
1635                                         mocall_index = vcui_app_doc_get_mocall_index(papp_document);
1636
1637                                         /*Update MO CALL Display Data with the SAT modified info */
1638                                         if (mocall_index != -1) {
1639                                                 vcui_app_call_display_data_t display_data;
1640                                                 vcui_app_call_display_data_t new_display_data;
1641                                                 vcui_app_view_mo_state_t *pmo_state = NULL;
1642
1643                                                 if (FALSE == vcui_app_cdm_get_display_object_byindex(&papp_document->call_display_manager, mocall_index, &display_data)) {
1644                                                         return TRUE;
1645                                                 }
1646
1647                                                 vcui_app_cdm_clear_display_object(&new_display_data);
1648
1649                                                 /*Copy all must parameters required for MO Call */
1650                                                 new_display_data.call_handle = display_data.call_handle;
1651                                                 new_display_data.call_index = display_data.call_index;
1652                                                 new_display_data.call_type = display_data.call_type;
1653                                                 new_display_data.start_time = display_data.start_time;
1654                                                 new_display_data.used = display_data.used;
1655
1656                                                 if (strlen(psat_call_info->call_number) > 0) {
1657                                                         vcui_app_util_strcpy(new_display_data.source_tel_number, sizeof(new_display_data.source_tel_number), psat_call_info->call_number);
1658                                                         _vc_core_engine_extract_phone_number(new_display_data.source_tel_number, new_display_data.tel_number, VC_PHONE_NUMBER_LENGTH_MAX);
1659                                                 }
1660
1661                                                 if (strlen(psat_call_info->disp_text) > 0) {
1662                                                         vcui_app_util_strcpy(new_display_data.name, sizeof(new_display_data.name), psat_call_info->disp_text);
1663                                                 }
1664
1665                                                 /*todo, Check whether contact search need to be done for the SAT modified number */
1666
1667                                                 /*Set the newly modified data to the CDM */
1668                                                 vcui_app_cdm_set_display_object(pdisplay_mgr, &new_display_data);
1669
1670                                                 /*Update the MO View */
1671                                                 pmo_state = (vcui_app_view_mo_state_t *) calloc(1, sizeof(vcui_app_view_mo_state_t));
1672                                                 pmo_state->mo_call_state = VCUI_MO_CALL_STATE_UPDATE;
1673
1674                                                 /* Update MO Call Screen View to update the connection status */
1675                                                 dv_view_manager_update_view(dv_document_get_view_manager(DV_DOCUMENT(papp_document)), VCUI_APP_VIEWID_MO_VIEW, VCUI_APP_UPD_MO_SET_STATE, pmo_state);
1676
1677                                         } else {
1678                                                 VCUI_DEBUG(VCUI_LOG_ERR, "Invalid Mo Call Index: %d", mocall_index);
1679                                         }
1680 #endif
1681                                 } else if (CALL_CHANGED_TO_SS == psat_call_info->sat_mo_call_ctrl_res) {
1682                                         /*Issue notification to Launch SS */
1683                                 }
1684                         }
1685                 }
1686                 break;
1687
1688         case VC_ACTION_CALL_END_HELD_RETREIVED:
1689                 {
1690                         int call_handle = param1;
1691                         vc_engine_common_with_handle_type event_data;
1692
1693                         CALL_ENG_DEBUG(ENG_DEBUG, "call handle:[%d]", call_handle);
1694
1695                         memset(&event_data, 0, sizeof(event_data));
1696
1697                         vcall_engine_send_event_to_client(VC_ENGINE_MSG_ACTION_CALL_END_HELD_RETREIVED_TO_UI, (void *)&event_data);
1698                 }
1699                 break;
1700
1701         case VC_ACTION_NO_ACTIVE_TASK:
1702                 {
1703                         CALL_ENG_DEBUG(ENG_DEBUG, "Not yet.");
1704                 }
1705                 break;
1706
1707         case VC_CALL_GET_VOLUME_RESP:
1708                 {
1709                         vc_engine_vol_resp_type event_data;
1710
1711                         CALL_ENG_DEBUG(ENG_DEBUG, "Current Voicecall (TAPI)Volume Type %d, Current Volume Level: %d", param1, param2);
1712
1713                         memset(&event_data, 0, sizeof(event_data));
1714                         event_data.vol_alert_type = VOICE_CALL_VOL_TYPE_VOICE;
1715                         event_data.vol_level = param2;
1716                         vcall_engine_send_event_to_client(VC_ENGINE_MSG_GET_VOLUME_RESP_TO_UI, (void *)&event_data);
1717                 }
1718                 break;
1719
1720         case VC_CALL_NOTI_WBAMR:
1721                 {
1722                         vc_engine_wbamr_status_type event_data;
1723
1724                         CALL_ENG_DEBUG(ENG_DEBUG, "Current WBAmr status %d", param1);
1725
1726                         memset(&event_data, 0, sizeof(event_data));
1727                         event_data.bstatus = param1;
1728                         vcall_engine_send_event_to_client(VC_ENGINE_MSG_NOTI_WBAMR_TO_UI, (void *)&event_data);
1729                 }
1730                 break;
1731
1732         default:
1733                 CALL_ENG_DEBUG(ENG_DEBUG, " Engine Event ID : %d not handled", event);
1734                 break;
1735         }
1736
1737         CALL_VC_DUMP_CALLDETAILS(&pcall_engine->call_manager);
1738
1739         CALL_ENG_DEBUG(ENG_DEBUG, " Ended.");
1740
1741         return TRUE;
1742 }
1743
1744 /**
1745  * This function converts Error Code to string id.
1746  *
1747  * @return              string id
1748  * @param[in]           error_code              error code to be used to display the message content
1749  */
1750 static int __voicecall_core_get_string_id_by_errorcode(int error_code)
1751 {
1752         int string_id = -1;
1753         switch (error_code) {
1754         case ERROR_VOICECALL_DTMF_FAILED:
1755                 string_id = IDS_CALL_POP_DTMFSENDING_FAIL;
1756                 break;
1757
1758         case ERROR_VOICECALL_CALL_NOT_ALLOWED:
1759                 string_id = IDS_CALL_POP_CALLNOTCALLOWED;
1760                 break;
1761
1762         case ERROR_VOICECALL_CALL_IMPOSSIBLE_NOSIM_NOEMERGNUM:
1763                 string_id = IDS_CALL_POP_SOS_CALL_ONLY_IN_NO_SIM_MODE;
1764                 break;
1765
1766         case ERROR_VOICECALL_EMERGENCY_CALLS_ONLY:
1767                 string_id = IDS_CALL_POP_CALLING_EMERG_ONLY;
1768                 break;
1769
1770         case ERROR_VOICECALL_PHONE_NOT_INITIALIZED:
1771                 string_id = IDS_CALL_POP_PHONE_NOT_INITIALISED;
1772                 break;
1773
1774         case ERROR_VOICECALL_ANSWER_FAILED:
1775                 string_id = IDS_CALL_POP_CALLFAILED;
1776                 break;
1777
1778         case ERROR_VOICECALL_HOLD_REJECTED:
1779         case ERROR_VOICECALL_HOLD_FAILED:
1780                 string_id = IDS_CALL_POP_HOLD_FAILED;
1781                 break;
1782
1783         case ERROR_VOICECALL_ACTIVATE_REJECTED:
1784         case ERROR_VOICECALL_RETREIVE_FAILED:
1785                 string_id = IDS_CALL_POP_UNABLE_TO_RETRIEVE;
1786                 break;
1787
1788         case ERROR_VOICECALL_SWAP_REJECTED:
1789         case ERROR_VOICECALL_SWAP_FAILED:
1790                 string_id = IDS_CALL_POP_SWAP_FAILED;
1791                 break;
1792
1793         case ERROR_VOICECALL_SPLIT_CONF_FAILED:
1794                 string_id = IDS_CALL_POP_SPLIT_FAILED;
1795                 break;
1796
1797         case ERROR_VOICECALL_SETUP_CONF_FAILED:
1798                 string_id = IDS_CALL_POP_JOIN_FAILED;
1799                 break;
1800
1801         case ERROR_VOICECALL_TRANSFER_FAILED:
1802                 string_id = IDS_CALL_POP_TRANSFER_FAILED;
1803                 break;
1804
1805         case ERROR_VOICECALL_SWAP_NOT_SUPPORTED:
1806                 string_id = IDS_CALL_POP_SWAP_NOT_SUPPORTED;
1807                 break;
1808
1809         case ERROR_VOICECALL_HOLD_NOT_SUPPORTED:
1810                 string_id = IDS_CALL_POP_HOLD_NOT_SUPPORTED;
1811                 break;
1812
1813         case ERROR_VOICECALL_RETREIVE_NOT_SUPPORTED:
1814                 string_id = IDS_CALL_POP_UNHOLD_NOT_SUPPORTED;
1815                 break;
1816
1817         case ERROR_VOICECALL_SETUP_CONF_NOT_SUPPORTED:
1818                 string_id = IDS_CALL_POP_JOIN_NOT_SUPPORTED;
1819                 break;
1820
1821         case ERROR_VOICECALL_SPLIT_CONF_NOT_SUPPORTED:
1822                 string_id = IDS_CALL_POP_SPLIT_NOT_SUPPORTED;
1823                 break;
1824         case ERROR_VOICECALL_TRANSFER_NOT_SUPPORTED:
1825                 string_id = IDS_CALL_POP_TRANSFER_NOT_SUPPORTED;
1826                 break;
1827
1828         case ERROR_VOICECALL_INCOMPLETE:
1829                 string_id = IDS_CALL_POP_INCOMPLETE;
1830                 break;
1831
1832         case ERROR_VOICECALL_UNAVAILABLE:
1833                 string_id = IDS_CALL_POP_UNAVAILABLE;
1834                 break;
1835
1836         case ERROR_VOICECALL_TAPI_CAUSE_CALL_FAILED:
1837                 string_id = IDS_CALL_POP_CALLFAILED;
1838                 break;
1839
1840         case ERROR_VOICECALL_INVALID_CALL_TYPE:
1841         case ERROR_VOICECALL_INVALID_TELEPHONE_NUMBER:
1842                 string_id = IDS_CALL_POP_CAUSE_WRONG_NUMBER;
1843                 break;
1844
1845         default:
1846                 CALL_ENG_DEBUG(ENG_DEBUG, " Invalid Error Code: %x", error_code);
1847                 string_id = IDS_CALL_POP_CALLFAILED;
1848                 break;
1849         }
1850         return string_id;
1851 }
1852
1853 gboolean voicecall_core_set_to_default(call_vc_core_state_t *pcall_core)
1854 {
1855         CALL_ENG_DEBUG(ENG_DEBUG, "");
1856         if (pcall_core->pcall_engine == NULL)
1857                 return FALSE;
1858
1859         /*Set Engine states to default */
1860         _vc_core_engine_set_to_default_values(pcall_core->pcall_engine);
1861
1862         /*Initialize MO Call Setup Info */
1863         pcall_core->call_setup_info.mo_call_index = VC_TAPI_INVALID_CALLHANDLE;
1864         pcall_core->call_setup_info.call_setup_by = VC_CALL_SETUP_BY_NORMAL;
1865
1866         pcall_core->call_setup_info.mo_call_index = VC_TAPI_INVALID_CALLHANDLE;
1867         pcall_core->call_setup_info.call_setup_by = VC_CALL_SETUP_BY_NORMAL;
1868         memset(pcall_core->call_setup_info.tel_number, 0, sizeof(pcall_core->call_setup_info.tel_number));
1869
1870         pcall_core->mo_redial_timer = -1;
1871         __vc_core_set_auto_redial_count(pcall_core, 0);
1872
1873         _vc_core_util_set_call_status(VCONFKEY_CALL_OFF);
1874         voicecall_core_set_status(pcall_core, CALL_VC_CORE_FLAG_NONE, TRUE);
1875
1876         pcall_core->bt_connected = _vc_bt_get_bt_status();
1877         if (FALSE == pcall_core->bt_connected) {
1878                 voicecall_snd_set_path_status(pcall_core->papp_snd, VOICE_CALL_SND_PATH_RECEIVER_EARJACK);
1879         } else {
1880                 CALL_ENG_DEBUG(ENG_DEBUG, "BT connected, Not changing the sound status");
1881         }
1882
1883         /* sound reset */
1884         voicecall_snd_unregister_cm(pcall_core->papp_snd);
1885
1886         if (vconf_set_int(VCONFKEY_FACTORY_CALL_CONNECT_STATE, VCONFKEY_FACTORY_CALL_DISCONNECTED)) {
1887                 CALL_ENG_DEBUG(ENG_ERR, "vconf_set_int failed.");
1888         }
1889
1890         return TRUE;
1891 }
1892
1893 static void __voicecall_core_mocall_reset_engine_state(voicecall_engine_t *pcall_engine)
1894 {
1895         int eng_state = VC_INOUT_STATE_NONE;
1896
1897         voicecall_core_get_engine_state(pcall_engine, &eng_state);
1898
1899         CALL_ENG_DEBUG(ENG_DEBUG, "current engine state is: %d", eng_state);
1900
1901         if ((eng_state > VC_INOUT_STATE_OUTGOING_START) && (eng_state < VC_INOUT_STATE_OUTGOING_END)) {
1902                 voicecall_core_change_engine_state(pcall_engine, VC_INOUT_STATE_NONE);
1903         } else {
1904                 CALL_ENG_DEBUG(ENG_DEBUG, "Engine state is already changed, current engine state is: %d", eng_state);
1905                 CALL_VC_DUMP_CALLDETAILS(&pcall_engine->call_manager);
1906         }
1907 }
1908
1909 /**
1910  * This function initialize voicecall core
1911  *
1912  * @return              Returns TRUE on success or FALSE on failure
1913  * @param[in]           pcall_core              Handle to voicecall core
1914  * @param[in]           pcallback_func  callback function
1915  */
1916 int voicecall_core_init(call_vc_core_state_t *pcall_core)
1917 {
1918         voicecall_engine_t *pcall_engine = NULL;
1919
1920         if (ERROR_VOICECALL_NONE != _vc_core_engine_init(&pcall_engine, (voicecall_cb) voicecall_core_cb, pcall_core)) {
1921                 CALL_ENG_DEBUG(ENG_DEBUG, "Voicecall Engine Init Failed");
1922                 return FALSE;
1923         }
1924
1925         if (FALSE == voicecall_snd_init(pcall_core, &pcall_core->papp_snd)) {
1926                 CALL_ENG_DEBUG(ENG_DEBUG, "voicecall_snd_init() failed");
1927                 return FALSE;
1928         }
1929         /*Store Voicecall Engine Handle */
1930         pcall_core->pcall_engine = pcall_engine;
1931
1932         _vc_bt_status_init(pcall_core);
1933
1934         _voicecall_dvc_earjack_init(pcall_core);
1935
1936         voicecall_core_set_status(pcall_core, CALL_VC_CORE_FLAG_NONE, TRUE);
1937         return TRUE;
1938 }
1939
1940 /**
1941  * This function prepares a voice call with the given data
1942  *
1943  * @return              Returns TRUE on success or FALSE on failure
1944  * @param[in]           pcall_core              Handle to voicecall core
1945  * @param[in]           bemergency              emergency call or not from dialer
1946  * @param[in]
1947  */
1948 gboolean voicecall_core_setup_call(call_vc_core_state_t *pcall_core, gboolean bemergency)
1949 {
1950         voicecall_engine_t *pcall_engine = pcall_core->pcall_engine;
1951         voicecall_setup_info_t setupcall_info = { 0, };
1952         voicecall_error_t error_code = -1;
1953         gboolean bemergency_call = FALSE;
1954         gboolean bmocall_exists = FALSE;
1955         gboolean bmtcall_exists = FALSE;
1956         int nw_status = 0;
1957
1958         CALL_ENG_DEBUG(ENG_DEBUG, "");
1959
1960         voicecall_core_set_status(pcall_core, CALL_VC_CORE_FLAG_SOS_CALL_ONLY, bemergency);
1961
1962         _vc_core_engine_status_isexists_call_bytype(pcall_engine, VC_OUTGOING_CALL, &bmocall_exists);
1963         if (TRUE == bmocall_exists) {
1964                 CALL_ENG_DEBUG(ENG_DEBUG, "MO call is in progress...");
1965                 voicecall_core_set_status(pcall_core, CALL_VC_CORE_FLAG_SETUPCALL_FAIL, TRUE);
1966                 return FALSE;
1967         }
1968
1969         /*Ignore the MO Call, if already an Incoming call is in progress, MT Call is given high priority */
1970         _vc_core_engine_status_isexists_call_bytype(pcall_engine, VC_INCOMING_CALL, &bmtcall_exists);
1971         if (TRUE == bmtcall_exists) {
1972                 CALL_ENG_DEBUG(ENG_DEBUG, "MT call is in progress");
1973                 voicecall_core_set_status(pcall_core, CALL_VC_CORE_FLAG_SETUPCALL_FAIL, TRUE);
1974                 return FALSE;
1975         }
1976
1977         if (TRUE == _vc_core_util_check_video_call_status()) {
1978                 CALL_ENG_DEBUG(ENG_DEBUG, "Voice call is not allowed during video call...");
1979                 voicecall_core_set_status(pcall_core, CALL_VC_CORE_FLAG_SETUPCALL_FAIL, TRUE);
1980                 vc_engine_msg_box_type event_data;
1981
1982                 memset(&event_data, 0, sizeof(event_data));
1983                 event_data.string_id = IDS_CALL_POP_VOICE_CALL_IS_NOT_ALLOWED_DURING_VIDEO_CALL;
1984                 vcall_engine_send_event_to_client(VC_ENGINE_MSG_MESSAGE_BOX_TO_UI, (void *)&event_data);
1985
1986                 return FALSE;
1987         }
1988
1989         if (TRUE == _vc_core_util_get_SAP_status()) {
1990                 CALL_ENG_DEBUG(ENG_DEBUG, "SAP is on");
1991                 voicecall_core_set_status(pcall_core, CALL_VC_CORE_FLAG_SETUPCALL_FAIL, TRUE);
1992                 vc_engine_msg_box_type event_data;
1993
1994                 memset(&event_data, 0, sizeof(event_data));
1995                 event_data.string_id = IDS_CALL_POP_UNAVAILABLE;
1996                 vcall_engine_send_event_to_client(VC_ENGINE_MSG_MESSAGE_BOX_TO_UI, (void *)&event_data);
1997
1998                 return FALSE;
1999         }
2000
2001         /*Prpare a call with the Voicecall Engine */
2002         setupcall_info.call_type = pcall_core->call_setup_info.call_type;
2003         _vc_core_util_strcpy(setupcall_info.source_tel_number, sizeof(setupcall_info.source_tel_number), pcall_core->call_setup_info.source_tel_number);
2004         _vc_core_util_strcpy(setupcall_info.tel_number, sizeof(setupcall_info.tel_number), pcall_core->call_setup_info.tel_number);
2005
2006         /*Get CUG Details */
2007         _vc_core_util_get_cug_info(&setupcall_info);
2008
2009         /*Get Identity Mode */
2010         _vc_core_util_get_identity_mode(&setupcall_info);
2011
2012         CALL_ENG_DEBUG(ENG_DEBUG, "identity_mode = [%d], tel_number = [%s]", setupcall_info.identity_mode, setupcall_info.tel_number);
2013
2014         error_code = _vc_core_engine_prepare_call(pcall_engine, &setupcall_info);
2015         if (ERROR_VOICECALL_NONE != error_code) {
2016                 CALL_ENG_DEBUG(ENG_DEBUG, "_vc_core_engine_prepare_call failed, error code: %d", error_code);
2017                 _vc_core_engine_finalize_call(pcall_engine, VC_OUTGOING_CALL, -1);
2018                 voicecall_core_set_status(pcall_core, CALL_VC_CORE_FLAG_SETUPCALL_FAIL, TRUE);
2019                 vc_engine_msg_box_type event_data;
2020
2021                 memset(&event_data, 0, sizeof(event_data));
2022                 event_data.string_id = __voicecall_core_get_string_id_by_errorcode(error_code);
2023                 vcall_engine_send_event_to_client(VC_ENGINE_MSG_MESSAGE_BOX_TO_UI, (void *)&event_data);
2024                 return FALSE;
2025         }
2026         pcall_core->call_setup_info.call_type = setupcall_info.call_type;
2027         CALL_ENG_DEBUG(ENG_DEBUG, "call_type:[%d]", pcall_core->call_setup_info.call_type);
2028
2029         pcall_core->call_setup_info.mo_call_index = setupcall_info.mo_call_index;
2030         if (TRUE == _vc_core_util_is_offline_mode()) {
2031                 _vc_core_engine_finalize_call(pcall_engine, VC_OUTGOING_CALL, -1);
2032                 voicecall_core_set_status(pcall_core, CALL_VC_CORE_FLAG_SETUPCALL_FAIL, TRUE);
2033
2034                 vc_engine_msg_box_type event_data;
2035
2036                 memset(&event_data, 0, sizeof(event_data));
2037                 event_data.string_id = IDS_CALL_POP_CHANGEOFFLINEMODETOCALL;
2038                 vcall_engine_send_event_to_client(VC_ENGINE_MSG_MESSAGE_BOX_TO_UI, (void *)&event_data);
2039                 return FALSE;
2040         }
2041
2042         /* Check for Following Conditions , only if not emergency Number */
2043         CALL_ENG_DEBUG(ENG_DEBUG, "mo_call_index = [%d]", setupcall_info.mo_call_index);
2044         error_code = _vc_core_engine_status_check_emergency_byindex(pcall_engine, setupcall_info.mo_call_index, &bemergency_call);
2045         if (ERROR_VOICECALL_NONE != error_code) {
2046                 CALL_ENG_DEBUG(ENG_DEBUG, "Emergency Check Error code: %d", error_code);
2047         }
2048
2049         /*Check PwLock */
2050         if (TRUE == _vc_core_util_is_pwlock()) {
2051                 CALL_ENG_DEBUG(ENG_DEBUG, "PwLock is enabled.");
2052                 if (bemergency_call == FALSE) {
2053                         CALL_ENG_DEBUG(ENG_DEBUG, "Only emergency call is possible.");
2054                         _vc_core_engine_finalize_call(pcall_engine, VC_OUTGOING_CALL, -1);
2055                         voicecall_core_set_status(pcall_core, CALL_VC_CORE_FLAG_SETUPCALL_FAIL, TRUE);
2056
2057                         vc_engine_msg_box_type event_data;
2058                         memset(&event_data, 0, sizeof(event_data));
2059                         event_data.string_id = IDS_CALL_POP_CALLING_EMERG_ONLY;
2060                         vcall_engine_send_event_to_client(VC_ENGINE_MSG_MESSAGE_BOX_TO_UI, (void *)&event_data);
2061
2062                         return FALSE;
2063                 }
2064         }
2065
2066         /*Check for the following cases, if the call is not emergency call */
2067         if (FALSE == bemergency_call) {
2068                 vc_engine_msg_box_type event_data;
2069
2070                 memset(&event_data, 0, sizeof(event_data));
2071                 /* Check for NW Status and Emergency Mode */
2072                 if (FALSE == _vc_core_util_get_nw_status(&nw_status)) {
2073                         CALL_ENG_DEBUG(ENG_DEBUG, "Can't get a network status...");
2074                         _vc_core_engine_finalize_call(pcall_engine, VC_OUTGOING_CALL, -1);
2075
2076                         event_data.string_id = IDS_CALL_POP_CALLNOTCALLOWED;
2077                         vcall_engine_send_event_to_client(VC_ENGINE_MSG_MESSAGE_BOX_TO_UI, (void *)&event_data);
2078
2079                         voicecall_core_set_status(pcall_core, CALL_VC_CORE_FLAG_SETUPCALL_FAIL, TRUE);
2080                         return FALSE;
2081                 } else {
2082                         if ((VCONFKEY_TELEPHONY_SVCTYPE_NONE == nw_status) || (VCONFKEY_TELEPHONY_SVCTYPE_NOSVC == nw_status) || (VCONFKEY_TELEPHONY_SVCTYPE_SEARCH == nw_status)) {
2083                                 CALL_ENG_DEBUG(ENG_DEBUG, "No Service: Call not Allowed");
2084                                 _vc_core_engine_finalize_call(pcall_engine, VC_OUTGOING_CALL, -1);
2085                                 event_data.string_id = IDS_CALL_POP_CALLNOTCALLOWED;
2086                                 vcall_engine_send_event_to_client(VC_ENGINE_MSG_MESSAGE_BOX_TO_UI, (void *)&event_data);
2087
2088                                 voicecall_core_set_status(pcall_core, CALL_VC_CORE_FLAG_SETUPCALL_FAIL, TRUE);
2089                                 return FALSE;
2090                         } else if ((VCONFKEY_TELEPHONY_SVCTYPE_EMERGENCY == nw_status)) {
2091                                 CALL_ENG_DEBUG(ENG_DEBUG, "Emergency mode: Emergency call only...");
2092                                 _vc_core_engine_finalize_call(pcall_engine, VC_OUTGOING_CALL, -1);
2093                                 event_data.string_id = IDS_CALL_POP_CALLING_EMERG_ONLY;
2094                                 vcall_engine_send_event_to_client(VC_ENGINE_MSG_MESSAGE_BOX_TO_UI, (void *)&event_data);
2095
2096                                 voicecall_core_set_status(pcall_core, CALL_VC_CORE_FLAG_SETUPCALL_FAIL, TRUE);
2097                                 return FALSE;
2098                         } else {
2099                                 /* ok. */
2100                         }
2101
2102                 }
2103
2104                 /*Check for voicemail number if it is not an emergency call */
2105         }
2106
2107         CALL_ENG_DEBUG(ENG_DEBUG, "MO Call Setup OVer");
2108
2109         if (_vc_bt_get_bt_status() == TRUE) {
2110                 voicecall_snd_set_path_status(pcall_core->papp_snd, VOICE_CALL_SND_PATH_BT);
2111         }
2112
2113         voicecall_core_make_call(pcall_core);
2114
2115         return TRUE;
2116 }
2117
2118 /**
2119  * This function makes the actual voicecall prepared by the #voicecall_core_setup_call
2120  *
2121  * @return              Returns TRUE on success or FALSE on failure
2122  * @param[in]           pcall_core              Handle to voicecall core
2123  */
2124 gboolean voicecall_core_make_call(call_vc_core_state_t *pcall_core)
2125 {
2126         voicecall_engine_t *pcall_engine = pcall_core->pcall_engine;
2127
2128         voicecall_error_t error_code = ERROR_VOICECALL_NONE;
2129         int call_handle = -1;
2130
2131         CALL_ENG_DEBUG(ENG_DEBUG, "");
2132
2133         /*Make Actual Call with Voicecall Engine */
2134         error_code = _vc_core_engine_make_call(pcall_engine, pcall_core->call_setup_info.mo_call_index, &call_handle);
2135         if (ERROR_VOICECALL_NONE != error_code) {
2136                 vc_engine_msg_box_type event_data;
2137
2138                 memset(&event_data, 0, sizeof(event_data));
2139
2140                 _vc_core_engine_finalize_call(pcall_engine, VC_OUTGOING_CALL, -1);
2141
2142                 CALL_ENG_DEBUG(ENG_DEBUG, "_vc_core_engine_make_call Failed: Error_Code: %d..", error_code);
2143
2144                 switch (error_code) {
2145                 case ERROR_VOICECALL_TAPI_CAUSE_CALL_FAILED:
2146                         event_data.string_id = IDS_CALL_POP_CALLFAILED;
2147                         break;
2148
2149                 case ERROR_VOICECALL_CALL_IMPOSSIBLE_NOSIM_NOEMERGNUM:
2150                         event_data.string_id = IDS_CALL_POP_CALLFAILED;
2151                         break;
2152
2153                 default:
2154                         event_data.string_id = IDS_CALL_BODY_CALLENDED;
2155                         break;
2156                 }
2157                 vcall_engine_send_event_to_client(VC_ENGINE_MSG_MESSAGE_BOX_TO_UI, (void *)&event_data);
2158
2159                 return FALSE;
2160         }
2161
2162         CALL_ENG_DEBUG(ENG_DEBUG, "Call Handle After Setup Call %d.", call_handle);
2163
2164         voicecall_snd_register_cm(pcall_core->papp_snd);
2165
2166         /* Set phonestatus value */
2167         _vc_core_util_set_call_status(VCONFKEY_CALL_VOICE_CONNECTING);
2168
2169         return TRUE;
2170 }
2171
2172 /**
2173  * This function processed sat setup call
2174  *
2175  * @return              Returns TRUE on success or FALSE on failure
2176  * @param[in]           pcall_core              Handle to voicecall core
2177  * @param[in]
2178 */
2179 gboolean voicecall_core_process_sat_setup_call(vcall_engine_sat_setup_call_info_t *sat_setup_call_info)
2180 {
2181         CALL_ENG_DEBUG(ENG_DEBUG, "");
2182         TelSatSetupCallIndCallData_t *SatSetupCallIndCallInfo = NULL;
2183
2184         SatSetupCallIndCallInfo = (TelSatSetupCallIndCallData_t *) calloc(1, sizeof(TelSatSetupCallIndCallData_t));
2185         if (NULL == SatSetupCallIndCallInfo)
2186                 return FALSE;
2187
2188         SatSetupCallIndCallInfo->commandId = sat_setup_call_info->command_id;
2189         SatSetupCallIndCallInfo->calltype = sat_setup_call_info->command_qualifier;
2190         SatSetupCallIndCallInfo->dispText.stringLen = strlen(sat_setup_call_info->disp_text);
2191         memcpy(SatSetupCallIndCallInfo->dispText.string, sat_setup_call_info->disp_text, strlen(sat_setup_call_info->disp_text));
2192
2193         SatSetupCallIndCallInfo->callNumber.stringLen = strlen(sat_setup_call_info->call_num);
2194         memcpy(SatSetupCallIndCallInfo->callNumber.string, sat_setup_call_info->call_num, strlen(sat_setup_call_info->call_num));
2195
2196         SatSetupCallIndCallInfo->duration = sat_setup_call_info->duration;
2197
2198         _vc_core_engine_handle_sat_events_cb(SatSetupCallIndCallInfo, NULL);
2199
2200         if (SatSetupCallIndCallInfo) {
2201                 free(SatSetupCallIndCallInfo);
2202                 SatSetupCallIndCallInfo = NULL;
2203         }
2204
2205         CALL_ENG_DEBUG(ENG_DEBUG, "End..");
2206
2207         return TRUE;
2208 }
2209
2210 /**
2211  * This function processed incoming call
2212  *
2213  * @return              Returns TRUE on success or FALSE on failure
2214  * @param[in]           pcall_core              Handle to voicecall core
2215  * @param[in]
2216 */
2217 gboolean voicecall_core_process_incoming_call(call_vc_core_incoming_info_t *incoming_call_info)
2218 {
2219         CALL_ENG_DEBUG(ENG_DEBUG, "");
2220         TelCallIncomingCallInfo_t *IncomingCallInfo = NULL;
2221
2222         CALL_ENG_DEBUG(ENG_DEBUG, " number is : [%s]", incoming_call_info->call_num);
2223
2224         IncomingCallInfo = (TelCallIncomingCallInfo_t *) malloc(sizeof(TelCallIncomingCallInfo_t));
2225         if (NULL == IncomingCallInfo)
2226                 return FALSE;
2227         memset(IncomingCallInfo, 0, sizeof(IncomingCallInfo));
2228
2229         IncomingCallInfo->CallHandle = incoming_call_info->call_handle;
2230         IncomingCallInfo->CallType = incoming_call_info->call_type;
2231         IncomingCallInfo->CliPresentationIndicator = incoming_call_info->cli_presentation_indicator;
2232         _vc_core_util_strcpy(IncomingCallInfo->szCallingPartyNumber, sizeof(IncomingCallInfo->szCallingPartyNumber), incoming_call_info->call_num);
2233         IncomingCallInfo->CallingNameInfo.NameMode = incoming_call_info->calling_name_mode;
2234         _vc_core_util_strcpy(IncomingCallInfo->CallingNameInfo.szNameData, sizeof(IncomingCallInfo->CallingNameInfo.szNameData), incoming_call_info->calling_name);
2235         _vc_core_util_strcpy(IncomingCallInfo->RedirectInfo.szRedirectedNumber, sizeof(IncomingCallInfo->RedirectInfo.szRedirectedNumber), incoming_call_info->redirected_number);
2236         _vc_core_util_strcpy(IncomingCallInfo->RedirectInfo.szRedirectSubAddress, sizeof(IncomingCallInfo->RedirectInfo.szRedirectSubAddress), incoming_call_info->redirected_sub_address);
2237         IncomingCallInfo->CliCause = incoming_call_info->cli_cause;
2238         IncomingCallInfo->fwded = incoming_call_info->bfwded;
2239         IncomingCallInfo->ActiveLine = incoming_call_info->active_line;
2240
2241         _vc_core_engine_handle_incoming_tapi_events(IncomingCallInfo, NULL);
2242
2243         if (IncomingCallInfo) {
2244                 free(IncomingCallInfo);
2245                 IncomingCallInfo = NULL;
2246         }
2247
2248         CALL_ENG_DEBUG(ENG_DEBUG, "End..");
2249
2250         return TRUE;
2251 }
2252
2253 /**
2254  * This function answers an incoming call
2255  *
2256  * @return              Returns TRUE on success or FALSE on failure
2257  * @param[in]           pcall_core              Handle to voicecall core
2258  * @param[in]
2259 */
2260 gboolean voicecall_core_answer_call(call_vc_core_state_t *pcall_core, gboolean auto_accept)
2261 {
2262         voicecall_engine_t *pcall_engine = pcall_core->pcall_engine;
2263
2264         gboolean active_calls = FALSE;
2265         gboolean held_calls = FALSE;
2266
2267         CALL_ENG_DEBUG(ENG_DEBUG, "");
2268
2269         /*First Stop the Incoming alert */
2270         voicecall_snd_stop_alert(pcall_core->papp_snd);
2271
2272         __voicecall_core_cancel_auto_answer(pcall_core);
2273
2274         _vc_core_engine_status_isexists_any_call(pcall_engine, &active_calls, &held_calls);
2275         CALL_ENG_DEBUG(ENG_DEBUG, "active_calls=%d, held_calls=%d", active_calls, held_calls);
2276
2277         if (TRUE == active_calls && TRUE == held_calls) {
2278                 /* Both Active and held calls available, so show Accept Call Choice Box */
2279                 vc_engine_accept_choice_box_type event_data;
2280
2281                 memset(&event_data, 0, sizeof(event_data));
2282                 event_data.choice = VC_CALL_ACCEPT_2;
2283
2284                 vcall_engine_send_event_to_client(VC_ENGINE_MSG_ACCEPT_CHOICE_BOX_TO_UI, (void *)&event_data);
2285
2286                 return TRUE;
2287         } else if (TRUE == active_calls) {
2288                 /*If Auto Accpet is FALSE, show popup for manual accept */
2289                 if (FALSE == auto_accept) {
2290                         /* Active  calls available, so show Accept Call Choice Box */
2291                         vc_engine_accept_choice_box_type event_data;
2292
2293                         memset(&event_data, 0, sizeof(event_data));
2294                         event_data.choice = VC_CALL_ACCEPT_1;
2295
2296                         vcall_engine_send_event_to_client(VC_ENGINE_MSG_ACCEPT_CHOICE_BOX_TO_UI, (void *)&event_data);
2297                 } else {
2298                         voicecall_core_answer_call_bytype(pcall_core, VC_ANSWER_HOLD_ACTIVE_AND_ACCEPT);
2299                 }
2300                 return TRUE;
2301         } else if (TRUE == held_calls) {
2302                 /* vcui_app_view_mtcall_destroy(papp_document); */
2303         }
2304
2305         /* Normal Call Scenario */
2306         voicecall_core_answer_call_bytype(pcall_core, VC_ANSWER_NORMAL);
2307
2308         return TRUE;
2309 }
2310
2311 /**
2312  * This function answers an incoming call  according to the given type
2313  *
2314  * @return              Returns TRUE -if answer is sucess, FALSE - otherwise
2315  * @param[in]           pcall_core              Handle to voicecall core
2316  */
2317 gboolean voicecall_core_answer_call_bytype(call_vc_core_state_t *pcall_core, voicecall_answer_type_t answer_type)
2318 {
2319         voicecall_engine_t *pcall_engine = pcall_core->pcall_engine;
2320
2321         voicecall_error_t error_code = ERROR_VOICECALL_NONE;
2322
2323         CALL_ENG_DEBUG(ENG_DEBUG, "answer type: %d", answer_type);
2324
2325         /*First Stop the Incoming alert */
2326         voicecall_snd_stop_alert(pcall_core->papp_snd);
2327         __voicecall_core_cancel_auto_answer(pcall_core);
2328
2329         error_code = _vc_core_engine_answer_call(pcall_engine, answer_type);
2330
2331         if (ERROR_VOICECALL_NONE != error_code) {
2332                 CALL_ENG_DEBUG(ENG_ERR, "_vc_core_engine_answer_call Failed : %d", error_code);
2333                 return FALSE;
2334         }
2335
2336         return TRUE;
2337 }
2338
2339 /**
2340 * This function rejects an incoming call
2341 *
2342 * @return               Returns TRUE on success or FALSE on failure
2343 * @param[in]            pcall_core              Handle to voicecall core
2344 * @param[in]            bUDUB                   TRUE - set UDUB, FALSE - reject call
2345 */
2346 gboolean voicecall_core_reject_mt(call_vc_core_state_t *pcall_core, gboolean bUDUB)
2347 {
2348         voicecall_engine_t *pcall_engine = pcall_core->pcall_engine;
2349         voicecall_snd_mgr_t *papp_snd = pcall_core->papp_snd;
2350
2351         voicecall_error_t error_code = ERROR_VOICECALL_NONE;
2352
2353         CALL_ENG_DEBUG(ENG_DEBUG, "");
2354
2355         /*Incoming call rejected, reset the accept by flag */
2356         voicecall_core_set_status(pcall_core, CALL_VC_CORE_FLAG_ACCEPT_BY_BT, FALSE);
2357
2358         /* Stop Incmoing Call Alert */
2359         voicecall_snd_stop_alert(papp_snd);
2360
2361         __voicecall_core_cancel_auto_answer(pcall_core);
2362
2363         CALL_ENG_DEBUG(ENG_DEBUG, "bUDUB = %d", bUDUB);
2364         error_code = _vc_core_engine_reject_call(pcall_engine, bUDUB);
2365
2366         if (ERROR_VOICECALL_NONE != error_code) {
2367                 CALL_ENG_DEBUG(ENG_ERR, "_vc_core_engine_reject_call Failed, error_code = %ud", error_code);
2368                 return FALSE;
2369         }
2370
2371         return TRUE;
2372
2373 }
2374
2375 /**
2376  * This function ends the call by state
2377  *
2378  * @return              Returns TRUE on success or FALSE on failure
2379  * @param[in]           pcall_core              Handle to voicecall core
2380  */
2381 gboolean voicecall_core_end_call(call_vc_core_state_t *pcall_core)
2382 {
2383         voicecall_engine_t *pcall_engine = pcall_core->pcall_engine;
2384
2385         CALL_ENG_DEBUG(ENG_DEBUG, "");
2386
2387         return (ERROR_VOICECALL_NONE == _vc_core_engine_end_call(pcall_engine, VC_END_ACTIVE_OR_HELD_CALLS)) ? TRUE : FALSE;
2388 }
2389
2390 /**
2391  * This function ends the call corresponding to the given call handle
2392  *
2393  * @return              Returns TRUE on success or FALSE on failure
2394  * @param[in]           pcall_core              Handle to voicecall core
2395  * @param[in]           call_handle             handle of the call to be ended
2396  */
2397 gboolean voicecall_core_end_call_by_handle(call_vc_core_state_t *pcall_core, int call_handle)
2398 {
2399         voicecall_engine_t *pcall_engine = pcall_core->pcall_engine;
2400
2401         CALL_ENG_DEBUG(ENG_DEBUG, "");
2402
2403         return (ERROR_VOICECALL_NONE == _vc_core_engine_end_call_byhandle(pcall_engine, call_handle)) ? TRUE : FALSE;
2404 }
2405
2406 /**
2407  * This function ends all available calls
2408  *
2409  * @return              Returns TRUE on success or FALSE on failure
2410  * @param[in]           pcall_core              Handle to voicecall core
2411  */
2412 gboolean voicecall_core_end_all_calls(call_vc_core_state_t *pcall_core)
2413 {
2414         voicecall_engine_t *pcall_engine = pcall_core->pcall_engine;
2415
2416         CALL_ENG_DEBUG(ENG_DEBUG, "");
2417
2418         return (ERROR_VOICECALL_NONE == _vc_core_engine_end_call(pcall_engine, VC_END_ALL_CALLS)) ? TRUE : FALSE;
2419 }
2420
2421 /**
2422  * This function ends all available active calls
2423  *
2424  * @return              Returns TRUE on success or FALSE on failure
2425  * @param[in]           pcall_core              Handle to voicecall core
2426  */
2427 gboolean voicecall_core_end_all_active_calls(call_vc_core_state_t *pcall_core)
2428 {
2429         voicecall_engine_t *pcall_engine = pcall_core->pcall_engine;
2430
2431         CALL_ENG_DEBUG(ENG_DEBUG, "");
2432
2433         return (ERROR_VOICECALL_NONE == _vc_core_engine_end_call(pcall_engine, VC_END_ALL_ACTIVE_CALLS)) ? TRUE : FALSE;
2434 }
2435
2436 /**
2437  * This function ends all available held calls
2438  *
2439  * @return              Returns TRUE on success or FALSE on failure
2440  * @param[in]           pcall_core              Handle to voicecall core
2441  */
2442 gboolean voicecall_core_end_all_held_calls(call_vc_core_state_t *pcall_core)
2443 {
2444         voicecall_engine_t *pcall_engine = pcall_core->pcall_engine;
2445
2446         CALL_ENG_DEBUG(ENG_DEBUG, "");
2447
2448         return (ERROR_VOICECALL_NONE == _vc_core_engine_end_call(pcall_engine, VC_END_ALL_HELD_CALLS)) ? TRUE : FALSE;
2449 }
2450
2451 /**
2452  * This function cancel outgoing call
2453  *
2454  * @return              Returns TRUE -if answer is sucess, FALSE - otherwise
2455  * @param[in]           pcall_core              Handle to voicecall core
2456  */
2457 gboolean voicecall_core_cancel_call(call_vc_core_state_t *pcall_core)
2458 {
2459         int io_state = 0;
2460         voicecall_engine_t *pcall_engine = pcall_core->pcall_engine;
2461
2462         voicecall_call_type_bysetup_t call_setup_by = VC_CALL_SETUP_BY_NORMAL;
2463
2464         CALL_ENG_DEBUG(ENG_DEBUG, "");
2465
2466         /*Get Call Setup by Information */
2467         call_setup_by = pcall_core->call_setup_info.call_setup_by;
2468
2469         _vc_core_engine_status_get_engine_iostate(pcall_engine, &io_state);
2470
2471         switch (io_state) {
2472         case VC_INOUT_STATE_OUTGOING_WAIT_HOLD:
2473                 {
2474                         int call_handle = -1;
2475
2476                         if (VC_CALL_SETUP_BY_SAT == call_setup_by) {
2477                                 _vc_core_engine_send_sat_response(pcall_engine, SAT_RQST_SETUP_CALL, CALL_VC_ME_CLEAR_DOWN_BEFORE_CONN);
2478                         }
2479
2480                         /* Clear the MO Call, since the call is not dialed yet */
2481                         _vc_core_engine_status_get_call_handle_bytype(pcall_engine, VC_OUTGOING_CALL, &call_handle);
2482                         _vc_bt_send_response_to_bt(pcall_core, BT_AG_RES_CALL_END, call_handle, NULL);
2483
2484                         __vc_core_set_auto_redial_count(pcall_core, 0);
2485                         voicecall_core_clear_mo_call(pcall_engine);
2486
2487                         _vc_core_engine_change_engine_iostate(pcall_engine, VC_INOUT_STATE_OUTGOING_ABORTED);
2488                 }
2489                 return TRUE;
2490
2491         case VC_INOUT_STATE_OUTGOING_WAIT_ORIG:
2492         case VC_INOUT_STATE_OUTGOING_WAIT_ALERT:
2493         case VC_INOUT_STATE_OUTGOING_WAIT_CONNECTED:
2494                 {
2495                         /*To retrieve the held call automatically once the mo call is ended, if held is call is available */
2496                         _vc_core_engine_status_set_end_flag(pcall_engine, VC_RETREIVE_CALL_ON_MOCALL_END);
2497
2498                         /* release the call , since it is dialed and waiting for connecting */
2499                         if (FALSE == voicecall_core_end_mo_call(pcall_engine)) {
2500                                 CALL_ENG_DEBUG(ENG_DEBUG, "MO Call Release Failed");
2501                         } else {
2502                                 voicecall_core_set_status(pcall_core, CALL_VC_CORE_FLAG_MOCALL_END_BY_USER, TRUE);
2503                                 _vc_core_engine_change_engine_iostate(pcall_engine, VC_INOUT_STATE_OUTGOING_WAIT_RELEASE);
2504                         }
2505                 }
2506                 return TRUE;
2507
2508         case VC_INOUT_STATE_OUTGOING_WAIT_RELEASE:
2509                 {
2510                         /*Call already released */
2511                         CALL_ENG_DEBUG(ENG_DEBUG, "MO Call has been released already");
2512                 }
2513                 return TRUE;
2514
2515         case VC_INOUT_STATE_OUTGOING_SHOW_REDIALCAUSE:
2516         case VC_INOUT_STATE_OUTGOING_ABORTED:
2517         case VC_INOUT_STATE_OUTGOING_WAIT_REDIAL:
2518                 {
2519                         int call_handle = -1;
2520
2521                         if (VC_CALL_SETUP_BY_SAT == call_setup_by) {
2522                                 _vc_core_engine_send_sat_response(pcall_engine, SAT_RQST_SETUP_CALL, CALL_VC_NETWORK_UNABLE_TO_PROCESS_COMMAND);
2523                         }
2524
2525                         /*Stop Signal Play */
2526                         voicecall_snd_stop_signal(pcall_core->papp_snd);
2527
2528                         __voicecall_core_mocall_reset_engine_state(pcall_engine);
2529
2530                         _vc_core_engine_status_get_call_handle_bytype(pcall_engine, VC_OUTGOING_CALL, &call_handle);
2531                         _vc_bt_send_response_to_bt(pcall_core, BT_AG_RES_CALL_END, call_handle, NULL);
2532
2533                         __vc_core_set_auto_redial_count(pcall_core, 0);
2534                         voicecall_core_clear_mo_call(pcall_engine);
2535
2536                 }
2537                 return TRUE;
2538
2539         default:
2540                 CALL_ENG_DEBUG(ENG_DEBUG, "Action not defined for this IO State: %d", io_state);
2541                 break;
2542         }
2543
2544         return FALSE;
2545 }
2546
2547 /**
2548  * This function process hold/retrive/swap conntected call
2549  *
2550  * @return              Returns TRUE -if answer is sucess, FALSE - otherwise
2551  * @param[in]           pcall_core              Handle to voicecall core
2552  */
2553 gboolean voicecall_core_process_hold_call(call_vc_core_state_t *pcall_core)
2554 {
2555         voicecall_engine_t *pcall_engine = pcall_core->pcall_engine;
2556
2557         gboolean active_calls = FALSE;
2558         gboolean held_calls = FALSE;
2559
2560         CALL_ENG_DEBUG(ENG_DEBUG, "");
2561
2562         if (TRUE == voicecall_core_get_status(pcall_core, CALL_VC_CORE_FLAG_SOS_CALL_ONLY)) {
2563                 CALL_ENG_DEBUG(ENG_DEBUG, "SOS Call... Ignore this button...");
2564                 return TRUE;
2565         }
2566
2567         if (FALSE == voicecall_core_is_incall_request_possible(pcall_engine)) {
2568                 return TRUE;
2569         }
2570
2571         voicecall_core_is_call_exists(pcall_engine, &active_calls, &held_calls);
2572         CALL_ENG_DEBUG(ENG_DEBUG, "active calls: %d, held calls: %d", active_calls, held_calls);
2573
2574         if (active_calls && held_calls) {
2575
2576                 /*Both Calls available, swap the calls */
2577                 if (FALSE == voicecall_core_swap_calls(pcall_engine)) {
2578                         return FALSE;
2579                 }
2580         } else if (active_calls) {
2581                 /*Only activa call available, hold the call */
2582                 if (FALSE == voicecall_core_hold_call(pcall_engine)) {
2583                         return FALSE;
2584                 }
2585         } else if (held_calls) {
2586                 /*Only Held call available, retrieve the call */
2587                 if (FALSE == voicecall_core_retrieve_call(pcall_engine)) {
2588                         return FALSE;
2589                 }
2590         } else {
2591                 CALL_ENG_DEBUG(ENG_DEBUG, "no call exists!");
2592                 return FALSE;
2593         }
2594
2595         return TRUE;
2596 }
2597
2598 /**
2599  * This function sets up a conference call
2600  *
2601  * @return              Returns TRUE on success or FALSE on failure
2602  * @param[in]           pcall_core              Handle to voicecall core
2603  */
2604 gboolean voicecall_core_setup_conference(call_vc_core_state_t *pcall_core)
2605 {
2606         voicecall_engine_t *pcall_engine = pcall_core->pcall_engine;
2607
2608         CALL_ENG_DEBUG(ENG_DEBUG, "");
2609
2610         return (ERROR_VOICECALL_NONE == _vc_core_engine_setup_conference(pcall_engine)) ? TRUE : FALSE;
2611 }
2612
2613 /**
2614  * This function splits the call corressponding to the given call handle and makes a private call
2615  *
2616  * @return              Returns TRUE on success or FALSE on failure
2617  * @param[in]           pcall_core              Handle to voicecall core
2618  * @param[in]           call_handle             Call to be splitted from the conference call
2619  */
2620 gboolean voicecall_core_make_private_call(call_vc_core_state_t *pcall_core, int call_handle)
2621 {
2622         voicecall_engine_t *pcall_engine = pcall_core->pcall_engine;
2623
2624         CALL_ENG_DEBUG(ENG_DEBUG, "");
2625
2626         return (ERROR_VOICECALL_NONE == _vc_core_engine_private_call(pcall_engine, call_handle)) ? TRUE : FALSE;
2627 }
2628
2629 /**
2630  * This function transfers the call from active call to the held call
2631  *
2632  * @return              Returns TRUE on success or FALSE on failure
2633  * @param[in]           pcall_core              Handle to voicecall core
2634  */
2635 gboolean voicecall_core_transfer_calls(call_vc_core_state_t *pcall_core)
2636 {
2637         voicecall_engine_t *pcall_engine = pcall_core->pcall_engine;
2638
2639         CALL_ENG_DEBUG(ENG_DEBUG, "");
2640
2641         return (ERROR_VOICECALL_NONE == _vc_core_engine_transfer_calls(pcall_engine)) ? TRUE : FALSE;
2642 }
2643
2644 /**
2645  * This function sends a dtmf string
2646  *
2647  * @return              Returns TRUE on success or FALSE on failure
2648  * @param[in]           pcall_core              Handle to voicecall core
2649  * @param[in]           dtmf_string             dtmf string to be sent
2650  */
2651 gboolean voicecall_core_send_dtmf(call_vc_core_state_t *pcall_core, char *dtmf_string)
2652 {
2653         voicecall_error_t error_code = ERROR_VOICECALL_NONE;
2654         CALL_ENG_DEBUG(ENG_DEBUG, "dtmf string: %s", dtmf_string);
2655
2656         pcall_core->bdtmf_queue = FALSE;
2657         error_code = _vc_core_engine_send_dtmf(pcall_core->pcall_engine, dtmf_string);
2658         return (ERROR_VOICECALL_NONE == error_code) ? TRUE : FALSE;
2659 }
2660
2661 /**
2662 * This function stops sound alert in case of reject with msg
2663 *
2664 * @return               Returns TRUE on success or FALSE on failure
2665 * @param[in]            pcall_core              Handle to voicecall core
2666 */
2667 gboolean voicecall_core_stop_alert(call_vc_core_state_t *pcall_core)
2668 {
2669         CALL_ENG_DEBUG(ENG_DEBUG, "");
2670
2671         /* Stop Incmoing Call Alert */
2672         voicecall_snd_stop_alert(pcall_core->papp_snd);
2673
2674         return TRUE;
2675 }
2676
2677 inline gboolean voicecall_core_get_mo_call_handle(call_vc_core_state_t *pcall_core, int *pcall_handle)
2678 {
2679         *pcall_handle = -1;
2680         return (ERROR_VOICECALL_NONE == _vc_core_engine_status_get_call_handle_bytype(pcall_core->pcall_engine, VC_OUTGOING_CALL, pcall_handle)) ? TRUE : FALSE;
2681 }
2682
2683 inline int voicecall_core_get_auto_redial_count(call_vc_core_state_t *pcall_core)
2684 {
2685         return pcall_core->auto_redial_count;
2686 }
2687
2688 void __vc_core_set_auto_redial_count(call_vc_core_state_t *pcall_core, int auto_redial_count)
2689 {
2690         pcall_core->auto_redial_count = auto_redial_count;
2691 }
2692
2693 gboolean voicecall_core_start_redial(call_vc_core_state_t *pcall_core, int manual_redial)
2694 {
2695         int auto_redial_status = FALSE;
2696         int redial_count = 1;
2697         int call_handle = -1;
2698         int total_call_member = 0;
2699
2700         CALL_ENG_DEBUG(ENG_DEBUG, "");
2701         CALL_ENG_DEBUG(ENG_DEBUG, "auto_redial_status:[%d]", auto_redial_status);
2702
2703         redial_count = voicecall_core_get_auto_redial_count(pcall_core);
2704
2705         redial_count++;
2706
2707         /*
2708            bmanual_redial == TRUE : Redial is made by User, No need to check the auto redial status and count
2709            auto_redial_status == 1: Auto Redial for GCF case, auto redial count must be checked
2710          */
2711         if ((1 == manual_redial) || ((auto_redial_status == 1) && (redial_count < MO_REDIAL_COUNT_MAX))) {
2712                 CALL_ENG_DEBUG(ENG_DEBUG, "redial_count = %d", redial_count);
2713
2714                 /*Start Redial Timer */
2715                 if (1 == redial_count) {
2716                         CALL_ENG_DEBUG(ENG_DEBUG, "MO_REDIAL_TIMER_INTERVAL_FIRST");
2717                         pcall_core->mo_redial_timer = g_timeout_add(MO_REDIAL_TIMER_INTERVAL_FIRST, mo_redial_timer_cb, pcall_core);
2718                 } else if ((redial_count > 1) && (redial_count < 5)) {
2719                         CALL_ENG_DEBUG(ENG_DEBUG, "MO_REDIAL_TIMER_INTERVAL_SECOND");
2720                         pcall_core->mo_redial_timer = g_timeout_add(MO_REDIAL_TIMER_INTERVAL_SECOND, mo_redial_timer_cb, pcall_core);
2721                 } else {
2722                         CALL_ENG_DEBUG(ENG_DEBUG, "MO_REDIAL_TIMER_INTERVAL_THIRD");
2723                         pcall_core->mo_redial_timer = g_timeout_add(MO_REDIAL_TIMER_INTERVAL_THIRD, mo_redial_timer_cb, pcall_core);
2724                 }
2725
2726                 voicecall_core_change_engine_state(pcall_core->pcall_engine, VC_INOUT_STATE_OUTGOING_WAIT_REDIAL);
2727         } else {
2728                 CALL_ENG_DEBUG(ENG_DEBUG, "You dont need to redial close the MO Call Things");
2729
2730                 /* __vcui_app_view_mo_canceltimer_cb() */
2731                 _vc_core_engine_status_get_call_handle_bytype(pcall_core->pcall_engine, VC_OUTGOING_CALL, &call_handle);
2732                 _vc_bt_send_response_to_bt(pcall_core, BT_AG_RES_CALL_END, call_handle, NULL);
2733
2734                 __vc_core_set_auto_redial_count(pcall_core, 0);
2735                 voicecall_core_clear_mo_call(pcall_core->pcall_engine);
2736
2737                 __voicecall_core_mocall_reset_engine_state(pcall_core->pcall_engine);
2738
2739                 voicecall_core_get_total_call_member(pcall_core->pcall_engine, &total_call_member);
2740
2741                 voicecall_snd_stop_signal(pcall_core->papp_snd);
2742
2743                 /* If No Connected Calls End the UI */
2744                 if (total_call_member == 0) {
2745                         /*Reset voice call core to default values */
2746                         voicecall_core_set_to_default(pcall_core);
2747                 } else {
2748                         voicecall_snd_change_path(pcall_core->papp_snd);
2749                 }
2750
2751         }
2752
2753         return TRUE;
2754 }
2755
2756 inline gboolean voicecall_core_prepare_redial(call_vc_core_state_t *pcall_core, int call_handle)
2757 {
2758         voicecall_error_t error_code = ERROR_VOICECALL_NONE;
2759
2760         CALL_ENG_DEBUG(ENG_DEBUG, "");
2761
2762         error_code = _vc_core_engine_prepare_redial(pcall_core->pcall_engine, call_handle);
2763
2764         CALL_ENG_DEBUG(ENG_DEBUG, "_vc_core_engine_prepare_redial returned : %d", error_code);
2765
2766         return (ERROR_VOICECALL_NONE == error_code) ? TRUE : FALSE;
2767 }
2768
2769 gboolean mo_redial_timer_cb(void *data)
2770 {
2771         int call_handle = -1;
2772         int redial_count;
2773
2774         CALL_ENG_DEBUG(ENG_DEBUG, "mo_redial_timer_cb");
2775         call_vc_core_state_t *pcall_core = (call_vc_core_state_t *)data;
2776         voicecall_core_get_mo_call_handle(pcall_core, &call_handle);
2777         CALL_ENG_DEBUG(ENG_DEBUG, "call handle is %d", call_handle);
2778
2779         redial_count = voicecall_core_get_auto_redial_count(pcall_core);
2780         redial_count++;
2781         __vc_core_set_auto_redial_count(pcall_core, redial_count);
2782
2783         CALL_ENG_DEBUG(ENG_DEBUG, "redial_count:[%d]", redial_count);
2784
2785         voicecall_core_prepare_redial(pcall_core, call_handle);
2786         CALL_ENG_DEBUG(ENG_DEBUG, "voicecall_core_prepare_redial done.");
2787
2788         voicecall_core_make_call(pcall_core);
2789         return FALSE;
2790 }
2791
2792 gboolean voicecall_core_stop_redial(call_vc_core_state_t *pcall_core)
2793 {
2794         int call_handle = -1, total_call_member = -1;
2795
2796         CALL_ENG_DEBUG(ENG_DEBUG, "coming inside voicecall_core_stop_redial");
2797
2798         _vc_core_util_set_call_status(VCONFKEY_CALL_OFF);
2799
2800         /*Cancel the Redial Timer */
2801         if (pcall_core->mo_redial_timer != -1) {
2802                 CALL_ENG_DEBUG(ENG_DEBUG, "mo_redial_timer removing..");
2803                 g_source_remove(pcall_core->mo_redial_timer);
2804                 pcall_core->mo_redial_timer = -1;
2805         }
2806
2807         /* __vcui_app_view_mo_canceltimer_cb() */
2808         _vc_core_engine_status_get_call_handle_bytype(pcall_core->pcall_engine, VC_OUTGOING_CALL, &call_handle);
2809         _vc_bt_send_response_to_bt(pcall_core, BT_AG_RES_CALL_END, call_handle, NULL);
2810
2811         __vc_core_set_auto_redial_count(pcall_core, 0);
2812         voicecall_core_clear_mo_call(pcall_core->pcall_engine);
2813
2814         __voicecall_core_mocall_reset_engine_state(pcall_core->pcall_engine);
2815
2816         voicecall_core_get_total_call_member(pcall_core->pcall_engine, &total_call_member);
2817
2818         voicecall_snd_stop_signal(pcall_core->papp_snd);
2819
2820         /* If No Connected Calls End the UI */
2821         if (total_call_member == 0) {
2822                 /*Reset voice call core to default values */
2823                 voicecall_core_set_to_default(pcall_core);
2824         } else {
2825                 voicecall_snd_change_path(pcall_core->papp_snd);
2826         }
2827         return TRUE;
2828
2829 }
2830
2831 static gboolean __voicecall_core_auto_answer_timer_cb(gpointer puser_data)
2832 {
2833         call_vc_core_state_t *pcall_core = (call_vc_core_state_t *)puser_data;
2834
2835         if (pcall_core->auto_answer_timer > 0) {
2836                 g_source_remove(pcall_core->auto_answer_timer);
2837                 pcall_core->auto_answer_timer = 0;
2838         }
2839
2840         /*Check for Incoming call and then answer the call */
2841         if (TRUE == voicecall_core_is_incoming_call_exists(pcall_core->pcall_engine)) {
2842                 CALL_ENG_DEBUG(ENG_DEBUG, "Call Answered");
2843                 voicecall_core_answer_call(pcall_core, TRUE);
2844         }
2845
2846         return FALSE;
2847 }
2848
2849 #if 0
2850 static gboolean __voicecall_core_callstatus_set_timer_cb(gpointer puser_data)
2851 {
2852         call_vc_core_state_t *pcall_core = (call_vc_core_state_t *)puser_data;
2853
2854         if (pcall_core->callstatus_timer > 0) {
2855                 g_source_remove(pcall_core->callstatus_timer);
2856                 pcall_core->callstatus_timer = 0;
2857         }
2858
2859         _vc_core_util_set_call_status(VCONFKEY_CALL_VOICE_CONNECTING);
2860
2861         return FALSE;
2862 }
2863 #endif
2864
2865 static gboolean __voicecall_core_auto_answer_idle_cb(gpointer puser_data)
2866 {
2867         call_vc_core_state_t *pcall_core = (call_vc_core_state_t *)puser_data;
2868         int engine_state = 0;
2869         int auto_answer_time = 0, ret = -1;
2870         unsigned long auto_answer_time_interval = 0;
2871
2872         _vc_core_engine_status_get_engine_iostate(pcall_core->pcall_engine, &engine_state);
2873         CALL_ENG_DEBUG(ENG_DEBUG, "eng_state : %d", engine_state);
2874         if (engine_state != VC_INOUT_STATE_INCOME_BOX) {
2875                 CALL_ENG_DEBUG(ENG_DEBUG, "Engine State not in Income Box, Current State: %d", engine_state);
2876                 return FALSE;
2877         }
2878         /* Read the time interval from gconf and set the redial timer  */
2879         ret = vconf_get_int(VCONFKEY_CISSAPPL_ANSWERING_MODE_TIME_INT, &auto_answer_time);
2880         if (0 == ret) {
2881                 auto_answer_time_interval = auto_answer_time * 1000;
2882                 CALL_ENG_DEBUG(ENG_DEBUG, "The time interval is : %ld", auto_answer_time_interval);
2883         } else {
2884                 CALL_ENG_DEBUG(ENG_DEBUG, "vconf_get_int FAILED");
2885                 return FALSE;
2886         }
2887
2888         pcall_core->auto_answer_timer = g_timeout_add(auto_answer_time_interval, __voicecall_core_auto_answer_timer_cb, pcall_core);
2889         return FALSE;
2890 }
2891
2892 /**
2893 * This function checks whether given answer mode is enabled or not
2894 *
2895 * @return               returns TRUE if given answer mode type is enabled in the settings or FALSE otherwise
2896 *
2897 */
2898 static gboolean __vc_core_is_answermode_enabled_from_testmode(void)
2899 {
2900         CALL_ENG_DEBUG(ENG_DEBUG, "..");
2901         int benabled = -1;
2902         int ret = -1;
2903
2904         ret = vconf_get_int(VCONFKEY_TESTMODE_AUTO_ANSWER, &benabled);
2905         if (0 == ret) {
2906                 CALL_ENG_DEBUG(ENG_DEBUG, "benabled = %d", benabled);
2907                 if (TRUE == benabled)
2908                         return TRUE;
2909                 else
2910                         return FALSE;
2911         } else {
2912                 CALL_ENG_DEBUG(ENG_DEBUG, "vconf_get_int FAILED");
2913                 return FALSE;
2914         }
2915 }
2916
2917 /**
2918 * This function checks whether given answer mode is enabled or not
2919 *
2920 * @return               returns TRUE if given answer mode type is enabled in the settings or FALSE otherwise
2921 *
2922 */
2923 static gboolean __vc_core_is_answermode_enabled(void)
2924 {
2925         CALL_ENG_DEBUG(ENG_DEBUG, "coming inside voicecall_is_answermode_enabled");
2926         int answer_mode_enabled = -1;
2927         int ret = -1;
2928
2929         ret = vconf_get_int(VCONFKEY_CISSAPPL_ANSWERING_MODE_INT, &answer_mode_enabled);
2930         if (0 == ret) {
2931                 CALL_ENG_DEBUG(ENG_DEBUG, "answer_mode_enabled = %d", answer_mode_enabled);
2932                 if (2 == answer_mode_enabled)   /* here 2 is auto answer mode is enabled */
2933                         return TRUE;
2934                 else
2935                         return FALSE;
2936         } else {
2937                 CALL_ENG_DEBUG(ENG_DEBUG, "vconf_get_int FAILED");
2938                 return FALSE;
2939         }
2940
2941 }
2942
2943 /**
2944 * This function processes auto answer request
2945 *
2946 * @return               Returns void
2947 * @param[in]            pcall_core              Handle to voicecall core
2948 */
2949 static void __voicecall_core_start_auto_answer(call_vc_core_state_t *pcall_core, gboolean isTestMode)
2950 {
2951         gboolean earjack_connected = FALSE;
2952         gboolean headset_connected = FALSE;
2953
2954         CALL_ENG_DEBUG(ENG_DEBUG, "..");
2955
2956         if (TRUE == isTestMode) {
2957                 CALL_ENG_DEBUG(ENG_DEBUG, "In case Of Testmode, always auto answer enabled");
2958
2959                 g_idle_add(__voicecall_core_auto_answer_idle_cb, pcall_core);
2960                 return;
2961         }
2962         earjack_connected = _voicecall_dvc_get_earjack_connected();
2963
2964         if (TRUE == earjack_connected) {
2965                 CALL_ENG_DEBUG(ENG_DEBUG, "earjack is connected");
2966         }
2967         headset_connected = _vc_bt_get_bt_status();
2968
2969         if (TRUE == headset_connected) {
2970                 CALL_ENG_DEBUG(ENG_DEBUG, "headset is connected");
2971         }
2972
2973         if (TRUE == earjack_connected || TRUE == headset_connected) {
2974                 g_idle_add(__voicecall_core_auto_answer_idle_cb, pcall_core);
2975         } else {
2976                 CALL_ENG_DEBUG(ENG_DEBUG, "Without earjack or headset, skip auto answer ");
2977                 return;
2978         }
2979 }
2980
2981 /**
2982 * This function cancels the auto answering timer
2983 *
2984 * @return               void
2985 * @param[in]            pcall_core              Handle to voicecall core
2986 */
2987 static void __voicecall_core_cancel_auto_answer(call_vc_core_state_t *pcall_core)
2988 {
2989         CALL_ENG_DEBUG(ENG_DEBUG, "coming inside __voicecall_cancel_auto_answer");
2990         if (pcall_core->auto_answer_timer > 0) {
2991                 g_source_remove(pcall_core->auto_answer_timer);
2992                 pcall_core->auto_answer_timer = 0;
2993         }
2994 }
2995
2996 #if 0
2997 /**
2998 * This function checks BT headset and Earjack status
2999 *
3000 * @return               void
3001 * @param[in]            pcall_core              Handle to voicecall core
3002 */
3003 static void __voicecall_core_check_headset_earjack_status(call_vc_core_state_t *pcall_core)
3004 {
3005         gboolean bt_connected = FALSE;
3006
3007         bt_connected = _vc_bt_get_bt_status();
3008         CALL_ENG_DEBUG(ENG_DEBUG, "Bt connected =%d", bt_connected);
3009
3010         pcall_core->bt_connected = bt_connected;
3011
3012         CALL_ENG_DEBUG(ENG_DEBUG, "Update the earjack status");
3013         _voicecall_dvc_get_earjack_status(pcall_core);
3014 }
3015 #endif
3016
3017 /**
3018  * This function parses the in call supplementary services string and returns the in call ss to be used
3019  *
3020  * @return              Returns in call ss state #vcui_app_incall_ss_state_t
3021  * @param[in]           pcall_core              Handle to voicecall core
3022  * @param[in]           number                  number to be parsed
3023  */
3024 call_vc_core_incall_ss_state_t voicecall_core_parse_incall_ss_string(call_vc_core_state_t *pcall_core, char *number)
3025 {
3026         call_vc_core_incall_ss_state_t ss_value = CALL_VC_CORE_SS_USSD;
3027
3028         if (strlen(number) == 1) {
3029                 switch (number[0]) {
3030                 case '0':
3031                         ss_value = CALL_VC_CORE_SS_0;
3032                         break;
3033                 case '1':
3034                         ss_value = CALL_VC_CORE_SS_1;
3035                         break;
3036                 case '2':
3037                         ss_value = CALL_VC_CORE_SS_2;
3038                         break;
3039                 case '3':
3040                         ss_value = CALL_VC_CORE_SS_3;
3041                         break;
3042                 case '4':
3043                         ss_value = CALL_VC_CORE_SS_4;
3044                         break;
3045                 default:
3046                         ss_value = CALL_VC_CORE_SS_USSD;
3047                         break;
3048                 }
3049         } else if (strlen(number) == 2) {
3050                 if ((number[0] == '1') && (number[1] > '0') && (number[1] < '8')) {
3051                         pcall_core->selected_call_id_in_ss = atoi(number + 1);
3052                         ss_value = CALL_VC_CORE_SS_1X;
3053                 }
3054
3055                 if ((number[0] == '2') && (number[1] > '0') && (number[1] < '8')) {
3056                         pcall_core->selected_call_id_in_ss = atoi(number + 1);
3057                         ss_value = CALL_VC_CORE_SS_2X;
3058                 }
3059         }
3060         CALL_ENG_DEBUG(ENG_DEBUG, "ss parsed value: %d", ss_value);
3061         return ss_value;
3062 }
3063
3064 /**
3065  * This function starts the supplementary services while on call
3066  *
3067  * @return              Returns TRUE If transfer call can be made or FALSE if not
3068  * @param[in]           pcall_core              Handle to voicecall core
3069  * @param[in]           incall_ss_state         state of the In Call Supplementary Service
3070  */
3071 gboolean voicecall_core_start_incall_ss(call_vc_core_state_t *pcall_core, call_vc_core_incall_ss_state_t incall_ss_state)
3072 {
3073         gboolean active_calls = FALSE, held_calls = FALSE;
3074
3075         _vc_core_engine_status_isexists_any_call(pcall_core->pcall_engine, &active_calls, &held_calls);
3076
3077         CALL_ENG_DEBUG(ENG_DEBUG, "ss state = %d", incall_ss_state);
3078         vc_engine_msg_box_type event_data;
3079         memset(&event_data, 0, sizeof(event_data));
3080         event_data.string_id = IDS_CALL_POP_OPERATION_REFUSED;
3081
3082         /*Cancel DTMF Sending if any and close the dtmf ui */
3083         /* vcui_app_doc_cancel_dtmf_queue(papp_document); sathwick TBD */
3084
3085         switch (incall_ss_state) {
3086                 /* Releases all held calls or Set UDUB(User Determined User Busy) for a waiting call */
3087         case CALL_VC_CORE_SS_0:
3088                 {
3089                         /* if an incoming call is activated, reject the incoming all  */
3090                         if (TRUE == voicecall_core_is_incoming_call_exists(pcall_core->pcall_engine)) {
3091                                 voicecall_core_reject_mt(pcall_core, TRUE);
3092                                 return TRUE;
3093                         } else if (held_calls) {
3094                                 voicecall_core_end_all_held_calls(pcall_core);
3095                         } else {
3096                                 CALL_ENG_DEBUG(ENG_DEBUG, "There are no held calls to do the processing");
3097                                 vcall_engine_send_event_to_client(VC_ENGINE_MSG_MESSAGE_BOX_TO_UI, (void *)&event_data);
3098                                 CALL_ENG_DEBUG(ENG_DEBUG, "Need to show a popup to the user ");
3099                         }
3100                 }
3101                 break;
3102         case CALL_VC_CORE_SS_1:
3103                 {
3104                         if (voicecall_core_is_incoming_call_exists(pcall_core->pcall_engine)) {
3105                                 /* Accept incoming call */
3106                                 voicecall_core_answer_call_bytype(pcall_core, VC_ANSWER_RELEASE_ACTIVE_AND_ACCEPT);
3107                                 return TRUE;
3108                         } else if (voicecall_core_is_outgoing_call_exists(pcall_core->pcall_engine)) {
3109                                 /* This fucntion checks for held calls to be retreived on response of ending call */
3110                                 voicecall_core_set_check_ss_on_end(pcall_core);
3111                                 voicecall_core_end_mo_call(pcall_core->pcall_engine);
3112                         } else if (active_calls) {
3113                                 voicecall_core_end_all_active_calls(pcall_core);
3114                                 voicecall_core_set_check_ss_on_end(pcall_core);
3115                         } else if (held_calls) {
3116                                 _vc_core_engine_retrieve_call(pcall_core->pcall_engine);
3117                         } else {
3118
3119                                 CALL_ENG_DEBUG(ENG_DEBUG, "Need to show a popup to the user ");
3120                                 vcall_engine_send_event_to_client(VC_ENGINE_MSG_MESSAGE_BOX_TO_UI, (void *)&event_data);
3121                         }
3122                 }
3123                 break;
3124         case CALL_VC_CORE_SS_1X:
3125                 {
3126                         if (voicecall_core_is_incoming_call_exists(pcall_core->pcall_engine)) {
3127
3128                                 CALL_ENG_DEBUG(ENG_DEBUG, "Need to show a popup to the user ");
3129                                 vcall_engine_send_event_to_client(VC_ENGINE_MSG_MESSAGE_BOX_TO_UI, (void *)&event_data);
3130                         } else if (active_calls) {
3131
3132                                 if (!(ERROR_VOICECALL_NONE == _vc_core_engine_end_call_bycallId(pcall_core->pcall_engine, pcall_core->selected_call_id_in_ss))) {
3133
3134                                         CALL_ENG_DEBUG(ENG_DEBUG, "Need to show a popup to the user ");
3135                                         vcall_engine_send_event_to_client(VC_ENGINE_MSG_MESSAGE_BOX_TO_UI, (void *)&event_data);
3136                                 }
3137                         } else {
3138
3139                                 CALL_ENG_DEBUG(ENG_DEBUG, "Need to show a popup to the user ");
3140                                 vcall_engine_send_event_to_client(VC_ENGINE_MSG_MESSAGE_BOX_TO_UI, (void *)&event_data);
3141                         }
3142                 }
3143                 break;
3144         case CALL_VC_CORE_SS_2:
3145                 {
3146
3147                         if (voicecall_core_is_incoming_call_exists(pcall_core->pcall_engine)) {
3148                                 if (active_calls && held_calls) {
3149
3150                                         CALL_ENG_DEBUG(ENG_DEBUG, "Need to show a popup to the user ");
3151                                         vcall_engine_send_event_to_client(VC_ENGINE_MSG_MESSAGE_BOX_TO_UI, (void *)&event_data);
3152                                 } else {
3153 #ifdef _CPHS_DEFINED_           /* Not used currently */
3154                                         if (TRUE == active_calls && (voicecall_core_get_cphs_csp_status(pcall_core->pcall_engine, VC_CPHS_CSP_HOLD))) {
3155
3156                                                 CALL_ENG_DEBUG(ENG_DEBUG, "Need to show a popup to the user ");
3157                                                 vcall_engine_send_event_to_client(VC_ENGINE_MSG_MESSAGE_BOX_TO_UI, (void *)&event_data);
3158                                                 break;
3159                                         }
3160 #endif
3161                                         voicecall_core_answer_call(pcall_core, TRUE);
3162                                 }
3163                         } else if (voicecall_core_is_outgoing_call_exists(pcall_core->pcall_engine)) {
3164
3165                                 CALL_ENG_DEBUG(ENG_DEBUG, "Need to show a popup to the user ");
3166                                 vcall_engine_send_event_to_client(VC_ENGINE_MSG_MESSAGE_BOX_TO_UI, (void *)&event_data);
3167                         } else if (active_calls && held_calls) {
3168                                 _vc_core_engine_swap_calls(pcall_core->pcall_engine);
3169                         } else if (active_calls) {
3170                                 _vc_core_engine_hold_call(pcall_core->pcall_engine);
3171                         } else if (held_calls) {
3172                                 _vc_core_engine_retrieve_call(pcall_core->pcall_engine);
3173                         } else {
3174
3175                                 CALL_ENG_DEBUG(ENG_DEBUG, "Need to show a popup to the user ");
3176                                 vcall_engine_send_event_to_client(VC_ENGINE_MSG_MESSAGE_BOX_TO_UI, (void *)&event_data);
3177                         }
3178                 }
3179                 break;
3180         case CALL_VC_CORE_SS_2X:
3181                 {
3182                         if (voicecall_core_is_incoming_call_exists(pcall_core->pcall_engine) || voicecall_core_is_outgoing_call_exists(pcall_core->pcall_engine)) {
3183
3184                                 vcall_engine_send_event_to_client(VC_ENGINE_MSG_MESSAGE_BOX_TO_UI, (void *)&event_data);
3185                                 CALL_ENG_DEBUG(ENG_DEBUG, "Need to show a popup to the user ");
3186                         } else if (TRUE == active_calls && FALSE == held_calls) {
3187                                 int active_members = 0;
3188
3189                                 voicecall_core_get_active_call_member(pcall_core, &active_members);
3190
3191                                 if (!(active_members > 1 && (ERROR_VOICECALL_NONE == _vc_core_engine_private_call_by_callid(pcall_core->pcall_engine, pcall_core->selected_call_id_in_ss)))) {
3192
3193                                         CALL_ENG_DEBUG(ENG_DEBUG, "Need to show a popup to the user ");
3194                                         vcall_engine_send_event_to_client(VC_ENGINE_MSG_MESSAGE_BOX_TO_UI, (void *)&event_data);
3195                                 }
3196                         } else {
3197
3198                                 CALL_ENG_DEBUG(ENG_DEBUG, "Need to show a popup to the user ");
3199                                 vcall_engine_send_event_to_client(VC_ENGINE_MSG_MESSAGE_BOX_TO_UI, (void *)&event_data);
3200                         }
3201                 }
3202                 break;
3203         case CALL_VC_CORE_SS_3:
3204                 {
3205                         if (TRUE == voicecall_core_is_incoming_call_exists(pcall_core->pcall_engine)) {
3206
3207                                 CALL_ENG_DEBUG(ENG_DEBUG, "Need to show a popup to the user ");
3208                                 vcall_engine_send_event_to_client(VC_ENGINE_MSG_MESSAGE_BOX_TO_UI, (void *)&event_data);
3209                                 return TRUE;
3210                         }
3211
3212                         if (TRUE == voicecall_core_is_conf_call_possible(pcall_core)) {
3213                                 _vc_core_engine_setup_conference(pcall_core->pcall_engine);
3214                         } else {
3215
3216                                 CALL_ENG_DEBUG(ENG_DEBUG, "Need to show a popup to the user ");
3217                                 vcall_engine_send_event_to_client(VC_ENGINE_MSG_MESSAGE_BOX_TO_UI, (void *)&event_data);
3218                         }
3219                 }
3220                 break;
3221         case CALL_VC_CORE_SS_4:
3222                 if (TRUE == voicecall_core_is_transfer_call_possible(pcall_core)) {
3223                         if (FALSE == voicecall_core_transfer_calls(pcall_core)) {
3224
3225                                 CALL_ENG_DEBUG(ENG_DEBUG, "Need to show a popup to the user ");
3226                                 vcall_engine_send_event_to_client(VC_ENGINE_MSG_MESSAGE_BOX_TO_UI, (void *)&event_data);
3227                         }
3228                 } else {
3229
3230                         CALL_ENG_DEBUG(ENG_DEBUG, "Need to show a popup to the user ");
3231                         vcall_engine_send_event_to_client(VC_ENGINE_MSG_MESSAGE_BOX_TO_UI, (void *)&event_data);
3232                 }
3233                 break;
3234         default:
3235                 CALL_ENG_DEBUG(ENG_DEBUG, "Invalid SS State");
3236                 CALL_ENG_DEBUG(ENG_DEBUG, "Need to show a popup to the user ");
3237                 vcall_engine_send_event_to_client(VC_ENGINE_MSG_MESSAGE_BOX_TO_UI, (void *)&event_data);
3238         }
3239         return TRUE;
3240 }
3241
3242 /**
3243  * This function processed the supplementary services while on call
3244  *
3245  * @return              Returns TRUE If transfer call can be made or FALSE if not
3246  * @param[in]           pcall_core              Handle to voicecall core
3247  * @param[in]           pdialled_number         dial number
3248  */
3249 void voicecall_core_process_incall_ss(call_vc_core_state_t *pcall_core, char *pdialled_number)
3250 {
3251         call_vc_core_incall_ss_state_t incall_ss_state = CALL_VC_CORE_SS_NONE;
3252
3253         CALL_ENG_DEBUG(ENG_DEBUG, " ..");
3254
3255         incall_ss_state = voicecall_core_parse_incall_ss_string(pcall_core, pdialled_number);
3256
3257         if (incall_ss_state != CALL_VC_CORE_SS_USSD) {
3258                 voicecall_core_start_incall_ss(pcall_core, incall_ss_state);
3259         } else {
3260
3261                 CALL_ENG_DEBUG(ENG_DEBUG, "Involves CISS functionality so need for us to handle and will be handled by CISS");
3262                 vc_engine_msg_box_type event_data;
3263                 memset(&event_data, 0, sizeof(event_data));
3264                 event_data.string_id = IDS_CALL_POP_OPERATION_REFUSED;
3265                 vcall_engine_send_event_to_client(VC_ENGINE_MSG_MESSAGE_BOX_TO_UI, (void *)&event_data);
3266         }
3267 }
3268
3269 #ifdef  PDIAL_SEND_DTMF
3270 gboolean voicecall_core_send_phone_number_dtmf(gpointer puser_data)
3271 {
3272         call_vc_core_state_t *pcall_core = (call_vc_core_state_t *)vcall_engine_get_core_state();
3273         int call_handle = (int)puser_data;
3274         char dtmf_number[VC_PHONE_NUMBER_LENGTH_MAX];
3275         call_vc_call_objectinfo_t obj_info = { 0, };
3276
3277         CALL_ENG_DEBUG(ENG_DEBUG, "inside ...");
3278
3279         if (TRUE == _vc_core_cm_get_call_object(&pcall_core->pcall_engine->call_manager, call_handle, &obj_info)) {
3280                 CALL_ENG_DEBUG(ENG_DEBUG, "Source telephone number - %s", obj_info.source_tel_number);
3281                 if (TRUE == _vc_core_util_extract_dtmf_number(obj_info.source_tel_number, dtmf_number, sizeof(dtmf_number))) {
3282                         CALL_ENG_DEBUG(ENG_DEBUG, "DTMF number - %s", dtmf_number);
3283                         if (VC_CALL_ORIG_TYPE_SAT == pcall_core->call_setup_info.call_type) {
3284                                 __voicecall_core_queue_dtmf_string(pcall_core, dtmf_number, TRUE);
3285                         } else {
3286                                 __voicecall_core_queue_dtmf_string(pcall_core, dtmf_number, FALSE);
3287                         }
3288                 }
3289         } else {
3290                 CALL_ENG_DEBUG(ENG_DEBUG, "Call Info not available for call handle: %d", call_handle);
3291         }
3292
3293         return FALSE;
3294 }
3295
3296 /**
3297  * This function cancels the dtmf queue
3298  *
3299  * @return              TRUE - sucess, FALSE otherwise
3300  * @param[in]           papp_document           Handle to Application Document
3301  */
3302 gboolean voicecall_core_cancel_dtmf_queue(call_vc_core_state_t *pcall_core)
3303 {
3304         voicecall_dtmf_info_t *pdtmf_info = (voicecall_dtmf_info_t *)&pcall_core->dtmf_info;
3305
3306         CALL_ENG_DEBUG(ENG_DEBUG, "Start:pcall_core(%p)", pcall_core);
3307
3308         if (FALSE == pdtmf_info->bdtmf_queue) {
3309                 return TRUE;
3310         }
3311
3312         /*Remove Pauser Timer */
3313         if (pdtmf_info->dtmf_pause_timer > 0) {
3314                 g_source_remove(pdtmf_info->dtmf_pause_timer);
3315                 pdtmf_info->dtmf_pause_timer = -1;
3316         }
3317
3318         /*Reset the Status Flags */
3319         pdtmf_info->bdtmf_queue = FALSE;
3320         pdtmf_info->dtmf_index = 0;
3321         pdtmf_info->bdtmf_wait = FALSE;
3322         memset(pdtmf_info->dtmf_number, 0, sizeof(pdtmf_info->dtmf_number));
3323         if (TRUE == pdtmf_info->bsat_dtmf) {
3324                 voicecall_core_send_sat_response(pcall_core->pcall_engine, SAT_RQST_SEND_DTMF, CALL_VC_ME_UNABLE_TO_PROCESS_COMMAND);
3325         }
3326         pdtmf_info->bsat_dtmf = FALSE;
3327         pdtmf_info->bsat_hidden = FALSE;
3328         CALL_ENG_DEBUG(ENG_DEBUG, "End");
3329         return TRUE;
3330 }
3331
3332 static gboolean __voicecall_core_dtmf_pause_timer_cb(gpointer puser_data)
3333 {
3334         call_vc_core_state_t *pcall_core = (call_vc_core_state_t *)puser_data;
3335
3336         __voicecall_core_handle_dtmf_ack(pcall_core, TRUE);
3337
3338         /*Always return FALSE, so that it won't be called again */
3339         return FALSE;
3340 }
3341
3342 gboolean __voicecall_core_send_dtmf_idle_cb(gpointer pdata)
3343 {
3344         call_vc_core_state_t *pcall_core = (call_vc_core_state_t *)pdata;
3345         voicecall_dtmf_info_t *pdtmf_info = (voicecall_dtmf_info_t *)&pcall_core->dtmf_info;
3346         voicecall_error_t vc_error;
3347         vc_engine_dtmf_ack_type event_data;
3348         char dtmf_string[2];
3349
3350         dtmf_string[0] = pdtmf_info->dtmf_number[pdtmf_info->dtmf_index];
3351         dtmf_string[1] = '\0';
3352
3353         CALL_ENG_DEBUG(ENG_DEBUG, "inside ...");
3354
3355         vc_error = _vc_core_engine_send_dtmf(pcall_core->pcall_engine, dtmf_string);
3356
3357         if (vc_error == ERROR_VOICECALL_INVALID_DTMF_CHAR) {
3358                 CALL_ENG_DEBUG(ENG_DEBUG, "ERROR_VOICECALL_INVALID_DTMF_CHAR");
3359         } else if (ERROR_VOICECALL_NONE != vc_error) {
3360                 voicecall_core_cancel_dtmf_queue(pcall_core);
3361                 memset(&event_data, 0, sizeof(event_data));
3362                 event_data.bstatus = FALSE;
3363                 event_data.string_id = IDS_CALL_POP_DTMFSENDING_FAIL;
3364                 vcall_engine_send_event_to_client(VC_ENGINE_MSG_DTMF_ACK_TO_UI, (void *)&event_data);
3365
3366                 if (TRUE == pdtmf_info->bsat_dtmf) {
3367                         voicecall_core_send_sat_response(pcall_core->pcall_engine, SAT_RQST_SEND_DTMF, CALL_VC_ME_UNABLE_TO_PROCESS_COMMAND);
3368                 }
3369
3370                 if (!((TRUE == pdtmf_info->bsat_dtmf) && (TRUE == pdtmf_info->bsat_hidden))) {
3371                         memset(&event_data, 0, sizeof(event_data));
3372                         event_data.bstatus = FALSE;
3373                         event_data.string_id = IDS_CALL_POP_DTMFSENDING_FAIL;
3374                         vcall_engine_send_event_to_client(VC_ENGINE_MSG_DTMF_ACK_TO_UI, (void *)&event_data);
3375                 }
3376         }
3377
3378         return FALSE;
3379 }
3380
3381 static gboolean __voicecall_core_handle_dtmf_ack(call_vc_core_state_t *pcall_core, gboolean success)
3382 {
3383         voicecall_dtmf_info_t *pdtmf_info = (voicecall_dtmf_info_t *)&pcall_core->dtmf_info;
3384         vc_engine_dtmf_ack_type event_data;
3385         CALL_ENG_DEBUG(ENG_DEBUG, "...");
3386
3387         if (FALSE == pdtmf_info->bdtmf_queue) {
3388                 CALL_ENG_DEBUG(ENG_DEBUG, "DTMF Queue Canceled, do nothing");
3389                 return TRUE;
3390         }
3391
3392         if (TRUE == success) {
3393                 char dtmf_string[2];
3394                 pdtmf_info->dtmf_index++;
3395
3396                 dtmf_string[0] = pdtmf_info->dtmf_number[pdtmf_info->dtmf_index];
3397                 dtmf_string[1] = '\0';
3398
3399                 CALL_ENG_DEBUG(ENG_DEBUG, "Current dtmf_index: %d,dtmf_max_length=%d", pdtmf_info->dtmf_index, pdtmf_info->dtmf_max_length);
3400                 CALL_ENG_DEBUG(ENG_DEBUG, "Current DTMF String: %s", &pdtmf_info->dtmf_number[pdtmf_info->dtmf_index]);
3401
3402                 /*Find the End of the queue */
3403                 if (pdtmf_info->dtmf_index >= pdtmf_info->dtmf_max_length) {
3404
3405                         CALL_ENG_DEBUG(ENG_DEBUG, "Updating DTMF Progress before destroying");
3406
3407                         if (!((TRUE == pdtmf_info->bsat_dtmf) && (TRUE == pdtmf_info->bsat_hidden))) {
3408                                 memset(&event_data, 0, sizeof(event_data));
3409                                 event_data.bstatus = FALSE;     /*check it*/
3410                                 event_data.string_id = IDS_CALL_POP_DTMF_SENT; /*check it*/
3411                                 vcall_engine_send_event_to_client(VC_ENGINE_MSG_DTMF_ACK_TO_UI, (void *)&event_data);
3412                         }
3413
3414                         if (TRUE == pdtmf_info->bsat_dtmf) {
3415                                 voicecall_core_send_sat_response(pcall_core->pcall_engine, SAT_RQST_SEND_DTMF, CALL_VC_ME_RET_SUCCESS);
3416                         }
3417                 } else {
3418                         if (0 == strcasecmp(dtmf_string, "p") || 0 == strcmp(dtmf_string, ",")) {
3419                                 CALL_ENG_DEBUG(ENG_DEBUG, "Pause on the dtmf string");
3420
3421                                 memset(&event_data, 0, sizeof(event_data));
3422                                 event_data.bstatus = TRUE;
3423                                 event_data.string_id = IDS_CALL_POP_SENDING;
3424                                 snprintf(event_data.display_string, sizeof(event_data.display_string), "%s", &pdtmf_info->dtmf_number[pdtmf_info->dtmf_index]);
3425                                 vcall_engine_send_event_to_client(VC_ENGINE_MSG_DTMF_ACK_TO_UI, (void *)&event_data);
3426
3427                                 int dtmf_interval = 0;
3428
3429                                 if (FALSE == _vc_core_util_check_gcf_status()) {
3430                                         dtmf_interval = (pdtmf_info->dtmf_index == 0) ? DTMF_PAUSE_TIMER_INTERVAL_FIRST : DTMF_PAUSE_TIMER_INTERVAL_REST;
3431                                 } else {
3432 #ifdef GCONF_GCF_SAT_TEST
3433                                         int start_interval = DTMF_PAUSE_TIMER_INTERVAL_GCF_FIRST;
3434                                         int rest_interval = DTMF_PAUSE_TIMER_INTERVAL_GCF_REST;
3435                                         {
3436                                                 GConfClient *client = NULL;
3437                                                 client = gconf_client_get_default();
3438                                                 if (NULL == client) {
3439                                                         CALL_ENG_DEBUG(ENG_DEBUG, "gconf_client_get_default failed..");
3440                                                 } else {
3441
3442                                                         start_interval = gconf_client_get_int(client, PATH_DTMF_INTERVAL_GCF_FIRST, NULL);
3443
3444                                                         rest_interval = gconf_client_get_int(client, PATH_DTMF_INTERVAL_GCF_REST, NULL);
3445                                                         g_object_unref(client);
3446                                                 }
3447
3448                                         }
3449                                         CALL_ENG_DEBUG(ENG_DEBUG, "start_interval:%d, rest_interval = %d", start_interval, rest_interval);
3450                                         dtmf_interval = (pdtmf_info->dtmf_index == 0) ? start_interval : rest_interval;
3451 #else
3452                                         dtmf_interval = (pdtmf_info->dtmf_index == 0) ? DTMF_PAUSE_TIMER_INTERVAL_GCF_FIRST : DTMF_PAUSE_TIMER_INTERVAL_GCF_REST;
3453 #endif
3454                                 }
3455                                 CALL_ENG_DEBUG(ENG_DEBUG, "dtmf_interval:%d", dtmf_interval);
3456                                 pdtmf_info->dtmf_pause_timer = g_timeout_add(dtmf_interval, __voicecall_core_dtmf_pause_timer_cb, pcall_core);
3457                         } else if (0 == strcasecmp(dtmf_string, "w") || 0 == strcmp(dtmf_string, ";")) {
3458                                 CALL_ENG_DEBUG(ENG_DEBUG, "Wait on the dtmf string");
3459                                 memset(&event_data, 0, sizeof(event_data));
3460                                 event_data.bstatus = TRUE;
3461                                 event_data.string_id = IDS_CALL_POP_UNAVAILABLE;        /*assign ID when string is added*/
3462                                 snprintf(event_data.display_string, sizeof(event_data.display_string), "%s", &pdtmf_info->dtmf_number[pdtmf_info->dtmf_index]);
3463                                 vcall_engine_send_event_to_client(VC_ENGINE_MSG_DTMF_ACK_TO_UI, (void *)&event_data);
3464                         } else {
3465                                 g_idle_add_full(G_PRIORITY_HIGH_IDLE + 25, __voicecall_core_send_dtmf_idle_cb, pcall_core, NULL);
3466                         }
3467                 }
3468         } else {
3469                 voicecall_core_cancel_dtmf_queue(pcall_core);
3470
3471                 memset(&event_data, 0, sizeof(event_data));
3472                 event_data.bstatus = FALSE;
3473                 event_data.string_id = IDS_CALL_POP_DTMFSENDING_FAIL;
3474                 vcall_engine_send_event_to_client(VC_ENGINE_MSG_DTMF_ACK_TO_UI, (void *)&event_data);
3475         }
3476
3477         return TRUE;
3478 }
3479
3480 /**
3481  * This function queues the dtmf digits one by one from the given dtmf string
3482  *
3483  * @return              TRUE - sucess, FALSE otherwise
3484  * @param[in]           papp_document           Handle to Application Document
3485  * @param[in]           dtmf_string                     dtmf string to be queued
3486  */
3487 static gboolean __voicecall_core_queue_dtmf_string(call_vc_core_state_t *pcall_core, char *dtmf_string, gboolean bsat_dtmf)
3488 {
3489         voicecall_dtmf_info_t *pdtmf_info = (voicecall_dtmf_info_t *)&pcall_core->dtmf_info;
3490         gboolean bhidden_mode = FALSE;
3491         char dtmf_digit[2];
3492         vc_engine_dtmf_ack_type event_data;
3493
3494         CALL_ENG_DEBUG(ENG_DEBUG, "bsat_dtmf = %d", bsat_dtmf);
3495
3496         if (TRUE == bsat_dtmf) {
3497                 /*Always get the status from the engine */
3498                 _vc_core_engine_get_sat_dtmf_hidden_mode(pcall_core->pcall_engine, &bhidden_mode);
3499                 CALL_ENG_DEBUG(ENG_DEBUG, "SAT Hidden Mode : %d", bhidden_mode);
3500         }
3501
3502         /*Check for the validity of the DTMF String */
3503         if (FALSE == _vc_core_util_isvalid_full_dtmf_number(dtmf_string)) {
3504                 if (TRUE == bsat_dtmf) {
3505                         voicecall_core_send_sat_response(pcall_core->pcall_engine, SAT_RQST_SEND_DTMF, CALL_VC_ME_UNABLE_TO_PROCESS_COMMAND);
3506                 }
3507
3508                 if (!((TRUE == bsat_dtmf) && (TRUE == bhidden_mode))) {
3509                         memset(&event_data, 0, sizeof(event_data));
3510                         event_data.bstatus = FALSE;
3511                         event_data.string_id = IDS_CALL_POP_INVALID_DTMF;
3512                         vcall_engine_send_event_to_client(VC_ENGINE_MSG_DTMF_ACK_TO_UI, (void *)&event_data);
3513                 }
3514                 return FALSE;
3515         }
3516
3517         /*Reset DTMF Values */
3518         pdtmf_info->bdtmf_queue = FALSE;
3519         pdtmf_info->dtmf_index = 0;
3520         pdtmf_info->bsat_dtmf = bsat_dtmf;
3521
3522         if (TRUE == bsat_dtmf) {
3523                 /*Initialize */
3524                 pdtmf_info->bsat_hidden = bhidden_mode;
3525         }
3526
3527         /*It takes only 40 characters from the source, rest of the characters are ignored*/
3528         memset(pdtmf_info->dtmf_number, 0, sizeof(pdtmf_info->dtmf_number));
3529         strncpy(pdtmf_info->dtmf_number, dtmf_string, min((sizeof(pdtmf_info->dtmf_number) - 1), strlen(dtmf_string)));
3530         pdtmf_info->dtmf_max_length = strlen(pdtmf_info->dtmf_number);
3531         CALL_ENG_DEBUG(ENG_DEBUG, "Dtmf Number:%s ,dtmf_max_length:%d", pdtmf_info->dtmf_number, pdtmf_info->dtmf_max_length);
3532
3533         dtmf_digit[0] = pdtmf_info->dtmf_number[pdtmf_info->dtmf_index];
3534         dtmf_digit[1] = '\0';
3535
3536         /*Send DTMF */
3537         if (0 == strcasecmp(dtmf_digit, "p") || 0 == strcmp(dtmf_digit, ",")) {
3538                 int dtmf_interval = 0;
3539
3540                 if (FALSE == _vc_core_util_check_gcf_status()) {
3541                         dtmf_interval = (pdtmf_info->dtmf_index == 0) ? DTMF_PAUSE_TIMER_INTERVAL_FIRST : DTMF_PAUSE_TIMER_INTERVAL_REST;
3542                 } else {
3543 #ifdef GCONF_GCF_SAT_TEST
3544                         int start_interval = DTMF_PAUSE_TIMER_INTERVAL_GCF_FIRST;
3545                         int rest_interval = DTMF_PAUSE_TIMER_INTERVAL_GCF_REST;
3546                         {
3547
3548                                 GConfClient *client = NULL;
3549                                 client = gconf_client_get_default();
3550                                 if (NULL == client) {
3551                                         CALL_ENG_DEBUG(ENG_DEBUG, "gconf_client_get_default failed..");
3552                                 } else {
3553
3554                                         start_interval = gconf_client_get_int(client, PATH_DTMF_INTERVAL_GCF_FIRST, NULL);
3555
3556                                         rest_interval = gconf_client_get_int(client, PATH_DTMF_INTERVAL_GCF_REST, NULL);
3557                                         g_object_unref(client);
3558                                 }
3559
3560                         }
3561                         CALL_ENG_DEBUG(ENG_DEBUG, "start_interval:%d, rest_interval = %d", start_interval, rest_interval);
3562                         dtmf_interval = (pdtmf_info->dtmf_index == 0) ? start_interval : rest_interval;
3563 #else
3564                         dtmf_interval = (pdtmf_info->dtmf_index == 0) ? DTMF_PAUSE_TIMER_INTERVAL_GCF_FIRST : DTMF_PAUSE_TIMER_INTERVAL_GCF_REST;
3565 #endif
3566                         CALL_ENG_DEBUG(ENG_DEBUG, "updated dtmf_interval:%d", dtmf_interval);
3567                 }
3568                 pdtmf_info->dtmf_pause_timer = g_timeout_add(dtmf_interval, __voicecall_core_dtmf_pause_timer_cb, pcall_core);
3569         } else if (0 == strcasecmp(dtmf_digit, "w") || 0 == strcmp(dtmf_digit, ";")) {
3570                 /* enable wait flag for dtmf sending */
3571                 pdtmf_info->bdtmf_wait = TRUE;
3572         } else if ((ERROR_VOICECALL_NONE != _vc_core_engine_send_dtmf(pcall_core->pcall_engine, dtmf_digit))) {
3573                 if (!((TRUE == pdtmf_info->bsat_dtmf) && (TRUE == pdtmf_info->bsat_hidden))) {
3574                         memset(&event_data, 0, sizeof(event_data));
3575                         event_data.bstatus = FALSE;
3576                         event_data.string_id = IDS_CALL_POP_DTMFSENDING_FAIL;
3577                         vcall_engine_send_event_to_client(VC_ENGINE_MSG_DTMF_ACK_TO_UI, (void *)&event_data);
3578                 }
3579                 if (TRUE == pdtmf_info->bsat_dtmf) {
3580                         voicecall_core_send_sat_response(pcall_core->pcall_engine, SAT_RQST_SEND_DTMF, CALL_VC_ME_UNABLE_TO_PROCESS_COMMAND);
3581                 }
3582                 return FALSE;
3583         }
3584         pdtmf_info->bdtmf_queue = TRUE;
3585
3586         /*Create Progressbar popup */
3587         if (!((TRUE == pdtmf_info->bsat_dtmf) && (TRUE == pdtmf_info->bsat_hidden))) {
3588                 memset(&event_data, 0, sizeof(event_data));
3589                 event_data.bstatus = TRUE;
3590                 CALL_ENG_DEBUG(ENG_DEBUG, "pdtmf_info->bdtmf_wait [%d]", pdtmf_info->bdtmf_wait);
3591                 if (pdtmf_info->bdtmf_wait) {
3592                         event_data.string_id = IDS_CALL_POP_UNAVAILABLE;
3593                 } else {
3594                         event_data.string_id = IDS_CALL_POP_SENDING;
3595                 }
3596                 _vc_core_util_strcpy(event_data.display_string, VC_PHONE_NUMBER_LENGTH_MAX, pdtmf_info->dtmf_number);
3597                 vcall_engine_send_event_to_client(VC_ENGINE_MSG_DTMF_ACK_TO_UI, (void *)&event_data);
3598         } else {
3599                 CALL_ENG_DEBUG(ENG_DEBUG, "SAT DTMF Hidden Mode, not showing UI");
3600         }
3601         return TRUE;
3602 }
3603 #endif
3604
3605 gboolean voicecall_core_change_sound_path(call_vc_core_state_t *pcall_core, voicecall_snd_audio_type_t sound_path)
3606 {
3607         voicecall_snd_mgr_t *papp_snd = pcall_core->papp_snd;
3608         int ret = FALSE;
3609         int total_call_member = -1;
3610
3611         CALL_ENG_DEBUG(ENG_DEBUG, "sound_path:[%d]", sound_path);
3612
3613         voicecall_core_get_total_call_member(pcall_core->pcall_engine, &total_call_member);
3614         if (total_call_member == 0) {
3615                 CALL_ENG_DEBUG(ENG_DEBUG, "There are not active calls hence it should not work");
3616                 return FALSE;
3617         }
3618
3619         switch (sound_path) {
3620         case VOICE_CALL_AUDIO_SPEAKER:
3621                 {
3622                         if (voicecall_snd_get_path_status(pcall_core->papp_snd) == VOICE_CALL_SND_PATH_BT) {
3623                                 /*_vc_bt_send_response_to_bt(pcall_core, BT_AG_RES_SWITCH_TO_PHONE, -1, NULL);*/
3624                                 _vc_bt_request_switch_headset_path(pcall_core, FALSE);
3625                         }
3626                         voicecall_snd_set_path_status(pcall_core->papp_snd, VOICE_CALL_SND_PATH_SPEAKER);
3627                         ret = TRUE;
3628                 }
3629                 break;
3630
3631         case VOICE_CALL_AUDIO_HEADSET:
3632                 {
3633                         voicecall_snd_set_path_status(pcall_core->papp_snd, VOICE_CALL_SND_PATH_BT);
3634 /*                      _vc_bt_send_response_to_bt(pcall_core, BT_AG_RES_SWITCH_TO_HEADSET, -1, NULL);*/
3635                         _vc_bt_request_switch_headset_path(pcall_core, TRUE);
3636
3637                         ret = TRUE;
3638                 }
3639                 break;
3640
3641         case VOICE_CALL_AUDIO_RECEIVER_EARJACK:
3642                 {
3643                         if (voicecall_snd_get_path_status(pcall_core->papp_snd) == VOICE_CALL_SND_PATH_BT) {
3644                                 /*_vc_bt_send_response_to_bt(pcall_core, BT_AG_RES_SWITCH_TO_PHONE, -1, NULL);*/
3645                                 _vc_bt_request_switch_headset_path(pcall_core, FALSE);
3646                         }
3647                         voicecall_snd_set_path_status(pcall_core->papp_snd, VOICE_CALL_SND_PATH_RECEIVER_EARJACK);
3648                         ret = TRUE;
3649                 }
3650                 break;
3651
3652         default:
3653                 {
3654                         CALL_ENG_DEBUG(ENG_DEBUG, "Unknown type!!");
3655                         ret = FALSE;
3656                 }
3657                 break;
3658         }
3659
3660         /* Change Audio Path according to the current status */
3661         voicecall_snd_change_path(papp_snd);
3662
3663         return ret;
3664 }
3665
3666 gboolean voicecall_core_get_sound_path(call_vc_core_state_t *pcall_core, int *sound_path)
3667 {
3668         voicecall_snd_mgr_t *papp_snd = pcall_core->papp_snd;
3669
3670         CALL_ENG_DEBUG(ENG_DEBUG, "..");
3671
3672         switch (voicecall_snd_get_path_status(papp_snd)) {
3673         case VOICE_CALL_SND_PATH_SPEAKER:
3674                 {
3675                         *sound_path = VOICE_CALL_AUDIO_SPEAKER;
3676                 }
3677                 break;
3678
3679         case VOICE_CALL_SND_PATH_BT:
3680                 {
3681                         *sound_path = VOICE_CALL_AUDIO_HEADSET;
3682                 }
3683                 break;
3684
3685         case VOICE_CALL_SND_PATH_RECEIVER_EARJACK:
3686         default:
3687                 {
3688                         *sound_path = VOICE_CALL_AUDIO_RECEIVER_EARJACK;
3689                 }
3690                 break;
3691         }
3692
3693         return TRUE;
3694 }
3695
3696 static gboolean __voicecall_core_is_redial_cuase(int end_cause)
3697 {
3698         CALL_ENG_DEBUG(ENG_DEBUG, "end_cause(%d)", end_cause);
3699
3700         switch (end_cause) {
3701         case VC_ENDCAUSE_CALL_BARRED:
3702         case VC_ENDCAUSE_NO_SERVICE:
3703         case VC_ENDCAUSE_USER_UNAVAILABLE:
3704         case VC_ENDCAUSE_INVALID_NUMBER_FORMAT:
3705         case VC_ENDCAUSE_NUMBER_CHANGED:
3706         case VC_ENDCAUSE_NO_CREDIT:
3707         case VC_ENDCAUSE_UNASSIGNED_NUMBER:
3708                 return FALSE;
3709
3710         case VC_ENDCAUSE_CALL_ENDED:
3711         case VC_ENDCAUSE_CALL_DISCONNECTED:
3712         case VC_ENDCAUSE_NO_ANSWER:
3713         case VC_ENDCAUSE_NW_BUSY:
3714         case VC_ENDCAUSE_CALL_SERVICE_NOT_ALLOWED:
3715         case VC_ENDCAUSE_NW_FAILED:
3716         case VC_ENDCAUSE_REJECTED:
3717         case VC_ENDCAUSE_USER_BUSY:
3718         case VC_ENDCAUSE_WRONG_GROUP:
3719         case VC_ENDCAUSE_CALL_NOT_ALLOWED:
3720         case VC_ENDCAUSE_CALL_FAILED:
3721         case VC_ENDCAUSE_NO_USER_RESPONDING:
3722         case VC_ENDCAUSE_USER_ALERTING_NO_ANSWER:
3723         case VC_ENDCAUSE_SERVICE_TEMP_UNAVAILABLE:
3724         case VC_ENDCAUSE_USER_DOESNOT_RESPOND:
3725         case VC_ENDCAUSE_IMEI_REJECTED:
3726         case VC_ENDCAUSE_TAPI_ERROR:
3727         default:
3728                 return TRUE;
3729         }
3730 }
3731
3732 /**
3733  * This function processed the supplementary services while on call
3734  *
3735  * @return              Returns TRUE If transfer call can be made or FALSE if not
3736  * @param[in]           pcall_core              Handle to voicecall core
3737  */
3738 void voicecall_core_process_dtmf_send_status(call_vc_core_state_t *pcall_core, gboolean bsuccess)
3739 {
3740         CALL_ENG_DEBUG(ENG_DEBUG, " ..");
3741         VOICECALL_RETURN_IF_FAIL(pcall_core);
3742         __voicecall_core_handle_dtmf_ack(pcall_core, bsuccess);
3743 }
3744