From b96b428d9ff44d3e007a2b81113390c734f2323d Mon Sep 17 00:00:00 2001 From: James Rayner Date: Sun, 21 Nov 2010 13:23:51 +1100 Subject: FS#20150 - 802.11x: correct state check, handle disconnect --- src/8021x | 5 +++-- src/connections/ethernet | 15 ++++++++++++++- 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/src/8021x b/src/8021x index f57ba7e..f510944 100644 --- a/src/8021x +++ b/src/8021x @@ -2,7 +2,8 @@ # wpa_check interface [timeout] wpa_check() { - local timeout=0 INTERFACE="$1" TIMEOUT="${2:-15}" + local timeout=0 INTERFACE="$1" TIMEOUT="${2:-15}" CONDITION="${3:-COMPLETED}" + # CONDITION is required as wired connections are ready at ASSOCIATED not COMPLETED FS#20150 while [[ $timeout -lt "$TIMEOUT" ]]; do ( # Sometimes wpa_supplicant isn't ready so silence errors for 2s only to avoid hiding real errors @@ -11,7 +12,7 @@ wpa_check() else eval $(wpa_cli -i "$INTERFACE" status | fgrep "wpa_state=") fi - [[ "$wpa_state" = "COMPLETED" ]] + [[ "$wpa_state" = "$CONDITION" ]] ) && return 0 sleep 1 let timeout++ diff --git a/src/connections/ethernet b/src/connections/ethernet index 36f6b93..cdb45ce 100644 --- a/src/connections/ethernet +++ b/src/connections/ethernet @@ -39,7 +39,7 @@ ethernet_up() { return 1 fi - if ! wpa_check "$INTERFACE"; then + if ! wpa_check "$INTERFACE" 15 "ASSOCIATED"; then bring_interface down "$INTERFACE" report_fail "WPA Authentication/Association Failed" return 1 @@ -53,6 +53,7 @@ ethernet_up() { report_debug ethernet_up dhclient -q -e TIMEOUT="${DHCP_TIMEOUT:-10}" -pf "/var/run/dhclient-$INTERFACE.pid" "$INTERFACE" if ! dhclient -q -e TIMEOUT="${DHCP_TIMEOUT:-10}" -pf "/var/run/dhclient-${INTERFACE}.pid" ${DHCLIENT_OPTIONS} "$INTERFACE"; then report_fail "DHCP IP lease attempt failed." + stop_80211x return 1 fi else @@ -65,6 +66,7 @@ ethernet_up() { dhcpcd -qL -t "${DHCP_TIMEOUT:-10}" $DHCP_OPTIONS "$INTERFACE" 2>&1 | report_debug "$(cat)" if [[ "$PIPESTATUS" -ne 0 ]]; then report_fail "DHCP IP lease attempt failed." + stop_80211x return 1 fi fi @@ -143,6 +145,8 @@ ethernet_down() { fi fi + stop_80211x + report_debug ethernet_down if_down if [[ "$CONNECTION" == "wireless" ]]; then bring_interface flush "$INTERFACE" @@ -159,6 +163,15 @@ ethernet_status() { fi } +# Stop wpa_supplicant if neccessary +stop_80211x() { + if checkyesno "${AUTH8021X:-no}"; then + . "$SUBR_DIR/8021x" + report_debug ethernet_down stop_wpa "$INTERFACE" + stop_wpa "$INTERFACE" + fi +} + ethernet_$1 "$2" exit $? # vim: set ts=4 et sw=4: -- cgit v1.2.3-24-g4f1b