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

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