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