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 = NULL;
125 unique_ptr<SMS_CBMSG_S*, void(*)(SMS_CBMSG_S**)> buf(&cbMsg, unique_ptr_deleter);
126 cbMsg = (SMS_CBMSG_S *)new char[sizeof(SMS_CBMSG_S)];
127 memset(cbMsg, 0x00, sizeof(SMS_CBMSG_S));
129 MSG_MESSAGE_INFO_S msgInfo;
131 /** initialize msgInfo */
132 memset(&msgInfo, 0x00, sizeof(MSG_MESSAGE_INFO_S));
134 msgInfo.addressList = NULL;
135 unique_ptr<MSG_ADDRESS_INFO_S*, void(*)(MSG_ADDRESS_INFO_S**)> addressListBuf(&msgInfo.addressList, unique_ptr_deleter);
137 // Make CB Msg Structure
138 MakeCbMsg(&CbMsgPage, cbMsg);
140 // Convert to MSG_MESSAGE_INFO_S
141 convertCbMsgToMsginfo(cbMsg, &msgInfo, simIndex);
143 // Add CB Msg into DB
144 msg_error_t err = MSG_SUCCESS;
146 err = SmsPluginStorage::instance()->checkMessage(&msgInfo);
148 if (err == MSG_SUCCESS)
150 MSG_CB_MSG_S cbOutMsg = {0, };
152 cbOutMsg.type = MSG_CB_SMS;
153 cbOutMsg.receivedTime = cbMsg->recvTime;
154 cbOutMsg.serialNum = encodeCbSerialNum (CbMsgPage.pageHeader.serialNum);
155 cbOutMsg.messageId = cbMsg->msgId;
156 cbOutMsg.dcs = CbMsgPage.pageHeader.dcs.rawData;
157 memset (cbOutMsg.cbText, 0x00, sizeof(cbOutMsg.cbText));
159 cbOutMsg.cbTextLen= convertTextToUtf8((unsigned char*)cbOutMsg.cbText, sizeof(cbOutMsg.cbText), cbMsg);
160 memset(cbOutMsg.language_type, 0x00, sizeof(cbOutMsg.language_type));
161 memcpy(cbOutMsg.language_type, CbMsgPage.pageHeader.dcs.iso639Lang, 3);
162 err = SmsPluginEventHandler::instance()->callbackCBMsgIncoming(&cbOutMsg, &msgInfo);
163 if (err != MSG_SUCCESS)
165 MSG_DEBUG("callbackMsgIncoming() Error !! [%d]", err);
170 MSG_DEBUG("checkMessage() Error !! [%d]", err);
174 // insert message-id to internal CB message table
175 SmsPluginStorage *storageHandler = SmsPluginStorage::instance();
176 err = storageHandler->insertReceivedCBMessage(CbMsgPage);
177 if (err != MSG_SUCCESS)
179 MSG_DEBUG("insertReceivedCBMessage() Error !! [%d]", err);
183 removeFromPageList(&CbMsgPage);
189 void SmsPluginCbMsgHandler::handleEtwsMsg(TapiHandle *handle, TelSmsEtwsMsg_t *pEtwsMsg)
192 msg_error_t err = MSG_SUCCESS;
193 TelSmsEtwsMsgType_t type = pEtwsMsg->EtwsMsgType;
194 //MSG_MESSAGE_INFO_S msgInfo = {};
195 SMS_ETWS_PRIMARY_S etwsPn = {0, };
196 MSG_CB_MSG_S cbOutMsg = {0, };
198 if(type != TAPI_NETTEXT_ETWS_PRIMARY)
200 MSG_DEBUG("The Etws secondary Message");
201 handleCbMsg(handle, (TelSmsCbMsg_t *)pEtwsMsg);
204 DecodeEtwsMsg(pEtwsMsg, &etwsPn);
205 //convertEtwsMsgToMsginfo(&CbMsgPage, &msgInfo, simIndex);
207 cbOutMsg.type = MSG_ETWS_SMS;
208 cbOutMsg.receivedTime = etwsPn.recvTime;
209 cbOutMsg.serialNum = encodeCbSerialNum (etwsPn.serialNum);
210 cbOutMsg.messageId = etwsPn.msgId;
211 cbOutMsg.etwsWarningType = etwsPn.warningType;
212 memcpy (cbOutMsg.etwsWarningSecurityInfo, etwsPn.warningSecurityInfo, sizeof(cbOutMsg.etwsWarningSecurityInfo));
214 err = SmsPluginEventHandler::instance()->callbackCBMsgIncoming(&cbOutMsg, NULL);
215 if (err != MSG_SUCCESS)
217 MSG_DEBUG("callbackMsgIncoming() Error !! [%d]", err);
224 void SmsPluginCbMsgHandler::Decode2gCbMsg(TelSmsCbMsg_t *pCbMsg, SMS_CBMSG_PAGE_S *pCbPage)
226 unsigned char cbData[pCbMsg->Length+1];
228 memset(cbData, 0x00, sizeof(cbData));
229 memcpy(cbData, pCbMsg->szMsgData, pCbMsg->Length);
230 cbData[pCbMsg->Length] = '\0';
233 MSG_INFO("Received CB length:%d", pCbMsg->Length);
234 char cbDataTmp[(pCbMsg->Length*2)+1];
235 memset(cbDataTmp, 0x00, sizeof(cbDataTmp));
237 for (int i = 0; i < pCbMsg->Length; i++) {
238 snprintf(cbDataTmp+(i*2), sizeof(cbDataTmp)-(i*2), "%02X", cbData[i]);
240 MSG_INFO("[%s]", cbDataTmp);
242 pCbPage->cbMsgType = SMS_CBMSG_TYPE_CBS;
245 pCbPage->pageHeader.serialNum.geoScope = (cbData[0] & 0xC0) >> 6;
247 pCbPage->pageHeader.serialNum.msgCode = (cbData[0] & 0x3F) << 4;
248 pCbPage->pageHeader.serialNum.msgCode |= (cbData[1] & 0xF0) >> 4;
250 pCbPage->pageHeader.serialNum.updateNum = cbData[1] & 0x0F;
252 MSG_DEBUG("geoScope : [%d], msgCode : [%d], updateNum : [%d]", pCbPage->pageHeader.serialNum.geoScope, pCbPage->pageHeader.serialNum.msgCode, pCbPage->pageHeader.serialNum.updateNum);
254 pCbPage->pageHeader.msgId = (cbData[2] << 8) | cbData[3];
256 MSG_DEBUG("MSG ID : [%d]", pCbPage->pageHeader.msgId);
259 decodeCbMsgDCS(cbData[4], (unsigned char*)cbData + 6, &(pCbPage->pageHeader.dcs));
262 pCbPage->pageHeader.totalPages = cbData[5] & 0x0F;
263 pCbPage->pageHeader.page = (cbData[5] & 0xF0) >> 4;
265 if (pCbPage->pageHeader.totalPages > MAX_CBMSG_PAGE_NUM)
266 THROW(MsgException::SMS_PLG_ERROR, "CB Page Count is over MAX[%d]", pCbPage->pageHeader.totalPages);
268 MSG_DEBUG("Total Page : [%d], Page : [%d]", pCbPage->pageHeader.totalPages, pCbPage->pageHeader.page);
270 // Convert Language Type
271 convertLangType(pCbPage->pageHeader.dcs.langType, &(pCbPage->pageHeader.langType));
273 MSG_DEBUG("In Language Type : [%d], Out Language Type : [%d]", pCbPage->pageHeader.dcs.langType, pCbPage->pageHeader.langType);
274 MSG_DEBUG("iso639Lang : [%s]", pCbPage->pageHeader.dcs.iso639Lang);
276 pCbPage->pageHeader.recvTime = getRecvTime();
279 int dataLen = pCbMsg->Length - 6;
281 MSG_DEBUG("codingScheme:[%d]", pCbPage->pageHeader.dcs.codingScheme);
283 switch (pCbPage->pageHeader.dcs.codingScheme)
285 case SMS_CHARSET_7BIT :
287 MSG_DEBUG("GSM 7 BIT");
289 dataLen = (dataLen*8) / 7;
291 SmsPluginUDCodec udCodec;
292 char pageData[MAX_CBMSG_PAGE_SIZE+1];
293 int unpackLen = udCodec.unpack7bitChar(&cbData[6], dataLen, 0, pageData);
295 if(pCbPage->pageHeader.dcs.iso639Lang[0])
297 unpackLen = unpackLen - 3;
299 memcpy(pCbPage->pageData, &pageData[3], unpackLen);
303 memcpy(pCbPage->pageData, &pageData, unpackLen);
306 MSG_DEBUG("unpackLen : [%d]", unpackLen);
308 pCbPage->pageLength = unpackLen;
309 pCbPage->pageData[unpackLen] = '\0';
313 case SMS_CHARSET_8BIT :
314 case SMS_CHARSET_UCS2 :
316 MSG_DEBUG("UCS2 or 8BIT");
318 if(pCbPage->pageHeader.dcs.iso639Lang[0])
320 memcpy(pCbPage->pageData, &cbData[8], dataLen - 2);
321 pCbPage->pageLength = dataLen - 2;
323 memcpy(pCbPage->pageData, &cbData[6], dataLen);
324 pCbPage->pageLength = dataLen;
330 MSG_DEBUG("Page Length : [%d], Page Data : [%s]", pCbPage->pageLength, pCbPage->pageData);
334 void SmsPluginCbMsgHandler::DecodeEtwsMsg(TelSmsEtwsMsg_t *pEtwsMsg, SMS_ETWS_PRIMARY_S *pEtwsPn)
336 if ( !pEtwsMsg || !pEtwsPn )
339 if (pEtwsMsg->Length > MAX_ETWS_SIZE)
340 THROW(MsgException::SMS_PLG_ERROR, "ETWS Msg Size is over MAX [%d]", pEtwsMsg->Length);
342 unsigned char EtwsData[pEtwsMsg->Length+1];
344 memset(EtwsData, 0x00, sizeof(EtwsData));
345 memcpy(EtwsData, pEtwsMsg->szMsgData, pEtwsMsg->Length);
346 EtwsData[pEtwsMsg->Length] = '\0';
348 // print received msg data
349 MSG_INFO("Received Etws length:%d", pEtwsMsg->Length);
350 char EtwsDataTmp[(pEtwsMsg->Length*2)+1];
351 memset(EtwsDataTmp, 0x00, sizeof(EtwsDataTmp));
353 for (int i = 0; i < pEtwsMsg->Length; i++) {
354 snprintf(EtwsDataTmp+(i*2), sizeof(EtwsDataTmp)-(i*2), "%02X", EtwsData[i]);
356 MSG_INFO("[%s]", EtwsDataTmp);
359 pEtwsPn->recvTime = getRecvTime();
362 pEtwsPn->serialNum.geoScope = (EtwsData[0] & 0xC0) >> 6;
363 pEtwsPn->serialNum.msgCode = (EtwsData[0] & 0x3F) << 4;
364 pEtwsPn->serialNum.msgCode |= (EtwsData[1] & 0xF0) >> 4;
365 pEtwsPn->serialNum.updateNum = EtwsData[1] & 0x0F;
367 MSG_DEBUG("geoScope : [%d], msgCode : [%d], updateNum : [%d]", pEtwsPn->serialNum.geoScope, pEtwsPn->serialNum.msgCode, pEtwsPn->serialNum.updateNum);
369 // Message Identifier
370 pEtwsPn->msgId = (EtwsData[2] << 8) | EtwsData[3];
371 MSG_DEBUG("MSG ID : [%d]", pEtwsPn->msgId);
374 pEtwsPn->warningType = (EtwsData[4] << 8) | EtwsData[5];
375 MSG_DEBUG("warningType : [0x%04x]", pEtwsPn->msgId);
377 // warning security information
378 memcpy(pEtwsPn->warningSecurityInfo, &EtwsData[6], sizeof(pEtwsPn->warningSecurityInfo)); // 50bytes
379 for (unsigned int i = 0; i < sizeof(pEtwsPn->warningSecurityInfo); i++)
381 MSG_DEBUG("warning secu info [%02x]", pEtwsPn->warningSecurityInfo[i] );
385 void SmsPluginCbMsgHandler::Decode3gCbMsg(TelSmsCbMsg_t *pCbMsg, SMS_CBMSG_PAGE_S *pCbPage)
387 unsigned char cbData[(MAX_CBMSG_PAGE_SIZE*MAX_CBMSG_PAGE_NUM)+1];
389 memset(cbData, 0x00, sizeof(cbData));
390 memcpy(cbData, pCbMsg->szMsgData, pCbMsg->Length);
391 cbData[pCbMsg->Length] = '\0';
394 MSG_INFO("Received CB length:%d", pCbMsg->Length);
395 char cbDataTmp[(pCbMsg->Length*2)+1];
396 memset(cbDataTmp, 0x00, sizeof(cbDataTmp));
398 for (int i = 0; i < pCbMsg->Length; i++) {
399 snprintf(cbDataTmp+(i*2), sizeof(cbDataTmp)-(i*2), "%02X", cbData[i]);
401 MSG_INFO("[%s]", cbDataTmp);
403 pCbPage->cbMsgType = (SMS_CBMSG_TYPE_T)cbData[0];
405 pCbPage->pageHeader.msgId = (cbData[1] << 8) | cbData[2];
407 MSG_DEBUG("MSG ID : [%d]", pCbPage->pageHeader.msgId);
410 pCbPage->pageHeader.serialNum.geoScope = (cbData[3] & 0xC0) >> 6;
412 pCbPage->pageHeader.serialNum.msgCode = (cbData[3] & 0x3F) << 4;
413 pCbPage->pageHeader.serialNum.msgCode |= (cbData[4] & 0xF0) >> 4;
415 pCbPage->pageHeader.serialNum.updateNum = cbData[4] & 0x0F;
417 MSG_DEBUG("geoScope : [%d], msgCode : [%d], updateNum : [%d]", pCbPage->pageHeader.serialNum.geoScope, pCbPage->pageHeader.serialNum.msgCode, pCbPage->pageHeader.serialNum.updateNum);
420 decodeCbMsgDCS(cbData[5], (unsigned char*)cbData + 6, &(pCbPage->pageHeader.dcs));
422 // Convert Language Type
423 convertLangType(pCbPage->pageHeader.dcs.langType, &(pCbPage->pageHeader.langType));
425 MSG_DEBUG("In Language Type : [%d], Out Language Type : [%d]", pCbPage->pageHeader.dcs.langType, pCbPage->pageHeader.langType);
428 pCbPage->pageHeader.recvTime = getRecvTime();
429 pCbPage->pageHeader.totalPages = cbData[6];
435 switch (pCbPage->pageHeader.dcs.codingScheme)
437 case SMS_CHARSET_7BIT :
439 for(int i = 0; i < pCbPage->pageHeader.totalPages; ++i)
441 char cbMessage[MAX_CBMSG_PAGE_SIZE]= {0,};
442 dataLen = cbData[7+(i+1)*82 + i];
443 memcpy(cbMessage, &cbData[7+(i*82)+ i], dataLen);
445 dataLen = (dataLen*8) / 7;
447 if (dataLen > MAX_CBMSG_PAGE_SIZE)
448 THROW(MsgException::SMS_PLG_ERROR, "CB Msg Size is over MAX [%d]", dataLen);
450 SmsPluginUDCodec udCodec;
451 int unpackLen = udCodec.unpack7bitChar((const unsigned char *)cbMessage, dataLen, 0, pCbPage->pageData + offset);
454 pCbPage->pageLength = offset;
458 case SMS_CHARSET_8BIT :
459 case SMS_CHARSET_UCS2 :
462 char cbMessage[MAX_CBMSG_PAGE_SIZE]= {0,};
464 for(int i = 0; i < pCbPage->pageHeader.totalPages; ++i)
466 dataLen = cbData[7+(i+1)*82 + i];
467 memcpy(cbMessage + offset, &cbData[7+(i*82)+ i], dataLen);
472 if(pCbPage->pageHeader.dcs.iso639Lang[0])
474 int tmpDataLen = (dataLen > 2)?(dataLen - 2):0;
475 memcpy(pCbPage->pageData, cbMessage + 2, tmpDataLen);
476 pCbPage->pageLength = tmpDataLen;
478 memcpy(pCbPage->pageData, cbMessage, dataLen);
479 pCbPage->pageLength = dataLen;
482 char cbMessage[MAX_CBMSG_PAGE_SIZE]= {0,};
484 for(int i = 0; i < pCbPage->pageHeader.totalPages; ++i)
486 if(pCbPage->pageHeader.dcs.iso639Lang[0])
488 dataLen = cbData[7+(i+1)*82 + i] - 2;
489 memcpy(cbMessage + offset, &cbData[7+(i*82)+ i + 2], dataLen);
492 dataLen = cbData[7+(i+1)*82 + i];
493 memcpy(cbMessage + offset, &cbData[7+(i*82)+ i], dataLen);
498 memcpy(pCbPage->pageData, cbMessage, dataLen);
499 pCbPage->pageLength = dataLen;
504 pCbPage->pageHeader.totalPages = 1;
506 MSG_DEBUG("Page Length : [%d], Page Data : [%s]", pCbPage->pageLength, pCbPage->pageData);
509 unsigned short SmsPluginCbMsgHandler::encodeCbSerialNum ( SMS_CBMSG_SERIAL_NUM_S snFields )
511 unsigned short serialNum = 0;
513 serialNum = ((snFields.geoScope & 0x03) << 14) | ((snFields.msgCode&0x03FF) << 4) | (snFields.updateNum&0x0F);
514 MSG_DEBUG ("serialNum (%x), geo(%x), mc(%x), un(%x)\n", serialNum, snFields.geoScope, snFields.msgCode, snFields.updateNum);
519 int SmsPluginCbMsgHandler::CMAS_class(unsigned short message_id)
527 ret = MSG_CMAS_PRESIDENTIAL;
533 ret = MSG_CMAS_EXTREME;
547 ret = MSG_CMAS_SEVERE;
551 ret = MSG_CMAS_AMBER;
561 ret = MSG_CMAS_OPERATOR_DEFINED;
570 bool SmsPluginCbMsgHandler::checkCbOpt(SMS_CBMSG_PAGE_S *CbPage, bool *pJavaMsg, msg_sim_slot_id_t simIndex)
572 bool bReceive = false;
573 char keyName[MAX_VCONFKEY_NAME_LEN];
574 memset(keyName, 0x00, sizeof(keyName));
575 snprintf(keyName, sizeof(keyName), "%s/%d", CB_RECEIVE, simIndex);
576 MsgSettingGetBool(keyName, &bReceive);
578 // Receive CB Msg = FALSE
581 MSG_DEBUG("RECEIVE CB = FALSE");
588 memset(keyName, 0x00, sizeof(keyName));
589 snprintf(keyName, sizeof(keyname), "%s/%d", CB_LANGUAGE, MSG_CBLANG_TYPE_ALL);
591 bool bAllLang = false;
592 MsgSettingGetBool(keyName, &bAllLang);
596 MSG_DEBUG("ALL LANGUAGE = FALSE");
598 memset(keyName, 0x00, sizeof(keyName));
599 snprintf(keyName, sizeof(keyname), "%s/%d", CB_LANGUAGE, CbPage.pageHeader.langType);
603 MsgSettingGetBool(keyName, &bLang);
605 if (!bLang || CbPage.pageHeader.langType == MSG_CBLANG_TYPE_MAX)
607 MSG_DEBUG("LANGUAGE [%d] = FALSE", CbPage.pageHeader.langType);
613 bool bActivate = false;
614 int MsgId_from = 0, MsgId_to = 0;
615 MSG_CB_CHANNEL_S cbChannelInfo = {0,};
616 msg_error_t err = MSG_SUCCESS;
617 MsgDbHandler *dbHandle = getDbHandle();
619 err = MsgStoGetCBChannelInfo(dbHandle, &cbChannelInfo, simIndex);
620 if (err != MSG_SUCCESS)
621 MSG_ERR("Error value of MsgStoGetCBChannelInfo [%d]", err);
623 for (int i = 0; i < cbChannelInfo.channelCnt; i++)
625 bActivate = cbChannelInfo.channelInfo[i].bActivate;
626 MsgId_from = cbChannelInfo.channelInfo[i].from;
627 MsgId_to = cbChannelInfo.channelInfo[i].to;
629 if (bActivate == true && CbPage->pageHeader.msgId >= MsgId_from && CbPage->pageHeader.msgId <= MsgId_to)
631 MSG_DEBUG("FIND CHANNEL = [%d]", CbPage->pageHeader.msgId);
639 unsigned char SmsPluginCbMsgHandler::checkCbPage(SMS_CBMSG_PAGE_S *CbPage)
641 unsigned char currPageCnt = 0;
646 msg_error_t err = MSG_SUCCESS;
648 SmsPluginStorage *storageHandler = SmsPluginStorage::instance();
649 err = storageHandler->isReceivedCBMessage(CbPage);
650 // check existing message with cb internal table;
651 if(err != MSG_ERR_DB_NORECORD)
653 MSG_DEBUG("already received message: [%d]", CbPage.pageHeader.msgId);
658 if (CbPage->pageHeader.totalPages > 0)
660 for (unsigned int i = 0; i < pageList.size(); i++)
662 if (pageList[i].geoScope == CbPage->pageHeader.serialNum.geoScope && pageList[i].msgCode == CbPage->pageHeader.serialNum.msgCode)
664 MSG_DEBUG("geoScope [%d], msgCode [%d]", pageList[i].geoScope, pageList[i].msgCode);
666 if (pageList[i].msgId == CbPage->pageHeader.msgId)
668 int updateNum = CbPage->pageHeader.serialNum.updateNum - pageList[i].updateNum;
670 if (updateNum > 0) // New Message Content
674 else if (updateNum == 0) // Same Message Content
676 if (pageList[i].data.count(CbPage->pageHeader.page) != 0)
678 MSG_DEBUG("The Page Number already exists [%d]", CbPage->pageHeader.page);
682 pair<unsigned char, SMS_CBMSG_PAGE_S> newData(CbPage->pageHeader.page, *CbPage);
683 pageList[i].data.insert(newData);
685 MSG_DEBUG("PAGE DATA : %s", CbPage->pageData);
686 MSG_DEBUG("PAIR DATA [%d] : %s", newData.first, newData.second.pageData);
688 pageList[i].pageCnt++;
689 pageList[i].totalSize += CbPage->pageLength;
691 currPageCnt = pageList[i].pageCnt;
697 else // Old Message Content
706 if (bFind == false || CbPage->pageHeader.totalPages == 1)
708 addToPageList(CbPage);
716 void SmsPluginCbMsgHandler::MakeCbMsg(SMS_CBMSG_PAGE_S *CbPage, SMS_CBMSG_S *pCbMsg)
718 pCbMsg->cbMsgType = CbPage->cbMsgType;
719 pCbMsg->msgId = CbPage->pageHeader.msgId;
720 pCbMsg->classType = CbPage->pageHeader.dcs.classType;
721 pCbMsg->codingScheme = CbPage->pageHeader.dcs.codingScheme;
722 pCbMsg->recvTime = CbPage->pageHeader.recvTime;
724 cbPageMap::iterator it;
727 for (unsigned int i = 0; i < pageList.size(); i++)
729 if (pageList[i].geoScope == CbPage->pageHeader.serialNum.geoScope && pageList[i].msgCode == CbPage->pageHeader.serialNum.msgCode)
731 MSG_DEBUG("geoScope [%d], msgCode [%d]", pageList[i].geoScope, pageList[i].msgCode);
733 if (pageList[i].msgId == CbPage->pageHeader.msgId)
736 for (it = pageList[i].data.begin(); it != pageList[i].data.end(); it++)
738 memcpy(pCbMsg->msgData + offset, it->second.pageData, it->second.pageLength);
739 pCbMsg->msgLength += it->second.pageLength;
740 offset = pCbMsg->msgLength;
747 pCbMsg->msgLength = tmpStr.size();
749 memcpy(pCbMsg->msgData, tmpStr.c_str(), tmpStr.size());
750 pCbMsg->msgData[tmpStr.size()] = '\0';
752 MSG_DEBUG("SIZE : [%d] TOTAL MSG : %s", tmpStr.size(), tmpStr.c_str());
757 void SmsPluginCbMsgHandler::convertCbMsgToMsginfo(SMS_CBMSG_S *pCbMsg, MSG_MESSAGE_INFO_S *pMsgInfo, msg_sim_slot_id_t simIndex)
759 pMsgInfo->msgId = (msg_message_id_t)pCbMsg->msgId;
761 pMsgInfo->folderId = MSG_CBMSGBOX_ID;
763 // Convert Type values
764 pMsgInfo->msgType.mainType = MSG_SMS_TYPE;
766 if (pCbMsg->cbMsgType == SMS_CBMSG_TYPE_CBS) {
767 int cmas_class = CMAS_class(pCbMsg->msgId);
770 pMsgInfo->msgType.subType = MSG_CB_SMS;
772 pMsgInfo->msgType.subType = (MSG_SUB_TYPE_T)cmas_class;
774 else if (pCbMsg->cbMsgType == SMS_CBMSG_TYPE_JAVACBS) {
775 pMsgInfo->msgType.subType = MSG_JAVACB_SMS;
778 switch(pCbMsg->classType)
780 case SMS_MSG_CLASS_0:
781 pMsgInfo->msgType.classType = MSG_CLASS_0;
783 case SMS_MSG_CLASS_1:
784 pMsgInfo->msgType.classType = MSG_CLASS_1;
786 case SMS_MSG_CLASS_2:
787 pMsgInfo->msgType.classType = MSG_CLASS_2;
789 case SMS_MSG_CLASS_3:
790 pMsgInfo->msgType.classType = MSG_CLASS_3;
793 pMsgInfo->msgType.classType = MSG_CLASS_NONE;
797 pMsgInfo->storageId = MSG_STORAGE_PHONE;
798 pMsgInfo->networkStatus = MSG_NETWORK_RECEIVED;
799 pMsgInfo->bRead = false;
800 pMsgInfo->bProtected = false;
801 pMsgInfo->priority = MSG_MESSAGE_PRIORITY_NORMAL;
802 pMsgInfo->direction = MSG_DIRECTION_TYPE_MT;
805 pMsgInfo->nAddressCnt = 1;
807 pMsgInfo->addressList = (MSG_ADDRESS_INFO_S *)new char[sizeof(MSG_ADDRESS_INFO_S)];
808 memset(pMsgInfo->addressList, 0x00, sizeof(MSG_ADDRESS_INFO_S));
810 pMsgInfo->addressList[0].addressType = MSG_ADDRESS_TYPE_UNKNOWN;
811 pMsgInfo->addressList[0].recipientType = MSG_RECIPIENTS_TYPE_UNKNOWN;
812 pMsgInfo->sim_idx = simIndex;
814 // TODO :: MSG ID should be used to get CB message type
815 getDisplayName(pCbMsg->msgId, pMsgInfo->addressList[0].addressVal, simIndex);
816 MSG_SEC_DEBUG("%s", pMsgInfo->addressList[0].addressVal);
819 pMsgInfo->msgPort.valid = false;
820 pMsgInfo->msgPort.dstPort = 0;
821 pMsgInfo->msgPort.srcPort = 0;
823 pMsgInfo->displayTime = pCbMsg->recvTime;
824 MSG_DEBUG("recvTime is %d", pMsgInfo->displayTime);
826 int bufSize = pCbMsg->msgLength*2;
828 char tmpBuf[bufSize];
829 memset(tmpBuf, 0x00, sizeof(tmpBuf));
831 while (pCbMsg->msgLength > 0) {
832 if (pCbMsg->msgData[pCbMsg->msgLength-1] == ' ' ||
833 pCbMsg->msgData[pCbMsg->msgLength-1] == '\r' ||
834 pCbMsg->msgData[pCbMsg->msgLength-1] == '\n') {
841 pCbMsg->msgData[pCbMsg->msgLength] = '\0';
843 MSG_DEBUG("LENGTH %d CB MSG %s", pCbMsg->msgLength, pCbMsg->msgData);
845 // Convert Data values
846 pMsgInfo->dataSize = convertTextToUtf8((unsigned char*)tmpBuf, bufSize, pCbMsg);
848 if (pMsgInfo->dataSize > MAX_MSG_TEXT_LEN)
850 pMsgInfo->bTextSms = false;
852 // Save Message Data into File
853 char fileName[MSG_FILENAME_LEN_MAX+1];
854 memset(fileName, 0x00, sizeof(fileName));
856 if (MsgCreateFileName(fileName) == false)
857 THROW(MsgException::FILE_ERROR, "MsgCreateFileName error");
859 MSG_SEC_DEBUG("Save Message Data into file : size[%d] name[%s]\n", pMsgInfo->dataSize, fileName);
860 if (MsgWriteIpcFile(fileName, tmpBuf, pMsgInfo->dataSize) == false)
861 THROW(MsgException::FILE_ERROR, "MsgWriteIpcFile error");
863 strncpy(pMsgInfo->msgData, fileName, MAX_MSG_DATA_LEN);
867 pMsgInfo->bTextSms = true;
869 memset(pMsgInfo->msgText, 0x00, sizeof(pMsgInfo->msgText));
870 memcpy(pMsgInfo->msgText, tmpBuf, pMsgInfo->dataSize);
871 pMsgInfo->dataSize = strlen(pMsgInfo->msgText);
872 MSG_SEC_DEBUG("CB MSG %s", pMsgInfo->msgText);
877 void SmsPluginCbMsgHandler::convertEtwsMsgToMsginfo(SMS_CBMSG_PAGE_S *EtwsMsg, MSG_MESSAGE_INFO_S *pMsgInfo, msg_sim_slot_id_t simIndex)
879 pMsgInfo->msgId = (msg_message_id_t)EtwsMsg->pageHeader.msgId;
881 pMsgInfo->folderId = MSG_CBMSGBOX_ID;
883 // Convert Type values
884 pMsgInfo->msgType.mainType = MSG_SMS_TYPE;
886 if (EtwsMsg->cbMsgType == SMS_CBMSG_TYPE_ETWS)
887 pMsgInfo->msgType.subType = MSG_ETWS_SMS;
889 pMsgInfo->storageId = MSG_STORAGE_PHONE;
890 pMsgInfo->networkStatus = MSG_NETWORK_RECEIVED;
891 pMsgInfo->bRead = false;
892 pMsgInfo->bProtected = false;
893 pMsgInfo->priority = MSG_MESSAGE_PRIORITY_NORMAL;
894 pMsgInfo->direction = MSG_DIRECTION_TYPE_MT;
897 pMsgInfo->nAddressCnt = 1;
899 pMsgInfo->addressList[0].addressType = MSG_ADDRESS_TYPE_UNKNOWN;
900 pMsgInfo->addressList[0].recipientType = MSG_RECIPIENTS_TYPE_UNKNOWN;
902 getDisplayName(EtwsMsg->pageHeader.msgId, pMsgInfo->addressList[0].addressVal, simIndex);
903 MSG_SEC_DEBUG("%s", pMsgInfo->addressList[0].addressVal);
905 pMsgInfo->msgPort.valid = false;
906 pMsgInfo->msgPort.dstPort = 0;
907 pMsgInfo->msgPort.srcPort = 0;
909 pMsgInfo->displayTime = EtwsMsg->pageHeader.recvTime;
910 MSG_DEBUG("recvTime is %d", pMsgInfo->displayTime);
911 MSG_DEBUG("LENGTH %d", EtwsMsg->pageLength);
912 pMsgInfo->bTextSms = true;
913 pMsgInfo->dataSize = EtwsMsg->pageLength;
914 memset(pMsgInfo->msgData, 0x00, sizeof(pMsgInfo->msgData));
915 memcpy(pMsgInfo->msgData, EtwsMsg->pageData, pMsgInfo->dataSize);
918 int SmsPluginCbMsgHandler::convertTextToUtf8 (unsigned char* outBuf, int outBufSize, SMS_CBMSG_S* pCbMsg)
920 int convertedTextSize = 0;
921 MSG_LANG_INFO_S langInfo = {0,};
923 MsgTextConvert *textCvt = MsgTextConvert::instance();
925 if (!outBuf || !pCbMsg)
927 MSG_DEBUG ("invalid param.\n");
931 langInfo.bSingleShift = false;
932 langInfo.bLockingShift = false;
935 // Convert Data values
936 if (pCbMsg->codingScheme == SMS_CHARSET_7BIT)
937 convertedTextSize = textCvt->convertGSM7bitToUTF8(outBuf, outBufSize, (unsigned char*)pCbMsg->msgData, pCbMsg->msgLength, &langInfo);
938 else if (pCbMsg->codingScheme == SMS_CHARSET_UCS2)
939 convertedTextSize = textCvt->convertUCS2ToUTF8(outBuf, outBufSize, (unsigned char*)pCbMsg->msgData, pCbMsg->msgLength);
941 return convertedTextSize;
944 void SmsPluginCbMsgHandler::addToPageList(SMS_CBMSG_PAGE_S *CbPage)
946 CB_PAGE_INFO_S tmpInfo;
948 tmpInfo.geoScope = CbPage->pageHeader.serialNum.geoScope;
949 tmpInfo.msgCode = CbPage->pageHeader.serialNum.msgCode;
950 tmpInfo.updateNum = CbPage->pageHeader.serialNum.updateNum;
951 tmpInfo.msgId = CbPage->pageHeader.msgId;
952 tmpInfo.totalPages = CbPage->pageHeader.totalPages;
955 tmpInfo.totalSize = CbPage->pageLength;
957 pair<unsigned char, SMS_CBMSG_PAGE_S> newData(CbPage->pageHeader.page, *CbPage);
958 tmpInfo.data.insert(newData);
960 MSG_DEBUG("MSG DATA : %s", CbPage->pageData);
961 MSG_DEBUG("PAIR DATA [%d] : %s", newData.first, newData.second.pageData);
963 pageList.push_back(tmpInfo);
967 void SmsPluginCbMsgHandler::removeFromPageList(SMS_CBMSG_PAGE_S *CbPage)
971 for (index = 0; index < pageList.size(); index++)
973 if (pageList[index].geoScope == CbPage->pageHeader.serialNum.geoScope && pageList[index].msgCode == CbPage->pageHeader.serialNum.msgCode)
975 MSG_DEBUG("geoScope [%d], msgCode [%d]", pageList[index].geoScope, pageList[index].msgCode);
977 if (pageList[index].msgId == CbPage->pageHeader.msgId) break;
981 MSG_DEBUG("remove index [%d]", index);
983 pageList.erase(pageList.begin()+index);
987 void SmsPluginCbMsgHandler::decodeCbMsgDCS(unsigned char dcsData, const unsigned char *pMsgData, SMS_CBMSG_DCS_S* pDcs)
989 pDcs->codingGroup = SMS_CBMSG_CODGRP_GENERAL_DCS;
990 pDcs->classType = SMS_MSG_CLASS_NONE;
991 pDcs->bCompressed = false;
992 pDcs->codingScheme = SMS_CHARSET_7BIT;
993 pDcs->langType = SMS_CBMSG_LANG_UNSPECIFIED;
994 memset(pDcs->iso639Lang, 0x00, sizeof(pDcs->iso639Lang));
996 pDcs->rawData = dcsData;
998 unsigned char codingGrp = (dcsData & 0xF0) >> 4;
1006 pDcs->codingGroup = SMS_CBMSG_CODGRP_GENERAL_DCS;
1007 pDcs->langType = (SMS_CBMSG_LANG_TYPE_T)dcsData;
1013 if (dcsData == 0x10 || dcsData == 0x11)
1015 pDcs->codingGroup = SMS_CBMSG_CODGRP_GENERAL_DCS;
1016 pDcs->codingScheme = (dcsData & 0x01) ? SMS_CHARSET_UCS2 : SMS_CHARSET_7BIT;
1017 pDcs->langType = SMS_CBMSG_LANG_ISO639;
1018 MSG_DEBUG("codingScheme: [%d]", pDcs->codingScheme);
1019 if (pMsgData[0] && pMsgData[1])
1021 pDcs->iso639Lang[0] = pMsgData[0] & 0x7F;
1022 pDcs->iso639Lang[1] = (pMsgData[0] & 0X80) >> 7;
1023 pDcs->iso639Lang[1] |= (pMsgData[1] & 0X3F) << 1;
1024 pDcs->iso639Lang[2] = 0x13; /* CR */
1028 /* Default it to English if pMsgData is NULL */
1029 pDcs->iso639Lang[0] = 0x45; /* E */
1030 pDcs->iso639Lang[1] = 0x4E; /* N */
1031 pDcs->iso639Lang[2] = 0x13; /* CR */
1042 pDcs->codingGroup = SMS_CBMSG_CODGRP_GENERAL_DCS;
1044 pDcs->bCompressed = (dcsData & 0x20) ? true : false;
1047 pDcs->classType = (SMS_MSG_CLASS_T)(dcsData & 0x03);
1049 unsigned char tmpScheme = (dcsData & 0x0C) >> 2;
1051 switch (tmpScheme) {
1053 pDcs->codingScheme = SMS_CHARSET_7BIT;
1056 pDcs->codingScheme = SMS_CHARSET_8BIT;
1059 pDcs->codingScheme = SMS_CHARSET_UCS2;
1062 MSG_DEBUG("tmpScheme: [%d]", tmpScheme);
1071 pDcs->classType = (MSG_CLASS_TYPE_T)(dcsData & 0x03);
1072 pDcs->codingScheme = (SMS_CODING_SCHEME_T)((dcsData & 0x0C) >> 2);
1078 pDcs->codingGroup = SMS_CBMSG_CODGRP_WAP;
1084 pDcs->codingGroup = SMS_CBMSG_CODGRP_CLASS_CODING;
1085 pDcs->codingScheme = (dcsData & 0x04) ? SMS_CHARSET_8BIT : SMS_CHARSET_7BIT;
1086 pDcs->classType = (MSG_CLASS_TYPE_T)(dcsData & 0x03);
1090 MSG_DEBUG("codingGrp: [0x%x]", codingGrp);
1096 void SmsPluginCbMsgHandler::convertLangType(SMS_CBMSG_LANG_TYPE_T InType , MSG_CB_LANGUAGE_TYPE_T *pOutType)
1100 case SMS_CBMSG_LANG_GERMAN :
1101 *pOutType = MSG_CBLANG_TYPE_GER;
1104 case SMS_CBMSG_LANG_ENGLISH :
1105 *pOutType = MSG_CBLANG_TYPE_ENG;
1108 case SMS_CBMSG_LANG_ITALIAN :
1109 *pOutType = MSG_CBLANG_TYPE_ITA;
1112 case SMS_CBMSG_LANG_FRENCH :
1113 *pOutType = MSG_CBLANG_TYPE_FRE;
1116 case SMS_CBMSG_LANG_SPANISH :
1117 *pOutType = MSG_CBLANG_TYPE_SPA;
1120 case SMS_CBMSG_LANG_DUTCH :
1121 *pOutType = MSG_CBLANG_TYPE_NED;
1124 case SMS_CBMSG_LANG_SWEDISH :
1125 *pOutType = MSG_CBLANG_TYPE_SWE;
1128 case SMS_CBMSG_LANG_PORTUGUESE :
1129 *pOutType = MSG_CBLANG_TYPE_POR;
1132 case SMS_CBMSG_LANG_TURKISH :
1133 *pOutType = MSG_CBLANG_TYPE_TUR;
1137 *pOutType = MSG_CBLANG_TYPE_MAX;
1143 unsigned long SmsPluginCbMsgHandler::getRecvTime()
1147 recvTime = time(NULL);
1149 return (unsigned long)recvTime;
1153 void SmsPluginCbMsgHandler::getDisplayName(unsigned short MsgId, char *pDisplayName, msg_sim_slot_id_t simIndex)
1155 MSG_CB_CHANNEL_S cbChannelInfo = {0,};
1156 msg_error_t err = MSG_SUCCESS;
1157 MsgDbHandler *dbHandle = getDbHandle();
1159 err = MsgStoGetCBChannelInfo(dbHandle, &cbChannelInfo, simIndex);
1160 MSG_DEBUG("MsgStoGetCBChannelInfo [err = %d]", err);
1162 for (int i = 0; i < cbChannelInfo.channelCnt; i++)
1164 if (MsgId >= cbChannelInfo.channelInfo[i].from && MsgId <= cbChannelInfo.channelInfo[i].to)
1166 MSG_DEBUG("FIND MSG ID = [%d]", MsgId);
1168 char strTmp[CB_CHANNEL_NAME_MAX + 1];
1169 memset(strTmp, 0x00, sizeof(strTmp));
1171 strncpy(strTmp, cbChannelInfo.channelInfo[i].name, CB_CHANNEL_NAME_MAX);
1173 if (strlen(strTmp) > 0)
1174 snprintf(pDisplayName, sizeof(strTmp), "[%s]", strTmp);
1176 snprintf(pDisplayName, sizeof(unsigned short), "[%d]", MsgId);
1179 #ifdef MSG_NOTI_INTEGRATION
1180 snprintf(pDisplayName, MAX_ADDRESS_VAL_LEN + 1, "CB message");
1182 snprintf(pDisplayName, MAX_ADDRESS_VAL_LEN + 1, "[%d]", MsgId);
1191 snprintf(pDisplayName, MAX_ADDRESS_VAL_LEN + 1, "[%d]", MsgId);