From: Michael Tremer Date: Thu, 21 Mar 2019 21:14:43 +0000 (+0100) Subject: wireless-ap: Allow setting the wireless environment (indoor/outdoor) X-Git-Url: http://git.ipfire.org/?p=people%2Fms%2Fnetwork.git;a=commitdiff_plain;h=7842c2ce43d1f185e65bb9f2beead96376e2bd34;ds=sidebyside wireless-ap: Allow setting the wireless environment (indoor/outdoor) Signed-off-by: Michael Tremer --- diff --git a/src/functions/functions.hostapd b/src/functions/functions.hostapd index 9024ab25..94b06db9 100644 --- a/src/functions/functions.hostapd +++ b/src/functions/functions.hostapd @@ -39,6 +39,7 @@ hostapd_config_write() { local country_code="$(wireless_get_reg_domain)" local dfs="on" local encryption + local environment="${WIRELESS_DEFAULT_ENVIRONMENT}" local key local mode local ssid @@ -61,6 +62,9 @@ hostapd_config_write() { --encryption=*) encryption=$(cli_get_val "${1}") ;; + --environment=*) + environment="$(cli_get_val "${1}")" + ;; --key=*) key=$(cli_get_val "${1}") ;; @@ -111,6 +115,12 @@ hostapd_config_write() { assert isset key fi + # Check wireless environment + if ! wireless_environment_is_valid "${environment}"; then + error "Invalid wireless environment: ${environment}" + return ${EXIT_ERROR} + 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}" @@ -208,6 +218,21 @@ hostapd_config_write() { # Advertise country code and maximum transmission power print "ieee80211d=1" + print "country_code=${country_code}" + + # Wireless Environment + case "${environment}" in + indoor) + print "country3=0x49" + country3 + ;; + outdoor) + print "country3=0x4f" + ;; + indoor+outdoor) + print "country3=0x20" + ;; + esac # Enable Radar Detection if enabled dfs && wireless_supports_dfs "${device}"; then @@ -230,7 +255,6 @@ hostapd_config_write() { fi print "channel=${channel}" - print "country_code=${country_code}" print "ignore_broadcast_ssid=${ignore_broadcast_ssid}" if contains_spaces "${ssid}"; then diff --git a/src/functions/functions.wireless b/src/functions/functions.wireless index 9e72fe0b..12204c07 100644 --- a/src/functions/functions.wireless +++ b/src/functions/functions.wireless @@ -37,6 +37,9 @@ declare -A WIRELESS_CHANNEL_BANDWIDTHS=( ["802.11g"]="20 40" ) +WIRELESS_ENVIRONMENTS=( "indoor+outdoor" "indoor" "outdoor" ) +WIRELESS_DEFAULT_ENVIRONMENT="${WIRELESS_ENVIRONMENTS[0]}" + cli_wireless() { local action=${1} shift 1 @@ -561,3 +564,9 @@ wireless_supports_dfs() { phy_supports_dfs "${phy}" } + +wireless_environment_is_valid() { + local environment="${1}" + + list_match "${environment}" "${WIRELESS_ENVIRONMENTS[@]}" +} diff --git a/src/helpers/hostapd-config-helper b/src/helpers/hostapd-config-helper index 8af3097f..d3292c3a 100644 --- a/src/helpers/hostapd-config-helper +++ b/src/helpers/hostapd-config-helper @@ -43,6 +43,7 @@ case "${action}" in --channel-bandwidth="${CHANNEL_BANDWIDTH}" \ --dfs="${DFS}" \ --encryption="${ENCRYPTION}" \ + --environment="${ENVIRONMENT}" \ --key="${KEY}" \ --mode="${MODE}" \ --ssid="${SSID}" \ diff --git a/src/hooks/ports/wireless-ap b/src/hooks/ports/wireless-ap index 0c42b61c..6db39b8c 100644 --- a/src/hooks/ports/wireless-ap +++ b/src/hooks/ports/wireless-ap @@ -24,7 +24,7 @@ HOOK_PORT_PATTERN="${PORT_PATTERN_ACCESSPOINT}" HOOK_SETTINGS="ADDRESS BROADCAST_SSID CHANNEL CHANNEL_BANDWIDTH DFS MODE PHY" -HOOK_SETTINGS="${HOOK_SETTINGS} ENCRYPTION KEY SSID" +HOOK_SETTINGS="${HOOK_SETTINGS} ENCRYPTION ENVIRONMENT KEY SSID" ADDRESS=$(mac_generate) BROADCAST_SSID=on @@ -37,6 +37,8 @@ SSID= # Perform radar detection by default when possible DFS="on" +ENVIRONMENT="${WIRELESS_DEFAULT_ENVIRONMENT}" + hook_check_settings() { assert isset ADDRESS assert ismac ADDRESS @@ -57,6 +59,8 @@ hook_check_settings() { assert [ ${#KEY} -ge 8 ] assert [ ${#KEY} -le 63 ] fi + + assert wireless_environment_is_valid "${ENVIRONMENT}" } hook_parse_cmdline() { @@ -86,6 +90,14 @@ hook_parse_cmdline() { --encryption=*) ENCRYPTION=$(cli_get_val "${1}") ;; + --environment=*) + ENVIRONMENT="$(cli_get_val "${1}")" + + if ! wireless_environment_is_valid "${ENVIRONMENT}"; then + error "Invalid wireless environment: ${ENVIRONMENT}" + return ${EXIT_ERROR} + fi + ;; --key=*) KEY=$(cli_get_val "${1}") ;;