mac80211/hostapd: add support for HT capa in case of IBSS/RSN
[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         local options="$3"
6         local freq=""
7         local ht="$5"
8         local ap_scan=""
9         local scan_ssid="1"
10         [ -n "$4" ] && freq="frequency=$4"
11
12         # make sure we have the encryption type and the psk
13         [ -n "$enc" ] || {
14                 config_get enc "$vif" encryption
15         }
16         [ -n "$key" ] || {
17                 config_get key "$vif" key
18         }
19
20         local net_cfg bridge
21         config_get bridge "$vif" bridge
22         [ -z "$bridge" ] && {
23                 net_cfg="$(find_net_config "$vif")"
24                 [ -z "$net_cfg" ] || bridge="$(bridge_interface "$net_cfg")"
25                 config_set "$vif" bridge "$bridge"
26         }
27
28         local mode ifname wds modestr=""
29         config_get mode "$vif" mode
30         config_get ifname "$vif" ifname
31         config_get_bool wds "$vif" wds 0
32         [ -z "$bridge" ] || [ "$mode" = ap ] || [ "$mode" = sta -a $wds -eq 1 ] || {
33                 echo "wpa_supplicant_setup_vif($ifname): Refusing to bridge $mode mode interface"
34                 return 1
35         }
36         [ "$mode" = "adhoc" ] && {
37                 modestr="mode=1"
38                 scan_ssid="0"
39                 ap_scan="ap_scan=2"
40         }
41
42         key_mgmt='NONE'
43         case "$enc" in
44                 *none*) ;;
45                 *wep*)
46                         config_get key "$vif" key
47                         key="${key:-1}"
48                         case "$key" in
49                                 [1234])
50                                         for idx in 1 2 3 4; do
51                                                 local zidx
52                                                 zidx=$(($idx - 1))
53                                                 config_get ckey "$vif" "key${idx}"
54                                                 [ -n "$ckey" ] && \
55                                                         append "wep_key${zidx}" "wep_key${zidx}=$(prepare_key_wep "$ckey")"
56                                         done
57                                         wep_tx_keyidx="wep_tx_keyidx=$((key - 1))"
58                                 ;;
59                                 *)
60                                         wep_key0="wep_key0=$(prepare_key_wep "$key")"
61                                         wep_tx_keyidx="wep_tx_keyidx=0"
62                                 ;;
63                         esac
64                 ;;
65                 *psk*)
66                         key_mgmt='WPA-PSK'
67                         # if you want to use PSK with a non-nl80211 driver you
68                         # have to use WPA-NONE and wext driver for wpa_s
69                         [ "$mode" = "adhoc" -a "$driver" != "nl80211" ] && {
70                                 key_mgmt='WPA-NONE'
71                                 driver='wext'
72                         }
73                         if [ ${#key} -eq 64 ]; then
74                                 passphrase="psk=${key}"
75                         else
76                                 passphrase="psk=\"${key}\""
77                         fi
78                         case "$enc" in
79                                 *psk2*)
80                                         proto='proto=RSN'
81                                         config_get ieee80211w "$vif" ieee80211w
82                                 ;;
83                                 *psk*)
84                                         proto='proto=WPA'
85                                 ;;
86                         esac
87                 ;;
88                 *wpa*|*8021x*)
89                         proto='proto=WPA2'
90                         key_mgmt='WPA-EAP'
91                         config_get ieee80211w "$vif" ieee80211w
92                         config_get ca_cert "$vif" ca_cert
93                         config_get eap_type "$vif" eap_type
94                         ca_cert=${ca_cert:+"ca_cert=\"$ca_cert\""}
95                         case "$eap_type" in
96                                 tls)
97                                         pairwise='pairwise=CCMP'
98                                         group='group=CCMP'
99                                         config_get identity "$vif" identity
100                                         config_get client_cert "$vif" client_cert
101                                         config_get priv_key "$vif" priv_key
102                                         config_get priv_key_pwd "$vif" priv_key_pwd
103                                         identity="identity=\"$identity\""
104                                         client_cert="client_cert=\"$client_cert\""
105                                         priv_key="private_key=\"$priv_key\""
106                                         priv_key_pwd="private_key_passwd=\"$priv_key_pwd\""
107                                 ;;
108                                 peap|ttls)
109                                         config_get auth "$vif" auth
110                                         config_get identity "$vif" identity
111                                         config_get password "$vif" password
112                                         phase2="phase2=\"auth=${auth:-MSCHAPV2}\""
113                                         identity="identity=\"$identity\""
114                                         password="password=\"$password\""
115                                 ;;
116                         esac
117                         eap_type="eap=$(echo $eap_type | tr 'a-z' 'A-Z')"
118                 ;;
119         esac
120
121         case "$ieee80211w" in
122                 [012])
123                         ieee80211w="ieee80211w=$ieee80211w"
124                 ;;
125         esac
126
127         local fixed_freq bssid1 beacon_interval brates mrate
128         config_get ifname "$vif" ifname
129         config_get bridge "$vif" bridge
130         bssid1=${bssid:+"bssid=$bssid"}
131         beacon_interval=${beacon_int:+"beacon_interval=$beacon_int"}
132
133         local br brval brsub brstr
134         [ -n "$basic_rate_list" ] && {
135                 for br in $basic_rate_list; do
136                         brval="$(($br / 1000))"
137                         brsub="$((($br / 100) % 10))"
138                         [ "$brsub" -gt 0 ] && brval="$brval.$brsub"
139                         [ -n "$brstr" ] && brstr="$brstr,"
140                         brstr="$brstr$brval"
141                 done
142                 brates=${basic_rate_list:+"rates=$brstr"}
143         }
144
145         local mcval=""
146         [ -n "$mcast_rate" ] && {
147                 mcval="$(($mcast_rate / 1000))"
148                 mcsub="$(( ($mcast_rate / 100) % 10 ))"
149                 [ "$mcsub" -gt 0 ] && mcval="$mcval.$mcsub"
150                 mrate=${mcast_rate:+"mcast_rate=$mcval"}
151         }
152
153         local ht_str
154         [ -n "$ht" ] && ht_str="htmode=$ht"
155
156         rm -rf /var/run/wpa_supplicant-$ifname
157         cat > /var/run/wpa_supplicant-$ifname.conf <<EOF
158 ctrl_interface=/var/run/wpa_supplicant-$ifname
159 $ap_scan
160 network={
161         $modestr
162         scan_ssid=$scan_ssid
163         ssid="$ssid"
164         $bssid1
165         key_mgmt=$key_mgmt
166         $proto
167         $freq
168         ${fixed:+"fixed_freq=1"}
169         $beacon_interval
170         $brates
171         $mrate
172         $ht_str
173         $ieee80211w
174         $passphrase
175         $pairwise
176         $group
177         $eap_type
178         $ca_cert
179         $client_cert
180         $priv_key
181         $priv_key_pwd
182         $phase2
183         $identity
184         $password
185         $wep_key0
186         $wep_key1
187         $wep_key2
188         $wep_key3
189         $wep_tx_keyidx
190 }
191 EOF
192         [ -z "$proto" -a "$key_mgmt" != "NONE" ] || \
193                 wpa_supplicant ${bridge:+ -b $bridge} -B -P "/var/run/wifi-${ifname}.pid" -D ${driver:-wext} -i "$ifname" -c /var/run/wpa_supplicant-$ifname.conf $options
194 }