blob: 8c358880b209b2004cbd3223c1e7e678c65bc1d7 [file] [log] [blame]
developer27057f82023-07-10 17:23:13 +08001From c5b6477df27a7da54a56ee0cc94b147072b25749 Mon Sep 17 00:00:00 2001
developer683be522023-05-11 14:24:50 +08002From: StanleyYP Wang <StanleyYP.Wang@mediatek.com>
3Date: Mon, 20 Feb 2023 10:51:47 +0800
developer27057f82023-07-10 17:23:13 +08004Subject: [PATCH 17/32] hostapd: mtk: Add sta-assisted DFS state update
developer683be522023-05-11 14:24:50 +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
developer27057f82023-07-10 17:23:13 +080019index e5ed645d6..d52a60e0d 100644
developer683be522023-05-11 14:24:50 +080020--- a/src/ap/dfs.c
21+++ b/src/ap/dfs.c
22@@ -1508,6 +1508,26 @@ int hostapd_dfs_nop_finished(struct hostapd_iface *iface, int freq,
23 }
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
developer27057f82023-07-10 17:23:13 +080050index c2556d2d9..25ba29ca1 100644
developer683be522023-05-11 14:24:50 +080051--- 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
developer27057f82023-07-10 17:23:13 +080064index b0bba9906..694056b42 100644
developer683be522023-05-11 14:24:50 +080065--- a/src/ap/drv_callbacks.c
66+++ b/src/ap/drv_callbacks.c
developer27057f82023-07-10 17:23:13 +080067@@ -1912,6 +1912,24 @@ static void hostapd_event_dfs_cac_started(struct hostapd_data *hapd,
developer683be522023-05-11 14:24:50 +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
developer27057f82023-07-10 17:23:13 +080092@@ -2190,6 +2208,16 @@ void hostapd_wpa_event(void *ctx, enum wpa_event_type event,
developer683be522023-05-11 14:24:50 +080093 break;
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
developer27057f82023-07-10 17:23:13 +0800110index ccff0ee09..e209ac6d7 100644
developer683be522023-05-11 14:24:50 +0800111--- a/src/common/wpa_ctrl.h
112+++ b/src/common/wpa_ctrl.h
developer27057f82023-07-10 17:23:13 +0800113@@ -374,6 +374,7 @@ extern "C" {
developer683be522023-05-11 14:24:50 +0800114 #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
developer27057f82023-07-10 17:23:13 +0800122index 87a5a9b64..592f506ec 100644
developer683be522023-05-11 14:24:50 +0800123--- a/src/drivers/driver.h
124+++ b/src/drivers/driver.h
developer27057f82023-07-10 17:23:13 +0800125@@ -5760,6 +5760,20 @@ enum wpa_event_type {
126 * EVENT_LINK_RECONFIG - Notification that AP links removed
developer683be522023-05-11 14:24:50 +0800127 */
developer27057f82023-07-10 17:23:13 +0800128 EVENT_LINK_RECONFIG,
developer683be522023-05-11 14:24:50 +0800129+
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
developer27057f82023-07-10 17:23:13 +0800147index 3e8ace052..3d0d9b7bb 100644
developer683be522023-05-11 14:24:50 +0800148--- a/src/drivers/driver_nl80211_event.c
149+++ b/src/drivers/driver_nl80211_event.c
developer27057f82023-07-10 17:23:13 +0800150@@ -2447,6 +2447,12 @@ static void nl80211_radar_event(struct wpa_driver_nl80211_data *drv,
developer683be522023-05-11 14:24:50 +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
developer27057f82023-07-10 17:23:13 +0800164index 82860ae32..225864b94 100644
developer683be522023-05-11 14:24:50 +0800165--- a/src/drivers/nl80211_copy.h
166+++ b/src/drivers/nl80211_copy.h
developer27057f82023-07-10 17:23:13 +0800167@@ -6643,6 +6643,10 @@ enum nl80211_smps_mode {
developer683be522023-05-11 14:24:50 +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,
developer27057f82023-07-10 17:23:13 +0800178@@ -6651,6 +6655,8 @@ enum nl80211_radar_event {
developer683be522023-05-11 14:24:50 +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--
developer27057f82023-07-10 17:23:13 +08001882.39.2
developer683be522023-05-11 14:24:50 +0800189