]> git.ipfire.org Git - people/stevee/network.git/blobdiff - hooks/ports/wireless-ap
route: Allow to specify MTU along the path to the destination.
[people/stevee/network.git] / hooks / ports / wireless-ap
index 7ff695263735d3890248685857d4c5c1991400ef..391e682800257520c6b13dba49cc00658abbef67 100755 (executable)
 . /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=
 
@@ -38,10 +41,18 @@ function _check() {
        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() {
@@ -56,6 +67,12 @@ 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})
                                ;;
@@ -106,6 +123,12 @@ function _edit() {
                        --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})
                                ;;
@@ -126,30 +149,30 @@ function _edit() {
 
 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}
@@ -159,8 +182,6 @@ function _down() {
        local port=${1}
        assert isset port
 
-       config_read $(port_file ${port})
-
        # Stop the hostapd daemon.
        hostapd_stop ${port}
 
@@ -174,10 +195,11 @@ function _down() {
 
 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.
@@ -189,7 +211,8 @@ function _hotplug() {
        # 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}