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,
73 * The way this plugin works is following:
75 * powered -> SubscriberIdentity or Online = True -> gprs, context ->
76 * attached -> netreg -> ready
78 * Enabling and disabling modems are steered through the rfkill
79 * interface. That means when ConnMan toggles the rfkill bit oFono
80 * will add or remove the modems.
82 * ConnMan will always power up (set Powered and Online) the
83 * modems. No need to power them down because this will be done
84 * through the rfkill inteface.
87 static DBusConnection *connection;
89 static GHashTable *modem_hash;
90 static GHashTable *context_hash;
92 struct network_context {
96 enum connman_ipconfig_method ipv4_method;
97 struct connman_ipaddress *ipv4_address;
98 char *ipv4_nameservers;
100 enum connman_ipconfig_method ipv6_method;
101 struct connman_ipaddress *ipv6_address;
102 char *ipv6_nameservers;
108 struct connman_device *device;
109 struct connman_network *network;
111 struct network_context *context;
113 /* Modem Interface */
115 connman_bool_t powered;
116 connman_bool_t online;
118 connman_bool_t ignore;
120 connman_bool_t set_powered;
121 connman_bool_t set_online;
123 /* ConnectionManager Interface */
124 connman_bool_t attached;
125 connman_bool_t cm_powered;
127 connman_bool_t set_cm_powered;
129 /* ConnectionContext Interface */
130 connman_bool_t active;
131 connman_bool_t set_active;
133 /* SimManager Interface */
136 /* Netreg Interface */
141 DBusPendingCall *call_set_property;
142 DBusPendingCall *call_get_properties;
143 DBusPendingCall *call_get_contexts;
146 static char *get_ident(const char *path)
153 pos = strrchr(path, '/');
160 static struct network_context *network_context_alloc(const char *path)
162 struct network_context *context;
164 context = g_try_new0(struct network_context, 1);
168 context->path = g_strdup(path);
171 context->ipv4_method = CONNMAN_IPCONFIG_METHOD_UNKNOWN;
172 context->ipv4_address = NULL;
173 context->ipv4_nameservers = NULL;
175 context->ipv6_method = CONNMAN_IPCONFIG_METHOD_UNKNOWN;
176 context->ipv6_address = NULL;
177 context->ipv6_nameservers = NULL;
182 static void network_context_free(struct network_context *context)
184 g_free(context->path);
186 connman_ipaddress_free(context->ipv4_address);
187 g_free(context->ipv4_nameservers);
189 connman_ipaddress_free(context->ipv6_address);
190 g_free(context->ipv6_nameservers);
195 static void set_connected(struct modem_data *modem)
197 connman_bool_t setip = FALSE;
199 DBG("%s", modem->path);
201 connman_network_set_index(modem->network, modem->context->index);
203 switch (modem->context->ipv4_method) {
204 case CONNMAN_IPCONFIG_METHOD_UNKNOWN:
205 case CONNMAN_IPCONFIG_METHOD_OFF:
206 case CONNMAN_IPCONFIG_METHOD_MANUAL:
207 case CONNMAN_IPCONFIG_METHOD_AUTO:
210 case CONNMAN_IPCONFIG_METHOD_FIXED:
211 connman_network_set_ipv4_method(modem->network,
212 modem->context->ipv4_method);
213 connman_network_set_ipaddress(modem->network,
214 modem->context->ipv4_address);
215 connman_network_set_nameservers(modem->network,
216 modem->context->ipv4_nameservers);
220 case CONNMAN_IPCONFIG_METHOD_DHCP:
221 connman_network_set_ipv4_method(modem->network,
222 modem->context->ipv4_method);
227 switch (modem->context->ipv6_method) {
228 case CONNMAN_IPCONFIG_METHOD_UNKNOWN:
229 case CONNMAN_IPCONFIG_METHOD_OFF:
230 case CONNMAN_IPCONFIG_METHOD_MANUAL:
231 case CONNMAN_IPCONFIG_METHOD_DHCP:
232 case CONNMAN_IPCONFIG_METHOD_AUTO:
235 case CONNMAN_IPCONFIG_METHOD_FIXED:
236 connman_network_set_ipv6_method(modem->network,
237 modem->context->ipv6_method);
238 connman_network_set_ipaddress(modem->network,
239 modem->context->ipv6_address);
245 connman_network_set_connected(modem->network, TRUE);
248 static void set_disconnected(struct modem_data *modem)
250 DBG("%s", modem->path);
252 connman_network_set_connected(modem->network, FALSE);
255 typedef void (*set_property_cb)(struct modem_data *data,
256 connman_bool_t success);
257 typedef void (*get_properties_cb)(struct modem_data *data,
258 DBusMessageIter *dict);
260 struct property_info {
261 struct modem_data *modem;
263 const char *interface;
264 const char *property;
265 set_property_cb set_property_cb;
266 get_properties_cb get_properties_cb;
269 static void set_property_reply(DBusPendingCall *call, void *user_data)
271 struct property_info *info = user_data;
274 connman_bool_t success = TRUE;
276 DBG("%s path %s %s.%s", info->modem->path,
277 info->path, info->interface, info->property);
279 info->modem->call_set_property = NULL;
281 dbus_error_init(&error);
283 reply = dbus_pending_call_steal_reply(call);
285 if (dbus_set_error_from_message(&error, reply)) {
286 connman_error("Failed to change property: %s %s.%s: %s %s",
287 info->path, info->interface, info->property,
288 error.name, error.message);
289 dbus_error_free(&error);
293 if (info->set_property_cb != NULL)
294 (*info->set_property_cb)(info->modem, success);
296 dbus_message_unref(reply);
298 dbus_pending_call_unref(call);
301 static int set_property(struct modem_data *modem,
302 const char *path, const char *interface,
303 const char *property, int type, void *value,
304 set_property_cb notify)
306 DBusMessage *message;
307 DBusMessageIter iter;
308 struct property_info *info;
310 DBG("%s path %s %s.%s", modem->path, path, interface, property);
312 if (modem->call_set_property != NULL) {
313 connman_error("Pending SetProperty");
317 message = dbus_message_new_method_call(OFONO_SERVICE, path,
318 interface, SET_PROPERTY);
322 dbus_message_iter_init_append(message, &iter);
323 connman_dbus_property_append_basic(&iter, property, type, value);
325 if (dbus_connection_send_with_reply(connection, message,
326 &modem->call_set_property, TIMEOUT) == FALSE) {
327 connman_error("Failed to change property: %s %s.%s",
328 path, interface, property);
329 dbus_message_unref(message);
333 if (modem->call_set_property == NULL) {
334 connman_error("D-Bus connection not available");
335 dbus_message_unref(message);
339 info = g_try_new0(struct property_info, 1);
341 dbus_message_unref(message);
347 info->interface = interface;
348 info->property = property;
349 info->set_property_cb = notify;
351 dbus_pending_call_set_notify(modem->call_set_property,
352 set_property_reply, info, g_free);
354 dbus_message_unref(message);
359 static void get_properties_reply(DBusPendingCall *call, void *user_data)
361 struct property_info *info = user_data;
362 DBusMessageIter array, dict;
366 DBG("%s path %s %s", info->modem->path, info->path, info->interface);
368 info->modem->call_get_properties = NULL;
370 dbus_error_init(&error);
372 reply = dbus_pending_call_steal_reply(call);
374 if (dbus_set_error_from_message(&error, reply)) {
375 connman_error("Failed to get properties: %s %s: %s %s",
376 info->path, info->interface,
377 error.name, error.message);
378 dbus_error_free(&error);
383 if (dbus_message_iter_init(reply, &array) == FALSE)
386 if (dbus_message_iter_get_arg_type(&array) != DBUS_TYPE_ARRAY)
389 dbus_message_iter_recurse(&array, &dict);
391 if (info->get_properties_cb != NULL)
392 (*info->get_properties_cb)(info->modem, &dict);
396 dbus_message_unref(reply);
398 dbus_pending_call_unref(call);
401 static int get_properties(const char *path, const char *interface,
402 get_properties_cb notify,
403 struct modem_data *modem)
405 DBusMessage *message;
406 struct property_info *info;
408 DBG("%s path %s %s", modem->path, path, interface);
410 if (modem->call_get_properties != NULL) {
411 connman_error("Pending GetProperties");
415 message = dbus_message_new_method_call(OFONO_SERVICE, path,
416 interface, GET_PROPERTIES);
420 if (dbus_connection_send_with_reply(connection, message,
421 &modem->call_get_properties, TIMEOUT) == FALSE) {
422 connman_error("Failed to call %s.GetProperties()", interface);
423 dbus_message_unref(message);
427 if (modem->call_get_properties == NULL) {
428 connman_error("D-Bus connection not available");
429 dbus_message_unref(message);
433 info = g_try_new0(struct property_info, 1);
435 dbus_message_unref(message);
441 info->interface = interface;
442 info->get_properties_cb = notify;
444 dbus_pending_call_set_notify(modem->call_get_properties,
445 get_properties_reply, info, g_free);
447 dbus_message_unref(message);
452 static void context_set_active_reply(struct modem_data *modem,
453 connman_bool_t success)
455 DBG("%s", modem->path);
457 if (success == TRUE) {
459 * Don't handle do anything on success here. oFono will send
460 * the change via PropertyChanged singal.
466 * Active = True might fail due a timeout. That means oFono
467 * still tries to go online. If we retry to set Active = True,
468 * we just get a InProgress error message. Should we power
469 * cycle the modem in such cases?
472 connman_network_set_error(modem->network,
473 CONNMAN_NETWORK_ERROR_ASSOCIATE_FAIL);
476 static int context_set_active(struct modem_data *modem)
478 dbus_bool_t active = TRUE;
480 DBG("%s", modem->path);
482 return set_property(modem, modem->context->path,
483 OFONO_CONTEXT_INTERFACE,
484 "Active", DBUS_TYPE_BOOLEAN,
486 context_set_active_reply);
489 static int context_set_inactive(struct modem_data *modem)
491 dbus_bool_t active = FALSE;
494 DBG("%s", modem->path);
496 err = set_property(modem, modem->context->path,
497 OFONO_CONTEXT_INTERFACE,
498 "Active", DBUS_TYPE_BOOLEAN,
501 if (err == -EINPROGRESS)
507 static void modem_set_online_reply(struct modem_data *modem,
508 connman_bool_t success)
510 DBG("%s", modem->path);
512 if (success == TRUE) {
514 * Don't handle do anything on success here. oFono will send
515 * the change via PropertyChanged singal.
520 modem->set_online = FALSE;
523 static int modem_set_online(struct modem_data *modem)
525 DBG("%s", modem->path);
527 modem->set_online = TRUE;
529 return set_property(modem, modem->path,
530 OFONO_MODEM_INTERFACE,
531 "Online", DBUS_TYPE_BOOLEAN,
533 modem_set_online_reply);
536 static void cm_set_powered_reply(struct modem_data *modem,
537 connman_bool_t success)
539 DBG("%s", modem->path);
541 if (success == TRUE) {
543 * Don't handle do anything on success here. oFono will send
544 * the change via PropertyChanged singal.
549 modem->set_cm_powered = FALSE;
552 static int cm_set_powered(struct modem_data *modem)
554 DBG("%s", modem->path);
556 modem->set_cm_powered = TRUE;
558 return set_property(modem, modem->path,
560 "Powered", DBUS_TYPE_BOOLEAN,
561 &modem->set_cm_powered,
562 cm_set_powered_reply);
565 static int modem_set_powered(struct modem_data *modem)
567 DBG("%s", modem->path);
569 modem->set_powered = TRUE;
571 return set_property(modem, modem->path,
572 OFONO_MODEM_INTERFACE,
573 "Powered", DBUS_TYPE_BOOLEAN,
578 static int modem_set_unpowered(struct modem_data *modem)
580 DBG("%s", modem->path);
582 modem->set_powered = FALSE;
584 return set_property(modem, modem->path,
585 OFONO_MODEM_INTERFACE,
586 "Powered", DBUS_TYPE_BOOLEAN,
591 static connman_bool_t has_interface(uint8_t interfaces,
594 if ((interfaces & api) == api)
600 static uint8_t extract_interfaces(DBusMessageIter *array)
602 DBusMessageIter entry;
603 uint8_t interfaces = 0;
605 dbus_message_iter_recurse(array, &entry);
607 while (dbus_message_iter_get_arg_type(&entry) == DBUS_TYPE_STRING) {
610 dbus_message_iter_get_basic(&entry, &name);
612 if (g_str_equal(name, OFONO_SIM_INTERFACE) == TRUE)
613 interfaces |= OFONO_API_SIM;
614 else if (g_str_equal(name, OFONO_NETREG_INTERFACE) == TRUE)
615 interfaces |= OFONO_API_NETREG;
616 else if (g_str_equal(name, OFONO_CM_INTERFACE) == TRUE)
617 interfaces |= OFONO_API_CM;
619 dbus_message_iter_next(&entry);
625 static char *extract_nameservers(DBusMessageIter *array)
627 DBusMessageIter entry;
628 char *nameservers = NULL;
631 dbus_message_iter_recurse(array, &entry);
633 while (dbus_message_iter_get_arg_type(&entry) == DBUS_TYPE_STRING) {
634 const char *nameserver;
636 dbus_message_iter_get_basic(&entry, &nameserver);
638 if (nameservers == NULL) {
639 nameservers = g_strdup(nameserver);
642 nameservers = g_strdup_printf("%s %s", tmp, nameserver);
646 dbus_message_iter_next(&entry);
652 static void extract_ipv4_settings(DBusMessageIter *array,
653 struct network_context *context)
655 DBusMessageIter dict;
656 char *address = NULL, *netmask = NULL, *gateway = NULL;
657 char *nameservers = NULL;
658 const char *interface = NULL;
661 if (dbus_message_iter_get_arg_type(array) != DBUS_TYPE_ARRAY)
664 dbus_message_iter_recurse(array, &dict);
666 while (dbus_message_iter_get_arg_type(&dict) == DBUS_TYPE_DICT_ENTRY) {
667 DBusMessageIter entry, value;
668 const char *key, *val;
670 dbus_message_iter_recurse(&dict, &entry);
671 dbus_message_iter_get_basic(&entry, &key);
673 dbus_message_iter_next(&entry);
674 dbus_message_iter_recurse(&entry, &value);
676 if (g_str_equal(key, "Interface") == TRUE) {
677 dbus_message_iter_get_basic(&value, &interface);
679 DBG("Interface %s", interface);
681 index = connman_inet_ifindex(interface);
683 DBG("index %d", index);
684 } else if (g_str_equal(key, "Method") == TRUE) {
685 dbus_message_iter_get_basic(&value, &val);
687 DBG("Method %s", val);
689 if (g_strcmp0(val, "static") == 0) {
690 context->ipv4_method = CONNMAN_IPCONFIG_METHOD_FIXED;
691 } else if (g_strcmp0(val, "dhcp") == 0) {
692 context->ipv4_method = CONNMAN_IPCONFIG_METHOD_DHCP;
695 } else if (g_str_equal(key, "Address") == TRUE) {
696 dbus_message_iter_get_basic(&value, &val);
698 address = g_strdup(val);
700 DBG("Address %s", address);
701 } else if (g_str_equal(key, "Netmask") == TRUE) {
702 dbus_message_iter_get_basic(&value, &val);
704 netmask = g_strdup(val);
706 DBG("Netmask %s", netmask);
707 } else if (g_str_equal(key, "DomainNameServers") == TRUE) {
708 nameservers = extract_nameservers(&value);
710 DBG("Nameservers %s", nameservers);
711 } else if (g_str_equal(key, "Gateway") == TRUE) {
712 dbus_message_iter_get_basic(&value, &val);
714 gateway = g_strdup(val);
716 DBG("Gateway %s", gateway);
719 dbus_message_iter_next(&dict);
725 if (context->ipv4_method != CONNMAN_IPCONFIG_METHOD_FIXED)
728 context->ipv4_address = connman_ipaddress_alloc(CONNMAN_IPCONFIG_TYPE_IPV4);
729 if (context->ipv4_address == NULL)
732 context->index = index;
733 connman_ipaddress_set_ipv4(context->ipv4_address, address,
736 context->ipv4_nameservers = nameservers;
739 if (context->ipv4_nameservers != nameservers)
747 static void extract_ipv6_settings(DBusMessageIter *array,
748 struct network_context *context)
750 DBusMessageIter dict;
751 char *address = NULL, *gateway = NULL;
752 unsigned char prefix_length;
753 char *nameservers = NULL;
754 const char *interface = NULL;
757 if (dbus_message_iter_get_arg_type(array) != DBUS_TYPE_ARRAY)
760 dbus_message_iter_recurse(array, &dict);
762 while (dbus_message_iter_get_arg_type(&dict) == DBUS_TYPE_DICT_ENTRY) {
763 DBusMessageIter entry, value;
764 const char *key, *val;
766 dbus_message_iter_recurse(&dict, &entry);
767 dbus_message_iter_get_basic(&entry, &key);
769 dbus_message_iter_next(&entry);
770 dbus_message_iter_recurse(&entry, &value);
772 if (g_str_equal(key, "Interface") == TRUE) {
773 dbus_message_iter_get_basic(&value, &interface);
775 DBG("Interface %s", interface);
777 index = connman_inet_ifindex(interface);
779 DBG("index %d", index);
780 } else if (g_str_equal(key, "Address") == TRUE) {
781 dbus_message_iter_get_basic(&value, &val);
783 address = g_strdup(val);
785 DBG("Address %s", address);
786 } else if (g_str_equal(key, "PrefixLength") == TRUE) {
787 dbus_message_iter_get_basic(&value, &prefix_length);
789 DBG("prefix length %d", prefix_length);
790 } else if (g_str_equal(key, "DomainNameServers") == TRUE) {
791 nameservers = extract_nameservers(&value);
793 DBG("Nameservers %s", nameservers);
794 } else if (g_str_equal(key, "Gateway") == TRUE) {
795 dbus_message_iter_get_basic(&value, &val);
797 gateway = g_strdup(val);
799 DBG("Gateway %s", gateway);
802 dbus_message_iter_next(&dict);
808 context->ipv6_method = CONNMAN_IPCONFIG_METHOD_FIXED;
810 context->ipv6_address =
811 connman_ipaddress_alloc(CONNMAN_IPCONFIG_TYPE_IPV6);
812 if (context->ipv6_address == NULL)
815 context->index = index;
816 connman_ipaddress_set_ipv6(context->ipv6_address, address,
817 prefix_length, gateway);
819 context->ipv6_nameservers = nameservers;
822 if (context->ipv6_nameservers != nameservers)
829 static connman_bool_t ready_to_create_device(struct modem_data *modem)
832 * There are three different modem types which behave slightly
834 * - GSM modems will expose the SIM interface then the
836 * - DUN modems will expose first a unique serial number (BDADDR)
837 * and then the CM interface.
838 * - CDMA modems will expose CM first and sometime later
839 * a unique serial number.
841 * This functions tests if we have the necessary information gathered
842 * before we are able to create a device.
845 if (modem->device != NULL)
848 if (modem->imsi != NULL || modem->serial != NULL)
854 static void create_device(struct modem_data *modem)
856 struct connman_device *device;
857 char *uninitialized_var(ident);
859 DBG("%s", modem->path);
861 if (modem->imsi != NULL)
863 else if (modem->serial != NULL)
864 ident = modem->serial;
866 if (connman_dbus_validate_ident(ident) == FALSE)
867 ident = connman_dbus_encode_string(ident);
869 ident = g_strdup(ident);
871 device = connman_device_create(ident, CONNMAN_DEVICE_TYPE_CELLULAR);
875 DBG("device %p", device);
877 connman_device_set_ident(device, ident);
879 connman_device_set_string(device, "Path", modem->path);
881 connman_device_set_data(device, modem);
883 if (connman_device_register(device) < 0) {
884 connman_error("Failed to register cellular device");
885 connman_device_unref(device);
889 modem->device = device;
895 static void destroy_device(struct modem_data *modem)
897 DBG("%s", modem->path);
899 connman_device_set_powered(modem->device, FALSE);
901 if (modem->network != NULL) {
902 connman_device_remove_network(modem->device, modem->network);
903 connman_network_unref(modem->network);
904 modem->network = NULL;
907 connman_device_unregister(modem->device);
908 connman_device_unref(modem->device);
910 modem->device = NULL;
913 static void add_network(struct modem_data *modem)
917 DBG("%s", modem->path);
919 if (modem->network != NULL)
922 modem->network = connman_network_create(modem->context->path,
923 CONNMAN_NETWORK_TYPE_CELLULAR);
924 if (modem->network == NULL)
927 DBG("network %p", modem->network);
929 connman_network_set_data(modem->network, modem);
931 connman_network_set_string(modem->network, "Path",
932 modem->context->path);
934 connman_network_set_index(modem->network, modem->context->index);
936 if (modem->name != NULL)
937 connman_network_set_name(modem->network, modem->name);
939 connman_network_set_name(modem->network, "");
941 connman_network_set_strength(modem->network, modem->strength);
943 group = get_ident(modem->context->path);
944 connman_network_set_group(modem->network, group);
946 connman_network_set_available(modem->network, TRUE);
948 if (connman_device_add_network(modem->device, modem->network) < 0) {
949 connman_network_unref(modem->network);
950 modem->network = NULL;
955 static int add_cm_context(struct modem_data *modem, const char *context_path,
956 DBusMessageIter *dict)
958 const char *context_type;
959 struct network_context *context = NULL;
960 connman_bool_t active = FALSE;
962 DBG("%s context path %s", modem->path, context_path);
964 if (modem->context != NULL) {
966 * We have already assigned a context to this modem
967 * and we do only support one Internet context.
972 context = network_context_alloc(context_path);
976 while (dbus_message_iter_get_arg_type(dict) == DBUS_TYPE_DICT_ENTRY) {
977 DBusMessageIter entry, value;
980 dbus_message_iter_recurse(dict, &entry);
981 dbus_message_iter_get_basic(&entry, &key);
983 dbus_message_iter_next(&entry);
984 dbus_message_iter_recurse(&entry, &value);
986 if (g_str_equal(key, "Type") == TRUE) {
987 dbus_message_iter_get_basic(&value, &context_type);
989 DBG("%s context %s type %s", modem->path,
990 context_path, context_type);
991 } else if (g_str_equal(key, "Settings") == TRUE) {
992 DBG("%s Settings", modem->path);
994 extract_ipv4_settings(&value, context);
995 } else if (g_str_equal(key, "IPv6.Settings") == TRUE) {
996 DBG("%s IPv6.Settings", modem->path);
998 extract_ipv6_settings(&value, context);
999 } else if (g_str_equal(key, "Active") == TRUE) {
1000 dbus_message_iter_get_basic(&value, &active);
1002 DBG("%s Active %d", modem->path, active);
1005 dbus_message_iter_next(dict);
1008 if (g_strcmp0(context_type, "internet") != 0) {
1009 network_context_free(context);
1013 modem->context = context;
1014 modem->active = active;
1016 g_hash_table_replace(context_hash, g_strdup(context_path), modem);
1021 static void remove_cm_context(struct modem_data *modem,
1022 const char *context_path)
1024 if (modem->context == NULL)
1027 g_hash_table_remove(context_hash, context_path);
1029 network_context_free(modem->context);
1030 modem->context = NULL;
1033 static gboolean context_changed(DBusConnection *connection,
1034 DBusMessage *message,
1037 const char *context_path = dbus_message_get_path(message);
1038 struct modem_data *modem = NULL;
1039 DBusMessageIter iter, value;
1042 DBG("context_path %s", context_path);
1044 modem = g_hash_table_lookup(context_hash, context_path);
1048 if (dbus_message_iter_init(message, &iter) == FALSE)
1051 dbus_message_iter_get_basic(&iter, &key);
1053 dbus_message_iter_next(&iter);
1054 dbus_message_iter_recurse(&iter, &value);
1057 * oFono guarantees the ordering of Settings and
1058 * Active. Settings will always be send before Active = True.
1059 * That means we don't have to order here.
1061 if (g_str_equal(key, "Settings") == TRUE) {
1062 DBG("%s Settings", modem->path);
1064 extract_ipv4_settings(&value, modem->context);
1065 } else if (g_str_equal(key, "IPv6.Settings") == TRUE) {
1066 DBG("%s IPv6.Settings", modem->path);
1068 extract_ipv6_settings(&value, modem->context);
1069 } else if (g_str_equal(key, "Active") == TRUE) {
1070 dbus_message_iter_get_basic(&value, &modem->active);
1072 DBG("%s Active %d", modem->path, modem->active);
1074 if (modem->active == TRUE)
1075 set_connected(modem);
1077 set_disconnected(modem);
1083 static void cm_get_contexts_reply(DBusPendingCall *call, void *user_data)
1085 struct modem_data *modem = user_data;
1086 DBusMessageIter array, dict, entry, value;
1090 DBG("%s", modem->path);
1092 modem->call_get_contexts = NULL;
1094 reply = dbus_pending_call_steal_reply(call);
1096 dbus_error_init(&error);
1098 if (dbus_set_error_from_message(&error, reply) == TRUE) {
1099 connman_error("%s", error.message);
1100 dbus_error_free(&error);
1104 if (dbus_message_iter_init(reply, &array) == FALSE)
1107 if (dbus_message_iter_get_arg_type(&array) != DBUS_TYPE_ARRAY)
1110 dbus_message_iter_recurse(&array, &dict);
1112 while (dbus_message_iter_get_arg_type(&dict) == DBUS_TYPE_STRUCT) {
1113 const char *context_path;
1115 dbus_message_iter_recurse(&dict, &entry);
1116 dbus_message_iter_get_basic(&entry, &context_path);
1118 dbus_message_iter_next(&entry);
1119 dbus_message_iter_recurse(&entry, &value);
1121 if (add_cm_context(modem, context_path, &value) == 0)
1124 dbus_message_iter_next(&dict);
1128 dbus_message_unref(reply);
1130 dbus_pending_call_unref(call);
1133 static int cm_get_contexts(struct modem_data *modem)
1135 DBusMessage *message;
1137 DBG("%s", modem->path);
1139 if (modem->call_get_contexts != NULL)
1142 message = dbus_message_new_method_call(OFONO_SERVICE, modem->path,
1143 OFONO_CM_INTERFACE, GET_CONTEXTS);
1144 if (message == NULL)
1147 if (dbus_connection_send_with_reply(connection, message,
1148 &modem->call_get_contexts, TIMEOUT) == FALSE) {
1149 connman_error("Failed to call GetContexts()");
1150 dbus_message_unref(message);
1154 if (modem->call_get_contexts == NULL) {
1155 connman_error("D-Bus connection not available");
1156 dbus_message_unref(message);
1160 dbus_pending_call_set_notify(modem->call_get_contexts,
1161 cm_get_contexts_reply,
1164 dbus_message_unref(message);
1166 return -EINPROGRESS;
1169 static gboolean cm_context_added(DBusConnection *connection,
1170 DBusMessage *message,
1173 const char *path = dbus_message_get_path(message);
1175 struct modem_data *modem;
1176 DBusMessageIter iter, properties;
1180 modem = g_hash_table_lookup(modem_hash, context_path);
1184 if (dbus_message_iter_init(message, &iter) == FALSE)
1187 dbus_message_iter_get_basic(&iter, &context_path);
1189 dbus_message_iter_next(&iter);
1190 dbus_message_iter_recurse(&iter, &properties);
1192 if (add_cm_context(modem, context_path, &properties) != 0)
1198 static gboolean cm_context_removed(DBusConnection *connection,
1199 DBusMessage *message,
1202 const char *path = dbus_message_get_path(message);
1203 const char *context_path;
1204 struct modem_data *modem;
1205 DBusMessageIter iter;
1207 DBG("context path %s", path);
1209 if (dbus_message_iter_init(message, &iter) == FALSE)
1212 dbus_message_iter_get_basic(&iter, &context_path);
1214 modem = g_hash_table_lookup(context_hash, context_path);
1218 remove_cm_context(modem, context_path);
1223 static gboolean netreg_changed(DBusConnection *connection, DBusMessage *message,
1226 const char *path = dbus_message_get_path(message);
1227 struct modem_data *modem;
1228 DBusMessageIter iter, value;
1231 modem = g_hash_table_lookup(modem_hash, path);
1235 if (modem->ignore == TRUE)
1238 if (dbus_message_iter_init(message, &iter) == FALSE)
1241 dbus_message_iter_get_basic(&iter, &key);
1243 dbus_message_iter_next(&iter);
1244 dbus_message_iter_recurse(&iter, &value);
1246 if (g_str_equal(key, "Name") == TRUE) {
1249 dbus_message_iter_get_basic(&value, &name);
1251 DBG("%s Name %s", modem->path, name);
1253 g_free(modem->name);
1254 modem->name = g_strdup(name);
1256 if (modem->network == NULL)
1259 connman_network_set_name(modem->network, modem->name);
1260 connman_network_update(modem->network);
1261 } else if (g_str_equal(key, "Strength") == TRUE) {
1262 dbus_message_iter_get_basic(&value, &modem->strength);
1264 DBG("%s Strength %d", modem->path, modem->strength);
1266 if (modem->network == NULL)
1269 connman_network_set_strength(modem->network, modem->strength);
1270 connman_network_update(modem->network);
1276 static void netreg_properties_reply(struct modem_data *modem,
1277 DBusMessageIter *dict)
1279 DBG("%s", modem->path);
1281 while (dbus_message_iter_get_arg_type(dict) == DBUS_TYPE_DICT_ENTRY) {
1282 DBusMessageIter entry, value;
1285 dbus_message_iter_recurse(dict, &entry);
1286 dbus_message_iter_get_basic(&entry, &key);
1288 dbus_message_iter_next(&entry);
1289 dbus_message_iter_recurse(&entry, &value);
1291 if (g_str_equal(key, "Name") == TRUE) {
1294 dbus_message_iter_get_basic(&value, &name);
1296 DBG("%s Name %s", modem->path, name);
1298 g_free(modem->name);
1299 modem->name = g_strdup(name);
1301 if (modem->network != NULL) {
1302 connman_network_set_name(modem->network,
1304 connman_network_update(modem->network);
1306 } else if (g_str_equal(key, "Strength") == TRUE) {
1307 dbus_message_iter_get_basic(&value, &modem->strength);
1309 DBG("%s Strength %d", modem->path,
1312 if (modem->network != NULL) {
1313 connman_network_set_strength(modem->network,
1315 connman_network_update(modem->network);
1319 dbus_message_iter_next(dict);
1322 if (modem->context == NULL) {
1324 * netgreg_get_properties() was issued after we got
1325 * cm_get_contexts_reply() where we create the
1326 * context. Though before we got the
1327 * netreg_properties_reply the context was removed
1328 * again. Therefore we have to skip the network
1336 if (modem->active == TRUE)
1337 set_connected(modem);
1340 static int netreg_get_properties(struct modem_data *modem)
1342 return get_properties(modem->path, OFONO_NETREG_INTERFACE,
1343 netreg_properties_reply, modem);
1346 static gboolean cm_changed(DBusConnection *connection, DBusMessage *message,
1349 const char *path = dbus_message_get_path(message);
1350 struct modem_data *modem;
1351 DBusMessageIter iter, value;
1354 modem = g_hash_table_lookup(modem_hash, path);
1358 if (modem->ignore == TRUE)
1361 if (dbus_message_iter_init(message, &iter) == FALSE)
1364 dbus_message_iter_get_basic(&iter, &key);
1366 dbus_message_iter_next(&iter);
1367 dbus_message_iter_recurse(&iter, &value);
1369 if (g_str_equal(key, "Attached") == TRUE) {
1370 dbus_message_iter_get_basic(&value, &modem->attached);
1372 DBG("%s Attached %d", modem->path, modem->attached);
1374 if (modem->attached == TRUE) {
1375 if (has_interface(modem->interfaces,
1376 OFONO_API_NETREG) == TRUE) {
1377 netreg_get_properties(modem);
1380 } else if (g_str_equal(key, "Powered") == TRUE) {
1381 dbus_message_iter_get_basic(&value, &modem->cm_powered);
1383 DBG("%s ConnnectionManager Powered %d", modem->path,
1386 if (modem->cm_powered == FALSE)
1387 cm_set_powered(modem);
1393 static void cm_properties_reply(struct modem_data *modem, DBusMessageIter *dict)
1395 DBG("%s", modem->path);
1397 while (dbus_message_iter_get_arg_type(dict) == DBUS_TYPE_DICT_ENTRY) {
1398 DBusMessageIter entry, value;
1401 dbus_message_iter_recurse(dict, &entry);
1402 dbus_message_iter_get_basic(&entry, &key);
1404 dbus_message_iter_next(&entry);
1405 dbus_message_iter_recurse(&entry, &value);
1407 if (g_str_equal(key, "Attached") == TRUE) {
1408 dbus_message_iter_get_basic(&value, &modem->attached);
1410 DBG("%s Attached %d", modem->path,
1413 if (modem->attached == TRUE) {
1414 if (has_interface(modem->interfaces,
1415 OFONO_API_NETREG) == TRUE) {
1416 netreg_get_properties(modem);
1419 } else if (g_str_equal(key, "Powered") == TRUE) {
1420 dbus_message_iter_get_basic(&value, &modem->cm_powered);
1422 DBG("%s ConnnectionManager Powered %d", modem->path,
1425 if (modem->cm_powered == FALSE)
1426 cm_set_powered(modem);
1429 dbus_message_iter_next(dict);
1433 static int cm_get_properties(struct modem_data *modem)
1435 return get_properties(modem->path, OFONO_CM_INTERFACE,
1436 cm_properties_reply, modem);
1439 static void update_sim_imsi(struct modem_data *modem,
1442 DBG("%s imsi %s", modem->path, imsi);
1444 if (g_strcmp0(modem->imsi, imsi) == 0)
1447 g_free(modem->imsi);
1448 modem->imsi = g_strdup(imsi);
1451 static gboolean sim_changed(DBusConnection *connection, DBusMessage *message,
1454 const char *path = dbus_message_get_path(message);
1455 struct modem_data *modem;
1456 DBusMessageIter iter, value;
1459 modem = g_hash_table_lookup(modem_hash, path);
1463 if (modem->ignore == TRUE)
1466 if (dbus_message_iter_init(message, &iter) == FALSE)
1469 dbus_message_iter_get_basic(&iter, &key);
1471 dbus_message_iter_next(&iter);
1472 dbus_message_iter_recurse(&iter, &value);
1474 if (g_str_equal(key, "SubscriberIdentity") == TRUE) {
1477 dbus_message_iter_get_basic(&value, &imsi);
1479 update_sim_imsi(modem, imsi);
1481 if (modem->online == FALSE) {
1482 modem_set_online(modem);
1483 } else if (has_interface(modem->interfaces,
1484 OFONO_API_CM) == TRUE) {
1485 if (ready_to_create_device(modem) == TRUE)
1486 create_device(modem);
1493 static void sim_properties_reply(struct modem_data *modem,
1494 DBusMessageIter *dict)
1496 DBG("%s", modem->path);
1498 while (dbus_message_iter_get_arg_type(dict) == DBUS_TYPE_DICT_ENTRY) {
1499 DBusMessageIter entry, value;
1502 dbus_message_iter_recurse(dict, &entry);
1503 dbus_message_iter_get_basic(&entry, &key);
1505 dbus_message_iter_next(&entry);
1506 dbus_message_iter_recurse(&entry, &value);
1508 if (g_str_equal(key, "SubscriberIdentity") == TRUE) {
1511 dbus_message_iter_get_basic(&value, &imsi);
1513 update_sim_imsi(modem, imsi);
1515 if (modem->online == FALSE) {
1516 modem_set_online(modem);
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);
1531 dbus_message_iter_next(dict);
1535 static int sim_get_properties(struct modem_data *modem)
1537 return get_properties(modem->path, OFONO_SIM_INTERFACE,
1538 sim_properties_reply, modem);
1541 static gboolean modem_changed(DBusConnection *connection, DBusMessage *message,
1544 const char *path = dbus_message_get_path(message);
1545 struct modem_data *modem;
1546 DBusMessageIter iter, value;
1549 modem = g_hash_table_lookup(modem_hash, path);
1553 if (modem->ignore == TRUE)
1556 if (dbus_message_iter_init(message, &iter) == FALSE)
1559 dbus_message_iter_get_basic(&iter, &key);
1561 dbus_message_iter_next(&iter);
1562 dbus_message_iter_recurse(&iter, &value);
1564 if (g_str_equal(key, "Powered") == TRUE) {
1565 dbus_message_iter_get_basic(&value, &modem->powered);
1567 DBG("%s Powered %d", modem->path, modem->powered);
1569 if (modem->powered == FALSE)
1570 modem_set_powered(modem);
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);
1576 if (modem->online == FALSE)
1579 if (has_interface(modem->interfaces, OFONO_API_CM) == FALSE)
1581 if (ready_to_create_device(modem) == TRUE)
1582 create_device(modem);
1583 if (modem->device != NULL) {
1584 cm_get_properties(modem);
1585 cm_get_contexts(modem);
1587 } else if (g_str_equal(key, "Interfaces") == TRUE) {
1588 modem->interfaces = extract_interfaces(&value);
1590 DBG("%s Interfaces 0x%02x", modem->path,
1593 if (has_interface(modem->interfaces, OFONO_API_SIM) == TRUE) {
1594 if (modem->imsi == NULL &&
1595 modem->set_powered == FALSE) {
1597 * Only use do GetProperties() when
1598 * device has not been powered up.
1600 sim_get_properties(modem);
1605 if (has_interface(modem->interfaces, OFONO_API_CM) == TRUE) {
1606 if (ready_to_create_device(modem) == TRUE)
1607 create_device(modem);
1608 if (modem->device != NULL) {
1609 cm_get_properties(modem);
1610 cm_get_contexts(modem);
1614 if (modem->context != NULL) {
1615 remove_cm_context(modem,
1616 modem->context->path);
1619 if (modem->device != NULL)
1620 destroy_device(modem);
1625 if (has_interface(modem->interfaces, OFONO_API_NETREG) == TRUE) {
1626 if (modem->attached == TRUE)
1627 netreg_get_properties(modem);
1629 } else if (g_str_equal(key, "Serial") == TRUE) {
1632 dbus_message_iter_get_basic(&value, &serial);
1634 g_free(modem->serial);
1635 modem->serial = g_strdup(serial);
1637 DBG("%s Serial %s", modem->path, modem->serial);
1639 if (has_interface(modem->interfaces, OFONO_API_CM) == TRUE) {
1640 if (ready_to_create_device(modem) == TRUE)
1641 create_device(modem);
1642 if (modem->device != NULL) {
1643 cm_get_properties(modem);
1644 cm_get_contexts(modem);
1652 static void add_modem(const char *path, DBusMessageIter *prop)
1654 struct modem_data *modem;
1658 modem = g_hash_table_lookup(modem_hash, path);
1659 if (modem != NULL) {
1661 * When oFono powers up we ask for the modems and oFono is
1662 * reporting with modem_added signal the modems. Only
1668 modem = g_try_new0(struct modem_data, 1);
1672 modem->path = g_strdup(path);
1674 g_hash_table_insert(modem_hash, g_strdup(path), modem);
1676 while (dbus_message_iter_get_arg_type(prop) == DBUS_TYPE_DICT_ENTRY) {
1677 DBusMessageIter entry, value;
1680 dbus_message_iter_recurse(prop, &entry);
1681 dbus_message_iter_get_basic(&entry, &key);
1683 dbus_message_iter_next(&entry);
1684 dbus_message_iter_recurse(&entry, &value);
1686 if (g_str_equal(key, "Powered") == TRUE) {
1687 dbus_message_iter_get_basic(&value, &modem->powered);
1689 DBG("%s Powered %d", modem->path, modem->powered);
1690 } else if (g_str_equal(key, "Online") == TRUE) {
1691 dbus_message_iter_get_basic(&value, &modem->online);
1693 DBG("%s Online %d", modem->path, modem->online);
1694 } else if (g_str_equal(key, "Interfaces") == TRUE) {
1695 modem->interfaces = extract_interfaces(&value);
1697 DBG("%s Interfaces 0x%02x", modem->path,
1699 } else if (g_str_equal(key, "Serial") == TRUE) {
1702 dbus_message_iter_get_basic(&value, &serial);
1703 modem->serial = g_strdup(serial);
1705 DBG("%s Serial %s", modem->path, modem->serial);
1706 } else if (g_str_equal(key, "Type") == TRUE) {
1709 dbus_message_iter_get_basic(&value, &type);
1711 DBG("%s Type %s", modem->path, type);
1712 if (g_strcmp0(type, "hardware") != 0) {
1713 DBG("%s Ignore this modem", modem->path);
1714 modem->ignore = TRUE;
1718 dbus_message_iter_next(prop);
1721 if (modem->ignore == TRUE)
1724 if (modem->powered == FALSE) {
1725 modem_set_powered(modem);
1726 } else if (has_interface(modem->interfaces, OFONO_API_SIM) == TRUE) {
1727 sim_get_properties(modem);
1728 } else if (has_interface(modem->interfaces, OFONO_API_CM) == TRUE) {
1729 if (ready_to_create_device(modem) == TRUE)
1730 create_device(modem);
1731 if (modem->device != NULL) {
1732 cm_get_properties(modem);
1733 cm_get_contexts(modem);
1738 static void modem_power_down(gpointer key, gpointer value, gpointer user_data)
1740 struct modem_data *modem = value;
1742 DBG("%s", modem->path);
1744 if (modem->ignore == TRUE)
1747 modem_set_unpowered(modem);
1750 static void remove_modem(gpointer data)
1752 struct modem_data *modem = data;
1754 DBG("%s", modem->path);
1756 if (modem->call_set_property != NULL)
1757 dbus_pending_call_cancel(modem->call_set_property);
1759 if (modem->call_get_properties != NULL)
1760 dbus_pending_call_cancel(modem->call_get_properties);
1762 if (modem->call_get_contexts != NULL)
1763 dbus_pending_call_cancel(modem->call_get_contexts);
1765 if (modem->device != NULL)
1766 destroy_device(modem);
1768 if (modem->context != NULL)
1769 remove_cm_context(modem, modem->context->path);
1771 g_free(modem->serial);
1772 g_free(modem->name);
1773 g_free(modem->imsi);
1774 g_free(modem->path);
1779 static gboolean modem_added(DBusConnection *connection,
1780 DBusMessage *message, void *user_data)
1782 DBusMessageIter iter, properties;
1787 if (dbus_message_iter_init(message, &iter) == FALSE)
1790 dbus_message_iter_get_basic(&iter, &path);
1792 dbus_message_iter_next(&iter);
1793 dbus_message_iter_recurse(&iter, &properties);
1795 add_modem(path, &properties);
1800 static gboolean modem_removed(DBusConnection *connection,
1801 DBusMessage *message, void *user_data)
1803 DBusMessageIter iter;
1808 if (dbus_message_iter_init(message, &iter) == FALSE)
1811 dbus_message_iter_get_basic(&iter, &path);
1813 g_hash_table_remove(modem_hash, path);
1818 static void manager_get_modems_reply(DBusPendingCall *call, void *user_data)
1822 DBusMessageIter array, dict;
1826 reply = dbus_pending_call_steal_reply(call);
1828 dbus_error_init(&error);
1830 if (dbus_set_error_from_message(&error, reply) == TRUE) {
1831 connman_error("%s", error.message);
1832 dbus_error_free(&error);
1836 if (dbus_message_iter_init(reply, &array) == FALSE)
1839 dbus_message_iter_recurse(&array, &dict);
1841 while (dbus_message_iter_get_arg_type(&dict) == DBUS_TYPE_STRUCT) {
1842 DBusMessageIter value, properties;
1845 dbus_message_iter_recurse(&dict, &value);
1846 dbus_message_iter_get_basic(&value, &path);
1848 dbus_message_iter_next(&value);
1849 dbus_message_iter_recurse(&value, &properties);
1851 add_modem(path, &properties);
1853 dbus_message_iter_next(&dict);
1857 dbus_message_unref(reply);
1859 dbus_pending_call_unref(call);
1862 static int manager_get_modems(void)
1864 DBusMessage *message;
1865 DBusPendingCall *call;
1869 message = dbus_message_new_method_call(OFONO_SERVICE, "/",
1870 OFONO_MANAGER_INTERFACE, GET_MODEMS);
1871 if (message == NULL)
1874 if (dbus_connection_send_with_reply(connection, message,
1875 &call, TIMEOUT) == FALSE) {
1876 connman_error("Failed to call GetModems()");
1877 dbus_message_unref(message);
1882 connman_error("D-Bus connection not available");
1883 dbus_message_unref(message);
1887 dbus_pending_call_set_notify(call, manager_get_modems_reply,
1890 dbus_message_unref(message);
1892 return -EINPROGRESS;
1895 static void ofono_connect(DBusConnection *conn, void *user_data)
1899 modem_hash = g_hash_table_new_full(g_str_hash, g_str_equal,
1900 g_free, remove_modem);
1901 if (modem_hash == NULL)
1904 context_hash = g_hash_table_new_full(g_str_hash, g_str_equal,
1906 if (context_hash == NULL) {
1907 g_hash_table_destroy(modem_hash);
1911 manager_get_modems();
1914 static void ofono_disconnect(DBusConnection *conn, void *user_data)
1918 if (modem_hash == NULL || context_hash == NULL)
1921 g_hash_table_destroy(modem_hash);
1924 g_hash_table_destroy(context_hash);
1925 context_hash = NULL;
1928 static int network_probe(struct connman_network *network)
1930 struct modem_data *modem = connman_network_get_data(network);
1932 DBG("%s network %p", modem->path, network);
1937 static void network_remove(struct connman_network *network)
1939 struct modem_data *modem = connman_network_get_data(network);
1941 DBG("%s network %p", modem->path, network);
1944 static int network_connect(struct connman_network *network)
1946 struct modem_data *modem = connman_network_get_data(network);
1948 DBG("%s network %p", modem->path, network);
1950 return context_set_active(modem);
1953 static int network_disconnect(struct connman_network *network)
1955 struct modem_data *modem = connman_network_get_data(network);
1957 DBG("%s network %p", modem->path, network);
1959 return context_set_inactive(modem);
1962 static struct connman_network_driver network_driver = {
1964 .type = CONNMAN_NETWORK_TYPE_CELLULAR,
1965 .probe = network_probe,
1966 .remove = network_remove,
1967 .connect = network_connect,
1968 .disconnect = network_disconnect,
1971 static int modem_probe(struct connman_device *device)
1973 struct modem_data *modem = connman_device_get_data(device);
1975 DBG("%s device %p", modem->path, device);
1980 static void modem_remove(struct connman_device *device)
1982 struct modem_data *modem = connman_device_get_data(device);
1984 DBG("%s device %p", modem->path, device);
1987 static int modem_enable(struct connman_device *device)
1989 struct modem_data *modem = connman_device_get_data(device);
1991 DBG("%s device %p", modem->path, device);
1996 static int modem_disable(struct connman_device *device)
1998 struct modem_data *modem = connman_device_get_data(device);
2000 DBG("%s device %p", modem->path, device);
2005 static struct connman_device_driver modem_driver = {
2007 .type = CONNMAN_DEVICE_TYPE_CELLULAR,
2008 .probe = modem_probe,
2009 .remove = modem_remove,
2010 .enable = modem_enable,
2011 .disable = modem_disable,
2015 static guint modem_added_watch;
2016 static guint modem_removed_watch;
2017 static guint modem_watch;
2018 static guint cm_watch;
2019 static guint sim_watch;
2020 static guint context_added_watch;
2021 static guint context_removed_watch;
2022 static guint netreg_watch;
2023 static guint context_watch;
2025 static int ofono_init(void)
2031 connection = connman_dbus_get_connection();
2032 if (connection == NULL)
2035 watch = g_dbus_add_service_watch(connection,
2036 OFONO_SERVICE, ofono_connect,
2037 ofono_disconnect, NULL, NULL);
2039 modem_added_watch = g_dbus_add_signal_watch(connection, NULL, NULL,
2040 OFONO_MANAGER_INTERFACE,
2045 modem_removed_watch = g_dbus_add_signal_watch(connection, NULL, NULL,
2046 OFONO_MANAGER_INTERFACE,
2051 modem_watch = g_dbus_add_signal_watch(connection, NULL, NULL,
2052 OFONO_MODEM_INTERFACE,
2057 cm_watch = g_dbus_add_signal_watch(connection, NULL, NULL,
2063 sim_watch = g_dbus_add_signal_watch(connection, NULL, NULL,
2064 OFONO_SIM_INTERFACE,
2069 context_added_watch = g_dbus_add_signal_watch(connection, NULL, NULL,
2075 context_removed_watch = g_dbus_add_signal_watch(connection, NULL, NULL,
2081 context_watch = g_dbus_add_signal_watch(connection, NULL, NULL,
2082 OFONO_CONTEXT_INTERFACE,
2087 netreg_watch = g_dbus_add_signal_watch(connection, NULL, NULL,
2088 OFONO_NETREG_INTERFACE,
2094 if (watch == 0 || modem_added_watch == 0 || modem_removed_watch == 0 ||
2095 modem_watch == 0 || cm_watch == 0 || sim_watch == 0 ||
2096 context_added_watch == 0 ||
2097 context_removed_watch == 0 ||
2098 context_watch == 0 || netreg_watch == 0) {
2103 err = connman_network_driver_register(&network_driver);
2107 err = connman_device_driver_register(&modem_driver);
2109 connman_network_driver_unregister(&network_driver);
2116 g_dbus_remove_watch(connection, netreg_watch);
2117 g_dbus_remove_watch(connection, context_watch);
2118 g_dbus_remove_watch(connection, context_removed_watch);
2119 g_dbus_remove_watch(connection, context_added_watch);
2120 g_dbus_remove_watch(connection, sim_watch);
2121 g_dbus_remove_watch(connection, cm_watch);
2122 g_dbus_remove_watch(connection, modem_watch);
2123 g_dbus_remove_watch(connection, modem_removed_watch);
2124 g_dbus_remove_watch(connection, modem_added_watch);
2125 g_dbus_remove_watch(connection, watch);
2126 dbus_connection_unref(connection);
2131 static void ofono_exit(void)
2135 if (modem_hash != NULL) {
2137 * We should propably wait for the SetProperty() reply
2138 * message, because ...
2140 g_hash_table_foreach(modem_hash, modem_power_down, NULL);
2143 * ... here we will cancel the call.
2145 g_hash_table_destroy(modem_hash);
2149 if (context_hash != NULL) {
2150 g_hash_table_destroy(context_hash);
2151 context_hash = NULL;
2154 connman_device_driver_unregister(&modem_driver);
2155 connman_network_driver_unregister(&network_driver);
2157 g_dbus_remove_watch(connection, netreg_watch);
2158 g_dbus_remove_watch(connection, context_watch);
2159 g_dbus_remove_watch(connection, context_removed_watch);
2160 g_dbus_remove_watch(connection, context_added_watch);
2161 g_dbus_remove_watch(connection, sim_watch);
2162 g_dbus_remove_watch(connection, cm_watch);
2163 g_dbus_remove_watch(connection, modem_watch);
2164 g_dbus_remove_watch(connection, modem_added_watch);
2165 g_dbus_remove_watch(connection, modem_removed_watch);
2166 g_dbus_remove_watch(connection, watch);
2168 dbus_connection_unref(connection);
2171 CONNMAN_PLUGIN_DEFINE(ofono, "oFono telephony plugin", VERSION,
2172 CONNMAN_PLUGIN_PRIORITY_DEFAULT, ofono_init, ofono_exit)