4 * Copyright (c) 2012 Samsung Electronics Co., Ltd. All rights reserved.
6 * Contact: Ja-young Gu <jygu@samsung.com>
8 * Licensed under the Apache License, Version 2.0 (the "License");
9 * you may not use this file except in compliance with the License.
10 * You may obtain a copy of the License at
12 * http://www.apache.org/licenses/LICENSE-2.0
14 * Unless required by applicable law or agreed to in writing, software
15 * distributed under the License is distributed on an "AS IS" BASIS,
16 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 * See the License for the specific language governing permissions and
18 * limitations under the License.
28 #include <glib-object.h>
31 #include "tapi_common.h"
32 #include "TapiUtility.h"
36 #include "TelNetwork.h"
46 #define CALLBACK_CALL(data) \
47 if (evt_cb_data->cb_fn) { \
48 evt_cb_data->cb_fn(handle, noti_id, (data), evt_cb_data->user_data); \
51 extern char *g_cookie_name;
52 extern int g_cookie_size;
54 TelSatEventDownloadType_t g_event_list[TAPI_SAT_EVENT_LIST_MAX_COUNT] = {-1};
56 /*static void _cookie_deinit(void)
65 static void _process_network_event(const gchar *sig, GVariant *param,
66 TapiHandle *handle, char *noti_id, struct tapi_evt_cb *evt_cb_data)
71 if (!g_strcmp0(sig, "RegistrationStatus")) {
72 struct tel_noti_network_registration_status noti;
74 g_variant_get(param, "(iiib)", ¬i.cs, ¬i.ps, ¬i.type, ¬i.is_roaming);
78 else if (!g_strcmp0(sig, "Info")) {
79 struct tel_noti_network_info noti;
81 memset(¬i, 0, sizeof(struct tel_noti_network_info));
82 g_variant_get(param, "(ii)", ¬i.rssi, ¬i.battery);
86 else if (!g_strcmp0(sig, "CellInfo")) {
87 struct tel_noti_network_cell_info noti;
89 memset(¬i, 0, sizeof(struct tel_noti_network_cell_info));
90 g_variant_get(param, "(ii)", ¬i.lac, ¬i.cell_id);
94 else if (!g_strcmp0(sig, "Change")) {
95 struct tel_noti_network_change noti;
98 memset(¬i, 0, sizeof(struct tel_noti_network_change));
100 g_variant_get(param, "(isi)", &act, &plmn, ¬i.lac);
104 noti.act = TAPI_NETWORK_SYSTEM_GSM;
107 noti.act = TAPI_NETWORK_SYSTEM_GPRS;
110 noti.act = TAPI_NETWORK_SYSTEM_EGPRS;
113 noti.act = TAPI_NETWORK_SYSTEM_UMTS;
116 noti.act = TAPI_NETWORK_SYSTEM_GSM_AND_UMTS;
119 noti.act = TAPI_NETWORK_SYSTEM_IS95A;
122 noti.act = TAPI_NETWORK_SYSTEM_IS95B;
125 noti.act = TAPI_NETWORK_SYSTEM_CDMA_1X;
128 noti.act = TAPI_NETWORK_SYSTEM_EVDO_REV_0;
131 noti.act = TAPI_NETWORK_SYSTEM_1X_EVDO_REV_0_HYBRID;
134 noti.act = TAPI_NETWORK_SYSTEM_EVDO_REV_A;
137 noti.act = TAPI_NETWORK_SYSTEM_1X_EVDO_REV_A_HYBRID;
140 noti.act = TAPI_NETWORK_SYSTEM_EVDV;
143 noti.act = TAPI_NETWORK_SYSTEM_LTE;
146 noti.act = TAPI_NETWORK_SYSTEM_NO_SRV;
151 snprintf(noti.plmn, 7, "%s", plmn);
154 CALLBACK_CALL(¬i);
156 else if (!g_strcmp0(sig, "TimeInfo")) {
157 struct tel_noti_network_time_info noti;
160 memset(¬i, 0, sizeof(struct tel_noti_network_time_info));
161 g_variant_get(param, "(iiiiiiiiibs)", ¬i.year, ¬i.month, ¬i.day,
162 ¬i.hour, ¬i.minute, ¬i.second,
163 ¬i.wday, ¬i.gmtoff, ¬i.dstoff, ¬i.isdst,
167 snprintf(noti.plmn, 7, "%s", plmn);
170 CALLBACK_CALL(¬i);
172 else if (!g_strcmp0(sig, "Identity")) {
173 struct tel_noti_network_identity noti;
174 char *plmn = NULL, *s_name = NULL, *f_name = NULL;
176 memset(¬i, 0, sizeof(struct tel_noti_network_identity));
178 g_variant_get(param, "(sss)", &plmn, &s_name, &f_name);
181 snprintf(noti.plmn, 7, "%s", plmn);
184 snprintf(noti.short_name, 17, "%s", s_name);
187 snprintf(noti.full_name, 33, "%s", f_name);
190 CALLBACK_CALL(¬i);
193 dbg("not handled Network noti[%s]", sig);
197 static void _process_sms_event(const gchar *sig, GVariant *param,
198 TapiHandle *handle, char *noti_id, struct tapi_evt_cb *evt_cb_data)
203 if (!g_strcmp0(sig, "IncommingMsg")) {
204 struct tel_noti_sms_incomming_msg noti;
206 const char *sca = NULL;
207 const char *tpdu = NULL;
209 guchar *decoded_sca = NULL;
210 guchar *decoded_tpdu = NULL;
212 memset(¬i, 0, sizeof(struct tel_noti_sms_incomming_msg));
214 g_variant_get(param, "(sis)", &sca, ¬i.MsgLength, &tpdu);
216 decoded_sca = g_base64_decode(sca, &length);
218 memcpy(&(noti.Sca[0]), decoded_sca, TAPI_SMS_ENCODED_SCA_LEN_MAX);
222 decoded_tpdu = g_base64_decode(tpdu, &length);
224 memcpy(&(noti.szData[0]), decoded_tpdu, TAPI_NETTEXT_SMDATA_SIZE_MAX + 1);
225 g_free(decoded_tpdu);
228 CALLBACK_CALL(¬i);
230 else if (!g_strcmp0(sig, "IncommingCbMsg")) {
231 struct tel_noti_sms_incomming_cb_msg noti;
233 const char *cbMsg = NULL;
235 guchar *decoded_cbMsg = NULL;
237 memset(¬i, 0, sizeof(struct tel_noti_sms_incomming_cb_msg));
238 g_variant_get(param, "(iis)", ¬i.CbMsgType, ¬i.Length, &cbMsg);
240 decoded_cbMsg = g_base64_decode(cbMsg, &length);
242 memcpy(&(noti.szMsgData[0]), decoded_cbMsg, TAPI_NETTEXT_CB_SIZE_MAX + 1);
243 g_free(decoded_cbMsg);
246 CALLBACK_CALL(¬i);
248 else if (!g_strcmp0(sig, "IncommingEtwsMsg")) {
249 struct tel_noti_sms_incomming_etws_msg noti;
251 const char *etwsMsg = NULL;
253 guchar *decoded_etwsMsg = NULL;
255 memset(¬i, 0, sizeof(struct tel_noti_sms_incomming_etws_msg));
256 g_variant_get(param, "(iis)", ¬i.EtwsMsgType, ¬i.Length, &etwsMsg);
258 decoded_etwsMsg = g_base64_decode(etwsMsg, &length);
259 if (decoded_etwsMsg) {
260 memcpy(&(noti.szMsgData[0]), decoded_etwsMsg, TAPI_NETTEXT_ETWS_SIZE_MAX + 1);
261 g_free(decoded_etwsMsg);
264 CALLBACK_CALL(¬i);
266 else if (!g_strcmp0(sig, "MemoryStatus")) {
269 g_variant_get(param, "(i)", ¬i);
270 CALLBACK_CALL(¬i);
272 else if (!g_strcmp0(sig, "SmsReady")) {
275 g_variant_get(param, "(b)", ¬i);
276 CALLBACK_CALL(¬i);
279 dbg("not handled Sms noti[%s]", sig);
283 static void _process_call_event(const gchar *sig, GVariant *param,
284 TapiHandle *handle, char *noti_id, struct tapi_evt_cb *evt_cb_data)
289 if (!g_strcmp0(sig, "VoiceCallStatusIdle") || !g_strcmp0(sig, "VideoCallStatusIdle") ) {
290 TelCallStatusIdleNoti_t data;
291 int start_time = 0, end_time = 0;
292 g_variant_get(param, "(iiii)", &data.id, &data.cause, &start_time, &end_time);
293 dbg("[ check ] %s : call_id(%d), end_cause(0x%x)", "Status Idle noti", data.id, data.cause);
294 CALLBACK_CALL(&data);
296 else if (!g_strcmp0(sig, "VoiceCallStatusDialing") || !g_strcmp0(sig, "VideoCallStatusDialing")) {
297 TelCallStatusDialingNoti_t data;
298 g_variant_get(param, "(i)", &data.id);
299 dbg("[ check ] %s : call_id(%d)", "Status Dialing noti", data.id);
300 CALLBACK_CALL(&data);
302 else if (!g_strcmp0(sig, "VoiceCallStatusAlert") || !g_strcmp0(sig, "VideoCallStatusAlert")) {
303 TelCallStatusAlertNoti_t data;
304 g_variant_get(param, "(i)", &data.id);
305 dbg("[ check ] %s : call_id(%d)", "Status Alert noti", data.id);
306 CALLBACK_CALL(&data);
308 else if (!g_strcmp0(sig, "VoiceCallStatusActive") || !g_strcmp0(sig, "VideoCallStatusActive")) {
309 TelCallStatusActiveNoti_t data;
310 g_variant_get(param, "(i)", &data.id);
311 dbg("[ check ] %s : call_id(%d)", "Status Active noti", data.id);
312 CALLBACK_CALL(&data);
314 else if (!g_strcmp0(sig, "VoiceCallStatusHeld") ) {
315 TelCallStatusHeldNoti_t data;
316 g_variant_get(param, "(i)", &data.id);
317 dbg("[ check ] %s : call_id(%d)", "Status Held noti", data.id);
318 CALLBACK_CALL(&data);
320 else if (!g_strcmp0(sig, "VoiceCallStatusIncoming") || !g_strcmp0(sig, "VideoCallStatusIncoming")) {
321 TelCallStatusIncomingNoti_t data;
322 g_variant_get(param, "(i)", &data.id);
323 dbg("[ check ] %s : call_id(%d)", "Status Incoming noti", data.id);
324 CALLBACK_CALL(&data);
326 else if (!g_strcmp0(sig, "Waiting")) {
327 TelCallInfoWaitingNoti_t data;
328 g_variant_get(param, "(i)", &data.id);
329 dbg("[ check ] %s : data.id(%d)", "Call Info Waiting noti", data.id);
330 CALLBACK_CALL(&data.id);
332 else if (!g_strcmp0(sig, "Forwarded")) {
333 TelCallInfoForwardedNoti_t data;
334 g_variant_get(param, "(i)", &data.id);
335 dbg("[ check ] %s : data.id(%d)", "Call Info Forwarded noti", data.id);
336 CALLBACK_CALL(&data.id);
338 else if (!g_strcmp0(sig, "BarredIncoming")) {
339 TelCallInfoBarredIncomingNoti_t data;
340 g_variant_get(param, "(i)", &data.id);
341 dbg("[ check ] %s : data.id(%d)", "Call Info Barred Incoming noti", data.id);
342 CALLBACK_CALL(&data.id);
344 else if (!g_strcmp0(sig, "BarredOutgoing")) {
345 TelCallInfoBarredOutgoingNoti_t data;
346 g_variant_get(param, "(i)", &data.id);
347 dbg("[ check ] %s : data.id(%d)", "Call Info Barred Outgoing noti", data.id);
348 CALLBACK_CALL(&data.id);
350 else if (!g_strcmp0(sig, "ForwardConditional")) {
351 TelCallInfoForwardConditionalNoti_t data;
352 g_variant_get(param, "(i)", &data.id);
353 dbg("[ check ] %s : data.id(%d)", "Call Info Forward Conditional noti", data.id);
354 CALLBACK_CALL(&data.id);
356 else if (!g_strcmp0(sig, "ForwardUnconditional")) {
357 TelCallInfoForwardUnconditionalNoti_t data;
358 g_variant_get(param, "(i)", &data.id);
359 dbg("[ check ] %s : data.id(%d)", "Call Info Forward Unconditional noti", data.id);
360 CALLBACK_CALL(&data.id);
362 else if (!g_strcmp0(sig, "CallActive")) {
363 TelCallInfoActiveNoti_t data;
364 g_variant_get(param, "(i)", &data.id);
365 dbg("[ check ] %s : data.id(%d)", "Call Info Call Active noti", data.id);
366 CALLBACK_CALL(&data.id);
368 else if (!g_strcmp0(sig, "CallHeld")) {
369 TelCallInfoHeldNoti_t data;
370 g_variant_get(param, "(i)", &data.id);
371 dbg("[ check ] %s : data.id(%d)", "Call Info Call Held noti", data.id);
372 CALLBACK_CALL(&data.id);
374 else if (!g_strcmp0(sig, "CallJoined")) {
375 TelCallInfoJoinedNoti_t data;
376 g_variant_get(param, "(i)", &data.id);
377 dbg("[ check ] %s : data.id(%d)", "Call Info Call Joined noti", data.id);
378 CALLBACK_CALL(&data.id);
380 else if (!g_strcmp0(sig, "CallSoundPath")) {
381 TelCallSoundPathNoti_t data;
382 g_variant_get(param, "(i)", &data.path);
383 dbg("[ check ] %s : path(%d)", "Call Sound Path noti", data.path);
384 CALLBACK_CALL(&data);
386 else if (!g_strcmp0(sig, "CallSoundRingbackTone")) {
387 TelCallSoundRingbackToneNoti_t status;
388 g_variant_get(param, "(i)", &status);
389 dbg("[ check ] %s : status(%d)", "Call Sound Ringbacktone noti", status);
390 CALLBACK_CALL(&status);
392 else if (!g_strcmp0(sig, "CallSoundWbamr")) {
393 TelCallSoundWbamrNoti_t status;
394 g_variant_get(param, "(i)", &status);
395 dbg("[ check ] %s : status(%d)", "Call Sound Wbamr noti", status);
396 CALLBACK_CALL(&status);
398 else if (!g_strcmp0(sig, "CallSoundEqualization")) {
399 TelCallSoundEqualizationNoti_t data;
400 g_variant_get(param, "(ii)", &data.mode, &data.direction);
401 dbg("[ check ] %s : mode(%d), direction(%d)", "Call Sound Equalization noti", data.mode, data.direction);
402 CALLBACK_CALL(&data);
404 else if (!g_strcmp0(sig, "CallSoundNoiseReduction")) {
405 TelCallSoundNoiseReductionNoti_t data;
406 g_variant_get(param, "(i)", &data.status);
407 dbg("[ check ] %s : status(%d)", "Call Sound Noise Reduction noti", data.status);
408 CALLBACK_CALL(&data);
410 else if (!g_strcmp0(sig, "CallSoundClockStatus")) {
412 g_variant_get(param, "(b)", &data);
413 dbg("[ check ] %s : status(%d)", "Call Sound Clock Status noti", data);
414 CALLBACK_CALL(&data);
417 dbg("not handled Call noti[%s]", sig);
421 static void _process_sat_event(const gchar *sig, GVariant *param,
422 TapiHandle *handle, char *noti_id, struct tapi_evt_cb *evt_cb_data)
427 if (!g_strcmp0(sig, "SetupMenu")) {
428 TelSatSetupMenuInfo_t setup_menu;
431 gint command_id, item_cnt;
432 gboolean b_present, b_helpinfo, b_updated;
433 GVariant *items = NULL;
435 memset(&setup_menu, 0, sizeof(TelSatSetupMenuInfo_t));
437 g_variant_get(param, "(ibs@vibb)", &command_id, &b_present, &title, &items, &item_cnt,
438 &b_helpinfo, &b_updated);
440 setup_menu.commandId = command_id;
441 setup_menu.bIsMainMenuPresent = (b_present ? 1 : 0);
442 memcpy(setup_menu.satMainTitle, title, TAPI_SAT_DEF_TITLE_LEN_MAX+1);
443 setup_menu.satMainMenuNum = item_cnt;
444 if(items && item_cnt > 0){
451 unbox = g_variant_get_variant(items);
452 dbg("items(%p) items type_format(%s)", items, g_variant_get_type_string(unbox));
454 g_variant_get(unbox, "a(si)", &iter);
455 while(g_variant_iter_loop(iter,"(si)",&item_str, &item_id)){
456 setup_menu.satMainMenuItem[index].itemId = item_id;
457 memcpy(setup_menu.satMainMenuItem[index].itemString, item_str, TAPI_SAT_DEF_ITEM_STR_LEN_MAX + 6);
458 dbg("item index(%d) id(%d) str(%s)",index, setup_menu.satMainMenuItem[index].itemId, setup_menu.satMainMenuItem[index].itemString);
459 //dbg("item index(%d) id(%d) str(%s)",index, item_id, item_str);
462 g_variant_iter_free(iter);
464 setup_menu.bIsSatMainMenuHelpInfo = (b_helpinfo ? 1 : 0);
465 setup_menu.bIsUpdatedSatMainMenu = (b_updated ? 1 : 0);
467 dbg("command id (%d)", setup_menu.commandId);
468 dbg("menu present (%d)", setup_menu.bIsMainMenuPresent);
469 dbg("menu title (%s)", setup_menu.satMainTitle);
470 dbg("item cnt (%d)", setup_menu.satMainMenuNum);
471 dbg("menu help info (%d)", setup_menu.bIsSatMainMenuHelpInfo);
472 dbg("menu updated (%d)", setup_menu.bIsUpdatedSatMainMenu);
474 CALLBACK_CALL(&setup_menu);
476 else if (!g_strcmp0(sig, "DisplayText")) {
477 TelSatDisplayTextInd_t display_text;
480 gint command_id, text_len, duration;
481 gboolean high_priority, user_rsp_required, immediately_rsp;
483 memset(&display_text, 0, sizeof(TelSatDisplayTextInd_t));
485 g_variant_get(param, "(isiibbb)", &command_id, &text, &text_len, &duration,
486 &high_priority, &user_rsp_required, &immediately_rsp);
488 display_text.commandId = command_id;
489 memcpy(display_text.text.string, text, TAPI_SAT_DEF_TEXT_STRING_LEN_MAX+1);
490 display_text.text.stringLen = text_len;
491 display_text.duration = duration;
492 display_text.bIsPriorityHigh = (high_priority ? 1 : 0);
493 display_text.bIsUserRespRequired = (user_rsp_required ? 1 : 0);
494 display_text.b_immediately_resp = (immediately_rsp ? 1 : 0);
496 dbg("command id (%d)", display_text.commandId);
497 dbg("display text (%s)", display_text.text.string);
498 dbg("string len(%d)", display_text.text.stringLen);
499 dbg("duration (%d)", display_text.duration);
500 dbg("high priority (%d)", display_text.bIsPriorityHigh);
501 dbg("user response required(%d)", display_text.bIsUserRespRequired);
502 dbg("immediately response (%d)", display_text.b_immediately_resp);
504 CALLBACK_CALL(&display_text);
506 else if (!g_strcmp0(sig, "SelectItem")) {
507 TelSatSelectItemInd_t select_item;
510 gchar *selected_text;
511 gint command_id, default_item_id, menu_cnt, text_len =0;
512 GVariant *menu_items;
514 memset(&select_item, 0, sizeof(TelSatSelectItemInd_t));
516 g_variant_get(param, "(ibsiii@v)", &command_id, &help_info, &selected_text,
517 &text_len, &default_item_id, &menu_cnt, &menu_items);
519 select_item.commandId = command_id;
520 select_item.bIsHelpInfoAvailable = (help_info ? 1 : 0);
521 memcpy(select_item.text.string, selected_text, TAPI_SAT_DEF_TITLE_LEN_MAX+1);
522 select_item.text.stringLen = text_len;
523 select_item.defaultItemIndex = default_item_id;
524 select_item.menuItemCount = menu_cnt;
525 if(menu_items && menu_cnt > 0){
531 gint item_id, item_len;
532 unbox = g_variant_get_variant(menu_items);
533 dbg("items(%p) items type_format(%s)", menu_items, g_variant_get_type_string(unbox));
535 g_variant_get(unbox, "a(iis)", &iter);
536 while(g_variant_iter_loop(iter,"(iis)",&item_id, &item_len, &item_str)){
537 select_item.menuItem[index].itemId = item_id;
538 select_item.menuItem[index].textLen = item_len;
539 memcpy(select_item.menuItem[index].text, item_str, TAPI_SAT_ITEM_TEXT_LEN_MAX + 1);
540 dbg("item index(%d) id(%d) len(%d) str(%s)", index,
541 select_item.menuItem[index].itemId, select_item.menuItem[index].textLen, select_item.menuItem[index].text);
544 g_variant_iter_free(iter);
547 dbg("command id (%d)", select_item.commandId);
548 dbg("help info(%d)", select_item.bIsHelpInfoAvailable);
549 dbg("selected item string(%s)", select_item.text.string);
550 dbg("string len(%d)", select_item.text.stringLen);
551 dbg("default item index(%d)", select_item.defaultItemIndex);
552 dbg("item count(%d)", select_item.menuItemCount);
554 CALLBACK_CALL(&select_item);
556 else if (!g_strcmp0(sig, "GetInkey")) {
557 TelSatGetInkeyInd_t get_inkey;
559 gint command_id, key_type, input_character_mode;
560 gint text_len, duration;
561 gboolean b_numeric, b_help_info;
564 memset(&get_inkey, 0, sizeof(TelSatGetInkeyInd_t));
566 g_variant_get(param, "(iiibbsii)", &command_id, &key_type, &input_character_mode,
567 &b_numeric,&b_help_info, &text, &text_len, &duration);
569 get_inkey.commandId = command_id;
570 get_inkey.keyType = key_type;
571 get_inkey.inputCharMode = input_character_mode;
572 get_inkey.bIsNumeric = (b_numeric ? 1 : 0);
573 get_inkey.bIsHelpInfoAvailable = (b_help_info ? 1 : 0);
574 memcpy(get_inkey.text.string, text, TAPI_SAT_DEF_TEXT_STRING_LEN_MAX+1);
575 get_inkey.text.stringLen = text_len;
576 get_inkey.duration = duration;
578 dbg("command id(%d)", get_inkey.commandId);
579 dbg("key type(%d)", get_inkey.keyType);
580 dbg("input character mode(%d)", get_inkey.inputCharMode);
581 dbg("numeric(%d)", get_inkey.bIsNumeric);
582 dbg("help info available(%d)", get_inkey.bIsHelpInfoAvailable);
583 dbg("text (%s)", get_inkey.text.string);
584 dbg("text length", get_inkey.text.stringLen);
585 dbg("duration", get_inkey.duration);
587 CALLBACK_CALL(&get_inkey);
589 else if (!g_strcmp0(sig, "GetInput")) {
590 TelSatGetInputInd_t get_input;
592 gint command_id, input_character_mode;
593 gint text_len, def_text_len, rsp_len_min, rsp_len_max;
594 gboolean b_numeric, b_help_info, b_echo_input;
595 gchar *text, *def_text;
597 memset(&get_input, 0, sizeof(TelSatGetInputInd_t));
599 g_variant_get(param, "(iibbbsiiisi)", &command_id, &input_character_mode, &b_numeric, &b_help_info, &b_echo_input,
600 &text, &text_len, &rsp_len_max, &rsp_len_min, &def_text, &def_text_len);
602 get_input.commandId = command_id;
603 get_input.inputCharMode = input_character_mode;
604 get_input.bIsNumeric = (b_numeric ? 1 : 0);
605 get_input.bIsHelpInfoAvailable = (b_help_info ? 1 : 0);
606 get_input.bIsEchoInput = (b_echo_input ? 1 : 0);
607 memcpy(get_input.text.string, text, TAPI_SAT_DEF_TEXT_STRING_LEN_MAX+1);
608 get_input.text.stringLen = text_len;
609 get_input.respLen.max = rsp_len_max;
610 get_input.respLen.min = rsp_len_min;
611 memcpy(get_input.defaultText.string, def_text, TAPI_SAT_DEF_TEXT_STRING_LEN_MAX+1);
612 get_input.defaultText.stringLen = def_text_len;
614 dbg("command id(%d)", get_input.commandId);
615 dbg("input character mode(%d)", get_input.inputCharMode);
616 dbg("numeric(%d)", get_input.bIsNumeric);
617 dbg("help info avaiable(%d)", get_input.bIsHelpInfoAvailable);
618 dbg("echo input(%d)", get_input.bIsEchoInput);
619 dbg("text(%s)", get_input.text.string);
620 dbg("text length(%d)", get_input.text.stringLen);
621 dbg("response length max(%d)", get_input.respLen.max);
622 dbg("response length min(%d)", get_input.respLen.min);
623 dbg("default text(%s)", get_input.defaultText.string);
624 dbg("default text length(%d)", get_input.defaultText.stringLen);
626 CALLBACK_CALL(&get_input);
628 else if (!g_strcmp0(sig, "SendSMS")) {
629 TelSatSendSmsIndSmsData_t send_sms;
631 gint command_id, ton, npi, tpdu_type;
632 gboolean b_packing_required;
633 gint text_len, number_len, tpdu_data_len, tmp_data_len;
634 gchar* text, *dialling_number;
637 memset(&send_sms, 0, sizeof(TelSatSendSmsIndSmsData_t));
639 g_variant_get(param, "(isibiisii@vi)", &command_id, &text, &text_len, &b_packing_required, &ton, &npi,
640 &dialling_number, &number_len, &tpdu_type, &tpdu_data, &tpdu_data_len);
642 send_sms.commandId = command_id;
643 send_sms.bIsPackingRequired = (b_packing_required ? 1 : 0);
645 send_sms.address.ton = ton;
646 send_sms.address.npi = npi;
647 send_sms.address.diallingNumberLen = number_len;
648 memcpy(send_sms.address.diallingNumber, dialling_number, TAPI_SAT_DIALLING_NUMBER_LEN_MAX);
650 send_sms.smsTpdu.tpduType = tpdu_type;
651 send_sms.smsTpdu.dataLen = tpdu_data_len;
656 GVariantIter *iter = NULL;
657 GVariant *inner_gv = NULL;
659 inner_gv = g_variant_get_variant(tpdu_data);
660 dbg("tpdu data exist type_format(%s)", g_variant_get_type_string(inner_gv));
662 g_variant_get(inner_gv, "ay", &iter);
663 while( g_variant_iter_loop (iter, "y", &data)){
664 dbg("index(%d) data(%c)", index, data);
665 send_sms.smsTpdu.data[index] = data;
668 g_variant_iter_free(iter);
669 g_variant_unref(inner_gv);
670 tmp_data_len = index - 1;
673 dbg("command id(%d)", send_sms.commandId);
674 dbg("packing required(%d)", send_sms.bIsPackingRequired);
675 dbg("address ton(%d)", send_sms.address.ton);
676 dbg("address npi(%d)", send_sms.address.npi);
677 dbg("address dialing number (%s)", send_sms.address.diallingNumber);
678 dbg("address number length (%d)", send_sms.address.diallingNumberLen);
679 dbg("tpdu type (%d)", send_sms.smsTpdu.tpduType);
680 dbg("tpdu length (%d)", send_sms.smsTpdu.dataLen);
682 CALLBACK_CALL(&send_sms);
684 else if (!g_strcmp0(sig, "SetupEventList")) {
688 TelSatEventListData_t event_list;
690 memset(&event_list, 0, sizeof(TelSatEventListData_t));
692 g_variant_get(param, "(i@v)", &event_cnt, &evt_list);
696 GVariantIter *iter = NULL;
697 GVariant *inner_gv = NULL;
699 inner_gv = g_variant_get_variant(evt_list);
700 dbg("event list exist type_format(%s)", g_variant_get_type_string(inner_gv));
702 g_variant_get(inner_gv, "ai", &iter);
703 while( g_variant_iter_loop (iter, "i", &data)){
704 dbg("g_index(%d) event(%d)", g_index, data);
705 g_event_list[g_index] = data;
707 if(data == TAPI_EVENT_SAT_DW_TYPE_IDLE_SCREEN_AVAILABLE){
708 event_list.bIsIdleScreenAvailable = 1;
710 else if(data == TAPI_EVENT_SAT_DW_TYPE_LANGUAGE_SELECTION){
711 event_list.bIsLanguageSelection = 1;
713 else if(data == TAPI_EVENT_SAT_DW_TYPE_BROWSER_TERMINATION){
714 event_list.bIsBrowserTermination = 1;
716 else if(data == TAPI_EVENT_SAT_DW_TYPE_DATA_AVAILABLE){
717 event_list.bIsDataAvailable = 1;
719 else if(data == TAPI_EVENT_SAT_DW_TYPE_CHANNEL_STATUS){
720 event_list.bIsChannelStatus = 1;
726 g_variant_iter_free(iter);
727 g_variant_unref(inner_gv);
730 dbg("event list cnt(%d)", event_cnt);
732 CALLBACK_CALL(&event_list);
734 else if (!g_strcmp0(sig, "Refresh")) {
735 TelSatRefreshInd_t refresh_info;
738 gint refresh_type =0;
740 GVariant *file_list = NULL;
742 memset(&refresh_info, 0, sizeof(TelSatRefreshInd_t));
744 g_variant_get(param, "(ii@v)", &command_id, &refresh_type, &file_list);
746 refresh_info.commandId = command_id;
747 refresh_info.refreshMode = refresh_type;
752 GVariantIter *iter = NULL;
753 GVariant *inner_gv = NULL;
755 inner_gv = g_variant_get_variant(file_list);
756 dbg("file list exist type_format(%s)", g_variant_get_type_string(inner_gv));
758 g_variant_get(inner_gv, "ai", &iter);
759 while( g_variant_iter_loop (iter, "i", &data)){
760 dbg("g_index(%d) file id(%d)", g_index, data);
761 refresh_info.fileId[g_index] = data;
767 g_variant_iter_free(iter);
768 g_variant_unref(inner_gv);
770 refresh_info.fileCount = file_cnt;
772 dbg("refresh event/file cnt(%d)", refresh_info.fileCount);
774 CALLBACK_CALL(&refresh_info);
776 else if (!g_strcmp0(sig, "SendDtmf")) {
777 TelSatSendDtmfIndDtmfData_t send_dtmf;
780 gint text_len = 0, dtmf_str_len = 0;
782 gchar *dtmf_str = NULL;
784 memset(&send_dtmf, 0, sizeof(TelSatSendDtmfIndDtmfData_t));
786 g_variant_get(param, "(isisi)", &command_id, &text, &text_len, &dtmf_str, &dtmf_str_len);
788 send_dtmf.commandId = command_id;
789 if(text_len <= 0 || g_strcmp0(text,"") == 0 ){
790 send_dtmf.bIsHiddenMode = 1;
793 send_dtmf.dtmfString.stringLen = dtmf_str_len;
794 memcpy(send_dtmf.dtmfString.string, dtmf_str, TAPI_SAT_DEF_TEXT_STRING_LEN_MAX+1);
796 dbg("dtmf event command id(%d)", send_dtmf.commandId);
797 dbg("dtmf event dtmf(%s)", send_dtmf.dtmfString.string);
799 CALLBACK_CALL(&send_dtmf);
801 else if (!g_strcmp0(sig, "EndProactiveSession")) {
802 int command_type = 0;
804 g_variant_get(param, "(i)", &command_type);
805 dbg("end session evt : command type(%d)", command_type);
806 CALLBACK_CALL(&command_type);
809 dbg("not handled Sat noti[%s]", sig);
813 static void _process_sim_event(const gchar *sig, GVariant *param,
814 TapiHandle *handle, char *noti_id, struct tapi_evt_cb *evt_cb_data)
819 if (!g_strcmp0(sig, "Status")) {
821 g_variant_get(param, "(i)", ¬i);
822 CALLBACK_CALL(¬i);
824 dbg("not handled SIM noti[%s]",sig );
828 static void _process_pb_event(const gchar *sig, GVariant *param,
829 TapiHandle *handle, char *noti_id, struct tapi_evt_cb *evt_cb_data)
834 if (!g_strcmp0(sig, "Status")) {
836 g_variant_get(param, "(i)", ¬i);
837 CALLBACK_CALL(¬i);
839 dbg("not handled Phonebook noti[%s]",sig );
843 static void _process_sap_event(const gchar *sig, GVariant *param,
844 TapiHandle *handle, char *noti_id, struct tapi_evt_cb *evt_cb_data)
849 if (!g_strcmp0(sig, "Status")) {
851 g_variant_get(param, "(i)", ¬i);
852 CALLBACK_CALL(¬i);
853 } else if (!g_strcmp0(sig, "Disconnect")) {
855 g_variant_get(param, "(i)", &disconnect);
856 CALLBACK_CALL(&disconnect);
858 dbg("not handled SAP noti[%s]",sig );
862 static void _process_modem_event(const gchar *sig, GVariant *param,
863 TapiHandle *handle, char *noti_id, struct tapi_evt_cb *evt_cb_data)
868 if (!g_strcmp0(sig, "Power")) {
871 g_variant_get(param, "(i)", ¬i);
873 CALLBACK_CALL(¬i);
875 else if (!g_strcmp0(sig, "DunPinCtrl")) {
876 tapi_ps_btdun_pincontrol pin_ctrl;
877 int signal = 0, status = 0;
879 memset(&pin_ctrl, 0, sizeof(tapi_ps_btdun_pincontrol));
880 g_variant_get(param, "(ib)", &signal, &status);
881 pin_ctrl.signal = signal;
882 pin_ctrl.status = status;
884 CALLBACK_CALL(&pin_ctrl);
886 else if (!g_strcmp0(sig, "DunExternalCall")) {
887 gboolean external_call;
889 g_variant_get(param, "(b)", &external_call);
891 CALLBACK_CALL(&external_call);
894 dbg("not handled Modem noti[%s]", sig);
900 static void _process_ss_event(const gchar *sig, GVariant *param,
901 TapiHandle *handle, char *noti_id, struct tapi_evt_cb *evt_cb_data)
906 if (!g_strcmp0(sig, "NotifyUSSD")) {
907 TelSsUssdMsgInfo_t noti;
909 memset(¬i, 0, sizeof(TelSsUssdMsgInfo_t));
911 g_variant_get(param, "(iis)", ¬i.Type, ¬i.Length, &str);
914 g_strlcpy(noti.szString, str, TAPI_SS_USSD_DATA_SIZE_MAX);
918 CALLBACK_CALL(¬i);
920 } else if (!g_strcmp0(sig, "ReleaseComplete")) {
921 TelSsRelCompMsgInfo_t noti;
925 memset ( ¬i, 0, sizeof( TelSsRelCompMsgInfo_t ));
927 g_variant_get(param, "(i@v)", &len, &msg);
929 noti.RelCompMsgLen = (unsigned char)len;
934 GVariantIter *iter = NULL;
935 GVariant *inner_gv = NULL;
937 inner_gv = g_variant_get_variant(msg);
938 dbg("[ check ] data exist type_format(%s)", g_variant_get_type_string(inner_gv));
940 g_variant_get(inner_gv, "ay", &iter);
941 while( g_variant_iter_loop (iter, "y", &data)){
942 dbg("index(%d) data(%c)", index, data);
943 noti.szRelCompMsg[i] = data;
946 g_variant_iter_free(iter);
947 g_variant_unref(inner_gv);
950 CALLBACK_CALL(¬i);
953 dbg("not handled SS noti[%s]", sig);
959 static void _process_gps_event(const gchar *sig, GVariant *param,
960 TapiHandle *handle, char *noti_id, struct tapi_evt_cb *evt_cb_data)
962 gboolean b_decode_data = FALSE;
963 guchar *decoded_data = NULL;
968 if (!g_strcmp0(sig, "AssistData")) {
969 b_decode_data = TRUE;
971 else if (!g_strcmp0(sig, "MeasurePosition")) {
972 b_decode_data = TRUE;
974 else if (!g_strcmp0(sig, "ResetAssistData")) {
975 /* noting to decode */
977 else if (!g_strcmp0(sig, "FrequencyAiding")) {
978 b_decode_data = TRUE;
981 dbg("not handled Gps noti[%s]", sig);
988 dbg("[%s] decoding start", sig);
990 g_variant_get(param, "(s)", &data);
991 decoded_data = g_base64_decode((const gchar *)data, &length);
993 CALLBACK_CALL(decoded_data);
996 dbg("length=%d", length);
1000 g_free(decoded_data);
1003 static void on_signal_callback(GDBusConnection *conn, const gchar *name, const gchar *path, const gchar *interface,
1004 const gchar *sig, GVariant *param, gpointer user_data)
1006 TapiHandle *handle = user_data;
1007 struct tapi_evt_cb *evt_cb_data = NULL;
1011 dbg("handle is NULL");
1015 noti_id = g_strdup_printf("%s:%s", interface, sig);
1017 evt_cb_data = g_hash_table_lookup(handle->evt_list, noti_id);
1019 dbg("can't find noti_id(%s) callback info", noti_id);
1024 if (!g_strcmp0(interface, DBUS_TELEPHONY_NETWORK_INTERFACE)) {
1025 _process_network_event(sig, param, handle, noti_id, evt_cb_data);
1027 else if (!g_strcmp0(interface, DBUS_TELEPHONY_SMS_INTERFACE)) {
1028 _process_sms_event(sig, param, handle, noti_id, evt_cb_data);
1030 else if (!g_strcmp0(interface, DBUS_TELEPHONY_CALL_INTERFACE)) {
1031 _process_call_event(sig, param, handle, noti_id, evt_cb_data);
1033 else if (!g_strcmp0(interface, DBUS_TELEPHONY_SAT_INTERFACE)) {
1034 _process_sat_event(sig, param, handle, noti_id, evt_cb_data);
1036 else if (!g_strcmp0(interface, DBUS_TELEPHONY_SIM_INTERFACE)) {
1037 _process_sim_event(sig, param, handle, noti_id, evt_cb_data);
1039 else if (!g_strcmp0(interface, DBUS_TELEPHONY_PB_INTERFACE)) {
1040 _process_pb_event(sig, param, handle, noti_id, evt_cb_data);
1042 else if (!g_strcmp0(interface, DBUS_TELEPHONY_SAP_INTERFACE)) {
1043 _process_sap_event(sig, param, handle, noti_id, evt_cb_data);
1045 else if (!g_strcmp0(interface, DBUS_TELEPHONY_MODEM_INTERFACE)) {
1046 _process_modem_event(sig, param, handle, noti_id, evt_cb_data);
1048 else if (!g_strcmp0(interface, DBUS_TELEPHONY_SS_INTERFACE)) {
1049 _process_ss_event(sig, param, handle, noti_id, evt_cb_data);
1051 else if (!g_strcmp0(interface, DBUS_TELEPHONY_GPS_INTERFACE)) {
1052 _process_gps_event(sig, param, handle, noti_id, evt_cb_data);
1055 dbg("can't find interface(%s)", interface);
1060 EXPORT_API char** tel_get_cp_name_list(void)
1062 GError *error = NULL;
1063 GDBusProxy *proxy = NULL;
1065 GVariantIter *iter = NULL;
1066 GVariant *rst = NULL;
1068 gchar *modem_path = NULL;
1069 GSList *list = NULL;
1072 int i = 0, element_cnt = 0;
1073 gchar **cp_list = NULL;
1075 proxy = g_dbus_proxy_new_for_bus_sync (G_BUS_TYPE_SYSTEM, G_DBUS_PROXY_FLAGS_NONE, NULL,
1076 "org.tizen.telephony", "/org/tizen/telephony", "org.tizen.telephony.Manager",
1079 dbg("g_dbus_proxy_new_for_bus_sycn() failed. (%s)", error->message);
1080 g_error_free (error);
1084 rst = g_dbus_proxy_call_sync (proxy, "GetModems", NULL, G_DBUS_CALL_FLAGS_NONE, -1, NULL, &error);
1086 dbg( "GetModems() failed. (%s)", error->message);
1087 g_error_free (error);
1091 g_variant_get (rst, "(as)", &iter);
1092 while (g_variant_iter_next(iter, "s", &modem_path))
1093 list = g_slist_append(list, modem_path);
1095 g_variant_iter_free(iter);
1096 g_variant_unref(rst);
1103 element_cnt = g_slist_length(list);
1104 cp_list = g_new0(char*, element_cnt + 1);
1109 for (l = list; l; l = l->next, i++) {
1110 cp_list[i] = g_strdup(l->data);
1111 dbg("cp name[%d] = %s", i, cp_list[i]);
1113 cp_list[element_cnt] = NULL;
1116 g_slist_free_full(list, g_free);
1117 g_object_unref(proxy);
1122 EXPORT_API int tel_get_property_int(TapiHandle *handle, const char *property, int *result)
1125 GDBusProxy *proxy = NULL;
1126 GVariant *value = NULL;
1127 GError *error = NULL;
1128 int ret = TAPI_API_SUCCESS;
1130 if (!handle || !property)
1131 return TAPI_API_INVALID_INPUT;
1133 dbus_info = g_strsplit(property, ":", 2);
1135 dbg("invalid property");
1136 return TAPI_API_INVALID_INPUT;
1139 if (!dbus_info[0] || !dbus_info[1]) {
1140 dbg("invalid property");
1141 ret = TAPI_API_INVALID_INPUT;
1145 proxy = g_dbus_proxy_new_for_bus_sync (G_BUS_TYPE_SYSTEM, G_DBUS_PROXY_FLAGS_NONE, NULL,
1146 DBUS_TELEPHONY_SERVICE, handle->path, dbus_info[0],
1149 dbg("g_dbus_proxy_new_for_bus_sycn() failed. (%s)", error->message);
1150 g_error_free (error);
1151 ret = TAPI_API_OPERATION_FAILED;
1155 value = g_dbus_proxy_get_cached_property(proxy, dbus_info[1]);
1157 dbg("g_dbus_proxy_get_cached_property('power') failed.");
1158 ret = TAPI_API_OPERATION_FAILED;
1162 g_variant_get(value, "i", result);
1163 g_variant_unref(value);
1167 g_object_unref(proxy);
1169 g_strfreev(dbus_info);
1174 EXPORT_API TapiHandle* tel_init(const char *cp_name)
1176 GError *error = NULL;
1177 struct tapi_handle *handle = NULL;
1179 #if !GLIB_CHECK_VERSION (2, 35, 3)
1183 dbg("process info: env: [%s] invocation: [%s]",
1184 getenv("_"), program_invocation_name);
1186 /* Get System BUS */
1187 addr = g_dbus_address_get_for_bus_sync(G_BUS_TYPE_SYSTEM,
1191 err("Error get dbus: [%s]", error->message);
1195 /* Allocate new Handle */
1196 handle = g_try_new0(struct tapi_handle, 1);
1197 if (handle == NULL) {
1198 err("Failed to allocate handle");
1202 /* Create DBUS connection */
1203 handle->dbus_connection = g_dbus_connection_new_for_address_sync(addr,
1204 (G_DBUS_CONNECTION_FLAGS_AUTHENTICATION_CLIENT |
1205 G_DBUS_CONNECTION_FLAGS_MESSAGE_BUS_CONNECTION),
1209 if (handle->dbus_connection == NULL) {
1210 err("Error creating DBUS connection: [%s]", error->message);
1214 handle->ca = g_cancellable_new();
1215 if (handle->ca == NULL) {
1216 err("Error allocating cancellable object");
1221 if (cp_name != NULL)
1222 handle->cp_name = g_strdup(cp_name);
1227 /* Get CP Name list */
1228 list = tel_get_cp_name_list();
1229 if ((list == NULL) || (list[0] == NULL)) {
1230 err("Get CP name list failed");
1237 * Presently, we would only be providing the 'default' CP name,
1238 * it is the first CP name in the obtained list of CP names.
1240 * We would evolve this logic in due course.
1242 dbg("Use 'default' Plug-in: [%s]", list[0]);
1243 handle->cp_name = g_strdup(list[0]);
1245 /* Free CP name list */
1246 while (list[i] != NULL)
1252 /* Create Event list Hash Table */
1253 handle->evt_list = g_hash_table_new_full(g_str_hash,
1259 handle->path = g_strdup_printf("%s/%s",
1260 DBUS_TELEPHONY_DEFAULT_PATH, handle->cp_name);
1261 dbg("handle: [0x%x] Path: [%s]", handle, handle->path);
1267 /* Free all resources */
1269 g_error_free (error);
1271 if (handle != NULL) {
1272 g_cancellable_cancel(handle->ca);
1273 g_object_unref(handle->ca);
1275 if (g_dbus_connection_close_sync(handle->dbus_connection,
1278 err("Failed to close connection");
1280 g_object_unref(handle->dbus_connection);
1287 static gboolean _unregister_noti(gpointer key, gpointer value, gpointer user_data)
1289 struct tapi_evt_cb *evt_cb_data = value;
1290 TapiHandle *handle = user_data;
1295 g_dbus_connection_signal_unsubscribe(handle->dbus_connection, evt_cb_data->evt_id);
1300 EXPORT_API int tel_deinit(TapiHandle *handle)
1303 return TAPI_API_INVALID_INPUT;
1305 g_free(handle->cp_name);
1306 g_free(handle->path);
1308 dbg("Remove all signals");
1309 g_hash_table_foreach_remove(handle->evt_list, _unregister_noti, handle);
1310 g_hash_table_destroy(handle->evt_list);
1312 g_cancellable_cancel(handle->ca);
1313 g_object_unref(handle->ca);
1315 dbg("Close DBUS connection");
1316 if (g_dbus_connection_close_sync(handle->dbus_connection,
1317 NULL, NULL) == FALSE) {
1318 err("Failed to close DBUS connection");
1320 g_object_unref(handle->dbus_connection);
1323 dbg("deinit complete");
1324 return TAPI_API_SUCCESS;
1327 EXPORT_API int tel_register_noti_event(TapiHandle *handle, const char *noti_id,
1328 tapi_notification_cb callback, void *user_data)
1330 gchar **dbus_str = NULL;
1331 gpointer tmp = NULL;
1332 struct tapi_evt_cb *evt_cb_data = NULL;
1334 if ((handle == NULL) || (handle->dbus_connection == NULL)
1335 || (callback == NULL) || (noti_id == NULL)) {
1336 err("Invalid input parameters");
1337 return TAPI_API_INVALID_INPUT;
1340 tmp = g_hash_table_lookup(handle->evt_list, noti_id);
1342 dbg("noti_id(%s) is already registered", noti_id);
1343 return TAPI_API_INVALID_INPUT;
1346 dbus_str = g_strsplit(noti_id, ":", 2);
1348 dbg("invalid noti_id");
1349 return TAPI_API_INVALID_INPUT;
1352 if (!dbus_str[0] || !dbus_str[1]) {
1353 g_strfreev(dbus_str);
1354 dbg("invalid noti_id");
1355 return TAPI_API_INVALID_INPUT;
1358 evt_cb_data = g_try_new0(struct tapi_evt_cb, 1);
1359 if (evt_cb_data == NULL) {
1360 err("Failed to allocate memory");
1361 g_strfreev(dbus_str);
1362 return TAPI_API_SYSTEM_OUT_OF_MEM;
1365 /* Assign callback and user_data */
1366 evt_cb_data->cb_fn = callback;
1367 evt_cb_data->user_data = user_data;
1368 evt_cb_data->handle = handle;
1370 dbg("path(%s) interface (%s) signal (%s)", handle->path, dbus_str[0], dbus_str[1]);
1372 evt_cb_data->evt_id = g_dbus_connection_signal_subscribe(handle->dbus_connection,
1373 DBUS_TELEPHONY_SERVICE, /* Sender */
1374 dbus_str[0], /* Interface */
1375 dbus_str[1], /* Member */
1376 handle->path, /* Object path */
1378 G_DBUS_SIGNAL_FLAGS_NONE,
1379 on_signal_callback, handle,
1382 g_hash_table_insert(handle->evt_list, g_strdup(noti_id), evt_cb_data);
1384 g_strfreev(dbus_str);
1386 return TAPI_API_SUCCESS;
1389 EXPORT_API int tel_deregister_noti_event(TapiHandle *handle, const char *noti_id)
1391 struct tapi_evt_cb *evt_cb_data = NULL;
1392 gboolean rv = FALSE;
1394 if (!handle || !handle->dbus_connection){
1395 dbg("invalid parameter");
1396 return TAPI_API_INVALID_INPUT;
1399 evt_cb_data = g_hash_table_lookup(handle->evt_list, noti_id);
1402 dbg("event does not registered");
1403 return TAPI_API_INVALID_INPUT;
1406 g_dbus_connection_signal_unsubscribe(handle->dbus_connection, evt_cb_data->evt_id);
1408 rv = g_hash_table_remove(handle->evt_list, noti_id);
1410 dbg("fail to deregister noti event(%s)", noti_id);
1411 return TAPI_API_OPERATION_FAILED;
1414 return TAPI_API_SUCCESS;