9011adb2d06123ad89774c8b92595572a53b2e48
[openwrt/svn-archive/archive.git] / package / wpa_supplicant / files / wpa_supplicant.sh
1 wpa_supplicant_setup_vif() {
2 local vif="$1"
3 local driver="$2"
4
5 # wpa_supplicant should use wext for mac80211 cards
6 [ "$driver" = "mac80211" ] && driver='wext'
7
8 case "$enc" in
9 PSK|psk|psk2|PSK2)
10 key_mgmt='WPA-PSK'
11 config_get_bool usepassphrase "$vif" passphrase 1
12 case "$enc" in
13 psk|PSK)
14 proto='WPA'
15 if [ "$usepassphrase" = "1" ]; then
16 passphrase="psk=\"${key}\""
17 else
18 passphrase="psk=${key}"
19 fi
20 ;;
21 psk2|PSK2)
22 proto='RSN'
23 if [ "$usepassphrase" = "1" ]; then
24 passphrase="psk=\"${key}\""
25 else
26 passphrase="psk=${key}"
27 fi
28 ;;
29 esac
30 ;;
31 WPA|wpa|WPA2|wpa2|8021x|8021X)
32 proto='WPA2'
33 key_mgmt='WPA-EAP'
34 config_get ca_cert "$vif" ca_cert
35 ca_cert="ca_cert=\"$ca_cert\""
36 case "$eap_type" in
37 tls|TLS)
38 pairwise='pairwise=CCMP'
39 group='group=CCMP'
40 config_get priv_key "$vif" priv_key
41 config_get priv_key_pwd "$vif" priv_key_pwd
42 priv_key="private_key=\"$priv_key\""
43 priv_key_pwd="private_key_passwd=\"$priv_key_pwd\""
44 ;;
45 peap|PEAP|ttls|TTLS)
46 config_get auth "$vif" auth
47 config_get identity "$vif" identity
48 config_get password "$vif" password
49 phase2="phase2=\"auth=${auth:-MSCHAPV2}\""
50 identity="identity=\"$identity\""
51 password="password=\"$password\""
52 ;;
53 esac
54 eap_type="eap_type=$(echo $eap_type | tr 'a-z' 'A-Z')"
55 ;;
56 esac
57 config_get ifname "$vif" ifname
58 config_get bridge "$vif" bridge
59 config_get ssid "$vif" ssid
60 cat > /var/run/wpa_supplicant-$ifname.conf <<EOF
61 network={
62 scan_ssid=1
63 ssid="$ssid"
64 key_mgmt=$key_mgmt
65 proto=$proto
66 $passphrase
67 $pairwise
68 $group
69 $eap_type
70 $ca_cert
71 $priv_key
72 $priv_key_pwd
73 $phase2
74 $identity
75 $password
76 }
77 EOF
78 [ -z "$proto" ] || wpa_supplicant ${bridge:+ -b $bridge} -B -P "/var/run/wifi-${ifname}.pid" -D ${driver:-wext} -i "$ifname" -c /var/run/wpa_supplicant-$ifname.conf
79 }