[OLPC-devel] [PATCH] wireless/libertas: scan results WE fixes

Dan Williams dcbw at redhat.com
Sun Jun 25 18:08:11 EDT 2006


- Calculate quality for scanned access points using ipw-derived code
- Convert WPA/RSN IE reporting to IWEVGENIE
- Don't bail out from scan result if we can't talk to the hardware

Signed-off-by: Dan Williams <dcbw at redhat.com>

--- a/drivers/net/wireless/libertas/wlan_scan.c	2006-06-25 13:50:47.000000000 -0400
+++ b/drivers/net/wireless/libertas/wlan_scan.c	2006-06-25 18:03:51.000000000 -0400
@@ -35,6 +35,7 @@ Change Log:
 
 ************************************************************/
 
+#include <net/ieee80211.h>
 #include    "include.h"
 
 /********************************************************
@@ -1668,6 +1669,10 @@ int wlan_get_scan(struct net_device *dev
 	int i;
 	int j;
 	int rate;
+#define PERFECT_RSSI ((u8)50)
+#define WORST_RSSI   ((u8)0)
+#define RSSI_DIFF    ((u8)(PERFECT_RSSI - WORST_RSSI))
+	u8 rssi;
 
 	u8 buf[16 + 256 * 2];
 	u8 *ptr;
@@ -1753,8 +1758,19 @@ int wlan_get_scan(struct net_device *dev
 
 		/* Add quality statistics */
 		iwe.cmd = IWEVQUAL;
+		iwe.u.qual.updated = IW_QUAL_ALL_UPDATED;
 		iwe.u.qual.level = SCAN_RSSI(Adapter->ScanTable[i].Rssi);
-		iwe.u.qual.qual = 0;
+
+		rssi = iwe.u.qual.level - MRVDRV_NF_DEFAULT_SCAN_VALUE;
+		iwe.u.qual.qual =
+		    (100 * RSSI_DIFF * RSSI_DIFF - (PERFECT_RSSI - rssi) *
+		     (15 * (RSSI_DIFF) + 62 * (PERFECT_RSSI - rssi))) /
+		    (RSSI_DIFF * RSSI_DIFF);
+		if (iwe.u.qual.qual > 100)
+			iwe.u.qual.qual = 100;
+		else if (iwe.u.qual.qual < 1)
+			iwe.u.qual.qual = 0;
+
 		if (Adapter->NF[TYPE_BEACON][TYPE_NOAVG] == 0) {
 			iwe.u.qual.noise = MRVDRV_NF_DEFAULT_SCAN_VALUE;
 		} else {
@@ -1771,17 +1787,14 @@ int wlan_get_scan(struct net_device *dev
 						    HostCmd_OPTION_WAITFORRSP,
 						    0, NULL);
 
-			if (ret) {
-				LEAVE();
-				return ret;
+			if (!ret) {
+				iwe.u.qual.level =
+				    CAL_RSSI(Adapter->SNR[TYPE_RXPD][TYPE_AVG] /
+					     AVG_SCALE,
+					     Adapter->NF[TYPE_RXPD][TYPE_AVG] /
+					     AVG_SCALE);
 			}
-			iwe.u.qual.level =
-			    CAL_RSSI(Adapter->SNR[TYPE_RXPD][TYPE_AVG] /
-				     AVG_SCALE,
-				     Adapter->NF[TYPE_RXPD][TYPE_AVG] /
-				     AVG_SCALE);
 		}
-
 		iwe.len = IW_EV_QUAL_LEN;
 		current_ev =
 		    iwe_stream_add_event(current_ev, end_buf, &iwe, iwe.len);
@@ -1846,56 +1859,30 @@ int wlan_get_scan(struct net_device *dev
 		if (Adapter->ScanTable[i].wpa2_supplicant.Wpa_ie[0] == WPA2_IE) {
 			memset(&iwe, 0, sizeof(iwe));
 			memset(buf, 0, sizeof(buf));
-			ptr = buf;
-			ptr += sprintf(ptr, "rsn_ie=");
-
-			for (j = 0;
-			     j <
-			     Adapter->ScanTable[i].wpa2_supplicant.Wpa_ie_len;
-			     j++) {
-				ptr +=
-				    sprintf(ptr, "%02x", (Adapter->ScanTable[i]
-							  .wpa2_supplicant.
-							  Wpa_ie[j]));
-			}
-			iwe.u.data.length = strlen(buf);
-
-			PRINTM(INFO, "iwe.u.data.length %d\n",
-			       iwe.u.data.length);
-			PRINTM(INFO, "WPA2 BUF: %s \n", buf);
-
-			iwe.cmd = IWEVCUSTOM;
+			memcpy(buf, Adapter->ScanTable[i].
+						wpa2_supplicant.Wpa_ie,
+					Adapter->ScanTable[i].wpa2_supplicant.
+						Wpa_ie_len);
+			iwe.cmd = IWEVGENIE;
+			iwe.u.data.length = Adapter->ScanTable[i].
+					wpa2_supplicant.Wpa_ie_len;
 			iwe.len = IW_EV_POINT_LEN + iwe.u.data.length;
-			current_ev =
-			    iwe_stream_add_point(current_ev, end_buf, &iwe,
-						 buf);
+			current_ev = iwe_stream_add_point(current_ev, end_buf,
+					&iwe, buf);
 		}
 		if (Adapter->ScanTable[i].wpa_supplicant.Wpa_ie[0] == WPA_IE) {
 			memset(&iwe, 0, sizeof(iwe));
 			memset(buf, 0, sizeof(buf));
-			ptr = buf;
-			ptr += sprintf(ptr, "wpa_ie=");
-
-			for (j = 0;
-			     j <
-			     Adapter->ScanTable[i].wpa_supplicant.Wpa_ie_len;
-			     j++) {
-				ptr +=
-				    sprintf(ptr, "%02x",
-					    Adapter->ScanTable[i].
-					    wpa_supplicant.Wpa_ie[j]);
-			}
-			iwe.u.data.length = strlen(buf);
-
-			PRINTM(INFO, "iwe.u.data.length %d\n",
-			       iwe.u.data.length);
-			PRINTM(INFO, "WPA BUF: %s \n", buf);
-
-			iwe.cmd = IWEVCUSTOM;
+			memcpy(buf, Adapter->ScanTable[i].
+						wpa_supplicant.Wpa_ie,
+					Adapter->ScanTable[i].wpa_supplicant.
+						Wpa_ie_len);
+			iwe.cmd = IWEVGENIE;
+			iwe.u.data.length = Adapter->ScanTable[i].
+					wpa_supplicant.Wpa_ie_len;
 			iwe.len = IW_EV_POINT_LEN + iwe.u.data.length;
-			current_ev =
-			    iwe_stream_add_point(current_ev, end_buf, &iwe,
-						 buf);
+			current_ev = iwe_stream_add_point(current_ev, end_buf,
+					&iwe, buf);
 		}
 
 #if WIRELESS_EXT > 14





More information about the Devel mailing list