Blame SOURCES/0007-network-Fix-connection-selection-and-SSID-display-fo.patch

44c0da
From e6cebd2fc9b0d18a92f2935e23551b62a7031236 Mon Sep 17 00:00:00 2001
44c0da
From: Benjamin Berg <bberg@redhat.com>
44c0da
Date: Tue, 4 Jan 2022 11:29:25 +0100
44c0da
Subject: [PATCH 7/8] network: Fix connection selection and SSID display for
44c0da
 OWE
44c0da
44c0da
When dealing with OWE APs, we need to use the SSID from the connection
44c0da
rather than the AP. In this case, we want to group the current AP with
44c0da
other APs that have the connection SSID.
44c0da
44c0da
As such, first change the unqiue AP selection to take the active AP and
44c0da
active connection into account (preferring the active AP for correct
44c0da
signal strength display).
44c0da
44c0da
Then, make sure we have the active connection in the list everywhere and
44c0da
skip the SSID check when assiging the AP to the connection for the
44c0da
active AP/connection.
44c0da
44c0da
This way we make sure to have the active connection together with the
44c0da
active AP in the list. The code will prefer to display the connections
44c0da
SSID rather than the APS, so we get the right one for OWE.
44c0da
44c0da
This mimicks the behaviour of newer g-c-c versions without pulling in
44c0da
the full rewrite of the connection list widget.
44c0da
---
44c0da
 panels/network/net-device-wifi.c | 86 ++++++++++++++++++++++++++------
44c0da
 1 file changed, 72 insertions(+), 14 deletions(-)
44c0da
44c0da
diff --git a/panels/network/net-device-wifi.c b/panels/network/net-device-wifi.c
44c0da
index fc2fba63f..af489afcc 100644
44c0da
--- a/panels/network/net-device-wifi.c
44c0da
+++ b/panels/network/net-device-wifi.c
44c0da
@@ -163,25 +163,50 @@ get_access_point_security (NMAccessPoint *ap)
44c0da
 }
44c0da
 
44c0da
 static GPtrArray *
