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
108 ### Hostapd configuration for ${device}
110 # Interface configuration
114 # Wireless configuration
116 country_code=${country_code}
118 ieee80211n=${ieee80211n}
119 ignore_broadcast_ssid=${ignore_broadcast_ssid}
123 dump_file=$(hostapd_config_dir ${device}/dump)
125 ctrl_interface=/var/run/hostapd
126 ctrl_interface_group=0
130 if isset encryption
; then
131 local encryption_mode
=0
132 case "${encryption}" in
144 print
"# Encryption settings."
145 print
"wpa=${encryption_mode}"
146 print
"wpa_passphrase=${key}"
147 print
"wpa_key_mgmt=WPA-PSK"
148 print
"wpa_pairwise=TKIP"
149 print
"rsn_pairwise=CCMP"
156 function hostapd_start
() {
162 local config_dir
=$
(hostapd_config_dir
${device})
163 mkdir
-p ${config_dir}
165 local config_file
=${config_dir}/config
166 hostapd_config_write
${device} $@
> ${config_file}
168 service_start
"hostapd@${device}.service"
173 log DEBUG
"Hostapd was successfully started for '${device}'."
177 error_log
"Could not start hostapd properly for '${device}'."
179 error_log
"Configuration file dump:"
183 done < ${config_file}
190 function hostapd_stop
() {
194 service_stop
"hostapd@${device}.service"
196 rm -rf $
(hostapd_config_dir
${device})