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 # Check channel bandwidth for validity
115 if isset channel_bandwidth
&& ! wireless_channel_bandwidth_is_valid
"${mode}" "${channel_bandwidth}"; then
116 error
"Invalid channel bandwidth for ${mode}: ${channel_bandwidth}"
124 local vht_oper_chwidth
="0"
138 ht_caps
="$(wireless_get_ht_caps "${device}")"
150 ht_caps
="$(wireless_get_ht_caps "${device}")"
159 vht_caps
="$(wireless_get_vht_caps "${device}")"
162 ht_caps
="$(wireless_get_ht_caps "${device}")"
164 case "${channel_bandwidth}" in
178 # Create configuration directory.
179 local config_dir
=$
(dirname ${file})
180 mkdir
-p ${HOSTAPD_CONTROL_INTERFACE_DIR} ${config_dir} 2>/dev
/null
182 config_header
"hostapd" > ${file}
184 # Interface configuration
186 print
"# Interface configuration"
187 print
"driver=nl80211"
188 print
"interface=${device}"
192 # Wireless configuration
193 local ignore_broadcast_ssid
194 if enabled broadcast_ssid
; then
195 ignore_broadcast_ssid
="0"
197 ignore_broadcast_ssid
="1"
201 print
"# Default settings"
203 # Advertise country code and maximum transmission power
206 # Enable Radar Detection
207 if enabled dfs
&& wireless_supports_dfs
"${device}"; then
215 print
"# Wireless configuration"
216 print
"hw_mode=${hw_mode}"
218 if isset ieee80211ac
; then
219 print
"ieee80211ac=${ieee80211ac}"
222 if isset ieee80211n
; then
223 print
"ieee80211n=${ieee80211n}"
226 print
"channel=${channel}"
227 print
"country_code=${country_code}"
228 print
"ignore_broadcast_ssid=${ignore_broadcast_ssid}"
230 if contains_spaces
"${ssid}"; then
231 print
"ssid=\"${ssid}\""
237 print
"wmm_enabled=${wmm}"
240 if isset vht_caps
; then
241 print
"vht_capab=${vht_caps}"
245 print
"ht_capab=${ht_caps}"
248 print
"vht_oper_chwidth=${vht_oper_chwidth}"
255 print
"# Control interface"
256 print
"ctrl_interface=${HOSTAPD_CONTROL_INTERFACE_DIR}"
257 print
"ctrl_interface_group=0"
261 # Encryption settings
262 if isset encryption
; then
263 local encryption_mode
=0
264 case "${encryption}" in
277 print
"# Encryption settings"
278 print
"wpa=${encryption_mode}"
279 print
"wpa_passphrase=${key}"
280 print
"wpa_key_mgmt=WPA-PSK"
281 print
"wpa_pairwise=TKIP"
282 print
"rsn_pairwise=CCMP"
294 service_start
"hostapd@${device}.service"
297 if [ ${ret} -eq ${EXIT_OK} ]; then
298 log DEBUG
"hostapd has been successfully started on '${device}'"
300 log ERROR
"Could not start hostapd on '${device}': ${ret}"
311 service_stop
"hostapd@${device}.service"