blob: c540b5eb047eee1f676ae9059a3089033648dc04 [file] [log] [blame]
From 9d180d46527a6a53824227c2b7c6e4e37bf3acfb Mon Sep 17 00:00:00 2001
From: StanleyYP Wang <StanleyYP.Wang@mediatek.com>
Date: Mon, 20 Feb 2023 14:55:49 +0800
Subject: [PATCH 038/104] mtk: hostapd: Add DFS detection mode
Add DFS detection mode for testing radar detection rate.
If DFS detection mode is on, AP will not switch channels when receiving
a radar signal.
This detection mode also supports background chain.
Signed-off-by: StanleyYP Wang <StanleyYP.Wang@mediatek.com>
---
hostapd/config_file.c | 4 ++++
hostapd/ctrl_iface.c | 23 +++++++++++++++++++++++
src/ap/ap_config.h | 13 +++++++++++++
src/ap/dfs.c | 10 ++++++++++
4 files changed, 50 insertions(+)
diff --git a/hostapd/config_file.c b/hostapd/config_file.c
index 247d68811..40ade89c0 100644
--- a/hostapd/config_file.c
+++ b/hostapd/config_file.c
@@ -5398,6 +5398,10 @@ static int hostapd_config_fill(struct hostapd_config *conf,
} else if (os_strcmp(buf, "ibf_enable") == 0) { /*ibf setting is per device*/
int val = atoi(pos);
conf->ibf_enable = !!val;
+ } else if (os_strcmp(buf, "dfs_detect_mode") == 0) { /*bypass channel switch*/
+ u8 en = strtol(pos, NULL, 10);
+
+ conf->dfs_detect_mode = en;
} else {
wpa_printf(MSG_ERROR,
"Line %d: unknown configuration item '%s'",
diff --git a/hostapd/ctrl_iface.c b/hostapd/ctrl_iface.c
index 10bbce341..71a87459c 100644
--- a/hostapd/ctrl_iface.c
+++ b/hostapd/ctrl_iface.c
@@ -4134,6 +4134,26 @@ hostapd_ctrl_iface_get_ibf(struct hostapd_data *hapd, char *buf,
}
+static int
+hostapd_ctrl_iface_set_dfs_detect_mode(struct hostapd_data *hapd, char *value,
+ char *buf, size_t buflen)
+{
+ u8 dfs_detect_mode;
+
+ if (!value)
+ return -1;
+
+ dfs_detect_mode = strtol(value, NULL, 10);
+ if (dfs_detect_mode > DFS_DETECT_MODE_MAX) {
+ wpa_printf(MSG_ERROR, "Invalid value for dfs detect mode");
+ return -1;
+ }
+ hapd->iconf->dfs_detect_mode = dfs_detect_mode;
+
+ return os_snprintf(buf, buflen, "OK\n");
+}
+
+
static int hostapd_ctrl_iface_receive_process(struct hostapd_data *hapd,
char *buf, char *reply,
int reply_size,
@@ -4747,6 +4767,9 @@ static int hostapd_ctrl_iface_receive_process(struct hostapd_data *hapd,
reply_len = hostapd_ctrl_iface_get_mu(hapd, reply, reply_size);
} else if (os_strncmp(buf, "GET_IBF", 7) == 0) {
reply_len = hostapd_ctrl_iface_get_ibf(hapd, reply, reply_size);
+ } else if (os_strncmp(buf, "DFS_DETECT_MODE ", 16) == 0) {
+ reply_len = hostapd_ctrl_iface_set_dfs_detect_mode(hapd, buf + 16,
+ reply, reply_size);
} else {
os_memcpy(reply, "UNKNOWN COMMAND\n", 16);
reply_len = 16;
diff --git a/src/ap/ap_config.h b/src/ap/ap_config.h
index 5f084796d..7607c63e1 100644
--- a/src/ap/ap_config.h
+++ b/src/ap/ap_config.h
@@ -1288,6 +1288,7 @@ struct hostapd_config {
int *edcca_threshold;
u8 three_wire_enable;
u8 ibf_enable;
+ u8 dfs_detect_mode;
};
enum three_wire_mode {
@@ -1302,6 +1303,18 @@ enum three_wire_mode {
NUM_THREE_WIRE_MODE - 1
};
+enum dfs_mode {
+ DFS_DETECT_MODE_DISABLE,
+ DFS_DETECT_MODE_AP_ENABLE,
+ DFS_DETECT_MODE_BACKGROUND_ENABLE,
+ DFS_DETECT_MODE_ALL_ENABLE,
+
+ /* keep last */
+ NUM_DFS_DETECT_MODE,
+ DFS_DETECT_MODE_MAX =
+ NUM_DFS_DETECT_MODE - 1
+};
+
enum edcca_mode {
EDCCA_MODE_FORCE_DISABLE = 0,
EDCCA_MODE_AUTO = 1,
diff --git a/src/ap/dfs.c b/src/ap/dfs.c
index d14fad136..1df4de6b8 100644
--- a/src/ap/dfs.c
+++ b/src/ap/dfs.c
@@ -1336,6 +1336,11 @@ hostapd_dfs_background_start_channel_switch(struct hostapd_iface *iface,
__func__, iface->radar_background.cac_started ? "yes" : "no",
hostapd_csa_in_progress(iface) ? "yes" : "no");
+ /* Skip channel switch when background dfs detect mode is on */
+ if (iface->conf->dfs_detect_mode == DFS_DETECT_MODE_BACKGROUND_ENABLE ||
+ iface->conf->dfs_detect_mode == DFS_DETECT_MODE_ALL_ENABLE)
+ return 0;
+
/* Check if CSA in progress */
if (hostapd_csa_in_progress(iface))
return 0;
@@ -1384,6 +1389,11 @@ static int hostapd_dfs_start_channel_switch(struct hostapd_iface *iface)
__func__, iface->cac_started ? "yes" : "no",
hostapd_csa_in_progress(iface) ? "yes" : "no");
+ /* Skip channel switch when dfs detect mode is on */
+ if (iface->conf->dfs_detect_mode == DFS_DETECT_MODE_AP_ENABLE ||
+ iface->conf->dfs_detect_mode == DFS_DETECT_MODE_ALL_ENABLE)
+ return 0;
+
/* Check if CSA in progress */
if (hostapd_csa_in_progress(iface))
return 0;
--
2.39.2