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 static DBusConnection *connection;
57 static gboolean context_changed(DBusConnection *connection,
64 static gboolean cm_context_added(DBusConnection *connection,
71 static gboolean cm_context_removed(DBusConnection *connection,
78 static gboolean netreg_changed(DBusConnection *connection, DBusMessage *message,
84 static gboolean cm_changed(DBusConnection *connection, DBusMessage *message,
90 static gboolean sim_changed(DBusConnection *connection, DBusMessage *message,
96 static gboolean modem_changed(DBusConnection *connection, DBusMessage *message,
102 static gboolean modem_added(DBusConnection *connection,
103 DBusMessage *message, void *user_data)
108 static gboolean modem_removed(DBusConnection *connection,
109 DBusMessage *message, void *user_data)
114 static void ofono_connect(DBusConnection *conn, void *user_data)
118 static void ofono_disconnect(DBusConnection *conn, void *user_data)
122 static int network_probe(struct connman_network *network)
124 DBG("network %p", network);
129 static void network_remove(struct connman_network *network)
131 DBG("network %p", network);
134 static int network_connect(struct connman_network *network)
136 DBG("network %p", network);
141 static int network_disconnect(struct connman_network *network)
143 DBG("network %p", network);
148 static struct connman_network_driver network_driver = {
150 .type = CONNMAN_NETWORK_TYPE_CELLULAR,
151 .probe = network_probe,
152 .remove = network_remove,
153 .connect = network_connect,
154 .disconnect = network_disconnect,
157 static int modem_probe(struct connman_device *device)
159 DBG("device %p", device);
164 static void modem_remove(struct connman_device *device)
166 DBG("device %p", device);
169 static int modem_enable(struct connman_device *device)
171 DBG("device %p", device);
176 static int modem_disable(struct connman_device *device)
178 DBG("device %p", device);
183 static struct connman_device_driver modem_driver = {
185 .type = CONNMAN_DEVICE_TYPE_CELLULAR,
186 .probe = modem_probe,
187 .remove = modem_remove,
188 .enable = modem_enable,
189 .disable = modem_disable,
193 static guint modem_added_watch;
194 static guint modem_removed_watch;
195 static guint modem_watch;
196 static guint cm_watch;
197 static guint sim_watch;
198 static guint context_added_watch;
199 static guint context_removed_watch;
200 static guint netreg_watch;
201 static guint context_watch;
203 static int ofono_init(void)
209 connection = connman_dbus_get_connection();
210 if (connection == NULL)
213 watch = g_dbus_add_service_watch(connection,
214 OFONO_SERVICE, ofono_connect,
215 ofono_disconnect, NULL, NULL);
217 modem_added_watch = g_dbus_add_signal_watch(connection, NULL, NULL,
218 OFONO_MANAGER_INTERFACE,
223 modem_removed_watch = g_dbus_add_signal_watch(connection, NULL, NULL,
224 OFONO_MANAGER_INTERFACE,
229 modem_watch = g_dbus_add_signal_watch(connection, NULL, NULL,
230 OFONO_MODEM_INTERFACE,
235 cm_watch = g_dbus_add_signal_watch(connection, NULL, NULL,
241 sim_watch = g_dbus_add_signal_watch(connection, NULL, NULL,
247 context_added_watch = g_dbus_add_signal_watch(connection, NULL, NULL,
253 context_removed_watch = g_dbus_add_signal_watch(connection, NULL, NULL,
259 context_watch = g_dbus_add_signal_watch(connection, NULL, NULL,
260 OFONO_CONTEXT_INTERFACE,
265 netreg_watch = g_dbus_add_signal_watch(connection, NULL, NULL,
266 OFONO_NETREG_INTERFACE,
272 if (watch == 0 || modem_added_watch == 0 || modem_removed_watch == 0 ||
273 modem_watch == 0 || cm_watch == 0 || sim_watch == 0 ||
274 context_added_watch == 0 ||
275 context_removed_watch == 0 ||
276 context_watch == 0 || netreg_watch == 0) {
281 err = connman_network_driver_register(&network_driver);
285 err = connman_device_driver_register(&modem_driver);
287 connman_network_driver_unregister(&network_driver);
294 g_dbus_remove_watch(connection, netreg_watch);
295 g_dbus_remove_watch(connection, context_watch);
296 g_dbus_remove_watch(connection, context_removed_watch);
297 g_dbus_remove_watch(connection, context_added_watch);
298 g_dbus_remove_watch(connection, sim_watch);
299 g_dbus_remove_watch(connection, cm_watch);
300 g_dbus_remove_watch(connection, modem_watch);
301 g_dbus_remove_watch(connection, modem_removed_watch);
302 g_dbus_remove_watch(connection, modem_added_watch);
303 g_dbus_remove_watch(connection, watch);
304 dbus_connection_unref(connection);
309 static void ofono_exit(void)
313 connman_device_driver_unregister(&modem_driver);
314 connman_network_driver_unregister(&network_driver);
316 g_dbus_remove_watch(connection, netreg_watch);
317 g_dbus_remove_watch(connection, context_watch);
318 g_dbus_remove_watch(connection, context_removed_watch);
319 g_dbus_remove_watch(connection, context_added_watch);
320 g_dbus_remove_watch(connection, sim_watch);
321 g_dbus_remove_watch(connection, cm_watch);
322 g_dbus_remove_watch(connection, modem_watch);
323 g_dbus_remove_watch(connection, modem_added_watch);
324 g_dbus_remove_watch(connection, modem_removed_watch);
325 g_dbus_remove_watch(connection, watch);
327 dbus_connection_unref(connection);
330 CONNMAN_PLUGIN_DEFINE(ofono, "oFono telephony plugin", VERSION,
331 CONNMAN_PLUGIN_PRIORITY_DEFAULT, ofono_init, ofono_exit)