blob: 09ed283a6c3431827528f7f5cc635c38427fcb07 [file] [log] [blame]
developer05f3b2b2024-08-19 19:17:34 +08001From a6e614017f8f6c007fa3ee2cf1543e6460097f10 Mon Sep 17 00:00:00 2001
developer66e89bc2024-04-23 14:50:01 +08002From: StanleyYP Wang <StanleyYP.Wang@mediatek.com>
3Date: Mon, 20 Feb 2023 10:51:47 +0800
developer05f3b2b2024-08-19 19:17:34 +08004Subject: [PATCH 027/126] mtk: hostapd: Add sta-assisted DFS state update
developer66e89bc2024-04-23 14:50:01 +08005 mechanism
6
7Signed-off-by: StanleyYP Wang <StanleyYP.Wang@mediatek.com>
8---
9 src/ap/dfs.c | 20 ++++++++++++++++++++
10 src/ap/dfs.h | 3 +++
11 src/ap/drv_callbacks.c | 28 ++++++++++++++++++++++++++++
12 src/common/wpa_ctrl.h | 1 +
13 src/drivers/driver.h | 14 ++++++++++++++
14 src/drivers/driver_nl80211_event.c | 6 ++++++
15 src/drivers/nl80211_copy.h | 6 ++++++
16 7 files changed, 78 insertions(+)
17
18diff --git a/src/ap/dfs.c b/src/ap/dfs.c
developer05f3b2b2024-08-19 19:17:34 +080019index aaaea0edc..4f8ef8111 100644
developer66e89bc2024-04-23 14:50:01 +080020--- a/src/ap/dfs.c
21+++ b/src/ap/dfs.c
developer05f3b2b2024-08-19 19:17:34 +080022@@ -1535,6 +1535,26 @@ int hostapd_dfs_nop_finished(struct hostapd_iface *iface, int freq,
developer66e89bc2024-04-23 14:50:01 +080023 }
24
25
26+int hostapd_dfs_sta_update_state(struct hostapd_iface *iface, int freq,
27+ int ht_enabled, int chan_offset, int chan_width,
28+ int cf1, int cf2, u32 state)
29+{
30+ wpa_msg(iface->bss[0]->msg_ctx, MSG_INFO, DFS_EVENT_STA_UPDATE
31+ "freq=%d ht_enabled=%d chan_offset=%d chan_width=%d cf1=%d cf2=%d state=%s",
32+ freq, ht_enabled, chan_offset, chan_width, cf1, cf2,
33+ (state == HOSTAPD_CHAN_DFS_AVAILABLE) ? "available" : "usable");
34+
35+ /* Proceed only if DFS is not offloaded to the driver */
36+ if (iface->drv_flags & WPA_DRIVER_FLAGS_DFS_OFFLOAD)
37+ return 0;
38+
39+ set_dfs_state(iface, freq, ht_enabled, chan_offset, chan_width,
40+ cf1, cf2, state);
41+
42+ return 0;
43+}
44+
45+
46 int hostapd_is_dfs_required(struct hostapd_iface *iface)
47 {
48 int n_chans, n_chans1, start_chan_idx, start_chan_idx1, res;
49diff --git a/src/ap/dfs.h b/src/ap/dfs.h
50index c2556d2d9..25ba29ca1 100644
51--- a/src/ap/dfs.h
52+++ b/src/ap/dfs.h
53@@ -30,6 +30,9 @@ int hostapd_dfs_radar_detected(struct hostapd_iface *iface, int freq,
54 int hostapd_dfs_nop_finished(struct hostapd_iface *iface, int freq,
55 int ht_enabled,
56 int chan_offset, int chan_width, int cf1, int cf2);
57+int hostapd_dfs_sta_update_state(struct hostapd_iface *iface, int freq,
58+ int ht_enabled, int chan_offset, int chan_width,
59+ int cf1, int cf2, u32 state);
60 int hostapd_is_dfs_required(struct hostapd_iface *iface);
61 int hostapd_is_dfs_chan_available(struct hostapd_iface *iface);
62 int hostapd_dfs_start_cac(struct hostapd_iface *iface, int freq,
63diff --git a/src/ap/drv_callbacks.c b/src/ap/drv_callbacks.c
developer05f3b2b2024-08-19 19:17:34 +080064index 6e76f697a..1d40943d6 100644
developer66e89bc2024-04-23 14:50:01 +080065--- a/src/ap/drv_callbacks.c
66+++ b/src/ap/drv_callbacks.c
developer05f3b2b2024-08-19 19:17:34 +080067@@ -2270,6 +2270,24 @@ static void hostapd_event_dfs_cac_started(struct hostapd_data *hapd,
developer66e89bc2024-04-23 14:50:01 +080068 radar->cf1, radar->cf2);
69 }
70
71+static void hostapd_event_dfs_sta_cac_skipped(struct hostapd_data *hapd,
72+ struct dfs_event *radar)
73+{
74+ wpa_printf(MSG_DEBUG, "DFS CAC skipped (by STA) on %d MHz", radar->freq);
75+ hostapd_dfs_sta_update_state(hapd->iface, radar->freq, radar->ht_enabled,
76+ radar->chan_offset, radar->chan_width,
77+ radar->cf1, radar->cf2, HOSTAPD_CHAN_DFS_AVAILABLE);
78+}
79+
80+static void hostapd_event_dfs_sta_cac_expired(struct hostapd_data *hapd,
81+ struct dfs_event *radar)
82+{
83+ wpa_printf(MSG_DEBUG, "DFS CAC expired (by STA) on %d MHz", radar->freq);
84+ hostapd_dfs_sta_update_state(hapd->iface, radar->freq, radar->ht_enabled,
85+ radar->chan_offset, radar->chan_width,
86+ radar->cf1, radar->cf2, HOSTAPD_CHAN_DFS_USABLE);
87+}
88+
89 #endif /* NEED_AP_MLME */
90
91
developer05f3b2b2024-08-19 19:17:34 +080092@@ -2687,6 +2705,16 @@ void hostapd_wpa_event(void *ctx, enum wpa_event_type event,
developer66e89bc2024-04-23 14:50:01 +080093 hapd = switch_link_hapd(hapd, data->dfs_event.link_id);
94 hostapd_event_dfs_nop_finished(hapd, &data->dfs_event);
95 break;
96+ case EVENT_DFS_STA_CAC_SKIPPED:
97+ if (!data)
98+ break;
99+ hostapd_event_dfs_sta_cac_skipped(hapd, &data->dfs_event);
100+ break;
101+ case EVENT_DFS_STA_CAC_EXPIRED:
102+ if (!data)
103+ break;
104+ hostapd_event_dfs_sta_cac_expired(hapd, &data->dfs_event);
105+ break;
106 case EVENT_CHANNEL_LIST_CHANGED:
107 /* channel list changed (regulatory?), update channel list */
108 /* TODO: check this. hostapd_get_hw_features() initializes
109diff --git a/src/common/wpa_ctrl.h b/src/common/wpa_ctrl.h
developer05f3b2b2024-08-19 19:17:34 +0800110index d1ce1dd29..4700c5487 100644
developer66e89bc2024-04-23 14:50:01 +0800111--- a/src/common/wpa_ctrl.h
112+++ b/src/common/wpa_ctrl.h
113@@ -383,6 +383,7 @@ extern "C" {
114 #define DFS_EVENT_CAC_COMPLETED "DFS-CAC-COMPLETED "
115 #define DFS_EVENT_NOP_FINISHED "DFS-NOP-FINISHED "
116 #define DFS_EVENT_PRE_CAC_EXPIRED "DFS-PRE-CAC-EXPIRED "
117+#define DFS_EVENT_STA_UPDATE "DFS-STA-UPDATE "
118
119 #define AP_CSA_FINISHED "AP-CSA-FINISHED "
120
121diff --git a/src/drivers/driver.h b/src/drivers/driver.h
developer05f3b2b2024-08-19 19:17:34 +0800122index 348cf9c88..cccc44147 100644
developer66e89bc2024-04-23 14:50:01 +0800123--- a/src/drivers/driver.h
124+++ b/src/drivers/driver.h
developer05f3b2b2024-08-19 19:17:34 +0800125@@ -5926,6 +5926,20 @@ enum wpa_event_type {
developer66e89bc2024-04-23 14:50:01 +0800126 * EVENT_LINK_RECONFIG - Notification that AP links removed
127 */
128 EVENT_LINK_RECONFIG,
129+
130+ /**
131+ * EVENT_DFS_STA_CAC_SKIPPED - Notification that CAC has been skipped
132+ *
133+ * The channel in the notification is now marked as available.
134+ */
135+ EVENT_DFS_STA_CAC_SKIPPED,
136+
137+ /**
138+ * EVENT_DFS_STA_CAC_EXPIRED - Notification that CAC has expired
139+ *
140+ * The channel in the notification is now marked as usable.
141+ */
142+ EVENT_DFS_STA_CAC_EXPIRED,
143 };
144
145
146diff --git a/src/drivers/driver_nl80211_event.c b/src/drivers/driver_nl80211_event.c
developer05f3b2b2024-08-19 19:17:34 +0800147index 1787dbd99..8ba479861 100644
developer66e89bc2024-04-23 14:50:01 +0800148--- a/src/drivers/driver_nl80211_event.c
149+++ b/src/drivers/driver_nl80211_event.c
developer05f3b2b2024-08-19 19:17:34 +0800150@@ -2539,6 +2539,12 @@ static void nl80211_radar_event(struct wpa_driver_nl80211_data *drv,
developer66e89bc2024-04-23 14:50:01 +0800151 case NL80211_RADAR_CAC_STARTED:
152 wpa_supplicant_event(drv->ctx, EVENT_DFS_CAC_STARTED, &data);
153 break;
154+ case NL80211_RADAR_STA_CAC_SKIPPED:
155+ wpa_supplicant_event(drv->ctx, EVENT_DFS_STA_CAC_SKIPPED, &data);
156+ break;
157+ case NL80211_RADAR_STA_CAC_EXPIRED:
158+ wpa_supplicant_event(drv->ctx, EVENT_DFS_STA_CAC_EXPIRED, &data);
159+ break;
160 default:
161 wpa_printf(MSG_DEBUG, "nl80211: Unknown radar event %d "
162 "received", event_type);
163diff --git a/src/drivers/nl80211_copy.h b/src/drivers/nl80211_copy.h
developer05f3b2b2024-08-19 19:17:34 +0800164index f97f5adc8..622fa71fd 100644
developer66e89bc2024-04-23 14:50:01 +0800165--- a/src/drivers/nl80211_copy.h
166+++ b/src/drivers/nl80211_copy.h
developer05f3b2b2024-08-19 19:17:34 +0800167@@ -6843,6 +6843,10 @@ enum nl80211_smps_mode {
developer66e89bc2024-04-23 14:50:01 +0800168 * applicable for ETSI dfs domain where pre-CAC is valid for ever.
169 * @NL80211_RADAR_CAC_STARTED: Channel Availability Check has been started,
170 * should be generated by HW if NL80211_EXT_FEATURE_DFS_OFFLOAD is enabled.
171+ * @NL80211_RADAR_STA_CAC_SKIPPED: STA set the DFS state to available
172+ * when receiving CSA/assoc resp
173+ * @NL80211_RADAR_STA_CAC_EXPIRED: STA set the DFS state to usable
174+ * when STA is disconnected or leaving the channel
175 */
176 enum nl80211_radar_event {
177 NL80211_RADAR_DETECTED,
developer05f3b2b2024-08-19 19:17:34 +0800178@@ -6851,6 +6855,8 @@ enum nl80211_radar_event {
developer66e89bc2024-04-23 14:50:01 +0800179 NL80211_RADAR_NOP_FINISHED,
180 NL80211_RADAR_PRE_CAC_EXPIRED,
181 NL80211_RADAR_CAC_STARTED,
182+ NL80211_RADAR_STA_CAC_SKIPPED,
183+ NL80211_RADAR_STA_CAC_EXPIRED,
184 };
185
186 /**
187--
developer05f3b2b2024-08-19 19:17:34 +08001882.18.0
developer66e89bc2024-04-23 14:50:01 +0800189