Sync with tizen 2.4
[platform/core/messaging/msg-service.git] / plugin / sms_plugin / SmsPluginEventHandler.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 #include<stdio.h>
19 #include<stdlib.h>
20 #include <errno.h>
21
22 #include "MsgDebug.h"
23 #include "MsgUtilFile.h"
24 #include "MsgCppTypes.h"
25 #include "MsgContact.h"
26 #include "MsgGconfWrapper.h"
27 #include "MsgNotificationWrapper.h"
28 #include "MsgDevicedWrapper.h"
29 #include "SmsPluginTransport.h"
30 #include "SmsPluginSimMsg.h"
31 #include "SmsPluginStorage.h"
32 #include "SmsPluginSetting.h"
33 #include "SmsPluginConcatHandler.h"
34 #include "SmsPluginEventHandler.h"
35 #include "SmsPluginDSHandler.h"
36
37
38 /*==================================================================================================
39                                      IMPLEMENTATION OF SmsPluginEventHandler - Member Functions
40 ==================================================================================================*/
41 SmsPluginEventHandler* SmsPluginEventHandler::pInstance = NULL;
42
43
44 SmsPluginEventHandler::SmsPluginEventHandler()
45 {
46         /**  Initialize global parameters */
47         memset(&listener, 0x00, sizeof(MSG_PLUGIN_LISTENER_S));
48
49         pSimCnt = NULL;
50         devStatus = false;
51         bUdhMwiMethod = false;
52         udhMwiCnt = 0;
53         devHandle = NULL;
54 }
55
56
57 SmsPluginEventHandler::~SmsPluginEventHandler()
58 {
59
60 }
61
62
63 SmsPluginEventHandler* SmsPluginEventHandler::instance()
64 {
65         if (!pInstance)
66                 pInstance = new SmsPluginEventHandler();
67
68         return pInstance;
69 }
70
71
72 void SmsPluginEventHandler::registerListener(MSG_PLUGIN_LISTENER_S *pListener)
73 {
74         listener = *pListener;
75 }
76
77
78 void SmsPluginEventHandler::handleSentStatus(msg_network_status_t NetStatus)
79 {
80         MSG_DEBUG("NetStatus[%d]", NetStatus);
81
82         if (sentInfo.bLast == true || NetStatus != MSG_NETWORK_SEND_SUCCESS) {
83                 /** Update Msg Status */
84                 if (sentInfo.reqInfo.msgInfo.msgPort.valid == false) {
85 //                      SmsPluginStorage::instance()->updateSentMsg(&(sentInfo.reqInfo.msgInfo), NetStatus);
86
87                         sentInfo.reqInfo.msgInfo.networkStatus = NetStatus;
88
89                         if (NetStatus == MSG_NETWORK_SEND_SUCCESS) {
90                                 //contacts-service is not used for gear
91 #ifndef MSG_CONTACTS_SERVICE_NOT_SUPPORTED
92                                 MSG_DEBUG("Add phone log");
93                                 MsgAddPhoneLog(&(sentInfo.reqInfo.msgInfo));
94 #endif //MSG_CONTACTS_SERVICE_NOT_SUPPORTED
95                                 sentInfo.reqInfo.msgInfo.folderId = MSG_SENTBOX_ID; // It should be set after adding phone log.
96                         } else {
97                                 sentInfo.reqInfo.msgInfo.bRead = false;
98                         }
99
100                         callbackStorageChange(MSG_STORAGE_CHANGE_UPDATE, &(sentInfo.reqInfo.msgInfo));
101                 }
102
103                 MSG_DEBUG("sentInfo.reqInfo.sendOptInfo.bSetting [%d]", sentInfo.reqInfo.sendOptInfo.bSetting);
104                 MSG_DEBUG("sentInfo.reqInfo.sendOptInfo.bKeepCopy [%d]", sentInfo.reqInfo.sendOptInfo.bKeepCopy);
105                 /** Check sending options */
106                 if (sentInfo.reqInfo.sendOptInfo.bSetting && !sentInfo.reqInfo.sendOptInfo.bKeepCopy && NetStatus == MSG_NETWORK_SEND_SUCCESS) {
107 //                      SmsPluginStorage::instance()->deleteSmsMessage(sentInfo.reqInfo.msgInfo.msgId);
108                         callbackStorageChange(MSG_STORAGE_CHANGE_DELETE, &(sentInfo.reqInfo.msgInfo));
109                 }
110
111                 /** Callback to MSG FW */
112                 MSG_SENT_STATUS_S msgStatus;
113
114                 msgStatus.reqId = sentInfo.reqInfo.reqId;
115                 msgStatus.status = NetStatus;
116
117                 MSG_DEBUG("sentStatus.reqId : %d", msgStatus.reqId);
118                 MSG_DEBUG("sentStatus.status : %d", msgStatus.status);
119
120                 listener.pfSentStatusCb(&msgStatus);
121         }
122 }
123
124
125 void SmsPluginEventHandler::handleMsgIncoming(struct tapi_handle *handle, SMS_TPDU_S *pTpdu)
126 {
127
128         /** Make MSG_MESSAGE_INFO_S */
129         MSG_MESSAGE_INFO_S msgInfo;
130
131         /** initialize msgInfo */
132         memset(&msgInfo, 0x00, sizeof(MSG_MESSAGE_INFO_S));
133
134         msgInfo.addressList = NULL;
135         AutoPtr<MSG_ADDRESS_INFO_S> addressListBuf(&msgInfo.addressList);
136
137
138         if (pTpdu->tpduType == SMS_TPDU_DELIVER) {
139                 /** check unsupported message */
140                 if (pTpdu->data.deliver.dcs.codingScheme == SMS_CHARSET_8BIT && pTpdu->data.deliver.pid == 0x11) {
141                         MSG_DEBUG("Unsupported message!!");
142                         SmsPluginTransport::instance()->sendDeliverReport(handle, MSG_SUCCESS);
143                         return;
144                 }
145         }
146
147         bUdhMwiMethod = false;
148         udhMwiCnt = 0;
149
150         if(pTpdu->data.deliver.dcs.msgClass == SMS_MSG_CLASS_2)
151                 msgInfo.storageId = MSG_STORAGE_UNKNOWN;
152         else
153                 msgInfo.storageId = MSG_STORAGE_PHONE;
154
155         msgInfo.sim_idx = SmsPluginDSHandler::instance()->getSimIndex(handle);
156
157         /** convert to msgInfo */
158         convertTpduToMsginfo(pTpdu, &msgInfo);
159
160         if (msgInfo.msgPort.valid == true) {
161                 if ((msgInfo.msgPort.dstPort >= 0x23F4 && msgInfo.msgPort.dstPort <= 0x23F7) || /** Check unsupported message (Vcard WAP push) **/
162                         (msgInfo.msgPort.dstPort == 0x1581)) { /** Check unsupported message (ringtone smart message) **/
163                         memset(msgInfo.msgText, 0x00, sizeof(msgInfo.msgText));
164                         snprintf(msgInfo.msgText, sizeof(msgInfo.msgText), "<Unsupported message>");
165                         msgInfo.dataSize = strlen(msgInfo.msgText);
166                         msgInfo.msgPort.valid = false;
167                 }
168         }
169
170         if (bUdhMwiMethod == false) {
171                 /** check MWI and set info to SIM for DCS & Address method */
172                 if (pTpdu->tpduType == SMS_TPDU_DELIVER && pTpdu->data.deliver.dcs.bMWI == true) {
173                         MSG_DEBUG("MWI message - DCS method");
174
175                         if (pTpdu->data.deliver.dcs.bIndActive == false) {
176                                 SmsPluginSetting::instance()->setMwiInfo(msgInfo.sim_idx, msgInfo.msgType.subType, 0);
177                                 SmsPluginTransport::instance()->sendDeliverReport(handle, MSG_SUCCESS);
178                                 return;
179                         } else {
180                                 SmsPluginSetting::instance()->setMwiInfo(msgInfo.sim_idx, msgInfo.msgType.subType, 1);
181
182                                 /* For address method */
183                                 if (pTpdu->data.deliver.pid == 0x20 && pTpdu->data.deliver.originAddress.ton == SMS_TON_ALPHANUMERIC) {
184                                         MSG_DEBUG("MWI message - Address method");
185                                         char *voiceNumber = NULL;
186                                         char *voiceAlphaId = NULL;
187                                         char keyName[MAX_VCONFKEY_NAME_LEN];
188
189                                         memset(keyName, 0x00, sizeof(keyName));
190                                         snprintf(keyName, sizeof(keyName), "%s/%d", VOICEMAIL_NUMBER, msgInfo.sim_idx);
191                                         voiceNumber = MsgSettingGetString(keyName);
192
193                                         memset(keyName, 0x00, sizeof(keyName));
194                                         snprintf(keyName, sizeof(keyName), "%s/%d", VOICEMAIL_ALPHA_ID, msgInfo.sim_idx);
195                                         voiceAlphaId = MsgSettingGetString(keyName);
196
197                                         memset(msgInfo.addressList[0].addressVal, 0x00, sizeof(msgInfo.addressList[0].addressVal));
198                                         memset(msgInfo.addressList[0].displayName, 0x00, sizeof(msgInfo.addressList[0].displayName));
199
200                                         if (voiceNumber) {
201                                                 snprintf(msgInfo.addressList[0].addressVal, sizeof(msgInfo.addressList[0].addressVal), "%s", voiceNumber);
202                                                 free(voiceNumber);
203                                                 voiceNumber = NULL;
204                                         }
205
206                                         if (voiceAlphaId) {
207                                                 snprintf(msgInfo.addressList[0].displayName, sizeof(msgInfo.addressList[0].displayName), "%s", voiceAlphaId);
208                                                 free(voiceAlphaId);
209                                                 voiceAlphaId = NULL;
210                                         }
211
212                                         memset(msgInfo.msgText, 0x00, sizeof(msgInfo.msgText));
213                                         snprintf(msgInfo.msgText, sizeof(msgInfo.msgText), "New voice message");
214
215                                 }
216                         }
217
218                         if (pTpdu->data.deliver.dcs.codingGroup == SMS_GROUP_DISCARD)
219                                 msgInfo.bStore = false;
220                 }
221         } else {
222                 MSG_DEBUG("MWI message - UDH method");
223                 if (udhMwiCnt <= 0) {
224                         MSG_DEBUG("MWI count is 0");
225                         SmsPluginSetting::instance()->setMwiInfo(msgInfo.sim_idx, msgInfo.msgType.subType, 0);
226                         SmsPluginTransport::instance()->sendDeliverReport(handle, MSG_SUCCESS);
227                         return;
228                 }
229         }
230
231         /** Short Message Type 0 - Just Send Deliver Report */
232         if (msgInfo.msgType.subType == MSG_TYPE0_SMS) {
233                 SmsPluginTransport::instance()->sendDeliverReport(handle, MSG_SUCCESS);
234                 return;
235         }
236
237         /** Print MSG_MESSAGE_INFO_S */
238         MSG_DEBUG("############# Convert  tpdu values to Message Info values ####################");
239         MSG_DEBUG("msgInfo.nAddressCnt : %d", msgInfo.nAddressCnt);
240         if (msgInfo.nAddressCnt > 0) {
241                 MSG_DEBUG("msgInfo.addressList[0].addressType : %d", msgInfo.addressList[0].addressType);
242                 MSG_SEC_DEBUG("msgInfo.addressList[0].addressVal : %s", msgInfo.addressList[0].addressVal);
243                 MSG_SEC_DEBUG("msgInfo.addressList[0].displayName : %s", msgInfo.addressList[0].displayName);
244         }
245         MSG_DEBUG("msgInfo.priority : %d", msgInfo.priority);
246         MSG_DEBUG("msgInfo.bProtected : %d", msgInfo.bProtected);
247         MSG_DEBUG("msgInfo.bRead : %d", msgInfo.bRead);
248         MSG_DEBUG("msgInfo.bTextSms : %d", msgInfo.bTextSms);
249         MSG_DEBUG("msgInfo.bStore : %d", msgInfo.bStore);
250         MSG_DEBUG("msgInfo.direction : %d", msgInfo.direction);
251         MSG_DEBUG("msgInfo.msgType.mainType : %d", msgInfo.msgType.mainType);
252         MSG_DEBUG("msgInfo.msgType.subType : %d", msgInfo.msgType.subType);
253         MSG_DEBUG("msgInfo.msgType.classType : %d", msgInfo.msgType.classType);
254         MSG_DEBUG("msgInfo.displayTime : %s", ctime(&msgInfo.displayTime));
255         MSG_DEBUG("msgInfo.msgPort.valid : %d", msgInfo.msgPort.valid);
256         MSG_DEBUG("msgInfo.encodeType : %d", msgInfo.encodeType);
257         MSG_DEBUG("msgInfo.dataSize : %d", msgInfo.dataSize);
258         MSG_DEBUG("msgInfo.sim_idx : %d", msgInfo.sim_idx);
259
260         if (msgInfo.bTextSms == true) {
261                 MSG_SEC_DEBUG("msgInfo.msgText : %s", msgInfo.msgText);
262         } else {
263                 MSG_SEC_DEBUG("msgInfo.msgData : %s", msgInfo.msgData);
264         }
265
266         MSG_DEBUG("###############################################################");
267
268         msg_error_t err = MSG_SUCCESS;
269
270         if (msgInfo.msgType.subType == MSG_STATUS_REPORT_SMS) {
271                 /** Status Report Message */
272                 err = SmsPluginStorage::instance()->updateMsgDeliverStatus(&msgInfo, pTpdu->data.statusRep.msgRef);
273
274                 if (err == MSG_SUCCESS)
275                         err = listener.pfMsgIncomingCb(&msgInfo);
276                 else
277                         MSG_DEBUG("updateMsgDeliverStatus is failed [%d]", err);
278
279                 /** Handling of Fail Case ?? */
280                 SmsPluginTransport::instance()->sendDeliverReport(handle, MSG_SUCCESS);
281         } else { /** SMS Deliver */
282                 /** Class 2 Msg */
283                 if (msgInfo.msgType.classType == MSG_CLASS_2) {
284                         if (msgInfo.bTextSms == false) { /** Concat Msg cannot be saved in SIM */
285                                 msgInfo.msgType.classType = MSG_CLASS_NONE;
286                                 msgInfo.storageId = MSG_STORAGE_PHONE;
287                         } else {
288                                 /** set total segment of Class2 message as 1 */
289                                 SmsPluginSimMsg::instance()->setSmsTpduTotalSegCount(1);
290                         }
291                 }
292
293                 /** Add message to DB */
294                 if (msgInfo.msgPort.valid == false) {
295                         err = SmsPluginStorage::instance()->checkMessage(&msgInfo);
296                 }
297
298                 /** Callback to MSG FW */
299                 if (msgInfo.msgType.classType == MSG_CLASS_2) {
300                         if (((msgInfo.msgType.subType >= MSG_MWI_VOICE_SMS) && (msgInfo.msgType.subType <= MSG_MWI_OTHER_SMS)) &&
301                                         (msgInfo.bStore == false)) {
302                                 if (listener.pfMsgIncomingCb(&msgInfo) != MSG_SUCCESS)
303                                         MSG_DEBUG("listener.pfMsgIncomingCb is failed!");
304
305                                 SmsPluginTransport::instance()->sendDeliverReport(handle, MSG_SUCCESS);
306                         }
307                 } else {
308                         if (err == MSG_SUCCESS) {
309                                 MSG_DEBUG("callback to msg fw");
310                                 err = listener.pfMsgIncomingCb(&msgInfo);
311                         } else {
312                                 if (msgInfo.msgType.classType == MSG_CLASS_0) {
313                                         MSG_DEBUG("callback for class0 message to msg fw");
314                                         if (listener.pfMsgIncomingCb(&msgInfo) != MSG_SUCCESS)
315                                                 MSG_DEBUG("listener.pfMsgIncomingCb is failed!");
316                                 }
317                         }
318
319                         /** Send Deliver Report */
320                         if (msgInfo.msgType.classType == MSG_CLASS_0)
321                                 SmsPluginTransport::instance()->sendClass0DeliverReport(handle, err);
322                         else
323                                 SmsPluginTransport::instance()->sendDeliverReport(handle, err);
324                 }
325
326                 // Tizen Validation System
327                 char *msisdn = NULL;
328                 char keyName[MAX_VCONFKEY_NAME_LEN];
329                 memset(keyName, 0x00, sizeof(keyName));
330                 snprintf(keyName, sizeof(keyName), "%s/%d", MSG_SIM_MSISDN, msgInfo.sim_idx);
331                 msisdn = MsgSettingGetString(keyName);
332
333                 MSG_SMS_VLD_INFO("%d, SMS Receive, %s->%s, %s",  msgInfo.msgId, \
334                                                                                                                                 msgInfo.addressList[0].addressVal, \
335                                                                                                                                 (msisdn == NULL)?"ME":msisdn, \
336                                                                                                                                 (err == MSG_SUCCESS)?"Success":"Fail");
337
338                 MSG_SMS_VLD_TXT("%d, [%s]", msgInfo.msgId, msgInfo.msgText);
339
340                 if (msisdn) {
341                         free(msisdn);
342                         msisdn = NULL;
343                 }
344         }
345 }
346
347 void SmsPluginEventHandler::handlePushMsgIncoming(char* pPushHeader, char* pPushBody, int pushBodyLen, char *application_id, char *content_type)
348 {
349         MSG_PUSH_MESSAGE_DATA_S pushData;
350
351         memset(&pushData, 0x00, sizeof(MSG_PUSH_MESSAGE_DATA_S));
352
353         /** set PUSH data */
354         memcpy(pushData.pushHeader, pPushHeader, strlen(pPushHeader));
355
356         pushData.pushBodyLen = pushBodyLen;
357         memcpy(pushData.pushBody, pPushBody, pushBodyLen);
358
359         memcpy(pushData.pushAppId, application_id, MAX_WAPPUSH_ID_LEN);
360         memcpy(pushData.pushContentType, content_type, MAX_WAPPUSH_CONTENT_TYPE_LEN);
361
362         /** Callback to MSG FW */
363         listener.pfPushMsgIncomingCb(&pushData);
364 }
365
366
367 void SmsPluginEventHandler::handleResendMessage(void)
368 {
369         listener.pfResendMessageCb();
370 }
371
372
373 void SmsPluginEventHandler::handleSyncMLMsgIncoming(msg_syncml_message_type_t msgType, char* pPushBody, int PushBodyLen, char* pWspHeader, int WspHeaderLen,int simIndex)
374 {
375         MSG_SYNCML_MESSAGE_DATA_S syncMLData;
376
377         memset(&syncMLData, 0x00, sizeof(MSG_SYNCML_MESSAGE_DATA_S));
378
379         /** set syncML data */
380         syncMLData.syncmlType = msgType;
381
382         syncMLData.simIndex = simIndex;
383
384         syncMLData.pushBodyLen = PushBodyLen;
385         memcpy(syncMLData.pushBody, pPushBody, PushBodyLen);
386
387         syncMLData.wspHeaderLen= WspHeaderLen;
388         memcpy(syncMLData.wspHeader, pWspHeader, WspHeaderLen);
389
390         /** Callback to MSG FW */
391         listener.pfSyncMLMsgIncomingCb(&syncMLData);
392 }
393
394
395 void SmsPluginEventHandler::handleLBSMsgIncoming(char* pPushHeader, char* pPushBody, int pushBodyLen)
396 {
397         MSG_LBS_MESSAGE_DATA_S lBSData;
398
399         memset(&lBSData, 0x00, sizeof(MSG_LBS_MESSAGE_DATA_S));
400
401         /** set LBA data */
402         memcpy(lBSData.pushHeader, pPushHeader, strlen(pPushHeader));
403
404         lBSData.pushBodyLen = pushBodyLen;
405         memcpy(lBSData.pushBody, pPushBody, pushBodyLen);
406
407         /** Callback to MSG FW */
408         listener.pfLBSMsgIncomingCb(&lBSData);
409 }
410
411 msg_error_t SmsPluginEventHandler::callbackMsgIncoming(MSG_MESSAGE_INFO_S *pMsgInfo)
412 {
413         MSG_BEGIN();
414
415         msg_error_t err = MSG_SUCCESS;
416
417         /** Callback to MSG FW */
418         err = listener.pfMsgIncomingCb(pMsgInfo);
419
420         MSG_END();
421
422         return err;
423 }
424
425 msg_error_t SmsPluginEventHandler::callbackCBMsgIncoming(MSG_CB_MSG_S *pCbMsg, MSG_MESSAGE_INFO_S *pMsgInfo)
426 {
427         MSG_BEGIN();
428
429         msg_error_t err = MSG_SUCCESS;
430
431         /** Callback to MSG FW */
432         err = listener.pfCBMsgIncomingCb(pCbMsg, pMsgInfo);
433
434         MSG_END();
435
436         return err;
437 }
438
439
440 msg_error_t SmsPluginEventHandler::callbackInitSimBySat()
441 {
442         /** Callback to MSG FW */
443         return listener.pfInitSimBySatCb();
444 }
445
446
447 msg_error_t SmsPluginEventHandler::callbackStorageChange(msg_storage_change_type_t storageChangeType, MSG_MESSAGE_INFO_S *pMsgInfo)
448 {
449         /** Callback to MSG FW */
450         listener.pfStorageChangeCb(storageChangeType, pMsgInfo);
451
452         return MSG_SUCCESS;
453 }
454
455
456 void SmsPluginEventHandler::convertTpduToMsginfo(SMS_TPDU_S *pTpdu, MSG_MESSAGE_INFO_S *msgInfo)
457 {
458
459         switch(pTpdu->tpduType)
460         {
461                 case SMS_TPDU_SUBMIT :
462                         convertSubmitTpduToMsginfo(&pTpdu->data.submit, msgInfo);
463                         break;
464                 case SMS_TPDU_DELIVER :
465                         convertDeliverTpduToMsginfo(&pTpdu->data.deliver, msgInfo);
466                         break;
467                 case SMS_TPDU_STATUS_REP :
468                         convertStatusRepTpduToMsginfo(&pTpdu->data.statusRep, msgInfo);
469                         break;
470         }
471 }
472
473
474 void SmsPluginEventHandler::convertSubmitTpduToMsginfo(const SMS_SUBMIT_S *pTpdu, MSG_MESSAGE_INFO_S *msgInfo)
475 {
476         int addressListCnt = 0;
477
478         /** Convert Type  values */
479         msgInfo->msgType.mainType = MSG_SMS_TYPE;
480         msgInfo->msgType.subType = convertMsgSubType(pTpdu->pid);
481
482         /** set folder id (temporary) */
483         msgInfo->folderId = MSG_SENTBOX_ID;
484
485         switch(pTpdu->dcs.msgClass)
486         {
487                 case SMS_MSG_CLASS_0:
488                         msgInfo->msgType.classType = MSG_CLASS_0;
489                         break;
490                 case SMS_MSG_CLASS_1:
491                         msgInfo->msgType.classType = MSG_CLASS_1;
492                         break;
493                 case SMS_MSG_CLASS_2:
494                         msgInfo->msgType.classType = MSG_CLASS_2;
495                         break;
496                 case SMS_MSG_CLASS_3:
497                         msgInfo->msgType.classType = MSG_CLASS_3;
498                         break;
499                 default:
500                         msgInfo->msgType.classType = MSG_CLASS_NONE;
501                         break;
502         }
503
504         msgInfo->networkStatus = MSG_NETWORK_SEND_SUCCESS;
505         msgInfo->bRead = false;
506         msgInfo->bProtected = false;
507         msgInfo->priority = MSG_MESSAGE_PRIORITY_NORMAL;
508         msgInfo->direction = MSG_DIRECTION_TYPE_MO;
509         msgInfo->bTextSms = true;
510
511         memset(msgInfo->subject, 0x00, MAX_SUBJECT_LEN+1);
512
513         /** What kind of time has to be saved?? (temporary store time) */
514
515         time_t curTime;
516         localtime(&curTime);
517
518         msgInfo->displayTime = curTime;
519
520         /** Convert Address values */
521         msgInfo->nAddressCnt = 1;
522
523         msgInfo->addressList =  (MSG_ADDRESS_INFO_S *)new char[sizeof(MSG_ADDRESS_INFO_S)];
524         memset(msgInfo->addressList, 0x00, sizeof(MSG_ADDRESS_INFO_S));
525
526         msgInfo->addressList[addressListCnt].addressType = MSG_ADDRESS_TYPE_PLMN;
527         strncpy(msgInfo->addressList[addressListCnt].addressVal, pTpdu->destAddress.address, MAX_ADDRESS_VAL_LEN);
528
529         /**exception operation for none userdata */
530         if (pTpdu->userData.length == 0) {
531                 sprintf(msgInfo->msgText, "[Broken Message]");
532                 msgInfo->dataSize = strlen(msgInfo->msgText);
533                 return;
534         }
535
536         /** Convert Data values */
537         MsgTextConvert *textCvt = MsgTextConvert::instance();
538         if (pTpdu->dcs.codingScheme == SMS_CHARSET_7BIT) {
539                 MSG_LANG_INFO_S langInfo = {0,};
540
541                 langInfo.bSingleShift = false;
542                 langInfo.bLockingShift = false;
543
544                 msgInfo->dataSize = textCvt->convertGSM7bitToUTF8((unsigned char*)msgInfo->msgText, MAX_MSG_TEXT_LEN, (unsigned char*)pTpdu->userData.data, pTpdu->userData.length, &langInfo);
545         } else if (pTpdu->dcs.codingScheme == SMS_CHARSET_UCS2) {
546                 msgInfo->dataSize = textCvt->convertUCS2ToUTF8((unsigned char*)msgInfo->msgText, MAX_MSG_TEXT_LEN, (unsigned char*)pTpdu->userData.data, pTpdu->userData.length);
547         }
548 }
549
550
551 void SmsPluginEventHandler::convertDeliverTpduToMsginfo(const SMS_DELIVER_S *pTpdu, MSG_MESSAGE_INFO_S *msgInfo)
552 {
553         MSG_BEGIN();
554
555         /** Convert Type  values */
556         msgInfo->msgType.mainType = MSG_SMS_TYPE;
557         msgInfo->msgType.subType = convertMsgSubType(pTpdu->pid);
558
559         /** set folder id (temporary) */
560         msgInfo->folderId = MSG_INBOX_ID;
561
562         time_t rawtime = 0;
563         if(msgInfo->storageId == MSG_STORAGE_SIM)
564         {
565         /*** Comment below lines to save local UTC time..... (it could be used later.)
566         ***/
567                 if (pTpdu->timeStamp.format == SMS_TIME_ABSOLUTE) {
568
569                         MSG_DEBUG("year : %d", pTpdu->timeStamp.time.absolute.year);
570                         MSG_DEBUG("month : %d", pTpdu->timeStamp.time.absolute.month);
571                         MSG_DEBUG("day : %d", pTpdu->timeStamp.time.absolute.day);
572                         MSG_DEBUG("hour : %d", pTpdu->timeStamp.time.absolute.hour);
573                         MSG_DEBUG("minute : %d", pTpdu->timeStamp.time.absolute.minute);
574                         MSG_DEBUG("second : %d", pTpdu->timeStamp.time.absolute.second);
575                         MSG_DEBUG("timezone : %d", pTpdu->timeStamp.time.absolute.timeZone);
576
577                         char displayTime[32];
578                         struct tm * timeTM;
579
580                         struct tm timeinfo;
581                         memset(&timeinfo, 0x00, sizeof(tm));
582
583                         timeinfo.tm_year = (pTpdu->timeStamp.time.absolute.year + 100);
584                         timeinfo.tm_mon = (pTpdu->timeStamp.time.absolute.month - 1);
585                         timeinfo.tm_mday = pTpdu->timeStamp.time.absolute.day;
586                         timeinfo.tm_hour = pTpdu->timeStamp.time.absolute.hour;
587                         timeinfo.tm_min = pTpdu->timeStamp.time.absolute.minute;
588                         timeinfo.tm_sec = pTpdu->timeStamp.time.absolute.second;
589                         timeinfo.tm_isdst = 0;
590
591                         rawtime = mktime(&timeinfo);
592
593                         MSG_DEBUG("tzname[0] [%s]", tzname[0]);
594                         MSG_DEBUG("tzname[1] [%s]", tzname[1]);
595                         MSG_DEBUG("timezone [%d]", timezone);
596                         MSG_DEBUG("daylight [%d]", daylight);
597
598                         memset(displayTime, 0x00, sizeof(displayTime));
599                         strftime(displayTime, 32, "%Y-%02m-%02d %T %z", &timeinfo);
600                         MSG_DEBUG("displayTime [%s]", displayTime);
601
602                         rawtime -= (pTpdu->timeStamp.time.absolute.timeZone * (3600/4));
603
604                         timeTM = localtime(&rawtime);
605                         memset(displayTime, 0x00, sizeof(displayTime));
606                         strftime(displayTime, 32, "%Y-%02m-%02d %T %z", timeTM);
607                         MSG_DEBUG("displayTime [%s]", displayTime);
608
609                         rawtime -= timezone;
610
611                         timeTM = localtime(&rawtime);
612                         memset(displayTime, 0x00, sizeof(displayTime));
613                         strftime(displayTime, 32, "%Y-%02m-%02d %T %z", timeTM);
614                         MSG_DEBUG("displayTime [%s]", displayTime);
615                 }
616         }
617         else
618                 rawtime = time(NULL);
619
620         msgInfo->displayTime = rawtime;
621
622         switch(pTpdu->dcs.msgClass)
623         {
624                 case SMS_MSG_CLASS_0:
625                         msgInfo->msgType.classType = MSG_CLASS_0;
626                         break;
627                 case SMS_MSG_CLASS_1:
628                         msgInfo->msgType.classType = MSG_CLASS_1;
629                         break;
630                 case SMS_MSG_CLASS_2:
631                         msgInfo->msgType.classType = MSG_CLASS_2;
632                         msgInfo->storageId = MSG_STORAGE_SIM;
633                         break;
634                 case SMS_MSG_CLASS_3:
635                         msgInfo->msgType.classType = MSG_CLASS_3;
636                         break;
637                 default:
638                         msgInfo->msgType.classType = MSG_CLASS_NONE;
639                         break;
640         }
641
642         if (pTpdu->dcs.bMWI) {
643                 if (pTpdu->dcs.indType == SMS_VOICE_INDICATOR)
644                         msgInfo->msgType.subType = MSG_MWI_VOICE_SMS;
645                 else if (pTpdu->dcs.indType == SMS_VOICE2_INDICATOR)
646                         msgInfo->msgType.subType = MSG_MWI_VOICE2_SMS;
647                 else if (pTpdu->dcs.indType == SMS_FAX_INDICATOR)
648                         msgInfo->msgType.subType = MSG_MWI_FAX_SMS;
649                 else if (pTpdu->dcs.indType == SMS_EMAIL_INDICATOR)
650                         msgInfo->msgType.subType = MSG_MWI_EMAIL_SMS;
651                 else if (pTpdu->dcs.indType == SMS_OTHER_INDICATOR)
652                         msgInfo->msgType.subType = MSG_MWI_OTHER_SMS;
653         }
654
655         msgInfo->networkStatus = MSG_NETWORK_RECEIVED;
656         msgInfo->bRead = false;
657         msgInfo->bProtected = false;
658         msgInfo->priority = MSG_MESSAGE_PRIORITY_NORMAL;
659         msgInfo->direction = MSG_DIRECTION_TYPE_MT;
660         msgInfo->bTextSms = true;
661
662         memset(msgInfo->subject, 0x00, MAX_SUBJECT_LEN+1);
663
664         /** Convert Address values */
665         msgInfo->nAddressCnt = 1;
666
667         msgInfo->addressList =  (MSG_ADDRESS_INFO_S *)new char[sizeof(MSG_ADDRESS_INFO_S)];
668         memset(msgInfo->addressList, 0x00, sizeof(MSG_ADDRESS_INFO_S));
669
670         msgInfo->addressList[0].addressType = MSG_ADDRESS_TYPE_PLMN;
671         strncpy(msgInfo->addressList[0].addressVal, pTpdu->originAddress.address, MAX_ADDRESS_VAL_LEN);
672
673         msgInfo->msgPort.valid = false;
674         msgInfo->msgPort.dstPort = 0;
675         msgInfo->msgPort.srcPort = 0;
676
677         for (int i = 0; i < pTpdu->userData.headerCnt; i++) {
678                 /** Convert UDH values - Port Number */
679                 if (pTpdu->userData.header[i].udhType == SMS_UDH_APP_PORT_8BIT) {
680                         msgInfo->msgPort.valid = true;
681                         msgInfo->msgPort.dstPort = pTpdu->userData.header[i].udh.appPort8bit.destPort;
682                         msgInfo->msgPort.srcPort = pTpdu->userData.header[i].udh.appPort8bit.originPort;
683                 } else if (pTpdu->userData.header[i].udhType == SMS_UDH_APP_PORT_16BIT) {
684                         msgInfo->msgPort.valid = true;
685                         msgInfo->msgPort.dstPort = pTpdu->userData.header[i].udh.appPort16bit.destPort;
686                         msgInfo->msgPort.srcPort = pTpdu->userData.header[i].udh.appPort16bit.originPort;
687                 } else if (pTpdu->userData.header[i].udhType == SMS_UDH_SPECIAL_SMS) {
688                         msgInfo->msgType.subType = (pTpdu->userData.header[i].udh.specialInd.msgInd+MSG_MWI_VOICE_SMS);
689                         msgInfo->bStore = pTpdu->userData.header[i].udh.specialInd.bStore;
690
691                         bUdhMwiMethod = true;
692
693                         if (pTpdu->dcs.codingGroup == SMS_GROUP_DISCARD)
694                                 msgInfo->bStore = false;
695
696                         udhMwiCnt = pTpdu->userData.header[i].udh.specialInd.waitMsgNum;
697                         MSG_DEBUG("Message waiting number : [%d]", udhMwiCnt);
698
699                         SmsPluginSetting::instance()->setMwiInfo(msgInfo->sim_idx, msgInfo->msgType.subType, udhMwiCnt);
700
701                         if (udhMwiCnt > 0 && (msgInfo->msgType.subType >= MSG_MWI_VOICE_SMS && msgInfo->msgType.subType <= MSG_MWI_OTHER_SMS)) {
702                                 switch (msgInfo->msgType.subType) {
703                                 case MSG_MWI_VOICE_SMS :
704                                         snprintf(msgInfo->msgText, sizeof(msgInfo->msgText), "%d", udhMwiCnt);
705                                         break;
706                                 case MSG_MWI_FAX_SMS :
707                                         snprintf(msgInfo->msgText, sizeof(msgInfo->msgText), "%d new fax message", udhMwiCnt);
708                                         break;
709                                 case MSG_MWI_EMAIL_SMS :
710                                         snprintf(msgInfo->msgText, sizeof(msgInfo->msgText), "%d new email message", udhMwiCnt);
711                                         break;
712                                 default :
713                                         snprintf(msgInfo->msgText, sizeof(msgInfo->msgText), "%d new special message", udhMwiCnt);
714                                         break;
715                                 }
716                                 msgInfo->dataSize = strlen(msgInfo->msgText);
717                                 return;
718                         }
719                 } else if (pTpdu->userData.header[i].udhType == SMS_UDH_ALTERNATE_REPLY_ADDRESS) {
720                         strncpy(msgInfo->addressList[0].addressVal, pTpdu->userData.header[i].udh.alternateAddress.address, MAX_ADDRESS_VAL_LEN);
721                 } else if (pTpdu->userData.header[i].udhType >= SMS_UDH_EMS_FIRST && pTpdu->userData.header[i].udhType <= SMS_UDH_EMS_LAST) {
722                         snprintf(msgInfo->msgText, sizeof(msgInfo->msgText), "Unsupported Message");
723                         msgInfo->dataSize = strlen(msgInfo->msgText);
724                         return;
725                 }
726         }
727
728         /**length 0 - no user data - msg should be received */
729         if (pTpdu->userData.length <= 0) {
730                 memset(msgInfo->msgText, 0x00, sizeof(msgInfo->msgText));
731                 msgInfo->dataSize = 0;
732
733                 switch(pTpdu->dcs.codingScheme)
734                 {
735                         case SMS_CHARSET_7BIT:
736                                 msgInfo->encodeType = MSG_ENCODE_GSM7BIT;
737                                 break;
738                         case SMS_CHARSET_8BIT:
739                                 msgInfo->encodeType = MSG_ENCODE_8BIT;
740                                 break;
741                         case SMS_CHARSET_UCS2:
742                                 msgInfo->encodeType = MSG_ENCODE_UCS2;
743                                 break;
744                         default:
745                                 msgInfo->encodeType = MSG_ENCODE_8BIT;
746                                 break;
747                 }
748
749                 return;
750         } else if (pTpdu->userData.length > MAX_MSG_TEXT_LEN) {
751                 sprintf(msgInfo->msgText, "[Broken Message]");
752                 msgInfo->dataSize = strlen(msgInfo->msgData);
753                 return;
754         }
755
756         /** Convert Data values */
757         MsgTextConvert *textCvt = MsgTextConvert::instance();
758         if (pTpdu->dcs.codingScheme == SMS_CHARSET_7BIT) {
759                 MSG_LANG_INFO_S langInfo = {0,};
760
761                 langInfo.bSingleShift = false;
762                 langInfo.bLockingShift = false;
763
764                 for (int i = 0; i < pTpdu->userData.headerCnt; i++)     {
765                         if (pTpdu->userData.header[i].udhType == SMS_UDH_SINGLE_SHIFT) {
766                                 langInfo.bSingleShift = true;
767                                 langInfo.singleLang = pTpdu->userData.header[i].udh.singleShift.langId;
768                         } else if (pTpdu->userData.header[i].udhType == SMS_UDH_LOCKING_SHIFT) {
769                                 langInfo.bLockingShift = true;
770                                 langInfo.lockingLang = pTpdu->userData.header[i].udh.lockingShift.langId;
771                         }
772                 }
773
774                 msgInfo->encodeType = MSG_ENCODE_GSM7BIT;
775                 msgInfo->dataSize = textCvt->convertGSM7bitToUTF8((unsigned char*)msgInfo->msgText, MAX_MSG_TEXT_LEN, (unsigned char*)pTpdu->userData.data, pTpdu->userData.length, &langInfo);
776         } else if (pTpdu->dcs.codingScheme == SMS_CHARSET_8BIT) {
777                 msgInfo->encodeType = MSG_ENCODE_8BIT;
778                 memcpy(msgInfo->msgText, pTpdu->userData.data, sizeof(pTpdu->userData.data));
779                 msgInfo->dataSize = pTpdu->userData.length;
780         } else if (pTpdu->dcs.codingScheme == SMS_CHARSET_UCS2) {
781                 msgInfo->encodeType = MSG_ENCODE_UCS2;
782                 msgInfo->dataSize = textCvt->convertUCS2ToUTF8((unsigned char*)msgInfo->msgText, MAX_MSG_TEXT_LEN, (unsigned char*)pTpdu->userData.data, pTpdu->userData.length);
783         } else if (pTpdu->dcs.codingScheme == SMS_CHARSET_EUCKR) {
784                 msgInfo->encodeType = MSG_ENCODE_8BIT;
785                 msgInfo->dataSize = textCvt->convertEUCKRToUTF8((unsigned char*)msgInfo->msgText, MAX_MSG_TEXT_LEN, (unsigned char*)pTpdu->userData.data, pTpdu->userData.length);
786                 return;
787         }
788
789         MSG_END();
790 }
791
792
793 void SmsPluginEventHandler::convertStatusRepTpduToMsginfo(const SMS_STATUS_REPORT_S *pTpdu, MSG_MESSAGE_INFO_S *msgInfo)
794 {
795         /** Convert Type  values */
796         msgInfo->msgType.mainType = MSG_SMS_TYPE;
797         msgInfo->msgType.subType = MSG_STATUS_REPORT_SMS;
798
799         /** set folder id */
800         msgInfo->folderId = MSG_INBOX_ID;
801
802         /** set storage id */
803         if (msgInfo->storageId == MSG_STORAGE_UNKNOWN) {
804                 msgInfo->storageId = MSG_STORAGE_PHONE;
805         }
806
807         switch(pTpdu->dcs.msgClass)
808         {
809                 case SMS_MSG_CLASS_0:
810                         msgInfo->msgType.classType = MSG_CLASS_0;
811                         break;
812                 case SMS_MSG_CLASS_1:
813                         msgInfo->msgType.classType = MSG_CLASS_1;
814                         break;
815                 case SMS_MSG_CLASS_2:
816                         msgInfo->msgType.classType = MSG_CLASS_2;
817                         break;
818                 case SMS_MSG_CLASS_3:
819                         msgInfo->msgType.classType = MSG_CLASS_3;
820                         break;
821                 default:
822                         msgInfo->msgType.classType = MSG_CLASS_NONE;
823                         break;
824         }
825
826         MSG_DEBUG("delivery status : [%d]", pTpdu->status);
827
828         if (pTpdu->status == SMS_STATUS_RECEIVE_SUCCESS)
829         {
830                 msgInfo->networkStatus = MSG_NETWORK_DELIVER_SUCCESS;
831         }
832         else if(pTpdu->status == SMS_STATUS_TRY_REQUEST_PENDING)
833         {
834                 msgInfo->networkStatus = MSG_NETWORK_DELIVER_PENDING;
835         }
836         else if(pTpdu->status == SMS_STATUS_PERM_MSG_VAL_PERIOD_EXPIRED)
837         {
838                 msgInfo->networkStatus = MSG_NETWORK_DELIVER_EXPIRED;
839         }
840         else
841         {
842                 msgInfo->networkStatus = MSG_NETWORK_DELIVER_FAIL;
843         }
844
845         msgInfo->bRead = false;
846         msgInfo->bProtected = false;
847         msgInfo->priority = MSG_MESSAGE_PRIORITY_NORMAL;
848         msgInfo->direction = MSG_DIRECTION_TYPE_MT;
849         msgInfo->bTextSms = true;
850
851         memset(msgInfo->subject, 0x00, MAX_SUBJECT_LEN+1);
852
853         time_t rawtime = time(NULL);
854
855 /*** Comment below lines to save local UTC time..... (it could be used later.)
856
857         if (pTpdu->timeStamp.format == SMS_TIME_ABSOLUTE) {
858
859                 MSG_DEBUG("year : %d", pTpdu->timeStamp.time.absolute.year);
860                 MSG_DEBUG("month : %d", pTpdu->timeStamp.time.absolute.month);
861                 MSG_DEBUG("day : %d", pTpdu->timeStamp.time.absolute.day);
862                 MSG_DEBUG("hour : %d", pTpdu->timeStamp.time.absolute.hour);
863                 MSG_DEBUG("minute : %d", pTpdu->timeStamp.time.absolute.minute);
864                 MSG_DEBUG("second : %d", pTpdu->timeStamp.time.absolute.second);
865                 MSG_DEBUG("timezone : %d", pTpdu->timeStamp.time.absolute.timeZone);
866
867                 char displayTime[32];
868                 struct tm * timeTM;
869
870                 struct tm timeinfo;
871                 memset(&timeinfo, 0x00, sizeof(tm));
872
873                 timeinfo.tm_year = (pTpdu->timeStamp.time.absolute.year + 100);
874                 timeinfo.tm_mon = (pTpdu->timeStamp.time.absolute.month - 1);
875                 timeinfo.tm_mday = pTpdu->timeStamp.time.absolute.day;
876                 timeinfo.tm_hour = pTpdu->timeStamp.time.absolute.hour;
877                 timeinfo.tm_min = pTpdu->timeStamp.time.absolute.minute;
878                 timeinfo.tm_sec = pTpdu->timeStamp.time.absolute.second;
879                 timeinfo.tm_isdst = 0;
880
881                 rawtime = mktime(&timeinfo);
882
883                 MSG_DEBUG("tzname[0] [%s]", tzname[0]);
884                 MSG_DEBUG("tzname[1] [%s]", tzname[1]);
885                 MSG_DEBUG("timezone [%d]", timezone);
886                 MSG_DEBUG("daylight [%d]", daylight);
887
888                 memset(displayTime, 0x00, sizeof(displayTime));
889                 strftime(displayTime, 32, "%Y-%02m-%02d %T %z", &timeinfo);
890                 MSG_DEBUG("displayTime [%s]", displayTime);
891
892                 rawtime -= (pTpdu->timeStamp.time.absolute.timeZone * (3600/4));
893
894                 timeTM = localtime(&rawtime);
895                 memset(displayTime, 0x00, sizeof(displayTime));
896                 strftime(displayTime, 32, "%Y-%02m-%02d %T %z", timeTM);
897                 MSG_DEBUG("displayTime [%s]", displayTime);
898
899                 rawtime -= timezone;
900
901                 timeTM = localtime(&rawtime);
902                 memset(displayTime, 0x00, sizeof(displayTime));
903                 strftime(displayTime, 32, "%Y-%02m-%02d %T %z", timeTM);
904                 MSG_DEBUG("displayTime [%s]", displayTime);
905         }
906
907 ***/
908
909         msgInfo->displayTime = rawtime;
910
911         /** Convert Address values */
912         msgInfo->nAddressCnt = 1;
913
914         msgInfo->addressList =  (MSG_ADDRESS_INFO_S *)new char[sizeof(MSG_ADDRESS_INFO_S)];
915         memset(msgInfo->addressList, 0x00, sizeof(MSG_ADDRESS_INFO_S));
916
917         msgInfo->addressList[0].addressType = MSG_ADDRESS_TYPE_PLMN;
918         strncpy(msgInfo->addressList[0].addressVal, pTpdu->recipAddress.address, MAX_ADDRESS_VAL_LEN);
919
920         msgInfo->msgPort.valid = false;
921         msgInfo->msgPort.dstPort = 0;
922         msgInfo->msgPort.srcPort = 0;
923
924         for (int i = 0; i < pTpdu->userData.headerCnt; i++) {
925                 /** Convert UDH values - Port Number */
926                 if (pTpdu->userData.header[i].udhType == SMS_UDH_APP_PORT_8BIT) {
927                         msgInfo->msgPort.valid = true;
928                         msgInfo->msgPort.dstPort = pTpdu->userData.header[i].udh.appPort8bit.destPort;
929                         msgInfo->msgPort.srcPort = pTpdu->userData.header[i].udh.appPort8bit.originPort;
930                 } else if (pTpdu->userData.header[i].udhType == SMS_UDH_APP_PORT_16BIT) {
931                         msgInfo->msgPort.valid = true;
932                         msgInfo->msgPort.dstPort = pTpdu->userData.header[i].udh.appPort16bit.destPort;
933                         msgInfo->msgPort.srcPort = pTpdu->userData.header[i].udh.appPort16bit.originPort;
934                 }
935         }
936
937         memset(msgInfo->msgText, 0x00, sizeof(msgInfo->msgText));
938         msgInfo->dataSize = 0;
939
940         if (pTpdu->status <= SMS_STATUS_SMSC_SPECIFIC_LAST) {
941                 strncpy(msgInfo->msgText, "IDS_MSGF_BODY_MESSAGE_DELIVERED", MAX_MSG_TEXT_LEN);
942                 msgInfo->dataSize = strlen(msgInfo->msgText);
943         } else if (pTpdu->status == SMS_STATUS_TEMP_SERVICE_REJECTED) {
944                 strncpy(msgInfo->msgText, "IDS_MSGF_BODY_MMSDELIVERYMSGREJECTED", MAX_MSG_TEXT_LEN);
945                 msgInfo->dataSize = strlen(msgInfo->msgText);
946         } else if (pTpdu->status == SMS_STATUS_PERM_MSG_VAL_PERIOD_EXPIRED) {
947                 strncpy(msgInfo->msgText, "IDS_MSGF_BODY_MESSAGE_HAS_EXPIRED", MAX_MSG_TEXT_LEN);
948                 msgInfo->dataSize = strlen(msgInfo->msgText);
949         } else {
950                 strncpy(msgInfo->msgText, "Message delivery failed.", MAX_MSG_TEXT_LEN);
951                 msgInfo->dataSize = strlen(msgInfo->msgText);
952         }
953 }
954
955
956 MSG_SUB_TYPE_T SmsPluginEventHandler::convertMsgSubType(SMS_PID_T pid)
957 {
958         switch (pid)
959         {
960                 case SMS_PID_TYPE0 :
961                         return MSG_TYPE0_SMS;
962                 case SMS_PID_REPLACE_TYPE1 :
963                         return MSG_REPLACE_TYPE1_SMS;
964                 case SMS_PID_REPLACE_TYPE2 :
965                         return MSG_REPLACE_TYPE2_SMS;
966                 case SMS_PID_REPLACE_TYPE3 :
967                         return MSG_REPLACE_TYPE3_SMS;
968                 case SMS_PID_REPLACE_TYPE4 :
969                         return MSG_REPLACE_TYPE4_SMS;
970                 case SMS_PID_REPLACE_TYPE5 :
971                         return MSG_REPLACE_TYPE5_SMS;
972                 case SMS_PID_REPLACE_TYPE6 :
973                         return MSG_REPLACE_TYPE6_SMS;
974                 case SMS_PID_REPLACE_TYPE7 :
975                         return MSG_REPLACE_TYPE7_SMS;
976                 case SMS_PID_RETURN_CALL :
977                         return MSG_MWI_OTHER_SMS;
978                 default :
979                         return MSG_NORMAL_SMS;
980         }
981
982 }
983
984
985 void SmsPluginEventHandler::SetSentInfo(SMS_SENT_INFO_S *pSentInfo)
986 {
987         memset(&sentInfo, 0x00, sizeof(SMS_SENT_INFO_S));
988         memcpy(&sentInfo, pSentInfo, sizeof(SMS_SENT_INFO_S));
989
990         MSG_DEBUG("sentInfo.reqId : %d", sentInfo.reqInfo.reqId);
991         MSG_DEBUG("sentInfo.bLast : %d", sentInfo.bLast);
992 }
993
994
995 void SmsPluginEventHandler::setDeviceStatus(struct tapi_handle *handle)
996 {
997         if (handle == devHandle) {
998                 mx.lock();
999                 devStatus = true;
1000                 cv.signal();
1001                 mx.unlock();
1002         }
1003 }
1004
1005
1006 bool SmsPluginEventHandler::getDeviceStatus(struct tapi_handle *handle)
1007 {
1008         int ret = 0;
1009
1010         mx.lock();
1011         devHandle = handle;
1012         ret = cv.timedwait(mx.pMutex(), MAX_TAPI_SIM_API_TIMEOUT);
1013
1014         if (ret == ETIMEDOUT) {
1015                 MSG_WARN("WARNING: DEVICE STATUS TIME-OUT");
1016                 devStatus = false;
1017         }
1018         devHandle = NULL;
1019         mx.unlock();
1020         return devStatus;
1021 }
1022
1023
1024 msg_error_t SmsPluginEventHandler::handleSimMsg(MSG_MESSAGE_INFO_S *pMsgInfo, int *simIdList, msg_message_id_t *retMsgId, int listSize)
1025 {
1026         MSG_BEGIN();
1027
1028         msg_error_t err = MSG_SUCCESS;
1029
1030         /** Callback to MSG FW */
1031         err = listener.pfSimMsgIncomingCb(pMsgInfo, simIdList, retMsgId, listSize);
1032
1033         MSG_END();
1034
1035         return err;
1036 }
1037
1038 msg_error_t SmsPluginEventHandler::updateIMSI(int sim_idx)
1039 {
1040         MSG_BEGIN();
1041
1042         msg_error_t err = MSG_SUCCESS;
1043
1044         /** Callback to MSG FW */
1045         err = listener.pfSimInitImsiCb(sim_idx);
1046
1047         MSG_END();
1048
1049         return err;
1050 }
1051
1052 void SmsPluginEventHandler::handleSimMemoryFull(int simIndex)
1053 {
1054         char keyName[MAX_VCONFKEY_NAME_LEN];
1055         bool bSimSst = true;
1056         memset(keyName, 0x00, sizeof(keyName));
1057         snprintf(keyName, sizeof(keyName), "%s/%d", MSG_SIM_SERVICE_TABLE, simIndex);
1058         if (MsgSettingGetBool(keyName, &bSimSst) != MSG_SUCCESS)
1059                 MSG_ERR("MsgSettingGetBool [%s] failed", keyName);
1060
1061         if (bSimSst == true)
1062                 MsgInsertTicker("Sim memory full. Delete some items", SMS_MESSAGE_SIM_MESSAGE_FULL, true, 0);
1063 }