RSA sync with private
[platform/core/messaging/msg-service.git] / plugin / sms_plugin / SmsPluginCallback.cpp
1 /*
2 * Copyright 2012  Samsung Electronics Co., Ltd
3 *
4 * Licensed under the Flora License, Version 1.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.tizenopensource.org/license
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 "MsgException.h"
22 #include "SmsPluginEventHandler.h"
23 #include "SmsPluginCbMsgHandler.h"
24 #include "SmsPluginConcatHandler.h"
25 #include "SmsPluginWapPushHandler.h"
26 #include "SmsPluginSatHandler.h"
27 #include "SmsPluginParamCodec.h"
28 #include "SmsPluginTpduCodec.h"
29 #include "SmsPluginTransport.h"
30 #include "SmsPluginSimMsg.h"
31 #include "SmsPluginSetting.h"
32 #include "MsgGconfWrapper.h"
33 #include "SmsPluginCallback.h"
34
35 extern struct tapi_handle *pTapiHandle;
36
37 /*==================================================================================================
38                                      FUNCTION IMPLEMENTATION
39 ==================================================================================================*/
40 void TapiEventDeviceReady(TapiHandle *handle, const char *noti_id, void *data, void *user_data)
41 {
42         MSG_DEBUG("TapiEventDeviceReady is called. : noti_id = [%d]", noti_id);
43
44         try
45         {
46                 // Call Event Handler
47                 SmsPluginEventHandler::instance()->setDeviceStatus();
48         }
49         catch (MsgException& e)
50         {
51                 MSG_FATAL("%s", e.what());
52                 return;
53         }
54
55 }
56
57
58 void TapiEventSentStatus(TapiHandle *handle, int result, void *data, void *user_data)
59 {
60         MSG_DEBUG("TapiEventSentStatus is called. : result = [%d]", result);
61
62         msg_network_status_t netStatus;
63
64         // Convert TAPI status -> Messaging status
65         if ((TelSmsResponse_t)result == TAPI_NETTEXT_SENDSMS_SUCCESS)
66                 netStatus = MSG_NETWORK_SEND_SUCCESS;
67         else
68                 netStatus = MSG_NETWORK_SEND_FAIL;
69
70         try
71         {
72                 // Call Event Handler
73                 SmsPluginEventHandler::instance()->handleSentStatus(netStatus);
74
75                 // Call SAT Handler
76                 SmsPluginSatHandler::instance()->ctrlSms(netStatus);
77         }
78         catch (MsgException& e)
79         {
80                 MSG_FATAL("%s", e.what());
81                 return;
82         }
83
84 }
85
86
87 void TapiEventMsgIncoming(TapiHandle *handle, const char *noti_id, void *data, void *user_data)
88 {
89         MSG_DEBUG("TapiEventMsgIncoming is called. noti_id [%s]", noti_id);
90
91         if (data == NULL) {
92                 MSG_DEBUG("Error. evt->pData is NULL.");
93                 return;
94         }
95
96         TelSmsDatapackageInfo_t* pDataPackage = (TelSmsDatapackageInfo_t*)data;
97
98         SMS_TPDU_S tpdu;
99         memset(&tpdu, 0x00, sizeof(SMS_TPDU_S));
100
101         // Decode Incoming Message
102         SmsPluginTpduCodec::decodeTpdu(pDataPackage->szData, pDataPackage->MsgLength, &tpdu);
103
104         /// Print tpdu
105         if (tpdu.tpduType == SMS_TPDU_DELIVER)
106         {
107                 MSG_DEBUG("############# SMS_TPDU_DELIVER Incoming decoded tpdu values ####################");
108                 MSG_DEBUG("tpdu.data.deliver.bMoreMsg : %d", tpdu.data.deliver.bMoreMsg);
109                 MSG_DEBUG("tpdu.data.deliver.bStatusReport : %d", tpdu.data.deliver.bStatusReport);
110                 MSG_DEBUG("tpdu.data.deliver.bHeaderInd : %d", tpdu.data.deliver.bHeaderInd);
111                 MSG_DEBUG("tpdu.data.deliver.bReplyPath : %d", tpdu.data.deliver.bReplyPath);
112                 MSG_DEBUG("tpdu.data.deliver.pid : %d", tpdu.data.deliver.pid);
113                 MSG_DEBUG("tpdu.data.deliver.dcs.bCompressed : %d", tpdu.data.deliver.dcs.bCompressed);
114                 MSG_DEBUG("tpdu.data.deliver.dcs.msgClass : %d", tpdu.data.deliver.dcs.msgClass);
115                 MSG_DEBUG("tpdu.data.deliver.dcs.codingScheme : %d", tpdu.data.deliver.dcs.codingScheme);
116                 MSG_DEBUG("tpdu.data.deliver.dcs.codingGroup : %d", tpdu.data.deliver.dcs.codingGroup);
117                 MSG_DEBUG("tpdu.data.deliver.originAddress.address : %s", tpdu.data.deliver.originAddress.address);
118                 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,
119                         tpdu.data.deliver.timeStamp.time.absolute.hour, tpdu.data.deliver.timeStamp.time.absolute.minute, tpdu.data.deliver.timeStamp.time.absolute.second);
120                 MSG_DEBUG("tpdu.data.deliver.userData.headerCnt : %d", tpdu.data.deliver.userData.headerCnt);
121                 MSG_DEBUG("tpdu.data.deliver.userData.length : %d", tpdu.data.deliver.userData.length);
122                 MSG_DEBUG("tpdu.data.deliver.userData.data : %s", tpdu.data.deliver.userData.data);
123                 MSG_DEBUG("#####################################################");
124         }
125         else if (tpdu.tpduType == SMS_TPDU_STATUS_REP)
126         {
127                 MSG_DEBUG("############# SMS_TPDU_STATUS_REP Incoming decoded tpdu values ####################");
128                 MSG_DEBUG("tpdu.data.statusRep.msgRef : %d", tpdu.data.statusRep.msgRef);
129                 MSG_DEBUG("tpdu.data.statusRep.bMoreMsg : %d", tpdu.data.statusRep.bMoreMsg);
130                 MSG_DEBUG("tpdu.data.statusRep.bStatusReport : %d", tpdu.data.statusRep.bStatusReport);
131                 MSG_DEBUG("tpdu.data.statusRep.statusRep : %d", tpdu.data.statusRep.bHeaderInd);
132                 MSG_DEBUG("tpdu.data.statusRep.status : %02x", tpdu.data.statusRep.status);
133                 MSG_DEBUG("tpdu.data.statusRep.pid : %d", tpdu.data.statusRep.pid);
134                 MSG_DEBUG("tpdu.data.statusRep.dcs.bCompressed : %d", tpdu.data.statusRep.dcs.bCompressed);
135                 MSG_DEBUG("tpdu.data.statusRep.dcs.msgClass : %d", tpdu.data.statusRep.dcs.msgClass);
136                 MSG_DEBUG("tpdu.data.statusRep.dcs.codingScheme : %d", tpdu.data.statusRep.dcs.codingScheme);
137                 MSG_DEBUG("tpdu.data.statusRep.dcs.codingGroup : %d", tpdu.data.statusRep.dcs.codingGroup);
138                 MSG_DEBUG("tpdu.data.statusRep.recipAddress.address : %s", tpdu.data.statusRep.recipAddress.address);
139                 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,
140                         tpdu.data.statusRep.timeStamp.time.absolute.hour, tpdu.data.statusRep.timeStamp.time.absolute.minute, tpdu.data.statusRep.timeStamp.time.absolute.second);
141                 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,
142                         tpdu.data.statusRep.dischargeTime.time.absolute.hour, tpdu.data.statusRep.dischargeTime.time.absolute.minute, tpdu.data.statusRep.dischargeTime.time.absolute.second);
143                 MSG_DEBUG("tpdu.data.statusRep.userData.headerCnt : %d", tpdu.data.statusRep.userData.headerCnt);
144                 MSG_DEBUG("tpdu.data.statusRep.userData.length : %d", tpdu.data.statusRep.userData.length);
145                 MSG_DEBUG("tpdu.data.statusRep.userData.data : %s", tpdu.data.statusRep.userData.data);
146                 MSG_DEBUG("#####################################################");
147         }
148
149         try
150         {
151                 if (tpdu.tpduType == SMS_TPDU_DELIVER)
152                 {
153                         if (tpdu.data.deliver.dcs.msgClass == SMS_MSG_CLASS_2) {
154                                 // For GCF test, 34.2.5.3
155                                 SmsPluginSimMsg::instance()->setSmsData((const char*)pDataPackage->Sca, (const char *)pDataPackage->szData, pDataPackage->MsgLength);
156                         }
157
158                         if (tpdu.data.deliver.dcs.codingGroup == SMS_GROUP_DISCARD) {
159                                 if (tpdu.data.deliver.dcs.bIndActive == false) {
160                                         SmsPluginSetting::instance()->setMwiInfo(tpdu.data.deliver.dcs.indType + MSG_MWI_VOICE_SMS, 0);
161                                 }
162                                 SmsPluginTransport::instance()->sendDeliverReport(MSG_SUCCESS);
163                         } else {
164                                 if (SmsPluginConcatHandler::instance()->IsConcatMsg(&(tpdu.data.deliver.userData)) == true ||
165                                         SmsPluginWapPushHandler::instance()->IsWapPushMsg(&(tpdu.data.deliver.userData)) == true)
166                                 {
167                                         SmsPluginConcatHandler::instance()->handleConcatMsg(&tpdu); // Call Concat Msg Handler
168                                 }
169                                 else
170                                 {
171                                         SmsPluginEventHandler::instance()->handleMsgIncoming(&tpdu); // Call Event Handler
172                                 }
173                         }
174                 }
175                 else if (tpdu.tpduType == SMS_TPDU_STATUS_REP)
176                 {
177                         SmsPluginEventHandler::instance()->handleMsgIncoming(&tpdu); // Call Event Handler
178                 }
179         }
180         catch (MsgException& e)
181         {
182                 MSG_FATAL("%s", e.what());
183                 return;
184         }
185
186 }
187
188
189 void TapiEventCbMsgIncoming(TapiHandle *handle, const char *noti_id, void *data, void *user_data)
190 {
191         MSG_DEBUG("TapiEventCbMsgIncoming is called. noti_id [%s]", noti_id);
192
193         if (data == NULL) {
194                 MSG_DEBUG("Error. evt->pData is NULL.");
195                 return;
196         }
197
198         TelSmsCbMsg_t *pCbMsg = (TelSmsCbMsg_t*)data;
199
200         try
201         {
202                 SmsPluginCbMsgHandler::instance()->handleCbMsg(pCbMsg);
203         }
204         catch (MsgException& e)
205         {
206                 MSG_FATAL("%s", e.what());
207                 return;
208         }
209
210 }
211
212
213 void TapiEventEtwsMsgIncoming(TapiHandle *handle, const char *noti_id, void *data, void *user_data)
214 {
215         MSG_DEBUG("TapiEventEtwsMsgIncoming is called. noti_id [%s]", noti_id);
216
217         if (data == NULL) {
218                 MSG_DEBUG("Error. evt->pData is NULL.");
219                 return;
220         }
221
222         TelSmsEtwsMsg_t *pEtwsMsg = (TelSmsEtwsMsg_t*)data;
223
224         try
225         {
226                 SmsPluginCbMsgHandler::instance()->handleEtwsMsg(pEtwsMsg);
227         }
228         catch (MsgException& e)
229         {
230                 MSG_FATAL("%s", e.what());
231                 return;
232         }
233 }
234
235
236 void TapiEventDeliveryReportCNF(TapiHandle *handle, int result, void *data, void *user_data)
237 {
238         MSG_DEBUG("TapiEventDeliveryReportCNF is called. : result = [%d]", result);
239
240         return;
241 }
242
243
244 void TapiEventGetSimMsgCnt(TapiHandle *handle, int result, void *data, void *user_data)
245 {
246         MSG_DEBUG("TapiEventGetSimMsgCnt is called.");
247
248         if (result != TAPI_API_SUCCESS || data == NULL)
249         {
250                 MSG_DEBUG("Error. data is NULL.");
251                 MSG_SIM_COUNT_S simCnt;
252                 memset(&simCnt, 0x00, sizeof(MSG_SIM_COUNT_S));
253                 SmsPluginSimMsg::instance()->setSimMsgCntEvent(&simCnt);
254                 return;
255         }
256
257         SmsPluginSimMsg::instance()->setSimMsgCntEvent((MSG_SIM_COUNT_S *)data);
258
259 }
260
261
262 void TapiEventGetSimMsg(TapiHandle *handle, int result, void *data, void *user_data)
263 {
264         MSG_DEBUG("TapiEventGetSimMsg is called.");
265
266         if (result != TAPI_API_SUCCESS || data == NULL)
267         {
268                 MSG_DEBUG("Error!! pEvent->Status [%d]", result);
269
270                 SmsPluginSimMsg::instance()->setSimMsgEvent(NULL, false);
271
272                 return;
273         }
274
275         TelSmsData_t* pSmsTpdu = (TelSmsData_t*)data;
276
277         // Reading TelSmsData_t
278         MSG_DEBUG ("sim index %d", pSmsTpdu->SimIndex);
279         MSG_DEBUG ("status %d", pSmsTpdu->MsgStatus);
280
281         // Reading TelSmsDatapackageInfo_t
282         if (pSmsTpdu->SmsData.MsgLength > MAX_TPDU_DATA_LEN)
283         {
284                 MSG_DEBUG ("WARNING: tpdu_len > MAX_SMS_TPDU_SIZE [%d] bytes. setting to 0.", pSmsTpdu->SmsData.MsgLength);
285
286                 SmsPluginSimMsg::instance()->setSimMsgEvent(NULL, false);
287
288                 return;
289         }
290
291         SMS_TPDU_S tpdu;
292
293         // decode Tpdu
294         SmsPluginTpduCodec::decodeTpdu(pSmsTpdu->SmsData.szData, pSmsTpdu->SmsData.MsgLength, &tpdu);
295
296         MSG_DEBUG("Sim Message Type [%d]", tpdu.tpduType);
297
298         bool bRead = false;
299
300         // set read status
301         if (pSmsTpdu->MsgStatus == TAPI_NETTEXT_STATUS_READ)
302                 bRead = true;
303         else if (pSmsTpdu->MsgStatus == TAPI_NETTEXT_STATUS_UNREAD)
304                 bRead = false;
305
306         if (tpdu.tpduType == SMS_TPDU_DELIVER)
307         {
308                 if (tpdu.data.deliver.dcs.codingScheme == SMS_CHARSET_8BIT && tpdu.data.deliver.pid == 0x11) {
309                         MSG_DEBUG("Unsupported message!!");
310                         SmsPluginSimMsg::instance()->setSimMsgEvent(NULL, false);
311                         return;
312                 }
313
314                 MSG_DEBUG("headerCnt [%d]", tpdu.data.deliver.userData.headerCnt);
315                 for (int i = 0; i < tpdu.data.deliver.userData.headerCnt; i++)
316                 {
317                         // Handler Concatenated Message
318                         if (tpdu.data.deliver.userData.header[i].udhType == SMS_UDH_CONCAT_8BIT ||
319                                 tpdu.data.deliver.userData.header[i].udhType == SMS_UDH_CONCAT_16BIT)
320                         {
321                                 SmsPluginSimMsg::instance()->setSimMsgEvent(NULL, false);
322                                 return;
323                         }
324                 }
325         }
326         else if (tpdu.tpduType == SMS_TPDU_SUBMIT)
327         {
328                 if (tpdu.data.submit.dcs.codingScheme == SMS_CHARSET_8BIT && tpdu.data.submit.pid == 0x11) {
329                         MSG_DEBUG("Unsupported message!!");
330                         SmsPluginSimMsg::instance()->setSimMsgEvent(NULL, false);
331                         return;
332                 }
333
334                 MSG_DEBUG("headerCnt [%d]", tpdu.data.submit.userData.headerCnt);
335
336                 for (int i = 0; i < tpdu.data.submit.userData.headerCnt; i++)
337                 {
338                         // Handler Concatenated Message
339                         if (tpdu.data.submit.userData.header[i].udhType == SMS_UDH_CONCAT_8BIT ||
340                                 tpdu.data.submit.userData.header[i].udhType == SMS_UDH_CONCAT_16BIT)
341                         {
342                                 SmsPluginSimMsg::instance()->setSimMsgEvent(NULL, false);
343                                 return;
344                         }
345                 }
346         }
347
348         // Make MSG_MESSAGE_INFO_S
349         MSG_MESSAGE_INFO_S msgInfo;
350         memset(&msgInfo, 0x00, sizeof(MSG_MESSAGE_INFO_S));
351
352         SmsPluginEventHandler::instance()->convertTpduToMsginfo(&tpdu, &msgInfo);
353
354         // set Sim Message ID
355         msgInfo.msgId = pSmsTpdu->SimIndex;
356
357         // set read status
358         msgInfo.bRead = bRead;
359
360         // set storage id
361         msgInfo.storageId = MSG_STORAGE_SIM;
362
363         /// Print MSG_MESSAGE_INFO_S
364         MSG_DEBUG("############# Convert  tpdu values to Message Info values ####################");
365         MSG_DEBUG("msgInfo.msgId : %d", msgInfo.msgId);
366         MSG_DEBUG("msgInfo.nAddressCnt : %d", msgInfo.nAddressCnt);
367         MSG_DEBUG("msgInfo.addressList[0].addressType : %d", msgInfo.addressList[0].addressType);
368         MSG_DEBUG("msgInfo.addressList[0].addressVal : %s", msgInfo.addressList[0].addressVal);
369         MSG_DEBUG("msgInfo.priority : %d", msgInfo.priority);
370         MSG_DEBUG("msgInfo.bProtected : %d", msgInfo.bProtected);
371         MSG_DEBUG("msgInfo.bRead : %d", msgInfo.bRead);
372         MSG_DEBUG("msgInfo.bTextSms : %d", msgInfo.bTextSms);
373         MSG_DEBUG("msgInfo.direction : %d", msgInfo.direction);
374         MSG_DEBUG("msgInfo.msgType.mainType : %d", msgInfo.msgType.mainType);
375         MSG_DEBUG("msgInfo.msgType.subType : %d", msgInfo.msgType.subType);
376         MSG_DEBUG("msgInfo.msgType.classType : %d", msgInfo.msgType.classType);
377         MSG_DEBUG("msgInfo.displayTime : %s", ctime(&msgInfo.displayTime));
378         MSG_DEBUG("msgInfo.dataSize : %d", msgInfo.dataSize);
379         if (msgInfo.bTextSms == true)
380                 MSG_DEBUG("msgInfo.msgText : %s", msgInfo.msgText);
381         else
382         MSG_DEBUG("msgInfo.msgData : %s", msgInfo.msgData);
383         MSG_DEBUG("###############################################################");
384
385         SmsPluginSimMsg::instance()->setSimMsgEvent(&msgInfo, true); // Call Event Handler
386
387 }
388
389
390 void TapiEventSaveSimMsg(TapiHandle *handle, int result, void *data, void *user_data)
391 {
392         MSG_DEBUG("TapiEventSaveSimMsg is called. result [%d]", result);
393
394         int simId = -1;
395
396         if (data != NULL)
397                 simId = *((int*)data);
398         else
399                 MSG_DEBUG("Data(SIM Msg ID) is NULL");
400
401         SmsPluginSimMsg::instance()->setSaveSimMsgEvent(simId, result);
402 }
403
404
405 void TapiEventSaveClass2Msg(TapiHandle *handle, int result, void *data, void *user_data)
406 {
407         MSG_DEBUG("TapiEventSaveSimMsg is called. result [%d]", result);
408
409         int simId = -1;
410
411         if (data != NULL)
412                 simId = *((int*)data);
413         else
414                 MSG_DEBUG("Data(SIM Msg ID) is NULL");
415
416         SmsPluginSimMsg::instance()->setSaveClass2MsgEvent(simId, result);
417 }
418
419
420 void TapiEventDeleteSimMsg(TapiHandle *handle, int result, void *data, void *user_data)
421 {
422         MSG_DEBUG("TapiEventDeleteSimMsg is called. result [%d]", result);
423
424         MSG_DEBUG("status : [%d]", (TelSmsCause_t)result);
425
426         if (result != TAPI_API_SUCCESS || data == NULL)
427         {
428                 MSG_DEBUG("Error. data is NULL.");
429                 SmsPluginSimMsg::instance()->setSimEvent((msg_sim_id_t)0, false);
430                 return;
431         }
432
433         int sim_id = *((int*)data);
434
435         SmsPluginSimMsg::instance()->setSimEvent((msg_sim_id_t)sim_id, true);
436
437 }
438
439
440 void TapiEventSetConfigData(TapiHandle *handle, int result, void *data, void *user_data)
441 {
442         MSG_DEBUG("TapiEventSetConfigData is called.");
443
444         if (data == NULL)
445         {
446                 MSG_DEBUG("Error. data is NULL.");
447                 return;
448         }
449
450         TelSmsSetResponse* responseType = (TelSmsSetResponse*)data;
451
452         MSG_DEBUG("responseType : [%d]", *responseType);
453
454         switch (*responseType)
455         {
456                 case TAPI_NETTEXT_SETPREFERREDBEARER_RSP :
457                         MSG_DEBUG("TAPI_NETTEXT_SETPREFERREDBEARER_RSP is called");
458                 break;
459
460                 case TAPI_NETTEXT_SETPARAMETERS_RSP :
461                         MSG_DEBUG("TAPI_NETTEXT_SETPARAMETERS_RSP is called");
462                 break;
463
464                 case TAPI_NETTEXT_CBSETCONFIG_RSP :
465                         MSG_DEBUG("TAPI_NETTEXT_CBSETCONFIG_RSP is called");
466                 break;
467
468                 case TAPI_NETTEXT_SETMEMORYSTATUS_RSP :
469                         MSG_DEBUG("TAPI_NETTEXT_SETMEMORYSTATUS_RSP is called");
470                 break;
471
472                 case TAPI_NETTEXT_SETMESSAGESTATUS_RSP :
473                         MSG_DEBUG("TAPI_NETTEXT_SETMESSAGESTATUS_RSP is called");
474                 break;
475
476                 default :
477                         MSG_DEBUG("Unknown Response is called [%d]", *responseType);
478                 break;
479         }
480
481         bool bRet = true;
482
483         MSG_DEBUG("status : [%d]", (TelSmsCause_t)result);
484
485         if ((TelSmsCause_t)result != TAPI_NETTEXT_SUCCESS) bRet = false;
486
487         if (*responseType == TAPI_NETTEXT_SETMESSAGESTATUS_RSP)
488                 SmsPluginSimMsg::instance()->setSimEvent(0, bRet);
489         else
490                 SmsPluginSetting::instance()->setResultFromSim(bRet);
491
492 }
493
494
495 void TapiEventGetParamCnt(TapiHandle *handle, int result, void *data, void *user_data)
496 {
497         MSG_DEBUG("TapiEventGetParamCnt is called.");
498
499         if (result != TAPI_API_SUCCESS || data == NULL)
500         {
501                 MSG_DEBUG("Error. evt->pData is NULL.");
502                 SmsPluginSetting::instance()->setParamCntEvent(0);
503                 return;
504         }
505
506         int paramCnt = 0;
507         paramCnt = *((int*)data);
508
509         SmsPluginSetting::instance()->setParamCntEvent(paramCnt);
510
511 }
512
513
514 void TapiEventGetParam(TapiHandle *handle, int result, void *data, void *user_data)
515 {
516         MSG_DEBUG("TapiEventGetConfigData is called.");
517
518         if (result != TAPI_API_SUCCESS || data == NULL)
519         {
520                 MSG_DEBUG("Error. data is NULL.");
521                 SmsPluginSetting::instance()->setParamEvent(NULL, -1, false);
522                 return;
523         }
524
525         TelSmsParams_t* smsParam = (TelSmsParams_t*)data;
526
527         int alphaIdLen = 0;
528         int addrLen = 0;
529         MSG_SMSC_DATA_S smscData = {0, };
530
531         /*Check Alpha ID value*/
532         alphaIdLen = smsParam->AlphaIdLen;
533         MSG_DEBUG("alphaId_len[%d]", alphaIdLen);
534
535         if (alphaIdLen < 0 || alphaIdLen > SMSC_NAME_MAX)
536         {
537                 MSG_DEBUG("Wrong Alpha ID Length[%d]", alphaIdLen);
538
539                 SmsPluginSetting::instance()->setParamEvent(NULL, -1, false);
540
541                 return;
542         }
543
544
545         /*Check Address value*/
546         addrLen = smsParam->TpSvcCntrAddr.DialNumLen;
547
548         if(addrLen > SMSC_ADDR_MAX)
549         {
550                 MSG_DEBUG("addrLen is too long: %d", addrLen);
551                 SmsPluginSetting::instance()->setParamEvent(NULL, -1, false);
552                 return;
553         }
554         else if(addrLen < 2)
555         {
556                 MSG_DEBUG("addrLen is too short: %d", addrLen);
557                 SmsPluginSetting::instance()->setParamEvent(NULL, -1, false);
558                 return;
559         }
560
561         MSG_DEBUG("addrLen : %d", addrLen);
562
563
564         /*SMSP Parameter Indicator value*/
565         MSG_DEBUG("ParamIndicator[%02x]", smsParam->ParamIndicator);
566
567         /*Get SMSC Address*/
568         if(0x00 == (0x02 & smsParam->ParamIndicator))
569         {
570                 MSG_DEBUG("record index[%d]", (int)smsParam->RecordIndex);
571
572                 MSG_DEBUG("TON : %d", smsParam->TpSvcCntrAddr.Ton);
573                 MSG_DEBUG("NPI : %d", smsParam->TpSvcCntrAddr.Npi);
574
575                 smscData.smscAddr.ton = smsParam->TpSvcCntrAddr.Ton;
576                 smscData.smscAddr.npi = smsParam->TpSvcCntrAddr.Npi;
577
578                 SmsPluginParamCodec paramCodec;
579
580                 memset(smscData.smscAddr.address, 0x00, SMSC_ADDR_MAX+1);
581                 paramCodec.decodeSMSC(smsParam->TpSvcCntrAddr.szDiallingNum, addrLen, smscData.smscAddr.ton, smscData.smscAddr.address);
582
583                 MSG_DEBUG("SMSC Address : [%s]", smscData.smscAddr.address);
584
585                 memset(smscData.name, 0x00, SMSC_NAME_MAX+1);
586                 memcpy(smscData.name, smsParam->szAlphaId, alphaIdLen);
587                 smscData.name[alphaIdLen] = '\0';
588
589                 MSG_DEBUG("SMSC Name : [%s]", smscData.name);
590         }
591         else
592         {
593                 MSG_DEBUG("SMSC Address is not present");
594
595 //              smscData.smscAddr.ton = MSG_TON_UNKNOWN;
596 //              smscData.smscAddr.npi = MSG_NPI_UNKNOWN;
597 //
598 //              memset(smscData.smscAddr.address, 0x00, SMSC_ADDR_MAX+1);
599 //              memset(smscData.name, 0x00, SMSC_NAME_MAX+1);
600
601                 SmsPluginSetting::instance()->setParamEvent(NULL, -1, false);
602
603                 return;
604         }
605
606         /*Get the PID value*/
607         if (0x00 == (0x04 & smsParam->ParamIndicator))
608         {
609                 SMS_PID_T pid = (SMS_PID_T)smsParam->TpProtocolId;
610
611                 MSG_DEBUG("smsParam->TpProtocolId : %d", smsParam->TpProtocolId);
612
613                 switch (pid)
614                 {
615                         case SMS_PID_NORMAL:
616                                 smscData.pid = MSG_PID_TEXT;
617                         break;
618                         case SMS_PID_VOICE:
619                                 smscData.pid = MSG_PID_VOICE;
620                         break;
621                         case SMS_PID_TELEX:
622                                 smscData.pid = MSG_PID_FAX;
623                         break;
624                         case SMS_PID_x400:
625                                 smscData.pid = MSG_PID_X400;
626                         break;
627                         case SMS_PID_ERMES:
628                                 smscData.pid = MSG_PID_ERMES;
629                         break;
630                         case SMS_PID_EMAIL:
631                                 smscData.pid = MSG_PID_EMAIL;
632                         break;
633                         default:
634                                 smscData.pid = MSG_PID_TEXT;
635                         break;
636                 }
637
638                 MSG_DEBUG("smscData.pid : %d", smscData.pid);
639         }
640         else
641         {
642                 MSG_DEBUG("PID is not present");
643                 smscData.pid = MSG_PID_TEXT;
644                 MSG_DEBUG("MSG_PID_TEXT is inserted to PID");
645         }
646
647 #if 0
648         /*Get the DCS value*/
649         if (0x00 == (0x08 & smsParam->ParamIndicator))
650         {
651                 smscList.smscData[index].dcs = smsParam->TpDataCodingScheme;
652                 MSG_DEBUG("dcs : %d", smscList.smscData[index].dcs);
653         }
654         else
655         {
656                 smscList.smscData[index].dcs = MSG_ENCODE_GSM7BIT;
657                 MSG_DEBUG("DCS is not present");
658         }
659 #endif
660
661         /*Get the ValidityPeriod value*/
662         if (0x00 == (0x10 & smsParam->ParamIndicator))
663         {
664                 smscData.valPeriod = smsParam->TpValidityPeriod;
665                 MSG_DEBUG("valPeriod : %d", smscData.valPeriod);
666         }
667         else
668         {
669                 smscData.valPeriod = 0;
670                 MSG_DEBUG("Validity Period is not present");
671         }
672
673         SmsPluginSetting::instance()->setParamEvent(&smscData, (int)smsParam->RecordIndex, true);
674
675 }
676
677
678 void TapiEventGetCBConfig(TapiHandle *handle, int result, void *data, void *user_data)
679 {
680         MSG_DEBUG("TapiEventGetCBConfig is called.");
681
682         MSG_CBMSG_OPT_S cbOpt = {0};
683
684         if (result != TAPI_API_SUCCESS || data == NULL)
685         {
686                 MSG_DEBUG("Error. data is NULL.");
687
688                 SmsPluginSetting::instance()->setCbConfigEvent(NULL, false);
689
690                 return;
691         }
692
693         TelSmsCbConfig_t* pCBConfig = (TelSmsCbConfig_t*)data;
694
695         cbOpt.bReceive = (bool)pCBConfig->CBEnabled;
696
697         cbOpt.maxSimCnt = pCBConfig->MsgIdMaxCount;
698
699         MSG_DEBUG("Receive [%d], Max SIM Count [%d]", cbOpt.bReceive, cbOpt.maxSimCnt);
700
701         cbOpt.channelData.channelCnt = pCBConfig->MsgIdRangeCount;
702
703         if (cbOpt.channelData.channelCnt > CB_CHANNEL_MAX)
704         {
705                 MSG_DEBUG("Channel Count [%d] from TAPI is over MAX", cbOpt.channelData.channelCnt);
706                 cbOpt.channelData.channelCnt = CB_CHANNEL_MAX;
707         }
708
709         if (MsgSettingSetInt(CB_CHANNEL_COUNT, cbOpt.channelData.channelCnt) != MSG_SUCCESS) {
710                 MSG_DEBUG("Error to set config data [%s]", CB_CHANNEL_COUNT);
711         }
712
713         MSG_DEBUG("Channel Count [%d]", cbOpt.channelData.channelCnt);
714
715         for (int i = 0; i < cbOpt.channelData.channelCnt; i++)
716         {
717                 cbOpt.channelData.channelInfo[i].bActivate = pCBConfig->MsgIDs[i].Net3gpp.Selected;
718                 cbOpt.channelData.channelInfo[i].from = pCBConfig->MsgIDs[i].Net3gpp.FromMsgId;
719                 cbOpt.channelData.channelInfo[i].to = pCBConfig->MsgIDs[i].Net3gpp.ToMsgId;
720                 memset(cbOpt.channelData.channelInfo[i].name, 0x00, CB_CHANNEL_NAME_MAX+1);
721
722                 MSG_DEBUG("Channel FROM [%d], Channel TO [%d] ", cbOpt.channelData.channelInfo[i].from, cbOpt.channelData.channelInfo[i].to);
723         }
724
725         SmsPluginSetting::instance()->setCbConfigEvent(&cbOpt, true);
726 }
727
728 void TapiEventSetMailboxInfo(TapiHandle *handle, int result, void *data, void *user_data)
729 {
730         MSG_DEBUG("TapiEventSetMailboxInfo is called. result = [%d]", result);
731
732         bool bRet = true;
733
734         if (result != TAPI_SIM_ACCESS_SUCCESS)
735                 bRet = false;
736
737         SmsPluginSetting::instance()->setResultFromSim(bRet);
738 }
739
740 void TapiEventGetMailboxInfo(TapiHandle *handle, int result, void *data, void *user_data)
741 {
742         MSG_DEBUG("TapiEventGetMailboxInfo is called.");
743
744         if (result != TAPI_SIM_ACCESS_SUCCESS || data == NULL)
745         {
746                 MSG_DEBUG("Error. data is NULL.");
747                 SmsPluginSetting::instance()->setMailboxInfoEvent(NULL, false);
748
749                 return;
750         }
751
752         TelSimMailboxList_t *list = (TelSimMailboxList_t *)data;
753         SMS_SIM_MAILBOX_LIST_S mbList = {0,};
754
755         if (list->count <= 0) {
756                 SmsPluginSetting::instance()->setMailboxInfoEvent(NULL, true);
757                 return;
758         }
759
760         mbList.count = list->count;
761
762         for (int i = 0; i < mbList.count; i++) {
763                 mbList.list[i].b_cphs = list->list[i].b_cphs;
764                 mbList.list[i].alpha_id_max_len = list->list[i].alpha_id_max_len;
765                 mbList.list[i].mb_type = list->list[i].mb_type;
766                 mbList.list[i].profile_num = list->list[i].profile_num;
767                 mbList.list[i].rec_index = list->list[i].rec_index;
768                 mbList.list[i].ton = list->list[i].ton;
769                 mbList.list[i].npi = list->list[i].npi;
770                 snprintf(mbList.list[i].alpha_id, sizeof(mbList.list[i].alpha_id), "%s", list->list[i].alpha_id);
771                 snprintf(mbList.list[i].num, sizeof(mbList.list[i].num), "%s", list->list[i].num);
772                 mbList.list[i].cc_id = list->list[i].cc_id;
773                 mbList.list[i].ext1_id = list->list[i].ext1_id;
774         }
775
776         SmsPluginSetting::instance()->setMailboxInfoEvent(&mbList, true);
777 }
778
779 void TapiEventSetMwiInfo(TapiHandle *handle, int result, void *data, void *user_data)
780 {
781         MSG_DEBUG("TapiEventSetMwiInfo is called. result = [%d]", result);
782
783         bool bRet = true;
784
785         if (result != TAPI_SIM_ACCESS_SUCCESS)
786                 bRet = false;
787
788         SmsPluginSetting::instance()->setResultFromSim(bRet);
789 }
790
791 void TapiEventGetMwiInfo(TapiHandle *handle, int result, void *data, void *user_data)
792 {
793         MSG_DEBUG("TapiEventGetMwiInfo is called.");
794
795         if (result != TAPI_SIM_ACCESS_SUCCESS || data == NULL)
796         {
797                 MSG_DEBUG("Error. data is NULL.");
798                 SmsPluginSetting::instance()->setMwiInfoEvent(NULL, false);
799
800                 return;
801         }
802
803         TelSimMessageWaitingResp_t *MwiInfo = (TelSimMessageWaitingResp_t *)data;
804         SMS_SIM_MWI_INFO_S simMwiInfo = {0,};
805
806         memcpy(&simMwiInfo, MwiInfo, sizeof(SMS_SIM_MWI_INFO_S));
807
808         SmsPluginSetting::instance()->setMwiInfoEvent(&simMwiInfo, true);
809 }
810
811 void TapiEventGetMsisdnInfo(TapiHandle *handle, int result, void *data, void *user_data)
812 {
813         MSG_DEBUG("TapiEventGetMsisdnInfo is called.");
814
815         if (result != TAPI_SIM_ACCESS_SUCCESS || data == NULL)
816         {
817                 MSG_DEBUG("Error. data is NULL.");
818                 return;
819         }
820
821         TelSimMsisdnList_t *list = (TelSimMsisdnList_t *)data;
822
823         for (int i = 0; i < list->count; i++) {
824                 if (list->list[i].num[0] != '\0') {
825                         if (MsgSettingSetString(MSG_SIM_MSISDN, list->list[i].num) == MSG_SUCCESS)
826                                 MSG_DEBUG("Get MSISDN from SIM : [%s]", list->list[i].num);
827                         else
828                                 MSG_DEBUG("Getting MSISDN is failed!");
829
830                         break;
831                 }
832         }
833 }
834
835 void TapiEventSatSmsRefresh(TapiHandle *handle, int result, void *data, void *user_data)
836 {
837         MSG_DEBUG("TapiEventSatSmsRefresh is called.");
838
839         if (result != TAPI_API_SUCCESS || data == NULL)
840         {
841                 MSG_DEBUG("Error. data is NULL.");
842                 return;
843         }
844
845         try
846         {
847                 SmsPluginSatHandler::instance()->refreshSms(data);
848         }
849         catch (MsgException& e)
850         {
851                 MSG_FATAL("%s", e.what());
852                 return;
853         }
854
855 }
856
857
858 void TapiEventSatSendSms(TapiHandle *handle, const char *noti_id, void *data, void *user_data)
859 {
860         MSG_DEBUG("TapiEventSatSendSms is called.");
861
862         if (data == NULL)
863         {
864                 MSG_DEBUG("Error. data is NULL.");
865                 return;
866         }
867
868         try
869         {
870                 SmsPluginSatHandler::instance()->sendSms(data);
871         }
872         catch (MsgException& e)
873         {
874                 MSG_FATAL("%s", e.what());
875                 return;
876         }
877
878 }
879
880
881 void TapiEventSatMoSmsCtrl(TapiHandle *handle, int result, void *data, void *user_data)
882 {
883         MSG_DEBUG("TapiEventSatMoSmsCtrl is called.");
884
885         if (result != TAPI_API_SUCCESS || data == NULL)
886         {
887                 MSG_DEBUG("Error. data is NULL.");
888                 return;
889         }
890
891         try
892         {
893                 SmsPluginSatHandler::instance()->ctrlSms(data);
894         }
895         catch (MsgException& e)
896         {
897                 MSG_FATAL("%s", e.what());
898                 return;
899         }
900
901 }
902
903 void TapiEventMemoryStatus(TapiHandle *handle, int result, void *data, void *user_data)
904 {
905         MSG_DEBUG("Tapi result is [%d]", result);
906 }
907
908 void TapiEventSetMsgStatus(TapiHandle *handle, int result, void *data, void *user_data)
909 {
910         MSG_DEBUG("TapiEventSetMsgStatus is called. result [%d]", result);
911
912         if (result != TAPI_API_SUCCESS || data == NULL)
913         {
914                 MSG_DEBUG("Error. data is NULL.");
915                 SmsPluginSimMsg::instance()->setSimEvent((msg_sim_id_t)0, false);
916                 return;
917         }
918
919         msg_sim_id_t sim_id = *((msg_sim_id_t *)user_data);
920
921         SmsPluginSimMsg::instance()->setSimEvent(sim_id, true);
922 }
923
924 /*==================================================================================================
925                                      IMPLEMENTATION OF SmsPluginCallback - Member Functions
926 ==================================================================================================*/
927 SmsPluginCallback* SmsPluginCallback::pInstance = NULL;
928
929
930 SmsPluginCallback::SmsPluginCallback()
931 {
932
933
934 }
935
936
937 SmsPluginCallback::~SmsPluginCallback()
938 {
939         if (pInstance != NULL)
940         {
941                 delete pInstance;
942                 pInstance = NULL;
943         }
944 }
945
946
947 SmsPluginCallback* SmsPluginCallback::instance()
948 {
949         if (!pInstance)
950                 pInstance = new SmsPluginCallback();
951
952         return pInstance;
953 }
954
955
956 void SmsPluginCallback::registerEvent()
957 {
958         tel_register_noti_event(pTapiHandle, TAPI_NOTI_SMS_DEVICE_READY, TapiEventDeviceReady, NULL);
959         tel_register_noti_event(pTapiHandle, TAPI_NOTI_SMS_INCOM_MSG, TapiEventMsgIncoming, NULL);
960         tel_register_noti_event(pTapiHandle, TAPI_NOTI_SMS_CB_INCOM_MSG, TapiEventCbMsgIncoming, NULL);
961         tel_register_noti_event(pTapiHandle, TAPI_NOTI_SMS_ETWS_INCOM_MSG, TapiEventEtwsMsgIncoming, NULL);
962 //      tel_register_noti_event(pTapiHandle, TAPI_NOTI_SAT_REFRESH, TapiEventSatSmsRefresh, NULL);
963         tel_register_noti_event(pTapiHandle, TAPI_NOTI_SAT_SEND_SMS, TapiEventSatSendSms, NULL);
964 //      tel_register_noti_event(pTapiHandle, TAPI_NOTI_SAT_MO_SMS_CTRL, TapiEventSatMoSmsCtrl, NULL);
965 }
966
967
968 void SmsPluginCallback::deRegisterEvent()
969 {
970
971
972 }
973