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.
20 #include "MsgCppTypes.h"
21 #include "MsgException.h"
22 #include "MsgGconfWrapper.h"
23 #include "MsgUtilFile.h"
24 #include "SmsPluginTextConvert.h"
25 #include "SmsPluginUDCodec.h"
26 #include "SmsPluginStorage.h"
27 #include "SmsPluginEventHandler.h"
28 #include "SmsPluginCbMsgHandler.h"
31 /*==================================================================================================
32 IMPLEMENTATION OF SmsPluginCbMsgHandler - Member Functions
33 ==================================================================================================*/
34 SmsPluginCbMsgHandler* SmsPluginCbMsgHandler::pInstance = NULL;
37 SmsPluginCbMsgHandler::SmsPluginCbMsgHandler()
43 SmsPluginCbMsgHandler::~SmsPluginCbMsgHandler()
49 SmsPluginCbMsgHandler* SmsPluginCbMsgHandler::instance()
52 pInstance = new SmsPluginCbMsgHandler();
58 void SmsPluginCbMsgHandler::handleCbMsg(TelSmsCbMsg_t *pCbMsg)
62 SMS_CB_NETWORK_TYPE_T type = pCbMsg->CbMsgType;
64 SMS_CBMSG_PAGE_S CbMsgPage = {0};
68 case SMS_CB_NETWORK_TYPE_2G_GSM :
69 Decode2gCbMsg(pCbMsg, &CbMsgPage);
72 case SMS_CB_NETWORK_TYPE_3G_UMTS :
73 Decode3gCbMsg(pCbMsg, &CbMsgPage);
77 // Check CB Msg Options
78 bool bJavaMsg = false;
80 if (!checkCbOpt(CbMsgPage, &bJavaMsg))
82 MSG_DEBUG("The CB Msg is not supported by option.");
88 MSG_DEBUG("JAVA CB Msg.");
89 CbMsgPage.cbMsgType = SMS_CBMSG_TYPE_JAVACBS;
93 unsigned char pageCnt = checkCbPage(CbMsgPage);
95 if (pageCnt == CbMsgPage.pageHeader.totalPages)
97 MSG_DEBUG("RECEIVED LAST MSG : %d", pageCnt);
99 SMS_CBMSG_S cbMsg = {};
100 MSG_MESSAGE_INFO_S msgInfo = {};
102 // Make CB Msg Structure
103 MakeCbMsg(CbMsgPage, &cbMsg);
105 // Convert to MSG_MESSAGE_INFO_S
106 convertCbMsgToMsginfo(cbMsg, &msgInfo);
108 // Add CB Msg into DB
109 msg_error_t err = MSG_SUCCESS;
111 err = SmsPluginStorage::instance()->addMessage(&msgInfo);
113 if (err == MSG_SUCCESS)
115 MSG_CB_MSG_S cbOutMsg = {0, };
117 cbOutMsg.type = MSG_CB_SMS;
118 cbOutMsg.receivedTime = cbMsg.recvTime;
119 cbOutMsg.serialNum = encodeCbSerialNum (CbMsgPage.pageHeader.serialNum);
120 cbOutMsg.messageId = cbMsg.msgId;
121 cbOutMsg.dcs = CbMsgPage.pageHeader.dcs.rawData;
122 memset (cbOutMsg.cbText, 0x00, sizeof(cbOutMsg.cbText));
124 SMS_LANG_INFO_S langInfo = {0};
126 langInfo.bSingleShift = false;
127 langInfo.bLockingShift = false;
129 if (cbMsg.codingScheme == SMS_CHARSET_7BIT)
130 cbOutMsg.cbTextLen = SmsPluginTextConvert::instance()->convertGSM7bitToUTF8((unsigned char*)cbOutMsg.cbText, sizeof(cbOutMsg.cbText), (unsigned char*)cbMsg.msgData, cbMsg.msgLength, &langInfo);
131 else if (cbMsg.codingScheme == SMS_CHARSET_UCS2)
132 cbOutMsg.cbTextLen = SmsPluginTextConvert::instance()->convertUCS2ToUTF8((unsigned char*)cbOutMsg.cbText, sizeof(cbOutMsg.cbText), (unsigned char*)cbMsg.msgData, cbMsg.msgLength);
135 err = SmsPluginEventHandler::instance()->callbackCBMsgIncoming(&cbOutMsg);
136 if (err != MSG_SUCCESS)
138 MSG_DEBUG("callbackMsgIncoming() Error !! [%d]", err);
143 MSG_DEBUG("addMessage() Error !! [%d]", err);
147 removeFromPageList(CbMsgPage);
153 void SmsPluginCbMsgHandler::handleEtwsMsg(TelSmsEtwsMsg_t *pEtwsMsg)
156 msg_error_t err = MSG_SUCCESS;
157 SMS_ETWS_NETWORK_TYPE_T type = pEtwsMsg->EtwsMsgType;
158 //MSG_MESSAGE_INFO_S msgInfo = {};
159 SMS_ETWS_PRIMARY_S etwsPn = {0, };
160 MSG_CB_MSG_S cbOutMsg = {0, };
162 if(type != TAPI_NETTEXT_ETWS_PRIMARY)
164 MSG_DEBUG("The Etws Msg is not supported");
167 DecodeEtwsMsg(pEtwsMsg, &etwsPn);
168 //convertEtwsMsgToMsginfo(CbMsgPage, &msgInfo);
170 cbOutMsg.type = MSG_ETWS_SMS;
171 cbOutMsg.receivedTime = etwsPn.recvTime;
172 cbOutMsg.serialNum = encodeCbSerialNum (etwsPn.serialNum);
173 cbOutMsg.messageId = etwsPn.msgId;
174 cbOutMsg.etwsWarningType = etwsPn.warningType;
175 memcpy (cbOutMsg.etwsWarningSecurityInfo, etwsPn.warningSecurityInfo, sizeof(cbOutMsg.etwsWarningSecurityInfo));
177 err = SmsPluginEventHandler::instance()->callbackCBMsgIncoming(&cbOutMsg);
178 if (err != MSG_SUCCESS)
180 MSG_DEBUG("callbackMsgIncoming() Error !! [%d]", err);
187 void SmsPluginCbMsgHandler::Decode2gCbMsg(TelSmsCbMsg_t *pCbMsg, SMS_CBMSG_PAGE_S *pCbPage)
189 if (pCbMsg->Length > MAX_CBMSG_PAGE_SIZE)
190 THROW(MsgException::SMS_PLG_ERROR, "CB Msg Size is over MAX [%d]", pCbMsg->Length);
192 unsigned char cbData[pCbMsg->Length+1];
194 memset(cbData, 0x00, sizeof(cbData));
195 memcpy(cbData, pCbMsg->szMsgData, pCbMsg->Length);
196 cbData[pCbMsg->Length] = '\0';
198 pCbPage->cbMsgType = SMS_CBMSG_TYPE_CBS;
201 pCbPage->pageHeader.serialNum.geoScope = (cbData[0] & 0xC0) >> 6;
203 pCbPage->pageHeader.serialNum.msgCode = (cbData[0] & 0x3F) << 4;
204 pCbPage->pageHeader.serialNum.msgCode |= (cbData[1] & 0xF0) >> 4;
206 pCbPage->pageHeader.serialNum.updateNum = cbData[1] & 0x0F;
208 MSG_DEBUG("geoScope : [%d], msgCode : [%d], updateNum : [%d]", pCbPage->pageHeader.serialNum.geoScope, pCbPage->pageHeader.serialNum.msgCode, pCbPage->pageHeader.serialNum.updateNum);
210 pCbPage->pageHeader.msgId = (cbData[2] << 8) | cbData[3];
212 MSG_DEBUG("MSG ID : [%d]", pCbPage->pageHeader.msgId);
215 decodeCbMsgDCS(cbData[4], (unsigned char*)cbData[6], &(pCbPage->pageHeader.dcs));
218 pCbPage->pageHeader.totalPages = cbData[5] & 0x0F;
219 pCbPage->pageHeader.page = (cbData[5] & 0xF0) >> 4;
221 if (pCbPage->pageHeader.totalPages > MAX_CBMSG_PAGE_NUM)
222 THROW(MsgException::SMS_PLG_ERROR, "CB Page Count is over MAX[%d]", pCbPage->pageHeader.totalPages);
224 MSG_DEBUG("Total Page : [%d], Page : [%d]", pCbPage->pageHeader.totalPages, pCbPage->pageHeader.page);
226 // Convert Language Type
227 convertLangType(pCbPage->pageHeader.dcs.langType, &(pCbPage->pageHeader.langType));
229 MSG_DEBUG("In Language Type : [%d], Out Language Type : [%d]", pCbPage->pageHeader.dcs.langType, pCbPage->pageHeader.langType);
232 pCbPage->pageHeader.recvTime = getRecvTime();
235 int dataLen = pCbMsg->Length - 6;
237 switch (pCbPage->pageHeader.dcs.codingScheme)
239 case SMS_CHARSET_7BIT :
241 MSG_DEBUG("GSM 7 BIT");
243 dataLen = (dataLen*8) / 7;
245 SmsPluginUDCodec udCodec;
246 int unpackLen = udCodec.unpack7bitChar(&cbData[6], dataLen, 0, pCbPage->pageData);
248 MSG_DEBUG("dataLen : [%d]", dataLen);
249 MSG_DEBUG("unpackLen : [%d]", unpackLen);
251 pCbPage->pageLength = unpackLen;
252 pCbPage->pageData[unpackLen] = '\0';
254 // pCbPage->pageLength = strlen(pCbPage->pageData);
255 // pCbPage->pageData[pCbPage->pageLength] = '\0';
259 case SMS_CHARSET_8BIT :
260 case SMS_CHARSET_UCS2 :
264 memcpy(pCbPage->pageData, &cbData[6], dataLen);
266 pCbPage->pageLength = strlen(pCbPage->pageData);
268 pCbPage->pageData[pCbPage->pageLength] = '\0';
273 MSG_DEBUG("Page Length : [%d], Page Data : [%s]", pCbPage->pageLength, pCbPage->pageData);
277 void SmsPluginCbMsgHandler::DecodeEtwsMsg(TelSmsEtwsMsg_t *pEtwsMsg, SMS_ETWS_PRIMARY_S *pEtwsPn)
279 if ( !pEtwsMsg || !pEtwsPn )
282 if (pEtwsMsg->Length > MAX_ETWS_SIZE)
283 THROW(MsgException::SMS_PLG_ERROR, "ETWS Msg Size is over MAX [%d]", pEtwsMsg->Length);
285 unsigned char EtwsData[pEtwsMsg->Length+1];
287 memset(EtwsData, 0x00, sizeof(EtwsData));
288 memcpy(EtwsData, pEtwsMsg->szMsgData, pEtwsMsg->Length);
289 EtwsData[pEtwsMsg->Length] = '\0';
292 pEtwsPn->recvTime = getRecvTime();
295 pEtwsPn->serialNum.geoScope = (EtwsData[0] & 0xC0) >> 6;
296 pEtwsPn->serialNum.msgCode = (EtwsData[0] & 0x3F) << 4;
297 pEtwsPn->serialNum.msgCode |= (EtwsData[1] & 0xF0) >> 4;
298 pEtwsPn->serialNum.updateNum = EtwsData[1] & 0x0F;
300 MSG_DEBUG("geoScope : [%d], msgCode : [%d], updateNum : [%d]", pEtwsPn->serialNum.geoScope, pEtwsPn->serialNum.msgCode, pEtwsPn->serialNum.updateNum);
302 // Message Identifier
303 pEtwsPn->msgId = (EtwsData[2] << 8) | EtwsData[3];
304 MSG_DEBUG("MSG ID : [%d]", pEtwsPn->msgId);
307 pEtwsPn->warningType = (EtwsData[4] << 8) | EtwsData[5];
308 MSG_DEBUG("warningType : [0x%04x]", pEtwsPn->msgId);
310 // warning security information
311 memcpy(pEtwsPn->warningSecurityInfo, &EtwsData[6], sizeof(pEtwsPn->warningSecurityInfo)); // 50bytes
312 for (unsigned int i = 0; i < sizeof(pEtwsPn->warningSecurityInfo); i++)
314 MSG_DEBUG("warning secu info [%02x]", pEtwsPn->warningSecurityInfo[i] );
318 void SmsPluginCbMsgHandler::Decode3gCbMsg(TelSmsCbMsg_t *pCbMsg, SMS_CBMSG_PAGE_S *pCbPage)
320 if (pCbMsg->Length > (MAX_CBMSG_PAGE_SIZE*MAX_CBMSG_PAGE_NUM))
321 THROW(MsgException::SMS_PLG_ERROR, "CB Msg Size is over MAX [%d]", pCbMsg->Length);
323 char cbData[(MAX_CBMSG_PAGE_SIZE*MAX_CBMSG_PAGE_NUM)+1];
325 memset(cbData, 0x00, sizeof(cbData));
326 memcpy(cbData, pCbMsg->szMsgData, pCbMsg->Length);
327 cbData[pCbMsg->Length] = '\0';
329 pCbPage->cbMsgType = (SMS_CBMSG_TYPE_T)cbData[0];
331 pCbPage->pageHeader.msgId = (cbData[1] << 8) | cbData[2];
333 MSG_DEBUG("MSG ID : [%d]", pCbPage->pageHeader.msgId);
336 pCbPage->pageHeader.serialNum.geoScope = (cbData[3] & 0xC0) >> 6;
338 pCbPage->pageHeader.serialNum.msgCode = (cbData[3] & 0x3F) << 4;
339 pCbPage->pageHeader.serialNum.msgCode |= (cbData[4] & 0xF0) >> 4;
341 pCbPage->pageHeader.serialNum.updateNum = cbData[4] & 0x0F;
343 MSG_DEBUG("geoScope : [%d], msgCode : [%d], updateNum : [%d]", pCbPage->pageHeader.serialNum.geoScope, pCbPage->pageHeader.serialNum.msgCode, pCbPage->pageHeader.serialNum.updateNum);
346 decodeCbMsgDCS(cbData[5], (unsigned char*)cbData[6], &(pCbPage->pageHeader.dcs));
348 // Convert Language Type
349 convertLangType(pCbPage->pageHeader.dcs.langType, &(pCbPage->pageHeader.langType));
351 MSG_DEBUG("In Language Type : [%d], Out Language Type : [%d]", pCbPage->pageHeader.dcs.langType, pCbPage->pageHeader.langType);
354 pCbPage->pageHeader.recvTime = getRecvTime();
358 int dataLen = pCbMsg->Length - 6;
360 switch (pCbPage->pageHeader.dcs.codingScheme)
362 case SMS_CHARSET_7BIT :
364 dataLen = (dataLen*8) / 7;
366 if (pCbPage->pageLength > MAX_CBMSG_PAGE_SIZE)
367 THROW(MsgException::SMS_PLG_ERROR, "CB Msg Size is over MAX [%d]", pCbPage->pageLength);
369 SmsPluginUDCodec udCodec;
370 int unpackLen = udCodec.unpack7bitChar(&cbData[6], dataLen, 0, pCbPage->pageData);
371 pCbPage->pageData[unpackLen] = '\0';
373 pCbPage->pageLength = unpackLen;
377 case SMS_CHARSET_8BIT :
378 case SMS_CHARSET_UCS2 :
380 pCbPage->pageLength = dataLen;
382 memcpy(pCbPage->pageData, &cbData[6], pCbPage->pageLength);
383 pCbPage->pageData[pCbPage->pageLength] = '\0';
388 MSG_DEBUG("Page Length : [%d], Page Data : [%s]", pCbPage->pageLength, pCbPage->pageData);
392 unsigned short SmsPluginCbMsgHandler::encodeCbSerialNum ( SMS_CBMSG_SERIAL_NUM_S snFields )
394 unsigned short serialNum = 0;
396 serialNum = ((snFields.geoScope & 0x03) << 14) | ((snFields.msgCode&0x03FF) << 4) | (snFields.updateNum&0x0F);
397 MSG_DEBUG ("serialNum (%x), geo(%x), mc(%x), un(%x)\n", serialNum, snFields.geoScope, snFields.msgCode, snFields.updateNum);
402 bool SmsPluginCbMsgHandler::checkCbOpt(SMS_CBMSG_PAGE_S CbPage, bool *pJavaMsg)
404 bool bReceive = false;
405 MsgSettingGetBool(CB_RECEIVE, &bReceive);
407 // Receive CB Msg = FALSE
410 MSG_DEBUG("RECEIVE CB = FALSE");
417 memset(keyName, 0x00, sizeof(keyName));
418 sprintf(keyName, "%s/%d", CB_LANGUAGE, MSG_CBLANG_TYPE_ALL);
420 bool bAllLang = false;
421 MsgSettingGetBool(keyName, &bAllLang);
425 MSG_DEBUG("ALL LANGUAGE = FALSE");
427 memset(keyName, 0x00, sizeof(keyName));
428 sprintf(keyName, "%s/%d", CB_LANGUAGE, CbPage.pageHeader.langType);
432 MsgSettingGetBool(keyName, &bLang);
434 if (!bLang || CbPage.pageHeader.langType == MSG_CBLANG_TYPE_MAX)
436 MSG_DEBUG("LANGUAGE [%d] = FALSE", CbPage.pageHeader.langType);
441 int MsgIdCnt = MsgSettingGetInt(CB_CHANNEL_COUNT);
443 bool bActivate = false;
444 int MsgId_from = 0, MsgId_to = 0;
446 for (int i = 0; i < MsgIdCnt; i++)
448 memset(keyName, 0x00, sizeof(keyName));
449 sprintf(keyName, "%s/%d", CB_CHANNEL_ACTIVATE, i);
451 MsgSettingGetBool(keyName, &bActivate);
453 memset(keyName, 0x00, sizeof(keyName));
454 sprintf(keyName, "%s/%d", CB_CHANNEL_ID_FROM, i);
456 MsgId_from = MsgSettingGetInt(keyName);
458 memset(keyName, 0x00, sizeof(keyName));
459 sprintf(keyName, "%s/%d", CB_CHANNEL_ID_TO, i);
461 MsgId_to = MsgSettingGetInt(keyName);
463 if (bActivate == true && CbPage.pageHeader.msgId >= MsgId_from && CbPage.pageHeader.msgId <= MsgId_to)
465 MSG_DEBUG("FIND CHANNEL = [%d]", CbPage.pageHeader.msgId);
474 unsigned char SmsPluginCbMsgHandler::checkCbPage(SMS_CBMSG_PAGE_S CbPage)
476 unsigned char currPageCnt = 0;
480 if (CbPage.pageHeader.totalPages > 1)
482 for (unsigned int i = 0; i < pageList.size(); i++)
484 if (pageList[i].geoScope == CbPage.pageHeader.serialNum.geoScope && pageList[i].msgCode == CbPage.pageHeader.serialNum.msgCode)
486 MSG_DEBUG("geoScope [%d], msgCode [%d]", pageList[i].geoScope, pageList[i].msgCode);
488 if (pageList[i].msgId == CbPage.pageHeader.msgId)
490 int updateNum = CbPage.pageHeader.serialNum.updateNum - pageList[i].updateNum;
492 if (updateNum > 0) // New Message Content
496 else if (updateNum == 0) // Same Message Content
498 if (pageList[i].data.count(CbPage.pageHeader.page) != 0)
500 MSG_DEBUG("The Page Number already exists [%d]", CbPage.pageHeader.page);
504 pair<unsigned char, string> newData(CbPage.pageHeader.page, CbPage.pageData);
505 pageList[i].data.insert(newData);
507 MSG_DEBUG("PAGE DATA : %s", CbPage.pageData);
508 MSG_DEBUG("PAIR DATA [%d] : %s", newData.first, newData.second.c_str());
510 pageList[i].pageCnt++;
511 pageList[i].totalSize += CbPage.pageLength;
513 currPageCnt = pageList[i].pageCnt;
519 else // Old Message Content
528 if (bFind == false || CbPage.pageHeader.totalPages == 1)
530 addToPageLiat(CbPage);
538 void SmsPluginCbMsgHandler::MakeCbMsg(SMS_CBMSG_PAGE_S CbPage, SMS_CBMSG_S *pCbMsg)
540 pCbMsg->cbMsgType = CbPage.cbMsgType;
541 pCbMsg->msgId = CbPage.pageHeader.msgId;
542 pCbMsg->classType = CbPage.pageHeader.dcs.classType;
543 pCbMsg->codingScheme = CbPage.pageHeader.dcs.codingScheme;
544 pCbMsg->recvTime = CbPage.pageHeader.recvTime;
546 cbPageMap::iterator it;
549 for (unsigned int i = 0; i < pageList.size(); i++)
551 if (pageList[i].geoScope == CbPage.pageHeader.serialNum.geoScope && pageList[i].msgCode == CbPage.pageHeader.serialNum.msgCode)
553 MSG_DEBUG("geoScope [%d], msgCode [%d]", pageList[i].geoScope, pageList[i].msgCode);
555 if (pageList[i].msgId == CbPage.pageHeader.msgId)
557 for (it = pageList[i].data.begin(); it != pageList[i].data.end(); it++)
559 tmpStr += it->second;
565 pCbMsg->msgLength = tmpStr.size();
567 memcpy(pCbMsg->msgData, tmpStr.c_str(), tmpStr.size());
568 pCbMsg->msgData[tmpStr.size()] = '\0';
570 MSG_DEBUG("SIZE : [%d] TOTAL MSG : %s", tmpStr.size(), tmpStr.c_str());
574 void SmsPluginCbMsgHandler::convertCbMsgToMsginfo(SMS_CBMSG_S cbMsg, MSG_MESSAGE_INFO_S *pMsgInfo)
576 pMsgInfo->msgId = (msg_message_id_t)cbMsg.msgId;
578 pMsgInfo->folderId = MSG_CBMSGBOX_ID;
580 // Convert Type values
581 pMsgInfo->msgType.mainType = MSG_SMS_TYPE;
583 if (cbMsg.cbMsgType == SMS_CBMSG_TYPE_CBS)
584 pMsgInfo->msgType.subType = MSG_CB_SMS;
585 else if (cbMsg.cbMsgType == SMS_CBMSG_TYPE_JAVACBS)
586 pMsgInfo->msgType.subType = MSG_JAVACB_SMS;
588 switch(cbMsg.classType)
590 case SMS_MSG_CLASS_0:
591 pMsgInfo->msgType.classType = MSG_CLASS_0;
593 case SMS_MSG_CLASS_1:
594 pMsgInfo->msgType.classType = MSG_CLASS_1;
596 case SMS_MSG_CLASS_2:
597 pMsgInfo->msgType.classType = MSG_CLASS_2;
599 case SMS_MSG_CLASS_3:
600 pMsgInfo->msgType.classType = MSG_CLASS_3;
603 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(cbMsg.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 = cbMsg.recvTime;
627 MSG_DEBUG("recvTime is %s", ctime(&pMsgInfo->displayTime));
629 int bufSize = cbMsg.msgLength*2;
631 char tmpBuf[bufSize];
632 memset(tmpBuf, 0x00, sizeof(tmpBuf));
634 MSG_DEBUG("LENGTH %d CB MSG %s", cbMsg.msgLength, cbMsg.msgData);
636 SMS_LANG_INFO_S langInfo = {0};
638 langInfo.bSingleShift = false;
639 langInfo.bLockingShift = false;
641 // Convert Data values
642 if (cbMsg.codingScheme == SMS_CHARSET_7BIT)
643 pMsgInfo->dataSize = SmsPluginTextConvert::instance()->convertGSM7bitToUTF8((unsigned char*)tmpBuf, bufSize, (unsigned char*)cbMsg.msgData, cbMsg.msgLength, &langInfo);
644 else if (cbMsg.codingScheme == SMS_CHARSET_UCS2)
645 pMsgInfo->dataSize = SmsPluginTextConvert::instance()->convertUCS2ToUTF8((unsigned char*)tmpBuf, bufSize, (unsigned char*)cbMsg.msgData, cbMsg.msgLength);
647 if (pMsgInfo->dataSize > MAX_MSG_TEXT_LEN)
649 pMsgInfo->bTextSms = false;
651 // Save Message Data into File
652 char fileName[MAX_COMMON_INFO_SIZE+1];
653 memset(fileName, 0x00, sizeof(fileName));
655 if (MsgCreateFileName(fileName) == false)
656 THROW(MsgException::FILE_ERROR, "MsgCreateFileName error");
658 MSG_DEBUG("Save Message Data into file : size[%d] name[%s]\n", pMsgInfo->dataSize, fileName);
659 if (MsgWriteIpcFile(fileName, tmpBuf, pMsgInfo->dataSize) == false)
660 THROW(MsgException::FILE_ERROR, "MsgWriteIpcFile error");
662 strncpy(pMsgInfo->msgData, fileName, MAX_MSG_DATA_LEN);
666 pMsgInfo->bTextSms = true;
668 memset(pMsgInfo->msgText, 0x00, sizeof(pMsgInfo->msgText));
669 memcpy(pMsgInfo->msgText, tmpBuf, pMsgInfo->dataSize);
674 void SmsPluginCbMsgHandler::convertEtwsMsgToMsginfo(SMS_CBMSG_PAGE_S EtwsMsg, MSG_MESSAGE_INFO_S *pMsgInfo)
676 pMsgInfo->msgId = (msg_message_id_t)EtwsMsg.pageHeader.msgId;
678 pMsgInfo->folderId = MSG_CBMSGBOX_ID;
680 // Convert Type values
681 pMsgInfo->msgType.mainType = MSG_SMS_TYPE;
683 if (EtwsMsg.cbMsgType == SMS_CBMSG_TYPE_ETWS)
684 pMsgInfo->msgType.subType = MSG_ETWS_SMS;
686 pMsgInfo->storageId = MSG_STORAGE_PHONE;
687 pMsgInfo->networkStatus = MSG_NETWORK_RECEIVED;
688 pMsgInfo->bRead = false;
689 pMsgInfo->bProtected = false;
690 pMsgInfo->priority = MSG_MESSAGE_PRIORITY_NORMAL;
691 pMsgInfo->direction = MSG_DIRECTION_TYPE_MT;
694 pMsgInfo->nAddressCnt = 1;
696 pMsgInfo->addressList[0].addressType = MSG_ADDRESS_TYPE_UNKNOWN;
697 pMsgInfo->addressList[0].recipientType = MSG_RECIPIENTS_TYPE_UNKNOWN;
699 getDisplayName(EtwsMsg.pageHeader.msgId, pMsgInfo->addressList[0].addressVal);
700 MSG_DEBUG("%s", pMsgInfo->addressList[0].addressVal);
702 pMsgInfo->msgPort.valid = false;
703 pMsgInfo->msgPort.dstPort = 0;
704 pMsgInfo->msgPort.srcPort = 0;
706 pMsgInfo->displayTime = EtwsMsg.pageHeader.recvTime;
707 MSG_DEBUG("recvTime is %s", ctime(&pMsgInfo->displayTime));
708 MSG_DEBUG("LENGTH %d", EtwsMsg.pageLength);
709 pMsgInfo->bTextSms = true;
710 pMsgInfo->dataSize = EtwsMsg.pageLength;
711 memset(pMsgInfo->msgData, 0x00, sizeof(pMsgInfo->msgData));
712 memcpy(pMsgInfo->msgData, EtwsMsg.pageData, pMsgInfo->dataSize);
715 void SmsPluginCbMsgHandler::addToPageLiat(SMS_CBMSG_PAGE_S CbPage)
717 CB_PAGE_INFO_S tmpInfo;
719 tmpInfo.geoScope = CbPage.pageHeader.serialNum.geoScope;
720 tmpInfo.msgCode = CbPage.pageHeader.serialNum.msgCode;
721 tmpInfo.updateNum = CbPage.pageHeader.serialNum.updateNum;
722 tmpInfo.msgId = CbPage.pageHeader.msgId;
723 tmpInfo.totalPages = CbPage.pageHeader.totalPages;
726 tmpInfo.totalSize = CbPage.pageLength;
728 pair<unsigned char, string> newData(CbPage.pageHeader.page, CbPage.pageData);
729 tmpInfo.data.insert(newData);
731 MSG_DEBUG("MSG DATA : %s", CbPage.pageData);
732 MSG_DEBUG("PAIR DATA [%d] : %s", newData.first, newData.second.c_str());
734 pageList.push_back(tmpInfo);
738 void SmsPluginCbMsgHandler::removeFromPageList(SMS_CBMSG_PAGE_S CbPage)
742 for (index = 0; index < pageList.size(); index++)
744 if (pageList[index].geoScope == CbPage.pageHeader.serialNum.geoScope && pageList[index].msgCode == CbPage.pageHeader.serialNum.msgCode)
746 MSG_DEBUG("geoScope [%d], msgCode [%d]", pageList[index].geoScope, pageList[index].msgCode);
748 if (pageList[index].msgId == CbPage.pageHeader.msgId) break;
752 MSG_DEBUG("remove index [%d]", index);
754 pageList.erase(pageList.begin()+index);
758 void SmsPluginCbMsgHandler::decodeCbMsgDCS(unsigned char dcsData, const unsigned char *pMsgData, SMS_CBMSG_DCS_S* pDcs)
760 pDcs->codingGroup = SMS_CBMSG_CODGRP_GENERAL_DCS;
761 pDcs->classType = SMS_MSG_CLASS_NONE;
762 pDcs->bCompressed = false;
763 pDcs->codingScheme = SMS_CHARSET_7BIT;
764 pDcs->langType = SMS_CBMSG_LANG_UNSPECIFIED;
765 memset(pDcs->iso639Lang, 0x00, sizeof(pDcs->iso639Lang));
767 pDcs->rawData = dcsData;
769 unsigned char codingGrp = (dcsData & 0xF0) >> 4;
777 pDcs->codingGroup = SMS_CBMSG_CODGRP_GENERAL_DCS;
778 pDcs->langType = (SMS_CBMSG_LANG_TYPE_T)dcsData;
784 if (dcsData == 0x10 || dcsData == 0x11)
786 pDcs->codingGroup = SMS_CBMSG_CODGRP_GENERAL_DCS;
787 pDcs->codingScheme = (dcsData & 0x01) ? SMS_CHARSET_UCS2 : SMS_CHARSET_7BIT;
788 pDcs->langType = SMS_CBMSG_LANG_ISO639;
790 if (pMsgData != NULL)
792 pDcs->iso639Lang[0] = pMsgData[0] & 0x7F;
793 pDcs->iso639Lang[1] = (pMsgData[0] & 0x80) >> 7;
794 pDcs->iso639Lang[1] |= (pMsgData[1] & 0x3F) << 1;
795 pDcs->iso639Lang[2] = 0x13; /* CR char in GSM 7-bit Alphabet */
799 /* Default it to English if pMsgData is NULL */
800 pDcs->iso639Lang[0] = 0x45; /* E */
801 pDcs->iso639Lang[1] = 0x4E; /* N */
802 pDcs->iso639Lang[2] = 0x13; /* CR */
813 pDcs->codingGroup = SMS_CBMSG_CODGRP_GENERAL_DCS;
815 pDcs->bCompressed = (dcsData & 0x20) ? true : false;
818 pDcs->classType = (SMS_MSG_CLASS_T)(dcsData & 0x03);
820 pDcs->codingScheme = (SMS_CODING_SCHEME_T)(dcsData & 0x0C);
832 pDcs->codingGroup = SMS_CBMSG_CODGRP_WAP;
838 pDcs->codingGroup = SMS_CBMSG_CODGRP_CLASS_CODING;
839 pDcs->codingScheme = (dcsData & 0x04) ? SMS_CHARSET_UCS2 : SMS_CHARSET_7BIT;
840 pDcs->classType = (MSG_CLASS_TYPE_T)(dcsData & 0x03);
847 void SmsPluginCbMsgHandler::convertLangType(SMS_CBMSG_LANG_TYPE_T InType , MSG_CB_LANGUAGE_TYPE_T *pOutType)
851 case SMS_CBMSG_LANG_GERMAN :
852 *pOutType = MSG_CBLANG_TYPE_GER;
855 case SMS_CBMSG_LANG_ENGLISH :
856 *pOutType = MSG_CBLANG_TYPE_ENG;
859 case SMS_CBMSG_LANG_ITALIAN :
860 *pOutType = MSG_CBLANG_TYPE_ITA;
863 case SMS_CBMSG_LANG_FRENCH :
864 *pOutType = MSG_CBLANG_TYPE_FRE;
867 case SMS_CBMSG_LANG_SPANISH :
868 *pOutType = MSG_CBLANG_TYPE_SPA;
871 case SMS_CBMSG_LANG_DUTCH :
872 *pOutType = MSG_CBLANG_TYPE_NED;
875 case SMS_CBMSG_LANG_SWEDISH :
876 *pOutType = MSG_CBLANG_TYPE_SWE;
879 case SMS_CBMSG_LANG_PORTUGUESE :
880 *pOutType = MSG_CBLANG_TYPE_POR;
883 case SMS_CBMSG_LANG_TURKISH :
884 *pOutType = MSG_CBLANG_TYPE_TUR;
888 *pOutType = MSG_CBLANG_TYPE_MAX;
894 unsigned long SmsPluginCbMsgHandler::getRecvTime()
898 recvTime = time(NULL);
900 return (unsigned long)recvTime;
904 void SmsPluginCbMsgHandler::getDisplayName(unsigned short MsgId, char *pDisplayName)
906 int MsgIdCnt = MsgSettingGetInt(CB_CHANNEL_COUNT);
911 for (int i = 0; i < MsgIdCnt; i++)
913 memset(from, 0x00, sizeof(from));
914 sprintf(from, "%s/%d", CB_CHANNEL_ID_FROM, i);
916 memset(to, 0x00, sizeof(to));
917 sprintf(to, "%s/%d", CB_CHANNEL_ID_TO, i);
919 if (MsgId >= MsgSettingGetInt(from) && MsgId <= MsgSettingGetInt(to))
921 MSG_DEBUG("FIND MSG ID = [%d]", MsgId);
923 memset(keyName, 0x00, sizeof(keyName));
924 sprintf(keyName, "%s/%d", CB_CHANNEL_NAME, i);
926 memset(strTmp, 0x00, sizeof(strTmp));
928 channelName = MsgSettingGetString(keyName);
930 strncpy(strTmp, channelName, CB_CHANNEL_NAME_MAX);
937 if (strlen(strTmp) > 0)
938 sprintf(pDisplayName, "[%s]", strTmp);
940 sprintf(pDisplayName, "[%d]", MsgId);
942 sprintf(pDisplayName, "[%d]", MsgId);
949 sprintf(pDisplayName, "[%d]", MsgId);