carl9170: update to 0.9.9.1
[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 psk
10 [ -n "$key" ] || {
11 config_get key "$vif" key
12 }
13
14 case "$enc" in
15 *wep*)
16 key_mgmt='NONE'
17 config_get key "$vif" key
18 key="${key:-1}"
19 case "$key" in
20 [1234])
21 for idx in 1 2 3 4; do
22 local zidx
23 zidx=$(($idx - 1))
24 config_get ckey "$vif" "key${idx}"
25 [ -n "$ckey" ] && \
26 append "wep_key${zidx}" "wep_key${zidx}=$(prepare_key_wep "$ckey")"
27 done
28 wep_tx_keyidx="wep_tx_keyidx=$((key - 1))"
29 ;;
30 *)
31 wep_key0="wep_key0=$(prepare_key_wep "$key")"
32 wep_tx_keyidx="wep_tx_keyidx=0"
33 ;;
34 esac
35 ;;
36 *psk*)
37 key_mgmt='WPA-PSK'
38 config_get_bool usepassphrase "$vif" passphrase 1
39 case "$enc" in
40 *psk2*)
41 proto='proto=RSN'
42 if [ "$usepassphrase" = "1" ]; then
43 passphrase="psk=\"${key}\""
44 else
45 passphrase="psk=${key}"
46 fi
47 ;;
48 *psk*)
49 proto='proto=WPA'
50 if [ "$usepassphrase" = "1" ]; then
51 passphrase="psk=\"${key}\""
52 else
53 passphrase="psk=${key}"
54 fi
55 ;;
56 esac
57 ;;
58 *wpa*|*8021x*)
59 proto='proto=WPA2'
60 key_mgmt='WPA-EAP'
61 config_get ca_cert "$vif" ca_cert
62 ca_cert=${ca_cert:+"ca_cert=\"$ca_cert\""}
63 case "$eap_type" in
64 tls)
65 pairwise='pairwise=CCMP'
66 group='group=CCMP'
67 config_get priv_key "$vif" priv_key
68 config_get priv_key_pwd "$vif" priv_key_pwd
69 priv_key="private_key=\"$priv_key\""
70 priv_key_pwd="private_key_passwd=\"$priv_key_pwd\""
71 ;;
72 peap|ttls)
73 config_get auth "$vif" auth
74 config_get identity "$vif" identity
75 config_get password "$vif" password
76 phase2="phase2=\"auth=${auth:-MSCHAPV2}\""
77 identity="identity=\"$identity\""
78 password="password=\"$password\""
79 ;;
80 esac
81 eap_type="eap=$(echo $eap_type | tr 'a-z' 'A-Z')"
82 ;;
83 esac
84 config_get ifname "$vif" ifname
85 config_get bridge "$vif" bridge
86 config_get ssid "$vif" ssid
87 config_get bssid "$vif" bssid
88 bssid=${bssid:+"bssid=$bssid"}
89 rm -rf /var/run/wpa_supplicant-$ifname
90 cat > /var/run/wpa_supplicant-$ifname.conf <<EOF
91 ctrl_interface=/var/run/wpa_supplicant-$ifname
92 network={
93 scan_ssid=1
94 ssid="$ssid"
95 $bssid
96 key_mgmt=$key_mgmt
97 $proto
98 $passphrase
99 $pairwise
100 $group
101 $eap_type
102 $ca_cert
103 $priv_key
104 $priv_key_pwd
105 $phase2
106 $identity
107 $password
108 $wep_key0
109 $wep_key1
110 $wep_key2
111 $wep_key3
112 $wep_tx_keyidx
113 }
114 EOF
115 [ -z "$proto" -a "$key_mgmt" != "NONE" ] || \
116 wpa_supplicant ${bridge:+ -b $bridge} -B -P "/var/run/wifi-${ifname}.pid" -D ${driver:-wext} -i "$ifname" -c /var/run/wpa_supplicant-$ifname.conf
117 }
This page took 0.049806 seconds and 5 git commands to generate.