File wpa_supplicant-fix_ap_ordering.patch of Package wpa_supplicant

diff -ur BUILD/wpa_supplicant-0.6.4/src/drivers/scan_helpers.c BUILD2/wpa_supplicant-0.6.4/src/drivers/scan_helpers.c
--- BUILD/wpa_supplicant-0.6.4/src/drivers/scan_helpers.c	2008-08-10 19:33:12.000000000 +0200
+++ BUILD2/wpa_supplicant-0.6.4/src/drivers/scan_helpers.c	2009-01-28 14:01:42.000000000 +0100
@@ -125,10 +125,13 @@
 		return -1;
 
 	/* best/max rate preferred if signal level close enough XXX */
-	maxrate_a = wpa_scan_get_max_rate(wa);
-	maxrate_b = wpa_scan_get_max_rate(wb);
-	if (maxrate_a != maxrate_b && abs(wb->level - wa->level) < 5)
-		return maxrate_b - maxrate_a;
+	if ( (wb->level != 0 && wa->level != 0 && abs(wb->level - wa->level) < 5) ||
+	     (abs(wb->qual - wa->qual) < 10) ) {
+		maxrate_a = wpa_scan_get_max_rate(wa);
+		maxrate_b = wpa_scan_get_max_rate(wb);
+		if (maxrate_a != maxrate_b)
+			return maxrate_b - maxrate_a;
+	}
 
 	/* use freq for channel preference */