]> git.ipfire.org Git - people/ms/network.git/blobdiff - src/functions/functions.hostapd
wireless-ap: Allow setting the wireless environment (indoor/outdoor)
[people/ms/network.git] / src / functions / functions.hostapd
index e19f9b3f16d34103d00c9b4dcc75227439313044..94b06db97561deb6cb80c09f12f831336aececba 100644 (file)
@@ -35,9 +35,11 @@ hostapd_config_write() {
 
        local broadcast_ssid
        local channel
+       local channel_bandwidth
        local country_code="$(wireless_get_reg_domain)"
        local dfs="on"
        local encryption
+       local environment="${WIRELESS_DEFAULT_ENVIRONMENT}"
        local key
        local mode
        local ssid
@@ -51,12 +53,18 @@ hostapd_config_write() {
                        --channel=*)
                                channel=$(cli_get_val "${1}")
                                ;;
+                       --channel-bandwidth=*)
+                               channel_bandwidth="$(cli_get_val "${1}")"
+                               ;;
                        --dfs=*)
                                dfs="$(cli_get_val "${1}")"
                                ;;
                        --encryption=*)
                                encryption=$(cli_get_val "${1}")
                                ;;
+                       --environment=*)
+                               environment="$(cli_get_val "${1}")"
+                               ;;
                        --key=*)
                                key=$(cli_get_val "${1}")
                                ;;
@@ -107,10 +115,29 @@ 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}"
+               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}"
+               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 +176,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
 
@@ -179,9 +218,24 @@ 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; then
+               if enabled dfs && wireless_supports_dfs "${device}"; then
                        print "ieee80211h=1"
                else
                        print "ieee80211h=0"
@@ -201,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
@@ -221,6 +274,9 @@ hostapd_config_write() {
                # Enable HT caps
                print "ht_capab=${ht_caps}"
 
+               # Wider Channels
+               print "vht_oper_chwidth=${vht_oper_chwidth}"
+
                print
        ) >> ${file}