summary refs log tree commit diff
path: root/src/core/devices/wifi
diff options
context:
space:
mode:
Diffstat (limited to 'src/core/devices/wifi')
-rw-r--r--src/core/devices/wifi/nm-device-iwd.c11
-rw-r--r--src/core/devices/wifi/nm-device-olpc-mesh.c7
-rw-r--r--src/core/devices/wifi/nm-device-wifi-p2p.c44
-rw-r--r--src/core/devices/wifi/nm-device-wifi.c23
-rw-r--r--src/core/devices/wifi/nm-wifi-ap.c2
-rw-r--r--src/core/devices/wifi/nm-wifi-common.c2
-rw-r--r--src/core/devices/wifi/nm-wifi-p2p-peer.c18
-rw-r--r--src/core/devices/wifi/nm-wifi-utils.c27
-rw-r--r--src/core/devices/wifi/tests/test-devices-wifi.c2
9 files changed, 66 insertions, 70 deletions
diff --git a/src/core/devices/wifi/nm-device-iwd.c b/src/core/devices/wifi/nm-device-iwd.c
index 56338743..27a3188b 100644
--- a/src/core/devices/wifi/nm-device-iwd.c
+++ b/src/core/devices/wifi/nm-device-iwd.c
@@ -18,6 +18,7 @@
 #include "libnm-glib-aux/nm-ref-string.h"
 #include "nm-iwd-manager.h"
 #include "libnm-core-aux-intern/nm-common-macros.h"
+#include "libnm-core-aux-intern/nm-libnm-core-utils.h"
 #include "nm-setting-8021x.h"
 #include "nm-setting-connection.h"
 #include "nm-setting-wireless-security.h"
