svace issues fixed
[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 "MsgContact.h"
26 #include "MsgUtilStorage.h"
27 #include "MsgTextConvert.h"
28 #include "MsgDevicedWrapper.h"
29
30 #include "SmsPluginParamCodec.h"
31 #include "SmsPluginCallback.h"
32 #include "SmsPluginEventHandler.h"
33 #include "SmsPluginSimMsg.h"
34 #include "SmsPluginMain.h"
35 #include "SmsPluginSetting.h"
36 #include "SmsPluginDSHandler.h"
37
38 extern "C" {
39         #include <tapi_common.h>
40         #include <TelSms.h>
41         #include <TapiUtility.h>
42         #include <ITapiNetText.h>
43         #include <ITapiSim.h>
44         #include <ITapiModem.h>
45 }
46
47 /*==================================================================================================
48                                   INTERNAL FUNCTION
49 ==================================================================================================*/
50
51
52 /*==================================================================================================
53                    IMPLEMENTATION OF SmsPluginSetting - Member Functions
54 ==================================================================================================*/
55 SmsPluginSetting* SmsPluginSetting::pInstance = NULL;
56
57
58 SmsPluginSetting::SmsPluginSetting()
59 {
60         /* Initialize member variables */
61         for (int i = 0; i <= MAX_TELEPHONY_HANDLE_CNT; i++) {
62                 memset(&smscData[i], 0x00, sizeof(MSG_SMSC_DATA_S));
63                 simStatus[i] = MSG_SIM_STATUS_NOT_FOUND;
64         }
65         smscList.clear();
66         simMailboxList.clear();
67         simMwiInfo.clear();
68         cbOpt.clear();
69         memset(&meImei, 0x00, sizeof(meImei));
70
71         bTapiResult = false;
72         paramCnt = 0;
73         selectedParam = 0;
74         selectedSimIndex = 0;
75
76         for (int i = 0; i < MAX_TELEPHONY_HANDLE_CNT; i++)
77                 bMbdnEnable[i] = false;
78 }
79
80
81 SmsPluginSetting::~SmsPluginSetting()
82 {
83         smscList.erase(smscList.begin(), smscList.end());
84         simMailboxList.erase(simMailboxList.begin(), simMailboxList.end());
85         simMwiInfo.erase(simMwiInfo.begin(), simMwiInfo.end());
86         cbOpt.erase(cbOpt.begin(), cbOpt.end());
87 }
88
89
90 SmsPluginSetting* SmsPluginSetting::instance()
91 {
92         if (!pInstance)
93                 pInstance = new SmsPluginSetting();
94
95         return pInstance;
96 }
97
98
99 void* SmsPluginSetting::initSimInfo(void *data)
100 {
101         static MsgMutex mm;
102         MsgMutexLocker lock(mm);
103
104         instance()->processInitSimInfo(data);
105
106         return NULL;
107 }
108
109 void* SmsPluginSetting::processInitSimInfo(void *data)
110 {
111         MSG_BEGIN();
112
113         /* Handle sim info initialization separately */
114         TapiHandle *handle = (TapiHandle *)data;
115         instance()->updateSimStatus(handle);
116
117         MSG_END();
118         return NULL;
119 }
120
121
122 void SmsPluginSetting::updateSimStatus(TapiHandle *handle)
123 {
124         MSG_BEGIN();
125
126         if (!handle) {
127                 MSG_DEBUG("handle is NULL.");
128                 return;
129         }
130
131         int status = 0;
132         int tapiRet = TAPI_API_SUCCESS;
133
134         char keyName[MAX_VCONFKEY_NAME_LEN];
135         memset(keyName, 0x00, sizeof(keyName));
136
137         int simIndex = SmsPluginDSHandler::instance()->getSimIndex(handle);
138
139         /* Get IMSI */
140         TelSimImsiInfo_t imsiInfo;
141         memset(&imsiInfo, 0x00, sizeof(TelSimImsiInfo_t));
142
143         tapiRet = tel_get_sim_imsi(handle, &imsiInfo);
144         if (tapiRet != TAPI_API_SUCCESS) {
145                 MSG_SEC_DEBUG("tel_get_sim_imsi() Error![%d]", tapiRet);
146         }
147
148         /* Save Subcriber ID */
149         char *subscriberId = NULL;
150         memset(keyName, 0x00, sizeof(keyName));
151
152         if (SmsPluginDSHandler::instance()->getSubscriberId(simIndex, &subscriberId) != MSG_SUCCESS) {
153                 MSG_DEBUG("getSubscriberId() is failed");
154         } else {
155                 snprintf(keyName, sizeof(keyName), "%s/%d", MSG_SIM_SUBS_ID, simIndex);
156                 if (MsgSettingSetString(keyName, subscriberId) != MSG_SUCCESS)
157                         MSG_DEBUG("Fail MsgSettingSetString");
158         }
159
160         g_free(subscriberId); subscriberId = NULL;
161
162         /* Check device status */
163         tapiRet = tel_check_sms_device_status(handle, &status);
164
165         if (tapiRet != TAPI_API_SUCCESS) {
166                 MSG_DEBUG("tel_check_sms_device_status() Error! [%d], Status [%d]", tapiRet, status);
167                 return;
168         }
169
170         if (status == TAPI_NETTEXT_READY_STATUS_3GPP) {
171                 MSG_DEBUG("Device Is Ready");
172         } else {
173                 MSG_DEBUG("Device Is Not Ready.. Waiting For Ready Callback");
174
175                 if (SmsPluginEventHandler::instance()->getDeviceStatus(handle) == true) {
176                         MSG_DEBUG("Device Is Ready");
177                 } else {
178                         MSG_DEBUG("Device Is Not Ready.");
179                         return;
180                 }
181         }
182
183         /* init config data. */
184         initConfigData(handle);
185
186         try {
187                 /* init sim messages. */
188                 SmsPluginSimMsg::instance()->initSimMessage(handle);
189         } catch (MsgException& e) {
190                 MSG_FATAL("%s", e.what());
191                 return;
192         }
193
194
195         MSG_END();
196
197         return;
198 }
199
200
201 void SmsPluginSetting::initConfigData(TapiHandle *handle)
202 {
203         MSG_BEGIN();
204
205         char keyName[MAX_VCONFKEY_NAME_LEN];
206
207         int sim_idx = SmsPluginDSHandler::instance()->getSimIndex(handle);
208         /*==================== SMSC setting ====================*/
209         /* Init SMS Parameter */
210         int paramCnt = 0;
211         int failCnt = 0;
212         bool bSelectedFound = false;
213         bool bAPReceive = false;
214
215         paramCnt = getParamCount(handle);
216
217         MSG_INFO("Parameter Count [%d]", paramCnt);
218
219         MSG_SMSC_DATA_S tmpSmscData = {};
220         MSG_SMSC_LIST_S tmpSmscList = {0, };
221
222         for (int index = 0; index < paramCnt; index++) {
223                 memset(&tmpSmscData, 0x00, sizeof(MSG_SMSC_DATA_S));
224                 if (getParam(handle, index, &tmpSmscData) == false) {
225                         failCnt++;
226                         continue;
227                 }
228
229                 memcpy(&(tmpSmscList.smscData[index]), &tmpSmscData, sizeof(MSG_SMSC_DATA_S));
230
231                 MSG_DEBUG("pid[%d]", tmpSmscList.smscData[index].pid);
232                 MSG_DEBUG("val_period[%d]", tmpSmscList.smscData[index].valPeriod);
233                 MSG_SEC_DEBUG("name[%s]", tmpSmscList.smscData[index].name);
234
235                 MSG_DEBUG("ton[%d]", tmpSmscList.smscData[index].smscAddr.ton);
236                 MSG_DEBUG("npi[%d]", tmpSmscList.smscData[index].smscAddr.npi);
237                 MSG_SEC_DEBUG("address[%s]", tmpSmscList.smscData[index].smscAddr.address);
238
239                 /* First smsc is selected index */
240                 if (!bSelectedFound) {
241                         tmpSmscList.selected = selectedParam;
242                         bSelectedFound = !bSelectedFound;
243                 }
244         }
245
246         tmpSmscList.totalCnt = (paramCnt - failCnt);
247         tmpSmscList.simIndex = sim_idx;
248
249         if (paramCnt > 0) {
250                 MSG_DEBUG("########  Add SMSC ist #######");
251                 addSMSCList(&tmpSmscList);
252         }
253
254         /*==================== CB configuration ====================*/
255         if (simStatus[sim_idx] != MSG_SIM_STATUS_NOT_FOUND) {
256                 MSG_DEBUG("simStatus == [%d]", simStatus[sim_idx]);
257
258                 MSG_CBMSG_OPT_S cbMsgOpt = {0, };
259                 cbMsgOpt.simIndex = sim_idx;
260
261                 if (getCbConfig(&cbMsgOpt) == true) {
262                         cbMsgOpt.simIndex = sim_idx;
263
264                         memset(keyName, 0x00, sizeof(keyName));
265                         snprintf(keyName, sizeof(keyName), "%s/%d", CB_RECEIVE, sim_idx);
266                         if (MsgSettingGetBool(keyName, &bAPReceive) != MSG_SUCCESS)
267                                 MSG_INFO("MsgSettingGetBool() is failed");
268
269                         if (cbMsgOpt.bReceive == false && bAPReceive == false) {
270                                 MSG_DEBUG("CB is off in CP and in AP. No need to send CB request to CP. ");
271                         } else {
272                                 MSG_DEBUG("########  Add CB Option Success !!! #######");
273                                 MSG_SETTING_S cbSetting;
274                                 getCbOpt(&cbSetting, sim_idx);
275                                 setCbConfig(&(cbSetting.option.cbMsgOpt));
276                         }
277                 } else {
278                         MSG_WARN("########  getCbConfig Fail !!! #######");
279                 }
280
281                 /*==================== Default Voice mail Setting ====================*/
282                 if (simStatus[sim_idx] == MSG_SIM_STATUS_CHANGED) {
283                         char keyName[MAX_VCONFKEY_NAME_LEN];
284
285                         MSG_INFO("=================SIM CHANGED===================");
286                         /* reset voicemail number */
287                         memset(keyName, 0x00, sizeof(keyName));
288                         snprintf(keyName, sizeof(keyName), "%s/%d", VOICEMAIL_NUMBER, sim_idx);
289                         if (MsgSettingSetString(keyName, "") != MSG_SUCCESS)
290                                 MSG_DEBUG("MsgSettingSetString is failed!!");
291
292                         memset(keyName, 0x00, sizeof(keyName));
293                         snprintf(keyName, sizeof(keyName), "%s/%d", VOICEMAIL_COUNT, sim_idx);
294                         if (MsgSettingSetInt(keyName, 0) != MSG_SUCCESS)
295                                 MSG_DEBUG("MsgSettingSetInt is failed!!");
296
297                         memset(keyName, 0x00, sizeof(keyName));
298                         snprintf(keyName, sizeof(keyName), "%s/%d", VOICEMAIL_ALPHA_ID, sim_idx);
299                         if (MsgSettingSetString(keyName, VOICEMAIL_DEFAULT_ALPHA_ID) != MSG_SUCCESS)
300                                 MSG_DEBUG("MsgSettingSetString is failed!!");
301
302                         MsgDeleteNoti(MSG_NOTI_TYPE_VOICE_1, sim_idx);
303                         MsgDeleteNoti(MSG_NOTI_TYPE_VOICE_2, sim_idx);
304                 }
305
306                 /*==================== Voice mail information update ====================*/
307                 if (getVoiceMailInfo(handle) == true) {
308                         MSG_DEBUG("########  getVoiceMailInfo Success !!! #######");
309                         memset(keyName, 0x00, sizeof(keyName));
310                         snprintf(keyName, sizeof(keyName), "%s/%d", VOICEMAIL_NUMBER, sim_idx);
311
312                         char *voiceNumber = NULL;
313                         if (MsgSettingGetString(keyName, &voiceNumber) != MSG_SUCCESS) {
314                                 MSG_INFO("MsgSettingGetString() is failed");
315                         }
316
317                         if (!voiceNumber || (voiceNumber && voiceNumber[0] == '\0')) {
318                                 MSG_WARN("Voice Number is Empty!!");
319                         }
320
321                         if (voiceNumber) {
322                                 free(voiceNumber);
323                                 voiceNumber = NULL;
324                         }
325                 } else {
326                         MSG_WARN("########  getVoiceMailInfo Fail !!! #######");
327                 }
328
329                 /*==================== Voice mail count update ====================*/
330                 if (getMwiInfo(handle) == true) {
331                         MSG_DEBUG("########  getMwiInfo Success !!! #######");
332                 } else {
333                         MSG_WARN("########  getMwiInfo Fail !!! #######");
334
335                         /* Get MWI from vconf and insert notification */
336                         int mwiCnt = 0;
337                         char keyName[MAX_VCONFKEY_NAME_LEN];
338                         memset(keyName, 0x00, sizeof(keyName));
339                         snprintf(keyName, sizeof(keyName), "%s/%d", VOICEMAIL_COUNT, sim_idx);
340                         if (MsgSettingGetInt(keyName, &mwiCnt) != MSG_SUCCESS) {
341                                 MSG_INFO("MsgSettingGetInt() is failed");
342                         }
343                         if (mwiCnt > 0)
344                                 deliverVoiceMsgNoti(sim_idx, mwiCnt);
345                 }
346
347                 /*==================== MSISDN update ====================*/
348                 if (getMsisdnInfo(handle) == true) {
349                         MSG_DEBUG("########  getMsisdnInfo Success !!! #######");
350                 } else {
351                         MSG_WARN("########  getMsisdnInfo Fail !!! #######");
352                 }
353
354                 /*==================== SST(SIM Service Table) update ====================*/
355                 if (getSimServiceTable(handle) == true) {
356                         MSG_DEBUG("########  getSimServiceTable Success !!! #######");
357                 } else {
358                         MSG_WARN("########  getSimServiceTable Fail !!! #######");
359                 }
360         }
361
362         MSG_END();
363 }
364
365
366 void SmsPluginSetting::SimRefreshCb(TapiHandle *handle)
367 {
368         pthread_t thd;
369
370         if (pthread_create(&thd, NULL, &init_config_data, handle) < 0) {
371                 MSG_ERR("pthread_create() error");
372                 return;
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         MsgMutexLocker 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         MsgMutexLocker 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                         MsgMutexLocker 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                 MsgMutexLocker 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         MsgMutexLocker 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         MsgMutexLocker 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         MsgMutexLocker 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         MsgMutexLocker 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         MsgMutexLocker 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.pMsgMutex(), 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.pMsgMutex(), 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.pMsgMutex(), 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         ret = cv.timedwait(mx.pMsgMutex(), MAX_TAPI_SIM_API_TIMEOUT);
1669
1670         if (ret == ETIMEDOUT) {
1671                 MSG_DEBUG("WARNING: TAPI callback TIME-OUT");
1672                 return false;
1673         }
1674
1675         return bTapiResult;
1676 }
1677
1678 void SmsPluginSetting::setMwiInfoEvent(struct tapi_handle *handle, SMS_SIM_MWI_INFO_S *pMwiInfo, bool bSuccess)
1679 {
1680         MSG_BEGIN();
1681
1682         mx.lock();
1683
1684         bTapiResult = bSuccess;
1685
1686         int index = SmsPluginDSHandler::instance()->getSimIndex(handle);
1687
1688         if (bTapiResult == true) {
1689                 int mwiCnt = 0;
1690                 char keyName[MAX_VCONFKEY_NAME_LEN];
1691
1692                 pair <int, SMS_SIM_MWI_INFO_S> newList(index, *pMwiInfo);
1693                 simMwiInfoMap::iterator it = simMwiInfo.find(index);
1694
1695                 if (it == simMwiInfo.end()) {
1696                         MSG_DEBUG("IT not present");
1697                 } else {
1698                         MSG_DEBUG("IT present");
1699                         simMwiInfo.erase(it);
1700                 }
1701                 simMwiInfo.insert(newList);
1702
1703                 simMwiInfoMap::iterator iter = simMwiInfo.find(index);
1704
1705                 SMS_SIM_MWI_INFO_S &pTmpsimMwiInfoList = iter->second;
1706
1707                 /* Save MW count with VOICE line1 number */
1708                 if (pTmpsimMwiInfoList.b_cphs == true) {
1709                         mwiCnt = pTmpsimMwiInfoList.cphs_mwi.b_voice1;
1710                 } else {
1711                         mwiCnt = pTmpsimMwiInfoList.mwi_list.mw_info[0].voice_count;
1712                 }
1713                 /* TODO :: Add operation for voice mail of line 2 */
1714
1715                 memset(keyName, 0x00, sizeof(keyName));
1716                 snprintf(keyName, sizeof(keyName), "%s/%d", VOICEMAIL_COUNT, index);
1717                 if (MsgSettingSetInt(keyName, mwiCnt) != MSG_SUCCESS)
1718                         MSG_DEBUG("MsgSettingSetInt is failed!!");
1719
1720                 MSG_DEBUG("MWI count = [%d]", mwiCnt);
1721
1722                 if (mwiCnt > 0) {
1723                         deliverVoiceMsgNoti(index, mwiCnt);
1724                 }
1725         } else {
1726                 SMS_SIM_MWI_INFO_S pTmpsimMwiInfo;
1727
1728                 memset(&pTmpsimMwiInfo, 0x00, sizeof(SMS_SIM_MWI_INFO_S));
1729
1730                 pair <int, SMS_SIM_MWI_INFO_S> newList(index, pTmpsimMwiInfo);
1731                 simMwiInfoMap::iterator it = simMwiInfo.find(index);
1732
1733                 if (it == simMwiInfo.end()) {
1734                         MSG_DEBUG("IT not present");
1735                 } else {
1736                         MSG_DEBUG("IT present");
1737                         simMwiInfo.erase(it);
1738                 }
1739                 simMwiInfo.insert(newList);
1740         }
1741
1742         cv.signal();
1743
1744         mx.unlock();
1745
1746         MSG_END();
1747 }
1748
1749
1750 void SmsPluginSetting::setResultImei(bool bResult, char *pImei)
1751 {
1752         mx.lock();
1753
1754         bTapiResult = bResult;
1755
1756         memset(&meImei, 0x00, sizeof(meImei));
1757
1758         if (bTapiResult == true && pImei) {
1759                 snprintf(meImei, sizeof(meImei), "%s", pImei);
1760         }
1761
1762         cv.signal();
1763
1764         mx.unlock();
1765 }
1766
1767
1768 bool SmsPluginSetting::getResultImei(char *pImei)
1769 {
1770         int ret = 0;
1771
1772         mx.lock();
1773
1774         ret = cv.timedwait(mx.pMsgMutex(), MAX_TAPI_SIM_API_TIMEOUT);
1775
1776         mx.unlock();
1777
1778         if (ret == ETIMEDOUT) {
1779                 MSG_DEBUG("WARNING: TAPI callback TIME-OUT");
1780                 return false;
1781         }
1782
1783         if (bTapiResult == true && pImei) {
1784                 snprintf(pImei, sizeof(meImei), "%s", meImei);
1785         }
1786
1787         return bTapiResult;
1788 }
1789
1790
1791 void SmsPluginSetting::setResultFromSim(bool bResult)
1792 {
1793         mx.lock();
1794
1795         bTapiResult = bResult;
1796
1797         cv.signal();
1798
1799         mx.unlock();
1800 }
1801
1802
1803 bool SmsPluginSetting::getResultFromSim()
1804 {
1805         int ret = 0;
1806
1807         MSG_DEBUG("getResultFromSim() is called .");
1808
1809         ret = cv.timedwait(mx.pMsgMutex(), MAX_TAPI_SIM_API_TIMEOUT);
1810
1811         if (ret == ETIMEDOUT) {
1812                 MSG_DEBUG("WARNING: TAPI callback TIME-OUT");
1813                 return false;
1814         }
1815
1816         return bTapiResult;
1817 }
1818
1819
1820 SMS_PID_T SmsPluginSetting::convertPid(MSG_SMS_PID_T pid)
1821 {
1822         SMS_PID_T retPid;
1823
1824         switch (pid) {
1825         case MSG_PID_TEXT :
1826                 retPid = SMS_PID_NORMAL;
1827                 break;
1828         case MSG_PID_VOICE :
1829                 retPid = SMS_PID_VOICE;
1830                 break;
1831         case MSG_PID_FAX :
1832                 retPid = SMS_PID_TELEX;
1833                 break;
1834         case MSG_PID_X400 :
1835                 retPid = SMS_PID_x400;
1836                 break;
1837         case MSG_PID_ERMES :
1838                 retPid = SMS_PID_ERMES;
1839                 break;
1840         case MSG_PID_EMAIL :
1841                 retPid = SMS_PID_EMAIL;
1842                 break;
1843         default :
1844                 retPid = SMS_PID_NORMAL;
1845                 break;
1846         }
1847
1848         return retPid;
1849 }
1850
1851
1852 void SmsPluginSetting::deliverVoiceMsgNoti(int simIndex, int mwiCnt)
1853 {
1854         MSG_BEGIN();
1855
1856         MSG_MESSAGE_INFO_S msgInfo = {0, };
1857
1858         msgInfo.addressList = NULL;
1859         unique_ptr<MSG_ADDRESS_INFO_S*, void(*)(MSG_ADDRESS_INFO_S**)> addressListBuf(&msgInfo.addressList, unique_ptr_deleter);
1860
1861         msgInfo.addressList = (MSG_ADDRESS_INFO_S *)new char[sizeof(MSG_ADDRESS_INFO_S)];
1862         memset(msgInfo.addressList, 0x00, sizeof(MSG_ADDRESS_INFO_S));
1863
1864         msgInfo.nAddressCnt = 1;
1865
1866         msgInfo.displayTime = time(NULL);
1867
1868         char keyName[MAX_VCONFKEY_NAME_LEN];
1869         char *voiceNum = NULL;
1870         memset(keyName, 0x00, sizeof(keyName));
1871         snprintf(keyName, sizeof(keyName), "%s/%d", VOICEMAIL_NUMBER, simIndex);
1872         if (MsgSettingGetString(keyName, &voiceNum) != MSG_SUCCESS) {
1873                 MSG_INFO("MsgSettingGetString() is failed");
1874         }
1875
1876         if (voiceNum) {
1877                 snprintf(msgInfo.addressList[0].addressVal, sizeof(msgInfo.addressList[0].addressVal), "%s", voiceNum);
1878                 free(voiceNum);
1879                 voiceNum = NULL;
1880         }
1881         memset(msgInfo.addressList[0].displayName, 0x00, sizeof(msgInfo.addressList[0].displayName));
1882         msgInfo.msgType.mainType = MSG_SMS_TYPE;
1883         msgInfo.msgType.subType = MSG_MWI_VOICE_SMS;
1884         msgInfo.sim_idx = simIndex;
1885
1886 #if 0
1887         if (simMwiInfo.b_cphs == false) {
1888                 snprintf(msgInfo.msgText, sizeof(msgInfo.msgText), "%d new voice message", mwiCnt);
1889         } else {
1890                 snprintf(msgInfo.msgText, sizeof(msgInfo.msgText), "New voice message");
1891         }
1892 #else
1893         snprintf(msgInfo.msgText, sizeof(msgInfo.msgText), "%d", mwiCnt);
1894 #endif
1895
1896 #if 0
1897         if (SmsPluginEventHandler::instance()->callbackMsgIncoming(&msgInfo) != MSG_SUCCESS)
1898                 MSG_DEBUG("callbackIncoming is failed.");
1899 #else
1900         MsgInsertNotification(&msgInfo);
1901         MsgChangePmState();
1902 #endif
1903
1904         MSG_END();
1905 }
1906
1907
1908 void SmsPluginSetting::setSimChangeStatus(TapiHandle *handle, bool bInitializing)
1909 {
1910         MSG_BEGIN();
1911
1912         int tapiRet = TAPI_API_SUCCESS;
1913         TelSimCardStatus_t status = TAPI_SIM_STATUS_CARD_ERROR;
1914
1915         int cardChanged = 0;
1916         int simIndex = SmsPluginDSHandler::instance()->getSimIndex(handle);
1917
1918         pthread_t thd;
1919         char keyName[MAX_VCONFKEY_NAME_LEN] = {0, };
1920
1921         tapiRet = tel_get_sim_init_info(handle, &status, &cardChanged);
1922         MSG_INFO("Tapi Ret=[%d], SIM index [%d], SIM status [%d], CardChanged [%d]", tapiRet, simIndex, status, cardChanged);
1923
1924         if (status == TAPI_SIM_STATUS_SIM_INIT_COMPLETED) {
1925                 if (simStatus[simIndex] == MSG_SIM_STATUS_NOT_FOUND) {
1926                         if (cardChanged == 1) {
1927                                 snprintf(keyName, sizeof(keyName), "%s/%d", MSG_SIM_CHANGED, simIndex);
1928                                 MsgSettingSetInt(keyName, MSG_SIM_STATUS_CHANGED);
1929                                 simStatus[simIndex] = MSG_SIM_STATUS_CHANGED;
1930                         } else {
1931                                 snprintf(keyName, sizeof(keyName), "%s/%d", MSG_SIM_CHANGED, simIndex);
1932                                 MsgSettingSetInt(keyName, MSG_SIM_STATUS_NORMAL);
1933                                 simStatus[simIndex] = MSG_SIM_STATUS_NORMAL;
1934                         }
1935
1936                         /* Modified to call initSimInfo for SIM separately */
1937                         MSG_DEBUG("calling initSimInfo");
1938                         if (pthread_create(&thd, NULL, &initSimInfo, handle) < 0) {
1939                                 MSG_DEBUG("pthread_create() error");
1940                         } else {
1941                                 pthread_detach(thd);
1942                         }
1943                 } else {
1944                         MSG_DEBUG("SIM init was already done!");
1945                 }
1946         } else {
1947                 MSG_DEBUG("It doesn't initialize yet!!");
1948                 snprintf(keyName, sizeof(keyName), "%s/%d", MSG_SIM_CHANGED, simIndex);
1949                 MSG_DEBUG("Set MSG_SIM_CHANGED to MSG_SIM_STATUS_NOT_FOUND");
1950                 if (MsgSettingSetInt(keyName, MSG_SIM_STATUS_NOT_FOUND) != MSG_SUCCESS)
1951                         MSG_DEBUG("Fail to set MSG_SIM_CHANGED to MSG_SIM_STATUS_NOT_FOUND");
1952
1953                 simStatus[simIndex] = MSG_SIM_STATUS_NOT_FOUND;
1954         }
1955
1956         MSG_END();
1957 }