hostapd: switch to using uloop (integrated with built-in eloop)
[openwrt/openwrt.git] / package / network / services / hostapd / patches / 600-ubus_support.patch
1 --- a/hostapd/Makefile
2 +++ b/hostapd/Makefile
3 @@ -166,6 +166,12 @@ 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/utils/uloop.o
10 +OBJS += ../src/ap/ubus.o
11 +LIBS += -lubox -lubus
12 +endif
13
14 ifdef CONFIG_CODE_COVERAGE
15 CFLAGS += -O0 -fprofile-arcs -ftest-coverage
16 --- a/src/ap/hostapd.h
17 +++ b/src/ap/hostapd.h
18 @@ -18,6 +18,7 @@
19 #include "utils/list.h"
20 #include "ap_config.h"
21 #include "drivers/driver.h"
22 +#include "ubus.h"
23
24 #define OCE_STA_CFON_ENABLED(hapd) \
25 ((hapd->conf->oce & OCE_STA_CFON) && \
26 @@ -92,7 +93,7 @@ struct hapd_interfaces {
27 #ifdef CONFIG_CTRL_IFACE_UDP
28 unsigned char ctrl_iface_cookie[CTRL_IFACE_COOKIE_LEN];
29 #endif /* CONFIG_CTRL_IFACE_UDP */
30 -
31 + struct ubus_object ubus;
32 };
33
34 enum hostapd_chan_status {
35 @@ -184,6 +185,7 @@ struct hostapd_data {
36 struct hostapd_iface *iface;
37 struct hostapd_config *iconf;
38 struct hostapd_bss_config *conf;
39 + struct hostapd_ubus_bss ubus;
40 int interface_added; /* virtual interface added for this BSS */
41 unsigned int started:1;
42 unsigned int disabled:1;
43 @@ -695,6 +697,7 @@ hostapd_alloc_bss_data(struct hostapd_if
44 struct hostapd_bss_config *bss);
45 int hostapd_setup_interface(struct hostapd_iface *iface);
46 int hostapd_setup_interface_complete(struct hostapd_iface *iface, int err);
47 +void hostapd_set_own_neighbor_report(struct hostapd_data *hapd);
48 void hostapd_interface_deinit(struct hostapd_iface *iface);
49 void hostapd_interface_free(struct hostapd_iface *iface);
50 struct hostapd_iface * hostapd_alloc_iface(void);
51 --- a/src/ap/hostapd.c
52 +++ b/src/ap/hostapd.c
53 @@ -455,6 +455,7 @@ void hostapd_free_hapd_data(struct hosta
54 hapd->beacon_set_done = 0;
55
56 wpa_printf(MSG_DEBUG, "%s(%s)", __func__, hapd->conf->iface);
57 + hostapd_ubus_free_bss(hapd);
58 accounting_deinit(hapd);
59 hostapd_deinit_wpa(hapd);
60 vlan_deinit(hapd);
61 @@ -1207,6 +1208,8 @@ static int hostapd_start_beacon(struct h
62 if (hapd->driver && hapd->driver->set_operstate)
63 hapd->driver->set_operstate(hapd->drv_priv, 1);
64
65 + hostapd_ubus_add_bss(hapd);
66 +
67 return 0;
68 }
69
70 @@ -2295,6 +2298,7 @@ static int hostapd_setup_interface_compl
71 if (err)
72 goto fail;
73
74 + hostapd_ubus_add_iface(iface);
75 wpa_printf(MSG_DEBUG, "Completing interface initialization");
76 if (iface->freq) {
77 #ifdef NEED_AP_MLME
78 @@ -2514,6 +2518,7 @@ dfs_offload:
79
80 fail:
81 wpa_printf(MSG_ERROR, "Interface initialization failed");
82 + hostapd_ubus_free_iface(iface);
83
84 if (iface->is_no_ir) {
85 hostapd_set_state(iface, HAPD_IFACE_NO_IR);
86 @@ -3004,6 +3009,7 @@ void hostapd_interface_deinit_free(struc
87 (unsigned int) iface->conf->num_bss);
88 driver = iface->bss[0]->driver;
89 drv_priv = iface->bss[0]->drv_priv;
90 + hostapd_ubus_free_iface(iface);
91 hostapd_interface_deinit(iface);
92 wpa_printf(MSG_DEBUG, "%s: driver=%p drv_priv=%p -> hapd_deinit",
93 __func__, driver, drv_priv);
94 --- a/src/ap/ieee802_11.c
95 +++ b/src/ap/ieee802_11.c
96 @@ -2778,7 +2778,7 @@ static void handle_auth(struct hostapd_d
97 u16 auth_alg, auth_transaction, status_code;
98 u16 resp = WLAN_STATUS_SUCCESS;
99 struct sta_info *sta = NULL;
100 - int res, reply_res;
101 + int res, reply_res, ubus_resp;
102 u16 fc;
103 const u8 *challenge = NULL;
104 u8 resp_ies[2 + WLAN_AUTH_CHALLENGE_LEN];
105 @@ -2787,6 +2787,11 @@ static void handle_auth(struct hostapd_d
106 struct radius_sta rad_info;
107 const u8 *dst, *sa, *bssid;
108 bool mld_sta = false;
109 + struct hostapd_ubus_request req = {
110 + .type = HOSTAPD_UBUS_AUTH_REQ,
111 + .mgmt_frame = mgmt,
112 + .ssi_signal = rssi,
113 + };
114
115 if (len < IEEE80211_HDRLEN + sizeof(mgmt->u.auth)) {
116 wpa_printf(MSG_INFO, "handle_auth - too short payload (len=%lu)",
117 @@ -2978,6 +2983,13 @@ static void handle_auth(struct hostapd_d
118 resp = WLAN_STATUS_UNSPECIFIED_FAILURE;
119 goto fail;
120 }
121 + ubus_resp = hostapd_ubus_handle_event(hapd, &req);
122 + if (ubus_resp) {
123 + wpa_printf(MSG_DEBUG, "Station " MACSTR " rejected by ubus handler.\n",
124 + MAC2STR(mgmt->sa));
125 + resp = ubus_resp > 0 ? (u16) ubus_resp : WLAN_STATUS_UNSPECIFIED_FAILURE;
126 + goto fail;
127 + }
128 if (res == HOSTAPD_ACL_PENDING)
129 return;
130
131 @@ -5141,7 +5153,7 @@ static void handle_assoc(struct hostapd_
132 int resp = WLAN_STATUS_SUCCESS;
133 u16 reply_res = WLAN_STATUS_UNSPECIFIED_FAILURE;
134 const u8 *pos;
135 - int left, i;
136 + int left, i, ubus_resp;
137 struct sta_info *sta;
138 u8 *tmp = NULL;
139 #ifdef CONFIG_FILS
140 @@ -5354,6 +5366,11 @@ static void handle_assoc(struct hostapd_
141 left = res;
142 }
143 #endif /* CONFIG_FILS */
144 + struct hostapd_ubus_request req = {
145 + .type = HOSTAPD_UBUS_ASSOC_REQ,
146 + .mgmt_frame = mgmt,
147 + .ssi_signal = rssi,
148 + };
149
150 /* followed by SSID and Supported rates; and HT capabilities if 802.11n
151 * is used */
152 @@ -5452,6 +5469,13 @@ static void handle_assoc(struct hostapd_
153 }
154 #endif /* CONFIG_FILS */
155
156 + ubus_resp = hostapd_ubus_handle_event(hapd, &req);
157 + if (ubus_resp) {
158 + wpa_printf(MSG_DEBUG, "Station " MACSTR " assoc rejected by ubus handler.\n",
159 + MAC2STR(mgmt->sa));
160 + resp = ubus_resp > 0 ? (u16) ubus_resp : WLAN_STATUS_UNSPECIFIED_FAILURE;
161 + goto fail;
162 + }
163 fail:
164
165 /*
166 @@ -5733,6 +5757,7 @@ static void handle_disassoc(struct hosta
167 (unsigned long) len);
168 return;
169 }
170 + hostapd_ubus_notify(hapd, "disassoc", mgmt->sa);
171
172 sta = ap_get_sta(hapd, mgmt->sa);
173 if (!sta) {
174 @@ -5764,6 +5789,8 @@ static void handle_deauth(struct hostapd
175 /* Clear the PTKSA cache entries for PASN */
176 ptksa_cache_flush(hapd->ptksa, mgmt->sa, WPA_CIPHER_NONE);
177
178 + hostapd_ubus_notify(hapd, "deauth", mgmt->sa);
179 +
180 sta = ap_get_sta(hapd, mgmt->sa);
181 if (!sta) {
182 wpa_msg(hapd->msg_ctx, MSG_DEBUG, "Station " MACSTR
183 --- a/src/ap/beacon.c
184 +++ b/src/ap/beacon.c
185 @@ -1036,6 +1036,12 @@ void handle_probe_req(struct hostapd_dat
186 u16 csa_offs[2];
187 size_t csa_offs_len;
188 struct radius_sta rad_info;
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 (hapd->iconf->rssi_ignore_probe_request && ssi_signal &&
197 ssi_signal < hapd->iconf->rssi_ignore_probe_request)
198 @@ -1222,6 +1228,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 @@ -145,6 +145,10 @@ int hostapd_notif_assoc(struct hostapd_d
214 u16 reason = WLAN_REASON_UNSPECIFIED;
215 int 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 @@ -237,6 +241,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 @@ -471,6 +471,7 @@ void ap_handle_timer(void *eloop_ctx, vo
240 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
241 HOSTAPD_LEVEL_INFO, "deauthenticated due to "
242 "local deauth request");
243 + hostapd_ubus_notify(hapd, "local-deauth", sta->addr);
244 ap_free_sta(hapd, sta);
245 return;
246 }
247 @@ -626,6 +627,7 @@ skip_poll:
248 mlme_deauthenticate_indication(
249 hapd, sta,
250 WLAN_REASON_PREV_AUTH_NOT_VALID);
251 + hostapd_ubus_notify(hapd, "inactive-deauth", sta->addr);
252 ap_free_sta(hapd, sta);
253 break;
254 }
255 @@ -1344,15 +1346,28 @@ void ap_sta_set_authorized(struct hostap
256 sta->addr, authorized, dev_addr);
257
258 if (authorized) {
259 + static const char * const auth_algs[] = {
260 + [WLAN_AUTH_OPEN] = "open",
261 + [WLAN_AUTH_SHARED_KEY] = "shared",
262 + [WLAN_AUTH_FT] = "ft",
263 + [WLAN_AUTH_SAE] = "sae",
264 + [WLAN_AUTH_FILS_SK] = "fils-sk",
265 + [WLAN_AUTH_FILS_SK_PFS] = "fils-sk-pfs",
266 + [WLAN_AUTH_FILS_PK] = "fils-pk",
267 + [WLAN_AUTH_PASN] = "pasn",
268 + };
269 + const char *auth_alg = NULL;
270 const u8 *dpp_pkhash;
271 const char *keyid;
272 char dpp_pkhash_buf[100];
273 char keyid_buf[100];
274 char ip_addr[100];
275 + char alg_buf[100];
276
277 dpp_pkhash_buf[0] = '\0';
278 keyid_buf[0] = '\0';
279 ip_addr[0] = '\0';
280 + alg_buf[0] = '\0';
281 #ifdef CONFIG_P2P
282 if (wpa_auth_get_ip_addr(sta->wpa_sm, ip_addr_buf) == 0) {
283 os_snprintf(ip_addr, sizeof(ip_addr),
284 @@ -1362,6 +1377,13 @@ void ap_sta_set_authorized(struct hostap
285 }
286 #endif /* CONFIG_P2P */
287
288 + if (sta->auth_alg < ARRAY_SIZE(auth_algs))
289 + auth_alg = auth_algs[sta->auth_alg];
290 +
291 + if (auth_alg)
292 + os_snprintf(alg_buf, sizeof(alg_buf),
293 + " auth_alg=%s", auth_alg);
294 +
295 keyid = ap_sta_wpa_get_keyid(hapd, sta);
296 if (keyid) {
297 os_snprintf(keyid_buf, sizeof(keyid_buf),
298 @@ -1380,17 +1402,19 @@ void ap_sta_set_authorized(struct hostap
299 dpp_pkhash, SHA256_MAC_LEN);
300 }
301
302 - wpa_msg(hapd->msg_ctx, MSG_INFO, AP_STA_CONNECTED "%s%s%s%s",
303 - buf, ip_addr, keyid_buf, dpp_pkhash_buf);
304 + hostapd_ubus_notify_authorized(hapd, sta, auth_alg);
305 + wpa_msg(hapd->msg_ctx, MSG_INFO, AP_STA_CONNECTED "%s%s%s%s%s",
306 + buf, ip_addr, keyid_buf, dpp_pkhash_buf, alg_buf);
307
308 if (hapd->msg_ctx_parent &&
309 hapd->msg_ctx_parent != hapd->msg_ctx)
310 wpa_msg_no_global(hapd->msg_ctx_parent, MSG_INFO,
311 - AP_STA_CONNECTED "%s%s%s%s",
312 + AP_STA_CONNECTED "%s%s%s%s%s",
313 buf, ip_addr, keyid_buf,
314 - dpp_pkhash_buf);
315 + dpp_pkhash_buf, alg_buf);
316 } else {
317 wpa_msg(hapd->msg_ctx, MSG_INFO, AP_STA_DISCONNECTED "%s", buf);
318 + hostapd_ubus_notify(hapd, "disassoc", sta->addr);
319
320 if (hapd->msg_ctx_parent &&
321 hapd->msg_ctx_parent != hapd->msg_ctx)
322 --- a/src/ap/wpa_auth_glue.c
323 +++ b/src/ap/wpa_auth_glue.c
324 @@ -269,6 +269,7 @@ static void hostapd_wpa_auth_psk_failure
325 struct hostapd_data *hapd = ctx;
326 wpa_msg(hapd->msg_ctx, MSG_INFO, AP_STA_POSSIBLE_PSK_MISMATCH MACSTR,
327 MAC2STR(addr));
328 + hostapd_ubus_notify(hapd, "key-mismatch", addr);
329 }
330
331
332 --- a/wpa_supplicant/Makefile
333 +++ b/wpa_supplicant/Makefile
334 @@ -194,6 +194,13 @@ ifdef CONFIG_EAPOL_TEST
335 CFLAGS += -Werror -DEAPOL_TEST
336 endif
337
338 +ifdef CONFIG_UBUS
339 +CFLAGS += -DUBUS_SUPPORT
340 +OBJS += ubus.o
341 +OBJS += ../src/utils/uloop.o
342 +LIBS += -lubox -lubus
343 +endif
344 +
345 ifdef CONFIG_CODE_COVERAGE
346 CFLAGS += -O0 -fprofile-arcs -ftest-coverage
347 LIBS += -lgcov
348 @@ -989,6 +996,9 @@ ifdef CONFIG_CTRL_IFACE_MIB
349 CFLAGS += -DCONFIG_CTRL_IFACE_MIB
350 endif
351 OBJS += ../src/ap/ctrl_iface_ap.o
352 +ifdef CONFIG_UBUS
353 +OBJS += ../src/ap/ubus.o
354 +endif
355 endif
356
357 CFLAGS += -DEAP_SERVER -DEAP_SERVER_IDENTITY
358 --- a/wpa_supplicant/wpa_supplicant.c
359 +++ b/wpa_supplicant/wpa_supplicant.c
360 @@ -7635,6 +7635,8 @@ struct wpa_supplicant * wpa_supplicant_a
361 }
362 #endif /* CONFIG_P2P */
363
364 + wpas_ubus_add_bss(wpa_s);
365 +
366 return wpa_s;
367 }
368
369 @@ -7661,6 +7663,8 @@ int wpa_supplicant_remove_iface(struct w
370 struct wpa_supplicant *parent = wpa_s->parent;
371 #endif /* CONFIG_MESH */
372
373 + wpas_ubus_free_bss(wpa_s);
374 +
375 /* Remove interface from the global list of interfaces */
376 prev = global->ifaces;
377 if (prev == wpa_s) {
378 @@ -8007,8 +8011,12 @@ int wpa_supplicant_run(struct wpa_global
379 eloop_register_signal_terminate(wpa_supplicant_terminate, global);
380 eloop_register_signal_reconfig(wpa_supplicant_reconfig, global);
381
382 + wpas_ubus_add(global);
383 +
384 eloop_run();
385
386 + wpas_ubus_free(global);
387 +
388 return 0;
389 }
390
391 --- a/wpa_supplicant/wpa_supplicant_i.h
392 +++ b/wpa_supplicant/wpa_supplicant_i.h
393 @@ -21,6 +21,7 @@
394 #include "config_ssid.h"
395 #include "wmm_ac.h"
396 #include "pasn/pasn_common.h"
397 +#include "ubus.h"
398
399 extern const char *const wpa_supplicant_version;
400 extern const char *const wpa_supplicant_license;
401 @@ -324,6 +325,8 @@ struct wpa_global {
402 #endif /* CONFIG_WIFI_DISPLAY */
403
404 struct psk_list_entry *add_psk; /* From group formation */
405 +
406 + struct ubus_object ubus_global;
407 };
408
409
410 @@ -655,6 +658,7 @@ struct wpa_supplicant {
411 unsigned char own_addr[ETH_ALEN];
412 unsigned char perm_addr[ETH_ALEN];
413 char ifname[100];
414 + struct wpas_ubus_bss ubus;
415 #ifdef CONFIG_MATCH_IFACE
416 int matched;
417 #endif /* CONFIG_MATCH_IFACE */
418 --- a/wpa_supplicant/wps_supplicant.c
419 +++ b/wpa_supplicant/wps_supplicant.c
420 @@ -33,6 +33,7 @@
421 #include "p2p/p2p.h"
422 #include "p2p_supplicant.h"
423 #include "wps_supplicant.h"
424 +#include "ubus.h"
425
426
427 #ifndef WPS_PIN_SCAN_IGNORE_SEL_REG
428 @@ -402,6 +403,8 @@ static int wpa_supplicant_wps_cred(void
429 wpa_hexdump_key(MSG_DEBUG, "WPS: Received Credential attribute",
430 cred->cred_attr, cred->cred_attr_len);
431
432 + wpas_ubus_notify(wpa_s, cred);
433 +
434 if (wpa_s->conf->wps_cred_processing == 1)
435 return 0;
436
437 --- a/hostapd/main.c
438 +++ b/hostapd/main.c
439 @@ -991,6 +991,7 @@ int main(int argc, char *argv[])
440 }
441
442 hostapd_global_ctrl_iface_init(&interfaces);
443 + hostapd_ubus_add(&interfaces);
444
445 if (hostapd_global_run(&interfaces, daemonize, pid_file)) {
446 wpa_printf(MSG_ERROR, "Failed to start eloop");
447 @@ -1000,6 +1001,7 @@ int main(int argc, char *argv[])
448 ret = 0;
449
450 out:
451 + hostapd_ubus_free(&interfaces);
452 hostapd_global_ctrl_iface_deinit(&interfaces);
453 /* Deinitialize all interfaces */
454 for (i = 0; i < interfaces.count; i++) {
455 --- a/wpa_supplicant/main.c
456 +++ b/wpa_supplicant/main.c
457 @@ -204,7 +204,7 @@ int main(int argc, char *argv[])
458
459 for (;;) {
460 c = getopt(argc, argv,
461 - "b:Bc:C:D:de:f:g:G:hH:i:I:KLMm:No:O:p:P:qsTtuv::W");
462 + "b:Bc:C:D:de:f:g:G:hH:i:I:KLMm:nNo:O:p:P:qsTtuv::W");
463 if (c < 0)
464 break;
465 switch (c) {
466 @@ -272,6 +272,9 @@ int main(int argc, char *argv[])
467 params.conf_p2p_dev = optarg;
468 break;
469 #endif /* CONFIG_P2P */
470 + case 'n':
471 + iface_count = 0;
472 + break;
473 case 'o':
474 params.override_driver = optarg;
475 break;
476 --- a/src/ap/rrm.c
477 +++ b/src/ap/rrm.c
478 @@ -89,6 +89,9 @@ static void hostapd_handle_beacon_report
479 return;
480 wpa_msg(hapd->msg_ctx, MSG_INFO, BEACON_RESP_RX MACSTR " %u %02x %s",
481 MAC2STR(addr), token, rep_mode, report);
482 + if (len < sizeof(struct rrm_measurement_beacon_report))
483 + return;
484 + hostapd_ubus_notify_beacon_report(hapd, addr, token, rep_mode, (struct rrm_measurement_beacon_report*) pos, len);
485 }
486
487
488 @@ -352,6 +355,9 @@ void hostapd_handle_radio_measurement(st
489 mgmt->u.action.u.rrm.action, MAC2STR(mgmt->sa));
490
491 switch (mgmt->u.action.u.rrm.action) {
492 + case WLAN_RRM_LINK_MEASUREMENT_REPORT:
493 + hostapd_ubus_handle_link_measurement(hapd, buf, len);
494 + break;
495 case WLAN_RRM_RADIO_MEASUREMENT_REPORT:
496 hostapd_handle_radio_msmt_report(hapd, buf, len);
497 break;
498 --- a/src/ap/vlan_init.c
499 +++ b/src/ap/vlan_init.c
500 @@ -22,6 +22,7 @@
501 static int vlan_if_add(struct hostapd_data *hapd, struct hostapd_vlan *vlan,
502 int existsok)
503 {
504 + bool vlan_exists = iface_exists(vlan->ifname);
505 int ret;
506 #ifdef CONFIG_WEP
507 int i;
508 @@ -36,7 +37,7 @@ static int vlan_if_add(struct hostapd_da
509 }
510 #endif /* CONFIG_WEP */
511
512 - if (!iface_exists(vlan->ifname))
513 + if (!vlan_exists)
514 ret = hostapd_vlan_if_add(hapd, vlan->ifname);
515 else if (!existsok)
516 return -1;
517 @@ -51,6 +52,9 @@ static int vlan_if_add(struct hostapd_da
518 if (hapd->wpa_auth)
519 ret = wpa_auth_ensure_group(hapd->wpa_auth, vlan->vlan_id);
520
521 + if (!ret && !vlan_exists)
522 + hostapd_ubus_add_vlan(hapd, vlan);
523 +
524 if (ret == 0)
525 return ret;
526
527 @@ -77,6 +81,8 @@ int vlan_if_remove(struct hostapd_data *
528 "WPA deinitialization for VLAN %d failed (%d)",
529 vlan->vlan_id, ret);
530
531 + hostapd_ubus_remove_vlan(hapd, vlan);
532 +
533 return hostapd_vlan_if_remove(hapd, vlan->ifname);
534 }
535
536 --- a/src/ap/dfs.c
537 +++ b/src/ap/dfs.c
538 @@ -1211,6 +1211,8 @@ int hostapd_dfs_pre_cac_expired(struct h
539 "freq=%d ht_enabled=%d chan_offset=%d chan_width=%d cf1=%d cf2=%d",
540 freq, ht_enabled, chan_offset, chan_width, cf1, cf2);
541
542 + hostapd_ubus_notify_radar_detected(iface, freq, chan_width, cf1, cf2);
543 +
544 /* Proceed only if DFS is not offloaded to the driver */
545 if (iface->drv_flags & WPA_DRIVER_FLAGS_DFS_OFFLOAD)
546 return 0;
547 --- a/src/ap/airtime_policy.c
548 +++ b/src/ap/airtime_policy.c
549 @@ -112,8 +112,14 @@ static void set_sta_weights(struct hosta
550 {
551 struct sta_info *sta;
552
553 - for (sta = hapd->sta_list; sta; sta = sta->next)
554 - sta_set_airtime_weight(hapd, sta, weight);
555 + for (sta = hapd->sta_list; sta; sta = sta->next) {
556 + unsigned int sta_weight = weight;
557 +
558 + if (sta->dyn_airtime_weight)
559 + sta_weight = (weight * sta->dyn_airtime_weight) / 256;
560 +
561 + sta_set_airtime_weight(hapd, sta, sta_weight);
562 + }
563 }
564
565
566 @@ -244,7 +250,10 @@ int airtime_policy_new_sta(struct hostap
567 unsigned int weight;
568
569 if (hapd->iconf->airtime_mode == AIRTIME_MODE_STATIC) {
570 - weight = get_weight_for_sta(hapd, sta->addr);
571 + if (sta->dyn_airtime_weight)
572 + weight = sta->dyn_airtime_weight;
573 + else
574 + weight = get_weight_for_sta(hapd, sta->addr);
575 if (weight)
576 return sta_set_airtime_weight(hapd, sta, weight);
577 }
578 --- a/src/ap/sta_info.h
579 +++ b/src/ap/sta_info.h
580 @@ -322,6 +322,7 @@ struct sta_info {
581 #endif /* CONFIG_TESTING_OPTIONS */
582 #ifdef CONFIG_AIRTIME_POLICY
583 unsigned int airtime_weight;
584 + unsigned int dyn_airtime_weight;
585 struct os_reltime backlogged_until;
586 #endif /* CONFIG_AIRTIME_POLICY */
587
588 --- a/src/ap/wnm_ap.c
589 +++ b/src/ap/wnm_ap.c
590 @@ -455,7 +455,8 @@ static void ieee802_11_rx_bss_trans_mgmt
591 MAC2STR(addr), reason, hex ? " neighbor=" : "", hex);
592 os_free(hex);
593
594 - ieee802_11_send_bss_trans_mgmt_request(hapd, addr, dialog_token);
595 + if (!hostapd_ubus_notify_bss_transition_query(hapd, addr, dialog_token, reason, pos, end - pos))
596 + ieee802_11_send_bss_trans_mgmt_request(hapd, addr, dialog_token);
597 }
598
599
600 @@ -477,7 +478,7 @@ static void ieee802_11_rx_bss_trans_mgmt
601 size_t len)
602 {
603 u8 dialog_token, status_code, bss_termination_delay;
604 - const u8 *pos, *end;
605 + const u8 *pos, *end, *target_bssid = NULL;
606 int enabled = hapd->conf->bss_transition;
607 struct sta_info *sta;
608
609 @@ -524,6 +525,7 @@ static void ieee802_11_rx_bss_trans_mgmt
610 wpa_printf(MSG_DEBUG, "WNM: not enough room for Target BSSID field");
611 return;
612 }
613 + target_bssid = pos;
614 sta->agreed_to_steer = 1;
615 eloop_cancel_timeout(ap_sta_reset_steer_flag_timer, hapd, sta);
616 eloop_register_timeout(2, 0, ap_sta_reset_steer_flag_timer,
617 @@ -543,6 +545,10 @@ static void ieee802_11_rx_bss_trans_mgmt
618 MAC2STR(addr), status_code, bss_termination_delay);
619 }
620
621 + hostapd_ubus_notify_bss_transition_response(hapd, sta->addr, dialog_token,
622 + status_code, bss_termination_delay,
623 + target_bssid, pos, end - pos);
624 +
625 wpa_hexdump(MSG_DEBUG, "WNM: BSS Transition Candidate List Entries",
626 pos, end - pos);
627 }
628 --- a/src/utils/eloop.c
629 +++ b/src/utils/eloop.c
630 @@ -77,6 +77,9 @@ struct eloop_sock_table {
631 struct eloop_data {
632 int max_sock;
633
634 + eloop_timeout_poll_handler timeout_poll_cb;
635 + eloop_poll_handler poll_cb;
636 +
637 size_t count; /* sum of all table counts */
638 #ifdef CONFIG_ELOOP_POLL
639 size_t max_pollfd_map; /* number of pollfds_map currently allocated */
640 @@ -1121,6 +1124,12 @@ void eloop_run(void)
641 os_reltime_sub(&timeout->time, &now, &tv);
642 else
643 tv.sec = tv.usec = 0;
644 + }
645 +
646 + if (eloop.timeout_poll_cb && eloop.timeout_poll_cb(&tv, !!timeout))
647 + timeout = (void *)1;
648 +
649 + if (timeout) {
650 #if defined(CONFIG_ELOOP_POLL) || defined(CONFIG_ELOOP_EPOLL)
651 timeout_ms = tv.sec * 1000 + tv.usec / 1000;
652 #endif /* defined(CONFIG_ELOOP_POLL) || defined(CONFIG_ELOOP_EPOLL) */
653 @@ -1190,7 +1199,8 @@ void eloop_run(void)
654 eloop.exceptions.changed = 0;
655
656 eloop_process_pending_signals();
657 -
658 + if (eloop.poll_cb)
659 + eloop.poll_cb();
660
661 /* check if some registered timeouts have occurred */
662 timeout = dl_list_first(&eloop.timeout, struct eloop_timeout,
663 @@ -1252,6 +1262,14 @@ out:
664 return;
665 }
666
667 +int eloop_register_cb(eloop_poll_handler poll_cb,
668 + eloop_timeout_poll_handler timeout_cb)
669 +{
670 + eloop.poll_cb = poll_cb;
671 + eloop.timeout_poll_cb = timeout_cb;
672 +
673 + return 0;
674 +}
675
676 void eloop_terminate(void)
677 {
678 --- a/src/utils/eloop.h
679 +++ b/src/utils/eloop.h
680 @@ -65,6 +65,9 @@ typedef void (*eloop_timeout_handler)(vo
681 */
682 typedef void (*eloop_signal_handler)(int sig, void *signal_ctx);
683
684 +typedef bool (*eloop_timeout_poll_handler)(struct os_reltime *tv, bool tv_set);
685 +typedef void (*eloop_poll_handler)(void);
686 +
687 /**
688 * eloop_init() - Initialize global event loop data
689 * Returns: 0 on success, -1 on failure
690 @@ -73,6 +76,9 @@ typedef void (*eloop_signal_handler)(int
691 */
692 int eloop_init(void);
693
694 +int eloop_register_cb(eloop_poll_handler poll_cb,
695 + eloop_timeout_poll_handler timeout_cb);
696 +
697 /**
698 * eloop_register_read_sock - Register handler for read events
699 * @sock: File descriptor number for the socket
700 @@ -320,6 +326,8 @@ int eloop_register_signal_reconfig(eloop
701 */
702 int eloop_sock_requeue(void);
703
704 +void eloop_add_uloop(void);
705 +
706 /**
707 * eloop_run - Start the event loop
708 *
709 --- /dev/null
710 +++ b/src/utils/uloop.c
711 @@ -0,0 +1,64 @@
712 +#include <libubox/uloop.h>
713 +#include "includes.h"
714 +#include "common.h"
715 +#include "eloop.h"
716 +
717 +static void eloop_uloop_event_cb(int sock, void *eloop_ctx, void *sock_ctx)
718 +{
719 +}
720 +
721 +static void eloop_uloop_fd_cb(struct uloop_fd *fd, unsigned int events)
722 +{
723 + unsigned int changed = events ^ fd->flags;
724 +
725 + if (changed & ULOOP_READ) {
726 + if (events & ULOOP_READ)
727 + eloop_register_sock(fd->fd, EVENT_TYPE_READ, eloop_uloop_event_cb, fd, fd);
728 + else
729 + eloop_unregister_sock(fd->fd, EVENT_TYPE_READ);
730 + }
731 +
732 + if (changed & ULOOP_WRITE) {
733 + if (events & ULOOP_WRITE)
734 + eloop_register_sock(fd->fd, EVENT_TYPE_WRITE, eloop_uloop_event_cb, fd, fd);
735 + else
736 + eloop_unregister_sock(fd->fd, EVENT_TYPE_WRITE);
737 + }
738 +}
739 +
740 +static bool uloop_timeout_poll_handler(struct os_reltime *tv, bool tv_set)
741 +{
742 + struct os_reltime tv_uloop;
743 + int timeout_ms = uloop_get_next_timeout();
744 +
745 + if (timeout_ms < 0)
746 + return false;
747 +
748 + tv_uloop.sec = timeout_ms / 1000;
749 + tv_uloop.usec = (timeout_ms % 1000) * 1000;
750 +
751 + if (!tv_set || os_reltime_before(&tv_uloop, tv)) {
752 + *tv = tv_uloop;
753 + return true;
754 + }
755 +
756 + return false;
757 +}
758 +
759 +static void uloop_poll_handler(void)
760 +{
761 + uloop_run_timeout(0);
762 +}
763 +
764 +void eloop_add_uloop(void)
765 +{
766 + static bool init_done = false;
767 +
768 + if (!init_done) {
769 + uloop_init();
770 + uloop_fd_set_cb = eloop_uloop_fd_cb;
771 + init_done = true;
772 + }
773 +
774 + eloop_register_cb(uloop_poll_handler, uloop_timeout_poll_handler);
775 +}