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 function hostapd_config_dir
() {
25 echo "${RUN_DIR}/hostapd/${device}"
28 function hostapd_config_write
() {
32 assert device_exists
${device}
42 while [ $# -gt 0 ]; do
45 broadcast_ssid
=${1#--broadcast-ssid=}
48 channel
=${1#--channel=}
51 country_code
=${1#--country-code=}
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 local ignore_broadcast_ssid
89 if enabled broadcast_ssid
; then
90 ignore_broadcast_ssid
="0"
92 ignore_broadcast_ssid
="1"
95 local hw_mode ieee80211n
="0"
96 if [ "${mode}" = "n" ]; then
97 if [ ${channel} -le 15 ]; then
106 ### Hostapd configuration for ${device}
108 # Interface configuration
112 # Wireless configuration
114 country_code=${country_code}
116 ieee80211n=${ieee80211n}
117 ignore_broadcast_ssid=${ignore_broadcast_ssid}
121 dump_file=$(hostapd_config_dir ${device}/dump)
123 ctrl_interface=/var/run/hostapd
124 ctrl_interface_group=0
128 if isset encryption
; then
129 local encryption_mode
=0
130 case "${encryption}" in
142 print
"# Encryption settings."
143 print
"wpa=${encryption_mode}"
144 print
"wpa_passphrase=${key}"
145 print
"wpa_key_mgmt=WPA-PSK"
146 print
"wpa_pairwise=TKIP"
147 print
"rsn_pairwise=CCMP"
154 function hostapd_start
() {
160 local config_dir
=$
(hostapd_config_dir
${device})
161 mkdir
-p ${config_dir}
163 local config_file
=${config_dir}/config
164 hostapd_config_write
${device} $@
> ${config_file}
166 service_start
"hostapd@${device}.service"
171 log DEBUG
"Hostapd was successfully started for '${device}'."
175 error_log
"Could not start hostapd properly for '${device}'."
177 error_log
"Configuration file dump:"
181 done < ${config_file}
188 function hostapd_stop
() {
192 service_stop
"hostapd@${device}.service"
194 rm -rf $
(hostapd_config_dir
${device})
197 function hostapd_get_pid
() {
202 local pid_file
="$(hostapd_config_dir ${device})/pid"
204 [ -e "${pid_file}" ] ||
return ${EXIT_ERROR}
206 cat ${pid_file} 2>/dev
/null
210 function hostapd_is_running
() {
215 local pid
=$
(hostapd_get_pid
${device})
217 if isset pid
&& [ -d "/proc/${pid}" ]; then