0c85a27ca5329e909a1a498f6ee26f792ffa6495
[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 @@ -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) */
36
37 + struct hostapd_ubus_iface ubus;
38 +
39 enum hostapd_iface_state {
40 HAPD_IFACE_UNINITIALIZED,
41 HAPD_IFACE_DISABLED,
42 --- a/src/ap/hostapd.c
43 +++ b/src/ap/hostapd.c
44 @@ -309,6 +309,7 @@ static void hostapd_free_hapd_data(struc
45 hapd->started = 0;
46
47 wpa_printf(MSG_DEBUG, "%s(%s)", __func__, hapd->conf->iface);
48 + hostapd_ubus_free_bss(hapd);
49 iapp_deinit(hapd->iapp);
50 hapd->iapp = NULL;
51 accounting_deinit(hapd);
52 @@ -1186,6 +1187,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);
55
56 + hostapd_ubus_add_bss(hapd);
57 +
58 return 0;
59 }
60
61 @@ -1711,6 +1714,7 @@ static int hostapd_setup_interface_compl
62 if (err)
63 goto fail;
64
65 + hostapd_ubus_add_iface(iface);
66 wpa_printf(MSG_DEBUG, "Completing interface initialization");
67 if (iface->conf->channel) {
68 #ifdef NEED_AP_MLME
69 @@ -1890,6 +1894,7 @@ dfs_offload:
70
71 fail:
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);
76 #ifdef CONFIG_FST
77 @@ -2344,6 +2349,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 @@ -1587,7 +1587,8 @@ ieee802_11_set_radius_info(struct hostap
88
89
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)
94 {
95 u16 auth_alg, auth_transaction, status_code;
96 u16 resp = WLAN_STATUS_SUCCESS;
97 @@ -1603,6 +1604,11 @@ static void handle_auth(struct hostapd_d
98 char *identity = NULL;
99 char *radius_cui = NULL;
100 u16 seq_ctrl;
101 + struct hostapd_ubus_request req = {
102 + .type = HOSTAPD_UBUS_AUTH_REQ,
103 + .mgmt_frame = mgmt,
104 + .frame_info = fi,
105 + };
106
107 if (len < IEEE80211_HDRLEN + sizeof(mgmt->u.auth)) {
108 wpa_printf(MSG_INFO, "handle_auth - too short payload (len=%lu)",
109 @@ -1757,6 +1763,12 @@ static void handle_auth(struct hostapd_d
110 resp = WLAN_STATUS_UNSPECIFIED_FAILURE;
111 goto fail;
112 }
113 + if (hostapd_ubus_handle_event(hapd, &req)) {
114 + wpa_printf(MSG_DEBUG, "Station " MACSTR " rejected by ubus handler.\n",
115 + MAC2STR(mgmt->sa));
116 + resp = WLAN_STATUS_UNSPECIFIED_FAILURE;
117 + goto fail;
118 + }
119 if (res == HOSTAPD_ACL_PENDING)
120 return;
121
122 @@ -2870,7 +2882,7 @@ void fils_hlp_timeout(void *eloop_ctx, v
123
124 static void handle_assoc(struct hostapd_data *hapd,
125 const struct ieee80211_mgmt *mgmt, size_t len,
126 - int reassoc)
127 + int reassoc, struct hostapd_frame_info *fi)
128 {
129 u16 capab_info, listen_interval, seq_ctrl, fc;
130 u16 resp = WLAN_STATUS_SUCCESS, reply_res;
131 @@ -2884,6 +2896,11 @@ static void handle_assoc(struct hostapd_
132 #ifdef CONFIG_FILS
133 int delay_assoc = 0;
134 #endif /* CONFIG_FILS */
135 + struct hostapd_ubus_request req = {
136 + .type = HOSTAPD_UBUS_ASSOC_REQ,
137 + .mgmt_frame = mgmt,
138 + .frame_info = fi,
139 + };
140
141 if (len < IEEE80211_HDRLEN + (reassoc ? sizeof(mgmt->u.reassoc_req) :
142 sizeof(mgmt->u.assoc_req))) {
143 @@ -3051,6 +3068,13 @@ static void handle_assoc(struct hostapd_
144 }
145 #endif /* CONFIG_MBO */
146
147 + if (hostapd_ubus_handle_event(hapd, &req)) {
148 + wpa_printf(MSG_DEBUG, "Station " MACSTR " assoc rejected by ubus handler.\n",
149 + MAC2STR(mgmt->sa));
150 + resp = WLAN_STATUS_UNSPECIFIED_FAILURE;
151 + goto fail;
152 + }
153 +
154 /*
155 * sta->capability is used in check_assoc_ies() for RRM enabled
156 * capability element.
157 @@ -3258,6 +3282,7 @@ static void handle_disassoc(struct hosta
158 wpa_printf(MSG_DEBUG, "disassocation: STA=" MACSTR " reason_code=%d",
159 MAC2STR(mgmt->sa),
160 le_to_host16(mgmt->u.disassoc.reason_code));
161 + hostapd_ubus_notify(hapd, "disassoc", mgmt->sa);
162
163 sta = ap_get_sta(hapd, mgmt->sa);
164 if (sta == NULL) {
165 @@ -3323,6 +3348,8 @@ static void handle_deauth(struct hostapd
166 " reason_code=%d",
167 MAC2STR(mgmt->sa), le_to_host16(mgmt->u.deauth.reason_code));
168
169 + hostapd_ubus_notify(hapd, "deauth", mgmt->sa);
170 +
171 sta = ap_get_sta(hapd, mgmt->sa);
172 if (sta == NULL) {
173 wpa_msg(hapd->msg_ctx, MSG_DEBUG, "Station " MACSTR " trying "
174 @@ -3637,7 +3664,7 @@ int ieee802_11_mgmt(struct hostapd_data
175
176
177 if (stype == WLAN_FC_STYPE_PROBE_REQ) {
178 - handle_probe_req(hapd, mgmt, len, fi->ssi_signal);
179 + handle_probe_req(hapd, mgmt, len, fi);
180 return 1;
181 }
182
183 @@ -3657,17 +3684,17 @@ int ieee802_11_mgmt(struct hostapd_data
184 switch (stype) {
185 case WLAN_FC_STYPE_AUTH:
186 wpa_printf(MSG_DEBUG, "mgmt::auth");
187 - handle_auth(hapd, mgmt, len);
188 + handle_auth(hapd, mgmt, len, fi);
189 ret = 1;
190 break;
191 case WLAN_FC_STYPE_ASSOC_REQ:
192 wpa_printf(MSG_DEBUG, "mgmt::assoc_req");
193 - handle_assoc(hapd, mgmt, len, 0);
194 + handle_assoc(hapd, mgmt, len, 0, fi);
195 ret = 1;
196 break;
197 case WLAN_FC_STYPE_REASSOC_REQ:
198 wpa_printf(MSG_DEBUG, "mgmt::reassoc_req");
199 - handle_assoc(hapd, mgmt, len, 1);
200 + handle_assoc(hapd, mgmt, len, 1, fi);
201 ret = 1;
202 break;
203 case WLAN_FC_STYPE_DISASSOC:
204 --- a/src/ap/beacon.c
205 +++ b/src/ap/beacon.c
206 @@ -716,7 +716,7 @@ void sta_track_claim_taxonomy_info(struc
207
208 void handle_probe_req(struct hostapd_data *hapd,
209 const struct ieee80211_mgmt *mgmt, size_t len,
210 - int ssi_signal)
211 + struct hostapd_frame_info *fi)
212 {
213 u8 *resp;
214 struct ieee802_11_elems elems;
215 @@ -725,9 +725,15 @@ void handle_probe_req(struct hostapd_dat
216 size_t i, resp_len;
217 int noack;
218 enum ssid_match_result res;
219 + int ssi_signal = fi->ssi_signal;
220 int ret;
221 u16 csa_offs[2];
222 size_t csa_offs_len;
223 + struct hostapd_ubus_request req = {
224 + .type = HOSTAPD_UBUS_PROBE_REQ,
225 + .mgmt_frame = mgmt,
226 + .frame_info = fi,
227 + };
228
229 if (len < IEEE80211_HDRLEN)
230 return;
231 @@ -894,6 +900,12 @@ void handle_probe_req(struct hostapd_dat
232 }
233 #endif /* CONFIG_P2P */
234
235 + if (hostapd_ubus_handle_event(hapd, &req)) {
236 + wpa_printf(MSG_DEBUG, "Probe request for " MACSTR " rejected by ubus handler.\n",
237 + MAC2STR(mgmt->sa));
238 + return;
239 + }
240 +
241 /* TODO: verify that supp_rates contains at least one matching rate
242 * with AP configuration */
243
244 --- a/src/ap/beacon.h
245 +++ b/src/ap/beacon.h
246 @@ -14,7 +14,7 @@ struct ieee80211_mgmt;
247
248 void handle_probe_req(struct hostapd_data *hapd,
249 const struct ieee80211_mgmt *mgmt, size_t len,
250 - int ssi_signal);
251 + struct hostapd_frame_info *fi);
252 int ieee802_11_set_beacon(struct hostapd_data *hapd);
253 int ieee802_11_set_beacons(struct hostapd_iface *iface);
254 int ieee802_11_update_beacons(struct hostapd_iface *iface);
255 --- a/src/ap/drv_callbacks.c
256 +++ b/src/ap/drv_callbacks.c
257 @@ -116,6 +116,10 @@ int hostapd_notif_assoc(struct hostapd_d
258 u16 reason = WLAN_REASON_UNSPECIFIED;
259 u16 status = WLAN_STATUS_SUCCESS;
260 const u8 *p2p_dev_addr = NULL;
261 + struct hostapd_ubus_request req = {
262 + .type = HOSTAPD_UBUS_ASSOC_REQ,
263 + .addr = addr,
264 + };
265
266 if (addr == NULL) {
267 /*
268 @@ -195,6 +199,12 @@ int hostapd_notif_assoc(struct hostapd_d
269 goto fail;
270 }
271
272 + if (hostapd_ubus_handle_event(hapd, &req)) {
273 + wpa_printf(MSG_DEBUG, "Station " MACSTR " assoc rejected by ubus handler.\n",
274 + MAC2STR(req.addr));
275 + goto fail;
276 + }
277 +
278 #ifdef CONFIG_P2P
279 if (elems.p2p) {
280 wpabuf_free(sta->p2p_ie);
281 --- a/src/ap/sta_info.c
282 +++ b/src/ap/sta_info.c
283 @@ -404,6 +404,7 @@ void ap_handle_timer(void *eloop_ctx, vo
284 HOSTAPD_LEVEL_INFO, "deauthenticated due to "
285 "local deauth request");
286 ap_free_sta(hapd, sta);
287 + hostapd_ubus_notify(hapd, "local-deauth", sta->addr);
288 return;
289 }
290
291 @@ -551,6 +552,7 @@ skip_poll:
292 hapd, sta,
293 WLAN_REASON_PREV_AUTH_NOT_VALID);
294 ap_free_sta(hapd, sta);
295 + hostapd_ubus_notify(hapd, "inactive-deauth", sta->addr);
296 break;
297 }
298 }
299 --- a/src/ap/wpa_auth_glue.c
300 +++ b/src/ap/wpa_auth_glue.c
301 @@ -173,6 +173,7 @@ static void hostapd_wpa_auth_psk_failure
302 struct hostapd_data *hapd = ctx;
303 wpa_msg(hapd->msg_ctx, MSG_INFO, AP_STA_POSSIBLE_PSK_MISMATCH MACSTR,
304 MAC2STR(addr));
305 + hostapd_ubus_notify(hapd, "key-mismatch", addr);
306 }
307
308