X-Git-Url: http://git.ipfire.org/?a=blobdiff_plain;f=src%2Ffunctions%2Ffunctions.hostapd;h=57f8c1e4fc470803555f98f3f2a5f543904ac0cf;hb=f9e980d91e081613e5dcc7899c28fbdfc7a4c172;hp=433d172272d0799bfc7641283d9e23072b29f78c;hpb=0e1c630c8d5f4c1f831fb5c32203561e98cc3083;p=network.git diff --git a/src/functions/functions.hostapd b/src/functions/functions.hostapd index 433d1722..57f8c1e4 100644 --- a/src/functions/functions.hostapd +++ b/src/functions/functions.hostapd @@ -21,6 +21,8 @@ HOSTAPD_CONTROL_INTERFACE_DIR="/run/hostapd/ctrl" +HOSTAPD_SUPPORTED_MODES="802.11a 802.11a/n 802.11ac 802.11g 802.11g/n" + hostapd_config_write() { local device=${1} assert isset device @@ -33,9 +35,10 @@ hostapd_config_write() { local broadcast_ssid local channel + local channel_bandwidth local country_code="$(wireless_get_reg_domain)" + local dfs="on" local encryption - local ieee80211d="1" local key local mode local ssid @@ -49,22 +52,25 @@ 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}") ;; - --ieee80211d=*) - local val="$(cli_get_val "${1}")" - if enabled val; then - ieee80211d="1" - else - ieee80211d="0" - fi - ;; --key=*) key=$(cli_get_val "${1}") ;; --mode=*) mode=$(cli_get_val "${1}") + + if ! isoneof mode ${HOSTAPD_SUPPORTED_MODES}; then + error "Unsupported mode: ${mode}" + return ${EXIT_ERROR} + fi ;; --ssid=*) ssid=$(cli_get_val "${1}") @@ -84,6 +90,12 @@ hostapd_config_write() { shift done + # Check if mode is set + if ! isset mode; then + error "Mode is not set" + return ${EXIT_ERROR} + fi + assert isset broadcast_ssid assert isbool broadcast_ssid @@ -99,8 +111,69 @@ hostapd_config_write() { assert isset key fi - # Get HT caps - local ht_caps="$(wireless_get_ht_caps "${device}")" + # 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 + case "${mode}" in + 802.11a) + hw_mode="a" + ;; + + 802.11a/n) + hw_mode="a" + ieee80211n="1" + + # Fetch HT caps + ht_caps="$(wireless_get_ht_caps "${device}")" + ;; + + 802.11g) + hw_mode="g" + ;; + + 802.11g/n) + hw_mode="g" + ieee80211n="1" + + # Fetch HT caps + ht_caps="$(wireless_get_ht_caps "${device}")" + ;; + + 802.11ac) + hw_mode="a" + ieee80211ac="1" + ieee80211n="1" + + # Fetch VHT caps + vht_caps="$(wireless_get_vht_caps "${device}")" + + # 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 # Create configuration directory. local config_dir=$(dirname ${file}) @@ -124,25 +197,34 @@ hostapd_config_write() { ignore_broadcast_ssid="1" fi - local hw_mode ieee80211n="0" - if [ "${mode}" = "n" ]; then - if [ ${channel} -le 15 ]; then - hw_mode="g" + ( + print "# Default settings" + + # Advertise country code and maximum transmission power + print "ieee80211d=1" + + # Enable Radar Detection + if enabled dfs && wireless_supports_dfs "${device}"; then + print "ieee80211h=1" else - hw_mode="a" + print "ieee80211h=0" fi - ieee80211n="1" - else - hw_mode="${mode}" - fi - ( + print # empty line + print "# Wireless configuration" + print "hw_mode=${hw_mode}" + + if isset ieee80211ac; then + print "ieee80211ac=${ieee80211ac}" + fi + + if isset ieee80211n; then + print "ieee80211n=${ieee80211n}" + fi + print "channel=${channel}" print "country_code=${country_code}" - print "hw_mode=${hw_mode}" - print "ieee80211d=${ieee80211d}" - print "ieee80211n=${ieee80211n}" print "ignore_broadcast_ssid=${ignore_broadcast_ssid}" if contains_spaces "${ssid}"; then @@ -154,9 +236,17 @@ hostapd_config_write() { # WMM print "wmm_enabled=${wmm}" + # Enable VHT caps + if isset vht_caps; then + print "vht_capab=${vht_caps}" + fi + # Enable HT caps print "ht_capab=${ht_caps}" + # Wider Channels + print "vht_oper_chwidth=${vht_oper_chwidth}" + print ) >> ${file}