2 * Copyright (c) 2014 Samsung Electronics Co., Ltd. All rights reserved
4 * Licensed under the Apache License, Version 2.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.apache.org/licenses/LICENSE-2.0
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 "MsgUtilStorage.h"
25 #include "SmsPluginUDCodec.h"
26 #include "SmsPluginStorage.h"
27 #include "SmsPluginEventHandler.h"
28 #include "SmsPluginCbMsgHandler.h"
29 #include "SmsPluginDSHandler.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(TapiHandle *handle, TelSmsCbMsg_t *pCbMsg)
63 char temp[1000]= {0x01, 0xa4, 0x1f, 0x51, 0x10, 0x11, 0x02, 0xea, 0x30, 0x30, 0xa8, 0x30, 0xea, 0x30, 0xa2, 0x30, 0xe1, 0x30, 0xfc, 0x30, 0xeb, 0x91, 0x4d, 0x4f, 0xe1, 0x30, 0xc6, 0x30, 0xb9, 0x30, 0xc8, 0x00, 0x0d, 0x00, 0x0a, 0x30, 0x53, 0x30, 0x8c, 0x30, 0x6f, 0x8a, 0x66, 0x9a, 0x13, 0x75, 0x28, 0x30, 0x6e, 0x30, 0xe1, 0x30, 0xc3, 0x30, 0xbb, 0x30, 0xfc, 0x30, 0xb8, 0x30, 0x67, 0x30, 0x59, 0x30, 0x02, 0x00, 0x0d, 0x00, 0x0a, 0xff, 0x08, 0x00, 0x32, 0x00, 0x30, 0x00, 0x31, 0x00, 0x33, 0x00, 0x2f, 0x00, 0x31, 0x00, 0x31, 0x00, 0x2f, 0x00, 0x32, 0x52, 0xea, 0x30, 0x00, 0x37, 0x00, 0x20, 0x00, 0x31, 0x00, 0x35, 0x00, 0x3a, 0x00, 0x34, 0x00, 0x34, 0xff, 0x09, 0x00, 0x0d, 0x00, 0x0a, 0xff, 0x08, 0x30, 0xa8, 0x30, 0xea, 0x30, 0xa2, 0x5e, 0x02, 0xff, 0x09, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x22};
64 TelSmsEtwsMsg_t *pCbMsg = (TelSmsEtwsMsg_t *)calloc(1, sizeof(TelSmsEtwsMsg_t));
66 pCbMsg->EtwsMsgType = (TelSmsEtwsMsgType_t)2;
67 memcpy(pCbMsg->szMsgData, temp, pCbMsg->Length);
69 SMS_CB_NETWORK_TYPE_T type = pCbMsg->EtwsMsgType;
70 SMS_CBMSG_PAGE_S CbMsgPage = {0};
74 case SMS_CB_NETWORK_TYPE_2G_GSM :
75 Decode2gCbMsg((TelSmsCbMsg_t *)pCbMsg, &CbMsgPage);
78 case SMS_CB_NETWORK_TYPE_3G_UMTS :
79 Decode3gCbMsg((TelSmsCbMsg_t *)pCbMsg, &CbMsgPage);
84 SMS_CB_NETWORK_TYPE_T type = pCbMsg->CbMsgType;
85 SMS_CBMSG_PAGE_S CbMsgPage = {0};
89 case SMS_CB_NETWORK_TYPE_2G_GSM :
90 Decode2gCbMsg(pCbMsg, &CbMsgPage);
93 case SMS_CB_NETWORK_TYPE_3G_UMTS :
94 Decode3gCbMsg(pCbMsg, &CbMsgPage);
99 // Check CB Msg Options
100 bool bJavaMsg = false;
102 int simIndex = SmsPluginDSHandler::instance()->getSimIndex(handle);
104 if (!checkCbOpt(CbMsgPage, &bJavaMsg, simIndex))
106 MSG_DEBUG("The CB Msg is not supported by option.");
110 if (bJavaMsg == true)
112 MSG_DEBUG("JAVA CB Msg.");
113 CbMsgPage.cbMsgType = SMS_CBMSG_TYPE_JAVACBS;
118 unsigned char pageCnt = checkCbPage(CbMsgPage);
120 if (pageCnt == CbMsgPage.pageHeader.totalPages)
122 MSG_DEBUG("RECEIVED LAST MSG : %d", pageCnt);
124 SMS_CBMSG_S cbMsg = {0,};
125 MSG_MESSAGE_INFO_S msgInfo;
127 /** initialize msgInfo */
128 memset(&msgInfo, 0x00, sizeof(MSG_MESSAGE_INFO_S));
130 msgInfo.addressList = NULL;
131 AutoPtr<MSG_ADDRESS_INFO_S> addressListBuf(&msgInfo.addressList);
133 // Make CB Msg Structure
134 MakeCbMsg(CbMsgPage, &cbMsg);
136 // Convert to MSG_MESSAGE_INFO_S
137 convertCbMsgToMsginfo(&cbMsg, &msgInfo, simIndex);
139 // Add CB Msg into DB
140 msg_error_t err = MSG_SUCCESS;
142 err = SmsPluginStorage::instance()->checkMessage(&msgInfo);
144 if (err == MSG_SUCCESS)
146 MSG_CB_MSG_S cbOutMsg = {0, };
148 cbOutMsg.type = MSG_CB_SMS;
149 cbOutMsg.receivedTime = cbMsg.recvTime;
150 cbOutMsg.serialNum = encodeCbSerialNum (CbMsgPage.pageHeader.serialNum);
151 cbOutMsg.messageId = cbMsg.msgId;
152 cbOutMsg.dcs = CbMsgPage.pageHeader.dcs.rawData;
153 memset (cbOutMsg.cbText, 0x00, sizeof(cbOutMsg.cbText));
155 cbOutMsg.cbTextLen= convertTextToUtf8((unsigned char*)cbOutMsg.cbText, sizeof(cbOutMsg.cbText), &cbMsg);
156 memset(cbOutMsg.language_type, 0x00, sizeof(cbOutMsg.language_type));
157 memcpy(cbOutMsg.language_type, CbMsgPage.pageHeader.dcs.iso639Lang, 3);
158 err = SmsPluginEventHandler::instance()->callbackCBMsgIncoming(&cbOutMsg, &msgInfo);
159 if (err != MSG_SUCCESS)
161 MSG_DEBUG("callbackMsgIncoming() Error !! [%d]", err);
166 MSG_DEBUG("checkMessage() Error !! [%d]", err);
170 // insert message-id to internal CB message table
171 SmsPluginStorage *storageHandler = SmsPluginStorage::instance();
172 err = storageHandler->insertReceivedCBMessage(CbMsgPage);
173 if (err != MSG_SUCCESS)
175 MSG_DEBUG("insertReceivedCBMessage() Error !! [%d]", err);
179 removeFromPageList(CbMsgPage);
187 void SmsPluginCbMsgHandler::handleEtwsMsg(TapiHandle *handle, TelSmsEtwsMsg_t *pEtwsMsg)
190 msg_error_t err = MSG_SUCCESS;
191 TelSmsEtwsMsgType_t type = pEtwsMsg->EtwsMsgType;
192 //MSG_MESSAGE_INFO_S msgInfo = {};
193 SMS_ETWS_PRIMARY_S etwsPn = {0, };
194 MSG_CB_MSG_S cbOutMsg = {0, };
196 if(type != TAPI_NETTEXT_ETWS_PRIMARY)
198 MSG_DEBUG("The Etws secondary Message");
199 handleCbMsg(handle, (TelSmsCbMsg_t *)pEtwsMsg);
202 DecodeEtwsMsg(pEtwsMsg, &etwsPn);
203 //convertEtwsMsgToMsginfo(CbMsgPage, &msgInfo, simIndex);
205 cbOutMsg.type = MSG_ETWS_SMS;
206 cbOutMsg.receivedTime = etwsPn.recvTime;
207 cbOutMsg.serialNum = encodeCbSerialNum (etwsPn.serialNum);
208 cbOutMsg.messageId = etwsPn.msgId;
209 cbOutMsg.etwsWarningType = etwsPn.warningType;
210 memcpy (cbOutMsg.etwsWarningSecurityInfo, etwsPn.warningSecurityInfo, sizeof(cbOutMsg.etwsWarningSecurityInfo));
212 err = SmsPluginEventHandler::instance()->callbackCBMsgIncoming(&cbOutMsg, NULL);
213 if (err != MSG_SUCCESS)
215 MSG_DEBUG("callbackMsgIncoming() Error !! [%d]", err);
222 void SmsPluginCbMsgHandler::Decode2gCbMsg(TelSmsCbMsg_t *pCbMsg, SMS_CBMSG_PAGE_S *pCbPage)
224 unsigned char cbData[pCbMsg->Length+1];
226 memset(cbData, 0x00, sizeof(cbData));
227 memcpy(cbData, pCbMsg->szMsgData, pCbMsg->Length);
228 cbData[pCbMsg->Length] = '\0';
231 MSG_INFO("Received CB length:%d", pCbMsg->Length);
232 char cbDataTmp[(pCbMsg->Length*2)+1];
233 memset(cbDataTmp, 0x00, sizeof(cbDataTmp));
235 for (int i = 0; i < pCbMsg->Length; i++) {
236 snprintf(cbDataTmp+(i*2), sizeof(cbDataTmp)-(i*2), "%02X", cbData[i]);
238 MSG_INFO("[%s]", cbDataTmp);
240 pCbPage->cbMsgType = SMS_CBMSG_TYPE_CBS;
243 pCbPage->pageHeader.serialNum.geoScope = (cbData[0] & 0xC0) >> 6;
245 pCbPage->pageHeader.serialNum.msgCode = (cbData[0] & 0x3F) << 4;
246 pCbPage->pageHeader.serialNum.msgCode |= (cbData[1] & 0xF0) >> 4;
248 pCbPage->pageHeader.serialNum.updateNum = cbData[1] & 0x0F;
250 MSG_DEBUG("geoScope : [%d], msgCode : [%d], updateNum : [%d]", pCbPage->pageHeader.serialNum.geoScope, pCbPage->pageHeader.serialNum.msgCode, pCbPage->pageHeader.serialNum.updateNum);
252 pCbPage->pageHeader.msgId = (cbData[2] << 8) | cbData[3];
254 MSG_DEBUG("MSG ID : [%d]", pCbPage->pageHeader.msgId);
257 decodeCbMsgDCS(cbData[4], (unsigned char*)cbData + 6, &(pCbPage->pageHeader.dcs));
260 pCbPage->pageHeader.totalPages = cbData[5] & 0x0F;
261 pCbPage->pageHeader.page = (cbData[5] & 0xF0) >> 4;
263 if (pCbPage->pageHeader.totalPages > MAX_CBMSG_PAGE_NUM)
264 THROW(MsgException::SMS_PLG_ERROR, "CB Page Count is over MAX[%d]", pCbPage->pageHeader.totalPages);
266 MSG_DEBUG("Total Page : [%d], Page : [%d]", pCbPage->pageHeader.totalPages, pCbPage->pageHeader.page);
268 // Convert Language Type
269 convertLangType(pCbPage->pageHeader.dcs.langType, &(pCbPage->pageHeader.langType));
271 MSG_DEBUG("In Language Type : [%d], Out Language Type : [%d]", pCbPage->pageHeader.dcs.langType, pCbPage->pageHeader.langType);
272 MSG_DEBUG("iso639Lang : [%s]", pCbPage->pageHeader.dcs.iso639Lang);
274 pCbPage->pageHeader.recvTime = getRecvTime();
277 int dataLen = pCbMsg->Length - 6;
279 MSG_DEBUG("codingScheme:[%d]", pCbPage->pageHeader.dcs.codingScheme);
281 switch (pCbPage->pageHeader.dcs.codingScheme)
283 case SMS_CHARSET_7BIT :
285 MSG_DEBUG("GSM 7 BIT");
287 dataLen = (dataLen*8) / 7;
289 SmsPluginUDCodec udCodec;
290 char pageData[MAX_CBMSG_PAGE_SIZE+1];
291 int unpackLen = udCodec.unpack7bitChar(&cbData[6], dataLen, 0, pageData);
293 if(pCbPage->pageHeader.dcs.iso639Lang[0])
295 unpackLen = unpackLen - 3;
297 memcpy(pCbPage->pageData, &pageData[3], unpackLen);
301 memcpy(pCbPage->pageData, &pageData, unpackLen);
304 MSG_DEBUG("unpackLen : [%d]", unpackLen);
306 pCbPage->pageLength = unpackLen;
307 pCbPage->pageData[unpackLen] = '\0';
311 case SMS_CHARSET_8BIT :
312 case SMS_CHARSET_UCS2 :
314 MSG_DEBUG("UCS2 or 8BIT");
316 if(pCbPage->pageHeader.dcs.iso639Lang[0])
318 memcpy(pCbPage->pageData, &cbData[8], dataLen - 2);
319 pCbPage->pageLength = dataLen - 2;
321 memcpy(pCbPage->pageData, &cbData[6], dataLen);
322 pCbPage->pageLength = dataLen;
328 MSG_DEBUG("Page Length : [%d], Page Data : [%s]", pCbPage->pageLength, pCbPage->pageData);
332 void SmsPluginCbMsgHandler::DecodeEtwsMsg(TelSmsEtwsMsg_t *pEtwsMsg, SMS_ETWS_PRIMARY_S *pEtwsPn)
334 if ( !pEtwsMsg || !pEtwsPn )
337 if (pEtwsMsg->Length > MAX_ETWS_SIZE)
338 THROW(MsgException::SMS_PLG_ERROR, "ETWS Msg Size is over MAX [%d]", pEtwsMsg->Length);
340 unsigned char EtwsData[pEtwsMsg->Length+1];
342 memset(EtwsData, 0x00, sizeof(EtwsData));
343 memcpy(EtwsData, pEtwsMsg->szMsgData, pEtwsMsg->Length);
344 EtwsData[pEtwsMsg->Length] = '\0';
346 // print received msg data
347 MSG_INFO("Received Etws length:%d", pEtwsMsg->Length);
348 char EtwsDataTmp[(pEtwsMsg->Length*2)+1];
349 memset(EtwsDataTmp, 0x00, sizeof(EtwsDataTmp));
351 for (int i = 0; i < pEtwsMsg->Length; i++) {
352 snprintf(EtwsDataTmp+(i*2), sizeof(EtwsDataTmp)-(i*2), "%02X", EtwsData[i]);
354 MSG_INFO("[%s]", EtwsDataTmp);
357 pEtwsPn->recvTime = getRecvTime();
360 pEtwsPn->serialNum.geoScope = (EtwsData[0] & 0xC0) >> 6;
361 pEtwsPn->serialNum.msgCode = (EtwsData[0] & 0x3F) << 4;
362 pEtwsPn->serialNum.msgCode |= (EtwsData[1] & 0xF0) >> 4;
363 pEtwsPn->serialNum.updateNum = EtwsData[1] & 0x0F;
365 MSG_DEBUG("geoScope : [%d], msgCode : [%d], updateNum : [%d]", pEtwsPn->serialNum.geoScope, pEtwsPn->serialNum.msgCode, pEtwsPn->serialNum.updateNum);
367 // Message Identifier
368 pEtwsPn->msgId = (EtwsData[2] << 8) | EtwsData[3];
369 MSG_DEBUG("MSG ID : [%d]", pEtwsPn->msgId);
372 pEtwsPn->warningType = (EtwsData[4] << 8) | EtwsData[5];
373 MSG_DEBUG("warningType : [0x%04x]", pEtwsPn->msgId);
375 // warning security information
376 memcpy(pEtwsPn->warningSecurityInfo, &EtwsData[6], sizeof(pEtwsPn->warningSecurityInfo)); // 50bytes
377 for (unsigned int i = 0; i < sizeof(pEtwsPn->warningSecurityInfo); i++)
379 MSG_DEBUG("warning secu info [%02x]", pEtwsPn->warningSecurityInfo[i] );
383 void SmsPluginCbMsgHandler::Decode3gCbMsg(TelSmsCbMsg_t *pCbMsg, SMS_CBMSG_PAGE_S *pCbPage)
385 unsigned char cbData[(MAX_CBMSG_PAGE_SIZE*MAX_CBMSG_PAGE_NUM)+1];
387 memset(cbData, 0x00, sizeof(cbData));
388 memcpy(cbData, pCbMsg->szMsgData, pCbMsg->Length);
389 cbData[pCbMsg->Length] = '\0';
392 MSG_INFO("Received CB length:%d", pCbMsg->Length);
393 char cbDataTmp[(pCbMsg->Length*2)+1];
394 memset(cbDataTmp, 0x00, sizeof(cbDataTmp));
396 for (int i = 0; i < pCbMsg->Length; i++) {
397 snprintf(cbDataTmp+(i*2), sizeof(cbDataTmp)-(i*2), "%02X", cbData[i]);
399 MSG_INFO("[%s]", cbDataTmp);
401 pCbPage->cbMsgType = (SMS_CBMSG_TYPE_T)cbData[0];
403 pCbPage->pageHeader.msgId = (cbData[1] << 8) | cbData[2];
405 MSG_DEBUG("MSG ID : [%d]", pCbPage->pageHeader.msgId);
408 pCbPage->pageHeader.serialNum.geoScope = (cbData[3] & 0xC0) >> 6;
410 pCbPage->pageHeader.serialNum.msgCode = (cbData[3] & 0x3F) << 4;
411 pCbPage->pageHeader.serialNum.msgCode |= (cbData[4] & 0xF0) >> 4;
413 pCbPage->pageHeader.serialNum.updateNum = cbData[4] & 0x0F;
415 MSG_DEBUG("geoScope : [%d], msgCode : [%d], updateNum : [%d]", pCbPage->pageHeader.serialNum.geoScope, pCbPage->pageHeader.serialNum.msgCode, pCbPage->pageHeader.serialNum.updateNum);
418 decodeCbMsgDCS(cbData[5], (unsigned char*)cbData + 6, &(pCbPage->pageHeader.dcs));
420 // Convert Language Type
421 convertLangType(pCbPage->pageHeader.dcs.langType, &(pCbPage->pageHeader.langType));
423 MSG_DEBUG("In Language Type : [%d], Out Language Type : [%d]", pCbPage->pageHeader.dcs.langType, pCbPage->pageHeader.langType);
426 pCbPage->pageHeader.recvTime = getRecvTime();
427 pCbPage->pageHeader.totalPages = cbData[6];
433 switch (pCbPage->pageHeader.dcs.codingScheme)
435 case SMS_CHARSET_7BIT :
437 for(int i = 0; i < pCbPage->pageHeader.totalPages; ++i)
439 char cbMessage[MAX_CBMSG_PAGE_SIZE]= {0,};
440 dataLen = cbData[7+(i+1)*82 + i];
441 memcpy(cbMessage, &cbData[7+(i*82)+ i], dataLen);
443 dataLen = (dataLen*8) / 7;
445 if (dataLen > MAX_CBMSG_PAGE_SIZE)
446 THROW(MsgException::SMS_PLG_ERROR, "CB Msg Size is over MAX [%d]", dataLen);
448 SmsPluginUDCodec udCodec;
449 int unpackLen = udCodec.unpack7bitChar((const unsigned char *)cbMessage, dataLen, 0, pCbPage->pageData + offset);
452 pCbPage->pageLength = offset;
456 case SMS_CHARSET_8BIT :
457 case SMS_CHARSET_UCS2 :
460 char cbMessage[MAX_CBMSG_PAGE_SIZE]= {0,};
462 for(int i = 0; i < pCbPage->pageHeader.totalPages; ++i)
464 dataLen = cbData[7+(i+1)*82 + i];
465 memcpy(cbMessage + offset, &cbData[7+(i*82)+ i], dataLen);
470 if(pCbPage->pageHeader.dcs.iso639Lang[0])
472 int tmpDataLen = (dataLen > 2)?(dataLen - 2):0;
473 memcpy(pCbPage->pageData, cbMessage + 2, tmpDataLen);
474 pCbPage->pageLength = tmpDataLen;
476 memcpy(pCbPage->pageData, cbMessage, dataLen);
477 pCbPage->pageLength = dataLen;
480 char cbMessage[MAX_CBMSG_PAGE_SIZE]= {0,};
482 for(int i = 0; i < pCbPage->pageHeader.totalPages; ++i)
484 if(pCbPage->pageHeader.dcs.iso639Lang[0])
486 dataLen = cbData[7+(i+1)*82 + i] - 2;
487 memcpy(cbMessage + offset, &cbData[7+(i*82)+ i + 2], dataLen);
490 dataLen = cbData[7+(i+1)*82 + i];
491 memcpy(cbMessage + offset, &cbData[7+(i*82)+ i], dataLen);
496 memcpy(pCbPage->pageData, cbMessage, dataLen);
497 pCbPage->pageLength = dataLen;
502 pCbPage->pageHeader.totalPages = 1;
504 MSG_DEBUG("Page Length : [%d], Page Data : [%s]", pCbPage->pageLength, pCbPage->pageData);
507 unsigned short SmsPluginCbMsgHandler::encodeCbSerialNum ( SMS_CBMSG_SERIAL_NUM_S snFields )
509 unsigned short serialNum = 0;
511 serialNum = ((snFields.geoScope & 0x03) << 14) | ((snFields.msgCode&0x03FF) << 4) | (snFields.updateNum&0x0F);
512 MSG_DEBUG ("serialNum (%x), geo(%x), mc(%x), un(%x)\n", serialNum, snFields.geoScope, snFields.msgCode, snFields.updateNum);
517 int SmsPluginCbMsgHandler::CMAS_class(unsigned short message_id)
525 ret = MSG_CMAS_PRESIDENTIAL;
531 ret = MSG_CMAS_EXTREME;
545 ret = MSG_CMAS_SEVERE;
549 ret = MSG_CMAS_AMBER;
559 ret = MSG_CMAS_OPERATOR_DEFINED;
568 bool SmsPluginCbMsgHandler::checkCbOpt(SMS_CBMSG_PAGE_S CbPage, bool *pJavaMsg, msg_sim_slot_id_t simIndex)
570 bool bReceive = false;
571 char keyName[MAX_VCONFKEY_NAME_LEN];
572 memset(keyName, 0x00, sizeof(keyName));
573 snprintf(keyName, sizeof(keyName), "%s/%d", CB_RECEIVE, simIndex);
574 MsgSettingGetBool(keyName, &bReceive);
576 // Receive CB Msg = FALSE
579 MSG_DEBUG("RECEIVE CB = FALSE");
586 memset(keyName, 0x00, sizeof(keyName));
587 snprintf(keyName, sizeof(keyname), "%s/%d", CB_LANGUAGE, MSG_CBLANG_TYPE_ALL);
589 bool bAllLang = false;
590 MsgSettingGetBool(keyName, &bAllLang);
594 MSG_DEBUG("ALL LANGUAGE = FALSE");
596 memset(keyName, 0x00, sizeof(keyName));
597 snprintf(keyName, sizeof(keyname), "%s/%d", CB_LANGUAGE, CbPage.pageHeader.langType);
601 MsgSettingGetBool(keyName, &bLang);
603 if (!bLang || CbPage.pageHeader.langType == MSG_CBLANG_TYPE_MAX)
605 MSG_DEBUG("LANGUAGE [%d] = FALSE", CbPage.pageHeader.langType);
611 bool bActivate = false;
612 int MsgId_from = 0, MsgId_to = 0;
613 MSG_CB_CHANNEL_S cbChannelInfo = {0,};
614 msg_error_t err = MSG_SUCCESS;
615 MsgDbHandler *dbHandle = getDbHandle();
617 err = MsgStoGetCBChannelInfo(dbHandle, &cbChannelInfo, simIndex);
618 if (err != MSG_SUCCESS)
619 MSG_ERR("Error value of MsgStoGetCBChannelInfo [%d]", err);
621 for (int i = 0; i < cbChannelInfo.channelCnt; i++)
623 bActivate = cbChannelInfo.channelInfo[i].bActivate;
624 MsgId_from = cbChannelInfo.channelInfo[i].from;
625 MsgId_to = cbChannelInfo.channelInfo[i].to;
627 if (bActivate == true && CbPage.pageHeader.msgId >= MsgId_from && CbPage.pageHeader.msgId <= MsgId_to)
629 MSG_DEBUG("FIND CHANNEL = [%d]", CbPage.pageHeader.msgId);
637 unsigned char SmsPluginCbMsgHandler::checkCbPage(SMS_CBMSG_PAGE_S CbPage)
639 unsigned char currPageCnt = 0;
644 msg_error_t err = MSG_SUCCESS;
646 SmsPluginStorage *storageHandler = SmsPluginStorage::instance();
647 err = storageHandler->isReceivedCBMessage(CbPage);
648 // check existing message with cb internal table;
649 if(err != MSG_ERR_DB_NORECORD)
651 MSG_DEBUG("already received message: [%d]", CbPage.pageHeader.msgId);
656 if (CbPage.pageHeader.totalPages > 0)
658 for (unsigned int i = 0; i < pageList.size(); i++)
660 if (pageList[i].geoScope == CbPage.pageHeader.serialNum.geoScope && pageList[i].msgCode == CbPage.pageHeader.serialNum.msgCode)
662 MSG_DEBUG("geoScope [%d], msgCode [%d]", pageList[i].geoScope, pageList[i].msgCode);
664 if (pageList[i].msgId == CbPage.pageHeader.msgId)
666 int updateNum = CbPage.pageHeader.serialNum.updateNum - pageList[i].updateNum;
668 if (updateNum > 0) // New Message Content
672 else if (updateNum == 0) // Same Message Content
674 if (pageList[i].data.count(CbPage.pageHeader.page) != 0)
676 MSG_DEBUG("The Page Number already exists [%d]", CbPage.pageHeader.page);
680 pair<unsigned char, SMS_CBMSG_PAGE_S> newData(CbPage.pageHeader.page, CbPage);
681 pageList[i].data.insert(newData);
683 MSG_DEBUG("PAGE DATA : %s", CbPage.pageData);
684 MSG_DEBUG("PAIR DATA [%d] : %s", newData.first, newData.second.pageData);
686 pageList[i].pageCnt++;
687 pageList[i].totalSize += CbPage.pageLength;
689 currPageCnt = pageList[i].pageCnt;
695 else // Old Message Content
704 if (bFind == false || CbPage.pageHeader.totalPages == 1)
706 addToPageList(CbPage);
714 void SmsPluginCbMsgHandler::MakeCbMsg(SMS_CBMSG_PAGE_S CbPage, SMS_CBMSG_S *pCbMsg)
716 pCbMsg->cbMsgType = CbPage.cbMsgType;
717 pCbMsg->msgId = CbPage.pageHeader.msgId;
718 pCbMsg->classType = CbPage.pageHeader.dcs.classType;
719 pCbMsg->codingScheme = CbPage.pageHeader.dcs.codingScheme;
720 pCbMsg->recvTime = CbPage.pageHeader.recvTime;
722 cbPageMap::iterator it;
725 for (unsigned int i = 0; i < pageList.size(); i++)
727 if (pageList[i].geoScope == CbPage.pageHeader.serialNum.geoScope && pageList[i].msgCode == CbPage.pageHeader.serialNum.msgCode)
729 MSG_DEBUG("geoScope [%d], msgCode [%d]", pageList[i].geoScope, pageList[i].msgCode);
731 if (pageList[i].msgId == CbPage.pageHeader.msgId)
734 for (it = pageList[i].data.begin(); it != pageList[i].data.end(); it++)
736 memcpy(pCbMsg->msgData + offset, it->second.pageData, it->second.pageLength);
737 pCbMsg->msgLength += it->second.pageLength;
738 offset = pCbMsg->msgLength;
745 pCbMsg->msgLength = tmpStr.size();
747 memcpy(pCbMsg->msgData, tmpStr.c_str(), tmpStr.size());
748 pCbMsg->msgData[tmpStr.size()] = '\0';
750 MSG_DEBUG("SIZE : [%d] TOTAL MSG : %s", tmpStr.size(), tmpStr.c_str());
755 void SmsPluginCbMsgHandler::convertCbMsgToMsginfo(SMS_CBMSG_S *pCbMsg, MSG_MESSAGE_INFO_S *pMsgInfo, msg_sim_slot_id_t simIndex)
757 pMsgInfo->msgId = (msg_message_id_t)pCbMsg->msgId;
759 pMsgInfo->folderId = MSG_CBMSGBOX_ID;
761 // Convert Type values
762 pMsgInfo->msgType.mainType = MSG_SMS_TYPE;
764 if (pCbMsg->cbMsgType == SMS_CBMSG_TYPE_CBS) {
765 int cmas_class = CMAS_class(pCbMsg->msgId);
768 pMsgInfo->msgType.subType = MSG_CB_SMS;
770 pMsgInfo->msgType.subType = (MSG_SUB_TYPE_T)cmas_class;
772 else if (pCbMsg->cbMsgType == SMS_CBMSG_TYPE_JAVACBS) {
773 pMsgInfo->msgType.subType = MSG_JAVACB_SMS;
776 switch(pCbMsg->classType)
778 case SMS_MSG_CLASS_0:
779 pMsgInfo->msgType.classType = MSG_CLASS_0;
781 case SMS_MSG_CLASS_1:
782 pMsgInfo->msgType.classType = MSG_CLASS_1;
784 case SMS_MSG_CLASS_2:
785 pMsgInfo->msgType.classType = MSG_CLASS_2;
787 case SMS_MSG_CLASS_3:
788 pMsgInfo->msgType.classType = MSG_CLASS_3;
791 pMsgInfo->msgType.classType = MSG_CLASS_NONE;
795 pMsgInfo->storageId = MSG_STORAGE_PHONE;
796 pMsgInfo->networkStatus = MSG_NETWORK_RECEIVED;
797 pMsgInfo->bRead = false;
798 pMsgInfo->bProtected = false;
799 pMsgInfo->priority = MSG_MESSAGE_PRIORITY_NORMAL;
800 pMsgInfo->direction = MSG_DIRECTION_TYPE_MT;
803 pMsgInfo->nAddressCnt = 1;
805 pMsgInfo->addressList = (MSG_ADDRESS_INFO_S *)new char[sizeof(MSG_ADDRESS_INFO_S)];
806 memset(pMsgInfo->addressList, 0x00, sizeof(MSG_ADDRESS_INFO_S));
808 pMsgInfo->addressList[0].addressType = MSG_ADDRESS_TYPE_UNKNOWN;
809 pMsgInfo->addressList[0].recipientType = MSG_RECIPIENTS_TYPE_UNKNOWN;
810 pMsgInfo->sim_idx = simIndex;
812 // TODO :: MSG ID should be used to get CB message type
813 getDisplayName(pCbMsg->msgId, pMsgInfo->addressList[0].addressVal, simIndex);
814 MSG_SEC_DEBUG("%s", pMsgInfo->addressList[0].addressVal);
817 pMsgInfo->msgPort.valid = false;
818 pMsgInfo->msgPort.dstPort = 0;
819 pMsgInfo->msgPort.srcPort = 0;
821 pMsgInfo->displayTime = pCbMsg->recvTime;
822 MSG_DEBUG("recvTime is %s", ctime(&pMsgInfo->displayTime));
824 int bufSize = pCbMsg->msgLength*2;
826 char tmpBuf[bufSize];
827 memset(tmpBuf, 0x00, sizeof(tmpBuf));
829 while (pCbMsg->msgLength > 0) {
830 if (pCbMsg->msgData[pCbMsg->msgLength-1] == ' ' ||
831 pCbMsg->msgData[pCbMsg->msgLength-1] == '\r' ||
832 pCbMsg->msgData[pCbMsg->msgLength-1] == '\n') {
839 pCbMsg->msgData[pCbMsg->msgLength] = '\0';
841 MSG_DEBUG("LENGTH %d CB MSG %s", pCbMsg->msgLength, pCbMsg->msgData);
843 // Convert Data values
844 pMsgInfo->dataSize = convertTextToUtf8((unsigned char*)tmpBuf, bufSize, pCbMsg);
846 if (pMsgInfo->dataSize > MAX_MSG_TEXT_LEN)
848 pMsgInfo->bTextSms = false;
850 // Save Message Data into File
851 char fileName[MSG_FILENAME_LEN_MAX+1];
852 memset(fileName, 0x00, sizeof(fileName));
854 if (MsgCreateFileName(fileName) == false)
855 THROW(MsgException::FILE_ERROR, "MsgCreateFileName error");
857 MSG_SEC_DEBUG("Save Message Data into file : size[%d] name[%s]\n", pMsgInfo->dataSize, fileName);
858 if (MsgWriteIpcFile(fileName, tmpBuf, pMsgInfo->dataSize) == false)
859 THROW(MsgException::FILE_ERROR, "MsgWriteIpcFile error");
861 strncpy(pMsgInfo->msgData, fileName, MAX_MSG_DATA_LEN);
865 pMsgInfo->bTextSms = true;
867 memset(pMsgInfo->msgText, 0x00, sizeof(pMsgInfo->msgText));
868 memcpy(pMsgInfo->msgText, tmpBuf, pMsgInfo->dataSize);
869 pMsgInfo->dataSize = strlen(pMsgInfo->msgText);
870 MSG_SEC_DEBUG("CB MSG %s", pMsgInfo->msgText);
875 void SmsPluginCbMsgHandler::convertEtwsMsgToMsginfo(SMS_CBMSG_PAGE_S EtwsMsg, MSG_MESSAGE_INFO_S *pMsgInfo, msg_sim_slot_id_t simIndex)
877 pMsgInfo->msgId = (msg_message_id_t)EtwsMsg.pageHeader.msgId;
879 pMsgInfo->folderId = MSG_CBMSGBOX_ID;
881 // Convert Type values
882 pMsgInfo->msgType.mainType = MSG_SMS_TYPE;
884 if (EtwsMsg.cbMsgType == SMS_CBMSG_TYPE_ETWS)
885 pMsgInfo->msgType.subType = MSG_ETWS_SMS;
887 pMsgInfo->storageId = MSG_STORAGE_PHONE;
888 pMsgInfo->networkStatus = MSG_NETWORK_RECEIVED;
889 pMsgInfo->bRead = false;
890 pMsgInfo->bProtected = false;
891 pMsgInfo->priority = MSG_MESSAGE_PRIORITY_NORMAL;
892 pMsgInfo->direction = MSG_DIRECTION_TYPE_MT;
895 pMsgInfo->nAddressCnt = 1;
897 pMsgInfo->addressList[0].addressType = MSG_ADDRESS_TYPE_UNKNOWN;
898 pMsgInfo->addressList[0].recipientType = MSG_RECIPIENTS_TYPE_UNKNOWN;
900 getDisplayName(EtwsMsg.pageHeader.msgId, pMsgInfo->addressList[0].addressVal, simIndex);
901 MSG_SEC_DEBUG("%s", pMsgInfo->addressList[0].addressVal);
903 pMsgInfo->msgPort.valid = false;
904 pMsgInfo->msgPort.dstPort = 0;
905 pMsgInfo->msgPort.srcPort = 0;
907 pMsgInfo->displayTime = EtwsMsg.pageHeader.recvTime;
908 MSG_DEBUG("recvTime is %s", ctime(&pMsgInfo->displayTime));
909 MSG_DEBUG("LENGTH %d", EtwsMsg.pageLength);
910 pMsgInfo->bTextSms = true;
911 pMsgInfo->dataSize = EtwsMsg.pageLength;
912 memset(pMsgInfo->msgData, 0x00, sizeof(pMsgInfo->msgData));
913 memcpy(pMsgInfo->msgData, EtwsMsg.pageData, pMsgInfo->dataSize);
916 int SmsPluginCbMsgHandler::convertTextToUtf8 (unsigned char* outBuf, int outBufSize, SMS_CBMSG_S* pCbMsg)
918 int convertedTextSize = 0;
919 MSG_LANG_INFO_S langInfo = {0,};
921 MsgTextConvert *textCvt = MsgTextConvert::instance();
923 if (!outBuf || !pCbMsg)
925 MSG_DEBUG ("invalid param.\n");
929 langInfo.bSingleShift = false;
930 langInfo.bLockingShift = false;
933 // Convert Data values
934 if (pCbMsg->codingScheme == SMS_CHARSET_7BIT)
935 convertedTextSize = textCvt->convertGSM7bitToUTF8(outBuf, outBufSize, (unsigned char*)pCbMsg->msgData, pCbMsg->msgLength, &langInfo);
936 else if (pCbMsg->codingScheme == SMS_CHARSET_UCS2)
937 convertedTextSize = textCvt->convertUCS2ToUTF8(outBuf, outBufSize, (unsigned char*)pCbMsg->msgData, pCbMsg->msgLength);
939 return convertedTextSize;
942 void SmsPluginCbMsgHandler::addToPageList(SMS_CBMSG_PAGE_S CbPage)
944 CB_PAGE_INFO_S tmpInfo;
946 tmpInfo.geoScope = CbPage.pageHeader.serialNum.geoScope;
947 tmpInfo.msgCode = CbPage.pageHeader.serialNum.msgCode;
948 tmpInfo.updateNum = CbPage.pageHeader.serialNum.updateNum;
949 tmpInfo.msgId = CbPage.pageHeader.msgId;
950 tmpInfo.totalPages = CbPage.pageHeader.totalPages;
953 tmpInfo.totalSize = CbPage.pageLength;
955 pair<unsigned char, SMS_CBMSG_PAGE_S> newData(CbPage.pageHeader.page, CbPage);
956 tmpInfo.data.insert(newData);
958 MSG_DEBUG("MSG DATA : %s", CbPage.pageData);
959 MSG_DEBUG("PAIR DATA [%d] : %s", newData.first, newData.second.pageData);
961 pageList.push_back(tmpInfo);
965 void SmsPluginCbMsgHandler::removeFromPageList(SMS_CBMSG_PAGE_S CbPage)
969 for (index = 0; index < pageList.size(); index++)
971 if (pageList[index].geoScope == CbPage.pageHeader.serialNum.geoScope && pageList[index].msgCode == CbPage.pageHeader.serialNum.msgCode)
973 MSG_DEBUG("geoScope [%d], msgCode [%d]", pageList[index].geoScope, pageList[index].msgCode);
975 if (pageList[index].msgId == CbPage.pageHeader.msgId) break;
979 MSG_DEBUG("remove index [%d]", index);
981 pageList.erase(pageList.begin()+index);
985 void SmsPluginCbMsgHandler::decodeCbMsgDCS(unsigned char dcsData, const unsigned char *pMsgData, SMS_CBMSG_DCS_S* pDcs)
987 pDcs->codingGroup = SMS_CBMSG_CODGRP_GENERAL_DCS;
988 pDcs->classType = SMS_MSG_CLASS_NONE;
989 pDcs->bCompressed = false;
990 pDcs->codingScheme = SMS_CHARSET_7BIT;
991 pDcs->langType = SMS_CBMSG_LANG_UNSPECIFIED;
992 memset(pDcs->iso639Lang, 0x00, sizeof(pDcs->iso639Lang));
994 pDcs->rawData = dcsData;
996 unsigned char codingGrp = (dcsData & 0xF0) >> 4;
1004 pDcs->codingGroup = SMS_CBMSG_CODGRP_GENERAL_DCS;
1005 pDcs->langType = (SMS_CBMSG_LANG_TYPE_T)dcsData;
1011 if (dcsData == 0x10 || dcsData == 0x11)
1013 pDcs->codingGroup = SMS_CBMSG_CODGRP_GENERAL_DCS;
1014 pDcs->codingScheme = (dcsData & 0x01) ? SMS_CHARSET_UCS2 : SMS_CHARSET_7BIT;
1015 pDcs->langType = SMS_CBMSG_LANG_ISO639;
1016 MSG_DEBUG("codingScheme: [%d]", pDcs->codingScheme);
1017 if (pMsgData[0] && pMsgData[1])
1019 pDcs->iso639Lang[0] = pMsgData[0] & 0x7F;
1020 pDcs->iso639Lang[1] = (pMsgData[0] & 0X80) >> 7;
1021 pDcs->iso639Lang[1] |= (pMsgData[1] & 0X3F) << 1;
1022 pDcs->iso639Lang[2] = 0x13; /* CR */
1026 /* Default it to English if pMsgData is NULL */
1027 pDcs->iso639Lang[0] = 0x45; /* E */
1028 pDcs->iso639Lang[1] = 0x4E; /* N */
1029 pDcs->iso639Lang[2] = 0x13; /* CR */
1040 pDcs->codingGroup = SMS_CBMSG_CODGRP_GENERAL_DCS;
1042 pDcs->bCompressed = (dcsData & 0x20) ? true : false;
1045 pDcs->classType = (SMS_MSG_CLASS_T)(dcsData & 0x03);
1047 unsigned char tmpScheme = (dcsData & 0x0C) >> 2;
1049 switch (tmpScheme) {
1051 pDcs->codingScheme = SMS_CHARSET_7BIT;
1054 pDcs->codingScheme = SMS_CHARSET_8BIT;
1057 pDcs->codingScheme = SMS_CHARSET_UCS2;
1060 MSG_DEBUG("tmpScheme: [%d]", tmpScheme);
1069 pDcs->classType = (MSG_CLASS_TYPE_T)(dcsData & 0x03);
1070 pDcs->codingScheme = (SMS_CODING_SCHEME_T)((dcsData & 0x0C) >> 2);
1076 pDcs->codingGroup = SMS_CBMSG_CODGRP_WAP;
1082 pDcs->codingGroup = SMS_CBMSG_CODGRP_CLASS_CODING;
1083 pDcs->codingScheme = (dcsData & 0x04) ? SMS_CHARSET_8BIT : SMS_CHARSET_7BIT;
1084 pDcs->classType = (MSG_CLASS_TYPE_T)(dcsData & 0x03);
1088 MSG_DEBUG("codingGrp: [0x%x]", codingGrp);
1094 void SmsPluginCbMsgHandler::convertLangType(SMS_CBMSG_LANG_TYPE_T InType , MSG_CB_LANGUAGE_TYPE_T *pOutType)
1098 case SMS_CBMSG_LANG_GERMAN :
1099 *pOutType = MSG_CBLANG_TYPE_GER;
1102 case SMS_CBMSG_LANG_ENGLISH :
1103 *pOutType = MSG_CBLANG_TYPE_ENG;
1106 case SMS_CBMSG_LANG_ITALIAN :
1107 *pOutType = MSG_CBLANG_TYPE_ITA;
1110 case SMS_CBMSG_LANG_FRENCH :
1111 *pOutType = MSG_CBLANG_TYPE_FRE;
1114 case SMS_CBMSG_LANG_SPANISH :
1115 *pOutType = MSG_CBLANG_TYPE_SPA;
1118 case SMS_CBMSG_LANG_DUTCH :
1119 *pOutType = MSG_CBLANG_TYPE_NED;
1122 case SMS_CBMSG_LANG_SWEDISH :
1123 *pOutType = MSG_CBLANG_TYPE_SWE;
1126 case SMS_CBMSG_LANG_PORTUGUESE :
1127 *pOutType = MSG_CBLANG_TYPE_POR;
1130 case SMS_CBMSG_LANG_TURKISH :
1131 *pOutType = MSG_CBLANG_TYPE_TUR;
1135 *pOutType = MSG_CBLANG_TYPE_MAX;
1141 unsigned long SmsPluginCbMsgHandler::getRecvTime()
1145 recvTime = time(NULL);
1147 return (unsigned long)recvTime;
1151 void SmsPluginCbMsgHandler::getDisplayName(unsigned short MsgId, char *pDisplayName, msg_sim_slot_id_t simIndex)
1153 MSG_CB_CHANNEL_S cbChannelInfo = {0,};
1154 msg_error_t err = MSG_SUCCESS;
1155 MsgDbHandler *dbHandle = getDbHandle();
1157 err = MsgStoGetCBChannelInfo(dbHandle, &cbChannelInfo, simIndex);
1158 MSG_DEBUG("MsgStoGetCBChannelInfo [err = %d]", err);
1160 for (int i = 0; i < cbChannelInfo.channelCnt; i++)
1162 if (MsgId >= cbChannelInfo.channelInfo[i].from && MsgId <= cbChannelInfo.channelInfo[i].to)
1164 MSG_DEBUG("FIND MSG ID = [%d]", MsgId);
1166 char strTmp[CB_CHANNEL_NAME_MAX + 1];
1167 memset(strTmp, 0x00, sizeof(strTmp));
1169 strncpy(strTmp, cbChannelInfo.channelInfo[i].name, CB_CHANNEL_NAME_MAX);
1171 if (strlen(strTmp) > 0)
1172 snprintf(pDisplayName, sizeof(strTmp), "[%s]", strTmp);
1174 snprintf(pDisplayName, sizeof(unsigned short), "[%d]", MsgId);
1177 #ifdef MSG_NOTI_INTEGRATION
1178 snprintf(pDisplayName, MAX_ADDRESS_VAL_LEN + 1, "CB message");
1180 snprintf(pDisplayName, MAX_ADDRESS_VAL_LEN + 1, "[%d]", MsgId);
1189 sprintf(pDisplayName, "[%d]", MsgId);