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;
458 memcpy(cbMessage + offset, &cbData[7+(i*82)+ i + 2], dataLen);
462 dataLen = cbData[7+(i+1)*82 + i];
464 memcpy(cbMessage + offset, &cbData[7+(i*82)+ i], dataLen);
470 memcpy(pCbPage->pageData, cbMessage, dataLen);
471 pCbPage->pageLength = dataLen;
476 pCbPage->pageHeader.totalPages = 1;
478 MSG_DEBUG("Page Length : [%d], Page Data : [%s]", pCbPage->pageLength, pCbPage->pageData);
481 unsigned short SmsPluginCbMsgHandler::encodeCbSerialNum(SMS_CBMSG_SERIAL_NUM_S snFields)
483 unsigned short serialNum = 0;
485 serialNum = ((snFields.geoScope & 0x03) << 14) | ((snFields.msgCode&0x03FF) << 4) | (snFields.updateNum&0x0F);
486 MSG_DEBUG("serialNum (%x), geo(%x), mc(%x), un(%x)\n", serialNum, snFields.geoScope, snFields.msgCode, snFields.updateNum);
491 int SmsPluginCbMsgHandler::CMAS_class(unsigned short message_id)
495 switch (message_id) {
498 ret = MSG_CMAS_PRESIDENTIAL;
504 ret = MSG_CMAS_EXTREME;
518 ret = MSG_CMAS_SEVERE;
522 ret = MSG_CMAS_AMBER;
530 ret = MSG_CMAS_EXERCISE;
534 ret = MSG_CMAS_OPERATOR_DEFINED;
543 bool SmsPluginCbMsgHandler::checkCbOpt(SMS_CBMSG_PAGE_S *CbPage, bool *pJavaMsg, msg_sim_slot_id_t simIndex)
545 bool bReceive = false;
546 char keyName[MAX_VCONFKEY_NAME_LEN];
547 memset(keyName, 0x00, sizeof(keyName));
548 snprintf(keyName, sizeof(keyName), "%s/%d", CB_RECEIVE, simIndex);
549 if (MsgSettingGetBool(keyName, &bReceive) != MSG_SUCCESS)
550 MSG_INFO("MsgSettingGetBool() is failed");
552 /* Receive CB Msg = FALSE */
554 MSG_DEBUG("RECEIVE CB = FALSE");
561 memset(keyName, 0x00, sizeof(keyName));
562 snprintf(keyName, sizeof(keyname), "%s/%d", CB_LANGUAGE, MSG_CBLANG_TYPE_ALL);
564 bool bAllLang = false;
565 if (MsgSettingGetBool(keyName, &bAllLang) != MSG_SUCCESS)
566 MSG_INFO("MsgSettingGetBool() is failed");
569 MSG_DEBUG("ALL LANGUAGE = FALSE");
571 memset(keyName, 0x00, sizeof(keyName));
572 snprintf(keyName, sizeof(keyname), "%s/%d", CB_LANGUAGE, CbPage.pageHeader.langType);
576 if (MsgSettingGetBool(keyName, &bLang) != MSG_SUCCESS)
577 MSG_INFO("MsgSettingGetBool() is failed");
579 if (!bLang || CbPage.pageHeader.langType == MSG_CBLANG_TYPE_MAX) {
580 MSG_DEBUG("LANGUAGE [%d] = FALSE", CbPage.pageHeader.langType);
586 bool bActivate = false;
587 int MsgId_from = 0, MsgId_to = 0;
588 MSG_CB_CHANNEL_S cbChannelInfo = {0, };
589 msg_error_t err = MSG_SUCCESS;
590 MsgDbHandler *dbHandle = getDbHandle();
592 err = MsgStoGetCBChannelInfo(dbHandle, &cbChannelInfo, simIndex);
593 if (err != MSG_SUCCESS)
594 MSG_ERR("Error value of MsgStoGetCBChannelInfo [%d]", err);
596 for (int i = 0; i < cbChannelInfo.channelCnt; i++) {
597 bActivate = cbChannelInfo.channelInfo[i].bActivate;
598 MsgId_from = cbChannelInfo.channelInfo[i].from;
599 MsgId_to = cbChannelInfo.channelInfo[i].to;
601 if (bActivate == true && CbPage->pageHeader.msgId >= MsgId_from && CbPage->pageHeader.msgId <= MsgId_to) {
602 MSG_DEBUG("FIND CHANNEL = [%d]", CbPage->pageHeader.msgId);
610 unsigned char SmsPluginCbMsgHandler::checkCbPage(SMS_CBMSG_PAGE_S *CbPage)
612 unsigned char currPageCnt = 0;
617 msg_error_t err = MSG_SUCCESS;
619 SmsPluginStorage *storageHandler = SmsPluginStorage::instance();
620 err = storageHandler->isReceivedCBMessage(CbPage);
622 /* check existing message with cb internal table; */
623 if (err != MSG_ERR_DB_NORECORD) {
624 MSG_DEBUG("already received message: [%d]", CbPage.pageHeader.msgId);
629 if (CbPage->pageHeader.totalPages > 0) {
630 for (unsigned int i = 0; i < pageList.size(); i++) {
631 if (pageList[i].geoScope == CbPage->pageHeader.serialNum.geoScope && pageList[i].msgCode == CbPage->pageHeader.serialNum.msgCode) {
632 MSG_DEBUG("geoScope [%d], msgCode [%d]", pageList[i].geoScope, pageList[i].msgCode);
634 if (pageList[i].msgId == CbPage->pageHeader.msgId) {
635 int updateNum = CbPage->pageHeader.serialNum.updateNum - pageList[i].updateNum;
637 if (updateNum > 0) { /* New Message Content */
639 } else if (updateNum == 0) { /* Same Message Content */
640 if (pageList[i].data.count(CbPage->pageHeader.page) != 0) {
641 MSG_DEBUG("The Page Number already exists [%d]", CbPage->pageHeader.page);
645 pair<unsigned char, SMS_CBMSG_PAGE_S> newData(CbPage->pageHeader.page, *CbPage);
646 pageList[i].data.insert(newData);
648 MSG_DEBUG("PAGE DATA : %s", CbPage->pageData);
649 MSG_DEBUG("PAIR DATA [%d] : %s", newData.first, newData.second.pageData);
651 pageList[i].pageCnt++;
652 pageList[i].totalSize += CbPage->pageLength;
654 currPageCnt = pageList[i].pageCnt;
659 } else { /* Old Message Content */
667 if (bFind == false || CbPage->pageHeader.totalPages == 1) {
668 addToPageList(CbPage);
676 void SmsPluginCbMsgHandler::MakeCbMsg(SMS_CBMSG_PAGE_S *CbPage, SMS_CBMSG_S *pCbMsg)
678 pCbMsg->cbMsgType = CbPage->cbMsgType;
679 pCbMsg->msgId = CbPage->pageHeader.msgId;
680 pCbMsg->classType = CbPage->pageHeader.dcs.classType;
681 pCbMsg->codingScheme = CbPage->pageHeader.dcs.codingScheme;
682 pCbMsg->recvTime = CbPage->pageHeader.recvTime;
684 cbPageMap::iterator it;
687 for (unsigned int i = 0; i < pageList.size(); i++) {
688 if (pageList[i].geoScope == CbPage->pageHeader.serialNum.geoScope && pageList[i].msgCode == CbPage->pageHeader.serialNum.msgCode) {
689 MSG_DEBUG("geoScope [%d], msgCode [%d]", pageList[i].geoScope, pageList[i].msgCode);
691 if (pageList[i].msgId == CbPage->pageHeader.msgId) {
692 for (it = pageList[i].data.begin(); it != pageList[i].data.end(); it++) {
693 memcpy(pCbMsg->msgData + offset, it->second.pageData, it->second.pageLength);
694 pCbMsg->msgLength += it->second.pageLength;
695 offset = pCbMsg->msgLength;
702 pCbMsg->msgLength = tmpStr.size();
704 memcpy(pCbMsg->msgData, tmpStr.c_str(), tmpStr.size());
705 pCbMsg->msgData[tmpStr.size()] = '\0';
707 MSG_DEBUG("SIZE : [%d] TOTAL MSG : %s", tmpStr.size(), tmpStr.c_str());
712 void SmsPluginCbMsgHandler::convertCbMsgToMsginfo(SMS_CBMSG_S *pCbMsg, MSG_MESSAGE_INFO_S *pMsgInfo, msg_sim_slot_id_t simIndex)
714 pMsgInfo->msgId = (msg_message_id_t)pCbMsg->msgId;
716 pMsgInfo->folderId = MSG_CBMSGBOX_ID;
718 /* Convert Type values */
719 pMsgInfo->msgType.mainType = MSG_SMS_TYPE;
721 if (pCbMsg->cbMsgType == SMS_CBMSG_TYPE_CBS) {
722 int cmas_class = CMAS_class(pCbMsg->msgId);
725 pMsgInfo->msgType.subType = MSG_CB_SMS;
727 pMsgInfo->msgType.subType = (MSG_SUB_TYPE_T)cmas_class;
728 } else if (pCbMsg->cbMsgType == SMS_CBMSG_TYPE_JAVACBS) {
729 pMsgInfo->msgType.subType = MSG_JAVACB_SMS;
732 switch (pCbMsg->classType) {
733 case SMS_MSG_CLASS_0:
734 pMsgInfo->msgType.classType = MSG_CLASS_0;
736 case SMS_MSG_CLASS_1:
737 pMsgInfo->msgType.classType = MSG_CLASS_1;
739 case SMS_MSG_CLASS_2:
740 pMsgInfo->msgType.classType = MSG_CLASS_2;
742 case SMS_MSG_CLASS_3:
743 pMsgInfo->msgType.classType = MSG_CLASS_3;
746 pMsgInfo->msgType.classType = MSG_CLASS_NONE;
750 pMsgInfo->storageId = MSG_STORAGE_PHONE;
751 pMsgInfo->networkStatus = MSG_NETWORK_RECEIVED;
752 pMsgInfo->bRead = false;
753 pMsgInfo->bProtected = false;
754 pMsgInfo->priority = MSG_MESSAGE_PRIORITY_NORMAL;
755 pMsgInfo->direction = MSG_DIRECTION_TYPE_MT;
758 pMsgInfo->nAddressCnt = 1;
760 pMsgInfo->addressList = (MSG_ADDRESS_INFO_S *)new char[sizeof(MSG_ADDRESS_INFO_S)];
761 memset(pMsgInfo->addressList, 0x00, sizeof(MSG_ADDRESS_INFO_S));
763 pMsgInfo->addressList[0].addressType = MSG_ADDRESS_TYPE_UNKNOWN;
764 pMsgInfo->addressList[0].recipientType = MSG_RECIPIENTS_TYPE_UNKNOWN;
765 pMsgInfo->sim_idx = simIndex;
767 /* TODO :: MSG ID should be used to get CB message type */
768 getDisplayName(pCbMsg->msgId, pMsgInfo->addressList[0].addressVal, simIndex);
769 MSG_SEC_DEBUG("%s", pMsgInfo->addressList[0].addressVal);
772 pMsgInfo->msgPort.valid = false;
773 pMsgInfo->msgPort.dstPort = 0;
774 pMsgInfo->msgPort.srcPort = 0;
776 pMsgInfo->displayTime = pCbMsg->recvTime;
777 MSG_DEBUG("recvTime is %d", pMsgInfo->displayTime);
779 int bufSize = pCbMsg->msgLength*2;
781 char tmpBuf[bufSize];
782 memset(tmpBuf, 0x00, sizeof(tmpBuf));
784 while (pCbMsg->msgLength > 0) {
785 if (pCbMsg->msgData[pCbMsg->msgLength-1] == ' ' ||
786 pCbMsg->msgData[pCbMsg->msgLength-1] == '\r' ||
787 pCbMsg->msgData[pCbMsg->msgLength-1] == '\n') {
793 pCbMsg->msgData[pCbMsg->msgLength] = '\0';
795 MSG_DEBUG("LENGTH %d CB MSG %s", pCbMsg->msgLength, pCbMsg->msgData);
797 /* Convert Data values */
798 pMsgInfo->dataSize = convertTextToUtf8((unsigned char*)tmpBuf, bufSize, pCbMsg);
800 if (pMsgInfo->dataSize > MAX_MSG_TEXT_LEN) {
801 pMsgInfo->bTextSms = false;
803 /* Save Message Data into File */
804 char fileName[MSG_FILENAME_LEN_MAX+1];
805 memset(fileName, 0x00, sizeof(fileName));
807 if (MsgCreateFileName(fileName) == false)
808 THROW(MsgException::FILE_ERROR, "MsgCreateFileName error");
810 MSG_SEC_DEBUG("Save Message Data into file : size[%d] name[%s]\n", pMsgInfo->dataSize, fileName);
811 if (MsgWriteIpcFile(fileName, tmpBuf, pMsgInfo->dataSize) == false)
812 THROW(MsgException::FILE_ERROR, "MsgWriteIpcFile error");
814 strncpy(pMsgInfo->msgData, fileName, MAX_MSG_DATA_LEN);
816 pMsgInfo->bTextSms = true;
818 memset(pMsgInfo->msgText, 0x00, sizeof(pMsgInfo->msgText));
819 memcpy(pMsgInfo->msgText, tmpBuf, pMsgInfo->dataSize);
820 pMsgInfo->dataSize = strlen(pMsgInfo->msgText);
821 MSG_SEC_DEBUG("CB MSG %s", pMsgInfo->msgText);
826 void SmsPluginCbMsgHandler::convertEtwsMsgToMsginfo(SMS_CBMSG_PAGE_S *EtwsMsg, MSG_MESSAGE_INFO_S *pMsgInfo, msg_sim_slot_id_t simIndex)
828 pMsgInfo->msgId = (msg_message_id_t)EtwsMsg->pageHeader.msgId;
830 pMsgInfo->folderId = MSG_CBMSGBOX_ID;
832 /* Convert Type values */
833 pMsgInfo->msgType.mainType = MSG_SMS_TYPE;
835 if (EtwsMsg->cbMsgType == SMS_CBMSG_TYPE_ETWS)
836 pMsgInfo->msgType.subType = MSG_ETWS_SMS;
838 pMsgInfo->storageId = MSG_STORAGE_PHONE;
839 pMsgInfo->networkStatus = MSG_NETWORK_RECEIVED;
840 pMsgInfo->bRead = false;
841 pMsgInfo->bProtected = false;
842 pMsgInfo->priority = MSG_MESSAGE_PRIORITY_NORMAL;
843 pMsgInfo->direction = MSG_DIRECTION_TYPE_MT;
846 pMsgInfo->nAddressCnt = 1;
848 pMsgInfo->addressList[0].addressType = MSG_ADDRESS_TYPE_UNKNOWN;
849 pMsgInfo->addressList[0].recipientType = MSG_RECIPIENTS_TYPE_UNKNOWN;
851 getDisplayName(EtwsMsg->pageHeader.msgId, pMsgInfo->addressList[0].addressVal, simIndex);
852 MSG_SEC_DEBUG("%s", pMsgInfo->addressList[0].addressVal);
854 pMsgInfo->msgPort.valid = false;
855 pMsgInfo->msgPort.dstPort = 0;
856 pMsgInfo->msgPort.srcPort = 0;
858 pMsgInfo->displayTime = EtwsMsg->pageHeader.recvTime;
859 MSG_DEBUG("recvTime is %d", pMsgInfo->displayTime);
860 MSG_DEBUG("LENGTH %d", EtwsMsg->pageLength);
861 pMsgInfo->bTextSms = true;
862 pMsgInfo->dataSize = EtwsMsg->pageLength;
863 memset(pMsgInfo->msgData, 0x00, sizeof(pMsgInfo->msgData));
864 memcpy(pMsgInfo->msgData, EtwsMsg->pageData, pMsgInfo->dataSize);
867 int SmsPluginCbMsgHandler::convertTextToUtf8(unsigned char* outBuf, int outBufSize, SMS_CBMSG_S* pCbMsg)
869 int convertedTextSize = 0;
870 MSG_LANG_INFO_S langInfo = {0, };
872 MsgTextConvert *textCvt = MsgTextConvert::instance();
874 if (!outBuf || !pCbMsg) {
875 MSG_DEBUG("invalid param.\n");
879 langInfo.bSingleShift = false;
880 langInfo.bLockingShift = false;
883 /* Convert Data values */
884 if (pCbMsg->codingScheme == SMS_CHARSET_7BIT)
885 convertedTextSize = textCvt->convertGSM7bitToUTF8(outBuf, outBufSize, (unsigned char*)pCbMsg->msgData, pCbMsg->msgLength, &langInfo);
886 else if (pCbMsg->codingScheme == SMS_CHARSET_UCS2)
887 convertedTextSize = textCvt->convertUCS2ToUTF8(outBuf, outBufSize, (unsigned char*)pCbMsg->msgData, pCbMsg->msgLength);
889 return convertedTextSize;
892 void SmsPluginCbMsgHandler::addToPageList(SMS_CBMSG_PAGE_S *CbPage)
894 CB_PAGE_INFO_S tmpInfo;
896 tmpInfo.geoScope = CbPage->pageHeader.serialNum.geoScope;
897 tmpInfo.msgCode = CbPage->pageHeader.serialNum.msgCode;
898 tmpInfo.updateNum = CbPage->pageHeader.serialNum.updateNum;
899 tmpInfo.msgId = CbPage->pageHeader.msgId;
900 tmpInfo.totalPages = CbPage->pageHeader.totalPages;
903 tmpInfo.totalSize = CbPage->pageLength;
905 pair<unsigned char, SMS_CBMSG_PAGE_S> newData(CbPage->pageHeader.page, *CbPage);
906 tmpInfo.data.insert(newData);
908 MSG_DEBUG("MSG DATA : %s", CbPage->pageData);
909 MSG_DEBUG("PAIR DATA [%d] : %s", newData.first, newData.second.pageData);
911 pageList.push_back(tmpInfo);
915 void SmsPluginCbMsgHandler::removeFromPageList(SMS_CBMSG_PAGE_S *CbPage)
919 for (index = 0; index < pageList.size(); index++) {
920 if (pageList[index].geoScope == CbPage->pageHeader.serialNum.geoScope && pageList[index].msgCode == CbPage->pageHeader.serialNum.msgCode) {
921 MSG_DEBUG("geoScope [%d], msgCode [%d]", pageList[index].geoScope, pageList[index].msgCode);
923 if (pageList[index].msgId == CbPage->pageHeader.msgId)
928 MSG_DEBUG("remove index [%d]", index);
930 pageList.erase(pageList.begin()+index);
934 void SmsPluginCbMsgHandler::decodeCbMsgDCS(unsigned char dcsData, const unsigned char *pMsgData, SMS_CBMSG_DCS_S* pDcs)
936 pDcs->codingGroup = SMS_CBMSG_CODGRP_GENERAL_DCS;
937 pDcs->classType = SMS_MSG_CLASS_NONE;
938 pDcs->bCompressed = false;
939 pDcs->codingScheme = SMS_CHARSET_7BIT;
940 pDcs->langType = SMS_CBMSG_LANG_UNSPECIFIED;
941 memset(pDcs->iso639Lang, 0x00, sizeof(pDcs->iso639Lang));
943 pDcs->rawData = dcsData;
945 unsigned char codingGrp = (dcsData & 0xF0) >> 4;
951 pDcs->codingGroup = SMS_CBMSG_CODGRP_GENERAL_DCS;
952 pDcs->langType = (SMS_CBMSG_LANG_TYPE_T)dcsData;
957 if (dcsData == 0x10 || dcsData == 0x11) {
958 pDcs->codingGroup = SMS_CBMSG_CODGRP_GENERAL_DCS;
959 pDcs->codingScheme = (dcsData & 0x01) ? SMS_CHARSET_UCS2 : SMS_CHARSET_7BIT;
960 pDcs->langType = SMS_CBMSG_LANG_ISO639;
961 MSG_DEBUG("codingScheme: [%d]", pDcs->codingScheme);
962 if (pMsgData[0] && pMsgData[1]) {
963 pDcs->iso639Lang[0] = pMsgData[0] & 0x7F;
964 pDcs->iso639Lang[1] = (pMsgData[0] & 0X80) >> 7;
965 pDcs->iso639Lang[1] |= (pMsgData[1] & 0X3F) << 1;
966 pDcs->iso639Lang[2] = 0x13; /* CR */
968 /* Default it to English if pMsgData is NULL */
969 pDcs->iso639Lang[0] = 0x45; /* E */
970 pDcs->iso639Lang[1] = 0x4E; /* N */
971 pDcs->iso639Lang[2] = 0x13; /* CR */
981 pDcs->codingGroup = SMS_CBMSG_CODGRP_GENERAL_DCS;
983 pDcs->bCompressed = (dcsData & 0x20) ? true : false;
986 pDcs->classType = (SMS_MSG_CLASS_T)(dcsData & 0x03);
988 unsigned char tmpScheme = (dcsData & 0x0C) >> 2;
992 pDcs->codingScheme = SMS_CHARSET_7BIT;
995 pDcs->codingScheme = SMS_CHARSET_8BIT;
998 pDcs->codingScheme = SMS_CHARSET_UCS2;
1001 MSG_DEBUG("tmpScheme: [%d]", tmpScheme);
1009 pDcs->classType = (MSG_CLASS_TYPE_T)(dcsData & 0x03);
1010 pDcs->codingScheme = (SMS_CODING_SCHEME_T)((dcsData & 0x0C) >> 2);
1015 pDcs->codingGroup = SMS_CBMSG_CODGRP_WAP;
1020 pDcs->codingGroup = SMS_CBMSG_CODGRP_CLASS_CODING;
1021 pDcs->codingScheme = (dcsData & 0x04) ? SMS_CHARSET_8BIT : SMS_CHARSET_7BIT;
1022 pDcs->classType = (MSG_CLASS_TYPE_T)(dcsData & 0x03);
1026 MSG_DEBUG("codingGrp: [0x%x]", codingGrp);
1032 void SmsPluginCbMsgHandler::convertLangType(SMS_CBMSG_LANG_TYPE_T InType , MSG_CB_LANGUAGE_TYPE_T *pOutType)
1035 case SMS_CBMSG_LANG_GERMAN :
1036 *pOutType = MSG_CBLANG_TYPE_GER;
1039 case SMS_CBMSG_LANG_ENGLISH :
1040 *pOutType = MSG_CBLANG_TYPE_ENG;
1043 case SMS_CBMSG_LANG_ITALIAN :
1044 *pOutType = MSG_CBLANG_TYPE_ITA;
1047 case SMS_CBMSG_LANG_FRENCH :
1048 *pOutType = MSG_CBLANG_TYPE_FRE;
1051 case SMS_CBMSG_LANG_SPANISH :
1052 *pOutType = MSG_CBLANG_TYPE_SPA;
1055 case SMS_CBMSG_LANG_DUTCH :
1056 *pOutType = MSG_CBLANG_TYPE_NED;
1059 case SMS_CBMSG_LANG_SWEDISH :
1060 *pOutType = MSG_CBLANG_TYPE_SWE;
1063 case SMS_CBMSG_LANG_PORTUGUESE :
1064 *pOutType = MSG_CBLANG_TYPE_POR;
1067 case SMS_CBMSG_LANG_TURKISH :
1068 *pOutType = MSG_CBLANG_TYPE_TUR;
1072 *pOutType = MSG_CBLANG_TYPE_MAX;
1078 unsigned long SmsPluginCbMsgHandler::getRecvTime()
1082 recvTime = time(NULL);
1084 return (unsigned long)recvTime;
1088 void SmsPluginCbMsgHandler::getDisplayName(unsigned short MsgId, char *pDisplayName, msg_sim_slot_id_t simIndex)
1090 MSG_CB_CHANNEL_S cbChannelInfo = {0, };
1091 msg_error_t err = MSG_SUCCESS;
1092 MsgDbHandler *dbHandle = getDbHandle();
1094 err = MsgStoGetCBChannelInfo(dbHandle, &cbChannelInfo, simIndex);
1095 MSG_DEBUG("MsgStoGetCBChannelInfo [err = %d]", err);
1097 for (int i = 0; i < cbChannelInfo.channelCnt; i++) {
1098 if (MsgId >= cbChannelInfo.channelInfo[i].from && MsgId <= cbChannelInfo.channelInfo[i].to) {
1099 MSG_DEBUG("FIND MSG ID = [%d]", MsgId);
1101 char strTmp[CB_CHANNEL_NAME_MAX + 1];
1102 memset(strTmp, 0x00, sizeof(strTmp));
1104 strncpy(strTmp, cbChannelInfo.channelInfo[i].name, CB_CHANNEL_NAME_MAX);
1106 if (strlen(strTmp) > 0)
1107 snprintf(pDisplayName, sizeof(strTmp), "[%s]", strTmp);
1109 snprintf(pDisplayName, sizeof(unsigned short), "[%d]", MsgId);
1112 #ifdef MSG_NOTI_INTEGRATION
1113 snprintf(pDisplayName, MAX_ADDRESS_VAL_LEN + 1, "CB message");
1115 snprintf(pDisplayName, MAX_ADDRESS_VAL_LEN + 1, "[%d]", MsgId);
1123 snprintf(pDisplayName, MAX_ADDRESS_VAL_LEN + 1, "[%d]", MsgId);