3 @@ -166,6 +166,11 @@ OBJS += ../src/common/hw_features_common
5 OBJS += ../src/eapol_auth/eapol_auth_sm.o
8 +CFLAGS += -DUBUS_SUPPORT
9 +OBJS += ../src/ap/ubus.o
10 +LIBS += -lubox -lubus
13 ifdef CONFIG_CODE_COVERAGE
14 CFLAGS += -O0 -fprofile-arcs -ftest-coverage
15 --- a/src/ap/hostapd.h
16 +++ b/src/ap/hostapd.h
18 #include "utils/list.h"
19 #include "ap_config.h"
20 #include "drivers/driver.h"
23 #define OCE_STA_CFON_ENABLED(hapd) \
24 ((hapd->conf->oce & OCE_STA_CFON) && \
25 @@ -92,7 +93,7 @@ struct hapd_interfaces {
26 #ifdef CONFIG_CTRL_IFACE_UDP
27 unsigned char ctrl_iface_cookie[CTRL_IFACE_COOKIE_LEN];
28 #endif /* CONFIG_CTRL_IFACE_UDP */
30 + struct ubus_object ubus;
33 enum hostapd_chan_status {
34 @@ -183,6 +184,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 @@ -673,6 +675,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 @@ -401,6 +401,7 @@ void hostapd_free_hapd_data(struct hosta
53 hapd->beacon_set_done = 0;
55 wpa_printf(MSG_DEBUG, "%s(%s)", __func__, hapd->conf->iface);
56 + hostapd_ubus_free_bss(hapd);
57 accounting_deinit(hapd);
58 hostapd_deinit_wpa(hapd);
60 @@ -1431,6 +1432,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);
64 + hostapd_ubus_add_bss(hapd);
69 @@ -2050,6 +2053,7 @@ static int hostapd_setup_interface_compl
73 + hostapd_ubus_add_iface(iface);
74 wpa_printf(MSG_DEBUG, "Completing interface initialization");
77 @@ -2248,6 +2252,7 @@ dfs_offload:
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);
85 @@ -2723,6 +2728,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 @@ -3573,13 +3573,18 @@ 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;
100 + int res, reply_res, ubus_resp;
102 const u8 *challenge = NULL;
103 u8 resp_ies[2 + WLAN_AUTH_CHALLENGE_LEN];
104 size_t resp_ies_len = 0;
106 struct radius_sta rad_info;
107 + struct hostapd_ubus_request req = {
108 + .type = HOSTAPD_UBUS_AUTH_REQ,
109 + .mgmt_frame = mgmt,
110 + .ssi_signal = rssi,
113 if (len < IEEE80211_HDRLEN + sizeof(mgmt->u.auth)) {
114 wpa_printf(MSG_INFO, "handle_auth - too short payload (len=%lu)",
115 @@ -3747,6 +3752,13 @@ static void handle_auth(struct hostapd_d
116 resp = WLAN_STATUS_UNSPECIFIED_FAILURE;
119 + ubus_resp = hostapd_ubus_handle_event(hapd, &req);
121 + wpa_printf(MSG_DEBUG, "Station " MACSTR " rejected by ubus handler.\n",
122 + MAC2STR(mgmt->sa));
123 + resp = ubus_resp > 0 ? (u16) ubus_resp : WLAN_STATUS_UNSPECIFIED_FAILURE;
126 if (res == HOSTAPD_ACL_PENDING)
129 @@ -5488,7 +5500,7 @@ static void handle_assoc(struct hostapd_
130 int resp = WLAN_STATUS_SUCCESS;
131 u16 reply_res = WLAN_STATUS_UNSPECIFIED_FAILURE;
134 + int left, i, ubus_resp;
135 struct sta_info *sta;
138 @@ -5701,6 +5713,11 @@ static void handle_assoc(struct hostapd_
141 #endif /* CONFIG_FILS */
142 + struct hostapd_ubus_request req = {
143 + .type = HOSTAPD_UBUS_ASSOC_REQ,
144 + .mgmt_frame = mgmt,
145 + .ssi_signal = rssi,
148 /* followed by SSID and Supported rates; and HT capabilities if 802.11n
150 @@ -5799,6 +5816,13 @@ static void handle_assoc(struct hostapd_
152 #endif /* CONFIG_FILS */
154 + ubus_resp = hostapd_ubus_handle_event(hapd, &req);
156 + wpa_printf(MSG_DEBUG, "Station " MACSTR " assoc rejected by ubus handler.\n",
157 + MAC2STR(mgmt->sa));
158 + resp = ubus_resp > 0 ? (u16) ubus_resp : WLAN_STATUS_UNSPECIFIED_FAILURE;
164 @@ -5892,6 +5916,7 @@ static void handle_disassoc(struct hosta
165 wpa_printf(MSG_DEBUG, "disassocation: STA=" MACSTR " reason_code=%d",
167 le_to_host16(mgmt->u.disassoc.reason_code));
168 + hostapd_ubus_notify(hapd, "disassoc", mgmt->sa);
170 sta = ap_get_sta(hapd, mgmt->sa);
172 @@ -5961,6 +5986,8 @@ static void handle_deauth(struct hostapd
173 /* Clear the PTKSA cache entries for PASN */
174 ptksa_cache_flush(hapd->ptksa, mgmt->sa, WPA_CIPHER_NONE);
176 + hostapd_ubus_notify(hapd, "deauth", mgmt->sa);
178 sta = ap_get_sta(hapd, mgmt->sa);
180 wpa_msg(hapd->msg_ctx, MSG_DEBUG, "Station " MACSTR " trying "
181 --- a/src/ap/beacon.c
182 +++ b/src/ap/beacon.c
183 @@ -919,6 +919,12 @@ void handle_probe_req(struct hostapd_dat
186 struct radius_sta rad_info;
187 + struct hostapd_ubus_request req = {
188 + .type = HOSTAPD_UBUS_PROBE_REQ,
189 + .mgmt_frame = mgmt,
190 + .ssi_signal = ssi_signal,
194 if (hapd->iconf->rssi_ignore_probe_request && ssi_signal &&
195 ssi_signal < hapd->iconf->rssi_ignore_probe_request)
196 @@ -1105,6 +1111,12 @@ void handle_probe_req(struct hostapd_dat
198 #endif /* CONFIG_P2P */
200 + if (hostapd_ubus_handle_event(hapd, &req)) {
201 + wpa_printf(MSG_DEBUG, "Probe request for " MACSTR " rejected by ubus handler.\n",
202 + MAC2STR(mgmt->sa));
206 /* TODO: verify that supp_rates contains at least one matching rate
207 * with AP configuration */
209 --- a/src/ap/drv_callbacks.c
210 +++ b/src/ap/drv_callbacks.c
211 @@ -145,6 +145,10 @@ int hostapd_notif_assoc(struct hostapd_d
212 u16 reason = WLAN_REASON_UNSPECIFIED;
213 int status = WLAN_STATUS_SUCCESS;
214 const u8 *p2p_dev_addr = NULL;
215 + struct hostapd_ubus_request req = {
216 + .type = HOSTAPD_UBUS_ASSOC_REQ,
222 @@ -237,6 +241,12 @@ int hostapd_notif_assoc(struct hostapd_d
226 + if (hostapd_ubus_handle_event(hapd, &req)) {
227 + wpa_printf(MSG_DEBUG, "Station " MACSTR " assoc rejected by ubus handler.\n",
228 + MAC2STR(req.addr));
234 wpabuf_free(sta->p2p_ie);
235 --- a/src/ap/sta_info.c
236 +++ b/src/ap/sta_info.c
237 @@ -460,6 +460,7 @@ void ap_handle_timer(void *eloop_ctx, vo
238 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
239 HOSTAPD_LEVEL_INFO, "deauthenticated due to "
240 "local deauth request");
241 + hostapd_ubus_notify(hapd, "local-deauth", sta->addr);
242 ap_free_sta(hapd, sta);
245 @@ -615,6 +616,7 @@ skip_poll:
246 mlme_deauthenticate_indication(
248 WLAN_REASON_PREV_AUTH_NOT_VALID);
249 + hostapd_ubus_notify(hapd, "inactive-deauth", sta->addr);
250 ap_free_sta(hapd, sta);
253 @@ -1298,12 +1300,25 @@ void ap_sta_set_authorized(struct hostap
254 sta->addr, authorized, dev_addr);
257 + static const char * const auth_algs[] = {
258 + [WLAN_AUTH_OPEN] = "open",
259 + [WLAN_AUTH_SHARED_KEY] = "shared",
260 + [WLAN_AUTH_FT] = "ft",
261 + [WLAN_AUTH_SAE] = "sae",
262 + [WLAN_AUTH_FILS_SK] = "fils-sk",
263 + [WLAN_AUTH_FILS_SK_PFS] = "fils-sk-pfs",
264 + [WLAN_AUTH_FILS_PK] = "fils-pk",
265 + [WLAN_AUTH_PASN] = "pasn",
267 + const char *auth_alg = NULL;
277 if (wpa_auth_get_ip_addr(sta->wpa_sm, ip_addr_buf) == 0) {
278 os_snprintf(ip_addr, sizeof(ip_addr),
279 @@ -1313,22 +1328,31 @@ void ap_sta_set_authorized(struct hostap
281 #endif /* CONFIG_P2P */
283 + if (sta->auth_alg < ARRAY_SIZE(auth_algs))
284 + auth_alg = auth_algs[sta->auth_alg];
287 + os_snprintf(alg_buf, sizeof(alg_buf),
288 + " auth_alg=%s", auth_alg);
290 keyid = ap_sta_wpa_get_keyid(hapd, sta);
292 os_snprintf(keyid_buf, sizeof(keyid_buf),
296 - wpa_msg(hapd->msg_ctx, MSG_INFO, AP_STA_CONNECTED "%s%s%s",
297 - buf, ip_addr, keyid_buf);
298 + hostapd_ubus_notify_authorized(hapd, sta, auth_alg);
299 + wpa_msg(hapd->msg_ctx, MSG_INFO, AP_STA_CONNECTED "%s%s%s%s",
300 + buf, ip_addr, keyid_buf, alg_buf);
302 if (hapd->msg_ctx_parent &&
303 hapd->msg_ctx_parent != hapd->msg_ctx)
304 wpa_msg_no_global(hapd->msg_ctx_parent, MSG_INFO,
305 - AP_STA_CONNECTED "%s%s%s",
306 - buf, ip_addr, keyid_buf);
307 + AP_STA_CONNECTED "%s%s%s%s",
308 + buf, ip_addr, keyid_buf, alg_buf);
310 wpa_msg(hapd->msg_ctx, MSG_INFO, AP_STA_DISCONNECTED "%s", buf);
311 + hostapd_ubus_notify(hapd, "disassoc", sta->addr);
313 if (hapd->msg_ctx_parent &&
314 hapd->msg_ctx_parent != hapd->msg_ctx)
315 --- a/src/ap/wpa_auth_glue.c
316 +++ b/src/ap/wpa_auth_glue.c
317 @@ -268,6 +268,7 @@ static void hostapd_wpa_auth_psk_failure
318 struct hostapd_data *hapd = ctx;
319 wpa_msg(hapd->msg_ctx, MSG_INFO, AP_STA_POSSIBLE_PSK_MISMATCH MACSTR,
321 + hostapd_ubus_notify(hapd, "key-mismatch", addr);
325 --- a/wpa_supplicant/Makefile
326 +++ b/wpa_supplicant/Makefile
327 @@ -183,6 +183,12 @@ ifdef CONFIG_EAPOL_TEST
328 CFLAGS += -Werror -DEAPOL_TEST
332 +CFLAGS += -DUBUS_SUPPORT
334 +LIBS += -lubox -lubus
337 ifdef CONFIG_CODE_COVERAGE
338 CFLAGS += -O0 -fprofile-arcs -ftest-coverage
340 @@ -977,6 +983,9 @@ ifdef CONFIG_CTRL_IFACE_MIB
341 CFLAGS += -DCONFIG_CTRL_IFACE_MIB
343 OBJS += ../src/ap/ctrl_iface_ap.o
345 +OBJS += ../src/ap/ubus.o
349 CFLAGS += -DEAP_SERVER -DEAP_SERVER_IDENTITY
350 --- a/wpa_supplicant/wpa_supplicant.c
351 +++ b/wpa_supplicant/wpa_supplicant.c
352 @@ -7285,6 +7285,8 @@ struct wpa_supplicant * wpa_supplicant_a
354 #endif /* CONFIG_P2P */
356 + wpas_ubus_add_bss(wpa_s);
361 @@ -7311,6 +7313,8 @@ int wpa_supplicant_remove_iface(struct w
362 struct wpa_supplicant *parent = wpa_s->parent;
363 #endif /* CONFIG_MESH */
365 + wpas_ubus_free_bss(wpa_s);
367 /* Remove interface from the global list of interfaces */
368 prev = global->ifaces;
370 @@ -7614,8 +7618,12 @@ int wpa_supplicant_run(struct wpa_global
371 eloop_register_signal_terminate(wpa_supplicant_terminate, global);
372 eloop_register_signal_reconfig(wpa_supplicant_reconfig, global);
374 + wpas_ubus_add(global);
378 + wpas_ubus_free(global);
383 --- a/wpa_supplicant/wpa_supplicant_i.h
384 +++ b/wpa_supplicant/wpa_supplicant_i.h
386 #include "wps/wps_defs.h"
387 #include "config_ssid.h"
391 extern const char *const wpa_supplicant_version;
392 extern const char *const wpa_supplicant_license;
393 @@ -323,6 +324,8 @@ struct wpa_global {
394 #endif /* CONFIG_WIFI_DISPLAY */
396 struct psk_list_entry *add_psk; /* From group formation */
398 + struct ubus_object ubus_global;
402 @@ -707,6 +710,7 @@ struct wpa_supplicant {
403 unsigned char own_addr[ETH_ALEN];
404 unsigned char perm_addr[ETH_ALEN];
406 + struct wpas_ubus_bss ubus;
407 #ifdef CONFIG_MATCH_IFACE
409 #endif /* CONFIG_MATCH_IFACE */
410 --- a/wpa_supplicant/wps_supplicant.c
411 +++ b/wpa_supplicant/wps_supplicant.c
414 #include "p2p_supplicant.h"
415 #include "wps_supplicant.h"
419 #ifndef WPS_PIN_SCAN_IGNORE_SEL_REG
420 @@ -391,6 +392,8 @@ static int wpa_supplicant_wps_cred(void
421 wpa_hexdump_key(MSG_DEBUG, "WPS: Received Credential attribute",
422 cred->cred_attr, cred->cred_attr_len);
424 + wpas_ubus_notify(wpa_s, cred);
426 if (wpa_s->conf->wps_cred_processing == 1)
431 @@ -897,6 +897,7 @@ int main(int argc, char *argv[])
434 hostapd_global_ctrl_iface_init(&interfaces);
435 + hostapd_ubus_add(&interfaces);
437 if (hostapd_global_run(&interfaces, daemonize, pid_file)) {
438 wpa_printf(MSG_ERROR, "Failed to start eloop");
439 @@ -906,6 +907,7 @@ int main(int argc, char *argv[])
443 + hostapd_ubus_free(&interfaces);
444 hostapd_global_ctrl_iface_deinit(&interfaces);
445 /* Deinitialize all interfaces */
446 for (i = 0; i < interfaces.count; i++) {
447 --- a/wpa_supplicant/main.c
448 +++ b/wpa_supplicant/main.c
449 @@ -204,7 +204,7 @@ int main(int argc, char *argv[])
452 c = getopt(argc, argv,
453 - "b:Bc:C:D:de:f:g:G:hH:i:I:KLMm:No:O:p:P:qsTtuv::W");
454 + "b:Bc:C:D:de:f:g:G:hH:i:I:KLMm:nNo:O:p:P:qsTtuv::W");
458 @@ -272,6 +272,9 @@ int main(int argc, char *argv[])
459 params.conf_p2p_dev = optarg;
461 #endif /* CONFIG_P2P */
466 params.override_driver = optarg;
470 @@ -89,6 +89,9 @@ static void hostapd_handle_beacon_report
472 wpa_msg(hapd->msg_ctx, MSG_INFO, BEACON_RESP_RX MACSTR " %u %02x %s",
473 MAC2STR(addr), token, rep_mode, report);
474 + if (len < sizeof(struct rrm_measurement_beacon_report))
476 + hostapd_ubus_notify_beacon_report(hapd, addr, token, rep_mode, (struct rrm_measurement_beacon_report*) pos, len);
480 @@ -352,6 +355,9 @@ void hostapd_handle_radio_measurement(st
481 mgmt->u.action.u.rrm.action, MAC2STR(mgmt->sa));
483 switch (mgmt->u.action.u.rrm.action) {
484 + case WLAN_RRM_LINK_MEASUREMENT_REPORT:
485 + hostapd_ubus_handle_link_measurement(hapd, buf, len);
487 case WLAN_RRM_RADIO_MEASUREMENT_REPORT:
488 hostapd_handle_radio_msmt_report(hapd, buf, len);
490 --- a/src/ap/vlan_init.c
491 +++ b/src/ap/vlan_init.c
493 static int vlan_if_add(struct hostapd_data *hapd, struct hostapd_vlan *vlan,
496 + bool vlan_exists = iface_exists(vlan->ifname);
500 @@ -36,7 +37,7 @@ static int vlan_if_add(struct hostapd_da
502 #endif /* CONFIG_WEP */
504 - if (!iface_exists(vlan->ifname))
506 ret = hostapd_vlan_if_add(hapd, vlan->ifname);
509 @@ -51,6 +52,9 @@ static int vlan_if_add(struct hostapd_da
511 ret = wpa_auth_ensure_group(hapd->wpa_auth, vlan->vlan_id);
513 + if (!ret && !vlan_exists)
514 + hostapd_ubus_add_vlan(hapd, vlan);
519 @@ -77,6 +81,8 @@ int vlan_if_remove(struct hostapd_data *
520 "WPA deinitialization for VLAN %d failed (%d)",
523 + hostapd_ubus_remove_vlan(hapd, vlan);
525 return hostapd_vlan_if_remove(hapd, vlan->ifname);
530 @@ -1203,6 +1203,8 @@ int hostapd_dfs_pre_cac_expired(struct h
531 "freq=%d ht_enabled=%d chan_offset=%d chan_width=%d cf1=%d cf2=%d",
532 freq, ht_enabled, chan_offset, chan_width, cf1, cf2);
534 + hostapd_ubus_notify_radar_detected(iface, freq, chan_width, cf1, cf2);
536 /* Proceed only if DFS is not offloaded to the driver */
537 if (iface->drv_flags & WPA_DRIVER_FLAGS_DFS_OFFLOAD)
539 --- a/src/ap/airtime_policy.c
540 +++ b/src/ap/airtime_policy.c
541 @@ -112,8 +112,14 @@ static void set_sta_weights(struct hosta
543 struct sta_info *sta;
545 - for (sta = hapd->sta_list; sta; sta = sta->next)
546 - sta_set_airtime_weight(hapd, sta, weight);
547 + for (sta = hapd->sta_list; sta; sta = sta->next) {
548 + unsigned int sta_weight = weight;
550 + if (sta->dyn_airtime_weight)
551 + sta_weight = (weight * sta->dyn_airtime_weight) / 256;
553 + sta_set_airtime_weight(hapd, sta, sta_weight);
558 @@ -244,7 +250,10 @@ int airtime_policy_new_sta(struct hostap
561 if (hapd->iconf->airtime_mode == AIRTIME_MODE_STATIC) {
562 - weight = get_weight_for_sta(hapd, sta->addr);
563 + if (sta->dyn_airtime_weight)
564 + weight = sta->dyn_airtime_weight;
566 + weight = get_weight_for_sta(hapd, sta->addr);
568 return sta_set_airtime_weight(hapd, sta, weight);
570 --- a/src/ap/sta_info.h
571 +++ b/src/ap/sta_info.h
572 @@ -328,6 +328,7 @@ struct sta_info {
573 #endif /* CONFIG_TESTING_OPTIONS */
574 #ifdef CONFIG_AIRTIME_POLICY
575 unsigned int airtime_weight;
576 + unsigned int dyn_airtime_weight;
577 struct os_reltime backlogged_until;
578 #endif /* CONFIG_AIRTIME_POLICY */
580 --- a/src/ap/wnm_ap.c
581 +++ b/src/ap/wnm_ap.c
582 @@ -455,7 +455,8 @@ static void ieee802_11_rx_bss_trans_mgmt
583 MAC2STR(addr), reason, hex ? " neighbor=" : "", hex);
586 - ieee802_11_send_bss_trans_mgmt_request(hapd, addr, dialog_token);
587 + if (!hostapd_ubus_notify_bss_transition_query(hapd, addr, dialog_token, reason, pos, end - pos))
588 + ieee802_11_send_bss_trans_mgmt_request(hapd, addr, dialog_token);
592 @@ -477,7 +478,7 @@ static void ieee802_11_rx_bss_trans_mgmt
595 u8 dialog_token, status_code, bss_termination_delay;
596 - const u8 *pos, *end;
597 + const u8 *pos, *end, *target_bssid = NULL;
598 int enabled = hapd->conf->bss_transition;
599 struct sta_info *sta;
601 @@ -524,6 +525,7 @@ static void ieee802_11_rx_bss_trans_mgmt
602 wpa_printf(MSG_DEBUG, "WNM: not enough room for Target BSSID field");
605 + target_bssid = pos;
606 sta->agreed_to_steer = 1;
607 eloop_cancel_timeout(ap_sta_reset_steer_flag_timer, hapd, sta);
608 eloop_register_timeout(2, 0, ap_sta_reset_steer_flag_timer,
609 @@ -543,6 +545,10 @@ static void ieee802_11_rx_bss_trans_mgmt
610 MAC2STR(addr), status_code, bss_termination_delay);
613 + hostapd_ubus_notify_bss_transition_response(hapd, sta->addr, dialog_token,
614 + status_code, bss_termination_delay,
615 + target_bssid, pos, end - pos);
617 wpa_hexdump(MSG_DEBUG, "WNM: BSS Transition Candidate List Entries",