e4f6bfa37a8e8cde71b507ad78f780b68397fbec
[framework/telephony/libslp-tapi.git] / mobile / src / tapi_sms.c
1 /*
2  * libslp-tapi
3  *
4  * Copyright (c) 2011 Samsung Electronics Co., Ltd. All rights reserved.
5  *
6  * Contact: Ja-young Gu <jygu@samsung.com>
7  *
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
11  *
12  * http://www.apache.org/licenses/LICENSE-2.0
13  *
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.
19  */
20
21
22 /**
23  * @ingroup     TAPI
24  * @defgroup    SMS
25  * @{
26  *
27  * SMS APIs allow a client to accomplish the following features: @n
28  * - Send, Recieve, Save, Delete, Read short messages  @n
29  * - Set and Get information like Service Center Address, Cell Broadcast configuration,Preferred Bearer, SMS parameters @n
30  * - Retrieve information like Current Memory selected, NetTextCount related to the messages @n
31  * - Set delivery report @n
32  */
33
34 #include <stdio.h>
35 #include <stdlib.h>
36 #include <string.h>
37
38 #include "tapi_common.h"
39 #include "TapiUtility.h"
40 #include "TelSms.h"
41
42 #include "common.h"
43 #include "tapi_log.h"
44 #include "ITapiNetText.h"
45
46 static void on_response_default(GObject *source_object, GAsyncResult *res, gpointer user_data)
47 {
48         GError *error = NULL;
49         GDBusConnection *conn = NULL;
50         struct tapi_resp_data *evt_cb_data = user_data;
51         int result = -1;
52
53         GVariant *dbus_result = NULL;
54         int data = 0;
55
56         conn = G_DBUS_CONNECTION (source_object);
57         dbus_result = g_dbus_connection_call_finish(conn, res, &error);
58
59         CHECK_DEINIT(error);
60
61         if (!dbus_result) {
62                 if (evt_cb_data) {
63                         if (evt_cb_data->cb_fn) {
64                                 evt_cb_data->cb_fn(evt_cb_data->handle, -1, NULL, evt_cb_data->user_data);
65                         }
66
67                         free(evt_cb_data);
68                 }
69
70                 if (error)
71                         g_error_free(error);
72
73                 return;
74         }
75
76         dbg("on_response_default type_format(%s)", g_variant_get_type_string(dbus_result));
77
78         g_variant_get (dbus_result, "(i)", &result);
79
80         if (evt_cb_data) {
81                 if (evt_cb_data->cb_fn) {
82                         evt_cb_data->cb_fn(evt_cb_data->handle, result, &data, evt_cb_data->user_data);
83                 }
84
85                 free(evt_cb_data);
86         }
87 }
88
89 static void on_response_read_msg(GObject *source_object, GAsyncResult *res, gpointer user_data)
90 {
91         GError *error = NULL;
92         GDBusConnection *conn = NULL;
93         struct tapi_resp_data *evt_cb_data = user_data;
94         int result = -1;
95
96         TelSmsData_t    readMsg = {0,};
97
98         GVariant *dbus_result = NULL;
99         const char *sca = NULL;
100         const char *tpdu = NULL;
101         gsize length;
102         guchar *decoded_sca = NULL;
103         guchar *decoded_tpdu = NULL;
104
105         conn = G_DBUS_CONNECTION (source_object);
106         dbus_result = g_dbus_connection_call_finish(conn, res, &error);
107         CHECK_DEINIT(error);
108
109         if (!dbus_result) {
110                 if (evt_cb_data) {
111                         if (evt_cb_data->cb_fn) {
112                                 evt_cb_data->cb_fn(evt_cb_data->handle, -1, NULL, evt_cb_data->user_data);
113                         }
114
115                         free(evt_cb_data);
116                 }
117
118                 if (error)
119                         g_error_free(error);
120
121                 return;
122         }
123
124         dbg("on_response_read_msg type_format(%s)", g_variant_get_type_string(dbus_result));
125
126 //      readMsg.SimIndex = 0xFFFFFFFF;
127         g_variant_get (dbus_result, "(iiisis)", &result,
128                         &readMsg.SimIndex,
129                         &readMsg.MsgStatus,
130                         &sca,
131                         &readMsg.SmsData.MsgLength,
132                         &tpdu);
133
134         decoded_sca = g_base64_decode(sca, &length);
135         if (decoded_sca) {
136                 memcpy(&(readMsg.SmsData.Sca[0]), decoded_sca, TAPI_SMS_ENCODED_SCA_LEN_MAX);
137                 g_free(decoded_sca);
138         }
139
140         decoded_tpdu = g_base64_decode(tpdu, &length);
141         if (decoded_tpdu) {
142                 memcpy(&(readMsg.SmsData.szData[0]), decoded_tpdu, TAPI_NETTEXT_SMDATA_SIZE_MAX + 1);
143                 g_free(decoded_tpdu);
144         }
145
146         if (evt_cb_data) {
147                 if (evt_cb_data->cb_fn) {
148                         evt_cb_data->cb_fn(evt_cb_data->handle, result, &readMsg, evt_cb_data->user_data);
149                 }
150
151                 free(evt_cb_data);
152         }
153 }
154
155 static void on_response_write_msg(GObject *source_object, GAsyncResult *res, gpointer user_data)
156 {
157         GError *error = NULL;
158         GDBusConnection *conn = NULL;
159         struct tapi_resp_data *evt_cb_data = user_data;
160         int result = -1;
161         int index = 0;
162
163         GVariant *dbus_result = NULL;
164
165         conn = G_DBUS_CONNECTION (source_object);
166         dbus_result = g_dbus_connection_call_finish(conn, res, &error);
167         CHECK_DEINIT(error);
168
169         if (!dbus_result) {
170                 if (evt_cb_data) {
171                         if (evt_cb_data->cb_fn) {
172                                 evt_cb_data->cb_fn(evt_cb_data->handle, -1, NULL, evt_cb_data->user_data);
173                         }
174
175                         free(evt_cb_data);
176                 }
177
178                 if (error)
179                         g_error_free(error);
180
181                 return;
182         }
183
184         dbg("on_response_write_msg type_format(%s)", g_variant_get_type_string(dbus_result));
185
186         g_variant_get (dbus_result, "(ii)", &result, &index);
187
188         if (evt_cb_data) {
189                 if (evt_cb_data->cb_fn) {
190                         evt_cb_data->cb_fn(evt_cb_data->handle, result, &index, evt_cb_data->user_data);
191                 }
192
193                 free(evt_cb_data);
194         }
195 }
196
197 static void on_response_delete_msg(GObject *source_object, GAsyncResult *res, gpointer user_data)
198 {
199         GError *error = NULL;
200         GDBusConnection *conn = NULL;
201         struct tapi_resp_data *evt_cb_data = user_data;
202         int result = -1;
203         int index = -1;
204
205         GVariant *dbus_result = NULL;
206
207         conn = G_DBUS_CONNECTION (source_object);
208         dbus_result = g_dbus_connection_call_finish(conn, res, &error);
209         CHECK_DEINIT(error);
210
211         if (!dbus_result) {
212                 if (evt_cb_data) {
213                         if (evt_cb_data->cb_fn) {
214                                 evt_cb_data->cb_fn(evt_cb_data->handle, -1, NULL, evt_cb_data->user_data);
215                         }
216
217                         free(evt_cb_data);
218                 }
219
220                 if (error)
221                         g_error_free(error);
222
223                 return;
224         }
225
226         dbg("on_response_delete_msg type_format(%s)", g_variant_get_type_string(dbus_result));
227
228         g_variant_get (dbus_result, "(ii)", &result, &index);
229
230         if (evt_cb_data) {
231                 if (evt_cb_data->cb_fn) {
232                         evt_cb_data->cb_fn(evt_cb_data->handle, result, &index, evt_cb_data->user_data);
233                 }
234
235                 free(evt_cb_data);
236         }
237 }
238
239 static void on_response_get_msg_count(GObject *source_object, GAsyncResult *res, gpointer user_data)
240 {
241         GError *error = NULL;
242         GDBusConnection *conn = NULL;
243         struct tapi_resp_data *evt_cb_data = user_data;
244         int result = -1;
245         TelSmsStoredMsgCountInfo_t storedMsgCnt = {0,};
246
247         GVariant *dbus_result = NULL;
248         const char *indexList = NULL;
249         gsize length;
250         guchar *decoded_indexList = NULL;
251
252         conn = G_DBUS_CONNECTION (source_object);
253         dbus_result = g_dbus_connection_call_finish(conn, res, &error);
254         CHECK_DEINIT(error);
255
256         if (!dbus_result) {
257                 if (evt_cb_data) {
258                         if (evt_cb_data->cb_fn) {
259                                 evt_cb_data->cb_fn(evt_cb_data->handle, -1, NULL, evt_cb_data->user_data);
260                         }
261
262                         free(evt_cb_data);
263                 }
264
265                 if (error)
266                         g_error_free(error);
267
268                 return;
269         }
270
271         dbg("on_response_get_msg_count type_format(%s)", g_variant_get_type_string(dbus_result));
272
273         g_variant_get (dbus_result, "(iiis)", &result,
274                                                                 &storedMsgCnt.TotalCount,
275                                                                 &storedMsgCnt.UsedCount,
276                                                                 &indexList);
277
278         decoded_indexList = g_base64_decode(indexList, &length);
279         if (decoded_indexList) {
280                 memcpy(&(storedMsgCnt.IndexList[0]), decoded_indexList, TAPI_NETTEXT_GSM_SMS_MSG_NUM_MAX);
281                 g_free(decoded_indexList);
282         }
283
284         if (evt_cb_data) {
285                 if (evt_cb_data->cb_fn) {
286                         evt_cb_data->cb_fn(evt_cb_data->handle, result, &storedMsgCnt, evt_cb_data->user_data);
287                 }
288
289                 free(evt_cb_data);
290         }
291
292 }
293
294 static void on_response_get_sca(GObject *source_object, GAsyncResult *res, gpointer user_data)
295 {
296         GError *error = NULL;
297         GDBusConnection *conn = NULL;
298         struct tapi_resp_data *evt_cb_data = user_data;
299         int result = -1;
300         TelSmsAddressInfo_t scaInfo = {0,};
301
302         GVariant *dbus_result = NULL;
303         const char *sca = NULL;
304         gsize length;
305         guchar *decoded_sca = NULL;
306
307         conn = G_DBUS_CONNECTION (source_object);
308         dbus_result = g_dbus_connection_call_finish(conn, res, &error);
309         CHECK_DEINIT(error);
310
311         if (!dbus_result) {
312                 if (evt_cb_data) {
313                         if (evt_cb_data->cb_fn) {
314                                 evt_cb_data->cb_fn(evt_cb_data->handle, -1, NULL, evt_cb_data->user_data);
315                         }
316
317                         free(evt_cb_data);
318                 }
319
320                 if (error)
321                         g_error_free(error);
322
323                 return;
324         }
325
326         dbg("on_response_get_sca type_format(%s)", g_variant_get_type_string(dbus_result));
327
328         g_variant_get (dbus_result, "(iiiis)", &result,
329                                         &scaInfo.Ton,
330                                         &scaInfo.Npi,
331                                         &scaInfo.DialNumLen,
332                                         &sca);
333
334         decoded_sca = g_base64_decode(sca, &length);
335         if (decoded_sca) {
336                 memcpy(&(scaInfo.szDiallingNum[0]), decoded_sca, TAPI_SIM_SMSP_ADDRESS_LEN + 1);
337                 g_free(decoded_sca);
338         }
339
340         if (evt_cb_data) {
341                 if (evt_cb_data->cb_fn) {
342                         evt_cb_data->cb_fn(evt_cb_data->handle, result, &scaInfo, evt_cb_data->user_data);
343                 }
344
345                 free(evt_cb_data);
346         }
347 }
348
349 static void on_response_get_cb_config(GObject *source_object, GAsyncResult *res, gpointer user_data)
350 {
351         GError *error = NULL;
352         GDBusConnection *conn = NULL;
353         struct tapi_resp_data *evt_cb_data = user_data;
354         int result = -1;
355         int i;
356         TelSmsCbConfig_t cbConfig = {0,};
357
358         GVariant *dbus_result = NULL;
359         GVariant *value = NULL;
360         GVariantIter *iter = NULL;
361         GVariantIter *iter_row = NULL;
362         const gchar *key = NULL;
363
364         conn = G_DBUS_CONNECTION (source_object);
365         dbus_result = g_dbus_connection_call_finish(conn, res, &error);
366         CHECK_DEINIT(error);
367
368         if (!dbus_result) {
369                 if (evt_cb_data) {
370                         if (evt_cb_data->cb_fn) {
371                                 evt_cb_data->cb_fn(evt_cb_data->handle, -1, NULL, evt_cb_data->user_data);
372                         }
373
374                         free(evt_cb_data);
375                 }
376
377                 if (error)
378                         g_error_free(error);
379
380                 return;
381         }
382
383         dbg("on_response_get_cb_config type_format(%s)", g_variant_get_type_string(dbus_result));
384
385         g_variant_get (dbus_result, "(iiiiiaa{sv})", &result,
386                                         &cbConfig.Net3gppType,
387                                         &cbConfig.CBEnabled,
388                                         &cbConfig.MsgIdMaxCount,
389                                         &cbConfig.MsgIdRangeCount,
390                                         &iter);
391
392         i = 0;
393         while (g_variant_iter_next(iter, "a{sv}", &iter_row)) {
394                 while (g_variant_iter_loop(iter_row, "{sv}", &key, &value)) {
395                         if (!g_strcmp0(key, "FromMsgId")) {
396                                 cbConfig.MsgIDs[i].Net3gpp.FromMsgId = g_variant_get_uint16(value);
397                         }
398                         if (!g_strcmp0(key, "ToMsgId")) {
399                                 cbConfig.MsgIDs[i].Net3gpp.ToMsgId = g_variant_get_uint16(value);
400                         }
401                         if (!g_strcmp0(key, "CBCategory")) {
402                                 cbConfig.MsgIDs[i].Net3gpp2.CBCategory = g_variant_get_uint16(value);
403                         }
404                         if (!g_strcmp0(key, "CBLanguage")) {
405                                 cbConfig.MsgIDs[i].Net3gpp2.CBLanguage = g_variant_get_uint16(value);
406                         }
407                         if (!g_strcmp0(key, "Selected")) {
408                                 cbConfig.MsgIDs[i].Net3gpp.Selected = g_variant_get_byte(value);
409                         }
410                 }
411                 i++;
412                 g_variant_iter_free(iter_row);
413         }
414         g_variant_iter_free(iter);
415
416         if (evt_cb_data) {
417                 if (evt_cb_data->cb_fn) {
418                         evt_cb_data->cb_fn(evt_cb_data->handle, result, &cbConfig, evt_cb_data->user_data);
419                 }
420
421                 free(evt_cb_data);
422         }
423 }
424
425 static void on_response_get_sms_params(GObject *source_object, GAsyncResult *res, gpointer user_data)
426 {
427         GError *error = NULL;
428         GDBusConnection *conn = NULL;
429         struct tapi_resp_data *evt_cb_data = user_data;
430         int result = -1;
431         TelSmsParams_t paramInfo = {0,};
432
433         GVariant *dbus_result = NULL;
434         const char *alphaId = NULL;
435         const char *destDialNum = NULL;
436         const char *scaDialNum = NULL;
437         gsize length;
438         guchar *decoded_alphaId = NULL;
439         guchar *decoded_destDialNum = NULL;
440         guchar *decoded_scaDialNum = NULL;
441
442         conn = G_DBUS_CONNECTION (source_object);
443         dbus_result = g_dbus_connection_call_finish(conn, res, &error);
444         CHECK_DEINIT(error);
445
446         if (!dbus_result) {
447                 if (evt_cb_data) {
448                         if (evt_cb_data->cb_fn) {
449                                 evt_cb_data->cb_fn(evt_cb_data->handle, -1, NULL, evt_cb_data->user_data);
450                         }
451
452                         free(evt_cb_data);
453                 }
454
455                 if (error)
456                         g_error_free(error);
457
458                 return;
459         }
460
461         dbg("on_response_get_sms_params type_format(%s)", g_variant_get_type_string(dbus_result));
462
463         g_variant_get (dbus_result, "(iiiisiiiisiiisiii)", &result,
464                                                                 &paramInfo.RecordIndex,
465                                                                 &paramInfo.RecordLen,
466                                                                 &paramInfo.AlphaIdLen,
467                                                                 &alphaId,
468                                                                 &paramInfo.ParamIndicator,
469                                                                 &paramInfo.TpDestAddr.DialNumLen,
470                                                                 &paramInfo.TpDestAddr.Ton,
471                                                                 &paramInfo.TpDestAddr.Npi,
472                                                                 &destDialNum,
473                                                                 &paramInfo.TpSvcCntrAddr.DialNumLen,
474                                                                 &paramInfo.TpSvcCntrAddr.Ton,
475                                                                 &paramInfo.TpSvcCntrAddr.Npi,
476                                                                 &scaDialNum,
477                                                                 &paramInfo.TpProtocolId,
478                                                                 &paramInfo.TpDataCodingScheme,
479                                                                 &paramInfo.TpValidityPeriod);
480
481         decoded_alphaId = g_base64_decode(alphaId, &length);
482         if (decoded_alphaId) {
483                 memcpy(&(paramInfo.szAlphaId[0]), decoded_alphaId, TAPI_SIM_SMSP_ALPHA_ID_LEN_MAX + 1);
484                 g_free(decoded_alphaId);
485         }
486
487         decoded_destDialNum = g_base64_decode(destDialNum, &length);
488         if (decoded_destDialNum) {
489                 memcpy(&(paramInfo.TpDestAddr.szDiallingNum[0]), decoded_destDialNum, TAPI_SIM_SMSP_ADDRESS_LEN + 1);
490                 g_free(decoded_destDialNum);
491         }
492
493         decoded_scaDialNum = g_base64_decode(scaDialNum, &length);
494         if (decoded_scaDialNum) {
495                 memcpy(&(paramInfo.TpSvcCntrAddr.szDiallingNum[0]), decoded_scaDialNum, TAPI_SIM_SMSP_ADDRESS_LEN + 1);
496                 g_free(decoded_scaDialNum);
497         }
498
499         if (evt_cb_data) {
500                 if (evt_cb_data->cb_fn) {
501                         evt_cb_data->cb_fn(evt_cb_data->handle, result, &paramInfo, evt_cb_data->user_data);
502                 }
503
504                 free(evt_cb_data);
505         }
506
507 }
508
509 static void on_response_get_sms_param_cnt(GObject *source_object, GAsyncResult *res, gpointer user_data)
510 {
511         GError *error = NULL;
512         GDBusConnection *conn = NULL;
513         struct tapi_resp_data *evt_cb_data = user_data;
514         int result = -1;
515         int recordCount = 0;
516
517         GVariant *dbus_result = NULL;
518
519         conn = G_DBUS_CONNECTION (source_object);
520         dbus_result = g_dbus_connection_call_finish(conn, res, &error);
521         CHECK_DEINIT(error);
522
523         if (!dbus_result) {
524                 if (evt_cb_data) {
525                         if (evt_cb_data->cb_fn) {
526                                 evt_cb_data->cb_fn(evt_cb_data->handle, -1, NULL, evt_cb_data->user_data);
527                         }
528
529                         free(evt_cb_data);
530                 }
531
532                 if (error)
533                         g_error_free(error);
534
535                 return;
536         }
537
538         dbg("on_response_get_sms_param_cnt type_format(%s)", g_variant_get_type_string(dbus_result));
539
540         g_variant_get (dbus_result, "(ii)", &result,
541                         &recordCount);
542
543         if (evt_cb_data) {
544                 if (evt_cb_data->cb_fn) {
545                         evt_cb_data->cb_fn(evt_cb_data->handle, result, &recordCount, evt_cb_data->user_data);
546                 }
547
548                 free(evt_cb_data);
549         }
550 }
551
552 /**
553  *
554  * This function enables the applications to send SMS to the network.
555  *
556  * @return              Returns appropriate error code. Refer TapiResult_t .
557  * @param[in]          pDataPackage - SMS-SUBMIT TPDU or SMS-COMMAND, and its length have to be passed in this structure.
558  *                              tapi_sms_more_to_send_t parameter denotes whether the sms is short or concatenated.
559  *
560  * @param[out]  RequestId-Unique identifier for a particular request
561  *                         Its value can be any value from 0 to 255 if the API is returned successfully
562  *                           -1 (INVALID_REQUEST_ID) will be sent in case of failure
563  * @Interface           Asynchronous.
564  * @remark
565  * @Refer               tapi_sms_datapackage, tapi_sms_more_to_send_t.
566  */
567 EXPORT_API int tel_send_sms(struct tapi_handle *handle,
568                 const TelSmsDatapackageInfo_t *pDataPackage,
569                 int bMoreMsgToSend,
570                 tapi_response_cb callback, void* user_data)
571 {
572         struct tapi_resp_data *evt_cb_data = NULL;
573         GVariant *param;
574         gchar *encoded_sca = NULL;
575         gchar *encoded_tpdu = NULL;
576
577         dbg("Func Entrance ");
578
579         TAPI_RET_ERR_NUM_IF_FAIL(pDataPackage ,TAPI_API_INVALID_PTR);
580
581         if ((pDataPackage->Sca[0] > TAPI_SIM_SMSP_ADDRESS_LEN)
582                         || (pDataPackage->MsgLength > TAPI_NETTEXT_SMDATA_SIZE_MAX))
583                 return TAPI_API_INVALID_INPUT;
584
585         MAKE_RESP_CB_DATA(evt_cb_data, handle, callback, user_data);
586
587         encoded_sca = g_base64_encode(&(pDataPackage->Sca[0]), TAPI_SMS_ENCODED_SCA_LEN_MAX);
588         if (encoded_sca == NULL) {
589                 dbg("g_base64_encode: Failed to Enocde the SCA");
590                 return TAPI_API_OPERATION_FAILED;
591         }
592
593         encoded_tpdu = g_base64_encode(&(pDataPackage->szData[0]), pDataPackage->MsgLength);
594         if (encoded_tpdu == NULL) {
595                 dbg("g_base64_encode: Failed to Enocde the TPDU");
596                 return TAPI_API_OPERATION_FAILED;
597         }
598
599         param = g_variant_new("(sisi)", encoded_sca,
600                                                         pDataPackage->MsgLength,
601                                                         encoded_tpdu,
602                                                         bMoreMsgToSend);
603
604         g_dbus_connection_call(handle->dbus_connection,
605                 DBUS_TELEPHONY_SERVICE , handle->path, DBUS_TELEPHONY_SMS_INTERFACE,
606                 "SendMsg", param, NULL,
607                 G_DBUS_CALL_FLAGS_NONE, 120000, handle->ca,
608                 on_response_default, evt_cb_data);
609
610         g_free(encoded_sca);
611         g_free(encoded_tpdu);
612
613         return TAPI_API_SUCCESS;
614 }
615
616
617 /**
618  *
619  * This function enables the applications to read sms from the preferred storage.
620  *
621  * @return              Returns appropriate error code. Refer TapiResult_t .
622  * @param[in]           index - the message to be read
623  *
624  * @param[out]  RequestId-Unique identifier for a particular request
625  *                         Its value can be any value from 0 to 255 if the API is returned successfully
626  *                           -1 (INVALID_REQUEST_ID) will be sent in case of failure
627  * @Interface           Asynchronous.
628  * @remark              tapi_sms_selmem_set is to be called always to select the
629  *                              preferred memory before calling this api.
630  * @Refer
631  */
632 EXPORT_API int tel_read_sms_in_sim(struct tapi_handle *handle, int index, tapi_response_cb callback, void* user_data)
633 {
634         struct tapi_resp_data *evt_cb_data = NULL;
635         GVariant *param;
636
637         dbg("Func Entrance ");
638
639         if( (index < 0) || (index > TAPI_NETTEXT_MAX_INDEX) ) {
640                 err("Invalid Input -Read SMS %d",index);
641
642                 return TAPI_API_INVALID_INPUT;
643         }
644
645         TAPI_RET_ERR_NUM_IF_FAIL(callback ,TAPI_API_INVALID_PTR);
646
647         MAKE_RESP_CB_DATA(evt_cb_data, handle, callback, user_data);
648
649         param = g_variant_new("(i)", index);
650
651         g_dbus_connection_call(handle->dbus_connection,
652                 DBUS_TELEPHONY_SERVICE , handle->path, DBUS_TELEPHONY_SMS_INTERFACE,
653                 "ReadMsg", param, NULL,
654                 G_DBUS_CALL_FLAGS_NONE, -1, handle->ca,
655                 on_response_read_msg, evt_cb_data);
656
657         return TAPI_API_SUCCESS;
658 }
659
660
661 /**
662  *
663  * This function enables the applications to write/save sms to the preferred storage.
664  *
665  * @return              Returns appropriate error code. Refer TapiResult_t .
666  * @param[in]           index - the message to be saved, msg_status will denote the status
667  *                              of the message whether Sent, Unsent, Read, Unread, Unknown.
668  *                              pDataPackage- the SMS-SUBMIT PDU or SMS-DELIVER,SMS-STATUSREPORT
669  *                              being passed to be saved in memory.
670  *
671  * @param[out]  RequestId-Unique identifier for a particular request
672  *                         Its value can be any value from 0 to 255 if the API is returned successfully
673  *                           -1 (INVALID_REQUEST_ID) will be sent in case of failure
674  * @Interface           Asynchronous.
675  * @Refer               tapi_sms_datapackage, tapi_sms_status_type.
676  */
677 EXPORT_API int tel_write_sms_in_sim(struct tapi_handle *handle, const TelSmsData_t *pWriteData, tapi_response_cb callback, void* user_data)
678 {
679         struct tapi_resp_data *evt_cb_data = NULL;
680         GVariant *param;
681         gchar *encoded_sca = NULL;
682         gchar *encoded_tpdu = NULL;
683
684         dbg("Func Entrance ");
685
686         TAPI_RET_ERR_NUM_IF_FAIL(pWriteData ,TAPI_API_INVALID_PTR);
687
688         MAKE_RESP_CB_DATA(evt_cb_data, handle, callback, user_data);
689
690         encoded_sca = g_base64_encode(&(pWriteData->SmsData.Sca[0]), TAPI_SMS_ENCODED_SCA_LEN_MAX);
691         if (encoded_sca == NULL) {
692                 dbg("g_base64_encode: Failed to Enocde the SCA");
693                 return TAPI_API_OPERATION_FAILED;
694         }
695
696         encoded_tpdu = g_base64_encode(&(pWriteData->SmsData.szData[0]), TAPI_NETTEXT_SMDATA_SIZE_MAX + 1);
697         if (encoded_tpdu == NULL) {
698                 dbg("g_base64_encode: Failed to Enocde the TPDU");
699                 return TAPI_API_OPERATION_FAILED;
700         }
701
702         param = g_variant_new("(isis)", pWriteData->MsgStatus,
703                                                         encoded_sca,
704                                                         pWriteData->SmsData.MsgLength,
705                                                         encoded_tpdu);
706
707         g_dbus_connection_call(handle->dbus_connection,
708                 DBUS_TELEPHONY_SERVICE , handle->path, DBUS_TELEPHONY_SMS_INTERFACE,
709                 "SaveMsg", param, NULL,
710                 G_DBUS_CALL_FLAGS_NONE, -1, handle->ca,
711                 on_response_write_msg, evt_cb_data);
712
713         g_free(encoded_sca);
714         g_free(encoded_tpdu);
715
716         return TAPI_API_SUCCESS;
717 }
718
719
720 /**
721  *
722  * This function enables the applications to delete sms to the preferred storage.
723  *
724  * @return              Returns appropriate error code. Refer TapiResult_t .
725  * @param[in]           index - the message to be deleted. if index is -1, all sms in the sim are deleted.
726  *
727  * @param[out]  RequestId-Unique identifier for a particular request
728  *                         Its value can be any value from 0 to 255 if the API is returned successfully
729  *                           -1 (INVALID_REQUEST_ID) will be sent in case of failure
730  * @Interface           Asynchronous.
731  * @remark              tapi_sms_selmem_set has to be called always before calling this API
732  * @Refer
733  */
734 EXPORT_API int tel_delete_sms_in_sim(struct tapi_handle *handle, int index, tapi_response_cb callback, void* user_data)
735 {
736         struct tapi_resp_data *evt_cb_data = NULL;
737         GVariant *param;
738
739         dbg("Func Entrance ");
740
741         if ((index < -1) || (index > TAPI_NETTEXT_MAX_INDEX)) {
742                 err("Invalid Index Input");
743                 return TAPI_API_INVALID_INPUT;
744         }
745
746         MAKE_RESP_CB_DATA(evt_cb_data, handle, callback, user_data);
747
748         param = g_variant_new("(i)", index);
749
750         g_dbus_connection_call(handle->dbus_connection,
751                 DBUS_TELEPHONY_SERVICE , handle->path, DBUS_TELEPHONY_SMS_INTERFACE,
752                 "DeleteMsg", param, NULL,
753                 G_DBUS_CALL_FLAGS_NONE, -1, handle->ca,
754                 on_response_delete_msg, evt_cb_data);
755
756         return TAPI_API_SUCCESS;
757 }
758
759
760 /**
761  *
762  * This function enables the applications to get the count of the messages stored in the memory
763  *
764  * @return              Returns appropriate error code. Refer TapiResult_t .
765  * @param[in]   None
766  *
767  * @param[out]  RequestId-Unique identifier for a particular request
768  *              Its value can be any value from 0 to 255 if the API is returned successfully
769  *                  -1 (INVALID_REQUEST_ID) will be sent in case of failure
770  * @Interface   Asynchronous
771  * @remark              The requested memory details come in response API
772  * @Refer           None
773  */
774 EXPORT_API int tel_get_sms_count(struct tapi_handle *handle, tapi_response_cb callback, void* user_data)
775 {
776         struct tapi_resp_data *evt_cb_data = NULL;
777
778         dbg("Func Entrance ");
779
780         TAPI_RET_ERR_NUM_IF_FAIL(callback ,TAPI_API_INVALID_PTR);
781
782         MAKE_RESP_CB_DATA(evt_cb_data, handle, callback, user_data);
783
784         g_dbus_connection_call(handle->dbus_connection,
785                 DBUS_TELEPHONY_SERVICE , handle->path, DBUS_TELEPHONY_SMS_INTERFACE,
786                 "GetMsgCount", NULL, NULL,
787                 G_DBUS_CALL_FLAGS_NONE, -1, handle->ca,
788                 on_response_get_msg_count, evt_cb_data);
789
790         return TAPI_API_SUCCESS;
791 }
792
793
794 /**
795  *
796  * This function enables the applications to get the service center address from the SIM storage
797  *
798  * @return              Returns appropriate error code. Refer TapiResult_t .
799  * @param[in]           pSCA - the service center address that is to be set in the SIM storage
800  *                                          refer to 3GPP TS 23.040:9.1.2.5 Address fields
801  *                              index - the index that is to be set in the SIM storage
802  *
803  * @param[out]  RequestId-Unique identifier for a particular request
804  *                         Its value can be any value from 0 to 255 if the API is returned successfully
805  *                           -1 (INVALID_REQUEST_ID) will be sent in case of failure
806  * @Interface           Asynchronous.
807  * @remark
808  * @Refer              tapi_sms_sms_addr_info
809  */
810 EXPORT_API int tel_get_sms_sca(struct tapi_handle *handle, int index, tapi_response_cb callback, void* user_data)
811 {
812         struct tapi_resp_data *evt_cb_data = NULL;
813         GVariant *param;
814
815         dbg("Func Entrance ");
816
817         TAPI_RET_ERR_NUM_IF_FAIL(callback ,TAPI_API_INVALID_PTR);
818
819         if ((index < 0) || (index > TAPI_NETTEXT_MAX_INDEX)) {
820                 err("Invalid Index Input");
821                 return TAPI_API_INVALID_INPUT;
822         }
823
824         MAKE_RESP_CB_DATA(evt_cb_data, handle, callback, user_data);
825
826         param = g_variant_new("(i)", index);
827
828         g_dbus_connection_call(handle->dbus_connection,
829                 DBUS_TELEPHONY_SERVICE , handle->path, DBUS_TELEPHONY_SMS_INTERFACE,
830                 "GetSca", param, NULL,
831                 G_DBUS_CALL_FLAGS_NONE, -1, handle->ca,
832                 on_response_get_sca, evt_cb_data);
833
834         return TAPI_API_SUCCESS;
835 }
836
837
838 /**
839  *
840  * This function enables the applications to set the service center address in the SIM storage
841  *
842  * @return              Returns appropriate error code. Refer TapiResult_t .
843  * @param[in]           pSCA - the service center address that is to be set in the SIM storage
844  *                                          refer to 3GPP TS 23.040:9.1.2.5 Address fields
845  *                              index - the index that is to be set in the SIM storage
846  *
847  * @param[out]  RequestId-Unique identifier for a particular request
848  *                         Its value can be any value from 0 to 255 if the API is returned successfully
849  *                           -1 (INVALID_REQUEST_ID) will be sent in case of failure
850  * @Interface           ASynchronous.
851  * @remark
852  * @Refer              tapi_sms_sms_addr_info
853  */
854 EXPORT_API int tel_set_sms_sca(struct tapi_handle *handle, const TelSmsAddressInfo_t *pSCA, int index, tapi_response_cb callback, void* user_data)
855 {
856         struct tapi_resp_data *evt_cb_data = NULL;
857         GVariant *param;
858         gchar *encoded_sca = NULL;
859
860         dbg("Func Entrance ");
861
862         TAPI_RET_ERR_NUM_IF_FAIL(pSCA ,TAPI_API_INVALID_PTR);
863
864         if ((index < 0) || (index > TAPI_NETTEXT_MAX_INDEX)) {
865                 err("Invalid Index Input");
866                 return TAPI_API_INVALID_INPUT;
867         }
868
869         MAKE_RESP_CB_DATA(evt_cb_data, handle, callback, user_data);
870
871         encoded_sca = g_base64_encode(&(pSCA->szDiallingNum[0]), TAPI_SIM_SMSP_ADDRESS_LEN);
872         if (encoded_sca == NULL) {
873                 dbg("g_base64_encode: Failed to Enocde the SCA");
874                 return TAPI_API_OPERATION_FAILED;
875         }
876
877         param = g_variant_new("(iiiis)", index,
878                                                         pSCA->Ton,
879                                                         pSCA->Npi,
880                                                         pSCA->DialNumLen,
881                                                         encoded_sca);
882
883         g_dbus_connection_call(handle->dbus_connection,
884                 DBUS_TELEPHONY_SERVICE , handle->path, DBUS_TELEPHONY_SMS_INTERFACE,
885                 "SetSca", param, NULL,
886                 G_DBUS_CALL_FLAGS_NONE, -1, handle->ca,
887                 on_response_default, evt_cb_data);
888
889         g_free(encoded_sca);
890
891
892         return TAPI_API_SUCCESS;
893 }
894
895
896 /**
897  *
898  * This function enables the applications to set the configuration for cell broadcast messages
899  *
900  * @return              Returns appropriate error code. Refer TapiResult_t .
901  * @param[in]           None
902  *
903  * @param[out]  RequestId-Unique identifier for a particular request
904  *                         Its value can be any value from 0 to 255 if the API is returned successfully
905  *                           -1 (INVALID_REQUEST_ID) will be sent in case of failure
906  * @Interface           Asynchronous.
907  * @remark
908  * @Refer              None
909  */
910 EXPORT_API int tel_get_sms_cb_config(struct tapi_handle *handle, tapi_response_cb callback, void* user_data)
911 {
912         struct tapi_resp_data *evt_cb_data = NULL;
913
914         dbg("Func Entrance ");
915
916         TAPI_RET_ERR_NUM_IF_FAIL(callback ,TAPI_API_INVALID_PTR);
917
918         MAKE_RESP_CB_DATA(evt_cb_data, handle, callback, user_data);
919
920         g_dbus_connection_call(handle->dbus_connection,
921                 DBUS_TELEPHONY_SERVICE , handle->path, DBUS_TELEPHONY_SMS_INTERFACE,
922                 "GetCbConfig", NULL, NULL,
923                 G_DBUS_CALL_FLAGS_NONE, -1, handle->ca,
924                 on_response_get_cb_config, evt_cb_data);
925
926         return TAPI_API_SUCCESS;
927 }
928
929 /**
930  *
931  * This function enables the applications to set the configuration for cell broadcast messages
932  *
933  * @return              Returns appropriate error code. Refer TapiResult_t .
934  * @param[in]           tapi_sms_cb_config the configuration details to be set
935  *
936  * @param[out]  RequestId-Unique identifier for a particular request
937  *                         Its value can be any value from 0 to 255 if the API is returned successfully
938  *                           -1 (INVALID_REQUEST_ID) will be sent in case of failure
939  * @Interface           Asynchronous.
940  * @remark
941  * @Refer              tapi_sms_cb_config
942  */
943 EXPORT_API int tel_set_sms_cb_config(struct tapi_handle *handle, const TelSmsCbConfig_t *pCBConfig, tapi_response_cb callback, void* user_data)
944 {
945         struct tapi_resp_data *evt_cb_data = NULL;
946         GVariant *param;
947         gchar *encoded_cbConfig = NULL;
948
949         dbg("Func Entrance ");
950
951         TAPI_RET_ERR_NUM_IF_FAIL(pCBConfig ,TAPI_API_INVALID_PTR);
952
953         if ((pCBConfig->Net3gppType > 2) || (pCBConfig->MsgIdRangeCount < 0)) {
954                 err("Invalid Input -3gppType(%d)",pCBConfig->Net3gppType);
955                 err("Invalid Input -MsgIdRangeCount(%d)",pCBConfig->MsgIdRangeCount);
956
957                 return TAPI_API_INVALID_INPUT;
958         }
959
960         MAKE_RESP_CB_DATA(evt_cb_data, handle, callback, user_data);
961
962         encoded_cbConfig = g_base64_encode((const guchar *)&(pCBConfig->MsgIDs[0]), TAPI_NETTEXT_GSM_SMS_CBMI_LIST_SIZE_MAX*5);
963         if (encoded_cbConfig == NULL) {
964                 dbg("g_base64_encode: Failed to Enocde the CB Config");
965                 return TAPI_API_OPERATION_FAILED;
966         }
967
968         param = g_variant_new("(iiiis)", pCBConfig->Net3gppType,
969                                                         pCBConfig->CBEnabled,
970                                                         pCBConfig->MsgIdMaxCount,
971                                                         pCBConfig->MsgIdRangeCount,
972                                                         encoded_cbConfig);
973
974         g_dbus_connection_call(handle->dbus_connection,
975                 DBUS_TELEPHONY_SERVICE , handle->path, DBUS_TELEPHONY_SMS_INTERFACE,
976                 "SetCbConfig", param, NULL,
977                 G_DBUS_CALL_FLAGS_NONE, -1, handle->ca,
978                 on_response_default, evt_cb_data);
979
980         g_free(encoded_cbConfig);
981
982         return TAPI_API_SUCCESS;
983 }
984
985 /**
986  *
987  * This function enables the applications to set the phone memory status whether full or available
988  *
989  * @return              Returns appropriate error code. Refer TapiResult_t .
990  * @param[in]           memory_status whether full or available
991  *
992  * @param[out]  RequestId-Unique identifier for a particular request
993  *                         Its value can be any value from 0 to 255 if the API is returned successfully
994  *                           -1 (INVALID_REQUEST_ID) will be sent in case of failure
995  * @Interface           Asynchronous.
996  * @remark
997  * @Refer              tapi_sms_memstatus_type
998  */
999 EXPORT_API int tel_set_sms_memory_status(struct tapi_handle *handle, int memoryStatus, tapi_response_cb callback, void* user_data)
1000 {
1001         struct tapi_resp_data *evt_cb_data = NULL;
1002         GVariant *param;
1003
1004         dbg("Func Entrance ");
1005
1006         if ((memoryStatus < TAPI_NETTEXT_PDA_MEMORY_STATUS_AVAILABLE) || (memoryStatus > TAPI_NETTEXT_PDA_MEMORY_STATUS_FULL)) {
1007                 err("Invalid Input -MemoryStatus Nettext");
1008                 return TAPI_API_INVALID_INPUT;
1009         }
1010
1011         MAKE_RESP_CB_DATA(evt_cb_data, handle, callback, user_data);
1012
1013         param = g_variant_new("(i)", memoryStatus);
1014
1015         g_dbus_connection_call(handle->dbus_connection,
1016                 DBUS_TELEPHONY_SERVICE , handle->path, DBUS_TELEPHONY_SMS_INTERFACE,
1017                 "SetMemStatus", param, NULL,
1018                 G_DBUS_CALL_FLAGS_NONE, -1, handle->ca,
1019                 on_response_default, evt_cb_data);
1020
1021         return TAPI_API_SUCCESS;
1022 }
1023
1024 /**
1025  *
1026  * This function is used to get SMS preferred bearer on which SMS has to be transmitted. This is a synchronous function
1027  *
1028  * @return              TRUE in case of success and FALSE in case of error .
1029  * @param[in]        None
1030  *
1031  * @param[out]  requestId-Unique identifier for a particular request
1032  *                          Its value can be any value from 0 to 255 if the API is returned successfully
1033  *                           -1 (INVALID_REQUEST_ID) will be sent in case of failure
1034  * @Interface           Asynchronous.
1035  * @remark
1036  * @Refer
1037  */
1038 EXPORT_API int tel_get_sms_preferred_bearer(struct tapi_handle *handle, tapi_response_cb callback, void* user_data)
1039 {
1040         struct tapi_resp_data *evt_cb_data = NULL;
1041
1042         dbg("Func Entrance ");
1043
1044         TAPI_RET_ERR_NUM_IF_FAIL(callback ,TAPI_API_INVALID_PTR);
1045
1046         MAKE_RESP_CB_DATA(evt_cb_data, handle, callback, user_data);
1047
1048         g_dbus_connection_call(handle->dbus_connection,
1049                 DBUS_TELEPHONY_SERVICE , handle->path, DBUS_TELEPHONY_SMS_INTERFACE,
1050                 "GetPrefBearer", NULL, NULL,
1051                 G_DBUS_CALL_FLAGS_NONE, -1, handle->ca,
1052                 on_response_default, evt_cb_data);
1053
1054         return TAPI_API_SUCCESS;
1055 }
1056
1057 /**
1058  *
1059  * This function enables the applications to set the preferred bearer
1060  *
1061  * @return              Returns appropriate error code. Refer TapiResult_t .
1062  * @param[in]           service option ie the bearer type to be set
1063  *
1064  * @param[out]  RequestId-Unique identifier for a particular request
1065  *                         Its value can be any value from 0 to 255 if the API is returned successfully
1066  *                           -1 (INVALID_REQUEST_ID) will be sent in case of failure
1067  * @Interface           Asynchronous.
1068  * @remark
1069  * @Refer              tapi_sms_bearer_type
1070  */
1071 EXPORT_API int tel_set_sms_preferred_bearer(struct tapi_handle *handle, TelSmsBearerType_t BearerType, tapi_response_cb callback, void* user_data)
1072 {
1073         struct tapi_resp_data *evt_cb_data = NULL;
1074         GVariant *param;
1075
1076         dbg("Func Entrance ");
1077
1078         if ((TAPI_NETTEXT_BEARER_PS_ONLY > BearerType) || (TAPI_NETTEXT_NO_PREFERRED_BEARER < BearerType)) {
1079                 err("Invalid Input -PrefBearer Set Nettext");
1080                 return TAPI_API_INVALID_INPUT;
1081         }
1082
1083         MAKE_RESP_CB_DATA(evt_cb_data, handle, callback, user_data);
1084
1085         param = g_variant_new("(i)", BearerType);
1086
1087         g_dbus_connection_call(handle->dbus_connection,
1088                 DBUS_TELEPHONY_SERVICE , handle->path, DBUS_TELEPHONY_SMS_INTERFACE,
1089                 "SetPrefBearer", param, NULL,
1090                 G_DBUS_CALL_FLAGS_NONE, -1, handle->ca,
1091                 on_response_default, evt_cb_data);
1092
1093         return TAPI_API_SUCCESS;
1094 }
1095
1096 /**
1097  *
1098  * This function enables the applications to set the deliver report for an incoming message(MT).
1099  *
1100  * @return              Returns appropriate error code. Refer TapiResult_t .
1101  * @param[in]          pDataPackage - SMS-DELIVER-REPORT, and its length have to be passed in this structure.
1102  * @param[in]           RPCause - the result cause
1103  *
1104  * @param[out]  RequestId-Unique identifier for a particular request
1105  *                         Its value can be any value from 0 to 255 if the API is returned successfully
1106  *                           -1 (INVALID_REQUEST_ID) will be sent in case of failure
1107  * @Interface           Synchronous.
1108  * @remark
1109  * @Refer              tapi_sms_deliver_report
1110  */
1111 EXPORT_API int tel_send_sms_deliver_report(struct tapi_handle *handle,
1112                 const TelSmsDatapackageInfo_t *pDataPackage,
1113                 TelSmsResponse_t RPCause,
1114                 tapi_response_cb callback, void* user_data)
1115 {
1116         struct tapi_resp_data *evt_cb_data = NULL;
1117         GVariant *param;
1118         gchar *encoded_sca = NULL;
1119         gchar *encoded_tpdu = NULL;
1120
1121         dbg("Func Entrance ");
1122
1123         TAPI_RET_ERR_NUM_IF_FAIL(pDataPackage ,TAPI_API_INVALID_PTR);
1124
1125         MAKE_RESP_CB_DATA(evt_cb_data, handle, callback, user_data);
1126
1127         encoded_sca = g_base64_encode(&(pDataPackage->Sca[0]), TAPI_SMS_ENCODED_SCA_LEN_MAX);
1128         if (encoded_sca == NULL) {
1129                 dbg("g_base64_encode: Failed to Enocde the SCA");
1130                 return TAPI_API_OPERATION_FAILED;
1131         }
1132
1133         encoded_tpdu = g_base64_encode(&(pDataPackage->szData[0]), TAPI_NETTEXT_SMDATA_SIZE_MAX + 1);
1134         if (encoded_tpdu == NULL) {
1135                 dbg("g_base64_encode: Failed to Enocde the TPDU");
1136                 return TAPI_API_OPERATION_FAILED;
1137         }
1138
1139         param = g_variant_new("(sisi)", encoded_sca,
1140                                                         pDataPackage->MsgLength,
1141                                                         encoded_tpdu,
1142                                                         RPCause);
1143
1144         g_dbus_connection_call(handle->dbus_connection,
1145                 DBUS_TELEPHONY_SERVICE , handle->path, DBUS_TELEPHONY_SMS_INTERFACE,
1146                 "SetDeliveryReport", param, NULL,
1147                 G_DBUS_CALL_FLAGS_NONE, -1, handle->ca,
1148                 on_response_default, evt_cb_data);
1149
1150         g_free(encoded_sca);
1151         g_free(encoded_tpdu);
1152
1153         return TAPI_API_SUCCESS;
1154 }
1155
1156 /**
1157  *
1158  * This function enables the application to set the status of a message
1159  *
1160  * @return              Returns appropriate error code. Refer TapiResult_t .
1161  * @param[in]           index - the message to be changed
1162  *                              msgStatus -SMS message status
1163  *
1164  * @param[out]  RequestId-Unique identifier for a particular request
1165  *                         Its value can be any value from 0 to 255 if the API is returned successfully
1166  *                           -1 (INVALID_REQUEST_ID) will be sent in case of failure
1167  * @Interface           Asynchronous.
1168  * @remark
1169  * @Refer              tapi_sms_memory_type,tapi_sms_status_type
1170  */
1171 EXPORT_API int tel_set_sms_message_status(struct tapi_handle *handle, int index, TelSmsMsgStatus_t msgStatus, tapi_response_cb callback, void* user_data)
1172 {
1173         struct tapi_resp_data *evt_cb_data = NULL;
1174         GVariant *param;
1175
1176         dbg("Func Entrance ");
1177
1178         if ((index < 0) || (index > TAPI_NETTEXT_MAX_INDEX) ||
1179                 (msgStatus > TAPI_NETTEXT_STATUS_RESERVED)) {
1180                 err("Invalid Input -MsgStatus Set Nettext");
1181                 return TAPI_API_INVALID_INPUT;
1182         }
1183
1184         MAKE_RESP_CB_DATA(evt_cb_data, handle, callback, user_data);
1185
1186         param = g_variant_new("(ii)", index, msgStatus);
1187
1188         g_dbus_connection_call(handle->dbus_connection,
1189                 DBUS_TELEPHONY_SERVICE , handle->path, DBUS_TELEPHONY_SMS_INTERFACE,
1190                 "SetMsgStatus", param, NULL,
1191                 G_DBUS_CALL_FLAGS_NONE, -1, handle->ca,
1192                 on_response_default, evt_cb_data);
1193
1194         return TAPI_API_SUCCESS;
1195 }
1196
1197 /**
1198  *
1199  * This function enables to application to get the sms parameters
1200  *
1201  * @return              Returns appropriate error code. Refer TapiResult_t .
1202  * @param[in]           record index of the record in which the sms parameters are stored in the EFsmsp file
1203  *
1204  * @param[out]  RequestId-Unique identifier for a particular request
1205  *                         Its value can be any value from 0 to 255 if the API is returned successfully
1206  *                           -1 (INVALID_REQUEST_ID) will be sent in case of failure
1207  * @Interface           ASynchronous.
1208  * @remark              Requested details come in response API
1209  * @Refer
1210  */
1211 EXPORT_API int tel_get_sms_parameters(struct tapi_handle *handle, int index, tapi_response_cb callback, void* user_data)
1212 {
1213         struct tapi_resp_data *evt_cb_data = NULL;
1214         GVariant *param;
1215
1216         dbg("Func Entrance ");
1217
1218         TAPI_RET_ERR_NUM_IF_FAIL(callback ,TAPI_API_INVALID_PTR);
1219
1220         if ((index < 0) || (index > TAPI_NETTEXT_MAX_INDEX)) {
1221                 err("Invalid Input -SMS Param Get Nettext");
1222                 return TAPI_API_INVALID_INPUT;
1223         }
1224
1225         MAKE_RESP_CB_DATA(evt_cb_data, handle, callback, user_data);
1226
1227         param = g_variant_new("(i)", index);
1228
1229         g_dbus_connection_call(handle->dbus_connection,
1230                 DBUS_TELEPHONY_SERVICE , handle->path, DBUS_TELEPHONY_SMS_INTERFACE,
1231                 "GetSmsParams", param, NULL,
1232                 G_DBUS_CALL_FLAGS_NONE, -1, handle->ca,
1233                 on_response_get_sms_params, evt_cb_data);
1234
1235         return TAPI_API_SUCCESS;
1236 }
1237
1238 /**
1239  *
1240  * This function enables to application to get the sms parameters
1241  *
1242  * @return              Returns appropriate error code. Refer TapiResult_t .
1243  * @param[in]           tapi_smsp_set_param_t sms parameters to be set in the EFsmsp file
1244  *
1245  * @param[out]  RequestId-Unique identifier for a particular request
1246  *                         Its value can be any value from 0 to 255 if the API is returned successfully
1247  *                           -1 (INVALID_REQUEST_ID) will be sent in case of failure
1248  * @Interface           ASynchronous.
1249  * @remark
1250  * @Refer              tapi_smsp_set_param_t
1251  */
1252 EXPORT_API int tel_set_sms_parameters(struct tapi_handle *handle, const TelSmsParams_t *pSmsSetParameters, tapi_response_cb callback, void* user_data)
1253 {
1254         struct tapi_resp_data *evt_cb_data = NULL;
1255         GVariant *param;
1256         gchar *encoded_alphaId = NULL;
1257         gchar *encoded_destDialNum = NULL;
1258         gchar *encoded_scaDialNum = NULL;
1259
1260         dbg("Func Entrance ");
1261
1262         TAPI_RET_ERR_NUM_IF_FAIL(pSmsSetParameters ,TAPI_API_INVALID_PTR);
1263
1264         MAKE_RESP_CB_DATA(evt_cb_data, handle, callback, user_data);
1265
1266         encoded_alphaId = g_base64_encode((guchar *)&(pSmsSetParameters->szAlphaId[0]), TAPI_SIM_SMSP_ALPHA_ID_LEN_MAX + 1);
1267         if (encoded_alphaId == NULL) {
1268                 dbg("g_base64_encode: Failed to Enocde the AlphaId");
1269                 return TAPI_API_OPERATION_FAILED;
1270         }
1271
1272         encoded_destDialNum = g_base64_encode(&(pSmsSetParameters->TpDestAddr.szDiallingNum[0]), TAPI_SIM_SMSP_ADDRESS_LEN + 1);
1273         if (encoded_destDialNum == NULL) {
1274                 dbg("g_base64_encode: Failed to Enocde the DestAddr.DiallingNum");
1275                 return TAPI_API_OPERATION_FAILED;
1276         }
1277
1278         encoded_scaDialNum = g_base64_encode(&(pSmsSetParameters->TpSvcCntrAddr.szDiallingNum[0]), TAPI_SIM_SMSP_ADDRESS_LEN + 1);
1279         if (encoded_scaDialNum == NULL) {
1280                 dbg("g_base64_encode: Failed to Enocde the ScaAddr.DiallingNum");
1281                 return TAPI_API_OPERATION_FAILED;
1282         }
1283
1284         param = g_variant_new("(iiisiiiisiiisiii)", pSmsSetParameters->RecordIndex,
1285                                                                         pSmsSetParameters->RecordLen,
1286                                                                         pSmsSetParameters->AlphaIdLen,
1287                                                                         encoded_alphaId,
1288                                                                         pSmsSetParameters->ParamIndicator,
1289                                                                         pSmsSetParameters->TpDestAddr.DialNumLen,
1290                                                                         pSmsSetParameters->TpDestAddr.Ton,
1291                                                                         pSmsSetParameters->TpDestAddr.Npi,
1292                                                                         encoded_destDialNum,
1293                                                                         pSmsSetParameters->TpSvcCntrAddr.DialNumLen,
1294                                                                         pSmsSetParameters->TpSvcCntrAddr.Ton,
1295                                                                         pSmsSetParameters->TpSvcCntrAddr.Npi,
1296                                                                         encoded_scaDialNum,
1297                                                                         pSmsSetParameters->TpProtocolId,
1298                                                                         pSmsSetParameters->TpDataCodingScheme,
1299                                                                         pSmsSetParameters->TpValidityPeriod);
1300
1301         g_dbus_connection_call(handle->dbus_connection,
1302                 DBUS_TELEPHONY_SERVICE , handle->path, DBUS_TELEPHONY_SMS_INTERFACE,
1303                 "SetSmsParams", param, NULL,
1304                 G_DBUS_CALL_FLAGS_NONE, -1, handle->ca,
1305                 on_response_default, evt_cb_data);
1306
1307         g_free(encoded_alphaId);
1308         g_free(encoded_destDialNum);
1309         g_free(encoded_scaDialNum);
1310
1311         return TAPI_API_SUCCESS;
1312 }
1313
1314 /**
1315  *
1316  * This function enables to application to get the sms parameter count from the EFsmsp file.
1317  *
1318  * @return              Returns appropriate error code. Refer TapiResult_t .
1319  * @param[in]           None
1320  *
1321  * @param[out]  RequestId-Unique identifier for a particular request
1322  *                         Its value can be any value from 0 to 255 if the API is returned successfully
1323  *                           -1 (INVALID_REQUEST_ID) will be sent in case of failure
1324  * @Interface           ASynchronous.
1325  * @remark              Requested details come in response API
1326  * @Refer
1327  */
1328 EXPORT_API int tel_get_sms_parameter_count(struct tapi_handle *handle, tapi_response_cb callback, void* user_data)
1329 {
1330         struct tapi_resp_data *evt_cb_data = NULL;
1331
1332         dbg("Func Entrance ");
1333
1334         TAPI_RET_ERR_NUM_IF_FAIL(callback ,TAPI_API_INVALID_PTR);
1335
1336         MAKE_RESP_CB_DATA(evt_cb_data, handle, callback, user_data);
1337
1338         g_dbus_connection_call(handle->dbus_connection,
1339                 DBUS_TELEPHONY_SERVICE , handle->path, DBUS_TELEPHONY_SMS_INTERFACE,
1340                 "GetSmsParamCnt", NULL, NULL,
1341                 G_DBUS_CALL_FLAGS_NONE, -1, handle->ca,
1342                 on_response_get_sms_param_cnt, evt_cb_data);
1343
1344         return TAPI_API_SUCCESS;
1345 }
1346
1347 #if 0
1348 /**
1349  *
1350  *  This API is used to send an SMS message to the network. This API allows keeping
1351  *  the dedicated link at lower layers by passing information as more messages to send in parameters.
1352  * This will enable not to release if a dedicated connection is used for transmission.
1353  *
1354  * @return              TRUE in case of success and FALSE in case of error .
1355  * @param[in]           TelSmsMsgInfo_t - SMS_SUBMIT/ACK/CANCEL and its length have to be passed in this structure.
1356  *
1357  *                              unsigned int MoreMsgToSend will be set to TRUE when there are more than one message to be
1358  *                         send or Multiple segmented concatenated message to be send, otherwise FALSE. This flag
1359  *                         indicates OEM that more messages to send.
1360  *
1361  * @param[out]  RequestId-Unique identifier for a particular request
1362  *                         Its value can be any value from 0 to 255 if the API is returned successfully
1363  *                           -1 (INVALID_REQUEST_ID) will be sent in case of failure
1364  *
1365  * @Interface           Asynchronous.
1366  * @remark
1367  * @Refer               TelSmsMsgInfo_t.
1368  */
1369 EXPORT_API int tel_send_sms_msg(struct tapi_handle *handle, const TelSmsMsgInfo_t *pSmsMsgInfo, unsigned int MoreMsgToSend, tapi_response_cb callback, void* user_data)
1370 {
1371         struct tapi_resp_data *evt_cb_data = NULL;
1372         GVariant *param;
1373
1374         dbg("Func Entrance ");
1375
1376         MAKE_RESP_CB_DATA(evt_cb_data, handle, callback, user_data);
1377         TS_BOOL ret = FALSE;
1378         int api_err = TAPI_API_SUCCESS;
1379         int emergency_mode = 0;
1380
1381         if (vconf_get_int("db/telephony/emergency", &emergency_mode) != 0) {
1382                 TAPI_LIB_DEBUG(LEVEL_ERR, "[FAIL]GET db/telephony/emergency");
1383                 return TAPI_API_OPERATION_FAILED;
1384         }
1385         if (emergency_mode) {
1386                 TAPI_LIB_DEBUG(LEVEL_DEBUG, "emergency mode on");
1387                 return TAPI_API_OPERATION_FAILED;
1388         }
1389
1390         TAPI_RET_ERR_NUM_IF_FAIL(pSmsMsgInfo ,TAPI_API_INVALID_PTR);
1391
1392         if (conn_name.length_of_name == 0) {
1393                 TAPI_LIB_DEBUG(LEVEL_ERR, "No dbus connection name");
1394                 return TAPI_API_OPERATION_FAILED;
1395         }
1396
1397         TAPI_RET_ERR_NUM_IF_FAIL(tapi_check_dbus_status(), TAPI_API_SYSTEM_RPC_LINK_NOT_EST);
1398         TAPI_GLIB_INIT_PARAMS();
1399
1400         TAPI_GLIB_ALLOC_PARAMS(in_param1,in_param2,in_param3,in_param4,
1401                         out_param1,out_param2,out_param3,out_param4);
1402
1403         g_array_append_vals(in_param1, pSmsMsgInfo, sizeof(TelSmsMsgInfo_t));
1404         g_array_append_vals(in_param2, &MoreMsgToSend, sizeof(unsigned int));
1405         g_array_append_vals(in_param4, &conn_name, sizeof(tapi_dbus_connection_name));
1406
1407         ret = tapi_send_request(TAPI_CS_SERVICE_NETTEXT, TAPI_CS_NETTEXT_SEND_EX, in_param1, in_param2, in_param3,
1408                         in_param4, &out_param1, &out_param2, &out_param3, &out_param4);
1409
1410         if (ret) {
1411                 api_err = g_array_index(out_param1, int, 0);
1412         }
1413         else {
1414                 api_err = TAPI_API_SYSTEM_RPC_LINK_DOWN;
1415         }
1416
1417         TAPI_GLIB_FREE_PARAMS(in_param1,in_param2,in_param3,in_param4,
1418                         out_param1,out_param2,out_param3,out_param4);
1419
1420         return api_err;
1421 }
1422 #endif
1423
1424 /**
1425  *
1426  * This function enables the applications to check the device status
1427  *
1428  * @return              Returns appropriate error code. Refer TapiResult_t .
1429  * @param[in]           None
1430  *
1431  *
1432  * @param[out]  Device status whether Ready or Not Ready
1433  * @Interface           Synchronous.
1434  * @remark
1435  * @Refer
1436  */
1437 EXPORT_API int tel_check_sms_device_status(struct tapi_handle *handle, int *pReadyStatus)
1438 {
1439         GError *error;
1440         GVariant *smsReady = NULL;
1441
1442         dbg("Func Entrance ");
1443
1444         TAPI_RET_ERR_NUM_IF_FAIL(handle, TAPI_API_INVALID_PTR);
1445         TAPI_RET_ERR_NUM_IF_FAIL(pReadyStatus, TAPI_API_INVALID_PTR);
1446
1447         memset(pReadyStatus, 0, sizeof(int));
1448
1449         error = NULL;
1450         smsReady = g_dbus_connection_call_sync(handle->dbus_connection, DBUS_TELEPHONY_SERVICE , handle->path,
1451                         DBUS_TELEPHONY_SMS_INTERFACE, "GetSmsReadyStatus", NULL, NULL, G_DBUS_CALL_FLAGS_NONE, -1, NULL, &error);
1452
1453         if(!smsReady){
1454                 dbg( "error to get SMS ready_status(%s)", error->message);
1455                 g_error_free (error);
1456                 return TAPI_API_OPERATION_FAILED;
1457         }
1458
1459         dbg("get SMS ready_status type_format(%s)", g_variant_get_type_string(smsReady));
1460
1461         g_variant_get(smsReady, "(b)", pReadyStatus);
1462
1463         dbg("************SMS_device_status (%d)", *pReadyStatus);
1464
1465         return TAPI_API_SUCCESS;
1466 }
1467
1468 #if 0
1469 /**
1470  *
1471  * This function enables to application to set that the device is ready to recieve messages from network.
1472  *
1473  * @return              Returns appropriate error code. Refer TapiResult_t .
1474  * @param[in]           None
1475  *
1476  * @param[out]  None
1477  * @Interface           Synchronous.
1478  * @remark
1479  * @Refer
1480  */
1481 EXPORT_API int tel_set_sms_device_status(struct tapi_handle *handle)
1482 {
1483         struct tapi_resp_data *evt_cb_data = NULL;
1484         GVariant *param;
1485
1486         dbg("Func Entrance ");
1487
1488         MAKE_RESP_CB_DATA(evt_cb_data, handle, callback, user_data);
1489
1490         TS_BOOL ret = FALSE;
1491         int api_err = TAPI_API_SUCCESS;
1492
1493         TAPI_RET_ERR_NUM_IF_FAIL(tapi_check_dbus_status_internal(), TAPI_API_SYSTEM_RPC_LINK_NOT_EST);
1494         TAPI_GLIB_INIT_PARAMS();
1495         TAPI_GLIB_ALLOC_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param1, out_param2, out_param3, out_param4);
1496
1497         ret = tapi_send_request_internal(TAPI_CS_SERVICE_NETTEXT, TAPI_CS_NETTEXT_DEVICEREADY,
1498                         in_param1, in_param2, in_param3, in_param4,
1499                         &out_param1, &out_param2, &out_param3, &out_param4);
1500
1501         if (ret) {
1502                 api_err = g_array_index(out_param1, int, 0);
1503         }
1504         else {
1505                 api_err = TAPI_API_SYSTEM_RPC_LINK_DOWN;
1506         }
1507
1508         TAPI_GLIB_FREE_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param1, out_param2, out_param3, out_param4);
1509
1510         return api_err;
1511 }
1512 #endif
1513 //eof