hostapd: Apply channel bandwidth to configuration
authorMichael Tremer <michael.tremer@ipfire.org>
Mon, 18 Mar 2019 20:24:02 +0000 (21:24 +0100)
committerMichael Tremer <michael.tremer@ipfire.org>
Mon, 18 Mar 2019 20:24:02 +0000 (21:24 +0100)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/functions/functions.hostapd
src/helpers/hostapd-config-helper
src/hooks/ports/wireless-ap

index b855994..57f8c1e 100644 (file)
@@ -35,6 +35,7 @@ hostapd_config_write() {
 
        local broadcast_ssid
        local channel
+       local channel_bandwidth
        local country_code="$(wireless_get_reg_domain)"
        local dfs="on"
        local encryption
@@ -51,6 +52,9 @@ hostapd_config_write() {
                        --channel=*)
                                channel=$(cli_get_val "${1}")
                                ;;
+                       --channel-bandwidth=*)
+                               channel_bandwidth="$(cli_get_val "${1}")"
+                               ;;
                        --dfs=*)
                                dfs="$(cli_get_val "${1}")"
                                ;;
@@ -107,10 +111,17 @@ hostapd_config_write() {
                assert isset key
        fi
 
+       # Check channel bandwidth for validity
+       if isset channel_bandwidth && ! wireless_channel_bandwidth_is_valid "${mode}" "${channel_bandwidth}"; then
+               error "Invalid channel bandwidth for ${mode}: ${channel_bandwidth}"
+               return ${EXIT_ERROR}
+       fi
+
        # 802.11ac/n flags
        local ieee80211ac
        local ieee80211n
        local vht_caps
+       local vht_oper_chwidth="0"
        local ht_caps
 
        local hw_mode
@@ -149,6 +160,18 @@ hostapd_config_write() {
 
                        # Fetch HT caps
                        ht_caps="$(wireless_get_ht_caps "${device}")"
+
+                       case "${channel_bandwidth}" in
+                               80)
+                                       vht_oper_chwidth="1"
+                                       ;;
+                               160)
+                                       vht_oper_chwidth="2"
+                                       ;;
+                               80+80)
+                                       vht_oper_chwidth="3"
+                                       ;;
+                       esac
                        ;;
        esac
 
@@ -221,6 +244,9 @@ hostapd_config_write() {
                # Enable HT caps
                print "ht_capab=${ht_caps}"
 
+               # Wider Channels
+               print "vht_oper_chwidth=${vht_oper_chwidth}"
+
                print
        ) >> ${file}
 
index 30d3456..8af3097 100644 (file)
@@ -40,6 +40,7 @@ case "${action}" in
                hostapd_config_write ${port} ${config_file} \
                        --broadcast-ssid="${BROADCAST_SSID}" \
                        --channel="${CHANNEL}" \
+                       --channel-bandwidth="${CHANNEL_BANDWIDTH}" \
                        --dfs="${DFS}" \
                        --encryption="${ENCRYPTION}" \
                        --key="${KEY}" \
index 5e00014..983f0f9 100644 (file)
@@ -127,7 +127,7 @@ hook_parse_cmdline() {
 
        # 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"
+               error "Channel Bandwidth '${CHANNEL_BANDWIDTH}' is not supported for ${MODE}"
                return ${EXIT_ERROR}
        fi