2 * Copyright (c) 2014 Samsung Electronics Co., Ltd. All rights reserved
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
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"
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"
39 #include <tapi_common.h>
41 #include <TapiUtility.h>
42 #include <ITapiNetText.h>
44 #include <ITapiModem.h>
47 /*==================================================================================================
49 ==================================================================================================*/
52 /*==================================================================================================
53 IMPLEMENTATION OF SmsPluginSetting - Member Functions
54 ==================================================================================================*/
55 SmsPluginSetting* SmsPluginSetting::pInstance = NULL;
58 SmsPluginSetting::SmsPluginSetting()
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;
66 simMailboxList.clear();
69 memset(&meImei, 0x00, sizeof(meImei));
76 for (int i = 0; i < MAX_TELEPHONY_HANDLE_CNT; i++)
77 bMbdnEnable[i] = false;
81 SmsPluginSetting::~SmsPluginSetting()
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());
90 SmsPluginSetting* SmsPluginSetting::instance()
93 pInstance = new SmsPluginSetting();
99 void* SmsPluginSetting::initSimInfo(void *data)
102 MsgMutexLocker lock(mm);
104 instance()->processInitSimInfo(data);
109 void* SmsPluginSetting::processInitSimInfo(void *data)
113 /* Handle sim info initialization separately */
114 TapiHandle *handle = (TapiHandle *)data;
115 instance()->updateSimStatus(handle);
122 void SmsPluginSetting::updateSimStatus(TapiHandle *handle)
127 MSG_DEBUG("handle is NULL.");
132 int tapiRet = TAPI_API_SUCCESS;
134 char keyName[MAX_VCONFKEY_NAME_LEN];
135 memset(keyName, 0x00, sizeof(keyName));
137 int simIndex = SmsPluginDSHandler::instance()->getSimIndex(handle);
140 TelSimImsiInfo_t imsiInfo;
141 memset(&imsiInfo, 0x00, sizeof(TelSimImsiInfo_t));
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);
148 /* Save Subcriber ID */
149 char *subscriberId = NULL;
150 memset(keyName, 0x00, sizeof(keyName));
152 if (SmsPluginDSHandler::instance()->getSubscriberId(simIndex, &subscriberId) != MSG_SUCCESS) {
153 MSG_DEBUG("getSubscriberId() is failed");
155 snprintf(keyName, sizeof(keyName), "%s/%d", MSG_SIM_SUBS_ID, simIndex);
156 if (MsgSettingSetString(keyName, subscriberId) != MSG_SUCCESS)
157 MSG_DEBUG("Fail MsgSettingSetString");
160 g_free(subscriberId); subscriberId = NULL;
162 /* Check device status */
163 tapiRet = tel_check_sms_device_status(handle, &status);
165 if (tapiRet != TAPI_API_SUCCESS) {
166 MSG_DEBUG("tel_check_sms_device_status() Error! [%d], Status [%d]", tapiRet, status);
170 if (status == TAPI_NETTEXT_READY_STATUS_3GPP) {
171 MSG_DEBUG("Device Is Ready");
173 MSG_DEBUG("Device Is Not Ready.. Waiting For Ready Callback");
175 if (SmsPluginEventHandler::instance()->getDeviceStatus(handle) == true) {
176 MSG_DEBUG("Device Is Ready");
178 MSG_DEBUG("Device Is Not Ready.");
183 /* init config data. */
184 initConfigData(handle);
187 /* init sim messages. */
188 SmsPluginSimMsg::instance()->initSimMessage(handle);
189 } catch (MsgException& e) {
190 MSG_FATAL("%s", e.what());
201 void SmsPluginSetting::initConfigData(TapiHandle *handle)
205 char keyName[MAX_VCONFKEY_NAME_LEN];
207 int sim_idx = SmsPluginDSHandler::instance()->getSimIndex(handle);
208 /*==================== SMSC setting ====================*/
209 /* Init SMS Parameter */
212 bool bSelectedFound = false;
213 bool bAPReceive = false;
215 paramCnt = getParamCount(handle);
217 MSG_INFO("Parameter Count [%d]", paramCnt);
219 MSG_SMSC_DATA_S tmpSmscData = {};
220 MSG_SMSC_LIST_S tmpSmscList = {0, };
222 for (int index = 0; index < paramCnt; index++) {
223 memset(&tmpSmscData, 0x00, sizeof(MSG_SMSC_DATA_S));
224 if (getParam(handle, index, &tmpSmscData) == false) {
229 memcpy(&(tmpSmscList.smscData[index]), &tmpSmscData, sizeof(MSG_SMSC_DATA_S));
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);
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);
239 /* First smsc is selected index */
240 if (!bSelectedFound) {
241 tmpSmscList.selected = selectedParam;
242 bSelectedFound = !bSelectedFound;
246 tmpSmscList.totalCnt = (paramCnt - failCnt);
247 tmpSmscList.simIndex = sim_idx;
250 MSG_DEBUG("######## Add SMSC ist #######");
251 addSMSCList(&tmpSmscList);
254 /*==================== CB configuration ====================*/
255 if (simStatus[sim_idx] != MSG_SIM_STATUS_NOT_FOUND) {
256 MSG_DEBUG("simStatus == [%d]", simStatus[sim_idx]);
258 MSG_CBMSG_OPT_S cbMsgOpt = {0, };
259 cbMsgOpt.simIndex = sim_idx;
261 if (getCbConfig(&cbMsgOpt) == true) {
262 cbMsgOpt.simIndex = sim_idx;
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");
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. ");
272 MSG_DEBUG("######## Add CB Option Success !!! #######");
273 MSG_SETTING_S cbSetting;
274 getCbOpt(&cbSetting, sim_idx);
275 setCbConfig(&(cbSetting.option.cbMsgOpt));
278 MSG_WARN("######## getCbConfig Fail !!! #######");
281 /*==================== Default Voice mail Setting ====================*/
282 if (simStatus[sim_idx] == MSG_SIM_STATUS_CHANGED) {
283 char keyName[MAX_VCONFKEY_NAME_LEN];
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!!");
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!!");
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!!");
302 MsgDeleteNoti(MSG_NOTI_TYPE_VOICE_1, sim_idx);
303 MsgDeleteNoti(MSG_NOTI_TYPE_VOICE_2, sim_idx);
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);
312 char *voiceNumber = NULL;
313 if (MsgSettingGetString(keyName, &voiceNumber) != MSG_SUCCESS) {
314 MSG_INFO("MsgSettingGetString() is failed");
317 if (!voiceNumber || (voiceNumber && voiceNumber[0] == '\0')) {
318 MSG_WARN("Voice Number is Empty!!");
326 MSG_WARN("######## getVoiceMailInfo Fail !!! #######");
329 /*==================== Voice mail count update ====================*/
330 if (getMwiInfo(handle) == true) {
331 MSG_DEBUG("######## getMwiInfo Success !!! #######");
333 MSG_WARN("######## getMwiInfo Fail !!! #######");
335 /* Get MWI from vconf and insert notification */
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");
344 deliverVoiceMsgNoti(sim_idx, mwiCnt);
347 /*==================== MSISDN update ====================*/
348 if (getMsisdnInfo(handle) == true) {
349 MSG_DEBUG("######## getMsisdnInfo Success !!! #######");
351 MSG_WARN("######## getMsisdnInfo Fail !!! #######");
354 /*==================== SST(SIM Service Table) update ====================*/
355 if (getSimServiceTable(handle) == true) {
356 MSG_DEBUG("######## getSimServiceTable Success !!! #######");
358 MSG_WARN("######## getSimServiceTable Fail !!! #######");
366 void SmsPluginSetting::SimRefreshCb(TapiHandle *handle)
370 if (pthread_create(&thd, NULL, &init_config_data, handle) < 0) {
371 MSG_ERR("pthread_create() error");
379 void* SmsPluginSetting::init_config_data(void *data)
381 TapiHandle *handle = (TapiHandle *)data;
382 instance()->initConfigData(handle);
387 void SmsPluginSetting::setConfigData(const MSG_SETTING_S *pSetting)
389 MSG_DEBUG("Setting Type : [%d]", pSetting->type);
391 switch (pSetting->type) {
393 case MSG_SMS_SENDOPT :
394 setNetworkMode(&pSetting->option.smsSendOpt);
398 setParamList(&pSetting->option.smscList);
399 addSMSCList((MSG_SMSC_LIST_S *)(&pSetting->option.smscList));
402 if (setCbConfig(&pSetting->option.cbMsgOpt) == false) {
403 THROW(MsgException::SMS_PLG_ERROR, "Failed to set config.");
406 case MSG_VOICEMAIL_OPT:
407 setVoiceMailInfo(&pSetting->option.voiceMailOpt);
410 THROW(MsgException::SMS_PLG_ERROR, "The Setting type is not supported. [%d]", pSetting->type);
416 void SmsPluginSetting::getConfigData(MSG_SETTING_S *pSetting)
418 MSG_DEBUG("Setting Type : [%d]", pSetting->type);
420 switch (pSetting->type) {
422 getSmscListInfo(pSetting->option.smscList.simIndex, &(pSetting->option.smscList));
426 if (getCbConfig(&pSetting->option.cbMsgOpt) == false) {
427 THROW(MsgException::SMS_PLG_ERROR, "Get CB config option failed.");
432 THROW(MsgException::SMS_PLG_ERROR, "The Setting type is not supported. [%d]", pSetting->type);
438 void SmsPluginSetting::addSMSCList(MSG_SMSC_LIST_S *pSmscList)
444 MSG_DEBUG("SIM index[%d]", pSmscList->simIndex);
445 MSG_DEBUG("total_count[%d]", pSmscList->totalCnt);
446 MSG_DEBUG("selected index[%d]", pSmscList->selected);
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);
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);
458 sim_index = pSmscList->simIndex;
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);
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;
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);
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);
480 if (pTmpSmscList.smscData[i].smscAddr.address[0] == '+')
481 pTmpSmscList.smscData[i].smscAddr.ton = MSG_TON_INTERNATIONAL;
483 pTmpSmscList.smscData[i].smscAddr.ton = MSG_TON_NATIONAL;
485 pTmpSmscList.smscData[i].smscAddr.npi = MSG_NPI_ISDN; /* app cannot set this value */
493 void SmsPluginSetting::getSmscListInfo(int simIndex, MSG_SMSC_LIST_S *pSmscList)
495 if (pSmscList == NULL) {
496 MSG_DEBUG("pSmscList is NULL!");
501 TapiHandle *handle = SmsPluginDSHandler::instance()->getTelHandle(simIndex);
502 simIndex = SmsPluginDSHandler::instance()->getSimIndex(handle);
505 memset(pSmscList, 0x00, sizeof(MSG_SMSC_LIST_S));
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);
520 msg_error_t SmsPluginSetting::addCbOpt(MSG_CBMSG_OPT_S *pCbOpt)
522 msg_error_t err = MSG_SUCCESS;
523 char keyName[MAX_VCONFKEY_NAME_LEN];
525 MSG_DEBUG("Receive [%d], Max SIM Count [%d]", pCbOpt->bReceive, pCbOpt->maxSimCnt);
527 MSG_DEBUG("Channel Count [%d]", pCbOpt->channelData.channelCnt);
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);
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;
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;
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;
563 void SmsPluginSetting::getCbOpt(MSG_SETTING_S *pSetting, int simIndex)
565 char keyName[MAX_VCONFKEY_NAME_LEN];
567 msg_error_t err = MSG_SUCCESS;
568 MsgDbHandler *dbHandle = getDbHandle();
570 memset(&(pSetting->option.cbMsgOpt), 0x00, sizeof(MSG_CBMSG_OPT_S));
572 pSetting->type = MSG_CBMSG_OPT;
573 pSetting->option.cbMsgOpt.simIndex = simIndex;
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");
580 memset(keyName, 0x00, sizeof(keyName));
581 snprintf(keyName, sizeof(keyName), "%s/%d", CB_MAX_SIM_COUNT, simIndex);
583 if (MsgSettingGetInt(keyName, &maxSimCnt) != MSG_SUCCESS) {
584 MSG_INFO("MsgSettingGetInt() is failed");
586 pSetting->option.cbMsgOpt.maxSimCnt = maxSimCnt;
588 err = MsgStoGetCBChannelInfo(dbHandle, &pSetting->option.cbMsgOpt.channelData, simIndex);
589 if (err != MSG_SUCCESS)
590 MSG_ERR("MsgStoGetCBChannelInfo : err=[%d]", err);
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);
596 if (MsgSettingGetBool(keyName, &pSetting->option.cbMsgOpt.bLanguage[i]) != MSG_SUCCESS)
597 MSG_INFO("MsgSettingGetBool() is failed");
602 void SmsPluginSetting::setParamList(const MSG_SMSC_LIST_S *pSMSCList)
606 MsgMutexLocker lock(mx);
608 TelSmsParams_t smsParam = {0};
610 int ret = TAPI_API_SUCCESS;
612 int index = pSMSCList->index;
613 MSG_DEBUG("SMSC Index to be set in SIM = %d", index);
615 /*Setting the SMSP Record index value*/
616 smsParam.RecordIndex = (unsigned char)index;
618 /*Setting the SMSP Record Length value = 28 + alphaId_len*/
619 smsParam.RecordLen = 28 + strlen(pSMSCList->smscData[index].name);
621 /*Setting the SMSP Alpha ID value*/
622 smsParam.AlphaIdLen = strlen(pSMSCList->smscData[index].name);
623 MSG_DEBUG("AlphaIdLen = %ld", smsParam.AlphaIdLen);
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);
631 smsParam.ParamIndicator = 0x00;
633 if (strlen(pSMSCList->smscData[index].smscAddr.address) > 0) {
634 smsParam.ParamIndicator |= 0x02 ; /* enable 2nd Bit */
635 MSG_DEBUG("ParamIndicator = [%02x]", smsParam.ParamIndicator);
637 if (pSMSCList->smscData[index].smscAddr.address[0] == '+')
638 smsParam.TpSvcCntrAddr.Ton = TAPI_SIM_TON_INTERNATIONAL;
640 smsParam.TpSvcCntrAddr.Ton = TAPI_SIM_TON_NATIONAL;
642 smsParam.TpSvcCntrAddr.Npi = TAPI_SIM_NPI_ISDN_TEL; /* app cannot set this value */
644 MSG_DEBUG("SMSC TON = [%d] NPI = [%d]", smsParam.TpSvcCntrAddr.Ton, smsParam.TpSvcCntrAddr.Npi);
646 MSG_SEC_DEBUG("address = %s", pSMSCList->smscData[index].smscAddr.address);
648 smsParam.TpSvcCntrAddr.DialNumLen = SmsPluginParamCodec::encodeSMSC(pSMSCList->smscData[index].smscAddr.address, smsParam.TpSvcCntrAddr.szDiallingNum);
650 MSG_DEBUG("SMSC Addr is not present");
653 /*Setting the PID value*/
654 smsParam.ParamIndicator |= 0x04 ; /* enable 3rd Bit */
655 MSG_DEBUG("ParamIndicator = [%02x]", smsParam.ParamIndicator);
657 smsParam.TpProtocolId = (unsigned short)convertPid(pSMSCList->smscData[index].pid);
659 /*Setting the ValidityPeriod value*/
660 smsParam.ParamIndicator |= 0x10 ; /* enable 5th Bit */
661 MSG_DEBUG("ParamIndicator = [%02x]", smsParam.ParamIndicator);
663 smsParam.TpValidityPeriod = (unsigned short)pSMSCList->smscData[index].valPeriod;
665 smsParam.ParamIndicator = ~(smsParam.ParamIndicator);
666 MSG_DEBUG("ParamIndicator = [%02x]", smsParam.ParamIndicator);
668 /* Get TAPI handle */
669 TapiHandle *handle = SmsPluginDSHandler::instance()->getTelHandle(pSMSCList->simIndex);
671 ret = tel_set_sms_parameters(handle, (const TelSmsParams_t*)&smsParam, TapiEventSetConfigData, NULL);
673 if (ret != TAPI_API_SUCCESS)
674 THROW(MsgException::SMS_PLG_ERROR, "tel_set_sms_parameters() Error. [%d]", ret);
676 if (!getResultFromSim())
677 THROW(MsgException::SMS_PLG_ERROR, "tel_set_sms_parameters() Result Error.");
683 void SmsPluginSetting::getParamList(MSG_SMSC_LIST_S *pSMSCList)
689 MSG_SEC_DEBUG("SIM index [%d]", pSMSCList->simIndex);
690 TapiHandle *handle = SmsPluginDSHandler::instance()->getTelHandle(pSMSCList->simIndex);
691 paramCnt = getParamCount(handle);
693 MSG_DEBUG("Parameter Count [%d]", paramCnt);
695 int ret = TAPI_API_SUCCESS;
697 MSG_SMSC_DATA_S tmpSmscData = {};
699 for (int index = 0; index < paramCnt; index++) {
700 ret = tel_get_sms_parameters(handle, index, TapiEventGetParam, NULL);
702 if (ret == TAPI_API_SUCCESS) {
703 MSG_DEBUG("######## tel_get_sms_parameters() Success !!! #######");
705 THROW(MsgException::SMS_PLG_ERROR, "######## tel_get_sms_parameters() Fail !!! return : %d #######", ret);
708 if (getParamEvent(handle, &tmpSmscData) == true) {
709 MSG_DEBUG("######## Get Parameter was Successful !!! #######");
711 memcpy(&(pSMSCList->smscData[index]), &tmpSmscData, sizeof(MSG_SMSC_DATA_S));
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);
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);
721 MSG_DEBUG("######## Get Parameter was Failed !!! #######");
725 pSMSCList->totalCnt = paramCnt;
726 pSMSCList->selected = selectedParam;
728 MSG_DEBUG("total_count[%d]", pSMSCList->totalCnt);
734 int SmsPluginSetting::getParamCount(TapiHandle *handle)
736 int ret = TAPI_API_SUCCESS;
738 ret = tel_get_sms_parameter_count(handle, TapiEventGetParamCnt, NULL);
740 if (ret == TAPI_API_SUCCESS) {
741 MSG_DEBUG("######## tel_get_sms_parameter_count() Success !!! #######");
743 THROW(MsgException::SMS_PLG_ERROR, "tel_get_sms_parameter_count() Error. [%d]", ret);
746 return getParamCntEvent();
750 bool SmsPluginSetting::getParam(TapiHandle *handle, int Index, MSG_SMSC_DATA_S *pSmscData)
752 int ret = TAPI_API_SUCCESS;
754 ret = tel_get_sms_parameters(handle, Index, TapiEventGetParam, NULL);
756 if (ret == TAPI_API_SUCCESS) {
757 MSG_DEBUG("######## tel_get_sms_parameters() Success !!! #######");
759 MSG_ERR("######## tel_get_sms_parameters() Fail !!! return : %d #######", ret);
763 if (getParamEvent(handle, pSmscData) == true) {
764 MSG_DEBUG("######## Get Parameter was Successful !!! #######");
766 MSG_ERR("######## Get Parameter was Failed !!! #######");
774 void SmsPluginSetting::setSmscInfo(const MSG_SMSC_LIST_S *pSmscList)
778 MsgMutexLocker lock(mx);
780 int ret = TAPI_API_SUCCESS;
782 TapiHandle *handle = NULL;
784 handle = SmsPluginDSHandler::instance()->getTelHandle(pSmscList->simIndex);
786 int select_id = pSmscList->selected;
787 const MSG_SMSC_DATA_S *pSmscData = (const MSG_SMSC_DATA_S *)&(pSmscList->smscData[select_id]);
789 MSG_DEBUG("Select SMSC id = [%d]", select_id);
791 TelSmsAddressInfo_t sca;
792 memset(&sca, 0x00, sizeof(TelSmsAddressInfo_t));
794 if (strlen(pSmscData->smscAddr.address) > 0) {
795 if (pSmscData->smscAddr.address[0] == '+')
796 sca.Ton = TAPI_SIM_TON_INTERNATIONAL;
798 sca.Ton = TAPI_SIM_TON_NATIONAL;
800 sca.Npi = TAPI_SIM_NPI_ISDN_TEL; /* app cannot set this value */
802 MSG_SEC_DEBUG("SMSC TON = [%d], NPI = [%d], Address = [%s]", sca.Ton, sca.Npi, pSmscData->smscAddr.address);
804 sca.DialNumLen = SmsPluginParamCodec::encodeSMSC(pSmscData->smscAddr.address, sca.szDiallingNum);
806 MSG_DEBUG("SMSC Addr is not present");
809 ret = tel_set_sms_sca(handle, (const TelSmsAddressInfo_t *)&sca, 0, TapiEventSetSmscInfo, NULL);
811 if (ret != TAPI_API_SUCCESS)
812 THROW(MsgException::SMS_PLG_ERROR, "tel_set_sms_sca() Error. [%d]", ret);
814 if (!getResultFromSim())
815 THROW(MsgException::SMS_PLG_ERROR, "tel_set_sms_sca() Result Error.");
821 bool SmsPluginSetting::setCbConfig(const MSG_CBMSG_OPT_S *pCbOpt)
823 TapiHandle *handle = NULL;
824 int simCnt = SmsPluginDSHandler::instance()->getTelHandleCount();
826 TelSmsCbConfig_t cbConfig = {};
829 int ret = TAPI_API_SUCCESS;
831 if (pCbOpt->bReceive == true)
832 cbEnabled = 2;/* Need to get a Enumeration from TAPI, currently it is not available */
834 MSG_DEBUG("simIndex:%d, cbEnabled:%d", pCbOpt->simIndex, cbEnabled);
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;
841 for (int i = 1; i <= simCnt; i++) {
842 MsgMutexLocker lock(mx);
844 memset(keyName, 0x00, sizeof(keyName));
845 snprintf(keyName, sizeof(keyName), "%s/%d", MSG_SIM_CHANGED, i);
847 if (MsgSettingGetInt(keyName, &tmpVal) != MSG_SUCCESS) {
848 MSG_INFO("MsgSettingGetInt() is failed");
850 simStatus = (MSG_SIM_STATUS_T)tmpVal;
852 if (simStatus == MSG_SIM_STATUS_NOT_FOUND) {
853 MSG_DEBUG("SIM %d is not present..", i);
857 handle = SmsPluginDSHandler::instance()->getTelHandle(i);
858 memset(&cbConfig, 0x00, sizeof(TelSmsCbConfig_t));
859 cbConfig.CBEnabled = cbEnabled;
860 cbConfig.Net3gppType = TAPI_NETTEXT_NETTYPE_3GPP;
862 /*MSG_SETTING_S cbSetting;
863 getCbOpt(&cbSetting, i);
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;
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;
876 ret = tel_set_sms_cb_config(handle, &cbConfig, TapiEventSetConfigData, NULL);
878 if (ret == TAPI_API_SUCCESS) {
879 MSG_DEBUG("######## tel_set_sms_cb_config() Success !!! #######");
881 MSG_ERR("######## tel_set_sms_cb_config() Fail !!! return : %d #######", ret);
885 if (getResultFromSim() == true) {
886 MSG_DEBUG("######## Set Cb Config was Successful !!! #######");
888 MSG_ERR("######## Set Cb Config was Failed !!! #######");
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);
901 MSG_DEBUG("SIM Index = [0], Set CB Receive is done");
904 MsgMutexLocker lock(mx);
906 handle = SmsPluginDSHandler::instance()->getTelHandle(pCbOpt->simIndex);
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;
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;
921 MSG_DEBUG("FROM: %d, TO: %d", cbConfig.MsgIDs[i].Net3gpp.FromMsgId, cbConfig.MsgIDs[i].Net3gpp.ToMsgId);
923 MSG_DEBUG("CBEnabled: %d, range_count: %d", cbConfig.CBEnabled, cbConfig.MsgIdRangeCount);*/
925 ret = tel_set_sms_cb_config(handle, &cbConfig, TapiEventSetConfigData, NULL);
927 if (ret == TAPI_API_SUCCESS) {
928 MSG_DEBUG("######## tel_set_sms_cb_config() Success !!! #######");
930 MSG_ERR("######## tel_set_sms_cb_config() Fail !!! return : %d #######", ret);
934 if (getResultFromSim() == true) {
935 MSG_DEBUG("######## Set Cb Config was Successful !!! #######");
937 MSG_ERR("######## Set Cb Config was Failed !!! #######");
946 bool SmsPluginSetting::getCbConfig(MSG_CBMSG_OPT_S *pCbOpt)
948 int ret = TAPI_API_SUCCESS;
950 TapiHandle *handle = NULL;
952 if (pCbOpt->simIndex == 0) {
953 MSG_DEBUG("SIM Index for getCBConfig = 0, CANNOT get cbconfig from SIM 0");
957 handle = SmsPluginDSHandler::instance()->getTelHandle(pCbOpt->simIndex);
959 ret = tel_get_sms_cb_config(handle, TapiEventGetCBConfig, NULL);
961 if (ret == TAPI_API_SUCCESS) {
962 MSG_DEBUG("######## tel_get_sms_cb_config() Success !!! #######");
964 MSG_ERR("######## tel_get_sms_cb_config() Fail !!! return : %d #######", ret);
968 if (getCbConfigEvent(pCbOpt) == true) {
969 MSG_DEBUG("######## Get Cb Config was Successful !!! #######");
971 MSG_ERR("######## Get Cb Config was Failed !!! #######");
979 void SmsPluginSetting::setVoiceMailInfo(const MSG_VOICEMAIL_OPT_S *pVoiceOpt)
982 MsgMutexLocker lock(mx);
984 int ret = TAPI_API_SUCCESS;
985 bool *bShowError = NULL; /* When invalid voicemail data exists on SIM, update error should not be handled. */
987 int simIndex = pVoiceOpt->simIndex;
989 if (bMbdnEnable[simIndex] == false) {
990 MSG_DEBUG("MBDN service is disable.");
994 TelSimMailBoxNumber_t mailboxInfo = {0, };
995 bool bExistVoicetype = false;
998 smsSimMailboxListMap::iterator it = simMailboxList.find(simIndex);
999 if (it == simMailboxList.end()) {
1003 SMS_SIM_MAILBOX_LIST_S &pTmpSimMailboxList = it->second;
1004 if (pTmpSimMailboxList.count < 0) { /* Not available */
1008 bShowError = (bool*)calloc(1, sizeof(bool));
1012 if (pTmpSimMailboxList.count == 0) {
1013 char num[MAX_PHONE_NUMBER_LEN + 1] = {0, };
1015 mailboxInfo.mb_type = TAPI_SIM_MAILBOX_VOICE;
1016 mailboxInfo.rec_index = 1;
1017 mailboxInfo.ton = TAPI_SIM_TON_UNKNOWN;
1019 snprintf(num, sizeof(num), "%s", pVoiceOpt->mailNumber);
1020 MSG_DEBUG("Mailbox number config [%s]", num);
1022 if (num[0] == '+') {
1023 snprintf(mailboxInfo.num, sizeof(mailboxInfo.num), "%s", &(num[1]));
1024 mailboxInfo.ton = TAPI_SIM_TON_INTERNATIONAL;
1026 snprintf(mailboxInfo.num, sizeof(mailboxInfo.num), "%s", num);
1029 MSG_SEC_DEBUG("Mailbox number to save sim [%s]", mailboxInfo.num);
1031 *bShowError = false;
1034 for (i = 0; i < pTmpSimMailboxList.count; i++) {
1035 if (pTmpSimMailboxList.list[i].mb_type == TAPI_SIM_MAILBOX_VOICE) {
1036 bExistVoicetype = true;
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;
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");
1061 MSG_INFO("bShowError = %d", *bShowError);
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);
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);
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;
1080 snprintf(mailboxInfo.num, sizeof(mailboxInfo.num), "%s", pTmpSimMailboxList.list[i].num);
1082 MSG_DEBUG("Mailbox number to save sim [%s]", mailboxInfo.num);
1084 mailboxInfo.cc_id = pTmpSimMailboxList.list[i].cc_id;
1085 mailboxInfo.ext1_id = pTmpSimMailboxList.list[i].ext1_id;
1088 TapiHandle *handle = SmsPluginDSHandler::instance()->getTelHandle(simIndex);
1090 ret = tel_set_sim_mailbox_info(handle, &mailboxInfo, TapiEventSetMailboxInfo, (void*)bShowError);
1092 if (ret == TAPI_API_SUCCESS) {
1093 MSG_DEBUG("######## tel_set_sim_mailbox_info() Success !!! #######");
1095 MSG_ERR("######## tel_set_sim_mailbox_info() Fail !!! return : %d #######", ret);
1098 if (getResultFromSim() == true) {
1099 MSG_DEBUG("######## Set mailbox info Success !!! #######");
1103 THROW(MsgException::SMS_PLG_ERROR, "######## Set mailbox info Failed !!!#######");
1104 MSG_ERR("######## Set mailbox info Failed !!! #######");
1115 bool SmsPluginSetting::getVoiceMailInfo(TapiHandle *handle)
1117 MsgMutexLocker lock(mx);
1119 int ret = TAPI_API_SUCCESS;
1121 ret = tel_get_sim_mailbox_info(handle, TapiEventGetMailboxInfo, NULL);
1123 if (ret == TAPI_API_SUCCESS) {
1124 MSG_DEBUG("######## tel_get_sim_mailbox_info() Success !!! #######");
1126 MSG_ERR("######## tel_get_sim_mailbox_info() Fail !!! return : %d #######", ret);
1130 if (getMailboxInfoEvent() == true) {
1131 MSG_DEBUG("######## Get mailbox info was Successful !!! #######");
1133 MSG_ERR("######## Get mailbox info was Failed !!! #######");
1141 void SmsPluginSetting::getMeImei(char *pImei)
1143 int ret = TAPI_API_SUCCESS;
1145 TapiHandle *handle = NULL;
1146 handle = SmsPluginDSHandler::instance()->getTelHandle(1);
1148 if (handle == NULL) {
1149 MSG_DEBUG("Tapi Handle is NULL!");
1153 ret = tel_get_misc_me_imei(handle, TapiEventGetMeImei, NULL);
1155 if (ret == TAPI_API_SUCCESS) {
1156 MSG_SEC_DEBUG("######## tel_get_misc_me_imei() Success !!! #######");
1158 if (getResultImei(pImei) == true) {
1159 MSG_SEC_DEBUG("######## Get ME IMEI was Successful !!! #######");
1161 MSG_SEC_DEBUG("######## Get ME IMEI was Failed !!! #######");
1164 MSG_SEC_DEBUG("######## tel_get_misc_me_imei() Fail !!! return : %d #######", ret);
1169 void SmsPluginSetting::setMwiInfo(int simIndex, MSG_SUB_TYPE_T type, int count)
1171 MSG_DEBUG("SET MWI INFO, type=[%d]", type);
1172 MSG_DEBUG("SET MWI INFO, count=[%d]", count);
1174 char keyName[MAX_VCONFKEY_NAME_LEN];
1176 memset(keyName, 0x00, sizeof(keyName));
1177 snprintf(keyName, sizeof(keyName), "%s/%d", VOICEMAIL_COUNT, simIndex);
1179 if (MsgSettingSetInt(keyName, count) != MSG_SUCCESS)
1180 MSG_DEBUG("MsgSettingSetInt is failed!!");
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);
1189 if (bMbdnEnable[simIndex] == false) {
1190 MSG_DEBUG("MBDN service is disable.");
1194 int ret = TAPI_API_SUCCESS;
1195 TelSimMessageWaitingReq_t mwReq = {0, };
1197 simMwiInfoMap::iterator iter = simMwiInfo.find(simIndex);
1198 if(iter == simMwiInfo.end()) {
1199 MSG_DEBUG("IT is not present");
1203 MSG_DEBUG("IT is present");
1205 SMS_SIM_MWI_INFO_S &pTmpsimMwiInfo = iter->second;
1207 MSG_DEBUG("SET MWI INFO, CPHS? [%s]", pTmpsimMwiInfo.b_cphs?"Yes":"No");
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);
1218 MSG_DEBUG("There is no type [%d] in CPHS.", type);
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;
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);
1233 MSG_DEBUG("b_cphs is not set");
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;
1244 mwReq.mw_data_u.mw.rec_index = pTmpsimMwiInfo.mwi_list.mw_info[0].rec_index;
1247 mwReq.mw_data_u.mw.indicator_status = 0x00;
1249 mwReq.mw_data_u.mw.indicator_status = 0x01;
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;
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);
1266 mwReq.b_cphs = pTmpsimMwiInfo.b_cphs;
1268 TapiHandle *handle = SmsPluginDSHandler::instance()->getTelHandle(simIndex);
1270 ret = tel_set_sim_messagewaiting_info(handle, &mwReq, TapiEventSetMwiInfo, NULL);
1272 if (ret == TAPI_API_SUCCESS) {
1273 MSG_DEBUG("######## tel_set_sim_messagewaiting_info() Success !!! #######");
1275 MSG_DEBUG("######## tel_set_sim_messagewaiting_info() Fail !!! return : %d #######", ret);
1282 bool SmsPluginSetting::getMwiInfo(TapiHandle *handle)
1284 MsgMutexLocker lock(mx);
1286 int ret = TAPI_API_SUCCESS;
1288 ret = tel_get_sim_messagewaiting_info(handle, TapiEventGetMwiInfo, NULL);
1290 if (ret == TAPI_API_SUCCESS) {
1291 MSG_DEBUG("######## tel_get_sim_messagewaiting_info() Success !!! #######");
1293 MSG_DEBUG("######## tel_get_sim_messagewaiting_info() Fail !!! return : %d #######", ret);
1297 if (getResultFromSim() == true) {
1298 MSG_DEBUG("######## Get Mainbox info was Successful !!! #######");
1300 MSG_DEBUG("######## Get Mainbox info was Failed !!! #######");
1308 bool SmsPluginSetting::getMsisdnInfo(TapiHandle *handle)
1310 MsgMutexLocker lock(mx);
1312 int ret = TAPI_API_SUCCESS;
1314 ret = tel_get_sim_msisdn(handle, TapiEventGetMsisdnInfo, NULL);
1316 if (ret == TAPI_API_SUCCESS) {
1317 MSG_DEBUG("######## tel_get_sim_msisdn() Success !!! #######");
1319 MSG_DEBUG("######## tel_get_sim_msisdn() Fail !!! return : %d #######", ret);
1323 if (getResultFromSim() == true) {
1324 MSG_DEBUG("######## Get Sim msisdn was Successful !!! #######");
1326 MSG_DEBUG("######## Get Sim msisdn was Failed !!! #######");
1334 bool SmsPluginSetting::getSimServiceTable(TapiHandle *handle)
1336 MsgMutexLocker lock(mx);
1338 int ret = TAPI_API_SUCCESS;
1340 ret = tel_get_sim_service_table(handle, TapiEventGetSimServiceTable, NULL);
1342 if (ret == TAPI_API_SUCCESS) {
1343 MSG_DEBUG("######## tel_get_sim_service_table() Success !!! #######");
1345 MSG_DEBUG("######## tel_get_sim_service_table() Fail !!! return : %d #######", ret);
1349 if (getResultFromSim() == true) {
1350 MSG_DEBUG("######## Get SST info was Successful !!! #######");
1352 MSG_DEBUG("######## Get SST info was Failed !!! #######");
1360 void SmsPluginSetting::setParamCntEvent(int ParamCnt)
1364 paramCnt = ParamCnt;
1372 int SmsPluginSetting::getParamCntEvent()
1378 ret = cv.timedwait(mx.pMsgMutex(), MAX_TAPI_SIM_API_TIMEOUT);
1382 if (ret == ETIMEDOUT) {
1383 MSG_ERR("WARNING: TAPI callback TIME-OUT");
1391 void SmsPluginSetting::setParamEvent(struct tapi_handle *handle, const MSG_SMSC_DATA_S *pSmscData, int RecordIdx, bool bSuccess)
1395 bTapiResult = bSuccess;
1397 int sim_idx = SmsPluginDSHandler::instance()->getSimIndex(handle);
1399 memset(&smscData[sim_idx], 0x00, sizeof(MSG_SMSC_DATA_S));
1401 if (bTapiResult == true) {
1402 MSG_DEBUG("Success to get parameter data");
1404 selectedParam = RecordIdx;
1406 memcpy(&smscData[sim_idx], pSmscData, sizeof(MSG_SMSC_DATA_S));
1415 bool SmsPluginSetting::getParamEvent(TapiHandle *handle, MSG_SMSC_DATA_S *pSmscData)
1421 bTapiResult = false;
1422 ret = cv.timedwait(mx.pMsgMutex(), MAX_TAPI_SIM_API_TIMEOUT);
1426 if (ret == ETIMEDOUT) {
1427 MSG_DEBUG("WARNING: TAPI callback TIME-OUT");
1431 memset(pSmscData, 0x00, sizeof(MSG_SMSC_DATA_S));
1433 if (bTapiResult == true) {
1434 int index = SmsPluginDSHandler::instance()->getSimIndex(handle);
1435 memcpy(pSmscData, &smscData[index], sizeof(MSG_SMSC_DATA_S));
1442 void SmsPluginSetting::setCbConfigEvent(TapiHandle *handle, const MSG_CBMSG_OPT_S *pCbOpt, bool bSuccess)
1448 char keyName[MAX_VCONFKEY_NAME_LEN];
1450 bTapiResult = bSuccess;
1452 int simIndex = SmsPluginDSHandler::instance()->getSimIndex(handle);
1454 if (bTapiResult == true) {
1455 MSG_DEBUG("Success to get cb config data");
1457 pair <int, MSG_CBMSG_OPT_S> newCbOpt(simIndex, *pCbOpt);
1458 cbOptMap::iterator it = cbOpt.find(simIndex);
1460 if (it == cbOpt.end()) {
1461 MSG_DEBUG("IT is not present");
1463 MSG_DEBUG("IT present");
1466 cbOpt.insert(newCbOpt);
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);
1474 MSG_DEBUG("Failed to get cb config data");
1476 cbOptMap::iterator it = cbOpt.find(simIndex);
1478 if (it == cbOpt.end()) {
1479 MSG_DEBUG("IT not present");
1480 MSG_CBMSG_OPT_S pTmpCbOpt;
1482 memset(&pTmpCbOpt, 0x00, sizeof(MSG_CBMSG_OPT_S));
1483 pair <int, MSG_CBMSG_OPT_S> newCbOpt(simIndex, pTmpCbOpt);
1485 cbOpt.insert(newCbOpt);
1496 bool SmsPluginSetting::getCbConfigEvent(MSG_CBMSG_OPT_S *pCbOpt)
1504 bTapiResult = false;
1505 ret = cv.timedwait(mx.pMsgMutex(), MAX_TAPI_SIM_API_TIMEOUT);
1509 if (ret == ETIMEDOUT) {
1510 MSG_DEBUG("WARNING: TAPI callback TIME-OUT");
1514 int simIndex = pCbOpt->simIndex;
1516 memset(pCbOpt, 0x00, sizeof(MSG_CBMSG_OPT_S));
1518 if (bTapiResult == true) {
1519 cbOptMap::iterator it = cbOpt.find(simIndex);
1521 if (it == cbOpt.end()) {
1522 MSG_DEBUG("IT is not present");
1526 MSG_DEBUG("IT is present");
1528 MSG_CBMSG_OPT_S &pTmpCbOpt = it->second;
1529 memcpy(pCbOpt, &pTmpCbOpt, sizeof(MSG_CBMSG_OPT_S));
1537 void SmsPluginSetting::setMailboxInfoEvent(TapiHandle *handle, SMS_SIM_MAILBOX_LIST_S *pMailboxList, bool bSuccess, bool bMbdn)
1541 MSG_DEBUG("bSuccess = %d, bMbdn = %d", bSuccess, bMbdn);
1544 bTapiResult = bSuccess;
1546 int simIndex = SmsPluginDSHandler::instance()->getSimIndex(handle);
1548 bMbdnEnable[simIndex] = bMbdn;
1550 /* print incoming mailbox list */
1552 MSG_DEBUG("Input list is count = %d ", pMailboxList->count);
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);
1559 MSG_INFO("pMailboxList is NULL");
1562 if (bTapiResult == true) {
1564 bool bExistMailboxType = false;
1565 char keyName[MAX_VCONFKEY_NAME_LEN];
1567 if (pMailboxList && pMailboxList->count > 0) {
1568 pair <int, SMS_SIM_MAILBOX_LIST_S> newList(simIndex, *pMailboxList);
1570 smsSimMailboxListMap::iterator it = simMailboxList.find(simIndex);
1571 if (it == simMailboxList.end()) {
1572 MSG_DEBUG("IT not present !!!");
1573 simMailboxList.insert(newList);
1575 MSG_DEBUG("IT present !!!");
1576 simMailboxList.erase(it);
1577 simMailboxList.insert(newList);
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);
1584 if (pMailboxList->list[i].mb_type == TAPI_SIM_MAILBOX_VOICE) {
1585 bExistMailboxType = true;
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;
1600 smsSimMailboxListMap::iterator iter = simMailboxList.find(simIndex);
1602 SMS_SIM_MAILBOX_LIST_S &pTmpMailboxList = iter->second;
1604 char mailNumber[MAX_PHONE_NUMBER_LEN+1];
1605 memset(mailNumber, 0x00 , sizeof(mailNumber));
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);
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);
1615 snprintf(mailNumber, sizeof(mailNumber), "%s", pTmpMailboxList.list[i].num);
1616 MSG_DEBUG("[%s]", mailNumber);
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!!");
1626 if (pTmpMailboxList.list[i].alpha_id[0] != '\0') {
1627 char unpackAlphaId[MAX_SIM_XDN_ALPHA_ID_LEN+8];
1629 MSG_LANG_INFO_S langInfo = {0, };
1631 memset(unpackAlphaId, 0x00, sizeof(unpackAlphaId));
1633 langInfo.bSingleShift = false;
1634 langInfo.bLockingShift = false;
1636 tmpLen = strlen(pTmpMailboxList.list[i].alpha_id);
1638 MsgTextConvert *textCvt = MsgTextConvert::instance();
1639 textCvt->convertGSM7bitToUTF8((unsigned char*)unpackAlphaId, sizeof(unpackAlphaId), (unsigned char*)pTmpMailboxList.list[i].alpha_id, tmpLen, &langInfo);
1641 MSG_DEBUG("UTF8 ALPHA_ID = [%s]", unpackAlphaId);
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!!");
1650 /* insert empty list with sim index */
1651 SMS_SIM_MAILBOX_LIST_S pDummySimMailboxList;
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);
1664 bool SmsPluginSetting::getMailboxInfoEvent()
1668 ret = cv.timedwait(mx.pMsgMutex(), MAX_TAPI_SIM_API_TIMEOUT);
1670 if (ret == ETIMEDOUT) {
1671 MSG_DEBUG("WARNING: TAPI callback TIME-OUT");
1678 void SmsPluginSetting::setMwiInfoEvent(struct tapi_handle *handle, SMS_SIM_MWI_INFO_S *pMwiInfo, bool bSuccess)
1684 bTapiResult = bSuccess;
1686 int index = SmsPluginDSHandler::instance()->getSimIndex(handle);
1688 if (bTapiResult == true) {
1690 char keyName[MAX_VCONFKEY_NAME_LEN];
1692 pair <int, SMS_SIM_MWI_INFO_S> newList(index, *pMwiInfo);
1693 simMwiInfoMap::iterator it = simMwiInfo.find(index);
1695 if (it == simMwiInfo.end()) {
1696 MSG_DEBUG("IT not present");
1698 MSG_DEBUG("IT present");
1699 simMwiInfo.erase(it);
1701 simMwiInfo.insert(newList);
1703 simMwiInfoMap::iterator iter = simMwiInfo.find(index);
1705 SMS_SIM_MWI_INFO_S &pTmpsimMwiInfoList = iter->second;
1707 /* Save MW count with VOICE line1 number */
1708 if (pTmpsimMwiInfoList.b_cphs == true) {
1709 mwiCnt = pTmpsimMwiInfoList.cphs_mwi.b_voice1;
1711 mwiCnt = pTmpsimMwiInfoList.mwi_list.mw_info[0].voice_count;
1713 /* TODO :: Add operation for voice mail of line 2 */
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!!");
1720 MSG_DEBUG("MWI count = [%d]", mwiCnt);
1723 deliverVoiceMsgNoti(index, mwiCnt);
1726 SMS_SIM_MWI_INFO_S pTmpsimMwiInfo;
1728 memset(&pTmpsimMwiInfo, 0x00, sizeof(SMS_SIM_MWI_INFO_S));
1730 pair <int, SMS_SIM_MWI_INFO_S> newList(index, pTmpsimMwiInfo);
1731 simMwiInfoMap::iterator it = simMwiInfo.find(index);
1733 if (it == simMwiInfo.end()) {
1734 MSG_DEBUG("IT not present");
1736 MSG_DEBUG("IT present");
1737 simMwiInfo.erase(it);
1739 simMwiInfo.insert(newList);
1750 void SmsPluginSetting::setResultImei(bool bResult, char *pImei)
1754 bTapiResult = bResult;
1756 memset(&meImei, 0x00, sizeof(meImei));
1758 if (bTapiResult == true && pImei) {
1759 snprintf(meImei, sizeof(meImei), "%s", pImei);
1768 bool SmsPluginSetting::getResultImei(char *pImei)
1774 ret = cv.timedwait(mx.pMsgMutex(), MAX_TAPI_SIM_API_TIMEOUT);
1778 if (ret == ETIMEDOUT) {
1779 MSG_DEBUG("WARNING: TAPI callback TIME-OUT");
1783 if (bTapiResult == true && pImei) {
1784 snprintf(pImei, sizeof(meImei), "%s", meImei);
1791 void SmsPluginSetting::setResultFromSim(bool bResult)
1795 bTapiResult = bResult;
1803 bool SmsPluginSetting::getResultFromSim()
1807 MSG_DEBUG("getResultFromSim() is called .");
1809 ret = cv.timedwait(mx.pMsgMutex(), MAX_TAPI_SIM_API_TIMEOUT);
1811 if (ret == ETIMEDOUT) {
1812 MSG_DEBUG("WARNING: TAPI callback TIME-OUT");
1820 SMS_PID_T SmsPluginSetting::convertPid(MSG_SMS_PID_T pid)
1826 retPid = SMS_PID_NORMAL;
1828 case MSG_PID_VOICE :
1829 retPid = SMS_PID_VOICE;
1832 retPid = SMS_PID_TELEX;
1835 retPid = SMS_PID_x400;
1837 case MSG_PID_ERMES :
1838 retPid = SMS_PID_ERMES;
1840 case MSG_PID_EMAIL :
1841 retPid = SMS_PID_EMAIL;
1844 retPid = SMS_PID_NORMAL;
1852 void SmsPluginSetting::deliverVoiceMsgNoti(int simIndex, int mwiCnt)
1856 MSG_MESSAGE_INFO_S msgInfo = {0, };
1858 msgInfo.addressList = NULL;
1859 unique_ptr<MSG_ADDRESS_INFO_S*, void(*)(MSG_ADDRESS_INFO_S**)> addressListBuf(&msgInfo.addressList, unique_ptr_deleter);
1861 msgInfo.addressList = (MSG_ADDRESS_INFO_S *)new char[sizeof(MSG_ADDRESS_INFO_S)];
1862 memset(msgInfo.addressList, 0x00, sizeof(MSG_ADDRESS_INFO_S));
1864 msgInfo.nAddressCnt = 1;
1866 msgInfo.displayTime = time(NULL);
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");
1877 snprintf(msgInfo.addressList[0].addressVal, sizeof(msgInfo.addressList[0].addressVal), "%s", voiceNum);
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;
1887 if (simMwiInfo.b_cphs == false) {
1888 snprintf(msgInfo.msgText, sizeof(msgInfo.msgText), "%d new voice message", mwiCnt);
1890 snprintf(msgInfo.msgText, sizeof(msgInfo.msgText), "New voice message");
1893 snprintf(msgInfo.msgText, sizeof(msgInfo.msgText), "%d", mwiCnt);
1897 if (SmsPluginEventHandler::instance()->callbackMsgIncoming(&msgInfo) != MSG_SUCCESS)
1898 MSG_DEBUG("callbackIncoming is failed.");
1900 MsgInsertNotification(&msgInfo);
1908 void SmsPluginSetting::setSimChangeStatus(TapiHandle *handle, bool bInitializing)
1912 int tapiRet = TAPI_API_SUCCESS;
1913 TelSimCardStatus_t status = TAPI_SIM_STATUS_CARD_ERROR;
1915 int cardChanged = 0;
1916 int simIndex = SmsPluginDSHandler::instance()->getSimIndex(handle);
1919 char keyName[MAX_VCONFKEY_NAME_LEN] = {0, };
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);
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;
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;
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");
1941 pthread_detach(thd);
1944 MSG_DEBUG("SIM init was already done!");
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");
1953 simStatus[simIndex] = MSG_SIM_STATUS_NOT_FOUND;