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 bool is_duplicated = SmsPluginStorage::instance()->isDuplicatedCBMsg(&msgInfo);
142 if (is_duplicated == false) {
143 MSG_CB_MSG_S cbOutMsg = {0, };
145 /*cbOutMsg.type = MSG_CB_SMS; */
146 cbOutMsg.type = msgInfo.msgType.subType;
147 cbOutMsg.receivedTime = cbMsg->recvTime;
148 cbOutMsg.serialNum = cbMsg->serialNum;
149 cbOutMsg.messageId = cbMsg->msgId;
150 cbOutMsg.dcs = CbMsgPage.pageHeader.dcs.rawData;
151 memset (cbOutMsg.cbText, 0x00, sizeof(cbOutMsg.cbText));
153 cbOutMsg.cbTextLen = convertTextToUtf8((unsigned char*)cbOutMsg.cbText, sizeof(cbOutMsg.cbText), cbMsg);
154 memset(cbOutMsg.language_type, 0x00, sizeof(cbOutMsg.language_type));
155 memcpy(cbOutMsg.language_type, CbMsgPage.pageHeader.dcs.iso639Lang, 3);
156 err = SmsPluginEventHandler::instance()->callbackCBMsgIncoming(&cbOutMsg, &msgInfo);
157 if (err != MSG_SUCCESS)
158 MSG_WARN("callbackMsgIncoming() Error !! [%d]", err);
160 MSG_DEBUG("This cb message is duplicated");
163 MSG_WARN("checkMessage() Error !! [%d]", err);
167 /* insert message-id to internal CB message table */
168 SmsPluginStorage *storageHandler = SmsPluginStorage::instance();
169 err = storageHandler->insertReceivedCBMessage(CbMsgPage);
170 if (err != MSG_SUCCESS) {
171 MSG_DEBUG("insertReceivedCBMessage() Error !! [%d]", err);
174 /* Remove From List */
175 removeFromPageList(&CbMsgPage);
181 void SmsPluginCbMsgHandler::handleEtwsMsg(TapiHandle *handle, TelSmsEtwsMsg_t *pEtwsMsg)
184 msg_error_t err = MSG_SUCCESS;
185 TelSmsEtwsMsgType_t type = pEtwsMsg->EtwsMsgType;
186 SMS_ETWS_PRIMARY_S etwsPn = {0, };
187 MSG_CB_MSG_S cbOutMsg = {0, };
189 if (type != TAPI_NETTEXT_ETWS_PRIMARY) {
190 MSG_DEBUG("The Etws secondary Message");
191 handleCbMsg(handle, (TelSmsCbMsg_t *)pEtwsMsg);
194 DecodeEtwsMsg(pEtwsMsg, &etwsPn);
196 cbOutMsg.type = MSG_ETWS_SMS;
197 cbOutMsg.receivedTime = etwsPn.recvTime;
198 cbOutMsg.serialNum = encodeCbSerialNum(etwsPn.serialNum);
199 cbOutMsg.messageId = etwsPn.msgId;
200 cbOutMsg.etwsWarningType = etwsPn.warningType;
201 memcpy (cbOutMsg.etwsWarningSecurityInfo, etwsPn.warningSecurityInfo, sizeof(cbOutMsg.etwsWarningSecurityInfo));
203 err = SmsPluginEventHandler::instance()->callbackCBMsgIncoming(&cbOutMsg, NULL);
204 if (err != MSG_SUCCESS)
205 MSG_DEBUG("callbackMsgIncoming() Error !! [%d]", err);
211 void SmsPluginCbMsgHandler::Decode2gCbMsg(TelSmsCbMsg_t *pCbMsg, SMS_CBMSG_PAGE_S *pCbPage)
213 unsigned char cbData[pCbMsg->Length+1] = {0};
214 memcpy(cbData, pCbMsg->szMsgData, pCbMsg->Length);
215 cbData[pCbMsg->Length] = '\0';
218 MSG_INFO("Received CB length:%d", pCbMsg->Length);
219 char cbDataTmp[(pCbMsg->Length*2)+1];
220 memset(cbDataTmp, 0x00, sizeof(cbDataTmp));
222 for (int i = 0; i < pCbMsg->Length; i++) {
223 snprintf(cbDataTmp+(i*2), sizeof(cbDataTmp)-(i*2), "%02X", cbData[i]);
225 MSG_INFO("[%s]", cbDataTmp);
227 pCbPage->cbMsgType = SMS_CBMSG_TYPE_CBS;
230 pCbPage->pageHeader.serialNum.geoScope = (cbData[0] & 0xC0) >> 6;
232 pCbPage->pageHeader.serialNum.msgCode = (cbData[0] & 0x3F) << 4;
233 pCbPage->pageHeader.serialNum.msgCode |= (cbData[1] & 0xF0) >> 4;
235 pCbPage->pageHeader.serialNum.updateNum = cbData[1] & 0x0F;
237 MSG_DEBUG("geoScope : [%d], msgCode : [%d], updateNum : [%d]", pCbPage->pageHeader.serialNum.geoScope, pCbPage->pageHeader.serialNum.msgCode, pCbPage->pageHeader.serialNum.updateNum);
239 pCbPage->pageHeader.msgId = (cbData[2] << 8) | cbData[3];
241 MSG_DEBUG("MSG ID : [%d]", pCbPage->pageHeader.msgId);
244 decodeCbMsgDCS(cbData[4], (unsigned char*)cbData + 6, &(pCbPage->pageHeader.dcs));
247 pCbPage->pageHeader.totalPages = cbData[5] & 0x0F;
248 pCbPage->pageHeader.page = (cbData[5] & 0xF0) >> 4;
250 if (pCbPage->pageHeader.totalPages > MAX_CBMSG_PAGE_NUM)
251 THROW(MsgException::SMS_PLG_ERROR, "CB Page Count is over MAX[%d]", pCbPage->pageHeader.totalPages);
253 MSG_DEBUG("Total Page : [%d], Page : [%d]", pCbPage->pageHeader.totalPages, pCbPage->pageHeader.page);
255 /* Convert Language Type */
256 convertLangType(pCbPage->pageHeader.dcs.langType, &(pCbPage->pageHeader.langType));
258 MSG_DEBUG("In Language Type : [%d], Out Language Type : [%d]", pCbPage->pageHeader.dcs.langType, pCbPage->pageHeader.langType);
259 MSG_DEBUG("iso639Lang : [%s]", pCbPage->pageHeader.dcs.iso639Lang);
260 /* Get Receive Time */
261 pCbPage->pageHeader.recvTime = getRecvTime();
264 int dataLen = pCbMsg->Length - 6;
266 MSG_DEBUG("codingScheme:[%d]", pCbPage->pageHeader.dcs.codingScheme);
268 switch (pCbPage->pageHeader.dcs.codingScheme) {
269 case SMS_CHARSET_7BIT: {
270 MSG_DEBUG("GSM 7 BIT");
272 dataLen = (dataLen*8) / 7;
274 SmsPluginUDCodec udCodec;
275 char pageData[MAX_CBMSG_PAGE_SIZE*8/7] = {0};
276 int unpackLen = udCodec.unpack7bitChar(&cbData[6], dataLen, 0, pageData);
278 if (pCbPage->pageHeader.dcs.iso639Lang[0]) {
279 unpackLen = unpackLen - 3;
281 memcpy(pCbPage->pageData, &pageData[3], unpackLen);
285 memcpy(pCbPage->pageData, &pageData, unpackLen);
288 MSG_DEBUG("unpackLen : [%d]", unpackLen);
290 pCbPage->pageLength = unpackLen;
291 pCbPage->pageData[unpackLen] = '\0';
295 case SMS_CHARSET_8BIT:
296 case SMS_CHARSET_UCS2: {
297 MSG_DEBUG("UCS2 or 8BIT");
299 if (pCbPage->pageHeader.dcs.iso639Lang[0]) {
300 memcpy(pCbPage->pageData, &cbData[8], dataLen - 2);
301 pCbPage->pageLength = dataLen - 2;
303 memcpy(pCbPage->pageData, &cbData[6], dataLen);
304 pCbPage->pageLength = dataLen;
310 MSG_DEBUG("Page Length : [%d], Page Data : [%s]", pCbPage->pageLength, pCbPage->pageData);
314 void SmsPluginCbMsgHandler::DecodeEtwsMsg(TelSmsEtwsMsg_t *pEtwsMsg, SMS_ETWS_PRIMARY_S *pEtwsPn)
316 if ( !pEtwsMsg || !pEtwsPn )
319 if (pEtwsMsg->Length > MAX_ETWS_SIZE)
320 THROW(MsgException::SMS_PLG_ERROR, "ETWS Msg Size is over MAX [%d]", pEtwsMsg->Length);
322 unsigned char EtwsData[pEtwsMsg->Length+1];
324 memset(EtwsData, 0x00, sizeof(EtwsData));
325 memcpy(EtwsData, pEtwsMsg->szMsgData, pEtwsMsg->Length);
326 EtwsData[pEtwsMsg->Length] = '\0';
328 /* print received msg data */
329 MSG_INFO("Received Etws length:%d", pEtwsMsg->Length);
330 char EtwsDataTmp[(pEtwsMsg->Length*2)+1];
331 memset(EtwsDataTmp, 0x00, sizeof(EtwsDataTmp));
333 for (int i = 0; i < pEtwsMsg->Length; i++) {
334 snprintf(EtwsDataTmp+(i*2), sizeof(EtwsDataTmp)-(i*2), "%02X", EtwsData[i]);
336 MSG_INFO("[%s]", EtwsDataTmp);
339 pEtwsPn->recvTime = getRecvTime();
342 pEtwsPn->serialNum.geoScope = (EtwsData[0] & 0xC0) >> 6;
343 pEtwsPn->serialNum.msgCode = (EtwsData[0] & 0x3F) << 4;
344 pEtwsPn->serialNum.msgCode |= (EtwsData[1] & 0xF0) >> 4;
345 pEtwsPn->serialNum.updateNum = EtwsData[1] & 0x0F;
347 MSG_DEBUG("geoScope : [%d], msgCode : [%d], updateNum : [%d]", pEtwsPn->serialNum.geoScope, pEtwsPn->serialNum.msgCode, pEtwsPn->serialNum.updateNum);
349 /* Message Identifier */
350 pEtwsPn->msgId = (EtwsData[2] << 8) | EtwsData[3];
351 MSG_DEBUG("MSG ID : [%d]", pEtwsPn->msgId);
354 pEtwsPn->warningType = (EtwsData[4] << 8) | EtwsData[5];
355 MSG_DEBUG("warningType : [0x%04x]", pEtwsPn->msgId);
357 /* warning security information */
358 memcpy(pEtwsPn->warningSecurityInfo, &EtwsData[6], sizeof(pEtwsPn->warningSecurityInfo)); /* 50bytes */
359 for (unsigned int i = 0; i < sizeof(pEtwsPn->warningSecurityInfo); i++) {
360 MSG_DEBUG("warning secu info [%02x]", pEtwsPn->warningSecurityInfo[i]);
364 void SmsPluginCbMsgHandler::Decode3gCbMsg(TelSmsCbMsg_t *pCbMsg, SMS_CBMSG_PAGE_S *pCbPage)
366 unsigned char cbData[MAX_CBMSG_TOTAL_PAGE_SIZE + 1] = {0};
367 memcpy(cbData, pCbMsg->szMsgData, pCbMsg->Length);
368 cbData[pCbMsg->Length] = '\0';
371 MSG_INFO("Received CB length:%d", pCbMsg->Length);
372 char cbDataTmp[(pCbMsg->Length*2)+1];
373 memset(cbDataTmp, 0x00, sizeof(cbDataTmp));
375 for (int i = 0; i < pCbMsg->Length; i++) {
376 snprintf(cbDataTmp+(i*2), sizeof(cbDataTmp)-(i*2), "%02X", cbData[i]);
378 MSG_INFO("[%s]", cbDataTmp);
380 pCbPage->cbMsgType = (SMS_CBMSG_TYPE_T)cbData[0];
382 pCbPage->pageHeader.msgId = (cbData[1] << 8) | cbData[2];
384 MSG_DEBUG("MSG ID : [%d]", pCbPage->pageHeader.msgId);
387 pCbPage->pageHeader.serialNum.geoScope = (cbData[3] & 0xC0) >> 6;
389 pCbPage->pageHeader.serialNum.msgCode = (cbData[3] & 0x3F) << 4;
390 pCbPage->pageHeader.serialNum.msgCode |= (cbData[4] & 0xF0) >> 4;
392 pCbPage->pageHeader.serialNum.updateNum = cbData[4] & 0x0F;
394 MSG_DEBUG("geoScope : [%d], msgCode : [%d], updateNum : [%d]", pCbPage->pageHeader.serialNum.geoScope, pCbPage->pageHeader.serialNum.msgCode, pCbPage->pageHeader.serialNum.updateNum);
397 decodeCbMsgDCS(cbData[5], (unsigned char*)cbData + 6, &(pCbPage->pageHeader.dcs));
399 /* Convert Language Type */
400 convertLangType(pCbPage->pageHeader.dcs.langType, &(pCbPage->pageHeader.langType));
402 MSG_DEBUG("In Language Type : [%d], Out Language Type : [%d]", pCbPage->pageHeader.dcs.langType, pCbPage->pageHeader.langType);
404 /* Get Receive Time */
405 pCbPage->pageHeader.recvTime = getRecvTime();
406 pCbPage->pageHeader.totalPages = cbData[6];
412 switch (pCbPage->pageHeader.dcs.codingScheme) {
413 case SMS_CHARSET_7BIT: {
414 for (int i = 0; i < pCbPage->pageHeader.totalPages; ++i) {
415 unsigned char cbMessage[MAX_CBMSG_PAGE_SIZE] = {0};
416 dataLen = cbData[7 + (i + 1) * MAX_CBMSG_PAGE_SIZE + i];
418 if (dataLen > MAX_CBMSG_PAGE_SIZE)
419 THROW(MsgException::SMS_PLG_ERROR, "CB Msg Size is over MAX [%d]", dataLen);
421 memcpy(cbMessage, &cbData[7+(i*MAX_CBMSG_PAGE_SIZE)+ i], dataLen);
422 dataLen = (dataLen*8) / 7;
424 SmsPluginUDCodec udCodec;
425 int unpackLen = udCodec.unpack7bitChar((const unsigned char *)cbMessage, dataLen, 0, pCbPage->pageData + offset);
428 pCbPage->pageLength = offset;
432 case SMS_CHARSET_8BIT:
433 case SMS_CHARSET_UCS2: {
435 char cbMessage[MAX_CBMSG_PAGE_SIZE]= {0, };
437 for (int i = 0; i < pCbPage->pageHeader.totalPages; ++i) {
438 dataLen = cbData[7+(i+1)*MAX_CBMSG_PAGE_SIZE + i];
439 memcpy(cbMessage + offset, &cbData[7+(i*MAX_CBMSG_PAGE_SIZE)+ i], dataLen);
444 if (pCbPage->pageHeader.dcs.iso639Lang[0]) {
445 int tmpDataLen = (dataLen > 2)?(dataLen - 2):0;
446 memcpy(pCbPage->pageData, cbMessage + 2, tmpDataLen);
447 pCbPage->pageLength = tmpDataLen;
449 memcpy(pCbPage->pageData, cbMessage, dataLen);
450 pCbPage->pageLength = dataLen;
453 char cbMessage[MAX_CBMSG_PAGE_SIZE*MAX_CBMSG_PAGE_NUM+1] = {0, };
455 for (int i = 0; i < pCbPage->pageHeader.totalPages; ++i) {
456 if (pCbPage->pageHeader.dcs.iso639Lang[0]) {
457 dataLen = cbData[7+(i+1)*MAX_CBMSG_PAGE_SIZE + i] - 2;
459 memcpy(cbMessage + offset, &cbData[7+(i*MAX_CBMSG_PAGE_SIZE)+ i + 2], dataLen);
463 dataLen = cbData[7+(i+1)*MAX_CBMSG_PAGE_SIZE + i];
465 memcpy(cbMessage + offset, &cbData[7+(i*MAX_CBMSG_PAGE_SIZE)+ i], dataLen);
471 memcpy(pCbPage->pageData, cbMessage, dataLen);
472 pCbPage->pageLength = dataLen;
477 pCbPage->pageHeader.totalPages = 1;
479 MSG_DEBUG("Page Length : [%d], Page Data : [%s]", pCbPage->pageLength, pCbPage->pageData);
482 unsigned short SmsPluginCbMsgHandler::encodeCbSerialNum(SMS_CBMSG_SERIAL_NUM_S snFields)
484 unsigned short serialNum = 0;
486 serialNum = ((snFields.geoScope & 0x03) << 14) | ((snFields.msgCode&0x03FF) << 4) | (snFields.updateNum&0x0F);
487 MSG_DEBUG("serialNum (%x), geo(%x), mc(%x), un(%x)\n", serialNum, snFields.geoScope, snFields.msgCode, snFields.updateNum);
492 int SmsPluginCbMsgHandler::CMAS_class(unsigned short message_id)
496 switch (message_id) {
499 ret = MSG_CMAS_PRESIDENTIAL;
505 ret = MSG_CMAS_EXTREME;
519 ret = MSG_CMAS_SEVERE;
523 ret = MSG_CMAS_AMBER;
531 ret = MSG_CMAS_EXERCISE;
535 ret = MSG_CMAS_OPERATOR_DEFINED;
544 bool SmsPluginCbMsgHandler::checkCbOpt(SMS_CBMSG_PAGE_S *CbPage, bool *pJavaMsg, msg_sim_slot_id_t simIndex)
546 bool bReceive = false;
547 char keyName[MAX_VCONFKEY_NAME_LEN];
548 memset(keyName, 0x00, sizeof(keyName));
549 snprintf(keyName, sizeof(keyName), "%s/%d", CB_RECEIVE, simIndex);
550 if (MsgSettingGetBool(keyName, &bReceive) != MSG_SUCCESS)
551 MSG_INFO("MsgSettingGetBool() is failed");
553 /* Receive CB Msg = FALSE */
555 MSG_DEBUG("RECEIVE CB = FALSE");
562 memset(keyName, 0x00, sizeof(keyName));
563 snprintf(keyName, sizeof(keyname), "%s/%d", CB_LANGUAGE, MSG_CBLANG_TYPE_ALL);
565 bool bAllLang = false;
566 if (MsgSettingGetBool(keyName, &bAllLang) != MSG_SUCCESS)
567 MSG_INFO("MsgSettingGetBool() is failed");
570 MSG_DEBUG("ALL LANGUAGE = FALSE");
572 memset(keyName, 0x00, sizeof(keyName));
573 snprintf(keyName, sizeof(keyname), "%s/%d", CB_LANGUAGE, CbPage.pageHeader.langType);
577 if (MsgSettingGetBool(keyName, &bLang) != MSG_SUCCESS)
578 MSG_INFO("MsgSettingGetBool() is failed");
580 if (!bLang || CbPage.pageHeader.langType == MSG_CBLANG_TYPE_MAX) {
581 MSG_DEBUG("LANGUAGE [%d] = FALSE", CbPage.pageHeader.langType);
587 bool bActivate = false;
588 int MsgId_from = 0, MsgId_to = 0;
589 MSG_CB_CHANNEL_S cbChannelInfo = {0, };
590 msg_error_t err = MSG_SUCCESS;
591 MsgDbHandler *dbHandle = getDbHandle();
593 err = MsgStoGetCBChannelInfo(dbHandle, &cbChannelInfo, simIndex);
594 if (err != MSG_SUCCESS)
595 MSG_ERR("Error value of MsgStoGetCBChannelInfo [%d]", err);
597 for (int i = 0; i < cbChannelInfo.channelCnt; i++) {
598 bActivate = cbChannelInfo.channelInfo[i].bActivate;
599 MsgId_from = cbChannelInfo.channelInfo[i].from;
600 MsgId_to = cbChannelInfo.channelInfo[i].to;
602 if (bActivate == true && CbPage->pageHeader.msgId >= MsgId_from && CbPage->pageHeader.msgId <= MsgId_to) {
603 MSG_DEBUG("FIND CHANNEL = [%d]", CbPage->pageHeader.msgId);
611 unsigned char SmsPluginCbMsgHandler::checkCbPage(SMS_CBMSG_PAGE_S *CbPage)
613 unsigned char currPageCnt = 0;
618 msg_error_t err = MSG_SUCCESS;
620 SmsPluginStorage *storageHandler = SmsPluginStorage::instance();
621 err = storageHandler->isReceivedCBMessage(CbPage);
623 /* check existing message with cb internal table; */
624 if (err != MSG_ERR_DB_NORECORD) {
625 MSG_DEBUG("already received message: [%d]", CbPage.pageHeader.msgId);
630 if (CbPage->pageHeader.totalPages > 0) {
631 for (unsigned int i = 0; i < pageList.size(); i++) {
632 if (pageList[i].geoScope == CbPage->pageHeader.serialNum.geoScope && pageList[i].msgCode == CbPage->pageHeader.serialNum.msgCode) {
633 MSG_DEBUG("geoScope [%d], msgCode [%d]", pageList[i].geoScope, pageList[i].msgCode);
635 if (pageList[i].msgId == CbPage->pageHeader.msgId) {
636 int updateNum = CbPage->pageHeader.serialNum.updateNum - pageList[i].updateNum;
638 if (updateNum > 0) { /* New Message Content */
640 } else if (updateNum == 0) { /* Same Message Content */
641 if (pageList[i].data.count(CbPage->pageHeader.page) != 0) {
642 MSG_DEBUG("The Page Number already exists [%d]", CbPage->pageHeader.page);
646 pair<unsigned char, SMS_CBMSG_PAGE_S> newData(CbPage->pageHeader.page, *CbPage);
647 pageList[i].data.insert(newData);
649 MSG_DEBUG("PAGE DATA : %s", CbPage->pageData);
650 MSG_DEBUG("PAIR DATA [%d] : %s", newData.first, newData.second.pageData);
652 pageList[i].pageCnt++;
653 pageList[i].totalSize += CbPage->pageLength;
655 currPageCnt = pageList[i].pageCnt;
660 } else { /* Old Message Content */
668 if (bFind == false || CbPage->pageHeader.totalPages == 1) {
669 addToPageList(CbPage);
677 void SmsPluginCbMsgHandler::MakeCbMsg(SMS_CBMSG_PAGE_S *CbPage, SMS_CBMSG_S *pCbMsg)
679 pCbMsg->cbMsgType = CbPage->cbMsgType;
680 pCbMsg->msgId = CbPage->pageHeader.msgId;
681 pCbMsg->classType = CbPage->pageHeader.dcs.classType;
682 pCbMsg->codingScheme = CbPage->pageHeader.dcs.codingScheme;
683 pCbMsg->recvTime = CbPage->pageHeader.recvTime;
684 pCbMsg->serialNum = encodeCbSerialNum(CbPage->pageHeader.serialNum);
686 cbPageMap::iterator it;
689 for (unsigned int i = 0; i < pageList.size(); i++) {
690 if (pageList[i].geoScope == CbPage->pageHeader.serialNum.geoScope && pageList[i].msgCode == CbPage->pageHeader.serialNum.msgCode) {
691 MSG_DEBUG("geoScope [%d], msgCode [%d]", pageList[i].geoScope, pageList[i].msgCode);
693 if (pageList[i].msgId == CbPage->pageHeader.msgId) {
694 for (it = pageList[i].data.begin(); it != pageList[i].data.end(); it++) {
695 memcpy(pCbMsg->msgData + offset, it->second.pageData, it->second.pageLength);
696 pCbMsg->msgLength += it->second.pageLength;
697 offset = pCbMsg->msgLength;
704 pCbMsg->msgLength = tmpStr.size();
706 memcpy(pCbMsg->msgData, tmpStr.c_str(), tmpStr.size());
707 pCbMsg->msgData[tmpStr.size()] = '\0';
709 MSG_DEBUG("SIZE : [%d] TOTAL MSG : %s", tmpStr.size(), tmpStr.c_str());
714 void SmsPluginCbMsgHandler::convertCbMsgToMsginfo(SMS_CBMSG_S *pCbMsg, MSG_MESSAGE_INFO_S *pMsgInfo, msg_sim_slot_id_t simIndex)
716 pMsgInfo->msgId = (msg_message_id_t)pCbMsg->msgId;
717 pMsgInfo->serialNum = pCbMsg->serialNum;
719 pMsgInfo->folderId = MSG_CBMSGBOX_ID;
721 /* Convert Type values */
722 pMsgInfo->msgType.mainType = MSG_SMS_TYPE;
724 if (pCbMsg->cbMsgType == SMS_CBMSG_TYPE_CBS) {
725 int cmas_class = CMAS_class(pCbMsg->msgId);
728 pMsgInfo->msgType.subType = MSG_CB_SMS;
730 pMsgInfo->msgType.subType = (MSG_SUB_TYPE_T)cmas_class;
731 } else if (pCbMsg->cbMsgType == SMS_CBMSG_TYPE_JAVACBS) {
732 pMsgInfo->msgType.subType = MSG_JAVACB_SMS;
735 switch (pCbMsg->classType) {
736 case SMS_MSG_CLASS_0:
737 pMsgInfo->msgType.classType = MSG_CLASS_0;
739 case SMS_MSG_CLASS_1:
740 pMsgInfo->msgType.classType = MSG_CLASS_1;
742 case SMS_MSG_CLASS_2:
743 pMsgInfo->msgType.classType = MSG_CLASS_2;
745 case SMS_MSG_CLASS_3:
746 pMsgInfo->msgType.classType = MSG_CLASS_3;
749 pMsgInfo->msgType.classType = MSG_CLASS_NONE;
753 pMsgInfo->storageId = MSG_STORAGE_PHONE;
754 pMsgInfo->networkStatus = MSG_NETWORK_RECEIVED;
755 pMsgInfo->bRead = false;
756 pMsgInfo->bProtected = false;
757 pMsgInfo->priority = MSG_MESSAGE_PRIORITY_NORMAL;
758 pMsgInfo->direction = MSG_DIRECTION_TYPE_MT;
761 pMsgInfo->nAddressCnt = 1;
763 pMsgInfo->addressList = (MSG_ADDRESS_INFO_S *)new char[sizeof(MSG_ADDRESS_INFO_S)];
764 memset(pMsgInfo->addressList, 0x00, sizeof(MSG_ADDRESS_INFO_S));
766 pMsgInfo->addressList[0].addressType = MSG_ADDRESS_TYPE_UNKNOWN;
767 pMsgInfo->addressList[0].recipientType = MSG_RECIPIENTS_TYPE_UNKNOWN;
768 pMsgInfo->sim_idx = simIndex;
770 /* TODO :: MSG ID should be used to get CB message type */
771 getDisplayName(pCbMsg->msgId, pMsgInfo->addressList[0].addressVal, simIndex);
772 MSG_SEC_DEBUG("%s", pMsgInfo->addressList[0].addressVal);
775 pMsgInfo->msgPort.valid = false;
776 pMsgInfo->msgPort.dstPort = 0;
777 pMsgInfo->msgPort.srcPort = 0;
779 pMsgInfo->displayTime = pCbMsg->recvTime;
780 MSG_DEBUG("recvTime is %d", pMsgInfo->displayTime);
782 int bufSize = pCbMsg->msgLength*2;
784 char tmpBuf[bufSize];
785 memset(tmpBuf, 0x00, sizeof(tmpBuf));
787 while (pCbMsg->msgLength > 0) {
788 if (pCbMsg->msgData[pCbMsg->msgLength-1] == ' ' ||
789 pCbMsg->msgData[pCbMsg->msgLength-1] == '\r' ||
790 pCbMsg->msgData[pCbMsg->msgLength-1] == '\n') {
796 pCbMsg->msgData[pCbMsg->msgLength] = '\0';
798 MSG_DEBUG("LENGTH %d CB MSG %s", pCbMsg->msgLength, pCbMsg->msgData);
800 /* Convert Data values */
801 pMsgInfo->dataSize = convertTextToUtf8((unsigned char*)tmpBuf, bufSize, pCbMsg);
803 if (pMsgInfo->dataSize > MAX_MSG_TEXT_LEN) {
804 pMsgInfo->bTextSms = false;
806 /* Save Message Data into File */
807 char fileName[MSG_FILENAME_LEN_MAX+1];
808 memset(fileName, 0x00, sizeof(fileName));
810 if (MsgCreateFileName(fileName) == false)
811 THROW(MsgException::FILE_ERROR, "MsgCreateFileName error");
813 MSG_SEC_DEBUG("Save Message Data into file : size[%d] name[%s]\n", pMsgInfo->dataSize, fileName);
814 if (MsgWriteIpcFile(fileName, tmpBuf, pMsgInfo->dataSize) == false)
815 THROW(MsgException::FILE_ERROR, "MsgWriteIpcFile error");
817 strncpy(pMsgInfo->msgData, fileName, MAX_MSG_DATA_LEN);
819 pMsgInfo->bTextSms = true;
821 memset(pMsgInfo->msgText, 0x00, sizeof(pMsgInfo->msgText));
822 memcpy(pMsgInfo->msgText, tmpBuf, pMsgInfo->dataSize);
823 pMsgInfo->dataSize = strlen(pMsgInfo->msgText);
824 MSG_SEC_DEBUG("CB MSG %s", pMsgInfo->msgText);
829 void SmsPluginCbMsgHandler::convertEtwsMsgToMsginfo(SMS_CBMSG_PAGE_S *EtwsMsg, MSG_MESSAGE_INFO_S *pMsgInfo, msg_sim_slot_id_t simIndex)
831 pMsgInfo->msgId = (msg_message_id_t)EtwsMsg->pageHeader.msgId;
833 pMsgInfo->folderId = MSG_CBMSGBOX_ID;
835 /* Convert Type values */
836 pMsgInfo->msgType.mainType = MSG_SMS_TYPE;
838 if (EtwsMsg->cbMsgType == SMS_CBMSG_TYPE_ETWS)
839 pMsgInfo->msgType.subType = MSG_ETWS_SMS;
841 pMsgInfo->storageId = MSG_STORAGE_PHONE;
842 pMsgInfo->networkStatus = MSG_NETWORK_RECEIVED;
843 pMsgInfo->bRead = false;
844 pMsgInfo->bProtected = false;
845 pMsgInfo->priority = MSG_MESSAGE_PRIORITY_NORMAL;
846 pMsgInfo->direction = MSG_DIRECTION_TYPE_MT;
849 pMsgInfo->nAddressCnt = 1;
851 pMsgInfo->addressList[0].addressType = MSG_ADDRESS_TYPE_UNKNOWN;
852 pMsgInfo->addressList[0].recipientType = MSG_RECIPIENTS_TYPE_UNKNOWN;
854 getDisplayName(EtwsMsg->pageHeader.msgId, pMsgInfo->addressList[0].addressVal, simIndex);
855 MSG_SEC_DEBUG("%s", pMsgInfo->addressList[0].addressVal);
857 pMsgInfo->msgPort.valid = false;
858 pMsgInfo->msgPort.dstPort = 0;
859 pMsgInfo->msgPort.srcPort = 0;
861 pMsgInfo->displayTime = EtwsMsg->pageHeader.recvTime;
862 MSG_DEBUG("recvTime is %d", pMsgInfo->displayTime);
863 MSG_DEBUG("LENGTH %d", EtwsMsg->pageLength);
864 pMsgInfo->bTextSms = true;
865 pMsgInfo->dataSize = EtwsMsg->pageLength;
866 memset(pMsgInfo->msgData, 0x00, sizeof(pMsgInfo->msgData));
867 memcpy(pMsgInfo->msgData, EtwsMsg->pageData, pMsgInfo->dataSize);
870 int SmsPluginCbMsgHandler::convertTextToUtf8(unsigned char* outBuf, int outBufSize, SMS_CBMSG_S* pCbMsg)
872 int convertedTextSize = 0;
873 MSG_LANG_INFO_S langInfo = {0, };
875 MsgTextConvert *textCvt = MsgTextConvert::instance();
877 if (!outBuf || !pCbMsg) {
878 MSG_DEBUG("invalid param.\n");
882 langInfo.bSingleShift = false;
883 langInfo.bLockingShift = false;
886 /* Convert Data values */
887 if (pCbMsg->codingScheme == SMS_CHARSET_7BIT)
888 convertedTextSize = textCvt->convertGSM7bitToUTF8(outBuf, outBufSize, (unsigned char*)pCbMsg->msgData, pCbMsg->msgLength, &langInfo);
889 else if (pCbMsg->codingScheme == SMS_CHARSET_UCS2)
890 convertedTextSize = textCvt->convertUCS2ToUTF8(outBuf, outBufSize, (unsigned char*)pCbMsg->msgData, pCbMsg->msgLength);
892 return convertedTextSize;
895 void SmsPluginCbMsgHandler::addToPageList(SMS_CBMSG_PAGE_S *CbPage)
897 CB_PAGE_INFO_S tmpInfo;
899 tmpInfo.geoScope = CbPage->pageHeader.serialNum.geoScope;
900 tmpInfo.msgCode = CbPage->pageHeader.serialNum.msgCode;
901 tmpInfo.updateNum = CbPage->pageHeader.serialNum.updateNum;
902 tmpInfo.msgId = CbPage->pageHeader.msgId;
903 tmpInfo.totalPages = CbPage->pageHeader.totalPages;
906 tmpInfo.totalSize = CbPage->pageLength;
908 pair<unsigned char, SMS_CBMSG_PAGE_S> newData(CbPage->pageHeader.page, *CbPage);
909 tmpInfo.data.insert(newData);
911 MSG_DEBUG("MSG DATA : %s", CbPage->pageData);
912 MSG_DEBUG("PAIR DATA [%d] : %s", newData.first, newData.second.pageData);
914 pageList.push_back(tmpInfo);
918 void SmsPluginCbMsgHandler::removeFromPageList(SMS_CBMSG_PAGE_S *CbPage)
922 for (index = 0; index < pageList.size(); index++) {
923 if (pageList[index].geoScope == CbPage->pageHeader.serialNum.geoScope && pageList[index].msgCode == CbPage->pageHeader.serialNum.msgCode) {
924 MSG_DEBUG("geoScope [%d], msgCode [%d]", pageList[index].geoScope, pageList[index].msgCode);
926 if (pageList[index].msgId == CbPage->pageHeader.msgId)
931 MSG_DEBUG("remove index [%d]", index);
933 pageList.erase(pageList.begin()+index);
937 void SmsPluginCbMsgHandler::decodeCbMsgDCS(unsigned char dcsData, const unsigned char *pMsgData, SMS_CBMSG_DCS_S* pDcs)
939 pDcs->codingGroup = SMS_CBMSG_CODGRP_GENERAL_DCS;
940 pDcs->classType = SMS_MSG_CLASS_NONE;
941 pDcs->bCompressed = false;
942 pDcs->codingScheme = SMS_CHARSET_7BIT;
943 pDcs->langType = SMS_CBMSG_LANG_UNSPECIFIED;
944 memset(pDcs->iso639Lang, 0x00, sizeof(pDcs->iso639Lang));
946 pDcs->rawData = dcsData;
948 unsigned char codingGrp = (dcsData & 0xF0) >> 4;
954 pDcs->codingGroup = SMS_CBMSG_CODGRP_GENERAL_DCS;
955 pDcs->langType = (SMS_CBMSG_LANG_TYPE_T)dcsData;
960 if (dcsData == 0x10 || dcsData == 0x11) {
961 pDcs->codingGroup = SMS_CBMSG_CODGRP_GENERAL_DCS;
962 pDcs->codingScheme = (dcsData & 0x01) ? SMS_CHARSET_UCS2 : SMS_CHARSET_7BIT;
963 pDcs->langType = SMS_CBMSG_LANG_ISO639;
964 MSG_DEBUG("codingScheme: [%d]", pDcs->codingScheme);
965 if (pMsgData[0] && pMsgData[1]) {
966 pDcs->iso639Lang[0] = pMsgData[0] & 0x7F;
967 pDcs->iso639Lang[1] = (pMsgData[0] & 0X80) >> 7;
968 pDcs->iso639Lang[1] |= (pMsgData[1] & 0X3F) << 1;
969 pDcs->iso639Lang[2] = 0x13; /* CR */
971 /* Default it to English if pMsgData is NULL */
972 pDcs->iso639Lang[0] = 0x45; /* E */
973 pDcs->iso639Lang[1] = 0x4E; /* N */
974 pDcs->iso639Lang[2] = 0x13; /* CR */
984 pDcs->codingGroup = SMS_CBMSG_CODGRP_GENERAL_DCS;
986 pDcs->bCompressed = (dcsData & 0x20) ? true : false;
989 pDcs->classType = (SMS_MSG_CLASS_T)(dcsData & 0x03);
991 unsigned char tmpScheme = (dcsData & 0x0C) >> 2;
995 pDcs->codingScheme = SMS_CHARSET_7BIT;
998 pDcs->codingScheme = SMS_CHARSET_8BIT;
1001 pDcs->codingScheme = SMS_CHARSET_UCS2;
1004 MSG_DEBUG("tmpScheme: [%d]", tmpScheme);
1012 pDcs->classType = (MSG_CLASS_TYPE_T)(dcsData & 0x03);
1013 pDcs->codingScheme = (SMS_CODING_SCHEME_T)((dcsData & 0x0C) >> 2);
1018 pDcs->codingGroup = SMS_CBMSG_CODGRP_WAP;
1023 pDcs->codingGroup = SMS_CBMSG_CODGRP_CLASS_CODING;
1024 pDcs->codingScheme = (dcsData & 0x04) ? SMS_CHARSET_8BIT : SMS_CHARSET_7BIT;
1025 pDcs->classType = (MSG_CLASS_TYPE_T)(dcsData & 0x03);
1029 MSG_DEBUG("codingGrp: [0x%x]", codingGrp);
1035 void SmsPluginCbMsgHandler::convertLangType(SMS_CBMSG_LANG_TYPE_T InType , MSG_CB_LANGUAGE_TYPE_T *pOutType)
1038 case SMS_CBMSG_LANG_GERMAN :
1039 *pOutType = MSG_CBLANG_TYPE_GER;
1042 case SMS_CBMSG_LANG_ENGLISH :
1043 *pOutType = MSG_CBLANG_TYPE_ENG;
1046 case SMS_CBMSG_LANG_ITALIAN :
1047 *pOutType = MSG_CBLANG_TYPE_ITA;
1050 case SMS_CBMSG_LANG_FRENCH :
1051 *pOutType = MSG_CBLANG_TYPE_FRE;
1054 case SMS_CBMSG_LANG_SPANISH :
1055 *pOutType = MSG_CBLANG_TYPE_SPA;
1058 case SMS_CBMSG_LANG_DUTCH :
1059 *pOutType = MSG_CBLANG_TYPE_NED;
1062 case SMS_CBMSG_LANG_SWEDISH :
1063 *pOutType = MSG_CBLANG_TYPE_SWE;
1066 case SMS_CBMSG_LANG_PORTUGUESE :
1067 *pOutType = MSG_CBLANG_TYPE_POR;
1070 case SMS_CBMSG_LANG_TURKISH :
1071 *pOutType = MSG_CBLANG_TYPE_TUR;
1075 *pOutType = MSG_CBLANG_TYPE_MAX;
1081 unsigned long SmsPluginCbMsgHandler::getRecvTime()
1085 recvTime = time(NULL);
1087 return (unsigned long)recvTime;
1091 void SmsPluginCbMsgHandler::getDisplayName(unsigned short MsgId, char *pDisplayName, msg_sim_slot_id_t simIndex)
1093 MSG_CB_CHANNEL_S cbChannelInfo = {0, };
1094 msg_error_t err = MSG_SUCCESS;
1095 MsgDbHandler *dbHandle = getDbHandle();
1097 err = MsgStoGetCBChannelInfo(dbHandle, &cbChannelInfo, simIndex);
1098 MSG_DEBUG("MsgStoGetCBChannelInfo [err = %d]", err);
1100 for (int i = 0; i < cbChannelInfo.channelCnt; i++) {
1101 if (MsgId >= cbChannelInfo.channelInfo[i].from && MsgId <= cbChannelInfo.channelInfo[i].to) {
1102 MSG_DEBUG("FIND MSG ID = [%d]", MsgId);
1104 char strTmp[CB_CHANNEL_NAME_MAX + 1];
1105 memset(strTmp, 0x00, sizeof(strTmp));
1107 strncpy(strTmp, cbChannelInfo.channelInfo[i].name, CB_CHANNEL_NAME_MAX);
1109 if (strlen(strTmp) > 0)
1110 snprintf(pDisplayName, sizeof(strTmp), "[%s]", strTmp);
1112 snprintf(pDisplayName, sizeof(unsigned short), "[%d]", MsgId);
1115 #ifdef MSG_NOTI_INTEGRATION
1116 snprintf(pDisplayName, MAX_ADDRESS_VAL_LEN + 1, "CB message");
1118 snprintf(pDisplayName, MAX_ADDRESS_VAL_LEN + 1, "[%d]", MsgId);
1126 snprintf(pDisplayName, MAX_ADDRESS_VAL_LEN + 1, "[%d]", MsgId);