2 * Copyright 2012 Samsung Electronics Co., Ltd
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
8 * http://www.tizenopensource.org/license
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.
20 #include "MsgException.h"
21 #include "MsgGconfWrapper.h"
24 #include "SmsPluginTransport.h"
25 #include "SmsPluginSimMsg.h"
26 #include "SmsPluginStorage.h"
27 #include "SmsPluginSetting.h"
28 #include "SmsPluginCallback.h"
29 #include "SmsPluginEventHandler.h"
30 #include "SmsPluginUAManager.h"
31 #include "SmsPluginMain.h"
35 #include <tapi_common.h>
37 #include <TapiUtility.h>
39 #include <ITapiNetText.h>
42 struct tapi_handle *pTapiHandle = NULL;
47 /*==================================================================================================
48 FUNCTION IMPLEMENTATION
49 ==================================================================================================*/
50 static void MsgTapiInitCB(keynode_t *key, void* data)
52 MSG_DEBUG("MsgTapiInitCB is called.");
58 msg_error_t MsgPlgCreateHandle(MSG_PLUGIN_HANDLER_S *pPluginHandle)
60 if (pPluginHandle == NULL)
62 MSG_DEBUG("SMS plugin: create handler error ");
63 return MSG_ERR_NULL_POINTER;
67 pPluginHandle->pfInitialize = SmsPlgInitialize;
68 pPluginHandle->pfFinalize = SmsPlgFinalize;
69 pPluginHandle->pfRegisterListener = SmsPlgRegisterListener;
70 pPluginHandle->pfCheckSimStatus = SmsPlgCheckSimStatus;
71 pPluginHandle->pfCheckDeviceStatus = SmsPlgCheckDeviceStatus;
72 pPluginHandle->pfSubmitRequest = SmsPlgSubmitRequest;
73 pPluginHandle->pfInitSimMessage = SmsPlgInitSimMessage;
74 pPluginHandle->pfSaveSimMessage = SmsPlgSaveSimMessage;
75 pPluginHandle->pfDeleteSimMessage = SmsPlgDeleteSimMessage;
76 pPluginHandle->pfSetReadStatus = SmsPlgSetReadStatus;
77 pPluginHandle->pfSetMemoryStatus = SmsPlgSetMemoryStatus;
78 pPluginHandle->pfInitConfigData = SmsPlgInitConfigData;
79 pPluginHandle->pfSetConfigData = SmsPlgSetConfigData;
80 pPluginHandle->pfGetConfigData = SmsPlgGetConfigData;
82 pPluginHandle->pfRestoreMsg = NULL;
84 MSG_DEBUG("SMS plugin: create handler OK");
85 MSG_DEBUG ("SMS plugin %p", pPluginHandle);
92 msg_error_t MsgPlgDestroyHandle(MSG_PLUGIN_HANDLER_S *pPluginHandle)
94 if (pPluginHandle != NULL)
100 MSG_DEBUG("SMS plugin: destory handler OK");
106 msg_error_t SmsPlgInitialize()
110 MSG_DEBUG("set MSG_SIM_CHANGED to MSG_SIM_STATUS_NOT_FOUND.");
111 if (MsgSettingSetInt(MSG_SIM_CHANGED, MSG_SIM_STATUS_NOT_FOUND) != MSG_SUCCESS)
112 MSG_DEBUG("MsgSettingSetInt is failed!!");
115 MsgSettingGetBool(VCONFKEY_TELEPHONY_READY, &bReady);
116 MSG_DEBUG("Get VCONFKEY_TELEPHONY_READY [%d].", bReady);
121 MsgSettingRegVconfCBCommon(VCONFKEY_TELEPHONY_READY, MsgTapiInitCB);
123 ret = cv.timedwait(mx.pMutex(), 90);
129 if (ret != ETIMEDOUT) {
130 pTapiHandle = tel_init(NULL);
131 SmsPluginCallback::instance()->registerEvent();
134 catch (MsgException& e)
136 MSG_FATAL("%s", e.what());
137 return MSG_ERR_PLUGIN_REGEVENT;
141 MSG_FATAL("%s", e.what());
142 return MSG_ERR_PLUGIN_REGEVENT;
151 msg_error_t SmsPlgFinalize()
156 return MSG_ERR_PLUGIN_TAPIINIT;
158 SmsPluginCallback::instance()->deRegisterEvent();
160 tel_deinit(pTapiHandle);
168 msg_error_t SmsPlgRegisterListener(MSG_PLUGIN_LISTENER_S *pListener)
172 SmsPluginEventHandler::instance()->registerListener(pListener);
180 msg_error_t SmsPlgCheckSimStatus(MSG_SIM_STATUS_T *pStatus)
185 return MSG_ERR_PLUGIN_TAPIINIT;
187 int tryNum = 0, tapiRet = TAPI_API_SUCCESS;
189 TelSimCardStatus_t status = TAPI_SIM_STATUS_CARD_ERROR;
192 // initialize pStatus.
193 *pStatus = MSG_SIM_STATUS_NOT_FOUND;
198 if (tryNum > 30) return MSG_ERR_PLUGIN_TAPIINIT;
200 tapiRet = tel_get_sim_init_info(pTapiHandle, &status, &cardChanged);
202 if (tapiRet == TAPI_API_SUCCESS) {
203 if (status == TAPI_SIM_STATUS_SIM_PIN_REQUIRED || status == TAPI_SIM_STATUS_SIM_PUK_REQUIRED) {
204 MSG_DEBUG("PIN or PUK is required [%d]", status);
211 if (status == TAPI_SIM_STATUS_SIM_INIT_COMPLETED) {
212 MSG_DEBUG("SIM status is OK [%d]", status);
214 MSG_DEBUG("SIM Changed [%d]", cardChanged);
216 if (cardChanged == 1)
217 *pStatus = MSG_SIM_STATUS_CHANGED;
219 *pStatus = MSG_SIM_STATUS_NORMAL;
222 } else if (status == TAPI_SIM_STATUS_CARD_NOT_PRESENT) {
223 MSG_DEBUG("SIM is not present [%d]", status);
226 MSG_DEBUG("SIM status is not OK [%d]", status);
231 } else if (tapiRet == TAPI_API_SIM_NOT_FOUND) {
232 MSG_DEBUG("tel_get_sim_init_info() result is TAPI_API_SIM_NOT_FOUND");
235 MSG_DEBUG("tel_get_sim_init_info() result is unknown!!!!!!!!!! [%d]", tapiRet);
244 memset(imsi, 0x00, sizeof(imsi));
247 if (*pStatus != MSG_SIM_STATUS_NOT_FOUND)
250 TelSimImsiInfo_t imsiInfo;
251 memset(&imsiInfo, 0x00, sizeof(TelSimImsiInfo_t));
253 tapiRet = tel_get_sim_imsi(pTapiHandle, &imsiInfo);
255 if (tapiRet == TAPI_API_SUCCESS)
257 MSG_DEBUG("tel_get_sim_imsi() Success - MCC [%s], MNC [%s]", imsiInfo.szMcc, imsiInfo.szMnc);
259 sprintf(imsi, "%03d%03d", atoi(imsiInfo.szMcc), atoi(imsiInfo.szMnc));
261 MSG_DEBUG("IMSI [%d]", atoi(imsi));
265 MSG_DEBUG("tel_get_sim_imsi() Error![%d]", tapiRet);
267 MsgSettingSetBool(MSG_NATIONAL_SIM, false);
272 MsgSettingSetBool(MSG_NATIONAL_SIM, false);
275 MsgSettingSetString(MSG_SIM_IMSI, imsi);
283 msg_error_t SmsPlgCheckDeviceStatus()
288 return MSG_ERR_PLUGIN_TAPIINIT;
290 int status = 0, tapiRet = TAPI_API_SUCCESS;
292 tapiRet = tel_check_sms_device_status(pTapiHandle, &status);
294 if (tapiRet != TAPI_API_SUCCESS) {
295 MSG_DEBUG("tel_check_sms_device_status() Error! [%d], Status [%d]", tapiRet, status);
296 return MSG_ERR_PLUGIN_TAPI_FAILED;
300 MSG_DEBUG("Device Is Ready");
302 } else if (status == 0) {
303 MSG_DEBUG("Device Is Not Ready.. Waiting For Ready Callback");
305 if (SmsPluginEventHandler::instance()->getDeviceStatus() == true) {
306 MSG_DEBUG("Device Is Ready");
309 MSG_DEBUG("Device Is Not Ready.");
310 return MSG_ERR_PLUGIN_TAPI_FAILED;
318 msg_error_t SmsPlgSubmitRequest(MSG_REQUEST_INFO_S *pReqInfo)
320 msg_error_t err = MSG_SUCCESS;
322 // Add Submit SMS into DB
323 if (pReqInfo->msgInfo.msgId == 0) {
324 if (pReqInfo->msgInfo.msgPort.valid == false) {
325 err = SmsPluginStorage::instance()->addMessage(&(pReqInfo->msgInfo));
326 if (err != MSG_SUCCESS) {
327 MSG_DEBUG("######## addMessage Fail !!");
328 return MSG_ERR_PLUGIN_STORAGE;
333 // Check SIM is present or not
334 MSG_SIM_STATUS_T simStatus = (MSG_SIM_STATUS_T)MsgSettingGetInt(MSG_SIM_CHANGED);
336 if (simStatus == MSG_SIM_STATUS_NOT_FOUND)
338 MSG_DEBUG("SIM is not present..");
341 if (pReqInfo->msgInfo.msgPort.valid == false)
342 SmsPluginStorage::instance()->updateSentMsg(&(pReqInfo->msgInfo), MSG_NETWORK_SEND_FAIL);
344 return MSG_ERR_NO_SIM;
347 SMS_REQUEST_INFO_S *request = NULL;
349 request = (SMS_REQUEST_INFO_S *)calloc(1, sizeof(SMS_REQUEST_INFO_S));
351 if (request != NULL) {
352 request->reqId = pReqInfo->reqId;
354 memcpy(&(request->msgInfo), &(pReqInfo->msgInfo), sizeof(MSG_MESSAGE_INFO_S));
355 memcpy(&(request->sendOptInfo), &(pReqInfo->sendOptInfo), sizeof(MSG_SENDINGOPT_INFO_S));
357 /* Add Request into Queue and Start UA Manger */
358 SmsPluginUAManager::instance()->addReqEntity(request);
368 msg_error_t SmsPlgInitSimMessage()
370 // Check SIM is present or not
371 MSG_SIM_STATUS_T simStatus = (MSG_SIM_STATUS_T)MsgSettingGetInt(MSG_SIM_CHANGED);
373 if (simStatus == MSG_SIM_STATUS_NOT_FOUND) {
374 MSG_DEBUG("SIM is not present..");
375 return MSG_ERR_NO_SIM;
380 SmsPluginSimMsg::instance()->initSimMessage();
382 catch (MsgException& e)
384 MSG_FATAL("%s", e.what());
385 return MSG_ERR_PLUGIN_STORAGE;
389 MSG_FATAL("%s", e.what());
390 return MSG_ERR_PLUGIN_STORAGE;
397 msg_error_t SmsPlgSaveSimMessage(const MSG_MESSAGE_INFO_S *pMsgInfo, SMS_SIM_ID_LIST_S *pSimIdList)
399 // Check SIM is present or not
400 MSG_SIM_STATUS_T simStatus = (MSG_SIM_STATUS_T)MsgSettingGetInt(MSG_SIM_CHANGED);
402 if (simStatus == MSG_SIM_STATUS_NOT_FOUND) {
403 MSG_DEBUG("SIM is not present..");
404 return MSG_ERR_NO_SIM;
407 msg_error_t err = MSG_SUCCESS;
409 err = SmsPluginSimMsg::instance()->saveSimMessage(pMsgInfo, pSimIdList);
415 msg_error_t SmsPlgDeleteSimMessage(msg_sim_id_t SimMsgId)
417 // Check SIM is present or not
418 MSG_SIM_STATUS_T simStatus = (MSG_SIM_STATUS_T)MsgSettingGetInt(MSG_SIM_CHANGED);
420 if (simStatus == MSG_SIM_STATUS_NOT_FOUND) {
421 MSG_DEBUG("SIM is not present..");
422 return MSG_ERR_NO_SIM;
427 SmsPluginSimMsg::instance()->deleteSimMessage(SimMsgId);
429 catch (MsgException& e)
431 MSG_FATAL("%s", e.what());
432 return MSG_ERR_PLUGIN_STORAGE;
436 MSG_FATAL("%s", e.what());
437 return MSG_ERR_PLUGIN_STORAGE;
444 msg_error_t SmsPlgSetReadStatus(msg_sim_id_t SimMsgId)
446 // Check SIM is present or not
447 MSG_SIM_STATUS_T simStatus = (MSG_SIM_STATUS_T)MsgSettingGetInt(MSG_SIM_CHANGED);
449 if (simStatus == MSG_SIM_STATUS_NOT_FOUND) {
450 MSG_DEBUG("SIM is not present..");
451 return MSG_ERR_NO_SIM;
456 SmsPluginSimMsg::instance()->setReadStatus(SimMsgId);
458 catch (MsgException& e)
460 MSG_FATAL("%s", e.what());
461 return MSG_ERR_PLUGIN_STORAGE;
465 MSG_FATAL("%s", e.what());
466 return MSG_ERR_PLUGIN_STORAGE;
473 msg_error_t SmsPlgSetMemoryStatus(msg_error_t Error)
475 // Check SIM is present or not
476 MSG_SIM_STATUS_T simStatus = (MSG_SIM_STATUS_T)MsgSettingGetInt(MSG_SIM_CHANGED);
478 if (simStatus == MSG_SIM_STATUS_NOT_FOUND) {
479 MSG_DEBUG("SIM is not present..");
480 return MSG_ERR_NO_SIM;
483 int tapiRet = TAPI_API_SUCCESS;
484 int status = TAPI_NETTEXT_PDA_MEMORY_STATUS_AVAILABLE;
486 if (Error == MSG_ERR_SIM_STORAGE_FULL || Error == MSG_ERR_MESSAGE_COUNT_FULL)
488 status = TAPI_NETTEXT_PDA_MEMORY_STATUS_FULL;
491 MSG_DEBUG("Set Status : [%d]", status);
493 tapiRet = tel_set_sms_memory_status(pTapiHandle, status, TapiEventMemoryStatus, NULL);
495 if (tapiRet == TAPI_API_SUCCESS)
497 MSG_DEBUG("######## tel_set_sms_memory_status() Success !!! #######");
501 MSG_DEBUG("######## tel_set_sms_memory_status() Success !!! return : [%d] #######", tapiRet);
508 msg_error_t SmsPlgInitConfigData(MSG_SIM_STATUS_T SimStatus)
510 // Check SIM is present or not
511 MSG_SIM_STATUS_T simStatus = (MSG_SIM_STATUS_T)MsgSettingGetInt(MSG_SIM_CHANGED);
513 if (simStatus == MSG_SIM_STATUS_NOT_FOUND) {
514 MSG_DEBUG("SIM is not present..");
515 return MSG_ERR_NO_SIM;
520 SmsPluginSetting::instance()->initConfigData(SimStatus);
522 catch (MsgException& e)
524 MSG_FATAL("%s", e.what());
525 return MSG_ERR_PLUGIN_SETTING;
529 MSG_FATAL("%s", e.what());
530 return MSG_ERR_PLUGIN_SETTING;
537 msg_error_t SmsPlgSetConfigData(const MSG_SETTING_S *pSetting)
539 // Check SIM is present or not
540 MSG_SIM_STATUS_T simStatus = (MSG_SIM_STATUS_T)MsgSettingGetInt(MSG_SIM_CHANGED);
542 if (simStatus == MSG_SIM_STATUS_NOT_FOUND) {
543 MSG_DEBUG("SIM is not present..");
544 return MSG_ERR_NO_SIM;
549 SmsPluginSetting::instance()->setConfigData(pSetting);
551 catch (MsgException& e)
553 MSG_FATAL("%s", e.what());
554 return MSG_ERR_PLUGIN_SETTING;
558 MSG_FATAL("%s", e.what());
559 return MSG_ERR_PLUGIN_SETTING;
566 msg_error_t SmsPlgGetConfigData(MSG_SETTING_S *pSetting)
568 // Check SIM is present or not
569 MSG_SIM_STATUS_T simStatus = (MSG_SIM_STATUS_T)MsgSettingGetInt(MSG_SIM_CHANGED);
571 if (simStatus == MSG_SIM_STATUS_NOT_FOUND) {
572 MSG_DEBUG("SIM is not present..");
573 return MSG_ERR_NO_SIM;
578 SmsPluginSetting::instance()->getConfigData(pSetting);
580 catch (MsgException& e)
582 MSG_FATAL("%s", e.what());
583 return MSG_ERR_PLUGIN_SETTING;
587 MSG_FATAL("%s", e.what());
588 return MSG_ERR_PLUGIN_SETTING;