Fix for read, delete and CB config issues
authorPrasanth Kammampati <prasanth.k@samsung.com>
Fri, 7 Sep 2012 05:30:46 +0000 (11:00 +0530)
committerPrasanth Kammampati <prasanth.k@samsung.com>
Fri, 7 Sep 2012 05:31:35 +0000 (11:01 +0530)
Change-Id: I440c5cefb5b73a7830ddf4fac68982131a1de33b

packaging/tel-plugin-imc.spec [changed mode: 0755->0644]
src/s_sms.c

old mode 100755 (executable)
new mode 100644 (file)
index 0b9c230..2a39f08
@@ -2,7 +2,7 @@
 Name:       tel-plugin-imc
 Summary:    imc plugin for telephony
 ExclusiveArch:  %{arm}
-Version:    0.1.13
+Version:    0.1.14
 Release:    1
 Group:      System/Libraries
 License:    Apache
index bcc955a..8418dd1 100755 (executable)
-/*\r
- * tel-plugin-imc\r
- *\r
- * Copyright (c) 2012 Samsung Electronics Co., Ltd. All rights reserved.\r
- *\r
- * Contact: Madhavi Akella <madhavi.a@samsung.com>\r
- *\r
- * Licensed under the Apache License, Version 2.0 (the "License");\r
- * you may not use this file except in compliance with the License.\r
- * You may obtain a copy of the License at\r
- *\r
- * http://www.apache.org/licenses/LICENSE-2.0\r
- *\r
- * Unless required by applicable law or agreed to in writing, software\r
- * distributed under the License is distributed on an "AS IS" BASIS,\r
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
- * See the License for the specific language governing permissions and\r
- * limitations under the License.\r
- */\r
-\r
-#include <stdio.h>\r
-#include <stdlib.h>\r
-#include <string.h>\r
-#include <stdint.h>\r
-\r
-#include <glib.h>\r
-\r
-#include <tcore.h>\r
-#include <hal.h>\r
-#include <core_object.h>\r
-#include <plugin.h>\r
-#include <queue.h>\r
-#include <co_sms.h>\r
-#include <co_sim.h>\r
-#include <user_request.h>\r
-#include <storage.h>\r
-#include <server.h>\r
-#include <at.h>\r
-#include <plugin.h>\r
-\r
-#include "common/TelErr.h"\r
-#include "s_common.h"\r
-#include "s_sms.h"\r
-\r
-/*=============================================================\r
-                                                       GSM-SMS Size\r
-==============================================================*/\r
-#define MAX_GSM_SMS_TPDU_SIZE                                          244\r
-#define MAX_GSM_SMS_MSG_NUM                                                    255\r
-#define MAX_GSM_SMS_SERVICE_CENTER_ADDR                                12              /* Maximum number of bytes of service center address */\r
-#define MAX_GSM_SMS_CBMI_LIST_SIZE                                     100             /* Maximum number of CBMI list size for CBS 30*2=60  */\r
-#define MAX_GSM_SMS_PARAM_RECORD_SIZE                          156             /* Maximum number of bytes SMSP Record size (Y + 28), y : 0 ~ 128 */\r
-#define MAX_GSM_SMS_STATUS_FILE_SIZE                                   2               /* Last Used TP-MR + SMS "Memory Cap. Exceeded" Noti Flag */\r
-#define TAPI_SIM_SMSP_ADDRESS_LEN                                      20\r
-\r
-/*=============================================================\r
-                                                       Device Ready\r
-==============================================================*/\r
-#define AT_SMS_DEVICE_READY                    12              /* AT device ready */\r
-#define SMS_DEVICE_READY                               1               /* Telephony device ready */\r
-#define SMS_DEVICE_NOT_READY                   0               /* Telephony device not ready */\r
-\r
-/*=============================================================\r
-                                                       CBMI Selection\r
-==============================================================*/\r
-#define SMS_CBMI_SELECTED_SOME         0x02    /* Some CBMIs are selected */\r
-#define SMS_CBMI_SELECTED_ALL                  0x01    /* All CBMIs are selected */\r
-\r
-/*=============================================================\r
-                                                       Message Status\r
-==============================================================*/\r
-#define AT_REC_UNREAD                                  0               /* Received and Unread */\r
-#define AT_REC_READ                                    1               /* Received and Read */\r
-#define AT_STO_UNSENT                                  2               /* Unsent */\r
-#define AT_STO_SENT                                    3               /* Sent */\r
-#define AT_ALL                                                         4               /* Unknown */\r
-\r
-/*=============================================================\r
-                                                       Memory Status\r
-==============================================================*/\r
-#define AT_MEMORY_AVAILABLE                    0               /* Memory Available */\r
-#define AT_MEMORY_FULL                                 1               /* Memory Full */\r
-\r
-/*=============================================================\r
-               SIM CRSM SW1 and Sw2 Error definitions */\r
-\r
-#define AT_SW1_SUCCESS 0x90\r
-#define AT_SW2_SUCCESS 0\r
-#define AT_SW1_LEN_RESP 0x9F\r
-\r
-#define AT_MAX_RECORD_LEN 256\r
-#define AT_EF_SMS_RECORD_LEN 176\r
-\r
-/*=============================================================*/\r
-\r
-\r
-/*=========================================================\r
-                                                       Security\r
-==============================================================*/\r
-#define MAX_SEC_PIN_LEN                                                        8\r
-#define MAX_SEC_PUK_LEN                                                        8\r
-#define MAX_SEC_PHONE_LOCK_PW_LEN                              39              /* Maximum Phone Locking Password Length */\r
-#define MAX_SEC_SIM_DATA_STRING                                        256             /* Maximum Length of the DATA or RESPONSE. Restricted SIM Access, Generic SIM Access Message */\r
-#define MAX_SEC_NUM_LOCK_TYPE                                          8               /* Maximum number of Lock Type used in Lock Information Message */\r
-#define MAX_SEC_IMS_AUTH_LEN                                           512             /* Maximum Length of IMS Authentication Message */\r
-\r
-/*=============================================================\r
-                                                       String Preprocessor\r
-==============================================================*/\r
-#define CR             '\r'            /* Carriage Return */\r
-\r
-/*=============================================================\r
-                                                       Developer\r
-==============================================================*/\r
-#define SMS_SWAPBYTES16(x) (((x) & 0xffff0000) | (((x) & 0x0000ff00) >> 8) | (((x) & 0x000000ff) << 8))\r
-\r
-void print_glib_list_elem(gpointer data, gpointer user_data);\r
-\r
-static void on_response_class2_read_msg(TcorePending *pending, int data_len, const void *data, void *user_data);\r
-\r
-\r
-gboolean util_byte_to_hex(const char *byte_pdu, char *hex_pdu, int num_bytes);\r
-\r
-/* gaurav.kalra: For test */\r
-void print_glib_list_elem(gpointer data, gpointer user_data)\r
-{\r
-       char *item = (char *)data;\r
-       dbg("item: [%s]", item);\r
-}\r
-\r
-/*=============================================================\r
-                                                       Send Callback\r
-==============================================================*/\r
-static void on_confirmation_sms_message_send(TcorePending *p, gboolean result, void *user_data)\r
-{\r
-       dbg("Entered Function. Request message out from queue");\r
-\r
-       dbg("TcorePending: [%p]", p);\r
-       dbg("result: [%02x]", result);\r
-       dbg("user_data: [%p]", user_data);\r
-\r
-       if (result == TRUE) {\r
-               dbg("SEND OK");\r
-       } else { /* Failed */\r
-               dbg("SEND NOK");\r
-       }\r
-\r
-       dbg("Exiting Function. Nothing to return");\r
-}\r
-\r
-/*=============================================================\r
-                                                       Utilities\r
-==============================================================*/\r
-static void util_sms_free_memory(void *sms_ptr)\r
-{\r
-       dbg("Entry");\r
-\r
-       if (NULL != sms_ptr) {\r
-               dbg("Freeing memory location: [%p]", sms_ptr);\r
-               free(sms_ptr);\r
-               sms_ptr = NULL;\r
-       } else {\r
-               err("Invalid memory location. Nothing to do.");\r
-       }\r
-\r
-       dbg("Exit");\r
-}\r
-\r
\r
-static int util_sms_decode_smsParameters(unsigned char *incoming, unsigned int length, struct telephony_sms_Params *params)\r
-{\r
-       int alpha_id_len = 0;\r
-       int i = 0;\r
-       int nOffset = 0;\r
-\r
-       dbg(" RecordLen = %d", length);\r
-\r
-       if(incoming == NULL || params == NULL)\r
-               return FALSE;\r
-\r
-       alpha_id_len = length -SMS_SMSP_PARAMS_MAX_LEN;\r
-\r
-       if (alpha_id_len > 0) {\r
-               if (alpha_id_len > SMS_SMSP_ALPHA_ID_LEN_MAX) {\r
-                       alpha_id_len = SMS_SMSP_ALPHA_ID_LEN_MAX;\r
-               }\r
-\r
-               for (i = 0; i < alpha_id_len; i++) {\r
-                       if (0xff == incoming[i]) {\r
-                               dbg(" found");\r
-                               break;\r
-                       }\r
-               }\r
-\r
-               memcpy(params->szAlphaId, incoming, i);\r
-\r
-               params->alphaIdLen = i;\r
-\r
-               dbg(" Alpha id length = %d", i);\r
-       } else {\r
-               params->alphaIdLen = 0;\r
-               dbg(" Alpha id length is zero");\r
-       }\r
-\r
-       //dongil01.park - start parse from here.\r
-       params->paramIndicator = incoming[alpha_id_len];\r
-\r
-       dbg(" Param Indicator = %02x", params->paramIndicator);\r
-\r
-       //dongil01.park(2008/12/26) - DestAddr\r
-       if ((params->paramIndicator & SMSPValidDestAddr) == 0) {\r
-               nOffset = nDestAddrOffset;\r
-\r
-               if (0x00 == incoming[alpha_id_len + nOffset] || 0xff == incoming[alpha_id_len + nOffset]) {\r
-                       params->tpDestAddr.dialNumLen = 0;\r
-\r
-                       dbg("DestAddr Length is 0");\r
-               } else {\r
-                       if (0 < (int) incoming[alpha_id_len + nOffset]) {\r
-                               params->tpDestAddr.dialNumLen = (int) (incoming[alpha_id_len + nOffset] - 1);\r
-\r
-                               if (params->tpDestAddr.dialNumLen > SMS_SMSP_ADDRESS_LEN)\r
-                                       params->tpDestAddr.dialNumLen = SMS_SMSP_ADDRESS_LEN;\r
-                       } else {\r
-                               params->tpDestAddr.dialNumLen = 0;\r
-                       }\r
-\r
-                       params->tpDestAddr.numPlanId = incoming[alpha_id_len + (++nOffset)] & 0x0f;\r
-                       params->tpDestAddr.typeOfNum = (incoming[alpha_id_len + nOffset] & 0x70) >> 4;\r
-\r
-                       memcpy(params->tpDestAddr.diallingNum, &incoming[alpha_id_len + (++nOffset)], (params->tpDestAddr.dialNumLen));\r
-\r
-                       dbg("Dest TON is %d", params->tpDestAddr.typeOfNum);\r
-                       dbg("Dest NPI is %d", params->tpDestAddr.numPlanId);\r
-                       dbg("Dest Length = %d", params->tpDestAddr.dialNumLen);\r
-                       dbg("Dest Addr = %s", params->tpDestAddr.diallingNum);\r
-               }\r
-       }\r
-       else {\r
-               params->tpDestAddr.dialNumLen = 0;                      \r
-       }\r
-\r
-       // dongil01.park(2008/12/26) - SvcAddr\r
-       if ((params->paramIndicator & SMSPValidSvcAddr) == 0) {\r
-               nOffset = nSCAAddrOffset;\r
-\r
-               if (0x00 == (int) incoming[alpha_id_len + nOffset] || 0xff == (int) incoming[alpha_id_len + nOffset]) {\r
-                       params->tpSvcCntrAddr.dialNumLen = 0;\r
-\r
-                       dbg(" SCAddr Length is 0");\r
-               } else {\r
-                       if (0 < (int) incoming[alpha_id_len + nOffset]) {\r
-                               params->tpSvcCntrAddr.dialNumLen = (int) (incoming[alpha_id_len + nOffset] - 1);\r
-\r
-                               if (params->tpSvcCntrAddr.dialNumLen > SMS_SMSP_ADDRESS_LEN)\r
-                                       params->tpSvcCntrAddr.dialNumLen = SMS_SMSP_ADDRESS_LEN;\r
-\r
-                               params->tpSvcCntrAddr.numPlanId = incoming[alpha_id_len + (++nOffset)] & 0x0f;\r
-                               params->tpSvcCntrAddr.typeOfNum = (incoming[alpha_id_len + nOffset] & 0x70) >> 4;\r
-\r
-                               memcpy(params->tpSvcCntrAddr.diallingNum, &incoming[alpha_id_len + (++nOffset)], (params->tpSvcCntrAddr.dialNumLen));\r
-\r
-                               dbg("SCAddr Length = %d ", params->tpSvcCntrAddr.dialNumLen);\r
-                               dbg("SCAddr TON is %d", params->tpSvcCntrAddr.typeOfNum);\r
-                               dbg("SCAddr NPI is %d", params->tpSvcCntrAddr.numPlanId);\r
-\r
-                               for (i = 0; i < (int) params->tpSvcCntrAddr.dialNumLen; i++)\r
-                                       dbg("SCAddr = %d [%02x]", i, params->tpSvcCntrAddr.diallingNum[i]);\r
-                       } else {\r
-                               params->tpSvcCntrAddr.dialNumLen = 0;\r
-                       }\r
-               }\r
-       } else if ((0x00 < (int) incoming[alpha_id_len + nSCAAddrOffset] && (int) incoming[alpha_id_len + nSCAAddrOffset] <= 12)\r
-                          || 0xff != (int) incoming[alpha_id_len + nSCAAddrOffset]) {\r
-               nOffset = nSCAAddrOffset;\r
-\r
-               if (0x00 == (int) incoming[alpha_id_len + nOffset] || 0xff == (int) incoming[alpha_id_len + nOffset]) {\r
-                       params->tpSvcCntrAddr.dialNumLen = 0;\r
-                       dbg("SCAddr Length is 0");\r
-               } else {\r
-                       if (0 < (int) incoming[alpha_id_len + nOffset]) {\r
-                               params->tpSvcCntrAddr.dialNumLen = (int) (incoming[alpha_id_len + nOffset] - 1);\r
-\r
-                               params->tpSvcCntrAddr.dialNumLen = incoming[alpha_id_len + nOffset] - 1;\r
-\r
-                               if (params->tpSvcCntrAddr.dialNumLen > SMS_SMSP_ADDRESS_LEN)\r
-                                       params->tpSvcCntrAddr.dialNumLen = SMS_SMSP_ADDRESS_LEN;\r
-\r
-                               params->tpSvcCntrAddr.numPlanId = incoming[alpha_id_len + (++nOffset)] & 0x0f;\r
-                               params->tpSvcCntrAddr.typeOfNum = (incoming[alpha_id_len + nOffset] & 0x70) >> 4;\r
-\r
-                               memcpy(params->tpSvcCntrAddr.diallingNum, &incoming[alpha_id_len + (++nOffset)],\r
-                                          (params->tpSvcCntrAddr.dialNumLen));\r
-\r
-                               dbg("SCAddr Length = %d ", params->tpSvcCntrAddr.dialNumLen);\r
-                               dbg("SCAddr TON is %d", params->tpSvcCntrAddr.typeOfNum);\r
-                               dbg("SCAddr NPI is %d", params->tpSvcCntrAddr.numPlanId);\r
-\r
-                               for (i = 0; i < (int) params->tpSvcCntrAddr.dialNumLen; i++)\r
-                                       dbg("SCAddr = %d [%02x]", i, params->tpSvcCntrAddr.diallingNum[i]);\r
-                       } else {\r
-                               params->tpSvcCntrAddr.dialNumLen = 0;\r
-                       }\r
-               }\r
-       }\r
-       else {\r
-                       params->tpSvcCntrAddr.dialNumLen = 0;\r
-       }\r
-\r
-       if ((params->paramIndicator & SMSPValidPID) == 0 && (alpha_id_len + nPIDOffset) < MAX_GSM_SMS_PARAM_RECORD_SIZE) {\r
-               params->tpProtocolId = incoming[alpha_id_len + nPIDOffset];\r
-       }\r
-       if ((params->paramIndicator & SMSPValidDCS) == 0 && (alpha_id_len + nDCSOffset) < MAX_GSM_SMS_PARAM_RECORD_SIZE) {\r
-               params->tpDataCodingScheme = incoming[alpha_id_len + nDCSOffset];\r
-       }\r
-       if ((params->paramIndicator & SMSPValidVP) == 0 && (alpha_id_len + nVPOffset) < MAX_GSM_SMS_PARAM_RECORD_SIZE) {\r
-               params->tpValidityPeriod = incoming[alpha_id_len + nVPOffset];\r
-       }\r
-\r
-       dbg(" Alpha Id(Len) = %d", (int) params->alphaIdLen);\r
-\r
-       for (i = 0; i < (int) params->alphaIdLen; i++) {\r
-               dbg(" Alpha Id = [%d] [%c]", i, params->szAlphaId[i]);\r
-       }\r
-       dbg(" PID = %d",params->tpProtocolId);\r
-       dbg(" DCS = %d",params->tpDataCodingScheme);\r
-       dbg(" VP = %d",params->tpValidityPeriod);\r
-\r
-       return TRUE;\r
-}\r
-\r
-\r
-/*=============================================================\r
-                                                       Notifications\r
-==============================================================*/\r
-static gboolean on_event_sms_ready_status(CoreObject *o, const void *event_info, void *user_data)\r
-{\r
-       struct tnoti_sms_ready_status readyStatusInfo = {0,};\r
-       char *line = NULL;\r
-       GSList *tokens = NULL;\r
-       GSList *lines = NULL;\r
-       char *pResp = NULL;\r
-       //CoreObject *o = NULL;\r
-\r
-       int rtn = -1 , status = 0;\r
-\r
-       dbg(" Func Entrance");\r
-\r
-       lines = (GSList *)event_info;\r
-       if (1 != g_slist_length(lines)) {\r
-               dbg("unsolicited msg but multiple line");\r
-               goto OUT;\r
-       }\r
-       line = (char *) (lines->data);\r
-\r
-       dbg(" Func Entrance");\r
-\r
-       if (line != NULL) {\r
-               dbg("Response OK");\r
-               dbg("noti line is %s", line);\r
-               tokens = tcore_at_tok_new(line);\r
-               pResp = g_slist_nth_data(tokens, 0);\r
-               if (pResp != NULL)\r
-                       status = atoi(pResp);\r
-       } else {\r
-               dbg("Response NOK");\r
-       }\r
-\r
-       if (status == AT_SMS_DEVICE_READY) {\r
-               readyStatusInfo.status = SMS_DEVICE_READY;\r
-               tcore_sms_set_ready_status(o, readyStatusInfo.status);\r
-               dbg("SMS Ready status = [%s]", readyStatusInfo.status ? "TRUE" : "FALSE");\r
-               rtn = tcore_server_send_notification(tcore_plugin_ref_server(tcore_object_ref_plugin(o)), o, TNOTI_SMS_DEVICE_READY, sizeof(struct tnoti_sms_ready_status), &readyStatusInfo);\r
-               dbg(" Return value [%d]", rtn);\r
-       } else {\r
-               readyStatusInfo.status = SMS_DEVICE_NOT_READY;\r
-       }\r
-\r
-OUT:\r
-       if(NULL!=tokens)\r
-               tcore_at_tok_free(tokens);\r
-       return TRUE;\r
-}\r
-\r
-static gboolean on_event_class2_sms_incom_msg(CoreObject *obj, const void *event_info, void *user_data)\r
-{\r
-       //+CMTI: <mem>,<index>\r
-       \r
-       GSList *tokens = NULL , *lines = NULL;\r
-       char *line = NULL, *cmd_str = NULL;\r
-       int index = 0, mem_type = 0;\r
-       TcoreHal *hal = NULL;\r
-       TcoreATRequest *atreq = NULL;\r
-       TcorePending *pending = NULL;\r
-\r
-       dbg("Entered Function");\r
-\r
-       lines = (GSList *)event_info;\r
-       line = (char *)g_slist_nth_data(lines, 0); /* Fetch Line 1 */\r
-\r
-       dbg("Line 1: [%s]", line);\r
-\r
-       if (!line) {\r
-               err("Line 1 is invalid");\r
-               return FALSE;\r
-       }\r
-\r
-       tokens = tcore_at_tok_new(line); /* Split Line 1 into tokens */\r
-       mem_type = atoi(g_slist_nth_data(tokens, 0));       // Type of Memory stored\r
-       index = atoi((char *) g_slist_nth_data(tokens, 1));\r
-\r
-       hal = tcore_object_get_hal(obj);\r
-       if (NULL == hal) {\r
-               err("NULL input. Unable to proceed");\r
-               dbg("readMsg: hal: [%p]", hal);\r
-\r
-               dbg("Exit");\r
-               return TCORE_RETURN_EINVAL;\r
-       }\r
-\r
-       dbg("index: [%d]", index);\r
-\r
-       cmd_str = g_strdup_printf("AT+CMGR=%d", index); \r
-       atreq     = tcore_at_request_new((const char *)cmd_str, "+CMGR", TCORE_AT_PDU);\r
-       pending = tcore_pending_new(obj, 0);\r
-\r
-       if (NULL == cmd_str || NULL == atreq || NULL == pending) {\r
-               err("Out of memory. Unable to proceed");\r
-               dbg("cmd_str: [%p], atreq: [%p], pending: [%p]", cmd_str, atreq, pending);\r
-\r
-               //free memory we own\r
-               g_free(cmd_str);\r
-               util_sms_free_memory(atreq);\r
-               util_sms_free_memory(pending);\r
-\r
-               dbg("Exit");\r
-               return TCORE_RETURN_ENOMEM;\r
-       }\r
-\r
-       util_hex_dump("    ", strlen(cmd_str), (void *)cmd_str);\r
-\r
-       tcore_pending_set_request_data(pending, 0, atreq);\r
-       tcore_pending_set_response_callback(pending, on_response_class2_read_msg, (void *)(uintptr_t)index); //storing index as user data for response\r
-       tcore_pending_link_user_request(pending, NULL);\r
-       tcore_pending_set_send_callback(pending, on_confirmation_sms_message_send, NULL);\r
-       tcore_hal_send_request(hal, pending);\r
-       g_free(cmd_str);\r
-       \r
-       if(tokens)\r
-               tcore_at_tok_free(tokens);\r
-\r
-       return TRUE;\r
-}\r
-\r
-static gboolean on_event_sms_incom_msg(CoreObject *o, const void *event_info, void *user_data)\r
-{\r
-       //+CMT: [<alpha>],<length><CR><LF><pdu> (PDU mode enabled);\r
-       \r
-       int rtn = -1;\r
-       GSList *tokens = NULL;\r
-       GSList *lines = NULL;\r
-       char *line = NULL;\r
-       int pdu_len = 0, no_of_tokens = 0;\r
-       unsigned char *bytePDU = NULL;\r
-       struct tnoti_sms_umts_msg gsmMsgInfo;\r
-       int sca_length = 0;\r
-\r
-       dbg("Entered Function");\r
-\r
-       lines = (GSList *)event_info;\r
-       memset(&gsmMsgInfo, 0x00, sizeof(struct tnoti_sms_umts_msg));\r
-\r
-       if (2 != g_slist_length(lines)) {\r
-               err("Invalid number of lines for +CMT. Must be 2");\r
-               return FALSE;\r
-       }\r
-\r
-       line = (char *)g_slist_nth_data(lines, 0); /* Fetch Line 1 */\r
-\r
-       dbg("Line 1: [%s]", line);\r
-\r
-       if (!line) {\r
-               err("Line 1 is invalid");\r
-               return FALSE;\r
-       }\r
-\r
-       tokens = tcore_at_tok_new(line); /* Split Line 1 into tokens */\r
-\r
-       no_of_tokens = g_slist_length(tokens);\r
-\r
-       if (no_of_tokens == 2) { // in case of incoming SMS +CMT\r
-               dbg("Alpha ID: [%02x]", g_slist_nth_data(tokens, 0)); /* 0: Alpha ID */\r
-               pdu_len = atoi((char *)g_slist_nth_data(tokens, 1));\r
-               dbg("pdu_len: [%d]", pdu_len);  /* 1: PDU Length */\r
-       } else if (no_of_tokens == 1) { // in case of incoming status report +CDS\r
-               pdu_len = atoi((char *)g_slist_nth_data(tokens, 0));\r
-               dbg("pdu_len: [%d]", pdu_len);  /* 1: PDU Length */\r
-       }\r
-       \r
-       line = (char *)g_slist_nth_data(lines, 1); /* Fetch Line 2 */\r
-\r
-       dbg("Line 2: [%s]", line);\r
-\r
-       if (!line) {\r
-               err("Line 2 is invalid");\r
-               return FALSE;\r
-       }\r
-\r
-       /* Convert to Bytes */\r
-       bytePDU = (unsigned char *)util_hexStringToBytes(line);\r
-\r
-       sca_length = bytePDU[0];\r
-               \r
-       dbg("SCA length = %d", sca_length);\r
-       \r
-       gsmMsgInfo.msgInfo.msgLength = pdu_len-(sca_length+1);\r
-\r
-       if (sca_length == 0) { \r
-               memcpy(gsmMsgInfo.msgInfo.tpduData, &bytePDU[1], gsmMsgInfo.msgInfo.msgLength);\r
-       }\r
-       else     {\r
-               memcpy(gsmMsgInfo.msgInfo.sca, &bytePDU[1], sca_length);\r
-               memcpy(gsmMsgInfo.msgInfo.tpduData, &bytePDU[sca_length+1], gsmMsgInfo.msgInfo.msgLength);\r
-       }\r
-\r
-       util_hex_dump("      ", strlen(line)/2, bytePDU);\r
-       util_hex_dump("      ", sca_length, gsmMsgInfo.msgInfo.sca);\r
-       util_hex_dump("      ", gsmMsgInfo.msgInfo.msgLength,gsmMsgInfo.msgInfo.tpduData);\r
-\r
-       rtn = tcore_server_send_notification(tcore_plugin_ref_server(tcore_object_ref_plugin(o)), o, TNOTI_SMS_INCOM_MSG, sizeof(struct tnoti_sms_umts_msg), &gsmMsgInfo);\r
-       \r
-       if(tokens)\r
-               tcore_at_tok_free(tokens);\r
-\r
-       free(bytePDU);\r
-\r
-       return TRUE;\r
-}\r
-\r
-\r
-\r
-static gboolean on_event_sms_memory_status(CoreObject *o, const void *event_info, void *user_data)\r
-{\r
-       struct tnoti_sms_memory_status memStatusInfo = {0,};\r
-\r
-       int rtn = -1 ,memoryStatus = -1;\r
-       GSList *tokens=NULL;\r
-       GSList *lines=NULL;\r
-       char *line = NULL , *pResp = NULL;\r
-\r
-       dbg(" Entry");\r
-\r
-       lines = (GSList *)event_info;\r
-       if (1 != g_slist_length(lines)) {\r
-                dbg("unsolicited msg but multiple line");\r
-        }\r
-\r
-       line = (char*)(lines->data);\r
-\r
-       if (line) {\r
-               dbg("Response OK");\r
-               tokens = tcore_at_tok_new(line);\r
-               pResp = g_slist_nth_data(tokens, 0);\r
-\r
-               if (pResp) {\r
-                       memoryStatus = atoi(pResp);\r
-                       dbg("memoryStatus is %d",memoryStatus);\r
-                       if (memoryStatus == 0) {//SIM Full condition\r
-                               memStatusInfo.status = SMS_PHONE_MEMORY_STATUS_FULL;\r
-                       }\r
-                       rtn = tcore_server_send_notification(tcore_plugin_ref_server(tcore_object_ref_plugin(o)), o, TNOTI_SMS_MEMORY_STATUS, sizeof(struct tnoti_sms_memory_status), &memStatusInfo);\r
-               }\r
-               tcore_at_tok_free(tokens);\r
-       }else {\r
-               dbg("Response NOK");\r
-       }\r
-\r
-       dbg(" Exit ");\r
-       return TRUE;\r
-}\r
-\r
-static gboolean on_event_sms_cb_incom_msg(CoreObject *o, const void *event_info, void *user_data)\r
-{\r
-       //+CBM: <length><CR><LF><pdu>\r
-\r
-       struct tnoti_sms_cellBroadcast_msg cbMsgInfo;\r
-\r
-       int rtn = -1 , length = 0;\r
-       char * line = NULL, *pdu = NULL, *pResp = NULL;\r
-       GSList *tokens = NULL;\r
-       GSList *lines = NULL;\r
-\r
-       dbg(" Func Entrance");\r
-\r
-       lines = (GSList *)event_info;\r
-\r
-       memset(&cbMsgInfo, 0, sizeof(struct tnoti_sms_cellBroadcast_msg));\r
-\r
-       line = (char *)(lines->data);\r
-\r
-       if (line != NULL) {\r
-               dbg("Response OK");\r
-               dbg("Noti line is %s",line);\r
-               tokens = tcore_at_tok_new(line); /* Split Line 1 into tokens */\r
-\r
-               pResp = g_slist_nth_data(tokens, 0);\r
-               if (pResp) {\r
-                       length = atoi(pResp);\r
-               } else {\r
-                       dbg("token 0 is null");\r
-               }\r
-               \r
-               pdu = g_slist_nth_data(lines, 1);\r
-               if (pdu != NULL) {\r
-                       cbMsgInfo.cbMsg.length = length;\r
-                       cbMsgInfo.cbMsg.cbMsgType = SMS_CB_MSG_CBS;\r
-\r
-                       dbg("CB Msg LENGTH [%2x]", length);\r
-\r
-                       if ((cbMsgInfo.cbMsg.length >0) && (SMS_CB_SIZE_MAX >= cbMsgInfo.cbMsg.length)) {\r
-                               unsigned char *byte_pdu = NULL;\r
-                               \r
-                               byte_pdu = (unsigned char *)util_hexStringToBytes(pdu);\r
-                               \r
-                               memcpy(cbMsgInfo.cbMsg.msgData, (char*)byte_pdu, cbMsgInfo.cbMsg.length);\r
-                               rtn = tcore_server_send_notification(tcore_plugin_ref_server(tcore_object_ref_plugin(o)), o, TNOTI_SMS_CB_INCOM_MSG, sizeof(struct tnoti_sms_cellBroadcast_msg), &cbMsgInfo);\r
-                               free(byte_pdu);\r
-                       } else {\r
-                               dbg("Invalid Message Length");\r
-                       }\r
-               } else {\r
-                       dbg("Recieved NULL pdu");\r
-               }\r
-       } else {\r
-               dbg("Response NOK");\r
-       }\r
-\r
-       dbg(" Return value [%d]",rtn);\r
-\r
-       if(tokens)\r
-               tcore_at_tok_free(tokens);\r
-\r
-       return TRUE;\r
-}\r
-\r
-\r
-/*=============================================================\r
-                                                       Responses\r
-==============================================================*/\r
-static void on_response_sms_delete_msg(TcorePending *p, int data_len, const void *data, void *user_data)\r
-{\r
-       struct tresp_sms_delete_msg delMsgInfo = {0,};\r
-       UserRequest *ur = NULL;\r
-       const TcoreATResponse *atResp = data;\r
-\r
-       int rtn = -1;\r
-       int *index = (int *)user_data;\r
-\r
-       dbg(" Func Entrance");\r
-\r
-       ur = tcore_pending_ref_user_request(p);\r
-       if (atResp->success) {\r
-               dbg("Response OK");\r
-               delMsgInfo.index = *index;\r
-               delMsgInfo.result = SMS_SENDSMS_SUCCESS;\r
-       } else {\r
-               dbg("Response NOK");\r
-               delMsgInfo.index = *index;\r
-               delMsgInfo.result = SMS_DEVICE_FAILURE;\r
-       }\r
-\r
-       rtn = tcore_user_request_send_response(ur, TRESP_SMS_DELETE_MSG, sizeof(struct tresp_sms_delete_msg), &delMsgInfo);\r
-\r
-       return;\r
-}\r
-\r
-static void on_response_sms_save_msg(TcorePending *p, int data_len, const void *data, void *user_data)\r
-{\r
-       struct tresp_sms_save_msg saveMsgInfo = {0,};\r
-       UserRequest *ur = NULL;\r
-       const TcoreATResponse *atResp = data;\r
-       GSList *tokens = NULL;\r
-       char *line = NULL;\r
-       char *pResp = NULL;\r
-       int rtn = -1;\r
-\r
-       ur = tcore_pending_ref_user_request(p);\r
-       if (atResp->success) {\r
-               dbg("Response OK");\r
-               if (atResp->lines) {\r
-                       line = (char *)atResp->lines->data;\r
-                       tokens = tcore_at_tok_new(line);\r
-                       pResp = g_slist_nth_data(tokens, 0);\r
-                       if (pResp) {\r
-                               dbg("0: %s", pResp);\r
-                               saveMsgInfo.index = (atoi(pResp) - 1); /* IMC index starts from 1 */\r
-                               saveMsgInfo.result = SMS_SENDSMS_SUCCESS;\r
-                       } else {\r
-                               dbg("No Tokens");\r
-                               saveMsgInfo.index = -1;\r
-                               saveMsgInfo.result = SMS_DEVICE_FAILURE;\r
-                       }\r
-                       tcore_at_tok_free(tokens);\r
-               }\r
-       } else {\r
-               dbg("Response NOK");\r
-               saveMsgInfo.index = -1;\r
-               saveMsgInfo.result = SMS_DEVICE_FAILURE;\r
-       }\r
-\r
-       rtn = tcore_user_request_send_response(ur, TRESP_SMS_SAVE_MSG, sizeof(struct tresp_sms_save_msg), &saveMsgInfo);\r
-       dbg("Return value [%d]", rtn);\r
-       return;\r
-}\r
-\r
-static void on_response_send_umts_msg(TcorePending *pending, int data_len, const void *data, void *user_data)\r
-{\r
-       const TcoreATResponse *at_response = data;\r
-       struct tresp_sms_send_umts_msg resp_umts;\r
-       UserRequest *user_req = NULL;\r
-\r
-       int msg_ref = 0;\r
-       GSList *tokens = NULL;\r
-       char *gslist_line = NULL, *line_token = NULL;\r
-\r
-       dbg("Entry");\r
-\r
-       user_req = tcore_pending_ref_user_request(pending);\r
-\r
-       if (NULL == user_req) {\r
-               err("No user request");\r
-\r
-               dbg("Exit");\r
-               return;\r
-       }\r
-\r
-       memset(&resp_umts, 0x00, sizeof(resp_umts));\r
-       resp_umts.result = SMS_DEVICE_FAILURE;\r
-\r
-       if (at_response->success > 0) { // success\r
-               dbg("Response OK");\r
-               if (at_response->lines) { // lines present in at_response\r
-                       gslist_line = (char *)at_response->lines->data;\r
-                       dbg("gslist_line: [%s]", gslist_line);\r
-\r
-                       tokens = tcore_at_tok_new(gslist_line); //extract tokens\r
-\r
-                       line_token = g_slist_nth_data(tokens, 0);\r
-                       if (line_token != NULL) {\r
-                               msg_ref = atoi(line_token);\r
-                               dbg("Message Reference: [%d]", msg_ref);\r
-\r
-                               resp_umts.result = SMS_SENDSMS_SUCCESS;\r
-                       } else {\r
-                               dbg("No Message Reference received");\r
-                       }\r
-                       tcore_at_tok_free(tokens);\r
-               } else { // no lines in at_response\r
-                       dbg("No lines");\r
-               }\r
-       } else { // failure\r
-               dbg("Response NOK");\r
-       }\r
-\r
-       tcore_user_request_send_response(user_req, TRESP_SMS_SEND_UMTS_MSG, sizeof(resp_umts), &resp_umts);\r
-\r
-       dbg("Exit");\r
-       return;\r
-}\r
-\r
-static void on_response_class2_read_msg(TcorePending *pending, int data_len, const void *data, void *user_data)\r
-{\r
-       const TcoreATResponse *at_response = data;\r
-       GSList *tokens=NULL;\r
-       char *gslist_line = NULL, *line_token = NULL, *hex_pdu = NULL;\r
-       int  pdu_len = 0, rtn = 0;\r
-       unsigned char *bytePDU = NULL;\r
-       struct tnoti_sms_umts_msg gsmMsgInfo;\r
-       int sca_length= 0;\r
-\r
-       dbg("Entry");\r
-       dbg("lines: [%p]", at_response->lines);\r
-       g_slist_foreach(at_response->lines, print_glib_list_elem, NULL); //for debug log\r
-\r
-       if (at_response->success > 0) {\r
-               dbg("Response OK");\r
-               if (at_response->lines) {\r
-                       //fetch first line\r
-                       gslist_line = (char *)at_response->lines->data;\r
-\r
-                       dbg("gslist_line: [%s]", gslist_line);\r
-\r
-                       tokens = tcore_at_tok_new(gslist_line);\r
-                       dbg("Number of tokens: [%d]", g_slist_length(tokens));\r
-                       g_slist_foreach(tokens, print_glib_list_elem, NULL); //for debug log\r
-\r
-                       line_token = g_slist_nth_data(tokens, 2); //Third Token: Length\r
-                       if (line_token != NULL) {\r
-                               pdu_len = atoi(line_token);\r
-                               dbg("Length: [%d]", pdu_len);\r
-                       }\r
-\r
-                       //fetch second line\r
-                       gslist_line = (char *)at_response->lines->next->data;\r
-\r
-                       dbg("gslist_line: [%s]", gslist_line);\r
-\r
-                       //free the consumed token\r
-                       tcore_at_tok_free(tokens);\r
-\r
-                       tokens = tcore_at_tok_new(gslist_line);\r
-                       dbg("Number of tokens: [%d]", g_slist_length(tokens));\r
-                       g_slist_foreach(tokens, print_glib_list_elem, NULL); //for debug log\r
-\r
-                       hex_pdu = g_slist_nth_data(tokens, 0); //Fetch SMS PDU\r
-\r
-                       //free the consumed token\r
-                       tcore_at_tok_free(tokens);\r
-               } else {\r
-                       dbg("No lines");\r
-               }\r
-       } else {\r
-               err("Response NOK");\r
-       }\r
-\r
-       /* Convert to Bytes */\r
-       bytePDU = (unsigned char *)util_hexStringToBytes(hex_pdu);\r
-\r
-       sca_length = bytePDU[0];\r
-               \r
-       dbg("SCA length = %d", sca_length);\r
-\r
-       gsmMsgInfo.msgInfo.msgLength = pdu_len-(sca_length+1);\r
-\r
-       if (sca_length == 0) { \r
-               memcpy(gsmMsgInfo.msgInfo.tpduData, &bytePDU[1], gsmMsgInfo.msgInfo.msgLength);\r
-       }\r
-       else     {\r
-               memcpy(gsmMsgInfo.msgInfo.sca, bytePDU, sca_length);\r
-               memcpy(gsmMsgInfo.msgInfo.tpduData, &bytePDU[sca_length+1], gsmMsgInfo.msgInfo.msgLength);\r
-       }\r
-\r
-       util_hex_dump("      ", strlen(hex_pdu)/2, bytePDU);\r
-       util_hex_dump("      ", sca_length, gsmMsgInfo.msgInfo.sca);\r
-       util_hex_dump("      ", gsmMsgInfo.msgInfo.msgLength,gsmMsgInfo.msgInfo.tpduData);\r
-\r
-       rtn = tcore_server_send_notification(tcore_plugin_ref_server(tcore_object_ref_plugin(tcore_pending_ref_core_object(pending))), tcore_pending_ref_core_object(pending), TNOTI_SMS_INCOM_MSG, sizeof(struct tnoti_sms_umts_msg), &gsmMsgInfo);\r
-\r
-       free(bytePDU);\r
-\r
-       dbg("Exit");\r
-       return;\r
-}\r
-\r
-static void on_response_read_msg(TcorePending *pending, int data_len, const void *data, void *user_data)\r
-{\r
-       const TcoreATResponse *at_response = data;\r
-       struct tresp_sms_read_msg resp_read_msg;\r
-       UserRequest *user_req = NULL;\r
-\r
-       GSList *tokens=NULL;\r
-       char *gslist_line = NULL, *line_token = NULL, *byte_pdu = NULL, *hex_pdu = NULL;\r
-       int sca_length = 0;\r
-       int msg_status = 0, alpha_id = 0, pdu_len = 0;\r
-       int index = (int)(uintptr_t)user_data;\r
-\r
-       dbg("Entry");\r
-       dbg("index: [%d]", index);\r
-       dbg("lines: [%p]", at_response->lines);\r
-       g_slist_foreach(at_response->lines, print_glib_list_elem, NULL); //for debug log\r
-\r
-       user_req = tcore_pending_ref_user_request(pending);\r
-       if (NULL == user_req) {\r
-               err("No user request");\r
-\r
-               dbg("Exit");\r
-               return;\r
-       }\r
-\r
-       memset(&resp_read_msg, 0x00, sizeof(resp_read_msg));\r
-       resp_read_msg.result = SMS_PHONE_FAILURE;\r
-\r
-       if (at_response->success > 0) {\r
-               dbg("Response OK");\r
-               if (at_response->lines) {\r
-                       //fetch first line\r
-                       gslist_line = (char *)at_response->lines->data;\r
-\r
-                       dbg("gslist_line: [%s]", gslist_line);\r
-\r
-                       tokens = tcore_at_tok_new(gslist_line);\r
-                       dbg("Number of tokens: [%d]", g_slist_length(tokens));\r
-                       g_slist_foreach(tokens, print_glib_list_elem, NULL); //for debug log\r
-\r
-                       line_token = g_slist_nth_data(tokens, 0); //First Token: Message Status\r
-                       if (line_token != NULL) {\r
-                               msg_status = atoi(line_token);\r
-                               dbg("msg_status is %d",msg_status);\r
-                               switch (msg_status) {\r
-                                       case AT_REC_UNREAD:\r
-                                               resp_read_msg.dataInfo.msgStatus = SMS_STATUS_UNREAD;\r
-                                               break;\r
-\r
-                                       case AT_REC_READ:\r
-                                               resp_read_msg.dataInfo.msgStatus = SMS_STATUS_READ;\r
-                                               break;\r
-\r
-                                       case AT_STO_UNSENT:\r
-                                               resp_read_msg.dataInfo.msgStatus = SMS_STATUS_UNSENT;\r
-                                               break;\r
-\r
-                                       case AT_STO_SENT:\r
-                                               resp_read_msg.dataInfo.msgStatus = SMS_STATUS_SENT;\r
-                                               break;\r
-\r
-                                       case AT_ALL: //Fall Through\r
-                                       default: //Fall Through\r
-                                               resp_read_msg.dataInfo.msgStatus = SMS_STATUS_RESERVED;\r
-                                               break;\r
-                               }\r
-                       }\r
-\r
-                       line_token = g_slist_nth_data(tokens, 1); //Second Token: AlphaID\r
-                       if (line_token != NULL) {\r
-                               alpha_id = atoi(line_token);\r
-                               dbg("AlphaID: [%d]", alpha_id);\r
-                       }\r
-\r
-                       line_token = g_slist_nth_data(tokens, 2); //Third Token: Length\r
-                       if (line_token != NULL) {\r
-                               pdu_len = atoi(line_token);\r
-                               dbg("Length: [%d]", pdu_len);\r
-                       }\r
-\r
-                       //fetch second line\r
-                       gslist_line = (char *)at_response->lines->next->data;\r
-\r
-                       dbg("gslist_line: [%s]", gslist_line);\r
-\r
-                       //free the consumed token\r
-                       tcore_at_tok_free(tokens);\r
-\r
-                       tokens = tcore_at_tok_new(gslist_line);\r
-                       \r
-                       dbg("Number of tokens: [%d]", g_slist_length(tokens));\r
-                       g_slist_foreach(tokens, print_glib_list_elem, NULL); //for debug log\r
-\r
-                       hex_pdu = g_slist_nth_data(tokens, 0); //Fetch SMS PDU\r
-\r
-                       //free the consumed token\r
-                       tcore_at_tok_free(tokens);\r
-\r
-                       if (NULL != hex_pdu) {\r
-                               util_hex_dump("    ", sizeof(hex_pdu), (void *)hex_pdu);\r
-\r
-                               byte_pdu = util_hexStringToBytes(hex_pdu);\r
-\r
-                               sca_length = (int)byte_pdu[0];\r
-\r
-                               resp_read_msg.dataInfo.simIndex = index; //Retrieving index stored as user_data\r
-\r
-                               dbg("SCA Length : %d", sca_length);\r
-\r
-                               resp_read_msg.dataInfo.smsData.msgLength =  (pdu_len - (sca_length+1));\r
-                               dbg("msgLength: [%d]", resp_read_msg.dataInfo.smsData.msgLength);\r
-                               \r
-                               if(0 == sca_length) {\r
-                                       if ((resp_read_msg.dataInfo.smsData.msgLength > 0)\r
-                                               && (resp_read_msg.dataInfo.smsData.msgLength <= SMS_SMDATA_SIZE_MAX))   {\r
-                                               memset(resp_read_msg.dataInfo.smsData.sca, 0, TAPI_SIM_SMSP_ADDRESS_LEN);\r
-                                               memcpy(resp_read_msg.dataInfo.smsData.tpduData, &byte_pdu[1], resp_read_msg.dataInfo.smsData.msgLength);\r
-\r
-                                               resp_read_msg.result = SMS_SUCCESS;\r
-                                       } else {\r
-                                               dbg("Invalid Message Length");\r
-                                               resp_read_msg.result = SMS_INVALID_PARAMETER_FORMAT;\r
-                                       }\r
-                               } else {\r
-                                       if ((resp_read_msg.dataInfo.smsData.msgLength > 0)\r
-                                               && (resp_read_msg.dataInfo.smsData.msgLength <= SMS_SMDATA_SIZE_MAX)) {\r
-                                               memcpy(resp_read_msg.dataInfo.smsData.sca, (char *)byte_pdu, (sca_length+1));\r
-                                               memcpy(resp_read_msg.dataInfo.smsData.tpduData, &byte_pdu[sca_length+1], resp_read_msg.dataInfo.smsData.msgLength);\r
-\r
-                                               util_hex_dump("    ", SMS_SMSP_ADDRESS_LEN, (void *)resp_read_msg.dataInfo.smsData.sca);\r
-                                               util_hex_dump("    ", (SMS_SMDATA_SIZE_MAX + 1), (void *)resp_read_msg.dataInfo.smsData.tpduData);\r
-                                               util_hex_dump("    ", sizeof(byte_pdu), (void *)byte_pdu);\r
-\r
-                                               resp_read_msg.result = SMS_SUCCESS;\r
-                                       } else {\r
-                                               dbg("Invalid Message Length");\r
-                                               resp_read_msg.result = SMS_INVALID_PARAMETER_FORMAT;\r
-                                       }\r
-                               }\r
-                               free(byte_pdu);\r
-                       }else {\r
-                               dbg("NULL PDU");\r
-                       }\r
-               }else {\r
-                       dbg("No lines");\r
-               }\r
-       } else {\r
-               err("Response NOK");\r
-       }\r
-\r
-       tcore_user_request_send_response(user_req, TRESP_SMS_READ_MSG, sizeof(resp_read_msg), &resp_read_msg);\r
-\r
-       dbg("Exit");\r
-       return;\r
-}\r
-\r
-static void on_response_get_msg_indices(TcorePending *pending, int data_len, const void *data, void *user_data)\r
-{\r
-       const TcoreATResponse *at_response = data;\r
-       struct tresp_sms_get_storedMsgCnt resp_stored_msg_cnt;\r
-       UserRequest *user_req = NULL;\r
-       struct tresp_sms_get_storedMsgCnt *resp_stored_msg_cnt_prev = NULL;\r
-\r
-       GSList *tokens = NULL;\r
-       char *gslist_line = NULL, *line_token = NULL;\r
-       int gslist_line_count = 0, ctr_loop = 0;\r
-\r
-       dbg("Entry");\r
-\r
-       resp_stored_msg_cnt_prev = (struct tresp_sms_get_storedMsgCnt *)user_data;\r
-       user_req = tcore_pending_ref_user_request(pending);\r
-\r
-       memset(&resp_stored_msg_cnt, 0x00, sizeof(resp_stored_msg_cnt));\r
-       resp_stored_msg_cnt.result = SMS_DEVICE_FAILURE;\r
-\r
-       if (at_response->success) {\r
-               dbg("Response OK");\r
-               if (at_response->lines) {\r
-                       gslist_line_count = g_slist_length(at_response->lines);\r
-\r
-                       if (gslist_line_count > SMS_GSM_SMS_MSG_NUM_MAX)\r
-                               gslist_line_count = SMS_GSM_SMS_MSG_NUM_MAX;\r
-\r
-                       dbg("Number of lines: [%d]", gslist_line_count);\r
-                       g_slist_foreach(at_response->lines, print_glib_list_elem, NULL); //for debug log\r
-\r
-                       for (ctr_loop = 0; ctr_loop < gslist_line_count; ctr_loop++) {\r
-                               gslist_line = (char *)g_slist_nth_data(at_response->lines, ctr_loop); /* Fetch Line i */\r
-\r
-                               dbg("gslist_line [%d] is [%s]", ctr_loop, gslist_line);\r
-\r
-                               if (NULL != gslist_line)\r
-                               {\r
-                                       tokens = tcore_at_tok_new(gslist_line);\r
-\r
-                                       g_slist_foreach(tokens, print_glib_list_elem, NULL); //for debug log\r
-\r
-                                       line_token = g_slist_nth_data(tokens, 0);\r
-                                       if (NULL != line_token) {\r
-                                               resp_stored_msg_cnt.storedMsgCnt.indexList[ctr_loop] = atoi(line_token);\r
-                                               resp_stored_msg_cnt.result = SMS_SENDSMS_SUCCESS;\r
-                                       } else {\r
-                                               dbg("line_token of gslist_line [%d] is NULL", ctr_loop);\r
-                                               continue;\r
-                                       }\r
-                                       tcore_at_tok_free(tokens);\r
-                               } else {\r
-                                       dbg("gslist_line [%d] is NULL", ctr_loop);\r
-                                       continue;\r
-                               }\r
-                       }\r
-               } else {\r
-                       dbg("No lines.");\r
-                       if (resp_stored_msg_cnt_prev->storedMsgCnt.usedCount == 0) { // Check if used count is zero\r
-                               resp_stored_msg_cnt.result = SMS_SENDSMS_SUCCESS;\r
-                       }\r
-               }\r
-       } else {\r
-               dbg("Respnose NOK");\r
-       }\r
-\r
-       resp_stored_msg_cnt.storedMsgCnt.totalCount = resp_stored_msg_cnt_prev->storedMsgCnt.totalCount;\r
-       resp_stored_msg_cnt.storedMsgCnt.usedCount = resp_stored_msg_cnt_prev->storedMsgCnt.usedCount;\r
-\r
-       util_sms_free_memory(resp_stored_msg_cnt_prev);\r
-\r
-       dbg("total: [%d], used: [%d], result: [%d]", resp_stored_msg_cnt.storedMsgCnt.totalCount, resp_stored_msg_cnt.storedMsgCnt.usedCount, resp_stored_msg_cnt.result);\r
-       for (ctr_loop = 0; ctr_loop < gslist_line_count; ctr_loop++) {\r
-               dbg("index: [%d]", resp_stored_msg_cnt.storedMsgCnt.indexList[ctr_loop]);\r
-       }\r
-\r
-       tcore_user_request_send_response(user_req, TRESP_SMS_GET_STORED_MSG_COUNT, sizeof(resp_stored_msg_cnt), &resp_stored_msg_cnt);\r
-\r
-       dbg("Exit");\r
-       return;\r
-}\r
-\r
-static void on_response_get_stored_msg_cnt(TcorePending *pending, int data_len, const void *data, void *user_data)\r
-{\r
-       UserRequest *ur = NULL, *ur_dup = NULL;\r
-       struct tresp_sms_get_storedMsgCnt *respStoredMsgCnt = NULL;\r
-       const TcoreATResponse *atResp = data;\r
-       GSList *tokens=NULL;\r
-       char *line = NULL , *pResp = NULL , *cmd_str = NULL;\r
-       TcoreATRequest *atReq = NULL;\r
-       int usedCnt = 0, totalCnt = 0, result = 0;\r
-\r
-       TcorePending *pending_new = NULL;\r
-       CoreObject *o = NULL;\r
-\r
-       dbg("Entered");\r
-\r
-       respStoredMsgCnt = malloc(sizeof(struct tresp_sms_get_storedMsgCnt));\r
-\r
-       ur = tcore_pending_ref_user_request(pending);\r
-       ur_dup = tcore_user_request_ref(ur);\r
-       o = tcore_pending_ref_core_object(pending);\r
-\r
-       if (atResp->success > 0) {\r
-               dbg("Response OK");\r
-               if (NULL != atResp->lines) {\r
-                       line = (char *)atResp->lines->data;\r
-                       dbg("line is %s",line);\r
-\r
-                       tokens = tcore_at_tok_new(line);\r
-                       pResp = g_slist_nth_data(tokens, 0);\r
-\r
-                       if (pResp) {\r
-                               usedCnt =atoi(pResp);\r
-                               dbg("used cnt is %d",usedCnt);\r
-                       }\r
-\r
-                       pResp = g_slist_nth_data(tokens, 1);\r
-                       if (pResp) {\r
-                               totalCnt =atoi(pResp);\r
-                               result = SMS_SENDSMS_SUCCESS;\r
-\r
-                               respStoredMsgCnt->storedMsgCnt.usedCount = usedCnt;\r
-                               respStoredMsgCnt->storedMsgCnt.totalCount = totalCnt;\r
-                               respStoredMsgCnt->result = result;\r
-\r
-                               dbg("used %d, total %d, result %d",usedCnt, totalCnt,result);\r
-\r
-                               pending_new = tcore_pending_new(o, 0);\r
-                               //Get all messages information\r
-                               cmd_str = g_strdup_printf("AT+CMGL=4");\r
-                               atReq = tcore_at_request_new((const char *)cmd_str, "+CMGL", TCORE_AT_MULTILINE);\r
-\r
-                               dbg("cmd str is %s",cmd_str);\r
-\r
-                               tcore_pending_set_request_data(pending_new, 0,atReq);\r
-                               tcore_pending_set_response_callback(pending_new, on_response_get_msg_indices, (void *)respStoredMsgCnt);\r
-                               tcore_pending_link_user_request(pending_new, ur_dup);\r
-                               tcore_pending_set_send_callback(pending_new, on_confirmation_sms_message_send, NULL);\r
-                               tcore_hal_send_request(tcore_object_get_hal(o), pending_new);\r
-                               \r
-                               //free the consumed token\r
-                               tcore_at_tok_free(tokens);\r
-                       \r
-                               g_free(cmd_str);\r
-\r
-                               dbg("Exit");\r
-                               return;\r
-\r
-                       }\r
-                       //free the consumed token\r
-                       tcore_at_tok_free(tokens);\r
-               } else {\r
-                       dbg("No data");\r
-                       result = SMS_DEVICE_FAILURE;\r
-               }\r
-       }\r
-\r
-       err("Response NOK");\r
-\r
-       dbg("Exit");\r
-       return;\r
-}\r
-\r
-static void on_response_get_sca(TcorePending *pending, int data_len, const void *data, void *user_data)\r
-{\r
-       const TcoreATResponse *at_response = data;\r
-       struct tresp_sms_get_sca respGetSca;\r
-       UserRequest *user_req = NULL;\r
-\r
-       GSList *tokens = NULL;\r
-       char *gslist_line = NULL, *sca_addr = NULL, *sca_toa = NULL;\r
-\r
-       dbg("Entry");\r
-\r
-       memset(&respGetSca, 0, sizeof(respGetSca));\r
-       respGetSca.result = SMS_DEVICE_FAILURE;\r
-\r
-       user_req = tcore_pending_ref_user_request(pending);\r
-\r
-       if (at_response->success) {\r
-               dbg("Response OK");\r
-               if (at_response->lines) {\r
-                       gslist_line = (char *)at_response->lines->data;\r
-\r
-                       tokens = tcore_at_tok_new(gslist_line);\r
-                       sca_addr = g_slist_nth_data(tokens, 0);\r
-                       sca_toa = g_slist_nth_data(tokens, 1);\r
-\r
-                       if ((NULL != sca_addr)\r
-                               && (NULL != sca_toa)) {\r
-                               dbg("sca_addr: [%s]. sca_toa: [%s]", sca_addr, sca_toa);\r
-\r
-                               respGetSca.scaAddress.dialNumLen = strlen(sca_addr);\r
-\r
-                               if (145 == atoi(sca_toa)) {\r
-                                       respGetSca.scaAddress.typeOfNum = SIM_TON_INTERNATIONAL;\r
-                               } else {\r
-                                       respGetSca.scaAddress.typeOfNum = SIM_TON_NATIONAL;\r
-                               }\r
-\r
-                               respGetSca.scaAddress.numPlanId = 0;\r
-\r
-                               memcpy(respGetSca.scaAddress.diallingNum, sca_addr, strlen(sca_addr));\r
-\r
-                               dbg("len [%d], sca_addr [%s], TON [%d], NPI [%d]", respGetSca.scaAddress.dialNumLen, respGetSca.scaAddress.diallingNum, respGetSca.scaAddress.typeOfNum, respGetSca.scaAddress.numPlanId);\r
-\r
-                               respGetSca.result = SMS_SENDSMS_SUCCESS;\r
-                       } else {\r
-                               err("sca_addr OR sca_toa NULL");\r
-                       }\r
-               } else {\r
-                       dbg("NO Lines");\r
-               }\r
-       } else {\r
-               dbg("Response NOK");\r
-       }\r
-\r
-       tcore_user_request_send_response(user_req, TRESP_SMS_GET_SCA, sizeof(respGetSca), &respGetSca);\r
-\r
-       if(tokens)\r
-               tcore_at_tok_free(tokens);\r
-\r
-       dbg("Exit");\r
-       return;\r
-}\r
-\r
-static void on_response_set_sca(TcorePending *pending, int data_len, const void *data, void *user_data)\r
-{\r
-       /*\r
-       Response is expected in this format\r
-       OK\r
-               or\r
-       +CMS ERROR: <err>\r
-       */\r
-\r
-       //CoreObject *obj = user_data;\r
-       UserRequest *ur;\r
-       //copies the AT response data to resp\r
-       const TcoreATResponse *atResp = data;\r
-       struct tresp_sms_set_sca respSetSca;\r
-\r
-       memset(&respSetSca, 0, sizeof(struct tresp_sms_set_sca));\r
-\r
-       ur = tcore_pending_ref_user_request(pending);\r
-       if (!ur) {\r
-               dbg("no user_request");\r
-               return;\r
-       }\r
-\r
-       if (atResp->success > 0) {\r
-               dbg("RESPONSE OK");\r
-               respSetSca.result = SMS_SUCCESS;\r
-       } else {\r
-               dbg("RESPONSE NOK");\r
-               respSetSca.result = SMS_DEVICE_FAILURE;\r
-       }\r
-\r
-       tcore_user_request_send_response(ur, TRESP_SMS_SET_SCA, sizeof(struct tresp_sms_set_sca), &respSetSca);\r
-\r
-       return;\r
-}\r
-\r
-static void on_response_get_cb_config(TcorePending *p, int data_len, const void *data, void *user_data)\r
-{\r
-       UserRequest *ur;\r
-       struct tresp_sms_get_cb_config respGetCbConfig;\r
-       const TcoreATResponse *atResp = data;\r
-       GSList *tokens=NULL;\r
-       int i = 0, mode =0;\r
-       char *mid = NULL, *pResp = NULL, *line = NULL, *res = NULL;\r
-       char delim[] = ",";\r
-\r
-       memset(&respGetCbConfig, 0, sizeof(struct tresp_sms_get_cb_config));\r
-       respGetCbConfig.result = SMS_DEVICE_FAILURE;\r
-       \r
-       ur = tcore_pending_ref_user_request(p);\r
-       if (!ur) {\r
-               dbg("no user_request");\r
-               return;\r
-       }\r
-\r
-       respGetCbConfig.cbConfig.net3gppType = SMS_NETTYPE_3GPP;\r
-\r
-       if (atResp->success) {\r
-               dbg("Response OK");\r
-               if (atResp->lines) {\r
-                       line = (char*)atResp->lines->data;\r
-                       if (line != NULL) {\r
-                               dbg("line is %s",line);\r
-                               tokens = tcore_at_tok_new(line);\r
-                               pResp = g_slist_nth_data(tokens, 0);\r
-                               if (pResp) {\r
-                                       mode = atoi(pResp);\r
-                                       respGetCbConfig.cbConfig.cbEnabled = mode;\r
-\r
-                                       pResp = g_slist_nth_data(tokens, 1);\r
-                                       if (pResp) {\r
-                                               mid = strtok(pResp, delim);\r
-                                               i = 0;\r
-                                               while ( res != NULL ) {\r
-                                                       res = strtok( NULL, delim );\r
-                                                       dbg("mid is %s%s\n", mid,res);\r
-                                                       if (res != NULL) {\r
-                                                               if (strlen(res) >0) {\r
-                                                                       respGetCbConfig.cbConfig.msgIDs[i].net3gpp.fromMsgId = atoi(res);\r
-                                                                       respGetCbConfig.cbConfig.msgIDs[i].net3gpp.toMsgId = atoi(res);\r
-                                                                       respGetCbConfig.cbConfig.msgIDs[i].net3gpp.selected = TRUE;\r
-                                                                       i++;\r
-                                                                       respGetCbConfig.result = SMS_SENDSMS_SUCCESS;\r
-                                                               }\r
-                                                       }\r
-                                               }\r
-                                               \r
-                                               respGetCbConfig.cbConfig.msgIdRangeCount = i;\r
-\r
-                                       }else {\r
-                                               if (mode == 1) {\r
-                                                       respGetCbConfig.cbConfig.msgIdRangeCount = 1;\r
-                                                       respGetCbConfig.cbConfig.msgIDs[0].net3gpp.fromMsgId = 0x0000;\r
-                                                       respGetCbConfig.cbConfig.msgIDs[0].net3gpp.toMsgId = 0xFFFF;\r
-                                                       respGetCbConfig.cbConfig.msgIDs[0].net3gpp.selected = TRUE;\r
-                                                       respGetCbConfig.result = SMS_SENDSMS_SUCCESS;\r
-                                               } else {\r
-                                                       respGetCbConfig.cbConfig.msgIdRangeCount = 0;\r
-                                                       respGetCbConfig.cbConfig.msgIDs[0].net3gpp.selected = FALSE;\r
-                                                       respGetCbConfig.result = SMS_SENDSMS_SUCCESS;\r
-                                               }\r
-                                       }\r
-                               }                       \r
-                       } else {\r
-                                       dbg("line is NULL");\r
-                       }\r
-               } else {\r
-                       dbg("atresp->lines is NULL");\r
-               }\r
-       } else {\r
-               dbg("RESPONSE NOK");\r
-       }\r
-\r
-       tcore_user_request_send_response(ur, TRESP_SMS_GET_CB_CONFIG, sizeof(struct tresp_sms_get_cb_config), &respGetCbConfig);\r
-\r
-       if(tokens)\r
-               tcore_at_tok_free(tokens);\r
-       \r
-       return;\r
-}\r
-\r
-static void on_response_set_cb_config(TcorePending *pending, int data_len, const void *data, void *user_data)\r
-{\r
-       /*\r
-       Response is expected in this format\r
-       OK\r
-               or\r
-       +CMS ERROR: <err>\r
-       */\r
-\r
-       UserRequest *ur;\r
-       const TcoreATResponse *resp = data;\r
-       int response = 0;\r
-       const char *line = NULL;\r
-       GSList *tokens=NULL;\r
-\r
-       struct tresp_sms_set_cb_config respSetCbConfig = {0,};\r
-\r
-       memset(&respSetCbConfig, 0, sizeof(struct tresp_sms_set_cb_config));\r
-\r
-       ur = tcore_pending_ref_user_request(pending);\r
-       respSetCbConfig.result = SMS_SENDSMS_SUCCESS;\r
-       \r
-       if (resp->success > 0) {\r
-               dbg("RESPONSE OK");\r
-       } else {\r
-               dbg("RESPONSE NOK");\r
-               line = (const char*)resp->final_response;\r
-               tokens = tcore_at_tok_new(line);\r
-\r
-               if (g_slist_length(tokens) < 1) {\r
-                       dbg("err cause not specified or string corrupted");\r
-                       respSetCbConfig.result = SMS_DEVICE_FAILURE;\r
-               } else {\r
-                       response = atoi(g_slist_nth_data(tokens, 0));\r
-                       /* TODO: CMEE error mapping is required. */\r
-                       respSetCbConfig.result = SMS_DEVICE_FAILURE;\r
-               }\r
-       }\r
-       if (!ur) {\r
-               dbg("no user_request");\r
-               return;\r
-       }\r
-\r
-       tcore_user_request_send_response(ur, TRESP_SMS_SET_CB_CONFIG, sizeof(struct tresp_sms_set_cb_config), &respSetCbConfig);\r
-\r
-       if(tokens)\r
-               tcore_at_tok_free(tokens);\r
-\r
-       return;\r
-}\r
-\r
-static void on_response_set_mem_status(TcorePending *p, int data_len, const void *data, void *user_data)\r
-{\r
-       UserRequest *ur;\r
-       struct tresp_sms_set_mem_status respSetMemStatus = {0,};\r
-       const TcoreATResponse *resp = data;\r
-\r
-       memset(&respSetMemStatus, 0, sizeof(struct tresp_sms_set_mem_status));\r
-\r
-       if (resp->success > 0) {\r
-               dbg("RESPONSE OK");\r
-               respSetMemStatus.result = SMS_SENDSMS_SUCCESS;\r
-       } else {\r
-               dbg("RESPONSE NOK");\r
-               respSetMemStatus.result = SMS_DEVICE_FAILURE;\r
-       }\r
-\r
-       ur = tcore_pending_ref_user_request(p);\r
-       if (!ur) {\r
-               dbg("no user_request");\r
-               return;\r
-       }\r
-\r
-       tcore_user_request_send_response(ur, TRESP_SMS_SET_MEM_STATUS, sizeof(struct tresp_sms_set_mem_status), &respSetMemStatus);\r
-\r
-       return;\r
-}\r
-\r
-static void on_response_set_msg_status(TcorePending *pending, int data_len, const void *data, void *user_data)\r
-{\r
-       UserRequest *ur;\r
-       struct tresp_sms_set_msg_status respMsgStatus = {0, };\r
-       const TcoreATResponse *atResp = data;\r
-       int response = 0, sw1 = 0, sw2 = 0;\r
-       const char *line = NULL;\r
-       char *pResp = NULL;\r
-       GSList *tokens = NULL;\r
-\r
-       dbg("Entry");\r
-\r
-       memset(&respMsgStatus, 0, sizeof(struct tresp_sms_set_msg_status));\r
-       respMsgStatus.result = SMS_DEVICE_FAILURE;\r
-\r
-       ur = tcore_pending_ref_user_request(pending);\r
-\r
-       if (atResp->success > 0) {\r
-               dbg("RESPONSE OK");\r
-\r
-               if (atResp->lines) {\r
-                       line = (const char *) atResp->lines->data;\r
-                       tokens = tcore_at_tok_new(line);\r
-                       pResp = g_slist_nth_data(tokens, 0);\r
-                       if (pResp != NULL) {\r
-                               sw1 = atoi(pResp);\r
-                       } else {\r
-                               dbg("sw1 is NULL");\r
-                       }\r
-                       pResp = g_slist_nth_data(tokens, 1);\r
-                       if (pResp != NULL) {\r
-                               sw2 = atoi(pResp);\r
-                               if ((sw1 == AT_SW1_SUCCESS) && (sw2 == 0)) {\r
-                                       respMsgStatus.result = SMS_SENDSMS_SUCCESS;\r
-                               }\r
-                       } else {\r
-                               dbg("sw2 is NULL");\r
-                       }\r
-                       pResp = g_slist_nth_data(tokens, 3);\r
-\r
-                       if (pResp != NULL) {\r
-                               response = atoi(pResp);\r
-                               dbg("response is %s", response);\r
-                       }\r
-               } else {\r
-                       dbg("No lines");\r
-               }\r
-       } else {\r
-               dbg("RESPONSE NOK");\r
-       }\r
-\r
-        tcore_user_request_send_response(ur, TRESP_SMS_SET_MSG_STATUS , sizeof(struct tresp_sms_set_msg_status), &respMsgStatus);\r
-\r
-       if(tokens)\r
-               tcore_at_tok_free(tokens);\r
-       \r
-       dbg("Exit");\r
-       return;\r
-}\r
-\r
-static void on_response_get_sms_params(TcorePending *pending, int data_len, const void *data, void *user_data)\r
-{\r
-       UserRequest *ur;\r
-       struct tresp_sms_get_params respGetParams ;\r
-       const TcoreATResponse *atResp = data;\r
-       int sw1 = 0, sw2 = 0;\r
-       const char *line = NULL;\r
-       char *pResp = NULL;\r
-       GSList *tokens=NULL;\r
-       char *hexData = NULL;\r
-    char *recordData = NULL;\r
-    int i = 0;\r
-\r
-       memset(&respGetParams, 0, sizeof(struct tresp_sms_get_params));\r
-       respGetParams.result = SMS_DEVICE_FAILURE;\r
-\r
-       ur = tcore_pending_ref_user_request(pending);\r
-\r
-       if (atResp->success > 0) {\r
-               dbg("RESPONSE OK");\r
-\r
-               if (atResp->lines) {\r
-                       line = (const char *) atResp->lines->data;\r
-                       tokens = tcore_at_tok_new(line);\r
-                       pResp = g_slist_nth_data(tokens, 0);\r
-                       if (pResp != NULL) {\r
-                               sw1 = atoi(pResp);\r
-                               dbg("sw1 is %d", sw1);\r
-                       } else {\r
-                               dbg("sw1 is NULL");\r
-                       }\r
-                       pResp = g_slist_nth_data(tokens, 1);\r
-                       if (pResp != NULL) {\r
-                               sw2 = atoi(pResp);\r
-                               dbg("sw2 is %d", sw2);\r
-                               if ((sw1 == 0x90 && sw2 == 0x00) || sw1 == 0x91) {\r
-                                       respGetParams.result = SMS_SENDSMS_SUCCESS;\r
-                               }\r
-                       } else {\r
-                               dbg("sw2 is NULL");\r
-                       }\r
-                       pResp = g_slist_nth_data(tokens, 2);\r
-                       if (pResp != NULL) {\r
-                               hexData = util_removeQuotes(pResp);\r
-\r
-                               recordData = util_hexStringToBytes(hexData);\r
-                               util_hex_dump("    ", strlen(hexData) / 2, recordData);\r
-\r
-                               respGetParams.paramsInfo.recordLen = strlen(hexData) / 2;\r
-\r
-                               util_sms_decode_smsParameters((unsigned char *) recordData, strlen(hexData) / 2, &(respGetParams.paramsInfo));\r
-                               respGetParams.result = SMS_SENDSMS_SUCCESS;\r
-\r
-                               for (i = 0; i < (int) respGetParams.paramsInfo.tpSvcCntrAddr.dialNumLen; i++)\r
-                                       dbg("SCAddr = %d [%02x]", i, respGetParams.paramsInfo.tpSvcCntrAddr.diallingNum[i]);\r
-\r
-                               free(recordData);\r
-                               free(hexData);\r
-                       } else {\r
-                               dbg("No response");\r
-                       }\r
-                       tcore_at_tok_free(tokens);\r
-               }\r
-       } else {\r
-               dbg("RESPONSE NOK");\r
-       }\r
-\r
-       tcore_user_request_send_response(ur, TRESP_SMS_GET_PARAMS, sizeof(struct tresp_sms_get_params), &respGetParams);\r
-\r
-       dbg("Exit");\r
-       return;\r
-}\r
-\r
-static void on_response_set_sms_params(TcorePending *pending, int data_len, const void *data, void *user_data)\r
-{\r
-       UserRequest *ur;\r
-       struct tresp_sms_set_params respSetParams = {0, };\r
-       const TcoreATResponse *atResp = data;\r
-       int sw1 =0 , sw2 = 0;\r
-       const char *line = NULL;\r
-       char *pResp = NULL;\r
-       GSList *tokens=NULL;\r
-\r
-\r
-       memset(&respSetParams, 0, sizeof(struct tresp_sms_set_params));\r
-       ur = tcore_pending_ref_user_request(pending);\r
-\r
-       respSetParams.result = SMS_DEVICE_FAILURE;\r
-\r
-       if (atResp->success > 0) {\r
-               dbg("RESPONSE OK");\r
-\r
-               if (atResp->lines) {\r
-                       line = (const char *) atResp->lines->data;\r
-                       tokens = tcore_at_tok_new(line);\r
-                       pResp = g_slist_nth_data(tokens, 0);\r
-                       if (pResp != NULL) {\r
-                               sw1 = atoi(pResp);\r
-                       } else {\r
-                               dbg("sw1 is NULL");\r
-                       }\r
-\r
-                       pResp = g_slist_nth_data(tokens, 1);\r
-                       if (pResp != NULL) {\r
-                               sw2 = atoi(pResp);\r
-                               if (((sw1 == AT_SW1_SUCCESS) && (sw2 == AT_SW2_SUCCESS)) || (sw1 == 0x91)) {\r
-                                       respSetParams.result = SMS_SENDSMS_SUCCESS;\r
-                               }\r
-                       } else {\r
-                               dbg("sw2 is NULL");\r
-                       }\r
-               } else {\r
-                       dbg("No lines");\r
-               }\r
-       } else {\r
-               dbg("RESPONSE NOK");\r
-       }\r
-\r
-       tcore_user_request_send_response(ur, TRESP_SMS_SET_PARAMS , sizeof(struct tresp_sms_set_params), &respSetParams);\r
-\r
-       if(tokens)\r
-               tcore_at_tok_free(tokens);\r
-               \r
-       dbg("Exit");\r
-       return;\r
-}\r
-\r
-static void on_response_get_paramcnt(TcorePending *p, int data_len, const void *data, void *user_data)\r
-{\r
-       UserRequest *ur = NULL;\r
-       struct tresp_sms_get_paramcnt respGetParamCnt = {0, };\r
-       const TcoreATResponse *atResp = data;\r
-       char *line = NULL , *pResp = NULL;\r
-       int sw1 = 0 , sw2 = 0, *smsp_record_len = NULL;\r
-       int sim_type = 0;\r
-       GSList *tokens=NULL;\r
-       CoreObject *co_sim = NULL;  //need this to get the sim type GSM/USIM\r
-       TcorePlugin *plugin = NULL;\r
-\r
-       dbg("Entry");\r
-\r
-       ur = tcore_pending_ref_user_request(p);\r
-       respGetParamCnt.result = SMS_DEVICE_FAILURE;\r
-\r
-       if (atResp->success > 0) {\r
-               dbg("RESPONSE OK");\r
-\r
-               if (atResp->lines) {\r
-                       line = (char *) atResp->lines->data;\r
-\r
-                       dbg("line is %s", line);\r
-\r
-                       tokens = tcore_at_tok_new(line);\r
-                       pResp = g_slist_nth_data(tokens, 0);\r
-                       if (pResp != NULL) {\r
-                               sw1 = atoi(pResp);\r
-                       } else {\r
-                               dbg("sw1 is NULL");\r
-                       }\r
-                       pResp = g_slist_nth_data(tokens, 1);\r
-                       if (pResp != NULL) {\r
-                               sw2 = atoi(pResp);\r
-                               if ((sw1 == 144) && (sw2 == 0)) {\r
-                                       respGetParamCnt.result = SMS_SENDSMS_SUCCESS;\r
-                               }\r
-                       } else {\r
-                               dbg("sw2 is NULL");\r
-                       }\r
-                       pResp = g_slist_nth_data(tokens, 2);\r
-                       if (pResp != NULL) {\r
-                               char *hexData = NULL;\r
-                               char *recordData = NULL;\r
-                               hexData = util_removeQuotes(pResp);\r
-\r
-                               /*1. SIM access success case*/\r
-                               if ((sw1 == 0x90 && sw2 == 0x00) || sw1 == 0x91) {\r
-                                       unsigned char tag_len = 0; /*   1 or 2 bytes ??? */\r
-                                       int record_len = 0;\r
-                                       char num_of_records = 0;\r
-                                       unsigned char file_id_len = 0;\r
-                                       unsigned short file_id = 0;\r
-                                       unsigned short file_size = 0;\r
-                                       unsigned short file_type = 0;\r
-                                       unsigned short arr_file_id = 0;\r
-                                       int arr_file_id_rec_num = 0;\r
-\r
-                                       /*      handling only last 3 bits */\r
-                                       unsigned char file_type_tag = 0x07;\r
-                                       unsigned char *ptr_data;\r
-\r
-                                       recordData = util_hexStringToBytes(hexData);\r
-                                       util_hex_dump("    ", strlen(hexData)/2, recordData);\r
-\r
-                                       ptr_data = (unsigned char *)recordData;\r
-\r
-                                       co_sim = tcore_plugin_ref_core_object(tcore_pending_ref_plugin(p), "sim");\r
-                                       sim_type = tcore_sim_get_type(co_sim);\r
-                                       dbg("sim type is %d",sim_type);\r
-\r
-                                       if (sim_type ==  SIM_TYPE_USIM) {\r
-                                               /*\r
-                                                ETSI TS 102 221 v7.9.0\r
-                                                       - Response Data\r
-                                                        '62'   FCP template tag\r
-                                                        - Response for an EF\r
-                                                        '82'   M       File Descriptor\r
-                                                        '83'   M       File Identifier\r
-                                                       'A5'    O       Proprietary information\r
-                                                        '8A'   M       Life Cycle Status Integer\r
-                                                        '8B', '8C' or 'AB'     C1      Security attributes\r
-                                                       '80'    M       File size\r
-                                                        '81'   O       Total file size\r
-                                                        '88'   O       Short File Identifier (SFI)\r
-                                               */\r
-\r
-                                               /* rsim.res_len  has complete data length received  */\r
-\r
-                                               /* FCP template tag - File Control Parameters tag*/\r
-                                               if (*ptr_data == 0x62) {\r
-                                                       /* parse complete FCP tag*/\r
-                                                       /* increment to next byte */\r
-                                                       ptr_data++;\r
-                                                       tag_len = *ptr_data++;\r
-                                                       /* FCP file descriptor - file type, accessibility, DF, ADF etc*/\r
-                                                       if (*ptr_data == 0x82) {\r
-                                                                       /* increment to next byte */\r
-                                                                       ptr_data++;\r
-                                                                       /*2 or 5 value*/\r
-                                                                       ptr_data++;\r
-                                                       /*      unsigned char file_desc_len = *ptr_data++;*/\r
-                                                       /*      dbg("file descriptor length: [%d]", file_desc_len);*/\r
-                                                       /* TBD:  currently capture only file type : ignore sharable, non sharable, working, internal etc*/\r
-                                                       /* consider only last 3 bits*/\r
-                                                       file_type_tag = file_type_tag & (*ptr_data);\r
-\r
-                                                       switch (file_type_tag) {\r
-                                                               /* increment to next byte */\r
-                                                               ptr_data++;\r
-\r
-                                                               case 0x1:\r
-                                                                       dbg("Getting FileType: [Transparent file type]");\r
-                                                                       /* increment to next byte */\r
-                                                                       ptr_data++;\r
-                                                                       file_type = 0x01;       //SIM_FTYPE_TRANSPARENT\r
-                                                                       /*      data coding byte - value 21 */\r
-                                                                       ptr_data++;\r
-                                                                       break;\r
-\r
-                                                               case 0x2:\r
-                                                                       dbg("Getting FileType: [Linear fixed file type]");\r
-                                                                       /* increment to next byte */\r
-                                                                       ptr_data++;\r
-                                                                       /*      data coding byte - value 21 */\r
-                                                                       ptr_data++;\r
-                                                                       /*      2bytes */\r
-                                                                       memcpy(&record_len, ptr_data, 2);\r
-                                                                       /* swap bytes */\r
-                                                                       record_len = SMS_SWAPBYTES16(record_len);\r
-                                                                       ptr_data = ptr_data + 2;\r
-                                                                       num_of_records = *ptr_data++;\r
-                                                                       /* Data lossy conversation from enum (int) to unsigned char */\r
-                                                                       file_type = 0x02;       // SIM_FTYPE_LINEAR_FIXED\r
-                                                                       break;\r
-\r
-                                                               case 0x6:\r
-                                                                       dbg(" Cyclic fixed file type");\r
-                                                                       /* increment to next byte */\r
-                                                                       ptr_data++;\r
-                                                                       /*      data coding byte - value 21 */\r
-                                                                       ptr_data++;\r
-                                                                       /*      2bytes */\r
-                                                                       memcpy(&record_len, ptr_data, 2);\r
-                                                                       /* swap bytes  */\r
-                                                                       record_len = SMS_SWAPBYTES16(record_len);\r
-                                                                       ptr_data = ptr_data + 2;\r
-                                                                       num_of_records = *ptr_data++;\r
-                                                                       file_type = 0x04;       //SIM_FTYPE_CYCLIC\r
-                                                                       break;\r
-\r
-                                                               default:\r
-                                                                       dbg("not handled file type [0x%x]", *ptr_data);\r
-                                                                       break;\r
-                                                               }\r
-                                                       } else {\r
-                                                               dbg("INVALID FCP received - DEbug!");\r
-                                                               tcore_at_tok_free(tokens);\r
-                                                               return;\r
-                                                       }\r
-\r
-                                                       /*File identifier - file id?? */ // 0x84,0x85,0x86 etc are currently ignored and not handled\r
-                                                       if (*ptr_data == 0x83) {\r
-                                                               /* increment to next byte */\r
-                                                               ptr_data++;\r
-                                                               file_id_len = *ptr_data++;\r
-                                                               memcpy(&file_id, ptr_data, file_id_len);\r
-                                                               /* swap bytes    */\r
-                                                               file_id = SMS_SWAPBYTES16(file_id);\r
-                                                               ptr_data = ptr_data + 2;\r
-                                                               dbg("Getting FileID=[0x%x]", file_id);\r
-                                                       } else {\r
-                                                               dbg("INVALID FCP received - DEbug!");\r
-                                                               free(hexData);\r
-                                                               free(recordData);\r
-                                                               tcore_at_tok_free(tokens);\r
-                                                               return;\r
-                                                       }\r
-\r
-                                                       /*      proprietary information  */\r
-                                                       if (*ptr_data == 0xA5) {\r
-                                                               unsigned short prop_len;\r
-                                                               /* increment to next byte */\r
-                                                               ptr_data++;\r
-                                                               /* length */\r
-                                                               prop_len = *ptr_data;\r
-                                                               /* skip data */\r
-                                                               ptr_data = ptr_data + prop_len + 1;\r
-                                                       } else {\r
-                                                               dbg("INVALID FCP received - DEbug!");\r
-                                                       }\r
-\r
-                                                       /* life cycle status integer [8A][length:0x01][status]*/\r
-                                                       /*\r
-                                                        status info b8~b1\r
-                                                        00000000 : No information given\r
-                                                        00000001 : creation state\r
-                                                        00000011 : initialization state\r
-                                                        000001-1 : operation state -activated\r
-                                                        000001-0 : operation state -deactivated\r
-                                                        000011-- : Termination state\r
-                                                        b8~b5 !=0, b4~b1=X : Proprietary\r
-                                                        Any other value : RFU\r
-                                                        */\r
-                                                       if (*ptr_data == 0x8A) {\r
-                                                               /* increment to next byte */\r
-                                                               ptr_data++;\r
-                                                               /* length - value 1 */\r
-                                                               ptr_data++;\r
-\r
-                                                               switch (*ptr_data) {\r
-                                                                       case 0x04:\r
-                                                                       case 0x06:\r
-                                                                               dbg("<IPC_RX> operation state -deactivated");\r
-                                                                               ptr_data++;\r
-                                                                               break;\r
-\r
-                                                                       case 0x05:\r
-                                                                       case 0x07:\r
-                                                                               dbg("<IPC_RX> operation state -activated");\r
-                                                                               ptr_data++;\r
-                                                                               break;\r
-\r
-                                                                       default:\r
-                                                                               dbg("<IPC_RX> DEBUG! LIFE CYCLE STATUS =[0x%x]",*ptr_data);\r
-                                                                               ptr_data++;\r
-                                                                               break;\r
-                                                               }\r
-                                                       }\r
-\r
-                                                       /* related to security attributes : currently not handled*/\r
-                                                       if (*ptr_data == 0x86 || *ptr_data == 0x8B || *ptr_data == 0x8C || *ptr_data == 0xAB) {\r
-                                                               /* increment to next byte */\r
-                                                               ptr_data++;\r
-                                                               /* if tag length is 3 */\r
-                                                               if (*ptr_data == 0x03) {\r
-                                                                       /* increment to next byte */\r
-                                                                       ptr_data++;\r
-                                                                       /* EFARR file id */\r
-                                                                       memcpy(&arr_file_id, ptr_data, 2);\r
-                                                                       /* swap byes */\r
-                                                                       arr_file_id = SMS_SWAPBYTES16(arr_file_id);\r
-                                                                       ptr_data = ptr_data + 2;\r
-                                                                       arr_file_id_rec_num = *ptr_data++;\r
-                                                               } else {\r
-                                                                       /* if tag length is not 3 */\r
-                                                                       /* ignoring bytes       */\r
-                                                                       //      ptr_data = ptr_data + 4;\r
-                                                                       dbg("Useless security attributes, so jump to next tag");\r
-                                                                       ptr_data = ptr_data + (*ptr_data + 1);\r
-                                                               }\r
-                                                       } else {\r
-                                                               dbg("INVALID FCP received[0x%x] - DEbug!", *ptr_data);\r
-                                                               free(hexData);\r
-                                                               free(recordData);\r
-                                                               tcore_at_tok_free(tokens);\r
-                                                               return;\r
-                                                       }\r
-\r
-                                                       dbg("Current ptr_data value is [%x]", *ptr_data);\r
-\r
-                                                       /* file size excluding structural info*/\r
-                                                       if (*ptr_data == 0x80) {\r
-                                                               /* for EF file size is body of file and for Linear or cyclic it is\r
-                                                                * number of recXsizeof(one record)\r
-                                                                */\r
-                                                               /* increment to next byte */\r
-                                                               ptr_data++;\r
-                                                               /* length is 1 byte - value is 2 bytes or more */\r
-                                                               ptr_data++;\r
-                                                               memcpy(&file_size, ptr_data, 2);\r
-                                                               /* swap bytes */\r
-                                                               file_size = SMS_SWAPBYTES16(file_size);\r
-                                                               ptr_data = ptr_data + 2;\r
-                                                       } else {\r
-                                                               dbg("INVALID FCP received - DEbug!");\r
-                                                               free(hexData);\r
-                                                               free(recordData);\r
-                                                               tcore_at_tok_free(tokens);\r
-                                                               return;\r
-                                                       }\r
-\r
-                                                       /* total file size including structural info*/\r
-                                                       if (*ptr_data == 0x81) {\r
-                                                               int len;\r
-                                                               /* increment to next byte */\r
-                                                               ptr_data++;\r
-                                                               /* length */\r
-                                                               len = *ptr_data;\r
-                                                               /* ignored bytes */\r
-                                                               ptr_data = ptr_data + 3;\r
-                                                       } else {\r
-                                                               dbg("INVALID FCP received - DEbug!");\r
-                                                               /* 0x81 is optional tag?? check out! so do not return -1 from here! */\r
-                                                               /* return -1; */\r
-                                                       }\r
-                                                       /*short file identifier ignored*/\r
-                                                       if (*ptr_data == 0x88) {\r
-                                                               dbg("0x88: Do Nothing");\r
-                                                               /*DO NOTHING*/\r
-                                                       }\r
-                                               } else {\r
-                                                       dbg("INVALID FCP received - DEbug!");\r
-                                                       free(hexData);\r
-                                                       free(recordData);\r
-                                                       tcore_at_tok_free(tokens);\r
-                                                       return;\r
-                                               }\r
-                                       } else if (sim_type == SIM_TYPE_GSM) {\r
-                                               unsigned char gsm_specific_file_data_len = 0;\r
-                                               /*      ignore RFU byte1 and byte2 */\r
-                                               ptr_data++;\r
-                                               ptr_data++;\r
-                                               /*      file size */\r
-                                               //file_size = p_info->response_len;\r
-                                               memcpy(&file_size, ptr_data, 2);\r
-                                               /* swap bytes */\r
-                                               file_size = SMS_SWAPBYTES16(file_size);\r
-                                               /*      parsed file size */\r
-                                               ptr_data = ptr_data + 2;\r
-                                               /*  file id  */\r
-                                               memcpy(&file_id, ptr_data, 2);\r
-                                               file_id = SMS_SWAPBYTES16(file_id);\r
-                                               dbg(" FILE id --> [%x]", file_id);\r
-                                               ptr_data = ptr_data + 2;\r
-                                               /* save file type - transparent, linear fixed or cyclic */\r
-                                               file_type_tag = (*(ptr_data + 7));\r
-\r
-                                               switch (*ptr_data) {\r
-                                                       case 0x0:\r
-                                                               /* RFU file type */\r
-                                                               dbg(" RFU file type- not handled - Debug!");\r
-                                                               break;\r
-\r
-                                                       case 0x1:\r
-                                                               /* MF file type */\r
-                                                               dbg(" MF file type - not handled - Debug!");\r
-                                                               break;\r
-\r
-                                                       case 0x2:\r
-                                                               /* DF file type */\r
-                                                               dbg(" DF file type - not handled - Debug!");\r
-                                                               break;\r
-\r
-                                                       case 0x4:\r
-                                                               /* EF file type */\r
-                                                               dbg(" EF file type [%d] ", file_type_tag);\r
-                                                               /*      increment to next byte */\r
-                                                               ptr_data++;\r
-\r
-                                                               if (file_type_tag == 0x00 || file_type_tag == 0x01) {\r
-                                                                       /* increament to next byte as this byte is RFU */\r
-                                                                       ptr_data++;\r
-                                                                       file_type =\r
-                                                                                       (file_type_tag == 0x00) ? 0x01 : 0x02; // SIM_FTYPE_TRANSPARENT:SIM_FTYPE_LINEAR_FIXED;\r
-                                                               } else {\r
-                                                                       /* increment to next byte */\r
-                                                                       ptr_data++;\r
-                                                                       /*      For a cyclic EF all bits except bit 7 are RFU; b7=1 indicates that */\r
-                                                                       /* the INCREASE command is allowed on the selected cyclic file. */\r
-                                                                       file_type = 0x04;       // SIM_FTYPE_CYCLIC;\r
-                                                               }\r
-                                                               /* bytes 9 to 11 give SIM file access conditions */\r
-                                                               ptr_data++;\r
-                                                               /* byte 10 has one nibble that is RF U and another for INCREASE which is not used currently */\r
-                                                               ptr_data++;\r
-                                                               /* byte 11 is invalidate and rehabilate nibbles */\r
-                                                               ptr_data++;\r
-                                                               /* byte 12 - file status */\r
-                                                               ptr_data++;\r
-                                                               /* byte 13 - GSM specific data */\r
-                                                               gsm_specific_file_data_len = *ptr_data;\r
-                                                               ptr_data++;\r
-                                                               /*      byte 14 - structure of EF - transparent or linear or cyclic , already saved above */\r
-                                                               ptr_data++;\r
-                                                               /* byte 15 - length of record for linear and cyclic , for transparent it is set to 0x00. */\r
-                                                               record_len = *ptr_data;\r
-                                                               dbg("record length[%d], file size[%d]", record_len, file_size);\r
-\r
-                                                               if (record_len != 0)\r
-                                                                       num_of_records = (file_size / record_len);\r
-\r
-                                                               dbg("Number of records [%d]", num_of_records);\r
-                                                               break;\r
-\r
-                                                       default:\r
-                                                               dbg(" not handled file type");\r
-                                                               break;\r
-                                               }\r
-                                       } else {\r
-                                               dbg(" Card Type - UNKNOWN  [%d]", sim_type);\r
-                                       }\r
-\r
-                                       dbg("EF[0x%x] size[%ld] Type[0x%x] NumOfRecords[%ld] RecordLen[%ld]", file_id, file_size, file_type, num_of_records, record_len);\r
-\r
-                                       respGetParamCnt.recordCount = num_of_records;\r
-                                       respGetParamCnt.result = SMS_SUCCESS;\r
-\r
-                                       //TO Store smsp record length in the property\r
-                                       plugin = tcore_pending_ref_plugin(p);\r
-                                       smsp_record_len = tcore_plugin_ref_property(plugin, "SMSPRECORDLEN");\r
-                                       memcpy(smsp_record_len, &record_len, sizeof(int));\r
-\r
-                                       free(recordData);\r
-                                       free(hexData);\r
-                               } else {\r
-                                       /*2. SIM access fail case*/\r
-                                       dbg("SIM access fail");\r
-                                       respGetParamCnt.result = SMS_UNKNOWN;\r
-                               }\r
-                       } else {\r
-                               dbg("presp is NULL");\r
-                       }\r
-               } else {\r
-                       dbg("line is blank");\r
-               }\r
-       } else {\r
-               dbg("RESPONSE NOK");\r
-       }\r
-\r
-       tcore_user_request_send_response(ur, TRESP_SMS_GET_PARAMCNT, sizeof(struct tresp_sms_get_paramcnt), &respGetParamCnt);\r
-\r
-       if(tokens)\r
-               tcore_at_tok_free(tokens);\r
-\r
-       dbg("Exit");\r
-       return;\r
-}\r
-\r
-static void _response_get_efsms_data(TcorePending *p, int data_len, const void *data, void *user_data)\r
-{\r
-       UserRequest *ur = NULL;\r
-       UserRequest *dup_ur = NULL;\r
-       struct tresp_sms_set_msg_status resp_msg_status = {0,};\r
-       const struct treq_sms_set_msg_status *req_msg_status = NULL ;\r
-\r
-       const TcoreATResponse *resp = data;\r
-       char *encoded_data = NULL;\r
-       char msg_status = 0;\r
-        char *pResp = NULL;\r
-        GSList *tokens=NULL;\r
-       const char *line = NULL;\r
-       int sw1 = 0;\r
-       int sw2 = 0;\r
-       \r
-       TcoreHal *hal = NULL;\r
-       TcoreATRequest *atreq = NULL;\r
-       TcorePending *pending = NULL;\r
-       gchar *cmd_str = NULL;\r
-\r
-       ur = tcore_pending_ref_user_request(p);\r
-\r
-       req_msg_status = tcore_user_request_ref_data(ur, NULL);\r
-\r
-       resp_msg_status.result = SMS_DEVICE_FAILURE;\r
-               \r
-       hal = tcore_object_get_hal(tcore_pending_ref_core_object(pending));\r
-       dbg("msgStatus: [%x], index [%x]", req_msg_status->msgStatus, req_msg_status->index);\r
-\r
-       if (resp->success <= 0) {\r
-               goto OUT;\r
-       }\r
-\r
-       {\r
-               dbg("RESPONSE OK");\r
-               if (resp->lines) {\r
-                       line = (const char *) resp->lines->data;\r
-                       tokens = tcore_at_tok_new(line);\r
-                       if (g_slist_length(tokens) != 3) {\r
-                               msg("invalid message");\r
-                               goto OUT;\r
-                       }\r
-               }\r
-               sw1 = atoi(g_slist_nth_data(tokens, 0));\r
-               sw2 = atoi(g_slist_nth_data(tokens, 1));\r
-               pResp = g_slist_nth_data(tokens, 2);\r
-\r
-               if ((sw1 == 0x90 && sw2 == 0x00) || sw1 == 0x91) {\r
-                       switch (req_msg_status->msgStatus) {\r
-                               case SMS_STATUS_READ:\r
-                                       msg_status = 0x01;\r
-                                       break;\r
-\r
-                               case SMS_STATUS_UNREAD:\r
-                                       msg_status = 0x03;\r
-                                       break;\r
-\r
-                               case SMS_STATUS_UNSENT:\r
-                                       msg_status = 0x07;\r
-                                       break;\r
-\r
-                               case SMS_STATUS_SENT:\r
-                                       msg_status = 0x05;\r
-                                       break;\r
-\r
-                               case SMS_STATUS_DELIVERED:\r
-                                       msg_status = 0x1D;\r
-                                       break;\r
-\r
-                               case SMS_STATUS_DELIVERY_UNCONFIRMED:\r
-                                       msg_status = 0xD;\r
-                                       break;\r
-\r
-                               case SMS_STATUS_MESSAGE_REPLACED:\r
-                               case SMS_STATUS_RESERVED:\r
-                               default:\r
-                                       msg_status = 0x03;\r
-                                       break;\r
-                       }\r
-\r
-                       encoded_data = util_removeQuotes(pResp);\r
-\r
-                       //overwrite Status byte information\r
-                       util_byte_to_hex((const char *)&msg_status, (char *)encoded_data, 1);\r
-\r
-                       //Update EF-SMS with just status byte overwritten, rest 175 bytes are same as received in read information\r
-                       cmd_str = g_strdup_printf("AT+CRSM=220,28476,%d, 4, %d, \"%s\"", (req_msg_status->index+1), AT_EF_SMS_RECORD_LEN, encoded_data);\r
-                       atreq = tcore_at_request_new((const char *)cmd_str, "+CRSM", TCORE_AT_SINGLELINE);\r
-                       pending = tcore_pending_new(tcore_pending_ref_core_object(pending), 0);\r
-                       if (NULL == cmd_str || NULL == atreq || NULL == pending) {\r
-                               err("Out of memory. Unable to proceed");\r
-                               dbg("cmd_str: [%p], atreq: [%p], pending: [%p]", cmd_str, atreq, pending);\r
-\r
-                               //free memory we own\r
-                               g_free(cmd_str);\r
-                               free(encoded_data);\r
-                               util_sms_free_memory(atreq);\r
-                               util_sms_free_memory(pending);\r
-\r
-                               goto OUT;\r
-                       }\r
-\r
-                       util_hex_dump("    ", strlen(cmd_str), (void *)cmd_str);\r
-\r
-                       dup_ur = tcore_user_request_ref(ur);\r
-\r
-                       tcore_pending_set_request_data(pending, 0, atreq);\r
-                       tcore_pending_set_response_callback(pending, on_response_set_msg_status, NULL);\r
-                       tcore_pending_link_user_request(pending, dup_ur);\r
-                       tcore_pending_set_send_callback(pending, on_confirmation_sms_message_send, NULL);\r
-                       tcore_hal_send_request(hal, pending);\r
-\r
-                       g_free(cmd_str);\r
-                       free(encoded_data);\r
-               }\r
-       }\r
-\r
-OUT:\r
-       if(tokens)\r
-               tcore_at_tok_free(tokens);\r
-       \r
-       tcore_user_request_send_response(ur, TRESP_SMS_SET_MSG_STATUS , sizeof(struct tresp_sms_set_msg_status), &msg_status);\r
-\r
-       dbg("Exit");\r
-\r
-       return;\r
-}\r
-\r
-/*=============================================================\r
-                                                       Requests\r
-==============================================================*/\r
-static TReturn send_umts_msg(CoreObject *obj, UserRequest *ur)\r
-{\r
-       gchar *cmd_str = NULL;\r
-       TcoreHal *hal = NULL;\r
-       TcoreATRequest *atreq = NULL;\r
-       TcorePending *pending = NULL;\r
-       const struct treq_sms_send_umts_msg *sendUmtsMsg = NULL;\r
-       char buf[2*(SMS_SMSP_ADDRESS_LEN+SMS_SMDATA_SIZE_MAX)+1] = {0};\r
-       int ScLength = 0;\r
-       int pdu_len = 0;\r
-\r
-       dbg("Entry");\r
-\r
-       sendUmtsMsg = tcore_user_request_ref_data(ur, NULL);\r
-       hal = tcore_object_get_hal(obj);\r
-       if (NULL == sendUmtsMsg || NULL == hal) {\r
-               err("NULL input. Unable to proceed");\r
-               dbg("sendUmtsMsg: [%p], hal: [%p]", sendUmtsMsg, hal);\r
-\r
-               dbg("Exit");\r
-               return TCORE_RETURN_EINVAL;\r
-       }\r
-\r
-       dbg("msgLength: [%d]", sendUmtsMsg->msgDataPackage.msgLength);\r
-       util_hex_dump("    ", (SMS_SMDATA_SIZE_MAX+1), (void *)sendUmtsMsg->msgDataPackage.tpduData);\r
-       util_hex_dump("    ", SMS_SMSP_ADDRESS_LEN, (void *)sendUmtsMsg->msgDataPackage.sca);\r
-\r
-       ScLength = (int)sendUmtsMsg->msgDataPackage.sca[0];\r
-\r
-       dbg("ScLength: [%d]", ScLength);\r
-\r
-       if ((sendUmtsMsg->msgDataPackage.msgLength > 0)\r
-               && (sendUmtsMsg->msgDataPackage.msgLength <= SMS_SMDATA_SIZE_MAX)\r
-               && (ScLength <= SMS_MAX_SMS_SERVICE_CENTER_ADDR)) {\r
-               if (ScLength == 0) { // ScAddress not specified\r
-                       buf[0] = '0';\r
-                       buf[1] = '0';\r
-                       pdu_len = 2;\r
-               } else {\r
-                       dbg("Specifying SCA in TPDU is currently not supported");\r
-\r
-                       buf[0] = '0';\r
-                       buf[1] = '0';\r
-                       pdu_len = 2;\r
-               }\r
-\r
-               util_byte_to_hex((const char *)sendUmtsMsg->msgDataPackage.tpduData, (char *)&buf[pdu_len], sendUmtsMsg->msgDataPackage.msgLength);\r
-\r
-               pdu_len = pdu_len + 2*sendUmtsMsg->msgDataPackage.msgLength;\r
-\r
-               buf[pdu_len] = '\0'; //Ensure termination\r
-\r
-               dbg("pdu_len: [%d]", pdu_len);\r
-               util_hex_dump("    ", sizeof(buf), (void *)buf);\r
-\r
-               //AT+CMGS=<length><CR>PDU is given<ctrl-Z/ESC>\r
-               cmd_str = g_strdup_printf("AT+CMGS=%d%s%s\x1A", sendUmtsMsg->msgDataPackage.msgLength,"\r",buf);\r
-               atreq = tcore_at_request_new((const char *)cmd_str, "+CMGS", TCORE_AT_SINGLELINE);\r
-               pending = tcore_pending_new(obj, 0);\r
-\r
-               if (NULL == cmd_str || NULL == atreq || NULL == pending) {\r
-                       err("Out of memory. Unable to proceed");\r
-                       dbg("cmd_str: [%p], atreq: [%p], pending: [%p]", cmd_str, atreq, pending);\r
-\r
-                       //free memory we own\r
-                       g_free(cmd_str);\r
-                       util_sms_free_memory(atreq);\r
-                       util_sms_free_memory(pending);\r
-\r
-                       dbg("Exit");\r
-                       return TCORE_RETURN_ENOMEM;\r
-               }\r
-\r
-               util_hex_dump("    ", strlen(cmd_str), (void *)cmd_str);\r
-\r
-               tcore_pending_set_request_data(pending, 0, atreq);\r
-               tcore_pending_set_response_callback(pending, on_response_send_umts_msg, NULL);\r
-               tcore_pending_link_user_request(pending, ur);\r
-               tcore_pending_set_send_callback(pending, on_confirmation_sms_message_send, NULL);\r
-               tcore_hal_send_request(hal, pending);\r
-\r
-               g_free(cmd_str);\r
-\r
-               dbg("Exit");\r
-               return TCORE_RETURN_SUCCESS;\r
-       }\r
-\r
-       err("Invalid Data len");\r
-       dbg("Exit");\r
-       return TCORE_RETURN_SMS_INVALID_DATA_LEN;\r
-}\r
-\r
-static TReturn read_msg(CoreObject *obj, UserRequest *ur)\r
-{\r
-       gchar *cmd_str = NULL;\r
-       TcoreHal *hal = NULL;\r
-       TcoreATRequest *atreq = NULL;\r
-       TcorePending *pending = NULL;\r
-       const struct treq_sms_read_msg *readMsg = NULL;\r
-\r
-       dbg("Entry");\r
-\r
-       readMsg = tcore_user_request_ref_data(ur, NULL);\r
-       hal = tcore_object_get_hal(obj);\r
-       if (NULL == readMsg || NULL == hal) {\r
-               err("NULL input. Unable to proceed");\r
-               dbg("readMsg: [%p], hal: [%p]", readMsg, hal);\r
-\r
-               dbg("Exit");\r
-               return TCORE_RETURN_EINVAL;\r
-       }\r
-\r
-       dbg("index: [%d]", readMsg->index);\r
-\r
-       cmd_str = g_strdup_printf("AT+CMGR=%d", (readMsg->index + 1)); //IMC index is one ahead of TAPI\r
-       atreq = tcore_at_request_new((const char *)cmd_str, "+CMGR", TCORE_AT_PDU);\r
-       pending = tcore_pending_new(obj, 0);\r
-\r
-       if (NULL == cmd_str || NULL == atreq || NULL == pending) {\r
-               err("Out of memory. Unable to proceed");\r
-               dbg("cmd_str: [%p], atreq: [%p], pending: [%p]", cmd_str, atreq, pending);\r
-\r
-               //free memory we own\r
-               g_free(cmd_str);\r
-               util_sms_free_memory(atreq);\r
-               util_sms_free_memory(pending);\r
-\r
-               dbg("Exit");\r
-               return TCORE_RETURN_ENOMEM;\r
-       }\r
-\r
-       util_hex_dump("    ", strlen(cmd_str), (void *)cmd_str);\r
-\r
-       tcore_pending_set_request_data(pending, 0, atreq);\r
-       tcore_pending_set_response_callback(pending, on_response_read_msg, (void *)(uintptr_t)(readMsg->index)); //storing index as user data for response\r
-       tcore_pending_link_user_request(pending, ur);\r
-       tcore_pending_set_send_callback(pending, on_confirmation_sms_message_send, NULL);\r
-       tcore_hal_send_request(hal, pending);\r
-\r
-       g_free(cmd_str);\r
-\r
-       dbg("Exit");\r
-       return TCORE_RETURN_SUCCESS;\r
-}\r
-\r
-static TReturn save_msg(CoreObject *obj, UserRequest *ur)\r
-{\r
-       gchar *cmd_str = NULL;\r
-       TcoreHal *hal = NULL;\r
-       TcoreATRequest *atreq = NULL;\r
-       TcorePending *pending = NULL;\r
-       const struct treq_sms_save_msg *saveMsg = NULL;\r
-       int ScLength = 0, pdu_len = 0, stat = 0;\r
-       char buf[2*(SMS_SMSP_ADDRESS_LEN+SMS_SMDATA_SIZE_MAX)+1] = {0};\r
-       char *hex_pdu = NULL;\r
-\r
-       dbg("Entry");\r
-\r
-       saveMsg = tcore_user_request_ref_data(ur, NULL);\r
-       hal = tcore_object_get_hal(obj);\r
-       if (NULL == saveMsg || NULL == hal) {\r
-               err("NULL input. Unable to proceed");\r
-               dbg("saveMsg: [%p], hal: [%p]", saveMsg, hal);\r
-\r
-               dbg("Exit");\r
-               return TCORE_RETURN_EINVAL;\r
-       }\r
-\r
-       dbg("msgStatus: %x, msgLength: [%d]", saveMsg->msgStatus, saveMsg->msgDataPackage.msgLength);\r
-       util_hex_dump("    ", (SMS_SMDATA_SIZE_MAX+1), (void *)saveMsg->msgDataPackage.tpduData);\r
-       util_hex_dump("    ", SMS_SMSP_ADDRESS_LEN, (void *)saveMsg->msgDataPackage.sca);\r
-\r
-       switch (saveMsg->msgStatus) {\r
-               case SMS_STATUS_READ:\r
-                       stat = AT_REC_READ;\r
-                       break;\r
-\r
-               case SMS_STATUS_UNREAD:\r
-                       stat = AT_REC_UNREAD;\r
-                       break;\r
-\r
-               case SMS_STATUS_SENT:\r
-                       stat = AT_STO_SENT;\r
-                       break;\r
-\r
-               case SMS_STATUS_UNSENT:\r
-                       stat = AT_STO_UNSENT;\r
-                       break;\r
-\r
-               default:\r
-                       err("Invalid msgStatus");\r
-                       dbg("Exit");\r
-                       return TCORE_RETURN_EINVAL;\r
-       }\r
-\r
-       if ((saveMsg->msgDataPackage.msgLength > 0)\r
-               && (saveMsg->msgDataPackage.msgLength <= SMS_SMDATA_SIZE_MAX)) {\r
-               ScLength = (int)saveMsg->msgDataPackage.sca[0];\r
-\r
-               buf[0] = ScLength;\r
-               dbg("ScLength = %d", ScLength);\r
-               \r
-               if(ScLength == 0) {\r
-                       buf[0] = 0;\r
-               } else {\r
-                       memcpy(&buf[1],  saveMsg->msgDataPackage.sca, ScLength);\r
-               }\r
-\r
-               memcpy(&buf[ScLength+1],  saveMsg->msgDataPackage.tpduData, saveMsg->msgDataPackage.msgLength);\r
-\r
-               pdu_len= saveMsg->msgDataPackage.msgLength + ScLength + 1;\r
-               dbg("pdu_len: [%d]", pdu_len);\r
-\r
-               hex_pdu = malloc(pdu_len * 2 + 1);\r
-               util_hex_dump("    ", sizeof(buf), (void *)buf);\r
-\r
-               memset (hex_pdu, 0x00, pdu_len * 2 + 1);\r
-               \r
-               util_byte_to_hex((const char *)buf, (char *)hex_pdu, pdu_len);\r
-\r
-               //AT+CMGW=<length>[,<stat>]<CR>PDU is given<ctrl-Z/ESC>\r
-               cmd_str = g_strdup_printf("AT+CMGW=%d,%d%s%s\x1A", saveMsg->msgDataPackage.msgLength, stat, "\r", hex_pdu);\r
-               pending = tcore_pending_new(obj, 0);\r
-               atreq = tcore_at_request_new((const char *)cmd_str, "+CMGW", TCORE_AT_SINGLELINE);\r
-\r
-               if(NULL == cmd_str || NULL == atreq || NULL == pending) {\r
-                       err("Out of memory. Unable to proceed");\r
-                       dbg("cmd_str: [%p], atreq: [%p], pending: [%p]", cmd_str, atreq, pending);\r
-\r
-                       //free memory we own\r
-                       g_free(cmd_str);\r
-                       util_sms_free_memory(atreq);\r
-                       util_sms_free_memory(pending);\r
-                       util_sms_free_memory(hex_pdu);\r
-\r
-                       dbg("Exit");\r
-                       return TCORE_RETURN_ENOMEM;\r
-               }\r
-\r
-               util_hex_dump("    ", strlen(cmd_str), (void *)cmd_str);\r
-\r
-               tcore_pending_set_request_data(pending, 0, atreq);\r
-               tcore_pending_set_response_callback(pending, on_response_sms_save_msg, NULL);\r
-               tcore_pending_link_user_request(pending, ur);\r
-               tcore_pending_set_send_callback(pending, on_confirmation_sms_message_send, NULL);\r
-               tcore_hal_send_request(hal, pending);\r
-\r
-               g_free(cmd_str);\r
-               free(hex_pdu);\r
-\r
-               dbg("Exit");\r
-               return TCORE_RETURN_SUCCESS;\r
-       }\r
-\r
-       err("Invalid Data len");\r
-       dbg("Exit");\r
-       return TCORE_RETURN_SMS_INVALID_DATA_LEN;\r
-}\r
-\r
-static TReturn delete_msg(CoreObject *obj, UserRequest *ur)\r
-{\r
-       gchar *cmd_str = NULL;\r
-       TcoreHal *hal = NULL;\r
-       TcoreATRequest *atreq = NULL;\r
-       TcorePending *pending = NULL;\r
-       const struct treq_sms_delete_msg *deleteMsg = NULL;\r
-\r
-       dbg("Entry");\r
-\r
-       deleteMsg = tcore_user_request_ref_data(ur, NULL);\r
-       hal = tcore_object_get_hal(obj);\r
-       if (NULL == deleteMsg || NULL == hal) {\r
-               err("NULL input. Unable to proceed");\r
-               dbg("deleteMsg: [%p], hal: [%p]", deleteMsg, hal);\r
-\r
-               dbg("Exit");\r
-               return TCORE_RETURN_EINVAL;\r
-       }\r
-\r
-       dbg("index: %d", deleteMsg->index);\r
-\r
-       cmd_str =g_strdup_printf("AT+CMGD=%d,0", deleteMsg->index+1);\r
-       pending = tcore_pending_new(obj, 0);\r
-       atreq = tcore_at_request_new((const char *)cmd_str, NULL, TCORE_AT_NO_RESULT);\r
-       if (NULL == cmd_str || NULL == atreq || NULL == pending) {\r
-               err("Out of memory. Unable to proceed");\r
-               dbg("cmd_str: [%p], atreq: [%p], pending: [%p]", cmd_str, atreq, pending);\r
-\r
-               //free memory we own\r
-               g_free(cmd_str);\r
-               util_sms_free_memory(atreq);\r
-               util_sms_free_memory(pending);\r
-\r
-               dbg("Exit");\r
-               return TCORE_RETURN_ENOMEM;\r
-       }\r
-\r
-       util_hex_dump("    ", strlen(cmd_str), (void *)cmd_str);\r
-\r
-       tcore_pending_set_request_data(pending, 0, atreq);\r
-       tcore_pending_set_response_callback(pending, on_response_sms_delete_msg, (void *)(uintptr_t)(deleteMsg->index)); //storing index as user data for response\r
-       tcore_pending_link_user_request(pending, ur);\r
-       tcore_pending_set_send_callback(pending, on_confirmation_sms_message_send, NULL);\r
-       tcore_hal_send_request(hal, pending);\r
-\r
-       g_free(cmd_str);\r
-\r
-       dbg("Exit");\r
-       return TCORE_RETURN_SUCCESS;\r
-}\r
-\r
-static TReturn get_storedMsgCnt(CoreObject *obj, UserRequest *ur)\r
-{\r
-       gchar *cmd_str = NULL;\r
-       TcoreHal *hal = NULL;\r
-       TcoreATRequest *atreq = NULL;\r
-       TcorePending *pending = NULL;\r
-\r
-       dbg("Entry");\r
-\r
-       hal = tcore_object_get_hal(obj);\r
-       if (NULL == hal) {\r
-               err("NULL HAL. Unable to proceed");\r
-\r
-               dbg("Exit");\r
-               return TCORE_RETURN_EINVAL;\r
-       }\r
-\r
-       cmd_str = g_strdup_printf("AT+CPMS=\"SM\"");\r
-       pending = tcore_pending_new(obj, 0);\r
-       atreq = tcore_at_request_new((const char *)cmd_str, "+CPMS", TCORE_AT_SINGLELINE);\r
-\r
-       if (NULL == cmd_str || NULL == atreq || NULL == pending) {\r
-               err("Out of memory. Unable to proceed");\r
-               dbg("cmd_str: [%p], atreq: [%p], pending: [%p]", cmd_str, atreq, pending);\r
-\r
-               //free memory we own\r
-               g_free(cmd_str);\r
-               util_sms_free_memory(atreq);\r
-               util_sms_free_memory(pending);\r
-\r
-               dbg("Exit");\r
-               return TCORE_RETURN_ENOMEM;\r
-       }\r
-\r
-       util_hex_dump("    ", strlen(cmd_str), (void *)cmd_str);\r
-\r
-       tcore_pending_set_request_data(pending, 0, atreq);\r
-       tcore_pending_set_response_callback(pending, on_response_get_stored_msg_cnt, NULL);\r
-       tcore_pending_link_user_request(pending, ur);\r
-       tcore_pending_set_send_callback(pending, on_confirmation_sms_message_send, NULL);\r
-       tcore_hal_send_request(hal, pending);\r
-\r
-       g_free(cmd_str);\r
-\r
-       dbg("Exit");\r
-       return TCORE_RETURN_SUCCESS;\r
-}\r
-\r
-static TReturn get_sca(CoreObject *obj, UserRequest *ur)\r
-{\r
-       gchar * cmd_str = NULL;\r
-       TcoreHal *hal = NULL;\r
-       TcoreATRequest *atreq = NULL;\r
-       TcorePending *pending = NULL;\r
-       \r
-       dbg("Entry");\r
-\r
-       hal = tcore_object_get_hal(obj);\r
-       if (NULL == hal) {\r
-               err("HAL NULL. Unable to proceed");\r
-\r
-               dbg("Exit");\r
-               return TCORE_RETURN_EINVAL;\r
-       }\r
-\r
-       cmd_str = g_strdup_printf("AT+CSCA?");\r
-       pending = tcore_pending_new(obj, 0);\r
-       atreq = tcore_at_request_new((const char *)cmd_str, "+CSCA", TCORE_AT_SINGLELINE);\r
-\r
-       if (NULL == cmd_str || NULL == atreq || NULL == pending) {\r
-               err("Out of memory. Unable to proceed");\r
-               dbg("cmd_str: [%p], atreq: [%p], pending: [%p]", cmd_str, atreq, pending);\r
-\r
-               //free memory we own\r
-               g_free(cmd_str);\r\r
-               util_sms_free_memory(atreq);\r
-               util_sms_free_memory(pending);\r
-\r
-               dbg("Exit");\r
-               return TCORE_RETURN_ENOMEM;\r
-       }\r
-\r
-       util_hex_dump("    ", strlen(cmd_str), (void *)cmd_str);\r
-\r
-       tcore_pending_set_request_data(pending, 0, atreq);\r
-       tcore_pending_set_response_callback(pending, on_response_get_sca, NULL);\r
-       tcore_pending_link_user_request(pending, ur);\r
-       tcore_pending_set_send_callback(pending, on_confirmation_sms_message_send, NULL);\r
-       tcore_hal_send_request(hal, pending);\r
-\r
-       g_free(cmd_str);\r
-\r
-       dbg("Exit");\r
-       return TCORE_RETURN_SUCCESS;\r
-}\r
-\r
-static TReturn set_sca(CoreObject *obj, UserRequest *ur)\r
-{\r
-       gchar *cmd_str = NULL;\r
-       TcoreHal *hal = NULL;\r
-       TcoreATRequest *atreq = NULL;\r
-       TcorePending *pending = NULL;\r
-       const struct treq_sms_set_sca *setSca = NULL;\r
-       int addrType = 0;\r
-\r
-       dbg("Entry");\r
-\r
-       setSca = tcore_user_request_ref_data(ur, NULL);\r
-       hal = tcore_object_get_hal(obj);\r
-       if (NULL == setSca || NULL == hal) {\r
-               err("NULL input. Unable to proceed");\r
-               dbg("setSca: [%p], hal: [%p]", setSca, hal);\r
-\r
-               dbg("Exit");\r
-               return TCORE_RETURN_EINVAL;\r
-       }\r
-\r
-       dbg("dialNumLen: %u, typeOfNum: %d, numPlanId: %d, ", setSca->scaInfo.dialNumLen, setSca->scaInfo.typeOfNum, setSca->scaInfo.numPlanId);\r
-\r
-       util_hex_dump("    ", (SMS_SMSP_ADDRESS_LEN+1), (void *)setSca->scaInfo.diallingNum);\r
-\r
-       addrType = ((setSca->scaInfo.typeOfNum << 4) | setSca->scaInfo.numPlanId) | 0x80;\r
-\r
-       cmd_str = g_strdup_printf("AT+CSCA=\"%s\",%d", setSca->scaInfo.diallingNum, addrType);\r
-       pending = tcore_pending_new(obj, 0);\r
-       atreq = tcore_at_request_new((const char *)cmd_str, NULL, TCORE_AT_NO_RESULT);\r
-\r
-       if (NULL == cmd_str || NULL == atreq || NULL == pending) {\r
-               err("Out of memory. Unable to proceed");\r
-               dbg("cmd_str: [%p], atreq: [%p], pending: [%p]", cmd_str, atreq, pending);\r
-\r
-               //free memory we own\r
-               g_free(cmd_str);\r
-               util_sms_free_memory(atreq);\r
-               util_sms_free_memory(pending);\r
-\r
-               dbg("Exit");\r
-               return TCORE_RETURN_ENOMEM;\r
-       }\r
-\r
-       util_hex_dump("    ", strlen(cmd_str), (void *)cmd_str);\r
-\r
-       tcore_pending_set_request_data(pending, 0, atreq);\r
-       tcore_pending_set_response_callback(pending, on_response_set_sca, NULL);\r
-       tcore_pending_link_user_request(pending, ur);\r
-       tcore_pending_set_send_callback(pending, on_confirmation_sms_message_send, NULL);\r
-       tcore_hal_send_request(hal, pending);\r
-\r
-       g_free(cmd_str);\r
-\r
-       dbg("Exit");\r
-       return TCORE_RETURN_SUCCESS;\r
-}\r
-\r
-static TReturn get_cb_config(CoreObject *obj, UserRequest *ur)\r
-{\r
-       gchar *cmd_str = NULL;\r
-       TcoreHal *hal = NULL;\r
-       TcoreATRequest *atreq = NULL;\r
-       TcorePending *pending = NULL;\r
-\r
-       dbg("Entry");\r
-\r
-       hal = tcore_object_get_hal(obj);\r
-       if (NULL == hal) {\r
-               err("NULL HAL. Unable to proceed");\r
-\r
-               dbg("Exit");\r
-               return TCORE_RETURN_EINVAL;\r
-       }\r
-\r
-       cmd_str = g_strdup_printf("AT+CSCB?");\r
-       pending = tcore_pending_new(obj, 0);\r
-       atreq = tcore_at_request_new((const char *)cmd_str, "+CSCB", TCORE_AT_SINGLELINE);\r
-       if (NULL == cmd_str || NULL == atreq || NULL == pending) {\r
-               err("Out of memory. Unable to proceed");\r
-               dbg("cmd_str: [%p], atreq: [%p], pending: [%p]", cmd_str, atreq, pending);\r
-\r
-               //free memory we own\r
-               g_free(cmd_str);\r
-               util_sms_free_memory(atreq);\r
-               util_sms_free_memory(pending);\r
-\r
-               dbg("Exit");\r
-               return TCORE_RETURN_ENOMEM;\r
-       }\r
-\r
-       util_hex_dump("    ", strlen(cmd_str), (void *)cmd_str);\r
-\r
-       tcore_pending_set_request_data(pending, 0, atreq);\r
-       tcore_pending_set_response_callback(pending, on_response_get_cb_config, NULL);\r
-       tcore_pending_set_send_callback(pending, on_confirmation_sms_message_send, NULL);\r
-       tcore_pending_link_user_request(pending, ur);\r
-       tcore_hal_send_request(hal, pending);\r
-\r
-       g_free(cmd_str);\r
-\r
-       dbg("Exit");\r
-       return TCORE_RETURN_SUCCESS;\r
-}\r
-\r
-static TReturn set_cb_config(CoreObject *obj, UserRequest *ur)\r
-{\r
-       gchar *cmd_str = NULL;\r
-       gchar *mids_str = NULL;\r
-       GString *mids_GString = NULL;\r
-\r
-       TcoreHal *hal = NULL;\r
-       TcoreATRequest *atreq = NULL;\r
-       TcorePending *pending = NULL;\r
-       const struct treq_sms_set_cb_config *setCbConfig = NULL;\r
-       int ctr1= 0, ctr2 =0;\r
-       unsigned short appendMsgId = 0;\r
-\r
-       dbg("Entry");\r
-\r
-       setCbConfig = tcore_user_request_ref_data(ur, NULL);\r
-       hal = tcore_object_get_hal(obj);\r
-       if (NULL == setCbConfig || NULL == hal) {\r
-               err("NULL input. Unable to proceed");\r
-               dbg("setCbConfig: [%p], hal: [%p]", setCbConfig, hal);\r
-\r
-               dbg("Exit");\r
-               return TCORE_RETURN_EINVAL;\r
-       }\r
-\r
-       dbg("bCBEnabled: %d,  msgIdMaxCount: %x, msgIdCount: %d", setCbConfig->cbEnabled, setCbConfig->msgIdMaxCount, setCbConfig->msgIdRangeCount);\r
-       //util_hex_dump("    ", SMS_GSM_SMS_CBMI_LIST_SIZE_MAX, (void *)setCbConfig->msgIDs);\r
-\r
-       if (setCbConfig->cbEnabled == 2) { //Enable all CBS\r
-               cmd_str = g_strdup_printf("AT+CSCB=1");\r
-       } else if (setCbConfig->cbEnabled == 0) {//AT+CSCB=0: Disable CBS\r
-               cmd_str = g_strdup_printf("AT+CSCB=0");\r
-       } else {\r
-               mids_GString = g_string_new("AT+CSCB=0,\"");\r
-\r
-               for(ctr1 = 0; ctr1 < setCbConfig->msgIdRangeCount; ctr1++ ) {\r
-                       if( setCbConfig->msgIDs[ctr1].net3gpp.selected == FALSE )\r
-                               continue;\r
-\r
-                       if( SMS_GSM_SMS_CBMI_LIST_SIZE_MAX <= (setCbConfig->msgIDs[ctr1].net3gpp.toMsgId - setCbConfig->msgIDs[ctr1].net3gpp.fromMsgId) ) {\r
-                               mids_GString = g_string_new("AT+CSCB=1");\r
-                               break;\r
-                       }\r
-                       \r
-                       appendMsgId = setCbConfig->msgIDs[ctr1].net3gpp.fromMsgId;\r
-\r
-                       for( ctr2 = 0; (ctr2 <= ((setCbConfig->msgIDs[ctr1].net3gpp.toMsgId) - (setCbConfig->msgIDs[ctr1].net3gpp.fromMsgId))); ctr2++ ) {\r
-                               dbg( "%x", appendMsgId);\r
-                               mids_GString = g_string_append(mids_GString, g_strdup_printf("%d", appendMsgId));\r
-                               \r
-                               if (ctr2 == ((setCbConfig->msgIDs[ctr1].net3gpp.toMsgId) - (setCbConfig->msgIDs[ctr1].net3gpp.fromMsgId))) {\r
-                                       mids_GString = g_string_append(mids_GString, "\""); //Mids string termination\r
-                               } else {\r
-                                       mids_GString = g_string_append(mids_GString, ",");\r
-                               }\r
-\r
-                               appendMsgId++;\r
-                       }\r
-               }\r
-               mids_str = g_string_free(mids_GString, FALSE);\r
-               cmd_str = g_strdup_printf("%s", mids_str);\r
-               g_free(mids_str);\r
-       }\r
-\r
-       pending = tcore_pending_new(obj, 0);\r
-       atreq = tcore_at_request_new((const char *)cmd_str, NULL, TCORE_AT_NO_RESULT);\r
-       if(NULL == cmd_str || NULL == atreq || NULL == pending) {\r
-               err("Out of memory. Unable to proceed");\r
-               dbg("cmd_str: [%p], atreq: [%p], pending: [%p]", cmd_str, atreq, pending);\r
-\r
-               //free memory we own\r
-               g_free(cmd_str);\r
-               util_sms_free_memory(atreq);\r
-               util_sms_free_memory(pending);\r
-\r
-               dbg("Exit");\r
-               return TCORE_RETURN_ENOMEM;\r
-       }\r
-\r
-       util_hex_dump("    ", strlen(cmd_str), (void *)cmd_str);\r
-\r
-       tcore_pending_set_request_data(pending, 0, atreq);\r
-       tcore_pending_set_response_callback(pending, on_response_set_cb_config, NULL);\r
-       tcore_pending_link_user_request(pending, ur);\r
-       tcore_pending_set_send_callback(pending, on_confirmation_sms_message_send, NULL);\r
-       tcore_hal_send_request(hal, pending);\r
-\r
-       g_free(cmd_str);\r
-\r
-       dbg("Exit");\r
-       return TCORE_RETURN_SUCCESS;\r
-}\r
-\r
-static TReturn set_mem_status(CoreObject *obj, UserRequest *ur)\r
-{\r
-       gchar *cmd_str = NULL;\r
-       TcoreHal *hal = NULL;\r
-       TcoreATRequest *atreq = NULL;\r
-       TcorePending *pending = NULL;\r
-       const struct treq_sms_set_mem_status *setMemStatus = NULL;\r
-       int memoryStatus = 0;\r
-\r
-       dbg("Entry");\r
-\r
-       setMemStatus = tcore_user_request_ref_data(ur, NULL);\r
-       hal = tcore_object_get_hal(obj);\r
-       if (NULL == setMemStatus || NULL == hal) {\r
-               err("NULL input. Unable to proceed");\r
-               dbg("setMemStatus: [%p], hal: [%p]", setMemStatus, hal);\r
-\r
-               dbg("Exit");\r
-               return TCORE_RETURN_EINVAL;\r
-       }\r
-\r
-       dbg("memory_status: %d", setMemStatus->memory_status);\r
-\r
-       if(setMemStatus->memory_status < SMS_PDA_MEMORY_STATUS_AVAILABLE\r
-               || setMemStatus->memory_status > SMS_PDA_MEMORY_STATUS_FULL) {\r
-               err("Invalid memory_status");\r
-\r
-               dbg("Exit");\r
-               return TCORE_RETURN_EINVAL;\r
-       }\r
-\r
-       switch (setMemStatus->memory_status) {\r
-               case SMS_PDA_MEMORY_STATUS_AVAILABLE:\r
-                       memoryStatus = AT_MEMORY_AVAILABLE;\r
-                       break;\r
-\r
-               case SMS_PDA_MEMORY_STATUS_FULL:\r
-                       memoryStatus = AT_MEMORY_FULL;\r
-                       break;\r
-\r
-               default:\r
-                       err("Invalid memory_status");\r
-                       dbg("Exit");\r
-                       return TCORE_RETURN_EINVAL;\r
-       }\r
-\r
-       cmd_str = g_strdup_printf("AT+XTESM=%d", memoryStatus);\r
-       pending = tcore_pending_new(obj, 0);\r
-       atreq = tcore_at_request_new((const char *)cmd_str, NULL, TCORE_AT_NO_RESULT);\r
-\r
-       if (NULL == cmd_str || NULL == atreq || NULL == pending) {\r
-               err("Out of memory. Unable to proceed");\r
-               dbg("cmd_str: [%p], atreq: [%p], pending: [%p]", cmd_str, atreq, pending);\r
-\r
-               //free memory we own\r
-               g_free(cmd_str);\r
-               util_sms_free_memory(atreq);\r
-               util_sms_free_memory(pending);\r
-\r
-               dbg("Exit");\r
-               return TCORE_RETURN_ENOMEM;\r
-       }\r
-\r
-       util_hex_dump("    ", strlen(cmd_str), (void *)cmd_str);\r
-\r
-       tcore_pending_set_request_data(pending, 0, atreq);\r
-       tcore_pending_set_response_callback(pending, on_response_set_mem_status, NULL);\r
-       tcore_pending_link_user_request(pending, ur);\r
-       tcore_pending_set_send_callback(pending, on_confirmation_sms_message_send, NULL);\r
-       tcore_hal_send_request(hal, pending);\r
-\r
-       g_free(cmd_str);\r
-\r
-       dbg("Exit");\r
-       return TCORE_RETURN_SUCCESS;\r
-}\r
-\r
-static TReturn set_delivery_report(CoreObject *obj, UserRequest *ur)\r
-{\r
-       struct tresp_sms_set_delivery_report respSetDeliveryReport = {0,};\r
-       \r
-       respSetDeliveryReport.result = SMS_SUCCESS;\r
-\r
-       dbg("Entry");\r
-\r
-       dbg("CP takes care of sending SMS ack to network for all classes of SMS. Sending default success.");\r
-\r
-       tcore_user_request_send_response(ur, TRESP_SMS_SET_DELIVERY_REPORT, sizeof(struct tresp_sms_set_delivery_report), &respSetDeliveryReport);\r
-\r
-       dbg("Exit");\r
-       return TCORE_RETURN_SUCCESS;\r
-}\r
-\r
-static TReturn set_msg_status(CoreObject *obj, UserRequest *ur)\r
-{\r
-       gchar *cmd_str = NULL;\r
-       TcoreHal *hal = NULL;\r
-       TcoreATRequest *atreq = NULL;\r
-       TcorePending *pending = NULL;\r
-       const struct treq_sms_set_msg_status *msg_status = NULL;\r
-\r
-       dbg("Entry");\r
-\r
-       msg_status = tcore_user_request_ref_data(ur, NULL);\r
-\r
-       cmd_str = g_strdup_printf("AT+CRSM=178,28476,%d,4,%d", (msg_status->index+1), AT_EF_SMS_RECORD_LEN);\r
-       atreq = tcore_at_request_new((const char *)cmd_str, "+CRSM", TCORE_AT_SINGLELINE);\r
-       pending = tcore_pending_new(obj, 0);\r
-       if (NULL == cmd_str || NULL == atreq || NULL == pending) {\r
-               err("Out of memory. Unable to proceed");\r
-               dbg("cmd_str: [%p], atreq: [%p], pending: [%p]", cmd_str, atreq, pending);\r
-\r
-               //free memory we own\r
-               g_free(cmd_str);\r
-               util_sms_free_memory(atreq);\r
-               util_sms_free_memory(pending);\r
-\r
-               dbg("Exit");\r
-               return TCORE_RETURN_ENOMEM;\r
-       }\r
-\r
-       util_hex_dump("    ", strlen(cmd_str), (void *)cmd_str);\r
-\r
-       tcore_pending_set_request_data(pending, 0, atreq);\r
-       tcore_pending_set_response_callback(pending, _response_get_efsms_data, NULL);\r
-       tcore_pending_link_user_request(pending, ur);\r
-       tcore_pending_set_send_callback(pending, on_confirmation_sms_message_send, NULL);\r
-       tcore_hal_send_request(hal, pending);\r
-\r
-       g_free(cmd_str);\r
-\r
-       dbg("Exit");\r
-       return TCORE_RETURN_SUCCESS;\r
-}\r
-\r
-static TReturn get_sms_params(CoreObject *obj, UserRequest *ur)\r
-{\r
-       gchar *cmd_str = NULL;\r
-       TcoreHal *hal = NULL;\r
-       TcoreATRequest *atreq = NULL;\r
-       TcorePending *pending = NULL;\r
-       const struct treq_sms_get_params *getSmsParams = NULL;\r
-       int record_len = 0 , *smsp_record_len = NULL;\r
-\r
-       dbg("Entry");\r
-\r
-       getSmsParams = tcore_user_request_ref_data(ur, NULL);\r
-       hal = tcore_object_get_hal(obj);\r
-       if (NULL == getSmsParams || NULL == hal) {\r
-               err("NULL input. Unable to proceed");\r
-               dbg("getSmsParams: [%p], hal: [%p]", getSmsParams, hal);\r
-\r
-               dbg("Exit");\r
-               return TCORE_RETURN_EINVAL;\r
-       }\r
-\r
-       smsp_record_len = tcore_plugin_ref_property(tcore_object_ref_plugin(obj), "SMSPRECORDLEN");\r
-       record_len = *smsp_record_len;\r
-       dbg("record len from property %d", record_len);\r
-\r
-       //AT+CRSM=command>[,<fileid>[,<P1>,<P2>,<P3>[,<data>[,<pathid>]]]]\r
-       cmd_str = g_strdup_printf("AT+CRSM=178,28482,%d,4,%d", (getSmsParams->index + 1), record_len);\r
-\r
-       dbg("cmd_str is %s",cmd_str);\r
-\r
-       atreq = tcore_at_request_new((const char *)cmd_str, "+CRSM", TCORE_AT_SINGLELINE);\r
-       pending = tcore_pending_new(obj, 0);\r
-       if (NULL == cmd_str || NULL == atreq || NULL == pending) {\r
-               err("Out of memory. Unable to proceed");\r
-               dbg("cmd_str: [%p], atreq: [%p], pending: [%p]", cmd_str, atreq, pending);\r
-\r
-               //free memory we own\r
-               g_free(cmd_str);\r
-               util_sms_free_memory(atreq);\r
-               util_sms_free_memory(pending);\r
-\r
-               dbg("Exit");\r
-               return TCORE_RETURN_ENOMEM;\r
-       }\r
-\r
-       util_hex_dump("    ", strlen(cmd_str), (void *)cmd_str);\r
-\r
-       tcore_pending_set_request_data(pending, 0, atreq);\r
-       tcore_pending_set_response_callback(pending, on_response_get_sms_params, NULL);\r
-       tcore_pending_link_user_request(pending, ur);\r
-       tcore_pending_set_send_callback(pending, on_confirmation_sms_message_send, NULL);\r
-       tcore_hal_send_request(hal, pending);\r
-\r
-       g_free(cmd_str);\r
-\r
-       dbg("Exit");\r
-       return TCORE_RETURN_SUCCESS;\r
-}\r
-\r
-static TReturn set_sms_params(CoreObject *obj, UserRequest *ur)\r
-{\r
-       gchar *cmd_str = NULL;\r
-       char *encoded_data = NULL;\r
-       unsigned char *temp_data = NULL;\r
-       int SMSPRecordLen = 0;\r
-\r
-       TcoreHal *hal = NULL;\r
-       TcoreATRequest *atreq = NULL;\r
-       TcorePending *pending = NULL;\r
-       const struct treq_sms_set_params *setSmsParams = NULL;\r
-       int encoded_data_len = 0;\r
-\r
-       dbg("Entry");\r
-\r
-       setSmsParams = tcore_user_request_ref_data(ur, NULL);\r
-       hal = tcore_object_get_hal(obj);\r
-       if (NULL == setSmsParams || NULL == hal) {\r
-               err("NULL input. Unable to proceed");\r
-               dbg("setSmsParams: [%p], hal: [%p]", setSmsParams, hal);\r
-               return FALSE;\r
-       }\r
-\r
-       //EFsmsp file size is 28 +Y bytes (Y is alpha id size)\r
-       SMSPRecordLen = 28 + setSmsParams->params.alphaIdLen;\r
-       temp_data = calloc(SMSPRecordLen,1);\r
-       encoded_data = calloc(SMSPRecordLen*2 + 1,1);\r
-       \r
-       _tcore_util_sms_encode_smsParameters(&(setSmsParams->params), temp_data, SMSPRecordLen);\r
-\r
-       util_byte_to_hex((const char *)temp_data, (char *)encoded_data,SMSPRecordLen);\r
-       \r
-       encoded_data_len = ((SMSPRecordLen) * 2);\r
-\r
-       hal = tcore_object_get_hal(obj);\r
-       pending = tcore_pending_new(obj, 0);\r
-\r
-        dbg("alpha id len %d encoded data %s. Encoded data len %d",setSmsParams->params.alphaIdLen,encoded_data, encoded_data_len);\r
-        cmd_str = g_strdup_printf("AT+CRSM=220,28482,%d,4,%d,\"%s\"",(setSmsParams->params.recordIndex+1),SMSPRecordLen,encoded_data);\r
-\r
-        dbg("cmd str is %s",cmd_str);\r
-        atreq = tcore_at_request_new(cmd_str, "+CRSM:", TCORE_AT_SINGLELINE);\r
-\r
-       if (NULL == cmd_str || NULL == atreq || NULL == pending) {\r
-               err("Out of memory. Unable to proceed");\r
-               dbg("cmd_str: [%p], atreq: [%p], pending: [%p]", cmd_str, atreq, pending);\r
-\r
-               //free memory we own\r
-               g_free(cmd_str);\r
-               util_sms_free_memory(atreq);\r
-               util_sms_free_memory(pending);\r
-\r
-               util_sms_free_memory(temp_data);\r
-               util_sms_free_memory(encoded_data);\r
-\r
-               dbg("Exit");\r
-               return TCORE_RETURN_ENOMEM;\r
-       }\r
-\r
-       util_hex_dump("    ", strlen(cmd_str), (void *)cmd_str);\r
-\r
-       tcore_pending_set_request_data(pending, 0,atreq);\r
-       tcore_pending_set_response_callback(pending, on_response_set_sms_params, NULL);\r
-       tcore_pending_link_user_request(pending, ur);\r
-       tcore_pending_set_send_callback(pending, on_confirmation_sms_message_send, NULL);\r
-       tcore_hal_send_request(hal, pending);\r
-\r
-       g_free(cmd_str);\r
-       util_sms_free_memory(temp_data);\r
-       util_sms_free_memory(encoded_data);\r
-\r
-       return TRUE;\r
-}\r
-\r
-static TReturn get_paramcnt(CoreObject *obj, UserRequest *ur)\r
-{\r
-       gchar *cmd_str = NULL;\r
-       TcoreHal *hal = NULL;\r
-       TcoreATRequest *atreq = NULL;\r
-       TcorePending *pending = NULL;\r
-\r
-       dbg("Entry");\r
-\r
-       hal = tcore_object_get_hal(obj);\r
-       if (NULL == hal) {\r
-               err("NULL HAL. Unable to proceed");\r
-\r
-               dbg("Exit");\r
-               return TCORE_RETURN_EINVAL;\r
-       }\r
-\r
-       //AT+CRSM=command>[,<fileid>[,<P1>,<P2>,<P3>[,<data>[,<pathid>]]]]\r
-       cmd_str = g_strdup_printf("AT+CRSM=192,28482");\r
-       atreq = tcore_at_request_new((const char *)cmd_str, "+CRSM", TCORE_AT_SINGLELINE);\r
-       pending = tcore_pending_new(obj, 0);\r
-\r
-       if (NULL == cmd_str || NULL == atreq || NULL == pending) {\r
-               err("NULL pointer. Unable to proceed");\r
-               dbg("cmd_str: [%p], atreq: [%p], pending: [%p]", cmd_str, atreq, pending);\r
-\r
-               //free memory we own\r
-               g_free(cmd_str);\r
-               util_sms_free_memory(atreq);\r
-               util_sms_free_memory(pending);\r
-\r
-               dbg("Exit");\r
-               return TCORE_RETURN_FAILURE;\r
-       }\r
-\r
-       util_hex_dump("    ", strlen(cmd_str), (void *)cmd_str);\r
-\r
-       tcore_pending_set_request_data(pending, 0, atreq);\r
-       tcore_pending_set_response_callback(pending, on_response_get_paramcnt, NULL);\r
-       tcore_pending_link_user_request(pending, ur);\r
-       tcore_pending_set_send_callback(pending, on_confirmation_sms_message_send, NULL);\r
-       tcore_hal_send_request(hal, pending);\r
-\r
-       g_free(cmd_str);\r
-\r
-       dbg("Exit");\r
-       return TCORE_RETURN_SUCCESS;\r
-}\r
-\r
-static struct tcore_sms_operations sms_ops = {\r
-       .send_umts_msg = send_umts_msg,\r
-       .read_msg = read_msg,\r
-       .save_msg = save_msg,\r
-       .delete_msg = delete_msg,\r
-       .get_storedMsgCnt = get_storedMsgCnt,\r
-       .get_sca = get_sca,\r
-       .set_sca = set_sca,\r
-       .get_cb_config = get_cb_config,\r
-       .set_cb_config = set_cb_config,\r
-       .set_mem_status = set_mem_status,\r
-       .get_pref_brearer = NULL,\r
-       .set_pref_brearer = NULL,\r
-       .set_delivery_report = set_delivery_report,\r
-       .set_msg_status = set_msg_status,\r
-       .get_sms_params = get_sms_params,\r
-       .set_sms_params = set_sms_params,\r
-       .get_paramcnt = get_paramcnt,\r
-};\r
-\r
-gboolean s_sms_init(TcorePlugin *plugin, TcoreHal *hal)\r
-{\r
-       CoreObject *obj = NULL;\r
-       struct property_sms_info *data = NULL;\r
-       GQueue *work_queue = NULL;\r
-       int *smsp_record_len = NULL;\r
-\r
-       dbg("Entry");\r
-       dbg("plugin: [%p]", plugin);\r
-       dbg("hal: [%p]", hal);\r
-\r
-       obj = tcore_sms_new(plugin, "umts_sms", &sms_ops, hal);\r
-\r
-       data = calloc(sizeof(struct property_sms_info), 1);\r
-\r
-       if (NULL == obj || NULL == data) {\r
-               err("Unable to initialize. Exiting");\r
-               s_sms_exit(plugin);\r
-\r
-               dbg("Exit");\r
-               return FALSE;\r
-       }\r
-\r
-       work_queue = g_queue_new();\r
-       tcore_object_link_user_data(obj, work_queue);\r
-\r
-       //Registering for SMS notifications\r
-       tcore_object_add_callback(obj, "\e+CMTI", on_event_class2_sms_incom_msg, NULL);\r
-       tcore_object_add_callback(obj, "\e+CMT", on_event_sms_incom_msg, NULL);\r
-\r
-       tcore_object_add_callback(obj, "\e+CDS", on_event_sms_incom_msg, NULL);\r
-       tcore_object_add_callback(obj, "+XSMSMMSTAT", on_event_sms_memory_status, NULL);\r
-       tcore_object_add_callback(obj, "+CMS", on_event_sms_memory_status, NULL);\r
-\r
-       tcore_object_add_callback(obj, "\e+CBMI", on_event_sms_cb_incom_msg, NULL);\r
-       tcore_object_add_callback(obj, "\e+CBM", on_event_sms_cb_incom_msg, NULL);\r
-       tcore_object_add_callback(obj, "+XSIM", on_event_sms_ready_status, NULL);\r
-\r
-       tcore_plugin_link_property(plugin, "SMS", data);\r
-\r
-       //storing smsp record length\r
-       smsp_record_len = calloc(sizeof(int), 1);\r
-       tcore_plugin_link_property(plugin, "SMSPRECORDLEN", smsp_record_len);\r
-\r
-       dbg("Exit");\r
-       return TRUE;\r
-}\r
-\r
-void s_sms_exit(TcorePlugin *plugin)\r
-{\r
-       CoreObject *obj = NULL;\r
-       struct property_sms_info *data = NULL;\r
-\r
-       dbg("Entry");\r
-       dbg("plugin: [%p]", plugin);\r
-\r
-       obj = tcore_plugin_ref_core_object(plugin, "umts_sms");\r
-       if (NULL == obj) {\r
-               err("NULL core object. Nothing to do.");\r
-               return;\r
-       }\r
-       tcore_sms_free(obj);\r
-\r
-       data = tcore_plugin_ref_property(plugin, "SMS");\r
-       util_sms_free_memory(data);\r
-\r
-       dbg("Exit");\r
-       return;\r
-}\r
+/*
+ * tel-plugin-imc
+ *
+ * Copyright (c) 2012 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Contact: Madhavi Akella <madhavi.a@samsung.com>
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <stdint.h>
+
+#include <glib.h>
+
+#include <tcore.h>
+#include <hal.h>
+#include <core_object.h>
+#include <plugin.h>
+#include <queue.h>
+#include <co_sms.h>
+#include <co_sim.h>
+#include <user_request.h>
+#include <storage.h>
+#include <server.h>
+#include <at.h>
+#include <plugin.h>
+
+#include "common/TelErr.h"
+#include "s_common.h"
+#include "s_sms.h"
+
+/*=============================================================
+                            GSM-SMS Size
+==============================================================*/
+#define MAX_GSM_SMS_TPDU_SIZE                       244
+#define MAX_GSM_SMS_MSG_NUM                         255
+#define MAX_GSM_SMS_SERVICE_CENTER_ADDR             12      /* Maximum number of bytes of service center address */
+#define MAX_GSM_SMS_CBMI_LIST_SIZE                  100     /* Maximum number of CBMI list size for CBS 30*2=60  */
+#define MAX_GSM_SMS_PARAM_RECORD_SIZE               156     /* Maximum number of bytes SMSP Record size (Y + 28), y : 0 ~ 128 */
+#define MAX_GSM_SMS_STATUS_FILE_SIZE                2       /* Last Used TP-MR + SMS "Memory Cap. Exceeded" Noti Flag */
+#define TAPI_SIM_SMSP_ADDRESS_LEN                   20
+
+/*=============================================================
+                            Device Ready
+==============================================================*/
+#define AT_SMS_DEVICE_READY             12      /* AT device ready */
+#define SMS_DEVICE_READY                1       /* Telephony device ready */
+#define SMS_DEVICE_NOT_READY            0       /* Telephony device not ready */
+
+/*=============================================================
+                            CBMI Selection
+==============================================================*/
+#define SMS_CBMI_SELECTED_SOME          0x02    /* Some CBMIs are selected */
+#define SMS_CBMI_SELECTED_ALL           0x01    /* All CBMIs are selected */
+
+/*=============================================================
+                            Message Status
+==============================================================*/
+#define AT_REC_UNREAD                   0       /* Received and Unread */
+#define AT_REC_READ                     1       /* Received and Read */
+#define AT_STO_UNSENT                   2       /* Unsent */
+#define AT_STO_SENT                     3       /* Sent */
+#define AT_ALL                          4       /* Unknown */
+
+/*=============================================================
+                            Memory Status
+==============================================================*/
+#define AT_MEMORY_AVAILABLE             0       /* Memory Available */
+#define AT_MEMORY_FULL                  1       /* Memory Full */
+
+/*=============================================================
+        SIM CRSM SW1 and Sw2 Error definitions */
+
+#define AT_SW1_SUCCESS                  0x90
+#define AT_SW2_SUCCESS                  0
+#define AT_SW1_LEN_RESP                 0x9F
+
+#define AT_MAX_RECORD_LEN               256
+#define AT_EF_SMS_RECORD_LEN            176
+
+/*=============================================================*/
+
+
+/*=========================================================
+                            Security
+==============================================================*/
+#define MAX_SEC_PIN_LEN                         8
+#define MAX_SEC_PUK_LEN                         8
+#define MAX_SEC_PHONE_LOCK_PW_LEN               39      /* Maximum Phone Locking Password Length */
+#define MAX_SEC_SIM_DATA_STRING                 256     /* Maximum Length of the DATA or RESPONSE. Restricted SIM Access, Generic SIM Access Message */
+#define MAX_SEC_NUM_LOCK_TYPE                   8       /* Maximum number of Lock Type used in Lock Information Message */
+#define MAX_SEC_IMS_AUTH_LEN                    512     /* Maximum Length of IMS Authentication Message */
+
+/*=============================================================
+                            String Preprocessor
+==============================================================*/
+#define CR      '\r'        /* Carriage Return */
+
+/*=============================================================
+                            Developer
+==============================================================*/
+#define SMS_SWAPBYTES16(x) (((x) & 0xffff0000) | (((x) & 0x0000ff00) >> 8) | (((x) & 0x000000ff) << 8))
+
+void print_glib_list_elem(gpointer data, gpointer user_data);
+
+static void on_response_class2_read_msg(TcorePending *pending, int data_len, const void *data, void *user_data);
+
+
+gboolean util_byte_to_hex(const char *byte_pdu, char *hex_pdu, int num_bytes);
+
+/* gaurav.kalra: For test */
+void print_glib_list_elem(gpointer data, gpointer user_data)
+{
+       char *item = (char *) data;
+
+       dbg("item: [%s]", item);
+}
+
+/*=============================================================
+                            Send Callback
+==============================================================*/
+static void on_confirmation_sms_message_send(TcorePending *p, gboolean result, void *user_data)
+{
+       dbg("Entered Function. Request message out from queue");
+
+       dbg("TcorePending: [%p]", p);
+       dbg("result: [%02x]", result);
+       dbg("user_data: [%p]", user_data);
+
+       if (result == TRUE) {
+               dbg("SEND OK");
+       } else { /* Failed */
+               dbg("SEND NOK");
+       }
+
+       dbg("Exiting Function. Nothing to return");
+}
+
+/*=============================================================
+                            Utilities
+==============================================================*/
+static void util_sms_free_memory(void *sms_ptr)
+{
+       dbg("Entry");
+
+       if (NULL != sms_ptr) {
+               dbg("Freeing memory location: [%p]", sms_ptr);
+               free(sms_ptr);
+               sms_ptr = NULL;
+       } else {
+               err("Invalid memory location. Nothing to do.");
+       }
+
+       dbg("Exit");
+}
+
+
+static int util_sms_decode_smsParameters(unsigned char *incoming, unsigned int length, struct telephony_sms_Params *params)
+{
+       int alpha_id_len = 0;
+       int i = 0;
+       int nOffset = 0;
+
+       dbg(" RecordLen = %d", length);
+
+       if (incoming == NULL || params == NULL)
+               return FALSE;
+
+       alpha_id_len = length - SMS_SMSP_PARAMS_MAX_LEN;
+
+       if (alpha_id_len > 0) {
+               if (alpha_id_len > SMS_SMSP_ALPHA_ID_LEN_MAX) {
+                       alpha_id_len = SMS_SMSP_ALPHA_ID_LEN_MAX;
+               }
+
+               for (i = 0; i < alpha_id_len; i++) {
+                       if (0xff == incoming[i]) {
+                               dbg(" found");
+                               break;
+                       }
+               }
+
+               memcpy(params->szAlphaId, incoming, i);
+
+               params->alphaIdLen = i;
+
+               dbg(" Alpha id length = %d", i);
+       } else {
+               params->alphaIdLen = 0;
+               dbg(" Alpha id length is zero");
+       }
+
+       // dongil01.park - start parse from here.
+       params->paramIndicator = incoming[alpha_id_len];
+
+       dbg(" Param Indicator = %02x", params->paramIndicator);
+
+       // dongil01.park(2008/12/26) - DestAddr
+       if ((params->paramIndicator & SMSPValidDestAddr) == 0) {
+               nOffset = nDestAddrOffset;
+
+               if (0x00 == incoming[alpha_id_len + nOffset] || 0xff == incoming[alpha_id_len + nOffset]) {
+                       params->tpDestAddr.dialNumLen = 0;
+
+                       dbg("DestAddr Length is 0");
+               } else {
+                       if (0 < (int) incoming[alpha_id_len + nOffset]) {
+                               params->tpDestAddr.dialNumLen = (int) (incoming[alpha_id_len + nOffset] - 1);
+
+                               if (params->tpDestAddr.dialNumLen > SMS_SMSP_ADDRESS_LEN)
+                                       params->tpDestAddr.dialNumLen = SMS_SMSP_ADDRESS_LEN;
+                       } else {
+                               params->tpDestAddr.dialNumLen = 0;
+                       }
+
+                       params->tpDestAddr.numPlanId = incoming[alpha_id_len + (++nOffset)] & 0x0f;
+                       params->tpDestAddr.typeOfNum = (incoming[alpha_id_len + nOffset] & 0x70) >> 4;
+
+                       memcpy(params->tpDestAddr.diallingNum, &incoming[alpha_id_len + (++nOffset)], (params->tpDestAddr.dialNumLen));
+
+                       dbg("Dest TON is %d", params->tpDestAddr.typeOfNum);
+                       dbg("Dest NPI is %d", params->tpDestAddr.numPlanId);
+                       dbg("Dest Length = %d", params->tpDestAddr.dialNumLen);
+                       dbg("Dest Addr = %s", params->tpDestAddr.diallingNum);
+               }
+       } else {
+               params->tpDestAddr.dialNumLen = 0;
+       }
+
+       // dongil01.park(2008/12/26) - SvcAddr
+       if ((params->paramIndicator & SMSPValidSvcAddr) == 0) {
+               nOffset = nSCAAddrOffset;
+
+               if (0x00 == (int) incoming[alpha_id_len + nOffset] || 0xff == (int) incoming[alpha_id_len + nOffset]) {
+                       params->tpSvcCntrAddr.dialNumLen = 0;
+
+                       dbg(" SCAddr Length is 0");
+               } else {
+                       if (0 < (int) incoming[alpha_id_len + nOffset]) {
+                               params->tpSvcCntrAddr.dialNumLen = (int) (incoming[alpha_id_len + nOffset] - 1);
+
+                               if (params->tpSvcCntrAddr.dialNumLen > SMS_SMSP_ADDRESS_LEN)
+                                       params->tpSvcCntrAddr.dialNumLen = SMS_SMSP_ADDRESS_LEN;
+
+                               params->tpSvcCntrAddr.numPlanId = incoming[alpha_id_len + (++nOffset)] & 0x0f;
+                               params->tpSvcCntrAddr.typeOfNum = (incoming[alpha_id_len + nOffset] & 0x70) >> 4;
+
+                               memcpy(params->tpSvcCntrAddr.diallingNum, &incoming[alpha_id_len + (++nOffset)], (params->tpSvcCntrAddr.dialNumLen));
+
+                               dbg("SCAddr Length = %d ", params->tpSvcCntrAddr.dialNumLen);
+                               dbg("SCAddr TON is %d", params->tpSvcCntrAddr.typeOfNum);
+                               dbg("SCAddr NPI is %d", params->tpSvcCntrAddr.numPlanId);
+
+                               for (i = 0; i < (int) params->tpSvcCntrAddr.dialNumLen; i++)
+                                       dbg("SCAddr = %d [%02x]", i, params->tpSvcCntrAddr.diallingNum[i]);
+                       } else {
+                               params->tpSvcCntrAddr.dialNumLen = 0;
+                       }
+               }
+       } else if ((0x00 < (int) incoming[alpha_id_len + nSCAAddrOffset] && (int) incoming[alpha_id_len + nSCAAddrOffset] <= 12)
+                          || 0xff != (int) incoming[alpha_id_len + nSCAAddrOffset]) {
+               nOffset = nSCAAddrOffset;
+
+               if (0x00 == (int) incoming[alpha_id_len + nOffset] || 0xff == (int) incoming[alpha_id_len + nOffset]) {
+                       params->tpSvcCntrAddr.dialNumLen = 0;
+                       dbg("SCAddr Length is 0");
+               } else {
+                       if (0 < (int) incoming[alpha_id_len + nOffset]) {
+                               params->tpSvcCntrAddr.dialNumLen = (int) (incoming[alpha_id_len + nOffset] - 1);
+
+                               params->tpSvcCntrAddr.dialNumLen = incoming[alpha_id_len + nOffset] - 1;
+
+                               if (params->tpSvcCntrAddr.dialNumLen > SMS_SMSP_ADDRESS_LEN)
+                                       params->tpSvcCntrAddr.dialNumLen = SMS_SMSP_ADDRESS_LEN;
+
+                               params->tpSvcCntrAddr.numPlanId = incoming[alpha_id_len + (++nOffset)] & 0x0f;
+                               params->tpSvcCntrAddr.typeOfNum = (incoming[alpha_id_len + nOffset] & 0x70) >> 4;
+
+                               memcpy(params->tpSvcCntrAddr.diallingNum, &incoming[alpha_id_len + (++nOffset)],
+                                          (params->tpSvcCntrAddr.dialNumLen));
+
+                               dbg("SCAddr Length = %d ", params->tpSvcCntrAddr.dialNumLen);
+                               dbg("SCAddr TON is %d", params->tpSvcCntrAddr.typeOfNum);
+                               dbg("SCAddr NPI is %d", params->tpSvcCntrAddr.numPlanId);
+
+                               for (i = 0; i < (int) params->tpSvcCntrAddr.dialNumLen; i++)
+                                       dbg("SCAddr = %d [%02x]", i, params->tpSvcCntrAddr.diallingNum[i]);
+                       } else {
+                               params->tpSvcCntrAddr.dialNumLen = 0;
+                       }
+               }
+       } else {
+               params->tpSvcCntrAddr.dialNumLen = 0;
+       }
+
+       if ((params->paramIndicator & SMSPValidPID) == 0 && (alpha_id_len + nPIDOffset) < MAX_GSM_SMS_PARAM_RECORD_SIZE) {
+               params->tpProtocolId = incoming[alpha_id_len + nPIDOffset];
+       }
+       if ((params->paramIndicator & SMSPValidDCS) == 0 && (alpha_id_len + nDCSOffset) < MAX_GSM_SMS_PARAM_RECORD_SIZE) {
+               params->tpDataCodingScheme = incoming[alpha_id_len + nDCSOffset];
+       }
+       if ((params->paramIndicator & SMSPValidVP) == 0 && (alpha_id_len + nVPOffset) < MAX_GSM_SMS_PARAM_RECORD_SIZE) {
+               params->tpValidityPeriod = incoming[alpha_id_len + nVPOffset];
+       }
+
+       dbg(" Alpha Id(Len) = %d", (int) params->alphaIdLen);
+
+       for (i = 0; i < (int) params->alphaIdLen; i++) {
+               dbg(" Alpha Id = [%d] [%c]", i, params->szAlphaId[i]);
+       }
+       dbg(" PID = %d", params->tpProtocolId);
+       dbg(" DCS = %d", params->tpDataCodingScheme);
+       dbg(" VP = %d", params->tpValidityPeriod);
+
+       return TRUE;
+}
+
+
+/*=============================================================
+                            Notifications
+==============================================================*/
+static gboolean on_event_sms_ready_status(CoreObject *o, const void *event_info, void *user_data)
+{
+       struct tnoti_sms_ready_status readyStatusInfo = {0, };
+       char *line = NULL;
+       GSList *tokens = NULL;
+       GSList *lines = NULL;
+       char *pResp = NULL;
+       // CoreObject *o = NULL;
+
+       int rtn = -1, status = 0;
+
+       dbg(" Func Entrance");
+
+       lines = (GSList *) event_info;
+       if (1 != g_slist_length(lines)) {
+               dbg("unsolicited msg but multiple line");
+               goto OUT;
+       }
+       line = (char *) (lines->data);
+
+       dbg(" Func Entrance");
+
+       if (line != NULL) {
+               dbg("Response OK");
+               dbg("noti line is %s", line);
+               tokens = tcore_at_tok_new(line);
+               pResp = g_slist_nth_data(tokens, 0);
+               if (pResp != NULL)
+                       status = atoi(pResp);
+       } else {
+               dbg("Response NOK");
+       }
+
+       if (status == AT_SMS_DEVICE_READY) {
+               readyStatusInfo.status = SMS_DEVICE_READY;
+               tcore_sms_set_ready_status(o, readyStatusInfo.status);
+               dbg("SMS Ready status = [%s]", readyStatusInfo.status ? "TRUE" : "FALSE");
+               rtn = tcore_server_send_notification(tcore_plugin_ref_server(tcore_object_ref_plugin(o)), o, TNOTI_SMS_DEVICE_READY, sizeof(struct tnoti_sms_ready_status), &readyStatusInfo);
+               dbg(" Return value [%d]", rtn);
+       } else {
+               readyStatusInfo.status = SMS_DEVICE_NOT_READY;
+       }
+
+OUT:
+       if (NULL != tokens)
+               tcore_at_tok_free(tokens);
+       return TRUE;
+}
+
+static gboolean on_event_class2_sms_incom_msg(CoreObject *obj, const void *event_info, void *user_data)
+{
+       // +CMTI: <mem>,<index>
+
+       GSList *tokens = NULL, *lines = NULL;
+       char *line = NULL, *cmd_str = NULL;
+       int index = 0, mem_type = 0;
+       TcoreHal *hal = NULL;
+       TcoreATRequest *atreq = NULL;
+       TcorePending *pending = NULL;
+
+       dbg("Entered Function");
+
+       lines = (GSList *) event_info;
+       line = (char *) g_slist_nth_data(lines, 0); /* Fetch Line 1 */
+
+       dbg("Line 1: [%s]", line);
+
+       if (!line) {
+               err("Line 1 is invalid");
+               return FALSE;
+       }
+
+       tokens = tcore_at_tok_new(line); /* Split Line 1 into tokens */
+       mem_type = atoi(g_slist_nth_data(tokens, 0));       // Type of Memory stored
+       index = atoi((char *) g_slist_nth_data(tokens, 1));
+
+       hal = tcore_object_get_hal(obj);
+       if (NULL == hal) {
+               err("NULL input. Unable to proceed");
+               dbg("readMsg: hal: [%p]", hal);
+
+               dbg("Exit");
+               return TCORE_RETURN_EINVAL;
+       }
+
+       dbg("index: [%d]", index);
+
+       cmd_str = g_strdup_printf("AT+CMGR=%d", index);
+       atreq = tcore_at_request_new((const char *) cmd_str, "+CMGR", TCORE_AT_PDU);
+       pending = tcore_pending_new(obj, 0);
+
+       if (NULL == cmd_str || NULL == atreq || NULL == pending) {
+               err("Out of memory. Unable to proceed");
+               dbg("cmd_str: [%p], atreq: [%p], pending: [%p]", cmd_str, atreq, pending);
+
+               // free memory we own
+               g_free(cmd_str);
+               util_sms_free_memory(atreq);
+               util_sms_free_memory(pending);
+
+               dbg("Exit");
+               return TCORE_RETURN_ENOMEM;
+       }
+
+       util_hex_dump("    ", strlen(cmd_str), (void *) cmd_str);
+
+       tcore_pending_set_request_data(pending, 0, atreq);
+       tcore_pending_set_response_callback(pending, on_response_class2_read_msg, (void *) (uintptr_t) index); // storing index as user data for response
+       tcore_pending_link_user_request(pending, NULL);
+       tcore_pending_set_send_callback(pending, on_confirmation_sms_message_send, NULL);
+       tcore_hal_send_request(hal, pending);
+       g_free(cmd_str);
+
+       if (tokens)
+               tcore_at_tok_free(tokens);
+
+       return TRUE;
+}
+
+static gboolean on_event_sms_incom_msg(CoreObject *o, const void *event_info, void *user_data)
+{
+       // +CMT: [<alpha>],<length><CR><LF><pdu> (PDU mode enabled);
+
+       int rtn = -1;
+       GSList *tokens = NULL;
+       GSList *lines = NULL;
+       char *line = NULL;
+       int pdu_len = 0, no_of_tokens = 0;
+       unsigned char *bytePDU = NULL;
+       struct tnoti_sms_umts_msg gsmMsgInfo;
+       int sca_length = 0;
+
+       dbg("Entered Function");
+
+       lines = (GSList *) event_info;
+       memset(&gsmMsgInfo, 0x00, sizeof(struct tnoti_sms_umts_msg));
+
+       if (2 != g_slist_length(lines)) {
+               err("Invalid number of lines for +CMT. Must be 2");
+               return FALSE;
+       }
+
+       line = (char *) g_slist_nth_data(lines, 0); /* Fetch Line 1 */
+
+       dbg("Line 1: [%s]", line);
+
+       if (!line) {
+               err("Line 1 is invalid");
+               return FALSE;
+       }
+
+       tokens = tcore_at_tok_new(line); /* Split Line 1 into tokens */
+
+       no_of_tokens = g_slist_length(tokens);
+
+       if (no_of_tokens == 2) { // in case of incoming SMS +CMT
+               dbg("Alpha ID: [%02x]", g_slist_nth_data(tokens, 0)); /* 0: Alpha ID */
+               pdu_len = atoi((char *) g_slist_nth_data(tokens, 1));
+               dbg("pdu_len: [%d]", pdu_len);  /* 1: PDU Length */
+       } else if (no_of_tokens == 1) { // in case of incoming status report +CDS
+               pdu_len = atoi((char *) g_slist_nth_data(tokens, 0));
+               dbg("pdu_len: [%d]", pdu_len);  /* 1: PDU Length */
+       }
+
+       line = (char *) g_slist_nth_data(lines, 1); /* Fetch Line 2 */
+
+       dbg("Line 2: [%s]", line);
+
+       if (!line) {
+               err("Line 2 is invalid");
+               return FALSE;
+       }
+
+       /* Convert to Bytes */
+       bytePDU = (unsigned char *) util_hexStringToBytes(line);
+
+       sca_length = bytePDU[0];
+
+       dbg("SCA length = %d", sca_length);
+
+       gsmMsgInfo.msgInfo.msgLength = pdu_len - (sca_length + 1);
+
+       if (sca_length == 0) {
+               memcpy(gsmMsgInfo.msgInfo.tpduData, &bytePDU[1], gsmMsgInfo.msgInfo.msgLength);
+       } else {
+               memcpy(gsmMsgInfo.msgInfo.sca, &bytePDU[1], sca_length);
+               memcpy(gsmMsgInfo.msgInfo.tpduData, &bytePDU[sca_length + 1], gsmMsgInfo.msgInfo.msgLength);
+       }
+
+       util_hex_dump("      ", strlen(line) / 2, bytePDU);
+       util_hex_dump("      ", sca_length, gsmMsgInfo.msgInfo.sca);
+       util_hex_dump("      ", gsmMsgInfo.msgInfo.msgLength, gsmMsgInfo.msgInfo.tpduData);
+
+       rtn = tcore_server_send_notification(tcore_plugin_ref_server(tcore_object_ref_plugin(o)), o, TNOTI_SMS_INCOM_MSG, sizeof(struct tnoti_sms_umts_msg), &gsmMsgInfo);
+
+       if (tokens)
+               tcore_at_tok_free(tokens);
+
+       free(bytePDU);
+
+       return TRUE;
+}
+
+
+
+static gboolean on_event_sms_memory_status(CoreObject *o, const void *event_info, void *user_data)
+{
+       struct tnoti_sms_memory_status memStatusInfo = {0, };
+
+       int rtn = -1, memoryStatus = -1;
+       GSList *tokens = NULL;
+       GSList *lines = NULL;
+       char *line = NULL, *pResp = NULL;
+
+       dbg(" Entry");
+
+       lines = (GSList *) event_info;
+       if (1 != g_slist_length(lines)) {
+               dbg("unsolicited msg but multiple line");
+       }
+
+       line = (char *) (lines->data);
+
+       if (line) {
+               dbg("Response OK");
+               tokens = tcore_at_tok_new(line);
+               pResp = g_slist_nth_data(tokens, 0);
+
+               if (pResp) {
+                       memoryStatus = atoi(pResp);
+                       dbg("memoryStatus is %d", memoryStatus);
+                       if (memoryStatus == 0) { // SIM Full condition
+                               memStatusInfo.status = SMS_PHONE_MEMORY_STATUS_FULL;
+                       }
+                       rtn = tcore_server_send_notification(tcore_plugin_ref_server(tcore_object_ref_plugin(o)), o, TNOTI_SMS_MEMORY_STATUS, sizeof(struct tnoti_sms_memory_status), &memStatusInfo);
+               }
+               tcore_at_tok_free(tokens);
+       } else {
+               dbg("Response NOK");
+       }
+
+       dbg(" Exit ");
+       return TRUE;
+}
+
+static gboolean on_event_sms_cb_incom_msg(CoreObject *o, const void *event_info, void *user_data)
+{
+       // +CBM: <length><CR><LF><pdu>
+
+       struct tnoti_sms_cellBroadcast_msg cbMsgInfo;
+
+       int rtn = -1, length = 0;
+       char *line = NULL, *pdu = NULL, *pResp = NULL;
+       GSList *tokens = NULL;
+       GSList *lines = NULL;
+
+       dbg(" Func Entrance");
+
+       lines = (GSList *) event_info;
+
+       memset(&cbMsgInfo, 0, sizeof(struct tnoti_sms_cellBroadcast_msg));
+
+       line = (char *) (lines->data);
+
+       if (line != NULL) {
+               dbg("Response OK");
+               dbg("Noti line is %s", line);
+               tokens = tcore_at_tok_new(line); /* Split Line 1 into tokens */
+
+               pResp = g_slist_nth_data(tokens, 0);
+               if (pResp) {
+                       length = atoi(pResp);
+               } else {
+                       dbg("token 0 is null");
+               }
+
+               pdu = g_slist_nth_data(lines, 1);
+               if (pdu != NULL) {
+                       cbMsgInfo.cbMsg.length = length;
+                       cbMsgInfo.cbMsg.cbMsgType = SMS_CB_MSG_CBS;
+
+                       dbg("CB Msg LENGTH [%2x]", length);
+
+                       if ((cbMsgInfo.cbMsg.length > 0) && (SMS_CB_SIZE_MAX >= cbMsgInfo.cbMsg.length)) {
+                               unsigned char *byte_pdu = NULL;
+
+                               byte_pdu = (unsigned char *) util_hexStringToBytes(pdu);
+
+                               memcpy(cbMsgInfo.cbMsg.msgData, (char *) byte_pdu, cbMsgInfo.cbMsg.length);
+                               rtn = tcore_server_send_notification(tcore_plugin_ref_server(tcore_object_ref_plugin(o)), o, TNOTI_SMS_CB_INCOM_MSG, sizeof(struct tnoti_sms_cellBroadcast_msg), &cbMsgInfo);
+                               free(byte_pdu);
+                       } else {
+                               dbg("Invalid Message Length");
+                       }
+               } else {
+                       dbg("Recieved NULL pdu");
+               }
+       } else {
+               dbg("Response NOK");
+       }
+
+       dbg(" Return value [%d]", rtn);
+
+       if (tokens)
+               tcore_at_tok_free(tokens);
+
+       return TRUE;
+}
+
+
+/*=============================================================
+                            Responses
+==============================================================*/
+static void on_response_sms_delete_msg(TcorePending *p, int data_len, const void *data, void *user_data)
+{
+       struct tresp_sms_delete_msg delMsgInfo = {0, };
+       UserRequest *ur = NULL;
+       const TcoreATResponse *atResp = data;
+
+       int rtn = -1;
+       int index = (int) user_data;
+
+       dbg(" Func Entrance");
+
+       ur = tcore_pending_ref_user_request(p);
+       if (atResp->success) {
+               dbg("Response OK");
+               delMsgInfo.index = index;
+               delMsgInfo.result = SMS_SENDSMS_SUCCESS;
+       } else {
+               dbg("Response NOK");
+               delMsgInfo.index = index;
+               delMsgInfo.result = SMS_DEVICE_FAILURE;
+       }
+
+       rtn = tcore_user_request_send_response(ur, TRESP_SMS_DELETE_MSG, sizeof(struct tresp_sms_delete_msg), &delMsgInfo);
+
+       return;
+}
+
+static void on_response_sms_save_msg(TcorePending *p, int data_len, const void *data, void *user_data)
+{
+       struct tresp_sms_save_msg saveMsgInfo = {0, };
+       UserRequest *ur = NULL;
+       const TcoreATResponse *atResp = data;
+       GSList *tokens = NULL;
+       char *line = NULL;
+       char *pResp = NULL;
+       int rtn = -1;
+
+       ur = tcore_pending_ref_user_request(p);
+       if (atResp->success) {
+               dbg("Response OK");
+               if (atResp->lines) {
+                       line = (char *) atResp->lines->data;
+                       tokens = tcore_at_tok_new(line);
+                       pResp = g_slist_nth_data(tokens, 0);
+                       if (pResp) {
+                               dbg("0: %s", pResp);
+                               saveMsgInfo.index = (atoi(pResp) - 1); /* IMC index starts from 1 */
+                               saveMsgInfo.result = SMS_SENDSMS_SUCCESS;
+                       } else {
+                               dbg("No Tokens");
+                               saveMsgInfo.index = -1;
+                               saveMsgInfo.result = SMS_DEVICE_FAILURE;
+                       }
+                       tcore_at_tok_free(tokens);
+               }
+       } else {
+               dbg("Response NOK");
+               saveMsgInfo.index = -1;
+               saveMsgInfo.result = SMS_DEVICE_FAILURE;
+       }
+
+       rtn = tcore_user_request_send_response(ur, TRESP_SMS_SAVE_MSG, sizeof(struct tresp_sms_save_msg), &saveMsgInfo);
+       dbg("Return value [%d]", rtn);
+       return;
+}
+
+static void on_response_send_umts_msg(TcorePending *pending, int data_len, const void *data, void *user_data)
+{
+       const TcoreATResponse *at_response = data;
+       struct tresp_sms_send_umts_msg resp_umts;
+       UserRequest *user_req = NULL;
+
+       int msg_ref = 0;
+       GSList *tokens = NULL;
+       char *gslist_line = NULL, *line_token = NULL;
+
+       dbg("Entry");
+
+       user_req = tcore_pending_ref_user_request(pending);
+
+       if (NULL == user_req) {
+               err("No user request");
+
+               dbg("Exit");
+               return;
+       }
+
+       memset(&resp_umts, 0x00, sizeof(resp_umts));
+       resp_umts.result = SMS_DEVICE_FAILURE;
+
+       if (at_response->success > 0) { // success
+               dbg("Response OK");
+               if (at_response->lines) { // lines present in at_response
+                       gslist_line = (char *) at_response->lines->data;
+                       dbg("gslist_line: [%s]", gslist_line);
+
+                       tokens = tcore_at_tok_new(gslist_line); // extract tokens
+
+                       line_token = g_slist_nth_data(tokens, 0);
+                       if (line_token != NULL) {
+                               msg_ref = atoi(line_token);
+                               dbg("Message Reference: [%d]", msg_ref);
+
+                               resp_umts.result = SMS_SENDSMS_SUCCESS;
+                       } else {
+                               dbg("No Message Reference received");
+                       }
+                       tcore_at_tok_free(tokens);
+               } else { // no lines in at_response
+                       dbg("No lines");
+               }
+       } else { // failure
+               dbg("Response NOK");
+       }
+
+       tcore_user_request_send_response(user_req, TRESP_SMS_SEND_UMTS_MSG, sizeof(resp_umts), &resp_umts);
+
+       dbg("Exit");
+       return;
+}
+
+static void on_response_class2_read_msg(TcorePending *pending, int data_len, const void *data, void *user_data)
+{
+       const TcoreATResponse *at_response = data;
+       GSList *tokens = NULL;
+       char *gslist_line = NULL, *line_token = NULL, *hex_pdu = NULL;
+       int pdu_len = 0, rtn = 0;
+       unsigned char *bytePDU = NULL;
+       struct tnoti_sms_umts_msg gsmMsgInfo;
+       int sca_length = 0;
+
+       dbg("Entry");
+       dbg("lines: [%p]", at_response->lines);
+       g_slist_foreach(at_response->lines, print_glib_list_elem, NULL); // for debug log
+
+       if (at_response->success > 0) {
+               dbg("Response OK");
+               if (at_response->lines) {
+                       // fetch first line
+                       gslist_line = (char *) at_response->lines->data;
+
+                       dbg("gslist_line: [%s]", gslist_line);
+
+                       tokens = tcore_at_tok_new(gslist_line);
+                       dbg("Number of tokens: [%d]", g_slist_length(tokens));
+                       g_slist_foreach(tokens, print_glib_list_elem, NULL); // for debug log
+
+                       line_token = g_slist_nth_data(tokens, 2); // Third Token: Length
+                       if (line_token != NULL) {
+                               pdu_len = atoi(line_token);
+                               dbg("Length: [%d]", pdu_len);
+                       }
+
+                       // fetch second line
+                       gslist_line = (char *) at_response->lines->next->data;
+
+                       dbg("gslist_line: [%s]", gslist_line);
+
+                       // free the consumed token
+                       tcore_at_tok_free(tokens);
+
+                       tokens = tcore_at_tok_new(gslist_line);
+                       dbg("Number of tokens: [%d]", g_slist_length(tokens));
+                       g_slist_foreach(tokens, print_glib_list_elem, NULL); // for debug log
+
+                       hex_pdu = g_slist_nth_data(tokens, 0); // Fetch SMS PDU
+
+                       // free the consumed token
+                       tcore_at_tok_free(tokens);
+               } else {
+                       dbg("No lines");
+               }
+       } else {
+               err("Response NOK");
+       }
+
+       /* Convert to Bytes */
+       bytePDU = (unsigned char *) util_hexStringToBytes(hex_pdu);
+
+       sca_length = bytePDU[0];
+
+       dbg("SCA length = %d", sca_length);
+
+       gsmMsgInfo.msgInfo.msgLength = pdu_len - (sca_length + 1);
+
+       if (sca_length == 0) {
+               memcpy(gsmMsgInfo.msgInfo.tpduData, &bytePDU[1], gsmMsgInfo.msgInfo.msgLength);
+       } else {
+               memcpy(gsmMsgInfo.msgInfo.sca, bytePDU, sca_length);
+               memcpy(gsmMsgInfo.msgInfo.tpduData, &bytePDU[sca_length + 1], gsmMsgInfo.msgInfo.msgLength);
+       }
+
+       util_hex_dump("      ", strlen(hex_pdu) / 2, bytePDU);
+       util_hex_dump("      ", sca_length, gsmMsgInfo.msgInfo.sca);
+       util_hex_dump("      ", gsmMsgInfo.msgInfo.msgLength, gsmMsgInfo.msgInfo.tpduData);
+
+       rtn = tcore_server_send_notification(tcore_plugin_ref_server(tcore_object_ref_plugin(tcore_pending_ref_core_object(pending))), tcore_pending_ref_core_object(pending), TNOTI_SMS_INCOM_MSG, sizeof(struct tnoti_sms_umts_msg), &gsmMsgInfo);
+
+       free(bytePDU);
+
+       dbg("Exit");
+       return;
+}
+
+static void on_response_read_msg(TcorePending *pending, int data_len, const void *data, void *user_data)
+{
+       const TcoreATResponse *at_response = data;
+       struct tresp_sms_read_msg resp_read_msg;
+       UserRequest *user_req = NULL;
+
+       GSList *tokens = NULL;
+       char *gslist_line = NULL, *line_token = NULL, *byte_pdu = NULL, *hex_pdu = NULL;
+       int sca_length = 0;
+       int msg_status = 0, alpha_id = 0, pdu_len = 0;
+       int index = (int) (uintptr_t) user_data;
+
+       dbg("Entry");
+       dbg("index: [%d]", index);
+       g_slist_foreach(at_response->lines, print_glib_list_elem, NULL); // for debug log
+
+       user_req = tcore_pending_ref_user_request(pending);
+       if (NULL == user_req) {
+               err("No user request");
+
+               dbg("Exit");
+               return;
+       }
+
+       memset(&resp_read_msg, 0x00, sizeof(resp_read_msg));
+       resp_read_msg.result = SMS_PHONE_FAILURE;
+
+       if (at_response->success > 0) {
+               dbg("Response OK");
+               if (at_response->lines) {
+                       // fetch first line
+                       gslist_line = (char *) at_response->lines->data;
+
+                       dbg("gslist_line: [%s]", gslist_line);
+
+                       tokens = tcore_at_tok_new(gslist_line);
+                       dbg("Number of tokens: [%d]", g_slist_length(tokens));
+                       g_slist_foreach(tokens, print_glib_list_elem, NULL); // for debug log
+
+                       line_token = g_slist_nth_data(tokens, 0); // First Token: Message Status
+                       if (line_token != NULL) {
+                               msg_status = atoi(line_token);
+                               dbg("msg_status is %d", msg_status);
+                               switch (msg_status) {
+                               case AT_REC_UNREAD:
+                                       resp_read_msg.dataInfo.msgStatus = SMS_STATUS_UNREAD;
+                                       break;
+
+                               case AT_REC_READ:
+                                       resp_read_msg.dataInfo.msgStatus = SMS_STATUS_READ;
+                                       break;
+
+                               case AT_STO_UNSENT:
+                                       resp_read_msg.dataInfo.msgStatus = SMS_STATUS_UNSENT;
+                                       break;
+
+                               case AT_STO_SENT:
+                                       resp_read_msg.dataInfo.msgStatus = SMS_STATUS_SENT;
+                                       break;
+
+                               case AT_ALL:     // Fall Through
+                               default:     // Fall Through
+                                       resp_read_msg.dataInfo.msgStatus = SMS_STATUS_RESERVED;
+                                       break;
+                               }
+                       }
+
+                       line_token = g_slist_nth_data(tokens, 1); // Second Token: AlphaID
+                       if (line_token != NULL) {
+                               alpha_id = atoi(line_token);
+                               dbg("AlphaID: [%d]", alpha_id);
+                       }
+
+                       line_token = g_slist_nth_data(tokens, 2); // Third Token: Length
+                       if (line_token != NULL) {
+                               pdu_len = atoi(line_token);
+                               dbg("Length: [%d]", pdu_len);
+                       }
+
+                       // fetch second line
+                       hex_pdu = (char *) at_response->lines->next->data;
+
+                       dbg("EF-SMS PDU: [%s]", hex_pdu);
+
+                       // free the consumed token
+                       tcore_at_tok_free(tokens);
+
+                       if (NULL != hex_pdu) {
+                               util_hex_dump("    ", sizeof(hex_pdu), (void *) hex_pdu);
+
+                               byte_pdu = util_hexStringToBytes(hex_pdu);
+
+                               sca_length = (int) byte_pdu[0];
+
+                               resp_read_msg.dataInfo.simIndex = index; // Retrieving index stored as user_data
+
+                               dbg("SCA Length : %d", sca_length);
+
+                               resp_read_msg.dataInfo.smsData.msgLength = pdu_len;
+                               dbg("msgLength: [%d]", resp_read_msg.dataInfo.smsData.msgLength);
+
+                               if (0 == sca_length) {
+                                       if ((resp_read_msg.dataInfo.smsData.msgLength > 0)
+                                               && (resp_read_msg.dataInfo.smsData.msgLength <= SMS_SMDATA_SIZE_MAX)) {
+                                               memset(resp_read_msg.dataInfo.smsData.sca, 0, TAPI_SIM_SMSP_ADDRESS_LEN);
+                                               memcpy(resp_read_msg.dataInfo.smsData.tpduData, &byte_pdu[1], resp_read_msg.dataInfo.smsData.msgLength);
+
+                                               resp_read_msg.result = SMS_SUCCESS;
+                                       } else {
+                                               dbg("Invalid Message Length");
+                                               resp_read_msg.result = SMS_INVALID_PARAMETER_FORMAT;
+                                       }
+                               } else {
+                                       if ((resp_read_msg.dataInfo.smsData.msgLength > 0)
+                                               && (resp_read_msg.dataInfo.smsData.msgLength <= SMS_SMDATA_SIZE_MAX)) {
+                                               memcpy(resp_read_msg.dataInfo.smsData.sca, (char *) byte_pdu, (sca_length + 1));
+                                               memcpy(resp_read_msg.dataInfo.smsData.tpduData, &byte_pdu[sca_length + 1], resp_read_msg.dataInfo.smsData.msgLength);
+
+                                               util_hex_dump("    ", SMS_SMSP_ADDRESS_LEN, (void *) resp_read_msg.dataInfo.smsData.sca);
+                                               util_hex_dump("    ", (SMS_SMDATA_SIZE_MAX + 1), (void *) resp_read_msg.dataInfo.smsData.tpduData);
+                                               util_hex_dump("    ", sizeof(byte_pdu), (void *) byte_pdu);
+
+                                               resp_read_msg.result = SMS_SUCCESS;
+                                       } else {
+                                               dbg("Invalid Message Length");
+                                               resp_read_msg.result = SMS_INVALID_PARAMETER_FORMAT;
+                                       }
+                               }
+                               free(byte_pdu);
+                       } else {
+                               dbg("NULL PDU");
+                       }
+               } else {
+                       dbg("No lines");
+               }
+       } else {
+               err("Response NOK");
+       }
+
+       tcore_user_request_send_response(user_req, TRESP_SMS_READ_MSG, sizeof(resp_read_msg), &resp_read_msg);
+
+       dbg("Exit");
+       return;
+}
+
+static void on_response_get_msg_indices(TcorePending *pending, int data_len, const void *data, void *user_data)
+{
+       const TcoreATResponse *at_response = data;
+       struct tresp_sms_get_storedMsgCnt resp_stored_msg_cnt;
+       UserRequest *user_req = NULL;
+       struct tresp_sms_get_storedMsgCnt *resp_stored_msg_cnt_prev = NULL;
+
+       GSList *tokens = NULL;
+       char *gslist_line = NULL, *line_token = NULL;
+       int gslist_line_count = 0, ctr_loop = 0;
+
+       dbg("Entry");
+
+       resp_stored_msg_cnt_prev = (struct tresp_sms_get_storedMsgCnt *) user_data;
+       user_req = tcore_pending_ref_user_request(pending);
+
+       memset(&resp_stored_msg_cnt, 0x00, sizeof(resp_stored_msg_cnt));
+       resp_stored_msg_cnt.result = SMS_DEVICE_FAILURE;
+
+       if (at_response->success) {
+               dbg("Response OK");
+               if (at_response->lines) {
+                       gslist_line_count = g_slist_length(at_response->lines);
+
+                       if (gslist_line_count > SMS_GSM_SMS_MSG_NUM_MAX)
+                               gslist_line_count = SMS_GSM_SMS_MSG_NUM_MAX;
+
+                       dbg("Number of lines: [%d]", gslist_line_count);
+                       g_slist_foreach(at_response->lines, print_glib_list_elem, NULL); // for debug log
+
+                       for (ctr_loop = 0; ctr_loop < gslist_line_count; ctr_loop++) {
+                               gslist_line = (char *) g_slist_nth_data(at_response->lines, ctr_loop); /* Fetch Line i */
+
+                               dbg("gslist_line [%d] is [%s]", ctr_loop, gslist_line);
+
+                               if (NULL != gslist_line) {
+                                       tokens = tcore_at_tok_new(gslist_line);
+
+                                       g_slist_foreach(tokens, print_glib_list_elem, NULL); // for debug log
+
+                                       line_token = g_slist_nth_data(tokens, 0);
+                                       if (NULL != line_token) {
+                                               resp_stored_msg_cnt.storedMsgCnt.indexList[ctr_loop] = atoi(line_token);
+                                               resp_stored_msg_cnt.result = SMS_SENDSMS_SUCCESS;
+                                       } else {
+                                               dbg("line_token of gslist_line [%d] is NULL", ctr_loop);
+                                               continue;
+                                       }
+                                       tcore_at_tok_free(tokens);
+                               } else {
+                                       dbg("gslist_line [%d] is NULL", ctr_loop);
+                                       continue;
+                               }
+                       }
+               } else {
+                       dbg("No lines.");
+                       if (resp_stored_msg_cnt_prev->storedMsgCnt.usedCount == 0) { // Check if used count is zero
+                               resp_stored_msg_cnt.result = SMS_SENDSMS_SUCCESS;
+                       }
+               }
+       } else {
+               dbg("Respnose NOK");
+       }
+
+       resp_stored_msg_cnt.storedMsgCnt.totalCount = resp_stored_msg_cnt_prev->storedMsgCnt.totalCount;
+       resp_stored_msg_cnt.storedMsgCnt.usedCount = resp_stored_msg_cnt_prev->storedMsgCnt.usedCount;
+
+       util_sms_free_memory(resp_stored_msg_cnt_prev);
+
+       dbg("total: [%d], used: [%d], result: [%d]", resp_stored_msg_cnt.storedMsgCnt.totalCount, resp_stored_msg_cnt.storedMsgCnt.usedCount, resp_stored_msg_cnt.result);
+       for (ctr_loop = 0; ctr_loop < gslist_line_count; ctr_loop++) {
+               dbg("index: [%d]", resp_stored_msg_cnt.storedMsgCnt.indexList[ctr_loop]);
+       }
+
+       tcore_user_request_send_response(user_req, TRESP_SMS_GET_STORED_MSG_COUNT, sizeof(resp_stored_msg_cnt), &resp_stored_msg_cnt);
+
+       dbg("Exit");
+       return;
+}
+
+static void on_response_get_stored_msg_cnt(TcorePending *pending, int data_len, const void *data, void *user_data)
+{
+       UserRequest *ur = NULL, *ur_dup = NULL;
+       struct tresp_sms_get_storedMsgCnt *respStoredMsgCnt = NULL;
+       const TcoreATResponse *atResp = data;
+       GSList *tokens = NULL;
+       char *line = NULL, *pResp = NULL, *cmd_str = NULL;
+       TcoreATRequest *atReq = NULL;
+       int usedCnt = 0, totalCnt = 0, result = 0;
+
+       TcorePending *pending_new = NULL;
+       CoreObject *o = NULL;
+
+       dbg("Entered");
+
+       respStoredMsgCnt = malloc(sizeof(struct tresp_sms_get_storedMsgCnt));
+       result = SMS_DEVICE_FAILURE;
+
+       ur = tcore_pending_ref_user_request(pending);
+       ur_dup = tcore_user_request_ref(ur);
+       o = tcore_pending_ref_core_object(pending);
+
+       if (atResp->success > 0) {
+               dbg("Response OK");
+               if (NULL != atResp->lines) {
+                       line = (char *) atResp->lines->data;
+                       dbg("line is %s", line);
+
+                       tokens = tcore_at_tok_new(line);
+                       pResp = g_slist_nth_data(tokens, 0);
+
+                       if (pResp) {
+                               usedCnt = atoi(pResp);
+                               dbg("used cnt is %d", usedCnt);
+                       }
+
+                       pResp = g_slist_nth_data(tokens, 1);
+                       if (pResp) {
+                               totalCnt = atoi(pResp);
+                               result = SMS_SENDSMS_SUCCESS;
+
+                               respStoredMsgCnt->storedMsgCnt.usedCount = usedCnt;
+                               respStoredMsgCnt->storedMsgCnt.totalCount = totalCnt;
+                               respStoredMsgCnt->result = result;
+
+                               dbg("used %d, total %d, result %d", usedCnt, totalCnt, result);
+
+                               pending_new = tcore_pending_new(o, 0);
+                               // Get all messages information
+                               cmd_str = g_strdup_printf("AT+CMGL=4");
+                               atReq = tcore_at_request_new((const char *) cmd_str, "+CMGL", TCORE_AT_MULTILINE);
+
+                               dbg("cmd str is %s", cmd_str);
+
+                               tcore_pending_set_request_data(pending_new, 0, atReq);
+                               tcore_pending_set_response_callback(pending_new, on_response_get_msg_indices, (void *) respStoredMsgCnt);
+                               tcore_pending_link_user_request(pending_new, ur_dup);
+                               tcore_pending_set_send_callback(pending_new, on_confirmation_sms_message_send, NULL);
+                               tcore_hal_send_request(tcore_object_get_hal(o), pending_new);
+
+                               // free the consumed token
+                               tcore_at_tok_free(tokens);
+
+                               g_free(cmd_str);
+
+                               dbg("Exit");
+                               return;
+                       }
+                       // free the consumed token
+                       if (tokens)
+                               tcore_at_tok_free(tokens);
+               } else {
+                       dbg("No data");
+               }
+       } else {
+               err("Response NOK");
+       }
+       respStoredMsgCnt->result = result;
+       tcore_user_request_send_response(ur, TRESP_SMS_GET_STORED_MSG_COUNT, sizeof(struct tresp_sms_get_storedMsgCnt), &respStoredMsgCnt);
+
+
+       dbg("Exit");
+       return;
+}
+
+static void on_response_get_sca(TcorePending *pending, int data_len, const void *data, void *user_data)
+{
+       const TcoreATResponse *at_response = data;
+       struct tresp_sms_get_sca respGetSca;
+       UserRequest *user_req = NULL;
+
+       GSList *tokens = NULL;
+       char *gslist_line = NULL, *sca_addr = NULL, *sca_toa = NULL;
+
+       dbg("Entry");
+
+       memset(&respGetSca, 0, sizeof(respGetSca));
+       respGetSca.result = SMS_DEVICE_FAILURE;
+
+       user_req = tcore_pending_ref_user_request(pending);
+
+       if (at_response->success) {
+               dbg("Response OK");
+               if (at_response->lines) {
+                       gslist_line = (char *) at_response->lines->data;
+
+                       tokens = tcore_at_tok_new(gslist_line);
+                       sca_addr = g_slist_nth_data(tokens, 0);
+                       sca_toa = g_slist_nth_data(tokens, 1);
+
+                       if ((NULL != sca_addr)
+                               && (NULL != sca_toa)) {
+                               dbg("sca_addr: [%s]. sca_toa: [%s]", sca_addr, sca_toa);
+
+                               respGetSca.scaAddress.dialNumLen = strlen(sca_addr);
+
+                               if (145 == atoi(sca_toa)) {
+                                       respGetSca.scaAddress.typeOfNum = SIM_TON_INTERNATIONAL;
+                               } else {
+                                       respGetSca.scaAddress.typeOfNum = SIM_TON_NATIONAL;
+                               }
+
+                               respGetSca.scaAddress.numPlanId = 0;
+
+                               memcpy(respGetSca.scaAddress.diallingNum, sca_addr, strlen(sca_addr));
+
+                               dbg("len [%d], sca_addr [%s], TON [%d], NPI [%d]", respGetSca.scaAddress.dialNumLen, respGetSca.scaAddress.diallingNum, respGetSca.scaAddress.typeOfNum, respGetSca.scaAddress.numPlanId);
+
+                               respGetSca.result = SMS_SENDSMS_SUCCESS;
+                       } else {
+                               err("sca_addr OR sca_toa NULL");
+                       }
+               } else {
+                       dbg("NO Lines");
+               }
+       } else {
+               dbg("Response NOK");
+       }
+
+       tcore_user_request_send_response(user_req, TRESP_SMS_GET_SCA, sizeof(respGetSca), &respGetSca);
+
+       if (tokens)
+               tcore_at_tok_free(tokens);
+
+       dbg("Exit");
+       return;
+}
+
+static void on_response_set_sca(TcorePending *pending, int data_len, const void *data, void *user_data)
+{
+       /*
+       Response is expected in this format
+       OK
+           or
+       +CMS ERROR: <err>
+       */
+
+       // CoreObject *obj = user_data;
+       UserRequest *ur;
+       // copies the AT response data to resp
+       const TcoreATResponse *atResp = data;
+       struct tresp_sms_set_sca respSetSca;
+
+       memset(&respSetSca, 0, sizeof(struct tresp_sms_set_sca));
+
+       ur = tcore_pending_ref_user_request(pending);
+       if (!ur) {
+               dbg("no user_request");
+               return;
+       }
+
+       if (atResp->success > 0) {
+               dbg("RESPONSE OK");
+               respSetSca.result = SMS_SUCCESS;
+       } else {
+               dbg("RESPONSE NOK");
+               respSetSca.result = SMS_DEVICE_FAILURE;
+       }
+
+       tcore_user_request_send_response(ur, TRESP_SMS_SET_SCA, sizeof(struct tresp_sms_set_sca), &respSetSca);
+
+       return;
+}
+
+static void on_response_get_cb_config(TcorePending *p, int data_len, const void *data, void *user_data)
+{
+       UserRequest *ur;
+       struct tresp_sms_get_cb_config respGetCbConfig;
+       const TcoreATResponse *atResp = data;
+       GSList *tokens = NULL;
+       int i = 0, mode = 0, h_flag = FALSE;
+       char *mid = NULL, *mid1 = NULL, *pResp = NULL, *line = NULL;
+       char delim[] = ",", delim1[] = "-";
+
+       memset(&respGetCbConfig, 0, sizeof(struct tresp_sms_get_cb_config));
+       respGetCbConfig.result = SMS_DEVICE_FAILURE;
+
+       ur = tcore_pending_ref_user_request(p);
+       if (!ur) {
+               dbg("no user_request");
+               return;
+       }
+
+       respGetCbConfig.cbConfig.net3gppType = SMS_NETTYPE_3GPP;
+
+       if (atResp->success) {
+               dbg("Response OK");
+               if (atResp->lines) {
+                       line = (char *) atResp->lines->data;
+                       if (line != NULL) {
+                               dbg("line is %s", line);
+                               tokens = tcore_at_tok_new(line);
+                               pResp = g_slist_nth_data(tokens, 0);
+                               if (pResp) {
+                                       mode = atoi(pResp);
+                                       respGetCbConfig.cbConfig.cbEnabled = mode;
+
+                                       pResp = g_slist_nth_data(tokens, 1);
+                                       if (pResp) {
+                                               mid = strtok(pResp, delim); // check for multiple msg ids seperated by comma delimiter
+                                               while (mid != NULL) {
+                                                       mid1 = strtok(mid, delim1); // check for msg id ranges where delim is hyphen. Ex 0 -21
+                                                       while (mid1 != NULL) {
+                                                               respGetCbConfig.cbConfig.msgIDs[i].net3gpp.fromMsgId = atoi(mid1);
+                                                               mid1 = strtok(NULL, delim1);
+                                                               if (mid1 != NULL) {
+                                                                       respGetCbConfig.cbConfig.msgIDs[i].net3gpp.toMsgId = atoi(mid1);
+                                                               }
+                                                               respGetCbConfig.cbConfig.msgIDs[i].net3gpp.selected = TRUE;
+                                                               respGetCbConfig.result = SMS_SENDSMS_SUCCESS;
+                                                               i++;
+                                                               h_flag = TRUE;
+                                                       }
+                                                       if ((h_flag == FALSE) && (mid != NULL) && (strlen(mid) > 0)) {
+                                                               respGetCbConfig.cbConfig.msgIDs[i].net3gpp.fromMsgId = atoi(mid);
+                                                               respGetCbConfig.cbConfig.msgIDs[i].net3gpp.toMsgId = atoi(mid);
+                                                               respGetCbConfig.cbConfig.msgIDs[i].net3gpp.selected = TRUE;
+                                                               i++;
+                                                               respGetCbConfig.result = SMS_SENDSMS_SUCCESS;
+                                                       }
+                                                       dbg("mid is %s\n", mid);
+                                                       mid = strtok(NULL, delim);
+                                               }
+
+                                               respGetCbConfig.cbConfig.msgIdRangeCount = i;
+                                       } else {
+                                               if (mode == 1) {
+                                                       respGetCbConfig.cbConfig.msgIdRangeCount = 1;
+                                                       respGetCbConfig.cbConfig.msgIDs[0].net3gpp.fromMsgId = 0x0000;
+                                                       respGetCbConfig.cbConfig.msgIDs[0].net3gpp.toMsgId = 0xFFFF;
+                                                       respGetCbConfig.cbConfig.msgIDs[0].net3gpp.selected = TRUE;
+                                                       respGetCbConfig.result = SMS_SENDSMS_SUCCESS;
+                                               } else {
+                                                       respGetCbConfig.cbConfig.msgIdRangeCount = 0;
+                                                       respGetCbConfig.cbConfig.msgIDs[0].net3gpp.selected = FALSE;
+                                                       respGetCbConfig.result = SMS_SENDSMS_SUCCESS;
+                                               }
+                                       }
+                               }
+                       } else {
+                               dbg("line is NULL");
+                       }
+               } else {
+                       dbg("atresp->lines is NULL");
+               }
+       } else {
+               dbg("RESPONSE NOK");
+       }
+
+       tcore_user_request_send_response(ur, TRESP_SMS_GET_CB_CONFIG, sizeof(struct tresp_sms_get_cb_config), &respGetCbConfig);
+
+       if (tokens)
+               tcore_at_tok_free(tokens);
+
+       return;
+}
+
+static void on_response_set_cb_config(TcorePending *pending, int data_len, const void *data, void *user_data)
+{
+       /*
+       Response is expected in this format
+       OK
+           or
+       +CMS ERROR: <err>
+       */
+
+       UserRequest *ur;
+       const TcoreATResponse *resp = data;
+       int response = 0;
+       const char *line = NULL;
+       GSList *tokens = NULL;
+
+       struct tresp_sms_set_cb_config respSetCbConfig = {0, };
+
+       memset(&respSetCbConfig, 0, sizeof(struct tresp_sms_set_cb_config));
+
+       ur = tcore_pending_ref_user_request(pending);
+       respSetCbConfig.result = SMS_SENDSMS_SUCCESS;
+
+       if (resp->success > 0) {
+               dbg("RESPONSE OK");
+       } else {
+               dbg("RESPONSE NOK");
+               line = (const char *) resp->final_response;
+               tokens = tcore_at_tok_new(line);
+
+               if (g_slist_length(tokens) < 1) {
+                       dbg("err cause not specified or string corrupted");
+                       respSetCbConfig.result = SMS_DEVICE_FAILURE;
+               } else {
+                       response = atoi(g_slist_nth_data(tokens, 0));
+                       /* TODO: CMEE error mapping is required. */
+                       respSetCbConfig.result = SMS_DEVICE_FAILURE;
+               }
+       }
+       if (!ur) {
+               dbg("no user_request");
+               return;
+       }
+
+       tcore_user_request_send_response(ur, TRESP_SMS_SET_CB_CONFIG, sizeof(struct tresp_sms_set_cb_config), &respSetCbConfig);
+
+       if (tokens)
+               tcore_at_tok_free(tokens);
+
+       return;
+}
+
+static void on_response_set_mem_status(TcorePending *p, int data_len, const void *data, void *user_data)
+{
+       UserRequest *ur;
+       struct tresp_sms_set_mem_status respSetMemStatus = {0, };
+       const TcoreATResponse *resp = data;
+
+       memset(&respSetMemStatus, 0, sizeof(struct tresp_sms_set_mem_status));
+
+       if (resp->success > 0) {
+               dbg("RESPONSE OK");
+               respSetMemStatus.result = SMS_SENDSMS_SUCCESS;
+       } else {
+               dbg("RESPONSE NOK");
+               respSetMemStatus.result = SMS_DEVICE_FAILURE;
+       }
+
+       ur = tcore_pending_ref_user_request(p);
+       if (!ur) {
+               dbg("no user_request");
+               return;
+       }
+
+       tcore_user_request_send_response(ur, TRESP_SMS_SET_MEM_STATUS, sizeof(struct tresp_sms_set_mem_status), &respSetMemStatus);
+
+       return;
+}
+
+static void on_response_set_msg_status(TcorePending *pending, int data_len, const void *data, void *user_data)
+{
+       UserRequest *ur;
+       struct tresp_sms_set_msg_status respMsgStatus = {0, };
+       const TcoreATResponse *atResp = data;
+       int response = 0, sw1 = 0, sw2 = 0;
+       const char *line = NULL;
+       char *pResp = NULL;
+       GSList *tokens = NULL;
+
+       dbg("Entry");
+
+       memset(&respMsgStatus, 0, sizeof(struct tresp_sms_set_msg_status));
+       respMsgStatus.result = SMS_DEVICE_FAILURE;
+
+       ur = tcore_pending_ref_user_request(pending);
+
+       if (atResp->success > 0) {
+               dbg("RESPONSE OK");
+
+               if (atResp->lines) {
+                       line = (const char *) atResp->lines->data;
+                       tokens = tcore_at_tok_new(line);
+                       pResp = g_slist_nth_data(tokens, 0);
+                       if (pResp != NULL) {
+                               sw1 = atoi(pResp);
+                       } else {
+                               dbg("sw1 is NULL");
+                       }
+                       pResp = g_slist_nth_data(tokens, 1);
+                       if (pResp != NULL) {
+                               sw2 = atoi(pResp);
+                               if ((sw1 == AT_SW1_SUCCESS) && (sw2 == 0)) {
+                                       respMsgStatus.result = SMS_SENDSMS_SUCCESS;
+                               }
+                       } else {
+                               dbg("sw2 is NULL");
+                       }
+                       pResp = g_slist_nth_data(tokens, 3);
+
+                       if (pResp != NULL) {
+                               response = atoi(pResp);
+                               dbg("response is %s", response);
+                       }
+               } else {
+                       dbg("No lines");
+               }
+       } else {
+               dbg("RESPONSE NOK");
+       }
+
+       tcore_user_request_send_response(ur, TRESP_SMS_SET_MSG_STATUS, sizeof(struct tresp_sms_set_msg_status), &respMsgStatus);
+
+       if (tokens)
+               tcore_at_tok_free(tokens);
+
+       dbg("Exit");
+       return;
+}
+
+static void on_response_get_sms_params(TcorePending *pending, int data_len, const void *data, void *user_data)
+{
+       UserRequest *ur;
+       struct tresp_sms_get_params respGetParams;
+       const TcoreATResponse *atResp = data;
+       int sw1 = 0, sw2 = 0;
+       const char *line = NULL;
+       char *pResp = NULL;
+       GSList *tokens = NULL;
+       char *hexData = NULL;
+       char *recordData = NULL;
+       int i = 0;
+
+       memset(&respGetParams, 0, sizeof(struct tresp_sms_get_params));
+       respGetParams.result = SMS_DEVICE_FAILURE;
+
+       ur = tcore_pending_ref_user_request(pending);
+
+       if (atResp->success > 0) {
+               dbg("RESPONSE OK");
+
+               if (atResp->lines) {
+                       line = (const char *) atResp->lines->data;
+                       tokens = tcore_at_tok_new(line);
+                       pResp = g_slist_nth_data(tokens, 0);
+                       if (pResp != NULL) {
+                               sw1 = atoi(pResp);
+                               dbg("sw1 is %d", sw1);
+                       } else {
+                               dbg("sw1 is NULL");
+                       }
+                       pResp = g_slist_nth_data(tokens, 1);
+                       if (pResp != NULL) {
+                               sw2 = atoi(pResp);
+                               dbg("sw2 is %d", sw2);
+                               if ((sw1 == 0x90 && sw2 == 0x00) || sw1 == 0x91) {
+                                       respGetParams.result = SMS_SENDSMS_SUCCESS;
+                               }
+                       } else {
+                               dbg("sw2 is NULL");
+                       }
+                       pResp = g_slist_nth_data(tokens, 2);
+                       if (pResp != NULL) {
+                               hexData = util_removeQuotes(pResp);
+
+                               recordData = util_hexStringToBytes(hexData);
+                               util_hex_dump("    ", strlen(hexData) / 2, recordData);
+
+                               respGetParams.paramsInfo.recordLen = strlen(hexData) / 2;
+
+                               util_sms_decode_smsParameters((unsigned char *) recordData, strlen(hexData) / 2, &(respGetParams.paramsInfo));
+                               respGetParams.result = SMS_SENDSMS_SUCCESS;
+
+                               for (i = 0; i < (int) respGetParams.paramsInfo.tpSvcCntrAddr.dialNumLen; i++)
+                                       dbg("SCAddr = %d [%02x]", i, respGetParams.paramsInfo.tpSvcCntrAddr.diallingNum[i]);
+
+                               free(recordData);
+                               free(hexData);
+                       } else {
+                               dbg("No response");
+                       }
+                       tcore_at_tok_free(tokens);
+               }
+       } else {
+               dbg("RESPONSE NOK");
+       }
+
+       tcore_user_request_send_response(ur, TRESP_SMS_GET_PARAMS, sizeof(struct tresp_sms_get_params), &respGetParams);
+
+       dbg("Exit");
+       return;
+}
+
+static void on_response_set_sms_params(TcorePending *pending, int data_len, const void *data, void *user_data)
+{
+       UserRequest *ur;
+       struct tresp_sms_set_params respSetParams = {0, };
+       const TcoreATResponse *atResp = data;
+       int sw1 = 0, sw2 = 0;
+       const char *line = NULL;
+       char *pResp = NULL;
+       GSList *tokens = NULL;
+
+
+       memset(&respSetParams, 0, sizeof(struct tresp_sms_set_params));
+       ur = tcore_pending_ref_user_request(pending);
+
+       respSetParams.result = SMS_DEVICE_FAILURE;
+
+       if (atResp->success > 0) {
+               dbg("RESPONSE OK");
+
+               if (atResp->lines) {
+                       line = (const char *) atResp->lines->data;
+                       tokens = tcore_at_tok_new(line);
+                       pResp = g_slist_nth_data(tokens, 0);
+                       if (pResp != NULL) {
+                               sw1 = atoi(pResp);
+                       } else {
+                               dbg("sw1 is NULL");
+                       }
+
+                       pResp = g_slist_nth_data(tokens, 1);
+                       if (pResp != NULL) {
+                               sw2 = atoi(pResp);
+                               if (((sw1 == AT_SW1_SUCCESS) && (sw2 == AT_SW2_SUCCESS)) || (sw1 == 0x91)) {
+                                       respSetParams.result = SMS_SENDSMS_SUCCESS;
+                               }
+                       } else {
+                               dbg("sw2 is NULL");
+                       }
+               } else {
+                       dbg("No lines");
+               }
+       } else {
+               dbg("RESPONSE NOK");
+       }
+
+       tcore_user_request_send_response(ur, TRESP_SMS_SET_PARAMS, sizeof(struct tresp_sms_set_params), &respSetParams);
+
+       if (tokens)
+               tcore_at_tok_free(tokens);
+
+       dbg("Exit");
+       return;
+}
+
+static void on_response_get_paramcnt(TcorePending *p, int data_len, const void *data, void *user_data)
+{
+       UserRequest *ur = NULL;
+       struct tresp_sms_get_paramcnt respGetParamCnt = {0, };
+       const TcoreATResponse *atResp = data;
+       char *line = NULL, *pResp = NULL;
+       int sw1 = 0, sw2 = 0, *smsp_record_len = NULL;
+       int sim_type = 0;
+       GSList *tokens = NULL;
+       CoreObject *co_sim = NULL;  // need this to get the sim type GSM/USIM
+       TcorePlugin *plugin = NULL;
+
+       dbg("Entry");
+
+       ur = tcore_pending_ref_user_request(p);
+       respGetParamCnt.result = SMS_DEVICE_FAILURE;
+
+       if (atResp->success > 0) {
+               dbg("RESPONSE OK");
+
+               if (atResp->lines) {
+                       line = (char *) atResp->lines->data;
+
+                       dbg("line is %s", line);
+
+                       tokens = tcore_at_tok_new(line);
+                       pResp = g_slist_nth_data(tokens, 0);
+                       if (pResp != NULL) {
+                               sw1 = atoi(pResp);
+                       } else {
+                               dbg("sw1 is NULL");
+                       }
+                       pResp = g_slist_nth_data(tokens, 1);
+                       if (pResp != NULL) {
+                               sw2 = atoi(pResp);
+                               if ((sw1 == 144) && (sw2 == 0)) {
+                                       respGetParamCnt.result = SMS_SENDSMS_SUCCESS;
+                               }
+                       } else {
+                               dbg("sw2 is NULL");
+                       }
+                       pResp = g_slist_nth_data(tokens, 2);
+                       if (pResp != NULL) {
+                               char *hexData = NULL;
+                               char *recordData = NULL;
+                               hexData = util_removeQuotes(pResp);
+
+                               /*1. SIM access success case*/
+                               if ((sw1 == 0x90 && sw2 == 0x00) || sw1 == 0x91) {
+                                       unsigned char tag_len = 0; /*   1 or 2 bytes ??? */
+                                       int record_len = 0;
+                                       char num_of_records = 0;
+                                       unsigned char file_id_len = 0;
+                                       unsigned short file_id = 0;
+                                       unsigned short file_size = 0;
+                                       unsigned short file_type = 0;
+                                       unsigned short arr_file_id = 0;
+                                       int arr_file_id_rec_num = 0;
+
+                                       /*      handling only last 3 bits */
+                                       unsigned char file_type_tag = 0x07;
+                                       unsigned char *ptr_data;
+
+                                       recordData = util_hexStringToBytes(hexData);
+                                       util_hex_dump("    ", strlen(hexData) / 2, recordData);
+
+                                       ptr_data = (unsigned char *) recordData;
+
+                                       co_sim = tcore_plugin_ref_core_object(tcore_pending_ref_plugin(p), "sim");
+                                       sim_type = tcore_sim_get_type(co_sim);
+                                       dbg("sim type is %d", sim_type);
+
+                                       if (sim_type == SIM_TYPE_USIM) {
+                                               /*
+                                                ETSI TS 102 221 v7.9.0
+                                                   - Response Data
+                                                    '62'       FCP template tag
+                                                    - Response for an EF
+                                                    '82'       M       File Descriptor
+                                                    '83'       M       File Identifier
+                                                   'A5'        O       Proprietary information
+                                                    '8A'       M       Life Cycle Status Integer
+                                                    '8B', '8C' or 'AB' C1      Security attributes
+                                                   '80'        M       File size
+                                                    '81'       O       Total file size
+                                                    '88'       O       Short File Identifier (SFI)
+                                               */
+
+                                               /* rsim.res_len  has complete data length received  */
+
+                                               /* FCP template tag - File Control Parameters tag*/
+                                               if (*ptr_data == 0x62) {
+                                                       /* parse complete FCP tag*/
+                                                       /* increment to next byte */
+                                                       ptr_data++;
+                                                       tag_len = *ptr_data++;
+                                                       /* FCP file descriptor - file type, accessibility, DF, ADF etc*/
+                                                       if (*ptr_data == 0x82) {
+                                                               /* increment to next byte */
+                                                               ptr_data++;
+                                                               /*2 or 5 value*/
+                                                               ptr_data++;
+                                                               /*      unsigned char file_desc_len = *ptr_data++;*/
+                                                               /*      dbg("file descriptor length: [%d]", file_desc_len);*/
+                                                               /* TBD:  currently capture only file type : ignore sharable, non sharable, working, internal etc*/
+                                                               /* consider only last 3 bits*/
+                                                               file_type_tag = file_type_tag & (*ptr_data);
+
+                                                               switch (file_type_tag) {
+                                                                       /* increment to next byte */
+                                                                       ptr_data++;
+
+                                                               case 0x1:
+                                                                       dbg("Getting FileType: [Transparent file type]");
+                                                                       /* increment to next byte */
+                                                                       ptr_data++;
+                                                                       file_type = 0x01;   // SIM_FTYPE_TRANSPARENT
+                                                                       /*      data coding byte - value 21 */
+                                                                       ptr_data++;
+                                                                       break;
+
+                                                               case 0x2:
+                                                                       dbg("Getting FileType: [Linear fixed file type]");
+                                                                       /* increment to next byte */
+                                                                       ptr_data++;
+                                                                       /*      data coding byte - value 21 */
+                                                                       ptr_data++;
+                                                                       /*      2bytes */
+                                                                       memcpy(&record_len, ptr_data, 2);
+                                                                       /* swap bytes */
+                                                                       record_len = SMS_SWAPBYTES16(record_len);
+                                                                       ptr_data = ptr_data + 2;
+                                                                       num_of_records = *ptr_data++;
+                                                                       /* Data lossy conversation from enum (int) to unsigned char */
+                                                                       file_type = 0x02;   // SIM_FTYPE_LINEAR_FIXED
+                                                                       break;
+
+                                                               case 0x6:
+                                                                       dbg(" Cyclic fixed file type");
+                                                                       /* increment to next byte */
+                                                                       ptr_data++;
+                                                                       /*      data coding byte - value 21 */
+                                                                       ptr_data++;
+                                                                       /*      2bytes */
+                                                                       memcpy(&record_len, ptr_data, 2);
+                                                                       /* swap bytes  */
+                                                                       record_len = SMS_SWAPBYTES16(record_len);
+                                                                       ptr_data = ptr_data + 2;
+                                                                       num_of_records = *ptr_data++;
+                                                                       file_type = 0x04;   // SIM_FTYPE_CYCLIC
+                                                                       break;
+
+                                                               default:
+                                                                       dbg("not handled file type [0x%x]", *ptr_data);
+                                                                       break;
+                                                               }
+                                                       } else {
+                                                               dbg("INVALID FCP received - DEbug!");
+                                                               tcore_at_tok_free(tokens);
+                                                               return;
+                                                       }
+
+                                                       /*File identifier - file id?? */ // 0x84,0x85,0x86 etc are currently ignored and not handled
+                                                       if (*ptr_data == 0x83) {
+                                                               /* increment to next byte */
+                                                               ptr_data++;
+                                                               file_id_len = *ptr_data++;
+                                                               memcpy(&file_id, ptr_data, file_id_len);
+                                                               /* swap bytes    */
+                                                               file_id = SMS_SWAPBYTES16(file_id);
+                                                               ptr_data = ptr_data + 2;
+                                                               dbg("Getting FileID=[0x%x]", file_id);
+                                                       } else {
+                                                               dbg("INVALID FCP received - DEbug!");
+                                                               free(hexData);
+                                                               free(recordData);
+                                                               tcore_at_tok_free(tokens);
+                                                               return;
+                                                       }
+
+                                                       /*      proprietary information  */
+                                                       if (*ptr_data == 0xA5) {
+                                                               unsigned short prop_len;
+                                                               /* increment to next byte */
+                                                               ptr_data++;
+                                                               /* length */
+                                                               prop_len = *ptr_data;
+                                                               /* skip data */
+                                                               ptr_data = ptr_data + prop_len + 1;
+                                                       } else {
+                                                               dbg("INVALID FCP received - DEbug!");
+                                                       }
+
+                                                       /* life cycle status integer [8A][length:0x01][status]*/
+                                                       /*
+                                                        status info b8~b1
+                                                        00000000 : No information given
+                                                        00000001 : creation state
+                                                        00000011 : initialization state
+                                                        000001-1 : operation state -activated
+                                                        000001-0 : operation state -deactivated
+                                                        000011-- : Termination state
+                                                        b8~b5 !=0, b4~b1=X : Proprietary
+                                                        Any other value : RFU
+                                                        */
+                                                       if (*ptr_data == 0x8A) {
+                                                               /* increment to next byte */
+                                                               ptr_data++;
+                                                               /* length - value 1 */
+                                                               ptr_data++;
+
+                                                               switch (*ptr_data) {
+                                                               case 0x04:
+                                                               case 0x06:
+                                                                       dbg("<IPC_RX> operation state -deactivated");
+                                                                       ptr_data++;
+                                                                       break;
+
+                                                               case 0x05:
+                                                               case 0x07:
+                                                                       dbg("<IPC_RX> operation state -activated");
+                                                                       ptr_data++;
+                                                                       break;
+
+                                                               default:
+                                                                       dbg("<IPC_RX> DEBUG! LIFE CYCLE STATUS =[0x%x]", *ptr_data);
+                                                                       ptr_data++;
+                                                                       break;
+                                                               }
+                                                       }
+
+                                                       /* related to security attributes : currently not handled*/
+                                                       if (*ptr_data == 0x86 || *ptr_data == 0x8B || *ptr_data == 0x8C || *ptr_data == 0xAB) {
+                                                               /* increment to next byte */
+                                                               ptr_data++;
+                                                               /* if tag length is 3 */
+                                                               if (*ptr_data == 0x03) {
+                                                                       /* increment to next byte */
+                                                                       ptr_data++;
+                                                                       /* EFARR file id */
+                                                                       memcpy(&arr_file_id, ptr_data, 2);
+                                                                       /* swap byes */
+                                                                       arr_file_id = SMS_SWAPBYTES16(arr_file_id);
+                                                                       ptr_data = ptr_data + 2;
+                                                                       arr_file_id_rec_num = *ptr_data++;
+                                                               } else {
+                                                                       /* if tag length is not 3 */
+                                                                       /* ignoring bytes       */
+                                                                       // ptr_data = ptr_data + 4;
+                                                                       dbg("Useless security attributes, so jump to next tag");
+                                                                       ptr_data = ptr_data + (*ptr_data + 1);
+                                                               }
+                                                       } else {
+                                                               dbg("INVALID FCP received[0x%x] - DEbug!", *ptr_data);
+                                                               free(hexData);
+                                                               free(recordData);
+                                                               tcore_at_tok_free(tokens);
+                                                               return;
+                                                       }
+
+                                                       dbg("Current ptr_data value is [%x]", *ptr_data);
+
+                                                       /* file size excluding structural info*/
+                                                       if (*ptr_data == 0x80) {
+                                                               /* for EF file size is body of file and for Linear or cyclic it is
+                                                                * number of recXsizeof(one record)
+                                                                */
+                                                               /* increment to next byte */
+                                                               ptr_data++;
+                                                               /* length is 1 byte - value is 2 bytes or more */
+                                                               ptr_data++;
+                                                               memcpy(&file_size, ptr_data, 2);
+                                                               /* swap bytes */
+                                                               file_size = SMS_SWAPBYTES16(file_size);
+                                                               ptr_data = ptr_data + 2;
+                                                       } else {
+                                                               dbg("INVALID FCP received - DEbug!");
+                                                               free(hexData);
+                                                               free(recordData);
+                                                               tcore_at_tok_free(tokens);
+                                                               return;
+                                                       }
+
+                                                       /* total file size including structural info*/
+                                                       if (*ptr_data == 0x81) {
+                                                               int len;
+                                                               /* increment to next byte */
+                                                               ptr_data++;
+                                                               /* length */
+                                                               len = *ptr_data;
+                                                               /* ignored bytes */
+                                                               ptr_data = ptr_data + 3;
+                                                       } else {
+                                                               dbg("INVALID FCP received - DEbug!");
+                                                               /* 0x81 is optional tag?? check out! so do not return -1 from here! */
+                                                               /* return -1; */
+                                                       }
+                                                       /*short file identifier ignored*/
+                                                       if (*ptr_data == 0x88) {
+                                                               dbg("0x88: Do Nothing");
+                                                               /*DO NOTHING*/
+                                                       }
+                                               } else {
+                                                       dbg("INVALID FCP received - DEbug!");
+                                                       free(hexData);
+                                                       free(recordData);
+                                                       tcore_at_tok_free(tokens);
+                                                       return;
+                                               }
+                                       } else if (sim_type == SIM_TYPE_GSM) {
+                                               unsigned char gsm_specific_file_data_len = 0;
+                                               /*      ignore RFU byte1 and byte2 */
+                                               ptr_data++;
+                                               ptr_data++;
+                                               /*      file size */
+                                               // file_size = p_info->response_len;
+                                               memcpy(&file_size, ptr_data, 2);
+                                               /* swap bytes */
+                                               file_size = SMS_SWAPBYTES16(file_size);
+                                               /*      parsed file size */
+                                               ptr_data = ptr_data + 2;
+                                               /*  file id  */
+                                               memcpy(&file_id, ptr_data, 2);
+                                               file_id = SMS_SWAPBYTES16(file_id);
+                                               dbg(" FILE id --> [%x]", file_id);
+                                               ptr_data = ptr_data + 2;
+                                               /* save file type - transparent, linear fixed or cyclic */
+                                               file_type_tag = (*(ptr_data + 7));
+
+                                               switch (*ptr_data) {
+                                               case 0x0:
+                                                       /* RFU file type */
+                                                       dbg(" RFU file type- not handled - Debug!");
+                                                       break;
+
+                                               case 0x1:
+                                                       /* MF file type */
+                                                       dbg(" MF file type - not handled - Debug!");
+                                                       break;
+
+                                               case 0x2:
+                                                       /* DF file type */
+                                                       dbg(" DF file type - not handled - Debug!");
+                                                       break;
+
+                                               case 0x4:
+                                                       /* EF file type */
+                                                       dbg(" EF file type [%d] ", file_type_tag);
+                                                       /*      increment to next byte */
+                                                       ptr_data++;
+
+                                                       if (file_type_tag == 0x00 || file_type_tag == 0x01) {
+                                                               /* increament to next byte as this byte is RFU */
+                                                               ptr_data++;
+                                                               file_type =
+                                                                       (file_type_tag == 0x00) ? 0x01 : 0x02;         // SIM_FTYPE_TRANSPARENT:SIM_FTYPE_LINEAR_FIXED;
+                                                       } else {
+                                                               /* increment to next byte */
+                                                               ptr_data++;
+                                                               /*      For a cyclic EF all bits except bit 7 are RFU; b7=1 indicates that */
+                                                               /* the INCREASE command is allowed on the selected cyclic file. */
+                                                               file_type = 0x04;       // SIM_FTYPE_CYCLIC;
+                                                       }
+                                                       /* bytes 9 to 11 give SIM file access conditions */
+                                                       ptr_data++;
+                                                       /* byte 10 has one nibble that is RF U and another for INCREASE which is not used currently */
+                                                       ptr_data++;
+                                                       /* byte 11 is invalidate and rehabilate nibbles */
+                                                       ptr_data++;
+                                                       /* byte 12 - file status */
+                                                       ptr_data++;
+                                                       /* byte 13 - GSM specific data */
+                                                       gsm_specific_file_data_len = *ptr_data;
+                                                       ptr_data++;
+                                                       /*      byte 14 - structure of EF - transparent or linear or cyclic , already saved above */
+                                                       ptr_data++;
+                                                       /* byte 15 - length of record for linear and cyclic , for transparent it is set to 0x00. */
+                                                       record_len = *ptr_data;
+                                                       dbg("record length[%d], file size[%d]", record_len, file_size);
+
+                                                       if (record_len != 0)
+                                                               num_of_records = (file_size / record_len);
+
+                                                       dbg("Number of records [%d]", num_of_records);
+                                                       break;
+
+                                               default:
+                                                       dbg(" not handled file type");
+                                                       break;
+                                               }
+                                       } else {
+                                               dbg(" Card Type - UNKNOWN  [%d]", sim_type);
+                                       }
+
+                                       dbg("EF[0x%x] size[%ld] Type[0x%x] NumOfRecords[%ld] RecordLen[%ld]", file_id, file_size, file_type, num_of_records, record_len);
+
+                                       respGetParamCnt.recordCount = num_of_records;
+                                       respGetParamCnt.result = SMS_SUCCESS;
+
+                                       // TO Store smsp record length in the property
+                                       plugin = tcore_pending_ref_plugin(p);
+                                       smsp_record_len = tcore_plugin_ref_property(plugin, "SMSPRECORDLEN");
+                                       memcpy(smsp_record_len, &record_len, sizeof(int));
+
+                                       free(recordData);
+                                       free(hexData);
+                               } else {
+                                       /*2. SIM access fail case*/
+                                       dbg("SIM access fail");
+                                       respGetParamCnt.result = SMS_UNKNOWN;
+                               }
+                       } else {
+                               dbg("presp is NULL");
+                       }
+               } else {
+                       dbg("line is blank");
+               }
+       } else {
+               dbg("RESPONSE NOK");
+       }
+
+       tcore_user_request_send_response(ur, TRESP_SMS_GET_PARAMCNT, sizeof(struct tresp_sms_get_paramcnt), &respGetParamCnt);
+
+       if (tokens)
+               tcore_at_tok_free(tokens);
+
+       dbg("Exit");
+       return;
+}
+
+static void _response_get_efsms_data(TcorePending *p, int data_len, const void *data, void *user_data)
+{
+       UserRequest *ur = NULL;
+       UserRequest *dup_ur = NULL;
+       struct tresp_sms_set_msg_status resp_msg_status = {0, };
+       const struct treq_sms_set_msg_status *req_msg_status = NULL;
+
+       const TcoreATResponse *resp = data;
+       char *encoded_data = NULL;
+       char msg_status = 0;
+       char *pResp = NULL;
+       GSList *tokens = NULL;
+       const char *line = NULL;
+       int sw1 = 0;
+       int sw2 = 0;
+
+       TcoreHal *hal = NULL;
+       TcoreATRequest *atreq = NULL;
+       TcorePending *pending = NULL;
+       gchar *cmd_str = NULL;
+
+       ur = tcore_pending_ref_user_request(p);
+
+       req_msg_status = tcore_user_request_ref_data(ur, NULL);
+
+       resp_msg_status.result = SMS_DEVICE_FAILURE;
+
+       hal = tcore_object_get_hal(tcore_pending_ref_core_object(pending));
+       dbg("msgStatus: [%x], index [%x]", req_msg_status->msgStatus, req_msg_status->index);
+
+       if (resp->success <= 0) {
+               goto OUT;
+       }
+
+       {
+               dbg("RESPONSE OK");
+               if (resp->lines) {
+                       line = (const char *) resp->lines->data;
+                       tokens = tcore_at_tok_new(line);
+                       if (g_slist_length(tokens) != 3) {
+                               msg("invalid message");
+                               goto OUT;
+                       }
+               }
+               sw1 = atoi(g_slist_nth_data(tokens, 0));
+               sw2 = atoi(g_slist_nth_data(tokens, 1));
+               pResp = g_slist_nth_data(tokens, 2);
+
+               if ((sw1 == 0x90 && sw2 == 0x00) || sw1 == 0x91) {
+                       switch (req_msg_status->msgStatus) {
+                       case SMS_STATUS_READ:
+                               msg_status = 0x01;
+                               break;
+
+                       case SMS_STATUS_UNREAD:
+                               msg_status = 0x03;
+                               break;
+
+                       case SMS_STATUS_UNSENT:
+                               msg_status = 0x07;
+                               break;
+
+                       case SMS_STATUS_SENT:
+                               msg_status = 0x05;
+                               break;
+
+                       case SMS_STATUS_DELIVERED:
+                               msg_status = 0x1D;
+                               break;
+
+                       case SMS_STATUS_DELIVERY_UNCONFIRMED:
+                               msg_status = 0xD;
+                               break;
+
+                       case SMS_STATUS_MESSAGE_REPLACED:
+                       case SMS_STATUS_RESERVED:
+                       default:
+                               msg_status = 0x03;
+                               break;
+                       }
+
+                       encoded_data = util_removeQuotes(pResp);
+
+                       // overwrite Status byte information
+                       util_byte_to_hex((const char *) &msg_status, (char *) encoded_data, 1);
+
+                       // Update EF-SMS with just status byte overwritten, rest 175 bytes are same as received in read information
+                       cmd_str = g_strdup_printf("AT+CRSM=220,28476,%d, 4, %d, \"%s\"", (req_msg_status->index + 1), AT_EF_SMS_RECORD_LEN, encoded_data);
+                       atreq = tcore_at_request_new((const char *) cmd_str, "+CRSM", TCORE_AT_SINGLELINE);
+                       pending = tcore_pending_new(tcore_pending_ref_core_object(pending), 0);
+                       if (NULL == cmd_str || NULL == atreq || NULL == pending) {
+                               err("Out of memory. Unable to proceed");
+                               dbg("cmd_str: [%p], atreq: [%p], pending: [%p]", cmd_str, atreq, pending);
+
+                               // free memory we own
+                               g_free(cmd_str);
+                               free(encoded_data);
+                               util_sms_free_memory(atreq);
+                               util_sms_free_memory(pending);
+
+                               goto OUT;
+                       }
+
+                       util_hex_dump("    ", strlen(cmd_str), (void *) cmd_str);
+
+                       dup_ur = tcore_user_request_ref(ur);
+
+                       tcore_pending_set_request_data(pending, 0, atreq);
+                       tcore_pending_set_response_callback(pending, on_response_set_msg_status, NULL);
+                       tcore_pending_link_user_request(pending, dup_ur);
+                       tcore_pending_set_send_callback(pending, on_confirmation_sms_message_send, NULL);
+                       tcore_hal_send_request(hal, pending);
+
+                       g_free(cmd_str);
+                       free(encoded_data);
+               }
+       }
+
+OUT:
+       if (tokens)
+               tcore_at_tok_free(tokens);
+
+       tcore_user_request_send_response(ur, TRESP_SMS_SET_MSG_STATUS, sizeof(struct tresp_sms_set_msg_status), &msg_status);
+
+       dbg("Exit");
+
+       return;
+}
+
+/*=============================================================
+                            Requests
+==============================================================*/
+static TReturn send_umts_msg(CoreObject *obj, UserRequest *ur)
+{
+       gchar *cmd_str = NULL;
+       TcoreHal *hal = NULL;
+       TcoreATRequest *atreq = NULL;
+       TcorePending *pending = NULL;
+       const struct treq_sms_send_umts_msg *sendUmtsMsg = NULL;
+       char buf[2 * (SMS_SMSP_ADDRESS_LEN + SMS_SMDATA_SIZE_MAX) + 1] = {0};
+       int ScLength = 0;
+       int pdu_len = 0;
+
+       dbg("Entry");
+
+       sendUmtsMsg = tcore_user_request_ref_data(ur, NULL);
+       hal = tcore_object_get_hal(obj);
+       if (NULL == sendUmtsMsg || NULL == hal) {
+               err("NULL input. Unable to proceed");
+               dbg("sendUmtsMsg: [%p], hal: [%p]", sendUmtsMsg, hal);
+
+               dbg("Exit");
+               return TCORE_RETURN_EINVAL;
+       }
+
+       dbg("msgLength: [%d]", sendUmtsMsg->msgDataPackage.msgLength);
+       util_hex_dump("    ", (SMS_SMDATA_SIZE_MAX + 1), (void *) sendUmtsMsg->msgDataPackage.tpduData);
+       util_hex_dump("    ", SMS_SMSP_ADDRESS_LEN, (void *) sendUmtsMsg->msgDataPackage.sca);
+
+       ScLength = (int) sendUmtsMsg->msgDataPackage.sca[0];
+
+       dbg("ScLength: [%d]", ScLength);
+
+       if ((sendUmtsMsg->msgDataPackage.msgLength > 0)
+               && (sendUmtsMsg->msgDataPackage.msgLength <= SMS_SMDATA_SIZE_MAX)
+               && (ScLength <= SMS_MAX_SMS_SERVICE_CENTER_ADDR)) {
+               if (ScLength == 0) { // ScAddress not specified
+                       buf[0] = '0';
+                       buf[1] = '0';
+                       pdu_len = 2;
+               } else {
+                       dbg("Specifying SCA in TPDU is currently not supported");
+
+                       buf[0] = '0';
+                       buf[1] = '0';
+                       pdu_len = 2;
+               }
+
+               util_byte_to_hex((const char *) sendUmtsMsg->msgDataPackage.tpduData, (char *) &buf[pdu_len], sendUmtsMsg->msgDataPackage.msgLength);
+
+               pdu_len = pdu_len + 2 * sendUmtsMsg->msgDataPackage.msgLength;
+
+               buf[pdu_len] = '\0'; // Ensure termination
+
+               dbg("pdu_len: [%d]", pdu_len);
+               util_hex_dump("    ", sizeof(buf), (void *) buf);
+
+               // AT+CMGS=<length><CR>PDU is given<ctrl-Z/ESC>
+               cmd_str = g_strdup_printf("AT+CMGS=%d%s%s\x1A", sendUmtsMsg->msgDataPackage.msgLength, "\r", buf);
+               atreq = tcore_at_request_new((const char *) cmd_str, "+CMGS", TCORE_AT_SINGLELINE);
+               pending = tcore_pending_new(obj, 0);
+
+               if (NULL == cmd_str || NULL == atreq || NULL == pending) {
+                       err("Out of memory. Unable to proceed");
+                       dbg("cmd_str: [%p], atreq: [%p], pending: [%p]", cmd_str, atreq, pending);
+
+                       // free memory we own
+                       g_free(cmd_str);
+                       util_sms_free_memory(atreq);
+                       util_sms_free_memory(pending);
+
+                       dbg("Exit");
+                       return TCORE_RETURN_ENOMEM;
+               }
+
+               util_hex_dump("    ", strlen(cmd_str), (void *) cmd_str);
+
+               tcore_pending_set_request_data(pending, 0, atreq);
+               tcore_pending_set_response_callback(pending, on_response_send_umts_msg, NULL);
+               tcore_pending_link_user_request(pending, ur);
+               tcore_pending_set_send_callback(pending, on_confirmation_sms_message_send, NULL);
+               tcore_hal_send_request(hal, pending);
+
+               g_free(cmd_str);
+
+               dbg("Exit");
+               return TCORE_RETURN_SUCCESS;
+       }
+
+       err("Invalid Data len");
+       dbg("Exit");
+       return TCORE_RETURN_SMS_INVALID_DATA_LEN;
+}
+
+static TReturn read_msg(CoreObject *obj, UserRequest *ur)
+{
+       gchar *cmd_str = NULL;
+       TcoreHal *hal = NULL;
+       TcoreATRequest *atreq = NULL;
+       TcorePending *pending = NULL;
+       const struct treq_sms_read_msg *readMsg = NULL;
+
+       dbg("Entry");
+
+       readMsg = tcore_user_request_ref_data(ur, NULL);
+       hal = tcore_object_get_hal(obj);
+       if (NULL == readMsg || NULL == hal) {
+               err("NULL input. Unable to proceed");
+               dbg("readMsg: [%p], hal: [%p]", readMsg, hal);
+
+               dbg("Exit");
+               return TCORE_RETURN_EINVAL;
+       }
+
+       dbg("index: [%d]", readMsg->index);
+
+       cmd_str = g_strdup_printf("AT+CMGR=%d", (readMsg->index + 1)); // IMC index is one ahead of TAPI
+       atreq = tcore_at_request_new((const char *) cmd_str, "+CMGR", TCORE_AT_PDU);
+       pending = tcore_pending_new(obj, 0);
+
+       if (NULL == cmd_str || NULL == atreq || NULL == pending) {
+               err("Out of memory. Unable to proceed");
+               dbg("cmd_str: [%p], atreq: [%p], pending: [%p]", cmd_str, atreq, pending);
+
+               // free memory we own
+               g_free(cmd_str);
+               util_sms_free_memory(atreq);
+               util_sms_free_memory(pending);
+
+               dbg("Exit");
+               return TCORE_RETURN_ENOMEM;
+       }
+
+       util_hex_dump("    ", strlen(cmd_str), (void *) cmd_str);
+
+       tcore_pending_set_request_data(pending, 0, atreq);
+       tcore_pending_set_response_callback(pending, on_response_read_msg, (void *) (uintptr_t) (readMsg->index)); // storing index as user data for response
+       tcore_pending_link_user_request(pending, ur);
+       tcore_pending_set_send_callback(pending, on_confirmation_sms_message_send, NULL);
+       tcore_hal_send_request(hal, pending);
+
+       g_free(cmd_str);
+
+       dbg("Exit");
+       return TCORE_RETURN_SUCCESS;
+}
+
+static TReturn save_msg(CoreObject *obj, UserRequest *ur)
+{
+       gchar *cmd_str = NULL;
+       TcoreHal *hal = NULL;
+       TcoreATRequest *atreq = NULL;
+       TcorePending *pending = NULL;
+       const struct treq_sms_save_msg *saveMsg = NULL;
+       int ScLength = 0, pdu_len = 0, stat = 0;
+       char buf[2 * (SMS_SMSP_ADDRESS_LEN + SMS_SMDATA_SIZE_MAX) + 1] = {0};
+       char *hex_pdu = NULL;
+
+       dbg("Entry");
+
+       saveMsg = tcore_user_request_ref_data(ur, NULL);
+       hal = tcore_object_get_hal(obj);
+       if (NULL == saveMsg || NULL == hal) {
+               err("NULL input. Unable to proceed");
+               dbg("saveMsg: [%p], hal: [%p]", saveMsg, hal);
+
+               dbg("Exit");
+               return TCORE_RETURN_EINVAL;
+       }
+
+       dbg("msgStatus: %x, msgLength: [%d]", saveMsg->msgStatus, saveMsg->msgDataPackage.msgLength);
+       util_hex_dump("    ", (SMS_SMDATA_SIZE_MAX + 1), (void *) saveMsg->msgDataPackage.tpduData);
+       util_hex_dump("    ", SMS_SMSP_ADDRESS_LEN, (void *) saveMsg->msgDataPackage.sca);
+
+       switch (saveMsg->msgStatus) {
+       case SMS_STATUS_READ:
+               stat = AT_REC_READ;
+               break;
+
+       case SMS_STATUS_UNREAD:
+               stat = AT_REC_UNREAD;
+               break;
+
+       case SMS_STATUS_SENT:
+               stat = AT_STO_SENT;
+               break;
+
+       case SMS_STATUS_UNSENT:
+               stat = AT_STO_UNSENT;
+               break;
+
+       default:
+               err("Invalid msgStatus");
+               dbg("Exit");
+               return TCORE_RETURN_EINVAL;
+       }
+
+       if ((saveMsg->msgDataPackage.msgLength > 0)
+               && (saveMsg->msgDataPackage.msgLength <= SMS_SMDATA_SIZE_MAX)) {
+               ScLength = (int) saveMsg->msgDataPackage.sca[0];
+
+               buf[0] = ScLength;
+               dbg("ScLength = %d", ScLength);
+
+               if (ScLength == 0) {
+                       buf[0] = 0;
+               } else {
+                       memcpy(&buf[1], saveMsg->msgDataPackage.sca, ScLength);
+               }
+
+               memcpy(&buf[ScLength + 1], saveMsg->msgDataPackage.tpduData, saveMsg->msgDataPackage.msgLength);
+
+               pdu_len = saveMsg->msgDataPackage.msgLength + ScLength + 1;
+               dbg("pdu_len: [%d]", pdu_len);
+
+               hex_pdu = malloc(pdu_len * 2 + 1);
+               util_hex_dump("    ", sizeof(buf), (void *) buf);
+
+               memset(hex_pdu, 0x00, pdu_len * 2 + 1);
+
+               util_byte_to_hex((const char *) buf, (char *) hex_pdu, pdu_len);
+
+               // AT+CMGW=<length>[,<stat>]<CR>PDU is given<ctrl-Z/ESC>
+               cmd_str = g_strdup_printf("AT+CMGW=%d,%d%s%s\x1A", saveMsg->msgDataPackage.msgLength, stat, "\r", hex_pdu);
+               pending = tcore_pending_new(obj, 0);
+               atreq = tcore_at_request_new((const char *) cmd_str, "+CMGW", TCORE_AT_SINGLELINE);
+
+               if (NULL == cmd_str || NULL == atreq || NULL == pending) {
+                       err("Out of memory. Unable to proceed");
+                       dbg("cmd_str: [%p], atreq: [%p], pending: [%p]", cmd_str, atreq, pending);
+
+                       // free memory we own
+                       g_free(cmd_str);
+                       util_sms_free_memory(atreq);
+                       util_sms_free_memory(pending);
+                       util_sms_free_memory(hex_pdu);
+
+                       dbg("Exit");
+                       return TCORE_RETURN_ENOMEM;
+               }
+
+               util_hex_dump("    ", strlen(cmd_str), (void *) cmd_str);
+
+               tcore_pending_set_request_data(pending, 0, atreq);
+               tcore_pending_set_response_callback(pending, on_response_sms_save_msg, NULL);
+               tcore_pending_link_user_request(pending, ur);
+               tcore_pending_set_send_callback(pending, on_confirmation_sms_message_send, NULL);
+               tcore_hal_send_request(hal, pending);
+
+               g_free(cmd_str);
+               free(hex_pdu);
+
+               dbg("Exit");
+               return TCORE_RETURN_SUCCESS;
+       }
+
+       err("Invalid Data len");
+       dbg("Exit");
+       return TCORE_RETURN_SMS_INVALID_DATA_LEN;
+}
+
+static TReturn delete_msg(CoreObject *obj, UserRequest *ur)
+{
+       gchar *cmd_str = NULL;
+       TcoreHal *hal = NULL;
+       TcoreATRequest *atreq = NULL;
+       TcorePending *pending = NULL;
+       const struct treq_sms_delete_msg *delete_msg = NULL;
+
+       dbg("Entry");
+
+       delete_msg = tcore_user_request_ref_data(ur, NULL);
+       hal = tcore_object_get_hal(obj);
+       if (NULL == delete_msg || NULL == hal) {
+               err("NULL input. Unable to proceed");
+               dbg("deleteMsg: [%p], hal: [%p]", delete_msg, hal);
+
+               dbg("Exit");
+               return TCORE_RETURN_EINVAL;
+       }
+
+       dbg("index: %d", delete_msg->index);
+
+       if (delete_msg->index == -1) {
+               cmd_str = g_strdup_printf("AT+CMGD=0,4"); // Delete All Messages
+       } else {
+               cmd_str = g_strdup_printf("AT+CMGD=%d,0", delete_msg->index + 1); // Delete specified index
+       }
+
+       pending = tcore_pending_new(obj, 0);
+       atreq = tcore_at_request_new((const char *) cmd_str, NULL, TCORE_AT_NO_RESULT);
+       if (NULL == cmd_str || NULL == atreq || NULL == pending) {
+               err("Out of memory. Unable to proceed");
+               dbg("cmd_str: [%p], atreq: [%p], pending: [%p]", cmd_str, atreq, pending);
+
+               // free memory we own
+               g_free(cmd_str);
+               util_sms_free_memory(atreq);
+               util_sms_free_memory(pending);
+
+               dbg("Exit");
+               return TCORE_RETURN_ENOMEM;
+       }
+
+       util_hex_dump("    ", strlen(cmd_str), (void *) cmd_str);
+
+       tcore_pending_set_request_data(pending, 0, atreq);
+       tcore_pending_set_response_callback(pending, on_response_sms_delete_msg, (void *) (uintptr_t) (delete_msg->index)); // storing index as user data for response
+       tcore_pending_link_user_request(pending, ur);
+       tcore_pending_set_send_callback(pending, on_confirmation_sms_message_send, NULL);
+       tcore_hal_send_request(hal, pending);
+
+       g_free(cmd_str);
+
+       dbg("Exit");
+       return TCORE_RETURN_SUCCESS;
+}
+
+static TReturn get_storedMsgCnt(CoreObject *obj, UserRequest *ur)
+{
+       gchar *cmd_str = NULL;
+       TcoreHal *hal = NULL;
+       TcoreATRequest *atreq = NULL;
+       TcorePending *pending = NULL;
+
+       dbg("Entry");
+
+       hal = tcore_object_get_hal(obj);
+       if (NULL == hal) {
+               err("NULL HAL. Unable to proceed");
+
+               dbg("Exit");
+               return TCORE_RETURN_EINVAL;
+       }
+
+       cmd_str = g_strdup_printf("AT+CPMS=\"SM\"");
+       pending = tcore_pending_new(obj, 0);
+       atreq = tcore_at_request_new((const char *) cmd_str, "+CPMS", TCORE_AT_SINGLELINE);
+
+       if (NULL == cmd_str || NULL == atreq || NULL == pending) {
+               err("Out of memory. Unable to proceed");
+               dbg("cmd_str: [%p], atreq: [%p], pending: [%p]", cmd_str, atreq, pending);
+
+               // free memory we own
+               g_free(cmd_str);
+               util_sms_free_memory(atreq);
+               util_sms_free_memory(pending);
+
+               dbg("Exit");
+               return TCORE_RETURN_ENOMEM;
+       }
+
+       util_hex_dump("    ", strlen(cmd_str), (void *) cmd_str);
+
+       tcore_pending_set_request_data(pending, 0, atreq);
+       tcore_pending_set_response_callback(pending, on_response_get_stored_msg_cnt, NULL);
+       tcore_pending_link_user_request(pending, ur);
+       tcore_pending_set_send_callback(pending, on_confirmation_sms_message_send, NULL);
+       tcore_hal_send_request(hal, pending);
+
+       g_free(cmd_str);
+
+       dbg("Exit");
+       return TCORE_RETURN_SUCCESS;
+}
+
+static TReturn get_sca(CoreObject *obj, UserRequest *ur)
+{
+       gchar *cmd_str = NULL;
+       TcoreHal *hal = NULL;
+       TcoreATRequest *atreq = NULL;
+       TcorePending *pending = NULL;
+
+       dbg("Entry");
+
+       hal = tcore_object_get_hal(obj);
+       if (NULL == hal) {
+               err("HAL NULL. Unable to proceed");
+
+               dbg("Exit");
+               return TCORE_RETURN_EINVAL;
+       }
+
+       cmd_str = g_strdup_printf("AT+CSCA?");
+       pending = tcore_pending_new(obj, 0);
+       atreq = tcore_at_request_new((const char *) cmd_str, "+CSCA", TCORE_AT_SINGLELINE);
+
+       if (NULL == cmd_str || NULL == atreq || NULL == pending) {
+               err("Out of memory. Unable to proceed");
+               dbg("cmd_str: [%p], atreq: [%p], pending: [%p]", cmd_str, atreq, pending);
+
+               // free memory we own
+               g_free(cmd_str);
+               util_sms_free_memory(atreq);
+               util_sms_free_memory(pending);
+
+               dbg("Exit");
+               return TCORE_RETURN_ENOMEM;
+       }
+
+       util_hex_dump("    ", strlen(cmd_str), (void *) cmd_str);
+
+       tcore_pending_set_request_data(pending, 0, atreq);
+       tcore_pending_set_response_callback(pending, on_response_get_sca, NULL);
+       tcore_pending_link_user_request(pending, ur);
+       tcore_pending_set_send_callback(pending, on_confirmation_sms_message_send, NULL);
+       tcore_hal_send_request(hal, pending);
+
+       g_free(cmd_str);
+
+       dbg("Exit");
+       return TCORE_RETURN_SUCCESS;
+}
+
+static TReturn set_sca(CoreObject *obj, UserRequest *ur)
+{
+       gchar *cmd_str = NULL;
+       TcoreHal *hal = NULL;
+       TcoreATRequest *atreq = NULL;
+       TcorePending *pending = NULL;
+       const struct treq_sms_set_sca *setSca = NULL;
+       int addrType = 0;
+
+       dbg("Entry");
+
+       setSca = tcore_user_request_ref_data(ur, NULL);
+       hal = tcore_object_get_hal(obj);
+       if (NULL == setSca || NULL == hal) {
+               err("NULL input. Unable to proceed");
+               dbg("setSca: [%p], hal: [%p]", setSca, hal);
+
+               dbg("Exit");
+               return TCORE_RETURN_EINVAL;
+       }
+
+       dbg("dialNumLen: %u, typeOfNum: %d, numPlanId: %d, ", setSca->scaInfo.dialNumLen, setSca->scaInfo.typeOfNum, setSca->scaInfo.numPlanId);
+
+       util_hex_dump("    ", (SMS_SMSP_ADDRESS_LEN + 1), (void *) setSca->scaInfo.diallingNum);
+
+       addrType = ((setSca->scaInfo.typeOfNum << 4) | setSca->scaInfo.numPlanId) | 0x80;
+
+       cmd_str = g_strdup_printf("AT+CSCA=\"%s\",%d", setSca->scaInfo.diallingNum, addrType);
+       pending = tcore_pending_new(obj, 0);
+       atreq = tcore_at_request_new((const char *) cmd_str, NULL, TCORE_AT_NO_RESULT);
+
+       if (NULL == cmd_str || NULL == atreq || NULL == pending) {
+               err("Out of memory. Unable to proceed");
+               dbg("cmd_str: [%p], atreq: [%p], pending: [%p]", cmd_str, atreq, pending);
+
+               // free memory we own
+               g_free(cmd_str);
+               util_sms_free_memory(atreq);
+               util_sms_free_memory(pending);
+
+               dbg("Exit");
+               return TCORE_RETURN_ENOMEM;
+       }
+
+       util_hex_dump("    ", strlen(cmd_str), (void *) cmd_str);
+
+       tcore_pending_set_request_data(pending, 0, atreq);
+       tcore_pending_set_response_callback(pending, on_response_set_sca, NULL);
+       tcore_pending_link_user_request(pending, ur);
+       tcore_pending_set_send_callback(pending, on_confirmation_sms_message_send, NULL);
+       tcore_hal_send_request(hal, pending);
+
+       g_free(cmd_str);
+
+       dbg("Exit");
+       return TCORE_RETURN_SUCCESS;
+}
+
+static TReturn get_cb_config(CoreObject *obj, UserRequest *ur)
+{
+       gchar *cmd_str = NULL;
+       TcoreHal *hal = NULL;
+       TcoreATRequest *atreq = NULL;
+       TcorePending *pending = NULL;
+
+       dbg("Entry");
+
+       hal = tcore_object_get_hal(obj);
+       if (NULL == hal) {
+               err("NULL HAL. Unable to proceed");
+
+               dbg("Exit");
+               return TCORE_RETURN_EINVAL;
+       }
+
+       cmd_str = g_strdup_printf("AT+CSCB?");
+       pending = tcore_pending_new(obj, 0);
+       atreq = tcore_at_request_new((const char *) cmd_str, "+CSCB", TCORE_AT_SINGLELINE);
+       if (NULL == cmd_str || NULL == atreq || NULL == pending) {
+               err("Out of memory. Unable to proceed");
+               dbg("cmd_str: [%p], atreq: [%p], pending: [%p]", cmd_str, atreq, pending);
+
+               // free memory we own
+               g_free(cmd_str);
+               util_sms_free_memory(atreq);
+               util_sms_free_memory(pending);
+
+               dbg("Exit");
+               return TCORE_RETURN_ENOMEM;
+       }
+
+       util_hex_dump("    ", strlen(cmd_str), (void *) cmd_str);
+
+       tcore_pending_set_request_data(pending, 0, atreq);
+       tcore_pending_set_response_callback(pending, on_response_get_cb_config, NULL);
+       tcore_pending_set_send_callback(pending, on_confirmation_sms_message_send, NULL);
+       tcore_pending_link_user_request(pending, ur);
+       tcore_hal_send_request(hal, pending);
+
+       g_free(cmd_str);
+
+       dbg("Exit");
+       return TCORE_RETURN_SUCCESS;
+}
+
+static TReturn set_cb_config(CoreObject *obj, UserRequest *ur)
+{
+       gchar *cmd_str = NULL;
+       gchar *mids_str = NULL;
+       GString *mids_GString = NULL;
+
+       TcoreHal *hal = NULL;
+       TcoreATRequest *atreq = NULL;
+       TcorePending *pending = NULL;
+       const struct treq_sms_set_cb_config *setCbConfig = NULL;
+       int ctr1 = 0, ctr2 = 0;
+       unsigned short appendMsgId = 0;
+
+       dbg("Entry");
+
+       setCbConfig = tcore_user_request_ref_data(ur, NULL);
+       hal = tcore_object_get_hal(obj);
+       if (NULL == setCbConfig || NULL == hal) {
+               err("NULL input. Unable to proceed");
+               dbg("setCbConfig: [%p], hal: [%p]", setCbConfig, hal);
+
+               dbg("Exit");
+               return TCORE_RETURN_EINVAL;
+       }
+
+       dbg("bCBEnabled: %d,  msgIdMaxCount: %x, msgIdCount: %d", setCbConfig->cbEnabled, setCbConfig->msgIdMaxCount, setCbConfig->msgIdRangeCount);
+       // util_hex_dump("    ", SMS_GSM_SMS_CBMI_LIST_SIZE_MAX, (void *)setCbConfig->msgIDs);
+
+       if (setCbConfig->cbEnabled == 2) { // Enable all CBS
+               cmd_str = g_strdup_printf("AT+CSCB=1");
+       } else if (setCbConfig->cbEnabled == 0) { // AT+CSCB=0: Disable CBS
+               cmd_str = g_strdup_printf("AT+CSCB=0");
+       } else {
+               mids_GString = g_string_new("AT+CSCB=0,\"");
+
+               for (ctr1 = 0; ctr1 < setCbConfig->msgIdRangeCount; ctr1++) {
+                       if (setCbConfig->msgIDs[ctr1].net3gpp.selected == FALSE)
+                               continue;
+
+                       if (SMS_GSM_SMS_CBMI_LIST_SIZE_MAX <= (setCbConfig->msgIDs[ctr1].net3gpp.toMsgId - setCbConfig->msgIDs[ctr1].net3gpp.fromMsgId)) {
+                               mids_GString = g_string_new("AT+CSCB=1");
+                               break;
+                       }
+
+                       appendMsgId = setCbConfig->msgIDs[ctr1].net3gpp.fromMsgId;
+
+                       for (ctr2 = 0; (ctr2 <= ((setCbConfig->msgIDs[ctr1].net3gpp.toMsgId) - (setCbConfig->msgIDs[ctr1].net3gpp.fromMsgId))); ctr2++) {
+                               dbg("%x", appendMsgId);
+                               mids_GString = g_string_append(mids_GString, g_strdup_printf("%d", appendMsgId));
+
+                               if (ctr2 == ((setCbConfig->msgIDs[ctr1].net3gpp.toMsgId) - (setCbConfig->msgIDs[ctr1].net3gpp.fromMsgId))) {
+                                       mids_GString = g_string_append(mids_GString, "\""); // Mids string termination
+                               } else {
+                                       mids_GString = g_string_append(mids_GString, ",");
+                               }
+
+                               appendMsgId++;
+                       }
+               }
+               mids_str = g_string_free(mids_GString, FALSE);
+               cmd_str = g_strdup_printf("%s", mids_str);
+               g_free(mids_str);
+       }
+
+       pending = tcore_pending_new(obj, 0);
+       atreq = tcore_at_request_new((const char *) cmd_str, NULL, TCORE_AT_NO_RESULT);
+       if (NULL == cmd_str || NULL == atreq || NULL == pending) {
+               err("Out of memory. Unable to proceed");
+               dbg("cmd_str: [%p], atreq: [%p], pending: [%p]", cmd_str, atreq, pending);
+
+               // free memory we own
+               g_free(cmd_str);
+               util_sms_free_memory(atreq);
+               util_sms_free_memory(pending);
+
+               dbg("Exit");
+               return TCORE_RETURN_ENOMEM;
+       }
+
+       util_hex_dump("    ", strlen(cmd_str), (void *) cmd_str);
+
+       tcore_pending_set_request_data(pending, 0, atreq);
+       tcore_pending_set_response_callback(pending, on_response_set_cb_config, NULL);
+       tcore_pending_link_user_request(pending, ur);
+       tcore_pending_set_send_callback(pending, on_confirmation_sms_message_send, NULL);
+       tcore_hal_send_request(hal, pending);
+
+       g_free(cmd_str);
+
+       dbg("Exit");
+       return TCORE_RETURN_SUCCESS;
+}
+
+static TReturn set_mem_status(CoreObject *obj, UserRequest *ur)
+{
+       gchar *cmd_str = NULL;
+       TcoreHal *hal = NULL;
+       TcoreATRequest *atreq = NULL;
+       TcorePending *pending = NULL;
+       const struct treq_sms_set_mem_status *setMemStatus = NULL;
+       int memoryStatus = 0;
+
+       dbg("Entry");
+
+       setMemStatus = tcore_user_request_ref_data(ur, NULL);
+       hal = tcore_object_get_hal(obj);
+       if (NULL == setMemStatus || NULL == hal) {
+               err("NULL input. Unable to proceed");
+               dbg("setMemStatus: [%p], hal: [%p]", setMemStatus, hal);
+
+               dbg("Exit");
+               return TCORE_RETURN_EINVAL;
+       }
+
+       dbg("memory_status: %d", setMemStatus->memory_status);
+
+       if (setMemStatus->memory_status < SMS_PDA_MEMORY_STATUS_AVAILABLE
+               || setMemStatus->memory_status > SMS_PDA_MEMORY_STATUS_FULL) {
+               err("Invalid memory_status");
+
+               dbg("Exit");
+               return TCORE_RETURN_EINVAL;
+       }
+
+       switch (setMemStatus->memory_status) {
+       case SMS_PDA_MEMORY_STATUS_AVAILABLE:
+               memoryStatus = AT_MEMORY_AVAILABLE;
+               break;
+
+       case SMS_PDA_MEMORY_STATUS_FULL:
+               memoryStatus = AT_MEMORY_FULL;
+               break;
+
+       default:
+               err("Invalid memory_status");
+               dbg("Exit");
+               return TCORE_RETURN_EINVAL;
+       }
+
+       cmd_str = g_strdup_printf("AT+XTESM=%d", memoryStatus);
+       pending = tcore_pending_new(obj, 0);
+       atreq = tcore_at_request_new((const char *) cmd_str, NULL, TCORE_AT_NO_RESULT);
+
+       if (NULL == cmd_str || NULL == atreq || NULL == pending) {
+               err("Out of memory. Unable to proceed");
+               dbg("cmd_str: [%p], atreq: [%p], pending: [%p]", cmd_str, atreq, pending);
+
+               // free memory we own
+               g_free(cmd_str);
+               util_sms_free_memory(atreq);
+               util_sms_free_memory(pending);
+
+               dbg("Exit");
+               return TCORE_RETURN_ENOMEM;
+       }
+
+       util_hex_dump("    ", strlen(cmd_str), (void *) cmd_str);
+
+       tcore_pending_set_request_data(pending, 0, atreq);
+       tcore_pending_set_response_callback(pending, on_response_set_mem_status, NULL);
+       tcore_pending_link_user_request(pending, ur);
+       tcore_pending_set_send_callback(pending, on_confirmation_sms_message_send, NULL);
+       tcore_hal_send_request(hal, pending);
+
+       g_free(cmd_str);
+
+       dbg("Exit");
+       return TCORE_RETURN_SUCCESS;
+}
+
+static TReturn set_delivery_report(CoreObject *obj, UserRequest *ur)
+{
+       struct tresp_sms_set_delivery_report respSetDeliveryReport = {0, };
+
+       respSetDeliveryReport.result = SMS_SUCCESS;
+
+       dbg("Entry");
+
+       dbg("CP takes care of sending SMS ack to network for all classes of SMS. Sending default success.");
+
+       tcore_user_request_send_response(ur, TRESP_SMS_SET_DELIVERY_REPORT, sizeof(struct tresp_sms_set_delivery_report), &respSetDeliveryReport);
+
+       dbg("Exit");
+       return TCORE_RETURN_SUCCESS;
+}
+
+static TReturn set_msg_status(CoreObject *obj, UserRequest *ur)
+{
+       gchar *cmd_str = NULL;
+       TcoreHal *hal = NULL;
+       TcoreATRequest *atreq = NULL;
+       TcorePending *pending = NULL;
+       const struct treq_sms_set_msg_status *msg_status = NULL;
+
+       dbg("Entry");
+
+       msg_status = tcore_user_request_ref_data(ur, NULL);
+
+       cmd_str = g_strdup_printf("AT+CRSM=178,28476,%d,4,%d", (msg_status->index + 1), AT_EF_SMS_RECORD_LEN);
+       atreq = tcore_at_request_new((const char *) cmd_str, "+CRSM", TCORE_AT_SINGLELINE);
+       pending = tcore_pending_new(obj, 0);
+       if (NULL == cmd_str || NULL == atreq || NULL == pending) {
+               err("Out of memory. Unable to proceed");
+               dbg("cmd_str: [%p], atreq: [%p], pending: [%p]", cmd_str, atreq, pending);
+
+               // free memory we own
+               g_free(cmd_str);
+               util_sms_free_memory(atreq);
+               util_sms_free_memory(pending);
+
+               dbg("Exit");
+               return TCORE_RETURN_ENOMEM;
+       }
+
+       util_hex_dump("    ", strlen(cmd_str), (void *) cmd_str);
+
+       tcore_pending_set_request_data(pending, 0, atreq);
+       tcore_pending_set_response_callback(pending, _response_get_efsms_data, NULL);
+       tcore_pending_link_user_request(pending, ur);
+       tcore_pending_set_send_callback(pending, on_confirmation_sms_message_send, NULL);
+       tcore_hal_send_request(hal, pending);
+
+       g_free(cmd_str);
+
+       dbg("Exit");
+       return TCORE_RETURN_SUCCESS;
+}
+
+static TReturn get_sms_params(CoreObject *obj, UserRequest *ur)
+{
+       gchar *cmd_str = NULL;
+       TcoreHal *hal = NULL;
+       TcoreATRequest *atreq = NULL;
+       TcorePending *pending = NULL;
+       const struct treq_sms_get_params *getSmsParams = NULL;
+       int record_len = 0, *smsp_record_len = NULL;
+
+       dbg("Entry");
+
+       getSmsParams = tcore_user_request_ref_data(ur, NULL);
+       hal = tcore_object_get_hal(obj);
+       if (NULL == getSmsParams || NULL == hal) {
+               err("NULL input. Unable to proceed");
+               dbg("getSmsParams: [%p], hal: [%p]", getSmsParams, hal);
+
+               dbg("Exit");
+               return TCORE_RETURN_EINVAL;
+       }
+
+       smsp_record_len = tcore_plugin_ref_property(tcore_object_ref_plugin(obj), "SMSPRECORDLEN");
+       record_len = *smsp_record_len;
+       dbg("record len from property %d", record_len);
+
+       // AT+CRSM=command>[,<fileid>[,<P1>,<P2>,<P3>[,<data>[,<pathid>]]]]
+       cmd_str = g_strdup_printf("AT+CRSM=178,28482,%d,4,%d", (getSmsParams->index + 1), record_len);
+
+       dbg("cmd_str is %s", cmd_str);
+
+       atreq = tcore_at_request_new((const char *) cmd_str, "+CRSM", TCORE_AT_SINGLELINE);
+       pending = tcore_pending_new(obj, 0);
+       if (NULL == cmd_str || NULL == atreq || NULL == pending) {
+               err("Out of memory. Unable to proceed");
+               dbg("cmd_str: [%p], atreq: [%p], pending: [%p]", cmd_str, atreq, pending);
+
+               // free memory we own
+               g_free(cmd_str);
+               util_sms_free_memory(atreq);
+               util_sms_free_memory(pending);
+
+               dbg("Exit");
+               return TCORE_RETURN_ENOMEM;
+       }
+
+       util_hex_dump("    ", strlen(cmd_str), (void *) cmd_str);
+
+       tcore_pending_set_request_data(pending, 0, atreq);
+       tcore_pending_set_response_callback(pending, on_response_get_sms_params, NULL);
+       tcore_pending_link_user_request(pending, ur);
+       tcore_pending_set_send_callback(pending, on_confirmation_sms_message_send, NULL);
+       tcore_hal_send_request(hal, pending);
+
+       g_free(cmd_str);
+
+       dbg("Exit");
+       return TCORE_RETURN_SUCCESS;
+}
+
+static TReturn set_sms_params(CoreObject *obj, UserRequest *ur)
+{
+       gchar *cmd_str = NULL;
+       char *encoded_data = NULL;
+       unsigned char *temp_data = NULL;
+       int SMSPRecordLen = 0;
+
+       TcoreHal *hal = NULL;
+       TcoreATRequest *atreq = NULL;
+       TcorePending *pending = NULL;
+       const struct treq_sms_set_params *setSmsParams = NULL;
+       int encoded_data_len = 0;
+
+       dbg("Entry");
+
+       setSmsParams = tcore_user_request_ref_data(ur, NULL);
+       hal = tcore_object_get_hal(obj);
+       if (NULL == setSmsParams || NULL == hal) {
+               err("NULL input. Unable to proceed");
+               dbg("setSmsParams: [%p], hal: [%p]", setSmsParams, hal);
+               return FALSE;
+       }
+
+       // EFsmsp file size is 28 +Y bytes (Y is alpha id size)
+       SMSPRecordLen = 28 + setSmsParams->params.alphaIdLen;
+       temp_data = calloc(SMSPRecordLen, 1);
+       encoded_data = calloc(SMSPRecordLen * 2 + 1, 1);
+
+       _tcore_util_sms_encode_smsParameters(&(setSmsParams->params), temp_data, SMSPRecordLen);
+
+       util_byte_to_hex((const char *) temp_data, (char *) encoded_data, SMSPRecordLen);
+
+       encoded_data_len = ((SMSPRecordLen) * 2);
+
+       hal = tcore_object_get_hal(obj);
+       pending = tcore_pending_new(obj, 0);
+
+       dbg("alpha id len %d encoded data %s. Encoded data len %d", setSmsParams->params.alphaIdLen, encoded_data, encoded_data_len);
+       cmd_str = g_strdup_printf("AT+CRSM=220,28482,%d,4,%d,\"%s\"", (setSmsParams->params.recordIndex + 1), SMSPRecordLen, encoded_data);
+
+       dbg("cmd str is %s", cmd_str);
+       atreq = tcore_at_request_new(cmd_str, "+CRSM:", TCORE_AT_SINGLELINE);
+
+       if (NULL == cmd_str || NULL == atreq || NULL == pending) {
+               err("Out of memory. Unable to proceed");
+               dbg("cmd_str: [%p], atreq: [%p], pending: [%p]", cmd_str, atreq, pending);
+
+               // free memory we own
+               g_free(cmd_str);
+               util_sms_free_memory(atreq);
+               util_sms_free_memory(pending);
+
+               util_sms_free_memory(temp_data);
+               util_sms_free_memory(encoded_data);
+
+               dbg("Exit");
+               return TCORE_RETURN_ENOMEM;
+       }
+
+       util_hex_dump("    ", strlen(cmd_str), (void *) cmd_str);
+
+       tcore_pending_set_request_data(pending, 0, atreq);
+       tcore_pending_set_response_callback(pending, on_response_set_sms_params, NULL);
+       tcore_pending_link_user_request(pending, ur);
+       tcore_pending_set_send_callback(pending, on_confirmation_sms_message_send, NULL);
+       tcore_hal_send_request(hal, pending);
+
+       g_free(cmd_str);
+       util_sms_free_memory(temp_data);
+       util_sms_free_memory(encoded_data);
+
+       return TRUE;
+}
+
+static TReturn get_paramcnt(CoreObject *obj, UserRequest *ur)
+{
+       gchar *cmd_str = NULL;
+       TcoreHal *hal = NULL;
+       TcoreATRequest *atreq = NULL;
+       TcorePending *pending = NULL;
+
+       dbg("Entry");
+
+       hal = tcore_object_get_hal(obj);
+       if (NULL == hal) {
+               err("NULL HAL. Unable to proceed");
+
+               dbg("Exit");
+               return TCORE_RETURN_EINVAL;
+       }
+
+       // AT+CRSM=command>[,<fileid>[,<P1>,<P2>,<P3>[,<data>[,<pathid>]]]]
+       cmd_str = g_strdup_printf("AT+CRSM=192,28482");
+       atreq = tcore_at_request_new((const char *) cmd_str, "+CRSM", TCORE_AT_SINGLELINE);
+       pending = tcore_pending_new(obj, 0);
+
+       if (NULL == cmd_str || NULL == atreq || NULL == pending) {
+               err("NULL pointer. Unable to proceed");
+               dbg("cmd_str: [%p], atreq: [%p], pending: [%p]", cmd_str, atreq, pending);
+
+               // free memory we own
+               g_free(cmd_str);
+               util_sms_free_memory(atreq);
+               util_sms_free_memory(pending);
+
+               dbg("Exit");
+               return TCORE_RETURN_FAILURE;
+       }
+
+       util_hex_dump("    ", strlen(cmd_str), (void *) cmd_str);
+
+       tcore_pending_set_request_data(pending, 0, atreq);
+       tcore_pending_set_response_callback(pending, on_response_get_paramcnt, NULL);
+       tcore_pending_link_user_request(pending, ur);
+       tcore_pending_set_send_callback(pending, on_confirmation_sms_message_send, NULL);
+       tcore_hal_send_request(hal, pending);
+
+       g_free(cmd_str);
+
+       dbg("Exit");
+       return TCORE_RETURN_SUCCESS;
+}
+
+static struct tcore_sms_operations sms_ops = {
+       .send_umts_msg = send_umts_msg,
+       .read_msg = read_msg,
+       .save_msg = save_msg,
+       .delete_msg = delete_msg,
+       .get_storedMsgCnt = get_storedMsgCnt,
+       .get_sca = get_sca,
+       .set_sca = set_sca,
+       .get_cb_config = get_cb_config,
+       .set_cb_config = set_cb_config,
+       .set_mem_status = set_mem_status,
+       .get_pref_brearer = NULL,
+       .set_pref_brearer = NULL,
+       .set_delivery_report = set_delivery_report,
+       .set_msg_status = set_msg_status,
+       .get_sms_params = get_sms_params,
+       .set_sms_params = set_sms_params,
+       .get_paramcnt = get_paramcnt,
+};
+
+gboolean s_sms_init(TcorePlugin *plugin, TcoreHal *hal)
+{
+       CoreObject *obj = NULL;
+       struct property_sms_info *data = NULL;
+       GQueue *work_queue = NULL;
+       int *smsp_record_len = NULL;
+
+       dbg("Entry");
+       dbg("plugin: [%p]", plugin);
+       dbg("hal: [%p]", hal);
+
+       obj = tcore_sms_new(plugin, "umts_sms", &sms_ops, hal);
+
+       data = calloc(sizeof(struct property_sms_info), 1);
+
+       if (NULL == obj || NULL == data) {
+               err("Unable to initialize. Exiting");
+               s_sms_exit(plugin);
+
+               dbg("Exit");
+               return FALSE;
+       }
+
+       work_queue = g_queue_new();
+       tcore_object_link_user_data(obj, work_queue);
+
+       // Registering for SMS notifications
+       tcore_object_add_callback(obj, "\e+CMTI", on_event_class2_sms_incom_msg, NULL);
+       tcore_object_add_callback(obj, "\e+CMT", on_event_sms_incom_msg, NULL);
+
+       tcore_object_add_callback(obj, "\e+CDS", on_event_sms_incom_msg, NULL);
+       tcore_object_add_callback(obj, "+XSMSMMSTAT", on_event_sms_memory_status, NULL);
+       tcore_object_add_callback(obj, "+CMS", on_event_sms_memory_status, NULL);
+
+       tcore_object_add_callback(obj, "\e+CBMI", on_event_sms_cb_incom_msg, NULL);
+       tcore_object_add_callback(obj, "\e+CBM", on_event_sms_cb_incom_msg, NULL);
+       tcore_object_add_callback(obj, "+XSIM", on_event_sms_ready_status, NULL);
+
+       tcore_plugin_link_property(plugin, "SMS", data);
+
+       // storing smsp record length
+       smsp_record_len = calloc(sizeof(int), 1);
+       tcore_plugin_link_property(plugin, "SMSPRECORDLEN", smsp_record_len);
+
+       dbg("Exit");
+       return TRUE;
+}
+
+void s_sms_exit(TcorePlugin *plugin)
+{
+       CoreObject *obj = NULL;
+       struct property_sms_info *data = NULL;
+
+       dbg("Entry");
+       dbg("plugin: [%p]", plugin);
+
+       obj = tcore_plugin_ref_core_object(plugin, "umts_sms");
+       if (NULL == obj) {
+               err("NULL core object. Nothing to do.");
+               return;
+       }
+       tcore_sms_free(obj);
+
+       data = tcore_plugin_ref_property(plugin, "SMS");
+       util_sms_free_memory(data);
+
+       dbg("Exit");
+       return;
+}