1 hostapd_set_bss_options() {
4 local enc wep_rekey wpa_group_rekey wpa_pair_rekey wpa_master_rekey wps_possible wpa_key_mgmt
6 config_get enc "$vif" encryption "none"
7 config_get wep_rekey "$vif" wep_rekey # 300
8 config_get wpa_group_rekey "$vif" wpa_group_rekey # 300
9 config_get wpa_pair_rekey "$vif" wpa_pair_rekey # 300
10 config_get wpa_master_rekey "$vif" wpa_master_rekey # 640
11 config_get_bool ap_isolate "$vif" isolate 0
12 config_get_bool disassoc_low_ack "$vif" disassoc_low_ack 1
13 config_get max_num_sta "$vif" max_num_sta 0
14 config_get max_inactivity "$vif" max_inactivity 0
15 config_get_bool preamble "$vif" short_preamble 1
17 config_get device "$vif" device
18 config_get hwmode "$device" hwmode
19 config_get phy "$device" phy
21 append "$var" "ctrl_interface=/var/run/hostapd-$phy" "$N"
23 if [ "$ap_isolate" -gt 0 ]; then
24 append "$var" "ap_isolate=$ap_isolate" "$N"
26 if [ "$max_num_sta" -gt 0 ]; then
27 append "$var" "max_num_sta=$max_num_sta" "$N"
29 if [ "$max_inactivity" -gt 0 ]; then
30 append "$var" "ap_max_inactivity=$max_inactivity" "$N"
32 append "$var" "disassoc_low_ack=$disassoc_low_ack" "$N"
33 if [ "$preamble" -gt 0 ]; then
34 append "$var" "preamble=$preamble" "$N"
38 # psk-mixed/tkip => WPA1+2 PSK, TKIP
39 # wpa-psk2/tkip+aes => WPA2 PSK, CCMP+TKIP
40 # wpa2/tkip+aes => WPA2 RADIUS, CCMP+TKIP
43 # TODO: move this parsing function somewhere generic, so that
44 # later it can be reused by drivers that don't use hostapd
46 # crypto defaults: WPA2 vs WPA1
62 # explicit override for crypto setting
64 *tkip+aes|*tkip+ccmp|*aes+tkip|*ccmp+tkip) crypto="CCMP TKIP";;
65 *aes|*ccmp) crypto="CCMP";;
66 *tkip) crypto="TKIP";;
69 # enforce CCMP for 11ng and 11na
70 case "$hwmode:$crypto" in
71 *ng:TKIP|*na:TKIP) crypto="CCMP TKIP";;
74 # use crypto/auth settings for building the hostapd config
80 # Here we make the assumption that if we're in open mode
81 # with WPS enabled, we got to be in unconfigured state.
85 config_get psk "$vif" key
86 if [ ${#psk} -eq 64 ]; then
87 append "$var" "wpa_psk=$psk" "$N"
89 append "$var" "wpa_passphrase=$psk" "$N"
92 [ -n "$wpa_group_rekey" ] && append "$var" "wpa_group_rekey=$wpa_group_rekey" "$N"
93 [ -n "$wpa_pair_rekey" ] && append "$var" "wpa_ptk_rekey=$wpa_pair_rekey" "$N"
94 [ -n "$wpa_master_rekey" ] && append "$var" "wpa_gmk_rekey=$wpa_master_rekey" "$N"
95 append wpa_key_mgmt "WPA-PSK"
98 # required fields? formats?
99 # hostapd is particular, maybe a default configuration for failures
100 config_get auth_server "$vif" auth_server
101 [ -z "$auth_server" ] && config_get auth_server "$vif" server
102 append "$var" "auth_server_addr=$auth_server" "$N"
103 config_get auth_port "$vif" auth_port
104 [ -z "$auth_port" ] && config_get auth_port "$vif" port
105 auth_port=${auth_port:-1812}
106 append "$var" "auth_server_port=$auth_port" "$N"
107 config_get auth_secret "$vif" auth_secret
108 [ -z "$auth_secret" ] && config_get auth_secret "$vif" key
109 append "$var" "auth_server_shared_secret=$auth_secret" "$N"
110 # You don't really want to enable this unless you are doing
111 # some corner case testing or are using OpenWrt as a work around
112 # for some systematic issues.
113 config_get_bool auth_cache "$vif" auth_cache 0
114 config_get rsn_preauth "$vif" rsn_preauth
115 [ "$auth_cache" -gt 0 ] || [[ "$rsn_preauth" = 1 ]] || append "$var" "disable_pmksa_caching=1" "$N"
116 [ "$auth_cache" -gt 0 ] || [[ "$rsn_preauth" = 1 ]] || append "$var" "okc=0" "$N"
117 config_get acct_server "$vif" acct_server
118 [ -n "$acct_server" ] && append "$var" "acct_server_addr=$acct_server" "$N"
119 config_get acct_port "$vif" acct_port
120 [ -n "$acct_port" ] && acct_port=${acct_port:-1813}
121 [ -n "$acct_port" ] && append "$var" "acct_server_port=$acct_port" "$N"
122 config_get acct_secret "$vif" acct_secret
123 [ -n "$acct_secret" ] && append "$var" "acct_server_shared_secret=$acct_secret" "$N"
124 config_get eap_reauth_period "$vif" eap_reauth_period
125 [ -n "$eap_reauth_period" ] && append "$var" "eap_reauth_period=$eap_reauth_period" "$N"
126 config_get dae_client "$vif" dae_client
127 config_get dae_secret "$vif" dae_secret
128 [ -n "$dae_client" -a -n "$dae_secret" ] && {
129 config_get dae_port "$vif" dae_port
130 append "$var" "radius_das_port=${dae_port:-3799}" "$N"
131 append "$var" "radius_das_client=$dae_client $dae_secret" "$N"
133 config_get ownip "$vif" ownip
134 append "$var" "own_ip_addr=$ownip" "$N"
135 append "$var" "eapol_key_index_workaround=1" "$N"
136 append "$var" "ieee8021x=1" "$N"
137 append wpa_key_mgmt "WPA-EAP"
138 [ -n "$wpa_group_rekey" ] && append "$var" "wpa_group_rekey=$wpa_group_rekey" "$N"
139 [ -n "$wpa_pair_rekey" ] && append "$var" "wpa_ptk_rekey=$wpa_pair_rekey" "$N"
140 [ -n "$wpa_master_rekey" ] && append "$var" "wpa_gmk_rekey=$wpa_master_rekey" "$N"
143 config_get key "$vif" key
147 for idx in 1 2 3 4; do
150 config_get ckey "$vif" "key${idx}"
152 append "$var" "wep_key${zidx}=$(prepare_key_wep "$ckey")" "$N"
154 append "$var" "wep_default_key=$((key - 1))" "$N"
157 append "$var" "wep_key0=$(prepare_key_wep "$key")" "$N"
158 append "$var" "wep_default_key=0" "$N"
159 [ -n "$wep_rekey" ] && append "$var" "wep_rekey_period=$wep_rekey" "$N"
178 append "$var" "auth_algs=${auth_algs:-1}" "$N"
179 append "$var" "wpa=$wpa" "$N"
180 [ -n "$crypto" ] && append "$var" "wpa_pairwise=$crypto" "$N"
181 [ -n "$wpa_group_rekey" ] && append "$var" "wpa_group_rekey=$wpa_group_rekey" "$N"
183 config_get ssid "$vif" ssid
184 config_get bridge "$vif" bridge
185 config_get ieee80211d "$vif" ieee80211d
186 config_get iapp_interface "$vif" iapp_interface
188 config_get_bool wps_pbc "$vif" wps_pushbutton 0
189 config_get_bool wps_label "$vif" wps_label 0
191 config_get config_methods "$vif" wps_config
192 [ "$wps_pbc" -gt 0 ] && append config_methods push_button
194 [ -n "$wps_possible" -a -n "$config_methods" ] && {
195 config_get device_type "$vif" wps_device_type "6-0050F204-1"
196 config_get device_name "$vif" wps_device_name "OpenWrt AP"
197 config_get manufacturer "$vif" wps_manufacturer "openwrt.org"
198 config_get wps_pin "$vif" wps_pin
200 config_get_bool ext_registrar "$vif" ext_registrar 0
201 [ "$ext_registrar" -gt 0 -a -n "$bridge" ] && append "$var" "upnp_iface=$bridge" "$N"
203 append "$var" "eap_server=1" "$N"
204 [ -n "$wps_pin" ] && append "$var" "ap_pin=$wps_pin" "$N"
205 append "$var" "wps_state=${wps_not_configured:-2}" "$N"
206 append "$var" "ap_setup_locked=0" "$N"
207 append "$var" "device_type=$device_type" "$N"
208 append "$var" "device_name=$device_name" "$N"
209 append "$var" "manufacturer=$manufacturer" "$N"
210 append "$var" "config_methods=$config_methods" "$N"
213 append "$var" "ssid=$ssid" "$N"
214 [ -n "$bridge" ] && append "$var" "bridge=$bridge" "$N"
215 [ -n "$ieee80211d" ] && append "$var" "ieee80211d=$ieee80211d" "$N"
216 [ -n "$iapp_interface" ] && append "$var" iapp_interface=$(uci_get_state network "$iapp_interface" ifname "$iapp_interface") "$N"
218 if [ "$wpa" -ge "1" ]
220 config_get nasid "$vif" nasid
221 [ -n "$nasid" ] && append "$var" "nas_identifier=$nasid" "$N"
223 config_get_bool ieee80211r "$vif" ieee80211r 0
224 if [ "$ieee80211r" -gt 0 ]
226 config_get mobility_domain "$vif" mobility_domain "4f57"
227 config_get r0_key_lifetime "$vif" r0_key_lifetime "10000"
228 config_get r1_key_holder "$vif" r1_key_holder "00004f577274"
229 config_get reassociation_deadline "$vif" reassociation_deadline "1000"
230 config_get r0kh "$vif" r0kh
231 config_get r1kh "$vif" r1kh
232 config_get_bool pmk_r1_push "$vif" pmk_r1_push 0
234 append "$var" "mobility_domain=$mobility_domain" "$N"
235 append "$var" "r0_key_lifetime=$r0_key_lifetime" "$N"
236 append "$var" "r1_key_holder=$r1_key_holder" "$N"
237 append "$var" "reassociation_deadline=$reassociation_deadline" "$N"
238 append "$var" "pmk_r1_push=$pmk_r1_push" "$N"
241 "$var" "r0kh=${kh//,/ }" "$N"
244 "$var" "r1kh=${kh//,/ }" "$N"
247 [ "$wpa_key_mgmt" != "${wpa_key_mgmt/EAP/}" ] && append wpa_key_mgmt "FT-EAP"
248 [ "$wpa_key_mgmt" != "${wpa_key_mgmt/PSK/}" ] && append wpa_key_mgmt "FT-PSK"
251 [ -n "wpa_key_mgmt" ] && append "$var" "wpa_key_mgmt=$wpa_key_mgmt"
254 if [ "$wpa" -ge "2" ]
256 # RSN -> allow preauthentication. You have two
257 # options, rsn_preauth for production or rsn_preauth_testing
258 # for validation / testing.
259 if [ -n "$bridge" -a "$rsn_preauth" = 1 ]
261 append "$var" "rsn_preauth=1" "$N"
262 append "$var" "rsn_preauth_interfaces=$bridge" "$N"
263 append "$var" "okc=1" "$N"
265 # RSN preauthentication testings hould disable
266 # Opportunistic Key Caching (okc) as otherwise the PMKSA
267 # entry for a test could come from the Opportunistic Key Caching
268 config_get rsn_preauth_testing "$vif" rsn_preauth_testing
269 if [ -n "$bridge" -a "$rsn_preauth_testing" = 1 ]
271 append "$var" "rsn_preauth=1" "$N"
272 append "$var" "rsn_preauth_interfaces=$bridge" "$N"
273 append "$var" "okc=0" "$N"
277 # RSN -> allow management frame protection
278 config_get ieee80211w "$vif" ieee80211w
279 case "$ieee80211w" in
281 append "$var" "ieee80211w=$ieee80211w" "$N"
282 [ "$ieee80211w" -gt "0" ] && {
283 config_get ieee80211w_max_timeout "$vif" ieee80211w_max_timeout
284 config_get ieee80211w_retry_timeout "$vif" ieee80211w_retry_timeout
285 [ -n "$ieee80211w_max_timeout" ] && \
286 append "$var" "assoc_sa_query_max_timeout=$ieee80211w_max_timeout" "$N"
287 [ -n "$ieee80211w_retry_timeout" ] && \
288 append "$var" "assoc_sa_query_retry_timeout=$ieee80211w_retry_timeout" "$N"
294 config_get macfile "$vif" macfile
295 config_get maclist "$vif" maclist
298 # if no macfile has been specified, fallback to the default name
299 # and truncate file to avoid aggregating entries over time
300 macfile="/var/run/hostapd-$ifname.maclist"
305 # to avoid to overwrite the original file, make a copy
306 # before appending the entries specified by the maclist
308 cp $macfile $macfile.maclist
309 macfile=$macfile.maclist
315 for mac in $maclist; do
316 echo "$mac" >> $macfile
320 config_get macfilter "$vif" macfilter
323 append "$var" "macaddr_acl=1" "$N"
324 append "$var" "accept_mac_file=$macfile" "$N"
327 append "$var" "macaddr_acl=0" "$N"
328 append "$var" "deny_mac_file=$macfile" "$N"
333 hostapd_set_log_options() {
336 local log_level log_80211 log_8021x log_radius log_wpa log_driver log_iapp log_mlme
338 config_get log_level "$cfg" log_level 2
340 config_get_bool log_80211 "$cfg" log_80211 1
341 config_get_bool log_8021x "$cfg" log_8021x 1
342 config_get_bool log_radius "$cfg" log_radius 1
343 config_get_bool log_wpa "$cfg" log_wpa 1
344 config_get_bool log_driver "$cfg" log_driver 1
345 config_get_bool log_iapp "$cfg" log_iapp 1
346 config_get_bool log_mlme "$cfg" log_mlme 1
349 ($log_80211 << 0) | \
350 ($log_8021x << 1) | \
351 ($log_radius << 2) | \
353 ($log_driver << 4) | \
358 append "$var" "logger_syslog=$log_mask" "$N"
359 append "$var" "logger_syslog_level=$log_level" "$N"
360 append "$var" "logger_stdout=$log_mask" "$N"
361 append "$var" "logger_stdout_level=$log_level" "$N"
364 hostapd_setup_vif() {
367 local ifname device channel hwmode
371 config_get ifname "$vif" ifname
372 config_get device "$vif" device
373 config_get channel "$device" channel
374 config_get hwmode "$device" hwmode
376 hostapd_set_log_options hostapd_cfg "$device"
377 hostapd_set_bss_options hostapd_cfg "$vif"
380 *bg|*gdt|*gst|*fh) hwmode=g;;
381 *adt|*ast) hwmode=a;;
383 [ "$channel" = auto ] && channel=
384 [ -n "$channel" -a -z "$hwmode" ] && wifi_fixup_hwmode "$device"
385 cat > /var/run/hostapd-$ifname.conf <<EOF
388 ${hwmode:+hw_mode=${hwmode#11}}
389 ${channel:+channel=$channel}
392 hostapd -P /var/run/wifi-$ifname.pid -B /var/run/hostapd-$ifname.conf