wireless-ap: Add CLI to set channel bandwidth
authorMichael Tremer <michael.tremer@ipfire.org>
Mon, 18 Mar 2019 19:50:44 +0000 (20:50 +0100)
committerMichael Tremer <michael.tremer@ipfire.org>
Mon, 18 Mar 2019 19:50:44 +0000 (20:50 +0100)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/functions/functions.wireless
src/hooks/ports/wireless-ap

index 221866e..0437d27 100644 (file)
@@ -29,6 +29,14 @@ WIRELESS_DEFAULT_ENCRYPTION_MODE="NONE"
 WIRELESS_VALID_ENCRYPTION_MODES="WPA2-PSK-SHA256 WPA2-PSK \
        WPA-PSK-SHA256 WPA-PSK NONE"
 
+declare -A WIRELESS_CHANNEL_BANDWIDTHS=(
+       ["802.11ac"]="20 40 80 160 80+80"
+       ["802.11a/n"]="20 40"
+       ["802.11a"]="20 40"
+       ["802.11g/n"]="20 40"
+       ["802.11g"]="20 40"
+)
+
 cli_wireless() {
        local action=${1}
        shift 1
@@ -309,6 +317,18 @@ wireless_channel_is_valid() {
        return ${EXIT_FALSE}
 }
 
+wireless_channel_bandwidth_is_valid() {
+       local mode="${1}"
+       assert isset mode
+
+       local bandwidth="${2}"
+       assert isset bandwidth
+
+       local bandwidths="${WIRELESS_CHANNEL_BANDWIDTHS["${mode}"]}"
+
+       list_match "${bandwidth}" ${bandwidths}
+}
+
 wireless_channel_is_ht40_plus() {
        local channel="${1}"
        assert isinteger channel
index 49c0a84..8b626bf 100644 (file)
@@ -29,6 +29,7 @@ HOOK_SETTINGS="${HOOK_SETTINGS} ENCRYPTION KEY"
 ADDRESS=$(mac_generate)
 BROADCAST_SSID=on
 CHANNEL=0
+CHANNEL_BANDWIDTH=
 ENCRYPTION=""
 KEY=""
 SSID=
@@ -67,6 +68,9 @@ hook_parse_cmdline() {
                        --channel=*)
                                CHANNEL=$(cli_get_val "${1}")
                                ;;
+                       --channel-bandwidth=*)
+                               CHANNEL_BANDWIDTH="$(cli_get_val "${1}")"
+                               ;;
                        --dfs=*)
                                DFS="$(cli_get_val "${1}")"
 
@@ -121,6 +125,12 @@ hook_parse_cmdline() {
                return ${EXIT_ERROR}
        fi
 
+       # Channel bandwidth must match the mode
+       if isset CHANNEL_BANDWIDTH && ! wireless_channel_bandwidth_is_valid "${MODE}" "${CHANNEL_BANDWIDTH}"; then
+               error "Channel Bandwidth '${CHANNEL_BANDWIDTH}' is not supported"
+               return ${EXIT_ERROR}
+       fi
+
        # Save address of phy do identify it again
        PHY=$(phy_get ${PHY})
        PHY=$(phy_get_address ${PHY})