blob: 82b66f45ce5a174d575fd1ffabf30898326d221d [file] [log] [blame]
developer1e50cbb2023-11-16 18:52:50 +08001From 018d87d5b9b53b3e630032bf2cb7e6eaeae09d71 Mon Sep 17 00:00:00 2001
2From: StanleyYP Wang <StanleyYP.Wang@mediatek.com>
3Date: Wed, 15 Nov 2023 15:06:00 +0800
4Subject: [PATCH 47/49] hostapd: mtk: add support for channel switching to dfs
5 with csa sent
6
7Signed-off-by: StanleyYP Wang <StanleyYP.Wang@mediatek.com>
8---
9 hostapd/ctrl_iface.c | 26 ++------------------------
10 src/ap/beacon.c | 5 +++++
11 src/ap/dfs.c | 16 ++++++++++++----
12 src/ap/ieee802_11.c | 5 +++++
13 4 files changed, 24 insertions(+), 28 deletions(-)
14
15diff --git a/hostapd/ctrl_iface.c b/hostapd/ctrl_iface.c
16index b521a08..0afa6a2 100644
17--- a/hostapd/ctrl_iface.c
18+++ b/hostapd/ctrl_iface.c
19@@ -2747,7 +2747,6 @@ static int hostapd_ctrl_iface_chan_switch(struct hostapd_iface *iface,
20 int dfs_range = 0;
21 unsigned int i;
22 int bandwidth;
23- u8 chan;
24
25 ret = hostapd_parse_csa_settings(pos, &settings);
26 if (ret)
27@@ -2809,29 +2808,8 @@ static int hostapd_ctrl_iface_chan_switch(struct hostapd_iface *iface,
28 iface, bandwidth, settings.freq_params.center_freq2);
29
30 if (dfs_range) {
31- ret = ieee80211_freq_to_chan(settings.freq_params.freq, &chan);
32- if (ret == NUM_HOSTAPD_MODES) {
33- wpa_printf(MSG_ERROR,
34- "Failed to get channel for (freq=%d, sec_channel_offset=%d, bw=%d)",
35- settings.freq_params.freq,
36- settings.freq_params.sec_channel_offset,
37- settings.freq_params.bandwidth);
38- return -1;
39- }
40-
41- settings.freq_params.channel = chan;
42-
43- wpa_printf(MSG_DEBUG,
44- "DFS/CAC to (channel=%u, freq=%d, sec_channel_offset=%d, bw=%d, center_freq1=%d)",
45- settings.freq_params.channel,
46- settings.freq_params.freq,
47- settings.freq_params.sec_channel_offset,
48- settings.freq_params.bandwidth,
49- settings.freq_params.center_freq1);
50-
51- /* Perform CAC and switch channel */
52- hostapd_switch_channel_fallback(iface, &settings.freq_params);
53- return 0;
54+ settings.cs_count = 5;
55+ settings.block_tx = 1;
56 }
57
58 for (i = 0; i < iface->num_bss; i++) {
59diff --git a/src/ap/beacon.c b/src/ap/beacon.c
60index 02f4f87..f9c4924 100644
61--- a/src/ap/beacon.c
62+++ b/src/ap/beacon.c
63@@ -2027,6 +2027,11 @@ static int __ieee802_11_set_beacon(struct hostapd_data *hapd)
64 return -1;
65 }
66
67+ if (iface->cac_started) {
68+ wpa_printf(MSG_DEBUG, "Ignore set beacons during CAC period");
69+ return 0;
70+ }
71+
72 hapd->beacon_set_done = 1;
73
74 if (ieee802_11_build_ap_params(hapd, &params) < 0)
75diff --git a/src/ap/dfs.c b/src/ap/dfs.c
76index 80d3605..012050c 100644
77--- a/src/ap/dfs.c
78+++ b/src/ap/dfs.c
79@@ -1255,10 +1255,10 @@ int hostapd_dfs_complete_cac(struct hostapd_iface *iface, int success, int freq,
80 * another radio.
81 */
82 if (iface->state != HAPD_IFACE_ENABLED &&
83- hostapd_is_dfs_chan_available(iface)) {
84+ hostapd_is_dfs_chan_available(iface))
85 hostapd_setup_interface_complete(iface, 0);
86- iface->cac_started = 0;
87- }
88+
89+ iface->cac_started = 0;
90
91 /*
92 * When background radar is enabled but the CAC completion
93@@ -1272,6 +1272,13 @@ int hostapd_dfs_complete_cac(struct hostapd_iface *iface, int success, int freq,
94 } else if (hostapd_dfs_is_background_event(iface, freq)) {
95 iface->radar_background.cac_started = 0;
96 hostpad_dfs_update_background_chain(iface);
97+ } else {
98+ int i;
99+
100+ iface->cac_started = 0;
101+ /* Clear all CSA flags once channel switch to DFS channel fails */
102+ for (i = 0; i < iface->num_bss; i++)
103+ iface->bss[i]->csa_in_progress = 0;
104 }
105
106 return 0;
107@@ -1646,7 +1653,8 @@ int hostapd_dfs_start_cac(struct hostapd_iface *iface, int freq,
108 } else {
109 /* This is called when the driver indicates that an offloaded
110 * DFS has started CAC. */
111- hostapd_set_state(iface, HAPD_IFACE_DFS);
112+ if (iface->drv_flags & WPA_DRIVER_FLAGS_DFS_OFFLOAD)
113+ hostapd_set_state(iface, HAPD_IFACE_DFS);
114 iface->cac_started = 1;
115 }
116 /* TODO: How to check CAC time for ETSI weather channels? */
117diff --git a/src/ap/ieee802_11.c b/src/ap/ieee802_11.c
118index 01ceb79..dd477fd 100644
119--- a/src/ap/ieee802_11.c
120+++ b/src/ap/ieee802_11.c
121@@ -6352,6 +6352,11 @@ int ieee802_11_mgmt(struct hostapd_data *hapd, const u8 *buf, size_t len,
122 return 1;
123 }
124
125+ if (hapd->iface->cac_started) {
126+ wpa_printf(MSG_DEBUG, "MGMT: Ignore management frame during CAC");
127+ return 1;
128+ }
129+
130 if (stype == WLAN_FC_STYPE_PROBE_REQ) {
131 handle_probe_req(hapd, mgmt, len, ssi_signal);
132 return 1;
133--
1342.18.0
135