Fixed N_SE-9138
[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 "vc-core-engine.h"
34
35 #include "voice-call-engine.h"
36
37 #define MO_REDIAL_COUNT_MAX 10
38 #define MO_REDIAL_TIMER_INTERVAL_FIRST  3000    /**< MO Redial Timer Interva; - 5 Secs*/
39 #define MO_REDIAL_TIMER_INTERVAL_SECOND         3000    /**< MO Redial Timer Interva; - 1 Minute*/
40 #define MO_REDIAL_TIMER_INTERVAL_THIRD  3000    /**< MO Redial Timer Interva; - 3 Minutes*/
41
42 #define MINUTE_MINDER_TIMEOUT_VALUE     60000
43
44 #define DTMF_PAUSE_TIMER_INTERVAL_FIRST         3000    /*3 Seconds */
45 #define DTMF_PAUSE_TIMER_INTERVAL_REST                  3000    /*3 Seconds */
46 #define DTMF_PAUSE_TIMER_INTERVAL_GCF_FIRST     800     /*0.8 Second */
47 #define DTMF_PAUSE_TIMER_INTERVAL_GCF_REST              3300    /*3 Seconds */
48
49 gboolean mo_redial_timer_cb(void *data);
50
51 #define SET_PATH_TIMER_VALUE    50
52 static guint g_set_path_timer_handler = 0;
53 static gboolean __voicecall_core_set_path_timer_cb(gpointer puser_data);
54 static gboolean __voicecall_core_check_incoming_handle(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                         /* send to ui */
995                         event_data.call_handle = call_handle;
996                         event_data.brejected = brejected_number;
997                         _vc_core_util_strcpy(event_data.call_num, sizeof(event_data.call_num), tel_number);
998
999                         vcall_engine_send_event_to_client(VC_ENGINE_MSG_INCOM_TO_UI, (void *)&event_data);
1000
1001                         {
1002                                 /* in case of rejected number, sound & callstatus is not processed */
1003                                 if (!brejected_number) {
1004                                         gboolean benabledTestMode = FALSE;
1005                                         voicecall_snd_register_cm(pcall_core->papp_snd);
1006
1007                                         /*Send Incoming Call Event to Blue Tooth */
1008                                         _vc_bt_send_response_to_bt(pcall_core, BT_AG_RES_CALL_INCOM, call_handle, tel_number);
1009
1010                                         _vc_core_util_set_call_status(VCONFKEY_CALL_VOICE_CONNECTING);
1011
1012                                         benabledTestMode = __vc_core_is_answermode_enabled_from_testmode();
1013                                         if ((TRUE == __vc_core_is_answermode_enabled()) || (TRUE == benabledTestMode)) {
1014                                                 CALL_ENG_DEBUG(ENG_DEBUG, "auto answer mode is enabled.");
1015                                                 __voicecall_core_start_auto_answer(pcall_core, benabledTestMode);
1016                                         }
1017
1018                                         CALL_ENG_DEBUG(ENG_DEBUG, "Preparing Sound ");
1019                                         voicecall_snd_prepare_alert(pcall_core->papp_snd, call_handle);
1020                                         if (FALSE == voicecall_core_is_connected_call_exist(pcall_core->pcall_engine)) {
1021                                                 CALL_ENG_DEBUG(ENG_DEBUG, "Changing MM Path just before playing the ring tone");
1022                                                 sound_manager_call_session_set_mode(pcall_core->papp_snd->psnd_session, SOUND_CALL_SESSION_MODE_RINGTONE);
1023                                         } else {
1024                                                 CALL_ENG_DEBUG(ENG_DEBUG, "2nd MT call alert.");
1025                                         }
1026                                         voicecall_snd_play_alert(pcall_core->papp_snd);
1027
1028                                         pcall_core->mtcall_handle = call_handle;
1029                                         g_idle_add(__voicecall_core_check_incoming_handle, pcall_core);
1030                                 }
1031                         }
1032                 }
1033                 break;
1034
1035         case VC_CALL_OUTGOING:
1036                 {
1037                         int call_handle = param1;
1038                         vc_engine_common_with_handle_type event_data;
1039                         memset(&event_data, 0, sizeof(event_data));
1040
1041                         CALL_ENG_DEBUG(ENG_DEBUG, "MO Call Start: Call handle %d", call_handle);
1042                 }
1043                 break;
1044
1045         case VC_CALL_OUTGOING_ORIG:
1046                 {
1047                         int call_handle = param1;
1048                         vc_engine_outgoing_orig_type event_data;
1049                         call_vc_call_objectinfo_t callobject_info;
1050
1051                         memset(&event_data, 0, sizeof(event_data));
1052                         event_data.call_handle = call_handle;
1053                         if (pcall_core->call_setup_info.call_type == VC_CALL_ORIG_TYPE_EMERGENCY) {
1054                                 event_data.bemergency = TRUE;
1055                         } else {
1056                                 event_data.bemergency = FALSE;
1057                         }
1058
1059                         CALL_ENG_DEBUG(ENG_DEBUG, "Call Handle = %d, bemergency:[%d]", event_data.call_handle, event_data.bemergency);
1060                         vcall_engine_send_event_to_client(VC_ENGINE_MSG_OUTGOING_ORIG_TO_UI, (void *)&event_data);
1061
1062                         g_set_path_timer_handler = g_timeout_add(SET_PATH_TIMER_VALUE, __voicecall_core_set_path_timer_cb, pcall_core);
1063
1064                         /*Send Event to Blue Tooth */
1065                         voicecall_core_get_call_object(pcall_engine, call_handle, &callobject_info);
1066                         _vc_bt_send_response_to_bt(pcall_core, BT_AG_RES_CALL_ORIG, call_handle, callobject_info.tel_number);
1067                 }
1068                 break;
1069
1070         case VC_CALL_OUTGOING_ALERT:
1071                 {
1072                         int call_handle = param1;
1073                         vc_engine_common_with_handle_type event_data;
1074
1075                         memset(&event_data, 0, sizeof(event_data));
1076
1077                         event_data.call_handle = call_handle;
1078
1079                         vcall_engine_send_event_to_client(VC_ENGINE_MSG_OUTGOING_ALERT_TO_UI, (void *)&event_data);
1080
1081                         /*Play Connected Effect Tone */
1082                         CALL_ENG_KPI("voicecall_snd_play_effect_tone start");
1083                         if (FALSE == voicecall_snd_play_effect_tone(pcall_core->papp_snd, VOICE_CALL_SND_EFFECT_CALL_CONNECT)) {
1084                                 CALL_ENG_DEBUG(ENG_DEBUG, "voicecall_snd_play_effect_tone return value is FALSE");
1085                                 voicecall_snd_change_path(pcall_core->papp_snd);
1086                         }
1087                         CALL_ENG_KPI("voicecall_snd_play_effect_tone done");
1088
1089                         CALL_ENG_KPI("_vc_bt_send_response_to_bt start");
1090                         _vc_bt_send_response_to_bt(pcall_core, BT_AG_RES_CALL_REMOTE_RINGING, call_handle, NULL);
1091                         CALL_ENG_KPI("_vc_bt_send_response_to_bt done");
1092                 }
1093                 break;
1094
1095         case VC_CALL_ANSWER_CNF:
1096                 {
1097                         CALL_ENG_DEBUG(ENG_DEBUG, "Answer confirm");
1098                         if (_vc_core_cm_get_call_member_count(&(pcall_engine->call_manager)) == 1) {
1099                                 CALL_ENG_DEBUG(ENG_DEBUG, "single call state");
1100                                 voicecall_snd_change_path(pcall_core->papp_snd);
1101                         }
1102                 }
1103                 break;
1104
1105         case VC_CALL_CONNECTED:
1106                 {
1107                         int call_handle = param1;
1108                         vc_engine_connected_type event_data;
1109                         int bstatus = FALSE;
1110
1111                         memset(&event_data, 0, sizeof(event_data));
1112
1113                         CALL_ENG_DEBUG(ENG_DEBUG, "Connected Call Handle : %d", call_handle);
1114
1115                         event_data.call_handle = call_handle;
1116                         event_data.bt_status = (int)_vc_bt_get_bt_status();
1117
1118                         vcall_engine_send_event_to_client(VC_ENGINE_MSG_CONNECTED_TO_UI, (void *)&event_data);
1119                         voicecall_snd_stop_alert(pcall_core->papp_snd); /* To stop alert in case of call accept by AT command */
1120                         voicecall_snd_change_path(pcall_core->papp_snd);
1121
1122                         /* Set phone-status value */
1123                         _vc_core_util_set_call_status(VCONFKEY_CALL_VOICE_ACTIVE);
1124
1125                         /* check minute minder */
1126                         if (vconf_get_bool(VCONFKEY_CISSAPPL_MINUTE_MINDER_BOOL, &bstatus)) {
1127                                 CALL_ENG_DEBUG(ENG_ERR, "vconf_get_bool failed.");
1128                         }
1129                         if (bstatus) {
1130                                 if (pcall_core->minute_minder_timer == 0) {
1131                                         pcall_core->minute_minder_timer = g_timeout_add(MINUTE_MINDER_TIMEOUT_VALUE, __voicecall_core_minute_minder, pcall_core);
1132                                 }
1133                         }
1134
1135                         /*Send Event to Blue Tooth */
1136                         _vc_bt_send_response_to_bt(pcall_core, BT_AG_RES_CALL_CONNECT, call_handle, NULL);
1137
1138                         /*Call is accepted, reset the flag */
1139                         voicecall_core_set_status(pcall_core, CALL_VC_CORE_FLAG_ACCEPT_BY_BT, FALSE);
1140
1141
1142                 }
1143                 break;
1144
1145         case VC_CALL_NORMAL_END:
1146                 {
1147                         int call_handle = param1;
1148                         voice_call_end_cause_type_t end_cause = param2;
1149                         vc_engine_normal_end_type event_data;
1150
1151                         memset(&event_data, 0, sizeof(event_data));
1152
1153                         CALL_ENG_DEBUG(ENG_DEBUG, "Normal End Call Handle : %d,End Cause=%d", call_handle, end_cause);
1154
1155                         event_data.call_handle = call_handle;
1156                         event_data.end_cause_type = end_cause;
1157
1158                         __voicecall_core_handle_normal_end(pcall_core, call_handle, end_cause);
1159
1160                         vcall_engine_send_event_to_client(VC_ENGINE_MSG_NORMAL_END_TO_UI, (void *)&event_data);
1161
1162                         /*Send Event to Blue Tooth */
1163                         _vc_bt_send_response_to_bt(pcall_core, BT_AG_RES_CALL_END, call_handle, NULL);
1164                 }
1165                 break;
1166
1167         case VC_CALL_INCOM_END:
1168                 {
1169                         int call_handle = param1;
1170                         vc_engine_common_with_handle_type event_data;
1171
1172                         memset(&event_data, 0, sizeof(event_data));
1173
1174                         CALL_ENG_DEBUG(ENG_DEBUG, "Incoming call End Call Handle: %d", call_handle);
1175
1176                         voicecall_core_set_status(pcall_core, CALL_VC_CORE_FLAG_ACCEPT_BY_BT, FALSE);
1177
1178                         if (TRUE == __voicecall_core_handle_call_end_on_silent_reject(pcall_core, call_handle)) {
1179                                 CALL_ENG_DEBUG(ENG_DEBUG, "Call end processed for silent reject:");
1180                                 return TRUE;
1181                         }
1182
1183                         event_data.call_handle = call_handle;
1184
1185                         __voicecall_core_handle_incoming_call_end(pcall_core, call_handle);
1186
1187                         vcall_engine_send_event_to_client(VC_ENGINE_MSG_INCOM_END_TO_UI, (void *)&event_data);
1188                 }
1189                 break;
1190
1191         case VC_CALL_INCOM_DROPPED:
1192                 {
1193                         CALL_ENG_DEBUG(ENG_DEBUG, "Check it. Not used");
1194                 }
1195                 break;
1196
1197         case VC_CALL_REJECTED_END:
1198                 {
1199                         int call_handle = param1;
1200                         vc_engine_common_with_handle_type event_data;
1201
1202                         memset(&event_data, 0, sizeof(event_data));
1203
1204                         CALL_ENG_DEBUG(ENG_DEBUG, "Rejected call End Call Handle: %d", call_handle);
1205
1206                         event_data.call_handle = call_handle;
1207
1208                         voicecall_core_set_status(pcall_core, CALL_VC_CORE_FLAG_ACCEPT_BY_BT, FALSE);
1209
1210                         __voicecall_core_handle_rejected_call_end(pcall_core, call_handle);
1211
1212                         vcall_engine_send_event_to_client(VC_ENGINE_MSG_REJECTED_END_TO_UI, (void *)&event_data);
1213                 }
1214                 break;
1215
1216         case VC_CALL_OUTGOING_END:
1217                 {
1218                         int call_handle = param1;
1219                         int end_cause_type = param2;
1220                         int bauto_redial = -1;
1221
1222                         CALL_ENG_DEBUG(ENG_DEBUG, "end cause type :[%d]", end_cause_type);
1223                         CALL_ENG_DEBUG(ENG_DEBUG, "bauto_redial:[%d]", bauto_redial);
1224
1225                         if ((TRUE == bauto_redial) && (FALSE == voicecall_core_is_connected_call_exist(pcall_engine))
1226                             && (FALSE == voicecall_core_get_status(pcall_core, CALL_VC_CORE_FLAG_MOCALL_END_BY_USER))
1227                             && (TRUE == __voicecall_core_is_redial_cuase(end_cause_type))) {
1228                                 /* auto redial */
1229                                 CALL_ENG_DEBUG(ENG_DEBUG, "It is auto redial case.");
1230
1231                                 _vc_core_util_set_call_status(VCONFKEY_CALL_OFF);
1232
1233                                 vc_engine_outgoing_end_type event_data;
1234
1235                                 memset(&event_data, 0, sizeof(event_data));
1236                                 event_data.call_handle = call_handle;
1237                                 event_data.end_cause_type = end_cause_type;
1238                                 event_data.bauto_redial = TRUE;
1239                                 vcall_engine_send_event_to_client(VC_ENGINE_MSG_OUTGOING_END_TO_UI, (void *)&event_data);
1240                         } else {
1241                                 __voicecall_core_handle_outgoingcall_end(pcall_core, call_handle, end_cause_type);
1242                         }
1243                 }
1244                 break;
1245
1246         case VC_CALL_OUTGOING_ABORTED:
1247                 {
1248                         vc_engine_common_type event_data;
1249
1250                         memset(&event_data, 0, sizeof(event_data));
1251
1252                         vcall_engine_send_event_to_client(VC_ENGINE_MSG_OUTGOING_ABORTED_TO_UI, (void *)&event_data);
1253                 }
1254                 break;
1255
1256         case VC_CALL_DTMF_ACK:
1257                 {
1258                         gboolean bsuccess = param1;
1259                         CALL_ENG_DEBUG(ENG_DEBUG, "bsuccess:[%d]", bsuccess);
1260                         __voicecall_core_handle_dtmf_ack(pcall_core, bsuccess);
1261                 }
1262                 break;
1263
1264         case VC_CALL_AUTO_REDIAL_CHECK:
1265                 {
1266                         CALL_ENG_DEBUG(ENG_DEBUG, "Check it. Not used");
1267                 }
1268                 break;
1269
1270         case VC_CALL_SS_HELD:
1271                 {
1272                         int call_handle = param1;
1273                         vc_engine_common_type event_data;
1274
1275                         /*  held popup shold not be displayed on outgoing popup */
1276                         memset(&event_data, 0, sizeof(event_data));
1277
1278                         vcall_engine_send_event_to_client(VC_ENGINE_MSG_SS_HELD_TO_UI, (void *)&event_data);
1279
1280                         /*Send Event to Blue Tooth */
1281                         _vc_bt_send_response_to_bt(pcall_core, BT_AG_RES_CALL_HOLD, call_handle, NULL);
1282                 }
1283                 break;
1284
1285         case VC_CALL_SS_RETREIVED:
1286                 {
1287                         int call_handle = param1;
1288                         vc_engine_common_type event_data;
1289
1290                         /*  held popup shold not be displayed on outgoing popup */
1291                         memset(&event_data, 0, sizeof(event_data));
1292                         vcall_engine_send_event_to_client(VC_ENGINE_MSG_SS_RETREIVED_TO_UI, (void *)&event_data);
1293
1294                         /*Send Event to Blue Tooth */
1295                         _vc_bt_send_response_to_bt(pcall_core, BT_AG_RES_CALL_RETRIEVE, call_handle, NULL);
1296                 }
1297                 break;
1298
1299         case VC_CALL_SS_SWAP:
1300                 {
1301                         vc_engine_common_type event_data;
1302
1303                         int call_handle = param1;
1304
1305                         memset(&event_data, 0, sizeof(event_data));
1306
1307                         /* Show Call Swapped Message Box */
1308                         vcall_engine_send_event_to_client(VC_ENGINE_MSG_SS_SWAP_TO_UI, (void *)&event_data);
1309
1310                         _vc_bt_send_response_to_bt(pcall_core, BT_AG_RES_CALL_SWAPPED, call_handle, NULL);
1311                 }
1312                 break;
1313
1314         case VC_CALL_SS_SETUP_CONF:
1315                 {
1316                         vc_engine_common_type event_data;
1317
1318                         memset(&event_data, 0, sizeof(event_data));
1319
1320                         /* Show Call Joined Message Box */
1321                         vcall_engine_send_event_to_client(VC_ENGINE_MSG_SS_SETUP_CONF_TO_UI, (void *)&event_data);
1322
1323                         _vc_bt_send_response_to_bt(pcall_core, BT_AG_RES_CALL_JOINED, 0, NULL);
1324                 }
1325                 break;
1326
1327         case VC_CALL_SS_SPLIT_CONF:
1328                 {
1329                         vc_engine_common_with_handle_type event_data;
1330                         int call_handle = param1;
1331                         CALL_ENG_DEBUG(ENG_DEBUG, "The handle to be split is %d", call_handle);
1332
1333                         memset(&event_data, 0, sizeof(event_data));
1334                         event_data.call_handle = call_handle;
1335
1336                         /* Show Private Call Message Box */
1337                         vcall_engine_send_event_to_client(VC_ENGINE_MSG_SS_SPLIT_CONF_TO_UI, (void *)&event_data);
1338                 }
1339                 break;
1340
1341         case VC_CALL_SS_TRANSFERRED:
1342                 {
1343                         vc_engine_common_type event_data;
1344
1345                         memset(&event_data, 0, sizeof(event_data));
1346
1347                         vcall_engine_send_event_to_client(VC_ENGINE_MSG_SS_TRANSFERRED_TO_UI, (void *)&event_data);
1348                 }
1349                 break;
1350
1351         case VC_CALL_SS_CONNECT_LINE_IND:
1352                 {
1353                         int call_handle = param1;
1354                         char *pconnected_number = (char *)param3;
1355                         vc_engine_msg_box_type event_data;
1356
1357                         CALL_ENG_DEBUG(ENG_DEBUG, "call_handle : [%d]", call_handle);
1358
1359                         /* check whether Call Info for recevice Call Handle exists or not. */
1360
1361                         if ((pconnected_number != NULL) && (strlen(pconnected_number) > 0)) {
1362                                 CALL_ENG_DEBUG(ENG_DEBUG, "connected line ind : [%s]", pconnected_number);
1363
1364                                 memset(&event_data, 0, sizeof(event_data));
1365
1366                                 event_data.string_id = IDS_CALL_POP_CALL_IS_DIVERTED;
1367                                 _vc_core_util_strcpy(event_data.diverted_num, sizeof(event_data.diverted_num), pconnected_number);
1368                         } else {
1369                                 CALL_ENG_DEBUG(ENG_DEBUG, "No conneccted info");
1370                         }
1371
1372                 }
1373                 break;
1374
1375         case VC_CALL_IND_FORWARD:
1376                 {
1377                         vc_engine_ind_forward_type event_data;
1378                         int fwd_type = param1;
1379
1380                         memset(&event_data, 0, sizeof(event_data));
1381                         event_data.fwd_type = fwd_type;
1382
1383                         vcall_engine_send_event_to_client(VC_ENGINE_MSG_IND_FORWARD_TO_UI, (void *)&event_data);
1384                 }
1385                 break;
1386
1387         case VC_CALL_IND_ACTIVATE:
1388                 {
1389                         vc_engine_common_type event_data;
1390
1391                         memset(&event_data, 0, sizeof(event_data));
1392
1393                         vcall_engine_send_event_to_client(VC_ENGINE_MSG_IND_ACTIVATE_TO_UI, (void *)&event_data);
1394                 }
1395                 break;
1396
1397         case VC_CALL_IND_HOLD:
1398                 {
1399                         vc_engine_common_type event_data;
1400                         int call_handle = param1;
1401
1402                         memset(&event_data, 0, sizeof(event_data));
1403
1404                         vcall_engine_send_event_to_client(VC_ENGINE_MSG_IND_HOLD_TO_UI, (void *)&event_data);
1405
1406                         /*Send Event to Blue Tooth */
1407                         _vc_bt_send_response_to_bt(pcall_core, BT_AG_RES_CALL_HOLD, call_handle, NULL);
1408                 }
1409                 break;
1410
1411         case VC_CALL_IND_TRANSFER:
1412                 {
1413                         CALL_ENG_DEBUG(ENG_DEBUG, "Not used.");
1414                 }
1415                 break;
1416
1417         case VC_CALL_IND_SETUPCONFERENCE:
1418                 {
1419                         CALL_ENG_DEBUG(ENG_DEBUG, "Not used.");
1420                 }
1421                 break;
1422
1423         case VC_CALL_IND_BARRING:
1424                 {
1425                         vc_engine_common_type event_data;
1426
1427                         memset(&event_data, 0, sizeof(event_data));
1428
1429                         vcall_engine_send_event_to_client(VC_ENGINE_MSG_IND_BARRING_TO_UI, (void *)&event_data);
1430                 }
1431                 break;
1432
1433         case VC_CALL_IND_WAITING:
1434                 {
1435                         vc_engine_common_type event_data;
1436
1437                         memset(&event_data, 0, sizeof(event_data));
1438
1439                         vcall_engine_send_event_to_client(VC_ENGINE_MSG_IND_WAITING_TO_UI, (void *)&event_data);
1440                 }
1441                 break;
1442
1443         case VC_CALL_IND_CUGINFO:
1444                 {
1445                         CALL_ENG_DEBUG(ENG_DEBUG, "Not used.");
1446                 }
1447                 break;
1448
1449         case VC_CALL_IND_SSNOTIFY:
1450                 {
1451                         vc_engine_ind_ssnotify_type event_data;
1452                         int ss_type = param1;
1453
1454                         memset(&event_data, 0, sizeof(event_data));
1455                         event_data.ss_type = ss_type;
1456
1457                         vcall_engine_send_event_to_client(VC_ENGINE_MSG_IND_SSNOTIFY_TO_UI, (void *)&event_data);
1458                 }
1459                 break;
1460
1461         case VC_CALL_IND_CALLINGNAMEINFO:
1462                 {
1463                         CALL_ENG_DEBUG(ENG_DEBUG, "Not used.");
1464                 }
1465                 break;
1466         case VC_CALL_IND_ACTIVATECCBS_CNF:
1467                 {
1468                         CALL_ENG_DEBUG(ENG_DEBUG, "Not used.");
1469                 }
1470                 break;
1471
1472         case VC_CALL_IND_ACTIVATECCBS_USERINFO:
1473                 {
1474                         CALL_ENG_DEBUG(ENG_DEBUG, "Not used.");
1475                 }
1476                 break;
1477
1478         case VC_CALL_IND_AOC:
1479                 {
1480                         CALL_ENG_DEBUG(ENG_DEBUG, "Not yet.");
1481                 }
1482                 break;
1483
1484         case VC_ERROR_OCCURED:
1485                 {
1486                         int error_code = param1;
1487
1488                         CALL_ENG_DEBUG(ENG_DEBUG, "error code:[%d]", error_code);
1489                         switch (error_code) {
1490                         case ERROR_VOICECALL_INVALID_DTMF_CHAR:
1491                         case ERROR_VOICECALL_DTMF_FAILED:
1492                                 {
1493                                         vc_engine_error_occured_type event_data;
1494
1495                                         memset(&event_data, 0, sizeof(event_data));
1496                                         event_data.error_code = error_code;
1497
1498                                         vcall_engine_send_event_to_client(VC_ENGINE_MSG_ERROR_OCCURED_TO_UI, (void *)&event_data);
1499                                 }
1500                                 break;
1501                         default:
1502                                 {
1503                                         vc_engine_msg_box_type event_data;
1504                                         int string_id = -1;
1505
1506                                         string_id = __voicecall_core_get_string_id_by_errorcode(error_code);
1507
1508                                         memset(&event_data, 0, sizeof(event_data));
1509                                         event_data.string_id = __voicecall_core_get_string_id_by_errorcode(error_code);
1510
1511                                         vcall_engine_send_event_to_client(VC_ENGINE_MSG_MESSAGE_BOX_TO_UI, (void *)&event_data);
1512                                 }
1513                                 break;
1514                         }
1515                 }
1516                 break;
1517
1518         case VC_ACTION_INCOM_FORCE:
1519                 {
1520                         int call_handle = param1;
1521                         vc_engine_common_with_handle_type event_data;
1522
1523                         CALL_ENG_DEBUG(ENG_DEBUG, "Call Handle = %d", call_handle);
1524
1525                         memset(&event_data, 0, sizeof(event_data));
1526                         event_data.call_handle = call_handle;
1527
1528                         vcall_engine_send_event_to_client(VC_ENGINE_MSG_ACTION_INCOM_FORCE_TO_UI, (void *)&event_data);
1529                 }
1530                 break;
1531
1532         case VC_ACTION_SAT_REQUEST:
1533                 {
1534                         if (SAT_RQST_SETUP_CALL == param1) {
1535                                 voicecall_sat_callinfo_t *psat_callinfo = (voicecall_sat_callinfo_t *) param3;
1536                                 vc_engine_outgoing_type event_data;
1537
1538                                 if (psat_callinfo == NULL) {
1539                                         CALL_ENG_DEBUG(ENG_ERR, "psat_callinfo is NULL..");
1540                                         assert(psat_callinfo != NULL);
1541                                 } else {
1542                                         CALL_ENG_DEBUG(ENG_DEBUG, "VC_ACTION_SAT_REQUEST is received by Voice call.");
1543                                         pcall_core->call_setup_info.call_setup_by = VC_CALL_SETUP_BY_SAT;
1544                                         pcall_core->call_setup_info.call_type = VC_CALL_ORIG_TYPE_SAT;
1545
1546                                         /*Phone Number */
1547                                         _vc_core_util_strcpy(pcall_core->call_setup_info.source_tel_number, VC_PHONE_NUMBER_LENGTH_MAX, psat_callinfo->call_number);
1548                                         _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);
1549
1550                                         /*Name */
1551                                         CALL_ENG_DEBUG(ENG_ERR, "psat_callinfo->disp_text:[%s]", psat_callinfo->disp_text);
1552
1553                                         memset(&event_data, 0, sizeof(event_data));
1554                                         _vc_core_util_strcpy(event_data.call_num, sizeof(event_data.call_num), pcall_core->call_setup_info.tel_number);
1555                                         event_data.contact_index = -1;
1556                                         event_data.phone_type = -1;
1557                                         event_data.bday_remaining_days = -1;
1558                                         _vc_core_util_strcpy(event_data.call_num, sizeof(event_data.call_num), psat_callinfo->disp_text);
1559
1560                                         vcall_engine_send_event_to_client(VC_ENGINE_MSG_OUTGOING_TO_UI, (void *)&event_data);
1561
1562                                         /*Get Icon Information */
1563                                         if (TRUE == psat_callinfo->bicon_present) {     /*bicon_present is TRUE when SAT icon info available and when GCF is enabled */
1564                                                 CALL_ENG_DEBUG(ENG_ERR, "SAT icon available.");
1565                                         }
1566
1567                                         /* Prepare and Make Call with the Give Information */
1568                                         if (FALSE == voicecall_core_setup_call(pcall_core, FALSE)) {
1569                                                 /*Send Response to SAT Engine */
1570                                                 voicecall_core_send_sat_response(pcall_core->pcall_engine, SAT_RQST_SETUP_CALL, CALL_VC_ME_UNABLE_TO_PROCESS_COMMAND);
1571                                         }
1572                                 }
1573                         } else if (SAT_RQST_SEND_DTMF == param1) {
1574                                 voicecall_sat_callinfo_t *psat_callinfo = (voicecall_sat_callinfo_t *) param3;
1575
1576                                 CALL_ENG_DEBUG(ENG_DEBUG, "SAT Send DTMF Number: %s, hidden: %d", psat_callinfo->call_number, psat_callinfo->bsat_hidden);
1577                                 __voicecall_core_queue_dtmf_string(pcall_core, psat_callinfo->call_number, TRUE);
1578                         } else {
1579                                 CALL_ENG_DEBUG(ENG_ERR, "Invalid SAT Request Type: %d", param2);
1580                         }
1581                 }
1582                 break;
1583
1584         case VC_ACTION_SAT_RESPONSE:
1585                 {
1586                         if (SAT_RESP_SETUP_CALL == param1) {
1587                                 voicecall_sat_callinfo_t *psat_call_info = (voicecall_sat_callinfo_t *) param3;
1588
1589                                 CALL_ENG_DEBUG(ENG_DEBUG, "sat_mo_call_ctrl_res = %d", psat_call_info->sat_mo_call_ctrl_res);
1590
1591                                 if (CALL_NOT_ALLOWED == psat_call_info->sat_mo_call_ctrl_res) {
1592                                         vc_engine_msg_box_type event_data;
1593
1594                                         memset(&event_data, 0, sizeof(event_data));
1595                                         event_data.string_id = IDS_CALL_POP_CALLNOTCALLOWED;
1596                                         vcall_engine_send_event_to_client(VC_ENGINE_MSG_MESSAGE_BOX_TO_UI, (void *)&event_data);
1597                                 } else if (CALL_ALLOWED_WITH_MOD == psat_call_info->sat_mo_call_ctrl_res) {
1598                                         CALL_ENG_DEBUG(ENG_DEBUG, "psat_call_info->call_number = [%s]", psat_call_info->call_number);
1599                                         CALL_ENG_DEBUG(ENG_DEBUG, "psat_call_info->disp_text = [%s]", psat_call_info->disp_text);
1600 #ifdef _OLD_SAT_
1601                                         mocall_index = vcui_app_doc_get_mocall_index(papp_document);
1602
1603                                         /*Update MO CALL Display Data with the SAT modified info */
1604                                         if (mocall_index != -1) {
1605                                                 vcui_app_call_display_data_t display_data;
1606                                                 vcui_app_call_display_data_t new_display_data;
1607                                                 vcui_app_view_mo_state_t *pmo_state = NULL;
1608
1609                                                 if (FALSE == vcui_app_cdm_get_display_object_byindex(&papp_document->call_display_manager, mocall_index, &display_data)) {
1610                                                         return TRUE;
1611                                                 }
1612
1613                                                 vcui_app_cdm_clear_display_object(&new_display_data);
1614
1615                                                 /*Copy all must parameters required for MO Call */
1616                                                 new_display_data.call_handle = display_data.call_handle;
1617                                                 new_display_data.call_index = display_data.call_index;
1618                                                 new_display_data.call_type = display_data.call_type;
1619                                                 new_display_data.start_time = display_data.start_time;
1620                                                 new_display_data.used = display_data.used;
1621
1622                                                 if (strlen(psat_call_info->call_number) > 0) {
1623                                                         vcui_app_util_strcpy(new_display_data.source_tel_number, sizeof(new_display_data.source_tel_number), psat_call_info->call_number);
1624                                                         _vc_core_engine_extract_phone_number(new_display_data.source_tel_number, new_display_data.tel_number, VC_PHONE_NUMBER_LENGTH_MAX);
1625                                                 }
1626
1627                                                 if (strlen(psat_call_info->disp_text) > 0) {
1628                                                         vcui_app_util_strcpy(new_display_data.name, sizeof(new_display_data.name), psat_call_info->disp_text);
1629                                                 }
1630
1631                                                 /*todo, Check whether contact search need to be done for the SAT modified number */
1632
1633                                                 /*Set the newly modified data to the CDM */
1634                                                 vcui_app_cdm_set_display_object(pdisplay_mgr, &new_display_data);
1635
1636                                                 /*Update the MO View */
1637                                                 pmo_state = (vcui_app_view_mo_state_t *) calloc(1, sizeof(vcui_app_view_mo_state_t));
1638                                                 pmo_state->mo_call_state = VCUI_MO_CALL_STATE_UPDATE;
1639
1640                                                 /* Update MO Call Screen View to update the connection status */
1641                                                 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);
1642
1643                                         } else {
1644                                                 VCUI_DEBUG(VCUI_LOG_ERR, "Invalid Mo Call Index: %d", mocall_index);
1645                                         }
1646 #endif
1647                                 } else if (CALL_CHANGED_TO_SS == psat_call_info->sat_mo_call_ctrl_res) {
1648                                         /*Issue notification to Launch SS */
1649                                 }
1650                         }
1651                 }
1652                 break;
1653
1654         case VC_ACTION_CALL_END_HELD_RETREIVED:
1655                 {
1656                         int call_handle = param1;
1657                         vc_engine_common_with_handle_type event_data;
1658
1659                         CALL_ENG_DEBUG(ENG_DEBUG, "call handle:[%d]", call_handle);
1660
1661                         memset(&event_data, 0, sizeof(event_data));
1662
1663                         vcall_engine_send_event_to_client(VC_ENGINE_MSG_ACTION_CALL_END_HELD_RETREIVED_TO_UI, (void *)&event_data);
1664                 }
1665                 break;
1666
1667         case VC_ACTION_NO_ACTIVE_TASK:
1668                 {
1669                         CALL_ENG_DEBUG(ENG_DEBUG, "Not yet.");
1670                 }
1671                 break;
1672
1673         case VC_CALL_GET_VOLUME_RESP:
1674                 {
1675                         vc_engine_vol_resp_type event_data;
1676
1677                         CALL_ENG_DEBUG(ENG_DEBUG, "Current Voicecall (TAPI)Volume Type %d, Current Volume Level: %d", param1, param2);
1678
1679                         memset(&event_data, 0, sizeof(event_data));
1680                         event_data.vol_alert_type = VOICE_CALL_VOL_TYPE_VOICE;
1681                         event_data.vol_level = param2;
1682                         vcall_engine_send_event_to_client(VC_ENGINE_MSG_GET_VOLUME_RESP_TO_UI, (void *)&event_data);
1683                 }
1684                 break;
1685
1686         case VC_CALL_NOTI_WBAMR:
1687                 {
1688                         vc_engine_wbamr_status_type event_data;
1689
1690                         CALL_ENG_DEBUG(ENG_DEBUG, "Current WBAmr status %d", param1);
1691
1692                         memset(&event_data, 0, sizeof(event_data));
1693                         event_data.bstatus = param1;
1694                         vcall_engine_send_event_to_client(VC_ENGINE_MSG_NOTI_WBAMR_TO_UI, (void *)&event_data);
1695                 }
1696                 break;
1697
1698         default:
1699                 CALL_ENG_DEBUG(ENG_DEBUG, " Engine Event ID : %d not handled", event);
1700                 break;
1701         }
1702
1703         CALL_VC_DUMP_CALLDETAILS(&pcall_engine->call_manager);
1704
1705         CALL_ENG_DEBUG(ENG_DEBUG, " Ended.");
1706
1707         return TRUE;
1708 }
1709
1710 /**
1711  * This function converts Error Code to string id.
1712  *
1713  * @return              string id
1714  * @param[in]           error_code              error code to be used to display the message content
1715  */
1716 static int __voicecall_core_get_string_id_by_errorcode(int error_code)
1717 {
1718         int string_id = -1;
1719         switch (error_code) {
1720         case ERROR_VOICECALL_DTMF_FAILED:
1721                 string_id = IDS_CALL_POP_DTMFSENDING_FAIL;
1722                 break;
1723
1724         case ERROR_VOICECALL_CALL_NOT_ALLOWED:
1725                 string_id = IDS_CALL_POP_CALLNOTCALLOWED;
1726                 break;
1727
1728         case ERROR_VOICECALL_CALL_IMPOSSIBLE_NOSIM_NOEMERGNUM:
1729                 string_id = IDS_CALL_POP_SOS_CALL_ONLY_IN_NO_SIM_MODE;
1730                 break;
1731
1732         case ERROR_VOICECALL_EMERGENCY_CALLS_ONLY:
1733                 string_id = IDS_CALL_POP_CALLING_EMERG_ONLY;
1734                 break;
1735
1736         case ERROR_VOICECALL_PHONE_NOT_INITIALIZED:
1737                 string_id = IDS_CALL_POP_PHONE_NOT_INITIALISED;
1738                 break;
1739
1740         case ERROR_VOICECALL_ANSWER_FAILED:
1741                 string_id = IDS_CALL_POP_CALLFAILED;
1742                 break;
1743
1744         case ERROR_VOICECALL_HOLD_REJECTED:
1745         case ERROR_VOICECALL_HOLD_FAILED:
1746                 string_id = IDS_CALL_POP_HOLD_FAILED;
1747                 break;
1748
1749         case ERROR_VOICECALL_ACTIVATE_REJECTED:
1750         case ERROR_VOICECALL_RETREIVE_FAILED:
1751                 string_id = IDS_CALL_POP_UNABLE_TO_RETRIEVE;
1752                 break;
1753
1754         case ERROR_VOICECALL_SWAP_REJECTED:
1755         case ERROR_VOICECALL_SWAP_FAILED:
1756                 string_id = IDS_CALL_POP_SWAP_FAILED;
1757                 break;
1758
1759         case ERROR_VOICECALL_SPLIT_CONF_FAILED:
1760                 string_id = IDS_CALL_POP_SPLIT_FAILED;
1761                 break;
1762
1763         case ERROR_VOICECALL_SETUP_CONF_FAILED:
1764                 string_id = IDS_CALL_POP_JOIN_FAILED;
1765                 break;
1766
1767         case ERROR_VOICECALL_TRANSFER_FAILED:
1768                 string_id = IDS_CALL_POP_TRANSFER_FAILED;
1769                 break;
1770
1771         case ERROR_VOICECALL_SWAP_NOT_SUPPORTED:
1772                 string_id = IDS_CALL_POP_SWAP_NOT_SUPPORTED;
1773                 break;
1774
1775         case ERROR_VOICECALL_HOLD_NOT_SUPPORTED:
1776                 string_id = IDS_CALL_POP_HOLD_NOT_SUPPORTED;
1777                 break;
1778
1779         case ERROR_VOICECALL_RETREIVE_NOT_SUPPORTED:
1780                 string_id = IDS_CALL_POP_UNHOLD_NOT_SUPPORTED;
1781                 break;
1782
1783         case ERROR_VOICECALL_SETUP_CONF_NOT_SUPPORTED:
1784                 string_id = IDS_CALL_POP_JOIN_NOT_SUPPORTED;
1785                 break;
1786
1787         case ERROR_VOICECALL_SPLIT_CONF_NOT_SUPPORTED:
1788                 string_id = IDS_CALL_POP_SPLIT_NOT_SUPPORTED;
1789                 break;
1790         case ERROR_VOICECALL_TRANSFER_NOT_SUPPORTED:
1791                 string_id = IDS_CALL_POP_TRANSFER_NOT_SUPPORTED;
1792                 break;
1793
1794         case ERROR_VOICECALL_INCOMPLETE:
1795                 string_id = IDS_CALL_POP_INCOMPLETE;
1796                 break;
1797
1798         case ERROR_VOICECALL_UNAVAILABLE:
1799                 string_id = IDS_CALL_POP_UNAVAILABLE;
1800                 break;
1801
1802         case ERROR_VOICECALL_TAPI_CAUSE_CALL_FAILED:
1803                 string_id = IDS_CALL_POP_CALLFAILED;
1804                 break;
1805
1806         case ERROR_VOICECALL_INVALID_CALL_TYPE:
1807         case ERROR_VOICECALL_INVALID_TELEPHONE_NUMBER:
1808                 string_id = IDS_CALL_POP_CAUSE_WRONG_NUMBER;
1809                 break;
1810
1811         default:
1812                 CALL_ENG_DEBUG(ENG_DEBUG, " Invalid Error Code: %x", error_code);
1813                 string_id = IDS_CALL_POP_CALLFAILED;
1814                 break;
1815         }
1816         return string_id;
1817 }
1818
1819 gboolean voicecall_core_set_to_default(call_vc_core_state_t *pcall_core)
1820 {
1821         CALL_ENG_DEBUG(ENG_DEBUG, "");
1822         if (pcall_core->pcall_engine == NULL)
1823                 return FALSE;
1824
1825         /*Set Engine states to default */
1826         _vc_core_engine_set_to_default_values(pcall_core->pcall_engine);
1827
1828         /*Initialize MO Call Setup Info */
1829         pcall_core->call_setup_info.mo_call_index = VC_TAPI_INVALID_CALLHANDLE;
1830         pcall_core->call_setup_info.call_setup_by = VC_CALL_SETUP_BY_NORMAL;
1831
1832         pcall_core->call_setup_info.mo_call_index = VC_TAPI_INVALID_CALLHANDLE;
1833         pcall_core->call_setup_info.call_setup_by = VC_CALL_SETUP_BY_NORMAL;
1834         memset(pcall_core->call_setup_info.tel_number, 0, sizeof(pcall_core->call_setup_info.tel_number));
1835
1836         pcall_core->mo_redial_timer = -1;
1837         __vc_core_set_auto_redial_count(pcall_core, 0);
1838
1839         _vc_core_util_set_call_status(VCONFKEY_CALL_OFF);
1840         voicecall_core_set_status(pcall_core, CALL_VC_CORE_FLAG_NONE, TRUE);
1841
1842         pcall_core->bt_connected = _vc_bt_get_bt_status();
1843         if (FALSE == pcall_core->bt_connected) {
1844                 voicecall_snd_set_path_status(pcall_core->papp_snd, VOICE_CALL_SND_PATH_RECEIVER_EARJACK);
1845         } else {
1846                 CALL_ENG_DEBUG(ENG_DEBUG, "BT connected, Not changing the sound status");
1847         }
1848
1849         /* sound reset */
1850         voicecall_snd_unregister_cm(pcall_core->papp_snd);
1851
1852         if (vconf_set_int(VCONFKEY_FACTORY_CALL_CONNECT_STATE, VCONFKEY_FACTORY_CALL_DISCONNECTED)) {
1853                 CALL_ENG_DEBUG(ENG_ERR, "vconf_set_int failed.");
1854         }
1855
1856         return TRUE;
1857 }
1858
1859 static void __voicecall_core_mocall_reset_engine_state(voicecall_engine_t *pcall_engine)
1860 {
1861         int eng_state = VC_INOUT_STATE_NONE;
1862
1863         voicecall_core_get_engine_state(pcall_engine, &eng_state);
1864
1865         CALL_ENG_DEBUG(ENG_DEBUG, "current engine state is: %d", eng_state);
1866
1867         if ((eng_state > VC_INOUT_STATE_OUTGOING_START) && (eng_state < VC_INOUT_STATE_OUTGOING_END)) {
1868                 voicecall_core_change_engine_state(pcall_engine, VC_INOUT_STATE_NONE);
1869         } else {
1870                 CALL_ENG_DEBUG(ENG_DEBUG, "Engine state is already changed, current engine state is: %d", eng_state);
1871                 CALL_VC_DUMP_CALLDETAILS(&pcall_engine->call_manager);
1872         }
1873 }
1874
1875 /**
1876  * This function initialize voicecall core
1877  *
1878  * @return              Returns TRUE on success or FALSE on failure
1879  * @param[in]           pcall_core              Handle to voicecall core
1880  * @param[in]           pcallback_func  callback function
1881  */
1882 int voicecall_core_init(call_vc_core_state_t *pcall_core)
1883 {
1884         voicecall_engine_t *pcall_engine = NULL;
1885
1886         if (ERROR_VOICECALL_NONE != _vc_core_engine_init(&pcall_engine, (voicecall_cb) voicecall_core_cb, pcall_core)) {
1887                 CALL_ENG_DEBUG(ENG_DEBUG, "Voicecall Engine Init Failed");
1888                 return FALSE;
1889         }
1890
1891         if (FALSE == voicecall_snd_init(pcall_core, &pcall_core->papp_snd)) {
1892                 CALL_ENG_DEBUG(ENG_DEBUG, "voicecall_snd_init() failed");
1893                 return FALSE;
1894         }
1895         /*Store Voicecall Engine Handle */
1896         pcall_core->pcall_engine = pcall_engine;
1897
1898         _vc_bt_status_init(pcall_core);
1899
1900         _voicecall_dvc_earjack_init(pcall_core);
1901
1902         voicecall_core_set_status(pcall_core, CALL_VC_CORE_FLAG_NONE, TRUE);
1903         return TRUE;
1904 }
1905
1906 /**
1907  * This function prepares a voice call with the given data
1908  *
1909  * @return              Returns TRUE on success or FALSE on failure
1910  * @param[in]           pcall_core              Handle to voicecall core
1911  * @param[in]           bemergency              emergency call or not from dialer
1912  * @param[in]
1913  */
1914 gboolean voicecall_core_setup_call(call_vc_core_state_t *pcall_core, gboolean bemergency)
1915 {
1916         voicecall_engine_t *pcall_engine = pcall_core->pcall_engine;
1917         voicecall_setup_info_t setupcall_info = { 0, };
1918         voicecall_error_t error_code = -1;
1919         gboolean bemergency_call = FALSE;
1920         gboolean bmocall_exists = FALSE;
1921         gboolean bmtcall_exists = FALSE;
1922         int nw_status = 0;
1923
1924         CALL_ENG_DEBUG(ENG_DEBUG, "");
1925
1926         voicecall_core_set_status(pcall_core, CALL_VC_CORE_FLAG_SOS_CALL_ONLY, bemergency);
1927
1928         _vc_core_engine_status_isexists_call_bytype(pcall_engine, VC_OUTGOING_CALL, &bmocall_exists);
1929         if (TRUE == bmocall_exists) {
1930                 CALL_ENG_DEBUG(ENG_DEBUG, "MO call is in progress...");
1931                 voicecall_core_set_status(pcall_core, CALL_VC_CORE_FLAG_SETUPCALL_FAIL, TRUE);
1932                 return FALSE;
1933         }
1934
1935         /*Ignore the MO Call, if already an Incoming call is in progress, MT Call is given high priority */
1936         _vc_core_engine_status_isexists_call_bytype(pcall_engine, VC_INCOMING_CALL, &bmtcall_exists);
1937         if (TRUE == bmtcall_exists) {
1938                 CALL_ENG_DEBUG(ENG_DEBUG, "MT call is in progress");
1939                 voicecall_core_set_status(pcall_core, CALL_VC_CORE_FLAG_SETUPCALL_FAIL, TRUE);
1940                 return FALSE;
1941         }
1942
1943         if (TRUE == _vc_core_util_check_video_call_status()) {
1944                 CALL_ENG_DEBUG(ENG_DEBUG, "Voice call is not allowed during video call...");
1945                 voicecall_core_set_status(pcall_core, CALL_VC_CORE_FLAG_SETUPCALL_FAIL, TRUE);
1946                 vc_engine_msg_box_type event_data;
1947
1948                 memset(&event_data, 0, sizeof(event_data));
1949                 event_data.string_id = IDS_CALL_POP_VOICE_CALL_IS_NOT_ALLOWED_DURING_VIDEO_CALL;
1950                 vcall_engine_send_event_to_client(VC_ENGINE_MSG_MESSAGE_BOX_TO_UI, (void *)&event_data);
1951
1952                 return FALSE;
1953         }
1954
1955         if (TRUE == _vc_core_util_get_SAP_status()) {
1956                 CALL_ENG_DEBUG(ENG_DEBUG, "SAP is on");
1957                 voicecall_core_set_status(pcall_core, CALL_VC_CORE_FLAG_SETUPCALL_FAIL, TRUE);
1958                 vc_engine_msg_box_type event_data;
1959
1960                 memset(&event_data, 0, sizeof(event_data));
1961                 event_data.string_id = IDS_CALL_POP_UNAVAILABLE;
1962                 vcall_engine_send_event_to_client(VC_ENGINE_MSG_MESSAGE_BOX_TO_UI, (void *)&event_data);
1963
1964                 return FALSE;
1965         }
1966
1967         /*Prpare a call with the Voicecall Engine */
1968         setupcall_info.call_type = pcall_core->call_setup_info.call_type;
1969         _vc_core_util_strcpy(setupcall_info.source_tel_number, sizeof(setupcall_info.source_tel_number), pcall_core->call_setup_info.source_tel_number);
1970         _vc_core_util_strcpy(setupcall_info.tel_number, sizeof(setupcall_info.tel_number), pcall_core->call_setup_info.tel_number);
1971
1972         /*Get CUG Details */
1973         _vc_core_util_get_cug_info(&setupcall_info);
1974
1975         /*Get Identity Mode */
1976         _vc_core_util_get_identity_mode(&setupcall_info);
1977
1978         CALL_ENG_DEBUG(ENG_DEBUG, "identity_mode = [%d], tel_number = [%s]", setupcall_info.identity_mode, setupcall_info.tel_number);
1979
1980         error_code = _vc_core_engine_prepare_call(pcall_engine, &setupcall_info);
1981         if (ERROR_VOICECALL_NONE != error_code) {
1982                 CALL_ENG_DEBUG(ENG_DEBUG, "_vc_core_engine_prepare_call failed, error code: %d", error_code);
1983                 _vc_core_engine_finalize_call(pcall_engine, VC_OUTGOING_CALL, -1);
1984                 voicecall_core_set_status(pcall_core, CALL_VC_CORE_FLAG_SETUPCALL_FAIL, TRUE);
1985                 vc_engine_msg_box_type event_data;
1986
1987                 memset(&event_data, 0, sizeof(event_data));
1988                 event_data.string_id = __voicecall_core_get_string_id_by_errorcode(error_code);
1989                 vcall_engine_send_event_to_client(VC_ENGINE_MSG_MESSAGE_BOX_TO_UI, (void *)&event_data);
1990                 return FALSE;
1991         }
1992         pcall_core->call_setup_info.call_type = setupcall_info.call_type;
1993         CALL_ENG_DEBUG(ENG_DEBUG, "call_type:[%d]", pcall_core->call_setup_info.call_type);
1994
1995         pcall_core->call_setup_info.mo_call_index = setupcall_info.mo_call_index;
1996         if (TRUE == _vc_core_util_is_offline_mode()) {
1997                 _vc_core_engine_finalize_call(pcall_engine, VC_OUTGOING_CALL, -1);
1998                 voicecall_core_set_status(pcall_core, CALL_VC_CORE_FLAG_SETUPCALL_FAIL, TRUE);
1999
2000                 vc_engine_msg_box_type event_data;
2001
2002                 memset(&event_data, 0, sizeof(event_data));
2003                 event_data.string_id = IDS_CALL_POP_CHANGEOFFLINEMODETOCALL;
2004                 vcall_engine_send_event_to_client(VC_ENGINE_MSG_MESSAGE_BOX_TO_UI, (void *)&event_data);
2005                 return FALSE;
2006         }
2007
2008         /* Check for Following Conditions , only if not emergency Number */
2009         CALL_ENG_DEBUG(ENG_DEBUG, "mo_call_index = [%d]", setupcall_info.mo_call_index);
2010         error_code = _vc_core_engine_status_check_emergency_byindex(pcall_engine, setupcall_info.mo_call_index, &bemergency_call);
2011         if (ERROR_VOICECALL_NONE != error_code) {
2012                 CALL_ENG_DEBUG(ENG_DEBUG, "Emergency Check Error code: %d", error_code);
2013         }
2014
2015         /*Check PwLock */
2016         if (TRUE == _vc_core_util_is_pwlock()) {
2017                 CALL_ENG_DEBUG(ENG_DEBUG, "PwLock is enabled.");
2018                 if (bemergency_call == FALSE) {
2019                         CALL_ENG_DEBUG(ENG_DEBUG, "Only emergency call is possible.");
2020                         _vc_core_engine_finalize_call(pcall_engine, VC_OUTGOING_CALL, -1);
2021                         voicecall_core_set_status(pcall_core, CALL_VC_CORE_FLAG_SETUPCALL_FAIL, TRUE);
2022
2023                         vc_engine_msg_box_type event_data;
2024                         memset(&event_data, 0, sizeof(event_data));
2025                         event_data.string_id = IDS_CALL_POP_CALLING_EMERG_ONLY;
2026                         vcall_engine_send_event_to_client(VC_ENGINE_MSG_MESSAGE_BOX_TO_UI, (void *)&event_data);
2027
2028                         return FALSE;
2029                 }
2030         }
2031
2032         /*Check for the following cases, if the call is not emergency call */
2033         if (FALSE == bemergency_call) {
2034                 vc_engine_msg_box_type event_data;
2035
2036                 memset(&event_data, 0, sizeof(event_data));
2037                 /* Check for NW Status and Emergency Mode */
2038                 if (FALSE == _vc_core_util_get_nw_status(&nw_status)) {
2039                         CALL_ENG_DEBUG(ENG_DEBUG, "Can't get a network status...");
2040                         _vc_core_engine_finalize_call(pcall_engine, VC_OUTGOING_CALL, -1);
2041
2042                         event_data.string_id = IDS_CALL_POP_CALLNOTCALLOWED;
2043                         vcall_engine_send_event_to_client(VC_ENGINE_MSG_MESSAGE_BOX_TO_UI, (void *)&event_data);
2044
2045                         voicecall_core_set_status(pcall_core, CALL_VC_CORE_FLAG_SETUPCALL_FAIL, TRUE);
2046                         return FALSE;
2047                 } else {
2048                         if ((VCONFKEY_TELEPHONY_SVCTYPE_NONE == nw_status) || (VCONFKEY_TELEPHONY_SVCTYPE_NOSVC == nw_status) || (VCONFKEY_TELEPHONY_SVCTYPE_SEARCH == nw_status)) {
2049                                 CALL_ENG_DEBUG(ENG_DEBUG, "No Service: Call not Allowed");
2050                                 _vc_core_engine_finalize_call(pcall_engine, VC_OUTGOING_CALL, -1);
2051                                 event_data.string_id = IDS_CALL_POP_CALLNOTCALLOWED;
2052                                 vcall_engine_send_event_to_client(VC_ENGINE_MSG_MESSAGE_BOX_TO_UI, (void *)&event_data);
2053
2054                                 voicecall_core_set_status(pcall_core, CALL_VC_CORE_FLAG_SETUPCALL_FAIL, TRUE);
2055                                 return FALSE;
2056                         } else if ((VCONFKEY_TELEPHONY_SVCTYPE_EMERGENCY == nw_status)) {
2057                                 CALL_ENG_DEBUG(ENG_DEBUG, "Emergency mode: Emergency call only...");
2058                                 _vc_core_engine_finalize_call(pcall_engine, VC_OUTGOING_CALL, -1);
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                                 voicecall_core_set_status(pcall_core, CALL_VC_CORE_FLAG_SETUPCALL_FAIL, TRUE);
2063                                 return FALSE;
2064                         } else {
2065                                 /* ok. */
2066                         }
2067
2068                 }
2069
2070                 /*Check for voicemail number if it is not an emergency call */
2071         }
2072
2073         CALL_ENG_DEBUG(ENG_DEBUG, "MO Call Setup OVer");
2074
2075         if (_vc_bt_get_bt_status() == TRUE) {
2076                 voicecall_snd_set_path_status(pcall_core->papp_snd, VOICE_CALL_SND_PATH_BT);
2077         }
2078
2079         voicecall_core_make_call(pcall_core);
2080
2081         return TRUE;
2082 }
2083
2084 /**
2085  * This function makes the actual voicecall prepared by the #voicecall_core_setup_call
2086  *
2087  * @return              Returns TRUE on success or FALSE on failure
2088  * @param[in]           pcall_core              Handle to voicecall core
2089  */
2090 gboolean voicecall_core_make_call(call_vc_core_state_t *pcall_core)
2091 {
2092         voicecall_engine_t *pcall_engine = pcall_core->pcall_engine;
2093
2094         voicecall_error_t error_code = ERROR_VOICECALL_NONE;
2095         int call_handle = -1;
2096
2097         CALL_ENG_DEBUG(ENG_DEBUG, "");
2098
2099         /*Make Actual Call with Voicecall Engine */
2100         error_code = _vc_core_engine_make_call(pcall_engine, pcall_core->call_setup_info.mo_call_index, &call_handle);
2101         if (ERROR_VOICECALL_NONE != error_code) {
2102                 vc_engine_msg_box_type event_data;
2103
2104                 memset(&event_data, 0, sizeof(event_data));
2105
2106                 _vc_core_engine_finalize_call(pcall_engine, VC_OUTGOING_CALL, -1);
2107
2108                 CALL_ENG_DEBUG(ENG_DEBUG, "_vc_core_engine_make_call Failed: Error_Code: %d..", error_code);
2109
2110                 switch (error_code) {
2111                 case ERROR_VOICECALL_TAPI_CAUSE_CALL_FAILED:
2112                         event_data.string_id = IDS_CALL_POP_CALLFAILED;
2113                         break;
2114
2115                 case ERROR_VOICECALL_CALL_IMPOSSIBLE_NOSIM_NOEMERGNUM:
2116                         event_data.string_id = IDS_CALL_POP_CALLFAILED;
2117                         break;
2118
2119                 default:
2120                         event_data.string_id = IDS_CALL_BODY_CALLENDED;
2121                         break;
2122                 }
2123                 vcall_engine_send_event_to_client(VC_ENGINE_MSG_MESSAGE_BOX_TO_UI, (void *)&event_data);
2124
2125                 return FALSE;
2126         }
2127
2128         CALL_ENG_DEBUG(ENG_DEBUG, "Call Handle After Setup Call %d.", call_handle);
2129
2130         voicecall_snd_register_cm(pcall_core->papp_snd);
2131
2132         /* Set phonestatus value */
2133         _vc_core_util_set_call_status(VCONFKEY_CALL_VOICE_CONNECTING);
2134
2135         return TRUE;
2136 }
2137
2138 /**
2139  * This function processed sat setup call
2140  *
2141  * @return              Returns TRUE on success or FALSE on failure
2142  * @param[in]           pcall_core              Handle to voicecall core
2143  * @param[in]
2144 */
2145 gboolean voicecall_core_process_sat_setup_call(vcall_engine_sat_setup_call_info_t *sat_setup_call_info)
2146 {
2147         CALL_ENG_DEBUG(ENG_DEBUG, "");
2148         TelSatSetupCallIndCallData_t *SatSetupCallIndCallInfo = NULL;
2149
2150         SatSetupCallIndCallInfo = (TelSatSetupCallIndCallData_t *) calloc(1, sizeof(TelSatSetupCallIndCallData_t));
2151         if (NULL == SatSetupCallIndCallInfo)
2152                 return FALSE;
2153
2154         SatSetupCallIndCallInfo->commandId = sat_setup_call_info->command_id;
2155         SatSetupCallIndCallInfo->calltype = sat_setup_call_info->command_qualifier;
2156         SatSetupCallIndCallInfo->dispText.stringLen = strlen(sat_setup_call_info->disp_text);
2157         memcpy(SatSetupCallIndCallInfo->dispText.string, sat_setup_call_info->disp_text, strlen(sat_setup_call_info->disp_text));
2158
2159         SatSetupCallIndCallInfo->callNumber.stringLen = strlen(sat_setup_call_info->call_num);
2160         memcpy(SatSetupCallIndCallInfo->callNumber.string, sat_setup_call_info->call_num, strlen(sat_setup_call_info->call_num));
2161
2162         SatSetupCallIndCallInfo->duration = sat_setup_call_info->duration;
2163
2164         _vc_core_engine_handle_sat_events_cb(SatSetupCallIndCallInfo, NULL);
2165
2166         if (SatSetupCallIndCallInfo) {
2167                 free(SatSetupCallIndCallInfo);
2168                 SatSetupCallIndCallInfo = NULL;
2169         }
2170
2171         CALL_ENG_DEBUG(ENG_DEBUG, "End..");
2172
2173         return TRUE;
2174 }
2175
2176 /**
2177  * This function processed incoming call
2178  *
2179  * @return              Returns TRUE on success or FALSE on failure
2180  * @param[in]           pcall_core              Handle to voicecall core
2181  * @param[in]
2182 */
2183 gboolean voicecall_core_process_incoming_call(call_vc_core_incoming_info_t *incoming_call_info)
2184 {
2185         CALL_ENG_DEBUG(ENG_DEBUG, "");
2186         TelCallIncomingCallInfo_t *IncomingCallInfo = NULL;
2187
2188         CALL_ENG_DEBUG(ENG_DEBUG, " number is : [%s]", incoming_call_info->call_num);
2189
2190         IncomingCallInfo = (TelCallIncomingCallInfo_t *) malloc(sizeof(TelCallIncomingCallInfo_t));
2191         if (NULL == IncomingCallInfo)
2192                 return FALSE;
2193         memset(IncomingCallInfo, 0, sizeof(IncomingCallInfo));
2194
2195         IncomingCallInfo->CallHandle = incoming_call_info->call_handle;
2196         IncomingCallInfo->CallType = incoming_call_info->call_type;
2197         IncomingCallInfo->CliPresentationIndicator = incoming_call_info->cli_presentation_indicator;
2198         _vc_core_util_strcpy(IncomingCallInfo->szCallingPartyNumber, sizeof(IncomingCallInfo->szCallingPartyNumber), incoming_call_info->call_num);
2199         IncomingCallInfo->CallingNameInfo.NameMode = incoming_call_info->calling_name_mode;
2200         _vc_core_util_strcpy(IncomingCallInfo->CallingNameInfo.szNameData, sizeof(IncomingCallInfo->CallingNameInfo.szNameData), incoming_call_info->calling_name);
2201         _vc_core_util_strcpy(IncomingCallInfo->RedirectInfo.szRedirectedNumber, sizeof(IncomingCallInfo->RedirectInfo.szRedirectedNumber), incoming_call_info->redirected_number);
2202         _vc_core_util_strcpy(IncomingCallInfo->RedirectInfo.szRedirectSubAddress, sizeof(IncomingCallInfo->RedirectInfo.szRedirectSubAddress), incoming_call_info->redirected_sub_address);
2203         IncomingCallInfo->CliCause = incoming_call_info->cli_cause;
2204         IncomingCallInfo->fwded = incoming_call_info->bfwded;
2205         IncomingCallInfo->ActiveLine = incoming_call_info->active_line;
2206
2207         _vc_core_engine_handle_incoming_tapi_events(IncomingCallInfo, NULL);
2208
2209         if (IncomingCallInfo) {
2210                 free(IncomingCallInfo);
2211                 IncomingCallInfo = NULL;
2212         }
2213
2214         CALL_ENG_DEBUG(ENG_DEBUG, "End..");
2215
2216         return TRUE;
2217 }
2218
2219 /**
2220  * This function answers an incoming call
2221  *
2222  * @return              Returns TRUE on success or FALSE on failure
2223  * @param[in]           pcall_core              Handle to voicecall core
2224  * @param[in]
2225 */
2226 gboolean voicecall_core_answer_call(call_vc_core_state_t *pcall_core, gboolean auto_accept)
2227 {
2228         voicecall_engine_t *pcall_engine = pcall_core->pcall_engine;
2229
2230         gboolean active_calls = FALSE;
2231         gboolean held_calls = FALSE;
2232
2233         CALL_ENG_DEBUG(ENG_DEBUG, "");
2234
2235         /*First Stop the Incoming alert */
2236         voicecall_snd_stop_alert(pcall_core->papp_snd);
2237
2238         __voicecall_core_cancel_auto_answer(pcall_core);
2239
2240         _vc_core_engine_status_isexists_any_call(pcall_engine, &active_calls, &held_calls);
2241         CALL_ENG_DEBUG(ENG_DEBUG, "active_calls=%d, held_calls=%d", active_calls, held_calls);
2242
2243         if (TRUE == active_calls && TRUE == held_calls) {
2244                 /* Both Active and held calls available, so show Accept Call Choice Box */
2245                 vc_engine_accept_choice_box_type event_data;
2246
2247                 memset(&event_data, 0, sizeof(event_data));
2248                 event_data.choice = VC_CALL_ACCEPT_2;
2249
2250                 vcall_engine_send_event_to_client(VC_ENGINE_MSG_ACCEPT_CHOICE_BOX_TO_UI, (void *)&event_data);
2251
2252                 return TRUE;
2253         } else if (TRUE == active_calls) {
2254                 /*If Auto Accpet is FALSE, show popup for manual accept */
2255                 if (FALSE == auto_accept) {
2256                         /* Active  calls available, so show Accept Call Choice Box */
2257                         vc_engine_accept_choice_box_type event_data;
2258
2259                         memset(&event_data, 0, sizeof(event_data));
2260                         event_data.choice = VC_CALL_ACCEPT_1;
2261
2262                         vcall_engine_send_event_to_client(VC_ENGINE_MSG_ACCEPT_CHOICE_BOX_TO_UI, (void *)&event_data);
2263                 } else {
2264                         voicecall_core_answer_call_bytype(pcall_core, VC_ANSWER_HOLD_ACTIVE_AND_ACCEPT);
2265                 }
2266                 return TRUE;
2267         } else if (TRUE == held_calls) {
2268                 /* vcui_app_view_mtcall_destroy(papp_document); */
2269         }
2270
2271         /* Normal Call Scenario */
2272         voicecall_core_answer_call_bytype(pcall_core, VC_ANSWER_NORMAL);
2273
2274         return TRUE;
2275 }
2276
2277 /**
2278  * This function answers an incoming call  according to the given type
2279  *
2280  * @return              Returns TRUE -if answer is sucess, FALSE - otherwise
2281  * @param[in]           pcall_core              Handle to voicecall core
2282  */
2283 gboolean voicecall_core_answer_call_bytype(call_vc_core_state_t *pcall_core, voicecall_answer_type_t answer_type)
2284 {
2285         voicecall_engine_t *pcall_engine = pcall_core->pcall_engine;
2286
2287         voicecall_error_t error_code = ERROR_VOICECALL_NONE;
2288
2289         CALL_ENG_DEBUG(ENG_DEBUG, "answer type: %d", answer_type);
2290
2291         /*First Stop the Incoming alert */
2292         voicecall_snd_stop_alert(pcall_core->papp_snd);
2293         __voicecall_core_cancel_auto_answer(pcall_core);
2294
2295         error_code = _vc_core_engine_answer_call(pcall_engine, answer_type);
2296
2297         if (ERROR_VOICECALL_NONE != error_code) {
2298                 CALL_ENG_DEBUG(ENG_ERR, "_vc_core_engine_answer_call Failed : %d", error_code);
2299                 return FALSE;
2300         }
2301
2302         return TRUE;
2303 }
2304
2305 /**
2306 * This function rejects an incoming call
2307 *
2308 * @return               Returns TRUE on success or FALSE on failure
2309 * @param[in]            pcall_core              Handle to voicecall core
2310 * @param[in]            bUDUB                   TRUE - set UDUB, FALSE - reject call
2311 */
2312 gboolean voicecall_core_reject_mt(call_vc_core_state_t *pcall_core, gboolean bUDUB)
2313 {
2314         voicecall_engine_t *pcall_engine = pcall_core->pcall_engine;
2315         voicecall_snd_mgr_t *papp_snd = pcall_core->papp_snd;
2316
2317         voicecall_error_t error_code = ERROR_VOICECALL_NONE;
2318
2319         CALL_ENG_DEBUG(ENG_DEBUG, "");
2320
2321         /*Incoming call rejected, reset the accept by flag */
2322         voicecall_core_set_status(pcall_core, CALL_VC_CORE_FLAG_ACCEPT_BY_BT, FALSE);
2323
2324         /* Stop Incmoing Call Alert */
2325         voicecall_snd_stop_alert(papp_snd);
2326
2327         __voicecall_core_cancel_auto_answer(pcall_core);
2328
2329         CALL_ENG_DEBUG(ENG_DEBUG, "bUDUB = %d", bUDUB);
2330         error_code = _vc_core_engine_reject_call(pcall_engine, bUDUB);
2331
2332         if (ERROR_VOICECALL_NONE != error_code) {
2333                 CALL_ENG_DEBUG(ENG_ERR, "_vc_core_engine_reject_call Failed, error_code = %ud", error_code);
2334                 return FALSE;
2335         }
2336
2337         return TRUE;
2338
2339 }
2340
2341 /**
2342  * This function ends the call by state
2343  *
2344  * @return              Returns TRUE on success or FALSE on failure
2345  * @param[in]           pcall_core              Handle to voicecall core
2346  */
2347 gboolean voicecall_core_end_call(call_vc_core_state_t *pcall_core)
2348 {
2349         voicecall_engine_t *pcall_engine = pcall_core->pcall_engine;
2350
2351         CALL_ENG_DEBUG(ENG_DEBUG, "");
2352
2353         return (ERROR_VOICECALL_NONE == _vc_core_engine_end_call(pcall_engine, VC_END_ACTIVE_OR_HELD_CALLS)) ? TRUE : FALSE;
2354 }
2355
2356 /**
2357  * This function ends the call corresponding to the given call handle
2358  *
2359  * @return              Returns TRUE on success or FALSE on failure
2360  * @param[in]           pcall_core              Handle to voicecall core
2361  * @param[in]           call_handle             handle of the call to be ended
2362  */
2363 gboolean voicecall_core_end_call_by_handle(call_vc_core_state_t *pcall_core, int call_handle)
2364 {
2365         voicecall_engine_t *pcall_engine = pcall_core->pcall_engine;
2366
2367         CALL_ENG_DEBUG(ENG_DEBUG, "");
2368
2369         return (ERROR_VOICECALL_NONE == _vc_core_engine_end_call_byhandle(pcall_engine, call_handle)) ? TRUE : FALSE;
2370 }
2371
2372 /**
2373  * This function ends all available calls
2374  *
2375  * @return              Returns TRUE on success or FALSE on failure
2376  * @param[in]           pcall_core              Handle to voicecall core
2377  */
2378 gboolean voicecall_core_end_all_calls(call_vc_core_state_t *pcall_core)
2379 {
2380         voicecall_engine_t *pcall_engine = pcall_core->pcall_engine;
2381
2382         CALL_ENG_DEBUG(ENG_DEBUG, "");
2383
2384         return (ERROR_VOICECALL_NONE == _vc_core_engine_end_call(pcall_engine, VC_END_ALL_CALLS)) ? TRUE : FALSE;
2385 }
2386
2387 /**
2388  * This function ends all available active calls
2389  *
2390  * @return              Returns TRUE on success or FALSE on failure
2391  * @param[in]           pcall_core              Handle to voicecall core
2392  */
2393 gboolean voicecall_core_end_all_active_calls(call_vc_core_state_t *pcall_core)
2394 {
2395         voicecall_engine_t *pcall_engine = pcall_core->pcall_engine;
2396
2397         CALL_ENG_DEBUG(ENG_DEBUG, "");
2398
2399         return (ERROR_VOICECALL_NONE == _vc_core_engine_end_call(pcall_engine, VC_END_ALL_ACTIVE_CALLS)) ? TRUE : FALSE;
2400 }
2401
2402 /**
2403  * This function ends all available held calls
2404  *
2405  * @return              Returns TRUE on success or FALSE on failure
2406  * @param[in]           pcall_core              Handle to voicecall core
2407  */
2408 gboolean voicecall_core_end_all_held_calls(call_vc_core_state_t *pcall_core)
2409 {
2410         voicecall_engine_t *pcall_engine = pcall_core->pcall_engine;
2411
2412         CALL_ENG_DEBUG(ENG_DEBUG, "");
2413
2414         return (ERROR_VOICECALL_NONE == _vc_core_engine_end_call(pcall_engine, VC_END_ALL_HELD_CALLS)) ? TRUE : FALSE;
2415 }
2416
2417 /**
2418  * This function cancel outgoing call
2419  *
2420  * @return              Returns TRUE -if answer is sucess, FALSE - otherwise
2421  * @param[in]           pcall_core              Handle to voicecall core
2422  */
2423 gboolean voicecall_core_cancel_call(call_vc_core_state_t *pcall_core)
2424 {
2425         int io_state = 0;
2426         voicecall_engine_t *pcall_engine = pcall_core->pcall_engine;
2427
2428         voicecall_call_type_bysetup_t call_setup_by = VC_CALL_SETUP_BY_NORMAL;
2429
2430         CALL_ENG_DEBUG(ENG_DEBUG, "");
2431
2432         /*Get Call Setup by Information */
2433         call_setup_by = pcall_core->call_setup_info.call_setup_by;
2434
2435         _vc_core_engine_status_get_engine_iostate(pcall_engine, &io_state);
2436
2437         switch (io_state) {
2438         case VC_INOUT_STATE_OUTGOING_WAIT_HOLD:
2439                 {
2440                         int call_handle = -1;
2441
2442                         if (VC_CALL_SETUP_BY_SAT == call_setup_by) {
2443                                 _vc_core_engine_send_sat_response(pcall_engine, SAT_RQST_SETUP_CALL, CALL_VC_ME_CLEAR_DOWN_BEFORE_CONN);
2444                         }
2445
2446                         /* Clear the MO Call, since the call is not dialed yet */
2447                         _vc_core_engine_status_get_call_handle_bytype(pcall_engine, VC_OUTGOING_CALL, &call_handle);
2448                         _vc_bt_send_response_to_bt(pcall_core, BT_AG_RES_CALL_END, call_handle, NULL);
2449
2450                         __vc_core_set_auto_redial_count(pcall_core, 0);
2451                         voicecall_core_clear_mo_call(pcall_engine);
2452
2453                         _vc_core_engine_change_engine_iostate(pcall_engine, VC_INOUT_STATE_OUTGOING_ABORTED);
2454                 }
2455                 return TRUE;
2456
2457         case VC_INOUT_STATE_OUTGOING_WAIT_ORIG:
2458         case VC_INOUT_STATE_OUTGOING_WAIT_ALERT:
2459         case VC_INOUT_STATE_OUTGOING_WAIT_CONNECTED:
2460                 {
2461                         /*To retrieve the held call automatically once the mo call is ended, if held is call is available */
2462                         _vc_core_engine_status_set_end_flag(pcall_engine, VC_RETREIVE_CALL_ON_MOCALL_END);
2463
2464                         /* release the call , since it is dialed and waiting for connecting */
2465                         if (FALSE == voicecall_core_end_mo_call(pcall_engine)) {
2466                                 CALL_ENG_DEBUG(ENG_DEBUG, "MO Call Release Failed");
2467                         } else {
2468                                 voicecall_core_set_status(pcall_core, CALL_VC_CORE_FLAG_MOCALL_END_BY_USER, TRUE);
2469                                 _vc_core_engine_change_engine_iostate(pcall_engine, VC_INOUT_STATE_OUTGOING_WAIT_RELEASE);
2470                         }
2471                 }
2472                 return TRUE;
2473
2474         case VC_INOUT_STATE_OUTGOING_WAIT_RELEASE:
2475                 {
2476                         /*Call already released */
2477                         CALL_ENG_DEBUG(ENG_DEBUG, "MO Call has been released already");
2478                 }
2479                 return TRUE;
2480
2481         case VC_INOUT_STATE_OUTGOING_SHOW_REDIALCAUSE:
2482         case VC_INOUT_STATE_OUTGOING_ABORTED:
2483         case VC_INOUT_STATE_OUTGOING_WAIT_REDIAL:
2484                 {
2485                         int call_handle = -1;
2486
2487                         if (VC_CALL_SETUP_BY_SAT == call_setup_by) {
2488                                 _vc_core_engine_send_sat_response(pcall_engine, SAT_RQST_SETUP_CALL, CALL_VC_NETWORK_UNABLE_TO_PROCESS_COMMAND);
2489                         }
2490
2491                         /*Stop Signal Play */
2492                         voicecall_snd_stop_signal(pcall_core->papp_snd);
2493
2494                         __voicecall_core_mocall_reset_engine_state(pcall_engine);
2495
2496                         _vc_core_engine_status_get_call_handle_bytype(pcall_engine, VC_OUTGOING_CALL, &call_handle);
2497                         _vc_bt_send_response_to_bt(pcall_core, BT_AG_RES_CALL_END, call_handle, NULL);
2498
2499                         __vc_core_set_auto_redial_count(pcall_core, 0);
2500                         voicecall_core_clear_mo_call(pcall_engine);
2501
2502                 }
2503                 return TRUE;
2504
2505         default:
2506                 CALL_ENG_DEBUG(ENG_DEBUG, "Action not defined for this IO State: %d", io_state);
2507                 break;
2508         }
2509
2510         return FALSE;
2511 }
2512
2513 /**
2514  * This function process hold/retrive/swap conntected call
2515  *
2516  * @return              Returns TRUE -if answer is sucess, FALSE - otherwise
2517  * @param[in]           pcall_core              Handle to voicecall core
2518  */
2519 gboolean voicecall_core_process_hold_call(call_vc_core_state_t *pcall_core)
2520 {
2521         voicecall_engine_t *pcall_engine = pcall_core->pcall_engine;
2522
2523         gboolean active_calls = FALSE;
2524         gboolean held_calls = FALSE;
2525
2526         CALL_ENG_DEBUG(ENG_DEBUG, "");
2527
2528         if (TRUE == voicecall_core_get_status(pcall_core, CALL_VC_CORE_FLAG_SOS_CALL_ONLY)) {
2529                 CALL_ENG_DEBUG(ENG_DEBUG, "SOS Call... Ignore this button...");
2530                 return TRUE;
2531         }
2532
2533         if (FALSE == voicecall_core_is_incall_request_possible(pcall_engine)) {
2534                 return TRUE;
2535         }
2536
2537         voicecall_core_is_call_exists(pcall_engine, &active_calls, &held_calls);
2538         CALL_ENG_DEBUG(ENG_DEBUG, "active calls: %d, held calls: %d", active_calls, held_calls);
2539
2540         if (active_calls && held_calls) {
2541
2542                 /*Both Calls available, swap the calls */
2543                 if (FALSE == voicecall_core_swap_calls(pcall_engine)) {
2544                         return FALSE;
2545                 }
2546         } else if (active_calls) {
2547                 /*Only activa call available, hold the call */
2548                 if (FALSE == voicecall_core_hold_call(pcall_engine)) {
2549                         return FALSE;
2550                 }
2551         } else if (held_calls) {
2552                 /*Only Held call available, retrieve the call */
2553                 if (FALSE == voicecall_core_retrieve_call(pcall_engine)) {
2554                         return FALSE;
2555                 }
2556         } else {
2557                 CALL_ENG_DEBUG(ENG_DEBUG, "no call exists!");
2558                 return FALSE;
2559         }
2560
2561         return TRUE;
2562 }
2563
2564 /**
2565  * This function sets up a conference call
2566  *
2567  * @return              Returns TRUE on success or FALSE on failure
2568  * @param[in]           pcall_core              Handle to voicecall core
2569  */
2570 gboolean voicecall_core_setup_conference(call_vc_core_state_t *pcall_core)
2571 {
2572         voicecall_engine_t *pcall_engine = pcall_core->pcall_engine;
2573
2574         CALL_ENG_DEBUG(ENG_DEBUG, "");
2575
2576         return (ERROR_VOICECALL_NONE == _vc_core_engine_setup_conference(pcall_engine)) ? TRUE : FALSE;
2577 }
2578
2579 /**
2580  * This function splits the call corressponding to the given call handle and makes a private call
2581  *
2582  * @return              Returns TRUE on success or FALSE on failure
2583  * @param[in]           pcall_core              Handle to voicecall core
2584  * @param[in]           call_handle             Call to be splitted from the conference call
2585  */
2586 gboolean voicecall_core_make_private_call(call_vc_core_state_t *pcall_core, int call_handle)
2587 {
2588         voicecall_engine_t *pcall_engine = pcall_core->pcall_engine;
2589
2590         CALL_ENG_DEBUG(ENG_DEBUG, "");
2591
2592         return (ERROR_VOICECALL_NONE == _vc_core_engine_private_call(pcall_engine, call_handle)) ? TRUE : FALSE;
2593 }
2594
2595 /**
2596  * This function transfers the call from active call to the held call
2597  *
2598  * @return              Returns TRUE on success or FALSE on failure
2599  * @param[in]           pcall_core              Handle to voicecall core
2600  */
2601 gboolean voicecall_core_transfer_calls(call_vc_core_state_t *pcall_core)
2602 {
2603         voicecall_engine_t *pcall_engine = pcall_core->pcall_engine;
2604
2605         CALL_ENG_DEBUG(ENG_DEBUG, "");
2606
2607         return (ERROR_VOICECALL_NONE == _vc_core_engine_transfer_calls(pcall_engine)) ? TRUE : FALSE;
2608 }
2609
2610 /**
2611  * This function sends a dtmf string
2612  *
2613  * @return              Returns TRUE on success or FALSE on failure
2614  * @param[in]           pcall_core              Handle to voicecall core
2615  * @param[in]           dtmf_string             dtmf string to be sent
2616  */
2617 gboolean voicecall_core_send_dtmf(call_vc_core_state_t *pcall_core, char *dtmf_string)
2618 {
2619         voicecall_error_t error_code = ERROR_VOICECALL_NONE;
2620         CALL_ENG_DEBUG(ENG_DEBUG, "dtmf string: %s", dtmf_string);
2621
2622         pcall_core->bdtmf_queue = FALSE;
2623         error_code = _vc_core_engine_send_dtmf(pcall_core->pcall_engine, dtmf_string);
2624         return (ERROR_VOICECALL_NONE == error_code) ? TRUE : FALSE;
2625 }
2626
2627 /**
2628 * This function stops sound alert in case of reject with msg
2629 *
2630 * @return               Returns TRUE on success or FALSE on failure
2631 * @param[in]            pcall_core              Handle to voicecall core
2632 */
2633 gboolean voicecall_core_stop_alert(call_vc_core_state_t *pcall_core)
2634 {
2635         CALL_ENG_DEBUG(ENG_DEBUG, "");
2636
2637         /* Stop Incmoing Call Alert */
2638         voicecall_snd_stop_alert(pcall_core->papp_snd);
2639
2640         return TRUE;
2641 }
2642
2643 inline gboolean voicecall_core_get_mo_call_handle(call_vc_core_state_t *pcall_core, int *pcall_handle)
2644 {
2645         *pcall_handle = -1;
2646         return (ERROR_VOICECALL_NONE == _vc_core_engine_status_get_call_handle_bytype(pcall_core->pcall_engine, VC_OUTGOING_CALL, pcall_handle)) ? TRUE : FALSE;
2647 }
2648
2649 inline int voicecall_core_get_auto_redial_count(call_vc_core_state_t *pcall_core)
2650 {
2651         return pcall_core->auto_redial_count;
2652 }
2653
2654 void __vc_core_set_auto_redial_count(call_vc_core_state_t *pcall_core, int auto_redial_count)
2655 {
2656         pcall_core->auto_redial_count = auto_redial_count;
2657 }
2658
2659 gboolean voicecall_core_start_redial(call_vc_core_state_t *pcall_core, int manual_redial)
2660 {
2661         int auto_redial_status = FALSE;
2662         int redial_count = 1;
2663         int call_handle = -1;
2664         int total_call_member = 0;
2665
2666         CALL_ENG_DEBUG(ENG_DEBUG, "");
2667         CALL_ENG_DEBUG(ENG_DEBUG, "auto_redial_status:[%d]", auto_redial_status);
2668
2669         redial_count = voicecall_core_get_auto_redial_count(pcall_core);
2670
2671         redial_count++;
2672
2673         /*
2674            bmanual_redial == TRUE : Redial is made by User, No need to check the auto redial status and count
2675            auto_redial_status == 1: Auto Redial for GCF case, auto redial count must be checked
2676          */
2677         if ((1 == manual_redial) || ((auto_redial_status == 1) && (redial_count < MO_REDIAL_COUNT_MAX))) {
2678                 CALL_ENG_DEBUG(ENG_DEBUG, "redial_count = %d", redial_count);
2679
2680                 /*Start Redial Timer */
2681                 if (1 == redial_count) {
2682                         CALL_ENG_DEBUG(ENG_DEBUG, "MO_REDIAL_TIMER_INTERVAL_FIRST");
2683                         pcall_core->mo_redial_timer = g_timeout_add(MO_REDIAL_TIMER_INTERVAL_FIRST, mo_redial_timer_cb, pcall_core);
2684                 } else if ((redial_count > 1) && (redial_count < 5)) {
2685                         CALL_ENG_DEBUG(ENG_DEBUG, "MO_REDIAL_TIMER_INTERVAL_SECOND");
2686                         pcall_core->mo_redial_timer = g_timeout_add(MO_REDIAL_TIMER_INTERVAL_SECOND, mo_redial_timer_cb, pcall_core);
2687                 } else {
2688                         CALL_ENG_DEBUG(ENG_DEBUG, "MO_REDIAL_TIMER_INTERVAL_THIRD");
2689                         pcall_core->mo_redial_timer = g_timeout_add(MO_REDIAL_TIMER_INTERVAL_THIRD, mo_redial_timer_cb, pcall_core);
2690                 }
2691
2692                 voicecall_core_change_engine_state(pcall_core->pcall_engine, VC_INOUT_STATE_OUTGOING_WAIT_REDIAL);
2693         } else {
2694                 CALL_ENG_DEBUG(ENG_DEBUG, "You dont need to redial close the MO Call Things");
2695
2696                 /* __vcui_app_view_mo_canceltimer_cb() */
2697                 _vc_core_engine_status_get_call_handle_bytype(pcall_core->pcall_engine, VC_OUTGOING_CALL, &call_handle);
2698                 _vc_bt_send_response_to_bt(pcall_core, BT_AG_RES_CALL_END, call_handle, NULL);
2699
2700                 __vc_core_set_auto_redial_count(pcall_core, 0);
2701                 voicecall_core_clear_mo_call(pcall_core->pcall_engine);
2702
2703                 __voicecall_core_mocall_reset_engine_state(pcall_core->pcall_engine);
2704
2705                 voicecall_core_get_total_call_member(pcall_core->pcall_engine, &total_call_member);
2706
2707                 voicecall_snd_stop_signal(pcall_core->papp_snd);
2708
2709                 /* If No Connected Calls End the UI */
2710                 if (total_call_member == 0) {
2711                         /*Reset voice call core to default values */
2712                         voicecall_core_set_to_default(pcall_core);
2713                 } else {
2714                         voicecall_snd_change_path(pcall_core->papp_snd);
2715                 }
2716
2717         }
2718
2719         return TRUE;
2720 }
2721
2722 inline gboolean voicecall_core_prepare_redial(call_vc_core_state_t *pcall_core, int call_handle)
2723 {
2724         voicecall_error_t error_code = ERROR_VOICECALL_NONE;
2725
2726         CALL_ENG_DEBUG(ENG_DEBUG, "");
2727
2728         error_code = _vc_core_engine_prepare_redial(pcall_core->pcall_engine, call_handle);
2729
2730         CALL_ENG_DEBUG(ENG_DEBUG, "_vc_core_engine_prepare_redial returned : %d", error_code);
2731
2732         return (ERROR_VOICECALL_NONE == error_code) ? TRUE : FALSE;
2733 }
2734
2735 gboolean mo_redial_timer_cb(void *data)
2736 {
2737         int call_handle = -1;
2738         int redial_count;
2739
2740         CALL_ENG_DEBUG(ENG_DEBUG, "mo_redial_timer_cb");
2741         call_vc_core_state_t *pcall_core = (call_vc_core_state_t *)data;
2742         voicecall_core_get_mo_call_handle(pcall_core, &call_handle);
2743         CALL_ENG_DEBUG(ENG_DEBUG, "call handle is %d", call_handle);
2744
2745         redial_count = voicecall_core_get_auto_redial_count(pcall_core);
2746         redial_count++;
2747         __vc_core_set_auto_redial_count(pcall_core, redial_count);
2748
2749         CALL_ENG_DEBUG(ENG_DEBUG, "redial_count:[%d]", redial_count);
2750
2751         voicecall_core_prepare_redial(pcall_core, call_handle);
2752         CALL_ENG_DEBUG(ENG_DEBUG, "voicecall_core_prepare_redial done.");
2753
2754         voicecall_core_make_call(pcall_core);
2755         return FALSE;
2756 }
2757
2758 gboolean voicecall_core_stop_redial(call_vc_core_state_t *pcall_core)
2759 {
2760         int call_handle = -1, total_call_member = -1;
2761
2762         CALL_ENG_DEBUG(ENG_DEBUG, "coming inside voicecall_core_stop_redial");
2763
2764         _vc_core_util_set_call_status(VCONFKEY_CALL_OFF);
2765
2766         /*Cancel the Redial Timer */
2767         if (pcall_core->mo_redial_timer != -1) {
2768                 CALL_ENG_DEBUG(ENG_DEBUG, "mo_redial_timer removing..");
2769                 g_source_remove(pcall_core->mo_redial_timer);
2770                 pcall_core->mo_redial_timer = -1;
2771         }
2772
2773         /* __vcui_app_view_mo_canceltimer_cb() */
2774         _vc_core_engine_status_get_call_handle_bytype(pcall_core->pcall_engine, VC_OUTGOING_CALL, &call_handle);
2775         _vc_bt_send_response_to_bt(pcall_core, BT_AG_RES_CALL_END, call_handle, NULL);
2776
2777         __vc_core_set_auto_redial_count(pcall_core, 0);
2778         voicecall_core_clear_mo_call(pcall_core->pcall_engine);
2779
2780         __voicecall_core_mocall_reset_engine_state(pcall_core->pcall_engine);
2781
2782         voicecall_core_get_total_call_member(pcall_core->pcall_engine, &total_call_member);
2783
2784         voicecall_snd_stop_signal(pcall_core->papp_snd);
2785
2786         /* If No Connected Calls End the UI */
2787         if (total_call_member == 0) {
2788                 /*Reset voice call core to default values */
2789                 voicecall_core_set_to_default(pcall_core);
2790         } else {
2791                 voicecall_snd_change_path(pcall_core->papp_snd);
2792         }
2793         return TRUE;
2794
2795 }
2796
2797 static gboolean __voicecall_core_auto_answer_timer_cb(gpointer puser_data)
2798 {
2799         call_vc_core_state_t *pcall_core = (call_vc_core_state_t *)puser_data;
2800
2801         if (pcall_core->auto_answer_timer > 0) {
2802                 g_source_remove(pcall_core->auto_answer_timer);
2803                 pcall_core->auto_answer_timer = 0;
2804         }
2805
2806         /*Check for Incoming call and then answer the call */
2807         if (TRUE == voicecall_core_is_incoming_call_exists(pcall_core->pcall_engine)) {
2808                 CALL_ENG_DEBUG(ENG_DEBUG, "Call Answered");
2809                 voicecall_core_answer_call(pcall_core, TRUE);
2810         }
2811
2812         return FALSE;
2813 }
2814
2815 #if 0
2816 static gboolean __voicecall_core_callstatus_set_timer_cb(gpointer puser_data)
2817 {
2818         call_vc_core_state_t *pcall_core = (call_vc_core_state_t *)puser_data;
2819
2820         if (pcall_core->callstatus_timer > 0) {
2821                 g_source_remove(pcall_core->callstatus_timer);
2822                 pcall_core->callstatus_timer = 0;
2823         }
2824
2825         _vc_core_util_set_call_status(VCONFKEY_CALL_VOICE_CONNECTING);
2826
2827         return FALSE;
2828 }
2829 #endif
2830
2831 static gboolean __voicecall_core_auto_answer_idle_cb(gpointer puser_data)
2832 {
2833         call_vc_core_state_t *pcall_core = (call_vc_core_state_t *)puser_data;
2834         int engine_state = 0;
2835         int auto_answer_time = 0, ret = -1;
2836         unsigned long auto_answer_time_interval = 0;
2837
2838         _vc_core_engine_status_get_engine_iostate(pcall_core->pcall_engine, &engine_state);
2839         CALL_ENG_DEBUG(ENG_DEBUG, "eng_state : %d", engine_state);
2840         if (engine_state != VC_INOUT_STATE_INCOME_BOX) {
2841                 CALL_ENG_DEBUG(ENG_DEBUG, "Engine State not in Income Box, Current State: %d", engine_state);
2842                 return FALSE;
2843         }
2844         /* Read the time interval from gconf and set the redial timer  */
2845         ret = vconf_get_int(VCONFKEY_CISSAPPL_ANSWERING_MODE_TIME_INT, &auto_answer_time);
2846         if (0 == ret) {
2847                 auto_answer_time_interval = auto_answer_time * 1000;
2848                 CALL_ENG_DEBUG(ENG_DEBUG, "The time interval is : %ld", auto_answer_time_interval);
2849         } else {
2850                 CALL_ENG_DEBUG(ENG_DEBUG, "vconf_get_int FAILED");
2851                 return FALSE;
2852         }
2853
2854         pcall_core->auto_answer_timer = g_timeout_add(auto_answer_time_interval, __voicecall_core_auto_answer_timer_cb, pcall_core);
2855         return FALSE;
2856 }
2857
2858 /**
2859 * This function checks whether given answer mode is enabled or not
2860 *
2861 * @return               returns TRUE if given answer mode type is enabled in the settings or FALSE otherwise
2862 *
2863 */
2864 static gboolean __vc_core_is_answermode_enabled_from_testmode(void)
2865 {
2866         CALL_ENG_DEBUG(ENG_DEBUG, "..");
2867         int benabled = -1;
2868         int ret = -1;
2869
2870         ret = vconf_get_int(VCONFKEY_TESTMODE_AUTO_ANSWER, &benabled);
2871         if (0 == ret) {
2872                 CALL_ENG_DEBUG(ENG_DEBUG, "benabled = %d", benabled);
2873                 if (TRUE == benabled)
2874                         return TRUE;
2875                 else
2876                         return FALSE;
2877         } else {
2878                 CALL_ENG_DEBUG(ENG_DEBUG, "vconf_get_int FAILED");
2879                 return FALSE;
2880         }
2881 }
2882
2883 /**
2884 * This function checks whether given answer mode is enabled or not
2885 *
2886 * @return               returns TRUE if given answer mode type is enabled in the settings or FALSE otherwise
2887 *
2888 */
2889 static gboolean __vc_core_is_answermode_enabled(void)
2890 {
2891         CALL_ENG_DEBUG(ENG_DEBUG, "coming inside voicecall_is_answermode_enabled");
2892         int answer_mode_enabled = -1;
2893         int ret = -1;
2894
2895         ret = vconf_get_int(VCONFKEY_CISSAPPL_ANSWERING_MODE_INT, &answer_mode_enabled);
2896         if (0 == ret) {
2897                 CALL_ENG_DEBUG(ENG_DEBUG, "answer_mode_enabled = %d", answer_mode_enabled);
2898                 if (2 == answer_mode_enabled)   /* here 2 is auto answer mode is enabled */
2899                         return TRUE;
2900                 else
2901                         return FALSE;
2902         } else {
2903                 CALL_ENG_DEBUG(ENG_DEBUG, "vconf_get_int FAILED");
2904                 return FALSE;
2905         }
2906
2907 }
2908
2909 /**
2910 * This function processes auto answer request
2911 *
2912 * @return               Returns void
2913 * @param[in]            pcall_core              Handle to voicecall core
2914 */
2915 static void __voicecall_core_start_auto_answer(call_vc_core_state_t *pcall_core, gboolean isTestMode)
2916 {
2917         gboolean earjack_connected = FALSE;
2918         gboolean headset_connected = FALSE;
2919
2920         CALL_ENG_DEBUG(ENG_DEBUG, "..");
2921
2922         if (TRUE == isTestMode) {
2923                 CALL_ENG_DEBUG(ENG_DEBUG, "In case Of Testmode, always auto answer enabled");
2924
2925                 g_idle_add(__voicecall_core_auto_answer_idle_cb, pcall_core);
2926                 return;
2927         }
2928         earjack_connected = _voicecall_dvc_get_earjack_connected();
2929
2930         if (TRUE == earjack_connected) {
2931                 CALL_ENG_DEBUG(ENG_DEBUG, "earjack is connected");
2932         }
2933         headset_connected = _vc_bt_get_bt_status();
2934
2935         if (TRUE == headset_connected) {
2936                 CALL_ENG_DEBUG(ENG_DEBUG, "headset is connected");
2937         }
2938
2939         if (TRUE == earjack_connected || TRUE == headset_connected) {
2940                 g_idle_add(__voicecall_core_auto_answer_idle_cb, pcall_core);
2941         } else {
2942                 CALL_ENG_DEBUG(ENG_DEBUG, "Without earjack or headset, skip auto answer ");
2943                 return;
2944         }
2945 }
2946
2947 /**
2948 * This function cancels the auto answering timer
2949 *
2950 * @return               void
2951 * @param[in]            pcall_core              Handle to voicecall core
2952 */
2953 static void __voicecall_core_cancel_auto_answer(call_vc_core_state_t *pcall_core)
2954 {
2955         CALL_ENG_DEBUG(ENG_DEBUG, "coming inside __voicecall_cancel_auto_answer");
2956         if (pcall_core->auto_answer_timer > 0) {
2957                 g_source_remove(pcall_core->auto_answer_timer);
2958                 pcall_core->auto_answer_timer = 0;
2959         }
2960 }
2961
2962 #if 0
2963 /**
2964 * This function checks BT headset and Earjack status
2965 *
2966 * @return               void
2967 * @param[in]            pcall_core              Handle to voicecall core
2968 */
2969 static void __voicecall_core_check_headset_earjack_status(call_vc_core_state_t *pcall_core)
2970 {
2971         gboolean bt_connected = FALSE;
2972
2973         bt_connected = _vc_bt_get_bt_status();
2974         CALL_ENG_DEBUG(ENG_DEBUG, "Bt connected =%d", bt_connected);
2975
2976         pcall_core->bt_connected = bt_connected;
2977
2978         CALL_ENG_DEBUG(ENG_DEBUG, "Update the earjack status");
2979         _voicecall_dvc_get_earjack_status(pcall_core);
2980 }
2981 #endif
2982
2983 /**
2984  * This function parses the in call supplementary services string and returns the in call ss to be used
2985  *
2986  * @return              Returns in call ss state #vcui_app_incall_ss_state_t
2987  * @param[in]           pcall_core              Handle to voicecall core
2988  * @param[in]           number                  number to be parsed
2989  */
2990 call_vc_core_incall_ss_state_t voicecall_core_parse_incall_ss_string(call_vc_core_state_t *pcall_core, char *number)
2991 {
2992         call_vc_core_incall_ss_state_t ss_value = CALL_VC_CORE_SS_USSD;
2993
2994         if (strlen(number) == 1) {
2995                 switch (number[0]) {
2996                 case '0':
2997                         ss_value = CALL_VC_CORE_SS_0;
2998                         break;
2999                 case '1':
3000                         ss_value = CALL_VC_CORE_SS_1;
3001                         break;
3002                 case '2':
3003                         ss_value = CALL_VC_CORE_SS_2;
3004                         break;
3005                 case '3':
3006                         ss_value = CALL_VC_CORE_SS_3;
3007                         break;
3008                 case '4':
3009                         ss_value = CALL_VC_CORE_SS_4;
3010                         break;
3011                 default:
3012                         ss_value = CALL_VC_CORE_SS_USSD;
3013                         break;
3014                 }
3015         } else if (strlen(number) == 2) {
3016                 if ((number[0] == '1') && (number[1] > '0') && (number[1] < '8')) {
3017                         pcall_core->selected_call_id_in_ss = atoi(number + 1);
3018                         ss_value = CALL_VC_CORE_SS_1X;
3019                 }
3020
3021                 if ((number[0] == '2') && (number[1] > '0') && (number[1] < '8')) {
3022                         pcall_core->selected_call_id_in_ss = atoi(number + 1);
3023                         ss_value = CALL_VC_CORE_SS_2X;
3024                 }
3025         }
3026         CALL_ENG_DEBUG(ENG_DEBUG, "ss parsed value: %d", ss_value);
3027         return ss_value;
3028 }
3029
3030 /**
3031  * This function starts the supplementary services while on call
3032  *
3033  * @return              Returns TRUE If transfer call can be made or FALSE if not
3034  * @param[in]           pcall_core              Handle to voicecall core
3035  * @param[in]           incall_ss_state         state of the In Call Supplementary Service
3036  */
3037 gboolean voicecall_core_start_incall_ss(call_vc_core_state_t *pcall_core, call_vc_core_incall_ss_state_t incall_ss_state)
3038 {
3039         gboolean active_calls = FALSE, held_calls = FALSE;
3040
3041         _vc_core_engine_status_isexists_any_call(pcall_core->pcall_engine, &active_calls, &held_calls);
3042
3043         CALL_ENG_DEBUG(ENG_DEBUG, "ss state = %d", incall_ss_state);
3044         vc_engine_msg_box_type event_data;
3045         memset(&event_data, 0, sizeof(event_data));
3046         event_data.string_id = IDS_CALL_POP_OPERATION_REFUSED;
3047
3048         /*Cancel DTMF Sending if any and close the dtmf ui */
3049         /* vcui_app_doc_cancel_dtmf_queue(papp_document); sathwick TBD */
3050
3051         switch (incall_ss_state) {
3052                 /* Releases all held calls or Set UDUB(User Determined User Busy) for a waiting call */
3053         case CALL_VC_CORE_SS_0:
3054                 {
3055                         /* if an incoming call is activated, reject the incoming all  */
3056                         if (TRUE == voicecall_core_is_incoming_call_exists(pcall_core->pcall_engine)) {
3057                                 voicecall_core_reject_mt(pcall_core, TRUE);
3058                                 return TRUE;
3059                         } else if (held_calls) {
3060                                 voicecall_core_end_all_held_calls(pcall_core);
3061                         } else {
3062                                 CALL_ENG_DEBUG(ENG_DEBUG, "There are no held calls to do the processing");
3063                                 vcall_engine_send_event_to_client(VC_ENGINE_MSG_MESSAGE_BOX_TO_UI, (void *)&event_data);
3064                                 CALL_ENG_DEBUG(ENG_DEBUG, "Need to show a popup to the user ");
3065                         }
3066                 }
3067                 break;
3068         case CALL_VC_CORE_SS_1:
3069                 {
3070                         if (voicecall_core_is_incoming_call_exists(pcall_core->pcall_engine)) {
3071                                 /* Accept incoming call */
3072                                 voicecall_core_answer_call_bytype(pcall_core, VC_ANSWER_RELEASE_ACTIVE_AND_ACCEPT);
3073                                 return TRUE;
3074                         } else if (voicecall_core_is_outgoing_call_exists(pcall_core->pcall_engine)) {
3075                                 /* This fucntion checks for held calls to be retreived on response of ending call */
3076                                 voicecall_core_set_check_ss_on_end(pcall_core);
3077                                 voicecall_core_end_mo_call(pcall_core->pcall_engine);
3078                         } else if (active_calls) {
3079                                 voicecall_core_end_all_active_calls(pcall_core);
3080                                 voicecall_core_set_check_ss_on_end(pcall_core);
3081                         } else if (held_calls) {
3082                                 _vc_core_engine_retrieve_call(pcall_core->pcall_engine);
3083                         } else {
3084
3085                                 CALL_ENG_DEBUG(ENG_DEBUG, "Need to show a popup to the user ");
3086                                 vcall_engine_send_event_to_client(VC_ENGINE_MSG_MESSAGE_BOX_TO_UI, (void *)&event_data);
3087                         }
3088                 }
3089                 break;
3090         case CALL_VC_CORE_SS_1X:
3091                 {
3092                         if (voicecall_core_is_incoming_call_exists(pcall_core->pcall_engine)) {
3093
3094                                 CALL_ENG_DEBUG(ENG_DEBUG, "Need to show a popup to the user ");
3095                                 vcall_engine_send_event_to_client(VC_ENGINE_MSG_MESSAGE_BOX_TO_UI, (void *)&event_data);
3096                         } else if (active_calls) {
3097
3098                                 if (!(ERROR_VOICECALL_NONE == _vc_core_engine_end_call_bycallId(pcall_core->pcall_engine, pcall_core->selected_call_id_in_ss))) {
3099
3100                                         CALL_ENG_DEBUG(ENG_DEBUG, "Need to show a popup to the user ");
3101                                         vcall_engine_send_event_to_client(VC_ENGINE_MSG_MESSAGE_BOX_TO_UI, (void *)&event_data);
3102                                 }
3103                         } else {
3104
3105                                 CALL_ENG_DEBUG(ENG_DEBUG, "Need to show a popup to the user ");
3106                                 vcall_engine_send_event_to_client(VC_ENGINE_MSG_MESSAGE_BOX_TO_UI, (void *)&event_data);
3107                         }
3108                 }
3109                 break;
3110         case CALL_VC_CORE_SS_2:
3111                 {
3112
3113                         if (voicecall_core_is_incoming_call_exists(pcall_core->pcall_engine)) {
3114                                 if (active_calls && held_calls) {
3115
3116                                         CALL_ENG_DEBUG(ENG_DEBUG, "Need to show a popup to the user ");
3117                                         vcall_engine_send_event_to_client(VC_ENGINE_MSG_MESSAGE_BOX_TO_UI, (void *)&event_data);
3118                                 } else {
3119 #ifdef _CPHS_DEFINED_           /* Not used currently */
3120                                         if (TRUE == active_calls && (voicecall_core_get_cphs_csp_status(pcall_core->pcall_engine, VC_CPHS_CSP_HOLD))) {
3121
3122                                                 CALL_ENG_DEBUG(ENG_DEBUG, "Need to show a popup to the user ");
3123                                                 vcall_engine_send_event_to_client(VC_ENGINE_MSG_MESSAGE_BOX_TO_UI, (void *)&event_data);
3124                                                 break;
3125                                         }
3126 #endif
3127                                         voicecall_core_answer_call(pcall_core, TRUE);
3128                                 }
3129                         } else if (voicecall_core_is_outgoing_call_exists(pcall_core->pcall_engine)) {
3130
3131                                 CALL_ENG_DEBUG(ENG_DEBUG, "Need to show a popup to the user ");
3132                                 vcall_engine_send_event_to_client(VC_ENGINE_MSG_MESSAGE_BOX_TO_UI, (void *)&event_data);
3133                         } else if (active_calls && held_calls) {
3134                                 _vc_core_engine_swap_calls(pcall_core->pcall_engine);
3135                         } else if (active_calls) {
3136                                 _vc_core_engine_hold_call(pcall_core->pcall_engine);
3137                         } else if (held_calls) {
3138                                 _vc_core_engine_retrieve_call(pcall_core->pcall_engine);
3139                         } else {
3140
3141                                 CALL_ENG_DEBUG(ENG_DEBUG, "Need to show a popup to the user ");
3142                                 vcall_engine_send_event_to_client(VC_ENGINE_MSG_MESSAGE_BOX_TO_UI, (void *)&event_data);
3143                         }
3144                 }
3145                 break;
3146         case CALL_VC_CORE_SS_2X:
3147                 {
3148                         if (voicecall_core_is_incoming_call_exists(pcall_core->pcall_engine) || voicecall_core_is_outgoing_call_exists(pcall_core->pcall_engine)) {
3149
3150                                 vcall_engine_send_event_to_client(VC_ENGINE_MSG_MESSAGE_BOX_TO_UI, (void *)&event_data);
3151                                 CALL_ENG_DEBUG(ENG_DEBUG, "Need to show a popup to the user ");
3152                         } else if (TRUE == active_calls && FALSE == held_calls) {
3153                                 int active_members = 0;
3154
3155                                 voicecall_core_get_active_call_member(pcall_core, &active_members);
3156
3157                                 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)))) {
3158
3159                                         CALL_ENG_DEBUG(ENG_DEBUG, "Need to show a popup to the user ");
3160                                         vcall_engine_send_event_to_client(VC_ENGINE_MSG_MESSAGE_BOX_TO_UI, (void *)&event_data);
3161                                 }
3162                         } else {
3163
3164                                 CALL_ENG_DEBUG(ENG_DEBUG, "Need to show a popup to the user ");
3165                                 vcall_engine_send_event_to_client(VC_ENGINE_MSG_MESSAGE_BOX_TO_UI, (void *)&event_data);
3166                         }
3167                 }
3168                 break;
3169         case CALL_VC_CORE_SS_3:
3170                 {
3171                         if (TRUE == voicecall_core_is_incoming_call_exists(pcall_core->pcall_engine)) {
3172
3173                                 CALL_ENG_DEBUG(ENG_DEBUG, "Need to show a popup to the user ");
3174                                 vcall_engine_send_event_to_client(VC_ENGINE_MSG_MESSAGE_BOX_TO_UI, (void *)&event_data);
3175                                 return TRUE;
3176                         }
3177
3178                         if (TRUE == voicecall_core_is_conf_call_possible(pcall_core)) {
3179                                 _vc_core_engine_setup_conference(pcall_core->pcall_engine);
3180                         } else {
3181
3182                                 CALL_ENG_DEBUG(ENG_DEBUG, "Need to show a popup to the user ");
3183                                 vcall_engine_send_event_to_client(VC_ENGINE_MSG_MESSAGE_BOX_TO_UI, (void *)&event_data);
3184                         }
3185                 }
3186                 break;
3187         case CALL_VC_CORE_SS_4:
3188                 if (TRUE == voicecall_core_is_transfer_call_possible(pcall_core)) {
3189                         if (FALSE == voicecall_core_transfer_calls(pcall_core)) {
3190
3191                                 CALL_ENG_DEBUG(ENG_DEBUG, "Need to show a popup to the user ");
3192                                 vcall_engine_send_event_to_client(VC_ENGINE_MSG_MESSAGE_BOX_TO_UI, (void *)&event_data);
3193                         }
3194                 } else {
3195
3196                         CALL_ENG_DEBUG(ENG_DEBUG, "Need to show a popup to the user ");
3197                         vcall_engine_send_event_to_client(VC_ENGINE_MSG_MESSAGE_BOX_TO_UI, (void *)&event_data);
3198                 }
3199                 break;
3200         default:
3201                 CALL_ENG_DEBUG(ENG_DEBUG, "Invalid SS State");
3202                 CALL_ENG_DEBUG(ENG_DEBUG, "Need to show a popup to the user ");
3203                 vcall_engine_send_event_to_client(VC_ENGINE_MSG_MESSAGE_BOX_TO_UI, (void *)&event_data);
3204         }
3205         return TRUE;
3206 }
3207
3208 /**
3209  * This function processed the supplementary services while on call
3210  *
3211  * @return              Returns TRUE If transfer call can be made or FALSE if not
3212  * @param[in]           pcall_core              Handle to voicecall core
3213  * @param[in]           pdialled_number         dial number
3214  */
3215 void voicecall_core_process_incall_ss(call_vc_core_state_t *pcall_core, char *pdialled_number)
3216 {
3217         call_vc_core_incall_ss_state_t incall_ss_state = CALL_VC_CORE_SS_NONE;
3218
3219         CALL_ENG_DEBUG(ENG_DEBUG, " ..");
3220
3221         incall_ss_state = voicecall_core_parse_incall_ss_string(pcall_core, pdialled_number);
3222
3223         if (incall_ss_state != CALL_VC_CORE_SS_USSD) {
3224                 voicecall_core_start_incall_ss(pcall_core, incall_ss_state);
3225         } else {
3226
3227                 CALL_ENG_DEBUG(ENG_DEBUG, "Involves CISS functionality so need for us to handle and will be handled by CISS");
3228                 vc_engine_msg_box_type event_data;
3229                 memset(&event_data, 0, sizeof(event_data));
3230                 event_data.string_id = IDS_CALL_POP_OPERATION_REFUSED;
3231                 vcall_engine_send_event_to_client(VC_ENGINE_MSG_MESSAGE_BOX_TO_UI, (void *)&event_data);
3232         }
3233 }
3234
3235 #ifdef  PDIAL_SEND_DTMF
3236 gboolean voicecall_core_send_phone_number_dtmf(gpointer puser_data)
3237 {
3238         call_vc_core_state_t *pcall_core = (call_vc_core_state_t *)vcall_engine_get_core_state();
3239         int call_handle = (int)puser_data;
3240         char dtmf_number[VC_PHONE_NUMBER_LENGTH_MAX];
3241         call_vc_call_objectinfo_t obj_info = { 0, };
3242
3243         CALL_ENG_DEBUG(ENG_DEBUG, "inside ...");
3244
3245         if (TRUE == _vc_core_cm_get_call_object(&pcall_core->pcall_engine->call_manager, call_handle, &obj_info)) {
3246                 CALL_ENG_DEBUG(ENG_DEBUG, "Source telephone number - %s", obj_info.source_tel_number);
3247                 if (TRUE == _vc_core_util_extract_dtmf_number(obj_info.source_tel_number, dtmf_number, sizeof(dtmf_number))) {
3248                         CALL_ENG_DEBUG(ENG_DEBUG, "DTMF number - %s", dtmf_number);
3249                         if (VC_CALL_ORIG_TYPE_SAT == pcall_core->call_setup_info.call_type) {
3250                                 __voicecall_core_queue_dtmf_string(pcall_core, dtmf_number, TRUE);
3251                         } else {
3252                                 __voicecall_core_queue_dtmf_string(pcall_core, dtmf_number, FALSE);
3253                         }
3254                 }
3255         } else {
3256                 CALL_ENG_DEBUG(ENG_DEBUG, "Call Info not available for call handle: %d", call_handle);
3257         }
3258
3259         return FALSE;
3260 }
3261
3262 /**
3263  * This function cancels the dtmf queue
3264  *
3265  * @return              TRUE - sucess, FALSE otherwise
3266  * @param[in]           papp_document           Handle to Application Document
3267  */
3268 gboolean voicecall_core_cancel_dtmf_queue(call_vc_core_state_t *pcall_core)
3269 {
3270         voicecall_dtmf_info_t *pdtmf_info = (voicecall_dtmf_info_t *)&pcall_core->dtmf_info;
3271
3272         CALL_ENG_DEBUG(ENG_DEBUG, "Start:pcall_core(%p)", pcall_core);
3273
3274         if (FALSE == pdtmf_info->bdtmf_queue) {
3275                 return TRUE;
3276         }
3277
3278         /*Remove Pauser Timer */
3279         if (pdtmf_info->dtmf_pause_timer > 0) {
3280                 g_source_remove(pdtmf_info->dtmf_pause_timer);
3281                 pdtmf_info->dtmf_pause_timer = -1;
3282         }
3283
3284         /*Reset the Status Flags */
3285         pdtmf_info->bdtmf_queue = FALSE;
3286         pdtmf_info->dtmf_index = 0;
3287         pdtmf_info->bdtmf_wait = FALSE;
3288         memset(pdtmf_info->dtmf_number, 0, sizeof(pdtmf_info->dtmf_number));
3289         if (TRUE == pdtmf_info->bsat_dtmf) {
3290                 voicecall_core_send_sat_response(pcall_core->pcall_engine, SAT_RQST_SEND_DTMF, CALL_VC_ME_UNABLE_TO_PROCESS_COMMAND);
3291         }
3292         pdtmf_info->bsat_dtmf = FALSE;
3293         pdtmf_info->bsat_hidden = FALSE;
3294         CALL_ENG_DEBUG(ENG_DEBUG, "End");
3295         return TRUE;
3296 }
3297
3298 static gboolean __voicecall_core_dtmf_pause_timer_cb(gpointer puser_data)
3299 {
3300         call_vc_core_state_t *pcall_core = (call_vc_core_state_t *)puser_data;
3301
3302         __voicecall_core_handle_dtmf_ack(pcall_core, TRUE);
3303
3304         /*Always return FALSE, so that it won't be called again */
3305         return FALSE;
3306 }
3307
3308 gboolean __voicecall_core_send_dtmf_idle_cb(gpointer pdata)
3309 {
3310         call_vc_core_state_t *pcall_core = (call_vc_core_state_t *)pdata;
3311         voicecall_dtmf_info_t *pdtmf_info = (voicecall_dtmf_info_t *)&pcall_core->dtmf_info;
3312         voicecall_error_t vc_error;
3313         vc_engine_dtmf_ack_type event_data;
3314         char dtmf_string[2];
3315
3316         dtmf_string[0] = pdtmf_info->dtmf_number[pdtmf_info->dtmf_index];
3317         dtmf_string[1] = '\0';
3318
3319         CALL_ENG_DEBUG(ENG_DEBUG, "inside ...");
3320
3321         vc_error = _vc_core_engine_send_dtmf(pcall_core->pcall_engine, dtmf_string);
3322
3323         if (vc_error == ERROR_VOICECALL_INVALID_DTMF_CHAR) {
3324                 CALL_ENG_DEBUG(ENG_DEBUG, "ERROR_VOICECALL_INVALID_DTMF_CHAR");
3325         } else if (ERROR_VOICECALL_NONE != vc_error) {
3326                 voicecall_core_cancel_dtmf_queue(pcall_core);
3327                 memset(&event_data, 0, sizeof(event_data));
3328                 event_data.bstatus = FALSE;
3329                 event_data.string_id = IDS_CALL_POP_DTMFSENDING_FAIL;
3330                 vcall_engine_send_event_to_client(VC_ENGINE_MSG_DTMF_ACK_TO_UI, (void *)&event_data);
3331
3332                 if (TRUE == pdtmf_info->bsat_dtmf) {
3333                         voicecall_core_send_sat_response(pcall_core->pcall_engine, SAT_RQST_SEND_DTMF, CALL_VC_ME_UNABLE_TO_PROCESS_COMMAND);
3334                 }
3335
3336                 if (!((TRUE == pdtmf_info->bsat_dtmf) && (TRUE == pdtmf_info->bsat_hidden))) {
3337                         memset(&event_data, 0, sizeof(event_data));
3338                         event_data.bstatus = FALSE;
3339                         event_data.string_id = IDS_CALL_POP_DTMFSENDING_FAIL;
3340                         vcall_engine_send_event_to_client(VC_ENGINE_MSG_DTMF_ACK_TO_UI, (void *)&event_data);
3341                 }
3342         }
3343
3344         return FALSE;
3345 }
3346
3347 static gboolean __voicecall_core_handle_dtmf_ack(call_vc_core_state_t *pcall_core, gboolean success)
3348 {
3349         voicecall_dtmf_info_t *pdtmf_info = (voicecall_dtmf_info_t *)&pcall_core->dtmf_info;
3350         vc_engine_dtmf_ack_type event_data;
3351         CALL_ENG_DEBUG(ENG_DEBUG, "...");
3352
3353         if (FALSE == pdtmf_info->bdtmf_queue) {
3354                 CALL_ENG_DEBUG(ENG_DEBUG, "DTMF Queue Canceled, do nothing");
3355                 return TRUE;
3356         }
3357
3358         if (TRUE == success) {
3359                 char dtmf_string[2];
3360                 pdtmf_info->dtmf_index++;
3361
3362                 dtmf_string[0] = pdtmf_info->dtmf_number[pdtmf_info->dtmf_index];
3363                 dtmf_string[1] = '\0';
3364
3365                 CALL_ENG_DEBUG(ENG_DEBUG, "Current dtmf_index: %d,dtmf_max_length=%d", pdtmf_info->dtmf_index, pdtmf_info->dtmf_max_length);
3366                 CALL_ENG_DEBUG(ENG_DEBUG, "Current DTMF String: %s", &pdtmf_info->dtmf_number[pdtmf_info->dtmf_index]);
3367
3368                 /*Find the End of the queue */
3369                 if (pdtmf_info->dtmf_index >= pdtmf_info->dtmf_max_length) {
3370
3371                         CALL_ENG_DEBUG(ENG_DEBUG, "Updating DTMF Progress before destroying");
3372
3373                         if (!((TRUE == pdtmf_info->bsat_dtmf) && (TRUE == pdtmf_info->bsat_hidden))) {
3374                                 memset(&event_data, 0, sizeof(event_data));
3375                                 event_data.bstatus = FALSE;     /*check it*/
3376                                 event_data.string_id = IDS_CALL_POP_DTMF_SENT; /*check it*/
3377                                 vcall_engine_send_event_to_client(VC_ENGINE_MSG_DTMF_ACK_TO_UI, (void *)&event_data);
3378                         }
3379
3380                         if (TRUE == pdtmf_info->bsat_dtmf) {
3381                                 voicecall_core_send_sat_response(pcall_core->pcall_engine, SAT_RQST_SEND_DTMF, CALL_VC_ME_RET_SUCCESS);
3382                         }
3383                 } else {
3384                         if (0 == strcasecmp(dtmf_string, "p") || 0 == strcmp(dtmf_string, ",")) {
3385                                 CALL_ENG_DEBUG(ENG_DEBUG, "Pause on the dtmf string");
3386
3387                                 memset(&event_data, 0, sizeof(event_data));
3388                                 event_data.bstatus = TRUE;
3389                                 event_data.string_id = IDS_CALL_POP_SENDING;
3390                                 snprintf(event_data.display_string, sizeof(event_data.display_string), "%s", &pdtmf_info->dtmf_number[pdtmf_info->dtmf_index]);
3391                                 vcall_engine_send_event_to_client(VC_ENGINE_MSG_DTMF_ACK_TO_UI, (void *)&event_data);
3392
3393                                 int dtmf_interval = 0;
3394
3395                                 if (FALSE == _vc_core_util_check_gcf_status()) {
3396                                         dtmf_interval = (pdtmf_info->dtmf_index == 0) ? DTMF_PAUSE_TIMER_INTERVAL_FIRST : DTMF_PAUSE_TIMER_INTERVAL_REST;
3397                                 } else {
3398 #ifdef GCONF_GCF_SAT_TEST
3399                                         int start_interval = DTMF_PAUSE_TIMER_INTERVAL_GCF_FIRST;
3400                                         int rest_interval = DTMF_PAUSE_TIMER_INTERVAL_GCF_REST;
3401                                         {
3402                                                 GConfClient *client = NULL;
3403                                                 client = gconf_client_get_default();
3404                                                 if (NULL == client) {
3405                                                         CALL_ENG_DEBUG(ENG_DEBUG, "gconf_client_get_default failed..");
3406                                                 } else {
3407
3408                                                         start_interval = gconf_client_get_int(client, PATH_DTMF_INTERVAL_GCF_FIRST, NULL);
3409
3410                                                         rest_interval = gconf_client_get_int(client, PATH_DTMF_INTERVAL_GCF_REST, NULL);
3411                                                         g_object_unref(client);
3412                                                 }
3413
3414                                         }
3415                                         CALL_ENG_DEBUG(ENG_DEBUG, "start_interval:%d, rest_interval = %d", start_interval, rest_interval);
3416                                         dtmf_interval = (pdtmf_info->dtmf_index == 0) ? start_interval : rest_interval;
3417 #else
3418                                         dtmf_interval = (pdtmf_info->dtmf_index == 0) ? DTMF_PAUSE_TIMER_INTERVAL_GCF_FIRST : DTMF_PAUSE_TIMER_INTERVAL_GCF_REST;
3419 #endif
3420                                 }
3421                                 CALL_ENG_DEBUG(ENG_DEBUG, "dtmf_interval:%d", dtmf_interval);
3422                                 pdtmf_info->dtmf_pause_timer = g_timeout_add(dtmf_interval, __voicecall_core_dtmf_pause_timer_cb, pcall_core);
3423                         } else if (0 == strcasecmp(dtmf_string, "w") || 0 == strcmp(dtmf_string, ";")) {
3424                                 CALL_ENG_DEBUG(ENG_DEBUG, "Wait on the dtmf string");
3425                                 memset(&event_data, 0, sizeof(event_data));
3426                                 event_data.bstatus = TRUE;
3427                                 event_data.string_id = IDS_CALL_POP_UNAVAILABLE;        /*assign ID when string is added*/
3428                                 snprintf(event_data.display_string, sizeof(event_data.display_string), "%s", &pdtmf_info->dtmf_number[pdtmf_info->dtmf_index]);
3429                                 vcall_engine_send_event_to_client(VC_ENGINE_MSG_DTMF_ACK_TO_UI, (void *)&event_data);
3430                         } else {
3431                                 g_idle_add_full(G_PRIORITY_HIGH_IDLE + 25, __voicecall_core_send_dtmf_idle_cb, pcall_core, NULL);
3432                         }
3433                 }
3434         } else {
3435                 voicecall_core_cancel_dtmf_queue(pcall_core);
3436
3437                 memset(&event_data, 0, sizeof(event_data));
3438                 event_data.bstatus = FALSE;
3439                 event_data.string_id = IDS_CALL_POP_DTMFSENDING_FAIL;
3440                 vcall_engine_send_event_to_client(VC_ENGINE_MSG_DTMF_ACK_TO_UI, (void *)&event_data);
3441         }
3442
3443         return TRUE;
3444 }
3445
3446 /**
3447  * This function queues the dtmf digits one by one from the given dtmf string
3448  *
3449  * @return              TRUE - sucess, FALSE otherwise
3450  * @param[in]           papp_document           Handle to Application Document
3451  * @param[in]           dtmf_string                     dtmf string to be queued
3452  */
3453 static gboolean __voicecall_core_queue_dtmf_string(call_vc_core_state_t *pcall_core, char *dtmf_string, gboolean bsat_dtmf)
3454 {
3455         voicecall_dtmf_info_t *pdtmf_info = (voicecall_dtmf_info_t *)&pcall_core->dtmf_info;
3456         gboolean bhidden_mode = FALSE;
3457         char dtmf_digit[2];
3458         vc_engine_dtmf_ack_type event_data;
3459
3460         CALL_ENG_DEBUG(ENG_DEBUG, "bsat_dtmf = %d", bsat_dtmf);
3461
3462         if (TRUE == bsat_dtmf) {
3463                 /*Always get the status from the engine */
3464                 _vc_core_engine_get_sat_dtmf_hidden_mode(pcall_core->pcall_engine, &bhidden_mode);
3465                 CALL_ENG_DEBUG(ENG_DEBUG, "SAT Hidden Mode : %d", bhidden_mode);
3466         }
3467
3468         /*Check for the validity of the DTMF String */
3469         if (FALSE == _vc_core_util_isvalid_full_dtmf_number(dtmf_string)) {
3470                 if (TRUE == bsat_dtmf) {
3471                         voicecall_core_send_sat_response(pcall_core->pcall_engine, SAT_RQST_SEND_DTMF, CALL_VC_ME_UNABLE_TO_PROCESS_COMMAND);
3472                 }
3473
3474                 if (!((TRUE == bsat_dtmf) && (TRUE == bhidden_mode))) {
3475                         memset(&event_data, 0, sizeof(event_data));
3476                         event_data.bstatus = FALSE;
3477                         event_data.string_id = IDS_CALL_POP_INVALID_DTMF;
3478                         vcall_engine_send_event_to_client(VC_ENGINE_MSG_DTMF_ACK_TO_UI, (void *)&event_data);
3479                 }
3480                 return FALSE;
3481         }
3482
3483         /*Reset DTMF Values */
3484         pdtmf_info->bdtmf_queue = FALSE;
3485         pdtmf_info->dtmf_index = 0;
3486         pdtmf_info->bsat_dtmf = bsat_dtmf;
3487
3488         if (TRUE == bsat_dtmf) {
3489                 /*Initialize */
3490                 pdtmf_info->bsat_hidden = bhidden_mode;
3491         }
3492
3493         /*It takes only 40 characters from the source, rest of the characters are ignored*/
3494         memset(pdtmf_info->dtmf_number, 0, sizeof(pdtmf_info->dtmf_number));
3495         strncpy(pdtmf_info->dtmf_number, dtmf_string, min((sizeof(pdtmf_info->dtmf_number) - 1), strlen(dtmf_string)));
3496         pdtmf_info->dtmf_max_length = strlen(pdtmf_info->dtmf_number);
3497         CALL_ENG_DEBUG(ENG_DEBUG, "Dtmf Number:%s ,dtmf_max_length:%d", pdtmf_info->dtmf_number, pdtmf_info->dtmf_max_length);
3498
3499         dtmf_digit[0] = pdtmf_info->dtmf_number[pdtmf_info->dtmf_index];
3500         dtmf_digit[1] = '\0';
3501
3502         /*Send DTMF */
3503         if (0 == strcasecmp(dtmf_digit, "p") || 0 == strcmp(dtmf_digit, ",")) {
3504                 int dtmf_interval = 0;
3505
3506                 if (FALSE == _vc_core_util_check_gcf_status()) {
3507                         dtmf_interval = (pdtmf_info->dtmf_index == 0) ? DTMF_PAUSE_TIMER_INTERVAL_FIRST : DTMF_PAUSE_TIMER_INTERVAL_REST;
3508                 } else {
3509 #ifdef GCONF_GCF_SAT_TEST
3510                         int start_interval = DTMF_PAUSE_TIMER_INTERVAL_GCF_FIRST;
3511                         int rest_interval = DTMF_PAUSE_TIMER_INTERVAL_GCF_REST;
3512                         {
3513
3514                                 GConfClient *client = NULL;
3515                                 client = gconf_client_get_default();
3516                                 if (NULL == client) {
3517                                         CALL_ENG_DEBUG(ENG_DEBUG, "gconf_client_get_default failed..");
3518                                 } else {
3519
3520                                         start_interval = gconf_client_get_int(client, PATH_DTMF_INTERVAL_GCF_FIRST, NULL);
3521
3522                                         rest_interval = gconf_client_get_int(client, PATH_DTMF_INTERVAL_GCF_REST, NULL);
3523                                         g_object_unref(client);
3524                                 }
3525
3526                         }
3527                         CALL_ENG_DEBUG(ENG_DEBUG, "start_interval:%d, rest_interval = %d", start_interval, rest_interval);
3528                         dtmf_interval = (pdtmf_info->dtmf_index == 0) ? start_interval : rest_interval;
3529 #else
3530                         dtmf_interval = (pdtmf_info->dtmf_index == 0) ? DTMF_PAUSE_TIMER_INTERVAL_GCF_FIRST : DTMF_PAUSE_TIMER_INTERVAL_GCF_REST;
3531 #endif
3532                         CALL_ENG_DEBUG(ENG_DEBUG, "updated dtmf_interval:%d", dtmf_interval);
3533                 }
3534                 pdtmf_info->dtmf_pause_timer = g_timeout_add(dtmf_interval, __voicecall_core_dtmf_pause_timer_cb, pcall_core);
3535         } else if (0 == strcasecmp(dtmf_digit, "w") || 0 == strcmp(dtmf_digit, ";")) {
3536                 /* enable wait flag for dtmf sending */
3537                 pdtmf_info->bdtmf_wait = TRUE;
3538         } else if ((ERROR_VOICECALL_NONE != _vc_core_engine_send_dtmf(pcall_core->pcall_engine, dtmf_digit))) {
3539                 if (!((TRUE == pdtmf_info->bsat_dtmf) && (TRUE == pdtmf_info->bsat_hidden))) {
3540                         memset(&event_data, 0, sizeof(event_data));
3541                         event_data.bstatus = FALSE;
3542                         event_data.string_id = IDS_CALL_POP_DTMFSENDING_FAIL;
3543                         vcall_engine_send_event_to_client(VC_ENGINE_MSG_DTMF_ACK_TO_UI, (void *)&event_data);
3544                 }
3545                 if (TRUE == pdtmf_info->bsat_dtmf) {
3546                         voicecall_core_send_sat_response(pcall_core->pcall_engine, SAT_RQST_SEND_DTMF, CALL_VC_ME_UNABLE_TO_PROCESS_COMMAND);
3547                 }
3548                 return FALSE;
3549         }
3550         pdtmf_info->bdtmf_queue = TRUE;
3551
3552         /*Create Progressbar popup */
3553         if (!((TRUE == pdtmf_info->bsat_dtmf) && (TRUE == pdtmf_info->bsat_hidden))) {
3554                 memset(&event_data, 0, sizeof(event_data));
3555                 event_data.bstatus = TRUE;
3556                 CALL_ENG_DEBUG(ENG_DEBUG, "pdtmf_info->bdtmf_wait [%d]", pdtmf_info->bdtmf_wait);
3557                 if (pdtmf_info->bdtmf_wait) {
3558                         event_data.string_id = IDS_CALL_POP_UNAVAILABLE;
3559                 } else {
3560                         event_data.string_id = IDS_CALL_POP_SENDING;
3561                 }
3562                 _vc_core_util_strcpy(event_data.display_string, VC_PHONE_NUMBER_LENGTH_MAX, pdtmf_info->dtmf_number);
3563                 vcall_engine_send_event_to_client(VC_ENGINE_MSG_DTMF_ACK_TO_UI, (void *)&event_data);
3564         } else {
3565                 CALL_ENG_DEBUG(ENG_DEBUG, "SAT DTMF Hidden Mode, not showing UI");
3566         }
3567         return TRUE;
3568 }
3569 #endif
3570
3571 gboolean voicecall_core_change_sound_path(call_vc_core_state_t *pcall_core, voicecall_snd_audio_type_t sound_path)
3572 {
3573         voicecall_snd_mgr_t *papp_snd = pcall_core->papp_snd;
3574         int ret = FALSE;
3575         int total_call_member = -1;
3576
3577         CALL_ENG_DEBUG(ENG_DEBUG, "sound_path:[%d]", sound_path);
3578
3579         voicecall_core_get_total_call_member(pcall_core->pcall_engine, &total_call_member);
3580         if (total_call_member == 0) {
3581                 CALL_ENG_DEBUG(ENG_DEBUG, "There are not active calls hence it should not work");
3582                 return FALSE;
3583         }
3584
3585         switch (sound_path) {
3586         case VOICE_CALL_AUDIO_SPEAKER:
3587                 {
3588                         if (voicecall_snd_get_path_status(pcall_core->papp_snd) == VOICE_CALL_SND_PATH_BT) {
3589                                 /*_vc_bt_send_response_to_bt(pcall_core, BT_AG_RES_SWITCH_TO_PHONE, -1, NULL);*/
3590                                 _vc_bt_request_switch_headset_path(pcall_core, FALSE);
3591                         }
3592                         voicecall_snd_set_path_status(pcall_core->papp_snd, VOICE_CALL_SND_PATH_SPEAKER);
3593                         ret = TRUE;
3594                 }
3595                 break;
3596
3597         case VOICE_CALL_AUDIO_HEADSET:
3598                 {
3599                         voicecall_snd_set_path_status(pcall_core->papp_snd, VOICE_CALL_SND_PATH_BT);
3600 /*                      _vc_bt_send_response_to_bt(pcall_core, BT_AG_RES_SWITCH_TO_HEADSET, -1, NULL);*/
3601                         _vc_bt_request_switch_headset_path(pcall_core, TRUE);
3602
3603                         ret = TRUE;
3604                 }
3605                 break;
3606
3607         case VOICE_CALL_AUDIO_RECEIVER_EARJACK:
3608                 {
3609                         if (voicecall_snd_get_path_status(pcall_core->papp_snd) == VOICE_CALL_SND_PATH_BT) {
3610                                 /*_vc_bt_send_response_to_bt(pcall_core, BT_AG_RES_SWITCH_TO_PHONE, -1, NULL);*/
3611                                 _vc_bt_request_switch_headset_path(pcall_core, FALSE);
3612                         }
3613                         voicecall_snd_set_path_status(pcall_core->papp_snd, VOICE_CALL_SND_PATH_RECEIVER_EARJACK);
3614                         ret = TRUE;
3615                 }
3616                 break;
3617
3618         default:
3619                 {
3620                         CALL_ENG_DEBUG(ENG_DEBUG, "Unknown type!!");
3621                         ret = FALSE;
3622                 }
3623                 break;
3624         }
3625
3626         /* Change Audio Path according to the current status */
3627         voicecall_snd_change_path(papp_snd);
3628
3629         return ret;
3630 }
3631
3632 gboolean voicecall_core_get_sound_path(call_vc_core_state_t *pcall_core, int *sound_path)
3633 {
3634         voicecall_snd_mgr_t *papp_snd = pcall_core->papp_snd;
3635
3636         CALL_ENG_DEBUG(ENG_DEBUG, "..");
3637
3638         switch (voicecall_snd_get_path_status(papp_snd)) {
3639         case VOICE_CALL_SND_PATH_SPEAKER:
3640                 {
3641                         *sound_path = VOICE_CALL_AUDIO_SPEAKER;
3642                 }
3643                 break;
3644
3645         case VOICE_CALL_SND_PATH_BT:
3646                 {
3647                         *sound_path = VOICE_CALL_AUDIO_HEADSET;
3648                 }
3649                 break;
3650
3651         case VOICE_CALL_SND_PATH_RECEIVER_EARJACK:
3652         default:
3653                 {
3654                         *sound_path = VOICE_CALL_AUDIO_RECEIVER_EARJACK;
3655                 }
3656                 break;
3657         }
3658
3659         return TRUE;
3660 }
3661
3662 static gboolean __voicecall_core_is_redial_cuase(int end_cause)
3663 {
3664         CALL_ENG_DEBUG(ENG_DEBUG, "end_cause(%d)", end_cause);
3665
3666         switch (end_cause) {
3667         case VC_ENDCAUSE_CALL_BARRED:
3668         case VC_ENDCAUSE_NO_SERVICE:
3669         case VC_ENDCAUSE_USER_UNAVAILABLE:
3670         case VC_ENDCAUSE_INVALID_NUMBER_FORMAT:
3671         case VC_ENDCAUSE_NUMBER_CHANGED:
3672         case VC_ENDCAUSE_NO_CREDIT:
3673         case VC_ENDCAUSE_UNASSIGNED_NUMBER:
3674                 return FALSE;
3675
3676         case VC_ENDCAUSE_CALL_ENDED:
3677         case VC_ENDCAUSE_CALL_DISCONNECTED:
3678         case VC_ENDCAUSE_NO_ANSWER:
3679         case VC_ENDCAUSE_NW_BUSY:
3680         case VC_ENDCAUSE_CALL_SERVICE_NOT_ALLOWED:
3681         case VC_ENDCAUSE_NW_FAILED:
3682         case VC_ENDCAUSE_REJECTED:
3683         case VC_ENDCAUSE_USER_BUSY:
3684         case VC_ENDCAUSE_WRONG_GROUP:
3685         case VC_ENDCAUSE_CALL_NOT_ALLOWED:
3686         case VC_ENDCAUSE_CALL_FAILED:
3687         case VC_ENDCAUSE_NO_USER_RESPONDING:
3688         case VC_ENDCAUSE_USER_ALERTING_NO_ANSWER:
3689         case VC_ENDCAUSE_SERVICE_TEMP_UNAVAILABLE:
3690         case VC_ENDCAUSE_USER_DOESNOT_RESPOND:
3691         case VC_ENDCAUSE_IMEI_REJECTED:
3692         case VC_ENDCAUSE_TAPI_ERROR:
3693         default:
3694                 return TRUE;
3695         }
3696 }
3697
3698 /**
3699  * This function processed the supplementary services while on call
3700  *
3701  * @return              Returns TRUE If transfer call can be made or FALSE if not
3702  * @param[in]           pcall_core              Handle to voicecall core
3703  */
3704 void voicecall_core_process_dtmf_send_status(call_vc_core_state_t *pcall_core, gboolean bsuccess)
3705 {
3706         CALL_ENG_DEBUG(ENG_DEBUG, " ..");
3707         VOICECALL_RETURN_IF_FAIL(pcall_core);
3708         __voicecall_core_handle_dtmf_ack(pcall_core, bsuccess);
3709 }
3710
3711 /**
3712  * This function checks validation of incoming handle
3713  *
3714  * @return              gboolean
3715  * @param[in]           puser_data              Handle to voicecall core
3716  */
3717 static gboolean __voicecall_core_check_incoming_handle(gpointer puser_data)
3718 {
3719         call_vc_core_state_t *pcall_core = (call_vc_core_state_t *)puser_data;
3720         VOICECALL_RETURN_FALSE_IF_FAIL(pcall_core);
3721
3722         _vc_core_engine_check_incoming_handle(pcall_core->pcall_engine, pcall_core->mtcall_handle);
3723
3724         return FALSE;
3725 }
3726
3727
3728