3 * Copyright (c) 2000-2012 Samsung Electronics Co., Ltd. All Rights Reserved.
5 * This file is part of msg-service.
7 * Contact: Jaeyun Jeong <jyjeong@samsung.com>
8 * Sangkoo Kim <sangkoo.kim@samsung.com>
9 * Seunghwan Lee <sh.cat.lee@samsung.com>
10 * SoonMin Jung <sm0415.jung@samsung.com>
11 * Jae-Young Lee <jy4710.lee@samsung.com>
12 * KeeBum Kim <keebum.kim@samsung.com>
14 * PROPRIETARY/CONFIDENTIAL
16 * This software is the confidential and proprietary information of
17 * SAMSUNG ELECTRONICS ("Confidential Information"). You shall not
18 * disclose such Confidential Information and shall use it only in
19 * accordance with the terms of the license agreement you entered
20 * into with SAMSUNG ELECTRONICS.
22 * SAMSUNG make no representations or warranties about the suitability
23 * of the software, either express or implied, including but not limited
24 * to the implied warranties of merchantability, fitness for a particular
25 * purpose, or non-infringement. SAMSUNG shall not be liable for any
26 * damages suffered by licensee as a result of using, modifying or
27 * distributing this software or its derivatives.
32 #include "MsgCppTypes.h"
33 #include "MsgException.h"
34 #include "MsgGconfWrapper.h"
35 #include "SmsPluginParamCodec.h"
36 #include "SmsPluginUDCodec.h"
37 #include "SmsPluginSetting.h"
38 #include "SmsPluginTransport.h"
39 #include "SmsPluginEventHandler.h"
40 #include "SmsPluginSatHandler.h"
44 #include <ITapiNetText.h>
48 /*==================================================================================================
49 IMPLEMENTATION OF SmsPluginCbMsgHandler - Member Functions
50 ==================================================================================================*/
51 SmsPluginSatHandler* SmsPluginSatHandler::pInstance = NULL;
54 SmsPluginSatHandler::SmsPluginSatHandler()
65 SmsPluginSatHandler::~SmsPluginSatHandler()
71 SmsPluginSatHandler* SmsPluginSatHandler::instance()
74 pInstance = new SmsPluginSatHandler();
80 void SmsPluginSatHandler::refreshSms(void *pData)
82 TelSatRefreshInd_t* pRefreshData = (TelSatRefreshInd_t*)pData;
84 if (pRefreshData->appType != TAPI_SAT_REFRESH_MSG)
86 MSG_DEBUG("App Type is wrong. [%d]", pRefreshData->appType);
90 commandId = pRefreshData->commandId;
92 switch (pRefreshData->refreshMode)
94 case TAPI_SAT_REFRESH_SIM_INIT_AND_FULL_FCN :
95 case TAPI_SAT_REFRESH_SIM_INIT_AND_FCN :
97 for (int i = 0; i < pRefreshData->fileCount; i++)
99 if ((SMS_SIM_EFILE_NAME_T)pRefreshData->fileId[i].FileName == SMS_SIM_EFILE_USIM_SMSP ||
100 (SMS_SIM_EFILE_NAME_T)pRefreshData->fileId[i].FileName == SMS_SIM_EFILE_SMSP)
104 else if ((SMS_SIM_EFILE_NAME_T)pRefreshData->fileId[i].FileName == SMS_SIM_EFILE_USIM_CBMI ||
105 (SMS_SIM_EFILE_NAME_T)pRefreshData->fileId[i].FileName == SMS_SIM_EFILE_CBMI)
115 case TAPI_SAT_REFRESH_FCN :
117 for (int i = 0; i < pRefreshData->fileCount; i++)
119 if ((SMS_SIM_EFILE_NAME_T)pRefreshData->fileId[i].FileName == SMS_SIM_EFILE_USIM_SMSP ||
120 (SMS_SIM_EFILE_NAME_T)pRefreshData->fileId[i].FileName == SMS_SIM_EFILE_SMSP)
124 else if ((SMS_SIM_EFILE_NAME_T)pRefreshData->fileId[i].FileName == SMS_SIM_EFILE_USIM_CBMI ||
125 (SMS_SIM_EFILE_NAME_T)pRefreshData->fileId[i].FileName == SMS_SIM_EFILE_CBMI)
133 case TAPI_SAT_REFRESH_SIM_INIT :
145 void SmsPluginSatHandler::sendSms(void *pData)
147 TelSatSendSmsIndSmsData_t* pSmsData = (TelSatSendSmsIndSmsData_t*)pData;
151 commandId = pSmsData->commandId;
153 MSG_DEBUG("commandId [%d]", commandId);
155 // The TPDU Maximum Length at SAT side is 175
156 // This is because Sat can send 160 bytes unpacked and header
157 unsigned char tpdu[MAX_SAT_TPDU_LEN+1];
160 memset(tpdu, 0x00, sizeof(tpdu));
161 memcpy(tpdu, pSmsData->smsTpdu.data, pSmsData->smsTpdu.dataLen);
163 // Modify Parameters, Pack User Data
164 tpduLen = handleSatTpdu(tpdu, pSmsData->smsTpdu.dataLen, pSmsData->bIsPackingRequired);
166 if (tpduLen <= 0 || tpduLen > MAX_TPDU_DATA_LEN)
168 sendResult(SMS_SAT_CMD_SEND_SMS, TAPI_SAT_R_BEYOND_ME_CAPABILITIES);
172 // Make Telephony Structure
173 TelSmsDatapackageInfo_t pkgInfo;
176 memset((void*)pkgInfo.szData, 0x00, sizeof(pkgInfo.szData));
177 memcpy((void*)pkgInfo.szData, tpdu, tpduLen);
179 pkgInfo.szData[tpduLen] = '\0';
180 pkgInfo.MsgLength = tpduLen;
185 if (pSmsData->address.diallingNumberLen > 0)
187 smsc.ton = pSmsData->address.ton;
188 smsc.npi = pSmsData->address.npi;
189 memcpy(smsc.address, pSmsData->address.diallingNumber, pSmsData->address.diallingNumberLen);
190 smsc.address[pSmsData->address.diallingNumberLen] = '\0';
192 MSG_DEBUG("SCA TON[%d], NPI[%d], LEN[%d], ADDR[%s]", smsc.ton, smsc.npi, strlen(smsc.address), smsc.address);
197 SmsPluginTransport::instance()->setSmscOptions(&smsc);
200 unsigned char smscAddr[MAX_SMSC_LEN];
201 memset(smscAddr, 0x00, sizeof(smscAddr));
203 int smscLen = SmsPluginParamCodec::encodeSMSC(&smsc, smscAddr);
205 if (smscLen <= 0) return;
208 memset(pkgInfo.Sca, 0x00, sizeof(pkgInfo.Sca));
209 memcpy((void*)pkgInfo.Sca, smscAddr, smscLen);
210 pkgInfo.Sca[smscLen] = '\0';
212 int reqId = 0, tapiRet = TAPI_API_SUCCESS;
215 tapiRet = tel_send_sms(&pkgInfo, 0, &reqId);
217 if (tapiRet == TAPI_API_SUCCESS)
219 MSG_DEBUG("######## TelTapiSmsSend Success !!! return : %d #######", tapiRet);
223 MSG_DEBUG("######## TelTapiSmsSend Fail !!! return : %d #######", tapiRet);
224 sendResult(SMS_SAT_CMD_SEND_SMS, TAPI_SAT_R_BEYOND_ME_CAPABILITIES);
229 void SmsPluginSatHandler::ctrlSms(void *pData)
231 TelSatMoSmCtrlIndData_t* pCtrlData = (TelSatMoSmCtrlIndData_t*)pData;
233 if (bSendSms == true) // Send SMS By SAT
235 if (pCtrlData->moSmsCtrlResult == TAPI_SAT_CALL_CTRL_R_NOT_ALLOWED)
237 MSG_DEBUG("SIM does not allow to send SMS");
239 sendResult(SMS_SAT_CMD_SEND_SMS, TAPI_SAT_R_INTRCTN_WITH_CC_OR_SMS_CTRL_PRMNT_PRBLM);
241 else if (pCtrlData->moSmsCtrlResult == TAPI_SAT_CALL_CTRL_R_ALLOWED_WITH_MOD)
243 MSG_DEBUG("SIM allows to send SMS with modification");
245 sendResult(SMS_SAT_CMD_SEND_SMS, TAPI_SAT_R_SUCCESS);
248 else // Send SMS By APP
250 MSG_NETWORK_STATUS_T netStatus = MSG_NETWORK_NOT_SEND;
252 if (pCtrlData->moSmsCtrlResult == TAPI_SAT_CALL_CTRL_R_NOT_ALLOWED)
254 MSG_DEBUG("SIM does not allow to send SMS");
256 netStatus = MSG_NETWORK_SEND_FAIL;
258 else if (pCtrlData->moSmsCtrlResult == TAPI_SAT_CALL_CTRL_R_ALLOWED_WITH_MOD)
260 MSG_DEBUG("SIM allows to send SMS with modification");
262 netStatus = MSG_NETWORK_SEND_SUCCESS;
265 // Call Event Handler
266 SmsPluginEventHandler::instance()->handleSentStatus(-1, netStatus);
271 void SmsPluginSatHandler::ctrlSms(MSG_NETWORK_STATUS_T netStatus)
273 if (bSendSms == true) // Send SMS By SAT
275 if (netStatus == MSG_NETWORK_SEND_SUCCESS)
277 MSG_DEBUG("Sending SMS by SAT is OK");
279 sendResult(SMS_SAT_CMD_SEND_SMS, TAPI_SAT_R_SUCCESS);
281 else if (netStatus == MSG_NETWORK_SEND_FAIL)
283 MSG_DEBUG("Sending SMS by SAT is failed");
285 sendResult(SMS_SAT_CMD_SEND_SMS, TAPI_SAT_R_SMS_RP_ERROR);
291 void SmsPluginSatHandler::finishSimMsgInit(MSG_ERROR_T Err)
293 // SAT Handler is initializing SIM now
294 if (bInitSim == true)
296 // Init SMSC List and CB ID Info
299 if (bSMSPChanged == true) initSMSCList();
301 catch (MsgException& e)
303 // Send Result to TAPI
304 sendResult(SMS_SAT_CMD_REFRESH, TAPI_SAT_R_ME_UNABLE_TO_PROCESS_COMMAND);
306 MSG_FATAL("%s", e.what());
312 if (bCBMIChanged == true) initCBConfig();
314 catch (MsgException& e)
316 // Send Result to TAPI
317 sendResult(SMS_SAT_CMD_REFRESH, TAPI_SAT_R_ME_UNABLE_TO_PROCESS_COMMAND);
319 MSG_FATAL("%s", e.what());
323 // Send Result to TAPI
324 sendResult(SMS_SAT_CMD_REFRESH, TAPI_SAT_R_SUCCESS);
329 void SmsPluginSatHandler::initSim()
334 if (SmsPluginEventHandler::instance()->callbackInitSimBySat() != MSG_SUCCESS)
336 MSG_DEBUG("Init Sim Error");
338 // Send Result to TAPI
339 sendResult(SMS_SAT_CMD_REFRESH, TAPI_SAT_R_ME_UNABLE_TO_PROCESS_COMMAND);
344 void SmsPluginSatHandler::initSMSCList()
346 MSG_SETTING_S settingData;
348 settingData.type = MSG_SMSC_LIST;
351 SmsPluginSetting::instance()->getConfigData(&settingData);
353 MSG_DEBUG("total_count[%d]", settingData.option.smscList.totalCnt);
354 MSG_DEBUG("selected[%d]", settingData.option.smscList.selected);
356 for (int i = 0; i < settingData.option.smscList.totalCnt; i++)
358 MSG_DEBUG("pid[%d]", settingData.option.smscList.smscData[i].pid);
359 MSG_DEBUG("val_period[%d]", settingData.option.smscList.smscData[i].valPeriod);
360 MSG_DEBUG("name[%s]", settingData.option.smscList.smscData[i].name);
362 MSG_DEBUG("ton[%d]", settingData.option.smscList.smscData[i].smscAddr.ton);
363 MSG_DEBUG("npi[%d]", settingData.option.smscList.smscData[i].smscAddr.npi);
364 MSG_DEBUG("address[%s]", settingData.option.smscList.smscData[i].smscAddr.address);
367 if (MsgSettingSetInt(SMSC_SELECTED, settingData.option.smscList.selected) != MSG_SUCCESS)
369 THROW(MsgException::SMS_PLG_ERROR, "Error to set config data [%s]", SMSC_SELECTED);
373 if (MsgSettingSetInt(SMSC_TOTAL_COUNT, settingData.option.smscList.totalCnt) != MSG_SUCCESS)
375 THROW(MsgException::SMS_PLG_ERROR, "Error to set config data [%s]", SMSC_TOTAL_COUNT);
380 MSG_ERROR_T err = MSG_SUCCESS;
382 for (int i = 0; i < settingData.option.smscList.totalCnt; i++)
384 memset(keyName, 0x00, sizeof(keyName));
385 sprintf(keyName, "%s/%d", SMSC_PID, i);
387 if ((err = MsgSettingSetInt(keyName, (int)settingData.option.smscList.smscData[i].pid)) != MSG_SUCCESS)
390 memset(keyName, 0x00, sizeof(keyName));
391 sprintf(keyName, "%s/%d", SMSC_VAL_PERIOD, i);
393 if ((err = MsgSettingSetInt(keyName, (int)settingData.option.smscList.smscData[i].valPeriod)) != MSG_SUCCESS)
396 memset(keyName, 0x00, sizeof(keyName));
397 sprintf(keyName, "%s/%d", SMSC_NAME, i);
399 if ((err = MsgSettingSetString(keyName, settingData.option.smscList.smscData[i].name)) != MSG_SUCCESS)
402 memset(keyName, 0x00, sizeof(keyName));
403 sprintf(keyName, "%s/%d", SMSC_TON, i);
405 if ((err = MsgSettingSetInt(keyName, (int)settingData.option.smscList.smscData[i].smscAddr.ton)) != MSG_SUCCESS)
408 memset(keyName, 0x00, sizeof(keyName));
409 sprintf(keyName, "%s/%d", SMSC_NPI, i);
411 if ((err = MsgSettingSetInt(keyName, (int)settingData.option.smscList.smscData[i].smscAddr.npi)) != MSG_SUCCESS)
414 memset(keyName, 0x00, sizeof(keyName));
415 sprintf(keyName, "%s/%d", SMSC_ADDRESS, i);
417 if ((err = MsgSettingSetString(keyName, settingData.option.smscList.smscData[i].smscAddr.address)) != MSG_SUCCESS)
421 if (err != MSG_SUCCESS)
423 THROW(MsgException::SMS_PLG_ERROR, "Error to set config data [%s]", keyName);
428 void SmsPluginSatHandler::initCBConfig()
430 MSG_SETTING_S settingData;
432 settingData.type = MSG_CBMSG_OPT;
435 SmsPluginSetting::instance()->getConfigData(&settingData);
437 if (MsgSettingSetBool(CB_RECEIVE, settingData.option.cbMsgOpt.bReceive) != MSG_SUCCESS)
439 THROW(MsgException::SMS_PLG_ERROR, "Error to set config data [%s]", CB_RECEIVE);
443 if (MsgSettingSetBool(CB_ALL_CHANNEL, settingData.option.cbMsgOpt.bAllChannel) != MSG_SUCCESS)
445 THROW(MsgException::SMS_PLG_ERROR, "Error to set config data [%s]", CB_ALL_CHANNEL);
449 if (MsgSettingSetInt(CB_MAX_SIM_COUNT, settingData.option.cbMsgOpt.maxSimCnt) != MSG_SUCCESS)
451 THROW(MsgException::SMS_PLG_ERROR, "Error to set config data [%s]", CB_MAX_SIM_COUNT);
455 if (MsgSettingSetInt(CB_CHANNEL_COUNT, settingData.option.cbMsgOpt.channelData.channelCnt) != MSG_SUCCESS)
457 THROW(MsgException::SMS_PLG_ERROR, "Error to set config data [%s]", CB_CHANNEL_COUNT);
462 MSG_ERROR_T err = MSG_SUCCESS;
464 for (int i = 0; i < settingData.option.cbMsgOpt.channelData.channelCnt; i++)
466 memset(keyName, 0x00, sizeof(keyName));
467 sprintf(keyName, "%s/%d", CB_CHANNEL_ACTIVATE, i);
469 if ((err = MsgSettingSetBool(keyName, settingData.option.cbMsgOpt.channelData.channelInfo[i].bActivate)) != MSG_SUCCESS)
472 memset(keyName, 0x00, sizeof(keyName));
473 sprintf(keyName, "%s/%d", CB_CHANNEL_ID, i);
475 if ((err = MsgSettingSetInt(keyName, settingData.option.cbMsgOpt.channelData.channelInfo[i].id)) != MSG_SUCCESS)
478 memset(keyName, 0x00, sizeof(keyName));
479 sprintf(keyName, "%s/%d", CB_CHANNEL_NAME, i);
481 if ((err = MsgSettingSetString(keyName, settingData.option.cbMsgOpt.channelData.channelInfo[i].name)) != MSG_SUCCESS)
485 if (err != MSG_SUCCESS)
487 THROW(MsgException::SMS_PLG_ERROR, "Error to set config data [%s]", keyName);
492 int SmsPluginSatHandler::handleSatTpdu(unsigned char *pTpdu, unsigned char TpduLen, int bIsPackingRequired)
495 THROW(MsgException::SMS_PLG_ERROR, "SAT TPDU is NULL");
499 // TP-MTI, TP-RD, TP-VPF, TP-RP, TP-UDHI, TP-SRR
501 SMS_VPF_T vpf = (SMS_VPF_T)(pTpdu[pos++] & 0x18);
504 unsigned char tmpRef = pTpdu[pos];
506 MSG_DEBUG("current Msg Ref : %d", tmpRef);
508 pTpdu[pos] = tmpRef + 1;
510 MSG_DEBUG("new Msg Ref : %d", pTpdu[pos]);
515 SMS_ADDRESS_S destAddr = {0};
516 int addrLen = SmsPluginParamCodec::decodeAddress(&pTpdu[pos], &destAddr);
526 int dcsLen = SmsPluginParamCodec::decodeDCS(&pTpdu[pos], &dcs);
528 if (bIsPackingRequired == true)
530 dcs.codingScheme = SMS_CHARSET_7BIT;
533 AutoPtr<char> dcsBuf(&pDcs);
535 SmsPluginParamCodec::encodeDCS(&dcs, &pDcs);
537 memcpy(&(pTpdu[pos]), pDcs, dcsLen);
543 if (vpf == SMS_VPF_RELATIVE)
545 pos += MAX_REL_TIME_PARAM_LEN;
547 else if (vpf == SMS_VPF_ABSOLUTE)
549 pos += MAX_ABS_TIME_PARAM_LEN;
553 int udl = pTpdu[pos];
557 if (bIsPackingRequired == true)
559 SMS_USERDATA_S userData = {0};
561 userData.headerCnt = 0;
562 userData.length = udl;
563 memcpy(userData.data, &pTpdu[pos+1], udl);
564 userData.data[udl] = '\0';
566 MSG_DEBUG("user data : %s", userData.data);
568 int encodeSize = SmsPluginUDCodec::encodeUserData(&userData, dcs.codingScheme, (char*)&pTpdu[pos]);
570 retLen = pos + encodeSize;
581 void SmsPluginSatHandler::sendResult(SMS_SAT_CMD_TYPE_T CmdType, int ResultType)
583 TelSatAppsRetInfo_t satRetInfo;
585 satRetInfo.commandId = commandId;
587 MSG_DEBUG("satRetInfo.commandId [%d]", satRetInfo.commandId);
589 if (CmdType == SMS_SAT_CMD_REFRESH)
591 satRetInfo.commandType = TAPI_SAT_CMD_TYPE_REFRESH;
593 satRetInfo.appsRet.refresh.appType = TAPI_SAT_REFRESH_MSG;
594 satRetInfo.appsRet.refresh.resp = (TelSatResultType_t)ResultType;
596 else if (CmdType == SMS_SAT_CMD_SEND_SMS)
598 satRetInfo.commandType = TAPI_SAT_CMD_TYPE_SEND_SMS;
600 satRetInfo.appsRet.sendSms.resp = (TelSatResultType_t)ResultType;
603 int tapiRet = TAPI_API_SUCCESS;
605 tapiRet = tel_send_sat_app_exec_result(&satRetInfo);
607 if (tapiRet == TAPI_API_SUCCESS)
609 MSG_DEBUG("TelTapiSatSendAppExecutionResult() SUCCESS");
613 MSG_DEBUG("TelTapiSatSendAppExecutionResult() FAIL [%d]", tapiRet);
618 bSMSPChanged = false;
619 bCBMIChanged = false;