summaryrefslogtreecommitdiffstats
path: root/src/lib/connections/wireless
blob: 8a21fdf03bc5185eaf89564d33241da78a99880a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
# Wireless connection support for netctl

. "$SUBR_DIR/ip"
. "$SUBR_DIR/wpa"
. "$SUBR_DIR/rfkill"


wireless_up() {
    local config_file

    if ! is_interface "$Interface"; then
        report_error "Interface '$Interface' does not exist"
        return 1
    fi

    # Default settings
    : ${Security:=none}
    : ${WPADriver:=nl80211,wext}
    : ${TimeoutWPA:=15}

    if [[ $RFKill ]]; then
        rf_enable "$Interface" "$RFKill" || return 1
    fi

    # Kill any lingering WPA supplicants
    WPAConfigFile= wpa_stop "$Interface" &> /dev/null

    if [[ $Security == "wpa-config" ]]; then
        : ${WPAConfigFile:=/etc/wpa_supplicant.conf}
        config_file=$WPAConfigFile
    else
        config_file=$(wpa_make_config_file "$Interface")
        if [[ -z $config_file ]]; then
            report_error "Could not create a wpa config file for interface '$Interface'"
            return 1
        fi
        printf "%s\n" "network={" "$(wpa_make_config_block)" "}" >> "$config_file"
    fi

    # Start the WPA supplicant
    if ! wpa_start "$Interface" "$WPADriver" "$config_file"; then
        report_error "The WPA supplicant did not start for interface '$Interface'"
        bring_interface_down "$Interface"
        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.
    bring_interface_up "$Interface" || return 1

    if ! wpa_wait_until_state "$TimeoutWPA" "$Interface" "COMPLETED"; then
        report_error "WPA association/authentication failed for interface '$Interface'"
        report_debug "WPA state for interface '$Interface': $(wpa_get_state "$Interface")"
        wpa_stop "$Interface"
        bring_interface_down "$Interface"
        return 1
    fi

    if ! ip_set; then
        wpa_stop "$Interface"
        bring_interface_down "$Interface"
        return 1
    fi
}

wireless_down() {
    ip_unset
    if [[ $Security == "wpa-config" ]]; then
        : ${WPAConfigFile:=/etc/wpa_supplicant.conf}
    fi
    wpa_stop "$Interface"
    bring_interface_down "$Interface" || return 1
    if [[ $RFKill ]]; then
        rf_disable "$Interface" "$RFKill"
    fi
}


# vim: ft=sh ts=4 et sw=4: