blob: 5c5547ab5ac96a4d06ed7c03995344c6a6fdbd64 [file] [log] [blame]
developer05f3b2b2024-08-19 19:17:34 +08001From fe8560c4ccea682bb471816a1e5200ef7f3cde60 Mon Sep 17 00:00:00 2001
developer66e89bc2024-04-23 14:50:01 +08002From: StanleyYP Wang <StanleyYP.Wang@mediatek.com>
3Date: Wed, 2 Aug 2023 19:00:34 +0800
developer05f3b2b2024-08-19 19:17:34 +08004Subject: [PATCH 053/126] mtk: hostapd: add zwdfs mode ctrl for eagle efem
developer66e89bc2024-04-23 14:50:01 +08005
6Signed-off-by: StanleyYP Wang <StanleyYP.Wang@mediatek.com>
7---
8 hostapd/config_file.c | 2 ++
9 hostapd/ctrl_iface.c | 30 +++++++++++++++++++++++++++
10 src/ap/ap_config.h | 6 ++++++
11 src/ap/ap_drv_ops.c | 14 +++++++++++++
12 src/ap/ap_drv_ops.h | 1 +
13 src/ap/dfs.c | 6 ++++++
14 src/common/mtk_vendor.h | 12 +++++++++++
15 src/drivers/driver.h | 7 +++++++
16 src/drivers/driver_nl80211.c | 34 +++++++++++++++++++++++++++++++
17 src/drivers/driver_nl80211.h | 1 +
18 src/drivers/driver_nl80211_capa.c | 3 +++
19 11 files changed, 116 insertions(+)
20
21diff --git a/hostapd/config_file.c b/hostapd/config_file.c
developer05f3b2b2024-08-19 19:17:34 +080022index dc05738db..b941ec5fa 100644
developer66e89bc2024-04-23 14:50:01 +080023--- a/hostapd/config_file.c
24+++ b/hostapd/config_file.c
developer05f3b2b2024-08-19 19:17:34 +080025@@ -3662,6 +3662,8 @@ static int hostapd_config_fill(struct hostapd_config *conf,
developer66e89bc2024-04-23 14:50:01 +080026 conf->acs_exclude_6ghz_non_psc = atoi(pos);
27 } else if (os_strcmp(buf, "enable_background_radar") == 0) {
28 conf->enable_background_radar = atoi(pos);
29+ } else if (os_strcmp(buf, "background_radar_mode") == 0) {
30+ conf->background_radar_mode = atoi(pos);
31 } else if (os_strcmp(buf, "min_tx_power") == 0) {
32 int val = atoi(pos);
33
34diff --git a/hostapd/ctrl_iface.c b/hostapd/ctrl_iface.c
developer05f3b2b2024-08-19 19:17:34 +080035index 53924b265..61d69902d 100644
developer66e89bc2024-04-23 14:50:01 +080036--- a/hostapd/ctrl_iface.c
37+++ b/hostapd/ctrl_iface.c
developer05f3b2b2024-08-19 19:17:34 +080038@@ -4919,6 +4919,33 @@ hostapd_ctrl_iface_dump_amnt(struct hostapd_data *hapd, char *cmd,
developer66e89bc2024-04-23 14:50:01 +080039 return pos - buf;
40 }
41
42+static int
43+hostapd_ctrl_iface_set_background_radar_mode(struct hostapd_data *hapd, char *cmd,
44+ char *buf, size_t buflen)
45+{
46+ struct hostapd_iface *iface = hapd->iface;
47+ char *pos, *param;
48+
49+ param = os_strchr(cmd, ' ');
50+ if (!param)
51+ return -1;
52+ *param++ = '\0';
53+
54+ pos = os_strstr(param, "mode=");
55+ if (!pos)
56+ return -1;
57+
58+ if (os_strncmp(pos + 5, "cert", 4) == 0)
59+ iface->conf->background_radar_mode = BACKGROUND_RADAR_CERT_MODE;
60+ else if (os_strncmp(pos + 5, "normal", 6) == 0)
61+ iface->conf->background_radar_mode = BACKGROUND_RADAR_NORMAL_MODE;
62+
63+ if (hostapd_drv_background_radar_mode(hapd) < 0)
64+ return -1;
65+
66+ return os_snprintf(buf, buflen, "OK\n");
67+}
68+
69 static int hostapd_ctrl_iface_receive_process(struct hostapd_data *hapd,
70 char *buf, char *reply,
71 int reply_size,
developer05f3b2b2024-08-19 19:17:34 +080072@@ -5568,6 +5595,9 @@ static int hostapd_ctrl_iface_receive_process(struct hostapd_data *hapd,
developer66e89bc2024-04-23 14:50:01 +080073 if (pos)
74 *pos = ' ';
75 reply_len = hostapd_ctrl_iface_set_mu(hapd, buf + 23, reply, reply_size);
76+ } else if (os_strncmp(buf, "SET_BACKGROUND_RADAR_MODE", 25) == 0) {
77+ reply_len = hostapd_ctrl_iface_set_background_radar_mode(hapd, buf + 25,
78+ reply, reply_size);
79 } else {
80 os_memcpy(reply, "UNKNOWN COMMAND\n", 16);
81 reply_len = 16;
82diff --git a/src/ap/ap_config.h b/src/ap/ap_config.h
developer05f3b2b2024-08-19 19:17:34 +080083index 0c51d2ab9..cffde344f 100644
developer66e89bc2024-04-23 14:50:01 +080084--- a/src/ap/ap_config.h
85+++ b/src/ap/ap_config.h
developer05f3b2b2024-08-19 19:17:34 +080086@@ -1101,6 +1101,7 @@ struct hostapd_config {
developer66e89bc2024-04-23 14:50:01 +080087 bool hw_mode_set;
88 int acs_exclude_6ghz_non_psc;
89 int enable_background_radar;
90+ int background_radar_mode;
91 enum {
92 LONG_PREAMBLE = 0,
93 SHORT_PREAMBLE = 1
developer05f3b2b2024-08-19 19:17:34 +080094@@ -1359,6 +1360,11 @@ enum three_wire_mode {
developer66e89bc2024-04-23 14:50:01 +080095 NUM_THREE_WIRE_MODE - 1
96 };
97
98+enum background_radar_mode {
99+ BACKGROUND_RADAR_NORMAL_MODE,
100+ BACKGROUND_RADAR_CERT_MODE,
101+};
102+
103 enum dfs_mode {
104 DFS_DETECT_MODE_DISABLE,
105 DFS_DETECT_MODE_AP_ENABLE,
106diff --git a/src/ap/ap_drv_ops.c b/src/ap/ap_drv_ops.c
developer05f3b2b2024-08-19 19:17:34 +0800107index ccd0cb939..6f8f329b0 100644
developer66e89bc2024-04-23 14:50:01 +0800108--- a/src/ap/ap_drv_ops.c
109+++ b/src/ap/ap_drv_ops.c
developer05f3b2b2024-08-19 19:17:34 +0800110@@ -1401,3 +1401,17 @@ int hostapd_drv_amnt_dump(struct hostapd_data *hapd, u8 amnt_idx, u8 *amnt_dump_
developer66e89bc2024-04-23 14:50:01 +0800111 return 0;
112 return hapd->driver->amnt_dump(hapd->drv_priv, amnt_idx, amnt_dump_buf);
113 }
114+
115+int hostapd_drv_background_radar_mode(struct hostapd_data *hapd)
116+{
117+ if (!hapd->driver || !hapd->driver->background_radar_mode ||
118+ !(hapd->iface->drv_flags2 & WPA_DRIVER_FLAGS2_RADAR_BACKGROUND) ||
119+ !hapd->iface->conf->enable_background_radar)
120+ return 0;
121+ if (hapd->iconf->background_radar_mode > BACKGROUND_RADAR_CERT_MODE) {
122+ wpa_printf(MSG_INFO, "Invalid value for background radar mode\n");
123+ return 0;
124+ }
125+ return hapd->driver->background_radar_mode(hapd->drv_priv,
126+ hapd->iconf->background_radar_mode);
127+}
128diff --git a/src/ap/ap_drv_ops.h b/src/ap/ap_drv_ops.h
developer05f3b2b2024-08-19 19:17:34 +0800129index 659154f56..53075ea94 100644
developer66e89bc2024-04-23 14:50:01 +0800130--- a/src/ap/ap_drv_ops.h
131+++ b/src/ap/ap_drv_ops.h
developer05f3b2b2024-08-19 19:17:34 +0800132@@ -171,6 +171,7 @@ int hostapd_drv_ap_trig_type(struct hostapd_data *hapd, u8 enable, u8 type);
developer66e89bc2024-04-23 14:50:01 +0800133
134 int hostapd_drv_amnt_set(struct hostapd_data *hapd, u8 amnt_idx, u8 *amnt_sta_mac);
135 int hostapd_drv_amnt_dump(struct hostapd_data *hapd, u8 amnt_idx, u8 *amnt_dump_buf);
136+int hostapd_drv_background_radar_mode(struct hostapd_data *hapd);
137
138 #include "drivers/driver.h"
139
140diff --git a/src/ap/dfs.c b/src/ap/dfs.c
developer05f3b2b2024-08-19 19:17:34 +0800141index 72bb469a6..db26f6536 100644
developer66e89bc2024-04-23 14:50:01 +0800142--- a/src/ap/dfs.c
143+++ b/src/ap/dfs.c
developer05f3b2b2024-08-19 19:17:34 +0800144@@ -986,6 +986,9 @@ int hostapd_handle_dfs(struct hostapd_iface *iface)
developer66e89bc2024-04-23 14:50:01 +0800145 if (res < 0)
146 return res;
147
148+ if (hostapd_drv_background_radar_mode(iface->bss[0]) < 0)
149+ return -1;
150+
151 iface->radar_background.temp_ch = 1;
152 return 1;
153 } else if (dfs_use_radar_background(iface)) {
developer05f3b2b2024-08-19 19:17:34 +0800154@@ -1026,6 +1029,9 @@ int hostapd_handle_dfs(struct hostapd_iface *iface)
developer66e89bc2024-04-23 14:50:01 +0800155 iface->radar_background.secondary_channel = sec;
156 iface->radar_background.centr_freq_seg0_idx = cf1;
157 iface->radar_background.centr_freq_seg1_idx = cf2;
158+
159+ if (hostapd_drv_background_radar_mode(iface->bss[0]) < 0)
160+ return -1;
161 }
162
163 return 0;
164diff --git a/src/common/mtk_vendor.h b/src/common/mtk_vendor.h
developer05f3b2b2024-08-19 19:17:34 +0800165index f0abcb6b1..3fb4c38f3 100644
developer66e89bc2024-04-23 14:50:01 +0800166--- a/src/common/mtk_vendor.h
167+++ b/src/common/mtk_vendor.h
168@@ -16,6 +16,7 @@ enum mtk_nl80211_vendor_subcmds {
169 MTK_NL80211_VENDOR_SUBCMD_3WIRE_CTRL = 0xc8,
170 MTK_NL80211_VENDOR_SUBCMD_IBF_CTRL = 0xc9,
171 MTK_NL80211_VENDOR_SUBCMD_BSS_COLOR_CTRL = 0xca,
172+ MTK_NL80211_VENDOR_SUBCMD_BACKGROUND_RADAR_CTRL = 0xcb,
173 };
174
175 enum mtk_vendor_attr_edcca_ctrl {
developer05f3b2b2024-08-19 19:17:34 +0800176@@ -247,6 +248,17 @@ enum mtk_vendor_attr_bss_color_ctrl {
developer66e89bc2024-04-23 14:50:01 +0800177 NUM_MTK_VENDOR_ATTRS_BSS_COLOR_CTRL - 1
178 };
179
180+enum mtk_vendor_attr_background_radar_ctrl {
181+ MTK_VENDOR_ATTR_BACKGROUND_RADAR_CTRL_UNSPEC,
182+
183+ MTK_VENDOR_ATTR_BACKGROUND_RADAR_CTRL_MODE,
184+
185+ /* keep last */
186+ NUM_MTK_VENDOR_ATTRS_BACKGROUND_RADAR_CTRL,
187+ MTK_VENDOR_ATTR_BACKGROUND_RADAR_CTRL_MAX =
188+ NUM_MTK_VENDOR_ATTRS_BACKGROUND_RADAR_CTRL - 1
189+};
190+
191 #define CSI_MAX_COUNT 256
192 #define ETH_ALEN 6
193
194diff --git a/src/drivers/driver.h b/src/drivers/driver.h
developer05f3b2b2024-08-19 19:17:34 +0800195index 8457f4703..35c02937d 100644
developer66e89bc2024-04-23 14:50:01 +0800196--- a/src/drivers/driver.h
197+++ b/src/drivers/driver.h
developer05f3b2b2024-08-19 19:17:34 +0800198@@ -5346,6 +5346,13 @@ struct wpa_driver_ops {
developer66e89bc2024-04-23 14:50:01 +0800199 * @amnt_dump_buf: Buffer to print
200 */
201 int (*amnt_dump)(void *priv, u8 amnt_idx, u8 *amnt_dump_buf);
202+
203+ /**
204+ * background_radar_mode - set background radar mode
205+ * @priv: Private driver interface data
206+ * @background_radar_mode: background radar mode
207+ */
208+ int (*background_radar_mode)(void *priv, u8 background_radar_mode);
209 };
210
211 /**
212diff --git a/src/drivers/driver_nl80211.c b/src/drivers/driver_nl80211.c
developer05f3b2b2024-08-19 19:17:34 +0800213index 8a8f8abe8..2d2b47456 100644
developer66e89bc2024-04-23 14:50:01 +0800214--- a/src/drivers/driver_nl80211.c
215+++ b/src/drivers/driver_nl80211.c
developer05f3b2b2024-08-19 19:17:34 +0800216@@ -15080,6 +15080,39 @@ fail:
developer66e89bc2024-04-23 14:50:01 +0800217 return -ENOBUFS;
218 }
219
220+static int nl80211_background_radar_mode(void *priv, const u8 background_radar_mode)
221+{
222+ struct i802_bss *bss = priv;
223+ struct wpa_driver_nl80211_data *drv = bss->drv;
224+ /* Prepare nl80211 cmd */
225+ struct nl_msg *msg;
226+ struct nlattr *data;
227+ int ret;
228+
229+ if (!drv->mtk_background_radar_vendor_cmd_avail) {
230+ wpa_printf(MSG_INFO,
231+ "nl80211: Driver does not support setting background radar mode");
232+ return 0;
233+ }
234+
235+ if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_VENDOR)) ||
236+ nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_MTK) ||
237+ nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
238+ MTK_NL80211_VENDOR_SUBCMD_BACKGROUND_RADAR_CTRL) ||
239+ !(data = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
240+ nla_put_u8(msg, MTK_VENDOR_ATTR_BACKGROUND_RADAR_CTRL_MODE, background_radar_mode)) {
241+ nlmsg_free(msg);
242+ return -ENOBUFS;
243+ }
244+ nla_nest_end(msg, data);
245+ ret = send_and_recv_cmd(drv, msg);
246+ if (ret) {
247+ wpa_printf(MSG_ERROR, "Failed to set background radar mode. ret=%d (%s) ",
248+ ret, strerror(-ret));
249+ }
250+ return ret;
251+}
252+
253 const struct wpa_driver_ops wpa_driver_nl80211_ops = {
254 .name = "nl80211",
255 .desc = "Linux nl80211/cfg80211",
developer05f3b2b2024-08-19 19:17:34 +0800256@@ -15257,4 +15290,5 @@ const struct wpa_driver_ops wpa_driver_nl80211_ops = {
developer66e89bc2024-04-23 14:50:01 +0800257 .ap_trigtype = nl80211_ap_trigtype,
258 .amnt_set = nl80211_amnt_set,
259 .amnt_dump = nl80211_amnt_dump,
260+ .background_radar_mode = nl80211_background_radar_mode,
261 };
262diff --git a/src/drivers/driver_nl80211.h b/src/drivers/driver_nl80211.h
263index adc1b9bf7..e9aae8d14 100644
264--- a/src/drivers/driver_nl80211.h
265+++ b/src/drivers/driver_nl80211.h
266@@ -208,6 +208,7 @@ struct wpa_driver_nl80211_data {
267 unsigned int mtk_bss_color_vendor_cmd_avail:1;
268 unsigned int mtk_rfeatures_vendor_cmd_avail:1;
269 unsigned int mtk_amnt_vendor_cmd_avail:1;
270+ unsigned int mtk_background_radar_vendor_cmd_avail:1;
271
272 u32 ignore_next_local_disconnect;
273 u32 ignore_next_local_deauth;
274diff --git a/src/drivers/driver_nl80211_capa.c b/src/drivers/driver_nl80211_capa.c
developer05f3b2b2024-08-19 19:17:34 +0800275index 4a6ff0f28..fd8c7b0ad 100644
developer66e89bc2024-04-23 14:50:01 +0800276--- a/src/drivers/driver_nl80211_capa.c
277+++ b/src/drivers/driver_nl80211_capa.c
278@@ -1164,6 +1164,9 @@ static int wiphy_info_handler(struct nl_msg *msg, void *arg)
279 case MTK_NL80211_VENDOR_SUBCMD_RFEATURE_CTRL:
280 drv->mtk_rfeatures_vendor_cmd_avail = 1;
281 break;
282+ case MTK_NL80211_VENDOR_SUBCMD_BACKGROUND_RADAR_CTRL:
283+ drv->mtk_background_radar_vendor_cmd_avail = 1;
284+ break;
285 }
286 }
287
288--
developer05f3b2b2024-08-19 19:17:34 +08002892.18.0
developer66e89bc2024-04-23 14:50:01 +0800290