blob: a02ef0c736e6b8ee9e6f6e12740c58cb2c84b4f8 [file] [log] [blame]
developer8eb72a32023-03-30 08:32:07 +08001From ac475cd84943d939463cb26f5a752f98ddfc3be6 Mon Sep 17 00:00:00 2001
developer8f0138a2022-09-01 21:20:56 +08002From: StanleyYP Wang <StanleyYP.Wang@mediatek.com>
3Date: Fri, 2 Sep 2022 01:03:23 +0800
developer8eb72a32023-03-30 08:32:07 +08004Subject: [PATCH 07/25] hostapd: mtk: Add three wire PTA ctrl hostapd vendor
developer57a17d42023-02-14 23:19:14 +08005 command
developer8f0138a2022-09-01 21:20:56 +08006
7Signed-off-by: StanleyYP Wang <StanleyYP.Wang@mediatek.com>
8---
9 hostapd/config_file.c | 4 ++++
10 src/ap/ap_config.c | 1 +
11 src/ap/ap_config.h | 13 ++++++++++++
12 src/ap/ap_drv_ops.c | 11 +++++++++++
13 src/ap/ap_drv_ops.h | 1 +
14 src/ap/hostapd.c | 2 ++
15 src/common/mtk_vendor.h | 16 +++++++++++++++
developer5cebe562022-10-08 00:32:24 +080016 src/drivers/driver.h | 8 ++++++++
developer8f0138a2022-09-01 21:20:56 +080017 src/drivers/driver_nl80211.c | 33 +++++++++++++++++++++++++++++++
18 src/drivers/driver_nl80211.h | 1 +
19 src/drivers/driver_nl80211_capa.c | 3 +++
developer5cebe562022-10-08 00:32:24 +080020 11 files changed, 93 insertions(+)
developer8f0138a2022-09-01 21:20:56 +080021
22diff --git a/hostapd/config_file.c b/hostapd/config_file.c
developer81939a52023-03-25 15:31:11 +080023index 62e8b33..6e526eb 100644
developer8f0138a2022-09-01 21:20:56 +080024--- a/hostapd/config_file.c
25+++ b/hostapd/config_file.c
developer57a17d42023-02-14 23:19:14 +080026@@ -4796,6 +4796,10 @@ static int hostapd_config_fill(struct hostapd_config *conf,
developer8f0138a2022-09-01 21:20:56 +080027 return 1;
28 }
29 conf->edcca_compensation = (s8) val;
30+ } else if (os_strcmp(buf, "three_wire_enable") == 0) {
31+ u8 en = atoi(pos);
32+
33+ conf->three_wire_enable = en;
34 } else {
35 wpa_printf(MSG_ERROR,
36 "Line %d: unknown configuration item '%s'",
37diff --git a/src/ap/ap_config.c b/src/ap/ap_config.c
developer81939a52023-03-25 15:31:11 +080038index d4fc191..1a1a059 100644
developer8f0138a2022-09-01 21:20:56 +080039--- a/src/ap/ap_config.c
40+++ b/src/ap/ap_config.c
41@@ -297,6 +297,7 @@ struct hostapd_config * hostapd_config_defaults(void)
42
43 conf->edcca_enable = EDCCA_MODE_AUTO;
44 conf->edcca_compensation = EDCCA_DEFAULT_COMPENSATION;
45+ conf->three_wire_enable = THREE_WIRE_MODE_DISABLE;
46
47 return conf;
48 }
49diff --git a/src/ap/ap_config.h b/src/ap/ap_config.h
developer81939a52023-03-25 15:31:11 +080050index 37779b7..f1be7ae 100644
developer8f0138a2022-09-01 21:20:56 +080051--- a/src/ap/ap_config.h
52+++ b/src/ap/ap_config.h
developer57a17d42023-02-14 23:19:14 +080053@@ -1158,6 +1158,19 @@ struct hostapd_config {
developer8f0138a2022-09-01 21:20:56 +080054 u8 edcca_enable;
55 s8 edcca_compensation;
developerbf811862022-11-17 14:31:04 +080056 int *edcca_threshold;
developer8f0138a2022-09-01 21:20:56 +080057+ u8 three_wire_enable;
developer03ddc372022-09-05 15:21:03 +080058+};
59+
developer8f0138a2022-09-01 21:20:56 +080060+enum three_wire_mode {
61+ THREE_WIRE_MODE_DISABLE,
62+ THREE_WIRE_MODE_EXT0_ENABLE,
63+ THREE_WIRE_MODE_EXT1_ENABLE,
64+ THREE_WIRE_MODE_ALL_ENABLE,
65+
66+ /* keep last */
67+ NUM_THREE_WIRE_MODE,
68+ THREE_WIRE_MODE_MAX =
69+ NUM_THREE_WIRE_MODE - 1
developer03ddc372022-09-05 15:21:03 +080070 };
71
72 enum edcca_mode {
developer8f0138a2022-09-01 21:20:56 +080073diff --git a/src/ap/ap_drv_ops.c b/src/ap/ap_drv_ops.c
developer81939a52023-03-25 15:31:11 +080074index 60b9fc0..973b44e 100644
developer8f0138a2022-09-01 21:20:56 +080075--- a/src/ap/ap_drv_ops.c
76+++ b/src/ap/ap_drv_ops.c
developer57de9b72023-02-20 11:15:54 +080077@@ -1053,3 +1053,14 @@ int hostapd_drv_mu_dump(struct hostapd_data *hapd, u8 *mu_onoff)
developer8f0138a2022-09-01 21:20:56 +080078 return 0;
developer57de9b72023-02-20 11:15:54 +080079 return hapd->driver->mu_dump(hapd->drv_priv, mu_onoff);
developer8f0138a2022-09-01 21:20:56 +080080 }
81+
82+int hostapd_drv_three_wire_ctrl(struct hostapd_data *hapd)
83+{
84+ if (!hapd->driver || !hapd->driver->three_wire_ctrl)
85+ return 0;
86+ if (hapd->iconf->three_wire_enable > THREE_WIRE_MODE_MAX) {
87+ wpa_printf(MSG_INFO, "Invalid value for three wire enable\n");
88+ return 0;
89+ }
90+ return hapd->driver->three_wire_ctrl(hapd->drv_priv, hapd->iconf->three_wire_enable);
91+}
92diff --git a/src/ap/ap_drv_ops.h b/src/ap/ap_drv_ops.h
developer81939a52023-03-25 15:31:11 +080093index 185d5f3..51d7b3b 100644
developer8f0138a2022-09-01 21:20:56 +080094--- a/src/ap/ap_drv_ops.h
95+++ b/src/ap/ap_drv_ops.h
developerbf811862022-11-17 14:31:04 +080096@@ -144,6 +144,7 @@ int hostapd_drv_configure_edcca_threshold(struct hostapd_data *hapd,
97 int hostapd_drv_get_edcca(struct hostapd_data *hapd, const u8 mode, u8 *value);
developer57de9b72023-02-20 11:15:54 +080098 int hostapd_drv_mu_ctrl(struct hostapd_data *hapd);
99 int hostapd_drv_mu_dump(struct hostapd_data *hapd, u8 *mu_onoff);
developer8f0138a2022-09-01 21:20:56 +0800100+int hostapd_drv_three_wire_ctrl(struct hostapd_data *hapd);
101
102 #include "drivers/driver.h"
103
104diff --git a/src/ap/hostapd.c b/src/ap/hostapd.c
developer81939a52023-03-25 15:31:11 +0800105index 71d7bfa..77e7eb4 100644
developer8f0138a2022-09-01 21:20:56 +0800106--- a/src/ap/hostapd.c
107+++ b/src/ap/hostapd.c
developer57a17d42023-02-14 23:19:14 +0800108@@ -2304,6 +2304,8 @@ dfs_offload:
developer8f0138a2022-09-01 21:20:56 +0800109 goto fail;
developer57de9b72023-02-20 11:15:54 +0800110 if (hostapd_drv_mu_ctrl(hapd) < 0)
developer8f0138a2022-09-01 21:20:56 +0800111 goto fail;
112+ if (hostapd_drv_three_wire_ctrl(hapd) < 0)
113+ goto fail;
114
115 wpa_printf(MSG_DEBUG, "%s: Setup of interface done.",
116 iface->bss[0]->conf->iface);
117diff --git a/src/common/mtk_vendor.h b/src/common/mtk_vendor.h
developer81939a52023-03-25 15:31:11 +0800118index ef8618e..ed47487 100644
developer8f0138a2022-09-01 21:20:56 +0800119--- a/src/common/mtk_vendor.h
120+++ b/src/common/mtk_vendor.h
121@@ -13,6 +13,7 @@ enum mtk_nl80211_vendor_subcmds {
developer57de9b72023-02-20 11:15:54 +0800122 MTK_NL80211_VENDOR_SUBCMD_MU_CTRL = 0xc5,
developer8f0138a2022-09-01 21:20:56 +0800123 MTK_NL80211_VENDOR_SUBCMD_PHY_CAPA_CTRL= 0xc6,
124 MTK_NL80211_VENDOR_SUBCMD_EDCCA_CTRL = 0xc7,
125+ MTK_NL80211_VENDOR_SUBCMD_3WIRE_CTRL = 0xc8
126 };
127
128 enum mtk_vendor_attr_edcca_ctrl {
developerbf811862022-11-17 14:31:04 +0800129@@ -55,6 +56,21 @@ static struct nla_policy edcca_ctrl_policy[NUM_MTK_VENDOR_ATTRS_EDCCA_CTRL] = {
developer8f0138a2022-09-01 21:20:56 +0800130 [MTK_VENDOR_ATTR_EDCCA_CTRL_COMPENSATE] = { .type = NLA_U8 },
131 };
132
133+enum mtk_vendor_attr_3wire_ctrl {
134+ MTK_VENDOR_ATTR_3WIRE_CTRL_UNSPEC,
135+
136+ MTK_VENDOR_ATTR_3WIRE_CTRL_MODE,
137+
138+ /* keep last */
139+ NUM_MTK_VENDOR_ATTRS_3WIRE_CTRL,
140+ MTK_VENDOR_ATTR_3WIRE_CTRL_MAX =
141+ NUM_MTK_VENDOR_ATTRS_3WIRE_CTRL - 1
142+};
143+
144+static struct nla_policy three_wire_ctrl_policy[NUM_MTK_VENDOR_ATTRS_3WIRE_CTRL] = {
145+ [MTK_VENDOR_ATTR_3WIRE_CTRL_MODE] = {.type = NLA_U8 },
146+};
147+
148 enum mtk_vendor_attr_csi_ctrl {
149 MTK_VENDOR_ATTR_CSI_CTRL_UNSPEC,
150
151diff --git a/src/drivers/driver.h b/src/drivers/driver.h
developer81939a52023-03-25 15:31:11 +0800152index fa5ad45..6c4c70c 100644
developer8f0138a2022-09-01 21:20:56 +0800153--- a/src/drivers/driver.h
154+++ b/src/drivers/driver.h
developerbf811862022-11-17 14:31:04 +0800155@@ -4693,6 +4693,14 @@ struct wpa_driver_ops {
developer8f0138a2022-09-01 21:20:56 +0800156 */
developer57de9b72023-02-20 11:15:54 +0800157 int (*mu_ctrl)(void *priv, u8 mu_onoff);
158 int (*mu_dump)(void *priv, u8 *mu_onoff);
developer5cebe562022-10-08 00:32:24 +0800159+
160+ /**
161+ * three_wire_ctrl - set three_wire_ctrl mode
162+ * @priv: Private driver interface data
163+ * @three_wire_enable: three_wire_ctrl mode
164+ *
165+ */
developer8f0138a2022-09-01 21:20:56 +0800166+ int (*three_wire_ctrl)(void *priv, u8 three_wire_enable);
167 };
168
169 /**
170diff --git a/src/drivers/driver_nl80211.c b/src/drivers/driver_nl80211.c
developer81939a52023-03-25 15:31:11 +0800171index 0523aab..568c704 100644
developer8f0138a2022-09-01 21:20:56 +0800172--- a/src/drivers/driver_nl80211.c
173+++ b/src/drivers/driver_nl80211.c
developerbf811862022-11-17 14:31:04 +0800174@@ -12637,6 +12637,38 @@ static int nl80211_get_edcca(void *priv, const u8 mode, u8 *value)
developer8f0138a2022-09-01 21:20:56 +0800175 return ret;
176 }
177
178+static int nl80211_enable_three_wire(void *priv, const u8 three_wire_enable)
179+{
180+ struct i802_bss *bss = priv;
181+ struct wpa_driver_nl80211_data *drv = bss->drv;
182+ /* Prepare nl80211 cmd */
183+ struct nl_msg *msg;
184+ struct nlattr *data;
185+ int ret;
186+
187+ if (!drv->mtk_3wire_vendor_cmd_avail) {
188+ wpa_printf(MSG_INFO,
189+ "nl80211: Driver does not support setting three wire control");
190+ return 0;
191+ }
192+
193+ if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_VENDOR)) ||
194+ nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_MTK) ||
195+ nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
196+ MTK_NL80211_VENDOR_SUBCMD_3WIRE_CTRL) ||
197+ !(data = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
198+ nla_put_u8(msg, MTK_VENDOR_ATTR_3WIRE_CTRL_MODE, three_wire_enable)) {
199+ nlmsg_free(msg);
200+ return -ENOBUFS;
201+ }
202+ nla_nest_end(msg, data);
203+ ret = send_and_recv_msgs(drv, msg, NULL, NULL, NULL, NULL);
204+ if (ret) {
205+ wpa_printf(MSG_ERROR, "Failed to enable three wire. ret=%d (%s) ",
206+ ret, strerror(-ret));
207+ }
208+ return ret;
209+}
210
211 const struct wpa_driver_ops wpa_driver_nl80211_ops = {
212 .name = "nl80211",
developerbf811862022-11-17 14:31:04 +0800213@@ -12789,4 +12821,5 @@ const struct wpa_driver_ops wpa_driver_nl80211_ops = {
214 .configure_edcca_enable = nl80211_configure_edcca_enable,
developer8f0138a2022-09-01 21:20:56 +0800215 .configure_edcca_threshold = nl80211_configure_edcca_threshold,
developerbf811862022-11-17 14:31:04 +0800216 .get_edcca = nl80211_get_edcca,
developer8f0138a2022-09-01 21:20:56 +0800217+ .three_wire_ctrl = nl80211_enable_three_wire,
218 };
219diff --git a/src/drivers/driver_nl80211.h b/src/drivers/driver_nl80211.h
developer81939a52023-03-25 15:31:11 +0800220index 1dd984c..35fd4d2 100644
developer8f0138a2022-09-01 21:20:56 +0800221--- a/src/drivers/driver_nl80211.h
222+++ b/src/drivers/driver_nl80211.h
developerc41fcd32022-09-20 22:09:06 +0800223@@ -183,6 +183,7 @@ struct wpa_driver_nl80211_data {
224 unsigned int uses_6ghz:1;
developer8f0138a2022-09-01 21:20:56 +0800225 unsigned int mtk_edcca_vendor_cmd_avail:1;
developer57de9b72023-02-20 11:15:54 +0800226 unsigned int mtk_mu_vendor_cmd_avail:1;
developer8f0138a2022-09-01 21:20:56 +0800227+ unsigned int mtk_3wire_vendor_cmd_avail:1;
228
229 u64 vendor_scan_cookie;
230 u64 remain_on_chan_cookie;
231diff --git a/src/drivers/driver_nl80211_capa.c b/src/drivers/driver_nl80211_capa.c
developer81939a52023-03-25 15:31:11 +0800232index cc11891..dc2d7b1 100644
developer8f0138a2022-09-01 21:20:56 +0800233--- a/src/drivers/driver_nl80211_capa.c
234+++ b/src/drivers/driver_nl80211_capa.c
developerc41fcd32022-09-20 22:09:06 +0800235@@ -1059,6 +1059,9 @@ static int wiphy_info_handler(struct nl_msg *msg, void *arg)
developer57de9b72023-02-20 11:15:54 +0800236 case MTK_NL80211_VENDOR_SUBCMD_MU_CTRL :
237 drv->mtk_mu_vendor_cmd_avail = 1;
developer8f0138a2022-09-01 21:20:56 +0800238 break;
239+ case MTK_NL80211_VENDOR_SUBCMD_3WIRE_CTRL :
240+ drv->mtk_3wire_vendor_cmd_avail = 1;
241+ break;
242 }
243 }
244
245--
developer81939a52023-03-25 15:31:11 +08002462.18.0
developer8f0138a2022-09-01 21:20:56 +0800247