2 * Copyright 2012-2013 Samsung Electronics Co., Ltd
4 * Licensed under the Flora License, Version 1.1 (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://floralicense.org/license/
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 "MsgGconfWrapper.h"
25 #include "SmsPluginTransport.h"
26 #include "SmsPluginSimMsg.h"
27 #include "SmsPluginStorage.h"
28 #include "SmsPluginSetting.h"
29 #include "SmsPluginConcatHandler.h"
30 #include "SmsPluginEventHandler.h"
33 /*==================================================================================================
34 IMPLEMENTATION OF SmsPluginEventHandler - Member Functions
35 ==================================================================================================*/
36 SmsPluginEventHandler* SmsPluginEventHandler::pInstance = NULL;
39 SmsPluginEventHandler::SmsPluginEventHandler()
41 /** Initialize global parameters */
42 memset(&listener, 0x00, sizeof(MSG_PLUGIN_LISTENER_S));
49 SmsPluginEventHandler::~SmsPluginEventHandler()
55 SmsPluginEventHandler* SmsPluginEventHandler::instance()
58 pInstance = new SmsPluginEventHandler();
64 void SmsPluginEventHandler::registerListener(MSG_PLUGIN_LISTENER_S *pListener)
66 listener = *pListener;
70 void SmsPluginEventHandler::handleSentStatus(msg_network_status_t NetStatus)
72 MSG_DEBUG("NetStatus[%d]", NetStatus);
74 SmsPluginTransport::instance()->setNetStatus(NetStatus);
76 if (sentInfo.bLast == true || NetStatus != MSG_NETWORK_SEND_SUCCESS) {
77 /** Update Msg Status */
78 if (sentInfo.reqInfo.msgInfo.msgPort.valid == false){
79 SmsPluginStorage::instance()->updateSentMsg(&(sentInfo.reqInfo.msgInfo), NetStatus);
80 sentInfo.reqInfo.msgInfo.networkStatus = NetStatus;
81 callbackStorageChange(MSG_STORAGE_CHANGE_UPDATE, &(sentInfo.reqInfo.msgInfo));
84 MSG_DEBUG("sentInfo.reqInfo.sendOptInfo.bSetting [%d]", sentInfo.reqInfo.sendOptInfo.bSetting);
85 MSG_DEBUG("sentInfo.reqInfo.sendOptInfo.bKeepCopy [%d]", sentInfo.reqInfo.sendOptInfo.bKeepCopy);
86 /** Check sending options */
87 if (sentInfo.reqInfo.sendOptInfo.bSetting && !sentInfo.reqInfo.sendOptInfo.bKeepCopy && NetStatus == MSG_NETWORK_SEND_SUCCESS) {
88 SmsPluginStorage::instance()->deleteSmsMessage(sentInfo.reqInfo.msgInfo.msgId);
89 callbackStorageChange(MSG_STORAGE_CHANGE_DELETE, &(sentInfo.reqInfo.msgInfo));
92 /** Callback to MSG FW */
93 MSG_SENT_STATUS_S msgStatus;
95 msgStatus.reqId = sentInfo.reqInfo.reqId;
96 msgStatus.status = NetStatus;
98 MSG_DEBUG("sentStatus.reqId : %d", msgStatus.reqId);
99 MSG_DEBUG("sentStatus.status : %d", msgStatus.status);
101 listener.pfSentStatusCb(&msgStatus);
106 void SmsPluginEventHandler::handleMsgIncoming(SMS_TPDU_S *pTpdu)
108 /** Make MSG_MESSAGE_INFO_S */
109 MSG_MESSAGE_INFO_S msgInfo;
111 /** initialize msgInfo */
112 memset(&msgInfo, 0x00, sizeof(MSG_MESSAGE_INFO_S));
114 /** check unsupported message */
115 if (pTpdu->tpduType == SMS_TPDU_DELIVER) {
116 if (pTpdu->data.deliver.dcs.codingScheme == SMS_CHARSET_8BIT && pTpdu->data.deliver.pid == 0x11) {
117 MSG_DEBUG("Unsupported message!!");
118 SmsPluginTransport::instance()->sendDeliverReport(MSG_SUCCESS);
123 /** check discard & indicator inactive message **/
124 if (pTpdu->data.deliver.dcs.bMWI == true &&
125 pTpdu->data.deliver.dcs.bIndActive == false &&
126 pTpdu->data.deliver.dcs.codingGroup == SMS_GROUP_DISCARD) {
127 MSG_DEBUG("Discard and no-indication message!!");
128 SmsPluginTransport::instance()->sendDeliverReport(MSG_SUCCESS);
132 /** convert to msgInfo */
133 convertTpduToMsginfo(pTpdu, &msgInfo);
135 /** Short Message Type 0 - Just Send Deliver Report */
136 if (msgInfo.msgType.subType == MSG_TYPE0_SMS) {
137 SmsPluginTransport::instance()->sendDeliverReport(MSG_SUCCESS);
141 /** Print MSG_MESSAGE_INFO_S */
142 MSG_DEBUG("############# Convert tpdu values to Message Info values ####################");
143 MSG_DEBUG("msgInfo.nAddressCnt : %d", msgInfo.nAddressCnt);
144 MSG_DEBUG("msgInfo.addressList[0].addressType : %d", msgInfo.addressList[0].addressType);
145 MSG_DEBUG("msgInfo.addressList[0].addressVal : %s", msgInfo.addressList[0].addressVal);
146 MSG_DEBUG("msgInfo.priority : %d", msgInfo.priority);
147 MSG_DEBUG("msgInfo.bProtected : %d", msgInfo.bProtected);
148 MSG_DEBUG("msgInfo.bRead : %d", msgInfo.bRead);
149 MSG_DEBUG("msgInfo.bTextSms : %d", msgInfo.bTextSms);
150 MSG_DEBUG("msgInfo.direction : %d", msgInfo.direction);
151 MSG_DEBUG("msgInfo.msgType.mainType : %d", msgInfo.msgType.mainType);
152 MSG_DEBUG("msgInfo.msgType.subType : %d", msgInfo.msgType.subType);
153 MSG_DEBUG("msgInfo.msgType.classType : %d", msgInfo.msgType.classType);
154 MSG_DEBUG("msgInfo.displayTime : %s", ctime(&msgInfo.displayTime));
155 MSG_DEBUG("msgInfo.msgPort.valid : %d", msgInfo.msgPort.valid);
156 MSG_DEBUG("msgInfo.encodeType : %d", msgInfo.encodeType);
157 MSG_DEBUG("msgInfo.dataSize : %d", msgInfo.dataSize);
159 if (msgInfo.bTextSms == true) {
160 MSG_DEBUG("msgInfo.msgText : %s", msgInfo.msgText);
162 MSG_DEBUG("msgInfo.msgData : %s", msgInfo.msgData);
165 MSG_DEBUG("###############################################################");
167 msg_error_t err = MSG_SUCCESS;
169 if (msgInfo.msgType.subType == MSG_STATUS_REPORT_SMS) {
170 /** Status Report Message */
171 err = listener.pfMsgIncomingCb(&msgInfo);
173 /** Handling of Fail Case ?? */
174 SmsPluginTransport::instance()->sendDeliverReport(MSG_SUCCESS);
175 } else { /** SMS Deliver */
177 if (msgInfo.msgType.classType == MSG_CLASS_2) {
178 if (msgInfo.bTextSms == false) { /** Concat Msg cannot be saved in SIM */
179 msgInfo.msgType.classType = MSG_CLASS_NONE;
180 msgInfo.storageId = MSG_STORAGE_PHONE;
184 if (msgInfo.msgPort.valid == false) {
185 err = SmsPluginStorage::instance()->addMessage(&msgInfo);
188 /** Callback to MSG FW */
189 if (msgInfo.msgType.classType != MSG_CLASS_2) {
190 if (err == MSG_SUCCESS) {
191 MSG_DEBUG("callback to msg fw");
192 err = listener.pfMsgIncomingCb(&msgInfo);
194 if (msgInfo.msgType.classType == MSG_CLASS_0) {
195 MSG_DEBUG("callback for class0 message to msg fw");
196 if (listener.pfMsgIncomingCb(&msgInfo) != MSG_SUCCESS)
197 MSG_DEBUG("listener.pfMsgIncomingCb is failed!");
201 /** Send Deliver Report */
202 if (msgInfo.msgType.classType == MSG_CLASS_0)
203 SmsPluginTransport::instance()->sendClass0DeliverReport(err);
205 SmsPluginTransport::instance()->sendDeliverReport(err);
208 // Tizen Validation System
210 msisdn = MsgSettingGetString(MSG_SIM_MSISDN);
212 MSG_SMS_VLD_INFO("%d, SMS Receive, %s->%s, %s", msgInfo.msgId, \
213 msgInfo.addressList[0].addressVal, \
214 (msisdn == NULL)?"ME":msisdn, \
215 (err == MSG_SUCCESS)?"Success":"Fail");
217 MSG_SMS_VLD_TXT("%d, [%s]", msgInfo.msgId, msgInfo.msgText);
221 void SmsPluginEventHandler::handlePushMsgIncoming(char* pPushHeader, char* pPushBody, int pushBodyLen, char *application_id, char *content_type)
223 MSG_PUSH_MESSAGE_DATA_S pushData;
225 memset(&pushData, 0x00, sizeof(MSG_PUSH_MESSAGE_DATA_S));
228 memcpy(&pushData.pushHeader, pPushHeader, strlen(pPushHeader));
230 pushData.pushBodyLen = pushBodyLen;
231 memcpy(pushData.pushBody, pPushBody, pushBodyLen);
233 memcpy(pushData.pushAppId, application_id, MAX_WAPPUSH_ID_LEN);
234 memcpy(pushData.pushContentType, content_type, MAX_WAPPUSH_CONTENT_TYPE_LEN);
236 /** Callback to MSG FW */
237 listener.pfPushMsgIncomingCb(&pushData);
241 void SmsPluginEventHandler::handleSyncMLMsgIncoming(msg_syncml_message_type_t msgType, char* pPushBody, int PushBodyLen, char* pWspHeader, int WspHeaderLen)
243 MSG_SYNCML_MESSAGE_DATA_S syncMLData;
245 memset(&syncMLData, 0x00, sizeof(MSG_SYNCML_MESSAGE_DATA_S));
247 /** set syncML data */
248 syncMLData.syncmlType = msgType;
250 syncMLData.pushBodyLen = PushBodyLen;
251 memcpy(syncMLData.pushBody, pPushBody, PushBodyLen);
253 syncMLData.wspHeaderLen= WspHeaderLen;
254 memcpy(syncMLData.wspHeader, pWspHeader, WspHeaderLen);
256 /** Callback to MSG FW */
257 listener.pfSyncMLMsgIncomingCb(&syncMLData);
261 void SmsPluginEventHandler::handleLBSMsgIncoming(char* pPushHeader, char* pPushBody, int pushBodyLen)
263 MSG_LBS_MESSAGE_DATA_S lBSData;
265 memset(&lBSData, 0x00, sizeof(MSG_LBS_MESSAGE_DATA_S));
268 memcpy(&lBSData.pushHeader, pPushHeader, strlen(pPushHeader));
270 lBSData.pushBodyLen = pushBodyLen;
271 memcpy(lBSData.pushBody, pPushBody, pushBodyLen);
273 /** Callback to MSG FW */
274 listener.pfLBSMsgIncomingCb(&lBSData);
278 msg_error_t SmsPluginEventHandler::callbackMsgIncoming(MSG_MESSAGE_INFO_S *pMsgInfo)
282 msg_error_t err = MSG_SUCCESS;
284 /** Callback to MSG FW */
285 err = listener.pfMsgIncomingCb(pMsgInfo);
292 msg_error_t SmsPluginEventHandler::callbackCBMsgIncoming(MSG_CB_MSG_S *pCbMsg)
296 msg_error_t err = MSG_SUCCESS;
298 /** Callback to MSG FW */
299 err = listener.pfCBMsgIncomingCb(pCbMsg);
307 msg_error_t SmsPluginEventHandler::callbackInitSimBySat()
309 /** Callback to MSG FW */
310 return listener.pfInitSimBySatCb();
314 msg_error_t SmsPluginEventHandler::callbackStorageChange(msg_storage_change_type_t storageChangeType, MSG_MESSAGE_INFO_S *pMsgInfo)
316 /** Callback to MSG FW */
317 listener.pfStorageChangeCb(storageChangeType, pMsgInfo);
323 void SmsPluginEventHandler::convertTpduToMsginfo(SMS_TPDU_S *pTpdu, MSG_MESSAGE_INFO_S *msgInfo)
325 memset(msgInfo, 0x00, sizeof(MSG_MESSAGE_INFO_S));
327 switch(pTpdu->tpduType)
329 case SMS_TPDU_SUBMIT :
330 convertSubmitTpduToMsginfo(&pTpdu->data.submit, msgInfo);
332 case SMS_TPDU_DELIVER :
333 convertDeliverTpduToMsginfo(&pTpdu->data.deliver, msgInfo);
335 case SMS_TPDU_STATUS_REP :
336 convertStatusRepTpduToMsginfo(&pTpdu->data.statusRep, msgInfo);
342 void SmsPluginEventHandler::convertSubmitTpduToMsginfo(const SMS_SUBMIT_S *pTpdu, MSG_MESSAGE_INFO_S *msgInfo)
344 int addressListCnt = 0;
346 /** Convert Type values */
347 msgInfo->msgType.mainType = MSG_SMS_TYPE;
348 msgInfo->msgType.subType = convertMsgSubType(pTpdu->pid);
350 /** set folder id (temporary) */
351 msgInfo->folderId = MSG_OUTBOX_ID;
353 switch(pTpdu->dcs.msgClass)
355 case SMS_MSG_CLASS_0:
356 msgInfo->msgType.classType = MSG_CLASS_0;
358 case SMS_MSG_CLASS_1:
359 msgInfo->msgType.classType = MSG_CLASS_1;
361 case SMS_MSG_CLASS_2:
362 msgInfo->msgType.classType = MSG_CLASS_2;
364 case SMS_MSG_CLASS_3:
365 msgInfo->msgType.classType = MSG_CLASS_3;
368 msgInfo->msgType.classType = MSG_CLASS_NONE;
371 msgInfo->networkStatus = MSG_NETWORK_SEND_SUCCESS;
372 msgInfo->bRead = false;
373 msgInfo->bProtected = false;
374 msgInfo->priority = MSG_MESSAGE_PRIORITY_NORMAL;
375 msgInfo->direction = MSG_DIRECTION_TYPE_MT;
376 msgInfo->bTextSms = true;
378 memset(msgInfo->subject, 0x00, MAX_SUBJECT_LEN+1);
380 /** What kind of time has to be saved?? (temporary store time) */
385 msgInfo->displayTime = curTime;
387 /** Convert Address values */
388 msgInfo->nAddressCnt = 1;
389 msgInfo->addressList[addressListCnt].addressType = MSG_ADDRESS_TYPE_PLMN;
390 strncpy(msgInfo->addressList[addressListCnt].addressVal, pTpdu->destAddress.address, MAX_ADDRESS_VAL_LEN);
392 /**exception operation for none userdata */
393 if (pTpdu->userData.length == 0) {
394 sprintf(msgInfo->msgText, "[Broken Message]");
395 msgInfo->dataSize = strlen(msgInfo->msgText);
399 /** Convert Data values */
400 if (pTpdu->dcs.codingScheme == SMS_CHARSET_7BIT) {
401 MSG_LANG_INFO_S langInfo = {0,};
403 langInfo.bSingleShift = false;
404 langInfo.bLockingShift = false;
406 msgInfo->dataSize = textCvt.convertGSM7bitToUTF8((unsigned char*)msgInfo->msgText, MAX_MSG_TEXT_LEN, (unsigned char*)pTpdu->userData.data, pTpdu->userData.length, &langInfo);
407 } else if (pTpdu->dcs.codingScheme == SMS_CHARSET_UCS2) {
408 msgInfo->dataSize = textCvt.convertUCS2ToUTF8((unsigned char*)msgInfo->msgText, MAX_MSG_TEXT_LEN, (unsigned char*)pTpdu->userData.data, pTpdu->userData.length);
413 void SmsPluginEventHandler::convertDeliverTpduToMsginfo(const SMS_DELIVER_S *pTpdu, MSG_MESSAGE_INFO_S *msgInfo)
417 /** Convert Type values */
418 msgInfo->msgType.mainType = MSG_SMS_TYPE;
419 msgInfo->msgType.subType = convertMsgSubType(pTpdu->pid);
421 /** set folder id (temporary) */
422 msgInfo->folderId = MSG_INBOX_ID;
424 msgInfo->storageId = MSG_STORAGE_PHONE;
426 switch(pTpdu->dcs.msgClass)
428 case SMS_MSG_CLASS_0:
429 msgInfo->msgType.classType = MSG_CLASS_0;
431 case SMS_MSG_CLASS_1:
432 msgInfo->msgType.classType = MSG_CLASS_1;
434 case SMS_MSG_CLASS_2:
435 msgInfo->msgType.classType = MSG_CLASS_2;
436 msgInfo->storageId = MSG_STORAGE_SIM;
438 case SMS_MSG_CLASS_3:
439 msgInfo->msgType.classType = MSG_CLASS_3;
442 msgInfo->msgType.classType = MSG_CLASS_NONE;
446 if (pTpdu->dcs.bMWI) {
447 msgInfo->msgType.subType = (pTpdu->dcs.indType + MSG_MWI_VOICE_SMS);
450 msgInfo->networkStatus = MSG_NETWORK_RECEIVED;
451 msgInfo->bRead = false;
452 msgInfo->bProtected = false;
453 msgInfo->priority = MSG_MESSAGE_PRIORITY_NORMAL;
454 msgInfo->direction = MSG_DIRECTION_TYPE_MT;
455 msgInfo->bTextSms = true;
457 memset(msgInfo->subject, 0x00, MAX_SUBJECT_LEN+1);
459 time_t rawtime = time(NULL);
461 /*** Comment below lines to save local UTC time..... (it could be used later.)
463 if (pTpdu->timeStamp.format == SMS_TIME_ABSOLUTE) {
465 MSG_DEBUG("year : %d", pTpdu->timeStamp.time.absolute.year);
466 MSG_DEBUG("month : %d", pTpdu->timeStamp.time.absolute.month);
467 MSG_DEBUG("day : %d", pTpdu->timeStamp.time.absolute.day);
468 MSG_DEBUG("hour : %d", pTpdu->timeStamp.time.absolute.hour);
469 MSG_DEBUG("minute : %d", pTpdu->timeStamp.time.absolute.minute);
470 MSG_DEBUG("second : %d", pTpdu->timeStamp.time.absolute.second);
471 MSG_DEBUG("timezone : %d", pTpdu->timeStamp.time.absolute.timeZone);
473 char displayTime[32];
477 memset(&timeinfo, 0x00, sizeof(tm));
479 timeinfo.tm_year = (pTpdu->timeStamp.time.absolute.year + 100);
480 timeinfo.tm_mon = (pTpdu->timeStamp.time.absolute.month - 1);
481 timeinfo.tm_mday = pTpdu->timeStamp.time.absolute.day;
482 timeinfo.tm_hour = pTpdu->timeStamp.time.absolute.hour;
483 timeinfo.tm_min = pTpdu->timeStamp.time.absolute.minute;
484 timeinfo.tm_sec = pTpdu->timeStamp.time.absolute.second;
485 timeinfo.tm_isdst = 0;
487 rawtime = mktime(&timeinfo);
489 MSG_DEBUG("tzname[0] [%s]", tzname[0]);
490 MSG_DEBUG("tzname[1] [%s]", tzname[1]);
491 MSG_DEBUG("timezone [%d]", timezone);
492 MSG_DEBUG("daylight [%d]", daylight);
494 memset(displayTime, 0x00, sizeof(displayTime));
495 strftime(displayTime, 32, "%Y-%02m-%02d %T %z", &timeinfo);
496 MSG_DEBUG("displayTime [%s]", displayTime);
498 rawtime -= (pTpdu->timeStamp.time.absolute.timeZone * (3600/4));
500 timeTM = localtime(&rawtime);
501 memset(displayTime, 0x00, sizeof(displayTime));
502 strftime(displayTime, 32, "%Y-%02m-%02d %T %z", timeTM);
503 MSG_DEBUG("displayTime [%s]", displayTime);
507 timeTM = localtime(&rawtime);
508 memset(displayTime, 0x00, sizeof(displayTime));
509 strftime(displayTime, 32, "%Y-%02m-%02d %T %z", timeTM);
510 MSG_DEBUG("displayTime [%s]", displayTime);
515 msgInfo->displayTime = rawtime;
517 /** Convert Address values */
518 msgInfo->nAddressCnt = 1;
519 msgInfo->addressList[0].addressType = MSG_ADDRESS_TYPE_PLMN;
520 strncpy(msgInfo->addressList[0].addressVal, pTpdu->originAddress.address, MAX_ADDRESS_VAL_LEN);
522 msgInfo->msgPort.valid = false;
523 msgInfo->msgPort.dstPort = 0;
524 msgInfo->msgPort.srcPort = 0;
526 for (int i = 0; i < pTpdu->userData.headerCnt; i++) {
527 /** Convert UDH values - Port Number */
528 if (pTpdu->userData.header[i].udhType == SMS_UDH_APP_PORT_8BIT) {
529 msgInfo->msgPort.valid = true;
530 msgInfo->msgPort.dstPort = pTpdu->userData.header[i].udh.appPort8bit.destPort;
531 msgInfo->msgPort.srcPort = pTpdu->userData.header[i].udh.appPort8bit.originPort;
532 } else if (pTpdu->userData.header[i].udhType == SMS_UDH_APP_PORT_16BIT) {
533 msgInfo->msgPort.valid = true;
534 msgInfo->msgPort.dstPort = pTpdu->userData.header[i].udh.appPort16bit.destPort;
535 msgInfo->msgPort.srcPort = pTpdu->userData.header[i].udh.appPort16bit.originPort;
536 } else if (pTpdu->userData.header[i].udhType == SMS_UDH_SPECIAL_SMS) {
537 msgInfo->msgType.subType = (pTpdu->userData.header[i].udh.specialInd.msgInd+MSG_MWI_VOICE_SMS);
538 msgInfo->bStore = pTpdu->userData.header[i].udh.specialInd.bStore;
540 if (pTpdu->dcs.codingGroup == SMS_GROUP_DISCARD)
541 msgInfo->bStore = false;
543 MSG_DEBUG("Message waiting number : [%d]", pTpdu->userData.header[i].udh.specialInd.waitMsgNum);
544 SmsPluginSetting::instance()->setMwiInfo(msgInfo->msgType.subType, pTpdu->userData.header[i].udh.specialInd.waitMsgNum);
546 if (pTpdu->userData.length == 0) {
547 switch (msgInfo->msgType.subType) {
548 case MSG_MWI_VOICE_SMS :
549 sprintf(msgInfo->msgText, "%d new voice message", pTpdu->userData.header[i].udh.specialInd.waitMsgNum);
551 case MSG_MWI_FAX_SMS :
552 sprintf(msgInfo->msgText, "%d new fax message", pTpdu->userData.header[i].udh.specialInd.waitMsgNum);
554 case MSG_MWI_EMAIL_SMS :
555 sprintf(msgInfo->msgText, "%d new email message", pTpdu->userData.header[i].udh.specialInd.waitMsgNum);
558 sprintf(msgInfo->msgText, "%d new special message", pTpdu->userData.header[i].udh.specialInd.waitMsgNum);
561 msgInfo->dataSize = strlen(msgInfo->msgText);
564 } else if (pTpdu->userData.header[i].udhType == SMS_UDH_ALTERNATE_REPLY_ADDRESS) {
565 strncpy(msgInfo->addressList[0].addressVal, pTpdu->userData.header[i].udh.alternateAddress.address, MAX_ADDRESS_VAL_LEN);
569 /**length 0 - no user data - msg should be received */
570 if (pTpdu->userData.length <= 0) {
571 memset(msgInfo->msgText, 0x00, sizeof(msgInfo->msgText));
572 msgInfo->dataSize = 0;
574 switch(pTpdu->dcs.codingScheme)
576 case SMS_CHARSET_7BIT:
577 msgInfo->encodeType = MSG_ENCODE_GSM7BIT;
579 case SMS_CHARSET_8BIT:
580 msgInfo->encodeType = MSG_ENCODE_8BIT;
582 case SMS_CHARSET_UCS2:
583 msgInfo->encodeType = MSG_ENCODE_UCS2;
586 msgInfo->encodeType = MSG_ENCODE_8BIT;
591 } else if (pTpdu->userData.length > MAX_MSG_TEXT_LEN) {
592 sprintf(msgInfo->msgText, "[Broken Message]");
593 msgInfo->dataSize = strlen(msgInfo->msgData);
597 /** Convert Data values */
598 if (pTpdu->dcs.codingScheme == SMS_CHARSET_7BIT) {
599 MSG_LANG_INFO_S langInfo = {0,};
601 langInfo.bSingleShift = false;
602 langInfo.bLockingShift = false;
604 for (int i = 0; i < pTpdu->userData.headerCnt; i++) {
605 if (pTpdu->userData.header[i].udhType == SMS_UDH_SINGLE_SHIFT) {
606 langInfo.bSingleShift = true;
607 langInfo.singleLang = pTpdu->userData.header[i].udh.singleShift.langId;
608 } else if (pTpdu->userData.header[i].udhType == SMS_UDH_LOCKING_SHIFT) {
609 langInfo.bLockingShift = true;
610 langInfo.lockingLang = pTpdu->userData.header[i].udh.lockingShift.langId;
614 msgInfo->encodeType = MSG_ENCODE_GSM7BIT;
615 msgInfo->dataSize = textCvt.convertGSM7bitToUTF8((unsigned char*)msgInfo->msgText, MAX_MSG_TEXT_LEN, (unsigned char*)pTpdu->userData.data, pTpdu->userData.length, &langInfo);
616 } else if (pTpdu->dcs.codingScheme == SMS_CHARSET_8BIT) {
617 msgInfo->encodeType = MSG_ENCODE_8BIT;
618 memcpy(msgInfo->msgText, pTpdu->userData.data, sizeof(pTpdu->userData.data));
619 msgInfo->dataSize = pTpdu->userData.length;
620 } else if (pTpdu->dcs.codingScheme == SMS_CHARSET_UCS2) {
621 msgInfo->encodeType = MSG_ENCODE_UCS2;
622 msgInfo->dataSize = textCvt.convertUCS2ToUTF8((unsigned char*)msgInfo->msgText, MAX_MSG_TEXT_LEN, (unsigned char*)pTpdu->userData.data, pTpdu->userData.length);
623 } else if (pTpdu->dcs.codingScheme == SMS_CHARSET_EUCKR) {
624 msgInfo->encodeType = MSG_ENCODE_8BIT;
625 msgInfo->dataSize = textCvt.convertEUCKRToUTF8((unsigned char*)msgInfo->msgText, MAX_MSG_TEXT_LEN, (unsigned char*)pTpdu->userData.data, pTpdu->userData.length);
633 void SmsPluginEventHandler::convertStatusRepTpduToMsginfo(const SMS_STATUS_REPORT_S *pTpdu, MSG_MESSAGE_INFO_S *msgInfo)
635 /** Convert Type values */
636 msgInfo->msgType.mainType = MSG_SMS_TYPE;
637 msgInfo->msgType.subType = MSG_STATUS_REPORT_SMS;
640 msgInfo->folderId = MSG_INBOX_ID;
642 /** set storage id */
643 msgInfo->storageId = MSG_STORAGE_PHONE;
645 switch(pTpdu->dcs.msgClass)
647 case SMS_MSG_CLASS_0:
648 msgInfo->msgType.classType = MSG_CLASS_0;
650 case SMS_MSG_CLASS_1:
651 msgInfo->msgType.classType = MSG_CLASS_1;
653 case SMS_MSG_CLASS_2:
654 msgInfo->msgType.classType = MSG_CLASS_2;
656 case SMS_MSG_CLASS_3:
657 msgInfo->msgType.classType = MSG_CLASS_3;
660 msgInfo->msgType.classType = MSG_CLASS_NONE;
664 MSG_DEBUG("delivery status : [%d]", pTpdu->status);
666 if (pTpdu->status == SMS_STATUS_RECEIVE_SUCCESS) {
667 msgInfo->networkStatus = MSG_NETWORK_DELIVER_SUCCESS;
669 msgInfo->networkStatus = MSG_NETWORK_DELIVER_FAIL;
672 msgInfo->bRead = false;
673 msgInfo->bProtected = false;
674 msgInfo->priority = MSG_MESSAGE_PRIORITY_NORMAL;
675 msgInfo->direction = MSG_DIRECTION_TYPE_MT;
676 msgInfo->bTextSms = true;
678 memset(msgInfo->subject, 0x00, MAX_SUBJECT_LEN+1);
680 time_t rawtime = time(NULL);
682 /*** Comment below lines to save local UTC time..... (it could be used later.)
684 if (pTpdu->timeStamp.format == SMS_TIME_ABSOLUTE) {
686 MSG_DEBUG("year : %d", pTpdu->timeStamp.time.absolute.year);
687 MSG_DEBUG("month : %d", pTpdu->timeStamp.time.absolute.month);
688 MSG_DEBUG("day : %d", pTpdu->timeStamp.time.absolute.day);
689 MSG_DEBUG("hour : %d", pTpdu->timeStamp.time.absolute.hour);
690 MSG_DEBUG("minute : %d", pTpdu->timeStamp.time.absolute.minute);
691 MSG_DEBUG("second : %d", pTpdu->timeStamp.time.absolute.second);
692 MSG_DEBUG("timezone : %d", pTpdu->timeStamp.time.absolute.timeZone);
694 char displayTime[32];
698 memset(&timeinfo, 0x00, sizeof(tm));
700 timeinfo.tm_year = (pTpdu->timeStamp.time.absolute.year + 100);
701 timeinfo.tm_mon = (pTpdu->timeStamp.time.absolute.month - 1);
702 timeinfo.tm_mday = pTpdu->timeStamp.time.absolute.day;
703 timeinfo.tm_hour = pTpdu->timeStamp.time.absolute.hour;
704 timeinfo.tm_min = pTpdu->timeStamp.time.absolute.minute;
705 timeinfo.tm_sec = pTpdu->timeStamp.time.absolute.second;
706 timeinfo.tm_isdst = 0;
708 rawtime = mktime(&timeinfo);
710 MSG_DEBUG("tzname[0] [%s]", tzname[0]);
711 MSG_DEBUG("tzname[1] [%s]", tzname[1]);
712 MSG_DEBUG("timezone [%d]", timezone);
713 MSG_DEBUG("daylight [%d]", daylight);
715 memset(displayTime, 0x00, sizeof(displayTime));
716 strftime(displayTime, 32, "%Y-%02m-%02d %T %z", &timeinfo);
717 MSG_DEBUG("displayTime [%s]", displayTime);
719 rawtime -= (pTpdu->timeStamp.time.absolute.timeZone * (3600/4));
721 timeTM = localtime(&rawtime);
722 memset(displayTime, 0x00, sizeof(displayTime));
723 strftime(displayTime, 32, "%Y-%02m-%02d %T %z", timeTM);
724 MSG_DEBUG("displayTime [%s]", displayTime);
728 timeTM = localtime(&rawtime);
729 memset(displayTime, 0x00, sizeof(displayTime));
730 strftime(displayTime, 32, "%Y-%02m-%02d %T %z", timeTM);
731 MSG_DEBUG("displayTime [%s]", displayTime);
736 msgInfo->displayTime = rawtime;
738 /** Convert Address values */
739 msgInfo->nAddressCnt = 1;
740 msgInfo->addressList[0].addressType = MSG_ADDRESS_TYPE_PLMN;
741 strncpy(msgInfo->addressList[0].addressVal, pTpdu->recipAddress.address, MAX_ADDRESS_VAL_LEN);
743 msgInfo->msgPort.valid = false;
744 msgInfo->msgPort.dstPort = 0;
745 msgInfo->msgPort.srcPort = 0;
747 for (int i = 0; i < pTpdu->userData.headerCnt; i++) {
748 /** Convert UDH values - Port Number */
749 if (pTpdu->userData.header[i].udhType == SMS_UDH_APP_PORT_8BIT) {
750 msgInfo->msgPort.valid = true;
751 msgInfo->msgPort.dstPort = pTpdu->userData.header[i].udh.appPort8bit.destPort;
752 msgInfo->msgPort.srcPort = pTpdu->userData.header[i].udh.appPort8bit.originPort;
753 } else if (pTpdu->userData.header[i].udhType == SMS_UDH_APP_PORT_16BIT) {
754 msgInfo->msgPort.valid = true;
755 msgInfo->msgPort.dstPort = pTpdu->userData.header[i].udh.appPort16bit.destPort;
756 msgInfo->msgPort.srcPort = pTpdu->userData.header[i].udh.appPort16bit.originPort;
760 memset(msgInfo->msgText, 0x00, sizeof(msgInfo->msgText));
761 msgInfo->dataSize = 0;
763 if (pTpdu->status <= SMS_STATUS_SMSC_SPECIFIC_LAST) {
764 strncpy(msgInfo->msgText, "Message delivered.", MAX_MSG_TEXT_LEN);
765 msgInfo->dataSize = strlen(msgInfo->msgText);
766 } else if (pTpdu->status == SMS_STATUS_TEMP_SERVICE_REJECTED) {
767 strncpy(msgInfo->msgText, "Message delivery rejected.", MAX_MSG_TEXT_LEN);
768 msgInfo->dataSize = strlen(msgInfo->msgText);
769 } else if (pTpdu->status == SMS_STATUS_PERM_MSG_VAL_PERIOD_EXPIRED) {
770 strncpy(msgInfo->msgText, "Message delivery expired.", MAX_MSG_TEXT_LEN);
771 msgInfo->dataSize = strlen(msgInfo->msgText);
773 strncpy(msgInfo->msgText, "Message delivery failed.", MAX_MSG_TEXT_LEN);
774 msgInfo->dataSize = strlen(msgInfo->msgText);
779 MSG_SUB_TYPE_T SmsPluginEventHandler::convertMsgSubType(SMS_PID_T pid)
784 return MSG_TYPE0_SMS;
785 case SMS_PID_REPLACE_TYPE1 :
786 return MSG_REPLACE_TYPE1_SMS;
787 case SMS_PID_REPLACE_TYPE2 :
788 return MSG_REPLACE_TYPE2_SMS;
789 case SMS_PID_REPLACE_TYPE3 :
790 return MSG_REPLACE_TYPE3_SMS;
791 case SMS_PID_REPLACE_TYPE4 :
792 return MSG_REPLACE_TYPE4_SMS;
793 case SMS_PID_REPLACE_TYPE5 :
794 return MSG_REPLACE_TYPE5_SMS;
795 case SMS_PID_REPLACE_TYPE6 :
796 return MSG_REPLACE_TYPE6_SMS;
797 case SMS_PID_REPLACE_TYPE7 :
798 return MSG_REPLACE_TYPE7_SMS;
799 case SMS_PID_RETURN_CALL :
800 return MSG_MWI_OTHER_SMS;
802 return MSG_NORMAL_SMS;
808 void SmsPluginEventHandler::SetSentInfo(SMS_SENT_INFO_S *pSentInfo)
810 memset(&sentInfo, 0x00, sizeof(SMS_SENT_INFO_S));
811 memcpy(&sentInfo, pSentInfo, sizeof(SMS_SENT_INFO_S));
813 MSG_DEBUG("sentInfo.reqId : %d", sentInfo.reqInfo.reqId);
814 MSG_DEBUG("sentInfo.bLast : %d", sentInfo.bLast);
818 void SmsPluginEventHandler::setDeviceStatus()
827 bool SmsPluginEventHandler::getDeviceStatus()
833 ret = cv.timedwait(mx.pMutex(), 16);
835 if (ret == ETIMEDOUT) {
836 MSG_DEBUG("WARNING: DEVICE STATUS TIME-OUT");