]> git.ipfire.org Git - people/stevee/network.git/commitdiff
wireless: Try to automatically enable HT40+/- on devices that support it
authorMichael Tremer <michael.tremer@ipfire.org>
Sun, 23 Sep 2018 14:30:29 +0000 (16:30 +0200)
committerMichael Tremer <michael.tremer@ipfire.org>
Sun, 23 Sep 2018 14:30:29 +0000 (16:30 +0200)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/functions/functions.phy
src/functions/functions.wireless

index 76974fa860c46c2fc0766ad49f8436d5ea9842f9..96287a524de6141305728093184527af46502e29 100644 (file)
@@ -169,3 +169,22 @@ phy_supports_channel() {
 
        return ${EXIT_FALSE}
 }
+
+__phy_list_ht_capabilities() {
+       local phy="${1}"
+       assert isset phy
+
+       local capabilities="$(network-phy-list-ht-caps "${phy}")"
+
+       print "${capabilities//[\[\]]/ }"
+}
+
+phy_supports_ht_capability() {
+       local phy="${1}"
+       assert isset phy
+
+       local capability="${2}"
+       assert isset capability
+
+       list_match "${capability}" $(__phy_list_ht_capabilities "${phy}")
+}
index ba4cd472043b413696c93cf1bec010bd73a2ee5c..3608e1195c2c496bccdfdb9e83b918840a95b297 100644 (file)
@@ -111,7 +111,7 @@ wireless_create() {
 
        # Set the channel
        if isset channel; then
-               wireless_set_channel "${device}" "${channel}" || return $?
+               wireless_set_channel "${device}" "${channel}" "auto" || return $?
        fi
 
        return ${ret}
@@ -309,9 +309,34 @@ wireless_channel_is_valid() {
        return ${EXIT_FALSE}
 }
 
+wireless_channel_is_ht40_plus() {
+       local channel="${1}"
+       assert isinteger channel
+
+       # 2.4 GHz
+       if [ ${channel} -le 6 ]; then
+               return ${EXIT_TRUE}
+       fi
+
+       return ${EXIT_FALSE}
+}
+
+wireless_channel_is_ht40_minus() {
+       local channel="${1}"
+       assert isinteger channel
+
+       # 2.4 GHz
+       if [ ${channel} -ge 6 ]; then
+               return ${EXIT_TRUE}
+       fi
+
+       return ${EXIT_FALSE}
+}
+
 wireless_set_channel() {
-       local device=${1}
-       local channel=${2}
+       local device="${1}"
+       local channel="${2}"
+       local bandwidth="${3}"
 
        # Check if the device exists
        if ! device_exists "${device}"; then
@@ -325,8 +350,27 @@ wireless_set_channel() {
                return ${EXIT_ERROR}
        fi
 
+       local ht_flag
+       if [ "${bandwidth}" = "auto" ]; then
+               local phy="$(device_get_phy "${device}")"
+
+               # Offset of a 40 MHz channel
+               local ht_offset=5
+
+               if wireless_channel_is_ht40_plus "${channel}" \
+                               && phy_supports_ht_capability "${phy}" "HT40+" \
+                               && phy_supports_channel "${phy}" $(( channel + ht_offset )); then
+                       ht_flag="HT40+"
+
+               elif wireless_channel_is_ht40_minus "${channel}" \
+                               && phy_supports_ht_capability "${phy}" "HT40-" \
+                               && phy_supports_channel "${phy}" $(( channel - ht_offset )); then
+                       ht_flags="HT40-"
+               fi
+       fi
+
        log DEBUG "Setting wireless channel on device '${device}' to channel '${channel}'"
-       cmd iw dev "${device}" set channel "${channel}"
+       cmd iw dev "${device}" set channel "${channel}" "${ht_flag}"
 }
 
 wireless_pre_shared_key_is_valid() {