blob: 7ae38e322ca6c328560fd182536d93230b890761 [file] [log] [blame]
developerdfb50982023-09-11 13:34:36 +08001From 2ae0d6fb6b676f76081a9edd3416d93b26091400 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
developerdfb50982023-09-11 13:34:36 +08004Subject: [PATCH 06/40] hostapd: mtk: Add hostapd MU SET/GET control
developer1c2c7d42023-01-18 18:20:58 +08005
6---
7 hostapd/config_file.c | 9 +++
8 hostapd/ctrl_iface.c | 62 +++++++++++++++++
9 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 +
20 13 files changed, 251 insertions(+)
21
22diff --git a/hostapd/config_file.c b/hostapd/config_file.c
developerdfb50982023-09-11 13:34:36 +080023index 1fc6456..0e67796 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
developerdfb50982023-09-11 13:34:36 +080043index cad3f86..c5d92b0 100644
developer1c2c7d42023-01-18 18:20:58 +080044--- a/hostapd/ctrl_iface.c
45+++ b/hostapd/ctrl_iface.c
developerdfb50982023-09-11 13:34:36 +080046@@ -3488,6 +3488,63 @@ 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+
developere0a1e0e2023-02-24 11:26:12 +080096+ if (hostapd_drv_mu_dump(hapd, &mu_onoff) == 0) {
97+ hapd->iconf->mu_onoff = mu_onoff;
developer1c2c7d42023-01-18 18:20:58 +080098+ 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 +080099+ !!(mu_onoff&BIT(3)), !!(mu_onoff&BIT(2)), !!(mu_onoff&BIT(1)), !!(mu_onoff&BIT(0)));
developer1c2c7d42023-01-18 18:20:58 +0800100+ } else {
101+ wpa_printf(MSG_INFO, "ctrl iface failed to call");
102+ return -1;
103+ }
104+}
105+
106+
107 static int hostapd_ctrl_iface_receive_process(struct hostapd_data *hapd,
108 char *buf, char *reply,
109 int reply_size,
developerdfb50982023-09-11 13:34:36 +0800110@@ -4047,6 +4104,11 @@ static int hostapd_ctrl_iface_receive_process(struct hostapd_data *hapd,
developer1c2c7d42023-01-18 18:20:58 +0800111 } else if (os_strncmp(buf, "GET_EDCCA ", 10) == 0) {
112 reply_len = hostapd_ctrl_iface_get_edcca(hapd, buf+10, reply,
113 reply_size);
developere0a1e0e2023-02-24 11:26:12 +0800114+ } else if (os_strncmp(buf, "SET_MU ", 7) == 0) {
115+ reply_len = hostapd_ctrl_iface_set_mu(hapd, buf + 7, reply,
developer1c2c7d42023-01-18 18:20:58 +0800116+ reply_size);
developere0a1e0e2023-02-24 11:26:12 +0800117+ } else if (os_strncmp(buf, "GET_MU", 6) == 0) {
118+ reply_len = hostapd_ctrl_iface_get_mu(hapd, reply, reply_size);
developer1c2c7d42023-01-18 18:20:58 +0800119 } else {
120 os_memcpy(reply, "UNKNOWN COMMAND\n", 16);
121 reply_len = 16;
122diff --git a/hostapd/hostapd_cli.c b/hostapd/hostapd_cli.c
developerdfb50982023-09-11 13:34:36 +0800123index dfc996d..98892ee 100644
developer1c2c7d42023-01-18 18:20:58 +0800124--- a/hostapd/hostapd_cli.c
125+++ b/hostapd/hostapd_cli.c
developer505c9432023-05-12 18:58:17 +0800126@@ -1400,6 +1400,20 @@ static int hostapd_cli_cmd_driver_flags(struct wpa_ctrl *ctrl, int argc,
developer1c2c7d42023-01-18 18:20:58 +0800127 }
128
129
developere0a1e0e2023-02-24 11:26:12 +0800130+static int hostapd_cli_cmd_set_mu(struct wpa_ctrl *ctrl, int argc,
developer1c2c7d42023-01-18 18:20:58 +0800131+ char *argv[])
132+{
developere0a1e0e2023-02-24 11:26:12 +0800133+ return hostapd_cli_cmd(ctrl, "SET_MU", 1, argc, argv);
developer1c2c7d42023-01-18 18:20:58 +0800134+}
135+
136+
developere0a1e0e2023-02-24 11:26:12 +0800137+static int hostapd_cli_cmd_get_mu(struct wpa_ctrl *ctrl, int argc,
developer1c2c7d42023-01-18 18:20:58 +0800138+ char *argv[])
139+{
developere0a1e0e2023-02-24 11:26:12 +0800140+ return hostapd_cli_cmd(ctrl, "GET_MU", 0, NULL, NULL);
developer1c2c7d42023-01-18 18:20:58 +0800141+}
142+
143+
144 #ifdef CONFIG_DPP
145
146 static int hostapd_cli_cmd_dpp_qr_code(struct wpa_ctrl *ctrl, int argc,
developer505c9432023-05-12 18:58:17 +0800147@@ -1729,6 +1743,10 @@ static const struct hostapd_cli_cmd hostapd_cli_commands[] = {
developer1c2c7d42023-01-18 18:20:58 +0800148 " = send FTM range request"},
149 { "driver_flags", hostapd_cli_cmd_driver_flags, NULL,
150 " = show supported driver flags"},
developere0a1e0e2023-02-24 11:26:12 +0800151+ { "set_mu", hostapd_cli_cmd_set_mu, NULL,
developer1c2c7d42023-01-18 18:20:58 +0800152+ "<value> [0-15] bitmap- UL MU-MIMO(bit3), DL MU-MIMO(bit2), UL OFDMA(bit1), DL OFDMA(bit0)"},
developere0a1e0e2023-02-24 11:26:12 +0800153+ { "get_mu", hostapd_cli_cmd_get_mu, NULL,
154+ " = show mu onoff value in 0-15 bitmap"},
developer1c2c7d42023-01-18 18:20:58 +0800155 #ifdef CONFIG_DPP
156 { "dpp_qr_code", hostapd_cli_cmd_dpp_qr_code, NULL,
157 "report a scanned DPP URI from a QR Code" },
158diff --git a/src/ap/ap_config.c b/src/ap/ap_config.c
developerdfb50982023-09-11 13:34:36 +0800159index 8e56d10..cf7f563 100644
developer1c2c7d42023-01-18 18:20:58 +0800160--- a/src/ap/ap_config.c
161+++ b/src/ap/ap_config.c
developer8bff6472023-07-17 11:11:44 +0800162@@ -281,6 +281,7 @@ struct hostapd_config * hostapd_config_defaults(void)
developer1c2c7d42023-01-18 18:20:58 +0800163 conf->he_6ghz_max_ampdu_len_exp = 7;
164 conf->he_6ghz_rx_ant_pat = 1;
165 conf->he_6ghz_tx_ant_pat = 1;
developerbc837d52023-06-12 11:22:18 +0800166+ conf->mu_onoff = 15;
developer1c2c7d42023-01-18 18:20:58 +0800167 #endif /* CONFIG_IEEE80211AX */
168
169 /* The third octet of the country string uses an ASCII space character
170diff --git a/src/ap/ap_config.h b/src/ap/ap_config.h
developerdfb50982023-09-11 13:34:36 +0800171index 0e829c0..0bd6254 100644
developer1c2c7d42023-01-18 18:20:58 +0800172--- a/src/ap/ap_config.h
173+++ b/src/ap/ap_config.h
developerdfb50982023-09-11 13:34:36 +0800174@@ -1143,6 +1143,7 @@ struct hostapd_config {
developer1c2c7d42023-01-18 18:20:58 +0800175 u8 he_6ghz_tx_ant_pat;
176 u8 he_6ghz_reg_pwr_type;
developer505c9432023-05-12 18:58:17 +0800177 bool require_he;
developere0a1e0e2023-02-24 11:26:12 +0800178+ u8 mu_onoff;
developer1c2c7d42023-01-18 18:20:58 +0800179 #endif /* CONFIG_IEEE80211AX */
180
181 /* VHT enable/disable config from CHAN_SWITCH */
182diff --git a/src/ap/ap_drv_ops.c b/src/ap/ap_drv_ops.c
developerdfb50982023-09-11 13:34:36 +0800183index 99ba973..44f494e 100644
developer1c2c7d42023-01-18 18:20:58 +0800184--- a/src/ap/ap_drv_ops.c
185+++ b/src/ap/ap_drv_ops.c
developer8bff6472023-07-17 11:11:44 +0800186@@ -1161,3 +1161,17 @@ int hostapd_drv_get_edcca(struct hostapd_data *hapd, const u8 mode, u8 *value)
developer1c2c7d42023-01-18 18:20:58 +0800187 return 0;
188 return hapd->driver->get_edcca(hapd->drv_priv, mode, value);
189 }
190+
developere0a1e0e2023-02-24 11:26:12 +0800191+int hostapd_drv_mu_ctrl(struct hostapd_data *hapd)
developer1c2c7d42023-01-18 18:20:58 +0800192+{
developere0a1e0e2023-02-24 11:26:12 +0800193+ if (!hapd->driver || !hapd->driver->mu_ctrl)
developer1c2c7d42023-01-18 18:20:58 +0800194+ return 0;
developere0a1e0e2023-02-24 11:26:12 +0800195+ return hapd->driver->mu_ctrl(hapd->drv_priv, hapd->iconf->mu_onoff);
developer1c2c7d42023-01-18 18:20:58 +0800196+}
197+
developere0a1e0e2023-02-24 11:26:12 +0800198+int hostapd_drv_mu_dump(struct hostapd_data *hapd, u8 *mu_onoff)
developer1c2c7d42023-01-18 18:20:58 +0800199+{
developere0a1e0e2023-02-24 11:26:12 +0800200+ if (!hapd->driver || !hapd->driver->mu_dump)
developer1c2c7d42023-01-18 18:20:58 +0800201+ return 0;
developere0a1e0e2023-02-24 11:26:12 +0800202+ return hapd->driver->mu_dump(hapd->drv_priv, mu_onoff);
developer1c2c7d42023-01-18 18:20:58 +0800203+}
204diff --git a/src/ap/ap_drv_ops.h b/src/ap/ap_drv_ops.h
developerdfb50982023-09-11 13:34:36 +0800205index 8806217..6e0cf81 100644
developer1c2c7d42023-01-18 18:20:58 +0800206--- a/src/ap/ap_drv_ops.h
207+++ b/src/ap/ap_drv_ops.h
developer505c9432023-05-12 18:58:17 +0800208@@ -148,6 +148,8 @@ int hostapd_drv_configure_edcca_enable(struct hostapd_data *hapd);
developer1c2c7d42023-01-18 18:20:58 +0800209 int hostapd_drv_configure_edcca_threshold(struct hostapd_data *hapd,
210 const int *threshold);
211 int hostapd_drv_get_edcca(struct hostapd_data *hapd, const u8 mode, u8 *value);
developere0a1e0e2023-02-24 11:26:12 +0800212+int hostapd_drv_mu_ctrl(struct hostapd_data *hapd);
213+int hostapd_drv_mu_dump(struct hostapd_data *hapd, u8 *mu_onoff);
developer1c2c7d42023-01-18 18:20:58 +0800214
215 #include "drivers/driver.h"
216
217diff --git a/src/ap/hostapd.c b/src/ap/hostapd.c
developerdfb50982023-09-11 13:34:36 +0800218index b34c9d2..4251699 100644
developer1c2c7d42023-01-18 18:20:58 +0800219--- a/src/ap/hostapd.c
220+++ b/src/ap/hostapd.c
developerdfb50982023-09-11 13:34:36 +0800221@@ -2517,6 +2517,8 @@ dfs_offload:
developer1c2c7d42023-01-18 18:20:58 +0800222 if (hostapd_drv_configure_edcca_threshold(hapd,
223 hapd->iconf->edcca_threshold) < 0)
224 goto fail;
developere0a1e0e2023-02-24 11:26:12 +0800225+ if (hostapd_drv_mu_ctrl(hapd) < 0)
developer1c2c7d42023-01-18 18:20:58 +0800226+ goto fail;
227
228 wpa_printf(MSG_DEBUG, "%s: Setup of interface done.",
229 iface->bss[0]->conf->iface);
230diff --git a/src/common/mtk_vendor.h b/src/common/mtk_vendor.h
developerdfb50982023-09-11 13:34:36 +0800231index 6121857..60bc4cd 100644
developer1c2c7d42023-01-18 18:20:58 +0800232--- a/src/common/mtk_vendor.h
233+++ b/src/common/mtk_vendor.h
234@@ -10,6 +10,8 @@ enum mtk_nl80211_vendor_subcmds {
235 MTK_NL80211_VENDOR_SUBCMD_CSI_CTRL = 0xc2,
236 MTK_NL80211_VENDOR_SUBCMD_RFEATURE_CTRL = 0xc3,
237 MTK_NL80211_VENDOR_SUBCMD_WIRELESS_CTRL = 0xc4,
developere0a1e0e2023-02-24 11:26:12 +0800238+ MTK_NL80211_VENDOR_SUBCMD_MU_CTRL = 0xc5,
developer1c2c7d42023-01-18 18:20:58 +0800239+ MTK_NL80211_VENDOR_SUBCMD_PHY_CAPA_CTRL= 0xc6,
240 MTK_NL80211_VENDOR_SUBCMD_EDCCA_CTRL = 0xc7,
241 };
242
developer8bff6472023-07-17 11:11:44 +0800243@@ -177,6 +179,19 @@ enum mtk_vendor_attr_rfeature_ctrl {
developer1c2c7d42023-01-18 18:20:58 +0800244 NUM_MTK_VENDOR_ATTRS_RFEATURE_CTRL - 1
245 };
246
developere0a1e0e2023-02-24 11:26:12 +0800247+enum mtk_vendor_attr_mu_ctrl {
248+ MTK_VENDOR_ATTR_MU_CTRL_UNSPEC,
developer1c2c7d42023-01-18 18:20:58 +0800249+
developere0a1e0e2023-02-24 11:26:12 +0800250+ MTK_VENDOR_ATTR_MU_CTRL_ONOFF,
251+ MTK_VENDOR_ATTR_MU_CTRL_DUMP,
developer1c2c7d42023-01-18 18:20:58 +0800252+
253+ /* keep last */
developere0a1e0e2023-02-24 11:26:12 +0800254+ NUM_MTK_VENDOR_ATTRS_MU_CTRL,
255+ MTK_VENDOR_ATTR_MU_CTRL_MAX =
256+ NUM_MTK_VENDOR_ATTRS_MU_CTRL - 1
developer1c2c7d42023-01-18 18:20:58 +0800257+};
258+
259+
260 #define CSI_MAX_COUNT 256
261 #define ETH_ALEN 6
262
263diff --git a/src/drivers/driver.h b/src/drivers/driver.h
developerdfb50982023-09-11 13:34:36 +0800264index 443c4a7..1471ba2 100644
developer1c2c7d42023-01-18 18:20:58 +0800265--- a/src/drivers/driver.h
266+++ b/src/drivers/driver.h
developer8bff6472023-07-17 11:11:44 +0800267@@ -176,6 +176,11 @@ struct hostapd_channel_data {
268 * punct_bitmap - RU puncturing bitmap
developer1c2c7d42023-01-18 18:20:58 +0800269 */
developer505c9432023-05-12 18:58:17 +0800270 u16 punct_bitmap;
developer1c2c7d42023-01-18 18:20:58 +0800271+
272+ /**
developere0a1e0e2023-02-24 11:26:12 +0800273+ * mu onoff=<val> (bitmap- UL MU-MIMO(bit3), DL MU-MIMO(bit2), UL OFDMA(bit1), DL OFDMA(bit0))
developer1c2c7d42023-01-18 18:20:58 +0800274+ */
developere0a1e0e2023-02-24 11:26:12 +0800275+ u8 mu_onoff;
developer1c2c7d42023-01-18 18:20:58 +0800276 };
277
developer8bff6472023-07-17 11:11:44 +0800278 #define HE_MAC_CAPAB_0 0
279@@ -5084,6 +5089,14 @@ struct wpa_driver_ops {
developer1c2c7d42023-01-18 18:20:58 +0800280 const s8 edcca_compensation);
281 int (*configure_edcca_threshold)(void *priv, const int *threshold);
282 int (*get_edcca)(void *priv, const u8 mode, u8 *value);
283+
284+ /**
developere0a1e0e2023-02-24 11:26:12 +0800285+ * mu_ctrl - ctrl on off for UL/DL MURU
developer1c2c7d42023-01-18 18:20:58 +0800286+ * @priv: Private driver interface data
287+ *
288+ */
developere0a1e0e2023-02-24 11:26:12 +0800289+ int (*mu_ctrl)(void *priv, u8 mu_onoff);
290+ int (*mu_dump)(void *priv, u8 *mu_onoff);
developer1c2c7d42023-01-18 18:20:58 +0800291 };
292
293 /**
294diff --git a/src/drivers/driver_nl80211.c b/src/drivers/driver_nl80211.c
developerdfb50982023-09-11 13:34:36 +0800295index 5a3e208..8e8a4fd 100644
developer1c2c7d42023-01-18 18:20:58 +0800296--- a/src/drivers/driver_nl80211.c
297+++ b/src/drivers/driver_nl80211.c
developerdfb50982023-09-11 13:34:36 +0800298@@ -13497,6 +13497,114 @@ fail:
developer1c2c7d42023-01-18 18:20:58 +0800299 }
300
301
302+#ifdef CONFIG_IEEE80211AX
developere0a1e0e2023-02-24 11:26:12 +0800303+static int nl80211_mu_onoff(void *priv, u8 mu_onoff)
developer1c2c7d42023-01-18 18:20:58 +0800304+{
305+ struct i802_bss *bss = priv;
306+ struct wpa_driver_nl80211_data *drv = bss->drv;
307+ struct nl_msg *msg;
308+ struct nlattr *data;
309+ int ret;
310+
developere0a1e0e2023-02-24 11:26:12 +0800311+ if (!drv->mtk_mu_vendor_cmd_avail) {
developer1c2c7d42023-01-18 18:20:58 +0800312+ wpa_printf(MSG_INFO,
developere0a1e0e2023-02-24 11:26:12 +0800313+ "nl80211: Driver does not support setting mu control");
developer1c2c7d42023-01-18 18:20:58 +0800314+ return 0;
315+ }
316+
317+ if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_VENDOR)) ||
318+ nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_MTK) ||
developere0a1e0e2023-02-24 11:26:12 +0800319+ nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD, MTK_NL80211_VENDOR_SUBCMD_MU_CTRL) ||
developer1c2c7d42023-01-18 18:20:58 +0800320+ !(data = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
developere0a1e0e2023-02-24 11:26:12 +0800321+ nla_put_u8(msg, MTK_VENDOR_ATTR_MU_CTRL_ONOFF, mu_onoff)) {
developer1c2c7d42023-01-18 18:20:58 +0800322+ nlmsg_free(msg);
323+ return -ENOBUFS;
324+ }
325+ nla_nest_end(msg, data);
326+ ret = send_and_recv_msgs(drv, msg, NULL, NULL, NULL, NULL);
327+ if(ret){
developere0a1e0e2023-02-24 11:26:12 +0800328+ wpa_printf(MSG_ERROR, "Failed to set mu_onoff. ret=%d (%s)", ret, strerror(-ret));
developer1c2c7d42023-01-18 18:20:58 +0800329+ }
330+ return ret;
331+}
332+
333+
developere0a1e0e2023-02-24 11:26:12 +0800334+static int mu_dump_handler(struct nl_msg *msg, void *arg)
developer1c2c7d42023-01-18 18:20:58 +0800335+{
developere0a1e0e2023-02-24 11:26:12 +0800336+ u8 *mu_onoff = (u8 *) arg;
developer1c2c7d42023-01-18 18:20:58 +0800337+ struct nlattr *tb[NL80211_ATTR_MAX + 1];
developere0a1e0e2023-02-24 11:26:12 +0800338+ struct nlattr *tb_vendor[MTK_VENDOR_ATTR_MU_CTRL_MAX + 1];
developer1c2c7d42023-01-18 18:20:58 +0800339+ struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg));
340+ struct nlattr *nl_vend, *attr;
341+
342+ static const struct nla_policy
developere0a1e0e2023-02-24 11:26:12 +0800343+ mu_ctrl_policy[NUM_MTK_VENDOR_ATTRS_MU_CTRL + 1] = {
344+ [MTK_VENDOR_ATTR_MU_CTRL_ONOFF] = {.type = NLA_U8 },
345+ [MTK_VENDOR_ATTR_MU_CTRL_DUMP] = {.type = NLA_U8 },
developer1c2c7d42023-01-18 18:20:58 +0800346+ };
347+
348+ nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0),
349+ genlmsg_attrlen(gnlh, 0), NULL);
350+
351+ nl_vend = tb[NL80211_ATTR_VENDOR_DATA];
352+ if (!nl_vend)
353+ return NL_SKIP;
354+
developere0a1e0e2023-02-24 11:26:12 +0800355+ nla_parse(tb_vendor, MTK_VENDOR_ATTR_MU_CTRL_MAX,
developer1c2c7d42023-01-18 18:20:58 +0800356+ nla_data(nl_vend), nla_len(nl_vend), NULL);
357+
developere0a1e0e2023-02-24 11:26:12 +0800358+ attr = tb_vendor[MTK_VENDOR_ATTR_MU_CTRL_DUMP];
developer1c2c7d42023-01-18 18:20:58 +0800359+ if (!attr) {
developere0a1e0e2023-02-24 11:26:12 +0800360+ wpa_printf(MSG_ERROR, "nl80211: cannot find MTK_VENDOR_ATTR_MU_CTRL_DUMP");
developer1c2c7d42023-01-18 18:20:58 +0800361+ return NL_SKIP;
362+ }
363+
developere0a1e0e2023-02-24 11:26:12 +0800364+ *mu_onoff = nla_get_u8(attr);
365+ wpa_printf(MSG_DEBUG, "nla_get mu_onoff: %d\n", *mu_onoff);
developer1c2c7d42023-01-18 18:20:58 +0800366+
367+ return 0;
368+}
369+
developere0a1e0e2023-02-24 11:26:12 +0800370+static int nl80211_mu_dump(void *priv, u8 *mu_onoff)
developer1c2c7d42023-01-18 18:20:58 +0800371+{
372+ struct i802_bss *bss = priv;
373+ struct wpa_driver_nl80211_data *drv = bss->drv;
374+ struct nl_msg *msg;
375+ struct nlattr *attr;
376+ int ret;
377+
developere0a1e0e2023-02-24 11:26:12 +0800378+ if (!drv->mtk_mu_vendor_cmd_avail) {
developer1c2c7d42023-01-18 18:20:58 +0800379+ wpa_printf(MSG_INFO,
developere0a1e0e2023-02-24 11:26:12 +0800380+ "nl80211: Driver does not support setting mu control");
developer1c2c7d42023-01-18 18:20:58 +0800381+ return 0;
382+ }
383+
384+ if (!(msg = nl80211_drv_msg(drv, NLM_F_DUMP, NL80211_CMD_VENDOR)) ||
385+ nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_MTK) ||
developere0a1e0e2023-02-24 11:26:12 +0800386+ nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD, MTK_NL80211_VENDOR_SUBCMD_MU_CTRL)) {
developer1c2c7d42023-01-18 18:20:58 +0800387+ nlmsg_free(msg);
388+ return -ENOBUFS;
389+ }
390+
391+ attr = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA);
392+ if (!attr) {
393+ nlmsg_free(msg);
394+ return -1;
395+ }
396+
397+ nla_nest_end(msg, attr);
398+
developere0a1e0e2023-02-24 11:26:12 +0800399+ ret = send_and_recv_msgs(drv, msg, mu_dump_handler, mu_onoff, NULL, NULL);
developer1c2c7d42023-01-18 18:20:58 +0800400+
401+ if(ret){
developere0a1e0e2023-02-24 11:26:12 +0800402+ wpa_printf(MSG_ERROR, "Failed to get mu_onoff. ret=%d (%s)", ret, strerror(-ret));
developer1c2c7d42023-01-18 18:20:58 +0800403+ }
404+
405+ return ret;
406+}
407+#endif /* CONFIG_IEEE80211AX */
408+
409+
410 #ifdef CONFIG_DPP
411 static int nl80211_dpp_listen(void *priv, bool enable)
412 {
developerdfb50982023-09-11 13:34:36 +0800413@@ -13947,6 +14055,8 @@ const struct wpa_driver_ops wpa_driver_nl80211_ops = {
developer1c2c7d42023-01-18 18:20:58 +0800414 .update_connect_params = nl80211_update_connection_params,
415 .send_external_auth_status = nl80211_send_external_auth_status,
416 .set_4addr_mode = nl80211_set_4addr_mode,
developere0a1e0e2023-02-24 11:26:12 +0800417+ .mu_ctrl = nl80211_mu_onoff,
418+ .mu_dump = nl80211_mu_dump,
developer1c2c7d42023-01-18 18:20:58 +0800419 #ifdef CONFIG_DPP
420 .dpp_listen = nl80211_dpp_listen,
421 #endif /* CONFIG_DPP */
422diff --git a/src/drivers/driver_nl80211.h b/src/drivers/driver_nl80211.h
developerdfb50982023-09-11 13:34:36 +0800423index 51b3fbe..bd5d284 100644
developer1c2c7d42023-01-18 18:20:58 +0800424--- a/src/drivers/driver_nl80211.h
425+++ b/src/drivers/driver_nl80211.h
developer8bff6472023-07-17 11:11:44 +0800426@@ -203,6 +203,7 @@ struct wpa_driver_nl80211_data {
developer505c9432023-05-12 18:58:17 +0800427 unsigned int puncturing:1;
developer8bff6472023-07-17 11:11:44 +0800428 unsigned int qca_ap_allowed_freqs:1;
developer1c2c7d42023-01-18 18:20:58 +0800429 unsigned int mtk_edcca_vendor_cmd_avail:1;
developere0a1e0e2023-02-24 11:26:12 +0800430+ unsigned int mtk_mu_vendor_cmd_avail:1;
developer1c2c7d42023-01-18 18:20:58 +0800431
432 u64 vendor_scan_cookie;
433 u64 remain_on_chan_cookie;
434diff --git a/src/drivers/driver_nl80211_capa.c b/src/drivers/driver_nl80211_capa.c
developerdfb50982023-09-11 13:34:36 +0800435index 5dadf24..ac66a91 100644
developer1c2c7d42023-01-18 18:20:58 +0800436--- a/src/drivers/driver_nl80211_capa.c
437+++ b/src/drivers/driver_nl80211_capa.c
developer8bff6472023-07-17 11:11:44 +0800438@@ -1113,6 +1113,9 @@ static int wiphy_info_handler(struct nl_msg *msg, void *arg)
439 case MTK_NL80211_VENDOR_SUBCMD_EDCCA_CTRL:
developer1c2c7d42023-01-18 18:20:58 +0800440 drv->mtk_edcca_vendor_cmd_avail = 1;
441 break;
developere0a1e0e2023-02-24 11:26:12 +0800442+ case MTK_NL80211_VENDOR_SUBCMD_MU_CTRL :
443+ drv->mtk_mu_vendor_cmd_avail = 1;
developer1c2c7d42023-01-18 18:20:58 +0800444+ break;
445 }
446 }
447
448--
developerdfb50982023-09-11 13:34:36 +08004492.18.0
developer1c2c7d42023-01-18 18:20:58 +0800450