hostapd: bring back mesh patches
[oweals/openwrt.git] / package / network / services / hostapd / patches / 600-ubus_support.patch
1 --- a/hostapd/Makefile
2 +++ b/hostapd/Makefile
3 @@ -167,6 +167,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 @@ -80,7 +81,7 @@ struct hapd_interfaces {
26  #ifdef CONFIG_CTRL_IFACE_UDP
27         unsigned char ctrl_iface_cookie[CTRL_IFACE_COOKIE_LEN];
28  #endif /* CONFIG_CTRL_IFACE_UDP */
29 -
30 +       struct ubus_object ubus;
31  };
32  
33  enum hostapd_chan_status {
34 @@ -154,6 +155,7 @@ struct hostapd_data {
35         struct hostapd_iface *iface;
36         struct hostapd_config *iconf;
37         struct hostapd_bss_config *conf;
38 +       struct hostapd_ubus_bss ubus;
39         int interface_added; /* virtual interface added for this BSS */
40         unsigned int started:1;
41         unsigned int disabled:1;
42 @@ -603,6 +605,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 @@ -395,6 +395,7 @@ static void hostapd_free_hapd_data(struc
53         hapd->beacon_set_done = 0;
54  
55         wpa_printf(MSG_DEBUG, "%s(%s)", __func__, hapd->conf->iface);
56 +       hostapd_ubus_free_bss(hapd);
57         accounting_deinit(hapd);
58         hostapd_deinit_wpa(hapd);
59         vlan_deinit(hapd);
60 @@ -1413,6 +1414,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 @@ -1988,6 +1991,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->freq) {
76  #ifdef NEED_AP_MLME
77 @@ -2185,6 +2189,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 @@ -2658,6 +2663,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 @@ -2252,13 +2252,18 @@ static void handle_auth(struct hostapd_d
96         u16 auth_alg, auth_transaction, status_code;
97         u16 resp = WLAN_STATUS_SUCCESS;
98         struct sta_info *sta = NULL;
99 -       int res, reply_res;
100 +       int res, reply_res, ubus_resp;
101         u16 fc;
102         const u8 *challenge = NULL;
103         u8 resp_ies[2 + WLAN_AUTH_CHALLENGE_LEN];
104         size_t resp_ies_len = 0;
105         u16 seq_ctrl;
106         struct radius_sta rad_info;
107 +       struct hostapd_ubus_request req = {
108 +               .type = HOSTAPD_UBUS_AUTH_REQ,
109 +               .mgmt_frame = mgmt,
110 +               .ssi_signal = rssi,
111 +       };
112  
113         if (len < IEEE80211_HDRLEN + sizeof(mgmt->u.auth)) {
114                 wpa_printf(MSG_INFO, "handle_auth - too short payload (len=%lu)",
115 @@ -2418,6 +2423,13 @@ static void handle_auth(struct hostapd_d
116                 resp = WLAN_STATUS_UNSPECIFIED_FAILURE;
117                 goto fail;
118         }
119 +       ubus_resp = hostapd_ubus_handle_event(hapd, &req);
120 +       if (ubus_resp) {
121 +               wpa_printf(MSG_DEBUG, "Station " MACSTR " rejected by ubus handler.\n",
122 +                       MAC2STR(mgmt->sa));
123 +               resp = ubus_resp > 0 ? (u16) ubus_resp : WLAN_STATUS_UNSPECIFIED_FAILURE;
124 +               goto fail;
125 +       }
126         if (res == HOSTAPD_ACL_PENDING)
127                 return;
128  
129 @@ -4087,7 +4099,7 @@ static void handle_assoc(struct hostapd_
130         int resp = WLAN_STATUS_SUCCESS;
131         u16 reply_res;
132         const u8 *pos;
133 -       int left, i;
134 +       int left, i, ubus_resp;
135         struct sta_info *sta;
136         u8 *tmp = NULL;
137  #ifdef CONFIG_FILS
138 @@ -4300,6 +4312,11 @@ static void handle_assoc(struct hostapd_
139                 left = res;
140         }
141  #endif /* CONFIG_FILS */
142 +       struct hostapd_ubus_request req = {
143 +               .type = HOSTAPD_UBUS_ASSOC_REQ,
144 +               .mgmt_frame = mgmt,
145 +               .ssi_signal = rssi,
146 +       };
147  
148         /* followed by SSID and Supported rates; and HT capabilities if 802.11n
149          * is used */
150 @@ -4464,6 +4481,14 @@ static void handle_assoc(struct hostapd_
151                                             pos, left, rssi, omit_rsnxe);
152         os_free(tmp);
153  
154 +       ubus_resp = hostapd_ubus_handle_event(hapd, &req);
155 +       if (ubus_resp) {
156 +               wpa_printf(MSG_DEBUG, "Station " MACSTR " assoc rejected by ubus handler.\n",
157 +                      MAC2STR(mgmt->sa));
158 +               resp = ubus_resp > 0 ? (u16) ubus_resp : WLAN_STATUS_UNSPECIFIED_FAILURE;
159 +               goto fail;
160 +       }
161 +
162         /*
163          * Remove the station in case tranmission of a success response fails
164          * (the STA was added associated to the driver) or if the station was
165 @@ -4491,6 +4516,7 @@ static void handle_disassoc(struct hosta
166         wpa_printf(MSG_DEBUG, "disassocation: STA=" MACSTR " reason_code=%d",
167                    MAC2STR(mgmt->sa),
168                    le_to_host16(mgmt->u.disassoc.reason_code));
169 +       hostapd_ubus_notify(hapd, "disassoc", mgmt->sa);
170  
171         sta = ap_get_sta(hapd, mgmt->sa);
172         if (sta == NULL) {
173 @@ -4557,6 +4583,8 @@ static void handle_deauth(struct hostapd
174                 " reason_code=%d",
175                 MAC2STR(mgmt->sa), le_to_host16(mgmt->u.deauth.reason_code));
176  
177 +       hostapd_ubus_notify(hapd, "deauth", mgmt->sa);
178 +
179         sta = ap_get_sta(hapd, mgmt->sa);
180         if (sta == NULL) {
181                 wpa_msg(hapd->msg_ctx, MSG_DEBUG, "Station " MACSTR " trying "
182 --- a/src/ap/beacon.c
183 +++ b/src/ap/beacon.c
184 @@ -814,6 +814,12 @@ void handle_probe_req(struct hostapd_dat
185         u16 csa_offs[2];
186         size_t csa_offs_len;
187         struct radius_sta rad_info;
188 +       struct hostapd_ubus_request req = {
189 +               .type = HOSTAPD_UBUS_PROBE_REQ,
190 +               .mgmt_frame = mgmt,
191 +               .ssi_signal = ssi_signal,
192 +               .elems = &elems,
193 +       };
194  
195         if (len < IEEE80211_HDRLEN)
196                 return;
197 @@ -996,6 +1002,12 @@ void handle_probe_req(struct hostapd_dat
198         }
199  #endif /* CONFIG_P2P */
200  
201 +       if (hostapd_ubus_handle_event(hapd, &req)) {
202 +               wpa_printf(MSG_DEBUG, "Probe request for " MACSTR " rejected by ubus handler.\n",
203 +                      MAC2STR(mgmt->sa));
204 +               return;
205 +       }
206 +
207         /* TODO: verify that supp_rates contains at least one matching rate
208          * with AP configuration */
209  
210 --- a/src/ap/drv_callbacks.c
211 +++ b/src/ap/drv_callbacks.c
212 @@ -119,6 +119,10 @@ int hostapd_notif_assoc(struct hostapd_d
213         u16 reason = WLAN_REASON_UNSPECIFIED;
214         int status = WLAN_STATUS_SUCCESS;
215         const u8 *p2p_dev_addr = NULL;
216 +       struct hostapd_ubus_request req = {
217 +               .type = HOSTAPD_UBUS_ASSOC_REQ,
218 +               .addr = addr,
219 +       };
220  
221         if (addr == NULL) {
222                 /*
223 @@ -211,6 +215,12 @@ int hostapd_notif_assoc(struct hostapd_d
224                 goto fail;
225         }
226  
227 +       if (hostapd_ubus_handle_event(hapd, &req)) {
228 +               wpa_printf(MSG_DEBUG, "Station " MACSTR " assoc rejected by ubus handler.\n",
229 +                          MAC2STR(req.addr));
230 +               goto fail;
231 +       }
232 +
233  #ifdef CONFIG_P2P
234         if (elems.p2p) {
235                 wpabuf_free(sta->p2p_ie);
236 --- a/src/ap/sta_info.c
237 +++ b/src/ap/sta_info.c
238 @@ -424,6 +424,7 @@ void ap_handle_timer(void *eloop_ctx, vo
239                                HOSTAPD_LEVEL_INFO, "deauthenticated due to "
240                                "local deauth request");
241                 ap_free_sta(hapd, sta);
242 +               hostapd_ubus_notify(hapd, "local-deauth", sta->addr);
243                 return;
244         }
245  
246 @@ -579,6 +580,7 @@ skip_poll:
247                         hapd, sta,
248                         WLAN_REASON_PREV_AUTH_NOT_VALID);
249                 ap_free_sta(hapd, sta);
250 +               hostapd_ubus_notify(hapd, "inactive-deauth", sta->addr);
251                 break;
252         }
253  }
254 @@ -1294,6 +1296,7 @@ void ap_sta_set_authorized(struct hostap
255                                           buf, ip_addr, keyid_buf);
256         } else {
257                 wpa_msg(hapd->msg_ctx, MSG_INFO, AP_STA_DISCONNECTED "%s", buf);
258 +               hostapd_ubus_notify(hapd, "disassoc", sta->addr);
259  
260                 if (hapd->msg_ctx_parent &&
261                     hapd->msg_ctx_parent != hapd->msg_ctx)
262 --- a/src/ap/wpa_auth_glue.c
263 +++ b/src/ap/wpa_auth_glue.c
264 @@ -251,6 +251,7 @@ static void hostapd_wpa_auth_psk_failure
265         struct hostapd_data *hapd = ctx;
266         wpa_msg(hapd->msg_ctx, MSG_INFO, AP_STA_POSSIBLE_PSK_MISMATCH MACSTR,
267                 MAC2STR(addr));
268 +       hostapd_ubus_notify(hapd, "key-mismatch", addr);
269  }
270  
271  
272 --- a/wpa_supplicant/Makefile
273 +++ b/wpa_supplicant/Makefile
274 @@ -190,6 +190,12 @@ ifdef CONFIG_EAPOL_TEST
275  CFLAGS += -Werror -DEAPOL_TEST
276  endif
277  
278 +ifdef CONFIG_UBUS
279 +CFLAGS += -DUBUS_SUPPORT
280 +OBJS += ubus.o
281 +LIBS += -lubox -lubus
282 +endif
283 +
284  ifdef CONFIG_CODE_COVERAGE
285  CFLAGS += -O0 -fprofile-arcs -ftest-coverage
286  LIBS += -lgcov
287 @@ -883,6 +889,9 @@ OBJS += ../src/pae/ieee802_1x_secy_ops.o
288  ifdef CONFIG_AP
289  OBJS += ../src/ap/wpa_auth_kay.o
290  endif
291 +ifdef CONFIG_UBUS
292 +OBJS += ../src/ap/ubus.o
293 +endif
294  endif
295  
296  ifdef CONFIG_IEEE8021X_EAPOL
297 --- a/wpa_supplicant/wpa_supplicant.c
298 +++ b/wpa_supplicant/wpa_supplicant.c
299 @@ -6793,6 +6793,8 @@ struct wpa_supplicant * wpa_supplicant_a
300         }
301  #endif /* CONFIG_P2P */
302  
303 +       wpas_ubus_add_bss(wpa_s);
304 +
305         return wpa_s;
306  }
307  
308 @@ -6819,6 +6821,8 @@ int wpa_supplicant_remove_iface(struct w
309         struct wpa_supplicant *parent = wpa_s->parent;
310  #endif /* CONFIG_MESH */
311  
312 +       wpas_ubus_free_bss(wpa_s);
313 +
314         /* Remove interface from the global list of interfaces */
315         prev = global->ifaces;
316         if (prev == wpa_s) {
317 @@ -7122,8 +7126,12 @@ int wpa_supplicant_run(struct wpa_global
318         eloop_register_signal_terminate(wpa_supplicant_terminate, global);
319         eloop_register_signal_reconfig(wpa_supplicant_reconfig, global);
320  
321 +       wpas_ubus_add(global);
322 +
323         eloop_run();
324  
325 +       wpas_ubus_free(global);
326 +
327         return 0;
328  }
329  
330 --- a/wpa_supplicant/wpa_supplicant_i.h
331 +++ b/wpa_supplicant/wpa_supplicant_i.h
332 @@ -17,6 +17,7 @@
333  #include "wps/wps_defs.h"
334  #include "config_ssid.h"
335  #include "wmm_ac.h"
336 +#include "ubus.h"
337  
338  extern const char *const wpa_supplicant_version;
339  extern const char *const wpa_supplicant_license;
340 @@ -310,6 +311,8 @@ struct wpa_global {
341  #endif /* CONFIG_WIFI_DISPLAY */
342  
343         struct psk_list_entry *add_psk; /* From group formation */
344 +
345 +       struct ubus_object ubus_global;
346  };
347  
348  
349 @@ -520,6 +523,7 @@ struct wpa_supplicant {
350         unsigned char own_addr[ETH_ALEN];
351         unsigned char perm_addr[ETH_ALEN];
352         char ifname[100];
353 +       struct wpas_ubus_bss ubus;
354  #ifdef CONFIG_MATCH_IFACE
355         int matched;
356  #endif /* CONFIG_MATCH_IFACE */
357 --- a/wpa_supplicant/wps_supplicant.c
358 +++ b/wpa_supplicant/wps_supplicant.c
359 @@ -33,6 +33,7 @@
360  #include "p2p/p2p.h"
361  #include "p2p_supplicant.h"
362  #include "wps_supplicant.h"
363 +#include "ubus.h"
364  
365  
366  #ifndef WPS_PIN_SCAN_IGNORE_SEL_REG
367 @@ -392,6 +393,8 @@ static int wpa_supplicant_wps_cred(void
368         wpa_hexdump_key(MSG_DEBUG, "WPS: Received Credential attribute",
369                         cred->cred_attr, cred->cred_attr_len);
370  
371 +       wpas_ubus_notify(wpa_s, cred);
372 +
373         if (wpa_s->conf->wps_cred_processing == 1)
374                 return 0;
375  
376 --- a/hostapd/main.c
377 +++ b/hostapd/main.c
378 @@ -896,6 +896,7 @@ int main(int argc, char *argv[])
379         }
380  
381         hostapd_global_ctrl_iface_init(&interfaces);
382 +       hostapd_ubus_add(&interfaces);
383  
384         if (hostapd_global_run(&interfaces, daemonize, pid_file)) {
385                 wpa_printf(MSG_ERROR, "Failed to start eloop");
386 @@ -905,6 +906,7 @@ int main(int argc, char *argv[])
387         ret = 0;
388  
389   out:
390 +       hostapd_ubus_free(&interfaces);
391         hostapd_global_ctrl_iface_deinit(&interfaces);
392         /* Deinitialize all interfaces */
393         for (i = 0; i < interfaces.count; i++) {
394 --- a/wpa_supplicant/main.c
395 +++ b/wpa_supplicant/main.c
396 @@ -203,7 +203,7 @@ int main(int argc, char *argv[])
397  
398         for (;;) {
399                 c = getopt(argc, argv,
400 -                          "b:Bc:C:D:de:f:g:G:hH:i:I:KLMm:No:O:p:P:qsTtuv::W");
401 +                          "b:Bc:C:D:de:f:g:G:hH:i:I:KLMm:nNo:O:p:P:qsTtuv::W");
402                 if (c < 0)
403                         break;
404                 switch (c) {
405 @@ -271,6 +271,9 @@ int main(int argc, char *argv[])
406                         params.conf_p2p_dev = optarg;
407                         break;
408  #endif /* CONFIG_P2P */
409 +               case 'n':
410 +                       iface_count = 0;
411 +                       break;
412                 case 'o':
413                         params.override_driver = optarg;
414                         break;
415 --- a/src/ap/rrm.c
416 +++ b/src/ap/rrm.c
417 @@ -89,6 +89,9 @@ static void hostapd_handle_beacon_report
418                 return;
419         wpa_msg(hapd->msg_ctx, MSG_INFO, BEACON_RESP_RX MACSTR " %u %02x %s",
420                 MAC2STR(addr), token, rep_mode, report);
421 +       if (len < sizeof(struct rrm_measurement_beacon_report))
422 +               return;
423 +       hostapd_ubus_notify_beacon_report(hapd, addr, token, rep_mode, (struct rrm_measurement_beacon_report*) pos, len);
424  }
425  
426