@@ -966,7 +967,7 @@ complete_connection(NMDevice *           device,
     gboolean            hidden = FALSE;
     const char *        mode;
 
-    s_wifi = nm_connection_get_setting_wireless(connection);
+    s_wifi = _nm_connection_ensure_setting(connection, NM_TYPE_SETTING_WIRELESS);
 
     mode = s_wifi ? nm_setting_wireless_get_mode(s_wifi) : NULL;
 
@@ -1031,12 +1032,6 @@ complete_connection(NMDevice *           device,
         }
 
         ssid = nm_wifi_ap_get_ssid(ap);
-
-        /* Add a wifi setting if one doesn't exist yet */
-        if (!s_wifi) {
-            s_wifi = (NMSettingWireless *) nm_setting_wireless_new();
-            nm_connection_add_setting(connection, NM_SETTING(s_wifi));
-        }
     }
 
     if (ap) {
@@ -2651,7 +2646,7 @@ get_property(GObject *object, guint prop_id, GValue *value, GParamSpec *pspec)
         break;
     case PROP_ACCESS_POINTS:
         list = nm_wifi_aps_get_paths(&priv->aps_lst_head, TRUE);
-        g_value_take_boxed(value, nm_utils_strv_make_deep_copied(list));
+        g_value_take_boxed(value, nm_strv_make_deep_copied(list));
         break;
     case PROP_ACTIVE_ACCESS_POINT:
         nm_dbus_utils_g_value_set_object_path(value, priv->current_ap);
diff --git a/src/core/devices/wifi/nm-device-olpc-mesh.c b/src/core/devices/wifi/nm-device-olpc-mesh.c
index 040350d5..d829f9ae 100644
--- a/src/core/devices/wifi/nm-device-olpc-mesh.c
+++ b/src/core/devices/wifi/nm-device-olpc-mesh.c
@@ -28,6 +28,7 @@
 #include "nm-setting-connection.h"
 #include "nm-setting-olpc-mesh.h"
 #include "nm-manager.h"
+#include "libnm-core-aux-intern/nm-libnm-core-utils.h"
 #include "libnm-platform/nm-platform.h"
 
 #define _NMLOG_DEVICE_TYPE NMDeviceOlpcMesh
@@ -88,11 +89,7 @@ complete_connection(NMDevice *           device,
 {
     NMSettingOlpcMesh *s_mesh;
 
-    s_mesh = nm_connection_get_setting_olpc_mesh(connection);
-    if (!s_mesh) {
-        s_mesh = (NMSettingOlpcMesh *) nm_setting_olpc_mesh_new();
-        nm_connection_add_setting(connection, NM_SETTING(s_mesh));
-    }
+    s_mesh = _nm_connection_ensure_setting(connection, NM_TYPE_SETTING_OLPC_MESH);
 
     if (!nm_setting_olpc_mesh_get_ssid(s_mesh)) {
         gs_unref_bytes GBytes *ssid = NULL;
diff --git a/src/core/devices/wifi/nm-device-wifi-p2p.c b/src/core/devices/wifi/nm-device-wifi-p2p.c
index a8ea2ed7..67202a67 100644
--- a/src/core/devices/wifi/nm-device-wifi-p2p.c
+++ b/src/core/devices/wifi/nm-device-wifi-p2p.c
@@ -15,6 +15,7 @@
 #include "NetworkManagerUtils.h"
 #include "devices/nm-device-private.h"
 #include "nm-act-request.h"
+#include "libnm-core-aux-intern/nm-libnm-core-utils.h"
 #include "libnm-core-intern/nm-core-internal.h"
 #include "libnm-glib-aux/nm-ref-string.h"
 #include "nm-ip4-config.h"
@@ -302,10 +303,7 @@ complete_connection(NMDevice *           device,
     }
 
     /* Add a Wi-Fi P2P setting if one doesn't exist yet */
-    if (!s_wifi_p2p) {
-        s_wifi_p2p = NM_SETTING_WIFI_P2P(nm_setting_wifi_p2p_new());
-        nm_connection_add_setting(connection, NM_SETTING(s_wifi_p2p));
-    }
+    s_wifi_p2p = _nm_connection_ensure_setting(connection, NM_TYPE_SETTING_WIFI_P2P);
 
     g_object_set(G_OBJECT(s_wifi_p2p), NM_SETTING_WIFI_P2P_PEER, setting_peer, NULL);
 
@@ -560,14 +558,39 @@ act_stage3_ip_config_start(NMDevice *           device,
                            gpointer *           out_config,
                            NMDeviceStateReason *out_failure_reason)
 {
-    gboolean      indicate_addressing_running;
-    NMConnection *connection;
-    const char *  method;
+    NMDeviceWifiP2PPrivate *priv = NM_DEVICE_WIFI_P2P_GET_PRIVATE(device);
+    gboolean                indicate_addressing_running;
+    NMConnection *          connection;
+    const char *            method;
 
     connection = nm_device_get_applied_connection(device);
 
     method = nm_utils_get_ip_config_method(connection, addr_family);
 
+    /* We may have an address assigned by the group owner */
+    if (NM_IN_STRSET(method, NM_SETTING_IP4_CONFIG_METHOD_AUTO) && priv->group_iface
+        && !nm_supplicant_interface_get_p2p_group_owner(priv->group_iface)) {
+        in_addr_t addr;
+        guint8    plen;
+
+        if (nm_supplicant_interface_get_p2p_assigned_addr(priv->group_iface, &addr, &plen)) {
+            NMPlatformIP4Address address = {
+                .addr_source = NM_IP_CONFIG_SOURCE_DHCP,
+            };
+            gs_unref_object NMIP4Config *ip4_config = NULL;
+
+            nm_platform_ip4_address_set_addr(&address, addr, plen);
+
+            ip4_config = nm_device_ip4_config_new(device);
+            nm_ip4_config_add_address(ip4_config, &address);
+
+            nm_device_set_dev2_ip_config(device, AF_INET, NM_IP_CONFIG(ip4_config));
+
+            /* This just disables the addressing indicator. */
+            method = NM_SETTING_IP4_CONFIG_METHOD_DISABLED;
+        }
+    }
+
     if (addr_family == AF_INET)
         indicate_addressing_running = NM_IN_STRSET(method, NM_SETTING_IP4_CONFIG_METHOD_AUTO);
     else {
@@ -622,6 +645,11 @@ get_auto_ip_config_method(NMDevice *device, int addr_family)
     NMDeviceWifiP2P *       self = NM_DEVICE_WIFI_P2P(device);
     NMDeviceWifiP2PPrivate *priv = NM_DEVICE_WIFI_P2P_GET_PRIVATE(self);
 
+    if (addr_family == AF_INET && priv->group_iface
+        && !nm_supplicant_interface_get_p2p_group_owner(priv->group_iface)
+        && nm_supplicant_interface_get_p2p_assigned_addr(priv->group_iface, NULL, NULL))
+        return NM_SETTING_IP4_CONFIG_METHOD_DISABLED;
+
     /* Override the AUTO method to mean shared if we are group owner. */
     if (priv->group_iface && nm_supplicant_interface_get_p2p_group_owner(priv->group_iface)) {
         if (addr_family == AF_INET)
@@ -1163,7 +1191,7 @@ get_property(GObject *object, guint prop_id, GValue *value, GParamSpec *pspec)
     switch (prop_id) {
     case PROP_PEERS:
         list = nm_wifi_p2p_peers_get_paths(&priv->peers_lst_head);
-        g_value_take_boxed(value, nm_utils_strv_make_deep_copied(list));
+        g_value_take_boxed(value, nm_strv_make_deep_copied(list));
         break;
     default:
         G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
diff --git a/src/core/devices/wifi/nm-device-wifi.c b/src/core/devices/wifi/nm-device-wifi.c
index fca2fde5..82896c77 100644
--- a/src/core/devices/wifi/nm-device-wifi.c
+++ b/src/core/devices/wifi/nm-device-wifi.c
@@ -17,6 +17,7 @@
 #include "nm-device-wifi-p2p.h"
 #include "nm-wifi-ap.h"
 #include "libnm-core-aux-intern/nm-common-macros.h"
+#include "libnm-core-aux-intern/nm-libnm-core-utils.h"
 #include "devices/nm-device.h"
 #include "devices/nm-device-private.h"
 #include "nm-dbus-manager.h"
@@ -321,7 +322,7 @@ _scan_request_ssids_track(NMDeviceWifiPrivate *priv, const GPtrArray *ssids)
     now_msec = nm_utils_get_monotonic_timestamp_msec();
 
     if (!priv->scan_request_ssids_hash)
-        priv->scan_request_ssids_hash = g_hash_table_new(nm_pgbytes_hash, nm_pgbytes_equal);
+        priv->scan_request_ssids_hash = g_hash_table_new(nm_pg_bytes_hash, nm_pg_bytes_equal);
 
     /* Do a little dance. New elements shall keep their order as in @ssids, but all
      * new elements should be sorted in the list preexisting elements of the list.
@@ -1205,10 +1206,7 @@ complete_connection(NMDevice *           device,
     }
 
     /* Add a wifi setting if one doesn't exist yet */
-    if (!s_wifi) {
-        s_wifi = (NMSettingWireless *) nm_setting_wireless_new();
-        nm_connection_add_setting(connection, NM_SETTING(s_wifi));
-    }
+    s_wifi = _nm_connection_ensure_setting(connection, NM_TYPE_SETTING_WIRELESS);
 
     if (ap)
         ssid = nm_wifi_ap_get_ssid(ap);
@@ -1571,7 +1569,7 @@ _scan_request_ssids_build_hidden(NMDeviceWifi *self,
     if (ssids) {
         if (ssids->len < max_scan_ssids) {
             /* Add wildcard SSID using a static wildcard SSID used for every scan */
-            g_ptr_array_insert(ssids, 0, g_bytes_ref(nm_gbytes_get_empty()));
+            g_ptr_array_insert(ssids, 0, g_bytes_ref(nm_g_bytes_get_empty()));
         }
         if (ssids->len >= max_scan_ssids) {
             /* there is no more space. Use what we have. */
@@ -1592,10 +1590,10 @@ _scan_request_ssids_build_hidden(NMDeviceWifi *self,
     if (!ssids) {
         ssids = g_ptr_array_new_full(max_scan_ssids, (GDestroyNotify) g_bytes_unref);
         /* Add wildcard SSID using a static wildcard SSID used for every scan */
-        g_ptr_array_insert(ssids, 0, g_bytes_ref(nm_gbytes_get_empty()));
+        g_ptr_array_insert(ssids, 0, g_bytes_ref(nm_g_bytes_get_empty()));
     }
 
-    unique_ssids = g_hash_table_new(nm_gbytes_hash, nm_gbytes_equal);
+    unique_ssids = g_hash_table_new(nm_g_bytes_hash, nm_g_bytes_equal);
     for (i = 1; i < ssids->len; i++) {
         if (!g_hash_table_add(unique_ssids, ssids->pdata[i]))
             nm_assert_not_reached();
@@ -1673,12 +1671,7 @@ _scan_supplicant_request_scan_cb(NMSupplicantInterface *supp_iface,
      * Artificially keep the scanning state on, for another SCAN_EXTRA_DELAY_MSEC msec. */
     nm_clear_g_source_inst(&priv->scan_request_delay_source);
     priv->scan_request_delay_source =
-        nm_g_source_attach(nm_g_timeout_source_new(SCAN_EXTRA_DELAY_MSEC,
-                                                   G_PRIORITY_DEFAULT,
-                                                   _scan_request_delay_cb,
-                                                   self,
-                                                   NULL),
-                           NULL);
+        nm_g_timeout_add_source(SCAN_EXTRA_DELAY_MSEC, _scan_request_delay_cb, self);
 
     g_clear_object(&priv->scan_request_cancellable);
     _scan_notify_is_scanning(self);
@@ -3646,7 +3639,7 @@ get_property(GObject *object, guint prop_id, GValue *value, GParamSpec *pspec)
         break;
     case PROP_ACCESS_POINTS:
         list = nm_wifi_aps_get_paths(&priv->aps_lst_head, TRUE);
-        g_value_take_boxed(value, nm_utils_strv_make_deep_copied(list));
+        g_value_take_boxed(value, nm_strv_make_deep_copied(list));
         break;
     case PROP_ACTIVE_ACCESS_POINT:
         nm_dbus_utils_g_value_set_object_path(value, priv->current_ap);
diff --git a/src/core/devices/wifi/nm-wifi-ap.c b/src/core/devices/wifi/nm-wifi-ap.c
index 20ed6833..72a60885 100644
--- a/src/core/devices/wifi/nm-wifi-ap.c
+++ b/src/core/devices/wifi/nm-wifi-ap.c
@@ -669,7 +669,7 @@ get_property(GObject *object, guint prop_id, GValue *value, GParamSpec *pspec)
         g_value_set_uint(value, priv->rsn_flags);
         break;
     case PROP_SSID:
-        g_value_take_variant(value, nm_utils_gbytes_to_variant_ay(priv->ssid));
+        g_value_take_variant(value, nm_g_bytes_to_variant_ay(priv->ssid));
         break;
     case PROP_FREQUENCY:
         g_value_set_uint(value, priv->freq);
diff --git a/src/core/devices/wifi/nm-wifi-common.c b/src/core/devices/wifi/nm-wifi-common.c
index b98ef222..d029ce7f 100644
--- a/src/core/devices/wifi/nm-wifi-common.c
+++ b/src/core/devices/wifi/nm-wifi-common.c
@@ -13,7 +13,7 @@
 #include "nm-dbus-manager.h"
 
 #if WITH_IWD
-    #include "nm-device-iwd.h"
+#include "nm-device-iwd.h"
 #endif
 
 /*****************************************************************************/
diff --git a/src/core/devices/wifi/nm-wifi-p2p-peer.c b/src/core/devices/wifi/nm-wifi-p2p-peer.c
index 433c2833..ac13952d 100644
--- a/src/core/devices/wifi/nm-wifi-p2p-peer.c
+++ b/src/core/devices/wifi/nm-wifi-p2p-peer.c
@@ -168,7 +168,7 @@ nm_wifi_p2p_peer_set_name(NMWifiP2PPeer *peer, const char *str)
 {
     NMWifiP2PPeerPrivate *priv = NM_WIFI_P2P_PEER_GET_PRIVATE(peer);
 
-    if (!nm_utils_strdup_reset(&priv->name, str))
+    if (!nm_strdup_reset(&priv->name, str))
         return FALSE;
     _notify(peer, PROP_NAME);
     return TRUE;
@@ -187,7 +187,7 @@ nm_wifi_p2p_peer_set_manufacturer(NMWifiP2PPeer *peer, const char *str)
 {
     NMWifiP2PPeerPrivate *priv = NM_WIFI_P2P_PEER_GET_PRIVATE(peer);
 
-    if (!nm_utils_strdup_reset(&priv->manufacturer, str))
+    if (!nm_strdup_reset(&priv->manufacturer, str))
         return FALSE;
     _notify(peer, PROP_MANUFACTURER);
     return TRUE;
@@ -206,7 +206,7 @@ nm_wifi_p2p_peer_set_model(NMWifiP2PPeer *peer, const char *str)
 {
     NMWifiP2PPeerPrivate *priv = NM_WIFI_P2P_PEER_GET_PRIVATE(peer);
 
-    if (!nm_utils_strdup_reset(&priv->model, str))
+    if (!nm_strdup_reset(&priv->model, str))
         return FALSE;
     _notify(peer, PROP_MODEL);
     return TRUE;
@@ -225,7 +225,7 @@ nm_wifi_p2p_peer_set_model_number(NMWifiP2PPeer *peer, const char *str)
 {
     NMWifiP2PPeerPrivate *priv = NM_WIFI_P2P_PEER_GET_PRIVATE(peer);
 
-    if (!nm_utils_strdup_reset(&priv->model_number, str))
+    if (!nm_strdup_reset(&priv->model_number, str))
         return FALSE;
     _notify(peer, PROP_MODEL_NUMBER);
     return TRUE;
@@ -244,7 +244,7 @@ nm_wifi_p2p_peer_set_serial(NMWifiP2PPeer *peer, const char *str)
 {
     NMWifiP2PPeerPrivate *priv = NM_WIFI_P2P_PEER_GET_PRIVATE(peer);
 
-    if (!nm_utils_strdup_reset(&priv->serial, str))
+    if (!nm_strdup_reset(&priv->serial, str))
         return FALSE;
     _notify(peer, PROP_SERIAL);
     return TRUE;
@@ -268,7 +268,7 @@ nm_wifi_p2p_peer_set_wfd_ies(NMWifiP2PPeer *peer, GBytes *wfd_ies)
 
     priv = NM_WIFI_P2P_PEER_GET_PRIVATE(peer);
 
-    if (nm_gbytes_equal0(priv->wfd_ies, wfd_ies))
+    if (nm_g_bytes_equal0(priv->wfd_ies, wfd_ies))
         return FALSE;
 
     wfd_ies_old   = g_steal_pointer(&priv->wfd_ies);
@@ -408,9 +408,9 @@ nm_wifi_p2p_peer_update_from_properties(NMWifiP2PPeer *peer, const NMSupplicantP
 
     /* We currently only use the groups information internally to check if
      * the peer is still joined. */
-    if (!nm_utils_strv_equal(priv->groups, peer_info->groups)) {
+    if (!nm_strv_equal(priv->groups, peer_info->groups)) {
         g_free(priv->groups);
-        priv->groups = nm_utils_strv_dup_packed(peer_info->groups, -1);
+        priv->groups = nm_strv_dup_packed(peer_info->groups, -1);
         changed |= TRUE;
     }
 
@@ -509,7 +509,7 @@ get_property(GObject *object, guint prop_id, GValue *value, GParamSpec *pspec)
         g_value_set_string(value, priv->serial);
         break;
     case PROP_WFD_IES:
-        g_value_take_variant(value, nm_utils_gbytes_to_variant_ay(priv->wfd_ies));
+        g_value_take_variant(value, nm_g_bytes_to_variant_ay(priv->wfd_ies));
         break;
     case PROP_HW_ADDRESS:
         g_value_set_string(value, priv->address);
diff --git a/src/core/devices/wifi/nm-wifi-utils.c b/src/core/devices/wifi/nm-wifi-utils.c
index 15ced990..4939e786 100644
--- a/src/core/devices/wifi/nm-wifi-utils.c
+++ b/src/core/devices/wifi/nm-wifi-utils.c
@@ -13,6 +13,7 @@
 
 #include "nm-utils.h"
 #include "libnm-core-intern/nm-core-internal.h"
+#include "libnm-core-aux-intern/nm-libnm-core-utils.h"
 #include "libnm-core-aux-intern/nm-common-macros.h"
 #include "libnm-base/nm-config-base.h"
 
@@ -679,10 +680,7 @@ nm_wifi_utils_complete_connection(GBytes *      ap_ssid,
     }
 
     /* Everything else requires security */
-    if (!s_wsec) {
-        s_wsec = (NMSettingWirelessSecurity *) nm_setting_wireless_security_new();
-        nm_connection_add_setting(connection, NM_SETTING(s_wsec));
-    }
+    s_wsec = _nm_connection_ensure_setting(connection, NM_TYPE_SETTING_WIRELESS_SECURITY);
 
     key_mgmt      = nm_setting_wireless_security_get_key_mgmt(s_wsec);
     auth_alg      = nm_setting_wireless_security_get_auth_alg(s_wsec);
@@ -825,21 +823,11 @@ nm_wifi_utils_complete_connection(GBytes *      ap_ssid,
                      "open",
                      NULL);
     } else if (nm_streq0(key_mgmt, "sae") || (ap_rsn_flags & NM_802_11_AP_SEC_KEY_MGMT_SAE)) {
-        g_object_set(s_wsec,
-                     NM_SETTING_WIRELESS_SECURITY_KEY_MGMT,
-                     "sae",
-                     NM_SETTING_WIRELESS_SECURITY_AUTH_ALG,
-                     "open",
-                     NULL);
+        g_object_set(s_wsec, NM_SETTING_WIRELESS_SECURITY_KEY_MGMT, "sae", NULL);
     } else if (nm_streq0(key_mgmt, "owe")
                || NM_FLAGS_ANY(ap_rsn_flags,
                                NM_802_11_AP_SEC_KEY_MGMT_OWE | NM_802_11_AP_SEC_KEY_MGMT_OWE_TM)) {
-        g_object_set(s_wsec,
-                     NM_SETTING_WIRELESS_SECURITY_KEY_MGMT,
-                     "owe",
-                     NM_SETTING_WIRELESS_SECURITY_AUTH_ALG,
-                     "open",
-                     NULL);
+        g_object_set(s_wsec, NM_SETTING_WIRELESS_SECURITY_KEY_MGMT, "owe", NULL);
     } else if (ap_wpa_flags & NM_802_11_AP_SEC_KEY_MGMT_PSK
                || ap_rsn_flags & NM_802_11_AP_SEC_KEY_MGMT_PSK) {
         g_object_set(s_wsec,
@@ -853,12 +841,7 @@ nm_wifi_utils_complete_connection(GBytes *      ap_ssid,
          */
     } else if (nm_streq0(key_mgmt, "wpa-eap-suite-b-192")
                || (ap_rsn_flags & NM_802_11_AP_SEC_KEY_MGMT_EAP_SUITE_B_192)) {
-        g_object_set(s_wsec,
-                     NM_SETTING_WIRELESS_SECURITY_KEY_MGMT,
-                     "wpa-eap-suite-b-192",
-                     NM_SETTING_WIRELESS_SECURITY_AUTH_ALG,
-                     "open",
-                     NULL);
+        g_object_set(s_wsec, NM_SETTING_WIRELESS_SECURITY_KEY_MGMT, "wpa-eap-suite-b-192", NULL);
     } else {
         g_set_error_literal(error,
                             NM_CONNECTION_ERROR,
diff --git a/src/core/devices/wifi/tests/test-devices-wifi.c b/src/core/devices/wifi/tests/test-devices-wifi.c
index dc278c94..5d1167cf 100644
--- a/src/core/devices/wifi/tests/test-devices-wifi.c
+++ b/src/core/devices/wifi/tests/test-devices-wifi.c
@@ -1445,7 +1445,7 @@ do_test_ssids_options_to_ptrarray(const char *const *ssids)
         const char *ssid  = ssids[i];
         GBytes *    bytes = ssids_arr->pdata[i];
 
-        g_assert(nm_utils_gbytes_equal_mem(bytes, ssid, strlen(ssid)));
+        g_assert(nm_g_bytes_equal_mem(bytes, ssid, strlen(ssid)));
     }
 }