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.
34 #include <communicator.h>
37 #include <user_request.h>
40 #include "generated-code.h"
45 on_modem_set_power (TelephonyModem *modem, GDBusMethodInvocation *invocation,
46 gint mode, gpointer user_data)
48 struct custom_data *ctx = user_data;
49 UserRequest *ur = NULL;
50 enum tcore_request_command command;
51 TReturn ret = TCORE_RETURN_SUCCESS;
53 if (!check_access_control (invocation, AC_MODEM, "w"))
56 ur = MAKE_UR(ctx, modem, invocation);
61 case MODEM_STATE_ONLINE:
62 command = TREQ_MODEM_POWER_ON;
64 case MODEM_STATE_OFFLINE:
65 command = TREQ_MODEM_POWER_OFF;
67 case MODEM_STATE_RESET:
68 command = TREQ_MODEM_POWER_RESET;
71 command = TREQ_MODEM_POWER_LOW;
74 ret = TCORE_RETURN_EINVAL;
78 tcore_user_request_set_command(ur, command);
79 ret = tcore_communicator_dispatch_request(ctx->comm, ur);
80 if (ret != TCORE_RETURN_SUCCESS)
86 FAIL_RESPONSE (invocation, DEFAULT_MSG_REQ_FAILED);
87 tcore_user_request_unref(ur);
93 on_modem_set_flight_mode (TelephonyModem *modem, GDBusMethodInvocation *invocation,
94 gboolean enable, gpointer user_data)
96 struct treq_modem_set_flightmode data;
97 struct custom_data *ctx = user_data;
98 UserRequest *ur = NULL;
101 if (!check_access_control (invocation, AC_MODEM, "w"))
104 ur = MAKE_UR(ctx, modem, invocation);
108 data.enable = enable;
109 if (TCORE_RETURN_SUCCESS != tcore_user_request_set_data (ur, sizeof(data), &data))
111 tcore_user_request_set_command (ur, TREQ_MODEM_SET_FLIGHTMODE);
113 ret = tcore_communicator_dispatch_request (ctx->comm, ur);
114 if (ret != TCORE_RETURN_SUCCESS)
120 FAIL_RESPONSE (invocation, DEFAULT_MSG_REQ_FAILED);
121 tcore_user_request_unref(ur);
127 on_modem_get_flight_mode (TelephonyModem *modem, GDBusMethodInvocation *invocation,
130 struct custom_data *ctx = user_data;
131 UserRequest *ur = NULL;
134 if (!check_access_control (invocation, AC_MODEM, "r"))
137 ur = MAKE_UR(ctx, modem, invocation);
141 tcore_user_request_set_data(ur, 0, NULL);
142 tcore_user_request_set_command(ur, TREQ_MODEM_GET_FLIGHTMODE);
143 ret = tcore_communicator_dispatch_request(ctx->comm, ur);
144 if (ret != TCORE_RETURN_SUCCESS)
150 FAIL_RESPONSE (invocation, DEFAULT_MSG_REQ_FAILED);
151 tcore_user_request_unref(ur);
157 on_modem_get_version (TelephonyModem *modem, GDBusMethodInvocation *invocation,
160 struct custom_data *ctx = user_data;
161 UserRequest *ur = NULL;
164 if (!check_access_control (invocation, AC_MODEM, "r"))
167 ur = MAKE_UR(ctx, modem, invocation);
171 tcore_user_request_set_command(ur, TREQ_MODEM_GET_VERSION);
172 ret = tcore_communicator_dispatch_request(ctx->comm, ur);
173 if (ret != TCORE_RETURN_SUCCESS)
179 FAIL_RESPONSE (invocation, DEFAULT_MSG_REQ_FAILED);
180 tcore_user_request_unref(ur);
186 on_modem_get_serial_number (TelephonyModem *modem, GDBusMethodInvocation *invocation,
189 struct custom_data *ctx = user_data;
190 UserRequest *ur = NULL;
193 if (!check_access_control (invocation, AC_MODEM, "r"))
196 ur = MAKE_UR(ctx, modem, invocation);
200 tcore_user_request_set_command(ur, TREQ_MODEM_GET_SN);
201 ret = tcore_communicator_dispatch_request(ctx->comm, ur);
202 if (ret != TCORE_RETURN_SUCCESS)
208 FAIL_RESPONSE (invocation, DEFAULT_MSG_REQ_FAILED);
209 tcore_user_request_unref(ur);
215 on_modem_get_imei (TelephonyModem *modem, GDBusMethodInvocation *invocation,
218 struct custom_data *ctx = user_data;
219 UserRequest *ur = NULL;
222 if (!check_access_control (invocation, AC_MODEM, "r"))
225 ur = MAKE_UR(ctx, modem, invocation);
229 tcore_user_request_set_command(ur, TREQ_MODEM_GET_IMEI);
230 ret = tcore_communicator_dispatch_request(ctx->comm, ur);
231 if (ret != TCORE_RETURN_SUCCESS)
237 FAIL_RESPONSE (invocation, DEFAULT_MSG_REQ_FAILED);
238 tcore_user_request_unref(ur);
243 static gboolean on_modem_set_dun_pin_ctrl (TelephonyModem *modem, GDBusMethodInvocation *invocation,
244 gint arg_signal, gboolean arg_status, gpointer user_data)
246 struct treq_modem_set_dun_pin_control data;
247 struct custom_data *ctx = user_data;
248 UserRequest *ur = NULL;
251 if (!check_access_control (invocation, AC_MODEM, "w"))
254 ur = MAKE_UR(ctx, modem, invocation);
258 data.signal = arg_signal;
259 data.status = arg_status;
261 if (TCORE_RETURN_SUCCESS != tcore_user_request_set_data(ur, sizeof(data), &data))
263 tcore_user_request_set_command(ur, TREQ_MODEM_SET_DUN_PIN_CONTROL);
264 ret = tcore_communicator_dispatch_request(ctx->comm, ur);
265 if (ret != TCORE_RETURN_SUCCESS)
271 FAIL_RESPONSE (invocation, DEFAULT_MSG_REQ_FAILED);
272 tcore_user_request_unref(ur);
277 gboolean dbus_plugin_setup_modem_interface(TelephonyObjectSkeleton *object, struct custom_data *ctx)
279 TelephonyModem *modem;
281 modem = telephony_modem_skeleton_new();
282 telephony_object_skeleton_set_modem(object, modem);
283 g_object_unref(modem);
285 dbg("modem: [%p]", modem);
287 g_signal_connect (modem,
289 G_CALLBACK (on_modem_set_power),
292 g_signal_connect (modem,
293 "handle-set-flight-mode",
294 G_CALLBACK (on_modem_set_flight_mode),
297 g_signal_connect (modem,
298 "handle-get-flight-mode",
299 G_CALLBACK (on_modem_get_flight_mode),
302 g_signal_connect (modem,
303 "handle-get-version",
304 G_CALLBACK (on_modem_get_version),
307 g_signal_connect (modem,
308 "handle-get-serial-number",
309 G_CALLBACK (on_modem_get_serial_number),
312 g_signal_connect (modem,
314 G_CALLBACK (on_modem_get_imei),
317 g_signal_connect (modem,
318 "handle-set-dun-pin-ctrl",
319 G_CALLBACK (on_modem_set_dun_pin_ctrl),
322 telephony_modem_set_power(modem, MODEM_STATE_UNKNOWN);
327 gboolean dbus_plugin_modem_response(struct custom_data *ctx, UserRequest *ur,
328 struct dbus_request_info *dbus_info, enum tcore_response_command command,
329 unsigned int data_len, const void *data)
331 dbg("Response!!! Command: [0x%x] CP Name: [%s]",
332 command, GET_CP_NAME(dbus_info->invocation));
335 case TRESP_MODEM_SET_FLIGHTMODE: {
336 const struct tresp_modem_set_flightmode *resp_set_flight_mode = data;
337 int info_set_flight_mode = 3; /* TAPI_POWER_FLIGHT_MODE_RESP_FAIL */
339 dbg("TRESP_MODEM_SET_FLIGHTMODE - Result: [%s]",
340 (resp_set_flight_mode->result == TCORE_RETURN_SUCCESS ? "Success" : "Fail"));
342 if (resp_set_flight_mode->result == TCORE_RETURN_SUCCESS) {
343 const struct treq_modem_set_flightmode *treq_data;
344 treq_data = tcore_user_request_ref_data(ur, NULL);
345 if (treq_data == NULL) {
346 warn("No Request data!!!");
347 info_set_flight_mode = 3; /* TAPI_POWER_FLIGHT_MODE_RESP_FAIL */
349 else if (treq_data->enable == TRUE) {
350 info_set_flight_mode = 1; /* TAPI_POWER_FLIGHT_MODE_RESP_ON */
352 info_set_flight_mode = 2; /* TAPI_POWER_FLIGHT_MODE_RESP_OFF */
355 dbg("Set Flight mode: [%s]", (info_set_flight_mode == 1 ? "ON"
356 : (info_set_flight_mode == 2 ? "OFF" : "Request FAIL")));
358 telephony_modem_complete_set_flight_mode(dbus_info->interface_object, dbus_info->invocation,
359 info_set_flight_mode);
363 case TRESP_MODEM_GET_FLIGHTMODE: {
364 const struct tresp_modem_get_flightmode *resp_get_flight_mode = data;
366 dbg("TRESP_MODEM_GET_FLIGHTMODE - Result: [%s]",
367 (resp_get_flight_mode->result == TCORE_RETURN_SUCCESS ? "Success" : "Fail"));
369 telephony_modem_complete_get_flight_mode(dbus_info->interface_object, dbus_info->invocation,
370 resp_get_flight_mode->enable, resp_get_flight_mode->result);
374 case TRESP_MODEM_POWER_ON: {
375 const struct tresp_modem_power_on *resp_modem_power_on = data;
378 dbg("TRESP_MODEM_POWER_ON - Result: [%s]",
379 (resp_modem_power_on->result == TCORE_RETURN_SUCCESS ? "Success" : "Fail"));
381 /*TBD: value should be defined in TAPI*/
382 if(resp_modem_power_on->result == TCORE_RETURN_EALREADY)
384 else if(resp_modem_power_on->result == TCORE_RETURN_OPERATION_ABORTED)
387 telephony_modem_complete_set_power(dbus_info->interface_object, dbus_info->invocation, result);
391 case TRESP_MODEM_POWER_OFF: {
392 dbg("TRESP_MODEM_POWER_OFF");
394 telephony_modem_complete_set_power(dbus_info->interface_object, dbus_info->invocation, 0);
398 case TRESP_MODEM_POWER_RESET: {
399 dbg("TRESP_MODEM_POWER_RESET");
401 telephony_modem_complete_set_power(dbus_info->interface_object, dbus_info->invocation, 0);
405 case TRESP_MODEM_POWER_LOW: {
406 dbg("TRESP_MODEM_POWER_LOW");
408 telephony_modem_complete_set_power(dbus_info->interface_object, dbus_info->invocation, 0);
412 case TRESP_MODEM_GET_IMEI: {
413 const struct tresp_modem_get_imei *resp_get_imei = data;
415 dbg("TRESP_MODEM_GET_IMEI - Result: [%s]",
416 (resp_get_imei->result == TCORE_RETURN_SUCCESS ? "Success" : "Fail"));
418 telephony_modem_complete_get_imei(dbus_info->interface_object, dbus_info->invocation,
419 resp_get_imei->result, resp_get_imei->imei);
423 case TRESP_MODEM_GET_SN: {
424 const struct tresp_modem_get_sn *resp_get_sn = data;
426 dbg("TRESP_MODEM_GET_SN - Result: [%s]",
427 (resp_get_sn->result == TCORE_RETURN_SUCCESS ? "Success" : "Fail"));
429 telephony_modem_complete_get_serial_number(dbus_info->interface_object, dbus_info->invocation,
430 resp_get_sn->result, resp_get_sn->sn, resp_get_sn->meid, resp_get_sn->imei, resp_get_sn->imeisv);
434 case TRESP_MODEM_GET_VERSION: {
435 const struct tresp_modem_get_version *resp_get_version = data;
437 dbg("TRESP_MODEM_GET_VERSION - Result: [%s]",
438 (resp_get_version->result == TCORE_RETURN_SUCCESS ? "Success" : "Fail"));
440 telephony_modem_complete_get_version(dbus_info->interface_object, dbus_info->invocation,
441 resp_get_version->result,
442 resp_get_version->software,
443 resp_get_version->hardware,
444 resp_get_version->calibration,
445 resp_get_version->product_code,
446 resp_get_version->prl_version,
447 resp_get_version->eri_version);
451 case TRESP_MODEM_SET_DUN_PIN_CONTROL: {
452 const struct tresp_modem_set_dun_pin_control *resp_dun_pin_ctrl = data;
454 dbg("TRESP_MODEM_SET_DUN_PIN_CONTROL - Result: [%s]",
455 (resp_dun_pin_ctrl->result == TCORE_RETURN_SUCCESS ? "Success" : "Fail"));
457 telephony_modem_complete_set_dun_pin_ctrl(dbus_info->interface_object, dbus_info->invocation,
458 resp_dun_pin_ctrl->result);
463 err("Unhandled/Unknown Response!!!");
470 gboolean dbus_plugin_modem_notification(struct custom_data *ctx, CoreObject *source,
471 TelephonyObjectSkeleton *object, enum tcore_notification_command command,
472 unsigned int data_len, const void *data)
474 TelephonyModem *modem;
477 dbg("object is NULL");
480 dbg("Notification!!! Command: [0x%x] CP Name: [%s]",
481 command, tcore_server_get_cp_name_by_plugin(tcore_object_ref_plugin(source)));
483 modem = telephony_object_peek_modem(TELEPHONY_OBJECT(object));
484 dbg("modem: [%p]", modem);
487 case TNOTI_MODEM_POWER: {
488 const struct tnoti_modem_power *info = data;
490 dbg("TNOTI_MODEM_POWER - Modem state: [%d]", info->state);
492 if (info->state > MODEM_STATE_MAX)
495 telephony_modem_emit_power(modem, info->state);
496 telephony_modem_set_power(modem, info->state);
500 case TNOTI_MODEM_DUN_PIN_CONTROL: {
501 const struct tnoti_modem_dun_pin_control *pin = data;
503 dbg("TNOTI_MODEM_DUN_PIN_CONTROL - Signal: [0x%2x] Status: [0x%2x]", pin->signal, pin->status);
505 telephony_modem_emit_dun_pin_ctrl(modem, pin->signal, pin->status);
509 case TNOTI_MODEM_DUN_EXTERNAL_CALL: {
510 dbg("TNOTI_MODEM_DUN_EXTERNAL_CALL");
512 telephony_modem_emit_dun_external_call(modem, TRUE);
517 err("Unhandled/Unknown Notification!!!");