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.
20 #include "MsgCppTypes.h"
21 #include "MsgException.h"
22 #include "MsgGconfWrapper.h"
23 #include "SmsPluginParamCodec.h"
24 #include "SmsPluginTpduCodec.h"
25 #include "SmsPluginTransport.h"
26 #include "SmsPluginStorage.h"
27 #include "SmsPluginEventHandler.h"
28 #include "SmsPluginCallback.h"
29 #include "MsgUtilStorage.h"
30 #include "MsgNotificationWrapper.h"
32 #include "SmsPluginSimMsg.h"
33 #include "SmsPluginDSHandler.h"
36 /*==================================================================================================
37 IMPLEMENTATION OF SmsPluginSimMsg - Member Functions
38 ==================================================================================================*/
39 SmsPluginSimMsg* SmsPluginSimMsg::pInstance = NULL;
42 SmsPluginSimMsg::SmsPluginSimMsg()
44 /* Initialize member variables */
50 memset(&simMsgDataInfo, 0x00, sizeof(simMsgDataInfo));
51 memset(simIdList, 0, sizeof(int) * MAX_SIM_SMS_NUM);
52 memset(&simMsgCnt, 0x00, sizeof(simMsgCnt));
53 memset(&simMsgInfo, 0x00, sizeof(simMsgInfo));
54 memset(&simAddrInfo, 0x00, sizeof(simAddrInfo));
58 SmsPluginSimMsg::~SmsPluginSimMsg()
63 SmsPluginSimMsg* SmsPluginSimMsg::instance()
66 pInstance = new SmsPluginSimMsg();
72 void SmsPluginSimMsg::initSimMessage(TapiHandle *handle)
76 char keyName[MAX_VCONFKEY_NAME_LEN] = {0, };
77 int sim_idx = SmsPluginDSHandler::instance()->getSimIndex(handle);
79 snprintf(keyName, sizeof(keyName), "%s/%d", SIM_USED_COUNT, sim_idx);
80 /* Set SIM count of vconf to 0 */
81 if (MsgSettingSetInt(keyName, 0) != MSG_SUCCESS) {
82 MSG_DEBUG("Error to set config data [%s]", keyName);
84 memset(keyName, 0, sizeof(keyName));
85 snprintf(keyName, sizeof(keyName), "%s/%d", SIM_TOTAL_COUNT, sim_idx);
87 if (MsgSettingSetInt(keyName, 0) != MSG_SUCCESS) {
88 MSG_DEBUG("Error to set config data [%s]", keyName);
91 MSG_SIM_COUNT_S tmpMsgCnt;
92 memset(&tmpMsgCnt, 0x00, sizeof(MSG_SIM_COUNT_S));
93 getSimMsgCount(handle, &tmpMsgCnt);
95 MSG_MESSAGE_INFO_S tmpMsgInfo;
96 int simIdList[MAX_SIM_SMS_NUM];
99 for (int i = 0; i < tmpMsgCnt.usedCount; i++) {
100 memset(&tmpMsgInfo, 0x00, sizeof(MSG_MESSAGE_INFO_S));
101 memset(simIdList, 0, sizeof(int) * MAX_SIM_SMS_NUM);
104 if (getSimMsg(handle, tmpMsgCnt.indexList[i], &tmpMsgInfo, simIdList) == false)
107 if (tmpMsgInfo.bRead == false)
110 if (SmsPluginEventHandler::instance()->handleSimMsg(&tmpMsgInfo, simIdList, NULL, MAX_SIM_SMS_NUM) < 0) {
111 MSG_DEBUG("Fail to handleSimMsg()");
114 if (tmpMsgInfo.addressList) {
115 free(tmpMsgInfo.addressList);
116 tmpMsgInfo.addressList = NULL;
120 MSG_DEBUG("Unread SIM message count = [%d]", unreadSimMsg);
121 #ifndef MSG_NOTI_INTEGRATION
122 if (unreadSimMsg > 0) {
123 MsgRefreshNotification(MSG_NOTI_TYPE_SIM, true, MSG_ACTIVE_NOTI_TYPE_NONE);
127 if (SmsPluginEventHandler::instance()->updateIMSI(sim_idx) != MSG_SUCCESS) {
128 MSG_ERR("Fail to handleSimMsg()");
135 msg_error_t SmsPluginSimMsg::saveSimMessage(const MSG_MESSAGE_INFO_S *pMsgInfo, SMS_SIM_ID_LIST_S *pSimIdList)
139 TapiHandle *handle = SmsPluginDSHandler::instance()->getTelHandle(pMsgInfo->sim_idx);
140 char keyName[MAX_VCONFKEY_NAME_LEN];
141 memset(keyName, 0x00, sizeof(keyName));
142 snprintf(keyName, sizeof(keyName), "%s/%d", MSG_SIM_SERVICE_TABLE, pMsgInfo->sim_idx);
143 if (MsgSettingGetBool(keyName, &bSimSst) != MSG_SUCCESS)
144 MSG_DEBUG("MsgSettingGetBool [%s] failed", keyName);
145 /* No return, default value is true. */
147 if (bSimSst == false)
148 return MSG_ERR_STORE_RESTRICT;
150 /* Reset Out Parameter */
151 pSimIdList->count = 0;
154 memset(&tpdu, 0x00, sizeof(SMS_TPDU_S));
155 if (pMsgInfo->direction == MSG_DIRECTION_TYPE_MO) {
156 tpdu.tpduType = SMS_TPDU_SUBMIT;
157 tpdu.data.submit.dcs.msgClass = SMS_MSG_CLASS_NONE;
158 /*SmsPluginTransport::instance()->setSmsSendOptions(&(tpdu.data.submit));*/
159 tpdu.data.submit.vpf = SMS_VPF_NOT_PRESENT;
160 tpdu.data.submit.dcs.codingScheme = SMS_CHARSET_AUTO;
162 tpdu.tpduType = SMS_TPDU_DELIVER;
163 setSmsOptions(pMsgInfo, &(tpdu.data.deliver));
165 convertTimeStamp(pMsgInfo, &(tpdu.data.deliver));
166 tpdu.data.deliver.dcs.codingScheme = SMS_CHARSET_AUTO;
169 for (int i = 0; i <pMsgInfo->nAddressCnt; ++i) {
170 SMS_SUBMIT_DATA_S submitData;
171 memset(&submitData, 0x00, sizeof(SMS_SUBMIT_DATA_S));
173 char buf[MAX_TPDU_DATA_LEN];
175 if (pMsgInfo->direction == MSG_DIRECTION_TYPE_MO) { /* SUBMIT MSG */
176 SmsPluginTransport::instance()->msgInfoToSubmitData(pMsgInfo, &submitData, &(tpdu.data.submit.dcs.codingScheme), i);
178 int addLen = strlen(submitData.destAddress.address);
180 tpdu.data.submit.destAddress.ton = submitData.destAddress.ton;
181 tpdu.data.submit.destAddress.npi = submitData.destAddress.npi;
183 if (addLen < MAX_ADDRESS_LEN) {
184 memcpy(tpdu.data.submit.destAddress.address, submitData.destAddress.address, addLen);
185 tpdu.data.submit.destAddress.address[addLen] = '\0';
187 memcpy(tpdu.data.submit.destAddress.address, submitData.destAddress.address, MAX_ADDRESS_LEN);
188 tpdu.data.submit.destAddress.address[MAX_ADDRESS_LEN] = '\0';
191 } else { /* DELIVER MSG */
192 SmsPluginTransport::instance()->msgInfoToSubmitData(pMsgInfo, &submitData, &(tpdu.data.deliver.dcs.codingScheme), i);
194 int addLen = strlen(submitData.destAddress.address);
196 tpdu.data.deliver.originAddress.ton = submitData.destAddress.ton;
197 tpdu.data.deliver.originAddress.npi = submitData.destAddress.npi;
199 if (addLen < MAX_ADDRESS_LEN) {
200 memcpy(tpdu.data.deliver.originAddress.address, submitData.destAddress.address, addLen);
201 tpdu.data.deliver.originAddress.address[addLen] = '\0';
203 memcpy(tpdu.data.deliver.originAddress.address, submitData.destAddress.address, MAX_ADDRESS_LEN);
204 tpdu.data.deliver.originAddress.address[MAX_ADDRESS_LEN] = '\0';
208 /* Check sim message full. */
209 if (checkSimMsgFull(pMsgInfo->sim_idx, submitData.segCount) == true) {
210 MSG_DEBUG("SIM storage is full.");
211 MsgInsertTicker("Sim memory full. Delete some items", SMS_MESSAGE_SIM_MESSAGE_FULL, true, 0);
213 return MSG_ERR_SIM_STORAGE_FULL;
216 if (submitData.segCount > 1) {
217 if (pMsgInfo->direction == MSG_DIRECTION_TYPE_MO) { /* SUBMIT MSG */
218 tpdu.data.submit.bHeaderInd = true;
220 tpdu.data.deliver.bHeaderInd = true;
224 for (unsigned int segCnt = 0; segCnt < submitData.segCount; segCnt++) {
225 if (pMsgInfo->direction == MSG_DIRECTION_TYPE_MO) {
226 memcpy(&(tpdu.data.submit.userData), &(submitData.userData[segCnt]), sizeof(SMS_USERDATA_S));
228 memcpy(&(tpdu.data.deliver.userData), &(submitData.userData[segCnt]), sizeof(SMS_USERDATA_S));
231 memset(buf, 0x00, sizeof(buf));
233 /* Encode SMS-DELIVER TPDU */
234 bufLen = SmsPluginTpduCodec::encodeTpdu(&tpdu, buf);
236 /* Make Telephony Structure */
237 TelSmsData_t simSmsData;
238 memset((void*)&simSmsData, 0x00, sizeof(simSmsData));
241 memcpy((void*)simSmsData.SmsData.szData, buf, bufLen);
243 simSmsData.SmsData.szData[bufLen] = 0;
244 simSmsData.SmsData.MsgLength = bufLen;
245 simSmsData.SmsData.format = TAPI_NETTEXT_NETTYPE_3GPP;
247 if (pMsgInfo->direction == MSG_DIRECTION_TYPE_MT) { /* MT messages */
248 if (pMsgInfo->bRead == true)
249 simSmsData.MsgStatus = TAPI_NETTEXT_STATUS_READ;
251 simSmsData.MsgStatus = TAPI_NETTEXT_STATUS_UNREAD;
252 } else { /* MO messages */
253 if (pMsgInfo->networkStatus == MSG_NETWORK_SEND_SUCCESS)
254 simSmsData.MsgStatus = TAPI_NETTEXT_STATUS_SENT;
255 else if (pMsgInfo->networkStatus == MSG_NETWORK_DELIVER_SUCCESS)
256 simSmsData.MsgStatus = TAPI_NETTEXT_STATUS_DELIVERED;
257 else if (pMsgInfo->networkStatus == MSG_NETWORK_DELIVER_FAIL)
258 simSmsData.MsgStatus = TAPI_NETTEXT_STATUS_DELIVERY_UNCONFIRMED;
260 simSmsData.MsgStatus = TAPI_NETTEXT_STATUS_UNSENT;
263 /* Save SMS in SIM */
266 ret = tel_write_sms_in_sim(handle, &simSmsData, TapiEventSaveSimMsg, NULL);
268 if (ret == TAPI_API_SUCCESS) {
269 MSG_DEBUG("######## tel_write_sms_in_sim Success !!!#######");
271 MSG_DEBUG("######## tel_write_sms_in_sim Fail !!! return : [%d] #######", ret);
273 return MSG_ERR_PLUGIN_STORAGE;
276 msg_sim_id_t SimId = 0;
278 bool bResult = false;
280 bResult = getSimEvent(&SimId);
284 if (bResult == true) {
285 MSG_DEBUG("######## Saving Msg was Successful !!! SIM ID : [%d] #######", SimId);
287 char keyName[MAX_VCONFKEY_NAME_LEN];
288 memset(keyName, 0x00, sizeof(keyName));
289 snprintf(keyName, sizeof(keyName), "%s/%d", SIM_USED_COUNT, pMsgInfo->sim_idx);
290 if (MsgSettingGetInt(keyName, &usedCnt) != MSG_SUCCESS) {
291 MSG_INFO("MsgSettingGetInt() is failed");
295 if (MsgSettingSetInt(keyName, usedCnt) != MSG_SUCCESS)
296 MSG_DEBUG("Error to set config data [%s]", SIM_USED_COUNT);
298 pSimIdList->simId[pSimIdList->count] = SimId;
301 MSG_DEBUG("######## Saving Msg was Failed !!! SIM ID : [%d] #######", SimId);
303 return MSG_ERR_PLUGIN_STORAGE;
311 msg_error_t SmsPluginSimMsg::saveClass2Message(const MSG_MESSAGE_INFO_S *pMsgInfo)
313 msg_error_t err = MSG_SUCCESS;
315 int tapiRet = TAPI_API_SUCCESS;
317 int replaceSimId = -1;
318 int replaceMsgId = 0;
320 TapiHandle *handle = SmsPluginDSHandler::instance()->getTelHandle(pMsgInfo->sim_idx);
322 char keyName[MAX_VCONFKEY_NAME_LEN];
323 memset(keyName, 0x00, sizeof(keyName));
324 snprintf(keyName, sizeof(keyName), "%s/%d", MSG_SIM_SERVICE_TABLE, pMsgInfo->sim_idx);
325 if (MsgSettingGetBool(keyName, &bSimSst) != MSG_SUCCESS)
326 MSG_DEBUG("MsgSettingGetBool [%s] failed", keyName);
327 /* No return, default value is true. */
329 if (bSimSst == false) {
330 SmsPluginTransport::instance()->sendDeliverReport(handle, MSG_SUCCESS);
337 tpdu.tpduType = SMS_TPDU_DELIVER;
339 convertTimeStamp(pMsgInfo, &(tpdu.data.deliver));
341 /* Set SMS TPDU Options */
342 setSmsOptions(pMsgInfo, &(tpdu.data.deliver));
344 SMS_SUBMIT_DATA_S submitData;
346 char buf[MAX_TPDU_DATA_LEN];
348 SmsPluginTransport::instance()->msgInfoToSubmitData(pMsgInfo, &submitData, &(tpdu.data.deliver.dcs.codingScheme), 0);
350 if (pMsgInfo->msgType.subType >= MSG_REPLACE_TYPE1_SMS && pMsgInfo->msgType.subType <= MSG_REPLACE_TYPE7_SMS) {
351 err = SmsPluginStorage::instance()->getReplaceSimMsg(pMsgInfo, &replaceMsgId, &replaceSimId);
352 MSG_DEBUG("getReplaceSimMsg(): err=[%d], Replace Sim Id = [%d], Replace message id = [%d]", err, replaceSimId, replaceMsgId);
353 if (replaceMsgId < 0)
358 if (replaceSimId < 0) { /* Normal message type */
359 /* Check sim message full. */
360 if (checkSimMsgFull(pMsgInfo->sim_idx, submitData.segCount) == true) {
361 MSG_ERR("SIM storage is full.");
363 SmsPluginTransport::instance()->sendDeliverReport(handle, MSG_ERR_SIM_STORAGE_FULL);
365 return MSG_ERR_SIM_STORAGE_FULL;
368 int addLen = strlen(submitData.destAddress.address);
370 tpdu.data.deliver.originAddress.ton = submitData.destAddress.ton;
371 tpdu.data.deliver.originAddress.npi = submitData.destAddress.npi;
373 if (addLen < MAX_ADDRESS_LEN) {
374 memcpy(tpdu.data.deliver.originAddress.address, submitData.destAddress.address, addLen);
375 tpdu.data.deliver.originAddress.address[addLen] = '\0';
377 memcpy(tpdu.data.deliver.originAddress.address, submitData.destAddress.address, MAX_ADDRESS_LEN);
378 tpdu.data.deliver.originAddress.address[MAX_ADDRESS_LEN] = '\0';
381 if (submitData.segCount > 1)
382 tpdu.data.deliver.bHeaderInd = true;
383 } else { /* Replace message type */
384 tapiRet = tel_delete_sms_in_sim(handle, replaceSimId, TapiEventDeleteSimMsg, NULL);
386 if (tapiRet == TAPI_API_SUCCESS) {
387 MSG_DEBUG("######## tel_delete_sms_in_sim Success !!! #######");
390 if (getDelSimEvent(&simId) == true) {
391 err = SmsPluginStorage::instance()->deleteSimMessage(pMsgInfo->sim_idx, replaceSimId);
393 MSG_DEBUG("tel_delete_sms_in_sim() : Err=[%d], Replace Sim Id=[%d], Result Sim id=[%d]", err, replaceSimId, simId);
396 MSG_DEBUG("######## tel_delete_sms_in_sim Fail !!! return : [%d] #######", tapiRet);
400 for (unsigned int segCnt = 0; segCnt < submitData.segCount; segCnt++) {
401 /* Create TelSmsData_t data */
402 TelSmsData_t simSmsData = {0, };
404 if (submitData.segCount == 1) {
405 memcpy(&simSmsData.SmsData.Sca, &simMsgDataInfo.sca, sizeof(simSmsData.SmsData.Sca)-1);
406 memcpy(&simSmsData.SmsData.szData, &simMsgDataInfo.szData, sizeof(simSmsData.SmsData.szData)-1);
407 simSmsData.SmsData.MsgLength = simMsgDataInfo.msgLength;
410 memcpy(&(tpdu.data.deliver.userData), &(submitData.userData[segCnt]), sizeof(SMS_USERDATA_S));
412 memset(buf, 0x00, sizeof(buf));
414 /* Encode SMS-DELIVER TPDU */
415 bufLen = SmsPluginTpduCodec::encodeTpdu(&tpdu, buf);
418 int copyLen = (bufLen > TAPI_NETTEXT_SMDATA_SIZE_MAX) ? TAPI_NETTEXT_SMDATA_SIZE_MAX : bufLen;
419 memcpy((void*)simSmsData.SmsData.Sca, &simMsgDataInfo.sca, sizeof(simSmsData.SmsData.Sca)-1);
420 memcpy((void*)simSmsData.SmsData.szData, buf, (size_t)copyLen);
421 simSmsData.SmsData.szData[copyLen] = 0;
422 simSmsData.SmsData.MsgLength = copyLen;
425 simSmsData.SmsData.format = TAPI_NETTEXT_NETTYPE_3GPP;
426 simSmsData.MsgStatus = TAPI_NETTEXT_STATUS_UNREAD;
428 MSG_MESSAGE_INFO_S *tmpSimMsgInfo = (MSG_MESSAGE_INFO_S *)calloc(1, sizeof(MSG_MESSAGE_INFO_S));
430 memcpy(tmpSimMsgInfo, pMsgInfo, sizeof(MSG_MESSAGE_INFO_S));
432 tmpSimMsgInfo->msgId = replaceMsgId;
434 tmpSimMsgInfo->addressList = NULL;
435 tmpSimMsgInfo->addressList = (MSG_ADDRESS_INFO_S *)new char[sizeof(MSG_ADDRESS_INFO_S)];
436 memcpy(&tmpSimMsgInfo->addressList[0], &pMsgInfo->addressList[0], sizeof(MSG_ADDRESS_INFO_S));
438 tapiRet = tel_write_sms_in_sim(handle, &simSmsData, TapiEventSaveClass2Msg, tmpSimMsgInfo);
440 if (tapiRet == TAPI_API_SUCCESS) {
441 MSG_DEBUG("######## tel_write_sms_in_sim Success !!!, segNum = [%d] #######", segCnt);
443 MSG_DEBUG("######## tel_write_sms_in_sim Fail !!! return : [%d] #######", tapiRet);
445 SmsPluginTransport::instance()->sendDeliverReport(handle, MSG_ERR_STORAGE_ERROR);
447 return MSG_ERR_PLUGIN_STORAGE;
451 msg_sim_id_t retSimId;
452 if (!getSimEvent(&retSimId))
453 return MSG_ERR_PLUGIN_STORAGE;
460 void SmsPluginSimMsg::deleteSimMessage(msg_sim_slot_id_t sim_idx, msg_sim_id_t SimMsgId)
462 int tapiRet = TAPI_API_SUCCESS;
464 TapiHandle *handle = SmsPluginDSHandler::instance()->getTelHandle(sim_idx);
465 tapiRet = tel_delete_sms_in_sim(handle, (int)SimMsgId, TapiEventDeleteSimMsg, NULL);
467 if (tapiRet == TAPI_API_SUCCESS)
468 MSG_DEBUG("######## tel_delete_sms_in_sim Success !!! #######");
470 THROW(MsgException::SMS_PLG_ERROR, "######## tel_delete_sms_in_sim Fail !!! return : [%d] #######", tapiRet);
473 bool bResult = false;
475 bResult = getDelSimEvent(&SimId);
477 int usedCnt = 0, totalCnt = 0;
479 if (bResult == true) {
480 MSG_DEBUG("######## Deleting Msg was Successful !!! SIM ID : [%d] #######", SimId);
481 char keyName[MAX_VCONFKEY_NAME_LEN];
482 memset(keyName, 0x00, sizeof(keyName));
483 snprintf(keyName, sizeof(keyName), "%s/%d", SIM_USED_COUNT, sim_idx);
484 if (MsgSettingGetInt(keyName, &usedCnt) != MSG_SUCCESS) {
485 MSG_INFO("MsgSettingGetInt() is failed");
487 memset(keyName, 0x00, sizeof(keyName));
488 snprintf(keyName, sizeof(keyName), "%s/%d", SIM_TOTAL_COUNT, sim_idx);
489 if (MsgSettingGetInt(keyName, &totalCnt) != MSG_SUCCESS) {
490 MSG_INFO("MsgSettingGetInt() is failed");
493 if (usedCnt == totalCnt) {
494 tapiRet = tel_set_sms_memory_status(handle, TAPI_NETTEXT_PDA_MEMORY_STATUS_AVAILABLE, NULL, NULL);
496 if (tapiRet == TAPI_API_SUCCESS)
497 MSG_DEBUG("######## tel_set_sms_memory_status() Success !!! #######");
499 MSG_DEBUG("######## tel_set_sms_memory_status() Success !!! return : [%d] #######", tapiRet);
504 memset(keyName, 0x00, sizeof(keyName));
505 snprintf(keyName, sizeof(keyName), "%s/%d", SIM_USED_COUNT, sim_idx);
507 if (MsgSettingSetInt(keyName, usedCnt) != MSG_SUCCESS)
508 MSG_DEBUG("Error to set config data [%s]", keyName);
510 THROW(MsgException::SMS_PLG_ERROR, "######## Deleting Msg was Failed !!! SIM ID : [%d] #######", SimId);
515 bool SmsPluginSimMsg::checkSimMsgFull(msg_sim_slot_id_t sim_idx, unsigned int SegCnt)
517 int usedCnt = 0, totalCnt = 0;
519 char keyName[MAX_VCONFKEY_NAME_LEN];
520 memset(keyName, 0x00, sizeof(keyName));
521 snprintf(keyName, sizeof(keyName), "%s/%d", SIM_USED_COUNT, sim_idx);
522 if (MsgSettingGetInt(keyName, &usedCnt) != MSG_SUCCESS) {
523 MSG_INFO("MsgSettingGetInt() is failed");
525 memset(keyName, 0x00, sizeof(keyName));
526 snprintf(keyName, sizeof(keyName), "%s/%d", SIM_TOTAL_COUNT, sim_idx);
527 if (MsgSettingGetInt(keyName, &totalCnt) != MSG_SUCCESS) {
528 MSG_INFO("MsgSettingGetInt() is failed");
531 MSG_DEBUG("Segment Count [%d]", SegCnt);
532 MSG_DEBUG("usedCnt [%d], totalCnt [%d]", usedCnt, totalCnt);
534 if ((usedCnt + (int)SegCnt) <= totalCnt)
541 void SmsPluginSimMsg::setReadStatus(msg_sim_slot_id_t sim_idx, msg_sim_id_t SimMsgId)
543 MSG_DEBUG("Sim Message ID [%d]", SimMsgId);
545 int ret = TAPI_API_SUCCESS;
546 TapiHandle *handle = SmsPluginDSHandler::instance()->getTelHandle(sim_idx);
548 ret = tel_set_sms_message_status(handle, (int)SimMsgId, TAPI_NETTEXT_STATUS_READ, TapiEventSetMsgStatus, (void *)&SimMsgId);
550 if (ret == TAPI_API_SUCCESS)
551 MSG_DEBUG("######## tel_set_sms_message_status Success !!! return : %d #######", ret);
553 THROW(MsgException::SMS_PLG_ERROR, "######## tel_set_sms_message_status Fail !!! return : %d #######", ret);
555 msg_sim_id_t SimId = 0;
556 bool bResult = false;
558 bResult = getSimEvent(&SimId);
561 MSG_DEBUG("######## Setting Read Status was Successful !!!, sim id=[%d] #######", SimId);
563 THROW(MsgException::SMS_PLG_ERROR, "######## Setting Read Status was Failed !!! #######");
567 void SmsPluginSimMsg::getSimMsgCount(TapiHandle *handle, MSG_SIM_COUNT_S *pSimMsgCnt)
569 int ret = TAPI_API_SUCCESS;
571 ret = tel_get_sms_count(handle, TapiEventGetSimMsgCnt, NULL);
573 if (ret == TAPI_API_SUCCESS)
574 MSG_DEBUG("######## tel_get_sms_count() Success !!! #######");
576 THROW(MsgException::SMS_PLG_ERROR, "######## tel_get_sms_count() Fail !!! return : %d #######", ret);
578 if (getSimMsgCntEvent(handle, pSimMsgCnt) == true)
579 MSG_DEBUG("######## Get Sim Msg Count was Successful !!! #######");
581 THROW(MsgException::SMS_PLG_ERROR, "######## Get Sim Msg Count was Failed !!! #######");
585 bool SmsPluginSimMsg::getSimMsg(TapiHandle *handle, msg_sim_id_t SimMsgId, MSG_MESSAGE_INFO_S *pMsgInfo, int *simIdList)
587 int ret = TAPI_API_SUCCESS;
589 ret = tel_read_sms_in_sim(handle, SimMsgId, TapiEventGetSimMsg, simIdList);
591 if (ret == TAPI_API_SUCCESS) {
592 MSG_DEBUG("######## tel_read_sms_in_sim() Success !!! Sim ID : [%d] #######", SimMsgId);
594 MSG_DEBUG("######## tel_read_sms_in_sim() Fail !!! return : %d #######", ret);
598 if (getSimMsgEvent(handle, pMsgInfo) == true) {
599 MSG_DEBUG("######## Get Sim Msg was Successful !!! #######");
601 MSG_DEBUG("######## Get Sim Msg was Failed !!! #######");
609 void SmsPluginSimMsg::setSmsOptions(const MSG_MESSAGE_INFO_S* pMsgInfo, SMS_DELIVER_S *pDeliver)
611 pDeliver->bMoreMsg = false;
612 pDeliver->bStatusReport = false;
613 pDeliver->bHeaderInd = false;
614 pDeliver->bReplyPath = false;
616 pDeliver->dcs.bCompressed = false;
617 pDeliver->dcs.msgClass = SMS_MSG_CLASS_NONE;
618 pDeliver->dcs.codingGroup = SMS_GROUP_GENERAL;
620 pDeliver->dcs.codingScheme = pMsgInfo->encodeType;
622 MSG_DEBUG("DCS : %d", pDeliver->dcs.codingScheme);
624 pDeliver->pid = SMS_PID_NORMAL;
626 MSG_DEBUG("PID : %d", pDeliver->pid);
630 void SmsPluginSimMsg::convertTimeStamp(const MSG_MESSAGE_INFO_S* pMsgInfo, SMS_DELIVER_S *pDeliver)
634 /* encode time stamp */
635 pDeliver->timeStamp.format = SMS_TIME_ABSOLUTE;
637 /* encode absolute time */
638 struct tm timeinfo = {0, };
640 localtime_r(&pMsgInfo->displayTime, &timeinfo);
642 pDeliver->timeStamp.time.absolute.year = timeinfo.tm_year - 100;
643 MSG_DEBUG("pDeliver->timeStamp.time.absolute.year is %d", pDeliver->timeStamp.time.absolute.year);
645 pDeliver->timeStamp.time.absolute.month = timeinfo.tm_mon + 1;
646 MSG_DEBUG("pDeliver->timeStamp.time.absolute.month is %d", pDeliver->timeStamp.time.absolute.month);
648 pDeliver->timeStamp.time.absolute.day = timeinfo.tm_mday;
649 MSG_DEBUG("pDeliver->timeStamp.time.absolute.day is %d", pDeliver->timeStamp.time.absolute.day);
651 pDeliver->timeStamp.time.absolute.hour = timeinfo.tm_hour;
652 MSG_DEBUG("pDeliver->timeStamp.time.absolute.hour is %d", pDeliver->timeStamp.time.absolute.hour);
654 pDeliver->timeStamp.time.absolute.minute = timeinfo.tm_min;
655 MSG_DEBUG("pDeliver->timeStamp.time.absolute.minute is %d", pDeliver->timeStamp.time.absolute.minute);
657 pDeliver->timeStamp.time.absolute.second = timeinfo.tm_sec;
658 MSG_DEBUG("pDeliver->timeStamp.time.absolute.second is %d", pDeliver->timeStamp.time.absolute.second);
660 pDeliver->timeStamp.time.absolute.timeZone = 0;
661 MSG_DEBUG("pDeliver->timeStamp.time.absolute.timeZone is %d", pDeliver->timeStamp.time.absolute.timeZone);
667 void SmsPluginSimMsg::setSimMsgCntEvent(TapiHandle *handle, const MSG_SIM_COUNT_S *pSimMsgCnt)
671 MSG_INFO("Sim Message Count is %d.", pSimMsgCnt->usedCount);
673 int sim_idx = SmsPluginDSHandler::instance()->getSimIndex(handle);
674 char keyName[MAX_VCONFKEY_NAME_LEN] = {0, };
676 for (int i = 0; i < pSimMsgCnt->usedCount; i++) {
677 MSG_DEBUG("Sim Message Index is %d.", pSimMsgCnt->indexList[i]);
680 snprintf(keyName, sizeof(keyName), "%s/%d", SIM_USED_COUNT, sim_idx);
681 if (MsgSettingSetInt(keyName, pSimMsgCnt->usedCount) != MSG_SUCCESS)
682 MSG_ERR("Error to set config data [%s]", SIM_USED_COUNT);
684 memset(keyName, 0, sizeof(keyName));
685 snprintf(keyName, sizeof(keyName), "%s/%d", SIM_TOTAL_COUNT, sim_idx);
686 if (MsgSettingSetInt(keyName, (int)pSimMsgCnt->totalCount) != MSG_SUCCESS)
687 MSG_ERR("Error to set config data [%s]", SIM_TOTAL_COUNT);
689 memset(&simMsgCnt, 0x00, sizeof(MSG_SIM_COUNT_S));
690 memcpy(&simMsgCnt, pSimMsgCnt, sizeof(MSG_SIM_COUNT_S));
698 bool SmsPluginSimMsg::getSimMsgCntEvent(TapiHandle *handle, MSG_SIM_COUNT_S *pSimMsgCnt)
704 ret = cv.timedwait(mx.pMutex(), 10);
708 if (ret == ETIMEDOUT) {
709 MSG_ERR("WARNING: TAPI callback TIME-OUT");
713 memcpy(pSimMsgCnt, &simMsgCnt, sizeof(MSG_SIM_COUNT_S));
718 void SmsPluginSimMsg::setSimMsgEvent(TapiHandle *handle, const MSG_MESSAGE_INFO_S *pMsgInfo, bool bSuccess)
722 bTapiResult = bSuccess;
724 memset(&simMsgInfo, 0x00, sizeof(MSG_MESSAGE_INFO_S));
725 memset(&simAddrInfo, 0x00, sizeof(MSG_ADDRESS_INFO_S));
727 if (bTapiResult == true) {
728 MSG_DEBUG("Success to get sim msg - Id : [%d]", pMsgInfo->msgId);
730 memcpy(&simMsgInfo, pMsgInfo, sizeof(MSG_MESSAGE_INFO_S));
731 simMsgInfo.addressList = &simAddrInfo;
732 memcpy(&simAddrInfo, pMsgInfo->addressList, sizeof(MSG_ADDRESS_INFO_S));
741 bool SmsPluginSimMsg::getSimMsgEvent(TapiHandle *handle, MSG_MESSAGE_INFO_S *pMsgInfo)
748 ret = cv.timedwait(mx.pMutex(), 10);
752 if (ret == ETIMEDOUT) {
753 MSG_DEBUG("WARNING: TAPI callback TIME-OUT");
757 memset(pMsgInfo, 0x00, sizeof(MSG_MESSAGE_INFO_S));
759 if (bTapiResult == true) {
760 memcpy(pMsgInfo, &simMsgInfo, sizeof(MSG_MESSAGE_INFO_S));
761 pMsgInfo->addressList = (MSG_ADDRESS_INFO_S *)calloc(1, sizeof(MSG_ADDRESS_INFO_S));
762 memset(pMsgInfo->addressList, 0x00, sizeof(MSG_ADDRESS_INFO_S));
763 memcpy(pMsgInfo->addressList, simMsgInfo.addressList, sizeof(MSG_ADDRESS_INFO_S));
764 pMsgInfo->sim_idx = SmsPluginDSHandler::instance()->getSimIndex(handle);
772 void SmsPluginSimMsg::setSaveSimMsgEvent(TapiHandle *handle, int simId, int result)
774 msg_error_t err = MSG_SUCCESS;
778 if (result != TAPI_NETTEXT_SENDSMS_SUCCESS) {
779 if (result == TAPI_NETTEXT_ROUTING_NOT_AVAILABLE || result == TAPI_NETTEXT_SIM_FULL)
780 err = MSG_ERR_SIM_STORAGE_FULL;
782 err = MSG_ERR_UNKNOWN;
785 if (err == MSG_SUCCESS)
796 int tapiRet = TAPI_API_SUCCESS;
798 if (err == MSG_SUCCESS) {
799 tapiRet = tel_set_sms_memory_status(handle, TAPI_NETTEXT_PDA_MEMORY_STATUS_AVAILABLE, TapiEventMemoryStatus, NULL);
800 } else if (err == MSG_ERR_SIM_STORAGE_FULL) {
801 tapiRet = tel_set_sms_memory_status(handle, TAPI_NETTEXT_PDA_MEMORY_STATUS_FULL, TapiEventMemoryStatus, NULL);
806 if (tapiRet == TAPI_API_SUCCESS) {
807 MSG_DEBUG("######## tel_set_sms_memory_status() Success !!! #######");
809 MSG_DEBUG("######## tel_set_sms_memory_status() Failed !!! return : [%d] #######", tapiRet);
814 void SmsPluginSimMsg::setSaveClass2MsgEvent(TapiHandle *handle, int simId, int result, MSG_MESSAGE_INFO_S *pMsgInfo)
816 msg_error_t err = MSG_SUCCESS;
817 /*int sim_idx = SmsPluginDSHandler::instance()->getSimIndex(handle); */
819 if (result == TAPI_NETTEXT_SENDSMS_SUCCESS && simId >= 0 && pMsgInfo) {
820 bool isNewSimMsg = true;
822 for (int i = 0; i < MAX_SIM_SMS_NUM; i++) {
823 if (simIdList[i] != 0) {
824 MSG_DEBUG("simIdList[%d] is exist [%d]", i, simIdList[i]);
827 simIdList[i] = simId + 1;
828 MSG_DEBUG("simIdList[%d] is assigned [%d]", i, simId + 1);
833 if (pMsgInfo->msgType.subType >= MSG_REPLACE_TYPE1_SMS && pMsgInfo->msgType.subType <= MSG_REPLACE_TYPE7_SMS) {
834 if (pMsgInfo->msgId > 0) {
839 if (simMsgDataInfo.totalSegment >= 1 && simIdList[simMsgDataInfo.totalSegment-1] != 0) {
840 msg_message_id_t saved_msg_id = 0;
841 SmsPluginEventHandler::instance()->handleSimMsg(pMsgInfo, simIdList, &saved_msg_id, MAX_SIM_SMS_NUM);
843 MSG_DEBUG("Saved message ID = [%d]", saved_msg_id);
845 if (saved_msg_id > 0)
846 pMsgInfo->msgId = saved_msg_id;
848 err = SmsPluginEventHandler::instance()->callbackMsgIncoming(pMsgInfo);
850 if (err != MSG_SUCCESS)
851 MSG_DEBUG("callbackMsgIncoming() Error !! [%d]", err);
854 if (isNewSimMsg == true) {
855 char keyName[MAX_VCONFKEY_NAME_LEN];
856 memset(keyName, 0x00, sizeof(keyName));
857 snprintf(keyName, sizeof(keyName), "%s/%d", SIM_USED_COUNT, pMsgInfo->sim_idx);
858 if (MsgSettingGetInt(keyName, &usedCnt) != MSG_SUCCESS) {
859 MSG_INFO("MsgSettingGetInt() is failed");
863 if (MsgSettingSetInt(keyName, usedCnt) != MSG_SUCCESS)
864 MSG_DEBUG("Error to set config data [%s]", SIM_USED_COUNT);
867 if (simMsgDataInfo.totalSegment >= 1 && simIdList[simMsgDataInfo.totalSegment-1] != 0) {
868 memset(simIdList, 0, sizeof(int) * MAX_SIM_SMS_NUM);
871 if (result == TAPI_NETTEXT_SIM_FULL)
872 err = MSG_ERR_SIM_STORAGE_FULL;
874 err = MSG_ERR_UNKNOWN;
877 /* Send Deliver Report */
878 SmsPluginTransport::instance()->sendDeliverReport(handle, err);
882 void SmsPluginSimMsg::setSimEvent(msg_sim_id_t SimId, bool bResult)
887 bTapiResult = bResult;
895 bool SmsPluginSimMsg::getSimEvent(msg_sim_id_t *pSimId)
902 ret = cv.timedwait(mx.pMutex(), 10);
906 if (ret == ETIMEDOUT) {
907 MSG_DEBUG("WARNING: TAPI callback TIME-OUT");
913 MSG_DEBUG("Returned SimMsgId is %d.", simMsgId);
919 void SmsPluginSimMsg::setDelSimEvent(int SimId, bool bResult)
924 bTapiResult = bResult;
932 bool SmsPluginSimMsg::getDelSimEvent(int *pSimId)
940 ret = cv.timedwait(mx.pMutex(), 10);
944 if (ret == ETIMEDOUT) {
945 MSG_DEBUG("WARNING: TAPI callback TIME-OUT");
949 *pSimId = delSimMsgId;
951 MSG_DEBUG("Returned delSimMsgId is %d.", delSimMsgId);
957 void SmsPluginSimMsg::setSmsData(const char *sca, const char *szData, int msgLength)
959 MSG_DEBUG("Set SMS data(class2 message)");
961 memset(&simMsgDataInfo, 0x00, sizeof(simMsgDataInfo));
963 memcpy(&simMsgDataInfo.sca, sca, sizeof(simMsgDataInfo.sca)-1);
964 memcpy(&simMsgDataInfo.szData, szData, sizeof(simMsgDataInfo.szData)-1);
965 simMsgDataInfo.msgLength = msgLength;
968 void SmsPluginSimMsg::setSmsTpduTotalSegCount(int totalSeg)
970 MSG_DEBUG("Set SMS Segements Info");
972 simMsgDataInfo.totalSegment = totalSeg;