svace issues fixed
[platform/core/messaging/msg-service.git] / plugin / sms_plugin / SmsPluginCallback.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 <glib.h>
18 #include <pthread.h>
19
20 #include "MsgDebug.h"
21 #include "MsgCppTypes.h"
22 #include "MsgException.h"
23 #include "SmsPluginEventHandler.h"
24 #include "SmsPluginCbMsgHandler.h"
25 #include "SmsPluginConcatHandler.h"
26 #include "SmsPluginWapPushHandler.h"
27 #include "SmsPluginSatHandler.h"
28 #include "SmsPluginParamCodec.h"
29 #include "SmsPluginTpduCodec.h"
30 #include "SmsPluginTransport.h"
31 #include "SmsPluginSimMsg.h"
32 #include "SmsPluginSetting.h"
33 #include "MsgGconfWrapper.h"
34 #include "MsgDevicedWrapper.h"
35 #include "SmsPluginCallback.h"
36 #include "SmsPluginDSHandler.h"
37
38 extern bool isMemAvailable;
39
40
41 /*==================================================================================================
42                                      FUNCTION IMPLEMENTATION
43 ==================================================================================================*/
44 void TapiEventDeviceReady(TapiHandle *handle, const char *noti_id, void *data, void *user_data)
45 {
46         MSG_DEBUG("TapiEventDeviceReady is called. : noti_id = [%d]", noti_id);
47
48         try {
49                 /* Call Event Handler */
50                 SmsPluginEventHandler::instance()->setDeviceStatus(handle);
51         } catch (MsgException& e) {
52                 MSG_FATAL("%s", e.what());
53                 return;
54         }
55 }
56
57 SMS_NETWORK_STATUS_T convertTapiRespToSmsPlugin(int result)
58 {
59         SMS_NETWORK_STATUS_T sentStatus;
60
61         /* Convert TAPI status -> SMS network status */
62         switch ((TelSmsResponse_t)result) {
63         case TAPI_NETTEXT_SENDSMS_SUCCESS :
64                 sentStatus = SMS_NETWORK_SEND_SUCCESS;
65                 break;
66
67         case TAPI_NETTEXT_INVALID_MANDATORY_INFO :
68                 sentStatus = SMS_NETWORK_SEND_FAIL_MANDATORY_INFO_MISSING;
69                 break;
70
71         case TAPI_NETTEXT_DESTINAITION_OUTOFSERVICE :
72         case TAPI_NETTEXT_TEMPORARY_FAILURE :
73         case TAPI_NETTEXT_CONGESTION :
74         case TAPI_NETTEXT_RESOURCES_UNAVAILABLE :
75         case TAPI_NETTEXT_MESSAGE_NOT_COMPAT_PROTOCOL :
76         case TAPI_NETTEXT_NETWORK_OUTOFORDER:
77                 sentStatus = SMS_NETWORK_SEND_FAIL_TEMPORARY;
78                 break;
79
80         case TAPI_NETTEXT_MESSAGE_TRANSFER_REJECTED :
81                 sentStatus = SMS_NETWORK_SEND_FAIL_BY_MO_CONTROL_NOT_ALLOWED;
82                 break;
83
84         case TAPI_NETTEXT_DEST_ADDRESS_FDN_RESTRICTED :
85         case TAPI_NETTEXT_SCADDRESS_FDN_RESTRICTED :
86                 sentStatus = SMS_NETWORK_SEND_FAIL_FDN_RESTRICED;
87                 break;
88         case TAPI_NETTEXT_ROUTING_NOT_AVAILABLE :
89                 sentStatus = SMS_NETWORK_SEND_FAIL_NO_ROUTING;
90                 break;
91         default :
92                 sentStatus = SMS_NETWORK_SEND_FAIL;
93                 break;
94         }
95
96         return sentStatus;
97 }
98
99 void TapiEventSentStatus(TapiHandle *handle, int result, void *data, void *user_data)
100 {
101         MSG_DEBUG("TapiEventSentStatus is called. : result = [0x%x]", result);
102
103         SMS_NETWORK_STATUS_T sentStatus;
104
105         TelSatMoSmCtrlIndData_t *moCtrlStatus = (TelSatMoSmCtrlIndData_t *)user_data;
106
107         sentStatus = convertTapiRespToSmsPlugin(result);
108
109         if (moCtrlStatus && sentStatus == SMS_NETWORK_SEND_FAIL_BY_MO_CONTROL_NOT_ALLOWED) {
110                 if (moCtrlStatus->moSmsCtrlResult == TAPI_SAT_CALL_CTRL_R_ALLOWED_WITH_MOD)
111                         sentStatus = SMS_NETWORK_SEND_FAIL_BY_MO_CONTROL_WITH_MOD;
112         }
113
114         if (result != TAPI_NETTEXT_SENDSMS_SUCCESS)
115                 MSG_INFO("sentStatus:[%d], tapi_result:[0x%x]", sentStatus, result);
116
117         MSG_DEBUG("SMS Network Status = [%d]", sentStatus);
118
119         /* only temporary errors should be returned without calling handleSentStatus() in order to resend sms  */
120         if (sentStatus == SMS_NETWORK_SEND_FAIL_TEMPORARY ||
121                         sentStatus == SMS_NETWORK_SEND_FAIL_BY_MO_CONTROL_WITH_MOD ||
122                         sentStatus == SMS_NETWORK_SEND_FAIL_FDN_RESTRICED) {
123                 SmsPluginTransport::instance()->setNetStatus(sentStatus);
124                 return;
125         }
126
127         if (sentStatus == SMS_NETWORK_SEND_FAIL) {
128                 int svc_type;
129                 tel_get_property_int(handle, TAPI_PROP_NETWORK_SERVICE_TYPE, &svc_type);
130                 if (svc_type < TAPI_NETWORK_SERVICE_TYPE_2G)
131                         sentStatus = SMS_NETWORK_SEND_PENDING;
132         }
133
134         /* Convert SMS status -> Messaging network status */
135         msg_network_status_t netStatus;
136
137         if (sentStatus == SMS_NETWORK_SEND_SUCCESS) {
138                 netStatus = MSG_NETWORK_SEND_SUCCESS;
139         } else if (sentStatus == SMS_NETWORK_SENDING) {
140                 netStatus = MSG_NETWORK_SENDING;
141         } else if (sentStatus == SMS_NETWORK_SEND_PENDING) {
142                 netStatus = MSG_NETWORK_SEND_PENDING;
143         } else {
144                 netStatus = MSG_NETWORK_SEND_FAIL;
145         }
146
147         try {
148                 SmsPluginEventHandler::instance()->handleSentStatus(netStatus);
149
150                 SmsPluginTransport::instance()->setNetStatus(sentStatus);
151         } catch (MsgException& e) {
152                 MSG_FATAL("%s", e.what());
153                 return;
154         }
155 }
156
157 void TapiEventSatSmsSentStatus(TapiHandle *handle, int result, void *data, void *user_data)
158 {
159         MSG_INFO("TapiEventSatSmsSentStatus is called. : result = [%d]", result);
160
161         SMS_NETWORK_STATUS_T sentStatus;
162
163         sentStatus = convertTapiRespToSmsPlugin(result);
164
165         MSG_DEBUG("SMS Network Status = [%d]", sentStatus);
166
167         if (sentStatus == SMS_NETWORK_SEND_FAIL && result != TAPI_NETTEXT_DEVICE_FAILURE) {
168                 int svc_type;
169                 tel_get_property_int(handle, TAPI_PROP_NETWORK_SERVICE_TYPE, &svc_type);
170                 if (svc_type < TAPI_NETWORK_SERVICE_TYPE_2G)
171                         sentStatus = SMS_NETWORK_SEND_PENDING;
172         }
173
174         try {
175                 SmsPluginSatHandler::instance()->ctrlSms(handle, sentStatus);
176         } catch (MsgException& e) {
177                 MSG_FATAL("%s", e.what());
178                 return;
179         }
180 }
181
182 void TapiEventMsgIncoming(TapiHandle *handle, const char *noti_id, void *data, void *user_data)
183 {
184         MSG_SEC_DEBUG("TapiEventMsgIncoming is called. noti_id [%s]", noti_id);
185
186         if (data == NULL) {
187                 MSG_ERR("Error. data is NULL.");
188                 return;
189         }
190 #if 0
191         SmsPluginCbMsgHandler::instance()->handleCbMsg(handle, NULL);
192         return;
193 #endif
194         /* make a margin timeout(500ms) till suspending status */
195         MsgDisplayLock();
196
197         TelSmsDatapackageInfo_t* pDataPackage = (TelSmsDatapackageInfo_t*)data;
198
199         SMS_TPDU_S tpdu;
200         memset(&tpdu, 0x00, sizeof(SMS_TPDU_S));
201
202         /* Decode Incoming Message */
203         SmsPluginTpduCodec::decodeTpdu(pDataPackage->szData, pDataPackage->MsgLength, &tpdu);
204
205         /* Print tpdu */
206         if (tpdu.tpduType == SMS_TPDU_DELIVER) {
207                 MSG_DEBUG("############# SMS_TPDU_DELIVER Incoming decoded tpdu values ####################");
208                 MSG_DEBUG("tpdu.data.deliver.bMoreMsg : %d", tpdu.data.deliver.bMoreMsg);
209                 MSG_DEBUG("tpdu.data.deliver.bStatusReport : %d", tpdu.data.deliver.bStatusReport);
210                 MSG_DEBUG("tpdu.data.deliver.bHeaderInd : %d", tpdu.data.deliver.bHeaderInd);
211                 MSG_DEBUG("tpdu.data.deliver.bReplyPath : %d", tpdu.data.deliver.bReplyPath);
212                 MSG_DEBUG("tpdu.data.deliver.pid : %d", tpdu.data.deliver.pid);
213                 MSG_DEBUG("tpdu.data.deliver.dcs.bCompressed : %d", tpdu.data.deliver.dcs.bCompressed);
214                 MSG_DEBUG("tpdu.data.deliver.dcs.msgClass : %d", tpdu.data.deliver.dcs.msgClass);
215                 MSG_DEBUG("tpdu.data.deliver.dcs.codingScheme : %d", tpdu.data.deliver.dcs.codingScheme);
216                 MSG_DEBUG("tpdu.data.deliver.dcs.codingGroup : %d", tpdu.data.deliver.dcs.codingGroup);
217                 MSG_DEBUG("tpdu.data.deliver.dcs.bIndActive : %d", tpdu.data.deliver.dcs.bIndActive);
218                 MSG_SEC_DEBUG("tpdu.data.deliver.originAddress.address : %s", tpdu.data.deliver.originAddress.address);
219                 MSG_DEBUG("tpdu.data.deliver.timeStamp.time : %d/%d/%d %d:%d:%d ", tpdu.data.deliver.timeStamp.time.absolute.year, tpdu.data.deliver.timeStamp.time.absolute.month, tpdu.data.deliver.timeStamp.time.absolute.day,
220                         tpdu.data.deliver.timeStamp.time.absolute.hour, tpdu.data.deliver.timeStamp.time.absolute.minute, tpdu.data.deliver.timeStamp.time.absolute.second);
221                 MSG_DEBUG("tpdu.data.deliver.userData.headerCnt : %d", tpdu.data.deliver.userData.headerCnt);
222                 MSG_DEBUG("tpdu.data.deliver.userData.length : %d", tpdu.data.deliver.userData.length);
223                 MSG_DEBUG("tpdu.data.deliver.userData.data : %s", tpdu.data.deliver.userData.data);
224                 MSG_DEBUG("#####################################################");
225         } else if (tpdu.tpduType == SMS_TPDU_STATUS_REP) {
226                 MSG_DEBUG("############# SMS_TPDU_STATUS_REP Incoming decoded tpdu values ####################");
227                 MSG_DEBUG("tpdu.data.statusRep.msgRef : %d", tpdu.data.statusRep.msgRef);
228                 MSG_DEBUG("tpdu.data.statusRep.bMoreMsg : %d", tpdu.data.statusRep.bMoreMsg);
229                 MSG_DEBUG("tpdu.data.statusRep.bStatusReport : %d", tpdu.data.statusRep.bStatusReport);
230                 MSG_DEBUG("tpdu.data.statusRep.statusRep : %d", tpdu.data.statusRep.bHeaderInd);
231                 MSG_DEBUG("tpdu.data.statusRep.status : %02x", tpdu.data.statusRep.status);
232                 MSG_DEBUG("tpdu.data.statusRep.pid : %d", tpdu.data.statusRep.pid);
233                 MSG_DEBUG("tpdu.data.statusRep.dcs.bCompressed : %d", tpdu.data.statusRep.dcs.bCompressed);
234                 MSG_DEBUG("tpdu.data.statusRep.dcs.msgClass : %d", tpdu.data.statusRep.dcs.msgClass);
235                 MSG_DEBUG("tpdu.data.statusRep.dcs.codingScheme : %d", tpdu.data.statusRep.dcs.codingScheme);
236                 MSG_DEBUG("tpdu.data.statusRep.dcs.codingGroup : %d", tpdu.data.statusRep.dcs.codingGroup);
237                 MSG_SEC_DEBUG("tpdu.data.statusRep.recipAddress.address : %s", tpdu.data.statusRep.recipAddress.address);
238                 MSG_DEBUG("tpdu.data.statusRep.timeStamp.time : %d/%d/%d %d:%d:%d ", tpdu.data.statusRep.timeStamp.time.absolute.year, tpdu.data.statusRep.timeStamp.time.absolute.month, tpdu.data.statusRep.timeStamp.time.absolute.day,
239                         tpdu.data.statusRep.timeStamp.time.absolute.hour, tpdu.data.statusRep.timeStamp.time.absolute.minute, tpdu.data.statusRep.timeStamp.time.absolute.second);
240                 MSG_DEBUG("tpdu.data.statusRep.dischargeTime.time : %d/%d/%d %d:%d:%d ", tpdu.data.statusRep.dischargeTime.time.absolute.year, tpdu.data.statusRep.dischargeTime.time.absolute.month, tpdu.data.statusRep.dischargeTime.time.absolute.day,
241                         tpdu.data.statusRep.dischargeTime.time.absolute.hour, tpdu.data.statusRep.dischargeTime.time.absolute.minute, tpdu.data.statusRep.dischargeTime.time.absolute.second);
242                 MSG_DEBUG("tpdu.data.statusRep.userData.headerCnt : %d", tpdu.data.statusRep.userData.headerCnt);
243                 MSG_DEBUG("tpdu.data.statusRep.userData.length : %d", tpdu.data.statusRep.userData.length);
244                 MSG_DEBUG("tpdu.data.statusRep.userData.data : %s", tpdu.data.statusRep.userData.data);
245                 MSG_DEBUG("#####################################################");
246         }
247
248         MsgDisplayUnlock();
249
250         try {
251                 if (tpdu.tpduType == SMS_TPDU_DELIVER) {
252                         if (tpdu.data.deliver.dcs.msgClass == SMS_MSG_CLASS_2) {
253                                 /* For GCF test, 34.2.5.3 */
254                                 SmsPluginSimMsg::instance()->setSmsData((const char*)pDataPackage->Sca, (const char *)pDataPackage->szData, pDataPackage->MsgLength);
255                         }
256
257                         if (SmsPluginConcatHandler::instance()->IsConcatMsg(&(tpdu.data.deliver.userData)) == true ||
258                                 SmsPluginWapPushHandler::instance()->IsWapPushMsg(&(tpdu.data.deliver.userData)) == true) {
259                                 /* Call Concat Msg Handler */
260                                 SmsPluginConcatHandler::instance()->handleConcatMsg(handle, &tpdu);
261                         } else {
262                                 /* Call Event Handler */
263                                 SmsPluginEventHandler::instance()->handleMsgIncoming(handle, &tpdu);
264                         }
265                 } else if (tpdu.tpduType == SMS_TPDU_STATUS_REP) {
266                         /* Call Event Handler */
267                         SmsPluginEventHandler::instance()->handleMsgIncoming(handle, &tpdu);
268                 }
269         } catch (MsgException& e) {
270                 MSG_FATAL("%s", e.what());
271                 return;
272         }
273 }
274
275
276 void TapiEventCbMsgIncoming(TapiHandle *handle, const char *noti_id, void *data, void *user_data)
277 {
278         MSG_SEC_DEBUG("TapiEventCbMsgIncoming is called. noti_id [%s]", noti_id);
279
280         if (data == NULL) {
281                 MSG_ERR("Error. data is NULL.");
282                 return;
283         }
284
285         TelSmsCbMsg_t *pCbMsg = (TelSmsCbMsg_t*)data;
286
287         try {
288                 SmsPluginCbMsgHandler::instance()->handleCbMsg(handle, pCbMsg);
289         } catch (MsgException& e) {
290                 MSG_FATAL("%s", e.what());
291                 return;
292         }
293 }
294
295
296 void TapiEventEtwsMsgIncoming(TapiHandle *handle, const char *noti_id, void *data, void *user_data)
297 {
298         MSG_SEC_DEBUG("TapiEventEtwsMsgIncoming is called. noti_id [%s]", noti_id);
299
300         if (data == NULL) {
301                 MSG_ERR("Error. data is NULL.");
302                 return;
303         }
304
305         TelSmsEtwsMsg_t *pEtwsMsg = (TelSmsEtwsMsg_t*)data;
306
307         try {
308                 SmsPluginCbMsgHandler::instance()->handleEtwsMsg(handle, pEtwsMsg);
309         } catch (MsgException& e) {
310                 MSG_FATAL("%s", e.what());
311                 return;
312         }
313 }
314
315
316 void TapiEventDeliveryReportCNF(TapiHandle *handle, int result, void *data, void *user_data)
317 {
318         MSG_DEBUG("TapiEventDeliveryReportCNF is called. : result = [%d]", result);
319
320         return;
321 }
322
323
324 void TapiEventGetSimMsgCnt(TapiHandle *handle, int result, void *data, void *user_data)
325 {
326         MSG_DEBUG("TapiEventGetSimMsgCnt is called.");
327
328         if (result != TAPI_API_SUCCESS || data == NULL) {
329                 MSG_ERR("Error. data is NULL. result:[0x%x]", result);
330                 MSG_SIM_COUNT_S simCnt;
331                 memset(&simCnt, 0x00, sizeof(MSG_SIM_COUNT_S));
332                 SmsPluginSimMsg::instance()->setSimMsgCntEvent(handle, &simCnt);
333                 return;
334         }
335
336         SmsPluginSimMsg::instance()->setSimMsgCntEvent(handle, (MSG_SIM_COUNT_S *)data);
337 }
338
339
340 void TapiEventGetSimMsg(TapiHandle *handle, int result, void *data, void *user_data)
341 {
342         MSG_DEBUG("TapiEventGetSimMsg is called.");
343
344         if (result != TAPI_API_SUCCESS || data == NULL) {
345                 MSG_ERR("Error!! result [0x%x]", result);
346
347                 SmsPluginSimMsg::instance()->setSimMsgEvent(handle, NULL, false);
348
349                 return;
350         }
351
352
353         TelSmsData_t* pSmsTpdu = (TelSmsData_t*)data;
354
355         int *simIdList = (int *)user_data;
356
357         /* Reading TelSmsData_t */
358         MSG_DEBUG("sim index %d", pSmsTpdu->SimIndex);
359         MSG_DEBUG("status %d", pSmsTpdu->MsgStatus);
360         MSG_DEBUG("sim msg [%s]", pSmsTpdu->SmsData.szData);
361
362         /* Reading TelSmsDatapackageInfo_t */
363         if (pSmsTpdu->SmsData.MsgLength > MAX_TPDU_DATA_LEN) {
364                 MSG_DEBUG("WARNING: tpdu_len > MAX_SMS_TPDU_SIZE [%d] bytes. setting to 0.", pSmsTpdu->SmsData.MsgLength);
365
366                 SmsPluginSimMsg::instance()->setSimMsgEvent(handle, NULL, false);
367
368                 return;
369         }
370
371         SMS_TPDU_S tpdu;
372
373         /* decode Tpdu */
374         SmsPluginTpduCodec::decodeTpdu(pSmsTpdu->SmsData.szData, pSmsTpdu->SmsData.MsgLength, &tpdu);
375
376         MSG_DEBUG("Sim Message Type [%d]", tpdu.tpduType);
377
378         bool bRead = false;
379
380         /* set read status */
381         if (pSmsTpdu->MsgStatus == TAPI_NETTEXT_STATUS_READ)
382                 bRead = true;
383         else if (pSmsTpdu->MsgStatus == TAPI_NETTEXT_STATUS_UNREAD)
384                 bRead = false;
385
386         if (tpdu.tpduType == SMS_TPDU_DELIVER) {
387                 if (tpdu.data.deliver.dcs.codingScheme == SMS_CHARSET_8BIT && tpdu.data.deliver.pid == 0x11) {
388                         MSG_DEBUG("Unsupported message!!");
389                         SmsPluginSimMsg::instance()->setSimMsgEvent(handle, NULL, false);
390                         return;
391                 }
392
393                 MSG_DEBUG("headerCnt [%d]", tpdu.data.deliver.userData.headerCnt);
394                 for (int i = 0; i < tpdu.data.deliver.userData.headerCnt; i++) {
395                         /* Handler Concatenated Message */
396                         if (tpdu.data.deliver.userData.header[i].udhType == SMS_UDH_CONCAT_8BIT ||
397                                 tpdu.data.deliver.userData.header[i].udhType == SMS_UDH_CONCAT_16BIT) {
398                                 SmsPluginConcatHandler::instance()->handleSimConcatMsg(handle, &tpdu, pSmsTpdu->SimIndex, bRead, simIdList);
399                                 return;
400                         }
401
402                         if (tpdu.data.deliver.userData.header[i].udhType == SMS_UDH_SPECIAL_SMS) {
403                                 MSG_DEBUG("Unsupported Special SMS!!");
404                                 SmsPluginSimMsg::instance()->setSimMsgEvent(handle, NULL, false);
405                                 return;
406                         }
407                 }
408         } else if (tpdu.tpduType == SMS_TPDU_SUBMIT) {
409                 if (tpdu.data.submit.dcs.codingScheme == SMS_CHARSET_8BIT && tpdu.data.submit.pid == 0x11) {
410                         MSG_DEBUG("Unsupported message!!");
411                         SmsPluginSimMsg::instance()->setSimMsgEvent(handle, NULL, false);
412                         return;
413                 }
414                 MSG_DEBUG("headerCnt [%d]", tpdu.data.submit.userData.headerCnt);
415
416                 for (int i = 0; i < tpdu.data.submit.userData.headerCnt; i++) {
417                         /* Handler Concatenated Message */
418                         if (tpdu.data.submit.userData.header[i].udhType == SMS_UDH_CONCAT_8BIT ||
419                                 tpdu.data.submit.userData.header[i].udhType == SMS_UDH_CONCAT_16BIT) {
420                                 SmsPluginConcatHandler::instance()->handleSimConcatMsg(handle, &tpdu, pSmsTpdu->SimIndex, bRead, simIdList);
421                                 return;
422                         }
423                 }
424         }
425
426         /* Make MSG_MESSAGE_INFO_S */
427         MSG_MESSAGE_INFO_S msgInfo;
428         memset(&msgInfo, 0x00, sizeof(MSG_MESSAGE_INFO_S));
429
430         /* set storage id */
431         msgInfo.storageId = MSG_STORAGE_SIM;
432
433         msgInfo.addressList = NULL;
434         unique_ptr<MSG_ADDRESS_INFO_S*, void(*)(MSG_ADDRESS_INFO_S**)> addressListBuf(&msgInfo.addressList, unique_ptr_deleter);
435
436         SmsPluginEventHandler::instance()->convertTpduToMsginfo(&tpdu, &msgInfo);
437
438         msgInfo.sim_idx = SmsPluginDSHandler::instance()->getSimIndex(handle);
439
440         if (tpdu.tpduType == SMS_TPDU_DELIVER && tpdu.data.deliver.dcs.bMWI == true) {
441                 if (tpdu.data.deliver.pid == 0x20 && tpdu.data.deliver.originAddress.ton == SMS_TON_ALPHANUMERIC) {
442                         char keyName[MAX_VCONFKEY_NAME_LEN];
443                         char *voiceNumber = NULL;
444                         char *voiceAlphaId = NULL;
445
446                         memset(keyName, 0x00, sizeof(keyName));
447                         snprintf(keyName, sizeof(keyName), "%s/%d", VOICEMAIL_NUMBER, msgInfo.sim_idx);
448                         if (MsgSettingGetString(keyName, &voiceNumber) != MSG_SUCCESS) {
449                                 MSG_INFO("MsgSettingGetString() is failed");
450                         }
451
452                         memset(keyName, 0x00, sizeof(keyName));
453                         snprintf(keyName, sizeof(keyName), "%s/%d", VOICEMAIL_ALPHA_ID, msgInfo.sim_idx);
454                         if (MsgSettingGetString(keyName, &voiceAlphaId) != MSG_SUCCESS) {
455                                 MSG_INFO("MsgSettingGetString() is failed");
456                         }
457
458                         memset(msgInfo.addressList[0].addressVal, 0x00, sizeof(msgInfo.addressList[0].addressVal));
459                         memset(msgInfo.addressList[0].displayName, 0x00, sizeof(msgInfo.addressList[0].displayName));
460
461                         if (voiceNumber) {
462                                 snprintf(msgInfo.addressList[0].addressVal, sizeof(msgInfo.addressList[0].addressVal), "%s", voiceNumber);
463                                 free(voiceNumber);
464                                 voiceNumber = NULL;
465                         }
466
467                         if (voiceAlphaId) {
468                                 snprintf(msgInfo.addressList[0].displayName, sizeof(msgInfo.addressList[0].displayName), "%s", voiceAlphaId);
469                                 free(voiceAlphaId);
470                                 voiceAlphaId = NULL;
471                         }
472
473                         memset(msgInfo.msgText, 0x00, sizeof(msgInfo.msgText));
474                         snprintf(msgInfo.msgText, sizeof(msgInfo.msgText), "Voice message");
475                 }
476         } else if (tpdu.tpduType == SMS_TPDU_SUBMIT) {
477                 msgInfo.displayTime =  time(NULL);
478         }
479
480         /* set read status */
481         msgInfo.bRead = bRead;
482
483         simIdList[0] = pSmsTpdu->SimIndex + 1;
484         /* Print MSG_MESSAGE_INFO_S */
485         MSG_DEBUG("############# Convert  tpdu values to Message Info values ####################");
486         MSG_DEBUG("msgInfo.msgId : %d", msgInfo.msgId);
487         MSG_DEBUG("msgInfo.nAddressCnt : %d", msgInfo.nAddressCnt);
488         MSG_DEBUG("msgInfo.addressList[0].addressType : %d", msgInfo.addressList[0].addressType);
489         MSG_SEC_DEBUG("msgInfo.addressList[0].addressVal : %s", msgInfo.addressList[0].addressVal);
490         MSG_SEC_DEBUG("msgInfo.addressList[0].displayName : %s", msgInfo.addressList[0].displayName);
491         MSG_DEBUG("msgInfo.priority : %d", msgInfo.priority);
492         MSG_DEBUG("msgInfo.bProtected : %d", msgInfo.bProtected);
493         MSG_DEBUG("msgInfo.bRead : %d", msgInfo.bRead);
494         MSG_DEBUG("msgInfo.bTextSms : %d", msgInfo.bTextSms);
495         MSG_DEBUG("msgInfo.direction : %d", msgInfo.direction);
496         MSG_DEBUG("msgInfo.msgType.mainType : %d", msgInfo.msgType.mainType);
497         MSG_DEBUG("msgInfo.msgType.subType : %d", msgInfo.msgType.subType);
498         MSG_DEBUG("msgInfo.msgType.classType : %d", msgInfo.msgType.classType);
499         MSG_DEBUG("msgInfo.displayTime : %d", msgInfo.displayTime);
500         MSG_DEBUG("msgInfo.dataSize : %d", msgInfo.dataSize);
501         if (msgInfo.bTextSms == true)
502                 MSG_SEC_DEBUG("msgInfo.msgText : %s", msgInfo.msgText);
503         else
504                 MSG_SEC_DEBUG("msgInfo.msgData : %s", msgInfo.msgData);
505         MSG_DEBUG("msgInfo.sim_idx : %d", msgInfo.sim_idx);
506         MSG_DEBUG("###############################################################");
507
508         /* Call Event Handler */
509         SmsPluginSimMsg::instance()->setSimMsgEvent(handle, &msgInfo, true);
510 }
511
512
513 void TapiEventSaveSimMsg(TapiHandle *handle, int result, void *data, void *user_data)
514 {
515         MSG_DEBUG("TapiEventSaveSimMsg is called. result [%d]", result);
516
517         int simId = -1;
518
519         if (data != NULL)
520                 simId = *((int*)data);
521         else
522                 MSG_ERR("Data(SIM Msg ID) is NULL");
523
524         SmsPluginSimMsg::instance()->setSaveSimMsgEvent(handle, simId, result);
525 }
526
527
528 void TapiEventSaveClass2Msg(TapiHandle *handle, int result, void *data, void *user_data)
529 {
530         MSG_DEBUG("TapiEventSaveClass2Msg is called. result [%d]", result);
531
532         int simId = -1;
533
534         if (data != NULL) {
535                 simId = *((int*)data);
536                 MSG_DEBUG("SIM Msg ID : %d", simId);
537         } else {
538                 MSG_ERR("Data(SIM Msg ID) is NULL");
539         }
540
541         MSG_MESSAGE_INFO_S *pMsgInfo = (MSG_MESSAGE_INFO_S *)user_data;
542
543         SmsPluginSimMsg::instance()->setSaveClass2MsgEvent(handle, simId, result, pMsgInfo);
544
545         if (result == TAPI_NETTEXT_SENDSMS_SUCCESS)
546                 SmsPluginSimMsg::instance()->setSimEvent((msg_sim_id_t)simId, true);
547         else
548                 SmsPluginSimMsg::instance()->setSimEvent((msg_sim_id_t)0, false);
549
550         if (pMsgInfo) {
551                 if (pMsgInfo->addressList) {
552                         delete[] pMsgInfo->addressList;
553                         pMsgInfo->addressList = NULL;
554                 }
555                 free(pMsgInfo);
556                 pMsgInfo = NULL;
557         }
558 }
559
560
561 void TapiEventDeleteSimMsg(TapiHandle *handle, int result, void *data, void *user_data)
562 {
563         MSG_DEBUG("TapiEventDeleteSimMsg is called. result [%d]", result);
564
565         if (result != TAPI_API_SUCCESS || data == NULL) {
566                 MSG_ERR("Error. data is NULL. result:0x%x", result);
567                 SmsPluginSimMsg::instance()->setDelSimEvent(-1, false);
568                 return;
569         }
570
571         int sim_id = *((int*)data);
572
573         SmsPluginSimMsg::instance()->setDelSimEvent(sim_id, true);
574 }
575
576
577 void TapiEventSetConfigData(TapiHandle *handle, int result, void *data, void *user_data)
578 {
579         MSG_DEBUG("TapiEventSetConfigData is called.");
580
581         if (data == NULL) {
582                 MSG_ERR("Error. data is NULL. result:%d", result);
583                 SmsPluginSetting::instance()->setResultFromSim(false);
584                 return;
585         }
586
587         TelSmsSetResponse* responseType = (TelSmsSetResponse*)data;
588
589         MSG_DEBUG("responseType : [%d]", *responseType);
590
591         switch (*responseType) {
592         case TAPI_NETTEXT_SETPREFERREDBEARER_RSP :
593                 MSG_DEBUG("TAPI_NETTEXT_SETPREFERREDBEARER_RSP is called");
594                 break;
595
596         case TAPI_NETTEXT_SETPARAMETERS_RSP :
597                 MSG_DEBUG("TAPI_NETTEXT_SETPARAMETERS_RSP is called");
598                 break;
599
600         case TAPI_NETTEXT_CBSETCONFIG_RSP :
601                 MSG_DEBUG("TAPI_NETTEXT_CBSETCONFIG_RSP is called");
602                 break;
603
604         case TAPI_NETTEXT_SETMEMORYSTATUS_RSP :
605                 MSG_DEBUG("TAPI_NETTEXT_SETMEMORYSTATUS_RSP is called");
606                 break;
607
608         case TAPI_NETTEXT_SETMESSAGESTATUS_RSP :
609                 MSG_DEBUG("TAPI_NETTEXT_SETMESSAGESTATUS_RSP is called");
610                 break;
611
612         default :
613                 MSG_DEBUG("Unknown Response is called [%d]", *responseType);
614                 break;
615         }
616
617         bool bRet = true;
618
619         MSG_DEBUG("status : [%d]", (TelSmsCause_t)result);
620
621         if ((TelSmsCause_t)result != TAPI_NETTEXT_SUCCESS) bRet = false;
622
623         if (*responseType == TAPI_NETTEXT_SETMESSAGESTATUS_RSP)
624                 SmsPluginSimMsg::instance()->setSimEvent(0, bRet);
625         else
626                 SmsPluginSetting::instance()->setResultFromSim(bRet);
627 }
628
629
630 void TapiEventGetParamCnt(TapiHandle *handle, int result, void *data, void *user_data)
631 {
632         MSG_DEBUG("TapiEventGetParamCnt is called.");
633
634         if (result != TAPI_API_SUCCESS || data == NULL) {
635                 MSG_ERR("Error. data is NULL. result:0x%x", result);
636                 SmsPluginSetting::instance()->setParamCntEvent(0);
637                 return;
638         }
639
640         int paramCnt = 0;
641         paramCnt = *((int*)data);
642
643         SmsPluginSetting::instance()->setParamCntEvent(paramCnt);
644 }
645
646
647 void TapiEventGetParam(TapiHandle *handle, int result, void *data, void *user_data)
648 {
649         MSG_DEBUG("TapiEventGetConfigData is called.");
650
651         if (result != TAPI_API_SUCCESS || data == NULL) {
652                 MSG_ERR("Error. data is NULL. result:0x%x", result);
653                 SmsPluginSetting::instance()->setParamEvent(handle, NULL, -1, false);
654                 return;
655         }
656
657         TelSmsParams_t* smsParam = (TelSmsParams_t*)data;
658
659         int alphaIdLen = 0;
660         int addrLen = 0;
661         MSG_SMSC_DATA_S smscData = {0, };
662
663         /*Check Alpha ID value*/
664         alphaIdLen = smsParam->AlphaIdLen;
665         MSG_DEBUG("alphaId_len[%d]", alphaIdLen);
666
667         if (alphaIdLen < 0 || alphaIdLen > SMSC_NAME_MAX) {
668                 MSG_DEBUG("Wrong Alpha ID Length[%d]", alphaIdLen);
669
670                 SmsPluginSetting::instance()->setParamEvent(handle, NULL, -1, false);
671
672                 return;
673         }
674
675
676         /*Check Address value*/
677         addrLen = smsParam->TpSvcCntrAddr.DialNumLen;
678
679         if (addrLen > SMSC_ADDR_MAX) {
680                 MSG_DEBUG("addrLen is too long: %d", addrLen);
681                 SmsPluginSetting::instance()->setParamEvent(handle, NULL, -1, false);
682                 return;
683         } else if (addrLen < 2) {
684                 MSG_DEBUG("addrLen is too short: %d", addrLen);
685                 SmsPluginSetting::instance()->setParamEvent(handle, NULL, -1, false);
686                 return;
687         }
688
689         MSG_DEBUG("addrLen : %d", addrLen);
690
691         /*SMSP Parameter Indicator value*/
692         MSG_DEBUG("ParamIndicator[%02x]", smsParam->ParamIndicator);
693
694         /*Get SMSC Address*/
695         if (0x00 == (0x02 & smsParam->ParamIndicator)) {
696                 MSG_DEBUG("record index[%d]", (int)smsParam->RecordIndex);
697
698                 MSG_DEBUG("TON : %d", smsParam->TpSvcCntrAddr.Ton);
699                 MSG_DEBUG("NPI : %d", smsParam->TpSvcCntrAddr.Npi);
700
701                 smscData.smscAddr.ton = smsParam->TpSvcCntrAddr.Ton;
702                 smscData.smscAddr.npi = smsParam->TpSvcCntrAddr.Npi;
703
704                 SmsPluginParamCodec paramCodec;
705
706                 memset(smscData.smscAddr.address, 0x00, SMSC_ADDR_MAX+1);
707                 paramCodec.decodeSMSC(smsParam->TpSvcCntrAddr.szDiallingNum, addrLen, smscData.smscAddr.ton, smscData.smscAddr.address);
708
709                 MSG_SEC_DEBUG("SMSC Address : [%s]", smscData.smscAddr.address);
710
711                 memset(smscData.name, 0x00, SMSC_NAME_MAX+1);
712                 memcpy(smscData.name, smsParam->szAlphaId, alphaIdLen);
713                 smscData.name[alphaIdLen] = '\0';
714
715                 MSG_SEC_DEBUG("SMSC Name : [%s]", smscData.name);
716         } else {
717                 MSG_DEBUG("SMSC Address is not present");
718
719                 SmsPluginSetting::instance()->setParamEvent(handle, NULL, -1, false);
720
721                 return;
722         }
723
724         /*Get the PID value*/
725         if (0x00 == (0x04 & smsParam->ParamIndicator)) {
726                 SMS_PID_T pid = (SMS_PID_T)smsParam->TpProtocolId;
727
728                 MSG_DEBUG("smsParam->TpProtocolId : %d", smsParam->TpProtocolId);
729
730                 switch (pid) {
731                 case SMS_PID_NORMAL:
732                         smscData.pid = MSG_PID_TEXT;
733                         break;
734                 case SMS_PID_VOICE:
735                         smscData.pid = MSG_PID_VOICE;
736                         break;
737                 case SMS_PID_TELEX:
738                         smscData.pid = MSG_PID_FAX;
739                         break;
740                 case SMS_PID_x400:
741                         smscData.pid = MSG_PID_X400;
742                         break;
743                 case SMS_PID_ERMES:
744                         smscData.pid = MSG_PID_ERMES;
745                         break;
746                 case SMS_PID_EMAIL:
747                         smscData.pid = MSG_PID_EMAIL;
748                         break;
749                 default:
750                         smscData.pid = MSG_PID_TEXT;
751                         break;
752                 }
753
754                 MSG_DEBUG("smscData.pid : %d", smscData.pid);
755         } else {
756                 MSG_DEBUG("PID is not present");
757                 smscData.pid = MSG_PID_TEXT;
758                 MSG_DEBUG("MSG_PID_TEXT is inserted to PID");
759         }
760
761 #if 0
762         /*Get the DCS value*/
763         if (0x00 == (0x08 & smsParam->ParamIndicator)) {
764                 smscList.smscData[index].dcs = smsParam->TpDataCodingScheme;
765                 MSG_DEBUG("dcs : %d", smscList.smscData[index].dcs);
766         } else {
767                 smscList.smscData[index].dcs = MSG_ENCODE_GSM7BIT;
768                 MSG_DEBUG("DCS is not present");
769         }
770 #endif
771
772         /*Get the ValidityPeriod value*/
773         if (0x00 == (0x10 & smsParam->ParamIndicator)) {
774                 smscData.valPeriod = smsParam->TpValidityPeriod;
775                 MSG_DEBUG("valPeriod : %d", smscData.valPeriod);
776         } else {
777                 smscData.valPeriod = 0;
778
779                 MSG_DEBUG("Validity Period is not present");
780         }
781
782         SmsPluginSetting::instance()->setParamEvent(handle, &smscData, (int)smsParam->RecordIndex, true);
783 }
784
785
786 void TapiEventSetSmscInfo(TapiHandle *handle, int result, void *data, void *user_data)
787 {
788         MSG_DEBUG("TapiEventSetSmscInfo is called. result=[%d]", result);
789
790         if (result != TAPI_API_SUCCESS)
791                 SmsPluginSetting::instance()->setResultFromSim(false);
792         else
793                 SmsPluginSetting::instance()->setResultFromSim(true);
794 }
795
796
797 void TapiEventGetCBConfig(TapiHandle *handle, int result, void *data, void *user_data)
798 {
799         MSG_DEBUG("TapiEventGetCBConfig is called.");
800
801         MSG_CBMSG_OPT_S cbOpt = {0};
802
803         int simIndex = SmsPluginDSHandler::instance()->getSimIndex(handle);
804
805         if (result != TAPI_API_SUCCESS || data == NULL || simIndex == 0) {
806                 MSG_ERR("Error. data is NULL. result:0x%x, simIndex:%d", result, simIndex);
807
808                 SmsPluginSetting::instance()->setCbConfigEvent(handle, NULL, false);
809
810                 return;
811         }
812
813         TelSmsCbConfig_t* pCBConfig = (TelSmsCbConfig_t*)data;
814
815         cbOpt.bReceive = (bool)pCBConfig->CBEnabled;
816
817         cbOpt.maxSimCnt = TAPI_NETTEXT_SMS_CBMI_LIST_SIZE_MAX;
818
819         cbOpt.simIndex = simIndex;
820
821         MSG_DEBUG("Sim Index [%d], Receive [%d], Max SIM Count [%d]", simIndex, cbOpt.bReceive, cbOpt.maxSimCnt);
822
823         cbOpt.channelData.channelCnt = pCBConfig->MsgIdRangeCount;
824
825         if (cbOpt.channelData.channelCnt > CB_CHANNEL_MAX) {
826                 MSG_DEBUG("Channel Count [%d] from TAPI is over MAX", cbOpt.channelData.channelCnt);
827                 cbOpt.channelData.channelCnt = CB_CHANNEL_MAX;
828         }
829
830         MSG_DEBUG("Channel Count [%d]", cbOpt.channelData.channelCnt);
831
832         for (int i = 0; i < cbOpt.channelData.channelCnt; i++) {
833                 cbOpt.channelData.channelInfo[i].bActivate = pCBConfig->MsgIDs[i].Net3gpp.Selected;
834                 cbOpt.channelData.channelInfo[i].from = pCBConfig->MsgIDs[i].Net3gpp.FromMsgId;
835                 cbOpt.channelData.channelInfo[i].to = pCBConfig->MsgIDs[i].Net3gpp.ToMsgId;
836                 memset(cbOpt.channelData.channelInfo[i].name, 0x00, CB_CHANNEL_NAME_MAX+1);
837
838                 MSG_DEBUG("Channel FROM [%d], Channel TO [%d] ", cbOpt.channelData.channelInfo[i].from, cbOpt.channelData.channelInfo[i].to);
839         }
840
841         SmsPluginSetting::instance()->setCbConfigEvent(handle, &cbOpt, true);
842 }
843
844 void TapiEventSetMailboxInfo(TapiHandle *handle, int result, void *data, void *user_data)
845 {
846         MSG_DEBUG("TapiEventSetMailboxInfo is called. result = [%d]", result);
847
848         bool bRet = true;
849         bool *bShowError = (bool*)user_data;
850
851         if (result != TAPI_SIM_ACCESS_SUCCESS && *bShowError == true)
852                 bRet = false;
853
854         SmsPluginSetting::instance()->setResultFromSim(bRet);
855 }
856
857 void TapiEventGetMailboxInfo(TapiHandle *handle, int result, void *data, void *user_data)
858 {
859         MSG_DEBUG("TapiEventGetMailboxInfo is called. result=[%d]", result);
860
861         if (result == TAPI_API_SIM_SERVICE_IS_DISABLED) {
862                 MSG_INFO("result is TAPI_API_SIM_SERVICE_IS_DISABLED");
863                 char keyName[MAX_VCONFKEY_NAME_LEN];
864                 int sim_idx = SmsPluginDSHandler::instance()->getSimIndex(handle);
865                 char *voiceNum = NULL;
866                 memset(keyName, 0x00, sizeof(keyName));
867                 snprintf(keyName, sizeof(keyName), "%s/%d", VOICEMAIL_NUMBER, sim_idx);
868                 if (MsgSettingGetString(keyName, &voiceNum) != MSG_SUCCESS) {
869                         MSG_INFO("MsgSettingGetString() is failed");
870                 }
871
872                 if (voiceNum && strlen(voiceNum)) {
873                         MSG_DEBUG("Voice mailbox number exist in vconf");
874                         SmsPluginSetting::instance()->setMailboxInfoEvent(handle, NULL, true, false);
875                         free(voiceNum);
876                         voiceNum = NULL;
877                         return;
878                 } else {
879                         SmsPluginSetting::instance()->setMailboxInfoEvent(handle, NULL, false, false);
880                         if (voiceNum) {
881                                 free(voiceNum);
882                                 voiceNum = NULL;
883                         }
884                         return;
885                 }
886         } else if (result != TAPI_SIM_ACCESS_SUCCESS || data == NULL) {
887                 MSG_ERR("Error. data is NULL.");
888                 /*If result is not TAPI_SIM_ACCESS_SUCCESS, set bMbdnEnable to false*/
889                 SmsPluginSetting::instance()->setMailboxInfoEvent(handle, NULL, false, false);
890                 return;
891         }
892
893         TelSimMailboxList_t *list = (TelSimMailboxList_t *)data;
894         SMS_SIM_MAILBOX_LIST_S mbList = {0, };
895
896         if (list->count <= 0) {
897                 MSG_INFO("Mailbox list is empty");
898                 SmsPluginSetting::instance()->setMailboxInfoEvent(handle, NULL, false, true);
899                 return;
900         }
901
902         mbList.count = list->count;
903
904         for (int i = 0; i < mbList.count; i++) {
905                 mbList.list[i].b_cphs = list->list[i].b_cphs;
906                 mbList.list[i].alpha_id_max_len = list->list[i].alpha_id_max_len;
907                 mbList.list[i].mb_type = list->list[i].mb_type;
908                 mbList.list[i].profile_num = list->list[i].profile_num;
909                 mbList.list[i].rec_index = list->list[i].rec_index;
910                 mbList.list[i].ton = list->list[i].ton;
911                 mbList.list[i].npi = list->list[i].npi;
912                 snprintf(mbList.list[i].alpha_id, sizeof(mbList.list[i].alpha_id), "%s", list->list[i].alpha_id);
913                 snprintf(mbList.list[i].num, sizeof(mbList.list[i].num), "%s", list->list[i].num);
914                 mbList.list[i].cc_id = list->list[i].cc_id;
915                 mbList.list[i].ext1_id = list->list[i].ext1_id;
916                 mbList.list[i].num_len = strlen(mbList.list[i].num);
917         }
918
919         SmsPluginSetting::instance()->setMailboxInfoEvent(handle, &mbList, true, true);
920 }
921
922 void TapiEventSetMwiInfo(TapiHandle *handle, int result, void *data, void *user_data)
923 {
924         MSG_DEBUG("TapiEventSetMwiInfo is called. result = [%d]", result);
925 }
926
927 void TapiEventGetMwiInfo(TapiHandle *handle, int result, void *data, void *user_data)
928 {
929         MSG_DEBUG("TapiEventGetMwiInfo is called.");
930
931         if (result != TAPI_SIM_ACCESS_SUCCESS || data == NULL) {
932                 MSG_ERR("Error. data is NULL. result:0x%x", result);
933                 SmsPluginSetting::instance()->setMwiInfoEvent(handle, NULL, false);
934
935                 return;
936         }
937
938         TelSimMessageWaitingResp_t *MwiInfo = (TelSimMessageWaitingResp_t *)data;
939         SMS_SIM_MWI_INFO_S simMwiInfo = {0, };
940
941         memcpy(&simMwiInfo, MwiInfo, sizeof(SMS_SIM_MWI_INFO_S));
942
943         SmsPluginSetting::instance()->setMwiInfoEvent(handle, &simMwiInfo, true);
944 }
945
946 void TapiEventGetMsisdnInfo(TapiHandle *handle, int result, void *data, void *user_data)
947 {
948         MSG_DEBUG("TapiEventGetMsisdnInfo is called.");
949
950         bool bRet = false;
951
952         if (result != TAPI_SIM_ACCESS_SUCCESS || data == NULL) {
953                 MSG_ERR("Error. data is NULL. result:0x%x", result);
954                 SmsPluginSetting::instance()->setResultFromSim(bRet);
955                 return;
956         }
957
958         TelSimMsisdnList_t *list = (TelSimMsisdnList_t *)data;
959
960         for (int i = 0; i < list->count; i++) {
961                 if (list->list[i].num[0] != '\0') {
962                         char keyName[MAX_VCONFKEY_NAME_LEN];
963                         int simIndex = SmsPluginDSHandler::instance()->getSimIndex(handle);
964
965                         memset(keyName, 0x00, sizeof(keyName));
966                         snprintf(keyName, sizeof(keyName), "%s/%d", MSG_SIM_MSISDN, simIndex);
967
968                         if (MsgSettingSetString(keyName, list->list[i].num) == MSG_SUCCESS) {
969                                 MSG_SEC_INFO("Get MSISDN from SIM : [%s]", list->list[i].num);
970                                 bRet = true;
971                         } else {
972                                 MSG_DEBUG("Getting MSISDN is failed!");
973                         }
974                         break;
975                 }
976         }
977
978         SmsPluginSetting::instance()->setResultFromSim(bRet);
979 }
980
981 void TapiEventGetSimServiceTable(TapiHandle *handle, int result, void *data, void *user_data)
982 {
983         MSG_DEBUG("TapiEventGetSimServiceTable is called.");
984
985     TelSimAccessResult_t access_rt = (TelSimAccessResult_t)result;
986     TelSimServiceTable_t *svct = (TelSimServiceTable_t *)data;
987
988         bool bRet = true;
989
990         if (access_rt != TAPI_SIM_ACCESS_SUCCESS || svct == NULL) {
991                 MSG_ERR("Error. data is NULL and access_rt [%d] failed", access_rt);
992                 SmsPluginSetting::instance()->setResultFromSim(false);
993                 return;
994         }
995
996         msg_error_t err = MSG_SUCCESS;
997
998         char sstKey[128];
999         char moCtrlKey[128];
1000
1001         int simIndex = SmsPluginDSHandler::instance()->getSimIndex(handle);
1002
1003         memset(sstKey, 0x00, sizeof(sstKey));
1004         snprintf(sstKey, sizeof(sstKey), "%s/%d", MSG_SIM_SERVICE_TABLE, simIndex);
1005
1006         memset(moCtrlKey, 0x00, sizeof(moCtrlKey));
1007         snprintf(moCtrlKey, sizeof(moCtrlKey), "%s/%d", MSG_SIM_MO_CONTROL, simIndex);
1008
1009         if (svct->sim_type == TAPI_SIM_CARD_TYPE_GSM) {
1010                 if (svct->table.sst.service[TAPI_SIM_SST_SMS] == 1) {
1011                         err = MsgSettingSetBool(sstKey, true);
1012                 } else {
1013                         err = MsgSettingSetBool(sstKey, false);
1014                 }
1015                 MSG_DEBUG("Setting result = [%d]", err);
1016
1017                 if (svct->table.sst.service[TAPI_SIM_SST_MO_SMS_CTRL_BY_SIM] == 1) {
1018                         err = MsgSettingSetBool(moCtrlKey, true);
1019                 } else {
1020                         err = MsgSettingSetBool(moCtrlKey, false);
1021                 }
1022                 MSG_DEBUG("Setting result = [%d]", err);
1023
1024         } else if (svct->sim_type == TAPI_SIM_CARD_TYPE_USIM) {
1025                 if (svct->table.ust.service[TAPI_SIM_UST_SMS] == 1) {
1026                         err = MsgSettingSetBool(sstKey, true);
1027                 } else {
1028                         err = MsgSettingSetBool(sstKey, false);
1029                 }
1030                 MSG_DEBUG("Setting result = [%d]", err);
1031
1032                 if (svct->table.ust.service[TAPI_SIM_UST_MO_SMS_CTRL] == 1) {
1033                         err = MsgSettingSetBool(moCtrlKey, true);
1034                 } else {
1035                         err = MsgSettingSetBool(moCtrlKey, false);
1036                 }
1037                 MSG_DEBUG("Setting result = [%d]", err);
1038
1039         } else {
1040                 MSG_DEBUG("Unknown SIM type value");
1041         }
1042
1043         SmsPluginSetting::instance()->setResultFromSim(bRet);
1044 }
1045
1046 void TapiEventSatSmsRefresh(TapiHandle *handle, int result, void *data, void *user_data)
1047 {
1048         MSG_DEBUG("TapiEventSatSmsRefresh is called.");
1049
1050         if (result != TAPI_API_SUCCESS || data == NULL) {
1051                 MSG_ERR("Error. data is NULL. result:0x%x", result);
1052                 return;
1053         }
1054
1055         try {
1056                 SmsPluginSatHandler::instance()->refreshSms(handle, data);
1057         } catch (MsgException& e) {
1058                 MSG_FATAL("%s", e.what());
1059                 return;
1060         }
1061 }
1062
1063
1064 void TapiEventSatSendSms(TapiHandle *handle, const char *noti_id, void *data, void *user_data)
1065 {
1066         MSG_DEBUG("TapiEventSatSendSms is called.");
1067
1068         if (data == NULL) {
1069                 MSG_ERR("Error. data is NULL.");
1070                 return;
1071         }
1072
1073         try {
1074                 SmsPluginSatHandler::instance()->sendSms(handle, data);
1075         } catch (MsgException& e) {
1076                 MSG_FATAL("%s", e.what());
1077                 return;
1078         }
1079 }
1080
1081
1082 void TapiEventSatMoSmsCtrl(TapiHandle *handle, const char *noti_id, void *data, void *user_data)
1083 {
1084         MSG_DEBUG("TapiEventSatMoSmsCtrl is called.");
1085
1086         if (data == NULL) {
1087                 MSG_ERR("Error. data is NULL.");
1088                 return;
1089         }
1090
1091         try {
1092                 SmsPluginSatHandler::instance()->ctrlSms(handle, data);
1093         } catch (MsgException& e) {
1094                 MSG_FATAL("%s", e.what());
1095                 return;
1096         }
1097 }
1098
1099 void TapiEventMemoryStatus(TapiHandle *handle, int result, void *data, void *user_data)
1100 {
1101         MSG_DEBUG("Tapi result is [%d]", result);
1102         if (result == TAPI_API_SUCCESS)
1103                 isMemAvailable = true;
1104 }
1105
1106 void TapiEventSetMsgStatus(TapiHandle *handle, int result, void *data, void *user_data)
1107 {
1108         MSG_DEBUG("TapiEventSetMsgStatus is called. result [%d]", result);
1109
1110         if (result != TAPI_API_SUCCESS || data == NULL) {
1111                 MSG_ERR("Error. data is NULL. result:0x%x", result);
1112                 SmsPluginSimMsg::instance()->setSimEvent((msg_sim_id_t)0, false);
1113                 return;
1114         }
1115
1116         msg_sim_id_t sim_id = *((msg_sim_id_t *)user_data);
1117
1118         SmsPluginSimMsg::instance()->setSimEvent(sim_id, true);
1119 }
1120
1121
1122 void TapiEventGetMeImei(TapiHandle *handle, int result, void *data, void *user_data)
1123 {
1124         MSG_SEC_DEBUG("TapiEventGetMeImei is called. result [%d]", result);
1125
1126         if (result != TAPI_API_SUCCESS || data == NULL) {
1127                 MSG_ERR("Error. data is NULL. result:0x%x", result);
1128                 SmsPluginSetting::instance()->setResultImei(false, NULL);
1129                 return;
1130         }
1131
1132         char *tmpImei = (char *)data;
1133
1134         SmsPluginSetting::instance()->setResultImei(true, tmpImei);
1135 }
1136
1137
1138 void TapiEventSimStatusChange(TapiHandle *handle, const char *noti_id, void *data, void *user_data)
1139 {
1140         MSG_DEBUG("TapiEventSimStatusChange is called.");
1141
1142         if (data == NULL) {
1143                 MSG_ERR("Error. data is NULL.");
1144                 return;
1145         }
1146
1147          int status = *(int *)data;
1148
1149          MSG_DEBUG("SIM Status [%d]", status);
1150
1151          if (status == TAPI_SIM_STATUS_SIM_INIT_COMPLETED) {
1152                  MSG_INFO("SIM Initialize by sim status change callback");
1153                  SmsPluginSetting::instance()->setSimChangeStatus(handle, false);
1154          }
1155 }
1156
1157 void TapiEventNetworkStatusChange(TapiHandle *handle, const char *noti_id, void *data, void *user_data)
1158 {
1159         MSG_DEBUG("TapiEventNetworkStatusChange is called.");
1160
1161         if (data == NULL) {
1162                 MSG_ERR("Error. data is NULL.");
1163                 return;
1164         }
1165
1166         TelNetworkServiceType_t *type = (TelNetworkServiceType_t *)data;
1167
1168         MSG_INFO("network status type [%d]", *type);
1169
1170         if (*type > TAPI_NETWORK_SERVICE_TYPE_SEARCH) {
1171                 /* Call Event Handler */
1172                 SmsPluginEventHandler::instance()->handleResendMessage();
1173         }
1174 }
1175
1176 void TapiEventSimRefreshed(TapiHandle *handle, const char *noti_id, void *data, void *user_data)
1177 {
1178         MSG_DEBUG("TapiEventSimRefreshed is called.");
1179
1180         SmsPluginSetting::instance()->SimRefreshCb(handle);
1181 }
1182
1183 /*==================================================================================================
1184                                      IMPLEMENTATION OF SmsPluginCallback - Member Functions
1185 ==================================================================================================*/
1186 SmsPluginCallback* SmsPluginCallback::pInstance = NULL;
1187
1188
1189 SmsPluginCallback::SmsPluginCallback()
1190 {
1191 }
1192
1193
1194 SmsPluginCallback::~SmsPluginCallback()
1195 {
1196         if (pInstance != NULL) {
1197                 delete pInstance;
1198                 pInstance = NULL;
1199         }
1200 }
1201
1202
1203 SmsPluginCallback* SmsPluginCallback::instance()
1204 {
1205         if (!pInstance)
1206                 pInstance = new SmsPluginCallback();
1207
1208         return pInstance;
1209 }
1210
1211
1212 void SmsPluginCallback::registerEvent()
1213 {
1214         TapiHandle *pTapiHandle;
1215
1216         int count = SmsPluginDSHandler::instance()->getTelHandleCount();
1217
1218         for (int i = 1; i <= count; ++i) {
1219                 pTapiHandle = SmsPluginDSHandler::instance()->getTelHandle(i);
1220 /*              int simIndex = SmsPluginDSHandler::instance()->getSimIndex(pTapiHandle); */
1221
1222                 if (tel_register_noti_event(pTapiHandle, TAPI_NOTI_SMS_DEVICE_READY, TapiEventDeviceReady, NULL) != TAPI_API_SUCCESS)
1223                         MSG_DEBUG("tel_register_noti_event is failed : [%s]", TAPI_NOTI_SMS_DEVICE_READY);
1224                 if (tel_register_noti_event(pTapiHandle, TAPI_NOTI_SMS_INCOM_MSG, TapiEventMsgIncoming, NULL) != TAPI_API_SUCCESS)
1225                         MSG_DEBUG("tel_register_noti_event is failed : [%s]", TAPI_NOTI_SMS_INCOM_MSG);
1226                 if (tel_register_noti_event(pTapiHandle, TAPI_NOTI_SMS_CB_INCOM_MSG, TapiEventCbMsgIncoming, NULL) != TAPI_API_SUCCESS)
1227                         MSG_DEBUG("tel_register_noti_event is failed : [%s]", TAPI_NOTI_SMS_CB_INCOM_MSG);
1228                 if (tel_register_noti_event(pTapiHandle, TAPI_NOTI_SMS_ETWS_INCOM_MSG, TapiEventEtwsMsgIncoming, NULL) != TAPI_API_SUCCESS)
1229                         MSG_DEBUG("tel_register_noti_event is failed : [%s]", TAPI_NOTI_SMS_ETWS_INCOM_MSG);
1230                 if (tel_register_noti_event(pTapiHandle, TAPI_NOTI_SAT_SEND_SMS, TapiEventSatSendSms, NULL) != TAPI_API_SUCCESS)
1231                         MSG_DEBUG("tel_register_noti_event is failed : [%s]", TAPI_NOTI_SAT_SEND_SMS);
1232                 if (tel_register_noti_event(pTapiHandle, TAPI_NOTI_SAT_MO_SM_CONTROL_RESULT, TapiEventSatMoSmsCtrl, NULL) != TAPI_API_SUCCESS)
1233                         MSG_DEBUG("tel_register_noti_event is failed : [%s]", TAPI_NOTI_SAT_MO_SM_CONTROL_RESULT);
1234                 if (tel_register_noti_event(pTapiHandle, TAPI_NOTI_SIM_STATUS, TapiEventSimStatusChange, NULL) != TAPI_API_SUCCESS)
1235                         MSG_DEBUG("tel_register_noti_event is failed : [%s]", TAPI_NOTI_SIM_STATUS);
1236                 if (tel_register_noti_event(pTapiHandle, TAPI_PROP_NETWORK_SERVICE_TYPE, TapiEventNetworkStatusChange, NULL) != TAPI_API_SUCCESS)
1237                         MSG_DEBUG("tel_register_noti_event is failed : [%s]", TAPI_PROP_NETWORK_SERVICE_TYPE);
1238                 if (tel_register_noti_event(pTapiHandle, TAPI_NOTI_SIM_REFRESHED, TapiEventSimRefreshed, NULL) != TAPI_API_SUCCESS)
1239                         MSG_DEBUG("tel_register_noti_event is failed : [%s]", TAPI_NOTI_SIM_REFRESHED);
1240 /*              if (tel_register_noti_event(pTapiHandle, TAPI_NOTI_SAT_REFRESH, TapiEventSatSmsRefresh, NULL) != TAPI_API_SUCCESS) */
1241 /*                      MSG_DEBUG("tel_register_noti_event is failed : [%s]", TAPI_NOTI_SAT_REFRESH); */
1242 /*              if (tel_register_noti_event(pTapiHandle, TAPI_NOTI_SAT_MO_SMS_CTRL, TapiEventSatMoSmsCtrl, NULL) != TAPI_API_SUCCESS) */
1243 /*                      MSG_DEBUG("tel_register_noti_event is failed : [%s]", TAPI_NOTI_SAT_MO_SMS_CTRL); */
1244         }
1245 }
1246
1247
1248 void SmsPluginCallback::deRegisterEvent()
1249 {
1250 }
1251