a70f8861ac16a28eec655fb993318bdd0bd5252c
[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 #define OCE_STA_CFON_ENABLED(hapd) \
24 ((hapd->conf->oce & OCE_STA_CFON) && \
25 @@ -136,6 +137,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 @@ -547,6 +549,7 @@ hostapd_alloc_bss_data(struct hostapd_if
34 struct hostapd_bss_config *bss);
35 int hostapd_setup_interface(struct hostapd_iface *iface);
36 int hostapd_setup_interface_complete(struct hostapd_iface *iface, int err);
37 +void hostapd_set_own_neighbor_report(struct hostapd_data *hapd);
38 void hostapd_interface_deinit(struct hostapd_iface *iface);
39 void hostapd_interface_free(struct hostapd_iface *iface);
40 struct hostapd_iface * hostapd_alloc_iface(void);
41 --- a/src/ap/hostapd.c
42 +++ b/src/ap/hostapd.c
43 @@ -373,6 +373,7 @@ static void hostapd_free_hapd_data(struc
44 hapd->started = 0;
45
46 wpa_printf(MSG_DEBUG, "%s(%s)", __func__, hapd->conf->iface);
47 + hostapd_ubus_free_bss(hapd);
48 iapp_deinit(hapd->iapp);
49 hapd->iapp = NULL;
50 accounting_deinit(hapd);
51 @@ -1295,6 +1296,8 @@ static int hostapd_setup_bss(struct host
52 if (hapd->driver && hapd->driver->set_operstate)
53 hapd->driver->set_operstate(hapd->drv_priv, 1);
54
55 + hostapd_ubus_add_bss(hapd);
56 +
57 return 0;
58 }
59
60 @@ -1709,7 +1712,7 @@ static enum nr_chan_width hostapd_get_nr
61 #endif /* NEED_AP_MLME */
62
63
64 -static void hostapd_set_own_neighbor_report(struct hostapd_data *hapd)
65 +void hostapd_set_own_neighbor_report(struct hostapd_data *hapd)
66 {
67 #ifdef NEED_AP_MLME
68 u16 capab = hostapd_own_capab_info(hapd);
69 @@ -1930,6 +1933,7 @@ static int hostapd_setup_interface_compl
70 if (err)
71 goto fail;
72
73 + hostapd_ubus_add_iface(iface);
74 wpa_printf(MSG_DEBUG, "Completing interface initialization");
75 if (iface->conf->channel) {
76 #ifdef NEED_AP_MLME
77 @@ -2110,6 +2114,7 @@ dfs_offload:
78
79 fail:
80 wpa_printf(MSG_ERROR, "Interface initialization failed");
81 + hostapd_ubus_free_iface(iface);
82 hostapd_set_state(iface, HAPD_IFACE_DISABLED);
83 wpa_msg(hapd->msg_ctx, MSG_INFO, AP_EVENT_DISABLED);
84 #ifdef CONFIG_FST
85 @@ -2576,6 +2581,7 @@ void hostapd_interface_deinit_free(struc
86 (unsigned int) iface->conf->num_bss);
87 driver = iface->bss[0]->driver;
88 drv_priv = iface->bss[0]->drv_priv;
89 + hostapd_ubus_free_iface(iface);
90 hostapd_interface_deinit(iface);
91 wpa_printf(MSG_DEBUG, "%s: driver=%p drv_priv=%p -> hapd_deinit",
92 __func__, driver, drv_priv);
93 --- a/src/ap/ieee802_11.c
94 +++ b/src/ap/ieee802_11.c
95 @@ -1743,12 +1743,13 @@ ieee802_11_set_radius_info(struct hostap
96
97
98 static void handle_auth(struct hostapd_data *hapd,
99 - const struct ieee80211_mgmt *mgmt, size_t len)
100 + const struct ieee80211_mgmt *mgmt, size_t len,
101 + struct hostapd_frame_info *fi)
102 {
103 u16 auth_alg, auth_transaction, status_code;
104 u16 resp = WLAN_STATUS_SUCCESS;
105 struct sta_info *sta = NULL;
106 - int res, reply_res;
107 + int res, reply_res, ubus_resp;
108 u16 fc;
109 const u8 *challenge = NULL;
110 u32 session_timeout, acct_interim_interval;
111 @@ -1759,6 +1760,11 @@ static void handle_auth(struct hostapd_d
112 char *identity = NULL;
113 char *radius_cui = NULL;
114 u16 seq_ctrl;
115 + struct hostapd_ubus_request req = {
116 + .type = HOSTAPD_UBUS_AUTH_REQ,
117 + .mgmt_frame = mgmt,
118 + .frame_info = fi,
119 + };
120
121 if (len < IEEE80211_HDRLEN + sizeof(mgmt->u.auth)) {
122 wpa_printf(MSG_INFO, "handle_auth - too short payload (len=%lu)",
123 @@ -1919,6 +1925,13 @@ static void handle_auth(struct hostapd_d
124 resp = WLAN_STATUS_UNSPECIFIED_FAILURE;
125 goto fail;
126 }
127 + ubus_resp = hostapd_ubus_handle_event(hapd, &req);
128 + if (ubus_resp) {
129 + wpa_printf(MSG_DEBUG, "Station " MACSTR " rejected by ubus handler.\n",
130 + MAC2STR(mgmt->sa));
131 + resp = ubus_resp > 0 ? (u16) ubus_resp : WLAN_STATUS_UNSPECIFIED_FAILURE;
132 + goto fail;
133 + }
134 if (res == HOSTAPD_ACL_PENDING)
135 return;
136
137 @@ -3210,12 +3223,12 @@ void fils_hlp_timeout(void *eloop_ctx, v
138
139 static void handle_assoc(struct hostapd_data *hapd,
140 const struct ieee80211_mgmt *mgmt, size_t len,
141 - int reassoc)
142 + int reassoc, struct hostapd_frame_info *fi)
143 {
144 u16 capab_info, listen_interval, seq_ctrl, fc;
145 u16 resp = WLAN_STATUS_SUCCESS, reply_res;
146 const u8 *pos;
147 - int left, i;
148 + int left, i, ubus_resp;
149 struct sta_info *sta;
150 u8 *tmp = NULL;
151 struct hostapd_sta_wpa_psk_short *psk = NULL;
152 @@ -3224,6 +3237,11 @@ static void handle_assoc(struct hostapd_
153 #ifdef CONFIG_FILS
154 int delay_assoc = 0;
155 #endif /* CONFIG_FILS */
156 + struct hostapd_ubus_request req = {
157 + .type = HOSTAPD_UBUS_ASSOC_REQ,
158 + .mgmt_frame = mgmt,
159 + .frame_info = fi,
160 + };
161
162 if (len < IEEE80211_HDRLEN + (reassoc ? sizeof(mgmt->u.reassoc_req) :
163 sizeof(mgmt->u.assoc_req))) {
164 @@ -3395,6 +3413,14 @@ static void handle_assoc(struct hostapd_
165 }
166 #endif /* CONFIG_MBO */
167
168 + ubus_resp = hostapd_ubus_handle_event(hapd, &req);
169 + if (ubus_resp) {
170 + wpa_printf(MSG_DEBUG, "Station " MACSTR " assoc rejected by ubus handler.\n",
171 + MAC2STR(mgmt->sa));
172 + resp = ubus_resp > 0 ? (u16) ubus_resp : WLAN_STATUS_UNSPECIFIED_FAILURE;
173 + goto fail;
174 + }
175 +
176 /*
177 * sta->capability is used in check_assoc_ies() for RRM enabled
178 * capability element.
179 @@ -3608,6 +3634,7 @@ static void handle_disassoc(struct hosta
180 wpa_printf(MSG_DEBUG, "disassocation: STA=" MACSTR " reason_code=%d",
181 MAC2STR(mgmt->sa),
182 le_to_host16(mgmt->u.disassoc.reason_code));
183 + hostapd_ubus_notify(hapd, "disassoc", mgmt->sa);
184
185 sta = ap_get_sta(hapd, mgmt->sa);
186 if (sta == NULL) {
187 @@ -3673,6 +3700,8 @@ static void handle_deauth(struct hostapd
188 " reason_code=%d",
189 MAC2STR(mgmt->sa), le_to_host16(mgmt->u.deauth.reason_code));
190
191 + hostapd_ubus_notify(hapd, "deauth", mgmt->sa);
192 +
193 sta = ap_get_sta(hapd, mgmt->sa);
194 if (sta == NULL) {
195 wpa_msg(hapd->msg_ctx, MSG_DEBUG, "Station " MACSTR " trying "
196 @@ -4000,7 +4029,7 @@ int ieee802_11_mgmt(struct hostapd_data
197
198
199 if (stype == WLAN_FC_STYPE_PROBE_REQ) {
200 - handle_probe_req(hapd, mgmt, len, ssi_signal);
201 + handle_probe_req(hapd, mgmt, len, fi);
202 return 1;
203 }
204
205 @@ -4020,17 +4049,17 @@ int ieee802_11_mgmt(struct hostapd_data
206 switch (stype) {
207 case WLAN_FC_STYPE_AUTH:
208 wpa_printf(MSG_DEBUG, "mgmt::auth");
209 - handle_auth(hapd, mgmt, len);
210 + handle_auth(hapd, mgmt, len, fi);
211 ret = 1;
212 break;
213 case WLAN_FC_STYPE_ASSOC_REQ:
214 wpa_printf(MSG_DEBUG, "mgmt::assoc_req");
215 - handle_assoc(hapd, mgmt, len, 0);
216 + handle_assoc(hapd, mgmt, len, 0, fi);
217 ret = 1;
218 break;
219 case WLAN_FC_STYPE_REASSOC_REQ:
220 wpa_printf(MSG_DEBUG, "mgmt::reassoc_req");
221 - handle_assoc(hapd, mgmt, len, 1);
222 + handle_assoc(hapd, mgmt, len, 1, fi);
223 ret = 1;
224 break;
225 case WLAN_FC_STYPE_DISASSOC:
226 --- a/src/ap/beacon.c
227 +++ b/src/ap/beacon.c
228 @@ -725,7 +725,7 @@ void sta_track_claim_taxonomy_info(struc
229
230 void handle_probe_req(struct hostapd_data *hapd,
231 const struct ieee80211_mgmt *mgmt, size_t len,
232 - int ssi_signal)
233 + struct hostapd_frame_info *fi)
234 {
235 u8 *resp;
236 struct ieee802_11_elems elems;
237 @@ -734,6 +734,7 @@ void handle_probe_req(struct hostapd_dat
238 size_t i, resp_len;
239 int noack;
240 enum ssid_match_result res;
241 + int ssi_signal = fi->ssi_signal;
242 int ret;
243 u16 csa_offs[2];
244 size_t csa_offs_len;
245 @@ -742,6 +743,12 @@ void handle_probe_req(struct hostapd_dat
246 struct hostapd_sta_wpa_psk_short *psk = NULL;
247 char *identity = NULL;
248 char *radius_cui = NULL;
249 + struct hostapd_ubus_request req = {
250 + .type = HOSTAPD_UBUS_PROBE_REQ,
251 + .mgmt_frame = mgmt,
252 + .frame_info = fi,
253 + .elems = &elems,
254 + };
255
256 if (len < IEEE80211_HDRLEN)
257 return;
258 @@ -919,6 +926,12 @@ void handle_probe_req(struct hostapd_dat
259 }
260 #endif /* CONFIG_P2P */
261
262 + if (hostapd_ubus_handle_event(hapd, &req)) {
263 + wpa_printf(MSG_DEBUG, "Probe request for " MACSTR " rejected by ubus handler.\n",
264 + MAC2STR(mgmt->sa));
265 + return;
266 + }
267 +
268 /* TODO: verify that supp_rates contains at least one matching rate
269 * with AP configuration */
270
271 --- a/src/ap/beacon.h
272 +++ b/src/ap/beacon.h
273 @@ -14,7 +14,7 @@ struct ieee80211_mgmt;
274
275 void handle_probe_req(struct hostapd_data *hapd,
276 const struct ieee80211_mgmt *mgmt, size_t len,
277 - int ssi_signal);
278 + struct hostapd_frame_info *fi);
279 int ieee802_11_set_beacon(struct hostapd_data *hapd);
280 int ieee802_11_set_beacons(struct hostapd_iface *iface);
281 int ieee802_11_update_beacons(struct hostapd_iface *iface);
282 --- a/src/ap/drv_callbacks.c
283 +++ b/src/ap/drv_callbacks.c
284 @@ -116,6 +116,10 @@ int hostapd_notif_assoc(struct hostapd_d
285 u16 reason = WLAN_REASON_UNSPECIFIED;
286 u16 status = WLAN_STATUS_SUCCESS;
287 const u8 *p2p_dev_addr = NULL;
288 + struct hostapd_ubus_request req = {
289 + .type = HOSTAPD_UBUS_ASSOC_REQ,
290 + .addr = addr,
291 + };
292
293 if (addr == NULL) {
294 /*
295 @@ -195,6 +199,12 @@ int hostapd_notif_assoc(struct hostapd_d
296 goto fail;
297 }
298
299 + if (hostapd_ubus_handle_event(hapd, &req)) {
300 + wpa_printf(MSG_DEBUG, "Station " MACSTR " assoc rejected by ubus handler.\n",
301 + MAC2STR(req.addr));
302 + goto fail;
303 + }
304 +
305 #ifdef CONFIG_P2P
306 if (elems.p2p) {
307 wpabuf_free(sta->p2p_ie);
308 --- a/src/ap/sta_info.c
309 +++ b/src/ap/sta_info.c
310 @@ -416,6 +416,7 @@ void ap_handle_timer(void *eloop_ctx, vo
311 HOSTAPD_LEVEL_INFO, "deauthenticated due to "
312 "local deauth request");
313 ap_free_sta(hapd, sta);
314 + hostapd_ubus_notify(hapd, "local-deauth", sta->addr);
315 return;
316 }
317
318 @@ -563,6 +564,7 @@ skip_poll:
319 hapd, sta,
320 WLAN_REASON_PREV_AUTH_NOT_VALID);
321 ap_free_sta(hapd, sta);
322 + hostapd_ubus_notify(hapd, "inactive-deauth", sta->addr);
323 break;
324 }
325 }
326 @@ -1224,6 +1226,7 @@ void ap_sta_set_authorized(struct hostap
327 buf, ip_addr);
328 } else {
329 wpa_msg(hapd->msg_ctx, MSG_INFO, AP_STA_DISCONNECTED "%s", buf);
330 + hostapd_ubus_notify(hapd, "disassoc", sta->addr);
331
332 if (hapd->msg_ctx_parent &&
333 hapd->msg_ctx_parent != hapd->msg_ctx)
334 --- a/src/ap/wpa_auth_glue.c
335 +++ b/src/ap/wpa_auth_glue.c
336 @@ -177,6 +177,7 @@ static void hostapd_wpa_auth_psk_failure
337 struct hostapd_data *hapd = ctx;
338 wpa_msg(hapd->msg_ctx, MSG_INFO, AP_STA_POSSIBLE_PSK_MISMATCH MACSTR,
339 MAC2STR(addr));
340 + hostapd_ubus_notify(hapd, "key-mismatch", addr);
341 }
342
343
344 --- a/wpa_supplicant/Makefile
345 +++ b/wpa_supplicant/Makefile
346 @@ -189,6 +189,12 @@ ifdef CONFIG_EAPOL_TEST
347 CFLAGS += -Werror -DEAPOL_TEST
348 endif
349
350 +ifdef CONFIG_UBUS
351 +CFLAGS += -DUBUS_SUPPORT
352 +OBJS += ubus.o
353 +LIBS += -lubox -lubus
354 +endif
355 +
356 ifdef CONFIG_CODE_COVERAGE
357 CFLAGS += -O0 -fprofile-arcs -ftest-coverage
358 LIBS += -lgcov
359 @@ -915,6 +921,9 @@ endif
360 ifdef CONFIG_IEEE80211AX
361 OBJS += ../src/ap/ieee802_11_he.o
362 endif
363 +ifdef CONFIG_UBUS
364 +OBJS += ../src/ap/ubus.o
365 +endif
366 endif
367 ifdef CONFIG_WNM_AP
368 CFLAGS += -DCONFIG_WNM_AP
369 --- a/wpa_supplicant/wpa_supplicant.c
370 +++ b/wpa_supplicant/wpa_supplicant.c
371 @@ -6062,6 +6062,8 @@ struct wpa_supplicant * wpa_supplicant_a
372 }
373 #endif /* CONFIG_P2P */
374
375 + wpas_ubus_add_bss(wpa_s);
376 +
377 return wpa_s;
378 }
379
380 @@ -6088,6 +6090,8 @@ int wpa_supplicant_remove_iface(struct w
381 struct wpa_supplicant *parent = wpa_s->parent;
382 #endif /* CONFIG_MESH */
383
384 + wpas_ubus_free_bss(wpa_s);
385 +
386 /* Remove interface from the global list of interfaces */
387 prev = global->ifaces;
388 if (prev == wpa_s) {
389 --- a/wpa_supplicant/wpa_supplicant_i.h
390 +++ b/wpa_supplicant/wpa_supplicant_i.h
391 @@ -17,6 +17,7 @@
392 #include "wps/wps_defs.h"
393 #include "config_ssid.h"
394 #include "wmm_ac.h"
395 +#include "ubus.h"
396
397 extern const char *const wpa_supplicant_version;
398 extern const char *const wpa_supplicant_license;
399 @@ -500,6 +501,7 @@ struct wpa_supplicant {
400 unsigned char own_addr[ETH_ALEN];
401 unsigned char perm_addr[ETH_ALEN];
402 char ifname[100];
403 + struct wpas_ubus_bss ubus;
404 #ifdef CONFIG_MATCH_IFACE
405 int matched;
406 #endif /* CONFIG_MATCH_IFACE */
407 --- a/wpa_supplicant/wps_supplicant.c
408 +++ b/wpa_supplicant/wps_supplicant.c
409 @@ -33,6 +33,7 @@
410 #include "p2p/p2p.h"
411 #include "p2p_supplicant.h"
412 #include "wps_supplicant.h"
413 +#include "ubus.h"
414
415
416 #ifndef WPS_PIN_SCAN_IGNORE_SEL_REG
417 @@ -388,6 +389,8 @@ static int wpa_supplicant_wps_cred(void
418 wpa_hexdump_key(MSG_DEBUG, "WPS: Received Credential attribute",
419 cred->cred_attr, cred->cred_attr_len);
420
421 + wpas_ubus_notify(wpa_s, cred);
422 +
423 if (wpa_s->conf->wps_cred_processing == 1)
424 return 0;
425