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 country_code
="$(wireless_get_reg_domain)"
46 while [ $# -gt 0 ]; do
49 broadcast_ssid
=$
(cli_get_val
"${1}")
52 channel
=$
(cli_get_val
"${1}")
55 dfs
="$(cli_get_val "${1}")"
58 encryption
=$
(cli_get_val
"${1}")
61 key
=$
(cli_get_val
"${1}")
64 mode
=$
(cli_get_val
"${1}")
66 if ! isoneof mode
${HOSTAPD_SUPPORTED_MODES}; then
67 error
"Unsupported mode: ${mode}"
72 ssid
=$
(cli_get_val
"${1}")
75 local val
="$(cli_get_val "${1}")"
83 warning_log
"Ignoring unknown argument '${1}'."
89 # Check if mode is set
91 error
"Mode is not set"
95 assert isset broadcast_ssid
96 assert isbool broadcast_ssid
99 assert isinteger channel
104 # Check if key is set when encryption is used.
105 if isset encryption
; then
106 assert isoneof encryption WPA WPA2 WPA
/WPA2
127 ht_caps
="$(wireless_get_ht_caps "${device}")"
139 ht_caps
="$(wireless_get_ht_caps "${device}")"
148 vht_caps
="$(wireless_get_vht_caps "${device}")"
151 ht_caps
="$(wireless_get_ht_caps "${device}")"
155 # Create configuration directory.
156 local config_dir
=$
(dirname ${file})
157 mkdir
-p ${HOSTAPD_CONTROL_INTERFACE_DIR} ${config_dir} 2>/dev
/null
159 config_header
"hostapd" > ${file}
161 # Interface configuration
163 print
"# Interface configuration"
164 print
"driver=nl80211"
165 print
"interface=${device}"
169 # Wireless configuration
170 local ignore_broadcast_ssid
171 if enabled broadcast_ssid
; then
172 ignore_broadcast_ssid
="0"
174 ignore_broadcast_ssid
="1"
178 print
"# Default settings"
180 # Advertise country code and maximum transmission power
183 # Enable Radar Detection
184 if enabled dfs
&& wireless_supports_dfs
"${device}"; then
192 print
"# Wireless configuration"
193 print
"hw_mode=${hw_mode}"
195 if isset ieee80211ac
; then
196 print
"ieee80211ac=${ieee80211ac}"
199 if isset ieee80211n
; then
200 print
"ieee80211n=${ieee80211n}"
203 print
"channel=${channel}"
204 print
"country_code=${country_code}"
205 print
"ignore_broadcast_ssid=${ignore_broadcast_ssid}"
207 if contains_spaces
"${ssid}"; then
208 print
"ssid=\"${ssid}\""
214 print
"wmm_enabled=${wmm}"
217 if isset vht_caps
; then
218 print
"vht_capab=${vht_caps}"
222 print
"ht_capab=${ht_caps}"
229 print
"# Control interface"
230 print
"ctrl_interface=${HOSTAPD_CONTROL_INTERFACE_DIR}"
231 print
"ctrl_interface_group=0"
235 # Encryption settings
236 if isset encryption
; then
237 local encryption_mode
=0
238 case "${encryption}" in
251 print
"# Encryption settings"
252 print
"wpa=${encryption_mode}"
253 print
"wpa_passphrase=${key}"
254 print
"wpa_key_mgmt=WPA-PSK"
255 print
"wpa_pairwise=TKIP"
256 print
"rsn_pairwise=CCMP"
268 service_start
"hostapd@${device}.service"
271 if [ ${ret} -eq ${EXIT_OK} ]; then
272 log DEBUG
"hostapd has been successfully started on '${device}'"
274 log ERROR
"Could not start hostapd on '${device}': ${ret}"
285 service_stop
"hostapd@${device}.service"