[3/3] Do something with trusted networks



And here is policy and behavioral changes for the daemon to do something
with trusted networks.

Two such changes:

First, given no better options and a disconnected state, NM will now try
to blindly connect to trusted networks, round robin.  The idea being
that if your card is shitty or the network is hidden, you might not see
the network.  Also, on boot, NM does not have the network MAC addresses
and won't see any hidden networks.

Second, trusted networks now persist in the scan list, even if NM does
not see them.  Like bookmarks or favorites.  This is useful if your card
is broken and cannot scan, if your card is broken and does not return
hidden networks, or if your network is hidden and you don't know all of
the MAC addresses.

What we do here is debatable.  This is one such solution.

	Robert Love

Index: src/NetworkManagerAPList.c
===================================================================
RCS file: /cvs/gnome/NetworkManager/src/NetworkManagerAPList.c,v
retrieving revision 1.51.2.2
diff -u -r1.51.2.2 NetworkManagerAPList.c
--- src/NetworkManagerAPList.c	20 Apr 2006 20:39:52 -0000	1.51.2.2
+++ src/NetworkManagerAPList.c	7 Jun 2006 17:18:47 -0000
@@ -422,6 +422,56 @@
 	return (found_ap);
 }
 
+/*
+ * nm_ap_list_merge_trusted
+ *
+ * Merges the user's trusted networks, if any, into the scan list.  We treat these networks
+ * as persistent, always in the scan and allowed list regardless of their presence in a scan.
+ */
+void nm_ap_list_merge_trusted (NMDevice80211Wireless *dev)
+{
+	NMAccessPointList *	allowed_list;
+	NMAccessPointList *	scan_list;
+	NMAPListIter *		iter;
+	NMData *			app_data;
+
+	app_data = nm_device_get_app_data (NM_DEVICE (dev));
+	allowed_list = app_data->allowed_ap_list;
+	scan_list = nm_device_802_11_wireless_ap_list_get (dev);
+
+	iter = nm_ap_list_iter_new (allowed_list);
+	if (iter)
+	{
+		NMAccessPoint *	allowed_ap;
+
+		while ((allowed_ap = nm_ap_list_iter_next (iter)))
+		{
+			if (nm_ap_get_trusted (allowed_ap))
+			{
+				NMAccessPoint *	ap;
+				GTimeVal			cur_time;
+
+				ap = nm_ap_new ();
+				nm_ap_set_essid (ap, nm_ap_get_essid (allowed_ap));
+				nm_ap_set_timestamp_via_timestamp (ap, nm_ap_get_timestamp (allowed_ap));
+				nm_ap_set_trusted (ap, TRUE);
+				nm_ap_set_security (ap, nm_ap_get_security (allowed_ap));
+
+				/*
+				 * Fake it as if we see the AP right now.  We process the scan results _after_ this, thus
+				 * if the AP is seen in a scan we will favor that AP when we merge.
+				 */
+				g_get_current_time (&cur_time);
+				nm_ap_set_last_seen (ap, &cur_time);
+				nm_ap_set_artificial (ap, TRUE);
+
+				nm_ap_list_merge_scanned_ap (dev, scan_list, ap);
+				nm_ap_unref (ap);
+			}
+		}
+		nm_ap_list_iter_free (iter);
+	}
+}
 
 /*
  * nm_ap_list_merge_scanned_ap
Index: src/NetworkManagerAPList.h
===================================================================
RCS file: /cvs/gnome/NetworkManager/src/NetworkManagerAPList.h,v
retrieving revision 1.15.2.1
diff -u -r1.15.2.1 NetworkManagerAPList.h
--- src/NetworkManagerAPList.h	20 Apr 2006 20:39:52 -0000	1.15.2.1
+++ src/NetworkManagerAPList.h	7 Jun 2006 17:18:47 -0000
@@ -51,6 +51,8 @@
 void				nm_ap_list_copy_essids_by_address	(NMData *app_data, NMDevice80211Wireless *dev, NMAccessPointList *dest, NMAccessPointList *source);
 void				nm_ap_list_copy_one_essid_by_address	(NMData *app_data, NMDevice80211Wireless *dev, NMAccessPoint *ap, NMAccessPointList *search_list);
 
+void				nm_ap_list_merge_trusted			(NMDevice80211Wireless *dev);
+
 gboolean			nm_ap_list_merge_scanned_ap		(NMDevice80211Wireless *dev, NMAccessPointList *list, NMAccessPoint *merge_ap);
 
 NMNetworkType		nm_ap_list_get_type				(NMAccessPointList *list);
Index: src/nm-device-802-11-wireless.c
===================================================================
RCS file: /cvs/gnome/NetworkManager/src/nm-device-802-11-wireless.c,v
retrieving revision 1.60.2.11
diff -u -r1.60.2.11 nm-device-802-11-wireless.c
--- src/nm-device-802-11-wireless.c	2 Jun 2006 20:00:49 -0000	1.60.2.11
+++ src/nm-device-802-11-wireless.c	7 Jun 2006 17:18:48 -0000
@@ -675,8 +675,10 @@
 	NMActRequest *		req = NULL;
 	NMAccessPoint *	trusted_best_ap = NULL;
 	NMAccessPoint *	untrusted_best_ap = NULL;
+	NMAccessPoint *	blind_best_ap = NULL;
 	GTimeVal			trusted_latest_timestamp = {0, 0};
 	GTimeVal		 	untrusted_latest_timestamp = {0, 0};
+	GTimeVal		 	blind_latest_timestamp = {0, 0};
 	NMData *			app_data;
 
 	g_return_val_if_fail (self != NULL, NULL);
@@ -762,27 +764,68 @@
 					}
 				}
 
-				g_slist_foreach (user_addrs, (GFunc)g_free, NULL);
+				g_slist_foreach (user_addrs, (GFunc) g_free, NULL);
 				g_slist_free (user_addrs);
 			}
 
-			if (!blacklisted && nm_ap_get_trusted (tmp_ap) && (curtime->tv_sec > trusted_latest_timestamp.tv_sec))
-			{
-				trusted_latest_timestamp = *nm_ap_get_timestamp (tmp_ap);
-				trusted_best_ap = scan_ap;
-				nm_ap_set_security (trusted_best_ap, nm_ap_get_security (tmp_ap));
-			}
-			else if (!blacklisted && !nm_ap_get_trusted (tmp_ap) && (curtime->tv_sec > untrusted_latest_timestamp.tv_sec))
+			/*
+			 * Is this a candidate for a "Best AP" ?
+			 *
+			 * We maintain three lists: trusted, untrusted, and blind.  We prefer any member from an earlier
+			 * list (e.g., any trusted over any brute).  Within any given list, we prefer the MRU network.
+			 *
+			 * The "trusted" list contains all non-artificial (that is, seen in a scan) networks that the user
+			 * has marked as trusted, are on the allowed list, are not on the invalid list, and are not
+			 * blacklisted.
+			 *
+			 * The "untrusted" list contains all non-artificial networks that the user has not marked as trusted,
+			 * are on the allowed list, are not on the invalid list, and are not blacklisted.
+			 *
+			 * The "blind" list contains trusted networks not seen in a scan; that is, all artificial networks
+			 * that the user has marked as trusted, are in the allowed list, are not on the invalid list, and
+			 * are not blacklisted.  Given no better option, we will try to blindly connect to such networks.
+			 * Note if a trusted network is seen in a scan, it will be in the trusted list, not this one.
+			 */
+			if (!blacklisted)
 			{
-				untrusted_latest_timestamp = *nm_ap_get_timestamp (tmp_ap);
-				untrusted_best_ap = scan_ap;
-				nm_ap_set_security (untrusted_best_ap, nm_ap_get_security (tmp_ap));
+				if (!nm_ap_get_artificial (tmp_ap))
+				{
+					if (nm_ap_get_trusted (tmp_ap) && (curtime->tv_sec > trusted_latest_timestamp.tv_sec))
+					{
+						trusted_latest_timestamp = *nm_ap_get_timestamp (tmp_ap);
+						trusted_best_ap = scan_ap;
+						nm_ap_set_security (trusted_best_ap, nm_ap_get_security (tmp_ap));
+					}
+					else if (!nm_ap_get_trusted (tmp_ap) && (curtime->tv_sec > untrusted_latest_timestamp.tv_sec))
+					{
+						untrusted_latest_timestamp = *nm_ap_get_timestamp (tmp_ap);
+						untrusted_best_ap = scan_ap;
+						nm_ap_set_security (untrusted_best_ap, nm_ap_get_security (tmp_ap));
+					}
+				}
+				else
+				{
+					if (nm_ap_get_trusted (tmp_ap) && (curtime->tv_sec > blind_latest_timestamp.tv_sec))
+					{
+						blind_latest_timestamp = *nm_ap_get_timestamp (tmp_ap);
+						blind_best_ap = scan_ap;
+						nm_ap_set_security (blind_best_ap, nm_ap_get_security (tmp_ap));
+					}
+				}
+
 			}
 		}
 	}
