summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRémy Oudompheng <remy@archlinux.org>2011-06-19 17:23:29 +0200
committerRémy Oudompheng <remy@archlinux.org>2011-06-19 18:49:26 +0200
commitae967f278e150f83f4d3e05eae789ee0f0cfc8f0 (patch)
tree41699fd8f7baff30766aede34dbb32f22d164443
parent13393d42c895b5f5b8853bafdb17c8b6d69e65bb (diff)
downloadnetctl-ae967f278e150f83f4d3e05eae789ee0f0cfc8f0.tar.gz
netctl-ae967f278e150f83f4d3e05eae789ee0f0cfc8f0.tar.xz
Switch to wpa_supplicant for scanning
Signed-off-by: Rémy Oudompheng <remy@archlinux.org>
-rw-r--r--src/8021x6
-rw-r--r--src/connections/wireless63
2 files changed, 43 insertions, 26 deletions
diff --git a/src/8021x b/src/8021x
index 0584040..a4a08ca 100644
--- a/src/8021x
+++ b/src/8021x
@@ -50,6 +50,12 @@ stop_wpa()
fi
}
+wpa_reconfigure() {
+ local INTERFACE=$1
+ $WPA_CLI -i "$INTERFACE" reconfigure
+ return $?
+}
+
wpa_find_essid() {
# usage: wpa_find_essid $INTERFACE $ESSID
# look for existence of a given essid. Assumes wpa_supplicant is
diff --git a/src/connections/wireless b/src/connections/wireless
index ff93cf3..29d7cb2 100644
--- a/src/connections/wireless
+++ b/src/connections/wireless
@@ -9,6 +9,14 @@ wireless_up() {
PROFILE="$1"
load_profile "$PROFILE"
+ # Default settings
+ SECURITY=${SECURITY:-none}
+ if [[ "$SECURITY" != "${SECURITY%-old}" ]]; then
+ report_warn "SECURITY=none-old, wep-old are deprecated, please use none, wep instead!"
+ SECURITY=${SECURITY%-old}
+ fi
+ WPA_DRIVER=${WPA_DRIVER:-nl80211,wext}
+
enable_rf $INTERFACE $RFKILL $RFKILL_NAME || return 1
# Check if interface exists
@@ -27,17 +35,31 @@ wireless_up() {
report_debug wireless_up ifup
bring_interface up "$INTERFACE" || return 1
+ # Start wpa_supplicant
+ if [ "$SECURITY" = "wpa-config" ]; then
+ WPA_CONF="${WPA_CONF:-/etc/wpa_supplicant.conf}"
+ else
+ WPA_CONF=$(make_wpa_config_file $INTERFACE)
+ fi
+ report_debug wireless_up start_wpa "$INTERFACE" "$WPA_CONF" "$WPA_DRIVER" "$WPA_OPTS"
+ if ! start_wpa "$INTERFACE" "$WPA_CONF" "$WPA_DRIVER" "$WPA_OPTS"; then
+ report_fail "wpa_supplicant did not start, possible configuration error"
+ return 1
+ fi
+
# Scan for network's existence first
if checkyesno "${SCAN:-no}"; then
report_debug wireless_up scanning
local OLDESSID="$ESSID"
if [[ -n "$AP" ]]; then
- ESSID=$(find_ap "$INTERFACE" "$AP")
+ ESSID=$(wpa_find_ap "$INTERFACE" "$AP")
else
- ESSID=$(find_essid "$INTERFACE" "$ESSID")
+ ESSID=$(wpa_find_essid "$INTERFACE" "$ESSID")
fi
if [[ $? -gt 0 ]]; then
report_fail "Wireless network \"$OLDESSID\" not present."
+ report_debug wireless_up stop_wpa "$INTERFACE"
+ stop_wpa "$INTERFACE"
return 1
fi
fi
@@ -48,40 +70,29 @@ wireless_up() {
iwconfig "$INTERFACE" $IWCONFIG
fi
- # Set to 'none' if not set
- [[ -z "$SECURITY" ]] && SECURITY="none"
-
- if [[ "$SECURITY" != "${SECURITY%-old}" ]]; then
- report_warn "SECURITY=none-old, wep-old are deprecated, please use none, wep instead!"
- SECURITY=${SECURITY%-old}
- fi
-
+ # Build configuration file
case "$SECURITY" in
wpa-config)
- [[ -z "$WPA_CONF" ]] && WPA_CONF="/etc/wpa_supplicant.conf" # defaults
;;
none|wep|wpa|wpa-configsection)
- WPA_CONF="$(make_wpa_config_file $INTERFACE)"
- echo -e "network={ \n$(make_wpa_config) \n}">> "$WPA_CONF"
+ echo -e "network={ \n$(make_wpa_config) \n}" >> "$WPA_CONF"
+ report_debug wireless_up "Configuration generated at $WPA_CONF"
+ report_debug wireless_up wpa_reconfigure "$INTERFACE"
+ if ! wpa_reconfigure "$INTERFACE"; then
+ report_fail "WPA configuration failed!"
+ stop_wpa "$INTERFACE"
+ return 1
+ fi
;;
*)
report_fail "Invalid SECURITY setting: $SECURITY"
;;
esac
- if [[ ${SECURITY:(-4)} != "-old" ]]; then
- report_debug wireless_up "Configuration generated at $WPA_CONF"
- [[ -z "$WPA_DRIVER" ]] && WPA_DRIVER="nl80211,wext"
- report_debug wireless_up start_wpa "$INTERFACE" "$WPA_CONF" "$WPA_DRIVER" "$WPA_OPTS"
- if ! start_wpa "$INTERFACE" "$WPA_CONF" "$WPA_DRIVER" "$WPA_OPTS"; then
- report_fail "wpa_supplicant did not start, possible configuration error"
- return 1
- fi
- report_debug wireless_up wpa_check
- if ! wpa_check "$INTERFACE" "$TIMEOUT"; then
- report_fail "WPA Authentication/Association Failed"
- return 1
- fi
+ report_debug wireless_up wpa_check
+ if ! wpa_check "$INTERFACE" "$TIMEOUT"; then
+ report_fail "WPA Authentication/Association Failed"
+ return 1
fi
if ! "$CONN_DIR/ethernet" up "$PROFILE"; then