diff options
Diffstat (limited to 'src/connections/wireless')
-rw-r--r-- | src/connections/wireless | 133 |
1 files changed, 49 insertions, 84 deletions
diff --git a/src/connections/wireless b/src/connections/wireless index d93a672..7bb35ea 100644 --- a/src/connections/wireless +++ b/src/connections/wireless @@ -1,53 +1,21 @@ #! /bin/bash . /usr/lib/network/network . $SUBR_DIR/8021x -. $SUBR_DIR/wireless - - -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-old" ]]; then - if [[ -n "$AP" ]]; then - WEP_OPTS="ap \"$AP\" key $KEY" - else - WEP_OPTS="essid \"$ESSID\" key $KEY" - fi - elif [[ "$SECURITY" = "none-old" ]]; then - if [[ -n "$AP" ]]; then - WEP_OPTS="ap \"$AP\"" - else - WEP_OPTS="essid \"$ESSID\"" - fi - fi - fi - - quirk "predown" && bring_interface down "$INTERFACE" # madwifi FS#10585 - - report_debug wireless_up iwconfig "$INTERFACE" $WEP_OPTS - - if ! iwconfig "$INTERFACE" $WEP_OPTS; then - report_fail "Could not set wireless configuration." - return 1 - fi - - quirk "predown" && bring_interface up "$INTERFACE" # madwifi FS#10585 - - report_debug ethernet_up wep_check - if ! wep_check "$INTERFACE" "$TIMEOUT"; then - report_fail "WEP Association Failed" - return 1 - fi -} +. $SUBR_DIR/rfkill 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 @@ -57,69 +25,71 @@ wireless_up() { report_debug wireless_up stop_wpa "$INTERFACE" stop_wpa "$INTERFACE" - # Most drivers (mac80211) need mode set before device is brought up - if [[ $(iwgetid -sm "$INTERFACE") -ne Managed ]]; then - report_debug wireless_up iwconfig "$INTERFACE" mode managed - iwconfig "$INTERFACE" mode managed + # 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 - - report_debug wireless_up ifup - bring_interface up "$INTERFACE" || return 1 # 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 - # Manually set iwconfig options + # Manually set iwconfig options (DEPRECATED) if [[ -n "$IWCONFIG" ]]; then + report_warn "The use of IWCONFIG option is deprecated." report_debug wireless_up iwconfig "$INTERFACE" $IWCONFIG iwconfig "$INTERFACE" $IWCONFIG fi - # Set to 'none' if not set - [[ -z "$SECURITY" ]] && SECURITY="none" - + # Build configuration file case "$SECURITY" in - *-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" + 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 + # Bring interface up after starting wpa_supplicant + # This is important since cards such as iwl3945 do not support + # mode switching when they are already up. + report_debug wireless_up ifup + bring_interface up "$INTERFACE" || return 1 + + 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 @@ -135,14 +105,9 @@ wireless_down() { "$CONN_DIR/ethernet" down "$PROFILE" - if [[ ${SECURITY:(-4)} == "-old" ]]; then - report_debug wireless_down iwconfig "$INTERFACE" essid off key off - iwconfig "$INTERFACE" essid off key off &> /dev/null - else - report_debug wireless_down stop_wpa "$INTERFACE" - stop_wpa "$INTERFACE" - rm -rf "${TMPDIR:-/tmp}/wpa.$INTERFACE" - fi + report_debug wireless_down stop_wpa "$INTERFACE" + stop_wpa "$INTERFACE" + rm -rf "$STATE_DIR/wpa.$INTERFACE" bring_interface down "$INTERFACE" @@ -157,7 +122,7 @@ wireless_down() { # Returns status of profile - is it still functional? wireless_status() { load_profile "$1" - if [[ "$(iwgetid -r)" -ne "$ESSID" ]]; then + if ! wpa_check_current_essid "$INTERFACE" "$ESSID"; then return 1 elif ! ip link show dev "$INTERFACE" | fgrep -q "state UP"; then return 1 @@ -168,5 +133,5 @@ wireless_status() { wireless_$1 "$2" "$3" exit $? -# vim: ft=sh ts=4 et sw=4: +# vim: ft=sh ts=4 et sw=4 tw=0: |