44c0da
-panel_get_strongest_unique_aps (const GPtrArray *aps)
44c0da
+panel_get_strongest_unique_aps (NMDevice *nm_device)
44c0da
 {
44c0da
-        GBytes *ssid, *ssid_tmp;
44c0da
+        const GPtrArray *aps;
44c0da
         GPtrArray *aps_unique = NULL;
44c0da
         gboolean add_ap;
44c0da
         guint i;
44c0da
         guint j;
44c0da
         NMAccessPoint *ap;
44c0da
         NMAccessPoint *ap_tmp;
44c0da
+        NMAccessPoint *active_ap;
44c0da
+        NMActiveConnection *ac;
44c0da
+        NMConnection *ac_con = NULL;
44c0da
+        GBytes *ac_ssid = NULL;
44c0da
+
44c0da
+        aps = nm_device_wifi_get_access_points (NM_DEVICE_WIFI (nm_device));
44c0da
+        active_ap = nm_device_wifi_get_active_access_point (NM_DEVICE_WIFI (nm_device));
44c0da
+
44c0da
+        /* Use the connection SSID for the active AP as it is different with OWE. */
44c0da
+        ac = nm_device_get_active_connection (nm_device);
44c0da
+        if (ac)
44c0da
+                ac_con = NM_CONNECTION (nm_active_connection_get_connection (ac));
44c0da
+        if (ac_con) {
44c0da
+                NMSetting *setting;
44c0da
+
44c0da
+                setting = nm_connection_get_setting_by_name (ac_con, NM_SETTING_WIRELESS_SETTING_NAME);
44c0da
+                if (setting)
44c0da
+                        ac_ssid = nm_setting_wireless_get_ssid (NM_SETTING_WIRELESS (setting));
44c0da
+        }
44c0da
 
44c0da
         /* we will have multiple entries for typical hotspots, just
44c0da
          * filter to the one with the strongest signal */
44c0da
         aps_unique = g_ptr_array_new_with_free_func ((GDestroyNotify) g_object_unref);
44c0da
         if (aps != NULL)
44c0da
                 for (i = 0; i < aps->len; i++) {
44c0da
+                        GBytes *ssid = NULL;
44c0da
+
44c0da
                         ap = NM_ACCESS_POINT (g_ptr_array_index (aps, i));
44c0da
 
44c0da
+                        if (ap == active_ap)
44c0da
+                                ssid = ac_ssid;
44c0da
+                        if (!ssid)
44c0da
+                                ssid = nm_access_point_get_ssid (ap);
44c0da
+
44c0da
                         /* Hidden SSIDs don't get shown in the list */
44c0da
-                        ssid = nm_access_point_get_ssid (ap);
44c0da
                         if (!ssid)
44c0da
                                 continue;
44c0da
 
44c0da
@@ -189,8 +214,15 @@ panel_get_strongest_unique_aps (const GPtrArray *aps)
44c0da
 
44c0da
                         /* get already added list */
44c0da
                         for (j=0; j<aps_unique->len; j++) {
44c0da
+                                GBytes *ssid_tmp = NULL;
44c0da
+
44c0da
                                 ap_tmp = NM_ACCESS_POINT (g_ptr_array_index (aps_unique, j));
44c0da
-                                ssid_tmp = nm_access_point_get_ssid (ap_tmp);
44c0da
+
44c0da
+                                ssid_tmp = NULL;
44c0da
+                                if (ap_tmp == active_ap)
44c0da
+                                        ssid_tmp = ac_ssid;
44c0da
+                                if (!ssid_tmp)
44c0da
+                                        ssid_tmp = nm_access_point_get_ssid (ap_tmp);
44c0da
                                 g_assert (ssid_tmp);
44c0da
 
44c0da
                                 /* is this the same type and data? */
44c0da
@@ -202,9 +234,12 @@ panel_get_strongest_unique_aps (const GPtrArray *aps)
44c0da
                                                  nm_utils_escape_ssid (g_bytes_get_data (ssid_tmp, NULL),
44c0da
                                                                        g_bytes_get_size (ssid_tmp)));
44c0da
 
44c0da
-                                        /* the new access point is stronger */
44c0da
-                                        if (nm_access_point_get_strength (ap) >
44c0da
+                                        if (ap_tmp == active_ap) {
44c0da
+                                                add_ap = FALSE;
44c0da
+                                        } else if (ap == active_ap ||
44c0da
+                                            nm_access_point_get_strength (ap) >
44c0da
                                             nm_access_point_get_strength (ap_tmp)) {
44c0da
+                                                /* the new access point is the default or stronger */
44c0da
                                                 g_debug ("removing %s",
44c0da
                                                          nm_utils_escape_ssid (g_bytes_get_data (ssid_tmp, NULL),
44c0da
                                                                                g_bytes_get_size (ssid_tmp)));
44c0da
@@ -2042,9 +2077,10 @@ open_history (NetDeviceWifi *device_wifi)
44c0da
         GtkWidget *separator;
44c0da
         GSList *connections;
44c0da
         GSList *l;
44c0da
-        const GPtrArray *aps;
44c0da
         GPtrArray *aps_unique = NULL;
44c0da
         NMAccessPoint *active_ap;
44c0da
+        NMActiveConnection *ac;
44c0da
+        NMConnection *ac_con = NULL;
44c0da
         guint i;
44c0da
         NMDevice *nm_device;
44c0da
         GtkWidget *list;
44c0da
@@ -2119,10 +2155,15 @@ open_history (NetDeviceWifi *device_wifi)
44c0da
 
44c0da
         connections = net_device_get_valid_connections (NET_DEVICE (device_wifi));
44c0da
 
44c0da
-        aps = nm_device_wifi_get_access_points (NM_DEVICE_WIFI (nm_device));
44c0da
-        aps_unique = panel_get_strongest_unique_aps (aps);
44c0da
+        aps_unique = panel_get_strongest_unique_aps (nm_device);
44c0da
         active_ap = nm_device_wifi_get_active_access_point (NM_DEVICE_WIFI (nm_device));
44c0da
 
44c0da
+        ac = nm_device_get_active_connection (nm_device);
44c0da
+        if (ac)
44c0da
+                ac_con = NM_CONNECTION (nm_active_connection_get_connection (ac));
44c0da
+        if (ac_con && !g_slist_find (connections, ac_con))
44c0da
+                connections = g_slist_prepend (connections, ac_con);
44c0da
+
44c0da
         for (l = connections; l; l = l->next) {
44c0da
                 NMConnection *connection = l->data;
44c0da
                 NMAccessPoint *ap = NULL;
44c0da
@@ -2137,7 +2178,13 @@ open_history (NetDeviceWifi *device_wifi)
44c0da
                         GBytes *ssid_ap;
44c0da
                         ap = NM_ACCESS_POINT (g_ptr_array_index (aps_unique, i));
44c0da
                         ssid_ap = nm_access_point_get_ssid (ap);
44c0da
-                        if (nm_utils_same_ssid (g_bytes_get_data (ssid, NULL), g_bytes_get_size (ssid),
44c0da
+
44c0da
+                        /* Skip SSID check for active connection/AP (will not match with OWE) */
44c0da
+                        if (ap == active_ap && connection == ac_con)
44c0da
+                                break;
44c0da
+
44c0da
+                        if (ssid_ap &&
44c0da
+                            nm_utils_same_ssid (g_bytes_get_data (ssid, NULL), g_bytes_get_size (ssid),
44c0da
                                                 g_bytes_get_data (ssid_ap, NULL), g_bytes_get_size (ssid_ap),
44c0da
                                                 TRUE))
44c0da
                                 break;
44c0da
@@ -2167,13 +2214,14 @@ populate_ap_list_idle (NetDeviceWifi *device_wifi)
44c0da
         NMDevice *nm_device;
44c0da
         GSList *connections;
44c0da
         GSList *l;
44c0da
-        const GPtrArray *aps;
44c0da
         GPtrArray *aps_unique = NULL;
44c0da
         NMAccessPoint *active_ap;
44c0da
         guint i;
44c0da
         GtkWidget *row;
44c0da
         GtkWidget *button;
44c0da
         GList *children, *child;
44c0da
+        NMActiveConnection *ac;
44c0da
+        NMConnection *ac_con = NULL;
44c0da
 
44c0da
         device_wifi->priv->populate_ap_list_idle_id = 0;
44c0da
 
44c0da
@@ -2192,10 +2240,15 @@ populate_ap_list_idle (NetDeviceWifi *device_wifi)
44c0da
 
44c0da
         connections = net_device_get_valid_connections (NET_DEVICE (device_wifi));
44c0da
 
44c0da
-        aps = nm_device_wifi_get_access_points (NM_DEVICE_WIFI (nm_device));
44c0da
-        aps_unique = panel_get_strongest_unique_aps (aps);
44c0da
+        aps_unique = panel_get_strongest_unique_aps (nm_device);
44c0da
         active_ap = nm_device_wifi_get_active_access_point (NM_DEVICE_WIFI (nm_device));
44c0da
 
44c0da
+        ac = nm_device_get_active_connection (nm_device);
44c0da
+        if (ac)
44c0da
+                ac_con = NM_CONNECTION (nm_active_connection_get_connection (ac));
44c0da
+        if (ac_con && !g_slist_find (connections, ac_con))
44c0da
+                connections = g_slist_prepend (connections, ac_con);
44c0da
+
44c0da
         for (i = 0; i < aps_unique->len; i++) {
44c0da
                 GBytes *ssid_ap;
44c0da
                 NMAccessPoint *ap;
44c0da
@@ -2212,9 +2265,14 @@ populate_ap_list_idle (NetDeviceWifi *device_wifi)
44c0da
                                 continue;
44c0da
                         }
44c0da
 
44c0da
+                        /* Skip SSID check for active connection/AP (will not match with OWE) */
44c0da
+                        if (ap == active_ap && connection == ac_con)
44c0da
+                                break;
44c0da
+
44c0da
                         setting = nm_connection_get_setting_by_name (connection, NM_SETTING_WIRELESS_SETTING_NAME);
44c0da
                         ssid = nm_setting_wireless_get_ssid (NM_SETTING_WIRELESS (setting));
44c0da
-                        if (nm_utils_same_ssid (g_bytes_get_data (ssid, NULL), g_bytes_get_size (ssid),
44c0da
+                        if (ssid_ap &&
44c0da
+                            nm_utils_same_ssid (g_bytes_get_data (ssid, NULL), g_bytes_get_size (ssid),
44c0da
                                                 g_bytes_get_data (ssid_ap, NULL), g_bytes_get_size (ssid_ap),
44c0da
                                                 TRUE))
44c0da
                                 break;
44c0da
-- 
44c0da
2.34.1
44c0da