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 <eventsystem.h>
26 #include "MsgUtilFile.h"
27 #include "MsgUtilFunction.h"
28 #include "MsgCppTypes.h"
29 #include "MsgContact.h"
30 #include "MsgGconfWrapper.h"
31 #include "MsgNotificationWrapper.h"
32 #include "MsgDevicedWrapper.h"
33 #include "SmsPluginTransport.h"
34 #include "SmsPluginSimMsg.h"
35 #include "SmsPluginStorage.h"
36 #include "SmsPluginSetting.h"
37 #include "SmsPluginConcatHandler.h"
38 #include "SmsPluginEventHandler.h"
39 #include "SmsPluginDSHandler.h"
40 #include "SmsPluginParamCodec.h"
43 /*==================================================================================================
44 IMPLEMENTATION OF SmsPluginEventHandler - Member Functions
45 ==================================================================================================*/
46 SmsPluginEventHandler* SmsPluginEventHandler::pInstance = NULL;
49 SmsPluginEventHandler::SmsPluginEventHandler()
51 /** Initialize global parameters */
52 memset(&listener, 0x00, sizeof(MSG_PLUGIN_LISTENER_S));
53 memset(&sentInfo, 0x00, sizeof(SMS_SENT_INFO_S));
57 bUdhMwiMethod = false;
63 SmsPluginEventHandler::~SmsPluginEventHandler()
68 SmsPluginEventHandler* SmsPluginEventHandler::instance()
71 pInstance = new SmsPluginEventHandler();
77 void SmsPluginEventHandler::registerListener(MSG_PLUGIN_LISTENER_S *pListener)
79 listener = *pListener;
83 void SmsPluginEventHandler::handleSentStatus(msg_network_status_t NetStatus)
85 MSG_DEBUG("NetStatus[%d]", NetStatus);
87 if (sentInfo.bLast == true || NetStatus != MSG_NETWORK_SEND_SUCCESS) {
88 /** Update Msg Status */
89 if (sentInfo.reqInfo.msgInfo.msgPort.valid == false) {
90 /*SmsPluginStorage::instance()->updateSentMsg(&(sentInfo.reqInfo.msgInfo), NetStatus); */
92 sentInfo.reqInfo.msgInfo.networkStatus = NetStatus;
94 if (NetStatus == MSG_NETWORK_SEND_SUCCESS) {
95 /* contacts-service is not used for gear */
96 #ifndef MSG_CONTACTS_SERVICE_NOT_SUPPORTED
97 MSG_DEBUG("Add phone log");
98 MsgAddPhoneLog(&(sentInfo.reqInfo.msgInfo));
99 #endif /* MSG_CONTACTS_SERVICE_NOT_SUPPORTED */
100 sentInfo.reqInfo.msgInfo.folderId = MSG_SENTBOX_ID; /* It should be set after adding phone log. */
101 /* Send system event */
105 if (sentInfo.reqInfo.msgInfo.msgType.mainType == MSG_SMS_TYPE)
106 bundle_add_str(b, EVT_KEY_OUT_MSG_TYPE, EVT_VAL_OUT_MSG_SMS);
108 bundle_add_str(b, EVT_KEY_OUT_MSG_TYPE, EVT_VAL_OUT_MSG_MMS);
110 char msgId[MSG_EVENT_MSG_ID_LEN] = {0, };
111 snprintf(msgId, sizeof(msgId), "%u", sentInfo.reqInfo.msgInfo.msgId);
112 bundle_add_str(b, EVT_KEY_OUT_MSG_ID, msgId);
113 eventsystem_send_system_event(SYS_EVENT_OUTGOING_MSG, b);
114 bundle_add_str(b, "cmd", "outgoing_msg");
115 msg_launch_app(MSG_MGR_APP_ID, b);
119 sentInfo.reqInfo.msgInfo.bRead = false;
122 SmsPluginStorage::instance()->updateSmsMessage(&(sentInfo.reqInfo.msgInfo));
124 callbackStorageChange(MSG_STORAGE_CHANGE_UPDATE, &(sentInfo.reqInfo.msgInfo));
127 MSG_DEBUG("sentInfo.reqInfo.sendOptInfo.bSetting [%d]", sentInfo.reqInfo.sendOptInfo.bSetting);
128 MSG_DEBUG("sentInfo.reqInfo.sendOptInfo.bKeepCopy [%d]", sentInfo.reqInfo.sendOptInfo.bKeepCopy);
129 /** Check sending options */
130 if (sentInfo.reqInfo.sendOptInfo.bSetting && !sentInfo.reqInfo.sendOptInfo.bKeepCopy && NetStatus == MSG_NETWORK_SEND_SUCCESS) {
131 SmsPluginStorage::instance()->deleteSmsMessage(sentInfo.reqInfo.msgInfo.msgId);
132 callbackStorageChange(MSG_STORAGE_CHANGE_DELETE, &(sentInfo.reqInfo.msgInfo));
135 /** Callback to MSG FW */
136 MSG_SENT_STATUS_S msgStatus;
138 msgStatus.reqId = sentInfo.reqInfo.reqId;
139 msgStatus.status = NetStatus;
141 MSG_DEBUG("sentStatus.reqId : %d", msgStatus.reqId);
142 MSG_DEBUG("sentStatus.status : %d", msgStatus.status);
144 listener.pfSentStatusCb(&msgStatus);
149 void SmsPluginEventHandler::handleMsgIncoming(TapiHandle *handle, SMS_TPDU_S *pTpdu)
151 /** Make MSG_MESSAGE_INFO_S */
152 MSG_MESSAGE_INFO_S msgInfo;
153 MSG_MESSAGE_INFO_S stored_msgInfo;
155 /** initialize msgInfo */
156 memset(&msgInfo, 0x00, sizeof(MSG_MESSAGE_INFO_S));
158 msgInfo.addressList = NULL;
159 unique_ptr<MSG_ADDRESS_INFO_S*, void(*)(MSG_ADDRESS_INFO_S**)> addressListBuf(&msgInfo.addressList, unique_ptr_deleter);
162 if (pTpdu->tpduType == SMS_TPDU_DELIVER) {
163 /** check unsupported message */
164 if (pTpdu->data.deliver.dcs.codingScheme == SMS_CHARSET_8BIT && pTpdu->data.deliver.pid == 0x11) {
165 MSG_DEBUG("Unsupported message!!");
166 SmsPluginTransport::instance()->sendDeliverReport(handle, MSG_SUCCESS);
171 bUdhMwiMethod = false;
174 if (pTpdu->data.deliver.dcs.msgClass == SMS_MSG_CLASS_2)
175 msgInfo.storageId = MSG_STORAGE_UNKNOWN;
177 msgInfo.storageId = MSG_STORAGE_PHONE;
179 msgInfo.sim_idx = SmsPluginDSHandler::instance()->getSimIndex(handle);
181 /** convert to msgInfo */
182 convertTpduToMsginfo(pTpdu, &msgInfo);
184 if (msgInfo.msgPort.valid == true) {
185 if ((msgInfo.msgPort.dstPort >= 0x23F4 && msgInfo.msgPort.dstPort <= 0x23F7) || /** Check unsupported message (Vcard WAP push) **/
186 (msgInfo.msgPort.dstPort == 0x1581)) { /** Check unsupported message (ringtone smart message) **/
187 memset(msgInfo.msgText, 0x00, sizeof(msgInfo.msgText));
188 snprintf(msgInfo.msgText, sizeof(msgInfo.msgText), "<Unsupported message>");
189 msgInfo.dataSize = strlen(msgInfo.msgText);
190 msgInfo.msgPort.valid = false;
194 bool bStoreVoiceMsg = false;
196 if (bUdhMwiMethod == false) {
197 /** check MWI and set info to SIM for DCS & Address method */
198 if (pTpdu->tpduType == SMS_TPDU_DELIVER && pTpdu->data.deliver.dcs.bMWI == true) {
200 MSG_DEBUG("MWI message - DCS method");
202 if (pTpdu->data.deliver.dcs.bIndActive == false) {
203 SmsPluginSetting::instance()->setMwiInfo(msgInfo.sim_idx, msgInfo.msgType.subType, 0);
206 SmsPluginSetting::instance()->setMwiInfo(msgInfo.sim_idx, msgInfo.msgType.subType, 1);
209 /* For address method */
210 if (pTpdu->data.deliver.pid == 0x20 && pTpdu->data.deliver.originAddress.ton == SMS_TON_ALPHANUMERIC) {
211 MSG_DEBUG("MWI message - Address method");
212 char *voiceNumber = NULL;
213 char *voiceAlphaId = NULL;
214 char keyName[MAX_VCONFKEY_NAME_LEN];
216 memset(keyName, 0x00, sizeof(keyName));
217 snprintf(keyName, sizeof(keyName), "%s/%d", VOICEMAIL_NUMBER, msgInfo.sim_idx);
218 if (MsgSettingGetString(keyName, &voiceNumber) != MSG_SUCCESS) {
219 MSG_INFO("MsgSettingGetString() is failed");
222 memset(keyName, 0x00, sizeof(keyName));
223 snprintf(keyName, sizeof(keyName), "%s/%d", VOICEMAIL_ALPHA_ID, msgInfo.sim_idx);
224 if (MsgSettingGetString(keyName, &voiceAlphaId) != MSG_SUCCESS) {
225 MSG_INFO("MsgSettingGetString() is failed");
228 memset(msgInfo.addressList[0].addressVal, 0x00, sizeof(msgInfo.addressList[0].addressVal));
229 memset(msgInfo.addressList[0].displayName, 0x00, sizeof(msgInfo.addressList[0].displayName));
232 snprintf(msgInfo.addressList[0].addressVal, sizeof(msgInfo.addressList[0].addressVal), "%s", voiceNumber);
238 snprintf(msgInfo.addressList[0].displayName, sizeof(msgInfo.addressList[0].displayName), "%s", voiceAlphaId);
245 if (pTpdu->data.deliver.dcs.codingGroup == SMS_GROUP_STORE) {
246 bStoreVoiceMsg = true;
247 memset(&stored_msgInfo, 0x00, sizeof(MSG_MESSAGE_INFO_S));
248 memcpy(&stored_msgInfo, &msgInfo, sizeof(MSG_MESSAGE_INFO_S));
249 stored_msgInfo.msgType.subType = MSG_NORMAL_SMS;
252 memset(msgInfo.msgText, 0x00, sizeof(msgInfo.msgText));
253 switch (msgInfo.msgType.subType) {
254 case MSG_MWI_VOICE_SMS :
255 snprintf(msgInfo.msgText, sizeof(msgInfo.msgText), "%d", MwiCnt);
257 case MSG_MWI_FAX_SMS :
258 snprintf(msgInfo.msgText, sizeof(msgInfo.msgText), "%d new fax message", MwiCnt);
260 case MSG_MWI_EMAIL_SMS :
261 snprintf(msgInfo.msgText, sizeof(msgInfo.msgText), "%d new email message", MwiCnt);
264 snprintf(msgInfo.msgText, sizeof(msgInfo.msgText), "%d new special message", MwiCnt);
267 msgInfo.dataSize = strlen(msgInfo.msgText);
269 if (pTpdu->data.deliver.dcs.codingGroup == SMS_GROUP_DISCARD)
270 msgInfo.bStore = false;
274 /** Short Message Type 0 - Just Send Deliver Report */
275 if (msgInfo.msgType.subType == MSG_TYPE0_SMS) {
276 SmsPluginTransport::instance()->sendDeliverReport(handle, MSG_SUCCESS);
280 /** Print MSG_MESSAGE_INFO_S */
281 MSG_DEBUG("############# Convert tpdu values to Message Info values ####################");
282 MSG_DEBUG("msgInfo.nAddressCnt : %d", msgInfo.nAddressCnt);
283 if (msgInfo.nAddressCnt > 0) {
284 MSG_DEBUG("msgInfo.addressList[0].addressType : %d", msgInfo.addressList[0].addressType);
285 MSG_SEC_DEBUG("msgInfo.addressList[0].addressVal : %s", msgInfo.addressList[0].addressVal);
286 MSG_SEC_DEBUG("msgInfo.addressList[0].displayName : %s", msgInfo.addressList[0].displayName);
288 MSG_DEBUG("msgInfo.priority : %d", msgInfo.priority);
289 MSG_DEBUG("msgInfo.bProtected : %d", msgInfo.bProtected);
290 MSG_DEBUG("msgInfo.bRead : %d", msgInfo.bRead);
291 MSG_DEBUG("msgInfo.bTextSms : %d", msgInfo.bTextSms);
292 MSG_DEBUG("msgInfo.bStore : %d", msgInfo.bStore);
293 MSG_DEBUG("msgInfo.direction : %d", msgInfo.direction);
294 MSG_DEBUG("msgInfo.msgType.mainType : %d", msgInfo.msgType.mainType);
295 MSG_DEBUG("msgInfo.msgType.subType : %d", msgInfo.msgType.subType);
296 MSG_DEBUG("msgInfo.msgType.classType : %d", msgInfo.msgType.classType);
297 MSG_DEBUG("msgInfo.displayTime : %d", msgInfo.displayTime);
298 MSG_DEBUG("msgInfo.msgPort.valid : %d", msgInfo.msgPort.valid);
299 MSG_DEBUG("msgInfo.encodeType : %d", msgInfo.encodeType);
300 MSG_DEBUG("msgInfo.dataSize : %d", msgInfo.dataSize);
301 MSG_DEBUG("msgInfo.sim_idx : %d", msgInfo.sim_idx);
303 if (msgInfo.bTextSms == true) {
304 MSG_SEC_DEBUG("msgInfo.msgText : %s", msgInfo.msgText);
306 MSG_SEC_DEBUG("msgInfo.msgData : %s", msgInfo.msgData);
309 MSG_DEBUG("###############################################################");
311 msg_error_t err = MSG_SUCCESS;
313 if (msgInfo.msgType.subType == MSG_STATUS_REPORT_SMS) {
314 /** Status Report Message */
315 err = SmsPluginStorage::instance()->updateMsgDeliverStatus(&msgInfo, pTpdu->data.statusRep.msgRef);
317 if (err == MSG_SUCCESS)
318 err = listener.pfMsgIncomingCb(&msgInfo);
320 MSG_DEBUG("updateMsgDeliverStatus is failed [%d]", err);
322 /** Handling of Fail Case ?? */
323 SmsPluginTransport::instance()->sendDeliverReport(handle, MSG_SUCCESS);
324 } else { /** SMS Deliver */
326 if (msgInfo.msgType.classType == MSG_CLASS_2) {
327 if (msgInfo.bTextSms == false) { /** Concat Msg cannot be saved in SIM */
328 msgInfo.msgType.classType = MSG_CLASS_NONE;
329 msgInfo.storageId = MSG_STORAGE_PHONE;
331 /** set total segment of Class2 message as 1 */
332 SmsPluginSimMsg::instance()->setSmsTpduTotalSegCount(1);
336 /** Add message to DB */
337 if (msgInfo.msgPort.valid == false) {
338 err = SmsPluginStorage::instance()->checkMessage(&msgInfo);
341 /** Callback to MSG FW */
342 if (msgInfo.msgType.classType == MSG_CLASS_2) {
343 if (((msgInfo.msgType.subType >= MSG_MWI_VOICE_SMS) && (msgInfo.msgType.subType <= MSG_MWI_OTHER_SMS)) &&
344 (msgInfo.bStore == false)) {
345 if (listener.pfMsgIncomingCb(&msgInfo) != MSG_SUCCESS)
346 MSG_DEBUG("listener.pfMsgIncomingCb is failed!");
348 SmsPluginTransport::instance()->sendDeliverReport(handle, MSG_SUCCESS);
351 if (err == MSG_SUCCESS) {
352 MSG_DEBUG("callback to msg fw");
353 err = listener.pfMsgIncomingCb(&msgInfo);
354 if (bStoreVoiceMsg) {
355 err = listener.pfMsgIncomingCb(&stored_msgInfo);
358 if (msgInfo.msgType.classType == MSG_CLASS_0) {
359 MSG_DEBUG("callback for class0 message to msg fw");
360 if (listener.pfMsgIncomingCb(&msgInfo) != MSG_SUCCESS)
361 MSG_DEBUG("listener.pfMsgIncomingCb is failed!");
365 /** Send Deliver Report */
366 if (msgInfo.msgType.classType == MSG_CLASS_0)
367 SmsPluginTransport::instance()->sendClass0DeliverReport(handle, err);
369 SmsPluginTransport::instance()->sendDeliverReport(handle, err);
372 /* Tizen Validation System */
374 char keyName[MAX_VCONFKEY_NAME_LEN];
375 memset(keyName, 0x00, sizeof(keyName));
376 snprintf(keyName, sizeof(keyName), "%s/%d", MSG_SIM_MSISDN, msgInfo.sim_idx);
377 if (MsgSettingGetString(keyName, &msisdn) != MSG_SUCCESS) {
378 MSG_INFO("MsgSettingGetString() is failed");
381 MSG_SMS_VLD_INFO("%d, SMS Receive, %s->%s, %s", msgInfo.msgId, \
382 msgInfo.addressList[0].addressVal, \
383 (msisdn == NULL)?"ME":msisdn, \
384 (err == MSG_SUCCESS)?"Success":"Fail");
386 MSG_SMS_VLD_TXT("%d, [%s]", msgInfo.msgId, msgInfo.msgText);
395 void SmsPluginEventHandler::handlePushMsgIncoming(char* pPushHeader, char* pPushBody, int pushBodyLen, char *application_id, char *content_type)
397 MSG_PUSH_MESSAGE_DATA_S pushData;
399 memset(&pushData, 0x00, sizeof(MSG_PUSH_MESSAGE_DATA_S));
402 memcpy(pushData.pushHeader, pPushHeader, strlen(pPushHeader));
404 pushData.pushBodyLen = pushBodyLen;
405 memcpy(pushData.pushBody, pPushBody, pushBodyLen);
407 memcpy(pushData.pushAppId, application_id, MAX_WAPPUSH_ID_LEN);
408 memcpy(pushData.pushContentType, content_type, MAX_WAPPUSH_CONTENT_TYPE_LEN);
410 /** Callback to MSG FW */
411 listener.pfPushMsgIncomingCb(&pushData);
415 void SmsPluginEventHandler::handleResendMessage(void)
417 listener.pfResendMessageCb();
421 void SmsPluginEventHandler::handleSyncMLMsgIncoming(msg_syncml_message_type_t msgType, char* pPushBody, int PushBodyLen, char* pWspHeader, int WspHeaderLen, int simIndex)
423 MSG_SYNCML_MESSAGE_DATA_S syncMLData;
425 memset(&syncMLData, 0x00, sizeof(MSG_SYNCML_MESSAGE_DATA_S));
427 /** set syncML data */
428 syncMLData.syncmlType = msgType;
430 syncMLData.simIndex = simIndex;
432 syncMLData.pushBodyLen = PushBodyLen;
433 memcpy(syncMLData.pushBody, pPushBody, PushBodyLen);
435 syncMLData.wspHeaderLen = WspHeaderLen;
436 memcpy(syncMLData.wspHeader, pWspHeader, WspHeaderLen);
438 /** Callback to MSG FW */
439 listener.pfSyncMLMsgIncomingCb(&syncMLData);
443 void SmsPluginEventHandler::handleLBSMsgIncoming(char* pPushHeader, char* pPushBody, int pushBodyLen)
445 MSG_LBS_MESSAGE_DATA_S lBSData;
447 memset(&lBSData, 0x00, sizeof(MSG_LBS_MESSAGE_DATA_S));
450 memcpy(lBSData.pushHeader, pPushHeader, strlen(pPushHeader));
452 lBSData.pushBodyLen = pushBodyLen;
453 memcpy(lBSData.pushBody, pPushBody, pushBodyLen);
455 /** Callback to MSG FW */
456 listener.pfLBSMsgIncomingCb(&lBSData);
459 msg_error_t SmsPluginEventHandler::callbackMsgIncoming(MSG_MESSAGE_INFO_S *pMsgInfo)
463 msg_error_t err = MSG_SUCCESS;
465 /** Callback to MSG FW */
466 err = listener.pfMsgIncomingCb(pMsgInfo);
473 msg_error_t SmsPluginEventHandler::callbackCBMsgIncoming(MSG_CB_MSG_S *pCbMsg, MSG_MESSAGE_INFO_S *pMsgInfo)
477 msg_error_t err = MSG_SUCCESS;
479 /** Callback to MSG FW */
480 err = listener.pfCBMsgIncomingCb(pCbMsg, pMsgInfo);
488 msg_error_t SmsPluginEventHandler::callbackInitSimBySat()
490 /** Callback to MSG FW */
491 return listener.pfInitSimBySatCb();
495 msg_error_t SmsPluginEventHandler::callbackStorageChange(msg_storage_change_type_t storageChangeType, MSG_MESSAGE_INFO_S *pMsgInfo)
497 msg_id_list_s msgIdList;
498 msg_message_id_t msgIds[1];
499 memset(&msgIdList, 0x00, sizeof(msg_id_list_s));
501 msgIdList.nCount = 1;
502 msgIds[0] = pMsgInfo->msgId;
503 msgIdList.msgIdList = msgIds;
505 /* Callback to MSG FW */
506 listener.pfStorageChangeCb(storageChangeType, &msgIdList);
512 msg_error_t SmsPluginEventHandler::callbackThreadChange(msg_storage_change_type_t storageChangeType, msg_thread_id_t threadId)
514 /* Callback to MSG FW */
515 listener.pfThreadChangeCb(storageChangeType, threadId);
521 void SmsPluginEventHandler::convertTpduToMsginfo(SMS_TPDU_S *pTpdu, MSG_MESSAGE_INFO_S *msgInfo)
523 switch (pTpdu->tpduType) {
524 case SMS_TPDU_SUBMIT :
525 convertSubmitTpduToMsginfo(&pTpdu->data.submit, msgInfo);
527 case SMS_TPDU_DELIVER :
528 convertDeliverTpduToMsginfo(&pTpdu->data.deliver, msgInfo);
530 case SMS_TPDU_STATUS_REP :
531 convertStatusRepTpduToMsginfo(&pTpdu->data.statusRep, msgInfo);
537 void SmsPluginEventHandler::convertSubmitTpduToMsginfo(const SMS_SUBMIT_S *pTpdu, MSG_MESSAGE_INFO_S *msgInfo)
539 int addressListCnt = 0;
541 /** Convert Type values */
542 msgInfo->msgType.mainType = MSG_SMS_TYPE;
543 msgInfo->msgType.subType = convertMsgSubType(pTpdu->pid);
545 /** set folder id (temporary) */
546 msgInfo->folderId = MSG_SENTBOX_ID;
548 switch (pTpdu->dcs.msgClass) {
549 case SMS_MSG_CLASS_0:
550 msgInfo->msgType.classType = MSG_CLASS_0;
552 case SMS_MSG_CLASS_1:
553 msgInfo->msgType.classType = MSG_CLASS_1;
555 case SMS_MSG_CLASS_2:
556 msgInfo->msgType.classType = MSG_CLASS_2;
558 case SMS_MSG_CLASS_3:
559 msgInfo->msgType.classType = MSG_CLASS_3;
562 msgInfo->msgType.classType = MSG_CLASS_NONE;
566 msgInfo->networkStatus = MSG_NETWORK_SEND_SUCCESS;
567 msgInfo->bRead = false;
568 msgInfo->bProtected = false;
569 msgInfo->priority = MSG_MESSAGE_PRIORITY_NORMAL;
570 msgInfo->direction = MSG_DIRECTION_TYPE_MO;
571 msgInfo->bTextSms = true;
573 memset(msgInfo->subject, 0x00, MAX_SUBJECT_LEN+1);
575 /** What kind of time has to be saved?? (temporary store time) */
576 msgInfo->displayTime = time(NULL);
578 /** Convert Address values */
579 msgInfo->nAddressCnt = 1;
581 msgInfo->addressList = (MSG_ADDRESS_INFO_S *)new char[sizeof(MSG_ADDRESS_INFO_S)];
582 memset(msgInfo->addressList, 0x00, sizeof(MSG_ADDRESS_INFO_S));
584 msgInfo->addressList[addressListCnt].addressType = MSG_ADDRESS_TYPE_PLMN;
585 strncpy(msgInfo->addressList[addressListCnt].addressVal, pTpdu->destAddress.address, MAX_ADDRESS_VAL_LEN);
587 /**exception operation for none userdata */
588 if (pTpdu->userData.length == 0) {
589 snprintf(msgInfo->msgText, sizeof(msgInfo->msgText), "[Broken Message]");
590 msgInfo->dataSize = strlen(msgInfo->msgText);
594 /** Convert Data values */
595 MsgTextConvert *textCvt = MsgTextConvert::instance();
596 if (pTpdu->dcs.codingScheme == SMS_CHARSET_7BIT) {
597 MSG_LANG_INFO_S langInfo = {0, };
599 langInfo.bSingleShift = false;
600 langInfo.bLockingShift = false;
602 msgInfo->dataSize = textCvt->convertGSM7bitToUTF8((unsigned char*)msgInfo->msgText, MAX_MSG_TEXT_LEN, (unsigned char*)pTpdu->userData.data, pTpdu->userData.length, &langInfo);
603 } else if (pTpdu->dcs.codingScheme == SMS_CHARSET_UCS2) {
604 msgInfo->dataSize = textCvt->convertUCS2ToUTF8((unsigned char*)msgInfo->msgText, MAX_MSG_TEXT_LEN, (unsigned char*)pTpdu->userData.data, pTpdu->userData.length);
609 void SmsPluginEventHandler::convertDeliverTpduToMsginfo(const SMS_DELIVER_S *pTpdu, MSG_MESSAGE_INFO_S *msgInfo)
613 /** Convert Type values */
614 msgInfo->msgType.mainType = MSG_SMS_TYPE;
615 msgInfo->msgType.subType = convertMsgSubType(pTpdu->pid);
617 /** set folder id (temporary) */
618 msgInfo->folderId = MSG_INBOX_ID;
621 if (msgInfo->storageId == MSG_STORAGE_SIM) {
622 /*** Comment below lines to save local UTC time..... (it could be used later.)
624 if (pTpdu->timeStamp.format == SMS_TIME_ABSOLUTE) {
625 MSG_DEBUG("year : %d", pTpdu->timeStamp.time.absolute.year);
626 MSG_DEBUG("month : %d", pTpdu->timeStamp.time.absolute.month);
627 MSG_DEBUG("day : %d", pTpdu->timeStamp.time.absolute.day);
628 MSG_DEBUG("hour : %d", pTpdu->timeStamp.time.absolute.hour);
629 MSG_DEBUG("minute : %d", pTpdu->timeStamp.time.absolute.minute);
630 MSG_DEBUG("second : %d", pTpdu->timeStamp.time.absolute.second);
631 MSG_DEBUG("timezone : %d", pTpdu->timeStamp.time.absolute.timeZone);
633 char displayTime[32];
637 memset(&timeinfo, 0x00, sizeof(tm));
639 timeinfo.tm_year = (pTpdu->timeStamp.time.absolute.year + 100);
640 timeinfo.tm_mon = (pTpdu->timeStamp.time.absolute.month - 1);
641 timeinfo.tm_mday = pTpdu->timeStamp.time.absolute.day;
642 timeinfo.tm_hour = pTpdu->timeStamp.time.absolute.hour;
643 timeinfo.tm_min = pTpdu->timeStamp.time.absolute.minute;
644 timeinfo.tm_sec = pTpdu->timeStamp.time.absolute.second;
645 timeinfo.tm_isdst = 0;
647 rawtime = mktime(&timeinfo);
649 MSG_DEBUG("tzname[0] [%s]", tzname[0]);
650 MSG_DEBUG("tzname[1] [%s]", tzname[1]);
651 MSG_DEBUG("timezone [%d]", timezone);
652 MSG_DEBUG("daylight [%d]", daylight);
654 memset(displayTime, 0x00, sizeof(displayTime));
655 strftime(displayTime, 32, "%Y-%02m-%02d %T %z", &timeinfo);
656 MSG_DEBUG("displayTime [%s]", displayTime);
658 rawtime -= (pTpdu->timeStamp.time.absolute.timeZone * (3600/4));
660 localtime_r(&rawtime, &timeTM);
661 memset(displayTime, 0x00, sizeof(displayTime));
662 strftime(displayTime, 32, "%Y-%02m-%02d %T %z", &timeTM);
663 MSG_DEBUG("displayTime [%s]", displayTime);
667 localtime_r(&rawtime, &timeTM);
668 memset(displayTime, 0x00, sizeof(displayTime));
669 strftime(displayTime, 32, "%Y-%02m-%02d %T %z", &timeTM);
670 MSG_DEBUG("displayTime [%s]", displayTime);
673 rawtime = time(NULL);
676 msgInfo->displayTime = rawtime;
678 switch (pTpdu->dcs.msgClass) {
679 case SMS_MSG_CLASS_0:
680 msgInfo->msgType.classType = MSG_CLASS_0;
682 case SMS_MSG_CLASS_1:
683 msgInfo->msgType.classType = MSG_CLASS_1;
685 case SMS_MSG_CLASS_2:
686 msgInfo->msgType.classType = MSG_CLASS_2;
687 msgInfo->storageId = MSG_STORAGE_SIM;
689 case SMS_MSG_CLASS_3:
690 msgInfo->msgType.classType = MSG_CLASS_3;
693 msgInfo->msgType.classType = MSG_CLASS_NONE;
697 if (pTpdu->dcs.bMWI) {
698 if (pTpdu->dcs.indType == SMS_VOICE_INDICATOR)
699 msgInfo->msgType.subType = MSG_MWI_VOICE_SMS;
700 else if (pTpdu->dcs.indType == SMS_VOICE2_INDICATOR)
701 msgInfo->msgType.subType = MSG_MWI_VOICE2_SMS;
702 else if (pTpdu->dcs.indType == SMS_FAX_INDICATOR)
703 msgInfo->msgType.subType = MSG_MWI_FAX_SMS;
704 else if (pTpdu->dcs.indType == SMS_EMAIL_INDICATOR)
705 msgInfo->msgType.subType = MSG_MWI_EMAIL_SMS;
706 else if (pTpdu->dcs.indType == SMS_OTHER_INDICATOR)
707 msgInfo->msgType.subType = MSG_MWI_OTHER_SMS;
710 msgInfo->networkStatus = MSG_NETWORK_RECEIVED;
711 msgInfo->bRead = false;
712 msgInfo->bProtected = false;
713 msgInfo->priority = MSG_MESSAGE_PRIORITY_NORMAL;
714 msgInfo->direction = MSG_DIRECTION_TYPE_MT;
715 msgInfo->bTextSms = true;
717 memset(msgInfo->subject, 0x00, MAX_SUBJECT_LEN+1);
719 /** Convert Address values */
720 msgInfo->nAddressCnt = 1;
722 msgInfo->addressList = (MSG_ADDRESS_INFO_S *)new char[sizeof(MSG_ADDRESS_INFO_S)];
723 memset(msgInfo->addressList, 0x00, sizeof(MSG_ADDRESS_INFO_S));
725 msgInfo->addressList[0].addressType = MSG_ADDRESS_TYPE_PLMN;
726 strncpy(msgInfo->addressList[0].addressVal, pTpdu->originAddress.address, MAX_ADDRESS_VAL_LEN);
728 msgInfo->msgPort.valid = false;
729 msgInfo->msgPort.dstPort = 0;
730 msgInfo->msgPort.srcPort = 0;
732 for (int i = 0; i < pTpdu->userData.headerCnt; i++) {
733 /** Convert UDH values - Port Number */
734 if (pTpdu->userData.header[i].udhType == SMS_UDH_APP_PORT_8BIT) {
735 msgInfo->msgPort.valid = true;
736 msgInfo->msgPort.dstPort = pTpdu->userData.header[i].udh.appPort8bit.destPort;
737 msgInfo->msgPort.srcPort = pTpdu->userData.header[i].udh.appPort8bit.originPort;
738 } else if (pTpdu->userData.header[i].udhType == SMS_UDH_APP_PORT_16BIT) {
739 msgInfo->msgPort.valid = true;
740 msgInfo->msgPort.dstPort = pTpdu->userData.header[i].udh.appPort16bit.destPort;
741 msgInfo->msgPort.srcPort = pTpdu->userData.header[i].udh.appPort16bit.originPort;
742 } else if (pTpdu->userData.header[i].udhType == SMS_UDH_SPECIAL_SMS) {
743 msgInfo->msgType.subType = (pTpdu->userData.header[i].udh.specialInd.msgInd+MSG_MWI_VOICE_SMS);
744 msgInfo->bStore = pTpdu->userData.header[i].udh.specialInd.bStore;
746 bUdhMwiMethod = true;
748 if (pTpdu->dcs.codingGroup == SMS_GROUP_DISCARD)
749 msgInfo->bStore = false;
751 udhMwiCnt = pTpdu->userData.header[i].udh.specialInd.waitMsgNum;
754 MSG_DEBUG("Message waiting number is smaller than 0. It will be treated as 0. [%d]", udhMwiCnt);
758 MSG_DEBUG("Message waiting number : [%d]", udhMwiCnt);
760 SmsPluginSetting::instance()->setMwiInfo(msgInfo->sim_idx, msgInfo->msgType.subType, udhMwiCnt);
762 if (udhMwiCnt > 0 && (msgInfo->msgType.subType >= MSG_MWI_VOICE_SMS && msgInfo->msgType.subType <= MSG_MWI_OTHER_SMS)) {
763 switch (msgInfo->msgType.subType) {
764 case MSG_MWI_VOICE_SMS :
765 snprintf(msgInfo->msgText, sizeof(msgInfo->msgText), "%d", udhMwiCnt);
767 case MSG_MWI_FAX_SMS :
768 snprintf(msgInfo->msgText, sizeof(msgInfo->msgText), "%d new fax message", udhMwiCnt);
770 case MSG_MWI_EMAIL_SMS :
771 snprintf(msgInfo->msgText, sizeof(msgInfo->msgText), "%d new email message", udhMwiCnt);
774 snprintf(msgInfo->msgText, sizeof(msgInfo->msgText), "%d new special message", udhMwiCnt);
777 msgInfo->dataSize = strlen(msgInfo->msgText);
780 } else if (pTpdu->userData.header[i].udhType == SMS_UDH_ALTERNATE_REPLY_ADDRESS) {
781 strncpy(msgInfo->addressList[0].addressVal, pTpdu->userData.header[i].udh.alternateAddress.address, MAX_ADDRESS_VAL_LEN);
782 } else if (pTpdu->userData.header[i].udhType >= SMS_UDH_EMS_FIRST && pTpdu->userData.header[i].udhType <= SMS_UDH_EMS_LAST) {
783 /* TODO: Raw text should be changed to string design id. Currently there's no design id in message-app-lite */
784 /* char *msg_text = getTranslateText(MSG_APP_PACKAGE_NAME, MSG_APP_LOCALEDIR, "IDS_MSGF_POP_ERROR_UNSUPPORTED_MSG");
785 snprintf(msgInfo->msgText, sizeof(msgInfo->msgText), "%s", msg_text);
787 snprintf(msgInfo->msgText, sizeof(msgInfo->msgText), "Unsupported Message");
788 msgInfo->dataSize = strlen(msgInfo->msgText);
798 /**length 0 - no user data - msg should be received */
799 if (pTpdu->userData.length <= 0) {
800 memset(msgInfo->msgText, 0x00, sizeof(msgInfo->msgText));
801 msgInfo->dataSize = 0;
803 switch (pTpdu->dcs.codingScheme) {
804 case SMS_CHARSET_7BIT:
805 msgInfo->encodeType = MSG_ENCODE_GSM7BIT;
807 case SMS_CHARSET_8BIT:
808 msgInfo->encodeType = MSG_ENCODE_8BIT;
810 case SMS_CHARSET_UCS2:
811 msgInfo->encodeType = MSG_ENCODE_UCS2;
814 msgInfo->encodeType = MSG_ENCODE_8BIT;
819 } else if (pTpdu->userData.length > MAX_MSG_TEXT_LEN) {
820 snprintf(msgInfo->msgText, sizeof(msgInfo->msgText), "[Broken Message]");
821 msgInfo->dataSize = strlen(msgInfo->msgData);
825 /** Convert Data values */
826 MsgTextConvert *textCvt = MsgTextConvert::instance();
827 if (pTpdu->dcs.codingScheme == SMS_CHARSET_7BIT) {
828 MSG_LANG_INFO_S langInfo = {0, };
830 langInfo.bSingleShift = false;
831 langInfo.bLockingShift = false;
833 for (int i = 0; i < pTpdu->userData.headerCnt; i++) {
834 if (pTpdu->userData.header[i].udhType == SMS_UDH_SINGLE_SHIFT) {
835 langInfo.bSingleShift = true;
836 langInfo.singleLang = pTpdu->userData.header[i].udh.singleShift.langId;
837 } else if (pTpdu->userData.header[i].udhType == SMS_UDH_LOCKING_SHIFT) {
838 langInfo.bLockingShift = true;
839 langInfo.lockingLang = pTpdu->userData.header[i].udh.lockingShift.langId;
843 msgInfo->encodeType = MSG_ENCODE_GSM7BIT;
844 msgInfo->dataSize = textCvt->convertGSM7bitToUTF8((unsigned char*)msgInfo->msgText, MAX_MSG_TEXT_LEN, (unsigned char*)pTpdu->userData.data, pTpdu->userData.length, &langInfo);
845 } else if (pTpdu->dcs.codingScheme == SMS_CHARSET_8BIT) {
846 msgInfo->encodeType = MSG_ENCODE_8BIT;
847 memcpy(msgInfo->msgText, pTpdu->userData.data, sizeof(pTpdu->userData.data));
848 msgInfo->dataSize = pTpdu->userData.length;
849 } else if (pTpdu->dcs.codingScheme == SMS_CHARSET_UCS2) {
850 msgInfo->encodeType = MSG_ENCODE_UCS2;
851 msgInfo->dataSize = textCvt->convertUCS2ToUTF8((unsigned char*)msgInfo->msgText, MAX_MSG_TEXT_LEN, (unsigned char*)pTpdu->userData.data, pTpdu->userData.length);
852 } else if (pTpdu->dcs.codingScheme == SMS_CHARSET_EUCKR) {
853 msgInfo->encodeType = MSG_ENCODE_8BIT;
854 msgInfo->dataSize = textCvt->convertEUCKRToUTF8((unsigned char*)msgInfo->msgText, MAX_MSG_TEXT_LEN, (unsigned char*)pTpdu->userData.data, pTpdu->userData.length);
862 void SmsPluginEventHandler::convertStatusRepTpduToMsginfo(const SMS_STATUS_REPORT_S *pTpdu, MSG_MESSAGE_INFO_S *msgInfo)
864 /** Convert Type values */
865 msgInfo->msgType.mainType = MSG_SMS_TYPE;
866 msgInfo->msgType.subType = MSG_STATUS_REPORT_SMS;
869 msgInfo->folderId = MSG_INBOX_ID;
871 /** set storage id */
872 if (msgInfo->storageId == MSG_STORAGE_UNKNOWN) {
873 msgInfo->storageId = MSG_STORAGE_PHONE;
876 switch (pTpdu->dcs.msgClass) {
877 case SMS_MSG_CLASS_0:
878 msgInfo->msgType.classType = MSG_CLASS_0;
880 case SMS_MSG_CLASS_1:
881 msgInfo->msgType.classType = MSG_CLASS_1;
883 case SMS_MSG_CLASS_2:
884 msgInfo->msgType.classType = MSG_CLASS_2;
886 case SMS_MSG_CLASS_3:
887 msgInfo->msgType.classType = MSG_CLASS_3;
890 msgInfo->msgType.classType = MSG_CLASS_NONE;
894 MSG_DEBUG("delivery status : [%d]", pTpdu->status);
896 if (pTpdu->status == SMS_STATUS_RECEIVE_SUCCESS)
897 msgInfo->networkStatus = MSG_NETWORK_DELIVER_SUCCESS;
898 else if (pTpdu->status == SMS_STATUS_TRY_REQUEST_PENDING)
899 msgInfo->networkStatus = MSG_NETWORK_DELIVER_PENDING;
900 else if (pTpdu->status == SMS_STATUS_PERM_MSG_VAL_PERIOD_EXPIRED)
901 msgInfo->networkStatus = MSG_NETWORK_DELIVER_EXPIRED;
903 msgInfo->networkStatus = MSG_NETWORK_DELIVER_FAIL;
905 msgInfo->bRead = false;
906 msgInfo->bProtected = false;
907 msgInfo->priority = MSG_MESSAGE_PRIORITY_NORMAL;
908 msgInfo->direction = MSG_DIRECTION_TYPE_MT;
909 msgInfo->bTextSms = true;
911 memset(msgInfo->subject, 0x00, MAX_SUBJECT_LEN+1);
913 msgInfo->displayTime = time(NULL);
915 /** Convert Address values */
916 msgInfo->nAddressCnt = 1;
918 msgInfo->addressList = (MSG_ADDRESS_INFO_S *)new char[sizeof(MSG_ADDRESS_INFO_S)];
919 memset(msgInfo->addressList, 0x00, sizeof(MSG_ADDRESS_INFO_S));
921 msgInfo->addressList[0].addressType = MSG_ADDRESS_TYPE_PLMN;
922 strncpy(msgInfo->addressList[0].addressVal, pTpdu->recipAddress.address, MAX_ADDRESS_VAL_LEN);
924 msgInfo->msgPort.valid = false;
925 msgInfo->msgPort.dstPort = 0;
926 msgInfo->msgPort.srcPort = 0;
928 for (int i = 0; i < pTpdu->userData.headerCnt; i++) {
929 /** Convert UDH values - Port Number */
930 if (pTpdu->userData.header[i].udhType == SMS_UDH_APP_PORT_8BIT) {
931 msgInfo->msgPort.valid = true;
932 msgInfo->msgPort.dstPort = pTpdu->userData.header[i].udh.appPort8bit.destPort;
933 msgInfo->msgPort.srcPort = pTpdu->userData.header[i].udh.appPort8bit.originPort;
934 } else if (pTpdu->userData.header[i].udhType == SMS_UDH_APP_PORT_16BIT) {
935 msgInfo->msgPort.valid = true;
936 msgInfo->msgPort.dstPort = pTpdu->userData.header[i].udh.appPort16bit.destPort;
937 msgInfo->msgPort.srcPort = pTpdu->userData.header[i].udh.appPort16bit.originPort;
941 memset(msgInfo->msgText, 0x00, sizeof(msgInfo->msgText));
942 msgInfo->dataSize = 0;
944 if (pTpdu->status <= SMS_STATUS_SMSC_SPECIFIC_LAST) {
945 char *msg_text = getTranslateText(MSG_APP_PACKAGE_NAME, MSG_APP_LOCALEDIR, "IDS_MSG_SBODY_MESSAGE_DELIVERED_M_STATUS_ABB");
946 snprintf(msgInfo->msgText, sizeof(msgInfo->msgText), "%s", msg_text);
947 msgInfo->dataSize = strlen(msgInfo->msgText);
952 } else if (pTpdu->status == SMS_STATUS_TEMP_SERVICE_REJECTED) {
953 char *msg_text = getTranslateText(MSG_APP_PACKAGE_NAME, MSG_APP_LOCALEDIR, "IDS_MSG_SBODY_MESSAGE_REJECTED_M_STATUS_ABB");
954 snprintf(msgInfo->msgText, sizeof(msgInfo->msgText), "%s", msg_text);
955 msgInfo->dataSize = strlen(msgInfo->msgText);
960 } else if (pTpdu->status == SMS_STATUS_PERM_MSG_VAL_PERIOD_EXPIRED) {
961 char *msg_text = getTranslateText(MSG_APP_PACKAGE_NAME, MSG_APP_LOCALEDIR, "IDS_MSG_SBODY_MESSAGE_EXPIRED_M_STATUS_ABB");
962 snprintf(msgInfo->msgText, sizeof(msgInfo->msgText), "%s", msg_text);
963 msgInfo->dataSize = strlen(msgInfo->msgText);
969 strncpy(msgInfo->msgText, "Message delivery failed.", MAX_MSG_TEXT_LEN);
970 msgInfo->dataSize = strlen(msgInfo->msgText);
975 MSG_SUB_TYPE_T SmsPluginEventHandler::convertMsgSubType(SMS_PID_T pid)
979 return MSG_TYPE0_SMS;
980 case SMS_PID_REPLACE_TYPE1 :
981 return MSG_REPLACE_TYPE1_SMS;
982 case SMS_PID_REPLACE_TYPE2 :
983 return MSG_REPLACE_TYPE2_SMS;
984 case SMS_PID_REPLACE_TYPE3 :
985 return MSG_REPLACE_TYPE3_SMS;
986 case SMS_PID_REPLACE_TYPE4 :
987 return MSG_REPLACE_TYPE4_SMS;
988 case SMS_PID_REPLACE_TYPE5 :
989 return MSG_REPLACE_TYPE5_SMS;
990 case SMS_PID_REPLACE_TYPE6 :
991 return MSG_REPLACE_TYPE6_SMS;
992 case SMS_PID_REPLACE_TYPE7 :
993 return MSG_REPLACE_TYPE7_SMS;
994 case SMS_PID_RETURN_CALL :
995 return MSG_MWI_OTHER_SMS;
997 return MSG_NORMAL_SMS;
1002 void SmsPluginEventHandler::SetSentInfo(SMS_SENT_INFO_S *pSentInfo)
1004 memset(&sentInfo, 0x00, sizeof(SMS_SENT_INFO_S));
1005 memcpy(&sentInfo, pSentInfo, sizeof(SMS_SENT_INFO_S));
1007 MSG_DEBUG("sentInfo.reqId : %d", sentInfo.reqInfo.reqId);
1008 MSG_DEBUG("sentInfo.bLast : %d", sentInfo.bLast);
1012 void SmsPluginEventHandler::setDeviceStatus(TapiHandle *handle)
1014 if (handle == devHandle) {
1023 bool SmsPluginEventHandler::getDeviceStatus(TapiHandle *handle)
1029 ret = cv.timedwait(mx.pMsgMutex(), MAX_TAPI_SIM_API_TIMEOUT);
1031 if (ret == ETIMEDOUT) {
1032 MSG_WARN("WARNING: DEVICE STATUS TIME-OUT");
1041 msg_error_t SmsPluginEventHandler::handleSimMsg(MSG_MESSAGE_INFO_S *pMsgInfo, int *simIdList, msg_message_id_t *retMsgId, int listSize)
1045 msg_error_t err = MSG_SUCCESS;
1047 /** Callback to MSG FW */
1048 err = listener.pfSimMsgIncomingCb(pMsgInfo, simIdList, retMsgId, listSize);
1055 msg_error_t SmsPluginEventHandler::updateIMSI(int sim_idx)
1059 msg_error_t err = MSG_SUCCESS;
1061 /** Callback to MSG FW */
1062 err = listener.pfSimInitImsiCb(sim_idx);
1069 void SmsPluginEventHandler::handleSimMemoryFull(int simIndex)
1071 char keyName[MAX_VCONFKEY_NAME_LEN];
1072 bool bSimSst = true;
1073 memset(keyName, 0x00, sizeof(keyName));
1074 snprintf(keyName, sizeof(keyName), "%s/%d", MSG_SIM_SERVICE_TABLE, simIndex);
1075 if (MsgSettingGetBool(keyName, &bSimSst) != MSG_SUCCESS)
1076 MSG_ERR("MsgSettingGetBool [%s] failed", keyName);
1078 if (bSimSst == true)
1079 MsgInsertTicker("Sim memory full. Delete some items", SMS_MESSAGE_SIM_MESSAGE_FULL, true, 0);