[pkg-wpa-devel] [PATCH] add event hysteresis

Jason Lunz lunz at falooley.org
Sun Sep 24 02:07:35 UTC 2006


I use wpa-roam and the wpasupplicant package's wpa_action script.
Sometimes, usually after a resume from suspend, the running wpa_cli gets
into an endless loop of DISCONNECT/CONNECT events.

As near as I can tell, the cause is the use of ifupdown and dhcp clients
in combination with quirks of the wireless driver implementation. (I use
bcm43xx). It goes like this:

1. a suspend/resume cycle occurs.
2. on resume, a DISCONNECT event is received by wpasupplicant as a
result of the driver suspending.
3. wpa_action handles the DISCONNECT, while at the same time, a CONNECT
happens, since the driver has immediately reassociated with the AP after
resume.
4. The CONNECT runs a dhcp client, which may involve manipulation of the
wireless interface.
5. something about the activities resulting from the DISCONNECT/CONNECT
events causes another DISCONNECT to occur.
6. goto 2.

step 5 is a little vague, I know, and it's the root cause of the
problem. I've reproduced it using both dhcp3-client and pump, and it
generally doesn't happen if no dhcp client is used. It may have multiple
causes, from what I can tell.

Adding a simple form of hysteresis prevents this. I simply ignore all
CONNECT and DISCONNECT events for a 4-second window after a CONNECT
event occurs.

Jason

---
 debian/functions.sh  |   24 ++++++++++++++++++++++++
 debian/wpa_action.sh |    3 +++
 2 files changed, 27 insertions(+)

Index: wpasupplicant-0.5.5/debian/functions.sh
===================================================================
--- wpasupplicant-0.5.5.orig/debian/functions.sh
+++ wpasupplicant-0.5.5/debian/functions.sh
@@ -28,6 +28,7 @@
 WPA_CLI_PIDFILE="/var/run/wpa_action.$IFACE.pid"
 WPA_CLI_LOCKFILE="/var/lock/wpa_action.$IFACE.lock"
 WPA_CLI_LOGFILE="/var/log/wpa_action.log"
+WPA_CLI_HYSTERESIS="/var/run/wpa_action.$IFACE.timestamp"
 
 # default ctrl_interface socket directory
 if [ -z "$WPA_CTRL_DIR" ]; then
@@ -682,6 +683,29 @@
 	fi
 }
 
+# with some wireless drivers (bcm43xx), the act of using tools like ifupdown or
+# dhcp clients in response to CONNECTED/DISCONNECTED events can provoke further
+# events, leading to endless loops.
+#
+# these functions avoid that by remembering recent event history and ignoring
+# further events that happen immediately after.
+wpa_hysteresis_event () {
+	touch "$WPA_CLI_HYSTERESIS"
+}
+
+wpa_hysteresis_check () {
+	ts=`mktemp`
+	window=4
+	touch -d "$window seconds ago" $ts
+	test "$WPA_CLI_HYSTERESIS" -nt $ts && too_soon=true
+	rm -f $ts
+	if [ "$too_soon" ]
+	then
+		echo "ignoring $WPA_ACTION within $window seconds"
+		exit 0
+	fi
+}
+
 #####################################################################
 ## wpa_action basic logging
 # Log actions to file, test to see if it is writeable first
Index: wpasupplicant-0.5.5/debian/wpa_action.sh
===================================================================
--- wpasupplicant-0.5.5.orig/debian/wpa_action.sh
+++ wpasupplicant-0.5.5/debian/wpa_action.sh
@@ -38,6 +38,7 @@
 case "$WPA_ACTION" in
 	"CONNECTED")
 		wpa_log_init
+		wpa_hysteresis_check
 		wpa_action_lock
 		wpa_log_action
 		wpa_log_environment
@@ -45,11 +46,13 @@
 			ifup
 		fi
 		wpa_cli status
+		wpa_hysteresis_event
 		wpa_action_unlock
 		;;
 
 	"DISCONNECTED")
 		wpa_log_init
+		wpa_hysteresis_check
 		wpa_action_lock
 		wpa_log_action
 		wpa_log_environment



More information about the Pkg-wpa-devel mailing list