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)"
45 while [ $# -gt 0 ]; do
48 broadcast_ssid
=$
(cli_get_val
"${1}")
51 channel
=$
(cli_get_val
"${1}")
54 encryption
=$
(cli_get_val
"${1}")
57 key
=$
(cli_get_val
"${1}")
60 mode
=$
(cli_get_val
"${1}")
62 if ! isoneof mode
${HOSTAPD_SUPPORTED_MODES}; then
63 error
"Unsupported mode: ${mode}"
68 ssid
=$
(cli_get_val
"${1}")
71 local val
="$(cli_get_val "${1}")"
79 warning_log
"Ignoring unknown argument '${1}'."
85 # Check if mode is set
87 error
"Mode is not set"
91 assert isset broadcast_ssid
92 assert isbool broadcast_ssid
95 assert isinteger channel
100 # Check if key is set when encryption is used.
101 if isset encryption
; then
102 assert isoneof encryption WPA WPA2 WPA
/WPA2
123 ht_caps
="$(wireless_get_ht_caps "${device}")"
135 ht_caps
="$(wireless_get_ht_caps "${device}")"
144 vht_caps
="$(wireless_get_vht_caps "${device}")"
147 ht_caps
="$(wireless_get_ht_caps "${device}")"
151 # Create configuration directory.
152 local config_dir
=$
(dirname ${file})
153 mkdir
-p ${HOSTAPD_CONTROL_INTERFACE_DIR} ${config_dir} 2>/dev
/null
155 config_header
"hostapd" > ${file}
157 # Interface configuration
159 print
"# Interface configuration"
160 print
"driver=nl80211"
161 print
"interface=${device}"
165 # Wireless configuration
166 local ignore_broadcast_ssid
167 if enabled broadcast_ssid
; then
168 ignore_broadcast_ssid
="0"
170 ignore_broadcast_ssid
="1"
174 print
"# Default settings"
176 # Advertise country code and maximum transmission power
179 # Enable Radar Detection
184 print
"# Wireless configuration"
185 print
"hw_mode=${hw_mode}"
187 if isset ieee80211ac
; then
188 print
"ieee80211ac=${ieee80211ac}"
191 if isset ieee80211n
; then
192 print
"ieee80211n=${ieee80211n}"
195 print
"channel=${channel}"
196 print
"country_code=${country_code}"
197 print
"ignore_broadcast_ssid=${ignore_broadcast_ssid}"
199 if contains_spaces
"${ssid}"; then
200 print
"ssid=\"${ssid}\""
206 print
"wmm_enabled=${wmm}"
209 if isset vht_caps
; then
210 print
"vht_capab=${vht_caps}"
214 print
"ht_capab=${ht_caps}"
221 print
"# Control interface"
222 print
"ctrl_interface=${HOSTAPD_CONTROL_INTERFACE_DIR}"
223 print
"ctrl_interface_group=0"
227 # Encryption settings
228 if isset encryption
; then
229 local encryption_mode
=0
230 case "${encryption}" in
243 print
"# Encryption settings"
244 print
"wpa=${encryption_mode}"
245 print
"wpa_passphrase=${key}"
246 print
"wpa_key_mgmt=WPA-PSK"
247 print
"wpa_pairwise=TKIP"
248 print
"rsn_pairwise=CCMP"
260 service_start
"hostapd@${device}.service"
263 if [ ${ret} -eq ${EXIT_OK} ]; then
264 log DEBUG
"hostapd has been successfully started on '${device}'"
266 log ERROR
"Could not start hostapd on '${device}': ${ret}"
277 service_stop
"hostapd@${device}.service"