[][MAC80211][hostapd][Add channel information for hostapd reload]

[Description]
Add center channel, operating class, and bandwidth into the UPDATE
command when wpa_supplciant reloads hostapd.
Hostapd can correctly update its channel information.

[Release-log]
N/A

Change-Id: I80d3b097cb85a45f9877b69701233a1cf2034538
Reviewed-on: https://gerrit.mediatek.inc/c/openwrt/feeds/mtk_openwrt_feeds/+/7273521
diff --git a/autobuild_mac80211_release/package/network/services/hostapd/patches/mtk-0023-hostapd-mtk-Add-channel-information-for-hostapd-relo.patch b/autobuild_mac80211_release/package/network/services/hostapd/patches/mtk-0023-hostapd-mtk-Add-channel-information-for-hostapd-relo.patch
new file mode 100644
index 0000000..f92c996
--- /dev/null
+++ b/autobuild_mac80211_release/package/network/services/hostapd/patches/mtk-0023-hostapd-mtk-Add-channel-information-for-hostapd-relo.patch
@@ -0,0 +1,78 @@
+From 55d35cf2ac29b250494916d33768b9e52e989e31 Mon Sep 17 00:00:00 2001
+From: Michael Lee <michael-cy.lee@mediatek.com>
+Date: Wed, 22 Mar 2023 13:59:29 +0800
+Subject: [PATCH] hostapd: mtk: Add channel information for hostapd reload
+
+Add center channel, operating class, and bandwidth into the UPDATE
+command when wpa_supplciant reloads hostapd.
+Hostapd can correctly update its channel information.
+
+Signed-off-by: Michael Lee <michael-cy.lee@mediatek.com>
+---
+ hostapd/ctrl_iface.c            | 11 +++++++++++
+ wpa_supplicant/wpa_supplicant.c | 17 ++++++++++++++---
+ 2 files changed, 25 insertions(+), 3 deletions(-)
+
+diff --git a/hostapd/ctrl_iface.c b/hostapd/ctrl_iface.c
+index 61c9e80..e2c9e43 100644
+--- a/hostapd/ctrl_iface.c
++++ b/hostapd/ctrl_iface.c
+@@ -170,6 +170,17 @@ static struct hostapd_config *hostapd_ctrl_iface_config_read(const char *fname)
+ 			conf->hw_mode = atoi(val);
+ 		else if ((val = get_option(opt, "ieee80211n=")))
+ 			conf->ieee80211n = atoi(val);
++		else if ((val = get_option(opt, "center_segment0=")))
++			hostapd_set_oper_centr_freq_seg0_idx(conf, atoi(val));
++		else if ((val = get_option(opt, "center_segment1=")))
++			hostapd_set_oper_centr_freq_seg1_idx(conf, atoi(val));
++		else if ((val = get_option(opt, "op_class="))) {
++			enum oper_chan_width ch_width;
++
++			conf->op_class = atoi(val);
++			ch_width = op_class_to_ch_width(conf->op_class);
++			hostapd_set_oper_chwidth(conf, ch_width);
++		}
+ 		else
+ 			break;
+ 	}
+diff --git a/wpa_supplicant/wpa_supplicant.c b/wpa_supplicant/wpa_supplicant.c
+index 616e00d..ca6612a 100644
+--- a/wpa_supplicant/wpa_supplicant.c
++++ b/wpa_supplicant/wpa_supplicant.c
+@@ -150,9 +150,10 @@ static int hostapd_reload(struct wpa_supplicant *wpa_s, struct wpa_bss *bss)
+ 	char buf[256];
+ 	size_t len = sizeof(buf);
+ 	enum hostapd_hw_mode hw_mode;
+-	u8 channel;
++	u8 channel, center_segment0, center_segment1, op_class;
+ 	int sec_chan = 0;
+ 	int ret;
++	struct wpa_channel_info ci;
+ 
+ 	if (!bss)
+ 		return -1;
+@@ -165,9 +166,19 @@ static int hostapd_reload(struct wpa_supplicant *wpa_s, struct wpa_bss *bss)
+ 			sec_chan = -1;
+ 	}
+ 
++	ret = wpa_drv_channel_info(wpa_s, &ci);
++	if (ret)
++		return -1;
++
++	ieee80211_freq_to_chan(ci.center_frq1, &center_segment0);
++	ieee80211_freq_to_chan(ci.center_frq2, &center_segment1);
++	ieee80211_chaninfo_to_channel(ci.frequency, ci.chanwidth, sec_chan,
++				      &op_class, &channel);
+ 	hw_mode = ieee80211_freq_to_chan(bss->freq, &channel);
+-	if (asprintf(&cmd, "UPDATE channel=%d sec_chan=%d hw_mode=%d",
+-		     channel, sec_chan, hw_mode) < 0)
++	if (asprintf(&cmd, "UPDATE channel=%d center_segment0=%d "
++		     "center_segment1=%d sec_chan=%d hw_mode=%d op_class=%d",
++		     channel, center_segment0, center_segment1, sec_chan,
++		     hw_mode, op_class) < 0)
+ 		return -1;
+ 
+ 	ret = wpa_ctrl_request(wpa_s->hostapd, cmd, os_strlen(cmd), buf, &len, NULL);
+-- 
+2.25.1
+