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