RSA sync with private
[platform/core/messaging/msg-service.git] / plugin / sms_plugin / SmsPluginSetting.cpp
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 #include <errno.h>
18
19 #include "MsgDebug.h"
20 #include "MsgException.h"
21 #include "MsgGconfWrapper.h"
22 #include "MsgNotificationWrapper.h"
23 #include "MsgSoundPlayer.h"
24
25 #include "SmsPluginParamCodec.h"
26 #include "SmsPluginCallback.h"
27 #include "SmsPluginSetting.h"
28
29
30 extern "C"
31 {
32         #include <tapi_common.h>
33         #include <TelSms.h>
34         #include <TapiUtility.h>
35         #include <ITapiNetText.h>
36         #include <ITapiSim.h>
37 }
38
39 extern struct tapi_handle *pTapiHandle;
40
41 /*==================================================================================================
42                                      IMPLEMENTATION OF SmsPluginSetting - Member Functions
43 ==================================================================================================*/
44 SmsPluginSetting* SmsPluginSetting::pInstance = NULL;
45
46
47 SmsPluginSetting::SmsPluginSetting()
48 {
49         // Initialize member variables
50         memset(&smscData, 0x00, sizeof(MSG_SMSC_DATA_S));
51         memset(&cbOpt, 0x00, sizeof(MSG_CBMSG_OPT_S));
52         memset(&simMailboxList, 0x00, sizeof(SMS_SIM_MAILBOX_LIST_S));
53
54         bTapiResult = false;
55         paramCnt = 0;
56         selectedParam = 0;
57 }
58
59
60 SmsPluginSetting::~SmsPluginSetting()
61 {
62
63
64 }
65
66
67 SmsPluginSetting* SmsPluginSetting::instance()
68 {
69         if (!pInstance)
70                 pInstance = new SmsPluginSetting();
71
72         return pInstance;
73 }
74
75
76 void SmsPluginSetting::initConfigData(MSG_SIM_STATUS_T SimStatus)
77 {
78         MSG_BEGIN();
79
80         msg_error_t     err = MSG_SUCCESS;
81
82         // Init SMS Parameter
83         int paramCnt = 0;
84         int failCnt = 0;
85
86         paramCnt = getParamCount();
87
88         MSG_DEBUG("Parameter Count [%d]", paramCnt);
89
90         MSG_SMSC_DATA_S tmpSmscData = {};
91         MSG_SMSC_LIST_S tmpSmscList = {};
92
93         for (int index = 0; index < paramCnt; index++)
94         {
95                 if (getParam(index, &tmpSmscData) == false) {
96                         failCnt++;
97                         continue;
98                 }
99
100                 memcpy(&(tmpSmscList.smscData[index]), &tmpSmscData, sizeof(MSG_SMSC_DATA_S));
101
102                 MSG_DEBUG("pid[%d]", tmpSmscList.smscData[index].pid);
103                 MSG_DEBUG("val_period[%d]", tmpSmscList.smscData[index].valPeriod);
104                 MSG_DEBUG("name[%s]", tmpSmscList.smscData[index].name);
105
106                 MSG_DEBUG("ton[%d]", tmpSmscList.smscData[index].smscAddr.ton);
107                 MSG_DEBUG("npi[%d]", tmpSmscList.smscData[index].smscAddr.npi);
108                 MSG_DEBUG("address[%s]", tmpSmscList.smscData[index].smscAddr.address);
109         }
110
111         tmpSmscList.totalCnt = (paramCnt - failCnt);
112 //      below is commented to be the first smsc is selected.
113 //      tmpSmscList.selected = selectedParam;
114
115         if (paramCnt > 0) {
116                 err = addSMSCList(&tmpSmscList);
117
118                 if (err == MSG_SUCCESS) {
119                         MSG_DEBUG("########  Add SMSC List Success !!! #######");
120                 } else {
121                         MSG_DEBUG("########  Add SMSC List Fail !!! return : %d #######", err);
122                 }
123         }
124
125         // Init CB Config
126         if (SimStatus == MSG_SIM_STATUS_CHANGED) {
127                 MSG_DEBUG("simStatus == MSG_SIM_STATUS_CHANGED");
128
129                 MSG_CBMSG_OPT_S cbMsgOpt = {};
130
131                 if (getCbConfig(&cbMsgOpt) == true) {
132                         err = addCbOpt(&cbMsgOpt);
133
134                         if (err == MSG_SUCCESS) {
135                                 MSG_DEBUG("########  Add CB Option Success !!! #######");
136                         } else {
137                                 MSG_DEBUG("########  Add CB Option Fail !!! return : %d #######", err);
138                         }
139                 }
140         } else if (SimStatus == MSG_SIM_STATUS_NORMAL) {
141                 MSG_DEBUG("simStatus == MSG_SIM_STATUS_NORMAL");
142
143                 // Set CB Data into SIM in case of same SIM
144                 MSG_SETTING_S cbSetting;
145                 cbSetting.type = MSG_CBMSG_OPT;
146
147                 getCbOpt(&cbSetting);
148
149                 setCbConfig(&(cbSetting.option.cbMsgOpt));
150         }
151
152         if (SimStatus != MSG_SIM_STATUS_NOT_FOUND)
153         {
154                 MSG_VOICEMAIL_OPT_S tmpVoiceMail;
155                 memset(&tmpVoiceMail, 0x00, sizeof(MSG_VOICEMAIL_OPT_S));
156
157                 if (getVoiceMailInfo(&tmpVoiceMail) == true) {
158                         MSG_DEBUG("########  getVoiceMailInfo Success !!! #######");
159                 } else {
160                         MSG_DEBUG("########  getVoiceMailInfo Fail !!! #######");
161                 }
162
163                 if (getMwiInfo() == true) {
164                         MSG_DEBUG("########  getMwiInfo Success !!! #######");
165                 } else {
166                         MSG_DEBUG("########  getMwiInfo Fail !!! #######");
167                 }
168
169                 if (getMsisdnInfo() == true) {
170                         MSG_DEBUG("########  getMsisdnInfo Success !!! #######");
171                 } else {
172                         MSG_DEBUG("########  getMsisdnInfo Fail !!! #######");
173                 }
174         }
175
176         MSG_END();
177 }
178
179
180 void SmsPluginSetting::setConfigData(const MSG_SETTING_S *pSetting)
181 {
182         MSG_DEBUG("Setting Type : [%d]", pSetting->type);
183
184         switch (pSetting->type)
185         {
186 #if 0
187                 case MSG_SMS_SENDOPT :
188                         setNetworkMode(&pSetting->option.smsSendOpt);
189                         break;
190 #endif
191                 case MSG_SMSC_LIST :
192                         setParamList(&pSetting->option.smscList);
193                         break;
194                 case MSG_CBMSG_OPT :
195                         setCbConfig(&pSetting->option.cbMsgOpt);
196                         break;
197                 case MSG_VOICEMAIL_OPT:
198                         setVoiceMailInfo(&pSetting->option.voiceMailOpt);
199                         break;
200                 default :
201                         THROW(MsgException::SMS_PLG_ERROR, "The Setting type is not supported. [%d]", pSetting->type);
202                         break;
203         }
204 }
205
206
207 void SmsPluginSetting::getConfigData(MSG_SETTING_S *pSetting)
208 {
209         MSG_DEBUG("Setting Type : [%d]", pSetting->type);
210
211         switch (pSetting->type)
212         {
213                 case MSG_SMSC_LIST :
214                         getParamList(&pSetting->option.smscList);
215                 break;
216
217                 case MSG_CBMSG_OPT :
218                         getCbConfig(&pSetting->option.cbMsgOpt);
219                 break;
220
221                 default :
222                         THROW(MsgException::SMS_PLG_ERROR, "The Setting type is not supported. [%d]", pSetting->type);
223                 break;
224         }
225 }
226
227
228 msg_error_t SmsPluginSetting::addSMSCList(MSG_SMSC_LIST_S *pSmscList)
229 {
230         msg_error_t err = MSG_SUCCESS;
231
232         MSG_DEBUG("total_count[%d]", pSmscList->totalCnt);
233         MSG_DEBUG("selected index[%d]", pSmscList->selected);
234
235         for (int i = 0; i < pSmscList->totalCnt; i++)
236         {
237                 MSG_DEBUG("pid[%d]", pSmscList->smscData[i].pid);
238                 MSG_DEBUG("val_period[%d]", pSmscList->smscData[i].valPeriod);
239                 MSG_DEBUG("name[%s]", pSmscList->smscData[i].name);
240
241                 MSG_DEBUG("ton[%d]", pSmscList->smscData[i].smscAddr.ton);
242                 MSG_DEBUG("npi[%d]", pSmscList->smscData[i].smscAddr.npi);
243                 MSG_DEBUG("address[%s]", pSmscList->smscData[i].smscAddr.address);
244         }
245
246         char keyName[128];
247
248         if (MsgSettingSetInt(SMSC_TOTAL_COUNT, pSmscList->totalCnt) != MSG_SUCCESS) {
249                 MSG_DEBUG("Error to set config data [%s]", SMSC_TOTAL_COUNT);
250                 return MSG_ERR_SET_SETTING;
251         }
252
253         if (MsgSettingSetInt(SMSC_SELECTED, pSmscList->selected) != MSG_SUCCESS) {
254                 MSG_DEBUG("Error to set config data [%s]", SMSC_SELECTED);
255                 return MSG_ERR_SET_SETTING;
256         }
257
258         for (int i = 0; i < pSmscList->totalCnt; i++) {
259                 memset(keyName, 0x00, sizeof(keyName));
260                 sprintf(keyName, "%s/%d", SMSC_PID, i);
261
262                 if ((err = MsgSettingSetInt(keyName, (int)pSmscList->smscData[i].pid)) != MSG_SUCCESS)
263                         break;
264
265                 memset(keyName, 0x00, sizeof(keyName));
266                 sprintf(keyName, "%s/%d", SMSC_VAL_PERIOD, i);
267
268                 if ((err = MsgSettingSetInt(keyName, (int)pSmscList->smscData[i].valPeriod)) != MSG_SUCCESS)
269                         break;
270
271                 memset(keyName, 0x00, sizeof(keyName));
272                 sprintf(keyName, "%s/%d", SMSC_NAME, i);
273
274                 if ((err = MsgSettingSetString(keyName, pSmscList->smscData[i].name)) != MSG_SUCCESS)
275                         break;
276
277                 memset(keyName, 0x00, sizeof(keyName));
278                 sprintf(keyName, "%s/%d", SMSC_TON, i);
279
280                 if (pSmscList->smscData[i].smscAddr.address[0] == '+')
281                         pSmscList->smscData[i].smscAddr.ton = MSG_TON_INTERNATIONAL;
282                 else
283                         pSmscList->smscData[i].smscAddr.ton = MSG_TON_NATIONAL;
284
285                 if ((err = MsgSettingSetInt(keyName, (int)pSmscList->smscData[i].smscAddr.ton)) != MSG_SUCCESS)
286                         break;
287
288                 memset(keyName, 0x00, sizeof(keyName));
289                 sprintf(keyName, "%s/%d", SMSC_NPI, i);
290
291                 pSmscList->smscData[i].smscAddr.npi = MSG_NPI_ISDN; // app cannot set this value
292
293                 if ((err = MsgSettingSetInt(keyName, (int)pSmscList->smscData[i].smscAddr.npi)) != MSG_SUCCESS)
294                         break;
295
296                 memset(keyName, 0x00, sizeof(keyName));
297                 sprintf(keyName, "%s/%d", SMSC_ADDRESS, i);
298
299                 if ((err = MsgSettingSetString(keyName, pSmscList->smscData[i].smscAddr.address)) != MSG_SUCCESS)
300                         break;
301         }
302
303         if (err != MSG_SUCCESS) {
304                 MSG_DEBUG("Error to set config data [%s]", keyName);
305         }
306
307         return err;
308 }
309
310
311 msg_error_t SmsPluginSetting::addCbOpt(MSG_CBMSG_OPT_S *pCbOpt)
312 {
313         msg_error_t err = MSG_SUCCESS;
314
315         MSG_DEBUG("Receive [%d], Max SIM Count [%d]", pCbOpt->bReceive, pCbOpt->maxSimCnt);
316
317         MSG_DEBUG("Channel Count [%d]", pCbOpt->channelData.channelCnt);
318
319         for (int i = 0; i < pCbOpt->channelData.channelCnt; i++)
320         {
321                 MSG_DEBUG("Channel FROM [%d], Channel TO [%d]", pCbOpt->channelData.channelInfo[i].from, pCbOpt->channelData.channelInfo[i].to);
322         }
323
324         // Set Setting Data into Vconf
325         if (MsgSettingSetBool(CB_RECEIVE, pCbOpt->bReceive) != MSG_SUCCESS) {
326                 MSG_DEBUG("Error to set config data [%s]", CB_RECEIVE);
327                 return MSG_ERR_SET_SETTING;
328         }
329
330         if (MsgSettingSetInt(CB_MAX_SIM_COUNT, pCbOpt->maxSimCnt) != MSG_SUCCESS) {
331                 MSG_DEBUG("Error to set config data [%s]", CB_MAX_SIM_COUNT);
332                 return MSG_ERR_SET_SETTING;
333         }
334
335         if (MsgSettingSetInt(CB_CHANNEL_COUNT, pCbOpt->channelData.channelCnt) != MSG_SUCCESS) {
336                 MSG_DEBUG("Error to set config data [%s]", CB_CHANNEL_COUNT);
337                 return MSG_ERR_SET_SETTING;
338         }
339
340         char keyName[128];
341
342         for (int i = 0; i < pCbOpt->channelData.channelCnt; i++) {
343                 memset(keyName, 0x00, sizeof(keyName));
344                 sprintf(keyName, "%s/%d", CB_CHANNEL_ACTIVATE, i);
345
346                 if ((err = MsgSettingSetBool(keyName, pCbOpt->channelData.channelInfo[i].bActivate)) != MSG_SUCCESS)
347                         break;
348
349                 memset(keyName, 0x00, sizeof(keyName));
350                 sprintf(keyName, "%s/%d", CB_CHANNEL_ID_FROM, i);
351
352                 if ((err = MsgSettingSetInt(keyName, pCbOpt->channelData.channelInfo[i].from)) != MSG_SUCCESS)
353                         break;
354
355                 memset(keyName, 0x00, sizeof(keyName));
356                 sprintf(keyName, "%s/%d", CB_CHANNEL_ID_TO, i);
357
358                 if ((err = MsgSettingSetInt(keyName, pCbOpt->channelData.channelInfo[i].to)) != MSG_SUCCESS)
359                         break;
360
361                 memset(keyName, 0x00, sizeof(keyName));
362                 sprintf(keyName, "%s/%d", CB_CHANNEL_NAME, i);
363
364                 if ((err = MsgSettingSetString(keyName, pCbOpt->channelData.channelInfo[i].name)) != MSG_SUCCESS)
365                         break;
366         }
367
368         return err;
369 }
370
371
372 void SmsPluginSetting::getCbOpt(MSG_SETTING_S *pSetting)
373 {
374         char keyName[128];
375         char *tmpValue = NULL;
376
377         memset(&(pSetting->option.cbMsgOpt), 0x00, sizeof(MSG_CBMSG_OPT_S));
378
379         MsgSettingGetBool(CB_RECEIVE, &pSetting->option.cbMsgOpt.bReceive);
380
381         pSetting->option.cbMsgOpt.maxSimCnt = MsgSettingGetInt(CB_MAX_SIM_COUNT);
382
383         pSetting->option.cbMsgOpt.channelData.channelCnt = MsgSettingGetInt(CB_CHANNEL_COUNT);
384
385         for (int i = 0; i < pSetting->option.cbMsgOpt.channelData.channelCnt; i++) {
386                 memset(keyName, 0x00, sizeof(keyName));
387                 sprintf(keyName, "%s/%d", CB_CHANNEL_ACTIVATE, i);
388
389                 MsgSettingGetBool(keyName, &pSetting->option.cbMsgOpt.channelData.channelInfo[i].bActivate);
390
391                 memset(keyName, 0x00, sizeof(keyName));
392                 sprintf(keyName, "%s/%d", CB_CHANNEL_ID_FROM, i);
393
394                 pSetting->option.cbMsgOpt.channelData.channelInfo[i].from = MsgSettingGetInt(keyName);
395
396                 memset(keyName, 0x00, sizeof(keyName));
397                 sprintf(keyName, "%s/%d", CB_CHANNEL_ID_TO, i);
398
399                 pSetting->option.cbMsgOpt.channelData.channelInfo[i].to = MsgSettingGetInt(keyName);
400
401                 memset(keyName, 0x00, sizeof(keyName));
402                 sprintf(keyName, "%s/%d", CB_CHANNEL_NAME, i);
403
404                 tmpValue = MsgSettingGetString(keyName);
405
406                 if (tmpValue != NULL)
407                 {
408                         strncpy(pSetting->option.cbMsgOpt.channelData.channelInfo[i].name, tmpValue, CB_CHANNEL_NAME_MAX);
409                         free(tmpValue);
410                         tmpValue = NULL;
411                 }
412         }
413
414         for (int i = MSG_CBLANG_TYPE_ALL; i < MSG_CBLANG_TYPE_MAX; i++) {
415                 memset(keyName, 0x00, sizeof(keyName));
416                 sprintf(keyName, "%s/%d", CB_LANGUAGE, i);
417
418                 MsgSettingGetBool(keyName, &pSetting->option.cbMsgOpt.bLanguage[i]);
419         }
420
421 }
422
423
424 void SmsPluginSetting::setParamList(const MSG_SMSC_LIST_S *pSMSCList)
425 {
426         MSG_BEGIN();
427
428         TelSmsParams_t smsParam = {0};
429
430         int ret = TAPI_API_SUCCESS;
431
432         for (int index = 0; index < pSMSCList->totalCnt; index++) {
433                 /*Setting the SMSP Record index value*/
434                 smsParam.RecordIndex = (unsigned char)index;
435
436                 /*Setting the SMSP Record Length value = 28 + alphaId_len*/
437                 smsParam.RecordLen = 28 + strlen(pSMSCList->smscData[index].name);
438
439                 /*Setting the SMSP Alpha ID value*/
440                 smsParam.AlphaIdLen = strlen(pSMSCList->smscData[index].name);
441                 MSG_DEBUG("AlphaIdLen = %ld", smsParam.AlphaIdLen);
442
443                 if (smsParam.AlphaIdLen > 0 &&  smsParam.AlphaIdLen <= SMSC_NAME_MAX) {
444                         memcpy(smsParam.szAlphaId, pSMSCList->smscData[index].name, smsParam.AlphaIdLen);
445                         smsParam.szAlphaId[smsParam.AlphaIdLen] = '\0';
446                         MSG_DEBUG("szAlphaId = %s", smsParam.szAlphaId);
447                 }
448
449                 smsParam.ParamIndicator = 0x00;
450
451                 if (strlen(pSMSCList->smscData[index].smscAddr.address) > 0) {
452                         smsParam.ParamIndicator |= 0x02 ;  //enable 2nd Bit
453                         MSG_DEBUG("ParamIndicator = [%02x]", smsParam.ParamIndicator);
454
455                         if (pSMSCList->smscData[index].smscAddr.address[0] == '+')
456                                 smsParam.TpSvcCntrAddr.Ton = TAPI_SIM_TON_INTERNATIONAL;
457                         else
458                                 smsParam.TpSvcCntrAddr.Ton = TAPI_SIM_TON_NATIONAL;
459
460                         smsParam.TpSvcCntrAddr.Npi = TAPI_SIM_NPI_ISDN_TEL; // app cannot set this value
461
462                         MSG_DEBUG("SMSC TON = [%d] NPI = [%d]", smsParam.TpSvcCntrAddr.Ton, smsParam.TpSvcCntrAddr.Npi);
463
464                         MSG_DEBUG("address = %s", pSMSCList->smscData[index].smscAddr.address);
465
466                         smsParam.TpSvcCntrAddr.DialNumLen = SmsPluginParamCodec::encodeSMSC(pSMSCList->smscData[index].smscAddr.address, smsParam.TpSvcCntrAddr.szDiallingNum);
467                 } else {
468                         MSG_DEBUG("SMSC Addr is not present");
469                 }
470
471                 /*Setting the PID value*/
472                 smsParam.ParamIndicator |= 0x04 ;  //enable 3nd Bit
473                 MSG_DEBUG("ParamIndicator = [%02x]", smsParam.ParamIndicator);
474
475                 smsParam.TpProtocolId = (unsigned short)convertPid(pSMSCList->smscData[index].pid);
476
477                 /*Setting the ValidityPeriod value*/
478                 smsParam.ParamIndicator |= 0x10 ;  //enable 5nd Bit
479                 MSG_DEBUG("ParamIndicator = [%02x]", smsParam.ParamIndicator);
480
481                 smsParam.TpValidityPeriod = (unsigned short)pSMSCList->smscData[index].valPeriod;
482
483                 smsParam.ParamIndicator = ~(smsParam.ParamIndicator);
484                 MSG_DEBUG("ParamIndicator = [%02x]", smsParam.ParamIndicator);
485
486                 ret = tel_set_sms_parameters(pTapiHandle, (const TelSmsParams_t*)&smsParam, TapiEventSetConfigData, NULL);
487
488                 if (ret != TAPI_API_SUCCESS)
489                         THROW(MsgException::SMS_PLG_ERROR, "tel_set_sms_parameters() Error. [%d]", ret);
490
491                 if (!getResultFromSim())
492                         THROW(MsgException::SMS_PLG_ERROR, "tel_set_sms_parameters() Result Error.");
493         }
494
495         MSG_END();
496 }
497
498
499 void SmsPluginSetting::getParamList(MSG_SMSC_LIST_S *pSMSCList)
500 {
501         MSG_BEGIN();
502
503         int paramCnt = 0;
504
505         paramCnt = getParamCount();
506
507         MSG_DEBUG("Parameter Count [%d]", paramCnt);
508
509         int ret = TAPI_API_SUCCESS;
510
511         MSG_SMSC_DATA_S tmpSmscData = {};
512
513         for (int index = 0; index < paramCnt; index++) {
514                 ret = tel_get_sms_parameters(pTapiHandle, index, TapiEventGetParam, NULL);
515
516                 if (ret == TAPI_API_SUCCESS) {
517                         MSG_DEBUG("######## tel_get_sms_parameters() Success !!! #######");
518                 } else {
519                         THROW(MsgException::SMS_PLG_ERROR, "######## tel_get_sms_parameters() Fail !!! return : %d #######", ret);
520                 }
521
522                 if (getParamEvent(&tmpSmscData) == true) {
523                         MSG_DEBUG("######## Get Parameter was Successful !!! #######");
524                 } else {
525                         THROW(MsgException::SMS_PLG_ERROR, "######## Get Parameter was Failed !!! #######");
526                 }
527
528                 memcpy(&(pSMSCList->smscData[index]), &tmpSmscData, sizeof(MSG_SMSC_DATA_S));
529
530                 MSG_DEBUG("pid[%d]", pSMSCList->smscData[index].pid);
531                 MSG_DEBUG("val_period[%d]", pSMSCList->smscData[index].valPeriod);
532                 MSG_DEBUG("name[%s]", pSMSCList->smscData[index].name);
533
534                 MSG_DEBUG("ton[%d]", pSMSCList->smscData[index].smscAddr.ton);
535                 MSG_DEBUG("npi[%d]", pSMSCList->smscData[index].smscAddr.npi);
536                 MSG_DEBUG("address[%s]", pSMSCList->smscData[index].smscAddr.address);
537         }
538
539         pSMSCList->totalCnt = paramCnt;
540         pSMSCList->selected = selectedParam;
541
542         MSG_DEBUG("total_count[%d]", pSMSCList->totalCnt);
543
544         MSG_END();
545 }
546
547
548 int SmsPluginSetting::getParamCount()
549 {
550         int ret = TAPI_API_SUCCESS;
551
552         ret = tel_get_sms_parameter_count(pTapiHandle, TapiEventGetParamCnt, NULL);
553
554         if (ret == TAPI_API_SUCCESS) {
555                 MSG_DEBUG("######## tel_get_sms_parameter_count() Success !!! #######");
556         } else {
557                 THROW(MsgException::SMS_PLG_ERROR, "tel_get_sms_parameter_count() Error. [%d]", ret);
558         }
559
560         return getParamCntEvent();
561 }
562
563
564 bool SmsPluginSetting::getParam(int Index, MSG_SMSC_DATA_S *pSmscData)
565 {
566         int ret = TAPI_API_SUCCESS;
567
568         ret = tel_get_sms_parameters(pTapiHandle, Index, TapiEventGetParam, NULL);
569
570         if (ret == TAPI_API_SUCCESS) {
571                 MSG_DEBUG("######## tel_get_sms_parameters() Success !!! #######");
572         } else {
573                 MSG_DEBUG("######## tel_get_sms_parameters() Fail !!! return : %d #######", ret);
574                 return false;
575         }
576
577         if (getParamEvent(pSmscData) == true) {
578                 MSG_DEBUG("######## Get Parameter was Successful !!! #######");
579         } else {
580                 MSG_DEBUG("######## Get Parameter was Failed !!! #######");
581                 return false;
582         }
583
584         return true;
585 }
586
587
588 bool SmsPluginSetting::setCbConfig(const MSG_CBMSG_OPT_S *pCbOpt)
589 {
590         int ret = TAPI_API_SUCCESS;
591
592         TelSmsCbConfig_t cbConfig = {};
593
594         cbConfig.CBEnabled = (int)pCbOpt->bReceive;
595         cbConfig.Net3gppType = TAPI_NETTEXT_NETTYPE_3GPP;
596         cbConfig.MsgIdMaxCount = pCbOpt->maxSimCnt;
597         cbConfig.MsgIdRangeCount = pCbOpt->channelData.channelCnt;
598
599         for (int i = 0; i < cbConfig.MsgIdRangeCount; i++) {
600                 cbConfig.MsgIDs[i].Net3gpp.Selected = (unsigned short)pCbOpt->channelData.channelInfo[i].bActivate;
601                 cbConfig.MsgIDs[i].Net3gpp.FromMsgId = (unsigned short)pCbOpt->channelData.channelInfo[i].from;
602                 cbConfig.MsgIDs[i].Net3gpp.ToMsgId = (unsigned short)pCbOpt->channelData.channelInfo[i].to;
603
604                 MSG_DEBUG("FROM: %d, TO: %d", cbConfig.MsgIDs[i].Net3gpp.FromMsgId, cbConfig.MsgIDs[i].Net3gpp.ToMsgId);
605         }
606         MSG_DEBUG("CBEnabled: %d, range_count: %d", cbConfig.CBEnabled, cbConfig.MsgIdRangeCount);
607
608         ret = tel_set_sms_cb_config(pTapiHandle, &cbConfig, TapiEventSetConfigData, NULL);
609
610         if (ret == TAPI_API_SUCCESS) {
611                 MSG_DEBUG("######## tel_set_sms_cb_config() Success !!! #######");
612         } else {
613                 MSG_DEBUG("######## tel_set_sms_cb_config() Fail !!! return : %d #######", ret);
614                 return false;
615         }
616
617         if (getResultFromSim() == true) {
618                 MSG_DEBUG("######## Set Cb Config was Successful !!! #######");
619         } else {
620                 MSG_DEBUG("######## Set Cb Config was Failed !!! #######");
621                 return false;
622         }
623
624         return true;
625 }
626
627
628 bool SmsPluginSetting::getCbConfig(MSG_CBMSG_OPT_S *pCbOpt)
629 {
630         int ret = TAPI_API_SUCCESS;
631
632         ret = tel_get_sms_cb_config(pTapiHandle, TapiEventGetCBConfig, NULL);
633
634         if (ret == TAPI_API_SUCCESS) {
635                 MSG_DEBUG("######## tel_get_sms_cb_config() Success !!! #######");
636         } else {
637                 MSG_DEBUG("######## tel_get_sms_cb_config() Fail !!! return : %d #######", ret);
638                 return false;
639         }
640
641         if (getCbConfigEvent(pCbOpt) == true) {
642                 MSG_DEBUG("######## Get Cb Config was Successful !!! #######");
643         } else {
644                 MSG_DEBUG("######## Get Cb Config was Failed !!! #######");
645                 return false;
646         }
647
648         return true;
649 }
650
651 void SmsPluginSetting::setVoiceMailInfo(const MSG_VOICEMAIL_OPT_S *pVoiceOpt)
652 {
653         int ret = TAPI_API_SUCCESS;
654
655         TelSimMailBoxNumber_t mailboxInfo = {0,};
656
657         for (int i = 0; i < simMailboxList.count; i++) {
658                 if (simMailboxList.list[i].mb_type == TAPI_SIM_MAILBOX_VOICE) {
659                         memset(&simMailboxList.list[i].num, 0x00, sizeof(simMailboxList.list[i].num));
660                         snprintf(simMailboxList.list[i].num, sizeof(simMailboxList.list[i].num), "%s", pVoiceOpt->mailNumber);
661                         MSG_DEBUG("Mailbox number config [%s]", simMailboxList.list[i].num);
662
663                         mailboxInfo.b_cphs = simMailboxList.list[i].b_cphs;
664                         mailboxInfo.alpha_id_max_len = simMailboxList.list[i].alpha_id_max_len;
665                         mailboxInfo.mb_type = (TelSimMailboxType_t)simMailboxList.list[i].mb_type;
666                         mailboxInfo.profile_num = simMailboxList.list[i].profile_num;
667                         mailboxInfo.rec_index = simMailboxList.list[i].rec_index;
668                         mailboxInfo.ton = (TelSimTypeOfNum_t)simMailboxList.list[i].ton;
669                         mailboxInfo.npi = (TelSimNumberingPlanIdentity_t)simMailboxList.list[i].npi;
670                         snprintf(mailboxInfo.alpha_id, sizeof(mailboxInfo.alpha_id), "%s", simMailboxList.list[i].alpha_id);
671                         snprintf(mailboxInfo.num, sizeof(mailboxInfo.num), "%s", simMailboxList.list[i].num);
672                         mailboxInfo.cc_id = simMailboxList.list[i].cc_id;
673                         mailboxInfo.ext1_id = simMailboxList.list[i].ext1_id;
674
675                         break;
676                 }
677         }
678
679         ret = tel_set_sim_mailbox_info(pTapiHandle, &mailboxInfo, TapiEventSetMailboxInfo, NULL);
680
681         if (ret == TAPI_API_SUCCESS) {
682                 MSG_DEBUG("######## tel_set_sim_mailbox_info() Success !!! #######");
683         } else {
684                 MSG_DEBUG("######## tel_set_sim_mailbox_info() Fail !!! return : %d #######", ret);
685         }
686
687         if (getResultFromSim() == true) {
688                 MSG_DEBUG("######## Set mailbox info Success !!! #######");
689         } else {
690                 THROW(MsgException::SMS_PLG_ERROR, "########  Set mailbox info Failed !!!#######");
691         }
692
693         return;
694 }
695
696 bool SmsPluginSetting::getVoiceMailInfo(MSG_VOICEMAIL_OPT_S *pVoiceOpt)
697 {
698         int ret = TAPI_API_SUCCESS;
699
700         ret = tel_get_sim_mailbox_info(pTapiHandle, TapiEventGetMailboxInfo, NULL);
701
702         if (ret == TAPI_API_SUCCESS) {
703                 MSG_DEBUG("######## tel_get_sim_mailbox_info() Success !!! #######");
704         } else {
705                 MSG_DEBUG("######## tel_get_sim_mailbox_info() Fail !!! return : %d #######", ret);
706                 return false;
707         }
708
709         if (getMailboxInfoEvent(pVoiceOpt) == true) {
710                 MSG_DEBUG("######## Get MWI info was Successful !!! #######");
711         } else {
712                 MSG_DEBUG("######## Get MWI info was Failed !!! #######");
713                 return false;
714         }
715
716         return true;
717 }
718
719 void SmsPluginSetting::setMwiInfo(MSG_SUB_TYPE_T type, int count)
720 {
721         if (type < MSG_MWI_VOICE_SMS || type > MSG_MWI_OTHER_SMS) {
722                 MSG_DEBUG("Invalid parameter");
723                 return;
724         }
725
726         int ret = TAPI_API_SUCCESS;
727
728         TelSimMessageWaitingReq_t mwReq = {0,};
729
730         if (simMwiInfo.b_cphs) {
731                 if (type == MSG_MWI_VOICE_SMS)
732                         simMwiInfo.cphs_mwi.b_voice1 = true;
733                 else if (type == MSG_MWI_FAX_SMS)
734                         simMwiInfo.cphs_mwi.b_fax = true;
735                 else
736                         MSG_DEBUG("There is no type [%d] in CPHS.", type);
737
738                 mwReq.mw_data_u.cphs_mw.b_voice1 = simMwiInfo.cphs_mwi.b_voice1;
739                 mwReq.mw_data_u.cphs_mw.b_voice2 = simMwiInfo.cphs_mwi.b_voice2;
740                 mwReq.mw_data_u.cphs_mw.b_fax = simMwiInfo.cphs_mwi.b_fax;
741                 mwReq.mw_data_u.cphs_mw.b_data = simMwiInfo.cphs_mwi.b_data;
742         } else {
743                 if (type == MSG_MWI_VOICE_SMS)
744                         simMwiInfo.mwi_list.mw_info[0].voice_count = count;
745                 else if (type == MSG_MWI_FAX_SMS)
746                         simMwiInfo.mwi_list.mw_info[0].fax_count = count;
747                 else if (type == MSG_MWI_EMAIL_SMS)
748                         simMwiInfo.mwi_list.mw_info[0].email_count = count;
749                 else // MSG_MWI_OTHER_SMS
750                         simMwiInfo.mwi_list.mw_info[0].other_count = count;
751
752                 mwReq.mw_data_u.mw.rec_index = simMwiInfo.mwi_list.mw_info[0].rec_index;
753                 mwReq.mw_data_u.mw.indicator_status = simMwiInfo.mwi_list.mw_info[0].indicator_status;
754                 mwReq.mw_data_u.mw.voice_count = simMwiInfo.mwi_list.mw_info[0].voice_count;
755                 mwReq.mw_data_u.mw.fax_count = simMwiInfo.mwi_list.mw_info[0].fax_count;
756                 mwReq.mw_data_u.mw.email_count = simMwiInfo.mwi_list.mw_info[0].email_count;
757                 mwReq.mw_data_u.mw.other_count = simMwiInfo.mwi_list.mw_info[0].other_count;
758                 mwReq.mw_data_u.mw.video_count = simMwiInfo.mwi_list.mw_info[0].video_count;
759         }
760
761         mwReq.b_cphs = simMwiInfo.b_cphs;
762
763         ret = tel_set_sim_messagewaiting_info(pTapiHandle, &mwReq, TapiEventSetMwiInfo, NULL);
764
765         if (ret == TAPI_API_SUCCESS) {
766                 MSG_DEBUG("######## tel_set_sim_messagewaiting_info() Success !!! #######");
767         } else {
768                 MSG_DEBUG("######## tel_set_sim_messagewaiting_info() Fail !!! return : %d #######", ret);
769         }
770
771         if (getResultFromSim() == true) {
772                 MSG_DEBUG("######## Set message waiting info Success !!! #######");
773         } else {
774                 MSG_DEBUG("######## Set message waiting info fail !!! #######");
775         }
776
777         return;
778 }
779
780
781 bool SmsPluginSetting::getMwiInfo(void)
782 {
783         int ret = TAPI_API_SUCCESS;
784
785         ret = tel_get_sim_messagewaiting_info(pTapiHandle, TapiEventGetMwiInfo, NULL);
786
787         if (ret == TAPI_API_SUCCESS) {
788                 MSG_DEBUG("######## tel_get_sim_messagewaiting_info() Success !!! #######");
789         } else {
790                 MSG_DEBUG("######## tel_get_sim_messagewaiting_info() Fail !!! return : %d #######", ret);
791                 return false;
792         }
793
794         if (getResultFromSim() == true) {
795                 MSG_DEBUG("######## Get Mainbox info was Successful !!! #######");
796         } else {
797                 MSG_DEBUG("######## Get Mainbox info was Failed !!! #######");
798                 return false;
799         }
800
801         return true;
802 }
803
804
805 bool SmsPluginSetting::getMsisdnInfo(void)
806 {
807         int ret = TAPI_API_SUCCESS;
808         bool result = true;
809
810         ret = tel_get_sim_msisdn(pTapiHandle, TapiEventGetMsisdnInfo, NULL);
811
812         if (ret == TAPI_API_SUCCESS) {
813                 result = true;
814                 MSG_DEBUG("######## tel_get_sim_msisdn() Success !!! #######");
815         } else {
816                 result = false;
817                 MSG_DEBUG("######## tel_get_sim_msisdn() Fail !!! return : %d #######", ret);
818         }
819
820         return result;
821 }
822
823
824 void SmsPluginSetting::setParamCntEvent(int ParamCnt)
825 {
826         mx.lock();
827
828         paramCnt = ParamCnt;
829
830         cv.signal();
831
832         mx.unlock();
833 }
834
835
836 int SmsPluginSetting::getParamCntEvent()
837 {
838         int ret = 0;
839
840         mx.lock();
841
842         ret = cv.timedwait(mx.pMutex(), 10);
843
844         mx.unlock();
845
846         if (ret == ETIMEDOUT) {
847                 MSG_DEBUG("WARNING: TAPI callback TIME-OUT");
848                 return 0;
849         }
850
851         return paramCnt;
852 }
853
854
855 void SmsPluginSetting::setParamEvent(const MSG_SMSC_DATA_S *pSmscData, int RecordIdx, bool bSuccess)
856 {
857         mx.lock();
858
859         bTapiResult = bSuccess;
860
861         memset(&smscData, 0x00, sizeof(MSG_SMSC_DATA_S));
862
863         if (bTapiResult == true) {
864                 MSG_DEBUG("Success to get parameter data");
865
866                 selectedParam = RecordIdx;
867
868                 memcpy(&smscData, pSmscData, sizeof(MSG_SMSC_DATA_S));
869         }
870
871         cv.signal();
872
873         mx.unlock();
874 }
875
876
877 bool SmsPluginSetting::getParamEvent(MSG_SMSC_DATA_S *pSmscData)
878 {
879         int ret = 0;
880
881         bTapiResult = false;
882
883         mx.lock();
884
885         ret = cv.timedwait(mx.pMutex(), 10);
886
887         mx.unlock();
888
889         if (ret == ETIMEDOUT) {
890                 MSG_DEBUG("WARNING: TAPI callback TIME-OUT");
891                 return false;
892         }
893
894         memset(pSmscData, 0x00, sizeof(MSG_SMSC_DATA_S));
895
896         if (bTapiResult == true) {
897                 memcpy(pSmscData, &smscData, sizeof(MSG_SMSC_DATA_S));
898         }
899
900         return bTapiResult;
901 }
902
903
904 void SmsPluginSetting::setCbConfigEvent(const MSG_CBMSG_OPT_S *pCbOpt, bool bSuccess)
905 {
906         mx.lock();
907
908         bTapiResult = bSuccess;
909
910         memset(&cbOpt, 0x00, sizeof(MSG_CBMSG_OPT_S));
911
912         if (bTapiResult == true) {
913                 MSG_DEBUG("Success to get cb config data");
914
915                 memcpy(&cbOpt, pCbOpt, sizeof(MSG_CBMSG_OPT_S));
916         }
917
918         cv.signal();
919
920         mx.unlock();
921 }
922
923
924 bool SmsPluginSetting::getCbConfigEvent(MSG_CBMSG_OPT_S *pCbOpt)
925 {
926         int ret = 0;
927
928         bTapiResult = false;
929
930         mx.lock();
931
932         ret = cv.timedwait(mx.pMutex(), 10);
933
934         mx.unlock();
935
936         if (ret == ETIMEDOUT) {
937                 MSG_DEBUG("WARNING: TAPI callback TIME-OUT");
938                 return false;
939         }
940
941         memset(pCbOpt, 0x00, sizeof(MSG_CBMSG_OPT_S));
942
943         if (bTapiResult == true) {
944                 memcpy(pCbOpt, &cbOpt, sizeof(MSG_CBMSG_OPT_S));
945         }
946
947         return bTapiResult;
948 }
949
950
951 void SmsPluginSetting::setMailboxInfoEvent(SMS_SIM_MAILBOX_LIST_S *pMailboxList, bool bSuccess)
952 {
953         mx.lock();
954
955         bTapiResult = bSuccess;
956
957         memset(&simMailboxList, 0x00, sizeof(SMS_SIM_MAILBOX_LIST_S));
958
959         if (bTapiResult == true) {
960                 int i = 0;
961
962                 if (pMailboxList && pMailboxList->count > 0) {
963                         memcpy(&simMailboxList, pMailboxList, sizeof(SMS_SIM_MAILBOX_LIST_S));
964
965                         /* Temp :: Save voicemail number with VOICE1 line number */
966                         for (i = 0; i < pMailboxList->count ; i++) {
967                                 MSG_DEBUG("Mailbox list[%d] type=[%d] address = [%s]", i, pMailboxList->list[i].mb_type, pMailboxList->list[i].num);
968                                 if (pMailboxList->list[i].mb_type == TAPI_SIM_MAILBOX_VOICE) {
969                                         char mailNumber[MAX_PHONE_NUMBER_LEN+1];
970                                         memset(mailNumber, 0x00 , sizeof(mailNumber));
971                                         if (simMailboxList.list[i].ton == MSG_TON_INTERNATIONAL && simMailboxList.list[i].num[0] != '+') {
972                                                 snprintf(mailNumber, MAX_PHONE_NUMBER_LEN, "+%s", simMailboxList.list[i].num);
973                                                 MSG_DEBUG("MSG_TON_INTERNATIONAL [%s]", mailNumber);
974                                         } else {
975                                                 snprintf(mailNumber, MAX_PHONE_NUMBER_LEN, "%s", simMailboxList.list[i].num);
976                                                 MSG_DEBUG("[%s]", mailNumber);
977                                         }
978                                         if (MsgSettingSetString(VOICEMAIL_NUMBER, mailNumber) != MSG_SUCCESS)
979                                                 MSG_DEBUG("MsgSettingSetString is failed!!");
980                                         break;
981                                 }
982                         }
983                 }
984         }
985
986         cv.signal();
987
988         mx.unlock();
989 }
990
991 bool SmsPluginSetting::getMailboxInfoEvent(MSG_VOICEMAIL_OPT_S *pVoiceOpt)
992 {
993         int ret = 0;
994
995         bTapiResult = false;
996
997         mx.lock();
998
999         ret = cv.timedwait(mx.pMutex(), 10);
1000
1001         mx.unlock();
1002
1003         if (ret == ETIMEDOUT) {
1004                 MSG_DEBUG("WARNING: TAPI callback TIME-OUT");
1005                 return false;
1006         }
1007
1008         memset(pVoiceOpt, 0x00, sizeof(MSG_VOICEMAIL_OPT_S));
1009
1010         if (bTapiResult == true) {
1011                 for(int i = 0; i < simMailboxList.count; i++) {
1012                         if (simMailboxList.list[i].mb_type == MSG_SIM_MAILBOX_VOICE) {
1013                                 if (simMailboxList.list[i].ton == MSG_TON_INTERNATIONAL && simMailboxList.list[i].num[0] != '+') {
1014                                         snprintf(pVoiceOpt->mailNumber, sizeof(pVoiceOpt->mailNumber), "+%s", simMailboxList.list[i].num);
1015                                 } else {
1016                                         snprintf(pVoiceOpt->mailNumber, sizeof(pVoiceOpt->mailNumber), "%s", simMailboxList.list[i].num);
1017                                 }
1018
1019                                 break;
1020                         }
1021                 }
1022         }
1023
1024         return bTapiResult;
1025 }
1026
1027 void SmsPluginSetting::setMwiInfoEvent(SMS_SIM_MWI_INFO_S *pMwiInfo, bool bSuccess)
1028 {
1029         mx.lock();
1030
1031         bTapiResult = bSuccess;
1032
1033         memset(&simMwiInfo, 0x00, sizeof(SMS_SIM_MWI_INFO_S));
1034
1035         if (bTapiResult == true) {
1036                 int mwi_cnt = 0;
1037                 int index = 0;
1038
1039                 memcpy(&simMwiInfo, pMwiInfo, sizeof(SMS_SIM_MWI_INFO_S));
1040
1041                 /* Save MW count with VOICE line number */
1042                 for(int i = 0; i < simMailboxList.count; i++) {
1043
1044                         if (simMailboxList.list[i].mb_type == MSG_SIM_MAILBOX_VOICE) {
1045
1046                                 index = simMailboxList.list[i].profile_num - 1;
1047                                 if (index < 0) {
1048                                         MSG_DEBUG("SIM profile number is invalid.");
1049                                         break;
1050                                 }
1051
1052                                 MSG_DEBUG("SIM MWI profile number=[%d], index=[%d]", simMailboxList.list[i].profile_num, index);
1053
1054                                 if (simMwiInfo.b_cphs == false) { // Normal case
1055                                         mwi_cnt = simMwiInfo.mwi_list.mw_info[index].voice_count;
1056                                 } else { // CPHS case
1057                                         /* For CPHS case, mwi_cnt value is boolean */
1058                                         mwi_cnt = simMwiInfo.cphs_mwi.b_voice1;
1059                                 }
1060
1061                                 if (MsgSettingSetInt(VOICEMAIL_COUNT, mwi_cnt) != MSG_SUCCESS)
1062                                         MSG_DEBUG("MsgSettingSetInt is failed!!");
1063
1064                                 if (mwi_cnt > 0) {
1065                                         MSG_MESSAGE_INFO_S msgInfo = {0,};
1066
1067                                         msgInfo.displayTime = time(NULL);
1068                                         snprintf(msgInfo.addressList[0].addressVal, sizeof(msgInfo.addressList[0].addressVal), \
1069                                                         "%s", simMailboxList.list[i].num);
1070                                         memset(msgInfo.addressList[0].displayName, 0x00, sizeof(msgInfo.addressList[0].displayName));
1071                                         msgInfo.msgType.mainType = MSG_SMS_TYPE;
1072                                         msgInfo.msgType.subType = MSG_MWI_VOICE_SMS;
1073
1074                                         snprintf(msgInfo.msgText, sizeof(msgInfo.msgText), "%d new voice message", mwi_cnt);
1075
1076                                         MsgSoundPlayStart(false);
1077                                         MsgInsertNoti(&msgInfo);
1078                                 }
1079                                 break;
1080                         }
1081                 }
1082         }
1083
1084         cv.signal();
1085
1086         mx.unlock();
1087 }
1088
1089 void SmsPluginSetting::setResultFromSim(bool bResult)
1090 {
1091         mx.lock();
1092
1093         bTapiResult = bResult;
1094
1095         cv.signal();
1096
1097         mx.unlock();
1098 }
1099
1100
1101 bool SmsPluginSetting::getResultFromSim()
1102 {
1103         int ret = 0;
1104
1105         mx.lock();
1106
1107         ret = cv.timedwait(mx.pMutex(), 10);
1108
1109         mx.unlock();
1110
1111         if (ret == ETIMEDOUT) {
1112                 MSG_DEBUG("WARNING: TAPI callback TIME-OUT");
1113                 return false;
1114         }
1115
1116         return bTapiResult;
1117 }
1118
1119
1120 SMS_PID_T SmsPluginSetting::convertPid(MSG_SMS_PID_T pid)
1121 {
1122         SMS_PID_T retPid;
1123
1124         switch (pid)
1125         {
1126                 case MSG_PID_TEXT :
1127                         retPid = SMS_PID_NORMAL;
1128                 break;
1129                 case MSG_PID_VOICE :
1130                         retPid = SMS_PID_VOICE;
1131                 break;
1132                 case MSG_PID_FAX :
1133                         retPid = SMS_PID_TELEX;
1134                 break;
1135                 case MSG_PID_X400 :
1136                         retPid = SMS_PID_x400;
1137                 break;
1138                 case MSG_PID_ERMES :
1139                         retPid = SMS_PID_ERMES;
1140                 break;
1141                 case MSG_PID_EMAIL :
1142                         retPid = SMS_PID_EMAIL;
1143                 break;
1144                 default :
1145                         retPid = SMS_PID_NORMAL;
1146                 break;
1147         }
1148
1149         return retPid;
1150 }
1151