4 * Copyright (c) 2013 Samsung Electronics Co. Ltd. All rights reserved.
6 * Licensed under the Apache License, Version 2.0 (the "License");
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
10 * http://www.apache.org/licenses/LICENSE-2.0
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
28 #include <core_object.h>
38 #include "imc_common.h"
43 #define AT_MT_UNREAD 0 /* Received and Unread */
44 #define AT_MT_READ 1 /* Received and Read */
45 #define AT_MO_UNSENT 2 /* Unsent */
46 #define AT_MO_SENT 3 /* Sent */
47 #define AT_ALL 4 /* Unknown */
49 #define IMC_NUM_PLAN_ID(sca) (gchar)(sca & 0x0F)
50 #define IMC_TYPE_OF_NUM(sca) (gchar)((sca & 0x70) >> 4)
52 /* SCA 12 bytes long and TDPU is 164 bytes long */
53 #define PDU_LEN_MAX 176
54 #define HEX_PDU_LEN_MAX ((PDU_LEN_MAX * 2) + 1)
56 #define IMC_SIM_TON_INTERNATIONAL 1
57 #define IMC_SIM_TON_NATIONAL 2
59 #define IMC_AT_EF_SMS_RECORD_LEN 176
62 guint total_param_count;
66 TelSmsParamsInfo *params;
70 __imc_sms_convert_cms_error_tel_sms_result(const TcoreAtResponse *at_resp)
72 TelSmsResult result = TEL_SMS_RESULT_FAILURE;
74 GSList *tokens = NULL;
77 if (!at_resp || !at_resp->lines) {
78 err("Invalid response data");
82 line = (const gchar *)at_resp->lines->data;
83 tokens = tcore_at_tok_new(line);
84 if (g_slist_length(tokens) > 0) {
88 resp_str = g_slist_nth_data(tokens, 0);
90 err("invalid cms error data");
91 tcore_at_tok_free(tokens);
94 cms_err = atoi(resp_str);
95 dbg("CMS error[%d]", cms_err);
99 result = TEL_SMS_RESULT_INVALID_MANDATORY_INFO;
108 result = TEL_SMS_RESULT_MEMORY_FAILURE;
112 result = TEL_SMS_RESULT_NETWORK_CONGESTION;
122 result = TEL_SMS_RESULT_NETWORK_FAILURE;
129 result = TEL_SMS_RESULT_OPERATION_NOT_SUPPORTED;
136 result = TEL_SMS_RESULT_UNKNOWN_FAILURE;
145 result = TEL_SMS_RESULT_SIM_FAILURE;
169 result = TEL_SMS_RESULT_INVALID_PARAMETER;
173 result = TEL_SMS_RESULT_FAILURE;
176 tcore_at_tok_free(tokens);
182 __imc_sms_convert_cme_error_tel_sms_result(const TcoreAtResponse *at_resp)
184 TelSmsResult result = TEL_SMS_RESULT_FAILURE;
186 GSList *tokens = NULL;
189 if (!at_resp || !at_resp->lines) {
190 err("Invalid response data");
194 line = (const gchar *)at_resp->lines->data;
195 tokens = tcore_at_tok_new(line);
196 if (g_slist_length(tokens) > 0) {
200 resp_str = g_slist_nth_data(tokens, 0);
202 err("Invalid CME Error data");
203 tcore_at_tok_free(tokens);
206 cme_err = atoi(resp_str);
207 dbg("CME error[%d]", cme_err);
212 result = TEL_SMS_RESULT_OPERATION_NOT_SUPPORTED;
223 result = TEL_SMS_RESULT_SIM_FAILURE;
227 result = TEL_SMS_RESULT_MEMORY_FAILURE;
232 result = TEL_SMS_RESULT_NETWORK_FAILURE;
236 result = TEL_SMS_RESULT_INVALID_PARAMETER;
240 result = TEL_SMS_RESULT_UNKNOWN_FAILURE;
244 result = TEL_SMS_RESULT_FAILURE;
247 tcore_at_tok_free(tokens);
253 * Notification - SMS-DELIVER
254 * +CMT = [<alpha>],<length><CR><LF><pdu> (PDU mode enabled)
258 * <length> length of the PDU
259 * <pdu> Incomming SMS PDU
261 * Notification - SMS-STATUS-REPORT
262 * +CDS: <length><CR><LF><pdu> (PDU mode enabled)
265 * <length> length of the PDU
266 * <pdu> Incomming SMS PDU
269 static gboolean on_notification_imc_sms_incoming_msg(CoreObject *co,
270 const void *event_info, void *user_data)
272 GSList *tokens = NULL;
273 GSList *lines = NULL;
275 int pdu_len = 0, no_of_tokens = 0;
277 TelSmsDatapackageInfo incoming_msg = {{0}, };
283 lines = (GSList *)event_info;
284 if (2 != g_slist_length(lines)) {
285 err("Invalid number of lines for +CMT. Must be 2");
290 line = (char *)g_slist_nth_data(lines, 0);
292 err("Line 1 is invalid");
295 dbg("Line 1: [%s]", line);
297 /* Split Line 1 into tokens */
298 tokens = tcore_at_tok_new(line);
299 no_of_tokens = g_slist_length(tokens);
303 * Number of tokens: 2
305 * Incoming SMS-STATUS-REPORT: +CDS
306 * Number of tokens: 1
308 if (2 == no_of_tokens) {
309 /* Token 0: Alpha ID */
310 dbg("Alpha ID: [0x%x]", g_slist_nth_data(tokens, 0));
312 /* Token 1: PDU Length */
313 pdu_len = atoi((char *)g_slist_nth_data(tokens, 1));
314 dbg("pdu_len: [%d]", pdu_len);
315 } else if (1 == no_of_tokens) {
316 /* Token 0: PDU Length */
317 pdu_len = atoi((char *)g_slist_nth_data(tokens, 0));
318 dbg("pdu_len: [%d]", pdu_len);
320 tcore_at_tok_free(tokens);
323 line = (char *)g_slist_nth_data(lines, 1);
325 err("Line 2 is invalid");
328 dbg("Line 2: [%s]", line);
330 /* Convert to Bytes */
331 tcore_util_hexstring_to_bytes(line, &byte_pdu, &byte_pdu_len);
333 sca_length = byte_pdu[0];
334 dbg("SCA length = %d", sca_length);
337 guint encoded_sca_len;
339 * byte_pdu[1] - sca_address_type
340 * Excluding sca_address_type and copy SCA
342 encoded_sca_len = sca_length - 1;
344 tcore_util_convert_bcd_to_ascii(&byte_pdu[2], encoded_sca_len, encoded_sca_len * 2);
345 dbg("Decoded SCA: [%s]", decoded_sca);
346 g_strlcpy(incoming_msg.sca.number, decoded_sca, strlen(decoded_sca)+1);
347 tcore_free(decoded_sca);
349 /*SCA Conversion for Address type*/
350 incoming_msg.sca.ton = IMC_TYPE_OF_NUM(byte_pdu[1]);
351 incoming_msg.sca.npi = IMC_NUM_PLAN_ID(byte_pdu[1]);
352 dbg("TON: [%d] NPI: [%d] SCA: [%s]",
353 incoming_msg.sca.ton, incoming_msg.sca.npi,
354 incoming_msg.sca.number);
356 dbg("NO SCA Present");
360 incoming_msg.tpdu_length = pdu_len;
361 memcpy(incoming_msg.tpdu,
362 &byte_pdu[sca_length+1], incoming_msg.tpdu_length);
364 tcore_util_hex_dump(" ",incoming_msg.tpdu_length, &byte_pdu[sca_length+1]);
366 /* Send notification */
367 tcore_object_send_notification(co,
368 TCORE_NOTIFICATION_SMS_INCOM_MSG,
369 sizeof(TelSmsDatapackageInfo), &incoming_msg);
377 * +CBM: <length><CR><LF><pdu> (PDU mode enabled);
380 * <length> length of the PDU
381 * <pdu> Incomming SMS CB PDU
384 static gboolean on_notification_imc_sms_cb_incom_msg(CoreObject *co,
385 const void *event_info, void *user_data)
387 char * line = NULL, *pdu = NULL, *line_token = NULL;
388 GSList *tokens = NULL;
389 unsigned char *byte_pdu = NULL;
390 guint byte_pdu_len = 0;
391 GSList *lines = NULL;
393 TelSmsCbMsgInfo cb_noti = {0, };
396 lines = (GSList *)event_info;
398 line = (char *)(lines->data);
400 /* Split Line 1 into tokens */
401 tokens = tcore_at_tok_new(line);
402 line_token = g_slist_nth_data(tokens, 0);
404 err("invalid token");
408 cb_noti.length = atoi(line_token);
409 pdu = g_slist_nth_data(lines, 1);
411 err("NULL PDU Recieved ");
415 cb_noti.cb_type = TEL_SMS_CB_MSG_GSM;
416 dbg("CB Msg LENGTH [%d]", cb_noti.length);
418 if ((cb_noti.length > 0) && (cb_noti.length <= TEL_SMS_CB_DATA_SIZE_MAX)) {
419 tcore_util_hexstring_to_bytes(pdu, (gchar **)&byte_pdu, &byte_pdu_len);
420 cb_noti.cb_data = tcore_malloc0(cb_noti.length + 1);
421 memcpy(cb_noti.cb_data, (char*)byte_pdu, cb_noti.length);
423 err("Invalid Message Length");
427 tcore_object_send_notification(co,
428 TCORE_NOTIFICATION_SMS_CB_INCOM_MSG,
429 sizeof(TelSmsCbMsgInfo), &cb_noti);
431 tcore_free(cb_noti.cb_data);
433 err("Invalid Message received");
436 tcore_at_tok_free(tokens);
442 * TODO - AT Command Description Not available
445 static gboolean on_notification_imc_sms_memory_status(CoreObject *co,
446 const void *event_info, void *user_data)
448 gboolean memory_status = TRUE;
450 GSList *tokens = NULL;
451 GSList *lines = NULL;
452 char *line = NULL , *line_token = NULL;
455 lines = (GSList *)event_info;
456 if (1 != g_slist_length(lines)) {
457 dbg("Unsolicited msg but multiple line");
461 line = (char*)(lines->data);
463 tokens = tcore_at_tok_new(line);
464 line_token = g_slist_nth_data(tokens, 0);
466 /* SIM Full condition */
467 if (0 == atoi(line_token))
468 memory_status = FALSE;
470 /* Send notification */
471 tcore_object_send_notification(co,
472 TCORE_NOTIFICATION_SMS_MEMORY_STATUS,
473 sizeof(gboolean), &memory_status);
475 tcore_at_tok_free(tokens);
477 err("invalid message received");
483 static void on_response_imc_class2_sms_incom_msg(TcorePending *p,
484 guint data_len, const void *data, void *user_data)
486 const TcoreAtResponse *at_resp = data;
487 CoreObject *co = tcore_pending_ref_core_object(p);
488 GSList *tokens = NULL;
489 char *gslist_line = NULL, *line_token = NULL;
490 char *byte_pdu = NULL, *hex_pdu = NULL;
492 guint byte_pdu_len = 0;
493 TelSmsDatapackageInfo incoming_msg = { { 0 }, };
496 if (at_resp && at_resp->success) {
498 if (!at_resp->lines) {
499 err("Invalid Response Received");
506 * Fetching First Line
508 gslist_line = (char *)at_resp->lines->data;
509 dbg("gslist_line: [%s]", gslist_line);
512 tokens = tcore_at_tok_new(gslist_line);
513 dbg("Number of tokens: [%d]", g_slist_length(tokens));
515 /* First Token : status (ignore)
516 * Second Token: Alpha ID(ignore)
517 * Third Token: PDU Length.
519 line_token = g_slist_nth_data(tokens, 2);
520 if (line_token != NULL) {
521 incoming_msg.tpdu_length = atoi(line_token);
522 dbg("Length: [%d]", incoming_msg.tpdu_length);
524 err("Line Token for PDU Length is NULL");
525 tcore_at_tok_free(tokens);
529 /* Fetching line: Second line is PDU */
530 hex_pdu = (char *) at_resp->lines->next->data;
531 dbg("EF-SMS PDU: [%s]", hex_pdu);
533 if (NULL != hex_pdu) {
534 tcore_util_hexstring_to_bytes(hex_pdu, &byte_pdu, &byte_pdu_len);
535 sca_length = (int)byte_pdu[0];
536 dbg("SCA Length [%d], msgLength: [%d]",
537 sca_length, incoming_msg.tpdu_length);
539 if (ZERO == sca_length) {
540 memcpy(incoming_msg.tpdu, &byte_pdu[1],
541 incoming_msg.tpdu_length);
546 * byte_pdu[1] - sca_address_type
547 * Excluding sca_address_type and copy SCA
549 memcpy(incoming_msg.sca.number, &byte_pdu[2],
553 * SCA Conversion: Address Type
554 * 3GPP TS 23.040 V6.5.0 Section: 9.1.2.5
556 sca_toa = byte_pdu[1];
557 incoming_msg.sca.npi = IMC_NUM_PLAN_ID(sca_toa);
558 incoming_msg.sca.ton = IMC_TYPE_OF_NUM(sca_toa);
560 memcpy(incoming_msg.tpdu,&byte_pdu[sca_length+1],
561 incoming_msg.tpdu_length);
565 tcore_object_send_notification(co,
566 TCORE_NOTIFICATION_SMS_INCOM_MSG,
567 sizeof(TelSmsDatapackageInfo), &incoming_msg);
568 tcore_at_tok_free(tokens);
577 * +CMTI: <mem>,<index>
580 * <mem> memory location
581 * <index> index where msg is stored
583 static gboolean on_notification_imc_sms_class2_incoming_msg(CoreObject *co,
584 const void *event_info, void *user_data)
586 gchar *at_cmd = NULL;
588 GSList *tokens = NULL , *lines = NULL;
590 gint index, mem_type = 0;
593 lines = (GSList *)event_info;
595 line = (char *)g_slist_nth_data(lines, 0);
597 err("Line 1 is invalid");
600 dbg("Line 1: [%s]", line);
602 /* Split Line 1 into tokens */
603 tokens = tcore_at_tok_new(line);
604 /* Type of Memory stored */
605 mem_type = atoi(g_slist_nth_data(tokens, 0));
606 dbg("mem_type = [%d]", mem_type);
607 index = atoi((char *) g_slist_nth_data(tokens, 1));
608 dbg("index: [%d]", index);
610 tcore_at_tok_free(tokens);
613 * Operation - read_sms_in_sim
616 * AT-Command: At+CMGR=<index>
618 * <index> index of the message to be read.
621 * Success: (PDU: Multi-line output)
622 * +CMGR: <stat>,[<alpha>],<length><CR><LF><pdu>
625 * +CMS ERROR: <error>
629 at_cmd = g_strdup_printf("AT+CMGR=%d", index);
631 /* Send Request to modem */
632 ret = tcore_at_prepare_and_send_request(co,
634 TCORE_AT_COMMAND_TYPE_PDU,
636 on_response_imc_class2_sms_incom_msg, NULL,
637 on_send_imc_request, NULL);
639 if (ret != TEL_RETURN_SUCCESS) {
640 err("Failed to Read Class2 Incomming Message");
646 static void on_response_imc_sms_send_more_msg(TcorePending *p,
647 guint data_len, const void *data, void *user_data)
649 const TcoreAtResponse *at_resp = data;
653 if (at_resp && at_resp->success)
654 dbg("Response OK for AT+CMMS: More msgs to send!!");
656 err("Response NOK for AT+CMMS: More msgs to send");
658 /* Need not send any response */
661 static void on_response_imc_sms_send_sms(TcorePending *p,
662 guint data_len, const void *data, void *user_data)
664 const TcoreAtResponse *at_resp = data;
665 CoreObject *co = tcore_pending_ref_core_object(p);
666 ImcRespCbData *resp_cb_data = user_data;
668 TelSmsResult result = TEL_SMS_RESULT_FAILURE;
671 tcore_check_return_assert(co != NULL);
672 tcore_check_return_assert(resp_cb_data != NULL);
674 if (at_resp && at_resp->success) {
676 if (at_resp->lines) {
679 GSList *tokens = NULL;
682 line = (const gchar *)at_resp->lines->data;
683 tokens = tcore_at_tok_new(line);
684 line_token = g_slist_nth_data(tokens, 0);
685 if (line_token != NULL) {
686 /* Response from MODEM for send SMS: +CMGS:
689 * Message Reference is not used by MSG_SERVER,
690 * and application. So Filling only result
692 msg_ref = atoi(line_token);
693 dbg("Message Reference: [%d]", msg_ref);
694 result = TEL_SMS_RESULT_SUCCESS;
696 err("No Message Reference received");
698 tcore_at_tok_free(tokens);
702 result = __imc_sms_convert_cms_error_tel_sms_result(at_resp);
705 /* Invoke callback */
706 if (resp_cb_data->cb)
707 resp_cb_data->cb(co, (gint)result, NULL, resp_cb_data->cb_data);
709 /* Free callback data */
710 imc_destroy_resp_cb_data(resp_cb_data);
713 static void on_response_imc_sms_write_sms_in_sim(TcorePending *p,
714 guint data_len, const void *data, void *user_data)
716 const TcoreAtResponse *at_resp = data;
717 CoreObject *co = tcore_pending_ref_core_object(p);
718 ImcRespCbData *resp_cb_data = user_data;
720 TelSmsResult result = TEL_SMS_RESULT_FAILURE;
721 GSList *tokens = NULL;
722 char *line = NULL, *line_token = NULL;
726 tcore_check_return_assert(co != NULL);
727 tcore_check_return_assert(resp_cb_data != NULL);
728 if (at_resp && at_resp->success) {
730 if (at_resp->lines) {
731 line = (char *)at_resp->lines->data;
732 tokens = tcore_at_tok_new(line);
733 line_token = g_slist_nth_data(tokens, 0);
735 index = atoi(line_token);
736 dbg("SMS written to '%d' index", index);
737 result = TEL_SMS_RESULT_SUCCESS;
739 err("invalid message");
742 err("Lines NOT present");
746 result = __imc_sms_convert_cms_error_tel_sms_result(at_resp);
749 /* Invoke callback */
750 if (resp_cb_data->cb)
751 resp_cb_data->cb(co, (gint)result, &index, resp_cb_data->cb_data);
753 /* Free callback data */
754 imc_destroy_resp_cb_data(resp_cb_data);
757 static void on_response_imc_sms_read_sms_in_sim(TcorePending *p,
758 guint data_len, const void *data, void *user_data)
760 const TcoreAtResponse *at_resp = data;
761 CoreObject *co = tcore_pending_ref_core_object(p);
762 ImcRespCbData *resp_cb_data = user_data;
763 TelSmsSimDataInfo read_resp = {0,};
764 GSList *tokens = NULL;
766 TelSmsResult result = TEL_SMS_RESULT_FAILURE;
769 tcore_check_return_assert(co != NULL);
770 tcore_check_return_assert(resp_cb_data != NULL);
772 if (at_resp && at_resp->success) {
774 if (at_resp->lines) {
775 gchar *gslist_line = NULL, *line_token = NULL;
776 gchar *byte_pdu = NULL, *hex_pdu = NULL;
777 gint msg_status = 0, pdu_len = 0, alpha_id = 0;
779 guint byte_pdu_len = 0;
785 * Fetching First Line
787 gslist_line = (char *)at_resp->lines->data;
788 dbg("gslist_line: [%s]", gslist_line);
791 tokens = tcore_at_tok_new(gslist_line);
792 dbg("Number of tokens: [%d]", g_slist_length(tokens));
794 /* +CMGR: <stat>,[<alpha>],<length><CR><LF><pdu> */
795 /* First Token: Message status */
796 line_token = g_slist_nth_data(tokens, 0);
797 if (line_token == NULL) {
802 msg_status = atoi(line_token);
803 dbg("msg_status [%d]", msg_status);
805 switch (msg_status) {
807 read_resp.status = TEL_SMS_STATUS_MT_UNREAD;
810 read_resp.status = TEL_SMS_STATUS_MT_READ;
813 read_resp.status = TEL_SMS_STATUS_MO_NOT_SENT;
816 read_resp.status = TEL_SMS_STATUS_MO_SENT;
820 read_resp.status = TEL_SMS_STATUS_REPLACED;
824 /* Second Token: Alpha ID */
825 line_token = g_slist_nth_data(tokens, 1);
826 if (line_token != NULL) {
827 alpha_id = atoi(line_token);
828 dbg("alpha_id: [%d]", alpha_id);
831 /* Third Token: Length */
832 line_token = g_slist_nth_data(tokens, 2);
833 if (line_token == NULL) {
834 err("Invalid PDU length");
837 pdu_len = atoi(line_token);
838 dbg("PDU length: [%d]", pdu_len);
840 /* Fetching line: Second line is PDU */
841 hex_pdu = (char *) at_resp->lines->next->data;
842 dbg("EF-SMS PDU: [%s]", hex_pdu);
844 if (NULL == hex_pdu) {
845 err("Invalid Response Received");
849 tcore_util_hex_dump(" ", sizeof(hex_pdu), (void *)hex_pdu);
851 tcore_util_hexstring_to_bytes(hex_pdu, &byte_pdu, &byte_pdu_len);
853 sca_length = byte_pdu[0];
854 dbg("SCA length = %d", sca_length);
857 guint encoded_sca_len;
860 * byte_pdu[1] - sca_address_type
861 * Excluding sca_address_type and copy SCA
863 encoded_sca_len = sca_length - 1;
865 tcore_util_convert_bcd_to_ascii(&byte_pdu[2],
866 encoded_sca_len, encoded_sca_len * 2);
868 dbg("Decoded SCA: [%s]", decoded_sca);
869 memcpy(read_resp.data.sca.number, decoded_sca,
870 TEL_SMS_SCA_LEN_MAX);
871 tcore_free(decoded_sca);
873 /* SCA Conversion for Address type */
874 read_resp.data.sca.ton = IMC_TYPE_OF_NUM(byte_pdu[1]);
875 read_resp.data.sca.npi = IMC_NUM_PLAN_ID(byte_pdu[1]);
876 dbg("TON: [%d] NPI: [%d] SCA: [%s]",
877 read_resp.data.sca.ton, read_resp.data.sca.npi,
878 read_resp.data.sca.number);
880 err("NO SCA Present");
884 read_resp.data.tpdu_length = pdu_len;
885 if ((read_resp.data.tpdu_length > 0)
886 && (read_resp.data.tpdu_length <= TEL_SMS_SMDATA_SIZE_MAX)) {
887 memcpy(read_resp.data.tpdu, &byte_pdu[sca_length+1],
888 read_resp.data.tpdu_length);
890 warn("Invalid TPDU length: [%d]",
891 read_resp.data.tpdu_length);
894 result = TEL_SMS_RESULT_SUCCESS;
900 result = __imc_sms_convert_cms_error_tel_sms_result(at_resp);
903 /* Invoke callback */
904 if (resp_cb_data->cb)
905 resp_cb_data->cb(co, (gint)result, &read_resp, resp_cb_data->cb_data);
907 /* Free callback data */
908 imc_destroy_resp_cb_data(resp_cb_data);
910 /* free the consumed token */
911 tcore_at_tok_free(tokens);
914 static void on_response_imc_sms_delete_sms_in_sim(TcorePending *p,
915 guint data_len, const void *data, void *user_data)
917 const TcoreAtResponse *at_resp = data;
918 CoreObject *co = tcore_pending_ref_core_object(p);
919 ImcRespCbData *resp_cb_data = user_data;
921 TelSmsResult result = TEL_SMS_RESULT_FAILURE;
924 tcore_check_return_assert(co != NULL);
925 tcore_check_return_assert(resp_cb_data != NULL);
927 if (at_resp && at_resp->success) {
929 result = TEL_SMS_RESULT_SUCCESS;
932 result = __imc_sms_convert_cms_error_tel_sms_result(at_resp);
935 /* Invoke callback */
936 if (resp_cb_data->cb)
937 resp_cb_data->cb(co, (gint)result, NULL, resp_cb_data->cb_data);
939 /* Free callback data */
940 imc_destroy_resp_cb_data(resp_cb_data);
943 static void on_response_imc_sms_get_msg_indices(TcorePending *p,
944 guint data_len, const void *data, void *user_data)
946 /* Response from get_count Request */
947 TelSmsStoredMsgCountInfo *count_info;
948 const TcoreAtResponse *at_resp = data;
949 CoreObject *co = tcore_pending_ref_core_object(p);
950 ImcRespCbData *resp_cb_data = user_data;
951 TelSmsResult result = TEL_SMS_RESULT_FAILURE;
954 tcore_check_return_assert(co != NULL);
955 tcore_check_return_assert(resp_cb_data != NULL);
956 count_info = (TelSmsStoredMsgCountInfo *)IMC_GET_DATA_FROM_RESP_CB_DATA(resp_cb_data);
958 if (at_resp && at_resp->success) {
960 if (at_resp->lines) {
961 gchar *gslist_line = NULL;
962 gint gslist_line_count = 0, ctr_loop = 0;
964 gslist_line_count = g_slist_length(at_resp->lines);
966 if (gslist_line_count > TEL_SMS_GSM_MSG_NUM_MAX)
967 gslist_line_count = TEL_SMS_GSM_MSG_NUM_MAX;
968 dbg("Number of lines: [%d]", gslist_line_count);
970 for (ctr_loop = 0; ctr_loop < gslist_line_count; ctr_loop++) {
971 /* Fetch Line 'ctr_loop' */
972 gslist_line = (char *)g_slist_nth_data(at_resp->lines, ctr_loop);
973 dbg("gslist_line [%d] is [%s]", ctr_loop, gslist_line);
975 if (NULL != gslist_line) {
976 GSList *tokens = NULL;
977 gchar *line_token = NULL;
979 tokens = tcore_at_tok_new(gslist_line);
981 line_token = g_slist_nth_data(tokens, 0);
982 if (NULL != line_token) {
983 count_info->index_list[ctr_loop] =
986 dbg("line_token of gslist_line [%d] is NULL",
990 tcore_at_tok_free(tokens);
992 err("gslist_line is NULL");
997 result = TEL_SMS_RESULT_SUCCESS;
999 err("Invalid Response received. No Lines present in response");
1000 /* Check if used count is zero*/
1001 if (count_info->used_count == 0)
1002 result = TEL_SMS_RESULT_SUCCESS;
1005 err("RESPONSE NOK");
1006 result = __imc_sms_convert_cms_error_tel_sms_result(at_resp);
1010 dbg("get msg indices: [%s]",
1011 (result == TEL_SMS_RESULT_SUCCESS ? "SUCCESS" : "FAIL"));
1013 /* Invoke callback */
1014 if (resp_cb_data->cb)
1015 resp_cb_data->cb(co, (gint)result, count_info, resp_cb_data->cb_data);
1017 /* Free callback data */
1018 imc_destroy_resp_cb_data(resp_cb_data);
1021 static void on_response_imc_sms_get_sms_count(TcorePending *p,
1022 guint data_len, const void *data, void *user_data)
1026 TelSmsStoredMsgCountInfo count_info = {0, };
1027 int used_count = 0, total_count = 0;
1028 const TcoreAtResponse *at_resp = data;
1029 CoreObject *co = tcore_pending_ref_core_object(p);
1030 ImcRespCbData *resp_cb_data = user_data;
1031 ImcRespCbData *getcnt_resp_cb_data;
1032 TelSmsResult result = TEL_SMS_RESULT_FAILURE;
1035 tcore_check_return_assert(co != NULL);
1036 tcore_check_return_assert(resp_cb_data != NULL);
1038 if (at_resp && at_resp->success) {
1040 if (at_resp->lines) {
1041 GSList *tokens = NULL;
1042 gchar *line = NULL, *line_token = NULL;
1044 line = (gchar *)at_resp->lines->data;
1045 dbg("line: [%s]", line);
1050 * +CPMS: <used1>, <total1>, <used2>, <total2>,
1053 tokens = tcore_at_tok_new(line);
1056 line_token = g_slist_nth_data(tokens, 0);
1058 err("Line Token for used count is NULL");
1059 tcore_at_tok_free(tokens);
1062 used_count = atoi(line_token);
1063 dbg("used count [%d]", used_count);
1066 line_token = g_slist_nth_data(tokens, 1);
1068 err("Line Token for Total count is NULL");
1069 tcore_at_tok_free(tokens);
1072 total_count = atoi(line_token);
1073 count_info.total_count = total_count;
1074 count_info.used_count = used_count;
1075 dbg("Count - used: [%d] total: [%d]", used_count, total_count);
1078 * Operation - get_msg_indices_in_sim
1081 * AT-Command: AT+CMGL
1082 * +CPMS=<mem1>[, <mem2>[,<mem3>]]
1084 * <mem1> memory storage to read.
1087 * Success: (Multi-line output)
1090 * <stat> status of the message.
1092 * +CMS ERROR: <error>
1095 /* Sending the Second AT Request to fetch msg indices */
1096 at_cmd = g_strdup_printf("AT+CMGL=4");
1098 /* Response callback data */
1099 getcnt_resp_cb_data = imc_create_resp_cb_data(resp_cb_data->cb,
1100 resp_cb_data->cb_data,
1101 &count_info, sizeof(TelSmsStoredMsgCountInfo));
1103 /* Free previous request callback data */
1104 imc_destroy_resp_cb_data(resp_cb_data);
1105 resp_cb_data = NULL;
1106 /* free the consumed token */
1107 tcore_at_tok_free(tokens);
1109 /* Send Request to modem */
1110 ret = tcore_at_prepare_and_send_request(co,
1112 TCORE_AT_COMMAND_TYPE_MULTILINE,
1114 on_response_imc_sms_get_msg_indices,
1115 getcnt_resp_cb_data,
1116 on_send_imc_request, NULL);
1119 if (ret != TEL_RETURN_SUCCESS) {
1120 err("Failed to Process Get Msg Indices Request");
1121 imc_destroy_resp_cb_data(getcnt_resp_cb_data);
1128 err("Invalid Response Received: NO Lines Present");
1131 err("RESPONSE NOK");
1132 result = __imc_sms_convert_cms_error_tel_sms_result(at_resp);
1136 dbg("Get sms count: [%s]",
1137 (result == TEL_SMS_RESULT_SUCCESS ? "SUCCESS" : "FAIL"));
1139 /* Invoke callback in case of error*/
1140 if (resp_cb_data->cb)
1141 resp_cb_data->cb(co, (gint)result, NULL, resp_cb_data->cb_data);
1143 /* Free callback data */
1144 imc_destroy_resp_cb_data(resp_cb_data);
1147 static void on_response_imc_sms_set_sca(TcorePending *p,
1148 guint data_len, const void *data, void *user_data)
1150 const TcoreAtResponse *at_resp = data;
1151 CoreObject *co = tcore_pending_ref_core_object(p);
1152 ImcRespCbData *resp_cb_data = user_data;
1154 TelSmsResult result = TEL_SMS_RESULT_FAILURE;
1157 tcore_check_return_assert(co != NULL);
1158 tcore_check_return_assert(resp_cb_data != NULL);
1160 if (at_resp && at_resp->success) {
1162 result = TEL_SMS_RESULT_SUCCESS;
1164 err("Response NOK");
1167 dbg("Set sca: [%s]",
1168 (result == TEL_SMS_RESULT_SUCCESS ? "SUCCESS" : "FAIL"));
1170 /* Invoke callback */
1171 if (resp_cb_data->cb)
1172 resp_cb_data->cb(co, (gint)result, NULL, resp_cb_data->cb_data);
1174 /* Free callback data */
1175 imc_destroy_resp_cb_data(resp_cb_data);
1178 static void on_response_imc_sms_get_sca(TcorePending *p,
1179 guint data_len, const void *data, void *user_data)
1181 const TcoreAtResponse *at_resp = data;
1182 CoreObject *co = tcore_pending_ref_core_object(p);
1183 ImcRespCbData *resp_cb_data = user_data;
1185 TelSmsSca sca_resp = { 0, };
1186 TelSmsResult result = TEL_SMS_RESULT_FAILURE;
1189 tcore_check_return_assert(co != NULL);
1190 tcore_check_return_assert(resp_cb_data != NULL);
1192 if (at_resp && at_resp->success) {
1194 if (at_resp->lines) {
1195 GSList *tokens = NULL;
1196 const char *sca_tok_addr;
1197 gchar *line = NULL, *sca_addr = NULL;
1199 gchar *sca_toa = NULL;
1201 line = (gchar *)at_resp->lines->data;
1202 tokens = tcore_at_tok_new(line);
1203 sca_tok_addr = g_slist_nth_data(tokens, 0);
1204 sca_toa = g_slist_nth_data(tokens, 1);
1206 sca_addr = tcore_at_tok_extract(sca_tok_addr);
1207 dbg("SCA: [%s] SCA-TOA: [%s]", sca_addr, sca_toa);
1208 if ((NULL != sca_addr) && (NULL != sca_toa)) {
1209 memcpy(sca_resp.number, sca_addr, strlen(sca_addr));
1211 hexa_toa = atoi(sca_toa);
1212 dbg("SCA-TOA: [0x%x]", hexa_toa);
1213 sca_resp.npi = hexa_toa & 0x0F;
1214 sca_resp.ton = (hexa_toa & 0x70) >> 4;
1215 result = TEL_SMS_RESULT_SUCCESS;
1219 tcore_at_tok_free(tokens);
1222 err("Invalid RESPONSE. No Lines Received");
1225 err("RESPONSE NOK");
1226 result = __imc_sms_convert_cms_error_tel_sms_result(at_resp);
1229 dbg("Get sca: [%s]",
1230 (result == TEL_SMS_RESULT_SUCCESS ? "SUCCESS" : "FAIL"));
1232 /* Invoke callback */
1233 if (resp_cb_data->cb)
1234 resp_cb_data->cb(co, (gint)result, &sca_resp, resp_cb_data->cb_data);
1236 /* Free callback data */
1237 imc_destroy_resp_cb_data(resp_cb_data);
1240 static void on_response_imc_sms_set_cb_config(TcorePending *p,
1241 guint data_len, const void *data, void *user_data)
1243 const TcoreAtResponse *at_resp = data;
1244 CoreObject *co = tcore_pending_ref_core_object(p);
1245 ImcRespCbData *resp_cb_data = user_data;
1247 TelSmsResult result = TEL_SMS_RESULT_FAILURE;
1250 tcore_check_return_assert(co != NULL);
1251 tcore_check_return_assert(resp_cb_data != NULL);
1253 if (at_resp && at_resp->success) {
1255 result = TEL_SMS_RESULT_SUCCESS;
1257 err("RESPONSE NOK");
1258 result = __imc_sms_convert_cme_error_tel_sms_result(at_resp);
1261 dbg("Set cb config: [%s]",
1262 (result == TEL_SMS_RESULT_SUCCESS ? "SUCCESS" : "FAIL"));
1264 /* Invoke callback */
1265 if (resp_cb_data->cb)
1266 resp_cb_data->cb(co, (gint)result, NULL, resp_cb_data->cb_data);
1268 /* Free callback data */
1269 imc_destroy_resp_cb_data(resp_cb_data);
1272 static void on_response_imc_sms_get_cb_config(TcorePending *p,
1273 guint data_len, const void *data, void *user_data)
1275 const TcoreAtResponse *at_resp = data;
1276 CoreObject *co = tcore_pending_ref_core_object(p);
1277 ImcRespCbData *resp_cb_data = user_data;
1279 TelSmsCbConfigInfo get_cb_conf = {0, };
1280 TelSmsResult result = TEL_SMS_RESULT_FAILURE;
1283 tcore_check_return_assert(co != NULL);
1284 tcore_check_return_assert(resp_cb_data != NULL);
1286 if (at_resp && at_resp->success) {
1288 if (at_resp->lines) {
1289 GSList *tokens = NULL;
1290 gchar *data = NULL, *line = NULL;
1291 gchar *msg_ids = NULL;
1292 GSList *cb_tokens = NULL;
1293 gint num_cb_tokens = 0;
1294 gchar *mid_tok = NULL;
1295 gint i = 0, mode = 0;
1296 gchar *first_tok = NULL, *second_tok = NULL;
1297 gchar delim[] = "-";
1299 line = (gchar*)at_resp->lines->data;
1301 err("Line is NULL");
1305 tokens = tcore_at_tok_new(line);
1308 * +CSCB: <mode>,<mids>,<dcss>
1310 data = g_slist_nth_data(tokens, 0);
1313 dbg("mode:[%d]", mode);
1314 get_cb_conf.cb_enabled = mode;
1316 err("Line Token for Mode is NULL");
1317 tcore_at_tok_free(tokens);
1321 data = g_slist_nth_data(tokens, 1);
1323 err("Line Token for MID is NULL");
1324 tcore_at_tok_free(tokens);
1327 msg_ids = tcore_at_tok_extract(data);
1328 cb_tokens = tcore_at_tok_new((const char *)msg_ids);
1329 num_cb_tokens = g_slist_length(cb_tokens);
1330 dbg("num_cb_tokens = %d", num_cb_tokens);
1332 if (num_cb_tokens == 0) {
1333 if (mode == 1) { /* All CBS Enabled */
1334 get_cb_conf.msg_id_range_cnt = 1;
1335 get_cb_conf.msg_ids[0].from_msg_id = 0x0000;
1336 get_cb_conf.msg_ids[0].to_msg_id =
1337 TEL_SMS_GSM_CBMI_LIST_SIZE_MAX + 1;
1338 get_cb_conf.msg_ids[0].selected = TRUE;
1339 } else { /* All CBS Disabled */
1340 get_cb_conf.msg_id_range_cnt = 0;
1341 get_cb_conf.msg_ids[0].selected = FALSE;
1345 for (i = 0; i < num_cb_tokens; i++) {
1346 get_cb_conf.msg_ids[i].selected = TRUE;
1347 dbg("msgIdRangeCount:[%d]", get_cb_conf.msg_id_range_cnt);
1349 get_cb_conf.msg_id_range_cnt++;
1350 dbg("Incremented msgIdRangeCount:[%d]",
1351 get_cb_conf.msg_id_range_cnt);
1353 mid_tok = tcore_at_tok_nth(cb_tokens, i);
1354 first_tok = strtok(mid_tok, delim);
1355 second_tok = strtok(NULL, delim);
1357 /* mids in range (320-478) */
1358 if ((first_tok != NULL) && (second_tok != NULL)) {
1359 get_cb_conf.msg_ids[i].from_msg_id = atoi(first_tok);
1360 get_cb_conf.msg_ids[i].to_msg_id = atoi(second_tok);
1361 } else { /* single mid value (0,1,5, 922)*/
1362 get_cb_conf.msg_ids[i].from_msg_id = atoi(mid_tok);
1363 get_cb_conf.msg_ids[i].to_msg_id = atoi(mid_tok);
1367 result = TEL_SMS_RESULT_SUCCESS;
1368 tcore_at_tok_free(tokens);
1369 tcore_at_tok_free(cb_tokens);
1372 err("Invalid Response.No Lines Received");
1375 err("RESPONSE NOK");
1376 result = __imc_sms_convert_cme_error_tel_sms_result(at_resp);
1380 dbg("Get cb config: [%s]",
1381 (result == TEL_SMS_RESULT_SUCCESS ? "SUCCESS" : "FAIL"));
1383 /* Invoke callback */
1384 if (resp_cb_data->cb)
1385 resp_cb_data->cb(co, (gint)result, &get_cb_conf, resp_cb_data->cb_data);
1387 /* Free callback data */
1388 imc_destroy_resp_cb_data(resp_cb_data);
1391 static void on_response_imc_sms_set_memory_status(TcorePending *p,
1392 guint data_len, const void *data, void *user_data)
1394 const TcoreAtResponse *at_resp = data;
1395 CoreObject *co = tcore_pending_ref_core_object(p);
1396 ImcRespCbData *resp_cb_data = user_data;
1398 TelSmsResult result = TEL_SMS_RESULT_FAILURE;
1401 tcore_check_return_assert(co != NULL);
1402 tcore_check_return_assert(resp_cb_data != NULL);
1404 if (at_resp && at_resp->success) {
1406 result = TEL_SMS_RESULT_SUCCESS;
1408 err("RESPONSE NOK");
1409 result = __imc_sms_convert_cme_error_tel_sms_result(at_resp);
1412 dbg("Set memory status: [%s]",
1413 (result == TEL_SMS_RESULT_SUCCESS ? "SUCCESS" : "FAIL"));
1414 /* Invoke callback */
1415 if (resp_cb_data->cb)
1416 resp_cb_data->cb(co, (gint)result, NULL, resp_cb_data->cb_data);
1418 /* Free callback data */
1419 imc_destroy_resp_cb_data(resp_cb_data);
1422 static void on_response_imc_sms_set_message_status(TcorePending *p,
1423 guint data_len, const void *data, void *user_data)
1425 const TcoreAtResponse *at_resp = data;
1426 CoreObject *co = tcore_pending_ref_core_object(p);
1427 ImcRespCbData *resp_cb_data = user_data;
1429 TelSmsResult result = TEL_SMS_RESULT_FAILURE;
1432 tcore_check_return_assert(co != NULL);
1433 tcore_check_return_assert(resp_cb_data != NULL);
1435 if (at_resp && at_resp->success) {
1437 if (at_resp->lines) {
1438 gint response = 0, sw1 = 0, sw2 = 0;
1439 const char *line = NULL;
1441 GSList *tokens = NULL;
1443 line = (const char *) at_resp->lines->data;
1444 tokens = tcore_at_tok_new(line);
1445 data = g_slist_nth_data(tokens, 0);
1452 data = g_slist_nth_data(tokens, 1);
1455 if ((sw1 == 0x90) && (sw2 == 0)) {
1456 result = TEL_SMS_RESULT_SUCCESS;
1462 data = g_slist_nth_data(tokens, 3);
1464 response = atoi(data);
1465 dbg("response is %s", response);
1467 tcore_at_tok_free(tokens);
1472 err("RESPONSE NOK");
1473 result = __imc_sms_convert_cme_error_tel_sms_result(at_resp);
1476 dbg("Set message status: [%s]",
1477 (result == TEL_SMS_RESULT_SUCCESS ? "SUCCESS" : "FAIL"));
1479 /* Invoke callback */
1480 if (resp_cb_data->cb)
1481 resp_cb_data->cb(co, (gint)result, NULL, resp_cb_data->cb_data);
1483 /* Free callback data */
1484 imc_destroy_resp_cb_data(resp_cb_data);
1487 static void _response_get_efsms_data(TcorePending *p,
1488 guint data_len, const void *data, void *user_data)
1491 const TcoreAtResponse *at_resp = data;
1492 CoreObject *co = tcore_pending_ref_core_object(p);
1493 ImcRespCbData *resp_cb_data = user_data;
1495 TelSmsStatusInfo *status_info;
1496 TelSmsResult result = TEL_SMS_RESULT_FAILURE;
1500 tcore_check_return_assert(co != NULL);
1501 tcore_check_return_assert(resp_cb_data != NULL);
1503 status_info = (TelSmsStatusInfo *)IMC_GET_DATA_FROM_RESP_CB_DATA(resp_cb_data);
1504 if (at_resp && at_resp->success) {
1506 if (at_resp->lines) {
1507 char *encoded_data = NULL;
1508 int encoded_len = 0;
1509 char msg_status = 0;
1510 char *line_token = NULL;
1511 GSList *tokens = NULL;
1512 const char *line = NULL;
1513 gint sw1 = 0, sw2 = 0;
1515 line = (const char *) at_resp->lines->data;
1516 tokens = tcore_at_tok_new(line);
1518 sw1 = atoi(g_slist_nth_data(tokens, 0));
1519 sw2 = atoi(g_slist_nth_data(tokens, 1));
1520 line_token = g_slist_nth_data(tokens, 2);
1521 encoded_len = strlen(line_token);
1523 dbg("line_token:[%s], Length of line token:[%d]",
1524 line_token, encoded_len);
1526 encoded_data = tcore_malloc0(2 * encoded_len + 1);
1527 memcpy(encoded_data, line_token, encoded_len);
1528 dbg("encoded_data: [%s]", encoded_data);
1530 if ((sw1 == 0x90 && sw2 == 0x00) || sw1 == 0x91) {
1531 switch (status_info->status) {
1532 case TEL_SMS_STATUS_MT_READ:
1536 case TEL_SMS_STATUS_MT_UNREAD:
1540 case TEL_SMS_STATUS_MO_NOT_SENT:
1544 case TEL_SMS_STATUS_MO_SENT:
1548 case TEL_SMS_STATUS_MO_DELIVERED:
1552 case TEL_SMS_STATUS_MO_DELIVERY_NOT_CONFIRMED:
1556 case TEL_SMS_STATUS_REPLACED:/*Fall Through*/
1562 /* overwrite Status byte information */
1563 tcore_util_byte_to_hex((const char *)&msg_status, encoded_data, 1);
1566 * Updating EF-SMS File with status byte
1567 * Rest 175 bytes are same as received in Read Record
1570 at_cmd = g_strdup_printf("AT+CRSM=220,28476,%d, 4, %d, \"%s\"",
1571 (status_info->index), IMC_AT_EF_SMS_RECORD_LEN, encoded_data);
1573 /* Send Request to modem */
1574 ret = tcore_at_prepare_and_send_request(co,
1576 TCORE_AT_COMMAND_TYPE_SINGLELINE,
1578 on_response_imc_sms_set_message_status,
1580 on_send_imc_request, NULL);
1581 IMC_CHECK_REQUEST_RET(ret, resp_cb_data,
1582 "Set Message Status-Updating status in Record");
1584 g_free(encoded_data);
1585 g_free(status_info);
1586 tcore_at_tok_free(tokens);
1589 err("Invalid Response Received");
1593 err("RESPONSE NOK");
1594 result = __imc_sms_convert_cme_error_tel_sms_result(at_resp);
1597 dbg("get efsms status: [%s]",
1598 (result == TEL_SMS_RESULT_SUCCESS ? "SUCCESS" : "FAIL"));
1600 /* Invoke callback */
1601 if (resp_cb_data->cb)
1602 resp_cb_data->cb(co, (gint)result, NULL, resp_cb_data->cb_data);
1604 /* Free callback data */
1605 imc_destroy_resp_cb_data(resp_cb_data);
1608 static void on_response_imc_sms_get_sms_params(TcorePending *p,
1609 guint data_len, const void *data, void *user_data)
1611 const TcoreAtResponse *at_resp = data;
1612 CoreObject *co = tcore_pending_ref_core_object(p);
1613 ImcRespCbData *resp_cb_data = user_data;
1614 ImcSmsParamsCbData *params_req_data;
1615 gint sw1 = 0, sw2 = 0, decoding_length = 0;
1616 const char *line = NULL;
1617 char *hex_data = NULL, *record_data = NULL;
1618 GSList *tokens = NULL;
1620 TelSmsResult result = TEL_SMS_RESULT_FAILURE;
1623 params_req_data = (ImcSmsParamsCbData *)IMC_GET_DATA_FROM_RESP_CB_DATA(resp_cb_data);
1625 if (at_resp && at_resp->success) {
1627 if (at_resp->lines) {
1628 line = (const char *) at_resp->lines->data;
1629 tokens = tcore_at_tok_new(line);
1631 sw1 = atoi(g_slist_nth_data(tokens, 0));
1632 sw2 = atoi(g_slist_nth_data(tokens, 1));
1633 dbg("sw1 [0x%x], sw2[0x%x]", sw1, sw2);
1635 if (!(sw1 == 0x90 && sw2 == 0x00) || sw1 == 0x91) {
1636 err("invalid response received");
1640 hex_data = g_slist_nth_data(tokens, 2);
1641 if (hex_data == NULL) {
1642 err("invalid response received");
1646 hex_data = tcore_at_tok_extract((const gchar *)hex_data);
1647 tcore_util_hexstring_to_bytes(hex_data, &record_data, (guint*)&decoding_length);
1648 tcore_free(hex_data);
1650 * Decrementing the Record Count and Filling the ParamsInfo List
1651 * Final RESPONSE will be posted when Record count is ZERO
1653 params_req_data->params[params_req_data->index].index = params_req_data->index;
1655 tcore_util_decode_sms_parameters((unsigned char *)record_data,
1657 ¶ms_req_data->params[params_req_data->index]);
1659 params_req_data->total_param_count -= 1;
1661 if (params_req_data->total_param_count == 0) {
1662 dbg("Reading all Records - Complete");
1663 result = TEL_SMS_RESULT_SUCCESS;
1669 dbg("Reading all records incomplete [Pending - %d]",
1670 params_req_data->total_param_count);
1672 params_req_data->index++;
1675 at_cmd = g_strdup_printf("AT+CRSM=178,28482,%d,4,%d",
1676 params_req_data->index, params_req_data->record_length);
1678 /* Send Request to modem */
1679 ret = tcore_at_prepare_and_send_request(co,
1681 TCORE_AT_COMMAND_TYPE_SINGLELINE,
1683 on_response_imc_sms_get_sms_params, resp_cb_data,
1684 on_send_imc_request, NULL);
1687 if (ret != TEL_RETURN_SUCCESS) {
1688 err("Failed to process request - [%s]", "Get SMS Parameters");
1692 tcore_at_tok_free(tokens);
1696 err("Invalid RESPONSE Received");
1699 err("RESPONSE NOK");
1700 result = __imc_sms_convert_cme_error_tel_sms_result(at_resp);
1705 TelSmsParamsInfoList param_info_list = {0, };
1706 if (result == TEL_SMS_RESULT_SUCCESS) {
1707 param_info_list.params = params_req_data->params;
1708 param_info_list.count = params_req_data->record_count;
1711 /* Invoke callback */
1712 if (resp_cb_data->cb)
1713 resp_cb_data->cb(co, (gint)result, (void *)¶m_info_list, resp_cb_data->cb_data);
1717 tcore_at_tok_free(tokens);
1719 tcore_free(params_req_data->params);
1720 g_free(record_data);
1722 /* Free callback data */
1723 imc_destroy_resp_cb_data(resp_cb_data);
1726 static void on_response_imc_sms_set_sms_params(TcorePending *p,
1727 guint data_len, const void *data, void *user_data)
1729 const TcoreAtResponse *at_resp = data;
1730 CoreObject *co = tcore_pending_ref_core_object(p);
1731 ImcRespCbData *resp_cb_data = user_data;
1732 TelSmsResult result = TEL_SMS_RESULT_FAILURE;
1735 tcore_check_return_assert(co != NULL);
1736 tcore_check_return_assert(resp_cb_data != NULL);
1738 if (at_resp && at_resp->success) {
1740 if (at_resp->lines) {
1741 gint sw1 = 0 , sw2 = 0;
1742 const char *line = NULL;
1743 GSList *tokens = NULL;
1745 line = (const char *) at_resp->lines->data;
1746 tokens = tcore_at_tok_new(line);
1748 sw1 = atoi(g_slist_nth_data(tokens, 0));
1749 sw2 = atoi(g_slist_nth_data(tokens, 1));
1751 if ((sw1 == 0x90 && sw2 == 0x00) || sw1 == 0x91) {
1752 result = TEL_SMS_RESULT_SUCCESS;
1754 tcore_at_tok_free(tokens);
1758 err("RESPONSE NOK");
1759 result = __imc_sms_convert_cme_error_tel_sms_result(at_resp);
1762 dbg("set sms params: [%s]",
1763 (result == TEL_SMS_RESULT_SUCCESS ? "SUCCESS" : "FAIL"));
1765 /* Invoke callback */
1766 if (resp_cb_data->cb)
1767 resp_cb_data->cb(co, (gint)result, NULL, resp_cb_data->cb_data);
1769 /* Free callback data */
1770 imc_destroy_resp_cb_data(resp_cb_data);
1773 static gboolean async_callback(gpointer data)
1775 ImcRespCbData *resp_cb_data = data;
1777 TelSmsResult result = TEL_SMS_RESULT_SUCCESS;
1779 co = ((CoreObject **)IMC_GET_DATA_FROM_RESP_CB_DATA(resp_cb_data));
1781 /* Invoke callback */
1782 if (resp_cb_data->cb)
1783 resp_cb_data->cb(*co, (gint)result, NULL, resp_cb_data->cb_data);
1785 /* Free callback data */
1786 imc_destroy_resp_cb_data(resp_cb_data);
1791 /* SMS Operations */
1793 * Operation - send_sms
1796 * AT-Command: AT+CMGS
1797 * For PDU mode (+CMGF=0):
1798 * +CMGS=<length><CR>
1799 * PDU is given<ctrl-Z/ESC>
1801 * <length> Length of the pdu.
1802 * <PDU> PDU to send.
1805 * +CMGS: <mr>[,<ackpdu>]
1808 * +CMS ERROR: <error>
1810 static TelReturn imc_sms_send_sms(CoreObject *co,
1811 const TelSmsSendInfo *send_info, TcoreObjectResponseCallback cb, void *cb_data)
1815 ImcRespCbData *resp_cb_data;
1818 const unsigned char *tpdu_byte_data;
1819 gint tpdu_byte_len, pdu_byte_len;
1820 char buf[HEX_PDU_LEN_MAX];
1821 char pdu[PDU_LEN_MAX];
1824 tpdu_byte_data = send_info->send_data.tpdu;
1826 /* TPDU length is in byte */
1827 tpdu_byte_len = send_info->send_data.tpdu_length;
1829 /* Use same Radio Resource Channel :More Messages to send*/
1830 dbg("More messages: [%d]", send_info->more_msgs);
1832 /* Prepare PDU for hex encoding */
1833 pdu_byte_len = tcore_util_encode_pdu(&(send_info->send_data.sca),
1834 tpdu_byte_data, tpdu_byte_len, pdu);
1835 tcore_util_hex_dump(" ", pdu_byte_len, pdu);
1837 tcore_util_encode_hex((unsigned char *)pdu, pdu_byte_len, buf);
1839 /* Response callback data */
1840 resp_cb_data = imc_create_resp_cb_data(cb, cb_data, NULL, 0);
1842 if (send_info->more_msgs == TRUE) {
1843 /* AT Command: More Msgs to Send */
1844 ret = tcore_at_prepare_and_send_request(co,
1845 "AT+CMMS=1", "+CMMS:",
1846 TCORE_AT_COMMAND_TYPE_SINGLELINE,
1848 on_response_imc_sms_send_more_msg, NULL,
1849 on_send_imc_request, NULL);
1850 IMC_CHECK_REQUEST_RET(ret, NULL, "More Msgs to Send");
1853 /* AT-Command : Send SMS*/
1854 at_cmd = g_strdup_printf("AT+CMGS=%d\r%s\x1A", tpdu_byte_len, buf);
1856 /* Send Request to modem */
1857 ret = tcore_at_prepare_and_send_request(co,
1859 TCORE_AT_COMMAND_TYPE_SINGLELINE,
1861 on_response_imc_sms_send_sms, resp_cb_data,
1862 on_send_imc_request, NULL);
1863 IMC_CHECK_REQUEST_RET(ret, resp_cb_data, "Send SMS");
1865 /* Free resources */
1872 * Operation - write_sms_in_sim
1875 * AT-Command: AT+CMGW
1876 * AT+CMGW = <length>[,<stat>]<CR>PDU is given<ctrl-Z/ESC>
1878 * <length> length of the tpdu
1879 * <stat> status of the message
1880 * <PDU> PDu of the message
1884 * Success: (Single line)
1887 * +CMS ERROR: <error>
1889 static TelReturn imc_sms_write_sms_in_sim(CoreObject *co,
1890 const TelSmsSimDataInfo *wdata, TcoreObjectResponseCallback cb, void *cb_data)
1894 ImcRespCbData *resp_cb_data;
1897 const unsigned char *tpdu_byte_data;
1898 int tpdu_byte_len, pdu_byte_len;
1899 char buf[HEX_PDU_LEN_MAX];
1900 char hex_pdu[PDU_LEN_MAX];
1904 switch (wdata->status) {
1905 case TEL_SMS_STATUS_MT_UNREAD:
1906 status = AT_MT_UNREAD;
1909 case TEL_SMS_STATUS_MT_READ:
1910 status = AT_MT_READ;
1913 case TEL_SMS_STATUS_MO_NOT_SENT:
1914 status = AT_MO_UNSENT;
1917 case TEL_SMS_STATUS_MO_SENT:
1918 status = AT_MO_SENT;
1922 err("Invalid Message Status");
1923 return TEL_RETURN_INVALID_PARAMETER;
1925 tpdu_byte_data = wdata->data.tpdu;
1927 tpdu_byte_len = wdata->data.tpdu_length;
1928 dbg("TDPU length: [%d]", tpdu_byte_len);
1930 /* Prepare PDU for hex encoding */
1931 pdu_byte_len = tcore_util_encode_pdu(&(wdata->data.sca),
1932 tpdu_byte_data, tpdu_byte_len, hex_pdu);
1933 tcore_util_hex_dump(" ", pdu_byte_len, hex_pdu);
1935 tcore_util_encode_hex((unsigned char *)hex_pdu, pdu_byte_len, buf);
1938 at_cmd = g_strdup_printf("AT+CMGW=%d,%d%c%s%c",
1939 tpdu_byte_len, status, CR, buf, CTRL_Z);
1941 /* Response callback data */
1942 resp_cb_data = imc_create_resp_cb_data(cb, cb_data, NULL, 0);
1944 /* Send Request to modem */
1945 ret = tcore_at_prepare_and_send_request(co,
1947 TCORE_AT_COMMAND_TYPE_SINGLELINE,
1949 on_response_imc_sms_write_sms_in_sim, resp_cb_data,
1950 on_send_imc_request, NULL);
1951 IMC_CHECK_REQUEST_RET(ret, resp_cb_data, "Write SMS in SIM");
1953 /* Free resources */
1960 * Operation - read_sms_in_sim
1963 * AT-Command: At+CMGR=<index>
1965 * <index> index of the message to be read.
1968 * Success: (PDU: Multi-line output)
1969 * +CMGR: <stat>,[<alpha>],<length><CR><LF><pdu>
1972 * +CMS ERROR: <error>
1974 static TelReturn imc_sms_read_sms_in_sim(CoreObject *co,
1975 unsigned int index, TcoreObjectResponseCallback cb, void *cb_data)
1979 ImcRespCbData *resp_cb_data;
1984 at_cmd = g_strdup_printf("AT+CMGR=%d", index);
1986 /* Response callback data */
1987 resp_cb_data = imc_create_resp_cb_data(cb, cb_data, NULL, ZERO);
1989 /* Send Request to modem */
1990 ret = tcore_at_prepare_and_send_request(co,
1992 TCORE_AT_COMMAND_TYPE_PDU,
1994 on_response_imc_sms_read_sms_in_sim, resp_cb_data,
1995 on_send_imc_request, NULL);
1996 IMC_CHECK_REQUEST_RET(ret, resp_cb_data, "Read SMS in SIM");
1998 /* Free resources */
2005 * Operation - delete_sms_in_sim
2008 * AT-Command: AT+CGMD
2009 * +CMGD=<index>[,<delflag>]
2012 * Success: (NO RESULT) -
2015 * +CMS ERROR: <error>
2017 static TelReturn imc_sms_delete_sms_in_sim(CoreObject *co,
2019 TcoreObjectResponseCallback cb, void *cb_data)
2023 ImcRespCbData *resp_cb_data;
2027 /* Response callback data */
2028 resp_cb_data = imc_create_resp_cb_data(cb, cb_data, NULL, 0);
2030 * TODO: Delete All Messages
2032 * at_cmd = g_strdup_printf("AT+CMGD=0,4");
2033 * Need to convey MSG_SERVICE to pass an index of
2034 * guint value to delete all Messages.probably as 0.
2038 at_cmd = g_strdup_printf("AT+CMGD=%d,0", index); /* Delete specified index */
2040 /* Send Request to modem */
2041 ret = tcore_at_prepare_and_send_request(co,
2043 TCORE_AT_COMMAND_TYPE_NO_RESULT,
2045 on_response_imc_sms_delete_sms_in_sim, resp_cb_data,
2046 on_send_imc_request, NULL);
2047 IMC_CHECK_REQUEST_RET(ret, resp_cb_data, "Delete SMS in SIM");
2049 /* Free resources */
2056 * Operation - get_sms_count_in_sim
2059 * AT-Command: AT+CPMS
2060 * +CPMS=<mem1>[, <mem2>[,<mem3>]]
2062 * <mem1> memory storage to read.
2065 * Success: (Single-line output)
2066 * +CPMS: <mem1>,<used1>,<total1>,<mem2>,<used2>,<total2>,
2067 * <mem3>,<used3>,<total3>
2071 * +CMS ERROR: <error>
2073 static TelReturn imc_sms_get_msg_count_in_sim(CoreObject *co,
2074 TcoreObjectResponseCallback cb, void *cb_data)
2078 ImcRespCbData *resp_cb_data;
2083 at_cmd = g_strdup_printf("AT+CPMS=\"SM\"");
2085 /* Response callback data */
2086 resp_cb_data = imc_create_resp_cb_data(cb, cb_data, NULL, 0);
2088 /* Send Request to modem */
2089 ret = tcore_at_prepare_and_send_request(co,
2091 TCORE_AT_COMMAND_TYPE_SINGLELINE,
2093 on_response_imc_sms_get_sms_count, resp_cb_data,
2094 on_send_imc_request, NULL);
2095 IMC_CHECK_REQUEST_RET(ret, resp_cb_data, "Get SMS Count");
2097 /* Free resources */
2104 * Operation - set SCA
2107 * AT-Command: AT+CSCA
2108 * AT+CSCA=<sca>[,<tosca>]
2110 * <sca> Service center number
2111 * <tosca> address type of SCA
2114 * Success: No result
2118 * +CMS ERROR: <error>
2120 static TelReturn imc_sms_set_sca(CoreObject *co,
2121 const TelSmsSca *sca, TcoreObjectResponseCallback cb, void *cb_data)
2125 ImcRespCbData *resp_cb_data;
2129 address_type = ((sca->ton << 4) | sca->npi ) | 0x80;
2132 at_cmd = g_strdup_printf("AT+CSCA=\"%s\",%d", sca->number, address_type);
2134 /* Response callback data */
2135 resp_cb_data = imc_create_resp_cb_data(cb, cb_data, NULL, 0);
2137 /* Send Request to modem */
2138 ret = tcore_at_prepare_and_send_request(co,
2140 TCORE_AT_COMMAND_TYPE_NO_RESULT,
2142 on_response_imc_sms_set_sca, resp_cb_data,
2143 on_send_imc_request, NULL);
2144 IMC_CHECK_REQUEST_RET(ret, resp_cb_data, "Set SCA");
2146 /* Free resources */
2153 * Operation - get SCA
2156 * AT-Command: AT+CSCA?
2159 * Success: Single-Line
2160 * +CSCA: <sca>,<tosca>
2163 * <sca> Service center number
2164 * <tosca> address type of SCA
2167 static TelReturn imc_sms_get_sca(CoreObject *co,
2168 TcoreObjectResponseCallback cb, void *cb_data)
2170 ImcRespCbData *resp_cb_data;
2174 /* Response callback data */
2175 resp_cb_data = imc_create_resp_cb_data(cb, cb_data, NULL, 0);
2177 /* Send Request to modem */
2178 ret = tcore_at_prepare_and_send_request(co,
2179 "AT+CSCA?", "+CSCA",
2180 TCORE_AT_COMMAND_TYPE_SINGLELINE,
2182 on_response_imc_sms_get_sca, resp_cb_data,
2183 on_send_imc_request, NULL);
2184 IMC_CHECK_REQUEST_RET(ret, resp_cb_data, "Get SCA");
2190 * Operation - set_cb_config
2193 * AT-Command: AT+CSCB
2194 * +CSCB=[<mode>[,<mids>[,<dcss>]]]
2201 * +CME ERROR: <error>
2203 static TelReturn imc_sms_set_cb_config(CoreObject *co,
2204 const TelSmsCbConfigInfo *cb_conf,
2205 TcoreObjectResponseCallback cb, void *cb_data)
2208 ImcRespCbData *resp_cb_data;
2210 unsigned short ctr1 = 0, ctr2 = 0, msg_id_range = 0;
2211 unsigned short append_msg_id = 0;
2214 if (cb_conf->msg_id_range_cnt != 0) { /* Enable Specific Msgid's */
2215 gchar *mids_str = NULL;
2216 GString *mid_string = NULL;
2219 mid_string = g_string_new("AT+CSCB=0,\"");
2220 for (ctr1 = 0; ctr1 < cb_conf->msg_id_range_cnt; ctr1++) {
2221 if (cb_conf->msg_ids[ctr1].selected == FALSE)
2223 msg_id_range = ((cb_conf->msg_ids[ctr1].to_msg_id) -
2224 (cb_conf->msg_ids[ctr1].from_msg_id));
2226 if (TEL_SMS_GSM_CBMI_LIST_SIZE_MAX <= msg_id_range) {
2227 mid_string = g_string_new("AT+CSCB=1"); /* Enable All CBS */
2230 append_msg_id = cb_conf->msg_ids[ctr1].from_msg_id;
2231 dbg( "%x", append_msg_id);
2233 for (ctr2 = 0; ctr2 <= msg_id_range; ctr2++) {
2234 mid_string = g_string_append(mid_string,
2235 g_strdup_printf("%d", append_msg_id));
2236 if (ctr2 == msg_id_range) {
2237 /* Mids string termination */
2238 mid_string = g_string_append(mid_string, "\"");
2240 mid_string = g_string_append(mid_string, ",");
2245 mids_str = g_string_free(mid_string, FALSE);
2246 at_cmd = g_strdup_printf("%s", mids_str);
2249 /* Enable or Disable MsgId's */
2250 at_cmd = g_strdup_printf("AT+CSCB=%d", cb_conf->cb_enabled);
2253 /* Response callback data */
2254 resp_cb_data = imc_create_resp_cb_data(cb, cb_data, NULL, 0);
2256 /* Send Request to modem */
2257 ret = tcore_at_prepare_and_send_request(co,
2259 TCORE_AT_COMMAND_TYPE_NO_RESULT,
2261 on_response_imc_sms_set_cb_config, resp_cb_data,
2262 on_send_imc_request, NULL);
2263 IMC_CHECK_REQUEST_RET(ret, resp_cb_data, "Set Cb Config");
2265 /* Free resources */
2272 * Operation - get_cb_config
2275 * AT-Command: AT+CSCB
2279 * Success - (Single line)
2280 * +CSCB : <mode>,<mids>,<dcss>
2284 static TelReturn imc_sms_get_cb_config(CoreObject *co,
2285 TcoreObjectResponseCallback cb, void *cb_data)
2287 ImcRespCbData *resp_cb_data;
2291 /* Response callback data */
2292 resp_cb_data = imc_create_resp_cb_data(cb, cb_data, NULL, 0);
2294 /* Send Request to modem */
2295 ret = tcore_at_prepare_and_send_request(co,
2297 TCORE_AT_COMMAND_TYPE_SINGLELINE,
2299 on_response_imc_sms_get_cb_config, resp_cb_data,
2300 on_send_imc_request, NULL);
2301 IMC_CHECK_REQUEST_RET(ret, resp_cb_data, "Get Cb Config");
2307 * Operation - send_deliver_report
2310 * Modem Takes care of sending the ACK to the network
2313 * Success: Default response always SUCCESS posted
2316 static TelReturn imc_sms_send_deliver_report(CoreObject *co,
2317 const TelSmsDeliverReportInfo *dr_info,
2318 TcoreObjectResponseCallback cb, void *cb_data)
2320 ImcRespCbData *resp_cb_data;
2321 TelReturn ret = TEL_RETURN_FAILURE;
2323 dbg("CP takes care of sending SMS ack to network for all "
2324 "classes of SMS. Sending default success.!!!");
2325 ret = TEL_RETURN_SUCCESS;
2327 /* Response callback data */
2328 resp_cb_data = imc_create_resp_cb_data(cb, cb_data,
2329 (void *)&co, sizeof(CoreObject*));
2331 g_idle_add(async_callback, (gpointer)resp_cb_data);
2337 /* Operation - set memory status
2340 * AT-Command: AT+XTESM=<mem_capacity>
2341 * <mem_capacity> status of the external SMS storage which may be:
2342 * 0: memory capacity free
2343 * 1: memory capacity full
2345 * Response -No Result
2350 * +CME ERROR: <error>
2352 static TelReturn imc_sms_set_memory_status(CoreObject *co,
2353 gboolean available, TcoreObjectResponseCallback cb, void *cb_data)
2357 ImcRespCbData *resp_cb_data;
2361 at_cmd = g_strdup_printf("AT+XTESM=%d", available? 0: 1);
2363 /* Response callback data */
2364 resp_cb_data = imc_create_resp_cb_data(cb, cb_data, NULL, 0);
2366 /* Send Request to modem */
2367 ret = tcore_at_prepare_and_send_request(co,
2369 TCORE_AT_COMMAND_TYPE_NO_RESULT,
2371 on_response_imc_sms_set_memory_status, resp_cb_data,
2372 on_send_imc_request, NULL);
2373 IMC_CHECK_REQUEST_RET(ret, resp_cb_data, "Set Memory Status");
2375 /* Free resources */
2381 /* Operation - set Message status
2384 * AT-Command: AT+CRSM= command>[,<fileid>[,<P1>,<P2>,<P3>[,<data>[,<pathid>]]]]
2386 * p3 SMSP record length
2389 * Response -Single Line
2394 * +CME ERROR: <error>
2396 static TelReturn imc_sms_set_message_status(CoreObject *co,
2397 const TelSmsStatusInfo *status_info,
2398 TcoreObjectResponseCallback cb, void *cb_data)
2402 ImcRespCbData *resp_cb_data;
2406 at_cmd = g_strdup_printf("AT+CRSM=178,28476,%d,4,%d",
2407 (status_info->index), IMC_AT_EF_SMS_RECORD_LEN);
2409 /* Response callback data */
2410 resp_cb_data = imc_create_resp_cb_data(cb, cb_data,
2411 (void *)status_info, sizeof(TelSmsStatusInfo));
2413 /* Send Request to modem */
2414 ret = tcore_at_prepare_and_send_request(co,
2416 TCORE_AT_COMMAND_TYPE_SINGLELINE,
2418 _response_get_efsms_data, resp_cb_data,
2419 on_send_imc_request, NULL);
2420 IMC_CHECK_REQUEST_RET(ret, resp_cb_data, "Set Message Status");
2422 /* Free resources */
2429 * Operation - get_sms_parameters
2432 * AT-Command: AT+CRSM
2433 * AT+CRSM= command>[,<fileid>[,<P1>,<P2>,<P3>[,<data>[,<pathid>]]]]
2436 * Success: (Single-line output)
2438 * <sw1>,<sw2>[,<response>]
2442 * +CME ERROR: <error>
2444 static TelReturn imc_sms_get_sms_params(CoreObject *co,
2445 TcoreObjectResponseCallback cb, void *cb_data)
2447 TcorePlugin *plugin;
2448 ImcRespCbData *resp_cb_data;
2449 ImcSmsParamsCbData params_req_data = {0, };
2450 gint record_count = 0, smsp_record_len = 0;
2454 TelReturn ret = TEL_RETURN_INVALID_PARAMETER;
2458 plugin = tcore_object_ref_plugin(co);
2460 /* Get Record count and SMSP record length*/
2461 if (FALSE == (imc_sim_get_smsp_info(plugin, &record_count,
2462 &smsp_record_len))) {
2463 err("Failed to get SMSP record Count and Record length");
2467 dbg("Record Count: [%d] SMSP Record Length: [%d]",
2468 record_count, smsp_record_len);
2470 /* Allocate Memory for params list data */
2471 params_req_data.params = tcore_malloc0(sizeof(TelSmsParamsInfo) * record_count);
2473 params_req_data.total_param_count = record_count;
2475 /* Actual count to be returned */
2476 params_req_data.record_count = record_count;
2477 /* SMSP record length */
2478 params_req_data.record_length = smsp_record_len;
2480 /* RESPONSE callback data */
2481 resp_cb_data = imc_create_resp_cb_data(cb, cb_data,
2482 (void *)¶ms_req_data,
2483 sizeof(ImcSmsParamsCbData));
2485 /* Starting the Index with 1 */
2486 params_req_data.index = 1;
2489 at_cmd = g_strdup_printf("AT+CRSM=178,28482,%d,4,%d",
2490 params_req_data.index, params_req_data.record_length);
2492 /* Send Request to modem */
2493 ret = tcore_at_prepare_and_send_request(co,
2495 TCORE_AT_COMMAND_TYPE_SINGLELINE,
2497 on_response_imc_sms_get_sms_params, resp_cb_data,
2498 on_send_imc_request, NULL);
2499 IMC_CHECK_REQUEST_RET(ret, resp_cb_data, "Get SMS Parameters");
2501 /* Free resources */
2502 if (ret != TEL_RETURN_SUCCESS)
2503 tcore_free(params_req_data.params);
2510 * Operation - set_sms_params
2513 * AT-Command: AT+CRSM
2514 * AT+CRSM= command>[,<fileid>[,<P1>,<P2>,<P3>[,<data>[,<pathid>]]]]
2517 * Success: (Single-line output)
2519 * <sw1>,<sw2>[,<response>]
2523 * +CME ERROR: <error>
2525 static TelReturn imc_sms_set_sms_params(CoreObject *co,
2526 const TelSmsParamsInfo *params,
2527 TcoreObjectResponseCallback cb, void *cb_data)
2530 ImcRespCbData *resp_cb_data;
2533 TcorePlugin *plugin;
2534 gint smsp_record_len = 0;
2535 gchar *set_params_data = NULL;
2536 gchar *encoded_data = NULL;
2540 plugin = tcore_object_ref_plugin(co);
2542 if (FALSE == imc_sim_get_smsp_info(plugin, &record_count, &smsp_record_len)) {
2543 err("Failed to get SMSP record Count and Record length");
2544 return TEL_RETURN_INVALID_PARAMETER;
2547 dbg("SMSP Record Length: [%d]", smsp_record_len);
2549 /* Allocate memory for set_params_data */
2550 set_params_data = tcore_malloc0(smsp_record_len);
2552 /* Allocate memory for encoded data*/
2553 encoded_data = tcore_malloc0((2*smsp_record_len)+1);
2555 tcore_util_encode_sms_parameters((TelSmsParamsInfo *)params,
2556 set_params_data, smsp_record_len);
2557 dbg("SCA Address: [%s]", params->sca.number);
2559 tcore_util_byte_to_hex((const char *)set_params_data,
2560 (char *)encoded_data, smsp_record_len);
2562 /* RESPONSE callback data */
2563 resp_cb_data = imc_create_resp_cb_data(cb, cb_data, NULL, 0);
2566 at_cmd = g_strdup_printf("AT+CRSM=220,28482,%d,4,%d,\"%s\"",
2567 params->index, smsp_record_len, encoded_data);
2568 dbg("at_cmd - %s", at_cmd);
2569 /* Send Request to modem */
2570 ret = tcore_at_prepare_and_send_request(co,
2572 TCORE_AT_COMMAND_TYPE_SINGLELINE,
2574 on_response_imc_sms_set_sms_params, resp_cb_data,
2575 on_send_imc_request, NULL);
2576 IMC_CHECK_REQUEST_RET(ret, resp_cb_data, "Set SMS Parameters");
2578 /* Free resources */
2580 g_free(set_params_data);
2581 g_free(encoded_data);
2586 /* SMS Operations */
2587 static TcoreSmsOps imc_sms_ops = {
2588 .send_sms = imc_sms_send_sms,
2589 .read_in_sim = imc_sms_read_sms_in_sim,
2590 .write_in_sim = imc_sms_write_sms_in_sim,
2591 .delete_in_sim = imc_sms_delete_sms_in_sim,
2592 .get_count = imc_sms_get_msg_count_in_sim,
2593 .set_cb_config = imc_sms_set_cb_config,
2594 .get_cb_config = imc_sms_get_cb_config,
2595 .get_parameters = imc_sms_get_sms_params,
2596 .set_parameters = imc_sms_set_sms_params,
2597 .send_deliver_report = imc_sms_send_deliver_report,
2598 .set_sca = imc_sms_set_sca,
2599 .get_sca = imc_sms_get_sca,
2600 .set_memory_status = imc_sms_set_memory_status,
2601 .set_message_status = imc_sms_set_message_status
2604 gboolean imc_sms_init(TcorePlugin *p, CoreObject *co)
2608 /* Set operations */
2609 tcore_sms_set_ops(co, &imc_sms_ops);
2612 tcore_object_add_callback(co, "\e+CMT:",
2613 on_notification_imc_sms_incoming_msg, NULL);
2614 tcore_object_add_callback(co, "\e+CDS",
2615 on_notification_imc_sms_incoming_msg, NULL);
2617 tcore_object_add_callback(co, "\e+CBM",
2618 on_notification_imc_sms_cb_incom_msg, NULL);
2619 tcore_object_add_callback(co, "+CMTI",
2620 on_notification_imc_sms_class2_incoming_msg, NULL);
2624 * TODO - AT Command Description Not available
2626 tcore_object_add_callback(co, "+XSMSMMSTAT",
2627 on_notification_imc_sms_memory_status, NULL);
2633 void imc_sms_exit(TcorePlugin *p, CoreObject *co)