3 @@ -171,6 +171,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 @@ -80,7 +81,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 @@ -154,6 +155,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 @@ -606,6 +608,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 @@ -395,6 +395,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 @@ -1417,6 +1418,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 @@ -1999,6 +2002,7 @@ static int hostapd_setup_interface_compl
73 + hostapd_ubus_add_iface(iface);
74 wpa_printf(MSG_DEBUG, "Completing interface initialization");
77 @@ -2196,6 +2200,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 @@ -2669,6 +2674,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 @@ -2327,13 +2327,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 @@ -2493,6 +2498,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 @@ -4166,7 +4178,7 @@ static void handle_assoc(struct hostapd_
130 int resp = WLAN_STATUS_SUCCESS;
134 + int left, i, ubus_resp;
135 struct sta_info *sta;
138 @@ -4379,6 +4391,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 @@ -4543,6 +4560,14 @@ static void handle_assoc(struct hostapd_
151 pos, left, rssi, omit_rsnxe);
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;
163 * Remove the station in case tranmission of a success response fails
164 * (the STA was added associated to the driver) or if the station was
165 @@ -4570,6 +4595,7 @@ static void handle_disassoc(struct hosta
166 wpa_printf(MSG_DEBUG, "disassocation: STA=" MACSTR " reason_code=%d",
168 le_to_host16(mgmt->u.disassoc.reason_code));
169 + hostapd_ubus_notify(hapd, "disassoc", mgmt->sa);
171 sta = ap_get_sta(hapd, mgmt->sa);
173 @@ -4636,6 +4662,8 @@ static void handle_deauth(struct hostapd
175 MAC2STR(mgmt->sa), le_to_host16(mgmt->u.deauth.reason_code));
177 + hostapd_ubus_notify(hapd, "deauth", mgmt->sa);
179 sta = ap_get_sta(hapd, mgmt->sa);
181 wpa_msg(hapd->msg_ctx, MSG_DEBUG, "Station " MACSTR " trying "
182 --- a/src/ap/beacon.c
183 +++ b/src/ap/beacon.c
184 @@ -814,6 +814,12 @@ void handle_probe_req(struct hostapd_dat
187 struct radius_sta rad_info;
188 + struct hostapd_ubus_request req = {
189 + .type = HOSTAPD_UBUS_PROBE_REQ,
190 + .mgmt_frame = mgmt,
191 + .ssi_signal = ssi_signal,
195 if (len < IEEE80211_HDRLEN)
197 @@ -996,6 +1002,12 @@ void handle_probe_req(struct hostapd_dat
199 #endif /* CONFIG_P2P */
201 + if (hostapd_ubus_handle_event(hapd, &req)) {
202 + wpa_printf(MSG_DEBUG, "Probe request for " MACSTR " rejected by ubus handler.\n",
203 + MAC2STR(mgmt->sa));
207 /* TODO: verify that supp_rates contains at least one matching rate
208 * with AP configuration */
210 --- a/src/ap/drv_callbacks.c
211 +++ b/src/ap/drv_callbacks.c
212 @@ -119,6 +119,10 @@ int hostapd_notif_assoc(struct hostapd_d
213 u16 reason = WLAN_REASON_UNSPECIFIED;
214 int status = WLAN_STATUS_SUCCESS;
215 const u8 *p2p_dev_addr = NULL;
216 + struct hostapd_ubus_request req = {
217 + .type = HOSTAPD_UBUS_ASSOC_REQ,
223 @@ -211,6 +215,12 @@ int hostapd_notif_assoc(struct hostapd_d
227 + if (hostapd_ubus_handle_event(hapd, &req)) {
228 + wpa_printf(MSG_DEBUG, "Station " MACSTR " assoc rejected by ubus handler.\n",
229 + MAC2STR(req.addr));
235 wpabuf_free(sta->p2p_ie);
236 --- a/src/ap/sta_info.c
237 +++ b/src/ap/sta_info.c
238 @@ -424,6 +424,7 @@ void ap_handle_timer(void *eloop_ctx, vo
239 HOSTAPD_LEVEL_INFO, "deauthenticated due to "
240 "local deauth request");
241 ap_free_sta(hapd, sta);
242 + hostapd_ubus_notify(hapd, "local-deauth", sta->addr);
246 @@ -579,6 +580,7 @@ skip_poll:
248 WLAN_REASON_PREV_AUTH_NOT_VALID);
249 ap_free_sta(hapd, sta);
250 + hostapd_ubus_notify(hapd, "inactive-deauth", sta->addr);
254 @@ -1294,6 +1296,7 @@ void ap_sta_set_authorized(struct hostap
255 buf, ip_addr, keyid_buf);
257 wpa_msg(hapd->msg_ctx, MSG_INFO, AP_STA_DISCONNECTED "%s", buf);
258 + hostapd_ubus_notify(hapd, "disassoc", sta->addr);
260 if (hapd->msg_ctx_parent &&
261 hapd->msg_ctx_parent != hapd->msg_ctx)
262 --- a/src/ap/wpa_auth_glue.c
263 +++ b/src/ap/wpa_auth_glue.c
264 @@ -259,6 +259,7 @@ static void hostapd_wpa_auth_psk_failure
265 struct hostapd_data *hapd = ctx;
266 wpa_msg(hapd->msg_ctx, MSG_INFO, AP_STA_POSSIBLE_PSK_MISMATCH MACSTR,
268 + hostapd_ubus_notify(hapd, "key-mismatch", addr);
272 --- a/wpa_supplicant/Makefile
273 +++ b/wpa_supplicant/Makefile
274 @@ -190,6 +190,12 @@ ifdef CONFIG_EAPOL_TEST
275 CFLAGS += -Werror -DEAPOL_TEST
279 +CFLAGS += -DUBUS_SUPPORT
281 +LIBS += -lubox -lubus
284 ifdef CONFIG_CODE_COVERAGE
285 CFLAGS += -O0 -fprofile-arcs -ftest-coverage
287 @@ -956,6 +962,9 @@ ifdef CONFIG_CTRL_IFACE_MIB
288 CFLAGS += -DCONFIG_CTRL_IFACE_MIB
290 OBJS += ../src/ap/ctrl_iface_ap.o
292 +OBJS += ../src/ap/ubus.o
296 CFLAGS += -DEAP_SERVER -DEAP_SERVER_IDENTITY
297 --- a/wpa_supplicant/wpa_supplicant.c
298 +++ b/wpa_supplicant/wpa_supplicant.c
299 @@ -6794,6 +6794,8 @@ struct wpa_supplicant * wpa_supplicant_a
301 #endif /* CONFIG_P2P */
303 + wpas_ubus_add_bss(wpa_s);
308 @@ -6820,6 +6822,8 @@ int wpa_supplicant_remove_iface(struct w
309 struct wpa_supplicant *parent = wpa_s->parent;
310 #endif /* CONFIG_MESH */
312 + wpas_ubus_free_bss(wpa_s);
314 /* Remove interface from the global list of interfaces */
315 prev = global->ifaces;
317 @@ -7123,8 +7127,12 @@ int wpa_supplicant_run(struct wpa_global
318 eloop_register_signal_terminate(wpa_supplicant_terminate, global);
319 eloop_register_signal_reconfig(wpa_supplicant_reconfig, global);
321 + wpas_ubus_add(global);
325 + wpas_ubus_free(global);
330 --- a/wpa_supplicant/wpa_supplicant_i.h
331 +++ b/wpa_supplicant/wpa_supplicant_i.h
333 #include "wps/wps_defs.h"
334 #include "config_ssid.h"
338 extern const char *const wpa_supplicant_version;
339 extern const char *const wpa_supplicant_license;
340 @@ -310,6 +311,8 @@ struct wpa_global {
341 #endif /* CONFIG_WIFI_DISPLAY */
343 struct psk_list_entry *add_psk; /* From group formation */
345 + struct ubus_object ubus_global;
349 @@ -520,6 +523,7 @@ struct wpa_supplicant {
350 unsigned char own_addr[ETH_ALEN];
351 unsigned char perm_addr[ETH_ALEN];
353 + struct wpas_ubus_bss ubus;
354 #ifdef CONFIG_MATCH_IFACE
356 #endif /* CONFIG_MATCH_IFACE */
357 --- a/wpa_supplicant/wps_supplicant.c
358 +++ b/wpa_supplicant/wps_supplicant.c
361 #include "p2p_supplicant.h"
362 #include "wps_supplicant.h"
366 #ifndef WPS_PIN_SCAN_IGNORE_SEL_REG
367 @@ -392,6 +393,8 @@ static int wpa_supplicant_wps_cred(void
368 wpa_hexdump_key(MSG_DEBUG, "WPS: Received Credential attribute",
369 cred->cred_attr, cred->cred_attr_len);
371 + wpas_ubus_notify(wpa_s, cred);
373 if (wpa_s->conf->wps_cred_processing == 1)
378 @@ -896,6 +896,7 @@ int main(int argc, char *argv[])
381 hostapd_global_ctrl_iface_init(&interfaces);
382 + hostapd_ubus_add(&interfaces);
384 if (hostapd_global_run(&interfaces, daemonize, pid_file)) {
385 wpa_printf(MSG_ERROR, "Failed to start eloop");
386 @@ -905,6 +906,7 @@ int main(int argc, char *argv[])
390 + hostapd_ubus_free(&interfaces);
391 hostapd_global_ctrl_iface_deinit(&interfaces);
392 /* Deinitialize all interfaces */
393 for (i = 0; i < interfaces.count; i++) {
394 --- a/wpa_supplicant/main.c
395 +++ b/wpa_supplicant/main.c
396 @@ -203,7 +203,7 @@ int main(int argc, char *argv[])
399 c = getopt(argc, argv,
400 - "b:Bc:C:D:de:f:g:G:hH:i:I:KLMm:No:O:p:P:qsTtuv::W");
401 + "b:Bc:C:D:de:f:g:G:hH:i:I:KLMm:nNo:O:p:P:qsTtuv::W");
405 @@ -271,6 +271,9 @@ int main(int argc, char *argv[])
406 params.conf_p2p_dev = optarg;
408 #endif /* CONFIG_P2P */
413 params.override_driver = optarg;
417 @@ -89,6 +89,9 @@ static void hostapd_handle_beacon_report
419 wpa_msg(hapd->msg_ctx, MSG_INFO, BEACON_RESP_RX MACSTR " %u %02x %s",
420 MAC2STR(addr), token, rep_mode, report);
421 + if (len < sizeof(struct rrm_measurement_beacon_report))
423 + hostapd_ubus_notify_beacon_report(hapd, addr, token, rep_mode, (struct rrm_measurement_beacon_report*) pos, len);