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] = {0};
209 memcpy(cbData, pCbMsg->szMsgData, pCbMsg->Length);
210 cbData[pCbMsg->Length] = '\0';
213 MSG_INFO("Received CB length:%d", pCbMsg->Length);
214 char cbDataTmp[(pCbMsg->Length*2)+1];
215 memset(cbDataTmp, 0x00, sizeof(cbDataTmp));
217 for (int i = 0; i < pCbMsg->Length; i++) {
218 snprintf(cbDataTmp+(i*2), sizeof(cbDataTmp)-(i*2), "%02X", cbData[i]);
220 MSG_INFO("[%s]", cbDataTmp);
222 pCbPage->cbMsgType = SMS_CBMSG_TYPE_CBS;
225 pCbPage->pageHeader.serialNum.geoScope = (cbData[0] & 0xC0) >> 6;
227 pCbPage->pageHeader.serialNum.msgCode = (cbData[0] & 0x3F) << 4;
228 pCbPage->pageHeader.serialNum.msgCode |= (cbData[1] & 0xF0) >> 4;
230 pCbPage->pageHeader.serialNum.updateNum = cbData[1] & 0x0F;
232 MSG_DEBUG("geoScope : [%d], msgCode : [%d], updateNum : [%d]", pCbPage->pageHeader.serialNum.geoScope, pCbPage->pageHeader.serialNum.msgCode, pCbPage->pageHeader.serialNum.updateNum);
234 pCbPage->pageHeader.msgId = (cbData[2] << 8) | cbData[3];
236 MSG_DEBUG("MSG ID : [%d]", pCbPage->pageHeader.msgId);
239 decodeCbMsgDCS(cbData[4], (unsigned char*)cbData + 6, &(pCbPage->pageHeader.dcs));
242 pCbPage->pageHeader.totalPages = cbData[5] & 0x0F;
243 pCbPage->pageHeader.page = (cbData[5] & 0xF0) >> 4;
245 if (pCbPage->pageHeader.totalPages > MAX_CBMSG_PAGE_NUM)
246 THROW(MsgException::SMS_PLG_ERROR, "CB Page Count is over MAX[%d]", pCbPage->pageHeader.totalPages);
248 MSG_DEBUG("Total Page : [%d], Page : [%d]", pCbPage->pageHeader.totalPages, pCbPage->pageHeader.page);
250 /* Convert Language Type */
251 convertLangType(pCbPage->pageHeader.dcs.langType, &(pCbPage->pageHeader.langType));
253 MSG_DEBUG("In Language Type : [%d], Out Language Type : [%d]", pCbPage->pageHeader.dcs.langType, pCbPage->pageHeader.langType);
254 MSG_DEBUG("iso639Lang : [%s]", pCbPage->pageHeader.dcs.iso639Lang);
255 /* Get Receive Time */
256 pCbPage->pageHeader.recvTime = getRecvTime();
259 int dataLen = pCbMsg->Length - 6;
261 MSG_DEBUG("codingScheme:[%d]", pCbPage->pageHeader.dcs.codingScheme);
263 switch (pCbPage->pageHeader.dcs.codingScheme) {
264 case SMS_CHARSET_7BIT: {
265 MSG_DEBUG("GSM 7 BIT");
267 dataLen = (dataLen*8) / 7;
269 SmsPluginUDCodec udCodec;
270 char pageData[MAX_CBMSG_PAGE_SIZE*8/7] = {0};
271 int unpackLen = udCodec.unpack7bitChar(&cbData[6], dataLen, 0, pageData);
273 if (pCbPage->pageHeader.dcs.iso639Lang[0]) {
274 unpackLen = unpackLen - 3;
276 memcpy(pCbPage->pageData, &pageData[3], unpackLen);
280 memcpy(pCbPage->pageData, &pageData, unpackLen);
283 MSG_DEBUG("unpackLen : [%d]", unpackLen);
285 pCbPage->pageLength = unpackLen;
286 pCbPage->pageData[unpackLen] = '\0';
290 case SMS_CHARSET_8BIT:
291 case SMS_CHARSET_UCS2: {
292 MSG_DEBUG("UCS2 or 8BIT");
294 if (pCbPage->pageHeader.dcs.iso639Lang[0]) {
295 memcpy(pCbPage->pageData, &cbData[8], dataLen - 2);
296 pCbPage->pageLength = dataLen - 2;
298 memcpy(pCbPage->pageData, &cbData[6], dataLen);
299 pCbPage->pageLength = dataLen;
305 MSG_DEBUG("Page Length : [%d], Page Data : [%s]", pCbPage->pageLength, pCbPage->pageData);
309 void SmsPluginCbMsgHandler::DecodeEtwsMsg(TelSmsEtwsMsg_t *pEtwsMsg, SMS_ETWS_PRIMARY_S *pEtwsPn)
311 if ( !pEtwsMsg || !pEtwsPn )
314 if (pEtwsMsg->Length > MAX_ETWS_SIZE)
315 THROW(MsgException::SMS_PLG_ERROR, "ETWS Msg Size is over MAX [%d]", pEtwsMsg->Length);
317 unsigned char EtwsData[pEtwsMsg->Length+1];
319 memset(EtwsData, 0x00, sizeof(EtwsData));
320 memcpy(EtwsData, pEtwsMsg->szMsgData, pEtwsMsg->Length);
321 EtwsData[pEtwsMsg->Length] = '\0';
323 /* print received msg data */
324 MSG_INFO("Received Etws length:%d", pEtwsMsg->Length);
325 char EtwsDataTmp[(pEtwsMsg->Length*2)+1];
326 memset(EtwsDataTmp, 0x00, sizeof(EtwsDataTmp));
328 for (int i = 0; i < pEtwsMsg->Length; i++) {
329 snprintf(EtwsDataTmp+(i*2), sizeof(EtwsDataTmp)-(i*2), "%02X", EtwsData[i]);
331 MSG_INFO("[%s]", EtwsDataTmp);
334 pEtwsPn->recvTime = getRecvTime();
337 pEtwsPn->serialNum.geoScope = (EtwsData[0] & 0xC0) >> 6;
338 pEtwsPn->serialNum.msgCode = (EtwsData[0] & 0x3F) << 4;
339 pEtwsPn->serialNum.msgCode |= (EtwsData[1] & 0xF0) >> 4;
340 pEtwsPn->serialNum.updateNum = EtwsData[1] & 0x0F;
342 MSG_DEBUG("geoScope : [%d], msgCode : [%d], updateNum : [%d]", pEtwsPn->serialNum.geoScope, pEtwsPn->serialNum.msgCode, pEtwsPn->serialNum.updateNum);
344 /* Message Identifier */
345 pEtwsPn->msgId = (EtwsData[2] << 8) | EtwsData[3];
346 MSG_DEBUG("MSG ID : [%d]", pEtwsPn->msgId);
349 pEtwsPn->warningType = (EtwsData[4] << 8) | EtwsData[5];
350 MSG_DEBUG("warningType : [0x%04x]", pEtwsPn->msgId);
352 /* warning security information */
353 memcpy(pEtwsPn->warningSecurityInfo, &EtwsData[6], sizeof(pEtwsPn->warningSecurityInfo)); /* 50bytes */
354 for (unsigned int i = 0; i < sizeof(pEtwsPn->warningSecurityInfo); i++) {
355 MSG_DEBUG("warning secu info [%02x]", pEtwsPn->warningSecurityInfo[i]);
359 void SmsPluginCbMsgHandler::Decode3gCbMsg(TelSmsCbMsg_t *pCbMsg, SMS_CBMSG_PAGE_S *pCbPage)
361 unsigned char cbData[MAX_CBMSG_TOTAL_PAGE_SIZE + 1] = {0};
362 memcpy(cbData, pCbMsg->szMsgData, pCbMsg->Length);
363 cbData[pCbMsg->Length] = '\0';
366 MSG_INFO("Received CB length:%d", pCbMsg->Length);
367 char cbDataTmp[(pCbMsg->Length*2)+1];
368 memset(cbDataTmp, 0x00, sizeof(cbDataTmp));
370 for (int i = 0; i < pCbMsg->Length; i++) {
371 snprintf(cbDataTmp+(i*2), sizeof(cbDataTmp)-(i*2), "%02X", cbData[i]);
373 MSG_INFO("[%s]", cbDataTmp);
375 pCbPage->cbMsgType = (SMS_CBMSG_TYPE_T)cbData[0];
377 pCbPage->pageHeader.msgId = (cbData[1] << 8) | cbData[2];
379 MSG_DEBUG("MSG ID : [%d]", pCbPage->pageHeader.msgId);
382 pCbPage->pageHeader.serialNum.geoScope = (cbData[3] & 0xC0) >> 6;
384 pCbPage->pageHeader.serialNum.msgCode = (cbData[3] & 0x3F) << 4;
385 pCbPage->pageHeader.serialNum.msgCode |= (cbData[4] & 0xF0) >> 4;
387 pCbPage->pageHeader.serialNum.updateNum = cbData[4] & 0x0F;
389 MSG_DEBUG("geoScope : [%d], msgCode : [%d], updateNum : [%d]", pCbPage->pageHeader.serialNum.geoScope, pCbPage->pageHeader.serialNum.msgCode, pCbPage->pageHeader.serialNum.updateNum);
392 decodeCbMsgDCS(cbData[5], (unsigned char*)cbData + 6, &(pCbPage->pageHeader.dcs));
394 /* Convert Language Type */
395 convertLangType(pCbPage->pageHeader.dcs.langType, &(pCbPage->pageHeader.langType));
397 MSG_DEBUG("In Language Type : [%d], Out Language Type : [%d]", pCbPage->pageHeader.dcs.langType, pCbPage->pageHeader.langType);
399 /* Get Receive Time */
400 pCbPage->pageHeader.recvTime = getRecvTime();
401 pCbPage->pageHeader.totalPages = cbData[6];
407 switch (pCbPage->pageHeader.dcs.codingScheme) {
408 case SMS_CHARSET_7BIT: {
409 for (int i = 0; i < pCbPage->pageHeader.totalPages; ++i) {
410 unsigned char cbMessage[MAX_CBMSG_PAGE_SIZE] = {0};
411 dataLen = cbData[7 + (i + 1) * MAX_CBMSG_PAGE_SIZE + i];
413 if (dataLen > MAX_CBMSG_PAGE_SIZE)
414 THROW(MsgException::SMS_PLG_ERROR, "CB Msg Size is over MAX [%d]", dataLen);
416 memcpy(cbMessage, &cbData[7+(i*MAX_CBMSG_PAGE_SIZE)+ i], dataLen);
417 dataLen = (dataLen*8) / 7;
419 SmsPluginUDCodec udCodec;
420 int unpackLen = udCodec.unpack7bitChar((const unsigned char *)cbMessage, dataLen, 0, pCbPage->pageData + offset);
423 pCbPage->pageLength = offset;
427 case SMS_CHARSET_8BIT:
428 case SMS_CHARSET_UCS2: {
430 char cbMessage[MAX_CBMSG_PAGE_SIZE]= {0, };
432 for (int i = 0; i < pCbPage->pageHeader.totalPages; ++i) {
433 dataLen = cbData[7+(i+1)*MAX_CBMSG_PAGE_SIZE + i];
434 memcpy(cbMessage + offset, &cbData[7+(i*MAX_CBMSG_PAGE_SIZE)+ i], dataLen);
439 if (pCbPage->pageHeader.dcs.iso639Lang[0]) {
440 int tmpDataLen = (dataLen > 2)?(dataLen - 2):0;
441 memcpy(pCbPage->pageData, cbMessage + 2, tmpDataLen);
442 pCbPage->pageLength = tmpDataLen;
444 memcpy(pCbPage->pageData, cbMessage, dataLen);
445 pCbPage->pageLength = dataLen;
448 char cbMessage[MAX_CBMSG_PAGE_SIZE*MAX_CBMSG_PAGE_NUM+1] = {0, };
450 for (int i = 0; i < pCbPage->pageHeader.totalPages; ++i) {
451 if (pCbPage->pageHeader.dcs.iso639Lang[0]) {
452 dataLen = cbData[7+(i+1)*MAX_CBMSG_PAGE_SIZE + i] - 2;
454 memcpy(cbMessage + offset, &cbData[7+(i*MAX_CBMSG_PAGE_SIZE)+ i + 2], dataLen);
458 dataLen = cbData[7+(i+1)*MAX_CBMSG_PAGE_SIZE + i];
460 memcpy(cbMessage + offset, &cbData[7+(i*MAX_CBMSG_PAGE_SIZE)+ 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 if (MsgSettingGetBool(keyName, &bReceive) != MSG_SUCCESS)
546 MSG_INFO("MsgSettingGetBool() is failed");
548 /* Receive CB Msg = FALSE */
550 MSG_DEBUG("RECEIVE CB = FALSE");
557 memset(keyName, 0x00, sizeof(keyName));
558 snprintf(keyName, sizeof(keyname), "%s/%d", CB_LANGUAGE, MSG_CBLANG_TYPE_ALL);
560 bool bAllLang = false;
561 if (MsgSettingGetBool(keyName, &bAllLang) != MSG_SUCCESS)
562 MSG_INFO("MsgSettingGetBool() is failed");
565 MSG_DEBUG("ALL LANGUAGE = FALSE");
567 memset(keyName, 0x00, sizeof(keyName));
568 snprintf(keyName, sizeof(keyname), "%s/%d", CB_LANGUAGE, CbPage.pageHeader.langType);
572 if (MsgSettingGetBool(keyName, &bLang) != MSG_SUCCESS)
573 MSG_INFO("MsgSettingGetBool() is failed");
575 if (!bLang || CbPage.pageHeader.langType == MSG_CBLANG_TYPE_MAX) {
576 MSG_DEBUG("LANGUAGE [%d] = FALSE", CbPage.pageHeader.langType);
582 bool bActivate = false;
583 int MsgId_from = 0, MsgId_to = 0;
584 MSG_CB_CHANNEL_S cbChannelInfo = {0, };
585 msg_error_t err = MSG_SUCCESS;
586 MsgDbHandler *dbHandle = getDbHandle();
588 err = MsgStoGetCBChannelInfo(dbHandle, &cbChannelInfo, simIndex);
589 if (err != MSG_SUCCESS)
590 MSG_ERR("Error value of MsgStoGetCBChannelInfo [%d]", err);
592 for (int i = 0; i < cbChannelInfo.channelCnt; i++) {
593 bActivate = cbChannelInfo.channelInfo[i].bActivate;
594 MsgId_from = cbChannelInfo.channelInfo[i].from;
595 MsgId_to = cbChannelInfo.channelInfo[i].to;
597 if (bActivate == true && CbPage->pageHeader.msgId >= MsgId_from && CbPage->pageHeader.msgId <= MsgId_to) {
598 MSG_DEBUG("FIND CHANNEL = [%d]", CbPage->pageHeader.msgId);
606 unsigned char SmsPluginCbMsgHandler::checkCbPage(SMS_CBMSG_PAGE_S *CbPage)
608 unsigned char currPageCnt = 0;
613 msg_error_t err = MSG_SUCCESS;
615 SmsPluginStorage *storageHandler = SmsPluginStorage::instance();
616 err = storageHandler->isReceivedCBMessage(CbPage);
618 /* check existing message with cb internal table; */
619 if (err != MSG_ERR_DB_NORECORD) {
620 MSG_DEBUG("already received message: [%d]", CbPage.pageHeader.msgId);
625 if (CbPage->pageHeader.totalPages > 0) {
626 for (unsigned int i = 0; i < pageList.size(); i++) {
627 if (pageList[i].geoScope == CbPage->pageHeader.serialNum.geoScope && pageList[i].msgCode == CbPage->pageHeader.serialNum.msgCode) {
628 MSG_DEBUG("geoScope [%d], msgCode [%d]", pageList[i].geoScope, pageList[i].msgCode);
630 if (pageList[i].msgId == CbPage->pageHeader.msgId) {
631 int updateNum = CbPage->pageHeader.serialNum.updateNum - pageList[i].updateNum;
633 if (updateNum > 0) { /* New Message Content */
635 } else if (updateNum == 0) { /* Same Message Content */
636 if (pageList[i].data.count(CbPage->pageHeader.page) != 0) {
637 MSG_DEBUG("The Page Number already exists [%d]", CbPage->pageHeader.page);
641 pair<unsigned char, SMS_CBMSG_PAGE_S> newData(CbPage->pageHeader.page, *CbPage);
642 pageList[i].data.insert(newData);
644 MSG_DEBUG("PAGE DATA : %s", CbPage->pageData);
645 MSG_DEBUG("PAIR DATA [%d] : %s", newData.first, newData.second.pageData);
647 pageList[i].pageCnt++;
648 pageList[i].totalSize += CbPage->pageLength;
650 currPageCnt = pageList[i].pageCnt;
655 } else { /* Old Message Content */
663 if (bFind == false || CbPage->pageHeader.totalPages == 1) {
664 addToPageList(CbPage);
672 void SmsPluginCbMsgHandler::MakeCbMsg(SMS_CBMSG_PAGE_S *CbPage, SMS_CBMSG_S *pCbMsg)
674 pCbMsg->cbMsgType = CbPage->cbMsgType;
675 pCbMsg->msgId = CbPage->pageHeader.msgId;
676 pCbMsg->classType = CbPage->pageHeader.dcs.classType;
677 pCbMsg->codingScheme = CbPage->pageHeader.dcs.codingScheme;
678 pCbMsg->recvTime = CbPage->pageHeader.recvTime;
680 cbPageMap::iterator it;
683 for (unsigned int i = 0; i < pageList.size(); i++) {
684 if (pageList[i].geoScope == CbPage->pageHeader.serialNum.geoScope && pageList[i].msgCode == CbPage->pageHeader.serialNum.msgCode) {
685 MSG_DEBUG("geoScope [%d], msgCode [%d]", pageList[i].geoScope, pageList[i].msgCode);
687 if (pageList[i].msgId == CbPage->pageHeader.msgId) {
688 for (it = pageList[i].data.begin(); it != pageList[i].data.end(); it++) {
689 memcpy(pCbMsg->msgData + offset, it->second.pageData, it->second.pageLength);
690 pCbMsg->msgLength += it->second.pageLength;
691 offset = pCbMsg->msgLength;
698 pCbMsg->msgLength = tmpStr.size();
700 memcpy(pCbMsg->msgData, tmpStr.c_str(), tmpStr.size());
701 pCbMsg->msgData[tmpStr.size()] = '\0';
703 MSG_DEBUG("SIZE : [%d] TOTAL MSG : %s", tmpStr.size(), tmpStr.c_str());
708 void SmsPluginCbMsgHandler::convertCbMsgToMsginfo(SMS_CBMSG_S *pCbMsg, MSG_MESSAGE_INFO_S *pMsgInfo, msg_sim_slot_id_t simIndex)
710 pMsgInfo->msgId = (msg_message_id_t)pCbMsg->msgId;
712 pMsgInfo->folderId = MSG_CBMSGBOX_ID;
714 /* Convert Type values */
715 pMsgInfo->msgType.mainType = MSG_SMS_TYPE;
717 if (pCbMsg->cbMsgType == SMS_CBMSG_TYPE_CBS) {
718 int cmas_class = CMAS_class(pCbMsg->msgId);
721 pMsgInfo->msgType.subType = MSG_CB_SMS;
723 pMsgInfo->msgType.subType = (MSG_SUB_TYPE_T)cmas_class;
724 } else if (pCbMsg->cbMsgType == SMS_CBMSG_TYPE_JAVACBS) {
725 pMsgInfo->msgType.subType = MSG_JAVACB_SMS;
728 switch (pCbMsg->classType) {
729 case SMS_MSG_CLASS_0:
730 pMsgInfo->msgType.classType = MSG_CLASS_0;
732 case SMS_MSG_CLASS_1:
733 pMsgInfo->msgType.classType = MSG_CLASS_1;
735 case SMS_MSG_CLASS_2:
736 pMsgInfo->msgType.classType = MSG_CLASS_2;
738 case SMS_MSG_CLASS_3:
739 pMsgInfo->msgType.classType = MSG_CLASS_3;
742 pMsgInfo->msgType.classType = MSG_CLASS_NONE;
746 pMsgInfo->storageId = MSG_STORAGE_PHONE;
747 pMsgInfo->networkStatus = MSG_NETWORK_RECEIVED;
748 pMsgInfo->bRead = false;
749 pMsgInfo->bProtected = false;
750 pMsgInfo->priority = MSG_MESSAGE_PRIORITY_NORMAL;
751 pMsgInfo->direction = MSG_DIRECTION_TYPE_MT;
754 pMsgInfo->nAddressCnt = 1;
756 pMsgInfo->addressList = (MSG_ADDRESS_INFO_S *)new char[sizeof(MSG_ADDRESS_INFO_S)];
757 memset(pMsgInfo->addressList, 0x00, sizeof(MSG_ADDRESS_INFO_S));
759 pMsgInfo->addressList[0].addressType = MSG_ADDRESS_TYPE_UNKNOWN;
760 pMsgInfo->addressList[0].recipientType = MSG_RECIPIENTS_TYPE_UNKNOWN;
761 pMsgInfo->sim_idx = simIndex;
763 /* TODO :: MSG ID should be used to get CB message type */
764 getDisplayName(pCbMsg->msgId, pMsgInfo->addressList[0].addressVal, simIndex);
765 MSG_SEC_DEBUG("%s", pMsgInfo->addressList[0].addressVal);
768 pMsgInfo->msgPort.valid = false;
769 pMsgInfo->msgPort.dstPort = 0;
770 pMsgInfo->msgPort.srcPort = 0;
772 pMsgInfo->displayTime = pCbMsg->recvTime;
773 MSG_DEBUG("recvTime is %d", pMsgInfo->displayTime);
775 int bufSize = pCbMsg->msgLength*2;
777 char tmpBuf[bufSize];
778 memset(tmpBuf, 0x00, sizeof(tmpBuf));
780 while (pCbMsg->msgLength > 0) {
781 if (pCbMsg->msgData[pCbMsg->msgLength-1] == ' ' ||
782 pCbMsg->msgData[pCbMsg->msgLength-1] == '\r' ||
783 pCbMsg->msgData[pCbMsg->msgLength-1] == '\n') {
789 pCbMsg->msgData[pCbMsg->msgLength] = '\0';
791 MSG_DEBUG("LENGTH %d CB MSG %s", pCbMsg->msgLength, pCbMsg->msgData);
793 /* Convert Data values */
794 pMsgInfo->dataSize = convertTextToUtf8((unsigned char*)tmpBuf, bufSize, pCbMsg);
796 if (pMsgInfo->dataSize > MAX_MSG_TEXT_LEN) {
797 pMsgInfo->bTextSms = false;
799 /* Save Message Data into File */
800 char fileName[MSG_FILENAME_LEN_MAX+1];
801 memset(fileName, 0x00, sizeof(fileName));
803 if (MsgCreateFileName(fileName) == false)
804 THROW(MsgException::FILE_ERROR, "MsgCreateFileName error");
806 MSG_SEC_DEBUG("Save Message Data into file : size[%d] name[%s]\n", pMsgInfo->dataSize, fileName);
807 if (MsgWriteIpcFile(fileName, tmpBuf, pMsgInfo->dataSize) == false)
808 THROW(MsgException::FILE_ERROR, "MsgWriteIpcFile error");
810 strncpy(pMsgInfo->msgData, fileName, MAX_MSG_DATA_LEN);
812 pMsgInfo->bTextSms = true;
814 memset(pMsgInfo->msgText, 0x00, sizeof(pMsgInfo->msgText));
815 memcpy(pMsgInfo->msgText, tmpBuf, pMsgInfo->dataSize);
816 pMsgInfo->dataSize = strlen(pMsgInfo->msgText);
817 MSG_SEC_DEBUG("CB MSG %s", pMsgInfo->msgText);
822 void SmsPluginCbMsgHandler::convertEtwsMsgToMsginfo(SMS_CBMSG_PAGE_S *EtwsMsg, MSG_MESSAGE_INFO_S *pMsgInfo, msg_sim_slot_id_t simIndex)
824 pMsgInfo->msgId = (msg_message_id_t)EtwsMsg->pageHeader.msgId;
826 pMsgInfo->folderId = MSG_CBMSGBOX_ID;
828 /* Convert Type values */
829 pMsgInfo->msgType.mainType = MSG_SMS_TYPE;
831 if (EtwsMsg->cbMsgType == SMS_CBMSG_TYPE_ETWS)
832 pMsgInfo->msgType.subType = MSG_ETWS_SMS;
834 pMsgInfo->storageId = MSG_STORAGE_PHONE;
835 pMsgInfo->networkStatus = MSG_NETWORK_RECEIVED;
836 pMsgInfo->bRead = false;
837 pMsgInfo->bProtected = false;
838 pMsgInfo->priority = MSG_MESSAGE_PRIORITY_NORMAL;
839 pMsgInfo->direction = MSG_DIRECTION_TYPE_MT;
842 pMsgInfo->nAddressCnt = 1;
844 pMsgInfo->addressList[0].addressType = MSG_ADDRESS_TYPE_UNKNOWN;
845 pMsgInfo->addressList[0].recipientType = MSG_RECIPIENTS_TYPE_UNKNOWN;
847 getDisplayName(EtwsMsg->pageHeader.msgId, pMsgInfo->addressList[0].addressVal, simIndex);
848 MSG_SEC_DEBUG("%s", pMsgInfo->addressList[0].addressVal);
850 pMsgInfo->msgPort.valid = false;
851 pMsgInfo->msgPort.dstPort = 0;
852 pMsgInfo->msgPort.srcPort = 0;
854 pMsgInfo->displayTime = EtwsMsg->pageHeader.recvTime;
855 MSG_DEBUG("recvTime is %d", pMsgInfo->displayTime);
856 MSG_DEBUG("LENGTH %d", EtwsMsg->pageLength);
857 pMsgInfo->bTextSms = true;
858 pMsgInfo->dataSize = EtwsMsg->pageLength;
859 memset(pMsgInfo->msgData, 0x00, sizeof(pMsgInfo->msgData));
860 memcpy(pMsgInfo->msgData, EtwsMsg->pageData, pMsgInfo->dataSize);
863 int SmsPluginCbMsgHandler::convertTextToUtf8(unsigned char* outBuf, int outBufSize, SMS_CBMSG_S* pCbMsg)
865 int convertedTextSize = 0;
866 MSG_LANG_INFO_S langInfo = {0, };
868 MsgTextConvert *textCvt = MsgTextConvert::instance();
870 if (!outBuf || !pCbMsg) {
871 MSG_DEBUG("invalid param.\n");
875 langInfo.bSingleShift = false;
876 langInfo.bLockingShift = false;
879 /* Convert Data values */
880 if (pCbMsg->codingScheme == SMS_CHARSET_7BIT)
881 convertedTextSize = textCvt->convertGSM7bitToUTF8(outBuf, outBufSize, (unsigned char*)pCbMsg->msgData, pCbMsg->msgLength, &langInfo);
882 else if (pCbMsg->codingScheme == SMS_CHARSET_UCS2)
883 convertedTextSize = textCvt->convertUCS2ToUTF8(outBuf, outBufSize, (unsigned char*)pCbMsg->msgData, pCbMsg->msgLength);
885 return convertedTextSize;
888 void SmsPluginCbMsgHandler::addToPageList(SMS_CBMSG_PAGE_S *CbPage)
890 CB_PAGE_INFO_S tmpInfo;
892 tmpInfo.geoScope = CbPage->pageHeader.serialNum.geoScope;
893 tmpInfo.msgCode = CbPage->pageHeader.serialNum.msgCode;
894 tmpInfo.updateNum = CbPage->pageHeader.serialNum.updateNum;
895 tmpInfo.msgId = CbPage->pageHeader.msgId;
896 tmpInfo.totalPages = CbPage->pageHeader.totalPages;
899 tmpInfo.totalSize = CbPage->pageLength;
901 pair<unsigned char, SMS_CBMSG_PAGE_S> newData(CbPage->pageHeader.page, *CbPage);
902 tmpInfo.data.insert(newData);
904 MSG_DEBUG("MSG DATA : %s", CbPage->pageData);
905 MSG_DEBUG("PAIR DATA [%d] : %s", newData.first, newData.second.pageData);
907 pageList.push_back(tmpInfo);
911 void SmsPluginCbMsgHandler::removeFromPageList(SMS_CBMSG_PAGE_S *CbPage)
915 for (index = 0; index < pageList.size(); index++) {
916 if (pageList[index].geoScope == CbPage->pageHeader.serialNum.geoScope && pageList[index].msgCode == CbPage->pageHeader.serialNum.msgCode) {
917 MSG_DEBUG("geoScope [%d], msgCode [%d]", pageList[index].geoScope, pageList[index].msgCode);
919 if (pageList[index].msgId == CbPage->pageHeader.msgId)
924 MSG_DEBUG("remove index [%d]", index);
926 pageList.erase(pageList.begin()+index);
930 void SmsPluginCbMsgHandler::decodeCbMsgDCS(unsigned char dcsData, const unsigned char *pMsgData, SMS_CBMSG_DCS_S* pDcs)
932 pDcs->codingGroup = SMS_CBMSG_CODGRP_GENERAL_DCS;
933 pDcs->classType = SMS_MSG_CLASS_NONE;
934 pDcs->bCompressed = false;
935 pDcs->codingScheme = SMS_CHARSET_7BIT;
936 pDcs->langType = SMS_CBMSG_LANG_UNSPECIFIED;
937 memset(pDcs->iso639Lang, 0x00, sizeof(pDcs->iso639Lang));
939 pDcs->rawData = dcsData;
941 unsigned char codingGrp = (dcsData & 0xF0) >> 4;
947 pDcs->codingGroup = SMS_CBMSG_CODGRP_GENERAL_DCS;
948 pDcs->langType = (SMS_CBMSG_LANG_TYPE_T)dcsData;
953 if (dcsData == 0x10 || dcsData == 0x11) {
954 pDcs->codingGroup = SMS_CBMSG_CODGRP_GENERAL_DCS;
955 pDcs->codingScheme = (dcsData & 0x01) ? SMS_CHARSET_UCS2 : SMS_CHARSET_7BIT;
956 pDcs->langType = SMS_CBMSG_LANG_ISO639;
957 MSG_DEBUG("codingScheme: [%d]", pDcs->codingScheme);
958 if (pMsgData[0] && pMsgData[1]) {
959 pDcs->iso639Lang[0] = pMsgData[0] & 0x7F;
960 pDcs->iso639Lang[1] = (pMsgData[0] & 0X80) >> 7;
961 pDcs->iso639Lang[1] |= (pMsgData[1] & 0X3F) << 1;
962 pDcs->iso639Lang[2] = 0x13; /* CR */
964 /* Default it to English if pMsgData is NULL */
965 pDcs->iso639Lang[0] = 0x45; /* E */
966 pDcs->iso639Lang[1] = 0x4E; /* N */
967 pDcs->iso639Lang[2] = 0x13; /* CR */
977 pDcs->codingGroup = SMS_CBMSG_CODGRP_GENERAL_DCS;
979 pDcs->bCompressed = (dcsData & 0x20) ? true : false;
982 pDcs->classType = (SMS_MSG_CLASS_T)(dcsData & 0x03);
984 unsigned char tmpScheme = (dcsData & 0x0C) >> 2;
988 pDcs->codingScheme = SMS_CHARSET_7BIT;
991 pDcs->codingScheme = SMS_CHARSET_8BIT;
994 pDcs->codingScheme = SMS_CHARSET_UCS2;
997 MSG_DEBUG("tmpScheme: [%d]", tmpScheme);
1005 pDcs->classType = (MSG_CLASS_TYPE_T)(dcsData & 0x03);
1006 pDcs->codingScheme = (SMS_CODING_SCHEME_T)((dcsData & 0x0C) >> 2);
1011 pDcs->codingGroup = SMS_CBMSG_CODGRP_WAP;
1016 pDcs->codingGroup = SMS_CBMSG_CODGRP_CLASS_CODING;
1017 pDcs->codingScheme = (dcsData & 0x04) ? SMS_CHARSET_8BIT : SMS_CHARSET_7BIT;
1018 pDcs->classType = (MSG_CLASS_TYPE_T)(dcsData & 0x03);
1022 MSG_DEBUG("codingGrp: [0x%x]", codingGrp);
1028 void SmsPluginCbMsgHandler::convertLangType(SMS_CBMSG_LANG_TYPE_T InType , MSG_CB_LANGUAGE_TYPE_T *pOutType)
1031 case SMS_CBMSG_LANG_GERMAN :
1032 *pOutType = MSG_CBLANG_TYPE_GER;
1035 case SMS_CBMSG_LANG_ENGLISH :
1036 *pOutType = MSG_CBLANG_TYPE_ENG;
1039 case SMS_CBMSG_LANG_ITALIAN :
1040 *pOutType = MSG_CBLANG_TYPE_ITA;
1043 case SMS_CBMSG_LANG_FRENCH :
1044 *pOutType = MSG_CBLANG_TYPE_FRE;
1047 case SMS_CBMSG_LANG_SPANISH :
1048 *pOutType = MSG_CBLANG_TYPE_SPA;
1051 case SMS_CBMSG_LANG_DUTCH :
1052 *pOutType = MSG_CBLANG_TYPE_NED;
1055 case SMS_CBMSG_LANG_SWEDISH :
1056 *pOutType = MSG_CBLANG_TYPE_SWE;
1059 case SMS_CBMSG_LANG_PORTUGUESE :
1060 *pOutType = MSG_CBLANG_TYPE_POR;
1063 case SMS_CBMSG_LANG_TURKISH :
1064 *pOutType = MSG_CBLANG_TYPE_TUR;
1068 *pOutType = MSG_CBLANG_TYPE_MAX;
1074 unsigned long SmsPluginCbMsgHandler::getRecvTime()
1078 recvTime = time(NULL);
1080 return (unsigned long)recvTime;
1084 void SmsPluginCbMsgHandler::getDisplayName(unsigned short MsgId, char *pDisplayName, msg_sim_slot_id_t simIndex)
1086 MSG_CB_CHANNEL_S cbChannelInfo = {0, };
1087 msg_error_t err = MSG_SUCCESS;
1088 MsgDbHandler *dbHandle = getDbHandle();
1090 err = MsgStoGetCBChannelInfo(dbHandle, &cbChannelInfo, simIndex);
1091 MSG_DEBUG("MsgStoGetCBChannelInfo [err = %d]", err);
1093 for (int i = 0; i < cbChannelInfo.channelCnt; i++) {
1094 if (MsgId >= cbChannelInfo.channelInfo[i].from && MsgId <= cbChannelInfo.channelInfo[i].to) {
1095 MSG_DEBUG("FIND MSG ID = [%d]", MsgId);
1097 char strTmp[CB_CHANNEL_NAME_MAX + 1];
1098 memset(strTmp, 0x00, sizeof(strTmp));
1100 strncpy(strTmp, cbChannelInfo.channelInfo[i].name, CB_CHANNEL_NAME_MAX);
1102 if (strlen(strTmp) > 0)
1103 snprintf(pDisplayName, sizeof(strTmp), "[%s]", strTmp);
1105 snprintf(pDisplayName, sizeof(unsigned short), "[%d]", MsgId);
1108 #ifdef MSG_NOTI_INTEGRATION
1109 snprintf(pDisplayName, MAX_ADDRESS_VAL_LEN + 1, "CB message");
1111 snprintf(pDisplayName, MAX_ADDRESS_VAL_LEN + 1, "[%d]", MsgId);
1119 snprintf(pDisplayName, MAX_ADDRESS_VAL_LEN + 1, "[%d]", MsgId);