# #
###############################################################################
-function hostapd_config_dir() {
- local device=${1}
-
- echo "${RUN_DIR}/hostapd/${device}"
-}
+HOSTAPD_CONTROL_INTERFACE_DIR="/run/hostapd/ctrl"
function hostapd_config_write() {
local device=${1}
- shift
+ assert isset device
- assert device_exists ${device}
+ local file=${2}
+ assert isset file
+
+ # Shift the device and file argument.
+ shift 2
local broadcast_ssid
local channel
while [ $# -gt 0 ]; do
case "${1}" in
--broadcast-ssid=*)
- broadcast_ssid=${1#--broadcast-ssid=}
+ broadcast_ssid=$(cli_get_val ${1})
;;
--channel=*)
- channel=${1#--channel=}
+ channel=$(cli_get_val ${1})
;;
--country-code=*)
- country_code=${1#--country-code=}
+ country_code=$(cli_get_val ${1})
;;
--mode=*)
- mode=${1#--mode=}
+ mode=$(cli_get_val ${1})
;;
--ssid=*)
- ssid=${1#--ssid=}
+ ssid=$(cli_get_val ${1})
;;
--encryption=*)
encryption=$(cli_get_val ${1})
assert isset key
fi
+ # Create configuration directory.
+ local config_dir=$(dirname ${file})
+ mkdir -p ${HOSTAPD_CONTROL_INTERFACE_DIR} ${config_dir} 2>/dev/null
+
+ config_header "hostapd" > ${file}
+
+ # Interface configuration
+ (
+ print "# Interface configuration"
+ print "driver=nl80211"
+ print "interface=${device}"
+ print
+ ) >> ${file}
+
+ # Wireless configuration
local ignore_broadcast_ssid
if enabled broadcast_ssid; then
ignore_broadcast_ssid="0"
hw_mode="${mode}"
fi
- cat <<EOF
-### Hostapd configuration for ${device}
-
-# Interface configuration
-driver=nl80211
-interface=${device}
+ (
+ print "# Wireless configuration"
+ print "channel=${channel}"
+ print "country_code=${country_code}"
+ print "hw_mode=${hw_mode}"
+ print "ieee80211n=${ieee80211n}"
+ print "ignore_broadcast_ssid=${ignore_broadcast_ssid}"
-# Wireless configuration
-channel=${channel}
-country_code=${country_code}
-hw_mode=${hw_mode}
-ieee80211n=${ieee80211n}
-ignore_broadcast_ssid=${ignore_broadcast_ssid}
-ssid=${ssid}
-
-# Dump file
-dump_file=$(hostapd_config_dir ${device}/dump)
+ if contains_spaces "${ssid}"; then
+ print "ssid=\"${ssid}\""
+ else
+ print "ssid=${ssid}"
+ fi
-ctrl_interface=/var/run/hostapd
-ctrl_interface_group=0
+ print
+ ) >> ${file}
-EOF
+ # Control interface.
+ (
+ print "# Control interface"
+ print "ctrl_interface=${HOSTAPD_CONTROL_INTERFACE_DIR}"
+ print "ctrl_interface_group=0"
+ print
+ ) >> ${file}
+ # Encryption settings
if isset encryption; then
local encryption_mode=0
case "${encryption}" in
;;
esac
- print "# Encryption settings."
- print "wpa=${encryption_mode}"
- print "wpa_passphrase=${key}"
- print "wpa_key_mgmt=WPA-PSK"
- print "wpa_pairwise=TKIP"
- print "rsn_pairwise=CCMP"
- print
+ (
+ print "# Encryption settings"
+ print "wpa=${encryption_mode}"
+ print "wpa_passphrase=${key}"
+ print "wpa_key_mgmt=WPA-PSK"
+ print "wpa_pairwise=TKIP"
+ print "rsn_pairwise=CCMP"
+ print
+ ) >> ${file}
fi
return ${EXIT_OK}
function hostapd_start() {
local device=${1}
- shift
-
assert isset device
- local config_dir=$(hostapd_config_dir ${device})
- mkdir -p ${config_dir}
-
- local config_file=${config_dir}/config
- hostapd_config_write ${device} $@ > ${config_file}
-
service_start "hostapd@${device}.service"
local ret=$?
- case "${ret}" in
- 0)
- log DEBUG "Hostapd was successfully started for '${device}'."
- return ${EXIT_OK}
- ;;
- 1)
- error_log "Could not start hostapd properly for '${device}'."
-
- error_log "Configuration file dump:"
- local line
- while read line; do
- error_log " ${line}"
- done < ${config_file}
-
- return ${EXIT_ERROR}
- ;;
- esac
+ if [ ${ret} -eq ${EXIT_OK} ]; then
+ log DEBUG "hostapd has been successfully started on '${device}'"
+ else
+ log ERROR "Could not start hostapd on '${device}': ${ret}"
+ return ${EXIT_ERROR}
+ fi
+
+ return ${EXIT_OK}
}
function hostapd_stop() {
assert isset device
service_stop "hostapd@${device}.service"
-
- rm -rf $(hostapd_config_dir ${device})
}
--- /dev/null
+#!/bin/bash
+###############################################################################
+# #
+# IPFire.org - A linux based firewall #
+# Copyright (C) 2012 IPFire Network Development Team #
+# #
+# This program is free software: you can redistribute it and/or modify #
+# it under the terms of the GNU General Public License as published by #
+# the Free Software Foundation, either version 3 of the License, or #
+# (at your option) any later version. #
+# #
+# This program is distributed in the hope that it will be useful, #
+# but WITHOUT ANY WARRANTY; without even the implied warranty of #
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the #
+# GNU General Public License for more details. #
+# #
+# You should have received a copy of the GNU General Public License #
+# along with this program. If not, see <http://www.gnu.org/licenses/>. #
+# #
+###############################################################################
+
+. /usr/lib/network/functions
+
+action="${1}"
+assert isset action
+
+port="${2}"
+assert isset port
+
+config_file="$(port_config_dir ${port})/hostapd.conf"
+
+case "${action}" in
+ create)
+ # Create the configuration file for this port.
+ port_config_read ${port} || exit $?
+
+ hostapd_config_write ${port} ${config_file} \
+ --broadcast-ssid="${BROADCAST_SSID}" \
+ --channel="${CHANNEL}" \
+ --country-code="${COUNTRY_CODE}" \
+ --encryption="${ENCRYPTION}" \
+ --key="${KEY}" \
+ --mode="${MODE}" \
+ --ssid="${SSID}" \
+ || exit $?
+ ;;
+
+ remove)
+ rm -f ${config_file}
+ ;;
+
+ *)
+ log ERROR "Unknown action passed: ${action}"
+ exit ${EXIT_ERROR}
+ ;;
+esac
+
+exit ${EXIT_OK}
config_read $(port_file ${port})
+ # Check if the PHY is present.
+ local phy=$(phy_get ${PHY})
+ if ! isset phy; then
+ log DEBUG "phy '${PHY}' is not present"
+ exit ${EXIT_ERROR}
+ fi
+
+ # Create the wireless device, if it does not exist, yet.
if ! device_exists ${port}; then
- wireless_create ${port} ${PHY} __ap ${ADDRESS}
+ wireless_create ${port} --phy="${phy}" --type="ap" \
+ --address="${ADDRESS}"
fi
- if ! hostapd_is_running ${port}; then
- hostapd_start ${port} \
- --broadcast-ssid="${BROADCAST_SSID}" \
- --channel="${CHANNEL}" \
- --country-code="${COUNTRY_CODE}" \
- --encryption="${ENCRYPTION}" \
- --key="${KEY}" \
- --mode="${MODE}" \
- --ssid="${SSID}"
-
- local ret=$?
-
- if [ ${ret} -eq ${EXIT_ERROR} ]; then
- error_log "Could not start '${port}' because hostapd crashed previously."
- ( _down ${port} )
- exit ${EXIT_ERROR}
- fi
+ # Start the hostapd service.
+ hostapd_start ${port}
+ local ret=$?
+
+ if [ ${ret} -ne ${EXIT_OK} ]; then
+ log ERROR "Could not start hostapd on port '${port}': ${ret}"
+ exit ${EXIT_ERROR}
fi
exit ${EXIT_OK}
local port=${1}
assert isset port
- config_read $(port_file ${port})
-
# Stop the hostapd daemon.
hostapd_stop ${port}
function _hotplug() {
local port=${1}
- local phy=${2}
-
assert isset port
+
+ local phy=${2}
assert isset phy
+
assert port_exists ${port}
# Read configuration of port.
# Check if the phy is the same we have
# read from the configuration file.
if [ "${PHY}" = "${phy_address}" ]; then
- wireless_create ${port} ${PHY} __ap ${ADDRESS}
+ wireless_create ${port} --phy="${phy_address}" --type="ap" \
+ --address="${ADDRESS}"
fi
exit ${EXIT_OK}