summary refs log tree commit diff
path: root/src/core/devices/wwan
diff options
context:
space:
mode:
authorMichael Biebl <biebl@debian.org>2021-10-01 23:05:04 +0200
committerMichael Biebl <biebl@debian.org>2021-10-01 23:05:04 +0200
commite74c568b07b50b97873fb4ee1d776dedefbd54d6 (patch)
tree3469f17ea9af91f7ff169b890633bda68b0cf76e /src/core/devices/wwan
parentbfe522304da217296e2a61040f58e35ec5d6f3f2 (diff)
New upstream version 1.32.12 upstream/1.32.12
Diffstat (limited to 'src/core/devices/wwan')
-rw-r--r--src/core/devices/wwan/meson.build2
-rw-r--r--src/core/devices/wwan/nm-device-modem.c36
-rw-r--r--src/core/devices/wwan/nm-modem-broadband.c4
-rw-r--r--src/core/devices/wwan/nm-modem-manager.c2
-rw-r--r--src/core/devices/wwan/nm-modem-ofono.c172
-rw-r--r--src/core/devices/wwan/nm-modem-ofono.h2
-rw-r--r--src/core/devices/wwan/nm-modem.c13
-rw-r--r--src/core/devices/wwan/nm-wwan-factory.c2
8 files changed, 154 insertions, 79 deletions
diff --git a/src/core/devices/wwan/meson.build b/src/core/devices/wwan/meson.build
index 87af0429..37ef738c 100644
--- a/src/core/devices/wwan/meson.build
+++ b/src/core/devices/wwan/meson.build
@@ -17,7 +17,6 @@ libnm_wwan = shared_module(
     libsystemd_dep,
     mm_glib_dep,
   ],
-  c_args: daemon_c_flags,
   link_args: '-Wl,--version-script,@0@'.format(linker_script),
   link_depends: linker_script,
   install: true,
@@ -51,7 +50,6 @@ libnm_device_plugin_wwan = shared_module(
     libsystemd_dep,
     mm_glib_dep,
   ],
-  c_args: daemon_c_flags,
   link_with: libnm_wwan,
   link_args: ldflags_linker_script_devices,
   link_depends: linker_script_devices,
diff --git a/src/core/devices/wwan/nm-device-modem.c b/src/core/devices/wwan/nm-device-modem.c
index 3ea89d2c..4d892e6f 100644
--- a/src/core/devices/wwan/nm-device-modem.c
+++ b/src/core/devices/wwan/nm-device-modem.c
@@ -14,7 +14,7 @@
 #include "settings/nm-settings-connection.h"
 #include "nm-modem-broadband.h"
 #include "NetworkManagerUtils.h"
-#include "nm-core-internal.h"
+#include "libnm-core-intern/nm-core-internal.h"
 
 #define _NMLOG_DEVICE_TYPE NMDeviceModem
 #include "devices/nm-device-logging.h"
@@ -193,15 +193,20 @@ modem_ip4_config_result(NMModem *modem, NMIP4Config *config, GError *error, gpoi
     NMDeviceModem *self   = NM_DEVICE_MODEM(user_data);
     NMDevice *     device = NM_DEVICE(self);
 
-    g_return_if_fail(nm_device_activate_ip4_state_in_conf(device) == TRUE);
+    if (!nm_device_activate_ip4_state_in_conf(device)) {
+        _LOGD(LOGD_MB | LOGD_IP4,
+              "retrieving IPv4 configuration while no longer in state IPv4 conf");
+        return;
+    }
 
     if (error) {
         _LOGW(LOGD_MB | LOGD_IP4, "retrieving IPv4 configuration failed: %s", error->message);
         nm_device_ip_method_failed(device, AF_INET, NM_DEVICE_STATE_REASON_IP_CONFIG_UNAVAILABLE);
-    } else {
-        nm_device_set_dev2_ip_config(device, AF_INET, NM_IP_CONFIG_CAST(config));
-        nm_device_activate_schedule_ip_config_result(device, AF_INET, NULL);
+        return;
     }
+
+    nm_device_set_dev2_ip_config(device, AF_INET, NM_IP_CONFIG_CAST(config));
+    nm_device_activate_schedule_ip_config_result(device, AF_INET, NULL);
 }
 
 static void
