5 * Copyright (C) 2007-2010 Intel Corporation. All rights reserved.
6 * Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License version 2 as
10 * published by the Free Software Foundation.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
33 #define CONNMAN_API_SUBJECT_TO_CHANGE
34 #include <connman/plugin.h>
35 #include <connman/device.h>
36 #include <connman/network.h>
37 #include <connman/dbus.h>
38 #include <connman/log.h>
40 #define OFONO_SERVICE "org.ofono"
42 #define OFONO_MANAGER_INTERFACE OFONO_SERVICE ".Manager"
43 #define OFONO_MODEM_INTERFACE OFONO_SERVICE ".Modem"
44 #define OFONO_SIM_INTERFACE OFONO_SERVICE ".SimManager"
45 #define OFONO_NETREG_INTERFACE OFONO_SERVICE ".NetworkRegistration"
46 #define OFONO_CM_INTERFACE OFONO_SERVICE ".ConnectionManager"
47 #define OFONO_CONTEXT_INTERFACE OFONO_SERVICE ".ConnectionContext"
49 #define MODEM_ADDED "ModemAdded"
50 #define MODEM_REMOVED "ModemRemoved"
51 #define PROPERTY_CHANGED "PropertyChanged"
52 #define CONTEXT_ADDED "ContextAdded"
53 #define CONTEXT_REMOVED "ContextRemoved"
55 #define GET_MODEMS "GetModems"
59 static DBusConnection *connection;
61 static gboolean context_changed(DBusConnection *connection,
68 static gboolean cm_context_added(DBusConnection *connection,
75 static gboolean cm_context_removed(DBusConnection *connection,
82 static gboolean netreg_changed(DBusConnection *connection, DBusMessage *message,
88 static gboolean cm_changed(DBusConnection *connection, DBusMessage *message,
94 static gboolean sim_changed(DBusConnection *connection, DBusMessage *message,
100 static gboolean modem_changed(DBusConnection *connection, DBusMessage *message,
106 static gboolean modem_added(DBusConnection *connection,
107 DBusMessage *message, void *user_data)
112 static gboolean modem_removed(DBusConnection *connection,
113 DBusMessage *message, void *user_data)
118 static void manager_get_modems_reply(DBusPendingCall *call, void *user_data)
122 DBusMessageIter array, dict;
126 reply = dbus_pending_call_steal_reply(call);
128 dbus_error_init(&error);
130 if (dbus_set_error_from_message(&error, reply) == TRUE) {
131 connman_error("%s", error.message);
132 dbus_error_free(&error);
136 if (dbus_message_iter_init(reply, &array) == FALSE)
139 dbus_message_iter_recurse(&array, &dict);
141 while (dbus_message_iter_get_arg_type(&dict) == DBUS_TYPE_STRUCT) {
142 DBusMessageIter value, properties;
145 dbus_message_iter_recurse(&dict, &value);
146 dbus_message_iter_get_basic(&value, &path);
148 dbus_message_iter_next(&value);
149 dbus_message_iter_recurse(&value, &properties);
151 dbus_message_iter_next(&dict);
155 dbus_message_unref(reply);
157 dbus_pending_call_unref(call);
160 static int manager_get_modems(void)
162 DBusMessage *message;
163 DBusPendingCall *call;
167 message = dbus_message_new_method_call(OFONO_SERVICE, "/",
168 OFONO_MANAGER_INTERFACE, GET_MODEMS);
172 if (dbus_connection_send_with_reply(connection, message,
173 &call, TIMEOUT) == FALSE) {
174 connman_error("Failed to call GetModems()");
175 dbus_message_unref(message);
180 connman_error("D-Bus connection not available");
181 dbus_message_unref(message);
185 dbus_pending_call_set_notify(call, manager_get_modems_reply,
188 dbus_message_unref(message);
193 static void ofono_connect(DBusConnection *conn, void *user_data)
197 manager_get_modems();
200 static void ofono_disconnect(DBusConnection *conn, void *user_data)
204 static int network_probe(struct connman_network *network)
206 DBG("network %p", network);
211 static void network_remove(struct connman_network *network)
213 DBG("network %p", network);
216 static int network_connect(struct connman_network *network)
218 DBG("network %p", network);
223 static int network_disconnect(struct connman_network *network)
225 DBG("network %p", network);
230 static struct connman_network_driver network_driver = {
232 .type = CONNMAN_NETWORK_TYPE_CELLULAR,
233 .probe = network_probe,
234 .remove = network_remove,
235 .connect = network_connect,
236 .disconnect = network_disconnect,
239 static int modem_probe(struct connman_device *device)
241 DBG("device %p", device);
246 static void modem_remove(struct connman_device *device)
248 DBG("device %p", device);
251 static int modem_enable(struct connman_device *device)
253 DBG("device %p", device);
258 static int modem_disable(struct connman_device *device)
260 DBG("device %p", device);
265 static struct connman_device_driver modem_driver = {
267 .type = CONNMAN_DEVICE_TYPE_CELLULAR,
268 .probe = modem_probe,
269 .remove = modem_remove,
270 .enable = modem_enable,
271 .disable = modem_disable,
275 static guint modem_added_watch;
276 static guint modem_removed_watch;
277 static guint modem_watch;
278 static guint cm_watch;
279 static guint sim_watch;
280 static guint context_added_watch;
281 static guint context_removed_watch;
282 static guint netreg_watch;
283 static guint context_watch;
285 static int ofono_init(void)
291 connection = connman_dbus_get_connection();
292 if (connection == NULL)
295 watch = g_dbus_add_service_watch(connection,
296 OFONO_SERVICE, ofono_connect,
297 ofono_disconnect, NULL, NULL);
299 modem_added_watch = g_dbus_add_signal_watch(connection, NULL, NULL,
300 OFONO_MANAGER_INTERFACE,
305 modem_removed_watch = g_dbus_add_signal_watch(connection, NULL, NULL,
306 OFONO_MANAGER_INTERFACE,
311 modem_watch = g_dbus_add_signal_watch(connection, NULL, NULL,
312 OFONO_MODEM_INTERFACE,
317 cm_watch = g_dbus_add_signal_watch(connection, NULL, NULL,
323 sim_watch = g_dbus_add_signal_watch(connection, NULL, NULL,
329 context_added_watch = g_dbus_add_signal_watch(connection, NULL, NULL,
335 context_removed_watch = g_dbus_add_signal_watch(connection, NULL, NULL,
341 context_watch = g_dbus_add_signal_watch(connection, NULL, NULL,
342 OFONO_CONTEXT_INTERFACE,
347 netreg_watch = g_dbus_add_signal_watch(connection, NULL, NULL,
348 OFONO_NETREG_INTERFACE,
354 if (watch == 0 || modem_added_watch == 0 || modem_removed_watch == 0 ||
355 modem_watch == 0 || cm_watch == 0 || sim_watch == 0 ||
356 context_added_watch == 0 ||
357 context_removed_watch == 0 ||
358 context_watch == 0 || netreg_watch == 0) {
363 err = connman_network_driver_register(&network_driver);
367 err = connman_device_driver_register(&modem_driver);
369 connman_network_driver_unregister(&network_driver);
376 g_dbus_remove_watch(connection, netreg_watch);
377 g_dbus_remove_watch(connection, context_watch);
378 g_dbus_remove_watch(connection, context_removed_watch);
379 g_dbus_remove_watch(connection, context_added_watch);
380 g_dbus_remove_watch(connection, sim_watch);
381 g_dbus_remove_watch(connection, cm_watch);
382 g_dbus_remove_watch(connection, modem_watch);
383 g_dbus_remove_watch(connection, modem_removed_watch);
384 g_dbus_remove_watch(connection, modem_added_watch);
385 g_dbus_remove_watch(connection, watch);
386 dbus_connection_unref(connection);
391 static void ofono_exit(void)
395 connman_device_driver_unregister(&modem_driver);
396 connman_network_driver_unregister(&network_driver);
398 g_dbus_remove_watch(connection, netreg_watch);
399 g_dbus_remove_watch(connection, context_watch);
400 g_dbus_remove_watch(connection, context_removed_watch);
401 g_dbus_remove_watch(connection, context_added_watch);
402 g_dbus_remove_watch(connection, sim_watch);
403 g_dbus_remove_watch(connection, cm_watch);
404 g_dbus_remove_watch(connection, modem_watch);
405 g_dbus_remove_watch(connection, modem_added_watch);
406 g_dbus_remove_watch(connection, modem_removed_watch);
407 g_dbus_remove_watch(connection, watch);
409 dbus_connection_unref(connection);
412 CONNMAN_PLUGIN_DEFINE(ofono, "oFono telephony plugin", VERSION,
413 CONNMAN_PLUGIN_PRIORITY_DEFAULT, ofono_init, ofono_exit)