2 * Copyright 2012-2013 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://floralicense.org
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.
18 #include "MsgException.h"
19 #include "MsgCppTypes.h"
20 #include "MsgUtilFile.h"
21 #include "SmsPluginStorage.h"
22 #include "SmsPluginTransport.h"
23 #include "SmsPluginEventHandler.h"
24 #include "SmsPluginWapPushHandler.h"
25 #include "SmsPluginConcatHandler.h"
27 /*==================================================================================================
28 IMPLEMENTATION OF SmsPluginConcatHandler - Member Functions
29 ==================================================================================================*/
30 SmsPluginConcatHandler* SmsPluginConcatHandler::pInstance = NULL;
33 SmsPluginConcatHandler::SmsPluginConcatHandler()
39 SmsPluginConcatHandler::~SmsPluginConcatHandler()
45 SmsPluginConcatHandler* SmsPluginConcatHandler::instance()
48 pInstance = new SmsPluginConcatHandler();
54 bool SmsPluginConcatHandler::IsConcatMsg(SMS_USERDATA_S *pUserData)
58 MSG_DEBUG("headerCnt [%d]", pUserData->headerCnt);
60 for (int i = 0; i < pUserData->headerCnt; i++) {
61 /** Handler Concatenated Message */
62 if (pUserData->header[i].udhType == SMS_UDH_CONCAT_8BIT) {
64 } else if (pUserData->header[i].udhType == SMS_UDH_CONCAT_16BIT) {
75 void SmsPluginConcatHandler::handleConcatMsg(SMS_TPDU_S *pTpdu)
79 msg_error_t err = MSG_SUCCESS;
80 bool noneConcatTypeHeader = true;
82 if (pTpdu->tpduType != SMS_TPDU_DELIVER) {
83 MSG_DEBUG("The TPDU type is not deliver [%d]", pTpdu->tpduType);
87 SMS_CONCAT_MSG_S msg = {0};
89 for (int i = 0; i < pTpdu->data.deliver.userData.headerCnt; i++) {
90 if (pTpdu->data.deliver.userData.header[i].udhType == SMS_UDH_CONCAT_8BIT) {
91 msg.msgRef = (unsigned short)pTpdu->data.deliver.userData.header[i].udh.concat8bit.msgRef;
92 msg.totalSeg = pTpdu->data.deliver.userData.header[i].udh.concat8bit.totalSeg;
93 msg.seqNum = pTpdu->data.deliver.userData.header[i].udh.concat8bit.seqNum;
95 memcpy(&(msg.timeStamp.time.absolute), &(pTpdu->data.deliver.timeStamp.time.absolute), sizeof(SMS_TIME_ABS_S));
96 memcpy(&(msg.originAddress), &(pTpdu->data.deliver.originAddress), sizeof(SMS_ADDRESS_S));
97 memcpy(&(msg.dcs), &(pTpdu->data.deliver.dcs), sizeof(SMS_DCS_S));
100 if (msg.totalSeg > MAX_SEGMENT_NUM) {
101 MSG_DEBUG("Total Segment Count is over Maximum [%d]", msg.totalSeg);
105 /** check noneConcatTypeHeader */
106 noneConcatTypeHeader = false;
109 } else if (pTpdu->data.deliver.userData.header[i].udhType == SMS_UDH_CONCAT_16BIT) {
110 msg.msgRef = (unsigned short)pTpdu->data.deliver.userData.header[i].udh.concat16bit.msgRef;
111 msg.totalSeg = pTpdu->data.deliver.userData.header[i].udh.concat16bit.totalSeg;
112 msg.seqNum = pTpdu->data.deliver.userData.header[i].udh.concat16bit.seqNum;
114 memcpy(&(msg.timeStamp.time.absolute), &(pTpdu->data.deliver.timeStamp.time.absolute), sizeof(SMS_TIME_ABS_S));
115 memcpy(&(msg.originAddress), &(pTpdu->data.deliver.originAddress), sizeof(SMS_ADDRESS_S));
116 memcpy(&(msg.dcs), &(pTpdu->data.deliver.dcs), sizeof(SMS_DCS_S));
118 if (msg.totalSeg > MAX_SEGMENT_NUM) {
119 MSG_DEBUG("Total Segment Count is over Maximum [%d]", msg.totalSeg);
124 /** check noneConcatTypeHeader */
125 noneConcatTypeHeader = false;
131 unsigned char segCnt = checkConcatMsg(&msg, &(pTpdu->data.deliver.userData));
133 MSG_DEBUG("segCnt [%d]", segCnt);
134 MSG_DEBUG("msg.totalSeg [%d]", msg.totalSeg);
136 if ((segCnt == msg.totalSeg) || noneConcatTypeHeader) {
137 MSG_DEBUG("RECEIVED LAST CONCAT : %d", segCnt);
140 char* pUserData = NULL;
141 AutoPtr<char> dataBuf(&pUserData);
143 MSG_MESSAGE_INFO_S msgInfo = {0};
145 dataSize = makeConcatUserData(msg.msgRef, &pUserData);
148 if (SmsPluginWapPushHandler::instance()->IsWapPushMsg(&(pTpdu->data.deliver.userData)) == true) {
149 SmsPluginWapPushHandler::instance()->copyDeliverData(&(pTpdu->data.deliver));
150 SmsPluginWapPushHandler::instance()->handleWapPushMsg(pUserData, dataSize);
152 convertConcatToMsginfo(&(pTpdu->data.deliver), pUserData, dataSize, &msgInfo);
154 if (msgInfo.msgPort.valid == false) {
155 /** Add Concat Msg into DB */
156 err = SmsPluginStorage::instance()->addMessage(&msgInfo);
159 if (err == MSG_SUCCESS) {
161 err = SmsPluginEventHandler::instance()->callbackMsgIncoming(&msgInfo);
163 if (err != MSG_SUCCESS) {
164 MSG_DEBUG("callbackMsgIncoming() Error !! [%d]", err);
167 MSG_DEBUG("addMessage() Error !! [%d]", err);
172 removeFromConcatList(msg.msgRef);
175 /** Send Deliver Report */
176 SmsPluginTransport::instance()->sendDeliverReport(err);
181 #ifdef CONCAT_SIM_MSG_OPERATION
182 void SmsPluginConcatHandler::handleConcatMsg(SMS_TPDU_S *pTpdu, msg_sim_id_t SimMsgId, bool bRead)
186 if (pTpdu->tpduType != SMS_TPDU_DELIVER)
188 MSG_DEBUG("The TPDU type is not deliver [%d]", pTpdu->tpduType);
192 SMS_CONCAT_MSG_S msg;
193 memset(&msg, 0x00, sizeof(SMS_CONCAT_MSG_S));
195 for (int i = 0; i < pTpdu->data.deliver.userData.headerCnt; i++)
197 if (pTpdu->data.deliver.userData.header[i].udhType == SMS_UDH_CONCAT_8BIT)
199 msg.msgRef = (unsigned short)pTpdu->data.deliver.userData.header[i].udh.concat8bit.msgRef;
200 msg.totalSeg = pTpdu->data.deliver.userData.header[i].udh.concat8bit.totalSeg;
201 msg.seqNum = pTpdu->data.deliver.userData.header[i].udh.concat8bit.seqNum;
203 memcpy(&(msg.timeStamp.time.absolute), &(pTpdu->data.deliver.timeStamp.time.absolute), sizeof(SMS_TIME_ABS_S));
204 memcpy(&(msg.originAddress), &(pTpdu->data.deliver.originAddress), sizeof(SMS_ADDRESS_S));
205 memcpy(&(msg.dcs), &(pTpdu->data.deliver.dcs), sizeof(SMS_DCS_S));
209 if (msg.totalSeg > MAX_SEGMENT_NUM)
211 MSG_DEBUG("Total Segment Count is over Maximum [%d]", msg.totalSeg);
217 else if (pTpdu->data.deliver.userData.header[i].udhType == SMS_UDH_CONCAT_16BIT)
219 msg.msgRef = (unsigned short)pTpdu->data.deliver.userData.header[i].udh.concat16bit.msgRef;
220 msg.totalSeg = pTpdu->data.deliver.userData.header[i].udh.concat16bit.totalSeg;
221 msg.seqNum = pTpdu->data.deliver.userData.header[i].udh.concat16bit.seqNum;
223 memcpy(&(msg.timeStamp.time.absolute), &(pTpdu->data.deliver.timeStamp.time.absolute), sizeof(SMS_TIME_ABS_S));
224 memcpy(&(msg.originAddress), &(pTpdu->data.deliver.originAddress), sizeof(SMS_ADDRESS_S));
225 memcpy(&(msg.dcs), &(pTpdu->data.deliver.dcs), sizeof(SMS_DCS_S));
229 if (msg.totalSeg > MAX_SEGMENT_NUM)
231 MSG_DEBUG("Total Segment Count is over Maximum [%d]", msg.totalSeg);
239 unsigned char segCnt = checkConcatMsg(&msg, &(pTpdu->data.deliver.userData));
241 addToSimIdList(msg.msgRef, SimMsgId);
243 if (segCnt == msg.totalSeg)
245 MSG_DEBUG("RECEIVED LAST CONCAT : %d", segCnt);
248 char* pUserData = NULL;
249 AutoPtr<char> dataBuf(&pUserData);
251 MSG_MESSAGE_INFO_S msgInfo = {0};
253 dataSize = makeConcatUserData(msg.msgRef, &pUserData);
257 MSG_DEBUG("TOTAL DATA : %s", pUserData);
259 convertSimMsgToMsginfo(&msg, pUserData, dataSize, &msgInfo);
261 // set Sim Message ID
262 msgInfo.msgId = SimMsgId;
265 msgInfo.bRead = bRead;
267 /// Print MSG_MESSAGE_INFO_S
268 MSG_DEBUG("############# Convert tpdu values to Message Info values ####################");
270 MSG_DEBUG("msgInfo.msgId : %d", msgInfo.msgId);
271 MSG_DEBUG("msgInfo.nAddressCnt : %d", msgInfo.nAddressCnt);
272 MSG_DEBUG("msgInfo.addressList[0].addressType : %d", msgInfo.addressList[0].addressType);
273 MSG_DEBUG("msgInfo.addressList[0].addressVal : %s", msgInfo.addressList[0].addressVal);
274 MSG_DEBUG("msgInfo.priority : %d", msgInfo.priority);
275 MSG_DEBUG("msgInfo.bProtected : %d", msgInfo.bProtected);
276 MSG_DEBUG("msgInfo.bRead : %d", msgInfo.bRead);
277 MSG_DEBUG("msgInfo.bTextSms : %d", msgInfo.bTextSms);
278 MSG_DEBUG("msgInfo.direction : %d", msgInfo.direction);
279 MSG_DEBUG("msgInfo.msgType.mainType : %d", msgInfo.msgType.mainType);
280 MSG_DEBUG("msgInfo.msgType.subType : %d", msgInfo.msgType.subType);
281 MSG_DEBUG("msgInfo.msgType.classType : %d", msgInfo.msgType.classType);
282 MSG_DEBUG("msgInfo.displayTime : %s", ctime(&msgInfo.displayTime));
283 MSG_DEBUG("msgInfo.dataSize : %d", msgInfo.dataSize);
285 if (msgInfo.bTextSms == true)
286 MSG_DEBUG("msgInfo.msgText : %s", msgInfo.msgText);
288 MSG_DEBUG("msgInfo.msgData : %s", msgInfo.msgData);
290 MSG_DEBUG("###############################################################");
293 removeFromConcatList(msg.msgRef);
294 removeFromSimIdList(msg.msgRef);
296 //add msgInfo to msg list
297 SmsPluginStorage::instance()->addSimMsgToList(&msgInfo, true);
299 // Callback to MSG FW
300 SmsPluginEventHandler::instance()->callbackGetSimMsg();
305 //add index count to msg list
306 SmsPluginStorage::instance()->addSimMsgToList(NULL, false);
308 // Callback to MSG FW
309 SmsPluginEventHandler::instance()->callbackGetSimMsg();
316 void SmsPluginConcatHandler::handleBrokenMsg()
318 if (concatList.size() <= 0 || simIdList.size() <= 0)
320 MSG_DEBUG("No Broken Concatenated Message");
326 int index = 0, dataSize = 0;
327 char* pUserData = NULL;
328 AutoPtr<char> dataBuf(&pUserData);
330 MSG_MESSAGE_INFO_S msgInfo = {0};
332 dataSize = makeConcatUserData(concatList[index].msgRef, &pUserData);
336 MSG_DEBUG("TOTAL DATA : %s", pUserData);
338 SMS_CONCAT_MSG_S msg;
339 memset(&msg, 0x00, sizeof(SMS_CONCAT_MSG_S));
341 msg.msgRef = concatList[index].msgRef;
342 msg.totalSeg = concatList[index].totalSeg;
344 memcpy(&(msg.timeStamp.time.absolute), &(concatList[index].timeStamp.time.absolute), sizeof(SMS_TIME_ABS_S));
345 memcpy(&(msg.originAddress), &(concatList[index].originAddress), sizeof(SMS_ADDRESS_S));
346 memcpy(&(msg.dcs), &(concatList[index].dcs), sizeof(SMS_DCS_S));
348 convertSimMsgToMsginfo(&msg, pUserData, dataSize, &msgInfo);
350 // set Sim Message ID
354 msgInfo.bRead = concatList[index].bRead;
356 /// Print MSG_MESSAGE_INFO_S
357 MSG_DEBUG("############# Convert tpdu values to Message Info values ####################");
358 MSG_DEBUG("msgInfo.msgId : %d", msgInfo.msgId);
359 MSG_DEBUG("msgInfo.nAddressCnt : %d", msgInfo.nAddressCnt);
360 MSG_DEBUG("msgInfo.addressList[0].addressType : %d", msgInfo.addressList[0].addressType);
361 MSG_DEBUG("msgInfo.addressList[0].addressVal : %s", msgInfo.addressList[0].addressVal);
362 MSG_DEBUG("msgInfo.priority : %d", msgInfo.priority);
363 MSG_DEBUG("msgInfo.bProtected : %d", msgInfo.bProtected);
364 MSG_DEBUG("msgInfo.bRead : %d", msgInfo.bRead);
365 MSG_DEBUG("msgInfo.bTextSms : %d", msgInfo.bTextSms);
366 MSG_DEBUG("msgInfo.direction : %d", msgInfo.direction);
367 MSG_DEBUG("msgInfo.msgType.mainType : %d", msgInfo.msgType.mainType);
368 MSG_DEBUG("msgInfo.msgType.subType : %d", msgInfo.msgType.subType);
369 MSG_DEBUG("msgInfo.msgType.classType : %d", msgInfo.msgType.classType);
370 MSG_DEBUG("msgInfo.displayTime : %s", ctime(&msgInfo.displayTime));
371 MSG_DEBUG("msgInfo.dataSize : %d", msgInfo.dataSize);
372 if (msgInfo.bTextSms == true)
373 MSG_DEBUG("msgInfo.msgText : %s", msgInfo.msgText);
375 MSG_DEBUG("msgInfo.msgData : %s", msgInfo.msgData);
376 MSG_DEBUG("###############################################################");
378 //add msgInfo to msg list
379 SmsPluginStorage::instance()->addSimMsgToList(&msgInfo, true);
382 removeFromConcatList(concatList[index].msgRef);
383 removeFromSimIdList(concatList[index].msgRef);
384 }while (concatList.size() > 0);
389 unsigned char SmsPluginConcatHandler::checkConcatMsg(SMS_CONCAT_MSG_S *pConcatMsg, SMS_USERDATA_S *pUserData)
391 if (pConcatMsg == NULL || pUserData == NULL) {
392 MSG_DEBUG("In Parameter is NULL");
396 unsigned char currSegCnt = 0;
400 for (unsigned int i = 0; i < concatList.size(); i++) {
401 if (concatList[i].msgRef == pConcatMsg->msgRef) {
402 if (concatList[i].data.count(pConcatMsg->seqNum) != 0) {
403 MSG_DEBUG("The Sequence Number already exists [%d]", pConcatMsg->seqNum);
407 CONCAT_DATA_S concatData = {0};
409 memcpy(concatData.data, pUserData->data, pUserData->length);
410 concatData.length = pUserData->length;
412 pair<unsigned char, CONCAT_DATA_S> newData(pConcatMsg->seqNum, concatData);
413 concatList[i].data.insert(newData);
415 MSG_DEBUG("MSG DATA : %s", pUserData->data);
416 MSG_DEBUG("PAIR DATA [%d] : %s", newData.first, newData.second.data);
418 concatList[i].segCnt++;
419 concatList[i].totalSize += pUserData->length;
421 currSegCnt = concatList[i].segCnt;
429 /** New Concat Msg */
430 if (bFind == false) {
431 SMS_CONCAT_INFO_S tmpInfo;
433 tmpInfo.msgRef = pConcatMsg->msgRef;
434 tmpInfo.totalSeg = pConcatMsg->totalSeg;
437 memcpy(&(tmpInfo.timeStamp.time.absolute), &(pConcatMsg->timeStamp.time.absolute), sizeof(SMS_TIME_ABS_S));
438 memcpy(&(tmpInfo.originAddress), &(pConcatMsg->originAddress), sizeof(SMS_ADDRESS_S));
439 memcpy(&(tmpInfo.dcs), &(pConcatMsg->dcs), sizeof(SMS_DCS_S));
441 tmpInfo.totalSize = pUserData->length;
443 CONCAT_DATA_S concatData = {0};
445 memcpy(concatData.data, pUserData->data, pUserData->length);
446 concatData.length = pUserData->length;
448 pair<unsigned char, CONCAT_DATA_S> newData(pConcatMsg->seqNum, concatData);
449 tmpInfo.data.insert(newData);
451 MSG_DEBUG("MSG DATA : %s", pUserData->data);
452 MSG_DEBUG("PAIR DATA [%d] : %s", newData.first, newData.second.data);
454 concatList.push_back(tmpInfo);
456 currSegCnt = tmpInfo.segCnt;
463 int SmsPluginConcatHandler::makeConcatUserData(unsigned short MsgRef, char **ppTotalData)
465 concatDataMap::iterator it;
467 int totalSize = 0, offset = 0;
469 for (unsigned int i = 0; i < concatList.size(); i++) {
470 if (concatList[i].msgRef == MsgRef) {
471 totalSize = concatList[i].totalSize;
473 if (totalSize <= 0) {
474 MSG_DEBUG("Size Error : totalSize <= 0");
478 MSG_DEBUG("totalSize [%d]", totalSize);
480 *ppTotalData = new char[totalSize];
482 for (it = concatList[i].data.begin(); it != concatList[i].data.end(); it++) {
483 memcpy(*ppTotalData+offset, it->second.data, it->second.length);
484 offset += it->second.length;
493 void SmsPluginConcatHandler::convertConcatToMsginfo(const SMS_DELIVER_S *pTpdu, const char *pUserData, int DataSize, MSG_MESSAGE_INFO_S *pMsgInfo)
495 /** Convert Type values */
496 pMsgInfo->msgType.mainType = MSG_SMS_TYPE;
497 pMsgInfo->msgType.subType = MSG_NORMAL_SMS;
500 pMsgInfo->folderId = MSG_INBOX_ID;
502 /** set storage id */
503 pMsgInfo->storageId = MSG_STORAGE_PHONE;
505 switch(pTpdu->dcs.msgClass)
507 case SMS_MSG_CLASS_0:
508 pMsgInfo->msgType.classType = MSG_CLASS_0;
510 case SMS_MSG_CLASS_1:
511 pMsgInfo->msgType.classType = MSG_CLASS_1;
513 case SMS_MSG_CLASS_2:
514 pMsgInfo->msgType.classType = MSG_CLASS_2;
516 case SMS_MSG_CLASS_3:
517 pMsgInfo->msgType.classType = MSG_CLASS_3;
520 pMsgInfo->msgType.classType = MSG_CLASS_NONE;
524 pMsgInfo->networkStatus = MSG_NETWORK_RECEIVED;
525 pMsgInfo->bRead = false;
526 pMsgInfo->bProtected = false;
527 pMsgInfo->priority = MSG_MESSAGE_PRIORITY_NORMAL;
528 pMsgInfo->direction = MSG_DIRECTION_TYPE_MT;
531 time_t rawtime = time(NULL);
533 /*** Comment below lines to save local UTC time..... (it could be used later.)
535 if (pTpdu->timeStamp.format == SMS_TIME_ABSOLUTE) {
537 MSG_DEBUG("year : %d", pTpdu->timeStamp.time.absolute.year);
538 MSG_DEBUG("month : %d", pTpdu->timeStamp.time.absolute.month);
539 MSG_DEBUG("day : %d", pTpdu->timeStamp.time.absolute.day);
540 MSG_DEBUG("hour : %d", pTpdu->timeStamp.time.absolute.hour);
541 MSG_DEBUG("minute : %d", pTpdu->timeStamp.time.absolute.minute);
542 MSG_DEBUG("second : %d", pTpdu->timeStamp.time.absolute.second);
543 MSG_DEBUG("timezone : %d", pTpdu->timeStamp.time.absolute.timeZone);
545 char displayTime[32];
549 memset(&timeinfo, 0x00, sizeof(tm));
551 timeinfo.tm_year = (pTpdu->timeStamp.time.absolute.year + 100);
552 timeinfo.tm_mon = (pTpdu->timeStamp.time.absolute.month - 1);
553 timeinfo.tm_mday = pTpdu->timeStamp.time.absolute.day;
554 timeinfo.tm_hour = pTpdu->timeStamp.time.absolute.hour;
555 timeinfo.tm_min = pTpdu->timeStamp.time.absolute.minute;
556 timeinfo.tm_sec = pTpdu->timeStamp.time.absolute.second;
557 timeinfo.tm_isdst = 0;
559 rawtime = mktime(&timeinfo);
561 MSG_DEBUG("tzname[0] [%s]", tzname[0]);
562 MSG_DEBUG("tzname[1] [%s]", tzname[1]);
563 MSG_DEBUG("timezone [%d]", timezone);
564 MSG_DEBUG("daylight [%d]", daylight);
566 memset(displayTime, 0x00, sizeof(displayTime));
567 strftime(displayTime, 32, "%Y-%02m-%02d %T %z", &timeinfo);
568 MSG_DEBUG("displayTime [%s]", displayTime);
570 rawtime -= (pTpdu->timeStamp.time.absolute.timeZone * (3600/4));
572 timeTM = localtime(&rawtime);
573 memset(displayTime, 0x00, sizeof(displayTime));
574 strftime(displayTime, 32, "%Y-%02m-%02d %T %z", timeTM);
575 MSG_DEBUG("displayTime [%s]", displayTime);
579 timeTM = localtime(&rawtime);
580 memset(displayTime, 0x00, sizeof(displayTime));
581 strftime(displayTime, 32, "%Y-%02m-%02d %T %z", timeTM);
582 MSG_DEBUG("displayTime [%s]", displayTime);
587 pMsgInfo->displayTime = rawtime;
589 /** Convert Address values */
590 pMsgInfo->nAddressCnt = 1;
591 pMsgInfo->addressList[0].addressType = MSG_ADDRESS_TYPE_PLMN;
592 strncpy(pMsgInfo->addressList[0].addressVal, pTpdu->originAddress.address, MAX_ADDRESS_VAL_LEN);
594 pMsgInfo->msgPort.valid = false;
595 pMsgInfo->msgPort.dstPort = 0;
596 pMsgInfo->msgPort.srcPort = 0;
598 for (int i = 0; i < pTpdu->userData.headerCnt; i++) {
599 /** Convert UDH values - Port Number */
600 if (pTpdu->userData.header[i].udhType == SMS_UDH_APP_PORT_8BIT) {
601 pMsgInfo->msgPort.valid = true;
602 pMsgInfo->msgPort.dstPort = pTpdu->userData.header[i].udh.appPort8bit.destPort;
603 pMsgInfo->msgPort.srcPort = pTpdu->userData.header[i].udh.appPort8bit.originPort;
604 } else if (pTpdu->userData.header[i].udhType == SMS_UDH_APP_PORT_16BIT) {
605 pMsgInfo->msgPort.valid = true;
606 pMsgInfo->msgPort.dstPort = pTpdu->userData.header[i].udh.appPort16bit.destPort;
607 pMsgInfo->msgPort.srcPort = pTpdu->userData.header[i].udh.appPort16bit.originPort;
611 //int bufSize = (MAX_MSG_DATA_LEN*MAX_SEGMENT_NUM) + 1;
612 int bufSize = (DataSize*4) + 1; // For UTF8
614 char tmpBuf[bufSize];
615 memset(tmpBuf, 0x00, sizeof(tmpBuf));
617 /** Convert Data values */
618 if (pTpdu->dcs.codingScheme == SMS_CHARSET_7BIT) {
619 MSG_LANG_INFO_S langInfo = {0,};
621 langInfo.bSingleShift = false;
622 langInfo.bLockingShift = false;
624 pMsgInfo->encodeType = MSG_ENCODE_GSM7BIT;
625 pMsgInfo->dataSize = textCvt.convertGSM7bitToUTF8((unsigned char*)tmpBuf, bufSize, (unsigned char*)pUserData, DataSize, &langInfo);
626 } else if (pTpdu->dcs.codingScheme == SMS_CHARSET_8BIT) {
627 pMsgInfo->encodeType = MSG_ENCODE_8BIT;
628 memcpy(tmpBuf, pUserData, DataSize);
629 pMsgInfo->dataSize = DataSize;
630 } else if (pTpdu->dcs.codingScheme == SMS_CHARSET_UCS2) {
631 pMsgInfo->encodeType = MSG_ENCODE_UCS2;
632 pMsgInfo->dataSize = textCvt.convertUCS2ToUTF8((unsigned char*)tmpBuf, bufSize, (unsigned char*)pUserData, DataSize);
635 MSG_DEBUG("Data Size [%d]", pMsgInfo->dataSize);
636 MSG_DEBUG("Data [%s]", tmpBuf);
638 #ifdef MSG_FW_FOR_DEBUG
641 for (int i = 0; i < pMsgInfo->dataSize; i++)
643 printf("[%02x]", tmpBuf[i]);
649 if (pMsgInfo->dataSize > MAX_MSG_TEXT_LEN) {
650 pMsgInfo->bTextSms = false;
652 /** Save Message Data into File */
653 char fileName[MSG_FILENAME_LEN_MAX+1];
654 memset(fileName, 0x00, sizeof(fileName));
656 if (MsgCreateFileName(fileName) == false)
657 THROW(MsgException::FILE_ERROR, "######## MsgCreateFileName Fail !!! #######");
659 MSG_DEBUG("Save Message Data into file : size[%d] name[%s]\n", pMsgInfo->dataSize, fileName);
660 if (MsgWriteIpcFile(fileName, tmpBuf, pMsgInfo->dataSize) == false)
661 THROW(MsgException::FILE_ERROR, "######## MsgWriteIpcFile Fail !!! #######");
663 strncpy(pMsgInfo->msgData, fileName, MAX_MSG_DATA_LEN);
665 pMsgInfo->bTextSms = true;
667 memset(pMsgInfo->msgText, 0x00, sizeof(pMsgInfo->msgText));
668 memcpy(pMsgInfo->msgText, tmpBuf, pMsgInfo->dataSize);
673 #ifdef CONCAT_SIM_MSG_OPERATION
674 void SmsPluginConcatHandler::convertSimMsgToMsginfo(const SMS_CONCAT_MSG_S *pConcatMsg, const char *pUserData, int DataSize, MSG_MESSAGE_INFO_S *pMsgInfo)
676 // Convert Type values
677 pMsgInfo->msgType.mainType = MSG_SMS_TYPE;
678 pMsgInfo->msgType.subType = MSG_CONCAT_SIM_SMS;
680 // set folder id (temporary)
681 pMsgInfo->folderId = MSG_INBOX_ID;
683 pMsgInfo->storageId = MSG_STORAGE_SIM;
685 switch (pConcatMsg->dcs.msgClass)
687 case SMS_MSG_CLASS_0:
688 pMsgInfo->msgType.classType = MSG_CLASS_0;
690 case SMS_MSG_CLASS_1:
691 pMsgInfo->msgType.classType = MSG_CLASS_1;
693 case SMS_MSG_CLASS_2:
694 pMsgInfo->msgType.classType = MSG_CLASS_2;
696 case SMS_MSG_CLASS_3:
697 pMsgInfo->msgType.classType = MSG_CLASS_3;
700 pMsgInfo->msgType.classType = MSG_CLASS_NONE;
703 pMsgInfo->networkStatus = MSG_NETWORK_RECEIVED;
704 pMsgInfo->bRead = false;
705 pMsgInfo->bProtected = false;
706 pMsgInfo->priority = MSG_MESSAGE_PRIORITY_NORMAL;
707 pMsgInfo->direction = MSG_DIRECTION_TYPE_MT;
709 time_t rawtime = time(NULL);
711 /*** Comment below lines to save local UTC time..... (it could be used later.)
713 if (pTpdu->timeStamp.format == SMS_TIME_ABSOLUTE) {
715 MSG_DEBUG("year : %d", pTpdu->timeStamp.time.absolute.year);
716 MSG_DEBUG("month : %d", pTpdu->timeStamp.time.absolute.month);
717 MSG_DEBUG("day : %d", pTpdu->timeStamp.time.absolute.day);
718 MSG_DEBUG("hour : %d", pTpdu->timeStamp.time.absolute.hour);
719 MSG_DEBUG("minute : %d", pTpdu->timeStamp.time.absolute.minute);
720 MSG_DEBUG("second : %d", pTpdu->timeStamp.time.absolute.second);
721 MSG_DEBUG("timezone : %d", pTpdu->timeStamp.time.absolute.timeZone);
723 char displayTime[32];
727 memset(&timeinfo, 0x00, sizeof(tm));
729 timeinfo.tm_year = (pTpdu->timeStamp.time.absolute.year + 100);
730 timeinfo.tm_mon = (pTpdu->timeStamp.time.absolute.month - 1);
731 timeinfo.tm_mday = pTpdu->timeStamp.time.absolute.day;
732 timeinfo.tm_hour = pTpdu->timeStamp.time.absolute.hour;
733 timeinfo.tm_min = pTpdu->timeStamp.time.absolute.minute;
734 timeinfo.tm_sec = pTpdu->timeStamp.time.absolute.second;
735 timeinfo.tm_isdst = 0;
737 rawtime = mktime(&timeinfo);
739 MSG_DEBUG("tzname[0] [%s]", tzname[0]);
740 MSG_DEBUG("tzname[1] [%s]", tzname[1]);
741 MSG_DEBUG("timezone [%d]", timezone);
742 MSG_DEBUG("daylight [%d]", daylight);
744 memset(displayTime, 0x00, sizeof(displayTime));
745 strftime(displayTime, 32, "%Y-%02m-%02d %T %z", &timeinfo);
746 MSG_DEBUG("displayTime [%s]", displayTime);
747 rawtime -= (pTpdu->timeStamp.time.absolute.timeZone * (3600/4));
749 timeTM = localtime(&rawtime);
750 memset(displayTime, 0x00, sizeof(displayTime));
751 strftime(displayTime, 32, "%Y-%02m-%02d %T %z", timeTM);
752 MSG_DEBUG("displayTime [%s]", displayTime);
756 timeTM = localtime(&rawtime);
757 memset(displayTime, 0x00, sizeof(displayTime));
758 strftime(displayTime, 32, "%Y-%02m-%02d %T %z", timeTM);
759 MSG_DEBUG("displayTime [%s]", displayTime);
764 pMsgInfo->displayTime = rawtime;
766 // Convert Address values
767 pMsgInfo->nAddressCnt = 1;
768 pMsgInfo->addressList[0].addressType = MSG_ADDRESS_TYPE_PLMN;
769 strncpy(pMsgInfo->addressList[0].addressVal, pConcatMsg->originAddress.address, MAX_ADDRESS_VAL_LEN);
771 pMsgInfo->msgPort.valid = false;
772 pMsgInfo->msgPort.dstPort = 0;
773 pMsgInfo->msgPort.srcPort = 0;
775 // Insert SMS_CONCAT_SIM_MSG_S into File
776 SMS_CONCAT_SIM_MSG_S concatSimMsg = {0};
778 for (unsigned int i = 0; i < simIdList.size(); i++)
780 if (simIdList[i].msgRef == pConcatMsg->msgRef)
782 MSG_DEBUG("Get SIM ID [%d] - List Index [%d]", simIdList[i].simId, concatSimMsg.simIdCnt);
784 concatSimMsg.simIdList[concatSimMsg.simIdCnt] = simIdList[i].simId;
785 concatSimMsg.simIdCnt++;
789 int bufSize = (MAX_MSG_DATA_LEN*MAX_SEGMENT_NUM) + 1;
791 char tmpBuf[bufSize];
792 memset(tmpBuf, 0x00, sizeof(tmpBuf));
794 // Convert Data values
795 if (pConcatMsg->dcs.codingScheme == SMS_CHARSET_7BIT)
797 SMS_LANG_INFO_S langInfo = {0};
799 langInfo.bSingleShift = false;
800 langInfo.bLockingShift = false;
802 pMsgInfo->encodeType = MSG_ENCODE_GSM7BIT;
803 pMsgInfo->dataSize = SmsPluginTextConvert::instance()->convertGSM7bitToUTF8((unsigned char*)tmpBuf, bufSize, (unsigned char*)pUserData, DataSize, &langInfo);
805 else if (pConcatMsg->dcs.codingScheme == SMS_CHARSET_8BIT)
807 pMsgInfo->encodeType = MSG_ENCODE_8BIT;
808 memcpy(tmpBuf, pUserData, DataSize);
809 pMsgInfo->dataSize = DataSize;
811 else if (pConcatMsg->dcs.codingScheme == SMS_CHARSET_UCS2)
813 pMsgInfo->encodeType = MSG_ENCODE_UCS2;
814 pMsgInfo->dataSize = SmsPluginTextConvert::instance()->convertUCS2ToUTF8((unsigned char*)tmpBuf, bufSize, (unsigned char*)pUserData, DataSize);
817 MSG_DEBUG("Data Size [%d]", pMsgInfo->dataSize);
819 pMsgInfo->bTextSms = false;
821 if (pMsgInfo->dataSize > 0)
822 memcpy(concatSimMsg.msgData, tmpBuf, pMsgInfo->dataSize);
824 // Save Message Data into File
825 char fileName[MAX_COMMON_INFO_SIZE+1];
826 memset(fileName, 0x00, sizeof(fileName));
828 if (MsgCreateFileName(fileName) == false)
829 THROW(MsgException::FILE_ERROR, "MsgCreateFileName error");
831 if (MsgWriteIpcFile(fileName, (char*)(&concatSimMsg), sizeof(SMS_CONCAT_SIM_MSG_S)) == false)
832 THROW(MsgException::FILE_ERROR, "MsgWriteIpcFile error");
834 memset(pMsgInfo->msgData, 0x00, sizeof(pMsgInfo->msgData));
835 strncpy(pMsgInfo->msgData, fileName, MAX_MSG_DATA_LEN);
837 MSG_DEBUG("Save Message Data into file : size[%d] name[%s]", pMsgInfo->dataSize, fileName);
842 void SmsPluginConcatHandler::removeFromConcatList(unsigned short MsgRef)
844 for (int index = concatList.size(); index >= 0 ; index--) {
845 if (concatList[index].msgRef == MsgRef) {
846 MSG_DEBUG("remove concatlist of the index [%d]", index);
847 concatList.erase(concatList.begin()+index);
853 #ifdef CONCAT_SIM_MSG_OPERATION
854 void SmsPluginConcatHandler::addToSimIdList(unsigned short MsgRef, msg_sim_id_t SimMsgId)
856 SMS_SIM_ID_S simIdStruct;
858 simIdStruct.msgRef = MsgRef;
859 simIdStruct.simId = SimMsgId;
861 simIdList.push_back(simIdStruct);
865 void SmsPluginConcatHandler::removeFromSimIdList(unsigned short MsgRef)
867 for (int index = simIdList.size()-1; index >= 0 ; index--)
869 if (simIdList[index].msgRef == MsgRef)
871 MSG_DEBUG("remove simIdList of the index [%d]", index);
873 simIdList.erase(simIdList.begin()+index);