[][MAC80211][hostapd][Refactor mac80211.sh patch]

[Description]
Refactor and merge 0001-support-EHT-for-mac80211.sh.patch into 0001-master-mac80211-generate-hostapd-setting-from-ap-cap.patch.
And add default random bss_color, twt_responder, mu_onoff and ibf/ebf onoff to uci.

[Release-log]
N/A

Change-Id: I400170e0472512846bfe80336ac4a9444829bcdf
Reviewed-on: https://gerrit.mediatek.inc/c/openwrt/feeds/mtk_openwrt_feeds/+/7398195
diff --git a/autobuild_mac80211_release/0001-master-mac80211-generate-hostapd-setting-from-ap-cap.patch b/autobuild_mac80211_release/0001-master-mac80211-generate-hostapd-setting-from-ap-cap.patch
index 19983cd..a8e85c0 100644
--- a/autobuild_mac80211_release/0001-master-mac80211-generate-hostapd-setting-from-ap-cap.patch
+++ b/autobuild_mac80211_release/0001-master-mac80211-generate-hostapd-setting-from-ap-cap.patch
@@ -1,5 +1,5 @@
 diff --git a/package/kernel/mac80211/Makefile b/package/kernel/mac80211/Makefile
-index b7059fe6..62c13eb2 100644
+index 02cf715d..d878cb2a 100644
 --- a/package/kernel/mac80211/Makefile
 +++ b/package/kernel/mac80211/Makefile
 @@ -20,6 +20,7 @@ PKG_SOURCE:=backports-$(PKG_VERSION).tar.xz
@@ -31,23 +31,36 @@
  		$(PKG_BUILD_DIR)/include/linux/ssb \
  		$(PKG_BUILD_DIR)/include/linux/bcma \
 diff --git a/package/kernel/mac80211/files/lib/netifd/wireless/mac80211.sh b/package/kernel/mac80211/files/lib/netifd/wireless/mac80211.sh
