File wpa_supplicant-roaming.patch of Package wpa_supplicant

diff -ur BUILD/wpa_supplicant-0.6.9/src/drivers/driver.h BUILD2/wpa_supplicant-0.6.9/src/drivers/driver.h
--- BUILD/wpa_supplicant-0.6.9/src/drivers/driver.h	2009-03-23 15:06:28.000000000 +0100
+++ BUILD2/wpa_supplicant-0.6.9/src/drivers/driver.h	2009-05-04 14:26:47.000000000 +0200
@@ -963,6 +963,8 @@
 	 */
 	int (*set_mode)(void *priv, int mode);
 
+	int (*get_default_roaming)(void *priv);
+ 
 	/**
 	 * set_country - Set country
 	 * @priv: Private driver interface data
@@ -1147,7 +1149,13 @@
 	 * FT authentication sequence from the AP. The FT IEs are included in
 	 * the extra information in union wpa_event_data::ft_ies.
 	 */
-	EVENT_FT_RESPONSE
+	EVENT_FT_RESPONSE,
+
+	/**
+	 * EVENT_ROAMING_THRESHOLD - Roaming threshold exceeded
+	 */
+	EVENT_ROAMING_THRESHOLD
+
 } wpa_event_type;
 
 
diff -ur BUILD/wpa_supplicant-0.6.9/src/drivers/driver_wext.c BUILD2/wpa_supplicant-0.6.9/src/drivers/driver_wext.c
--- BUILD/wpa_supplicant-0.6.9/src/drivers/driver_wext.c	2009-05-04 14:32:17.000000000 +0200
+++ BUILD2/wpa_supplicant-0.6.9/src/drivers/driver_wext.c	2009-05-04 14:28:20.000000000 +0200
@@ -524,10 +524,18 @@
 				drv->assoc_req_ies = NULL;
 				os_free(drv->assoc_resp_ies);
 				drv->assoc_resp_ies = NULL;
+
+				/* stop monitoring the signal quality */
+				eloop_cancel_timeout(wpa_driver_wext_monitor_quality, drv, drv->ctx);
+	
 				wpa_supplicant_event(ctx, EVENT_DISASSOC,
 						     NULL);
 			
 			} else {
+				/* start monitoring the signal quality */
+				eloop_register_timeout(5, 0, wpa_driver_wext_monitor_quality, drv,
+			       drv->ctx);
+
 				wpa_driver_wext_event_assoc_ies(drv);
 				wpa_supplicant_event(ctx, EVENT_ASSOC, NULL);
 			}
@@ -891,6 +899,30 @@
 	return wpa_driver_wext_set_ifflags_ifname(drv, drv->ifname, flags);
 }
 
