Make TIZEN 2.0
[apps/home/call.git] / call-engine / core / vc-core-svcall.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 #ifdef _CPHS_DEFINED_
18
19 #include <stdbool.h>
20 #include <assert.h>
21 #include "vc-core-engine.h"
22 #include "vc-core-svcall.h"
23 #include "vc-core-util.h"
24 #include "tapi-inc.h"
25 #include "status-interface.h"
26
27 /*Local Function Decleration*/
28 /**
29 * This function checks whether csp is enabled in the cphs group
30 *
31 * @internal
32 * @return               TRUE if customer service profile is enabled -FALSE otherwise
33 * @param[in]            pcall_agent     Handle to Voicecall Call Agent
34 */
35 static gboolean __call_vcsv_cphs_is_csp_enabled(call_vc_callagent_state_t *pcall_agent);
36
37 /**
38 * This function returns the csp index of the given csp service from the cphs cspprofile
39 *
40 * @internal
41 * @return               index to the specified csp service
42 * @param[in]            pcphs_csp_profile       Handle to csp profile entry table
43 * @param[in]            csp_group_max_count     maximumm service entry
44 * @param[in]            csp_service     csp service to be found
45 */
46 static int __call_vcsv_cphs_find_csp_index(TelSimCphsCustomerServiceProfileEntry_t *pcphs_csp_profile, int csp_group_max_count, TelSimCphsCustomerServiceGroup_t csp_service);
47
48 /**
49  * This function retrieves cphs information from the Telephony and stores with the engine
50  *
51  * @return              Returns TRUE on success and FALSE on failure
52  * @param[in]           pcall_agent     Handle to Voicecall Call Agent
53  */
54 gboolean _vc_core_svcall_init_cphs_info(call_vc_callagent_state_t *pcall_agent)
55 {
56         gboolean ret_val = FALSE;
57
58         CALL_ENG_DEBUG(ENG_DEBUG, "");
59
60         memset(&pcall_agent->cphs_status, 0, sizeof(status_class_cphs_type));
61
62         /*Read CPHS Info */
63 #ifdef _CPHS_DEFINED_
64         ret_val = nps_get_cphs_status(&pcall_agent->cphs_status);
65 #endif
66
67         if (FALSE == ret_val) {
68                 CALL_ENG_DEBUG(ENG_DEBUG, "nps_get_cphs_status failed or CPHS feature not enabled");
69                 pcall_agent->bcphs_read_success = FALSE;
70                 return FALSE;
71         }
72
73         pcall_agent->bcphs_read_success = TRUE;
74
75         return TRUE;
76 }
77
78 /**
79  * This function retrieves status of the given csp service type
80  *
81  * @return              Returns TRUE on success and FALSE on failure
82  * @param[in]           csp_service     csp service whose status to be retreived
83  */
84 gboolean _vc_core_svcall_cphs_csp_get_status(call_vc_callagent_state_t *pcall_agent, voicecall_cphs_csp_service csp_service)
85 {
86         status_class_cphs_type *pcphs_status_info = (status_class_cphs_type *) &pcall_agent->cphs_status;
87         int csp_index = -1;
88
89         if (FALSE == __call_vcsv_cphs_is_csp_enabled(pcall_agent)) {
90                 CALL_ENG_DEBUG(ENG_DEBUG, "CPHS CSP Not enabled");
91
92                 if (VC_CPHS_CSP_ALS == csp_service) {
93                         return FALSE;
94                 } else {
95                         /*If CPHS is not supported, then by default return TRUE for the client to have default action */
96                         return TRUE;
97                 }
98         }
99
100         switch (csp_service) {
101         case VC_CPHS_CSP_ALS:   /*CPHS Teleservices */
102                 {
103                         csp_index = __call_vcsv_cphs_find_csp_index(pcphs_status_info->csp.serviceProfileEntry, TAPI_SIM_CPHS_CUSTOMER_SERVICE_PROFILE_ENTRY_COUNT_MAX, TAPI_SIM_CPHS_CSP_SERVICE_GROUP_CPHS_TELESERVICES);
104                 }
105                 break;
106         case VC_CPHS_CSP_HOLD:  /*Call Completion Services */
107         case VC_CPHS_CSP_CW:
108         case VC_CPHS_CSP_CBS:
109         case VC_CPHS_CSP_UUS:
110                 {
111                         csp_index = __call_vcsv_cphs_find_csp_index(pcphs_status_info->csp.serviceProfileEntry, TAPI_SIM_CPHS_CUSTOMER_SERVICE_PROFILE_ENTRY_COUNT_MAX, TAPI_SIM_CPHS_CSP_SERVICE_GROUP_CALL_COMPLETION);
112                 }
113                 break;
114         case VC_CPHS_CSP_CT:    /*Call Offering Services */
115         case VC_CPHS_CSP_CFU:
116         case VC_CPHS_CSP_CFB:
117         case VC_CPHS_CSP_CFNRY:
118         case VC_CPHS_CSP_CFNRC:
119                 {
120                         csp_index = __call_vcsv_cphs_find_csp_index(pcphs_status_info->csp.serviceProfileEntry, TAPI_SIM_CPHS_CUSTOMER_SERVICE_PROFILE_ENTRY_COUNT_MAX, TAPI_SIM_CPHS_CSP_SERVICE_GROUP_CALL_OFFERING);
121                 }
122                 break;
123         case VC_CPHS_CSP_MPTY:  /*Other Supplementary Services */
124         case VC_CPHS_CSP_CUG:
125         case VC_CPHS_CSP_AOC:
126         case VC_CPHS_CSP_PREFCUG:
127         case VC_CPHS_CSP_CUGOA:
128                 {
129                         csp_index = __call_vcsv_cphs_find_csp_index(pcphs_status_info->csp.serviceProfileEntry, TAPI_SIM_CPHS_CUSTOMER_SERVICE_PROFILE_ENTRY_COUNT_MAX, TAPI_SIM_CPHS_CSP_SERVICE_GROUP_OTHER_SUPP_SERVICES);
130                 }
131                 break;
132         default:
133                 CALL_ENG_DEBUG(ENG_DEBUG, "No Actions defined for service type: %d", csp_service);
134                 break;
135         }
136
137         if (-1 == csp_index) {
138                 CALL_ENG_DEBUG(ENG_DEBUG, "csp_index failed for csp service: %d", csp_service);
139                 return FALSE;
140         }
141
142         switch (csp_service) {
143         case VC_CPHS_CSP_ALS:
144                 {
145                         return pcphs_status_info->csp.serviceProfileEntry[csp_index].u.cphsTeleservices.bAlternativeLineService;
146                 }
147                 break;
148         case VC_CPHS_CSP_HOLD:
149                 {
150                         return pcphs_status_info->csp.serviceProfileEntry[csp_index].u.callComplete.bCallHold;
151                 }
152                 break;
153         case VC_CPHS_CSP_CW:
154                 {
155                         return pcphs_status_info->csp.serviceProfileEntry[csp_index].u.callComplete.bCallWaiting;
156                 }
157                 break;
158         case VC_CPHS_CSP_CBS:
159                 {
160                         return pcphs_status_info->csp.serviceProfileEntry[csp_index].u.callComplete.bCompletionOfCallToBusySubscriber;
161                 }
162                 break;
163         case VC_CPHS_CSP_UUS:
164                 {
165                         return pcphs_status_info->csp.serviceProfileEntry[csp_index].u.callComplete.bUserUserSignalling;
166                 }
167                 break;
168         case VC_CPHS_CSP_CFU:
169                 {
170                         return pcphs_status_info->csp.serviceProfileEntry[csp_index].u.callOffering.bCallForwardingUnconditional;
171                 }
172                 break;
173         case VC_CPHS_CSP_CFB:
174                 {
175                         return pcphs_status_info->csp.serviceProfileEntry[csp_index].u.callOffering.bCallForwardingOnUserBusy;
176                 }
177                 break;
178         case VC_CPHS_CSP_CFNRY:
179                 {
180                         return pcphs_status_info->csp.serviceProfileEntry[csp_index].u.callOffering.bCallForwardingOnNoReply;
181                 }
182                 break;
183         case VC_CPHS_CSP_CFNRC:
184                 {
185                         return pcphs_status_info->csp.serviceProfileEntry[csp_index].u.callOffering.bCallForwardingOnUserNotReachable;
186                 }
187                 break;
188         case VC_CPHS_CSP_CT:
189                 {
190                         return pcphs_status_info->csp.serviceProfileEntry[csp_index].u.callOffering.bCallTransfer;
191                 }
192                 break;
193         case VC_CPHS_CSP_MPTY:
194                 {
195                         return pcphs_status_info->csp.serviceProfileEntry[csp_index].u.otherSuppServices.bMultiPartyService;
196                 }
197                 break;
198         case VC_CPHS_CSP_CUG:
199                 {
200                         return pcphs_status_info->csp.serviceProfileEntry[csp_index].u.otherSuppServices.bClosedUserGroup;
201                 }
202                 break;
203         case VC_CPHS_CSP_AOC:
204                 {
205                         return pcphs_status_info->csp.serviceProfileEntry[csp_index].u.otherSuppServices.bAdviceOfCharge;
206                 }
207                 break;
208         case VC_CPHS_CSP_PREFCUG:
209                 {
210                         return pcphs_status_info->csp.serviceProfileEntry[csp_index].u.otherSuppServices.bPreferentialClosedUserGroup;
211                 }
212                 break;
213         case VC_CPHS_CSP_CUGOA:
214                 {
215                         return pcphs_status_info->csp.serviceProfileEntry[csp_index].u.otherSuppServices.bPreferentialClosedUserGroup;
216                 }
217                 break;
218         default:
219                 CALL_ENG_DEBUG(ENG_DEBUG, "Action not defined for csp service: %d", csp_service);
220                 return FALSE;
221         }
222
223         return FALSE;
224 }
225
226 voice_call_cphs_alsline_t _vc_core_svcall_get_cphs_als_active_line(call_vc_callagent_state_t *pcall_agent)
227 {
228         status_class_cphs_type *pcphs_status_info = (status_class_cphs_type *) &pcall_agent->cphs_status;
229
230         if (FALSE == __call_vcsv_cphs_is_csp_enabled(pcall_agent)) {
231                 CALL_ENG_DEBUG(ENG_DEBUG, "CPHS CSP Not enabled");
232                 return VC_CALL_CPHS_ALS_LINE1;
233         }
234
235         if (TAPI_SIM_DYNAMIC_FLAGS_LINE1 == pcphs_status_info->dflagsinfo.dynamicFlags) {
236                 return VC_CALL_CPHS_ALS_LINE1;
237         } else if (TAPI_SIM_DYNAMIC_FLAGS_LINE2 == pcphs_status_info->dflagsinfo.dynamicFlags) {
238                 return VC_CALL_CPHS_ALS_LINE2;
239         }
240
241         return VC_CALL_CPHS_ALS_LINE1;
242
243 }
244
245 /*Local Function Decleration*/
246 static gboolean __call_vcsv_cphs_is_csp_enabled(call_vc_callagent_state_t *pcall_agent)
247 {
248         status_class_cphs_type *pnps_cphs_status = NULL;
249
250         CALL_ENG_DEBUG(ENG_DEBUG, "");
251
252         if (pcall_agent->bcphs_read_success == FALSE) {
253                 CALL_ENG_DEBUG(ENG_DEBUG, "CSP Status not read");
254                 return FALSE;
255         }
256
257         pnps_cphs_status = &pcall_agent->cphs_status;
258
259         if (FALSE == pnps_cphs_status->cphsinfo.CphsServiceTable.bCustomerServiceProfile) {
260                 return TRUE;
261         }
262
263         return FALSE;
264 }
265
266 static int __call_vcsv_cphs_find_csp_index(TelSimCphsCustomerServiceProfileEntry_t *pcphs_csp_profile, int csp_group_max_count, TelSimCphsCustomerServiceGroup_t csp_service)
267 {
268         int index = 0;
269         CALL_ENG_DEBUG(ENG_DEBUG, "");
270
271         for (index = 0; index < csp_group_max_count; index++) {
272                 if (pcphs_csp_profile[index].customerServiceGroup == csp_service) {
273                         return index;
274                 }
275         }
276
277         return VC_ERROR;
278 }
279 #endif                          /*_CPHS_DEFINED_*/