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)"
42 local environment
="${WIRELESS_DEFAULT_ENVIRONMENT}"
48 while [ $# -gt 0 ]; do
51 broadcast_ssid
=$
(cli_get_val
"${1}")
54 channel
=$
(cli_get_val
"${1}")
56 --channel-bandwidth=*)
57 channel_bandwidth
="$(cli_get_val "${1}")"
60 dfs
="$(cli_get_val "${1}")"
63 encryption
=$
(cli_get_val
"${1}")
66 environment
="$(cli_get_val "${1}")"
69 key
=$
(cli_get_val
"${1}")
72 mode
=$
(cli_get_val
"${1}")
74 if ! isoneof mode
${HOSTAPD_SUPPORTED_MODES}; then
75 error
"Unsupported mode: ${mode}"
80 ssid
=$
(cli_get_val
"${1}")
83 local val
="$(cli_get_val "${1}")"
91 warning_log
"Ignoring unknown argument '${1}'."
97 # Check if mode is set
99 error
"Mode is not set"
103 assert isset broadcast_ssid
104 assert isbool broadcast_ssid
107 assert isinteger channel
112 # Check if key is set when encryption is used.
113 if isset encryption
; then
114 assert isoneof encryption WPA WPA2 WPA
/WPA2
118 # Check wireless environment
119 if ! wireless_environment_is_valid
"${environment}"; then
120 error
"Invalid wireless environment: ${environment}"
124 # With channel 0, ACS must be supported
125 if [ ${channel} -eq 0 ] && ! wireless_supports_acs
"${device}"; then
126 error
"ACS requested, but not supported by ${device}"
130 # Check channel bandwidth for validity
131 if isset channel_bandwidth
&& ! wireless_channel_bandwidth_is_valid
"${mode}" "${channel_bandwidth}"; then
132 error
"Invalid channel bandwidth for ${mode}: ${channel_bandwidth}"
140 local vht_oper_chwidth
="0"
154 ht_caps
="$(wireless_get_ht_caps "${device}")"
166 ht_caps
="$(wireless_get_ht_caps "${device}")"
175 vht_caps
="$(wireless_get_vht_caps "${device}")"
178 ht_caps
="$(wireless_get_ht_caps "${device}")"
180 case "${channel_bandwidth}" in
194 # Create configuration directory.
195 local config_dir
=$
(dirname ${file})
196 mkdir
-p ${HOSTAPD_CONTROL_INTERFACE_DIR} ${config_dir} 2>/dev
/null
198 config_header
"hostapd" > ${file}
200 # Interface configuration
202 print
"# Interface configuration"
203 print
"driver=nl80211"
204 print
"interface=${device}"
208 # Wireless configuration
209 local ignore_broadcast_ssid
210 if enabled broadcast_ssid
; then
211 ignore_broadcast_ssid
="0"
213 ignore_broadcast_ssid
="1"
217 # Advertise country code and maximum transmission power
219 print
"country_code=${country_code}"
221 # Wireless Environment
222 case "${environment}" in
224 print
"country3=0x49"
228 print
"country3=0x4f"
231 print
"country3=0x20"
235 # Always advertise TPC
236 print
"local_pwr_constraint=3"
237 print
"spectrum_mgmt_required=1"
239 # Enable Radar Detection
240 if enabled dfs
&& wireless_supports_dfs
"${device}"; then
248 print
"# Wireless configuration"
249 print
"hw_mode=${hw_mode}"
251 if isset ieee80211ac
; then
252 print
"ieee80211ac=${ieee80211ac}"
255 if isset ieee80211n
; then
256 print
"ieee80211n=${ieee80211n}"
259 print
"channel=${channel}"
260 print
"ignore_broadcast_ssid=${ignore_broadcast_ssid}"
262 if contains_spaces
"${ssid}"; then
263 print
"ssid=\"${ssid}\""
269 print
"wmm_enabled=${wmm}"
272 if isset vht_caps
; then
273 print
"vht_capab=${vht_caps}"
277 print
"ht_capab=${ht_caps}"
280 print
"vht_oper_chwidth=${vht_oper_chwidth}"
287 print
"# Control interface"
288 print
"ctrl_interface=${HOSTAPD_CONTROL_INTERFACE_DIR}"
289 print
"ctrl_interface_group=0"
293 # Encryption settings
294 if isset encryption
; then
295 local encryption_mode
=0
296 case "${encryption}" in
309 print
"# Encryption settings"
310 print
"wpa=${encryption_mode}"
311 print
"wpa_passphrase=${key}"
312 print
"wpa_key_mgmt=WPA-PSK"
313 print
"wpa_pairwise=TKIP"
314 print
"rsn_pairwise=CCMP"
326 service_start
"hostapd@${device}.service"
329 if [ ${ret} -eq ${EXIT_OK} ]; then
330 log DEBUG
"hostapd has been successfully started on '${device}'"
332 log ERROR
"Could not start hostapd on '${device}': ${ret}"
343 service_stop
"hostapd@${device}.service"