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