Root/package/hostapd/files/wpa_supplicant.sh

1wpa_supplicant_setup_vif() {
2    local vif="$1"
3    local driver="$2"
4    local key="$key"
5    local options="$3"
6
7    # wpa_supplicant should use wext for mac80211 cards
8    [ "$driver" = "mac80211" ] && driver='wext'
9
10    # make sure we have the encryption type and the psk
11    [ -n "$enc" ] || {
12        config_get enc "$vif" encryption
13    }
14    [ -n "$key" ] || {
15        config_get key "$vif" key
16    }
17
18    local net_cfg bridge
19    config_get bridge "$vif" bridge
20    [ -z "$bridge" ] && {
21        net_cfg="$(find_net_config "$vif")"
22        [ -z "$net_cfg" ] || bridge="$(bridge_interface "$net_cfg")"
23        config_set "$vif" bridge "$bridge"
24    }
25
26    case "$enc" in
27        *none*)
28            key_mgmt='NONE'
29        ;;
30        *wep*)
31            key_mgmt='NONE'
32            config_get key "$vif" key
33            key="${key:-1}"
34            case "$key" in
35                [1234])
36                    for idx in 1 2 3 4; do
37                        local zidx
38                        zidx=$(($idx - 1))
39                        config_get ckey "$vif" "key${idx}"
40                        [ -n "$ckey" ] && \
41                            append "wep_key${zidx}" "wep_key${zidx}=$(prepare_key_wep "$ckey")"
42                    done
43                    wep_tx_keyidx="wep_tx_keyidx=$((key - 1))"
44                ;;
45                *)
46                    wep_key0="wep_key0=$(prepare_key_wep "$key")"
47                    wep_tx_keyidx="wep_tx_keyidx=0"
48                ;;
49            esac
50        ;;
51        *psk*)
52            key_mgmt='WPA-PSK'
53            config_get_bool usepassphrase "$vif" passphrase 1
54            if [ "$usepassphrase" = "1" ]; then
55                passphrase="psk=\"${key}\""
56            else
57                passphrase="psk=${key}"
58            fi
59            case "$enc" in
60                *psk2*)
61                    proto='proto=RSN'
62                    config_get ieee80211w "$vif" ieee80211w
63                ;;
64                *psk*)
65                    proto='proto=WPA'
66                ;;
67            esac
68        ;;
69        *wpa*|*8021x*)
70            proto='proto=WPA2'
71            key_mgmt='WPA-EAP'
72            config_get ieee80211w "$vif" ieee80211w
73            config_get ca_cert "$vif" ca_cert
74            config_get eap_type "$vif" eap_type
75            ca_cert=${ca_cert:+"ca_cert=\"$ca_cert\""}
76            case "$eap_type" in
77                tls)
78                    pairwise='pairwise=CCMP'
79                    group='group=CCMP'
80                    config_get priv_key "$vif" priv_key
81                    config_get priv_key_pwd "$vif" priv_key_pwd
82                    priv_key="private_key=\"$priv_key\""
83                    priv_key_pwd="private_key_passwd=\"$priv_key_pwd\""
84                ;;
85                peap|ttls)
86                    config_get auth "$vif" auth
87                    config_get identity "$vif" identity
88                    config_get password "$vif" password
89                    phase2="phase2=\"auth=${auth:-MSCHAPV2}\""
90                    identity="identity=\"$identity\""
91                    password="password=\"$password\""
92                ;;
93            esac
94            eap_type="eap=$(echo $eap_type | tr 'a-z' 'A-Z')"
95        ;;
96    esac
97
98    case "$ieee80211w" in
99        [012])
100            ieee80211w="ieee80211w=$ieee80211w"
101        ;;
102    esac
103
104    config_get ifname "$vif" ifname
105    config_get bridge "$vif" bridge
106    config_get ssid "$vif" ssid
107    config_get bssid "$vif" bssid
108    bssid=${bssid:+"bssid=$bssid"}
109    rm -rf /var/run/wpa_supplicant-$ifname
110    cat > /var/run/wpa_supplicant-$ifname.conf <<EOF
111ctrl_interface=/var/run/wpa_supplicant-$ifname
112network={
113    scan_ssid=1
114    ssid="$ssid"
115    $bssid
116    key_mgmt=$key_mgmt
117    $proto
118    $ieee80211w
119    $passphrase
120    $pairwise
121    $group
122    $eap_type
123    $ca_cert
124    $priv_key
125    $priv_key_pwd
126    $phase2
127    $identity
128    $password
129    $wep_key0
130    $wep_key1
131    $wep_key2
132    $wep_key3
133    $wep_tx_keyidx
134}
135EOF
136    [ -z "$proto" -a "$key_mgmt" != "NONE" ] || \
137        wpa_supplicant ${bridge:+ -b $bridge} -B -P "/var/run/wifi-${ifname}.pid" -D ${driver:-wext} -i "$ifname" -c /var/run/wpa_supplicant-$ifname.conf $options
138}
139

Archive Download this file



interactive