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_config_write
() {
31 # Shift the device and file argument.
36 local country_code
="$(wireless_get_reg_domain)"
44 while [ $# -gt 0 ]; do
47 broadcast_ssid
=$
(cli_get_val
"${1}")
50 channel
=$
(cli_get_val
"${1}")
53 encryption
=$
(cli_get_val
"${1}")
56 local val
="$(cli_get_val "${1}")"
64 key
=$
(cli_get_val
"${1}")
67 mode
=$
(cli_get_val
"${1}")
70 ssid
=$
(cli_get_val
"${1}")
73 local val
="$(cli_get_val "${1}")"
81 warning_log
"Ignoring unknown argument '${1}'."
87 assert isset broadcast_ssid
88 assert isbool broadcast_ssid
91 assert isinteger channel
96 # Check if key is set when encryption is used.
97 if isset encryption
; then
98 assert isoneof encryption WPA WPA2 WPA
/WPA2
103 local ht_caps
="$(wireless_get_ht_caps "${device}")"
105 # Create configuration directory.
106 local config_dir
=$
(dirname ${file})
107 mkdir
-p ${HOSTAPD_CONTROL_INTERFACE_DIR} ${config_dir} 2>/dev
/null
109 config_header
"hostapd" > ${file}
111 # Interface configuration
113 print
"# Interface configuration"
114 print
"driver=nl80211"
115 print
"interface=${device}"
119 # Wireless configuration
120 local ignore_broadcast_ssid
121 if enabled broadcast_ssid
; then
122 ignore_broadcast_ssid
="0"
124 ignore_broadcast_ssid
="1"
127 local hw_mode ieee80211n
="0"
128 if [ "${mode}" = "n" ]; then
129 if [ ${channel} -le 15 ]; then
140 print
"# Wireless configuration"
141 print
"channel=${channel}"
142 print
"country_code=${country_code}"
143 print
"hw_mode=${hw_mode}"
144 print
"ieee80211d=${ieee80211d}"
145 print
"ieee80211n=${ieee80211n}"
146 print
"ignore_broadcast_ssid=${ignore_broadcast_ssid}"
148 if contains_spaces
"${ssid}"; then
149 print
"ssid=\"${ssid}\""
155 print
"wmm_enabled=${wmm}"
158 print
"ht_capab=${ht_caps}"
165 print
"# Control interface"
166 print
"ctrl_interface=${HOSTAPD_CONTROL_INTERFACE_DIR}"
167 print
"ctrl_interface_group=0"
171 # Encryption settings
172 if isset encryption
; then
173 local encryption_mode
=0
174 case "${encryption}" in
187 print
"# Encryption settings"
188 print
"wpa=${encryption_mode}"
189 print
"wpa_passphrase=${key}"
190 print
"wpa_key_mgmt=WPA-PSK"
191 print
"wpa_pairwise=TKIP"
192 print
"rsn_pairwise=CCMP"
204 service_start
"hostapd@${device}.service"
207 if [ ${ret} -eq ${EXIT_OK} ]; then
208 log DEBUG
"hostapd has been successfully started on '${device}'"
210 log ERROR
"Could not start hostapd on '${device}': ${ret}"
221 service_stop
"hostapd@${device}.service"