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 function hostapd_config_write
() {
31 # Shift the device and file argument.
44 while [ $# -gt 0 ]; do
47 broadcast_ssid
=$
(cli_get_val
${1})
50 channel
=$
(cli_get_val
${1})
53 country_code
=$
(cli_get_val
${1})
56 encryption
=$
(cli_get_val
${1})
59 local val
="$(cli_get_val "${1}")"
67 key
=$
(cli_get_val
${1})
70 mode
=$
(cli_get_val
${1})
73 ssid
=$
(cli_get_val
${1})
76 local val
="$(cli_get_val "${1}")"
84 warning_log
"Ignoring unknown argument '${1}'."
90 assert isset broadcast_ssid
91 assert isbool broadcast_ssid
94 assert isinteger channel
96 assert isset country_code
100 # Check if key is set when encryption is used.
101 if isset encryption
; then
102 assert isoneof encryption WPA WPA2 WPA
/WPA2
106 # Create configuration directory.
107 local config_dir
=$
(dirname ${file})
108 mkdir
-p ${HOSTAPD_CONTROL_INTERFACE_DIR} ${config_dir} 2>/dev
/null
110 config_header
"hostapd" > ${file}
112 # Interface configuration
114 print
"# Interface configuration"
115 print
"driver=nl80211"
116 print
"interface=${device}"
120 # Wireless configuration
121 local ignore_broadcast_ssid
122 if enabled broadcast_ssid
; then
123 ignore_broadcast_ssid
="0"
125 ignore_broadcast_ssid
="1"
128 local hw_mode ieee80211n
="0"
129 if [ "${mode}" = "n" ]; then
130 if [ ${channel} -le 15 ]; then
141 print
"# Wireless configuration"
142 print
"channel=${channel}"
143 print
"country_code=${country_code}"
144 print
"hw_mode=${hw_mode}"
145 print
"ieee80211d=${ieee80211d}"
146 print
"ieee80211n=${ieee80211n}"
147 print
"ignore_broadcast_ssid=${ignore_broadcast_ssid}"
149 if contains_spaces
"${ssid}"; then
150 print
"ssid=\"${ssid}\""
156 print
"wmm_enabled=${wmm}"
163 print
"# Control interface"
164 print
"ctrl_interface=${HOSTAPD_CONTROL_INTERFACE_DIR}"
165 print
"ctrl_interface_group=0"
169 # Encryption settings
170 if isset encryption
; then
171 local encryption_mode
=0
172 case "${encryption}" in
185 print
"# Encryption settings"
186 print
"wpa=${encryption_mode}"
187 print
"wpa_passphrase=${key}"
188 print
"wpa_key_mgmt=WPA-PSK"
189 print
"wpa_pairwise=TKIP"
190 print
"rsn_pairwise=CCMP"
198 function hostapd_start
() {
202 service_start
"hostapd@${device}.service"
205 if [ ${ret} -eq ${EXIT_OK} ]; then
206 log DEBUG
"hostapd has been successfully started on '${device}'"
208 log ERROR
"Could not start hostapd on '${device}': ${ret}"
215 function hostapd_stop
() {
219 service_stop
"hostapd@${device}.service"