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 <user_request.h>
31 #include "generated-code.h"
32 #include "dtapi_common.h"
34 static gboolean on_modem_set_power(TelephonyModem *modem,
35 GDBusMethodInvocation *invocation, gint mode, gpointer user_data)
37 struct custom_data *ctx = user_data;
38 enum tcore_request_command command;
41 case MODEM_STATE_ONLINE:
42 command = TREQ_MODEM_POWER_ON;
45 case MODEM_STATE_OFFLINE:
46 command = TREQ_MODEM_POWER_OFF;
49 case MODEM_STATE_RESET:
50 command = TREQ_MODEM_POWER_RESET;
54 command = TREQ_MODEM_POWER_LOW;
58 FAIL_RESPONSE(invocation, DEFAULT_MSG_REQ_FAILED);
62 /* Dispatch request */
63 dtapi_dispatch_request(ctx, modem, invocation,
70 static gboolean on_modem_set_flight_mode(TelephonyModem *modem,
71 GDBusMethodInvocation *invocation, gboolean enable, gpointer user_data)
73 struct treq_modem_set_flightmode req;
74 struct custom_data *ctx = user_data;
78 /* Dispatch request */
79 dtapi_dispatch_request(ctx, modem, invocation,
80 TREQ_MODEM_SET_FLIGHTMODE,
81 &req, sizeof(struct treq_modem_set_flightmode));
86 static gboolean on_modem_get_flight_mode(TelephonyModem *modem,
87 GDBusMethodInvocation *invocation, gpointer user_data)
89 struct custom_data *ctx = user_data;
91 /* Dispatch request */
92 dtapi_dispatch_request(ctx, modem, invocation,
93 TREQ_MODEM_GET_FLIGHTMODE,
99 static gboolean on_modem_get_version(TelephonyModem *modem,
100 GDBusMethodInvocation *invocation, gpointer user_data)
102 struct custom_data *ctx = user_data;
104 /* Dispatch request */
105 dtapi_dispatch_request(ctx, modem, invocation,
106 TREQ_MODEM_GET_VERSION,
112 static gboolean on_modem_get_serial_number(TelephonyModem *modem,
113 GDBusMethodInvocation *invocation, gpointer user_data)
115 struct custom_data *ctx = user_data;
117 /* Dispatch request */
118 dtapi_dispatch_request(ctx, modem, invocation,
125 static gboolean on_modem_get_imei(TelephonyModem *modem,
126 GDBusMethodInvocation *invocation, gpointer user_data)
128 struct custom_data *ctx = user_data;
130 /* Dispatch request */
131 dtapi_dispatch_request(ctx, modem, invocation,
138 static gboolean on_modem_set_dun_pin_ctrl(TelephonyModem *modem,
139 GDBusMethodInvocation *invocation,
140 gint signal, gboolean status, gpointer user_data)
142 struct treq_modem_set_dun_pin_control req;
143 struct custom_data *ctx = user_data;
148 /* Dispatch request */
149 dtapi_dispatch_request(ctx, modem, invocation,
150 TREQ_MODEM_GET_VERSION,
151 &req, sizeof(struct treq_modem_set_dun_pin_control));
156 static gboolean on_modem_get_device_info(TelephonyModem *modem,
157 GDBusMethodInvocation *invocation, gpointer user_data)
159 struct custom_data *ctx = user_data;
161 /* Dispatch request */
162 dtapi_dispatch_request(ctx, modem, invocation,
163 TREQ_MODEM_GET_DEVICE_INFO,
169 gboolean dbus_plugin_setup_modem_interface(TelephonyObjectSkeleton *object,
170 struct custom_data *ctx)
172 TelephonyModem *modem;
174 modem = telephony_modem_skeleton_new();
175 telephony_object_skeleton_set_modem(object, modem);
176 g_object_unref(modem);
178 dbg("modem: [%p]", modem);
181 * Register signal handlers for Modem interface
183 g_signal_connect(modem,
185 G_CALLBACK(on_modem_set_power), ctx);
187 g_signal_connect(modem,
188 "handle-set-flight-mode",
189 G_CALLBACK(on_modem_set_flight_mode), ctx);
191 g_signal_connect(modem,
192 "handle-get-flight-mode",
193 G_CALLBACK(on_modem_get_flight_mode), ctx);
195 g_signal_connect(modem,
196 "handle-get-version",
197 G_CALLBACK(on_modem_get_version), ctx);
199 g_signal_connect(modem,
200 "handle-get-serial-number",
201 G_CALLBACK(on_modem_get_serial_number), ctx);
203 g_signal_connect(modem,
205 G_CALLBACK(on_modem_get_imei), ctx);
207 g_signal_connect(modem,
208 "handle-set-dun-pin-ctrl",
209 G_CALLBACK(on_modem_set_dun_pin_ctrl), ctx);
211 g_signal_connect(modem,
212 "handle-get-device-info",
213 G_CALLBACK(on_modem_get_device_info), ctx);
216 * Initialize 'properties'
218 telephony_modem_set_power(modem, MODEM_STATE_UNKNOWN);
223 gboolean dbus_plugin_modem_response(struct custom_data *ctx,
224 UserRequest *ur, struct dbus_request_info *dbus_info,
225 enum tcore_response_command command, unsigned int data_len, const void *data)
227 char *cpname = GET_CP_NAME(dbus_info->invocation);
230 case TRESP_MODEM_SET_FLIGHTMODE: {
231 const struct tresp_modem_set_flightmode *resp_set_flight_mode = data;
232 int set_flight_mode = 3; /* TAPI_POWER_FLIGHT_MODE_RESP_FAIL */
234 if (resp_set_flight_mode->result == TCORE_RETURN_SUCCESS) {
235 const struct treq_modem_set_flightmode *treq_data;
236 treq_data = tcore_user_request_ref_data(ur, NULL);
237 if (treq_data == NULL) {
238 warn("No Request data!!!");
239 set_flight_mode = 3; /* TAPI_POWER_FLIGHT_MODE_RESP_FAIL */
240 } else if (treq_data->enable == TRUE) {
241 set_flight_mode = 1; /* TAPI_POWER_FLIGHT_MODE_RESP_ON */
243 set_flight_mode = 2; /* TAPI_POWER_FLIGHT_MODE_RESP_OFF */
247 dbg("[%s] SET_FLIGHTMODE - [%s] [%s]", cpname,
248 (resp_set_flight_mode->result == TCORE_RETURN_SUCCESS ? "Success" : "Fail"),
249 (set_flight_mode == 1 ? "ON" :
250 (set_flight_mode == 2 ? "OFF" : "Request FAIL")));
252 telephony_modem_complete_set_flight_mode(dbus_info->interface_object,
253 dbus_info->invocation, set_flight_mode);
257 case TRESP_MODEM_GET_FLIGHTMODE: {
258 const struct tresp_modem_get_flightmode *resp_get_flight_mode = data;
260 dbg("[%s] GET_FLIGHTMODE - [%s]", cpname,
261 (resp_get_flight_mode->result == TCORE_RETURN_SUCCESS ? "Success" : "Fail"));
263 telephony_modem_complete_get_flight_mode(dbus_info->interface_object,
264 dbus_info->invocation,
265 resp_get_flight_mode->enable, resp_get_flight_mode->result);
269 case TRESP_MODEM_POWER_ON: {
270 const struct tresp_modem_power_on *resp_modem_power_on = data;
273 dbg("[%s] POWER_ON - [%s]", cpname,
274 (resp_modem_power_on->result == TCORE_RETURN_SUCCESS ? "Success" : "Fail"));
276 /* TBD: value should be defined in TAPI */
277 if (resp_modem_power_on->result == TCORE_RETURN_EALREADY)
279 else if (resp_modem_power_on->result == TCORE_RETURN_OPERATION_ABORTED)
282 telephony_modem_complete_set_power(dbus_info->interface_object,
283 dbus_info->invocation, result);
287 case TRESP_MODEM_POWER_OFF: {
288 dbg("[%s] POWER_OFF", cpname);
290 telephony_modem_complete_set_power(dbus_info->interface_object,
291 dbus_info->invocation, 0);
295 case TRESP_MODEM_POWER_RESET: {
296 dbg("[%s] POWER_RESET", cpname);
298 telephony_modem_complete_set_power(dbus_info->interface_object,
299 dbus_info->invocation, 0);
303 case TRESP_MODEM_POWER_LOW: {
304 dbg("[%s] POWER_LOW", cpname);
306 telephony_modem_complete_set_power(dbus_info->interface_object,
307 dbus_info->invocation, 0);
311 case TRESP_MODEM_GET_IMEI: {
312 const struct tresp_modem_get_imei *resp_get_imei = data;
314 dbg("[%s] GET_IMEI - [%s]", cpname,
315 (resp_get_imei->result == TCORE_RETURN_SUCCESS ? "Success" : "Fail"));
317 telephony_modem_complete_get_imei(dbus_info->interface_object,
318 dbus_info->invocation,
319 resp_get_imei->result, resp_get_imei->imei);
323 case TRESP_MODEM_GET_SN: {
324 const struct tresp_modem_get_sn *resp_get_sn = data;
326 dbg("[%s] GET_SN - [%s]", cpname,
327 (resp_get_sn->result == TCORE_RETURN_SUCCESS ? "Success" : "Fail"));
329 telephony_modem_complete_get_serial_number(dbus_info->interface_object,
330 dbus_info->invocation, resp_get_sn->result,
331 resp_get_sn->sn, resp_get_sn->meid,
332 resp_get_sn->imei, resp_get_sn->imeisv);
336 case TRESP_MODEM_GET_VERSION: {
337 const struct tresp_modem_get_version *resp_get_version = data;
339 dbg("[%s] GET_VERSION - [%s]", cpname,
340 (resp_get_version->result == TCORE_RETURN_SUCCESS ? "Success" : "Fail"));
342 telephony_modem_complete_get_version(dbus_info->interface_object,
343 dbus_info->invocation, resp_get_version->result,
344 resp_get_version->software, resp_get_version->hardware,
345 resp_get_version->calibration, resp_get_version->product_code,
346 resp_get_version->prl_version, resp_get_version->eri_version);
350 case TRESP_MODEM_SET_DUN_PIN_CONTROL: {
351 const struct tresp_modem_set_dun_pin_control *resp_dun_pin_ctrl = data;
353 dbg("[%s] SET_DUN_PIN_CONTROL - [%s]", cpname,
354 (resp_dun_pin_ctrl->result == TCORE_RETURN_SUCCESS ? "Success" : "Fail"));
356 telephony_modem_complete_set_dun_pin_ctrl(dbus_info->interface_object,
357 dbus_info->invocation, resp_dun_pin_ctrl->result);
361 case TRESP_MODEM_GET_DEVICE_INFO: {
362 const struct tresp_modem_get_device_info *resp_get_device_info = data;
364 dbg("[%s] TGET_DEVICE_INFO - Vendor[%s] Device[%s]", cpname,
365 resp_get_device_info->vendor_name,
366 resp_get_device_info->device_name);
368 telephony_modem_complete_get_device_info(dbus_info->interface_object,
369 dbus_info->invocation, resp_get_device_info->result,
370 resp_get_device_info->vendor_name, resp_get_device_info->device_name);
375 err("Unhandled/Unknown Response: [0x%x]", command);
382 gboolean dbus_plugin_modem_notification(struct custom_data *ctx,
383 CoreObject *source, TelephonyObjectSkeleton *object,
384 enum tcore_notification_command command, unsigned int data_len, const void *data)
386 TelephonyModem *modem;
388 cp_name = tcore_server_get_cp_name_by_plugin(tcore_object_ref_plugin(source));
391 dbg("object is NULL");
394 modem = telephony_object_peek_modem(TELEPHONY_OBJECT(object));
396 err("modem object is NULL!!!");
401 case TNOTI_MODEM_POWER: {
402 const struct tnoti_modem_power *info = data;
403 enum modem_state state = info->state;
405 dbg("[%s] MODEM_POWER: [%s]", cp_name,
406 (state == MODEM_STATE_UNKNOWN ? "UNKNOWN" :
407 (state == MODEM_STATE_ONLINE ? "ONLINE" :
408 (state == MODEM_STATE_OFFLINE ? "OFFLINE" :
409 (state == MODEM_STATE_RESET ? "RESET" :
410 (state == MODEM_STATE_LOW ? "LOW" :
411 "INTERNAL STATE"))))));
412 if (state > MODEM_STATE_MAX)
415 telephony_modem_emit_power(modem, state);
416 telephony_modem_set_power(modem, state);
420 case TNOTI_MODEM_DUN_PIN_CONTROL: {
421 const struct tnoti_modem_dun_pin_control *pin = data;
423 dbg("[%s] MODEM_DUN_PIN_CONTROL (Signal: [0x%2x] Status: [0x%2x])",
424 cp_name, pin->signal, pin->status);
426 telephony_modem_emit_dun_pin_ctrl(modem, pin->signal, pin->status);
430 case TNOTI_MODEM_DUN_EXTERNAL_CALL: {
431 dbg("[%s] MODEM_DUN_EXTERNAL_CALL", cp_name);
433 telephony_modem_emit_dun_external_call(modem, TRUE);
437 case TNOTI_MODEM_DONGLE_STATUS:
438 dbg("[%s] MODEM_DONGLE_STATUS (state:[%d])", cp_name, *(int *)data);
439 telephony_modem_set_dongle_status(modem, *(int *)data);
442 case TNOTI_MODEM_DONGLE_LOGIN:
443 dbg("[%s] MODEM_DONGLE_LOGIN (login state:[%d])", cp_name, *(int *)data);
444 telephony_modem_set_dongle_login(modem, *(int *)data);
448 err("Unhandled/Unknown Notification: [0x%x]", command);