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

Kel Modderman kelrin at tpg.com.au
Sun Sep 24 04:45:08 UTC 2006


On Sunday 24 September 2006 12:07, Jason Lunz wrote:
> 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.

Yes. My attempt to combat this behaviour was just dishonourably discharged 
with your other patch. Thanks for taking a look into this problem.

>
> 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.

Indeed. This behaviour is hard to diagnose reliably, I can relate to that.

>
> 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.

Ok, this approach may be more reliable, or it may also cause problems. For 
example, when ipw2200 craps itself and does a DISCONNECT/CONNECT out of the 
blue (maybe firmware restart, or whatever other crappiness it encounters), 
this would most likely cause the reconnection to be ignored, and roaming will 
stop dead in its tracks.

I always wanted to come up with a "action buffer" or "action queue" mechanism, 
whereby quick reconnect/disconnect events could be managed in a more 
intelligent manner than simply ignoring them for an arbitiary window of time. 
But well, my first attempt was lame, so I am very grateful for your idea and 
code. Will throw it in after some testing and thought.

Kel.


>
> 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
>
> _______________________________________________
> Pkg-wpa-devel mailing list
> Pkg-wpa-devel at lists.alioth.debian.org
> http://lists.alioth.debian.org/mailman/listinfo/pkg-wpa-devel



More information about the Pkg-wpa-devel mailing list