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