[][MAC80211][hostapd][refactor AP/STA CSA handling flow]

[Description]
Refactor AP/STA CSA handling flow.

There were two problems in the original CSA handling flow.
1. STA could not differentiate 20 MHz from 40 MHz when parsing CSA IE.
2. STA did not support a channel switch to 320 MHz.

These problems were mostly caused by hostapd/ma`c80211 not following new
802.11 standard.
To fix above two problems, a new CSA flow that follows new 802.11
standard is added.

In the AP side:
1. when creating Wide Bandwidth Channel Switch IE, fill the subfields
   according to band and PHY mode
   a. 2 GHz: no such IE
   b. 5 GHz: VHT operation
   c. 6 GHz: VHT operation in HE mode and HE operation in EHT mode

In the STA side:
1. Add the utilities to convert op_class to nl80211_chan_def
2. There are two way to convert CSA-related IEs to
   nl80211_chan_def
    a. use the subfield op_class from ECSA, then convert it to
       nl80211_chan_def by utilities added in item 1.
    b. use the Wide Bandwidth Channel Switch IE to fill VHT/HE
       operation, then convert it to nl80211_chan_def. This way is
       prefered. This way is used only if the ECSA IE is not presented.

In 6 GHz, because of the ambiguous definition of the subfields of the
Wide Bandwidth Channel Switch IE, we check the combination of new
channel width, ccfs0 and ccfs1 to build the correct chandef.

[Release-log]
N/A

Change-Id: I36ca00b30987de53914c0c3122dcef62de996fc3
Reviewed-on: https://gerrit.mediatek.inc/c/openwrt/feeds/mtk_openwrt_feeds/+/7921181
diff --git a/autobuild_mac80211_release/package/kernel/mac80211_dev/patches/subsys/mtk-0022-mac80211-mtk-Add-utilities-for-converting-op_class.patch b/autobuild_mac80211_release/package/kernel/mac80211_dev/patches/subsys/mtk-0022-mac80211-mtk-Add-utilities-for-converting-op_class.patch
new file mode 100644
index 0000000..e32ba2f
--- /dev/null
+++ b/autobuild_mac80211_release/package/kernel/mac80211_dev/patches/subsys/mtk-0022-mac80211-mtk-Add-utilities-for-converting-op_class.patch
@@ -0,0 +1,201 @@
+From 979c688e54a73cfedb8757881a95c4f6c795023a Mon Sep 17 00:00:00 2001
+From: Michael-CY Lee <michael-cy.lee@mediatek.com>
+Date: Mon, 14 Aug 2023 18:03:29 +0800
+Subject: mac80211: mtk: Add utilities for converting op_class
+
+These utilities include converting op_class to nl80211 channel width and
+center frequency.
+
+Signed-off-by: Michael-CY Lee <michael-cy.lee@mediatek.com>
+---
+ include/net/cfg80211.h |  25 ++++++++
+ net/wireless/util.c    | 130 ++++++++++++++++++++++++++++++++++++++++-
+ 2 files changed, 154 insertions(+), 1 deletion(-)
+
+diff --git a/include/net/cfg80211.h b/include/net/cfg80211.h
+index cfaa3d6..bea7d25 100644
+--- a/include/net/cfg80211.h
++++ b/include/net/cfg80211.h
+@@ -8693,6 +8693,31 @@ void cfg80211_ch_switch_started_notify(struct net_device *dev,
+ bool ieee80211_operating_class_to_band(u8 operating_class,
+ 				       enum nl80211_band *band);
+ 
++/**
++ * ieee80211_operating_class_to_center_freq - convert operating class to
++ * center frequency
++ *
++ * @operating_class: the operating class to convert
++ * @chan: the ieee80211_channel to convert
++ * @center_freq1: cneter frequency 1 pointer to fill
++ * @center_freq2: cneter frequency 2 pointer to fill
++ *
++ * Returns %true if the conversion was successful, %false otherwise.
++ */
++bool ieee80211_operating_class_to_center_freq(u8 operating_class,
++					      struct ieee80211_channel *chan,
++					      u32 *center_freq1,
++					      u32 *center_freq2);
++
++/**
++ * ieee80211_operating_class_to_chan_width - convert operating class to
++ * nl80211 channel width
++ *
++ * @operating_class: the operating class to convert
++ */
++enum nl80211_chan_width
++ieee80211_operating_class_to_chan_width(u8 operating_class);
++
+ /**
+  * ieee80211_chandef_to_operating_class - convert chandef to operation class
+  *
+diff --git a/net/wireless/util.c b/net/wireless/util.c
+index 1783ab9..13cb986 100644
+--- a/net/wireless/util.c
++++ b/net/wireless/util.c
+@@ -1981,7 +1981,7 @@ bool ieee80211_operating_class_to_band(u8 operating_class,
+ 	case 128 ... 130:
+ 		*band = NL80211_BAND_5GHZ;
+ 		return true;
+-	case 131 ... 135:
++	case 131 ... 137:
+ 		*band = NL80211_BAND_6GHZ;
+ 		return true;
+ 	case 81:
+@@ -1999,6 +1999,134 @@ bool ieee80211_operating_class_to_band(u8 operating_class,
+ }
+ EXPORT_SYMBOL(ieee80211_operating_class_to_band);
+ 
++bool ieee80211_operating_class_to_center_freq(u8 operating_class,
++					      struct ieee80211_channel *chan,
++					      u32 *center_freq1,
++					      u32 *center_freq2)
++{
++	u32 control_freq, offset;
++	enum nl80211_band band;
++
++	control_freq = chan->center_freq;
++	if (!ieee80211_operating_class_to_band(operating_class, &band))
++		return false;
++
++	if (band != chan->band)
++		return false;
++
++	if (control_freq >= 5955)
++		offset = control_freq - 5955;
++	else if (control_freq >= 5745)
++		offset = control_freq - 5745;
++	else if (control_freq >= 5180)
++		offset = control_freq - 5180;
++	offset /= 20;
++
++	*center_freq2 = 0;
++	switch (operating_class) {
++	case 81:  /* 2 GHz band; 20 MHz; channels 1..13 */
++	case 82:  /* 2 GHz band; 20 MHz; channel 14 */
++	case 115: /* 5 GHz band; 20 MHz; channels 36,40,44,48 */
++	case 118: /* 5 GHz band; 20 MHz; channels 52,56,60,64 */
++	case 121: /* 5 GHz band; 20 MHz; channels 100..144 */
++	case 124: /* 5 GHz band; 20 MHz; channels 149,153,157,161 */
++	case 125: /* 5 GHz band; 20 MHz; channels 149..177 */
++	case 131: /* 6 GHz band; 20 MHz; channels 1..233*/
++	case 136: /* 6 GHz band; 20 MHz; channel 2 */
++		*center_freq1 = control_freq;
++		return true;
++	case 83:  /* 2 GHz band; 40 MHz; channels 1..9 */
++	case 116: /* 5 GHz band; 40 MHz; channels 36,44 */
++	case 119: /* 5 GHz band; 40 MHz; channels 52,60 */
++	case 122: /* 5 GHz band; 40 MHz; channels 100,108,116,124,132,140 */
++	case 126: /* 5 GHz band; 40 MHz; channels 149,157,165,173 */
++		*center_freq1 = control_freq + 10;
++		return true;
++	case 84:  /* 2 GHz band; 40 MHz; channels 5..13 */
++	case 117: /* 5 GHz band; 40 MHz; channels 40,48 */
++	case 120: /* 5 GHz band; 40 MHz; channels 56,64 */
++	case 123: /* 5 GHz band; 40 MHz; channels 104,112,120,128,136,144 */
++	case 127: /* 5 GHz band; 40 MHz; channels 153,161,169,177 */
++		*center_freq1 = control_freq - 10;
++		return true;
++	case 132: /* 6 GHz band; 40 MHz; channels 1,5,..,229*/
++		*center_freq1 = control_freq + 10 - (offset & 1) * 20;
++		return true;
++	case 128: /* 5 GHz band; 80 MHz; channels 36..64,100..144,149..177 */
++		*center_freq1 = control_freq + 30 - (offset & 3) * 20;
++		return true;
++	case 130: /* 5 GHz band; 80+80 MHz; channels 36..64,100..144,149..177 */
++		/* TODO How to know the center_freq2 of 80+80 MHz?*/
++		*center_freq1 = 0;
++		return false;
++	case 133: /* 6 GHz band; 80 MHz; channels 1,5,..,229 */
++		*center_freq1 = control_freq + 30 - (offset & 3) * 20;
++		return true;
++	case 129: /* 5 GHz band; 160 MHz; channels 36..64,100..144,149..177 */
++		*center_freq1 = control_freq + 70 - (offset & 7) * 20;
++		return true;
++	case 134: /* 6 GHz band; 160 MHz; channels 1,5,..,229 */
++		*center_freq1 = control_freq + 70 - (offset & 7) * 20;
++		return true;
++	case 135: /* 6 GHz band; 80+80 MHz; channels 1,5,..,229 */
++		/* TODO How to know the center_freq2 of 80+80 MHz?*/
++		*center_freq1 = 0;
++		return false;
++	case 137: /* 6 GHz band; 320 MHz; channels 1,5,..,229 */
++		/* TODO it's 320-1 or 320-2 channelization? */
++		/* Currently convert to 320-1 */
++		*center_freq1 = control_freq + 150 - (offset & 15) * 20;
++		return true;
++	default:
++		return false;
++	}
++}
++EXPORT_SYMBOL(ieee80211_operating_class_to_center_freq);
++
++enum nl80211_chan_width
++ieee80211_operating_class_to_chan_width(u8 operating_class)
++{
++	switch (operating_class) {
++	case 81:  /* 2 GHz band; 20 MHz; channels 1..13 */
++	case 82:  /* 2 GHz band; 20 MHz; channel 14 */
++	case 115: /* 5 GHz band; 20 MHz; channels 36,40,44,48 */
++	case 118: /* 5 GHz band; 20 MHz; channels 52,56,60,64 */
++	case 121: /* 5 GHz band; 20 MHz; channels 100..144 */
++	case 124: /* 5 GHz band; 20 MHz; channels 149,153,157,161 */
++	case 125: /* 5 GHz band; 20 MHz; channels 149..177 */
++	case 131: /* 6 GHz band; 20 MHz; channels 1..233*/
++	case 136: /* 6 GHz band; 20 MHz; channel 2 */
++		return NL80211_CHAN_WIDTH_20;
++	case 83:  /* 2 GHz band; 40 MHz; channels 1..9 */
++	case 84:  /* 2 GHz band; 40 MHz; channels 5..13 */
++	case 116: /* 5 GHz band; 40 MHz; channels 36,44 */
++	case 117: /* 5 GHz band; 40 MHz; channels 40,48 */
++	case 119: /* 5 GHz band; 40 MHz; channels 52,60 */
++	case 120: /* 5 GHz band; 40 MHz; channels 56,64 */
++	case 122: /* 5 GHz band; 40 MHz; channels 100,108,116,124,132,140 */
++	case 123: /* 5 GHz band; 40 MHz; channels 104,112,120,128,136,144 */
++	case 126: /* 5 GHz band; 40 MHz; channels 149,157,165,173 */
++	case 127: /* 5 GHz band; 40 MHz; channels 153,161,169,177 */
++	case 132: /* 6 GHz band; 40 MHz; channels 1,5,..,229*/
++		return NL80211_CHAN_WIDTH_40;
++	case 128: /* 5 GHz band; 80 MHz; channels 36..64,100..144,149..177 */
++	case 133: /* 6 GHz band; 80 MHz; channels 1,5,..,229 */
++		return NL80211_CHAN_WIDTH_80;
++	case 130: /* 5 GHz band; 80+80 MHz; channels 36..64,100..144,149..177 */
++	case 135: /* 6 GHz band; 80+80 MHz; channels 1,5,..,229 */
++		return NL80211_CHAN_WIDTH_80P80;
++	case 129: /* 5 GHz band; 160 MHz; channels 36..64,100..144,149..177 */
++	case 134: /* 6 GHz band; 160 MHz; channels 1,5,..,229 */
++		return NL80211_CHAN_WIDTH_160;
++	case 137: /* 6 GHz band; 320 MHz; channels 1,5,..,229 */
++		return NL80211_CHAN_WIDTH_320;
++	default:
++		WARN_ON(1);
++		return NL80211_CHAN_WIDTH_20_NOHT;
++	}
++}
++EXPORT_SYMBOL(ieee80211_operating_class_to_chan_width);
++
+ bool ieee80211_chandef_to_operating_class(struct cfg80211_chan_def *chandef,
+ 					  u8 *op_class)
+ {
+-- 
+2.25.1
+
diff --git a/autobuild_mac80211_release/package/kernel/mac80211_dev/patches/subsys/mtk-0023-mac80211-mtk-change-STA-CSA-parsing-flows.patch b/autobuild_mac80211_release/package/kernel/mac80211_dev/patches/subsys/mtk-0023-mac80211-mtk-change-STA-CSA-parsing-flows.patch
new file mode 100644
index 0000000..54b59e1
--- /dev/null
+++ b/autobuild_mac80211_release/package/kernel/mac80211_dev/patches/subsys/mtk-0023-mac80211-mtk-change-STA-CSA-parsing-flows.patch
@@ -0,0 +1,598 @@
+From e7247da28b7d7e90abd9ced10438df1cbe59af7e Mon Sep 17 00:00:00 2001
+From: Michael-CY Lee <michael-cy.lee@mediatek.com>
+Date: Thu, 28 Sep 2023 09:28:50 +0800
+Subject: mac80211: mtk: refactor STA CSA parsing flows
+
+This patch changes the flows when STA parses csa IE:
+
+1. If Extended CSA IE is presented, this patch uses the subfield op_class
+   to build the VHT and HE operation in 5 GHz and 6 GHz, respectively.
+2. If Extended CSA IE is NOT presented but the Wide Bandwidth Channel
+   Switch IE is presented, the new channel width is at least 40 MHz.
+   Therefore this patch first prepares a 40 MHz chandef, then build the
+   VHT and HE operation in 5 GHz and 6 GHz, respectively.
+   Note that in a 6 GHz BSS, the subfield of Wide Bandwidth Channel Switch
+   IE might be the VHT, deprecated VHT or HE operation, so this patch
+   checks the combination of new channel width, ccfs0 and ccfs1 to build
+   the correct HE operation.
+3. From the HE/VHT operation created in step 1 or 2, this patch then
+   creates the chandef and assigns it to csa_ie.
+
+Signed-off-by: Michael-CY Lee <michael-cy.lee@mediatek.com>
+---
+ net/mac80211/spectmgmt.c | 508 ++++++++++++++++++++++++++++++++++-----
+ 1 file changed, 454 insertions(+), 54 deletions(-)
+
+diff --git a/net/mac80211/spectmgmt.c b/net/mac80211/spectmgmt.c
+index 871cdac..dee7a60 100644
+--- a/net/mac80211/spectmgmt.c
++++ b/net/mac80211/spectmgmt.c
+@@ -19,6 +19,332 @@
+ #include "sta_info.h"
+ #include "wme.h"
+ 
++static inline void
++op_class_to_6ghz_he_eht_oper(u8 op_class, struct ieee80211_channel *chan,
++			     struct ieee80211_he_operation *he_oper,
++			     struct ieee80211_eht_operation *eht_oper)
++{
++	u8 new_chan_width;
++	u32 he_oper_params, center_freq1 = 0, center_freq2 = 0;
++	struct ieee80211_he_6ghz_oper *he_6ghz_oper;
++	struct ieee80211_eht_operation_info *eht_oper_info;
++
++	new_chan_width = ieee80211_operating_class_to_chan_width(op_class);
++	if (!ieee80211_operating_class_to_center_freq(op_class, chan,
++						      &center_freq1,
++						      &center_freq2)) {
++		new_chan_width = NL80211_CHAN_WIDTH_20;
++		center_freq1 = chan->center_freq;
++	}
++
++	he_oper_params =
++		u32_encode_bits(1, IEEE80211_HE_OPERATION_6GHZ_OP_INFO);
++	he_oper->he_oper_params = cpu_to_le32(he_oper_params);
++
++	he_6ghz_oper = (struct ieee80211_he_6ghz_oper *)he_oper->optional;
++	he_6ghz_oper->primary =
++		ieee80211_frequency_to_channel(chan->center_freq);
++	he_6ghz_oper->ccfs0 = ieee80211_frequency_to_channel(center_freq1);
++	he_6ghz_oper->ccfs1 = center_freq2 ?
++		ieee80211_frequency_to_channel(center_freq2) : 0;
++
++	switch (new_chan_width) {
++	case NL80211_CHAN_WIDTH_320:
++		/* Cannot derive center frequency for 320 MHZ from op_class
++		 * since it might be 320-1 or 320-2
++		 */
++		WARN_ON(1);
++		break;
++	case NL80211_CHAN_WIDTH_160:
++		he_6ghz_oper->ccfs1 = he_6ghz_oper->ccfs0;
++		he_6ghz_oper->ccfs0 += chan->center_freq < center_freq1 ? -8 : 8;
++		fallthrough;
++	case NL80211_CHAN_WIDTH_80P80:
++		he_6ghz_oper->control =
++			IEEE80211_HE_6GHZ_OPER_CTRL_CHANWIDTH_160MHZ;
++		break;
++	case NL80211_CHAN_WIDTH_80:
++		he_6ghz_oper->control =
++			IEEE80211_HE_6GHZ_OPER_CTRL_CHANWIDTH_80MHZ;
++		break;
++	case NL80211_CHAN_WIDTH_40:
++		he_6ghz_oper->control =
++			IEEE80211_HE_6GHZ_OPER_CTRL_CHANWIDTH_40MHZ;
++		break;
++	default:
++		he_6ghz_oper->control =
++			IEEE80211_HE_6GHZ_OPER_CTRL_CHANWIDTH_20MHZ;
++		break;
++	}
++
++	eht_oper->params = IEEE80211_EHT_OPER_INFO_PRESENT;
++
++	eht_oper_info =
++		(struct ieee80211_eht_operation_info *)eht_oper->optional;
++	eht_oper_info->control = he_6ghz_oper->control;
++	eht_oper_info->ccfs0 = he_6ghz_oper->ccfs0;
++	eht_oper_info->ccfs1 = he_6ghz_oper->ccfs1;
++}
++
++static inline void
++wbcs_ie_to_6ghz_he_eht_oper(const struct ieee80211_wide_bw_chansw_ie *wbcs_ie,
++			    u8 new_chan_no,
++			    struct ieee80211_he_operation *he_oper,
++			    struct ieee80211_eht_operation *eht_oper)
++{
++	u32 he_oper_params;
++	struct ieee80211_he_6ghz_oper *he_6ghz_oper;
++	struct ieee80211_eht_operation_info *eht_oper_info;
++	bool fallback_20mhz;
++	u8 ccfs_diff;
++
++	he_oper_params =
++		u32_encode_bits(1, IEEE80211_HE_OPERATION_6GHZ_OP_INFO);
++	he_oper->he_oper_params = cpu_to_le32(he_oper_params);
++
++	he_6ghz_oper = (struct ieee80211_he_6ghz_oper *)he_oper->optional;
++	he_6ghz_oper->primary = new_chan_no;
++
++	/* The Wide Bandwidth Channel Switch IE in a 6 GHz BSS migth be
++	 * deprecated VHT operation, VHT operation (IEEE 802.11-2020 9.4.2.160)
++	 * or HE operation (IEEE P80211be D3.2 9.4.2.159).
++	 * Check the combination of width, ccfs0 and ccfs1 to build the correct
++	 * HE/EHT operation.
++	 */
++	he_6ghz_oper->ccfs0 = wbcs_ie->new_center_freq_seg0;
++	he_6ghz_oper->ccfs1 = wbcs_ie->new_center_freq_seg1;
++	switch (wbcs_ie->new_channel_width) {
++	case 0:
++		/* Must be [deprecated] VHT operation with 40 MHz bandwidth */
++		he_6ghz_oper->control =
++			IEEE80211_HE_6GHZ_OPER_CTRL_CHANWIDTH_40MHZ;
++		break;
++	case 1:
++		if (he_6ghz_oper->ccfs1) {
++			/* VHT operation with 160/80P80 MHz bandwidth */
++			he_6ghz_oper->control =
++				IEEE80211_HE_6GHZ_OPER_CTRL_CHANWIDTH_160MHZ;
++		} else if ((he_6ghz_oper->ccfs0 - 7) % 16 == 0) {
++			/* [deprecated] VHT operation with 80 MHz bandwidth */
++			he_6ghz_oper->control =
++				IEEE80211_HE_6GHZ_OPER_CTRL_CHANWIDTH_80MHZ;
++		} else {
++			/* HE operation with 40 MHz bandwidth */
++			he_6ghz_oper->control =
++				IEEE80211_HE_6GHZ_OPER_CTRL_CHANWIDTH_40MHZ;
++		}
++		break;
++	case 2:
++		if ((he_6ghz_oper->ccfs0 - 15) % 32 == 0) {
++			/* deprecated VHT operation with 160 MHz bandwidth */
++			he_6ghz_oper->control =
++				IEEE80211_HE_6GHZ_OPER_CTRL_CHANWIDTH_160MHZ;
++			he_6ghz_oper->ccfs1 = he_6ghz_oper->ccfs0;
++			he_6ghz_oper->ccfs0 +=
++				new_chan_no < he_6ghz_oper->ccfs0 ? -8 : 8;
++		} else {
++			/* HE operation with 80 MHz bandwidth */
++			he_6ghz_oper->control =
++				IEEE80211_HE_6GHZ_OPER_CTRL_CHANWIDTH_80MHZ;
++		}
++		break;
++	case 3:
++		/* Can be
++		 * 1. deprecated VHT operation with 80P80 MHz bandwidth
++		 * 2. HE operation with 160/80P80 MHz bandwidth
++		 */
++		he_6ghz_oper->control =
++			IEEE80211_HE_6GHZ_OPER_CTRL_CHANWIDTH_160MHZ;
++		break;
++	case 4:
++		/* 320 MHz bandwidth
++		 * TODO channel switch to 320 MHz bandwidth should be indiated
++		 * by Bandwidth Indication IE (IEEE P80211be D3.2 9.4.2.159)
++		 */
++		he_6ghz_oper->control = IEEE80211_EHT_OPER_CHAN_WIDTH_320MHZ;
++		break;
++	default:
++		/* Ignore invalid width */
++		break;
++	}
++
++	/* Validate the relationship between new channel width and center frequency
++	 * segments, and fallback to 20 MHz if the relationship is wrong.
++	 */
++	fallback_20mhz = false;
++	switch (he_6ghz_oper->control) {
++	case IEEE80211_HE_6GHZ_OPER_CTRL_CHANWIDTH_40MHZ:
++		if ((he_6ghz_oper->ccfs0 - 3) % 8 != 0)
++			fallback_20mhz = true;
++		break;
++	case IEEE80211_HE_6GHZ_OPER_CTRL_CHANWIDTH_80MHZ:
++		if ((he_6ghz_oper->ccfs0 - 7) % 16 != 0)
++			fallback_20mhz = true;
++		break;
++	case IEEE80211_HE_6GHZ_OPER_CTRL_CHANWIDTH_160MHZ:
++		ccfs_diff = abs(he_6ghz_oper->ccfs1 - he_6ghz_oper->ccfs0);
++		if ((ccfs_diff == 8 && (he_6ghz_oper->ccfs1 - 15) % 32 != 0) ||
++		    (ccfs_diff > 16 && ((he_6ghz_oper->ccfs0 - 7) % 16 != 0 ||
++		    (he_6ghz_oper->ccfs1 - 7) % 16 != 0)))
++			fallback_20mhz = true;
++		break;
++	case IEEE80211_EHT_OPER_CHAN_WIDTH_320MHZ:
++		if ((he_6ghz_oper->ccfs1 - 31) % 32 != 0)
++			fallback_20mhz = true;
++		break;
++	}
++
++	if (fallback_20mhz) {
++		he_6ghz_oper->control =
++			IEEE80211_HE_6GHZ_OPER_CTRL_CHANWIDTH_20MHZ;
++		he_6ghz_oper->ccfs0 = he_6ghz_oper->primary;
++		he_6ghz_oper->ccfs1 = 0;
++	}
++
++	eht_oper->params = IEEE80211_EHT_OPER_INFO_PRESENT;
++	eht_oper_info =
++		(struct ieee80211_eht_operation_info *)eht_oper->optional;
++	eht_oper_info->control = he_6ghz_oper->control;
++	eht_oper_info->ccfs0 = he_6ghz_oper->ccfs0;
++	eht_oper_info->ccfs1 = he_6ghz_oper->ccfs1;
++}
++
++static inline void
++op_class_to_ht_vht_oper(u8 op_class, struct ieee80211_channel *chan,
++			struct ieee80211_ht_operation *ht_oper,
++			struct ieee80211_vht_operation *vht_oper)
++{
++	u8 new_chan_width;
++	u32 center_freq1 = 0, center_freq2 = 0;
++
++	new_chan_width = ieee80211_operating_class_to_chan_width(op_class);
++	if (!ieee80211_operating_class_to_center_freq(op_class, chan,
++						      &center_freq1,
++						      &center_freq2)) {
++		new_chan_width = NL80211_CHAN_WIDTH_20;
++		center_freq1 = chan->center_freq;
++	}
++
++	vht_oper->center_freq_seg0_idx =
++		ieee80211_frequency_to_channel(center_freq1);
++	vht_oper->center_freq_seg1_idx = center_freq2 ?
++		ieee80211_frequency_to_channel(center_freq2) : 0;
++
++	ht_oper->ht_param = (chan->center_freq / 20) & 1 ?
++				IEEE80211_HT_PARAM_CHA_SEC_ABOVE :
++				IEEE80211_HT_PARAM_CHA_SEC_BELOW;
++
++	switch (new_chan_width) {
++	case NL80211_CHAN_WIDTH_320:
++		WARN_ON(1);
++		break;
++	case NL80211_CHAN_WIDTH_160:
++		vht_oper->chan_width = IEEE80211_VHT_CHANWIDTH_80MHZ;
++		vht_oper->center_freq_seg1_idx = vht_oper->center_freq_seg0_idx;
++		vht_oper->center_freq_seg0_idx +=
++			chan->center_freq < center_freq1 ? -8 : 8;
++		break;
++	case NL80211_CHAN_WIDTH_80P80:
++		vht_oper->chan_width = IEEE80211_VHT_CHANWIDTH_80MHZ;
++		break;
++	case NL80211_CHAN_WIDTH_80:
++		vht_oper->chan_width = IEEE80211_VHT_CHANWIDTH_80MHZ;
++		break;
++	default:
++		vht_oper->chan_width = IEEE80211_VHT_CHANWIDTH_USE_HT;
++		if (chan->center_freq != center_freq1)
++			ht_oper->ht_param = chan->center_freq > center_freq1 ?
++				IEEE80211_HT_PARAM_CHA_SEC_BELOW :
++				IEEE80211_HT_PARAM_CHA_SEC_ABOVE;
++		else
++			ht_oper->ht_param = IEEE80211_HT_PARAM_CHA_SEC_NONE;
++	}
++
++	ht_oper->operation_mode =
++		cpu_to_le16(vht_oper->center_freq_seg1_idx <<
++				IEEE80211_HT_OP_MODE_CCFS2_SHIFT);
++}
++
++static inline void
++wbcs_ie_to_ht_vht_oper(struct ieee80211_channel *chan,
++		       const struct ieee80211_wide_bw_chansw_ie *wbcs_ie,
++		       struct ieee80211_ht_operation *ht_oper,
++		       struct ieee80211_vht_operation *vht_oper)
++{
++	u8 new_chan_width, new_ccfs0, new_ccfs1;
++	bool fallback_20mhz;
++
++	new_chan_width = wbcs_ie->new_channel_width;
++	new_ccfs0 = wbcs_ie->new_center_freq_seg0;
++	new_ccfs1 = wbcs_ie->new_center_freq_seg1;
++
++	/* Validate the relationship between new channel width and center frequency
++	 * segments, and fallback to 20 MHz if the relationship is wrong.
++	 */
++	fallback_20mhz = false;
++	switch (new_chan_width) {
++	case IEEE80211_VHT_CHANWIDTH_USE_HT:
++		/* If the wide bandwidth channel switch IE is presented,
++		 * the new channel width is at least 40 MHz.
++		 */
++		if (!new_ccfs1) {
++			new_ccfs0 -= (new_ccfs0 >= 149) ? 151 : 38;
++			if (new_ccfs0 % 8 != 0)
++				fallback_20mhz = true;
++		} else {
++			fallback_20mhz = true;
++		}
++		break;
++	case IEEE80211_VHT_CHANWIDTH_80MHZ:
++		if (!new_ccfs1) {
++			new_ccfs0 -= (new_ccfs0 >= 149) ? 155 : 42;
++			if (new_ccfs0 % 16 != 0)
++				fallback_20mhz = true;
++			break;
++		} else if (abs(new_ccfs1 - new_ccfs0) == 8) {
++			new_ccfs0 = new_ccfs1;
++			new_ccfs1 = 0;
++		}
++		fallthrough;
++	case IEEE80211_VHT_CHANWIDTH_160MHZ:
++		if (!new_ccfs1) {
++			if (new_ccfs0 != 50 && new_ccfs0 != 114 && new_ccfs0 != 163)
++				fallback_20mhz = true;
++			break;
++		}
++		fallthrough;
++	case IEEE80211_VHT_CHANWIDTH_80P80MHZ:
++		new_ccfs0 -= (new_ccfs0 >= 149) ? 155 : 42;
++		new_ccfs1 -= (new_ccfs1 >= 149) ? 155 : 42;
++		if (new_ccfs0 % 16 != 0 || new_ccfs1 % 16 != 0)
++			fallback_20mhz = true;
++		break;
++	default:
++		fallback_20mhz = true;
++	}
++
++	if (fallback_20mhz) {
++		ht_oper->ht_param = IEEE80211_HT_PARAM_CHA_SEC_NONE;
++
++		vht_oper->chan_width = IEEE80211_VHT_CHANWIDTH_USE_HT;
++		vht_oper->center_freq_seg0_idx =
++			ieee80211_frequency_to_channel(chan->center_freq);
++		vht_oper->center_freq_seg1_idx = 0;
++
++	} else {
++		ht_oper->ht_param = (chan->center_freq / 20) & 1 ?
++					IEEE80211_HT_PARAM_CHA_SEC_ABOVE :
++					IEEE80211_HT_PARAM_CHA_SEC_BELOW;
++
++		vht_oper->chan_width = new_chan_width;
++		vht_oper->center_freq_seg0_idx = wbcs_ie->new_center_freq_seg0;
++		vht_oper->center_freq_seg1_idx = wbcs_ie->new_center_freq_seg1;
++	}
++
++	ht_oper->operation_mode = cpu_to_le16(vht_oper->center_freq_seg1_idx <<
++					      IEEE80211_HT_OP_MODE_CCFS2_SHIFT);
++}
++
+ int ieee80211_parse_ch_switch_ie(struct ieee80211_sub_if_data *sdata,
+ 				 struct ieee802_11_elems *elems,
+ 				 enum nl80211_band current_band,
+@@ -26,19 +352,27 @@ int ieee80211_parse_ch_switch_ie(struct ieee80211_sub_if_data *sdata,
+ 				 ieee80211_conn_flags_t conn_flags, u8 *bssid,
+ 				 struct ieee80211_csa_ie *csa_ie)
+ {
++	struct ieee80211_supported_band *sband;
+ 	enum nl80211_band new_band = current_band;
+-	int new_freq;
+-	u8 new_chan_no;
++	int new_freq, size;
++	u8 new_chan_no = 0, new_op_class = 0;
+ 	struct ieee80211_channel *new_chan;
+-	struct cfg80211_chan_def new_vht_chandef = {};
++	struct cfg80211_chan_def new_chandef = {};
+ 	const struct ieee80211_sec_chan_offs_ie *sec_chan_offs;
+ 	const struct ieee80211_wide_bw_chansw_ie *wide_bw_chansw_ie;
++	const struct ieee80211_ext_chansw_ie *ext_chansw_ie;
++	struct ieee80211_ht_operation *ht_oper;
++	struct ieee80211_vht_operation *vht_oper;
++	struct ieee80211_he_operation *he_oper;
++	struct ieee80211_eht_operation *eht_oper;
++	struct ieee80211_sta_ht_cap sta_ht_cap;
+ 	int secondary_channel_offset = -1;
+ 
+ 	memset(csa_ie, 0, sizeof(*csa_ie));
+ 
+ 	sec_chan_offs = elems->sec_chan_offs;
+ 	wide_bw_chansw_ie = elems->wide_bw_chansw_ie;
++	ext_chansw_ie = elems->ext_chansw_ie;
+ 
+ 	if (conn_flags & (IEEE80211_CONN_DISABLE_HT |
+ 			  IEEE80211_CONN_DISABLE_40MHZ)) {
+@@ -46,29 +380,30 @@ int ieee80211_parse_ch_switch_ie(struct ieee80211_sub_if_data *sdata,
+ 		wide_bw_chansw_ie = NULL;
+ 	}
+ 
+-	if (conn_flags & IEEE80211_CONN_DISABLE_VHT)
+-		wide_bw_chansw_ie = NULL;
+-
+-	if (elems->ext_chansw_ie) {
+-		if (!ieee80211_operating_class_to_band(
+-				elems->ext_chansw_ie->new_operating_class,
+-				&new_band)) {
+-			sdata_info(sdata,
+-				   "cannot understand ECSA IE operating class, %d, ignoring\n",
+-				   elems->ext_chansw_ie->new_operating_class);
++	if (ext_chansw_ie) {
++		new_op_class = ext_chansw_ie->new_operating_class;
++		if (!ieee80211_operating_class_to_band(new_op_class, &new_band)) {
++			new_op_class = 0;
++			sdata_info(sdata, "cannot understand ECSA IE "
++					  "operating class, %d, ignoring\n",
++				   ext_chansw_ie->new_operating_class);
++		} else {
++			new_chan_no = ext_chansw_ie->new_ch_num;
++			csa_ie->count = ext_chansw_ie->count;
++			csa_ie->mode = ext_chansw_ie->mode;
+ 		}
+-		new_chan_no = elems->ext_chansw_ie->new_ch_num;
+-		csa_ie->count = elems->ext_chansw_ie->count;
+-		csa_ie->mode = elems->ext_chansw_ie->mode;
+-	} else if (elems->ch_switch_ie) {
++	}
++
++	if (!new_op_class && elems->ch_switch_ie) {
+ 		new_chan_no = elems->ch_switch_ie->new_ch_num;
+ 		csa_ie->count = elems->ch_switch_ie->count;
+ 		csa_ie->mode = elems->ch_switch_ie->mode;
+-	} else {
+-		/* nothing here we understand */
+-		return 1;
+ 	}
+ 
++	/* nothing here we understand */
++	if (!new_chan_no)
++		return 1;
++
+ 	/* Mesh Channel Switch Parameters Element */
+ 	if (elems->mesh_chansw_params_ie) {
+ 		csa_ie->ttl = elems->mesh_chansw_params_ie->mesh_ttl;
+@@ -132,54 +467,119 @@ int ieee80211_parse_ch_switch_ie(struct ieee80211_sub_if_data *sdata,
+ 		break;
+ 	}
+ 
+-	if (wide_bw_chansw_ie) {
+-		u8 new_seg1 = wide_bw_chansw_ie->new_center_freq_seg1;
+-		struct ieee80211_vht_operation vht_oper = {
+-			.chan_width =
+-				wide_bw_chansw_ie->new_channel_width,
+-			.center_freq_seg0_idx =
+-				wide_bw_chansw_ie->new_center_freq_seg0,
+-			.center_freq_seg1_idx = new_seg1,
+-			/* .basic_mcs_set doesn't matter */
+-		};
+-		struct ieee80211_ht_operation ht_oper = {
+-			.operation_mode =
+-				cpu_to_le16(new_seg1 <<
+-					    IEEE80211_HT_OP_MODE_CCFS2_SHIFT),
+-		};
+-
+-		/* default, for the case of IEEE80211_VHT_CHANWIDTH_USE_HT,
+-		 * to the previously parsed chandef
+-		 */
+-		new_vht_chandef = csa_ie->chandef;
++	if (new_band == NL80211_BAND_6GHZ) {
++		size = sizeof(struct ieee80211_he_operation) +
++		       sizeof(struct ieee80211_he_6ghz_oper);
++		he_oper = kzalloc(size, GFP_KERNEL);
++		if (!he_oper)
++			return -ENOMEM;
++
++		size = sizeof(struct ieee80211_eht_operation) +
++		       sizeof(struct ieee80211_eht_operation_info);
++		eht_oper = kzalloc(size, GFP_KERNEL);
++		if (!eht_oper) {
++			kfree(he_oper);
++			return -ENOMEM;
++		}
++
++		if (new_op_class && new_op_class != 135 && new_op_class != 137) {
++			/* There is no way to tell the ccfs1 for op_class 135
++			 * (80P80 MHz) and 137 (320 MHz).
++			 */
++			op_class_to_6ghz_he_eht_oper(new_op_class, new_chan,
++						     he_oper, eht_oper);
++		} else if (wide_bw_chansw_ie) {
++			wbcs_ie_to_6ghz_he_eht_oper(wide_bw_chansw_ie,
++						    new_chan_no, he_oper,
++						    eht_oper);
++		}
++
++		new_chandef = csa_ie->chandef;
+ 
+ 		/* ignore if parsing fails */
+-		if (!ieee80211_chandef_vht_oper(&sdata->local->hw,
+-						vht_cap_info,
+-						&vht_oper, &ht_oper,
+-						&new_vht_chandef))
+-			new_vht_chandef.chan = NULL;
++		if (!ieee80211_chandef_he_6ghz_oper(sdata, he_oper, eht_oper,
++						    &new_chandef))
++			new_chandef.chan = NULL;
++
++		kfree(he_oper);
++		kfree(eht_oper);
++	} else {
++		sband = sdata->local->hw.wiphy->bands[new_band];
++		memcpy(&sta_ht_cap, &sband->ht_cap, sizeof(sta_ht_cap));
++		ieee80211_apply_htcap_overrides(sdata, &sta_ht_cap);
++
++		if (!sta_ht_cap.ht_supported ||
++		    !(sta_ht_cap.cap & IEEE80211_HT_CAP_SUP_WIDTH_20_40))
++			goto out;
++
++		ht_oper = kzalloc(sizeof(*ht_oper), GFP_KERNEL);
++		if (!ht_oper)
++			return -ENOMEM;
++
++		vht_oper = kzalloc(sizeof(*vht_oper), GFP_KERNEL);
++		if (!vht_oper) {
++			kfree(ht_oper);
++			return -ENOMEM;
++		}
++
++		if (new_op_class && new_op_class != 130) {
++			/* There is no way to tell the ccfs1 for op_class 130
++			 * (80P80 MHz).
++			 */
++			op_class_to_ht_vht_oper(new_op_class, new_chan, ht_oper,
++						vht_oper);
++		} else if (wide_bw_chansw_ie && new_band == NL80211_BAND_5GHZ &&
++			   sband->vht_cap.vht_supported) {
++			/* It is assumed that there is no WBCS IE in the beacon
++			 * from a 2 GHz BSS during a channel switch.
++			 */
++			wbcs_ie_to_ht_vht_oper(new_chan, wide_bw_chansw_ie,
++					       ht_oper, vht_oper);
++		} else {
++			kfree(ht_oper);
++			kfree(vht_oper);
++			goto out;
++		}
++
++		new_chandef = csa_ie->chandef;
++
++		ieee80211_chandef_ht_oper(ht_oper, &new_chandef);
++
++		/* ignore if parsing fails */
++		if (sband->vht_cap.vht_supported &&
++		    !ieee80211_chandef_vht_oper(&sdata->local->hw, vht_cap_info,
++						vht_oper, ht_oper, &new_chandef))
++			new_chandef.chan = NULL;
++
++		kfree(ht_oper);
++		kfree(vht_oper);
++	}
++
++	if (new_chandef.chan) {
++		if (conn_flags & IEEE80211_CONN_DISABLE_320MHZ &&
++		    new_chandef.width == NL80211_CHAN_WIDTH_320)
++			ieee80211_chandef_downgrade(&new_chandef);
+ 
+ 		if (conn_flags & IEEE80211_CONN_DISABLE_80P80MHZ &&
+-		    new_vht_chandef.width == NL80211_CHAN_WIDTH_80P80)
+-			ieee80211_chandef_downgrade(&new_vht_chandef);
++		    new_chandef.width == NL80211_CHAN_WIDTH_80P80)
++			ieee80211_chandef_downgrade(&new_chandef);
++
+ 		if (conn_flags & IEEE80211_CONN_DISABLE_160MHZ &&
+-		    new_vht_chandef.width == NL80211_CHAN_WIDTH_160)
+-			ieee80211_chandef_downgrade(&new_vht_chandef);
+-	}
++		    new_chandef.width == NL80211_CHAN_WIDTH_160)
++			ieee80211_chandef_downgrade(&new_chandef);
+ 
+-	/* if VHT data is there validate & use it */
+-	if (new_vht_chandef.chan) {
+-		if (!cfg80211_chandef_compatible(&new_vht_chandef,
++		if (!cfg80211_chandef_compatible(&new_chandef,
+ 						 &csa_ie->chandef)) {
+ 			sdata_info(sdata,
+ 				   "BSS %pM: CSA has inconsistent channel data, disconnecting\n",
+ 				   bssid);
+ 			return -EINVAL;
+ 		}
+-		csa_ie->chandef = new_vht_chandef;
++
++		csa_ie->chandef = new_chandef;
+ 	}
+ 
++out:
+ 	if (elems->max_channel_switch_time)
+ 		csa_ie->max_switch_time =
+ 			(elems->max_channel_switch_time[0] << 0) |
+-- 
+2.25.1
+
diff --git a/autobuild_mac80211_release/package/network/services/hostapd_new/patches/mtk-0043-hostapd-mtk-change-the-flow-to-create-Wide-Bandwidth.patch b/autobuild_mac80211_release/package/network/services/hostapd_new/patches/mtk-0043-hostapd-mtk-change-the-flow-to-create-Wide-Bandwidth.patch
new file mode 100644
index 0000000..f02f935
--- /dev/null
+++ b/autobuild_mac80211_release/package/network/services/hostapd_new/patches/mtk-0043-hostapd-mtk-change-the-flow-to-create-Wide-Bandwidth.patch
@@ -0,0 +1,168 @@
+From 92caaf40a058d4eac8061c0e3240f0b23aba69ce Mon Sep 17 00:00:00 2001
+From: Michael-CY Lee <michael-cy.lee@mediatek.com>
+Date: Thu, 24 Aug 2023 10:04:15 +0800
+Subject: hostapd: mtk: refactor the flow to create Wide Bandwidth
+ Channel Switch IE
+
+This patch changes the flow to create Wide Bandwidth Channel Switch IE:
+1. 2 GHz: Wide Bandwidth Channel Switch IE should not present.
+2. 5 GHz: fill the subfields according to VHT operation.
+3. 6 GHz: fill the subfields according to VHT operation and HE operation
+   in HE mode and EHT mode, respectively.
+   This is because the definition of the subfields of Wide Bandwidth
+   Channel Switch IE is ambiguous:
+   1. 802.11ac: the definition of subfields follows VHT operation
+      (IEEE80211-2020 9.4.2.160)
+   2. 802.11ax: the definition of subfields is not specified
+   3. 802.11be: the definition of subfields follows VHT operation in 5
+      GHz and HE operation in 6 GHz (IEEE P802.11be D3.2 9.4.2.159)
+
+To support 320 MHz
+   channel switch, set width to 4
+
+Signed-off-by: Michael-CY Lee <michael-cy.lee@mediatek.com>
+---
+ src/ap/ieee802_11.c | 99 ++++++++++++++++++++++++++++++++++-----------
+ 1 file changed, 76 insertions(+), 23 deletions(-)
+
+diff --git a/src/ap/ieee802_11.c b/src/ap/ieee802_11.c
+index ef520c8..5f4d78f 100755
+--- a/src/ap/ieee802_11.c
++++ b/src/ap/ieee802_11.c
+@@ -7065,57 +7065,110 @@ u8 * hostapd_eid_txpower_envelope(struct hostapd_data *hapd, u8 *eid)
+ 
+ u8 * hostapd_eid_wb_chsw_wrapper(struct hostapd_data *hapd, u8 *eid)
+ {
+-	u8 bw, chan1, chan2 = 0;
+-	int freq1;
++	u8 new_bw_field, ccfs0_chan, ccfs1_chan = 0;
++	int ccfs0_freq = 0, ccfs1_freq = 0;
++	int control_freq, center_freq1, center_freq2, bandwidth;
++	int base_freq, offset;
++	bool is_6ghz, use_he_oper;
+ 
+ 	if (!hapd->cs_freq_params.channel ||
++	    hapd->cs_freq_params.bandwidth == 20 ||
+ 	    (!hapd->cs_freq_params.vht_enabled &&
+ 	     !hapd->cs_freq_params.he_enabled &&
+ 	     !hapd->cs_freq_params.eht_enabled))
+ 		return eid;
+ 
+-	/* bandwidth: 0: 40, 1: 80, 2: 160, 3: 80+80, 4: 320 */
+-	switch (hapd->cs_freq_params.bandwidth) {
++	control_freq = hapd->cs_freq_params.freq;
++	center_freq1 = hapd->cs_freq_params.center_freq1;
++	center_freq2 = hapd->cs_freq_params.center_freq2;
++	bandwidth = hapd->cs_freq_params.bandwidth;
++
++	/* center_freq2 is used if and only if bandwidth is
++	 * 80+80 MHz and phy mode is not EHT
++	 */
++	if (center_freq2 &&
++	    (bandwidth != 80 || hapd->cs_freq_params.eht_enabled))
++		return eid;
++
++	is_6ghz = is_6ghz_freq(control_freq);
++	use_he_oper = is_6ghz && hapd->cs_freq_params.eht_enabled;
++	base_freq = is_6ghz ? 5955 : 5180;
++
++	/* About the subfields of the Wide Bandwidth Channel Switch IE,
++	 * IEEE802.11-2020 9.4.2.160 specifies that the subfields New
++	 * Channel Width, New Channel Center Frequency Segment 0 and New
++	 * Channel Center Frequency Segment 1 have the same definition as
++	 * they are in the VHT operation information field.
++	 * However, the standard does not specify the definition of these
++	 * subfields when it comes to HE phy-mode in 6 GHz.
++	 * And in IEEE P802.11be D3.2 9.4.2.159, it specifies that the
++	 * defition should follow VHT operation in 5 GHz, and follow HE
++	 * oepration in 6 GHz.
++	 * Problem happens here for some HE STAs in 6 GHz, they might still
++	 * use VHT operation to parse these subfields.
++	 *
++	 * Here we follow the new Standard to build the IE, meanwhile we have
++	 * a workaround for HE mode in 6 GHz.
++	 *
++	 * 5 GHz: VHT operation
++	 * HE mode in 6 GHz: VHT operation
++	 * EHT mode in 6 GHz: HE operation
++	 */
++	ccfs0_freq = center_freq1;
++	ccfs1_freq = center_freq2;
++	switch (bandwidth) {
+ 	case 40:
+-		bw = 0;
++		new_bw_field = use_he_oper ? 1 : 0;
+ 		break;
+ 	case 80:
+-		/* check if it's 80+80 */
+-		if (!hapd->cs_freq_params.center_freq2)
+-			bw = 1;
++		if (ccfs1_freq)
++			new_bw_field = use_he_oper ? 3 : 1;
+ 		else
+-			bw = 3;
++			new_bw_field = use_he_oper ? 2 : 1;
+ 		break;
+ 	case 160:
+-		bw = 2;
++		new_bw_field = use_he_oper ? 3 : 1;
++
++		/* ccfs0 is primary 80 MHz
++		 * ccfs1 is center frequency
++		 */
++		offset = (control_freq - base_freq) / 20;
++		ccfs0_freq = control_freq + 30 - (offset & 3) * 20;
++		ccfs1_freq = center_freq1;
+ 		break;
+ 	case 320:
+-		bw = 4;
++		/* TODO switch to bandwidth 320 MHz should be
++		 * indicated by Bandwidth indication IE.
++		 */
++		new_bw_field = 4;
++
++		/* ccfs0 is primary 160 MHz
++		 * ccfs1 is center frequency
++		 */
++		offset = (control_freq - base_freq) / 20;
++		ccfs0_freq = control_freq + 70 - (offset & 7) * 20;
++		ccfs1_freq = center_freq1;
+ 		break;
+ 	default:
+-		/* not valid VHT bandwidth or not in CSA */
++		/* not a valid VHT/HE bandwidth or not in CSA */
+ 		return eid;
+ 	}
+ 
+-	freq1 = hapd->cs_freq_params.center_freq1 ?
+-		hapd->cs_freq_params.center_freq1 :
+-		hapd->cs_freq_params.freq;
+-	if (ieee80211_freq_to_chan(freq1, &chan1) !=
+-	    HOSTAPD_MODE_IEEE80211A)
++	if (ieee80211_freq_to_chan(ccfs0_freq, &ccfs0_chan) !=
++			HOSTAPD_MODE_IEEE80211A)
+ 		return eid;
+ 
+-	if (hapd->cs_freq_params.center_freq2 &&
+-	    ieee80211_freq_to_chan(hapd->cs_freq_params.center_freq2,
+-				   &chan2) != HOSTAPD_MODE_IEEE80211A)
++	if (ccfs1_freq && ieee80211_freq_to_chan(ccfs1_freq, &ccfs1_chan) !=
++			HOSTAPD_MODE_IEEE80211A)
+ 		return eid;
+ 
+ 	*eid++ = WLAN_EID_CHANNEL_SWITCH_WRAPPER;
+ 	*eid++ = 5; /* Length of Channel Switch Wrapper */
+ 	*eid++ = WLAN_EID_WIDE_BW_CHSWITCH;
+ 	*eid++ = 3; /* Length of Wide Bandwidth Channel Switch element */
+-	*eid++ = bw; /* New Channel Width */
+-	*eid++ = chan1; /* New Channel Center Frequency Segment 0 */
+-	*eid++ = chan2; /* New Channel Center Frequency Segment 1 */
++	*eid++ = new_bw_field; /* New Channel Width */
++	*eid++ = ccfs0_chan; /* New Channel Center Frequency Segment 0 */
++	*eid++ = ccfs1_chan; /* New Channel Center Frequency Segment 1 */
+ 
+ 	return eid;
+ }
+-- 
+2.25.1
+