2 * Copyright 2012-2013 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://floralicense.org
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.");
55 bTelRdy = vconf_keynode_get_bool(key);
57 MSG_DEBUG("bTelRdy [%d]", bTelRdy);
66 msg_error_t MsgPlgCreateHandle(MSG_PLUGIN_HANDLER_S *pPluginHandle)
68 if (pPluginHandle == NULL)
70 MSG_DEBUG("SMS plugin: create handler error ");
71 return MSG_ERR_NULL_POINTER;
75 pPluginHandle->pfInitialize = SmsPlgInitialize;
76 pPluginHandle->pfFinalize = SmsPlgFinalize;
77 pPluginHandle->pfRegisterListener = SmsPlgRegisterListener;
78 pPluginHandle->pfCheckSimStatus = SmsPlgCheckSimStatus;
79 pPluginHandle->pfCheckDeviceStatus = SmsPlgCheckDeviceStatus;
80 pPluginHandle->pfSubmitRequest = SmsPlgSubmitRequest;
81 pPluginHandle->pfInitSimMessage = SmsPlgInitSimMessage;
82 pPluginHandle->pfSaveSimMessage = SmsPlgSaveSimMessage;
83 pPluginHandle->pfDeleteSimMessage = SmsPlgDeleteSimMessage;
84 pPluginHandle->pfSetReadStatus = SmsPlgSetReadStatus;
85 pPluginHandle->pfSetMemoryStatus = SmsPlgSetMemoryStatus;
86 pPluginHandle->pfInitConfigData = SmsPlgInitConfigData;
87 pPluginHandle->pfSetConfigData = SmsPlgSetConfigData;
88 pPluginHandle->pfGetConfigData = SmsPlgGetConfigData;
90 pPluginHandle->pfRestoreMsg = NULL;
92 MSG_DEBUG("SMS plugin: create handler OK");
93 MSG_DEBUG ("SMS plugin %p", pPluginHandle);
100 msg_error_t MsgPlgDestroyHandle(MSG_PLUGIN_HANDLER_S *pPluginHandle)
102 if (pPluginHandle != NULL)
105 pPluginHandle = NULL;
108 MSG_DEBUG("SMS plugin: destory handler OK");
114 msg_error_t SmsPlgInitialize()
118 MSG_DEBUG("set MSG_SIM_CHANGED to MSG_SIM_STATUS_NOT_FOUND.");
119 if (MsgSettingSetInt(MSG_SIM_CHANGED, MSG_SIM_STATUS_NOT_FOUND) != MSG_SUCCESS)
120 MSG_DEBUG("MsgSettingSetInt is failed!!");
123 MsgSettingGetBool(VCONFKEY_TELEPHONY_READY, &bReady);
124 MSG_DEBUG("Get VCONFKEY_TELEPHONY_READY [%d].", bReady);
129 MsgSettingRegVconfCBCommon(VCONFKEY_TELEPHONY_READY, MsgTapiInitCB);
131 ret = cv.timedwait(mx.pMutex(), 90);
137 if (ret != ETIMEDOUT) {
138 pTapiHandle = tel_init(NULL);
139 SmsPluginCallback::instance()->registerEvent();
141 MSG_DEBUG("MsgTapiInitCB is time out.");
144 catch (MsgException& e)
146 MSG_FATAL("%s", e.what());
147 return MSG_ERR_PLUGIN_REGEVENT;
151 MSG_FATAL("%s", e.what());
152 return MSG_ERR_PLUGIN_REGEVENT;
161 msg_error_t SmsPlgFinalize()
166 return MSG_ERR_PLUGIN_TAPIINIT;
168 SmsPluginCallback::instance()->deRegisterEvent();
170 tel_deinit(pTapiHandle);
178 msg_error_t SmsPlgRegisterListener(MSG_PLUGIN_LISTENER_S *pListener)
182 SmsPluginEventHandler::instance()->registerListener(pListener);
190 msg_error_t SmsPlgCheckSimStatus(MSG_SIM_STATUS_T *pStatus)
195 return MSG_ERR_PLUGIN_TAPIINIT;
197 int tryNum = 0, tapiRet = TAPI_API_SUCCESS;
199 TelSimCardStatus_t status = TAPI_SIM_STATUS_CARD_ERROR;
202 // initialize pStatus.
203 *pStatus = MSG_SIM_STATUS_NOT_FOUND;
208 if (tryNum > 30) return MSG_ERR_PLUGIN_TAPIINIT;
210 tapiRet = tel_get_sim_init_info(pTapiHandle, &status, &cardChanged);
212 if (tapiRet == TAPI_API_SUCCESS) {
213 if (status == TAPI_SIM_STATUS_SIM_PIN_REQUIRED || status == TAPI_SIM_STATUS_SIM_PUK_REQUIRED) {
214 MSG_DEBUG("PIN or PUK is required [%d]", status);
221 if (status == TAPI_SIM_STATUS_SIM_INIT_COMPLETED) {
222 MSG_DEBUG("SIM status is OK [%d]", status);
224 MSG_DEBUG("SIM Changed [%d]", cardChanged);
226 if (cardChanged == 1)
227 *pStatus = MSG_SIM_STATUS_CHANGED;
229 *pStatus = MSG_SIM_STATUS_NORMAL;
232 } else if (status == TAPI_SIM_STATUS_CARD_NOT_PRESENT) {
233 MSG_DEBUG("SIM is not present [%d]", status);
236 MSG_DEBUG("SIM status is not OK [%d]", status);
241 } else if (tapiRet == TAPI_API_SIM_NOT_FOUND) {
242 MSG_DEBUG("tel_get_sim_init_info() result is TAPI_API_SIM_NOT_FOUND");
245 MSG_DEBUG("tel_get_sim_init_info() result is unknown!!!!!!!!!! [%d]", tapiRet);
254 memset(imsi, 0x00, sizeof(imsi));
257 if (*pStatus != MSG_SIM_STATUS_NOT_FOUND)
260 TelSimImsiInfo_t imsiInfo;
261 memset(&imsiInfo, 0x00, sizeof(TelSimImsiInfo_t));
263 tapiRet = tel_get_sim_imsi(pTapiHandle, &imsiInfo);
265 if (tapiRet == TAPI_API_SUCCESS)
267 MSG_DEBUG("tel_get_sim_imsi() Success - MCC [%s], MNC [%s]", imsiInfo.szMcc, imsiInfo.szMnc);
269 sprintf(imsi, "%03d%03d", atoi(imsiInfo.szMcc), atoi(imsiInfo.szMnc));
271 MSG_DEBUG("IMSI [%d]", atoi(imsi));
275 MSG_DEBUG("tel_get_sim_imsi() Error![%d]", tapiRet);
277 MsgSettingSetBool(MSG_NATIONAL_SIM, false);
282 MsgSettingSetBool(MSG_NATIONAL_SIM, false);
285 MsgSettingSetString(MSG_SIM_IMSI, imsi);
293 msg_error_t SmsPlgCheckDeviceStatus()
298 return MSG_ERR_PLUGIN_TAPIINIT;
300 int status = 0, tapiRet = TAPI_API_SUCCESS;
302 tapiRet = tel_check_sms_device_status(pTapiHandle, &status);
304 if (tapiRet != TAPI_API_SUCCESS) {
305 MSG_DEBUG("tel_check_sms_device_status() Error! [%d], Status [%d]", tapiRet, status);
306 return MSG_ERR_PLUGIN_TAPI_FAILED;
310 MSG_DEBUG("Device Is Ready");
312 } else if (status == 0) {
313 MSG_DEBUG("Device Is Not Ready.. Waiting For Ready Callback");
315 if (SmsPluginEventHandler::instance()->getDeviceStatus() == true) {
316 MSG_DEBUG("Device Is Ready");
319 MSG_DEBUG("Device Is Not Ready.");
320 return MSG_ERR_PLUGIN_TAPI_FAILED;
328 msg_error_t SmsPlgSubmitRequest(MSG_REQUEST_INFO_S *pReqInfo)
330 msg_error_t err = MSG_SUCCESS;
332 // Add Submit SMS into DB
333 if (pReqInfo->msgInfo.msgId == 0) {
334 if (pReqInfo->msgInfo.msgPort.valid == false) {
335 err = SmsPluginStorage::instance()->addMessage(&(pReqInfo->msgInfo));
336 if (err != MSG_SUCCESS) {
337 MSG_DEBUG("######## addMessage Fail !!");
338 return MSG_ERR_PLUGIN_STORAGE;
340 if (SmsPluginStorage::instance()->addSmsSendOption(&(pReqInfo->msgInfo), &(pReqInfo->sendOptInfo)) != MSG_SUCCESS) {
341 MSG_DEBUG("######## addSmsSendOption Fail !!");
342 return MSG_ERR_PLUGIN_STORAGE;
347 // Check SIM is present or not
348 MSG_SIM_STATUS_T simStatus = (MSG_SIM_STATUS_T)MsgSettingGetInt(MSG_SIM_CHANGED);
350 if (simStatus == MSG_SIM_STATUS_NOT_FOUND)
352 MSG_DEBUG("SIM is not present..");
355 if (pReqInfo->msgInfo.msgPort.valid == false)
356 SmsPluginStorage::instance()->updateSentMsg(&(pReqInfo->msgInfo), MSG_NETWORK_SEND_FAIL);
358 return MSG_ERR_NO_SIM;
361 SMS_REQUEST_INFO_S *request = NULL;
363 request = (SMS_REQUEST_INFO_S *)calloc(1, sizeof(SMS_REQUEST_INFO_S));
365 if (request != NULL) {
366 request->reqId = pReqInfo->reqId;
368 memcpy(&(request->msgInfo), &(pReqInfo->msgInfo), sizeof(MSG_MESSAGE_INFO_S));
369 memcpy(&(request->sendOptInfo), &(pReqInfo->sendOptInfo), sizeof(MSG_SENDINGOPT_INFO_S));
371 /* Add Request into Queue and Start UA Manger */
372 SmsPluginUAManager::instance()->addReqEntity(request);
382 msg_error_t SmsPlgInitSimMessage()
384 // Check SIM is present or not
385 MSG_SIM_STATUS_T simStatus = (MSG_SIM_STATUS_T)MsgSettingGetInt(MSG_SIM_CHANGED);
387 if (simStatus == MSG_SIM_STATUS_NOT_FOUND) {
388 MSG_DEBUG("SIM is not present..");
389 return MSG_ERR_NO_SIM;
394 SmsPluginSimMsg::instance()->initSimMessage();
396 catch (MsgException& e)
398 MSG_FATAL("%s", e.what());
399 return MSG_ERR_PLUGIN_STORAGE;
403 MSG_FATAL("%s", e.what());
404 return MSG_ERR_PLUGIN_STORAGE;
411 msg_error_t SmsPlgSaveSimMessage(const MSG_MESSAGE_INFO_S *pMsgInfo, SMS_SIM_ID_LIST_S *pSimIdList)
413 // Check SIM is present or not
414 MSG_SIM_STATUS_T simStatus = (MSG_SIM_STATUS_T)MsgSettingGetInt(MSG_SIM_CHANGED);
416 if (simStatus == MSG_SIM_STATUS_NOT_FOUND) {
417 MSG_DEBUG("SIM is not present..");
418 return MSG_ERR_NO_SIM;
421 msg_error_t err = MSG_SUCCESS;
423 err = SmsPluginSimMsg::instance()->saveSimMessage(pMsgInfo, pSimIdList);
429 msg_error_t SmsPlgDeleteSimMessage(msg_sim_id_t SimMsgId)
431 // Check SIM is present or not
432 MSG_SIM_STATUS_T simStatus = (MSG_SIM_STATUS_T)MsgSettingGetInt(MSG_SIM_CHANGED);
434 if (simStatus == MSG_SIM_STATUS_NOT_FOUND) {
435 MSG_DEBUG("SIM is not present..");
436 return MSG_ERR_NO_SIM;
441 SmsPluginSimMsg::instance()->deleteSimMessage(SimMsgId);
443 catch (MsgException& e)
445 MSG_FATAL("%s", e.what());
446 return MSG_ERR_PLUGIN_STORAGE;
450 MSG_FATAL("%s", e.what());
451 return MSG_ERR_PLUGIN_STORAGE;
458 msg_error_t SmsPlgSetReadStatus(msg_sim_id_t SimMsgId)
460 // Check SIM is present or not
461 MSG_SIM_STATUS_T simStatus = (MSG_SIM_STATUS_T)MsgSettingGetInt(MSG_SIM_CHANGED);
463 if (simStatus == MSG_SIM_STATUS_NOT_FOUND) {
464 MSG_DEBUG("SIM is not present..");
465 return MSG_ERR_NO_SIM;
470 SmsPluginSimMsg::instance()->setReadStatus(SimMsgId);
472 catch (MsgException& e)
474 MSG_FATAL("%s", e.what());
475 return MSG_ERR_PLUGIN_STORAGE;
479 MSG_FATAL("%s", e.what());
480 return MSG_ERR_PLUGIN_STORAGE;
487 msg_error_t SmsPlgSetMemoryStatus(msg_error_t Error)
489 // Check SIM is present or not
490 MSG_SIM_STATUS_T simStatus = (MSG_SIM_STATUS_T)MsgSettingGetInt(MSG_SIM_CHANGED);
492 if (simStatus == MSG_SIM_STATUS_NOT_FOUND) {
493 MSG_DEBUG("SIM is not present..");
494 return MSG_ERR_NO_SIM;
497 int tapiRet = TAPI_API_SUCCESS;
498 int status = TAPI_NETTEXT_PDA_MEMORY_STATUS_AVAILABLE;
500 if (Error == MSG_ERR_SIM_STORAGE_FULL || Error == MSG_ERR_MESSAGE_COUNT_FULL)
502 status = TAPI_NETTEXT_PDA_MEMORY_STATUS_FULL;
505 MSG_DEBUG("Set Status : [%d]", status);
507 tapiRet = tel_set_sms_memory_status(pTapiHandle, status, TapiEventMemoryStatus, NULL);
509 if (tapiRet == TAPI_API_SUCCESS)
511 MSG_DEBUG("######## tel_set_sms_memory_status() Success !!! #######");
515 MSG_DEBUG("######## tel_set_sms_memory_status() Success !!! return : [%d] #######", tapiRet);
522 msg_error_t SmsPlgInitConfigData(MSG_SIM_STATUS_T SimStatus)
524 // Check SIM is present or not
525 MSG_SIM_STATUS_T simStatus = (MSG_SIM_STATUS_T)MsgSettingGetInt(MSG_SIM_CHANGED);
527 if (simStatus == MSG_SIM_STATUS_NOT_FOUND) {
528 MSG_DEBUG("SIM is not present..");
529 return MSG_ERR_NO_SIM;
534 SmsPluginSetting::instance()->initConfigData(SimStatus);
536 catch (MsgException& e)
538 MSG_FATAL("%s", e.what());
539 return MSG_ERR_PLUGIN_SETTING;
543 MSG_FATAL("%s", e.what());
544 return MSG_ERR_PLUGIN_SETTING;
551 msg_error_t SmsPlgSetConfigData(const MSG_SETTING_S *pSetting)
553 // Check SIM is present or not
554 MSG_SIM_STATUS_T simStatus = (MSG_SIM_STATUS_T)MsgSettingGetInt(MSG_SIM_CHANGED);
556 if (simStatus == MSG_SIM_STATUS_NOT_FOUND) {
557 MSG_DEBUG("SIM is not present..");
558 return MSG_ERR_NO_SIM;
563 SmsPluginSetting::instance()->setConfigData(pSetting);
565 catch (MsgException& e)
567 MSG_FATAL("%s", e.what());
568 return MSG_ERR_PLUGIN_SETTING;
572 MSG_FATAL("%s", e.what());
573 return MSG_ERR_PLUGIN_SETTING;
580 msg_error_t SmsPlgGetConfigData(MSG_SETTING_S *pSetting)
582 // Check SIM is present or not
583 MSG_SIM_STATUS_T simStatus = (MSG_SIM_STATUS_T)MsgSettingGetInt(MSG_SIM_CHANGED);
585 if (simStatus == MSG_SIM_STATUS_NOT_FOUND) {
586 MSG_DEBUG("SIM is not present..");
587 return MSG_ERR_NO_SIM;
592 SmsPluginSetting::instance()->getConfigData(pSetting);
594 catch (MsgException& e)
596 MSG_FATAL("%s", e.what());
597 return MSG_ERR_PLUGIN_SETTING;
601 MSG_FATAL("%s", e.what());
602 return MSG_ERR_PLUGIN_SETTING;