blob: a3d88377adf9afe2af1944dd314d2293519f715e [file] [log] [blame]
developer27b55252022-09-05 19:09:45 +08001From 1bd8935beffa0d94c34a2ba4f3400c65b8629250 Mon Sep 17 00:00:00 2001
2From: StanleyYP Wang <StanleyYP.Wang@mediatek.com>
3Date: Fri, 2 Sep 2022 01:03:23 +0800
4Subject: [PATCH] Add three wire PTA ctrl hostapd vendor command
5
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 +++++++++++++++
15 src/drivers/driver.h | 1 +
16 src/drivers/driver_nl80211.c | 33 +++++++++++++++++++++++++++++++
17 src/drivers/driver_nl80211.h | 1 +
18 src/drivers/driver_nl80211_capa.c | 3 +++
19 11 files changed, 86 insertions(+)
20
21diff --git a/hostapd/config_file.c b/hostapd/config_file.c
22index 85d58cd..ee5decb 100644
23--- a/hostapd/config_file.c
24+++ b/hostapd/config_file.c
25@@ -4770,6 +4770,10 @@ static int hostapd_config_fill(struct hostapd_config *conf,
26 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
37index 79e215f..34e4fb1 100644
38--- 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
49index 7528430..99edb49 100644
50--- a/src/ap/ap_config.h
51+++ b/src/ap/ap_config.h
52@@ -1153,6 +1153,19 @@ struct hostapd_config {
53 unsigned int ch_switch_eht_config;
54 u8 edcca_enable;
55 s8 edcca_compensation;
56+ 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
73index 5545232..77d5f89 100644
74--- a/src/ap/ap_drv_ops.c
75+++ b/src/ap/ap_drv_ops.c
76@@ -1038,3 +1038,14 @@ int hostapd_drv_hemu_dump(struct hostapd_data *hapd, u8 *hemu_onoff)
77 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
92index 5bcb225..0a8bf0c 100644
93--- a/src/ap/ap_drv_ops.h
94+++ b/src/ap/ap_drv_ops.h
95@@ -141,6 +141,7 @@ int hostapd_drv_dpp_listen(struct hostapd_data *hapd, bool enable);
96 int hostapd_drv_configure_edcca_threshold(struct hostapd_data *hapd);
97 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
104index 0f3691b..32b75dc 100644
105--- a/src/ap/hostapd.c
106+++ b/src/ap/hostapd.c
107@@ -2299,6 +2299,8 @@ dfs_offload:
108 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
117index 5c8f179..99a4d7f 100644
118--- 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 {
128@@ -48,6 +49,21 @@ static struct nla_policy edcca_ctrl_policy[NUM_MTK_VENDOR_ATTRS_EDCCA_CTRL] = {
129 [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
151index 0f12feb..79e80b6 100644
152--- a/src/drivers/driver.h
153+++ b/src/drivers/driver.h
154@@ -4689,6 +4689,7 @@ struct wpa_driver_ops {
155 */
156 int (*hemu_ctrl)(void *priv, u8 hemu_onoff);
157 int (*hemu_dump)(void *priv, u8 *hemu_onoff);
158+ int (*three_wire_ctrl)(void *priv, u8 three_wire_enable);
159 };
160
161 /**
162diff --git a/src/drivers/driver_nl80211.c b/src/drivers/driver_nl80211.c
163index b2c3a2e..02f4b95 100644
164--- a/src/drivers/driver_nl80211.c
165+++ b/src/drivers/driver_nl80211.c
166@@ -12505,6 +12505,38 @@ static int nl80211_configure_edcca_threshold(void *priv,
167 return ret;
168 }
169
170+static int nl80211_enable_three_wire(void *priv, const u8 three_wire_enable)
171+{
172+ struct i802_bss *bss = priv;
173+ struct wpa_driver_nl80211_data *drv = bss->drv;
174+ /* Prepare nl80211 cmd */
175+ struct nl_msg *msg;
176+ struct nlattr *data;
177+ int ret;
178+
179+ if (!drv->mtk_3wire_vendor_cmd_avail) {
180+ wpa_printf(MSG_INFO,
181+ "nl80211: Driver does not support setting three wire control");
182+ return 0;
183+ }
184+
185+ if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_VENDOR)) ||
186+ nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_MTK) ||
187+ nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
188+ MTK_NL80211_VENDOR_SUBCMD_3WIRE_CTRL) ||
189+ !(data = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
190+ nla_put_u8(msg, MTK_VENDOR_ATTR_3WIRE_CTRL_MODE, three_wire_enable)) {
191+ nlmsg_free(msg);
192+ return -ENOBUFS;
193+ }
194+ nla_nest_end(msg, data);
195+ ret = send_and_recv_msgs(drv, msg, NULL, NULL, NULL, NULL);
196+ if (ret) {
197+ wpa_printf(MSG_ERROR, "Failed to enable three wire. ret=%d (%s) ",
198+ ret, strerror(-ret));
199+ }
200+ return ret;
201+}
202
203 const struct wpa_driver_ops wpa_driver_nl80211_ops = {
204 .name = "nl80211",
205@@ -12655,4 +12687,5 @@ const struct wpa_driver_ops wpa_driver_nl80211_ops = {
206 #endif /* CONFIG_TESTING_OPTIONS */
207 /* Need ifdef CONFIG_DRIVER_NL80211_MTK */
208 .configure_edcca_threshold = nl80211_configure_edcca_threshold,
209+ .three_wire_ctrl = nl80211_enable_three_wire,
210 };
211diff --git a/src/drivers/driver_nl80211.h b/src/drivers/driver_nl80211.h
212index 62d9696..196d24f 100644
213--- a/src/drivers/driver_nl80211.h
214+++ b/src/drivers/driver_nl80211.h
215@@ -182,6 +182,7 @@ struct wpa_driver_nl80211_data {
216 unsigned int brcm_do_acs:1;
217 unsigned int mtk_edcca_vendor_cmd_avail:1;
218 unsigned int mtk_hemu_vendor_cmd_avail:1;
219+ unsigned int mtk_3wire_vendor_cmd_avail:1;
220
221 u64 vendor_scan_cookie;
222 u64 remain_on_chan_cookie;
223diff --git a/src/drivers/driver_nl80211_capa.c b/src/drivers/driver_nl80211_capa.c
224index b5cd2c5..f0397f5 100644
225--- a/src/drivers/driver_nl80211_capa.c
226+++ b/src/drivers/driver_nl80211_capa.c
227@@ -1053,6 +1053,9 @@ static int wiphy_info_handler(struct nl_msg *msg, void *arg)
228 case MTK_NL80211_VENDOR_SUBCMD_HEMU_CTRL :
229 drv->mtk_hemu_vendor_cmd_avail = 1;
230 break;
231+ case MTK_NL80211_VENDOR_SUBCMD_3WIRE_CTRL :
232+ drv->mtk_3wire_vendor_cmd_avail = 1;
233+ break;
234 }
235 }
236
237--
2382.18.0
239