Merge branch 'tizen_3.0' into tizen
[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] = {0};
209         memcpy(cbData, pCbMsg->szMsgData, pCbMsg->Length);
210         cbData[pCbMsg->Length] = '\0';
211
212         /* print cb data */
213         MSG_INFO("Received CB length:%d", pCbMsg->Length);
214         char cbDataTmp[(pCbMsg->Length*2)+1];
215         memset(cbDataTmp, 0x00, sizeof(cbDataTmp));
216
217         for (int i = 0; i < pCbMsg->Length; i++) {
218                 snprintf(cbDataTmp+(i*2), sizeof(cbDataTmp)-(i*2), "%02X", cbData[i]);
219         }
220         MSG_INFO("[%s]", cbDataTmp);
221
222         pCbPage->cbMsgType = SMS_CBMSG_TYPE_CBS;
223
224         /* Serial Number */
225         pCbPage->pageHeader.serialNum.geoScope = (cbData[0] & 0xC0) >> 6;
226
227         pCbPage->pageHeader.serialNum.msgCode = (cbData[0] & 0x3F) << 4;
228         pCbPage->pageHeader.serialNum.msgCode |= (cbData[1] & 0xF0) >> 4;
229
230         pCbPage->pageHeader.serialNum.updateNum = cbData[1] & 0x0F;
231
232         MSG_DEBUG("geoScope : [%d], msgCode : [%d], updateNum : [%d]", pCbPage->pageHeader.serialNum.geoScope, pCbPage->pageHeader.serialNum.msgCode, pCbPage->pageHeader.serialNum.updateNum);
233
234         pCbPage->pageHeader.msgId = (cbData[2] << 8) | cbData[3];
235
236         MSG_DEBUG("MSG ID : [%d]", pCbPage->pageHeader.msgId);
237
238         /* DCS */
239         decodeCbMsgDCS(cbData[4], (unsigned char*)cbData + 6, &(pCbPage->pageHeader.dcs));
240
241         /* Page Parameter */
242         pCbPage->pageHeader.totalPages = cbData[5] & 0x0F;
243         pCbPage->pageHeader.page = (cbData[5] & 0xF0) >> 4;
244
245         if (pCbPage->pageHeader.totalPages > MAX_CBMSG_PAGE_NUM)
246                 THROW(MsgException::SMS_PLG_ERROR, "CB Page Count is over MAX[%d]", pCbPage->pageHeader.totalPages);
247
248         MSG_DEBUG("Total Page : [%d], Page : [%d]", pCbPage->pageHeader.totalPages, pCbPage->pageHeader.page);
249
250         /* Convert Language Type */
251         convertLangType(pCbPage->pageHeader.dcs.langType, &(pCbPage->pageHeader.langType));
252
253         MSG_DEBUG("In Language Type : [%d], Out Language Type : [%d]", pCbPage->pageHeader.dcs.langType, pCbPage->pageHeader.langType);
254         MSG_DEBUG("iso639Lang : [%s]", pCbPage->pageHeader.dcs.iso639Lang);
255         /* Get Receive Time */
256         pCbPage->pageHeader.recvTime = getRecvTime();
257
258         /* Decode CB Data */
259         int dataLen = pCbMsg->Length - 6;
260
261         MSG_DEBUG("codingScheme:[%d]", pCbPage->pageHeader.dcs.codingScheme);
262
263         switch (pCbPage->pageHeader.dcs.codingScheme) {
264         case SMS_CHARSET_7BIT: {
265                 MSG_DEBUG("GSM 7 BIT");
266
267                 dataLen = (dataLen*8) / 7;
268
269                 SmsPluginUDCodec udCodec;
270                 char pageData[MAX_CBMSG_PAGE_SIZE*8/7] = {0};
271                 int unpackLen = udCodec.unpack7bitChar(&cbData[6], dataLen, 0, pageData);
272
273                 if (pCbPage->pageHeader.dcs.iso639Lang[0]) {
274                         unpackLen = unpackLen - 3;
275                         if (unpackLen > 0)
276                                 memcpy(pCbPage->pageData, &pageData[3], unpackLen);
277                         else
278                                 unpackLen = 0;
279                 } else {
280                         memcpy(pCbPage->pageData, &pageData, unpackLen);
281                 }
282
283                 MSG_DEBUG("unpackLen : [%d]", unpackLen);
284
285                 pCbPage->pageLength = unpackLen;
286                 pCbPage->pageData[unpackLen] = '\0';
287         }
288         break;
289
290         case SMS_CHARSET_8BIT:
291         case SMS_CHARSET_UCS2: {
292                 MSG_DEBUG("UCS2 or 8BIT");
293
294                 if (pCbPage->pageHeader.dcs.iso639Lang[0]) {
295                         memcpy(pCbPage->pageData, &cbData[8], dataLen - 2);
296                         pCbPage->pageLength = dataLen - 2;
297                 } else {
298                         memcpy(pCbPage->pageData, &cbData[6], dataLen);
299                         pCbPage->pageLength = dataLen;
300                 }
301         }
302         break;
303         }
304
305         MSG_DEBUG("Page Length : [%d], Page Data : [%s]", pCbPage->pageLength, pCbPage->pageData);
306 }
307
308
309 void SmsPluginCbMsgHandler::DecodeEtwsMsg(TelSmsEtwsMsg_t *pEtwsMsg, SMS_ETWS_PRIMARY_S *pEtwsPn)
310 {
311         if ( !pEtwsMsg || !pEtwsPn )
312                 return;
313
314         if (pEtwsMsg->Length > MAX_ETWS_SIZE)
315                 THROW(MsgException::SMS_PLG_ERROR, "ETWS Msg Size is over MAX [%d]", pEtwsMsg->Length);
316
317         unsigned char EtwsData[pEtwsMsg->Length+1];
318
319         memset(EtwsData, 0x00, sizeof(EtwsData));
320         memcpy(EtwsData, pEtwsMsg->szMsgData, pEtwsMsg->Length);
321         EtwsData[pEtwsMsg->Length] = '\0';
322
323         /* print received msg data */
324         MSG_INFO("Received Etws length:%d", pEtwsMsg->Length);
325         char EtwsDataTmp[(pEtwsMsg->Length*2)+1];
326         memset(EtwsDataTmp, 0x00, sizeof(EtwsDataTmp));
327
328         for (int i = 0; i < pEtwsMsg->Length; i++) {
329                 snprintf(EtwsDataTmp+(i*2), sizeof(EtwsDataTmp)-(i*2), "%02X", EtwsData[i]);
330         }
331         MSG_INFO("[%s]", EtwsDataTmp);
332
333         /* received time */
334         pEtwsPn->recvTime = getRecvTime();
335
336         /* Serial Number */
337         pEtwsPn->serialNum.geoScope = (EtwsData[0] & 0xC0) >> 6;
338         pEtwsPn->serialNum.msgCode = (EtwsData[0] & 0x3F) << 4;
339         pEtwsPn->serialNum.msgCode |= (EtwsData[1] & 0xF0) >> 4;
340         pEtwsPn->serialNum.updateNum = EtwsData[1] & 0x0F;
341
342         MSG_DEBUG("geoScope : [%d], msgCode : [%d], updateNum : [%d]", pEtwsPn->serialNum.geoScope, pEtwsPn->serialNum.msgCode, pEtwsPn->serialNum.updateNum);
343
344         /* Message Identifier */
345         pEtwsPn->msgId = (EtwsData[2] << 8) | EtwsData[3];
346         MSG_DEBUG("MSG ID : [%d]", pEtwsPn->msgId);
347
348         /* warning type */
349         pEtwsPn->warningType = (EtwsData[4] << 8) | EtwsData[5];
350         MSG_DEBUG("warningType : [0x%04x]", pEtwsPn->msgId);
351
352         /* warning security information */
353         memcpy(pEtwsPn->warningSecurityInfo, &EtwsData[6], sizeof(pEtwsPn->warningSecurityInfo));       /* 50bytes */
354         for (unsigned int i = 0; i < sizeof(pEtwsPn->warningSecurityInfo); i++) {
355                 MSG_DEBUG("warning secu info [%02x]", pEtwsPn->warningSecurityInfo[i]);
356         }
357 }
358
359 void SmsPluginCbMsgHandler::Decode3gCbMsg(TelSmsCbMsg_t *pCbMsg, SMS_CBMSG_PAGE_S *pCbPage)
360 {
361         unsigned char cbData[MAX_CBMSG_TOTAL_PAGE_SIZE + 1] = {0};
362         memcpy(cbData, pCbMsg->szMsgData, pCbMsg->Length);
363         cbData[pCbMsg->Length] = '\0';
364
365         /* print cb data */
366         MSG_INFO("Received CB length:%d", pCbMsg->Length);
367         char cbDataTmp[(pCbMsg->Length*2)+1];
368         memset(cbDataTmp, 0x00, sizeof(cbDataTmp));
369
370         for (int i = 0; i < pCbMsg->Length; i++) {
371                 snprintf(cbDataTmp+(i*2), sizeof(cbDataTmp)-(i*2), "%02X", cbData[i]);
372         }
373         MSG_INFO("[%s]", cbDataTmp);
374
375         pCbPage->cbMsgType = (SMS_CBMSG_TYPE_T)cbData[0];
376
377         pCbPage->pageHeader.msgId = (cbData[1] << 8) | cbData[2];
378
379         MSG_DEBUG("MSG ID : [%d]", pCbPage->pageHeader.msgId);
380
381         /* Serial Number */
382         pCbPage->pageHeader.serialNum.geoScope = (cbData[3] & 0xC0) >> 6;
383
384         pCbPage->pageHeader.serialNum.msgCode = (cbData[3] & 0x3F) << 4;
385         pCbPage->pageHeader.serialNum.msgCode |= (cbData[4] & 0xF0) >> 4;
386
387         pCbPage->pageHeader.serialNum.updateNum = cbData[4] & 0x0F;
388
389         MSG_DEBUG("geoScope : [%d], msgCode : [%d], updateNum : [%d]", pCbPage->pageHeader.serialNum.geoScope, pCbPage->pageHeader.serialNum.msgCode, pCbPage->pageHeader.serialNum.updateNum);
390
391         /* DCS */
392         decodeCbMsgDCS(cbData[5], (unsigned char*)cbData + 6, &(pCbPage->pageHeader.dcs));
393
394         /* Convert Language Type */
395         convertLangType(pCbPage->pageHeader.dcs.langType, &(pCbPage->pageHeader.langType));
396
397         MSG_DEBUG("In Language Type : [%d], Out Language Type : [%d]", pCbPage->pageHeader.dcs.langType, pCbPage->pageHeader.langType);
398
399         /* Get Receive Time */
400         pCbPage->pageHeader.recvTime = getRecvTime();
401         pCbPage->pageHeader.totalPages = cbData[6];
402
403         /* Decode CB Data */
404         int dataLen = 0;
405         int offset = 0;
406
407         switch (pCbPage->pageHeader.dcs.codingScheme) {
408         case SMS_CHARSET_7BIT: {
409                 for (int i = 0; i < pCbPage->pageHeader.totalPages; ++i) {
410                         unsigned char cbMessage[MAX_CBMSG_PAGE_SIZE] = {0};
411                         dataLen = cbData[7 + (i + 1) * MAX_CBMSG_PAGE_SIZE + i];
412
413                         if (dataLen > MAX_CBMSG_PAGE_SIZE)
414                                 THROW(MsgException::SMS_PLG_ERROR, "CB Msg Size is over MAX [%d]", dataLen);
415
416                         memcpy(cbMessage, &cbData[7+(i*MAX_CBMSG_PAGE_SIZE)+ i], dataLen);
417                         dataLen = (dataLen*8) / 7;
418
419                         SmsPluginUDCodec udCodec;
420                         int unpackLen = udCodec.unpack7bitChar((const unsigned char *)cbMessage, dataLen, 0, pCbPage->pageData + offset);
421                         offset += unpackLen;
422                 }
423                 pCbPage->pageLength = offset;
424         }
425         break;
426
427         case SMS_CHARSET_8BIT:
428         case SMS_CHARSET_UCS2: {
429 #if 0
430                 char cbMessage[MAX_CBMSG_PAGE_SIZE]= {0, };
431
432                 for (int i = 0; i < pCbPage->pageHeader.totalPages; ++i) {
433                         dataLen = cbData[7+(i+1)*MAX_CBMSG_PAGE_SIZE + i];
434                         memcpy(cbMessage + offset, &cbData[7+(i*MAX_CBMSG_PAGE_SIZE)+ i], dataLen);
435                         offset += dataLen;
436                 }
437                 dataLen = offset;
438
439                 if (pCbPage->pageHeader.dcs.iso639Lang[0]) {
440                         int tmpDataLen = (dataLen > 2)?(dataLen - 2):0;
441                         memcpy(pCbPage->pageData, cbMessage + 2, tmpDataLen);
442                         pCbPage->pageLength = tmpDataLen;
443                 } else {
444                         memcpy(pCbPage->pageData, cbMessage, dataLen);
445                         pCbPage->pageLength = dataLen;
446                 }
447 #else
448                 char cbMessage[MAX_CBMSG_PAGE_SIZE*MAX_CBMSG_PAGE_NUM+1] = {0, };
449
450                 for (int i = 0; i < pCbPage->pageHeader.totalPages; ++i) {
451                         if (pCbPage->pageHeader.dcs.iso639Lang[0]) {
452                                 dataLen = cbData[7+(i+1)*MAX_CBMSG_PAGE_SIZE + i] - 2;
453                                 if (dataLen > 0) {
454                                         memcpy(cbMessage + offset, &cbData[7+(i*MAX_CBMSG_PAGE_SIZE)+ i + 2], dataLen);
455                                         offset += dataLen;
456                                 }
457                         } else {
458                                 dataLen = cbData[7+(i+1)*MAX_CBMSG_PAGE_SIZE + i];
459                                 if (dataLen > 0) {
460                                         memcpy(cbMessage + offset, &cbData[7+(i*MAX_CBMSG_PAGE_SIZE)+ i], dataLen);
461                                         offset += dataLen;
462                                 }
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         if (MsgSettingGetBool(keyName, &bReceive) != MSG_SUCCESS)
546                 MSG_INFO("MsgSettingGetBool() is failed");
547
548         /* Receive CB Msg = FALSE */
549         if (!bReceive) {
550                 MSG_DEBUG("RECEIVE CB = FALSE");
551                 return false;
552         }
553
554 #if 0
555         char keyname[128];
556         /* check Language */
557         memset(keyName, 0x00, sizeof(keyName));
558         snprintf(keyName, sizeof(keyname), "%s/%d", CB_LANGUAGE, MSG_CBLANG_TYPE_ALL);
559
560         bool bAllLang = false;
561         if (MsgSettingGetBool(keyName, &bAllLang) != MSG_SUCCESS)
562                 MSG_INFO("MsgSettingGetBool() is failed");
563
564         if (!bAllLang) {
565                 MSG_DEBUG("ALL LANGUAGE = FALSE");
566
567                 memset(keyName, 0x00, sizeof(keyName));
568                 snprintf(keyName, sizeof(keyname), "%s/%d", CB_LANGUAGE, CbPage.pageHeader.langType);
569
570                 bool bLang = false;
571
572                 if (MsgSettingGetBool(keyName, &bLang) != MSG_SUCCESS)
573                         MSG_INFO("MsgSettingGetBool() is failed");
574
575                 if (!bLang || CbPage.pageHeader.langType == MSG_CBLANG_TYPE_MAX) {
576                         MSG_DEBUG("LANGUAGE [%d] = FALSE", CbPage.pageHeader.langType);
577                         return false;
578                 }
579         }
580 #endif
581
582         bool bActivate = false;
583         int MsgId_from = 0, MsgId_to = 0;
584         MSG_CB_CHANNEL_S cbChannelInfo = {0, };
585         msg_error_t err = MSG_SUCCESS;
586         MsgDbHandler *dbHandle = getDbHandle();
587
588         err = MsgStoGetCBChannelInfo(dbHandle, &cbChannelInfo, simIndex);
589         if (err != MSG_SUCCESS)
590                 MSG_ERR("Error value of MsgStoGetCBChannelInfo [%d]", err);
591
592         for (int i = 0; i < cbChannelInfo.channelCnt; i++) {
593                 bActivate = cbChannelInfo.channelInfo[i].bActivate;
594                 MsgId_from = cbChannelInfo.channelInfo[i].from;
595                 MsgId_to = cbChannelInfo.channelInfo[i].to;
596
597                 if (bActivate == true && CbPage->pageHeader.msgId >= MsgId_from && CbPage->pageHeader.msgId <= MsgId_to) {
598                         MSG_DEBUG("FIND CHANNEL = [%d]", CbPage->pageHeader.msgId);
599                         return true;
600                 }
601         }
602
603         return false;
604 }
605
606 unsigned char SmsPluginCbMsgHandler::checkCbPage(SMS_CBMSG_PAGE_S *CbPage)
607 {
608         unsigned char currPageCnt = 0;
609
610         bool bFind = false;
611
612 #if 0
613         msg_error_t err = MSG_SUCCESS;
614
615         SmsPluginStorage *storageHandler = SmsPluginStorage::instance();
616         err = storageHandler->isReceivedCBMessage(CbPage);
617
618         /* check existing message with cb internal table; */
619         if (err != MSG_ERR_DB_NORECORD) {
620                 MSG_DEBUG("already received message: [%d]", CbPage.pageHeader.msgId);
621                 return 0;
622         }
623 #endif
624
625         if (CbPage->pageHeader.totalPages > 0) {
626                 for (unsigned int i = 0; i < pageList.size(); i++) {
627                         if (pageList[i].geoScope == CbPage->pageHeader.serialNum.geoScope && pageList[i].msgCode == CbPage->pageHeader.serialNum.msgCode) {
628                                 MSG_DEBUG("geoScope [%d], msgCode [%d]", pageList[i].geoScope, pageList[i].msgCode);
629
630                                 if (pageList[i].msgId == CbPage->pageHeader.msgId) {
631                                         int updateNum = CbPage->pageHeader.serialNum.updateNum - pageList[i].updateNum;
632
633                                         if (updateNum > 0) { /* New Message Content */
634                                                 break;
635                                         } else if (updateNum == 0) { /* Same Message Content */
636                                                 if (pageList[i].data.count(CbPage->pageHeader.page) != 0) {
637                                                         MSG_DEBUG("The Page Number already exists [%d]", CbPage->pageHeader.page);
638                                                         return 0;
639                                                 }
640
641                                                 pair<unsigned char, SMS_CBMSG_PAGE_S> newData(CbPage->pageHeader.page, *CbPage);
642                                                 pageList[i].data.insert(newData);
643
644                                                 MSG_DEBUG("PAGE DATA : %s", CbPage->pageData);
645                                                 MSG_DEBUG("PAIR DATA [%d] : %s", newData.first, newData.second.pageData);
646
647                                                 pageList[i].pageCnt++;
648                                                 pageList[i].totalSize += CbPage->pageLength;
649
650                                                 currPageCnt = pageList[i].pageCnt;
651
652                                                 bFind = true;
653
654                                                 break;
655                                         } else { /* Old Message Content */
656                                                 return 0;
657                                         }
658                                 }
659                         }
660                 }
661         }
662
663         if (bFind == false || CbPage->pageHeader.totalPages == 1) {
664                 addToPageList(CbPage);
665                 return 1;
666         }
667
668         return currPageCnt;
669 }
670
671
672 void SmsPluginCbMsgHandler::MakeCbMsg(SMS_CBMSG_PAGE_S *CbPage, SMS_CBMSG_S *pCbMsg)
673 {
674         pCbMsg->cbMsgType = CbPage->cbMsgType;
675         pCbMsg->msgId = CbPage->pageHeader.msgId;
676         pCbMsg->classType = CbPage->pageHeader.dcs.classType;
677         pCbMsg->codingScheme = CbPage->pageHeader.dcs.codingScheme;
678         pCbMsg->recvTime = CbPage->pageHeader.recvTime;
679
680         cbPageMap::iterator it;
681         int offset = 0;
682
683         for (unsigned int i = 0; i < pageList.size(); i++) {
684                 if (pageList[i].geoScope == CbPage->pageHeader.serialNum.geoScope && pageList[i].msgCode == CbPage->pageHeader.serialNum.msgCode) {
685                         MSG_DEBUG("geoScope [%d], msgCode [%d]", pageList[i].geoScope, pageList[i].msgCode);
686
687                         if (pageList[i].msgId == CbPage->pageHeader.msgId) {
688                                 for (it = pageList[i].data.begin(); it != pageList[i].data.end(); it++) {
689                                         memcpy(pCbMsg->msgData + offset, it->second.pageData, it->second.pageLength);
690                                         pCbMsg->msgLength += it->second.pageLength;
691                                         offset = pCbMsg->msgLength;
692                                 }
693                         }
694                 }
695         }
696
697 #if 0
698         pCbMsg->msgLength = tmpStr.size();
699
700         memcpy(pCbMsg->msgData, tmpStr.c_str(), tmpStr.size());
701         pCbMsg->msgData[tmpStr.size()] = '\0';
702
703         MSG_DEBUG("SIZE : [%d] TOTAL MSG : %s", tmpStr.size(), tmpStr.c_str());
704 #endif
705 }
706
707
708 void SmsPluginCbMsgHandler::convertCbMsgToMsginfo(SMS_CBMSG_S *pCbMsg, MSG_MESSAGE_INFO_S *pMsgInfo, msg_sim_slot_id_t simIndex)
709 {
710         pMsgInfo->msgId = (msg_message_id_t)pCbMsg->msgId;
711
712         pMsgInfo->folderId = MSG_CBMSGBOX_ID;
713
714         /* Convert Type values */
715         pMsgInfo->msgType.mainType = MSG_SMS_TYPE;
716
717         if (pCbMsg->cbMsgType == SMS_CBMSG_TYPE_CBS) {
718                 int cmas_class = CMAS_class(pCbMsg->msgId);
719
720                 if (cmas_class == 0)
721                         pMsgInfo->msgType.subType = MSG_CB_SMS;
722                 else
723                         pMsgInfo->msgType.subType = (MSG_SUB_TYPE_T)cmas_class;
724         } else if (pCbMsg->cbMsgType == SMS_CBMSG_TYPE_JAVACBS) {
725                 pMsgInfo->msgType.subType = MSG_JAVACB_SMS;
726         }
727
728         switch (pCbMsg->classType) {
729         case SMS_MSG_CLASS_0:
730                 pMsgInfo->msgType.classType = MSG_CLASS_0;
731                 break;
732         case SMS_MSG_CLASS_1:
733                 pMsgInfo->msgType.classType = MSG_CLASS_1;
734                 break;
735         case SMS_MSG_CLASS_2:
736                 pMsgInfo->msgType.classType = MSG_CLASS_2;
737                 break;
738         case SMS_MSG_CLASS_3:
739                 pMsgInfo->msgType.classType = MSG_CLASS_3;
740                 break;
741         default:
742                 pMsgInfo->msgType.classType = MSG_CLASS_NONE;
743                 break;
744         }
745
746         pMsgInfo->storageId = MSG_STORAGE_PHONE;
747         pMsgInfo->networkStatus = MSG_NETWORK_RECEIVED;
748         pMsgInfo->bRead = false;
749         pMsgInfo->bProtected = false;
750         pMsgInfo->priority = MSG_MESSAGE_PRIORITY_NORMAL;
751         pMsgInfo->direction = MSG_DIRECTION_TYPE_MT;
752
753         /* Temporary */
754         pMsgInfo->nAddressCnt = 1;
755
756         pMsgInfo->addressList =  (MSG_ADDRESS_INFO_S *)new char[sizeof(MSG_ADDRESS_INFO_S)];
757         memset(pMsgInfo->addressList, 0x00, sizeof(MSG_ADDRESS_INFO_S));
758
759         pMsgInfo->addressList[0].addressType = MSG_ADDRESS_TYPE_UNKNOWN;
760         pMsgInfo->addressList[0].recipientType = MSG_RECIPIENTS_TYPE_UNKNOWN;
761         pMsgInfo->sim_idx = simIndex;
762
763         /*      TODO :: MSG ID should be used to get CB message type */
764         getDisplayName(pCbMsg->msgId, pMsgInfo->addressList[0].addressVal, simIndex);
765         MSG_SEC_DEBUG("%s", pMsgInfo->addressList[0].addressVal);
766
767
768         pMsgInfo->msgPort.valid = false;
769         pMsgInfo->msgPort.dstPort = 0;
770         pMsgInfo->msgPort.srcPort = 0;
771
772         pMsgInfo->displayTime = pCbMsg->recvTime;
773         MSG_DEBUG("recvTime is %d", pMsgInfo->displayTime);
774
775         int bufSize = pCbMsg->msgLength*2;
776
777         char tmpBuf[bufSize];
778         memset(tmpBuf, 0x00, sizeof(tmpBuf));
779
780         while (pCbMsg->msgLength > 0) {
781                 if (pCbMsg->msgData[pCbMsg->msgLength-1] == ' ' ||
782                                 pCbMsg->msgData[pCbMsg->msgLength-1] == '\r' ||
783                                 pCbMsg->msgData[pCbMsg->msgLength-1] == '\n') {
784                         pCbMsg->msgLength--;
785                 } else {
786                         break;
787                 }
788         }
789         pCbMsg->msgData[pCbMsg->msgLength] = '\0';
790
791         MSG_DEBUG("LENGTH %d CB MSG %s", pCbMsg->msgLength, pCbMsg->msgData);
792
793         /* Convert Data values */
794         pMsgInfo->dataSize = convertTextToUtf8((unsigned char*)tmpBuf, bufSize, pCbMsg);
795
796         if (pMsgInfo->dataSize > MAX_MSG_TEXT_LEN) {
797                 pMsgInfo->bTextSms = false;
798
799                 /* Save Message Data into File */
800                 char fileName[MSG_FILENAME_LEN_MAX+1];
801                 memset(fileName, 0x00, sizeof(fileName));
802
803                 if (MsgCreateFileName(fileName) == false)
804                         THROW(MsgException::FILE_ERROR, "MsgCreateFileName error");
805
806                 MSG_SEC_DEBUG("Save Message Data into file : size[%d] name[%s]\n", pMsgInfo->dataSize, fileName);
807                 if (MsgWriteIpcFile(fileName, tmpBuf, pMsgInfo->dataSize) == false)
808                         THROW(MsgException::FILE_ERROR, "MsgWriteIpcFile error");
809
810                 strncpy(pMsgInfo->msgData, fileName, MAX_MSG_DATA_LEN);
811         } else {
812                 pMsgInfo->bTextSms = true;
813
814                 memset(pMsgInfo->msgText, 0x00, sizeof(pMsgInfo->msgText));
815                 memcpy(pMsgInfo->msgText, tmpBuf, pMsgInfo->dataSize);
816                 pMsgInfo->dataSize = strlen(pMsgInfo->msgText);
817                 MSG_SEC_DEBUG("CB MSG %s", pMsgInfo->msgText);
818         }
819 }
820
821
822 void SmsPluginCbMsgHandler::convertEtwsMsgToMsginfo(SMS_CBMSG_PAGE_S *EtwsMsg, MSG_MESSAGE_INFO_S *pMsgInfo, msg_sim_slot_id_t simIndex)
823 {
824         pMsgInfo->msgId = (msg_message_id_t)EtwsMsg->pageHeader.msgId;
825
826         pMsgInfo->folderId = MSG_CBMSGBOX_ID;
827
828         /* Convert Type values */
829         pMsgInfo->msgType.mainType = MSG_SMS_TYPE;
830
831         if (EtwsMsg->cbMsgType == SMS_CBMSG_TYPE_ETWS)
832                 pMsgInfo->msgType.subType = MSG_ETWS_SMS;
833
834         pMsgInfo->storageId = MSG_STORAGE_PHONE;
835         pMsgInfo->networkStatus = MSG_NETWORK_RECEIVED;
836         pMsgInfo->bRead = false;
837         pMsgInfo->bProtected = false;
838         pMsgInfo->priority = MSG_MESSAGE_PRIORITY_NORMAL;
839         pMsgInfo->direction = MSG_DIRECTION_TYPE_MT;
840
841         /* Temporary */
842         pMsgInfo->nAddressCnt = 1;
843
844         pMsgInfo->addressList[0].addressType = MSG_ADDRESS_TYPE_UNKNOWN;
845         pMsgInfo->addressList[0].recipientType = MSG_RECIPIENTS_TYPE_UNKNOWN;
846
847         getDisplayName(EtwsMsg->pageHeader.msgId, pMsgInfo->addressList[0].addressVal, simIndex);
848         MSG_SEC_DEBUG("%s", pMsgInfo->addressList[0].addressVal);
849
850         pMsgInfo->msgPort.valid = false;
851         pMsgInfo->msgPort.dstPort = 0;
852         pMsgInfo->msgPort.srcPort = 0;
853
854         pMsgInfo->displayTime = EtwsMsg->pageHeader.recvTime;
855         MSG_DEBUG("recvTime is %d", pMsgInfo->displayTime);
856         MSG_DEBUG("LENGTH %d", EtwsMsg->pageLength);
857         pMsgInfo->bTextSms = true;
858         pMsgInfo->dataSize = EtwsMsg->pageLength;
859         memset(pMsgInfo->msgData, 0x00, sizeof(pMsgInfo->msgData));
860         memcpy(pMsgInfo->msgData, EtwsMsg->pageData, pMsgInfo->dataSize);
861 }
862
863 int SmsPluginCbMsgHandler::convertTextToUtf8(unsigned char* outBuf, int outBufSize, SMS_CBMSG_S* pCbMsg)
864 {
865         int     convertedTextSize = 0;
866         MSG_LANG_INFO_S langInfo = {0, };
867
868         MsgTextConvert *textCvt = MsgTextConvert::instance();
869
870         if (!outBuf || !pCbMsg) {
871                 MSG_DEBUG("invalid param.\n");
872                 return 0;
873         }
874
875         langInfo.bSingleShift = false;
876         langInfo.bLockingShift = false;
877
878
879         /* Convert Data values */
880         if (pCbMsg->codingScheme == SMS_CHARSET_7BIT)
881                 convertedTextSize = textCvt->convertGSM7bitToUTF8(outBuf, outBufSize, (unsigned char*)pCbMsg->msgData, pCbMsg->msgLength, &langInfo);
882         else if (pCbMsg->codingScheme == SMS_CHARSET_UCS2)
883                 convertedTextSize = textCvt->convertUCS2ToUTF8(outBuf, outBufSize, (unsigned char*)pCbMsg->msgData, pCbMsg->msgLength);
884
885         return convertedTextSize;
886 }
887
888 void SmsPluginCbMsgHandler::addToPageList(SMS_CBMSG_PAGE_S *CbPage)
889 {
890         CB_PAGE_INFO_S tmpInfo;
891
892         tmpInfo.geoScope = CbPage->pageHeader.serialNum.geoScope;
893         tmpInfo.msgCode = CbPage->pageHeader.serialNum.msgCode;
894         tmpInfo.updateNum = CbPage->pageHeader.serialNum.updateNum;
895         tmpInfo.msgId = CbPage->pageHeader.msgId;
896         tmpInfo.totalPages = CbPage->pageHeader.totalPages;
897
898         tmpInfo.pageCnt = 1;
899         tmpInfo.totalSize = CbPage->pageLength;
900
901         pair<unsigned char, SMS_CBMSG_PAGE_S> newData(CbPage->pageHeader.page, *CbPage);
902         tmpInfo.data.insert(newData);
903
904         MSG_DEBUG("MSG DATA : %s", CbPage->pageData);
905         MSG_DEBUG("PAIR DATA [%d] : %s", newData.first, newData.second.pageData);
906
907         pageList.push_back(tmpInfo);
908 }
909
910
911 void SmsPluginCbMsgHandler::removeFromPageList(SMS_CBMSG_PAGE_S *CbPage)
912 {
913         unsigned int index;
914
915         for (index = 0; index < pageList.size(); index++) {
916                 if (pageList[index].geoScope == CbPage->pageHeader.serialNum.geoScope && pageList[index].msgCode == CbPage->pageHeader.serialNum.msgCode) {
917                         MSG_DEBUG("geoScope [%d], msgCode [%d]", pageList[index].geoScope, pageList[index].msgCode);
918
919                         if (pageList[index].msgId == CbPage->pageHeader.msgId)
920                                 break;
921                 }
922         }
923
924         MSG_DEBUG("remove index [%d]", index);
925
926         pageList.erase(pageList.begin()+index);
927 }
928
929
930 void SmsPluginCbMsgHandler::decodeCbMsgDCS(unsigned char dcsData, const unsigned char *pMsgData, SMS_CBMSG_DCS_S* pDcs)
931 {
932         pDcs->codingGroup = SMS_CBMSG_CODGRP_GENERAL_DCS;
933         pDcs->classType = SMS_MSG_CLASS_NONE;
934         pDcs->bCompressed = false;
935         pDcs->codingScheme = SMS_CHARSET_7BIT;
936         pDcs->langType = SMS_CBMSG_LANG_UNSPECIFIED;
937         memset(pDcs->iso639Lang, 0x00, sizeof(pDcs->iso639Lang));
938         pDcs->bUDH = false;
939         pDcs->rawData = dcsData;
940
941         unsigned char codingGrp = (dcsData & 0xF0) >> 4;
942
943         switch (codingGrp) {
944         case 0x00:
945         case 0x02:
946         case 0x03: {
947                 pDcs->codingGroup = SMS_CBMSG_CODGRP_GENERAL_DCS;
948                 pDcs->langType = (SMS_CBMSG_LANG_TYPE_T)dcsData;
949         }
950         break;
951
952         case 0x01: {
953                 if (dcsData == 0x10 || dcsData == 0x11) {
954                         pDcs->codingGroup = SMS_CBMSG_CODGRP_GENERAL_DCS;
955                         pDcs->codingScheme = (dcsData & 0x01) ? SMS_CHARSET_UCS2 : SMS_CHARSET_7BIT;
956                         pDcs->langType = SMS_CBMSG_LANG_ISO639;
957                         MSG_DEBUG("codingScheme: [%d]", pDcs->codingScheme);
958                         if (pMsgData[0] && pMsgData[1]) {
959                                 pDcs->iso639Lang[0] = pMsgData[0] & 0x7F;
960                                 pDcs->iso639Lang[1] = (pMsgData[0] & 0X80) >> 7;
961                                 pDcs->iso639Lang[1] |= (pMsgData[1] & 0X3F) << 1;
962                                 pDcs->iso639Lang[2] = 0x13;  /* CR */
963                         } else {
964                                 /* Default it to English if pMsgData is NULL */
965                                 pDcs->iso639Lang[0] = 0x45;  /* E */
966                                 pDcs->iso639Lang[1] = 0x4E;  /* N */
967                                 pDcs->iso639Lang[2] = 0x13;  /* CR */
968                         }
969                 }
970         }
971         break;
972
973         case 0x04:
974         case 0x05:
975         case 0x06:
976         case 0x07: {
977                 pDcs->codingGroup = SMS_CBMSG_CODGRP_GENERAL_DCS;
978
979                 pDcs->bCompressed = (dcsData & 0x20) ? true : false;
980
981                 if (dcsData & 0x10)
982                         pDcs->classType = (SMS_MSG_CLASS_T)(dcsData & 0x03);
983
984                 unsigned char tmpScheme = (dcsData & 0x0C) >> 2;
985
986                 switch (tmpScheme) {
987                 case 0x00:
988                         pDcs->codingScheme = SMS_CHARSET_7BIT;
989                         break;
990                 case 0x01:
991                         pDcs->codingScheme = SMS_CHARSET_8BIT;
992                         break;
993                 case 0x02:
994                         pDcs->codingScheme = SMS_CHARSET_UCS2;
995                         break;
996                 default:
997                         MSG_DEBUG("tmpScheme: [%d]", tmpScheme);
998                         break;
999                 }
1000         }
1001         break;
1002
1003         case 0x09: {
1004                 pDcs->bUDH = true;
1005                 pDcs->classType = (MSG_CLASS_TYPE_T)(dcsData & 0x03);
1006                 pDcs->codingScheme = (SMS_CODING_SCHEME_T)((dcsData & 0x0C) >> 2);
1007         }
1008         break;
1009
1010         case 0x0E: {
1011                 pDcs->codingGroup = SMS_CBMSG_CODGRP_WAP;
1012         }
1013         break;
1014
1015         case 0x0F: {
1016                 pDcs->codingGroup = SMS_CBMSG_CODGRP_CLASS_CODING;
1017                 pDcs->codingScheme = (dcsData & 0x04) ? SMS_CHARSET_8BIT : SMS_CHARSET_7BIT;
1018                 pDcs->classType = (MSG_CLASS_TYPE_T)(dcsData & 0x03);
1019         }
1020         break;
1021         default:
1022                 MSG_DEBUG("codingGrp: [0x%x]", codingGrp);
1023                 break;
1024         }
1025 }
1026
1027
1028 void SmsPluginCbMsgHandler::convertLangType(SMS_CBMSG_LANG_TYPE_T InType , MSG_CB_LANGUAGE_TYPE_T *pOutType)
1029 {
1030         switch (InType) {
1031         case SMS_CBMSG_LANG_GERMAN :
1032                 *pOutType = MSG_CBLANG_TYPE_GER;
1033                 break;
1034
1035         case SMS_CBMSG_LANG_ENGLISH :
1036                 *pOutType = MSG_CBLANG_TYPE_ENG;
1037                 break;
1038
1039         case SMS_CBMSG_LANG_ITALIAN :
1040                 *pOutType = MSG_CBLANG_TYPE_ITA;
1041                 break;
1042
1043         case SMS_CBMSG_LANG_FRENCH :
1044                 *pOutType = MSG_CBLANG_TYPE_FRE;
1045                 break;
1046
1047         case SMS_CBMSG_LANG_SPANISH :
1048                 *pOutType = MSG_CBLANG_TYPE_SPA;
1049                 break;
1050
1051         case SMS_CBMSG_LANG_DUTCH :
1052                 *pOutType = MSG_CBLANG_TYPE_NED;
1053                 break;
1054
1055         case SMS_CBMSG_LANG_SWEDISH :
1056                 *pOutType = MSG_CBLANG_TYPE_SWE;
1057                 break;
1058
1059         case SMS_CBMSG_LANG_PORTUGUESE :
1060                 *pOutType = MSG_CBLANG_TYPE_POR;
1061                 break;
1062
1063         case SMS_CBMSG_LANG_TURKISH :
1064                 *pOutType = MSG_CBLANG_TYPE_TUR;
1065                 break;
1066
1067         default :
1068                 *pOutType = MSG_CBLANG_TYPE_MAX;
1069                 break;
1070         }
1071 }
1072
1073
1074 unsigned long SmsPluginCbMsgHandler::getRecvTime()
1075 {
1076         time_t recvTime;
1077
1078         recvTime = time(NULL);
1079
1080         return (unsigned long)recvTime;
1081 }
1082
1083
1084 void SmsPluginCbMsgHandler::getDisplayName(unsigned short       MsgId, char *pDisplayName, msg_sim_slot_id_t simIndex)
1085 {
1086         MSG_CB_CHANNEL_S cbChannelInfo = {0, };
1087         msg_error_t err = MSG_SUCCESS;
1088         MsgDbHandler *dbHandle = getDbHandle();
1089
1090         err = MsgStoGetCBChannelInfo(dbHandle, &cbChannelInfo, simIndex);
1091         MSG_DEBUG("MsgStoGetCBChannelInfo [err = %d]", err);
1092
1093         for (int i = 0; i < cbChannelInfo.channelCnt; i++) {
1094                 if (MsgId >= cbChannelInfo.channelInfo[i].from && MsgId <= cbChannelInfo.channelInfo[i].to) {
1095                         MSG_DEBUG("FIND MSG ID = [%d]", MsgId);
1096 #if 0
1097                         char strTmp[CB_CHANNEL_NAME_MAX + 1];
1098                         memset(strTmp, 0x00, sizeof(strTmp));
1099
1100                         strncpy(strTmp, cbChannelInfo.channelInfo[i].name, CB_CHANNEL_NAME_MAX);
1101
1102                         if (strlen(strTmp) > 0)
1103                                 snprintf(pDisplayName, sizeof(strTmp), "[%s]", strTmp);
1104                         else
1105                                 snprintf(pDisplayName, sizeof(unsigned short), "[%d]", MsgId);
1106 #else
1107
1108 #ifdef MSG_NOTI_INTEGRATION
1109                         snprintf(pDisplayName, MAX_ADDRESS_VAL_LEN + 1, "CB message");
1110 #else
1111                         snprintf(pDisplayName, MAX_ADDRESS_VAL_LEN + 1, "[%d]", MsgId);
1112 #endif
1113
1114 #endif
1115                         return;
1116                 }
1117         }
1118
1119         snprintf(pDisplayName, MAX_ADDRESS_VAL_LEN + 1, "[%d]", MsgId);
1120 }