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