# #
###############################################################################
-. /lib/network/header-port
-
-DEVICE_PATTERN="apN"
+. /usr/lib/network/header-port
HOOK_SETTINGS="HOOK ADDRESS BROADCAST_SSID CHANNEL COUNTRY_CODE MODE PHY SSID"
+HOOK_SETTINGS="${HOOK_SETTINGS} ENCRYPTION KEY"
ADDRESS=$(mac_generate)
BROADCAST_SSID=on
CHANNEL=1
COUNTRY_CODE="US"
+ENCRYPTION=""
+KEY=""
MODE="g"
SSID=
assert isset CHANNEL
assert isset COUNTRY_CODE
assert isset MODE
- assert isoneof MODE b g
+ assert isoneof MODE a b g n
assert isset PHY
assert ismac PHY
assert isset SSID
+
+ if isset ENCRYPTION; then
+ assert isoneof ENCRYPTION WPA WPA2 WPA/WPA2
+
+ assert isset KEY
+ assert [ ${#KEY} -ge 8 ]
+ assert [ ${#KEY} -le 63 ]
+ fi
}
function _create() {
--country-code=*)
COUNTRY_CODE=$(cli_get_val ${1})
;;
+ --encryption=*)
+ ENCRYPTION=$(cli_get_val ${1})
+ ;;
+ --key=*)
+ KEY=$(cli_get_val ${1})
+ ;;
--mac=*)
ADDRESS=$(cli_get_val ${1})
;;
PHY=$(phy_get ${PHY})
PHY=$(phy_get_address ${PHY})
- local port=$(port_find_free ${DEVICE_PATTERN})
+ local port=$(port_find_free ${PORT_PATTERN_ACCESSPOINT})
assert isset port
config_write $(port_file ${port}) ${HOOK_SETTINGS}
--country-code=*)
COUNTRY_CODE=$(cli_get_val ${1})
;;
+ --encryption=*)
+ ENCRYPTION=$(cli_get_val ${1})
+ ;;
+ --key=*)
+ KEY=$(cli_get_val ${1})
+ ;;
--ssid=*)
SSID=$(cli_get_val ${1})
;;
function _up() {
local port=${1}
-
assert isset port
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}" \
- --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}
function _down() {
local port=${1}
-
assert isset port
- config_read $(port_file ${port})
+ # Stop the hostapd daemon.
+ hostapd_stop ${port}
- if ! device_exists ${port}; then
- exit ${EXIT_OK}
+ # Remove the device if it is still present.
+ if device_exists ${port}; then
+ wireless_remove ${port}
fi
- hostapd_stop ${port}
- wireless_remove ${port}
-
exit ${EXIT_OK}
}
-function _status() {
- local zone=${1}
- local port=${2}
+function _hotplug() {
+ local port=${1}
+ assert isset port
+
+ local phy=${2}
+ assert isset phy
+
+ assert port_exists ${port}
-config_read $(zone_dir ${zone})/${port}
+ # Read configuration of port.
+ config_read $(port_file ${port})
- local device=$(devicify ${DEVICE_MAC})
+ # Get the address of the phy.
+ local phy_address=$(phy_get_address ${phy})
- printf " %-10s - " "${device}"
- if ! device_is_up ${device}; then
- echo -ne "${COLOUR_DOWN} DOWN ${COLOUR_NORMAL}"
- else
- local state=$(stp_port_state ${zone} ${device})
- local colour="COLOUR_STP_${state}"
- printf "${!colour}%10s${COLOUR_NORMAL}" ${state}
+ # Check if the phy is the same we have
+ # read from the configuration file.
+ if [ "${PHY}" = "${phy_address}" ]; then
+ wireless_create ${port} --phy="${phy_address}" --type="ap" \
+ --address="${ADDRESS}"
fi
- echo -n " - DSR: $(stp_port_designated_root ${zone} ${device})"
- echo -n " - Cost: $(stp_port_pathcost ${zone} ${device})"
- echo
-
exit ${EXIT_OK}
}
-
-run $@