RSA sync with private
[platform/core/messaging/msg-service.git] / plugin / sms_plugin / SmsPluginSimMsg.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 <errno.h>
18
19 #include "MsgDebug.h"
20 #include "MsgCppTypes.h"
21 #include "MsgException.h"
22 #include "MsgGconfWrapper.h"
23 #include "SmsPluginParamCodec.h"
24 #include "SmsPluginTpduCodec.h"
25 #include "SmsPluginTransport.h"
26 #include "SmsPluginStorage.h"
27 #include "SmsPluginEventHandler.h"
28 #include "SmsPluginCallback.h"
29 #include "SmsPluginSimMsg.h"
30
31 extern struct tapi_handle *pTapiHandle;
32
33 /*==================================================================================================
34                                      IMPLEMENTATION OF SmsPluginSimMsg - Member Functions
35 ==================================================================================================*/
36 SmsPluginSimMsg* SmsPluginSimMsg::pInstance = NULL;
37
38
39 SmsPluginSimMsg::SmsPluginSimMsg()
40 {
41         // Initialize member variables
42         simMsgId = 0;
43         usedCnt = 0;
44         totalCnt = 0;
45         bTapiResult = false;
46         memset(&simMsgDataInfo, 0x00, sizeof(simMsgDataInfo));
47 }
48
49
50 SmsPluginSimMsg::~SmsPluginSimMsg()
51 {
52
53
54 }
55
56
57 SmsPluginSimMsg* SmsPluginSimMsg::instance()
58 {
59         if (!pInstance)
60                 pInstance = new SmsPluginSimMsg();
61
62         return pInstance;
63 }
64
65
66 void SmsPluginSimMsg::initSimMessage()
67 {
68         MSG_BEGIN();
69
70         MSG_SIM_COUNT_S tmpMsgCnt;
71         memset(&tmpMsgCnt, 0x00, sizeof(MSG_SIM_COUNT_S));
72
73         getSimMsgCount(&tmpMsgCnt);
74
75         MSG_MESSAGE_INFO_S tmpMsgInfo;
76         memset(&tmpMsgInfo, 0x00, sizeof(MSG_MESSAGE_INFO_S));
77
78         for (int i = 0; i < tmpMsgCnt.usedCount; i++)
79         {
80                 // Get SIM Msg
81                 if (getSimMsg(tmpMsgCnt.indexList[i], &tmpMsgInfo) == false)
82                         continue;
83
84                 if (SmsPluginStorage::instance()->addSimMessage(&tmpMsgInfo) != MSG_SUCCESS)
85                 {
86                         MSG_DEBUG("Fail to addSimMessage()");
87                 }
88         }
89
90         MSG_END();
91 }
92
93
94 msg_error_t SmsPluginSimMsg::saveSimMessage(const MSG_MESSAGE_INFO_S *pMsgInfo, SMS_SIM_ID_LIST_S *pSimIdList)
95 {
96         // Reset Out Parameter
97         pSimIdList->count = 0;
98
99         SMS_TPDU_S tpdu;
100         memset(&tpdu, 0x00, sizeof(SMS_TPDU_S));
101
102         tpdu.tpduType = SMS_TPDU_DELIVER;
103
104         // Set SMS TPDU Options
105         setSmsOptions(&(tpdu.data.deliver));
106
107         // Set TimeStamp
108         convertTimeStamp(pMsgInfo, &(tpdu.data.deliver));
109
110         // Set SMSC Options
111         SMS_ADDRESS_S smsc;
112         memset(&smsc, 0x00, sizeof(SMS_ADDRESS_S));
113         SmsPluginTransport::instance()->setSmscOptions(&smsc);
114
115         // Make SMS_SUBMIT_DATA_S from MSG_REQUEST_INFO_S
116         SMS_SUBMIT_DATA_S submitData;
117         memset(&submitData, 0x00, sizeof(SMS_SUBMIT_DATA_S));
118         SmsPluginTransport::instance()->msgInfoToSubmitData(pMsgInfo, &submitData, &(tpdu.data.deliver.dcs.codingScheme), 0);
119
120         // Check sim message full.
121         if (checkSimMsgFull(submitData.segCount) == true)
122         {
123                 MSG_DEBUG("SIM storage is full.");
124
125                 return MSG_ERR_SIM_STORAGE_FULL;
126         }
127
128         tpdu.data.deliver.userData.headerCnt = 0;
129
130         if (submitData.segCount > 1)
131                 tpdu.data.deliver.bHeaderInd = true;
132
133         int bufLen = 0;
134
135         char buf[MAX_TPDU_DATA_LEN];
136
137         int addLen = strlen(submitData.destAddress.address);
138
139         tpdu.data.deliver.originAddress.ton = submitData.destAddress.ton;
140         tpdu.data.deliver.originAddress.npi = submitData.destAddress.npi;
141
142         memcpy(tpdu.data.deliver.originAddress.address, submitData.destAddress.address, addLen);
143         tpdu.data.deliver.originAddress.address[addLen] = '\0';
144
145         for (unsigned int segCnt = 0; segCnt < submitData.segCount; segCnt++)
146         {
147                 tpdu.data.deliver.userData.length = submitData.userData[segCnt].length;
148                 memcpy(tpdu.data.deliver.userData.data, submitData.userData[segCnt].data, submitData.userData[segCnt].length);
149
150                 memset(buf, 0x00, sizeof(buf));
151
152                 // Encode SMS-DELIVER TPDU
153                 bufLen = SmsPluginTpduCodec::encodeTpdu(&tpdu, buf);
154
155                 // Make Telephony Structure
156                 TelSmsData_t simSmsData;
157                 memset((void*)&simSmsData, 0x00, sizeof(simSmsData));
158
159                 // Set TPDU data
160                 memcpy((void*)simSmsData.SmsData.szData, buf, bufLen);
161
162                 simSmsData.SmsData.szData[bufLen] = 0;
163                 simSmsData.SmsData.MsgLength = bufLen;
164
165 #ifdef MSG_FOR_DEBUG
166                 MSG_DEBUG("Sim Message.");
167                 for (int j = 0; j < simSmsData.SmsData.MsgLength; j++)
168                 {
169                         MSG_DEBUG("[%02x]", simSmsData.SmsData.szData[j]);
170                 }
171 #endif
172
173                 MSG_DEBUG("Read Status [%d]", pMsgInfo->bRead);
174
175                 if (pMsgInfo->bRead == true)
176                         simSmsData.MsgStatus = TAPI_NETTEXT_STATUS_READ;
177                 else
178                         simSmsData.MsgStatus = TAPI_NETTEXT_STATUS_UNREAD;
179
180                 // Save SMS in SIM
181                 int ret = 0;
182
183                 ret = tel_write_sms_in_sim(pTapiHandle, &simSmsData, TapiEventSaveSimMsg, NULL);
184
185                 if (ret == TAPI_API_SUCCESS)
186                 {
187                         MSG_DEBUG("########  tel_write_sms_in_sim Success !!!#######");
188                 }
189                 else
190                 {
191                         MSG_DEBUG("########  tel_write_sms_in_sim Fail !!! return : [%d] #######", ret);
192
193                         return MSG_ERR_PLUGIN_STORAGE;
194                 }
195
196                 msg_sim_id_t SimId = 0;
197
198                 bool bResult = false;
199
200                 bResult = getSimEvent(&SimId);
201
202                 int usedCnt = 0;
203
204                 if (bResult == true)
205                 {
206                         MSG_DEBUG("########  Saving Msg was Successful !!! SIM ID : [%d] #######", SimId);
207
208                         usedCnt = MsgSettingGetInt(SIM_USED_COUNT);
209
210                         usedCnt++;
211
212                         if (MsgSettingSetInt(SIM_USED_COUNT, usedCnt) != MSG_SUCCESS)
213                         {
214                                 MSG_DEBUG("Error to set config data [%s]", SIM_USED_COUNT);
215                         }
216
217                         pSimIdList->simId[pSimIdList->count] = SimId;
218                         pSimIdList->count++;
219                 }
220                 else
221                 {
222                         MSG_DEBUG("########  Saving Msg was Failed !!! SIM ID : [%d] #######", SimId);
223
224                         return MSG_ERR_PLUGIN_STORAGE;
225                 }
226         }
227
228         return MSG_SUCCESS;
229 }
230
231
232 msg_error_t SmsPluginSimMsg::saveClass2Message(const MSG_MESSAGE_INFO_S *pMsgInfo)
233 {
234         // Reset Flag
235         SMS_TPDU_S tpdu;
236
237         tpdu.tpduType = SMS_TPDU_DELIVER;
238
239         // Set SMS TPDU Options
240         setSmsOptions(&(tpdu.data.deliver));
241
242         // Make SMS_SUBMIT_DATA_S from MSG_REQUEST_INFO_S to get segment count
243         SMS_SUBMIT_DATA_S submitData;
244         SmsPluginTransport::instance()->msgInfoToSubmitData(pMsgInfo, &submitData, &(tpdu.data.deliver.dcs.codingScheme), 0);
245
246         // Check sim message full.
247         if (checkSimMsgFull(submitData.segCount) == true)
248         {
249                 MSG_DEBUG("SIM storage is full.");
250
251                 SmsPluginTransport::instance()->sendDeliverReport(MSG_ERR_SIM_STORAGE_FULL);
252
253                 return MSG_ERR_SIM_STORAGE_FULL;
254         }
255
256         // Create TelSmsData_t data
257         TelSmsData_t simSmsData = {0,};
258
259         memcpy(&simSmsData.SmsData.Sca, &simMsgDataInfo.sca, sizeof(simSmsData.SmsData.Sca));
260         memcpy(&simSmsData.SmsData.szData, &simMsgDataInfo.szData, sizeof(simSmsData.SmsData.szData)-1);
261         simSmsData.SmsData.MsgLength = simMsgDataInfo.msgLength;
262
263         // Set message status
264         simSmsData.MsgStatus = TAPI_NETTEXT_STATUS_UNREAD;
265
266         // Save Class 2 Msg in SIM
267         int tapiRet = TAPI_API_SUCCESS;
268
269         tapiRet = tel_write_sms_in_sim(pTapiHandle, &simSmsData, TapiEventSaveClass2Msg, NULL);
270
271         if (tapiRet == TAPI_API_SUCCESS)
272         {
273                 memset(&simMsgInfo, 0x00, sizeof(MSG_MESSAGE_INFO_S));
274                 memcpy(&simMsgInfo, pMsgInfo, sizeof(MSG_MESSAGE_INFO_S));
275
276                 MSG_DEBUG("########  tel_write_sms_in_sim Success !!! #######");
277         }
278         else
279         {
280                 MSG_DEBUG("########  tel_write_sms_in_sim Fail !!! return : [%d] #######", tapiRet);
281
282                 SmsPluginTransport::instance()->sendDeliverReport(MSG_ERR_STORAGE_ERROR);
283
284                 return MSG_ERR_PLUGIN_STORAGE;
285         }
286
287         return MSG_SUCCESS;
288 }
289
290
291 void SmsPluginSimMsg::deleteSimMessage(msg_sim_id_t SimMsgId)
292 {
293         int tapiRet = TAPI_API_SUCCESS;
294
295         tapiRet = tel_delete_sms_in_sim(pTapiHandle, (int)SimMsgId, TapiEventDeleteSimMsg, NULL);
296
297         if (tapiRet == TAPI_API_SUCCESS)
298         {
299                 MSG_DEBUG("########  tel_delete_sms_in_sim Success !!! #######");
300         }
301         else
302         {
303                 THROW(MsgException::SMS_PLG_ERROR, "########  tel_delete_sms_in_sim Fail !!! return : [%d] #######", tapiRet);
304         }
305
306         msg_sim_id_t SimId = 0;
307         bool bResult = false;
308
309         bResult = getSimEvent(&SimId);
310
311         int usedCnt = 0, totalCnt = 0;
312
313         if (bResult == true)
314         {
315                 MSG_DEBUG("########  Deleting Msg was Successful !!! SIM ID : [%d] #######", SimId);
316
317                 usedCnt = MsgSettingGetInt(SIM_USED_COUNT);
318                 totalCnt = MsgSettingGetInt(SIM_TOTAL_COUNT);
319
320                 if (usedCnt == totalCnt)
321                 {
322                         tapiRet = tel_set_sms_memory_status(pTapiHandle, TAPI_NETTEXT_PDA_MEMORY_STATUS_AVAILABLE, NULL, NULL);
323
324                         if (tapiRet == TAPI_API_SUCCESS)
325                         {
326                                 MSG_DEBUG("########  tel_set_sms_memory_status() Success !!! #######");
327                         }
328                         else
329                         {
330                                 MSG_DEBUG("########  tel_set_sms_memory_status() Success !!! return : [%d] #######", tapiRet);
331                         }
332                 }
333
334                 usedCnt--;
335
336                 if (MsgSettingSetInt(SIM_USED_COUNT, usedCnt) != MSG_SUCCESS)
337                 {
338                         MSG_DEBUG("Error to set config data [%s]", SIM_USED_COUNT);
339                 }
340         }
341         else
342         {
343                 THROW(MsgException::SMS_PLG_ERROR, "########  Deleting Msg was Failed !!! SIM ID : [%d] #######", SimId);
344         }
345 }
346
347
348 bool SmsPluginSimMsg::checkSimMsgFull(unsigned int SegCnt)
349 {
350         int usedCnt = 0, totalCnt = 0;
351
352         usedCnt = MsgSettingGetInt(SIM_USED_COUNT);
353         totalCnt = MsgSettingGetInt(SIM_TOTAL_COUNT);
354
355         MSG_DEBUG("Segment Count [%d]", SegCnt);
356         MSG_DEBUG("usedCnt [%d], totalCnt [%d]", usedCnt, totalCnt);
357
358         if ((usedCnt + (int)SegCnt) <= totalCnt)
359                 return false;
360         else
361                 return true;
362 }
363
364
365 void SmsPluginSimMsg::setReadStatus(msg_sim_id_t SimMsgId)
366 {
367         MSG_DEBUG("Sim Message ID [%d]", SimMsgId);
368
369         int ret = TAPI_API_SUCCESS;
370
371         ret = tel_set_sms_message_status(pTapiHandle, (int)SimMsgId, TAPI_NETTEXT_STATUS_READ, TapiEventSetMsgStatus, (void *)&SimMsgId);
372
373         if (ret == TAPI_API_SUCCESS)
374         {
375                 MSG_DEBUG("########  tel_set_sms_message_status Success !!! return : %d #######", ret);
376         }
377         else
378         {
379                 THROW(MsgException::SMS_PLG_ERROR, "########  tel_set_sms_message_status Fail !!! return : %d #######", ret);
380         }
381
382         msg_sim_id_t SimId = 0;
383         bool bResult = false;
384
385         bResult = getSimEvent(&SimId);
386
387         if (bResult == true)
388         {
389                 MSG_DEBUG("######## Setting Read Status was Successful !!!, sim id=[%d] #######", SimId);
390         }
391         else
392         {
393                 THROW(MsgException::SMS_PLG_ERROR, "######## Setting Read Status was Failed !!! #######");
394         }
395 }
396
397
398 void SmsPluginSimMsg::getSimMsgCount(MSG_SIM_COUNT_S *pSimMsgCnt)
399 {
400         int ret = TAPI_API_SUCCESS;
401
402         ret = tel_get_sms_count(pTapiHandle, TapiEventGetSimMsgCnt, NULL);
403
404         if (ret == TAPI_API_SUCCESS)
405         {
406                 MSG_DEBUG("######## tel_get_sms_count() Success !!! #######");
407         }
408         else
409         {
410                 THROW(MsgException::SMS_PLG_ERROR, "########  tel_get_sms_count() Fail !!! return : %d #######", ret);
411         }
412
413         if (getSimMsgCntEvent(pSimMsgCnt) == true)
414         {
415                 MSG_DEBUG("######## Get Sim Msg Count was Successful !!! #######");
416         }
417         else
418         {
419                 THROW(MsgException::SMS_PLG_ERROR, "######## Get Sim Msg Count was Failed !!! #######");
420         }
421 }
422
423
424 bool SmsPluginSimMsg::getSimMsg(msg_sim_id_t SimMsgId, MSG_MESSAGE_INFO_S *pMsgInfo)
425 {
426         int ret = TAPI_API_SUCCESS;
427
428         ret = tel_read_sms_in_sim(pTapiHandle, SimMsgId, TapiEventGetSimMsg, NULL);
429
430         if (ret == TAPI_API_SUCCESS)
431         {
432                 MSG_DEBUG("######## tel_read_sms_in_sim() Success !!! Sim ID : [%d] #######", SimMsgId);
433         }
434         else
435         {
436                 MSG_DEBUG("########  tel_read_sms_in_sim() Fail !!! return : %d #######", ret);
437                 return false;
438         }
439
440         if (getSimMsgEvent(pMsgInfo) == true)
441         {
442                 MSG_DEBUG("######## Get Sim Msg was Successful !!! #######");
443         }
444         else
445         {
446                 MSG_DEBUG("######## Get Sim Msg was Failed !!! #######");
447                 return false;
448         }
449
450         return true;
451 }
452
453
454 void SmsPluginSimMsg::setSmsOptions(SMS_DELIVER_S *pDeliver)
455 {
456         pDeliver->bMoreMsg = false;
457         pDeliver->bStatusReport = false;
458         pDeliver->bHeaderInd = false;
459         pDeliver->bReplyPath = false;
460
461         pDeliver->dcs.bCompressed = false;
462         pDeliver->dcs.msgClass = SMS_MSG_CLASS_NONE;
463         pDeliver->dcs.codingGroup = SMS_GROUP_GENERAL;
464
465         pDeliver->dcs.codingScheme = (SMS_CODING_SCHEME_T)MsgSettingGetInt(SMS_SEND_DCS);
466
467         MSG_DEBUG("DCS : %d", pDeliver->dcs.codingScheme);
468
469         pDeliver->pid = SMS_PID_NORMAL;
470
471         MSG_DEBUG("PID : %d", pDeliver->pid);
472 }
473
474
475 void SmsPluginSimMsg::convertTimeStamp(const MSG_MESSAGE_INFO_S* pMsgInfo, SMS_DELIVER_S *pDeliver)
476 {
477         MSG_BEGIN();
478
479         // encode time stamp
480         pDeliver->timeStamp.format = SMS_TIME_ABSOLUTE;
481
482         // encode absolute time
483         struct tm timeinfo = {0,};
484         gmtime_r(&pMsgInfo->displayTime, &timeinfo);
485
486         pDeliver->timeStamp.time.absolute.year = timeinfo.tm_year - 100;
487         MSG_DEBUG("pDeliver->timeStamp.time.absolute.year is %d",pDeliver->timeStamp.time.absolute.year);
488
489         pDeliver->timeStamp.time.absolute.month = timeinfo.tm_mon + 1;
490         MSG_DEBUG("pDeliver->timeStamp.time.absolute.month is %d",pDeliver->timeStamp.time.absolute.month);
491
492         pDeliver->timeStamp.time.absolute.day = timeinfo.tm_mday;
493         MSG_DEBUG("pDeliver->timeStamp.time.absolute.day is %d",pDeliver->timeStamp.time.absolute.day);
494
495         pDeliver->timeStamp.time.absolute.hour = timeinfo.tm_hour;
496         MSG_DEBUG("pDeliver->timeStamp.time.absolute.hour is %d",pDeliver->timeStamp.time.absolute.hour);
497
498         pDeliver->timeStamp.time.absolute.minute = timeinfo.tm_min;
499         MSG_DEBUG("pDeliver->timeStamp.time.absolute.minute is %d",pDeliver->timeStamp.time.absolute.minute);
500
501         pDeliver->timeStamp.time.absolute.second = timeinfo.tm_sec;
502         MSG_DEBUG("pDeliver->timeStamp.time.absolute.second is %d",pDeliver->timeStamp.time.absolute.second);
503
504         pDeliver->timeStamp.time.absolute.timeZone = 0;
505         MSG_DEBUG("pDeliver->timeStamp.time.absolute.timeZone is %d",pDeliver->timeStamp.time.absolute.timeZone);
506
507         MSG_END();
508 }
509
510
511 void SmsPluginSimMsg::setSimMsgCntEvent(const MSG_SIM_COUNT_S *pSimMsgCnt)
512 {
513         mx.lock();
514
515         MSG_DEBUG("Sim Message Count is %d.", pSimMsgCnt->usedCount);
516
517         for (int i=0; i < pSimMsgCnt->usedCount; i++)
518         {
519                 MSG_DEBUG("Sim Message Index is %d.", pSimMsgCnt->indexList[i]);
520         }
521
522         if (MsgSettingSetInt(SIM_USED_COUNT, pSimMsgCnt->usedCount) != MSG_SUCCESS)
523         {
524                 MSG_DEBUG("Error to set config data [%s]", SIM_USED_COUNT);
525         }
526
527         if (MsgSettingSetInt(SIM_TOTAL_COUNT, (int)pSimMsgCnt->totalCount) != MSG_SUCCESS)
528         {
529                 MSG_DEBUG("Error to set config data [%s]", SIM_TOTAL_COUNT);
530         }
531
532         memset(&simMsgCnt, 0x00, sizeof(MSG_SIM_COUNT_S));
533         memcpy(&simMsgCnt, pSimMsgCnt, sizeof(MSG_SIM_COUNT_S));
534
535         cv.signal();
536
537         mx.unlock();
538 }
539
540
541 bool SmsPluginSimMsg::getSimMsgCntEvent(MSG_SIM_COUNT_S *pSimMsgCnt)
542 {
543         int ret = 0;
544
545         mx.lock();
546
547         ret = cv.timedwait(mx.pMutex(), 10);
548
549         mx.unlock();
550
551         if (ret == ETIMEDOUT)
552         {
553                 MSG_DEBUG("WARNING: TAPI callback TIME-OUT");
554                 return false;
555         }
556
557         memcpy(pSimMsgCnt, &simMsgCnt, sizeof(MSG_SIM_COUNT_S));
558
559         return true;
560 }
561
562 void SmsPluginSimMsg::setSimMsgEvent(const MSG_MESSAGE_INFO_S *pMsgInfo, bool bSuccess)
563 {
564         mx.lock();
565
566         bTapiResult = bSuccess;
567
568         memset(&simMsgInfo, 0x00, sizeof(MSG_MESSAGE_INFO_S));
569
570         if (bTapiResult  == true)
571         {
572                 MSG_DEBUG("Success to get sim msg - Id : [%d]", pMsgInfo->msgId);
573
574                 memcpy(&simMsgInfo, pMsgInfo, sizeof(MSG_MESSAGE_INFO_S));
575         }
576
577         cv.signal();
578
579         mx.unlock();
580 }
581
582
583 bool SmsPluginSimMsg::getSimMsgEvent(MSG_MESSAGE_INFO_S *pMsgInfo)
584 {
585         int ret = 0;
586
587         bTapiResult = false;
588
589         mx.lock();
590
591         ret = cv.timedwait(mx.pMutex(), 10);
592
593         mx.unlock();
594
595         if (ret == ETIMEDOUT)
596         {
597                 MSG_DEBUG("WARNING: TAPI callback TIME-OUT");
598                 return false;
599         }
600
601         memset(pMsgInfo, 0x00, sizeof(MSG_MESSAGE_INFO_S));
602
603         if (bTapiResult == true)
604         {
605                 memcpy(pMsgInfo, &simMsgInfo, sizeof(MSG_MESSAGE_INFO_S));
606         }
607
608         return bTapiResult;
609 }
610
611
612 void SmsPluginSimMsg::setSaveSimMsgEvent(int simMsgId, int result)
613 {
614         msg_error_t err = MSG_SUCCESS;
615
616         mx.lock();
617
618         if (result != TAPI_NETTEXT_SENDSMS_SUCCESS) {
619                 if (result == TAPI_NETTEXT_ROUTING_NOT_AVAILABLE)
620                         err = MSG_ERR_SIM_STORAGE_FULL;
621                 else
622                         err = MSG_ERR_UNKNOWN;
623         }
624
625         if (err == MSG_SUCCESS)
626                 bTapiResult = true;
627         else
628                 bTapiResult = false;
629
630         cv.signal();
631
632         mx.unlock();
633
634         // Send Deliver Report
635         SmsPluginTransport::instance()->sendDeliverReport(err);
636
637 }
638
639
640 void SmsPluginSimMsg::setSaveClass2MsgEvent(int simMsgId, int result)
641 {
642         msg_error_t err = MSG_SUCCESS;
643
644         if (result == TAPI_NETTEXT_SENDSMS_SUCCESS && simMsgId >= 0) {
645
646                 simMsgInfo.msgId = simMsgId;
647
648                 err = SmsPluginStorage::instance()->addSimMessage(&simMsgInfo);
649
650                 if (err == MSG_SUCCESS)
651                 {
652                         MSG_DEBUG("addSimMessage() Success !!");
653
654                         // Callback
655                         err = SmsPluginEventHandler::instance()->callbackMsgIncoming(&simMsgInfo);
656
657                         if (err != MSG_SUCCESS)
658                         {
659                                 MSG_DEBUG("callbackMsgIncoming() Error !! [%d]", err);
660                         }
661
662                         usedCnt = MsgSettingGetInt(SIM_USED_COUNT);
663
664                         usedCnt++;
665
666                         if (MsgSettingSetInt(SIM_USED_COUNT, usedCnt) != MSG_SUCCESS)
667                         {
668                                 MSG_DEBUG("Error to set config data [%s]", SIM_USED_COUNT);
669                         }
670                 } else  {
671                         MSG_DEBUG("addMessage() Error !! [%d]", err);
672                 }
673         } else {
674                         if (result == TAPI_NETTEXT_ROUTING_NOT_AVAILABLE)
675                                 err = MSG_ERR_SIM_STORAGE_FULL;
676                         else
677                                 err = MSG_ERR_UNKNOWN;
678         }
679
680         // Send Deliver Report
681         SmsPluginTransport::instance()->sendDeliverReport(err);
682 }
683
684
685 void SmsPluginSimMsg::setSimEvent(msg_sim_id_t SimId, bool bResult)
686 {
687         mx.lock();
688
689         simMsgId = SimId;
690         bTapiResult = bResult;
691
692         cv.signal();
693
694         mx.unlock();
695 }
696
697
698 bool SmsPluginSimMsg::getSimEvent(msg_sim_id_t *pSimId)
699 {
700         int ret = 0;
701
702         bTapiResult = false;
703
704         mx.lock();
705
706         ret = cv.timedwait(mx.pMutex(), 10);
707
708         mx.unlock();
709
710         if (ret == ETIMEDOUT)
711         {
712                 MSG_DEBUG("WARNING: TAPI callback TIME-OUT");
713                 return false;
714         }
715
716         *pSimId = simMsgId;
717
718         MSG_DEBUG("Returned SimMsgId is %d.", simMsgId);
719
720         return bTapiResult;
721 }
722
723 void SmsPluginSimMsg::setSmsData(const char *sca, const char *szData, int msgLength)
724 {
725         MSG_DEBUG("Set SMS data(class2 message)");
726
727         memset(&simMsgDataInfo, 0x00, sizeof(simMsgDataInfo));
728
729         memcpy(&simMsgDataInfo.sca, sca, sizeof(simMsgDataInfo.sca)-1);
730         memcpy(&simMsgDataInfo.szData, szData, sizeof(simMsgDataInfo.szData)-1);
731         simMsgDataInfo.msgLength = msgLength;
732 }