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 @@ -119,6 +120,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 @@ -328,6 +330,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 --- a/src/ap/hostapd.c
43 +++ b/src/ap/hostapd.c
44 @@ -302,6 +302,7 @@ static void hostapd_free_hapd_data(struc
47 wpa_printf(MSG_DEBUG, "%s(%s)", __func__, hapd->conf->iface);
48 + hostapd_ubus_free_bss(hapd);
49 iapp_deinit(hapd->iapp);
51 accounting_deinit(hapd);
52 @@ -1160,6 +1161,8 @@ static int hostapd_setup_bss(struct host
53 if (hapd->driver && hapd->driver->set_operstate)
54 hapd->driver->set_operstate(hapd->drv_priv, 1);
56 + hostapd_ubus_add_bss(hapd);
61 @@ -1683,6 +1686,7 @@ static int hostapd_setup_interface_compl
65 + hostapd_ubus_add_iface(iface);
66 wpa_printf(MSG_DEBUG, "Completing interface initialization");
67 if (iface->conf->channel) {
69 @@ -1862,6 +1866,7 @@ dfs_offload:
72 wpa_printf(MSG_ERROR, "Interface initialization failed");
73 + hostapd_ubus_free_iface(iface);
74 hostapd_set_state(iface, HAPD_IFACE_DISABLED);
75 wpa_msg(hapd->msg_ctx, MSG_INFO, AP_EVENT_DISABLED);
77 @@ -2310,6 +2315,7 @@ void hostapd_interface_deinit_free(struc
78 (unsigned int) iface->conf->num_bss);
79 driver = iface->bss[0]->driver;
80 drv_priv = iface->bss[0]->drv_priv;
81 + hostapd_ubus_free_iface(iface);
82 hostapd_interface_deinit(iface);
83 wpa_printf(MSG_DEBUG, "%s: driver=%p drv_priv=%p -> hapd_deinit",
84 __func__, driver, drv_priv);
85 --- a/src/ap/ieee802_11.c
86 +++ b/src/ap/ieee802_11.c
87 @@ -1293,7 +1293,8 @@ void ieee802_11_finish_fils_auth(struct
90 static void handle_auth(struct hostapd_data *hapd,
91 - const struct ieee80211_mgmt *mgmt, size_t len)
92 + const struct ieee80211_mgmt *mgmt, size_t len,
93 + struct hostapd_frame_info *fi)
95 u16 auth_alg, auth_transaction, status_code;
96 u16 resp = WLAN_STATUS_SUCCESS;
97 @@ -1309,6 +1310,11 @@ static void handle_auth(struct hostapd_d
98 char *identity = NULL;
99 char *radius_cui = NULL;
101 + struct hostapd_ubus_request req = {
102 + .type = HOSTAPD_UBUS_AUTH_REQ,
103 + .mgmt_frame = mgmt,
107 os_memset(&vlan_id, 0, sizeof(vlan_id));
109 @@ -1466,6 +1472,14 @@ static void handle_auth(struct hostapd_d
110 resp = WLAN_STATUS_UNSPECIFIED_FAILURE;
114 + if (hostapd_ubus_handle_event(hapd, &req)) {
115 + wpa_printf(MSG_DEBUG, "Station " MACSTR " rejected by ubus handler.\n",
116 + MAC2STR(mgmt->sa));
117 + resp = WLAN_STATUS_UNSPECIFIED_FAILURE;
121 if (res == HOSTAPD_ACL_PENDING) {
122 wpa_printf(MSG_DEBUG, "Authentication frame from " MACSTR
123 " waiting for an external authentication",
124 @@ -2391,7 +2405,7 @@ static u16 send_assoc_resp(struct hostap
126 static void handle_assoc(struct hostapd_data *hapd,
127 const struct ieee80211_mgmt *mgmt, size_t len,
129 + int reassoc, struct hostapd_frame_info *fi)
131 u16 capab_info, listen_interval, seq_ctrl, fc;
132 u16 resp = WLAN_STATUS_SUCCESS, reply_res;
133 @@ -2399,6 +2413,11 @@ static void handle_assoc(struct hostapd_
135 struct sta_info *sta;
137 + struct hostapd_ubus_request req = {
138 + .type = HOSTAPD_UBUS_ASSOC_REQ,
139 + .mgmt_frame = mgmt,
143 if (len < IEEE80211_HDRLEN + (reassoc ? sizeof(mgmt->u.reassoc_req) :
144 sizeof(mgmt->u.assoc_req))) {
145 @@ -2518,6 +2537,13 @@ static void handle_assoc(struct hostapd_
147 #endif /* CONFIG_MBO */
149 + if (hostapd_ubus_handle_event(hapd, &req)) {
150 + wpa_printf(MSG_DEBUG, "Station " MACSTR " assoc rejected by ubus handler.\n",
151 + MAC2STR(mgmt->sa));
152 + resp = WLAN_STATUS_UNSPECIFIED_FAILURE;
157 * sta->capability is used in check_assoc_ies() for RRM enabled
158 * capability element.
159 @@ -2688,6 +2714,7 @@ static void handle_disassoc(struct hosta
160 wpa_printf(MSG_DEBUG, "disassocation: STA=" MACSTR " reason_code=%d",
162 le_to_host16(mgmt->u.disassoc.reason_code));
163 + hostapd_ubus_notify(hapd, "disassoc", mgmt->sa);
165 sta = ap_get_sta(hapd, mgmt->sa);
167 @@ -2742,6 +2769,8 @@ static void handle_deauth(struct hostapd
169 MAC2STR(mgmt->sa), le_to_host16(mgmt->u.deauth.reason_code));
171 + hostapd_ubus_notify(hapd, "deauth", mgmt->sa);
173 sta = ap_get_sta(hapd, mgmt->sa);
175 wpa_msg(hapd->msg_ctx, MSG_DEBUG, "Station " MACSTR " trying "
176 @@ -3025,7 +3054,7 @@ int ieee802_11_mgmt(struct hostapd_data
179 if (stype == WLAN_FC_STYPE_PROBE_REQ) {
180 - handle_probe_req(hapd, mgmt, len, fi->ssi_signal);
181 + handle_probe_req(hapd, mgmt, len, fi);
185 @@ -3043,17 +3072,17 @@ int ieee802_11_mgmt(struct hostapd_data
187 case WLAN_FC_STYPE_AUTH:
188 wpa_printf(MSG_DEBUG, "mgmt::auth");
189 - handle_auth(hapd, mgmt, len);
190 + handle_auth(hapd, mgmt, len, fi);
193 case WLAN_FC_STYPE_ASSOC_REQ:
194 wpa_printf(MSG_DEBUG, "mgmt::assoc_req");
195 - handle_assoc(hapd, mgmt, len, 0);
196 + handle_assoc(hapd, mgmt, len, 0, fi);
199 case WLAN_FC_STYPE_REASSOC_REQ:
200 wpa_printf(MSG_DEBUG, "mgmt::reassoc_req");
201 - handle_assoc(hapd, mgmt, len, 1);
202 + handle_assoc(hapd, mgmt, len, 1, fi);
205 case WLAN_FC_STYPE_DISASSOC:
206 --- a/src/ap/beacon.c
207 +++ b/src/ap/beacon.c
208 @@ -702,7 +702,7 @@ void sta_track_claim_taxonomy_info(struc
210 void handle_probe_req(struct hostapd_data *hapd,
211 const struct ieee80211_mgmt *mgmt, size_t len,
213 + struct hostapd_frame_info *fi)
216 struct ieee802_11_elems elems;
217 @@ -711,9 +711,15 @@ void handle_probe_req(struct hostapd_dat
220 enum ssid_match_result res;
221 + int ssi_signal = fi->ssi_signal;
225 + struct hostapd_ubus_request req = {
226 + .type = HOSTAPD_UBUS_PROBE_REQ,
227 + .mgmt_frame = mgmt,
231 if (len < IEEE80211_HDRLEN)
233 @@ -880,6 +886,12 @@ void handle_probe_req(struct hostapd_dat
235 #endif /* CONFIG_P2P */
237 + if (hostapd_ubus_handle_event(hapd, &req)) {
238 + wpa_printf(MSG_DEBUG, "Probe request for " MACSTR " rejected by ubus handler.\n",
239 + MAC2STR(mgmt->sa));
243 /* TODO: verify that supp_rates contains at least one matching rate
244 * with AP configuration */
246 --- a/src/ap/beacon.h
247 +++ b/src/ap/beacon.h
248 @@ -14,7 +14,7 @@ struct ieee80211_mgmt;
250 void handle_probe_req(struct hostapd_data *hapd,
251 const struct ieee80211_mgmt *mgmt, size_t len,
253 + struct hostapd_frame_info *fi);
254 int ieee802_11_set_beacon(struct hostapd_data *hapd);
255 int ieee802_11_set_beacons(struct hostapd_iface *iface);
256 int ieee802_11_update_beacons(struct hostapd_iface *iface);
257 --- a/src/ap/drv_callbacks.c
258 +++ b/src/ap/drv_callbacks.c
259 @@ -52,6 +52,10 @@ int hostapd_notif_assoc(struct hostapd_d
260 u16 reason = WLAN_REASON_UNSPECIFIED;
261 u16 status = WLAN_STATUS_SUCCESS;
262 const u8 *p2p_dev_addr = NULL;
263 + struct hostapd_ubus_request req = {
264 + .type = HOSTAPD_UBUS_ASSOC_REQ,
270 @@ -131,6 +135,12 @@ int hostapd_notif_assoc(struct hostapd_d
274 + if (hostapd_ubus_handle_event(hapd, &req)) {
275 + wpa_printf(MSG_DEBUG, "Station " MACSTR " assoc rejected by ubus handler.\n",
276 + MAC2STR(req.addr));
282 wpabuf_free(sta->p2p_ie);
283 --- a/src/ap/sta_info.c
284 +++ b/src/ap/sta_info.c
285 @@ -386,6 +386,7 @@ void ap_handle_timer(void *eloop_ctx, vo
286 HOSTAPD_LEVEL_INFO, "deauthenticated due to "
287 "local deauth request");
288 ap_free_sta(hapd, sta);
289 + hostapd_ubus_notify(hapd, "local-deauth", sta->addr);
293 @@ -533,6 +534,7 @@ skip_poll:
295 WLAN_REASON_PREV_AUTH_NOT_VALID);
296 ap_free_sta(hapd, sta);
297 + hostapd_ubus_notify(hapd, "inactive-deauth", sta->addr);
301 --- a/src/ap/wpa_auth_glue.c
302 +++ b/src/ap/wpa_auth_glue.c
303 @@ -159,6 +159,7 @@ static void hostapd_wpa_auth_psk_failure
304 struct hostapd_data *hapd = ctx;
305 wpa_msg(hapd->msg_ctx, MSG_INFO, AP_STA_POSSIBLE_PSK_MISMATCH MACSTR,
307 + hostapd_ubus_notify(hapd, "key-mismatch", addr);