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