blob: c2760d984b4ef03f41238f79d01830a39df7a97d [file] [log] [blame]
developer66e89bc2024-04-23 14:50:01 +08001From 5b2e33617bfafa8c6776e80b13c8747f0021a804 Mon Sep 17 00:00:00 2001
2From: StanleyYP Wang <StanleyYP.Wang@mediatek.com>
3Date: Wed, 2 Aug 2023 19:00:34 +0800
4Subject: [PATCH 071/104] mtk: hostapd: add zwdfs mode ctrl for eagle efem
5 hwits
6
7Signed-off-by: StanleyYP Wang <StanleyYP.Wang@mediatek.com>
8---
9 hostapd/config_file.c | 2 ++
10 hostapd/ctrl_iface.c | 30 +++++++++++++++++++++++++++
11 src/ap/ap_config.h | 6 ++++++
12 src/ap/ap_drv_ops.c | 14 +++++++++++++
13 src/ap/ap_drv_ops.h | 1 +
14 src/ap/dfs.c | 6 ++++++
15 src/common/mtk_vendor.h | 12 +++++++++++
16 src/drivers/driver.h | 7 +++++++
17 src/drivers/driver_nl80211.c | 34 +++++++++++++++++++++++++++++++
18 src/drivers/driver_nl80211.h | 1 +
19 src/drivers/driver_nl80211_capa.c | 3 +++
20 11 files changed, 116 insertions(+)
21
22diff --git a/hostapd/config_file.c b/hostapd/config_file.c
23index dadc8f108..9467a1128 100644
24--- a/hostapd/config_file.c
25+++ b/hostapd/config_file.c
26@@ -3576,6 +3576,8 @@ static int hostapd_config_fill(struct hostapd_config *conf,
27 conf->acs_exclude_6ghz_non_psc = atoi(pos);
28 } else if (os_strcmp(buf, "enable_background_radar") == 0) {
29 conf->enable_background_radar = atoi(pos);
30+ } else if (os_strcmp(buf, "background_radar_mode") == 0) {
31+ conf->background_radar_mode = atoi(pos);
32 } else if (os_strcmp(buf, "min_tx_power") == 0) {
33 int val = atoi(pos);
34
35diff --git a/hostapd/ctrl_iface.c b/hostapd/ctrl_iface.c
36index 581acc260..9b072d1b2 100644
37--- a/hostapd/ctrl_iface.c
38+++ b/hostapd/ctrl_iface.c
39@@ -4782,6 +4782,33 @@ hostapd_ctrl_iface_dump_amnt(struct hostapd_data *hapd, char *cmd,
40 return pos - buf;
41 }
42
43+static int
44+hostapd_ctrl_iface_set_background_radar_mode(struct hostapd_data *hapd, char *cmd,
45+ char *buf, size_t buflen)
46+{
47+ struct hostapd_iface *iface = hapd->iface;
48+ char *pos, *param;
49+
50+ param = os_strchr(cmd, ' ');
51+ if (!param)
52+ return -1;
53+ *param++ = '\0';
54+
55+ pos = os_strstr(param, "mode=");
56+ if (!pos)
57+ return -1;
58+
59+ if (os_strncmp(pos + 5, "cert", 4) == 0)
60+ iface->conf->background_radar_mode = BACKGROUND_RADAR_CERT_MODE;
61+ else if (os_strncmp(pos + 5, "normal", 6) == 0)
62+ iface->conf->background_radar_mode = BACKGROUND_RADAR_NORMAL_MODE;
63+
64+ if (hostapd_drv_background_radar_mode(hapd) < 0)
65+ return -1;
66+
67+ return os_snprintf(buf, buflen, "OK\n");
68+}
69+
70 static int hostapd_ctrl_iface_receive_process(struct hostapd_data *hapd,
71 char *buf, char *reply,
72 int reply_size,
73@@ -5423,6 +5450,9 @@ static int hostapd_ctrl_iface_receive_process(struct hostapd_data *hapd,
74 if (pos)
75 *pos = ' ';
76 reply_len = hostapd_ctrl_iface_set_mu(hapd, buf + 23, reply, reply_size);
77+ } else if (os_strncmp(buf, "SET_BACKGROUND_RADAR_MODE", 25) == 0) {
78+ reply_len = hostapd_ctrl_iface_set_background_radar_mode(hapd, buf + 25,
79+ reply, reply_size);
80 } else {
81 os_memcpy(reply, "UNKNOWN COMMAND\n", 16);
82 reply_len = 16;
83diff --git a/src/ap/ap_config.h b/src/ap/ap_config.h
84index 3827a8fc8..0b07be516 100644
85--- a/src/ap/ap_config.h
86+++ b/src/ap/ap_config.h
87@@ -1051,6 +1051,7 @@ struct hostapd_config {
88 bool hw_mode_set;
89 int acs_exclude_6ghz_non_psc;
90 int enable_background_radar;
91+ int background_radar_mode;
92 enum {
93 LONG_PREAMBLE = 0,
94 SHORT_PREAMBLE = 1
95@@ -1306,6 +1307,11 @@ enum three_wire_mode {
96 NUM_THREE_WIRE_MODE - 1
97 };
98
99+enum background_radar_mode {
100+ BACKGROUND_RADAR_NORMAL_MODE,
101+ BACKGROUND_RADAR_CERT_MODE,
102+};
103+
104 enum dfs_mode {
105 DFS_DETECT_MODE_DISABLE,
106 DFS_DETECT_MODE_AP_ENABLE,
107diff --git a/src/ap/ap_drv_ops.c b/src/ap/ap_drv_ops.c
108index 116bc4ceb..2028e70fb 100644
109--- a/src/ap/ap_drv_ops.c
110+++ b/src/ap/ap_drv_ops.c
111@@ -1365,3 +1365,17 @@ int hostapd_drv_amnt_dump(struct hostapd_data *hapd, u8 amnt_idx, u8 *amnt_dump_
112 return 0;
113 return hapd->driver->amnt_dump(hapd->drv_priv, amnt_idx, amnt_dump_buf);
114 }
115+
116+int hostapd_drv_background_radar_mode(struct hostapd_data *hapd)
117+{
118+ if (!hapd->driver || !hapd->driver->background_radar_mode ||
119+ !(hapd->iface->drv_flags2 & WPA_DRIVER_FLAGS2_RADAR_BACKGROUND) ||
120+ !hapd->iface->conf->enable_background_radar)
121+ return 0;
122+ if (hapd->iconf->background_radar_mode > BACKGROUND_RADAR_CERT_MODE) {
123+ wpa_printf(MSG_INFO, "Invalid value for background radar mode\n");
124+ return 0;
125+ }
126+ return hapd->driver->background_radar_mode(hapd->drv_priv,
127+ hapd->iconf->background_radar_mode);
128+}
129diff --git a/src/ap/ap_drv_ops.h b/src/ap/ap_drv_ops.h
130index 84b41881a..f0e618bcc 100644
131--- a/src/ap/ap_drv_ops.h
132+++ b/src/ap/ap_drv_ops.h
133@@ -168,6 +168,7 @@ int hostapd_drv_ap_trig_type(struct hostapd_data *hapd, u8 enable, u8 type);
134
135 int hostapd_drv_amnt_set(struct hostapd_data *hapd, u8 amnt_idx, u8 *amnt_sta_mac);
136 int hostapd_drv_amnt_dump(struct hostapd_data *hapd, u8 amnt_idx, u8 *amnt_dump_buf);
137+int hostapd_drv_background_radar_mode(struct hostapd_data *hapd);
138
139 #include "drivers/driver.h"
140
141diff --git a/src/ap/dfs.c b/src/ap/dfs.c
142index e39f3c180..b12290556 100644
143--- a/src/ap/dfs.c
144+++ b/src/ap/dfs.c
145@@ -985,6 +985,9 @@ int hostapd_handle_dfs(struct hostapd_iface *iface)
146 if (res < 0)
147 return res;
148
149+ if (hostapd_drv_background_radar_mode(iface->bss[0]) < 0)
150+ return -1;
151+
152 iface->radar_background.temp_ch = 1;
153 return 1;
154 } else if (dfs_use_radar_background(iface)) {
155@@ -1025,6 +1028,9 @@ int hostapd_handle_dfs(struct hostapd_iface *iface)
156 iface->radar_background.secondary_channel = sec;
157 iface->radar_background.centr_freq_seg0_idx = cf1;
158 iface->radar_background.centr_freq_seg1_idx = cf2;
159+
160+ if (hostapd_drv_background_radar_mode(iface->bss[0]) < 0)
161+ return -1;
162 }
163
164 return 0;
165diff --git a/src/common/mtk_vendor.h b/src/common/mtk_vendor.h
166index e140de60b..5bc1e0444 100644
167--- a/src/common/mtk_vendor.h
168+++ b/src/common/mtk_vendor.h
169@@ -16,6 +16,7 @@ enum mtk_nl80211_vendor_subcmds {
170 MTK_NL80211_VENDOR_SUBCMD_3WIRE_CTRL = 0xc8,
171 MTK_NL80211_VENDOR_SUBCMD_IBF_CTRL = 0xc9,
172 MTK_NL80211_VENDOR_SUBCMD_BSS_COLOR_CTRL = 0xca,
173+ MTK_NL80211_VENDOR_SUBCMD_BACKGROUND_RADAR_CTRL = 0xcb,
174 };
175
176 enum mtk_vendor_attr_edcca_ctrl {
177@@ -244,6 +245,17 @@ enum mtk_vendor_attr_bss_color_ctrl {
178 NUM_MTK_VENDOR_ATTRS_BSS_COLOR_CTRL - 1
179 };
180
181+enum mtk_vendor_attr_background_radar_ctrl {
182+ MTK_VENDOR_ATTR_BACKGROUND_RADAR_CTRL_UNSPEC,
183+
184+ MTK_VENDOR_ATTR_BACKGROUND_RADAR_CTRL_MODE,
185+
186+ /* keep last */
187+ NUM_MTK_VENDOR_ATTRS_BACKGROUND_RADAR_CTRL,
188+ MTK_VENDOR_ATTR_BACKGROUND_RADAR_CTRL_MAX =
189+ NUM_MTK_VENDOR_ATTRS_BACKGROUND_RADAR_CTRL - 1
190+};
191+
192 #define CSI_MAX_COUNT 256
193 #define ETH_ALEN 6
194
195diff --git a/src/drivers/driver.h b/src/drivers/driver.h
196index 4e3dc9bdb..863748d4f 100644
197--- a/src/drivers/driver.h
198+++ b/src/drivers/driver.h
199@@ -5319,6 +5319,13 @@ struct wpa_driver_ops {
200 * @amnt_dump_buf: Buffer to print
201 */
202 int (*amnt_dump)(void *priv, u8 amnt_idx, u8 *amnt_dump_buf);
203+
204+ /**
205+ * background_radar_mode - set background radar mode
206+ * @priv: Private driver interface data
207+ * @background_radar_mode: background radar mode
208+ */
209+ int (*background_radar_mode)(void *priv, u8 background_radar_mode);
210 };
211
212 /**
213diff --git a/src/drivers/driver_nl80211.c b/src/drivers/driver_nl80211.c
214index aeb755b11..e3f00b6d6 100644
215--- a/src/drivers/driver_nl80211.c
216+++ b/src/drivers/driver_nl80211.c
217@@ -15052,6 +15052,39 @@ fail:
218 return -ENOBUFS;
219 }
220
221+static int nl80211_background_radar_mode(void *priv, const u8 background_radar_mode)
222+{
223+ struct i802_bss *bss = priv;
224+ struct wpa_driver_nl80211_data *drv = bss->drv;
225+ /* Prepare nl80211 cmd */
226+ struct nl_msg *msg;
227+ struct nlattr *data;
228+ int ret;
229+
230+ if (!drv->mtk_background_radar_vendor_cmd_avail) {
231+ wpa_printf(MSG_INFO,
232+ "nl80211: Driver does not support setting background radar mode");
233+ return 0;
234+ }
235+
236+ if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_VENDOR)) ||
237+ nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_MTK) ||
238+ nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
239+ MTK_NL80211_VENDOR_SUBCMD_BACKGROUND_RADAR_CTRL) ||
240+ !(data = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
241+ nla_put_u8(msg, MTK_VENDOR_ATTR_BACKGROUND_RADAR_CTRL_MODE, background_radar_mode)) {
242+ nlmsg_free(msg);
243+ return -ENOBUFS;
244+ }
245+ nla_nest_end(msg, data);
246+ ret = send_and_recv_cmd(drv, msg);
247+ if (ret) {
248+ wpa_printf(MSG_ERROR, "Failed to set background radar mode. ret=%d (%s) ",
249+ ret, strerror(-ret));
250+ }
251+ return ret;
252+}
253+
254 const struct wpa_driver_ops wpa_driver_nl80211_ops = {
255 .name = "nl80211",
256 .desc = "Linux nl80211/cfg80211",
257@@ -15229,4 +15262,5 @@ const struct wpa_driver_ops wpa_driver_nl80211_ops = {
258 .ap_trigtype = nl80211_ap_trigtype,
259 .amnt_set = nl80211_amnt_set,
260 .amnt_dump = nl80211_amnt_dump,
261+ .background_radar_mode = nl80211_background_radar_mode,
262 };
263diff --git a/src/drivers/driver_nl80211.h b/src/drivers/driver_nl80211.h
264index adc1b9bf7..e9aae8d14 100644
265--- a/src/drivers/driver_nl80211.h
266+++ b/src/drivers/driver_nl80211.h
267@@ -208,6 +208,7 @@ struct wpa_driver_nl80211_data {
268 unsigned int mtk_bss_color_vendor_cmd_avail:1;
269 unsigned int mtk_rfeatures_vendor_cmd_avail:1;
270 unsigned int mtk_amnt_vendor_cmd_avail:1;
271+ unsigned int mtk_background_radar_vendor_cmd_avail:1;
272
273 u32 ignore_next_local_disconnect;
274 u32 ignore_next_local_deauth;
275diff --git a/src/drivers/driver_nl80211_capa.c b/src/drivers/driver_nl80211_capa.c
276index 38e83e42b..9bc98aae7 100644
277--- a/src/drivers/driver_nl80211_capa.c
278+++ b/src/drivers/driver_nl80211_capa.c
279@@ -1164,6 +1164,9 @@ static int wiphy_info_handler(struct nl_msg *msg, void *arg)
280 case MTK_NL80211_VENDOR_SUBCMD_RFEATURE_CTRL:
281 drv->mtk_rfeatures_vendor_cmd_avail = 1;
282 break;
283+ case MTK_NL80211_VENDOR_SUBCMD_BACKGROUND_RADAR_CTRL:
284+ drv->mtk_background_radar_vendor_cmd_avail = 1;
285+ break;
286 }
287 }
288
289--
2902.39.2
291