-index 5aaba9af..6d051038 100644
+index 5aaba9af..ce30b61d 100644
 --- a/package/kernel/mac80211/files/lib/netifd/wireless/mac80211.sh
 +++ b/package/kernel/mac80211/files/lib/netifd/wireless/mac80211.sh
 @@ -27,6 +27,7 @@ drv_mac80211_init_device_config() {
  
  	config_add_string path phy 'macaddr:macaddr'
  	config_add_string tx_burst
-+	config_add_int mbssid
++	config_add_int mbssid mu_onoff
  	config_add_string distance
  	config_add_int beacon_int chanbw frag rts
  	config_add_int rxantenna txantenna antenna_gain txpower min_tx_power
-@@ -140,13 +141,10 @@ mac80211_hostapd_setup_base() {
+@@ -53,7 +54,10 @@ drv_mac80211_init_device_config() {
+ 		he_spr_sr_control \
+ 		he_spr_psr_enabled \
+ 		he_bss_color_enabled \
+-		he_twt_required
++		he_twt_required \
++		he_twt_responder \
++		etxbfen \
++		itxbfen
+ 	config_add_int \
+ 		beamformer_antennas \
+ 		beamformee_antennas \
+@@ -140,13 +144,11 @@ mac80211_hostapd_setup_base() {
  	[ -n "$acs_exclude_dfs" ] && [ "$acs_exclude_dfs" -gt 0 ] &&
  		append base_cfg "acs_exclude_dfs=1" "$N"
  
 -	json_get_vars noscan ht_coex min_tx_power:0 tx_burst
-+	json_get_vars noscan ht_coex min_tx_power:0 tx_burst mbssid
++	json_get_vars noscan ht_coex min_tx_power:0 tx_burst mbssid mu_onoff
++	json_get_vars etxbfen:1 itxbfen:1
  	json_get_values ht_capab_list ht_capab
  	json_get_values channel_list channels
  
@@ -57,7 +70,105 @@
  	[ "$min_tx_power" -gt 0 ] && append base_cfg "min_tx_power=$min_tx_power"
  
  	set_default noscan 0
-@@ -315,7 +313,6 @@ mac80211_hostapd_setup_base() {
+@@ -160,8 +162,8 @@ mac80211_hostapd_setup_base() {
+ 	ieee80211n=1
+ 	ht_capab=
+ 	case "$htmode" in
+-		VHT20|HT20|HE20) ;;
+-		HT40*|VHT40|VHT80|VHT160|HE40|HE80|HE160)
++		VHT20|HT20|HE20|EHT20) ;;
++		HT40*|VHT40|VHT80|VHT160|HE40|HE80|HE160|EHT40|EHT80|EHT160|EHT320*)
+ 			case "$hwmode" in
+ 				a)
+ 					case "$(( (($channel / 4) + $chan_ofs) % 2 ))" in
+@@ -205,7 +207,7 @@ mac80211_hostapd_setup_base() {
+ 			dsss_cck_40:1
+ 
+ 		ht_cap_mask=0
+-		for cap in $(iw phy "$phy" info | grep 'Capabilities:' | cut -d: -f2); do
++		for cap in $(iw phy "$phy" info | grep 'Capabilities: 0x' | cut -d: -f2); do
+ 			ht_cap_mask="$(($ht_cap_mask | $cap))"
+ 		done
+ 
+@@ -236,8 +238,8 @@ mac80211_hostapd_setup_base() {
+ 
+ 	idx="$channel"
+ 	case "$htmode" in
+-		VHT20|HE20) enable_ac=1;;
+-		VHT40|HE40)
++		VHT20|HE20|EHT20) enable_ac=1;;
++		VHT40|HE40|EHT40)
+ 			case "$(( (($channel / 4) + $chan_ofs) % 2 ))" in
+ 				1) idx=$(($channel + 2));;
+ 				0) idx=$(($channel - 2));;
+@@ -245,7 +247,7 @@ mac80211_hostapd_setup_base() {
+ 			enable_ac=1
+ 			vht_center_seg0=$idx
+ 		;;
+-		VHT80|HE80)
++		VHT80|HE80|EHT80)
+ 			case "$(( (($channel / 4) + $chan_ofs) % 4 ))" in
+ 				1) idx=$(($channel + 6));;
+ 				2) idx=$(($channel + 2));;
+@@ -256,7 +258,7 @@ mac80211_hostapd_setup_base() {
+ 			vht_oper_chwidth=1
+ 			vht_center_seg0=$idx
+ 		;;
+-		VHT160|HE160)
++		VHT160|HE160|EHT160)
+ 			if [ "$band" = "6g" ]; then
+ 				case "$channel" in
+ 					1|5|9|13|17|21|25|29) idx=15;;
+@@ -277,6 +279,36 @@ mac80211_hostapd_setup_base() {
+ 			vht_oper_chwidth=2
+ 			vht_center_seg0=$idx
+ 		;;
++		EHT320*)
++			case "$channel" in
++				1|5|9|13|17|21|25|29) idx=31;;
++				33|37|41|45|49|53|57|61| \
++				65|69|73|77|81|85|89|93) idx=63;;
++				97|101|105|109|113|117|121|125| \
++				129|133|137|141|145|149|153|157) idx=127;;
++				161|165|169|173|177|181|185|189| \
++				193|197|201|205|209|213|217|221) idx=191;;
++			esac
++			if [[ "$htmode" = "EHT320-1" && "$channel" -ge "193" ]] ||
++			   [[ "$htmode" = "EHT320-2" && "$channel" -le "29" ]]; then
++				echo "Could not set the center freq with this EHT setting"
++				return 1
++			elif [[ "$htmode" = "EHT320-1" && "$channel" -ge "33" ]]; then
++				if [ "$channel" -gt $idx ]; then
++					idx=$(($idx + 32))
++				else
++					idx=$(($idx - 32))
++				fi
++			fi
++			vht_oper_chwidth=2
++			if [ "$channel" -gt $idx ]; then
++				vht_center_seg0=$(($idx + 16))
++			else
++				vht_center_seg0=$(($idx - 16))
++			fi
++			eht_oper_chwidth=9
++			eht_oper_centr_freq_seg0_idx=$idx
++		;;
+ 	esac
+ 	[ "$band" = "5g" ] && {
+ 		json_get_vars background_radar:0
+@@ -286,8 +318,9 @@ mac80211_hostapd_setup_base() {
+ 	[ "$band" = "6g" ] && {
+ 		op_class=
+ 		case "$htmode" in
+-			HE20) op_class=131;;
+-			HE*) op_class=$((132 + $vht_oper_chwidth))
++			HE20|EHT20) op_class=131;;
++			EHT320*) op_class=137;;
++			HE*|EHT*) op_class=$((132 + $vht_oper_chwidth))
+ 		esac
+ 		[ -n "$op_class" ] && append base_cfg "op_class=$op_class" "$N"
+ 	}
+@@ -315,7 +348,6 @@ mac80211_hostapd_setup_base() {
  			vht_link_adapt:3 \
  			vht160:2
  
@@ -65,12 +176,103 @@
  		append base_cfg "ieee80211ac=1" "$N"
  		vht_cap=0
  		for cap in $(iw phy "$phy" info | awk -F "[()]" '/VHT Capabilities/ { print $2 }'); do
-@@ -484,12 +481,15 @@ mac80211_hostapd_setup_base() {
+@@ -329,6 +361,12 @@ mac80211_hostapd_setup_base() {
+ 		[ "$rx_stbc" -lt "$cap_rx_stbc" ] && cap_rx_stbc="$rx_stbc"
+ 		vht_cap="$(( ($vht_cap & ~(0x700)) | ($cap_rx_stbc << 8) ))"
+ 
++		[ "$etxbfen" -eq 0 ] && {
++			su_beamformer=0
++			su_beamformee=0
++			mu_beamformer=0
++		}
++
+ 		mac80211_add_capabilities vht_capab $vht_cap \
+ 			RXLDPC:0x10::$rxldpc \
+ 			SHORT-GI-80:0x20::$short_gi_80 \
+@@ -410,7 +448,7 @@ mac80211_hostapd_setup_base() {
+ 	# 802.11ax
+ 	enable_ax=0
+ 	case "$htmode" in
+-		HE*) enable_ax=1 ;;
++		HE*|EHT*) enable_ax=1 ;;
+ 	esac
+ 
+ 	if [ "$enable_ax" != "0" ]; then
+@@ -419,10 +457,11 @@ mac80211_hostapd_setup_base() {
+ 			he_su_beamformee:1 \
+ 			he_mu_beamformer:1 \
+ 			he_twt_required:0 \
++			he_twt_responder \
+ 			he_spr_sr_control:3 \
+ 			he_spr_psr_enabled:0 \
+ 			he_spr_non_srg_obss_pd_max_offset:0 \
+-			he_bss_color:128 \
++			he_bss_color \
+ 			he_bss_color_enabled:1
+ 
+ 		he_phy_cap=$(iw phy "$phy" info | sed -n '/HE Iftypes: AP/,$p' | awk -F "[()]" '/HE PHY Capabilities/ { print $2 }' | head -1)
+@@ -436,6 +475,11 @@ mac80211_hostapd_setup_base() {
+ 			append base_cfg "he_oper_centr_freq_seg0_idx=$vht_center_seg0" "$N"
+ 		}
+ 
++		[ "$etxbfen" -eq 0 ] && {
++			he_su_beamformer=0
++			he_mu_beamformer=0
++		}
++
+ 		mac80211_add_he_capabilities \
+ 			he_su_beamformer:${he_phy_cap:6:2}:0x80:$he_su_beamformer \
+ 			he_su_beamformee:${he_phy_cap:8:2}:0x1:$he_su_beamformee \
+@@ -443,7 +487,14 @@ mac80211_hostapd_setup_base() {
+ 			he_spr_psr_enabled:${he_phy_cap:14:2}:0x1:$he_spr_psr_enabled \
+ 			he_twt_required:${he_mac_cap:0:2}:0x6:$he_twt_required
+ 
++		if [ -n "$he_twt_responder" ]; then
++			append base_cfg "he_twt_responder=$he_twt_responder" "$N"
++		fi
+ 		if [ "$he_bss_color_enabled" -gt 0 ]; then
++			if [ -z "$he_bss_color" ]; then
++				rand=$(head -n 1 /dev/urandom | tr -dc 0-9 | head -c 2)
++				he_bss_color=$((rand % 63 + 1))
++			fi
+ 			append base_cfg "he_bss_color=$he_bss_color" "$N"
+ 			[ "$he_spr_non_srg_obss_pd_max_offset" -gt 0 ] && { \
+ 				append base_cfg "he_spr_non_srg_obss_pd_max_offset=$he_spr_non_srg_obss_pd_max_offset" "$N"
+@@ -484,12 +535,46 @@ mac80211_hostapd_setup_base() {
  		append base_cfg "he_mu_edca_ac_vo_timer=255" "$N"
  	fi
  
 +	set_default tx_burst 5.9
 +
++	# 802.11be
++	enable_be=0
++	case "$htmode" in
++		EHT*) enable_be=1 ;;
++	esac
++
++	if [ "$enable_be" != "0" ]; then
++		append base_cfg "ieee80211be=1" "$N"
++		if [ "$etxbfen" -eq 0 ]; then
++			append base_cfg "eht_su_beamformee=1" "$N"
++		else
++			append base_cfg "eht_su_beamformer=1" "$N"
++			append base_cfg "eht_su_beamformee=1" "$N"
++			append base_cfg "eht_mu_beamformer=1" "$N"
++		fi
++		[ "$hwmode" = "a" ] && {
++			case $htmode in
++				EHT320*)
++					append base_cfg "eht_oper_chwidth=$eht_oper_chwidth" "$N"
++					append base_cfg "eht_oper_centr_freq_seg0_idx=$eht_oper_centr_freq_seg0_idx" "$N"
++				;;
++				*)
++					append base_cfg "eht_oper_chwidth=$vht_oper_chwidth" "$N"
++					append base_cfg "eht_oper_centr_freq_seg0_idx=$vht_center_seg0" "$N"
++				;;
++			esac
++		}
++	fi
++
  	hostapd_prepare_device_config "$hostapd_conf_file" nl80211
  	cat >> "$hostapd_conf_file" <<EOF
  ${channel:+channel=$channel}
@@ -78,10 +280,12 @@
  ${hostapd_noscan:+noscan=1}
  ${tx_burst:+tx_queue_data2_burst=$tx_burst}
 +${mbssid:+mbssid=$mbssid}
++${mu_onoff:+mu_onoff=$mu_onoff}
++${itxbfen:+ibf_enable=$itxbfen}
  $base_cfg
  
  EOF
-@@ -517,7 +517,7 @@ mac80211_hostapd_setup_bss() {
+@@ -517,7 +602,7 @@ mac80211_hostapd_setup_bss() {
  		append hostapd_cfg "wds_sta=1" "$N"
  		[ -n "$wds_bridge" ] && append hostapd_cfg "wds_bridge=$wds_bridge" "$N"
  	}
@@ -90,7 +294,7 @@
  
  	cat >> /var/run/hostapd-$phy.conf <<EOF
  $hostapd_cfg
-@@ -527,6 +527,34 @@ ${max_listen_int:+max_listen_interval=$max_listen_int}
+@@ -527,6 +612,34 @@ ${max_listen_int:+max_listen_interval=$max_listen_int}
  EOF
  }
  
@@ -125,7 +329,7 @@
  mac80211_get_addr() {
  	local phy="$1"
  	local idx="$(($2 + 1))"
-@@ -757,7 +785,13 @@ mac80211_prepare_vif() {
+@@ -757,7 +870,13 @@ mac80211_prepare_vif() {
  
  	json_select ..
  
@@ -140,7 +344,7 @@
  		macaddr="$(mac80211_generate_mac $phy)"
  		macidx="$(($macidx + 1))"
  	elif [ "$macaddr" = 'random' ]; then
-@@ -1058,6 +1092,9 @@ mac80211_setup_vif() {
+@@ -1058,6 +1177,9 @@ mac80211_setup_vif() {
  
  	json_select ..
  	[ -n "$failed" ] || wireless_add_vif "$name" "$ifname"
@@ -150,7 +354,7 @@
  }
  
  get_freq() {
-@@ -1122,6 +1159,10 @@ drv_mac80211_cleanup() {
+@@ -1122,6 +1244,10 @@ drv_mac80211_cleanup() {
  	hostapd_common_cleanup
  }
  
@@ -161,7 +365,7 @@
  drv_mac80211_setup() {
  	json_select config
  	json_get_vars \
-@@ -1219,6 +1260,16 @@ drv_mac80211_setup() {
+@@ -1219,6 +1345,16 @@ drv_mac80211_setup() {
  	for_each_interface "sta adhoc mesh" mac80211_set_noscan
  	[ -n "$has_ap" ] && mac80211_hostapd_setup_base "$phy"
  
@@ -179,10 +383,38 @@
  	for_each_interface "sta adhoc mesh monitor" mac80211_prepare_vif
  	NEWAPLIST=
 diff --git a/package/kernel/mac80211/files/lib/wifi/mac80211.sh b/package/kernel/mac80211/files/lib/wifi/mac80211.sh
-index e24a2a63..10a3f8b4 100644
+index e24a2a63..80cd298c 100644
 --- a/package/kernel/mac80211/files/lib/wifi/mac80211.sh
 +++ b/package/kernel/mac80211/files/lib/wifi/mac80211.sh
-@@ -120,6 +120,13 @@ get_band_defaults() {
+@@ -60,6 +60,8 @@ BEGIN {
+ 		if (vht && band != "1:") mode="VHT80"
+ 		if (he) mode="HE80"
+ 		if (he && band == "1:") mode="HE20"
++		if (eht) mode="EHT80"
++		if (eht && band == "1:") mode="EHT20"
+                 sub("\\[", "", channel)
+                 sub("\\]", "", channel)
+                 bands = bands band channel ":" mode " "
+@@ -73,6 +75,7 @@ $1 == "Band" {
+ 	vht = ""
+ 	ht = ""
+ 	he = ""
++	eht = ""
+ }
+ 
+ $0 ~ "Capabilities:" {
+@@ -87,6 +90,10 @@ $0 ~ "HE Iftypes" {
+ 	he=1
+ }
+ 
++$0 ~ "EHT Iftypes" {
++	eht=1
++}
++
+ $1 == "*" && $3 == "MHz" && $0 !~ /disabled/ && band && !channel {
+         channel = $4
+ }
+@@ -120,6 +127,13 @@ get_band_defaults() {
  		mode_band="$band"
  		channel="$chan"
  		htmode="$mode"
@@ -196,7 +428,18 @@
  	done
  }
  
+@@ -153,6 +167,10 @@ detect_mac80211() {
+ 
+ 	json_load_file /etc/board.json
+ 
++	# generate random bytes for macaddr
++	rand=$(hexdump -C /dev/urandom | head -n 1 &)
++	killall hexdump
++
+ 	for _dev in /sys/class/ieee80211/*; do
+ 		[ -e "$_dev" ] || continue
+ 
-@@ -162,6 +169,8 @@ detect_mac80211() {
+@@ -162,6 +180,8 @@ detect_mac80211() {
  		channel=""
  		htmode=""
  		ht_capab=""
@@ -205,13 +448,27 @@
  
  		get_band_defaults "$dev"
  
+@@ -196,6 +216,11 @@ detect_mac80211() {
+ 				;;
+ 		esac
+ 
-@@ -210,8 +219,12 @@ detect_mac80211() {
++		macaddr=""
++		for i in $(seq 2 3); do
++			macaddr=${macaddr}:$(echo $rand | cut -d ' ' -f $i)
++		done
++
+ 		uci -q batch <<-EOF
+ 			set wireless.${name}=wifi-device
+ 			set wireless.${name}.type=mac80211
+@@ -210,8 +235,14 @@ detect_mac80211() {
  			set wireless.default_${name}.network=lan
  			set wireless.default_${name}.mode=ap
  			set wireless.default_${name}.ssid=OpenWrt
 -			set wireless.default_${name}.encryption=none
 +			set wireless.default_${name}.encryption=${encryption}
 +
++			set wireless.default_${name}.macaddr=00:0$(($devidx - 1)):55:66${macaddr}
++
  EOF
 +		[ -n "$key" ] && {
 +			uci -q set wireless.default_${name}.key=${key}
diff --git a/autobuild_mac80211_release/mt7988_mt7996_mac80211/0001-support-EHT-for-mac80211.sh.patch b/autobuild_mac80211_release/mt7988_mt7996_mac80211/0001-support-EHT-for-mac80211.sh.patch
deleted file mode 100644
index d026a3d..0000000
--- a/autobuild_mac80211_release/mt7988_mt7996_mac80211/0001-support-EHT-for-mac80211.sh.patch
+++ /dev/null
@@ -1,207 +0,0 @@
-diff --git a/package/kernel/mac80211/files/lib/netifd/wireless/mac80211.sh b/package/kernel/mac80211/files/lib/netifd/wireless/mac80211.sh
-index 5aaba9a..54a5d88 100644
---- a/package/kernel/mac80211/files/lib/netifd/wireless/mac80211.sh
-+++ b/package/kernel/mac80211/files/lib/netifd/wireless/mac80211.sh
-@@ -160,8 +160,8 @@ mac80211_hostapd_setup_base() {
- 	ieee80211n=1
- 	ht_capab=
- 	case "$htmode" in
--		VHT20|HT20|HE20) ;;
--		HT40*|VHT40|VHT80|VHT160|HE40|HE80|HE160)
-+		VHT20|HT20|HE20|EHT20) ;;
-+		HT40*|VHT40|VHT80|VHT160|HE40|HE80|HE160|EHT40|EHT80|EHT160|EHT320*)
- 			case "$hwmode" in
- 				a)
- 					case "$(( (($channel / 4) + $chan_ofs) % 2 ))" in
-@@ -205,7 +205,7 @@ mac80211_hostapd_setup_base() {
- 			dsss_cck_40:1
- 
- 		ht_cap_mask=0
--		for cap in $(iw phy "$phy" info | grep 'Capabilities:' | cut -d: -f2); do
-+		for cap in $(iw phy "$phy" info | grep 'Capabilities: 0x' | cut -d: -f2); do
- 			ht_cap_mask="$(($ht_cap_mask | $cap))"
- 		done
- 
-@@ -236,8 +236,8 @@ mac80211_hostapd_setup_base() {
- 
- 	idx="$channel"
- 	case "$htmode" in
--		VHT20|HE20) enable_ac=1;;
--		VHT40|HE40)
-+		VHT20|HE20|EHT20) enable_ac=1;;
-+		VHT40|HE40|EHT40)
- 			case "$(( (($channel / 4) + $chan_ofs) % 2 ))" in
- 				1) idx=$(($channel + 2));;
- 				0) idx=$(($channel - 2));;
-@@ -245,7 +245,7 @@ mac80211_hostapd_setup_base() {
- 			enable_ac=1
- 			vht_center_seg0=$idx
- 		;;
--		VHT80|HE80)
-+		VHT80|HE80|EHT80)
- 			case "$(( (($channel / 4) + $chan_ofs) % 4 ))" in
- 				1) idx=$(($channel + 6));;
- 				2) idx=$(($channel + 2));;
-@@ -256,7 +256,7 @@ mac80211_hostapd_setup_base() {
- 			vht_oper_chwidth=1
- 			vht_center_seg0=$idx
- 		;;
--		VHT160|HE160)
-+		VHT160|HE160|EHT160)
- 			if [ "$band" = "6g" ]; then
- 				case "$channel" in
- 					1|5|9|13|17|21|25|29) idx=15;;
-@@ -277,6 +277,36 @@ mac80211_hostapd_setup_base() {
- 			vht_oper_chwidth=2
- 			vht_center_seg0=$idx
- 		;;
-+		EHT320*)
-+			case "$channel" in
-+				1|5|9|13|17|21|25|29) idx=31;;
-+				33|37|41|45|49|53|57|61| \
-+				65|69|73|77|81|85|89|93) idx=63;;
-+				97|101|105|109|113|117|121|125| \
-+				129|133|137|141|145|149|153|157) idx=127;;
-+				161|165|169|173|177|181|185|189| \
-+				193|197|201|205|209|213|217|221) idx=191;;
-+			esac
-+			if [[ "$htmode" = "EHT320-1" && "$channel" -ge "193" ]] ||
-+			   [[ "$htmode" = "EHT320-2" && "$channel" -le "29" ]]; then
-+				echo "Could not set the center freq with this EHT setting"
-+				return 1
-+			elif [[ "$htmode" = "EHT320-1" && "$channel" -ge "33" ]]; then
-+				if [ "$channel" -gt $idx ]; then
-+					idx=$(($idx + 32))
-+				else
-+					idx=$(($idx - 32))
-+				fi
-+			fi
-+			vht_oper_chwidth=2
-+			if [ "$channel" -gt $idx ]; then
-+				vht_center_seg0=$(($idx + 16))
-+			else
-+				vht_center_seg0=$(($idx - 16))
-+			fi
-+			eht_oper_chwidth=9
-+			eht_oper_centr_freq_seg0_idx=$idx
-+		;;
- 	esac
- 	[ "$band" = "5g" ] && {
- 		json_get_vars background_radar:0
-@@ -286,8 +316,9 @@ mac80211_hostapd_setup_base() {
- 	[ "$band" = "6g" ] && {
- 		op_class=
- 		case "$htmode" in
--			HE20) op_class=131;;
--			HE*) op_class=$((132 + $vht_oper_chwidth))
-+			HE20|EHT20) op_class=131;;
-+			EHT320*) op_class=137;;
-+			HE*|EHT*) op_class=$((132 + $vht_oper_chwidth))
- 		esac
- 		[ -n "$op_class" ] && append base_cfg "op_class=$op_class" "$N"
- 	}
-@@ -410,7 +441,7 @@ mac80211_hostapd_setup_base() {
- 	# 802.11ax
- 	enable_ax=0
- 	case "$htmode" in
--		HE*) enable_ax=1 ;;
-+		HE*|EHT*) enable_ax=1 ;;
- 	esac
- 
- 	if [ "$enable_ax" != "0" ]; then
-@@ -484,6 +515,31 @@ mac80211_hostapd_setup_base() {
- 		append base_cfg "he_mu_edca_ac_vo_timer=255" "$N"
- 	fi
- 
-+	# 802.11be
-+	enable_be=0
-+	case "$htmode" in
-+		EHT*) enable_be=1 ;;
-+	esac
-+
-+	if [ "$enable_be" != "0" ]; then
-+		append base_cfg "ieee80211be=1" "$N"
-+		append base_cfg "eht_su_beamformer=1" "$N"
-+		append base_cfg "eht_su_beamformee=1" "$N"
-+		append base_cfg "eht_mu_beamformer=1" "$N"
-+		[ "$hwmode" = "a" ] && {
-+			case $htmode in
-+				EHT320*)
-+					append base_cfg "eht_oper_chwidth=$eht_oper_chwidth" "$N"
-+					append base_cfg "eht_oper_centr_freq_seg0_idx=$eht_oper_centr_freq_seg0_idx" "$N"
-+				;;
-+				*)
-+					append base_cfg "eht_oper_chwidth=$vht_oper_chwidth" "$N"
-+					append base_cfg "eht_oper_centr_freq_seg0_idx=$vht_center_seg0" "$N"
-+				;;
-+			esac
-+		}
-+	fi
-+
- 	hostapd_prepare_device_config "$hostapd_conf_file" nl80211
- 	cat >> "$hostapd_conf_file" <<EOF
- ${channel:+channel=$channel}
-diff --git a/package/kernel/mac80211/files/lib/wifi/mac80211.sh b/package/kernel/mac80211/files/lib/wifi/mac80211.sh
-index 10a3f8b..80cd298 100644
---- a/package/kernel/mac80211/files/lib/wifi/mac80211.sh
-+++ b/package/kernel/mac80211/files/lib/wifi/mac80211.sh
-@@ -60,6 +60,8 @@ BEGIN {
- 		if (vht && band != "1:") mode="VHT80"
- 		if (he) mode="HE80"
- 		if (he && band == "1:") mode="HE20"
-+		if (eht) mode="EHT80"
-+		if (eht && band == "1:") mode="EHT20"
-                 sub("\\[", "", channel)
-                 sub("\\]", "", channel)
-                 bands = bands band channel ":" mode " "
-@@ -73,6 +75,7 @@ $1 == "Band" {
- 	vht = ""
- 	ht = ""
- 	he = ""
-+	eht = ""
- }
- 
- $0 ~ "Capabilities:" {
-@@ -87,6 +90,10 @@ $0 ~ "HE Iftypes" {
- 	he=1
- }
- 
-+$0 ~ "EHT Iftypes" {
-+	eht=1
-+}
-+
- $1 == "*" && $3 == "MHz" && $0 !~ /disabled/ && band && !channel {
-         channel = $4
- }
-@@ -160,6 +167,10 @@ detect_mac80211() {
- 
- 	json_load_file /etc/board.json
- 
-+	# generate random bytes for macaddr
-+	rand=$(hexdump -C /dev/urandom | head -n 1 &)
-+	killall hexdump
-+
- 	for _dev in /sys/class/ieee80211/*; do
- 		[ -e "$_dev" ] || continue
- 
-@@ -205,6 +216,11 @@ detect_mac80211() {
- 				;;
- 		esac
- 
-+		macaddr=""
-+		for i in $(seq 2 3); do
-+			macaddr=${macaddr}:$(echo $rand | cut -d ' ' -f $i)
-+		done
-+
- 		uci -q batch <<-EOF
- 			set wireless.${name}=wifi-device
- 			set wireless.${name}.type=mac80211
-@@ -221,6 +237,8 @@ detect_mac80211() {
- 			set wireless.default_${name}.ssid=OpenWrt
- 			set wireless.default_${name}.encryption=${encryption}
- 
-+			set wireless.default_${name}.macaddr=00:0$(($devidx - 1)):55:66${macaddr}
-+
- EOF
- 		[ -n "$key" ] && {
- 			uci -q set wireless.default_${name}.key=${key}
diff --git a/autobuild_mac80211_release/mt7988_mt7996_mac80211/lede-branch-build-sanity.sh b/autobuild_mac80211_release/mt7988_mt7996_mac80211/lede-branch-build-sanity.sh
index 9b93c8f..80dfa41 100755
--- a/autobuild_mac80211_release/mt7988_mt7996_mac80211/lede-branch-build-sanity.sh
+++ b/autobuild_mac80211_release/mt7988_mt7996_mac80211/lede-branch-build-sanity.sh
@@ -51,8 +51,6 @@
 rm -rf ${BUILD_DIR}/package/kernel/mt76/patches/*
 
 # ========== specific modification on mt7996 autobuild for EHT support ==========
-# patch mac80211.sh script
-patch -p1 < ${BUILD_DIR}/autobuild/${branch_name}/0001-support-EHT-for-mac80211.sh.patch
 # patch hostapd to use latest version and add 11BE config
 patch -p1 < ${BUILD_DIR}/autobuild/${branch_name}/0002-add-EHT-config-for-hostapd.patch
 # copy DSP & testmode firmware