Apply tizen coding rule
[platform/core/messaging/msg-service.git] / plugin / sms_plugin / SmsPluginCbMsgHandler.cpp
1 /*
2  * Copyright (c) 2014 Samsung Electronics Co., Ltd. All rights reserved
3  *
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
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
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.
15 */
16
17 #include <time.h>
18
19 #include "MsgDebug.h"
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"
30
31 /*==================================================================================================
32                   IMPLEMENTATION OF SmsPluginCbMsgHandler - Member Functions
33 ==================================================================================================*/
34 SmsPluginCbMsgHandler* SmsPluginCbMsgHandler::pInstance = NULL;
35
36
37 SmsPluginCbMsgHandler::SmsPluginCbMsgHandler()
38 {
39         pageList.clear();
40 }
41
42
43 SmsPluginCbMsgHandler::~SmsPluginCbMsgHandler()
44 {
45 }
46
47
48 SmsPluginCbMsgHandler* SmsPluginCbMsgHandler::instance()
49 {
50         if (!pInstance)
51                 pInstance = new SmsPluginCbMsgHandler();
52
53         return pInstance;
54 }
55
56
57 void SmsPluginCbMsgHandler::handleCbMsg(TapiHandle *handle, TelSmsCbMsg_t *pCbMsg)
58 {
59         MSG_BEGIN();
60
61 #if 0
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));
64         pCbMsg->Length = 173;
65         pCbMsg->EtwsMsgType = (TelSmsEtwsMsgType_t)2;
66         memcpy(pCbMsg->szMsgData, temp, pCbMsg->Length);
67
68         SMS_CB_NETWORK_TYPE_T type = pCbMsg->EtwsMsgType;
69         SMS_CBMSG_PAGE_S CbMsgPage = {0};
70
71         switch (type) {
72         case SMS_CB_NETWORK_TYPE_2G_GSM :
73                 Decode2gCbMsg((TelSmsCbMsg_t *)pCbMsg, &CbMsgPage);
74                 break;
75
76         case SMS_CB_NETWORK_TYPE_3G_UMTS :
77                 Decode3gCbMsg((TelSmsCbMsg_t *)pCbMsg, &CbMsgPage);
78                 break;
79         }
80 #else
81         SMS_CB_NETWORK_TYPE_T type = pCbMsg->CbMsgType;
82         SMS_CBMSG_PAGE_S CbMsgPage = {0};
83
84         switch (type) {
85         case SMS_CB_NETWORK_TYPE_2G_GSM :
86                 Decode2gCbMsg(pCbMsg, &CbMsgPage);
87                 break;
88
89         case SMS_CB_NETWORK_TYPE_3G_UMTS :
90                 Decode3gCbMsg(pCbMsg, &CbMsgPage);
91                 break;
92         }
93 #endif
94         /* Check CB Msg Options */
95         bool bJavaMsg = false;
96
97         int simIndex = SmsPluginDSHandler::instance()->getSimIndex(handle);
98
99         if (!checkCbOpt(&CbMsgPage, &bJavaMsg, simIndex)) {
100                 MSG_DEBUG("The CB Msg is not supported by option.");
101                 return;
102         }
103
104         if (bJavaMsg == true) {
105                 MSG_DEBUG("JAVA CB Msg.");
106                 CbMsgPage.cbMsgType = SMS_CBMSG_TYPE_JAVACBS;
107         }
108
109
110         /* Check CB Pages */
111         unsigned char pageCnt = checkCbPage(&CbMsgPage);
112
113         if (pageCnt == CbMsgPage.pageHeader.totalPages) {
114                 MSG_DEBUG("RECEIVED LAST MSG : %d", pageCnt);
115
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));
120
121                 MSG_MESSAGE_INFO_S msgInfo;
122
123                 /** initialize msgInfo */
124                 memset(&msgInfo, 0x00, sizeof(MSG_MESSAGE_INFO_S));
125
126                 msgInfo.addressList = NULL;
127                 unique_ptr<MSG_ADDRESS_INFO_S*, void(*)(MSG_ADDRESS_INFO_S**)> addressListBuf(&msgInfo.addressList, unique_ptr_deleter);
128
129                 /* Make CB Msg Structure */
130                 MakeCbMsg(&CbMsgPage, cbMsg);
131
132                 /* Convert to MSG_MESSAGE_INFO_S */
133                 convertCbMsgToMsginfo(cbMsg, &msgInfo, simIndex);
134
135                 /* Add CB Msg into DB */
136                 msg_error_t err = MSG_SUCCESS;
137
138                 err = SmsPluginStorage::instance()->checkMessage(&msgInfo);
139
140                 if (err == MSG_SUCCESS) {
141                         MSG_CB_MSG_S cbOutMsg = {0, };
142
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));
150
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);
157                 } else {
158                         MSG_WARN("checkMessage() Error !! [%d]", err);
159                 }
160
161 #if 0
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);
167                 }
168 #endif
169                 /* Remove From List */
170                 removeFromPageList(&CbMsgPage);
171         }
172         MSG_END();
173 }
174
175
176 void SmsPluginCbMsgHandler::handleEtwsMsg(TapiHandle *handle, TelSmsEtwsMsg_t *pEtwsMsg)
177 {
178         MSG_BEGIN();
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, };
183
184         if (type != TAPI_NETTEXT_ETWS_PRIMARY) {
185                 MSG_DEBUG("The Etws secondary Message");
186                 handleCbMsg(handle, (TelSmsCbMsg_t *)pEtwsMsg);
187                 return;
188         }
189         DecodeEtwsMsg(pEtwsMsg, &etwsPn);
190
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));
197
198         err = SmsPluginEventHandler::instance()->callbackCBMsgIncoming(&cbOutMsg, NULL);
199         if (err != MSG_SUCCESS)
200                 MSG_DEBUG("callbackMsgIncoming() Error !! [%d]", err);
201
202         MSG_END();
203 }
204
205
206 void SmsPluginCbMsgHandler::Decode2gCbMsg(TelSmsCbMsg_t *pCbMsg, SMS_CBMSG_PAGE_S *pCbPage)
207 {
208         unsigned char cbData[pCbMsg->Length+1];
209
210         memset(cbData, 0x00, sizeof(cbData));
211         memcpy(cbData, pCbMsg->szMsgData, pCbMsg->Length);
212         cbData[pCbMsg->Length] = '\0';
213
214         /* print cb data */
215         MSG_INFO("Received CB length:%d", pCbMsg->Length);
216         char cbDataTmp[(pCbMsg->Length*2)+1];
217         memset(cbDataTmp, 0x00, sizeof(cbDataTmp));
218
219         for (int i = 0; i < pCbMsg->Length; i++) {
220                 snprintf(cbDataTmp+(i*2), sizeof(cbDataTmp)-(i*2), "%02X", cbData[i]);
221         }
222         MSG_INFO("[%s]", cbDataTmp);
223
224         pCbPage->cbMsgType = SMS_CBMSG_TYPE_CBS;
225
226         /* Serial Number */
227         pCbPage->pageHeader.serialNum.geoScope = (cbData[0] & 0xC0) >> 6;
228
229         pCbPage->pageHeader.serialNum.msgCode = (cbData[0] & 0x3F) << 4;
230         pCbPage->pageHeader.serialNum.msgCode |= (cbData[1] & 0xF0) >> 4;
231
232         pCbPage->pageHeader.serialNum.updateNum = cbData[1] & 0x0F;
233
234         MSG_DEBUG("geoScope : [%d], msgCode : [%d], updateNum : [%d]", pCbPage->pageHeader.serialNum.geoScope, pCbPage->pageHeader.serialNum.msgCode, pCbPage->pageHeader.serialNum.updateNum);
235
236         pCbPage->pageHeader.msgId = (cbData[2] << 8) | cbData[3];
237
238         MSG_DEBUG("MSG ID : [%d]", pCbPage->pageHeader.msgId);
239
240         /* DCS */
241         decodeCbMsgDCS(cbData[4], (unsigned char*)cbData + 6, &(pCbPage->pageHeader.dcs));
242
243         /* Page Parameter */
244         pCbPage->pageHeader.totalPages = cbData[5] & 0x0F;
245         pCbPage->pageHeader.page = (cbData[5] & 0xF0) >> 4;
246
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);
249
250         MSG_DEBUG("Total Page : [%d], Page : [%d]", pCbPage->pageHeader.totalPages, pCbPage->pageHeader.page);
251
252         /* Convert Language Type */
253         convertLangType(pCbPage->pageHeader.dcs.langType, &(pCbPage->pageHeader.langType));
254
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();
259
260         /* Decode CB Data */
261         int dataLen = pCbMsg->Length - 6;
262
263         MSG_DEBUG("codingScheme:[%d]", pCbPage->pageHeader.dcs.codingScheme);
264
265         switch (pCbPage->pageHeader.dcs.codingScheme) {
266         case SMS_CHARSET_7BIT: {
267                 MSG_DEBUG("GSM 7 BIT");
268
269                 dataLen = (dataLen*8) / 7;
270
271                 SmsPluginUDCodec udCodec;
272                 char pageData[MAX_CBMSG_PAGE_SIZE+1];
273                 int unpackLen = udCodec.unpack7bitChar(&cbData[6], dataLen, 0, pageData);
274
275                 if (pCbPage->pageHeader.dcs.iso639Lang[0]) {
276                         unpackLen = unpackLen - 3;
277                         if (unpackLen > 0)
278                                 memcpy(pCbPage->pageData, &pageData[3], unpackLen);
279                         else
280                                 unpackLen = 0;
281                 } else {
282                         memcpy(pCbPage->pageData, &pageData, unpackLen);
283                 }
284
285                 MSG_DEBUG("unpackLen : [%d]", unpackLen);
286
287                 pCbPage->pageLength = unpackLen;
288                 pCbPage->pageData[unpackLen] = '\0';
289         }
290         break;
291
292         case SMS_CHARSET_8BIT:
293         case SMS_CHARSET_UCS2: {
294                 MSG_DEBUG("UCS2 or 8BIT");
295
296                 if (pCbPage->pageHeader.dcs.iso639Lang[0]) {
297                         memcpy(pCbPage->pageData, &cbData[8], dataLen - 2);
298                         pCbPage->pageLength = dataLen - 2;
299                 } else {
300                         memcpy(pCbPage->pageData, &cbData[6], dataLen);
301                         pCbPage->pageLength = dataLen;
302                 }
303         }
304         break;
305         }
306
307         MSG_DEBUG("Page Length : [%d], Page Data : [%s]", pCbPage->pageLength, pCbPage->pageData);
308 }
309
310
311 void SmsPluginCbMsgHandler::DecodeEtwsMsg(TelSmsEtwsMsg_t *pEtwsMsg, SMS_ETWS_PRIMARY_S *pEtwsPn)
312 {
313         if ( !pEtwsMsg || !pEtwsPn )
314                 return;
315
316         if (pEtwsMsg->Length > MAX_ETWS_SIZE)
317                 THROW(MsgException::SMS_PLG_ERROR, "ETWS Msg Size is over MAX [%d]", pEtwsMsg->Length);
318
319         unsigned char EtwsData[pEtwsMsg->Length+1];
320
321         memset(EtwsData, 0x00, sizeof(EtwsData));
322         memcpy(EtwsData, pEtwsMsg->szMsgData, pEtwsMsg->Length);
323         EtwsData[pEtwsMsg->Length] = '\0';
324
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));
329
330         for (int i = 0; i < pEtwsMsg->Length; i++) {
331                 snprintf(EtwsDataTmp+(i*2), sizeof(EtwsDataTmp)-(i*2), "%02X", EtwsData[i]);
332         }
333         MSG_INFO("[%s]", EtwsDataTmp);
334
335         /* received time */
336         pEtwsPn->recvTime = getRecvTime();
337
338         /* Serial Number */
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;
343
344         MSG_DEBUG("geoScope : [%d], msgCode : [%d], updateNum : [%d]", pEtwsPn->serialNum.geoScope, pEtwsPn->serialNum.msgCode, pEtwsPn->serialNum.updateNum);
345
346         /* Message Identifier */
347         pEtwsPn->msgId = (EtwsData[2] << 8) | EtwsData[3];
348         MSG_DEBUG("MSG ID : [%d]", pEtwsPn->msgId);
349
350         /* warning type */
351         pEtwsPn->warningType = (EtwsData[4] << 8) | EtwsData[5];
352         MSG_DEBUG("warningType : [0x%04x]", pEtwsPn->msgId);
353
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]);
358         }
359 }
360
361 void SmsPluginCbMsgHandler::Decode3gCbMsg(TelSmsCbMsg_t *pCbMsg, SMS_CBMSG_PAGE_S *pCbPage)
362 {
363         unsigned char cbData[(MAX_CBMSG_PAGE_SIZE*MAX_CBMSG_PAGE_NUM)+1];
364
365         memset(cbData, 0x00, sizeof(cbData));
366         memcpy(cbData, pCbMsg->szMsgData, pCbMsg->Length);
367         cbData[pCbMsg->Length] = '\0';
368
369         /* print cb data */
370         MSG_INFO("Received CB length:%d", pCbMsg->Length);
371         char cbDataTmp[(pCbMsg->Length*2)+1];
372         memset(cbDataTmp, 0x00, sizeof(cbDataTmp));
373
374         for (int i = 0; i < pCbMsg->Length; i++) {
375                 snprintf(cbDataTmp+(i*2), sizeof(cbDataTmp)-(i*2), "%02X", cbData[i]);
376         }
377         MSG_INFO("[%s]", cbDataTmp);
378
379         pCbPage->cbMsgType = (SMS_CBMSG_TYPE_T)cbData[0];
380
381         pCbPage->pageHeader.msgId = (cbData[1] << 8) | cbData[2];
382
383         MSG_DEBUG("MSG ID : [%d]", pCbPage->pageHeader.msgId);
384
385         /* Serial Number */
386         pCbPage->pageHeader.serialNum.geoScope = (cbData[3] & 0xC0) >> 6;
387
388         pCbPage->pageHeader.serialNum.msgCode = (cbData[3] & 0x3F) << 4;
389         pCbPage->pageHeader.serialNum.msgCode |= (cbData[4] & 0xF0) >> 4;
390
391         pCbPage->pageHeader.serialNum.updateNum = cbData[4] & 0x0F;
392
393         MSG_DEBUG("geoScope : [%d], msgCode : [%d], updateNum : [%d]", pCbPage->pageHeader.serialNum.geoScope, pCbPage->pageHeader.serialNum.msgCode, pCbPage->pageHeader.serialNum.updateNum);
394
395         /* DCS */
396         decodeCbMsgDCS(cbData[5], (unsigned char*)cbData + 6, &(pCbPage->pageHeader.dcs));
397
398         /* Convert Language Type */
399         convertLangType(pCbPage->pageHeader.dcs.langType, &(pCbPage->pageHeader.langType));
400
401         MSG_DEBUG("In Language Type : [%d], Out Language Type : [%d]", pCbPage->pageHeader.dcs.langType, pCbPage->pageHeader.langType);
402
403         /* Get Receive Time */
404         pCbPage->pageHeader.recvTime = getRecvTime();
405         pCbPage->pageHeader.totalPages = cbData[6];
406
407         /* Decode CB Data */
408         int dataLen = 0;
409         int offset = 0;
410
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);
417
418                         dataLen = (dataLen*8) / 7;
419
420                         if (dataLen > MAX_CBMSG_PAGE_SIZE)
421                                 THROW(MsgException::SMS_PLG_ERROR, "CB Msg Size is over MAX [%d]", dataLen);
422
423                         SmsPluginUDCodec udCodec;
424                         int unpackLen = udCodec.unpack7bitChar((const unsigned char *)cbMessage, dataLen, 0, pCbPage->pageData + offset);
425                         offset += unpackLen;
426                 }
427                 pCbPage->pageLength = offset;
428         }
429         break;
430
431         case SMS_CHARSET_8BIT:
432         case SMS_CHARSET_UCS2: {
433 #if 0
434                 char cbMessage[MAX_CBMSG_PAGE_SIZE]= {0, };
435
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);
439                         offset += dataLen;
440                 }
441                 dataLen = offset;
442
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;
447                 } else {
448                         memcpy(pCbPage->pageData, cbMessage, dataLen);
449                         pCbPage->pageLength = dataLen;
450                 }
451 #else
452                 char cbMessage[MAX_CBMSG_PAGE_SIZE] = {0, };
453
454                 for (int i = 0; i < pCbPage->pageHeader.totalPages; ++i) {
455                         if (pCbPage->pageHeader.dcs.iso639Lang[0]) {
456                                 dataLen = cbData[7+(i+1)*82 + i] - 2;
457                                 memcpy(cbMessage + offset, &cbData[7+(i*82)+ i + 2], dataLen);
458                                 offset += dataLen;
459                         } else {
460                                 dataLen = cbData[7+(i+1)*82 + i];
461                                 memcpy(cbMessage + offset, &cbData[7+(i*82)+ i], dataLen);
462                                 offset += dataLen;
463                         }
464                 }
465                 dataLen = offset;
466                 memcpy(pCbPage->pageData, cbMessage, dataLen);
467                 pCbPage->pageLength = dataLen;
468 #endif
469         }
470         break;
471         }
472         pCbPage->pageHeader.totalPages = 1;
473
474         MSG_DEBUG("Page Length : [%d], Page Data : [%s]", pCbPage->pageLength, pCbPage->pageData);
475 }
476
477 unsigned short SmsPluginCbMsgHandler::encodeCbSerialNum(SMS_CBMSG_SERIAL_NUM_S snFields)
478 {
479         unsigned short serialNum = 0;
480
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);
483
484         return serialNum;
485 }
486
487 int SmsPluginCbMsgHandler::CMAS_class(unsigned short message_id)
488 {
489         int ret = 0;
490
491         switch (message_id) {
492         case 4370:
493         case 4383:
494                 ret = MSG_CMAS_PRESIDENTIAL;
495                 break;
496         case 4371:
497         case 4372:
498         case 4384:
499         case 4385:
500                 ret = MSG_CMAS_EXTREME;
501                 break;
502         case 4373:
503         case 4374:
504         case 4375:
505         case 4376:
506         case 4377:
507         case 4378:
508         case 4386:
509         case 4387:
510         case 4388:
511         case 4389:
512         case 4390:
513         case 4391:
514                 ret = MSG_CMAS_SEVERE;
515                 break;
516         case 4379:
517         case 4392:
518                 ret = MSG_CMAS_AMBER;
519                 break;
520         case 4380:
521         case 4393:
522                 ret = MSG_CMAS_TEST;
523                 break;
524         case 4381:
525         case 4394:
526                 ret = MSG_CMAS_EXERCISE;
527                 break;
528         case 4382:
529         case 4395:
530                 ret = MSG_CMAS_OPERATOR_DEFINED;
531                 break;
532         default:
533                 break;
534         }
535
536         return ret;
537 }
538
539 bool SmsPluginCbMsgHandler::checkCbOpt(SMS_CBMSG_PAGE_S *CbPage, bool *pJavaMsg, msg_sim_slot_id_t simIndex)
540 {
541         bool bReceive = false;
542         char keyName[MAX_VCONFKEY_NAME_LEN];
543         memset(keyName, 0x00, sizeof(keyName));
544         snprintf(keyName, sizeof(keyName), "%s/%d", CB_RECEIVE, simIndex);
545         MsgSettingGetBool(keyName, &bReceive);
546
547         /* Receive CB Msg = FALSE */
548         if (!bReceive) {
549                 MSG_DEBUG("RECEIVE CB = FALSE");
550                 return false;
551         }
552
553 #if 0
554         char keyname[128];
555         /* check Language */
556         memset(keyName, 0x00, sizeof(keyName));
557         snprintf(keyName, sizeof(keyname), "%s/%d", CB_LANGUAGE, MSG_CBLANG_TYPE_ALL);
558
559         bool bAllLang = false;
560         MsgSettingGetBool(keyName, &bAllLang);
561
562         if (!bAllLang) {
563                 MSG_DEBUG("ALL LANGUAGE = FALSE");
564
565                 memset(keyName, 0x00, sizeof(keyName));
566                 snprintf(keyName, sizeof(keyname), "%s/%d", CB_LANGUAGE, CbPage.pageHeader.langType);
567
568                 bool bLang = false;
569
570                 MsgSettingGetBool(keyName, &bLang);
571
572                 if (!bLang || CbPage.pageHeader.langType == MSG_CBLANG_TYPE_MAX) {
573                         MSG_DEBUG("LANGUAGE [%d] = FALSE", CbPage.pageHeader.langType);
574                         return false;
575                 }
576         }
577 #endif
578
579         bool bActivate = false;
580         int MsgId_from = 0, MsgId_to = 0;
581         MSG_CB_CHANNEL_S cbChannelInfo = {0, };
582         msg_error_t err = MSG_SUCCESS;
583         MsgDbHandler *dbHandle = getDbHandle();
584
585         err = MsgStoGetCBChannelInfo(dbHandle, &cbChannelInfo, simIndex);
586         if (err != MSG_SUCCESS)
587                 MSG_ERR("Error value of MsgStoGetCBChannelInfo [%d]", err);
588
589         for (int i = 0; i < cbChannelInfo.channelCnt; i++) {
590                 bActivate = cbChannelInfo.channelInfo[i].bActivate;
591                 MsgId_from = cbChannelInfo.channelInfo[i].from;
592                 MsgId_to = cbChannelInfo.channelInfo[i].to;
593
594                 if (bActivate == true && CbPage->pageHeader.msgId >= MsgId_from && CbPage->pageHeader.msgId <= MsgId_to) {
595                         MSG_DEBUG("FIND CHANNEL = [%d]", CbPage->pageHeader.msgId);
596                         return true;
597                 }
598         }
599
600         return false;
601 }
602
603 unsigned char SmsPluginCbMsgHandler::checkCbPage(SMS_CBMSG_PAGE_S *CbPage)
604 {
605         unsigned char currPageCnt = 0;
606
607         bool bFind = false;
608
609 #if 0
610         msg_error_t err = MSG_SUCCESS;
611
612         SmsPluginStorage *storageHandler = SmsPluginStorage::instance();
613         err = storageHandler->isReceivedCBMessage(CbPage);
614
615         /* check existing message with cb internal table; */
616         if (err != MSG_ERR_DB_NORECORD) {
617                 MSG_DEBUG("already received message: [%d]", CbPage.pageHeader.msgId);
618                 return 0;
619         }
620 #endif
621
622         if (CbPage->pageHeader.totalPages > 0) {
623                 for (unsigned int i = 0; i < pageList.size(); i++) {
624                         if (pageList[i].geoScope == CbPage->pageHeader.serialNum.geoScope && pageList[i].msgCode == CbPage->pageHeader.serialNum.msgCode) {
625                                 MSG_DEBUG("geoScope [%d], msgCode [%d]", pageList[i].geoScope, pageList[i].msgCode);
626
627                                 if (pageList[i].msgId == CbPage->pageHeader.msgId) {
628                                         int updateNum = CbPage->pageHeader.serialNum.updateNum - pageList[i].updateNum;
629
630                                         if (updateNum > 0) { /* New Message Content */
631                                                 break;
632                                         } else if (updateNum == 0) { /* Same Message Content */
633                                                 if (pageList[i].data.count(CbPage->pageHeader.page) != 0) {
634                                                         MSG_DEBUG("The Page Number already exists [%d]", CbPage->pageHeader.page);
635                                                         return 0;
636                                                 }
637
638                                                 pair<unsigned char, SMS_CBMSG_PAGE_S> newData(CbPage->pageHeader.page, *CbPage);
639                                                 pageList[i].data.insert(newData);
640
641                                                 MSG_DEBUG("PAGE DATA : %s", CbPage->pageData);
642                                                 MSG_DEBUG("PAIR DATA [%d] : %s", newData.first, newData.second.pageData);
643
644                                                 pageList[i].pageCnt++;
645                                                 pageList[i].totalSize += CbPage->pageLength;
646
647                                                 currPageCnt = pageList[i].pageCnt;
648
649                                                 bFind = true;
650
651                                                 break;
652                                         } else { /* Old Message Content */
653                                                 return 0;
654                                         }
655                                 }
656                         }
657                 }
658         }
659
660         if (bFind == false || CbPage->pageHeader.totalPages == 1) {
661                 addToPageList(CbPage);
662                 return 1;
663         }
664
665         return currPageCnt;
666 }
667
668
669 void SmsPluginCbMsgHandler::MakeCbMsg(SMS_CBMSG_PAGE_S *CbPage, SMS_CBMSG_S *pCbMsg)
670 {
671         pCbMsg->cbMsgType = CbPage->cbMsgType;
672         pCbMsg->msgId = CbPage->pageHeader.msgId;
673         pCbMsg->classType = CbPage->pageHeader.dcs.classType;
674         pCbMsg->codingScheme = CbPage->pageHeader.dcs.codingScheme;
675         pCbMsg->recvTime = CbPage->pageHeader.recvTime;
676
677         cbPageMap::iterator it;
678         int offset = 0;
679
680         for (unsigned int i = 0; i < pageList.size(); i++) {
681                 if (pageList[i].geoScope == CbPage->pageHeader.serialNum.geoScope && pageList[i].msgCode == CbPage->pageHeader.serialNum.msgCode) {
682                         MSG_DEBUG("geoScope [%d], msgCode [%d]", pageList[i].geoScope, pageList[i].msgCode);
683
684                         if (pageList[i].msgId == CbPage->pageHeader.msgId) {
685                                 for (it = pageList[i].data.begin(); it != pageList[i].data.end(); it++) {
686                                         memcpy(pCbMsg->msgData + offset, it->second.pageData, it->second.pageLength);
687                                         pCbMsg->msgLength += it->second.pageLength;
688                                         offset = pCbMsg->msgLength;
689                                 }
690                         }
691                 }
692         }
693
694 #if 0
695         pCbMsg->msgLength = tmpStr.size();
696
697         memcpy(pCbMsg->msgData, tmpStr.c_str(), tmpStr.size());
698         pCbMsg->msgData[tmpStr.size()] = '\0';
699
700         MSG_DEBUG("SIZE : [%d] TOTAL MSG : %s", tmpStr.size(), tmpStr.c_str());
701 #endif
702 }
703
704
705 void SmsPluginCbMsgHandler::convertCbMsgToMsginfo(SMS_CBMSG_S *pCbMsg, MSG_MESSAGE_INFO_S *pMsgInfo, msg_sim_slot_id_t simIndex)
706 {
707         pMsgInfo->msgId = (msg_message_id_t)pCbMsg->msgId;
708
709         pMsgInfo->folderId = MSG_CBMSGBOX_ID;
710
711         /* Convert Type values */
712         pMsgInfo->msgType.mainType = MSG_SMS_TYPE;
713
714         if (pCbMsg->cbMsgType == SMS_CBMSG_TYPE_CBS) {
715                 int cmas_class = CMAS_class(pCbMsg->msgId);
716
717                 if (cmas_class == 0)
718                         pMsgInfo->msgType.subType = MSG_CB_SMS;
719                 else
720                         pMsgInfo->msgType.subType = (MSG_SUB_TYPE_T)cmas_class;
721         } else if (pCbMsg->cbMsgType == SMS_CBMSG_TYPE_JAVACBS) {
722                 pMsgInfo->msgType.subType = MSG_JAVACB_SMS;
723         }
724
725         switch (pCbMsg->classType) {
726         case SMS_MSG_CLASS_0:
727                 pMsgInfo->msgType.classType = MSG_CLASS_0;
728                 break;
729         case SMS_MSG_CLASS_1:
730                 pMsgInfo->msgType.classType = MSG_CLASS_1;
731                 break;
732         case SMS_MSG_CLASS_2:
733                 pMsgInfo->msgType.classType = MSG_CLASS_2;
734                 break;
735         case SMS_MSG_CLASS_3:
736                 pMsgInfo->msgType.classType = MSG_CLASS_3;
737                 break;
738         default:
739                 pMsgInfo->msgType.classType = MSG_CLASS_NONE;
740                 break;
741         }
742
743         pMsgInfo->storageId = MSG_STORAGE_PHONE;
744         pMsgInfo->networkStatus = MSG_NETWORK_RECEIVED;
745         pMsgInfo->bRead = false;
746         pMsgInfo->bProtected = false;
747         pMsgInfo->priority = MSG_MESSAGE_PRIORITY_NORMAL;
748         pMsgInfo->direction = MSG_DIRECTION_TYPE_MT;
749
750         /* Temporary */
751         pMsgInfo->nAddressCnt = 1;
752
753         pMsgInfo->addressList =  (MSG_ADDRESS_INFO_S *)new char[sizeof(MSG_ADDRESS_INFO_S)];
754         memset(pMsgInfo->addressList, 0x00, sizeof(MSG_ADDRESS_INFO_S));
755
756         pMsgInfo->addressList[0].addressType = MSG_ADDRESS_TYPE_UNKNOWN;
757         pMsgInfo->addressList[0].recipientType = MSG_RECIPIENTS_TYPE_UNKNOWN;
758         pMsgInfo->sim_idx = simIndex;
759
760         /*      TODO :: MSG ID should be used to get CB message type */
761         getDisplayName(pCbMsg->msgId, pMsgInfo->addressList[0].addressVal, simIndex);
762         MSG_SEC_DEBUG("%s", pMsgInfo->addressList[0].addressVal);
763
764
765         pMsgInfo->msgPort.valid = false;
766         pMsgInfo->msgPort.dstPort = 0;
767         pMsgInfo->msgPort.srcPort = 0;
768
769         pMsgInfo->displayTime = pCbMsg->recvTime;
770         MSG_DEBUG("recvTime is %d", pMsgInfo->displayTime);
771
772         int bufSize = pCbMsg->msgLength*2;
773
774         char tmpBuf[bufSize];
775         memset(tmpBuf, 0x00, sizeof(tmpBuf));
776
777         while (pCbMsg->msgLength > 0) {
778                 if (pCbMsg->msgData[pCbMsg->msgLength-1] == ' ' ||
779                                 pCbMsg->msgData[pCbMsg->msgLength-1] == '\r' ||
780                                 pCbMsg->msgData[pCbMsg->msgLength-1] == '\n') {
781                         pCbMsg->msgLength--;
782                 }
783                 else {
784                         break;
785                 }
786         }
787         pCbMsg->msgData[pCbMsg->msgLength] = '\0';
788
789         MSG_DEBUG("LENGTH %d CB MSG %s", pCbMsg->msgLength, pCbMsg->msgData);
790
791         /* Convert Data values */
792         pMsgInfo->dataSize = convertTextToUtf8((unsigned char*)tmpBuf, bufSize, pCbMsg);
793
794         if (pMsgInfo->dataSize > MAX_MSG_TEXT_LEN) {
795                 pMsgInfo->bTextSms = false;
796
797                 /* Save Message Data into File */
798                 char fileName[MSG_FILENAME_LEN_MAX+1];
799                 memset(fileName, 0x00, sizeof(fileName));
800
801                 if (MsgCreateFileName(fileName) == false)
802                         THROW(MsgException::FILE_ERROR, "MsgCreateFileName error");
803
804                 MSG_SEC_DEBUG("Save Message Data into file : size[%d] name[%s]\n", pMsgInfo->dataSize, fileName);
805                 if (MsgWriteIpcFile(fileName, tmpBuf, pMsgInfo->dataSize) == false)
806                         THROW(MsgException::FILE_ERROR, "MsgWriteIpcFile error");
807
808                 strncpy(pMsgInfo->msgData, fileName, MAX_MSG_DATA_LEN);
809         } else {
810                 pMsgInfo->bTextSms = true;
811
812                 memset(pMsgInfo->msgText, 0x00, sizeof(pMsgInfo->msgText));
813                 memcpy(pMsgInfo->msgText, tmpBuf, pMsgInfo->dataSize);
814                 pMsgInfo->dataSize = strlen(pMsgInfo->msgText);
815                 MSG_SEC_DEBUG("CB MSG %s", pMsgInfo->msgText);
816         }
817 }
818
819
820 void SmsPluginCbMsgHandler::convertEtwsMsgToMsginfo(SMS_CBMSG_PAGE_S *EtwsMsg, MSG_MESSAGE_INFO_S *pMsgInfo, msg_sim_slot_id_t simIndex)
821 {
822         pMsgInfo->msgId = (msg_message_id_t)EtwsMsg->pageHeader.msgId;
823
824         pMsgInfo->folderId = MSG_CBMSGBOX_ID;
825
826         /* Convert Type values */
827         pMsgInfo->msgType.mainType = MSG_SMS_TYPE;
828
829         if (EtwsMsg->cbMsgType == SMS_CBMSG_TYPE_ETWS)
830                 pMsgInfo->msgType.subType = MSG_ETWS_SMS;
831
832         pMsgInfo->storageId = MSG_STORAGE_PHONE;
833         pMsgInfo->networkStatus = MSG_NETWORK_RECEIVED;
834         pMsgInfo->bRead = false;
835         pMsgInfo->bProtected = false;
836         pMsgInfo->priority = MSG_MESSAGE_PRIORITY_NORMAL;
837         pMsgInfo->direction = MSG_DIRECTION_TYPE_MT;
838
839         /* Temporary */
840         pMsgInfo->nAddressCnt = 1;
841
842         pMsgInfo->addressList[0].addressType = MSG_ADDRESS_TYPE_UNKNOWN;
843         pMsgInfo->addressList[0].recipientType = MSG_RECIPIENTS_TYPE_UNKNOWN;
844
845         getDisplayName(EtwsMsg->pageHeader.msgId, pMsgInfo->addressList[0].addressVal, simIndex);
846         MSG_SEC_DEBUG("%s", pMsgInfo->addressList[0].addressVal);
847
848         pMsgInfo->msgPort.valid = false;
849         pMsgInfo->msgPort.dstPort = 0;
850         pMsgInfo->msgPort.srcPort = 0;
851
852         pMsgInfo->displayTime = EtwsMsg->pageHeader.recvTime;
853         MSG_DEBUG("recvTime is %d", pMsgInfo->displayTime);
854         MSG_DEBUG("LENGTH %d", EtwsMsg->pageLength);
855         pMsgInfo->bTextSms = true;
856         pMsgInfo->dataSize = EtwsMsg->pageLength;
857         memset(pMsgInfo->msgData, 0x00, sizeof(pMsgInfo->msgData));
858         memcpy(pMsgInfo->msgData, EtwsMsg->pageData, pMsgInfo->dataSize);
859 }
860
861 int SmsPluginCbMsgHandler::convertTextToUtf8(unsigned char* outBuf, int outBufSize, SMS_CBMSG_S* pCbMsg)
862 {
863         int     convertedTextSize = 0;
864         MSG_LANG_INFO_S langInfo = {0, };
865
866         MsgTextConvert *textCvt = MsgTextConvert::instance();
867
868         if (!outBuf || !pCbMsg) {
869                 MSG_DEBUG("invalid param.\n");
870                 return 0;
871         }
872
873         langInfo.bSingleShift = false;
874         langInfo.bLockingShift = false;
875
876
877         /* Convert Data values */
878         if (pCbMsg->codingScheme == SMS_CHARSET_7BIT)
879                 convertedTextSize = textCvt->convertGSM7bitToUTF8(outBuf, outBufSize, (unsigned char*)pCbMsg->msgData, pCbMsg->msgLength, &langInfo);
880         else if (pCbMsg->codingScheme == SMS_CHARSET_UCS2)
881                 convertedTextSize = textCvt->convertUCS2ToUTF8(outBuf, outBufSize, (unsigned char*)pCbMsg->msgData, pCbMsg->msgLength);
882
883         return convertedTextSize;
884 }
885
886 void SmsPluginCbMsgHandler::addToPageList(SMS_CBMSG_PAGE_S *CbPage)
887 {
888         CB_PAGE_INFO_S tmpInfo;
889
890         tmpInfo.geoScope = CbPage->pageHeader.serialNum.geoScope;
891         tmpInfo.msgCode = CbPage->pageHeader.serialNum.msgCode;
892         tmpInfo.updateNum = CbPage->pageHeader.serialNum.updateNum;
893         tmpInfo.msgId = CbPage->pageHeader.msgId;
894         tmpInfo.totalPages = CbPage->pageHeader.totalPages;
895
896         tmpInfo.pageCnt = 1;
897         tmpInfo.totalSize = CbPage->pageLength;
898
899         pair<unsigned char, SMS_CBMSG_PAGE_S> newData(CbPage->pageHeader.page, *CbPage);
900         tmpInfo.data.insert(newData);
901
902         MSG_DEBUG("MSG DATA : %s", CbPage->pageData);
903         MSG_DEBUG("PAIR DATA [%d] : %s", newData.first, newData.second.pageData);
904
905         pageList.push_back(tmpInfo);
906 }
907
908
909 void SmsPluginCbMsgHandler::removeFromPageList(SMS_CBMSG_PAGE_S *CbPage)
910 {
911         unsigned int index;
912
913         for (index = 0; index < pageList.size(); index++) {
914                 if (pageList[index].geoScope == CbPage->pageHeader.serialNum.geoScope && pageList[index].msgCode == CbPage->pageHeader.serialNum.msgCode) {
915                         MSG_DEBUG("geoScope [%d], msgCode [%d]", pageList[index].geoScope, pageList[index].msgCode);
916
917                         if (pageList[index].msgId == CbPage->pageHeader.msgId)
918                                 break;
919                 }
920         }
921
922         MSG_DEBUG("remove index [%d]", index);
923
924         pageList.erase(pageList.begin()+index);
925 }
926
927
928 void SmsPluginCbMsgHandler::decodeCbMsgDCS(unsigned char dcsData, const unsigned char *pMsgData, SMS_CBMSG_DCS_S* pDcs)
929 {
930         pDcs->codingGroup = SMS_CBMSG_CODGRP_GENERAL_DCS;
931         pDcs->classType = SMS_MSG_CLASS_NONE;
932         pDcs->bCompressed = false;
933         pDcs->codingScheme = SMS_CHARSET_7BIT;
934         pDcs->langType = SMS_CBMSG_LANG_UNSPECIFIED;
935         memset(pDcs->iso639Lang, 0x00, sizeof(pDcs->iso639Lang));
936         pDcs->bUDH = false;
937         pDcs->rawData = dcsData;
938
939         unsigned char codingGrp = (dcsData & 0xF0) >> 4;
940
941         switch (codingGrp) {
942         case 0x00:
943         case 0x02:
944         case 0x03: {
945                 pDcs->codingGroup = SMS_CBMSG_CODGRP_GENERAL_DCS;
946                 pDcs->langType = (SMS_CBMSG_LANG_TYPE_T)dcsData;
947         }
948         break;
949
950         case 0x01: {
951                 if (dcsData == 0x10 || dcsData == 0x11) {
952                         pDcs->codingGroup = SMS_CBMSG_CODGRP_GENERAL_DCS;
953                         pDcs->codingScheme = (dcsData & 0x01) ? SMS_CHARSET_UCS2 : SMS_CHARSET_7BIT;
954                         pDcs->langType = SMS_CBMSG_LANG_ISO639;
955                         MSG_DEBUG("codingScheme: [%d]", pDcs->codingScheme);
956                         if (pMsgData[0] && pMsgData[1]) {
957                                 pDcs->iso639Lang[0] = pMsgData[0] & 0x7F;
958                                 pDcs->iso639Lang[1] = (pMsgData[0] & 0X80) >> 7;
959                                 pDcs->iso639Lang[1] |= (pMsgData[1] & 0X3F) << 1;
960                                 pDcs->iso639Lang[2] = 0x13;  /* CR */
961                         } else {
962                                 /* Default it to English if pMsgData is NULL */
963                                 pDcs->iso639Lang[0] = 0x45;  /* E */
964                                 pDcs->iso639Lang[1] = 0x4E;  /* N */
965                                 pDcs->iso639Lang[2] = 0x13;  /* CR */
966                         }
967                 }
968         }
969         break;
970
971         case 0x04:
972         case 0x05:
973         case 0x06:
974         case 0x07: {
975                 pDcs->codingGroup = SMS_CBMSG_CODGRP_GENERAL_DCS;
976
977                 pDcs->bCompressed = (dcsData & 0x20) ? true : false;
978
979                 if (dcsData & 0x10)
980                         pDcs->classType = (SMS_MSG_CLASS_T)(dcsData & 0x03);
981
982                 unsigned char tmpScheme = (dcsData & 0x0C) >> 2;
983
984                 switch (tmpScheme) {
985                 case 0x00:
986                         pDcs->codingScheme = SMS_CHARSET_7BIT;
987                         break;
988                 case 0x01:
989                         pDcs->codingScheme = SMS_CHARSET_8BIT;
990                         break;
991                 case 0x02:
992                         pDcs->codingScheme = SMS_CHARSET_UCS2;
993                         break;
994                 default:
995                         MSG_DEBUG("tmpScheme: [%d]", tmpScheme);
996                         break;
997                 }
998         }
999         break;
1000
1001         case 0x09: {
1002                 pDcs->bUDH = true;
1003                 pDcs->classType = (MSG_CLASS_TYPE_T)(dcsData & 0x03);
1004                 pDcs->codingScheme = (SMS_CODING_SCHEME_T)((dcsData & 0x0C) >> 2);
1005         }
1006         break;
1007
1008         case 0x0E: {
1009                 pDcs->codingGroup = SMS_CBMSG_CODGRP_WAP;
1010         }
1011         break;
1012
1013         case 0x0F: {
1014                 pDcs->codingGroup = SMS_CBMSG_CODGRP_CLASS_CODING;
1015                 pDcs->codingScheme = (dcsData & 0x04) ? SMS_CHARSET_8BIT : SMS_CHARSET_7BIT;
1016                 pDcs->classType = (MSG_CLASS_TYPE_T)(dcsData & 0x03);
1017         }
1018         break;
1019         default:
1020                 MSG_DEBUG("codingGrp: [0x%x]", codingGrp);
1021                 break;
1022         }
1023 }
1024
1025
1026 void SmsPluginCbMsgHandler::convertLangType(SMS_CBMSG_LANG_TYPE_T InType , MSG_CB_LANGUAGE_TYPE_T *pOutType)
1027 {
1028         switch (InType) {
1029         case SMS_CBMSG_LANG_GERMAN :
1030                 *pOutType = MSG_CBLANG_TYPE_GER;
1031                 break;
1032
1033         case SMS_CBMSG_LANG_ENGLISH :
1034                 *pOutType = MSG_CBLANG_TYPE_ENG;
1035                 break;
1036
1037         case SMS_CBMSG_LANG_ITALIAN :
1038                 *pOutType = MSG_CBLANG_TYPE_ITA;
1039                 break;
1040
1041         case SMS_CBMSG_LANG_FRENCH :
1042                 *pOutType = MSG_CBLANG_TYPE_FRE;
1043                 break;
1044
1045         case SMS_CBMSG_LANG_SPANISH :
1046                 *pOutType = MSG_CBLANG_TYPE_SPA;
1047                 break;
1048
1049         case SMS_CBMSG_LANG_DUTCH :
1050                 *pOutType = MSG_CBLANG_TYPE_NED;
1051                 break;
1052
1053         case SMS_CBMSG_LANG_SWEDISH :
1054                 *pOutType = MSG_CBLANG_TYPE_SWE;
1055                 break;
1056
1057         case SMS_CBMSG_LANG_PORTUGUESE :
1058                 *pOutType = MSG_CBLANG_TYPE_POR;
1059                 break;
1060
1061         case SMS_CBMSG_LANG_TURKISH :
1062                 *pOutType = MSG_CBLANG_TYPE_TUR;
1063                 break;
1064
1065         default :
1066                 *pOutType = MSG_CBLANG_TYPE_MAX;
1067                 break;
1068         }
1069 }
1070
1071
1072 unsigned long SmsPluginCbMsgHandler::getRecvTime()
1073 {
1074         time_t recvTime;
1075
1076         recvTime = time(NULL);
1077
1078         return (unsigned long)recvTime;
1079 }
1080
1081
1082 void SmsPluginCbMsgHandler::getDisplayName(unsigned short       MsgId, char *pDisplayName, msg_sim_slot_id_t simIndex)
1083 {
1084         MSG_CB_CHANNEL_S cbChannelInfo = {0, };
1085         msg_error_t err = MSG_SUCCESS;
1086         MsgDbHandler *dbHandle = getDbHandle();
1087
1088         err = MsgStoGetCBChannelInfo(dbHandle, &cbChannelInfo, simIndex);
1089         MSG_DEBUG("MsgStoGetCBChannelInfo [err = %d]", err);
1090
1091         for (int i = 0; i < cbChannelInfo.channelCnt; i++) {
1092                 if (MsgId >= cbChannelInfo.channelInfo[i].from && MsgId <= cbChannelInfo.channelInfo[i].to) {
1093                         MSG_DEBUG("FIND MSG ID = [%d]", MsgId);
1094 #if 0
1095                         char strTmp[CB_CHANNEL_NAME_MAX + 1];
1096                         memset(strTmp, 0x00, sizeof(strTmp));
1097
1098                         strncpy(strTmp, cbChannelInfo.channelInfo[i].name, CB_CHANNEL_NAME_MAX);
1099
1100                         if (strlen(strTmp) > 0)
1101                                 snprintf(pDisplayName, sizeof(strTmp), "[%s]", strTmp);
1102                         else
1103                                 snprintf(pDisplayName, sizeof(unsigned short), "[%d]", MsgId);
1104 #else
1105
1106 #ifdef MSG_NOTI_INTEGRATION
1107                         snprintf(pDisplayName, MAX_ADDRESS_VAL_LEN + 1, "CB message");
1108 #else
1109                         snprintf(pDisplayName, MAX_ADDRESS_VAL_LEN + 1, "[%d]", MsgId);
1110 #endif
1111
1112 #endif
1113                         return;
1114                 }
1115         }
1116
1117         snprintf(pDisplayName, MAX_ADDRESS_VAL_LEN + 1, "[%d]", MsgId);
1118 }