[][MAC80211][hostapd][rebase patch based on 2023-03-29]

[Description]
Refactor patches based on 2023-03-29

[Release-log]
N/A

Change-Id: Ib9fb4ae566e213da8cb14dda1574ff711fdd3749
Reviewed-on: https://gerrit.mediatek.inc/c/openwrt/feeds/mtk_openwrt_feeds/+/7477769
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 80dfa41..d0f10fa 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
@@ -6,6 +6,7 @@
 branch_name=${temp##*/}
 hwpath=0
 backport_new=1
+hostapd_new=1
 args=
 
 for arg in $*; do
@@ -45,7 +46,7 @@
 prepare_flowoffload
 
 #prepare mac80211 mt76 wifi stuff
-prepare_mac80211 ${backport_new}
+prepare_mac80211 ${backport_new} ${hostapd_new}
 
 # find ${BUILD_DIR}/package/kernel/mt76/patches -name "*-mt76-*.patch" -delete
 rm -rf ${BUILD_DIR}/package/kernel/mt76/patches/*
diff --git a/autobuild_mac80211_release/mt7988_mt7996_mac80211/package/network/services/hostapd/patches/mtk-0100-hostapd-mtk-update-eht-operation-elem.patch b/autobuild_mac80211_release/mt7988_mt7996_mac80211/package/network/services/hostapd/patches/mtk-0100-hostapd-mtk-update-eht-operation-elem.patch
deleted file mode 100644
index bbb52ed..0000000
--- a/autobuild_mac80211_release/mt7988_mt7996_mac80211/package/network/services/hostapd/patches/mtk-0100-hostapd-mtk-update-eht-operation-elem.patch
+++ /dev/null
@@ -1,51 +0,0 @@
-From 6251cf18a39e56eb5b240f967d36a397573e5b3e Mon Sep 17 00:00:00 2001
-From: Peter Chiu <chui-hao.chiu@mediatek.com>
-Date: Fri, 30 Sep 2022 00:16:21 +0800
-Subject: [PATCH] hostapd: mtk: update eht operation elem
-
----
- src/ap/ieee802_11_eht.c      | 5 +++--
- src/common/ieee802_11_defs.h | 1 +
- 2 files changed, 4 insertions(+), 2 deletions(-)
-
-diff --git a/src/ap/ieee802_11_eht.c b/src/ap/ieee802_11_eht.c
-index ec36a9e..fc472b8 100644
---- a/src/ap/ieee802_11_eht.c
-+++ b/src/ap/ieee802_11_eht.c
-@@ -183,7 +183,7 @@ u8 * hostapd_eid_eht_operation(struct hostapd_data *hapd, u8 *eid)
- 		return eid;
- 
- 	*pos++ = WLAN_EID_EXTENSION;
--	*pos++ = 5;
-+	*pos++ = 9;
- 	*pos++ = WLAN_EID_EXT_EHT_OPERATION;
- 
- 	oper = (struct ieee80211_eht_operation *) pos;
-@@ -224,10 +224,11 @@ u8 * hostapd_eid_eht_operation(struct hostapd_data *hapd, u8 *eid)
- 		return eid;
- 	}
- 
-+	oper->mcs_nss_set = 0x11111111;
- 	oper->oper_info.ccfs0 = seg0 ? seg0 : hapd->iconf->channel;
- 	oper->oper_info.ccfs1 = seg1;
- 
--	return pos + 4;
-+	return pos + 8;
- }
- 
- 
-diff --git a/src/common/ieee802_11_defs.h b/src/common/ieee802_11_defs.h
-index 0bbbca9..f7ec11b 100644
---- a/src/common/ieee802_11_defs.h
-+++ b/src/common/ieee802_11_defs.h
-@@ -2440,6 +2440,7 @@ struct ieee80211_eht_oper_info {
- /* Figure 9-1002a: EHT Operation element format */
- struct ieee80211_eht_operation {
- 	u8 oper_params; /* EHT Operation Parameters: EHT_OPER_* bits */
-+	le32 mcs_nss_set;
- 	struct ieee80211_eht_oper_info oper_info; /* 0 or 3 or 5 octets */
- } STRUCT_PACKED;
- 
--- 
-2.18.0
-
diff --git a/autobuild_mac80211_release/mt7988_mt7996_mac80211/package/network/services/hostapd/patches/mtk-0100-hostapd-mtk-update-eht-operation-element.patch b/autobuild_mac80211_release/mt7988_mt7996_mac80211/package/network/services/hostapd/patches/mtk-0100-hostapd-mtk-update-eht-operation-element.patch
new file mode 100644
index 0000000..d8cdf15
--- /dev/null
+++ b/autobuild_mac80211_release/mt7988_mt7996_mac80211/package/network/services/hostapd/patches/mtk-0100-hostapd-mtk-update-eht-operation-element.patch
@@ -0,0 +1,29 @@
+From ea9c7bda66bcd7819e106d5f672345b941365d15 Mon Sep 17 00:00:00 2001
+From: Evelyn Tsai <evelyn.tsai@mediatek.com>
+Date: Wed, 10 May 2023 13:11:34 +0800
+Subject: [PATCH 100/103] hostapd: mtk: update eht operation element
+
+---
+ src/ap/ieee802_11_eht.c | 6 +++---
+ 1 file changed, 3 insertions(+), 3 deletions(-)
+
+diff --git a/src/ap/ieee802_11_eht.c b/src/ap/ieee802_11_eht.c
+index 6ebe0f9..c14c5e2 100644
+--- a/src/ap/ieee802_11_eht.c
++++ b/src/ap/ieee802_11_eht.c
+@@ -214,9 +214,9 @@ u8 * hostapd_eid_eht_operation(struct hostapd_data *hapd, u8 *eid)
+ 
+ 	/* TODO: Fill in appropriate EHT-MCS max Nss information */
+ 	oper->basic_eht_mcs_nss_set[0] = 0x11;
+-	oper->basic_eht_mcs_nss_set[1] = 0x00;
+-	oper->basic_eht_mcs_nss_set[2] = 0x00;
+-	oper->basic_eht_mcs_nss_set[3] = 0x00;
++	oper->basic_eht_mcs_nss_set[1] = 0x11;
++	oper->basic_eht_mcs_nss_set[2] = 0x11;
++	oper->basic_eht_mcs_nss_set[3] = 0x11;
+ 
+ 	if (is_6ghz_op_class(conf->op_class))
+ 		chwidth = op_class_to_ch_width(conf->op_class);
+-- 
+2.18.0
+
diff --git a/autobuild_mac80211_release/mt7988_mt7996_mac80211/package/network/services/hostapd/patches/mtk-0101-hostapd-mtk-Fix-CCA-issue.patch b/autobuild_mac80211_release/mt7988_mt7996_mac80211/package/network/services/hostapd/patches/mtk-0101-hostapd-mtk-Fix-CCA-issue.patch
new file mode 100644
index 0000000..9b46d70
--- /dev/null
+++ b/autobuild_mac80211_release/mt7988_mt7996_mac80211/package/network/services/hostapd/patches/mtk-0101-hostapd-mtk-Fix-CCA-issue.patch
@@ -0,0 +1,97 @@
+From 39a0dd44653f12ce13af68de81bfae683669623a Mon Sep 17 00:00:00 2001
+From: Evelyn Tsai <evelyn.tsai@mediatek.com>
+Date: Thu, 11 May 2023 14:08:59 +0800
+Subject: [PATCH 101/103] hostapd: mtk: Fix CCA issue
+
+When receiving CCA related nl80211 command, hostapd used to work on
+struct wpa_driver_nl80211_data, whose ctx always points to
+hostpad_iface->bss[0]. However, CCA command is sent on per-BSS based.
+This patch makes hostapd handle CCA related commands on per-BSS based.
+
+Signed-off-by: Michael Lee <michael-cy.lee@mediatek.com>
+---
+ src/drivers/driver_nl80211_event.c | 24 ++++++++++++------------
+ 1 file changed, 12 insertions(+), 12 deletions(-)
+
+diff --git a/src/drivers/driver_nl80211_event.c b/src/drivers/driver_nl80211_event.c
+index 67d9ce2..bcce9f5 100644
+--- a/src/drivers/driver_nl80211_event.c
++++ b/src/drivers/driver_nl80211_event.c
+@@ -3418,7 +3418,7 @@ static void nl80211_assoc_comeback(struct wpa_driver_nl80211_data *drv,
+ 
+ #ifdef CONFIG_IEEE80211AX
+ 
+-static void nl80211_obss_color_collision(struct wpa_driver_nl80211_data *drv,
++static void nl80211_obss_color_collision(struct i802_bss *bss,
+ 					 struct nlattr *tb[])
+ {
+ 	union wpa_event_data data;
+@@ -3432,37 +3432,37 @@ static void nl80211_obss_color_collision(struct wpa_driver_nl80211_data *drv,
+ 
+ 	wpa_printf(MSG_DEBUG, "nl80211: BSS color collision - bitmap %08llx",
+ 		   (long long unsigned int) data.bss_color_collision.bitmap);
+-	wpa_supplicant_event(drv->ctx, EVENT_BSS_COLOR_COLLISION, &data);
++	wpa_supplicant_event(bss->ctx, EVENT_BSS_COLOR_COLLISION, &data);
+ }
+ 
+ 
+ static void
+-nl80211_color_change_announcement_started(struct wpa_driver_nl80211_data *drv)
++nl80211_color_change_announcement_started(struct i802_bss *bss)
+ {
+ 	union wpa_event_data data = {};
+ 
+ 	wpa_printf(MSG_DEBUG, "nl80211: CCA started");
+-	wpa_supplicant_event(drv->ctx, EVENT_CCA_STARTED_NOTIFY, &data);
++	wpa_supplicant_event(bss->ctx, EVENT_CCA_STARTED_NOTIFY, &data);
+ }
+ 
+ 
+ static void
+-nl80211_color_change_announcement_aborted(struct wpa_driver_nl80211_data *drv)
++nl80211_color_change_announcement_aborted(struct i802_bss *bss)
+ {
+ 	union wpa_event_data data = {};
+ 
+ 	wpa_printf(MSG_DEBUG, "nl80211: CCA aborted");
+-	wpa_supplicant_event(drv->ctx, EVENT_CCA_ABORTED_NOTIFY, &data);
++	wpa_supplicant_event(bss->ctx, EVENT_CCA_ABORTED_NOTIFY, &data);
+ }
+ 
+ 
+ static void
+-nl80211_color_change_announcement_completed(struct wpa_driver_nl80211_data *drv)
++nl80211_color_change_announcement_completed(struct i802_bss *bss)
+ {
+ 	union wpa_event_data data = {};
+ 
+ 	wpa_printf(MSG_DEBUG, "nl80211: CCA completed");
+-	wpa_supplicant_event(drv->ctx, EVENT_CCA_NOTIFY, &data);
++	wpa_supplicant_event(bss->ctx, EVENT_CCA_NOTIFY, &data);
+ }
+ 
+ #endif /* CONFIG_IEEE80211AX */
+@@ -3724,16 +3724,16 @@ static void do_process_drv_event(struct i802_bss *bss, int cmd,
+ 		break;
+ #ifdef CONFIG_IEEE80211AX
+ 	case NL80211_CMD_OBSS_COLOR_COLLISION:
+-		nl80211_obss_color_collision(drv, tb);
++		nl80211_obss_color_collision(bss, tb);
+ 		break;
+ 	case NL80211_CMD_COLOR_CHANGE_STARTED:
+-		nl80211_color_change_announcement_started(drv);
++		nl80211_color_change_announcement_started(bss);
+ 		break;
+ 	case NL80211_CMD_COLOR_CHANGE_ABORTED:
+-		nl80211_color_change_announcement_aborted(drv);
++		nl80211_color_change_announcement_aborted(bss);
+ 		break;
+ 	case NL80211_CMD_COLOR_CHANGE_COMPLETED:
+-		nl80211_color_change_announcement_completed(drv);
++		nl80211_color_change_announcement_completed(bss);
+ 		break;
+ #endif /* CONFIG_IEEE80211AX */
+ 	default:
+-- 
+2.18.0
+
diff --git a/autobuild_mac80211_release/mt7988_mt7996_mac80211/package/network/services/hostapd/patches/mtk-0102-hostapd-mtk-Fix-unexpected-AP-beacon-state-transitio.patch b/autobuild_mac80211_release/mt7988_mt7996_mac80211/package/network/services/hostapd/patches/mtk-0102-hostapd-mtk-Fix-unexpected-AP-beacon-state-transitio.patch
new file mode 100644
index 0000000..4075531
--- /dev/null
+++ b/autobuild_mac80211_release/mt7988_mt7996_mac80211/package/network/services/hostapd/patches/mtk-0102-hostapd-mtk-Fix-unexpected-AP-beacon-state-transitio.patch
@@ -0,0 +1,37 @@
+From 097b204ffed838a4bbf7649fb23310f64ace22ad Mon Sep 17 00:00:00 2001
+From: Evelyn Tsai <evelyn.tsai@mediatek.com>
+Date: Thu, 11 May 2023 14:12:44 +0800
+Subject: [PATCH 102/103] hostapd: mtk: Fix unexpected AP beacon state
+ transition
+
+When AP fails setting the beacon, it assigns bss->beacon_set to 0 no
+matter what the error number is.
+However, in the case that the error number is -EBUSY, the driver might
+not free the beacon and expect a later beacon re-setting. If hostapd set
+a new beacon under this case, driver will return -EALREADY.
+This patch checks the error number after hostapd fails setting the
+beacon. If the error number is -EBUSY, bss->beacon_set will not be
+assigned to 0.
+
+Signed-off-by: Michael Lee <michael-cy.lee@mediatek.com>
+---
+ src/drivers/driver_nl80211.c | 3 ++-
+ 1 file changed, 2 insertions(+), 1 deletion(-)
+
+diff --git a/src/drivers/driver_nl80211.c b/src/drivers/driver_nl80211.c
+index 8400e57..ccfc2d0 100644
+--- a/src/drivers/driver_nl80211.c
++++ b/src/drivers/driver_nl80211.c
+@@ -5126,7 +5126,8 @@ static int wpa_driver_nl80211_set_ap(void *priv,
+ 			   ret, strerror(-ret));
+ 		if (!bss->flink->beacon_set)
+ 			ret = 0;
+-		bss->flink->beacon_set = 0;
++		if (ret != -EBUSY)
++			bss->flink->beacon_set = 0;
+ 	} else {
+ 		bss->flink->beacon_set = 1;
+ 		nl80211_set_bss(bss, params->cts_protect, params->preamble,
+-- 
+2.18.0
+
diff --git a/autobuild_mac80211_release/mt7988_mt7996_mac80211/package/network/services/hostapd/patches/mtk-0103-hostapd-mtk-Add-BW320-channel-switch-command.patch b/autobuild_mac80211_release/mt7988_mt7996_mac80211/package/network/services/hostapd/patches/mtk-0103-hostapd-mtk-Add-BW320-channel-switch-command.patch
new file mode 100644
index 0000000..5d38688
--- /dev/null
+++ b/autobuild_mac80211_release/mt7988_mt7996_mac80211/package/network/services/hostapd/patches/mtk-0103-hostapd-mtk-Add-BW320-channel-switch-command.patch
@@ -0,0 +1,107 @@
+From e61b734969cd94121434adef85f241f835aa1f5a Mon Sep 17 00:00:00 2001
+From: Evelyn Tsai <evelyn.tsai@mediatek.com>
+Date: Thu, 11 May 2023 14:16:57 +0800
+Subject: [PATCH 103/103] hostapd: mtk: Add BW320 channel switch command
+
+---
+ hostapd/ctrl_iface.c              | 32 +++++++++++++++++++++++++++++++
+ src/ap/drv_callbacks.c            |  3 ++-
+ src/ap/hostapd.c                  |  4 ++++
+ src/drivers/driver_nl80211_capa.c |  2 ++
+ 4 files changed, 40 insertions(+), 1 deletion(-)
+
+diff --git a/hostapd/ctrl_iface.c b/hostapd/ctrl_iface.c
+index 2d99647..274d079 100644
+--- a/hostapd/ctrl_iface.c
++++ b/hostapd/ctrl_iface.c
+@@ -2713,6 +2713,38 @@ static int hostapd_ctrl_check_freq_params(struct hostapd_freq_params *params,
+ 			return -1;
+ 		}
+ 		break;
++	case 320:
++		if (!params->center_freq1 || params->center_freq2 ||
++		    !params->sec_channel_offset)
++			return -1;
++
++		switch (params->sec_channel_offset) {
++		case 1:
++			if (params->freq + 150 != params->center_freq1 &&
++			    params->freq + 110 != params->center_freq1 &&
++			    params->freq + 70 != params->center_freq1 &&
++			    params->freq + 30 != params->center_freq1 &&
++			    params->freq - 10 != params->center_freq1 &&
++			    params->freq - 50 != params->center_freq1 &&
++			    params->freq - 90 != params->center_freq1 &&
++			    params->freq - 130 != params->center_freq1)
++				return -1;
++			break;
++		case -1:
++			if (params->freq + 130 != params->center_freq1 &&
++			    params->freq + 90 != params->center_freq1 &&
++			    params->freq + 50 != params->center_freq1 &&
++			    params->freq + 10 != params->center_freq1 &&
++			    params->freq - 30 != params->center_freq1 &&
++			    params->freq - 70 != params->center_freq1 &&
++			    params->freq - 110 != params->center_freq1 &&
++			    params->freq - 150 != params->center_freq1)
++				return -1;
++			break;
++		default:
++			return -1;
++		}
++		break;
+ 	default:
+ 		return -1;
+ 	}
+diff --git a/src/ap/drv_callbacks.c b/src/ap/drv_callbacks.c
+index c1f9a0e..dccbdb6 100644
+--- a/src/ap/drv_callbacks.c
++++ b/src/ap/drv_callbacks.c
+@@ -988,7 +988,8 @@ void hostapd_event_ch_switch(struct hostapd_data *hapd, int freq, int ht,
+ 	hapd->iconf->ch_switch_eht_config = 0;
+ 
+ 	if (width == CHAN_WIDTH_40 || width == CHAN_WIDTH_80 ||
+-	    width == CHAN_WIDTH_80P80 || width == CHAN_WIDTH_160)
++	    width == CHAN_WIDTH_80P80 || width == CHAN_WIDTH_160 ||
++	    width == CHAN_WIDTH_320)
+ 		hapd->iconf->ht_capab |= HT_CAP_INFO_SUPP_CHANNEL_WIDTH_SET;
+ 	else if (width == CHAN_WIDTH_20 || width == CHAN_WIDTH_20_NOHT)
+ 		hapd->iconf->ht_capab &= ~HT_CAP_INFO_SUPP_CHANNEL_WIDTH_SET;
+diff --git a/src/ap/hostapd.c b/src/ap/hostapd.c
+index 9bd81d3..6fd5947 100644
+--- a/src/ap/hostapd.c
++++ b/src/ap/hostapd.c
+@@ -3705,6 +3705,7 @@ static int hostapd_change_config_freq(struct hostapd_data *hapd,
+ 	case 40:
+ 	case 80:
+ 	case 160:
++	case 320:
+ 		conf->ht_capab |= HT_CAP_INFO_SUPP_CHANNEL_WIDTH_SET;
+ 		break;
+ 	default:
+@@ -3777,6 +3778,9 @@ static int hostapd_fill_csa_settings(struct hostapd_data *hapd,
+ 	case 160:
+ 		bandwidth = CONF_OPER_CHWIDTH_160MHZ;
+ 		break;
++	case 320:
++		bandwidth = CONF_OPER_CHWIDTH_320MHZ;
++		break;
+ 	default:
+ 		bandwidth = CONF_OPER_CHWIDTH_USE_HT;
+ 		break;
+diff --git a/src/drivers/driver_nl80211_capa.c b/src/drivers/driver_nl80211_capa.c
+index 7b5079b..1a53ade 100644
+--- a/src/drivers/driver_nl80211_capa.c
++++ b/src/drivers/driver_nl80211_capa.c
+@@ -1701,6 +1701,8 @@ static void phy_info_freq(struct hostapd_hw_modes *mode,
+ 		chan->allowed_bw &= ~HOSTAPD_CHAN_WIDTH_80;
+ 	if (tb_freq[NL80211_FREQUENCY_ATTR_NO_160MHZ])
+ 		chan->allowed_bw &= ~HOSTAPD_CHAN_WIDTH_160;
++	if (tb_freq[NL80211_FREQUENCY_ATTR_NO_320MHZ])
++		chan->allowed_bw &= ~HOSTAPD_CHAN_WIDTH_320;
+ 
+ 	if (tb_freq[NL80211_FREQUENCY_ATTR_DFS_STATE]) {
+ 		enum nl80211_dfs_state state =
+-- 
+2.18.0
+