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