hostapd: Remove unneeded patch
[librecmc/librecmc.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 @@ -17,6 +17,7 @@
18  #include "utils/list.h"
19  #include "ap_config.h"
20  #include "drivers/driver.h"
21 +#include "ubus.h"
22  
23  #define OCE_STA_CFON_ENABLED(hapd) \
24         ((hapd->conf->oce & OCE_STA_CFON) && \
25 @@ -145,6 +146,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 --- a/src/ap/hostapd.c
34 +++ b/src/ap/hostapd.c
35 @@ -380,6 +380,7 @@ static void hostapd_free_hapd_data(struc
36         hapd->beacon_set_done = 0;
37  
38         wpa_printf(MSG_DEBUG, "%s(%s)", __func__, hapd->conf->iface);
39 +       hostapd_ubus_free_bss(hapd);
40         iapp_deinit(hapd->iapp);
41         hapd->iapp = NULL;
42         accounting_deinit(hapd);
43 @@ -1377,6 +1378,8 @@ static int hostapd_setup_bss(struct host
44         if (hapd->driver && hapd->driver->set_operstate)
45                 hapd->driver->set_operstate(hapd->drv_priv, 1);
46  
47 +       hostapd_ubus_add_bss(hapd);
48 +
49         return 0;
50  }
51  
52 @@ -1891,6 +1894,7 @@ static int hostapd_setup_interface_compl
53         if (err)
54                 goto fail;
55  
56 +       hostapd_ubus_add_iface(iface);
57         wpa_printf(MSG_DEBUG, "Completing interface initialization");
58         if (iface->conf->channel) {
59  #ifdef NEED_AP_MLME
60 @@ -2087,6 +2091,7 @@ dfs_offload:
61  
62  fail:
63         wpa_printf(MSG_ERROR, "Interface initialization failed");
64 +       hostapd_ubus_free_iface(iface);
65         hostapd_set_state(iface, HAPD_IFACE_DISABLED);
66         wpa_msg(hapd->msg_ctx, MSG_INFO, AP_EVENT_DISABLED);
67  #ifdef CONFIG_FST
68 @@ -2562,6 +2567,7 @@ void hostapd_interface_deinit_free(struc
69                    (unsigned int) iface->conf->num_bss);
70         driver = iface->bss[0]->driver;
71         drv_priv = iface->bss[0]->drv_priv;
72 +       hostapd_ubus_free_iface(iface);
73         hostapd_interface_deinit(iface);
74         wpa_printf(MSG_DEBUG, "%s: driver=%p drv_priv=%p -> hapd_deinit",
75                    __func__, driver, drv_priv);
76 --- a/src/ap/ieee802_11.c
77 +++ b/src/ap/ieee802_11.c
78 @@ -2032,7 +2032,7 @@ static void handle_auth(struct hostapd_d
79         u16 auth_alg, auth_transaction, status_code;
80         u16 resp = WLAN_STATUS_SUCCESS;
81         struct sta_info *sta = NULL;
82 -       int res, reply_res;
83 +       int res, reply_res, ubus_resp;
84         u16 fc;
85         const u8 *challenge = NULL;
86         u32 session_timeout, acct_interim_interval;
87 @@ -2043,6 +2043,11 @@ static void handle_auth(struct hostapd_d
88         char *identity = NULL;
89         char *radius_cui = NULL;
90         u16 seq_ctrl;
91 +       struct hostapd_ubus_request req = {
92 +               .type = HOSTAPD_UBUS_AUTH_REQ,
93 +               .mgmt_frame = mgmt,
94 +               .ssi_signal = rssi,
95 +       };
96  
97         if (len < IEEE80211_HDRLEN + sizeof(mgmt->u.auth)) {
98                 wpa_printf(MSG_INFO, "handle_auth - too short payload (len=%lu)",
99 @@ -2204,6 +2209,13 @@ static void handle_auth(struct hostapd_d
100                 resp = WLAN_STATUS_UNSPECIFIED_FAILURE;
101                 goto fail;
102         }
103 +       ubus_resp = hostapd_ubus_handle_event(hapd, &req);
104 +       if (ubus_resp) {
105 +               wpa_printf(MSG_DEBUG, "Station " MACSTR " rejected by ubus handler.\n",
106 +                       MAC2STR(mgmt->sa));
107 +               resp = ubus_resp > 0 ? (u16) ubus_resp : WLAN_STATUS_UNSPECIFIED_FAILURE;
108 +               goto fail;
109 +       }
110         if (res == HOSTAPD_ACL_PENDING)
111                 return;
112  
113 @@ -3862,7 +3874,7 @@ static void handle_assoc(struct hostapd_
114         u16 capab_info, listen_interval, seq_ctrl, fc;
115         u16 resp = WLAN_STATUS_SUCCESS, reply_res;
116         const u8 *pos;
117 -       int left, i;
118 +       int left, i, ubus_resp;
119         struct sta_info *sta;
120         u8 *tmp = NULL;
121         struct hostapd_sta_wpa_psk_short *psk = NULL;
122 @@ -3871,6 +3883,11 @@ static void handle_assoc(struct hostapd_
123  #ifdef CONFIG_FILS
124         int delay_assoc = 0;
125  #endif /* CONFIG_FILS */
126 +       struct hostapd_ubus_request req = {
127 +               .type = HOSTAPD_UBUS_ASSOC_REQ,
128 +               .mgmt_frame = mgmt,
129 +               .ssi_signal = rssi,
130 +       };
131  
132         if (len < IEEE80211_HDRLEN + (reassoc ? sizeof(mgmt->u.reassoc_req) :
133                                       sizeof(mgmt->u.assoc_req))) {
134 @@ -4050,6 +4067,14 @@ static void handle_assoc(struct hostapd_
135         }
136  #endif /* CONFIG_MBO */
137  
138 +       ubus_resp = hostapd_ubus_handle_event(hapd, &req);
139 +       if (ubus_resp) {
140 +               wpa_printf(MSG_DEBUG, "Station " MACSTR " assoc rejected by ubus handler.\n",
141 +                      MAC2STR(mgmt->sa));
142 +               resp = ubus_resp > 0 ? (u16) ubus_resp : WLAN_STATUS_UNSPECIFIED_FAILURE;
143 +               goto fail;
144 +       }
145 +
146         /*
147          * sta->capability is used in check_assoc_ies() for RRM enabled
148          * capability element.
149 @@ -4277,6 +4302,7 @@ static void handle_disassoc(struct hosta
150         wpa_printf(MSG_DEBUG, "disassocation: STA=" MACSTR " reason_code=%d",
151                    MAC2STR(mgmt->sa),
152                    le_to_host16(mgmt->u.disassoc.reason_code));
153 +       hostapd_ubus_notify(hapd, "disassoc", mgmt->sa);
154  
155         sta = ap_get_sta(hapd, mgmt->sa);
156         if (sta == NULL) {
157 @@ -4342,6 +4368,8 @@ static void handle_deauth(struct hostapd
158                 " reason_code=%d",
159                 MAC2STR(mgmt->sa), le_to_host16(mgmt->u.deauth.reason_code));
160  
161 +       hostapd_ubus_notify(hapd, "deauth", mgmt->sa);
162 +
163         sta = ap_get_sta(hapd, mgmt->sa);
164         if (sta == NULL) {
165                 wpa_msg(hapd->msg_ctx, MSG_DEBUG, "Station " MACSTR " trying "
166 --- a/src/ap/beacon.c
167 +++ b/src/ap/beacon.c
168 @@ -746,6 +746,12 @@ void handle_probe_req(struct hostapd_dat
169         struct hostapd_sta_wpa_psk_short *psk = NULL;
170         char *identity = NULL;
171         char *radius_cui = NULL;
172 +       struct hostapd_ubus_request req = {
173 +               .type = HOSTAPD_UBUS_PROBE_REQ,
174 +               .mgmt_frame = mgmt,
175 +               .ssi_signal = ssi_signal,
176 +               .elems = &elems,
177 +       };
178  
179         if (len < IEEE80211_HDRLEN)
180                 return;
181 @@ -923,6 +929,12 @@ void handle_probe_req(struct hostapd_dat
182         }
183  #endif /* CONFIG_P2P */
184  
185 +       if (hostapd_ubus_handle_event(hapd, &req)) {
186 +               wpa_printf(MSG_DEBUG, "Probe request for " MACSTR " rejected by ubus handler.\n",
187 +                      MAC2STR(mgmt->sa));
188 +               return;
189 +       }
190 +
191         /* TODO: verify that supp_rates contains at least one matching rate
192          * with AP configuration */
193  
194 --- a/src/ap/drv_callbacks.c
195 +++ b/src/ap/drv_callbacks.c
196 @@ -118,6 +118,10 @@ int hostapd_notif_assoc(struct hostapd_d
197         u16 reason = WLAN_REASON_UNSPECIFIED;
198         u16 status = WLAN_STATUS_SUCCESS;
199         const u8 *p2p_dev_addr = NULL;
200 +       struct hostapd_ubus_request req = {
201 +               .type = HOSTAPD_UBUS_ASSOC_REQ,
202 +               .addr = addr,
203 +       };
204  
205         if (addr == NULL) {
206                 /*
207 @@ -210,6 +214,12 @@ int hostapd_notif_assoc(struct hostapd_d
208                 goto fail;
209         }
210  
211 +       if (hostapd_ubus_handle_event(hapd, &req)) {
212 +               wpa_printf(MSG_DEBUG, "Station " MACSTR " assoc rejected by ubus handler.\n",
213 +                          MAC2STR(req.addr));
214 +               goto fail;
215 +       }
216 +
217  #ifdef CONFIG_P2P
218         if (elems.p2p) {
219                 wpabuf_free(sta->p2p_ie);
220 --- a/src/ap/sta_info.c
221 +++ b/src/ap/sta_info.c
222 @@ -424,6 +424,7 @@ void ap_handle_timer(void *eloop_ctx, vo
223                                HOSTAPD_LEVEL_INFO, "deauthenticated due to "
224                                "local deauth request");
225                 ap_free_sta(hapd, sta);
226 +               hostapd_ubus_notify(hapd, "local-deauth", sta->addr);
227                 return;
228         }
229  
230 @@ -578,6 +579,7 @@ skip_poll:
231                         hapd, sta,
232                         WLAN_REASON_PREV_AUTH_NOT_VALID);
233                 ap_free_sta(hapd, sta);
234 +               hostapd_ubus_notify(hapd, "inactive-deauth", sta->addr);
235                 break;
236         }
237  }
238 @@ -1284,6 +1286,7 @@ void ap_sta_set_authorized(struct hostap
239                                           buf, ip_addr, keyid_buf);
240         } else {
241                 wpa_msg(hapd->msg_ctx, MSG_INFO, AP_STA_DISCONNECTED "%s", buf);
242 +               hostapd_ubus_notify(hapd, "disassoc", sta->addr);
243  
244                 if (hapd->msg_ctx_parent &&
245                     hapd->msg_ctx_parent != hapd->msg_ctx)
246 --- a/src/ap/wpa_auth_glue.c
247 +++ b/src/ap/wpa_auth_glue.c
248 @@ -185,6 +185,7 @@ static void hostapd_wpa_auth_psk_failure
249         struct hostapd_data *hapd = ctx;
250         wpa_msg(hapd->msg_ctx, MSG_INFO, AP_STA_POSSIBLE_PSK_MISMATCH MACSTR,
251                 MAC2STR(addr));
252 +       hostapd_ubus_notify(hapd, "key-mismatch", addr);
253  }
254  
255  
256 --- a/wpa_supplicant/Makefile
257 +++ b/wpa_supplicant/Makefile
258 @@ -188,6 +188,12 @@ ifdef CONFIG_EAPOL_TEST
259  CFLAGS += -Werror -DEAPOL_TEST
260  endif
261  
262 +ifdef CONFIG_UBUS
263 +CFLAGS += -DUBUS_SUPPORT
264 +OBJS += ubus.o
265 +LIBS += -lubox -lubus
266 +endif
267 +
268  ifdef CONFIG_CODE_COVERAGE
269  CFLAGS += -O0 -fprofile-arcs -ftest-coverage
270  LIBS += -lgcov
271 @@ -945,6 +951,9 @@ endif
272  ifdef CONFIG_IEEE80211AX
273  OBJS += ../src/ap/ieee802_11_he.o
274  endif
275 +ifdef CONFIG_UBUS
276 +OBJS += ../src/ap/ubus.o
277 +endif
278  endif
279  ifdef CONFIG_WNM_AP
280  CFLAGS += -DCONFIG_WNM_AP
281 --- a/wpa_supplicant/wpa_supplicant.c
282 +++ b/wpa_supplicant/wpa_supplicant.c
283 @@ -6297,6 +6297,8 @@ struct wpa_supplicant * wpa_supplicant_a
284         }
285  #endif /* CONFIG_P2P */
286  
287 +       wpas_ubus_add_bss(wpa_s);
288 +
289         return wpa_s;
290  }
291  
292 @@ -6323,6 +6325,8 @@ int wpa_supplicant_remove_iface(struct w
293         struct wpa_supplicant *parent = wpa_s->parent;
294  #endif /* CONFIG_MESH */
295  
296 +       wpas_ubus_free_bss(wpa_s);
297 +
298         /* Remove interface from the global list of interfaces */
299         prev = global->ifaces;
300         if (prev == wpa_s) {
301 --- a/wpa_supplicant/wpa_supplicant_i.h
302 +++ b/wpa_supplicant/wpa_supplicant_i.h
303 @@ -17,6 +17,7 @@
304  #include "wps/wps_defs.h"
305  #include "config_ssid.h"
306  #include "wmm_ac.h"
307 +#include "ubus.h"
308  
309  extern const char *const wpa_supplicant_version;
310  extern const char *const wpa_supplicant_license;
311 @@ -506,6 +507,7 @@ struct wpa_supplicant {
312         unsigned char own_addr[ETH_ALEN];
313         unsigned char perm_addr[ETH_ALEN];
314         char ifname[100];
315 +       struct wpas_ubus_bss ubus;
316  #ifdef CONFIG_MATCH_IFACE
317         int matched;
318  #endif /* CONFIG_MATCH_IFACE */
319 --- a/wpa_supplicant/wps_supplicant.c
320 +++ b/wpa_supplicant/wps_supplicant.c
321 @@ -33,6 +33,7 @@
322  #include "p2p/p2p.h"
323  #include "p2p_supplicant.h"
324  #include "wps_supplicant.h"
325 +#include "ubus.h"
326  
327  
328  #ifndef WPS_PIN_SCAN_IGNORE_SEL_REG
329 @@ -388,6 +389,8 @@ static int wpa_supplicant_wps_cred(void
330         wpa_hexdump_key(MSG_DEBUG, "WPS: Received Credential attribute",
331                         cred->cred_attr, cred->cred_attr_len);
332  
333 +       wpas_ubus_notify(wpa_s, cred);
334 +
335         if (wpa_s->conf->wps_cred_processing == 1)
336                 return 0;
337