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()
48 SmsPluginCbMsgHandler* SmsPluginCbMsgHandler::instance()
51 pInstance = new SmsPluginCbMsgHandler();
57 void SmsPluginCbMsgHandler::handleCbMsg(TapiHandle *handle, TelSmsCbMsg_t *pCbMsg)
62 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};
63 TelSmsEtwsMsg_t *pCbMsg = (TelSmsEtwsMsg_t *)calloc(1, sizeof(TelSmsEtwsMsg_t));
65 pCbMsg->EtwsMsgType = (TelSmsEtwsMsgType_t)2;
66 memcpy(pCbMsg->szMsgData, temp, pCbMsg->Length);
68 SMS_CB_NETWORK_TYPE_T type = pCbMsg->EtwsMsgType;
69 SMS_CBMSG_PAGE_S CbMsgPage = {0};
72 case SMS_CB_NETWORK_TYPE_2G_GSM :
73 Decode2gCbMsg((TelSmsCbMsg_t *)pCbMsg, &CbMsgPage);
76 case SMS_CB_NETWORK_TYPE_3G_UMTS :
77 Decode3gCbMsg((TelSmsCbMsg_t *)pCbMsg, &CbMsgPage);
81 SMS_CB_NETWORK_TYPE_T type = pCbMsg->CbMsgType;
82 SMS_CBMSG_PAGE_S CbMsgPage = {0};
85 case SMS_CB_NETWORK_TYPE_2G_GSM :
86 Decode2gCbMsg(pCbMsg, &CbMsgPage);
89 case SMS_CB_NETWORK_TYPE_3G_UMTS :
90 Decode3gCbMsg(pCbMsg, &CbMsgPage);
94 /* Check CB Msg Options */
95 bool bJavaMsg = false;
97 int simIndex = SmsPluginDSHandler::instance()->getSimIndex(handle);
99 if (!checkCbOpt(&CbMsgPage, &bJavaMsg, simIndex)) {
100 MSG_DEBUG("The CB Msg is not supported by option.");
104 if (bJavaMsg == true) {
105 MSG_DEBUG("JAVA CB Msg.");
106 CbMsgPage.cbMsgType = SMS_CBMSG_TYPE_JAVACBS;
111 unsigned char pageCnt = checkCbPage(&CbMsgPage);
113 if (pageCnt == CbMsgPage.pageHeader.totalPages) {
114 MSG_DEBUG("RECEIVED LAST MSG : %d", pageCnt);
116 SMS_CBMSG_S *cbMsg = NULL;
117 unique_ptr<SMS_CBMSG_S*, void(*)(SMS_CBMSG_S**)> buf(&cbMsg, unique_ptr_deleter);
118 cbMsg = (SMS_CBMSG_S *)new char[sizeof(SMS_CBMSG_S)];
119 memset(cbMsg, 0x00, sizeof(SMS_CBMSG_S));
121 MSG_MESSAGE_INFO_S msgInfo;
123 /** initialize msgInfo */
124 memset(&msgInfo, 0x00, sizeof(MSG_MESSAGE_INFO_S));
126 msgInfo.addressList = NULL;
127 unique_ptr<MSG_ADDRESS_INFO_S*, void(*)(MSG_ADDRESS_INFO_S**)> addressListBuf(&msgInfo.addressList, unique_ptr_deleter);
129 /* Make CB Msg Structure */
130 MakeCbMsg(&CbMsgPage, cbMsg);
132 /* Convert to MSG_MESSAGE_INFO_S */
133 convertCbMsgToMsginfo(cbMsg, &msgInfo, simIndex);
135 /* Add CB Msg into DB */
136 msg_error_t err = MSG_SUCCESS;
138 err = SmsPluginStorage::instance()->checkMessage(&msgInfo);
140 if (err == MSG_SUCCESS) {
141 MSG_CB_MSG_S cbOutMsg = {0, };
143 /*cbOutMsg.type = MSG_CB_SMS; */
144 cbOutMsg.type = msgInfo.msgType.subType;
145 cbOutMsg.receivedTime = cbMsg->recvTime;
146 cbOutMsg.serialNum = encodeCbSerialNum(CbMsgPage.pageHeader.serialNum);
147 cbOutMsg.messageId = cbMsg->msgId;
148 cbOutMsg.dcs = CbMsgPage.pageHeader.dcs.rawData;
149 memset (cbOutMsg.cbText, 0x00, sizeof(cbOutMsg.cbText));
151 cbOutMsg.cbTextLen = convertTextToUtf8((unsigned char*)cbOutMsg.cbText, sizeof(cbOutMsg.cbText), cbMsg);
152 memset(cbOutMsg.language_type, 0x00, sizeof(cbOutMsg.language_type));
153 memcpy(cbOutMsg.language_type, CbMsgPage.pageHeader.dcs.iso639Lang, 3);
154 err = SmsPluginEventHandler::instance()->callbackCBMsgIncoming(&cbOutMsg, &msgInfo);
155 if (err != MSG_SUCCESS)
156 MSG_WARN("callbackMsgIncoming() Error !! [%d]", err);
158 MSG_WARN("checkMessage() Error !! [%d]", err);
162 /* insert message-id to internal CB message table */
163 SmsPluginStorage *storageHandler = SmsPluginStorage::instance();
164 err = storageHandler->insertReceivedCBMessage(CbMsgPage);
165 if (err != MSG_SUCCESS) {
166 MSG_DEBUG("insertReceivedCBMessage() Error !! [%d]", err);
169 /* Remove From List */
170 removeFromPageList(&CbMsgPage);
176 void SmsPluginCbMsgHandler::handleEtwsMsg(TapiHandle *handle, TelSmsEtwsMsg_t *pEtwsMsg)
179 msg_error_t err = MSG_SUCCESS;
180 TelSmsEtwsMsgType_t type = pEtwsMsg->EtwsMsgType;
181 SMS_ETWS_PRIMARY_S etwsPn = {0, };
182 MSG_CB_MSG_S cbOutMsg = {0, };
184 if (type != TAPI_NETTEXT_ETWS_PRIMARY) {
185 MSG_DEBUG("The Etws secondary Message");
186 handleCbMsg(handle, (TelSmsCbMsg_t *)pEtwsMsg);
189 DecodeEtwsMsg(pEtwsMsg, &etwsPn);
191 cbOutMsg.type = MSG_ETWS_SMS;
192 cbOutMsg.receivedTime = etwsPn.recvTime;
193 cbOutMsg.serialNum = encodeCbSerialNum(etwsPn.serialNum);
194 cbOutMsg.messageId = etwsPn.msgId;
195 cbOutMsg.etwsWarningType = etwsPn.warningType;
196 memcpy (cbOutMsg.etwsWarningSecurityInfo, etwsPn.warningSecurityInfo, sizeof(cbOutMsg.etwsWarningSecurityInfo));
198 err = SmsPluginEventHandler::instance()->callbackCBMsgIncoming(&cbOutMsg, NULL);
199 if (err != MSG_SUCCESS)
200 MSG_DEBUG("callbackMsgIncoming() Error !! [%d]", err);
206 void SmsPluginCbMsgHandler::Decode2gCbMsg(TelSmsCbMsg_t *pCbMsg, SMS_CBMSG_PAGE_S *pCbPage)
208 unsigned char cbData[pCbMsg->Length+1];
210 memset(cbData, 0x00, sizeof(cbData));
211 memcpy(cbData, pCbMsg->szMsgData, pCbMsg->Length);
212 cbData[pCbMsg->Length] = '\0';
215 MSG_INFO("Received CB length:%d", pCbMsg->Length);
216 char cbDataTmp[(pCbMsg->Length*2)+1];
217 memset(cbDataTmp, 0x00, sizeof(cbDataTmp));
219 for (int i = 0; i < pCbMsg->Length; i++) {
220 snprintf(cbDataTmp+(i*2), sizeof(cbDataTmp)-(i*2), "%02X", cbData[i]);
222 MSG_INFO("[%s]", cbDataTmp);
224 pCbPage->cbMsgType = SMS_CBMSG_TYPE_CBS;
227 pCbPage->pageHeader.serialNum.geoScope = (cbData[0] & 0xC0) >> 6;
229 pCbPage->pageHeader.serialNum.msgCode = (cbData[0] & 0x3F) << 4;
230 pCbPage->pageHeader.serialNum.msgCode |= (cbData[1] & 0xF0) >> 4;
232 pCbPage->pageHeader.serialNum.updateNum = cbData[1] & 0x0F;
234 MSG_DEBUG("geoScope : [%d], msgCode : [%d], updateNum : [%d]", pCbPage->pageHeader.serialNum.geoScope, pCbPage->pageHeader.serialNum.msgCode, pCbPage->pageHeader.serialNum.updateNum);
236 pCbPage->pageHeader.msgId = (cbData[2] << 8) | cbData[3];
238 MSG_DEBUG("MSG ID : [%d]", pCbPage->pageHeader.msgId);
241 decodeCbMsgDCS(cbData[4], (unsigned char*)cbData + 6, &(pCbPage->pageHeader.dcs));
244 pCbPage->pageHeader.totalPages = cbData[5] & 0x0F;
245 pCbPage->pageHeader.page = (cbData[5] & 0xF0) >> 4;
247 if (pCbPage->pageHeader.totalPages > MAX_CBMSG_PAGE_NUM)
248 THROW(MsgException::SMS_PLG_ERROR, "CB Page Count is over MAX[%d]", pCbPage->pageHeader.totalPages);
250 MSG_DEBUG("Total Page : [%d], Page : [%d]", pCbPage->pageHeader.totalPages, pCbPage->pageHeader.page);
252 /* Convert Language Type */
253 convertLangType(pCbPage->pageHeader.dcs.langType, &(pCbPage->pageHeader.langType));
255 MSG_DEBUG("In Language Type : [%d], Out Language Type : [%d]", pCbPage->pageHeader.dcs.langType, pCbPage->pageHeader.langType);
256 MSG_DEBUG("iso639Lang : [%s]", pCbPage->pageHeader.dcs.iso639Lang);
257 /* Get Receive Time */
258 pCbPage->pageHeader.recvTime = getRecvTime();
261 int dataLen = pCbMsg->Length - 6;
263 MSG_DEBUG("codingScheme:[%d]", pCbPage->pageHeader.dcs.codingScheme);
265 switch (pCbPage->pageHeader.dcs.codingScheme) {
266 case SMS_CHARSET_7BIT: {
267 MSG_DEBUG("GSM 7 BIT");
269 dataLen = (dataLen*8) / 7;
271 SmsPluginUDCodec udCodec;
272 char pageData[MAX_CBMSG_PAGE_SIZE+1];
273 int unpackLen = udCodec.unpack7bitChar(&cbData[6], dataLen, 0, pageData);
275 if (pCbPage->pageHeader.dcs.iso639Lang[0]) {
276 unpackLen = unpackLen - 3;
278 memcpy(pCbPage->pageData, &pageData[3], unpackLen);
282 memcpy(pCbPage->pageData, &pageData, unpackLen);
285 MSG_DEBUG("unpackLen : [%d]", unpackLen);
287 pCbPage->pageLength = unpackLen;
288 pCbPage->pageData[unpackLen] = '\0';
292 case SMS_CHARSET_8BIT:
293 case SMS_CHARSET_UCS2: {
294 MSG_DEBUG("UCS2 or 8BIT");
296 if (pCbPage->pageHeader.dcs.iso639Lang[0]) {
297 memcpy(pCbPage->pageData, &cbData[8], dataLen - 2);
298 pCbPage->pageLength = dataLen - 2;
300 memcpy(pCbPage->pageData, &cbData[6], dataLen);
301 pCbPage->pageLength = dataLen;
307 MSG_DEBUG("Page Length : [%d], Page Data : [%s]", pCbPage->pageLength, pCbPage->pageData);
311 void SmsPluginCbMsgHandler::DecodeEtwsMsg(TelSmsEtwsMsg_t *pEtwsMsg, SMS_ETWS_PRIMARY_S *pEtwsPn)
313 if ( !pEtwsMsg || !pEtwsPn )
316 if (pEtwsMsg->Length > MAX_ETWS_SIZE)
317 THROW(MsgException::SMS_PLG_ERROR, "ETWS Msg Size is over MAX [%d]", pEtwsMsg->Length);
319 unsigned char EtwsData[pEtwsMsg->Length+1];
321 memset(EtwsData, 0x00, sizeof(EtwsData));
322 memcpy(EtwsData, pEtwsMsg->szMsgData, pEtwsMsg->Length);
323 EtwsData[pEtwsMsg->Length] = '\0';
325 /* print received msg data */
326 MSG_INFO("Received Etws length:%d", pEtwsMsg->Length);
327 char EtwsDataTmp[(pEtwsMsg->Length*2)+1];
328 memset(EtwsDataTmp, 0x00, sizeof(EtwsDataTmp));
330 for (int i = 0; i < pEtwsMsg->Length; i++) {
331 snprintf(EtwsDataTmp+(i*2), sizeof(EtwsDataTmp)-(i*2), "%02X", EtwsData[i]);
333 MSG_INFO("[%s]", EtwsDataTmp);
336 pEtwsPn->recvTime = getRecvTime();
339 pEtwsPn->serialNum.geoScope = (EtwsData[0] & 0xC0) >> 6;
340 pEtwsPn->serialNum.msgCode = (EtwsData[0] & 0x3F) << 4;
341 pEtwsPn->serialNum.msgCode |= (EtwsData[1] & 0xF0) >> 4;
342 pEtwsPn->serialNum.updateNum = EtwsData[1] & 0x0F;
344 MSG_DEBUG("geoScope : [%d], msgCode : [%d], updateNum : [%d]", pEtwsPn->serialNum.geoScope, pEtwsPn->serialNum.msgCode, pEtwsPn->serialNum.updateNum);
346 /* Message Identifier */
347 pEtwsPn->msgId = (EtwsData[2] << 8) | EtwsData[3];
348 MSG_DEBUG("MSG ID : [%d]", pEtwsPn->msgId);
351 pEtwsPn->warningType = (EtwsData[4] << 8) | EtwsData[5];
352 MSG_DEBUG("warningType : [0x%04x]", pEtwsPn->msgId);
354 /* warning security information */
355 memcpy(pEtwsPn->warningSecurityInfo, &EtwsData[6], sizeof(pEtwsPn->warningSecurityInfo)); /* 50bytes */
356 for (unsigned int i = 0; i < sizeof(pEtwsPn->warningSecurityInfo); i++) {
357 MSG_DEBUG("warning secu info [%02x]", pEtwsPn->warningSecurityInfo[i]);
361 void SmsPluginCbMsgHandler::Decode3gCbMsg(TelSmsCbMsg_t *pCbMsg, SMS_CBMSG_PAGE_S *pCbPage)
363 unsigned char cbData[(MAX_CBMSG_PAGE_SIZE*MAX_CBMSG_PAGE_NUM)+1];
365 memset(cbData, 0x00, sizeof(cbData));
366 memcpy(cbData, pCbMsg->szMsgData, pCbMsg->Length);
367 cbData[pCbMsg->Length] = '\0';
370 MSG_INFO("Received CB length:%d", pCbMsg->Length);
371 char cbDataTmp[(pCbMsg->Length*2)+1];
372 memset(cbDataTmp, 0x00, sizeof(cbDataTmp));
374 for (int i = 0; i < pCbMsg->Length; i++) {
375 snprintf(cbDataTmp+(i*2), sizeof(cbDataTmp)-(i*2), "%02X", cbData[i]);
377 MSG_INFO("[%s]", cbDataTmp);
379 pCbPage->cbMsgType = (SMS_CBMSG_TYPE_T)cbData[0];
381 pCbPage->pageHeader.msgId = (cbData[1] << 8) | cbData[2];
383 MSG_DEBUG("MSG ID : [%d]", pCbPage->pageHeader.msgId);
386 pCbPage->pageHeader.serialNum.geoScope = (cbData[3] & 0xC0) >> 6;
388 pCbPage->pageHeader.serialNum.msgCode = (cbData[3] & 0x3F) << 4;
389 pCbPage->pageHeader.serialNum.msgCode |= (cbData[4] & 0xF0) >> 4;
391 pCbPage->pageHeader.serialNum.updateNum = cbData[4] & 0x0F;
393 MSG_DEBUG("geoScope : [%d], msgCode : [%d], updateNum : [%d]", pCbPage->pageHeader.serialNum.geoScope, pCbPage->pageHeader.serialNum.msgCode, pCbPage->pageHeader.serialNum.updateNum);
396 decodeCbMsgDCS(cbData[5], (unsigned char*)cbData + 6, &(pCbPage->pageHeader.dcs));
398 /* Convert Language Type */
399 convertLangType(pCbPage->pageHeader.dcs.langType, &(pCbPage->pageHeader.langType));
401 MSG_DEBUG("In Language Type : [%d], Out Language Type : [%d]", pCbPage->pageHeader.dcs.langType, pCbPage->pageHeader.langType);
403 /* Get Receive Time */
404 pCbPage->pageHeader.recvTime = getRecvTime();
405 pCbPage->pageHeader.totalPages = cbData[6];
411 switch (pCbPage->pageHeader.dcs.codingScheme) {
412 case SMS_CHARSET_7BIT: {
413 for (int i = 0; i < pCbPage->pageHeader.totalPages; ++i) {
414 char cbMessage[MAX_CBMSG_PAGE_SIZE] = {0, };
415 dataLen = cbData[7+(i+1)*82 + i];
416 memcpy(cbMessage, &cbData[7+(i*82)+ i], dataLen);
418 dataLen = (dataLen*8) / 7;
420 if (dataLen > MAX_CBMSG_PAGE_SIZE)
421 THROW(MsgException::SMS_PLG_ERROR, "CB Msg Size is over MAX [%d]", dataLen);
423 SmsPluginUDCodec udCodec;
424 int unpackLen = udCodec.unpack7bitChar((const unsigned char *)cbMessage, dataLen, 0, pCbPage->pageData + offset);
427 pCbPage->pageLength = offset;
431 case SMS_CHARSET_8BIT:
432 case SMS_CHARSET_UCS2: {
434 char cbMessage[MAX_CBMSG_PAGE_SIZE]= {0, };
436 for (int i = 0; i < pCbPage->pageHeader.totalPages; ++i) {
437 dataLen = cbData[7+(i+1)*82 + i];
438 memcpy(cbMessage + offset, &cbData[7+(i*82)+ i], dataLen);
443 if (pCbPage->pageHeader.dcs.iso639Lang[0]) {
444 int tmpDataLen = (dataLen > 2)?(dataLen - 2):0;
445 memcpy(pCbPage->pageData, cbMessage + 2, tmpDataLen);
446 pCbPage->pageLength = tmpDataLen;
448 memcpy(pCbPage->pageData, cbMessage, dataLen);
449 pCbPage->pageLength = dataLen;
452 char cbMessage[MAX_CBMSG_PAGE_SIZE] = {0, };
454 for (int i = 0; i < pCbPage->pageHeader.totalPages; ++i) {
455 if (pCbPage->pageHeader.dcs.iso639Lang[0]) {
456 dataLen = cbData[7+(i+1)*82 + i] - 2;
457 memcpy(cbMessage + offset, &cbData[7+(i*82)+ i + 2], dataLen);
460 dataLen = cbData[7+(i+1)*82 + i];
461 memcpy(cbMessage + offset, &cbData[7+(i*82)+ i], dataLen);
466 memcpy(pCbPage->pageData, cbMessage, dataLen);
467 pCbPage->pageLength = dataLen;
472 pCbPage->pageHeader.totalPages = 1;
474 MSG_DEBUG("Page Length : [%d], Page Data : [%s]", pCbPage->pageLength, pCbPage->pageData);
477 unsigned short SmsPluginCbMsgHandler::encodeCbSerialNum(SMS_CBMSG_SERIAL_NUM_S snFields)
479 unsigned short serialNum = 0;
481 serialNum = ((snFields.geoScope & 0x03) << 14) | ((snFields.msgCode&0x03FF) << 4) | (snFields.updateNum&0x0F);
482 MSG_DEBUG("serialNum (%x), geo(%x), mc(%x), un(%x)\n", serialNum, snFields.geoScope, snFields.msgCode, snFields.updateNum);
487 int SmsPluginCbMsgHandler::CMAS_class(unsigned short message_id)
491 switch (message_id) {
494 ret = MSG_CMAS_PRESIDENTIAL;
500 ret = MSG_CMAS_EXTREME;
514 ret = MSG_CMAS_SEVERE;
518 ret = MSG_CMAS_AMBER;
526 ret = MSG_CMAS_EXERCISE;
530 ret = MSG_CMAS_OPERATOR_DEFINED;
539 bool SmsPluginCbMsgHandler::checkCbOpt(SMS_CBMSG_PAGE_S *CbPage, bool *pJavaMsg, msg_sim_slot_id_t simIndex)
541 bool bReceive = false;
542 char keyName[MAX_VCONFKEY_NAME_LEN];
543 memset(keyName, 0x00, sizeof(keyName));
544 snprintf(keyName, sizeof(keyName), "%s/%d", CB_RECEIVE, simIndex);
545 MsgSettingGetBool(keyName, &bReceive);
547 /* Receive CB Msg = FALSE */
549 MSG_DEBUG("RECEIVE CB = FALSE");
556 memset(keyName, 0x00, sizeof(keyName));
557 snprintf(keyName, sizeof(keyname), "%s/%d", CB_LANGUAGE, MSG_CBLANG_TYPE_ALL);
559 bool bAllLang = false;
560 MsgSettingGetBool(keyName, &bAllLang);
563 MSG_DEBUG("ALL LANGUAGE = FALSE");
565 memset(keyName, 0x00, sizeof(keyName));
566 snprintf(keyName, sizeof(keyname), "%s/%d", CB_LANGUAGE, CbPage.pageHeader.langType);
570 MsgSettingGetBool(keyName, &bLang);
572 if (!bLang || CbPage.pageHeader.langType == MSG_CBLANG_TYPE_MAX) {
573 MSG_DEBUG("LANGUAGE [%d] = FALSE", CbPage.pageHeader.langType);
579 bool bActivate = false;
580 int MsgId_from = 0, MsgId_to = 0;
581 MSG_CB_CHANNEL_S cbChannelInfo = {0, };
582 msg_error_t err = MSG_SUCCESS;
583 MsgDbHandler *dbHandle = getDbHandle();
585 err = MsgStoGetCBChannelInfo(dbHandle, &cbChannelInfo, simIndex);
586 if (err != MSG_SUCCESS)
587 MSG_ERR("Error value of MsgStoGetCBChannelInfo [%d]", err);
589 for (int i = 0; i < cbChannelInfo.channelCnt; i++) {
590 bActivate = cbChannelInfo.channelInfo[i].bActivate;
591 MsgId_from = cbChannelInfo.channelInfo[i].from;
592 MsgId_to = cbChannelInfo.channelInfo[i].to;
594 if (bActivate == true && CbPage->pageHeader.msgId >= MsgId_from && CbPage->pageHeader.msgId <= MsgId_to) {
595 MSG_DEBUG("FIND CHANNEL = [%d]", CbPage->pageHeader.msgId);
603 unsigned char SmsPluginCbMsgHandler::checkCbPage(SMS_CBMSG_PAGE_S *CbPage)
605 unsigned char currPageCnt = 0;
610 msg_error_t err = MSG_SUCCESS;
612 SmsPluginStorage *storageHandler = SmsPluginStorage::instance();
613 err = storageHandler->isReceivedCBMessage(CbPage);
615 /* check existing message with cb internal table; */
616 if (err != MSG_ERR_DB_NORECORD) {
617 MSG_DEBUG("already received message: [%d]", CbPage.pageHeader.msgId);
622 if (CbPage->pageHeader.totalPages > 0) {
623 for (unsigned int i = 0; i < pageList.size(); i++) {
624 if (pageList[i].geoScope == CbPage->pageHeader.serialNum.geoScope && pageList[i].msgCode == CbPage->pageHeader.serialNum.msgCode) {
625 MSG_DEBUG("geoScope [%d], msgCode [%d]", pageList[i].geoScope, pageList[i].msgCode);
627 if (pageList[i].msgId == CbPage->pageHeader.msgId) {
628 int updateNum = CbPage->pageHeader.serialNum.updateNum - pageList[i].updateNum;
630 if (updateNum > 0) { /* New Message Content */
632 } else if (updateNum == 0) { /* Same Message Content */
633 if (pageList[i].data.count(CbPage->pageHeader.page) != 0) {
634 MSG_DEBUG("The Page Number already exists [%d]", CbPage->pageHeader.page);
638 pair<unsigned char, SMS_CBMSG_PAGE_S> newData(CbPage->pageHeader.page, *CbPage);
639 pageList[i].data.insert(newData);
641 MSG_DEBUG("PAGE DATA : %s", CbPage->pageData);
642 MSG_DEBUG("PAIR DATA [%d] : %s", newData.first, newData.second.pageData);
644 pageList[i].pageCnt++;
645 pageList[i].totalSize += CbPage->pageLength;
647 currPageCnt = pageList[i].pageCnt;
652 } else { /* Old Message Content */
660 if (bFind == false || CbPage->pageHeader.totalPages == 1) {
661 addToPageList(CbPage);
669 void SmsPluginCbMsgHandler::MakeCbMsg(SMS_CBMSG_PAGE_S *CbPage, SMS_CBMSG_S *pCbMsg)
671 pCbMsg->cbMsgType = CbPage->cbMsgType;
672 pCbMsg->msgId = CbPage->pageHeader.msgId;
673 pCbMsg->classType = CbPage->pageHeader.dcs.classType;
674 pCbMsg->codingScheme = CbPage->pageHeader.dcs.codingScheme;
675 pCbMsg->recvTime = CbPage->pageHeader.recvTime;
677 cbPageMap::iterator it;
680 for (unsigned int i = 0; i < pageList.size(); i++) {
681 if (pageList[i].geoScope == CbPage->pageHeader.serialNum.geoScope && pageList[i].msgCode == CbPage->pageHeader.serialNum.msgCode) {
682 MSG_DEBUG("geoScope [%d], msgCode [%d]", pageList[i].geoScope, pageList[i].msgCode);
684 if (pageList[i].msgId == CbPage->pageHeader.msgId) {
685 for (it = pageList[i].data.begin(); it != pageList[i].data.end(); it++) {
686 memcpy(pCbMsg->msgData + offset, it->second.pageData, it->second.pageLength);
687 pCbMsg->msgLength += it->second.pageLength;
688 offset = pCbMsg->msgLength;
695 pCbMsg->msgLength = tmpStr.size();
697 memcpy(pCbMsg->msgData, tmpStr.c_str(), tmpStr.size());
698 pCbMsg->msgData[tmpStr.size()] = '\0';
700 MSG_DEBUG("SIZE : [%d] TOTAL MSG : %s", tmpStr.size(), tmpStr.c_str());
705 void SmsPluginCbMsgHandler::convertCbMsgToMsginfo(SMS_CBMSG_S *pCbMsg, MSG_MESSAGE_INFO_S *pMsgInfo, msg_sim_slot_id_t simIndex)
707 pMsgInfo->msgId = (msg_message_id_t)pCbMsg->msgId;
709 pMsgInfo->folderId = MSG_CBMSGBOX_ID;
711 /* Convert Type values */
712 pMsgInfo->msgType.mainType = MSG_SMS_TYPE;
714 if (pCbMsg->cbMsgType == SMS_CBMSG_TYPE_CBS) {
715 int cmas_class = CMAS_class(pCbMsg->msgId);
718 pMsgInfo->msgType.subType = MSG_CB_SMS;
720 pMsgInfo->msgType.subType = (MSG_SUB_TYPE_T)cmas_class;
721 } else if (pCbMsg->cbMsgType == SMS_CBMSG_TYPE_JAVACBS) {
722 pMsgInfo->msgType.subType = MSG_JAVACB_SMS;
725 switch (pCbMsg->classType) {
726 case SMS_MSG_CLASS_0:
727 pMsgInfo->msgType.classType = MSG_CLASS_0;
729 case SMS_MSG_CLASS_1:
730 pMsgInfo->msgType.classType = MSG_CLASS_1;
732 case SMS_MSG_CLASS_2:
733 pMsgInfo->msgType.classType = MSG_CLASS_2;
735 case SMS_MSG_CLASS_3:
736 pMsgInfo->msgType.classType = MSG_CLASS_3;
739 pMsgInfo->msgType.classType = MSG_CLASS_NONE;
743 pMsgInfo->storageId = MSG_STORAGE_PHONE;
744 pMsgInfo->networkStatus = MSG_NETWORK_RECEIVED;
745 pMsgInfo->bRead = false;
746 pMsgInfo->bProtected = false;
747 pMsgInfo->priority = MSG_MESSAGE_PRIORITY_NORMAL;
748 pMsgInfo->direction = MSG_DIRECTION_TYPE_MT;
751 pMsgInfo->nAddressCnt = 1;
753 pMsgInfo->addressList = (MSG_ADDRESS_INFO_S *)new char[sizeof(MSG_ADDRESS_INFO_S)];
754 memset(pMsgInfo->addressList, 0x00, sizeof(MSG_ADDRESS_INFO_S));
756 pMsgInfo->addressList[0].addressType = MSG_ADDRESS_TYPE_UNKNOWN;
757 pMsgInfo->addressList[0].recipientType = MSG_RECIPIENTS_TYPE_UNKNOWN;
758 pMsgInfo->sim_idx = simIndex;
760 /* TODO :: MSG ID should be used to get CB message type */
761 getDisplayName(pCbMsg->msgId, pMsgInfo->addressList[0].addressVal, simIndex);
762 MSG_SEC_DEBUG("%s", pMsgInfo->addressList[0].addressVal);
765 pMsgInfo->msgPort.valid = false;
766 pMsgInfo->msgPort.dstPort = 0;
767 pMsgInfo->msgPort.srcPort = 0;
769 pMsgInfo->displayTime = pCbMsg->recvTime;
770 MSG_DEBUG("recvTime is %d", pMsgInfo->displayTime);
772 int bufSize = pCbMsg->msgLength*2;
774 char tmpBuf[bufSize];
775 memset(tmpBuf, 0x00, sizeof(tmpBuf));
777 while (pCbMsg->msgLength > 0) {
778 if (pCbMsg->msgData[pCbMsg->msgLength-1] == ' ' ||
779 pCbMsg->msgData[pCbMsg->msgLength-1] == '\r' ||
780 pCbMsg->msgData[pCbMsg->msgLength-1] == '\n') {
787 pCbMsg->msgData[pCbMsg->msgLength] = '\0';
789 MSG_DEBUG("LENGTH %d CB MSG %s", pCbMsg->msgLength, pCbMsg->msgData);
791 /* Convert Data values */
792 pMsgInfo->dataSize = convertTextToUtf8((unsigned char*)tmpBuf, bufSize, pCbMsg);
794 if (pMsgInfo->dataSize > MAX_MSG_TEXT_LEN) {
795 pMsgInfo->bTextSms = false;
797 /* Save Message Data into File */
798 char fileName[MSG_FILENAME_LEN_MAX+1];
799 memset(fileName, 0x00, sizeof(fileName));
801 if (MsgCreateFileName(fileName) == false)
802 THROW(MsgException::FILE_ERROR, "MsgCreateFileName error");
804 MSG_SEC_DEBUG("Save Message Data into file : size[%d] name[%s]\n", pMsgInfo->dataSize, fileName);
805 if (MsgWriteIpcFile(fileName, tmpBuf, pMsgInfo->dataSize) == false)
806 THROW(MsgException::FILE_ERROR, "MsgWriteIpcFile error");
808 strncpy(pMsgInfo->msgData, fileName, MAX_MSG_DATA_LEN);
810 pMsgInfo->bTextSms = true;
812 memset(pMsgInfo->msgText, 0x00, sizeof(pMsgInfo->msgText));
813 memcpy(pMsgInfo->msgText, tmpBuf, pMsgInfo->dataSize);
814 pMsgInfo->dataSize = strlen(pMsgInfo->msgText);
815 MSG_SEC_DEBUG("CB MSG %s", pMsgInfo->msgText);
820 void SmsPluginCbMsgHandler::convertEtwsMsgToMsginfo(SMS_CBMSG_PAGE_S *EtwsMsg, MSG_MESSAGE_INFO_S *pMsgInfo, msg_sim_slot_id_t simIndex)
822 pMsgInfo->msgId = (msg_message_id_t)EtwsMsg->pageHeader.msgId;
824 pMsgInfo->folderId = MSG_CBMSGBOX_ID;
826 /* Convert Type values */
827 pMsgInfo->msgType.mainType = MSG_SMS_TYPE;
829 if (EtwsMsg->cbMsgType == SMS_CBMSG_TYPE_ETWS)
830 pMsgInfo->msgType.subType = MSG_ETWS_SMS;
832 pMsgInfo->storageId = MSG_STORAGE_PHONE;
833 pMsgInfo->networkStatus = MSG_NETWORK_RECEIVED;
834 pMsgInfo->bRead = false;
835 pMsgInfo->bProtected = false;
836 pMsgInfo->priority = MSG_MESSAGE_PRIORITY_NORMAL;
837 pMsgInfo->direction = MSG_DIRECTION_TYPE_MT;
840 pMsgInfo->nAddressCnt = 1;
842 pMsgInfo->addressList[0].addressType = MSG_ADDRESS_TYPE_UNKNOWN;
843 pMsgInfo->addressList[0].recipientType = MSG_RECIPIENTS_TYPE_UNKNOWN;
845 getDisplayName(EtwsMsg->pageHeader.msgId, pMsgInfo->addressList[0].addressVal, simIndex);
846 MSG_SEC_DEBUG("%s", pMsgInfo->addressList[0].addressVal);
848 pMsgInfo->msgPort.valid = false;
849 pMsgInfo->msgPort.dstPort = 0;
850 pMsgInfo->msgPort.srcPort = 0;
852 pMsgInfo->displayTime = EtwsMsg->pageHeader.recvTime;
853 MSG_DEBUG("recvTime is %d", pMsgInfo->displayTime);
854 MSG_DEBUG("LENGTH %d", EtwsMsg->pageLength);
855 pMsgInfo->bTextSms = true;
856 pMsgInfo->dataSize = EtwsMsg->pageLength;
857 memset(pMsgInfo->msgData, 0x00, sizeof(pMsgInfo->msgData));
858 memcpy(pMsgInfo->msgData, EtwsMsg->pageData, pMsgInfo->dataSize);
861 int SmsPluginCbMsgHandler::convertTextToUtf8(unsigned char* outBuf, int outBufSize, SMS_CBMSG_S* pCbMsg)
863 int convertedTextSize = 0;
864 MSG_LANG_INFO_S langInfo = {0, };
866 MsgTextConvert *textCvt = MsgTextConvert::instance();
868 if (!outBuf || !pCbMsg) {
869 MSG_DEBUG("invalid param.\n");
873 langInfo.bSingleShift = false;
874 langInfo.bLockingShift = false;
877 /* Convert Data values */
878 if (pCbMsg->codingScheme == SMS_CHARSET_7BIT)
879 convertedTextSize = textCvt->convertGSM7bitToUTF8(outBuf, outBufSize, (unsigned char*)pCbMsg->msgData, pCbMsg->msgLength, &langInfo);
880 else if (pCbMsg->codingScheme == SMS_CHARSET_UCS2)
881 convertedTextSize = textCvt->convertUCS2ToUTF8(outBuf, outBufSize, (unsigned char*)pCbMsg->msgData, pCbMsg->msgLength);
883 return convertedTextSize;
886 void SmsPluginCbMsgHandler::addToPageList(SMS_CBMSG_PAGE_S *CbPage)
888 CB_PAGE_INFO_S tmpInfo;
890 tmpInfo.geoScope = CbPage->pageHeader.serialNum.geoScope;
891 tmpInfo.msgCode = CbPage->pageHeader.serialNum.msgCode;
892 tmpInfo.updateNum = CbPage->pageHeader.serialNum.updateNum;
893 tmpInfo.msgId = CbPage->pageHeader.msgId;
894 tmpInfo.totalPages = CbPage->pageHeader.totalPages;
897 tmpInfo.totalSize = CbPage->pageLength;
899 pair<unsigned char, SMS_CBMSG_PAGE_S> newData(CbPage->pageHeader.page, *CbPage);
900 tmpInfo.data.insert(newData);
902 MSG_DEBUG("MSG DATA : %s", CbPage->pageData);
903 MSG_DEBUG("PAIR DATA [%d] : %s", newData.first, newData.second.pageData);
905 pageList.push_back(tmpInfo);
909 void SmsPluginCbMsgHandler::removeFromPageList(SMS_CBMSG_PAGE_S *CbPage)
913 for (index = 0; index < pageList.size(); index++) {
914 if (pageList[index].geoScope == CbPage->pageHeader.serialNum.geoScope && pageList[index].msgCode == CbPage->pageHeader.serialNum.msgCode) {
915 MSG_DEBUG("geoScope [%d], msgCode [%d]", pageList[index].geoScope, pageList[index].msgCode);
917 if (pageList[index].msgId == CbPage->pageHeader.msgId)
922 MSG_DEBUG("remove index [%d]", index);
924 pageList.erase(pageList.begin()+index);
928 void SmsPluginCbMsgHandler::decodeCbMsgDCS(unsigned char dcsData, const unsigned char *pMsgData, SMS_CBMSG_DCS_S* pDcs)
930 pDcs->codingGroup = SMS_CBMSG_CODGRP_GENERAL_DCS;
931 pDcs->classType = SMS_MSG_CLASS_NONE;
932 pDcs->bCompressed = false;
933 pDcs->codingScheme = SMS_CHARSET_7BIT;
934 pDcs->langType = SMS_CBMSG_LANG_UNSPECIFIED;
935 memset(pDcs->iso639Lang, 0x00, sizeof(pDcs->iso639Lang));
937 pDcs->rawData = dcsData;
939 unsigned char codingGrp = (dcsData & 0xF0) >> 4;
945 pDcs->codingGroup = SMS_CBMSG_CODGRP_GENERAL_DCS;
946 pDcs->langType = (SMS_CBMSG_LANG_TYPE_T)dcsData;
951 if (dcsData == 0x10 || dcsData == 0x11) {
952 pDcs->codingGroup = SMS_CBMSG_CODGRP_GENERAL_DCS;
953 pDcs->codingScheme = (dcsData & 0x01) ? SMS_CHARSET_UCS2 : SMS_CHARSET_7BIT;
954 pDcs->langType = SMS_CBMSG_LANG_ISO639;
955 MSG_DEBUG("codingScheme: [%d]", pDcs->codingScheme);
956 if (pMsgData[0] && pMsgData[1]) {
957 pDcs->iso639Lang[0] = pMsgData[0] & 0x7F;
958 pDcs->iso639Lang[1] = (pMsgData[0] & 0X80) >> 7;
959 pDcs->iso639Lang[1] |= (pMsgData[1] & 0X3F) << 1;
960 pDcs->iso639Lang[2] = 0x13; /* CR */
962 /* Default it to English if pMsgData is NULL */
963 pDcs->iso639Lang[0] = 0x45; /* E */
964 pDcs->iso639Lang[1] = 0x4E; /* N */
965 pDcs->iso639Lang[2] = 0x13; /* CR */
975 pDcs->codingGroup = SMS_CBMSG_CODGRP_GENERAL_DCS;
977 pDcs->bCompressed = (dcsData & 0x20) ? true : false;
980 pDcs->classType = (SMS_MSG_CLASS_T)(dcsData & 0x03);
982 unsigned char tmpScheme = (dcsData & 0x0C) >> 2;
986 pDcs->codingScheme = SMS_CHARSET_7BIT;
989 pDcs->codingScheme = SMS_CHARSET_8BIT;
992 pDcs->codingScheme = SMS_CHARSET_UCS2;
995 MSG_DEBUG("tmpScheme: [%d]", tmpScheme);
1003 pDcs->classType = (MSG_CLASS_TYPE_T)(dcsData & 0x03);
1004 pDcs->codingScheme = (SMS_CODING_SCHEME_T)((dcsData & 0x0C) >> 2);
1009 pDcs->codingGroup = SMS_CBMSG_CODGRP_WAP;
1014 pDcs->codingGroup = SMS_CBMSG_CODGRP_CLASS_CODING;
1015 pDcs->codingScheme = (dcsData & 0x04) ? SMS_CHARSET_8BIT : SMS_CHARSET_7BIT;
1016 pDcs->classType = (MSG_CLASS_TYPE_T)(dcsData & 0x03);
1020 MSG_DEBUG("codingGrp: [0x%x]", codingGrp);
1026 void SmsPluginCbMsgHandler::convertLangType(SMS_CBMSG_LANG_TYPE_T InType , MSG_CB_LANGUAGE_TYPE_T *pOutType)
1029 case SMS_CBMSG_LANG_GERMAN :
1030 *pOutType = MSG_CBLANG_TYPE_GER;
1033 case SMS_CBMSG_LANG_ENGLISH :
1034 *pOutType = MSG_CBLANG_TYPE_ENG;
1037 case SMS_CBMSG_LANG_ITALIAN :
1038 *pOutType = MSG_CBLANG_TYPE_ITA;
1041 case SMS_CBMSG_LANG_FRENCH :
1042 *pOutType = MSG_CBLANG_TYPE_FRE;
1045 case SMS_CBMSG_LANG_SPANISH :
1046 *pOutType = MSG_CBLANG_TYPE_SPA;
1049 case SMS_CBMSG_LANG_DUTCH :
1050 *pOutType = MSG_CBLANG_TYPE_NED;
1053 case SMS_CBMSG_LANG_SWEDISH :
1054 *pOutType = MSG_CBLANG_TYPE_SWE;
1057 case SMS_CBMSG_LANG_PORTUGUESE :
1058 *pOutType = MSG_CBLANG_TYPE_POR;
1061 case SMS_CBMSG_LANG_TURKISH :
1062 *pOutType = MSG_CBLANG_TYPE_TUR;
1066 *pOutType = MSG_CBLANG_TYPE_MAX;
1072 unsigned long SmsPluginCbMsgHandler::getRecvTime()
1076 recvTime = time(NULL);
1078 return (unsigned long)recvTime;
1082 void SmsPluginCbMsgHandler::getDisplayName(unsigned short MsgId, char *pDisplayName, msg_sim_slot_id_t simIndex)
1084 MSG_CB_CHANNEL_S cbChannelInfo = {0, };
1085 msg_error_t err = MSG_SUCCESS;
1086 MsgDbHandler *dbHandle = getDbHandle();
1088 err = MsgStoGetCBChannelInfo(dbHandle, &cbChannelInfo, simIndex);
1089 MSG_DEBUG("MsgStoGetCBChannelInfo [err = %d]", err);
1091 for (int i = 0; i < cbChannelInfo.channelCnt; i++) {
1092 if (MsgId >= cbChannelInfo.channelInfo[i].from && MsgId <= cbChannelInfo.channelInfo[i].to) {
1093 MSG_DEBUG("FIND MSG ID = [%d]", MsgId);
1095 char strTmp[CB_CHANNEL_NAME_MAX + 1];
1096 memset(strTmp, 0x00, sizeof(strTmp));
1098 strncpy(strTmp, cbChannelInfo.channelInfo[i].name, CB_CHANNEL_NAME_MAX);
1100 if (strlen(strTmp) > 0)
1101 snprintf(pDisplayName, sizeof(strTmp), "[%s]", strTmp);
1103 snprintf(pDisplayName, sizeof(unsigned short), "[%d]", MsgId);
1106 #ifdef MSG_NOTI_INTEGRATION
1107 snprintf(pDisplayName, MAX_ADDRESS_VAL_LEN + 1, "CB message");
1109 snprintf(pDisplayName, MAX_ADDRESS_VAL_LEN + 1, "[%d]", MsgId);
1117 snprintf(pDisplayName, MAX_ADDRESS_VAL_LEN + 1, "[%d]", MsgId);