5 * Copyright (C) 2007-2010 Intel Corporation. All rights reserved.
6 * Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License version 2 as
10 * published by the Free Software Foundation.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
34 #define CONNMAN_API_SUBJECT_TO_CHANGE
35 #include <connman/plugin.h>
36 #include <connman/device.h>
37 #include <connman/network.h>
38 #include <connman/inet.h>
39 #include <connman/dbus.h>
40 #include <connman/log.h>
42 #define uninitialized_var(x) x = x
44 #define OFONO_SERVICE "org.ofono"
46 #define OFONO_MANAGER_INTERFACE OFONO_SERVICE ".Manager"
47 #define OFONO_MODEM_INTERFACE OFONO_SERVICE ".Modem"
48 #define OFONO_SIM_INTERFACE OFONO_SERVICE ".SimManager"
49 #define OFONO_NETREG_INTERFACE OFONO_SERVICE ".NetworkRegistration"
50 #define OFONO_CM_INTERFACE OFONO_SERVICE ".ConnectionManager"
51 #define OFONO_CONTEXT_INTERFACE OFONO_SERVICE ".ConnectionContext"
53 #define MODEM_ADDED "ModemAdded"
54 #define MODEM_REMOVED "ModemRemoved"
55 #define PROPERTY_CHANGED "PropertyChanged"
56 #define CONTEXT_ADDED "ContextAdded"
57 #define CONTEXT_REMOVED "ContextRemoved"
59 #define GET_PROPERTIES "GetProperties"
60 #define SET_PROPERTY "SetProperty"
61 #define GET_MODEMS "GetModems"
62 #define GET_CONTEXTS "GetContexts"
68 OFONO_API_NETREG = 0x2,
72 static DBusConnection *connection;
74 static GHashTable *modem_hash;
75 static GHashTable *context_hash;
77 struct network_context {
81 enum connman_ipconfig_method ipv4_method;
82 struct connman_ipaddress *ipv4_address;
83 char *ipv4_nameservers;
85 enum connman_ipconfig_method ipv6_method;
86 struct connman_ipaddress *ipv6_address;
87 char *ipv6_nameservers;
93 struct connman_device *device;
94 struct connman_network *network;
96 struct network_context *context;
100 connman_bool_t powered;
101 connman_bool_t online;
103 connman_bool_t ignore;
105 connman_bool_t set_powered;
106 connman_bool_t set_online;
108 /* ConnectionManager Interface */
109 connman_bool_t attached;
110 connman_bool_t cm_powered;
112 connman_bool_t set_cm_powered;
114 /* ConnectionContext Interface */
115 connman_bool_t active;
116 connman_bool_t set_active;
118 /* SimManager Interface */
121 /* Netreg Interface */
126 DBusPendingCall *call_set_property;
127 DBusPendingCall *call_get_properties;
128 DBusPendingCall *call_get_contexts;
131 static char *get_ident(const char *path)
138 pos = strrchr(path, '/');
145 static struct network_context *network_context_alloc(const char *path)
147 struct network_context *context;
149 context = g_try_new0(struct network_context, 1);
153 context->path = g_strdup(path);
156 context->ipv4_method = CONNMAN_IPCONFIG_METHOD_UNKNOWN;
157 context->ipv4_address = NULL;
158 context->ipv4_nameservers = NULL;
160 context->ipv6_method = CONNMAN_IPCONFIG_METHOD_UNKNOWN;
161 context->ipv6_address = NULL;
162 context->ipv6_nameservers = NULL;
167 static void network_context_free(struct network_context *context)
169 g_free(context->path);
171 connman_ipaddress_free(context->ipv4_address);
172 g_free(context->ipv4_nameservers);
174 connman_ipaddress_free(context->ipv6_address);
175 g_free(context->ipv6_nameservers);
180 static void set_connected(struct modem_data *modem)
182 connman_bool_t setip = FALSE;
184 DBG("%s", modem->path);
186 connman_network_set_index(modem->network, modem->context->index);
188 switch (modem->context->ipv4_method) {
189 case CONNMAN_IPCONFIG_METHOD_UNKNOWN:
190 case CONNMAN_IPCONFIG_METHOD_OFF:
191 case CONNMAN_IPCONFIG_METHOD_MANUAL:
192 case CONNMAN_IPCONFIG_METHOD_AUTO:
195 case CONNMAN_IPCONFIG_METHOD_FIXED:
196 connman_network_set_ipv4_method(modem->network,
197 modem->context->ipv4_method);
198 connman_network_set_ipaddress(modem->network,
199 modem->context->ipv4_address);
200 connman_network_set_nameservers(modem->network,
201 modem->context->ipv4_nameservers);
205 case CONNMAN_IPCONFIG_METHOD_DHCP:
206 connman_network_set_ipv4_method(modem->network,
207 modem->context->ipv4_method);
212 switch (modem->context->ipv6_method) {
213 case CONNMAN_IPCONFIG_METHOD_UNKNOWN:
214 case CONNMAN_IPCONFIG_METHOD_OFF:
215 case CONNMAN_IPCONFIG_METHOD_MANUAL:
216 case CONNMAN_IPCONFIG_METHOD_DHCP:
217 case CONNMAN_IPCONFIG_METHOD_AUTO:
220 case CONNMAN_IPCONFIG_METHOD_FIXED:
221 connman_network_set_ipv6_method(modem->network,
222 modem->context->ipv6_method);
223 connman_network_set_ipaddress(modem->network,
224 modem->context->ipv6_address);
230 connman_network_set_connected(modem->network, TRUE);
233 static void set_disconnected(struct modem_data *modem)
235 DBG("%s", modem->path);
237 connman_network_set_connected(modem->network, FALSE);
240 typedef void (*set_property_cb)(struct modem_data *data,
241 connman_bool_t success);
242 typedef void (*get_properties_cb)(struct modem_data *data,
243 DBusMessageIter *dict);
245 struct property_info {
246 struct modem_data *modem;
248 const char *interface;
249 const char *property;
250 set_property_cb set_property_cb;
251 get_properties_cb get_properties_cb;
254 static void set_property_reply(DBusPendingCall *call, void *user_data)
256 struct property_info *info = user_data;
259 connman_bool_t success = TRUE;
261 DBG("%s path %s %s.%s", info->modem->path,
262 info->path, info->interface, info->property);
264 info->modem->call_set_property = NULL;
266 dbus_error_init(&error);
268 reply = dbus_pending_call_steal_reply(call);
270 if (dbus_set_error_from_message(&error, reply)) {
271 connman_error("Failed to change property: %s %s.%s: %s %s",
272 info->path, info->interface, info->property,
273 error.name, error.message);
274 dbus_error_free(&error);
278 if (info->set_property_cb != NULL)
279 (*info->set_property_cb)(info->modem, success);
281 dbus_message_unref(reply);
283 dbus_pending_call_unref(call);
286 static int set_property(struct modem_data *modem,
287 const char *path, const char *interface,
288 const char *property, int type, void *value,
289 set_property_cb notify)
291 DBusMessage *message;
292 DBusMessageIter iter;
293 struct property_info *info;
295 DBG("%s path %s %s.%s", modem->path, path, interface, property);
297 if (modem->call_set_property != NULL) {
298 connman_error("Pending SetProperty");
302 message = dbus_message_new_method_call(OFONO_SERVICE, path,
303 interface, SET_PROPERTY);
307 dbus_message_iter_init_append(message, &iter);
308 connman_dbus_property_append_basic(&iter, property, type, value);
310 if (dbus_connection_send_with_reply(connection, message,
311 &modem->call_set_property, TIMEOUT) == FALSE) {
312 connman_error("Failed to change property: %s %s.%s",
313 path, interface, property);
314 dbus_message_unref(message);
318 if (modem->call_set_property == NULL) {
319 connman_error("D-Bus connection not available");
320 dbus_message_unref(message);
324 info = g_try_new0(struct property_info, 1);
326 dbus_message_unref(message);
332 info->interface = interface;
333 info->property = property;
334 info->set_property_cb = notify;
336 dbus_pending_call_set_notify(modem->call_set_property,
337 set_property_reply, info, g_free);
339 dbus_message_unref(message);
344 static void get_properties_reply(DBusPendingCall *call, void *user_data)
346 struct property_info *info = user_data;
347 DBusMessageIter array, dict;
351 DBG("%s path %s %s", info->modem->path, info->path, info->interface);
353 info->modem->call_get_properties = NULL;
355 dbus_error_init(&error);
357 reply = dbus_pending_call_steal_reply(call);
359 if (dbus_set_error_from_message(&error, reply)) {
360 connman_error("Failed to get properties: %s %s: %s %s",
361 info->path, info->interface,
362 error.name, error.message);
363 dbus_error_free(&error);
368 if (dbus_message_iter_init(reply, &array) == FALSE)
371 if (dbus_message_iter_get_arg_type(&array) != DBUS_TYPE_ARRAY)
374 dbus_message_iter_recurse(&array, &dict);
376 if (info->get_properties_cb != NULL)
377 (*info->get_properties_cb)(info->modem, &dict);
381 dbus_message_unref(reply);
383 dbus_pending_call_unref(call);
386 static int get_properties(const char *path, const char *interface,
387 get_properties_cb notify,
388 struct modem_data *modem)
390 DBusMessage *message;
391 struct property_info *info;
393 DBG("%s path %s %s", modem->path, path, interface);
395 if (modem->call_get_properties != NULL) {
396 connman_error("Pending GetProperties");
400 message = dbus_message_new_method_call(OFONO_SERVICE, path,
401 interface, GET_PROPERTIES);
405 if (dbus_connection_send_with_reply(connection, message,
406 &modem->call_get_properties, TIMEOUT) == FALSE) {
407 connman_error("Failed to call %s.GetProperties()", interface);
408 dbus_message_unref(message);
412 if (modem->call_get_properties == NULL) {
413 connman_error("D-Bus connection not available");
414 dbus_message_unref(message);
418 info = g_try_new0(struct property_info, 1);
420 dbus_message_unref(message);
426 info->interface = interface;
427 info->get_properties_cb = notify;
429 dbus_pending_call_set_notify(modem->call_get_properties,
430 get_properties_reply, info, g_free);
432 dbus_message_unref(message);
437 static void context_set_active_reply(struct modem_data *modem,
438 connman_bool_t success)
440 DBG("%s", modem->path);
442 if (success == TRUE) {
444 * Don't handle do anything on success here. oFono will send
445 * the change via PropertyChanged singal.
451 * Active = True might fail due a timeout. That means oFono
452 * still tries to go online. If we retry to set Active = True,
453 * we just get a InProgress error message. Should we power
454 * cycle the modem in such cases?
457 connman_network_set_error(modem->network,
458 CONNMAN_NETWORK_ERROR_ASSOCIATE_FAIL);
461 static int context_set_active(struct modem_data *modem)
463 dbus_bool_t active = TRUE;
465 DBG("%s", modem->path);
467 return set_property(modem, modem->context->path,
468 OFONO_CONTEXT_INTERFACE,
469 "Active", DBUS_TYPE_BOOLEAN,
471 context_set_active_reply);
474 static int context_set_inactive(struct modem_data *modem)
476 dbus_bool_t active = FALSE;
479 DBG("%s", modem->path);
481 err = set_property(modem, modem->context->path,
482 OFONO_CONTEXT_INTERFACE,
483 "Active", DBUS_TYPE_BOOLEAN,
486 if (err == -EINPROGRESS)
492 static void modem_set_online_reply(struct modem_data *modem,
493 connman_bool_t success)
495 DBG("%s", modem->path);
497 if (success == TRUE) {
499 * Don't handle do anything on success here. oFono will send
500 * the change via PropertyChanged singal.
505 modem->set_online = FALSE;
508 static int modem_set_online(struct modem_data *modem)
510 DBG("%s", modem->path);
512 modem->set_online = TRUE;
514 return set_property(modem, modem->path,
515 OFONO_MODEM_INTERFACE,
516 "Online", DBUS_TYPE_BOOLEAN,
518 modem_set_online_reply);
521 static void cm_set_powered_reply(struct modem_data *modem,
522 connman_bool_t success)
524 DBG("%s", modem->path);
526 if (success == TRUE) {
528 * Don't handle do anything on success here. oFono will send
529 * the change via PropertyChanged singal.
534 modem->set_cm_powered = FALSE;
537 static int cm_set_powered(struct modem_data *modem)
539 DBG("%s", modem->path);
541 modem->set_cm_powered = TRUE;
543 return set_property(modem, modem->path,
545 "Powered", DBUS_TYPE_BOOLEAN,
546 &modem->set_cm_powered,
547 cm_set_powered_reply);
550 static int modem_set_powered(struct modem_data *modem)
552 DBG("%s", modem->path);
554 modem->set_powered = TRUE;
556 return set_property(modem, modem->path,
557 OFONO_MODEM_INTERFACE,
558 "Powered", DBUS_TYPE_BOOLEAN,
563 static int modem_set_unpowered(struct modem_data *modem)
565 DBG("%s", modem->path);
567 modem->set_powered = FALSE;
569 return set_property(modem, modem->path,
570 OFONO_MODEM_INTERFACE,
571 "Powered", DBUS_TYPE_BOOLEAN,
576 static connman_bool_t has_interface(uint8_t interfaces,
579 if ((interfaces & api) == api)
585 static uint8_t extract_interfaces(DBusMessageIter *array)
587 DBusMessageIter entry;
588 uint8_t interfaces = 0;
590 dbus_message_iter_recurse(array, &entry);
592 while (dbus_message_iter_get_arg_type(&entry) == DBUS_TYPE_STRING) {
595 dbus_message_iter_get_basic(&entry, &name);
597 if (g_str_equal(name, OFONO_SIM_INTERFACE) == TRUE)
598 interfaces |= OFONO_API_SIM;
599 else if (g_str_equal(name, OFONO_NETREG_INTERFACE) == TRUE)
600 interfaces |= OFONO_API_NETREG;
601 else if (g_str_equal(name, OFONO_CM_INTERFACE) == TRUE)
602 interfaces |= OFONO_API_CM;
604 dbus_message_iter_next(&entry);
610 static char *extract_nameservers(DBusMessageIter *array)
612 DBusMessageIter entry;
613 char *nameservers = NULL;
616 dbus_message_iter_recurse(array, &entry);
618 while (dbus_message_iter_get_arg_type(&entry) == DBUS_TYPE_STRING) {
619 const char *nameserver;
621 dbus_message_iter_get_basic(&entry, &nameserver);
623 if (nameservers == NULL) {
624 nameservers = g_strdup(nameserver);
627 nameservers = g_strdup_printf("%s %s", tmp, nameserver);
631 dbus_message_iter_next(&entry);
637 static void extract_ipv4_settings(DBusMessageIter *array,
638 struct network_context *context)
640 DBusMessageIter dict;
641 char *address = NULL, *netmask = NULL, *gateway = NULL;
642 char *nameservers = NULL;
643 const char *interface = NULL;
646 if (dbus_message_iter_get_arg_type(array) != DBUS_TYPE_ARRAY)
649 dbus_message_iter_recurse(array, &dict);
651 while (dbus_message_iter_get_arg_type(&dict) == DBUS_TYPE_DICT_ENTRY) {
652 DBusMessageIter entry, value;
653 const char *key, *val;
655 dbus_message_iter_recurse(&dict, &entry);
656 dbus_message_iter_get_basic(&entry, &key);
658 dbus_message_iter_next(&entry);
659 dbus_message_iter_recurse(&entry, &value);
661 if (g_str_equal(key, "Interface") == TRUE) {
662 dbus_message_iter_get_basic(&value, &interface);
664 DBG("Interface %s", interface);
666 index = connman_inet_ifindex(interface);
668 DBG("index %d", index);
669 } else if (g_str_equal(key, "Method") == TRUE) {
670 dbus_message_iter_get_basic(&value, &val);
672 DBG("Method %s", val);
674 if (g_strcmp0(val, "static") == 0) {
675 context->ipv4_method = CONNMAN_IPCONFIG_METHOD_FIXED;
676 } else if (g_strcmp0(val, "dhcp") == 0) {
677 context->ipv4_method = CONNMAN_IPCONFIG_METHOD_DHCP;
680 } else if (g_str_equal(key, "Address") == TRUE) {
681 dbus_message_iter_get_basic(&value, &val);
683 address = g_strdup(val);
685 DBG("Address %s", address);
686 } else if (g_str_equal(key, "Netmask") == TRUE) {
687 dbus_message_iter_get_basic(&value, &val);
689 netmask = g_strdup(val);
691 DBG("Netmask %s", netmask);
692 } else if (g_str_equal(key, "DomainNameServers") == TRUE) {
693 nameservers = extract_nameservers(&value);
695 DBG("Nameservers %s", nameservers);
696 } else if (g_str_equal(key, "Gateway") == TRUE) {
697 dbus_message_iter_get_basic(&value, &val);
699 gateway = g_strdup(val);
701 DBG("Gateway %s", gateway);
704 dbus_message_iter_next(&dict);
710 if (context->ipv4_method != CONNMAN_IPCONFIG_METHOD_FIXED)
713 context->ipv4_address = connman_ipaddress_alloc(CONNMAN_IPCONFIG_TYPE_IPV4);
714 if (context->ipv4_address == NULL)
717 context->index = index;
718 connman_ipaddress_set_ipv4(context->ipv4_address, address,
721 context->ipv4_nameservers = nameservers;
724 if (context->ipv4_nameservers != nameservers)
732 static void extract_ipv6_settings(DBusMessageIter *array,
733 struct network_context *context)
735 DBusMessageIter dict;
736 char *address = NULL, *gateway = NULL;
737 unsigned char prefix_length;
738 char *nameservers = NULL;
739 const char *interface = NULL;
742 if (dbus_message_iter_get_arg_type(array) != DBUS_TYPE_ARRAY)
745 dbus_message_iter_recurse(array, &dict);
747 while (dbus_message_iter_get_arg_type(&dict) == DBUS_TYPE_DICT_ENTRY) {
748 DBusMessageIter entry, value;
749 const char *key, *val;
751 dbus_message_iter_recurse(&dict, &entry);
752 dbus_message_iter_get_basic(&entry, &key);
754 dbus_message_iter_next(&entry);
755 dbus_message_iter_recurse(&entry, &value);
757 if (g_str_equal(key, "Interface") == TRUE) {
758 dbus_message_iter_get_basic(&value, &interface);
760 DBG("Interface %s", interface);
762 index = connman_inet_ifindex(interface);
764 DBG("index %d", index);
765 } else if (g_str_equal(key, "Address") == TRUE) {
766 dbus_message_iter_get_basic(&value, &val);
768 address = g_strdup(val);
770 DBG("Address %s", address);
771 } else if (g_str_equal(key, "PrefixLength") == TRUE) {
772 dbus_message_iter_get_basic(&value, &prefix_length);
774 DBG("prefix length %d", prefix_length);
775 } else if (g_str_equal(key, "DomainNameServers") == TRUE) {
776 nameservers = extract_nameservers(&value);
778 DBG("Nameservers %s", nameservers);
779 } else if (g_str_equal(key, "Gateway") == TRUE) {
780 dbus_message_iter_get_basic(&value, &val);
782 gateway = g_strdup(val);
784 DBG("Gateway %s", gateway);
787 dbus_message_iter_next(&dict);
793 context->ipv6_method = CONNMAN_IPCONFIG_METHOD_FIXED;
795 context->ipv6_address =
796 connman_ipaddress_alloc(CONNMAN_IPCONFIG_TYPE_IPV6);
797 if (context->ipv6_address == NULL)
800 context->index = index;
801 connman_ipaddress_set_ipv6(context->ipv6_address, address,
802 prefix_length, gateway);
804 context->ipv6_nameservers = nameservers;
807 if (context->ipv6_nameservers != nameservers)
814 static connman_bool_t ready_to_create_device(struct modem_data *modem)
817 * There are three different modem types which behave slightly
819 * - GSM modems will expose the SIM interface then the
821 * - DUN modems will expose first a unique serial number (BDADDR)
822 * and then the CM interface.
823 * - CDMA modems will expose CM first and sometime later
824 * a unique serial number.
826 * This functions tests if we have the necessary information gathered
827 * before we are able to create a device.
830 if (modem->device != NULL)
833 if (modem->imsi != NULL || modem->serial != NULL)
839 static void create_device(struct modem_data *modem)
841 struct connman_device *device;
842 char *uninitialized_var(ident);
844 DBG("%s", modem->path);
846 if (modem->imsi != NULL)
848 else if (modem->serial != NULL)
849 ident = modem->serial;
851 if (connman_dbus_validate_ident(ident) == FALSE)
852 ident = connman_dbus_encode_string(ident);
854 ident = g_strdup(ident);
856 device = connman_device_create(ident, CONNMAN_DEVICE_TYPE_CELLULAR);
860 DBG("device %p", device);
862 connman_device_set_ident(device, ident);
864 connman_device_set_string(device, "Path", modem->path);
866 connman_device_set_data(device, modem);
868 if (connman_device_register(device) < 0) {
869 connman_error("Failed to register cellular device");
870 connman_device_unref(device);
874 modem->device = device;
880 static void destroy_device(struct modem_data *modem)
882 DBG("%s", modem->path);
884 connman_device_set_powered(modem->device, FALSE);
886 if (modem->network != NULL) {
887 connman_device_remove_network(modem->device, modem->network);
888 connman_network_unref(modem->network);
889 modem->network = NULL;
892 connman_device_unregister(modem->device);
893 connman_device_unref(modem->device);
895 modem->device = NULL;
898 static void add_network(struct modem_data *modem)
902 DBG("%s", modem->path);
904 if (modem->network != NULL)
907 modem->network = connman_network_create(modem->context->path,
908 CONNMAN_NETWORK_TYPE_CELLULAR);
909 if (modem->network == NULL)
912 DBG("network %p", modem->network);
914 connman_network_set_data(modem->network, modem);
916 connman_network_set_string(modem->network, "Path",
917 modem->context->path);
919 connman_network_set_index(modem->network, modem->context->index);
921 if (modem->name != NULL)
922 connman_network_set_name(modem->network, modem->name);
924 connman_network_set_name(modem->network, "");
926 connman_network_set_strength(modem->network, modem->strength);
928 group = get_ident(modem->context->path);
929 connman_network_set_group(modem->network, group);
931 connman_network_set_available(modem->network, TRUE);
933 if (connman_device_add_network(modem->device, modem->network) < 0) {
934 connman_network_unref(modem->network);
935 modem->network = NULL;
940 static int add_cm_context(struct modem_data *modem, const char *context_path,
941 DBusMessageIter *dict)
943 const char *context_type;
944 struct network_context *context = NULL;
945 connman_bool_t active = FALSE;
947 DBG("%s context path %s", modem->path, context_path);
949 if (modem->context != NULL) {
951 * We have already assigned a context to this modem
952 * and we do only support one Internet context.
957 context = network_context_alloc(context_path);
961 while (dbus_message_iter_get_arg_type(dict) == DBUS_TYPE_DICT_ENTRY) {
962 DBusMessageIter entry, value;
965 dbus_message_iter_recurse(dict, &entry);
966 dbus_message_iter_get_basic(&entry, &key);
968 dbus_message_iter_next(&entry);
969 dbus_message_iter_recurse(&entry, &value);
971 if (g_str_equal(key, "Type") == TRUE) {
972 dbus_message_iter_get_basic(&value, &context_type);
974 DBG("%s context %s type %s", modem->path,
975 context_path, context_type);
976 } else if (g_str_equal(key, "Settings") == TRUE) {
977 DBG("%s Settings", modem->path);
979 extract_ipv4_settings(&value, context);
980 } else if (g_str_equal(key, "IPv6.Settings") == TRUE) {
981 DBG("%s IPv6.Settings", modem->path);
983 extract_ipv6_settings(&value, context);
984 } else if (g_str_equal(key, "Active") == TRUE) {
985 dbus_message_iter_get_basic(&value, &active);
987 DBG("%s Active %d", modem->path, active);
990 dbus_message_iter_next(dict);
993 if (g_strcmp0(context_type, "internet") != 0) {
994 network_context_free(context);
998 modem->context = context;
999 modem->active = active;
1001 g_hash_table_replace(context_hash, g_strdup(context_path), modem);
1006 static void remove_cm_context(struct modem_data *modem,
1007 const char *context_path)
1009 if (modem->context == NULL)
1012 g_hash_table_remove(context_hash, context_path);
1014 network_context_free(modem->context);
1015 modem->context = NULL;
1018 static gboolean context_changed(DBusConnection *connection,
1019 DBusMessage *message,
1022 const char *context_path = dbus_message_get_path(message);
1023 struct modem_data *modem = NULL;
1024 DBusMessageIter iter, value;
1027 DBG("context_path %s", context_path);
1029 modem = g_hash_table_lookup(context_hash, context_path);
1033 if (dbus_message_iter_init(message, &iter) == FALSE)
1036 dbus_message_iter_get_basic(&iter, &key);
1038 dbus_message_iter_next(&iter);
1039 dbus_message_iter_recurse(&iter, &value);
1042 * oFono guarantees the ordering of Settings and
1043 * Active. Settings will always be send before Active = True.
1044 * That means we don't have to order here.
1046 if (g_str_equal(key, "Settings") == TRUE) {
1047 DBG("%s Settings", modem->path);
1049 extract_ipv4_settings(&value, modem->context);
1050 } else if (g_str_equal(key, "IPv6.Settings") == TRUE) {
1051 DBG("%s IPv6.Settings", modem->path);
1053 extract_ipv6_settings(&value, modem->context);
1054 } else if (g_str_equal(key, "Active") == TRUE) {
1055 dbus_message_iter_get_basic(&value, &modem->active);
1057 DBG("%s Active %d", modem->path, modem->active);
1059 if (modem->active == TRUE)
1060 set_connected(modem);
1062 set_disconnected(modem);
1068 static void cm_get_contexts_reply(DBusPendingCall *call, void *user_data)
1070 struct modem_data *modem = user_data;
1071 DBusMessageIter array, dict, entry, value;
1075 DBG("%s", modem->path);
1077 modem->call_get_contexts = NULL;
1079 reply = dbus_pending_call_steal_reply(call);
1081 dbus_error_init(&error);
1083 if (dbus_set_error_from_message(&error, reply) == TRUE) {
1084 connman_error("%s", error.message);
1085 dbus_error_free(&error);
1089 if (dbus_message_iter_init(reply, &array) == FALSE)
1092 if (dbus_message_iter_get_arg_type(&array) != DBUS_TYPE_ARRAY)
1095 dbus_message_iter_recurse(&array, &dict);
1097 while (dbus_message_iter_get_arg_type(&dict) == DBUS_TYPE_STRUCT) {
1098 const char *context_path;
1100 dbus_message_iter_recurse(&dict, &entry);
1101 dbus_message_iter_get_basic(&entry, &context_path);
1103 dbus_message_iter_next(&entry);
1104 dbus_message_iter_recurse(&entry, &value);
1106 if (add_cm_context(modem, context_path, &value) == 0)
1109 dbus_message_iter_next(&dict);
1113 dbus_message_unref(reply);
1115 dbus_pending_call_unref(call);
1118 static int cm_get_contexts(struct modem_data *modem)
1120 DBusMessage *message;
1122 DBG("%s", modem->path);
1124 if (modem->call_get_contexts != NULL)
1127 message = dbus_message_new_method_call(OFONO_SERVICE, modem->path,
1128 OFONO_CM_INTERFACE, GET_CONTEXTS);
1129 if (message == NULL)
1132 if (dbus_connection_send_with_reply(connection, message,
1133 &modem->call_get_contexts, TIMEOUT) == FALSE) {
1134 connman_error("Failed to call GetContexts()");
1135 dbus_message_unref(message);
1139 if (modem->call_get_contexts == NULL) {
1140 connman_error("D-Bus connection not available");
1141 dbus_message_unref(message);
1145 dbus_pending_call_set_notify(modem->call_get_contexts,
1146 cm_get_contexts_reply,
1149 dbus_message_unref(message);
1151 return -EINPROGRESS;
1154 static gboolean cm_context_added(DBusConnection *connection,
1155 DBusMessage *message,
1158 const char *path = dbus_message_get_path(message);
1160 struct modem_data *modem;
1161 DBusMessageIter iter, properties;
1165 modem = g_hash_table_lookup(modem_hash, context_path);
1169 if (dbus_message_iter_init(message, &iter) == FALSE)
1172 dbus_message_iter_get_basic(&iter, &context_path);
1174 dbus_message_iter_next(&iter);
1175 dbus_message_iter_recurse(&iter, &properties);
1177 if (add_cm_context(modem, context_path, &properties) != 0)
1183 static gboolean cm_context_removed(DBusConnection *connection,
1184 DBusMessage *message,
1187 const char *path = dbus_message_get_path(message);
1188 const char *context_path;
1189 struct modem_data *modem;
1190 DBusMessageIter iter;
1192 DBG("context path %s", path);
1194 if (dbus_message_iter_init(message, &iter) == FALSE)
1197 dbus_message_iter_get_basic(&iter, &context_path);
1199 modem = g_hash_table_lookup(context_hash, context_path);
1203 remove_cm_context(modem, context_path);
1208 static gboolean netreg_changed(DBusConnection *connection, DBusMessage *message,
1211 const char *path = dbus_message_get_path(message);
1212 struct modem_data *modem;
1213 DBusMessageIter iter, value;
1216 modem = g_hash_table_lookup(modem_hash, path);
1220 if (modem->ignore == TRUE)
1223 if (dbus_message_iter_init(message, &iter) == FALSE)
1226 dbus_message_iter_get_basic(&iter, &key);
1228 dbus_message_iter_next(&iter);
1229 dbus_message_iter_recurse(&iter, &value);
1231 if (g_str_equal(key, "Name") == TRUE) {
1234 dbus_message_iter_get_basic(&value, &name);
1236 DBG("%s Name %s", modem->path, name);
1238 g_free(modem->name);
1239 modem->name = g_strdup(name);
1241 if (modem->network == NULL)
1244 connman_network_set_name(modem->network, modem->name);
1245 connman_network_update(modem->network);
1246 } else if (g_str_equal(key, "Strength") == TRUE) {
1247 dbus_message_iter_get_basic(&value, &modem->strength);
1249 DBG("%s Strength %d", modem->path, modem->strength);
1251 if (modem->network == NULL)
1254 connman_network_set_strength(modem->network, modem->strength);
1255 connman_network_update(modem->network);
1261 static void netreg_properties_reply(struct modem_data *modem,
1262 DBusMessageIter *dict)
1264 DBG("%s", modem->path);
1266 while (dbus_message_iter_get_arg_type(dict) == DBUS_TYPE_DICT_ENTRY) {
1267 DBusMessageIter entry, value;
1270 dbus_message_iter_recurse(dict, &entry);
1271 dbus_message_iter_get_basic(&entry, &key);
1273 dbus_message_iter_next(&entry);
1274 dbus_message_iter_recurse(&entry, &value);
1276 if (g_str_equal(key, "Name") == TRUE) {
1279 dbus_message_iter_get_basic(&value, &name);
1281 DBG("%s Name %s", modem->path, name);
1283 g_free(modem->name);
1284 modem->name = g_strdup(name);
1286 if (modem->network != NULL) {
1287 connman_network_set_name(modem->network,
1289 connman_network_update(modem->network);
1291 } else if (g_str_equal(key, "Strength") == TRUE) {
1292 dbus_message_iter_get_basic(&value, &modem->strength);
1294 DBG("%s Strength %d", modem->path,
1297 if (modem->network != NULL) {
1298 connman_network_set_strength(modem->network,
1300 connman_network_update(modem->network);
1304 dbus_message_iter_next(dict);
1307 if (modem->context == NULL) {
1309 * netgreg_get_properties() was issued after we got
1310 * cm_get_contexts_reply() where we create the
1311 * context. Though before we got the
1312 * netreg_properties_reply the context was removed
1313 * again. Therefore we have to skip the network
1321 if (modem->active == TRUE)
1322 set_connected(modem);
1325 static int netreg_get_properties(struct modem_data *modem)
1327 return get_properties(modem->path, OFONO_NETREG_INTERFACE,
1328 netreg_properties_reply, modem);
1331 static gboolean cm_changed(DBusConnection *connection, DBusMessage *message,
1334 const char *path = dbus_message_get_path(message);
1335 struct modem_data *modem;
1336 DBusMessageIter iter, value;
1339 modem = g_hash_table_lookup(modem_hash, path);
1343 if (modem->ignore == TRUE)
1346 if (dbus_message_iter_init(message, &iter) == FALSE)
1349 dbus_message_iter_get_basic(&iter, &key);
1351 dbus_message_iter_next(&iter);
1352 dbus_message_iter_recurse(&iter, &value);
1354 if (g_str_equal(key, "Attached") == TRUE) {
1355 dbus_message_iter_get_basic(&value, &modem->attached);
1357 DBG("%s Attached %d", modem->path, modem->attached);
1359 if (modem->attached == TRUE) {
1360 if (has_interface(modem->interfaces,
1361 OFONO_API_NETREG) == TRUE) {
1362 netreg_get_properties(modem);
1365 } else if (g_str_equal(key, "Powered") == TRUE) {
1366 dbus_message_iter_get_basic(&value, &modem->cm_powered);
1368 DBG("%s ConnnectionManager Powered %d", modem->path,
1371 if (modem->cm_powered == FALSE)
1372 cm_set_powered(modem);
1378 static void cm_properties_reply(struct modem_data *modem, DBusMessageIter *dict)
1380 DBG("%s", modem->path);
1382 while (dbus_message_iter_get_arg_type(dict) == DBUS_TYPE_DICT_ENTRY) {
1383 DBusMessageIter entry, value;
1386 dbus_message_iter_recurse(dict, &entry);
1387 dbus_message_iter_get_basic(&entry, &key);
1389 dbus_message_iter_next(&entry);
1390 dbus_message_iter_recurse(&entry, &value);
1392 if (g_str_equal(key, "Attached") == TRUE) {
1393 dbus_message_iter_get_basic(&value, &modem->attached);
1395 DBG("%s Attached %d", modem->path,
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);
1414 dbus_message_iter_next(dict);
1418 static int cm_get_properties(struct modem_data *modem)
1420 return get_properties(modem->path, OFONO_CM_INTERFACE,
1421 cm_properties_reply, modem);
1424 static void update_sim_imsi(struct modem_data *modem,
1427 DBG("%s imsi %s", modem->path, imsi);
1429 if (g_strcmp0(modem->imsi, imsi) == 0)
1432 g_free(modem->imsi);
1433 modem->imsi = g_strdup(imsi);
1436 static gboolean sim_changed(DBusConnection *connection, DBusMessage *message,
1439 const char *path = dbus_message_get_path(message);
1440 struct modem_data *modem;
1441 DBusMessageIter iter, value;
1444 modem = g_hash_table_lookup(modem_hash, path);
1448 if (modem->ignore == TRUE)
1451 if (dbus_message_iter_init(message, &iter) == FALSE)
1454 dbus_message_iter_get_basic(&iter, &key);
1456 dbus_message_iter_next(&iter);
1457 dbus_message_iter_recurse(&iter, &value);
1459 if (g_str_equal(key, "SubscriberIdentity") == TRUE) {
1462 dbus_message_iter_get_basic(&value, &imsi);
1464 update_sim_imsi(modem, imsi);
1466 if (modem->online == FALSE) {
1467 modem_set_online(modem);
1468 } else if (has_interface(modem->interfaces,
1469 OFONO_API_CM) == TRUE) {
1470 if (ready_to_create_device(modem) == TRUE)
1471 create_device(modem);
1478 static void sim_properties_reply(struct modem_data *modem,
1479 DBusMessageIter *dict)
1481 DBG("%s", modem->path);
1483 while (dbus_message_iter_get_arg_type(dict) == DBUS_TYPE_DICT_ENTRY) {
1484 DBusMessageIter entry, value;
1487 dbus_message_iter_recurse(dict, &entry);
1488 dbus_message_iter_get_basic(&entry, &key);
1490 dbus_message_iter_next(&entry);
1491 dbus_message_iter_recurse(&entry, &value);
1493 if (g_str_equal(key, "SubscriberIdentity") == TRUE) {
1496 dbus_message_iter_get_basic(&value, &imsi);
1498 update_sim_imsi(modem, imsi);
1500 if (modem->online == FALSE) {
1501 modem_set_online(modem);
1505 if (has_interface(modem->interfaces, OFONO_API_CM) == TRUE) {
1506 if (ready_to_create_device(modem) == TRUE)
1507 create_device(modem);
1508 if (modem->device != NULL) {
1509 cm_get_properties(modem);
1510 cm_get_contexts(modem);
1516 dbus_message_iter_next(dict);
1520 static int sim_get_properties(struct modem_data *modem)
1522 return get_properties(modem->path, OFONO_SIM_INTERFACE,
1523 sim_properties_reply, modem);
1526 static gboolean modem_changed(DBusConnection *connection, DBusMessage *message,
1529 const char *path = dbus_message_get_path(message);
1530 struct modem_data *modem;
1531 DBusMessageIter iter, value;
1534 modem = g_hash_table_lookup(modem_hash, path);
1538 if (modem->ignore == TRUE)
1541 if (dbus_message_iter_init(message, &iter) == FALSE)
1544 dbus_message_iter_get_basic(&iter, &key);
1546 dbus_message_iter_next(&iter);
1547 dbus_message_iter_recurse(&iter, &value);
1549 if (g_str_equal(key, "Powered") == TRUE) {
1550 dbus_message_iter_get_basic(&value, &modem->powered);
1552 DBG("%s Powered %d", modem->path, modem->powered);
1554 if (modem->powered == FALSE)
1555 modem_set_powered(modem);
1556 } else if (g_str_equal(key, "Online") == TRUE) {
1557 dbus_message_iter_get_basic(&value, &modem->online);
1559 DBG("%s Online %d", modem->path, modem->online);
1561 if (modem->online == FALSE)
1564 if (has_interface(modem->interfaces, OFONO_API_CM) == FALSE)
1566 if (ready_to_create_device(modem) == TRUE)
1567 create_device(modem);
1568 if (modem->device != NULL) {
1569 cm_get_properties(modem);
1570 cm_get_contexts(modem);
1572 } else if (g_str_equal(key, "Interfaces") == TRUE) {
1573 modem->interfaces = extract_interfaces(&value);
1575 DBG("%s Interfaces 0x%02x", modem->path,
1578 if (has_interface(modem->interfaces, OFONO_API_SIM) == TRUE) {
1579 if (modem->imsi == NULL &&
1580 modem->set_powered == FALSE) {
1582 * Only use do GetProperties() when
1583 * device has not been powered up.
1585 sim_get_properties(modem);
1590 if (has_interface(modem->interfaces, OFONO_API_CM) == TRUE) {
1591 if (ready_to_create_device(modem) == TRUE)
1592 create_device(modem);
1593 if (modem->device != NULL) {
1594 cm_get_properties(modem);
1595 cm_get_contexts(modem);
1599 if (modem->context != NULL) {
1600 remove_cm_context(modem,
1601 modem->context->path);
1604 if (modem->device != NULL)
1605 destroy_device(modem);
1610 if (has_interface(modem->interfaces, OFONO_API_NETREG) == TRUE) {
1611 if (modem->attached == TRUE)
1612 netreg_get_properties(modem);
1614 } else if (g_str_equal(key, "Serial") == TRUE) {
1617 dbus_message_iter_get_basic(&value, &serial);
1619 g_free(modem->serial);
1620 modem->serial = g_strdup(serial);
1622 DBG("%s Serial %s", modem->path, modem->serial);
1624 if (has_interface(modem->interfaces, OFONO_API_CM) == TRUE) {
1625 if (ready_to_create_device(modem) == TRUE)
1626 create_device(modem);
1627 if (modem->device != NULL) {
1628 cm_get_properties(modem);
1629 cm_get_contexts(modem);
1637 static void add_modem(const char *path, DBusMessageIter *prop)
1639 struct modem_data *modem;
1643 modem = g_hash_table_lookup(modem_hash, path);
1644 if (modem != NULL) {
1646 * When oFono powers up we ask for the modems and oFono is
1647 * reporting with modem_added signal the modems. Only
1653 modem = g_try_new0(struct modem_data, 1);
1657 modem->path = g_strdup(path);
1659 g_hash_table_insert(modem_hash, g_strdup(path), modem);
1661 while (dbus_message_iter_get_arg_type(prop) == DBUS_TYPE_DICT_ENTRY) {
1662 DBusMessageIter entry, value;
1665 dbus_message_iter_recurse(prop, &entry);
1666 dbus_message_iter_get_basic(&entry, &key);
1668 dbus_message_iter_next(&entry);
1669 dbus_message_iter_recurse(&entry, &value);
1671 if (g_str_equal(key, "Powered") == TRUE) {
1672 dbus_message_iter_get_basic(&value, &modem->powered);
1674 DBG("%s Powered %d", modem->path, modem->powered);
1675 } else if (g_str_equal(key, "Online") == TRUE) {
1676 dbus_message_iter_get_basic(&value, &modem->online);
1678 DBG("%s Online %d", modem->path, modem->online);
1679 } else if (g_str_equal(key, "Interfaces") == TRUE) {
1680 modem->interfaces = extract_interfaces(&value);
1682 DBG("%s Interfaces 0x%02x", modem->path,
1684 } else if (g_str_equal(key, "Serial") == TRUE) {
1687 dbus_message_iter_get_basic(&value, &serial);
1688 modem->serial = g_strdup(serial);
1690 DBG("%s Serial %s", modem->path, modem->serial);
1691 } else if (g_str_equal(key, "Type") == TRUE) {
1694 dbus_message_iter_get_basic(&value, &type);
1696 DBG("%s Type %s", modem->path, type);
1697 if (g_strcmp0(type, "hardware") != 0) {
1698 DBG("%s Ignore this modem", modem->path);
1699 modem->ignore = TRUE;
1703 dbus_message_iter_next(prop);
1706 if (modem->ignore == TRUE)
1709 if (modem->powered == FALSE) {
1710 modem_set_powered(modem);
1711 } else if (has_interface(modem->interfaces, OFONO_API_SIM) == TRUE) {
1712 sim_get_properties(modem);
1713 } else if (has_interface(modem->interfaces, OFONO_API_CM) == TRUE) {
1714 if (ready_to_create_device(modem) == TRUE)
1715 create_device(modem);
1716 if (modem->device != NULL) {
1717 cm_get_properties(modem);
1718 cm_get_contexts(modem);
1723 static void modem_power_down(gpointer key, gpointer value, gpointer user_data)
1725 struct modem_data *modem = value;
1727 DBG("%s", modem->path);
1729 if (modem->ignore == TRUE)
1732 modem_set_unpowered(modem);
1735 static void remove_modem(gpointer data)
1737 struct modem_data *modem = data;
1739 DBG("%s", modem->path);
1741 if (modem->call_set_property != NULL)
1742 dbus_pending_call_cancel(modem->call_set_property);
1744 if (modem->call_get_properties != NULL)
1745 dbus_pending_call_cancel(modem->call_get_properties);
1747 if (modem->call_get_contexts != NULL)
1748 dbus_pending_call_cancel(modem->call_get_contexts);
1750 if (modem->device != NULL)
1751 destroy_device(modem);
1753 if (modem->context != NULL)
1754 remove_cm_context(modem, modem->context->path);
1756 g_free(modem->serial);
1757 g_free(modem->name);
1758 g_free(modem->imsi);
1759 g_free(modem->path);
1764 static gboolean modem_added(DBusConnection *connection,
1765 DBusMessage *message, void *user_data)
1767 DBusMessageIter iter, properties;
1772 if (dbus_message_iter_init(message, &iter) == FALSE)
1775 dbus_message_iter_get_basic(&iter, &path);
1777 dbus_message_iter_next(&iter);
1778 dbus_message_iter_recurse(&iter, &properties);
1780 add_modem(path, &properties);
1785 static gboolean modem_removed(DBusConnection *connection,
1786 DBusMessage *message, void *user_data)
1788 DBusMessageIter iter;
1793 if (dbus_message_iter_init(message, &iter) == FALSE)
1796 dbus_message_iter_get_basic(&iter, &path);
1798 g_hash_table_remove(modem_hash, path);
1803 static void manager_get_modems_reply(DBusPendingCall *call, void *user_data)
1807 DBusMessageIter array, dict;
1811 reply = dbus_pending_call_steal_reply(call);
1813 dbus_error_init(&error);
1815 if (dbus_set_error_from_message(&error, reply) == TRUE) {
1816 connman_error("%s", error.message);
1817 dbus_error_free(&error);
1821 if (dbus_message_iter_init(reply, &array) == FALSE)
1824 dbus_message_iter_recurse(&array, &dict);
1826 while (dbus_message_iter_get_arg_type(&dict) == DBUS_TYPE_STRUCT) {
1827 DBusMessageIter value, properties;
1830 dbus_message_iter_recurse(&dict, &value);
1831 dbus_message_iter_get_basic(&value, &path);
1833 dbus_message_iter_next(&value);
1834 dbus_message_iter_recurse(&value, &properties);
1836 add_modem(path, &properties);
1838 dbus_message_iter_next(&dict);
1842 dbus_message_unref(reply);
1844 dbus_pending_call_unref(call);
1847 static int manager_get_modems(void)
1849 DBusMessage *message;
1850 DBusPendingCall *call;
1854 message = dbus_message_new_method_call(OFONO_SERVICE, "/",
1855 OFONO_MANAGER_INTERFACE, GET_MODEMS);
1856 if (message == NULL)
1859 if (dbus_connection_send_with_reply(connection, message,
1860 &call, TIMEOUT) == FALSE) {
1861 connman_error("Failed to call GetModems()");
1862 dbus_message_unref(message);
1867 connman_error("D-Bus connection not available");
1868 dbus_message_unref(message);
1872 dbus_pending_call_set_notify(call, manager_get_modems_reply,
1875 dbus_message_unref(message);
1877 return -EINPROGRESS;
1880 static void ofono_connect(DBusConnection *conn, void *user_data)
1884 modem_hash = g_hash_table_new_full(g_str_hash, g_str_equal,
1885 g_free, remove_modem);
1886 if (modem_hash == NULL)
1889 context_hash = g_hash_table_new_full(g_str_hash, g_str_equal,
1891 if (context_hash == NULL) {
1892 g_hash_table_destroy(modem_hash);
1896 manager_get_modems();
1899 static void ofono_disconnect(DBusConnection *conn, void *user_data)
1903 if (modem_hash == NULL || context_hash == NULL)
1906 g_hash_table_destroy(modem_hash);
1909 g_hash_table_destroy(context_hash);
1910 context_hash = NULL;
1913 static int network_probe(struct connman_network *network)
1915 struct modem_data *modem = connman_network_get_data(network);
1917 DBG("%s network %p", modem->path, network);
1922 static void network_remove(struct connman_network *network)
1924 struct modem_data *modem = connman_network_get_data(network);
1926 DBG("%s network %p", modem->path, network);
1929 static int network_connect(struct connman_network *network)
1931 struct modem_data *modem = connman_network_get_data(network);
1933 DBG("%s network %p", modem->path, network);
1935 return context_set_active(modem);
1938 static int network_disconnect(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_inactive(modem);
1947 static struct connman_network_driver network_driver = {
1949 .type = CONNMAN_NETWORK_TYPE_CELLULAR,
1950 .probe = network_probe,
1951 .remove = network_remove,
1952 .connect = network_connect,
1953 .disconnect = network_disconnect,
1956 static int modem_probe(struct connman_device *device)
1958 struct modem_data *modem = connman_device_get_data(device);
1960 DBG("%s device %p", modem->path, device);
1965 static void modem_remove(struct connman_device *device)
1967 struct modem_data *modem = connman_device_get_data(device);
1969 DBG("%s device %p", modem->path, device);
1972 static int modem_enable(struct connman_device *device)
1974 struct modem_data *modem = connman_device_get_data(device);
1976 DBG("%s device %p", modem->path, device);
1981 static int modem_disable(struct connman_device *device)
1983 struct modem_data *modem = connman_device_get_data(device);
1985 DBG("%s device %p", modem->path, device);
1990 static struct connman_device_driver modem_driver = {
1992 .type = CONNMAN_DEVICE_TYPE_CELLULAR,
1993 .probe = modem_probe,
1994 .remove = modem_remove,
1995 .enable = modem_enable,
1996 .disable = modem_disable,
2000 static guint modem_added_watch;
2001 static guint modem_removed_watch;
2002 static guint modem_watch;
2003 static guint cm_watch;
2004 static guint sim_watch;
2005 static guint context_added_watch;
2006 static guint context_removed_watch;
2007 static guint netreg_watch;
2008 static guint context_watch;
2010 static int ofono_init(void)
2016 connection = connman_dbus_get_connection();
2017 if (connection == NULL)
2020 watch = g_dbus_add_service_watch(connection,
2021 OFONO_SERVICE, ofono_connect,
2022 ofono_disconnect, NULL, NULL);
2024 modem_added_watch = g_dbus_add_signal_watch(connection, NULL, NULL,
2025 OFONO_MANAGER_INTERFACE,
2030 modem_removed_watch = g_dbus_add_signal_watch(connection, NULL, NULL,
2031 OFONO_MANAGER_INTERFACE,
2036 modem_watch = g_dbus_add_signal_watch(connection, NULL, NULL,
2037 OFONO_MODEM_INTERFACE,
2042 cm_watch = g_dbus_add_signal_watch(connection, NULL, NULL,
2048 sim_watch = g_dbus_add_signal_watch(connection, NULL, NULL,
2049 OFONO_SIM_INTERFACE,
2054 context_added_watch = g_dbus_add_signal_watch(connection, NULL, NULL,
2060 context_removed_watch = g_dbus_add_signal_watch(connection, NULL, NULL,
2066 context_watch = g_dbus_add_signal_watch(connection, NULL, NULL,
2067 OFONO_CONTEXT_INTERFACE,
2072 netreg_watch = g_dbus_add_signal_watch(connection, NULL, NULL,
2073 OFONO_NETREG_INTERFACE,
2079 if (watch == 0 || modem_added_watch == 0 || modem_removed_watch == 0 ||
2080 modem_watch == 0 || cm_watch == 0 || sim_watch == 0 ||
2081 context_added_watch == 0 ||
2082 context_removed_watch == 0 ||
2083 context_watch == 0 || netreg_watch == 0) {
2088 err = connman_network_driver_register(&network_driver);
2092 err = connman_device_driver_register(&modem_driver);
2094 connman_network_driver_unregister(&network_driver);
2101 g_dbus_remove_watch(connection, netreg_watch);
2102 g_dbus_remove_watch(connection, context_watch);
2103 g_dbus_remove_watch(connection, context_removed_watch);
2104 g_dbus_remove_watch(connection, context_added_watch);
2105 g_dbus_remove_watch(connection, sim_watch);
2106 g_dbus_remove_watch(connection, cm_watch);
2107 g_dbus_remove_watch(connection, modem_watch);
2108 g_dbus_remove_watch(connection, modem_removed_watch);
2109 g_dbus_remove_watch(connection, modem_added_watch);
2110 g_dbus_remove_watch(connection, watch);
2111 dbus_connection_unref(connection);
2116 static void ofono_exit(void)
2120 if (modem_hash != NULL) {
2122 * We should propably wait for the SetProperty() reply
2123 * message, because ...
2125 g_hash_table_foreach(modem_hash, modem_power_down, NULL);
2128 * ... here we will cancel the call.
2130 g_hash_table_destroy(modem_hash);
2134 if (context_hash != NULL) {
2135 g_hash_table_destroy(context_hash);
2136 context_hash = NULL;
2139 connman_device_driver_unregister(&modem_driver);
2140 connman_network_driver_unregister(&network_driver);
2142 g_dbus_remove_watch(connection, netreg_watch);
2143 g_dbus_remove_watch(connection, context_watch);
2144 g_dbus_remove_watch(connection, context_removed_watch);
2145 g_dbus_remove_watch(connection, context_added_watch);
2146 g_dbus_remove_watch(connection, sim_watch);
2147 g_dbus_remove_watch(connection, cm_watch);
2148 g_dbus_remove_watch(connection, modem_watch);
2149 g_dbus_remove_watch(connection, modem_added_watch);
2150 g_dbus_remove_watch(connection, modem_removed_watch);
2151 g_dbus_remove_watch(connection, watch);
2153 dbus_connection_unref(connection);
2156 CONNMAN_PLUGIN_DEFINE(ofono, "oFono telephony plugin", VERSION,
2157 CONNMAN_PLUGIN_PRIORITY_DEFAULT, ofono_init, ofono_exit)