release tizen_2.0 beta
[framework/telephony/libslp-tapi.git] / src / tapi_common.c
1 /*
2  * libslp-tapi
3  *
4  * Copyright (c) 2012 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 #include <stdio.h>
22 #include <stdlib.h>
23 #include <string.h>
24
25 #include <glib.h>
26 #include <glib-object.h>
27 #include <gio/gio.h>
28
29 #include "tapi_common.h"
30 #include "TapiUtility.h"
31
32 //
33 #include "ITapiPS.h"
34 #include "TelNetwork.h"
35 #include "TelSms.h"
36 #include "TelSat.h"
37 #include "TelSs.h"
38 #include "TelCall.h"
39
40 //
41 #include "common.h"
42 #include "tapi_log.h"
43
44 extern char *g_cookie_name;
45 extern int g_cookie_size;
46
47 TelSatEventDownloadType_t g_event_list[TAPI_SAT_EVENT_LIST_MAX_COUNT] = {-1};
48
49 /*static void _cookie_deinit(void)
50 {
51         if (g_cookie_name)
52                 free(g_cookie_name);
53
54         g_cookie_name = NULL;
55         g_cookie_size = 0;
56 }*/
57
58 static void on_signal_callback(GDBusConnection *conn, const gchar *name, const gchar *path, const gchar *interface,
59                 const gchar *sig, GVariant *param, gpointer user_data)
60 {
61         TapiHandle *handle = user_data;
62         struct tapi_evt_cb *evt_cb_data = NULL;
63         char *noti_id;
64         void *noti_data = NULL;
65
66         if (!handle) {
67                 dbg("handle is NULL");
68                 return;
69         }
70
71         noti_id = g_strdup_printf("%s:%s", interface, sig);
72
73         evt_cb_data = g_hash_table_lookup(handle->evt_list, noti_id);
74         if (!evt_cb_data) {
75                 dbg("can't find noti_id(%s) callback info", noti_id);
76                 g_free(noti_id);
77                 return;
78         }
79
80         if (!g_strcmp0(interface, DBUS_TELEPHONY_NETWORK_INTERFACE)) {
81                 if (!g_strcmp0(sig, "RegistrationStatus")) {
82                         struct tel_noti_network_registration_status noti;
83
84                         g_variant_get(param, "(iiib)", &noti.cs, &noti.ps, &noti.type, &noti.is_roaming);
85                         noti_data = &noti;
86                 }
87                 else if (!g_strcmp0(sig, "Info")) {
88                         struct tel_noti_network_info noti;
89
90                         memset(&noti, 0, sizeof(struct tel_noti_network_info));
91                         g_variant_get(param, "(ii)", &noti.rssi, &noti.battery);
92
93                         noti_data = &noti;
94                 }
95                 else if (!g_strcmp0(sig, "CellInfo")) {
96                         struct tel_noti_network_cell_info noti;
97
98                         memset(&noti, 0, sizeof(struct tel_noti_network_cell_info));
99                         g_variant_get(param, "(ii)", &noti.lac, &noti.cell_id);
100
101                         noti_data = &noti;
102                 }
103                 else if (!g_strcmp0(sig, "Change")) {
104                         struct tel_noti_network_change noti;
105                         char *plmn = NULL;
106
107                         memset(&noti, 0, sizeof(struct tel_noti_network_change));
108
109                         g_variant_get(param, "(isi)", &noti.act, &plmn, &noti.lac);
110
111                         if (plmn) {
112                                 snprintf(noti.plmn, 7, "%s", plmn);
113                         }
114
115                         noti_data = &noti;
116                 }
117                 else if (!g_strcmp0(sig, "TimeInfo")) {
118                         struct tel_noti_network_time_info noti;
119                         char *plmn = NULL;
120
121                         memset(&noti, 0, sizeof(struct tel_noti_network_time_info));
122                         g_variant_get(param, "(iiiiiiiiibs)", &noti.year, &noti.month, &noti.day,
123                                         &noti.hour, &noti.minute, &noti.second,
124                                         &noti.wday, &noti.gmtoff, &noti.dstoff, &noti.isdst,
125                                         &plmn);
126
127                         if (plmn) {
128                                 snprintf(noti.plmn, 7, "%s", plmn);
129                         }
130
131                         noti_data = &noti;
132                 }
133                 else if (!g_strcmp0(sig, "Identity")) {
134                         struct tel_noti_network_identity noti;
135                         char *plmn = NULL, *s_name = NULL, *f_name = NULL;
136
137                         memset(&noti, 0, sizeof(struct tel_noti_network_identity));
138
139                         g_variant_get(param, "(sss)", &plmn, &s_name, &f_name);
140
141                         if (plmn) {
142                                 snprintf(noti.plmn, 7, "%s", plmn);
143                         }
144                         if (s_name) {
145                                 snprintf(noti.short_name, 17, "%s", s_name);
146                         }
147                         if (f_name) {
148                                 snprintf(noti.full_name, 33, "%s", f_name);
149                         }
150
151                         noti_data = &noti;
152                 }
153         }
154
155         if (!g_strcmp0(interface, DBUS_TELEPHONY_SMS_INTERFACE)) {
156                 if (!g_strcmp0(sig, "IncommingMsg")) {
157                         struct tel_noti_sms_incomming_msg noti;
158
159                         const char *sca = NULL;
160                         const char *tpdu = NULL;
161                         gsize length;
162                         guchar *decoded_sca = NULL;
163                         guchar *decoded_tpdu = NULL;
164
165                         memset(&noti, 0, sizeof(struct tel_noti_sms_incomming_msg));
166
167                         g_variant_get(param, "(sis)", &sca, &noti.MsgLength, &tpdu);
168
169                         decoded_sca = g_base64_decode(sca, &length);
170                         memcpy(&(noti.Sca[0]), decoded_sca, TAPI_SIM_SMSP_ADDRESS_LEN);
171
172                         decoded_tpdu = g_base64_decode(tpdu, &length);
173                         memcpy(&(noti.szData[0]), decoded_tpdu, TAPI_NETTEXT_SMDATA_SIZE_MAX + 1);
174
175                         noti_data = &noti;
176
177                         if(decoded_sca)
178                                 g_free(decoded_sca);
179
180                         if(decoded_tpdu)
181                                 g_free(decoded_tpdu);
182
183                 }
184                 else if (!g_strcmp0(sig, "IncommingCbMsg")) {
185                         struct tel_noti_sms_incomming_cb_msg noti;
186
187                         const char *cbMsg = NULL;
188                         gsize length;
189                         guchar *decoded_cbMsg = NULL;
190
191                         memset(&noti, 0, sizeof(struct tel_noti_sms_incomming_cb_msg));
192                         g_variant_get(param, "(iis)", &noti.CbMsgType, &noti.Length, &cbMsg);
193
194                         decoded_cbMsg = g_base64_decode(cbMsg, &length);
195                         memcpy(&(noti.szMsgData[0]), decoded_cbMsg, TAPI_NETTEXT_CB_PAGE_SIZE_MAX + 1);
196
197                         noti_data = &noti;
198
199                         if(decoded_cbMsg)
200                                 g_free(decoded_cbMsg);
201
202                 }
203                 else if (!g_strcmp0(sig, "MemoryStatus")) {
204                         int noti = 0;
205
206                         g_variant_get(param, "(i)", &noti);
207                         noti_data = &noti;
208                 }
209                 else if (!g_strcmp0(sig, "SmsReady")) {
210                         gboolean noti = 0;
211
212                         g_variant_get(param, "(b)", &noti);
213                         noti_data = &noti;
214                 }
215         }
216
217         if (!g_strcmp0(interface, DBUS_TELEPHONY_CALL_INTERFACE)) {
218                 if (!g_strcmp0(sig, "VoiceCallStatusIdle") || !g_strcmp0(sig, "VideoCallStatusIdle") ) {
219                         TelCallStatusIdleNoti_t data;
220                         int start_time = 0, end_time = 0;
221                         g_variant_get(param, "(iiii)", &data.id, &data.cause, &start_time, &end_time);
222                         dbg("[ check ] %s : call_id(%d), end_cause(0x%x)", "Status Idle noti", data.id, data.cause);
223                         noti_data = &data;
224                 }
225                 if (!g_strcmp0(sig, "VoiceCallStatusDialing") || !g_strcmp0(sig, "VideoCallStatusDialing")) {
226                         TelCallStatusDialingNoti_t data;
227                         g_variant_get(param, "(i)", &data.id);
228                         dbg("[ check ] %s : call_id(%d)", "Status Dialing noti", data.id);
229                         noti_data = &data;
230                 }
231                 if (!g_strcmp0(sig, "VoiceCallStatusAlert") || !g_strcmp0(sig, "VideoCallStatusAlert")) {
232                         TelCallStatusAlertNoti_t data;
233                         g_variant_get(param, "(i)", &data.id);
234                         dbg("[ check ] %s : call_id(%d)", "Status Alert noti", data.id);
235                         noti_data = &data;
236                 }
237                 if (!g_strcmp0(sig, "VoiceCallStatusActive") || !g_strcmp0(sig, "VideoCallStatusActive")) {
238                         TelCallStatusActiveNoti_t data;
239                         g_variant_get(param, "(i)", &data.id);
240                         dbg("[ check ] %s : call_id(%d)", "Status Active noti", data.id);
241                         noti_data = &data;
242                 }
243                 if (!g_strcmp0(sig, "VoiceCallStatusHeld") ) {
244                         TelCallStatusHeldNoti_t data;
245                         g_variant_get(param, "(i)", &data.id);
246                         dbg("[ check ] %s : call_id(%d)", "Status Held noti", data.id);
247                         noti_data = &data;
248                 }
249                 if (!g_strcmp0(sig, "VoiceCallStatusIncoming") || !g_strcmp0(sig, "VideoCallStatusIncoming")) {
250                         TelCallStatusIncomingNoti_t data;
251                         g_variant_get(param, "(i)", &data.id);
252                         dbg("[ check ] %s : call_id(%d)", "Status Incoming noti", data.id);
253                         noti_data = &data;
254                 }
255                 if (!g_strcmp0(sig, "Waiting")) {
256                         TelCallInfoWaitingNoti_t data;
257                         g_variant_get(param, "(i)", &data.id);
258                         dbg("[ check ] %s : data.id(%d)", "Call Info Waiting noti", data.id);
259                         noti_data = &data.id;
260                 }
261                 if (!g_strcmp0(sig, "Forwarded")) {
262                         TelCallInfoForwardedNoti_t data;
263                         g_variant_get(param, "(i)", &data.id);
264                         dbg("[ check ] %s : data.id(%d)", "Call Info Forwarded noti", data.id);
265                         noti_data = &data.id;
266                 }
267                 if (!g_strcmp0(sig, "BarredIncoming")) {
268                         TelCallInfoBarredIncomingNoti_t data;
269                         g_variant_get(param, "(i)", &data.id);
270                         dbg("[ check ] %s : data.id(%d)", "Call Info Barred Incoming noti", data.id);
271                         noti_data = &data.id;
272                 }
273                 if (!g_strcmp0(sig, "BarredOutgoing")) {
274                         TelCallInfoBarredOutgoingNoti_t data;
275                         g_variant_get(param, "(i)", &data.id);
276                         dbg("[ check ] %s : data.id(%d)", "Call Info Barred Outgoing noti", data.id);
277                         noti_data = &data.id;
278                 }
279                 if (!g_strcmp0(sig, "ForwardConditional")) {
280                         TelCallInfoForwardConditionalNoti_t data;
281                         g_variant_get(param, "(i)", &data.id);
282                         dbg("[ check ] %s : data.id(%d)", "Call Info Forward Conditional noti", data.id);
283                         noti_data = &data.id;
284                 }
285                 if (!g_strcmp0(sig, "ForwardUnconditional")) {
286                         TelCallInfoForwardUnconditionalNoti_t data;
287                         g_variant_get(param, "(i)", &data.id);
288                         dbg("[ check ] %s : data.id(%d)", "Call Info Forward Unconditional noti", data.id);
289                         noti_data = &data.id;
290                 }
291                 if (!g_strcmp0(sig, "CallActive")) {
292                         TelCallInfoActiveNoti_t data;
293                         g_variant_get(param, "(i)", &data.id);
294                         dbg("[ check ] %s : data.id(%d)", "Call Info Call Active noti", data.id);
295                         noti_data = &data.id;
296                 }
297                 if (!g_strcmp0(sig, "CallHeld")) {
298                         TelCallInfoHeldNoti_t data;
299                         g_variant_get(param, "(i)", &data.id);
300                         dbg("[ check ] %s : data.id(%d)", "Call Info Call Held noti", data.id);
301                         noti_data = &data.id;
302                 }
303                 if (!g_strcmp0(sig, "CallJoined")) {
304                         TelCallInfoJoinedNoti_t data;
305                         g_variant_get(param, "(i)", &data.id);
306                         dbg("[ check ] %s : data.id(%d)", "Call Info Call Joined noti", data.id);
307                         noti_data = &data.id;
308                 }
309                 if (!g_strcmp0(sig, "CallSoundPath")) {
310                         TelCallSoundPathNoti_t data;
311                         g_variant_get(param, "(i)", &data.path);
312                         dbg("[ check ] %s : path(%d)", "Call Sound Path noti", data.path);
313                         noti_data = &data;
314                 }
315                 if (!g_strcmp0(sig, "CallSoundRingbackTone")) {
316                         TelCallSoundRingbackToneNoti_t status;
317                         g_variant_get(param, "(i)", &status);
318                         dbg("[ check ] %s : status(%d)", "Call Sound Ringbacktone noti", status);
319                         noti_data = &status;
320                 }
321                 if (!g_strcmp0(sig, "CallSoundWbamr")) {
322                         TelCallSoundWbamrNoti_t status;
323                         g_variant_get(param, "(i)", &status);
324                         dbg("[ check ] %s : status(%d)", "Call Sound Wbamr noti", status);
325                         noti_data = &status;
326                 }
327                 if (!g_strcmp0(sig, "CallSoundEqualization")) {
328                         TelCallSoundEqualizationNoti_t data;
329                         g_variant_get(param, "(ii)", &data.mode, &data.direction);
330                         dbg("[ check ] %s : mode(%d), direction(%d)", "Call Sound Equalization noti", data.mode, data.direction);
331                         noti_data = &data;
332                 }
333                 if (!g_strcmp0(sig, "CallSoundNoiseReduction")) {
334                         TelCallSoundNoiseReductionNoti_t data;
335                         g_variant_get(param, "(i)", &data.status);
336                         dbg("[ check ] %s : status(%d)", "Call Sound Noise Reduction noti", data.status);
337                         noti_data = &data;
338                 }
339         }
340
341         if (!g_strcmp0(interface, DBUS_TELEPHONY_SAT_INTERFACE)) {
342                 if (!g_strcmp0(sig, "SetupMenu")) {
343                         TelSatSetupMenuInfo_t setup_menu;
344
345                         gchar *title;
346                         gint command_id, item_cnt;
347                         gboolean b_present, b_helpinfo, b_updated;
348                         GVariant *items = NULL, *icon_id, *icon_list;
349
350                         memset(&setup_menu, 0, sizeof(TelSatSetupMenuInfo_t));
351
352                         g_variant_get(param, "(ibs@vibb@v@v)", &command_id, &b_present, &title, &items, &item_cnt,
353                                                 &b_helpinfo, &b_updated, &icon_id, &icon_list);
354
355                         setup_menu.commandId = command_id;
356                         setup_menu.bIsMainMenuPresent = (b_present ? 1 : 0);
357                         memcpy(setup_menu.satMainTitle, title, TAPI_SAT_DEF_TITLE_LEN_MAX+1);
358                         setup_menu.satMainMenuNum = item_cnt;
359                         if(items && item_cnt > 0){
360                                 int index = 0;
361                                 GVariant *unbox;
362                                 GVariantIter *iter;
363
364                                 gchar *item_str;
365                                 gint item_id;
366                                 unbox = g_variant_get_variant(items);
367                                 dbg("items(%p) items type_format(%s)", items, g_variant_get_type_string(unbox));
368
369                                 g_variant_get(unbox, "a(si)", &iter);
370                                 while(g_variant_iter_loop(iter,"(si)",&item_str, &item_id)){
371                                         setup_menu.satMainMenuItem[index].itemId = item_id;
372                                         memcpy(setup_menu.satMainMenuItem[index].itemString, item_str, TAPI_SAT_DEF_ITEM_STR_LEN_MAX + 6);
373                                         dbg("item index(%d) id(%d) str(%s)",index, setup_menu.satMainMenuItem[index].itemId, setup_menu.satMainMenuItem[index].itemString);
374                                         //dbg("item index(%d) id(%d) str(%s)",index, item_id, item_str);
375                                         index++;
376                                 }
377                                 g_variant_iter_free(iter);
378                         }
379                         setup_menu.bIsSatMainMenuHelpInfo = (b_helpinfo ? 1 : 0);
380                         setup_menu.bIsUpdatedSatMainMenu = (b_updated ? 1 : 0);
381
382                         dbg("command id (%d)", setup_menu.commandId);
383                         dbg("menu present (%d)", setup_menu.bIsMainMenuPresent);
384                         dbg("menu title (%s)", setup_menu.satMainTitle);
385                         dbg("item cnt (%d)", setup_menu.satMainMenuNum);
386                         dbg("menu help info (%d)", setup_menu.bIsSatMainMenuHelpInfo);
387                         dbg("menu updated (%d)", setup_menu.bIsUpdatedSatMainMenu);
388
389                         noti_data = &setup_menu;
390                 }
391                 else if (!g_strcmp0(sig, "DisplayText")) {
392                         TelSatDisplayTextInd_t display_text;
393
394                         gchar* text;
395                         gint command_id, text_len, duration;
396                         gboolean high_priority, user_rsp_required, immediately_rsp;
397                         GVariant *icon_id = NULL;
398
399                         memset(&display_text, 0, sizeof(TelSatDisplayTextInd_t));
400
401                         g_variant_get(param, "(isiibbb@v)", &command_id, &text, &text_len, &duration,
402                                 &high_priority, &user_rsp_required, &immediately_rsp, &icon_id);
403
404                         display_text.commandId = command_id;
405                         memcpy(display_text.text.string, text, TAPI_SAT_DEF_TEXT_STRING_LEN_MAX+1);
406                         display_text.text.stringLen = text_len;
407                         display_text.duration = duration;
408                         display_text.bIsPriorityHigh = (high_priority ? 1 : 0);
409                         display_text.bIsUserRespRequired = (user_rsp_required ? 1 : 0);
410
411                         dbg("command id (%d)", display_text.commandId);
412                         dbg("display text (%s)", display_text.text.string);
413                         dbg("string len(%d)", display_text.text.stringLen);
414                         dbg("duration (%d)", display_text.duration);
415                         dbg("high priority (%d)", display_text.bIsPriorityHigh);
416                         dbg("user response required(%d)", display_text.bIsUserRespRequired);
417
418                         noti_data = &display_text;
419                 }
420                 else if (!g_strcmp0(sig, "SelectItem")) {
421                         TelSatSelectItemInd_t select_item;
422
423                         gboolean help_info ;
424                         gchar *selected_text;
425                         gint command_id, default_item_id, menu_cnt, text_len =0;
426                         GVariant *menu_items, *icon_id, *icon_list;
427
428                         memset(&select_item, 0, sizeof(TelSatSelectItemInd_t));
429
430                         g_variant_get(param, "(ibsiii@v@v@v)", &command_id, &help_info, &selected_text,
431                                 &text_len, &default_item_id, &menu_cnt, &menu_items, &icon_id, &icon_list);
432
433                         select_item.commandId = command_id;
434                         select_item.bIsHelpInfoAvailable = (help_info ? 1 : 0);
435                         memcpy(select_item.text.string, selected_text, TAPI_SAT_DEF_TITLE_LEN_MAX+1);
436                         select_item.text.stringLen = text_len;
437                         select_item.defaultItemIndex = default_item_id;
438                         select_item.menuItemCount = menu_cnt;
439                         if(menu_items && menu_cnt > 0){
440                                 int index = 0;
441                                 GVariant *unbox;
442                                 GVariantIter *iter;
443
444                                 gchar *item_str;
445                                 gint item_id, item_len;
446                                 unbox = g_variant_get_variant(menu_items);
447                                 dbg("items(%p) items type_format(%s)", menu_items, g_variant_get_type_string(unbox));
448
449                                 g_variant_get(unbox, "a(iis)", &iter);
450                                 while(g_variant_iter_loop(iter,"(iis)",&item_id, &item_len, &item_str)){
451                                         select_item.menuItem[index].itemId = item_id;
452                                         select_item.menuItem[index].textLen = item_len;
453                                         memcpy(select_item.menuItem[index].text, item_str, TAPI_SAT_ITEM_TEXT_LEN_MAX + 1);
454                                         dbg("item index(%d) id(%d) len(%d) str(%s)", index,
455                                                         select_item.menuItem[index].itemId, select_item.menuItem[index].textLen, select_item.menuItem[index].text);
456                                         index++;
457                                 }
458                                 g_variant_iter_free(iter);
459                         }
460
461                         dbg("command id (%d)", select_item.commandId);
462                         dbg("help info(%d)", select_item.bIsHelpInfoAvailable);
463                         dbg("selected item string(%s)", select_item.text.string);
464                         dbg("string len(%d)", select_item.text.stringLen);
465                         dbg("default item index(%d)", select_item.defaultItemIndex);
466                         dbg("item count(%d)", select_item.menuItemCount);
467
468                         noti_data = &select_item;
469                 }
470                 else if (!g_strcmp0(sig, "GetInkey")) {
471                         TelSatGetInkeyInd_t get_inkey;
472
473                         gint command_id, key_type, input_character_mode;
474                         gint text_len, duration;
475                         gboolean b_numeric, b_help_info;
476                         gchar *text;
477                         GVariant *icon_id;
478
479                         memset(&get_inkey, 0, sizeof(TelSatGetInkeyInd_t));
480
481                         g_variant_get(param, "(iiibbsii@v)", &command_id, &key_type, &input_character_mode,
482                                 &b_numeric,&b_help_info, &text, &text_len, &duration, &icon_id);
483
484                         get_inkey.commandId = command_id;
485                         get_inkey.keyType = key_type;
486                         get_inkey.inputCharMode = input_character_mode;
487                         get_inkey.bIsNumeric = (b_numeric ? 1 : 0);
488                         get_inkey.bIsHelpInfoAvailable = (b_help_info ? 1 : 0);
489                         memcpy(get_inkey.text.string, text, TAPI_SAT_DEF_TEXT_STRING_LEN_MAX+1);
490                         get_inkey.text.stringLen = text_len;
491                         get_inkey.duration = duration;
492
493                         dbg("command id(%d)", get_inkey.commandId);
494                         dbg("key type(%d)", get_inkey.keyType);
495                         dbg("input character mode(%d)", get_inkey.inputCharMode);
496                         dbg("numeric(%d)", get_inkey.bIsNumeric);
497                         dbg("help info available(%d)", get_inkey.bIsHelpInfoAvailable);
498                         dbg("text (%s)", get_inkey.text.string);
499                         dbg("text length", get_inkey.text.stringLen);
500                         dbg("duration", get_inkey.duration);
501
502                         noti_data = &get_inkey;
503                 }
504                 else if (!g_strcmp0(sig, "GetInput")) {
505                         TelSatGetInputInd_t get_input;
506
507                         gint command_id, input_character_mode;
508                         gint text_len, def_text_len, rsp_len_min, rsp_len_max;
509                         gboolean b_numeric, b_help_info, b_echo_input;
510                         gchar *text, *def_text;
511                         GVariant *icon_id;
512
513                         memset(&get_input, 0, sizeof(TelSatGetInputInd_t));
514
515                         g_variant_get(param, "(iibbbsiiisi@v)", &command_id, &input_character_mode, &b_numeric, &b_help_info, &b_echo_input,
516                                 &text, &text_len, &rsp_len_max, &rsp_len_min, &def_text, &def_text_len, &icon_id);
517
518                         get_input.commandId = command_id;
519                         get_input.inputCharMode = input_character_mode;
520                         get_input.bIsNumeric = (b_numeric ? 1 : 0);
521                         get_input.bIsHelpInfoAvailable = (b_help_info ? 1 : 0);
522                         get_input.bIsEchoInput = (b_echo_input ? 1 : 0);
523                         memcpy(get_input.text.string, text, TAPI_SAT_DEF_TEXT_STRING_LEN_MAX+1);
524                         get_input.text.stringLen = text_len;
525                         get_input.respLen.max = rsp_len_max;
526                         get_input.respLen.min = rsp_len_min;
527                         memcpy(get_input.defaultText.string, def_text, TAPI_SAT_DEF_TEXT_STRING_LEN_MAX+1);
528                         get_input.defaultText.stringLen = def_text_len;
529
530                         dbg("command id(%d)", get_input.commandId);
531                         dbg("input character mode(%d)", get_input.inputCharMode);
532                         dbg("numeric(%d)", get_input.bIsNumeric);
533                         dbg("help info avaiable(%d)", get_input.bIsHelpInfoAvailable);
534                         dbg("echo input(%d)", get_input.bIsEchoInput);
535                         dbg("text(%s)", get_input.text.string);
536                         dbg("text length(%d)", get_input.text.stringLen);
537                         dbg("response length max(%d)", get_input.respLen.max);
538                         dbg("response length min(%d)", get_input.respLen.min);
539                         dbg("default text(%s)", get_input.defaultText.string);
540                         dbg("default text length(%d)", get_input.defaultText.stringLen);
541
542                         noti_data = &get_input;
543                 }
544                 else if (!g_strcmp0(sig, "SendSMS")) {
545                         TelSatSendSmsIndSmsData_t send_sms;
546
547                         gint command_id, ton, npi, tpdu_type;
548                         gboolean b_packing_required;
549                         gint text_len, number_len, tpdu_data_len, tmp_data_len;
550                         gchar* text, *dialling_number;
551                         GVariant *tpdu_data, *icon_id;
552
553                         memset(&send_sms, 0, sizeof(TelSatSendSmsIndSmsData_t));
554
555                         g_variant_get(param, "(isi@vbiisii@vi)", &command_id, &text, &text_len, &icon_id, &b_packing_required, &ton, &npi,
556                                                 &dialling_number, &number_len, &tpdu_type, &tpdu_data, &tpdu_data_len);
557
558                         send_sms.commandId = command_id;
559                         send_sms.bIsPackingRequired = (b_packing_required ? 1 : 0);
560
561                         send_sms.address.ton = ton;
562                         send_sms.address.npi = npi;
563                         send_sms.address.diallingNumberLen = number_len;
564                         memcpy(send_sms.address.diallingNumber, dialling_number, TAPI_SAT_DIALLING_NUMBER_LEN_MAX);
565
566                         send_sms.smsTpdu.tpduType = tpdu_type;
567                         send_sms.smsTpdu.dataLen = tpdu_data_len;
568
569                         if(tpdu_data){
570                                 int index = 0;
571                                 guchar data;
572                                 GVariantIter *iter = NULL;
573                                 GVariant *inner_gv = NULL;
574
575                                 inner_gv = g_variant_get_variant(tpdu_data);
576                                 dbg("tpdu data exist type_format(%s)", g_variant_get_type_string(inner_gv));
577
578                                 g_variant_get(inner_gv, "ay", &iter);
579                                 while( g_variant_iter_loop (iter, "y", &data)){
580                                         dbg("index(%d) data(%c)", index, data);
581                                         send_sms.smsTpdu.data[index] = data;
582                                         index++;
583                                 }
584                                 g_variant_iter_free(iter);
585                                 g_variant_unref(inner_gv);
586                                 tmp_data_len = index - 1;
587                         }
588
589                         dbg("command id(%d)", send_sms.commandId);
590                         dbg("packing required(%d)", send_sms.bIsPackingRequired);
591                         dbg("address ton(%d)", send_sms.address.ton);
592                         dbg("address npi(%d)", send_sms.address.npi);
593                         dbg("address dialing number (%s)", send_sms.address.diallingNumber);
594                         dbg("address number length (%d)", send_sms.address.diallingNumberLen);
595                         dbg("tpdu type (%d)", send_sms.smsTpdu.tpduType);
596                         dbg("tpdu length (%d)", send_sms.smsTpdu.dataLen);
597
598                         noti_data = &send_sms;
599                 }
600                 else if (!g_strcmp0(sig, "SetupEventList")) {
601                         int g_index = 0;
602                         gint event_cnt;
603                         GVariant *evt_list;
604                         TelSatEventListData_t event_list;
605
606                         memset(&event_list, 0, sizeof(TelSatEventListData_t));
607
608                         g_variant_get(param, "(i@v)", &event_cnt, &evt_list);
609
610                         if(evt_list){
611                                 guchar data;
612                                 GVariantIter *iter = NULL;
613                                 GVariant *inner_gv = NULL;
614
615                                 inner_gv = g_variant_get_variant(evt_list);
616                                 dbg("event list exist type_format(%s)", g_variant_get_type_string(inner_gv));
617
618                                 g_variant_get(inner_gv, "ai", &iter);
619                                 while( g_variant_iter_loop (iter, "i", &data)){
620                                         dbg("g_index(%d) event(%d)", g_index, data);
621                                         g_event_list[g_index] = data;
622
623                                         if(data == TAPI_EVENT_SAT_DW_TYPE_IDLE_SCREEN_AVAILABLE){
624                                                 event_list.bIsIdleScreenAvailable = 1;
625                                         }
626                                         else if(data == TAPI_EVENT_SAT_DW_TYPE_LANGUAGE_SELECTION){
627                                                 event_list.bIsLanguageSelection = 1;
628                                         }
629                                         else if(data == TAPI_EVENT_SAT_DW_TYPE_BROWSER_TERMINATION){
630                                                 event_list.bIsBrowserTermination = 1;
631                                         }
632                                         else if(data == TAPI_EVENT_SAT_DW_TYPE_DATA_AVAILABLE){
633                                                 event_list.bIsDataAvailable = 1;
634                                         }
635                                         else if(data == TAPI_EVENT_SAT_DW_TYPE_CHANNEL_STATUS){
636                                                 event_list.bIsChannelStatus = 1;
637                                         }
638
639                                         g_index++;
640                                 }
641                                 //while end
642                                 g_variant_iter_free(iter);
643                                 g_variant_unref(inner_gv);
644                         }
645
646                         dbg("event list cnt(%d)", event_cnt);
647
648                         noti_data = &event_list;
649                 }
650                 else if (!g_strcmp0(sig, "EndProactiveSession")) {
651                         int command_type = 0;
652
653                         g_variant_get(param, "(i)", &command_type);
654                         dbg("end session evt : command type(%d)", command_type);
655                         noti_data = &command_type;
656                 }
657         }
658
659         if (!g_strcmp0(interface, DBUS_TELEPHONY_SIM_INTERFACE)) {
660                 if (!g_strcmp0(sig, "Status")) {
661                         int noti = 0;
662                         g_variant_get(param, "(i)", &noti);
663                         noti_data = &noti;
664                 } else {
665                         dbg("not handled SIM noti[%s]",sig );
666                 }
667         }
668
669         if (!g_strcmp0(interface, DBUS_TELEPHONY_PB_INTERFACE)) {
670                 if (!g_strcmp0(sig, "Status")) {
671                         int noti = 0;
672                         g_variant_get(param, "(i)", &noti);
673                         noti_data = &noti;
674                 } else {
675                         dbg("not handled Phonebook noti[%s]",sig );
676                 }
677         }
678
679         if (!g_strcmp0(interface, DBUS_TELEPHONY_SAP_INTERFACE)) {
680                 if (!g_strcmp0(sig, "Status")) {
681                         int noti = 0;
682                         g_variant_get(param, "(i)", &noti);
683                         noti_data = &noti;
684                 } else if (!g_strcmp0(sig, "Disconnect")) {
685                         int disconnect = 0;
686                         g_variant_get(param, "(i)", &disconnect);
687                         noti_data = &disconnect;
688                 } else {
689                         dbg("not handled SAP noti[%s]",sig );
690                 }
691         }
692
693         if (!g_strcmp0(interface, DBUS_TELEPHONY_MODEM_INTERFACE)) {
694                 if (!g_strcmp0(sig, "Power")) {
695                         int noti = 0;
696                         g_variant_get(param, "(i)", &noti);
697                         noti_data = &noti;
698                 } else if (!g_strcmp0(sig, "DunPinCtrl")) {
699                         tapi_ps_btdun_pincontrol pin_ctrl;
700                         int signal = 0, status = 0;
701
702                         memset(&pin_ctrl, 0, sizeof(tapi_ps_btdun_pincontrol));
703                         g_variant_get(param, "(ib)", &signal, &status);
704                         pin_ctrl.signal = signal;
705                         pin_ctrl.status = status;
706
707                         noti_data = &pin_ctrl;
708                 } else if (!g_strcmp0(sig, "DunExternalCall")) {
709                         gboolean external_call;
710
711                         g_variant_get(param, "(b)", &external_call);
712
713                         noti_data = &external_call;
714                 }
715                 else {
716                         dbg("not handled Modem noti[%s]", sig);
717                 }
718         }
719
720         if (!g_strcmp0(interface, DBUS_TELEPHONY_SS_INTERFACE)) {
721                 if (!g_strcmp0(sig, "NotifyUSSD")) {
722                         TelSsUssdMsgInfo_t noti;
723                         char *str = NULL;
724                         memset(&noti, 0, sizeof(TelSsUssdMsgInfo_t));
725
726                         g_variant_get(param, "(iis)", &noti.Type, &noti.Length, &str);
727
728                         if (str)
729                                 g_strlcpy(noti.szString, str, TAPI_SS_USSD_DATA_SIZE_MAX);
730
731                         noti_data = &noti;
732                 }
733                 else {
734                         dbg("not handled SS noti[%s]", sig);
735                 }
736         }
737
738         if (evt_cb_data->cb_fn) {
739                 evt_cb_data->cb_fn(handle, noti_id, noti_data, evt_cb_data->user_data);
740         }
741
742         g_free(noti_id);
743         return;
744 }
745
746 EXPORT_API char** tel_get_cp_name_list(void)
747 {
748         GError *error = NULL;
749         GDBusProxy *proxy = NULL;
750
751         GVariantIter *iter = NULL;
752         GVariant *rst = NULL;
753
754         gchar *modem_path = NULL;
755         GSList *list = NULL;
756         GSList *l = NULL;
757
758         int i = 0, element_cnt = 0;
759         gchar **cp_list = NULL;
760
761         proxy = g_dbus_proxy_new_for_bus_sync (G_BUS_TYPE_SYSTEM, G_DBUS_PROXY_FLAGS_NONE, NULL,
762                                 "org.tizen.telephony", "/org/tizen/telephony", "org.tizen.telephony.Manager",
763                                 NULL, &error);
764         if (!proxy) {
765                 dbg("g_dbus_proxy_new_for_bus_sycn() failed. (%s)", error->message);
766                 g_error_free (error);
767                 return NULL;
768         }
769
770         rst = g_dbus_proxy_call_sync (proxy, "GetModems", NULL, G_DBUS_CALL_FLAGS_NONE, -1, NULL, &error);
771         if (!rst) {
772                 dbg( "GetModems() failed. (%s)", error->message);
773                 g_error_free (error);
774                 goto OUT;
775         }
776
777         g_variant_get (rst, "(as)", &iter);
778         while (g_variant_iter_next(iter, "s", &modem_path)){
779                 list = g_slist_append(list, modem_path);
780         }
781         g_variant_iter_free (iter);
782
783         if (!list) {
784                 dbg( "No CP name");
785                 goto OUT;
786         }
787
788         element_cnt = g_slist_length(list);
789         cp_list = g_new0(char*, element_cnt + 1);
790         if (!cp_list) {
791                 goto OUT;
792         }
793
794         for (l = list; l; l = l->next, i++) {
795                 cp_list[i] = g_strdup(l->data);
796                 dbg("cp name[%d] = %s", i, cp_list[i]);
797         }
798         cp_list[element_cnt] = NULL;
799
800         g_slist_free(list);
801
802 OUT:
803         if (proxy)
804                 g_object_unref(proxy);
805
806         return cp_list;
807 }
808
809 EXPORT_API int tel_get_property_int(TapiHandle *handle, const char *property, int *result)
810 {
811         char **dbus_info;
812         GDBusProxy *proxy = NULL;
813         GVariant *value = NULL;
814         GError *error = NULL;
815         int ret = TAPI_API_SUCCESS;
816
817         if (!handle || !property)
818                 return TAPI_API_INVALID_INPUT;
819
820         dbus_info = g_strsplit(property, ":", 2);
821         if (!dbus_info) {
822                 dbg("invalid property");
823                 return TAPI_API_INVALID_INPUT;
824         }
825
826         if (!dbus_info[0] || !dbus_info[1]) {
827                 dbg("invalid property");
828                 ret = TAPI_API_INVALID_INPUT;
829                 goto OUT;
830         }
831
832         proxy = g_dbus_proxy_new_for_bus_sync (G_BUS_TYPE_SYSTEM, G_DBUS_PROXY_FLAGS_NONE, NULL,
833                                 DBUS_TELEPHONY_SERVICE, handle->path, dbus_info[0],
834                                 NULL, &error);
835         if (!proxy) {
836                 dbg("g_dbus_proxy_new_for_bus_sycn() failed. (%s)", error->message);
837                 g_error_free (error);
838                 ret = TAPI_API_OPERATION_FAILED;
839                 goto OUT;
840         }
841
842         value = g_dbus_proxy_get_cached_property(proxy, dbus_info[1]);
843         if (!value) {
844                 dbg("g_dbus_proxy_get_cached_property('power') failed.");
845                 ret = TAPI_API_OPERATION_FAILED;
846                 goto OUT;
847         }
848
849         g_variant_get(value, "i", result);
850         g_variant_unref(value);
851
852 OUT:
853         if (proxy)
854                 g_object_unref(proxy);
855
856         g_strfreev(dbus_info);
857
858         return ret;
859 }
860
861 EXPORT_API TapiHandle* tel_init(const char *cp_name)
862 {
863         GError *error = NULL;
864         struct tapi_handle *handle;
865
866         g_type_init();
867
868         handle = g_new0(struct tapi_handle, 1);
869         if (!handle)
870                 return NULL;
871
872         if (cp_name) {
873                 handle->cp_name = g_strdup(cp_name);
874         }
875         else {
876                 char **list = NULL;
877
878                 list = tel_get_cp_name_list();
879                 if (!list)
880                         return NULL;
881
882                 if (!list[0])
883                         return NULL;
884
885                 dbg("use default plugin(%s)", list[0]);
886                 handle->cp_name = g_strdup(list[0]);
887         }
888
889         handle->dbus_connection = g_bus_get_sync(G_BUS_TYPE_SYSTEM, NULL, &error);
890         if (!handle->dbus_connection) {
891                 dbg("Error creating connection: %s\n", error->message);
892                 g_free(handle->cp_name);
893                 g_free(handle);
894                 g_error_free (error);
895                 return NULL;
896         }
897
898         handle->evt_list = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, g_free);
899
900         handle->path = g_strdup_printf("%s/%s",
901                         DBUS_TELEPHONY_DEFAULT_PATH, handle->cp_name);
902
903         return handle;
904 }
905
906 EXPORT_API int tel_deinit(TapiHandle* handle)
907 {
908         if (!handle)
909                 return -1;
910
911         if (handle->cp_name)
912                 g_free(handle->cp_name);
913
914         if (handle->path)
915                 g_free(handle->path);
916
917         dbg( "remove all signal");
918         /*
919          * TODO
920          */
921
922         memset(handle, 0, sizeof(struct tapi_handle));
923         g_free(handle);
924
925         return TAPI_API_SUCCESS;
926 }
927
928 EXPORT_API int tel_register_noti_event(TapiHandle *handle, const char *noti_id, tapi_notification_cb callback, void *user_data)
929 {
930         gchar **dbus_str = NULL;
931         gpointer tmp = NULL;
932         struct tapi_evt_cb *evt_cb_data = NULL;
933
934         if (!handle || !handle->dbus_connection || !callback || !noti_id) {
935                 dbg("invalid parameter");
936                 return TAPI_API_INVALID_INPUT;
937         }
938
939         tmp = g_hash_table_lookup(handle->evt_list, noti_id);
940         if (tmp != NULL) {
941                 dbg("noti_id(%s) is already registered", noti_id);
942                 return TAPI_API_INVALID_INPUT;
943         }
944
945         dbus_str = g_strsplit(noti_id, ":", 2);
946         if (!dbus_str) {
947                 dbg("invalid noti_id");
948                 return TAPI_API_INVALID_INPUT;
949         }
950
951         if (!dbus_str[0] || !dbus_str[1]) {
952                 g_strfreev(dbus_str);
953                 dbg("invalid noti_id");
954                 return TAPI_API_INVALID_INPUT;
955         }
956
957         evt_cb_data = g_new0(struct tapi_evt_cb, 1);
958         evt_cb_data->cb_fn = callback;
959         evt_cb_data->user_data = user_data;
960
961         dbg("path(%s) interface (%s) signal (%s)", handle->path, dbus_str[0], dbus_str[1]);
962
963         evt_cb_data->evt_id = g_dbus_connection_signal_subscribe(handle->dbus_connection,
964                         DBUS_TELEPHONY_SERVICE, /* Sender */
965                         dbus_str[0], /* Interface */
966                         dbus_str[1], /* Member */
967                         handle->path, /* Object path */
968                         NULL, /* arg0 */
969                         G_DBUS_SIGNAL_FLAGS_NONE,
970                         on_signal_callback, handle,
971                         NULL);
972
973         g_hash_table_insert(handle->evt_list, g_strdup(noti_id), evt_cb_data);
974
975         g_strfreev(dbus_str);
976
977         return TAPI_API_SUCCESS;
978 }
979
980 EXPORT_API int tel_deregister_noti_event(TapiHandle *handle, const char *noti_id)
981 {
982         struct tapi_evt_cb *evt_cb_data = NULL;
983         gboolean rv = FALSE;
984
985         if (!handle || !handle->dbus_connection){
986                 dbg("invalid parameter");
987                 return TAPI_API_INVALID_INPUT;
988         }
989
990         evt_cb_data = g_hash_table_lookup(handle->evt_list, noti_id);
991
992         if(!evt_cb_data){
993                 dbg("event does not registered");
994                 return TAPI_API_INVALID_INPUT;
995         }
996
997         g_dbus_connection_signal_unsubscribe(handle->dbus_connection, evt_cb_data->evt_id);
998
999         rv = g_hash_table_remove(handle->evt_list, noti_id);
1000         if(!rv){
1001                 dbg("fail to deregister noti event(%s)", noti_id);
1002                 return TAPI_API_OPERATION_FAILED;
1003         }
1004
1005         return TAPI_API_SUCCESS;
1006 }
1007 /*      EOF     */