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.
24 #include <eventsystem.h>
27 #include "MsgUtilFile.h"
28 #include "MsgUtilFunction.h"
29 #include "MsgCppTypes.h"
30 #include "MsgContact.h"
31 #include "MsgGconfWrapper.h"
32 #include "MsgNotificationWrapper.h"
33 #include "MsgDevicedWrapper.h"
34 #include "SmsPluginTransport.h"
35 #include "SmsPluginSimMsg.h"
36 #include "SmsPluginStorage.h"
37 #include "SmsPluginSetting.h"
38 #include "SmsPluginConcatHandler.h"
39 #include "SmsPluginEventHandler.h"
40 #include "SmsPluginDSHandler.h"
41 #include "SmsPluginParamCodec.h"
44 /*==================================================================================================
45 IMPLEMENTATION OF SmsPluginEventHandler - Member Functions
46 ==================================================================================================*/
47 SmsPluginEventHandler* SmsPluginEventHandler::pInstance = NULL;
50 SmsPluginEventHandler::SmsPluginEventHandler()
52 /** Initialize global parameters */
53 memset(&listener, 0x00, sizeof(MSG_PLUGIN_LISTENER_S));
54 memset(&sentInfo, 0x00, sizeof(SMS_SENT_INFO_S));
58 bUdhMwiMethod = false;
64 SmsPluginEventHandler::~SmsPluginEventHandler()
69 SmsPluginEventHandler* SmsPluginEventHandler::instance()
72 pInstance = new SmsPluginEventHandler();
78 void SmsPluginEventHandler::registerListener(MSG_PLUGIN_LISTENER_S *pListener)
80 listener = *pListener;
84 void SmsPluginEventHandler::handleSentStatus(msg_network_status_t NetStatus)
86 MSG_DEBUG("NetStatus[%d]", NetStatus);
88 if (sentInfo.bLast == true || NetStatus != MSG_NETWORK_SEND_SUCCESS) {
89 /** Update Msg Status */
90 if (sentInfo.reqInfo.msgInfo.msgPort.valid == false) {
91 /*SmsPluginStorage::instance()->updateSentMsg(&(sentInfo.reqInfo.msgInfo), NetStatus); */
93 sentInfo.reqInfo.msgInfo.networkStatus = NetStatus;
95 if (NetStatus == MSG_NETWORK_SEND_SUCCESS) {
96 /* contacts-service is not used for gear */
97 #ifndef MSG_CONTACTS_SERVICE_NOT_SUPPORTED
98 MSG_DEBUG("Add phone log");
99 MsgAddPhoneLog(&(sentInfo.reqInfo.msgInfo));
100 #endif /* MSG_CONTACTS_SERVICE_NOT_SUPPORTED */
101 sentInfo.reqInfo.msgInfo.folderId = MSG_SENTBOX_ID; /* It should be set after adding phone log. */
102 /* Send system event */
106 if (sentInfo.reqInfo.msgInfo.msgType.mainType == MSG_SMS_TYPE)
107 bundle_add_str(b, EVT_KEY_OUT_MSG_TYPE, EVT_VAL_SMS);
109 bundle_add_str(b, EVT_KEY_OUT_MSG_TYPE, EVT_VAL_MMS);
111 char msgId[MSG_EVENT_MSG_ID_LEN] = {0, };
112 snprintf(msgId, sizeof(msgId), "%u", sentInfo.reqInfo.msgInfo.msgId);
113 bundle_add_str(b, EVT_KEY_OUT_MSG_ID, msgId);
114 eventsystem_send_system_event(SYS_EVENT_OUTGOING_MSG, b);
115 bundle_add_str(b, "cmd", "outgoing_msg");
116 int ret = aul_launch_app_for_uid("org.tizen.msg-manager", b, msg_get_login_user());
118 MSG_DEBUG("aul_launch_app_for_uid() is failed : %d", ret);
123 sentInfo.reqInfo.msgInfo.bRead = false;
126 SmsPluginStorage::instance()->updateSmsMessage(&(sentInfo.reqInfo.msgInfo));
128 callbackStorageChange(MSG_STORAGE_CHANGE_UPDATE, &(sentInfo.reqInfo.msgInfo));
131 MSG_DEBUG("sentInfo.reqInfo.sendOptInfo.bSetting [%d]", sentInfo.reqInfo.sendOptInfo.bSetting);
132 MSG_DEBUG("sentInfo.reqInfo.sendOptInfo.bKeepCopy [%d]", sentInfo.reqInfo.sendOptInfo.bKeepCopy);
133 /** Check sending options */
134 if (sentInfo.reqInfo.sendOptInfo.bSetting && !sentInfo.reqInfo.sendOptInfo.bKeepCopy && NetStatus == MSG_NETWORK_SEND_SUCCESS) {
135 SmsPluginStorage::instance()->deleteSmsMessage(sentInfo.reqInfo.msgInfo.msgId);
136 callbackStorageChange(MSG_STORAGE_CHANGE_DELETE, &(sentInfo.reqInfo.msgInfo));
139 /** Callback to MSG FW */
140 MSG_SENT_STATUS_S msgStatus;
142 msgStatus.reqId = sentInfo.reqInfo.reqId;
143 msgStatus.status = NetStatus;
145 MSG_DEBUG("sentStatus.reqId : %d", msgStatus.reqId);
146 MSG_DEBUG("sentStatus.status : %d", msgStatus.status);
148 listener.pfSentStatusCb(&msgStatus);
153 void SmsPluginEventHandler::handleMsgIncoming(TapiHandle *handle, SMS_TPDU_S *pTpdu)
155 /** Make MSG_MESSAGE_INFO_S */
156 MSG_MESSAGE_INFO_S msgInfo;
157 MSG_MESSAGE_INFO_S stored_msgInfo;
159 /** initialize msgInfo */
160 memset(&msgInfo, 0x00, sizeof(MSG_MESSAGE_INFO_S));
162 msgInfo.addressList = NULL;
163 unique_ptr<MSG_ADDRESS_INFO_S*, void(*)(MSG_ADDRESS_INFO_S**)> addressListBuf(&msgInfo.addressList, unique_ptr_deleter);
166 if (pTpdu->tpduType == SMS_TPDU_DELIVER) {
167 /** check unsupported message */
168 if (pTpdu->data.deliver.dcs.codingScheme == SMS_CHARSET_8BIT && pTpdu->data.deliver.pid == 0x11) {
169 MSG_DEBUG("Unsupported message!!");
170 SmsPluginTransport::instance()->sendDeliverReport(handle, MSG_SUCCESS);
175 bUdhMwiMethod = false;
178 if (pTpdu->data.deliver.dcs.msgClass == SMS_MSG_CLASS_2)
179 msgInfo.storageId = MSG_STORAGE_UNKNOWN;
181 msgInfo.storageId = MSG_STORAGE_PHONE;
183 msgInfo.sim_idx = SmsPluginDSHandler::instance()->getSimIndex(handle);
185 /** convert to msgInfo */
186 convertTpduToMsginfo(pTpdu, &msgInfo);
188 if (msgInfo.msgPort.valid == true) {
189 if ((msgInfo.msgPort.dstPort >= 0x23F4 && msgInfo.msgPort.dstPort <= 0x23F7) || /** Check unsupported message (Vcard WAP push) **/
190 (msgInfo.msgPort.dstPort == 0x1581)) { /** Check unsupported message (ringtone smart message) **/
191 memset(msgInfo.msgText, 0x00, sizeof(msgInfo.msgText));
192 snprintf(msgInfo.msgText, sizeof(msgInfo.msgText), "<Unsupported message>");
193 msgInfo.dataSize = strlen(msgInfo.msgText);
194 msgInfo.msgPort.valid = false;
198 bool bStoreVoiceMsg = false;
200 if (bUdhMwiMethod == false) {
201 /** check MWI and set info to SIM for DCS & Address method */
202 if (pTpdu->tpduType == SMS_TPDU_DELIVER && pTpdu->data.deliver.dcs.bMWI == true) {
204 MSG_DEBUG("MWI message - DCS method");
206 if (pTpdu->data.deliver.dcs.bIndActive == false) {
207 SmsPluginSetting::instance()->setMwiInfo(msgInfo.sim_idx, msgInfo.msgType.subType, 0);
210 SmsPluginSetting::instance()->setMwiInfo(msgInfo.sim_idx, msgInfo.msgType.subType, 1);
213 /* For address method */
214 if (pTpdu->data.deliver.pid == 0x20 && pTpdu->data.deliver.originAddress.ton == SMS_TON_ALPHANUMERIC) {
215 MSG_DEBUG("MWI message - Address method");
216 char *voiceNumber = NULL;
217 char *voiceAlphaId = NULL;
218 char keyName[MAX_VCONFKEY_NAME_LEN];
220 memset(keyName, 0x00, sizeof(keyName));
221 snprintf(keyName, sizeof(keyName), "%s/%d", VOICEMAIL_NUMBER, msgInfo.sim_idx);
222 if (MsgSettingGetString(keyName, &voiceNumber) != MSG_SUCCESS) {
223 MSG_INFO("MsgSettingGetString() is failed");
226 memset(keyName, 0x00, sizeof(keyName));
227 snprintf(keyName, sizeof(keyName), "%s/%d", VOICEMAIL_ALPHA_ID, msgInfo.sim_idx);
228 if (MsgSettingGetString(keyName, &voiceAlphaId) != MSG_SUCCESS) {
229 MSG_INFO("MsgSettingGetString() is failed");
232 memset(msgInfo.addressList[0].addressVal, 0x00, sizeof(msgInfo.addressList[0].addressVal));
233 memset(msgInfo.addressList[0].displayName, 0x00, sizeof(msgInfo.addressList[0].displayName));
236 snprintf(msgInfo.addressList[0].addressVal, sizeof(msgInfo.addressList[0].addressVal), "%s", voiceNumber);
242 snprintf(msgInfo.addressList[0].displayName, sizeof(msgInfo.addressList[0].displayName), "%s", voiceAlphaId);
249 if (pTpdu->data.deliver.dcs.codingGroup == SMS_GROUP_STORE) {
250 bStoreVoiceMsg = true;
251 memset(&stored_msgInfo, 0x00, sizeof(MSG_MESSAGE_INFO_S));
252 memcpy(&stored_msgInfo, &msgInfo, sizeof(MSG_MESSAGE_INFO_S));
253 stored_msgInfo.msgType.subType = MSG_NORMAL_SMS;
256 memset(msgInfo.msgText, 0x00, sizeof(msgInfo.msgText));
257 switch (msgInfo.msgType.subType) {
258 case MSG_MWI_VOICE_SMS :
259 snprintf(msgInfo.msgText, sizeof(msgInfo.msgText), "%d", MwiCnt);
261 case MSG_MWI_FAX_SMS :
262 snprintf(msgInfo.msgText, sizeof(msgInfo.msgText), "%d new fax message", MwiCnt);
264 case MSG_MWI_EMAIL_SMS :
265 snprintf(msgInfo.msgText, sizeof(msgInfo.msgText), "%d new email message", MwiCnt);
268 snprintf(msgInfo.msgText, sizeof(msgInfo.msgText), "%d new special message", MwiCnt);
271 msgInfo.dataSize = strlen(msgInfo.msgText);
273 if (pTpdu->data.deliver.dcs.codingGroup == SMS_GROUP_DISCARD)
274 msgInfo.bStore = false;
278 /** Short Message Type 0 - Just Send Deliver Report */
279 if (msgInfo.msgType.subType == MSG_TYPE0_SMS) {
280 SmsPluginTransport::instance()->sendDeliverReport(handle, MSG_SUCCESS);
284 /** Print MSG_MESSAGE_INFO_S */
285 MSG_DEBUG("############# Convert tpdu values to Message Info values ####################");
286 MSG_DEBUG("msgInfo.nAddressCnt : %d", msgInfo.nAddressCnt);
287 if (msgInfo.nAddressCnt > 0) {
288 MSG_DEBUG("msgInfo.addressList[0].addressType : %d", msgInfo.addressList[0].addressType);
289 MSG_SEC_DEBUG("msgInfo.addressList[0].addressVal : %s", msgInfo.addressList[0].addressVal);
290 MSG_SEC_DEBUG("msgInfo.addressList[0].displayName : %s", msgInfo.addressList[0].displayName);
292 MSG_DEBUG("msgInfo.priority : %d", msgInfo.priority);
293 MSG_DEBUG("msgInfo.bProtected : %d", msgInfo.bProtected);
294 MSG_DEBUG("msgInfo.bRead : %d", msgInfo.bRead);
295 MSG_DEBUG("msgInfo.bTextSms : %d", msgInfo.bTextSms);
296 MSG_DEBUG("msgInfo.bStore : %d", msgInfo.bStore);
297 MSG_DEBUG("msgInfo.direction : %d", msgInfo.direction);
298 MSG_DEBUG("msgInfo.msgType.mainType : %d", msgInfo.msgType.mainType);
299 MSG_DEBUG("msgInfo.msgType.subType : %d", msgInfo.msgType.subType);
300 MSG_DEBUG("msgInfo.msgType.classType : %d", msgInfo.msgType.classType);
301 MSG_DEBUG("msgInfo.displayTime : %d", msgInfo.displayTime);
302 MSG_DEBUG("msgInfo.msgPort.valid : %d", msgInfo.msgPort.valid);
303 MSG_DEBUG("msgInfo.encodeType : %d", msgInfo.encodeType);
304 MSG_DEBUG("msgInfo.dataSize : %d", msgInfo.dataSize);
305 MSG_DEBUG("msgInfo.sim_idx : %d", msgInfo.sim_idx);
307 if (msgInfo.bTextSms == true) {
308 MSG_SEC_DEBUG("msgInfo.msgText : %s", msgInfo.msgText);
310 MSG_SEC_DEBUG("msgInfo.msgData : %s", msgInfo.msgData);
313 MSG_DEBUG("###############################################################");
315 msg_error_t err = MSG_SUCCESS;
317 if (msgInfo.msgType.subType == MSG_STATUS_REPORT_SMS) {
318 /** Status Report Message */
319 err = SmsPluginStorage::instance()->updateMsgDeliverStatus(&msgInfo, pTpdu->data.statusRep.msgRef);
321 if (err == MSG_SUCCESS)
322 err = listener.pfMsgIncomingCb(&msgInfo);
324 MSG_DEBUG("updateMsgDeliverStatus is failed [%d]", err);
326 /** Handling of Fail Case ?? */
327 SmsPluginTransport::instance()->sendDeliverReport(handle, MSG_SUCCESS);
328 } else { /** SMS Deliver */
330 if (msgInfo.msgType.classType == MSG_CLASS_2) {
331 if (msgInfo.bTextSms == false) { /** Concat Msg cannot be saved in SIM */
332 msgInfo.msgType.classType = MSG_CLASS_NONE;
333 msgInfo.storageId = MSG_STORAGE_PHONE;
335 /** set total segment of Class2 message as 1 */
336 SmsPluginSimMsg::instance()->setSmsTpduTotalSegCount(1);
340 /** Add message to DB */
341 if (msgInfo.msgPort.valid == false) {
342 err = SmsPluginStorage::instance()->checkMessage(&msgInfo);
345 /** Callback to MSG FW */
346 if (msgInfo.msgType.classType == MSG_CLASS_2) {
347 if (((msgInfo.msgType.subType >= MSG_MWI_VOICE_SMS) && (msgInfo.msgType.subType <= MSG_MWI_OTHER_SMS)) &&
348 (msgInfo.bStore == false)) {
349 if (listener.pfMsgIncomingCb(&msgInfo) != MSG_SUCCESS)
350 MSG_DEBUG("listener.pfMsgIncomingCb is failed!");
352 SmsPluginTransport::instance()->sendDeliverReport(handle, MSG_SUCCESS);
355 if (err == MSG_SUCCESS) {
356 MSG_DEBUG("callback to msg fw");
357 err = listener.pfMsgIncomingCb(&msgInfo);
358 if (bStoreVoiceMsg) {
359 err = listener.pfMsgIncomingCb(&stored_msgInfo);
362 if (msgInfo.msgType.classType == MSG_CLASS_0) {
363 MSG_DEBUG("callback for class0 message to msg fw");
364 if (listener.pfMsgIncomingCb(&msgInfo) != MSG_SUCCESS)
365 MSG_DEBUG("listener.pfMsgIncomingCb is failed!");
369 /** Send Deliver Report */
370 if (msgInfo.msgType.classType == MSG_CLASS_0)
371 SmsPluginTransport::instance()->sendClass0DeliverReport(handle, err);
373 SmsPluginTransport::instance()->sendDeliverReport(handle, err);
376 /* Tizen Validation System */
378 char keyName[MAX_VCONFKEY_NAME_LEN];
379 memset(keyName, 0x00, sizeof(keyName));
380 snprintf(keyName, sizeof(keyName), "%s/%d", MSG_SIM_MSISDN, msgInfo.sim_idx);
381 if (MsgSettingGetString(keyName, &msisdn) != MSG_SUCCESS) {
382 MSG_INFO("MsgSettingGetString() is failed");
385 MSG_SMS_VLD_INFO("%d, SMS Receive, %s->%s, %s", msgInfo.msgId, \
386 msgInfo.addressList[0].addressVal, \
387 (msisdn == NULL)?"ME":msisdn, \
388 (err == MSG_SUCCESS)?"Success":"Fail");
390 MSG_SMS_VLD_TXT("%d, [%s]", msgInfo.msgId, msgInfo.msgText);
399 void SmsPluginEventHandler::handlePushMsgIncoming(char* pPushHeader, char* pPushBody, int pushBodyLen, char *application_id, char *content_type)
401 MSG_PUSH_MESSAGE_DATA_S pushData;
403 memset(&pushData, 0x00, sizeof(MSG_PUSH_MESSAGE_DATA_S));
406 memcpy(pushData.pushHeader, pPushHeader, strlen(pPushHeader));
408 pushData.pushBodyLen = pushBodyLen;
409 memcpy(pushData.pushBody, pPushBody, pushBodyLen);
411 memcpy(pushData.pushAppId, application_id, MAX_WAPPUSH_ID_LEN);
412 memcpy(pushData.pushContentType, content_type, MAX_WAPPUSH_CONTENT_TYPE_LEN);
414 /** Callback to MSG FW */
415 listener.pfPushMsgIncomingCb(&pushData);
419 void SmsPluginEventHandler::handleResendMessage(void)
421 listener.pfResendMessageCb();
425 void SmsPluginEventHandler::handleSyncMLMsgIncoming(msg_syncml_message_type_t msgType, char* pPushBody, int PushBodyLen, char* pWspHeader, int WspHeaderLen, int simIndex)
427 MSG_SYNCML_MESSAGE_DATA_S syncMLData;
429 memset(&syncMLData, 0x00, sizeof(MSG_SYNCML_MESSAGE_DATA_S));
431 /** set syncML data */
432 syncMLData.syncmlType = msgType;
434 syncMLData.simIndex = simIndex;
436 syncMLData.pushBodyLen = PushBodyLen;
437 memcpy(syncMLData.pushBody, pPushBody, PushBodyLen);
439 syncMLData.wspHeaderLen = WspHeaderLen;
440 memcpy(syncMLData.wspHeader, pWspHeader, WspHeaderLen);
442 /** Callback to MSG FW */
443 listener.pfSyncMLMsgIncomingCb(&syncMLData);
447 void SmsPluginEventHandler::handleLBSMsgIncoming(char* pPushHeader, char* pPushBody, int pushBodyLen)
449 MSG_LBS_MESSAGE_DATA_S lBSData;
451 memset(&lBSData, 0x00, sizeof(MSG_LBS_MESSAGE_DATA_S));
454 memcpy(lBSData.pushHeader, pPushHeader, strlen(pPushHeader));
456 lBSData.pushBodyLen = pushBodyLen;
457 memcpy(lBSData.pushBody, pPushBody, pushBodyLen);
459 /** Callback to MSG FW */
460 listener.pfLBSMsgIncomingCb(&lBSData);
463 msg_error_t SmsPluginEventHandler::callbackMsgIncoming(MSG_MESSAGE_INFO_S *pMsgInfo)
467 msg_error_t err = MSG_SUCCESS;
469 /** Callback to MSG FW */
470 err = listener.pfMsgIncomingCb(pMsgInfo);
477 msg_error_t SmsPluginEventHandler::callbackCBMsgIncoming(MSG_CB_MSG_S *pCbMsg, MSG_MESSAGE_INFO_S *pMsgInfo)
481 msg_error_t err = MSG_SUCCESS;
483 /** Callback to MSG FW */
484 err = listener.pfCBMsgIncomingCb(pCbMsg, pMsgInfo);
492 msg_error_t SmsPluginEventHandler::callbackInitSimBySat()
494 /** Callback to MSG FW */
495 return listener.pfInitSimBySatCb();
499 msg_error_t SmsPluginEventHandler::callbackStorageChange(msg_storage_change_type_t storageChangeType, MSG_MESSAGE_INFO_S *pMsgInfo)
501 msg_id_list_s msgIdList;
502 msg_message_id_t msgIds[1];
503 memset(&msgIdList, 0x00, sizeof(msg_id_list_s));
505 msgIdList.nCount = 1;
506 msgIds[0] = pMsgInfo->msgId;
507 msgIdList.msgIdList = msgIds;
509 /* Callback to MSG FW */
510 listener.pfStorageChangeCb(storageChangeType, &msgIdList);
516 void SmsPluginEventHandler::convertTpduToMsginfo(SMS_TPDU_S *pTpdu, MSG_MESSAGE_INFO_S *msgInfo)
518 switch (pTpdu->tpduType) {
519 case SMS_TPDU_SUBMIT :
520 convertSubmitTpduToMsginfo(&pTpdu->data.submit, msgInfo);
522 case SMS_TPDU_DELIVER :
523 convertDeliverTpduToMsginfo(&pTpdu->data.deliver, msgInfo);
525 case SMS_TPDU_STATUS_REP :
526 convertStatusRepTpduToMsginfo(&pTpdu->data.statusRep, msgInfo);
532 void SmsPluginEventHandler::convertSubmitTpduToMsginfo(const SMS_SUBMIT_S *pTpdu, MSG_MESSAGE_INFO_S *msgInfo)
534 int addressListCnt = 0;
536 /** Convert Type values */
537 msgInfo->msgType.mainType = MSG_SMS_TYPE;
538 msgInfo->msgType.subType = convertMsgSubType(pTpdu->pid);
540 /** set folder id (temporary) */
541 msgInfo->folderId = MSG_SENTBOX_ID;
543 switch (pTpdu->dcs.msgClass) {
544 case SMS_MSG_CLASS_0:
545 msgInfo->msgType.classType = MSG_CLASS_0;
547 case SMS_MSG_CLASS_1:
548 msgInfo->msgType.classType = MSG_CLASS_1;
550 case SMS_MSG_CLASS_2:
551 msgInfo->msgType.classType = MSG_CLASS_2;
553 case SMS_MSG_CLASS_3:
554 msgInfo->msgType.classType = MSG_CLASS_3;
557 msgInfo->msgType.classType = MSG_CLASS_NONE;
561 msgInfo->networkStatus = MSG_NETWORK_SEND_SUCCESS;
562 msgInfo->bRead = false;
563 msgInfo->bProtected = false;
564 msgInfo->priority = MSG_MESSAGE_PRIORITY_NORMAL;
565 msgInfo->direction = MSG_DIRECTION_TYPE_MO;
566 msgInfo->bTextSms = true;
568 memset(msgInfo->subject, 0x00, MAX_SUBJECT_LEN+1);
570 /** What kind of time has to be saved?? (temporary store time) */
571 msgInfo->displayTime = time(NULL);
573 /** Convert Address values */
574 msgInfo->nAddressCnt = 1;
576 msgInfo->addressList = (MSG_ADDRESS_INFO_S *)new char[sizeof(MSG_ADDRESS_INFO_S)];
577 memset(msgInfo->addressList, 0x00, sizeof(MSG_ADDRESS_INFO_S));
579 msgInfo->addressList[addressListCnt].addressType = MSG_ADDRESS_TYPE_PLMN;
580 strncpy(msgInfo->addressList[addressListCnt].addressVal, pTpdu->destAddress.address, MAX_ADDRESS_VAL_LEN);
582 /**exception operation for none userdata */
583 if (pTpdu->userData.length == 0) {
584 snprintf(msgInfo->msgText, sizeof(msgInfo->msgText), "[Broken Message]");
585 msgInfo->dataSize = strlen(msgInfo->msgText);
589 /** Convert Data values */
590 MsgTextConvert *textCvt = MsgTextConvert::instance();
591 if (pTpdu->dcs.codingScheme == SMS_CHARSET_7BIT) {
592 MSG_LANG_INFO_S langInfo = {0, };
594 langInfo.bSingleShift = false;
595 langInfo.bLockingShift = false;
597 msgInfo->dataSize = textCvt->convertGSM7bitToUTF8((unsigned char*)msgInfo->msgText, MAX_MSG_TEXT_LEN, (unsigned char*)pTpdu->userData.data, pTpdu->userData.length, &langInfo);
598 } else if (pTpdu->dcs.codingScheme == SMS_CHARSET_UCS2) {
599 msgInfo->dataSize = textCvt->convertUCS2ToUTF8((unsigned char*)msgInfo->msgText, MAX_MSG_TEXT_LEN, (unsigned char*)pTpdu->userData.data, pTpdu->userData.length);
604 void SmsPluginEventHandler::convertDeliverTpduToMsginfo(const SMS_DELIVER_S *pTpdu, MSG_MESSAGE_INFO_S *msgInfo)
608 /** Convert Type values */
609 msgInfo->msgType.mainType = MSG_SMS_TYPE;
610 msgInfo->msgType.subType = convertMsgSubType(pTpdu->pid);
612 /** set folder id (temporary) */
613 msgInfo->folderId = MSG_INBOX_ID;
616 if (msgInfo->storageId == MSG_STORAGE_SIM) {
617 /*** Comment below lines to save local UTC time..... (it could be used later.)
619 if (pTpdu->timeStamp.format == SMS_TIME_ABSOLUTE) {
620 MSG_DEBUG("year : %d", pTpdu->timeStamp.time.absolute.year);
621 MSG_DEBUG("month : %d", pTpdu->timeStamp.time.absolute.month);
622 MSG_DEBUG("day : %d", pTpdu->timeStamp.time.absolute.day);
623 MSG_DEBUG("hour : %d", pTpdu->timeStamp.time.absolute.hour);
624 MSG_DEBUG("minute : %d", pTpdu->timeStamp.time.absolute.minute);
625 MSG_DEBUG("second : %d", pTpdu->timeStamp.time.absolute.second);
626 MSG_DEBUG("timezone : %d", pTpdu->timeStamp.time.absolute.timeZone);
628 char displayTime[32];
632 memset(&timeinfo, 0x00, sizeof(tm));
634 timeinfo.tm_year = (pTpdu->timeStamp.time.absolute.year + 100);
635 timeinfo.tm_mon = (pTpdu->timeStamp.time.absolute.month - 1);
636 timeinfo.tm_mday = pTpdu->timeStamp.time.absolute.day;
637 timeinfo.tm_hour = pTpdu->timeStamp.time.absolute.hour;
638 timeinfo.tm_min = pTpdu->timeStamp.time.absolute.minute;
639 timeinfo.tm_sec = pTpdu->timeStamp.time.absolute.second;
640 timeinfo.tm_isdst = 0;
642 rawtime = mktime(&timeinfo);
644 MSG_DEBUG("tzname[0] [%s]", tzname[0]);
645 MSG_DEBUG("tzname[1] [%s]", tzname[1]);
646 MSG_DEBUG("timezone [%d]", timezone);
647 MSG_DEBUG("daylight [%d]", daylight);
649 memset(displayTime, 0x00, sizeof(displayTime));
650 strftime(displayTime, 32, "%Y-%02m-%02d %T %z", &timeinfo);
651 MSG_DEBUG("displayTime [%s]", displayTime);
653 rawtime -= (pTpdu->timeStamp.time.absolute.timeZone * (3600/4));
655 localtime_r(&rawtime, &timeTM);
656 memset(displayTime, 0x00, sizeof(displayTime));
657 strftime(displayTime, 32, "%Y-%02m-%02d %T %z", &timeTM);
658 MSG_DEBUG("displayTime [%s]", displayTime);
662 localtime_r(&rawtime, &timeTM);
663 memset(displayTime, 0x00, sizeof(displayTime));
664 strftime(displayTime, 32, "%Y-%02m-%02d %T %z", &timeTM);
665 MSG_DEBUG("displayTime [%s]", displayTime);
669 rawtime = time(NULL);
671 msgInfo->displayTime = rawtime;
673 switch (pTpdu->dcs.msgClass) {
674 case SMS_MSG_CLASS_0:
675 msgInfo->msgType.classType = MSG_CLASS_0;
677 case SMS_MSG_CLASS_1:
678 msgInfo->msgType.classType = MSG_CLASS_1;
680 case SMS_MSG_CLASS_2:
681 msgInfo->msgType.classType = MSG_CLASS_2;
682 msgInfo->storageId = MSG_STORAGE_SIM;
684 case SMS_MSG_CLASS_3:
685 msgInfo->msgType.classType = MSG_CLASS_3;
688 msgInfo->msgType.classType = MSG_CLASS_NONE;
692 if (pTpdu->dcs.bMWI) {
693 if (pTpdu->dcs.indType == SMS_VOICE_INDICATOR)
694 msgInfo->msgType.subType = MSG_MWI_VOICE_SMS;
695 else if (pTpdu->dcs.indType == SMS_VOICE2_INDICATOR)
696 msgInfo->msgType.subType = MSG_MWI_VOICE2_SMS;
697 else if (pTpdu->dcs.indType == SMS_FAX_INDICATOR)
698 msgInfo->msgType.subType = MSG_MWI_FAX_SMS;
699 else if (pTpdu->dcs.indType == SMS_EMAIL_INDICATOR)
700 msgInfo->msgType.subType = MSG_MWI_EMAIL_SMS;
701 else if (pTpdu->dcs.indType == SMS_OTHER_INDICATOR)
702 msgInfo->msgType.subType = MSG_MWI_OTHER_SMS;
705 msgInfo->networkStatus = MSG_NETWORK_RECEIVED;
706 msgInfo->bRead = false;
707 msgInfo->bProtected = false;
708 msgInfo->priority = MSG_MESSAGE_PRIORITY_NORMAL;
709 msgInfo->direction = MSG_DIRECTION_TYPE_MT;
710 msgInfo->bTextSms = true;
712 memset(msgInfo->subject, 0x00, MAX_SUBJECT_LEN+1);
714 /** Convert Address values */
715 msgInfo->nAddressCnt = 1;
717 msgInfo->addressList = (MSG_ADDRESS_INFO_S *)new char[sizeof(MSG_ADDRESS_INFO_S)];
718 memset(msgInfo->addressList, 0x00, sizeof(MSG_ADDRESS_INFO_S));
720 msgInfo->addressList[0].addressType = MSG_ADDRESS_TYPE_PLMN;
721 strncpy(msgInfo->addressList[0].addressVal, pTpdu->originAddress.address, MAX_ADDRESS_VAL_LEN);
723 msgInfo->msgPort.valid = false;
724 msgInfo->msgPort.dstPort = 0;
725 msgInfo->msgPort.srcPort = 0;
727 for (int i = 0; i < pTpdu->userData.headerCnt; i++) {
728 /** Convert UDH values - Port Number */
729 if (pTpdu->userData.header[i].udhType == SMS_UDH_APP_PORT_8BIT) {
730 msgInfo->msgPort.valid = true;
731 msgInfo->msgPort.dstPort = pTpdu->userData.header[i].udh.appPort8bit.destPort;
732 msgInfo->msgPort.srcPort = pTpdu->userData.header[i].udh.appPort8bit.originPort;
733 } else if (pTpdu->userData.header[i].udhType == SMS_UDH_APP_PORT_16BIT) {
734 msgInfo->msgPort.valid = true;
735 msgInfo->msgPort.dstPort = pTpdu->userData.header[i].udh.appPort16bit.destPort;
736 msgInfo->msgPort.srcPort = pTpdu->userData.header[i].udh.appPort16bit.originPort;
737 } else if (pTpdu->userData.header[i].udhType == SMS_UDH_SPECIAL_SMS) {
738 msgInfo->msgType.subType = (pTpdu->userData.header[i].udh.specialInd.msgInd+MSG_MWI_VOICE_SMS);
739 msgInfo->bStore = pTpdu->userData.header[i].udh.specialInd.bStore;
741 bUdhMwiMethod = true;
743 if (pTpdu->dcs.codingGroup == SMS_GROUP_DISCARD)
744 msgInfo->bStore = false;
746 udhMwiCnt = pTpdu->userData.header[i].udh.specialInd.waitMsgNum;
749 MSG_DEBUG("Message waiting number is smaller than 0. It will be treated as 0. [%d]", udhMwiCnt);
753 MSG_DEBUG("Message waiting number : [%d]", udhMwiCnt);
755 SmsPluginSetting::instance()->setMwiInfo(msgInfo->sim_idx, msgInfo->msgType.subType, udhMwiCnt);
757 if (udhMwiCnt > 0 && (msgInfo->msgType.subType >= MSG_MWI_VOICE_SMS && msgInfo->msgType.subType <= MSG_MWI_OTHER_SMS)) {
758 switch (msgInfo->msgType.subType) {
759 case MSG_MWI_VOICE_SMS :
760 snprintf(msgInfo->msgText, sizeof(msgInfo->msgText), "%d", udhMwiCnt);
762 case MSG_MWI_FAX_SMS :
763 snprintf(msgInfo->msgText, sizeof(msgInfo->msgText), "%d new fax message", udhMwiCnt);
765 case MSG_MWI_EMAIL_SMS :
766 snprintf(msgInfo->msgText, sizeof(msgInfo->msgText), "%d new email message", udhMwiCnt);
769 snprintf(msgInfo->msgText, sizeof(msgInfo->msgText), "%d new special message", udhMwiCnt);
772 msgInfo->dataSize = strlen(msgInfo->msgText);
775 } else if (pTpdu->userData.header[i].udhType == SMS_UDH_ALTERNATE_REPLY_ADDRESS) {
776 strncpy(msgInfo->addressList[0].addressVal, pTpdu->userData.header[i].udh.alternateAddress.address, MAX_ADDRESS_VAL_LEN);
777 } else if (pTpdu->userData.header[i].udhType >= SMS_UDH_EMS_FIRST && pTpdu->userData.header[i].udhType <= SMS_UDH_EMS_LAST) {
778 /* TODO: Raw text should be changed to string design id. Currently there's no design id in message-app-lite */
779 /* char *msg_text = getTranslateText(MSG_APP_PACKAGE_NAME, MSG_APP_LOCALEDIR, "IDS_MSGF_POP_ERROR_UNSUPPORTED_MSG");
780 snprintf(msgInfo->msgText, sizeof(msgInfo->msgText), "%s", msg_text);
782 snprintf(msgInfo->msgText, sizeof(msgInfo->msgText), "Unsupported Message");
783 msgInfo->dataSize = strlen(msgInfo->msgText);
793 /**length 0 - no user data - msg should be received */
794 if (pTpdu->userData.length <= 0) {
795 memset(msgInfo->msgText, 0x00, sizeof(msgInfo->msgText));
796 msgInfo->dataSize = 0;
798 switch (pTpdu->dcs.codingScheme) {
799 case SMS_CHARSET_7BIT:
800 msgInfo->encodeType = MSG_ENCODE_GSM7BIT;
802 case SMS_CHARSET_8BIT:
803 msgInfo->encodeType = MSG_ENCODE_8BIT;
805 case SMS_CHARSET_UCS2:
806 msgInfo->encodeType = MSG_ENCODE_UCS2;
809 msgInfo->encodeType = MSG_ENCODE_8BIT;
814 } else if (pTpdu->userData.length > MAX_MSG_TEXT_LEN) {
815 snprintf(msgInfo->msgText, sizeof(msgInfo->msgText), "[Broken Message]");
816 msgInfo->dataSize = strlen(msgInfo->msgData);
820 /** Convert Data values */
821 MsgTextConvert *textCvt = MsgTextConvert::instance();
822 if (pTpdu->dcs.codingScheme == SMS_CHARSET_7BIT) {
823 MSG_LANG_INFO_S langInfo = {0, };
825 langInfo.bSingleShift = false;
826 langInfo.bLockingShift = false;
828 for (int i = 0; i < pTpdu->userData.headerCnt; i++) {
829 if (pTpdu->userData.header[i].udhType == SMS_UDH_SINGLE_SHIFT) {
830 langInfo.bSingleShift = true;
831 langInfo.singleLang = pTpdu->userData.header[i].udh.singleShift.langId;
832 } else if (pTpdu->userData.header[i].udhType == SMS_UDH_LOCKING_SHIFT) {
833 langInfo.bLockingShift = true;
834 langInfo.lockingLang = pTpdu->userData.header[i].udh.lockingShift.langId;
838 msgInfo->encodeType = MSG_ENCODE_GSM7BIT;
839 msgInfo->dataSize = textCvt->convertGSM7bitToUTF8((unsigned char*)msgInfo->msgText, MAX_MSG_TEXT_LEN, (unsigned char*)pTpdu->userData.data, pTpdu->userData.length, &langInfo);
840 } else if (pTpdu->dcs.codingScheme == SMS_CHARSET_8BIT) {
841 msgInfo->encodeType = MSG_ENCODE_8BIT;
842 memcpy(msgInfo->msgText, pTpdu->userData.data, sizeof(pTpdu->userData.data));
843 msgInfo->dataSize = pTpdu->userData.length;
844 } else if (pTpdu->dcs.codingScheme == SMS_CHARSET_UCS2) {
845 msgInfo->encodeType = MSG_ENCODE_UCS2;
846 msgInfo->dataSize = textCvt->convertUCS2ToUTF8((unsigned char*)msgInfo->msgText, MAX_MSG_TEXT_LEN, (unsigned char*)pTpdu->userData.data, pTpdu->userData.length);
847 } else if (pTpdu->dcs.codingScheme == SMS_CHARSET_EUCKR) {
848 msgInfo->encodeType = MSG_ENCODE_8BIT;
849 msgInfo->dataSize = textCvt->convertEUCKRToUTF8((unsigned char*)msgInfo->msgText, MAX_MSG_TEXT_LEN, (unsigned char*)pTpdu->userData.data, pTpdu->userData.length);
857 void SmsPluginEventHandler::convertStatusRepTpduToMsginfo(const SMS_STATUS_REPORT_S *pTpdu, MSG_MESSAGE_INFO_S *msgInfo)
859 /** Convert Type values */
860 msgInfo->msgType.mainType = MSG_SMS_TYPE;
861 msgInfo->msgType.subType = MSG_STATUS_REPORT_SMS;
864 msgInfo->folderId = MSG_INBOX_ID;
866 /** set storage id */
867 if (msgInfo->storageId == MSG_STORAGE_UNKNOWN) {
868 msgInfo->storageId = MSG_STORAGE_PHONE;
871 switch (pTpdu->dcs.msgClass) {
872 case SMS_MSG_CLASS_0:
873 msgInfo->msgType.classType = MSG_CLASS_0;
875 case SMS_MSG_CLASS_1:
876 msgInfo->msgType.classType = MSG_CLASS_1;
878 case SMS_MSG_CLASS_2:
879 msgInfo->msgType.classType = MSG_CLASS_2;
881 case SMS_MSG_CLASS_3:
882 msgInfo->msgType.classType = MSG_CLASS_3;
885 msgInfo->msgType.classType = MSG_CLASS_NONE;
889 MSG_DEBUG("delivery status : [%d]", pTpdu->status);
891 if (pTpdu->status == SMS_STATUS_RECEIVE_SUCCESS)
892 msgInfo->networkStatus = MSG_NETWORK_DELIVER_SUCCESS;
893 else if (pTpdu->status == SMS_STATUS_TRY_REQUEST_PENDING)
894 msgInfo->networkStatus = MSG_NETWORK_DELIVER_PENDING;
895 else if (pTpdu->status == SMS_STATUS_PERM_MSG_VAL_PERIOD_EXPIRED)
896 msgInfo->networkStatus = MSG_NETWORK_DELIVER_EXPIRED;
898 msgInfo->networkStatus = MSG_NETWORK_DELIVER_FAIL;
900 msgInfo->bRead = false;
901 msgInfo->bProtected = false;
902 msgInfo->priority = MSG_MESSAGE_PRIORITY_NORMAL;
903 msgInfo->direction = MSG_DIRECTION_TYPE_MT;
904 msgInfo->bTextSms = true;
906 memset(msgInfo->subject, 0x00, MAX_SUBJECT_LEN+1);
908 msgInfo->displayTime = time(NULL);
910 /** Convert Address values */
911 msgInfo->nAddressCnt = 1;
913 msgInfo->addressList = (MSG_ADDRESS_INFO_S *)new char[sizeof(MSG_ADDRESS_INFO_S)];
914 memset(msgInfo->addressList, 0x00, sizeof(MSG_ADDRESS_INFO_S));
916 msgInfo->addressList[0].addressType = MSG_ADDRESS_TYPE_PLMN;
917 strncpy(msgInfo->addressList[0].addressVal, pTpdu->recipAddress.address, MAX_ADDRESS_VAL_LEN);
919 msgInfo->msgPort.valid = false;
920 msgInfo->msgPort.dstPort = 0;
921 msgInfo->msgPort.srcPort = 0;
923 for (int i = 0; i < pTpdu->userData.headerCnt; i++) {
924 /** Convert UDH values - Port Number */
925 if (pTpdu->userData.header[i].udhType == SMS_UDH_APP_PORT_8BIT) {
926 msgInfo->msgPort.valid = true;
927 msgInfo->msgPort.dstPort = pTpdu->userData.header[i].udh.appPort8bit.destPort;
928 msgInfo->msgPort.srcPort = pTpdu->userData.header[i].udh.appPort8bit.originPort;
929 } else if (pTpdu->userData.header[i].udhType == SMS_UDH_APP_PORT_16BIT) {
930 msgInfo->msgPort.valid = true;
931 msgInfo->msgPort.dstPort = pTpdu->userData.header[i].udh.appPort16bit.destPort;
932 msgInfo->msgPort.srcPort = pTpdu->userData.header[i].udh.appPort16bit.originPort;
936 memset(msgInfo->msgText, 0x00, sizeof(msgInfo->msgText));
937 msgInfo->dataSize = 0;
939 if (pTpdu->status <= SMS_STATUS_SMSC_SPECIFIC_LAST) {
940 char *msg_text = getTranslateText(MSG_APP_PACKAGE_NAME, MSG_APP_LOCALEDIR, "IDS_MSGF_BODY_MESSAGE_DELIVERED");
941 snprintf(msgInfo->msgText, sizeof(msgInfo->msgText), "%s", msg_text);
942 msgInfo->dataSize = strlen(msgInfo->msgText);
947 } else if (pTpdu->status == SMS_STATUS_TEMP_SERVICE_REJECTED) {
948 char *msg_text = getTranslateText(MSG_APP_PACKAGE_NAME, MSG_APP_LOCALEDIR, "IDS_MSGF_BODY_MMSDELIVERYMSGREJECTED");
949 snprintf(msgInfo->msgText, sizeof(msgInfo->msgText), "%s", msg_text);
950 msgInfo->dataSize = strlen(msgInfo->msgText);
955 } else if (pTpdu->status == SMS_STATUS_PERM_MSG_VAL_PERIOD_EXPIRED) {
956 char *msg_text = getTranslateText(MSG_APP_PACKAGE_NAME, MSG_APP_LOCALEDIR, "IDS_MSGF_BODY_MESSAGE_HAS_EXPIRED");
957 snprintf(msgInfo->msgText, sizeof(msgInfo->msgText), "%s", msg_text);
958 msgInfo->dataSize = strlen(msgInfo->msgText);
964 strncpy(msgInfo->msgText, "Message delivery failed.", MAX_MSG_TEXT_LEN);
965 msgInfo->dataSize = strlen(msgInfo->msgText);
970 MSG_SUB_TYPE_T SmsPluginEventHandler::convertMsgSubType(SMS_PID_T pid)
974 return MSG_TYPE0_SMS;
975 case SMS_PID_REPLACE_TYPE1 :
976 return MSG_REPLACE_TYPE1_SMS;
977 case SMS_PID_REPLACE_TYPE2 :
978 return MSG_REPLACE_TYPE2_SMS;
979 case SMS_PID_REPLACE_TYPE3 :
980 return MSG_REPLACE_TYPE3_SMS;
981 case SMS_PID_REPLACE_TYPE4 :
982 return MSG_REPLACE_TYPE4_SMS;
983 case SMS_PID_REPLACE_TYPE5 :
984 return MSG_REPLACE_TYPE5_SMS;
985 case SMS_PID_REPLACE_TYPE6 :
986 return MSG_REPLACE_TYPE6_SMS;
987 case SMS_PID_REPLACE_TYPE7 :
988 return MSG_REPLACE_TYPE7_SMS;
989 case SMS_PID_RETURN_CALL :
990 return MSG_MWI_OTHER_SMS;
992 return MSG_NORMAL_SMS;
997 void SmsPluginEventHandler::SetSentInfo(SMS_SENT_INFO_S *pSentInfo)
999 memset(&sentInfo, 0x00, sizeof(SMS_SENT_INFO_S));
1000 memcpy(&sentInfo, pSentInfo, sizeof(SMS_SENT_INFO_S));
1002 MSG_DEBUG("sentInfo.reqId : %d", sentInfo.reqInfo.reqId);
1003 MSG_DEBUG("sentInfo.bLast : %d", sentInfo.bLast);
1007 void SmsPluginEventHandler::setDeviceStatus(TapiHandle *handle)
1009 if (handle == devHandle) {
1018 bool SmsPluginEventHandler::getDeviceStatus(TapiHandle *handle)
1024 ret = cv.timedwait(mx.pMsgMutex(), MAX_TAPI_SIM_API_TIMEOUT);
1026 if (ret == ETIMEDOUT) {
1027 MSG_WARN("WARNING: DEVICE STATUS TIME-OUT");
1036 msg_error_t SmsPluginEventHandler::handleSimMsg(MSG_MESSAGE_INFO_S *pMsgInfo, int *simIdList, msg_message_id_t *retMsgId, int listSize)
1040 msg_error_t err = MSG_SUCCESS;
1042 /** Callback to MSG FW */
1043 err = listener.pfSimMsgIncomingCb(pMsgInfo, simIdList, retMsgId, listSize);
1050 msg_error_t SmsPluginEventHandler::updateIMSI(int sim_idx)
1054 msg_error_t err = MSG_SUCCESS;
1056 /** Callback to MSG FW */
1057 err = listener.pfSimInitImsiCb(sim_idx);
1064 void SmsPluginEventHandler::handleSimMemoryFull(int simIndex)
1066 char keyName[MAX_VCONFKEY_NAME_LEN];
1067 bool bSimSst = true;
1068 memset(keyName, 0x00, sizeof(keyName));
1069 snprintf(keyName, sizeof(keyName), "%s/%d", MSG_SIM_SERVICE_TABLE, simIndex);
1070 if (MsgSettingGetBool(keyName, &bSimSst) != MSG_SUCCESS)
1071 MSG_ERR("MsgSettingGetBool [%s] failed", keyName);
1073 if (bSimSst == true)
1074 MsgInsertTicker("Sim memory full. Delete some items", SMS_MESSAGE_SIM_MESSAGE_FULL, true, 0);