From 1b4aa2ca01c5d0bd45213187e6a58b4cc0f57547 Mon Sep 17 00:00:00 2001 From: Michael Tremer Date: Thu, 21 Mar 2019 20:22:56 +0100 Subject: [PATCH] wireless-ap: Enable ACS only for ath* devices Signed-off-by: Michael Tremer --- src/functions/functions.hostapd | 6 ++++++ src/functions/functions.phy | 22 ++++++++++++++++++++++ src/functions/functions.wireless | 13 +++++++++++++ src/hooks/ports/wireless-ap | 9 ++++++++- 4 files changed, 49 insertions(+), 1 deletion(-) diff --git a/src/functions/functions.hostapd b/src/functions/functions.hostapd index 57f8c1e4..9024ab25 100644 --- a/src/functions/functions.hostapd +++ b/src/functions/functions.hostapd @@ -111,6 +111,12 @@ hostapd_config_write() { assert isset key fi + # With channel 0, ACS must be supported + if [ ${channel} -eq 0 ] && ! wireless_supports_acs "${device}"; then + error "ACS requested, but not supported by ${device}" + return ${EXIT_ERROR} + 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}" diff --git a/src/functions/functions.phy b/src/functions/functions.phy index 064ca7b6..ee0f2a2e 100644 --- a/src/functions/functions.phy +++ b/src/functions/functions.phy @@ -189,6 +189,28 @@ phy_supports_ht_capability() { list_match "${capability}" $(__phy_list_ht_capabilities "${phy}") } +# Returns TRUE if the PHY supports ACS +phy_supports_acs() { + local phy="${1}" + assert isset phy + + local driver="$(phy_get_driver "${phy}")" + if ! isset driver; then + return ${EXIT_ERROR} + fi + + # This is basically a whilelist of drivers which support this + # There is no better detection + case "${driver}" in + ath10k_*|ath9k|ath5k) + return ${EXIT_TRUE} + ;; + *) + return ${EXIT_FALSE} + ;; + esac +} + # Returns TRUE if the PHY supports DFS phy_supports_dfs() { local phy="${1}" diff --git a/src/functions/functions.wireless b/src/functions/functions.wireless index 0437d27b..9e72fe0b 100644 --- a/src/functions/functions.wireless +++ b/src/functions/functions.wireless @@ -536,6 +536,19 @@ wireless_get_vht_caps() { network-phy-list-vht-caps "${phy}" } +wireless_supports_acs() { + local device="${1}" + assert isset device + + local phy="$(device_get_phy "${device}")" + if ! isset phy; then + log ERROR "Could not determine PHY for ${device}" + return ${EXIT_ERROR} + fi + + phy_supports_acs "${phy}" +} + wireless_supports_dfs() { local device="${1}" assert isset device diff --git a/src/hooks/ports/wireless-ap b/src/hooks/ports/wireless-ap index 983f0f97..0c42b61c 100644 --- a/src/hooks/ports/wireless-ap +++ b/src/hooks/ports/wireless-ap @@ -28,7 +28,7 @@ HOOK_SETTINGS="${HOOK_SETTINGS} ENCRYPTION KEY SSID" ADDRESS=$(mac_generate) BROADCAST_SSID=on -CHANNEL=0 +CHANNEL= CHANNEL_BANDWIDTH= ENCRYPTION="" KEY="" @@ -125,6 +125,13 @@ hook_parse_cmdline() { return ${EXIT_ERROR} fi + # Automatically enable ACS if no channel is set and ACS is available + if ! isset CHANNEL && phy_supports_acs "${PHY}"; then + CHANNEL="0" + + log INFO "Automatic Channel Selection (ACS) enabled" + 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 for ${MODE}" -- 2.39.2