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.
23 #include "MsgUtilFile.h"
24 #include "MsgCppTypes.h"
25 #include "MsgContact.h"
26 #include "MsgGconfWrapper.h"
27 #include "MsgNotificationWrapper.h"
28 #include "MsgDevicedWrapper.h"
29 #include "SmsPluginTransport.h"
30 #include "SmsPluginSimMsg.h"
31 #include "SmsPluginStorage.h"
32 #include "SmsPluginSetting.h"
33 #include "SmsPluginConcatHandler.h"
34 #include "SmsPluginEventHandler.h"
35 #include "SmsPluginDSHandler.h"
38 /*==================================================================================================
39 IMPLEMENTATION OF SmsPluginEventHandler - Member Functions
40 ==================================================================================================*/
41 SmsPluginEventHandler* SmsPluginEventHandler::pInstance = NULL;
44 SmsPluginEventHandler::SmsPluginEventHandler()
46 /** Initialize global parameters */
47 memset(&listener, 0x00, sizeof(MSG_PLUGIN_LISTENER_S));
51 bUdhMwiMethod = false;
57 SmsPluginEventHandler::~SmsPluginEventHandler()
63 SmsPluginEventHandler* SmsPluginEventHandler::instance()
66 pInstance = new SmsPluginEventHandler();
72 void SmsPluginEventHandler::registerListener(MSG_PLUGIN_LISTENER_S *pListener)
74 listener = *pListener;
78 void SmsPluginEventHandler::handleSentStatus(msg_network_status_t NetStatus)
80 MSG_DEBUG("NetStatus[%d]", NetStatus);
82 if (sentInfo.bLast == true || NetStatus != MSG_NETWORK_SEND_SUCCESS) {
83 /** Update Msg Status */
84 if (sentInfo.reqInfo.msgInfo.msgPort.valid == false) {
85 // SmsPluginStorage::instance()->updateSentMsg(&(sentInfo.reqInfo.msgInfo), NetStatus);
87 sentInfo.reqInfo.msgInfo.networkStatus = NetStatus;
89 if (NetStatus == MSG_NETWORK_SEND_SUCCESS) {
90 //contacts-service is not used for gear
91 #ifndef MSG_CONTACTS_SERVICE_NOT_SUPPORTED
92 MSG_DEBUG("Add phone log");
93 MsgAddPhoneLog(&(sentInfo.reqInfo.msgInfo));
94 #endif //MSG_CONTACTS_SERVICE_NOT_SUPPORTED
95 sentInfo.reqInfo.msgInfo.folderId = MSG_SENTBOX_ID; // It should be set after adding phone log.
97 sentInfo.reqInfo.msgInfo.bRead = false;
100 callbackStorageChange(MSG_STORAGE_CHANGE_UPDATE, &(sentInfo.reqInfo.msgInfo));
103 MSG_DEBUG("sentInfo.reqInfo.sendOptInfo.bSetting [%d]", sentInfo.reqInfo.sendOptInfo.bSetting);
104 MSG_DEBUG("sentInfo.reqInfo.sendOptInfo.bKeepCopy [%d]", sentInfo.reqInfo.sendOptInfo.bKeepCopy);
105 /** Check sending options */
106 if (sentInfo.reqInfo.sendOptInfo.bSetting && !sentInfo.reqInfo.sendOptInfo.bKeepCopy && NetStatus == MSG_NETWORK_SEND_SUCCESS) {
107 // SmsPluginStorage::instance()->deleteSmsMessage(sentInfo.reqInfo.msgInfo.msgId);
108 callbackStorageChange(MSG_STORAGE_CHANGE_DELETE, &(sentInfo.reqInfo.msgInfo));
111 /** Callback to MSG FW */
112 MSG_SENT_STATUS_S msgStatus;
114 msgStatus.reqId = sentInfo.reqInfo.reqId;
115 msgStatus.status = NetStatus;
117 MSG_DEBUG("sentStatus.reqId : %d", msgStatus.reqId);
118 MSG_DEBUG("sentStatus.status : %d", msgStatus.status);
120 listener.pfSentStatusCb(&msgStatus);
125 void SmsPluginEventHandler::handleMsgIncoming(struct tapi_handle *handle, SMS_TPDU_S *pTpdu)
128 /** Make MSG_MESSAGE_INFO_S */
129 MSG_MESSAGE_INFO_S msgInfo;
131 /** initialize msgInfo */
132 memset(&msgInfo, 0x00, sizeof(MSG_MESSAGE_INFO_S));
134 msgInfo.addressList = NULL;
135 AutoPtr<MSG_ADDRESS_INFO_S> addressListBuf(&msgInfo.addressList);
138 if (pTpdu->tpduType == SMS_TPDU_DELIVER) {
139 /** check unsupported message */
140 if (pTpdu->data.deliver.dcs.codingScheme == SMS_CHARSET_8BIT && pTpdu->data.deliver.pid == 0x11) {
141 MSG_DEBUG("Unsupported message!!");
142 SmsPluginTransport::instance()->sendDeliverReport(handle, MSG_SUCCESS);
147 bUdhMwiMethod = false;
150 if(pTpdu->data.deliver.dcs.msgClass == SMS_MSG_CLASS_2)
151 msgInfo.storageId = MSG_STORAGE_UNKNOWN;
153 msgInfo.storageId = MSG_STORAGE_PHONE;
155 msgInfo.sim_idx = SmsPluginDSHandler::instance()->getSimIndex(handle);
157 /** convert to msgInfo */
158 convertTpduToMsginfo(pTpdu, &msgInfo);
160 if (msgInfo.msgPort.valid == true) {
161 if ((msgInfo.msgPort.dstPort >= 0x23F4 && msgInfo.msgPort.dstPort <= 0x23F7) || /** Check unsupported message (Vcard WAP push) **/
162 (msgInfo.msgPort.dstPort == 0x1581)) { /** Check unsupported message (ringtone smart message) **/
163 memset(msgInfo.msgText, 0x00, sizeof(msgInfo.msgText));
164 snprintf(msgInfo.msgText, sizeof(msgInfo.msgText), "<Unsupported message>");
165 msgInfo.dataSize = strlen(msgInfo.msgText);
166 msgInfo.msgPort.valid = false;
170 if (bUdhMwiMethod == false) {
171 /** check MWI and set info to SIM for DCS & Address method */
172 if (pTpdu->tpduType == SMS_TPDU_DELIVER && pTpdu->data.deliver.dcs.bMWI == true) {
173 MSG_DEBUG("MWI message - DCS method");
175 if (pTpdu->data.deliver.dcs.bIndActive == false) {
176 SmsPluginSetting::instance()->setMwiInfo(msgInfo.sim_idx, msgInfo.msgType.subType, 0);
177 SmsPluginTransport::instance()->sendDeliverReport(handle, MSG_SUCCESS);
180 SmsPluginSetting::instance()->setMwiInfo(msgInfo.sim_idx, msgInfo.msgType.subType, 1);
182 /* For address method */
183 if (pTpdu->data.deliver.pid == 0x20 && pTpdu->data.deliver.originAddress.ton == SMS_TON_ALPHANUMERIC) {
184 MSG_DEBUG("MWI message - Address method");
185 char *voiceNumber = NULL;
186 char *voiceAlphaId = NULL;
187 char keyName[MAX_VCONFKEY_NAME_LEN];
189 memset(keyName, 0x00, sizeof(keyName));
190 snprintf(keyName, sizeof(keyName), "%s/%d", VOICEMAIL_NUMBER, msgInfo.sim_idx);
191 voiceNumber = MsgSettingGetString(keyName);
193 memset(keyName, 0x00, sizeof(keyName));
194 snprintf(keyName, sizeof(keyName), "%s/%d", VOICEMAIL_ALPHA_ID, msgInfo.sim_idx);
195 voiceAlphaId = MsgSettingGetString(keyName);
197 memset(msgInfo.addressList[0].addressVal, 0x00, sizeof(msgInfo.addressList[0].addressVal));
198 memset(msgInfo.addressList[0].displayName, 0x00, sizeof(msgInfo.addressList[0].displayName));
201 snprintf(msgInfo.addressList[0].addressVal, sizeof(msgInfo.addressList[0].addressVal), "%s", voiceNumber);
207 snprintf(msgInfo.addressList[0].displayName, sizeof(msgInfo.addressList[0].displayName), "%s", voiceAlphaId);
212 memset(msgInfo.msgText, 0x00, sizeof(msgInfo.msgText));
213 snprintf(msgInfo.msgText, sizeof(msgInfo.msgText), "New voice message");
218 if (pTpdu->data.deliver.dcs.codingGroup == SMS_GROUP_DISCARD)
219 msgInfo.bStore = false;
222 MSG_DEBUG("MWI message - UDH method");
223 if (udhMwiCnt <= 0) {
224 MSG_DEBUG("MWI count is 0");
225 SmsPluginSetting::instance()->setMwiInfo(msgInfo.sim_idx, msgInfo.msgType.subType, 0);
226 SmsPluginTransport::instance()->sendDeliverReport(handle, MSG_SUCCESS);
231 /** Short Message Type 0 - Just Send Deliver Report */
232 if (msgInfo.msgType.subType == MSG_TYPE0_SMS) {
233 SmsPluginTransport::instance()->sendDeliverReport(handle, MSG_SUCCESS);
237 /** Print MSG_MESSAGE_INFO_S */
238 MSG_DEBUG("############# Convert tpdu values to Message Info values ####################");
239 MSG_DEBUG("msgInfo.nAddressCnt : %d", msgInfo.nAddressCnt);
240 if (msgInfo.nAddressCnt > 0) {
241 MSG_DEBUG("msgInfo.addressList[0].addressType : %d", msgInfo.addressList[0].addressType);
242 MSG_SEC_DEBUG("msgInfo.addressList[0].addressVal : %s", msgInfo.addressList[0].addressVal);
243 MSG_SEC_DEBUG("msgInfo.addressList[0].displayName : %s", msgInfo.addressList[0].displayName);
245 MSG_DEBUG("msgInfo.priority : %d", msgInfo.priority);
246 MSG_DEBUG("msgInfo.bProtected : %d", msgInfo.bProtected);
247 MSG_DEBUG("msgInfo.bRead : %d", msgInfo.bRead);
248 MSG_DEBUG("msgInfo.bTextSms : %d", msgInfo.bTextSms);
249 MSG_DEBUG("msgInfo.bStore : %d", msgInfo.bStore);
250 MSG_DEBUG("msgInfo.direction : %d", msgInfo.direction);
251 MSG_DEBUG("msgInfo.msgType.mainType : %d", msgInfo.msgType.mainType);
252 MSG_DEBUG("msgInfo.msgType.subType : %d", msgInfo.msgType.subType);
253 MSG_DEBUG("msgInfo.msgType.classType : %d", msgInfo.msgType.classType);
254 MSG_DEBUG("msgInfo.displayTime : %s", ctime(&msgInfo.displayTime));
255 MSG_DEBUG("msgInfo.msgPort.valid : %d", msgInfo.msgPort.valid);
256 MSG_DEBUG("msgInfo.encodeType : %d", msgInfo.encodeType);
257 MSG_DEBUG("msgInfo.dataSize : %d", msgInfo.dataSize);
258 MSG_DEBUG("msgInfo.sim_idx : %d", msgInfo.sim_idx);
260 if (msgInfo.bTextSms == true) {
261 MSG_SEC_DEBUG("msgInfo.msgText : %s", msgInfo.msgText);
263 MSG_SEC_DEBUG("msgInfo.msgData : %s", msgInfo.msgData);
266 MSG_DEBUG("###############################################################");
268 msg_error_t err = MSG_SUCCESS;
270 if (msgInfo.msgType.subType == MSG_STATUS_REPORT_SMS) {
271 /** Status Report Message */
272 err = SmsPluginStorage::instance()->updateMsgDeliverStatus(&msgInfo, pTpdu->data.statusRep.msgRef);
274 if (err == MSG_SUCCESS)
275 err = listener.pfMsgIncomingCb(&msgInfo);
277 MSG_DEBUG("updateMsgDeliverStatus is failed [%d]", err);
279 /** Handling of Fail Case ?? */
280 SmsPluginTransport::instance()->sendDeliverReport(handle, MSG_SUCCESS);
281 } else { /** SMS Deliver */
283 if (msgInfo.msgType.classType == MSG_CLASS_2) {
284 if (msgInfo.bTextSms == false) { /** Concat Msg cannot be saved in SIM */
285 msgInfo.msgType.classType = MSG_CLASS_NONE;
286 msgInfo.storageId = MSG_STORAGE_PHONE;
288 /** set total segment of Class2 message as 1 */
289 SmsPluginSimMsg::instance()->setSmsTpduTotalSegCount(1);
293 /** Add message to DB */
294 if (msgInfo.msgPort.valid == false) {
295 err = SmsPluginStorage::instance()->checkMessage(&msgInfo);
298 /** Callback to MSG FW */
299 if (msgInfo.msgType.classType == MSG_CLASS_2) {
300 if (((msgInfo.msgType.subType >= MSG_MWI_VOICE_SMS) && (msgInfo.msgType.subType <= MSG_MWI_OTHER_SMS)) &&
301 (msgInfo.bStore == false)) {
302 if (listener.pfMsgIncomingCb(&msgInfo) != MSG_SUCCESS)
303 MSG_DEBUG("listener.pfMsgIncomingCb is failed!");
305 SmsPluginTransport::instance()->sendDeliverReport(handle, MSG_SUCCESS);
308 if (err == MSG_SUCCESS) {
309 MSG_DEBUG("callback to msg fw");
310 err = listener.pfMsgIncomingCb(&msgInfo);
312 if (msgInfo.msgType.classType == MSG_CLASS_0) {
313 MSG_DEBUG("callback for class0 message to msg fw");
314 if (listener.pfMsgIncomingCb(&msgInfo) != MSG_SUCCESS)
315 MSG_DEBUG("listener.pfMsgIncomingCb is failed!");
319 /** Send Deliver Report */
320 if (msgInfo.msgType.classType == MSG_CLASS_0)
321 SmsPluginTransport::instance()->sendClass0DeliverReport(handle, err);
323 SmsPluginTransport::instance()->sendDeliverReport(handle, err);
326 // Tizen Validation System
328 char keyName[MAX_VCONFKEY_NAME_LEN];
329 memset(keyName, 0x00, sizeof(keyName));
330 snprintf(keyName, sizeof(keyName), "%s/%d", MSG_SIM_MSISDN, msgInfo.sim_idx);
331 msisdn = MsgSettingGetString(keyName);
333 MSG_SMS_VLD_INFO("%d, SMS Receive, %s->%s, %s", msgInfo.msgId, \
334 msgInfo.addressList[0].addressVal, \
335 (msisdn == NULL)?"ME":msisdn, \
336 (err == MSG_SUCCESS)?"Success":"Fail");
338 MSG_SMS_VLD_TXT("%d, [%s]", msgInfo.msgId, msgInfo.msgText);
347 void SmsPluginEventHandler::handlePushMsgIncoming(char* pPushHeader, char* pPushBody, int pushBodyLen, char *application_id, char *content_type)
349 MSG_PUSH_MESSAGE_DATA_S pushData;
351 memset(&pushData, 0x00, sizeof(MSG_PUSH_MESSAGE_DATA_S));
354 memcpy(pushData.pushHeader, pPushHeader, strlen(pPushHeader));
356 pushData.pushBodyLen = pushBodyLen;
357 memcpy(pushData.pushBody, pPushBody, pushBodyLen);
359 memcpy(pushData.pushAppId, application_id, MAX_WAPPUSH_ID_LEN);
360 memcpy(pushData.pushContentType, content_type, MAX_WAPPUSH_CONTENT_TYPE_LEN);
362 /** Callback to MSG FW */
363 listener.pfPushMsgIncomingCb(&pushData);
367 void SmsPluginEventHandler::handleResendMessage(void)
369 listener.pfResendMessageCb();
373 void SmsPluginEventHandler::handleSyncMLMsgIncoming(msg_syncml_message_type_t msgType, char* pPushBody, int PushBodyLen, char* pWspHeader, int WspHeaderLen,int simIndex)
375 MSG_SYNCML_MESSAGE_DATA_S syncMLData;
377 memset(&syncMLData, 0x00, sizeof(MSG_SYNCML_MESSAGE_DATA_S));
379 /** set syncML data */
380 syncMLData.syncmlType = msgType;
382 syncMLData.simIndex = simIndex;
384 syncMLData.pushBodyLen = PushBodyLen;
385 memcpy(syncMLData.pushBody, pPushBody, PushBodyLen);
387 syncMLData.wspHeaderLen= WspHeaderLen;
388 memcpy(syncMLData.wspHeader, pWspHeader, WspHeaderLen);
390 /** Callback to MSG FW */
391 listener.pfSyncMLMsgIncomingCb(&syncMLData);
395 void SmsPluginEventHandler::handleLBSMsgIncoming(char* pPushHeader, char* pPushBody, int pushBodyLen)
397 MSG_LBS_MESSAGE_DATA_S lBSData;
399 memset(&lBSData, 0x00, sizeof(MSG_LBS_MESSAGE_DATA_S));
402 memcpy(lBSData.pushHeader, pPushHeader, strlen(pPushHeader));
404 lBSData.pushBodyLen = pushBodyLen;
405 memcpy(lBSData.pushBody, pPushBody, pushBodyLen);
407 /** Callback to MSG FW */
408 listener.pfLBSMsgIncomingCb(&lBSData);
411 msg_error_t SmsPluginEventHandler::callbackMsgIncoming(MSG_MESSAGE_INFO_S *pMsgInfo)
415 msg_error_t err = MSG_SUCCESS;
417 /** Callback to MSG FW */
418 err = listener.pfMsgIncomingCb(pMsgInfo);
425 msg_error_t SmsPluginEventHandler::callbackCBMsgIncoming(MSG_CB_MSG_S *pCbMsg, MSG_MESSAGE_INFO_S *pMsgInfo)
429 msg_error_t err = MSG_SUCCESS;
431 /** Callback to MSG FW */
432 err = listener.pfCBMsgIncomingCb(pCbMsg, pMsgInfo);
440 msg_error_t SmsPluginEventHandler::callbackInitSimBySat()
442 /** Callback to MSG FW */
443 return listener.pfInitSimBySatCb();
447 msg_error_t SmsPluginEventHandler::callbackStorageChange(msg_storage_change_type_t storageChangeType, MSG_MESSAGE_INFO_S *pMsgInfo)
449 /** Callback to MSG FW */
450 listener.pfStorageChangeCb(storageChangeType, pMsgInfo);
456 void SmsPluginEventHandler::convertTpduToMsginfo(SMS_TPDU_S *pTpdu, MSG_MESSAGE_INFO_S *msgInfo)
459 switch(pTpdu->tpduType)
461 case SMS_TPDU_SUBMIT :
462 convertSubmitTpduToMsginfo(&pTpdu->data.submit, msgInfo);
464 case SMS_TPDU_DELIVER :
465 convertDeliverTpduToMsginfo(&pTpdu->data.deliver, msgInfo);
467 case SMS_TPDU_STATUS_REP :
468 convertStatusRepTpduToMsginfo(&pTpdu->data.statusRep, msgInfo);
474 void SmsPluginEventHandler::convertSubmitTpduToMsginfo(const SMS_SUBMIT_S *pTpdu, MSG_MESSAGE_INFO_S *msgInfo)
476 int addressListCnt = 0;
478 /** Convert Type values */
479 msgInfo->msgType.mainType = MSG_SMS_TYPE;
480 msgInfo->msgType.subType = convertMsgSubType(pTpdu->pid);
482 /** set folder id (temporary) */
483 msgInfo->folderId = MSG_SENTBOX_ID;
485 switch(pTpdu->dcs.msgClass)
487 case SMS_MSG_CLASS_0:
488 msgInfo->msgType.classType = MSG_CLASS_0;
490 case SMS_MSG_CLASS_1:
491 msgInfo->msgType.classType = MSG_CLASS_1;
493 case SMS_MSG_CLASS_2:
494 msgInfo->msgType.classType = MSG_CLASS_2;
496 case SMS_MSG_CLASS_3:
497 msgInfo->msgType.classType = MSG_CLASS_3;
500 msgInfo->msgType.classType = MSG_CLASS_NONE;
504 msgInfo->networkStatus = MSG_NETWORK_SEND_SUCCESS;
505 msgInfo->bRead = false;
506 msgInfo->bProtected = false;
507 msgInfo->priority = MSG_MESSAGE_PRIORITY_NORMAL;
508 msgInfo->direction = MSG_DIRECTION_TYPE_MO;
509 msgInfo->bTextSms = true;
511 memset(msgInfo->subject, 0x00, MAX_SUBJECT_LEN+1);
513 /** What kind of time has to be saved?? (temporary store time) */
518 msgInfo->displayTime = curTime;
520 /** Convert Address values */
521 msgInfo->nAddressCnt = 1;
523 msgInfo->addressList = (MSG_ADDRESS_INFO_S *)new char[sizeof(MSG_ADDRESS_INFO_S)];
524 memset(msgInfo->addressList, 0x00, sizeof(MSG_ADDRESS_INFO_S));
526 msgInfo->addressList[addressListCnt].addressType = MSG_ADDRESS_TYPE_PLMN;
527 strncpy(msgInfo->addressList[addressListCnt].addressVal, pTpdu->destAddress.address, MAX_ADDRESS_VAL_LEN);
529 /**exception operation for none userdata */
530 if (pTpdu->userData.length == 0) {
531 sprintf(msgInfo->msgText, "[Broken Message]");
532 msgInfo->dataSize = strlen(msgInfo->msgText);
536 /** Convert Data values */
537 MsgTextConvert *textCvt = MsgTextConvert::instance();
538 if (pTpdu->dcs.codingScheme == SMS_CHARSET_7BIT) {
539 MSG_LANG_INFO_S langInfo = {0,};
541 langInfo.bSingleShift = false;
542 langInfo.bLockingShift = false;
544 msgInfo->dataSize = textCvt->convertGSM7bitToUTF8((unsigned char*)msgInfo->msgText, MAX_MSG_TEXT_LEN, (unsigned char*)pTpdu->userData.data, pTpdu->userData.length, &langInfo);
545 } else if (pTpdu->dcs.codingScheme == SMS_CHARSET_UCS2) {
546 msgInfo->dataSize = textCvt->convertUCS2ToUTF8((unsigned char*)msgInfo->msgText, MAX_MSG_TEXT_LEN, (unsigned char*)pTpdu->userData.data, pTpdu->userData.length);
551 void SmsPluginEventHandler::convertDeliverTpduToMsginfo(const SMS_DELIVER_S *pTpdu, MSG_MESSAGE_INFO_S *msgInfo)
555 /** Convert Type values */
556 msgInfo->msgType.mainType = MSG_SMS_TYPE;
557 msgInfo->msgType.subType = convertMsgSubType(pTpdu->pid);
559 /** set folder id (temporary) */
560 msgInfo->folderId = MSG_INBOX_ID;
563 if(msgInfo->storageId == MSG_STORAGE_SIM)
565 /*** Comment below lines to save local UTC time..... (it could be used later.)
567 if (pTpdu->timeStamp.format == SMS_TIME_ABSOLUTE) {
569 MSG_DEBUG("year : %d", pTpdu->timeStamp.time.absolute.year);
570 MSG_DEBUG("month : %d", pTpdu->timeStamp.time.absolute.month);
571 MSG_DEBUG("day : %d", pTpdu->timeStamp.time.absolute.day);
572 MSG_DEBUG("hour : %d", pTpdu->timeStamp.time.absolute.hour);
573 MSG_DEBUG("minute : %d", pTpdu->timeStamp.time.absolute.minute);
574 MSG_DEBUG("second : %d", pTpdu->timeStamp.time.absolute.second);
575 MSG_DEBUG("timezone : %d", pTpdu->timeStamp.time.absolute.timeZone);
577 char displayTime[32];
581 memset(&timeinfo, 0x00, sizeof(tm));
583 timeinfo.tm_year = (pTpdu->timeStamp.time.absolute.year + 100);
584 timeinfo.tm_mon = (pTpdu->timeStamp.time.absolute.month - 1);
585 timeinfo.tm_mday = pTpdu->timeStamp.time.absolute.day;
586 timeinfo.tm_hour = pTpdu->timeStamp.time.absolute.hour;
587 timeinfo.tm_min = pTpdu->timeStamp.time.absolute.minute;
588 timeinfo.tm_sec = pTpdu->timeStamp.time.absolute.second;
589 timeinfo.tm_isdst = 0;
591 rawtime = mktime(&timeinfo);
593 MSG_DEBUG("tzname[0] [%s]", tzname[0]);
594 MSG_DEBUG("tzname[1] [%s]", tzname[1]);
595 MSG_DEBUG("timezone [%d]", timezone);
596 MSG_DEBUG("daylight [%d]", daylight);
598 memset(displayTime, 0x00, sizeof(displayTime));
599 strftime(displayTime, 32, "%Y-%02m-%02d %T %z", &timeinfo);
600 MSG_DEBUG("displayTime [%s]", displayTime);
602 rawtime -= (pTpdu->timeStamp.time.absolute.timeZone * (3600/4));
604 timeTM = localtime(&rawtime);
605 memset(displayTime, 0x00, sizeof(displayTime));
606 strftime(displayTime, 32, "%Y-%02m-%02d %T %z", timeTM);
607 MSG_DEBUG("displayTime [%s]", displayTime);
611 timeTM = localtime(&rawtime);
612 memset(displayTime, 0x00, sizeof(displayTime));
613 strftime(displayTime, 32, "%Y-%02m-%02d %T %z", timeTM);
614 MSG_DEBUG("displayTime [%s]", displayTime);
618 rawtime = time(NULL);
620 msgInfo->displayTime = rawtime;
622 switch(pTpdu->dcs.msgClass)
624 case SMS_MSG_CLASS_0:
625 msgInfo->msgType.classType = MSG_CLASS_0;
627 case SMS_MSG_CLASS_1:
628 msgInfo->msgType.classType = MSG_CLASS_1;
630 case SMS_MSG_CLASS_2:
631 msgInfo->msgType.classType = MSG_CLASS_2;
632 msgInfo->storageId = MSG_STORAGE_SIM;
634 case SMS_MSG_CLASS_3:
635 msgInfo->msgType.classType = MSG_CLASS_3;
638 msgInfo->msgType.classType = MSG_CLASS_NONE;
642 if (pTpdu->dcs.bMWI) {
643 if (pTpdu->dcs.indType == SMS_VOICE_INDICATOR)
644 msgInfo->msgType.subType = MSG_MWI_VOICE_SMS;
645 else if (pTpdu->dcs.indType == SMS_VOICE2_INDICATOR)
646 msgInfo->msgType.subType = MSG_MWI_VOICE2_SMS;
647 else if (pTpdu->dcs.indType == SMS_FAX_INDICATOR)
648 msgInfo->msgType.subType = MSG_MWI_FAX_SMS;
649 else if (pTpdu->dcs.indType == SMS_EMAIL_INDICATOR)
650 msgInfo->msgType.subType = MSG_MWI_EMAIL_SMS;
651 else if (pTpdu->dcs.indType == SMS_OTHER_INDICATOR)
652 msgInfo->msgType.subType = MSG_MWI_OTHER_SMS;
655 msgInfo->networkStatus = MSG_NETWORK_RECEIVED;
656 msgInfo->bRead = false;
657 msgInfo->bProtected = false;
658 msgInfo->priority = MSG_MESSAGE_PRIORITY_NORMAL;
659 msgInfo->direction = MSG_DIRECTION_TYPE_MT;
660 msgInfo->bTextSms = true;
662 memset(msgInfo->subject, 0x00, MAX_SUBJECT_LEN+1);
664 /** Convert Address values */
665 msgInfo->nAddressCnt = 1;
667 msgInfo->addressList = (MSG_ADDRESS_INFO_S *)new char[sizeof(MSG_ADDRESS_INFO_S)];
668 memset(msgInfo->addressList, 0x00, sizeof(MSG_ADDRESS_INFO_S));
670 msgInfo->addressList[0].addressType = MSG_ADDRESS_TYPE_PLMN;
671 strncpy(msgInfo->addressList[0].addressVal, pTpdu->originAddress.address, MAX_ADDRESS_VAL_LEN);
673 msgInfo->msgPort.valid = false;
674 msgInfo->msgPort.dstPort = 0;
675 msgInfo->msgPort.srcPort = 0;
677 for (int i = 0; i < pTpdu->userData.headerCnt; i++) {
678 /** Convert UDH values - Port Number */
679 if (pTpdu->userData.header[i].udhType == SMS_UDH_APP_PORT_8BIT) {
680 msgInfo->msgPort.valid = true;
681 msgInfo->msgPort.dstPort = pTpdu->userData.header[i].udh.appPort8bit.destPort;
682 msgInfo->msgPort.srcPort = pTpdu->userData.header[i].udh.appPort8bit.originPort;
683 } else if (pTpdu->userData.header[i].udhType == SMS_UDH_APP_PORT_16BIT) {
684 msgInfo->msgPort.valid = true;
685 msgInfo->msgPort.dstPort = pTpdu->userData.header[i].udh.appPort16bit.destPort;
686 msgInfo->msgPort.srcPort = pTpdu->userData.header[i].udh.appPort16bit.originPort;
687 } else if (pTpdu->userData.header[i].udhType == SMS_UDH_SPECIAL_SMS) {
688 msgInfo->msgType.subType = (pTpdu->userData.header[i].udh.specialInd.msgInd+MSG_MWI_VOICE_SMS);
689 msgInfo->bStore = pTpdu->userData.header[i].udh.specialInd.bStore;
691 bUdhMwiMethod = true;
693 if (pTpdu->dcs.codingGroup == SMS_GROUP_DISCARD)
694 msgInfo->bStore = false;
696 udhMwiCnt = pTpdu->userData.header[i].udh.specialInd.waitMsgNum;
697 MSG_DEBUG("Message waiting number : [%d]", udhMwiCnt);
699 SmsPluginSetting::instance()->setMwiInfo(msgInfo->sim_idx, msgInfo->msgType.subType, udhMwiCnt);
701 if (udhMwiCnt > 0 && (msgInfo->msgType.subType >= MSG_MWI_VOICE_SMS && msgInfo->msgType.subType <= MSG_MWI_OTHER_SMS)) {
702 switch (msgInfo->msgType.subType) {
703 case MSG_MWI_VOICE_SMS :
704 snprintf(msgInfo->msgText, sizeof(msgInfo->msgText), "%d", udhMwiCnt);
706 case MSG_MWI_FAX_SMS :
707 snprintf(msgInfo->msgText, sizeof(msgInfo->msgText), "%d new fax message", udhMwiCnt);
709 case MSG_MWI_EMAIL_SMS :
710 snprintf(msgInfo->msgText, sizeof(msgInfo->msgText), "%d new email message", udhMwiCnt);
713 snprintf(msgInfo->msgText, sizeof(msgInfo->msgText), "%d new special message", udhMwiCnt);
716 msgInfo->dataSize = strlen(msgInfo->msgText);
719 } else if (pTpdu->userData.header[i].udhType == SMS_UDH_ALTERNATE_REPLY_ADDRESS) {
720 strncpy(msgInfo->addressList[0].addressVal, pTpdu->userData.header[i].udh.alternateAddress.address, MAX_ADDRESS_VAL_LEN);
721 } else if (pTpdu->userData.header[i].udhType >= SMS_UDH_EMS_FIRST && pTpdu->userData.header[i].udhType <= SMS_UDH_EMS_LAST) {
722 snprintf(msgInfo->msgText, sizeof(msgInfo->msgText), "Unsupported Message");
723 msgInfo->dataSize = strlen(msgInfo->msgText);
728 /**length 0 - no user data - msg should be received */
729 if (pTpdu->userData.length <= 0) {
730 memset(msgInfo->msgText, 0x00, sizeof(msgInfo->msgText));
731 msgInfo->dataSize = 0;
733 switch(pTpdu->dcs.codingScheme)
735 case SMS_CHARSET_7BIT:
736 msgInfo->encodeType = MSG_ENCODE_GSM7BIT;
738 case SMS_CHARSET_8BIT:
739 msgInfo->encodeType = MSG_ENCODE_8BIT;
741 case SMS_CHARSET_UCS2:
742 msgInfo->encodeType = MSG_ENCODE_UCS2;
745 msgInfo->encodeType = MSG_ENCODE_8BIT;
750 } else if (pTpdu->userData.length > MAX_MSG_TEXT_LEN) {
751 sprintf(msgInfo->msgText, "[Broken Message]");
752 msgInfo->dataSize = strlen(msgInfo->msgData);
756 /** Convert Data values */
757 MsgTextConvert *textCvt = MsgTextConvert::instance();
758 if (pTpdu->dcs.codingScheme == SMS_CHARSET_7BIT) {
759 MSG_LANG_INFO_S langInfo = {0,};
761 langInfo.bSingleShift = false;
762 langInfo.bLockingShift = false;
764 for (int i = 0; i < pTpdu->userData.headerCnt; i++) {
765 if (pTpdu->userData.header[i].udhType == SMS_UDH_SINGLE_SHIFT) {
766 langInfo.bSingleShift = true;
767 langInfo.singleLang = pTpdu->userData.header[i].udh.singleShift.langId;
768 } else if (pTpdu->userData.header[i].udhType == SMS_UDH_LOCKING_SHIFT) {
769 langInfo.bLockingShift = true;
770 langInfo.lockingLang = pTpdu->userData.header[i].udh.lockingShift.langId;
774 msgInfo->encodeType = MSG_ENCODE_GSM7BIT;
775 msgInfo->dataSize = textCvt->convertGSM7bitToUTF8((unsigned char*)msgInfo->msgText, MAX_MSG_TEXT_LEN, (unsigned char*)pTpdu->userData.data, pTpdu->userData.length, &langInfo);
776 } else if (pTpdu->dcs.codingScheme == SMS_CHARSET_8BIT) {
777 msgInfo->encodeType = MSG_ENCODE_8BIT;
778 memcpy(msgInfo->msgText, pTpdu->userData.data, sizeof(pTpdu->userData.data));
779 msgInfo->dataSize = pTpdu->userData.length;
780 } else if (pTpdu->dcs.codingScheme == SMS_CHARSET_UCS2) {
781 msgInfo->encodeType = MSG_ENCODE_UCS2;
782 msgInfo->dataSize = textCvt->convertUCS2ToUTF8((unsigned char*)msgInfo->msgText, MAX_MSG_TEXT_LEN, (unsigned char*)pTpdu->userData.data, pTpdu->userData.length);
783 } else if (pTpdu->dcs.codingScheme == SMS_CHARSET_EUCKR) {
784 msgInfo->encodeType = MSG_ENCODE_8BIT;
785 msgInfo->dataSize = textCvt->convertEUCKRToUTF8((unsigned char*)msgInfo->msgText, MAX_MSG_TEXT_LEN, (unsigned char*)pTpdu->userData.data, pTpdu->userData.length);
793 void SmsPluginEventHandler::convertStatusRepTpduToMsginfo(const SMS_STATUS_REPORT_S *pTpdu, MSG_MESSAGE_INFO_S *msgInfo)
795 /** Convert Type values */
796 msgInfo->msgType.mainType = MSG_SMS_TYPE;
797 msgInfo->msgType.subType = MSG_STATUS_REPORT_SMS;
800 msgInfo->folderId = MSG_INBOX_ID;
802 /** set storage id */
803 if (msgInfo->storageId == MSG_STORAGE_UNKNOWN) {
804 msgInfo->storageId = MSG_STORAGE_PHONE;
807 switch(pTpdu->dcs.msgClass)
809 case SMS_MSG_CLASS_0:
810 msgInfo->msgType.classType = MSG_CLASS_0;
812 case SMS_MSG_CLASS_1:
813 msgInfo->msgType.classType = MSG_CLASS_1;
815 case SMS_MSG_CLASS_2:
816 msgInfo->msgType.classType = MSG_CLASS_2;
818 case SMS_MSG_CLASS_3:
819 msgInfo->msgType.classType = MSG_CLASS_3;
822 msgInfo->msgType.classType = MSG_CLASS_NONE;
826 MSG_DEBUG("delivery status : [%d]", pTpdu->status);
828 if (pTpdu->status == SMS_STATUS_RECEIVE_SUCCESS)
830 msgInfo->networkStatus = MSG_NETWORK_DELIVER_SUCCESS;
832 else if(pTpdu->status == SMS_STATUS_TRY_REQUEST_PENDING)
834 msgInfo->networkStatus = MSG_NETWORK_DELIVER_PENDING;
836 else if(pTpdu->status == SMS_STATUS_PERM_MSG_VAL_PERIOD_EXPIRED)
838 msgInfo->networkStatus = MSG_NETWORK_DELIVER_EXPIRED;
842 msgInfo->networkStatus = MSG_NETWORK_DELIVER_FAIL;
845 msgInfo->bRead = false;
846 msgInfo->bProtected = false;
847 msgInfo->priority = MSG_MESSAGE_PRIORITY_NORMAL;
848 msgInfo->direction = MSG_DIRECTION_TYPE_MT;
849 msgInfo->bTextSms = true;
851 memset(msgInfo->subject, 0x00, MAX_SUBJECT_LEN+1);
853 time_t rawtime = time(NULL);
855 /*** Comment below lines to save local UTC time..... (it could be used later.)
857 if (pTpdu->timeStamp.format == SMS_TIME_ABSOLUTE) {
859 MSG_DEBUG("year : %d", pTpdu->timeStamp.time.absolute.year);
860 MSG_DEBUG("month : %d", pTpdu->timeStamp.time.absolute.month);
861 MSG_DEBUG("day : %d", pTpdu->timeStamp.time.absolute.day);
862 MSG_DEBUG("hour : %d", pTpdu->timeStamp.time.absolute.hour);
863 MSG_DEBUG("minute : %d", pTpdu->timeStamp.time.absolute.minute);
864 MSG_DEBUG("second : %d", pTpdu->timeStamp.time.absolute.second);
865 MSG_DEBUG("timezone : %d", pTpdu->timeStamp.time.absolute.timeZone);
867 char displayTime[32];
871 memset(&timeinfo, 0x00, sizeof(tm));
873 timeinfo.tm_year = (pTpdu->timeStamp.time.absolute.year + 100);
874 timeinfo.tm_mon = (pTpdu->timeStamp.time.absolute.month - 1);
875 timeinfo.tm_mday = pTpdu->timeStamp.time.absolute.day;
876 timeinfo.tm_hour = pTpdu->timeStamp.time.absolute.hour;
877 timeinfo.tm_min = pTpdu->timeStamp.time.absolute.minute;
878 timeinfo.tm_sec = pTpdu->timeStamp.time.absolute.second;
879 timeinfo.tm_isdst = 0;
881 rawtime = mktime(&timeinfo);
883 MSG_DEBUG("tzname[0] [%s]", tzname[0]);
884 MSG_DEBUG("tzname[1] [%s]", tzname[1]);
885 MSG_DEBUG("timezone [%d]", timezone);
886 MSG_DEBUG("daylight [%d]", daylight);
888 memset(displayTime, 0x00, sizeof(displayTime));
889 strftime(displayTime, 32, "%Y-%02m-%02d %T %z", &timeinfo);
890 MSG_DEBUG("displayTime [%s]", displayTime);
892 rawtime -= (pTpdu->timeStamp.time.absolute.timeZone * (3600/4));
894 timeTM = localtime(&rawtime);
895 memset(displayTime, 0x00, sizeof(displayTime));
896 strftime(displayTime, 32, "%Y-%02m-%02d %T %z", timeTM);
897 MSG_DEBUG("displayTime [%s]", displayTime);
901 timeTM = localtime(&rawtime);
902 memset(displayTime, 0x00, sizeof(displayTime));
903 strftime(displayTime, 32, "%Y-%02m-%02d %T %z", timeTM);
904 MSG_DEBUG("displayTime [%s]", displayTime);
909 msgInfo->displayTime = rawtime;
911 /** Convert Address values */
912 msgInfo->nAddressCnt = 1;
914 msgInfo->addressList = (MSG_ADDRESS_INFO_S *)new char[sizeof(MSG_ADDRESS_INFO_S)];
915 memset(msgInfo->addressList, 0x00, sizeof(MSG_ADDRESS_INFO_S));
917 msgInfo->addressList[0].addressType = MSG_ADDRESS_TYPE_PLMN;
918 strncpy(msgInfo->addressList[0].addressVal, pTpdu->recipAddress.address, MAX_ADDRESS_VAL_LEN);
920 msgInfo->msgPort.valid = false;
921 msgInfo->msgPort.dstPort = 0;
922 msgInfo->msgPort.srcPort = 0;
924 for (int i = 0; i < pTpdu->userData.headerCnt; i++) {
925 /** Convert UDH values - Port Number */
926 if (pTpdu->userData.header[i].udhType == SMS_UDH_APP_PORT_8BIT) {
927 msgInfo->msgPort.valid = true;
928 msgInfo->msgPort.dstPort = pTpdu->userData.header[i].udh.appPort8bit.destPort;
929 msgInfo->msgPort.srcPort = pTpdu->userData.header[i].udh.appPort8bit.originPort;
930 } else if (pTpdu->userData.header[i].udhType == SMS_UDH_APP_PORT_16BIT) {
931 msgInfo->msgPort.valid = true;
932 msgInfo->msgPort.dstPort = pTpdu->userData.header[i].udh.appPort16bit.destPort;
933 msgInfo->msgPort.srcPort = pTpdu->userData.header[i].udh.appPort16bit.originPort;
937 memset(msgInfo->msgText, 0x00, sizeof(msgInfo->msgText));
938 msgInfo->dataSize = 0;
940 if (pTpdu->status <= SMS_STATUS_SMSC_SPECIFIC_LAST) {
941 strncpy(msgInfo->msgText, "IDS_MSGF_BODY_MESSAGE_DELIVERED", MAX_MSG_TEXT_LEN);
942 msgInfo->dataSize = strlen(msgInfo->msgText);
943 } else if (pTpdu->status == SMS_STATUS_TEMP_SERVICE_REJECTED) {
944 strncpy(msgInfo->msgText, "IDS_MSGF_BODY_MMSDELIVERYMSGREJECTED", MAX_MSG_TEXT_LEN);
945 msgInfo->dataSize = strlen(msgInfo->msgText);
946 } else if (pTpdu->status == SMS_STATUS_PERM_MSG_VAL_PERIOD_EXPIRED) {
947 strncpy(msgInfo->msgText, "IDS_MSGF_BODY_MESSAGE_HAS_EXPIRED", MAX_MSG_TEXT_LEN);
948 msgInfo->dataSize = strlen(msgInfo->msgText);
950 strncpy(msgInfo->msgText, "Message delivery failed.", MAX_MSG_TEXT_LEN);
951 msgInfo->dataSize = strlen(msgInfo->msgText);
956 MSG_SUB_TYPE_T SmsPluginEventHandler::convertMsgSubType(SMS_PID_T pid)
961 return MSG_TYPE0_SMS;
962 case SMS_PID_REPLACE_TYPE1 :
963 return MSG_REPLACE_TYPE1_SMS;
964 case SMS_PID_REPLACE_TYPE2 :
965 return MSG_REPLACE_TYPE2_SMS;
966 case SMS_PID_REPLACE_TYPE3 :
967 return MSG_REPLACE_TYPE3_SMS;
968 case SMS_PID_REPLACE_TYPE4 :
969 return MSG_REPLACE_TYPE4_SMS;
970 case SMS_PID_REPLACE_TYPE5 :
971 return MSG_REPLACE_TYPE5_SMS;
972 case SMS_PID_REPLACE_TYPE6 :
973 return MSG_REPLACE_TYPE6_SMS;
974 case SMS_PID_REPLACE_TYPE7 :
975 return MSG_REPLACE_TYPE7_SMS;
976 case SMS_PID_RETURN_CALL :
977 return MSG_MWI_OTHER_SMS;
979 return MSG_NORMAL_SMS;
985 void SmsPluginEventHandler::SetSentInfo(SMS_SENT_INFO_S *pSentInfo)
987 memset(&sentInfo, 0x00, sizeof(SMS_SENT_INFO_S));
988 memcpy(&sentInfo, pSentInfo, sizeof(SMS_SENT_INFO_S));
990 MSG_DEBUG("sentInfo.reqId : %d", sentInfo.reqInfo.reqId);
991 MSG_DEBUG("sentInfo.bLast : %d", sentInfo.bLast);
995 void SmsPluginEventHandler::setDeviceStatus(struct tapi_handle *handle)
997 if (handle == devHandle) {
1006 bool SmsPluginEventHandler::getDeviceStatus(struct tapi_handle *handle)
1012 ret = cv.timedwait(mx.pMutex(), MAX_TAPI_SIM_API_TIMEOUT);
1014 if (ret == ETIMEDOUT) {
1015 MSG_WARN("WARNING: DEVICE STATUS TIME-OUT");
1024 msg_error_t SmsPluginEventHandler::handleSimMsg(MSG_MESSAGE_INFO_S *pMsgInfo, int *simIdList, msg_message_id_t *retMsgId, int listSize)
1028 msg_error_t err = MSG_SUCCESS;
1030 /** Callback to MSG FW */
1031 err = listener.pfSimMsgIncomingCb(pMsgInfo, simIdList, retMsgId, listSize);
1038 msg_error_t SmsPluginEventHandler::updateIMSI(int sim_idx)
1042 msg_error_t err = MSG_SUCCESS;
1044 /** Callback to MSG FW */
1045 err = listener.pfSimInitImsiCb(sim_idx);
1052 void SmsPluginEventHandler::handleSimMemoryFull(int simIndex)
1054 char keyName[MAX_VCONFKEY_NAME_LEN];
1055 bool bSimSst = true;
1056 memset(keyName, 0x00, sizeof(keyName));
1057 snprintf(keyName, sizeof(keyName), "%s/%d", MSG_SIM_SERVICE_TABLE, simIndex);
1058 if (MsgSettingGetBool(keyName, &bSimSst) != MSG_SUCCESS)
1059 MSG_ERR("MsgSettingGetBool [%s] failed", keyName);
1061 if (bSimSst == true)
1062 MsgInsertTicker("Sim memory full. Delete some items", SMS_MESSAGE_SIM_MESSAGE_FULL, true, 0);