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"
24 struct radius_server_data;
25 @@ -122,6 +123,7 @@ struct hostapd_data {
26 struct hostapd_iface *iface;
27 struct hostapd_config *iconf;
28 struct hostapd_bss_config *conf;
29 + struct hostapd_ubus_bss ubus;
30 int interface_added; /* virtual interface added for this BSS */
31 unsigned int started:1;
32 unsigned int disabled:1;
33 @@ -370,6 +372,8 @@ struct hostapd_iface {
34 struct hostapd_config *conf;
35 char phy[16]; /* Name of the PHY (radio) */
37 + struct hostapd_ubus_iface ubus;
39 enum hostapd_iface_state {
40 HAPD_IFACE_UNINITIALIZED,
42 @@ -518,6 +522,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 @@ -309,6 +309,7 @@ static void hostapd_free_hapd_data(struc
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 @@ -1186,6 +1187,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 @@ -1600,7 +1603,7 @@ static enum nr_chan_width hostapd_get_nr
70 #endif /* NEED_AP_MLME */
73 -static void hostapd_set_own_neighbor_report(struct hostapd_data *hapd)
74 +void hostapd_set_own_neighbor_report(struct hostapd_data *hapd)
77 u16 capab = hostapd_own_capab_info(hapd);
78 @@ -1711,6 +1714,7 @@ static int hostapd_setup_interface_compl
82 + hostapd_ubus_add_iface(iface);
83 wpa_printf(MSG_DEBUG, "Completing interface initialization");
84 if (iface->conf->channel) {
86 @@ -1890,6 +1894,7 @@ dfs_offload:
89 wpa_printf(MSG_ERROR, "Interface initialization failed");
90 + hostapd_ubus_free_iface(iface);
91 hostapd_set_state(iface, HAPD_IFACE_DISABLED);
92 wpa_msg(hapd->msg_ctx, MSG_INFO, AP_EVENT_DISABLED);
94 @@ -2344,6 +2349,7 @@ void hostapd_interface_deinit_free(struc
95 (unsigned int) iface->conf->num_bss);
96 driver = iface->bss[0]->driver;
97 drv_priv = iface->bss[0]->drv_priv;
98 + hostapd_ubus_free_iface(iface);
99 hostapd_interface_deinit(iface);
100 wpa_printf(MSG_DEBUG, "%s: driver=%p drv_priv=%p -> hapd_deinit",
101 __func__, driver, drv_priv);
102 --- a/src/ap/ieee802_11.c
103 +++ b/src/ap/ieee802_11.c
104 @@ -1587,7 +1587,8 @@ ieee802_11_set_radius_info(struct hostap
107 static void handle_auth(struct hostapd_data *hapd,
108 - const struct ieee80211_mgmt *mgmt, size_t len)
109 + const struct ieee80211_mgmt *mgmt, size_t len,
110 + struct hostapd_frame_info *fi)
112 u16 auth_alg, auth_transaction, status_code;
113 u16 resp = WLAN_STATUS_SUCCESS;
114 @@ -1603,6 +1604,11 @@ static void handle_auth(struct hostapd_d
115 char *identity = NULL;
116 char *radius_cui = NULL;
118 + struct hostapd_ubus_request req = {
119 + .type = HOSTAPD_UBUS_AUTH_REQ,
120 + .mgmt_frame = mgmt,
124 if (len < IEEE80211_HDRLEN + sizeof(mgmt->u.auth)) {
125 wpa_printf(MSG_INFO, "handle_auth - too short payload (len=%lu)",
126 @@ -1757,6 +1763,12 @@ static void handle_auth(struct hostapd_d
127 resp = WLAN_STATUS_UNSPECIFIED_FAILURE;
130 + if (hostapd_ubus_handle_event(hapd, &req)) {
131 + wpa_printf(MSG_DEBUG, "Station " MACSTR " rejected by ubus handler.\n",
132 + MAC2STR(mgmt->sa));
133 + resp = WLAN_STATUS_UNSPECIFIED_FAILURE;
136 if (res == HOSTAPD_ACL_PENDING)
139 @@ -2870,7 +2882,7 @@ void fils_hlp_timeout(void *eloop_ctx, v
141 static void handle_assoc(struct hostapd_data *hapd,
142 const struct ieee80211_mgmt *mgmt, size_t len,
144 + int reassoc, struct hostapd_frame_info *fi)
146 u16 capab_info, listen_interval, seq_ctrl, fc;
147 u16 resp = WLAN_STATUS_SUCCESS, reply_res;
148 @@ -2884,6 +2896,11 @@ static void handle_assoc(struct hostapd_
151 #endif /* CONFIG_FILS */
152 + struct hostapd_ubus_request req = {
153 + .type = HOSTAPD_UBUS_ASSOC_REQ,
154 + .mgmt_frame = mgmt,
158 if (len < IEEE80211_HDRLEN + (reassoc ? sizeof(mgmt->u.reassoc_req) :
159 sizeof(mgmt->u.assoc_req))) {
160 @@ -3051,6 +3068,13 @@ static void handle_assoc(struct hostapd_
162 #endif /* CONFIG_MBO */
164 + if (hostapd_ubus_handle_event(hapd, &req)) {
165 + wpa_printf(MSG_DEBUG, "Station " MACSTR " assoc rejected by ubus handler.\n",
166 + MAC2STR(mgmt->sa));
167 + resp = WLAN_STATUS_UNSPECIFIED_FAILURE;
172 * sta->capability is used in check_assoc_ies() for RRM enabled
173 * capability element.
174 @@ -3258,6 +3282,7 @@ static void handle_disassoc(struct hosta
175 wpa_printf(MSG_DEBUG, "disassocation: STA=" MACSTR " reason_code=%d",
177 le_to_host16(mgmt->u.disassoc.reason_code));
178 + hostapd_ubus_notify(hapd, "disassoc", mgmt->sa);
180 sta = ap_get_sta(hapd, mgmt->sa);
182 @@ -3323,6 +3348,8 @@ static void handle_deauth(struct hostapd
184 MAC2STR(mgmt->sa), le_to_host16(mgmt->u.deauth.reason_code));
186 + hostapd_ubus_notify(hapd, "deauth", mgmt->sa);
188 sta = ap_get_sta(hapd, mgmt->sa);
190 wpa_msg(hapd->msg_ctx, MSG_DEBUG, "Station " MACSTR " trying "
191 @@ -3637,7 +3664,7 @@ int ieee802_11_mgmt(struct hostapd_data
194 if (stype == WLAN_FC_STYPE_PROBE_REQ) {
195 - handle_probe_req(hapd, mgmt, len, fi->ssi_signal);
196 + handle_probe_req(hapd, mgmt, len, fi);
200 @@ -3657,17 +3684,17 @@ int ieee802_11_mgmt(struct hostapd_data
202 case WLAN_FC_STYPE_AUTH:
203 wpa_printf(MSG_DEBUG, "mgmt::auth");
204 - handle_auth(hapd, mgmt, len);
205 + handle_auth(hapd, mgmt, len, fi);
208 case WLAN_FC_STYPE_ASSOC_REQ:
209 wpa_printf(MSG_DEBUG, "mgmt::assoc_req");
210 - handle_assoc(hapd, mgmt, len, 0);
211 + handle_assoc(hapd, mgmt, len, 0, fi);
214 case WLAN_FC_STYPE_REASSOC_REQ:
215 wpa_printf(MSG_DEBUG, "mgmt::reassoc_req");
216 - handle_assoc(hapd, mgmt, len, 1);
217 + handle_assoc(hapd, mgmt, len, 1, fi);
220 case WLAN_FC_STYPE_DISASSOC:
221 --- a/src/ap/beacon.c
222 +++ b/src/ap/beacon.c
223 @@ -716,7 +716,7 @@ void sta_track_claim_taxonomy_info(struc
225 void handle_probe_req(struct hostapd_data *hapd,
226 const struct ieee80211_mgmt *mgmt, size_t len,
228 + struct hostapd_frame_info *fi)
231 struct ieee802_11_elems elems;
232 @@ -725,9 +725,15 @@ void handle_probe_req(struct hostapd_dat
235 enum ssid_match_result res;
236 + int ssi_signal = fi->ssi_signal;
240 + struct hostapd_ubus_request req = {
241 + .type = HOSTAPD_UBUS_PROBE_REQ,
242 + .mgmt_frame = mgmt,
246 if (len < IEEE80211_HDRLEN)
248 @@ -894,6 +900,12 @@ void handle_probe_req(struct hostapd_dat
250 #endif /* CONFIG_P2P */
252 + if (hostapd_ubus_handle_event(hapd, &req)) {
253 + wpa_printf(MSG_DEBUG, "Probe request for " MACSTR " rejected by ubus handler.\n",
254 + MAC2STR(mgmt->sa));
258 /* TODO: verify that supp_rates contains at least one matching rate
259 * with AP configuration */
261 --- a/src/ap/beacon.h
262 +++ b/src/ap/beacon.h
263 @@ -14,7 +14,7 @@ struct ieee80211_mgmt;
265 void handle_probe_req(struct hostapd_data *hapd,
266 const struct ieee80211_mgmt *mgmt, size_t len,
268 + struct hostapd_frame_info *fi);
269 int ieee802_11_set_beacon(struct hostapd_data *hapd);
270 int ieee802_11_set_beacons(struct hostapd_iface *iface);
271 int ieee802_11_update_beacons(struct hostapd_iface *iface);
272 --- a/src/ap/drv_callbacks.c
273 +++ b/src/ap/drv_callbacks.c
274 @@ -116,6 +116,10 @@ int hostapd_notif_assoc(struct hostapd_d
275 u16 reason = WLAN_REASON_UNSPECIFIED;
276 u16 status = WLAN_STATUS_SUCCESS;
277 const u8 *p2p_dev_addr = NULL;
278 + struct hostapd_ubus_request req = {
279 + .type = HOSTAPD_UBUS_ASSOC_REQ,
285 @@ -195,6 +199,12 @@ int hostapd_notif_assoc(struct hostapd_d
289 + if (hostapd_ubus_handle_event(hapd, &req)) {
290 + wpa_printf(MSG_DEBUG, "Station " MACSTR " assoc rejected by ubus handler.\n",
291 + MAC2STR(req.addr));
297 wpabuf_free(sta->p2p_ie);
298 --- a/src/ap/sta_info.c
299 +++ b/src/ap/sta_info.c
300 @@ -404,6 +404,7 @@ void ap_handle_timer(void *eloop_ctx, vo
301 HOSTAPD_LEVEL_INFO, "deauthenticated due to "
302 "local deauth request");
303 ap_free_sta(hapd, sta);
304 + hostapd_ubus_notify(hapd, "local-deauth", sta->addr);
308 @@ -551,6 +552,7 @@ skip_poll:
310 WLAN_REASON_PREV_AUTH_NOT_VALID);
311 ap_free_sta(hapd, sta);
312 + hostapd_ubus_notify(hapd, "inactive-deauth", sta->addr);
316 @@ -1212,6 +1214,7 @@ void ap_sta_set_authorized(struct hostap
319 wpa_msg(hapd->msg_ctx, MSG_INFO, AP_STA_DISCONNECTED "%s", buf);
320 + hostapd_ubus_notify(hapd, "disassoc", sta->addr);
322 if (hapd->msg_ctx_parent &&
323 hapd->msg_ctx_parent != hapd->msg_ctx)
324 --- a/src/ap/wpa_auth_glue.c
325 +++ b/src/ap/wpa_auth_glue.c
326 @@ -175,6 +175,7 @@ static void hostapd_wpa_auth_psk_failure
327 struct hostapd_data *hapd = ctx;
328 wpa_msg(hapd->msg_ctx, MSG_INFO, AP_STA_POSSIBLE_PSK_MISMATCH MACSTR,
330 + hostapd_ubus_notify(hapd, "key-mismatch", addr);