-	best_ap = trusted_best_ap ? trusted_best_ap : untrusted_best_ap;
 	nm_ap_list_iter_free (iter);
 
+	/* We favor trusted over untrusted over blind */
+	if (trusted_best_ap)
+		best_ap = trusted_best_ap;
+	else if (untrusted_best_ap)
+		best_ap = untrusted_best_ap;
+	else if (blind_best_ap)
+		best_ap = blind_best_ap;
+
 	if (best_ap)
 		nm_ap_ref (best_ap);
 
@@ -1733,7 +1776,6 @@
 	NMDevice80211Wireless *	self;
 	GTimeVal				cur_time;
 	NMAPListIter *			iter = NULL;
-	const char *			iface;
 	NMData *				app_data;
 	NMAccessPointList *		ap_list;
 
@@ -1746,12 +1788,17 @@
 		return FALSE;
 	}
 
-	iface = nm_device_get_iface (NM_DEVICE (self));
+	nm_ap_list_merge_trusted (self);
+
 	app_data = nm_device_get_app_data (NM_DEVICE (self));
 	if (cb_data->results_len > 0)
 	{
 		if (!process_scan_results (self, cb_data->results, cb_data->results_len))
+		{
+			const char *	iface;
+			iface = nm_device_get_iface (NM_DEVICE (self));
 			nm_warning ("process_scan_results() on device %s returned an error.", iface);
+		}
 
 		/* Once we have the list, copy in any relevant information from our Allowed list. */
 		nm_ap_list_copy_properties (nm_device_802_11_wireless_ap_list_get (self), app_data->allowed_ap_list);
@@ -2883,10 +2930,10 @@
 
 	if ((ap = nm_act_request_get_ap (req)))
 	{
-		if (nm_ap_get_artificial (ap))
+		if (nm_ap_get_artificial (ap) && !nm_ap_get_trusted (ap))
 		{
 			NMAccessPointList *	dev_list;
-		
+
 			/* Artificial APs are ones that don't show up in scans,
 			 * but which the user explicitly attempted to connect to.
 			 * However, if we fail on one of these, remove it from the


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]