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.
42 while [ $# -gt 0 ]; do
45 broadcast_ssid
=$
(cli_get_val
${1})
48 channel
=$
(cli_get_val
${1})
51 country_code
=$
(cli_get_val
${1})
54 mode
=$
(cli_get_val
${1})
57 ssid
=$
(cli_get_val
${1})
60 encryption
=$
(cli_get_val
${1})
63 key
=$
(cli_get_val
${1})
66 warning_log
"Ignoring unknown argument '${1}'."
72 assert isset broadcast_ssid
73 assert isbool broadcast_ssid
76 assert isinteger channel
78 assert isset country_code
82 # Check if key is set when encryption is used.
83 if isset encryption
; then
84 assert isoneof encryption WPA WPA2 WPA
/WPA2
88 # Create configuration directory.
89 local config_dir
=$
(dirname ${file})
90 mkdir
-p ${HOSTAPD_CONTROL_INTERFACE_DIR} ${config_dir} 2>/dev
/null
92 config_header
"hostapd" > ${file}
94 # Interface configuration
96 print
"# Interface configuration"
97 print
"driver=nl80211"
98 print
"interface=${device}"
102 # Wireless configuration
103 local ignore_broadcast_ssid
104 if enabled broadcast_ssid
; then
105 ignore_broadcast_ssid
="0"
107 ignore_broadcast_ssid
="1"
110 local hw_mode ieee80211n
="0"
111 if [ "${mode}" = "n" ]; then
112 if [ ${channel} -le 15 ]; then
123 print
"# Wireless configuration"
124 print
"channel=${channel}"
125 print
"country_code=${country_code}"
126 print
"hw_mode=${hw_mode}"
127 print
"ieee80211n=${ieee80211n}"
128 print
"ignore_broadcast_ssid=${ignore_broadcast_ssid}"
130 if contains_spaces
"${ssid}"; then
131 print
"ssid=\"${ssid}\""
141 print
"# Control interface"
142 print
"ctrl_interface=${HOSTAPD_CONTROL_INTERFACE_DIR}"
143 print
"ctrl_interface_group=0"
147 # Encryption settings
148 if isset encryption
; then
149 local encryption_mode
=0
150 case "${encryption}" in
163 print
"# Encryption settings"
164 print
"wpa=${encryption_mode}"
165 print
"wpa_passphrase=${key}"
166 print
"wpa_key_mgmt=WPA-PSK"
167 print
"wpa_pairwise=TKIP"
168 print
"rsn_pairwise=CCMP"
176 function hostapd_start
() {
180 service_start
"hostapd@${device}.service"
183 if [ ${ret} -eq ${EXIT_OK} ]; then
184 log DEBUG
"hostapd has been successfully started on '${device}'"
186 log ERROR
"Could not start hostapd on '${device}': ${ret}"
193 function hostapd_stop
() {
197 service_stop
"hostapd@${device}.service"