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.
25 #include "tapi_common.h"
26 #include "TapiUtility.h"
33 extern TelSatEventDownloadType_t g_event_list[TAPI_SAT_EVENT_LIST_MAX_COUNT];
35 static GVariant* _tapi_sat_gen_app_exec_result_data(TelSatAppsRetInfo_t *result_info)
37 GVariant *result = NULL;
39 switch(result_info->commandType)
41 case TAPI_SAT_CMD_TYPE_SETUP_MENU:{
43 dbg("setup menu : result format (i)");
45 exec_result = result_info->appsRet.setupMenu.resp;
46 result = g_variant_new("(i)", exec_result);
48 case TAPI_SAT_CMD_TYPE_REFRESH:{
49 gint app_type, exec_result;
50 dbg("refresh : result format (ii)");
52 app_type = result_info->appsRet.refresh.appType;
53 exec_result = result_info->appsRet.refresh.resp;
54 result = g_variant_new("(ii)", app_type, exec_result);
56 case TAPI_SAT_CMD_TYPE_SETUP_CALL:{
57 gint exec_result, me_problem, call_ctrl_problem, call_cause;
58 dbg("setup call : result format (iiii)");
60 exec_result = result_info->appsRet.setupCall.resp;
61 me_problem = result_info->appsRet.setupCall.meProblem;
62 call_ctrl_problem = result_info->appsRet.setupCall.permanentCallCtrlProblem;
63 call_cause = result_info->appsRet.setupCall.tapiCause;
64 result = g_variant_new("(iiii)", exec_result, me_problem, call_ctrl_problem, call_cause);
66 case TAPI_SAT_CMD_TYPE_SEND_SS:{
67 gint exec_result, me_problem, ss_cause, call_ctrl_problem, ss_str_len;
68 gchar *ss_string = NULL;
69 dbg("send ss : result format (iiisii)");
71 exec_result = result_info->appsRet.sendSs.resp;
72 me_problem = result_info->appsRet.sendSs.meProblem;
73 ss_cause = result_info->appsRet.sendSs.ssCause;
74 call_ctrl_problem = result_info->appsRet.sendSs.additionalCallCtrlProblemInfo;
75 ss_str_len = result_info->appsRet.sendSs.ssString.stringLen;
76 ss_string = g_strdup((gchar*)result_info->appsRet.sendSs.ssString.string);
78 result = g_variant_new("(iiisii)", exec_result, me_problem, ss_cause, ss_string, ss_str_len, call_ctrl_problem);
80 case TAPI_SAT_CMD_TYPE_SEND_USSD:{
82 gint exec_result, me_problem, ss_cause, ussd_str_len;
83 GVariantBuilder *builder = NULL;
84 GVariant *ussd_str = NULL;
86 dbg("send ussd : result format (iiivi)");
88 exec_result = result_info->appsRet.sendUssd.resp;
89 me_problem = result_info->appsRet.sendUssd.meProblem;
90 ss_cause = result_info->appsRet.sendUssd.ssCause;
91 ussd_str_len = result_info->appsRet.sendUssd.ussdString.stringLen;
93 builder = g_variant_builder_new(G_VARIANT_TYPE ("ay"));
94 for (index = 0; index < ussd_str_len; index++) {
95 dbg("index(%d) data(%d)", index, result_info->appsRet.sendUssd.ussdString.string[index]);
96 g_variant_builder_add(builder, "y", result_info->appsRet.sendUssd.ussdString.string[index]);
98 ussd_str = g_variant_builder_end(builder);
100 result = g_variant_new("(iiivi)", exec_result, me_problem, ss_cause, ussd_str, ussd_str_len);
102 case TAPI_SAT_CMD_TYPE_SEND_SMS:{
104 dbg("send sms: result format (i)");
106 exec_result = result_info->appsRet.sendSms.resp;
107 result = g_variant_new("(i)", exec_result);
109 case TAPI_SAT_CMD_TYPE_SEND_DTMF:{
111 dbg("send DTMF: result format (i)");
113 exec_result = result_info->appsRet.sendDtmf.resp;
114 result = g_variant_new("(i)", exec_result);
116 case TAPI_SAT_CMD_TYPE_LAUNCH_BROWSER:{
117 gint exec_result, browser_problem;
118 dbg("launch browser: result format (ii)");
120 exec_result = result_info->appsRet.launchBrowser.resp;
121 browser_problem = result_info->appsRet.launchBrowser.browserProblem;
122 result = g_variant_new("(ii)", exec_result, browser_problem);
124 case TAPI_SAT_CMD_TYPE_SETUP_IDLE_MODE_TEXT:{
126 dbg("setup idle mode text: result format (i)");
128 exec_result = result_info->appsRet.setupIdleModeText.resp;
129 result = g_variant_new("(i)", exec_result);
131 case TAPI_SAT_CMD_TYPE_LANGUAGE_NOTIFICATION:{
133 dbg("language notification: result format (i)");
135 exec_result = result_info->appsRet.languageNoti.resp;
136 result = g_variant_new("(i)", exec_result);
138 case TAPI_SAT_CMD_TYPE_PROVIDE_LOCAL_INFO:{
140 dbg("provide local info: result format (i)");
142 exec_result = result_info->appsRet.provideLocalInfo.resp;
143 result = g_variant_new("(i)", exec_result);
145 case TAPI_SAT_CMD_TYPE_PLAY_TONE:{
147 dbg("play tone: result format (i)");
149 exec_result = result_info->appsRet.playTone.resp;
150 result = g_variant_new("(i)", exec_result);
152 case TAPI_SAT_CMD_TYPE_DISPLAY_TEXT:{
153 gint exec_result, me_problem;
154 dbg("display text: result format (ii)");
156 exec_result = result_info->appsRet.displayText.resp;
157 me_problem = result_info->appsRet.displayText.meProblem;
158 result = g_variant_new("(ii)", exec_result, me_problem);
161 dbg("unhandled command type(0x%x", result_info->commandType);
168 static GVariant* _tapi_sat_gen_event_download_data(const TelSatEventDownloadReqInfo_t *pEventData)
170 GVariant *result = NULL;
172 switch(pEventData->eventDownloadType)
174 case TAPI_EVENT_SAT_DW_TYPE_IDLE_SCREEN_AVAILABLE:{
175 gboolean idle_screen;
176 dbg("idle screen available (%d)", pEventData->u.bIdleScreenAvailable);
178 idle_screen = pEventData->u.bIdleScreenAvailable;
179 result = g_variant_new("(b)", idle_screen);
181 case TAPI_EVENT_SAT_DW_TYPE_LANGUAGE_SELECTION:{
182 gint selected_language;
183 dbg("selected language (%d)", pEventData->u.languageSelectionEventReqInfo.language);
185 selected_language = pEventData->u.languageSelectionEventReqInfo.language;
186 result = g_variant_new("(i)", selected_language);
188 case TAPI_EVENT_SAT_DW_TYPE_BROWSER_TERMINATION:{
189 gint browser_termination_cause;
190 dbg("Cause of browser termination (%d)", pEventData->u.browserTerminationEventReqInfo.browserTerminationCause);
192 browser_termination_cause = pEventData->u.browserTerminationEventReqInfo.browserTerminationCause;
193 result = g_variant_new("(i)", browser_termination_cause);
195 case TAPI_EVENT_SAT_DW_TYPE_DATA_AVAILABLE:
196 case TAPI_EVENT_SAT_DW_TYPE_CHANNEL_STATUS:
198 dbg("not support download event (%d)", pEventData->eventDownloadType);
205 static void on_response_menu_selection_envelop(GObject *source_object, GAsyncResult *res, gpointer user_data)
207 GError *error = NULL;
208 GDBusConnection *conn = NULL;
211 struct tapi_resp_data *evt_cb_data = user_data;
216 conn = G_DBUS_CONNECTION (source_object);
217 rst = g_dbus_connection_call_finish(conn, res, &error);
221 evt_cb_data->cb_fn(evt_cb_data->handle, result, &envelop_rsp, evt_cb_data->user_data);
223 g_error_free (error);
228 g_variant_get (rst, "(ii)", &result, &envelop_rsp);
229 dbg("menu selection envelop result(%d) envelop response(%d)", result, envelop_rsp);
231 if (evt_cb_data->cb_fn) {
232 evt_cb_data->cb_fn(evt_cb_data->handle, result, &envelop_rsp, evt_cb_data->user_data);
235 g_variant_unref(rst);
239 static void on_response_download_event_envelop(GObject *source_object, GAsyncResult *res, gpointer user_data)
241 GError *error = NULL;
242 GDBusConnection *conn = NULL;
245 struct tapi_resp_data *evt_cb_data = user_data;
250 conn = G_DBUS_CONNECTION (source_object);
251 rst = g_dbus_connection_call_finish(conn, res, &error);
255 evt_cb_data->cb_fn(evt_cb_data->handle, result, &envelop_rsp, evt_cb_data->user_data);
257 g_error_free (error);
262 g_variant_get (rst, "(ii)", &result, &envelop_rsp);
263 dbg("download event envelop result(%d) envelop response(%d)", result, envelop_rsp);
265 if (evt_cb_data->cb_fn) {
266 evt_cb_data->cb_fn(evt_cb_data->handle, result, &envelop_rsp, evt_cb_data->user_data);
269 g_variant_unref(rst);
275 * To send envelope command (MENU SELECTION) to USIM.
277 * @return values in enum TapiResult_t.
278 * @param[in] TelSatMenuSelectionReqInfo_t menu selection evelope data.
279 * @Interface Asynchronous.
281 * @Refer TelSatMenuSelectionReqInfo_t
284 EXPORT_API int tel_select_sat_menu(TapiHandle *handle, const TelSatMenuSelectionReqInfo_t *pMenuSelect, tapi_response_cb callback, void *user_data)
288 GVariant *inparam = NULL;
289 struct tapi_resp_data *evt_cb_data = NULL;
291 dbg("Func Entrance ");
293 if (!handle || !handle->dbus_connection || !pMenuSelect){
294 dbg("invalid parameter");
295 return TAPI_API_INVALID_INPUT;
298 MAKE_RESP_CB_DATA(evt_cb_data, handle, callback, user_data);
300 item_id = pMenuSelect->itemIdentifier;
301 help_req = ( (pMenuSelect->bIsHelpRequested != 0) ? TRUE : FALSE);
302 dbg("item id(%d) help request(%d)", item_id, help_req);
303 inparam = g_variant_new("(ib)", item_id, help_req);
305 g_dbus_connection_call(handle->dbus_connection, DBUS_TELEPHONY_SERVICE, handle->path,
306 DBUS_TELEPHONY_SAT_INTERFACE, "SelectMenu", inparam, NULL, G_DBUS_CALL_FLAGS_NONE, -1,
307 handle->ca, on_response_menu_selection_envelop, evt_cb_data);
309 g_variant_unref(inparam);
311 return TAPI_API_SUCCESS;
316 * API to send event download to SIM.
318 * @return values in enum TapiResult_t.
319 * @param[in] TelSatEventDownloadReqInfo_t event download data.
320 * @Interface Asynchronous.
322 * @Refer TelSatEventDownloadReqInfo_t
324 EXPORT_API int tel_download_sat_event(TapiHandle *handle, const TelSatEventDownloadReqInfo_t *pEventData, tapi_response_cb callback, void *user_data)
326 gboolean evt_check = FALSE;
328 gint event_download_type, src_dev, dest_dev;
329 GVariant *download_data = NULL;
331 GVariant *inparam = NULL;
332 struct tapi_resp_data *evt_cb_data = NULL;
334 dbg("Func Entrance ");
336 if (!handle || !handle->dbus_connection || !pEventData){
337 dbg("invalid parameter");
338 return TAPI_API_INVALID_INPUT;
341 for(g_index = 0; g_event_list[g_index] > 0; g_index++){
342 if(g_event_list[g_index] == pEventData->eventDownloadType ){
343 dbg("event (%d) shoud be passed to sim");
349 dbg("sim does not request event(%d)", pEventData->eventDownloadType);
350 return TAPI_API_SAT_EVENT_NOT_REQUIRED_BY_USIM;
353 MAKE_RESP_CB_DATA(evt_cb_data, handle, callback, user_data);
355 event_download_type = pEventData->eventDownloadType;
356 src_dev = TAPI_SAT_DEVICE_ID_ME;
357 dest_dev = TAPI_SAT_DEVICE_ID_SIM;
358 download_data = _tapi_sat_gen_event_download_data(pEventData);
359 dbg("event type(%d)", event_download_type);
360 inparam = g_variant_new("(iiiv)", event_download_type, src_dev, dest_dev, download_data);
362 g_dbus_connection_call(handle->dbus_connection, DBUS_TELEPHONY_SERVICE, handle->path,
363 DBUS_TELEPHONY_SAT_INTERFACE, "DownloadEvent", inparam, NULL, G_DBUS_CALL_FLAGS_NONE, -1,
364 handle->ca, on_response_download_event_envelop, evt_cb_data);
366 g_variant_unref(inparam);
368 return TAPI_API_SUCCESS;
373 * API to get main menu information.
375 * @return values in enum TapiResult_t.
376 * @param[out] TelSatSetupMenuInfo_t main menu data.
377 * @Interface Synchronous.
379 * @Refer TelSatSetupMenuInfo_t
381 EXPORT_API int tel_get_sat_main_menu_info(TapiHandle *handle, TelSatSetupMenuInfo_t *pMainMenu)
384 GVariant *rst = NULL;
387 gint result, command_id, item_cnt;
388 gboolean b_present, b_helpinfo, b_updated;
389 GVariant *items = NULL;
391 dbg("Func Entrance ");
393 if (!handle || !handle->dbus_connection || !pMainMenu){
394 dbg("invalid parameter");
395 return TAPI_API_INVALID_INPUT;
398 memset(pMainMenu, 0, sizeof(TelSatSetupMenuInfo_t));
401 rst = g_dbus_connection_call_sync(handle->dbus_connection, DBUS_TELEPHONY_SERVICE , handle->path,
402 DBUS_TELEPHONY_SAT_INTERFACE, "GetMainMenuInfo", NULL, NULL, G_DBUS_CALL_FLAGS_NONE, -1, NULL, &error);
405 dbg( "error to get main menu(%s)", error->message);
406 g_error_free (error);
407 return TAPI_API_OPERATION_FAILED;
410 dbg("menu_info type_format(%s)", g_variant_get_type_string(rst));
412 g_variant_get(rst, "(iibs@vibb)", &result, &command_id, &b_present, &title, &items, &item_cnt,
413 &b_helpinfo, &b_updated);
415 pMainMenu->commandId = command_id;
416 pMainMenu->bIsMainMenuPresent = (b_present ? 1 : 0);
417 memcpy(pMainMenu->satMainTitle, title, TAPI_SAT_DEF_TITLE_LEN_MAX+1);
418 pMainMenu->satMainMenuNum = item_cnt;
419 if(items && item_cnt > 0){
426 unbox = g_variant_get_variant(items);
427 dbg("items(%p) items type_format(%s)", items, g_variant_get_type_string(unbox));
429 g_variant_get(unbox, "a(si)", &iter);
430 while(g_variant_iter_loop(iter,"(si)",&item_str, &item_id)){
431 pMainMenu->satMainMenuItem[index].itemId = item_id;
432 memcpy(pMainMenu->satMainMenuItem[index].itemString, item_str, TAPI_SAT_DEF_ITEM_STR_LEN_MAX + 6);
433 dbg("item index(%d) id(%d) str(%s)",index, pMainMenu->satMainMenuItem[index].itemId, pMainMenu->satMainMenuItem[index].itemString);
434 //dbg("item index(%d) id(%d) str(%s)",index, item_id, item_str);
437 g_variant_iter_free(iter);
439 pMainMenu->bIsSatMainMenuHelpInfo = (b_helpinfo ? 1 : 0);
440 pMainMenu->bIsUpdatedSatMainMenu = (b_updated ? 1 : 0);
442 dbg("result (%d)", result);
443 dbg("command id (%d)", pMainMenu->commandId);
444 dbg("menu present (%d)", pMainMenu->bIsMainMenuPresent);
445 dbg("menu title (%s)", pMainMenu->satMainTitle);
446 dbg("item cnt (%d)", pMainMenu->satMainMenuNum);
447 dbg("menu help info (%d)", pMainMenu->bIsSatMainMenuHelpInfo);
448 dbg("menu updated (%d)", pMainMenu->bIsUpdatedSatMainMenu);
450 return TAPI_API_SUCCESS;
455 * API to send UI display status.
457 * @return values in enum TapiResult_t.
458 * @param[in] TelSatUiDisplayStatusType_t display status data.
459 command_id command identifier
460 * @Interface Asynchronous.
462 * @Refer TelSatUiDisplayStatusType_t
464 EXPORT_API int tel_send_sat_ui_display_status(TapiHandle *handle, int commandId, TelSatUiDisplayStatusType_t status)
467 GVariant *rst = NULL;
469 gint result, command_id;
470 gboolean display_status;
471 GVariant *inparam = NULL;
473 dbg("Func Entrance ");
475 if (!handle || !handle->dbus_connection){
476 dbg("invalid parameter");
477 return TAPI_API_INVALID_INPUT;
480 command_id = commandId;
481 display_status = ( (status == TAPI_SAT_DISPLAY_SUCCESS) ? TRUE : FALSE);
482 dbg("command id(%d) display status(%d)", command_id, display_status);
483 inparam = g_variant_new("(ib)", command_id, display_status);
486 rst = g_dbus_connection_call_sync(handle->dbus_connection, DBUS_TELEPHONY_SERVICE , handle->path,
487 DBUS_TELEPHONY_SAT_INTERFACE, "SendUiDisplayStatus", inparam, NULL, G_DBUS_CALL_FLAGS_NONE, -1, NULL, &error);
490 dbg( "error to send ui display status(%s)", error->message);
491 g_error_free (error);
492 return TAPI_API_OPERATION_FAILED;
495 dbg("send ui display status format(%s)", g_variant_get_type_string(rst));
497 g_variant_get(rst, "(i)", &result);
499 result = TAPI_API_SUCCESS;
502 result = TAPI_API_OPERATION_FAILED;
504 dbg("result (%d)", result);
511 * API to send UI user confirmation data.
513 * @return values in enum TapiResult_t.
514 * @param[in] command_id command identifier
515 command_type command type
516 key_type user confirmation value
517 addtional_data addtional data
519 * @Interface Asynchronous.
523 EXPORT_API int tel_send_sat_ui_user_confirm(TapiHandle *handle, TelSatUiUserConfirmInfo_t *pUserConfirmData)
526 GVariant *rst = NULL;
527 GVariantBuilder *builder = NULL;
528 GVariant *inner_gv = NULL;
532 gint result, command_id, command_type, key_type, data_len;
533 GVariant *inparam = NULL;
535 dbg("Func Entrance ");
537 if (!handle || !handle->dbus_connection || !pUserConfirmData){
538 dbg("invalid parameter");
539 return TAPI_API_INVALID_INPUT;
542 command_id = pUserConfirmData->commandId;
543 command_type = pUserConfirmData->commandType;
544 key_type = pUserConfirmData->keyType;
545 data = (gchar *)pUserConfirmData->pAdditionalData;
546 data_len = pUserConfirmData->dataLen;
548 builder = g_variant_builder_new(G_VARIANT_TYPE ("ay"));
549 for (index = 0; index < data_len; index++) {
550 dbg("index(%d) data(%d)", index, data[index]);
551 g_variant_builder_add(builder, "y", data[index]);
553 inner_gv = g_variant_builder_end(builder);
555 dbg("command id(%d) command type(%d) key type(%d) data len(%d)",
556 command_id, command_type, key_type, data_len);
557 inparam = g_variant_new("(iiiv)", command_id, command_type, key_type, inner_gv);
560 rst = g_dbus_connection_call_sync(handle->dbus_connection, DBUS_TELEPHONY_SERVICE , handle->path,
561 DBUS_TELEPHONY_SAT_INTERFACE, "SendUserConfirm", inparam, NULL, G_DBUS_CALL_FLAGS_NONE, -1, NULL, &error);
564 dbg( "error to send ui user confirm(%s)", error->message);
565 g_error_free (error);
566 return TAPI_API_OPERATION_FAILED;
569 dbg("send ui user confirm format(%s)", g_variant_get_type_string(rst));
571 g_variant_get(rst, "(i)", &result);
573 result = TAPI_API_SUCCESS;
576 result = TAPI_API_OPERATION_FAILED;
578 dbg("result (%d)", result);
585 * API to send application excution result.
587 * @return values in enum TapiResult_t.
588 * @param[in] TelSatAppsRetInfo_t application result information data.
589 * @Interface Asynchronous.
591 * @Refer TelSatAppsRetInfo_t
593 EXPORT_API int tel_send_sat_app_exec_result(TapiHandle *handle, TelSatAppsRetInfo_t *pAppRetInfo)
596 GVariant *rst = NULL;
598 gint result, command_id, command_type;
599 GVariant *app_exec_result = NULL;
600 GVariant *inparam = NULL;
602 dbg("Func Entrance ");
604 if (!handle || !handle->dbus_connection || !pAppRetInfo){
605 dbg("invalid parameter");
606 return TAPI_API_INVALID_INPUT;
609 command_id = pAppRetInfo->commandId;
610 command_type = pAppRetInfo->commandType;
611 app_exec_result = _tapi_sat_gen_app_exec_result_data(pAppRetInfo);
613 dbg("command id(%d) command type(%d) exec_result(%s)", command_id, command_type, g_variant_get_type_string(app_exec_result));
614 inparam = g_variant_new("(iiv)", command_id, command_type, app_exec_result);
617 dbg("test (%s)", g_variant_get_type_string(inparam));
618 rst = g_dbus_connection_call_sync(handle->dbus_connection, DBUS_TELEPHONY_SERVICE , handle->path,
619 DBUS_TELEPHONY_SAT_INTERFACE, "SendAppExecResult", inparam, NULL, G_DBUS_CALL_FLAGS_NONE, -1, NULL, &error);
622 dbg( "error to send app execution result(%s)", error->message);
623 g_error_free (error);
624 return TAPI_API_OPERATION_FAILED;
627 dbg("send app execution result format(%s)", g_variant_get_type_string(rst));
629 g_variant_get(rst, "(i)", &result);
631 result = TAPI_API_SUCCESS;
634 result = TAPI_API_OPERATION_FAILED;
636 dbg("result (%d)", result);