3 @@ -165,6 +165,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 @@ -72,6 +73,8 @@ struct hapd_interfaces {
27 struct dpp_global *dpp;
28 #endif /* CONFIG_DPP */
29 + struct ubus_object ubus;
33 enum hostapd_chan_status {
34 @@ -145,6 +148,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 @@ -580,6 +584,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 @@ -380,6 +380,7 @@ static void hostapd_free_hapd_data(struc
53 hapd->beacon_set_done = 0;
55 wpa_printf(MSG_DEBUG, "%s(%s)", __func__, hapd->conf->iface);
56 + hostapd_ubus_free_bss(hapd);
57 iapp_deinit(hapd->iapp);
59 accounting_deinit(hapd);
60 @@ -1377,6 +1378,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 @@ -1891,6 +1894,7 @@ static int hostapd_setup_interface_compl
73 + hostapd_ubus_add_iface(iface);
74 wpa_printf(MSG_DEBUG, "Completing interface initialization");
75 if (iface->conf->channel) {
77 @@ -2087,6 +2091,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 @@ -2562,6 +2567,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 @@ -2032,7 +2032,7 @@ 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 u32 session_timeout, acct_interim_interval;
104 @@ -2043,6 +2043,11 @@ static void handle_auth(struct hostapd_d
105 char *identity = NULL;
106 char *radius_cui = NULL;
108 + struct hostapd_ubus_request req = {
109 + .type = HOSTAPD_UBUS_AUTH_REQ,
110 + .mgmt_frame = mgmt,
111 + .ssi_signal = rssi,
114 if (len < IEEE80211_HDRLEN + sizeof(mgmt->u.auth)) {
115 wpa_printf(MSG_INFO, "handle_auth - too short payload (len=%lu)",
116 @@ -2204,6 +2209,13 @@ static void handle_auth(struct hostapd_d
117 resp = WLAN_STATUS_UNSPECIFIED_FAILURE;
120 + ubus_resp = hostapd_ubus_handle_event(hapd, &req);
122 + wpa_printf(MSG_DEBUG, "Station " MACSTR " rejected by ubus handler.\n",
123 + MAC2STR(mgmt->sa));
124 + resp = ubus_resp > 0 ? (u16) ubus_resp : WLAN_STATUS_UNSPECIFIED_FAILURE;
127 if (res == HOSTAPD_ACL_PENDING)
130 @@ -3862,7 +3874,7 @@ static void handle_assoc(struct hostapd_
131 u16 capab_info, listen_interval, seq_ctrl, fc;
132 u16 resp = WLAN_STATUS_SUCCESS, reply_res;
135 + int left, i, ubus_resp;
136 struct sta_info *sta;
138 struct hostapd_sta_wpa_psk_short *psk = NULL;
139 @@ -3871,6 +3883,11 @@ static void handle_assoc(struct hostapd_
142 #endif /* CONFIG_FILS */
143 + struct hostapd_ubus_request req = {
144 + .type = HOSTAPD_UBUS_ASSOC_REQ,
145 + .mgmt_frame = mgmt,
146 + .ssi_signal = rssi,
149 if (len < IEEE80211_HDRLEN + (reassoc ? sizeof(mgmt->u.reassoc_req) :
150 sizeof(mgmt->u.assoc_req))) {
151 @@ -4050,6 +4067,14 @@ static void handle_assoc(struct hostapd_
153 #endif /* CONFIG_MBO */
155 + ubus_resp = hostapd_ubus_handle_event(hapd, &req);
157 + wpa_printf(MSG_DEBUG, "Station " MACSTR " assoc rejected by ubus handler.\n",
158 + MAC2STR(mgmt->sa));
159 + resp = ubus_resp > 0 ? (u16) ubus_resp : WLAN_STATUS_UNSPECIFIED_FAILURE;
164 * sta->capability is used in check_assoc_ies() for RRM enabled
165 * capability element.
166 @@ -4277,6 +4302,7 @@ static void handle_disassoc(struct hosta
167 wpa_printf(MSG_DEBUG, "disassocation: STA=" MACSTR " reason_code=%d",
169 le_to_host16(mgmt->u.disassoc.reason_code));
170 + hostapd_ubus_notify(hapd, "disassoc", mgmt->sa);
172 sta = ap_get_sta(hapd, mgmt->sa);
174 @@ -4342,6 +4368,8 @@ static void handle_deauth(struct hostapd
176 MAC2STR(mgmt->sa), le_to_host16(mgmt->u.deauth.reason_code));
178 + hostapd_ubus_notify(hapd, "deauth", mgmt->sa);
180 sta = ap_get_sta(hapd, mgmt->sa);
182 wpa_msg(hapd->msg_ctx, MSG_DEBUG, "Station " MACSTR " trying "
183 --- a/src/ap/beacon.c
184 +++ b/src/ap/beacon.c
185 @@ -746,6 +746,12 @@ void handle_probe_req(struct hostapd_dat
186 struct hostapd_sta_wpa_psk_short *psk = NULL;
187 char *identity = NULL;
188 char *radius_cui = NULL;
189 + struct hostapd_ubus_request req = {
190 + .type = HOSTAPD_UBUS_PROBE_REQ,
191 + .mgmt_frame = mgmt,
192 + .ssi_signal = ssi_signal,
196 if (len < IEEE80211_HDRLEN)
198 @@ -923,6 +929,12 @@ void handle_probe_req(struct hostapd_dat
200 #endif /* CONFIG_P2P */
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));
208 /* TODO: verify that supp_rates contains at least one matching rate
209 * with AP configuration */
211 --- a/src/ap/drv_callbacks.c
212 +++ b/src/ap/drv_callbacks.c
213 @@ -118,6 +118,10 @@ int hostapd_notif_assoc(struct hostapd_d
214 u16 reason = WLAN_REASON_UNSPECIFIED;
215 u16 status = WLAN_STATUS_SUCCESS;
216 const u8 *p2p_dev_addr = NULL;
217 + struct hostapd_ubus_request req = {
218 + .type = HOSTAPD_UBUS_ASSOC_REQ,
224 @@ -210,6 +214,12 @@ int hostapd_notif_assoc(struct hostapd_d
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));
236 wpabuf_free(sta->p2p_ie);
237 --- a/src/ap/sta_info.c
238 +++ b/src/ap/sta_info.c
239 @@ -424,6 +424,7 @@ void ap_handle_timer(void *eloop_ctx, vo
240 HOSTAPD_LEVEL_INFO, "deauthenticated due to "
241 "local deauth request");
242 ap_free_sta(hapd, sta);
243 + hostapd_ubus_notify(hapd, "local-deauth", sta->addr);
247 @@ -578,6 +579,7 @@ skip_poll:
249 WLAN_REASON_PREV_AUTH_NOT_VALID);
250 ap_free_sta(hapd, sta);
251 + hostapd_ubus_notify(hapd, "inactive-deauth", sta->addr);
255 @@ -1284,6 +1286,7 @@ void ap_sta_set_authorized(struct hostap
256 buf, ip_addr, keyid_buf);
258 wpa_msg(hapd->msg_ctx, MSG_INFO, AP_STA_DISCONNECTED "%s", buf);
259 + hostapd_ubus_notify(hapd, "disassoc", sta->addr);
261 if (hapd->msg_ctx_parent &&
262 hapd->msg_ctx_parent != hapd->msg_ctx)
263 --- a/src/ap/wpa_auth_glue.c
264 +++ b/src/ap/wpa_auth_glue.c
265 @@ -185,6 +185,7 @@ static void hostapd_wpa_auth_psk_failure
266 struct hostapd_data *hapd = ctx;
267 wpa_msg(hapd->msg_ctx, MSG_INFO, AP_STA_POSSIBLE_PSK_MISMATCH MACSTR,
269 + hostapd_ubus_notify(hapd, "key-mismatch", addr);
273 --- a/wpa_supplicant/Makefile
274 +++ b/wpa_supplicant/Makefile
275 @@ -188,6 +188,12 @@ ifdef CONFIG_EAPOL_TEST
276 CFLAGS += -Werror -DEAPOL_TEST
280 +CFLAGS += -DUBUS_SUPPORT
282 +LIBS += -lubox -lubus
285 ifdef CONFIG_CODE_COVERAGE
286 CFLAGS += -O0 -fprofile-arcs -ftest-coverage
288 @@ -945,6 +951,9 @@ endif
289 ifdef CONFIG_IEEE80211AX
290 OBJS += ../src/ap/ieee802_11_he.o
293 +OBJS += ../src/ap/ubus.o
297 CFLAGS += -DCONFIG_WNM_AP
298 --- a/wpa_supplicant/wpa_supplicant.c
299 +++ b/wpa_supplicant/wpa_supplicant.c
300 @@ -6297,6 +6297,8 @@ struct wpa_supplicant * wpa_supplicant_a
302 #endif /* CONFIG_P2P */
304 + wpas_ubus_add_bss(wpa_s);
309 @@ -6323,6 +6325,8 @@ int wpa_supplicant_remove_iface(struct w
310 struct wpa_supplicant *parent = wpa_s->parent;
311 #endif /* CONFIG_MESH */
313 + wpas_ubus_free_bss(wpa_s);
315 /* Remove interface from the global list of interfaces */
316 prev = global->ifaces;
318 @@ -6520,6 +6524,8 @@ struct wpa_global * wpa_supplicant_init(
319 if (params->override_ctrl_interface)
320 global->params.override_ctrl_interface =
321 os_strdup(params->override_ctrl_interface);
323 + global->params.name = os_strdup(params->name);
324 #ifdef CONFIG_MATCH_IFACE
325 global->params.match_iface_count = params->match_iface_count;
326 if (params->match_iface_count) {
327 @@ -6626,8 +6632,12 @@ int wpa_supplicant_run(struct wpa_global
328 eloop_register_signal_terminate(wpa_supplicant_terminate, global);
329 eloop_register_signal_reconfig(wpa_supplicant_reconfig, global);
331 + wpas_ubus_add(global);
335 + wpas_ubus_free(global);
340 @@ -6687,6 +6697,7 @@ void wpa_supplicant_deinit(struct wpa_gl
341 #ifdef CONFIG_MATCH_IFACE
342 os_free(global->params.match_ifaces);
343 #endif /* CONFIG_MATCH_IFACE */
344 + os_free(global->params.name);
346 os_free(global->params.conf_p2p_dev);
347 #endif /* CONFIG_P2P */
348 --- a/wpa_supplicant/wpa_supplicant_i.h
349 +++ b/wpa_supplicant/wpa_supplicant_i.h
351 #include "wps/wps_defs.h"
352 #include "config_ssid.h"
356 extern const char *const wpa_supplicant_version;
357 extern const char *const wpa_supplicant_license;
358 @@ -246,6 +247,8 @@ struct wpa_params {
360 int match_iface_count;
361 #endif /* CONFIG_MATCH_IFACE */
366 struct p2p_srv_bonjour {
367 @@ -306,6 +309,8 @@ struct wpa_global {
368 #endif /* CONFIG_WIFI_DISPLAY */
370 struct psk_list_entry *add_psk; /* From group formation */
372 + struct ubus_object ubus_global;
376 @@ -506,6 +511,7 @@ struct wpa_supplicant {
377 unsigned char own_addr[ETH_ALEN];
378 unsigned char perm_addr[ETH_ALEN];
380 + struct wpas_ubus_bss ubus;
381 #ifdef CONFIG_MATCH_IFACE
383 #endif /* CONFIG_MATCH_IFACE */
384 --- a/wpa_supplicant/wps_supplicant.c
385 +++ b/wpa_supplicant/wps_supplicant.c
388 #include "p2p_supplicant.h"
389 #include "wps_supplicant.h"
393 #ifndef WPS_PIN_SCAN_IGNORE_SEL_REG
394 @@ -388,6 +389,8 @@ static int wpa_supplicant_wps_cred(void
395 wpa_hexdump_key(MSG_DEBUG, "WPS: Received Credential attribute",
396 cred->cred_attr, cred->cred_attr_len);
398 + wpas_ubus_notify(wpa_s, cred);
400 if (wpa_s->conf->wps_cred_processing == 1)
405 @@ -688,7 +688,7 @@ int main(int argc, char *argv[])
406 wpa_supplicant_event = hostapd_wpa_event;
407 wpa_supplicant_event_global = hostapd_wpa_event_global;
409 - c = getopt(argc, argv, "b:Bde:f:hi:KP:sSTtu:g:G:v::");
410 + c = getopt(argc, argv, "b:Bde:f:hi:KP:sSTtu:g:G:n:v::");
414 @@ -763,6 +763,8 @@ int main(int argc, char *argv[])
415 if (hostapd_get_interface_names(&if_names,
416 &if_names_size, optarg))
419 + interfaces.name = optarg;
423 @@ -894,6 +896,7 @@ int main(int argc, char *argv[])
426 hostapd_global_ctrl_iface_init(&interfaces);
427 + hostapd_ubus_add(&interfaces);
429 if (hostapd_global_run(&interfaces, daemonize, pid_file)) {
430 wpa_printf(MSG_ERROR, "Failed to start eloop");
431 @@ -903,6 +906,7 @@ int main(int argc, char *argv[])
435 + hostapd_ubus_free(&interfaces);
436 hostapd_global_ctrl_iface_deinit(&interfaces);
437 /* Deinitialize all interfaces */
438 for (i = 0; i < interfaces.count; i++) {
439 --- a/wpa_supplicant/main.c
440 +++ b/wpa_supplicant/main.c
441 @@ -203,7 +203,7 @@ int main(int argc, char *argv[])
444 c = getopt(argc, argv,
445 - "b:Bc:C:D:de:f:g:G:hH:i:I:KLMm:No:O:p:P:qsTtuv::W");
446 + "b:Bc:C:D:de:f:g:G:hH:i:I:KLMm:n:No:O:p:P:qsTtuv::W");
450 @@ -271,6 +271,10 @@ int main(int argc, char *argv[])
451 params.conf_p2p_dev = optarg;
453 #endif /* CONFIG_P2P */
455 + params.name = optarg;
459 params.override_driver = optarg;