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/inet.h>
39 #include <connman/dbus.h>
40 #include <connman/log.h>
42 #define uninitialized_var(x) x = x
44 #define OFONO_SERVICE "org.ofono"
46 #define OFONO_MANAGER_INTERFACE OFONO_SERVICE ".Manager"
47 #define OFONO_MODEM_INTERFACE OFONO_SERVICE ".Modem"
48 #define OFONO_SIM_INTERFACE OFONO_SERVICE ".SimManager"
49 #define OFONO_NETREG_INTERFACE OFONO_SERVICE ".NetworkRegistration"
50 #define OFONO_CM_INTERFACE OFONO_SERVICE ".ConnectionManager"
51 #define OFONO_CONTEXT_INTERFACE OFONO_SERVICE ".ConnectionContext"
53 #define MODEM_ADDED "ModemAdded"
54 #define MODEM_REMOVED "ModemRemoved"
55 #define PROPERTY_CHANGED "PropertyChanged"
56 #define CONTEXT_ADDED "ContextAdded"
57 #define CONTEXT_REMOVED "ContextRemoved"
59 #define GET_PROPERTIES "GetProperties"
60 #define SET_PROPERTY "SetProperty"
61 #define GET_MODEMS "GetModems"
62 #define GET_CONTEXTS "GetContexts"
68 OFONO_API_NETREG = 0x2,
72 static DBusConnection *connection;
74 static GHashTable *modem_hash;
75 static GHashTable *context_hash;
77 struct network_context {
81 enum connman_ipconfig_method ipv4_method;
82 struct connman_ipaddress *ipv4_address;
83 char *ipv4_nameservers;
85 enum connman_ipconfig_method ipv6_method;
86 struct connman_ipaddress *ipv6_address;
87 char *ipv6_nameservers;
93 struct connman_device *device;
94 struct connman_network *network;
96 struct network_context *context;
100 connman_bool_t powered;
101 connman_bool_t online;
104 connman_bool_t set_powered;
105 connman_bool_t set_online;
107 /* ConnectionManager Interface */
108 connman_bool_t attached;
109 connman_bool_t cm_powered;
111 connman_bool_t set_cm_powered;
113 /* ConnectionContext Interface */
114 connman_bool_t active;
116 /* SimManager Interface */
119 /* Netreg Interface */
124 DBusPendingCall *call_set_property;
125 DBusPendingCall *call_get_properties;
126 DBusPendingCall *call_get_contexts;
129 static char *get_ident(const char *path)
136 pos = strrchr(path, '/');
143 static struct network_context *network_context_alloc(const char *path)
145 struct network_context *context;
147 context = g_try_new0(struct network_context, 1);
151 context->path = g_strdup(path);
154 context->ipv4_method = CONNMAN_IPCONFIG_METHOD_UNKNOWN;
155 context->ipv4_address = NULL;
156 context->ipv4_nameservers = NULL;
158 context->ipv6_method = CONNMAN_IPCONFIG_METHOD_UNKNOWN;
159 context->ipv6_address = NULL;
160 context->ipv6_nameservers = NULL;
165 static void network_context_free(struct network_context *context)
167 g_free(context->path);
169 connman_ipaddress_free(context->ipv4_address);
170 g_free(context->ipv4_nameservers);
172 connman_ipaddress_free(context->ipv6_address);
173 g_free(context->ipv6_nameservers);
178 static void set_connected(struct modem_data *modem)
180 DBG("%s", modem->path);
182 connman_network_set_index(modem->network, modem->context->index);
184 switch (modem->context->method) {
185 case CONNMAN_IPCONFIG_METHOD_UNKNOWN:
186 case CONNMAN_IPCONFIG_METHOD_OFF:
187 case CONNMAN_IPCONFIG_METHOD_MANUAL:
188 case CONNMAN_IPCONFIG_METHOD_AUTO:
191 case CONNMAN_IPCONFIG_METHOD_FIXED:
192 connman_network_set_ipv4_method(modem->network,
193 modem->context->method);
194 connman_network_set_ipaddress(modem->network,
195 modem->context->address);
196 connman_network_set_nameservers(modem->network,
197 modem->context->nameservers);
200 case CONNMAN_IPCONFIG_METHOD_DHCP:
201 connman_network_set_ipv4_method(modem->network,
202 modem->context->method);
206 connman_network_set_connected(modem->network, TRUE);
209 static void set_disconnected(struct modem_data *modem)
211 DBG("%s", modem->path);
213 connman_network_set_connected(modem->network, FALSE);
216 typedef void (*set_property_cb)(struct modem_data *data,
217 connman_bool_t success);
218 typedef void (*get_properties_cb)(struct modem_data *data,
219 DBusMessageIter *dict);
221 struct property_info {
222 struct modem_data *modem;
224 const char *interface;
225 const char *property;
226 set_property_cb set_property_cb;
227 get_properties_cb get_properties_cb;
230 static void set_property_reply(DBusPendingCall *call, void *user_data)
232 struct property_info *info = user_data;
235 connman_bool_t success = TRUE;
237 DBG("%s path %s %s.%s", info->modem->path,
238 info->path, info->interface, info->property);
240 info->modem->call_set_property = NULL;
242 dbus_error_init(&error);
244 reply = dbus_pending_call_steal_reply(call);
246 if (dbus_set_error_from_message(&error, reply)) {
247 connman_error("Failed to change property: %s %s.%s: %s %s",
248 info->path, info->interface, info->property,
249 error.name, error.message);
250 dbus_error_free(&error);
254 if (info->set_property_cb != NULL)
255 (*info->set_property_cb)(info->modem, success);
257 dbus_message_unref(reply);
259 dbus_pending_call_unref(call);
262 static int set_property(struct modem_data *modem,
263 const char *path, const char *interface,
264 const char *property, int type, void *value,
265 set_property_cb notify)
267 DBusMessage *message;
268 DBusMessageIter iter;
269 struct property_info *info;
271 DBG("%s path %s %s.%s", modem->path, path, interface, property);
273 if (modem->call_set_property != NULL) {
274 connman_error("Pending SetProperty");
278 message = dbus_message_new_method_call(OFONO_SERVICE, path,
279 interface, SET_PROPERTY);
283 dbus_message_iter_init_append(message, &iter);
284 connman_dbus_property_append_basic(&iter, property, type, value);
286 if (dbus_connection_send_with_reply(connection, message,
287 &modem->call_set_property, TIMEOUT) == FALSE) {
288 connman_error("Failed to change property: %s %s.%s",
289 path, interface, property);
290 dbus_message_unref(message);
294 if (modem->call_set_property == NULL) {
295 connman_error("D-Bus connection not available");
296 dbus_message_unref(message);
300 info = g_try_new0(struct property_info, 1);
302 dbus_message_unref(message);
308 info->interface = interface;
309 info->property = property;
310 info->set_property_cb = notify;
312 dbus_pending_call_set_notify(modem->call_set_property,
313 set_property_reply, info, g_free);
315 dbus_message_unref(message);
320 static void get_properties_reply(DBusPendingCall *call, void *user_data)
322 struct property_info *info = user_data;
323 DBusMessageIter array, dict;
327 DBG("%s path %s %s", info->modem->path, info->path, info->interface);
329 info->modem->call_get_properties = NULL;
331 dbus_error_init(&error);
333 reply = dbus_pending_call_steal_reply(call);
335 if (dbus_set_error_from_message(&error, reply)) {
336 connman_error("Failed to get properties: %s %s: %s %s",
337 info->path, info->interface,
338 error.name, error.message);
339 dbus_error_free(&error);
344 if (dbus_message_iter_init(reply, &array) == FALSE)
347 if (dbus_message_iter_get_arg_type(&array) != DBUS_TYPE_ARRAY)
350 dbus_message_iter_recurse(&array, &dict);
352 if (info->get_properties_cb != NULL)
353 (*info->get_properties_cb)(info->modem, &dict);
357 dbus_message_unref(reply);
359 dbus_pending_call_unref(call);
362 static int get_properties(const char *path, const char *interface,
363 get_properties_cb notify,
364 struct modem_data *modem)
366 DBusMessage *message;
367 struct property_info *info;
369 DBG("%s path %s %s", modem->path, path, interface);
371 if (modem->call_get_properties != NULL) {
372 connman_error("Pending GetProperties");
376 message = dbus_message_new_method_call(OFONO_SERVICE, path,
377 interface, GET_PROPERTIES);
381 if (dbus_connection_send_with_reply(connection, message,
382 &modem->call_get_properties, TIMEOUT) == FALSE) {
383 connman_error("Failed to call %s.GetProperties()", interface);
384 dbus_message_unref(message);
388 if (modem->call_get_properties == NULL) {
389 connman_error("D-Bus connection not available");
390 dbus_message_unref(message);
394 info = g_try_new0(struct property_info, 1);
396 dbus_message_unref(message);
402 info->interface = interface;
403 info->get_properties_cb = notify;
405 dbus_pending_call_set_notify(modem->call_get_properties,
406 get_properties_reply, info, g_free);
408 dbus_message_unref(message);
413 static void modem_set_online_reply(struct modem_data *modem,
414 connman_bool_t success)
416 DBG("%s", modem->path);
418 if (success == TRUE) {
420 * Don't handle do anything on success here. oFono will send
421 * the change via PropertyChanged singal.
426 modem->set_online = FALSE;
429 static int modem_set_online(struct modem_data *modem)
431 DBG("%s", modem->path);
433 modem->set_online = TRUE;
435 return set_property(modem, modem->path,
436 OFONO_MODEM_INTERFACE,
437 "Online", DBUS_TYPE_BOOLEAN,
439 modem_set_online_reply);
442 static void cm_set_powered_reply(struct modem_data *modem,
443 connman_bool_t success)
445 DBG("%s", modem->path);
447 if (success == TRUE) {
449 * Don't handle do anything on success here. oFono will send
450 * the change via PropertyChanged singal.
455 modem->set_cm_powered = FALSE;
458 static int cm_set_powered(struct modem_data *modem)
460 DBG("%s", modem->path);
462 modem->set_cm_powered = TRUE;
464 return set_property(modem, modem->path,
466 "Powered", DBUS_TYPE_BOOLEAN,
467 &modem->set_cm_powered,
468 cm_set_powered_reply);
471 static int modem_set_powered(struct modem_data *modem)
473 DBG("%s", modem->path);
475 modem->set_powered = TRUE;
477 return set_property(modem, modem->path,
478 OFONO_MODEM_INTERFACE,
479 "Powered", DBUS_TYPE_BOOLEAN,
484 static connman_bool_t has_interface(uint8_t interfaces,
487 if ((interfaces & api) == api)
493 static uint8_t extract_interfaces(DBusMessageIter *array)
495 DBusMessageIter entry;
496 uint8_t interfaces = 0;
498 dbus_message_iter_recurse(array, &entry);
500 while (dbus_message_iter_get_arg_type(&entry) == DBUS_TYPE_STRING) {
503 dbus_message_iter_get_basic(&entry, &name);
505 if (g_str_equal(name, OFONO_SIM_INTERFACE) == TRUE)
506 interfaces |= OFONO_API_SIM;
507 else if (g_str_equal(name, OFONO_NETREG_INTERFACE) == TRUE)
508 interfaces |= OFONO_API_NETREG;
509 else if (g_str_equal(name, OFONO_CM_INTERFACE) == TRUE)
510 interfaces |= OFONO_API_CM;
512 dbus_message_iter_next(&entry);
518 static char *extract_nameservers(DBusMessageIter *array)
520 DBusMessageIter entry;
521 char *nameservers = NULL;
524 dbus_message_iter_recurse(array, &entry);
526 while (dbus_message_iter_get_arg_type(&entry) == DBUS_TYPE_STRING) {
527 const char *nameserver;
529 dbus_message_iter_get_basic(&entry, &nameserver);
531 if (nameservers == NULL) {
532 nameservers = g_strdup(nameserver);
535 nameservers = g_strdup_printf("%s %s", tmp, nameserver);
539 dbus_message_iter_next(&entry);
545 static void extract_ipv4_settings(DBusMessageIter *array,
546 struct network_context *context)
548 DBusMessageIter dict;
549 char *address = NULL, *netmask = NULL, *gateway = NULL;
550 char *nameservers = NULL;
551 const char *interface = NULL;
554 if (dbus_message_iter_get_arg_type(array) != DBUS_TYPE_ARRAY)
557 dbus_message_iter_recurse(array, &dict);
559 while (dbus_message_iter_get_arg_type(&dict) == DBUS_TYPE_DICT_ENTRY) {
560 DBusMessageIter entry, value;
561 const char *key, *val;
563 dbus_message_iter_recurse(&dict, &entry);
564 dbus_message_iter_get_basic(&entry, &key);
566 dbus_message_iter_next(&entry);
567 dbus_message_iter_recurse(&entry, &value);
569 if (g_str_equal(key, "Interface") == TRUE) {
570 dbus_message_iter_get_basic(&value, &interface);
572 DBG("Interface %s", interface);
574 index = connman_inet_ifindex(interface);
576 DBG("index %d", index);
577 } else if (g_str_equal(key, "Method") == TRUE) {
578 dbus_message_iter_get_basic(&value, &val);
580 DBG("Method %s", val);
582 if (g_strcmp0(val, "static") == 0) {
583 context->ipv4_method = CONNMAN_IPCONFIG_METHOD_FIXED;
584 } else if (g_strcmp0(val, "dhcp") == 0) {
585 context->ipv4_method = CONNMAN_IPCONFIG_METHOD_DHCP;
588 } else if (g_str_equal(key, "Address") == TRUE) {
589 dbus_message_iter_get_basic(&value, &val);
591 address = g_strdup(val);
593 DBG("Address %s", address);
594 } else if (g_str_equal(key, "Netmask") == TRUE) {
595 dbus_message_iter_get_basic(&value, &val);
597 netmask = g_strdup(val);
599 DBG("Netmask %s", netmask);
600 } else if (g_str_equal(key, "DomainNameServers") == TRUE) {
601 nameservers = extract_nameservers(&value);
603 DBG("Nameservers %s", nameservers);
604 } else if (g_str_equal(key, "Gateway") == TRUE) {
605 dbus_message_iter_get_basic(&value, &val);
607 gateway = g_strdup(val);
609 DBG("Gateway %s", gateway);
612 dbus_message_iter_next(&dict);
618 if (context->ipv4_method != CONNMAN_IPCONFIG_METHOD_FIXED)
621 context->ipv4_address = connman_ipaddress_alloc(CONNMAN_IPCONFIG_TYPE_IPV4);
622 if (context->ipv4_address == NULL)
625 context->index = index;
626 connman_ipaddress_set_ipv4(context->ipv4_address, address,
629 context->ipv4_nameservers = nameservers;
632 if (context->ipv4_nameservers != nameservers)
640 static void extract_ipv6_settings(DBusMessageIter *array,
641 struct network_context *context)
643 DBusMessageIter dict;
644 char *address = NULL, *gateway = NULL;
645 unsigned char prefix_length;
646 char *nameservers = NULL;
647 const char *interface = NULL;
650 if (dbus_message_iter_get_arg_type(array) != DBUS_TYPE_ARRAY)
653 dbus_message_iter_recurse(array, &dict);
655 while (dbus_message_iter_get_arg_type(&dict) == DBUS_TYPE_DICT_ENTRY) {
656 DBusMessageIter entry, value;
657 const char *key, *val;
659 dbus_message_iter_recurse(&dict, &entry);
660 dbus_message_iter_get_basic(&entry, &key);
662 dbus_message_iter_next(&entry);
663 dbus_message_iter_recurse(&entry, &value);
665 if (g_str_equal(key, "Interface") == TRUE) {
666 dbus_message_iter_get_basic(&value, &interface);
668 DBG("Interface %s", interface);
670 index = connman_inet_ifindex(interface);
672 DBG("index %d", index);
673 } else if (g_str_equal(key, "Address") == TRUE) {
674 dbus_message_iter_get_basic(&value, &val);
676 address = g_strdup(val);
678 DBG("Address %s", address);
679 } else if (g_str_equal(key, "PrefixLength") == TRUE) {
680 dbus_message_iter_get_basic(&value, &prefix_length);
682 DBG("prefix length %d", prefix_length);
683 } else if (g_str_equal(key, "DomainNameServers") == TRUE) {
684 nameservers = extract_nameservers(&value);
686 DBG("Nameservers %s", nameservers);
687 } else if (g_str_equal(key, "Gateway") == TRUE) {
688 dbus_message_iter_get_basic(&value, &val);
690 gateway = g_strdup(val);
692 DBG("Gateway %s", gateway);
695 dbus_message_iter_next(&dict);
701 context->ipv6_method = CONNMAN_IPCONFIG_METHOD_FIXED;
703 context->ipv6_address =
704 connman_ipaddress_alloc(CONNMAN_IPCONFIG_TYPE_IPV6);
705 if (context->ipv6_address == NULL)
708 context->index = index;
709 connman_ipaddress_set_ipv6(context->ipv6_address, address,
710 prefix_length, gateway);
712 context->ipv6_nameservers = nameservers;
715 if (context->ipv6_nameservers != nameservers)
722 static connman_bool_t ready_to_create_device(struct modem_data *modem)
725 * There are three different modem types which behave slightly
727 * - GSM modems will expose the SIM interface then the
729 * - DUN modems will expose first a unique serial number (BDADDR)
730 * and then the CM interface.
731 * - CDMA modems will expose CM first and sometime later
732 * a unique serial number.
734 * This functions tests if we have the necessary information gathered
735 * before we are able to create a device.
738 if (modem->device != NULL)
741 if (modem->imsi != NULL || modem->serial != NULL)
747 static void create_device(struct modem_data *modem)
749 struct connman_device *device;
750 char *uninitialized_var(ident);
752 DBG("%s", modem->path);
754 if (modem->imsi != NULL)
756 else if (modem->serial != NULL)
757 ident = modem->serial;
759 if (connman_dbus_validate_ident(ident) == FALSE)
760 ident = connman_dbus_encode_string(ident);
762 ident = g_strdup(ident);
764 device = connman_device_create(ident, CONNMAN_DEVICE_TYPE_CELLULAR);
768 DBG("device %p", device);
770 connman_device_set_ident(device, ident);
772 connman_device_set_string(device, "Path", modem->path);
774 connman_device_set_data(device, modem);
776 if (connman_device_register(device) < 0) {
777 connman_error("Failed to register cellular device");
778 connman_device_unref(device);
782 modem->device = device;
788 static void destroy_device(struct modem_data *modem)
790 DBG("%s", modem->path);
792 connman_device_set_powered(modem->device, FALSE);
794 if (modem->network != NULL) {
795 connman_device_remove_network(modem->device, modem->network);
796 connman_network_unref(modem->network);
797 modem->network = NULL;
800 connman_device_unregister(modem->device);
801 connman_device_unref(modem->device);
803 modem->device = NULL;
806 static void add_network(struct modem_data *modem)
810 DBG("%s", modem->path);
812 if (modem->network != NULL)
815 modem->network = connman_network_create(modem->context->path,
816 CONNMAN_NETWORK_TYPE_CELLULAR);
817 if (modem->network == NULL)
820 DBG("network %p", modem->network);
822 connman_network_set_data(modem->network, modem);
824 connman_network_set_string(modem->network, "Path",
825 modem->context->path);
827 connman_network_set_index(modem->network, modem->context->index);
829 if (modem->name != NULL)
830 connman_network_set_name(modem->network, modem->name);
832 connman_network_set_name(modem->network, "");
834 connman_network_set_strength(modem->network, modem->strength);
836 group = get_ident(modem->context->path);
837 connman_network_set_group(modem->network, group);
839 connman_network_set_available(modem->network, TRUE);
841 if (connman_device_add_network(modem->device, modem->network) < 0) {
842 connman_network_unref(modem->network);
843 modem->network = NULL;
848 static int add_cm_context(struct modem_data *modem, const char *context_path,
849 DBusMessageIter *dict)
851 const char *context_type;
852 struct network_context *context = NULL;
853 connman_bool_t active = FALSE;
855 DBG("%s context path %s", modem->path, context_path);
857 if (modem->context != NULL) {
859 * We have already assigned a context to this modem
860 * and we do only support one Internet context.
865 context = network_context_alloc(context_path);
869 while (dbus_message_iter_get_arg_type(dict) == DBUS_TYPE_DICT_ENTRY) {
870 DBusMessageIter entry, value;
873 dbus_message_iter_recurse(dict, &entry);
874 dbus_message_iter_get_basic(&entry, &key);
876 dbus_message_iter_next(&entry);
877 dbus_message_iter_recurse(&entry, &value);
879 if (g_str_equal(key, "Type") == TRUE) {
880 dbus_message_iter_get_basic(&value, &context_type);
882 DBG("%s context %s type %s", modem->path,
883 context_path, context_type);
884 } else if (g_str_equal(key, "Settings") == TRUE) {
885 DBG("%s Settings", modem->path);
887 extract_ipv4_settings(&value, context);
888 } else if (g_str_equal(key, "IPv6.Settings") == TRUE) {
889 DBG("%s IPv6.Settings", modem->path);
891 extract_ipv6_settings(&value, context);
892 } else if (g_str_equal(key, "Active") == TRUE) {
893 dbus_message_iter_get_basic(&value, &active);
895 DBG("%s Active %d", modem->path, active);
898 dbus_message_iter_next(dict);
901 if (g_strcmp0(context_type, "internet") != 0) {
902 network_context_free(context);
906 modem->context = context;
907 modem->active = active;
909 g_hash_table_replace(context_hash, g_strdup(context_path), modem);
914 static void remove_cm_context(struct modem_data *modem,
915 const char *context_path)
917 if (modem->context == NULL)
920 g_hash_table_remove(context_hash, context_path);
922 network_context_free(modem->context);
923 modem->context = NULL;
926 static gboolean context_changed(DBusConnection *connection,
927 DBusMessage *message,
930 const char *context_path = dbus_message_get_path(message);
931 struct modem_data *modem = NULL;
932 DBusMessageIter iter, value;
935 DBG("context_path %s", context_path);
937 modem = g_hash_table_lookup(context_hash, context_path);
941 if (dbus_message_iter_init(message, &iter) == FALSE)
944 dbus_message_iter_get_basic(&iter, &key);
946 dbus_message_iter_next(&iter);
947 dbus_message_iter_recurse(&iter, &value);
950 * oFono guarantees the ordering of Settings and
951 * Active. Settings will always be send before Active = True.
952 * That means we don't have to order here.
954 if (g_str_equal(key, "Settings") == TRUE) {
955 DBG("%s Settings", modem->path);
957 extract_ipv4_settings(&value, modem->context);
958 } else if (g_str_equal(key, "IPv6.Settings") == TRUE) {
959 DBG("%s IPv6.Settings", modem->path);
961 extract_ipv6_settings(&value, modem->context);
962 } else if (g_str_equal(key, "Active") == TRUE) {
963 dbus_message_iter_get_basic(&value, &modem->active);
965 DBG("%s Active %d", modem->path, modem->active);
967 if (modem->active == TRUE)
968 set_connected(modem);
970 set_disconnected(modem);
976 static void cm_get_contexts_reply(DBusPendingCall *call, void *user_data)
978 struct modem_data *modem = user_data;
979 DBusMessageIter array, dict, entry, value;
983 DBG("%s", modem->path);
985 modem->call_get_contexts = NULL;
987 reply = dbus_pending_call_steal_reply(call);
989 dbus_error_init(&error);
991 if (dbus_set_error_from_message(&error, reply) == TRUE) {
992 connman_error("%s", error.message);
993 dbus_error_free(&error);
997 if (dbus_message_iter_init(reply, &array) == FALSE)
1000 if (dbus_message_iter_get_arg_type(&array) != DBUS_TYPE_ARRAY)
1003 dbus_message_iter_recurse(&array, &dict);
1005 while (dbus_message_iter_get_arg_type(&dict) == DBUS_TYPE_STRUCT) {
1006 const char *context_path;
1008 dbus_message_iter_recurse(&dict, &entry);
1009 dbus_message_iter_get_basic(&entry, &context_path);
1011 dbus_message_iter_next(&entry);
1012 dbus_message_iter_recurse(&entry, &value);
1014 if (add_cm_context(modem, context_path, &value) == 0)
1017 dbus_message_iter_next(&dict);
1021 dbus_message_unref(reply);
1023 dbus_pending_call_unref(call);
1026 static int cm_get_contexts(struct modem_data *modem)
1028 DBusMessage *message;
1030 DBG("%s", modem->path);
1032 if (modem->call_get_contexts != NULL)
1035 message = dbus_message_new_method_call(OFONO_SERVICE, modem->path,
1036 OFONO_CM_INTERFACE, GET_CONTEXTS);
1037 if (message == NULL)
1040 if (dbus_connection_send_with_reply(connection, message,
1041 &modem->call_get_contexts, TIMEOUT) == FALSE) {
1042 connman_error("Failed to call GetContexts()");
1043 dbus_message_unref(message);
1047 if (modem->call_get_contexts == NULL) {
1048 connman_error("D-Bus connection not available");
1049 dbus_message_unref(message);
1053 dbus_pending_call_set_notify(modem->call_get_contexts,
1054 cm_get_contexts_reply,
1057 dbus_message_unref(message);
1059 return -EINPROGRESS;
1062 static gboolean cm_context_added(DBusConnection *connection,
1063 DBusMessage *message,
1066 const char *path = dbus_message_get_path(message);
1068 struct modem_data *modem;
1069 DBusMessageIter iter, properties;
1073 modem = g_hash_table_lookup(modem_hash, context_path);
1077 if (dbus_message_iter_init(message, &iter) == FALSE)
1080 dbus_message_iter_get_basic(&iter, &context_path);
1082 dbus_message_iter_next(&iter);
1083 dbus_message_iter_recurse(&iter, &properties);
1085 if (add_cm_context(modem, context_path, &properties) != 0)
1091 static gboolean cm_context_removed(DBusConnection *connection,
1092 DBusMessage *message,
1095 const char *path = dbus_message_get_path(message);
1096 const char *context_path;
1097 struct modem_data *modem;
1098 DBusMessageIter iter;
1100 DBG("context path %s", path);
1102 if (dbus_message_iter_init(message, &iter) == FALSE)
1105 dbus_message_iter_get_basic(&iter, &context_path);
1107 modem = g_hash_table_lookup(context_hash, context_path);
1111 remove_cm_context(modem, context_path);
1116 static gboolean netreg_changed(DBusConnection *connection, DBusMessage *message,
1119 const char *path = dbus_message_get_path(message);
1120 struct modem_data *modem;
1121 DBusMessageIter iter, value;
1124 modem = g_hash_table_lookup(modem_hash, path);
1128 if (dbus_message_iter_init(message, &iter) == FALSE)
1131 dbus_message_iter_get_basic(&iter, &key);
1133 dbus_message_iter_next(&iter);
1134 dbus_message_iter_recurse(&iter, &value);
1136 if (g_str_equal(key, "Name") == TRUE) {
1139 dbus_message_iter_get_basic(&value, &name);
1141 DBG("%s Name %s", modem->path, name);
1143 g_free(modem->name);
1144 modem->name = g_strdup(name);
1146 if (modem->network == NULL)
1149 connman_network_set_name(modem->network, modem->name);
1150 connman_network_update(modem->network);
1151 } else if (g_str_equal(key, "Strength") == TRUE) {
1152 dbus_message_iter_get_basic(&value, &modem->strength);
1154 DBG("%s Strength %d", modem->path, modem->strength);
1156 if (modem->network == NULL)
1159 connman_network_set_strength(modem->network, modem->strength);
1160 connman_network_update(modem->network);
1166 static void netreg_properties_reply(struct modem_data *modem,
1167 DBusMessageIter *dict)
1169 DBG("%s", modem->path);
1171 while (dbus_message_iter_get_arg_type(dict) == DBUS_TYPE_DICT_ENTRY) {
1172 DBusMessageIter entry, value;
1175 dbus_message_iter_recurse(dict, &entry);
1176 dbus_message_iter_get_basic(&entry, &key);
1178 dbus_message_iter_next(&entry);
1179 dbus_message_iter_recurse(&entry, &value);
1181 if (g_str_equal(key, "Name") == TRUE) {
1184 dbus_message_iter_get_basic(&value, &name);
1186 DBG("%s Name %s", modem->path, name);
1188 g_free(modem->name);
1189 modem->name = g_strdup(name);
1191 if (modem->network != NULL) {
1192 connman_network_set_name(modem->network,
1194 connman_network_update(modem->network);
1196 } else if (g_str_equal(key, "Strength") == TRUE) {
1197 dbus_message_iter_get_basic(&value, &modem->strength);
1199 DBG("%s Strength %d", modem->path,
1202 if (modem->network != NULL) {
1203 connman_network_set_strength(modem->network,
1205 connman_network_update(modem->network);
1209 dbus_message_iter_next(dict);
1212 if (modem->context == NULL) {
1214 * netgreg_get_properties() was issued after we got
1215 * cm_get_contexts_reply() where we create the
1216 * context. Though before we got the
1217 * netreg_properties_reply the context was removed
1218 * again. Therefore we have to skip the network
1226 if (modem->active == TRUE)
1227 set_connected(modem);
1230 static int netreg_get_properties(struct modem_data *modem)
1232 return get_properties(modem->path, OFONO_NETREG_INTERFACE,
1233 netreg_properties_reply, modem);
1236 static gboolean cm_changed(DBusConnection *connection, DBusMessage *message,
1239 const char *path = dbus_message_get_path(message);
1240 struct modem_data *modem;
1241 DBusMessageIter iter, value;
1244 modem = g_hash_table_lookup(modem_hash, path);
1248 if (dbus_message_iter_init(message, &iter) == FALSE)
1251 dbus_message_iter_get_basic(&iter, &key);
1253 dbus_message_iter_next(&iter);
1254 dbus_message_iter_recurse(&iter, &value);
1256 if (g_str_equal(key, "Attached") == TRUE) {
1257 dbus_message_iter_get_basic(&value, &modem->attached);
1259 DBG("%s Attached %d", modem->path, modem->attached);
1261 if (modem->attached == TRUE) {
1262 if (has_interface(modem->interfaces,
1263 OFONO_API_NETREG) == TRUE) {
1264 netreg_get_properties(modem);
1267 } else if (g_str_equal(key, "Powered") == TRUE) {
1268 dbus_message_iter_get_basic(&value, &modem->cm_powered);
1270 DBG("%s ConnnectionManager Powered %d", modem->path,
1273 if (modem->cm_powered == FALSE)
1274 cm_set_powered(modem);
1280 static void cm_properties_reply(struct modem_data *modem, DBusMessageIter *dict)
1282 DBG("%s", modem->path);
1284 while (dbus_message_iter_get_arg_type(dict) == DBUS_TYPE_DICT_ENTRY) {
1285 DBusMessageIter entry, value;
1288 dbus_message_iter_recurse(dict, &entry);
1289 dbus_message_iter_get_basic(&entry, &key);
1291 dbus_message_iter_next(&entry);
1292 dbus_message_iter_recurse(&entry, &value);
1294 if (g_str_equal(key, "Attached") == TRUE) {
1295 dbus_message_iter_get_basic(&value, &modem->attached);
1297 DBG("%s Attached %d", modem->path,
1300 if (modem->attached == TRUE) {
1301 if (has_interface(modem->interfaces,
1302 OFONO_API_NETREG) == TRUE) {
1303 netreg_get_properties(modem);
1306 } else if (g_str_equal(key, "Powered") == TRUE) {
1307 dbus_message_iter_get_basic(&value, &modem->cm_powered);
1309 DBG("%s ConnnectionManager Powered %d", modem->path,
1312 if (modem->cm_powered == FALSE)
1313 cm_set_powered(modem);
1316 dbus_message_iter_next(dict);
1320 static int cm_get_properties(struct modem_data *modem)
1322 return get_properties(modem->path, OFONO_CM_INTERFACE,
1323 cm_properties_reply, modem);
1326 static void update_sim_imsi(struct modem_data *modem,
1329 DBG("%s imsi %s", modem->path, imsi);
1331 if (g_strcmp0(modem->imsi, imsi) == 0)
1334 g_free(modem->imsi);
1335 modem->imsi = g_strdup(imsi);
1338 static gboolean sim_changed(DBusConnection *connection, DBusMessage *message,
1341 const char *path = dbus_message_get_path(message);
1342 struct modem_data *modem;
1343 DBusMessageIter iter, value;
1346 modem = g_hash_table_lookup(modem_hash, path);
1350 if (dbus_message_iter_init(message, &iter) == FALSE)
1353 dbus_message_iter_get_basic(&iter, &key);
1355 dbus_message_iter_next(&iter);
1356 dbus_message_iter_recurse(&iter, &value);
1358 if (g_str_equal(key, "SubscriberIdentity") == TRUE) {
1361 dbus_message_iter_get_basic(&value, &imsi);
1363 update_sim_imsi(modem, imsi);
1365 if (modem->online == FALSE) {
1366 modem_set_online(modem);
1367 } else if (has_interface(modem->interfaces,
1368 OFONO_API_CM) == TRUE) {
1369 if (ready_to_create_device(modem) == TRUE)
1370 create_device(modem);
1377 static void sim_properties_reply(struct modem_data *modem,
1378 DBusMessageIter *dict)
1380 DBG("%s", modem->path);
1382 while (dbus_message_iter_get_arg_type(dict) == DBUS_TYPE_DICT_ENTRY) {
1383 DBusMessageIter entry, value;
1386 dbus_message_iter_recurse(dict, &entry);
1387 dbus_message_iter_get_basic(&entry, &key);
1389 dbus_message_iter_next(&entry);
1390 dbus_message_iter_recurse(&entry, &value);
1392 if (g_str_equal(key, "SubscriberIdentity") == TRUE) {
1395 dbus_message_iter_get_basic(&value, &imsi);
1397 update_sim_imsi(modem, imsi);
1399 if (modem->online == FALSE) {
1400 modem_set_online(modem);
1404 if (has_interface(modem->interfaces, OFONO_API_CM) == TRUE) {
1405 if (ready_to_create_device(modem) == TRUE)
1406 create_device(modem);
1407 if (modem->device != NULL) {
1408 cm_get_properties(modem);
1409 cm_get_contexts(modem);
1415 dbus_message_iter_next(dict);
1419 static int sim_get_properties(struct modem_data *modem)
1421 return get_properties(modem->path, OFONO_SIM_INTERFACE,
1422 sim_properties_reply, modem);
1425 static gboolean modem_changed(DBusConnection *connection, DBusMessage *message,
1428 const char *path = dbus_message_get_path(message);
1429 struct modem_data *modem;
1430 DBusMessageIter iter, value;
1433 modem = g_hash_table_lookup(modem_hash, path);
1437 if (dbus_message_iter_init(message, &iter) == FALSE)
1440 dbus_message_iter_get_basic(&iter, &key);
1442 dbus_message_iter_next(&iter);
1443 dbus_message_iter_recurse(&iter, &value);
1445 if (g_str_equal(key, "Powered") == TRUE) {
1446 dbus_message_iter_get_basic(&value, &modem->powered);
1448 DBG("%s Powered %d", modem->path, modem->powered);
1450 if (modem->powered == FALSE)
1451 modem_set_powered(modem);
1452 } else if (g_str_equal(key, "Online") == TRUE) {
1453 dbus_message_iter_get_basic(&value, &modem->online);
1455 DBG("%s Online %d", modem->path, modem->online);
1457 if (modem->online == FALSE)
1460 if (has_interface(modem->interfaces, OFONO_API_CM) == FALSE)
1462 if (ready_to_create_device(modem) == TRUE)
1463 create_device(modem);
1464 if (modem->device != NULL) {
1465 cm_get_properties(modem);
1466 cm_get_contexts(modem);
1468 } else if (g_str_equal(key, "Interfaces") == TRUE) {
1469 modem->interfaces = extract_interfaces(&value);
1471 DBG("%s Interfaces 0x%02x", modem->path,
1474 if (has_interface(modem->interfaces, OFONO_API_SIM) == TRUE) {
1475 if (modem->imsi == NULL &&
1476 modem->set_powered == FALSE) {
1478 * Only use do GetProperties() when
1479 * device has not been powered up.
1481 sim_get_properties(modem);
1486 if (has_interface(modem->interfaces, OFONO_API_CM) == TRUE) {
1487 if (ready_to_create_device(modem) == TRUE)
1488 create_device(modem);
1489 if (modem->device != NULL) {
1490 cm_get_properties(modem);
1491 cm_get_contexts(modem);
1495 if (modem->context != NULL) {
1496 remove_cm_context(modem,
1497 modem->context->path);
1500 if (modem->device != NULL)
1501 destroy_device(modem);
1506 if (has_interface(modem->interfaces, OFONO_API_NETREG) == TRUE) {
1507 if (modem->attached == TRUE)
1508 netreg_get_properties(modem);
1510 } else if (g_str_equal(key, "Serial") == TRUE) {
1513 dbus_message_iter_get_basic(&value, &serial);
1515 g_free(modem->serial);
1516 modem->serial = g_strdup(serial);
1518 DBG("%s Serial %s", modem->path, modem->serial);
1520 if (has_interface(modem->interfaces, OFONO_API_CM) == TRUE) {
1521 if (ready_to_create_device(modem) == TRUE)
1522 create_device(modem);
1523 if (modem->device != NULL) {
1524 cm_get_properties(modem);
1525 cm_get_contexts(modem);
1533 static void add_modem(const char *path, DBusMessageIter *prop)
1535 struct modem_data *modem;
1539 modem = g_hash_table_lookup(modem_hash, path);
1540 if (modem != NULL) {
1542 * When oFono powers up we ask for the modems and oFono is
1543 * reporting with modem_added signal the modems. Only
1549 modem = g_try_new0(struct modem_data, 1);
1553 modem->path = g_strdup(path);
1555 g_hash_table_insert(modem_hash, g_strdup(path), modem);
1557 while (dbus_message_iter_get_arg_type(prop) == DBUS_TYPE_DICT_ENTRY) {
1558 DBusMessageIter entry, value;
1561 dbus_message_iter_recurse(prop, &entry);
1562 dbus_message_iter_get_basic(&entry, &key);
1564 dbus_message_iter_next(&entry);
1565 dbus_message_iter_recurse(&entry, &value);
1567 if (g_str_equal(key, "Powered") == TRUE) {
1568 dbus_message_iter_get_basic(&value, &modem->powered);
1570 DBG("%s Powered %d", modem->path, modem->powered);
1571 } else if (g_str_equal(key, "Online") == TRUE) {
1572 dbus_message_iter_get_basic(&value, &modem->online);
1574 DBG("%s Online %d", modem->path, modem->online);
1575 } else if (g_str_equal(key, "Interfaces") == TRUE) {
1576 modem->interfaces = extract_interfaces(&value);
1578 DBG("%s Interfaces 0x%02x", modem->path,
1580 } else if (g_str_equal(key, "Serial") == TRUE) {
1583 dbus_message_iter_get_basic(&value, &serial);
1584 modem->serial = g_strdup(serial);
1586 DBG("%s Serial %s", modem->path, modem->serial);
1589 dbus_message_iter_next(prop);
1592 if (modem->powered == FALSE) {
1593 modem_set_powered(modem);
1594 } else if (has_interface(modem->interfaces, OFONO_API_SIM) == TRUE) {
1595 sim_get_properties(modem);
1596 } else if (has_interface(modem->interfaces, OFONO_API_CM) == TRUE) {
1597 if (ready_to_create_device(modem) == TRUE)
1598 create_device(modem);
1599 if (modem->device != NULL) {
1600 cm_get_properties(modem);
1601 cm_get_contexts(modem);
1606 static void remove_modem(gpointer data)
1608 struct modem_data *modem = data;
1610 DBG("%s", modem->path);
1612 if (modem->call_set_property != NULL)
1613 dbus_pending_call_cancel(modem->call_set_property);
1615 if (modem->call_get_properties != NULL)
1616 dbus_pending_call_cancel(modem->call_get_properties);
1618 if (modem->call_get_contexts != NULL)
1619 dbus_pending_call_cancel(modem->call_get_contexts);
1621 if (modem->device != NULL)
1622 destroy_device(modem);
1624 if (modem->context != NULL)
1625 remove_cm_context(modem, modem->context->path);
1627 g_free(modem->serial);
1628 g_free(modem->name);
1629 g_free(modem->imsi);
1630 g_free(modem->path);
1635 static gboolean modem_added(DBusConnection *connection,
1636 DBusMessage *message, void *user_data)
1638 DBusMessageIter iter, properties;
1643 if (dbus_message_iter_init(message, &iter) == FALSE)
1646 dbus_message_iter_get_basic(&iter, &path);
1648 dbus_message_iter_next(&iter);
1649 dbus_message_iter_recurse(&iter, &properties);
1651 add_modem(path, &properties);
1656 static gboolean modem_removed(DBusConnection *connection,
1657 DBusMessage *message, void *user_data)
1659 DBusMessageIter iter;
1664 if (dbus_message_iter_init(message, &iter) == FALSE)
1667 dbus_message_iter_get_basic(&iter, &path);
1669 g_hash_table_remove(modem_hash, path);
1674 static void manager_get_modems_reply(DBusPendingCall *call, void *user_data)
1678 DBusMessageIter array, dict;
1682 reply = dbus_pending_call_steal_reply(call);
1684 dbus_error_init(&error);
1686 if (dbus_set_error_from_message(&error, reply) == TRUE) {
1687 connman_error("%s", error.message);
1688 dbus_error_free(&error);
1692 if (dbus_message_iter_init(reply, &array) == FALSE)
1695 dbus_message_iter_recurse(&array, &dict);
1697 while (dbus_message_iter_get_arg_type(&dict) == DBUS_TYPE_STRUCT) {
1698 DBusMessageIter value, properties;
1701 dbus_message_iter_recurse(&dict, &value);
1702 dbus_message_iter_get_basic(&value, &path);
1704 dbus_message_iter_next(&value);
1705 dbus_message_iter_recurse(&value, &properties);
1707 add_modem(path, &properties);
1709 dbus_message_iter_next(&dict);
1713 dbus_message_unref(reply);
1715 dbus_pending_call_unref(call);
1718 static int manager_get_modems(void)
1720 DBusMessage *message;
1721 DBusPendingCall *call;
1725 message = dbus_message_new_method_call(OFONO_SERVICE, "/",
1726 OFONO_MANAGER_INTERFACE, GET_MODEMS);
1727 if (message == NULL)
1730 if (dbus_connection_send_with_reply(connection, message,
1731 &call, TIMEOUT) == FALSE) {
1732 connman_error("Failed to call GetModems()");
1733 dbus_message_unref(message);
1738 connman_error("D-Bus connection not available");
1739 dbus_message_unref(message);
1743 dbus_pending_call_set_notify(call, manager_get_modems_reply,
1746 dbus_message_unref(message);
1748 return -EINPROGRESS;
1751 static void ofono_connect(DBusConnection *conn, void *user_data)
1755 modem_hash = g_hash_table_new_full(g_str_hash, g_str_equal,
1756 g_free, remove_modem);
1757 if (modem_hash == NULL)
1760 context_hash = g_hash_table_new_full(g_str_hash, g_str_equal,
1762 if (context_hash == NULL) {
1763 g_hash_table_destroy(modem_hash);
1767 manager_get_modems();
1770 static void ofono_disconnect(DBusConnection *conn, void *user_data)
1774 if (modem_hash == NULL || context_hash == NULL)
1777 g_hash_table_destroy(modem_hash);
1780 g_hash_table_destroy(context_hash);
1781 context_hash = NULL;
1784 static int network_probe(struct connman_network *network)
1786 struct modem_data *modem = connman_network_get_data(network);
1788 DBG("%s network %p", modem->path, network);
1793 static void network_remove(struct connman_network *network)
1795 struct modem_data *modem = connman_network_get_data(network);
1797 DBG("%s network %p", modem->path, network);
1800 static int network_connect(struct connman_network *network)
1802 struct modem_data *modem = connman_network_get_data(network);
1804 DBG("%s network %p", modem->path, network);
1809 static int network_disconnect(struct connman_network *network)
1811 struct modem_data *modem = connman_network_get_data(network);
1813 DBG("%s network %p", modem->path, network);
1818 static struct connman_network_driver network_driver = {
1820 .type = CONNMAN_NETWORK_TYPE_CELLULAR,
1821 .probe = network_probe,
1822 .remove = network_remove,
1823 .connect = network_connect,
1824 .disconnect = network_disconnect,
1827 static int modem_probe(struct connman_device *device)
1829 struct modem_data *modem = connman_device_get_data(device);
1831 DBG("%s device %p", modem->path, device);
1836 static void modem_remove(struct connman_device *device)
1838 struct modem_data *modem = connman_device_get_data(device);
1840 DBG("%s device %p", modem->path, device);
1843 static int modem_enable(struct connman_device *device)
1845 struct modem_data *modem = connman_device_get_data(device);
1847 DBG("%s device %p", modem->path, device);
1852 static int modem_disable(struct connman_device *device)
1854 struct modem_data *modem = connman_device_get_data(device);
1856 DBG("%s device %p", modem->path, device);
1861 static struct connman_device_driver modem_driver = {
1863 .type = CONNMAN_DEVICE_TYPE_CELLULAR,
1864 .probe = modem_probe,
1865 .remove = modem_remove,
1866 .enable = modem_enable,
1867 .disable = modem_disable,
1871 static guint modem_added_watch;
1872 static guint modem_removed_watch;
1873 static guint modem_watch;
1874 static guint cm_watch;
1875 static guint sim_watch;
1876 static guint context_added_watch;
1877 static guint context_removed_watch;
1878 static guint netreg_watch;
1879 static guint context_watch;
1881 static int ofono_init(void)
1887 connection = connman_dbus_get_connection();
1888 if (connection == NULL)
1891 watch = g_dbus_add_service_watch(connection,
1892 OFONO_SERVICE, ofono_connect,
1893 ofono_disconnect, NULL, NULL);
1895 modem_added_watch = g_dbus_add_signal_watch(connection, NULL, NULL,
1896 OFONO_MANAGER_INTERFACE,
1901 modem_removed_watch = g_dbus_add_signal_watch(connection, NULL, NULL,
1902 OFONO_MANAGER_INTERFACE,
1907 modem_watch = g_dbus_add_signal_watch(connection, NULL, NULL,
1908 OFONO_MODEM_INTERFACE,
1913 cm_watch = g_dbus_add_signal_watch(connection, NULL, NULL,
1919 sim_watch = g_dbus_add_signal_watch(connection, NULL, NULL,
1920 OFONO_SIM_INTERFACE,
1925 context_added_watch = g_dbus_add_signal_watch(connection, NULL, NULL,
1931 context_removed_watch = g_dbus_add_signal_watch(connection, NULL, NULL,
1937 context_watch = g_dbus_add_signal_watch(connection, NULL, NULL,
1938 OFONO_CONTEXT_INTERFACE,
1943 netreg_watch = g_dbus_add_signal_watch(connection, NULL, NULL,
1944 OFONO_NETREG_INTERFACE,
1950 if (watch == 0 || modem_added_watch == 0 || modem_removed_watch == 0 ||
1951 modem_watch == 0 || cm_watch == 0 || sim_watch == 0 ||
1952 context_added_watch == 0 ||
1953 context_removed_watch == 0 ||
1954 context_watch == 0 || netreg_watch == 0) {
1959 err = connman_network_driver_register(&network_driver);
1963 err = connman_device_driver_register(&modem_driver);
1965 connman_network_driver_unregister(&network_driver);
1972 g_dbus_remove_watch(connection, netreg_watch);
1973 g_dbus_remove_watch(connection, context_watch);
1974 g_dbus_remove_watch(connection, context_removed_watch);
1975 g_dbus_remove_watch(connection, context_added_watch);
1976 g_dbus_remove_watch(connection, sim_watch);
1977 g_dbus_remove_watch(connection, cm_watch);
1978 g_dbus_remove_watch(connection, modem_watch);
1979 g_dbus_remove_watch(connection, modem_removed_watch);
1980 g_dbus_remove_watch(connection, modem_added_watch);
1981 g_dbus_remove_watch(connection, watch);
1982 dbus_connection_unref(connection);
1987 static void ofono_exit(void)
1991 if (modem_hash != NULL) {
1992 g_hash_table_destroy(modem_hash);
1996 if (context_hash != NULL) {
1997 g_hash_table_destroy(context_hash);
1998 context_hash = NULL;
2001 connman_device_driver_unregister(&modem_driver);
2002 connman_network_driver_unregister(&network_driver);
2004 g_dbus_remove_watch(connection, netreg_watch);
2005 g_dbus_remove_watch(connection, context_watch);
2006 g_dbus_remove_watch(connection, context_removed_watch);
2007 g_dbus_remove_watch(connection, context_added_watch);
2008 g_dbus_remove_watch(connection, sim_watch);
2009 g_dbus_remove_watch(connection, cm_watch);
2010 g_dbus_remove_watch(connection, modem_watch);
2011 g_dbus_remove_watch(connection, modem_added_watch);
2012 g_dbus_remove_watch(connection, modem_removed_watch);
2013 g_dbus_remove_watch(connection, watch);
2015 dbus_connection_unref(connection);
2018 CONNMAN_PLUGIN_DEFINE(ofono, "oFono telephony plugin", VERSION,
2019 CONNMAN_PLUGIN_PRIORITY_DEFAULT, ofono_init, ofono_exit)