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};
73 case SMS_CB_NETWORK_TYPE_2G_GSM :
74 Decode2gCbMsg((TelSmsCbMsg_t *)pCbMsg, &CbMsgPage);
77 case SMS_CB_NETWORK_TYPE_3G_UMTS :
78 Decode3gCbMsg((TelSmsCbMsg_t *)pCbMsg, &CbMsgPage);
82 SMS_CB_NETWORK_TYPE_T type = pCbMsg->CbMsgType;
83 SMS_CBMSG_PAGE_S CbMsgPage = {0};
86 case SMS_CB_NETWORK_TYPE_2G_GSM :
87 Decode2gCbMsg(pCbMsg, &CbMsgPage);
90 case SMS_CB_NETWORK_TYPE_3G_UMTS :
91 Decode3gCbMsg(pCbMsg, &CbMsgPage);
95 /* Check CB Msg Options */
96 bool bJavaMsg = false;
98 int simIndex = SmsPluginDSHandler::instance()->getSimIndex(handle);
100 if (!checkCbOpt(&CbMsgPage, &bJavaMsg, simIndex)) {
101 MSG_DEBUG("The CB Msg is not supported by option.");
105 if (bJavaMsg == true) {
106 MSG_DEBUG("JAVA CB Msg.");
107 CbMsgPage.cbMsgType = SMS_CBMSG_TYPE_JAVACBS;
112 unsigned char pageCnt = checkCbPage(&CbMsgPage);
114 if (pageCnt == CbMsgPage.pageHeader.totalPages) {
115 MSG_DEBUG("RECEIVED LAST MSG : %d", pageCnt);
117 SMS_CBMSG_S *cbMsg = NULL;
118 unique_ptr<SMS_CBMSG_S*, void(*)(SMS_CBMSG_S**)> buf(&cbMsg, unique_ptr_deleter);
119 cbMsg = (SMS_CBMSG_S *)new char[sizeof(SMS_CBMSG_S)];
120 memset(cbMsg, 0x00, sizeof(SMS_CBMSG_S));
122 MSG_MESSAGE_INFO_S msgInfo;
124 /** initialize msgInfo */
125 memset(&msgInfo, 0x00, sizeof(MSG_MESSAGE_INFO_S));
127 msgInfo.addressList = NULL;
128 unique_ptr<MSG_ADDRESS_INFO_S*, void(*)(MSG_ADDRESS_INFO_S**)> addressListBuf(&msgInfo.addressList, unique_ptr_deleter);
130 /* Make CB Msg Structure */
131 MakeCbMsg(&CbMsgPage, cbMsg);
133 /* Convert to MSG_MESSAGE_INFO_S */
134 convertCbMsgToMsginfo(cbMsg, &msgInfo, simIndex);
136 /* Add CB Msg into DB */
137 msg_error_t err = MSG_SUCCESS;
139 err = SmsPluginStorage::instance()->checkMessage(&msgInfo);
141 if (err == MSG_SUCCESS) {
142 MSG_CB_MSG_S cbOutMsg = {0, };
144 // cbOutMsg.type = MSG_CB_SMS;
145 cbOutMsg.type = msgInfo.msgType.subType;
146 cbOutMsg.receivedTime = cbMsg->recvTime;
147 cbOutMsg.serialNum = encodeCbSerialNum (CbMsgPage.pageHeader.serialNum);
148 cbOutMsg.messageId = cbMsg->msgId;
149 cbOutMsg.dcs = CbMsgPage.pageHeader.dcs.rawData;
150 memset (cbOutMsg.cbText, 0x00, sizeof(cbOutMsg.cbText));
152 cbOutMsg.cbTextLen= convertTextToUtf8((unsigned char*)cbOutMsg.cbText, sizeof(cbOutMsg.cbText), cbMsg);
153 memset(cbOutMsg.language_type, 0x00, sizeof(cbOutMsg.language_type));
154 memcpy(cbOutMsg.language_type, CbMsgPage.pageHeader.dcs.iso639Lang, 3);
155 err = SmsPluginEventHandler::instance()->callbackCBMsgIncoming(&cbOutMsg, &msgInfo);
156 if (err != MSG_SUCCESS)
157 MSG_WARN("callbackMsgIncoming() Error !! [%d]", err);
159 MSG_WARN("checkMessage() Error !! [%d]", err);
163 // insert message-id to internal CB message table
164 SmsPluginStorage *storageHandler = SmsPluginStorage::instance();
165 err = storageHandler->insertReceivedCBMessage(CbMsgPage);
166 if (err != MSG_SUCCESS)
168 MSG_DEBUG("insertReceivedCBMessage() Error !! [%d]", err);
171 /* Remove From List */
172 removeFromPageList(&CbMsgPage);
178 void SmsPluginCbMsgHandler::handleEtwsMsg(TapiHandle *handle, TelSmsEtwsMsg_t *pEtwsMsg)
181 msg_error_t err = MSG_SUCCESS;
182 TelSmsEtwsMsgType_t type = pEtwsMsg->EtwsMsgType;
183 //MSG_MESSAGE_INFO_S msgInfo = {};
184 SMS_ETWS_PRIMARY_S etwsPn = {0, };
185 MSG_CB_MSG_S cbOutMsg = {0, };
187 if (type != TAPI_NETTEXT_ETWS_PRIMARY) {
188 MSG_DEBUG("The Etws secondary Message");
189 handleCbMsg(handle, (TelSmsCbMsg_t *)pEtwsMsg);
192 DecodeEtwsMsg(pEtwsMsg, &etwsPn);
193 //convertEtwsMsgToMsginfo(&CbMsgPage, &msgInfo, simIndex);
195 cbOutMsg.type = MSG_ETWS_SMS;
196 cbOutMsg.receivedTime = etwsPn.recvTime;
197 cbOutMsg.serialNum = encodeCbSerialNum (etwsPn.serialNum);
198 cbOutMsg.messageId = etwsPn.msgId;
199 cbOutMsg.etwsWarningType = etwsPn.warningType;
200 memcpy (cbOutMsg.etwsWarningSecurityInfo, etwsPn.warningSecurityInfo, sizeof(cbOutMsg.etwsWarningSecurityInfo));
202 err = SmsPluginEventHandler::instance()->callbackCBMsgIncoming(&cbOutMsg, NULL);
203 if (err != MSG_SUCCESS)
204 MSG_DEBUG("callbackMsgIncoming() Error !! [%d]", err);
210 void SmsPluginCbMsgHandler::Decode2gCbMsg(TelSmsCbMsg_t *pCbMsg, SMS_CBMSG_PAGE_S *pCbPage)
212 unsigned char cbData[pCbMsg->Length+1];
214 memset(cbData, 0x00, sizeof(cbData));
215 memcpy(cbData, pCbMsg->szMsgData, pCbMsg->Length);
216 cbData[pCbMsg->Length] = '\0';
219 MSG_INFO("Received CB length:%d", pCbMsg->Length);
220 char cbDataTmp[(pCbMsg->Length*2)+1];
221 memset(cbDataTmp, 0x00, sizeof(cbDataTmp));
223 for (int i = 0; i < pCbMsg->Length; i++) {
224 snprintf(cbDataTmp+(i*2), sizeof(cbDataTmp)-(i*2), "%02X", cbData[i]);
226 MSG_INFO("[%s]", cbDataTmp);
228 pCbPage->cbMsgType = SMS_CBMSG_TYPE_CBS;
231 pCbPage->pageHeader.serialNum.geoScope = (cbData[0] & 0xC0) >> 6;
233 pCbPage->pageHeader.serialNum.msgCode = (cbData[0] & 0x3F) << 4;
234 pCbPage->pageHeader.serialNum.msgCode |= (cbData[1] & 0xF0) >> 4;
236 pCbPage->pageHeader.serialNum.updateNum = cbData[1] & 0x0F;
238 MSG_DEBUG("geoScope : [%d], msgCode : [%d], updateNum : [%d]", pCbPage->pageHeader.serialNum.geoScope, pCbPage->pageHeader.serialNum.msgCode, pCbPage->pageHeader.serialNum.updateNum);
240 pCbPage->pageHeader.msgId = (cbData[2] << 8) | cbData[3];
242 MSG_DEBUG("MSG ID : [%d]", pCbPage->pageHeader.msgId);
245 decodeCbMsgDCS(cbData[4], (unsigned char*)cbData + 6, &(pCbPage->pageHeader.dcs));
248 pCbPage->pageHeader.totalPages = cbData[5] & 0x0F;
249 pCbPage->pageHeader.page = (cbData[5] & 0xF0) >> 4;
251 if (pCbPage->pageHeader.totalPages > MAX_CBMSG_PAGE_NUM)
252 THROW(MsgException::SMS_PLG_ERROR, "CB Page Count is over MAX[%d]", pCbPage->pageHeader.totalPages);
254 MSG_DEBUG("Total Page : [%d], Page : [%d]", pCbPage->pageHeader.totalPages, pCbPage->pageHeader.page);
256 /* Convert Language Type */
257 convertLangType(pCbPage->pageHeader.dcs.langType, &(pCbPage->pageHeader.langType));
259 MSG_DEBUG("In Language Type : [%d], Out Language Type : [%d]", pCbPage->pageHeader.dcs.langType, pCbPage->pageHeader.langType);
260 MSG_DEBUG("iso639Lang : [%s]", pCbPage->pageHeader.dcs.iso639Lang);
261 /* Get Receive Time */
262 pCbPage->pageHeader.recvTime = getRecvTime();
265 int dataLen = pCbMsg->Length - 6;
267 MSG_DEBUG("codingScheme:[%d]", pCbPage->pageHeader.dcs.codingScheme);
269 switch (pCbPage->pageHeader.dcs.codingScheme) {
270 case SMS_CHARSET_7BIT :
272 MSG_DEBUG("GSM 7 BIT");
274 dataLen = (dataLen*8) / 7;
276 SmsPluginUDCodec udCodec;
277 char pageData[MAX_CBMSG_PAGE_SIZE+1];
278 int unpackLen = udCodec.unpack7bitChar(&cbData[6], dataLen, 0, pageData);
280 if (pCbPage->pageHeader.dcs.iso639Lang[0]) {
281 unpackLen = unpackLen - 3;
283 memcpy(pCbPage->pageData, &pageData[3], unpackLen);
287 memcpy(pCbPage->pageData, &pageData, unpackLen);
290 MSG_DEBUG("unpackLen : [%d]", unpackLen);
292 pCbPage->pageLength = unpackLen;
293 pCbPage->pageData[unpackLen] = '\0';
297 case SMS_CHARSET_8BIT :
298 case SMS_CHARSET_UCS2 :
300 MSG_DEBUG("UCS2 or 8BIT");
302 if (pCbPage->pageHeader.dcs.iso639Lang[0]) {
303 memcpy(pCbPage->pageData, &cbData[8], dataLen - 2);
304 pCbPage->pageLength = dataLen - 2;
306 memcpy(pCbPage->pageData, &cbData[6], dataLen);
307 pCbPage->pageLength = dataLen;
313 MSG_DEBUG("Page Length : [%d], Page Data : [%s]", pCbPage->pageLength, pCbPage->pageData);
317 void SmsPluginCbMsgHandler::DecodeEtwsMsg(TelSmsEtwsMsg_t *pEtwsMsg, SMS_ETWS_PRIMARY_S *pEtwsPn)
319 if ( !pEtwsMsg || !pEtwsPn )
322 if (pEtwsMsg->Length > MAX_ETWS_SIZE)
323 THROW(MsgException::SMS_PLG_ERROR, "ETWS Msg Size is over MAX [%d]", pEtwsMsg->Length);
325 unsigned char EtwsData[pEtwsMsg->Length+1];
327 memset(EtwsData, 0x00, sizeof(EtwsData));
328 memcpy(EtwsData, pEtwsMsg->szMsgData, pEtwsMsg->Length);
329 EtwsData[pEtwsMsg->Length] = '\0';
331 /* print received msg data */
332 MSG_INFO("Received Etws length:%d", pEtwsMsg->Length);
333 char EtwsDataTmp[(pEtwsMsg->Length*2)+1];
334 memset(EtwsDataTmp, 0x00, sizeof(EtwsDataTmp));
336 for (int i = 0; i < pEtwsMsg->Length; i++) {
337 snprintf(EtwsDataTmp+(i*2), sizeof(EtwsDataTmp)-(i*2), "%02X", EtwsData[i]);
339 MSG_INFO("[%s]", EtwsDataTmp);
342 pEtwsPn->recvTime = getRecvTime();
345 pEtwsPn->serialNum.geoScope = (EtwsData[0] & 0xC0) >> 6;
346 pEtwsPn->serialNum.msgCode = (EtwsData[0] & 0x3F) << 4;
347 pEtwsPn->serialNum.msgCode |= (EtwsData[1] & 0xF0) >> 4;
348 pEtwsPn->serialNum.updateNum = EtwsData[1] & 0x0F;
350 MSG_DEBUG("geoScope : [%d], msgCode : [%d], updateNum : [%d]", pEtwsPn->serialNum.geoScope, pEtwsPn->serialNum.msgCode, pEtwsPn->serialNum.updateNum);
352 /* Message Identifier */
353 pEtwsPn->msgId = (EtwsData[2] << 8) | EtwsData[3];
354 MSG_DEBUG("MSG ID : [%d]", pEtwsPn->msgId);
357 pEtwsPn->warningType = (EtwsData[4] << 8) | EtwsData[5];
358 MSG_DEBUG("warningType : [0x%04x]", pEtwsPn->msgId);
360 /* warning security information */
361 memcpy(pEtwsPn->warningSecurityInfo, &EtwsData[6], sizeof(pEtwsPn->warningSecurityInfo)); /* 50bytes */
362 for (unsigned int i = 0; i < sizeof(pEtwsPn->warningSecurityInfo); i++) {
363 MSG_DEBUG("warning secu info [%02x]", pEtwsPn->warningSecurityInfo[i] );
367 void SmsPluginCbMsgHandler::Decode3gCbMsg(TelSmsCbMsg_t *pCbMsg, SMS_CBMSG_PAGE_S *pCbPage)
369 unsigned char cbData[(MAX_CBMSG_PAGE_SIZE*MAX_CBMSG_PAGE_NUM)+1];
371 memset(cbData, 0x00, sizeof(cbData));
372 memcpy(cbData, pCbMsg->szMsgData, pCbMsg->Length);
373 cbData[pCbMsg->Length] = '\0';
376 MSG_INFO("Received CB length:%d", pCbMsg->Length);
377 char cbDataTmp[(pCbMsg->Length*2)+1];
378 memset(cbDataTmp, 0x00, sizeof(cbDataTmp));
380 for (int i = 0; i < pCbMsg->Length; i++) {
381 snprintf(cbDataTmp+(i*2), sizeof(cbDataTmp)-(i*2), "%02X", cbData[i]);
383 MSG_INFO("[%s]", cbDataTmp);
385 pCbPage->cbMsgType = (SMS_CBMSG_TYPE_T)cbData[0];
387 pCbPage->pageHeader.msgId = (cbData[1] << 8) | cbData[2];
389 MSG_DEBUG("MSG ID : [%d]", pCbPage->pageHeader.msgId);
392 pCbPage->pageHeader.serialNum.geoScope = (cbData[3] & 0xC0) >> 6;
394 pCbPage->pageHeader.serialNum.msgCode = (cbData[3] & 0x3F) << 4;
395 pCbPage->pageHeader.serialNum.msgCode |= (cbData[4] & 0xF0) >> 4;
397 pCbPage->pageHeader.serialNum.updateNum = cbData[4] & 0x0F;
399 MSG_DEBUG("geoScope : [%d], msgCode : [%d], updateNum : [%d]", pCbPage->pageHeader.serialNum.geoScope, pCbPage->pageHeader.serialNum.msgCode, pCbPage->pageHeader.serialNum.updateNum);
402 decodeCbMsgDCS(cbData[5], (unsigned char*)cbData + 6, &(pCbPage->pageHeader.dcs));
404 /* Convert Language Type */
405 convertLangType(pCbPage->pageHeader.dcs.langType, &(pCbPage->pageHeader.langType));
407 MSG_DEBUG("In Language Type : [%d], Out Language Type : [%d]", pCbPage->pageHeader.dcs.langType, pCbPage->pageHeader.langType);
409 /* Get Receive Time */
410 pCbPage->pageHeader.recvTime = getRecvTime();
411 pCbPage->pageHeader.totalPages = cbData[6];
417 switch (pCbPage->pageHeader.dcs.codingScheme) {
418 case SMS_CHARSET_7BIT :
420 for (int i = 0; i < pCbPage->pageHeader.totalPages; ++i) {
421 char cbMessage[MAX_CBMSG_PAGE_SIZE]= {0,};
422 dataLen = cbData[7+(i+1)*82 + i];
423 memcpy(cbMessage, &cbData[7+(i*82)+ i], dataLen);
425 dataLen = (dataLen*8) / 7;
427 if (dataLen > MAX_CBMSG_PAGE_SIZE)
428 THROW(MsgException::SMS_PLG_ERROR, "CB Msg Size is over MAX [%d]", dataLen);
430 SmsPluginUDCodec udCodec;
431 int unpackLen = udCodec.unpack7bitChar((const unsigned char *)cbMessage, dataLen, 0, pCbPage->pageData + offset);
434 pCbPage->pageLength = offset;
438 case SMS_CHARSET_8BIT :
439 case SMS_CHARSET_UCS2 :
442 char cbMessage[MAX_CBMSG_PAGE_SIZE]= {0,};
444 for (int i = 0; i < pCbPage->pageHeader.totalPages; ++i) {
445 dataLen = cbData[7+(i+1)*82 + i];
446 memcpy(cbMessage + offset, &cbData[7+(i*82)+ i], dataLen);
451 if (pCbPage->pageHeader.dcs.iso639Lang[0]) {
452 int tmpDataLen = (dataLen > 2)?(dataLen - 2):0;
453 memcpy(pCbPage->pageData, cbMessage + 2, tmpDataLen);
454 pCbPage->pageLength = tmpDataLen;
456 memcpy(pCbPage->pageData, cbMessage, dataLen);
457 pCbPage->pageLength = dataLen;
460 char cbMessage[MAX_CBMSG_PAGE_SIZE]= {0,};
462 for (int i = 0; i < pCbPage->pageHeader.totalPages; ++i) {
463 if (pCbPage->pageHeader.dcs.iso639Lang[0]) {
464 dataLen = cbData[7+(i+1)*82 + i] - 2;
465 memcpy(cbMessage + offset, &cbData[7+(i*82)+ i + 2], dataLen);
468 dataLen = cbData[7+(i+1)*82 + i];
469 memcpy(cbMessage + offset, &cbData[7+(i*82)+ i], dataLen);
474 memcpy(pCbPage->pageData, cbMessage, dataLen);
475 pCbPage->pageLength = dataLen;
480 pCbPage->pageHeader.totalPages = 1;
482 MSG_DEBUG("Page Length : [%d], Page Data : [%s]", pCbPage->pageLength, pCbPage->pageData);
485 unsigned short SmsPluginCbMsgHandler::encodeCbSerialNum ( SMS_CBMSG_SERIAL_NUM_S snFields )
487 unsigned short serialNum = 0;
489 serialNum = ((snFields.geoScope & 0x03) << 14) | ((snFields.msgCode&0x03FF) << 4) | (snFields.updateNum&0x0F);
490 MSG_DEBUG ("serialNum (%x), geo(%x), mc(%x), un(%x)\n", serialNum, snFields.geoScope, snFields.msgCode, snFields.updateNum);
495 int SmsPluginCbMsgHandler::CMAS_class(unsigned short message_id)
503 ret = MSG_CMAS_PRESIDENTIAL;
509 ret = MSG_CMAS_EXTREME;
523 ret = MSG_CMAS_SEVERE;
527 ret = MSG_CMAS_AMBER;
535 ret = MSG_CMAS_EXERCISE;
539 ret = MSG_CMAS_OPERATOR_DEFINED;
548 bool SmsPluginCbMsgHandler::checkCbOpt(SMS_CBMSG_PAGE_S *CbPage, bool *pJavaMsg, msg_sim_slot_id_t simIndex)
550 bool bReceive = false;
551 char keyName[MAX_VCONFKEY_NAME_LEN];
552 memset(keyName, 0x00, sizeof(keyName));
553 snprintf(keyName, sizeof(keyName), "%s/%d", CB_RECEIVE, simIndex);
554 MsgSettingGetBool(keyName, &bReceive);
556 /* Receive CB Msg = FALSE */
558 MSG_DEBUG("RECEIVE CB = FALSE");
565 memset(keyName, 0x00, sizeof(keyName));
566 snprintf(keyName, sizeof(keyname), "%s/%d", CB_LANGUAGE, MSG_CBLANG_TYPE_ALL);
568 bool bAllLang = false;
569 MsgSettingGetBool(keyName, &bAllLang);
572 MSG_DEBUG("ALL LANGUAGE = FALSE");
574 memset(keyName, 0x00, sizeof(keyName));
575 snprintf(keyName, sizeof(keyname), "%s/%d", CB_LANGUAGE, CbPage.pageHeader.langType);
579 MsgSettingGetBool(keyName, &bLang);
581 if (!bLang || CbPage.pageHeader.langType == MSG_CBLANG_TYPE_MAX) {
582 MSG_DEBUG("LANGUAGE [%d] = FALSE", CbPage.pageHeader.langType);
588 bool bActivate = false;
589 int MsgId_from = 0, MsgId_to = 0;
590 MSG_CB_CHANNEL_S cbChannelInfo = {0,};
591 msg_error_t err = MSG_SUCCESS;
592 MsgDbHandler *dbHandle = getDbHandle();
594 err = MsgStoGetCBChannelInfo(dbHandle, &cbChannelInfo, simIndex);
595 if (err != MSG_SUCCESS)
596 MSG_ERR("Error value of MsgStoGetCBChannelInfo [%d]", err);
598 for (int i = 0; i < cbChannelInfo.channelCnt; i++) {
599 bActivate = cbChannelInfo.channelInfo[i].bActivate;
600 MsgId_from = cbChannelInfo.channelInfo[i].from;
601 MsgId_to = cbChannelInfo.channelInfo[i].to;
603 if (bActivate == true && CbPage->pageHeader.msgId >= MsgId_from && CbPage->pageHeader.msgId <= MsgId_to) {
604 MSG_DEBUG("FIND CHANNEL = [%d]", CbPage->pageHeader.msgId);
612 unsigned char SmsPluginCbMsgHandler::checkCbPage(SMS_CBMSG_PAGE_S *CbPage)
614 unsigned char currPageCnt = 0;
619 msg_error_t err = MSG_SUCCESS;
621 SmsPluginStorage *storageHandler = SmsPluginStorage::instance();
622 err = storageHandler->isReceivedCBMessage(CbPage);
623 // check existing message with cb internal table;
624 if (err != MSG_ERR_DB_NORECORD)
626 MSG_DEBUG("already received message: [%d]", CbPage.pageHeader.msgId);
631 if (CbPage->pageHeader.totalPages > 0) {
632 for (unsigned int i = 0; i < pageList.size(); i++) {
633 if (pageList[i].geoScope == CbPage->pageHeader.serialNum.geoScope && pageList[i].msgCode == CbPage->pageHeader.serialNum.msgCode) {
634 MSG_DEBUG("geoScope [%d], msgCode [%d]", pageList[i].geoScope, pageList[i].msgCode);
636 if (pageList[i].msgId == CbPage->pageHeader.msgId) {
637 int updateNum = CbPage->pageHeader.serialNum.updateNum - pageList[i].updateNum;
639 if (updateNum > 0) { /* New Message Content */
641 } else if (updateNum == 0) { /* Same Message Content */
642 if (pageList[i].data.count(CbPage->pageHeader.page) != 0) {
643 MSG_DEBUG("The Page Number already exists [%d]", CbPage->pageHeader.page);
647 pair<unsigned char, SMS_CBMSG_PAGE_S> newData(CbPage->pageHeader.page, *CbPage);
648 pageList[i].data.insert(newData);
650 MSG_DEBUG("PAGE DATA : %s", CbPage->pageData);
651 MSG_DEBUG("PAIR DATA [%d] : %s", newData.first, newData.second.pageData);
653 pageList[i].pageCnt++;
654 pageList[i].totalSize += CbPage->pageLength;
656 currPageCnt = pageList[i].pageCnt;
661 } else { /* Old Message Content */
669 if (bFind == false || CbPage->pageHeader.totalPages == 1) {
670 addToPageList(CbPage);
678 void SmsPluginCbMsgHandler::MakeCbMsg(SMS_CBMSG_PAGE_S *CbPage, SMS_CBMSG_S *pCbMsg)
680 pCbMsg->cbMsgType = CbPage->cbMsgType;
681 pCbMsg->msgId = CbPage->pageHeader.msgId;
682 pCbMsg->classType = CbPage->pageHeader.dcs.classType;
683 pCbMsg->codingScheme = CbPage->pageHeader.dcs.codingScheme;
684 pCbMsg->recvTime = CbPage->pageHeader.recvTime;
686 cbPageMap::iterator it;
689 for (unsigned int i = 0; i < pageList.size(); i++) {
690 if (pageList[i].geoScope == CbPage->pageHeader.serialNum.geoScope && pageList[i].msgCode == CbPage->pageHeader.serialNum.msgCode) {
691 MSG_DEBUG("geoScope [%d], msgCode [%d]", pageList[i].geoScope, pageList[i].msgCode);
693 if (pageList[i].msgId == CbPage->pageHeader.msgId) {
694 for (it = pageList[i].data.begin(); it != pageList[i].data.end(); it++) {
695 memcpy(pCbMsg->msgData + offset, it->second.pageData, it->second.pageLength);
696 pCbMsg->msgLength += it->second.pageLength;
697 offset = pCbMsg->msgLength;
704 pCbMsg->msgLength = tmpStr.size();
706 memcpy(pCbMsg->msgData, tmpStr.c_str(), tmpStr.size());
707 pCbMsg->msgData[tmpStr.size()] = '\0';
709 MSG_DEBUG("SIZE : [%d] TOTAL MSG : %s", tmpStr.size(), tmpStr.c_str());
714 void SmsPluginCbMsgHandler::convertCbMsgToMsginfo(SMS_CBMSG_S *pCbMsg, MSG_MESSAGE_INFO_S *pMsgInfo, msg_sim_slot_id_t simIndex)
716 pMsgInfo->msgId = (msg_message_id_t)pCbMsg->msgId;
718 pMsgInfo->folderId = MSG_CBMSGBOX_ID;
720 /* Convert Type values */
721 pMsgInfo->msgType.mainType = MSG_SMS_TYPE;
723 if (pCbMsg->cbMsgType == SMS_CBMSG_TYPE_CBS) {
724 int cmas_class = CMAS_class(pCbMsg->msgId);
727 pMsgInfo->msgType.subType = MSG_CB_SMS;
729 pMsgInfo->msgType.subType = (MSG_SUB_TYPE_T)cmas_class;
730 } else if (pCbMsg->cbMsgType == SMS_CBMSG_TYPE_JAVACBS) {
731 pMsgInfo->msgType.subType = MSG_JAVACB_SMS;
734 switch (pCbMsg->classType) {
735 case SMS_MSG_CLASS_0:
736 pMsgInfo->msgType.classType = MSG_CLASS_0;
738 case SMS_MSG_CLASS_1:
739 pMsgInfo->msgType.classType = MSG_CLASS_1;
741 case SMS_MSG_CLASS_2:
742 pMsgInfo->msgType.classType = MSG_CLASS_2;
744 case SMS_MSG_CLASS_3:
745 pMsgInfo->msgType.classType = MSG_CLASS_3;
748 pMsgInfo->msgType.classType = MSG_CLASS_NONE;
752 pMsgInfo->storageId = MSG_STORAGE_PHONE;
753 pMsgInfo->networkStatus = MSG_NETWORK_RECEIVED;
754 pMsgInfo->bRead = false;
755 pMsgInfo->bProtected = false;
756 pMsgInfo->priority = MSG_MESSAGE_PRIORITY_NORMAL;
757 pMsgInfo->direction = MSG_DIRECTION_TYPE_MT;
760 pMsgInfo->nAddressCnt = 1;
762 pMsgInfo->addressList = (MSG_ADDRESS_INFO_S *)new char[sizeof(MSG_ADDRESS_INFO_S)];
763 memset(pMsgInfo->addressList, 0x00, sizeof(MSG_ADDRESS_INFO_S));
765 pMsgInfo->addressList[0].addressType = MSG_ADDRESS_TYPE_UNKNOWN;
766 pMsgInfo->addressList[0].recipientType = MSG_RECIPIENTS_TYPE_UNKNOWN;
767 pMsgInfo->sim_idx = simIndex;
769 /* TODO :: MSG ID should be used to get CB message type */
770 getDisplayName(pCbMsg->msgId, pMsgInfo->addressList[0].addressVal, simIndex);
771 MSG_SEC_DEBUG("%s", pMsgInfo->addressList[0].addressVal);
774 pMsgInfo->msgPort.valid = false;
775 pMsgInfo->msgPort.dstPort = 0;
776 pMsgInfo->msgPort.srcPort = 0;
778 pMsgInfo->displayTime = pCbMsg->recvTime;
779 MSG_DEBUG("recvTime is %d", pMsgInfo->displayTime);
781 int bufSize = pCbMsg->msgLength*2;
783 char tmpBuf[bufSize];
784 memset(tmpBuf, 0x00, sizeof(tmpBuf));
786 while (pCbMsg->msgLength > 0) {
787 if (pCbMsg->msgData[pCbMsg->msgLength-1] == ' ' ||
788 pCbMsg->msgData[pCbMsg->msgLength-1] == '\r' ||
789 pCbMsg->msgData[pCbMsg->msgLength-1] == '\n') {
796 pCbMsg->msgData[pCbMsg->msgLength] = '\0';
798 MSG_DEBUG("LENGTH %d CB MSG %s", pCbMsg->msgLength, pCbMsg->msgData);
800 /* Convert Data values */
801 pMsgInfo->dataSize = convertTextToUtf8((unsigned char*)tmpBuf, bufSize, pCbMsg);
803 if (pMsgInfo->dataSize > MAX_MSG_TEXT_LEN) {
804 pMsgInfo->bTextSms = false;
806 /* Save Message Data into File */
807 char fileName[MSG_FILENAME_LEN_MAX+1];
808 memset(fileName, 0x00, sizeof(fileName));
810 if (MsgCreateFileName(fileName) == false)
811 THROW(MsgException::FILE_ERROR, "MsgCreateFileName error");
813 MSG_SEC_DEBUG("Save Message Data into file : size[%d] name[%s]\n", pMsgInfo->dataSize, fileName);
814 if (MsgWriteIpcFile(fileName, tmpBuf, pMsgInfo->dataSize) == false)
815 THROW(MsgException::FILE_ERROR, "MsgWriteIpcFile error");
817 strncpy(pMsgInfo->msgData, fileName, MAX_MSG_DATA_LEN);
819 pMsgInfo->bTextSms = true;
821 memset(pMsgInfo->msgText, 0x00, sizeof(pMsgInfo->msgText));
822 memcpy(pMsgInfo->msgText, tmpBuf, pMsgInfo->dataSize);
823 pMsgInfo->dataSize = strlen(pMsgInfo->msgText);
824 MSG_SEC_DEBUG("CB MSG %s", pMsgInfo->msgText);
829 void SmsPluginCbMsgHandler::convertEtwsMsgToMsginfo(SMS_CBMSG_PAGE_S *EtwsMsg, MSG_MESSAGE_INFO_S *pMsgInfo, msg_sim_slot_id_t simIndex)
831 pMsgInfo->msgId = (msg_message_id_t)EtwsMsg->pageHeader.msgId;
833 pMsgInfo->folderId = MSG_CBMSGBOX_ID;
835 /* Convert Type values */
836 pMsgInfo->msgType.mainType = MSG_SMS_TYPE;
838 if (EtwsMsg->cbMsgType == SMS_CBMSG_TYPE_ETWS)
839 pMsgInfo->msgType.subType = MSG_ETWS_SMS;
841 pMsgInfo->storageId = MSG_STORAGE_PHONE;
842 pMsgInfo->networkStatus = MSG_NETWORK_RECEIVED;
843 pMsgInfo->bRead = false;
844 pMsgInfo->bProtected = false;
845 pMsgInfo->priority = MSG_MESSAGE_PRIORITY_NORMAL;
846 pMsgInfo->direction = MSG_DIRECTION_TYPE_MT;
849 pMsgInfo->nAddressCnt = 1;
851 pMsgInfo->addressList[0].addressType = MSG_ADDRESS_TYPE_UNKNOWN;
852 pMsgInfo->addressList[0].recipientType = MSG_RECIPIENTS_TYPE_UNKNOWN;
854 getDisplayName(EtwsMsg->pageHeader.msgId, pMsgInfo->addressList[0].addressVal, simIndex);
855 MSG_SEC_DEBUG("%s", pMsgInfo->addressList[0].addressVal);
857 pMsgInfo->msgPort.valid = false;
858 pMsgInfo->msgPort.dstPort = 0;
859 pMsgInfo->msgPort.srcPort = 0;
861 pMsgInfo->displayTime = EtwsMsg->pageHeader.recvTime;
862 MSG_DEBUG("recvTime is %d", pMsgInfo->displayTime);
863 MSG_DEBUG("LENGTH %d", EtwsMsg->pageLength);
864 pMsgInfo->bTextSms = true;
865 pMsgInfo->dataSize = EtwsMsg->pageLength;
866 memset(pMsgInfo->msgData, 0x00, sizeof(pMsgInfo->msgData));
867 memcpy(pMsgInfo->msgData, EtwsMsg->pageData, pMsgInfo->dataSize);
870 int SmsPluginCbMsgHandler::convertTextToUtf8 (unsigned char* outBuf, int outBufSize, SMS_CBMSG_S* pCbMsg)
872 int convertedTextSize = 0;
873 MSG_LANG_INFO_S langInfo = {0,};
875 MsgTextConvert *textCvt = MsgTextConvert::instance();
877 if (!outBuf || !pCbMsg) {
878 MSG_DEBUG ("invalid param.\n");
882 langInfo.bSingleShift = false;
883 langInfo.bLockingShift = false;
886 /* Convert Data values */
887 if (pCbMsg->codingScheme == SMS_CHARSET_7BIT)
888 convertedTextSize = textCvt->convertGSM7bitToUTF8(outBuf, outBufSize, (unsigned char*)pCbMsg->msgData, pCbMsg->msgLength, &langInfo);
889 else if (pCbMsg->codingScheme == SMS_CHARSET_UCS2)
890 convertedTextSize = textCvt->convertUCS2ToUTF8(outBuf, outBufSize, (unsigned char*)pCbMsg->msgData, pCbMsg->msgLength);
892 return convertedTextSize;
895 void SmsPluginCbMsgHandler::addToPageList(SMS_CBMSG_PAGE_S *CbPage)
897 CB_PAGE_INFO_S tmpInfo;
899 tmpInfo.geoScope = CbPage->pageHeader.serialNum.geoScope;
900 tmpInfo.msgCode = CbPage->pageHeader.serialNum.msgCode;
901 tmpInfo.updateNum = CbPage->pageHeader.serialNum.updateNum;
902 tmpInfo.msgId = CbPage->pageHeader.msgId;
903 tmpInfo.totalPages = CbPage->pageHeader.totalPages;
906 tmpInfo.totalSize = CbPage->pageLength;
908 pair<unsigned char, SMS_CBMSG_PAGE_S> newData(CbPage->pageHeader.page, *CbPage);
909 tmpInfo.data.insert(newData);
911 MSG_DEBUG("MSG DATA : %s", CbPage->pageData);
912 MSG_DEBUG("PAIR DATA [%d] : %s", newData.first, newData.second.pageData);
914 pageList.push_back(tmpInfo);
918 void SmsPluginCbMsgHandler::removeFromPageList(SMS_CBMSG_PAGE_S *CbPage)
922 for (index = 0; index < pageList.size(); index++) {
923 if (pageList[index].geoScope == CbPage->pageHeader.serialNum.geoScope && pageList[index].msgCode == CbPage->pageHeader.serialNum.msgCode) {
924 MSG_DEBUG("geoScope [%d], msgCode [%d]", pageList[index].geoScope, pageList[index].msgCode);
926 if (pageList[index].msgId == CbPage->pageHeader.msgId)
931 MSG_DEBUG("remove index [%d]", index);
933 pageList.erase(pageList.begin()+index);
937 void SmsPluginCbMsgHandler::decodeCbMsgDCS(unsigned char dcsData, const unsigned char *pMsgData, SMS_CBMSG_DCS_S* pDcs)
939 pDcs->codingGroup = SMS_CBMSG_CODGRP_GENERAL_DCS;
940 pDcs->classType = SMS_MSG_CLASS_NONE;
941 pDcs->bCompressed = false;
942 pDcs->codingScheme = SMS_CHARSET_7BIT;
943 pDcs->langType = SMS_CBMSG_LANG_UNSPECIFIED;
944 memset(pDcs->iso639Lang, 0x00, sizeof(pDcs->iso639Lang));
946 pDcs->rawData = dcsData;
948 unsigned char codingGrp = (dcsData & 0xF0) >> 4;
955 pDcs->codingGroup = SMS_CBMSG_CODGRP_GENERAL_DCS;
956 pDcs->langType = (SMS_CBMSG_LANG_TYPE_T)dcsData;
962 if (dcsData == 0x10 || dcsData == 0x11) {
963 pDcs->codingGroup = SMS_CBMSG_CODGRP_GENERAL_DCS;
964 pDcs->codingScheme = (dcsData & 0x01) ? SMS_CHARSET_UCS2 : SMS_CHARSET_7BIT;
965 pDcs->langType = SMS_CBMSG_LANG_ISO639;
966 MSG_DEBUG("codingScheme: [%d]", pDcs->codingScheme);
967 if (pMsgData[0] && pMsgData[1]) {
968 pDcs->iso639Lang[0] = pMsgData[0] & 0x7F;
969 pDcs->iso639Lang[1] = (pMsgData[0] & 0X80) >> 7;
970 pDcs->iso639Lang[1] |= (pMsgData[1] & 0X3F) << 1;
971 pDcs->iso639Lang[2] = 0x13; /* CR */
973 /* Default it to English if pMsgData is NULL */
974 pDcs->iso639Lang[0] = 0x45; /* E */
975 pDcs->iso639Lang[1] = 0x4E; /* N */
976 pDcs->iso639Lang[2] = 0x13; /* CR */
987 pDcs->codingGroup = SMS_CBMSG_CODGRP_GENERAL_DCS;
989 pDcs->bCompressed = (dcsData & 0x20) ? true : false;
992 pDcs->classType = (SMS_MSG_CLASS_T)(dcsData & 0x03);
994 unsigned char tmpScheme = (dcsData & 0x0C) >> 2;
998 pDcs->codingScheme = SMS_CHARSET_7BIT;
1001 pDcs->codingScheme = SMS_CHARSET_8BIT;
1004 pDcs->codingScheme = SMS_CHARSET_UCS2;
1007 MSG_DEBUG("tmpScheme: [%d]", tmpScheme);
1016 pDcs->classType = (MSG_CLASS_TYPE_T)(dcsData & 0x03);
1017 pDcs->codingScheme = (SMS_CODING_SCHEME_T)((dcsData & 0x0C) >> 2);
1023 pDcs->codingGroup = SMS_CBMSG_CODGRP_WAP;
1029 pDcs->codingGroup = SMS_CBMSG_CODGRP_CLASS_CODING;
1030 pDcs->codingScheme = (dcsData & 0x04) ? SMS_CHARSET_8BIT : SMS_CHARSET_7BIT;
1031 pDcs->classType = (MSG_CLASS_TYPE_T)(dcsData & 0x03);
1035 MSG_DEBUG("codingGrp: [0x%x]", codingGrp);
1041 void SmsPluginCbMsgHandler::convertLangType(SMS_CBMSG_LANG_TYPE_T InType , MSG_CB_LANGUAGE_TYPE_T *pOutType)
1044 case SMS_CBMSG_LANG_GERMAN :
1045 *pOutType = MSG_CBLANG_TYPE_GER;
1048 case SMS_CBMSG_LANG_ENGLISH :
1049 *pOutType = MSG_CBLANG_TYPE_ENG;
1052 case SMS_CBMSG_LANG_ITALIAN :
1053 *pOutType = MSG_CBLANG_TYPE_ITA;
1056 case SMS_CBMSG_LANG_FRENCH :
1057 *pOutType = MSG_CBLANG_TYPE_FRE;
1060 case SMS_CBMSG_LANG_SPANISH :
1061 *pOutType = MSG_CBLANG_TYPE_SPA;
1064 case SMS_CBMSG_LANG_DUTCH :
1065 *pOutType = MSG_CBLANG_TYPE_NED;
1068 case SMS_CBMSG_LANG_SWEDISH :
1069 *pOutType = MSG_CBLANG_TYPE_SWE;
1072 case SMS_CBMSG_LANG_PORTUGUESE :
1073 *pOutType = MSG_CBLANG_TYPE_POR;
1076 case SMS_CBMSG_LANG_TURKISH :
1077 *pOutType = MSG_CBLANG_TYPE_TUR;
1081 *pOutType = MSG_CBLANG_TYPE_MAX;
1087 unsigned long SmsPluginCbMsgHandler::getRecvTime()
1091 recvTime = time(NULL);
1093 return (unsigned long)recvTime;
1097 void SmsPluginCbMsgHandler::getDisplayName(unsigned short MsgId, char *pDisplayName, msg_sim_slot_id_t simIndex)
1099 MSG_CB_CHANNEL_S cbChannelInfo = {0,};
1100 msg_error_t err = MSG_SUCCESS;
1101 MsgDbHandler *dbHandle = getDbHandle();
1103 err = MsgStoGetCBChannelInfo(dbHandle, &cbChannelInfo, simIndex);
1104 MSG_DEBUG("MsgStoGetCBChannelInfo [err = %d]", err);
1106 for (int i = 0; i < cbChannelInfo.channelCnt; i++) {
1107 if (MsgId >= cbChannelInfo.channelInfo[i].from && MsgId <= cbChannelInfo.channelInfo[i].to) {
1108 MSG_DEBUG("FIND MSG ID = [%d]", MsgId);
1110 char strTmp[CB_CHANNEL_NAME_MAX + 1];
1111 memset(strTmp, 0x00, sizeof(strTmp));
1113 strncpy(strTmp, cbChannelInfo.channelInfo[i].name, CB_CHANNEL_NAME_MAX);
1115 if (strlen(strTmp) > 0)
1116 snprintf(pDisplayName, sizeof(strTmp), "[%s]", strTmp);
1118 snprintf(pDisplayName, sizeof(unsigned short), "[%d]", MsgId);
1121 #ifdef MSG_NOTI_INTEGRATION
1122 snprintf(pDisplayName, MAX_ADDRESS_VAL_LEN + 1, "CB message");
1124 snprintf(pDisplayName, MAX_ADDRESS_VAL_LEN + 1, "[%d]", MsgId);
1132 snprintf(pDisplayName, MAX_ADDRESS_VAL_LEN + 1, "[%d]", MsgId);