diff options
-rwxr-xr-x | autowifi/autowifi-netcfg | 28 | ||||
-rw-r--r-- | src/8021x | 36 | ||||
-rw-r--r-- | src/connections/wireless | 55 |
3 files changed, 54 insertions, 65 deletions
diff --git a/autowifi/autowifi-netcfg b/autowifi/autowifi-netcfg index df448dc..f2dc266 100755 --- a/autowifi/autowifi-netcfg +++ b/autowifi/autowifi-netcfg @@ -22,7 +22,7 @@ if [[ -n "$RFKILL" ]]; then # Enable radio if necessary set_rf_state "$interface" up || exit $? fi -WPA_CONF="$(make_wpa_config $interface)" +WPA_CONF="$(make_wpa_config_file $interface)" for profile in $(list_profiles); do echo $profile @@ -32,31 +32,7 @@ for profile in $(list_profiles); do [[ $CONNECTION != "wireless" ]] && exit 1 [[ $INTERFACE != $interface ]] && exit 1 - case $SECURITY in - wep) - if [[ ${KEY:0:2} == "s:" ]]; then # TODO: does wpa_supplicant handle this as expected? - config="ssid=\"$ESSID\" \nkey_mgmt=NONE \nwep_key0=\"${KEY:2}\" \nwep_tx_keyidx=0" - else - config="ssid=\"$ESSID\" \nkey_mgmt=NONE \nwep_key0=$KEY \nwep_tx_keyidx=0" - fi - ;; - none) - config="ssid=\"$ESSID\" \nkey_mgmt=NONE" - ;; - wpa) - if [[ "${#KEY}" -eq 64 ]]; then - config="ssid=\"$ESSID\" \npsk=$KEY" - else - config="ssid=\"$ESSID\" \npsk=\"$KEY\"" - fi - ;; - wpa-configsection) - config="$CONFIGSECTION" - ;; - *) - exit 1 - ;; - esac + config=$(make_wpa_config) echo -e "network={ \n$config \nid_str=\"$profile\" \n}" >> $WPA_CONF ) @@ -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 |