[PATCH] roaming: add driver->get_snr()

Holger Schurig hs4233
Mon Sep 14 23:41:55 PDT 2009


Allows wpa_supplicant to fetch the SNR from the WEXT driver.

Signed-off-by: Holger Schurig <hs4233 at mail.mn-solutions.de>


Index: hostap/src/drivers/driver.h
===================================================================
--- hostap.orig/src/drivers/driver.h	2009-09-14 09:11:15.000000000 +0200
+++ hostap/src/drivers/driver.h	2009-09-14 09:14:00.000000000 +0200
@@ -536,6 +536,14 @@ struct wpa_driver_ops {
 	int (*get_bssid)(void *priv, u8 *bssid);
 
 	/**
+	 * get_snr - Get the current SNR
+	 * @priv: private interface data
+	 *
+	 * Return -1 on failure
+	 */
+	int (*get_snr)(void *priv);
+
+	/**
 	 * get_ssid - Get the current SSID
 	 * @priv: private driver interface data
 	 * @ssid: buffer for SSID (at least 32 bytes)
Index: hostap/src/drivers/driver_wext.h
===================================================================
--- hostap.orig/src/drivers/driver_wext.h	2009-09-14 09:11:14.000000000 +0200
+++ hostap/src/drivers/driver_wext.h	2009-09-14 09:14:00.000000000 +0200
@@ -62,6 +62,9 @@ struct wpa_scan_results * wpa_driver_wex
 
 void wpa_driver_wext_scan_timeout(void *eloop_ctx, void *timeout_ctx);
 
+#ifdef CONFIG_ROAM
+int wpa_driver_wext_get_snr(void *priv);
+#endif /* CONFIG_ROAM */
 int wpa_driver_wext_alternative_ifindex(struct wpa_driver_wext_data *drv,
 					const char *ifname);
 
Index: hostap/src/drivers/driver_wext.c
===================================================================
--- hostap.orig/src/drivers/driver_wext.c	2009-09-14 09:11:14.000000000 +0200
+++ hostap/src/drivers/driver_wext.c	2009-09-14 12:27:23.000000000 +0200
@@ -147,6 +147,46 @@ int wpa_driver_wext_get_bssid(void *priv
 
 
 /**
+ * wpa_driver_wext_get_snr - Get SNR, SIOCGIWSTATS
+ * @priv: Pointer to private wext data from wpa_driver_wext_init()
+ * Returns: 0 on success, -1 on failure
+ */
+int wpa_driver_wext_get_snr(void *priv)
+{
+	struct wpa_driver_wext_data *drv = priv;
+	struct iwreq iwr;
+	struct iw_statistics iws;
+	int sig = 0;
+	int noi = 0;
+
+	os_memset(&iwr, 0, sizeof(iwr));
+	iwr.u.data.pointer = (char*)&iws;
+	iwr.u.data.length  = sizeof(iws);
+	iwr.u.data.flags = 1;
+	os_strlcpy(iwr.ifr_name, drv->ifname, IFNAMSIZ);
+
+	if (ioctl(drv->ioctl_sock, SIOCGIWSTATS, &iwr) < 0) {
+		perror("ioctl[SIOCGIWSTATS");
+		return -1;
+	}
+
+	sig = iws.qual.level;
+	noi = iws.qual.noise;
+	if (sig == 0)
+		return -1;
+	if (iws.qual.updated & IW_QUAL_DBM) {
+		sig -= 0x100;
+		if (noi)
+			noi -= 0x100;
+	}
+	if (noi == 0)
+		noi = -96;
+
+	return sig - noi;
+}
+
+
+/**
  * wpa_driver_wext_set_bssid - Set BSSID, SIOCSIWAP
  * @priv: Pointer to private wext data from wpa_driver_wext_init()
  * @bssid: BSSID
@@ -2387,6 +2427,7 @@ const struct wpa_driver_ops wpa_driver_w
 	.name = "wext",
 	.desc = "Linux wireless extensions (generic)",
 	.get_bssid = wpa_driver_wext_get_bssid,
+	.get_snr = wpa_driver_wext_get_snr,
 	.get_ssid = wpa_driver_wext_get_ssid,
 	.set_wpa = wpa_driver_wext_set_wpa,
 	.set_key = wpa_driver_wext_set_key,
Index: hostap/wpa_supplicant/driver_i.h
===================================================================
--- hostap.orig/wpa_supplicant/driver_i.h	2009-09-14 09:11:14.000000000 +0200
+++ hostap/wpa_supplicant/driver_i.h	2009-09-14 09:14:00.000000000 +0200
@@ -153,6 +153,16 @@ static inline int wpa_drv_get_ssid(struc
 	return -1;
 }
 
+#ifdef CONFIG_ROAM
+static inline int wpa_drv_get_snr(struct wpa_supplicant *wpa_s)
+{
+	if (wpa_s->driver->get_snr) {
+		return wpa_s->driver->get_snr(wpa_s->drv_priv);
+	}
+	return -1;
+}
+#endif /* CONFIG_ROAM */
+
 static inline int wpa_drv_set_key(struct wpa_supplicant *wpa_s, wpa_alg alg,
 				   const u8 *addr, int key_idx, int set_tx,
 				   const u8 *seq, size_t seq_len,

-- 
http://www.holgerschurig.de



More information about the Hostap mailing list