2 * Copyright 2012 Samsung Electronics Co., Ltd
4 * Licensed under the Flora License, Version 1.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.tizenopensource.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"
32 /*==================================================================================================
33 IMPLEMENTATION OF SmsPluginEventHandler - Member Functions
34 ==================================================================================================*/
35 SmsPluginEventHandler* SmsPluginEventHandler::pInstance = NULL;
38 SmsPluginEventHandler::SmsPluginEventHandler()
40 /** Initialize global parameters */
41 memset(&listener, 0x00, sizeof(MSG_PLUGIN_LISTENER_S));
48 SmsPluginEventHandler::~SmsPluginEventHandler()
54 SmsPluginEventHandler* SmsPluginEventHandler::instance()
57 pInstance = new SmsPluginEventHandler();
63 void SmsPluginEventHandler::registerListener(MSG_PLUGIN_LISTENER_S *pListener)
65 listener = *pListener;
69 void SmsPluginEventHandler::handleSentStatus(msg_network_status_t NetStatus)
71 MSG_DEBUG("NetStatus[%d]", NetStatus);
73 SmsPluginTransport::instance()->setNetStatus(NetStatus);
75 if (sentInfo.bLast == true || NetStatus != MSG_NETWORK_SEND_SUCCESS) {
76 /** Update Msg Status */
77 if (sentInfo.reqInfo.msgInfo.msgPort.valid == false){
78 SmsPluginStorage::instance()->updateSentMsg(&(sentInfo.reqInfo.msgInfo), NetStatus);
79 sentInfo.reqInfo.msgInfo.networkStatus = NetStatus;
80 callbackStorageChange(MSG_STORAGE_CHANGE_UPDATE, &(sentInfo.reqInfo.msgInfo));
83 MSG_DEBUG("sentInfo.reqInfo.sendOptInfo.bSetting [%d]", sentInfo.reqInfo.sendOptInfo.bSetting);
84 MSG_DEBUG("sentInfo.reqInfo.sendOptInfo.bKeepCopy [%d]", sentInfo.reqInfo.sendOptInfo.bKeepCopy);
85 /** Check sending options */
86 if (sentInfo.reqInfo.sendOptInfo.bSetting && !sentInfo.reqInfo.sendOptInfo.bKeepCopy && NetStatus == MSG_NETWORK_SEND_SUCCESS) {
87 SmsPluginStorage::instance()->deleteSmsMessage(sentInfo.reqInfo.msgInfo.msgId);
88 callbackStorageChange(MSG_STORAGE_CHANGE_DELETE, &(sentInfo.reqInfo.msgInfo));
91 /** Callback to MSG FW */
92 MSG_SENT_STATUS_S msgStatus;
94 msgStatus.reqId = sentInfo.reqInfo.reqId;
95 msgStatus.status = NetStatus;
97 MSG_DEBUG("sentStatus.reqId : %d", msgStatus.reqId);
98 MSG_DEBUG("sentStatus.status : %d", msgStatus.status);
100 listener.pfSentStatusCb(&msgStatus);
105 void SmsPluginEventHandler::handleMsgIncoming(SMS_TPDU_S *pTpdu)
107 /** Make MSG_MESSAGE_INFO_S */
108 MSG_MESSAGE_INFO_S msgInfo;
110 /** initialize msgInfo */
111 memset(&msgInfo, 0x00, sizeof(MSG_MESSAGE_INFO_S));
113 /** check unsupported message */
114 if (pTpdu->tpduType == SMS_TPDU_DELIVER) {
115 if (pTpdu->data.deliver.dcs.codingScheme == SMS_CHARSET_8BIT && pTpdu->data.deliver.pid == 0x11) {
116 MSG_DEBUG("Unsupported message!!");
117 SmsPluginTransport::instance()->sendDeliverReport(MSG_SUCCESS);
122 /** convert to msgInfo */
123 convertTpduToMsginfo(pTpdu, &msgInfo);
125 /** Short Message Type 0 - Just Send Deliver Report */
126 if (msgInfo.msgType.subType == MSG_TYPE0_SMS) {
127 SmsPluginTransport::instance()->sendDeliverReport(MSG_SUCCESS);
131 /** Print MSG_MESSAGE_INFO_S */
132 MSG_DEBUG("############# Convert tpdu values to Message Info values ####################");
133 MSG_DEBUG("msgInfo.nAddressCnt : %d", msgInfo.nAddressCnt);
134 MSG_DEBUG("msgInfo.addressList[0].addressType : %d", msgInfo.addressList[0].addressType);
135 MSG_DEBUG("msgInfo.addressList[0].addressVal : %s", msgInfo.addressList[0].addressVal);
136 MSG_DEBUG("msgInfo.priority : %d", msgInfo.priority);
137 MSG_DEBUG("msgInfo.bProtected : %d", msgInfo.bProtected);
138 MSG_DEBUG("msgInfo.bRead : %d", msgInfo.bRead);
139 MSG_DEBUG("msgInfo.bTextSms : %d", msgInfo.bTextSms);
140 MSG_DEBUG("msgInfo.direction : %d", msgInfo.direction);
141 MSG_DEBUG("msgInfo.msgType.mainType : %d", msgInfo.msgType.mainType);
142 MSG_DEBUG("msgInfo.msgType.subType : %d", msgInfo.msgType.subType);
143 MSG_DEBUG("msgInfo.msgType.classType : %d", msgInfo.msgType.classType);
144 MSG_DEBUG("msgInfo.displayTime : %s", ctime(&msgInfo.displayTime));
145 MSG_DEBUG("msgInfo.msgPort.valid : %d", msgInfo.msgPort.valid);
146 MSG_DEBUG("msgInfo.encodeType : %d", msgInfo.encodeType);
147 MSG_DEBUG("msgInfo.dataSize : %d", msgInfo.dataSize);
149 if (msgInfo.bTextSms == true) {
150 MSG_DEBUG("msgInfo.msgText : %s", msgInfo.msgText);
152 MSG_DEBUG("msgInfo.msgData : %s", msgInfo.msgData);
155 MSG_DEBUG("###############################################################");
157 msg_error_t err = MSG_SUCCESS;
159 if (msgInfo.msgType.subType == MSG_STATUS_REPORT_SMS) {
160 /** Status Report Message */
161 err = listener.pfMsgIncomingCb(&msgInfo);
163 /** Handling of Fail Case ?? */
164 SmsPluginTransport::instance()->sendDeliverReport(MSG_SUCCESS);
165 } else { /** SMS Deliver */
167 if (msgInfo.msgType.classType == MSG_CLASS_2) {
168 if (msgInfo.bTextSms == false) { /** Concat Msg cannot be saved in SIM */
169 msgInfo.msgType.classType = MSG_CLASS_NONE;
170 msgInfo.storageId = MSG_STORAGE_PHONE;
174 if (msgInfo.msgPort.valid == false) {
175 err = SmsPluginStorage::instance()->addMessage(&msgInfo);
178 /** Callback to MSG FW */
179 if (msgInfo.msgType.classType != MSG_CLASS_2) {
180 if (err == MSG_SUCCESS) {
181 MSG_DEBUG("callback to msg fw");
182 err = listener.pfMsgIncomingCb(&msgInfo);
184 if (msgInfo.msgType.classType == MSG_CLASS_0) {
185 MSG_DEBUG("callback for class0 message to msg fw");
186 if (listener.pfMsgIncomingCb(&msgInfo) != MSG_SUCCESS)
187 MSG_DEBUG("listener.pfMsgIncomingCb is failed!");
191 /** Send Deliver Report */
192 if (msgInfo.msgType.classType == MSG_CLASS_0)
193 SmsPluginTransport::instance()->sendClass0DeliverReport(err);
195 SmsPluginTransport::instance()->sendDeliverReport(err);
198 // Tizen Validation System
200 msisdn = MsgSettingGetString(MSG_SIM_MSISDN);
202 MSG_SMS_VLD_INFO("%d, SMS Receive, %s->%s, %s", msgInfo.msgId, \
203 msgInfo.addressList[0].addressVal, \
204 (msisdn == NULL)?"ME":msisdn, \
205 (err == MSG_SUCCESS)?"Success":"Fail");
207 MSG_SMS_VLD_TXT("%d, [%s]", msgInfo.msgId, msgInfo.msgText);
211 void SmsPluginEventHandler::handlePushMsgIncoming(char* pPushHeader, char* pPushBody, int pushBodyLen, char *application_id)
213 MSG_PUSH_MESSAGE_DATA_S pushData;
215 memset(&pushData, 0x00, sizeof(MSG_PUSH_MESSAGE_DATA_S));
218 memcpy(&pushData.pushHeader, pPushHeader, strlen(pPushHeader));
220 pushData.pushBodyLen = pushBodyLen;
221 memcpy(pushData.pushBody, pPushBody, pushBodyLen);
223 memcpy(pushData.pushAppId, application_id, MAX_WAPPUSH_ID_LEN);
225 /** Callback to MSG FW */
226 listener.pfPushMsgIncomingCb(&pushData);
230 void SmsPluginEventHandler::handleSyncMLMsgIncoming(msg_syncml_message_type_t msgType, char* pPushBody, int PushBodyLen, char* pWspHeader, int WspHeaderLen)
232 MSG_SYNCML_MESSAGE_DATA_S syncMLData;
234 memset(&syncMLData, 0x00, sizeof(MSG_SYNCML_MESSAGE_DATA_S));
236 /** set syncML data */
237 syncMLData.syncmlType = msgType;
239 syncMLData.pushBodyLen = PushBodyLen;
240 memcpy(syncMLData.pushBody, pPushBody, PushBodyLen);
242 syncMLData.wspHeaderLen= WspHeaderLen;
243 memcpy(syncMLData.wspHeader, pWspHeader, WspHeaderLen);
245 /** Callback to MSG FW */
246 listener.pfSyncMLMsgIncomingCb(&syncMLData);
250 void SmsPluginEventHandler::handleLBSMsgIncoming(char* pPushHeader, char* pPushBody, int pushBodyLen)
252 MSG_LBS_MESSAGE_DATA_S lBSData;
254 memset(&lBSData, 0x00, sizeof(MSG_LBS_MESSAGE_DATA_S));
257 memcpy(&lBSData.pushHeader, pPushHeader, strlen(pPushHeader));
259 lBSData.pushBodyLen = pushBodyLen;
260 memcpy(lBSData.pushBody, pPushBody, pushBodyLen);
262 /** Callback to MSG FW */
263 listener.pfLBSMsgIncomingCb(&lBSData);
267 msg_error_t SmsPluginEventHandler::callbackMsgIncoming(MSG_MESSAGE_INFO_S *pMsgInfo)
271 msg_error_t err = MSG_SUCCESS;
273 /** Callback to MSG FW */
274 err = listener.pfMsgIncomingCb(pMsgInfo);
281 msg_error_t SmsPluginEventHandler::callbackCBMsgIncoming(MSG_CB_MSG_S *pCbMsg)
285 msg_error_t err = MSG_SUCCESS;
287 /** Callback to MSG FW */
288 err = listener.pfCBMsgIncomingCb(pCbMsg);
296 msg_error_t SmsPluginEventHandler::callbackInitSimBySat()
298 /** Callback to MSG FW */
299 return listener.pfInitSimBySatCb();
303 msg_error_t SmsPluginEventHandler::callbackStorageChange(msg_storage_change_type_t storageChangeType, MSG_MESSAGE_INFO_S *pMsgInfo)
305 /** Callback to MSG FW */
306 listener.pfStorageChangeCb(storageChangeType, pMsgInfo);
312 void SmsPluginEventHandler::convertTpduToMsginfo(SMS_TPDU_S *pTpdu, MSG_MESSAGE_INFO_S *msgInfo)
314 memset(msgInfo, 0x00, sizeof(MSG_MESSAGE_INFO_S));
316 switch(pTpdu->tpduType)
318 case SMS_TPDU_SUBMIT :
319 convertSubmitTpduToMsginfo(&pTpdu->data.submit, msgInfo);
321 case SMS_TPDU_DELIVER :
322 convertDeliverTpduToMsginfo(&pTpdu->data.deliver, msgInfo);
324 case SMS_TPDU_STATUS_REP :
325 convertStatusRepTpduToMsginfo(&pTpdu->data.statusRep, msgInfo);
331 void SmsPluginEventHandler::convertSubmitTpduToMsginfo(const SMS_SUBMIT_S *pTpdu, MSG_MESSAGE_INFO_S *msgInfo)
333 int addressListCnt = 0;
335 /** Convert Type values */
336 msgInfo->msgType.mainType = MSG_SMS_TYPE;
337 msgInfo->msgType.subType = convertMsgSubType(pTpdu->pid);
339 /** set folder id (temporary) */
340 msgInfo->folderId = MSG_OUTBOX_ID;
342 switch(pTpdu->dcs.msgClass)
344 case SMS_MSG_CLASS_0:
345 msgInfo->msgType.classType = MSG_CLASS_0;
347 case SMS_MSG_CLASS_1:
348 msgInfo->msgType.classType = MSG_CLASS_1;
350 case SMS_MSG_CLASS_2:
351 msgInfo->msgType.classType = MSG_CLASS_2;
353 case SMS_MSG_CLASS_3:
354 msgInfo->msgType.classType = MSG_CLASS_3;
357 msgInfo->msgType.classType = MSG_CLASS_NONE;
360 msgInfo->networkStatus = MSG_NETWORK_SEND_SUCCESS;
361 msgInfo->bRead = false;
362 msgInfo->bProtected = false;
363 msgInfo->priority = MSG_MESSAGE_PRIORITY_NORMAL;
364 msgInfo->direction = MSG_DIRECTION_TYPE_MT;
365 msgInfo->bTextSms = true;
367 memset(msgInfo->subject, 0x00, MAX_SUBJECT_LEN+1);
369 /** What kind of time has to be saved?? (temporary store time) */
374 msgInfo->displayTime = curTime;
376 /** Convert Address values */
377 msgInfo->nAddressCnt = 1;
378 msgInfo->addressList[addressListCnt].addressType = MSG_ADDRESS_TYPE_PLMN;
379 strncpy(msgInfo->addressList[addressListCnt].addressVal, pTpdu->destAddress.address, MAX_ADDRESS_VAL_LEN);
381 /**exception operation for none userdata */
382 if (pTpdu->userData.length == 0) {
383 sprintf(msgInfo->msgText, "[Broken Message]");
384 msgInfo->dataSize = strlen(msgInfo->msgText);
388 /** Convert Data values */
389 if (pTpdu->dcs.codingScheme == SMS_CHARSET_7BIT) {
390 MSG_LANG_INFO_S langInfo = {0,};
392 langInfo.bSingleShift = false;
393 langInfo.bLockingShift = false;
395 msgInfo->dataSize = textCvt.convertGSM7bitToUTF8((unsigned char*)msgInfo->msgText, MAX_MSG_TEXT_LEN, (unsigned char*)pTpdu->userData.data, pTpdu->userData.length, &langInfo);
396 } else if (pTpdu->dcs.codingScheme == SMS_CHARSET_UCS2) {
397 msgInfo->dataSize = textCvt.convertUCS2ToUTF8((unsigned char*)msgInfo->msgText, MAX_MSG_TEXT_LEN, (unsigned char*)pTpdu->userData.data, pTpdu->userData.length);
402 void SmsPluginEventHandler::convertDeliverTpduToMsginfo(const SMS_DELIVER_S *pTpdu, MSG_MESSAGE_INFO_S *msgInfo)
406 /** Convert Type values */
407 msgInfo->msgType.mainType = MSG_SMS_TYPE;
408 msgInfo->msgType.subType = convertMsgSubType(pTpdu->pid);
410 /** set folder id (temporary) */
411 msgInfo->folderId = MSG_INBOX_ID;
413 msgInfo->storageId = MSG_STORAGE_PHONE;
415 switch(pTpdu->dcs.msgClass)
417 case SMS_MSG_CLASS_0:
418 msgInfo->msgType.classType = MSG_CLASS_0;
420 case SMS_MSG_CLASS_1:
421 msgInfo->msgType.classType = MSG_CLASS_1;
423 case SMS_MSG_CLASS_2:
424 msgInfo->msgType.classType = MSG_CLASS_2;
425 msgInfo->storageId = MSG_STORAGE_SIM;
427 case SMS_MSG_CLASS_3:
428 msgInfo->msgType.classType = MSG_CLASS_3;
431 msgInfo->msgType.classType = MSG_CLASS_NONE;
435 if (pTpdu->dcs.bMWI) {
436 msgInfo->msgType.subType = (pTpdu->dcs.indType + MSG_MWI_VOICE_SMS);
439 msgInfo->networkStatus = MSG_NETWORK_RECEIVED;
440 msgInfo->bRead = false;
441 msgInfo->bProtected = false;
442 msgInfo->priority = MSG_MESSAGE_PRIORITY_NORMAL;
443 msgInfo->direction = MSG_DIRECTION_TYPE_MT;
444 msgInfo->bTextSms = true;
446 memset(msgInfo->subject, 0x00, MAX_SUBJECT_LEN+1);
448 time_t rawtime = time(NULL);
450 /*** Comment below lines to save local UTC time..... (it could be used later.)
452 if (pTpdu->timeStamp.format == SMS_TIME_ABSOLUTE) {
454 MSG_DEBUG("year : %d", pTpdu->timeStamp.time.absolute.year);
455 MSG_DEBUG("month : %d", pTpdu->timeStamp.time.absolute.month);
456 MSG_DEBUG("day : %d", pTpdu->timeStamp.time.absolute.day);
457 MSG_DEBUG("hour : %d", pTpdu->timeStamp.time.absolute.hour);
458 MSG_DEBUG("minute : %d", pTpdu->timeStamp.time.absolute.minute);
459 MSG_DEBUG("second : %d", pTpdu->timeStamp.time.absolute.second);
460 MSG_DEBUG("timezone : %d", pTpdu->timeStamp.time.absolute.timeZone);
462 char displayTime[32];
466 memset(&timeinfo, 0x00, sizeof(tm));
468 timeinfo.tm_year = (pTpdu->timeStamp.time.absolute.year + 100);
469 timeinfo.tm_mon = (pTpdu->timeStamp.time.absolute.month - 1);
470 timeinfo.tm_mday = pTpdu->timeStamp.time.absolute.day;
471 timeinfo.tm_hour = pTpdu->timeStamp.time.absolute.hour;
472 timeinfo.tm_min = pTpdu->timeStamp.time.absolute.minute;
473 timeinfo.tm_sec = pTpdu->timeStamp.time.absolute.second;
474 timeinfo.tm_isdst = 0;
476 rawtime = mktime(&timeinfo);
478 MSG_DEBUG("tzname[0] [%s]", tzname[0]);
479 MSG_DEBUG("tzname[1] [%s]", tzname[1]);
480 MSG_DEBUG("timezone [%d]", timezone);
481 MSG_DEBUG("daylight [%d]", daylight);
483 memset(displayTime, 0x00, sizeof(displayTime));
484 strftime(displayTime, 32, "%Y-%02m-%02d %T %z", &timeinfo);
485 MSG_DEBUG("displayTime [%s]", displayTime);
487 rawtime -= (pTpdu->timeStamp.time.absolute.timeZone * (3600/4));
489 timeTM = localtime(&rawtime);
490 memset(displayTime, 0x00, sizeof(displayTime));
491 strftime(displayTime, 32, "%Y-%02m-%02d %T %z", timeTM);
492 MSG_DEBUG("displayTime [%s]", displayTime);
496 timeTM = localtime(&rawtime);
497 memset(displayTime, 0x00, sizeof(displayTime));
498 strftime(displayTime, 32, "%Y-%02m-%02d %T %z", timeTM);
499 MSG_DEBUG("displayTime [%s]", displayTime);
504 msgInfo->displayTime = rawtime;
506 /** Convert Address values */
507 msgInfo->nAddressCnt = 1;
508 msgInfo->addressList[0].addressType = MSG_ADDRESS_TYPE_PLMN;
509 strncpy(msgInfo->addressList[0].addressVal, pTpdu->originAddress.address, MAX_ADDRESS_VAL_LEN);
511 msgInfo->msgPort.valid = false;
512 msgInfo->msgPort.dstPort = 0;
513 msgInfo->msgPort.srcPort = 0;
515 for (int i = 0; i < pTpdu->userData.headerCnt; i++) {
516 /** Convert UDH values - Port Number */
517 if (pTpdu->userData.header[i].udhType == SMS_UDH_APP_PORT_8BIT) {
518 msgInfo->msgPort.valid = true;
519 msgInfo->msgPort.dstPort = pTpdu->userData.header[i].udh.appPort8bit.destPort;
520 msgInfo->msgPort.srcPort = pTpdu->userData.header[i].udh.appPort8bit.originPort;
521 } else if (pTpdu->userData.header[i].udhType == SMS_UDH_APP_PORT_16BIT) {
522 msgInfo->msgPort.valid = true;
523 msgInfo->msgPort.dstPort = pTpdu->userData.header[i].udh.appPort16bit.destPort;
524 msgInfo->msgPort.srcPort = pTpdu->userData.header[i].udh.appPort16bit.originPort;
525 } else if (pTpdu->userData.header[i].udhType == SMS_UDH_SPECIAL_SMS) {
526 msgInfo->msgType.subType = (pTpdu->userData.header[i].udh.specialInd.msgInd+MSG_MWI_VOICE_SMS);
527 msgInfo->bStore = pTpdu->userData.header[i].udh.specialInd.bStore;
529 MSG_DEBUG("Message waiting number : [%d]", pTpdu->userData.header[i].udh.specialInd.waitMsgNum);
530 SmsPluginSetting::instance()->setMwiInfo(msgInfo->msgType.subType, pTpdu->userData.header[i].udh.specialInd.waitMsgNum);
532 if (pTpdu->userData.length == 0) {
533 switch (msgInfo->msgType.subType) {
534 case MSG_MWI_VOICE_SMS :
535 sprintf(msgInfo->msgText, "%d new voice message", pTpdu->userData.header[i].udh.specialInd.waitMsgNum);
537 case MSG_MWI_FAX_SMS :
538 sprintf(msgInfo->msgText, "%d new fax message", pTpdu->userData.header[i].udh.specialInd.waitMsgNum);
540 case MSG_MWI_EMAIL_SMS :
541 sprintf(msgInfo->msgText, "%d new email message", pTpdu->userData.header[i].udh.specialInd.waitMsgNum);
544 sprintf(msgInfo->msgText, "%d new special message", pTpdu->userData.header[i].udh.specialInd.waitMsgNum);
547 msgInfo->dataSize = strlen(msgInfo->msgText);
550 } else if (pTpdu->userData.header[i].udhType == SMS_UDH_ALTERNATE_REPLY_ADDRESS) {
551 strncpy(msgInfo->addressList[0].addressVal, pTpdu->userData.header[i].udh.alternateAddress.address, MAX_ADDRESS_VAL_LEN);
555 /**length 0 - no user data - msg should be received */
556 if (pTpdu->userData.length <= 0) {
557 memset(msgInfo->msgText, 0x00, sizeof(msgInfo->msgText));
558 msgInfo->dataSize = 0;
560 switch(pTpdu->dcs.codingScheme)
562 case SMS_CHARSET_7BIT:
563 msgInfo->encodeType = MSG_ENCODE_GSM7BIT;
565 case SMS_CHARSET_8BIT:
566 msgInfo->encodeType = MSG_ENCODE_8BIT;
568 case SMS_CHARSET_UCS2:
569 msgInfo->encodeType = MSG_ENCODE_UCS2;
572 msgInfo->encodeType = MSG_ENCODE_8BIT;
577 } else if (pTpdu->userData.length > MAX_MSG_TEXT_LEN) {
578 sprintf(msgInfo->msgText, "[Broken Message]");
579 msgInfo->dataSize = strlen(msgInfo->msgData);
583 /** Convert Data values */
584 if (pTpdu->dcs.codingScheme == SMS_CHARSET_7BIT) {
585 MSG_LANG_INFO_S langInfo = {0,};
587 langInfo.bSingleShift = false;
588 langInfo.bLockingShift = false;
590 for (int i = 0; i < pTpdu->userData.headerCnt; i++) {
591 if (pTpdu->userData.header[i].udhType == SMS_UDH_SINGLE_SHIFT) {
592 langInfo.bSingleShift = true;
593 langInfo.singleLang = pTpdu->userData.header[i].udh.singleShift.langId;
594 } else if (pTpdu->userData.header[i].udhType == SMS_UDH_LOCKING_SHIFT) {
595 langInfo.bLockingShift = true;
596 langInfo.lockingLang = pTpdu->userData.header[i].udh.lockingShift.langId;
600 msgInfo->encodeType = MSG_ENCODE_GSM7BIT;
601 msgInfo->dataSize = textCvt.convertGSM7bitToUTF8((unsigned char*)msgInfo->msgText, MAX_MSG_TEXT_LEN, (unsigned char*)pTpdu->userData.data, pTpdu->userData.length, &langInfo);
602 } else if (pTpdu->dcs.codingScheme == SMS_CHARSET_8BIT) {
603 msgInfo->encodeType = MSG_ENCODE_8BIT;
604 memcpy(msgInfo->msgText, pTpdu->userData.data, sizeof(pTpdu->userData.data));
605 msgInfo->dataSize = pTpdu->userData.length;
606 } else if (pTpdu->dcs.codingScheme == SMS_CHARSET_UCS2) {
607 msgInfo->encodeType = MSG_ENCODE_UCS2;
608 msgInfo->dataSize = textCvt.convertUCS2ToUTF8((unsigned char*)msgInfo->msgText, MAX_MSG_TEXT_LEN, (unsigned char*)pTpdu->userData.data, pTpdu->userData.length);
609 } else if (pTpdu->dcs.codingScheme == SMS_CHARSET_EUCKR) {
610 msgInfo->encodeType = MSG_ENCODE_8BIT;
611 msgInfo->dataSize = textCvt.convertEUCKRToUTF8((unsigned char*)msgInfo->msgText, MAX_MSG_TEXT_LEN, (unsigned char*)pTpdu->userData.data, pTpdu->userData.length);
619 void SmsPluginEventHandler::convertStatusRepTpduToMsginfo(const SMS_STATUS_REPORT_S *pTpdu, MSG_MESSAGE_INFO_S *msgInfo)
621 /** Convert Type values */
622 msgInfo->msgType.mainType = MSG_SMS_TYPE;
623 msgInfo->msgType.subType = MSG_STATUS_REPORT_SMS;
626 msgInfo->folderId = MSG_INBOX_ID;
628 /** set storage id */
629 msgInfo->storageId = MSG_STORAGE_PHONE;
631 switch(pTpdu->dcs.msgClass)
633 case SMS_MSG_CLASS_0:
634 msgInfo->msgType.classType = MSG_CLASS_0;
636 case SMS_MSG_CLASS_1:
637 msgInfo->msgType.classType = MSG_CLASS_1;
639 case SMS_MSG_CLASS_2:
640 msgInfo->msgType.classType = MSG_CLASS_2;
642 case SMS_MSG_CLASS_3:
643 msgInfo->msgType.classType = MSG_CLASS_3;
646 msgInfo->msgType.classType = MSG_CLASS_NONE;
650 MSG_DEBUG("delivery status : [%d]", pTpdu->status);
652 if (pTpdu->status == SMS_STATUS_RECEIVE_SUCCESS) {
653 msgInfo->networkStatus = MSG_NETWORK_DELIVER_SUCCESS;
655 msgInfo->networkStatus = MSG_NETWORK_DELIVER_FAIL;
658 msgInfo->bRead = false;
659 msgInfo->bProtected = false;
660 msgInfo->priority = MSG_MESSAGE_PRIORITY_NORMAL;
661 msgInfo->direction = MSG_DIRECTION_TYPE_MT;
662 msgInfo->bTextSms = true;
664 memset(msgInfo->subject, 0x00, MAX_SUBJECT_LEN+1);
666 time_t rawtime = time(NULL);
668 /*** Comment below lines to save local UTC time..... (it could be used later.)
670 if (pTpdu->timeStamp.format == SMS_TIME_ABSOLUTE) {
672 MSG_DEBUG("year : %d", pTpdu->timeStamp.time.absolute.year);
673 MSG_DEBUG("month : %d", pTpdu->timeStamp.time.absolute.month);
674 MSG_DEBUG("day : %d", pTpdu->timeStamp.time.absolute.day);
675 MSG_DEBUG("hour : %d", pTpdu->timeStamp.time.absolute.hour);
676 MSG_DEBUG("minute : %d", pTpdu->timeStamp.time.absolute.minute);
677 MSG_DEBUG("second : %d", pTpdu->timeStamp.time.absolute.second);
678 MSG_DEBUG("timezone : %d", pTpdu->timeStamp.time.absolute.timeZone);
680 char displayTime[32];
684 memset(&timeinfo, 0x00, sizeof(tm));
686 timeinfo.tm_year = (pTpdu->timeStamp.time.absolute.year + 100);
687 timeinfo.tm_mon = (pTpdu->timeStamp.time.absolute.month - 1);
688 timeinfo.tm_mday = pTpdu->timeStamp.time.absolute.day;
689 timeinfo.tm_hour = pTpdu->timeStamp.time.absolute.hour;
690 timeinfo.tm_min = pTpdu->timeStamp.time.absolute.minute;
691 timeinfo.tm_sec = pTpdu->timeStamp.time.absolute.second;
692 timeinfo.tm_isdst = 0;
694 rawtime = mktime(&timeinfo);
696 MSG_DEBUG("tzname[0] [%s]", tzname[0]);
697 MSG_DEBUG("tzname[1] [%s]", tzname[1]);
698 MSG_DEBUG("timezone [%d]", timezone);
699 MSG_DEBUG("daylight [%d]", daylight);
701 memset(displayTime, 0x00, sizeof(displayTime));
702 strftime(displayTime, 32, "%Y-%02m-%02d %T %z", &timeinfo);
703 MSG_DEBUG("displayTime [%s]", displayTime);
705 rawtime -= (pTpdu->timeStamp.time.absolute.timeZone * (3600/4));
707 timeTM = localtime(&rawtime);
708 memset(displayTime, 0x00, sizeof(displayTime));
709 strftime(displayTime, 32, "%Y-%02m-%02d %T %z", timeTM);
710 MSG_DEBUG("displayTime [%s]", displayTime);
714 timeTM = localtime(&rawtime);
715 memset(displayTime, 0x00, sizeof(displayTime));
716 strftime(displayTime, 32, "%Y-%02m-%02d %T %z", timeTM);
717 MSG_DEBUG("displayTime [%s]", displayTime);
722 msgInfo->displayTime = rawtime;
724 /** Convert Address values */
725 msgInfo->nAddressCnt = 1;
726 msgInfo->addressList[0].addressType = MSG_ADDRESS_TYPE_PLMN;
727 strncpy(msgInfo->addressList[0].addressVal, pTpdu->recipAddress.address, MAX_ADDRESS_VAL_LEN);
729 msgInfo->msgPort.valid = false;
730 msgInfo->msgPort.dstPort = 0;
731 msgInfo->msgPort.srcPort = 0;
733 for (int i = 0; i < pTpdu->userData.headerCnt; i++) {
734 /** Convert UDH values - Port Number */
735 if (pTpdu->userData.header[i].udhType == SMS_UDH_APP_PORT_8BIT) {
736 msgInfo->msgPort.valid = true;
737 msgInfo->msgPort.dstPort = pTpdu->userData.header[i].udh.appPort8bit.destPort;
738 msgInfo->msgPort.srcPort = pTpdu->userData.header[i].udh.appPort8bit.originPort;
739 } else if (pTpdu->userData.header[i].udhType == SMS_UDH_APP_PORT_16BIT) {
740 msgInfo->msgPort.valid = true;
741 msgInfo->msgPort.dstPort = pTpdu->userData.header[i].udh.appPort16bit.destPort;
742 msgInfo->msgPort.srcPort = pTpdu->userData.header[i].udh.appPort16bit.originPort;
746 memset(msgInfo->msgText, 0x00, sizeof(msgInfo->msgText));
747 msgInfo->dataSize = 0;
749 if (pTpdu->status <= SMS_STATUS_SMSC_SPECIFIC_LAST) {
750 strncpy(msgInfo->msgText, "Message delivered.", MAX_MSG_TEXT_LEN);
751 msgInfo->dataSize = strlen(msgInfo->msgText);
752 } else if (pTpdu->status == SMS_STATUS_TEMP_SERVICE_REJECTED) {
753 strncpy(msgInfo->msgText, "Message delivery rejected.", MAX_MSG_TEXT_LEN);
754 msgInfo->dataSize = strlen(msgInfo->msgText);
755 } else if (pTpdu->status == SMS_STATUS_PERM_MSG_VAL_PERIOD_EXPIRED) {
756 strncpy(msgInfo->msgText, "Message delivery expired.", MAX_MSG_TEXT_LEN);
757 msgInfo->dataSize = strlen(msgInfo->msgText);
759 strncpy(msgInfo->msgText, "Message delivery failed.", MAX_MSG_TEXT_LEN);
760 msgInfo->dataSize = strlen(msgInfo->msgText);
765 MSG_SUB_TYPE_T SmsPluginEventHandler::convertMsgSubType(SMS_PID_T pid)
770 return MSG_TYPE0_SMS;
771 case SMS_PID_REPLACE_TYPE1 :
772 return MSG_REPLACE_TYPE1_SMS;
773 case SMS_PID_REPLACE_TYPE2 :
774 return MSG_REPLACE_TYPE2_SMS;
775 case SMS_PID_REPLACE_TYPE3 :
776 return MSG_REPLACE_TYPE3_SMS;
777 case SMS_PID_REPLACE_TYPE4 :
778 return MSG_REPLACE_TYPE4_SMS;
779 case SMS_PID_REPLACE_TYPE5 :
780 return MSG_REPLACE_TYPE5_SMS;
781 case SMS_PID_REPLACE_TYPE6 :
782 return MSG_REPLACE_TYPE6_SMS;
783 case SMS_PID_REPLACE_TYPE7 :
784 return MSG_REPLACE_TYPE7_SMS;
785 case SMS_PID_RETURN_CALL :
786 return MSG_MWI_OTHER_SMS;
788 return MSG_NORMAL_SMS;
794 void SmsPluginEventHandler::SetSentInfo(SMS_SENT_INFO_S *pSentInfo)
796 memset(&sentInfo, 0x00, sizeof(SMS_SENT_INFO_S));
797 memcpy(&sentInfo, pSentInfo, sizeof(SMS_SENT_INFO_S));
799 MSG_DEBUG("sentInfo.reqId : %d", sentInfo.reqInfo.reqId);
800 MSG_DEBUG("sentInfo.bLast : %d", sentInfo.bLast);
804 void SmsPluginEventHandler::setDeviceStatus()
813 bool SmsPluginEventHandler::getDeviceStatus()
819 ret = cv.timedwait(mx.pMutex(), 16);
823 if (ret == ETIMEDOUT) {
824 MSG_DEBUG("WARNING: DEVICE STATUS TIME-OUT");