blob: e0bdc500dfdf0563fbe2cd763a86dfb361daaf63 [file] [log] [blame]
developerd243af02023-12-21 14:49:33 +08001From 8ed06968aea1170b6fbb7d88fbf546764c404eae Mon Sep 17 00:00:00 2001
developer1c2c7d42023-01-18 18:20:58 +08002From: TomLiu <tomml.liu@mediatek.com>
3Date: Tue, 9 Aug 2022 10:23:44 -0700
developerd243af02023-12-21 14:49:33 +08004Subject: [PATCH 06/54] mtk: hostapd: Add hostapd MU SET/GET control
developer1c2c7d42023-01-18 18:20:58 +08005
6---
7 hostapd/config_file.c | 9 +++
developerd243af02023-12-21 14:49:33 +08008 hostapd/ctrl_iface.c | 66 ++++++++++++++++++
developer1c2c7d42023-01-18 18:20:58 +08009 hostapd/hostapd_cli.c | 18 +++++
10 src/ap/ap_config.c | 1 +
11 src/ap/ap_config.h | 1 +
12 src/ap/ap_drv_ops.c | 14 ++++
13 src/ap/ap_drv_ops.h | 2 +
14 src/ap/hostapd.c | 2 +
15 src/common/mtk_vendor.h | 15 ++++
16 src/drivers/driver.h | 13 ++++
17 src/drivers/driver_nl80211.c | 110 ++++++++++++++++++++++++++++++
18 src/drivers/driver_nl80211.h | 1 +
19 src/drivers/driver_nl80211_capa.c | 3 +
developerd243af02023-12-21 14:49:33 +080020 13 files changed, 255 insertions(+)
developer1c2c7d42023-01-18 18:20:58 +080021
22diff --git a/hostapd/config_file.c b/hostapd/config_file.c
developerd243af02023-12-21 14:49:33 +080023index d281026e8..ec3b41abe 100644
developer1c2c7d42023-01-18 18:20:58 +080024--- a/hostapd/config_file.c
25+++ b/hostapd/config_file.c
developerdfb50982023-09-11 13:34:36 +080026@@ -3677,6 +3677,15 @@ static int hostapd_config_fill(struct hostapd_config *conf,
developer1c2c7d42023-01-18 18:20:58 +080027 return 1;
28 }
developer505c9432023-05-12 18:58:17 +080029 conf->mbssid = mbssid;
developere0a1e0e2023-02-24 11:26:12 +080030+ } else if (os_strcmp(buf, "mu_onoff") == 0) {
developer1c2c7d42023-01-18 18:20:58 +080031+ int val = atoi(pos);
32+ if (val < 0 || val > 15) {
33+ wpa_printf(MSG_ERROR,
developere0a1e0e2023-02-24 11:26:12 +080034+ "Line %d: invalid mu_onoff value",
developer1c2c7d42023-01-18 18:20:58 +080035+ line);
36+ return 1;
37+ }
developere0a1e0e2023-02-24 11:26:12 +080038+ conf->mu_onoff = val;
developer1c2c7d42023-01-18 18:20:58 +080039 #endif /* CONFIG_IEEE80211AX */
40 } else if (os_strcmp(buf, "max_listen_interval") == 0) {
41 bss->max_listen_interval = atoi(pos);
42diff --git a/hostapd/ctrl_iface.c b/hostapd/ctrl_iface.c
developerd243af02023-12-21 14:49:33 +080043index cad3f863c..b10483652 100644
developer1c2c7d42023-01-18 18:20:58 +080044--- a/hostapd/ctrl_iface.c
45+++ b/hostapd/ctrl_iface.c
developerd243af02023-12-21 14:49:33 +080046@@ -3488,6 +3488,67 @@ hostapd_ctrl_iface_get_edcca(struct hostapd_data *hapd, char *cmd, char *buf,
developer1c2c7d42023-01-18 18:20:58 +080047 }
48
49
50+static int
developere0a1e0e2023-02-24 11:26:12 +080051+hostapd_ctrl_iface_set_mu(struct hostapd_data *hapd, char *cmd,
developer1c2c7d42023-01-18 18:20:58 +080052+ char *buf, size_t buflen)
53+{
54+ char *pos, *config, *value;
55+ config = cmd;
56+ pos = os_strchr(config, ' ');
57+ if (pos == NULL)
58+ return -1;
59+ *pos++ = '\0';
60+
61+ if(pos == NULL)
62+ return -1;
63+ value = pos;
64+
65+ if (os_strcmp(config, "onoff") == 0) {
developere0a1e0e2023-02-24 11:26:12 +080066+ int mu = atoi(value);
67+ if (mu < 0 || mu > 15) {
68+ wpa_printf(MSG_ERROR, "Invalid value for mu");
developer1c2c7d42023-01-18 18:20:58 +080069+ return -1;
70+ }
developere0a1e0e2023-02-24 11:26:12 +080071+ hapd->iconf->mu_onoff = (u8) mu;
developer1c2c7d42023-01-18 18:20:58 +080072+ } else {
73+ wpa_printf(MSG_ERROR,
developere0a1e0e2023-02-24 11:26:12 +080074+ "Unsupported parameter %s for SET_MU", config);
developer1c2c7d42023-01-18 18:20:58 +080075+ return -1;
76+ }
77+
developere0a1e0e2023-02-24 11:26:12 +080078+ if(hostapd_drv_mu_ctrl(hapd) == 0) {
developer1c2c7d42023-01-18 18:20:58 +080079+ return os_snprintf(buf, buflen, "OK\n");
80+ } else {
81+ return -1;
82+ }
83+}
84+
85+
86+static int
developere0a1e0e2023-02-24 11:26:12 +080087+hostapd_ctrl_iface_get_mu(struct hostapd_data *hapd, char *buf,
developer1c2c7d42023-01-18 18:20:58 +080088+ size_t buflen)
89+{
developere0a1e0e2023-02-24 11:26:12 +080090+ u8 mu_onoff;
developer1c2c7d42023-01-18 18:20:58 +080091+ char *pos, *end;
92+
93+ pos = buf;
94+ end = buf + buflen;
95+
developerd243af02023-12-21 14:49:33 +080096+ if (hapd->iface->state != HAPD_IFACE_ENABLED)
97+ return os_snprintf(pos, end - pos, "Not allowed to get_mu when current state is %s\n",
98+ hostapd_state_text(hapd->iface->state));
99+
developere0a1e0e2023-02-24 11:26:12 +0800100+ if (hostapd_drv_mu_dump(hapd, &mu_onoff) == 0) {
101+ hapd->iconf->mu_onoff = mu_onoff;
developer1c2c7d42023-01-18 18:20:58 +0800102+ return os_snprintf(pos, end - pos, "[hostapd_cli] = UL MU-MIMO: %d, DL MU-MIMO: %d, UL OFDMA: %d, DL OFDMA: %d\n",
developere0a1e0e2023-02-24 11:26:12 +0800103+ !!(mu_onoff&BIT(3)), !!(mu_onoff&BIT(2)), !!(mu_onoff&BIT(1)), !!(mu_onoff&BIT(0)));
developer1c2c7d42023-01-18 18:20:58 +0800104+ } else {
105+ wpa_printf(MSG_INFO, "ctrl iface failed to call");
106+ return -1;
107+ }
108+}
109+
110+
111 static int hostapd_ctrl_iface_receive_process(struct hostapd_data *hapd,
112 char *buf, char *reply,
113 int reply_size,
developerd243af02023-12-21 14:49:33 +0800114@@ -4047,6 +4108,11 @@ static int hostapd_ctrl_iface_receive_process(struct hostapd_data *hapd,
developer1c2c7d42023-01-18 18:20:58 +0800115 } else if (os_strncmp(buf, "GET_EDCCA ", 10) == 0) {
116 reply_len = hostapd_ctrl_iface_get_edcca(hapd, buf+10, reply,
117 reply_size);
developere0a1e0e2023-02-24 11:26:12 +0800118+ } else if (os_strncmp(buf, "SET_MU ", 7) == 0) {
119+ reply_len = hostapd_ctrl_iface_set_mu(hapd, buf + 7, reply,
developer1c2c7d42023-01-18 18:20:58 +0800120+ reply_size);
developere0a1e0e2023-02-24 11:26:12 +0800121+ } else if (os_strncmp(buf, "GET_MU", 6) == 0) {
122+ reply_len = hostapd_ctrl_iface_get_mu(hapd, reply, reply_size);
developer1c2c7d42023-01-18 18:20:58 +0800123 } else {
124 os_memcpy(reply, "UNKNOWN COMMAND\n", 16);
125 reply_len = 16;
126diff --git a/hostapd/hostapd_cli.c b/hostapd/hostapd_cli.c
developerd243af02023-12-21 14:49:33 +0800127index dfc996d49..98892ee9d 100644
developer1c2c7d42023-01-18 18:20:58 +0800128--- a/hostapd/hostapd_cli.c
129+++ b/hostapd/hostapd_cli.c
developer505c9432023-05-12 18:58:17 +0800130@@ -1400,6 +1400,20 @@ static int hostapd_cli_cmd_driver_flags(struct wpa_ctrl *ctrl, int argc,
developer1c2c7d42023-01-18 18:20:58 +0800131 }
132
133
developere0a1e0e2023-02-24 11:26:12 +0800134+static int hostapd_cli_cmd_set_mu(struct wpa_ctrl *ctrl, int argc,
developer1c2c7d42023-01-18 18:20:58 +0800135+ char *argv[])
136+{
developere0a1e0e2023-02-24 11:26:12 +0800137+ return hostapd_cli_cmd(ctrl, "SET_MU", 1, argc, argv);
developer1c2c7d42023-01-18 18:20:58 +0800138+}
139+
140+
developere0a1e0e2023-02-24 11:26:12 +0800141+static int hostapd_cli_cmd_get_mu(struct wpa_ctrl *ctrl, int argc,
developer1c2c7d42023-01-18 18:20:58 +0800142+ char *argv[])
143+{
developere0a1e0e2023-02-24 11:26:12 +0800144+ return hostapd_cli_cmd(ctrl, "GET_MU", 0, NULL, NULL);
developer1c2c7d42023-01-18 18:20:58 +0800145+}
146+
147+
148 #ifdef CONFIG_DPP
149
150 static int hostapd_cli_cmd_dpp_qr_code(struct wpa_ctrl *ctrl, int argc,
developer505c9432023-05-12 18:58:17 +0800151@@ -1729,6 +1743,10 @@ static const struct hostapd_cli_cmd hostapd_cli_commands[] = {
developer1c2c7d42023-01-18 18:20:58 +0800152 " = send FTM range request"},
153 { "driver_flags", hostapd_cli_cmd_driver_flags, NULL,
154 " = show supported driver flags"},
developere0a1e0e2023-02-24 11:26:12 +0800155+ { "set_mu", hostapd_cli_cmd_set_mu, NULL,
developer1c2c7d42023-01-18 18:20:58 +0800156+ "<value> [0-15] bitmap- UL MU-MIMO(bit3), DL MU-MIMO(bit2), UL OFDMA(bit1), DL OFDMA(bit0)"},
developere0a1e0e2023-02-24 11:26:12 +0800157+ { "get_mu", hostapd_cli_cmd_get_mu, NULL,
158+ " = show mu onoff value in 0-15 bitmap"},
developer1c2c7d42023-01-18 18:20:58 +0800159 #ifdef CONFIG_DPP
160 { "dpp_qr_code", hostapd_cli_cmd_dpp_qr_code, NULL,
161 "report a scanned DPP URI from a QR Code" },
162diff --git a/src/ap/ap_config.c b/src/ap/ap_config.c
developerd243af02023-12-21 14:49:33 +0800163index 8e56d1082..cf7f56392 100644
developer1c2c7d42023-01-18 18:20:58 +0800164--- a/src/ap/ap_config.c
165+++ b/src/ap/ap_config.c
developer8bff6472023-07-17 11:11:44 +0800166@@ -281,6 +281,7 @@ struct hostapd_config * hostapd_config_defaults(void)
developer1c2c7d42023-01-18 18:20:58 +0800167 conf->he_6ghz_max_ampdu_len_exp = 7;
168 conf->he_6ghz_rx_ant_pat = 1;
169 conf->he_6ghz_tx_ant_pat = 1;
developerbc837d52023-06-12 11:22:18 +0800170+ conf->mu_onoff = 15;
developer1c2c7d42023-01-18 18:20:58 +0800171 #endif /* CONFIG_IEEE80211AX */
172
173 /* The third octet of the country string uses an ASCII space character
174diff --git a/src/ap/ap_config.h b/src/ap/ap_config.h
developerd243af02023-12-21 14:49:33 +0800175index 24d540dbf..421e6a647 100644
developer1c2c7d42023-01-18 18:20:58 +0800176--- a/src/ap/ap_config.h
177+++ b/src/ap/ap_config.h
developere35b8e42023-10-16 11:04:00 +0800178@@ -1146,6 +1146,7 @@ struct hostapd_config {
developer1c2c7d42023-01-18 18:20:58 +0800179 u8 he_6ghz_tx_ant_pat;
180 u8 he_6ghz_reg_pwr_type;
developer505c9432023-05-12 18:58:17 +0800181 bool require_he;
developere0a1e0e2023-02-24 11:26:12 +0800182+ u8 mu_onoff;
developer1c2c7d42023-01-18 18:20:58 +0800183 #endif /* CONFIG_IEEE80211AX */
184
185 /* VHT enable/disable config from CHAN_SWITCH */
186diff --git a/src/ap/ap_drv_ops.c b/src/ap/ap_drv_ops.c
developerd243af02023-12-21 14:49:33 +0800187index 99ba973aa..44f494ed9 100644
developer1c2c7d42023-01-18 18:20:58 +0800188--- a/src/ap/ap_drv_ops.c
189+++ b/src/ap/ap_drv_ops.c
developer8bff6472023-07-17 11:11:44 +0800190@@ -1161,3 +1161,17 @@ int hostapd_drv_get_edcca(struct hostapd_data *hapd, const u8 mode, u8 *value)
developer1c2c7d42023-01-18 18:20:58 +0800191 return 0;
192 return hapd->driver->get_edcca(hapd->drv_priv, mode, value);
193 }
194+
developere0a1e0e2023-02-24 11:26:12 +0800195+int hostapd_drv_mu_ctrl(struct hostapd_data *hapd)
developer1c2c7d42023-01-18 18:20:58 +0800196+{
developere0a1e0e2023-02-24 11:26:12 +0800197+ if (!hapd->driver || !hapd->driver->mu_ctrl)
developer1c2c7d42023-01-18 18:20:58 +0800198+ return 0;
developere0a1e0e2023-02-24 11:26:12 +0800199+ return hapd->driver->mu_ctrl(hapd->drv_priv, hapd->iconf->mu_onoff);
developer1c2c7d42023-01-18 18:20:58 +0800200+}
201+
developere0a1e0e2023-02-24 11:26:12 +0800202+int hostapd_drv_mu_dump(struct hostapd_data *hapd, u8 *mu_onoff)
developer1c2c7d42023-01-18 18:20:58 +0800203+{
developere0a1e0e2023-02-24 11:26:12 +0800204+ if (!hapd->driver || !hapd->driver->mu_dump)
developer1c2c7d42023-01-18 18:20:58 +0800205+ return 0;
developere0a1e0e2023-02-24 11:26:12 +0800206+ return hapd->driver->mu_dump(hapd->drv_priv, mu_onoff);
developer1c2c7d42023-01-18 18:20:58 +0800207+}
208diff --git a/src/ap/ap_drv_ops.h b/src/ap/ap_drv_ops.h
developerd243af02023-12-21 14:49:33 +0800209index 6ca693b0b..8a7d98128 100644
developer1c2c7d42023-01-18 18:20:58 +0800210--- a/src/ap/ap_drv_ops.h
211+++ b/src/ap/ap_drv_ops.h
developer505c9432023-05-12 18:58:17 +0800212@@ -148,6 +148,8 @@ int hostapd_drv_configure_edcca_enable(struct hostapd_data *hapd);
developer1c2c7d42023-01-18 18:20:58 +0800213 int hostapd_drv_configure_edcca_threshold(struct hostapd_data *hapd,
214 const int *threshold);
215 int hostapd_drv_get_edcca(struct hostapd_data *hapd, const u8 mode, u8 *value);
developere0a1e0e2023-02-24 11:26:12 +0800216+int hostapd_drv_mu_ctrl(struct hostapd_data *hapd);
217+int hostapd_drv_mu_dump(struct hostapd_data *hapd, u8 *mu_onoff);
developer1c2c7d42023-01-18 18:20:58 +0800218
219 #include "drivers/driver.h"
220
221diff --git a/src/ap/hostapd.c b/src/ap/hostapd.c
developerd243af02023-12-21 14:49:33 +0800222index f7c80c73b..65fdc47da 100644
developer1c2c7d42023-01-18 18:20:58 +0800223--- a/src/ap/hostapd.c
224+++ b/src/ap/hostapd.c
developerdfb50982023-09-11 13:34:36 +0800225@@ -2517,6 +2517,8 @@ dfs_offload:
developer1c2c7d42023-01-18 18:20:58 +0800226 if (hostapd_drv_configure_edcca_threshold(hapd,
227 hapd->iconf->edcca_threshold) < 0)
228 goto fail;
developere0a1e0e2023-02-24 11:26:12 +0800229+ if (hostapd_drv_mu_ctrl(hapd) < 0)
developer1c2c7d42023-01-18 18:20:58 +0800230+ goto fail;
231
232 wpa_printf(MSG_DEBUG, "%s: Setup of interface done.",
233 iface->bss[0]->conf->iface);
234diff --git a/src/common/mtk_vendor.h b/src/common/mtk_vendor.h
developerd243af02023-12-21 14:49:33 +0800235index 6121857dd..60bc4cd4c 100644
developer1c2c7d42023-01-18 18:20:58 +0800236--- a/src/common/mtk_vendor.h
237+++ b/src/common/mtk_vendor.h
238@@ -10,6 +10,8 @@ enum mtk_nl80211_vendor_subcmds {
239 MTK_NL80211_VENDOR_SUBCMD_CSI_CTRL = 0xc2,
240 MTK_NL80211_VENDOR_SUBCMD_RFEATURE_CTRL = 0xc3,
241 MTK_NL80211_VENDOR_SUBCMD_WIRELESS_CTRL = 0xc4,
developere0a1e0e2023-02-24 11:26:12 +0800242+ MTK_NL80211_VENDOR_SUBCMD_MU_CTRL = 0xc5,
developer1c2c7d42023-01-18 18:20:58 +0800243+ MTK_NL80211_VENDOR_SUBCMD_PHY_CAPA_CTRL= 0xc6,
244 MTK_NL80211_VENDOR_SUBCMD_EDCCA_CTRL = 0xc7,
245 };
246
developer8bff6472023-07-17 11:11:44 +0800247@@ -177,6 +179,19 @@ enum mtk_vendor_attr_rfeature_ctrl {
developer1c2c7d42023-01-18 18:20:58 +0800248 NUM_MTK_VENDOR_ATTRS_RFEATURE_CTRL - 1
249 };
250
developere0a1e0e2023-02-24 11:26:12 +0800251+enum mtk_vendor_attr_mu_ctrl {
252+ MTK_VENDOR_ATTR_MU_CTRL_UNSPEC,
developer1c2c7d42023-01-18 18:20:58 +0800253+
developere0a1e0e2023-02-24 11:26:12 +0800254+ MTK_VENDOR_ATTR_MU_CTRL_ONOFF,
255+ MTK_VENDOR_ATTR_MU_CTRL_DUMP,
developer1c2c7d42023-01-18 18:20:58 +0800256+
257+ /* keep last */
developere0a1e0e2023-02-24 11:26:12 +0800258+ NUM_MTK_VENDOR_ATTRS_MU_CTRL,
259+ MTK_VENDOR_ATTR_MU_CTRL_MAX =
260+ NUM_MTK_VENDOR_ATTRS_MU_CTRL - 1
developer1c2c7d42023-01-18 18:20:58 +0800261+};
262+
263+
264 #define CSI_MAX_COUNT 256
265 #define ETH_ALEN 6
266
267diff --git a/src/drivers/driver.h b/src/drivers/driver.h
developerd243af02023-12-21 14:49:33 +0800268index 7d71aa783..a23de244f 100644
developer1c2c7d42023-01-18 18:20:58 +0800269--- a/src/drivers/driver.h
270+++ b/src/drivers/driver.h
developer8bff6472023-07-17 11:11:44 +0800271@@ -176,6 +176,11 @@ struct hostapd_channel_data {
272 * punct_bitmap - RU puncturing bitmap
developer1c2c7d42023-01-18 18:20:58 +0800273 */
developer505c9432023-05-12 18:58:17 +0800274 u16 punct_bitmap;
developer1c2c7d42023-01-18 18:20:58 +0800275+
276+ /**
developere0a1e0e2023-02-24 11:26:12 +0800277+ * mu onoff=<val> (bitmap- UL MU-MIMO(bit3), DL MU-MIMO(bit2), UL OFDMA(bit1), DL OFDMA(bit0))
developer1c2c7d42023-01-18 18:20:58 +0800278+ */
developere0a1e0e2023-02-24 11:26:12 +0800279+ u8 mu_onoff;
developer1c2c7d42023-01-18 18:20:58 +0800280 };
281
developer8bff6472023-07-17 11:11:44 +0800282 #define HE_MAC_CAPAB_0 0
developerd243af02023-12-21 14:49:33 +0800283@@ -5109,6 +5114,14 @@ struct wpa_driver_ops {
developer1c2c7d42023-01-18 18:20:58 +0800284 const s8 edcca_compensation);
285 int (*configure_edcca_threshold)(void *priv, const int *threshold);
286 int (*get_edcca)(void *priv, const u8 mode, u8 *value);
287+
288+ /**
developere0a1e0e2023-02-24 11:26:12 +0800289+ * mu_ctrl - ctrl on off for UL/DL MURU
developer1c2c7d42023-01-18 18:20:58 +0800290+ * @priv: Private driver interface data
291+ *
292+ */
developere0a1e0e2023-02-24 11:26:12 +0800293+ int (*mu_ctrl)(void *priv, u8 mu_onoff);
294+ int (*mu_dump)(void *priv, u8 *mu_onoff);
developer1c2c7d42023-01-18 18:20:58 +0800295 };
296
297 /**
298diff --git a/src/drivers/driver_nl80211.c b/src/drivers/driver_nl80211.c
developerd243af02023-12-21 14:49:33 +0800299index 1a2f52b77..f7f157bf0 100644
developer1c2c7d42023-01-18 18:20:58 +0800300--- a/src/drivers/driver_nl80211.c
301+++ b/src/drivers/driver_nl80211.c
developerd243af02023-12-21 14:49:33 +0800302@@ -13633,6 +13633,114 @@ fail:
developer1c2c7d42023-01-18 18:20:58 +0800303 }
304
305
306+#ifdef CONFIG_IEEE80211AX
developere0a1e0e2023-02-24 11:26:12 +0800307+static int nl80211_mu_onoff(void *priv, u8 mu_onoff)
developer1c2c7d42023-01-18 18:20:58 +0800308+{
309+ struct i802_bss *bss = priv;
310+ struct wpa_driver_nl80211_data *drv = bss->drv;
311+ struct nl_msg *msg;
312+ struct nlattr *data;
313+ int ret;
314+
developere0a1e0e2023-02-24 11:26:12 +0800315+ if (!drv->mtk_mu_vendor_cmd_avail) {
developer1c2c7d42023-01-18 18:20:58 +0800316+ wpa_printf(MSG_INFO,
developere0a1e0e2023-02-24 11:26:12 +0800317+ "nl80211: Driver does not support setting mu control");
developer1c2c7d42023-01-18 18:20:58 +0800318+ return 0;
319+ }
320+
321+ if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_VENDOR)) ||
322+ nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_MTK) ||
developere0a1e0e2023-02-24 11:26:12 +0800323+ nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD, MTK_NL80211_VENDOR_SUBCMD_MU_CTRL) ||
developer1c2c7d42023-01-18 18:20:58 +0800324+ !(data = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
developere0a1e0e2023-02-24 11:26:12 +0800325+ nla_put_u8(msg, MTK_VENDOR_ATTR_MU_CTRL_ONOFF, mu_onoff)) {
developer1c2c7d42023-01-18 18:20:58 +0800326+ nlmsg_free(msg);
327+ return -ENOBUFS;
328+ }
329+ nla_nest_end(msg, data);
330+ ret = send_and_recv_msgs(drv, msg, NULL, NULL, NULL, NULL);
331+ if(ret){
developere0a1e0e2023-02-24 11:26:12 +0800332+ wpa_printf(MSG_ERROR, "Failed to set mu_onoff. ret=%d (%s)", ret, strerror(-ret));
developer1c2c7d42023-01-18 18:20:58 +0800333+ }
334+ return ret;
335+}
336+
337+
developere0a1e0e2023-02-24 11:26:12 +0800338+static int mu_dump_handler(struct nl_msg *msg, void *arg)
developer1c2c7d42023-01-18 18:20:58 +0800339+{
developere0a1e0e2023-02-24 11:26:12 +0800340+ u8 *mu_onoff = (u8 *) arg;
developer1c2c7d42023-01-18 18:20:58 +0800341+ struct nlattr *tb[NL80211_ATTR_MAX + 1];
developere0a1e0e2023-02-24 11:26:12 +0800342+ struct nlattr *tb_vendor[MTK_VENDOR_ATTR_MU_CTRL_MAX + 1];
developer1c2c7d42023-01-18 18:20:58 +0800343+ struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg));
344+ struct nlattr *nl_vend, *attr;
345+
346+ static const struct nla_policy
developere0a1e0e2023-02-24 11:26:12 +0800347+ mu_ctrl_policy[NUM_MTK_VENDOR_ATTRS_MU_CTRL + 1] = {
348+ [MTK_VENDOR_ATTR_MU_CTRL_ONOFF] = {.type = NLA_U8 },
349+ [MTK_VENDOR_ATTR_MU_CTRL_DUMP] = {.type = NLA_U8 },
developer1c2c7d42023-01-18 18:20:58 +0800350+ };
351+
352+ nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0),
353+ genlmsg_attrlen(gnlh, 0), NULL);
354+
355+ nl_vend = tb[NL80211_ATTR_VENDOR_DATA];
356+ if (!nl_vend)
357+ return NL_SKIP;
358+
developere0a1e0e2023-02-24 11:26:12 +0800359+ nla_parse(tb_vendor, MTK_VENDOR_ATTR_MU_CTRL_MAX,
developer1c2c7d42023-01-18 18:20:58 +0800360+ nla_data(nl_vend), nla_len(nl_vend), NULL);
361+
developere0a1e0e2023-02-24 11:26:12 +0800362+ attr = tb_vendor[MTK_VENDOR_ATTR_MU_CTRL_DUMP];
developer1c2c7d42023-01-18 18:20:58 +0800363+ if (!attr) {
developere0a1e0e2023-02-24 11:26:12 +0800364+ wpa_printf(MSG_ERROR, "nl80211: cannot find MTK_VENDOR_ATTR_MU_CTRL_DUMP");
developer1c2c7d42023-01-18 18:20:58 +0800365+ return NL_SKIP;
366+ }
367+
developere0a1e0e2023-02-24 11:26:12 +0800368+ *mu_onoff = nla_get_u8(attr);
369+ wpa_printf(MSG_DEBUG, "nla_get mu_onoff: %d\n", *mu_onoff);
developer1c2c7d42023-01-18 18:20:58 +0800370+
371+ return 0;
372+}
373+
developere0a1e0e2023-02-24 11:26:12 +0800374+static int nl80211_mu_dump(void *priv, u8 *mu_onoff)
developer1c2c7d42023-01-18 18:20:58 +0800375+{
376+ struct i802_bss *bss = priv;
377+ struct wpa_driver_nl80211_data *drv = bss->drv;
378+ struct nl_msg *msg;
379+ struct nlattr *attr;
380+ int ret;
381+
developere0a1e0e2023-02-24 11:26:12 +0800382+ if (!drv->mtk_mu_vendor_cmd_avail) {
developer1c2c7d42023-01-18 18:20:58 +0800383+ wpa_printf(MSG_INFO,
developere0a1e0e2023-02-24 11:26:12 +0800384+ "nl80211: Driver does not support setting mu control");
developer1c2c7d42023-01-18 18:20:58 +0800385+ return 0;
386+ }
387+
388+ if (!(msg = nl80211_drv_msg(drv, NLM_F_DUMP, NL80211_CMD_VENDOR)) ||
389+ nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_MTK) ||
developere0a1e0e2023-02-24 11:26:12 +0800390+ nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD, MTK_NL80211_VENDOR_SUBCMD_MU_CTRL)) {
developer1c2c7d42023-01-18 18:20:58 +0800391+ nlmsg_free(msg);
392+ return -ENOBUFS;
393+ }
394+
395+ attr = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA);
396+ if (!attr) {
397+ nlmsg_free(msg);
398+ return -1;
399+ }
400+
401+ nla_nest_end(msg, attr);
402+
developere0a1e0e2023-02-24 11:26:12 +0800403+ ret = send_and_recv_msgs(drv, msg, mu_dump_handler, mu_onoff, NULL, NULL);
developer1c2c7d42023-01-18 18:20:58 +0800404+
405+ if(ret){
developere0a1e0e2023-02-24 11:26:12 +0800406+ wpa_printf(MSG_ERROR, "Failed to get mu_onoff. ret=%d (%s)", ret, strerror(-ret));
developer1c2c7d42023-01-18 18:20:58 +0800407+ }
408+
409+ return ret;
410+}
411+#endif /* CONFIG_IEEE80211AX */
412+
413+
414 #ifdef CONFIG_DPP
415 static int nl80211_dpp_listen(void *priv, bool enable)
416 {
developerd243af02023-12-21 14:49:33 +0800417@@ -14085,6 +14193,8 @@ const struct wpa_driver_ops wpa_driver_nl80211_ops = {
developer1c2c7d42023-01-18 18:20:58 +0800418 .update_connect_params = nl80211_update_connection_params,
419 .send_external_auth_status = nl80211_send_external_auth_status,
420 .set_4addr_mode = nl80211_set_4addr_mode,
developere0a1e0e2023-02-24 11:26:12 +0800421+ .mu_ctrl = nl80211_mu_onoff,
422+ .mu_dump = nl80211_mu_dump,
developer1c2c7d42023-01-18 18:20:58 +0800423 #ifdef CONFIG_DPP
424 .dpp_listen = nl80211_dpp_listen,
425 #endif /* CONFIG_DPP */
426diff --git a/src/drivers/driver_nl80211.h b/src/drivers/driver_nl80211.h
developerd243af02023-12-21 14:49:33 +0800427index 51b3fbec8..bd5d28404 100644
developer1c2c7d42023-01-18 18:20:58 +0800428--- a/src/drivers/driver_nl80211.h
429+++ b/src/drivers/driver_nl80211.h
developer8bff6472023-07-17 11:11:44 +0800430@@ -203,6 +203,7 @@ struct wpa_driver_nl80211_data {
developer505c9432023-05-12 18:58:17 +0800431 unsigned int puncturing:1;
developer8bff6472023-07-17 11:11:44 +0800432 unsigned int qca_ap_allowed_freqs:1;
developer1c2c7d42023-01-18 18:20:58 +0800433 unsigned int mtk_edcca_vendor_cmd_avail:1;
developere0a1e0e2023-02-24 11:26:12 +0800434+ unsigned int mtk_mu_vendor_cmd_avail:1;
developer1c2c7d42023-01-18 18:20:58 +0800435
436 u64 vendor_scan_cookie;
437 u64 remain_on_chan_cookie;
438diff --git a/src/drivers/driver_nl80211_capa.c b/src/drivers/driver_nl80211_capa.c
developerd243af02023-12-21 14:49:33 +0800439index 47654f65b..07f6cb133 100644
developer1c2c7d42023-01-18 18:20:58 +0800440--- a/src/drivers/driver_nl80211_capa.c
441+++ b/src/drivers/driver_nl80211_capa.c
developerd243af02023-12-21 14:49:33 +0800442@@ -1117,6 +1117,9 @@ static int wiphy_info_handler(struct nl_msg *msg, void *arg)
developer8bff6472023-07-17 11:11:44 +0800443 case MTK_NL80211_VENDOR_SUBCMD_EDCCA_CTRL:
developer1c2c7d42023-01-18 18:20:58 +0800444 drv->mtk_edcca_vendor_cmd_avail = 1;
445 break;
developere0a1e0e2023-02-24 11:26:12 +0800446+ case MTK_NL80211_VENDOR_SUBCMD_MU_CTRL :
447+ drv->mtk_mu_vendor_cmd_avail = 1;
developer1c2c7d42023-01-18 18:20:58 +0800448+ break;
449 }
450 }
451
452--
developerdfb50982023-09-11 13:34:36 +08004532.18.0
developer1c2c7d42023-01-18 18:20:58 +0800454