hostapd: expose beacon reports through ubus
[openwrt/staging/wigyori.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 @@ -17,6 +17,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 @@ -72,6 +73,8 @@ struct hapd_interfaces {
26 #ifdef CONFIG_DPP
27 struct dpp_global *dpp;
28 #endif /* CONFIG_DPP */
29 + struct ubus_object ubus;
30 + char *name;
31 };
32
33 enum hostapd_chan_status {
34 @@ -145,6 +148,7 @@ struct hostapd_data {
35 struct hostapd_iface *iface;
36 struct hostapd_config *iconf;
37 struct hostapd_bss_config *conf;
38 + struct hostapd_ubus_bss ubus;
39 int interface_added; /* virtual interface added for this BSS */
40 unsigned int started:1;
41 unsigned int disabled:1;
42 @@ -580,6 +584,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 @@ -380,6 +380,7 @@ static void hostapd_free_hapd_data(struc
53 hapd->beacon_set_done = 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 @@ -1377,6 +1378,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 @@ -1891,6 +1894,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 @@ -2087,6 +2091,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 @@ -2562,6 +2567,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 @@ -2032,7 +2032,7 @@ static void handle_auth(struct hostapd_d
96 u16 auth_alg, auth_transaction, status_code;
97 u16 resp = WLAN_STATUS_SUCCESS;
98 struct sta_info *sta = NULL;
99 - int res, reply_res;
100 + int res, reply_res, ubus_resp;
101 u16 fc;
102 const u8 *challenge = NULL;
103 u32 session_timeout, acct_interim_interval;
104 @@ -2043,6 +2043,11 @@ static void handle_auth(struct hostapd_d
105 char *identity = NULL;
106 char *radius_cui = NULL;
107 u16 seq_ctrl;
108 + struct hostapd_ubus_request req = {
109 + .type = HOSTAPD_UBUS_AUTH_REQ,
110 + .mgmt_frame = mgmt,
111 + .ssi_signal = rssi,
112 + };
113
114 if (len < IEEE80211_HDRLEN + sizeof(mgmt->u.auth)) {
115 wpa_printf(MSG_INFO, "handle_auth - too short payload (len=%lu)",
116 @@ -2204,6 +2209,13 @@ static void handle_auth(struct hostapd_d
117 resp = WLAN_STATUS_UNSPECIFIED_FAILURE;
118 goto fail;
119 }
120 + ubus_resp = hostapd_ubus_handle_event(hapd, &req);
121 + if (ubus_resp) {
122 + wpa_printf(MSG_DEBUG, "Station " MACSTR " rejected by ubus handler.\n",
123 + MAC2STR(mgmt->sa));
124 + resp = ubus_resp > 0 ? (u16) ubus_resp : WLAN_STATUS_UNSPECIFIED_FAILURE;
125 + goto fail;
126 + }
127 if (res == HOSTAPD_ACL_PENDING)
128 return;
129
130 @@ -3862,7 +3874,7 @@ static void handle_assoc(struct hostapd_
131 u16 capab_info, listen_interval, seq_ctrl, fc;
132 u16 resp = WLAN_STATUS_SUCCESS, reply_res;
133 const u8 *pos;
134 - int left, i;
135 + int left, i, ubus_resp;
136 struct sta_info *sta;
137 u8 *tmp = NULL;
138 struct hostapd_sta_wpa_psk_short *psk = NULL;
139 @@ -3871,6 +3883,11 @@ static void handle_assoc(struct hostapd_
140 #ifdef CONFIG_FILS
141 int delay_assoc = 0;
142 #endif /* CONFIG_FILS */
143 + struct hostapd_ubus_request req = {
144 + .type = HOSTAPD_UBUS_ASSOC_REQ,
145 + .mgmt_frame = mgmt,
146 + .ssi_signal = rssi,
147 + };
148
149 if (len < IEEE80211_HDRLEN + (reassoc ? sizeof(mgmt->u.reassoc_req) :
150 sizeof(mgmt->u.assoc_req))) {
151 @@ -4050,6 +4067,14 @@ static void handle_assoc(struct hostapd_
152 }
153 #endif /* CONFIG_MBO */
154
155 + ubus_resp = hostapd_ubus_handle_event(hapd, &req);
156 + if (ubus_resp) {
157 + wpa_printf(MSG_DEBUG, "Station " MACSTR " assoc rejected by ubus handler.\n",
158 + MAC2STR(mgmt->sa));
159 + resp = ubus_resp > 0 ? (u16) ubus_resp : WLAN_STATUS_UNSPECIFIED_FAILURE;
160 + goto fail;
161 + }
162 +
163 /*
164 * sta->capability is used in check_assoc_ies() for RRM enabled
165 * capability element.
166 @@ -4277,6 +4302,7 @@ static void handle_disassoc(struct hosta
167 wpa_printf(MSG_DEBUG, "disassocation: STA=" MACSTR " reason_code=%d",
168 MAC2STR(mgmt->sa),
169 le_to_host16(mgmt->u.disassoc.reason_code));
170 + hostapd_ubus_notify(hapd, "disassoc", mgmt->sa);
171
172 sta = ap_get_sta(hapd, mgmt->sa);
173 if (sta == NULL) {
174 @@ -4342,6 +4368,8 @@ static void handle_deauth(struct hostapd
175 " reason_code=%d",
176 MAC2STR(mgmt->sa), le_to_host16(mgmt->u.deauth.reason_code));
177
178 + hostapd_ubus_notify(hapd, "deauth", mgmt->sa);
179 +
180 sta = ap_get_sta(hapd, mgmt->sa);
181 if (sta == NULL) {
182 wpa_msg(hapd->msg_ctx, MSG_DEBUG, "Station " MACSTR " trying "
183 --- a/src/ap/beacon.c
184 +++ b/src/ap/beacon.c
185 @@ -746,6 +746,12 @@ void handle_probe_req(struct hostapd_dat
186 struct hostapd_sta_wpa_psk_short *psk = NULL;
187 char *identity = NULL;
188 char *radius_cui = NULL;
189 + struct hostapd_ubus_request req = {
190 + .type = HOSTAPD_UBUS_PROBE_REQ,
191 + .mgmt_frame = mgmt,
192 + .ssi_signal = ssi_signal,
193 + .elems = &elems,
194 + };
195
196 if (len < IEEE80211_HDRLEN)
197 return;
198 @@ -923,6 +929,12 @@ void handle_probe_req(struct hostapd_dat
199 }
200 #endif /* CONFIG_P2P */
201
202 + if (hostapd_ubus_handle_event(hapd, &req)) {
203 + wpa_printf(MSG_DEBUG, "Probe request for " MACSTR " rejected by ubus handler.\n",
204 + MAC2STR(mgmt->sa));
205 + return;
206 + }
207 +
208 /* TODO: verify that supp_rates contains at least one matching rate
209 * with AP configuration */
210
211 --- a/src/ap/drv_callbacks.c
212 +++ b/src/ap/drv_callbacks.c
213 @@ -118,6 +118,10 @@ int hostapd_notif_assoc(struct hostapd_d
214 u16 reason = WLAN_REASON_UNSPECIFIED;
215 u16 status = WLAN_STATUS_SUCCESS;
216 const u8 *p2p_dev_addr = NULL;
217 + struct hostapd_ubus_request req = {
218 + .type = HOSTAPD_UBUS_ASSOC_REQ,
219 + .addr = addr,
220 + };
221
222 if (addr == NULL) {
223 /*
224 @@ -210,6 +214,12 @@ int hostapd_notif_assoc(struct hostapd_d
225 goto fail;
226 }
227
228 + if (hostapd_ubus_handle_event(hapd, &req)) {
229 + wpa_printf(MSG_DEBUG, "Station " MACSTR " assoc rejected by ubus handler.\n",
230 + MAC2STR(req.addr));
231 + goto fail;
232 + }
233 +
234 #ifdef CONFIG_P2P
235 if (elems.p2p) {
236 wpabuf_free(sta->p2p_ie);
237 --- a/src/ap/sta_info.c
238 +++ b/src/ap/sta_info.c
239 @@ -424,6 +424,7 @@ void ap_handle_timer(void *eloop_ctx, vo
240 HOSTAPD_LEVEL_INFO, "deauthenticated due to "
241 "local deauth request");
242 ap_free_sta(hapd, sta);
243 + hostapd_ubus_notify(hapd, "local-deauth", sta->addr);
244 return;
245 }
246
247 @@ -578,6 +579,7 @@ skip_poll:
248 hapd, sta,
249 WLAN_REASON_PREV_AUTH_NOT_VALID);
250 ap_free_sta(hapd, sta);
251 + hostapd_ubus_notify(hapd, "inactive-deauth", sta->addr);
252 break;
253 }
254 }
255 @@ -1284,6 +1286,7 @@ void ap_sta_set_authorized(struct hostap
256 buf, ip_addr, keyid_buf);
257 } else {
258 wpa_msg(hapd->msg_ctx, MSG_INFO, AP_STA_DISCONNECTED "%s", buf);
259 + hostapd_ubus_notify(hapd, "disassoc", sta->addr);
260
261 if (hapd->msg_ctx_parent &&
262 hapd->msg_ctx_parent != hapd->msg_ctx)
263 --- a/src/ap/wpa_auth_glue.c
264 +++ b/src/ap/wpa_auth_glue.c
265 @@ -185,6 +185,7 @@ static void hostapd_wpa_auth_psk_failure
266 struct hostapd_data *hapd = ctx;
267 wpa_msg(hapd->msg_ctx, MSG_INFO, AP_STA_POSSIBLE_PSK_MISMATCH MACSTR,
268 MAC2STR(addr));
269 + hostapd_ubus_notify(hapd, "key-mismatch", addr);
270 }
271
272
273 --- a/wpa_supplicant/Makefile
274 +++ b/wpa_supplicant/Makefile
275 @@ -188,6 +188,12 @@ ifdef CONFIG_EAPOL_TEST
276 CFLAGS += -Werror -DEAPOL_TEST
277 endif
278
279 +ifdef CONFIG_UBUS
280 +CFLAGS += -DUBUS_SUPPORT
281 +OBJS += ubus.o
282 +LIBS += -lubox -lubus
283 +endif
284 +
285 ifdef CONFIG_CODE_COVERAGE
286 CFLAGS += -O0 -fprofile-arcs -ftest-coverage
287 LIBS += -lgcov
288 @@ -945,6 +951,9 @@ endif
289 ifdef CONFIG_IEEE80211AX
290 OBJS += ../src/ap/ieee802_11_he.o
291 endif
292 +ifdef CONFIG_UBUS
293 +OBJS += ../src/ap/ubus.o
294 +endif
295 endif
296 ifdef CONFIG_WNM_AP
297 CFLAGS += -DCONFIG_WNM_AP
298 --- a/wpa_supplicant/wpa_supplicant.c
299 +++ b/wpa_supplicant/wpa_supplicant.c
300 @@ -6297,6 +6297,8 @@ struct wpa_supplicant * wpa_supplicant_a
301 }
302 #endif /* CONFIG_P2P */
303
304 + wpas_ubus_add_bss(wpa_s);
305 +
306 return wpa_s;
307 }
308
309 @@ -6323,6 +6325,8 @@ int wpa_supplicant_remove_iface(struct w
310 struct wpa_supplicant *parent = wpa_s->parent;
311 #endif /* CONFIG_MESH */
312
313 + wpas_ubus_free_bss(wpa_s);
314 +
315 /* Remove interface from the global list of interfaces */
316 prev = global->ifaces;
317 if (prev == wpa_s) {
318 @@ -6520,6 +6524,8 @@ struct wpa_global * wpa_supplicant_init(
319 if (params->override_ctrl_interface)
320 global->params.override_ctrl_interface =
321 os_strdup(params->override_ctrl_interface);
322 + if (params->name)
323 + global->params.name = os_strdup(params->name);
324 #ifdef CONFIG_MATCH_IFACE
325 global->params.match_iface_count = params->match_iface_count;
326 if (params->match_iface_count) {
327 @@ -6626,8 +6632,12 @@ int wpa_supplicant_run(struct wpa_global
328 eloop_register_signal_terminate(wpa_supplicant_terminate, global);
329 eloop_register_signal_reconfig(wpa_supplicant_reconfig, global);
330
331 + wpas_ubus_add(global);
332 +
333 eloop_run();
334
335 + wpas_ubus_free(global);
336 +
337 return 0;
338 }
339
340 @@ -6687,6 +6697,7 @@ void wpa_supplicant_deinit(struct wpa_gl
341 #ifdef CONFIG_MATCH_IFACE
342 os_free(global->params.match_ifaces);
343 #endif /* CONFIG_MATCH_IFACE */
344 + os_free(global->params.name);
345 #ifdef CONFIG_P2P
346 os_free(global->params.conf_p2p_dev);
347 #endif /* CONFIG_P2P */
348 --- a/wpa_supplicant/wpa_supplicant_i.h
349 +++ b/wpa_supplicant/wpa_supplicant_i.h
350 @@ -17,6 +17,7 @@
351 #include "wps/wps_defs.h"
352 #include "config_ssid.h"
353 #include "wmm_ac.h"
354 +#include "ubus.h"
355
356 extern const char *const wpa_supplicant_version;
357 extern const char *const wpa_supplicant_license;
358 @@ -246,6 +247,8 @@ struct wpa_params {
359 */
360 int match_iface_count;
361 #endif /* CONFIG_MATCH_IFACE */
362 +
363 + char *name;
364 };
365
366 struct p2p_srv_bonjour {
367 @@ -306,6 +309,8 @@ struct wpa_global {
368 #endif /* CONFIG_WIFI_DISPLAY */
369
370 struct psk_list_entry *add_psk; /* From group formation */
371 +
372 + struct ubus_object ubus_global;
373 };
374
375
376 @@ -506,6 +511,7 @@ struct wpa_supplicant {
377 unsigned char own_addr[ETH_ALEN];
378 unsigned char perm_addr[ETH_ALEN];
379 char ifname[100];
380 + struct wpas_ubus_bss ubus;
381 #ifdef CONFIG_MATCH_IFACE
382 int matched;
383 #endif /* CONFIG_MATCH_IFACE */
384 --- a/wpa_supplicant/wps_supplicant.c
385 +++ b/wpa_supplicant/wps_supplicant.c
386 @@ -33,6 +33,7 @@
387 #include "p2p/p2p.h"
388 #include "p2p_supplicant.h"
389 #include "wps_supplicant.h"
390 +#include "ubus.h"
391
392
393 #ifndef WPS_PIN_SCAN_IGNORE_SEL_REG
394 @@ -388,6 +389,8 @@ static int wpa_supplicant_wps_cred(void
395 wpa_hexdump_key(MSG_DEBUG, "WPS: Received Credential attribute",
396 cred->cred_attr, cred->cred_attr_len);
397
398 + wpas_ubus_notify(wpa_s, cred);
399 +
400 if (wpa_s->conf->wps_cred_processing == 1)
401 return 0;
402
403 --- a/hostapd/main.c
404 +++ b/hostapd/main.c
405 @@ -688,7 +688,7 @@ int main(int argc, char *argv[])
406 wpa_supplicant_event = hostapd_wpa_event;
407 wpa_supplicant_event_global = hostapd_wpa_event_global;
408 for (;;) {
409 - c = getopt(argc, argv, "b:Bde:f:hi:KP:sSTtu:g:G:v::");
410 + c = getopt(argc, argv, "b:Bde:f:hi:KP:sSTtu:g:G:n:v::");
411 if (c < 0)
412 break;
413 switch (c) {
414 @@ -763,6 +763,8 @@ int main(int argc, char *argv[])
415 if (hostapd_get_interface_names(&if_names,
416 &if_names_size, optarg))
417 goto out;
418 + case 'n':
419 + interfaces.name = optarg;
420 break;
421 default:
422 usage();
423 @@ -894,6 +896,7 @@ int main(int argc, char *argv[])
424 }
425
426 hostapd_global_ctrl_iface_init(&interfaces);
427 + hostapd_ubus_add(&interfaces);
428
429 if (hostapd_global_run(&interfaces, daemonize, pid_file)) {
430 wpa_printf(MSG_ERROR, "Failed to start eloop");
431 @@ -903,6 +906,7 @@ int main(int argc, char *argv[])
432 ret = 0;
433
434 out:
435 + hostapd_ubus_free(&interfaces);
436 hostapd_global_ctrl_iface_deinit(&interfaces);
437 /* Deinitialize all interfaces */
438 for (i = 0; i < interfaces.count; i++) {
439 --- a/wpa_supplicant/main.c
440 +++ b/wpa_supplicant/main.c
441 @@ -203,7 +203,7 @@ int main(int argc, char *argv[])
442
443 for (;;) {
444 c = getopt(argc, argv,
445 - "b:Bc:C:D:de:f:g:G:hH:i:I:KLMm:No:O:p:P:qsTtuv::W");
446 + "b:Bc:C:D:de:f:g:G:hH:i:I:KLMm:n:No:O:p:P:qsTtuv::W");
447 if (c < 0)
448 break;
449 switch (c) {
450 @@ -271,6 +271,10 @@ int main(int argc, char *argv[])
451 params.conf_p2p_dev = optarg;
452 break;
453 #endif /* CONFIG_P2P */
454 + case 'n':
455 + params.name = optarg;
456 + iface_count = 0;
457 + break;
458 case 'o':
459 params.override_driver = optarg;
460 break;
461 --- a/src/ap/rrm.c
462 +++ b/src/ap/rrm.c
463 @@ -89,6 +89,9 @@ static void hostapd_handle_beacon_report
464 return;
465 wpa_msg(hapd->msg_ctx, MSG_INFO, BEACON_RESP_RX MACSTR " %u %02x %s",
466 MAC2STR(addr), token, rep_mode, report);
467 + if (len < sizeof(struct rrm_measurement_beacon_report))
468 + return;
469 + hostapd_ubus_notify_beacon_report(hapd, addr, token, rep_mode, (struct rrm_measurement_beacon_report*) pos, len);
470 }
471
472