[][[mt76-vendor] hemu hostapd vendor command]

[Description]
Add hostapd mtk vendor subcmd ctrl hemu onoff

[Release-log]
N/A

Change-Id: I83307235a11e850f7bdcda08a91e80b5b0a16bc3
Reviewed-on: https://gerrit.mediatek.inc/c/openwrt/feeds/mtk_openwrt_feeds/+/6221214
diff --git a/autobuild_mac80211_release/package/network/services/hostapd/patches/920-hostapd-hemu-onoff-ctrl.patch b/autobuild_mac80211_release/package/network/services/hostapd/patches/920-hostapd-hemu-onoff-ctrl.patch
new file mode 100644
index 0000000..349b19e
--- /dev/null
+++ b/autobuild_mac80211_release/package/network/services/hostapd/patches/920-hostapd-hemu-onoff-ctrl.patch
@@ -0,0 +1,185 @@
+From b01a06578df836bc9df2c68134cfebf42d8ffde0 Mon Sep 17 00:00:00 2001
+From: TomLiu <tomml.liu@mediatek.com>
+Date: Thu, 14 Jul 2022 13:43:06 -0700
+Subject: [PATCH-920]Add hemu hostapd vendor command
+
+---
+ hostapd/config_file.c        |  9 +++++++++
+ src/ap/ap_config.h           |  1 +
+ src/ap/ap_drv_ops.c          |  7 +++++++
+ src/ap/beacon.c              |  2 ++
+ src/common/mtk_vendor.h      | 13 +++++++++++++
+ src/drivers/driver.h         | 12 ++++++++++++
+ src/drivers/driver_nl80211.c | 28 ++++++++++++++++++++++++++++
+ 7 files changed, 72 insertions(+)
+
+diff --git a/hostapd/config_file.c b/hostapd/config_file.c
+index 19a2fd5..85d58cd 100644
+--- a/hostapd/config_file.c
++++ b/hostapd/config_file.c
+@@ -3655,6 +3655,15 @@ static int hostapd_config_fill(struct hostapd_config *conf,
+ 			return 1;
+ 		}
+ 		bss->unsol_bcast_probe_resp_interval = val;
++	} else if (os_strcmp(buf, "hemu_onoff") == 0) {
++		int val = atoi(pos);
++		if (val < 0 || val > 15) {
++			wpa_printf(MSG_ERROR,
++				   "Line %d: invalid hemu_onoff value",
++				   line);
++			return 1;
++		}
++		conf->hemu_onoff = val;
+ #endif /* CONFIG_IEEE80211AX */
+ 	} else if (os_strcmp(buf, "max_listen_interval") == 0) {
+ 		bss->max_listen_interval = atoi(pos);
+diff --git a/src/ap/ap_config.h b/src/ap/ap_config.h
+index 9bbe7eb..737cc2f 100644
+--- a/src/ap/ap_config.h
++++ b/src/ap/ap_config.h
+@@ -1111,6 +1111,7 @@ struct hostapd_config {
+ 	u8 he_6ghz_rx_ant_pat;
+ 	u8 he_6ghz_tx_ant_pat;
+ 	u8 he_6ghz_reg_pwr_type;
++	u8 hemu_onoff;
+ #endif /* CONFIG_IEEE80211AX */
+ 
+ 	/* VHT enable/disable config from CHAN_SWITCH */
+diff --git a/src/ap/ap_drv_ops.c b/src/ap/ap_drv_ops.c
+index b8b98e4..517d2a5 100644
+--- a/src/ap/ap_drv_ops.c
++++ b/src/ap/ap_drv_ops.c
+@@ -1021,3 +1021,10 @@ int hostapd_drv_configure_edcca_threshold(struct hostapd_data *hapd)
+ 				hapd->iconf->edcca_enable,
+ 				hapd->iconf->edcca_compensation);
+ }
++
++int hostapd_drv_hemu_ctrl(struct hostapd_data *hapd)
++{
++	if (!hapd->driver || !hapd->driver->hemu_ctrl)
++		return 0;
++	return hapd->driver->hemu_ctrl(hapd->drv_priv, hapd->iconf->hemu_onoff);
++}
+diff --git a/src/ap/beacon.c b/src/ap/beacon.c
+index 575c92f..7170711 100644
+--- a/src/ap/beacon.c
++++ b/src/ap/beacon.c
+@@ -1976,6 +1976,8 @@ static int __ieee802_11_set_beacon(struct hostapd_data *hapd)
+ 		params.freq = &freq;
+ 
+ 	res = hostapd_drv_set_ap(hapd, &params);
++	if (hostapd_drv_hemu_ctrl(hapd) < 0)
++		goto fail;
+ 	hostapd_free_ap_extra_ies(hapd, beacon, proberesp, assocresp);
+ 	if (res)
+ 		wpa_printf(MSG_ERROR, "Failed to set beacon parameters");
+diff --git a/src/common/mtk_vendor.h b/src/common/mtk_vendor.h
+index 528387f..6a0e60a 100644
+--- a/src/common/mtk_vendor.h
++++ b/src/common/mtk_vendor.h
+@@ -10,6 +10,8 @@ enum mtk_nl80211_vendor_subcmds {
+ 	MTK_NL80211_VENDOR_SUBCMD_CSI_CTRL = 0xc2,
+ 	MTK_NL80211_VENDOR_SUBCMD_RFEATURE_CTRL = 0xc3,
+ 	MTK_NL80211_VENDOR_SUBCMD_WIRELESS_CTRL = 0xc4,
++	MTK_NL80211_VENDOR_SUBCMD_HEMU_CTRL = 0xc5,
++	MTK_NL80211_VENDOR_SUBCMD_PHY_CAPA_CTRL= 0xc6,
+ 	MTK_NL80211_VENDOR_SUBCMD_EDCCA_CTRL = 0xc7,
+ };
+ 
+@@ -167,6 +169,17 @@ enum mtk_vendor_attr_rfeature_ctrl {
+ 		NUM_MTK_VENDOR_ATTRS_RFEATURE_CTRL - 1
+ };
+ 
++enum mtk_vendor_attr_hemu_ctrl {
++	MTK_VENDOR_ATTR_HEMU_CTRL_UNSPEC,
++
++	MTK_VENDOR_ATTR_HEMU_CTRL_ONOFF,
++
++	/* keep last */
++	NUM_MTK_VENDOR_ATTRS_HEMU_CTRL,
++	MTK_VENDOR_ATTR_HEMU_CTRL_MAX =
++		NUM_MTK_VENDOR_ATTRS_HEMU_CTRL - 1
++};
++
+ #define CSI_MAX_COUNT 256
+ #define ETH_ALEN 6
+ 
+diff --git a/src/drivers/driver.h b/src/drivers/driver.h
+index fc96fef..298dbf3 100644
+--- a/src/drivers/driver.h
++++ b/src/drivers/driver.h
+@@ -1622,6 +1622,11 @@ struct wpa_driver_ap_params {
+ 	 * Unsolicited broadcast Probe Response template length
+ 	 */
+ 	size_t unsol_bcast_probe_resp_tmpl_len;
++
++	/**
++	 * hemu onoff=<val> (bitmap- UL MU-MIMO(bit3), DL MU-MIMO(bit2), UL OFDMA(bit1), DL OFDMA(bit0))
++	 */
++	u8 hemu_onoff;
+ };
+ 
+ struct wpa_driver_mesh_bss_params {
+@@ -4675,6 +4680,13 @@ struct wpa_driver_ops {
+ #endif /* CONFIG_TESTING_OPTIONS */
+ 	int (*configure_edcca_threshold)(void *priv, const u8 edcca_enable,
+ 				  const s8 edcca_compensation);
++
++	/**
++	 * hemu_ctrl - ctrl on off for UL/DL MURU
++	 * @priv: Private driver interface data
++	 *
++	 */
++	int (*hemu_ctrl)(void *priv, u8 hemu_onoff);
+ };
+ 
+ /**
+diff --git a/src/drivers/driver_nl80211.c b/src/drivers/driver_nl80211.c
+index b1e7b16..18ccbc7 100644
+--- a/src/drivers/driver_nl80211.c
++++ b/src/drivers/driver_nl80211.c
+@@ -12287,6 +12287,33 @@ fail:
+ }
+ 
+ 
++#ifdef CONFIG_IEEE80211AX
++static int nl80211_hemu_muruonoff(void *priv, u8 hemu_onoff)
++{
++	struct i802_bss *bss = priv;
++	struct wpa_driver_nl80211_data *drv = bss->drv;
++	struct nl_msg *msg;
++	struct nlattr *data;
++	int ret;
++
++	if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_VENDOR)) ||
++		nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_MTK) ||
++		nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD, MTK_NL80211_VENDOR_SUBCMD_HEMU_CTRL) ||
++		!(data = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
++		nla_put_u8(msg, MTK_VENDOR_ATTR_HEMU_CTRL_ONOFF, hemu_onoff)) {
++		nlmsg_free(msg);
++		return -ENOBUFS;
++	}
++	nla_nest_end(msg, data);
++	ret = send_and_recv_msgs(drv, msg, NULL, NULL, NULL, NULL);
++	if(ret){
++		wpa_printf(MSG_ERROR, "Failed to set hemu_onoff. ret=%d (%s)", ret, strerror(-ret));
++	}
++	return ret;
++}
++#endif /* CONFIG_IEEE80211AX */
++
++
+ #ifdef CONFIG_DPP
+ static int nl80211_dpp_listen(void *priv, bool enable)
+ {
+@@ -12531,6 +12558,7 @@ const struct wpa_driver_ops wpa_driver_nl80211_ops = {
+ 	.update_connect_params = nl80211_update_connection_params,
+ 	.send_external_auth_status = nl80211_send_external_auth_status,
+ 	.set_4addr_mode = nl80211_set_4addr_mode,
++	.hemu_ctrl = nl80211_hemu_muruonoff,
+ #ifdef CONFIG_DPP
+ 	.dpp_listen = nl80211_dpp_listen,
+ #endif /* CONFIG_DPP */
+-- 
+2.32.0
+