update tizen source
[framework/messaging/msg-service.git] / plugin / sms_plugin / SmsPluginCallback.cpp
1 /*
2 *
3 * Copyright (c) 2000-2012 Samsung Electronics Co., Ltd. All Rights Reserved.
4 *
5 * This file is part of msg-service.
6 *
7 * Contact: Jaeyun Jeong <jyjeong@samsung.com>
8 *          Sangkoo Kim <sangkoo.kim@samsung.com>
9 *          Seunghwan Lee <sh.cat.lee@samsung.com>
10 *          SoonMin Jung <sm0415.jung@samsung.com>
11 *          Jae-Young Lee <jy4710.lee@samsung.com>
12 *          KeeBum Kim <keebum.kim@samsung.com>
13 *
14 * PROPRIETARY/CONFIDENTIAL
15 *
16 * This software is the confidential and proprietary information of
17 * SAMSUNG ELECTRONICS ("Confidential Information"). You shall not
18 * disclose such Confidential Information and shall use it only in
19 * accordance with the terms of the license agreement you entered
20 * into with SAMSUNG ELECTRONICS.
21 *
22 * SAMSUNG make no representations or warranties about the suitability
23 * of the software, either express or implied, including but not limited
24 * to the implied warranties of merchantability, fitness for a particular
25 * purpose, or non-infringement. SAMSUNG shall not be liable for any
26 * damages suffered by licensee as a result of using, modifying or
27 * distributing this software or its derivatives.
28 *
29 */
30
31 #include <glib.h>
32 #include <pthread.h>
33
34 #include "MsgDebug.h"
35 #include "MsgException.h"
36 #include "SmsPluginEventHandler.h"
37 #include "SmsPluginCbMsgHandler.h"
38 #include "SmsPluginConcatHandler.h"
39 #include "SmsPluginWapPushHandler.h"
40 #include "SmsPluginSatHandler.h"
41 #include "SmsPluginParamCodec.h"
42 #include "SmsPluginTpduCodec.h"
43 #include "SmsPluginSimMsg.h"
44 #include "SmsPluginSetting.h"
45 #include "SmsPluginCallback.h"
46
47 extern "C"
48 {
49         #include <ITapiProductivity.h>
50 }
51
52
53 /*==================================================================================================
54                                      FUNCTION IMPLEMENTATION
55 ==================================================================================================*/
56 int TapiEventDeviceReady(const TelTapiEvent_t *pEvent, void*)
57 {
58         MSG_DEBUG("TapiEventDeviceReady is called. : request id = [%d] status = [%d]", pEvent->RequestId, pEvent->Status);
59
60         try
61         {
62                 // Call Event Handler
63                 SmsPluginEventHandler::instance()->setDeviceStatus();
64         }
65         catch (MsgException& e)
66         {
67                 MSG_FATAL("%s", e.what());
68                 return e.errorCode();
69         }
70
71         return 0;
72 }
73
74
75 int TapiEventSentStatus(const TelTapiEvent_t *pEvent, void*)
76 {
77         MSG_DEBUG("TapiEventSentStatus is called. : request id = [%d] status = [%d]", pEvent->RequestId, pEvent->Status);
78
79         MSG_NETWORK_STATUS_T netStatus;
80
81         // Convert TAPI status -> Messaging status
82         if ((TelSmsResponse_t)pEvent->Status == TAPI_NETTEXT_SENDSMS_SUCCESS)
83                 netStatus = MSG_NETWORK_SEND_SUCCESS;
84         else
85                 netStatus = MSG_NETWORK_SEND_FAIL;
86
87         try
88         {
89                 // Call Event Handler
90                 SmsPluginEventHandler::instance()->handleSentStatus(pEvent->RequestId, netStatus);
91
92                 // Call SAT Handler
93                 SmsPluginSatHandler::instance()->ctrlSms(netStatus);
94         }
95         catch (MsgException& e)
96         {
97                 MSG_FATAL("%s", e.what());
98                 return e.errorCode();
99         }
100
101         return 0;
102 }
103
104
105 int TapiEventMsgIncoming(const TelTapiEvent_t *pEvent, void*)
106 {
107         MSG_DEBUG("TapiEventMsgIncoming is called. Red Id [%d]", pEvent->RequestId);
108
109         if (pEvent->Status != TAPI_API_SUCCESS || pEvent->pData == NULL)
110         {
111                 MSG_DEBUG("Error. evt->pData is NULL.");
112                 return 0;
113         }
114
115         TelSmsDatapackageInfo_t* pDataPackage = (TelSmsDatapackageInfo_t*)pEvent->pData;
116
117         SMS_TPDU_S tpdu;
118
119         // Decode Incoming Message
120         SmsPluginTpduCodec::decodeTpdu(pDataPackage->szData, pDataPackage->MsgLength, &tpdu);
121
122         /// Print tpdu
123         if (tpdu.tpduType == SMS_TPDU_DELIVER)
124         {
125                 MSG_DEBUG("############# SMS_TPDU_DELIVER Incoming decoded tpdu values ####################");
126                 MSG_DEBUG("tpdu.data.deliver.bMoreMsg : %d", tpdu.data.deliver.bMoreMsg);
127                 MSG_DEBUG("tpdu.data.deliver.bStatusReport : %d", tpdu.data.deliver.bStatusReport);
128                 MSG_DEBUG("tpdu.data.deliver.bHeaderInd : %d", tpdu.data.deliver.bHeaderInd);
129                 MSG_DEBUG("tpdu.data.deliver.bReplyPath : %d", tpdu.data.deliver.bReplyPath);
130                 MSG_DEBUG("tpdu.data.deliver.pid : %d", tpdu.data.deliver.pid);
131                 MSG_DEBUG("tpdu.data.deliver.dcs.bCompressed : %d", tpdu.data.deliver.dcs.bCompressed);
132                 MSG_DEBUG("tpdu.data.deliver.dcs.msgClass : %d", tpdu.data.deliver.dcs.msgClass);
133                 MSG_DEBUG("tpdu.data.deliver.dcs.codingScheme : %d", tpdu.data.deliver.dcs.codingScheme);
134                 MSG_DEBUG("tpdu.data.deliver.dcs.codingGroup : %d", tpdu.data.deliver.dcs.codingGroup);
135                 MSG_DEBUG("tpdu.data.deliver.originAddress.address : %s", tpdu.data.deliver.originAddress.address);
136                 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,
137                         tpdu.data.deliver.timeStamp.time.absolute.hour, tpdu.data.deliver.timeStamp.time.absolute.minute, tpdu.data.deliver.timeStamp.time.absolute.second);
138                 MSG_DEBUG("tpdu.data.deliver.userData.headerCnt : %d", tpdu.data.deliver.userData.headerCnt);
139                 MSG_DEBUG("tpdu.data.deliver.userData.length : %d", tpdu.data.deliver.userData.length);
140                 MSG_DEBUG("tpdu.data.deliver.userData.data : %s", tpdu.data.deliver.userData.data);
141                 MSG_DEBUG("#####################################################");
142         }
143         else if (tpdu.tpduType == SMS_TPDU_STATUS_REP)
144         {
145                 MSG_DEBUG("############# SMS_TPDU_STATUS_REP Incoming decoded tpdu values ####################");
146                 MSG_DEBUG("tpdu.data.statusRep.msgRef : %d", tpdu.data.statusRep.msgRef);
147                 MSG_DEBUG("tpdu.data.statusRep.bMoreMsg : %d", tpdu.data.statusRep.bMoreMsg);
148                 MSG_DEBUG("tpdu.data.statusRep.bStatusReport : %d", tpdu.data.statusRep.bStatusReport);
149                 MSG_DEBUG("tpdu.data.statusRep.statusRep : %d", tpdu.data.statusRep.bHeaderInd);
150                 MSG_DEBUG("tpdu.data.statusRep.status : %02x", tpdu.data.statusRep.status);
151                 MSG_DEBUG("tpdu.data.statusRep.pid : %d", tpdu.data.statusRep.pid);
152                 MSG_DEBUG("tpdu.data.statusRep.dcs.bCompressed : %d", tpdu.data.statusRep.dcs.bCompressed);
153                 MSG_DEBUG("tpdu.data.statusRep.dcs.msgClass : %d", tpdu.data.statusRep.dcs.msgClass);
154                 MSG_DEBUG("tpdu.data.statusRep.dcs.codingScheme : %d", tpdu.data.statusRep.dcs.codingScheme);
155                 MSG_DEBUG("tpdu.data.statusRep.dcs.codingGroup : %d", tpdu.data.statusRep.dcs.codingGroup);
156                 MSG_DEBUG("tpdu.data.statusRep.recipAddress.address : %s", tpdu.data.statusRep.recipAddress.address);
157                 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,
158                         tpdu.data.statusRep.timeStamp.time.absolute.hour, tpdu.data.statusRep.timeStamp.time.absolute.minute, tpdu.data.statusRep.timeStamp.time.absolute.second);
159                 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,
160                         tpdu.data.statusRep.dischargeTime.time.absolute.hour, tpdu.data.statusRep.dischargeTime.time.absolute.minute, tpdu.data.statusRep.dischargeTime.time.absolute.second);
161                 MSG_DEBUG("tpdu.data.statusRep.userData.headerCnt : %d", tpdu.data.statusRep.userData.headerCnt);
162                 MSG_DEBUG("tpdu.data.statusRep.userData.length : %d", tpdu.data.statusRep.userData.length);
163                 MSG_DEBUG("tpdu.data.statusRep.userData.data : %s", tpdu.data.statusRep.userData.data);
164                 MSG_DEBUG("#####################################################");
165         }
166
167         try
168         {
169                 if (tpdu.tpduType == SMS_TPDU_DELIVER)
170                 {
171                         if (SmsPluginConcatHandler::instance()->IsConcatMsg(&(tpdu.data.deliver.userData)) == true ||
172                                 SmsPluginWapPushHandler::instance()->IsWapPushMsg(&(tpdu.data.deliver.userData)) == true)
173                         {
174                                 SmsPluginConcatHandler::instance()->handleConcatMsg(&tpdu); // Call Concat Msg Handler
175                         }
176                         else
177                         {
178                                 SmsPluginEventHandler::instance()->handleMsgIncoming(&tpdu); // Call Event Handler
179                         }
180                 }
181                 else if (tpdu.tpduType == SMS_TPDU_STATUS_REP)
182                 {
183                         SmsPluginEventHandler::instance()->handleMsgIncoming(&tpdu); // Call Event Handler
184                 }
185         }
186         catch (MsgException& e)
187         {
188                 MSG_FATAL("%s", e.what());
189                 return e.errorCode();
190         }
191
192         return 0;
193 }
194
195
196 int TapiEventCbMsgIncoming(const TelTapiEvent_t *pEvent, void*)
197 {
198         MSG_DEBUG("TapiEventCbMsgIncoming is called.");
199
200         if (pEvent->Status != TAPI_API_SUCCESS || pEvent->pData == NULL)
201         {
202                 MSG_DEBUG("Error. evt->pData is NULL.");
203                 return 0;
204         }
205
206         TelSmsCbMsg_t *pCbMsg = (TelSmsCbMsg_t*)pEvent->pData;
207
208         try
209         {
210                 SmsPluginCbMsgHandler::instance()->handleCbMsg(pCbMsg);
211         }
212         catch (MsgException& e)
213         {
214                 MSG_FATAL("%s", e.what());
215                 return 0;
216         }
217
218         return 0;
219 }
220
221
222 int TapiEventDeliveryReportCNF(const TelTapiEvent_t *pEvent, void*)
223 {
224         MSG_DEBUG("TapiEventDeliveryReportCNF is called. : request id = [%d] status = [%d]", pEvent->RequestId, pEvent->Status);
225
226         return 0;
227 }
228
229
230 int TapiEventGetSimMsgCnt(const TelTapiEvent_t *pEvent, void*)
231 {
232         MSG_DEBUG("TapiEventGetSimMsgCnt is called.");
233
234         if (pEvent->Status != TAPI_API_SUCCESS || pEvent->pData == NULL)
235         {
236                 MSG_DEBUG("Error. evt->pData is NULL.");
237                 MSG_SIM_COUNT_S simCnt;
238                 memset(&simCnt, 0x00, sizeof(MSG_SIM_COUNT_S));
239                 SmsPluginSimMsg::instance()->setSimMsgCntEvent(&simCnt);
240                 return 0;
241         }
242
243         SmsPluginSimMsg::instance()->setSimMsgCntEvent((MSG_SIM_COUNT_S *)pEvent->pData);
244
245         return 0;
246 }
247
248
249 int TapiEventGetSimMsg(const TelTapiEvent_t *pEvent, void*)
250 {
251         MSG_DEBUG("TapiEventGetSimMsg is called.");
252
253         if (pEvent->Status != TAPI_API_SUCCESS || pEvent->pData == NULL)
254         {
255                 MSG_DEBUG("Error!! pEvent->Status [%d]", pEvent->Status);
256
257                 SmsPluginSimMsg::instance()->setSimMsgEvent(NULL, false);
258
259                 return 0;
260         }
261
262         TelSmsData_t* pSmsTpdu = (TelSmsData_t*)pEvent->pData;
263
264         // Reading TelSmsData_t
265         MSG_DEBUG ("sim index %d", pSmsTpdu->SimIndex);
266         MSG_DEBUG ("status %d", pSmsTpdu->MsgStatus);
267
268         // Reading TelSmsDatapackageInfo_t
269         if (pSmsTpdu->SmsData.MsgLength > MAX_TPDU_DATA_LEN)
270         {
271                 MSG_DEBUG ("WARNING: tpdu_len > MAX_SMS_TPDU_SIZE [%d] bytes. setting to 0.", pSmsTpdu->SmsData.MsgLength);
272
273                 SmsPluginSimMsg::instance()->setSimMsgEvent(NULL, false);
274
275                 return 0;
276         }
277
278         SMS_TPDU_S tpdu;
279
280         // decode Tpdu
281         SmsPluginTpduCodec::decodeTpdu(pSmsTpdu->SmsData.szData, pSmsTpdu->SmsData.MsgLength, &tpdu);
282
283         MSG_DEBUG("Sim Message Type [%d]", tpdu.tpduType);
284
285         bool bRead = false;
286
287         // set read status
288         if (pSmsTpdu->MsgStatus == TAPI_NETTEXT_STATUS_READ)
289                 bRead = true;
290         else if (pSmsTpdu->MsgStatus == TAPI_NETTEXT_STATUS_UNREAD)
291                 bRead = false;
292
293         if (tpdu.tpduType == SMS_TPDU_DELIVER)
294         {
295                 MSG_DEBUG("headerCnt [%d]", tpdu.data.deliver.userData.headerCnt);
296
297                 for (int i = 0; i < tpdu.data.deliver.userData.headerCnt; i++)
298                 {
299                         // Handler Concatenated Message
300                         if (tpdu.data.deliver.userData.header[i].udhType == SMS_UDH_CONCAT_8BIT ||
301                                 tpdu.data.deliver.userData.header[i].udhType == SMS_UDH_CONCAT_16BIT)
302                         {
303                                 SmsPluginSimMsg::instance()->setSimMsgEvent(NULL, false);
304                                 return 0;
305                         }
306                 }
307         }
308         else if (tpdu.tpduType == SMS_TPDU_SUBMIT)
309         {
310                 MSG_DEBUG("headerCnt [%d]", tpdu.data.submit.userData.headerCnt);
311
312                 for (int i = 0; i < tpdu.data.submit.userData.headerCnt; i++)
313                 {
314                         // Handler Concatenated Message
315                         if (tpdu.data.submit.userData.header[i].udhType == SMS_UDH_CONCAT_8BIT ||
316                                 tpdu.data.submit.userData.header[i].udhType == SMS_UDH_CONCAT_16BIT)
317                         {
318                                 SmsPluginSimMsg::instance()->setSimMsgEvent(NULL, false);
319                                 return 0;
320                         }
321                 }
322         }
323
324         // Make MSG_MESSAGE_INFO_S
325         MSG_MESSAGE_INFO_S msgInfo;
326         memset(&msgInfo, 0x00, sizeof(MSG_MESSAGE_INFO_S));
327
328         SmsPluginEventHandler::instance()->convertTpduToMsginfo(&tpdu, &msgInfo);
329
330         // set Sim Message ID
331         msgInfo.msgId = pSmsTpdu->SimIndex;
332
333         // set read status
334         msgInfo.bRead = bRead;
335
336         // set storage id
337         msgInfo.storageId = MSG_STORAGE_SIM;
338
339         /// Print MSG_MESSAGE_INFO_S
340         MSG_DEBUG("############# Convert  tpdu values to Message Info values ####################");
341         MSG_DEBUG("msgInfo.msgId : %d", msgInfo.msgId);
342         MSG_DEBUG("msgInfo.nAddressCnt : %d", msgInfo.nAddressCnt);
343         MSG_DEBUG("msgInfo.addressList[0].addressType : %d", msgInfo.addressList[0].addressType);
344         MSG_DEBUG("msgInfo.addressList[0].addressVal : %s", msgInfo.addressList[0].addressVal);
345         MSG_DEBUG("msgInfo.priority : %d", msgInfo.priority);
346         MSG_DEBUG("msgInfo.bProtected : %d", msgInfo.bProtected);
347         MSG_DEBUG("msgInfo.bRead : %d", msgInfo.bRead);
348         MSG_DEBUG("msgInfo.bTextSms : %d", msgInfo.bTextSms);
349         MSG_DEBUG("msgInfo.direction : %d", msgInfo.direction);
350         MSG_DEBUG("msgInfo.msgType.mainType : %d", msgInfo.msgType.mainType);
351         MSG_DEBUG("msgInfo.msgType.subType : %d", msgInfo.msgType.subType);
352         MSG_DEBUG("msgInfo.msgType.classType : %d", msgInfo.msgType.classType);
353         MSG_DEBUG("msgInfo.displayTime : %s", ctime(&msgInfo.displayTime));
354         MSG_DEBUG("msgInfo.dataSize : %d", msgInfo.dataSize);
355         if (msgInfo.bTextSms == true)
356                 MSG_DEBUG("msgInfo.msgText : %s", msgInfo.msgText);
357         else
358         MSG_DEBUG("msgInfo.msgData : %s", msgInfo.msgData);
359         MSG_DEBUG("###############################################################");
360
361         SmsPluginSimMsg::instance()->setSimMsgEvent(&msgInfo, true); // Call Event Handler
362
363         return 0;
364 }
365
366
367 int TapiEventSaveSimMsg(const TelTapiEvent_t *pEvent, void*)
368 {
369         MSG_DEBUG("TapiEventSaveSimMsg is called. Red Id [%d]", pEvent->RequestId);
370
371         if (pEvent->Status != TAPI_API_SUCCESS || pEvent->pData == NULL)
372         {
373                 MSG_DEBUG("Error. evt->pData is NULL.");
374                 SmsPluginSimMsg::instance()->setSimEvent((MSG_SIM_ID_T)0, false);
375                 return 0;
376         }
377
378         int simId = *((int*)pEvent->pData);
379
380         MSG_DEBUG("sim ID : [%d], status : [%d]", simId, (TelSmsCause_t)pEvent->Status);
381
382         SmsPluginSimMsg::instance()->setSimEvent((MSG_SIM_ID_T)simId, true);
383
384         return 0;
385 }
386
387
388 int TapiEventDeleteSimMsg(const TelTapiEvent_t *pEvent, void*)
389 {
390         MSG_DEBUG("TapiEventDeleteSimMsg is called. Red Id [%d]", pEvent->RequestId);
391         MSG_DEBUG("status : [%d]", (TelSmsCause_t)pEvent->Status);
392
393         if (pEvent->Status != TAPI_API_SUCCESS || pEvent->pData == NULL)
394         {
395                 MSG_DEBUG("Error. evt->pData is NULL.");
396                 SmsPluginSimMsg::instance()->setSimEvent((MSG_SIM_ID_T)0, false);
397                 return 0;
398         }
399
400         int sim_id = *((int*)pEvent->pData);
401
402         SmsPluginSimMsg::instance()->setSimEvent((MSG_SIM_ID_T)sim_id, true);
403
404         return 0;
405 }
406
407
408 int TapiEventSetConfigData(const TelTapiEvent_t *pEvent, void*)
409 {
410         MSG_DEBUG("TapiEventSetConfigData is called.");
411
412         if (pEvent->pData == NULL)
413         {
414                 MSG_DEBUG("Error. evt->pData is NULL.");
415                 return 0;
416         }
417
418         TelSmsSetResponse* responseType = (TelSmsSetResponse*)pEvent->pData;
419
420         MSG_DEBUG("responseType : [%d]", *responseType);
421
422         switch (*responseType)
423         {
424                 case TAPI_NETTEXT_SETPREFERREDBEARER_RSP :
425                         MSG_DEBUG("TAPI_NETTEXT_SETPREFERREDBEARER_RSP is called");
426                 break;
427
428                 case TAPI_NETTEXT_SETPARAMETERS_RSP :
429                         MSG_DEBUG("TAPI_NETTEXT_SETPARAMETERS_RSP is called");
430                 break;
431
432                 case TAPI_NETTEXT_CBSETCONFIG_RSP :
433                         MSG_DEBUG("TAPI_NETTEXT_CBSETCONFIG_RSP is called");
434                 break;
435
436                 case TAPI_NETTEXT_SETMEMORYSTATUS_RSP :
437                         MSG_DEBUG("TAPI_NETTEXT_SETMEMORYSTATUS_RSP is called");
438                 break;
439
440                 case TAPI_NETTEXT_SETMESSAGESTATUS_RSP :
441                         MSG_DEBUG("TAPI_NETTEXT_SETMESSAGESTATUS_RSP is called");
442                 break;
443
444                 default :
445                         MSG_DEBUG("Unknown Response is called [%d]", *responseType);
446                 break;
447         }
448
449         bool bRet = true;
450
451         MSG_DEBUG("status : [%d]", (TelSmsCause_t)pEvent->Status);
452
453         if ((TelSmsCause_t)pEvent->Status != TAPI_NETTEXT_SUCCESS) bRet = false;
454
455         if (*responseType == TAPI_NETTEXT_SETMESSAGESTATUS_RSP)
456                 SmsPluginSimMsg::instance()->setSimEvent(0, bRet);
457         else
458                 SmsPluginSetting::instance()->setResultFromSim(bRet);
459
460         return 0;
461 }
462
463
464 int TapiEventGetParamCnt(const TelTapiEvent_t *pEvent, void*)
465 {
466         MSG_DEBUG("TapiEventGetParamCnt is called.");
467
468         if (pEvent->Status != TAPI_API_SUCCESS || pEvent->pData == NULL)
469         {
470                 MSG_DEBUG("Error. evt->pData is NULL.");
471                 SmsPluginSetting::instance()->setParamCntEvent(0);
472                 return 0;
473         }
474
475         int paramCnt = 0;
476         paramCnt = *((int*)pEvent->pData);
477
478         SmsPluginSetting::instance()->setParamCntEvent(paramCnt);
479
480         return 0;
481 }
482
483
484 int TapiEventGetParam(const TelTapiEvent_t *pEvent, void*)
485 {
486         MSG_DEBUG("TapiEventGetConfigData is called.");
487
488         if (pEvent->Status != TAPI_API_SUCCESS || pEvent->pData == NULL)
489         {
490                 MSG_DEBUG("Error. evt->pData is NULL.");
491                 SmsPluginSetting::instance()->setParamEvent(NULL, -1, false);
492                 return 0;
493         }
494
495         TelSmsParams_t* smsParam = (TelSmsParams_t*)pEvent->pData;
496
497         int alphaIdLen = 0;
498         int addrLen = 0;
499         MSG_SMSC_DATA_S smscData = {};
500
501         /*Check Alpha ID value*/
502         alphaIdLen = smsParam->AlphaIdLen;
503         MSG_DEBUG("alphaId_len[%d]", alphaIdLen);
504
505         if (alphaIdLen < 0 || alphaIdLen > SMSC_NAME_MAX)
506         {
507                 MSG_DEBUG("Wrong Alpha ID Length[%d]", alphaIdLen);
508
509                 SmsPluginSetting::instance()->setParamEvent(NULL, -1, false);
510
511                 return 0;
512         }
513
514
515         /*Check Address value*/
516         addrLen = smsParam->TpSvcCntrAddr.DialNumLen;
517
518         if(addrLen > SMSC_ADDR_MAX)
519         {
520                 MSG_DEBUG("addrLen is too long: %d", addrLen);
521                 SmsPluginSetting::instance()->setParamEvent(NULL, -1, false);
522                 return 0;
523         }
524         else if(addrLen < 2)
525         {
526                 MSG_DEBUG("addrLen is too short: %d", addrLen);
527                 SmsPluginSetting::instance()->setParamEvent(NULL, -1, false);
528                 return 0;
529         }
530
531         MSG_DEBUG("addrLen : %d", addrLen);
532
533
534         /*SMSP Parameter Indicator value*/
535         MSG_DEBUG("ParamIndicator[%02x]", smsParam->ParamIndicator);
536
537         /*Get SMSC Address*/
538         if(0x00 == (0x02 & smsParam->ParamIndicator))
539         {
540                 MSG_DEBUG("record index[%d]", (int)smsParam->RecordIndex);
541
542                 MSG_DEBUG("TON : %d", smsParam->TpSvcCntrAddr.Ton);
543                 MSG_DEBUG("NPI : %d", smsParam->TpSvcCntrAddr.Npi);
544
545                 smscData.smscAddr.ton = smsParam->TpSvcCntrAddr.Ton;
546                 smscData.smscAddr.npi = smsParam->TpSvcCntrAddr.Npi;
547
548                 SmsPluginParamCodec paramCodec;
549
550                 memset(smscData.smscAddr.address, 0x00, SMSC_ADDR_MAX+1);
551                 paramCodec.decodeSMSC(smsParam->TpSvcCntrAddr.szDiallingNum, addrLen, smscData.smscAddr.ton, smscData.smscAddr.address);
552
553                 MSG_DEBUG("SMSC Address : [%s]", smscData.smscAddr.address);
554
555                 memset(smscData.name, 0x00, SMSC_NAME_MAX+1);
556                 memcpy(smscData.name, smsParam->szAlphaId, alphaIdLen);
557                 smscData.name[alphaIdLen] = '\0';
558
559                 MSG_DEBUG("SMSC Name : [%s]", smscData.name);
560         }
561         else
562         {
563                 MSG_DEBUG("SMSC Address is not present");
564
565                 SmsPluginSetting::instance()->setParamEvent(NULL, -1, false);
566
567                 return 0;
568         }
569
570         /*Get the PID value*/
571         if (0x00 == (0x04 & smsParam->ParamIndicator))
572         {
573                 SMS_PID_T pid = (SMS_PID_T)smsParam->TpProtocolId;
574
575                 MSG_DEBUG("smsParam->TpProtocolId : %d", smsParam->TpProtocolId);
576
577                 switch (pid)
578                 {
579                         case SMS_PID_NORMAL:
580                                 smscData.pid = MSG_PID_TEXT;
581                         break;
582                         case SMS_PID_VOICE:
583                                 smscData.pid = MSG_PID_VOICE;
584                         break;
585                         case SMS_PID_TELEX:
586                                 smscData.pid = MSG_PID_FAX;
587                         break;
588                         case SMS_PID_x400:
589                                 smscData.pid = MSG_PID_X400;
590                         break;
591                         case SMS_PID_ERMES:
592                                 smscData.pid = MSG_PID_ERMES;
593                         break;
594                         case SMS_PID_EMAIL:
595                                 smscData.pid = MSG_PID_EMAIL;
596                         break;
597                         default:
598                                 smscData.pid = MSG_PID_TEXT;
599                         break;
600                 }
601
602                 MSG_DEBUG("smscData.pid : %d", smscData.pid);
603         }
604         else
605         {
606                 MSG_DEBUG("PID is not present");
607                 smscData.pid = MSG_PID_TEXT;
608                 MSG_DEBUG("MSG_PID_TEXT is inserted to PID");
609         }
610
611         /*Get the ValidityPeriod value*/
612         if (0x00 == (0x10 & smsParam->ParamIndicator))
613         {
614                 smscData.valPeriod = smsParam->TpValidityPeriod;
615                 MSG_DEBUG("valPeriod : %d", smscData.valPeriod);
616         }
617         else
618         {
619                 smscData.valPeriod = 0;
620                 MSG_DEBUG("Validity Period is not present");
621         }
622
623         SmsPluginSetting::instance()->setParamEvent(&smscData, (int)smsParam->RecordIndex, true);
624
625         return 0;
626 }
627
628
629 int TapiEventGetCBConfig(const TelTapiEvent_t *pEvent, void*)
630 {
631         MSG_DEBUG("TapiEventGetCBConfig is called.");
632
633         MSG_CBMSG_OPT_S cbOpt = {0};
634
635         if (pEvent->Status != TAPI_API_SUCCESS || pEvent->pData == NULL)
636         {
637                 MSG_DEBUG("Error. evt->pData is NULL.");
638
639                 SmsPluginSetting::instance()->setCbConfigEvent(NULL, false);
640
641                 return 0;
642         }
643
644         TelSmsCbConfig_t* pCBConfig = (TelSmsCbConfig_t*)pEvent->pData;
645
646         cbOpt.bReceive = (bool)pCBConfig->bCBEnabled;
647
648         if (pCBConfig->SelectedId == 0x01)
649                 cbOpt.bAllChannel = true;
650         else if (pCBConfig->SelectedId == 0x02)
651                 cbOpt.bAllChannel = false;
652
653         cbOpt.maxSimCnt = pCBConfig->MsgIdMaxCount;
654
655         MSG_DEBUG("Receive [%d], All Channel [%d], Max SIM Count [%d]", cbOpt.bReceive, cbOpt.bAllChannel, cbOpt.maxSimCnt);
656
657         cbOpt.channelData.channelCnt = pCBConfig->MsgIdCount;
658
659         if (cbOpt.channelData.channelCnt > CB_CHANNEL_MAX)
660         {
661                 MSG_DEBUG("Channel Count [%d] from TAPI is over MAX", cbOpt.channelData.channelCnt);
662                 cbOpt.channelData.channelCnt = CB_CHANNEL_MAX;
663         }
664
665         MSG_DEBUG("Channel Count [%d]", cbOpt.channelData.channelCnt);
666
667         for (int i = 0; i < cbOpt.channelData.channelCnt; i++)
668         {
669                 cbOpt.channelData.channelInfo[i].bActivate = cbOpt.bReceive;
670                 cbOpt.channelData.channelInfo[i].id = pCBConfig->MsgIDs[i];
671                 memset(cbOpt.channelData.channelInfo[i].name, 0x00, CB_CHANNEL_NAME_MAX+1);
672
673                 MSG_DEBUG("Channel ID [%d]", cbOpt.channelData.channelInfo[i].id);
674         }
675
676         SmsPluginSetting::instance()->setCbConfigEvent(&cbOpt, true);
677
678         return 0;
679 }
680
681
682 int TapiEventSatSmsRefresh(const TelTapiEvent_t *pEvent, void*)
683 {
684         MSG_DEBUG("TapiEventSatSmsRefresh is called.");
685
686         if (pEvent->Status != TAPI_API_SUCCESS || pEvent->pData == NULL)
687         {
688                 MSG_DEBUG("Error. evt->pData is NULL.");
689                 return 0;
690         }
691
692         try
693         {
694                 SmsPluginSatHandler::instance()->refreshSms(pEvent->pData);
695         }
696         catch (MsgException& e)
697         {
698                 MSG_FATAL("%s", e.what());
699                 return e.errorCode();
700         }
701
702         return 0;
703 }
704
705
706 int TapiEventSatSendSms(const TelTapiEvent_t *pEvent, void*)
707 {
708         MSG_DEBUG("TapiEventSatSendSms is called.");
709
710         if (pEvent->Status != TAPI_API_SUCCESS || pEvent->pData == NULL)
711         {
712                 MSG_DEBUG("Error. evt->pData is NULL.");
713                 return 0;
714         }
715
716         try
717         {
718                 SmsPluginSatHandler::instance()->sendSms(pEvent->pData);
719         }
720         catch (MsgException& e)
721         {
722                 MSG_FATAL("%s", e.what());
723                 return e.errorCode();
724         }
725
726         return 0;
727 }
728
729
730 int TapiEventSatMoSmsCtrl(const TelTapiEvent_t *pEvent, void*)
731 {
732         MSG_DEBUG("TapiEventSatMoSmsCtrl is called.");
733
734         if (pEvent->Status != TAPI_API_SUCCESS || pEvent->pData == NULL)
735         {
736                 MSG_DEBUG("Error. evt->pData is NULL.");
737                 return 0;
738         }
739
740         try
741         {
742                 SmsPluginSatHandler::instance()->ctrlSms(pEvent->pData);
743         }
744         catch (MsgException& e)
745         {
746                 MSG_FATAL("%s", e.what());
747                 return e.errorCode();
748         }
749
750         return 0;
751
752 }
753
754
755 int TapiEventFactoryDftSms(const TelTapiEvent_t *pEvent, void*)
756 {
757         MSG_DEBUG("TapiEventFactoryDftSms is called.");
758
759         if (pEvent->Status != TAPI_API_SUCCESS || pEvent->pData == NULL)
760         {
761                 MSG_DEBUG("Error. evt->pData is NULL.");
762                 return 0;
763         }
764
765         TelFactoryDftSmsInfo_t* pSmsInfo = (TelFactoryDftSmsInfo_t *)pEvent->pData;
766
767         MSG_FOLDER_ID_T folderId = MSG_INBOX_ID;
768
769         if (pSmsInfo->option == TAPI_FACTORY_DFT_SMS_INBOX)
770         {
771                 folderId = MSG_INBOX_ID;
772         }
773         else if (pSmsInfo->option == TAPI_FACTORY_DFT_SMS_DRAFTS)
774         {
775                 folderId = MSG_DRAFT_ID;
776         }
777         else if (pSmsInfo->option == TAPI_FACTORY_DFT_SMS_OUTBOX)
778         {
779                 folderId = MSG_OUTBOX_ID;
780         }
781         else if (pSmsInfo->option == TAPI_FACTORY_DFT_SMS_SENTBOX)
782         {
783                 folderId = MSG_SENTBOX_ID;
784         }
785
786         try
787         {
788                 SmsPluginEventHandler::instance()->handleDftSms(folderId, pSmsInfo->number, pSmsInfo->data); // Call Event Handler
789         }
790         catch (MsgException& e)
791         {
792                 MSG_FATAL("%s", e.what());
793                 return e.errorCode();
794         }
795
796         return 0;
797 }
798
799
800 /*==================================================================================================
801                                      IMPLEMENTATION OF SmsPluginCallback - Member Functions
802 ==================================================================================================*/
803 SmsPluginCallback* SmsPluginCallback::pInstance = NULL;
804
805
806 SmsPluginCallback::SmsPluginCallback()
807 {
808
809
810 }
811
812
813 SmsPluginCallback::~SmsPluginCallback()
814 {
815         if (pInstance != NULL)
816         {
817                 delete pInstance;
818                 pInstance = NULL;
819         }
820 }
821
822
823 SmsPluginCallback* SmsPluginCallback::instance()
824 {
825         if (!pInstance)
826                 pInstance = new SmsPluginCallback();
827
828         return pInstance;
829 }
830
831
832 void SmsPluginCallback::registerEvent()
833 {
834         unsigned int tempId = 0;
835
836         tel_register_event(TAPI_EVENT_NETTEXT_DEVICE_READY_IND, &tempId, (TelAppCallback)&TapiEventDeviceReady, NULL);
837
838         tel_register_event(TAPI_EVENT_NETTEXT_SENTSTATUS_CNF, &tempId, (TelAppCallback)&TapiEventSentStatus, NULL);
839         tel_register_event(TAPI_EVENT_NETTEXT_INCOM_IND, &tempId, (TelAppCallback)&TapiEventMsgIncoming, NULL);
840         tel_register_event(TAPI_EVENT_NETTEXT_CB_INCOM_IND, &tempId, (TelAppCallback)&TapiEventCbMsgIncoming, NULL);
841         tel_register_event(TAPI_EVENT_NETTEXT_DELIVERY_REPORT_CNF, &tempId, (TelAppCallback)&TapiEventDeliveryReportCNF, NULL);
842
843         tel_register_event(TAPI_EVENT_NETTEXT_SAVE_STATUS_CNF, &tempId, (TelAppCallback)&TapiEventSaveSimMsg, NULL);
844         tel_register_event(TAPI_EVENT_NETTEXT_DELETE_STATUS_CNF, &tempId, (TelAppCallback)&TapiEventDeleteSimMsg, NULL);
845         tel_register_event(TAPI_EVENT_NETTEXT_GET_COUNT_CNF, &tempId, (TelAppCallback)&TapiEventGetSimMsgCnt, NULL);
846         tel_register_event(TAPI_EVENT_NETTEXT_READ_SMS_CNF, &tempId, (TelAppCallback)&TapiEventGetSimMsg, NULL);
847
848         tel_register_event(TAPI_EVENT_NETTEXT_SET_REQUEST_CNF, &tempId, (TelAppCallback)&TapiEventSetConfigData, NULL);
849         tel_register_event(TAPI_EVENT_NETTEXT_PARAM_COUNT_IND, &tempId, (TelAppCallback)&TapiEventGetParamCnt, NULL);
850         tel_register_event(TAPI_EVENT_NETTEXT_GET_PARAM_CNF, &tempId, (TelAppCallback)&TapiEventGetParam, NULL);
851         tel_register_event(TAPI_EVENT_NETTEXT_GET_CB_CONFIG_CNF, &tempId, (TelAppCallback)&TapiEventGetCBConfig, NULL);
852
853         tel_register_event(TAPI_EVENT_SAT_SMS_REFRESH_IND, &tempId, (TelAppCallback)&TapiEventSatSmsRefresh, NULL);
854         tel_register_event(TAPI_EVENT_SAT_SEND_SMS_IND, &tempId, (TelAppCallback)&TapiEventSatSendSms, NULL);
855         tel_register_event(TAPI_EVENT_SAT_MO_SMS_CONTROL_IND, &tempId, (TelAppCallback)&TapiEventSatMoSmsCtrl, NULL);
856
857         tel_register_event(TAPI_EVENT_FACTORY_DFT_SMS, &tempId, (TelAppCallback)&TapiEventFactoryDftSms, NULL);
858
859         int tapiRet = TAPI_API_SUCCESS;
860
861         // Register app name to telephony server
862         tapiRet = tel_register_app_name((char*)"org.tizen.msgfw");
863
864         if (tapiRet != TAPI_API_SUCCESS)
865         {
866                 THROW(MsgException::SMS_PLG_ERROR, "Failed to register applicatoin name on Telephony Server [%d]", tapiRet);
867         }
868 }
869
870
871 void SmsPluginCallback::deRegisterEvent()
872 {
873
874
875 }
876