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://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.
20 #include "MsgCppTypes.h"
21 #include "MsgException.h"
22 #include "MsgGconfWrapper.h"
23 #include "MsgUtilFile.h"
24 #include "SmsPluginUDCodec.h"
25 #include "SmsPluginStorage.h"
26 #include "SmsPluginEventHandler.h"
27 #include "SmsPluginCbMsgHandler.h"
30 /*==================================================================================================
31 IMPLEMENTATION OF SmsPluginCbMsgHandler - Member Functions
32 ==================================================================================================*/
33 SmsPluginCbMsgHandler* SmsPluginCbMsgHandler::pInstance = NULL;
36 SmsPluginCbMsgHandler::SmsPluginCbMsgHandler()
42 SmsPluginCbMsgHandler::~SmsPluginCbMsgHandler()
48 SmsPluginCbMsgHandler* SmsPluginCbMsgHandler::instance()
51 pInstance = new SmsPluginCbMsgHandler();
57 void SmsPluginCbMsgHandler::handleCbMsg(TelSmsCbMsg_t *pCbMsg)
61 SMS_CB_NETWORK_TYPE_T type = pCbMsg->CbMsgType;
63 SMS_CBMSG_PAGE_S CbMsgPage = {0};
67 case SMS_CB_NETWORK_TYPE_2G_GSM :
68 Decode2gCbMsg(pCbMsg, &CbMsgPage);
71 case SMS_CB_NETWORK_TYPE_3G_UMTS :
72 Decode3gCbMsg(pCbMsg, &CbMsgPage);
76 // Check CB Msg Options
77 bool bJavaMsg = false;
79 if (!checkCbOpt(CbMsgPage, &bJavaMsg))
81 MSG_DEBUG("The CB Msg is not supported by option.");
87 MSG_DEBUG("JAVA CB Msg.");
88 CbMsgPage.cbMsgType = SMS_CBMSG_TYPE_JAVACBS;
92 unsigned char pageCnt = checkCbPage(CbMsgPage);
94 if (pageCnt == CbMsgPage.pageHeader.totalPages)
96 MSG_DEBUG("RECEIVED LAST MSG : %d", pageCnt);
98 SMS_CBMSG_S cbMsg = {};
99 MSG_MESSAGE_INFO_S msgInfo = {};
101 // Make CB Msg Structure
102 MakeCbMsg(CbMsgPage, &cbMsg);
104 // Convert to MSG_MESSAGE_INFO_S
105 convertCbMsgToMsginfo(&cbMsg, &msgInfo);
107 // Add CB Msg into DB
108 msg_error_t err = MSG_SUCCESS;
110 err = SmsPluginStorage::instance()->addMessage(&msgInfo);
112 if (err == MSG_SUCCESS)
114 MSG_CB_MSG_S cbOutMsg = {0, };
116 cbOutMsg.type = MSG_CB_SMS;
117 cbOutMsg.receivedTime = cbMsg.recvTime;
118 cbOutMsg.serialNum = encodeCbSerialNum (CbMsgPage.pageHeader.serialNum);
119 cbOutMsg.messageId = cbMsg.msgId;
120 cbOutMsg.dcs = CbMsgPage.pageHeader.dcs.rawData;
121 memset (cbOutMsg.cbText, 0x00, sizeof(cbOutMsg.cbText));
123 cbOutMsg.cbTextLen= convertTextToUtf8((unsigned char*)cbOutMsg.cbText, sizeof(cbOutMsg.cbText), &cbMsg);
124 memset(cbOutMsg.language_type, 0x00, sizeof(cbOutMsg.language_type));
125 memcpy(cbOutMsg.language_type, CbMsgPage.pageHeader.dcs.iso639Lang, 3);
126 err = SmsPluginEventHandler::instance()->callbackCBMsgIncoming(&cbOutMsg);
127 if (err != MSG_SUCCESS)
129 MSG_DEBUG("callbackMsgIncoming() Error !! [%d]", err);
134 MSG_DEBUG("addMessage() Error !! [%d]", err);
138 removeFromPageList(CbMsgPage);
144 void SmsPluginCbMsgHandler::handleEtwsMsg(TelSmsEtwsMsg_t *pEtwsMsg)
147 msg_error_t err = MSG_SUCCESS;
148 SMS_ETWS_NETWORK_TYPE_T type = pEtwsMsg->EtwsMsgType;
149 //MSG_MESSAGE_INFO_S msgInfo = {};
150 SMS_ETWS_PRIMARY_S etwsPn = {0, };
151 MSG_CB_MSG_S cbOutMsg = {0, };
153 if(type != TAPI_NETTEXT_ETWS_PRIMARY)
155 MSG_DEBUG("The Etws Msg is not supported");
158 DecodeEtwsMsg(pEtwsMsg, &etwsPn);
159 //convertEtwsMsgToMsginfo(CbMsgPage, &msgInfo);
161 cbOutMsg.type = MSG_ETWS_SMS;
162 cbOutMsg.receivedTime = etwsPn.recvTime;
163 cbOutMsg.serialNum = encodeCbSerialNum (etwsPn.serialNum);
164 cbOutMsg.messageId = etwsPn.msgId;
165 cbOutMsg.etwsWarningType = etwsPn.warningType;
166 memcpy (cbOutMsg.etwsWarningSecurityInfo, etwsPn.warningSecurityInfo, sizeof(cbOutMsg.etwsWarningSecurityInfo));
168 err = SmsPluginEventHandler::instance()->callbackCBMsgIncoming(&cbOutMsg);
169 if (err != MSG_SUCCESS)
171 MSG_DEBUG("callbackMsgIncoming() Error !! [%d]", err);
178 void SmsPluginCbMsgHandler::Decode2gCbMsg(TelSmsCbMsg_t *pCbMsg, SMS_CBMSG_PAGE_S *pCbPage)
180 if (pCbMsg->Length > MAX_CBMSG_PAGE_SIZE)
181 THROW(MsgException::SMS_PLG_ERROR, "CB Msg Size is over MAX [%d]", pCbMsg->Length);
183 unsigned char cbData[pCbMsg->Length+1];
185 memset(cbData, 0x00, sizeof(cbData));
186 memcpy(cbData, pCbMsg->szMsgData, pCbMsg->Length);
187 cbData[pCbMsg->Length] = '\0';
189 pCbPage->cbMsgType = SMS_CBMSG_TYPE_CBS;
192 pCbPage->pageHeader.serialNum.geoScope = (cbData[0] & 0xC0) >> 6;
194 pCbPage->pageHeader.serialNum.msgCode = (cbData[0] & 0x3F) << 4;
195 pCbPage->pageHeader.serialNum.msgCode |= (cbData[1] & 0xF0) >> 4;
197 pCbPage->pageHeader.serialNum.updateNum = cbData[1] & 0x0F;
199 MSG_DEBUG("geoScope : [%d], msgCode : [%d], updateNum : [%d]", pCbPage->pageHeader.serialNum.geoScope, pCbPage->pageHeader.serialNum.msgCode, pCbPage->pageHeader.serialNum.updateNum);
201 pCbPage->pageHeader.msgId = (cbData[2] << 8) | cbData[3];
203 MSG_DEBUG("MSG ID : [%d]", pCbPage->pageHeader.msgId);
206 decodeCbMsgDCS(cbData[4], (unsigned char*)cbData[6], &(pCbPage->pageHeader.dcs));
209 pCbPage->pageHeader.totalPages = cbData[5] & 0x0F;
210 pCbPage->pageHeader.page = (cbData[5] & 0xF0) >> 4;
212 if (pCbPage->pageHeader.totalPages > MAX_CBMSG_PAGE_NUM)
213 THROW(MsgException::SMS_PLG_ERROR, "CB Page Count is over MAX[%d]", pCbPage->pageHeader.totalPages);
215 MSG_DEBUG("Total Page : [%d], Page : [%d]", pCbPage->pageHeader.totalPages, pCbPage->pageHeader.page);
217 // Convert Language Type
218 convertLangType(pCbPage->pageHeader.dcs.langType, &(pCbPage->pageHeader.langType));
220 MSG_DEBUG("In Language Type : [%d], Out Language Type : [%d]", pCbPage->pageHeader.dcs.langType, pCbPage->pageHeader.langType);
221 MSG_DEBUG("iso639Lang : [%s]", pCbPage->pageHeader.dcs.iso639Lang);
223 pCbPage->pageHeader.recvTime = getRecvTime();
226 int dataLen = pCbMsg->Length - 6;
228 switch (pCbPage->pageHeader.dcs.codingScheme)
230 case SMS_CHARSET_7BIT :
232 MSG_DEBUG("GSM 7 BIT");
234 dataLen = (dataLen*8) / 7;
236 SmsPluginUDCodec udCodec;
237 char pageData[MAX_CBMSG_PAGE_SIZE+1];
238 int unpackLen = udCodec.unpack7bitChar(&cbData[6], dataLen, 0, pageData);
240 if(pCbPage->pageHeader.dcs.iso639Lang[0])
242 unpackLen = unpackLen - 3;
243 memcpy(pCbPage->pageData, &pageData[3], unpackLen);
245 memcpy(pCbPage->pageData, &pageData, unpackLen);
248 MSG_DEBUG("unpackLen : [%d]", unpackLen);
250 pCbPage->pageLength = unpackLen;
251 pCbPage->pageData[unpackLen] = '\0';
255 case SMS_CHARSET_8BIT :
256 case SMS_CHARSET_UCS2 :
260 if(pCbPage->pageHeader.dcs.iso639Lang[0])
262 memcpy(pCbPage->pageData, &cbData[8], dataLen - 2);
263 pCbPage->pageLength = dataLen - 2;
265 memcpy(pCbPage->pageData, &cbData[6], dataLen);
266 pCbPage->pageLength = dataLen;
272 MSG_DEBUG("Page Length : [%d], Page Data : [%s]", pCbPage->pageLength, pCbPage->pageData);
276 void SmsPluginCbMsgHandler::DecodeEtwsMsg(TelSmsEtwsMsg_t *pEtwsMsg, SMS_ETWS_PRIMARY_S *pEtwsPn)
278 if ( !pEtwsMsg || !pEtwsPn )
281 if (pEtwsMsg->Length > MAX_ETWS_SIZE)
282 THROW(MsgException::SMS_PLG_ERROR, "ETWS Msg Size is over MAX [%d]", pEtwsMsg->Length);
284 unsigned char EtwsData[pEtwsMsg->Length+1];
286 memset(EtwsData, 0x00, sizeof(EtwsData));
287 memcpy(EtwsData, pEtwsMsg->szMsgData, pEtwsMsg->Length);
288 EtwsData[pEtwsMsg->Length] = '\0';
291 pEtwsPn->recvTime = getRecvTime();
294 pEtwsPn->serialNum.geoScope = (EtwsData[0] & 0xC0) >> 6;
295 pEtwsPn->serialNum.msgCode = (EtwsData[0] & 0x3F) << 4;
296 pEtwsPn->serialNum.msgCode |= (EtwsData[1] & 0xF0) >> 4;
297 pEtwsPn->serialNum.updateNum = EtwsData[1] & 0x0F;
299 MSG_DEBUG("geoScope : [%d], msgCode : [%d], updateNum : [%d]", pEtwsPn->serialNum.geoScope, pEtwsPn->serialNum.msgCode, pEtwsPn->serialNum.updateNum);
301 // Message Identifier
302 pEtwsPn->msgId = (EtwsData[2] << 8) | EtwsData[3];
303 MSG_DEBUG("MSG ID : [%d]", pEtwsPn->msgId);
306 pEtwsPn->warningType = (EtwsData[4] << 8) | EtwsData[5];
307 MSG_DEBUG("warningType : [0x%04x]", pEtwsPn->msgId);
309 // warning security information
310 memcpy(pEtwsPn->warningSecurityInfo, &EtwsData[6], sizeof(pEtwsPn->warningSecurityInfo)); // 50bytes
311 for (unsigned int i = 0; i < sizeof(pEtwsPn->warningSecurityInfo); i++)
313 MSG_DEBUG("warning secu info [%02x]", pEtwsPn->warningSecurityInfo[i] );
317 void SmsPluginCbMsgHandler::Decode3gCbMsg(TelSmsCbMsg_t *pCbMsg, SMS_CBMSG_PAGE_S *pCbPage)
319 if (pCbMsg->Length > (MAX_CBMSG_PAGE_SIZE*MAX_CBMSG_PAGE_NUM))
320 THROW(MsgException::SMS_PLG_ERROR, "CB Msg Size is over MAX [%d]", pCbMsg->Length);
322 char cbData[(MAX_CBMSG_PAGE_SIZE*MAX_CBMSG_PAGE_NUM)+1];
324 memset(cbData, 0x00, sizeof(cbData));
325 memcpy(cbData, pCbMsg->szMsgData, sizeof(pCbMsg->szMsgData));
326 cbData[pCbMsg->Length] = '\0';
328 pCbPage->cbMsgType = (SMS_CBMSG_TYPE_T)cbData[0];
330 pCbPage->pageHeader.msgId = (cbData[1] << 8) | cbData[2];
332 MSG_DEBUG("MSG ID : [%d]", pCbPage->pageHeader.msgId);
335 pCbPage->pageHeader.serialNum.geoScope = (cbData[3] & 0xC0) >> 6;
337 pCbPage->pageHeader.serialNum.msgCode = (cbData[3] & 0x3F) << 4;
338 pCbPage->pageHeader.serialNum.msgCode |= (cbData[4] & 0xF0) >> 4;
340 pCbPage->pageHeader.serialNum.updateNum = cbData[4] & 0x0F;
342 MSG_DEBUG("geoScope : [%d], msgCode : [%d], updateNum : [%d]", pCbPage->pageHeader.serialNum.geoScope, pCbPage->pageHeader.serialNum.msgCode, pCbPage->pageHeader.serialNum.updateNum);
345 decodeCbMsgDCS(cbData[5], (unsigned char*)cbData[6], &(pCbPage->pageHeader.dcs));
347 // Convert Language Type
348 convertLangType(pCbPage->pageHeader.dcs.langType, &(pCbPage->pageHeader.langType));
350 MSG_DEBUG("In Language Type : [%d], Out Language Type : [%d]", pCbPage->pageHeader.dcs.langType, pCbPage->pageHeader.langType);
353 pCbPage->pageHeader.recvTime = getRecvTime();
357 int dataLen = pCbMsg->Length - 6;
359 switch (pCbPage->pageHeader.dcs.codingScheme)
361 case SMS_CHARSET_7BIT :
363 dataLen = (dataLen*8) / 7;
365 if (pCbPage->pageLength > MAX_CBMSG_PAGE_SIZE)
366 THROW(MsgException::SMS_PLG_ERROR, "CB Msg Size is over MAX [%d]", pCbPage->pageLength);
368 SmsPluginUDCodec udCodec;
369 int unpackLen = udCodec.unpack7bitChar(&cbData[6], dataLen, 0, pCbPage->pageData);
370 pCbPage->pageData[unpackLen] = '\0';
372 pCbPage->pageLength = unpackLen;
376 case SMS_CHARSET_8BIT :
377 case SMS_CHARSET_UCS2 :
379 pCbPage->pageLength = dataLen;
381 memcpy(pCbPage->pageData, &cbData[6], pCbPage->pageLength);
382 pCbPage->pageData[pCbPage->pageLength] = '\0';
387 MSG_DEBUG("Page Length : [%d], Page Data : [%s]", pCbPage->pageLength, pCbPage->pageData);
391 unsigned short SmsPluginCbMsgHandler::encodeCbSerialNum ( SMS_CBMSG_SERIAL_NUM_S snFields )
393 unsigned short serialNum = 0;
395 serialNum = ((snFields.geoScope & 0x03) << 14) | ((snFields.msgCode&0x03FF) << 4) | (snFields.updateNum&0x0F);
396 MSG_DEBUG ("serialNum (%x), geo(%x), mc(%x), un(%x)\n", serialNum, snFields.geoScope, snFields.msgCode, snFields.updateNum);
401 bool SmsPluginCbMsgHandler::checkCbOpt(SMS_CBMSG_PAGE_S CbPage, bool *pJavaMsg)
403 bool bReceive = false;
404 MsgSettingGetBool(CB_RECEIVE, &bReceive);
406 // Receive CB Msg = FALSE
409 MSG_DEBUG("RECEIVE CB = FALSE");
416 memset(keyName, 0x00, sizeof(keyName));
417 sprintf(keyName, "%s/%d", CB_LANGUAGE, MSG_CBLANG_TYPE_ALL);
419 bool bAllLang = false;
420 MsgSettingGetBool(keyName, &bAllLang);
424 MSG_DEBUG("ALL LANGUAGE = FALSE");
426 memset(keyName, 0x00, sizeof(keyName));
427 sprintf(keyName, "%s/%d", CB_LANGUAGE, CbPage.pageHeader.langType);
431 MsgSettingGetBool(keyName, &bLang);
433 if (!bLang || CbPage.pageHeader.langType == MSG_CBLANG_TYPE_MAX)
435 MSG_DEBUG("LANGUAGE [%d] = FALSE", CbPage.pageHeader.langType);
440 int MsgIdCnt = MsgSettingGetInt(CB_CHANNEL_COUNT);
442 bool bActivate = false;
443 int MsgId_from = 0, MsgId_to = 0;
445 for (int i = 0; i < MsgIdCnt; i++)
447 memset(keyName, 0x00, sizeof(keyName));
448 sprintf(keyName, "%s/%d", CB_CHANNEL_ACTIVATE, i);
450 MsgSettingGetBool(keyName, &bActivate);
452 memset(keyName, 0x00, sizeof(keyName));
453 sprintf(keyName, "%s/%d", CB_CHANNEL_ID_FROM, i);
455 MsgId_from = MsgSettingGetInt(keyName);
457 memset(keyName, 0x00, sizeof(keyName));
458 sprintf(keyName, "%s/%d", CB_CHANNEL_ID_TO, i);
460 MsgId_to = MsgSettingGetInt(keyName);
462 if (bActivate == true && CbPage.pageHeader.msgId >= MsgId_from && CbPage.pageHeader.msgId <= MsgId_to)
464 MSG_DEBUG("FIND CHANNEL = [%d]", CbPage.pageHeader.msgId);
473 unsigned char SmsPluginCbMsgHandler::checkCbPage(SMS_CBMSG_PAGE_S CbPage)
475 unsigned char currPageCnt = 0;
479 if (CbPage.pageHeader.totalPages > 1)
481 for (unsigned int i = 0; i < pageList.size(); i++)
483 if (pageList[i].geoScope == CbPage.pageHeader.serialNum.geoScope && pageList[i].msgCode == CbPage.pageHeader.serialNum.msgCode)
485 MSG_DEBUG("geoScope [%d], msgCode [%d]", pageList[i].geoScope, pageList[i].msgCode);
487 if (pageList[i].msgId == CbPage.pageHeader.msgId)
489 int updateNum = CbPage.pageHeader.serialNum.updateNum - pageList[i].updateNum;
491 if (updateNum > 0) // New Message Content
495 else if (updateNum == 0) // Same Message Content
497 if (pageList[i].data.count(CbPage.pageHeader.page) != 0)
499 MSG_DEBUG("The Page Number already exists [%d]", CbPage.pageHeader.page);
503 pair<unsigned char, string> newData(CbPage.pageHeader.page, CbPage.pageData);
504 pageList[i].data.insert(newData);
506 MSG_DEBUG("PAGE DATA : %s", CbPage.pageData);
507 MSG_DEBUG("PAIR DATA [%d] : %s", newData.first, newData.second.c_str());
509 pageList[i].pageCnt++;
510 pageList[i].totalSize += CbPage.pageLength;
512 currPageCnt = pageList[i].pageCnt;
518 else // Old Message Content
527 if (bFind == false || CbPage.pageHeader.totalPages == 1)
529 addToPageLiat(CbPage);
537 void SmsPluginCbMsgHandler::MakeCbMsg(SMS_CBMSG_PAGE_S CbPage, SMS_CBMSG_S *pCbMsg)
539 pCbMsg->cbMsgType = CbPage.cbMsgType;
540 pCbMsg->msgId = CbPage.pageHeader.msgId;
541 pCbMsg->classType = CbPage.pageHeader.dcs.classType;
542 pCbMsg->codingScheme = CbPage.pageHeader.dcs.codingScheme;
543 pCbMsg->recvTime = CbPage.pageHeader.recvTime;
545 cbPageMap::iterator it;
548 for (unsigned int i = 0; i < pageList.size(); i++)
550 if (pageList[i].geoScope == CbPage.pageHeader.serialNum.geoScope && pageList[i].msgCode == CbPage.pageHeader.serialNum.msgCode)
552 MSG_DEBUG("geoScope [%d], msgCode [%d]", pageList[i].geoScope, pageList[i].msgCode);
554 if (pageList[i].msgId == CbPage.pageHeader.msgId)
556 for (it = pageList[i].data.begin(); it != pageList[i].data.end(); it++)
558 tmpStr += it->second;
564 pCbMsg->msgLength = tmpStr.size();
566 memcpy(pCbMsg->msgData, tmpStr.c_str(), tmpStr.size());
567 pCbMsg->msgData[tmpStr.size()] = '\0';
569 MSG_DEBUG("SIZE : [%d] TOTAL MSG : %s", tmpStr.size(), tmpStr.c_str());
573 void SmsPluginCbMsgHandler::convertCbMsgToMsginfo(SMS_CBMSG_S *pCbMsg, MSG_MESSAGE_INFO_S *pMsgInfo)
575 pMsgInfo->msgId = (msg_message_id_t)pCbMsg->msgId;
577 pMsgInfo->folderId = MSG_CBMSGBOX_ID;
579 // Convert Type values
580 pMsgInfo->msgType.mainType = MSG_SMS_TYPE;
582 if (pCbMsg->cbMsgType == SMS_CBMSG_TYPE_CBS)
583 pMsgInfo->msgType.subType = MSG_CB_SMS;
584 else if (pCbMsg->cbMsgType == SMS_CBMSG_TYPE_JAVACBS)
585 pMsgInfo->msgType.subType = MSG_JAVACB_SMS;
587 switch(pCbMsg->classType)
589 case SMS_MSG_CLASS_0:
590 pMsgInfo->msgType.classType = MSG_CLASS_0;
592 case SMS_MSG_CLASS_1:
593 pMsgInfo->msgType.classType = MSG_CLASS_1;
595 case SMS_MSG_CLASS_2:
596 pMsgInfo->msgType.classType = MSG_CLASS_2;
598 case SMS_MSG_CLASS_3:
599 pMsgInfo->msgType.classType = MSG_CLASS_3;
602 pMsgInfo->msgType.classType = MSG_CLASS_NONE;
606 pMsgInfo->storageId = MSG_STORAGE_PHONE;
607 pMsgInfo->networkStatus = MSG_NETWORK_RECEIVED;
608 pMsgInfo->bRead = false;
609 pMsgInfo->bProtected = false;
610 pMsgInfo->priority = MSG_MESSAGE_PRIORITY_NORMAL;
611 pMsgInfo->direction = MSG_DIRECTION_TYPE_MT;
614 pMsgInfo->nAddressCnt = 1;
616 pMsgInfo->addressList[0].addressType = MSG_ADDRESS_TYPE_UNKNOWN;
617 pMsgInfo->addressList[0].recipientType = MSG_RECIPIENTS_TYPE_UNKNOWN;
619 getDisplayName(pCbMsg->msgId, pMsgInfo->addressList[0].addressVal);
620 MSG_DEBUG("%s", pMsgInfo->addressList[0].addressVal);
622 pMsgInfo->msgPort.valid = false;
623 pMsgInfo->msgPort.dstPort = 0;
624 pMsgInfo->msgPort.srcPort = 0;
626 pMsgInfo->displayTime = pCbMsg->recvTime;
627 MSG_DEBUG("recvTime is %s", ctime(&pMsgInfo->displayTime));
629 int bufSize = pCbMsg->msgLength*2;
631 char tmpBuf[bufSize];
632 memset(tmpBuf, 0x00, sizeof(tmpBuf));
634 MSG_DEBUG("LENGTH %d CB MSG %s", pCbMsg->msgLength, pCbMsg->msgData);
636 // Convert Data values
637 pMsgInfo->dataSize = convertTextToUtf8((unsigned char*)tmpBuf, bufSize, pCbMsg);
639 if (pMsgInfo->dataSize > MAX_MSG_TEXT_LEN)
641 pMsgInfo->bTextSms = false;
643 // Save Message Data into File
644 char fileName[MSG_FILENAME_LEN_MAX+1];
645 memset(fileName, 0x00, sizeof(fileName));
647 if (MsgCreateFileName(fileName) == false)
648 THROW(MsgException::FILE_ERROR, "MsgCreateFileName error");
650 MSG_DEBUG("Save Message Data into file : size[%d] name[%s]\n", pMsgInfo->dataSize, fileName);
651 if (MsgWriteIpcFile(fileName, tmpBuf, pMsgInfo->dataSize) == false)
652 THROW(MsgException::FILE_ERROR, "MsgWriteIpcFile error");
654 strncpy(pMsgInfo->msgData, fileName, MAX_MSG_DATA_LEN);
658 pMsgInfo->bTextSms = true;
660 memset(pMsgInfo->msgText, 0x00, sizeof(pMsgInfo->msgText));
661 memcpy(pMsgInfo->msgText, tmpBuf, pMsgInfo->dataSize);
666 void SmsPluginCbMsgHandler::convertEtwsMsgToMsginfo(SMS_CBMSG_PAGE_S EtwsMsg, MSG_MESSAGE_INFO_S *pMsgInfo)
668 pMsgInfo->msgId = (msg_message_id_t)EtwsMsg.pageHeader.msgId;
670 pMsgInfo->folderId = MSG_CBMSGBOX_ID;
672 // Convert Type values
673 pMsgInfo->msgType.mainType = MSG_SMS_TYPE;
675 if (EtwsMsg.cbMsgType == SMS_CBMSG_TYPE_ETWS)
676 pMsgInfo->msgType.subType = MSG_ETWS_SMS;
678 pMsgInfo->storageId = MSG_STORAGE_PHONE;
679 pMsgInfo->networkStatus = MSG_NETWORK_RECEIVED;
680 pMsgInfo->bRead = false;
681 pMsgInfo->bProtected = false;
682 pMsgInfo->priority = MSG_MESSAGE_PRIORITY_NORMAL;
683 pMsgInfo->direction = MSG_DIRECTION_TYPE_MT;
686 pMsgInfo->nAddressCnt = 1;
688 pMsgInfo->addressList[0].addressType = MSG_ADDRESS_TYPE_UNKNOWN;
689 pMsgInfo->addressList[0].recipientType = MSG_RECIPIENTS_TYPE_UNKNOWN;
691 getDisplayName(EtwsMsg.pageHeader.msgId, pMsgInfo->addressList[0].addressVal);
692 MSG_DEBUG("%s", pMsgInfo->addressList[0].addressVal);
694 pMsgInfo->msgPort.valid = false;
695 pMsgInfo->msgPort.dstPort = 0;
696 pMsgInfo->msgPort.srcPort = 0;
698 pMsgInfo->displayTime = EtwsMsg.pageHeader.recvTime;
699 MSG_DEBUG("recvTime is %s", ctime(&pMsgInfo->displayTime));
700 MSG_DEBUG("LENGTH %d", EtwsMsg.pageLength);
701 pMsgInfo->bTextSms = true;
702 pMsgInfo->dataSize = EtwsMsg.pageLength;
703 memset(pMsgInfo->msgData, 0x00, sizeof(pMsgInfo->msgData));
704 memcpy(pMsgInfo->msgData, EtwsMsg.pageData, pMsgInfo->dataSize);
707 int SmsPluginCbMsgHandler::convertTextToUtf8 (unsigned char* outBuf, int outBufSize, SMS_CBMSG_S* pCbMsg)
709 int convertedTextSize = 0;
710 MSG_LANG_INFO_S langInfo = {0,};
712 if (!outBuf || !pCbMsg)
714 MSG_DEBUG ("invalid param.\n");
718 langInfo.bSingleShift = false;
719 langInfo.bLockingShift = false;
722 // Convert Data values
723 if (pCbMsg->codingScheme == SMS_CHARSET_7BIT)
724 convertedTextSize = textCvt.convertGSM7bitToUTF8(outBuf, outBufSize, (unsigned char*)pCbMsg->msgData, pCbMsg->msgLength, &langInfo);
725 else if (pCbMsg->codingScheme == SMS_CHARSET_UCS2)
726 convertedTextSize = textCvt.convertUCS2ToUTF8(outBuf, outBufSize, (unsigned char*)pCbMsg->msgData, pCbMsg->msgLength);
728 return convertedTextSize;
731 void SmsPluginCbMsgHandler::addToPageLiat(SMS_CBMSG_PAGE_S CbPage)
733 CB_PAGE_INFO_S tmpInfo;
735 tmpInfo.geoScope = CbPage.pageHeader.serialNum.geoScope;
736 tmpInfo.msgCode = CbPage.pageHeader.serialNum.msgCode;
737 tmpInfo.updateNum = CbPage.pageHeader.serialNum.updateNum;
738 tmpInfo.msgId = CbPage.pageHeader.msgId;
739 tmpInfo.totalPages = CbPage.pageHeader.totalPages;
742 tmpInfo.totalSize = CbPage.pageLength;
744 pair<unsigned char, string> newData(CbPage.pageHeader.page, CbPage.pageData);
745 tmpInfo.data.insert(newData);
747 MSG_DEBUG("MSG DATA : %s", CbPage.pageData);
748 MSG_DEBUG("PAIR DATA [%d] : %s", newData.first, newData.second.c_str());
750 pageList.push_back(tmpInfo);
754 void SmsPluginCbMsgHandler::removeFromPageList(SMS_CBMSG_PAGE_S CbPage)
758 for (index = 0; index < pageList.size(); index++)
760 if (pageList[index].geoScope == CbPage.pageHeader.serialNum.geoScope && pageList[index].msgCode == CbPage.pageHeader.serialNum.msgCode)
762 MSG_DEBUG("geoScope [%d], msgCode [%d]", pageList[index].geoScope, pageList[index].msgCode);
764 if (pageList[index].msgId == CbPage.pageHeader.msgId) break;
768 MSG_DEBUG("remove index [%d]", index);
770 pageList.erase(pageList.begin()+index);
774 void SmsPluginCbMsgHandler::decodeCbMsgDCS(unsigned char dcsData, const unsigned char *pMsgData, SMS_CBMSG_DCS_S* pDcs)
776 pDcs->codingGroup = SMS_CBMSG_CODGRP_GENERAL_DCS;
777 pDcs->classType = SMS_MSG_CLASS_NONE;
778 pDcs->bCompressed = false;
779 pDcs->codingScheme = SMS_CHARSET_7BIT;
780 pDcs->langType = SMS_CBMSG_LANG_UNSPECIFIED;
781 memset(pDcs->iso639Lang, 0x00, sizeof(pDcs->iso639Lang));
783 pDcs->rawData = dcsData;
785 unsigned char codingGrp = (dcsData & 0xF0) >> 4;
793 pDcs->codingGroup = SMS_CBMSG_CODGRP_GENERAL_DCS;
794 pDcs->langType = (SMS_CBMSG_LANG_TYPE_T)dcsData;
800 if (dcsData == 0x10 || dcsData == 0x11)
802 pDcs->codingGroup = SMS_CBMSG_CODGRP_GENERAL_DCS;
803 pDcs->codingScheme = (dcsData & 0x01) ? SMS_CHARSET_UCS2 : SMS_CHARSET_7BIT;
804 pDcs->langType = SMS_CBMSG_LANG_ISO639;
806 if (pMsgData != NULL)
808 pDcs->iso639Lang[0] = pMsgData[0] & 0x7F;
809 pDcs->iso639Lang[1] = (pMsgData[0] & 0x80) >> 7;
810 pDcs->iso639Lang[1] |= (pMsgData[1] & 0x3F) << 1;
811 pDcs->iso639Lang[2] = 0x13; /* CR char in GSM 7-bit Alphabet */
815 /* Default it to English if pMsgData is NULL */
816 pDcs->iso639Lang[0] = 0x45; /* E */
817 pDcs->iso639Lang[1] = 0x4E; /* N */
818 pDcs->iso639Lang[2] = 0x13; /* CR */
829 pDcs->codingGroup = SMS_CBMSG_CODGRP_GENERAL_DCS;
831 pDcs->bCompressed = (dcsData & 0x20) ? true : false;
834 pDcs->classType = (SMS_MSG_CLASS_T)(dcsData & 0x03);
836 pDcs->codingScheme = (SMS_CODING_SCHEME_T)(dcsData & 0x0C);
848 pDcs->codingGroup = SMS_CBMSG_CODGRP_WAP;
854 pDcs->codingGroup = SMS_CBMSG_CODGRP_CLASS_CODING;
855 pDcs->codingScheme = (dcsData & 0x04) ? SMS_CHARSET_UCS2 : SMS_CHARSET_7BIT;
856 pDcs->classType = (MSG_CLASS_TYPE_T)(dcsData & 0x03);
863 void SmsPluginCbMsgHandler::convertLangType(SMS_CBMSG_LANG_TYPE_T InType , MSG_CB_LANGUAGE_TYPE_T *pOutType)
867 case SMS_CBMSG_LANG_GERMAN :
868 *pOutType = MSG_CBLANG_TYPE_GER;
871 case SMS_CBMSG_LANG_ENGLISH :
872 *pOutType = MSG_CBLANG_TYPE_ENG;
875 case SMS_CBMSG_LANG_ITALIAN :
876 *pOutType = MSG_CBLANG_TYPE_ITA;
879 case SMS_CBMSG_LANG_FRENCH :
880 *pOutType = MSG_CBLANG_TYPE_FRE;
883 case SMS_CBMSG_LANG_SPANISH :
884 *pOutType = MSG_CBLANG_TYPE_SPA;
887 case SMS_CBMSG_LANG_DUTCH :
888 *pOutType = MSG_CBLANG_TYPE_NED;
891 case SMS_CBMSG_LANG_SWEDISH :
892 *pOutType = MSG_CBLANG_TYPE_SWE;
895 case SMS_CBMSG_LANG_PORTUGUESE :
896 *pOutType = MSG_CBLANG_TYPE_POR;
899 case SMS_CBMSG_LANG_TURKISH :
900 *pOutType = MSG_CBLANG_TYPE_TUR;
904 *pOutType = MSG_CBLANG_TYPE_MAX;
910 unsigned long SmsPluginCbMsgHandler::getRecvTime()
914 recvTime = time(NULL);
916 return (unsigned long)recvTime;
920 void SmsPluginCbMsgHandler::getDisplayName(unsigned short MsgId, char *pDisplayName)
922 int MsgIdCnt = MsgSettingGetInt(CB_CHANNEL_COUNT);
927 for (int i = 0; i < MsgIdCnt; i++)
929 memset(from, 0x00, sizeof(from));
930 sprintf(from, "%s/%d", CB_CHANNEL_ID_FROM, i);
932 memset(to, 0x00, sizeof(to));
933 sprintf(to, "%s/%d", CB_CHANNEL_ID_TO, i);
935 if (MsgId >= MsgSettingGetInt(from) && MsgId <= MsgSettingGetInt(to))
937 MSG_DEBUG("FIND MSG ID = [%d]", MsgId);
939 memset(keyName, 0x00, sizeof(keyName));
940 sprintf(keyName, "%s/%d", CB_CHANNEL_NAME, i);
942 memset(strTmp, 0x00, sizeof(strTmp));
944 channelName = MsgSettingGetString(keyName);
946 strncpy(strTmp, channelName, CB_CHANNEL_NAME_MAX);
953 if (strlen(strTmp) > 0)
954 sprintf(pDisplayName, "[%s]", strTmp);
956 sprintf(pDisplayName, "[%d]", MsgId);
958 sprintf(pDisplayName, "[%d]", MsgId);
965 sprintf(pDisplayName, "[%d]", MsgId);