+void wpa_driver_wext_set_default_roaming(struct wpa_driver_wext_data *drv)
+{
+	/* ugly hack to enable roaming only for the iwlwifi driver */
+	char buf[256];
+	char line[256];
+	FILE* f;
+
+	/* the driver we want roaming enabled for */
+	char* driver = "DRIVER=iwlagn";
+
+	/* lookup this interface in sysfs */
+	snprintf(buf, sizeof(buf),"/sys/class/net/%s/device/uevent", drv->ifname);
+	if ( (f = fopen(buf, "r")) ) {
+		while (fgets(line, sizeof(line), f)) {
+			if (strstr (line, driver)) {
+				/* iwlwifi found -> enable roaming */
+				drv->default_roaming = 1;
+				break;
+			}
+		}
+		fclose(f);
+		f = NULL;
+	}
+}
 
 /**
  * wpa_driver_wext_init - Initialize WE driver interface
@@ -942,6 +974,9 @@
 
 	drv->mlme_sock = -1;
 
+	drv->default_roaming = 0;	
+	wpa_driver_wext_set_default_roaming(drv);
+
 	wpa_driver_wext_finish_drv_init(drv);
 
 	return drv;
@@ -1017,6 +1052,7 @@
 	int flags;
 
 	eloop_cancel_timeout(wpa_driver_wext_scan_timeout, drv, drv->ctx);
+	eloop_cancel_timeout(wpa_driver_wext_monitor_quality, drv, drv->ctx);
 
 	/*
 	 * Clear possibly configured driver parameters in order to make it
@@ -1058,6 +1094,69 @@
 	wpa_supplicant_event(timeout_ctx, EVENT_SCAN_RESULTS, NULL);
 }
 
+/**
+ * wpa_driver_wext_monitor_quality - Monitor the signal quality
+ * @eloop_ctx: Unused
+ * @timeout_ctx: ctx argument given to wpa_driver_wext_init()
+ */
+void wpa_driver_wext_monitor_quality(void *eloop_ctx, void *timeout_ctx)
+{
+	struct iwreq iwr;
+	struct iw_statistics stats;
+	struct wpa_driver_wext_data *drv = (struct wpa_driver_wext_data *) eloop_ctx;
+	int timeout_sec;
+
+	os_memset(&iwr, 0, sizeof(iwr));
+	os_memset(&stats, 0, sizeof(stats));
+
+	os_strlcpy(iwr.ifr_name, drv->ifname, IFNAMSIZ);
+
+	iwr.u.data.pointer = (caddr_t) &stats;
+	iwr.u.data.length = sizeof(stats);
+	iwr.u.data.flags = 1;
+
+	if (ioctl(drv->ioctl_sock, SIOCGIWSTATS, &iwr) < 0) {
+		perror("ioctl[SIOCGIWSTATS]");
+		return;
+	}
+
+	if (stats.qual.qual < (int) (0.4f * (float)drv->max_qual))
+	{
+		if (++drv->low_signal_count >= 3)
+		{
+			wpa_printf(MSG_DEBUG, "Signal quality low (%i/%i)", stats.qual.qual, drv->max_qual);
+			drv->low_signal_count = 0;
+			wpa_supplicant_event(drv->ctx, EVENT_ROAMING_THRESHOLD, NULL);
+			/* next measurement in 5 seconds */
+			eloop_register_timeout(5, 0, wpa_driver_wext_monitor_quality, drv, drv->ctx);
+		}
+		else
+		{
+			/* next measurment in 100ms */
+			eloop_register_timeout(0, 100000, wpa_driver_wext_monitor_quality, drv, drv->ctx);
+		}
+		return;
+	}
+	drv->low_signal_count = 0;
+
+	if (stats.qual.qual < (int) (0.6f * (float)drv->max_qual))
+		timeout_sec = 2;
+	else if (stats.qual.qual < (int) (0.8f * (float)drv->max_qual))
+		timeout_sec = 5;
+	else
+		timeout_sec = 10;
+
+	eloop_register_timeout(timeout_sec, 0, wpa_driver_wext_monitor_quality, drv, drv->ctx);
+}
+
+/**
+ * wpa_driver_get_default_roaming - Enable/Disable roaming per default
+ */
+int wpa_driver_get_default_roaming(void *priv)
+{
+	struct wpa_driver_wext_data *drv = priv;
+	return drv->default_roaming;
+}
 
 /**
  * wpa_driver_wext_scan - Request the driver to initiate scan
@@ -1610,6 +1709,7 @@
 		if (range->enc_capa & IW_ENC_CAPA_4WAY_HANDSHAKE)
 			drv->capa.flags |= WPA_DRIVER_FLAGS_4WAY_HANDSHAKE;
 
+		drv->max_qual = range->max_qual.qual;
 		wpa_printf(MSG_DEBUG, "  capabilities: key_mgmt 0x%x enc 0x%x "
 			   "flags 0x%x",
 			   drv->capa.key_mgmt, drv->capa.enc, drv->capa.flags);
@@ -2388,4 +2488,5 @@
 	.flush_pmkid = wpa_driver_wext_flush_pmkid,
 	.get_capa = wpa_driver_wext_get_capa,
 	.set_operstate = wpa_driver_wext_set_operstate,
+	.get_default_roaming = wpa_driver_get_default_roaming,
 };
diff -ur BUILD/wpa_supplicant-0.6.9/src/drivers/driver_wext.h BUILD2/wpa_supplicant-0.6.9/src/drivers/driver_wext.h
--- BUILD/wpa_supplicant-0.6.9/src/drivers/driver_wext.h	2009-03-23 15:06:28.000000000 +0100
+++ BUILD2/wpa_supplicant-0.6.9/src/drivers/driver_wext.h	2009-05-04 14:26:04.000000000 +0200
@@ -43,6 +43,9 @@
 	char mlmedev[IFNAMSIZ + 1];
 
 	int scan_complete_events;
+	int low_signal_count;
+	int max_qual;
+	int default_roaming;
 };
 
 int wpa_driver_wext_get_ifflags(struct wpa_driver_wext_data *drv, int *flags);
@@ -61,6 +64,7 @@
 struct wpa_scan_results * wpa_driver_wext_get_scan_results(void *priv);
 
 void wpa_driver_wext_scan_timeout(void *eloop_ctx, void *timeout_ctx);
+void wpa_driver_wext_monitor_quality(void *eloop_ctx, void *timeout_ctx);
 
 int wpa_driver_wext_alternative_ifindex(struct wpa_driver_wext_data *drv,
 					const char *ifname);
diff -ur BUILD/wpa_supplicant-0.6.9/wpa_supplicant/config.c BUILD2/wpa_supplicant-0.6.9/wpa_supplicant/config.c
--- BUILD/wpa_supplicant-0.6.9/wpa_supplicant/config.c	2009-03-23 15:06:28.000000000 +0100
+++ BUILD2/wpa_supplicant-0.6.9/wpa_supplicant/config.c	2009-05-04 14:26:04.000000000 +0200
@@ -1943,6 +1943,7 @@
 	config->eapol_version = DEFAULT_EAPOL_VERSION;
 	config->ap_scan = DEFAULT_AP_SCAN;
 	config->fast_reauth = DEFAULT_FAST_REAUTH;
+	config->roaming = DEFAULT_ROAMING;
 
 	if (ctrl_interface)
 		config->ctrl_interface = os_strdup(ctrl_interface);
diff -ur BUILD/wpa_supplicant-0.6.9/wpa_supplicant/config_file.c BUILD2/wpa_supplicant-0.6.9/wpa_supplicant/config_file.c
--- BUILD/wpa_supplicant-0.6.9/wpa_supplicant/config_file.c	2009-03-23 15:06:28.000000000 +0100
+++ BUILD2/wpa_supplicant-0.6.9/wpa_supplicant/config_file.c	2009-05-04 14:31:03.000000000 +0200
@@ -306,6 +306,12 @@
 	return 0;
 }
 
+static int wpa_config_process_roaming(struct wpa_config *config, char *pos)
+{
+	config->roaming = atoi(pos);
+	wpa_printf(MSG_DEBUG, "roaming=%d", config->roaming);
+	return 0;
+}
 
 static int wpa_config_parse_str(const struct global_parse_data *data,
 				struct wpa_config *config, int line,
@@ -457,6 +463,7 @@
 	{ STR(device_type) },
 	{ FUNC(os_version) },
 	{ INT_RANGE(wps_cred_processing, 0, 2) },
+	{ FUNC(roaming) },
 #endif /* CONFIG_WPS */
 	{ FUNC(country) }
 };
