blob: c853b08de083399f08eac0e271d486b53e3bd96b [file] [log] [blame]
developer2e506112022-11-21 10:53:12 +08001From f080902be233f0c28d205f62f737edabdb6b6aaa Mon Sep 17 00:00:00 2001
developer27b55252022-09-05 19:09:45 +08002From: StanleyYP Wang <StanleyYP.Wang@mediatek.com>
3Date: Fri, 2 Sep 2022 01:03:23 +0800
developer2e506112022-11-21 10:53:12 +08004Subject: [PATCH 2/6] Add three wire PTA ctrl hostapd vendor command
developer27b55252022-09-05 19:09:45 +08005
6Signed-off-by: StanleyYP Wang <StanleyYP.Wang@mediatek.com>
7---
8 hostapd/config_file.c | 4 ++++
9 src/ap/ap_config.c | 1 +
10 src/ap/ap_config.h | 13 ++++++++++++
11 src/ap/ap_drv_ops.c | 11 +++++++++++
12 src/ap/ap_drv_ops.h | 1 +
13 src/ap/hostapd.c | 2 ++
14 src/common/mtk_vendor.h | 16 +++++++++++++++
developer29344f12022-10-17 12:01:44 +080015 src/drivers/driver.h | 8 ++++++++
developer27b55252022-09-05 19:09:45 +080016 src/drivers/driver_nl80211.c | 33 +++++++++++++++++++++++++++++++
17 src/drivers/driver_nl80211.h | 1 +
18 src/drivers/driver_nl80211_capa.c | 3 +++
developer29344f12022-10-17 12:01:44 +080019 11 files changed, 93 insertions(+)
developer27b55252022-09-05 19:09:45 +080020
21diff --git a/hostapd/config_file.c b/hostapd/config_file.c
developer2e506112022-11-21 10:53:12 +080022index afe0f0c..a4875ee 100644
developer27b55252022-09-05 19:09:45 +080023--- a/hostapd/config_file.c
24+++ b/hostapd/config_file.c
developer2e506112022-11-21 10:53:12 +080025@@ -4836,6 +4836,10 @@ static int hostapd_config_fill(struct hostapd_config *conf,
developer27b55252022-09-05 19:09:45 +080026 return 1;
27 }
28 conf->edcca_compensation = (s8) val;
29+ } else if (os_strcmp(buf, "three_wire_enable") == 0) {
30+ u8 en = atoi(pos);
31+
32+ conf->three_wire_enable = en;
33 } else {
34 wpa_printf(MSG_ERROR,
35 "Line %d: unknown configuration item '%s'",
36diff --git a/src/ap/ap_config.c b/src/ap/ap_config.c
developer2e506112022-11-21 10:53:12 +080037index 0e1f192..9249a6b 100644
developer27b55252022-09-05 19:09:45 +080038--- a/src/ap/ap_config.c
39+++ b/src/ap/ap_config.c
40@@ -297,6 +297,7 @@ struct hostapd_config * hostapd_config_defaults(void)
41
42 conf->edcca_enable = EDCCA_MODE_AUTO;
43 conf->edcca_compensation = EDCCA_DEFAULT_COMPENSATION;
44+ conf->three_wire_enable = THREE_WIRE_MODE_DISABLE;
45
46 return conf;
47 }
48diff --git a/src/ap/ap_config.h b/src/ap/ap_config.h
developer2e506112022-11-21 10:53:12 +080049index 41b8c68..71cf515 100644
developer27b55252022-09-05 19:09:45 +080050--- a/src/ap/ap_config.h
51+++ b/src/ap/ap_config.h
developer2e506112022-11-21 10:53:12 +080052@@ -1157,6 +1157,19 @@ struct hostapd_config {
developer27b55252022-09-05 19:09:45 +080053 u8 edcca_enable;
54 s8 edcca_compensation;
developer2e506112022-11-21 10:53:12 +080055 int *edcca_threshold;
developer27b55252022-09-05 19:09:45 +080056+ u8 three_wire_enable;
57+};
58+
59+enum three_wire_mode {
60+ THREE_WIRE_MODE_DISABLE,
61+ THREE_WIRE_MODE_EXT0_ENABLE,
62+ THREE_WIRE_MODE_EXT1_ENABLE,
63+ THREE_WIRE_MODE_ALL_ENABLE,
64+
65+ /* keep last */
66+ NUM_THREE_WIRE_MODE,
67+ THREE_WIRE_MODE_MAX =
68+ NUM_THREE_WIRE_MODE - 1
69 };
70
71 enum edcca_mode {
72diff --git a/src/ap/ap_drv_ops.c b/src/ap/ap_drv_ops.c
developer2e506112022-11-21 10:53:12 +080073index 4598737..a1d83e4 100644
developer27b55252022-09-05 19:09:45 +080074--- a/src/ap/ap_drv_ops.c
75+++ b/src/ap/ap_drv_ops.c
developer2e506112022-11-21 10:53:12 +080076@@ -1053,3 +1053,14 @@ int hostapd_drv_hemu_dump(struct hostapd_data *hapd, u8 *hemu_onoff)
developer27b55252022-09-05 19:09:45 +080077 return 0;
78 return hapd->driver->hemu_dump(hapd->drv_priv, hemu_onoff);
79 }
80+
81+int hostapd_drv_three_wire_ctrl(struct hostapd_data *hapd)
82+{
83+ if (!hapd->driver || !hapd->driver->three_wire_ctrl)
84+ return 0;
85+ if (hapd->iconf->three_wire_enable > THREE_WIRE_MODE_MAX) {
86+ wpa_printf(MSG_INFO, "Invalid value for three wire enable\n");
87+ return 0;
88+ }
89+ return hapd->driver->three_wire_ctrl(hapd->drv_priv, hapd->iconf->three_wire_enable);
90+}
91diff --git a/src/ap/ap_drv_ops.h b/src/ap/ap_drv_ops.h
developer2e506112022-11-21 10:53:12 +080092index bca39c5..5ba6297 100644
developer27b55252022-09-05 19:09:45 +080093--- a/src/ap/ap_drv_ops.h
94+++ b/src/ap/ap_drv_ops.h
developer2e506112022-11-21 10:53:12 +080095@@ -144,6 +144,7 @@ int hostapd_drv_configure_edcca_threshold(struct hostapd_data *hapd,
96 int hostapd_drv_get_edcca(struct hostapd_data *hapd, const u8 mode, u8 *value);
developer27b55252022-09-05 19:09:45 +080097 int hostapd_drv_hemu_ctrl(struct hostapd_data *hapd);
98 int hostapd_drv_hemu_dump(struct hostapd_data *hapd, u8 *hemu_onoff);
99+int hostapd_drv_three_wire_ctrl(struct hostapd_data *hapd);
100
101 #include "drivers/driver.h"
102
103diff --git a/src/ap/hostapd.c b/src/ap/hostapd.c
developer2e506112022-11-21 10:53:12 +0800104index 921769d..f9dabdf 100644
developer27b55252022-09-05 19:09:45 +0800105--- a/src/ap/hostapd.c
106+++ b/src/ap/hostapd.c
developer2e506112022-11-21 10:53:12 +0800107@@ -2303,6 +2303,8 @@ dfs_offload:
developer27b55252022-09-05 19:09:45 +0800108 goto fail;
109 if (hostapd_drv_hemu_ctrl(hapd) < 0)
110 goto fail;
111+ if (hostapd_drv_three_wire_ctrl(hapd) < 0)
112+ goto fail;
113
114 wpa_printf(MSG_DEBUG, "%s: Setup of interface done.",
115 iface->bss[0]->conf->iface);
116diff --git a/src/common/mtk_vendor.h b/src/common/mtk_vendor.h
developer2e506112022-11-21 10:53:12 +0800117index 69a46df..ee5a4f4 100644
developer27b55252022-09-05 19:09:45 +0800118--- a/src/common/mtk_vendor.h
119+++ b/src/common/mtk_vendor.h
120@@ -13,6 +13,7 @@ enum mtk_nl80211_vendor_subcmds {
121 MTK_NL80211_VENDOR_SUBCMD_HEMU_CTRL = 0xc5,
122 MTK_NL80211_VENDOR_SUBCMD_PHY_CAPA_CTRL= 0xc6,
123 MTK_NL80211_VENDOR_SUBCMD_EDCCA_CTRL = 0xc7,
124+ MTK_NL80211_VENDOR_SUBCMD_3WIRE_CTRL = 0xc8
125 };
126
127 enum mtk_vendor_attr_edcca_ctrl {
developer2e506112022-11-21 10:53:12 +0800128@@ -55,6 +56,21 @@ static struct nla_policy edcca_ctrl_policy[NUM_MTK_VENDOR_ATTRS_EDCCA_CTRL] = {
developer27b55252022-09-05 19:09:45 +0800129 [MTK_VENDOR_ATTR_EDCCA_CTRL_COMPENSATE] = { .type = NLA_U8 },
130 };
131
132+enum mtk_vendor_attr_3wire_ctrl {
133+ MTK_VENDOR_ATTR_3WIRE_CTRL_UNSPEC,
134+
135+ MTK_VENDOR_ATTR_3WIRE_CTRL_MODE,
136+
137+ /* keep last */
138+ NUM_MTK_VENDOR_ATTRS_3WIRE_CTRL,
139+ MTK_VENDOR_ATTR_3WIRE_CTRL_MAX =
140+ NUM_MTK_VENDOR_ATTRS_3WIRE_CTRL - 1
141+};
142+
143+static struct nla_policy three_wire_ctrl_policy[NUM_MTK_VENDOR_ATTRS_3WIRE_CTRL] = {
144+ [MTK_VENDOR_ATTR_3WIRE_CTRL_MODE] = {.type = NLA_U8 },
145+};
146+
147 enum mtk_vendor_attr_csi_ctrl {
148 MTK_VENDOR_ATTR_CSI_CTRL_UNSPEC,
149
150diff --git a/src/drivers/driver.h b/src/drivers/driver.h
developer2e506112022-11-21 10:53:12 +0800151index 4cd7505..9ca19af 100644
developer27b55252022-09-05 19:09:45 +0800152--- a/src/drivers/driver.h
153+++ b/src/drivers/driver.h
developer2e506112022-11-21 10:53:12 +0800154@@ -4693,6 +4693,14 @@ struct wpa_driver_ops {
developer27b55252022-09-05 19:09:45 +0800155 */
156 int (*hemu_ctrl)(void *priv, u8 hemu_onoff);
157 int (*hemu_dump)(void *priv, u8 *hemu_onoff);
developer29344f12022-10-17 12:01:44 +0800158+
159+ /**
160+ * three_wire_ctrl - set three_wire_ctrl mode
161+ * @priv: Private driver interface data
162+ * @three_wire_enable: three_wire_ctrl mode
163+ *
164+ */
developer27b55252022-09-05 19:09:45 +0800165+ int (*three_wire_ctrl)(void *priv, u8 three_wire_enable);
166 };
167
168 /**
169diff --git a/src/drivers/driver_nl80211.c b/src/drivers/driver_nl80211.c
developer2e506112022-11-21 10:53:12 +0800170index ef0ca18..ec7b174 100644
developer27b55252022-09-05 19:09:45 +0800171--- a/src/drivers/driver_nl80211.c
172+++ b/src/drivers/driver_nl80211.c
developer2e506112022-11-21 10:53:12 +0800173@@ -12637,6 +12637,38 @@ static int nl80211_get_edcca(void *priv, const u8 mode, u8 *value)
developer27b55252022-09-05 19:09:45 +0800174 return ret;
175 }
176
177+static int nl80211_enable_three_wire(void *priv, const u8 three_wire_enable)
178+{
179+ struct i802_bss *bss = priv;
180+ struct wpa_driver_nl80211_data *drv = bss->drv;
181+ /* Prepare nl80211 cmd */
182+ struct nl_msg *msg;
183+ struct nlattr *data;
184+ int ret;
185+
186+ if (!drv->mtk_3wire_vendor_cmd_avail) {
187+ wpa_printf(MSG_INFO,
188+ "nl80211: Driver does not support setting three wire control");
189+ return 0;
190+ }
191+
192+ if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_VENDOR)) ||
193+ nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_MTK) ||
194+ nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
195+ MTK_NL80211_VENDOR_SUBCMD_3WIRE_CTRL) ||
196+ !(data = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
197+ nla_put_u8(msg, MTK_VENDOR_ATTR_3WIRE_CTRL_MODE, three_wire_enable)) {
198+ nlmsg_free(msg);
199+ return -ENOBUFS;
200+ }
201+ nla_nest_end(msg, data);
202+ ret = send_and_recv_msgs(drv, msg, NULL, NULL, NULL, NULL);
203+ if (ret) {
204+ wpa_printf(MSG_ERROR, "Failed to enable three wire. ret=%d (%s) ",
205+ ret, strerror(-ret));
206+ }
207+ return ret;
208+}
209
210 const struct wpa_driver_ops wpa_driver_nl80211_ops = {
211 .name = "nl80211",
developer2e506112022-11-21 10:53:12 +0800212@@ -12789,4 +12821,5 @@ const struct wpa_driver_ops wpa_driver_nl80211_ops = {
213 .configure_edcca_enable = nl80211_configure_edcca_enable,
developer27b55252022-09-05 19:09:45 +0800214 .configure_edcca_threshold = nl80211_configure_edcca_threshold,
developer2e506112022-11-21 10:53:12 +0800215 .get_edcca = nl80211_get_edcca,
developer27b55252022-09-05 19:09:45 +0800216+ .three_wire_ctrl = nl80211_enable_three_wire,
217 };
218diff --git a/src/drivers/driver_nl80211.h b/src/drivers/driver_nl80211.h
developer29344f12022-10-17 12:01:44 +0800219index 57f0249..9fe7811 100644
developer27b55252022-09-05 19:09:45 +0800220--- a/src/drivers/driver_nl80211.h
221+++ b/src/drivers/driver_nl80211.h
developer198585d2022-09-22 17:12:54 +0800222@@ -183,6 +183,7 @@ struct wpa_driver_nl80211_data {
223 unsigned int uses_6ghz:1;
developer27b55252022-09-05 19:09:45 +0800224 unsigned int mtk_edcca_vendor_cmd_avail:1;
225 unsigned int mtk_hemu_vendor_cmd_avail:1;
226+ unsigned int mtk_3wire_vendor_cmd_avail:1;
227
228 u64 vendor_scan_cookie;
229 u64 remain_on_chan_cookie;
230diff --git a/src/drivers/driver_nl80211_capa.c b/src/drivers/driver_nl80211_capa.c
developer29344f12022-10-17 12:01:44 +0800231index cc146d9..04bc54e 100644
developer27b55252022-09-05 19:09:45 +0800232--- a/src/drivers/driver_nl80211_capa.c
233+++ b/src/drivers/driver_nl80211_capa.c
developer198585d2022-09-22 17:12:54 +0800234@@ -1059,6 +1059,9 @@ static int wiphy_info_handler(struct nl_msg *msg, void *arg)
developer27b55252022-09-05 19:09:45 +0800235 case MTK_NL80211_VENDOR_SUBCMD_HEMU_CTRL :
236 drv->mtk_hemu_vendor_cmd_avail = 1;
237 break;
238+ case MTK_NL80211_VENDOR_SUBCMD_3WIRE_CTRL :
239+ drv->mtk_3wire_vendor_cmd_avail = 1;
240+ break;
241 }
242 }
243
244--
developer29344f12022-10-17 12:01:44 +08002452.18.0
developer27b55252022-09-05 19:09:45 +0800246