1 hostapd_set_bss_options
() {
4 local enc wpa_group_rekey wps_possible
6 config_get enc
"$vif" encryption
7 config_get wpa_group_rekey
"$vif" wpa_group_rekey
8 config_get_bool ap_isolate
"$vif" isolate
0
10 config_get device
"$vif" device
11 config_get hwmode
"$device" hwmode
12 config_get phy
"$device" phy
14 append
"$var" "ctrl_interface=/var/run/hostapd-$phy" "$N"
16 if [ "$ap_isolate" -gt 0 ]; then
17 append
"$var" "ap_isolate=$ap_isolate" "$N"
21 # psk-mixed/tkip => WPA1+2 PSK, TKIP
22 # wpa-psk2/tkip+aes => WPA2 PSK, CCMP+TKIP
23 # wpa2/tkip+aes => WPA2 RADIUS, CCMP+TKIP
26 # TODO: move this parsing function somewhere generic, so that
27 # later it can be reused by drivers that don't use hostapd
29 # crypto defaults: WPA2 vs WPA1
45 # explicit override for crypto setting
47 *tkip
+aes|
*tkip
+ccmp|
*aes
+tkip|
*ccmp
+tkip
) crypto
="CCMP TKIP";;
48 *aes|
*ccmp
) crypto
="CCMP";;
49 *tkip
) crypto
="TKIP";;
52 # enforce CCMP for 11ng and 11na
53 case "$hwmode:$crypto" in
54 *ng
:TKIP|
*na
:TKIP
) crypto
="CCMP TKIP";;
57 # use crypto/auth settings for building the hostapd config
60 config_get psk
"$vif" key
61 if [ ${#psk} -eq 64 ]; then
62 append
"$var" "wpa_psk=$psk" "$N"
64 append
"$var" "wpa_passphrase=$psk" "$N"
69 # required fields? formats?
70 # hostapd is particular, maybe a default configuration for failures
71 config_get auth_server
"$vif" auth_server
72 [ -z "$auth_server" ] && config_get auth_server
"$vif" server
73 append
"$var" "auth_server_addr=$auth_server" "$N"
74 config_get auth_port
"$vif" auth_port
75 [ -z "$auth_port" ] && config_get auth_port
"$vif" port
76 auth_port
=${auth_port:-1812}
77 append
"$var" "auth_server_port=$auth_port" "$N"
78 config_get auth_secret
"$vif" auth_secret
79 [ -z "$auth_secret" ] && config_get auth_secret
"$vif" key
80 append
"$var" "auth_server_shared_secret=$auth_secret" "$N"
81 config_get acct_server
"$vif" acct_server
82 [ -n "$acct_server" ] && append
"$var" "acct_server_addr=$acct_server" "$N"
83 config_get acct_port
"$vif" acct_port
84 [ -n "$acct_port" ] && acct_port
=${acct_port:-1813}
85 [ -n "$acct_port" ] && append
"$var" "acct_server_port=$acct_port" "$N"
86 config_get acct_secret
"$vif" acct_secret
87 [ -n "$acct_secret" ] && append
"$var" "acct_server_shared_secret=$acct_secret" "$N"
88 config_get nasid
"$vif" nasid
89 append
"$var" "nas_identifier=$nasid" "$N"
90 append
"$var" "eapol_key_index_workaround=1" "$N"
91 append
"$var" "radius_acct_interim_interval=300" "$N"
92 append
"$var" "ieee8021x=1" "$N"
93 append
"$var" "wpa_key_mgmt=WPA-EAP" "$N"
94 append
"$var" "wpa_group_rekey=300" "$N"
95 append
"$var" "wpa_gmk_rekey=640" "$N"
98 config_get key
"$vif" key
102 for idx
in 1 2 3 4; do
105 config_get ckey
"$vif" "key${idx}"
107 append
"$var" "wep_key${zidx}=$(prepare_key_wep "$ckey")" "$N"
109 append
"$var" "wep_default_key=$((key - 1))" "$N"
112 append
"$var" "wep_key0=$(prepare_key_wep "$key")" "$N"
113 append
"$var" "wep_default_key=0" "$N"
132 append
"$var" "auth_algs=${auth_algs:-1}" "$N"
133 append
"$var" "wpa=$wpa" "$N"
134 [ -n "$crypto" ] && append
"$var" "wpa_pairwise=$crypto" "$N"
135 [ -n "$wpa_group_rekey" ] && append
"$var" "wpa_group_rekey=$wpa_group_rekey" "$N"
137 config_get ssid
"$vif" ssid
138 config_get bridge
"$vif" bridge
139 config_get ieee80211d
"$vif" ieee80211d
140 config_get iapp_interface
"$vif" iapp_interface
142 config_get_bool wps_pbc
"$vif" wps_pushbutton
0
143 config_get_bool wps_label
"$vif" wps_label
0
145 config_get config_methods
"$vif" wps_config
146 [ "$wps_pbc" -gt 0 ] && append config_methods push_button
148 [ -n "$wps_possible" -a -n "$config_methods" ] && {
149 config_get device_type
"$vif" wps_device_type
"6-0050F204-1"
150 config_get device_name
"$vif" wps_device_name
"OpenWrt AP"
151 config_get manufacturer
"$vif" wps_manufacturer
"openwrt.org"
153 append
"$var" "eap_server=1" "$N"
154 append
"$var" "wps_state=2" "$N"
155 append
"$var" "ap_setup_locked=1" "$N"
156 append
"$var" "device_type=$device_type" "$N"
157 append
"$var" "device_name=$device_name" "$N"
158 append
"$var" "manufacturer=$manufacturer" "$N"
159 append
"$var" "config_methods=$config_methods" "$N"
162 append
"$var" "ssid=$ssid" "$N"
163 [ -n "$bridge" ] && append
"$var" "bridge=$bridge" "$N"
164 [ -n "$ieee80211d" ] && append
"$var" "ieee80211d=$ieee80211d" "$N"
165 [ -n "$iapp_interface" ] && append
"$var" iapp_interface
=$
(uci_get_state network
"$iapp_interface" ifname
"$iapp_interface") "$N"
167 if [ "$wpa" -ge "2" ]
169 # RSN -> allow preauthentication
170 config_get rsn_preauth
"$vif" rsn_preauth
171 if [ -n "$bridge" -a "$rsn_preauth" = 1 ]
173 append
"$var" "rsn_preauth=1" "$N"
174 append
"$var" "rsn_preauth_interfaces=$bridge" "$N"
177 # RSN -> allow management frame protection
178 config_get ieee80211w
"$vif" ieee80211w
179 case "$ieee80211w" in
181 append
"$var" "ieee80211w=$ieee80211w" "$N"
182 [ "$ieee80211w" -gt "0" ] && {
183 config_get ieee80211w_max_timeout
"$vif" ieee80211w_max_timeout
184 config_get ieee80211w_retry_timeout
"$vif" ieee80211w_retry_timeout
185 [ -n "$ieee80211w_max_timeout" ] && \
186 append
"$var" "assoc_sa_query_max_timeout=$ieee80211w_max_timeout" "$N"
187 [ -n "$ieee80211w_retry_timeout" ] && \
188 append
"$var" "assoc_sa_query_retry_timeout=$ieee80211w_retry_timeout" "$N"
195 hostapd_set_log_options
() {
198 local log_level log_80211 log_8021x log_radius log_wpa log_driver log_iapp log_mlme
200 config_get log_level
"$cfg" log_level
2
202 config_get_bool log_80211
"$cfg" log_80211
1
203 config_get_bool log_8021x
"$cfg" log_8021x
1
204 config_get_bool log_radius
"$cfg" log_radius
1
205 config_get_bool log_wpa
"$cfg" log_wpa
1
206 config_get_bool log_driver
"$cfg" log_driver
1
207 config_get_bool log_iapp
"$cfg" log_iapp
1
208 config_get_bool log_mlme
"$cfg" log_mlme
1
211 ($log_80211 << 0) | \
212 ($log_8021x << 1) | \
213 ($log_radius << 2) | \
215 ($log_driver << 4) | \
220 append "$var" "logger_syslog=$log_mask" "$N"
221 append "$var" "logger_syslog_level=$log_level" "$N"
222 append "$var" "logger_stdout=$log_mask" "$N"
223 append "$var" "logger_stdout_level=$log_level" "$N"
226 hostapd_setup_vif() {
229 local ifname device channel hwmode
233 config_get ifname "$vif" ifname
234 config_get device "$vif" device
235 config_get channel "$device" channel
236 config_get hwmode "$device" hwmode
238 hostapd_set_log_options hostapd_cfg "$device"
239 hostapd_set_bss_options hostapd_cfg "$vif"
242 *bg|*gdt|*gst|*fh) hwmode=g;;
243 *adt|*ast) hwmode=a;;
245 [ "$channel" = auto ] && channel=
246 [ -n "$channel" -a -z "$hwmode" ] && wifi_fixup_hwmode "$device"
247 cat > /var/run/hostapd-$ifname.conf <<EOF
250 ${hwmode:+hw_mode=${hwmode#11}}
251 ${channel:+channel=$channel}
254 hostapd -P /var/run/wifi-$ifname.pid -B /var/run/hostapd-$ifname.conf