diff -ur BUILD/wpa_supplicant-0.6.9/wpa_supplicant/config.h BUILD2/wpa_supplicant-0.6.9/wpa_supplicant/config.h
--- BUILD/wpa_supplicant-0.6.9/wpa_supplicant/config.h	2009-03-23 15:06:28.000000000 +0100
+++ BUILD2/wpa_supplicant-0.6.9/wpa_supplicant/config.h	2009-05-04 14:26:04.000000000 +0200
@@ -22,6 +22,7 @@
 #define DEFAULT_AP_SCAN 1
 #endif /* CONFIG_NO_SCAN_PROCESSING */
 #define DEFAULT_FAST_REAUTH 1
+#define DEFAULT_ROAMING -1
 
 #include "config_ssid.h"
 
@@ -244,6 +245,11 @@
 	int update_config;
 
 	/**
+	 * roaming
+	 */
+	int roaming;
+
+	/**
 	 * blobs - Configuration blobs
 	 */
 	struct wpa_config_blob *blobs;
diff -ur BUILD/wpa_supplicant-0.6.9/wpa_supplicant/events.c BUILD2/wpa_supplicant-0.6.9/wpa_supplicant/events.c
--- BUILD/wpa_supplicant-0.6.9/wpa_supplicant/events.c	2009-03-23 15:06:28.000000000 +0100
+++ BUILD2/wpa_supplicant-0.6.9/wpa_supplicant/events.c	2009-05-04 14:26:04.000000000 +0200
@@ -706,6 +706,21 @@
 }
 #endif /* CONFIG_NO_SCAN_PROCESSING */
 
+static void wpa_supplicant_event_roaming_threshold(struct wpa_supplicant *wpa_s)
+{
+	struct os_time t1, t2;
+	os_get_time(&t1);
+	os_time_sub(&t1, &(wpa_s->last_roaming_attempt), &t2);
+	if (wpa_s->conf->roaming > 0
+	    || (wpa_s->conf->roaming == -1
+	        && wpa_s->driver->get_default_roaming
+	        && wpa_s->driver->get_default_roaming(wpa_s->drv_priv)))
+		/* limit the scan triggering to one every 20 seconds */
+		if (t2.sec > 20) {
+			wpa_supplicant_req_scan(wpa_s, 0, 0);
+			os_get_time(&(wpa_s->last_roaming_attempt));
+		}
+}
 
 static void wpa_supplicant_event_associnfo(struct wpa_supplicant *wpa_s,
 					   union wpa_event_data *data)
@@ -1114,6 +1129,9 @@
 		wpa_supplicant_event_ft_response(wpa_s, data);
 		break;
 #endif /* CONFIG_IEEE80211R */
+	case EVENT_ROAMING_THRESHOLD:
+		wpa_supplicant_event_roaming_threshold(wpa_s);
+		break;
 	default:
 		wpa_printf(MSG_INFO, "Unknown event %d", event);
 		break;
diff -ur BUILD/wpa_supplicant-0.6.9/wpa_supplicant/wpa_supplicant_i.h BUILD2/wpa_supplicant-0.6.9/wpa_supplicant/wpa_supplicant_i.h
--- BUILD/wpa_supplicant-0.6.9/wpa_supplicant/wpa_supplicant_i.h	2009-03-23 15:06:28.000000000 +0100
+++ BUILD2/wpa_supplicant-0.6.9/wpa_supplicant/wpa_supplicant_i.h	2009-05-04 14:32:01.000000000 +0200
@@ -350,6 +350,7 @@
 	struct wpa_client_mlme mlme;
 	int use_client_mlme;
 	int driver_4way_handshake;
+	struct os_time last_roaming_attempt;
 
 	int pending_mic_error_report;
 	int pending_mic_error_pairwise;
openSUSE Build Service is sponsored by