ec2981d9334b09b2e4055bad6c0adffefd8c1772
[platform/core/messaging/msg-service.git] / plugin / sms_plugin / SmsPluginSetting.cpp
1 /*
2  * Copyright (c) 2014 Samsung Electronics Co., Ltd. All rights reserved
3  *
4  * Licensed under the Apache License, Version 2.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.apache.org/licenses/LICENSE-2.0
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 #include <pthread.h>
19
20 #include "MsgDebug.h"
21 #include "MsgCppTypes.h"
22 #include "MsgException.h"
23 #include "MsgGconfWrapper.h"
24 #include "MsgNotificationWrapper.h"
25 #include "MsgSoundPlayer.h"
26 #include "MsgContact.h"
27 #include "MsgUtilStorage.h"
28 #include "MsgTextConvert.h"
29 #include "MsgDevicedWrapper.h"
30
31 #include "SmsPluginParamCodec.h"
32 #include "SmsPluginCallback.h"
33 #include "SmsPluginEventHandler.h"
34 #include "SmsPluginSimMsg.h"
35 #include "SmsPluginMain.h"
36 #include "SmsPluginSetting.h"
37 #include "SmsPluginDSHandler.h"
38
39 extern "C" {
40         #include <tapi_common.h>
41         #include <TelSms.h>
42         #include <TapiUtility.h>
43         #include <ITapiNetText.h>
44         #include <ITapiSim.h>
45         #include <ITapiModem.h>
46 }
47
48 /*==================================================================================================
49                                   INTERNAL FUNCTION
50 ==================================================================================================*/
51
52
53 /*==================================================================================================
54                    IMPLEMENTATION OF SmsPluginSetting - Member Functions
55 ==================================================================================================*/
56 SmsPluginSetting* SmsPluginSetting::pInstance = NULL;
57
58
59 SmsPluginSetting::SmsPluginSetting()
60 {
61         /* Initialize member variables */
62         for (int i = 0; i <= MAX_TELEPHONY_HANDLE_CNT; i++) {
63                 memset(&smscData[i], 0x00, sizeof(MSG_SMSC_DATA_S));
64                 simStatus[i] = MSG_SIM_STATUS_NOT_FOUND;
65         }
66         smscList.clear();
67         simMailboxList.clear();
68         simMwiInfo.clear();
69         cbOpt.clear();
70         memset(&meImei, 0x00, sizeof(meImei));
71
72         bTapiResult = false;
73         paramCnt = 0;
74         selectedParam = 0;
75         selectedSimIndex = 0;
76
77         for (int i = 0; i < MAX_TELEPHONY_HANDLE_CNT; i++)
78                 bMbdnEnable[i] = false;
79 }
80
81
82 SmsPluginSetting::~SmsPluginSetting()
83 {
84         smscList.erase(smscList.begin(), smscList.end());
85         simMailboxList.erase(simMailboxList.begin(), simMailboxList.end());
86         simMwiInfo.erase(simMwiInfo.begin(), simMwiInfo.end());
87         cbOpt.erase(cbOpt.begin(), cbOpt.end());
88 }
89
90
91 SmsPluginSetting* SmsPluginSetting::instance()
92 {
93         if (!pInstance)
94                 pInstance = new SmsPluginSetting();
95
96         return pInstance;
97 }
98
99
100 void* SmsPluginSetting::initSimInfo(void *data)
101 {
102         static Mutex mm;
103         MutexLocker lock(mm);
104
105         instance()->processInitSimInfo(data);
106
107         return NULL;
108 }
109
110 void* SmsPluginSetting::processInitSimInfo(void *data)
111 {
112         MSG_BEGIN();
113
114         /* Handle sim info initialization separately */
115         TapiHandle *handle = (TapiHandle *)data;
116         instance()->updateSimStatus(handle);
117
118         MSG_END();
119         return NULL;
120 }
121
122
123 void SmsPluginSetting::updateSimStatus(TapiHandle *handle)
124 {
125         MSG_BEGIN();
126
127         if (!handle) {
128                 MSG_DEBUG("handle is NULL.");
129                 return;
130         }
131
132         int status = 0;
133         int tapiRet = TAPI_API_SUCCESS;
134
135         char keyName[MAX_VCONFKEY_NAME_LEN];
136         memset(keyName, 0x00, sizeof(keyName));
137
138         int simIndex = SmsPluginDSHandler::instance()->getSimIndex(handle);
139
140         /* Get IMSI */
141         TelSimImsiInfo_t imsiInfo;
142         memset(&imsiInfo, 0x00, sizeof(TelSimImsiInfo_t));
143
144         tapiRet = tel_get_sim_imsi(handle, &imsiInfo);
145         if (tapiRet != TAPI_API_SUCCESS) {
146                 MSG_SEC_DEBUG("tel_get_sim_imsi() Error![%d]", tapiRet);
147         }
148
149         /* Save Subcriber ID */
150         char *subscriberId = NULL;
151         memset(keyName, 0x00, sizeof(keyName));
152
153         if (SmsPluginDSHandler::instance()->getSubscriberId(simIndex, &subscriberId) != MSG_SUCCESS) {
154                 MSG_DEBUG("getSubscriberId() is failed");
155         } else {
156                 snprintf(keyName, sizeof(keyName), "%s/%d", MSG_SIM_SUBS_ID, simIndex);
157                 if (MsgSettingSetString(keyName, subscriberId) != MSG_SUCCESS)
158                         MSG_DEBUG("Fail MsgSettingSetString");
159         }
160
161         g_free(subscriberId); subscriberId = NULL;
162
163         /* Check device status */
164         tapiRet = tel_check_sms_device_status(handle, &status);
165
166         if (tapiRet != TAPI_API_SUCCESS) {
167                 MSG_DEBUG("tel_check_sms_device_status() Error! [%d], Status [%d]", tapiRet, status);
168                 return;
169         }
170
171         if (status == TAPI_NETTEXT_READY_STATUS_3GPP) {
172                 MSG_DEBUG("Device Is Ready");
173         } else {
174                 MSG_DEBUG("Device Is Not Ready.. Waiting For Ready Callback");
175
176                 if (SmsPluginEventHandler::instance()->getDeviceStatus(handle) == true) {
177                         MSG_DEBUG("Device Is Ready");
178                 } else {
179                         MSG_DEBUG("Device Is Not Ready.");
180                         return;
181                 }
182         }
183
184         /* init config data. */
185         initConfigData(handle);
186
187         try {
188                 /* init sim messages. */
189                 SmsPluginSimMsg::instance()->initSimMessage(handle);
190         } catch (MsgException& e) {
191                 MSG_FATAL("%s", e.what());
192                 return;
193         }
194
195
196         MSG_END();
197
198         return;
199 }
200
201
202 void SmsPluginSetting::initConfigData(TapiHandle *handle)
203 {
204         MSG_BEGIN();
205
206         char keyName[MAX_VCONFKEY_NAME_LEN];
207
208         int sim_idx = SmsPluginDSHandler::instance()->getSimIndex(handle);
209         /*==================== SMSC setting ====================*/
210         /* Init SMS Parameter */
211         int paramCnt = 0;
212         int failCnt = 0;
213         bool bSelectedFound = false;
214         bool bAPReceive = false;
215
216         paramCnt = getParamCount(handle);
217
218         MSG_INFO("Parameter Count [%d]", paramCnt);
219
220         MSG_SMSC_DATA_S tmpSmscData = {};
221         MSG_SMSC_LIST_S tmpSmscList = {0, };
222
223         for (int index = 0; index < paramCnt; index++) {
224                 memset(&tmpSmscData, 0x00, sizeof(MSG_SMSC_DATA_S));
225                 if (getParam(handle, index, &tmpSmscData) == false) {
226                         failCnt++;
227                         continue;
228                 }
229
230                 memcpy(&(tmpSmscList.smscData[index]), &tmpSmscData, sizeof(MSG_SMSC_DATA_S));
231
232                 MSG_DEBUG("pid[%d]", tmpSmscList.smscData[index].pid);
233                 MSG_DEBUG("val_period[%d]", tmpSmscList.smscData[index].valPeriod);
234                 MSG_SEC_DEBUG("name[%s]", tmpSmscList.smscData[index].name);
235
236                 MSG_DEBUG("ton[%d]", tmpSmscList.smscData[index].smscAddr.ton);
237                 MSG_DEBUG("npi[%d]", tmpSmscList.smscData[index].smscAddr.npi);
238                 MSG_SEC_DEBUG("address[%s]", tmpSmscList.smscData[index].smscAddr.address);
239
240                 /* First smsc is selected index */
241                 if (!bSelectedFound) {
242                         tmpSmscList.selected = selectedParam;
243                         bSelectedFound = !bSelectedFound;
244                 }
245         }
246
247         tmpSmscList.totalCnt = (paramCnt - failCnt);
248         tmpSmscList.simIndex = sim_idx;
249
250         if (paramCnt > 0) {
251                 MSG_DEBUG("########  Add SMSC ist #######");
252                 addSMSCList(&tmpSmscList);
253         }
254
255         /*==================== CB configuration ====================*/
256         if (simStatus[sim_idx] != MSG_SIM_STATUS_NOT_FOUND) {
257                 MSG_DEBUG("simStatus == [%d]", simStatus[sim_idx]);
258
259                 MSG_CBMSG_OPT_S cbMsgOpt = {0, };
260                 cbMsgOpt.simIndex = sim_idx;
261
262                 if (getCbConfig(&cbMsgOpt) == true) {
263                         cbMsgOpt.simIndex = sim_idx;
264
265                         memset(keyName, 0x00, sizeof(keyName));
266                         snprintf(keyName, sizeof(keyName), "%s/%d", CB_RECEIVE, sim_idx);
267                         if (MsgSettingGetBool(keyName, &bAPReceive) != MSG_SUCCESS)
268                                 MSG_INFO("MsgSettingGetBool() is failed");
269
270                         if (cbMsgOpt.bReceive == false && bAPReceive == false) {
271                                 MSG_DEBUG("CB is off in CP and in AP. No need to send CB request to CP. ");
272                         } else {
273                                 MSG_DEBUG("########  Add CB Option Success !!! #######");
274                                 MSG_SETTING_S cbSetting;
275                                 getCbOpt(&cbSetting, sim_idx);
276                                 setCbConfig(&(cbSetting.option.cbMsgOpt));
277                         }
278                 } else {
279                         MSG_WARN("########  getCbConfig Fail !!! #######");
280                 }
281
282                 /*==================== Default Voice mail Setting ====================*/
283                 if (simStatus[sim_idx] == MSG_SIM_STATUS_CHANGED) {
284                         char keyName[MAX_VCONFKEY_NAME_LEN];
285
286                         MSG_INFO("=================SIM CHANGED===================");
287                         /* reset voicemail number */
288                         memset(keyName, 0x00, sizeof(keyName));
289                         snprintf(keyName, sizeof(keyName), "%s/%d", VOICEMAIL_NUMBER, sim_idx);
290                         if (MsgSettingSetString(keyName, "") != MSG_SUCCESS)
291                                 MSG_DEBUG("MsgSettingSetInt is failed!!");
292
293                         memset(keyName, 0x00, sizeof(keyName));
294                         snprintf(keyName, sizeof(keyName), "%s/%d", VOICEMAIL_COUNT, sim_idx);
295                         if (MsgSettingSetInt(keyName, 0) != MSG_SUCCESS)
296                                 MSG_DEBUG("MsgSettingSetInt is failed!!");
297
298                         memset(keyName, 0x00, sizeof(keyName));
299                         snprintf(keyName, sizeof(keyName), "%s/%d", VOICEMAIL_ALPHA_ID, sim_idx);
300                         if (MsgSettingSetString(keyName, VOICEMAIL_DEFAULT_ALPHA_ID) != MSG_SUCCESS)
301                                 MSG_DEBUG("MsgSettingSetString is failed!!");
302
303                         MsgDeleteNoti(MSG_NOTI_TYPE_VOICE_1, sim_idx);
304                         MsgDeleteNoti(MSG_NOTI_TYPE_VOICE_2, sim_idx);
305                 }
306
307                 /*==================== Voice mail information update ====================*/
308                 if (getVoiceMailInfo(handle) == true) {
309                         MSG_DEBUG("########  getVoiceMailInfo Success !!! #######");
310                         memset(keyName, 0x00, sizeof(keyName));
311                         snprintf(keyName, sizeof(keyName), "%s/%d", VOICEMAIL_NUMBER, sim_idx);
312
313                         char *voiceNumber = NULL;
314                         if (MsgSettingGetString(keyName, &voiceNumber) != MSG_SUCCESS) {
315                                 MSG_INFO("MsgSettingGetString() is failed");
316                         }
317
318                         if (!voiceNumber || (voiceNumber && voiceNumber[0] == '\0')) {
319                                 MSG_WARN("Voice Number is Empty!!");
320                         }
321
322                         if (voiceNumber) {
323                                 free(voiceNumber);
324                                 voiceNumber = NULL;
325                         }
326                 } else {
327                         MSG_WARN("########  getVoiceMailInfo Fail !!! #######");
328                 }
329
330                 /*==================== Voice mail count update ====================*/
331                 if (getMwiInfo(handle) == true) {
332                         MSG_DEBUG("########  getMwiInfo Success !!! #######");
333                 } else {
334                         MSG_WARN("########  getMwiInfo Fail !!! #######");
335
336                         /* Get MWI from vconf and insert notification */
337                         int mwiCnt = 0;
338                         char keyName[MAX_VCONFKEY_NAME_LEN];
339                         memset(keyName, 0x00, sizeof(keyName));
340                         snprintf(keyName, sizeof(keyName), "%s/%d", VOICEMAIL_COUNT, sim_idx);
341                         if (MsgSettingGetInt(keyName, &mwiCnt) != MSG_SUCCESS) {
342                                 MSG_INFO("MsgSettingGetInt() is failed");
343                         }
344                         if (mwiCnt > 0)
345                                 deliverVoiceMsgNoti(sim_idx, mwiCnt);
346                 }
347
348                 /*==================== MSISDN update ====================*/
349                 if (getMsisdnInfo(handle) == true) {
350                         MSG_DEBUG("########  getMsisdnInfo Success !!! #######");
351                 } else {
352                         MSG_WARN("########  getMsisdnInfo Fail !!! #######");
353                 }
354
355                 /*==================== SST(SIM Service Table) update ====================*/
356                 if (getSimServiceTable(handle) == true) {
357                         MSG_DEBUG("########  getSimServiceTable Success !!! #######");
358                 } else {
359                         MSG_WARN("########  getSimServiceTable Fail !!! #######");
360                 }
361         }
362
363         MSG_END();
364 }
365
366
367 void SmsPluginSetting::SimRefreshCb(TapiHandle *handle)
368 {
369         pthread_t thd;
370
371         if (pthread_create(&thd, NULL, &init_config_data, handle) < 0) {
372                 MSG_DEBUG("pthread_create() error");
373         }
374
375         pthread_detach(thd);
376 }
377
378
379 void* SmsPluginSetting::init_config_data(void *data)
380 {
381         TapiHandle *handle = (TapiHandle *)data;
382         instance()->initConfigData(handle);
383         return NULL;
384 }
385
386
387 void SmsPluginSetting::setConfigData(const MSG_SETTING_S *pSetting)
388 {
389         MSG_DEBUG("Setting Type : [%d]", pSetting->type);
390
391         switch (pSetting->type) {
392 #if 0
393         case MSG_SMS_SENDOPT :
394                 setNetworkMode(&pSetting->option.smsSendOpt);
395                 break;
396 #endif
397         case MSG_SMSC_LIST :
398                 setParamList(&pSetting->option.smscList);
399                 addSMSCList((MSG_SMSC_LIST_S *)(&pSetting->option.smscList));
400                 break;
401         case MSG_CBMSG_OPT :
402                 if (setCbConfig(&pSetting->option.cbMsgOpt) == false) {
403                         THROW(MsgException::SMS_PLG_ERROR, "Failed to set config.");
404                 }
405                 break;
406         case MSG_VOICEMAIL_OPT:
407                 setVoiceMailInfo(&pSetting->option.voiceMailOpt);
408                 break;
409         default :
410                 THROW(MsgException::SMS_PLG_ERROR, "The Setting type is not supported. [%d]", pSetting->type);
411                 break;
412         }
413 }
414
415
416 void SmsPluginSetting::getConfigData(MSG_SETTING_S *pSetting)
417 {
418         MSG_DEBUG("Setting Type : [%d]", pSetting->type);
419
420         switch (pSetting->type) {
421         case MSG_SMSC_LIST :
422                 getSmscListInfo(pSetting->option.smscList.simIndex, &(pSetting->option.smscList));
423                 break;
424
425         case MSG_CBMSG_OPT :
426                 if (getCbConfig(&pSetting->option.cbMsgOpt) == false) {
427                         THROW(MsgException::SMS_PLG_ERROR, "Get CB config option failed.");
428                 }
429                 break;
430
431         default :
432                 THROW(MsgException::SMS_PLG_ERROR, "The Setting type is not supported. [%d]", pSetting->type);
433                 break;
434         }
435 }
436
437
438 void SmsPluginSetting::addSMSCList(MSG_SMSC_LIST_S *pSmscList)
439 {
440         MSG_BEGIN();
441
442         int sim_index = -1;
443
444         MSG_DEBUG("SIM index[%d]", pSmscList->simIndex);
445         MSG_DEBUG("total_count[%d]", pSmscList->totalCnt);
446         MSG_DEBUG("selected index[%d]", pSmscList->selected);
447
448         for (int i = 0; i < pSmscList->totalCnt; i++) {
449                 MSG_DEBUG("pid[%d]", pSmscList->smscData[i].pid);
450                 MSG_DEBUG("val_period[%d]", pSmscList->smscData[i].valPeriod);
451                 MSG_SEC_DEBUG("name[%s]", pSmscList->smscData[i].name);
452
453                 MSG_DEBUG("ton[%d]", pSmscList->smscData[i].smscAddr.ton);
454                 MSG_DEBUG("npi[%d]", pSmscList->smscData[i].smscAddr.npi);
455                 MSG_SEC_DEBUG("address[%s]", pSmscList->smscData[i].smscAddr.address);
456         }
457
458         sim_index = pSmscList->simIndex;
459
460         smscListMap::iterator it = smscList.find(pSmscList->simIndex);
461         if (it == smscList.end()) {
462                 pair<int, MSG_SMSC_LIST_S> newList(sim_index, *pSmscList);
463                 smscList.insert(newList);
464         } else {
465                 /* update the list. */
466                 MSG_SMSC_LIST_S &pTmpSmscList = it->second;
467                 pTmpSmscList.simIndex = pSmscList->simIndex;
468                 pTmpSmscList.totalCnt = pSmscList->totalCnt;
469                 pTmpSmscList.selected = pSmscList->selected;
470
471                 for (int i = 0; i < pSmscList->totalCnt; i++) {
472                         pTmpSmscList.smscData[i].pid = pSmscList->smscData[i].pid;
473                         pTmpSmscList.smscData[i].valPeriod = pSmscList->smscData[i].valPeriod;
474                         memset(pTmpSmscList.smscData[i].name, 0x00, SMSC_NAME_MAX+1);
475                         memcpy(pTmpSmscList.smscData[i].name, pSmscList->smscData[i].name, SMSC_NAME_MAX);
476
477                         memset(pTmpSmscList.smscData[i].smscAddr.address, 0x00, SMSC_ADDR_MAX+1);
478                         memcpy(pTmpSmscList.smscData[i].smscAddr.address, pSmscList->smscData[i].smscAddr.address, SMSC_ADDR_MAX);
479
480                         if (pTmpSmscList.smscData[i].smscAddr.address[0] == '+')
481                                 pTmpSmscList.smscData[i].smscAddr.ton = MSG_TON_INTERNATIONAL;
482                         else
483                                 pTmpSmscList.smscData[i].smscAddr.ton = MSG_TON_NATIONAL;
484
485                         pTmpSmscList.smscData[i].smscAddr.npi = MSG_NPI_ISDN; /* app cannot set this value */
486                 }
487         }
488
489         MSG_END();
490 }
491
492
493 void SmsPluginSetting::getSmscListInfo(int simIndex, MSG_SMSC_LIST_S *pSmscList)
494 {
495         if (pSmscList == NULL) {
496                 MSG_DEBUG("pSmscList is NULL!");
497                 return;
498         }
499
500         if (simIndex <= 0) {
501                 TapiHandle *handle = SmsPluginDSHandler::instance()->getTelHandle(simIndex);
502                 simIndex = SmsPluginDSHandler::instance()->getSimIndex(handle);
503         }
504
505         memset(pSmscList, 0x00, sizeof(MSG_SMSC_LIST_S));
506
507         if (simIndex != -1) {
508                 smscListMap::iterator it = smscList.find(simIndex);
509                 if (it != smscList.end()) {
510                         MSG_SMSC_LIST_S &pTmpSmscList = it->second;
511                         memcpy(pSmscList, &pTmpSmscList, sizeof(MSG_SMSC_LIST_S));
512                         MSG_SEC_DEBUG("SMSC number for sim index [%d] is [%s]", pSmscList->simIndex, pSmscList->smscData[pSmscList->selected].smscAddr.address);
513                 }
514         }
515
516         return;
517 }
518
519
520 msg_error_t SmsPluginSetting::addCbOpt(MSG_CBMSG_OPT_S *pCbOpt)
521 {
522         msg_error_t err = MSG_SUCCESS;
523         char keyName[MAX_VCONFKEY_NAME_LEN];
524
525         MSG_DEBUG("Receive [%d], Max SIM Count [%d]", pCbOpt->bReceive, pCbOpt->maxSimCnt);
526
527         MSG_DEBUG("Channel Count [%d]", pCbOpt->channelData.channelCnt);
528
529         for (int i = 0; i < pCbOpt->channelData.channelCnt; i++) {
530                 MSG_DEBUG("Channel FROM [%d], Channel TO [%d]", pCbOpt->channelData.channelInfo[i].from, pCbOpt->channelData.channelInfo[i].to);
531         }
532
533 #if 0
534         /* Set Setting Data into Vconf */
535         memset(keyName, 0x00, sizeof(keyName));
536         snprintf(keyName, sizeof(keyName), "%s/%d", CB_RECEIVE, pCbOpt->simIndex);
537         if (MsgSettingSetBool(keyName, pCbOpt->bReceive) != MSG_SUCCESS) {
538                 MSG_DEBUG("Error to set config data [%s]", keyName);
539                 return MSG_ERR_SET_SETTING;
540         }
541 #endif
542
543         memset(keyName, 0x00, sizeof(keyName));
544         snprintf(keyName, sizeof(keyName), "%s/%d", CB_MAX_SIM_COUNT, pCbOpt->simIndex);
545         if (MsgSettingSetInt(keyName, pCbOpt->maxSimCnt) != MSG_SUCCESS) {
546                 MSG_DEBUG("Error to set config data [%s]", keyName);
547                 return MSG_ERR_SET_SETTING;
548         }
549
550 #if 0
551         MsgDbHandler *dbHandle = getDbHandle();
552         err = MsgStoAddCBChannelInfo(dbHandle, &pCbOpt->channelData);
553         if (err != MSG_SUCCESS) {
554                 MSG_DEBUG("MsgStoGetCBChannelInfo is failed [%d]", err);
555                 return MSG_ERR_SET_SETTING;
556         }
557 #endif
558
559         return err;
560 }
561
562
563 void SmsPluginSetting::getCbOpt(MSG_SETTING_S *pSetting, int simIndex)
564 {
565         char keyName[MAX_VCONFKEY_NAME_LEN];
566
567         msg_error_t err = MSG_SUCCESS;
568         MsgDbHandler *dbHandle = getDbHandle();
569
570         memset(&(pSetting->option.cbMsgOpt), 0x00, sizeof(MSG_CBMSG_OPT_S));
571
572         pSetting->type = MSG_CBMSG_OPT;
573         pSetting->option.cbMsgOpt.simIndex = simIndex;
574
575         memset(keyName, 0x00, sizeof(keyName));
576         snprintf(keyName, sizeof(keyName), "%s/%d", CB_RECEIVE, simIndex);
577         if (MsgSettingGetBool(keyName, &pSetting->option.cbMsgOpt.bReceive) != MSG_SUCCESS)
578                 MSG_INFO("MsgSettingGetBool() is failed");
579
580         memset(keyName, 0x00, sizeof(keyName));
581         snprintf(keyName, sizeof(keyName), "%s/%d", CB_MAX_SIM_COUNT, simIndex);
582         int maxSimCnt = 0;
583         if (MsgSettingGetInt(keyName, &maxSimCnt) != MSG_SUCCESS) {
584                 MSG_INFO("MsgSettingGetInt() is failed");
585         }
586         pSetting->option.cbMsgOpt.maxSimCnt = maxSimCnt;
587
588         err = MsgStoGetCBChannelInfo(dbHandle, &pSetting->option.cbMsgOpt.channelData, simIndex);
589         if (err != MSG_SUCCESS)
590                 MSG_ERR("MsgStoGetCBChannelInfo : err=[%d]", err);
591
592         for (int i = MSG_CBLANG_TYPE_ALL; i < MSG_CBLANG_TYPE_MAX; i++) {
593                 memset(keyName, 0x00, sizeof(keyName));
594                 snprintf(keyName, sizeof(keyName), "%s/%d", CB_LANGUAGE, i);
595
596                 if (MsgSettingGetBool(keyName, &pSetting->option.cbMsgOpt.bLanguage[i]) != MSG_SUCCESS)
597                         MSG_INFO("MsgSettingGetBool() is failed");
598         }
599 }
600
601
602 void SmsPluginSetting::setParamList(const MSG_SMSC_LIST_S *pSMSCList)
603 {
604         MSG_BEGIN();
605
606         MutexLocker lock(mx);
607
608         TelSmsParams_t smsParam = {0};
609
610         int ret = TAPI_API_SUCCESS;
611
612         int index = pSMSCList->index;
613         MSG_DEBUG("SMSC Index to be set in SIM = %d", index);
614
615         /*Setting the SMSP Record index value*/
616         smsParam.RecordIndex = (unsigned char)index;
617
618         /*Setting the SMSP Record Length value = 28 + alphaId_len*/
619         smsParam.RecordLen = 28 + strlen(pSMSCList->smscData[index].name);
620
621         /*Setting the SMSP Alpha ID value*/
622         smsParam.AlphaIdLen = strlen(pSMSCList->smscData[index].name);
623         MSG_DEBUG("AlphaIdLen = %ld", smsParam.AlphaIdLen);
624
625         if (smsParam.AlphaIdLen > 0 &&  smsParam.AlphaIdLen <= SMSC_NAME_MAX) {
626                 memcpy(smsParam.szAlphaId, pSMSCList->smscData[index].name, smsParam.AlphaIdLen);
627                 smsParam.szAlphaId[smsParam.AlphaIdLen] = '\0';
628                 MSG_DEBUG("szAlphaId = %s", smsParam.szAlphaId);
629         }
630
631         smsParam.ParamIndicator = 0x00;
632
633         if (strlen(pSMSCList->smscData[index].smscAddr.address) > 0) {
634                 smsParam.ParamIndicator |= 0x02 ;  /* enable 2nd Bit */
635                 MSG_DEBUG("ParamIndicator = [%02x]", smsParam.ParamIndicator);
636
637                 if (pSMSCList->smscData[index].smscAddr.address[0] == '+')
638                         smsParam.TpSvcCntrAddr.Ton = TAPI_SIM_TON_INTERNATIONAL;
639                 else
640                         smsParam.TpSvcCntrAddr.Ton = TAPI_SIM_TON_NATIONAL;
641
642                 smsParam.TpSvcCntrAddr.Npi = TAPI_SIM_NPI_ISDN_TEL; /* app cannot set this value */
643
644                 MSG_DEBUG("SMSC TON = [%d] NPI = [%d]", smsParam.TpSvcCntrAddr.Ton, smsParam.TpSvcCntrAddr.Npi);
645
646                 MSG_SEC_DEBUG("address = %s", pSMSCList->smscData[index].smscAddr.address);
647
648                 smsParam.TpSvcCntrAddr.DialNumLen = SmsPluginParamCodec::encodeSMSC(pSMSCList->smscData[index].smscAddr.address, smsParam.TpSvcCntrAddr.szDiallingNum);
649         } else {
650                 MSG_DEBUG("SMSC Addr is not present");
651         }
652
653         /*Setting the PID value*/
654         smsParam.ParamIndicator |= 0x04 ;  /* enable 3rd Bit */
655         MSG_DEBUG("ParamIndicator = [%02x]", smsParam.ParamIndicator);
656
657         smsParam.TpProtocolId = (unsigned short)convertPid(pSMSCList->smscData[index].pid);
658
659         /*Setting the ValidityPeriod value*/
660         smsParam.ParamIndicator |= 0x10 ;  /* enable 5th Bit */
661         MSG_DEBUG("ParamIndicator = [%02x]", smsParam.ParamIndicator);
662
663         smsParam.TpValidityPeriod = (unsigned short)pSMSCList->smscData[index].valPeriod;
664
665         smsParam.ParamIndicator = ~(smsParam.ParamIndicator);
666         MSG_DEBUG("ParamIndicator = [%02x]", smsParam.ParamIndicator);
667
668         /* Get TAPI handle */
669         TapiHandle *handle = SmsPluginDSHandler::instance()->getTelHandle(pSMSCList->simIndex);
670
671         ret = tel_set_sms_parameters(handle, (const TelSmsParams_t*)&smsParam, TapiEventSetConfigData, NULL);
672
673         if (ret != TAPI_API_SUCCESS)
674                 THROW(MsgException::SMS_PLG_ERROR, "tel_set_sms_parameters() Error. [%d]", ret);
675
676         if (!getResultFromSim())
677                 THROW(MsgException::SMS_PLG_ERROR, "tel_set_sms_parameters() Result Error.");
678
679         MSG_END();
680 }
681
682
683 void SmsPluginSetting::getParamList(MSG_SMSC_LIST_S *pSMSCList)
684 {
685         MSG_BEGIN();
686
687         int paramCnt = 0;
688
689         MSG_SEC_DEBUG("SIM index [%d]", pSMSCList->simIndex);
690         TapiHandle *handle = SmsPluginDSHandler::instance()->getTelHandle(pSMSCList->simIndex);
691         paramCnt = getParamCount(handle);
692
693         MSG_DEBUG("Parameter Count [%d]", paramCnt);
694
695         int ret = TAPI_API_SUCCESS;
696
697         MSG_SMSC_DATA_S tmpSmscData = {};
698
699         for (int index = 0; index < paramCnt; index++) {
700                 ret = tel_get_sms_parameters(handle, index, TapiEventGetParam, NULL);
701
702                 if (ret == TAPI_API_SUCCESS) {
703                         MSG_DEBUG("######## tel_get_sms_parameters() Success !!! #######");
704                 } else {
705                         THROW(MsgException::SMS_PLG_ERROR, "######## tel_get_sms_parameters() Fail !!! return : %d #######", ret);
706                 }
707
708                 if (getParamEvent(handle, &tmpSmscData) == true) {
709                         MSG_DEBUG("######## Get Parameter was Successful !!! #######");
710
711                         memcpy(&(pSMSCList->smscData[index]), &tmpSmscData, sizeof(MSG_SMSC_DATA_S));
712
713                         MSG_DEBUG("pid[%d]", pSMSCList->smscData[index].pid);
714                         MSG_DEBUG("val_period[%d]", pSMSCList->smscData[index].valPeriod);
715                         MSG_SEC_DEBUG("name[%s]", pSMSCList->smscData[index].name);
716
717                         MSG_DEBUG("ton[%d]", pSMSCList->smscData[index].smscAddr.ton);
718                         MSG_DEBUG("npi[%d]", pSMSCList->smscData[index].smscAddr.npi);
719                         MSG_SEC_DEBUG("address[%s]", pSMSCList->smscData[index].smscAddr.address);
720                 } else {
721                         MSG_DEBUG("######## Get Parameter was Failed !!! #######");
722                 }
723         }
724
725         pSMSCList->totalCnt = paramCnt;
726         pSMSCList->selected = selectedParam;
727
728         MSG_DEBUG("total_count[%d]", pSMSCList->totalCnt);
729
730         MSG_END();
731 }
732
733
734 int SmsPluginSetting::getParamCount(TapiHandle *handle)
735 {
736         int ret = TAPI_API_SUCCESS;
737
738         ret = tel_get_sms_parameter_count(handle, TapiEventGetParamCnt, NULL);
739
740         if (ret == TAPI_API_SUCCESS) {
741                 MSG_DEBUG("######## tel_get_sms_parameter_count() Success !!! #######");
742         } else {
743                 THROW(MsgException::SMS_PLG_ERROR, "tel_get_sms_parameter_count() Error. [%d]", ret);
744         }
745
746         return getParamCntEvent();
747 }
748
749
750 bool SmsPluginSetting::getParam(TapiHandle *handle, int Index, MSG_SMSC_DATA_S *pSmscData)
751 {
752         int ret = TAPI_API_SUCCESS;
753
754         ret = tel_get_sms_parameters(handle, Index, TapiEventGetParam, NULL);
755
756         if (ret == TAPI_API_SUCCESS) {
757                 MSG_DEBUG("######## tel_get_sms_parameters() Success !!! #######");
758         } else {
759                 MSG_ERR("######## tel_get_sms_parameters() Fail !!! return : %d #######", ret);
760                 return false;
761         }
762
763         if (getParamEvent(handle, pSmscData) == true) {
764                 MSG_DEBUG("######## Get Parameter was Successful !!! #######");
765         } else {
766                 MSG_ERR("######## Get Parameter was Failed !!! #######");
767                 return false;
768         }
769
770         return true;
771 }
772
773
774 void SmsPluginSetting::setSmscInfo(const MSG_SMSC_LIST_S *pSmscList)
775 {
776         MSG_BEGIN();
777
778         MutexLocker lock(mx);
779
780         int ret = TAPI_API_SUCCESS;
781
782         TapiHandle *handle = NULL;
783
784         handle = SmsPluginDSHandler::instance()->getTelHandle(pSmscList->simIndex);
785
786         int select_id = pSmscList->selected;
787         const MSG_SMSC_DATA_S *pSmscData = (const MSG_SMSC_DATA_S *)&(pSmscList->smscData[select_id]);
788
789         MSG_DEBUG("Select SMSC id = [%d]", select_id);
790
791         TelSmsAddressInfo_t sca;
792         memset(&sca, 0x00, sizeof(TelSmsAddressInfo_t));
793
794         if (strlen(pSmscData->smscAddr.address) > 0) {
795                 if (pSmscData->smscAddr.address[0] == '+')
796                         sca.Ton = TAPI_SIM_TON_INTERNATIONAL;
797                 else
798                         sca.Ton = TAPI_SIM_TON_NATIONAL;
799
800                 sca.Npi = TAPI_SIM_NPI_ISDN_TEL; /* app cannot set this value */
801
802                 MSG_SEC_DEBUG("SMSC TON = [%d], NPI = [%d], Address = [%s]", sca.Ton, sca.Npi, pSmscData->smscAddr.address);
803
804                 sca.DialNumLen = SmsPluginParamCodec::encodeSMSC(pSmscData->smscAddr.address, sca.szDiallingNum);
805         } else {
806                 MSG_DEBUG("SMSC Addr is not present");
807         }
808
809         ret = tel_set_sms_sca(handle, (const TelSmsAddressInfo_t *)&sca, 0, TapiEventSetSmscInfo, NULL);
810
811         if (ret != TAPI_API_SUCCESS)
812                 THROW(MsgException::SMS_PLG_ERROR, "tel_set_sms_sca() Error. [%d]", ret);
813
814         if (!getResultFromSim())
815                 THROW(MsgException::SMS_PLG_ERROR, "tel_set_sms_sca() Result Error.");
816
817         MSG_END();
818 }
819
820
821 bool SmsPluginSetting::setCbConfig(const MSG_CBMSG_OPT_S *pCbOpt)
822 {
823         TapiHandle *handle = NULL;
824         int simCnt = SmsPluginDSHandler::instance()->getTelHandleCount();
825
826         TelSmsCbConfig_t cbConfig = {};
827
828         int cbEnabled = 0;
829         int ret = TAPI_API_SUCCESS;
830
831         if (pCbOpt->bReceive == true)
832                 cbEnabled = 2;/* Need to get a Enumeration from TAPI, currently it is not available */
833
834         MSG_DEBUG("simIndex:%d, cbEnabled:%d", pCbOpt->simIndex, cbEnabled);
835
836         if (pCbOpt->simIndex == 0) {
837                 char keyName[MAX_VCONFKEY_NAME_LEN];
838                 memset(keyName, 0x00, sizeof(keyName));
839                 MSG_SIM_STATUS_T simStatus = MSG_SIM_STATUS_NOT_FOUND;
840
841                 for (int i = 1; i <= simCnt; i++) {
842                         MutexLocker lock(mx);
843
844                         memset(keyName, 0x00, sizeof(keyName));
845                         snprintf(keyName, sizeof(keyName), "%s/%d", MSG_SIM_CHANGED, i);
846                         int tmpVal = 0;
847                         if (MsgSettingGetInt(keyName, &tmpVal) != MSG_SUCCESS) {
848                                 MSG_INFO("MsgSettingGetInt() is failed");
849                         }
850                         simStatus = (MSG_SIM_STATUS_T)tmpVal;
851
852                         if (simStatus == MSG_SIM_STATUS_NOT_FOUND) {
853                                 MSG_DEBUG("SIM %d is not present..", i);
854                                 continue;
855                         }
856
857                         handle = SmsPluginDSHandler::instance()->getTelHandle(i);
858                         memset(&cbConfig, 0x00, sizeof(TelSmsCbConfig_t));
859                         cbConfig.CBEnabled = cbEnabled;
860                         cbConfig.Net3gppType = TAPI_NETTEXT_NETTYPE_3GPP;
861
862                         /*MSG_SETTING_S cbSetting;
863                         getCbOpt(&cbSetting, i);
864
865                         cbConfig.CBEnabled = (int)pCbOpt->bReceive;
866                         cbConfig.Net3gppType = TAPI_NETTEXT_NETTYPE_3GPP;
867                         cbConfig.MsgIdMaxCount = cbSetting.option.cbMsgOpt.maxSimCnt;
868                         cbConfig.MsgIdRangeCount = cbSetting.option.cbMsgOpt.channelData.channelCnt;
869
870                         for (int i = 0; i < cbConfig.MsgIdRangeCount; i++) {
871                                 cbConfig.MsgIDs[i].Net3gpp.Selected = (unsigned short)cbSetting.option.cbMsgOpt.channelData.channelInfo[i].bActivate;
872                                 cbConfig.MsgIDs[i].Net3gpp.FromMsgId = (unsigned short)cbSetting.option.cbMsgOpt.channelData.channelInfo[i].from;
873                                 cbConfig.MsgIDs[i].Net3gpp.ToMsgId = (unsigned short)cbSetting.option.cbMsgOpt.channelData.channelInfo[i].to;
874                         }*/
875
876                         ret = tel_set_sms_cb_config(handle, &cbConfig, TapiEventSetConfigData, NULL);
877
878                         if (ret == TAPI_API_SUCCESS) {
879                                 MSG_DEBUG("######## tel_set_sms_cb_config() Success !!! #######");
880                         } else {
881                                 MSG_ERR("######## tel_set_sms_cb_config() Fail !!! return : %d #######", ret);
882                                 return false;
883                         }
884
885                         if (getResultFromSim() == true) {
886                                 MSG_DEBUG("######## Set Cb Config was Successful !!! #######");
887                         } else {
888                                 MSG_ERR("######## Set Cb Config was Failed !!! #######");
889                                 return false;
890                         }
891
892                         msg_error_t err = MSG_SUCCESS;
893                         MsgDbHandler *dbHandle = getDbHandle();
894                         err = MsgStoAddCBChannelInfo(dbHandle, const_cast<MSG_CB_CHANNEL_S*>(&pCbOpt->channelData), i);
895                         if (err != MSG_SUCCESS) {
896                                 MSG_DEBUG("MsgStoAddCBChannelInfo is failed [%d]", err);
897                                 return false;
898                         }
899                 }
900
901                 MSG_DEBUG("SIM Index = [0], Set CB Receive is done");
902                 return true;
903         } else {
904                 MutexLocker lock(mx);
905
906                 handle = SmsPluginDSHandler::instance()->getTelHandle(pCbOpt->simIndex);
907
908                 memset(&cbConfig, 0x00, sizeof(TelSmsCbConfig_t));
909                 cbConfig.CBEnabled = cbEnabled;
910                 cbConfig.Net3gppType = TAPI_NETTEXT_NETTYPE_3GPP;
911         /*      cbConfig.CBEnabled = (int)pCbOpt->bReceive;
912                 cbConfig.Net3gppType = TAPI_NETTEXT_NETTYPE_3GPP;
913                 cbConfig.MsgIdMaxCount = pCbOpt->maxSimCnt;
914                 cbConfig.MsgIdRangeCount = pCbOpt->channelData.channelCnt;
915
916                 for (int i = 0; i < cbConfig.MsgIdRangeCount; i++) {
917                         cbConfig.MsgIDs[i].Net3gpp.Selected = (unsigned short)pCbOpt->channelData.channelInfo[i].bActivate;
918                         cbConfig.MsgIDs[i].Net3gpp.FromMsgId = (unsigned short)pCbOpt->channelData.channelInfo[i].from;
919                         cbConfig.MsgIDs[i].Net3gpp.ToMsgId = (unsigned short)pCbOpt->channelData.channelInfo[i].to;
920
921                         MSG_DEBUG("FROM: %d, TO: %d", cbConfig.MsgIDs[i].Net3gpp.FromMsgId, cbConfig.MsgIDs[i].Net3gpp.ToMsgId);
922                 }
923                 MSG_DEBUG("CBEnabled: %d, range_count: %d", cbConfig.CBEnabled, cbConfig.MsgIdRangeCount);*/
924
925                 ret = tel_set_sms_cb_config(handle, &cbConfig, TapiEventSetConfigData, NULL);
926
927                 if (ret == TAPI_API_SUCCESS) {
928                         MSG_DEBUG("######## tel_set_sms_cb_config() Success !!! #######");
929                 } else {
930                         MSG_ERR("######## tel_set_sms_cb_config() Fail !!! return : %d #######", ret);
931                         return false;
932                 }
933
934                 if (getResultFromSim() == true) {
935                         MSG_DEBUG("######## Set Cb Config was Successful !!! #######");
936                 } else {
937                         MSG_ERR("######## Set Cb Config was Failed !!! #######");
938                         return false;
939                 }
940         }
941
942         return true;
943 }
944
945
946 bool SmsPluginSetting::getCbConfig(MSG_CBMSG_OPT_S *pCbOpt)
947 {
948         int ret = TAPI_API_SUCCESS;
949
950         TapiHandle *handle = NULL;
951
952         if (pCbOpt->simIndex == 0) {
953                 MSG_DEBUG("SIM Index for getCBConfig = 0, CANNOT get cbconfig from SIM 0");
954                 return false;
955         }
956
957         handle = SmsPluginDSHandler::instance()->getTelHandle(pCbOpt->simIndex);
958
959         ret = tel_get_sms_cb_config(handle, TapiEventGetCBConfig, NULL);
960
961         if (ret == TAPI_API_SUCCESS) {
962                 MSG_DEBUG("######## tel_get_sms_cb_config() Success !!! #######");
963         } else {
964                 MSG_ERR("######## tel_get_sms_cb_config() Fail !!! return : %d #######", ret);
965                 return false;
966         }
967
968         if (getCbConfigEvent(pCbOpt) == true) {
969                 MSG_DEBUG("######## Get Cb Config was Successful !!! #######");
970         } else {
971                 MSG_ERR("######## Get Cb Config was Failed !!! #######");
972                 return false;
973         }
974
975         return true;
976 }
977
978
979 void SmsPluginSetting::setVoiceMailInfo(const MSG_VOICEMAIL_OPT_S *pVoiceOpt)
980 {
981         MSG_BEGIN();
982         MutexLocker lock(mx);
983
984         int ret = TAPI_API_SUCCESS;
985         bool *bShowError = NULL; /* When invalid voicemail data exists on SIM, update error should not be handled. */
986
987         int simIndex = pVoiceOpt->simIndex;
988
989         if (bMbdnEnable[simIndex] == false) {
990                 MSG_DEBUG("MBDN service is disable.");
991                 return;
992         }
993
994         TelSimMailBoxNumber_t mailboxInfo = {0, };
995         bool bExistVoicetype = false;
996         int i = 0;
997
998         smsSimMailboxListMap::iterator it = simMailboxList.find(simIndex);
999         if (it == simMailboxList.end()) {
1000                 return;
1001         }
1002
1003         SMS_SIM_MAILBOX_LIST_S &pTmpSimMailboxList = it->second;
1004         if (pTmpSimMailboxList.count < 0) { /* Not available */
1005                 return;
1006         }
1007
1008         bShowError = (bool*)calloc(1, sizeof(bool));
1009         if (!bShowError)
1010                 return;
1011
1012         if (pTmpSimMailboxList.count == 0) {
1013                 char num[MAX_PHONE_NUMBER_LEN + 1] = {0, };
1014
1015                 mailboxInfo.mb_type = TAPI_SIM_MAILBOX_VOICE;
1016                 mailboxInfo.rec_index = 1;
1017                 mailboxInfo.ton = TAPI_SIM_TON_UNKNOWN;
1018
1019                 snprintf(num, sizeof(num), "%s", pVoiceOpt->mailNumber);
1020                 MSG_DEBUG("Mailbox number config [%s]", num);
1021
1022                 if (num[0] == '+') {
1023                         snprintf(mailboxInfo.num, sizeof(mailboxInfo.num), "%s", &(num[1]));
1024                         mailboxInfo.ton = TAPI_SIM_TON_INTERNATIONAL;
1025                 } else {
1026                         snprintf(mailboxInfo.num, sizeof(mailboxInfo.num), "%s", num);
1027                 }
1028
1029                 MSG_SEC_DEBUG("Mailbox number to save sim [%s]", mailboxInfo.num);
1030
1031                 *bShowError = false;
1032
1033         } else {
1034                 for (i = 0; i < pTmpSimMailboxList.count; i++) {
1035                         if (pTmpSimMailboxList.list[i].mb_type == TAPI_SIM_MAILBOX_VOICE) {
1036                                 bExistVoicetype = true;
1037                                 break;
1038                         }
1039                 }
1040
1041                 if (bExistVoicetype == false) {
1042                         *bShowError = false;
1043                         /* There is no mailbox information for voicemail type on SIM. */
1044                         for (i = 0; i < pTmpSimMailboxList.count; i++) {
1045                                 if (pTmpSimMailboxList.list[i].mb_type < TAPI_SIM_MAILBOX_VOICE || pTmpSimMailboxList.list[i].mb_type > TAPI_SIM_MAILBOX_OTHER) {
1046                                         pTmpSimMailboxList.list[i].mb_type = TAPI_SIM_MAILBOX_VOICE;
1047                                         break;
1048                                 }
1049                         }
1050                 }
1051
1052                 /* if strlen of voicemail number retrieved from SIM is zero, error is not shown */
1053                 if (pTmpSimMailboxList.list[i].num_len == 0) {
1054                         MSG_DEBUG("In SIM voicemail does not exist");
1055                         *bShowError = false;
1056                 } else if (pTmpSimMailboxList.list[i].num_len > 0) {
1057                         MSG_DEBUG("In SIM voicemail exist");
1058                         *bShowError = true;
1059                 }
1060
1061                 MSG_INFO("bShowError = %d", *bShowError);
1062
1063                 memset(&pTmpSimMailboxList.list[i].num, 0x00, sizeof(pTmpSimMailboxList.list[i].num));
1064                 snprintf(pTmpSimMailboxList.list[i].num, sizeof(pTmpSimMailboxList.list[i].num), "%s", pVoiceOpt->mailNumber);
1065                 MSG_DEBUG("Mailbox number config [%s]", pTmpSimMailboxList.list[i].num);
1066
1067                 mailboxInfo.b_cphs = pTmpSimMailboxList.list[i].b_cphs;
1068                 mailboxInfo.alpha_id_max_len = pTmpSimMailboxList.list[i].alpha_id_max_len;
1069                 mailboxInfo.mb_type = (TelSimMailboxType_t)pTmpSimMailboxList.list[i].mb_type;
1070                 mailboxInfo.profile_num = pTmpSimMailboxList.list[i].profile_num;
1071                 mailboxInfo.rec_index = (pTmpSimMailboxList.list[i].rec_index == 0) ? 1 : pTmpSimMailboxList.list[i].rec_index;
1072                 mailboxInfo.ton = (TelSimTypeOfNum_t)pTmpSimMailboxList.list[i].ton;
1073                 mailboxInfo.npi = (TelSimNumberingPlanIdentity_t)pTmpSimMailboxList.list[i].npi;
1074                 snprintf(mailboxInfo.alpha_id, sizeof(mailboxInfo.alpha_id), "%s", pTmpSimMailboxList.list[i].alpha_id);
1075
1076                 if (pTmpSimMailboxList.list[i].num[0] == '+') {
1077                         snprintf(mailboxInfo.num, sizeof(mailboxInfo.num), "%s", &(pTmpSimMailboxList.list[i].num[1]));
1078                         mailboxInfo.ton = TAPI_SIM_TON_INTERNATIONAL;
1079                 } else {
1080                         snprintf(mailboxInfo.num, sizeof(mailboxInfo.num), "%s", pTmpSimMailboxList.list[i].num);
1081                 }
1082                 MSG_DEBUG("Mailbox number to save sim [%s]", mailboxInfo.num);
1083
1084                 mailboxInfo.cc_id = pTmpSimMailboxList.list[i].cc_id;
1085                 mailboxInfo.ext1_id = pTmpSimMailboxList.list[i].ext1_id;
1086         }
1087
1088         TapiHandle *handle = SmsPluginDSHandler::instance()->getTelHandle(simIndex);
1089
1090         ret = tel_set_sim_mailbox_info(handle, &mailboxInfo, TapiEventSetMailboxInfo, (void*)bShowError);
1091
1092         if (ret == TAPI_API_SUCCESS) {
1093                 MSG_DEBUG("######## tel_set_sim_mailbox_info() Success !!! #######");
1094         } else {
1095                 MSG_ERR("######## tel_set_sim_mailbox_info() Fail !!! return : %d #######", ret);
1096         }
1097
1098         if (getResultFromSim() == true) {
1099                 MSG_DEBUG("######## Set mailbox info Success !!! #######");
1100         } else {
1101                 if (bShowError)
1102                         free(bShowError);
1103                 THROW(MsgException::SMS_PLG_ERROR, "########  Set mailbox info Failed !!!#######");
1104                 MSG_ERR("######## Set mailbox info Failed !!! #######");
1105         }
1106
1107         if (bShowError)
1108                 free(bShowError);
1109
1110         MSG_END();
1111         return;
1112 }
1113
1114
1115 bool SmsPluginSetting::getVoiceMailInfo(TapiHandle *handle)
1116 {
1117         MutexLocker lock(mx);
1118
1119         int ret = TAPI_API_SUCCESS;
1120
1121         ret = tel_get_sim_mailbox_info(handle, TapiEventGetMailboxInfo, NULL);
1122
1123         if (ret == TAPI_API_SUCCESS) {
1124                 MSG_DEBUG("######## tel_get_sim_mailbox_info() Success !!! #######");
1125         } else {
1126                 MSG_ERR("######## tel_get_sim_mailbox_info() Fail !!! return : %d #######", ret);
1127                 return false;
1128         }
1129
1130         if (getMailboxInfoEvent() == true) {
1131                 MSG_DEBUG("######## Get mailbox info was Successful !!! #######");
1132         } else {
1133                 MSG_ERR("######## Get mailbox info was Failed !!! #######");
1134                 return false;
1135         }
1136
1137         return true;
1138 }
1139
1140
1141 void SmsPluginSetting::getMeImei(char *pImei)
1142 {
1143         int ret = TAPI_API_SUCCESS;
1144
1145         TapiHandle *handle = NULL;
1146         handle = SmsPluginDSHandler::instance()->getTelHandle(1);
1147
1148         if (handle == NULL) {
1149                 MSG_DEBUG("Tapi Handle is NULL!");
1150                 return;
1151         }
1152
1153         ret = tel_get_misc_me_imei(handle, TapiEventGetMeImei, NULL);
1154
1155         if (ret == TAPI_API_SUCCESS) {
1156                 MSG_SEC_DEBUG("######## tel_get_misc_me_imei() Success !!! #######");
1157
1158                 if (getResultImei(pImei) == true) {
1159                         MSG_SEC_DEBUG("######## Get ME IMEI was Successful !!! #######");
1160                 } else {
1161                         MSG_SEC_DEBUG("######## Get ME IMEI was Failed !!! #######");
1162                 }
1163         } else {
1164                 MSG_SEC_DEBUG("######## tel_get_misc_me_imei() Fail !!! return : %d #######", ret);
1165         }
1166 }
1167
1168
1169 void SmsPluginSetting::setMwiInfo(int simIndex, MSG_SUB_TYPE_T type, int count)
1170 {
1171         MSG_DEBUG("SET MWI INFO, type=[%d]", type);
1172         MSG_DEBUG("SET MWI INFO, count=[%d]", count);
1173
1174         char keyName[MAX_VCONFKEY_NAME_LEN];
1175
1176         memset(keyName, 0x00, sizeof(keyName));
1177         snprintf(keyName, sizeof(keyName), "%s/%d", VOICEMAIL_COUNT, simIndex);
1178
1179         if (MsgSettingSetInt(keyName, count) != MSG_SUCCESS)
1180                 MSG_DEBUG("MsgSettingSetInt is failed!!");
1181
1182         if (count <= 0) {
1183                 if (type == MSG_MWI_VOICE_SMS)
1184                         MsgDeleteNoti(MSG_NOTI_TYPE_VOICE_1, simIndex);
1185                 else if (type == MSG_MWI_VOICE2_SMS)
1186                         MsgDeleteNoti(MSG_NOTI_TYPE_VOICE_2, simIndex);
1187         }
1188
1189         if (bMbdnEnable[simIndex] == false) {
1190                 MSG_DEBUG("MBDN service is disable.");
1191                 return;
1192         }
1193
1194         int ret = TAPI_API_SUCCESS;
1195         TelSimMessageWaitingReq_t mwReq = {0, };
1196
1197         simMwiInfoMap::iterator iter = simMwiInfo.find(simIndex);
1198         if(iter == simMwiInfo.end()) {
1199                 MSG_DEBUG("IT is not present");
1200                 return;
1201         }
1202
1203         MSG_DEBUG("IT is present");
1204
1205         SMS_SIM_MWI_INFO_S &pTmpsimMwiInfo = iter->second;
1206
1207         MSG_DEBUG("SET MWI INFO, CPHS? [%s]", pTmpsimMwiInfo.b_cphs?"Yes":"No");
1208
1209         if (pTmpsimMwiInfo.b_cphs) {
1210                 MSG_DEBUG("b_cphs is set");
1211                 if (type == MSG_MWI_VOICE_SMS)
1212                         pTmpsimMwiInfo.cphs_mwi.b_voice1 = (count > 0 ? 1:0);
1213                 else if (type == MSG_MWI_VOICE2_SMS)
1214                         pTmpsimMwiInfo.cphs_mwi.b_voice2 = (count > 0 ? 1:0);
1215                 else if (type == MSG_MWI_FAX_SMS)
1216                         pTmpsimMwiInfo.cphs_mwi.b_fax = (count > 0 ? 1:0);
1217                 else {
1218                         MSG_DEBUG("There is no type [%d] in CPHS.", type);
1219                         return;
1220                 }
1221
1222                 mwReq.mw_data_u.cphs_mw.b_voice1 = pTmpsimMwiInfo.cphs_mwi.b_voice1;
1223                 mwReq.mw_data_u.cphs_mw.b_voice2 = pTmpsimMwiInfo.cphs_mwi.b_voice2;
1224                 mwReq.mw_data_u.cphs_mw.b_fax = pTmpsimMwiInfo.cphs_mwi.b_fax;
1225                 mwReq.mw_data_u.cphs_mw.b_data = pTmpsimMwiInfo.cphs_mwi.b_data;
1226
1227                 MSG_DEBUG("MWI voice 1 = [%d]", mwReq.mw_data_u.cphs_mw.b_voice1);
1228                 MSG_DEBUG("MWI voice 2 = [%d]", mwReq.mw_data_u.cphs_mw.b_voice2);
1229                 MSG_DEBUG("MWI fax = [%d]", mwReq.mw_data_u.cphs_mw.b_fax);
1230                 MSG_DEBUG("MWI data = [%d]", mwReq.mw_data_u.cphs_mw.b_data);
1231
1232         } else {
1233                 MSG_DEBUG("b_cphs is not set");
1234
1235                 if (type == MSG_MWI_VOICE_SMS)
1236                         pTmpsimMwiInfo.mwi_list.mw_info[0].voice_count = count;
1237                 else if (type == MSG_MWI_FAX_SMS)
1238                         pTmpsimMwiInfo.mwi_list.mw_info[0].fax_count = count;
1239                 else if (type == MSG_MWI_EMAIL_SMS)
1240                         pTmpsimMwiInfo.mwi_list.mw_info[0].email_count = count;
1241                 else /* MSG_MWI_OTHER_SMS */
1242                         pTmpsimMwiInfo.mwi_list.mw_info[0].other_count = count;
1243
1244                 mwReq.mw_data_u.mw.rec_index = pTmpsimMwiInfo.mwi_list.mw_info[0].rec_index;
1245
1246                 if (count <= 0)
1247                         mwReq.mw_data_u.mw.indicator_status = 0x00;
1248                 else
1249                         mwReq.mw_data_u.mw.indicator_status = 0x01;
1250
1251                 mwReq.mw_data_u.mw.voice_count = pTmpsimMwiInfo.mwi_list.mw_info[0].voice_count;
1252                 mwReq.mw_data_u.mw.fax_count = pTmpsimMwiInfo.mwi_list.mw_info[0].fax_count;
1253                 mwReq.mw_data_u.mw.email_count = pTmpsimMwiInfo.mwi_list.mw_info[0].email_count;
1254                 mwReq.mw_data_u.mw.other_count = pTmpsimMwiInfo.mwi_list.mw_info[0].other_count;
1255                 mwReq.mw_data_u.mw.video_count = pTmpsimMwiInfo.mwi_list.mw_info[0].video_count;
1256
1257                 MSG_DEBUG("MWI record index = [%d]", mwReq.mw_data_u.mw.rec_index);
1258                 MSG_DEBUG("MWI ind status = [%d]", mwReq.mw_data_u.mw.indicator_status);
1259                 MSG_DEBUG("MWI voice = [%d]", mwReq.mw_data_u.mw.voice_count);
1260                 MSG_DEBUG("MWI fax = [%d]", mwReq.mw_data_u.mw.fax_count);
1261                 MSG_DEBUG("MWI email = [%d]", mwReq.mw_data_u.mw.email_count);
1262                 MSG_DEBUG("MWI other = [%d]", mwReq.mw_data_u.mw.other_count);
1263                 MSG_DEBUG("MWI video = [%d]", mwReq.mw_data_u.mw.video_count);
1264         }
1265
1266         mwReq.b_cphs = pTmpsimMwiInfo.b_cphs;
1267
1268         TapiHandle *handle = SmsPluginDSHandler::instance()->getTelHandle(simIndex);
1269
1270         ret = tel_set_sim_messagewaiting_info(handle, &mwReq, TapiEventSetMwiInfo, NULL);
1271
1272         if (ret == TAPI_API_SUCCESS) {
1273                 MSG_DEBUG("######## tel_set_sim_messagewaiting_info() Success !!! #######");
1274         } else {
1275                 MSG_DEBUG("######## tel_set_sim_messagewaiting_info() Fail !!! return : %d #######", ret);
1276         }
1277
1278         return;
1279 }
1280
1281
1282 bool SmsPluginSetting::getMwiInfo(TapiHandle *handle)
1283 {
1284         MutexLocker lock(mx);
1285
1286         int ret = TAPI_API_SUCCESS;
1287
1288         ret = tel_get_sim_messagewaiting_info(handle, TapiEventGetMwiInfo, NULL);
1289
1290         if (ret == TAPI_API_SUCCESS) {
1291                 MSG_DEBUG("######## tel_get_sim_messagewaiting_info() Success !!! #######");
1292         } else {
1293                 MSG_DEBUG("######## tel_get_sim_messagewaiting_info() Fail !!! return : %d #######", ret);
1294                 return false;
1295         }
1296
1297         if (getResultFromSim() == true) {
1298                 MSG_DEBUG("######## Get Mainbox info was Successful !!! #######");
1299         } else {
1300                 MSG_DEBUG("######## Get Mainbox info was Failed !!! #######");
1301                 return false;
1302         }
1303
1304         return true;
1305 }
1306
1307
1308 bool SmsPluginSetting::getMsisdnInfo(TapiHandle *handle)
1309 {
1310         MutexLocker lock(mx);
1311
1312         int ret = TAPI_API_SUCCESS;
1313
1314         ret = tel_get_sim_msisdn(handle, TapiEventGetMsisdnInfo, NULL);
1315
1316         if (ret == TAPI_API_SUCCESS) {
1317                 MSG_DEBUG("######## tel_get_sim_msisdn() Success !!! #######");
1318         } else {
1319                 MSG_DEBUG("######## tel_get_sim_msisdn() Fail !!! return : %d #######", ret);
1320                 return false;
1321         }
1322
1323         if (getResultFromSim() == true) {
1324                 MSG_DEBUG("######## Get Sim msisdn was Successful !!! #######");
1325         } else {
1326                 MSG_DEBUG("######## Get Sim msisdn was Failed !!! #######");
1327                 return false;
1328         }
1329
1330         return true;
1331 }
1332
1333
1334 bool SmsPluginSetting::getSimServiceTable(TapiHandle *handle)
1335 {
1336         MutexLocker lock(mx);
1337
1338         int ret = TAPI_API_SUCCESS;
1339
1340         ret = tel_get_sim_service_table(handle, TapiEventGetSimServiceTable, NULL);
1341
1342         if (ret == TAPI_API_SUCCESS) {
1343                 MSG_DEBUG("######## tel_get_sim_service_table() Success !!! #######");
1344         } else {
1345                 MSG_DEBUG("######## tel_get_sim_service_table() Fail !!! return : %d #######", ret);
1346                 return false;
1347         }
1348
1349         if (getResultFromSim() == true) {
1350                 MSG_DEBUG("######## Get SST info was Successful !!! #######");
1351         } else {
1352                 MSG_DEBUG("######## Get SST info was Failed !!! #######");
1353                 return false;
1354         }
1355
1356         return true;
1357 }
1358
1359
1360 void SmsPluginSetting::setParamCntEvent(int ParamCnt)
1361 {
1362         mx.lock();
1363
1364         paramCnt = ParamCnt;
1365
1366         cv.signal();
1367
1368         mx.unlock();
1369 }
1370
1371
1372 int SmsPluginSetting::getParamCntEvent()
1373 {
1374         int ret = 0;
1375
1376         mx.lock();
1377
1378         ret = cv.timedwait(mx.pMutex(), MAX_TAPI_SIM_API_TIMEOUT);
1379
1380         mx.unlock();
1381
1382         if (ret == ETIMEDOUT) {
1383                 MSG_ERR("WARNING: TAPI callback TIME-OUT");
1384                 return 0;
1385         }
1386
1387         return paramCnt;
1388 }
1389
1390
1391 void SmsPluginSetting::setParamEvent(struct tapi_handle *handle, const MSG_SMSC_DATA_S *pSmscData, int RecordIdx, bool bSuccess)
1392 {
1393         mx.lock();
1394
1395         bTapiResult = bSuccess;
1396
1397         int sim_idx = SmsPluginDSHandler::instance()->getSimIndex(handle);
1398
1399         memset(&smscData[sim_idx], 0x00, sizeof(MSG_SMSC_DATA_S));
1400
1401         if (bTapiResult == true) {
1402                 MSG_DEBUG("Success to get parameter data");
1403
1404                 selectedParam = RecordIdx;
1405
1406                 memcpy(&smscData[sim_idx], pSmscData, sizeof(MSG_SMSC_DATA_S));
1407         }
1408
1409         cv.signal();
1410
1411         mx.unlock();
1412 }
1413
1414
1415 bool SmsPluginSetting::getParamEvent(TapiHandle *handle, MSG_SMSC_DATA_S *pSmscData)
1416 {
1417         int ret = 0;
1418
1419         mx.lock();
1420
1421         bTapiResult = false;
1422         ret = cv.timedwait(mx.pMutex(), MAX_TAPI_SIM_API_TIMEOUT);
1423
1424         mx.unlock();
1425
1426         if (ret == ETIMEDOUT) {
1427                 MSG_DEBUG("WARNING: TAPI callback TIME-OUT");
1428                 return false;
1429         }
1430
1431         memset(pSmscData, 0x00, sizeof(MSG_SMSC_DATA_S));
1432
1433         if (bTapiResult == true) {
1434                 int index = SmsPluginDSHandler::instance()->getSimIndex(handle);
1435                 memcpy(pSmscData, &smscData[index], sizeof(MSG_SMSC_DATA_S));
1436         }
1437
1438         return bTapiResult;
1439 }
1440
1441
1442 void SmsPluginSetting::setCbConfigEvent(TapiHandle *handle, const MSG_CBMSG_OPT_S *pCbOpt, bool bSuccess)
1443 {
1444         MSG_BEGIN();
1445
1446         mx.lock();
1447
1448         char keyName[MAX_VCONFKEY_NAME_LEN];
1449
1450         bTapiResult = bSuccess;
1451
1452         int simIndex = SmsPluginDSHandler::instance()->getSimIndex(handle);
1453
1454         if (bTapiResult == true) {
1455                 MSG_DEBUG("Success to get cb config data");
1456
1457                 pair <int, MSG_CBMSG_OPT_S> newCbOpt(simIndex, *pCbOpt);
1458                 cbOptMap::iterator it = cbOpt.find(simIndex);
1459
1460                 if (it == cbOpt.end()) {
1461                         MSG_DEBUG("IT is not present");
1462                 } else {
1463                         MSG_DEBUG("IT present");
1464                         cbOpt.erase(it);
1465                 }
1466                 cbOpt.insert(newCbOpt);
1467
1468                 memset(keyName, 0x00, sizeof(keyName));
1469                 snprintf(keyName, sizeof(keyName), "%s/%d", CB_MAX_SIM_COUNT, simIndex);
1470                 if (MsgSettingSetInt(keyName, pCbOpt->maxSimCnt) != MSG_SUCCESS) {
1471                         MSG_DEBUG("Error to set config data [%s]", keyName);
1472                 }
1473         } else {
1474                 MSG_DEBUG("Failed to get cb config data");
1475
1476                 cbOptMap::iterator it = cbOpt.find(simIndex);
1477
1478                 if (it == cbOpt.end()) {
1479                         MSG_DEBUG("IT not present");
1480                         MSG_CBMSG_OPT_S pTmpCbOpt;
1481
1482                         memset(&pTmpCbOpt, 0x00, sizeof(MSG_CBMSG_OPT_S));
1483                         pair <int, MSG_CBMSG_OPT_S> newCbOpt(simIndex, pTmpCbOpt);
1484
1485                         cbOpt.insert(newCbOpt);
1486                 }
1487         }
1488
1489         cv.signal();
1490
1491         mx.unlock();
1492         MSG_END();
1493 }
1494
1495
1496 bool SmsPluginSetting::getCbConfigEvent(MSG_CBMSG_OPT_S *pCbOpt)
1497 {
1498         MSG_BEGIN();
1499
1500         int ret = 0;
1501
1502         mx.lock();
1503
1504         bTapiResult = false;
1505         ret = cv.timedwait(mx.pMutex(), MAX_TAPI_SIM_API_TIMEOUT);
1506
1507         mx.unlock();
1508
1509         if (ret == ETIMEDOUT) {
1510                 MSG_DEBUG("WARNING: TAPI callback TIME-OUT");
1511                 return false;
1512         }
1513
1514         int simIndex = pCbOpt->simIndex;
1515
1516         memset(pCbOpt, 0x00, sizeof(MSG_CBMSG_OPT_S));
1517
1518         if (bTapiResult == true) {
1519                 cbOptMap::iterator it = cbOpt.find(simIndex);
1520
1521                 if (it == cbOpt.end()) {
1522                         MSG_DEBUG("IT is not present");
1523                         return false;
1524                 }
1525
1526                 MSG_DEBUG("IT is present");
1527
1528                 MSG_CBMSG_OPT_S &pTmpCbOpt = it->second;
1529                 memcpy(pCbOpt, &pTmpCbOpt, sizeof(MSG_CBMSG_OPT_S));
1530         }
1531
1532         MSG_END();
1533         return bTapiResult;
1534 }
1535
1536
1537 void SmsPluginSetting::setMailboxInfoEvent(TapiHandle *handle, SMS_SIM_MAILBOX_LIST_S *pMailboxList, bool bSuccess, bool bMbdn)
1538 {
1539         MSG_BEGIN();
1540
1541         MSG_DEBUG("bSuccess = %d, bMbdn = %d", bSuccess, bMbdn);
1542         mx.lock();
1543
1544         bTapiResult = bSuccess;
1545
1546         int simIndex = SmsPluginDSHandler::instance()->getSimIndex(handle);
1547
1548         bMbdnEnable[simIndex] = bMbdn;
1549
1550         /* print incoming mailbox list */
1551         if (pMailboxList) {
1552                 MSG_DEBUG("Input list is count = %d ", pMailboxList->count);
1553
1554                 for (int i = 0; i < pMailboxList->count; i++) {
1555                         MSG_DEBUG("List index = %d", i);
1556                         MSG_DEBUG("ton = %d, num = %s, alpha_id = %s", pMailboxList->list[i].ton, pMailboxList->list[i].num, pMailboxList->list[i].alpha_id);
1557                 }
1558         } else {
1559                 MSG_INFO("pMailboxList is NULL");
1560         }
1561
1562         if (bTapiResult == true) {
1563                 int i = 0;
1564                 bool bExistMailboxType = false;
1565                 char keyName[MAX_VCONFKEY_NAME_LEN];
1566
1567                 if (pMailboxList && pMailboxList->count > 0) {
1568                         pair <int, SMS_SIM_MAILBOX_LIST_S> newList(simIndex, *pMailboxList);
1569
1570                         smsSimMailboxListMap::iterator it = simMailboxList.find(simIndex);
1571                         if (it == simMailboxList.end()) {
1572                                 MSG_DEBUG("IT not present !!!");
1573                                 simMailboxList.insert(newList);
1574                         } else {
1575                                 MSG_DEBUG("IT present !!!");
1576                                 simMailboxList.erase(it);
1577                                 simMailboxList.insert(newList);
1578                         }
1579
1580                         /* Temp :: Save voicemail number with VOICE1 line number */
1581                         for (i = 0; i < pMailboxList->count ; i++) {
1582                                 MSG_SEC_DEBUG("Mailbox list[%d] type=[%d]", i, pMailboxList->list[i].mb_type);
1583
1584                                 if (pMailboxList->list[i].mb_type == TAPI_SIM_MAILBOX_VOICE) {
1585                                         bExistMailboxType = true;
1586                                         break;
1587                                 }
1588                         }
1589
1590                         if (bExistMailboxType == false) {
1591                                 MSG_DEBUG("There is no voice mailbox type.");
1592                                 for (i = 0; i < simMailboxList[simIndex].count; i++) {
1593                                         if (pMailboxList->list[i].mb_type < TAPI_SIM_MAILBOX_VOICE || pMailboxList->list[i].mb_type > TAPI_SIM_MAILBOX_OTHER) {
1594                                                 pMailboxList->list[i].mb_type = TAPI_SIM_MAILBOX_VOICE;
1595                                                 break;
1596                                         }
1597                                 }
1598                         }
1599
1600                         smsSimMailboxListMap::iterator iter = simMailboxList.find(simIndex);
1601
1602                         SMS_SIM_MAILBOX_LIST_S &pTmpMailboxList = iter->second;
1603
1604                         char mailNumber[MAX_PHONE_NUMBER_LEN+1];
1605                         memset(mailNumber, 0x00 , sizeof(mailNumber));
1606
1607                         MSG_SEC_DEBUG("Mailbox list[%d] ton=[%d], address=[%s], alpha_id=[%s]", \
1608                                         i, pTmpMailboxList.list[i].ton, pTmpMailboxList.list[i].num, \
1609                                         pTmpMailboxList.list[i].alpha_id);
1610
1611                         if (pTmpMailboxList.list[i].ton == MSG_TON_INTERNATIONAL && pTmpMailboxList.list[i].num[0] != '+') {
1612                                 snprintf(mailNumber, sizeof(mailNumber), "+%s", pTmpMailboxList.list[i].num);
1613                                 MSG_WARN("MSG_TON_INTERNATIONAL [%s]", mailNumber);
1614                         } else {
1615                                 snprintf(mailNumber, sizeof(mailNumber), "%s", pTmpMailboxList.list[i].num);
1616                                 MSG_DEBUG("[%s]", mailNumber);
1617                         }
1618
1619                         if (mailNumber[0] != '\0') {
1620                                 memset(keyName, 0x00, sizeof(keyName));
1621                                 snprintf(keyName, sizeof(keyName), "%s/%d", VOICEMAIL_NUMBER, simIndex);
1622                                 if (MsgSettingSetString(keyName, mailNumber) != MSG_SUCCESS)
1623                                         MSG_DEBUG("MsgSettingSetString is failed!!");
1624                         }
1625
1626                         if (pTmpMailboxList.list[i].alpha_id[0] != '\0') {
1627                                 char unpackAlphaId[MAX_SIM_XDN_ALPHA_ID_LEN+8];
1628                                 int tmpLen = 0;
1629                                 MSG_LANG_INFO_S langInfo = {0, };
1630
1631                                 memset(unpackAlphaId, 0x00, sizeof(unpackAlphaId));
1632
1633                                 langInfo.bSingleShift = false;
1634                                 langInfo.bLockingShift = false;
1635
1636                                 tmpLen = strlen(pTmpMailboxList.list[i].alpha_id);
1637
1638                                 MsgTextConvert *textCvt = MsgTextConvert::instance();
1639                                 textCvt->convertGSM7bitToUTF8((unsigned char*)unpackAlphaId, sizeof(unpackAlphaId), (unsigned char*)pTmpMailboxList.list[i].alpha_id, tmpLen, &langInfo);
1640
1641                                 MSG_DEBUG("UTF8 ALPHA_ID = [%s]", unpackAlphaId);
1642
1643                                 memset(keyName, 0x00, sizeof(keyName));
1644                                 snprintf(keyName, sizeof(keyName), "%s/%d", VOICEMAIL_ALPHA_ID, simIndex);
1645                                 if (MsgSettingSetString(keyName, unpackAlphaId) != MSG_SUCCESS)
1646                                         MSG_DEBUG("MsgSettingSetString is failed!!");
1647                         }
1648                 }
1649         } else {
1650                 /* insert empty list with sim index */
1651                 SMS_SIM_MAILBOX_LIST_S pDummySimMailboxList;
1652
1653                 memset(&pDummySimMailboxList, 0x00, sizeof(SMS_SIM_MAILBOX_LIST_S));
1654                 pair <int, SMS_SIM_MAILBOX_LIST_S> newTmpList(simIndex, pDummySimMailboxList);
1655                 simMailboxList.insert(newTmpList);
1656         }
1657
1658         cv.signal();
1659
1660         mx.unlock();
1661         MSG_END();
1662 }
1663
1664 bool SmsPluginSetting::getMailboxInfoEvent()
1665 {
1666         int ret = 0;
1667
1668         mx.lock();
1669
1670         bTapiResult = false;
1671         ret = cv.timedwait(mx.pMutex(), MAX_TAPI_SIM_API_TIMEOUT);
1672
1673         mx.unlock();
1674
1675         if (ret == ETIMEDOUT) {
1676                 MSG_DEBUG("WARNING: TAPI callback TIME-OUT");
1677                 return false;
1678         }
1679
1680         return bTapiResult;
1681 }
1682
1683 void SmsPluginSetting::setMwiInfoEvent(struct tapi_handle *handle, SMS_SIM_MWI_INFO_S *pMwiInfo, bool bSuccess)
1684 {
1685         MSG_BEGIN();
1686
1687         mx.lock();
1688
1689         bTapiResult = bSuccess;
1690
1691         int index = SmsPluginDSHandler::instance()->getSimIndex(handle);
1692
1693         if (bTapiResult == true) {
1694                 int mwiCnt = 0;
1695                 char keyName[MAX_VCONFKEY_NAME_LEN];
1696
1697                 pair <int, SMS_SIM_MWI_INFO_S> newList(index, *pMwiInfo);
1698                 simMwiInfoMap::iterator it = simMwiInfo.find(index);
1699
1700                 if (it == simMwiInfo.end()) {
1701                         MSG_DEBUG("IT not present");
1702                 } else {
1703                         MSG_DEBUG("IT present");
1704                         simMwiInfo.erase(it);
1705                 }
1706                 simMwiInfo.insert(newList);
1707
1708                 simMwiInfoMap::iterator iter = simMwiInfo.find(index);
1709
1710                 SMS_SIM_MWI_INFO_S &pTmpsimMwiInfoList = iter->second;
1711
1712                 /* Save MW count with VOICE line1 number */
1713                 if (pTmpsimMwiInfoList.b_cphs == true) {
1714                         mwiCnt = pTmpsimMwiInfoList.cphs_mwi.b_voice1;
1715                 } else {
1716                         mwiCnt = pTmpsimMwiInfoList.mwi_list.mw_info[0].voice_count;
1717                 }
1718                 /* TODO :: Add operation for voice mail of line 2 */
1719
1720                 memset(keyName, 0x00, sizeof(keyName));
1721                 snprintf(keyName, sizeof(keyName), "%s/%d", VOICEMAIL_COUNT, index);
1722                 if (MsgSettingSetInt(keyName, mwiCnt) != MSG_SUCCESS)
1723                         MSG_DEBUG("MsgSettingSetInt is failed!!");
1724
1725                 MSG_DEBUG("MWI count = [%d]", mwiCnt);
1726
1727                 if (mwiCnt > 0) {
1728                         deliverVoiceMsgNoti(index, mwiCnt);
1729                 }
1730         } else {
1731                 SMS_SIM_MWI_INFO_S pTmpsimMwiInfo;
1732
1733                 memset(&pTmpsimMwiInfo, 0x00, sizeof(SMS_SIM_MWI_INFO_S));
1734
1735                 pair <int, SMS_SIM_MWI_INFO_S> newList(index, pTmpsimMwiInfo);
1736                 simMwiInfoMap::iterator it = simMwiInfo.find(index);
1737
1738                 if (it == simMwiInfo.end()) {
1739                         MSG_DEBUG("IT not present");
1740                 } else {
1741                         MSG_DEBUG("IT present");
1742                         simMwiInfo.erase(it);
1743                 }
1744                 simMwiInfo.insert(newList);
1745         }
1746
1747         cv.signal();
1748
1749         mx.unlock();
1750
1751         MSG_END();
1752 }
1753
1754
1755 void SmsPluginSetting::setResultImei(bool bResult, char *pImei)
1756 {
1757         mx.lock();
1758
1759         bTapiResult = bResult;
1760
1761         memset(&meImei, 0x00, sizeof(meImei));
1762
1763         if (bTapiResult == true && pImei) {
1764                 snprintf(meImei, sizeof(meImei), "%s", pImei);
1765         }
1766
1767         cv.signal();
1768
1769         mx.unlock();
1770 }
1771
1772
1773 bool SmsPluginSetting::getResultImei(char *pImei)
1774 {
1775         int ret = 0;
1776
1777         mx.lock();
1778
1779         ret = cv.timedwait(mx.pMutex(), MAX_TAPI_SIM_API_TIMEOUT);
1780
1781         mx.unlock();
1782
1783         if (ret == ETIMEDOUT) {
1784                 MSG_DEBUG("WARNING: TAPI callback TIME-OUT");
1785                 return false;
1786         }
1787
1788         if (bTapiResult == true && pImei) {
1789                 snprintf(pImei, sizeof(meImei), "%s", meImei);
1790         }
1791
1792         return bTapiResult;
1793 }
1794
1795
1796 void SmsPluginSetting::setResultFromSim(bool bResult)
1797 {
1798         mx.lock();
1799
1800         bTapiResult = bResult;
1801
1802         cv.signal();
1803
1804         mx.unlock();
1805 }
1806
1807
1808 bool SmsPluginSetting::getResultFromSim()
1809 {
1810         int ret = 0;
1811
1812         MSG_DEBUG("getResultFromSim() is called .");
1813
1814         ret = cv.timedwait(mx.pMutex(), MAX_TAPI_SIM_API_TIMEOUT);
1815
1816         if (ret == ETIMEDOUT) {
1817                 MSG_DEBUG("WARNING: TAPI callback TIME-OUT");
1818                 return false;
1819         }
1820
1821         return bTapiResult;
1822 }
1823
1824
1825 SMS_PID_T SmsPluginSetting::convertPid(MSG_SMS_PID_T pid)
1826 {
1827         SMS_PID_T retPid;
1828
1829         switch (pid) {
1830         case MSG_PID_TEXT :
1831                 retPid = SMS_PID_NORMAL;
1832                 break;
1833         case MSG_PID_VOICE :
1834                 retPid = SMS_PID_VOICE;
1835                 break;
1836         case MSG_PID_FAX :
1837                 retPid = SMS_PID_TELEX;
1838                 break;
1839         case MSG_PID_X400 :
1840                 retPid = SMS_PID_x400;
1841                 break;
1842         case MSG_PID_ERMES :
1843                 retPid = SMS_PID_ERMES;
1844                 break;
1845         case MSG_PID_EMAIL :
1846                 retPid = SMS_PID_EMAIL;
1847                 break;
1848         default :
1849                 retPid = SMS_PID_NORMAL;
1850                 break;
1851         }
1852
1853         return retPid;
1854 }
1855
1856
1857 void SmsPluginSetting::deliverVoiceMsgNoti(int simIndex, int mwiCnt)
1858 {
1859         MSG_BEGIN();
1860
1861         MSG_MESSAGE_INFO_S msgInfo = {0, };
1862
1863         msgInfo.addressList = NULL;
1864         unique_ptr<MSG_ADDRESS_INFO_S*, void(*)(MSG_ADDRESS_INFO_S**)> addressListBuf(&msgInfo.addressList, unique_ptr_deleter);
1865
1866         msgInfo.addressList = (MSG_ADDRESS_INFO_S *)new char[sizeof(MSG_ADDRESS_INFO_S)];
1867         memset(msgInfo.addressList, 0x00, sizeof(MSG_ADDRESS_INFO_S));
1868
1869         msgInfo.nAddressCnt = 1;
1870
1871         msgInfo.displayTime = time(NULL);
1872
1873         char keyName[MAX_VCONFKEY_NAME_LEN];
1874         char *voiceNum = NULL;
1875         memset(keyName, 0x00, sizeof(keyName));
1876         snprintf(keyName, sizeof(keyName), "%s/%d", VOICEMAIL_NUMBER, simIndex);
1877         if (MsgSettingGetString(keyName, &voiceNum) != MSG_SUCCESS) {
1878                 MSG_INFO("MsgSettingGetString() is failed");
1879         }
1880
1881         if (voiceNum) {
1882                 snprintf(msgInfo.addressList[0].addressVal, sizeof(msgInfo.addressList[0].addressVal), "%s", voiceNum);
1883                 free(voiceNum);
1884                 voiceNum = NULL;
1885         }
1886         memset(msgInfo.addressList[0].displayName, 0x00, sizeof(msgInfo.addressList[0].displayName));
1887         msgInfo.msgType.mainType = MSG_SMS_TYPE;
1888         msgInfo.msgType.subType = MSG_MWI_VOICE_SMS;
1889         msgInfo.sim_idx = simIndex;
1890
1891 #if 0
1892         if (simMwiInfo.b_cphs == false) {
1893                 snprintf(msgInfo.msgText, sizeof(msgInfo.msgText), "%d new voice message", mwiCnt);
1894         } else {
1895                 snprintf(msgInfo.msgText, sizeof(msgInfo.msgText), "New voice message");
1896         }
1897 #else
1898         snprintf(msgInfo.msgText, sizeof(msgInfo.msgText), "%d", mwiCnt);
1899 #endif
1900
1901 #if 0
1902         if (SmsPluginEventHandler::instance()->callbackMsgIncoming(&msgInfo) != MSG_SUCCESS)
1903                 MSG_DEBUG("callbackIncoming is failed.");
1904 #else
1905         MsgInsertNotification(&msgInfo);
1906         if (MsgCheckNotificationSettingEnable())
1907                 MsgChangePmState();
1908 #endif
1909
1910         MSG_END();
1911 }
1912
1913
1914 void SmsPluginSetting::setSimChangeStatus(TapiHandle *handle, bool bInitializing)
1915 {
1916         MSG_BEGIN();
1917
1918         int tapiRet = TAPI_API_SUCCESS;
1919         TelSimCardStatus_t status = TAPI_SIM_STATUS_CARD_ERROR;
1920
1921         int cardChanged = 0;
1922         int simIndex = SmsPluginDSHandler::instance()->getSimIndex(handle);
1923
1924         pthread_t thd;
1925         char keyName[MAX_VCONFKEY_NAME_LEN] = {0, };
1926
1927         tapiRet = tel_get_sim_init_info(handle, &status, &cardChanged);
1928         MSG_INFO("Tapi Ret=[%d], SIM index [%d], SIM status [%d], CardChanged [%d]", tapiRet, simIndex, status, cardChanged);
1929
1930         if (status == TAPI_SIM_STATUS_SIM_INIT_COMPLETED) {
1931                 if (simStatus[simIndex] == MSG_SIM_STATUS_NOT_FOUND) {
1932                         if (cardChanged == 1) {
1933                                 snprintf(keyName, sizeof(keyName), "%s/%d", MSG_SIM_CHANGED, simIndex);
1934                                 MsgSettingSetInt(keyName, MSG_SIM_STATUS_CHANGED);
1935                                 simStatus[simIndex] = MSG_SIM_STATUS_CHANGED;
1936                         } else {
1937                                 snprintf(keyName, sizeof(keyName), "%s/%d", MSG_SIM_CHANGED, simIndex);
1938                                 MsgSettingSetInt(keyName, MSG_SIM_STATUS_NORMAL);
1939                                 simStatus[simIndex] = MSG_SIM_STATUS_NORMAL;
1940                         }
1941
1942                         /* Modified to call initSimInfo for SIM separately */
1943                         MSG_DEBUG("calling initSimInfo");
1944                         if (pthread_create(&thd, NULL, &initSimInfo, handle) < 0) {
1945                                 MSG_DEBUG("pthread_create() error");
1946                         }
1947                         pthread_detach(thd);
1948
1949                 } else {
1950                         MSG_DEBUG("SIM init was already done!");
1951                 }
1952         } else {
1953                 MSG_DEBUG("It doesn't initialize yet!!");
1954                 snprintf(keyName, sizeof(keyName), "%s/%d", MSG_SIM_CHANGED, simIndex);
1955                 MSG_DEBUG("Set MSG_SIM_CHANGED to MSG_SIM_STATUS_NOT_FOUND");
1956                 if (MsgSettingSetInt(keyName, MSG_SIM_STATUS_NOT_FOUND) != MSG_SUCCESS)
1957                         MSG_DEBUG("Fail to set MSG_SIM_CHANGED to MSG_SIM_STATUS_NOT_FOUND");
1958
1959                 simStatus[simIndex] = MSG_SIM_STATUS_NOT_FOUND;
1960         }
1961
1962         MSG_END();
1963 }