diff options
author | makefu <github@syntax-fehler.de> | 2013-05-29 20:36:46 +0200 |
---|---|---|
committer | makefu <github@syntax-fehler.de> | 2013-05-29 20:36:46 +0200 |
commit | 3b3ad99602dbb7e03186c33c045774147b06da8b (patch) | |
tree | 3a9097839a4dc68d606f2fe97153b5e94f741e19 /usr/lib | |
parent | 91b2ec7821796c75bb3a56df951c6734d41a26bb (diff) |
add timeout for wpa_supplicant
Diffstat (limited to 'usr/lib')
-rw-r--r-- | usr/lib/autowifi/lib/wps | 50 |
1 files changed, 33 insertions, 17 deletions
diff --git a/usr/lib/autowifi/lib/wps b/usr/lib/autowifi/lib/wps index 8afd5b05..668bbbff 100644 --- a/usr/lib/autowifi/lib/wps +++ b/usr/lib/autowifi/lib/wps @@ -17,47 +17,63 @@ try_wps_pin(){ WPA_LOG=/tmp/wpa.log rm $WPA_LOG #mkfifo $WPA_LOG - killall wpa_supplicant && sleep 1 + killall wpa_supplicant 2>/dev/null && sleep 1 cat > $WPA_CONF <<EOF ctrl_interface=/var/run/wpa_supplicant ctrl_interface_group=0 update_config=1 EOF - wpa_supplicant -Dwext -iwlan0 -c $WPA_CONF -f $WPA_LOG & + wpa_supplicant -Dwext -iwlan0 -c $WPA_CONF -f $WPA_LOG 2>&1 & + WPA_PID=$! sleep 2 if !(sudo wpa_cli wps_reg $MAC $PIN | grep -q OK) ;then echo "wpa_cli wps_reg failed, bailing out!" return 1 fi - WPA_PID=$! - #*"WPA: Key negotiation completed"*) # association failed # exit 1 ;; + # TODO probably not posix compatible... + timeout(){ + ( timeout=10; + while [ $timeout -gt 0 ]; do + sleep 1; + kill -0 $$ 2> /dev/null || exit 0; + : $((timeout--)); + done ; + echo "TIMEOUT REACHED" ; + kill $$)& + exec $@ + } - if ( tail -f $WPA_LOG & echo "TAILPID: $!" )| while read line ; do + if ( timeout tail -f $WPA_LOG & echo "TAILPID: $!") | while read line ; do bye(){ + printf "%s:" "$2" >&2 + kill $WPA_PID kill -HUP $TAILPID exit $1 } - echo $line + # DEBUG + #echo $line >&2 case "$line" in TAILPID:*)IFS=" " set -- $line; TAILPID=$2;; - *"WPS-FAIL msg=10 config_error=18"*) bye 1 ;; # wrong pin - *"CTRL-EVENT-EAP-FAILURE EAP authentication failed"*) bye 1;; # rate limiting - *CTRL-EVENT-DISCONNECTED*):;; - *CTRL-EVENT-CONNECTED*) bye 0;; #yay connected - + *"WPS-FAIL msg=10 config_error=18"*) bye 1 "wrong pin";; + *"CTRL-EVENT-EAP-FAILURE EAP authentication failed"*) bye 1 "rate limiting";; + #*"Association request to the driver failed") bye 1 "wps not available";; + #*CTRL-EVENT-DISCONNECTED*):;; + *"CTRL-EVENT-DISCONNECTED bssid="*"reason=3 locally_generated=1"*)bye 1 "authentication failed, wps deactivated?";; + "TIMEOUT REACHED")bye 1 "timeout reached";; + *CTRL-EVENT-TERMINATING*) bye 1 "wpa_supplicant died";; + *CTRL-EVENT-CONNECTED*) bye 0 "yay connected";; esac done ; then - #echo "Connected!" - sed -n 's/[ \t]*psk="\(.*\)"$/\1/p' $WPA_CONF - return 0 + #echo "Connected!" + sed -n 's/[ \t]*psk="\(.*\)"$/\1/p' "$WPA_CONF" + return 0 else - echo "failed!" - return 1 + #echo "failed!" + return 1 fi - kill $WPA_PID } |