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