diff options
author | James Rayner <james@archlinux.org> | 2009-09-27 14:39:37 +0200 |
---|---|---|
committer | James Rayner <james@archlinux.org> | 2009-09-27 14:39:37 +0200 |
commit | 818dacfa7f435e42fe1c81ae002a8df01ea80677 (patch) | |
tree | a5c6c16d6605cb981d93fd6ecc90852d78f8cb84 /src | |
parent | dce7afd6a8d4bcd6adb7f1d1b330c21fcb8c9957 (diff) | |
download | netctl-818dacfa7f435e42fe1c81ae002a8df01ea80677.tar.gz netctl-818dacfa7f435e42fe1c81ae002a8df01ea80677.tar.xz |
Remove wpa generation duplication, fix wep/none-old
Diffstat (limited to 'src')
-rw-r--r-- | src/8021x | 36 | ||||
-rw-r--r-- | src/connections/wireless | 55 |
2 files changed, 52 insertions, 39 deletions
@@ -47,9 +47,10 @@ stop_wpa() fi } -# $1 is interface -make_wpa_config() { - local WPA_CONF="${TMPDIR:-/tmp}/wpa.${INTERFACE}" # substitute spaces out +# Requires already loaded profile +make_wpa_config_file() { + local interface=$1 + local WPA_CONF="${TMPDIR:-/tmp}/wpa.${interface}" # substitute spaces out # make empty tmp dir with correct permissions, rename it rm -rf "$WPA_CONF" @@ -60,5 +61,34 @@ make_wpa_config() { echo "$WPA_CONF/wpa.conf" } +# Requires already loaded profile +make_wpa_config() { + case $SECURITY in + wep) + if [[ ${KEY:0:2} == "s:" ]]; then # TODO: does wpa_supplicant handle this as expected? + echo "ssid=\"$ESSID\" \nkey_mgmt=NONE \nwep_key0=\"${KEY:2}\" \nwep_tx_keyidx=0" + else + echo "ssid=\"$ESSID\" \nkey_mgmt=NONE \nwep_key0=$KEY \nwep_tx_keyidx=0" + fi + ;; + none) + echo "ssid=\"$ESSID\" \nkey_mgmt=NONE" + ;; + wpa) + if [[ "${#KEY}" -eq 64 ]]; then + echo "ssid=\"$ESSID\" \npsk=$KEY" + else + echo "ssid=\"$ESSID\" \npsk=\"$KEY\"" + fi + ;; + wpa-configsection) + echo "$CONFIGSECTION" + ;; + *) + return 1 + ;; + esac +} + # vim: ft=sh ts=4 et sw=4: diff --git a/src/connections/wireless b/src/connections/wireless index 6de7379..6c51068 100644 --- a/src/connections/wireless +++ b/src/connections/wireless @@ -27,15 +27,15 @@ iwconfig_up() { quirk prescan && iwlist "$INTERFACE" scan &> /dev/null # bcm43xx # 'none' uses iwconfig like wep. Use sane default if WEP_OPTS="" - if [[ -z "$WEP_OPTS" ]]; then - if [[ "$SECURITY" = "wep" ]]; then + if [[ -z $WEP_OPTS ]]; then + if [[ "$SECURITY" = "wep-old" ]]; then if [[ -n "$AP" ]]; then WEP_OPTS="ap \"$AP\" key $KEY" else WEP_OPTS="essid \"$ESSID\" key $KEY" fi - elif [[ "$SECURITY" = "none" ]]; then - if [[ -n "$AP" ]]; then + elif [[ "$SECURITY" = "none-old" ]]; then + if [[ -n $AP ]]; then WEP_OPTS="ap \"$AP\"" else WEP_OPTS="essid \"$ESSID\"" @@ -47,7 +47,7 @@ iwconfig_up() { report_debug wireless_up iwconfig "$INTERFACE" $WEP_OPTS - if ! iwconfig "$INTERFACE" "$WEP_OPTS"; then + if ! iwconfig "$INTERFACE" $WEP_OPTS; then report_fail "Could not set wireless configuration." return 1 fi @@ -109,37 +109,20 @@ wireless_up() { [[ -z "$SECURITY" ]] && SECURITY="none" case "$SECURITY" in - *-old) - report_debug "Using older iwconfig based path" - iwconfig_up || return 1 - ;; - wep) - WPA_CONF="$(make_wpa_config $INTERFACE)" - if [[ ${KEY:0:2} == "s:" ]]; then # TODO: does wpa_supplicant handle this as expected? - echo -e "network={ \nssid=\"$ESSID\" \nkey_mgmt=NONE \nwep_key0=\"${KEY:2}\" \nwep_tx_keyidx=0 \n}" >> "$WPA_CONF" - else - echo -e "network={ \nssid=\"$ESSID\" \nkey_mgmt=NONE \nwep_key0=$KEY \nwep_tx_keyidx=0 \n}" >> "$WPA_CONF" - fi - ;; - none) - WPA_CONF="$(make_wpa_config $INTERFACE)" - echo -e "network={ \nssid=\"$ESSID\" \nkey_mgmt=NONE \n}" >> "$WPA_CONF" - ;; - wpa) - WPA_CONF="$(make_wpa_config $INTERFACE)" - if [[ "${#KEY}" -eq 64 ]]; then - echo -e "network={ \nssid=\"$ESSID\" \npsk=$KEY \n}" >> "$WPA_CONF" - else - echo -e "network={ \nssid=\"$ESSID\" \npsk=\"$KEY\"\n}" >> "$WPA_CONF" - fi - ;; - wpa-config) - [[ -z "$WPA_CONF" ]] && WPA_CONF="/etc/wpa_supplicant.conf" # defaults - ;; - wpa-configsection) - WPA_CONF="$(make_wpa_config $INTERFACE)" - echo -e "network={ \n$CONFIGSECTION \n}">> "$WPA_CONF" - ;; + *-old) + report_debug "Using older iwconfig based path" + iwconfig_up || return 1 + ;; + 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" + ;; + *) + report_fail "Invalid SECURITY setting: $SECURITY" + ;; esac if [[ ${SECURITY:(-4)} != "-old" ]]; then |