2 ###############################################################################
4 # IPFire.org - A linux based firewall #
5 # Copyright (C) 2010 Michael Tremer & Christian Schmidt #
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 PHY_DIR
="/sys/class/ieee80211"
27 echo "${PHY_DIR}/${phy}"
30 function phy_exists
() {
33 [ -d "$(phy_dir ${phy})" ]
38 for phy
in $
(phy_dir
)/*; do
39 phy
=$
(basename ${phy})
49 if listmatch
${info} $
(phy_list
); then
51 elif device_exists
${info}; then
52 info
=$
(device_get_address
${info})
55 if [ -z "${phy}" ] && mac_is_valid
${info}; then
57 for i
in $
(phy_list
); do
58 if [ "${info}" = "$(phy_get_address ${i})" ]; then
65 if [ -z "${phy}" ]; then
73 function phy_get_address
() {
78 cat $
(phy_dir
${phy})/macaddress
2>/dev
/null
81 function wireless_create
() {
83 local phy
=$
(phy_get
${2})
91 isset mac || mac
=$
(mac_generate
)
93 assert phy_exists
${phy}
94 assert isoneof
type managed __ap
96 iw phy
${phy} interface add ${device} type ${type}
98 if device_exists
${device}; then
99 device_set_address
${device} ${mac}
102 device_set_up
${device}
105 function wireless_remove
() {
108 assert device_exists
${device}
110 device_set_down
${device}
115 function wireless_set_channel
() {
120 assert device_exists
${device}
123 iw dev
${device} set channel
${channel} $@
126 function hostapd_init
() {
127 mkdir
-p $
(hostapd_config_dir
)
130 init_register hostapd_init
132 function hostapd_config_dir
() {
135 echo "${RUN_DIR}/hostapd/${device}"
138 function hostapd_config_write
() {
142 assert device_exists
${device}
150 while [ $# -gt 0 ]; do
153 broadcast_ssid
=${1#--broadcast-ssid=}
156 channel
=${1#--channel=}
159 country_code
=${1#--country-code=}
168 warning_log
"Ignoring unknown argument '${1}'."
174 assert isset broadcast_ssid
175 assert isbool broadcast_ssid
178 assert isinteger channel
180 assert isset country_code
184 local ignore_broadcast_ssid
185 if enabled broadcast_ssid
; then
186 ignore_broadcast_ssid
="0"
188 ignore_broadcast_ssid
="1"
192 ### Hostapd configuration for ${device}
194 # Interface configuration
198 # Wireless configuration
200 country_code=${country_code}
202 ignore_broadcast_ssid=${ignore_broadcast_ssid}
207 logger_syslog_level=2
209 logger_stdout_level=2
212 dump_file=$(hostapd_config_dir ${device}/dump
214 ctrl_interface=/var/run/hostapd
215 ctrl_interface_group=0
221 function hostapd_start
() {
227 local config_dir
=$
(hostapd_config_dir
${device})
228 mkdir
-p ${config_dir}
230 local config_file
=${config_dir}/config
231 hostapd_config_write
${device} $@
> ${config_file}
233 hostapd
-dd -B -P ${config_dir}/pid
${config_file}
238 log DEBUG
"Hostapd was successfully started for '${device}'."
242 error_log
"Could not start hostapd properly for '${device}'."
244 error_log
"Configuration file dump:"
248 done < ${config_file}
255 function hostapd_stop
() {
260 local pid
=$
(hostapd_get_pid
${device})
265 warning_log
"Could not find pid file for hostapd process running for ${device}."
268 rm -rf $
(hostapd_config_dir
${device})
271 function hostapd_get_pid
() {
276 local pid_file
="$(hostapd_config_dir ${device})/pid"
278 [ -e "${pid_file}" ] ||
return ${EXIT_ERROR}
280 cat ${pid_file} 2>/dev
/null
284 function hostapd_is_running
() {
289 local pid
=$
(hostapd_get_pid
${device})
291 if isset pid
&& [ -d "/proc/${pid}" ]; then