4 * Copyright (c) 2012 Samsung Electronics Co., Ltd. All rights reserved.
6 * Contact: Madhavi Akella <madhavi.a@samsung.com>
8 * Licensed under the Apache License, Version 2.0 (the "License");
9 * you may not use this file except in compliance with the License.
10 * You may obtain a copy of the License at
12 * http://www.apache.org/licenses/LICENSE-2.0
14 * Unless required by applicable law or agreed to in writing, software
15 * distributed under the License is distributed on an "AS IS" BASIS,
16 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 * See the License for the specific language governing permissions and
18 * limitations under the License.
30 #include <core_object.h>
35 #include <user_request.h>
43 #include "common/TelErr.h"
47 /*=============================================================
49 ==============================================================*/
50 #define MAX_GSM_SMS_TPDU_SIZE 244
51 #define MAX_GSM_SMS_MSG_NUM 255
52 #define MAX_GSM_SMS_SERVICE_CENTER_ADDR 12 /* Maximum number of bytes of service center address */
53 #define MAX_GSM_SMS_CBMI_LIST_SIZE 100 /* Maximum number of CBMI list size for CBS 30*2=60 */
54 #define MAX_GSM_SMS_PARAM_RECORD_SIZE 156 /* Maximum number of bytes SMSP Record size (Y + 28), y : 0 ~ 128 */
55 #define MAX_GSM_SMS_STATUS_FILE_SIZE 2 /* Last Used TP-MR + SMS "Memory Cap. Exceeded" Noti Flag */
56 #define TAPI_SIM_SMSP_ADDRESS_LEN 20
58 /*=============================================================
60 ==============================================================*/
61 #define SMS_DEVICE_READY 1 /* Telephony device ready */
62 #define SMS_DEVICE_NOT_READY 0 /* Telephony device not ready */
64 /*=============================================================
66 ==============================================================*/
67 #define SMS_CBMI_SELECTED_SOME 0x02 /* Some CBMIs are selected */
68 #define SMS_CBMI_SELECTED_ALL 0x01 /* All CBMIs are selected */
70 /*=============================================================
72 ==============================================================*/
73 #define AT_REC_UNREAD 0 /* Received and Unread */
74 #define AT_REC_READ 1 /* Received and Read */
75 #define AT_STO_UNSENT 2 /* Unsent */
76 #define AT_STO_SENT 3 /* Sent */
77 #define AT_ALL 4 /* Unknown */
79 /*=============================================================
81 ==============================================================*/
82 #define AT_MEMORY_AVAILABLE 0 /* Memory Available */
83 #define AT_MEMORY_FULL 1 /* Memory Full */
85 /*=============================================================
86 SIM CRSM SW1 and Sw2 Error definitions */
88 #define AT_SW1_SUCCESS 0x90
89 #define AT_SW2_SUCCESS 0
90 #define AT_SW1_LEN_RESP 0x9F
92 #define AT_MAX_RECORD_LEN 256
93 /* SCA 12 bytes long and TDPU is 164 bytes long */
94 #define PDU_LEN_MAX 176
95 #define HEX_PDU_LEN_MAX ((PDU_LEN_MAX * 2) + 1)
97 /*=============================================================
99 ==============================================================*/
100 #define CR '\r' /* Carriage Return */
102 /*=============================================================
104 ==============================================================*/
105 #define SMS_SWAPBYTES16(x) (((x) & 0xffff0000) | (((x) & 0x0000ff00) >> 8) | (((x) & 0x000000ff) << 8))
107 void print_glib_list_elem(gpointer data, gpointer user_data);
109 static void on_response_class2_read_msg(TcorePending *pending, int data_len, const void *data, void *user_data);
112 gboolean util_byte_to_hex(const char *byte_pdu, char *hex_pdu, int num_bytes);
114 void print_glib_list_elem(gpointer data, gpointer user_data)
116 char *item = (char *)data;
118 dbg("item: [%s]", item);
121 /*=============================================================
123 ==============================================================*/
124 static void on_confirmation_sms_message_send(TcorePending *p, gboolean result, void *user_data)
126 dbg("Entered Function. Request message out from queue");
128 dbg("TcorePending: [%p]", p);
129 dbg("result: [%02x]", result);
130 dbg("user_data: [%p]", user_data);
132 if (result == TRUE) {
134 } else { /* Failed */
138 dbg("Exiting Function. Nothing to return");
141 /*=============================================================
143 ==============================================================*/
144 static void util_sms_free_memory(void *sms_ptr)
148 if (NULL != sms_ptr) {
149 dbg("Freeing memory location: [%p]", sms_ptr);
153 err("Invalid memory location. Nothing to do.");
160 static int util_sms_decode_smsParameters(unsigned char *incoming, unsigned int length, struct telephony_sms_Params *params)
162 int alpha_id_len = 0;
166 dbg(" RecordLen = %d", length);
168 if(incoming == NULL || params == NULL)
171 alpha_id_len = length -SMS_SMSP_PARAMS_MAX_LEN;
173 if (alpha_id_len > 0) {
174 if (alpha_id_len > SMS_SMSP_ALPHA_ID_LEN_MAX) {
175 alpha_id_len = SMS_SMSP_ALPHA_ID_LEN_MAX;
178 for (i = 0; i < alpha_id_len; i++) {
179 if (0xff == incoming[i]) {
185 memcpy(params->szAlphaId, incoming, i);
187 params->alphaIdLen = i;
189 dbg(" Alpha id length = %d", i);
191 params->alphaIdLen = 0;
192 dbg(" Alpha id length is zero");
195 params->paramIndicator = incoming[alpha_id_len];
197 dbg(" Param Indicator = %02x", params->paramIndicator);
199 if ((params->paramIndicator & SMSPValidDestAddr) == 0) {
200 nOffset = nDestAddrOffset;
202 if (0x00 == incoming[alpha_id_len + nOffset] || 0xff == incoming[alpha_id_len + nOffset]) {
203 params->tpDestAddr.dialNumLen = 0;
205 dbg("DestAddr Length is 0");
207 if (0 < (int) incoming[alpha_id_len + nOffset]) {
208 params->tpDestAddr.dialNumLen = (int) (incoming[alpha_id_len + nOffset] - 1);
210 if (params->tpDestAddr.dialNumLen > SMS_SMSP_ADDRESS_LEN)
211 params->tpDestAddr.dialNumLen = SMS_SMSP_ADDRESS_LEN;
213 params->tpDestAddr.dialNumLen = 0;
216 params->tpDestAddr.numPlanId = incoming[alpha_id_len + (++nOffset)] & 0x0f;
217 params->tpDestAddr.typeOfNum = (incoming[alpha_id_len + nOffset] & 0x70) >> 4;
219 memcpy(params->tpDestAddr.diallingNum, &incoming[alpha_id_len + (++nOffset)], (params->tpDestAddr.dialNumLen));
221 dbg("Dest TON is %d", params->tpDestAddr.typeOfNum);
222 dbg("Dest NPI is %d", params->tpDestAddr.numPlanId);
223 dbg("Dest Length = %d", params->tpDestAddr.dialNumLen);
224 dbg("Dest Addr = %s", params->tpDestAddr.diallingNum);
227 params->tpDestAddr.dialNumLen = 0;
230 if ((params->paramIndicator & SMSPValidSvcAddr) == 0) {
231 nOffset = nSCAAddrOffset;
233 if (0x00 == (int) incoming[alpha_id_len + nOffset] || 0xff == (int) incoming[alpha_id_len + nOffset]) {
234 params->tpSvcCntrAddr.dialNumLen = 0;
236 dbg(" SCAddr Length is 0");
238 if (0 < (int) incoming[alpha_id_len + nOffset]) {
239 params->tpSvcCntrAddr.dialNumLen = (int) (incoming[alpha_id_len + nOffset] - 1);
241 if (params->tpSvcCntrAddr.dialNumLen > SMS_SMSP_ADDRESS_LEN)
242 params->tpSvcCntrAddr.dialNumLen = SMS_SMSP_ADDRESS_LEN;
244 params->tpSvcCntrAddr.numPlanId = incoming[alpha_id_len + (++nOffset)] & 0x0f;
245 params->tpSvcCntrAddr.typeOfNum = (incoming[alpha_id_len + nOffset] & 0x70) >> 4;
247 memcpy(params->tpSvcCntrAddr.diallingNum, &incoming[alpha_id_len + (++nOffset)], (params->tpSvcCntrAddr.dialNumLen));
249 dbg("SCAddr Length = %d ", params->tpSvcCntrAddr.dialNumLen);
250 dbg("SCAddr TON is %d", params->tpSvcCntrAddr.typeOfNum);
251 dbg("SCAddr NPI is %d", params->tpSvcCntrAddr.numPlanId);
253 for (i = 0; i < (int) params->tpSvcCntrAddr.dialNumLen; i++)
254 dbg("SCAddr = %d [%02x]", i, params->tpSvcCntrAddr.diallingNum[i]);
256 params->tpSvcCntrAddr.dialNumLen = 0;
259 } else if ((0x00 < (int) incoming[alpha_id_len + nSCAAddrOffset] && (int) incoming[alpha_id_len + nSCAAddrOffset] <= 12)
260 || 0xff != (int) incoming[alpha_id_len + nSCAAddrOffset]) {
261 nOffset = nSCAAddrOffset;
263 if (0x00 == (int) incoming[alpha_id_len + nOffset] || 0xff == (int) incoming[alpha_id_len + nOffset]) {
264 params->tpSvcCntrAddr.dialNumLen = 0;
265 dbg("SCAddr Length is 0");
267 if (0 < (int) incoming[alpha_id_len + nOffset]) {
268 params->tpSvcCntrAddr.dialNumLen = (int) (incoming[alpha_id_len + nOffset] - 1);
270 params->tpSvcCntrAddr.dialNumLen = incoming[alpha_id_len + nOffset] - 1;
272 if (params->tpSvcCntrAddr.dialNumLen > SMS_SMSP_ADDRESS_LEN)
273 params->tpSvcCntrAddr.dialNumLen = SMS_SMSP_ADDRESS_LEN;
275 params->tpSvcCntrAddr.numPlanId = incoming[alpha_id_len + (++nOffset)] & 0x0f;
276 params->tpSvcCntrAddr.typeOfNum = (incoming[alpha_id_len + nOffset] & 0x70) >> 4;
278 memcpy(params->tpSvcCntrAddr.diallingNum, &incoming[alpha_id_len + (++nOffset)],
279 (params->tpSvcCntrAddr.dialNumLen));
281 dbg("SCAddr Length = %d ", params->tpSvcCntrAddr.dialNumLen);
282 dbg("SCAddr TON is %d", params->tpSvcCntrAddr.typeOfNum);
283 dbg("SCAddr NPI is %d", params->tpSvcCntrAddr.numPlanId);
285 for (i = 0; i < (int) params->tpSvcCntrAddr.dialNumLen; i++)
286 dbg("SCAddr = %d [%02x]", i, params->tpSvcCntrAddr.diallingNum[i]);
288 params->tpSvcCntrAddr.dialNumLen = 0;
292 params->tpSvcCntrAddr.dialNumLen = 0;
295 if ((params->paramIndicator & SMSPValidPID) == 0 && (alpha_id_len + nPIDOffset) < MAX_GSM_SMS_PARAM_RECORD_SIZE) {
296 params->tpProtocolId = incoming[alpha_id_len + nPIDOffset];
298 if ((params->paramIndicator & SMSPValidDCS) == 0 && (alpha_id_len + nDCSOffset) < MAX_GSM_SMS_PARAM_RECORD_SIZE) {
299 params->tpDataCodingScheme = incoming[alpha_id_len + nDCSOffset];
301 if ((params->paramIndicator & SMSPValidVP) == 0 && (alpha_id_len + nVPOffset) < MAX_GSM_SMS_PARAM_RECORD_SIZE) {
302 params->tpValidityPeriod = incoming[alpha_id_len + nVPOffset];
305 dbg(" Alpha Id(Len) = %d", (int) params->alphaIdLen);
307 for (i = 0; i < (int) params->alphaIdLen; i++) {
308 dbg(" Alpha Id = [%d] [%c]", i, params->szAlphaId[i]);
310 dbg(" PID = %d",params->tpProtocolId);
311 dbg(" DCS = %d",params->tpDataCodingScheme);
312 dbg(" VP = %d",params->tpValidityPeriod);
317 /*=============================================================
319 ==============================================================*/
320 static gboolean on_event_class2_sms_incom_msg(CoreObject *obj,
321 const void *event_info, void *user_data)
323 //+CMTI: <mem>,<index>
325 GSList *tokens = NULL , *lines = NULL;
326 char *line = NULL, *cmd_str = NULL;
327 int index = 0, mem_type = 0;
328 TcoreHal *hal = NULL;
329 TcoreATRequest *atreq = NULL;
330 TcorePending *pending = NULL;
332 dbg("Entered Function");
334 lines = (GSList *)event_info;
335 line = (char *)g_slist_nth_data(lines, 0); /* Fetch Line 1 */
337 dbg("Line 1: [%s]", line);
340 err("Line 1 is invalid");
344 tokens = tcore_at_tok_new(line); /* Split Line 1 into tokens */
345 mem_type = atoi(g_slist_nth_data(tokens, 0)); // Type of Memory stored
346 index = atoi((char *) g_slist_nth_data(tokens, 1));
348 hal = tcore_object_get_hal(obj);
350 err("NULL input. Unable to proceed");
351 dbg("readMsg: hal: [%p]", hal);
354 return TCORE_RETURN_EINVAL;
357 dbg("index: [%d]", index);
359 cmd_str = g_strdup_printf("AT+CMGR=%d", index);
360 atreq = tcore_at_request_new((const char *)cmd_str, "+CMGR", TCORE_AT_PDU);
361 pending = tcore_pending_new(obj, 0);
363 if (NULL == cmd_str || NULL == atreq || NULL == pending) {
364 err("Out of memory. Unable to proceed");
365 dbg("cmd_str: [%p], atreq: [%p], pending: [%p]", cmd_str, atreq, pending);
369 util_sms_free_memory(atreq);
370 util_sms_free_memory(pending);
373 return TCORE_RETURN_ENOMEM;
376 util_hex_dump(" ", strlen(cmd_str), (void *)cmd_str);
378 tcore_pending_set_request_data(pending, 0, atreq);
379 tcore_pending_set_response_callback(pending, on_response_class2_read_msg, (void *)(uintptr_t)index); //storing index as user data for response
380 tcore_pending_link_user_request(pending, NULL);
381 tcore_pending_set_send_callback(pending, on_confirmation_sms_message_send, NULL);
382 tcore_hal_send_request(hal, pending);
386 tcore_at_tok_free(tokens);
391 static gboolean on_event_sms_incom_msg(CoreObject *o, const void *event_info, void *user_data)
393 //+CMT: [<alpha>],<length><CR><LF><pdu> (PDU mode enabled);
396 GSList *tokens = NULL;
397 GSList *lines = NULL;
399 int pdu_len = 0, no_of_tokens = 0;
400 unsigned char *bytePDU = NULL;
401 struct tnoti_sms_umts_msg gsmMsgInfo;
404 dbg("Entered Function");
406 lines = (GSList *)event_info;
407 memset(&gsmMsgInfo, 0x00, sizeof(struct tnoti_sms_umts_msg));
409 if (2 != g_slist_length(lines)) {
410 err("Invalid number of lines for +CMT. Must be 2");
414 line = (char *)g_slist_nth_data(lines, 0); /* Fetch Line 1 */
416 dbg("Line 1: [%s]", line);
419 err("Line 1 is invalid");
423 tokens = tcore_at_tok_new(line); /* Split Line 1 into tokens */
425 no_of_tokens = g_slist_length(tokens);
427 if (no_of_tokens == 2) { // in case of incoming SMS +CMT
428 dbg("Alpha ID: [%02x]", g_slist_nth_data(tokens, 0)); /* 0: Alpha ID */
429 pdu_len = atoi((char *)g_slist_nth_data(tokens, 1));
430 dbg("pdu_len: [%d]", pdu_len); /* 1: PDU Length */
431 } else if (no_of_tokens == 1) { // in case of incoming status report +CDS
432 pdu_len = atoi((char *)g_slist_nth_data(tokens, 0));
433 dbg("pdu_len: [%d]", pdu_len); /* 1: PDU Length */
436 line = (char *)g_slist_nth_data(lines, 1); /* Fetch Line 2 */
438 dbg("Line 2: [%s]", line);
441 err("Line 2 is invalid");
445 /* Convert to Bytes */
446 bytePDU = (unsigned char *)util_hexStringToBytes(line);
448 sca_length = bytePDU[0];
450 dbg("SCA length = %d", sca_length);
452 gsmMsgInfo.msgInfo.msgLength = pdu_len;
454 if (sca_length == 0) {
455 memcpy(gsmMsgInfo.msgInfo.tpduData, &bytePDU[1], gsmMsgInfo.msgInfo.msgLength);
457 memcpy(gsmMsgInfo.msgInfo.sca, &bytePDU[1], sca_length);
458 memcpy(gsmMsgInfo.msgInfo.tpduData, &bytePDU[sca_length+1], gsmMsgInfo.msgInfo.msgLength);
461 util_hex_dump(" ", strlen(line)/2, bytePDU);
462 util_hex_dump(" ", sca_length, gsmMsgInfo.msgInfo.sca);
463 util_hex_dump(" ", gsmMsgInfo.msgInfo.msgLength,gsmMsgInfo.msgInfo.tpduData);
465 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);
468 tcore_at_tok_free(tokens);
477 static gboolean on_event_sms_memory_status(CoreObject *o, const void *event_info, void *user_data)
479 struct tnoti_sms_memory_status memStatusInfo = {0,};
481 int rtn = -1 ,memoryStatus = -1;
484 char *line = NULL , *pResp = NULL;
488 lines = (GSList *)event_info;
489 if (1 != g_slist_length(lines)) {
490 dbg("unsolicited msg but multiple line");
493 line = (char*)(lines->data);
497 tokens = tcore_at_tok_new(line);
498 pResp = g_slist_nth_data(tokens, 0);
501 memoryStatus = atoi(pResp);
502 dbg("memoryStatus is %d",memoryStatus);
503 if (memoryStatus == 0) {//SIM Full condition
504 memStatusInfo.status = SMS_PHONE_MEMORY_STATUS_FULL;
506 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);
508 tcore_at_tok_free(tokens);
517 static gboolean on_event_sms_cb_incom_msg(CoreObject *o, const void *event_info, void *user_data)
519 //+CBM: <length><CR><LF><pdu>
521 struct tnoti_sms_cellBroadcast_msg cbMsgInfo;
523 int rtn = -1 , length = 0;
524 char * line = NULL, *pdu = NULL, *pResp = NULL;
525 GSList *tokens = NULL;
526 GSList *lines = NULL;
528 dbg(" Func Entrance");
530 lines = (GSList *)event_info;
532 memset(&cbMsgInfo, 0, sizeof(struct tnoti_sms_cellBroadcast_msg));
534 line = (char *)(lines->data);
538 dbg("Noti line is %s",line);
539 tokens = tcore_at_tok_new(line); /* Split Line 1 into tokens */
541 pResp = g_slist_nth_data(tokens, 0);
543 length = atoi(pResp);
545 dbg("token 0 is null");
548 pdu = g_slist_nth_data(lines, 1);
550 cbMsgInfo.cbMsg.length = length;
551 cbMsgInfo.cbMsg.cbMsgType = SMS_CB_MSG_GSM;
553 dbg("CB Msg LENGTH [%2x]", length);
555 if ((cbMsgInfo.cbMsg.length >0) && (SMS_CB_SIZE_MAX >= cbMsgInfo.cbMsg.length)) {
556 unsigned char *byte_pdu = NULL;
558 byte_pdu = (unsigned char *)util_hexStringToBytes(pdu);
560 memcpy(cbMsgInfo.cbMsg.msgData, (char*)byte_pdu, cbMsgInfo.cbMsg.length);
561 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);
564 dbg("Invalid Message Length");
567 dbg("Recieved NULL pdu");
573 dbg(" Return value [%d]",rtn);
576 tcore_at_tok_free(tokens);
582 /*=============================================================
584 ==============================================================*/
585 static void on_response_sms_delete_msg(TcorePending *p, int data_len, const void *data, void *user_data)
587 struct tresp_sms_delete_msg delMsgInfo = {0,};
588 UserRequest *ur = NULL;
589 const TcoreATResponse *atResp = data;
592 int index = (int) user_data;
594 dbg(" Func Entrance");
596 ur = tcore_pending_ref_user_request(p);
597 if (atResp->success) {
599 delMsgInfo.index = index;
600 delMsgInfo.result = SMS_SENDSMS_SUCCESS;
603 delMsgInfo.index = index;
604 delMsgInfo.result = SMS_DEVICE_FAILURE;
607 rtn = tcore_user_request_send_response(ur, TRESP_SMS_DELETE_MSG, sizeof(struct tresp_sms_delete_msg), &delMsgInfo);
612 static void on_response_sms_save_msg(TcorePending *p, int data_len, const void *data, void *user_data)
614 struct tresp_sms_save_msg saveMsgInfo = {0,};
615 UserRequest *ur = NULL;
616 const TcoreATResponse *atResp = data;
617 GSList *tokens = NULL;
622 ur = tcore_pending_ref_user_request(p);
623 if (atResp->success) {
626 line = (char *)atResp->lines->data;
627 tokens = tcore_at_tok_new(line);
628 pResp = g_slist_nth_data(tokens, 0);
631 saveMsgInfo.index = (atoi(pResp) - 1); /* IMC index starts from 1 */
632 saveMsgInfo.result = SMS_SENDSMS_SUCCESS;
635 saveMsgInfo.index = -1;
636 saveMsgInfo.result = SMS_DEVICE_FAILURE;
638 tcore_at_tok_free(tokens);
642 saveMsgInfo.index = -1;
643 saveMsgInfo.result = SMS_DEVICE_FAILURE;
646 rtn = tcore_user_request_send_response(ur, TRESP_SMS_SAVE_MSG, sizeof(struct tresp_sms_save_msg), &saveMsgInfo);
647 dbg("Return value [%d]", rtn);
651 static void on_response_send_umts_msg(TcorePending *pending, int data_len, const void *data, void *user_data)
653 const TcoreATResponse *at_response = data;
654 struct tresp_sms_send_umts_msg resp_umts;
655 UserRequest *user_req = NULL;
658 GSList *tokens = NULL;
659 char *gslist_line = NULL, *line_token = NULL;
663 user_req = tcore_pending_ref_user_request(pending);
665 if (NULL == user_req) {
666 err("No user request");
672 memset(&resp_umts, 0x00, sizeof(resp_umts));
673 resp_umts.result = SMS_DEVICE_FAILURE;
675 if (at_response->success > 0) { /* SUCCESS */
677 if (at_response->lines) { // lines present in at_response
678 gslist_line = (char *)at_response->lines->data;
679 dbg("gslist_line: [%s]", gslist_line);
681 tokens = tcore_at_tok_new(gslist_line); //extract tokens
683 line_token = g_slist_nth_data(tokens, 0);
684 if (line_token != NULL) {
685 msg_ref = atoi(line_token);
686 dbg("Message Reference: [%d]", msg_ref);
688 resp_umts.result = SMS_SENDSMS_SUCCESS;
690 dbg("No Message Reference received");
692 tcore_at_tok_free(tokens);
693 } else { // no lines in at_response
700 tcore_user_request_send_response(user_req, TRESP_SMS_SEND_UMTS_MSG, sizeof(resp_umts), &resp_umts);
706 static void on_response_class2_read_msg(TcorePending *pending, int data_len, const void *data, void *user_data)
708 const TcoreATResponse *at_response = data;
710 char *gslist_line = NULL, *line_token = NULL, *hex_pdu = NULL;
711 int pdu_len = 0, rtn = 0;
712 unsigned char *bytePDU = NULL;
713 struct tnoti_sms_umts_msg gsmMsgInfo;
717 dbg("lines: [%p]", at_response->lines);
718 g_slist_foreach(at_response->lines, print_glib_list_elem, NULL); //for debug log
720 if (at_response->success > 0) {
722 if (at_response->lines) {
724 gslist_line = (char *)at_response->lines->data;
726 dbg("gslist_line: [%s]", gslist_line);
728 tokens = tcore_at_tok_new(gslist_line);
729 dbg("Number of tokens: [%d]", g_slist_length(tokens));
730 g_slist_foreach(tokens, print_glib_list_elem, NULL); //for debug log
732 line_token = g_slist_nth_data(tokens, 2); //Third Token: Length
733 if (line_token != NULL) {
734 pdu_len = atoi(line_token);
735 dbg("Length: [%d]", pdu_len);
739 gslist_line = (char *)at_response->lines->next->data;
741 dbg("gslist_line: [%s]", gslist_line);
743 //free the consumed token
744 tcore_at_tok_free(tokens);
746 tokens = tcore_at_tok_new(gslist_line);
747 dbg("Number of tokens: [%d]", g_slist_length(tokens));
748 g_slist_foreach(tokens, print_glib_list_elem, NULL); //for debug log
750 hex_pdu = g_slist_nth_data(tokens, 0); //Fetch SMS PDU
752 //free the consumed token
753 tcore_at_tok_free(tokens);
761 /* Convert to Bytes */
762 bytePDU = (unsigned char *)util_hexStringToBytes(hex_pdu);
764 sca_length = bytePDU[0];
766 dbg("SCA length = %d", sca_length);
768 gsmMsgInfo.msgInfo.msgLength = pdu_len;
770 if (sca_length == 0) {
771 memcpy(gsmMsgInfo.msgInfo.tpduData, &bytePDU[1], gsmMsgInfo.msgInfo.msgLength);
773 memcpy(gsmMsgInfo.msgInfo.sca, bytePDU, sca_length);
774 memcpy(gsmMsgInfo.msgInfo.tpduData, &bytePDU[sca_length+1], gsmMsgInfo.msgInfo.msgLength);
777 util_hex_dump(" ", strlen(hex_pdu)/2, bytePDU);
778 util_hex_dump(" ", sca_length, gsmMsgInfo.msgInfo.sca);
779 util_hex_dump(" ", gsmMsgInfo.msgInfo.msgLength,gsmMsgInfo.msgInfo.tpduData);
781 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);
789 static void on_response_read_msg(TcorePending *pending, int data_len, const void *data, void *user_data)
791 const TcoreATResponse *at_response = data;
792 struct tresp_sms_read_msg resp_read_msg;
793 UserRequest *user_req = NULL;
796 char *gslist_line = NULL, *line_token = NULL, *byte_pdu = NULL, *hex_pdu = NULL;
798 int msg_status = 0, alpha_id = 0, pdu_len = 0;
799 int index = (int)(uintptr_t)user_data;
802 dbg("index: [%d]", index);
803 g_slist_foreach(at_response->lines, print_glib_list_elem, NULL); //for debug log
805 user_req = tcore_pending_ref_user_request(pending);
806 if (NULL == user_req) {
807 err("No user request");
813 memset(&resp_read_msg, 0x00, sizeof(resp_read_msg));
814 resp_read_msg.result = SMS_PHONE_FAILURE;
816 if (at_response->success > 0) {
818 if (at_response->lines) {
820 gslist_line = (char *)at_response->lines->data;
822 dbg("gslist_line: [%s]", gslist_line);
824 tokens = tcore_at_tok_new(gslist_line);
825 dbg("Number of tokens: [%d]", g_slist_length(tokens));
826 g_slist_foreach(tokens, print_glib_list_elem, NULL); //for debug log
828 line_token = g_slist_nth_data(tokens, 0); //First Token: Message Status
829 if (line_token != NULL) {
830 msg_status = atoi(line_token);
831 dbg("msg_status is %d",msg_status);
832 switch (msg_status) {
834 resp_read_msg.dataInfo.msgStatus = SMS_STATUS_UNREAD;
838 resp_read_msg.dataInfo.msgStatus = SMS_STATUS_READ;
842 resp_read_msg.dataInfo.msgStatus = SMS_STATUS_UNSENT;
846 resp_read_msg.dataInfo.msgStatus = SMS_STATUS_SENT;
849 case AT_ALL: //Fall Through
850 default: //Fall Through
851 resp_read_msg.dataInfo.msgStatus = SMS_STATUS_RESERVED;
856 line_token = g_slist_nth_data(tokens, 1); //Second Token: AlphaID
857 if (line_token != NULL) {
858 alpha_id = atoi(line_token);
859 dbg("AlphaID: [%d]", alpha_id);
862 line_token = g_slist_nth_data(tokens, 2); //Third Token: Length
863 if (line_token != NULL) {
864 pdu_len = atoi(line_token);
865 dbg("Length: [%d]", pdu_len);
869 hex_pdu = (char *) at_response->lines->next->data;
871 dbg("EF-SMS PDU: [%s]", hex_pdu);
873 //free the consumed token
874 tcore_at_tok_free(tokens);
876 if (NULL != hex_pdu) {
877 util_hex_dump(" ", sizeof(hex_pdu), (void *)hex_pdu);
879 byte_pdu = util_hexStringToBytes(hex_pdu);
881 sca_length = (int)byte_pdu[0];
883 resp_read_msg.dataInfo.simIndex = index; //Retrieving index stored as user_data
885 dbg("SCA Length : %d", sca_length);
887 resp_read_msg.dataInfo.smsData.msgLength = pdu_len;
888 dbg("msgLength: [%d]", resp_read_msg.dataInfo.smsData.msgLength);
890 if(0 == sca_length) {
891 if ((resp_read_msg.dataInfo.smsData.msgLength > 0)
892 && (resp_read_msg.dataInfo.smsData.msgLength <= SMS_SMDATA_SIZE_MAX)) {
893 memset(resp_read_msg.dataInfo.smsData.sca, 0, TAPI_SIM_SMSP_ADDRESS_LEN);
894 memcpy(resp_read_msg.dataInfo.smsData.tpduData, &byte_pdu[1], resp_read_msg.dataInfo.smsData.msgLength);
896 resp_read_msg.result = SMS_SUCCESS;
898 dbg("Invalid Message Length");
899 resp_read_msg.result = SMS_INVALID_PARAMETER_FORMAT;
901 } else if (sca_length > SMS_ENCODED_SCA_LEN_MAX) {
902 dbg("Invalid Message Length");
903 resp_read_msg.result = SMS_INVALID_PARAMETER_FORMAT;
905 if ((resp_read_msg.dataInfo.smsData.msgLength > 0)
906 && (resp_read_msg.dataInfo.smsData.msgLength <= SMS_SMDATA_SIZE_MAX)) {
907 memcpy(resp_read_msg.dataInfo.smsData.sca, (char *)byte_pdu, (sca_length+1));
908 memcpy(resp_read_msg.dataInfo.smsData.tpduData, &byte_pdu[sca_length+1], resp_read_msg.dataInfo.smsData.msgLength);
910 util_hex_dump(" ", SMS_SMSP_ADDRESS_LEN, (void *)resp_read_msg.dataInfo.smsData.sca);
911 util_hex_dump(" ", (SMS_SMDATA_SIZE_MAX + 1), (void *)resp_read_msg.dataInfo.smsData.tpduData);
912 util_hex_dump(" ", sizeof(byte_pdu), (void *)byte_pdu);
914 resp_read_msg.result = SMS_SUCCESS;
916 dbg("Invalid Message Length");
917 resp_read_msg.result = SMS_INVALID_PARAMETER_FORMAT;
931 tcore_user_request_send_response(user_req, TRESP_SMS_READ_MSG, sizeof(resp_read_msg), &resp_read_msg);
937 static void on_response_get_msg_indices(TcorePending *pending, int data_len, const void *data, void *user_data)
939 const TcoreATResponse *at_response = data;
940 struct tresp_sms_get_storedMsgCnt resp_stored_msg_cnt;
941 UserRequest *user_req = NULL;
942 struct tresp_sms_get_storedMsgCnt *resp_stored_msg_cnt_prev = NULL;
944 GSList *tokens = NULL;
945 char *gslist_line = NULL, *line_token = NULL;
946 int gslist_line_count = 0, ctr_loop = 0;
950 resp_stored_msg_cnt_prev = (struct tresp_sms_get_storedMsgCnt *)user_data;
951 user_req = tcore_pending_ref_user_request(pending);
953 memset(&resp_stored_msg_cnt, 0x00, sizeof(resp_stored_msg_cnt));
954 resp_stored_msg_cnt.result = SMS_DEVICE_FAILURE;
956 if (at_response->success) {
958 if (at_response->lines) {
959 gslist_line_count = g_slist_length(at_response->lines);
961 if (gslist_line_count > SMS_GSM_SMS_MSG_NUM_MAX)
962 gslist_line_count = SMS_GSM_SMS_MSG_NUM_MAX;
964 dbg("Number of lines: [%d]", gslist_line_count);
965 g_slist_foreach(at_response->lines, print_glib_list_elem, NULL); //for debug log
967 for (ctr_loop = 0; ctr_loop < gslist_line_count; ctr_loop++) {
968 gslist_line = (char *)g_slist_nth_data(at_response->lines, ctr_loop); /* Fetch Line i */
970 dbg("gslist_line [%d] is [%s]", ctr_loop, gslist_line);
972 if (NULL != gslist_line) {
973 tokens = tcore_at_tok_new(gslist_line);
975 g_slist_foreach(tokens, print_glib_list_elem, NULL); //for debug log
977 line_token = g_slist_nth_data(tokens, 0);
978 if (NULL != line_token) {
979 resp_stored_msg_cnt.storedMsgCnt.indexList[ctr_loop] = atoi(line_token);
980 resp_stored_msg_cnt.result = SMS_SENDSMS_SUCCESS;
982 dbg("line_token of gslist_line [%d] is NULL", ctr_loop);
985 tcore_at_tok_free(tokens);
987 dbg("gslist_line [%d] is NULL", ctr_loop);
993 if (resp_stored_msg_cnt_prev->storedMsgCnt.usedCount == 0) { // Check if used count is zero
994 resp_stored_msg_cnt.result = SMS_SENDSMS_SUCCESS;
1001 resp_stored_msg_cnt.storedMsgCnt.totalCount = resp_stored_msg_cnt_prev->storedMsgCnt.totalCount;
1002 resp_stored_msg_cnt.storedMsgCnt.usedCount = resp_stored_msg_cnt_prev->storedMsgCnt.usedCount;
1004 util_sms_free_memory(resp_stored_msg_cnt_prev);
1006 dbg("total: [%d], used: [%d], result: [%d]", resp_stored_msg_cnt.storedMsgCnt.totalCount, resp_stored_msg_cnt.storedMsgCnt.usedCount, resp_stored_msg_cnt.result);
1007 for (ctr_loop = 0; ctr_loop < gslist_line_count; ctr_loop++) {
1008 dbg("index: [%d]", resp_stored_msg_cnt.storedMsgCnt.indexList[ctr_loop]);
1011 tcore_user_request_send_response(user_req, TRESP_SMS_GET_STORED_MSG_COUNT, sizeof(resp_stored_msg_cnt), &resp_stored_msg_cnt);
1017 static void on_response_get_stored_msg_cnt(TcorePending *pending, int data_len, const void *data, void *user_data)
1019 UserRequest *ur = NULL, *ur_dup = NULL;
1020 struct tresp_sms_get_storedMsgCnt *respStoredMsgCnt = NULL;
1021 const TcoreATResponse *atResp = data;
1022 GSList *tokens=NULL;
1023 char *line = NULL , *pResp = NULL , *cmd_str = NULL;
1024 TcoreATRequest *atReq = NULL;
1025 int usedCnt = 0, totalCnt = 0, result = 0;
1027 TcorePending *pending_new = NULL;
1028 CoreObject *o = NULL;
1032 respStoredMsgCnt = malloc(sizeof(struct tresp_sms_get_storedMsgCnt));
1033 result = SMS_DEVICE_FAILURE;
1035 ur = tcore_pending_ref_user_request(pending);
1036 ur_dup = tcore_user_request_ref(ur);
1037 o = tcore_pending_ref_core_object(pending);
1039 if (atResp->success > 0) {
1041 if (NULL != atResp->lines) {
1042 line = (char *)atResp->lines->data;
1043 dbg("line is %s",line);
1045 tokens = tcore_at_tok_new(line);
1046 pResp = g_slist_nth_data(tokens, 0);
1049 usedCnt =atoi(pResp);
1050 dbg("used cnt is %d",usedCnt);
1053 pResp = g_slist_nth_data(tokens, 1);
1055 totalCnt =atoi(pResp);
1056 result = SMS_SENDSMS_SUCCESS;
1058 respStoredMsgCnt->storedMsgCnt.usedCount = usedCnt;
1059 respStoredMsgCnt->storedMsgCnt.totalCount = totalCnt;
1060 respStoredMsgCnt->result = result;
1062 dbg("used %d, total %d, result %d",usedCnt, totalCnt,result);
1064 pending_new = tcore_pending_new(o, 0);
1065 //Get all messages information
1066 cmd_str = g_strdup_printf("AT+CMGL=4");
1067 atReq = tcore_at_request_new((const char *)cmd_str, "+CMGL", TCORE_AT_MULTILINE);
1069 dbg("cmd str is %s",cmd_str);
1071 tcore_pending_set_request_data(pending_new, 0,atReq);
1072 tcore_pending_set_response_callback(pending_new, on_response_get_msg_indices, (void *)respStoredMsgCnt);
1073 tcore_pending_link_user_request(pending_new, ur_dup);
1074 tcore_pending_set_send_callback(pending_new, on_confirmation_sms_message_send, NULL);
1075 tcore_hal_send_request(tcore_object_get_hal(o), pending_new);
1077 //free the consumed token
1078 tcore_at_tok_free(tokens);
1085 //free the consumed token
1087 tcore_at_tok_free(tokens);
1092 err("Response NOK");
1094 respStoredMsgCnt->result = result;
1095 tcore_user_request_send_response(ur, TRESP_SMS_GET_STORED_MSG_COUNT, sizeof(struct tresp_sms_get_storedMsgCnt), &respStoredMsgCnt);
1102 static void on_response_get_sca(TcorePending *pending, int data_len, const void *data, void *user_data)
1104 const TcoreATResponse *at_response = data;
1105 struct tresp_sms_get_sca respGetSca;
1106 UserRequest *user_req = NULL;
1108 GSList *tokens = NULL;
1109 const char *sca_tok_addr;
1110 char *gslist_line = NULL, *sca_addr = NULL, *sca_toa = NULL;
1114 memset(&respGetSca, 0, sizeof(respGetSca));
1115 respGetSca.result = SMS_DEVICE_FAILURE;
1117 user_req = tcore_pending_ref_user_request(pending);
1119 if (at_response->success) {
1121 if (at_response->lines) {
1122 gslist_line = (char *)at_response->lines->data;
1124 tokens = tcore_at_tok_new(gslist_line);
1125 sca_tok_addr = g_slist_nth_data(tokens, 0);
1126 sca_toa = g_slist_nth_data(tokens, 1);
1128 sca_addr = tcore_at_tok_extract(sca_tok_addr);
1129 if ((NULL != sca_addr)
1130 && (NULL != sca_toa)) {
1131 dbg("sca_addr: [%s]. sca_toa: [%s]", sca_addr, sca_toa);
1133 respGetSca.scaAddress.dialNumLen = strlen(sca_addr);
1135 if (145 == atoi(sca_toa)) {
1136 respGetSca.scaAddress.typeOfNum = SIM_TON_INTERNATIONAL;
1138 respGetSca.scaAddress.typeOfNum = SIM_TON_NATIONAL;
1141 respGetSca.scaAddress.numPlanId = 0;
1143 memcpy(respGetSca.scaAddress.diallingNum, sca_addr, strlen(sca_addr));
1145 dbg("len [%d], sca_addr [%s], TON [%d], NPI [%d]", respGetSca.scaAddress.dialNumLen, respGetSca.scaAddress.diallingNum, respGetSca.scaAddress.typeOfNum, respGetSca.scaAddress.numPlanId);
1147 respGetSca.result = SMS_SENDSMS_SUCCESS;
1149 err("sca_addr OR sca_toa NULL");
1155 dbg("Response NOK");
1158 tcore_user_request_send_response(user_req, TRESP_SMS_GET_SCA, sizeof(respGetSca), &respGetSca);
1160 tcore_at_tok_free(tokens);
1167 static void on_response_set_sca(TcorePending *pending, int data_len, const void *data, void *user_data)
1170 Response is expected in this format
1176 //copies the AT response data to resp
1177 const TcoreATResponse *atResp = data;
1178 struct tresp_sms_set_sca respSetSca;
1180 memset(&respSetSca, 0, sizeof(struct tresp_sms_set_sca));
1182 ur = tcore_pending_ref_user_request(pending);
1184 dbg("no user_request");
1188 if (atResp->success > 0) {
1190 respSetSca.result = SMS_SUCCESS;
1192 dbg("RESPONSE NOK");
1193 respSetSca.result = SMS_DEVICE_FAILURE;
1196 tcore_user_request_send_response(ur, TRESP_SMS_SET_SCA, sizeof(struct tresp_sms_set_sca), &respSetSca);
1201 static void on_response_get_cb_config(TcorePending *p, int data_len, const void *data, void *user_data)
1204 struct tresp_sms_get_cb_config respGetCbConfig;
1205 const TcoreATResponse *atResp = data;
1206 GSList *tokens=NULL;
1208 char *pResp = NULL, *line = NULL;
1211 memset(&respGetCbConfig, 0, sizeof(struct tresp_sms_get_cb_config));
1212 respGetCbConfig.result = SMS_DEVICE_FAILURE;
1214 ur = tcore_pending_ref_user_request(p);
1216 dbg("no user_request");
1220 respGetCbConfig.cbConfig.net3gppType = SMS_NETTYPE_3GPP;
1222 if (atResp->success) {
1224 if (atResp->lines) {
1225 line = (char*)atResp->lines->data;
1227 dbg("line is %s",line);
1228 tokens = tcore_at_tok_new(line);
1229 pResp = g_slist_nth_data(tokens, 0);
1232 respGetCbConfig.cbConfig.cbEnabled = mode;
1234 pResp = g_slist_nth_data(tokens, 1);
1236 GSList *cb_tokens = NULL;
1237 char *cb_mid_str = NULL;
1238 int num_cb_tokens = 0;
1239 char *mid_tok = NULL;
1240 char *first_tok = NULL, *second_tok = NULL;
1242 // 0,1,5,320-478,922
1243 cb_mid_str = util_removeQuotes(pResp);
1244 cb_tokens = tcore_at_tok_new((const char *) cb_mid_str);
1248 num_cb_tokens = g_slist_length(cb_tokens);
1249 dbg("num_cb_tokens = %d", num_cb_tokens);
1251 if (num_cb_tokens == 0) {
1252 if (mode == 1) { // Enable all CBs
1253 respGetCbConfig.cbConfig.msgIdRangeCount = 1;
1254 respGetCbConfig.cbConfig.msgIDs[0].net3gpp.fromMsgId = 0x0000;
1255 respGetCbConfig.cbConfig.msgIDs[0].net3gpp.toMsgId = SMS_GSM_SMS_CBMI_LIST_SIZE_MAX + 1;
1256 respGetCbConfig.cbConfig.msgIDs[0].net3gpp.selected = TRUE;
1257 respGetCbConfig.result = SMS_SENDSMS_SUCCESS;
1258 } else { // all CBs disabled
1259 respGetCbConfig.cbConfig.msgIdRangeCount = 0;
1260 respGetCbConfig.cbConfig.msgIDs[0].net3gpp.selected = FALSE;
1261 respGetCbConfig.result = SMS_SENDSMS_SUCCESS;
1264 respGetCbConfig.cbConfig.msgIdRangeCount = 0;
1265 respGetCbConfig.cbConfig.msgIDs[0].net3gpp.selected = FALSE;
1266 respGetCbConfig.result = SMS_SENDSMS_SUCCESS;
1269 for (i = 0; i < num_cb_tokens; i++) {
1270 respGetCbConfig.cbConfig.msgIDs[i].net3gpp.selected = TRUE;
1271 respGetCbConfig.cbConfig.msgIdRangeCount++;
1273 mid_tok = tcore_at_tok_nth(cb_tokens, i);
1274 first_tok = strtok(mid_tok, delim);
1275 second_tok = strtok(NULL, delim);
1277 if ((first_tok != NULL) && (second_tok != NULL)) { // mids in range (320-478)
1278 dbg("inside if mid_range");
1279 respGetCbConfig.cbConfig.msgIDs[i].net3gpp.fromMsgId = atoi(first_tok);
1280 respGetCbConfig.cbConfig.msgIDs[i].net3gpp.toMsgId = atoi(second_tok);
1281 } // single mid value (0,1,5, 922)
1283 respGetCbConfig.cbConfig.msgIDs[i].net3gpp.fromMsgId = atoi(mid_tok);
1284 respGetCbConfig.cbConfig.msgIDs[i].net3gpp.toMsgId = atoi(mid_tok);
1290 respGetCbConfig.cbConfig.msgIdRangeCount = 1;
1291 respGetCbConfig.cbConfig.msgIDs[0].net3gpp.fromMsgId = 0x0000;
1292 respGetCbConfig.cbConfig.msgIDs[0].net3gpp.toMsgId = SMS_GSM_SMS_CBMI_LIST_SIZE_MAX + 1;
1293 respGetCbConfig.cbConfig.msgIDs[0].net3gpp.selected = TRUE;
1294 respGetCbConfig.result = SMS_SENDSMS_SUCCESS;
1296 respGetCbConfig.cbConfig.msgIdRangeCount = 0;
1297 respGetCbConfig.cbConfig.msgIDs[0].net3gpp.selected = FALSE;
1298 respGetCbConfig.result = SMS_SENDSMS_SUCCESS;
1302 dbg("line is NULL");
1305 dbg("atresp->lines is NULL");
1308 dbg("RESPONSE NOK");
1311 tcore_user_request_send_response(ur, TRESP_SMS_GET_CB_CONFIG, sizeof(struct tresp_sms_get_cb_config), &respGetCbConfig);
1314 tcore_at_tok_free(tokens);
1319 static void on_response_set_cb_config(TcorePending *pending, int data_len, const void *data, void *user_data)
1322 Response is expected in this format
1329 const TcoreATResponse *resp = data;
1331 const char *line = NULL;
1332 GSList *tokens=NULL;
1334 struct tresp_sms_set_cb_config respSetCbConfig = {0,};
1336 memset(&respSetCbConfig, 0, sizeof(struct tresp_sms_set_cb_config));
1338 ur = tcore_pending_ref_user_request(pending);
1339 respSetCbConfig.result = SMS_SENDSMS_SUCCESS;
1341 if (resp->success > 0) {
1344 dbg("RESPONSE NOK");
1345 line = (const char*)resp->final_response;
1346 tokens = tcore_at_tok_new(line);
1348 if (g_slist_length(tokens) < 1) {
1349 dbg("err cause not specified or string corrupted");
1350 respSetCbConfig.result = SMS_DEVICE_FAILURE;
1352 response = atoi(g_slist_nth_data(tokens, 0));
1353 /* TODO: CMEE error mapping is required. */
1354 respSetCbConfig.result = SMS_DEVICE_FAILURE;
1358 dbg("no user_request");
1362 tcore_user_request_send_response(ur, TRESP_SMS_SET_CB_CONFIG, sizeof(struct tresp_sms_set_cb_config), &respSetCbConfig);
1365 tcore_at_tok_free(tokens);
1370 static void on_response_set_mem_status(TcorePending *p, int data_len, const void *data, void *user_data)
1373 struct tresp_sms_set_mem_status respSetMemStatus = {0,};
1374 const TcoreATResponse *resp = data;
1376 memset(&respSetMemStatus, 0, sizeof(struct tresp_sms_set_mem_status));
1378 if (resp->success > 0) {
1380 respSetMemStatus.result = SMS_SENDSMS_SUCCESS;
1382 dbg("RESPONSE NOK");
1383 respSetMemStatus.result = SMS_DEVICE_FAILURE;
1386 ur = tcore_pending_ref_user_request(p);
1388 dbg("no user_request");
1392 tcore_user_request_send_response(ur, TRESP_SMS_SET_MEM_STATUS, sizeof(struct tresp_sms_set_mem_status), &respSetMemStatus);
1397 static void on_response_set_msg_status(TcorePending *pending, int data_len, const void *data, void *user_data)
1400 struct tresp_sms_set_msg_status respMsgStatus = {0, };
1401 const TcoreATResponse *atResp = data;
1402 int response = 0, sw1 = 0, sw2 = 0;
1403 const char *line = NULL;
1405 GSList *tokens = NULL;
1409 memset(&respMsgStatus, 0, sizeof(struct tresp_sms_set_msg_status));
1410 respMsgStatus.result = SMS_DEVICE_FAILURE;
1412 ur = tcore_pending_ref_user_request(pending);
1414 if (atResp->success > 0) {
1417 if (atResp->lines) {
1418 line = (const char *) atResp->lines->data;
1419 tokens = tcore_at_tok_new(line);
1420 pResp = g_slist_nth_data(tokens, 0);
1421 if (pResp != NULL) {
1426 pResp = g_slist_nth_data(tokens, 1);
1427 if (pResp != NULL) {
1429 if ((sw1 == AT_SW1_SUCCESS) && (sw2 == 0)) {
1430 respMsgStatus.result = SMS_SENDSMS_SUCCESS;
1435 pResp = g_slist_nth_data(tokens, 3);
1437 if (pResp != NULL) {
1438 response = atoi(pResp);
1439 dbg("response is %s", response);
1445 dbg("RESPONSE NOK");
1448 tcore_user_request_send_response(ur, TRESP_SMS_SET_MSG_STATUS , sizeof(struct tresp_sms_set_msg_status), &respMsgStatus);
1451 tcore_at_tok_free(tokens);
1457 static void on_response_get_sms_params(TcorePending *pending, int data_len, const void *data, void *user_data)
1460 struct tresp_sms_get_params respGetParams ;
1461 const TcoreATResponse *atResp = data;
1462 int sw1 = 0, sw2 = 0;
1463 const char *line = NULL;
1465 GSList *tokens=NULL;
1466 char *hexData = NULL;
1467 char *recordData = NULL;
1470 memset(&respGetParams, 0, sizeof(struct tresp_sms_get_params));
1471 respGetParams.result = SMS_DEVICE_FAILURE;
1473 ur = tcore_pending_ref_user_request(pending);
1475 if (atResp->success > 0) {
1478 if (atResp->lines) {
1479 line = (const char *) atResp->lines->data;
1480 tokens = tcore_at_tok_new(line);
1481 pResp = g_slist_nth_data(tokens, 0);
1482 if (pResp != NULL) {
1484 dbg("sw1 is %d", sw1);
1488 pResp = g_slist_nth_data(tokens, 1);
1489 if (pResp != NULL) {
1491 dbg("sw2 is %d", sw2);
1492 if ((sw1 == 0x90 && sw2 == 0x00) || sw1 == 0x91) {
1493 respGetParams.result = SMS_SENDSMS_SUCCESS;
1498 pResp = g_slist_nth_data(tokens, 2);
1499 if (pResp != NULL) {
1500 hexData = util_removeQuotes(pResp);
1502 recordData = util_hexStringToBytes(hexData);
1503 util_hex_dump(" ", strlen(hexData) / 2, recordData);
1505 respGetParams.paramsInfo.recordLen = strlen(hexData) / 2;
1507 util_sms_decode_smsParameters((unsigned char *) recordData, strlen(hexData) / 2, &(respGetParams.paramsInfo));
1508 respGetParams.result = SMS_SENDSMS_SUCCESS;
1510 for (i = 0; i < (int) respGetParams.paramsInfo.tpSvcCntrAddr.dialNumLen; i++)
1511 dbg("SCAddr = %d [%02x]", i, respGetParams.paramsInfo.tpSvcCntrAddr.diallingNum[i]);
1518 tcore_at_tok_free(tokens);
1521 dbg("RESPONSE NOK");
1524 tcore_user_request_send_response(ur, TRESP_SMS_GET_PARAMS, sizeof(struct tresp_sms_get_params), &respGetParams);
1530 static void on_response_set_sms_params(TcorePending *pending, int data_len, const void *data, void *user_data)
1533 struct tresp_sms_set_params respSetParams = {0, };
1534 const TcoreATResponse *atResp = data;
1535 int sw1 =0 , sw2 = 0;
1536 const char *line = NULL;
1538 GSList *tokens=NULL;
1541 memset(&respSetParams, 0, sizeof(struct tresp_sms_set_params));
1542 ur = tcore_pending_ref_user_request(pending);
1544 respSetParams.result = SMS_DEVICE_FAILURE;
1546 if (atResp->success > 0) {
1549 if (atResp->lines) {
1550 line = (const char *) atResp->lines->data;
1551 tokens = tcore_at_tok_new(line);
1552 pResp = g_slist_nth_data(tokens, 0);
1553 if (pResp != NULL) {
1559 pResp = g_slist_nth_data(tokens, 1);
1560 if (pResp != NULL) {
1562 if (((sw1 == AT_SW1_SUCCESS) && (sw2 == AT_SW2_SUCCESS)) || (sw1 == 0x91)) {
1563 respSetParams.result = SMS_SENDSMS_SUCCESS;
1572 dbg("RESPONSE NOK");
1575 tcore_user_request_send_response(ur, TRESP_SMS_SET_PARAMS , sizeof(struct tresp_sms_set_params), &respSetParams);
1578 tcore_at_tok_free(tokens);
1584 static void on_response_get_paramcnt(TcorePending *p, int data_len, const void *data, void *user_data)
1586 UserRequest *ur = NULL;
1587 struct tresp_sms_get_paramcnt respGetParamCnt = {0, };
1588 const TcoreATResponse *atResp = data;
1589 char *line = NULL , *pResp = NULL;
1590 int sw1 = 0 , sw2 = 0, *smsp_record_len = NULL;
1592 GSList *tokens=NULL;
1593 CoreObject *co_sim = NULL; //need this to get the sim type GSM/USIM
1594 TcorePlugin *plugin = NULL;
1598 ur = tcore_pending_ref_user_request(p);
1599 respGetParamCnt.result = SMS_DEVICE_FAILURE;
1601 if (atResp->success > 0) {
1604 if (atResp->lines) {
1605 line = (char *) atResp->lines->data;
1607 dbg("line is %s", line);
1609 tokens = tcore_at_tok_new(line);
1610 pResp = g_slist_nth_data(tokens, 0);
1611 if (pResp != NULL) {
1616 pResp = g_slist_nth_data(tokens, 1);
1617 if (pResp != NULL) {
1619 if ((sw1 == 144) && (sw2 == 0)) {
1620 respGetParamCnt.result = SMS_SENDSMS_SUCCESS;
1625 pResp = g_slist_nth_data(tokens, 2);
1626 if (pResp != NULL) {
1627 char *hexData = NULL;
1628 char *recordData = NULL;
1629 hexData = util_removeQuotes(pResp);
1631 /*1. SIM access success case*/
1632 if ((sw1 == 0x90 && sw2 == 0x00) || sw1 == 0x91) {
1633 unsigned char tag_len = 0; /* 1 or 2 bytes ??? */
1635 char num_of_records = 0;
1636 unsigned char file_id_len = 0;
1637 unsigned short file_id = 0;
1638 unsigned short file_size = 0;
1639 unsigned short file_type = 0;
1640 unsigned short arr_file_id = 0;
1641 int arr_file_id_rec_num = 0;
1643 /* handling only last 3 bits */
1644 unsigned char file_type_tag = 0x07;
1645 unsigned char *ptr_data;
1647 recordData = util_hexStringToBytes(hexData);
1648 util_hex_dump(" ", strlen(hexData)/2, recordData);
1650 ptr_data = (unsigned char *)recordData;
1652 co_sim = tcore_plugin_ref_core_object(tcore_pending_ref_plugin(p), CORE_OBJECT_TYPE_SIM);
1653 sim_type = tcore_sim_get_type(co_sim);
1654 dbg("sim type is %d",sim_type);
1656 if (sim_type == SIM_TYPE_USIM) {
1658 ETSI TS 102 221 v7.9.0
1660 '62' FCP template tag
1661 - Response for an EF
1662 '82' M File Descriptor
1663 '83' M File Identifier
1664 'A5' O Proprietary information
1665 '8A' M Life Cycle Status Integer
1666 '8B', '8C' or 'AB' C1 Security attributes
1668 '81' O Total file size
1669 '88' O Short File Identifier (SFI)
1672 /* rsim.res_len has complete data length received */
1674 /* FCP template tag - File Control Parameters tag*/
1675 if (*ptr_data == 0x62) {
1676 /* parse complete FCP tag*/
1677 /* increment to next byte */
1679 tag_len = *ptr_data++;
1680 /* FCP file descriptor - file type, accessibility, DF, ADF etc*/
1681 if (*ptr_data == 0x82) {
1682 /* increment to next byte */
1686 /* unsigned char file_desc_len = *ptr_data++;*/
1687 /* dbg("file descriptor length: [%d]", file_desc_len);*/
1688 /* TBD: currently capture only file type : ignore sharable, non sharable, working, internal etc*/
1689 /* consider only last 3 bits*/
1690 file_type_tag = file_type_tag & (*ptr_data);
1692 switch (file_type_tag) {
1693 /* increment to next byte */
1697 dbg("Getting FileType: [Transparent file type]");
1698 /* increment to next byte */
1700 file_type = 0x01; //SIM_FTYPE_TRANSPARENT
1701 /* data coding byte - value 21 */
1706 dbg("Getting FileType: [Linear fixed file type]");
1707 /* increment to next byte */
1709 /* data coding byte - value 21 */
1712 memcpy(&record_len, ptr_data, 2);
1714 record_len = SMS_SWAPBYTES16(record_len);
1715 ptr_data = ptr_data + 2;
1716 num_of_records = *ptr_data++;
1717 /* Data lossy conversation from enum (int) to unsigned char */
1718 file_type = 0x02; // SIM_FTYPE_LINEAR_FIXED
1722 dbg(" Cyclic fixed file type");
1723 /* increment to next byte */
1725 /* data coding byte - value 21 */
1728 memcpy(&record_len, ptr_data, 2);
1730 record_len = SMS_SWAPBYTES16(record_len);
1731 ptr_data = ptr_data + 2;
1732 num_of_records = *ptr_data++;
1733 file_type = 0x04; //SIM_FTYPE_CYCLIC
1737 dbg("not handled file type [0x%x]", *ptr_data);
1741 dbg("INVALID FCP received - DEbug!");
1744 tcore_at_tok_free(tokens);
1748 /*File identifier - file id?? */ // 0x84,0x85,0x86 etc are currently ignored and not handled
1749 if (*ptr_data == 0x83) {
1750 /* increment to next byte */
1752 file_id_len = *ptr_data++;
1753 memcpy(&file_id, ptr_data, file_id_len);
1755 file_id = SMS_SWAPBYTES16(file_id);
1756 ptr_data = ptr_data + 2;
1757 dbg("Getting FileID=[0x%x]", file_id);
1759 dbg("INVALID FCP received - DEbug!");
1762 tcore_at_tok_free(tokens);
1766 /* proprietary information */
1767 if (*ptr_data == 0xA5) {
1768 unsigned short prop_len;
1769 /* increment to next byte */
1772 prop_len = *ptr_data;
1774 ptr_data = ptr_data + prop_len + 1;
1776 dbg("INVALID FCP received - DEbug!");
1779 /* life cycle status integer [8A][length:0x01][status]*/
1782 00000000 : No information given
1783 00000001 : creation state
1784 00000011 : initialization state
1785 000001-1 : operation state -activated
1786 000001-0 : operation state -deactivated
1787 000011-- : Termination state
1788 b8~b5 !=0, b4~b1=X : Proprietary
1789 Any other value : RFU
1791 if (*ptr_data == 0x8A) {
1792 /* increment to next byte */
1794 /* length - value 1 */
1797 switch (*ptr_data) {
1800 dbg("[RX] Operation State: DEACTIVATED");
1806 dbg("[RX] Operation State: ACTIVATED");
1811 dbg("[RX] DEBUG! LIFE CYCLE STATUS: [0x%x]",*ptr_data);
1817 /* related to security attributes : currently not handled*/
1818 if (*ptr_data == 0x86 || *ptr_data == 0x8B || *ptr_data == 0x8C || *ptr_data == 0xAB) {
1819 /* increment to next byte */
1821 /* if tag length is 3 */
1822 if (*ptr_data == 0x03) {
1823 /* increment to next byte */
1826 memcpy(&arr_file_id, ptr_data, 2);
1828 arr_file_id = SMS_SWAPBYTES16(arr_file_id);
1829 ptr_data = ptr_data + 2;
1830 arr_file_id_rec_num = *ptr_data++;
1832 /* if tag length is not 3 */
1833 /* ignoring bytes */
1834 // ptr_data = ptr_data + 4;
1835 dbg("Useless security attributes, so jump to next tag");
1836 ptr_data = ptr_data + (*ptr_data + 1);
1839 dbg("INVALID FCP received[0x%x] - DEbug!", *ptr_data);
1842 tcore_at_tok_free(tokens);
1846 dbg("Current ptr_data value is [%x]", *ptr_data);
1848 /* file size excluding structural info*/
1849 if (*ptr_data == 0x80) {
1850 /* for EF file size is body of file and for Linear or cyclic it is
1851 * number of recXsizeof(one record)
1853 /* increment to next byte */
1855 /* length is 1 byte - value is 2 bytes or more */
1857 memcpy(&file_size, ptr_data, 2);
1859 file_size = SMS_SWAPBYTES16(file_size);
1860 ptr_data = ptr_data + 2;
1862 dbg("INVALID FCP received - DEbug!");
1865 tcore_at_tok_free(tokens);
1869 /* total file size including structural info*/
1870 if (*ptr_data == 0x81) {
1872 /* increment to next byte */
1877 ptr_data = ptr_data + 3;
1879 dbg("INVALID FCP received - DEbug!");
1880 /* 0x81 is optional tag?? check out! so do not return -1 from here! */
1883 /*short file identifier ignored*/
1884 if (*ptr_data == 0x88) {
1885 dbg("0x88: Do Nothing");
1889 dbg("INVALID FCP received - DEbug!");
1892 tcore_at_tok_free(tokens);
1895 } else if (sim_type == SIM_TYPE_GSM) {
1896 unsigned char gsm_specific_file_data_len = 0;
1897 /* ignore RFU byte1 and byte2 */
1901 //file_size = p_info->response_len;
1902 memcpy(&file_size, ptr_data, 2);
1904 file_size = SMS_SWAPBYTES16(file_size);
1905 /* parsed file size */
1906 ptr_data = ptr_data + 2;
1908 memcpy(&file_id, ptr_data, 2);
1909 file_id = SMS_SWAPBYTES16(file_id);
1910 dbg(" FILE id --> [%x]", file_id);
1911 ptr_data = ptr_data + 2;
1912 /* save file type - transparent, linear fixed or cyclic */
1913 file_type_tag = (*(ptr_data + 7));
1915 switch (*ptr_data) {
1918 dbg(" RFU file type- not handled - Debug!");
1923 dbg(" MF file type - not handled - Debug!");
1928 dbg(" DF file type - not handled - Debug!");
1933 dbg(" EF file type [%d] ", file_type_tag);
1934 /* increment to next byte */
1937 if (file_type_tag == 0x00 || file_type_tag == 0x01) {
1938 /* increament to next byte as this byte is RFU */
1941 (file_type_tag == 0x00) ? 0x01 : 0x02; // SIM_FTYPE_TRANSPARENT:SIM_FTYPE_LINEAR_FIXED;
1943 /* increment to next byte */
1945 /* For a cyclic EF all bits except bit 7 are RFU; b7=1 indicates that */
1946 /* the INCREASE command is allowed on the selected cyclic file. */
1947 file_type = 0x04; // SIM_FTYPE_CYCLIC;
1949 /* bytes 9 to 11 give SIM file access conditions */
1951 /* byte 10 has one nibble that is RF U and another for INCREASE which is not used currently */
1953 /* byte 11 is invalidate and rehabilate nibbles */
1955 /* byte 12 - file status */
1957 /* byte 13 - GSM specific data */
1958 gsm_specific_file_data_len = *ptr_data;
1960 /* byte 14 - structure of EF - transparent or linear or cyclic , already saved above */
1962 /* byte 15 - length of record for linear and cyclic , for transparent it is set to 0x00. */
1963 record_len = *ptr_data;
1964 dbg("record length[%d], file size[%d]", record_len, file_size);
1966 if (record_len != 0)
1967 num_of_records = (file_size / record_len);
1969 dbg("Number of records [%d]", num_of_records);
1973 dbg(" not handled file type");
1977 dbg(" Card Type - UNKNOWN [%d]", sim_type);
1980 dbg("EF[0x%x] size[%ld] Type[0x%x] NumOfRecords[%ld] RecordLen[%ld]", file_id, file_size, file_type, num_of_records, record_len);
1982 respGetParamCnt.recordCount = num_of_records;
1983 respGetParamCnt.result = SMS_SUCCESS;
1985 //TO Store smsp record length in the property
1986 plugin = tcore_pending_ref_plugin(p);
1987 smsp_record_len = tcore_plugin_ref_property(plugin, "SMSPRECORDLEN");
1988 memcpy(smsp_record_len, &record_len, sizeof(int));
1993 /*2. SIM access fail case*/
1994 dbg("SIM access fail");
1995 respGetParamCnt.result = SMS_UNKNOWN;
1998 dbg("presp is NULL");
2001 dbg("line is blank");
2004 dbg("RESPONSE NOK");
2007 tcore_user_request_send_response(ur, TRESP_SMS_GET_PARAMCNT, sizeof(struct tresp_sms_get_paramcnt), &respGetParamCnt);
2010 tcore_at_tok_free(tokens);
2016 static void _response_get_efsms_data(TcorePending *p, int data_len, const void *data, void *user_data)
2018 UserRequest *ur = NULL;
2019 UserRequest *dup_ur = NULL;
2020 struct tresp_sms_set_msg_status resp_msg_status = {0,};
2021 const struct treq_sms_set_msg_status *req_msg_status = NULL ;
2023 const TcoreATResponse *resp = data;
2024 char *encoded_data = NULL;
2025 char msg_status = 0;
2027 GSList *tokens=NULL;
2028 const char *line = NULL;
2032 TcoreHal *hal = NULL;
2033 TcoreATRequest *atreq = NULL;
2034 TcorePending *pending = NULL;
2035 gchar *cmd_str = NULL;
2037 ur = tcore_pending_ref_user_request(p);
2039 req_msg_status = tcore_user_request_ref_data(ur, NULL);
2041 resp_msg_status.result = SMS_DEVICE_FAILURE;
2043 hal = tcore_object_get_hal(tcore_pending_ref_core_object(pending));
2044 dbg("msgStatus: [%x], index [%x]", req_msg_status->msgStatus, req_msg_status->index);
2046 if (resp->success <= 0) {
2053 line = (const char *) resp->lines->data;
2054 tokens = tcore_at_tok_new(line);
2055 if (g_slist_length(tokens) != 3) {
2056 msg("invalid message");
2060 sw1 = atoi(g_slist_nth_data(tokens, 0));
2061 sw2 = atoi(g_slist_nth_data(tokens, 1));
2062 pResp = g_slist_nth_data(tokens, 2);
2064 if ((sw1 == 0x90 && sw2 == 0x00) || sw1 == 0x91) {
2065 switch (req_msg_status->msgStatus) {
2066 case SMS_STATUS_READ:
2070 case SMS_STATUS_UNREAD:
2074 case SMS_STATUS_UNSENT:
2078 case SMS_STATUS_SENT:
2082 case SMS_STATUS_DELIVERED:
2086 case SMS_STATUS_DELIVERY_UNCONFIRMED:
2090 case SMS_STATUS_MESSAGE_REPLACED:
2091 case SMS_STATUS_RESERVED:
2097 encoded_data = util_removeQuotes(pResp);
2099 //overwrite Status byte information
2100 util_byte_to_hex((const char *)&msg_status, (char *)encoded_data, 1);
2102 //Update EF-SMS with just status byte overwritten, rest 175 bytes are same as received in read information
2103 cmd_str = g_strdup_printf("AT+CRSM=220,28476,%d, 4, %d, \"%s\"", (req_msg_status->index+1), PDU_LEN_MAX, encoded_data);
2104 atreq = tcore_at_request_new((const char *)cmd_str, "+CRSM", TCORE_AT_SINGLELINE);
2105 pending = tcore_pending_new(tcore_pending_ref_core_object(pending), 0);
2106 if (NULL == cmd_str || NULL == atreq || NULL == pending) {
2107 err("Out of memory. Unable to proceed");
2108 dbg("cmd_str: [%p], atreq: [%p], pending: [%p]", cmd_str, atreq, pending);
2110 //free memory we own
2112 g_free(encoded_data);
2113 util_sms_free_memory(atreq);
2114 util_sms_free_memory(pending);
2119 util_hex_dump(" ", strlen(cmd_str), (void *)cmd_str);
2121 dup_ur = tcore_user_request_ref(ur);
2123 tcore_pending_set_request_data(pending, 0, atreq);
2124 tcore_pending_set_response_callback(pending, on_response_set_msg_status, NULL);
2125 tcore_pending_link_user_request(pending, dup_ur);
2126 tcore_pending_set_send_callback(pending, on_confirmation_sms_message_send, NULL);
2127 tcore_hal_send_request(hal, pending);
2130 g_free(encoded_data);
2136 tcore_at_tok_free(tokens);
2138 tcore_user_request_send_response(ur, TRESP_SMS_SET_MSG_STATUS , sizeof(struct tresp_sms_set_msg_status), &msg_status);
2145 /*=============================================================
2147 ==============================================================*/
2148 static TReturn send_umts_msg(CoreObject *co_sms, UserRequest *ur)
2150 const struct treq_sms_send_umts_msg *send_msg;
2151 const unsigned char *tpdu_byte_data, *sca_byte_data;
2152 int tpdu_byte_len, pdu_byte_len;
2153 char buf[HEX_PDU_LEN_MAX];
2154 char pdu[PDU_LEN_MAX];
2156 int pdu_hex_len, mms;
2161 send_msg = tcore_user_request_ref_data(ur, NULL);
2163 tpdu_byte_data = send_msg->msgDataPackage.tpduData;
2164 sca_byte_data = send_msg->msgDataPackage.sca;
2167 /* TPDU length is in byte */
2168 tpdu_byte_len = send_msg->msgDataPackage.msgLength;
2170 /* Use same Radio Resource Channel */
2171 mms = send_msg->more;
2173 dbg("TDPU length: [%d]", tpdu_byte_len);
2174 dbg("SCA semi-octet length: [%d]", sca_byte_data[0]);
2176 /* Prepare PDU for hex encoding */
2177 pdu_byte_len = tcore_util_pdu_encode(sca_byte_data, tpdu_byte_data,
2178 tpdu_byte_len, pdu);
2180 pdu_hex_len = (int) tcore_util_encode_hex((unsigned char *) pdu,
2183 dbg("PDU hexadecimal length: [%d]", pdu_hex_len);
2186 cmd_str = g_strdup_printf("AT+CMMS=%d", mms);
2188 ret = tcore_prepare_and_send_at_request(co_sms, cmd_str, NULL,
2189 TCORE_AT_NO_RESULT, NULL, NULL, NULL,
2190 on_confirmation_sms_message_send,
2192 if (ret != TCORE_RETURN_SUCCESS) {
2193 err("Failed to prepare and send AT request");
2200 cmd_str = g_strdup_printf("AT+CMGS=%d\r%s\x1A", tpdu_byte_len, buf);
2202 ret = tcore_prepare_and_send_at_request(co_sms, cmd_str, "+CMGS:",
2203 TCORE_AT_SINGLELINE, ur,
2204 on_response_send_umts_msg, NULL,
2205 on_confirmation_sms_message_send, NULL);
2206 if (ret != TCORE_RETURN_SUCCESS)
2207 err("Failed to prepare and send AT request");
2217 static TReturn read_msg(CoreObject *obj, UserRequest *ur)
2219 gchar *cmd_str = NULL;
2220 TcoreHal *hal = NULL;
2221 TcoreATRequest *atreq = NULL;
2222 TcorePending *pending = NULL;
2223 const struct treq_sms_read_msg *readMsg = NULL;
2227 readMsg = tcore_user_request_ref_data(ur, NULL);
2228 hal = tcore_object_get_hal(obj);
2229 if (NULL == readMsg || NULL == hal) {
2230 err("NULL input. Unable to proceed");
2231 dbg("readMsg: [%p], hal: [%p]", readMsg, hal);
2234 return TCORE_RETURN_EINVAL;
2237 if(FALSE == tcore_hal_get_power_state(hal)){
2238 dbg("cp not ready/n");
2239 return TCORE_RETURN_ENOSYS;
2241 dbg("index: [%d]", readMsg->index);
2243 cmd_str = g_strdup_printf("AT+CMGR=%d", readMsg->index); //IMC index is one ahead of TAPI
2244 atreq = tcore_at_request_new((const char *)cmd_str, "+CMGR", TCORE_AT_PDU);
2245 pending = tcore_pending_new(obj, 0);
2247 if (NULL == cmd_str || NULL == atreq || NULL == pending) {
2248 err("Out of memory. Unable to proceed");
2249 dbg("cmd_str: [%p], atreq: [%p], pending: [%p]", cmd_str, atreq, pending);
2251 //free memory we own
2253 util_sms_free_memory(atreq);
2254 util_sms_free_memory(pending);
2257 return TCORE_RETURN_ENOMEM;
2260 util_hex_dump(" ", strlen(cmd_str), (void *)cmd_str);
2262 tcore_pending_set_request_data(pending, 0, atreq);
2263 tcore_pending_set_response_callback(pending, on_response_read_msg, (void *)(uintptr_t)(readMsg->index)); //storing index as user data for response
2264 tcore_pending_link_user_request(pending, ur);
2265 tcore_pending_set_send_callback(pending, on_confirmation_sms_message_send, NULL);
2266 tcore_hal_send_request(hal, pending);
2271 return TCORE_RETURN_SUCCESS;
2274 static TReturn save_msg(CoreObject *obj, UserRequest *ur)
2276 gchar *cmd_str = NULL;
2277 TcoreHal *hal = NULL;
2278 TcoreATRequest *atreq = NULL;
2279 TcorePending *pending = NULL;
2280 const struct treq_sms_save_msg *saveMsg = NULL;
2281 int ScLength = 0, pdu_len = 0, stat = 0;
2282 char buf[2*(SMS_SMSP_ADDRESS_LEN+SMS_SMDATA_SIZE_MAX)+1] = {0};
2283 char *hex_pdu = NULL;
2287 saveMsg = tcore_user_request_ref_data(ur, NULL);
2288 hal = tcore_object_get_hal(obj);
2289 if (NULL == saveMsg || NULL == hal) {
2290 err("NULL input. Unable to proceed");
2291 dbg("saveMsg: [%p], hal: [%p]", saveMsg, hal);
2294 return TCORE_RETURN_EINVAL;
2296 if(FALSE == tcore_hal_get_power_state(hal)){
2297 dbg("cp not ready/n");
2298 return TCORE_RETURN_ENOSYS;
2301 dbg("msgStatus: %x, msgLength: [%d]", saveMsg->msgStatus, saveMsg->msgDataPackage.msgLength);
2302 util_hex_dump(" ", (SMS_SMDATA_SIZE_MAX+1), (void *)saveMsg->msgDataPackage.tpduData);
2303 util_hex_dump(" ", SMS_SMSP_ADDRESS_LEN, (void *)saveMsg->msgDataPackage.sca);
2305 switch (saveMsg->msgStatus) {
2306 case SMS_STATUS_READ:
2310 case SMS_STATUS_UNREAD:
2311 stat = AT_REC_UNREAD;
2314 case SMS_STATUS_SENT:
2318 case SMS_STATUS_UNSENT:
2319 stat = AT_STO_UNSENT;
2323 err("Invalid msgStatus");
2325 return TCORE_RETURN_EINVAL;
2328 if ((saveMsg->msgDataPackage.msgLength > 0)
2329 && (saveMsg->msgDataPackage.msgLength <= SMS_SMDATA_SIZE_MAX)) {
2330 ScLength = (int)saveMsg->msgDataPackage.sca[0];
2333 dbg("ScLength = %d", ScLength);
2338 memcpy(&buf[1], saveMsg->msgDataPackage.sca, ScLength);
2341 memcpy(&buf[ScLength+1], saveMsg->msgDataPackage.tpduData, saveMsg->msgDataPackage.msgLength);
2343 pdu_len= saveMsg->msgDataPackage.msgLength + ScLength + 1;
2344 dbg("pdu_len: [%d]", pdu_len);
2346 hex_pdu = malloc(pdu_len * 2 + 1);
2347 util_hex_dump(" ", sizeof(buf), (void *)buf);
2349 memset (hex_pdu, 0x00, pdu_len * 2 + 1);
2351 util_byte_to_hex((const char *)buf, (char *)hex_pdu, pdu_len);
2353 //AT+CMGW=<length>[,<stat>]<CR>PDU is given<ctrl-Z/ESC>
2354 cmd_str = g_strdup_printf("AT+CMGW=%d,%d%s%s\x1A", saveMsg->msgDataPackage.msgLength, stat, "\r", hex_pdu);
2355 pending = tcore_pending_new(obj, 0);
2356 atreq = tcore_at_request_new((const char *)cmd_str, "+CMGW", TCORE_AT_SINGLELINE);
2358 if(NULL == cmd_str || NULL == atreq || NULL == pending) {
2359 err("Out of memory. Unable to proceed");
2360 dbg("cmd_str: [%p], atreq: [%p], pending: [%p]", cmd_str, atreq, pending);
2362 //free memory we own
2364 util_sms_free_memory(atreq);
2365 util_sms_free_memory(pending);
2366 util_sms_free_memory(hex_pdu);
2369 return TCORE_RETURN_ENOMEM;
2372 util_hex_dump(" ", strlen(cmd_str), (void *)cmd_str);
2374 tcore_pending_set_request_data(pending, 0, atreq);
2375 tcore_pending_set_response_callback(pending, on_response_sms_save_msg, NULL);
2376 tcore_pending_link_user_request(pending, ur);
2377 tcore_pending_set_send_callback(pending, on_confirmation_sms_message_send, NULL);
2378 tcore_hal_send_request(hal, pending);
2384 return TCORE_RETURN_SUCCESS;
2387 err("Invalid Data len");
2389 return TCORE_RETURN_SMS_INVALID_DATA_LEN;
2392 static TReturn delete_msg(CoreObject *obj, UserRequest *ur)
2394 gchar *cmd_str = NULL;
2395 TcoreHal *hal = NULL;
2396 TcoreATRequest *atreq = NULL;
2397 TcorePending *pending = NULL;
2398 const struct treq_sms_delete_msg *delete_msg = NULL;
2402 delete_msg = tcore_user_request_ref_data(ur, NULL);
2403 hal = tcore_object_get_hal(obj);
2404 if (NULL == delete_msg || NULL == hal) {
2405 err("NULL input. Unable to proceed");
2406 dbg("deleteMsg: [%p], hal: [%p]", delete_msg, hal);
2409 return TCORE_RETURN_EINVAL;
2412 if(FALSE == tcore_hal_get_power_state(hal)){
2413 dbg("cp not ready/n");
2414 return TCORE_RETURN_ENOSYS;
2417 dbg("index: %d", delete_msg->index);
2419 if (delete_msg->index == -1) {
2420 cmd_str = g_strdup_printf("AT+CMGD=0,4"); // Delete All Messages
2422 cmd_str = g_strdup_printf("AT+CMGD=%d,0", delete_msg->index + 1); // Delete specified index
2425 pending = tcore_pending_new(obj, 0);
2426 atreq = tcore_at_request_new((const char *)cmd_str, NULL, TCORE_AT_NO_RESULT);
2427 if (NULL == cmd_str || NULL == atreq || NULL == pending) {
2428 err("Out of memory. Unable to proceed");
2429 dbg("cmd_str: [%p], atreq: [%p], pending: [%p]", cmd_str, atreq, pending);
2431 //free memory we own
2433 util_sms_free_memory(atreq);
2434 util_sms_free_memory(pending);
2437 return TCORE_RETURN_ENOMEM;
2440 util_hex_dump(" ", strlen(cmd_str), (void *)cmd_str);
2442 tcore_pending_set_request_data(pending, 0, atreq);
2443 tcore_pending_set_response_callback(pending, on_response_sms_delete_msg, (void *) (uintptr_t) (delete_msg->index)); // storing index as user data for response
2444 tcore_pending_link_user_request(pending, ur);
2445 tcore_pending_set_send_callback(pending, on_confirmation_sms_message_send, NULL);
2446 tcore_hal_send_request(hal, pending);
2451 return TCORE_RETURN_SUCCESS;
2454 static TReturn get_stored_msg_cnt(CoreObject *obj, UserRequest *ur)
2456 gchar *cmd_str = NULL;
2457 TcoreHal *hal = NULL;
2458 TcoreATRequest *atreq = NULL;
2459 TcorePending *pending = NULL;
2463 hal = tcore_object_get_hal(obj);
2465 err("NULL HAL. Unable to proceed");
2468 return TCORE_RETURN_EINVAL;
2471 if(FALSE == tcore_hal_get_power_state(hal)){
2472 dbg("cp not ready/n");
2473 return TCORE_RETURN_ENOSYS;
2476 cmd_str = g_strdup_printf("AT+CPMS=\"SM\"");
2477 pending = tcore_pending_new(obj, 0);
2478 atreq = tcore_at_request_new((const char *)cmd_str, "+CPMS", TCORE_AT_SINGLELINE);
2480 if (NULL == cmd_str || NULL == atreq || NULL == pending) {
2481 err("Out of memory. Unable to proceed");
2482 dbg("cmd_str: [%p], atreq: [%p], pending: [%p]", cmd_str, atreq, pending);
2484 //free memory we own
2486 util_sms_free_memory(atreq);
2487 util_sms_free_memory(pending);
2490 return TCORE_RETURN_ENOMEM;
2493 util_hex_dump(" ", strlen(cmd_str), (void *)cmd_str);
2495 tcore_pending_set_request_data(pending, 0, atreq);
2496 tcore_pending_set_response_callback(pending, on_response_get_stored_msg_cnt, NULL);
2497 tcore_pending_link_user_request(pending, ur);
2498 tcore_pending_set_send_callback(pending, on_confirmation_sms_message_send, NULL);
2499 tcore_hal_send_request(hal, pending);
2504 return TCORE_RETURN_SUCCESS;
2507 static TReturn get_sca(CoreObject *obj, UserRequest *ur)
2509 gchar * cmd_str = NULL;
2510 TcoreHal *hal = NULL;
2511 TcoreATRequest *atreq = NULL;
2512 TcorePending *pending = NULL;
2516 hal = tcore_object_get_hal(obj);
2518 err("HAL NULL. Unable to proceed");
2521 return TCORE_RETURN_EINVAL;
2523 if(FALSE == tcore_hal_get_power_state(hal)){
2524 dbg("cp not ready/n");
2525 return TCORE_RETURN_ENOSYS;
2528 cmd_str = g_strdup_printf("AT+CSCA?");
2529 pending = tcore_pending_new(obj, 0);
2530 atreq = tcore_at_request_new((const char *)cmd_str, "+CSCA", TCORE_AT_SINGLELINE);
2532 if (NULL == cmd_str || NULL == atreq || NULL == pending) {
2533 err("Out of memory. Unable to proceed");
2534 dbg("cmd_str: [%p], atreq: [%p], pending: [%p]", cmd_str, atreq, pending);
2536 //free memory we own
2538 util_sms_free_memory(atreq);
2539 util_sms_free_memory(pending);
2542 return TCORE_RETURN_ENOMEM;
2545 util_hex_dump(" ", strlen(cmd_str), (void *)cmd_str);
2547 tcore_pending_set_request_data(pending, 0, atreq);
2548 tcore_pending_set_response_callback(pending, on_response_get_sca, NULL);
2549 tcore_pending_link_user_request(pending, ur);
2550 tcore_pending_set_send_callback(pending, on_confirmation_sms_message_send, NULL);
2551 tcore_hal_send_request(hal, pending);
2556 return TCORE_RETURN_SUCCESS;
2559 static TReturn set_sca(CoreObject *obj, UserRequest *ur)
2561 gchar *cmd_str = NULL;
2562 TcoreHal *hal = NULL;
2563 TcoreATRequest *atreq = NULL;
2564 TcorePending *pending = NULL;
2565 const struct treq_sms_set_sca *setSca = NULL;
2570 setSca = tcore_user_request_ref_data(ur, NULL);
2571 hal = tcore_object_get_hal(obj);
2572 if (NULL == setSca || NULL == hal) {
2573 err("NULL input. Unable to proceed");
2574 dbg("setSca: [%p], hal: [%p]", setSca, hal);
2577 return TCORE_RETURN_EINVAL;
2579 if(FALSE == tcore_hal_get_power_state(hal)){
2580 dbg("cp not ready/n");
2581 return TCORE_RETURN_ENOSYS;
2584 dbg("dialNumLen: %u, typeOfNum: %d, numPlanId: %d, ", setSca->scaInfo.dialNumLen, setSca->scaInfo.typeOfNum, setSca->scaInfo.numPlanId);
2586 util_hex_dump(" ", (SMS_SMSP_ADDRESS_LEN+1), (void *)setSca->scaInfo.diallingNum);
2588 addrType = ((setSca->scaInfo.typeOfNum << 4) | setSca->scaInfo.numPlanId) | 0x80;
2590 cmd_str = g_strdup_printf("AT+CSCA=\"%s\",%d", setSca->scaInfo.diallingNum, addrType);
2591 pending = tcore_pending_new(obj, 0);
2592 atreq = tcore_at_request_new((const char *)cmd_str, NULL, TCORE_AT_NO_RESULT);
2594 if (NULL == cmd_str || NULL == atreq || NULL == pending) {
2595 err("Out of memory. Unable to proceed");
2596 dbg("cmd_str: [%p], atreq: [%p], pending: [%p]", cmd_str, atreq, pending);
2598 //free memory we own
2600 util_sms_free_memory(atreq);
2601 util_sms_free_memory(pending);
2604 return TCORE_RETURN_ENOMEM;
2607 util_hex_dump(" ", strlen(cmd_str), (void *)cmd_str);
2609 tcore_pending_set_request_data(pending, 0, atreq);
2610 tcore_pending_set_response_callback(pending, on_response_set_sca, NULL);
2611 tcore_pending_link_user_request(pending, ur);
2612 tcore_pending_set_send_callback(pending, on_confirmation_sms_message_send, NULL);
2613 tcore_hal_send_request(hal, pending);
2618 return TCORE_RETURN_SUCCESS;
2621 static TReturn get_cb_config(CoreObject *obj, UserRequest *ur)
2623 gchar *cmd_str = NULL;
2624 TcoreHal *hal = NULL;
2625 TcoreATRequest *atreq = NULL;
2626 TcorePending *pending = NULL;
2630 hal = tcore_object_get_hal(obj);
2632 err("NULL HAL. Unable to proceed");
2635 return TCORE_RETURN_EINVAL;
2637 if(FALSE == tcore_hal_get_power_state(hal)){
2638 dbg("cp not ready/n");
2639 return TCORE_RETURN_ENOSYS;
2642 cmd_str = g_strdup_printf("AT+CSCB?");
2643 pending = tcore_pending_new(obj, 0);
2644 atreq = tcore_at_request_new((const char *)cmd_str, "+CSCB", TCORE_AT_SINGLELINE);
2645 if (NULL == cmd_str || NULL == atreq || NULL == pending) {
2646 err("Out of memory. Unable to proceed");
2647 dbg("cmd_str: [%p], atreq: [%p], pending: [%p]", cmd_str, atreq, pending);
2649 //free memory we own
2651 util_sms_free_memory(atreq);
2652 util_sms_free_memory(pending);
2655 return TCORE_RETURN_ENOMEM;
2658 util_hex_dump(" ", strlen(cmd_str), (void *)cmd_str);
2660 tcore_pending_set_request_data(pending, 0, atreq);
2661 tcore_pending_set_response_callback(pending, on_response_get_cb_config, NULL);
2662 tcore_pending_set_send_callback(pending, on_confirmation_sms_message_send, NULL);
2663 tcore_pending_link_user_request(pending, ur);
2664 tcore_hal_send_request(hal, pending);
2669 return TCORE_RETURN_SUCCESS;
2672 static TReturn set_cb_config(CoreObject *obj, UserRequest *ur)
2674 gchar *cmd_str = NULL;
2675 gchar *mids_str = NULL;
2676 GString *mids_GString = NULL;
2678 TcoreHal *hal = NULL;
2679 TcoreATRequest *atreq = NULL;
2680 TcorePending *pending = NULL;
2681 const struct treq_sms_set_cb_config *setCbConfig = NULL;
2682 int ctr1= 0, ctr2 =0;
2683 unsigned short appendMsgId = 0;
2687 setCbConfig = tcore_user_request_ref_data(ur, NULL);
2688 hal = tcore_object_get_hal(obj);
2689 if (NULL == setCbConfig || NULL == hal) {
2690 err("NULL input. Unable to proceed");
2691 dbg("setCbConfig: [%p], hal: [%p]", setCbConfig, hal);
2694 return TCORE_RETURN_EINVAL;
2696 if(FALSE == tcore_hal_get_power_state(hal)){
2697 dbg("cp not ready/n");
2698 return TCORE_RETURN_ENOSYS;
2701 dbg("bCBEnabled: %d, msgIdCount: %d", setCbConfig->cbEnabled, setCbConfig->msgIdRangeCount);
2703 if (setCbConfig->cbEnabled == 2) { //Enable all CBS
2704 cmd_str = g_strdup_printf("AT+CSCB=1");
2705 } else if ((setCbConfig->cbEnabled == 1) && (setCbConfig->msgIdRangeCount == 0)) { // Special case: Enable all CBS
2706 cmd_str = g_strdup_printf("AT+CSCB=1");
2707 } else if (setCbConfig->cbEnabled == 0) {//AT+CSCB=0: Disable CBS
2708 cmd_str = g_strdup_printf("AT+CSCB=0");
2710 mids_GString = g_string_new("AT+CSCB=0,\"");
2712 for(ctr1 = 0; ctr1 < setCbConfig->msgIdRangeCount; ctr1++ ) {
2713 if( setCbConfig->msgIDs[ctr1].net3gpp.selected == FALSE )
2716 if( SMS_GSM_SMS_CBMI_LIST_SIZE_MAX <= (setCbConfig->msgIDs[ctr1].net3gpp.toMsgId - setCbConfig->msgIDs[ctr1].net3gpp.fromMsgId) ) {
2717 mids_GString = g_string_new("AT+CSCB=1");
2721 appendMsgId = setCbConfig->msgIDs[ctr1].net3gpp.fromMsgId;
2723 for( ctr2 = 0; (ctr2 <= ((setCbConfig->msgIDs[ctr1].net3gpp.toMsgId) - (setCbConfig->msgIDs[ctr1].net3gpp.fromMsgId))); ctr2++ ) {
2724 dbg( "%x", appendMsgId);
2725 mids_GString = g_string_append(mids_GString, g_strdup_printf("%d", appendMsgId));
2727 if (ctr2 == ((setCbConfig->msgIDs[ctr1].net3gpp.toMsgId) - (setCbConfig->msgIDs[ctr1].net3gpp.fromMsgId))) {
2728 mids_GString = g_string_append(mids_GString, "\""); //Mids string termination
2730 mids_GString = g_string_append(mids_GString, ",");
2736 mids_str = g_string_free(mids_GString, FALSE);
2737 cmd_str = g_strdup_printf("%s", mids_str);
2741 pending = tcore_pending_new(obj, 0);
2742 atreq = tcore_at_request_new((const char *)cmd_str, NULL, TCORE_AT_NO_RESULT);
2743 if(NULL == cmd_str || NULL == atreq || NULL == pending) {
2744 err("Out of memory. Unable to proceed");
2745 dbg("cmd_str: [%p], atreq: [%p], pending: [%p]", cmd_str, atreq, pending);
2747 //free memory we own
2749 util_sms_free_memory(atreq);
2750 util_sms_free_memory(pending);
2753 return TCORE_RETURN_ENOMEM;
2756 util_hex_dump(" ", strlen(cmd_str), (void *)cmd_str);
2758 tcore_pending_set_request_data(pending, 0, atreq);
2759 tcore_pending_set_response_callback(pending, on_response_set_cb_config, NULL);
2760 tcore_pending_link_user_request(pending, ur);
2761 tcore_pending_set_send_callback(pending, on_confirmation_sms_message_send, NULL);
2762 tcore_hal_send_request(hal, pending);
2767 return TCORE_RETURN_SUCCESS;
2770 static TReturn set_mem_status(CoreObject *obj, UserRequest *ur)
2772 gchar *cmd_str = NULL;
2773 TcoreHal *hal = NULL;
2774 TcoreATRequest *atreq = NULL;
2775 TcorePending *pending = NULL;
2776 const struct treq_sms_set_mem_status *setMemStatus = NULL;
2777 int memoryStatus = 0;
2781 setMemStatus = tcore_user_request_ref_data(ur, NULL);
2782 hal = tcore_object_get_hal(obj);
2783 if (NULL == setMemStatus || NULL == hal) {
2784 err("NULL input. Unable to proceed");
2785 dbg("setMemStatus: [%p], hal: [%p]", setMemStatus, hal);
2788 return TCORE_RETURN_EINVAL;
2790 if(FALSE == tcore_hal_get_power_state(hal)){
2791 dbg("cp not ready/n");
2792 return TCORE_RETURN_ENOSYS;
2795 dbg("memory_status: %d", setMemStatus->memory_status);
2797 if(setMemStatus->memory_status < SMS_PDA_MEMORY_STATUS_AVAILABLE
2798 || setMemStatus->memory_status > SMS_PDA_MEMORY_STATUS_FULL) {
2799 err("Invalid memory_status");
2802 return TCORE_RETURN_EINVAL;
2805 switch (setMemStatus->memory_status) {
2806 case SMS_PDA_MEMORY_STATUS_AVAILABLE:
2807 memoryStatus = AT_MEMORY_AVAILABLE;
2810 case SMS_PDA_MEMORY_STATUS_FULL:
2811 memoryStatus = AT_MEMORY_FULL;
2815 err("Invalid memory_status");
2817 return TCORE_RETURN_EINVAL;
2820 cmd_str = g_strdup_printf("AT+XTESM=%d", memoryStatus);
2821 pending = tcore_pending_new(obj, 0);
2822 atreq = tcore_at_request_new((const char *)cmd_str, NULL, TCORE_AT_NO_RESULT);
2824 if (NULL == cmd_str || NULL == atreq || NULL == pending) {
2825 err("Out of memory. Unable to proceed");
2826 dbg("cmd_str: [%p], atreq: [%p], pending: [%p]", cmd_str, atreq, pending);
2828 //free memory we own
2830 util_sms_free_memory(atreq);
2831 util_sms_free_memory(pending);
2834 return TCORE_RETURN_ENOMEM;
2837 util_hex_dump(" ", strlen(cmd_str), (void *)cmd_str);
2839 tcore_pending_set_request_data(pending, 0, atreq);
2840 tcore_pending_set_response_callback(pending, on_response_set_mem_status, NULL);
2841 tcore_pending_link_user_request(pending, ur);
2842 tcore_pending_set_send_callback(pending, on_confirmation_sms_message_send, NULL);
2843 tcore_hal_send_request(hal, pending);
2848 return TCORE_RETURN_SUCCESS;
2851 static TReturn set_delivery_report(CoreObject *obj, UserRequest *ur)
2853 struct tresp_sms_set_delivery_report respSetDeliveryReport = {0,};
2855 respSetDeliveryReport.result = SMS_SUCCESS;
2858 if(FALSE == tcore_hal_get_power_state(tcore_object_get_hal(obj))){
2859 dbg("cp not ready/n");
2860 return TCORE_RETURN_ENOSYS;
2863 dbg("CP takes care of sending SMS ack to network for all classes of SMS. Sending default success.");
2865 tcore_user_request_send_response(ur, TRESP_SMS_SET_DELIVERY_REPORT, sizeof(struct tresp_sms_set_delivery_report), &respSetDeliveryReport);
2868 return TCORE_RETURN_SUCCESS;
2871 static TReturn set_msg_status(CoreObject *obj, UserRequest *ur)
2873 gchar *cmd_str = NULL;
2874 TcoreHal *hal = NULL;
2875 TcoreATRequest *atreq = NULL;
2876 TcorePending *pending = NULL;
2877 const struct treq_sms_set_msg_status *msg_status = NULL;
2880 hal = tcore_object_get_hal(obj);
2881 if(FALSE == tcore_hal_get_power_state(hal)){
2882 dbg("cp not ready/n");
2883 return TCORE_RETURN_ENOSYS;
2885 msg_status = tcore_user_request_ref_data(ur, NULL);
2887 cmd_str = g_strdup_printf("AT+CRSM=178,28476,%d,4,%d", (msg_status->index+1), PDU_LEN_MAX);
2888 atreq = tcore_at_request_new((const char *)cmd_str, "+CRSM", TCORE_AT_SINGLELINE);
2889 pending = tcore_pending_new(obj, 0);
2890 if (NULL == cmd_str || NULL == atreq || NULL == pending) {
2891 err("Out of memory. Unable to proceed");
2892 dbg("cmd_str: [%p], atreq: [%p], pending: [%p]", cmd_str, atreq, pending);
2894 //free memory we own
2896 util_sms_free_memory(atreq);
2897 util_sms_free_memory(pending);
2900 return TCORE_RETURN_ENOMEM;
2903 util_hex_dump(" ", strlen(cmd_str), (void *)cmd_str);
2905 tcore_pending_set_request_data(pending, 0, atreq);
2906 tcore_pending_set_response_callback(pending, _response_get_efsms_data, NULL);
2907 tcore_pending_link_user_request(pending, ur);
2908 tcore_pending_set_send_callback(pending, on_confirmation_sms_message_send, NULL);
2909 tcore_hal_send_request(hal, pending);
2914 return TCORE_RETURN_SUCCESS;
2917 static TReturn get_sms_params(CoreObject *obj, UserRequest *ur)
2919 gchar *cmd_str = NULL;
2920 TcoreHal *hal = NULL;
2921 TcoreATRequest *atreq = NULL;
2922 TcorePending *pending = NULL;
2923 const struct treq_sms_get_params *getSmsParams = NULL;
2924 int record_len = 0 , *smsp_record_len = NULL;
2928 getSmsParams = tcore_user_request_ref_data(ur, NULL);
2929 hal = tcore_object_get_hal(obj);
2930 if (NULL == getSmsParams || NULL == hal) {
2931 err("NULL input. Unable to proceed");
2932 dbg("getSmsParams: [%p], hal: [%p]", getSmsParams, hal);
2935 return TCORE_RETURN_EINVAL;
2937 if(FALSE == tcore_hal_get_power_state(hal)){
2938 dbg("cp not ready/n");
2939 return TCORE_RETURN_ENOSYS;
2942 smsp_record_len = tcore_plugin_ref_property(tcore_object_ref_plugin(obj), "SMSPRECORDLEN");
2943 record_len = *smsp_record_len;
2944 dbg("record len from property %d", record_len);
2946 //AT+CRSM=command>[,<fileid>[,<P1>,<P2>,<P3>[,<data>[,<pathid>]]]]
2947 cmd_str = g_strdup_printf("AT+CRSM=178,28482,%d,4,%d", (getSmsParams->index + 1), record_len);
2949 dbg("cmd_str is %s",cmd_str);
2951 atreq = tcore_at_request_new((const char *)cmd_str, "+CRSM", TCORE_AT_SINGLELINE);
2952 pending = tcore_pending_new(obj, 0);
2953 if (NULL == cmd_str || NULL == atreq || NULL == pending) {
2954 err("Out of memory. Unable to proceed");
2955 dbg("cmd_str: [%p], atreq: [%p], pending: [%p]", cmd_str, atreq, pending);
2957 //free memory we own
2959 util_sms_free_memory(atreq);
2960 util_sms_free_memory(pending);
2963 return TCORE_RETURN_ENOMEM;
2966 util_hex_dump(" ", strlen(cmd_str), (void *)cmd_str);
2968 tcore_pending_set_request_data(pending, 0, atreq);
2969 tcore_pending_set_response_callback(pending, on_response_get_sms_params, NULL);
2970 tcore_pending_link_user_request(pending, ur);
2971 tcore_pending_set_send_callback(pending, on_confirmation_sms_message_send, NULL);
2972 tcore_hal_send_request(hal, pending);
2977 return TCORE_RETURN_SUCCESS;
2980 static TReturn set_sms_params(CoreObject *obj, UserRequest *ur)
2982 gchar *cmd_str = NULL;
2983 char *encoded_data = NULL;
2984 unsigned char *temp_data = NULL;
2985 int SMSPRecordLen = 0;
2986 int *smsp_record_len;
2988 TcoreHal *hal = NULL;
2989 TcoreATRequest *atreq = NULL;
2990 TcorePending *pending = NULL;
2991 const struct treq_sms_set_params *setSmsParams = NULL;
2992 int encoded_data_len = 0;
2996 setSmsParams = tcore_user_request_ref_data(ur, NULL);
2997 hal = tcore_object_get_hal(obj);
2998 if (NULL == setSmsParams || NULL == hal) {
2999 err("NULL input. Unable to proceed");
3000 dbg("setSmsParams: [%p], hal: [%p]", setSmsParams, hal);
3003 if(FALSE == tcore_hal_get_power_state(hal)){
3004 dbg("cp not ready/n");
3005 return TCORE_RETURN_ENOSYS;
3008 //EFsmsp file size is 28 +Y bytes (Y is alpha id size)
3009 smsp_record_len = tcore_plugin_ref_property(tcore_object_ref_plugin(obj), "SMSPRECORDLEN");
3010 SMSPRecordLen = *smsp_record_len;
3011 if (SMSPRecordLen < nDefaultSMSPWithoutAlphaId)
3014 temp_data = calloc(SMSPRecordLen,1);
3015 encoded_data = calloc(SMSPRecordLen*2 + 1,1);
3017 _tcore_util_sms_encode_smsParameters(&(setSmsParams->params), temp_data, SMSPRecordLen);
3019 util_byte_to_hex((const char *)temp_data, (char *)encoded_data,SMSPRecordLen);
3021 encoded_data_len = ((SMSPRecordLen) * 2);
3023 hal = tcore_object_get_hal(obj);
3024 pending = tcore_pending_new(obj, 0);
3026 dbg("alpha id len %d encoded data %s. Encoded data len %d",setSmsParams->params.alphaIdLen,encoded_data, encoded_data_len);
3027 cmd_str = g_strdup_printf("AT+CRSM=220,28482,%d,4,%d,\"%s\"",(setSmsParams->params.recordIndex+1),SMSPRecordLen,encoded_data);
3029 dbg("cmd str is %s",cmd_str);
3030 atreq = tcore_at_request_new(cmd_str, "+CRSM:", TCORE_AT_SINGLELINE);
3032 if (NULL == cmd_str || NULL == atreq || NULL == pending) {
3033 err("Out of memory. Unable to proceed");
3034 dbg("cmd_str: [%p], atreq: [%p], pending: [%p]", cmd_str, atreq, pending);
3036 //free memory we own
3038 util_sms_free_memory(atreq);
3039 util_sms_free_memory(pending);
3041 util_sms_free_memory(temp_data);
3042 util_sms_free_memory(encoded_data);
3045 return TCORE_RETURN_ENOMEM;
3048 util_hex_dump(" ", strlen(cmd_str), (void *)cmd_str);
3050 tcore_pending_set_request_data(pending, 0,atreq);
3051 tcore_pending_set_response_callback(pending, on_response_set_sms_params, NULL);
3052 tcore_pending_link_user_request(pending, ur);
3053 tcore_pending_set_send_callback(pending, on_confirmation_sms_message_send, NULL);
3054 tcore_hal_send_request(hal, pending);
3057 util_sms_free_memory(temp_data);
3058 util_sms_free_memory(encoded_data);
3060 return TCORE_RETURN_SUCCESS;
3063 static TReturn get_paramcnt(CoreObject *obj, UserRequest *ur)
3065 gchar *cmd_str = NULL;
3066 TcoreHal *hal = NULL;
3067 TcoreATRequest *atreq = NULL;
3068 TcorePending *pending = NULL;
3072 hal = tcore_object_get_hal(obj);
3074 err("NULL HAL. Unable to proceed");
3077 return TCORE_RETURN_EINVAL;
3079 if(FALSE == tcore_hal_get_power_state(hal)){
3080 dbg("cp not ready/n");
3081 return TCORE_RETURN_ENOSYS;
3084 //AT+CRSM=command>[,<fileid>[,<P1>,<P2>,<P3>[,<data>[,<pathid>]]]]
3085 cmd_str = g_strdup_printf("AT+CRSM=192,28482");
3086 atreq = tcore_at_request_new((const char *)cmd_str, "+CRSM", TCORE_AT_SINGLELINE);
3087 pending = tcore_pending_new(obj, 0);
3089 if (NULL == cmd_str || NULL == atreq || NULL == pending) {
3090 err("NULL pointer. Unable to proceed");
3091 dbg("cmd_str: [%p], atreq: [%p], pending: [%p]", cmd_str, atreq, pending);
3093 //free memory we own
3095 util_sms_free_memory(atreq);
3096 util_sms_free_memory(pending);
3099 return TCORE_RETURN_FAILURE;
3102 util_hex_dump(" ", strlen(cmd_str), (void *)cmd_str);
3104 tcore_pending_set_request_data(pending, 0, atreq);
3105 tcore_pending_set_response_callback(pending, on_response_get_paramcnt, NULL);
3106 tcore_pending_link_user_request(pending, ur);
3107 tcore_pending_set_send_callback(pending, on_confirmation_sms_message_send, NULL);
3108 tcore_hal_send_request(hal, pending);
3113 return TCORE_RETURN_SUCCESS;
3116 static struct tcore_sms_operations sms_ops = {
3117 .send_umts_msg = send_umts_msg,
3118 .read_msg = read_msg,
3119 .save_msg = save_msg,
3120 .delete_msg = delete_msg,
3121 .get_stored_msg_cnt = get_stored_msg_cnt,
3124 .get_cb_config = get_cb_config,
3125 .set_cb_config = set_cb_config,
3126 .set_mem_status = set_mem_status,
3127 .get_pref_brearer = NULL,
3128 .set_pref_brearer = NULL,
3129 .set_delivery_report = set_delivery_report,
3130 .set_msg_status = set_msg_status,
3131 .get_sms_params = get_sms_params,
3132 .set_sms_params = set_sms_params,
3133 .get_paramcnt = get_paramcnt,
3136 gboolean s_sms_init(TcorePlugin *cp, CoreObject *co_sms)
3138 int *smsp_record_len;
3141 /* Override SMS Operations */
3142 tcore_sms_override_ops(co_sms, &sms_ops);
3144 /* Registering for SMS notifications */
3145 tcore_object_override_callback(co_sms, "+CMTI:", on_event_class2_sms_incom_msg, NULL);
3146 tcore_object_override_callback(co_sms, "\e+CMT:", on_event_sms_incom_msg, NULL);
3148 tcore_object_override_callback(co_sms, "\e+CDS", on_event_sms_incom_msg, NULL);
3149 tcore_object_override_callback(co_sms, "+XSMSMMSTAT", on_event_sms_memory_status, NULL);
3150 tcore_object_override_callback(co_sms, "+CMS", on_event_sms_memory_status, NULL);
3152 tcore_object_override_callback(co_sms, "+CBMI:", on_event_sms_cb_incom_msg, NULL);
3153 tcore_object_override_callback(co_sms, "\e+CBM:", on_event_sms_cb_incom_msg, NULL);
3155 /* Storing SMSP record length */
3156 smsp_record_len = g_new0(int, 1);
3157 tcore_plugin_link_property(cp, "SMSPRECORDLEN", smsp_record_len);
3163 void s_sms_exit(TcorePlugin *cp, CoreObject *co_sms)
3165 int *smsp_record_len;
3167 smsp_record_len = tcore_plugin_ref_property(cp, "SMSPRECORDLEN");
3168 g_free(smsp_record_len);