hostapd: add support for turning on 802.11k/v features via ubus
[openwrt/openwrt.git] / package / network / services / hostapd / patches / 600-ubus_support.patch
1 --- a/hostapd/Makefile
2 +++ b/hostapd/Makefile
3 @@ -165,6 +165,11 @@ OBJS += ../src/common/hw_features_common
4
5 OBJS += ../src/eapol_auth/eapol_auth_sm.o
6
7 +ifdef CONFIG_UBUS
8 +CFLAGS += -DUBUS_SUPPORT
9 +OBJS += ../src/ap/ubus.o
10 +LIBS += -lubox -lubus
11 +endif
12
13 ifdef CONFIG_CODE_COVERAGE
14 CFLAGS += -O0 -fprofile-arcs -ftest-coverage
15 --- a/src/ap/hostapd.h
16 +++ b/src/ap/hostapd.h
17 @@ -13,6 +13,7 @@
18 #include "utils/list.h"
19 #include "ap_config.h"
20 #include "drivers/driver.h"
21 +#include "ubus.h"
22
23 struct wpa_ctrl_dst;
24 struct radius_server_data;
25 @@ -122,6 +123,7 @@ struct hostapd_data {
26 struct hostapd_iface *iface;
27 struct hostapd_config *iconf;
28 struct hostapd_bss_config *conf;
29 + struct hostapd_ubus_bss ubus;
30 int interface_added; /* virtual interface added for this BSS */
31 unsigned int started:1;
32 unsigned int disabled:1;
33 @@ -370,6 +372,8 @@ struct hostapd_iface {
34 struct hostapd_config *conf;
35 char phy[16]; /* Name of the PHY (radio) */
36
37 + struct hostapd_ubus_iface ubus;
38 +
39 enum hostapd_iface_state {
40 HAPD_IFACE_UNINITIALIZED,
41 HAPD_IFACE_DISABLED,
42 @@ -518,6 +522,7 @@ hostapd_alloc_bss_data(struct hostapd_if
43 struct hostapd_bss_config *bss);
44 int hostapd_setup_interface(struct hostapd_iface *iface);
45 int hostapd_setup_interface_complete(struct hostapd_iface *iface, int err);
46 +void hostapd_set_own_neighbor_report(struct hostapd_data *hapd);
47 void hostapd_interface_deinit(struct hostapd_iface *iface);
48 void hostapd_interface_free(struct hostapd_iface *iface);
49 struct hostapd_iface * hostapd_alloc_iface(void);
50 --- a/src/ap/hostapd.c
51 +++ b/src/ap/hostapd.c
52 @@ -309,6 +309,7 @@ static void hostapd_free_hapd_data(struc
53 hapd->started = 0;
54
55 wpa_printf(MSG_DEBUG, "%s(%s)", __func__, hapd->conf->iface);
56 + hostapd_ubus_free_bss(hapd);
57 iapp_deinit(hapd->iapp);
58 hapd->iapp = NULL;
59 accounting_deinit(hapd);
60 @@ -1186,6 +1187,8 @@ static int hostapd_setup_bss(struct host
61 if (hapd->driver && hapd->driver->set_operstate)
62 hapd->driver->set_operstate(hapd->drv_priv, 1);
63
64 + hostapd_ubus_add_bss(hapd);
65 +
66 return 0;
67 }
68
69 @@ -1600,7 +1603,7 @@ static enum nr_chan_width hostapd_get_nr
70 #endif /* NEED_AP_MLME */
71
72
73 -static void hostapd_set_own_neighbor_report(struct hostapd_data *hapd)
74 +void hostapd_set_own_neighbor_report(struct hostapd_data *hapd)
75 {
76 #ifdef NEED_AP_MLME
77 u16 capab = hostapd_own_capab_info(hapd);
78 @@ -1711,6 +1714,7 @@ static int hostapd_setup_interface_compl
79 if (err)
80 goto fail;
81
82 + hostapd_ubus_add_iface(iface);
83 wpa_printf(MSG_DEBUG, "Completing interface initialization");
84 if (iface->conf->channel) {
85 #ifdef NEED_AP_MLME
86 @@ -1890,6 +1894,7 @@ dfs_offload:
87
88 fail:
89 wpa_printf(MSG_ERROR, "Interface initialization failed");
90 + hostapd_ubus_free_iface(iface);
91 hostapd_set_state(iface, HAPD_IFACE_DISABLED);
92 wpa_msg(hapd->msg_ctx, MSG_INFO, AP_EVENT_DISABLED);
93 #ifdef CONFIG_FST
94 @@ -2344,6 +2349,7 @@ void hostapd_interface_deinit_free(struc
95 (unsigned int) iface->conf->num_bss);
96 driver = iface->bss[0]->driver;
97 drv_priv = iface->bss[0]->drv_priv;
98 + hostapd_ubus_free_iface(iface);
99 hostapd_interface_deinit(iface);
100 wpa_printf(MSG_DEBUG, "%s: driver=%p drv_priv=%p -> hapd_deinit",
101 __func__, driver, drv_priv);
102 --- a/src/ap/ieee802_11.c
103 +++ b/src/ap/ieee802_11.c
104 @@ -1587,7 +1587,8 @@ ieee802_11_set_radius_info(struct hostap
105
106
107 static void handle_auth(struct hostapd_data *hapd,
108 - const struct ieee80211_mgmt *mgmt, size_t len)
109 + const struct ieee80211_mgmt *mgmt, size_t len,
110 + struct hostapd_frame_info *fi)
111 {
112 u16 auth_alg, auth_transaction, status_code;
113 u16 resp = WLAN_STATUS_SUCCESS;
114 @@ -1603,6 +1604,11 @@ static void handle_auth(struct hostapd_d
115 char *identity = NULL;
116 char *radius_cui = NULL;
117 u16 seq_ctrl;
118 + struct hostapd_ubus_request req = {
119 + .type = HOSTAPD_UBUS_AUTH_REQ,
120 + .mgmt_frame = mgmt,
121 + .frame_info = fi,
122 + };
123
124 if (len < IEEE80211_HDRLEN + sizeof(mgmt->u.auth)) {
125 wpa_printf(MSG_INFO, "handle_auth - too short payload (len=%lu)",
126 @@ -1757,6 +1763,12 @@ static void handle_auth(struct hostapd_d
127 resp = WLAN_STATUS_UNSPECIFIED_FAILURE;
128 goto fail;
129 }
130 + if (hostapd_ubus_handle_event(hapd, &req)) {
131 + wpa_printf(MSG_DEBUG, "Station " MACSTR " rejected by ubus handler.\n",
132 + MAC2STR(mgmt->sa));
133 + resp = WLAN_STATUS_UNSPECIFIED_FAILURE;
134 + goto fail;
135 + }
136 if (res == HOSTAPD_ACL_PENDING)
137 return;
138
139 @@ -2870,7 +2882,7 @@ void fils_hlp_timeout(void *eloop_ctx, v
140
141 static void handle_assoc(struct hostapd_data *hapd,
142 const struct ieee80211_mgmt *mgmt, size_t len,
143 - int reassoc)
144 + int reassoc, struct hostapd_frame_info *fi)
145 {
146 u16 capab_info, listen_interval, seq_ctrl, fc;
147 u16 resp = WLAN_STATUS_SUCCESS, reply_res;
148 @@ -2884,6 +2896,11 @@ static void handle_assoc(struct hostapd_
149 #ifdef CONFIG_FILS
150 int delay_assoc = 0;
151 #endif /* CONFIG_FILS */
152 + struct hostapd_ubus_request req = {
153 + .type = HOSTAPD_UBUS_ASSOC_REQ,
154 + .mgmt_frame = mgmt,
155 + .frame_info = fi,
156 + };
157
158 if (len < IEEE80211_HDRLEN + (reassoc ? sizeof(mgmt->u.reassoc_req) :
159 sizeof(mgmt->u.assoc_req))) {
160 @@ -3051,6 +3068,13 @@ static void handle_assoc(struct hostapd_
161 }
162 #endif /* CONFIG_MBO */
163
164 + if (hostapd_ubus_handle_event(hapd, &req)) {
165 + wpa_printf(MSG_DEBUG, "Station " MACSTR " assoc rejected by ubus handler.\n",
166 + MAC2STR(mgmt->sa));
167 + resp = WLAN_STATUS_UNSPECIFIED_FAILURE;
168 + goto fail;
169 + }
170 +
171 /*
172 * sta->capability is used in check_assoc_ies() for RRM enabled
173 * capability element.
174 @@ -3258,6 +3282,7 @@ static void handle_disassoc(struct hosta
175 wpa_printf(MSG_DEBUG, "disassocation: STA=" MACSTR " reason_code=%d",
176 MAC2STR(mgmt->sa),
177 le_to_host16(mgmt->u.disassoc.reason_code));
178 + hostapd_ubus_notify(hapd, "disassoc", mgmt->sa);
179
180 sta = ap_get_sta(hapd, mgmt->sa);
181 if (sta == NULL) {
182 @@ -3323,6 +3348,8 @@ static void handle_deauth(struct hostapd
183 " reason_code=%d",
184 MAC2STR(mgmt->sa), le_to_host16(mgmt->u.deauth.reason_code));
185
186 + hostapd_ubus_notify(hapd, "deauth", mgmt->sa);
187 +
188 sta = ap_get_sta(hapd, mgmt->sa);
189 if (sta == NULL) {
190 wpa_msg(hapd->msg_ctx, MSG_DEBUG, "Station " MACSTR " trying "
191 @@ -3637,7 +3664,7 @@ int ieee802_11_mgmt(struct hostapd_data
192
193
194 if (stype == WLAN_FC_STYPE_PROBE_REQ) {
195 - handle_probe_req(hapd, mgmt, len, fi->ssi_signal);
196 + handle_probe_req(hapd, mgmt, len, fi);
197 return 1;
198 }
199
200 @@ -3657,17 +3684,17 @@ int ieee802_11_mgmt(struct hostapd_data
201 switch (stype) {
202 case WLAN_FC_STYPE_AUTH:
203 wpa_printf(MSG_DEBUG, "mgmt::auth");
204 - handle_auth(hapd, mgmt, len);
205 + handle_auth(hapd, mgmt, len, fi);
206 ret = 1;
207 break;
208 case WLAN_FC_STYPE_ASSOC_REQ:
209 wpa_printf(MSG_DEBUG, "mgmt::assoc_req");
210 - handle_assoc(hapd, mgmt, len, 0);
211 + handle_assoc(hapd, mgmt, len, 0, fi);
212 ret = 1;
213 break;
214 case WLAN_FC_STYPE_REASSOC_REQ:
215 wpa_printf(MSG_DEBUG, "mgmt::reassoc_req");
216 - handle_assoc(hapd, mgmt, len, 1);
217 + handle_assoc(hapd, mgmt, len, 1, fi);
218 ret = 1;
219 break;
220 case WLAN_FC_STYPE_DISASSOC:
221 --- a/src/ap/beacon.c
222 +++ b/src/ap/beacon.c
223 @@ -716,7 +716,7 @@ void sta_track_claim_taxonomy_info(struc
224
225 void handle_probe_req(struct hostapd_data *hapd,
226 const struct ieee80211_mgmt *mgmt, size_t len,
227 - int ssi_signal)
228 + struct hostapd_frame_info *fi)
229 {
230 u8 *resp;
231 struct ieee802_11_elems elems;
232 @@ -725,9 +725,15 @@ void handle_probe_req(struct hostapd_dat
233 size_t i, resp_len;
234 int noack;
235 enum ssid_match_result res;
236 + int ssi_signal = fi->ssi_signal;
237 int ret;
238 u16 csa_offs[2];
239 size_t csa_offs_len;
240 + struct hostapd_ubus_request req = {
241 + .type = HOSTAPD_UBUS_PROBE_REQ,
242 + .mgmt_frame = mgmt,
243 + .frame_info = fi,
244 + };
245
246 if (len < IEEE80211_HDRLEN)
247 return;
248 @@ -894,6 +900,12 @@ void handle_probe_req(struct hostapd_dat
249 }
250 #endif /* CONFIG_P2P */
251
252 + if (hostapd_ubus_handle_event(hapd, &req)) {
253 + wpa_printf(MSG_DEBUG, "Probe request for " MACSTR " rejected by ubus handler.\n",
254 + MAC2STR(mgmt->sa));
255 + return;
256 + }
257 +
258 /* TODO: verify that supp_rates contains at least one matching rate
259 * with AP configuration */
260
261 --- a/src/ap/beacon.h
262 +++ b/src/ap/beacon.h
263 @@ -14,7 +14,7 @@ struct ieee80211_mgmt;
264
265 void handle_probe_req(struct hostapd_data *hapd,
266 const struct ieee80211_mgmt *mgmt, size_t len,
267 - int ssi_signal);
268 + struct hostapd_frame_info *fi);
269 int ieee802_11_set_beacon(struct hostapd_data *hapd);
270 int ieee802_11_set_beacons(struct hostapd_iface *iface);
271 int ieee802_11_update_beacons(struct hostapd_iface *iface);
272 --- a/src/ap/drv_callbacks.c
273 +++ b/src/ap/drv_callbacks.c
274 @@ -116,6 +116,10 @@ int hostapd_notif_assoc(struct hostapd_d
275 u16 reason = WLAN_REASON_UNSPECIFIED;
276 u16 status = WLAN_STATUS_SUCCESS;
277 const u8 *p2p_dev_addr = NULL;
278 + struct hostapd_ubus_request req = {
279 + .type = HOSTAPD_UBUS_ASSOC_REQ,
280 + .addr = addr,
281 + };
282
283 if (addr == NULL) {
284 /*
285 @@ -195,6 +199,12 @@ int hostapd_notif_assoc(struct hostapd_d
286 goto fail;
287 }
288
289 + if (hostapd_ubus_handle_event(hapd, &req)) {
290 + wpa_printf(MSG_DEBUG, "Station " MACSTR " assoc rejected by ubus handler.\n",
291 + MAC2STR(req.addr));
292 + goto fail;
293 + }
294 +
295 #ifdef CONFIG_P2P
296 if (elems.p2p) {
297 wpabuf_free(sta->p2p_ie);
298 --- a/src/ap/sta_info.c
299 +++ b/src/ap/sta_info.c
300 @@ -404,6 +404,7 @@ void ap_handle_timer(void *eloop_ctx, vo
301 HOSTAPD_LEVEL_INFO, "deauthenticated due to "
302 "local deauth request");
303 ap_free_sta(hapd, sta);
304 + hostapd_ubus_notify(hapd, "local-deauth", sta->addr);
305 return;
306 }
307
308 @@ -551,6 +552,7 @@ skip_poll:
309 hapd, sta,
310 WLAN_REASON_PREV_AUTH_NOT_VALID);
311 ap_free_sta(hapd, sta);
312 + hostapd_ubus_notify(hapd, "inactive-deauth", sta->addr);
313 break;
314 }
315 }
316 @@ -1212,6 +1214,7 @@ void ap_sta_set_authorized(struct hostap
317 buf, ip_addr);
318 } else {
319 wpa_msg(hapd->msg_ctx, MSG_INFO, AP_STA_DISCONNECTED "%s", buf);
320 + hostapd_ubus_notify(hapd, "disassoc", sta->addr);
321
322 if (hapd->msg_ctx_parent &&
323 hapd->msg_ctx_parent != hapd->msg_ctx)
324 --- a/src/ap/wpa_auth_glue.c
325 +++ b/src/ap/wpa_auth_glue.c
326 @@ -175,6 +175,7 @@ static void hostapd_wpa_auth_psk_failure
327 struct hostapd_data *hapd = ctx;
328 wpa_msg(hapd->msg_ctx, MSG_INFO, AP_STA_POSSIBLE_PSK_MISMATCH MACSTR,
329 MAC2STR(addr));
330 + hostapd_ubus_notify(hapd, "key-mismatch", addr);
331 }
332
333