blob: 623e3fc84b0397dca917a4f306930be5d11b2722 [file] [log] [blame]
developerd243af02023-12-21 14:49:33 +08001From e878e546ee5d1e86f174b2713b7a46fb05b6a7b9 Mon Sep 17 00:00:00 2001
developere35b8e42023-10-16 11:04:00 +08002From: StanleyYP Wang <StanleyYP.Wang@mediatek.com>
3Date: Wed, 2 Aug 2023 19:00:34 +0800
developerd243af02023-12-21 14:49:33 +08004Subject: [PATCH 49/54] mtk: hostapd: add zwdfs mode ctrl for eagle efem hwits
developere35b8e42023-10-16 11:04:00 +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/dfs.c | 6 ++++++
13 src/common/mtk_vendor.h | 12 +++++++++++
14 src/drivers/driver.h | 7 +++++++
15 src/drivers/driver_nl80211.c | 34 +++++++++++++++++++++++++++++++
16 src/drivers/driver_nl80211.h | 1 +
17 src/drivers/driver_nl80211_capa.c | 3 +++
18 10 files changed, 115 insertions(+)
19
20diff --git a/hostapd/config_file.c b/hostapd/config_file.c
developerd243af02023-12-21 14:49:33 +080021index 9e3dbb24a..a75199345 100644
developere35b8e42023-10-16 11:04:00 +080022--- a/hostapd/config_file.c
23+++ b/hostapd/config_file.c
24@@ -3183,6 +3183,8 @@ static int hostapd_config_fill(struct hostapd_config *conf,
25 conf->acs_exclude_6ghz_non_psc = atoi(pos);
26 } else if (os_strcmp(buf, "enable_background_radar") == 0) {
27 conf->enable_background_radar = atoi(pos);
28+ } else if (os_strcmp(buf, "background_radar_mode") == 0) {
29+ conf->background_radar_mode = atoi(pos);
30 } else if (os_strcmp(buf, "min_tx_power") == 0) {
31 int val = atoi(pos);
32
33diff --git a/hostapd/ctrl_iface.c b/hostapd/ctrl_iface.c
developerd243af02023-12-21 14:49:33 +080034index aba22e1e6..f7c7a09f3 100644
developere35b8e42023-10-16 11:04:00 +080035--- a/hostapd/ctrl_iface.c
36+++ b/hostapd/ctrl_iface.c
developerd243af02023-12-21 14:49:33 +080037@@ -4221,6 +4221,33 @@ hostapd_ctrl_iface_dump_amnt(struct hostapd_data *hapd, char *cmd,
developere35b8e42023-10-16 11:04:00 +080038 return pos - buf;
39 }
40
41+static int
42+hostapd_ctrl_iface_set_background_radar_mode(struct hostapd_data *hapd, char *cmd,
43+ char *buf, size_t buflen)
44+{
45+ struct hostapd_iface *iface = hapd->iface;
46+ char *pos, *param;
47+
48+ param = os_strchr(cmd, ' ');
49+ if (!param)
50+ return -1;
51+ *param++ = '\0';
52+
53+ pos = os_strstr(param, "mode=");
54+ if (!pos)
55+ return -1;
56+
57+ if (os_strncmp(pos + 5, "cert", 4) == 0)
58+ iface->conf->background_radar_mode = BACKGROUND_RADAR_CERT_MODE;
59+ else if (os_strncmp(pos + 5, "normal", 6) == 0)
60+ iface->conf->background_radar_mode = BACKGROUND_RADAR_NORMAL_MODE;
61+
62+ if (hostapd_drv_background_radar_mode(hapd) < 0)
63+ return -1;
64+
65+ return os_snprintf(buf, buflen, "OK\n");
66+}
67+
68 static int hostapd_ctrl_iface_receive_process(struct hostapd_data *hapd,
69 char *buf, char *reply,
70 int reply_size,
developerd243af02023-12-21 14:49:33 +080071@@ -4815,6 +4842,9 @@ static int hostapd_ctrl_iface_receive_process(struct hostapd_data *hapd,
developere35b8e42023-10-16 11:04:00 +080072 if (pos)
73 *pos = ' ';
74 reply_len = hostapd_ctrl_iface_set_mu(hapd, buf + 23, reply, reply_size);
75+ } else if (os_strncmp(buf, "SET_BACKGROUND_RADAR_MODE", 25) == 0) {
76+ reply_len = hostapd_ctrl_iface_set_background_radar_mode(hapd, buf + 25,
77+ reply, reply_size);
78 } else {
79 os_memcpy(reply, "UNKNOWN COMMAND\n", 16);
80 reply_len = 16;
81diff --git a/src/ap/ap_config.h b/src/ap/ap_config.h
developerd243af02023-12-21 14:49:33 +080082index 7c0d12a3b..b6f05e7af 100644
developere35b8e42023-10-16 11:04:00 +080083--- a/src/ap/ap_config.h
84+++ b/src/ap/ap_config.h
85@@ -1025,6 +1025,7 @@ struct hostapd_config {
86 bool hw_mode_set;
87 int acs_exclude_6ghz_non_psc;
88 int enable_background_radar;
89+ int background_radar_mode;
90 enum {
91 LONG_PREAMBLE = 0,
92 SHORT_PREAMBLE = 1
93@@ -1218,6 +1219,11 @@ enum three_wire_mode {
94 NUM_THREE_WIRE_MODE - 1
95 };
96
97+enum background_radar_mode {
98+ BACKGROUND_RADAR_NORMAL_MODE,
99+ BACKGROUND_RADAR_CERT_MODE,
100+};
101+
102 enum dfs_mode {
103 DFS_DETECT_MODE_DISABLE,
104 DFS_DETECT_MODE_AP_ENABLE,
105diff --git a/src/ap/ap_drv_ops.c b/src/ap/ap_drv_ops.c
developerd243af02023-12-21 14:49:33 +0800106index 721bfa053..5b93ea647 100644
developere35b8e42023-10-16 11:04:00 +0800107--- a/src/ap/ap_drv_ops.c
108+++ b/src/ap/ap_drv_ops.c
109@@ -1257,3 +1257,17 @@ int hostapd_drv_amnt_dump(struct hostapd_data *hapd, u8 amnt_idx, u8 *amnt_dump_
110 return 0;
111 return hapd->driver->amnt_dump(hapd->drv_priv, amnt_idx, amnt_dump_buf);
112 }
113+
114+int hostapd_drv_background_radar_mode(struct hostapd_data *hapd)
115+{
116+ if (!hapd->driver || !hapd->driver->background_radar_mode ||
117+ !(hapd->iface->drv_flags2 & WPA_DRIVER_RADAR_BACKGROUND) ||
118+ !hapd->iface->conf->enable_background_radar)
119+ return 0;
120+ if (hapd->iconf->background_radar_mode > BACKGROUND_RADAR_CERT_MODE) {
121+ wpa_printf(MSG_INFO, "Invalid value for background radar mode\n");
122+ return 0;
123+ }
124+ return hapd->driver->background_radar_mode(hapd->drv_priv,
125+ hapd->iconf->background_radar_mode);
126+}
127diff --git a/src/ap/dfs.c b/src/ap/dfs.c
developerd243af02023-12-21 14:49:33 +0800128index 008596bb2..2564168bb 100644
developere35b8e42023-10-16 11:04:00 +0800129--- a/src/ap/dfs.c
130+++ b/src/ap/dfs.c
131@@ -983,6 +983,9 @@ int hostapd_handle_dfs(struct hostapd_iface *iface)
132 if (res < 0)
133 return res;
134
135+ if (hostapd_drv_background_radar_mode(iface->bss[0]) < 0)
136+ return -1;
137+
138 iface->radar_background.temp_ch = 1;
139 return 1;
140 } else if (dfs_use_radar_background(iface)) {
141@@ -1023,6 +1026,9 @@ int hostapd_handle_dfs(struct hostapd_iface *iface)
142 iface->radar_background.secondary_channel = sec;
143 iface->radar_background.centr_freq_seg0_idx = cf1;
144 iface->radar_background.centr_freq_seg1_idx = cf2;
145+
146+ if (hostapd_drv_background_radar_mode(iface->bss[0]) < 0)
147+ return -1;
148 }
149
150 return 0;
151diff --git a/src/common/mtk_vendor.h b/src/common/mtk_vendor.h
developerd243af02023-12-21 14:49:33 +0800152index e140de60b..5bc1e0444 100644
developere35b8e42023-10-16 11:04:00 +0800153--- a/src/common/mtk_vendor.h
154+++ b/src/common/mtk_vendor.h
155@@ -16,6 +16,7 @@ enum mtk_nl80211_vendor_subcmds {
156 MTK_NL80211_VENDOR_SUBCMD_3WIRE_CTRL = 0xc8,
157 MTK_NL80211_VENDOR_SUBCMD_IBF_CTRL = 0xc9,
158 MTK_NL80211_VENDOR_SUBCMD_BSS_COLOR_CTRL = 0xca,
159+ MTK_NL80211_VENDOR_SUBCMD_BACKGROUND_RADAR_CTRL = 0xcb,
160 };
161
162 enum mtk_vendor_attr_edcca_ctrl {
163@@ -244,6 +245,17 @@ enum mtk_vendor_attr_bss_color_ctrl {
164 NUM_MTK_VENDOR_ATTRS_BSS_COLOR_CTRL - 1
165 };
166
167+enum mtk_vendor_attr_background_radar_ctrl {
168+ MTK_VENDOR_ATTR_BACKGROUND_RADAR_CTRL_UNSPEC,
169+
170+ MTK_VENDOR_ATTR_BACKGROUND_RADAR_CTRL_MODE,
171+
172+ /* keep last */
173+ NUM_MTK_VENDOR_ATTRS_BACKGROUND_RADAR_CTRL,
174+ MTK_VENDOR_ATTR_BACKGROUND_RADAR_CTRL_MAX =
175+ NUM_MTK_VENDOR_ATTRS_BACKGROUND_RADAR_CTRL - 1
176+};
177+
178 #define CSI_MAX_COUNT 256
179 #define ETH_ALEN 6
180
181diff --git a/src/drivers/driver.h b/src/drivers/driver.h
developerd243af02023-12-21 14:49:33 +0800182index b0a6e3514..0c1b2e452 100644
developere35b8e42023-10-16 11:04:00 +0800183--- a/src/drivers/driver.h
184+++ b/src/drivers/driver.h
developerd243af02023-12-21 14:49:33 +0800185@@ -5204,6 +5204,13 @@ struct wpa_driver_ops {
developere35b8e42023-10-16 11:04:00 +0800186 * @amnt_dump_buf: Buffer to print
187 */
188 int (*amnt_dump)(void *priv, u8 amnt_idx, u8 *amnt_dump_buf);
189+
190+ /**
191+ * background_radar_mode - set background radar mode
192+ * @priv: Private driver interface data
193+ * @background_radar_mode: background radar mode
194+ */
195+ int (*background_radar_mode)(void *priv, u8 background_radar_mode);
196 };
197
198 /**
199diff --git a/src/drivers/driver_nl80211.c b/src/drivers/driver_nl80211.c
developerd243af02023-12-21 14:49:33 +0800200index b3897e61d..3cbf8610a 100644
developere35b8e42023-10-16 11:04:00 +0800201--- a/src/drivers/driver_nl80211.c
202+++ b/src/drivers/driver_nl80211.c
developerd243af02023-12-21 14:49:33 +0800203@@ -14743,6 +14743,39 @@ fail:
developere35b8e42023-10-16 11:04:00 +0800204 return -ENOBUFS;
205 }
206
207+static int nl80211_background_radar_mode(void *priv, const u8 background_radar_mode)
208+{
209+ struct i802_bss *bss = priv;
210+ struct wpa_driver_nl80211_data *drv = bss->drv;
211+ /* Prepare nl80211 cmd */
212+ struct nl_msg *msg;
213+ struct nlattr *data;
214+ int ret;
215+
216+ if (!drv->mtk_background_radar_vendor_cmd_avail) {
217+ wpa_printf(MSG_INFO,
218+ "nl80211: Driver does not support setting background radar mode");
219+ return 0;
220+ }
221+
222+ if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_VENDOR)) ||
223+ nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_MTK) ||
224+ nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
225+ MTK_NL80211_VENDOR_SUBCMD_BACKGROUND_RADAR_CTRL) ||
226+ !(data = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
227+ nla_put_u8(msg, MTK_VENDOR_ATTR_BACKGROUND_RADAR_CTRL_MODE, background_radar_mode)) {
228+ nlmsg_free(msg);
229+ return -ENOBUFS;
230+ }
231+ nla_nest_end(msg, data);
232+ ret = send_and_recv_msgs(drv, msg, NULL, NULL, NULL, NULL);
233+ if (ret) {
234+ wpa_printf(MSG_ERROR, "Failed to set background radar mode. ret=%d (%s) ",
235+ ret, strerror(-ret));
236+ }
237+ return ret;
238+}
239+
240 const struct wpa_driver_ops wpa_driver_nl80211_ops = {
241 .name = "nl80211",
242 .desc = "Linux nl80211/cfg80211",
developerd243af02023-12-21 14:49:33 +0800243@@ -14915,4 +14948,5 @@ const struct wpa_driver_ops wpa_driver_nl80211_ops = {
developere35b8e42023-10-16 11:04:00 +0800244 .ap_trigtype = nl80211_ap_trigtype,
245 .amnt_set = nl80211_amnt_set,
246 .amnt_dump = nl80211_amnt_dump,
247+ .background_radar_mode = nl80211_background_radar_mode,
248 };
249diff --git a/src/drivers/driver_nl80211.h b/src/drivers/driver_nl80211.h
developerd243af02023-12-21 14:49:33 +0800250index 0d85adfee..74ee9b191 100644
developere35b8e42023-10-16 11:04:00 +0800251--- a/src/drivers/driver_nl80211.h
252+++ b/src/drivers/driver_nl80211.h
253@@ -210,6 +210,7 @@ struct wpa_driver_nl80211_data {
254 unsigned int mtk_bss_color_vendor_cmd_avail:1;
255 unsigned int mtk_rfeatures_vendor_cmd_avail:1;
256 unsigned int mtk_amnt_vendor_cmd_avail:1;
257+ unsigned int mtk_background_radar_vendor_cmd_avail:1;
258
259 u64 vendor_scan_cookie;
260 u64 remain_on_chan_cookie;
261diff --git a/src/drivers/driver_nl80211_capa.c b/src/drivers/driver_nl80211_capa.c
developerd243af02023-12-21 14:49:33 +0800262index 4bd15f348..74c3e0d86 100644
developere35b8e42023-10-16 11:04:00 +0800263--- a/src/drivers/driver_nl80211_capa.c
264+++ b/src/drivers/driver_nl80211_capa.c
developerd243af02023-12-21 14:49:33 +0800265@@ -1137,6 +1137,9 @@ static int wiphy_info_handler(struct nl_msg *msg, void *arg)
developere35b8e42023-10-16 11:04:00 +0800266 case MTK_NL80211_VENDOR_SUBCMD_RFEATURE_CTRL:
267 drv->mtk_rfeatures_vendor_cmd_avail = 1;
268 break;
269+ case MTK_NL80211_VENDOR_SUBCMD_BACKGROUND_RADAR_CTRL:
270+ drv->mtk_background_radar_vendor_cmd_avail = 1;
271+ break;
272 }
273 }
274
275--
2762.18.0
277