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;
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);
672 dbg("command id(%d)", send_sms.commandId);
673 dbg("packing required(%d)", send_sms.bIsPackingRequired);
674 dbg("address ton(%d)", send_sms.address.ton);
675 dbg("address npi(%d)", send_sms.address.npi);
676 dbg("address dialing number (%s)", send_sms.address.diallingNumber);
677 dbg("address number length (%d)", send_sms.address.diallingNumberLen);
678 dbg("tpdu type (%d)", send_sms.smsTpdu.tpduType);
679 dbg("tpdu length (%d)", send_sms.smsTpdu.dataLen);
681 CALLBACK_CALL(&send_sms);
683 else if (!g_strcmp0(sig, "SetupEventList")) {
687 TelSatEventListData_t event_list;
689 memset(&event_list, 0, sizeof(TelSatEventListData_t));
691 g_variant_get(param, "(i@v)", &event_cnt, &evt_list);
695 GVariantIter *iter = NULL;
696 GVariant *inner_gv = NULL;
698 inner_gv = g_variant_get_variant(evt_list);
699 dbg("event list exist type_format(%s)", g_variant_get_type_string(inner_gv));
701 g_variant_get(inner_gv, "ai", &iter);
702 while( g_variant_iter_loop (iter, "i", &data)){
703 dbg("g_index(%d) event(%d)", g_index, data);
704 g_event_list[g_index] = data;
706 if(data == TAPI_EVENT_SAT_DW_TYPE_IDLE_SCREEN_AVAILABLE){
707 event_list.bIsIdleScreenAvailable = 1;
709 else if(data == TAPI_EVENT_SAT_DW_TYPE_LANGUAGE_SELECTION){
710 event_list.bIsLanguageSelection = 1;
712 else if(data == TAPI_EVENT_SAT_DW_TYPE_BROWSER_TERMINATION){
713 event_list.bIsBrowserTermination = 1;
715 else if(data == TAPI_EVENT_SAT_DW_TYPE_DATA_AVAILABLE){
716 event_list.bIsDataAvailable = 1;
718 else if(data == TAPI_EVENT_SAT_DW_TYPE_CHANNEL_STATUS){
719 event_list.bIsChannelStatus = 1;
725 g_variant_iter_free(iter);
726 g_variant_unref(inner_gv);
729 dbg("event list cnt(%d)", event_cnt);
731 CALLBACK_CALL(&event_list);
733 else if (!g_strcmp0(sig, "Refresh")) {
734 TelSatRefreshInd_t refresh_info;
737 gint refresh_type =0;
739 GVariant *file_list = NULL;
741 memset(&refresh_info, 0, sizeof(TelSatRefreshInd_t));
743 g_variant_get(param, "(ii@v)", &command_id, &refresh_type, &file_list);
745 refresh_info.commandId = command_id;
746 refresh_info.refreshMode = refresh_type;
751 GVariantIter *iter = NULL;
752 GVariant *inner_gv = NULL;
754 inner_gv = g_variant_get_variant(file_list);
755 dbg("file list exist type_format(%s)", g_variant_get_type_string(inner_gv));
757 g_variant_get(inner_gv, "ai", &iter);
758 while( g_variant_iter_loop (iter, "i", &data)){
759 dbg("g_index(%d) file id(%d)", g_index, data);
760 refresh_info.fileId[g_index] = data;
766 g_variant_iter_free(iter);
767 g_variant_unref(inner_gv);
769 refresh_info.fileCount = file_cnt;
771 dbg("refresh event/file cnt(%d)", refresh_info.fileCount);
773 CALLBACK_CALL(&refresh_info);
775 else if (!g_strcmp0(sig, "SendDtmf")) {
776 TelSatSendDtmfIndDtmfData_t send_dtmf;
779 gint text_len = 0, dtmf_str_len = 0;
781 gchar *dtmf_str = NULL;
783 memset(&send_dtmf, 0, sizeof(TelSatSendDtmfIndDtmfData_t));
785 g_variant_get(param, "(isisi)", &command_id, &text, &text_len, &dtmf_str, &dtmf_str_len);
787 send_dtmf.commandId = command_id;
788 if(text_len <= 0 || g_strcmp0(text,"") == 0 ){
789 send_dtmf.bIsHiddenMode = 1;
792 send_dtmf.dtmfString.stringLen = dtmf_str_len;
793 memcpy(send_dtmf.dtmfString.string, dtmf_str, TAPI_SAT_DEF_TEXT_STRING_LEN_MAX+1);
795 dbg("dtmf event command id(%d)", send_dtmf.commandId);
796 dbg("dtmf event dtmf(%s)", send_dtmf.dtmfString.string);
798 CALLBACK_CALL(&send_dtmf);
800 else if (!g_strcmp0(sig, "EndProactiveSession")) {
801 int command_type = 0;
803 g_variant_get(param, "(i)", &command_type);
804 dbg("end session evt : command type(%d)", command_type);
805 CALLBACK_CALL(&command_type);
808 dbg("not handled Sat noti[%s]", sig);
812 static void _process_sim_event(const gchar *sig, GVariant *param,
813 TapiHandle *handle, char *noti_id, struct tapi_evt_cb *evt_cb_data)
818 if (!g_strcmp0(sig, "Status")) {
820 g_variant_get(param, "(i)", ¬i);
821 CALLBACK_CALL(¬i);
823 dbg("not handled SIM noti[%s]",sig );
827 static void _process_pb_event(const gchar *sig, GVariant *param,
828 TapiHandle *handle, char *noti_id, struct tapi_evt_cb *evt_cb_data)
833 if (!g_strcmp0(sig, "Status")) {
835 g_variant_get(param, "(i)", ¬i);
836 CALLBACK_CALL(¬i);
838 dbg("not handled Phonebook noti[%s]",sig );
842 static void _process_sap_event(const gchar *sig, GVariant *param,
843 TapiHandle *handle, char *noti_id, struct tapi_evt_cb *evt_cb_data)
848 if (!g_strcmp0(sig, "Status")) {
850 g_variant_get(param, "(i)", ¬i);
851 CALLBACK_CALL(¬i);
852 } else if (!g_strcmp0(sig, "Disconnect")) {
854 g_variant_get(param, "(i)", &disconnect);
855 CALLBACK_CALL(&disconnect);
857 dbg("not handled SAP noti[%s]",sig );
861 static void _process_modem_event(const gchar *sig, GVariant *param,
862 TapiHandle *handle, char *noti_id, struct tapi_evt_cb *evt_cb_data)
867 if (!g_strcmp0(sig, "Power")) {
870 g_variant_get(param, "(i)", ¬i);
872 CALLBACK_CALL(¬i);
874 else if (!g_strcmp0(sig, "DunPinCtrl")) {
875 tapi_ps_btdun_pincontrol pin_ctrl;
876 int signal = 0, status = 0;
878 memset(&pin_ctrl, 0, sizeof(tapi_ps_btdun_pincontrol));
879 g_variant_get(param, "(ib)", &signal, &status);
880 pin_ctrl.signal = signal;
881 pin_ctrl.status = status;
883 CALLBACK_CALL(&pin_ctrl);
885 else if (!g_strcmp0(sig, "DunExternalCall")) {
886 gboolean external_call;
888 g_variant_get(param, "(b)", &external_call);
890 CALLBACK_CALL(&external_call);
893 dbg("not handled Modem noti[%s]", sig);
899 static void _process_ss_event(const gchar *sig, GVariant *param,
900 TapiHandle *handle, char *noti_id, struct tapi_evt_cb *evt_cb_data)
905 if (!g_strcmp0(sig, "NotifyUSSD")) {
906 TelSsUssdMsgInfo_t noti;
908 memset(¬i, 0, sizeof(TelSsUssdMsgInfo_t));
910 g_variant_get(param, "(iis)", ¬i.Type, ¬i.Length, &str);
913 g_strlcpy(noti.szString, str, TAPI_SS_USSD_DATA_SIZE_MAX);
917 CALLBACK_CALL(¬i);
919 } else if (!g_strcmp0(sig, "ReleaseComplete")) {
920 TelSsRelCompMsgInfo_t noti;
924 memset ( ¬i, 0, sizeof( TelSsRelCompMsgInfo_t ));
926 g_variant_get(param, "(i@v)", &len, &msg);
928 noti.RelCompMsgLen = (unsigned char)len;
933 GVariantIter *iter = NULL;
934 GVariant *inner_gv = NULL;
936 inner_gv = g_variant_get_variant(msg);
937 dbg("[ check ] data exist type_format(%s)", g_variant_get_type_string(inner_gv));
939 g_variant_get(inner_gv, "ay", &iter);
940 while( g_variant_iter_loop (iter, "y", &data)){
941 dbg("index(%d) data(%c)", index, data);
942 noti.szRelCompMsg[i] = data;
945 g_variant_iter_free(iter);
946 g_variant_unref(inner_gv);
949 CALLBACK_CALL(¬i);
952 dbg("not handled SS noti[%s]", sig);
958 static void _process_gps_event(const gchar *sig, GVariant *param,
959 TapiHandle *handle, char *noti_id, struct tapi_evt_cb *evt_cb_data)
961 gboolean b_decode_data = FALSE;
962 guchar *decoded_data = NULL;
967 if (!g_strcmp0(sig, "AssistData")) {
968 b_decode_data = TRUE;
970 else if (!g_strcmp0(sig, "MeasurePosition")) {
971 b_decode_data = TRUE;
973 else if (!g_strcmp0(sig, "ResetAssistData")) {
974 /* noting to decode */
976 else if (!g_strcmp0(sig, "FrequencyAiding")) {
977 b_decode_data = TRUE;
980 dbg("not handled Gps noti[%s]", sig);
987 dbg("[%s] decoding start", sig);
989 g_variant_get(param, "(s)", &data);
990 decoded_data = g_base64_decode((const gchar *)data, &length);
992 CALLBACK_CALL(decoded_data);
995 dbg("length=%d", length);
999 g_free(decoded_data);
1002 static void on_signal_callback(GDBusConnection *conn, const gchar *name, const gchar *path, const gchar *interface,
1003 const gchar *sig, GVariant *param, gpointer user_data)
1005 TapiHandle *handle = user_data;
1006 struct tapi_evt_cb *evt_cb_data = NULL;
1010 dbg("handle is NULL");
1014 noti_id = g_strdup_printf("%s:%s", interface, sig);
1016 evt_cb_data = g_hash_table_lookup(handle->evt_list, noti_id);
1018 dbg("can't find noti_id(%s) callback info", noti_id);
1023 if (!g_strcmp0(interface, DBUS_TELEPHONY_NETWORK_INTERFACE)) {
1024 _process_network_event(sig, param, handle, noti_id, evt_cb_data);
1026 else if (!g_strcmp0(interface, DBUS_TELEPHONY_SMS_INTERFACE)) {
1027 _process_sms_event(sig, param, handle, noti_id, evt_cb_data);
1029 else if (!g_strcmp0(interface, DBUS_TELEPHONY_CALL_INTERFACE)) {
1030 _process_call_event(sig, param, handle, noti_id, evt_cb_data);
1032 else if (!g_strcmp0(interface, DBUS_TELEPHONY_SAT_INTERFACE)) {
1033 _process_sat_event(sig, param, handle, noti_id, evt_cb_data);
1035 else if (!g_strcmp0(interface, DBUS_TELEPHONY_SIM_INTERFACE)) {
1036 _process_sim_event(sig, param, handle, noti_id, evt_cb_data);
1038 else if (!g_strcmp0(interface, DBUS_TELEPHONY_PB_INTERFACE)) {
1039 _process_pb_event(sig, param, handle, noti_id, evt_cb_data);
1041 else if (!g_strcmp0(interface, DBUS_TELEPHONY_SAP_INTERFACE)) {
1042 _process_sap_event(sig, param, handle, noti_id, evt_cb_data);
1044 else if (!g_strcmp0(interface, DBUS_TELEPHONY_MODEM_INTERFACE)) {
1045 _process_modem_event(sig, param, handle, noti_id, evt_cb_data);
1047 else if (!g_strcmp0(interface, DBUS_TELEPHONY_SS_INTERFACE)) {
1048 _process_ss_event(sig, param, handle, noti_id, evt_cb_data);
1050 else if (!g_strcmp0(interface, DBUS_TELEPHONY_GPS_INTERFACE)) {
1051 _process_gps_event(sig, param, handle, noti_id, evt_cb_data);
1054 dbg("can't find interface(%s)", interface);
1059 EXPORT_API char** tel_get_cp_name_list(void)
1061 GError *error = NULL;
1062 GDBusProxy *proxy = NULL;
1064 GVariantIter *iter = NULL;
1065 GVariant *rst = NULL;
1067 gchar *modem_path = NULL;
1068 GSList *list = NULL;
1071 int i = 0, element_cnt = 0;
1072 gchar **cp_list = NULL;
1074 proxy = g_dbus_proxy_new_for_bus_sync (G_BUS_TYPE_SYSTEM, G_DBUS_PROXY_FLAGS_NONE, NULL,
1075 "org.tizen.telephony", "/org/tizen/telephony", "org.tizen.telephony.Manager",
1078 dbg("g_dbus_proxy_new_for_bus_sycn() failed. (%s)", error->message);
1079 g_error_free (error);
1083 rst = g_dbus_proxy_call_sync (proxy, "GetModems", NULL, G_DBUS_CALL_FLAGS_NONE, -1, NULL, &error);
1085 dbg( "GetModems() failed. (%s)", error->message);
1086 g_error_free (error);
1090 g_variant_get (rst, "(as)", &iter);
1091 while (g_variant_iter_next(iter, "s", &modem_path))
1092 list = g_slist_append(list, modem_path);
1094 g_variant_iter_free(iter);
1095 g_variant_unref(rst);
1102 element_cnt = g_slist_length(list);
1103 cp_list = g_new0(char*, element_cnt + 1);
1108 for (l = list; l; l = l->next, i++) {
1109 cp_list[i] = g_strdup(l->data);
1110 dbg("cp name[%d] = %s", i, cp_list[i]);
1112 cp_list[element_cnt] = NULL;
1115 g_slist_free_full(list, g_free);
1116 g_object_unref(proxy);
1121 EXPORT_API int tel_get_property_int(TapiHandle *handle, const char *property, int *result)
1124 GDBusProxy *proxy = NULL;
1125 GVariant *value = NULL;
1126 GError *error = NULL;
1127 int ret = TAPI_API_SUCCESS;
1129 if (!handle || !property)
1130 return TAPI_API_INVALID_INPUT;
1132 dbus_info = g_strsplit(property, ":", 2);
1134 dbg("invalid property");
1135 return TAPI_API_INVALID_INPUT;
1138 if (!dbus_info[0] || !dbus_info[1]) {
1139 dbg("invalid property");
1140 ret = TAPI_API_INVALID_INPUT;
1144 proxy = g_dbus_proxy_new_for_bus_sync (G_BUS_TYPE_SYSTEM, G_DBUS_PROXY_FLAGS_NONE, NULL,
1145 DBUS_TELEPHONY_SERVICE, handle->path, dbus_info[0],
1148 dbg("g_dbus_proxy_new_for_bus_sycn() failed. (%s)", error->message);
1149 g_error_free (error);
1150 ret = TAPI_API_OPERATION_FAILED;
1154 value = g_dbus_proxy_get_cached_property(proxy, dbus_info[1]);
1156 dbg("g_dbus_proxy_get_cached_property('power') failed.");
1157 ret = TAPI_API_OPERATION_FAILED;
1161 g_variant_get(value, "i", result);
1162 g_variant_unref(value);
1166 g_object_unref(proxy);
1168 g_strfreev(dbus_info);
1173 EXPORT_API TapiHandle* tel_init(const char *cp_name)
1175 GError *error = NULL;
1176 struct tapi_handle *handle = NULL;
1178 #if !GLIB_CHECK_VERSION (2, 35, 3)
1182 dbg("process info: env: [%s] invocation: [%s]",
1183 getenv("_"), program_invocation_name);
1185 /* Get System BUS */
1186 addr = g_dbus_address_get_for_bus_sync(G_BUS_TYPE_SYSTEM,
1190 err("Error get dbus: [%s]", error->message);
1194 /* Allocate new Handle */
1195 handle = g_try_new0(struct tapi_handle, 1);
1196 if (handle == NULL) {
1197 err("Failed to allocate handle");
1201 /* Create DBUS connection */
1202 handle->dbus_connection = g_dbus_connection_new_for_address_sync(addr,
1203 (G_DBUS_CONNECTION_FLAGS_AUTHENTICATION_CLIENT |
1204 G_DBUS_CONNECTION_FLAGS_MESSAGE_BUS_CONNECTION),
1208 if (handle->dbus_connection == NULL) {
1209 err("Error creating DBUS connection: [%s]", error->message);
1213 handle->ca = g_cancellable_new();
1214 if (handle->ca == NULL) {
1215 err("Error allocating cancellable object");
1220 if (cp_name != NULL)
1221 handle->cp_name = g_strdup(cp_name);
1226 /* Get CP Name list */
1227 list = tel_get_cp_name_list();
1228 if ((list == NULL) || (list[0] == NULL)) {
1229 err("Get CP name list failed");
1236 * Presently, we would only be providing the 'default' CP name,
1237 * it is the first CP name in the obtained list of CP names.
1239 * We would evolve this logic in due course.
1241 dbg("Use 'default' Plug-in: [%s]", list[0]);
1242 handle->cp_name = g_strdup(list[0]);
1244 /* Free CP name list */
1245 while (list[i] != NULL)
1251 /* Create Event list Hash Table */
1252 handle->evt_list = g_hash_table_new_full(g_str_hash,
1258 handle->path = g_strdup_printf("%s/%s",
1259 DBUS_TELEPHONY_DEFAULT_PATH, handle->cp_name);
1260 dbg("handle: [0x%x] Path: [%s]", handle, handle->path);
1266 /* Free all resources */
1268 g_error_free (error);
1270 if (handle != NULL) {
1271 g_cancellable_cancel(handle->ca);
1272 g_object_unref(handle->ca);
1274 if (g_dbus_connection_close_sync(handle->dbus_connection,
1277 err("Failed to close connection");
1279 g_object_unref(handle->dbus_connection);
1286 static gboolean _unregister_noti(gpointer key, gpointer value, gpointer user_data)
1288 struct tapi_evt_cb *evt_cb_data = value;
1289 TapiHandle *handle = user_data;
1294 g_dbus_connection_signal_unsubscribe(handle->dbus_connection, evt_cb_data->evt_id);
1299 EXPORT_API int tel_deinit(TapiHandle *handle)
1302 return TAPI_API_INVALID_INPUT;
1304 g_free(handle->cp_name);
1305 g_free(handle->path);
1307 dbg("Remove all signals");
1308 g_hash_table_foreach_remove(handle->evt_list, _unregister_noti, handle);
1309 g_hash_table_destroy(handle->evt_list);
1311 g_cancellable_cancel(handle->ca);
1312 g_object_unref(handle->ca);
1314 dbg("Close DBUS connection");
1315 if (g_dbus_connection_close_sync(handle->dbus_connection,
1316 NULL, NULL) == FALSE) {
1317 err("Failed to close DBUS connection");
1319 g_object_unref(handle->dbus_connection);
1322 dbg("deinit complete");
1323 return TAPI_API_SUCCESS;
1326 EXPORT_API int tel_register_noti_event(TapiHandle *handle, const char *noti_id,
1327 tapi_notification_cb callback, void *user_data)
1329 gchar **dbus_str = NULL;
1330 gpointer tmp = NULL;
1331 struct tapi_evt_cb *evt_cb_data = NULL;
1333 if ((handle == NULL) || (handle->dbus_connection == NULL)
1334 || (callback == NULL) || (noti_id == NULL)) {
1335 err("Invalid input parameters");
1336 return TAPI_API_INVALID_INPUT;
1339 tmp = g_hash_table_lookup(handle->evt_list, noti_id);
1341 dbg("noti_id(%s) is already registered", noti_id);
1342 return TAPI_API_INVALID_INPUT;
1345 dbus_str = g_strsplit(noti_id, ":", 2);
1347 dbg("invalid noti_id");
1348 return TAPI_API_INVALID_INPUT;
1351 if (!dbus_str[0] || !dbus_str[1]) {
1352 g_strfreev(dbus_str);
1353 dbg("invalid noti_id");
1354 return TAPI_API_INVALID_INPUT;
1357 evt_cb_data = g_try_new0(struct tapi_evt_cb, 1);
1358 if (evt_cb_data == NULL) {
1359 err("Failed to allocate memory");
1360 g_strfreev(dbus_str);
1361 return TAPI_API_SYSTEM_OUT_OF_MEM;
1364 /* Assign callback and user_data */
1365 evt_cb_data->cb_fn = callback;
1366 evt_cb_data->user_data = user_data;
1367 evt_cb_data->handle = handle;
1369 dbg("path(%s) interface (%s) signal (%s)", handle->path, dbus_str[0], dbus_str[1]);
1371 evt_cb_data->evt_id = g_dbus_connection_signal_subscribe(handle->dbus_connection,
1372 DBUS_TELEPHONY_SERVICE, /* Sender */
1373 dbus_str[0], /* Interface */
1374 dbus_str[1], /* Member */
1375 handle->path, /* Object path */
1377 G_DBUS_SIGNAL_FLAGS_NONE,
1378 on_signal_callback, handle,
1381 g_hash_table_insert(handle->evt_list, g_strdup(noti_id), evt_cb_data);
1383 g_strfreev(dbus_str);
1385 return TAPI_API_SUCCESS;
1388 EXPORT_API int tel_deregister_noti_event(TapiHandle *handle, const char *noti_id)
1390 struct tapi_evt_cb *evt_cb_data = NULL;
1391 gboolean rv = FALSE;
1393 if (!handle || !handle->dbus_connection){
1394 dbg("invalid parameter");
1395 return TAPI_API_INVALID_INPUT;
1398 evt_cb_data = g_hash_table_lookup(handle->evt_list, noti_id);
1401 dbg("event does not registered");
1402 return TAPI_API_INVALID_INPUT;
1405 g_dbus_connection_signal_unsubscribe(handle->dbus_connection, evt_cb_data->evt_id);
1407 rv = g_hash_table_remove(handle->evt_list, noti_id);
1409 dbg("fail to deregister noti event(%s)", noti_id);
1410 return TAPI_API_OPERATION_FAILED;
1413 return TAPI_API_SUCCESS;