summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDan Winship <danw@gnome.org>2014-02-06 12:24:43 +0100
committerDan Winship <danw@gnome.org>2014-02-17 15:30:04 -0500
commit12a2d64063e426419718de58f9d69309603a15a1 (patch)
tree96db5816ba10cfc93edd6ed270ca98d0d6ba6704
parent62beb7a5b34b167ffde52dc78e587b3fa2d423c8 (diff)
downloadNetworkManager-12a2d64063e426419718de58f9d69309603a15a1.tar.gz
tui: handle Wi-Fi networks with multiple APs correctly
-rw-r--r--tui/nmt-connect-connection-list.c62
1 files changed, 62 insertions, 0 deletions
diff --git a/tui/nmt-connect-connection-list.c b/tui/nmt-connect-connection-list.c
index 1103c76bb4..2c71242d72 100644
--- a/tui/nmt-connect-connection-list.c
+++ b/tui/nmt-connect-connection-list.c
@@ -208,6 +208,55 @@ add_connections_for_device (NmtConnectDevice *nmtdev,
}
}
+/* stolen from nm-applet */
+static char *
+hash_ap (NMAccessPoint *ap)
+{
+ unsigned char input[66];
+ const GByteArray *ssid;
+ NM80211Mode mode;
+ guint32 flags;
+ guint32 wpa_flags;
+ guint32 rsn_flags;
+
+ memset (&input[0], 0, sizeof (input));
+
+ ssid = nm_access_point_get_ssid (ap);
+ if (ssid)
+ memcpy (input, ssid->data, ssid->len);
+
+ mode = nm_access_point_get_mode (ap);
+ if (mode == NM_802_11_MODE_INFRA)
+ input[32] |= (1 << 0);
+ else if (mode == NM_802_11_MODE_ADHOC)
+ input[32] |= (1 << 1);
+ else
+ input[32] |= (1 << 2);
+
+ /* Separate out no encryption, WEP-only, and WPA-capable */
+ flags = nm_access_point_get_flags (ap);
+ wpa_flags = nm_access_point_get_wpa_flags (ap);
+ rsn_flags = nm_access_point_get_rsn_flags (ap);
+ if ( !(flags & NM_802_11_AP_FLAGS_PRIVACY)
+ && (wpa_flags == NM_802_11_AP_SEC_NONE)
+ && (rsn_flags == NM_802_11_AP_SEC_NONE))
+ input[32] |= (1 << 3);
+ else if ( (flags & NM_802_11_AP_FLAGS_PRIVACY)
+ && (wpa_flags == NM_802_11_AP_SEC_NONE)
+ && (rsn_flags == NM_802_11_AP_SEC_NONE))
+ input[32] |= (1 << 4);
+ else if ( !(flags & NM_802_11_AP_FLAGS_PRIVACY)
+ && (wpa_flags != NM_802_11_AP_SEC_NONE)
+ && (rsn_flags != NM_802_11_AP_SEC_NONE))
+ input[32] |= (1 << 5);
+ else
+ input[32] |= (1 << 6);
+
+ /* duplicate it */
+ memcpy (&input[33], &input[0], 32);
+ return g_compute_checksum_for_data (G_CHECKSUM_MD5, input, sizeof (input));
+}
+
static void
add_connections_for_aps (NmtConnectDevice *nmtdev,
GSList *connections)
@@ -216,6 +265,8 @@ add_connections_for_aps (NmtConnectDevice *nmtdev,
NMConnection *conn;
NMAccessPoint *ap;
const GPtrArray *aps;
+ GHashTable *seen_ssids;
+ char *ap_hash;
GSList *iter;
int i;
@@ -223,12 +274,21 @@ add_connections_for_aps (NmtConnectDevice *nmtdev,
if (!aps)
return;
+ seen_ssids = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, NULL);
+
for (i = 0; i < aps->len; i++) {
ap = aps->pdata[i];
if (!nm_access_point_get_ssid (ap))
continue;
+ ap_hash = hash_ap (ap);
+ if (g_hash_table_contains (seen_ssids, ap_hash)) {
+ g_free (ap_hash);
+ continue;
+ }
+ g_hash_table_add (seen_ssids, ap_hash);
+
nmtconn = g_slice_new0 (NmtConnectConnection);
nmtconn->device = nmtdev->device;
nmtconn->ap = g_object_ref (ap);
@@ -249,6 +309,8 @@ add_connections_for_aps (NmtConnectDevice *nmtdev,
nmtdev->conns = g_slist_prepend (nmtdev->conns, nmtconn);
}
+
+ g_hash_table_unref (seen_ssids);
}
static GSList *