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 */
140 connman_bool_t roaming;
143 DBusPendingCall *call_set_property;
144 DBusPendingCall *call_get_properties;
145 DBusPendingCall *call_get_contexts;
148 static char *get_ident(const char *path)
155 pos = strrchr(path, '/');
162 static struct network_context *network_context_alloc(const char *path)
164 struct network_context *context;
166 context = g_try_new0(struct network_context, 1);
170 context->path = g_strdup(path);
173 context->ipv4_method = CONNMAN_IPCONFIG_METHOD_UNKNOWN;
174 context->ipv4_address = NULL;
175 context->ipv4_nameservers = NULL;
177 context->ipv6_method = CONNMAN_IPCONFIG_METHOD_UNKNOWN;
178 context->ipv6_address = NULL;
179 context->ipv6_nameservers = NULL;
184 static void network_context_free(struct network_context *context)
186 g_free(context->path);
188 connman_ipaddress_free(context->ipv4_address);
189 g_free(context->ipv4_nameservers);
191 connman_ipaddress_free(context->ipv6_address);
192 g_free(context->ipv6_nameservers);
197 static void set_connected(struct modem_data *modem)
199 connman_bool_t setip = FALSE;
201 DBG("%s", modem->path);
203 connman_network_set_index(modem->network, modem->context->index);
205 switch (modem->context->ipv4_method) {
206 case CONNMAN_IPCONFIG_METHOD_UNKNOWN:
207 case CONNMAN_IPCONFIG_METHOD_OFF:
208 case CONNMAN_IPCONFIG_METHOD_MANUAL:
209 case CONNMAN_IPCONFIG_METHOD_AUTO:
212 case CONNMAN_IPCONFIG_METHOD_FIXED:
213 connman_network_set_ipv4_method(modem->network,
214 modem->context->ipv4_method);
215 connman_network_set_ipaddress(modem->network,
216 modem->context->ipv4_address);
217 connman_network_set_nameservers(modem->network,
218 modem->context->ipv4_nameservers);
222 case CONNMAN_IPCONFIG_METHOD_DHCP:
223 connman_network_set_ipv4_method(modem->network,
224 modem->context->ipv4_method);
229 switch (modem->context->ipv6_method) {
230 case CONNMAN_IPCONFIG_METHOD_UNKNOWN:
231 case CONNMAN_IPCONFIG_METHOD_OFF:
232 case CONNMAN_IPCONFIG_METHOD_MANUAL:
233 case CONNMAN_IPCONFIG_METHOD_DHCP:
234 case CONNMAN_IPCONFIG_METHOD_AUTO:
237 case CONNMAN_IPCONFIG_METHOD_FIXED:
238 connman_network_set_ipv6_method(modem->network,
239 modem->context->ipv6_method);
240 connman_network_set_ipaddress(modem->network,
241 modem->context->ipv6_address);
247 connman_network_set_connected(modem->network, TRUE);
250 static void set_disconnected(struct modem_data *modem)
252 DBG("%s", modem->path);
254 connman_network_set_connected(modem->network, FALSE);
257 typedef void (*set_property_cb)(struct modem_data *data,
258 connman_bool_t success);
259 typedef void (*get_properties_cb)(struct modem_data *data,
260 DBusMessageIter *dict);
262 struct property_info {
263 struct modem_data *modem;
265 const char *interface;
266 const char *property;
267 set_property_cb set_property_cb;
268 get_properties_cb get_properties_cb;
271 static void set_property_reply(DBusPendingCall *call, void *user_data)
273 struct property_info *info = user_data;
276 connman_bool_t success = TRUE;
278 DBG("%s path %s %s.%s", info->modem->path,
279 info->path, info->interface, info->property);
281 info->modem->call_set_property = NULL;
283 dbus_error_init(&error);
285 reply = dbus_pending_call_steal_reply(call);
287 if (dbus_set_error_from_message(&error, reply)) {
288 connman_error("Failed to change property: %s %s.%s: %s %s",
289 info->path, info->interface, info->property,
290 error.name, error.message);
291 dbus_error_free(&error);
295 if (info->set_property_cb != NULL)
296 (*info->set_property_cb)(info->modem, success);
298 dbus_message_unref(reply);
300 dbus_pending_call_unref(call);
303 static int set_property(struct modem_data *modem,
304 const char *path, const char *interface,
305 const char *property, int type, void *value,
306 set_property_cb notify)
308 DBusMessage *message;
309 DBusMessageIter iter;
310 struct property_info *info;
312 DBG("%s path %s %s.%s", modem->path, path, interface, property);
314 if (modem->call_set_property != NULL) {
315 connman_error("Pending SetProperty");
319 message = dbus_message_new_method_call(OFONO_SERVICE, path,
320 interface, SET_PROPERTY);
324 dbus_message_iter_init_append(message, &iter);
325 connman_dbus_property_append_basic(&iter, property, type, value);
327 if (dbus_connection_send_with_reply(connection, message,
328 &modem->call_set_property, TIMEOUT) == FALSE) {
329 connman_error("Failed to change property: %s %s.%s",
330 path, interface, property);
331 dbus_message_unref(message);
335 if (modem->call_set_property == NULL) {
336 connman_error("D-Bus connection not available");
337 dbus_message_unref(message);
341 info = g_try_new0(struct property_info, 1);
343 dbus_message_unref(message);
349 info->interface = interface;
350 info->property = property;
351 info->set_property_cb = notify;
353 dbus_pending_call_set_notify(modem->call_set_property,
354 set_property_reply, info, g_free);
356 dbus_message_unref(message);
361 static void get_properties_reply(DBusPendingCall *call, void *user_data)
363 struct property_info *info = user_data;
364 DBusMessageIter array, dict;
368 DBG("%s path %s %s", info->modem->path, info->path, info->interface);
370 info->modem->call_get_properties = NULL;
372 dbus_error_init(&error);
374 reply = dbus_pending_call_steal_reply(call);
376 if (dbus_set_error_from_message(&error, reply)) {
377 connman_error("Failed to get properties: %s %s: %s %s",
378 info->path, info->interface,
379 error.name, error.message);
380 dbus_error_free(&error);
385 if (dbus_message_iter_init(reply, &array) == FALSE)
388 if (dbus_message_iter_get_arg_type(&array) != DBUS_TYPE_ARRAY)
391 dbus_message_iter_recurse(&array, &dict);
393 if (info->get_properties_cb != NULL)
394 (*info->get_properties_cb)(info->modem, &dict);
398 dbus_message_unref(reply);
400 dbus_pending_call_unref(call);
403 static int get_properties(const char *path, const char *interface,
404 get_properties_cb notify,
405 struct modem_data *modem)
407 DBusMessage *message;
408 struct property_info *info;
410 DBG("%s path %s %s", modem->path, path, interface);
412 if (modem->call_get_properties != NULL) {
413 connman_error("Pending GetProperties");
417 message = dbus_message_new_method_call(OFONO_SERVICE, path,
418 interface, GET_PROPERTIES);
422 if (dbus_connection_send_with_reply(connection, message,
423 &modem->call_get_properties, TIMEOUT) == FALSE) {
424 connman_error("Failed to call %s.GetProperties()", interface);
425 dbus_message_unref(message);
429 if (modem->call_get_properties == NULL) {
430 connman_error("D-Bus connection not available");
431 dbus_message_unref(message);
435 info = g_try_new0(struct property_info, 1);
437 dbus_message_unref(message);
443 info->interface = interface;
444 info->get_properties_cb = notify;
446 dbus_pending_call_set_notify(modem->call_get_properties,
447 get_properties_reply, info, g_free);
449 dbus_message_unref(message);
454 static void context_set_active_reply(struct modem_data *modem,
455 connman_bool_t success)
457 DBG("%s", modem->path);
459 if (success == TRUE) {
461 * Don't handle do anything on success here. oFono will send
462 * the change via PropertyChanged singal.
468 * Active = True might fail due a timeout. That means oFono
469 * still tries to go online. If we retry to set Active = True,
470 * we just get a InProgress error message. Should we power
471 * cycle the modem in such cases?
474 connman_network_set_error(modem->network,
475 CONNMAN_NETWORK_ERROR_ASSOCIATE_FAIL);
478 static int context_set_active(struct modem_data *modem)
480 dbus_bool_t active = TRUE;
482 DBG("%s", modem->path);
484 return set_property(modem, modem->context->path,
485 OFONO_CONTEXT_INTERFACE,
486 "Active", DBUS_TYPE_BOOLEAN,
488 context_set_active_reply);
491 static int context_set_inactive(struct modem_data *modem)
493 dbus_bool_t active = FALSE;
496 DBG("%s", modem->path);
498 err = set_property(modem, modem->context->path,
499 OFONO_CONTEXT_INTERFACE,
500 "Active", DBUS_TYPE_BOOLEAN,
503 if (err == -EINPROGRESS)
509 static void modem_set_online_reply(struct modem_data *modem,
510 connman_bool_t success)
512 DBG("%s", modem->path);
514 if (success == TRUE) {
516 * Don't handle do anything on success here. oFono will send
517 * the change via PropertyChanged singal.
522 modem->set_online = FALSE;
525 static int modem_set_online(struct modem_data *modem)
527 DBG("%s", modem->path);
529 modem->set_online = TRUE;
531 return set_property(modem, modem->path,
532 OFONO_MODEM_INTERFACE,
533 "Online", DBUS_TYPE_BOOLEAN,
535 modem_set_online_reply);
538 static void cm_set_powered_reply(struct modem_data *modem,
539 connman_bool_t success)
541 DBG("%s", modem->path);
543 if (success == TRUE) {
545 * Don't handle do anything on success here. oFono will send
546 * the change via PropertyChanged singal.
551 modem->set_cm_powered = FALSE;
554 static int cm_set_powered(struct modem_data *modem)
556 DBG("%s", modem->path);
558 modem->set_cm_powered = TRUE;
560 return set_property(modem, modem->path,
562 "Powered", DBUS_TYPE_BOOLEAN,
563 &modem->set_cm_powered,
564 cm_set_powered_reply);
567 static int modem_set_powered(struct modem_data *modem)
569 DBG("%s", modem->path);
571 modem->set_powered = TRUE;
573 return set_property(modem, modem->path,
574 OFONO_MODEM_INTERFACE,
575 "Powered", DBUS_TYPE_BOOLEAN,
580 static int modem_set_unpowered(struct modem_data *modem)
582 DBG("%s", modem->path);
584 modem->set_powered = FALSE;
586 return set_property(modem, modem->path,
587 OFONO_MODEM_INTERFACE,
588 "Powered", DBUS_TYPE_BOOLEAN,
593 static connman_bool_t has_interface(uint8_t interfaces,
596 if ((interfaces & api) == api)
602 static uint8_t extract_interfaces(DBusMessageIter *array)
604 DBusMessageIter entry;
605 uint8_t interfaces = 0;
607 dbus_message_iter_recurse(array, &entry);
609 while (dbus_message_iter_get_arg_type(&entry) == DBUS_TYPE_STRING) {
612 dbus_message_iter_get_basic(&entry, &name);
614 if (g_str_equal(name, OFONO_SIM_INTERFACE) == TRUE)
615 interfaces |= OFONO_API_SIM;
616 else if (g_str_equal(name, OFONO_NETREG_INTERFACE) == TRUE)
617 interfaces |= OFONO_API_NETREG;
618 else if (g_str_equal(name, OFONO_CM_INTERFACE) == TRUE)
619 interfaces |= OFONO_API_CM;
621 dbus_message_iter_next(&entry);
627 static char *extract_nameservers(DBusMessageIter *array)
629 DBusMessageIter entry;
630 char *nameservers = NULL;
633 dbus_message_iter_recurse(array, &entry);
635 while (dbus_message_iter_get_arg_type(&entry) == DBUS_TYPE_STRING) {
636 const char *nameserver;
638 dbus_message_iter_get_basic(&entry, &nameserver);
640 if (nameservers == NULL) {
641 nameservers = g_strdup(nameserver);
644 nameservers = g_strdup_printf("%s %s", tmp, nameserver);
648 dbus_message_iter_next(&entry);
654 static void extract_ipv4_settings(DBusMessageIter *array,
655 struct network_context *context)
657 DBusMessageIter dict;
658 char *address = NULL, *netmask = NULL, *gateway = NULL;
659 char *nameservers = NULL;
660 const char *interface = NULL;
663 if (dbus_message_iter_get_arg_type(array) != DBUS_TYPE_ARRAY)
666 dbus_message_iter_recurse(array, &dict);
668 while (dbus_message_iter_get_arg_type(&dict) == DBUS_TYPE_DICT_ENTRY) {
669 DBusMessageIter entry, value;
670 const char *key, *val;
672 dbus_message_iter_recurse(&dict, &entry);
673 dbus_message_iter_get_basic(&entry, &key);
675 dbus_message_iter_next(&entry);
676 dbus_message_iter_recurse(&entry, &value);
678 if (g_str_equal(key, "Interface") == TRUE) {
679 dbus_message_iter_get_basic(&value, &interface);
681 DBG("Interface %s", interface);
683 index = connman_inet_ifindex(interface);
685 DBG("index %d", index);
686 } else if (g_str_equal(key, "Method") == TRUE) {
687 dbus_message_iter_get_basic(&value, &val);
689 DBG("Method %s", val);
691 if (g_strcmp0(val, "static") == 0) {
692 context->ipv4_method = CONNMAN_IPCONFIG_METHOD_FIXED;
693 } else if (g_strcmp0(val, "dhcp") == 0) {
694 context->ipv4_method = CONNMAN_IPCONFIG_METHOD_DHCP;
697 } else if (g_str_equal(key, "Address") == TRUE) {
698 dbus_message_iter_get_basic(&value, &val);
700 address = g_strdup(val);
702 DBG("Address %s", address);
703 } else if (g_str_equal(key, "Netmask") == TRUE) {
704 dbus_message_iter_get_basic(&value, &val);
706 netmask = g_strdup(val);
708 DBG("Netmask %s", netmask);
709 } else if (g_str_equal(key, "DomainNameServers") == TRUE) {
710 nameservers = extract_nameservers(&value);
712 DBG("Nameservers %s", nameservers);
713 } else if (g_str_equal(key, "Gateway") == TRUE) {
714 dbus_message_iter_get_basic(&value, &val);
716 gateway = g_strdup(val);
718 DBG("Gateway %s", gateway);
721 dbus_message_iter_next(&dict);
727 if (context->ipv4_method != CONNMAN_IPCONFIG_METHOD_FIXED)
730 context->ipv4_address = connman_ipaddress_alloc(CONNMAN_IPCONFIG_TYPE_IPV4);
731 if (context->ipv4_address == NULL)
734 context->index = index;
735 connman_ipaddress_set_ipv4(context->ipv4_address, address,
738 context->ipv4_nameservers = nameservers;
741 if (context->ipv4_nameservers != nameservers)
749 static void extract_ipv6_settings(DBusMessageIter *array,
750 struct network_context *context)
752 DBusMessageIter dict;
753 char *address = NULL, *gateway = NULL;
754 unsigned char prefix_length;
755 char *nameservers = NULL;
756 const char *interface = NULL;
759 if (dbus_message_iter_get_arg_type(array) != DBUS_TYPE_ARRAY)
762 dbus_message_iter_recurse(array, &dict);
764 while (dbus_message_iter_get_arg_type(&dict) == DBUS_TYPE_DICT_ENTRY) {
765 DBusMessageIter entry, value;
766 const char *key, *val;
768 dbus_message_iter_recurse(&dict, &entry);
769 dbus_message_iter_get_basic(&entry, &key);
771 dbus_message_iter_next(&entry);
772 dbus_message_iter_recurse(&entry, &value);
774 if (g_str_equal(key, "Interface") == TRUE) {
775 dbus_message_iter_get_basic(&value, &interface);
777 DBG("Interface %s", interface);
779 index = connman_inet_ifindex(interface);
781 DBG("index %d", index);
782 } else if (g_str_equal(key, "Address") == TRUE) {
783 dbus_message_iter_get_basic(&value, &val);
785 address = g_strdup(val);
787 DBG("Address %s", address);
788 } else if (g_str_equal(key, "PrefixLength") == TRUE) {
789 dbus_message_iter_get_basic(&value, &prefix_length);
791 DBG("prefix length %d", prefix_length);
792 } else if (g_str_equal(key, "DomainNameServers") == TRUE) {
793 nameservers = extract_nameservers(&value);
795 DBG("Nameservers %s", nameservers);
796 } else if (g_str_equal(key, "Gateway") == TRUE) {
797 dbus_message_iter_get_basic(&value, &val);
799 gateway = g_strdup(val);
801 DBG("Gateway %s", gateway);
804 dbus_message_iter_next(&dict);
810 context->ipv6_method = CONNMAN_IPCONFIG_METHOD_FIXED;
812 context->ipv6_address =
813 connman_ipaddress_alloc(CONNMAN_IPCONFIG_TYPE_IPV6);
814 if (context->ipv6_address == NULL)
817 context->index = index;
818 connman_ipaddress_set_ipv6(context->ipv6_address, address,
819 prefix_length, gateway);
821 context->ipv6_nameservers = nameservers;
824 if (context->ipv6_nameservers != nameservers)
831 static connman_bool_t ready_to_create_device(struct modem_data *modem)
834 * There are three different modem types which behave slightly
836 * - GSM modems will expose the SIM interface then the
838 * - DUN modems will expose first a unique serial number (BDADDR)
839 * and then the CM interface.
840 * - CDMA modems will expose CM first and sometime later
841 * a unique serial number.
843 * This functions tests if we have the necessary information gathered
844 * before we are able to create a device.
847 if (modem->device != NULL)
850 if (modem->imsi != NULL || modem->serial != NULL)
856 static void create_device(struct modem_data *modem)
858 struct connman_device *device;
859 char *uninitialized_var(ident);
861 DBG("%s", modem->path);
863 if (modem->imsi != NULL)
865 else if (modem->serial != NULL)
866 ident = modem->serial;
868 if (connman_dbus_validate_ident(ident) == FALSE)
869 ident = connman_dbus_encode_string(ident);
871 ident = g_strdup(ident);
873 device = connman_device_create(ident, CONNMAN_DEVICE_TYPE_CELLULAR);
877 DBG("device %p", device);
879 connman_device_set_ident(device, ident);
881 connman_device_set_string(device, "Path", modem->path);
883 connman_device_set_data(device, modem);
885 if (connman_device_register(device) < 0) {
886 connman_error("Failed to register cellular device");
887 connman_device_unref(device);
891 modem->device = device;
897 static void destroy_device(struct modem_data *modem)
899 DBG("%s", modem->path);
901 connman_device_set_powered(modem->device, FALSE);
903 if (modem->network != NULL) {
904 connman_device_remove_network(modem->device, modem->network);
905 connman_network_unref(modem->network);
906 modem->network = NULL;
909 connman_device_unregister(modem->device);
910 connman_device_unref(modem->device);
912 modem->device = NULL;
915 static void add_network(struct modem_data *modem)
919 DBG("%s", modem->path);
921 if (modem->network != NULL)
924 modem->network = connman_network_create(modem->context->path,
925 CONNMAN_NETWORK_TYPE_CELLULAR);
926 if (modem->network == NULL)
929 DBG("network %p", modem->network);
931 connman_network_set_data(modem->network, modem);
933 connman_network_set_string(modem->network, "Path",
934 modem->context->path);
936 connman_network_set_index(modem->network, modem->context->index);
938 if (modem->name != NULL)
939 connman_network_set_name(modem->network, modem->name);
941 connman_network_set_name(modem->network, "");
943 connman_network_set_strength(modem->network, modem->strength);
945 group = get_ident(modem->context->path);
946 connman_network_set_group(modem->network, group);
948 connman_network_set_available(modem->network, TRUE);
950 connman_network_set_roaming(modem->network, modem->roaming);
952 if (connman_device_add_network(modem->device, modem->network) < 0) {
953 connman_network_unref(modem->network);
954 modem->network = NULL;
959 static int add_cm_context(struct modem_data *modem, const char *context_path,
960 DBusMessageIter *dict)
962 const char *context_type;
963 struct network_context *context = NULL;
964 connman_bool_t active = FALSE;
966 DBG("%s context path %s", modem->path, context_path);
968 if (modem->context != NULL) {
970 * We have already assigned a context to this modem
971 * and we do only support one Internet context.
976 context = network_context_alloc(context_path);
980 while (dbus_message_iter_get_arg_type(dict) == DBUS_TYPE_DICT_ENTRY) {
981 DBusMessageIter entry, value;
984 dbus_message_iter_recurse(dict, &entry);
985 dbus_message_iter_get_basic(&entry, &key);
987 dbus_message_iter_next(&entry);
988 dbus_message_iter_recurse(&entry, &value);
990 if (g_str_equal(key, "Type") == TRUE) {
991 dbus_message_iter_get_basic(&value, &context_type);
993 DBG("%s context %s type %s", modem->path,
994 context_path, context_type);
995 } else if (g_str_equal(key, "Settings") == TRUE) {
996 DBG("%s Settings", modem->path);
998 extract_ipv4_settings(&value, context);
999 } else if (g_str_equal(key, "IPv6.Settings") == TRUE) {
1000 DBG("%s IPv6.Settings", modem->path);
1002 extract_ipv6_settings(&value, context);
1003 } else if (g_str_equal(key, "Active") == TRUE) {
1004 dbus_message_iter_get_basic(&value, &active);
1006 DBG("%s Active %d", modem->path, active);
1009 dbus_message_iter_next(dict);
1012 if (g_strcmp0(context_type, "internet") != 0) {
1013 network_context_free(context);
1017 modem->context = context;
1018 modem->active = active;
1020 g_hash_table_replace(context_hash, g_strdup(context_path), modem);
1025 static void remove_cm_context(struct modem_data *modem,
1026 const char *context_path)
1028 if (modem->context == NULL)
1031 g_hash_table_remove(context_hash, context_path);
1033 network_context_free(modem->context);
1034 modem->context = NULL;
1037 static gboolean context_changed(DBusConnection *connection,
1038 DBusMessage *message,
1041 const char *context_path = dbus_message_get_path(message);
1042 struct modem_data *modem = NULL;
1043 DBusMessageIter iter, value;
1046 DBG("context_path %s", context_path);
1048 modem = g_hash_table_lookup(context_hash, context_path);
1052 if (dbus_message_iter_init(message, &iter) == FALSE)
1055 dbus_message_iter_get_basic(&iter, &key);
1057 dbus_message_iter_next(&iter);
1058 dbus_message_iter_recurse(&iter, &value);
1061 * oFono guarantees the ordering of Settings and
1062 * Active. Settings will always be send before Active = True.
1063 * That means we don't have to order here.
1065 if (g_str_equal(key, "Settings") == TRUE) {
1066 DBG("%s Settings", modem->path);
1068 extract_ipv4_settings(&value, modem->context);
1069 } else if (g_str_equal(key, "IPv6.Settings") == TRUE) {
1070 DBG("%s IPv6.Settings", modem->path);
1072 extract_ipv6_settings(&value, modem->context);
1073 } else if (g_str_equal(key, "Active") == TRUE) {
1074 dbus_message_iter_get_basic(&value, &modem->active);
1076 DBG("%s Active %d", modem->path, modem->active);
1078 if (modem->active == TRUE)
1079 set_connected(modem);
1081 set_disconnected(modem);
1087 static void cm_get_contexts_reply(DBusPendingCall *call, void *user_data)
1089 struct modem_data *modem = user_data;
1090 DBusMessageIter array, dict, entry, value;
1094 DBG("%s", modem->path);
1096 modem->call_get_contexts = NULL;
1098 reply = dbus_pending_call_steal_reply(call);
1100 dbus_error_init(&error);
1102 if (dbus_set_error_from_message(&error, reply) == TRUE) {
1103 connman_error("%s", error.message);
1104 dbus_error_free(&error);
1108 if (dbus_message_iter_init(reply, &array) == FALSE)
1111 if (dbus_message_iter_get_arg_type(&array) != DBUS_TYPE_ARRAY)
1114 dbus_message_iter_recurse(&array, &dict);
1116 while (dbus_message_iter_get_arg_type(&dict) == DBUS_TYPE_STRUCT) {
1117 const char *context_path;
1119 dbus_message_iter_recurse(&dict, &entry);
1120 dbus_message_iter_get_basic(&entry, &context_path);
1122 dbus_message_iter_next(&entry);
1123 dbus_message_iter_recurse(&entry, &value);
1125 if (add_cm_context(modem, context_path, &value) == 0)
1128 dbus_message_iter_next(&dict);
1132 dbus_message_unref(reply);
1134 dbus_pending_call_unref(call);
1137 static int cm_get_contexts(struct modem_data *modem)
1139 DBusMessage *message;
1141 DBG("%s", modem->path);
1143 if (modem->call_get_contexts != NULL)
1146 message = dbus_message_new_method_call(OFONO_SERVICE, modem->path,
1147 OFONO_CM_INTERFACE, GET_CONTEXTS);
1148 if (message == NULL)
1151 if (dbus_connection_send_with_reply(connection, message,
1152 &modem->call_get_contexts, TIMEOUT) == FALSE) {
1153 connman_error("Failed to call GetContexts()");
1154 dbus_message_unref(message);
1158 if (modem->call_get_contexts == NULL) {
1159 connman_error("D-Bus connection not available");
1160 dbus_message_unref(message);
1164 dbus_pending_call_set_notify(modem->call_get_contexts,
1165 cm_get_contexts_reply,
1168 dbus_message_unref(message);
1170 return -EINPROGRESS;
1173 static gboolean cm_context_added(DBusConnection *connection,
1174 DBusMessage *message,
1177 const char *path = dbus_message_get_path(message);
1179 struct modem_data *modem;
1180 DBusMessageIter iter, properties;
1184 modem = g_hash_table_lookup(modem_hash, context_path);
1188 if (dbus_message_iter_init(message, &iter) == FALSE)
1191 dbus_message_iter_get_basic(&iter, &context_path);
1193 dbus_message_iter_next(&iter);
1194 dbus_message_iter_recurse(&iter, &properties);
1196 if (add_cm_context(modem, context_path, &properties) != 0)
1202 static gboolean cm_context_removed(DBusConnection *connection,
1203 DBusMessage *message,
1206 const char *path = dbus_message_get_path(message);
1207 const char *context_path;
1208 struct modem_data *modem;
1209 DBusMessageIter iter;
1211 DBG("context path %s", path);
1213 if (dbus_message_iter_init(message, &iter) == FALSE)
1216 dbus_message_iter_get_basic(&iter, &context_path);
1218 modem = g_hash_table_lookup(context_hash, context_path);
1222 remove_cm_context(modem, context_path);
1227 static void netreg_update_name(struct modem_data *modem,
1228 DBusMessageIter* value)
1232 dbus_message_iter_get_basic(value, &name);
1234 DBG("%s Name %s", modem->path, name);
1236 g_free(modem->name);
1237 modem->name = g_strdup(name);
1239 if (modem->network == NULL)
1242 connman_network_set_name(modem->network, modem->name);
1243 connman_network_update(modem->network);
1246 static void netreg_update_strength(struct modem_data *modem,
1247 DBusMessageIter *value)
1249 dbus_message_iter_get_basic(value, &modem->strength);
1251 DBG("%s Strength %d", modem->path, modem->strength);
1253 if (modem->network == NULL)
1256 connman_network_set_strength(modem->network, modem->strength);
1257 connman_network_update(modem->network);
1260 static void netreg_update_roaming(struct modem_data *modem,
1261 DBusMessageIter *value)
1264 connman_bool_t roaming;
1266 dbus_message_iter_get_basic(value, &status);
1268 if (g_str_equal(status, "roaming") == TRUE)
1273 if (roaming == modem->roaming)
1276 modem->roaming = roaming;
1278 if (modem->network == NULL)
1281 connman_network_set_bool(modem->network,
1282 "Roaming", modem->roaming);
1283 connman_network_update(modem->network);
1286 static gboolean netreg_changed(DBusConnection *connection, DBusMessage *message,
1289 const char *path = dbus_message_get_path(message);
1290 struct modem_data *modem;
1291 DBusMessageIter iter, value;
1294 modem = g_hash_table_lookup(modem_hash, path);
1298 if (modem->ignore == TRUE)
1301 if (dbus_message_iter_init(message, &iter) == FALSE)
1304 dbus_message_iter_get_basic(&iter, &key);
1306 dbus_message_iter_next(&iter);
1307 dbus_message_iter_recurse(&iter, &value);
1309 if (g_str_equal(key, "Name") == TRUE) {
1310 netreg_update_name(modem, &value);
1311 } else if (g_str_equal(key, "Strength") == TRUE) {
1312 netreg_update_strength(modem, &value);
1313 } else if (g_str_equal(key, "Status") == TRUE) {
1314 netreg_update_roaming(modem, &value);
1320 static void netreg_properties_reply(struct modem_data *modem,
1321 DBusMessageIter *dict)
1323 DBG("%s", modem->path);
1325 while (dbus_message_iter_get_arg_type(dict) == DBUS_TYPE_DICT_ENTRY) {
1326 DBusMessageIter entry, value;
1329 dbus_message_iter_recurse(dict, &entry);
1330 dbus_message_iter_get_basic(&entry, &key);
1332 dbus_message_iter_next(&entry);
1333 dbus_message_iter_recurse(&entry, &value);
1335 if (g_str_equal(key, "Name") == TRUE) {
1336 netreg_update_name(modem, &value);
1337 } else if (g_str_equal(key, "Strength") == TRUE) {
1338 netreg_update_strength(modem, &value);
1339 } else if (g_str_equal(key, "Status") == TRUE) {
1340 netreg_update_roaming(modem, &value);
1343 dbus_message_iter_next(dict);
1346 if (modem->context == NULL) {
1348 * netgreg_get_properties() was issued after we got
1349 * cm_get_contexts_reply() where we create the
1350 * context. Though before we got the
1351 * netreg_properties_reply the context was removed
1352 * again. Therefore we have to skip the network
1360 if (modem->active == TRUE)
1361 set_connected(modem);
1364 static int netreg_get_properties(struct modem_data *modem)
1366 return get_properties(modem->path, OFONO_NETREG_INTERFACE,
1367 netreg_properties_reply, modem);
1370 static gboolean cm_changed(DBusConnection *connection, DBusMessage *message,
1373 const char *path = dbus_message_get_path(message);
1374 struct modem_data *modem;
1375 DBusMessageIter iter, value;
1378 modem = g_hash_table_lookup(modem_hash, path);
1382 if (modem->ignore == TRUE)
1385 if (dbus_message_iter_init(message, &iter) == FALSE)
1388 dbus_message_iter_get_basic(&iter, &key);
1390 dbus_message_iter_next(&iter);
1391 dbus_message_iter_recurse(&iter, &value);
1393 if (g_str_equal(key, "Attached") == TRUE) {
1394 dbus_message_iter_get_basic(&value, &modem->attached);
1396 DBG("%s Attached %d", modem->path, modem->attached);
1398 if (modem->attached == TRUE) {
1399 if (has_interface(modem->interfaces,
1400 OFONO_API_NETREG) == TRUE) {
1401 netreg_get_properties(modem);
1404 } else if (g_str_equal(key, "Powered") == TRUE) {
1405 dbus_message_iter_get_basic(&value, &modem->cm_powered);
1407 DBG("%s ConnnectionManager Powered %d", modem->path,
1410 if (modem->cm_powered == FALSE)
1411 cm_set_powered(modem);
1417 static void cm_properties_reply(struct modem_data *modem, DBusMessageIter *dict)
1419 DBG("%s", modem->path);
1421 while (dbus_message_iter_get_arg_type(dict) == DBUS_TYPE_DICT_ENTRY) {
1422 DBusMessageIter entry, value;
1425 dbus_message_iter_recurse(dict, &entry);
1426 dbus_message_iter_get_basic(&entry, &key);
1428 dbus_message_iter_next(&entry);
1429 dbus_message_iter_recurse(&entry, &value);
1431 if (g_str_equal(key, "Attached") == TRUE) {
1432 dbus_message_iter_get_basic(&value, &modem->attached);
1434 DBG("%s Attached %d", modem->path,
1437 if (modem->attached == TRUE) {
1438 if (has_interface(modem->interfaces,
1439 OFONO_API_NETREG) == TRUE) {
1440 netreg_get_properties(modem);
1443 } else if (g_str_equal(key, "Powered") == TRUE) {
1444 dbus_message_iter_get_basic(&value, &modem->cm_powered);
1446 DBG("%s ConnnectionManager Powered %d", modem->path,
1449 if (modem->cm_powered == FALSE)
1450 cm_set_powered(modem);
1453 dbus_message_iter_next(dict);
1457 static int cm_get_properties(struct modem_data *modem)
1459 return get_properties(modem->path, OFONO_CM_INTERFACE,
1460 cm_properties_reply, modem);
1463 static void update_sim_imsi(struct modem_data *modem,
1466 DBG("%s imsi %s", modem->path, imsi);
1468 if (g_strcmp0(modem->imsi, imsi) == 0)
1471 g_free(modem->imsi);
1472 modem->imsi = g_strdup(imsi);
1475 static gboolean sim_changed(DBusConnection *connection, DBusMessage *message,
1478 const char *path = dbus_message_get_path(message);
1479 struct modem_data *modem;
1480 DBusMessageIter iter, value;
1483 modem = g_hash_table_lookup(modem_hash, path);
1487 if (modem->ignore == TRUE)
1490 if (dbus_message_iter_init(message, &iter) == FALSE)
1493 dbus_message_iter_get_basic(&iter, &key);
1495 dbus_message_iter_next(&iter);
1496 dbus_message_iter_recurse(&iter, &value);
1498 if (g_str_equal(key, "SubscriberIdentity") == TRUE) {
1501 dbus_message_iter_get_basic(&value, &imsi);
1503 update_sim_imsi(modem, imsi);
1505 if (modem->online == FALSE) {
1506 modem_set_online(modem);
1507 } else if (has_interface(modem->interfaces,
1508 OFONO_API_CM) == TRUE) {
1509 if (ready_to_create_device(modem) == TRUE)
1510 create_device(modem);
1517 static void sim_properties_reply(struct modem_data *modem,
1518 DBusMessageIter *dict)
1520 DBG("%s", modem->path);
1522 while (dbus_message_iter_get_arg_type(dict) == DBUS_TYPE_DICT_ENTRY) {
1523 DBusMessageIter entry, value;
1526 dbus_message_iter_recurse(dict, &entry);
1527 dbus_message_iter_get_basic(&entry, &key);
1529 dbus_message_iter_next(&entry);
1530 dbus_message_iter_recurse(&entry, &value);
1532 if (g_str_equal(key, "SubscriberIdentity") == TRUE) {
1535 dbus_message_iter_get_basic(&value, &imsi);
1537 update_sim_imsi(modem, imsi);
1539 if (modem->online == FALSE) {
1540 modem_set_online(modem);
1544 if (has_interface(modem->interfaces, OFONO_API_CM) == TRUE) {
1545 if (ready_to_create_device(modem) == TRUE)
1546 create_device(modem);
1547 if (modem->device != NULL) {
1548 cm_get_properties(modem);
1549 cm_get_contexts(modem);
1555 dbus_message_iter_next(dict);
1559 static int sim_get_properties(struct modem_data *modem)
1561 return get_properties(modem->path, OFONO_SIM_INTERFACE,
1562 sim_properties_reply, modem);
1565 static gboolean modem_changed(DBusConnection *connection, DBusMessage *message,
1568 const char *path = dbus_message_get_path(message);
1569 struct modem_data *modem;
1570 DBusMessageIter iter, value;
1573 modem = g_hash_table_lookup(modem_hash, path);
1577 if (modem->ignore == TRUE)
1580 if (dbus_message_iter_init(message, &iter) == FALSE)
1583 dbus_message_iter_get_basic(&iter, &key);
1585 dbus_message_iter_next(&iter);
1586 dbus_message_iter_recurse(&iter, &value);
1588 if (g_str_equal(key, "Powered") == TRUE) {
1589 dbus_message_iter_get_basic(&value, &modem->powered);
1591 DBG("%s Powered %d", modem->path, modem->powered);
1593 if (modem->powered == FALSE)
1594 modem_set_powered(modem);
1595 } else if (g_str_equal(key, "Online") == TRUE) {
1596 dbus_message_iter_get_basic(&value, &modem->online);
1598 DBG("%s Online %d", modem->path, modem->online);
1600 if (modem->online == FALSE)
1603 if (has_interface(modem->interfaces, OFONO_API_CM) == FALSE)
1605 if (ready_to_create_device(modem) == TRUE)
1606 create_device(modem);
1607 if (modem->device != NULL) {
1608 cm_get_properties(modem);
1609 cm_get_contexts(modem);
1611 } else if (g_str_equal(key, "Interfaces") == TRUE) {
1612 modem->interfaces = extract_interfaces(&value);
1614 DBG("%s Interfaces 0x%02x", modem->path,
1617 if (has_interface(modem->interfaces, OFONO_API_SIM) == TRUE) {
1618 if (modem->imsi == NULL &&
1619 modem->set_powered == FALSE) {
1621 * Only use do GetProperties() when
1622 * device has not been powered up.
1624 sim_get_properties(modem);
1629 if (has_interface(modem->interfaces, OFONO_API_CM) == TRUE) {
1630 if (ready_to_create_device(modem) == TRUE)
1631 create_device(modem);
1632 if (modem->device != NULL) {
1633 cm_get_properties(modem);
1634 cm_get_contexts(modem);
1638 if (modem->context != NULL) {
1639 remove_cm_context(modem,
1640 modem->context->path);
1643 if (modem->device != NULL)
1644 destroy_device(modem);
1649 if (has_interface(modem->interfaces, OFONO_API_NETREG) == TRUE) {
1650 if (modem->attached == TRUE)
1651 netreg_get_properties(modem);
1653 } else if (g_str_equal(key, "Serial") == TRUE) {
1656 dbus_message_iter_get_basic(&value, &serial);
1658 g_free(modem->serial);
1659 modem->serial = g_strdup(serial);
1661 DBG("%s Serial %s", modem->path, modem->serial);
1663 if (has_interface(modem->interfaces, OFONO_API_CM) == TRUE) {
1664 if (ready_to_create_device(modem) == TRUE)
1665 create_device(modem);
1666 if (modem->device != NULL) {
1667 cm_get_properties(modem);
1668 cm_get_contexts(modem);
1676 static void add_modem(const char *path, DBusMessageIter *prop)
1678 struct modem_data *modem;
1682 modem = g_hash_table_lookup(modem_hash, path);
1683 if (modem != NULL) {
1685 * When oFono powers up we ask for the modems and oFono is
1686 * reporting with modem_added signal the modems. Only
1692 modem = g_try_new0(struct modem_data, 1);
1696 modem->path = g_strdup(path);
1698 g_hash_table_insert(modem_hash, g_strdup(path), modem);
1700 while (dbus_message_iter_get_arg_type(prop) == DBUS_TYPE_DICT_ENTRY) {
1701 DBusMessageIter entry, value;
1704 dbus_message_iter_recurse(prop, &entry);
1705 dbus_message_iter_get_basic(&entry, &key);
1707 dbus_message_iter_next(&entry);
1708 dbus_message_iter_recurse(&entry, &value);
1710 if (g_str_equal(key, "Powered") == TRUE) {
1711 dbus_message_iter_get_basic(&value, &modem->powered);
1713 DBG("%s Powered %d", modem->path, modem->powered);
1714 } else if (g_str_equal(key, "Online") == TRUE) {
1715 dbus_message_iter_get_basic(&value, &modem->online);
1717 DBG("%s Online %d", modem->path, modem->online);
1718 } else if (g_str_equal(key, "Interfaces") == TRUE) {
1719 modem->interfaces = extract_interfaces(&value);
1721 DBG("%s Interfaces 0x%02x", modem->path,
1723 } else if (g_str_equal(key, "Serial") == TRUE) {
1726 dbus_message_iter_get_basic(&value, &serial);
1727 modem->serial = g_strdup(serial);
1729 DBG("%s Serial %s", modem->path, modem->serial);
1730 } else if (g_str_equal(key, "Type") == TRUE) {
1733 dbus_message_iter_get_basic(&value, &type);
1735 DBG("%s Type %s", modem->path, type);
1736 if (g_strcmp0(type, "hardware") != 0) {
1737 DBG("%s Ignore this modem", modem->path);
1738 modem->ignore = TRUE;
1742 dbus_message_iter_next(prop);
1745 if (modem->ignore == TRUE)
1748 if (modem->powered == FALSE) {
1749 modem_set_powered(modem);
1750 } else if (has_interface(modem->interfaces, OFONO_API_SIM) == TRUE) {
1751 sim_get_properties(modem);
1752 } else if (has_interface(modem->interfaces, OFONO_API_CM) == TRUE) {
1753 if (ready_to_create_device(modem) == TRUE)
1754 create_device(modem);
1755 if (modem->device != NULL) {
1756 cm_get_properties(modem);
1757 cm_get_contexts(modem);
1762 static void modem_power_down(gpointer key, gpointer value, gpointer user_data)
1764 struct modem_data *modem = value;
1766 DBG("%s", modem->path);
1768 if (modem->ignore == TRUE)
1771 modem_set_unpowered(modem);
1774 static void remove_modem(gpointer data)
1776 struct modem_data *modem = data;
1778 DBG("%s", modem->path);
1780 if (modem->call_set_property != NULL)
1781 dbus_pending_call_cancel(modem->call_set_property);
1783 if (modem->call_get_properties != NULL)
1784 dbus_pending_call_cancel(modem->call_get_properties);
1786 if (modem->call_get_contexts != NULL)
1787 dbus_pending_call_cancel(modem->call_get_contexts);
1789 if (modem->device != NULL)
1790 destroy_device(modem);
1792 if (modem->context != NULL)
1793 remove_cm_context(modem, modem->context->path);
1795 g_free(modem->serial);
1796 g_free(modem->name);
1797 g_free(modem->imsi);
1798 g_free(modem->path);
1803 static gboolean modem_added(DBusConnection *connection,
1804 DBusMessage *message, void *user_data)
1806 DBusMessageIter iter, properties;
1811 if (dbus_message_iter_init(message, &iter) == FALSE)
1814 dbus_message_iter_get_basic(&iter, &path);
1816 dbus_message_iter_next(&iter);
1817 dbus_message_iter_recurse(&iter, &properties);
1819 add_modem(path, &properties);
1824 static gboolean modem_removed(DBusConnection *connection,
1825 DBusMessage *message, void *user_data)
1827 DBusMessageIter iter;
1832 if (dbus_message_iter_init(message, &iter) == FALSE)
1835 dbus_message_iter_get_basic(&iter, &path);
1837 g_hash_table_remove(modem_hash, path);
1842 static void manager_get_modems_reply(DBusPendingCall *call, void *user_data)
1846 DBusMessageIter array, dict;
1850 reply = dbus_pending_call_steal_reply(call);
1852 dbus_error_init(&error);
1854 if (dbus_set_error_from_message(&error, reply) == TRUE) {
1855 connman_error("%s", error.message);
1856 dbus_error_free(&error);
1860 if (dbus_message_iter_init(reply, &array) == FALSE)
1863 dbus_message_iter_recurse(&array, &dict);
1865 while (dbus_message_iter_get_arg_type(&dict) == DBUS_TYPE_STRUCT) {
1866 DBusMessageIter value, properties;
1869 dbus_message_iter_recurse(&dict, &value);
1870 dbus_message_iter_get_basic(&value, &path);
1872 dbus_message_iter_next(&value);
1873 dbus_message_iter_recurse(&value, &properties);
1875 add_modem(path, &properties);
1877 dbus_message_iter_next(&dict);
1881 dbus_message_unref(reply);
1883 dbus_pending_call_unref(call);
1886 static int manager_get_modems(void)
1888 DBusMessage *message;
1889 DBusPendingCall *call;
1893 message = dbus_message_new_method_call(OFONO_SERVICE, "/",
1894 OFONO_MANAGER_INTERFACE, GET_MODEMS);
1895 if (message == NULL)
1898 if (dbus_connection_send_with_reply(connection, message,
1899 &call, TIMEOUT) == FALSE) {
1900 connman_error("Failed to call GetModems()");
1901 dbus_message_unref(message);
1906 connman_error("D-Bus connection not available");
1907 dbus_message_unref(message);
1911 dbus_pending_call_set_notify(call, manager_get_modems_reply,
1914 dbus_message_unref(message);
1916 return -EINPROGRESS;
1919 static void ofono_connect(DBusConnection *conn, void *user_data)
1923 modem_hash = g_hash_table_new_full(g_str_hash, g_str_equal,
1924 g_free, remove_modem);
1925 if (modem_hash == NULL)
1928 context_hash = g_hash_table_new_full(g_str_hash, g_str_equal,
1930 if (context_hash == NULL) {
1931 g_hash_table_destroy(modem_hash);
1935 manager_get_modems();
1938 static void ofono_disconnect(DBusConnection *conn, void *user_data)
1942 if (modem_hash == NULL || context_hash == NULL)
1945 g_hash_table_destroy(modem_hash);
1948 g_hash_table_destroy(context_hash);
1949 context_hash = NULL;
1952 static int network_probe(struct connman_network *network)
1954 struct modem_data *modem = connman_network_get_data(network);
1956 DBG("%s network %p", modem->path, network);
1961 static void network_remove(struct connman_network *network)
1963 struct modem_data *modem = connman_network_get_data(network);
1965 DBG("%s network %p", modem->path, network);
1968 static int network_connect(struct connman_network *network)
1970 struct modem_data *modem = connman_network_get_data(network);
1972 DBG("%s network %p", modem->path, network);
1974 return context_set_active(modem);
1977 static int network_disconnect(struct connman_network *network)
1979 struct modem_data *modem = connman_network_get_data(network);
1981 DBG("%s network %p", modem->path, network);
1983 return context_set_inactive(modem);
1986 static struct connman_network_driver network_driver = {
1988 .type = CONNMAN_NETWORK_TYPE_CELLULAR,
1989 .probe = network_probe,
1990 .remove = network_remove,
1991 .connect = network_connect,
1992 .disconnect = network_disconnect,
1995 static int modem_probe(struct connman_device *device)
1997 struct modem_data *modem = connman_device_get_data(device);
1999 DBG("%s device %p", modem->path, device);
2004 static void modem_remove(struct connman_device *device)
2006 struct modem_data *modem = connman_device_get_data(device);
2008 DBG("%s device %p", modem->path, device);
2011 static int modem_enable(struct connman_device *device)
2013 struct modem_data *modem = connman_device_get_data(device);
2015 DBG("%s device %p", modem->path, device);
2020 static int modem_disable(struct connman_device *device)
2022 struct modem_data *modem = connman_device_get_data(device);
2024 DBG("%s device %p", modem->path, device);
2029 static struct connman_device_driver modem_driver = {
2031 .type = CONNMAN_DEVICE_TYPE_CELLULAR,
2032 .probe = modem_probe,
2033 .remove = modem_remove,
2034 .enable = modem_enable,
2035 .disable = modem_disable,
2039 static guint modem_added_watch;
2040 static guint modem_removed_watch;
2041 static guint modem_watch;
2042 static guint cm_watch;
2043 static guint sim_watch;
2044 static guint context_added_watch;
2045 static guint context_removed_watch;
2046 static guint netreg_watch;
2047 static guint context_watch;
2049 static int ofono_init(void)
2055 connection = connman_dbus_get_connection();
2056 if (connection == NULL)
2059 watch = g_dbus_add_service_watch(connection,
2060 OFONO_SERVICE, ofono_connect,
2061 ofono_disconnect, NULL, NULL);
2063 modem_added_watch = g_dbus_add_signal_watch(connection, NULL, NULL,
2064 OFONO_MANAGER_INTERFACE,
2069 modem_removed_watch = g_dbus_add_signal_watch(connection, NULL, NULL,
2070 OFONO_MANAGER_INTERFACE,
2075 modem_watch = g_dbus_add_signal_watch(connection, NULL, NULL,
2076 OFONO_MODEM_INTERFACE,
2081 cm_watch = g_dbus_add_signal_watch(connection, NULL, NULL,
2087 sim_watch = g_dbus_add_signal_watch(connection, NULL, NULL,
2088 OFONO_SIM_INTERFACE,
2093 context_added_watch = g_dbus_add_signal_watch(connection, NULL, NULL,
2099 context_removed_watch = g_dbus_add_signal_watch(connection, NULL, NULL,
2105 context_watch = g_dbus_add_signal_watch(connection, NULL, NULL,
2106 OFONO_CONTEXT_INTERFACE,
2111 netreg_watch = g_dbus_add_signal_watch(connection, NULL, NULL,
2112 OFONO_NETREG_INTERFACE,
2118 if (watch == 0 || modem_added_watch == 0 || modem_removed_watch == 0 ||
2119 modem_watch == 0 || cm_watch == 0 || sim_watch == 0 ||
2120 context_added_watch == 0 ||
2121 context_removed_watch == 0 ||
2122 context_watch == 0 || netreg_watch == 0) {
2127 err = connman_network_driver_register(&network_driver);
2131 err = connman_device_driver_register(&modem_driver);
2133 connman_network_driver_unregister(&network_driver);
2140 g_dbus_remove_watch(connection, netreg_watch);
2141 g_dbus_remove_watch(connection, context_watch);
2142 g_dbus_remove_watch(connection, context_removed_watch);
2143 g_dbus_remove_watch(connection, context_added_watch);
2144 g_dbus_remove_watch(connection, sim_watch);
2145 g_dbus_remove_watch(connection, cm_watch);
2146 g_dbus_remove_watch(connection, modem_watch);
2147 g_dbus_remove_watch(connection, modem_removed_watch);
2148 g_dbus_remove_watch(connection, modem_added_watch);
2149 g_dbus_remove_watch(connection, watch);
2150 dbus_connection_unref(connection);
2155 static void ofono_exit(void)
2159 if (modem_hash != NULL) {
2161 * We should propably wait for the SetProperty() reply
2162 * message, because ...
2164 g_hash_table_foreach(modem_hash, modem_power_down, NULL);
2167 * ... here we will cancel the call.
2169 g_hash_table_destroy(modem_hash);
2173 if (context_hash != NULL) {
2174 g_hash_table_destroy(context_hash);
2175 context_hash = NULL;
2178 connman_device_driver_unregister(&modem_driver);
2179 connman_network_driver_unregister(&network_driver);
2181 g_dbus_remove_watch(connection, netreg_watch);
2182 g_dbus_remove_watch(connection, context_watch);
2183 g_dbus_remove_watch(connection, context_removed_watch);
2184 g_dbus_remove_watch(connection, context_added_watch);
2185 g_dbus_remove_watch(connection, sim_watch);
2186 g_dbus_remove_watch(connection, cm_watch);
2187 g_dbus_remove_watch(connection, modem_watch);
2188 g_dbus_remove_watch(connection, modem_added_watch);
2189 g_dbus_remove_watch(connection, modem_removed_watch);
2190 g_dbus_remove_watch(connection, watch);
2192 dbus_connection_unref(connection);
2195 CONNMAN_PLUGIN_DEFINE(ofono, "oFono telephony plugin", VERSION,
2196 CONNMAN_PLUGIN_PRIORITY_DEFAULT, ofono_init, ofono_exit)