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