022f02d0f1e297c327601fd27bcd7158f1791d45
[openwrt/openwrt.git] / package / network / services / hostapd / patches / 600-ubus_support.patch
1 --- a/hostapd/Makefile
2 +++ b/hostapd/Makefile
3 @@ -165,6 +165,11 @@ OBJS += ../src/common/hw_features_common
4
5 OBJS += ../src/eapol_auth/eapol_auth_sm.o
6
7 +ifdef CONFIG_UBUS
8 +CFLAGS += -DUBUS_SUPPORT
9 +OBJS += ../src/ap/ubus.o
10 +LIBS += -lubox -lubus
11 +endif
12
13 ifdef CONFIG_CODE_COVERAGE
14 CFLAGS += -O0 -fprofile-arcs -ftest-coverage
15 --- a/src/ap/hostapd.h
16 +++ b/src/ap/hostapd.h
17 @@ -13,6 +13,7 @@
18 #include "utils/list.h"
19 #include "ap_config.h"
20 #include "drivers/driver.h"
21 +#include "ubus.h"
22
23 struct wpa_ctrl_dst;
24 struct radius_server_data;
25 @@ -129,6 +130,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 @@ -392,6 +394,8 @@ struct hostapd_iface {
34 struct hostapd_config *conf;
35 char phy[16]; /* Name of the PHY (radio) */
36
37 + struct hostapd_ubus_iface ubus;
38 +
39 enum hostapd_iface_state {
40 HAPD_IFACE_UNINITIALIZED,
41 HAPD_IFACE_DISABLED,
42 @@ -544,6 +548,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 @@ -315,6 +315,7 @@ static void hostapd_free_hapd_data(struc
53 hapd->started = 0;
54
55 wpa_printf(MSG_DEBUG, "%s(%s)", __func__, hapd->conf->iface);
56 + hostapd_ubus_free_bss(hapd);
57 iapp_deinit(hapd->iapp);
58 hapd->iapp = NULL;
59 accounting_deinit(hapd);
60 @@ -1237,6 +1238,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);
63
64 + hostapd_ubus_add_bss(hapd);
65 +
66 return 0;
67 }
68
69 @@ -1651,7 +1654,7 @@ static enum nr_chan_width hostapd_get_nr
70 #endif /* NEED_AP_MLME */
71
72
73 -static void hostapd_set_own_neighbor_report(struct hostapd_data *hapd)
74 +void hostapd_set_own_neighbor_report(struct hostapd_data *hapd)
75 {
76 #ifdef NEED_AP_MLME
77 u16 capab = hostapd_own_capab_info(hapd);
78 @@ -1872,6 +1875,7 @@ static int hostapd_setup_interface_compl
79 if (err)
80 goto fail;
81
82 + hostapd_ubus_add_iface(iface);
83 wpa_printf(MSG_DEBUG, "Completing interface initialization");
84 if (iface->conf->channel) {
85 #ifdef NEED_AP_MLME
86 @@ -2052,6 +2056,7 @@ dfs_offload:
87
88 fail:
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);
93 #ifdef CONFIG_FST
94 @@ -2517,6 +2522,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 @@ -1712,12 +1712,13 @@ ieee802_11_set_radius_info(struct hostap
105
106
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)
111 {
112 u16 auth_alg, auth_transaction, status_code;
113 u16 resp = WLAN_STATUS_SUCCESS;
114 struct sta_info *sta = NULL;
115 - int res, reply_res;
116 + int res, reply_res, ubus_resp;
117 u16 fc;
118 const u8 *challenge = NULL;
119 u32 session_timeout, acct_interim_interval;
120 @@ -1728,6 +1729,11 @@ static void handle_auth(struct hostapd_d
121 char *identity = NULL;
122 char *radius_cui = NULL;
123 u16 seq_ctrl;
124 + struct hostapd_ubus_request req = {
125 + .type = HOSTAPD_UBUS_AUTH_REQ,
126 + .mgmt_frame = mgmt,
127 + .frame_info = fi,
128 + };
129
130 if (len < IEEE80211_HDRLEN + sizeof(mgmt->u.auth)) {
131 wpa_printf(MSG_INFO, "handle_auth - too short payload (len=%lu)",
132 @@ -1888,6 +1894,13 @@ static void handle_auth(struct hostapd_d
133 resp = WLAN_STATUS_UNSPECIFIED_FAILURE;
134 goto fail;
135 }
136 + ubus_resp = hostapd_ubus_handle_event(hapd, &req);
137 + if (ubus_resp) {
138 + wpa_printf(MSG_DEBUG, "Station " MACSTR " rejected by ubus handler.\n",
139 + MAC2STR(mgmt->sa));
140 + resp = ubus_resp > 0 ? (u16) ubus_resp : WLAN_STATUS_UNSPECIFIED_FAILURE;
141 + goto fail;
142 + }
143 if (res == HOSTAPD_ACL_PENDING)
144 return;
145
146 @@ -3167,12 +3180,12 @@ void fils_hlp_timeout(void *eloop_ctx, v
147
148 static void handle_assoc(struct hostapd_data *hapd,
149 const struct ieee80211_mgmt *mgmt, size_t len,
150 - int reassoc)
151 + int reassoc, struct hostapd_frame_info *fi)
152 {
153 u16 capab_info, listen_interval, seq_ctrl, fc;
154 u16 resp = WLAN_STATUS_SUCCESS, reply_res;
155 const u8 *pos;
156 - int left, i;
157 + int left, i, ubus_resp;
158 struct sta_info *sta;
159 u8 *tmp = NULL;
160 struct hostapd_sta_wpa_psk_short *psk = NULL;
161 @@ -3181,6 +3194,11 @@ static void handle_assoc(struct hostapd_
162 #ifdef CONFIG_FILS
163 int delay_assoc = 0;
164 #endif /* CONFIG_FILS */
165 + struct hostapd_ubus_request req = {
166 + .type = HOSTAPD_UBUS_ASSOC_REQ,
167 + .mgmt_frame = mgmt,
168 + .frame_info = fi,
169 + };
170
171 if (len < IEEE80211_HDRLEN + (reassoc ? sizeof(mgmt->u.reassoc_req) :
172 sizeof(mgmt->u.assoc_req))) {
173 @@ -3352,6 +3370,14 @@ static void handle_assoc(struct hostapd_
174 }
175 #endif /* CONFIG_MBO */
176
177 + ubus_resp = hostapd_ubus_handle_event(hapd, &req);
178 + if (ubus_resp) {
179 + wpa_printf(MSG_DEBUG, "Station " MACSTR " assoc rejected by ubus handler.\n",
180 + MAC2STR(mgmt->sa));
181 + resp = ubus_resp > 0 ? (u16) ubus_resp : WLAN_STATUS_UNSPECIFIED_FAILURE;
182 + goto fail;
183 + }
184 +
185 /*
186 * sta->capability is used in check_assoc_ies() for RRM enabled
187 * capability element.
188 @@ -3565,6 +3591,7 @@ static void handle_disassoc(struct hosta
189 wpa_printf(MSG_DEBUG, "disassocation: STA=" MACSTR " reason_code=%d",
190 MAC2STR(mgmt->sa),
191 le_to_host16(mgmt->u.disassoc.reason_code));
192 + hostapd_ubus_notify(hapd, "disassoc", mgmt->sa);
193
194 sta = ap_get_sta(hapd, mgmt->sa);
195 if (sta == NULL) {
196 @@ -3630,6 +3657,8 @@ static void handle_deauth(struct hostapd
197 " reason_code=%d",
198 MAC2STR(mgmt->sa), le_to_host16(mgmt->u.deauth.reason_code));
199
200 + hostapd_ubus_notify(hapd, "deauth", mgmt->sa);
201 +
202 sta = ap_get_sta(hapd, mgmt->sa);
203 if (sta == NULL) {
204 wpa_msg(hapd->msg_ctx, MSG_DEBUG, "Station " MACSTR " trying "
205 @@ -3949,7 +3978,7 @@ int ieee802_11_mgmt(struct hostapd_data
206
207
208 if (stype == WLAN_FC_STYPE_PROBE_REQ) {
209 - handle_probe_req(hapd, mgmt, len, ssi_signal);
210 + handle_probe_req(hapd, mgmt, len, fi);
211 return 1;
212 }
213
214 @@ -3969,17 +3998,17 @@ int ieee802_11_mgmt(struct hostapd_data
215 switch (stype) {
216 case WLAN_FC_STYPE_AUTH:
217 wpa_printf(MSG_DEBUG, "mgmt::auth");
218 - handle_auth(hapd, mgmt, len);
219 + handle_auth(hapd, mgmt, len, fi);
220 ret = 1;
221 break;
222 case WLAN_FC_STYPE_ASSOC_REQ:
223 wpa_printf(MSG_DEBUG, "mgmt::assoc_req");
224 - handle_assoc(hapd, mgmt, len, 0);
225 + handle_assoc(hapd, mgmt, len, 0, fi);
226 ret = 1;
227 break;
228 case WLAN_FC_STYPE_REASSOC_REQ:
229 wpa_printf(MSG_DEBUG, "mgmt::reassoc_req");
230 - handle_assoc(hapd, mgmt, len, 1);
231 + handle_assoc(hapd, mgmt, len, 1, fi);
232 ret = 1;
233 break;
234 case WLAN_FC_STYPE_DISASSOC:
235 --- a/src/ap/beacon.c
236 +++ b/src/ap/beacon.c
237 @@ -720,7 +720,7 @@ void sta_track_claim_taxonomy_info(struc
238
239 void handle_probe_req(struct hostapd_data *hapd,
240 const struct ieee80211_mgmt *mgmt, size_t len,
241 - int ssi_signal)
242 + struct hostapd_frame_info *fi)
243 {
244 u8 *resp;
245 struct ieee802_11_elems elems;
246 @@ -729,6 +729,7 @@ void handle_probe_req(struct hostapd_dat
247 size_t i, resp_len;
248 int noack;
249 enum ssid_match_result res;
250 + int ssi_signal = fi->ssi_signal;
251 int ret;
252 u16 csa_offs[2];
253 size_t csa_offs_len;
254 @@ -737,6 +738,11 @@ void handle_probe_req(struct hostapd_dat
255 struct hostapd_sta_wpa_psk_short *psk = NULL;
256 char *identity = NULL;
257 char *radius_cui = NULL;
258 + struct hostapd_ubus_request req = {
259 + .type = HOSTAPD_UBUS_PROBE_REQ,
260 + .mgmt_frame = mgmt,
261 + .frame_info = fi,
262 + };
263
264 if (len < IEEE80211_HDRLEN)
265 return;
266 @@ -914,6 +920,12 @@ void handle_probe_req(struct hostapd_dat
267 }
268 #endif /* CONFIG_P2P */
269
270 + if (hostapd_ubus_handle_event(hapd, &req)) {
271 + wpa_printf(MSG_DEBUG, "Probe request for " MACSTR " rejected by ubus handler.\n",
272 + MAC2STR(mgmt->sa));
273 + return;
274 + }
275 +
276 /* TODO: verify that supp_rates contains at least one matching rate
277 * with AP configuration */
278
279 --- a/src/ap/beacon.h
280 +++ b/src/ap/beacon.h
281 @@ -14,7 +14,7 @@ struct ieee80211_mgmt;
282
283 void handle_probe_req(struct hostapd_data *hapd,
284 const struct ieee80211_mgmt *mgmt, size_t len,
285 - int ssi_signal);
286 + struct hostapd_frame_info *fi);
287 int ieee802_11_set_beacon(struct hostapd_data *hapd);
288 int ieee802_11_set_beacons(struct hostapd_iface *iface);
289 int ieee802_11_update_beacons(struct hostapd_iface *iface);
290 --- a/src/ap/drv_callbacks.c
291 +++ b/src/ap/drv_callbacks.c
292 @@ -116,6 +116,10 @@ int hostapd_notif_assoc(struct hostapd_d
293 u16 reason = WLAN_REASON_UNSPECIFIED;
294 u16 status = WLAN_STATUS_SUCCESS;
295 const u8 *p2p_dev_addr = NULL;
296 + struct hostapd_ubus_request req = {
297 + .type = HOSTAPD_UBUS_ASSOC_REQ,
298 + .addr = addr,
299 + };
300
301 if (addr == NULL) {
302 /*
303 @@ -195,6 +199,12 @@ int hostapd_notif_assoc(struct hostapd_d
304 goto fail;
305 }
306
307 + if (hostapd_ubus_handle_event(hapd, &req)) {
308 + wpa_printf(MSG_DEBUG, "Station " MACSTR " assoc rejected by ubus handler.\n",
309 + MAC2STR(req.addr));
310 + goto fail;
311 + }
312 +
313 #ifdef CONFIG_P2P
314 if (elems.p2p) {
315 wpabuf_free(sta->p2p_ie);
316 --- a/src/ap/sta_info.c
317 +++ b/src/ap/sta_info.c
318 @@ -415,6 +415,7 @@ void ap_handle_timer(void *eloop_ctx, vo
319 HOSTAPD_LEVEL_INFO, "deauthenticated due to "
320 "local deauth request");
321 ap_free_sta(hapd, sta);
322 + hostapd_ubus_notify(hapd, "local-deauth", sta->addr);
323 return;
324 }
325
326 @@ -562,6 +563,7 @@ skip_poll:
327 hapd, sta,
328 WLAN_REASON_PREV_AUTH_NOT_VALID);
329 ap_free_sta(hapd, sta);
330 + hostapd_ubus_notify(hapd, "inactive-deauth", sta->addr);
331 break;
332 }
333 }
334 @@ -1223,6 +1225,7 @@ void ap_sta_set_authorized(struct hostap
335 buf, ip_addr);
336 } else {
337 wpa_msg(hapd->msg_ctx, MSG_INFO, AP_STA_DISCONNECTED "%s", buf);
338 + hostapd_ubus_notify(hapd, "disassoc", sta->addr);
339
340 if (hapd->msg_ctx_parent &&
341 hapd->msg_ctx_parent != hapd->msg_ctx)
342 --- a/src/ap/wpa_auth_glue.c
343 +++ b/src/ap/wpa_auth_glue.c
344 @@ -177,6 +177,7 @@ static void hostapd_wpa_auth_psk_failure
345 struct hostapd_data *hapd = ctx;
346 wpa_msg(hapd->msg_ctx, MSG_INFO, AP_STA_POSSIBLE_PSK_MISMATCH MACSTR,
347 MAC2STR(addr));
348 + hostapd_ubus_notify(hapd, "key-mismatch", addr);
349 }
350
351