5 * Copyright (C) 2007-2010 Intel Corporation. All rights reserved.
6 * Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
7 * Copyright (C) 2011 BWM Car IT GmbH. All rights reserved.
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License version 2 as
11 * published by the Free Software Foundation.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
35 #define CONNMAN_API_SUBJECT_TO_CHANGE
36 #include <connman/plugin.h>
37 #include <connman/device.h>
38 #include <connman/network.h>
39 #include <connman/inet.h>
40 #include <connman/dbus.h>
41 #include <connman/log.h>
43 #define uninitialized_var(x) x = x
45 #define OFONO_SERVICE "org.ofono"
47 #define OFONO_MANAGER_INTERFACE OFONO_SERVICE ".Manager"
48 #define OFONO_MODEM_INTERFACE OFONO_SERVICE ".Modem"
49 #define OFONO_SIM_INTERFACE OFONO_SERVICE ".SimManager"
50 #define OFONO_NETREG_INTERFACE OFONO_SERVICE ".NetworkRegistration"
51 #define OFONO_CM_INTERFACE OFONO_SERVICE ".ConnectionManager"
52 #define OFONO_CONTEXT_INTERFACE OFONO_SERVICE ".ConnectionContext"
54 #define MODEM_ADDED "ModemAdded"
55 #define MODEM_REMOVED "ModemRemoved"
56 #define PROPERTY_CHANGED "PropertyChanged"
57 #define CONTEXT_ADDED "ContextAdded"
58 #define CONTEXT_REMOVED "ContextRemoved"
60 #define GET_PROPERTIES "GetProperties"
61 #define SET_PROPERTY "SetProperty"
62 #define GET_MODEMS "GetModems"
63 #define GET_CONTEXTS "GetContexts"
69 OFONO_API_NETREG = 0x2,
74 * The way this plugin works is following:
76 * powered -> SubscriberIdentity or Online = True -> gprs, context ->
77 * attached -> netreg -> ready
79 * Enabling and disabling modems are steered through the rfkill
80 * interface. That means when ConnMan toggles the rfkill bit oFono
81 * will add or remove the modems.
83 * ConnMan will always power up (set Powered and Online) the
84 * modems. No need to power them down because this will be done
85 * through the rfkill inteface.
88 static DBusConnection *connection;
90 static GHashTable *modem_hash;
91 static GHashTable *context_hash;
93 struct network_context {
97 enum connman_ipconfig_method ipv4_method;
98 struct connman_ipaddress *ipv4_address;
99 char *ipv4_nameservers;
101 enum connman_ipconfig_method ipv6_method;
102 struct connman_ipaddress *ipv6_address;
103 char *ipv6_nameservers;
109 struct connman_device *device;
110 struct connman_network *network;
112 struct network_context *context;
114 /* Modem Interface */
116 connman_bool_t powered;
117 connman_bool_t online;
119 connman_bool_t ignore;
121 connman_bool_t set_powered;
122 connman_bool_t set_online;
124 /* ConnectionManager Interface */
125 connman_bool_t attached;
126 connman_bool_t cm_powered;
128 connman_bool_t set_cm_powered;
130 /* ConnectionContext Interface */
131 connman_bool_t active;
132 connman_bool_t set_active;
134 /* SimManager Interface */
137 /* Netreg Interface */
142 DBusPendingCall *call_set_property;
143 DBusPendingCall *call_get_properties;
144 DBusPendingCall *call_get_contexts;
147 static char *get_ident(const char *path)
154 pos = strrchr(path, '/');
161 static struct network_context *network_context_alloc(const char *path)
163 struct network_context *context;
165 context = g_try_new0(struct network_context, 1);
169 context->path = g_strdup(path);
172 context->ipv4_method = CONNMAN_IPCONFIG_METHOD_UNKNOWN;
173 context->ipv4_address = NULL;
174 context->ipv4_nameservers = NULL;
176 context->ipv6_method = CONNMAN_IPCONFIG_METHOD_UNKNOWN;
177 context->ipv6_address = NULL;
178 context->ipv6_nameservers = NULL;
183 static void network_context_free(struct network_context *context)
185 g_free(context->path);
187 connman_ipaddress_free(context->ipv4_address);
188 g_free(context->ipv4_nameservers);
190 connman_ipaddress_free(context->ipv6_address);
191 g_free(context->ipv6_nameservers);
196 static void set_connected(struct modem_data *modem)
198 connman_bool_t setip = FALSE;
200 DBG("%s", modem->path);
202 connman_network_set_index(modem->network, modem->context->index);
204 switch (modem->context->ipv4_method) {
205 case CONNMAN_IPCONFIG_METHOD_UNKNOWN:
206 case CONNMAN_IPCONFIG_METHOD_OFF:
207 case CONNMAN_IPCONFIG_METHOD_MANUAL:
208 case CONNMAN_IPCONFIG_METHOD_AUTO:
211 case CONNMAN_IPCONFIG_METHOD_FIXED:
212 connman_network_set_ipv4_method(modem->network,
213 modem->context->ipv4_method);
214 connman_network_set_ipaddress(modem->network,
215 modem->context->ipv4_address);
216 connman_network_set_nameservers(modem->network,
217 modem->context->ipv4_nameservers);
221 case CONNMAN_IPCONFIG_METHOD_DHCP:
222 connman_network_set_ipv4_method(modem->network,
223 modem->context->ipv4_method);
228 switch (modem->context->ipv6_method) {
229 case CONNMAN_IPCONFIG_METHOD_UNKNOWN:
230 case CONNMAN_IPCONFIG_METHOD_OFF:
231 case CONNMAN_IPCONFIG_METHOD_MANUAL:
232 case CONNMAN_IPCONFIG_METHOD_DHCP:
233 case CONNMAN_IPCONFIG_METHOD_AUTO:
236 case CONNMAN_IPCONFIG_METHOD_FIXED:
237 connman_network_set_ipv6_method(modem->network,
238 modem->context->ipv6_method);
239 connman_network_set_ipaddress(modem->network,
240 modem->context->ipv6_address);
246 connman_network_set_connected(modem->network, TRUE);
249 static void set_disconnected(struct modem_data *modem)
251 DBG("%s", modem->path);
253 connman_network_set_connected(modem->network, FALSE);
256 typedef void (*set_property_cb)(struct modem_data *data,
257 connman_bool_t success);
258 typedef void (*get_properties_cb)(struct modem_data *data,
259 DBusMessageIter *dict);
261 struct property_info {
262 struct modem_data *modem;
264 const char *interface;
265 const char *property;
266 set_property_cb set_property_cb;
267 get_properties_cb get_properties_cb;
270 static void set_property_reply(DBusPendingCall *call, void *user_data)
272 struct property_info *info = user_data;
275 connman_bool_t success = TRUE;
277 DBG("%s path %s %s.%s", info->modem->path,
278 info->path, info->interface, info->property);
280 info->modem->call_set_property = NULL;
282 dbus_error_init(&error);
284 reply = dbus_pending_call_steal_reply(call);
286 if (dbus_set_error_from_message(&error, reply)) {
287 connman_error("Failed to change property: %s %s.%s: %s %s",
288 info->path, info->interface, info->property,
289 error.name, error.message);
290 dbus_error_free(&error);
294 if (info->set_property_cb != NULL)
295 (*info->set_property_cb)(info->modem, success);
297 dbus_message_unref(reply);
299 dbus_pending_call_unref(call);
302 static int set_property(struct modem_data *modem,
303 const char *path, const char *interface,
304 const char *property, int type, void *value,
305 set_property_cb notify)
307 DBusMessage *message;
308 DBusMessageIter iter;
309 struct property_info *info;
311 DBG("%s path %s %s.%s", modem->path, path, interface, property);
313 if (modem->call_set_property != NULL) {
314 connman_error("Pending SetProperty");
318 message = dbus_message_new_method_call(OFONO_SERVICE, path,
319 interface, SET_PROPERTY);
323 dbus_message_iter_init_append(message, &iter);
324 connman_dbus_property_append_basic(&iter, property, type, value);
326 if (dbus_connection_send_with_reply(connection, message,
327 &modem->call_set_property, TIMEOUT) == FALSE) {
328 connman_error("Failed to change property: %s %s.%s",
329 path, interface, property);
330 dbus_message_unref(message);
334 if (modem->call_set_property == NULL) {
335 connman_error("D-Bus connection not available");
336 dbus_message_unref(message);
340 info = g_try_new0(struct property_info, 1);
342 dbus_message_unref(message);
348 info->interface = interface;
349 info->property = property;
350 info->set_property_cb = notify;
352 dbus_pending_call_set_notify(modem->call_set_property,
353 set_property_reply, info, g_free);
355 dbus_message_unref(message);
360 static void get_properties_reply(DBusPendingCall *call, void *user_data)
362 struct property_info *info = user_data;
363 DBusMessageIter array, dict;
367 DBG("%s path %s %s", info->modem->path, info->path, info->interface);
369 info->modem->call_get_properties = NULL;
371 dbus_error_init(&error);
373 reply = dbus_pending_call_steal_reply(call);
375 if (dbus_set_error_from_message(&error, reply)) {
376 connman_error("Failed to get properties: %s %s: %s %s",
377 info->path, info->interface,
378 error.name, error.message);
379 dbus_error_free(&error);
384 if (dbus_message_iter_init(reply, &array) == FALSE)
387 if (dbus_message_iter_get_arg_type(&array) != DBUS_TYPE_ARRAY)
390 dbus_message_iter_recurse(&array, &dict);
392 if (info->get_properties_cb != NULL)
393 (*info->get_properties_cb)(info->modem, &dict);
397 dbus_message_unref(reply);
399 dbus_pending_call_unref(call);
402 static int get_properties(const char *path, const char *interface,
403 get_properties_cb notify,
404 struct modem_data *modem)
406 DBusMessage *message;
407 struct property_info *info;
409 DBG("%s path %s %s", modem->path, path, interface);
411 if (modem->call_get_properties != NULL) {
412 connman_error("Pending GetProperties");
416 message = dbus_message_new_method_call(OFONO_SERVICE, path,
417 interface, GET_PROPERTIES);
421 if (dbus_connection_send_with_reply(connection, message,
422 &modem->call_get_properties, TIMEOUT) == FALSE) {
423 connman_error("Failed to call %s.GetProperties()", interface);
424 dbus_message_unref(message);
428 if (modem->call_get_properties == NULL) {
429 connman_error("D-Bus connection not available");
430 dbus_message_unref(message);
434 info = g_try_new0(struct property_info, 1);
436 dbus_message_unref(message);
442 info->interface = interface;
443 info->get_properties_cb = notify;
445 dbus_pending_call_set_notify(modem->call_get_properties,
446 get_properties_reply, info, g_free);
448 dbus_message_unref(message);
453 static void context_set_active_reply(struct modem_data *modem,
454 connman_bool_t success)
456 DBG("%s", modem->path);
458 if (success == TRUE) {
460 * Don't handle do anything on success here. oFono will send
461 * the change via PropertyChanged singal.
467 * Active = True might fail due a timeout. That means oFono
468 * still tries to go online. If we retry to set Active = True,
469 * we just get a InProgress error message. Should we power
470 * cycle the modem in such cases?
473 connman_network_set_error(modem->network,
474 CONNMAN_NETWORK_ERROR_ASSOCIATE_FAIL);
477 static int context_set_active(struct modem_data *modem)
479 dbus_bool_t active = TRUE;
481 DBG("%s", modem->path);
483 return set_property(modem, modem->context->path,
484 OFONO_CONTEXT_INTERFACE,
485 "Active", DBUS_TYPE_BOOLEAN,
487 context_set_active_reply);
490 static int context_set_inactive(struct modem_data *modem)
492 dbus_bool_t active = FALSE;
495 DBG("%s", modem->path);
497 err = set_property(modem, modem->context->path,
498 OFONO_CONTEXT_INTERFACE,
499 "Active", DBUS_TYPE_BOOLEAN,
502 if (err == -EINPROGRESS)
508 static void modem_set_online_reply(struct modem_data *modem,
509 connman_bool_t success)
511 DBG("%s", modem->path);
513 if (success == TRUE) {
515 * Don't handle do anything on success here. oFono will send
516 * the change via PropertyChanged singal.
521 modem->set_online = FALSE;
524 static int modem_set_online(struct modem_data *modem)
526 DBG("%s", modem->path);
528 modem->set_online = TRUE;
530 return set_property(modem, modem->path,
531 OFONO_MODEM_INTERFACE,
532 "Online", DBUS_TYPE_BOOLEAN,
534 modem_set_online_reply);
537 static void cm_set_powered_reply(struct modem_data *modem,
538 connman_bool_t success)
540 DBG("%s", modem->path);
542 if (success == TRUE) {
544 * Don't handle do anything on success here. oFono will send
545 * the change via PropertyChanged singal.
550 modem->set_cm_powered = FALSE;
553 static int cm_set_powered(struct modem_data *modem)
555 DBG("%s", modem->path);
557 modem->set_cm_powered = TRUE;
559 return set_property(modem, modem->path,
561 "Powered", DBUS_TYPE_BOOLEAN,
562 &modem->set_cm_powered,
563 cm_set_powered_reply);
566 static int modem_set_powered(struct modem_data *modem)
568 DBG("%s", modem->path);
570 modem->set_powered = TRUE;
572 return set_property(modem, modem->path,
573 OFONO_MODEM_INTERFACE,
574 "Powered", DBUS_TYPE_BOOLEAN,
579 static int modem_set_unpowered(struct modem_data *modem)
581 DBG("%s", modem->path);
583 modem->set_powered = FALSE;
585 return set_property(modem, modem->path,
586 OFONO_MODEM_INTERFACE,
587 "Powered", DBUS_TYPE_BOOLEAN,
592 static connman_bool_t has_interface(uint8_t interfaces,
595 if ((interfaces & api) == api)
601 static uint8_t extract_interfaces(DBusMessageIter *array)
603 DBusMessageIter entry;
604 uint8_t interfaces = 0;
606 dbus_message_iter_recurse(array, &entry);
608 while (dbus_message_iter_get_arg_type(&entry) == DBUS_TYPE_STRING) {
611 dbus_message_iter_get_basic(&entry, &name);
613 if (g_str_equal(name, OFONO_SIM_INTERFACE) == TRUE)
614 interfaces |= OFONO_API_SIM;
615 else if (g_str_equal(name, OFONO_NETREG_INTERFACE) == TRUE)
616 interfaces |= OFONO_API_NETREG;
617 else if (g_str_equal(name, OFONO_CM_INTERFACE) == TRUE)
618 interfaces |= OFONO_API_CM;
620 dbus_message_iter_next(&entry);
626 static char *extract_nameservers(DBusMessageIter *array)
628 DBusMessageIter entry;
629 char *nameservers = NULL;
632 dbus_message_iter_recurse(array, &entry);
634 while (dbus_message_iter_get_arg_type(&entry) == DBUS_TYPE_STRING) {
635 const char *nameserver;
637 dbus_message_iter_get_basic(&entry, &nameserver);
639 if (nameservers == NULL) {
640 nameservers = g_strdup(nameserver);
643 nameservers = g_strdup_printf("%s %s", tmp, nameserver);
647 dbus_message_iter_next(&entry);
653 static void extract_ipv4_settings(DBusMessageIter *array,
654 struct network_context *context)
656 DBusMessageIter dict;
657 char *address = NULL, *netmask = NULL, *gateway = NULL;
658 char *nameservers = NULL;
659 const char *interface = NULL;
662 if (dbus_message_iter_get_arg_type(array) != DBUS_TYPE_ARRAY)
665 dbus_message_iter_recurse(array, &dict);
667 while (dbus_message_iter_get_arg_type(&dict) == DBUS_TYPE_DICT_ENTRY) {
668 DBusMessageIter entry, value;
669 const char *key, *val;
671 dbus_message_iter_recurse(&dict, &entry);
672 dbus_message_iter_get_basic(&entry, &key);
674 dbus_message_iter_next(&entry);
675 dbus_message_iter_recurse(&entry, &value);
677 if (g_str_equal(key, "Interface") == TRUE) {
678 dbus_message_iter_get_basic(&value, &interface);
680 DBG("Interface %s", interface);
682 index = connman_inet_ifindex(interface);
684 DBG("index %d", index);
685 } else if (g_str_equal(key, "Method") == TRUE) {
686 dbus_message_iter_get_basic(&value, &val);
688 DBG("Method %s", val);
690 if (g_strcmp0(val, "static") == 0) {
691 context->ipv4_method = CONNMAN_IPCONFIG_METHOD_FIXED;
692 } else if (g_strcmp0(val, "dhcp") == 0) {
693 context->ipv4_method = CONNMAN_IPCONFIG_METHOD_DHCP;
696 } else if (g_str_equal(key, "Address") == TRUE) {
697 dbus_message_iter_get_basic(&value, &val);
699 address = g_strdup(val);
701 DBG("Address %s", address);
702 } else if (g_str_equal(key, "Netmask") == TRUE) {
703 dbus_message_iter_get_basic(&value, &val);
705 netmask = g_strdup(val);
707 DBG("Netmask %s", netmask);
708 } else if (g_str_equal(key, "DomainNameServers") == TRUE) {
709 nameservers = extract_nameservers(&value);
711 DBG("Nameservers %s", nameservers);
712 } else if (g_str_equal(key, "Gateway") == TRUE) {
713 dbus_message_iter_get_basic(&value, &val);
715 gateway = g_strdup(val);
717 DBG("Gateway %s", gateway);
720 dbus_message_iter_next(&dict);
726 if (context->ipv4_method != CONNMAN_IPCONFIG_METHOD_FIXED)
729 context->ipv4_address = connman_ipaddress_alloc(CONNMAN_IPCONFIG_TYPE_IPV4);
730 if (context->ipv4_address == NULL)
733 context->index = index;
734 connman_ipaddress_set_ipv4(context->ipv4_address, address,
737 context->ipv4_nameservers = nameservers;
740 if (context->ipv4_nameservers != nameservers)
748 static void extract_ipv6_settings(DBusMessageIter *array,
749 struct network_context *context)
751 DBusMessageIter dict;
752 char *address = NULL, *gateway = NULL;
753 unsigned char prefix_length;
754 char *nameservers = NULL;
755 const char *interface = NULL;
758 if (dbus_message_iter_get_arg_type(array) != DBUS_TYPE_ARRAY)
761 dbus_message_iter_recurse(array, &dict);
763 while (dbus_message_iter_get_arg_type(&dict) == DBUS_TYPE_DICT_ENTRY) {
764 DBusMessageIter entry, value;
765 const char *key, *val;
767 dbus_message_iter_recurse(&dict, &entry);
768 dbus_message_iter_get_basic(&entry, &key);
770 dbus_message_iter_next(&entry);
771 dbus_message_iter_recurse(&entry, &value);
773 if (g_str_equal(key, "Interface") == TRUE) {
774 dbus_message_iter_get_basic(&value, &interface);
776 DBG("Interface %s", interface);
778 index = connman_inet_ifindex(interface);
780 DBG("index %d", index);
781 } else if (g_str_equal(key, "Address") == TRUE) {
782 dbus_message_iter_get_basic(&value, &val);
784 address = g_strdup(val);
786 DBG("Address %s", address);
787 } else if (g_str_equal(key, "PrefixLength") == TRUE) {
788 dbus_message_iter_get_basic(&value, &prefix_length);
790 DBG("prefix length %d", prefix_length);
791 } else if (g_str_equal(key, "DomainNameServers") == TRUE) {
792 nameservers = extract_nameservers(&value);
794 DBG("Nameservers %s", nameservers);
795 } else if (g_str_equal(key, "Gateway") == TRUE) {
796 dbus_message_iter_get_basic(&value, &val);
798 gateway = g_strdup(val);
800 DBG("Gateway %s", gateway);
803 dbus_message_iter_next(&dict);
809 context->ipv6_method = CONNMAN_IPCONFIG_METHOD_FIXED;
811 context->ipv6_address =
812 connman_ipaddress_alloc(CONNMAN_IPCONFIG_TYPE_IPV6);
813 if (context->ipv6_address == NULL)
816 context->index = index;
817 connman_ipaddress_set_ipv6(context->ipv6_address, address,
818 prefix_length, gateway);
820 context->ipv6_nameservers = nameservers;
823 if (context->ipv6_nameservers != nameservers)
830 static connman_bool_t ready_to_create_device(struct modem_data *modem)
833 * There are three different modem types which behave slightly
835 * - GSM modems will expose the SIM interface then the
837 * - DUN modems will expose first a unique serial number (BDADDR)
838 * and then the CM interface.
839 * - CDMA modems will expose CM first and sometime later
840 * a unique serial number.
842 * This functions tests if we have the necessary information gathered
843 * before we are able to create a device.
846 if (modem->device != NULL)
849 if (modem->imsi != NULL || modem->serial != NULL)
855 static void create_device(struct modem_data *modem)
857 struct connman_device *device;
858 char *uninitialized_var(ident);
860 DBG("%s", modem->path);
862 if (modem->imsi != NULL)
864 else if (modem->serial != NULL)
865 ident = modem->serial;
867 if (connman_dbus_validate_ident(ident) == FALSE)
868 ident = connman_dbus_encode_string(ident);
870 ident = g_strdup(ident);
872 device = connman_device_create(ident, CONNMAN_DEVICE_TYPE_CELLULAR);
876 DBG("device %p", device);
878 connman_device_set_ident(device, ident);
880 connman_device_set_string(device, "Path", modem->path);
882 connman_device_set_data(device, modem);
884 if (connman_device_register(device) < 0) {
885 connman_error("Failed to register cellular device");
886 connman_device_unref(device);
890 modem->device = device;
896 static void destroy_device(struct modem_data *modem)
898 DBG("%s", modem->path);
900 connman_device_set_powered(modem->device, FALSE);
902 if (modem->network != NULL) {
903 connman_device_remove_network(modem->device, modem->network);
904 connman_network_unref(modem->network);
905 modem->network = NULL;
908 connman_device_unregister(modem->device);
909 connman_device_unref(modem->device);
911 modem->device = NULL;
914 static void add_network(struct modem_data *modem)
918 DBG("%s", modem->path);
920 if (modem->network != NULL)
923 modem->network = connman_network_create(modem->context->path,
924 CONNMAN_NETWORK_TYPE_CELLULAR);
925 if (modem->network == NULL)
928 DBG("network %p", modem->network);
930 connman_network_set_data(modem->network, modem);
932 connman_network_set_string(modem->network, "Path",
933 modem->context->path);
935 connman_network_set_index(modem->network, modem->context->index);
937 if (modem->name != NULL)
938 connman_network_set_name(modem->network, modem->name);
940 connman_network_set_name(modem->network, "");
942 connman_network_set_strength(modem->network, modem->strength);
944 group = get_ident(modem->context->path);
945 connman_network_set_group(modem->network, group);
947 connman_network_set_available(modem->network, TRUE);
949 if (connman_device_add_network(modem->device, modem->network) < 0) {
950 connman_network_unref(modem->network);
951 modem->network = NULL;
956 static int add_cm_context(struct modem_data *modem, const char *context_path,
957 DBusMessageIter *dict)
959 const char *context_type;
960 struct network_context *context = NULL;
961 connman_bool_t active = FALSE;
963 DBG("%s context path %s", modem->path, context_path);
965 if (modem->context != NULL) {
967 * We have already assigned a context to this modem
968 * and we do only support one Internet context.
973 context = network_context_alloc(context_path);
977 while (dbus_message_iter_get_arg_type(dict) == DBUS_TYPE_DICT_ENTRY) {
978 DBusMessageIter entry, value;
981 dbus_message_iter_recurse(dict, &entry);
982 dbus_message_iter_get_basic(&entry, &key);
984 dbus_message_iter_next(&entry);
985 dbus_message_iter_recurse(&entry, &value);
987 if (g_str_equal(key, "Type") == TRUE) {
988 dbus_message_iter_get_basic(&value, &context_type);
990 DBG("%s context %s type %s", modem->path,
991 context_path, context_type);
992 } else if (g_str_equal(key, "Settings") == TRUE) {
993 DBG("%s Settings", modem->path);
995 extract_ipv4_settings(&value, context);
996 } else if (g_str_equal(key, "IPv6.Settings") == TRUE) {
997 DBG("%s IPv6.Settings", modem->path);
999 extract_ipv6_settings(&value, context);
1000 } else if (g_str_equal(key, "Active") == TRUE) {
1001 dbus_message_iter_get_basic(&value, &active);
1003 DBG("%s Active %d", modem->path, active);
1006 dbus_message_iter_next(dict);
1009 if (g_strcmp0(context_type, "internet") != 0) {
1010 network_context_free(context);
1014 modem->context = context;
1015 modem->active = active;
1017 g_hash_table_replace(context_hash, g_strdup(context_path), modem);
1022 static void remove_cm_context(struct modem_data *modem,
1023 const char *context_path)
1025 if (modem->context == NULL)
1028 g_hash_table_remove(context_hash, context_path);
1030 network_context_free(modem->context);
1031 modem->context = NULL;
1034 static gboolean context_changed(DBusConnection *connection,
1035 DBusMessage *message,
1038 const char *context_path = dbus_message_get_path(message);
1039 struct modem_data *modem = NULL;
1040 DBusMessageIter iter, value;
1043 DBG("context_path %s", context_path);
1045 modem = g_hash_table_lookup(context_hash, context_path);
1049 if (dbus_message_iter_init(message, &iter) == FALSE)
1052 dbus_message_iter_get_basic(&iter, &key);
1054 dbus_message_iter_next(&iter);
1055 dbus_message_iter_recurse(&iter, &value);
1058 * oFono guarantees the ordering of Settings and
1059 * Active. Settings will always be send before Active = True.
1060 * That means we don't have to order here.
1062 if (g_str_equal(key, "Settings") == TRUE) {
1063 DBG("%s Settings", modem->path);
1065 extract_ipv4_settings(&value, modem->context);
1066 } else if (g_str_equal(key, "IPv6.Settings") == TRUE) {
1067 DBG("%s IPv6.Settings", modem->path);
1069 extract_ipv6_settings(&value, modem->context);
1070 } else if (g_str_equal(key, "Active") == TRUE) {
1071 dbus_message_iter_get_basic(&value, &modem->active);
1073 DBG("%s Active %d", modem->path, modem->active);
1075 if (modem->active == TRUE)
1076 set_connected(modem);
1078 set_disconnected(modem);
1084 static void cm_get_contexts_reply(DBusPendingCall *call, void *user_data)
1086 struct modem_data *modem = user_data;
1087 DBusMessageIter array, dict, entry, value;
1091 DBG("%s", modem->path);
1093 modem->call_get_contexts = NULL;
1095 reply = dbus_pending_call_steal_reply(call);
1097 dbus_error_init(&error);
1099 if (dbus_set_error_from_message(&error, reply) == TRUE) {
1100 connman_error("%s", error.message);
1101 dbus_error_free(&error);
1105 if (dbus_message_iter_init(reply, &array) == FALSE)
1108 if (dbus_message_iter_get_arg_type(&array) != DBUS_TYPE_ARRAY)
1111 dbus_message_iter_recurse(&array, &dict);
1113 while (dbus_message_iter_get_arg_type(&dict) == DBUS_TYPE_STRUCT) {
1114 const char *context_path;
1116 dbus_message_iter_recurse(&dict, &entry);
1117 dbus_message_iter_get_basic(&entry, &context_path);
1119 dbus_message_iter_next(&entry);
1120 dbus_message_iter_recurse(&entry, &value);
1122 if (add_cm_context(modem, context_path, &value) == 0)
1125 dbus_message_iter_next(&dict);
1129 dbus_message_unref(reply);
1131 dbus_pending_call_unref(call);
1134 static int cm_get_contexts(struct modem_data *modem)
1136 DBusMessage *message;
1138 DBG("%s", modem->path);
1140 if (modem->call_get_contexts != NULL)
1143 message = dbus_message_new_method_call(OFONO_SERVICE, modem->path,
1144 OFONO_CM_INTERFACE, GET_CONTEXTS);
1145 if (message == NULL)
1148 if (dbus_connection_send_with_reply(connection, message,
1149 &modem->call_get_contexts, TIMEOUT) == FALSE) {
1150 connman_error("Failed to call GetContexts()");
1151 dbus_message_unref(message);
1155 if (modem->call_get_contexts == NULL) {
1156 connman_error("D-Bus connection not available");
1157 dbus_message_unref(message);
1161 dbus_pending_call_set_notify(modem->call_get_contexts,
1162 cm_get_contexts_reply,
1165 dbus_message_unref(message);
1167 return -EINPROGRESS;
1170 static gboolean cm_context_added(DBusConnection *connection,
1171 DBusMessage *message,
1174 const char *path = dbus_message_get_path(message);
1176 struct modem_data *modem;
1177 DBusMessageIter iter, properties;
1181 modem = g_hash_table_lookup(modem_hash, context_path);
1185 if (dbus_message_iter_init(message, &iter) == FALSE)
1188 dbus_message_iter_get_basic(&iter, &context_path);
1190 dbus_message_iter_next(&iter);
1191 dbus_message_iter_recurse(&iter, &properties);
1193 if (add_cm_context(modem, context_path, &properties) != 0)
1199 static gboolean cm_context_removed(DBusConnection *connection,
1200 DBusMessage *message,
1203 const char *path = dbus_message_get_path(message);
1204 const char *context_path;
1205 struct modem_data *modem;
1206 DBusMessageIter iter;
1208 DBG("context path %s", path);
1210 if (dbus_message_iter_init(message, &iter) == FALSE)
1213 dbus_message_iter_get_basic(&iter, &context_path);
1215 modem = g_hash_table_lookup(context_hash, context_path);
1219 remove_cm_context(modem, context_path);
1224 static void netreg_update_name(struct modem_data *modem,
1225 DBusMessageIter* value)
1229 dbus_message_iter_get_basic(value, &name);
1231 DBG("%s Name %s", modem->path, name);
1233 g_free(modem->name);
1234 modem->name = g_strdup(name);
1236 if (modem->network == NULL)
1239 connman_network_set_name(modem->network, modem->name);
1240 connman_network_update(modem->network);
1243 static gboolean netreg_changed(DBusConnection *connection, DBusMessage *message,
1246 const char *path = dbus_message_get_path(message);
1247 struct modem_data *modem;
1248 DBusMessageIter iter, value;
1251 modem = g_hash_table_lookup(modem_hash, path);
1255 if (modem->ignore == TRUE)
1258 if (dbus_message_iter_init(message, &iter) == FALSE)
1261 dbus_message_iter_get_basic(&iter, &key);
1263 dbus_message_iter_next(&iter);
1264 dbus_message_iter_recurse(&iter, &value);
1266 if (g_str_equal(key, "Name") == TRUE) {
1267 netreg_update_name(modem, &value);
1268 } else if (g_str_equal(key, "Strength") == TRUE) {
1269 dbus_message_iter_get_basic(&value, &modem->strength);
1271 DBG("%s Strength %d", modem->path, modem->strength);
1273 if (modem->network == NULL)
1276 connman_network_set_strength(modem->network, modem->strength);
1277 connman_network_update(modem->network);
1283 static void netreg_properties_reply(struct modem_data *modem,
1284 DBusMessageIter *dict)
1286 DBG("%s", modem->path);
1288 while (dbus_message_iter_get_arg_type(dict) == DBUS_TYPE_DICT_ENTRY) {
1289 DBusMessageIter entry, value;
1292 dbus_message_iter_recurse(dict, &entry);
1293 dbus_message_iter_get_basic(&entry, &key);
1295 dbus_message_iter_next(&entry);
1296 dbus_message_iter_recurse(&entry, &value);
1298 if (g_str_equal(key, "Name") == TRUE) {
1299 netreg_update_name(modem, &value);
1300 } else if (g_str_equal(key, "Strength") == TRUE) {
1301 dbus_message_iter_get_basic(&value, &modem->strength);
1303 DBG("%s Strength %d", modem->path,
1306 if (modem->network != NULL) {
1307 connman_network_set_strength(modem->network,
1309 connman_network_update(modem->network);
1313 dbus_message_iter_next(dict);
1316 if (modem->context == NULL) {
1318 * netgreg_get_properties() was issued after we got
1319 * cm_get_contexts_reply() where we create the
1320 * context. Though before we got the
1321 * netreg_properties_reply the context was removed
1322 * again. Therefore we have to skip the network
1330 if (modem->active == TRUE)
1331 set_connected(modem);
1334 static int netreg_get_properties(struct modem_data *modem)
1336 return get_properties(modem->path, OFONO_NETREG_INTERFACE,
1337 netreg_properties_reply, modem);
1340 static gboolean cm_changed(DBusConnection *connection, DBusMessage *message,
1343 const char *path = dbus_message_get_path(message);
1344 struct modem_data *modem;
1345 DBusMessageIter iter, value;
1348 modem = g_hash_table_lookup(modem_hash, path);
1352 if (modem->ignore == TRUE)
1355 if (dbus_message_iter_init(message, &iter) == FALSE)
1358 dbus_message_iter_get_basic(&iter, &key);
1360 dbus_message_iter_next(&iter);
1361 dbus_message_iter_recurse(&iter, &value);
1363 if (g_str_equal(key, "Attached") == TRUE) {
1364 dbus_message_iter_get_basic(&value, &modem->attached);
1366 DBG("%s Attached %d", modem->path, modem->attached);
1368 if (modem->attached == TRUE) {
1369 if (has_interface(modem->interfaces,
1370 OFONO_API_NETREG) == TRUE) {
1371 netreg_get_properties(modem);
1374 } else if (g_str_equal(key, "Powered") == TRUE) {
1375 dbus_message_iter_get_basic(&value, &modem->cm_powered);
1377 DBG("%s ConnnectionManager Powered %d", modem->path,
1380 if (modem->cm_powered == FALSE)
1381 cm_set_powered(modem);
1387 static void cm_properties_reply(struct modem_data *modem, DBusMessageIter *dict)
1389 DBG("%s", modem->path);
1391 while (dbus_message_iter_get_arg_type(dict) == DBUS_TYPE_DICT_ENTRY) {
1392 DBusMessageIter entry, value;
1395 dbus_message_iter_recurse(dict, &entry);
1396 dbus_message_iter_get_basic(&entry, &key);
1398 dbus_message_iter_next(&entry);
1399 dbus_message_iter_recurse(&entry, &value);
1401 if (g_str_equal(key, "Attached") == TRUE) {
1402 dbus_message_iter_get_basic(&value, &modem->attached);
1404 DBG("%s Attached %d", modem->path,
1407 if (modem->attached == TRUE) {
1408 if (has_interface(modem->interfaces,
1409 OFONO_API_NETREG) == TRUE) {
1410 netreg_get_properties(modem);
1413 } else if (g_str_equal(key, "Powered") == TRUE) {
1414 dbus_message_iter_get_basic(&value, &modem->cm_powered);
1416 DBG("%s ConnnectionManager Powered %d", modem->path,
1419 if (modem->cm_powered == FALSE)
1420 cm_set_powered(modem);
1423 dbus_message_iter_next(dict);
1427 static int cm_get_properties(struct modem_data *modem)
1429 return get_properties(modem->path, OFONO_CM_INTERFACE,
1430 cm_properties_reply, modem);
1433 static void update_sim_imsi(struct modem_data *modem,
1436 DBG("%s imsi %s", modem->path, imsi);
1438 if (g_strcmp0(modem->imsi, imsi) == 0)
1441 g_free(modem->imsi);
1442 modem->imsi = g_strdup(imsi);
1445 static gboolean sim_changed(DBusConnection *connection, DBusMessage *message,
1448 const char *path = dbus_message_get_path(message);
1449 struct modem_data *modem;
1450 DBusMessageIter iter, value;
1453 modem = g_hash_table_lookup(modem_hash, path);
1457 if (modem->ignore == TRUE)
1460 if (dbus_message_iter_init(message, &iter) == FALSE)
1463 dbus_message_iter_get_basic(&iter, &key);
1465 dbus_message_iter_next(&iter);
1466 dbus_message_iter_recurse(&iter, &value);
1468 if (g_str_equal(key, "SubscriberIdentity") == TRUE) {
1471 dbus_message_iter_get_basic(&value, &imsi);
1473 update_sim_imsi(modem, imsi);
1475 if (modem->online == FALSE) {
1476 modem_set_online(modem);
1477 } else if (has_interface(modem->interfaces,
1478 OFONO_API_CM) == TRUE) {
1479 if (ready_to_create_device(modem) == TRUE)
1480 create_device(modem);
1487 static void sim_properties_reply(struct modem_data *modem,
1488 DBusMessageIter *dict)
1490 DBG("%s", modem->path);
1492 while (dbus_message_iter_get_arg_type(dict) == DBUS_TYPE_DICT_ENTRY) {
1493 DBusMessageIter entry, value;
1496 dbus_message_iter_recurse(dict, &entry);
1497 dbus_message_iter_get_basic(&entry, &key);
1499 dbus_message_iter_next(&entry);
1500 dbus_message_iter_recurse(&entry, &value);
1502 if (g_str_equal(key, "SubscriberIdentity") == TRUE) {
1505 dbus_message_iter_get_basic(&value, &imsi);
1507 update_sim_imsi(modem, imsi);
1509 if (modem->online == FALSE) {
1510 modem_set_online(modem);
1514 if (has_interface(modem->interfaces, OFONO_API_CM) == TRUE) {
1515 if (ready_to_create_device(modem) == TRUE)
1516 create_device(modem);
1517 if (modem->device != NULL) {
1518 cm_get_properties(modem);
1519 cm_get_contexts(modem);
1525 dbus_message_iter_next(dict);
1529 static int sim_get_properties(struct modem_data *modem)
1531 return get_properties(modem->path, OFONO_SIM_INTERFACE,
1532 sim_properties_reply, modem);
1535 static gboolean modem_changed(DBusConnection *connection, DBusMessage *message,
1538 const char *path = dbus_message_get_path(message);
1539 struct modem_data *modem;
1540 DBusMessageIter iter, value;
1543 modem = g_hash_table_lookup(modem_hash, path);
1547 if (modem->ignore == TRUE)
1550 if (dbus_message_iter_init(message, &iter) == FALSE)
1553 dbus_message_iter_get_basic(&iter, &key);
1555 dbus_message_iter_next(&iter);
1556 dbus_message_iter_recurse(&iter, &value);
1558 if (g_str_equal(key, "Powered") == TRUE) {
1559 dbus_message_iter_get_basic(&value, &modem->powered);
1561 DBG("%s Powered %d", modem->path, modem->powered);
1563 if (modem->powered == FALSE)
1564 modem_set_powered(modem);
1565 } else if (g_str_equal(key, "Online") == TRUE) {
1566 dbus_message_iter_get_basic(&value, &modem->online);
1568 DBG("%s Online %d", modem->path, modem->online);
1570 if (modem->online == FALSE)
1573 if (has_interface(modem->interfaces, OFONO_API_CM) == FALSE)
1575 if (ready_to_create_device(modem) == TRUE)
1576 create_device(modem);
1577 if (modem->device != NULL) {
1578 cm_get_properties(modem);
1579 cm_get_contexts(modem);
1581 } else if (g_str_equal(key, "Interfaces") == TRUE) {
1582 modem->interfaces = extract_interfaces(&value);
1584 DBG("%s Interfaces 0x%02x", modem->path,
1587 if (has_interface(modem->interfaces, OFONO_API_SIM) == TRUE) {
1588 if (modem->imsi == NULL &&
1589 modem->set_powered == FALSE) {
1591 * Only use do GetProperties() when
1592 * device has not been powered up.
1594 sim_get_properties(modem);
1599 if (has_interface(modem->interfaces, OFONO_API_CM) == TRUE) {
1600 if (ready_to_create_device(modem) == TRUE)
1601 create_device(modem);
1602 if (modem->device != NULL) {
1603 cm_get_properties(modem);
1604 cm_get_contexts(modem);
1608 if (modem->context != NULL) {
1609 remove_cm_context(modem,
1610 modem->context->path);
1613 if (modem->device != NULL)
1614 destroy_device(modem);
1619 if (has_interface(modem->interfaces, OFONO_API_NETREG) == TRUE) {
1620 if (modem->attached == TRUE)
1621 netreg_get_properties(modem);
1623 } else if (g_str_equal(key, "Serial") == TRUE) {
1626 dbus_message_iter_get_basic(&value, &serial);
1628 g_free(modem->serial);
1629 modem->serial = g_strdup(serial);
1631 DBG("%s Serial %s", modem->path, modem->serial);
1633 if (has_interface(modem->interfaces, OFONO_API_CM) == TRUE) {
1634 if (ready_to_create_device(modem) == TRUE)
1635 create_device(modem);
1636 if (modem->device != NULL) {
1637 cm_get_properties(modem);
1638 cm_get_contexts(modem);
1646 static void add_modem(const char *path, DBusMessageIter *prop)
1648 struct modem_data *modem;
1652 modem = g_hash_table_lookup(modem_hash, path);
1653 if (modem != NULL) {
1655 * When oFono powers up we ask for the modems and oFono is
1656 * reporting with modem_added signal the modems. Only
1662 modem = g_try_new0(struct modem_data, 1);
1666 modem->path = g_strdup(path);
1668 g_hash_table_insert(modem_hash, g_strdup(path), modem);
1670 while (dbus_message_iter_get_arg_type(prop) == DBUS_TYPE_DICT_ENTRY) {
1671 DBusMessageIter entry, value;
1674 dbus_message_iter_recurse(prop, &entry);
1675 dbus_message_iter_get_basic(&entry, &key);
1677 dbus_message_iter_next(&entry);
1678 dbus_message_iter_recurse(&entry, &value);
1680 if (g_str_equal(key, "Powered") == TRUE) {
1681 dbus_message_iter_get_basic(&value, &modem->powered);
1683 DBG("%s Powered %d", modem->path, modem->powered);
1684 } else if (g_str_equal(key, "Online") == TRUE) {
1685 dbus_message_iter_get_basic(&value, &modem->online);
1687 DBG("%s Online %d", modem->path, modem->online);
1688 } else if (g_str_equal(key, "Interfaces") == TRUE) {
1689 modem->interfaces = extract_interfaces(&value);
1691 DBG("%s Interfaces 0x%02x", modem->path,
1693 } else if (g_str_equal(key, "Serial") == TRUE) {
1696 dbus_message_iter_get_basic(&value, &serial);
1697 modem->serial = g_strdup(serial);
1699 DBG("%s Serial %s", modem->path, modem->serial);
1700 } else if (g_str_equal(key, "Type") == TRUE) {
1703 dbus_message_iter_get_basic(&value, &type);
1705 DBG("%s Type %s", modem->path, type);
1706 if (g_strcmp0(type, "hardware") != 0) {
1707 DBG("%s Ignore this modem", modem->path);
1708 modem->ignore = TRUE;
1712 dbus_message_iter_next(prop);
1715 if (modem->ignore == TRUE)
1718 if (modem->powered == FALSE) {
1719 modem_set_powered(modem);
1720 } else if (has_interface(modem->interfaces, OFONO_API_SIM) == TRUE) {
1721 sim_get_properties(modem);
1722 } else if (has_interface(modem->interfaces, OFONO_API_CM) == TRUE) {
1723 if (ready_to_create_device(modem) == TRUE)
1724 create_device(modem);
1725 if (modem->device != NULL) {
1726 cm_get_properties(modem);
1727 cm_get_contexts(modem);
1732 static void modem_power_down(gpointer key, gpointer value, gpointer user_data)
1734 struct modem_data *modem = value;
1736 DBG("%s", modem->path);
1738 if (modem->ignore == TRUE)
1741 modem_set_unpowered(modem);
1744 static void remove_modem(gpointer data)
1746 struct modem_data *modem = data;
1748 DBG("%s", modem->path);
1750 if (modem->call_set_property != NULL)
1751 dbus_pending_call_cancel(modem->call_set_property);
1753 if (modem->call_get_properties != NULL)
1754 dbus_pending_call_cancel(modem->call_get_properties);
1756 if (modem->call_get_contexts != NULL)
1757 dbus_pending_call_cancel(modem->call_get_contexts);
1759 if (modem->device != NULL)
1760 destroy_device(modem);
1762 if (modem->context != NULL)
1763 remove_cm_context(modem, modem->context->path);
1765 g_free(modem->serial);
1766 g_free(modem->name);
1767 g_free(modem->imsi);
1768 g_free(modem->path);
1773 static gboolean modem_added(DBusConnection *connection,
1774 DBusMessage *message, void *user_data)
1776 DBusMessageIter iter, properties;
1781 if (dbus_message_iter_init(message, &iter) == FALSE)
1784 dbus_message_iter_get_basic(&iter, &path);
1786 dbus_message_iter_next(&iter);
1787 dbus_message_iter_recurse(&iter, &properties);
1789 add_modem(path, &properties);
1794 static gboolean modem_removed(DBusConnection *connection,
1795 DBusMessage *message, void *user_data)
1797 DBusMessageIter iter;
1802 if (dbus_message_iter_init(message, &iter) == FALSE)
1805 dbus_message_iter_get_basic(&iter, &path);
1807 g_hash_table_remove(modem_hash, path);
1812 static void manager_get_modems_reply(DBusPendingCall *call, void *user_data)
1816 DBusMessageIter array, dict;
1820 reply = dbus_pending_call_steal_reply(call);
1822 dbus_error_init(&error);
1824 if (dbus_set_error_from_message(&error, reply) == TRUE) {
1825 connman_error("%s", error.message);
1826 dbus_error_free(&error);
1830 if (dbus_message_iter_init(reply, &array) == FALSE)
1833 dbus_message_iter_recurse(&array, &dict);
1835 while (dbus_message_iter_get_arg_type(&dict) == DBUS_TYPE_STRUCT) {
1836 DBusMessageIter value, properties;
1839 dbus_message_iter_recurse(&dict, &value);
1840 dbus_message_iter_get_basic(&value, &path);
1842 dbus_message_iter_next(&value);
1843 dbus_message_iter_recurse(&value, &properties);
1845 add_modem(path, &properties);
1847 dbus_message_iter_next(&dict);
1851 dbus_message_unref(reply);
1853 dbus_pending_call_unref(call);
1856 static int manager_get_modems(void)
1858 DBusMessage *message;
1859 DBusPendingCall *call;
1863 message = dbus_message_new_method_call(OFONO_SERVICE, "/",
1864 OFONO_MANAGER_INTERFACE, GET_MODEMS);
1865 if (message == NULL)
1868 if (dbus_connection_send_with_reply(connection, message,
1869 &call, TIMEOUT) == FALSE) {
1870 connman_error("Failed to call GetModems()");
1871 dbus_message_unref(message);
1876 connman_error("D-Bus connection not available");
1877 dbus_message_unref(message);
1881 dbus_pending_call_set_notify(call, manager_get_modems_reply,
1884 dbus_message_unref(message);
1886 return -EINPROGRESS;
1889 static void ofono_connect(DBusConnection *conn, void *user_data)
1893 modem_hash = g_hash_table_new_full(g_str_hash, g_str_equal,
1894 g_free, remove_modem);
1895 if (modem_hash == NULL)
1898 context_hash = g_hash_table_new_full(g_str_hash, g_str_equal,
1900 if (context_hash == NULL) {
1901 g_hash_table_destroy(modem_hash);
1905 manager_get_modems();
1908 static void ofono_disconnect(DBusConnection *conn, void *user_data)
1912 if (modem_hash == NULL || context_hash == NULL)
1915 g_hash_table_destroy(modem_hash);
1918 g_hash_table_destroy(context_hash);
1919 context_hash = NULL;
1922 static int network_probe(struct connman_network *network)
1924 struct modem_data *modem = connman_network_get_data(network);
1926 DBG("%s network %p", modem->path, network);
1931 static void network_remove(struct connman_network *network)
1933 struct modem_data *modem = connman_network_get_data(network);
1935 DBG("%s network %p", modem->path, network);
1938 static int network_connect(struct connman_network *network)
1940 struct modem_data *modem = connman_network_get_data(network);
1942 DBG("%s network %p", modem->path, network);
1944 return context_set_active(modem);
1947 static int network_disconnect(struct connman_network *network)
1949 struct modem_data *modem = connman_network_get_data(network);
1951 DBG("%s network %p", modem->path, network);
1953 return context_set_inactive(modem);
1956 static struct connman_network_driver network_driver = {
1958 .type = CONNMAN_NETWORK_TYPE_CELLULAR,
1959 .probe = network_probe,
1960 .remove = network_remove,
1961 .connect = network_connect,
1962 .disconnect = network_disconnect,
1965 static int modem_probe(struct connman_device *device)
1967 struct modem_data *modem = connman_device_get_data(device);
1969 DBG("%s device %p", modem->path, device);
1974 static void modem_remove(struct connman_device *device)
1976 struct modem_data *modem = connman_device_get_data(device);
1978 DBG("%s device %p", modem->path, device);
1981 static int modem_enable(struct connman_device *device)
1983 struct modem_data *modem = connman_device_get_data(device);
1985 DBG("%s device %p", modem->path, device);
1990 static int modem_disable(struct connman_device *device)
1992 struct modem_data *modem = connman_device_get_data(device);
1994 DBG("%s device %p", modem->path, device);
1999 static struct connman_device_driver modem_driver = {
2001 .type = CONNMAN_DEVICE_TYPE_CELLULAR,
2002 .probe = modem_probe,
2003 .remove = modem_remove,
2004 .enable = modem_enable,
2005 .disable = modem_disable,
2009 static guint modem_added_watch;
2010 static guint modem_removed_watch;
2011 static guint modem_watch;
2012 static guint cm_watch;
2013 static guint sim_watch;
2014 static guint context_added_watch;
2015 static guint context_removed_watch;
2016 static guint netreg_watch;
2017 static guint context_watch;
2019 static int ofono_init(void)
2025 connection = connman_dbus_get_connection();
2026 if (connection == NULL)
2029 watch = g_dbus_add_service_watch(connection,
2030 OFONO_SERVICE, ofono_connect,
2031 ofono_disconnect, NULL, NULL);
2033 modem_added_watch = g_dbus_add_signal_watch(connection, NULL, NULL,
2034 OFONO_MANAGER_INTERFACE,
2039 modem_removed_watch = g_dbus_add_signal_watch(connection, NULL, NULL,
2040 OFONO_MANAGER_INTERFACE,
2045 modem_watch = g_dbus_add_signal_watch(connection, NULL, NULL,
2046 OFONO_MODEM_INTERFACE,
2051 cm_watch = g_dbus_add_signal_watch(connection, NULL, NULL,
2057 sim_watch = g_dbus_add_signal_watch(connection, NULL, NULL,
2058 OFONO_SIM_INTERFACE,
2063 context_added_watch = g_dbus_add_signal_watch(connection, NULL, NULL,
2069 context_removed_watch = g_dbus_add_signal_watch(connection, NULL, NULL,
2075 context_watch = g_dbus_add_signal_watch(connection, NULL, NULL,
2076 OFONO_CONTEXT_INTERFACE,
2081 netreg_watch = g_dbus_add_signal_watch(connection, NULL, NULL,
2082 OFONO_NETREG_INTERFACE,
2088 if (watch == 0 || modem_added_watch == 0 || modem_removed_watch == 0 ||
2089 modem_watch == 0 || cm_watch == 0 || sim_watch == 0 ||
2090 context_added_watch == 0 ||
2091 context_removed_watch == 0 ||
2092 context_watch == 0 || netreg_watch == 0) {
2097 err = connman_network_driver_register(&network_driver);
2101 err = connman_device_driver_register(&modem_driver);
2103 connman_network_driver_unregister(&network_driver);
2110 g_dbus_remove_watch(connection, netreg_watch);
2111 g_dbus_remove_watch(connection, context_watch);
2112 g_dbus_remove_watch(connection, context_removed_watch);
2113 g_dbus_remove_watch(connection, context_added_watch);
2114 g_dbus_remove_watch(connection, sim_watch);
2115 g_dbus_remove_watch(connection, cm_watch);
2116 g_dbus_remove_watch(connection, modem_watch);
2117 g_dbus_remove_watch(connection, modem_removed_watch);
2118 g_dbus_remove_watch(connection, modem_added_watch);
2119 g_dbus_remove_watch(connection, watch);
2120 dbus_connection_unref(connection);
2125 static void ofono_exit(void)
2129 if (modem_hash != NULL) {
2131 * We should propably wait for the SetProperty() reply
2132 * message, because ...
2134 g_hash_table_foreach(modem_hash, modem_power_down, NULL);
2137 * ... here we will cancel the call.
2139 g_hash_table_destroy(modem_hash);
2143 if (context_hash != NULL) {
2144 g_hash_table_destroy(context_hash);
2145 context_hash = NULL;
2148 connman_device_driver_unregister(&modem_driver);
2149 connman_network_driver_unregister(&network_driver);
2151 g_dbus_remove_watch(connection, netreg_watch);
2152 g_dbus_remove_watch(connection, context_watch);
2153 g_dbus_remove_watch(connection, context_removed_watch);
2154 g_dbus_remove_watch(connection, context_added_watch);
2155 g_dbus_remove_watch(connection, sim_watch);
2156 g_dbus_remove_watch(connection, cm_watch);
2157 g_dbus_remove_watch(connection, modem_watch);
2158 g_dbus_remove_watch(connection, modem_added_watch);
2159 g_dbus_remove_watch(connection, modem_removed_watch);
2160 g_dbus_remove_watch(connection, watch);
2162 dbus_connection_unref(connection);
2165 CONNMAN_PLUGIN_DEFINE(ofono, "oFono telephony plugin", VERSION,
2166 CONNMAN_PLUGIN_PRIORITY_DEFAULT, ofono_init, ofono_exit)