svace issues fixed
[platform/core/messaging/msg-service.git] / plugin / sms_plugin / SmsPluginSatHandler.cpp
1 /*
2  * Copyright (c) 2014 Samsung Electronics Co., Ltd. All rights reserved
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15 */
16
17 #include <errno.h>
18 #include "MsgDebug.h"
19 #include "MsgCppTypes.h"
20 #include "MsgException.h"
21 #include "MsgGconfWrapper.h"
22 #include "MsgNotificationWrapper.h"
23 #include "MsgUtilStorage.h"
24 #include "SmsPluginParamCodec.h"
25 #include "SmsPluginUDCodec.h"
26 #include "SmsPluginTpduCodec.h"
27 #include "SmsPluginSetting.h"
28 #include "SmsPluginTransport.h"
29 #include "SmsPluginCallback.h"
30 #include "SmsPluginEventHandler.h"
31 #include "SmsPluginSatHandler.h"
32 #include "SmsPluginDSHandler.h"
33
34 extern "C" {
35         #include <tapi_common.h>
36         #include <TelSms.h>
37         #include <TapiUtility.h>
38         #include <ITapiNetText.h>
39         #include <ITapiSat.h>
40 }
41
42 /*==================================================================================================
43                                      IMPLEMENTATION OF SmsPluginCbMsgHandler - Member Functions
44 ==================================================================================================*/
45 SmsPluginSatHandler* SmsPluginSatHandler::pInstance = NULL;
46
47
48 SmsPluginSatHandler::SmsPluginSatHandler()
49 {
50         commandId = 0;
51
52         bInitSim = false;
53         bSMSPChanged = false;
54         bCBMIChanged = false;
55 }
56
57
58 SmsPluginSatHandler::~SmsPluginSatHandler()
59 {
60 }
61
62
63 SmsPluginSatHandler* SmsPluginSatHandler::instance()
64 {
65         if (!pInstance)
66                 pInstance = new SmsPluginSatHandler();
67
68         return pInstance;
69 }
70
71
72 void SmsPluginSatHandler::refreshSms(TapiHandle *handle, void *pData)
73 {
74         /*
75         TelSatRefreshInd_t* pRefreshData = (TelSatRefreshInd_t*)pData;
76
77         if (pRefreshData->appType != TAPI_SAT_REFRESH_MSG)
78         {
79                 MSG_DEBUG("App Type is wrong. [%d]", pRefreshData->appType);
80                 return;
81         }
82
83         commandId = pRefreshData->commandId;
84
85         switch (pRefreshData->refreshMode)
86         {
87                 case TAPI_SAT_REFRESH_SIM_INIT_AND_FULL_FCN :
88                 case TAPI_SAT_REFRESH_SIM_INIT_AND_FCN :
89                 {
90                         for (int i = 0; i < pRefreshData->fileCount; i++)
91                         {
92                                 if ((SMS_SIM_EFILE_NAME_T)pRefreshData->fileId[i].FileName == SMS_SIM_EFILE_USIM_SMSP ||
93                                         (SMS_SIM_EFILE_NAME_T)pRefreshData->fileId[i].FileName == SMS_SIM_EFILE_SMSP)
94                                 {
95                                         bSMSPChanged = true;
96                                 }
97                                 else if ((SMS_SIM_EFILE_NAME_T)pRefreshData->fileId[i].FileName == SMS_SIM_EFILE_USIM_CBMI ||
98                                         (SMS_SIM_EFILE_NAME_T)pRefreshData->fileId[i].FileName == SMS_SIM_EFILE_CBMI)
99                                 {
100                                         bCBMIChanged = true;
101                                 }
102                         }
103
104                         initSim();
105                 }
106                 break;
107
108                 case TAPI_SAT_REFRESH_FCN :
109                 {
110                         for (int i = 0; i < pRefreshData->fileCount; i++)
111                         {
112                                 if ((SMS_SIM_EFILE_NAME_T)pRefreshData->fileId[i].FileName == SMS_SIM_EFILE_USIM_SMSP ||
113                                         (SMS_SIM_EFILE_NAME_T)pRefreshData->fileId[i].FileName == SMS_SIM_EFILE_SMSP)
114                                 {
115                                         bSMSPChanged = true;
116                                 }
117                                 else if ((SMS_SIM_EFILE_NAME_T)pRefreshData->fileId[i].FileName == SMS_SIM_EFILE_USIM_CBMI ||
118                                         (SMS_SIM_EFILE_NAME_T)pRefreshData->fileId[i].FileName == SMS_SIM_EFILE_CBMI)
119                                 {
120                                         bCBMIChanged = true;
121                                 }
122                         }
123                 }
124                 break;
125
126                 case TAPI_SAT_REFRESH_SIM_INIT :
127                 {
128                         initSim();
129                 }
130                 break;
131
132                 default:
133                 break;
134         }
135         */
136 }
137
138
139 void SmsPluginSatHandler::sendSms(TapiHandle *handle, void *pData)
140 {
141         TelSatSendSmsIndSmsData_t* pSmsData = (TelSatSendSmsIndSmsData_t*)pData;
142
143         commandId = pSmsData->commandId;
144
145         MSG_DEBUG("commandId [%d]", commandId);
146
147         /* The TPDU Maximum Length at SAT side is 175
148            This is because Sat can send 160 bytes unpacked and header */
149         unsigned char tpdu[MAX_SAT_TPDU_LEN+1];
150         int tpduLen = 0;
151
152         memset(tpdu, 0x00, sizeof(tpdu));
153         memcpy(tpdu, pSmsData->smsTpdu.data, pSmsData->smsTpdu.dataLen);
154
155         /* Modify Parameters, Pack User Data */
156         tpduLen = handleSatTpdu(tpdu, pSmsData->smsTpdu.dataLen, pSmsData->bIsPackingRequired);
157
158         if (tpduLen <= 0) {
159                 sendResult(handle, SMS_SAT_CMD_SEND_SMS, TAPI_SAT_R_SUCCESS);
160                 return;
161         } else if (tpduLen > MAX_SAT_TPDU_LEN) {
162                 sendResult(handle, SMS_SAT_CMD_SEND_SMS, TAPI_SAT_R_BEYOND_ME_CAPABILITIES);
163                 return;
164         }
165
166         /* Make Telephony Structure */
167         TelSmsDatapackageInfo_t pkgInfo;
168
169         /* Set TPDU data */
170         memset((void*)pkgInfo.szData, 0x00, sizeof(pkgInfo.szData));
171         memcpy((void*)pkgInfo.szData, tpdu, tpduLen);
172
173         pkgInfo.szData[tpduLen] = '\0';
174         pkgInfo.MsgLength = tpduLen;
175         pkgInfo.format = TAPI_NETTEXT_NETTYPE_3GPP;
176
177         /* Set SMSC Address */
178         SMS_ADDRESS_S smsc = {0, };
179         int simIndex = SmsPluginDSHandler::instance()->getSimIndex(handle);
180
181         if (pSmsData->address.diallingNumberLen > 0) {
182                 smsc.ton = pSmsData->address.ton;
183                 smsc.npi = pSmsData->address.npi;
184                 snprintf(smsc.address, sizeof(smsc.address), "%s", pSmsData->address.diallingNumber);
185
186                 MSG_SEC_DEBUG("SCA TON[%d], NPI[%d], LEN[%d], ADDR[%s]", smsc.ton, smsc.npi, strlen(smsc.address), smsc.address);
187         } else {
188                 /* Set SMSC Options */
189                 SmsPluginTransport::instance()->setSmscOptions(simIndex, &smsc);
190         }
191
192         unsigned char smscAddr[MAX_SMSC_LEN];
193         int smscLen = 0;
194
195         memset(smscAddr, 0x00, sizeof(smscAddr));
196         smscLen = SmsPluginParamCodec::encodeSMSC(&smsc, smscAddr);
197
198         if (smscLen <= 0)
199                 return;
200
201         /* Set SMSC Address */
202         memset(pkgInfo.Sca, 0x00, sizeof(pkgInfo.Sca));
203         memcpy((void*)pkgInfo.Sca, smscAddr, smscLen);
204         pkgInfo.Sca[smscLen] = '\0';
205
206         int tapiRet = TAPI_API_SUCCESS;
207
208         /* Send SMS */
209         tapiRet = tel_send_sms(handle, &pkgInfo, 0, TapiEventSatSmsSentStatus, NULL);
210
211         if (tapiRet == TAPI_API_SUCCESS) {
212                 MSG_DEBUG("########  TelTapiSmsSend Success !!! return : %d #######", tapiRet);
213
214         } else {
215                 MSG_DEBUG("########  TelTapiSmsSend Fail !!! return : %d #######", tapiRet);
216                 sendResult(handle, SMS_SAT_CMD_SEND_SMS, TAPI_SAT_R_BEYOND_ME_CAPABILITIES);
217         }
218 }
219
220
221 void SmsPluginSatHandler::ctrlSms(TapiHandle *handle, void *pData)
222 {
223         if (!pData) {
224                 MSG_DEBUG("pData is NULL");
225                 return;
226         }
227
228         TelSatMoSmCtrlIndData_t* pCtrlData = (TelSatMoSmCtrlIndData_t*)pData;
229
230 #if 0
231         if (bSendSmsbySat == true) {
232                 /* Send SMS By SAT */
233                 MSG_DEBUG("Event Noti for sending message by SAT : result = [%d]", pCtrlData->moSmsCtrlResult);
234         } else {
235                 /* Send SMS By APP */
236                 SmsPluginTransport::instance()->setMoCtrlStatus(pCtrlData);
237         }
238 #else
239         if (pCtrlData->moSmsCtrlResult == TAPI_SAT_CALL_CTRL_R_NOT_ALLOWED) {
240                 MsgInsertTicker("Sending message failed : blocked by call control", NULL, true, 0);
241         }
242 #endif
243
244         return;
245
246 #if 0
247         if (bSendSms == true) { /* Send SMS By SAT */
248                 if (pCtrlData->moSmsCtrlResult == TAPI_SAT_CALL_CTRL_R_NOT_ALLOWED) {
249                         MSG_DEBUG("SIM does not allow to send SMS");
250
251                         sendResult(SMS_SAT_CMD_SEND_SMS, TAPI_SAT_R_INTRCTN_WITH_CC_OR_SMS_CTRL_PRMNT_PRBLM);
252                 } else if (pCtrlData->moSmsCtrlResult == TAPI_SAT_CALL_CTRL_R_ALLOWED_WITH_MOD) {
253                         MSG_DEBUG("SIM allows to send SMS with modification");
254
255                         sendResult(SMS_SAT_CMD_SEND_SMS, TAPI_SAT_R_SUCCESS);
256                 }
257         } else { /* Send SMS By APP */
258                 msg_network_status_t netStatus = MSG_NETWORK_NOT_SEND;
259
260                 if (pCtrlData->moSmsCtrlResult == TAPI_SAT_CALL_CTRL_R_NOT_ALLOWED) {
261                         MSG_DEBUG("SIM does not allow to send SMS");
262
263                         netStatus = MSG_NETWORK_SEND_FAIL;
264                 } else if (pCtrlData->moSmsCtrlResult == TAPI_SAT_CALL_CTRL_R_ALLOWED_WITH_MOD) {
265                         MSG_DEBUG("SIM allows to send SMS with modification");
266
267                         netStatus = MSG_NETWORK_SEND_SUCCESS;
268                 }
269
270                 /* Call Event Handler */
271                 SmsPluginEventHandler::instance()->handleSentStatus(netStatus);
272         }
273 #endif
274 }
275
276
277 void SmsPluginSatHandler::ctrlSms(TapiHandle *handle, SMS_NETWORK_STATUS_T smsStatus)
278 {
279         MSG_DEBUG("SMS network status = [%d]", smsStatus);
280
281         if (smsStatus == SMS_NETWORK_SEND_SUCCESS) {
282                 MSG_DEBUG("Sending SMS by SAT is OK");
283                 sendResult(handle, SMS_SAT_CMD_SEND_SMS, TAPI_SAT_R_SUCCESS);
284         } else if (smsStatus == SMS_NETWORK_SEND_FAIL) {
285                 MSG_ERR("Sending SMS by SAT is failed");
286                 sendResult(handle, SMS_SAT_CMD_SEND_SMS, TAPI_SAT_R_SMS_RP_ERROR);
287         } else if (smsStatus == SMS_NETWORK_SEND_FAIL_MANDATORY_INFO_MISSING) {
288                 MSG_ERR("Sending SMS by SAT is failed, but result is 'success'");
289                 /* sendResult(SMS_SAT_CMD_SEND_SMS, TAPI_SAT_R_ERROR_REQUIRED_VALUES_ARE_MISSING); */
290                 sendResult(handle, SMS_SAT_CMD_SEND_SMS, TAPI_SAT_R_SUCCESS);
291         } else if (smsStatus == SMS_NETWORK_SEND_FAIL_BY_MO_CONTROL_NOT_ALLOWED) {
292                 MSG_ERR("Sending SMS is failed by MO control");
293                 sendResult(handle, SMS_SAT_CMD_SEND_SMS, TAPI_SAT_R_INTRCTN_WITH_CC_OR_SMS_CTRL_PRMNT_PRBLM);
294         } else if (smsStatus == SMS_NETWORK_SEND_FAIL_NO_ROUTING) {
295                 MSG_ERR("Sending SMS is failed by no routing");
296                 sendResult(handle, SMS_SAT_CMD_SEND_SMS, TAPI_SAT_R_NETWORK_UNABLE_TO_PROCESS_COMMAND);
297         } else {
298                 /*Default case*/
299                 MSG_ERR("Sending SMS by SAT is failed");
300                 sendResult(handle, SMS_SAT_CMD_SEND_SMS, TAPI_SAT_R_SMS_RP_ERROR);
301         }
302
303 #if 0 /* no ticker and sound for sending SAT sms failure case. */
304         if (smsStatus != SMS_NETWORK_SEND_SUCCESS) {
305                 MsgInsertTicker("Sending SMS is failed", SMS_MESSAGE_SENDING_FAIL, true, 0);
306         }
307 #endif
308 }
309
310 #if 0
311 void SmsPluginSatHandler::finishSimMsgInit(msg_error_t Err)
312 {
313         /* SAT Handler is initializing SIM now */
314         if (bInitSim == true) {
315                 /* Init SMSC List and CB ID Info */
316                 try {
317                         if (bSMSPChanged == true) initSMSCList();
318                 } catch (MsgException& e) {
319                         /* Send Result to TAPI */
320                         sendResult(SMS_SAT_CMD_REFRESH, TAPI_SAT_R_ME_UNABLE_TO_PROCESS_COMMAND);
321
322                         MSG_FATAL("%s", e.what());
323                         return;
324                 }
325
326                 try {
327                         if (bCBMIChanged == true) initCBConfig();
328                 } catch (MsgException& e) {
329                         /* Send Result to TAPI */
330                         sendResult(SMS_SAT_CMD_REFRESH, TAPI_SAT_R_ME_UNABLE_TO_PROCESS_COMMAND);
331
332                         MSG_FATAL("%s", e.what());
333                         return;
334                 }
335
336                 /* Send Result to TAPI */
337                 sendResult(SMS_SAT_CMD_REFRESH, TAPI_SAT_R_SUCCESS);
338         }
339 }
340
341
342 void SmsPluginSatHandler::initSim()
343 {
344         bInitSim = true;
345
346         /* Init SIM Message */
347         if (SmsPluginEventHandler::instance()->callbackInitSimBySat() != MSG_SUCCESS) {
348                 MSG_DEBUG("Init Sim Error");
349
350                 /* Send Result to TAPI */
351                 sendResult(SMS_SAT_CMD_REFRESH, TAPI_SAT_R_ME_UNABLE_TO_PROCESS_COMMAND);
352         }
353 }
354
355
356 void    SmsPluginSatHandler::initSMSCList()
357 {
358         MSG_SETTING_S settingData;
359
360         settingData.type = MSG_SMSC_LIST;
361
362         /* Get Data From SIM */
363         SmsPluginSetting::instance()->getConfigData(&settingData);
364
365         MSG_DEBUG("total_count[%d]", settingData.option.smscList.totalCnt);
366         MSG_DEBUG("selected[%d]", settingData.option.smscList.selected);
367
368         for (int i = 0; i < settingData.option.smscList.totalCnt; i++) {
369                 MSG_DEBUG("pid[%d]", settingData.option.smscList.smscData[i].pid);
370                 MSG_DEBUG("val_period[%d]", settingData.option.smscList.smscData[i].valPeriod);
371                 MSG_SEC_DEBUG("name[%s]", settingData.option.smscList.smscData[i].name);
372
373                 MSG_DEBUG("ton[%d]", settingData.option.smscList.smscData[i].smscAddr.ton);
374                 MSG_DEBUG("npi[%d]", settingData.option.smscList.smscData[i].smscAddr.npi);
375                 MSG_SEC_DEBUG("address[%s]", settingData.option.smscList.smscData[i].smscAddr.address);
376         }
377
378         if (MsgSettingSetInt(SMSC_SELECTED, settingData.option.smscList.selected) != MSG_SUCCESS) {
379                 THROW(MsgException::SMS_PLG_ERROR, "Error to set config data [%s]", SMSC_SELECTED);
380                 return;
381         }
382
383         if (MsgSettingSetInt(SMSC_TOTAL_COUNT, settingData.option.smscList.totalCnt) != MSG_SUCCESS) {
384                 THROW(MsgException::SMS_PLG_ERROR, "Error to set config data [%s]", SMSC_TOTAL_COUNT);
385                 return;
386         }
387
388         char keyName[MAX_VCONFKEY_NAME_LEN];
389         msg_error_t err = MSG_SUCCESS;
390
391         for (int i = 0; i < settingData.option.smscList.totalCnt; i++) {
392                 memset(keyName, 0x00, sizeof(keyName));
393                 snprintf(keyName, sizeof(keyName), "%s/%d", SMSC_PID, i);
394
395                 if ((err = MsgSettingSetInt(keyName, (int)settingData.option.smscList.smscData[i].pid)) != MSG_SUCCESS)
396                         break;
397
398 #if 0
399                 memset(keyName, 0x00, sizeof(keyName));
400                 snprintf(keyName, sizeof(keyName), "%s/%d", SMSC_DCS, i);
401
402                 if ((err = MsgSettingSetInt(keyName, (int)settingData.option.smscList.smscData[i].dcs)) != MSG_SUCCESS)
403                         break;
404 #endif
405
406                 memset(keyName, 0x00, sizeof(keyName));
407                 snprintf(keyName, sizeof(keyName), "%s/%d", SMSC_VAL_PERIOD, i);
408
409                 if ((err = MsgSettingSetInt(keyName, (int)settingData.option.smscList.smscData[i].valPeriod)) != MSG_SUCCESS)
410                         break;
411
412                 memset(keyName, 0x00, sizeof(keyName));
413                 snprintf(keyName, sizeof(keyName), "%s/%d", SMSC_NAME, i);
414
415                 if ((err = MsgSettingSetString(keyName, settingData.option.smscList.smscData[i].name)) != MSG_SUCCESS)
416                         break;
417
418                 memset(keyName, 0x00, sizeof(keyName));
419                 snprintf(keyName, sizeof(keyName), "%s/%d", SMSC_TON, i);
420
421                 if ((err = MsgSettingSetInt(keyName, (int)settingData.option.smscList.smscData[i].smscAddr.ton)) != MSG_SUCCESS)
422                         break;
423
424                 memset(keyName, 0x00, sizeof(keyName));
425                 snprintf(keyName, sizeof(keyName), "%s/%d", SMSC_NPI, i);
426
427                 if ((err = MsgSettingSetInt(keyName, (int)settingData.option.smscList.smscData[i].smscAddr.npi)) != MSG_SUCCESS)
428                         break;
429
430                 memset(keyName, 0x00, sizeof(keyName));
431                 snprintf(keyName, sizeof(keyName), "%s/%d", SMSC_ADDRESS, i);
432
433                 if ((err = MsgSettingSetString(keyName, settingData.option.smscList.smscData[i].smscAddr.address)) != MSG_SUCCESS)
434                         break;
435         }
436
437         if (err != MSG_SUCCESS) {
438                 THROW(MsgException::SMS_PLG_ERROR, "Error to set config data [%s]", keyName);
439         }
440 }
441
442
443 void SmsPluginSatHandler::initCBConfig()
444 {
445         MSG_SETTING_S settingData;
446
447         msg_error_t err = MSG_SUCCESS;
448         MsgDbHandler *dbHandle = getDbHandle();
449
450         settingData.type = MSG_CBMSG_OPT;
451
452         /* Get Data From SIM */
453         SmsPluginSetting::instance()->getConfigData(&settingData);
454
455         if (MsgSettingSetBool(CB_RECEIVE, settingData.option.cbMsgOpt.bReceive) != MSG_SUCCESS) {
456                 THROW(MsgException::SMS_PLG_ERROR, "Error to set config data [%s]", CB_RECEIVE);
457                 return;
458         }
459
460         if (MsgSettingSetInt(CB_MAX_SIM_COUNT, settingData.option.cbMsgOpt.maxSimCnt) != MSG_SUCCESS) {
461                 THROW(MsgException::SMS_PLG_ERROR, "Error to set config data [%s]", CB_MAX_SIM_COUNT);
462                 return;
463         }
464
465         err = MsgStoAddCBChannelInfo(dbHandle, &(settingData.option.cbMsgOpt.channelData), settingData.option.cbMsgOpt.simIndex);
466         MSG_DEBUG("MsgStoAddCBChannelInfo : err=[%d]", err);
467
468         if (err != MSG_SUCCESS) {
469                 THROW(MsgException::SMS_PLG_ERROR, "Error to set config data");
470         }
471 }
472 #endif
473
474 int SmsPluginSatHandler::handleSatTpdu(unsigned char *pTpdu, unsigned char TpduLen, int bIsPackingRequired)
475 {
476         if (pTpdu == NULL)
477                 THROW(MsgException::SMS_PLG_ERROR, "SAT TPDU is NULL");
478
479         int pos = 0;
480
481         /* TP-MTI, TP-RD, TP-VPF,  TP-RP, TP-UDHI, TP-SRR */
482         /* TP-VPF */
483         SMS_VPF_T vpf = (SMS_VPF_T)(pTpdu[pos++] & 0x18) >> 3;
484
485         /* TP-MR */
486         unsigned char tmpRef = pTpdu[pos];
487
488         MSG_DEBUG("current Msg Ref : %d", tmpRef);
489
490         pTpdu[pos] = tmpRef + 1;
491
492         MSG_DEBUG("new Msg Ref : %d", pTpdu[pos]);
493
494         pos++;
495
496         /*pTpdu[pos++] = SmsPluginTransport::instance()->getMsgRef(); */
497
498
499         /* TP-DA */
500         SMS_ADDRESS_S destAddr = {0};
501         int addrLen = SmsPluginParamCodec::decodeAddress(&pTpdu[pos], &destAddr);
502
503         pos += addrLen;
504
505         /* TP-PID */
506         pos++;
507
508         /* TP-DCS */
509         SMS_DCS_S dcs = {0};
510
511         int dcsLen = SmsPluginParamCodec::decodeDCS(&pTpdu[pos], &dcs);
512
513         if (bIsPackingRequired == true) {
514                 dcs.codingScheme = SMS_CHARSET_7BIT;
515
516                 char* pDcs = NULL;
517                 unique_ptr<char*, void(*)(char**)> dcsBuf(&pDcs, unique_ptr_deleter);
518
519                 SmsPluginParamCodec::encodeDCS(&dcs, &pDcs);
520
521                 memcpy(&(pTpdu[pos]), pDcs, dcsLen);
522         }
523
524         pos++;
525
526         /* TP-VP */
527         if (vpf == SMS_VPF_RELATIVE)
528                 pos += MAX_REL_TIME_PARAM_LEN;
529         else if (vpf == SMS_VPF_ABSOLUTE)
530                 pos += MAX_ABS_TIME_PARAM_LEN;
531
532         /* TP-UDL */
533         int udl = pTpdu[pos];
534         int retLen = 0;
535
536         if (bIsPackingRequired == true) {
537                 SMS_USERDATA_S userData = {0};
538
539                 userData.headerCnt = 0;
540                 userData.length = udl;
541                 memcpy(userData.data, &pTpdu[pos+1], udl);
542                 userData.data[udl] = '\0';
543
544                 MSG_DEBUG("user data : [%s]", userData.data);
545
546                 /* check for user data whether it is 7-bit packed or not. */
547                 bool is7bitPacked = false;
548                 int bitValue = 0;
549                 for (int i = 0; i < userData.length; i++) {
550                         bitValue = userData.data[i] & (1 << 7);
551                         if (bitValue != 0) {
552                                 is7bitPacked = true;
553                                 MSG_DEBUG("user data is already 7-bit packed !!");
554                                 break;
555                         }
556                 }
557
558                 if (!is7bitPacked) {
559                         MSG_DEBUG("packing 8-bit user data to 7-bit charset !!");
560                         int encodeSize = SmsPluginUDCodec::encodeUserData(&userData, dcs.codingScheme, (char*)&pTpdu[pos]);
561                         retLen = pos + encodeSize;
562                 } else {
563                         retLen = TpduLen;
564                 }
565         } else {
566                 retLen = TpduLen;
567         }
568
569         return retLen;
570 }
571
572
573 void SmsPluginSatHandler::sendResult(TapiHandle *handle, SMS_SAT_CMD_TYPE_T CmdType, int ResultType)
574 {
575         TelSatAppsRetInfo_t satRetInfo;
576         memset(&satRetInfo, 0, sizeof(TelSatAppsRetInfo_t));
577
578         satRetInfo.commandId = commandId;
579
580         MSG_INFO("satRetInfo.commandId [%d]", satRetInfo.commandId);
581
582         if (CmdType == SMS_SAT_CMD_REFRESH) {
583                 satRetInfo.commandType = TAPI_SAT_CMD_TYPE_REFRESH;
584
585                 satRetInfo.appsRet.refresh.appType = TAPI_SAT_REFRESH_MSG;
586                 satRetInfo.appsRet.refresh.resp = (TelSatResultType_t)ResultType;
587         } else if (CmdType == SMS_SAT_CMD_SEND_SMS) {
588                 satRetInfo.commandType = TAPI_SAT_CMD_TYPE_SEND_SMS;
589
590                 satRetInfo.appsRet.sendSms.resp = (TelSatResultType_t)ResultType;
591         }
592
593         int tapiRet = TAPI_API_SUCCESS;
594
595         tapiRet = tel_send_sat_app_exec_result(handle, &satRetInfo);
596
597         if (tapiRet == TAPI_API_SUCCESS)
598                 MSG_DEBUG("TelTapiSatSendAppExecutionResult() SUCCESS");
599         else
600                 MSG_ERR("TelTapiSatSendAppExecutionResult() FAIL [%d]", tapiRet);
601
602         bInitSim = false;
603         bSMSPChanged = false;
604         bCBMIChanged = false;
605 }