From 13b2253df64f13bde5064294c6c3e729e285886c Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Fri, 17 Jun 2016 13:34:29 +0200 Subject: [PATCH 01/30] wwan: cleanup clearing modem-manager instance --- src/devices/wwan/nm-modem-manager.c | 69 ++++++++++------------------- 1 file changed, 24 insertions(+), 45 deletions(-) diff --git a/src/devices/wwan/nm-modem-manager.c b/src/devices/wwan/nm-modem-manager.c index b159d1f8d2..2cfc436f8c 100644 --- a/src/devices/wwan/nm-modem-manager.c +++ b/src/devices/wwan/nm-modem-manager.c @@ -45,9 +45,9 @@ struct _NMModemManagerPrivate { GDBusConnection *dbus_connection; MMManager *modem_manager; guint mm_launch_id; - guint mm_name_owner_changed_id; - guint mm_object_added_id; - guint mm_object_removed_id; + gulong mm_name_owner_changed_id; + gulong mm_object_added_id; + gulong mm_object_removed_id; /* Common */ GHashTable *modems; @@ -85,34 +85,14 @@ remove_one_modem (gpointer key, gpointer value, gpointer user_data) } static void -modem_manager_clear_signals (NMModemManager *self) +clear_modem_manager (NMModemManager *self) { if (!self->priv->modem_manager) return; - - if (self->priv->mm_name_owner_changed_id) { - if (g_signal_handler_is_connected (self->priv->modem_manager, - self->priv->mm_name_owner_changed_id)) - g_signal_handler_disconnect (self->priv->modem_manager, - self->priv->mm_name_owner_changed_id); - self->priv->mm_name_owner_changed_id = 0; - } - - if (self->priv->mm_object_added_id) { - if (g_signal_handler_is_connected (self->priv->modem_manager, - self->priv->mm_object_added_id)) - g_signal_handler_disconnect (self->priv->modem_manager, - self->priv->mm_object_added_id); - self->priv->mm_object_added_id = 0; - } - - if (self->priv->mm_object_removed_id) { - if (g_signal_handler_is_connected (self->priv->modem_manager, - self->priv->mm_object_removed_id)) - g_signal_handler_disconnect (self->priv->modem_manager, - self->priv->mm_object_removed_id); - self->priv->mm_object_removed_id = 0; - } + nm_clear_g_signal_handler (self->priv->modem_manager, &self->priv->mm_name_owner_changed_id); + nm_clear_g_signal_handler (self->priv->modem_manager, &self->priv->mm_object_added_id); + nm_clear_g_signal_handler (self->priv->modem_manager, &self->priv->mm_object_removed_id); + g_clear_object (&self->priv->modem_manager); } static void @@ -219,8 +199,7 @@ modem_manager_name_owner_changed (MMManager *modem_manager, * nor 'object-removed' if it was created while there was no ModemManager in * the bus. This hack avoids this issue until we get a GIO with the fix * included... */ - modem_manager_clear_signals (self); - g_clear_object (&self->priv->modem_manager); + clear_modem_manager (self); ensure_client (self); /* Whenever GDBusObjectManagerClient is fixed, we can just do the following: @@ -303,7 +282,8 @@ manager_new_ready (GObject *source, GError *error = NULL; - g_assert (!self->priv->modem_manager); + g_return_if_fail (!self->priv->modem_manager); + self->priv->modem_manager = mm_manager_new_finish (res, &error); if (!self->priv->modem_manager) { /* We're not really supposed to get any error here. If we do get one, @@ -316,20 +296,20 @@ manager_new_ready (GObject *source, } else { /* Setup signals in the GDBusObjectManagerClient */ self->priv->mm_name_owner_changed_id = - g_signal_connect (self->priv->modem_manager, - "notify::name-owner", - G_CALLBACK (modem_manager_name_owner_changed), - self); + g_signal_connect (self->priv->modem_manager, + "notify::name-owner", + G_CALLBACK (modem_manager_name_owner_changed), + self); self->priv->mm_object_added_id = - g_signal_connect (self->priv->modem_manager, - "object-added", - G_CALLBACK (modem_object_added), - self); + g_signal_connect (self->priv->modem_manager, + "object-added", + G_CALLBACK (modem_object_added), + self); self->priv->mm_object_removed_id = - g_signal_connect (self->priv->modem_manager, - "object-removed", - G_CALLBACK (modem_object_removed), - self); + g_signal_connect (self->priv->modem_manager, + "object-removed", + G_CALLBACK (modem_object_removed), + self); modem_manager_check_name_owner (self); } @@ -433,8 +413,7 @@ dispose (GObject *object) nm_clear_g_source (&self->priv->mm_launch_id); - modem_manager_clear_signals (self); - g_clear_object (&self->priv->modem_manager); + clear_modem_manager (self); g_clear_object (&self->priv->dbus_connection); if (self->priv->modems) { From a6e81af87f181d405f1c4334b66aceafd01ec676 Mon Sep 17 00:00:00 2001 From: Mathieu Trudel-Lapierre Date: Fri, 10 Jun 2016 17:56:25 -0400 Subject: [PATCH 02/30] wwan: add support for using oFono as a modem manager This patch adds core wwan support for ofono, as used by Ubuntu Touch. Signed-off-by: Mathieu Trudel-Lapierre https://mail.gnome.org/archives/networkmanager-list/2016-June/msg00089.html --- configure.ac | 9 + src/devices/wwan/Makefile.am | 7 + src/devices/wwan/nm-device-modem.c | 2 + src/devices/wwan/nm-modem-manager.c | 243 ++++- src/devices/wwan/nm-modem-ofono.c | 1425 +++++++++++++++++++++++++++ src/devices/wwan/nm-modem-ofono.h | 64 ++ src/devices/wwan/nm-modem.c | 8 +- src/nm-core-utils.c | 20 +- 8 files changed, 1756 insertions(+), 22 deletions(-) create mode 100644 src/devices/wwan/nm-modem-ofono.c create mode 100644 src/devices/wwan/nm-modem-ofono.h diff --git a/configure.ac b/configure.ac index e93975b15c..eba3fcc657 100644 --- a/configure.ac +++ b/configure.ac @@ -734,6 +734,15 @@ else fi AM_CONDITIONAL(WITH_BLUEZ5_DUN, test "${enable_bluez5_dun}" = "yes") +# OFONO +AC_ARG_WITH(ofono, AS_HELP_STRING([--with-ofono], [Enable oFono support]),,[with_ofono=yes]) +if (test "${with_ofono}" = "yes"); then + AC_DEFINE(WITH_OFONO, 1, [Define if you have oFono support]) +else + AC_DEFINE(WITH_OFONO, 0, [Define if you have oFono support]) +fi +AM_CONDITIONAL(WITH_OFONO, test "${with_ofono}" = "yes") + # DHCP client support AC_ARG_WITH([dhclient], AS_HELP_STRING([--with-dhclient=yes|no|path], [Enable dhclient 4.x support])) AC_ARG_WITH([dhcpcd], AS_HELP_STRING([--with-dhcpcd=yes|no|path], [Enable dhcpcd 4.x support])) diff --git a/src/devices/wwan/Makefile.am b/src/devices/wwan/Makefile.am index 95e8ec8d60..1d3c7c851d 100644 --- a/src/devices/wwan/Makefile.am +++ b/src/devices/wwan/Makefile.am @@ -42,6 +42,13 @@ libnm_wwan_la_SOURCES = \ \ $(GLIB_GENERATED) +if WITH_OFONO +libnm_wwan_la_SOURCES += \ + nm-modem-ofono.c \ + nm-modem-ofono.h \ + $(NULL) +endif + WWAN_SYMBOL_VIS_FILE=$(srcdir)/wwan-exports.ver libnm_wwan_la_LDFLAGS = \ diff --git a/src/devices/wwan/nm-device-modem.c b/src/devices/wwan/nm-device-modem.c index 0f96dafbfc..d69804e816 100644 --- a/src/devices/wwan/nm-device-modem.c +++ b/src/devices/wwan/nm-device-modem.c @@ -112,6 +112,7 @@ modem_prepare_result (NMModem *modem, if (success) nm_device_activate_schedule_stage2_device_config (device); else { + if (reason == NM_DEVICE_STATE_REASON_SIM_PIN_INCORRECT) { /* If the connect failed because the SIM PIN was wrong don't allow * the device to be auto-activated anymore, which would risk locking @@ -562,6 +563,7 @@ get_ip_iface_identifier (NMDevice *device, NMUtilsIPv6IfaceId *out_iid) g_return_val_if_fail (priv->modem, FALSE); success = nm_modem_get_iid (priv->modem, out_iid); + if (!success) success = NM_DEVICE_CLASS (nm_device_modem_parent_class)->get_ip_iface_identifier (device, out_iid); return success; diff --git a/src/devices/wwan/nm-modem-manager.c b/src/devices/wwan/nm-modem-manager.c index 2cfc436f8c..bab2e91810 100644 --- a/src/devices/wwan/nm-modem-manager.c +++ b/src/devices/wwan/nm-modem-manager.c @@ -17,7 +17,7 @@ * * Copyright (C) 2009 - 2014 Red Hat, Inc. * Copyright (C) 2009 Novell, Inc. - * Copyright (C) 2009 Canonical Ltd. + * Copyright (C) 2009 - 2013 Canonical Ltd. */ #include "nm-default.h" @@ -37,6 +37,10 @@ #define sd_booted() FALSE #endif +#if WITH_OFONO +#include "nm-modem-ofono.h" +#endif + #define MODEM_POKE_INTERVAL 120 G_DEFINE_TYPE (NMModemManager, nm_modem_manager, G_TYPE_OBJECT) @@ -49,6 +53,12 @@ struct _NMModemManagerPrivate { gulong mm_object_added_id; gulong mm_object_removed_id; +#if WITH_OFONO + GDBusProxy *ofono_proxy; + + guint ofono_name_owner_changed_id; +#endif + /* Common */ GHashTable *modems; }; @@ -206,6 +216,178 @@ modem_manager_name_owner_changed (MMManager *modem_manager, * modem_manager_available (self); */ } +#if WITH_OFONO +static void +ofono_clear_signals (NMModemManager *self) +{ + if (!self->priv->ofono_proxy) + return; + + if (self->priv->ofono_name_owner_changed_id) { + if (g_signal_handler_is_connected (self->priv->ofono_proxy, + self->priv->ofono_name_owner_changed_id)) + g_signal_handler_disconnect (self->priv->ofono_proxy, + self->priv->ofono_name_owner_changed_id); + self->priv->ofono_name_owner_changed_id = 0; + } +} + +static void +ofono_create_modem (NMModemManager *self, const char *path) +{ + NMModem *modem = NULL; + + if (g_hash_table_lookup (self->priv->modems, path)) { + nm_log_warn (LOGD_MB, "modem with path %s already exists, ignoring", path); + return; + } + + /* Create modem instance */ + modem = nm_modem_ofono_new (path); + if (modem) + handle_new_modem (self, modem); + else + nm_log_warn (LOGD_MB, "Failed to create oFono modem for %s", path); +} + +static void +ofono_signal_cb (GDBusProxy *proxy, + gchar *sender_name, + gchar *signal_name, + GVariant *parameters, + gpointer user_data) +{ + NMModemManager *self = NM_MODEM_MANAGER (user_data); + gchar *object_path; + NMModem *modem; + + if (g_strcmp0 (signal_name, "ModemAdded") == 0) { + g_variant_get (parameters, "(oa{sv})", &object_path, NULL); + nm_log_info (LOGD_MB, "oFono modem appeared: %s", object_path); + + ofono_create_modem (NM_MODEM_MANAGER (user_data), object_path); + g_free (object_path); + } else if (g_strcmp0 (signal_name, "ModemRemoved") == 0) { + g_variant_get (parameters, "(o)", &object_path); + nm_log_info (LOGD_MB, "oFono modem removed: %s", object_path); + + modem = (NMModem *) g_hash_table_lookup (self->priv->modems, object_path); + if (modem) { + nm_modem_emit_removed (modem); + g_hash_table_remove (self->priv->modems, object_path); + } else { + nm_log_warn (LOGD_MB, "could not remove modem %s, not found in table", + object_path); + } + g_free (object_path); + } +} + +#define OFONO_DBUS_MODEM_ENTRY (dbus_g_type_get_struct ("GValueArray", DBUS_TYPE_G_OBJECT_PATH, DBUS_TYPE_G_MAP_OF_VARIANT, G_TYPE_INVALID)) +#define OFONO_DBUS_MODEM_ENTRIES (dbus_g_type_get_collection ("GPtrArray", OFONO_DBUS_MODEM_ENTRY)) + +static void +ofono_enumerate_devices_done (GDBusProxy *proxy, GAsyncResult *res, gpointer user_data) +{ + NMModemManager *manager = NM_MODEM_MANAGER (user_data); + GError *error = NULL; + GVariant *results; + GVariantIter *iter; + const char *path; + + results = g_dbus_proxy_call_finish (proxy, res, &error); + if (results) { + g_variant_get (results, "(a(oa{sv}))", &iter); + while (g_variant_iter_loop (iter, "(&oa{sv})", &path, NULL)) { + ofono_create_modem (manager, path); + } + g_variant_iter_free (iter); + g_variant_unref (results); + } + + if (error) + nm_log_warn (LOGD_MB, "failed to enumerate oFono devices: %s", + error->message ? error->message : "(unknown)"); +} + +static void ofono_appeared (NMModemManager *self); + + +static void +ofono_check_name_owner (NMModemManager *self) +{ + gchar *name_owner; + + name_owner = g_dbus_proxy_get_name_owner (G_DBUS_PROXY (self->priv->ofono_proxy)); + if (name_owner) { + /* Available! */ + ofono_appeared (self); + goto free; + } + + nm_log_info (LOGD_MB, "oFono disappeared from bus"); + + ofono_clear_signals (self); + g_clear_object (&self->priv->ofono_proxy); + ensure_client (self); + +free: + g_free (name_owner); + return; +} + +static void +ofono_name_owner_changed (GDBusProxy *ofono_proxy, + GParamSpec *pspec, + NMModemManager *self) +{ + ofono_check_name_owner (self); +} + +static void +ofono_appeared (NMModemManager *self) +{ + nm_log_info (LOGD_MB, "ofono is now available"); + + self->priv->ofono_name_owner_changed_id = + g_signal_connect (self->priv->ofono_proxy, + "notify::name-owner", + G_CALLBACK (ofono_name_owner_changed), + self); + g_dbus_proxy_call (self->priv->ofono_proxy, + "GetModems", + NULL, + G_DBUS_CALL_FLAGS_NONE, + -1, + NULL, + (GAsyncReadyCallback) ofono_enumerate_devices_done, + g_object_ref (self)); + + g_signal_connect (self->priv->ofono_proxy, + "g-signal", + G_CALLBACK (ofono_signal_cb), + self); +} + +static void +ofono_proxy_new_cb (GObject *source_object, GAsyncResult *res, gpointer user_data) +{ + NMModemManager *self = NM_MODEM_MANAGER (user_data); + GError *error = NULL; + + self->priv->ofono_proxy = g_dbus_proxy_new_finish (res, &error); + + if (error) { + //FIXME: do stuff if there's an error. + return; + } + + ofono_appeared (self); + + /* Balance refcount */ + g_object_unref (self); +} +#endif static void modem_manager_poke_cb (GDBusConnection *connection, @@ -217,19 +399,18 @@ modem_manager_poke_cb (GDBusConnection *connection, result = g_dbus_connection_call_finish (connection, res, &error); if (error) { - /* Ignore common errors when MM is not installed and such */ - if ( !g_error_matches (error, G_DBUS_ERROR, G_DBUS_ERROR_SERVICE_UNKNOWN) - && !g_error_matches (error, G_DBUS_ERROR, G_DBUS_ERROR_SPAWN_EXEC_FAILED) - && !g_error_matches (error, G_DBUS_ERROR, G_DBUS_ERROR_SPAWN_FORK_FAILED) - && !g_error_matches (error, G_DBUS_ERROR, G_DBUS_ERROR_SPAWN_FAILED) - && !g_error_matches (error, G_DBUS_ERROR, G_DBUS_ERROR_TIMEOUT) - && !g_error_matches (error, G_DBUS_ERROR, G_DBUS_ERROR_SPAWN_SERVICE_NOT_FOUND)) { - nm_log_dbg (LOGD_MB, "error poking ModemManager: %s", error->message); - } - g_error_free (error); + nm_log_warn (LOGD_MB, "error poking ModemManager: %s", + error ? error->message : ""); - /* Setup timeout to relaunch */ - schedule_modem_manager_relaunch (self, MODEM_POKE_INTERVAL); + /* Don't reschedule poke is MM service doesn't exist. */ + if (!g_error_matches (error, G_DBUS_ERROR, G_DBUS_ERROR_SERVICE_UNKNOWN) + && !g_error_matches (error, G_DBUS_ERROR, G_DBUS_ERROR_SPAWN_SERVICE_NOT_FOUND)) { + + /* Setup timeout to relaunch */ + schedule_modem_manager_relaunch (self, MODEM_POKE_INTERVAL); + } + + g_error_free (error); } else g_variant_unref (result); @@ -321,22 +502,44 @@ manager_new_ready (GObject *source, static void ensure_client (NMModemManager *self) { - g_assert (self->priv->dbus_connection); + NMModemManagerPrivate *priv = self->priv; + gboolean created = FALSE; + + g_assert (priv->dbus_connection); /* Create the GDBusObjectManagerClient. We do not request to autostart, as * we don't really want the MMManager creation to fail. We can always poke * later on if we want to request the autostart */ - if (!self->priv->modem_manager) { - mm_manager_new (self->priv->dbus_connection, + if (!priv->modem_manager) { + mm_manager_new (priv->dbus_connection, G_DBUS_OBJECT_MANAGER_CLIENT_FLAGS_DO_NOT_AUTO_START, NULL, (GAsyncReadyCallback)manager_new_ready, g_object_ref (self)); - return; + created = TRUE; } +#if WITH_OFONO + if (!priv->ofono_proxy) { + g_dbus_proxy_new (priv->dbus_connection, + G_DBUS_OBJECT_MANAGER_CLIENT_FLAGS_DO_NOT_AUTO_START, + NULL, + OFONO_DBUS_SERVICE, + OFONO_DBUS_PATH, + OFONO_DBUS_INTERFACE, + NULL, + (GAsyncReadyCallback) ofono_proxy_new_cb, + g_object_ref (self)); + created = TRUE; + } +#endif /* WITH_OFONO */ + + if (created) + return; + /* If already available, recheck name owner! */ modem_manager_check_name_owner (self); + ofono_check_name_owner (self); } static void @@ -414,6 +617,12 @@ dispose (GObject *object) nm_clear_g_source (&self->priv->mm_launch_id); clear_modem_manager (self); + +#if WITH_OFONO + ofono_clear_signals (self); + g_clear_object (&self->priv->ofono_proxy); +#endif + g_clear_object (&self->priv->dbus_connection); if (self->priv->modems) { diff --git a/src/devices/wwan/nm-modem-ofono.c b/src/devices/wwan/nm-modem-ofono.c new file mode 100644 index 0000000000..2b43b08cc8 --- /dev/null +++ b/src/devices/wwan/nm-modem-ofono.c @@ -0,0 +1,1425 @@ +/* -*- Mode: C; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */ +/* NetworkManager -- Network link manager + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Copyright (C) 2013 - 2016 Canonical Ltd. + */ + +#include "config.h" + +#include +#include + +#include "nm-default.h" +#include "nm-core-internal.h" + +#include "nm-modem-ofono.h" +#include "nm-device.h" +#include "nm-device-private.h" +#include "nm-setting-connection.h" +#include "nm-setting-gsm.h" +#include "nm-settings-connection.h" +#include "nm-enum-types.h" +#include "nm-logging.h" +#include "nm-modem.h" +#include "nm-platform.h" +#include "nm-utils.h" + +G_DEFINE_TYPE (NMModemOfono, nm_modem_ofono, NM_TYPE_MODEM) + +#define NM_MODEM_OFONO_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), NM_TYPE_MODEM_OFONO, NMModemOfonoPrivate)) + +#define VARIANT_IS_OF_TYPE_BOOLEAN(v) ((v) != NULL && ( g_variant_is_of_type ((v), G_VARIANT_TYPE_BOOLEAN) )) +#define VARIANT_IS_OF_TYPE_STRING(v) ((v) != NULL && ( g_variant_is_of_type ((v), G_VARIANT_TYPE_STRING) )) +#define VARIANT_IS_OF_TYPE_OBJECT_PATH(v) ((v) != NULL && ( g_variant_is_of_type ((v), G_VARIANT_TYPE_OBJECT_PATH) )) +#define VARIANT_IS_OF_TYPE_STRING_ARRAY(v) ((v) != NULL && ( g_variant_is_of_type ((v), G_VARIANT_TYPE_STRING_ARRAY) )) +#define VARIANT_IS_OF_TYPE_DICTIONARY(v) ((v) != NULL && ( g_variant_is_of_type ((v), G_VARIANT_TYPE_DICTIONARY) )) + +typedef struct { + GDBusConnection *dbus_connection; + + GHashTable *connect_properties; + + GDBusProxy *modem_proxy; + GDBusProxy *connman_proxy; + GDBusProxy *context_proxy; + GDBusProxy *sim_proxy; + + GError *property_error; + + char *context_path; + char *imsi; + + gboolean modem_online; + gboolean gprs_attached; + + NMIP4Config *ip4_config; + +} NMModemOfonoPrivate; + +#define NM_OFONO_ERROR (nm_ofono_error_quark ()) + +static GQuark +nm_ofono_error_quark (void) +{ + static GQuark quark = 0; + if (!quark) + quark = g_quark_from_static_string ("nm-ofono-error"); + return quark; +} + +static gboolean +ip_string_to_network_address (const gchar *str, + guint32 *out) +{ + guint32 addr = 0; + gboolean success = FALSE; + + if (!str || inet_pton (AF_INET, str, &addr) != 1) + addr = 0; + else + success = TRUE; + + *out = (guint32)addr; + return success; +} + +static void +get_capabilities (NMModem *_self, + NMDeviceModemCapabilities *modem_caps, + NMDeviceModemCapabilities *current_caps) +{ + NMDeviceModemCapabilities all_ofono_caps = NM_DEVICE_MODEM_CAPABILITY_GSM_UMTS; + + *modem_caps = all_ofono_caps; + *current_caps = all_ofono_caps; +} + +static void +update_modem_state (NMModemOfono *self) +{ + NMModemOfonoPrivate *priv = NM_MODEM_OFONO_GET_PRIVATE (self); + NMModemState state = nm_modem_get_state (NM_MODEM (self)); + NMModemState new_state = NM_MODEM_STATE_DISABLED; + const char *reason = NULL; + + nm_log_info (LOGD_MB, "(%s): %s: 'Attached': %s 'Online': %s 'IMSI': %s", + nm_modem_get_path (NM_MODEM (self)), + __func__, + priv->gprs_attached ? "true" : "false", + priv->modem_online ? "true" : "false", + priv->imsi); + + if (priv->modem_online == FALSE) { + reason = "modem 'Online=false'"; + } else if (priv->imsi == NULL && state != NM_MODEM_STATE_ENABLING) { + reason = "modem not ready"; + } else if (priv->gprs_attached == FALSE) { + new_state = NM_MODEM_STATE_SEARCHING; + reason = "modem searching"; + } else { + new_state = NM_MODEM_STATE_REGISTERED; + reason = "modem ready"; + } + + if (state != new_state) + nm_modem_set_state (NM_MODEM (self), new_state, reason); +} + +/* Disconnect */ +typedef struct { + NMModemOfono *self; + GSimpleAsyncResult *result; + GCancellable *cancellable; + gboolean warn; +} DisconnectContext; + +static void +disconnect_context_complete (DisconnectContext *ctx) +{ + g_simple_async_result_complete_in_idle (ctx->result); + if (ctx->cancellable) + g_object_unref (ctx->cancellable); + g_object_unref (ctx->result); + g_object_unref (ctx->self); + g_slice_free (DisconnectContext, ctx); +} + +static gboolean +disconnect_context_complete_if_cancelled (DisconnectContext *ctx) +{ + GError *error = NULL; + + if (g_cancellable_set_error_if_cancelled (ctx->cancellable, &error)) { + g_simple_async_result_take_error (ctx->result, error); + disconnect_context_complete (ctx); + return TRUE; + } + + return FALSE; +} + +static gboolean +disconnect_finish (NMModem *self, + GAsyncResult *result, + GError **error) +{ + return !g_simple_async_result_propagate_error (G_SIMPLE_ASYNC_RESULT (result), error); +} + +static void +disconnect_done (GDBusProxy *proxy, + GAsyncResult *result, + gpointer user_data) +{ + DisconnectContext *ctx = (DisconnectContext*) user_data; + NMModemOfono *self = ctx->self; + GError *error = NULL; + + + + g_dbus_proxy_call_finish (proxy, result, &error); + if (g_error_matches (error, G_IO_ERROR, G_IO_ERROR_CANCELLED)) { + nm_log_dbg (LOGD_MB, "(%s): disconnect cancelled", + nm_modem_get_uid (NM_MODEM (self))); + return; + } + + if (error) { + if (ctx->warn) + nm_log_warn (LOGD_MB, "(%s) failed to disconnect modem: %s", + nm_modem_get_uid (NM_MODEM (self)), + error && error->message ? error->message : "(unknown)"); + + g_clear_error (&error); + } + + nm_log_dbg (LOGD_MB, "(%s): modem disconnected", + nm_modem_get_uid (NM_MODEM (self))); + + update_modem_state (self); + disconnect_context_complete (ctx); +} + +static void +disconnect (NMModem *self, + gboolean warn, + GCancellable *cancellable, + GAsyncReadyCallback callback, + gpointer user_data) +{ + NMModemOfonoPrivate *priv = NM_MODEM_OFONO_GET_PRIVATE (self); + DisconnectContext *ctx; + NMModemState state = nm_modem_get_state (NM_MODEM (self)); + + nm_log_dbg (LOGD_MB, "(%s): warn: %s modem_state: %s", + nm_modem_get_uid (NM_MODEM (self)), + warn ? "TRUE" : "FALSE", + nm_modem_state_to_string (state)); + + if (state != NM_MODEM_STATE_CONNECTED) + return; + + ctx = g_slice_new (DisconnectContext); + ctx->self = g_object_ref (self); + ctx->warn = warn; + + if (callback) + ctx->result = g_simple_async_result_new (G_OBJECT (self), + callback, + user_data, + disconnect); + /* Setup cancellable */ + ctx->cancellable = cancellable ? g_object_ref (cancellable) : NULL; + if (disconnect_context_complete_if_cancelled (ctx)) + return; + + nm_modem_set_state (NM_MODEM (self), + NM_MODEM_STATE_DISCONNECTING, + nm_modem_state_to_string (NM_MODEM_STATE_DISCONNECTING)); + + g_dbus_proxy_call (priv->context_proxy, + "SetProperty", + g_variant_new ("(sv)", + "Active", + g_variant_new ("b", warn)), + G_DBUS_CALL_FLAGS_NONE, + 20000, + NULL, + (GAsyncReadyCallback) disconnect_done, + ctx); +} + +static void +deactivate_cleanup (NMModem *_self, NMDevice *device) +{ + NMModemOfono *self = NM_MODEM_OFONO (_self); + NMModemOfonoPrivate *priv = NM_MODEM_OFONO_GET_PRIVATE (self); + + /* TODO: cancel SimpleConnect() if any */ + + g_clear_object (&priv->ip4_config); + + /* Chain up parent's */ + NM_MODEM_CLASS (nm_modem_ofono_parent_class)->deactivate_cleanup (_self, device); +} + + +static gboolean +check_connection_compatible (NMModem *modem, + NMConnection *connection) +{ + NMModemOfono *self = NM_MODEM_OFONO (modem); + NMModemOfonoPrivate *priv = NM_MODEM_OFONO_GET_PRIVATE (self); + NMSettingConnection *s_con; + NMSettingGsm *s_gsm; + const char *uuid; + const char *id; + + s_con = nm_connection_get_setting_connection (connection); + g_assert (s_con); + + uuid = nm_connection_get_uuid (connection); + id = nm_connection_get_id (connection); + + s_gsm = nm_connection_get_setting_gsm (connection); + if (!s_gsm) + return FALSE; + + if (!priv->imsi) { + nm_log_warn (LOGD_MB, "ofono (%s): check_connection %s failed: no IMSI", + nm_modem_get_uid (NM_MODEM (self)), id); + return FALSE; + } + + if (strcmp (nm_setting_connection_get_connection_type (s_con), NM_SETTING_GSM_SETTING_NAME)) { + nm_log_dbg (LOGD_MB, "%s (%s) isn't of the right type, skipping.", id, uuid); + return FALSE; + } + + if (!g_strrstr (id, "/context")) { + nm_log_dbg (LOGD_MB, "%s (%s) isn't of the right type, skipping.", id, uuid); + return FALSE; + } + + if (!g_strrstr (id, priv->imsi)) { + nm_log_dbg (LOGD_MB, "%s (%s) isn't for the right SIM, skipping.", id, uuid); + return FALSE; + } + + nm_log_dbg (LOGD_MB, "(%s): %s is compatible with IMSI %s", + nm_modem_get_uid (NM_MODEM (self)), id, priv->imsi); + + return TRUE; +} + +static void +handle_sim_property (GDBusProxy *proxy, + const char *property, + GVariant *v, + gpointer user_data) +{ + NMModemOfono *self = NM_MODEM_OFONO (user_data); + NMModemOfonoPrivate *priv = NM_MODEM_OFONO_GET_PRIVATE (self); + + if (g_strcmp0 (property, "SubscriberIdentity") == 0 && VARIANT_IS_OF_TYPE_STRING (v)) { + gsize length; + const char *value_str = g_variant_get_string (v, &length); + + nm_log_dbg (LOGD_MB, "(%s): SubscriberIdentity found", nm_modem_get_uid (NM_MODEM (self))); + + /* Check for empty DBus string value */ + if (length && + g_strcmp0 (value_str, "(null)") != 0 && + g_strcmp0 (value_str, priv->imsi) != 0) { + + if (priv->imsi != NULL) { + nm_log_warn (LOGD_MB, "SimManager:'SubscriberIdentity' changed: %s", priv->imsi); + g_free(priv->imsi); + } + + priv->imsi = g_strdup (value_str); + update_modem_state (self); + } + } +} + +sim_property_changed (GDBusProxy *proxy, + const char *property, + GVariant *v, + gpointer user_data) +{ + GVariant *v_child = g_variant_get_child_value (v, 0); + + handle_sim_property (proxy, property, v_child, user_data); + g_variant_unref (v_child); +} + +static void +sim_get_properties_done (GDBusProxy *proxy, GAsyncResult *result, gpointer user_data) +{ + NMModemOfono *self = NM_MODEM_OFONO (user_data); + GError *error = NULL; + GVariant *v_properties, *v_dict, *v; + GVariantIter i; + const char *property; + + nm_log_dbg (LOGD_MB, "%s", __func__); + + v_properties = _nm_dbus_proxy_call_finish (proxy, + result, + G_VARIANT_TYPE ("(a{sv})"), + &error); + if (!v_properties) { + g_dbus_error_strip_remote_error (error); + nm_log_warn (LOGD_MB, "(%s) error getting sim properties: %s", + nm_modem_get_uid (NM_MODEM (self)), + error->message); + g_error_free (error); + return; + } + + nm_log_dbg (LOGD_MB, "sim v_properties is type: %s", g_variant_get_type_string (v_properties)); + + v_dict = g_variant_get_child_value (v_properties, 0); + if (!v_dict) { + nm_log_warn (LOGD_MB, "(%s) error getting sim properties: no v_dict", + nm_modem_get_uid (NM_MODEM (self))); + return; + } + + nm_log_dbg (LOGD_MB, "sim v_dict is type: %s", g_variant_get_type_string (v_dict)); + + /* + * TODO: + * 1) optimize by looking up properties ( Online, Interfaces ), instead + * of iterating + * + * 2) reduce code duplication between all of the get_properties_done + * functions in this class. + */ + + g_variant_iter_init (&i, v_dict); + while (g_variant_iter_next (&i, "{&sv}", &property, &v)) { + handle_sim_property (NULL, property, v, self); + g_variant_unref (v); + } + + g_variant_unref (v_dict); + g_variant_unref (v_properties); +} + +static void +handle_sim_iface (NMModemOfono *self, gboolean found) +{ + NMModemOfonoPrivate *priv = NM_MODEM_OFONO_GET_PRIVATE (self); + + nm_log_dbg (LOGD_MB, "%s: %s", __func__, found ? "TRUE" : "FALSE"); + + if (!found && priv->sim_proxy) { + nm_log_info (LOGD_MB, "(%s): SimManager interface disappeared", + nm_modem_get_path (NM_MODEM (self))); + + g_signal_handlers_disconnect_by_data (priv->sim_proxy, NM_MODEM_OFONO (self)); + g_clear_object (&priv->sim_proxy); + + g_free (priv->imsi); + priv->imsi = NULL; + + update_modem_state (self); + } else if (found && !priv->sim_proxy) { + GError *error = NULL; + GDBusProxyFlags flags; + + nm_log_info (LOGD_MB, "(%s): found new SimManager interface", + nm_modem_get_path (NM_MODEM (self))); + + flags |= G_DBUS_PROXY_FLAGS_DO_NOT_LOAD_PROPERTIES; + flags |= G_DBUS_PROXY_FLAGS_DO_NOT_AUTO_START; + + priv->sim_proxy = g_dbus_proxy_new_sync (priv->dbus_connection, + flags, + NULL, /* GDBusInterfaceInfo */ + OFONO_DBUS_SERVICE, + nm_modem_get_path (NM_MODEM (self)), + OFONO_DBUS_INTERFACE_SIM_MANAGER, + NULL, /* GCancellable */ + &error); + if (priv->sim_proxy == NULL) { + nm_log_warn (LOGD_MB, "(%s) failed to create SimManager proxy: %s", + nm_modem_get_uid (NM_MODEM (self)), + error && error->message ? error->message : "(unknown)"); + + g_error_free (error); + return; + } + + /* Watch for custom ofono PropertyChanged signals */ + _nm_dbus_signal_connect (priv->sim_proxy, + "PropertyChanged", + G_VARIANT_TYPE ("(sv)"), + G_CALLBACK (sim_property_changed), + self); + + g_dbus_proxy_call (priv->sim_proxy, + "GetProperties", + NULL, + G_DBUS_CALL_FLAGS_NONE, + 20000, + NULL, + (GAsyncReadyCallback) sim_get_properties_done, + g_object_ref (self)); + } +} + +static void +handle_connman_property (GDBusProxy *proxy, + const char *property, + GVariant *v, + gpointer user_data) +{ + NMModemOfono *self = NM_MODEM_OFONO (user_data); + NMModemOfonoPrivate *priv = NM_MODEM_OFONO_GET_PRIVATE (self); + + if (g_strcmp0 (property, "Attached") == 0 && VARIANT_IS_OF_TYPE_BOOLEAN (v)) { + gboolean attached = g_variant_get_boolean (v); + + nm_log_dbg (LOGD_MB, "(%s): Attached: %s", + nm_modem_get_uid (NM_MODEM (self)), attached ? "True" : "False"); + + if (priv->gprs_attached != attached) { + priv->gprs_attached = attached; + + nm_log_info (LOGD_MB, "(%s): %s: new value for 'Attached': %s", + nm_modem_get_path (NM_MODEM (self)), + __func__, + attached ? "true" : "false"); + + update_modem_state (self); + } + } +} + +static void +connman_property_changed (GDBusProxy *proxy, + const char *property, + GVariant *v, + gpointer user_data) +{ + GVariant *v_child = g_variant_get_child_value (v, 0); + + handle_connman_property (proxy, property, v_child, user_data); + g_variant_unref (v_child); +} + +static void +connman_get_properties_done (GDBusProxy *proxy, GAsyncResult *result, gpointer user_data) +{ + NMModemOfono *self = NM_MODEM_OFONO (user_data); + GError *error = NULL; + GVariant *v_properties, *v_dict, *v; + GVariantIter i; + const char *property; + + nm_log_dbg (LOGD_MB, "%s", __func__); + + v_properties = _nm_dbus_proxy_call_finish (proxy, + result, + G_VARIANT_TYPE ("(a{sv})"), + &error); + if (!v_properties) { + g_dbus_error_strip_remote_error (error); + nm_log_warn (LOGD_MB, "(%s) error getting connman properties: %s", + nm_modem_get_uid (NM_MODEM (self)), + error->message); + g_error_free (error); + return; + } + + v_dict = g_variant_get_child_value (v_properties, 0); + + /* + * TODO: + * 1) optimize by looking up properties ( Online, Interfaces ), instead + * of iterating + * + * 2) reduce code duplication between all of the get_properties_done + * functions in this class. + */ + + g_variant_iter_init (&i, v_dict); + while (g_variant_iter_next (&i, "{&sv}", &property, &v)) { + handle_connman_property (NULL, property, v, self); + g_variant_unref (v); + } + + g_variant_unref (v_dict); + g_variant_unref (v_properties); +} + +static void +handle_connman_iface (NMModemOfono *self, gboolean found) +{ + NMModemOfonoPrivate *priv = NM_MODEM_OFONO_GET_PRIVATE (self); + + nm_log_dbg (LOGD_MB, "%s: %s", __func__, found ? "TRUE" : "FALSE"); + + if (!found && priv->connman_proxy) { + nm_log_info (LOGD_MB, "(%s): ConnectionManager interface disappeared", + nm_modem_get_path (NM_MODEM (self))); + + g_signal_handlers_disconnect_by_data (priv->connman_proxy, NM_MODEM_OFONO (self)); + g_clear_object (&priv->connman_proxy); + + /* The connection manager proxy disappeared, we should + * consider the modem disabled. + */ + priv->gprs_attached = FALSE; + + update_modem_state (self); + } else if (found && !priv->connman_proxy) { + GError *error = NULL; + GDBusProxyFlags flags; + + nm_log_info (LOGD_MB, "(%s): found new ConnectionManager interface", + nm_modem_get_path (NM_MODEM (self))); + + flags |= G_DBUS_PROXY_FLAGS_DO_NOT_LOAD_PROPERTIES; + flags |= G_DBUS_PROXY_FLAGS_DO_NOT_AUTO_START; + + priv->connman_proxy = g_dbus_proxy_new_sync (priv->dbus_connection, + flags, + NULL, /* GDBusInterfaceInfo */ + OFONO_DBUS_SERVICE, + nm_modem_get_path (NM_MODEM (self)), + OFONO_DBUS_INTERFACE_CONNECTION_MANAGER, + NULL, /* GCancellable */ + &error); + if (priv->connman_proxy == NULL) { + nm_log_warn (LOGD_MB, "(%s) failed to create ConnectionManager proxy: %s", + nm_modem_get_uid (NM_MODEM (self)), + error && error->message ? error->message : "(unknown)"); + + g_error_free (error); + return; + } + + /* Watch for custom ofono PropertyChanged signals */ + _nm_dbus_signal_connect (priv->connman_proxy, + "PropertyChanged", + G_VARIANT_TYPE ("(sv)"), + G_CALLBACK (connman_property_changed), + self); + + g_dbus_proxy_call (priv->connman_proxy, + "GetProperties", + NULL, + G_DBUS_CALL_FLAGS_NONE, + 20000, + NULL, + (GAsyncReadyCallback) connman_get_properties_done, + g_object_ref (self)); + + /* NM 0.9.10x version registers for "ContextAdded/Removed", but + * did nothing but log a message. Removed for 1.2 + */ + } +} + +static void +handle_modem_property (GDBusProxy *proxy, + const char *property, + GVariant *v, + gpointer user_data) +{ + NMModemOfono *self = NM_MODEM_OFONO (user_data); + NMModemOfonoPrivate *priv = NM_MODEM_OFONO_GET_PRIVATE (self); + + if ((g_strcmp0 (property, "Online") == 0) && VARIANT_IS_OF_TYPE_BOOLEAN (v)) { + gboolean online = g_variant_get_boolean (v); + + nm_log_dbg (LOGD_MB, "(%s): Online: %s", + nm_modem_get_uid (NM_MODEM (self)), online ? "True" : "False"); + + if (online != priv->modem_online) { + priv->modem_online = online; + + nm_log_info (LOGD_MB, "(%s) modem is now %s", + nm_modem_get_path (NM_MODEM (self)), + online ? "Online" : "Offline"); + + update_modem_state (self); + } + + } else if ((g_strcmp0 (property, "Interfaces") == 0) && VARIANT_IS_OF_TYPE_STRING_ARRAY (v)) { + const char **array, **iter; + gboolean found_connman = FALSE; + gboolean found_sim = FALSE; + + nm_log_dbg (LOGD_MB, "(%s): Interfaces", nm_modem_get_uid (NM_MODEM (self))); + + array = g_variant_get_strv (v, NULL); + if (array) { + + iter = array; + while (*iter) { + + if (g_strcmp0 (OFONO_DBUS_INTERFACE_SIM_MANAGER, *iter) == 0) + found_sim = TRUE; + else if (g_strcmp0 (OFONO_DBUS_INTERFACE_CONNECTION_MANAGER, *iter) == 0) + found_connman = TRUE; + + *iter++; + } + + g_free (array); + } + + handle_sim_iface (self, found_sim); + handle_connman_iface (self, found_connman); + } +} + +static void +modem_property_changed (GDBusProxy *proxy, + const char *property, + GVariant *v, + gpointer user_data) +{ + GVariant *v_child = g_variant_get_child_value (v, 0); + + handle_modem_property (proxy, property, v_child, user_data); + g_variant_unref (v_child); +} + +static void +modem_get_properties_done (GDBusProxy *proxy, GAsyncResult *result, gpointer user_data) +{ + NMModemOfono *self = NM_MODEM_OFONO (user_data); + GError *error = NULL; + GVariant *v_properties, *v_dict, *v; + GVariantIter i; + const char *property; + + nm_log_dbg (LOGD_MB, "in %s", __func__); + + v_properties = _nm_dbus_proxy_call_finish (proxy, + result, + G_VARIANT_TYPE ("(a{sv})"), + &error); + if (!v_properties) { + g_dbus_error_strip_remote_error (error); + nm_log_warn (LOGD_MB, "(%s) error getting modem properties: %s", + nm_modem_get_uid (NM_MODEM (self)), + error->message); + g_error_free (error); + return; + } + + v_dict = g_variant_get_child_value (v_properties, 0); + if (!v_dict) { + nm_log_warn (LOGD_MB, "(%s) error getting modem properties: no v_dict", + nm_modem_get_uid (NM_MODEM (self))); + return; + } + + /* + * TODO: + * 1) optimize by looking up properties ( Online, Interfaces ), instead + * of iterating + * + * 2) reduce code duplication between all of the get_properties_done + * functions in this class. + */ + + g_variant_iter_init (&i, v_dict); + while (g_variant_iter_next (&i, "{&sv}", &property, &v)) { + handle_modem_property (NULL, property, v, self); + g_variant_unref (v); + } + + g_variant_unref (v_dict); + g_variant_unref (v_properties); +} + +NMModem * +nm_modem_ofono_new (const char *path) +{ + g_return_val_if_fail (path != NULL, NULL); + + nm_log_dbg (LOGD_MB, "in %s: path %s", __func__, path); + + return (NMModem *) g_object_new (NM_TYPE_MODEM_OFONO, + NM_MODEM_PATH, path, + NM_MODEM_UID, (path + 1), + NM_MODEM_DEVICE_ID, (path + 1), + NM_MODEM_CONTROL_PORT, "ofono", /* mandatory */ + NM_MODEM_DRIVER, "ofono", + NM_MODEM_STATE, NM_MODEM_STATE_INITIALIZING, + NULL); +} + +static void +stage1_prepare_done (GDBusProxy *proxy, GAsyncResult *result, gpointer user_data) +{ + NMModemOfono *self = NM_MODEM_OFONO (user_data); + NMModemOfonoPrivate *priv = NM_MODEM_OFONO_GET_PRIVATE (self); + GError *error = NULL; + + nm_log_dbg (LOGD_MB, "in %s", __func__); + + if (priv->connect_properties) { + g_hash_table_destroy (priv->connect_properties); + priv->connect_properties = NULL; + } + + g_dbus_proxy_call_finish (proxy, result, &error); + + if (error) { + nm_log_warn (LOGD_MB, "ofono: connection failed: (%d) %s", + error ? error->code : -1, + error && error->message ? error->message : "(unknown)"); + + g_signal_emit_by_name (self, NM_MODEM_PREPARE_RESULT, FALSE, + NM_DEVICE_STATE_REASON_MODEM_BUSY); + /* + * FIXME: add code to check for InProgress so that the + * connection doesn't continue to try and activate, + * leading to the connection being disabled, and a 5m + * timeout... + */ + + g_clear_error (&error); + } +} + +static void +context_property_changed (GDBusProxy *proxy, + const char *property, + GVariant *v, + gpointer user_data) +{ + NMModemOfono *self = NM_MODEM_OFONO (user_data); + NMModemOfonoPrivate *priv = NM_MODEM_OFONO_GET_PRIVATE (self); + NMDeviceStateReason reason = NM_DEVICE_STATE_REASON_NONE; + NMPlatformIP4Address addr; + gboolean ret = FALSE; + GVariant *v_dict; + GVariantIter i; + const gchar *s, *addr_s; + const gchar **array, **iter; + guint32 address_network, gateway_network; + guint prefix = 0; + + nm_log_dbg (LOGD_MB, "PropertyChanged: %s", property); + + /* + * TODO: might be a good idea and re-factor this to mimic bluez-device, + * ie. have this function just check the key, and call a sub-func to + * handle the action. + */ + + if (g_strcmp0 (property, "Settings") != 0) + return; + + v_dict = g_variant_get_child_value (v, 0); + if (!v_dict) { + nm_log_warn (LOGD_MB, "ofono: (%s): error getting IPv4 Settings", + nm_modem_get_uid (NM_MODEM (self))); + goto out; + } + + nm_log_info (LOGD_MB, "ofono: (%s): IPv4 static Settings:", nm_modem_get_uid (NM_MODEM (self))); + + if (g_variant_lookup (v_dict, "Interface", "&s", &s)) { + + nm_log_dbg (LOGD_MB, "(%s): Interface: %s", nm_modem_get_uid (NM_MODEM (self)), s); + + if (s && strlen (s)) { + g_object_set (self, + NM_MODEM_DATA_PORT, g_strdup (s), + NM_MODEM_IP4_METHOD, NM_MODEM_IP_METHOD_STATIC, + NULL); + } else { + nm_log_warn (LOGD_MB, "ofono: (%s): Settings 'Interface'; empty", + nm_modem_get_uid (NM_MODEM (self))); + goto out; + } + + } else { + nm_log_warn (LOGD_MB, "ofono: (%s): Settings 'Interface' missing", + nm_modem_get_uid (NM_MODEM (self))); + goto out; + } + + /* TODO: verify handling of ip4_config; check other places it's used... */ + if (priv->ip4_config) + g_object_unref (priv->ip4_config); + + memset (&addr, 0, sizeof (addr)); + + /* + * TODO: + * + * NM 1.2 changed the NMIP4Config constructor to take an ifindex + * ( vs. void pre 1.2 ), to tie config instance to a specific + * platform interface. + * + * This doesn't work for ofono, as the devices are created + * dynamically ( eg. ril_0, ril_1 ) in NMModemManager. The + * device created doesn't really map directly to a platform + * link. The closest would be one of the devices owned by + * rild ( eg. ccmin0 ), which is passed to us above as + * 'Interface'. + * + * This needs discussion with upstream. + */ + priv->ip4_config = nm_ip4_config_new (0); + + /* TODO: simply if/else error logic! */ + + if (g_variant_lookup (v_dict, "Address", "&s", &addr_s)) { + nm_log_dbg (LOGD_MB, "(%s): Address: %s", nm_modem_get_uid (NM_MODEM (self)), addr_s); + + if (ip_string_to_network_address (addr_s, &address_network)) { + addr.address = address_network; + addr.source = NM_IP_CONFIG_SOURCE_WWAN; + } else { + nm_log_warn (LOGD_MB, "ofono: (%s): can't convert 'Address' %s to addr", + nm_modem_get_uid (NM_MODEM (self)), s); + goto out; + } + + } else { + nm_log_warn (LOGD_MB, "ofono: (%s): Settings 'Address' missing", + nm_modem_get_uid (NM_MODEM (self))); + goto out; + } + + if (g_variant_lookup (v_dict, "Netmask", "&s", &s)) { + + nm_log_dbg (LOGD_MB, "(%s): Netmask: %s", nm_modem_get_uid (NM_MODEM (self)), s); + + if (s && ip_string_to_network_address (s, &address_network)) { + prefix = nm_utils_ip4_netmask_to_prefix (address_network); + if (prefix > 0) + addr.plen = prefix; + } else { + nm_log_warn (LOGD_MB, "ofono: (%s): invalid 'Netmask': %s", + nm_modem_get_uid (NM_MODEM (self)), s); + goto out; + } + + } else { + nm_log_warn (LOGD_MB, "ofono: (%s): Settings 'Netmask' missing", + nm_modem_get_uid (NM_MODEM (self))); + goto out; + } + + nm_log_info (LOGD_MB, "ofono (%s) Address: %s/%d", + nm_modem_get_uid (NM_MODEM (self)), addr_s, prefix); + + nm_ip4_config_add_address (priv->ip4_config, &addr); + + if (g_variant_lookup (v_dict, "Gateway", "&s", &s)) { + + if (s && ip_string_to_network_address (s, &gateway_network)) { + nm_log_info (LOGD_MB, "ofono: (%s): Gateway: %s", nm_modem_get_uid (NM_MODEM (self)), s); + + nm_ip4_config_set_gateway (priv->ip4_config, gateway_network); + } else { + nm_log_warn (LOGD_MB, "ofono: (%s): invalid 'Gateway': %s", + nm_modem_get_uid (NM_MODEM (self)), s); + goto out; + } + + nm_ip4_config_set_gateway (priv->ip4_config, gateway_network); + } else { + nm_log_warn (LOGD_MB, "ofono: (%s): Settings 'Gateway' missing", + nm_modem_get_uid (NM_MODEM (self))); + goto out; + } + + if (g_variant_lookup (v_dict, "DomainNameServers", "^a&s", &array)) { + iter = array; + + while (*iter) { + if (ip_string_to_network_address (*iter, &address_network) && address_network > 0) { + nm_log_info (LOGD_MB, "ofono: (%s): DNS: %s", + nm_modem_get_uid (NM_MODEM (self)), *iter); + + nm_ip4_config_add_nameserver (priv->ip4_config, address_network); + } else { + nm_log_warn (LOGD_MB, "ofono: (%s): invalid NameServer: %s", + nm_modem_get_uid (NM_MODEM (self)), *iter); + } + + *iter++; + } + + if (iter == array) { + nm_log_warn (LOGD_MB, "ofono: (%s): Settings: 'DomainNameServers': none specified", + nm_modem_get_uid (NM_MODEM (self))); + g_free (array); + goto out; + } + + g_free (array); + } else { + nm_log_warn (LOGD_MB, "ofono: (%s): Settings 'DomainNameServers' missing", + nm_modem_get_uid (NM_MODEM (self))); + goto out; + } + + if (g_variant_lookup (v_dict, "MessageProxy", "&s", &s)) { + nm_log_info (LOGD_MB, "ofono: (%s): MessageProxy: %s", + nm_modem_get_uid (NM_MODEM (self)), s); + + if (s && ip_string_to_network_address (s, &address_network)) { + NMPlatformIP4Route mms_route; + + mms_route.network = address_network; + mms_route.plen = 32; + mms_route.gateway = gateway_network; + + mms_route.metric = 1; + + nm_ip4_config_add_route (priv->ip4_config, &mms_route); + } else { + nm_log_warn (LOGD_MB, "ofono: (%s): invalid MessageProxy: %s", + nm_modem_get_uid (NM_MODEM (self)), s); + } + } + + ret = TRUE; + +out: + if (nm_modem_get_state (NM_MODEM (self)) != NM_MODEM_STATE_CONNECTED) { + nm_log_info (LOGD_MB, "ofono: (%s): emitting PREPARE_RESULT: %s", + nm_modem_get_uid (NM_MODEM (self)), ret ? "TRUE" : "FALSE"); + + if (!ret) + reason = NM_DEVICE_STATE_REASON_IP_CONFIG_UNAVAILABLE; + + g_signal_emit_by_name (self, NM_MODEM_PREPARE_RESULT, ret, reason); + } else { + nm_log_warn (LOGD_MB, "ofono: (%s): MODEM_PPP_FAILED", nm_modem_get_uid (NM_MODEM (self))); + + g_signal_emit_by_name (self, NM_MODEM_PPP_FAILED, NM_DEVICE_STATE_REASON_PPP_FAILED); + } +} + +static NMActStageReturn +static_stage3_ip4_config_start (NMModem *_self, + NMActRequest *req, + NMDeviceStateReason *reason) +{ + NMModemOfono *self = NM_MODEM_OFONO (_self); + NMModemOfonoPrivate *priv = NM_MODEM_OFONO_GET_PRIVATE (self); + NMActStageReturn ret = NM_ACT_STAGE_RETURN_FAILURE; + GError *error = NULL; + + nm_log_dbg (LOGD_MB, "(%s): stage_3_ip4_config_start", + nm_modem_get_uid (NM_MODEM (self))); + + if (priv->ip4_config) { + nm_log_dbg (LOGD_MB, "(%s): IP4 config is done; setting modem_state -> CONNECTED", + nm_modem_get_uid (NM_MODEM (self))); + + g_signal_emit_by_name (self, NM_MODEM_IP4_CONFIG_RESULT, priv->ip4_config, error); + + /* TODO: review!!! */ + priv->ip4_config = NULL; + nm_modem_set_state (NM_MODEM (self), + NM_MODEM_STATE_CONNECTED, + nm_modem_state_to_string (NM_MODEM_STATE_CONNECTED)); + ret = NM_ACT_STAGE_RETURN_POSTPONE; + } + + return ret; +} + +static void +context_proxy_new_cb (GDBusProxy *proxy, GAsyncResult *result, gpointer user_data) +{ + NMModemOfono *self = NM_MODEM_OFONO (user_data); + NMModemOfonoPrivate *priv = NM_MODEM_OFONO_GET_PRIVATE (self); + GError *error = NULL; + + nm_log_dbg (LOGD_MB, "%s:", __func__); + + priv->context_proxy = g_dbus_proxy_new_finish (result, &error); + + /* TODO: add path to log msg? */ + if (error) { + nm_log_err (LOGD_MB, "(%s) failed to create ofono ConnectionContext DBus proxy: %s", + nm_modem_get_uid (NM_MODEM (self)), + error->message ? error->message : "(unknown)"); + + g_signal_emit_by_name (self, NM_MODEM_PREPARE_RESULT, FALSE, + NM_DEVICE_STATE_REASON_MODEM_BUSY); + return; + } + + if (!priv->gprs_attached) { + g_signal_emit_by_name (self, NM_MODEM_PREPARE_RESULT, FALSE, + NM_DEVICE_STATE_REASON_MODEM_NO_CARRIER); + return; + } + + /* We have an old copy of the settings from a previous activation, + * clear it so that we can gate getting the IP config from oFono + * on whether or not we have already received them + */ + if (priv->ip4_config) + g_clear_object (&priv->ip4_config); + + /* Watch for custom ofono PropertyChanged signals */ + _nm_dbus_signal_connect (priv->context_proxy, + "PropertyChanged", + G_VARIANT_TYPE ("(sv)"), + G_CALLBACK (context_property_changed), + self); + + g_dbus_proxy_call (priv->context_proxy, + "SetProperty", + g_variant_new ("(sv)", + "Active", + g_variant_new ("b", TRUE)), + G_DBUS_CALL_FLAGS_NONE, + 20000, + NULL, + (GAsyncReadyCallback) stage1_prepare_done, + g_object_ref (self)); +} + +static void +do_context_activate (NMModemOfono *self) +{ + NMModemOfonoPrivate *priv = NM_MODEM_OFONO_GET_PRIVATE (self); + GValue value = G_VALUE_INIT; + + g_return_val_if_fail (self != NULL, FALSE); + g_return_val_if_fail (NM_IS_MODEM_OFONO (self), FALSE); + + nm_log_dbg (LOGD_MB, "in %s", __func__); + + g_value_init (&value, G_TYPE_BOOLEAN); + g_value_set_boolean (&value, TRUE); + + if (priv->context_proxy) + g_clear_object (&priv->context_proxy); + + g_dbus_proxy_new (priv->dbus_connection, + G_DBUS_OBJECT_MANAGER_CLIENT_FLAGS_DO_NOT_AUTO_START, + NULL, + OFONO_DBUS_SERVICE, + priv->context_path, + OFONO_DBUS_INTERFACE_CONNECTION_CONTEXT, + NULL, + (GAsyncReadyCallback) context_proxy_new_cb, + g_object_ref (self)); +} + +static GHashTable * +create_connect_properties (NMConnection *connection) +{ + NMSettingGsm *setting; + GHashTable *properties; + const char *str; + + nm_log_dbg (LOGD_MB, "in %s", __func__); + + setting = nm_connection_get_setting_gsm (connection); + properties = g_hash_table_new (g_str_hash, g_str_equal); + + str = nm_setting_gsm_get_apn (setting); + if (str) + g_hash_table_insert (properties, "AccessPointName", g_strdup (str)); + + str = nm_setting_gsm_get_username (setting); + if (str) + g_hash_table_insert (properties, "Username", g_strdup (str)); + + str = nm_setting_gsm_get_password (setting); + if (str) + g_hash_table_insert (properties, "Password", g_strdup (str)); + + return properties; +} + +static NMActStageReturn +act_stage1_prepare (NMModem *modem, + NMConnection *connection, + NMDeviceStateReason *reason) +{ + NMModemOfono *self = NM_MODEM_OFONO (modem); + NMModemOfonoPrivate *priv = NM_MODEM_OFONO_GET_PRIVATE (self); + const char *context_id; + char **id = NULL; + + nm_log_dbg (LOGD_MB, "%s", __func__); + + context_id = nm_connection_get_id (connection); + id = g_strsplit (context_id, "/", 0); + g_assert (id[2]); + + nm_log_dbg (LOGD_MB, " trying %s %s", id[1], id[2]); + + if (priv->context_path) + g_free (priv->context_path); + + priv->context_path = g_strdup_printf ("%s/%s", + nm_modem_get_path (modem), + id[2]); + g_strfreev (id); + + if (!priv->context_path) { + *reason = NM_DEVICE_STATE_REASON_GSM_APN_FAILED; + return NM_ACT_STAGE_RETURN_FAILURE; + } + + if (priv->connect_properties) + g_hash_table_destroy (priv->connect_properties); + + priv->connect_properties = create_connect_properties (connection); + + nm_log_info (LOGD_MB, "(%s): activating context %s", + nm_modem_get_path (modem), + priv->context_path); + + if (nm_modem_get_state (modem) == NM_MODEM_STATE_REGISTERED) { + do_context_activate (self); + } else { + nm_log_warn (LOGD_MB, "(%s): could not activate context, " + "modem is not registered.", + nm_modem_get_path (modem)); + *reason = NM_DEVICE_STATE_REASON_MODEM_NO_CARRIER; + return NM_ACT_STAGE_RETURN_FAILURE; + } + + return NM_ACT_STAGE_RETURN_POSTPONE; +} + +static void +modem_proxy_new_cb (GDBusProxy *proxy, GAsyncResult *result, gpointer user_data) +{ + NMModemOfono *self = NM_MODEM_OFONO (user_data); + NMModemOfonoPrivate *priv = NM_MODEM_OFONO_GET_PRIVATE (self); + GError *error = NULL; + + nm_log_dbg (LOGD_MB, "in %s", __func__); + + priv->modem_proxy = g_dbus_proxy_new_finish (result, &error); + + if (error) { + nm_log_err (LOGD_MB, "(%s) failed to create ofono modem DBus proxy: %s", + nm_modem_get_uid (NM_MODEM (self)), + error->message ? error->message : "(unknown)"); + + return; + } + + /* Watch for custom ofono PropertyChanged signals */ + _nm_dbus_signal_connect (priv->modem_proxy, + "PropertyChanged", + G_VARIANT_TYPE ("(sv)"), + G_CALLBACK (modem_property_changed), + self); + + g_dbus_proxy_call (priv->modem_proxy, + "GetProperties", + NULL, + G_DBUS_CALL_FLAGS_NONE, + 20000, + NULL, + (GAsyncReadyCallback) modem_get_properties_done, + g_object_ref (self)); + + g_object_unref (self); +} + +static void +bus_connected (NMModemOfono *self) +{ + NMModemOfonoPrivate *priv = NM_MODEM_OFONO_GET_PRIVATE (self); + + nm_log_dbg (LOGD_MB, "in %s", __func__); + + g_dbus_proxy_new (priv->dbus_connection, + G_DBUS_OBJECT_MANAGER_CLIENT_FLAGS_DO_NOT_AUTO_START, + NULL, + OFONO_DBUS_SERVICE, + nm_modem_get_path (NM_MODEM (self)), + OFONO_DBUS_INTERFACE_MODEM, + NULL, + (GAsyncReadyCallback) modem_proxy_new_cb, + g_object_ref (self)); +} + +static void +bus_get_ready (GObject *source, + GAsyncResult *result, + NMModemOfono *self) +{ + /* Note we always get an extra reference to self here */ + NMModemOfonoPrivate *priv = NM_MODEM_OFONO_GET_PRIVATE (self); + GError *error = NULL; + + nm_log_dbg (LOGD_MB, "in %s", __func__); + + priv->dbus_connection = g_bus_get_finish (result, &error); + if (!priv->dbus_connection) { + nm_log_warn (LOGD_CORE, "error getting bus connection: %s", error->message); + g_error_free (error); + + /* FIXME (awe): what do do if bus connection fails??? */ + } else { + /* Got the bus, ensure client */ + bus_connected (self); + } + + /* Balance refcount */ + g_object_unref (self); +} + +static gboolean +ensure_bus (NMModemOfono *self) +{ + /* FIXME: not sure how dbus_connection could ever be set here? */ + NMModemOfonoPrivate *priv = NM_MODEM_OFONO_GET_PRIVATE (self); + + nm_log_dbg (LOGD_MB, "in %s", __func__); + + if (!priv->dbus_connection) + g_bus_get (G_BUS_TYPE_SYSTEM, + NULL, + (GAsyncReadyCallback) bus_get_ready, + g_object_ref (self)); + else + bus_connected (self); + + return FALSE; +} + +static void +nm_modem_ofono_init (NMModemOfono *self) +{ + NMModemOfonoPrivate *priv = NM_MODEM_OFONO_GET_PRIVATE (self); + + nm_log_dbg (LOGD_MB, "in %s", __func__); + + priv->dbus_connection = NULL; + + priv->modem_proxy = NULL; + priv->connman_proxy = NULL; + priv->context_proxy = NULL; + priv->sim_proxy = NULL; + + priv->modem_online = FALSE; + priv->gprs_attached = FALSE; + + priv->ip4_config = NULL; + + ensure_bus (self); +} + +static GObject* +constructor (GType type, + guint n_construct_params, + GObjectConstructParam *construct_params) +{ + GObject *object; + NMModemOfonoPrivate *priv; + + nm_log_dbg (LOGD_MB, "in %s", __func__); + + object = G_OBJECT_CLASS (nm_modem_ofono_parent_class)->constructor (type, n_construct_params, construct_params); + if (!object) + return NULL; + + priv = NM_MODEM_OFONO_GET_PRIVATE (object); + + return object; +} + +static void +dispose (GObject *object) +{ + NMModemOfono *self = NM_MODEM_OFONO (object); + NMModemOfonoPrivate *priv = NM_MODEM_OFONO_GET_PRIVATE (self); + + nm_log_dbg (LOGD_MB, "in %s", __func__); + + if (priv->connect_properties) { + g_hash_table_destroy (priv->connect_properties); + priv->connect_properties = NULL; + } + + if (priv->ip4_config) + g_clear_object (&priv->ip4_config); + + if (priv->modem_proxy) { + g_signal_handlers_disconnect_by_data (priv->modem_proxy, NM_MODEM_OFONO (self)); + g_clear_object (&priv->modem_proxy); + } + + if (priv->connman_proxy) + g_clear_object (&priv->connman_proxy); + if (priv->context_proxy) + g_clear_object (&priv->context_proxy); + + if (priv->sim_proxy) { + g_signal_handlers_disconnect_by_data (priv->sim_proxy, NM_MODEM_OFONO (self)); + g_clear_object (&priv->sim_proxy); + } + + g_clear_object (&priv->dbus_connection); + + if (priv->imsi) { + g_free (priv->imsi); + priv->imsi = NULL; + } + + G_OBJECT_CLASS (nm_modem_ofono_parent_class)->dispose (object); +} + +static void +nm_modem_ofono_class_init (NMModemOfonoClass *klass) +{ + GObjectClass *object_class = G_OBJECT_CLASS (klass); + NMModemClass *modem_class = NM_MODEM_CLASS (klass); + + nm_log_dbg (LOGD_MB, "in %s", __func__); + + g_type_class_add_private (object_class, sizeof (NMModemOfonoPrivate)); + + /* Virtual methods */ + object_class->constructor = constructor; + object_class->dispose = dispose; + + modem_class->get_capabilities = get_capabilities; + modem_class->disconnect = disconnect; + modem_class->disconnect_finish = disconnect_finish; + modem_class->deactivate_cleanup = deactivate_cleanup; + modem_class->check_connection_compatible = check_connection_compatible; + + /* same as nm-modem-broadband */ + modem_class->act_stage1_prepare = act_stage1_prepare; + + /* same as nm-modem-broadband */ + modem_class->static_stage3_ip4_config_start = static_stage3_ip4_config_start; +} diff --git a/src/devices/wwan/nm-modem-ofono.h b/src/devices/wwan/nm-modem-ofono.h new file mode 100644 index 0000000000..fa79e156c0 --- /dev/null +++ b/src/devices/wwan/nm-modem-ofono.h @@ -0,0 +1,64 @@ +/* -*- Mode: C; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */ +/* NetworkManager -- Network link manager + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Copyright (C) 2013 - Canonical Ltd. + */ + +#ifndef NM_MODEM_OFONO_H +#define NM_MODEM_OFONO_H + +#include + +G_BEGIN_DECLS + +#define NM_TYPE_MODEM_OFONO (nm_modem_ofono_get_type ()) +#define NM_MODEM_OFONO(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), NM_TYPE_MODEM_OFONO, NMModemOfono)) +#define NM_IS_MODEM_OFONO(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), NM_TYPE_MODEM_OFONO)) +#define NM_MODEM_OFONO_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), NM_TYPE_MODEM_OFONO, NMModemOfonoClass)) +#define NM_IS_MODEM_OFONO_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), NM_TYPE_MODEM_OFONO)) +#define NM_MODEM_OFONO_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), NM_TYPE_MODEM_OFONO, NMModemOfonoClass)) +#define NM_MODEM_OFONO_MODEM "modem" + +#define OFONO_DBUS_SERVICE "org.ofono" +#define OFONO_DBUS_PATH "/" +#define OFONO_DBUS_INTERFACE "org.ofono.Manager" +#define OFONO_DBUS_INTERFACE_MODEM "org.ofono.Modem" +#define OFONO_DBUS_INTERFACE_CONNECTION_MANAGER "org.ofono.ConnectionManager" +#define OFONO_DBUS_INTERFACE_CONNECTION_CONTEXT "org.ofono.ConnectionContext" +#define OFONO_DBUS_INTERFACE_SIM_MANAGER "org.ofono.SimManager" + +typedef enum { + NM_OFONO_ERROR_CONNECTION_NOT_OFONO = 0, /*< nick=ConnectionNotOfono >*/ + NM_OFONO_ERROR_CONNECTION_INVALID, /*< nick=ConnectionInvalid >*/ + NM_OFONO_ERROR_CONNECTION_INCOMPATIBLE, /*< nick=ConnectionIncompatible >*/ +} NMOfonoError; + +typedef struct { + NMModem parent; +} NMModemOfono; + +typedef struct { + NMModemClass parent; +} NMModemOfonoClass; + +GType nm_modem_ofono_get_type (void); + +NMModem *nm_modem_ofono_new (const char *path); + +G_END_DECLS + +#endif /* NM_MODEM_OFONO_H */ diff --git a/src/devices/wwan/nm-modem.c b/src/devices/wwan/nm-modem.c index a6c770072c..2e3d63bb83 100644 --- a/src/devices/wwan/nm-modem.c +++ b/src/devices/wwan/nm-modem.c @@ -202,7 +202,9 @@ nm_modem_set_mm_enabled (NMModem *self, return; } - NM_MODEM_GET_CLASS (self)->set_mm_enabled (self, enabled); + /* Not all modem classes support set_mm_enabled */ + if (NM_MODEM_GET_CLASS (self)->set_mm_enabled) + NM_MODEM_GET_CLASS (self)->set_mm_enabled (self, enabled); /* Pre-empt the state change signal */ nm_modem_set_state (self, @@ -573,6 +575,8 @@ nm_modem_stage3_ip4_config_start (NMModem *self, const char *method; NMActStageReturn ret; + nm_log_dbg (LOGD_MB, "ip4_config_start"); + g_return_val_if_fail (NM_IS_MODEM (self), NM_ACT_STAGE_RETURN_FAILURE); g_return_val_if_fail (NM_IS_DEVICE (device), NM_ACT_STAGE_RETURN_FAILURE); g_return_val_if_fail (NM_IS_DEVICE_CLASS (device_class), NM_ACT_STAGE_RETURN_FAILURE); @@ -602,9 +606,11 @@ nm_modem_stage3_ip4_config_start (NMModem *self, ret = ppp_stage3_ip_config_start (self, req, reason); break; case NM_MODEM_IP_METHOD_STATIC: + nm_log_dbg (LOGD_MB, "MODEM_IP_METHOD_STATIC"); ret = NM_MODEM_GET_CLASS (self)->static_stage3_ip4_config_start (self, req, reason); break; case NM_MODEM_IP_METHOD_AUTO: + nm_log_dbg (LOGD_MB, "MODEM_IP_METHOD_AUTO"); ret = device_class->act_stage3_ip4_config_start (device, NULL, reason); break; default: diff --git a/src/nm-core-utils.c b/src/nm-core-utils.c index b20653838d..8c5c0a8b44 100644 --- a/src/nm-core-utils.c +++ b/src/nm-core-utils.c @@ -2558,7 +2558,13 @@ _get_property_path (const char *ifname, ipv6 ? IPV6_PROPERTY_DIR : IPV4_PROPERTY_DIR, ifname, property); - g_assert (len < sizeof (path) - 1); + + /* Ubuntu: don't assert, but log about the inconsistent size. */ + if (len > sizeof (path) - 1) + nm_log_warn (LOGD_CORE, + "IPv6 property path is too long: '" + IPV6_PROPERTY_DIR "%s/%s'", + ifname, property); return path; } @@ -2622,9 +2628,15 @@ NM_ASSERT_VALID_PATH_COMPONENT (const char *name) nm_log_err (LOGD_CORE, "Failed asserting path component: %s%s%s", NM_PRINT_FMT_QUOTED (name, "\"", name, "\"", "(null)")); - g_error ("FATAL: Failed asserting path component: %s%s%s", - NM_PRINT_FMT_QUOTED (name, "\"", name, "\"", "(null)")); - g_assert_not_reached (); + + /* Ubuntu: Don't outright fail, just return the name again. It's + * logged as being invalid, which is enough. + * There is a use of slashes in paths for oFono modems, which are + * actually valid paths to refer to an oFono modem, just don't map to + * anything on the filesystem. The following calls to sysctl paths can + * (and will) fail, but that's fine. + */ + return name; } gboolean From 1b570723b4bcb8b0e2b7026a1424d61454656e3c Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Mon, 13 Jun 2016 16:59:25 +0200 Subject: [PATCH 03/30] trivial: style issues and indention --- src/devices/wwan/nm-device-modem.c | 2 - src/devices/wwan/nm-modem-manager.c | 71 +++---- src/devices/wwan/nm-modem-ofono.c | 299 ++++++++++++++-------------- src/nm-core-utils.c | 11 +- 4 files changed, 192 insertions(+), 191 deletions(-) diff --git a/src/devices/wwan/nm-device-modem.c b/src/devices/wwan/nm-device-modem.c index d69804e816..0f96dafbfc 100644 --- a/src/devices/wwan/nm-device-modem.c +++ b/src/devices/wwan/nm-device-modem.c @@ -112,7 +112,6 @@ modem_prepare_result (NMModem *modem, if (success) nm_device_activate_schedule_stage2_device_config (device); else { - if (reason == NM_DEVICE_STATE_REASON_SIM_PIN_INCORRECT) { /* If the connect failed because the SIM PIN was wrong don't allow * the device to be auto-activated anymore, which would risk locking @@ -563,7 +562,6 @@ get_ip_iface_identifier (NMDevice *device, NMUtilsIPv6IfaceId *out_iid) g_return_val_if_fail (priv->modem, FALSE); success = nm_modem_get_iid (priv->modem, out_iid); - if (!success) success = NM_DEVICE_CLASS (nm_device_modem_parent_class)->get_ip_iface_identifier (device, out_iid); return success; diff --git a/src/devices/wwan/nm-modem-manager.c b/src/devices/wwan/nm-modem-manager.c index bab2e91810..fec25e5b20 100644 --- a/src/devices/wwan/nm-modem-manager.c +++ b/src/devices/wwan/nm-modem-manager.c @@ -225,9 +225,10 @@ ofono_clear_signals (NMModemManager *self) if (self->priv->ofono_name_owner_changed_id) { if (g_signal_handler_is_connected (self->priv->ofono_proxy, - self->priv->ofono_name_owner_changed_id)) + self->priv->ofono_name_owner_changed_id)) { g_signal_handler_disconnect (self->priv->ofono_proxy, - self->priv->ofono_name_owner_changed_id); + self->priv->ofono_name_owner_changed_id); + } self->priv->ofono_name_owner_changed_id = 0; } } @@ -252,10 +253,10 @@ ofono_create_modem (NMModemManager *self, const char *path) static void ofono_signal_cb (GDBusProxy *proxy, - gchar *sender_name, - gchar *signal_name, - GVariant *parameters, - gpointer user_data) + gchar *sender_name, + gchar *signal_name, + GVariant *parameters, + gpointer user_data) { NMModemManager *self = NM_MODEM_MANAGER (user_data); gchar *object_path; @@ -277,7 +278,7 @@ ofono_signal_cb (GDBusProxy *proxy, g_hash_table_remove (self->priv->modems, object_path); } else { nm_log_warn (LOGD_MB, "could not remove modem %s, not found in table", - object_path); + object_path); } g_free (object_path); } @@ -298,16 +299,16 @@ ofono_enumerate_devices_done (GDBusProxy *proxy, GAsyncResult *res, gpointer use results = g_dbus_proxy_call_finish (proxy, res, &error); if (results) { g_variant_get (results, "(a(oa{sv}))", &iter); - while (g_variant_iter_loop (iter, "(&oa{sv})", &path, NULL)) { + while (g_variant_iter_loop (iter, "(&oa{sv})", &path, NULL)) ofono_create_modem (manager, path); - } g_variant_iter_free (iter); g_variant_unref (results); } - if (error) + if (error) { nm_log_warn (LOGD_MB, "failed to enumerate oFono devices: %s", - error->message ? error->message : "(unknown)"); + error->message ? error->message : "(unknown)"); + } } static void ofono_appeared (NMModemManager *self); @@ -338,8 +339,8 @@ free: static void ofono_name_owner_changed (GDBusProxy *ofono_proxy, - GParamSpec *pspec, - NMModemManager *self) + GParamSpec *pspec, + NMModemManager *self) { ofono_check_name_owner (self); } @@ -350,23 +351,23 @@ ofono_appeared (NMModemManager *self) nm_log_info (LOGD_MB, "ofono is now available"); self->priv->ofono_name_owner_changed_id = - g_signal_connect (self->priv->ofono_proxy, - "notify::name-owner", - G_CALLBACK (ofono_name_owner_changed), - self); + g_signal_connect (self->priv->ofono_proxy, + "notify::name-owner", + G_CALLBACK (ofono_name_owner_changed), + self); g_dbus_proxy_call (self->priv->ofono_proxy, - "GetModems", - NULL, - G_DBUS_CALL_FLAGS_NONE, - -1, - NULL, - (GAsyncReadyCallback) ofono_enumerate_devices_done, - g_object_ref (self)); + "GetModems", + NULL, + G_DBUS_CALL_FLAGS_NONE, + -1, + NULL, + (GAsyncReadyCallback) ofono_enumerate_devices_done, + g_object_ref (self)); g_signal_connect (self->priv->ofono_proxy, - "g-signal", - G_CALLBACK (ofono_signal_cb), - self); + "g-signal", + G_CALLBACK (ofono_signal_cb), + self); } static void @@ -522,14 +523,14 @@ ensure_client (NMModemManager *self) #if WITH_OFONO if (!priv->ofono_proxy) { g_dbus_proxy_new (priv->dbus_connection, - G_DBUS_OBJECT_MANAGER_CLIENT_FLAGS_DO_NOT_AUTO_START, - NULL, - OFONO_DBUS_SERVICE, - OFONO_DBUS_PATH, - OFONO_DBUS_INTERFACE, - NULL, - (GAsyncReadyCallback) ofono_proxy_new_cb, - g_object_ref (self)); + G_DBUS_OBJECT_MANAGER_CLIENT_FLAGS_DO_NOT_AUTO_START, + NULL, + OFONO_DBUS_SERVICE, + OFONO_DBUS_PATH, + OFONO_DBUS_INTERFACE, + NULL, + (GAsyncReadyCallback) ofono_proxy_new_cb, + g_object_ref (self)); created = TRUE; } #endif /* WITH_OFONO */ diff --git a/src/devices/wwan/nm-modem-ofono.c b/src/devices/wwan/nm-modem-ofono.c index 2b43b08cc8..9535f2a792 100644 --- a/src/devices/wwan/nm-modem-ofono.c +++ b/src/devices/wwan/nm-modem-ofono.c @@ -194,15 +194,15 @@ disconnect_done (GDBusProxy *proxy, g_dbus_proxy_call_finish (proxy, result, &error); if (g_error_matches (error, G_IO_ERROR, G_IO_ERROR_CANCELLED)) { nm_log_dbg (LOGD_MB, "(%s): disconnect cancelled", - nm_modem_get_uid (NM_MODEM (self))); + nm_modem_get_uid (NM_MODEM (self))); return; } if (error) { if (ctx->warn) nm_log_warn (LOGD_MB, "(%s) failed to disconnect modem: %s", - nm_modem_get_uid (NM_MODEM (self)), - error && error->message ? error->message : "(unknown)"); + nm_modem_get_uid (NM_MODEM (self)), + error && error->message ? error->message : "(unknown)"); g_clear_error (&error); } @@ -237,30 +237,31 @@ disconnect (NMModem *self, ctx->self = g_object_ref (self); ctx->warn = warn; - if (callback) + if (callback) { ctx->result = g_simple_async_result_new (G_OBJECT (self), - callback, - user_data, - disconnect); + callback, + user_data, + disconnect); + } /* Setup cancellable */ ctx->cancellable = cancellable ? g_object_ref (cancellable) : NULL; if (disconnect_context_complete_if_cancelled (ctx)) return; nm_modem_set_state (NM_MODEM (self), - NM_MODEM_STATE_DISCONNECTING, - nm_modem_state_to_string (NM_MODEM_STATE_DISCONNECTING)); + NM_MODEM_STATE_DISCONNECTING, + nm_modem_state_to_string (NM_MODEM_STATE_DISCONNECTING)); g_dbus_proxy_call (priv->context_proxy, - "SetProperty", - g_variant_new ("(sv)", - "Active", - g_variant_new ("b", warn)), - G_DBUS_CALL_FLAGS_NONE, - 20000, - NULL, - (GAsyncReadyCallback) disconnect_done, - ctx); + "SetProperty", + g_variant_new ("(sv)", + "Active", + g_variant_new ("b", warn)), + G_DBUS_CALL_FLAGS_NONE, + 20000, + NULL, + (GAsyncReadyCallback) disconnect_done, + ctx); } static void @@ -280,7 +281,7 @@ deactivate_cleanup (NMModem *_self, NMDevice *device) static gboolean check_connection_compatible (NMModem *modem, - NMConnection *connection) + NMConnection *connection) { NMModemOfono *self = NM_MODEM_OFONO (modem); NMModemOfonoPrivate *priv = NM_MODEM_OFONO_GET_PRIVATE (self); @@ -301,7 +302,7 @@ check_connection_compatible (NMModem *modem, if (!priv->imsi) { nm_log_warn (LOGD_MB, "ofono (%s): check_connection %s failed: no IMSI", - nm_modem_get_uid (NM_MODEM (self)), id); + nm_modem_get_uid (NM_MODEM (self)), id); return FALSE; } @@ -358,9 +359,9 @@ handle_sim_property (GDBusProxy *proxy, } sim_property_changed (GDBusProxy *proxy, - const char *property, - GVariant *v, - gpointer user_data) + const char *property, + GVariant *v, + gpointer user_data) { GVariant *v_child = g_variant_get_child_value (v, 0); @@ -380,13 +381,13 @@ sim_get_properties_done (GDBusProxy *proxy, GAsyncResult *result, gpointer user_ nm_log_dbg (LOGD_MB, "%s", __func__); v_properties = _nm_dbus_proxy_call_finish (proxy, - result, - G_VARIANT_TYPE ("(a{sv})"), - &error); + result, + G_VARIANT_TYPE ("(a{sv})"), + &error); if (!v_properties) { g_dbus_error_strip_remote_error (error); nm_log_warn (LOGD_MB, "(%s) error getting sim properties: %s", - nm_modem_get_uid (NM_MODEM (self)), + nm_modem_get_uid (NM_MODEM (self)), error->message); g_error_free (error); return; @@ -397,7 +398,7 @@ sim_get_properties_done (GDBusProxy *proxy, GAsyncResult *result, gpointer user_ v_dict = g_variant_get_child_value (v_properties, 0); if (!v_dict) { nm_log_warn (LOGD_MB, "(%s) error getting sim properties: no v_dict", - nm_modem_get_uid (NM_MODEM (self))); + nm_modem_get_uid (NM_MODEM (self))); return; } @@ -431,7 +432,7 @@ handle_sim_iface (NMModemOfono *self, gboolean found) if (!found && priv->sim_proxy) { nm_log_info (LOGD_MB, "(%s): SimManager interface disappeared", - nm_modem_get_path (NM_MODEM (self))); + nm_modem_get_path (NM_MODEM (self))); g_signal_handlers_disconnect_by_data (priv->sim_proxy, NM_MODEM_OFONO (self)); g_clear_object (&priv->sim_proxy); @@ -445,23 +446,23 @@ handle_sim_iface (NMModemOfono *self, gboolean found) GDBusProxyFlags flags; nm_log_info (LOGD_MB, "(%s): found new SimManager interface", - nm_modem_get_path (NM_MODEM (self))); + nm_modem_get_path (NM_MODEM (self))); flags |= G_DBUS_PROXY_FLAGS_DO_NOT_LOAD_PROPERTIES; flags |= G_DBUS_PROXY_FLAGS_DO_NOT_AUTO_START; priv->sim_proxy = g_dbus_proxy_new_sync (priv->dbus_connection, - flags, - NULL, /* GDBusInterfaceInfo */ - OFONO_DBUS_SERVICE, - nm_modem_get_path (NM_MODEM (self)), - OFONO_DBUS_INTERFACE_SIM_MANAGER, - NULL, /* GCancellable */ - &error); + flags, + NULL, /* GDBusInterfaceInfo */ + OFONO_DBUS_SERVICE, + nm_modem_get_path (NM_MODEM (self)), + OFONO_DBUS_INTERFACE_SIM_MANAGER, + NULL, /* GCancellable */ + &error); if (priv->sim_proxy == NULL) { nm_log_warn (LOGD_MB, "(%s) failed to create SimManager proxy: %s", - nm_modem_get_uid (NM_MODEM (self)), - error && error->message ? error->message : "(unknown)"); + nm_modem_get_uid (NM_MODEM (self)), + error && error->message ? error->message : "(unknown)"); g_error_free (error); return; @@ -469,27 +470,27 @@ handle_sim_iface (NMModemOfono *self, gboolean found) /* Watch for custom ofono PropertyChanged signals */ _nm_dbus_signal_connect (priv->sim_proxy, - "PropertyChanged", - G_VARIANT_TYPE ("(sv)"), - G_CALLBACK (sim_property_changed), - self); + "PropertyChanged", + G_VARIANT_TYPE ("(sv)"), + G_CALLBACK (sim_property_changed), + self); g_dbus_proxy_call (priv->sim_proxy, - "GetProperties", - NULL, - G_DBUS_CALL_FLAGS_NONE, - 20000, - NULL, - (GAsyncReadyCallback) sim_get_properties_done, - g_object_ref (self)); + "GetProperties", + NULL, + G_DBUS_CALL_FLAGS_NONE, + 20000, + NULL, + (GAsyncReadyCallback) sim_get_properties_done, + g_object_ref (self)); } } static void handle_connman_property (GDBusProxy *proxy, - const char *property, - GVariant *v, - gpointer user_data) + const char *property, + GVariant *v, + gpointer user_data) { NMModemOfono *self = NM_MODEM_OFONO (user_data); NMModemOfonoPrivate *priv = NM_MODEM_OFONO_GET_PRIVATE (self); @@ -498,15 +499,15 @@ handle_connman_property (GDBusProxy *proxy, gboolean attached = g_variant_get_boolean (v); nm_log_dbg (LOGD_MB, "(%s): Attached: %s", - nm_modem_get_uid (NM_MODEM (self)), attached ? "True" : "False"); + nm_modem_get_uid (NM_MODEM (self)), attached ? "True" : "False"); if (priv->gprs_attached != attached) { priv->gprs_attached = attached; nm_log_info (LOGD_MB, "(%s): %s: new value for 'Attached': %s", - nm_modem_get_path (NM_MODEM (self)), - __func__, - attached ? "true" : "false"); + nm_modem_get_path (NM_MODEM (self)), + __func__, + attached ? "true" : "false"); update_modem_state (self); } @@ -515,9 +516,9 @@ handle_connman_property (GDBusProxy *proxy, static void connman_property_changed (GDBusProxy *proxy, - const char *property, - GVariant *v, - gpointer user_data) + const char *property, + GVariant *v, + gpointer user_data) { GVariant *v_child = g_variant_get_child_value (v, 0); @@ -537,13 +538,13 @@ connman_get_properties_done (GDBusProxy *proxy, GAsyncResult *result, gpointer u nm_log_dbg (LOGD_MB, "%s", __func__); v_properties = _nm_dbus_proxy_call_finish (proxy, - result, - G_VARIANT_TYPE ("(a{sv})"), - &error); + result, + G_VARIANT_TYPE ("(a{sv})"), + &error); if (!v_properties) { g_dbus_error_strip_remote_error (error); nm_log_warn (LOGD_MB, "(%s) error getting connman properties: %s", - nm_modem_get_uid (NM_MODEM (self)), + nm_modem_get_uid (NM_MODEM (self)), error->message); g_error_free (error); return; @@ -579,7 +580,7 @@ handle_connman_iface (NMModemOfono *self, gboolean found) if (!found && priv->connman_proxy) { nm_log_info (LOGD_MB, "(%s): ConnectionManager interface disappeared", - nm_modem_get_path (NM_MODEM (self))); + nm_modem_get_path (NM_MODEM (self))); g_signal_handlers_disconnect_by_data (priv->connman_proxy, NM_MODEM_OFONO (self)); g_clear_object (&priv->connman_proxy); @@ -595,23 +596,23 @@ handle_connman_iface (NMModemOfono *self, gboolean found) GDBusProxyFlags flags; nm_log_info (LOGD_MB, "(%s): found new ConnectionManager interface", - nm_modem_get_path (NM_MODEM (self))); + nm_modem_get_path (NM_MODEM (self))); flags |= G_DBUS_PROXY_FLAGS_DO_NOT_LOAD_PROPERTIES; flags |= G_DBUS_PROXY_FLAGS_DO_NOT_AUTO_START; priv->connman_proxy = g_dbus_proxy_new_sync (priv->dbus_connection, - flags, - NULL, /* GDBusInterfaceInfo */ - OFONO_DBUS_SERVICE, - nm_modem_get_path (NM_MODEM (self)), - OFONO_DBUS_INTERFACE_CONNECTION_MANAGER, - NULL, /* GCancellable */ - &error); + flags, + NULL, /* GDBusInterfaceInfo */ + OFONO_DBUS_SERVICE, + nm_modem_get_path (NM_MODEM (self)), + OFONO_DBUS_INTERFACE_CONNECTION_MANAGER, + NULL, /* GCancellable */ + &error); if (priv->connman_proxy == NULL) { nm_log_warn (LOGD_MB, "(%s) failed to create ConnectionManager proxy: %s", - nm_modem_get_uid (NM_MODEM (self)), - error && error->message ? error->message : "(unknown)"); + nm_modem_get_uid (NM_MODEM (self)), + error && error->message ? error->message : "(unknown)"); g_error_free (error); return; @@ -619,19 +620,19 @@ handle_connman_iface (NMModemOfono *self, gboolean found) /* Watch for custom ofono PropertyChanged signals */ _nm_dbus_signal_connect (priv->connman_proxy, - "PropertyChanged", - G_VARIANT_TYPE ("(sv)"), - G_CALLBACK (connman_property_changed), - self); + "PropertyChanged", + G_VARIANT_TYPE ("(sv)"), + G_CALLBACK (connman_property_changed), + self); g_dbus_proxy_call (priv->connman_proxy, - "GetProperties", - NULL, - G_DBUS_CALL_FLAGS_NONE, - 20000, - NULL, - (GAsyncReadyCallback) connman_get_properties_done, - g_object_ref (self)); + "GetProperties", + NULL, + G_DBUS_CALL_FLAGS_NONE, + 20000, + NULL, + (GAsyncReadyCallback) connman_get_properties_done, + g_object_ref (self)); /* NM 0.9.10x version registers for "ContextAdded/Removed", but * did nothing but log a message. Removed for 1.2 @@ -652,14 +653,14 @@ handle_modem_property (GDBusProxy *proxy, gboolean online = g_variant_get_boolean (v); nm_log_dbg (LOGD_MB, "(%s): Online: %s", - nm_modem_get_uid (NM_MODEM (self)), online ? "True" : "False"); + nm_modem_get_uid (NM_MODEM (self)), online ? "True" : "False"); if (online != priv->modem_online) { priv->modem_online = online; nm_log_info (LOGD_MB, "(%s) modem is now %s", - nm_modem_get_path (NM_MODEM (self)), - online ? "Online" : "Offline"); + nm_modem_get_path (NM_MODEM (self)), + online ? "Online" : "Offline"); update_modem_state (self); } @@ -695,9 +696,9 @@ handle_modem_property (GDBusProxy *proxy, static void modem_property_changed (GDBusProxy *proxy, - const char *property, - GVariant *v, - gpointer user_data) + const char *property, + GVariant *v, + gpointer user_data) { GVariant *v_child = g_variant_get_child_value (v, 0); @@ -717,13 +718,13 @@ modem_get_properties_done (GDBusProxy *proxy, GAsyncResult *result, gpointer use nm_log_dbg (LOGD_MB, "in %s", __func__); v_properties = _nm_dbus_proxy_call_finish (proxy, - result, - G_VARIANT_TYPE ("(a{sv})"), - &error); + result, + G_VARIANT_TYPE ("(a{sv})"), + &error); if (!v_properties) { g_dbus_error_strip_remote_error (error); nm_log_warn (LOGD_MB, "(%s) error getting modem properties: %s", - nm_modem_get_uid (NM_MODEM (self)), + nm_modem_get_uid (NM_MODEM (self)), error->message); g_error_free (error); return; @@ -732,7 +733,7 @@ modem_get_properties_done (GDBusProxy *proxy, GAsyncResult *result, gpointer use v_dict = g_variant_get_child_value (v_properties, 0); if (!v_dict) { nm_log_warn (LOGD_MB, "(%s) error getting modem properties: no v_dict", - nm_modem_get_uid (NM_MODEM (self))); + nm_modem_get_uid (NM_MODEM (self))); return; } @@ -808,9 +809,9 @@ stage1_prepare_done (GDBusProxy *proxy, GAsyncResult *result, gpointer user_data static void context_property_changed (GDBusProxy *proxy, - const char *property, - GVariant *v, - gpointer user_data) + const char *property, + GVariant *v, + gpointer user_data) { NMModemOfono *self = NM_MODEM_OFONO (user_data); NMModemOfonoPrivate *priv = NM_MODEM_OFONO_GET_PRIVATE (self); @@ -838,7 +839,7 @@ context_property_changed (GDBusProxy *proxy, v_dict = g_variant_get_child_value (v, 0); if (!v_dict) { nm_log_warn (LOGD_MB, "ofono: (%s): error getting IPv4 Settings", - nm_modem_get_uid (NM_MODEM (self))); + nm_modem_get_uid (NM_MODEM (self))); goto out; } @@ -850,18 +851,18 @@ context_property_changed (GDBusProxy *proxy, if (s && strlen (s)) { g_object_set (self, - NM_MODEM_DATA_PORT, g_strdup (s), - NM_MODEM_IP4_METHOD, NM_MODEM_IP_METHOD_STATIC, - NULL); + NM_MODEM_DATA_PORT, g_strdup (s), + NM_MODEM_IP4_METHOD, NM_MODEM_IP_METHOD_STATIC, + NULL); } else { nm_log_warn (LOGD_MB, "ofono: (%s): Settings 'Interface'; empty", - nm_modem_get_uid (NM_MODEM (self))); + nm_modem_get_uid (NM_MODEM (self))); goto out; } } else { nm_log_warn (LOGD_MB, "ofono: (%s): Settings 'Interface' missing", - nm_modem_get_uid (NM_MODEM (self))); + nm_modem_get_uid (NM_MODEM (self))); goto out; } @@ -899,13 +900,13 @@ context_property_changed (GDBusProxy *proxy, addr.source = NM_IP_CONFIG_SOURCE_WWAN; } else { nm_log_warn (LOGD_MB, "ofono: (%s): can't convert 'Address' %s to addr", - nm_modem_get_uid (NM_MODEM (self)), s); + nm_modem_get_uid (NM_MODEM (self)), s); goto out; } } else { nm_log_warn (LOGD_MB, "ofono: (%s): Settings 'Address' missing", - nm_modem_get_uid (NM_MODEM (self))); + nm_modem_get_uid (NM_MODEM (self))); goto out; } @@ -919,13 +920,13 @@ context_property_changed (GDBusProxy *proxy, addr.plen = prefix; } else { nm_log_warn (LOGD_MB, "ofono: (%s): invalid 'Netmask': %s", - nm_modem_get_uid (NM_MODEM (self)), s); + nm_modem_get_uid (NM_MODEM (self)), s); goto out; } } else { nm_log_warn (LOGD_MB, "ofono: (%s): Settings 'Netmask' missing", - nm_modem_get_uid (NM_MODEM (self))); + nm_modem_get_uid (NM_MODEM (self))); goto out; } @@ -942,14 +943,14 @@ context_property_changed (GDBusProxy *proxy, nm_ip4_config_set_gateway (priv->ip4_config, gateway_network); } else { nm_log_warn (LOGD_MB, "ofono: (%s): invalid 'Gateway': %s", - nm_modem_get_uid (NM_MODEM (self)), s); + nm_modem_get_uid (NM_MODEM (self)), s); goto out; } nm_ip4_config_set_gateway (priv->ip4_config, gateway_network); } else { nm_log_warn (LOGD_MB, "ofono: (%s): Settings 'Gateway' missing", - nm_modem_get_uid (NM_MODEM (self))); + nm_modem_get_uid (NM_MODEM (self))); goto out; } @@ -959,12 +960,12 @@ context_property_changed (GDBusProxy *proxy, while (*iter) { if (ip_string_to_network_address (*iter, &address_network) && address_network > 0) { nm_log_info (LOGD_MB, "ofono: (%s): DNS: %s", - nm_modem_get_uid (NM_MODEM (self)), *iter); + nm_modem_get_uid (NM_MODEM (self)), *iter); nm_ip4_config_add_nameserver (priv->ip4_config, address_network); } else { nm_log_warn (LOGD_MB, "ofono: (%s): invalid NameServer: %s", - nm_modem_get_uid (NM_MODEM (self)), *iter); + nm_modem_get_uid (NM_MODEM (self)), *iter); } *iter++; @@ -972,7 +973,7 @@ context_property_changed (GDBusProxy *proxy, if (iter == array) { nm_log_warn (LOGD_MB, "ofono: (%s): Settings: 'DomainNameServers': none specified", - nm_modem_get_uid (NM_MODEM (self))); + nm_modem_get_uid (NM_MODEM (self))); g_free (array); goto out; } @@ -980,13 +981,13 @@ context_property_changed (GDBusProxy *proxy, g_free (array); } else { nm_log_warn (LOGD_MB, "ofono: (%s): Settings 'DomainNameServers' missing", - nm_modem_get_uid (NM_MODEM (self))); + nm_modem_get_uid (NM_MODEM (self))); goto out; } if (g_variant_lookup (v_dict, "MessageProxy", "&s", &s)) { nm_log_info (LOGD_MB, "ofono: (%s): MessageProxy: %s", - nm_modem_get_uid (NM_MODEM (self)), s); + nm_modem_get_uid (NM_MODEM (self)), s); if (s && ip_string_to_network_address (s, &address_network)) { NMPlatformIP4Route mms_route; @@ -1000,7 +1001,7 @@ context_property_changed (GDBusProxy *proxy, nm_ip4_config_add_route (priv->ip4_config, &mms_route); } else { nm_log_warn (LOGD_MB, "ofono: (%s): invalid MessageProxy: %s", - nm_modem_get_uid (NM_MODEM (self)), s); + nm_modem_get_uid (NM_MODEM (self)), s); } } @@ -1009,7 +1010,7 @@ context_property_changed (GDBusProxy *proxy, out: if (nm_modem_get_state (NM_MODEM (self)) != NM_MODEM_STATE_CONNECTED) { nm_log_info (LOGD_MB, "ofono: (%s): emitting PREPARE_RESULT: %s", - nm_modem_get_uid (NM_MODEM (self)), ret ? "TRUE" : "FALSE"); + nm_modem_get_uid (NM_MODEM (self)), ret ? "TRUE" : "FALSE"); if (!ret) reason = NM_DEVICE_STATE_REASON_IP_CONFIG_UNAVAILABLE; @@ -1033,11 +1034,11 @@ static_stage3_ip4_config_start (NMModem *_self, GError *error = NULL; nm_log_dbg (LOGD_MB, "(%s): stage_3_ip4_config_start", - nm_modem_get_uid (NM_MODEM (self))); + nm_modem_get_uid (NM_MODEM (self))); if (priv->ip4_config) { nm_log_dbg (LOGD_MB, "(%s): IP4 config is done; setting modem_state -> CONNECTED", - nm_modem_get_uid (NM_MODEM (self))); + nm_modem_get_uid (NM_MODEM (self))); g_signal_emit_by_name (self, NM_MODEM_IP4_CONFIG_RESULT, priv->ip4_config, error); @@ -1066,8 +1067,8 @@ context_proxy_new_cb (GDBusProxy *proxy, GAsyncResult *result, gpointer user_dat /* TODO: add path to log msg? */ if (error) { nm_log_err (LOGD_MB, "(%s) failed to create ofono ConnectionContext DBus proxy: %s", - nm_modem_get_uid (NM_MODEM (self)), - error->message ? error->message : "(unknown)"); + nm_modem_get_uid (NM_MODEM (self)), + error->message ? error->message : "(unknown)"); g_signal_emit_by_name (self, NM_MODEM_PREPARE_RESULT, FALSE, NM_DEVICE_STATE_REASON_MODEM_BUSY); @@ -1089,21 +1090,21 @@ context_proxy_new_cb (GDBusProxy *proxy, GAsyncResult *result, gpointer user_dat /* Watch for custom ofono PropertyChanged signals */ _nm_dbus_signal_connect (priv->context_proxy, - "PropertyChanged", - G_VARIANT_TYPE ("(sv)"), - G_CALLBACK (context_property_changed), - self); + "PropertyChanged", + G_VARIANT_TYPE ("(sv)"), + G_CALLBACK (context_property_changed), + self); g_dbus_proxy_call (priv->context_proxy, - "SetProperty", - g_variant_new ("(sv)", - "Active", - g_variant_new ("b", TRUE)), - G_DBUS_CALL_FLAGS_NONE, - 20000, - NULL, - (GAsyncReadyCallback) stage1_prepare_done, - g_object_ref (self)); + "SetProperty", + g_variant_new ("(sv)", + "Active", + g_variant_new ("b", TRUE)), + G_DBUS_CALL_FLAGS_NONE, + 20000, + NULL, + (GAsyncReadyCallback) stage1_prepare_done, + g_object_ref (self)); } static void @@ -1124,14 +1125,14 @@ do_context_activate (NMModemOfono *self) g_clear_object (&priv->context_proxy); g_dbus_proxy_new (priv->dbus_connection, - G_DBUS_OBJECT_MANAGER_CLIENT_FLAGS_DO_NOT_AUTO_START, - NULL, - OFONO_DBUS_SERVICE, - priv->context_path, - OFONO_DBUS_INTERFACE_CONNECTION_CONTEXT, - NULL, - (GAsyncReadyCallback) context_proxy_new_cb, - g_object_ref (self)); + G_DBUS_OBJECT_MANAGER_CLIENT_FLAGS_DO_NOT_AUTO_START, + NULL, + OFONO_DBUS_SERVICE, + priv->context_path, + OFONO_DBUS_INTERFACE_CONNECTION_CONTEXT, + NULL, + (GAsyncReadyCallback) context_proxy_new_cb, + g_object_ref (self)); } static GHashTable * @@ -1163,8 +1164,8 @@ create_connect_properties (NMConnection *connection) static NMActStageReturn act_stage1_prepare (NMModem *modem, - NMConnection *connection, - NMDeviceStateReason *reason) + NMConnection *connection, + NMDeviceStateReason *reason) { NMModemOfono *self = NM_MODEM_OFONO (modem); NMModemOfonoPrivate *priv = NM_MODEM_OFONO_GET_PRIVATE (self); @@ -1227,8 +1228,8 @@ modem_proxy_new_cb (GDBusProxy *proxy, GAsyncResult *result, gpointer user_data) if (error) { nm_log_err (LOGD_MB, "(%s) failed to create ofono modem DBus proxy: %s", - nm_modem_get_uid (NM_MODEM (self)), - error->message ? error->message : "(unknown)"); + nm_modem_get_uid (NM_MODEM (self)), + error->message ? error->message : "(unknown)"); return; } @@ -1263,7 +1264,7 @@ bus_connected (NMModemOfono *self) G_DBUS_OBJECT_MANAGER_CLIENT_FLAGS_DO_NOT_AUTO_START, NULL, OFONO_DBUS_SERVICE, - nm_modem_get_path (NM_MODEM (self)), + nm_modem_get_path (NM_MODEM (self)), OFONO_DBUS_INTERFACE_MODEM, NULL, (GAsyncReadyCallback) modem_proxy_new_cb, diff --git a/src/nm-core-utils.c b/src/nm-core-utils.c index 8c5c0a8b44..5b3cc72a1f 100644 --- a/src/nm-core-utils.c +++ b/src/nm-core-utils.c @@ -2560,11 +2560,12 @@ _get_property_path (const char *ifname, property); /* Ubuntu: don't assert, but log about the inconsistent size. */ - if (len > sizeof (path) - 1) - nm_log_warn (LOGD_CORE, - "IPv6 property path is too long: '" - IPV6_PROPERTY_DIR "%s/%s'", - ifname, property); + if (len > sizeof (path) - 1) { + nm_log_warn (LOGD_CORE, + "IPv6 property path is too long: '" + IPV6_PROPERTY_DIR "%s/%s'", + ifname, property); + } return path; } From 8621b0aba99605c6dd2b90f1c6375f78265b3e63 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Mon, 13 Jun 2016 17:31:23 +0200 Subject: [PATCH 04/30] wwan: fix using wrong enum type for flags for g_dbus_proxy_new() --- src/devices/wwan/nm-modem-manager.c | 2 +- src/devices/wwan/nm-modem-ofono.c | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/devices/wwan/nm-modem-manager.c b/src/devices/wwan/nm-modem-manager.c index fec25e5b20..92b7ac7af7 100644 --- a/src/devices/wwan/nm-modem-manager.c +++ b/src/devices/wwan/nm-modem-manager.c @@ -523,7 +523,7 @@ ensure_client (NMModemManager *self) #if WITH_OFONO if (!priv->ofono_proxy) { g_dbus_proxy_new (priv->dbus_connection, - G_DBUS_OBJECT_MANAGER_CLIENT_FLAGS_DO_NOT_AUTO_START, + G_DBUS_PROXY_FLAGS_DO_NOT_AUTO_START, NULL, OFONO_DBUS_SERVICE, OFONO_DBUS_PATH, diff --git a/src/devices/wwan/nm-modem-ofono.c b/src/devices/wwan/nm-modem-ofono.c index 9535f2a792..c639045d72 100644 --- a/src/devices/wwan/nm-modem-ofono.c +++ b/src/devices/wwan/nm-modem-ofono.c @@ -1125,7 +1125,7 @@ do_context_activate (NMModemOfono *self) g_clear_object (&priv->context_proxy); g_dbus_proxy_new (priv->dbus_connection, - G_DBUS_OBJECT_MANAGER_CLIENT_FLAGS_DO_NOT_AUTO_START, + G_DBUS_PROXY_FLAGS_DO_NOT_AUTO_START, NULL, OFONO_DBUS_SERVICE, priv->context_path, @@ -1261,7 +1261,7 @@ bus_connected (NMModemOfono *self) nm_log_dbg (LOGD_MB, "in %s", __func__); g_dbus_proxy_new (priv->dbus_connection, - G_DBUS_OBJECT_MANAGER_CLIENT_FLAGS_DO_NOT_AUTO_START, + G_DBUS_PROXY_FLAGS_DO_NOT_AUTO_START, NULL, OFONO_DBUS_SERVICE, nm_modem_get_path (NM_MODEM (self)), From 9e63ada7e2cb862cb40db120fa3924d916fbd517 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Mon, 13 Jun 2016 17:31:23 +0200 Subject: [PATCH 05/30] wwna: fix compiler error about wrong prototype --- src/devices/wwan/nm-modem-ofono.c | 1 + 1 file changed, 1 insertion(+) diff --git a/src/devices/wwan/nm-modem-ofono.c b/src/devices/wwan/nm-modem-ofono.c index c639045d72..8618b47749 100644 --- a/src/devices/wwan/nm-modem-ofono.c +++ b/src/devices/wwan/nm-modem-ofono.c @@ -358,6 +358,7 @@ handle_sim_property (GDBusProxy *proxy, } } +static void sim_property_changed (GDBusProxy *proxy, const char *property, GVariant *v, From acac97f8186dd9696ad7192e5d69676084ff6f72 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Mon, 13 Jun 2016 18:35:22 +0200 Subject: [PATCH 06/30] wwan: fix compilation error about wrong field name --- src/devices/wwan/nm-modem-ofono.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/devices/wwan/nm-modem-ofono.c b/src/devices/wwan/nm-modem-ofono.c index 8618b47749..b3ecafc966 100644 --- a/src/devices/wwan/nm-modem-ofono.c +++ b/src/devices/wwan/nm-modem-ofono.c @@ -898,7 +898,7 @@ context_property_changed (GDBusProxy *proxy, if (ip_string_to_network_address (addr_s, &address_network)) { addr.address = address_network; - addr.source = NM_IP_CONFIG_SOURCE_WWAN; + addr.addr_source = NM_IP_CONFIG_SOURCE_WWAN; } else { nm_log_warn (LOGD_MB, "ofono: (%s): can't convert 'Address' %s to addr", nm_modem_get_uid (NM_MODEM (self)), s); From 735bb933f6e1001b8488c23db6bb4d8a2473790c Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Fri, 17 Jun 2016 13:20:44 +0200 Subject: [PATCH 07/30] wwan: fix building for !WITH_OFONO --- src/devices/wwan/nm-modem-manager.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/devices/wwan/nm-modem-manager.c b/src/devices/wwan/nm-modem-manager.c index 92b7ac7af7..919007cc12 100644 --- a/src/devices/wwan/nm-modem-manager.c +++ b/src/devices/wwan/nm-modem-manager.c @@ -540,7 +540,9 @@ ensure_client (NMModemManager *self) /* If already available, recheck name owner! */ modem_manager_check_name_owner (self); +#if WITH_OFONO ofono_check_name_owner (self); +#endif } static void From 4e00e7a15fcc9af9cbe1b8d78b39e93d25f30dca Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Fri, 17 Jun 2016 12:35:59 +0200 Subject: [PATCH 08/30] wwan: remove unused code --- src/devices/wwan/nm-modem-ofono.c | 11 ----------- 1 file changed, 11 deletions(-) diff --git a/src/devices/wwan/nm-modem-ofono.c b/src/devices/wwan/nm-modem-ofono.c index b3ecafc966..98e6e0d972 100644 --- a/src/devices/wwan/nm-modem-ofono.c +++ b/src/devices/wwan/nm-modem-ofono.c @@ -70,17 +70,6 @@ typedef struct { } NMModemOfonoPrivate; -#define NM_OFONO_ERROR (nm_ofono_error_quark ()) - -static GQuark -nm_ofono_error_quark (void) -{ - static GQuark quark = 0; - if (!quark) - quark = g_quark_from_static_string ("nm-ofono-error"); - return quark; -} - static gboolean ip_string_to_network_address (const gchar *str, guint32 *out) From 3ef0641674552cc5bce4ecbf76ee4028ea97e1dd Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Mon, 13 Jun 2016 17:39:50 +0200 Subject: [PATCH 09/30] wwan: some minor refactorings --- src/devices/wwan/nm-modem-manager.c | 2 +- src/devices/wwan/nm-modem-ofono.c | 61 +++++++++++------------------ 2 files changed, 23 insertions(+), 40 deletions(-) diff --git a/src/devices/wwan/nm-modem-manager.c b/src/devices/wwan/nm-modem-manager.c index 919007cc12..2be5ccc49f 100644 --- a/src/devices/wwan/nm-modem-manager.c +++ b/src/devices/wwan/nm-modem-manager.c @@ -307,7 +307,7 @@ ofono_enumerate_devices_done (GDBusProxy *proxy, GAsyncResult *res, gpointer use if (error) { nm_log_warn (LOGD_MB, "failed to enumerate oFono devices: %s", - error->message ? error->message : "(unknown)"); + error->message); } } diff --git a/src/devices/wwan/nm-modem-ofono.c b/src/devices/wwan/nm-modem-ofono.c index 98e6e0d972..5b93a7ae85 100644 --- a/src/devices/wwan/nm-modem-ofono.c +++ b/src/devices/wwan/nm-modem-ofono.c @@ -433,16 +433,13 @@ handle_sim_iface (NMModemOfono *self, gboolean found) update_modem_state (self); } else if (found && !priv->sim_proxy) { GError *error = NULL; - GDBusProxyFlags flags; nm_log_info (LOGD_MB, "(%s): found new SimManager interface", nm_modem_get_path (NM_MODEM (self))); - flags |= G_DBUS_PROXY_FLAGS_DO_NOT_LOAD_PROPERTIES; - flags |= G_DBUS_PROXY_FLAGS_DO_NOT_AUTO_START; - priv->sim_proxy = g_dbus_proxy_new_sync (priv->dbus_connection, - flags, + G_DBUS_PROXY_FLAGS_DO_NOT_LOAD_PROPERTIES + | G_DBUS_PROXY_FLAGS_DO_NOT_AUTO_START, NULL, /* GDBusInterfaceInfo */ OFONO_DBUS_SERVICE, nm_modem_get_path (NM_MODEM (self)), @@ -583,16 +580,13 @@ handle_connman_iface (NMModemOfono *self, gboolean found) update_modem_state (self); } else if (found && !priv->connman_proxy) { GError *error = NULL; - GDBusProxyFlags flags; nm_log_info (LOGD_MB, "(%s): found new ConnectionManager interface", nm_modem_get_path (NM_MODEM (self))); - flags |= G_DBUS_PROXY_FLAGS_DO_NOT_LOAD_PROPERTIES; - flags |= G_DBUS_PROXY_FLAGS_DO_NOT_AUTO_START; - priv->connman_proxy = g_dbus_proxy_new_sync (priv->dbus_connection, - flags, + G_DBUS_PROXY_FLAGS_DO_NOT_LOAD_PROPERTIES + | G_DBUS_PROXY_FLAGS_DO_NOT_AUTO_START, NULL, /* GDBusInterfaceInfo */ OFONO_DBUS_SERVICE, nm_modem_get_path (NM_MODEM (self)), @@ -664,18 +658,12 @@ handle_modem_property (GDBusProxy *proxy, array = g_variant_get_strv (v, NULL); if (array) { - - iter = array; - while (*iter) { - + for (iter = array; *iter; iter++) { if (g_strcmp0 (OFONO_DBUS_INTERFACE_SIM_MANAGER, *iter) == 0) found_sim = TRUE; else if (g_strcmp0 (OFONO_DBUS_INTERFACE_CONNECTION_MANAGER, *iter) == 0) found_connman = TRUE; - - *iter++; } - g_free (array); } @@ -809,7 +797,6 @@ context_property_changed (GDBusProxy *proxy, NMPlatformIP4Address addr; gboolean ret = FALSE; GVariant *v_dict; - GVariantIter i; const gchar *s, *addr_s; const gchar **array, **iter; guint32 address_network, gateway_network; @@ -945,30 +932,27 @@ context_property_changed (GDBusProxy *proxy, } if (g_variant_lookup (v_dict, "DomainNameServers", "^a&s", &array)) { - iter = array; + if (array) { + for (iter = array; *iter; iter++) { + if (ip_string_to_network_address (*iter, &address_network) && address_network > 0) { + nm_log_info (LOGD_MB, "ofono: (%s): DNS: %s", + nm_modem_get_uid (NM_MODEM (self)), *iter); - while (*iter) { - if (ip_string_to_network_address (*iter, &address_network) && address_network > 0) { - nm_log_info (LOGD_MB, "ofono: (%s): DNS: %s", - nm_modem_get_uid (NM_MODEM (self)), *iter); - - nm_ip4_config_add_nameserver (priv->ip4_config, address_network); - } else { - nm_log_warn (LOGD_MB, "ofono: (%s): invalid NameServer: %s", - nm_modem_get_uid (NM_MODEM (self)), *iter); + nm_ip4_config_add_nameserver (priv->ip4_config, address_network); + } else { + nm_log_warn (LOGD_MB, "ofono: (%s): invalid NameServer: %s", + nm_modem_get_uid (NM_MODEM (self)), *iter); + } } - *iter++; - } - - if (iter == array) { - nm_log_warn (LOGD_MB, "ofono: (%s): Settings: 'DomainNameServers': none specified", - nm_modem_get_uid (NM_MODEM (self))); + if (iter == array) { + nm_log_warn (LOGD_MB, "ofono: (%s): Settings: 'DomainNameServers': none specified", + nm_modem_get_uid (NM_MODEM (self))); + g_free (array); + goto out; + } g_free (array); - goto out; } - - g_free (array); } else { nm_log_warn (LOGD_MB, "ofono: (%s): Settings 'DomainNameServers' missing", nm_modem_get_uid (NM_MODEM (self))); @@ -1103,8 +1087,7 @@ do_context_activate (NMModemOfono *self) NMModemOfonoPrivate *priv = NM_MODEM_OFONO_GET_PRIVATE (self); GValue value = G_VALUE_INIT; - g_return_val_if_fail (self != NULL, FALSE); - g_return_val_if_fail (NM_IS_MODEM_OFONO (self), FALSE); + g_return_if_fail (NM_IS_MODEM_OFONO (self)); nm_log_dbg (LOGD_MB, "in %s", __func__); From 5cdb2b152038778e4822a30b8db756b55e2389b5 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Fri, 17 Jun 2016 12:48:42 +0200 Subject: [PATCH 10/30] wwan: cleanup includes --- src/devices/wwan/nm-modem-manager.c | 14 +++++++------- src/devices/wwan/nm-modem-ofono.c | 11 ++++------- src/devices/wwan/nm-modem-ofono.h | 6 +----- 3 files changed, 12 insertions(+), 19 deletions(-) diff --git a/src/devices/wwan/nm-modem-manager.c b/src/devices/wwan/nm-modem-manager.c index 2be5ccc49f..54fb8865be 100644 --- a/src/devices/wwan/nm-modem-manager.c +++ b/src/devices/wwan/nm-modem-manager.c @@ -22,14 +22,10 @@ #include "nm-default.h" -#include - -#include - #include "nm-modem-manager.h" -#include "nm-dbus-compat.h" -#include "nm-modem.h" -#include "nm-modem-broadband.h" + +#include +#include #if HAVE_LIBSYSTEMD #include @@ -37,6 +33,10 @@ #define sd_booted() FALSE #endif +#include "nm-dbus-compat.h" +#include "nm-modem.h" +#include "nm-modem-broadband.h" + #if WITH_OFONO #include "nm-modem-ofono.h" #endif diff --git a/src/devices/wwan/nm-modem-ofono.c b/src/devices/wwan/nm-modem-ofono.c index 5b93a7ae85..4f0860ad27 100644 --- a/src/devices/wwan/nm-modem-ofono.c +++ b/src/devices/wwan/nm-modem-ofono.c @@ -18,22 +18,19 @@ * Copyright (C) 2013 - 2016 Canonical Ltd. */ -#include "config.h" - -#include -#include - #include "nm-default.h" -#include "nm-core-internal.h" #include "nm-modem-ofono.h" + +#include + +#include "nm-core-internal.h" #include "nm-device.h" #include "nm-device-private.h" #include "nm-setting-connection.h" #include "nm-setting-gsm.h" #include "nm-settings-connection.h" #include "nm-enum-types.h" -#include "nm-logging.h" #include "nm-modem.h" #include "nm-platform.h" #include "nm-utils.h" diff --git a/src/devices/wwan/nm-modem-ofono.h b/src/devices/wwan/nm-modem-ofono.h index fa79e156c0..ccfae85033 100644 --- a/src/devices/wwan/nm-modem-ofono.h +++ b/src/devices/wwan/nm-modem-ofono.h @@ -21,9 +21,7 @@ #ifndef NM_MODEM_OFONO_H #define NM_MODEM_OFONO_H -#include - -G_BEGIN_DECLS +#include "nm-modem.h" #define NM_TYPE_MODEM_OFONO (nm_modem_ofono_get_type ()) #define NM_MODEM_OFONO(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), NM_TYPE_MODEM_OFONO, NMModemOfono)) @@ -59,6 +57,4 @@ GType nm_modem_ofono_get_type (void); NMModem *nm_modem_ofono_new (const char *path); -G_END_DECLS - #endif /* NM_MODEM_OFONO_H */ From 5a740d323e74c73f65eb16685416c62816b6f9f6 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Fri, 17 Jun 2016 12:55:56 +0200 Subject: [PATCH 11/30] wwan: fix memleaks And use gs_free in ofono_check_name_owner() --- src/devices/wwan/nm-modem-manager.c | 17 +++++------------ 1 file changed, 5 insertions(+), 12 deletions(-) diff --git a/src/devices/wwan/nm-modem-manager.c b/src/devices/wwan/nm-modem-manager.c index 54fb8865be..6eb6a7ce3b 100644 --- a/src/devices/wwan/nm-modem-manager.c +++ b/src/devices/wwan/nm-modem-manager.c @@ -291,7 +291,7 @@ static void ofono_enumerate_devices_done (GDBusProxy *proxy, GAsyncResult *res, gpointer user_data) { NMModemManager *manager = NM_MODEM_MANAGER (user_data); - GError *error = NULL; + gs_free_error GError *error = NULL; GVariant *results; GVariantIter *iter; const char *path; @@ -317,13 +317,13 @@ static void ofono_appeared (NMModemManager *self); static void ofono_check_name_owner (NMModemManager *self) { - gchar *name_owner; + gs_free char *name_owner = NULL; name_owner = g_dbus_proxy_get_name_owner (G_DBUS_PROXY (self->priv->ofono_proxy)); if (name_owner) { /* Available! */ ofono_appeared (self); - goto free; + return; } nm_log_info (LOGD_MB, "oFono disappeared from bus"); @@ -331,10 +331,6 @@ ofono_check_name_owner (NMModemManager *self) ofono_clear_signals (self); g_clear_object (&self->priv->ofono_proxy); ensure_client (self); - -free: - g_free (name_owner); - return; } static void @@ -373,8 +369,8 @@ ofono_appeared (NMModemManager *self) static void ofono_proxy_new_cb (GObject *source_object, GAsyncResult *res, gpointer user_data) { - NMModemManager *self = NM_MODEM_MANAGER (user_data); - GError *error = NULL; + gs_unref_object NMModemManager *self = NM_MODEM_MANAGER (user_data); + gs_free_error GError *error = NULL; self->priv->ofono_proxy = g_dbus_proxy_new_finish (res, &error); @@ -384,9 +380,6 @@ ofono_proxy_new_cb (GObject *source_object, GAsyncResult *res, gpointer user_dat } ofono_appeared (self); - - /* Balance refcount */ - g_object_unref (self); } #endif From 521133d4565f80f7241c061df2d9557703f4ac78 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Fri, 17 Jun 2016 13:14:22 +0200 Subject: [PATCH 12/30] core: revert asserts to NM_ASSERT_VALID_PATH_COMPONENT() and _get_property_path() If ofono violates these asserts, then the bug must be fixed somewhere else, not by silently doing something wrong. --- src/nm-core-utils.c | 21 ++++----------------- 1 file changed, 4 insertions(+), 17 deletions(-) diff --git a/src/nm-core-utils.c b/src/nm-core-utils.c index 5b3cc72a1f..b20653838d 100644 --- a/src/nm-core-utils.c +++ b/src/nm-core-utils.c @@ -2558,14 +2558,7 @@ _get_property_path (const char *ifname, ipv6 ? IPV6_PROPERTY_DIR : IPV4_PROPERTY_DIR, ifname, property); - - /* Ubuntu: don't assert, but log about the inconsistent size. */ - if (len > sizeof (path) - 1) { - nm_log_warn (LOGD_CORE, - "IPv6 property path is too long: '" - IPV6_PROPERTY_DIR "%s/%s'", - ifname, property); - } + g_assert (len < sizeof (path) - 1); return path; } @@ -2629,15 +2622,9 @@ NM_ASSERT_VALID_PATH_COMPONENT (const char *name) nm_log_err (LOGD_CORE, "Failed asserting path component: %s%s%s", NM_PRINT_FMT_QUOTED (name, "\"", name, "\"", "(null)")); - - /* Ubuntu: Don't outright fail, just return the name again. It's - * logged as being invalid, which is enough. - * There is a use of slashes in paths for oFono modems, which are - * actually valid paths to refer to an oFono modem, just don't map to - * anything on the filesystem. The following calls to sysctl paths can - * (and will) fail, but that's fine. - */ - return name; + g_error ("FATAL: Failed asserting path component: %s%s%s", + NM_PRINT_FMT_QUOTED (name, "\"", name, "\"", "(null)")); + g_assert_not_reached (); } gboolean From 44ce13c786f272f5ba16c76a180630d745846696 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Fri, 17 Jun 2016 13:17:11 +0200 Subject: [PATCH 13/30] wwan: don't compile ofono support by default and mark as experimental At least, there are assertions that fail and must be fixed. Still, let's merge the (incomplete) ofono patches early to have something that can be incrementally improved. However, for now mark it as experimental and disable it by default. --- configure.ac | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/configure.ac b/configure.ac index eba3fcc657..3f5708f7dd 100644 --- a/configure.ac +++ b/configure.ac @@ -735,11 +735,11 @@ fi AM_CONDITIONAL(WITH_BLUEZ5_DUN, test "${enable_bluez5_dun}" = "yes") # OFONO -AC_ARG_WITH(ofono, AS_HELP_STRING([--with-ofono], [Enable oFono support]),,[with_ofono=yes]) +AC_ARG_WITH(ofono, AS_HELP_STRING([--with-ofono], [Enable oFono support (experimental)]),,[with_ofono=no]) if (test "${with_ofono}" = "yes"); then - AC_DEFINE(WITH_OFONO, 1, [Define if you have oFono support]) + AC_DEFINE(WITH_OFONO, 1, [Define if you have oFono support (experimental)]) else - AC_DEFINE(WITH_OFONO, 0, [Define if you have oFono support]) + AC_DEFINE(WITH_OFONO, 0, [Define if you have oFono support (experimental)]) fi AM_CONDITIONAL(WITH_OFONO, test "${with_ofono}" = "yes") From e06e1d469164a01855bcea3e96e089413207358b Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Fri, 17 Jun 2016 13:39:20 +0200 Subject: [PATCH 14/30] wwan: cleanup clearing ofono proxy instance --- src/devices/wwan/nm-modem-manager.c | 21 +++++++-------------- 1 file changed, 7 insertions(+), 14 deletions(-) diff --git a/src/devices/wwan/nm-modem-manager.c b/src/devices/wwan/nm-modem-manager.c index 6eb6a7ce3b..2b7e87c80c 100644 --- a/src/devices/wwan/nm-modem-manager.c +++ b/src/devices/wwan/nm-modem-manager.c @@ -56,7 +56,7 @@ struct _NMModemManagerPrivate { #if WITH_OFONO GDBusProxy *ofono_proxy; - guint ofono_name_owner_changed_id; + gulong ofono_name_owner_changed_id; #endif /* Common */ @@ -216,21 +216,16 @@ modem_manager_name_owner_changed (MMManager *modem_manager, * modem_manager_available (self); */ } + #if WITH_OFONO static void -ofono_clear_signals (NMModemManager *self) +clear_ofono_proxy (NMModemManager *self) { if (!self->priv->ofono_proxy) return; - if (self->priv->ofono_name_owner_changed_id) { - if (g_signal_handler_is_connected (self->priv->ofono_proxy, - self->priv->ofono_name_owner_changed_id)) { - g_signal_handler_disconnect (self->priv->ofono_proxy, - self->priv->ofono_name_owner_changed_id); - } - self->priv->ofono_name_owner_changed_id = 0; - } + nm_clear_g_signal_handler (self->priv->ofono_proxy, &self->priv->ofono_name_owner_changed_id); + g_clear_object (&self->priv->ofono_proxy); } static void @@ -328,8 +323,7 @@ ofono_check_name_owner (NMModemManager *self) nm_log_info (LOGD_MB, "oFono disappeared from bus"); - ofono_clear_signals (self); - g_clear_object (&self->priv->ofono_proxy); + clear_ofono_proxy (self); ensure_client (self); } @@ -615,8 +609,7 @@ dispose (GObject *object) clear_modem_manager (self); #if WITH_OFONO - ofono_clear_signals (self); - g_clear_object (&self->priv->ofono_proxy); + clear_ofono_proxy (self); #endif g_clear_object (&self->priv->dbus_connection); From d99171d700c68e9f6b7d69f70a6918bd7d0c310c Mon Sep 17 00:00:00 2001 From: Dan Williams Date: Fri, 17 Jun 2016 12:25:37 -0500 Subject: [PATCH 15/30] wwan: use modem basename as NM device name NM_MODEM_UID is used as the modem device name, and the device name cannot contain path-like characters. Ofono has a bluez plugin that detects paired DUN/PAN capable Bluetooth devices, and these devices are created with a multi-component object path like "/hfp/org/bluez/hci0/dev_00_26_E2_AB_68_66". The NM ofono plugin cannot use these paths as NM device names. Instead, strip off any path components and use the last part of the object path as the NM device name. --- src/devices/wwan/nm-modem-ofono.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/devices/wwan/nm-modem-ofono.c b/src/devices/wwan/nm-modem-ofono.c index 4f0860ad27..f1a526cdfe 100644 --- a/src/devices/wwan/nm-modem-ofono.c +++ b/src/devices/wwan/nm-modem-ofono.c @@ -734,14 +734,21 @@ modem_get_properties_done (GDBusProxy *proxy, GAsyncResult *result, gpointer use NMModem * nm_modem_ofono_new (const char *path) { + gs_free char *basename = NULL; + g_return_val_if_fail (path != NULL, NULL); nm_log_dbg (LOGD_MB, "in %s: path %s", __func__, path); + /* Use short modem name (not its object path) as the NM device name (which + * comes from NM_MODEM_UID)and the device ID. + */ + basename = g_path_get_basename (path); + return (NMModem *) g_object_new (NM_TYPE_MODEM_OFONO, NM_MODEM_PATH, path, - NM_MODEM_UID, (path + 1), - NM_MODEM_DEVICE_ID, (path + 1), + NM_MODEM_UID, basename, + NM_MODEM_DEVICE_ID, basename, NM_MODEM_CONTROL_PORT, "ofono", /* mandatory */ NM_MODEM_DRIVER, "ofono", NM_MODEM_STATE, NM_MODEM_STATE_INITIALIZING, From 425ae4fbd2cfea5549d3cfbedf1b84f367ba87af Mon Sep 17 00:00:00 2001 From: Dan Williams Date: Fri, 17 Jun 2016 12:51:40 -0500 Subject: [PATCH 16/30] wwan: remove some dbus-glib left-overs --- src/devices/wwan/nm-modem-manager.c | 3 --- 1 file changed, 3 deletions(-) diff --git a/src/devices/wwan/nm-modem-manager.c b/src/devices/wwan/nm-modem-manager.c index 2b7e87c80c..f4123f9fd1 100644 --- a/src/devices/wwan/nm-modem-manager.c +++ b/src/devices/wwan/nm-modem-manager.c @@ -279,9 +279,6 @@ ofono_signal_cb (GDBusProxy *proxy, } } -#define OFONO_DBUS_MODEM_ENTRY (dbus_g_type_get_struct ("GValueArray", DBUS_TYPE_G_OBJECT_PATH, DBUS_TYPE_G_MAP_OF_VARIANT, G_TYPE_INVALID)) -#define OFONO_DBUS_MODEM_ENTRIES (dbus_g_type_get_collection ("GPtrArray", OFONO_DBUS_MODEM_ENTRY)) - static void ofono_enumerate_devices_done (GDBusProxy *proxy, GAsyncResult *res, gpointer user_data) { From 8a827b1b4f7432d3061a57b4ace8e4b9822899b5 Mon Sep 17 00:00:00 2001 From: Dan Williams Date: Fri, 17 Jun 2016 13:34:30 -0500 Subject: [PATCH 17/30] wwan/ofono: fix a few more memory leaks --- src/devices/wwan/nm-modem-ofono.c | 21 ++++++++------------- 1 file changed, 8 insertions(+), 13 deletions(-) diff --git a/src/devices/wwan/nm-modem-ofono.c b/src/devices/wwan/nm-modem-ofono.c index f1a526cdfe..4fc989d042 100644 --- a/src/devices/wwan/nm-modem-ofono.c +++ b/src/devices/wwan/nm-modem-ofono.c @@ -359,7 +359,7 @@ sim_property_changed (GDBusProxy *proxy, static void sim_get_properties_done (GDBusProxy *proxy, GAsyncResult *result, gpointer user_data) { - NMModemOfono *self = NM_MODEM_OFONO (user_data); + gs_unref_object NMModemOfono *self = NM_MODEM_OFONO (user_data); GError *error = NULL; GVariant *v_properties, *v_dict, *v; GVariantIter i; @@ -513,7 +513,7 @@ connman_property_changed (GDBusProxy *proxy, static void connman_get_properties_done (GDBusProxy *proxy, GAsyncResult *result, gpointer user_data) { - NMModemOfono *self = NM_MODEM_OFONO (user_data); + gs_unref_object NMModemOfono *self = NM_MODEM_OFONO (user_data); GError *error = NULL; GVariant *v_properties, *v_dict, *v; GVariantIter i; @@ -684,7 +684,7 @@ modem_property_changed (GDBusProxy *proxy, static void modem_get_properties_done (GDBusProxy *proxy, GAsyncResult *result, gpointer user_data) { - NMModemOfono *self = NM_MODEM_OFONO (user_data); + gs_unref_object NMModemOfono *self = NM_MODEM_OFONO (user_data); GError *error = NULL; GVariant *v_properties, *v_dict, *v; GVariantIter i; @@ -758,7 +758,7 @@ nm_modem_ofono_new (const char *path) static void stage1_prepare_done (GDBusProxy *proxy, GAsyncResult *result, gpointer user_data) { - NMModemOfono *self = NM_MODEM_OFONO (user_data); + gs_unref_object NMModemOfono *self = NM_MODEM_OFONO (user_data); NMModemOfonoPrivate *priv = NM_MODEM_OFONO_GET_PRIVATE (self); GError *error = NULL; @@ -1034,7 +1034,7 @@ static_stage3_ip4_config_start (NMModem *_self, static void context_proxy_new_cb (GDBusProxy *proxy, GAsyncResult *result, gpointer user_data) { - NMModemOfono *self = NM_MODEM_OFONO (user_data); + gs_unref_object NMModemOfono *self = NM_MODEM_OFONO (user_data); NMModemOfonoPrivate *priv = NM_MODEM_OFONO_GET_PRIVATE (self); GError *error = NULL; @@ -1195,7 +1195,7 @@ act_stage1_prepare (NMModem *modem, static void modem_proxy_new_cb (GDBusProxy *proxy, GAsyncResult *result, gpointer user_data) { - NMModemOfono *self = NM_MODEM_OFONO (user_data); + gs_unref_object NMModemOfono *self = NM_MODEM_OFONO (user_data); NMModemOfonoPrivate *priv = NM_MODEM_OFONO_GET_PRIVATE (self); GError *error = NULL; @@ -1226,8 +1226,6 @@ modem_proxy_new_cb (GDBusProxy *proxy, GAsyncResult *result, gpointer user_data) NULL, (GAsyncReadyCallback) modem_get_properties_done, g_object_ref (self)); - - g_object_unref (self); } static void @@ -1251,9 +1249,9 @@ bus_connected (NMModemOfono *self) static void bus_get_ready (GObject *source, GAsyncResult *result, - NMModemOfono *self) + gpointer user_data) { - /* Note we always get an extra reference to self here */ + gs_unref_object NMModemOfono *self = NM_MODEM_OFONO (user_data); NMModemOfonoPrivate *priv = NM_MODEM_OFONO_GET_PRIVATE (self); GError *error = NULL; @@ -1269,9 +1267,6 @@ bus_get_ready (GObject *source, /* Got the bus, ensure client */ bus_connected (self); } - - /* Balance refcount */ - g_object_unref (self); } static gboolean From 019b34af6208a4dfc4a0a2a400e8b6d62377b466 Mon Sep 17 00:00:00 2001 From: Dan Williams Date: Fri, 17 Jun 2016 13:38:06 -0500 Subject: [PATCH 18/30] wwan/ofono: whitespace fixup --- src/devices/wwan/nm-modem-manager.c | 4 +--- src/devices/wwan/nm-modem-ofono.c | 2 -- 2 files changed, 1 insertion(+), 5 deletions(-) diff --git a/src/devices/wwan/nm-modem-manager.c b/src/devices/wwan/nm-modem-manager.c index f4123f9fd1..bdb8b89382 100644 --- a/src/devices/wwan/nm-modem-manager.c +++ b/src/devices/wwan/nm-modem-manager.c @@ -305,7 +305,6 @@ ofono_enumerate_devices_done (GDBusProxy *proxy, GAsyncResult *res, gpointer use static void ofono_appeared (NMModemManager *self); - static void ofono_check_name_owner (NMModemManager *self) { @@ -364,13 +363,12 @@ ofono_proxy_new_cb (GObject *source_object, GAsyncResult *res, gpointer user_dat gs_free_error GError *error = NULL; self->priv->ofono_proxy = g_dbus_proxy_new_finish (res, &error); - if (error) { //FIXME: do stuff if there's an error. return; } - ofono_appeared (self); + ofono_check_name_owner (self); } #endif diff --git a/src/devices/wwan/nm-modem-ofono.c b/src/devices/wwan/nm-modem-ofono.c index 4fc989d042..5cecd59eaa 100644 --- a/src/devices/wwan/nm-modem-ofono.c +++ b/src/devices/wwan/nm-modem-ofono.c @@ -175,8 +175,6 @@ disconnect_done (GDBusProxy *proxy, NMModemOfono *self = ctx->self; GError *error = NULL; - - g_dbus_proxy_call_finish (proxy, result, &error); if (g_error_matches (error, G_IO_ERROR, G_IO_ERROR_CANCELLED)) { nm_log_dbg (LOGD_MB, "(%s): disconnect cancelled", From f0af7a0d05fc321d522a02ae39636ef4142b9e60 Mon Sep 17 00:00:00 2001 From: Dan Williams Date: Fri, 17 Jun 2016 15:18:34 -0500 Subject: [PATCH 19/30] wwan: rework ModemManager/ofono initialization Avoids the following error when ofono isn't running: NetworkManager[25133]: [1466186144.1392] ofono is now available NetworkManager[25133]: [1466186144.1637] failed to enumerate oFono devices: Cannot invoke method; proxy is for a well-known name without an owner and proxy was constructed with the G_DBUS_PROXY_FLAGS_DO_NOT_AUTO_START flag because the code assumes that if the GDBusProxy is created, that oFono is available. That's not the case with DO_NOT_AUTO_START because it creates the proxy anyway, and lets the caller listen for name-owner-changed signals instead. The GDBusProxy also doesn't need to be cleared, since it will follow name-owner changes and emit g-name-owner changes when oFono starts/stops. This also fixes the oFono name-owner-changed watch. It was presumably using the signal name copied from the ModemManager 'notify::name-owner' code, but that's a GDBusObjectManagerClient. The oFono code is using a GDBusProxy for which the signal is 'notify::g-name-owner'. Finally, the oFono code shouldn't really be piggy-backing on the ModemManager autolaunch code, it's just cleaner to keep the two code paths separate and initialize oFono in parallel. --- src/devices/wwan/nm-modem-manager.c | 238 ++++++++++++---------------- 1 file changed, 105 insertions(+), 133 deletions(-) diff --git a/src/devices/wwan/nm-modem-manager.c b/src/devices/wwan/nm-modem-manager.c index bdb8b89382..964485fc34 100644 --- a/src/devices/wwan/nm-modem-manager.c +++ b/src/devices/wwan/nm-modem-manager.c @@ -55,8 +55,6 @@ struct _NMModemManagerPrivate { #if WITH_OFONO GDBusProxy *ofono_proxy; - - gulong ofono_name_owner_changed_id; #endif /* Common */ @@ -179,7 +177,7 @@ modem_manager_available (NMModemManager *self) static void schedule_modem_manager_relaunch (NMModemManager *self, guint n_seconds); -static void ensure_client (NMModemManager *self); +static void ensure_modem_manager (NMModemManager *self); static void modem_manager_name_owner_changed (MMManager *modem_manager, @@ -210,7 +208,7 @@ modem_manager_name_owner_changed (MMManager *modem_manager, * the bus. This hack avoids this issue until we get a GIO with the fix * included... */ clear_modem_manager (self); - ensure_client (self); + ensure_modem_manager (self); /* Whenever GDBusObjectManagerClient is fixed, we can just do the following: * modem_manager_available (self); @@ -218,32 +216,23 @@ modem_manager_name_owner_changed (MMManager *modem_manager, } #if WITH_OFONO -static void -clear_ofono_proxy (NMModemManager *self) -{ - if (!self->priv->ofono_proxy) - return; - - nm_clear_g_signal_handler (self->priv->ofono_proxy, &self->priv->ofono_name_owner_changed_id); - g_clear_object (&self->priv->ofono_proxy); -} - static void ofono_create_modem (NMModemManager *self, const char *path) { NMModem *modem = NULL; - if (g_hash_table_lookup (self->priv->modems, path)) { - nm_log_warn (LOGD_MB, "modem with path %s already exists, ignoring", path); - return; + /* Ensure duplicate modems aren't created. Because we're not using the + * ObjectManager interface there's a race during oFono startup where we + * receive ModemAdded signals before GetModems() returns, so some of the + * modems returned from GetModems() may already have been created. + */ + if (!g_hash_table_lookup (self->priv->modems, path)) { + modem = nm_modem_ofono_new (path); + if (modem) + handle_new_modem (self, modem); + else + nm_log_warn (LOGD_MB, "Failed to create oFono modem for %s", path); } - - /* Create modem instance */ - modem = nm_modem_ofono_new (path); - if (modem) - handle_new_modem (self, modem); - else - nm_log_warn (LOGD_MB, "Failed to create oFono modem for %s", path); } static void @@ -303,8 +292,6 @@ ofono_enumerate_devices_done (GDBusProxy *proxy, GAsyncResult *res, gpointer use } } -static void ofono_appeared (NMModemManager *self); - static void ofono_check_name_owner (NMModemManager *self) { @@ -312,15 +299,31 @@ ofono_check_name_owner (NMModemManager *self) name_owner = g_dbus_proxy_get_name_owner (G_DBUS_PROXY (self->priv->ofono_proxy)); if (name_owner) { - /* Available! */ - ofono_appeared (self); - return; + nm_log_info (LOGD_MB, "oFono is now available"); + + g_dbus_proxy_call (self->priv->ofono_proxy, + "GetModems", + NULL, + G_DBUS_CALL_FLAGS_NONE, + -1, + NULL, + (GAsyncReadyCallback) ofono_enumerate_devices_done, + g_object_ref (self)); + } else { + GHashTableIter iter; + NMModem *modem; + + nm_log_info (LOGD_MB, "oFono disappeared from bus"); + + /* Remove any oFono modems that might be left around */ + g_hash_table_iter_init (&iter, self->priv->modems); + while (g_hash_table_iter_next (&iter, NULL, (gpointer) &modem)) { + if (NM_IS_MODEM_OFONO (modem)) { + nm_modem_emit_removed (modem); + g_hash_table_iter_remove (&iter); + } + } } - - nm_log_info (LOGD_MB, "oFono disappeared from bus"); - - clear_ofono_proxy (self); - ensure_client (self); } static void @@ -331,31 +334,6 @@ ofono_name_owner_changed (GDBusProxy *ofono_proxy, ofono_check_name_owner (self); } -static void -ofono_appeared (NMModemManager *self) -{ - nm_log_info (LOGD_MB, "ofono is now available"); - - self->priv->ofono_name_owner_changed_id = - g_signal_connect (self->priv->ofono_proxy, - "notify::name-owner", - G_CALLBACK (ofono_name_owner_changed), - self); - g_dbus_proxy_call (self->priv->ofono_proxy, - "GetModems", - NULL, - G_DBUS_CALL_FLAGS_NONE, - -1, - NULL, - (GAsyncReadyCallback) ofono_enumerate_devices_done, - g_object_ref (self)); - - g_signal_connect (self->priv->ofono_proxy, - "g-signal", - G_CALLBACK (ofono_signal_cb), - self); -} - static void ofono_proxy_new_cb (GObject *source_object, GAsyncResult *res, gpointer user_data) { @@ -364,12 +342,37 @@ ofono_proxy_new_cb (GObject *source_object, GAsyncResult *res, gpointer user_dat self->priv->ofono_proxy = g_dbus_proxy_new_finish (res, &error); if (error) { - //FIXME: do stuff if there's an error. + nm_log_warn (LOGD_MB, "error getting oFono bus proxy: %s", error->message); return; } + g_signal_connect (self->priv->ofono_proxy, + "notify::g-name-owner", + G_CALLBACK (ofono_name_owner_changed), + self); + + g_signal_connect (self->priv->ofono_proxy, + "g-signal", + G_CALLBACK (ofono_signal_cb), + self); + ofono_check_name_owner (self); } + +static void +ensure_ofono_client (NMModemManager *self) +{ + g_assert (self->priv->dbus_connection); + g_dbus_proxy_new (self->priv->dbus_connection, + G_DBUS_PROXY_FLAGS_DO_NOT_AUTO_START, + NULL, + OFONO_DBUS_SERVICE, + OFONO_DBUS_PATH, + OFONO_DBUS_INTERFACE, + NULL, + (GAsyncReadyCallback) ofono_proxy_new_cb, + g_object_ref (self)); +} #endif static void @@ -422,13 +425,12 @@ modem_manager_poke (NMModemManager *self) static void modem_manager_check_name_owner (NMModemManager *self) { - gchar *name_owner; + gs_free gchar *name_owner = NULL; name_owner = g_dbus_object_manager_client_get_name_owner (G_DBUS_OBJECT_MANAGER_CLIENT (self->priv->modem_manager)); if (name_owner) { /* Available! */ modem_manager_available (self); - g_free (name_owner); return; } @@ -483,90 +485,32 @@ manager_new_ready (GObject *source, } static void -ensure_client (NMModemManager *self) +ensure_modem_manager (NMModemManager *self) { - NMModemManagerPrivate *priv = self->priv; - gboolean created = FALSE; - - g_assert (priv->dbus_connection); + g_assert (self->priv->dbus_connection); /* Create the GDBusObjectManagerClient. We do not request to autostart, as * we don't really want the MMManager creation to fail. We can always poke * later on if we want to request the autostart */ - if (!priv->modem_manager) { - mm_manager_new (priv->dbus_connection, + if (!self->priv->modem_manager) { + mm_manager_new (self->priv->dbus_connection, G_DBUS_OBJECT_MANAGER_CLIENT_FLAGS_DO_NOT_AUTO_START, NULL, (GAsyncReadyCallback)manager_new_ready, g_object_ref (self)); - created = TRUE; - } - -#if WITH_OFONO - if (!priv->ofono_proxy) { - g_dbus_proxy_new (priv->dbus_connection, - G_DBUS_PROXY_FLAGS_DO_NOT_AUTO_START, - NULL, - OFONO_DBUS_SERVICE, - OFONO_DBUS_PATH, - OFONO_DBUS_INTERFACE, - NULL, - (GAsyncReadyCallback) ofono_proxy_new_cb, - g_object_ref (self)); - created = TRUE; - } -#endif /* WITH_OFONO */ - - if (created) return; + } /* If already available, recheck name owner! */ modem_manager_check_name_owner (self); -#if WITH_OFONO - ofono_check_name_owner (self); -#endif -} - -static void -bus_get_ready (GObject *source, - GAsyncResult *res, - NMModemManager *self) -{ - /* Note we always get an extra reference to self here */ - - GError *error = NULL; - - self->priv->dbus_connection = g_bus_get_finish (res, &error); - if (!self->priv->dbus_connection) { - nm_log_warn (LOGD_CORE, "error getting bus connection: %s", error->message); - g_error_free (error); - /* Setup timeout to relaunch */ - schedule_modem_manager_relaunch (self, MODEM_POKE_INTERVAL); - } else { - /* Got the bus, ensure client */ - ensure_client (self); - } - - /* Balance refcount */ - g_object_unref (self); } static gboolean -ensure_bus (NMModemManager *self) +mm_launch_cb (NMModemManager *self) { - /* Clear launch ID */ self->priv->mm_launch_id = 0; - - if (!self->priv->dbus_connection) - g_bus_get (G_BUS_TYPE_SYSTEM, - NULL, - (GAsyncReadyCallback)bus_get_ready, - g_object_ref (self)); - else - /* If bus is already available, ensure client */ - ensure_client (self); - - return FALSE; + ensure_modem_manager (self); + return G_SOURCE_REMOVE; } static void @@ -575,11 +519,31 @@ schedule_modem_manager_relaunch (NMModemManager *self, { /* No need to pass an extra reference to self; timeout/idle will be * cancelled if the object gets disposed. */ - if (n_seconds) - self->priv->mm_launch_id = g_timeout_add_seconds (n_seconds, (GSourceFunc)ensure_bus, self); + self->priv->mm_launch_id = g_timeout_add_seconds (n_seconds, (GSourceFunc)mm_launch_cb, self); else - self->priv->mm_launch_id = g_idle_add ((GSourceFunc)ensure_bus, self); + self->priv->mm_launch_id = g_idle_add ((GSourceFunc)mm_launch_cb, self); +} + +static void +bus_get_ready (GObject *source, + GAsyncResult *res, + gpointer user_data) +{ + gs_unref_object NMModemManager *self = NM_MODEM_MANAGER (user_data); + gs_free_error GError *error = NULL; + + self->priv->dbus_connection = g_bus_get_finish (res, &error); + if (!self->priv->dbus_connection) { + nm_log_warn (LOGD_MB, "error getting bus connection: %s", error->message); + return; + } + + /* Got the bus, ensure clients */ + ensure_modem_manager (self); +#if WITH_OFONO + ensure_ofono_client (self); +#endif } /************************************************************************/ @@ -591,7 +555,11 @@ nm_modem_manager_init (NMModemManager *self) self->priv->modems = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, g_object_unref); - schedule_modem_manager_relaunch (self, 0); + // FIXME: this doesn't handle bus-daemon restart + g_bus_get (G_BUS_TYPE_SYSTEM, + NULL, + (GAsyncReadyCallback)bus_get_ready, + g_object_ref (self)); } static void @@ -604,7 +572,11 @@ dispose (GObject *object) clear_modem_manager (self); #if WITH_OFONO - clear_ofono_proxy (self); + if (self->priv->ofono_proxy) { + g_signal_handlers_disconnect_by_func (self->priv->ofono_proxy, ofono_name_owner_changed, self); + g_signal_handlers_disconnect_by_func (self->priv->ofono_proxy, ofono_signal_cb, self); + g_clear_object (&self->priv->ofono_proxy); + } #endif g_clear_object (&self->priv->dbus_connection); From 58ab8c9316c4807bee495b7a6dab509ec6cce50c Mon Sep 17 00:00:00 2001 From: Dan Williams Date: Fri, 17 Jun 2016 15:36:50 -0500 Subject: [PATCH 20/30] wwan/ofono: use g_dbus_proxy_new_for_bus() --- src/devices/wwan/nm-modem-ofono.c | 169 ++++++++---------------------- 1 file changed, 42 insertions(+), 127 deletions(-) diff --git a/src/devices/wwan/nm-modem-ofono.c b/src/devices/wwan/nm-modem-ofono.c index 5cecd59eaa..3f028646d8 100644 --- a/src/devices/wwan/nm-modem-ofono.c +++ b/src/devices/wwan/nm-modem-ofono.c @@ -46,8 +46,6 @@ G_DEFINE_TYPE (NMModemOfono, nm_modem_ofono, NM_TYPE_MODEM) #define VARIANT_IS_OF_TYPE_DICTIONARY(v) ((v) != NULL && ( g_variant_is_of_type ((v), G_VARIANT_TYPE_DICTIONARY) )) typedef struct { - GDBusConnection *dbus_connection; - GHashTable *connect_properties; GDBusProxy *modem_proxy; @@ -432,15 +430,15 @@ handle_sim_iface (NMModemOfono *self, gboolean found) nm_log_info (LOGD_MB, "(%s): found new SimManager interface", nm_modem_get_path (NM_MODEM (self))); - priv->sim_proxy = g_dbus_proxy_new_sync (priv->dbus_connection, - G_DBUS_PROXY_FLAGS_DO_NOT_LOAD_PROPERTIES - | G_DBUS_PROXY_FLAGS_DO_NOT_AUTO_START, - NULL, /* GDBusInterfaceInfo */ - OFONO_DBUS_SERVICE, - nm_modem_get_path (NM_MODEM (self)), - OFONO_DBUS_INTERFACE_SIM_MANAGER, - NULL, /* GCancellable */ - &error); + priv->sim_proxy = g_dbus_proxy_new_for_bus_sync (G_BUS_TYPE_SYSTEM, + G_DBUS_PROXY_FLAGS_DO_NOT_LOAD_PROPERTIES + | G_DBUS_PROXY_FLAGS_DO_NOT_AUTO_START, + NULL, /* GDBusInterfaceInfo */ + OFONO_DBUS_SERVICE, + nm_modem_get_path (NM_MODEM (self)), + OFONO_DBUS_INTERFACE_SIM_MANAGER, + NULL, /* GCancellable */ + &error); if (priv->sim_proxy == NULL) { nm_log_warn (LOGD_MB, "(%s) failed to create SimManager proxy: %s", nm_modem_get_uid (NM_MODEM (self)), @@ -579,15 +577,15 @@ handle_connman_iface (NMModemOfono *self, gboolean found) nm_log_info (LOGD_MB, "(%s): found new ConnectionManager interface", nm_modem_get_path (NM_MODEM (self))); - priv->connman_proxy = g_dbus_proxy_new_sync (priv->dbus_connection, - G_DBUS_PROXY_FLAGS_DO_NOT_LOAD_PROPERTIES - | G_DBUS_PROXY_FLAGS_DO_NOT_AUTO_START, - NULL, /* GDBusInterfaceInfo */ - OFONO_DBUS_SERVICE, - nm_modem_get_path (NM_MODEM (self)), - OFONO_DBUS_INTERFACE_CONNECTION_MANAGER, - NULL, /* GCancellable */ - &error); + priv->connman_proxy = g_dbus_proxy_new_for_bus_sync (G_BUS_TYPE_SYSTEM, + G_DBUS_PROXY_FLAGS_DO_NOT_LOAD_PROPERTIES + | G_DBUS_PROXY_FLAGS_DO_NOT_AUTO_START, + NULL, /* GDBusInterfaceInfo */ + OFONO_DBUS_SERVICE, + nm_modem_get_path (NM_MODEM (self)), + OFONO_DBUS_INTERFACE_CONNECTION_MANAGER, + NULL, /* GCancellable */ + &error); if (priv->connman_proxy == NULL) { nm_log_warn (LOGD_MB, "(%s) failed to create ConnectionManager proxy: %s", nm_modem_get_uid (NM_MODEM (self)), @@ -1038,9 +1036,7 @@ context_proxy_new_cb (GDBusProxy *proxy, GAsyncResult *result, gpointer user_dat nm_log_dbg (LOGD_MB, "%s:", __func__); - priv->context_proxy = g_dbus_proxy_new_finish (result, &error); - - /* TODO: add path to log msg? */ + priv->context_proxy = g_dbus_proxy_new_for_bus_finish (result, &error); if (error) { nm_log_err (LOGD_MB, "(%s) failed to create ofono ConnectionContext DBus proxy: %s", nm_modem_get_uid (NM_MODEM (self)), @@ -1099,15 +1095,15 @@ do_context_activate (NMModemOfono *self) if (priv->context_proxy) g_clear_object (&priv->context_proxy); - g_dbus_proxy_new (priv->dbus_connection, - G_DBUS_PROXY_FLAGS_DO_NOT_AUTO_START, - NULL, - OFONO_DBUS_SERVICE, - priv->context_path, - OFONO_DBUS_INTERFACE_CONNECTION_CONTEXT, - NULL, - (GAsyncReadyCallback) context_proxy_new_cb, - g_object_ref (self)); + g_dbus_proxy_new_for_bus (G_BUS_TYPE_SYSTEM, + G_DBUS_PROXY_FLAGS_DO_NOT_AUTO_START, + NULL, + OFONO_DBUS_SERVICE, + priv->context_path, + OFONO_DBUS_INTERFACE_CONNECTION_CONTEXT, + NULL, + (GAsyncReadyCallback) context_proxy_new_cb, + g_object_ref (self)); } static GHashTable * @@ -1199,8 +1195,7 @@ modem_proxy_new_cb (GDBusProxy *proxy, GAsyncResult *result, gpointer user_data) nm_log_dbg (LOGD_MB, "in %s", __func__); - priv->modem_proxy = g_dbus_proxy_new_finish (result, &error); - + priv->modem_proxy = g_dbus_proxy_new_for_bus_finish (result, &error); if (error) { nm_log_err (LOGD_MB, "(%s) failed to create ofono modem DBus proxy: %s", nm_modem_get_uid (NM_MODEM (self)), @@ -1226,105 +1221,27 @@ modem_proxy_new_cb (GDBusProxy *proxy, GAsyncResult *result, gpointer user_data) g_object_ref (self)); } -static void -bus_connected (NMModemOfono *self) -{ - NMModemOfonoPrivate *priv = NM_MODEM_OFONO_GET_PRIVATE (self); - - nm_log_dbg (LOGD_MB, "in %s", __func__); - - g_dbus_proxy_new (priv->dbus_connection, - G_DBUS_PROXY_FLAGS_DO_NOT_AUTO_START, - NULL, - OFONO_DBUS_SERVICE, - nm_modem_get_path (NM_MODEM (self)), - OFONO_DBUS_INTERFACE_MODEM, - NULL, - (GAsyncReadyCallback) modem_proxy_new_cb, - g_object_ref (self)); -} - -static void -bus_get_ready (GObject *source, - GAsyncResult *result, - gpointer user_data) -{ - gs_unref_object NMModemOfono *self = NM_MODEM_OFONO (user_data); - NMModemOfonoPrivate *priv = NM_MODEM_OFONO_GET_PRIVATE (self); - GError *error = NULL; - - nm_log_dbg (LOGD_MB, "in %s", __func__); - - priv->dbus_connection = g_bus_get_finish (result, &error); - if (!priv->dbus_connection) { - nm_log_warn (LOGD_CORE, "error getting bus connection: %s", error->message); - g_error_free (error); - - /* FIXME (awe): what do do if bus connection fails??? */ - } else { - /* Got the bus, ensure client */ - bus_connected (self); - } -} - -static gboolean -ensure_bus (NMModemOfono *self) -{ - /* FIXME: not sure how dbus_connection could ever be set here? */ - NMModemOfonoPrivate *priv = NM_MODEM_OFONO_GET_PRIVATE (self); - - nm_log_dbg (LOGD_MB, "in %s", __func__); - - if (!priv->dbus_connection) - g_bus_get (G_BUS_TYPE_SYSTEM, - NULL, - (GAsyncReadyCallback) bus_get_ready, - g_object_ref (self)); - else - bus_connected (self); - - return FALSE; -} - static void nm_modem_ofono_init (NMModemOfono *self) { - NMModemOfonoPrivate *priv = NM_MODEM_OFONO_GET_PRIVATE (self); - - nm_log_dbg (LOGD_MB, "in %s", __func__); - - priv->dbus_connection = NULL; - - priv->modem_proxy = NULL; - priv->connman_proxy = NULL; - priv->context_proxy = NULL; - priv->sim_proxy = NULL; - - priv->modem_online = FALSE; - priv->gprs_attached = FALSE; - - priv->ip4_config = NULL; - - ensure_bus (self); } -static GObject* -constructor (GType type, - guint n_construct_params, - GObjectConstructParam *construct_params) +static void +constructed (GObject *object) { - GObject *object; - NMModemOfonoPrivate *priv; + NMModemOfono *self = NM_MODEM_OFONO (object); nm_log_dbg (LOGD_MB, "in %s", __func__); - object = G_OBJECT_CLASS (nm_modem_ofono_parent_class)->constructor (type, n_construct_params, construct_params); - if (!object) - return NULL; - - priv = NM_MODEM_OFONO_GET_PRIVATE (object); - - return object; + g_dbus_proxy_new_for_bus (G_BUS_TYPE_SYSTEM, + G_DBUS_PROXY_FLAGS_DO_NOT_AUTO_START, + NULL, + OFONO_DBUS_SERVICE, + nm_modem_get_path (NM_MODEM (self)), + OFONO_DBUS_INTERFACE_MODEM, + NULL, + (GAsyncReadyCallback) modem_proxy_new_cb, + g_object_ref (self)); } static void @@ -1358,8 +1275,6 @@ dispose (GObject *object) g_clear_object (&priv->sim_proxy); } - g_clear_object (&priv->dbus_connection); - if (priv->imsi) { g_free (priv->imsi); priv->imsi = NULL; @@ -1379,7 +1294,7 @@ nm_modem_ofono_class_init (NMModemOfonoClass *klass) g_type_class_add_private (object_class, sizeof (NMModemOfonoPrivate)); /* Virtual methods */ - object_class->constructor = constructor; + object_class->constructed = constructed; object_class->dispose = dispose; modem_class->get_capabilities = get_capabilities; From 219904920f8a6bb5344719097d4e5ca0f432eb8a Mon Sep 17 00:00:00 2001 From: Dan Williams Date: Fri, 17 Jun 2016 15:38:57 -0500 Subject: [PATCH 21/30] wwan/ofono: clean up g_clear_object() usage --- src/devices/wwan/nm-modem-ofono.c | 25 ++++++++----------------- 1 file changed, 8 insertions(+), 17 deletions(-) diff --git a/src/devices/wwan/nm-modem-ofono.c b/src/devices/wwan/nm-modem-ofono.c index 3f028646d8..098575517c 100644 --- a/src/devices/wwan/nm-modem-ofono.c +++ b/src/devices/wwan/nm-modem-ofono.c @@ -1057,8 +1057,7 @@ context_proxy_new_cb (GDBusProxy *proxy, GAsyncResult *result, gpointer user_dat * clear it so that we can gate getting the IP config from oFono * on whether or not we have already received them */ - if (priv->ip4_config) - g_clear_object (&priv->ip4_config); + g_clear_object (&priv->ip4_config); /* Watch for custom ofono PropertyChanged signals */ _nm_dbus_signal_connect (priv->context_proxy, @@ -1092,8 +1091,7 @@ do_context_activate (NMModemOfono *self) g_value_init (&value, G_TYPE_BOOLEAN); g_value_set_boolean (&value, TRUE); - if (priv->context_proxy) - g_clear_object (&priv->context_proxy); + g_clear_object (&priv->context_proxy); g_dbus_proxy_new_for_bus (G_BUS_TYPE_SYSTEM, G_DBUS_PROXY_FLAGS_DO_NOT_AUTO_START, @@ -1151,9 +1149,7 @@ act_stage1_prepare (NMModem *modem, nm_log_dbg (LOGD_MB, " trying %s %s", id[1], id[2]); - if (priv->context_path) - g_free (priv->context_path); - + g_free (priv->context_path); priv->context_path = g_strdup_printf ("%s/%s", nm_modem_get_path (modem), id[2]); @@ -1257,28 +1253,23 @@ dispose (GObject *object) priv->connect_properties = NULL; } - if (priv->ip4_config) - g_clear_object (&priv->ip4_config); + g_clear_object (&priv->ip4_config); if (priv->modem_proxy) { g_signal_handlers_disconnect_by_data (priv->modem_proxy, NM_MODEM_OFONO (self)); g_clear_object (&priv->modem_proxy); } - if (priv->connman_proxy) - g_clear_object (&priv->connman_proxy); - if (priv->context_proxy) - g_clear_object (&priv->context_proxy); + g_clear_object (&priv->connman_proxy); + g_clear_object (&priv->context_proxy); if (priv->sim_proxy) { g_signal_handlers_disconnect_by_data (priv->sim_proxy, NM_MODEM_OFONO (self)); g_clear_object (&priv->sim_proxy); } - if (priv->imsi) { - g_free (priv->imsi); - priv->imsi = NULL; - } + g_free (priv->imsi); + priv->imsi = NULL; G_OBJECT_CLASS (nm_modem_ofono_parent_class)->dispose (object); } From 87aa671e6b595092656a782e35c6f1f2bd84832a Mon Sep 17 00:00:00 2001 From: Dan Williams Date: Thu, 23 Jun 2016 11:08:59 -0500 Subject: [PATCH 22/30] wwan: no need for NM_MODEM_BROADBAND_MODEM to be public --- src/devices/wwan/nm-modem-broadband.c | 2 ++ src/devices/wwan/nm-modem-broadband.h | 2 -- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/devices/wwan/nm-modem-broadband.c b/src/devices/wwan/nm-modem-broadband.c index 105cf4ddf3..e72b75923c 100644 --- a/src/devices/wwan/nm-modem-broadband.c +++ b/src/devices/wwan/nm-modem-broadband.c @@ -30,6 +30,8 @@ #include "nm-device-private.h" #include "nm-platform.h" +#define NM_MODEM_BROADBAND_MODEM "modem" + G_DEFINE_TYPE (NMModemBroadband, nm_modem_broadband, NM_TYPE_MODEM) typedef enum { diff --git a/src/devices/wwan/nm-modem-broadband.h b/src/devices/wwan/nm-modem-broadband.h index a54e63a697..371607782b 100644 --- a/src/devices/wwan/nm-modem-broadband.h +++ b/src/devices/wwan/nm-modem-broadband.h @@ -32,8 +32,6 @@ G_BEGIN_DECLS #define NM_IS_MODEM_BROADBAND_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), NM_TYPE_MODEM_BROADBAND)) #define NM_MODEM_BROADBAND_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), NM_TYPE_MODEM_BROADBAND, NMModemBroadbandClass)) -#define NM_MODEM_BROADBAND_MODEM "modem" - typedef struct _NMModemBroadband NMModemBroadband; typedef struct _NMModemBroadbandClass NMModemBroadbandClass; typedef struct _NMModemBroadbandPrivate NMModemBroadbandPrivate; From 3c054e21ba6d7c658498721215190e745394883a Mon Sep 17 00:00:00 2001 From: Dan Williams Date: Thu, 23 Jun 2016 11:09:32 -0500 Subject: [PATCH 23/30] wwan/ofono: remove some unused types --- src/devices/wwan/nm-modem-ofono.h | 7 ------- 1 file changed, 7 deletions(-) diff --git a/src/devices/wwan/nm-modem-ofono.h b/src/devices/wwan/nm-modem-ofono.h index ccfae85033..5965526d61 100644 --- a/src/devices/wwan/nm-modem-ofono.h +++ b/src/devices/wwan/nm-modem-ofono.h @@ -29,7 +29,6 @@ #define NM_MODEM_OFONO_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), NM_TYPE_MODEM_OFONO, NMModemOfonoClass)) #define NM_IS_MODEM_OFONO_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), NM_TYPE_MODEM_OFONO)) #define NM_MODEM_OFONO_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), NM_TYPE_MODEM_OFONO, NMModemOfonoClass)) -#define NM_MODEM_OFONO_MODEM "modem" #define OFONO_DBUS_SERVICE "org.ofono" #define OFONO_DBUS_PATH "/" @@ -39,12 +38,6 @@ #define OFONO_DBUS_INTERFACE_CONNECTION_CONTEXT "org.ofono.ConnectionContext" #define OFONO_DBUS_INTERFACE_SIM_MANAGER "org.ofono.SimManager" -typedef enum { - NM_OFONO_ERROR_CONNECTION_NOT_OFONO = 0, /*< nick=ConnectionNotOfono >*/ - NM_OFONO_ERROR_CONNECTION_INVALID, /*< nick=ConnectionInvalid >*/ - NM_OFONO_ERROR_CONNECTION_INCOMPATIBLE, /*< nick=ConnectionIncompatible >*/ -} NMOfonoError; - typedef struct { NMModem parent; } NMModemOfono; From b898b0882be0baef7d112d12f09132f087a8a483 Mon Sep 17 00:00:00 2001 From: Dan Williams Date: Thu, 23 Jun 2016 11:10:07 -0500 Subject: [PATCH 24/30] wwan/ofono: whitespace fixup --- src/devices/wwan/nm-modem-ofono.c | 1 - 1 file changed, 1 deletion(-) diff --git a/src/devices/wwan/nm-modem-ofono.c b/src/devices/wwan/nm-modem-ofono.c index 098575517c..0f6fdf252c 100644 --- a/src/devices/wwan/nm-modem-ofono.c +++ b/src/devices/wwan/nm-modem-ofono.c @@ -62,7 +62,6 @@ typedef struct { gboolean gprs_attached; NMIP4Config *ip4_config; - } NMModemOfonoPrivate; static gboolean From 938b27a8d2d16818e9da6b82828d05be8782fbc1 Mon Sep 17 00:00:00 2001 From: Dan Williams Date: Thu, 23 Jun 2016 11:11:39 -0500 Subject: [PATCH 25/30] wwan/ofono: simplify capabilities function and add FIXME about LTE --- src/devices/wwan/nm-modem-ofono.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/src/devices/wwan/nm-modem-ofono.c b/src/devices/wwan/nm-modem-ofono.c index 0f6fdf252c..ecbd95d5a4 100644 --- a/src/devices/wwan/nm-modem-ofono.c +++ b/src/devices/wwan/nm-modem-ofono.c @@ -85,10 +85,9 @@ get_capabilities (NMModem *_self, NMDeviceModemCapabilities *modem_caps, NMDeviceModemCapabilities *current_caps) { - NMDeviceModemCapabilities all_ofono_caps = NM_DEVICE_MODEM_CAPABILITY_GSM_UMTS; - - *modem_caps = all_ofono_caps; - *current_caps = all_ofono_caps; + /* FIXME: auto-detect capabilities to allow LTE */ + *modem_caps = NM_DEVICE_MODEM_CAPABILITY_GSM_UMTS; + *current_caps = NM_DEVICE_MODEM_CAPABILITY_GSM_UMTS; } static void From 3ef9b6aa4125cd38019f654b24a4842dc447c657 Mon Sep 17 00:00:00 2001 From: Dan Williams Date: Thu, 23 Jun 2016 11:24:58 -0500 Subject: [PATCH 26/30] build: show ofono enablement status in configure summary --- configure.ac | 1 + 1 file changed, 1 insertion(+) diff --git a/configure.ac b/configure.ac index 3f5708f7dd..d795634b29 100644 --- a/configure.ac +++ b/configure.ac @@ -1244,6 +1244,7 @@ echo " wext: $ac_with_wext" echo " wifi: $enable_wifi" echo " ppp: $enable_ppp" echo " modemmanager-1: $with_modem_manager_1" +echo " ofono: $with_ofono" echo " concheck: $enable_concheck" echo " libteamdctl: $enable_teamdctl" echo " libnm-glib: $with_libnm_glib" From 602c3f6ed31559b82583e35711c9694ac0e82a6c Mon Sep 17 00:00:00 2001 From: Dan Williams Date: Thu, 23 Jun 2016 11:56:02 -0500 Subject: [PATCH 27/30] wwan/ofono: clean up and standardize logging --- src/devices/wwan/nm-modem-ofono.c | 306 +++++++++++------------------- 1 file changed, 106 insertions(+), 200 deletions(-) diff --git a/src/devices/wwan/nm-modem-ofono.c b/src/devices/wwan/nm-modem-ofono.c index ecbd95d5a4..39c99ee227 100644 --- a/src/devices/wwan/nm-modem-ofono.c +++ b/src/devices/wwan/nm-modem-ofono.c @@ -25,15 +25,9 @@ #include #include "nm-core-internal.h" -#include "nm-device.h" #include "nm-device-private.h" -#include "nm-setting-connection.h" -#include "nm-setting-gsm.h" -#include "nm-settings-connection.h" -#include "nm-enum-types.h" #include "nm-modem.h" #include "nm-platform.h" -#include "nm-utils.h" G_DEFINE_TYPE (NMModemOfono, nm_modem_ofono, NM_TYPE_MODEM) @@ -64,6 +58,35 @@ typedef struct { NMIP4Config *ip4_config; } NMModemOfonoPrivate; +/*****************************************************************************/ + +#define _NMLOG_DOMAIN LOGD_MB +#define _NMLOG_PREFIX_NAME "modem-ofono" +#define _NMLOG(level, ...) \ + G_STMT_START { \ + const NMLogLevel _level = (level); \ + \ + if (nm_logging_enabled (_level, (_NMLOG_DOMAIN))) { \ + NMModemOfono *const __self = (self); \ + char __prefix_name[128]; \ + const char *__uid; \ + \ + _nm_log (_level, (_NMLOG_DOMAIN), 0, \ + "%s%s: " _NM_UTILS_MACRO_FIRST(__VA_ARGS__), \ + _NMLOG_PREFIX_NAME, \ + (__self \ + ? ({ \ + ((__uid = nm_modem_get_uid ((NMModem *) __self)) \ + ? nm_sprintf_buf (__prefix_name, "[%s]", __uid) \ + : "(null)"); \ + }) \ + : "") \ + _NM_UTILS_MACRO_REST(__VA_ARGS__)); \ + } \ + } G_STMT_END + +/*****************************************************************************/ + static gboolean ip_string_to_network_address (const gchar *str, guint32 *out) @@ -98,12 +121,10 @@ update_modem_state (NMModemOfono *self) NMModemState new_state = NM_MODEM_STATE_DISABLED; const char *reason = NULL; - nm_log_info (LOGD_MB, "(%s): %s: 'Attached': %s 'Online': %s 'IMSI': %s", - nm_modem_get_path (NM_MODEM (self)), - __func__, - priv->gprs_attached ? "true" : "false", - priv->modem_online ? "true" : "false", - priv->imsi); + _LOGI ("'Attached': %s 'Online': %s 'IMSI': %s", + priv->gprs_attached ? "true" : "false", + priv->modem_online ? "true" : "false", + priv->imsi); if (priv->modem_online == FALSE) { reason = "modem 'Online=false'"; @@ -173,42 +194,37 @@ disconnect_done (GDBusProxy *proxy, g_dbus_proxy_call_finish (proxy, result, &error); if (g_error_matches (error, G_IO_ERROR, G_IO_ERROR_CANCELLED)) { - nm_log_dbg (LOGD_MB, "(%s): disconnect cancelled", - nm_modem_get_uid (NM_MODEM (self))); + _LOGD ("disconnect cancelled"); return; } if (error) { if (ctx->warn) - nm_log_warn (LOGD_MB, "(%s) failed to disconnect modem: %s", - nm_modem_get_uid (NM_MODEM (self)), - error && error->message ? error->message : "(unknown)"); - + _LOGW ("failed to disconnect modem: %s", error->message); g_clear_error (&error); } - nm_log_dbg (LOGD_MB, "(%s): modem disconnected", - nm_modem_get_uid (NM_MODEM (self))); + _LOGD ("modem disconnected"); update_modem_state (self); disconnect_context_complete (ctx); } static void -disconnect (NMModem *self, +disconnect (NMModem *modem, gboolean warn, GCancellable *cancellable, GAsyncReadyCallback callback, gpointer user_data) { + NMModemOfono *self = NM_MODEM_OFONO (modem); NMModemOfonoPrivate *priv = NM_MODEM_OFONO_GET_PRIVATE (self); DisconnectContext *ctx; NMModemState state = nm_modem_get_state (NM_MODEM (self)); - nm_log_dbg (LOGD_MB, "(%s): warn: %s modem_state: %s", - nm_modem_get_uid (NM_MODEM (self)), - warn ? "TRUE" : "FALSE", - nm_modem_state_to_string (state)); + _LOGD ("warn: %s modem_state: %s", + warn ? "TRUE" : "FALSE", + nm_modem_state_to_string (state)); if (state != NM_MODEM_STATE_CONNECTED) return; @@ -281,29 +297,26 @@ check_connection_compatible (NMModem *modem, return FALSE; if (!priv->imsi) { - nm_log_warn (LOGD_MB, "ofono (%s): check_connection %s failed: no IMSI", - nm_modem_get_uid (NM_MODEM (self)), id); + _LOGW ("skipping %s/%s: no IMSI", uuid, id); return FALSE; } if (strcmp (nm_setting_connection_get_connection_type (s_con), NM_SETTING_GSM_SETTING_NAME)) { - nm_log_dbg (LOGD_MB, "%s (%s) isn't of the right type, skipping.", id, uuid); + _LOGD ("skipping %s/%s: not GSM", uuid, id); return FALSE; } if (!g_strrstr (id, "/context")) { - nm_log_dbg (LOGD_MB, "%s (%s) isn't of the right type, skipping.", id, uuid); + _LOGD ("skipping %s/%s: unexpected ID", uuid, id); return FALSE; } if (!g_strrstr (id, priv->imsi)) { - nm_log_dbg (LOGD_MB, "%s (%s) isn't for the right SIM, skipping.", id, uuid); + _LOGD ("skipping %s/%s: ID doesn't contain IMSI", uuid, id); return FALSE; } - nm_log_dbg (LOGD_MB, "(%s): %s is compatible with IMSI %s", - nm_modem_get_uid (NM_MODEM (self)), id, priv->imsi); - + _LOGD ("%s/%s compatible with IMSI %s", uuid, id, priv->imsi); return TRUE; } @@ -320,7 +333,7 @@ handle_sim_property (GDBusProxy *proxy, gsize length; const char *value_str = g_variant_get_string (v, &length); - nm_log_dbg (LOGD_MB, "(%s): SubscriberIdentity found", nm_modem_get_uid (NM_MODEM (self))); + _LOGD ("SubscriberIdentify found"); /* Check for empty DBus string value */ if (length && @@ -328,7 +341,7 @@ handle_sim_property (GDBusProxy *proxy, g_strcmp0 (value_str, priv->imsi) != 0) { if (priv->imsi != NULL) { - nm_log_warn (LOGD_MB, "SimManager:'SubscriberIdentity' changed: %s", priv->imsi); + _LOGW ("SimManager:'SubscriberIdentity' changed: %s", priv->imsi); g_free(priv->imsi); } @@ -359,31 +372,26 @@ sim_get_properties_done (GDBusProxy *proxy, GAsyncResult *result, gpointer user_ GVariantIter i; const char *property; - nm_log_dbg (LOGD_MB, "%s", __func__); - v_properties = _nm_dbus_proxy_call_finish (proxy, result, G_VARIANT_TYPE ("(a{sv})"), &error); if (!v_properties) { g_dbus_error_strip_remote_error (error); - nm_log_warn (LOGD_MB, "(%s) error getting sim properties: %s", - nm_modem_get_uid (NM_MODEM (self)), - error->message); + _LOGW ("error getting sim properties: %s", error->message); g_error_free (error); return; } - nm_log_dbg (LOGD_MB, "sim v_properties is type: %s", g_variant_get_type_string (v_properties)); + _LOGD ("sim v_properties is type: %s", g_variant_get_type_string (v_properties)); v_dict = g_variant_get_child_value (v_properties, 0); if (!v_dict) { - nm_log_warn (LOGD_MB, "(%s) error getting sim properties: no v_dict", - nm_modem_get_uid (NM_MODEM (self))); + _LOGW ("error getting sim properties: no v_dict"); return; } - nm_log_dbg (LOGD_MB, "sim v_dict is type: %s", g_variant_get_type_string (v_dict)); + _LOGD ("sim v_dict is type: %s", g_variant_get_type_string (v_dict)); /* * TODO: @@ -409,24 +417,18 @@ handle_sim_iface (NMModemOfono *self, gboolean found) { NMModemOfonoPrivate *priv = NM_MODEM_OFONO_GET_PRIVATE (self); - nm_log_dbg (LOGD_MB, "%s: %s", __func__, found ? "TRUE" : "FALSE"); + _LOGD ("SimManager interface %sfound", found ? "" : "not "); if (!found && priv->sim_proxy) { - nm_log_info (LOGD_MB, "(%s): SimManager interface disappeared", - nm_modem_get_path (NM_MODEM (self))); - + _LOGI ("SimManager interface disappeared"); g_signal_handlers_disconnect_by_data (priv->sim_proxy, NM_MODEM_OFONO (self)); g_clear_object (&priv->sim_proxy); - - g_free (priv->imsi); - priv->imsi = NULL; - + g_clear_pointer (&priv->imsi, g_free); update_modem_state (self); } else if (found && !priv->sim_proxy) { GError *error = NULL; - nm_log_info (LOGD_MB, "(%s): found new SimManager interface", - nm_modem_get_path (NM_MODEM (self))); + _LOGI ("found new SimManager interface"); priv->sim_proxy = g_dbus_proxy_new_for_bus_sync (G_BUS_TYPE_SYSTEM, G_DBUS_PROXY_FLAGS_DO_NOT_LOAD_PROPERTIES @@ -438,10 +440,7 @@ handle_sim_iface (NMModemOfono *self, gboolean found) NULL, /* GCancellable */ &error); if (priv->sim_proxy == NULL) { - nm_log_warn (LOGD_MB, "(%s) failed to create SimManager proxy: %s", - nm_modem_get_uid (NM_MODEM (self)), - error && error->message ? error->message : "(unknown)"); - + _LOGW ("failed to create SimManager proxy: %s", error->message); g_error_free (error); return; } @@ -475,17 +474,16 @@ handle_connman_property (GDBusProxy *proxy, if (g_strcmp0 (property, "Attached") == 0 && VARIANT_IS_OF_TYPE_BOOLEAN (v)) { gboolean attached = g_variant_get_boolean (v); + gboolean old_attached = priv->gprs_attached; - nm_log_dbg (LOGD_MB, "(%s): Attached: %s", - nm_modem_get_uid (NM_MODEM (self)), attached ? "True" : "False"); + _LOGD ("Attached: %s", attached ? "True" : "False"); if (priv->gprs_attached != attached) { priv->gprs_attached = attached; - nm_log_info (LOGD_MB, "(%s): %s: new value for 'Attached': %s", - nm_modem_get_path (NM_MODEM (self)), - __func__, - attached ? "true" : "false"); + _LOGI ("Attached %s -> %s", + old_attached ? "true" : "false", + attached ? "true" : "false"); update_modem_state (self); } @@ -513,17 +511,13 @@ connman_get_properties_done (GDBusProxy *proxy, GAsyncResult *result, gpointer u GVariantIter i; const char *property; - nm_log_dbg (LOGD_MB, "%s", __func__); - v_properties = _nm_dbus_proxy_call_finish (proxy, result, G_VARIANT_TYPE ("(a{sv})"), &error); if (!v_properties) { g_dbus_error_strip_remote_error (error); - nm_log_warn (LOGD_MB, "(%s) error getting connman properties: %s", - nm_modem_get_uid (NM_MODEM (self)), - error->message); + _LOGW ("error getting connman properties: %s", error->message); g_error_free (error); return; } @@ -554,11 +548,10 @@ handle_connman_iface (NMModemOfono *self, gboolean found) { NMModemOfonoPrivate *priv = NM_MODEM_OFONO_GET_PRIVATE (self); - nm_log_dbg (LOGD_MB, "%s: %s", __func__, found ? "TRUE" : "FALSE"); + _LOGD ("ConnectionManager interface %sfound", found ? "" : "not "); if (!found && priv->connman_proxy) { - nm_log_info (LOGD_MB, "(%s): ConnectionManager interface disappeared", - nm_modem_get_path (NM_MODEM (self))); + _LOGI ("ConnectionManager interface disappeared"); g_signal_handlers_disconnect_by_data (priv->connman_proxy, NM_MODEM_OFONO (self)); g_clear_object (&priv->connman_proxy); @@ -572,8 +565,7 @@ handle_connman_iface (NMModemOfono *self, gboolean found) } else if (found && !priv->connman_proxy) { GError *error = NULL; - nm_log_info (LOGD_MB, "(%s): found new ConnectionManager interface", - nm_modem_get_path (NM_MODEM (self))); + _LOGI ("found new ConnectionManager interface"); priv->connman_proxy = g_dbus_proxy_new_for_bus_sync (G_BUS_TYPE_SYSTEM, G_DBUS_PROXY_FLAGS_DO_NOT_LOAD_PROPERTIES @@ -585,10 +577,7 @@ handle_connman_iface (NMModemOfono *self, gboolean found) NULL, /* GCancellable */ &error); if (priv->connman_proxy == NULL) { - nm_log_warn (LOGD_MB, "(%s) failed to create ConnectionManager proxy: %s", - nm_modem_get_uid (NM_MODEM (self)), - error && error->message ? error->message : "(unknown)"); - + _LOGW ("failed to create ConnectionManager proxy: %s", error->message); g_error_free (error); return; } @@ -608,10 +597,6 @@ handle_connman_iface (NMModemOfono *self, gboolean found) NULL, (GAsyncReadyCallback) connman_get_properties_done, g_object_ref (self)); - - /* NM 0.9.10x version registers for "ContextAdded/Removed", but - * did nothing but log a message. Removed for 1.2 - */ } } @@ -627,16 +612,11 @@ handle_modem_property (GDBusProxy *proxy, if ((g_strcmp0 (property, "Online") == 0) && VARIANT_IS_OF_TYPE_BOOLEAN (v)) { gboolean online = g_variant_get_boolean (v); - nm_log_dbg (LOGD_MB, "(%s): Online: %s", - nm_modem_get_uid (NM_MODEM (self)), online ? "True" : "False"); + _LOGD ("Online: %s", online ? "True" : "False"); if (online != priv->modem_online) { priv->modem_online = online; - - nm_log_info (LOGD_MB, "(%s) modem is now %s", - nm_modem_get_path (NM_MODEM (self)), - online ? "Online" : "Offline"); - + _LOGI ("modem is now %s", online ? "Online" : "Offline"); update_modem_state (self); } @@ -645,7 +625,7 @@ handle_modem_property (GDBusProxy *proxy, gboolean found_connman = FALSE; gboolean found_sim = FALSE; - nm_log_dbg (LOGD_MB, "(%s): Interfaces", nm_modem_get_uid (NM_MODEM (self))); + _LOGD ("Interfaces found"); array = g_variant_get_strv (v, NULL); if (array) { @@ -684,25 +664,20 @@ modem_get_properties_done (GDBusProxy *proxy, GAsyncResult *result, gpointer use GVariantIter i; const char *property; - nm_log_dbg (LOGD_MB, "in %s", __func__); - v_properties = _nm_dbus_proxy_call_finish (proxy, result, G_VARIANT_TYPE ("(a{sv})"), &error); if (!v_properties) { g_dbus_error_strip_remote_error (error); - nm_log_warn (LOGD_MB, "(%s) error getting modem properties: %s", - nm_modem_get_uid (NM_MODEM (self)), - error->message); + _LOGW ("error getting modem properties: %s", error->message); g_error_free (error); return; } v_dict = g_variant_get_child_value (v_properties, 0); if (!v_dict) { - nm_log_warn (LOGD_MB, "(%s) error getting modem properties: no v_dict", - nm_modem_get_uid (NM_MODEM (self))); + _LOGW ("error getting modem properties: no v_dict"); return; } @@ -732,7 +707,7 @@ nm_modem_ofono_new (const char *path) g_return_val_if_fail (path != NULL, NULL); - nm_log_dbg (LOGD_MB, "in %s: path %s", __func__, path); + nm_log_info (LOGD_MB, "ofono: creating new Ofono modem path %s", path); /* Use short modem name (not its object path) as the NM device name (which * comes from NM_MODEM_UID)and the device ID. @@ -756,19 +731,11 @@ stage1_prepare_done (GDBusProxy *proxy, GAsyncResult *result, gpointer user_data NMModemOfonoPrivate *priv = NM_MODEM_OFONO_GET_PRIVATE (self); GError *error = NULL; - nm_log_dbg (LOGD_MB, "in %s", __func__); - - if (priv->connect_properties) { - g_hash_table_destroy (priv->connect_properties); - priv->connect_properties = NULL; - } + g_clear_pointer (&priv->connect_properties, g_hash_table_destroy); g_dbus_proxy_call_finish (proxy, result, &error); - if (error) { - nm_log_warn (LOGD_MB, "ofono: connection failed: (%d) %s", - error ? error->code : -1, - error && error->message ? error->message : "(unknown)"); + _LOGW ("connection failed: %s", error->message); g_signal_emit_by_name (self, NM_MODEM_PREPARE_RESULT, FALSE, NM_DEVICE_STATE_REASON_MODEM_BUSY); @@ -800,7 +767,7 @@ context_property_changed (GDBusProxy *proxy, guint32 address_network, gateway_network; guint prefix = 0; - nm_log_dbg (LOGD_MB, "PropertyChanged: %s", property); + _LOGD ("PropertyChanged: %s", property); /* * TODO: might be a good idea and re-factor this to mimic bluez-device, @@ -813,37 +780,31 @@ context_property_changed (GDBusProxy *proxy, v_dict = g_variant_get_child_value (v, 0); if (!v_dict) { - nm_log_warn (LOGD_MB, "ofono: (%s): error getting IPv4 Settings", - nm_modem_get_uid (NM_MODEM (self))); + _LOGW ("error getting IPv4 Settings: no v_dict"); goto out; } - nm_log_info (LOGD_MB, "ofono: (%s): IPv4 static Settings:", nm_modem_get_uid (NM_MODEM (self))); + _LOGI ("IPv4 static Settings:"); if (g_variant_lookup (v_dict, "Interface", "&s", &s)) { - - nm_log_dbg (LOGD_MB, "(%s): Interface: %s", nm_modem_get_uid (NM_MODEM (self)), s); - if (s && strlen (s)) { + _LOGD ("Interface: %s", s); g_object_set (self, NM_MODEM_DATA_PORT, g_strdup (s), NM_MODEM_IP4_METHOD, NM_MODEM_IP_METHOD_STATIC, NULL); } else { - nm_log_warn (LOGD_MB, "ofono: (%s): Settings 'Interface'; empty", - nm_modem_get_uid (NM_MODEM (self))); + _LOGW ("Settings 'Interface'; empty"); goto out; } } else { - nm_log_warn (LOGD_MB, "ofono: (%s): Settings 'Interface' missing", - nm_modem_get_uid (NM_MODEM (self))); + _LOGW ("Settings 'Interface' missing"); goto out; } /* TODO: verify handling of ip4_config; check other places it's used... */ - if (priv->ip4_config) - g_object_unref (priv->ip4_config); + g_clear_object (&priv->ip4_config); memset (&addr, 0, sizeof (addr)); @@ -868,64 +829,52 @@ context_property_changed (GDBusProxy *proxy, /* TODO: simply if/else error logic! */ if (g_variant_lookup (v_dict, "Address", "&s", &addr_s)) { - nm_log_dbg (LOGD_MB, "(%s): Address: %s", nm_modem_get_uid (NM_MODEM (self)), addr_s); + _LOGD ("Address: %s", addr_s); if (ip_string_to_network_address (addr_s, &address_network)) { addr.address = address_network; addr.addr_source = NM_IP_CONFIG_SOURCE_WWAN; } else { - nm_log_warn (LOGD_MB, "ofono: (%s): can't convert 'Address' %s to addr", - nm_modem_get_uid (NM_MODEM (self)), s); + _LOGW ("can't convert 'Address' %s to addr", s); goto out; } } else { - nm_log_warn (LOGD_MB, "ofono: (%s): Settings 'Address' missing", - nm_modem_get_uid (NM_MODEM (self))); + _LOGW ("Settings 'Address' missing"); goto out; } if (g_variant_lookup (v_dict, "Netmask", "&s", &s)) { - - nm_log_dbg (LOGD_MB, "(%s): Netmask: %s", nm_modem_get_uid (NM_MODEM (self)), s); + _LOGD ("Netmask: %s", s); if (s && ip_string_to_network_address (s, &address_network)) { prefix = nm_utils_ip4_netmask_to_prefix (address_network); if (prefix > 0) addr.plen = prefix; } else { - nm_log_warn (LOGD_MB, "ofono: (%s): invalid 'Netmask': %s", - nm_modem_get_uid (NM_MODEM (self)), s); + _LOGW ("invalid 'Netmask': %s", s); goto out; } - } else { - nm_log_warn (LOGD_MB, "ofono: (%s): Settings 'Netmask' missing", - nm_modem_get_uid (NM_MODEM (self))); + _LOGW ("Settings 'Netmask' missing"); goto out; } - nm_log_info (LOGD_MB, "ofono (%s) Address: %s/%d", - nm_modem_get_uid (NM_MODEM (self)), addr_s, prefix); + _LOGI ("Address: %s/%d", addr_s, prefix); nm_ip4_config_add_address (priv->ip4_config, &addr); if (g_variant_lookup (v_dict, "Gateway", "&s", &s)) { - if (s && ip_string_to_network_address (s, &gateway_network)) { - nm_log_info (LOGD_MB, "ofono: (%s): Gateway: %s", nm_modem_get_uid (NM_MODEM (self)), s); - + _LOGI ("Gateway: %s", s); nm_ip4_config_set_gateway (priv->ip4_config, gateway_network); } else { - nm_log_warn (LOGD_MB, "ofono: (%s): invalid 'Gateway': %s", - nm_modem_get_uid (NM_MODEM (self)), s); + _LOGW ("invalid 'Gateway': %s", s); goto out; } - nm_ip4_config_set_gateway (priv->ip4_config, gateway_network); } else { - nm_log_warn (LOGD_MB, "ofono: (%s): Settings 'Gateway' missing", - nm_modem_get_uid (NM_MODEM (self))); + _LOGW ("Settings 'Gateway' missing"); goto out; } @@ -933,34 +882,27 @@ context_property_changed (GDBusProxy *proxy, if (array) { for (iter = array; *iter; iter++) { if (ip_string_to_network_address (*iter, &address_network) && address_network > 0) { - nm_log_info (LOGD_MB, "ofono: (%s): DNS: %s", - nm_modem_get_uid (NM_MODEM (self)), *iter); - + _LOGI ("DNS: %s", *iter); nm_ip4_config_add_nameserver (priv->ip4_config, address_network); } else { - nm_log_warn (LOGD_MB, "ofono: (%s): invalid NameServer: %s", - nm_modem_get_uid (NM_MODEM (self)), *iter); + _LOGW ("invalid NameServer: %s", *iter); } } if (iter == array) { - nm_log_warn (LOGD_MB, "ofono: (%s): Settings: 'DomainNameServers': none specified", - nm_modem_get_uid (NM_MODEM (self))); + _LOGW ("Settings: 'DomainNameServers': none specified"); g_free (array); goto out; } g_free (array); } } else { - nm_log_warn (LOGD_MB, "ofono: (%s): Settings 'DomainNameServers' missing", - nm_modem_get_uid (NM_MODEM (self))); + _LOGW ("Settings 'DomainNameServers' missing"); goto out; } if (g_variant_lookup (v_dict, "MessageProxy", "&s", &s)) { - nm_log_info (LOGD_MB, "ofono: (%s): MessageProxy: %s", - nm_modem_get_uid (NM_MODEM (self)), s); - + _LOGI ("MessageProxy: %s", s); if (s && ip_string_to_network_address (s, &address_network)) { NMPlatformIP4Route mms_route; @@ -972,8 +914,7 @@ context_property_changed (GDBusProxy *proxy, nm_ip4_config_add_route (priv->ip4_config, &mms_route); } else { - nm_log_warn (LOGD_MB, "ofono: (%s): invalid MessageProxy: %s", - nm_modem_get_uid (NM_MODEM (self)), s); + _LOGW ("invalid MessageProxy: %s", s); } } @@ -981,16 +922,12 @@ context_property_changed (GDBusProxy *proxy, out: if (nm_modem_get_state (NM_MODEM (self)) != NM_MODEM_STATE_CONNECTED) { - nm_log_info (LOGD_MB, "ofono: (%s): emitting PREPARE_RESULT: %s", - nm_modem_get_uid (NM_MODEM (self)), ret ? "TRUE" : "FALSE"); - + _LOGI ("emitting PREPARE_RESULT: %s", ret ? "TRUE" : "FALSE"); if (!ret) reason = NM_DEVICE_STATE_REASON_IP_CONFIG_UNAVAILABLE; - g_signal_emit_by_name (self, NM_MODEM_PREPARE_RESULT, ret, reason); } else { - nm_log_warn (LOGD_MB, "ofono: (%s): MODEM_PPP_FAILED", nm_modem_get_uid (NM_MODEM (self))); - + _LOGW ("MODEM_PPP_FAILED"); g_signal_emit_by_name (self, NM_MODEM_PPP_FAILED, NM_DEVICE_STATE_REASON_PPP_FAILED); } } @@ -1005,13 +942,8 @@ static_stage3_ip4_config_start (NMModem *_self, NMActStageReturn ret = NM_ACT_STAGE_RETURN_FAILURE; GError *error = NULL; - nm_log_dbg (LOGD_MB, "(%s): stage_3_ip4_config_start", - nm_modem_get_uid (NM_MODEM (self))); - if (priv->ip4_config) { - nm_log_dbg (LOGD_MB, "(%s): IP4 config is done; setting modem_state -> CONNECTED", - nm_modem_get_uid (NM_MODEM (self))); - + _LOGD ("IP4 config is done; setting modem_state -> CONNECTED"); g_signal_emit_by_name (self, NM_MODEM_IP4_CONFIG_RESULT, priv->ip4_config, error); /* TODO: review!!! */ @@ -1032,14 +964,9 @@ context_proxy_new_cb (GDBusProxy *proxy, GAsyncResult *result, gpointer user_dat NMModemOfonoPrivate *priv = NM_MODEM_OFONO_GET_PRIVATE (self); GError *error = NULL; - nm_log_dbg (LOGD_MB, "%s:", __func__); - priv->context_proxy = g_dbus_proxy_new_for_bus_finish (result, &error); if (error) { - nm_log_err (LOGD_MB, "(%s) failed to create ofono ConnectionContext DBus proxy: %s", - nm_modem_get_uid (NM_MODEM (self)), - error->message ? error->message : "(unknown)"); - + _LOGE ("failed to create ofono ConnectionContext DBus proxy: %s", error->message); g_signal_emit_by_name (self, NM_MODEM_PREPARE_RESULT, FALSE, NM_DEVICE_STATE_REASON_MODEM_BUSY); return; @@ -1084,8 +1011,6 @@ do_context_activate (NMModemOfono *self) g_return_if_fail (NM_IS_MODEM_OFONO (self)); - nm_log_dbg (LOGD_MB, "in %s", __func__); - g_value_init (&value, G_TYPE_BOOLEAN); g_value_set_boolean (&value, TRUE); @@ -1109,8 +1034,6 @@ create_connect_properties (NMConnection *connection) GHashTable *properties; const char *str; - nm_log_dbg (LOGD_MB, "in %s", __func__); - setting = nm_connection_get_setting_gsm (connection); properties = g_hash_table_new (g_str_hash, g_str_equal); @@ -1139,13 +1062,11 @@ act_stage1_prepare (NMModem *modem, const char *context_id; char **id = NULL; - nm_log_dbg (LOGD_MB, "%s", __func__); - context_id = nm_connection_get_id (connection); id = g_strsplit (context_id, "/", 0); g_assert (id[2]); - nm_log_dbg (LOGD_MB, " trying %s %s", id[1], id[2]); + _LOGD ("trying %s %s", id[1], id[2]); g_free (priv->context_path); priv->context_path = g_strdup_printf ("%s/%s", @@ -1163,16 +1084,12 @@ act_stage1_prepare (NMModem *modem, priv->connect_properties = create_connect_properties (connection); - nm_log_info (LOGD_MB, "(%s): activating context %s", - nm_modem_get_path (modem), - priv->context_path); + _LOGI ("activating context %s", priv->context_path); if (nm_modem_get_state (modem) == NM_MODEM_STATE_REGISTERED) { do_context_activate (self); } else { - nm_log_warn (LOGD_MB, "(%s): could not activate context, " - "modem is not registered.", - nm_modem_get_path (modem)); + _LOGW ("could not activate context: modem is not registered."); *reason = NM_DEVICE_STATE_REASON_MODEM_NO_CARRIER; return NM_ACT_STAGE_RETURN_FAILURE; } @@ -1187,14 +1104,9 @@ modem_proxy_new_cb (GDBusProxy *proxy, GAsyncResult *result, gpointer user_data) NMModemOfonoPrivate *priv = NM_MODEM_OFONO_GET_PRIVATE (self); GError *error = NULL; - nm_log_dbg (LOGD_MB, "in %s", __func__); - priv->modem_proxy = g_dbus_proxy_new_for_bus_finish (result, &error); if (error) { - nm_log_err (LOGD_MB, "(%s) failed to create ofono modem DBus proxy: %s", - nm_modem_get_uid (NM_MODEM (self)), - error->message ? error->message : "(unknown)"); - + _LOGE ("failed to create ofono modem DBus proxy: %s", error->message); return; } @@ -1225,8 +1137,6 @@ constructed (GObject *object) { NMModemOfono *self = NM_MODEM_OFONO (object); - nm_log_dbg (LOGD_MB, "in %s", __func__); - g_dbus_proxy_new_for_bus (G_BUS_TYPE_SYSTEM, G_DBUS_PROXY_FLAGS_DO_NOT_AUTO_START, NULL, @@ -1244,8 +1154,6 @@ dispose (GObject *object) NMModemOfono *self = NM_MODEM_OFONO (object); NMModemOfonoPrivate *priv = NM_MODEM_OFONO_GET_PRIVATE (self); - nm_log_dbg (LOGD_MB, "in %s", __func__); - if (priv->connect_properties) { g_hash_table_destroy (priv->connect_properties); priv->connect_properties = NULL; @@ -1278,8 +1186,6 @@ nm_modem_ofono_class_init (NMModemOfonoClass *klass) GObjectClass *object_class = G_OBJECT_CLASS (klass); NMModemClass *modem_class = NM_MODEM_CLASS (klass); - nm_log_dbg (LOGD_MB, "in %s", __func__); - g_type_class_add_private (object_class, sizeof (NMModemOfonoPrivate)); /* Virtual methods */ From 0c9527d9b8720649a4948fe41d673f6391cc0952 Mon Sep 17 00:00:00 2001 From: Dan Williams Date: Thu, 23 Jun 2016 11:58:30 -0500 Subject: [PATCH 28/30] wwan/ofono: fix comment about IP4Config refcounting --- src/devices/wwan/nm-modem-ofono.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/devices/wwan/nm-modem-ofono.c b/src/devices/wwan/nm-modem-ofono.c index 39c99ee227..ffc565b340 100644 --- a/src/devices/wwan/nm-modem-ofono.c +++ b/src/devices/wwan/nm-modem-ofono.c @@ -946,8 +946,9 @@ static_stage3_ip4_config_start (NMModem *_self, _LOGD ("IP4 config is done; setting modem_state -> CONNECTED"); g_signal_emit_by_name (self, NM_MODEM_IP4_CONFIG_RESULT, priv->ip4_config, error); - /* TODO: review!!! */ + /* Signal listener takes ownership of the IP4Config */ priv->ip4_config = NULL; + nm_modem_set_state (NM_MODEM (self), NM_MODEM_STATE_CONNECTED, nm_modem_state_to_string (NM_MODEM_STATE_CONNECTED)); From 7d89b862f434abe9e8e2871dd327ae68b8c8c2e1 Mon Sep 17 00:00:00 2001 From: Dan Williams Date: Thu, 23 Jun 2016 11:58:57 -0500 Subject: [PATCH 29/30] wwan/ofono: remove unused code --- src/devices/wwan/nm-modem-ofono.c | 5 ----- 1 file changed, 5 deletions(-) diff --git a/src/devices/wwan/nm-modem-ofono.c b/src/devices/wwan/nm-modem-ofono.c index ffc565b340..07b9bd8b0b 100644 --- a/src/devices/wwan/nm-modem-ofono.c +++ b/src/devices/wwan/nm-modem-ofono.c @@ -1008,15 +1008,10 @@ static void do_context_activate (NMModemOfono *self) { NMModemOfonoPrivate *priv = NM_MODEM_OFONO_GET_PRIVATE (self); - GValue value = G_VALUE_INIT; g_return_if_fail (NM_IS_MODEM_OFONO (self)); - g_value_init (&value, G_TYPE_BOOLEAN); - g_value_set_boolean (&value, TRUE); - g_clear_object (&priv->context_proxy); - g_dbus_proxy_new_for_bus (G_BUS_TYPE_SYSTEM, G_DBUS_PROXY_FLAGS_DO_NOT_AUTO_START, NULL, From 2b958dce91a1799a93d002d8b2b22748e66dd9d7 Mon Sep 17 00:00:00 2001 From: Beniamino Galvani Date: Sun, 26 Jun 2016 09:47:26 +0200 Subject: [PATCH 30/30] wwan/ofono: fix indentation --- src/devices/wwan/nm-modem-ofono.c | 46 +++++++++++++++---------------- 1 file changed, 23 insertions(+), 23 deletions(-) diff --git a/src/devices/wwan/nm-modem-ofono.c b/src/devices/wwan/nm-modem-ofono.c index 07b9bd8b0b..86492d3d98 100644 --- a/src/devices/wwan/nm-modem-ofono.c +++ b/src/devices/wwan/nm-modem-ofono.c @@ -322,9 +322,9 @@ check_connection_compatible (NMModem *modem, static void handle_sim_property (GDBusProxy *proxy, - const char *property, - GVariant *v, - gpointer user_data) + const char *property, + GVariant *v, + gpointer user_data) { NMModemOfono *self = NM_MODEM_OFONO (user_data); NMModemOfonoPrivate *priv = NM_MODEM_OFONO_GET_PRIVATE (self); @@ -602,9 +602,9 @@ handle_connman_iface (NMModemOfono *self, gboolean found) static void handle_modem_property (GDBusProxy *proxy, - const char *property, - GVariant *v, - gpointer user_data) + const char *property, + GVariant *v, + gpointer user_data) { NMModemOfono *self = NM_MODEM_OFONO (user_data); NMModemOfonoPrivate *priv = NM_MODEM_OFONO_GET_PRIVATE (self); @@ -934,8 +934,8 @@ out: static NMActStageReturn static_stage3_ip4_config_start (NMModem *_self, - NMActRequest *req, - NMDeviceStateReason *reason) + NMActRequest *req, + NMDeviceStateReason *reason) { NMModemOfono *self = NM_MODEM_OFONO (_self); NMModemOfonoPrivate *priv = NM_MODEM_OFONO_GET_PRIVATE (self); @@ -950,8 +950,8 @@ static_stage3_ip4_config_start (NMModem *_self, priv->ip4_config = NULL; nm_modem_set_state (NM_MODEM (self), - NM_MODEM_STATE_CONNECTED, - nm_modem_state_to_string (NM_MODEM_STATE_CONNECTED)); + NM_MODEM_STATE_CONNECTED, + nm_modem_state_to_string (NM_MODEM_STATE_CONNECTED)); ret = NM_ACT_STAGE_RETURN_POSTPONE; } @@ -1066,8 +1066,8 @@ act_stage1_prepare (NMModem *modem, g_free (priv->context_path); priv->context_path = g_strdup_printf ("%s/%s", - nm_modem_get_path (modem), - id[2]); + nm_modem_get_path (modem), + id[2]); g_strfreev (id); if (!priv->context_path) { @@ -1108,19 +1108,19 @@ modem_proxy_new_cb (GDBusProxy *proxy, GAsyncResult *result, gpointer user_data) /* Watch for custom ofono PropertyChanged signals */ _nm_dbus_signal_connect (priv->modem_proxy, - "PropertyChanged", - G_VARIANT_TYPE ("(sv)"), - G_CALLBACK (modem_property_changed), - self); + "PropertyChanged", + G_VARIANT_TYPE ("(sv)"), + G_CALLBACK (modem_property_changed), + self); g_dbus_proxy_call (priv->modem_proxy, - "GetProperties", - NULL, - G_DBUS_CALL_FLAGS_NONE, - 20000, - NULL, - (GAsyncReadyCallback) modem_get_properties_done, - g_object_ref (self)); + "GetProperties", + NULL, + G_DBUS_CALL_FLAGS_NONE, + 20000, + NULL, + (GAsyncReadyCallback) modem_get_properties_done, + g_object_ref (self)); } static void