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
34 #define CONNMAN_API_SUBJECT_TO_CHANGE
35 #include <connman/plugin.h>
36 #include <connman/device.h>
37 #include <connman/network.h>
38 #include <connman/dbus.h>
39 #include <connman/log.h>
41 #define uninitialized_var(x) x = x
43 #define OFONO_SERVICE "org.ofono"
45 #define OFONO_MANAGER_INTERFACE OFONO_SERVICE ".Manager"
46 #define OFONO_MODEM_INTERFACE OFONO_SERVICE ".Modem"
47 #define OFONO_SIM_INTERFACE OFONO_SERVICE ".SimManager"
48 #define OFONO_NETREG_INTERFACE OFONO_SERVICE ".NetworkRegistration"
49 #define OFONO_CM_INTERFACE OFONO_SERVICE ".ConnectionManager"
50 #define OFONO_CONTEXT_INTERFACE OFONO_SERVICE ".ConnectionContext"
52 #define MODEM_ADDED "ModemAdded"
53 #define MODEM_REMOVED "ModemRemoved"
54 #define PROPERTY_CHANGED "PropertyChanged"
55 #define CONTEXT_ADDED "ContextAdded"
56 #define CONTEXT_REMOVED "ContextRemoved"
58 #define GET_PROPERTIES "GetProperties"
59 #define SET_PROPERTY "SetProperty"
60 #define GET_MODEMS "GetModems"
66 OFONO_API_NETREG = 0x2,
70 static DBusConnection *connection;
72 static GHashTable *modem_hash;
77 struct connman_device *device;
81 connman_bool_t powered;
82 connman_bool_t online;
85 connman_bool_t set_powered;
86 connman_bool_t set_online;
88 /* ConnectionManager Interface */
89 connman_bool_t attached;
91 /* SimManager Interface */
95 DBusPendingCall *call_set_property;
96 DBusPendingCall *call_get_properties;
99 typedef void (*set_property_cb)(struct modem_data *data,
100 connman_bool_t success);
101 typedef void (*get_properties_cb)(struct modem_data *data,
102 DBusMessageIter *dict);
104 struct property_info {
105 struct modem_data *modem;
107 const char *interface;
108 const char *property;
109 set_property_cb set_property_cb;
110 get_properties_cb get_properties_cb;
113 static void set_property_reply(DBusPendingCall *call, void *user_data)
115 struct property_info *info = user_data;
118 connman_bool_t success = TRUE;
120 DBG("%s path %s %s.%s", info->modem->path,
121 info->path, info->interface, info->property);
123 info->modem->call_set_property = NULL;
125 dbus_error_init(&error);
127 reply = dbus_pending_call_steal_reply(call);
129 if (dbus_set_error_from_message(&error, reply)) {
130 connman_error("Failed to change property: %s %s.%s: %s %s",
131 info->path, info->interface, info->property,
132 error.name, error.message);
133 dbus_error_free(&error);
137 if (info->set_property_cb != NULL)
138 (*info->set_property_cb)(info->modem, success);
140 dbus_message_unref(reply);
142 dbus_pending_call_unref(call);
145 static int set_property(struct modem_data *modem,
146 const char *path, const char *interface,
147 const char *property, int type, void *value,
148 set_property_cb notify)
150 DBusMessage *message;
151 DBusMessageIter iter;
152 struct property_info *info;
154 DBG("%s path %s %s.%s", modem->path, path, interface, property);
156 if (modem->call_set_property != NULL) {
157 connman_error("Pending SetProperty");
161 message = dbus_message_new_method_call(OFONO_SERVICE, path,
162 interface, SET_PROPERTY);
166 dbus_message_iter_init_append(message, &iter);
167 connman_dbus_property_append_basic(&iter, property, type, value);
169 if (dbus_connection_send_with_reply(connection, message,
170 &modem->call_set_property, TIMEOUT) == FALSE) {
171 connman_error("Failed to change property: %s %s.%s",
172 path, interface, property);
173 dbus_message_unref(message);
177 if (modem->call_set_property == NULL) {
178 connman_error("D-Bus connection not available");
179 dbus_message_unref(message);
183 info = g_try_new0(struct property_info, 1);
185 dbus_message_unref(message);
191 info->interface = interface;
192 info->property = property;
193 info->set_property_cb = notify;
195 dbus_pending_call_set_notify(modem->call_set_property,
196 set_property_reply, info, g_free);
198 dbus_message_unref(message);
203 static void get_properties_reply(DBusPendingCall *call, void *user_data)
205 struct property_info *info = user_data;
206 DBusMessageIter array, dict;
210 DBG("%s path %s %s", info->modem->path, info->path, info->interface);
212 info->modem->call_get_properties = NULL;
214 dbus_error_init(&error);
216 reply = dbus_pending_call_steal_reply(call);
218 if (dbus_set_error_from_message(&error, reply)) {
219 connman_error("Failed to get properties: %s %s: %s %s",
220 info->path, info->interface,
221 error.name, error.message);
222 dbus_error_free(&error);
227 if (dbus_message_iter_init(reply, &array) == FALSE)
230 if (dbus_message_iter_get_arg_type(&array) != DBUS_TYPE_ARRAY)
233 dbus_message_iter_recurse(&array, &dict);
235 if (info->get_properties_cb != NULL)
236 (*info->get_properties_cb)(info->modem, &dict);
240 dbus_message_unref(reply);
242 dbus_pending_call_unref(call);
245 static int get_properties(const char *path, const char *interface,
246 get_properties_cb notify,
247 struct modem_data *modem)
249 DBusMessage *message;
250 struct property_info *info;
252 DBG("%s path %s %s", modem->path, path, interface);
254 if (modem->call_get_properties != NULL) {
255 connman_error("Pending GetProperties");
259 message = dbus_message_new_method_call(OFONO_SERVICE, path,
260 interface, GET_PROPERTIES);
264 if (dbus_connection_send_with_reply(connection, message,
265 &modem->call_get_properties, TIMEOUT) == FALSE) {
266 connman_error("Failed to call %s.GetProperties()", interface);
267 dbus_message_unref(message);
271 if (modem->call_get_properties == NULL) {
272 connman_error("D-Bus connection not available");
273 dbus_message_unref(message);
277 info = g_try_new0(struct property_info, 1);
279 dbus_message_unref(message);
285 info->interface = interface;
286 info->get_properties_cb = notify;
288 dbus_pending_call_set_notify(modem->call_get_properties,
289 get_properties_reply, info, g_free);
291 dbus_message_unref(message);
296 static void modem_set_online_reply(struct modem_data *modem,
297 connman_bool_t success)
299 DBG("%s", modem->path);
301 if (success == TRUE) {
303 * Don't handle do anything on success here. oFono will send
304 * the change via PropertyChanged singal.
309 modem->set_online = FALSE;
312 static int modem_set_online(struct modem_data *modem)
314 DBG("%s", modem->path);
316 modem->set_online = TRUE;
318 return set_property(modem, modem->path,
319 OFONO_MODEM_INTERFACE,
320 "Online", DBUS_TYPE_BOOLEAN,
322 modem_set_online_reply);
325 static int modem_set_powered(struct modem_data *modem)
327 DBG("%s", modem->path);
329 modem->set_powered = TRUE;
331 return set_property(modem, modem->path,
332 OFONO_MODEM_INTERFACE,
333 "Powered", DBUS_TYPE_BOOLEAN,
338 static connman_bool_t has_interface(uint8_t interfaces,
341 if ((interfaces & api) == api)
347 static uint8_t extract_interfaces(DBusMessageIter *array)
349 DBusMessageIter entry;
350 uint8_t interfaces = 0;
352 dbus_message_iter_recurse(array, &entry);
354 while (dbus_message_iter_get_arg_type(&entry) == DBUS_TYPE_STRING) {
357 dbus_message_iter_get_basic(&entry, &name);
359 if (g_str_equal(name, OFONO_SIM_INTERFACE) == TRUE)
360 interfaces |= OFONO_API_SIM;
361 else if (g_str_equal(name, OFONO_NETREG_INTERFACE) == TRUE)
362 interfaces |= OFONO_API_NETREG;
363 else if (g_str_equal(name, OFONO_CM_INTERFACE) == TRUE)
364 interfaces |= OFONO_API_CM;
366 dbus_message_iter_next(&entry);
372 static connman_bool_t ready_to_create_device(struct modem_data *modem)
375 * There are three different modem types which behave slightly
377 * - GSM modems will expose the SIM interface then the
379 * - DUN modems will expose first a unique serial number (BDADDR)
380 * and then the CM interface.
381 * - CDMA modems will expose CM first and sometime later
382 * a unique serial number.
384 * This functions tests if we have the necessary information gathered
385 * before we are able to create a device.
388 if (modem->device != NULL)
391 if (modem->imsi != NULL || modem->serial != NULL)
397 static void create_device(struct modem_data *modem)
399 struct connman_device *device;
400 char *uninitialized_var(ident);
402 DBG("%s", modem->path);
404 if (modem->imsi != NULL)
406 else if (modem->serial != NULL)
407 ident = modem->serial;
409 if (connman_dbus_validate_ident(ident) == FALSE)
410 ident = connman_dbus_encode_string(ident);
412 ident = g_strdup(ident);
414 device = connman_device_create(ident, CONNMAN_DEVICE_TYPE_CELLULAR);
418 DBG("device %p", device);
420 connman_device_set_ident(device, ident);
422 connman_device_set_string(device, "Path", modem->path);
424 connman_device_set_data(device, modem);
426 if (connman_device_register(device) < 0) {
427 connman_error("Failed to register cellular device");
428 connman_device_unref(device);
432 modem->device = device;
438 static void destroy_device(struct modem_data *modem)
440 DBG("%s", modem->path);
442 connman_device_set_powered(modem->device, FALSE);
444 connman_device_unregister(modem->device);
445 connman_device_unref(modem->device);
447 modem->device = NULL;
450 static gboolean context_changed(DBusConnection *connection,
451 DBusMessage *message,
457 static gboolean cm_context_added(DBusConnection *connection,
458 DBusMessage *message,
464 static gboolean cm_context_removed(DBusConnection *connection,
465 DBusMessage *message,
471 static gboolean netreg_changed(DBusConnection *connection, DBusMessage *message,
477 static gboolean cm_changed(DBusConnection *connection, DBusMessage *message,
480 const char *path = dbus_message_get_path(message);
481 struct modem_data *modem;
482 DBusMessageIter iter, value;
485 modem = g_hash_table_lookup(modem_hash, path);
489 if (dbus_message_iter_init(message, &iter) == FALSE)
492 dbus_message_iter_get_basic(&iter, &key);
494 dbus_message_iter_next(&iter);
495 dbus_message_iter_recurse(&iter, &value);
497 if (g_str_equal(key, "Attached") == TRUE) {
498 dbus_message_iter_get_basic(&value, &modem->attached);
500 DBG("%s Attached %d", modem->path, modem->attached);
506 static void cm_properties_reply(struct modem_data *modem, DBusMessageIter *dict)
508 DBG("%s", modem->path);
510 while (dbus_message_iter_get_arg_type(dict) == DBUS_TYPE_DICT_ENTRY) {
511 DBusMessageIter entry, value;
514 dbus_message_iter_recurse(dict, &entry);
515 dbus_message_iter_get_basic(&entry, &key);
517 dbus_message_iter_next(&entry);
518 dbus_message_iter_recurse(&entry, &value);
520 if (g_str_equal(key, "Attached") == TRUE) {
521 dbus_message_iter_get_basic(&value, &modem->attached);
523 DBG("%s Attached %d", modem->path,
529 dbus_message_iter_next(dict);
533 static int cm_get_properties(struct modem_data *modem)
535 return get_properties(modem->path, OFONO_CM_INTERFACE,
536 cm_properties_reply, modem);
539 static void update_sim_imsi(struct modem_data *modem,
542 DBG("%s imsi %s", modem->path, imsi);
544 if (g_strcmp0(modem->imsi, imsi) == 0)
548 modem->imsi = g_strdup(imsi);
551 static gboolean sim_changed(DBusConnection *connection, DBusMessage *message,
554 const char *path = dbus_message_get_path(message);
555 struct modem_data *modem;
556 DBusMessageIter iter, value;
559 modem = g_hash_table_lookup(modem_hash, path);
563 if (dbus_message_iter_init(message, &iter) == FALSE)
566 dbus_message_iter_get_basic(&iter, &key);
568 dbus_message_iter_next(&iter);
569 dbus_message_iter_recurse(&iter, &value);
571 if (g_str_equal(key, "SubscriberIdentity") == TRUE) {
574 dbus_message_iter_get_basic(&value, &imsi);
576 update_sim_imsi(modem, imsi);
578 if (modem->online == FALSE) {
579 modem_set_online(modem);
580 } else if (has_interface(modem->interfaces,
581 OFONO_API_CM) == TRUE) {
582 if (ready_to_create_device(modem) == TRUE)
583 create_device(modem);
590 static void sim_properties_reply(struct modem_data *modem,
591 DBusMessageIter *dict)
593 DBG("%s", modem->path);
595 while (dbus_message_iter_get_arg_type(dict) == DBUS_TYPE_DICT_ENTRY) {
596 DBusMessageIter entry, value;
599 dbus_message_iter_recurse(dict, &entry);
600 dbus_message_iter_get_basic(&entry, &key);
602 dbus_message_iter_next(&entry);
603 dbus_message_iter_recurse(&entry, &value);
605 if (g_str_equal(key, "SubscriberIdentity") == TRUE) {
608 dbus_message_iter_get_basic(&value, &imsi);
610 update_sim_imsi(modem, imsi);
612 if (modem->online == FALSE) {
613 modem_set_online(modem);
617 if (has_interface(modem->interfaces, OFONO_API_CM) == TRUE) {
618 if (ready_to_create_device(modem) == TRUE)
619 create_device(modem);
620 if (modem->device != NULL)
621 cm_get_properties(modem);
626 dbus_message_iter_next(dict);
630 static int sim_get_properties(struct modem_data *modem)
632 return get_properties(modem->path, OFONO_SIM_INTERFACE,
633 sim_properties_reply, modem);
636 static gboolean modem_changed(DBusConnection *connection, DBusMessage *message,
639 const char *path = dbus_message_get_path(message);
640 struct modem_data *modem;
641 DBusMessageIter iter, value;
644 modem = g_hash_table_lookup(modem_hash, path);
648 if (dbus_message_iter_init(message, &iter) == FALSE)
651 dbus_message_iter_get_basic(&iter, &key);
653 dbus_message_iter_next(&iter);
654 dbus_message_iter_recurse(&iter, &value);
656 if (g_str_equal(key, "Powered") == TRUE) {
657 dbus_message_iter_get_basic(&value, &modem->powered);
659 DBG("%s Powered %d", modem->path, modem->powered);
661 if (modem->powered == FALSE)
662 modem_set_powered(modem);
663 } else if (g_str_equal(key, "Online") == TRUE) {
664 dbus_message_iter_get_basic(&value, &modem->online);
666 DBG("%s Online %d", modem->path, modem->online);
668 if (modem->online == FALSE)
671 if (has_interface(modem->interfaces, OFONO_API_CM) == FALSE)
673 if (ready_to_create_device(modem) == TRUE)
674 create_device(modem);
675 if (modem->device != NULL)
676 cm_get_properties(modem);
677 } else if (g_str_equal(key, "Interfaces") == TRUE) {
678 modem->interfaces = extract_interfaces(&value);
680 DBG("%s Interfaces 0x%02x", modem->path,
683 if (has_interface(modem->interfaces, OFONO_API_SIM) == TRUE) {
684 if (modem->imsi == NULL &&
685 modem->set_powered == FALSE) {
687 * Only use do GetProperties() when
688 * device has not been powered up.
690 sim_get_properties(modem);
695 if (has_interface(modem->interfaces, OFONO_API_CM) == TRUE) {
696 if (ready_to_create_device(modem) == TRUE)
697 create_device(modem);
698 if (modem->device != NULL)
699 cm_get_properties(modem);
701 if (modem->device != NULL)
702 destroy_device(modem);
704 } else if (g_str_equal(key, "Serial") == TRUE) {
707 dbus_message_iter_get_basic(&value, &serial);
709 g_free(modem->serial);
710 modem->serial = g_strdup(serial);
712 DBG("%s Serial %s", modem->path, modem->serial);
714 if (has_interface(modem->interfaces, OFONO_API_CM) == TRUE) {
715 if (ready_to_create_device(modem) == TRUE)
716 create_device(modem);
717 if (modem->device != NULL)
718 cm_get_properties(modem);
725 static void add_modem(const char *path, DBusMessageIter *prop)
727 struct modem_data *modem;
731 modem = g_hash_table_lookup(modem_hash, path);
734 * When oFono powers up we ask for the modems and oFono is
735 * reporting with modem_added signal the modems. Only
741 modem = g_try_new0(struct modem_data, 1);
745 modem->path = g_strdup(path);
747 g_hash_table_insert(modem_hash, g_strdup(path), modem);
749 while (dbus_message_iter_get_arg_type(prop) == DBUS_TYPE_DICT_ENTRY) {
750 DBusMessageIter entry, value;
753 dbus_message_iter_recurse(prop, &entry);
754 dbus_message_iter_get_basic(&entry, &key);
756 dbus_message_iter_next(&entry);
757 dbus_message_iter_recurse(&entry, &value);
759 if (g_str_equal(key, "Powered") == TRUE) {
760 dbus_message_iter_get_basic(&value, &modem->powered);
762 DBG("%s Powered %d", modem->path, modem->powered);
763 } else if (g_str_equal(key, "Online") == TRUE) {
764 dbus_message_iter_get_basic(&value, &modem->online);
766 DBG("%s Online %d", modem->path, modem->online);
767 } else if (g_str_equal(key, "Interfaces") == TRUE) {
768 modem->interfaces = extract_interfaces(&value);
770 DBG("%s Interfaces 0x%02x", modem->path,
772 } else if (g_str_equal(key, "Serial") == TRUE) {
775 dbus_message_iter_get_basic(&value, &serial);
776 modem->serial = g_strdup(serial);
778 DBG("%s Serial %s", modem->path, modem->serial);
781 dbus_message_iter_next(prop);
784 if (modem->powered == FALSE) {
785 modem_set_powered(modem);
786 } else if (has_interface(modem->interfaces, OFONO_API_SIM) == TRUE) {
787 sim_get_properties(modem);
788 } else if (has_interface(modem->interfaces, OFONO_API_CM) == TRUE) {
789 if (ready_to_create_device(modem) == TRUE)
790 create_device(modem);
791 if (modem->device != NULL)
792 cm_get_properties(modem);
796 static void remove_modem(gpointer data)
798 struct modem_data *modem = data;
800 DBG("%s", modem->path);
802 if (modem->call_set_property != NULL)
803 dbus_pending_call_cancel(modem->call_set_property);
805 if (modem->call_get_properties != NULL)
806 dbus_pending_call_cancel(modem->call_get_properties);
808 if (modem->device != NULL)
809 destroy_device(modem);
811 g_free(modem->serial);
818 static gboolean modem_added(DBusConnection *connection,
819 DBusMessage *message, void *user_data)
821 DBusMessageIter iter, properties;
826 if (dbus_message_iter_init(message, &iter) == FALSE)
829 dbus_message_iter_get_basic(&iter, &path);
831 dbus_message_iter_next(&iter);
832 dbus_message_iter_recurse(&iter, &properties);
834 add_modem(path, &properties);
839 static gboolean modem_removed(DBusConnection *connection,
840 DBusMessage *message, void *user_data)
842 DBusMessageIter iter;
847 if (dbus_message_iter_init(message, &iter) == FALSE)
850 dbus_message_iter_get_basic(&iter, &path);
852 g_hash_table_remove(modem_hash, path);
857 static void manager_get_modems_reply(DBusPendingCall *call, void *user_data)
861 DBusMessageIter array, dict;
865 reply = dbus_pending_call_steal_reply(call);
867 dbus_error_init(&error);
869 if (dbus_set_error_from_message(&error, reply) == TRUE) {
870 connman_error("%s", error.message);
871 dbus_error_free(&error);
875 if (dbus_message_iter_init(reply, &array) == FALSE)
878 dbus_message_iter_recurse(&array, &dict);
880 while (dbus_message_iter_get_arg_type(&dict) == DBUS_TYPE_STRUCT) {
881 DBusMessageIter value, properties;
884 dbus_message_iter_recurse(&dict, &value);
885 dbus_message_iter_get_basic(&value, &path);
887 dbus_message_iter_next(&value);
888 dbus_message_iter_recurse(&value, &properties);
890 add_modem(path, &properties);
892 dbus_message_iter_next(&dict);
896 dbus_message_unref(reply);
898 dbus_pending_call_unref(call);
901 static int manager_get_modems(void)
903 DBusMessage *message;
904 DBusPendingCall *call;
908 message = dbus_message_new_method_call(OFONO_SERVICE, "/",
909 OFONO_MANAGER_INTERFACE, GET_MODEMS);
913 if (dbus_connection_send_with_reply(connection, message,
914 &call, TIMEOUT) == FALSE) {
915 connman_error("Failed to call GetModems()");
916 dbus_message_unref(message);
921 connman_error("D-Bus connection not available");
922 dbus_message_unref(message);
926 dbus_pending_call_set_notify(call, manager_get_modems_reply,
929 dbus_message_unref(message);
934 static void ofono_connect(DBusConnection *conn, void *user_data)
938 modem_hash = g_hash_table_new_full(g_str_hash, g_str_equal,
939 g_free, remove_modem);
940 if (modem_hash == NULL)
943 manager_get_modems();
946 static void ofono_disconnect(DBusConnection *conn, void *user_data)
950 if (modem_hash == NULL)
953 g_hash_table_destroy(modem_hash);
957 static int network_probe(struct connman_network *network)
959 DBG("network %p", network);
964 static void network_remove(struct connman_network *network)
966 DBG("network %p", network);
969 static int network_connect(struct connman_network *network)
971 DBG("network %p", network);
976 static int network_disconnect(struct connman_network *network)
978 DBG("network %p", network);
983 static struct connman_network_driver network_driver = {
985 .type = CONNMAN_NETWORK_TYPE_CELLULAR,
986 .probe = network_probe,
987 .remove = network_remove,
988 .connect = network_connect,
989 .disconnect = network_disconnect,
992 static int modem_probe(struct connman_device *device)
994 struct modem_data *modem = connman_device_get_data(device);
996 DBG("%s device %p", modem->path, device);
1001 static void modem_remove(struct connman_device *device)
1003 struct modem_data *modem = connman_device_get_data(device);
1005 DBG("%s device %p", modem->path, device);
1008 static int modem_enable(struct connman_device *device)
1010 struct modem_data *modem = connman_device_get_data(device);
1012 DBG("%s device %p", modem->path, device);
1017 static int modem_disable(struct connman_device *device)
1019 struct modem_data *modem = connman_device_get_data(device);
1021 DBG("%s device %p", modem->path, device);
1026 static struct connman_device_driver modem_driver = {
1028 .type = CONNMAN_DEVICE_TYPE_CELLULAR,
1029 .probe = modem_probe,
1030 .remove = modem_remove,
1031 .enable = modem_enable,
1032 .disable = modem_disable,
1036 static guint modem_added_watch;
1037 static guint modem_removed_watch;
1038 static guint modem_watch;
1039 static guint cm_watch;
1040 static guint sim_watch;
1041 static guint context_added_watch;
1042 static guint context_removed_watch;
1043 static guint netreg_watch;
1044 static guint context_watch;
1046 static int ofono_init(void)
1052 connection = connman_dbus_get_connection();
1053 if (connection == NULL)
1056 watch = g_dbus_add_service_watch(connection,
1057 OFONO_SERVICE, ofono_connect,
1058 ofono_disconnect, NULL, NULL);
1060 modem_added_watch = g_dbus_add_signal_watch(connection, NULL, NULL,
1061 OFONO_MANAGER_INTERFACE,
1066 modem_removed_watch = g_dbus_add_signal_watch(connection, NULL, NULL,
1067 OFONO_MANAGER_INTERFACE,
1072 modem_watch = g_dbus_add_signal_watch(connection, NULL, NULL,
1073 OFONO_MODEM_INTERFACE,
1078 cm_watch = g_dbus_add_signal_watch(connection, NULL, NULL,
1084 sim_watch = g_dbus_add_signal_watch(connection, NULL, NULL,
1085 OFONO_SIM_INTERFACE,
1090 context_added_watch = g_dbus_add_signal_watch(connection, NULL, NULL,
1096 context_removed_watch = g_dbus_add_signal_watch(connection, NULL, NULL,
1102 context_watch = g_dbus_add_signal_watch(connection, NULL, NULL,
1103 OFONO_CONTEXT_INTERFACE,
1108 netreg_watch = g_dbus_add_signal_watch(connection, NULL, NULL,
1109 OFONO_NETREG_INTERFACE,
1115 if (watch == 0 || modem_added_watch == 0 || modem_removed_watch == 0 ||
1116 modem_watch == 0 || cm_watch == 0 || sim_watch == 0 ||
1117 context_added_watch == 0 ||
1118 context_removed_watch == 0 ||
1119 context_watch == 0 || netreg_watch == 0) {
1124 err = connman_network_driver_register(&network_driver);
1128 err = connman_device_driver_register(&modem_driver);
1130 connman_network_driver_unregister(&network_driver);
1137 g_dbus_remove_watch(connection, netreg_watch);
1138 g_dbus_remove_watch(connection, context_watch);
1139 g_dbus_remove_watch(connection, context_removed_watch);
1140 g_dbus_remove_watch(connection, context_added_watch);
1141 g_dbus_remove_watch(connection, sim_watch);
1142 g_dbus_remove_watch(connection, cm_watch);
1143 g_dbus_remove_watch(connection, modem_watch);
1144 g_dbus_remove_watch(connection, modem_removed_watch);
1145 g_dbus_remove_watch(connection, modem_added_watch);
1146 g_dbus_remove_watch(connection, watch);
1147 dbus_connection_unref(connection);
1152 static void ofono_exit(void)
1156 if (modem_hash != NULL) {
1157 g_hash_table_destroy(modem_hash);
1161 connman_device_driver_unregister(&modem_driver);
1162 connman_network_driver_unregister(&network_driver);
1164 g_dbus_remove_watch(connection, netreg_watch);
1165 g_dbus_remove_watch(connection, context_watch);
1166 g_dbus_remove_watch(connection, context_removed_watch);
1167 g_dbus_remove_watch(connection, context_added_watch);
1168 g_dbus_remove_watch(connection, sim_watch);
1169 g_dbus_remove_watch(connection, cm_watch);
1170 g_dbus_remove_watch(connection, modem_watch);
1171 g_dbus_remove_watch(connection, modem_added_watch);
1172 g_dbus_remove_watch(connection, modem_removed_watch);
1173 g_dbus_remove_watch(connection, watch);
1175 dbus_connection_unref(connection);
1178 CONNMAN_PLUGIN_DEFINE(ofono, "oFono telephony plugin", VERSION,
1179 CONNMAN_PLUGIN_PRIORITY_DEFAULT, ofono_init, ofono_exit)