@@ -218,7 +223,11 @@ modem_ip6_config_result(NMModem *    modem,
     gs_unref_object NMIP6Config *ignored    = NULL;
     gboolean                     got_config = !!config;
 
-    g_return_if_fail(nm_device_activate_ip6_state_in_conf(device) == TRUE);
+    if (!nm_device_activate_ip6_state_in_conf(device)) {
+        _LOGD(LOGD_MB | LOGD_IP6,
+              "retrieving IPv6 configuration while no longer in state IPv6 conf");
+        return;
+    }
 
     if (error) {
         _LOGW(LOGD_MB | LOGD_IP6, "retrieving IPv6 configuration failed: %s", error->message);
@@ -357,7 +366,6 @@ modem_state_cb(NMModem *modem, int new_state_i, int old_state_i, gpointer user_d
         nm_device_state_changed(device,
                                 NM_DEVICE_STATE_FAILED,
                                 NM_DEVICE_STATE_REASON_MODEM_NO_CARRIER);
-        return;
     }
 
     if (new_state > NM_MODEM_STATE_LOCKED && old_state == NM_MODEM_STATE_LOCKED) {
@@ -856,14 +864,13 @@ dispose(GObject *object)
 static const NMDBusInterfaceInfoExtended interface_info_device_modem = {
     .parent = NM_DEFINE_GDBUS_INTERFACE_INFO_INIT(
         NM_DBUS_INTERFACE_DEVICE_MODEM,
-        .signals    = NM_DEFINE_GDBUS_SIGNAL_INFOS(&nm_signal_info_property_changed_legacy, ),
         .properties = NM_DEFINE_GDBUS_PROPERTY_INFOS(
-            NM_DEFINE_DBUS_PROPERTY_INFO_EXTENDED_READABLE_L("ModemCapabilities",
-                                                             "u",
-                                                             NM_DEVICE_MODEM_CAPABILITIES),
-            NM_DEFINE_DBUS_PROPERTY_INFO_EXTENDED_READABLE_L("CurrentCapabilities",
-                                                             "u",
-                                                             NM_DEVICE_MODEM_CURRENT_CAPABILITIES),
+            NM_DEFINE_DBUS_PROPERTY_INFO_EXTENDED_READABLE("ModemCapabilities",
+                                                           "u",
+                                                           NM_DEVICE_MODEM_CAPABILITIES),
+            NM_DEFINE_DBUS_PROPERTY_INFO_EXTENDED_READABLE("CurrentCapabilities",
+                                                           "u",
+                                                           NM_DEVICE_MODEM_CURRENT_CAPABILITIES),
             NM_DEFINE_DBUS_PROPERTY_INFO_EXTENDED_READABLE("DeviceId",
                                                            "s",
                                                            NM_DEVICE_MODEM_DEVICE_ID),
@@ -871,7 +878,6 @@ static const NMDBusInterfaceInfoExtended interface_info_device_modem = {
                                                            "s",
                                                            NM_DEVICE_MODEM_OPERATOR_CODE),
             NM_DEFINE_DBUS_PROPERTY_INFO_EXTENDED_READABLE("Apn", "s", NM_DEVICE_MODEM_APN), ), ),
-    .legacy_property_changed = TRUE,
 };
 
 static void
diff --git a/src/core/devices/wwan/nm-modem-broadband.c b/src/core/devices/wwan/nm-modem-broadband.c
index 1297d964..0872a8a1 100644
--- a/src/core/devices/wwan/nm-modem-broadband.c
+++ b/src/core/devices/wwan/nm-modem-broadband.c
@@ -11,10 +11,10 @@
 #include <arpa/inet.h>
 #include <libmm-glib.h>
 
-#include "nm-core-internal.h"
+#include "libnm-core-intern/nm-core-internal.h"
 #include "NetworkManagerUtils.h"
 #include "devices/nm-device-private.h"
-#include "platform/nm-platform.h"
+#include "libnm-platform/nm-platform.h"
 #include "nm-ip4-config.h"
 #include "nm-ip6-config.h"
 
diff --git a/src/core/devices/wwan/nm-modem-manager.c b/src/core/devices/wwan/nm-modem-manager.c
index 598c6898..4fb9a378 100644
--- a/src/core/devices/wwan/nm-modem-manager.c
+++ b/src/core/devices/wwan/nm-modem-manager.c
@@ -17,7 +17,7 @@
     #define sd_booted() FALSE
 #endif
 
-#include "nm-std-aux/nm-dbus-compat.h"
+#include "libnm-std-aux/nm-dbus-compat.h"
 #include "nm-modem.h"
 #include "nm-modem-broadband.h"
 
diff --git a/src/core/devices/wwan/nm-modem-ofono.c b/src/core/devices/wwan/nm-modem-ofono.c
index 21734cee..78ad7b68 100644
--- a/src/core/devices/wwan/nm-modem-ofono.c
+++ b/src/core/devices/wwan/nm-modem-ofono.c
@@ -7,10 +7,10 @@
 
 #include "nm-modem-ofono.h"
 
-#include "nm-core-internal.h"
+#include "libnm-core-intern/nm-core-internal.h"
 #include "devices/nm-device-private.h"
 #include "nm-modem.h"
-#include "platform/nm-platform.h"
+#include "libnm-platform/nm-platform.h"
 #include "nm-ip4-config.h"
 
 #define VARIANT_IS_OF_TYPE_BOOLEAN(v) \
@@ -316,10 +316,9 @@ handle_sim_property(GDBusProxy *proxy, const char *property, GVariant *v, gpoint
 static void
 sim_property_changed(GDBusProxy *proxy, const char *property, GVariant *v, gpointer user_data)
 {
-    GVariant *v_child = g_variant_get_child_value(v, 0);
+    gs_unref_variant 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
@@ -330,7 +329,7 @@ sim_get_properties_done(GObject *source, GAsyncResult *result, gpointer user_dat
     gs_free_error GError *error             = NULL;
     gs_unref_variant GVariant *v_properties = NULL;
     gs_unref_variant GVariant *v_dict       = NULL;
-    GVariant *                 v;
+    gs_unref_variant GVariant *v            = NULL;
     GVariantIter               i;
     const char *               property;
 
@@ -370,9 +369,8 @@ sim_get_properties_done(GObject *source, GAsyncResult *result, gpointer user_dat
      */
 
     g_variant_iter_init(&i, v_dict);
-    while (g_variant_iter_next(&i, "{&sv}", &property, &v)) {
+    while (g_variant_iter_loop(&i, "{&sv}", &property, &v)) {
         handle_sim_property(NULL, property, v, self);
-        g_variant_unref(v);
     }
 }
 
@@ -477,10 +475,9 @@ handle_connman_property(GDBusProxy *proxy, const char *property, GVariant *v, gp
 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);
+    gs_unref_variant 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
@@ -491,7 +488,7 @@ connman_get_properties_done(GObject *source, GAsyncResult *result, gpointer user
     gs_free_error GError *error             = NULL;
     gs_unref_variant GVariant *v_properties = NULL;
     gs_unref_variant GVariant *v_dict       = NULL;
-    GVariant *                 v;
+    gs_unref_variant GVariant *v            = NULL;
     GVariantIter               i;
     const char *               property;
 
@@ -523,9 +520,8 @@ connman_get_properties_done(GObject *source, GAsyncResult *result, gpointer user
      */
 
     g_variant_iter_init(&i, v_dict);
-    while (g_variant_iter_next(&i, "{&sv}", &property, &v)) {
+    while (g_variant_iter_loop(&i, "{&sv}", &property, &v)) {
         handle_connman_property(NULL, property, v, self);
-        g_variant_unref(v);
     }
 }
 
@@ -700,9 +696,8 @@ modem_get_properties_done(GObject *source, GAsyncResult *result, gpointer user_d
      */
 
     g_variant_iter_init(&i, v_dict);
-    while (g_variant_iter_next(&i, "{&sv}", &property, &v)) {
+    while (g_variant_iter_loop(&i, "{&sv}", &property, &v)) {
         handle_modem_property(NULL, property, v, self);
-        g_variant_unref(v);
     }
 }
 
@@ -726,35 +721,30 @@ stage1_prepare_done(GObject *source, GAsyncResult *result, gpointer user_data)
     nm_clear_pointer(&priv->connect_properties, g_hash_table_destroy);
 
     if (error) {
-        _LOGW("connection failed: %s", error->message);
-
-        nm_modem_emit_prepare_result(NM_MODEM(self), 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...
-         */
+        if (!g_strstr_len(error->message,
+                          NM_STRLEN(OFONO_ERROR_IN_PROGRESS),
+                          OFONO_ERROR_IN_PROGRESS)) {
+            nm_modem_emit_prepare_result(NM_MODEM(self), FALSE, NM_DEVICE_STATE_REASON_MODEM_BUSY);
+        }
     }
 }
 
 static void
-context_property_changed(GDBusProxy *proxy, const char *property, GVariant *v, gpointer user_data)
+handle_settings(GVariant *v_dict, gpointer user_data)
 {
     NMModemOfono *       self = NM_MODEM_OFONO(user_data);
     NMModemOfonoPrivate *priv = NM_MODEM_OFONO_GET_PRIVATE(self);
     NMPlatformIP4Address addr;
-    gboolean             ret          = FALSE;
-    gs_unref_variant GVariant *v_dict = NULL;
-    const char *               interface;
-    const char *               s;
-    const char **              array, **iter;
-    guint32                    address_network, gateway_network;
-    guint32                    ip4_route_table, ip4_route_metric;
-    int                        ifindex;
-    GError *                   error = NULL;
+    gboolean             ret = FALSE;
+    const char *         interface;
+    const char *         s;
+    const char **        array, **iter;
+    guint32              address_network, gateway_network;
+    guint32              ip4_route_table, ip4_route_metric;
+    int                  ifindex;
+    GError *             error = NULL;
 
-    _LOGD("PropertyChanged: %s", property);
+    //_LOGD("PropertyChanged: %s", property);
 
     /*
      * TODO: might be a good idea and re-factor this to mimic bluez-device,
@@ -762,15 +752,6 @@ context_property_changed(GDBusProxy *proxy, const char *property, GVariant *v, g
      * handle the action.
      */
 
-    if (g_strcmp0(property, "Settings") != 0)
-        return;
-
-    v_dict = g_variant_get_child_value(v, 0);
-    if (!v_dict) {
-        _LOGW("error getting IPv4 Settings: no v_dict");
-        goto out;
-    }
-
     _LOGI("IPv4 static Settings:");
 
     if (!g_variant_lookup(v_dict, "Interface", "&s", &interface)) {
@@ -909,6 +890,28 @@ out:
     }
 }
 
+static void
+context_property_changed(GDBusProxy *proxy, const char *property, GVariant *v, gpointer user_data)
+{
+    NMModemOfono *   self             = NM_MODEM_OFONO(user_data);
+    gs_unref_variant GVariant *v_dict = NULL;
+
+    _LOGD("PropertyChanged: %s", property);
+
+    if (g_strcmp0(property, "Settings") != 0)
+        return;
+
+    v_dict = g_variant_get_child_value(v, 0);
+    if (!v_dict) {
+        _LOGW("ofono: (%s): error getting IPv4 Settings", nm_modem_get_uid(NM_MODEM(self)));
+        return;
+    }
+
+    g_assert(g_variant_is_of_type(v_dict, G_VARIANT_TYPE_VARDICT));
+
+    handle_settings(v_dict, user_data);
+}
+
 static NMActStageReturn
 static_stage3_ip4_config_start(NMModem *            modem,
                                NMActRequest *       req,
@@ -936,6 +939,72 @@ static_stage3_ip4_config_start(NMModem *            modem,
 }
 
 static void
+context_properties_cb(GDBusProxy *proxy, GAsyncResult *result, gpointer user_data)
+{
+    NMModemOfono *       self;
+    NMModemOfonoPrivate *priv;
+    gs_free_error GError *error           = NULL;
+    gs_unref_variant GVariant *properties = NULL;
+    gs_unref_variant GVariant *settings   = NULL;
+    gs_unref_variant GVariant *v_dict     = NULL;
+    gboolean                   active;
+
+    self = NM_MODEM_OFONO(user_data);
+    priv = NM_MODEM_OFONO_GET_PRIVATE(self);
+
+    properties = g_dbus_proxy_call_finish(proxy, result, &error);
+
+    if (!properties) {
+        _LOGW("ofono: connection failed: no context properties returned %s", error->message);
+        g_clear_error(&error);
+        goto error;
+    }
+
+    v_dict = g_variant_get_child_value(properties, 0);
+    if (!v_dict || !g_variant_is_of_type(v_dict, G_VARIANT_TYPE_VARDICT)) {
+        _LOGW("ofono: connection failed; could not read connection properties");
+        goto error;
+    }
+
+    if (!g_variant_lookup(v_dict, "Active", "b", &active)) {
+        _LOGW("ofono: connection failed; can not read 'Active' property");
+        goto error;
+    }
+
+    /* Watch for custom ofono PropertyChanged signals */
+    _nm_dbus_signal_connect(priv->context_proxy,
+                            "PropertyChanged",
+                            G_VARIANT_TYPE("(sv)"),
+                            G_CALLBACK(context_property_changed),
+                            self);
+
+    if (active) {
+        _LOGD("ofono: connection is already Active");
+
+        settings = g_variant_lookup_value(v_dict, "Settings", G_VARIANT_TYPE_VARDICT);
+        if (settings == NULL) {
+            _LOGW("ofono: connection failed; can not read 'Settings' property");
+            goto error;
+        }
+
+        handle_settings(settings, user_data);
+    } else {
+        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,
+                          self);
+    }
+    return;
+
+error:
+    nm_modem_emit_prepare_result(NM_MODEM(self), FALSE, NM_DEVICE_STATE_REASON_MODEM_BUSY);
+}
+
+static void
 context_proxy_new_cb(GObject *source, GAsyncResult *result, gpointer user_data)
 {
     NMModemOfono *       self;
@@ -973,19 +1042,15 @@ context_proxy_new_cb(GObject *source, GAsyncResult *result, gpointer user_data)
      */
     g_clear_object(&priv->ip4_config);
 
-    _nm_dbus_signal_connect(priv->context_proxy,
-                            "PropertyChanged",
-                            G_VARIANT_TYPE("(sv)"),
-                            G_CALLBACK(context_property_changed),
-                            self);
-
+    /* We need to directly query ConnectionContextinteface to get the current
+     * property values */
     g_dbus_proxy_call(priv->context_proxy,
-                      "SetProperty",
-                      g_variant_new("(sv)", "Active", g_variant_new("b", TRUE)),
+                      "GetProperties",
+                      NULL,
                       G_DBUS_CALL_FLAGS_NONE,
                       20000,
-                      priv->context_proxy_cancellable,
-                      stage1_prepare_done,
+                      NULL,
+                      (GAsyncReadyCallback) context_properties_cb,
                       self);
 }
 
@@ -1069,6 +1134,7 @@ modem_act_stage1_prepare(NMModem *            modem,
 
     _LOGI("activating context %s", priv->context_path);
 
+    update_modem_state(self);
     if (nm_modem_get_state(modem) == NM_MODEM_STATE_REGISTERED) {
         do_context_activate(self);
     } else {
diff --git a/src/core/devices/wwan/nm-modem-ofono.h b/src/core/devices/wwan/nm-modem-ofono.h
index 260e3954..ebe21023 100644
--- a/src/core/devices/wwan/nm-modem-ofono.h
+++ b/src/core/devices/wwan/nm-modem-ofono.h
@@ -25,6 +25,8 @@
 #define OFONO_DBUS_INTERFACE_CONNECTION_CONTEXT "org.ofono.ConnectionContext"
 #define OFONO_DBUS_INTERFACE_SIM_MANAGER        "org.ofono.SimManager"
 
+#define OFONO_ERROR_IN_PROGRESS "org.ofono.Error.InProgress"
+
 typedef struct _NMModemOfono      NMModemOfono;
 typedef struct _NMModemOfonoClass NMModemOfonoClass;
 
diff --git a/src/core/devices/wwan/nm-modem.c b/src/core/devices/wwan/nm-modem.c
index 0d334fa4..15baa677 100644
--- a/src/core/devices/wwan/nm-modem.c
+++ b/src/core/devices/wwan/nm-modem.c
@@ -10,10 +10,11 @@
 
 #include <fcntl.h>
 #include <termios.h>
+#include <linux/if.h>
 #include <linux/rtnetlink.h>
 
-#include "nm-core-internal.h"
-#include "platform/nm-platform.h"
+#include "libnm-core-intern/nm-core-internal.h"
+#include "libnm-platform/nm-platform.h"
 #include "nm-setting-connection.h"
 #include "NetworkManagerUtils.h"
 #include "devices/nm-device-private.h"
@@ -799,8 +800,10 @@ nm_modem_ip4_pre_commit(NMModem *modem, NMDevice *device, NMIP4Config *config)
 
         g_assert(address);
         if (address->plen == 32)
-            nm_platform_link_set_noarp(nm_device_get_platform(device),
-                                       nm_device_get_ip_ifindex(device));
+            nm_platform_link_change_flags(nm_device_get_platform(device),
+                                          nm_device_get_ip_ifindex(device),
+                                          IFF_NOARP,
+                                          TRUE);
     }
 }
 
@@ -1199,7 +1202,7 @@ deactivate_cleanup(NMModem *self, NMDevice *device, gboolean stop_ppp_manager)
 
                 nm_platform_ip_route_flush(platform, AF_UNSPEC, ifindex);
                 nm_platform_ip_address_flush(platform, AF_UNSPEC, ifindex);
-                nm_platform_link_set_down(platform, ifindex);
+                nm_platform_link_change_flags(platform, ifindex, IFF_UP, FALSE);
             }
         }
     }
diff --git a/src/core/devices/wwan/nm-wwan-factory.c b/src/core/devices/wwan/nm-wwan-factory.c
index 5d2ce2b3..0d802ae1 100644
--- a/src/core/devices/wwan/nm-wwan-factory.c
+++ b/src/core/devices/wwan/nm-wwan-factory.c
@@ -12,7 +12,7 @@
 #include "nm-setting-cdma.h"
 #include "nm-modem-manager.h"
 #include "nm-device-modem.h"
-#include "platform/nm-platform.h"
+#include "libnm-platform/nm-platform.h"
 
 /*****************************************************************************/