blob: 3c36b27ff56f88405cfb8684d674d9a8e895d85b [file] [log] [blame]
developer1a173672023-12-21 14:49:33 +08001From 7782f39aa86e067030ee8277c7942423c6e64389 Mon Sep 17 00:00:00 2001
developer6ce3b612023-03-02 20:22:29 +08002From: StanleyYP Wang <StanleyYP.Wang@mediatek.com>
3Date: Mon, 20 Feb 2023 10:51:47 +0800
developer1a173672023-12-21 14:49:33 +08004Subject: [PATCH 17/54] mtk: hostapd: Add sta-assisted DFS state update
developer6ce3b612023-03-02 20:22:29 +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
developer1a173672023-12-21 14:49:33 +080019index cfc350879..9d002cfad 100644
developer6ce3b612023-03-02 20:22:29 +080020--- a/src/ap/dfs.c
21+++ b/src/ap/dfs.c
developerbd9fa1e2023-10-16 11:04:00 +080022@@ -1513,6 +1513,26 @@ int hostapd_dfs_nop_finished(struct hostapd_iface *iface, int freq,
developer6ce3b612023-03-02 20:22:29 +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
developer1a173672023-12-21 14:49:33 +080050index c2556d2d9..25ba29ca1 100644
developer6ce3b612023-03-02 20:22:29 +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
developer1a173672023-12-21 14:49:33 +080064index f6093c11c..e7f1f19ce 100644
developer6ce3b612023-03-02 20:22:29 +080065--- a/src/ap/drv_callbacks.c
66+++ b/src/ap/drv_callbacks.c
developerbd9fa1e2023-10-16 11:04:00 +080067@@ -2086,6 +2086,24 @@ static void hostapd_event_dfs_cac_started(struct hostapd_data *hapd,
developer6ce3b612023-03-02 20:22:29 +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
developerbd9fa1e2023-10-16 11:04:00 +080092@@ -2407,6 +2425,16 @@ void hostapd_wpa_event(void *ctx, enum wpa_event_type event,
developer6ce3b612023-03-02 20:22:29 +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
developer1a173672023-12-21 14:49:33 +0800110index 416e0d6a8..62f042e05 100644
developer6ce3b612023-03-02 20:22:29 +0800111--- a/src/common/wpa_ctrl.h
112+++ b/src/common/wpa_ctrl.h
developer9a587882023-07-17 11:11:44 +0800113@@ -374,6 +374,7 @@ extern "C" {
developer6ce3b612023-03-02 20:22:29 +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
developer1a173672023-12-21 14:49:33 +0800122index 577c34c07..24ab656fa 100644
developer6ce3b612023-03-02 20:22:29 +0800123--- a/src/drivers/driver.h
124+++ b/src/drivers/driver.h
developer1a173672023-12-21 14:49:33 +0800125@@ -5785,6 +5785,20 @@ enum wpa_event_type {
developer9a587882023-07-17 11:11:44 +0800126 * EVENT_LINK_RECONFIG - Notification that AP links removed
developer6ce3b612023-03-02 20:22:29 +0800127 */
developer9a587882023-07-17 11:11:44 +0800128 EVENT_LINK_RECONFIG,
developer6ce3b612023-03-02 20:22:29 +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
developer1a173672023-12-21 14:49:33 +0800147index 701c32e7b..63d44017c 100644
developer6ce3b612023-03-02 20:22:29 +0800148--- a/src/drivers/driver_nl80211_event.c
149+++ b/src/drivers/driver_nl80211_event.c
developerbd9fa1e2023-10-16 11:04:00 +0800150@@ -2514,6 +2514,12 @@ static void nl80211_radar_event(struct wpa_driver_nl80211_data *drv,
developer6ce3b612023-03-02 20:22:29 +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
developer1a173672023-12-21 14:49:33 +0800164index 82860ae32..225864b94 100644
developer6ce3b612023-03-02 20:22:29 +0800165--- a/src/drivers/nl80211_copy.h
166+++ b/src/drivers/nl80211_copy.h
developer9a587882023-07-17 11:11:44 +0800167@@ -6643,6 +6643,10 @@ enum nl80211_smps_mode {
developer6ce3b612023-03-02 20:22:29 +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,
developer9a587882023-07-17 11:11:44 +0800178@@ -6651,6 +6655,8 @@ enum nl80211_radar_event {
developer6ce3b612023-03-02 20:22:29 +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--
developerbddc9db2023-09-11 13:34:36 +08001882.18.0
developer6ce3b612023-03-02 20:22:29 +0800189