[OpenWrt-Devel] [PATCH] mac80211: Select better ch/VHT for sub-band radios

Jeff Kletsky lede at allycomm.com
Thu Mar 21 16:31:15 EDT 2019


From: Jeff Kletsky <git-commits at allycomm.com>

Certain wireless devices have limitations on the channels
on which they can operate. For some of these devices,
the present default of ch. 36 (VHT80) is outside of the
capabilities of the device.

For 5 GHz, provide a default of the first non-disabled channel
returned by `iw phy $phy info`. For VHT-capable devices,
Select VHT20 if that channel may  not be "clear" for either
VHT40 or VHT80 due to either band edges or DFS restrictions.

Based on hostap src/common/hw_features_common.c

VHT80: 36, 52, 100, 116, 132, 149
VHT40: 44, 60, 108, 124, 140, 157, 165, 184, 192

Adding in band edges, DFS, and limited-use bands reduces this to:

VHT80: 36, 149
VHT40: 44, 157

Runtime-tested: TP-Link Archer C7v2, GL.iNet AR750S
Runtime-tested: Linksys EA8300 (QCA9888; ch. 100 and above only)

Signed-off-by: Jeff Kletsky <git-commits at allycomm.com>
---
 package/kernel/mac80211/files/lib/wifi/mac80211.sh | 42 ++++++++++++++++++----
 1 file changed, 36 insertions(+), 6 deletions(-)
 mode change 100644 => 100755 package/kernel/mac80211/files/lib/wifi/mac80211.sh

diff --git a/package/kernel/mac80211/files/lib/wifi/mac80211.sh b/package/kernel/mac80211/files/lib/wifi/mac80211.sh
old mode 100644
new mode 100755
index 511a9188db..368973eea4
--- a/package/kernel/mac80211/files/lib/wifi/mac80211.sh
+++ b/package/kernel/mac80211/files/lib/wifi/mac80211.sh
@@ -59,8 +59,12 @@ check_mac80211_device() {
 }
 
 detect_mac80211() {
-	devidx=0
+	local iw_phy_info
+
 	config_load wireless
+
+	devidx=0
+
 	while :; do
 		config_get type "radio$devidx" type
 		[ -n "$type" ] || break
@@ -81,13 +85,39 @@ detect_mac80211() {
 		htmode=""
 		ht_capab=""
 
-		iw phy "$dev" info | grep -q 'Capabilities:' && htmode=HT20
+		iw_phy_info=$( iw phy "${dev}" info )
+
+		echo "${iw_phy_info}" | fgrep -q 'Capabilities:' && htmode=HT20
+
+		if echo "${iw_phy_info}" | egrep -q '(49|5[0-9])[0-9][0-9] MHz' ; then
 
-		iw phy "$dev" info | grep -q '5180 MHz' && {
 			mode_band="a"
-			channel="36"
-			iw phy "$dev" info | grep -q 'VHT Capabilities' && htmode="VHT80"
-		}
+
+			channel=$( echo "${iw_phy_info}" | \
+				fgrep -v disabled | \
+				sed -Ene 's/^.+ (49|5[0-9])[0-9][0-9] MHz \[([1-9][0-9]{1,2})\].*$/\2/p' | \
+				head -n 1 )
+
+			if [ -z "${channel}" ] ; then
+				logger -p warn -t detect_mac80211 \
+					"No enabled channel found in `iw phy ${dev} info`"
+			fi
+
+			if echo "${iw_phy_info}" | fgrep -q 'VHT Capabilities'
+			then
+				case "$channel" in
+					36 | 149 )
+						htmode="VHT80"
+						;;
+					44 | 157 )
+						htmode="VHT40"
+						;;
+					*)
+						htmode="VHT20"
+						;;
+				esac
+			fi
+		fi  # 5 GHz
 
 		[ -n "$htmode" ] && ht_capab="set wireless.radio${devidx}.htmode=$htmode"
 
-- 
2.11.0


_______________________________________________
openwrt-devel mailing list
openwrt-devel at lists.openwrt.org
https://lists.openwrt.org/mailman/listinfo/openwrt-devel



More information about the openwrt-devel mailing list