Add generic wpa_supplicant calls and use them for mac80211 and madwifi.
[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|wpa2i|8021x|8021X)
32 proto='WPA2'
33 key_mgmt='WPA-EAP'
34 config_get ca_cert "$vif" ca_cert
35 case "$eap_type" in
36 tls|TLS)
37 pairwise='pairwise=CCMP'
38 group='group=CCMP'
39 config_get priv_key "$vif" priv_key
40 config_get priv_key_pwd "$vif" priv_key_pwd
41 priv_key="private_key=\"$priv_key\""
42 priv_key_pwd="private_key_passwd=\"$priv_key_pwd\""
43 ;;
44 peap|PEAP|ttls|TTLS)
45 config_get auth "$vif" auth
46 config_get identity "$vif" identity
47 config_get password "$vif" password
48 phase2="phase2=\"auth=${auth:-MSCHAPV2}\""
49 identity="identity=\"$identity\""
50 password="password=\"$password\""
51 ;;
52 esac
53 ;;
54 esac
55 config_get ifname "$vif" ifname
56 config_get bridge "$vif" bridge
57 config_get ssid "$vif" ssid
58 eap_type=$(echo $eap_type | tr 'a-z' 'A-Z')
59 cat > /var/run/wpa_supplicant-$ifname.conf <<EOF
60 network={
61 scan_ssid=1
62 ssid="$ssid"
63 key_mgmt=$key_mgmt
64 proto=$proto
65 $passphrase
66 $pairwise
67 $group
68 eap=$eap_type
69 ca_cert="$ca_cert"
70 $priv_key
71 $priv_key_pwd
72 $phase2
73 $identity
74 $password
75 }
76 EOF
77 [ -z "$proto" ] || wpa_supplicant ${bridge:+ -b $bridge} -B -D ${driver:-wext} -i "$ifname" -c /var/run/wpa_supplicant-$ifname.conf
78 }