firmware-utils/mkzynfw: add support for the NBG460N board
[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 ca_cert=${ca_cert:+"ca_cert=\"$ca_cert\""}
74 case "$eap_type" in
75 tls)
76 pairwise='pairwise=CCMP'
77 group='group=CCMP'
78 config_get priv_key "$vif" priv_key
79 config_get priv_key_pwd "$vif" priv_key_pwd
80 priv_key="private_key=\"$priv_key\""
81 priv_key_pwd="private_key_passwd=\"$priv_key_pwd\""
82 ;;
83 peap|ttls)
84 config_get auth "$vif" auth
85 config_get identity "$vif" identity
86 config_get password "$vif" password
87 phase2="phase2=\"auth=${auth:-MSCHAPV2}\""
88 identity="identity=\"$identity\""
89 password="password=\"$password\""
90 ;;
91 esac
92 eap_type="eap=$(echo $eap_type | tr 'a-z' 'A-Z')"
93 ;;
94 esac
95
96 case "$ieee80211w" in
97 [012])
98 ieee80211w="ieee80211w=$ieee80211w"
99 ;;
100 esac
101
102 config_get ifname "$vif" ifname
103 config_get bridge "$vif" bridge
104 config_get ssid "$vif" ssid
105 config_get bssid "$vif" bssid
106 bssid=${bssid:+"bssid=$bssid"}
107 rm -rf /var/run/wpa_supplicant-$ifname
108 cat > /var/run/wpa_supplicant-$ifname.conf <<EOF
109 ctrl_interface=/var/run/wpa_supplicant-$ifname
110 network={
111 scan_ssid=1
112 ssid="$ssid"
113 $bssid
114 key_mgmt=$key_mgmt
115 $proto
116 $ieee80211w
117 $passphrase
118 $pairwise
119 $group
120 $eap_type
121 $ca_cert
122 $priv_key
123 $priv_key_pwd
124 $phase2
125 $identity
126 $password
127 $wep_key0
128 $wep_key1
129 $wep_key2
130 $wep_key3
131 $wep_tx_keyidx
132 }
133 EOF
134 [ -z "$proto" -a "$key_mgmt" != "NONE" ] || \
135 wpa_supplicant ${bridge:+ -b $bridge} -B -P "/var/run/wifi-${ifname}.pid" -D ${driver:-wext} -i "$ifname" -c /var/run/wpa_supplicant-$ifname.conf
136 }
This page took 0.049692 seconds and 5 git commands to generate.