2 ###############################################################################
4 # IPFire.org - A linux based firewall #
5 # Copyright (C) 2012 IPFire Network Development Team #
7 # This program is free software: you can redistribute it and/or modify #
8 # it under the terms of the GNU General Public License as published by #
9 # the Free Software Foundation, either version 3 of the License, or #
10 # (at your option) any later version. #
12 # This program is distributed in the hope that it will be useful, #
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of #
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the #
15 # GNU General Public License for more details. #
17 # You should have received a copy of the GNU General Public License #
18 # along with this program. If not, see <http://www.gnu.org/licenses/>. #
20 ###############################################################################
22 HOSTAPD_CONTROL_INTERFACE_DIR
="/run/hostapd/ctrl"
24 HOSTAPD_SUPPORTED_MODES
="802.11a 802.11a/n 802.11ac 802.11g 802.11g/n"
26 hostapd_config_write
() {
33 # Shift the device and file argument.
38 local channel_bandwidth
39 local country_code
="$(wireless_get_reg_domain)"
47 while [ $# -gt 0 ]; do
50 broadcast_ssid
=$
(cli_get_val
"${1}")
53 channel
=$
(cli_get_val
"${1}")
55 --channel-bandwidth=*)
56 channel_bandwidth
="$(cli_get_val "${1}")"
59 dfs
="$(cli_get_val "${1}")"
62 encryption
=$
(cli_get_val
"${1}")
65 key
=$
(cli_get_val
"${1}")
68 mode
=$
(cli_get_val
"${1}")
70 if ! isoneof mode
${HOSTAPD_SUPPORTED_MODES}; then
71 error
"Unsupported mode: ${mode}"
76 ssid
=$
(cli_get_val
"${1}")
79 local val
="$(cli_get_val "${1}")"
87 warning_log
"Ignoring unknown argument '${1}'."
93 # Check if mode is set
95 error
"Mode is not set"
99 assert isset broadcast_ssid
100 assert isbool broadcast_ssid
103 assert isinteger channel
108 # Check if key is set when encryption is used.
109 if isset encryption
; then
110 assert isoneof encryption WPA WPA2 WPA
/WPA2
114 # With channel 0, ACS must be supported
115 if [ ${channel} -eq 0 ] && ! wireless_supports_acs
"${device}"; then
116 error
"ACS requested, but not supported by ${device}"
120 # Check channel bandwidth for validity
121 if isset channel_bandwidth
&& ! wireless_channel_bandwidth_is_valid
"${mode}" "${channel_bandwidth}"; then
122 error
"Invalid channel bandwidth for ${mode}: ${channel_bandwidth}"
130 local vht_oper_chwidth
="0"
144 ht_caps
="$(wireless_get_ht_caps "${device}")"
156 ht_caps
="$(wireless_get_ht_caps "${device}")"
165 vht_caps
="$(wireless_get_vht_caps "${device}")"
168 ht_caps
="$(wireless_get_ht_caps "${device}")"
170 case "${channel_bandwidth}" in
184 # Create configuration directory.
185 local config_dir
=$
(dirname ${file})
186 mkdir
-p ${HOSTAPD_CONTROL_INTERFACE_DIR} ${config_dir} 2>/dev
/null
188 config_header
"hostapd" > ${file}
190 # Interface configuration
192 print
"# Interface configuration"
193 print
"driver=nl80211"
194 print
"interface=${device}"
198 # Wireless configuration
199 local ignore_broadcast_ssid
200 if enabled broadcast_ssid
; then
201 ignore_broadcast_ssid
="0"
203 ignore_broadcast_ssid
="1"
207 print
"# Default settings"
209 # Advertise country code and maximum transmission power
212 # Enable Radar Detection
213 if enabled dfs
&& wireless_supports_dfs
"${device}"; then
221 print
"# Wireless configuration"
222 print
"hw_mode=${hw_mode}"
224 if isset ieee80211ac
; then
225 print
"ieee80211ac=${ieee80211ac}"
228 if isset ieee80211n
; then
229 print
"ieee80211n=${ieee80211n}"
232 print
"channel=${channel}"
233 print
"country_code=${country_code}"
234 print
"ignore_broadcast_ssid=${ignore_broadcast_ssid}"
236 if contains_spaces
"${ssid}"; then
237 print
"ssid=\"${ssid}\""
243 print
"wmm_enabled=${wmm}"
246 if isset vht_caps
; then
247 print
"vht_capab=${vht_caps}"
251 print
"ht_capab=${ht_caps}"
254 print
"vht_oper_chwidth=${vht_oper_chwidth}"
261 print
"# Control interface"
262 print
"ctrl_interface=${HOSTAPD_CONTROL_INTERFACE_DIR}"
263 print
"ctrl_interface_group=0"
267 # Encryption settings
268 if isset encryption
; then
269 local encryption_mode
=0
270 case "${encryption}" in
283 print
"# Encryption settings"
284 print
"wpa=${encryption_mode}"
285 print
"wpa_passphrase=${key}"
286 print
"wpa_key_mgmt=WPA-PSK"
287 print
"wpa_pairwise=TKIP"
288 print
"rsn_pairwise=CCMP"
300 service_start
"hostapd@${device}.service"
303 if [ ${ret} -eq ${EXIT_OK} ]; then
304 log DEBUG
"hostapd has been successfully started on '${device}'"
306 log ERROR
"Could not start hostapd on '${device}': ${ret}"
317 service_stop
"hostapd@${device}.service"