hostapd: update to version 2013-11-20
[openwrt.git] / package / network / services / hostapd / patches / 600-ubus_support.patch
1 --- a/hostapd/Makefile
2 +++ b/hostapd/Makefile
3 @@ -105,6 +105,11 @@ OBJS += ../src/common/wpa_common.o
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  ifndef CONFIG_NO_DUMP_STATE
14  # define HOSTAPD_DUMP_STATE to include SIGUSR1 handler for dumping state to
15 --- a/src/ap/hostapd.h
16 +++ b/src/ap/hostapd.h
17 @@ -11,6 +11,7 @@
18  
19  #include "common/defs.h"
20  #include "ap_config.h"
21 +#include "ubus.h"
22  
23  struct wpa_driver_ops;
24  struct wpa_ctrl_dst;
25 @@ -105,6 +106,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  
33 @@ -256,6 +258,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 --- /dev/null
43 +++ b/src/ap/ubus.c
44 @@ -0,0 +1,373 @@
45 +/*
46 + * hostapd / ubus support
47 + * Copyright (c) 2013, Felix Fietkau <nbd@openwrt.org>
48 + *
49 + * This software may be distributed under the terms of the BSD license.
50 + * See README for more details.
51 + */
52 +
53 +#include "utils/includes.h"
54 +#include "utils/common.h"
55 +#include "utils/eloop.h"
56 +#include "common/ieee802_11_defs.h"
57 +#include "hostapd.h"
58 +#include "sta_info.h"
59 +#include "ubus.h"
60 +
61 +static struct ubus_context *ctx;
62 +static struct blob_buf b;
63 +static int ctx_ref;
64 +
65 +struct ubus_banned_client {
66 +       struct avl_node avl;
67 +       u8 addr[ETH_ALEN];
68 +};
69 +
70 +static void ubus_receive(int sock, void *eloop_ctx, void *sock_ctx)
71 +{
72 +       struct ubus_context *ctx = eloop_ctx;
73 +       ubus_handle_event(ctx);
74 +}
75 +
76 +static void ubus_reconnect_timeout(void *eloop_data, void *user_ctx)
77 +{
78 +       if (ubus_reconnect(ctx, NULL)) {
79 +               eloop_register_timeout(1, 0, ubus_reconnect_timeout, ctx, NULL);
80 +               return;
81 +       }
82 +
83 +       eloop_register_read_sock(ctx->sock.fd, ubus_receive, ctx, NULL);
84 +}
85 +
86 +static void hostapd_ubus_connection_lost(struct ubus_context *ctx)
87 +{
88 +       eloop_unregister_read_sock(ctx->sock.fd);
89 +       eloop_register_timeout(1, 0, ubus_reconnect_timeout, ctx, NULL);
90 +}
91 +
92 +static bool hostapd_ubus_init(void)
93 +{
94 +       if (ctx)
95 +               return true;
96 +
97 +       ctx = ubus_connect(NULL);
98 +       if (!ctx)
99 +               return false;
100 +
101 +       ctx->connection_lost = hostapd_ubus_connection_lost;
102 +       eloop_register_read_sock(ctx->sock.fd, ubus_receive, ctx, NULL);
103 +       return true;
104 +}
105 +
106 +static void hostapd_ubus_ref_inc(void)
107 +{
108 +       ctx_ref++;
109 +}
110 +
111 +static void hostapd_ubus_ref_dec(void)
112 +{
113 +       ctx_ref--;
114 +       if (!ctx)
115 +               return;
116 +
117 +       if (ctx_ref)
118 +               return;
119 +
120 +       eloop_unregister_read_sock(ctx->sock.fd);
121 +       ubus_free(ctx);
122 +       ctx = NULL;
123 +}
124 +
125 +void hostapd_ubus_add_iface(struct hostapd_iface *iface)
126 +{
127 +       if (!hostapd_ubus_init())
128 +               return;
129 +}
130 +
131 +void hostapd_ubus_free_iface(struct hostapd_iface *iface)
132 +{
133 +       if (!ctx)
134 +               return;
135 +}
136 +
137 +static void
138 +hostapd_bss_del_ban(void *eloop_data, void *user_ctx)
139 +{
140 +       struct ubus_banned_client *ban = eloop_data;
141 +       struct hostapd_data *hapd = user_ctx;
142 +
143 +       avl_delete(&hapd->ubus.banned, &ban->avl);
144 +       free(ban);
145 +}
146 +
147 +static void
148 +hostapd_bss_ban_client(struct hostapd_data *hapd, u8 *addr, int time)
149 +{
150 +       struct ubus_banned_client *ban;
151 +
152 +       if (time < 0)
153 +               time = 0;
154 +
155 +       ban = avl_find_element(&hapd->ubus.banned, addr, ban, avl);
156 +       if (!ban) {
157 +               if (!time)
158 +                       return;
159 +
160 +               ban = os_zalloc(sizeof(*ban));
161 +               memcpy(ban->addr, addr, sizeof(ban->addr));
162 +               ban->avl.key = ban->addr;
163 +               avl_insert(&hapd->ubus.banned, &ban->avl);
164 +       } else {
165 +               eloop_cancel_timeout(hostapd_bss_del_ban, ban, hapd);
166 +               if (!time) {
167 +                       hostapd_bss_del_ban(ban, hapd);
168 +                       return;
169 +               }
170 +       }
171 +
172 +       eloop_register_timeout(0, time * 1000, hostapd_bss_del_ban, ban, hapd);
173 +}
174 +
175 +static int
176 +hostapd_bss_get_clients(struct ubus_context *ctx, struct ubus_object *obj,
177 +                       struct ubus_request_data *req, const char *method,
178 +                       struct blob_attr *msg)
179 +{
180 +       struct hostapd_data *hapd = container_of(obj, struct hostapd_data, ubus.obj);
181 +       struct sta_info *sta;
182 +       void *list, *c;
183 +       char mac_buf[20];
184 +       static const struct {
185 +               const char *name;
186 +               uint32_t flag;
187 +       } sta_flags[] = {
188 +               { "auth", WLAN_STA_AUTH },
189 +               { "assoc", WLAN_STA_ASSOC },
190 +               { "authorized", WLAN_STA_AUTHORIZED },
191 +               { "preauth", WLAN_STA_PREAUTH },
192 +               { "wds", WLAN_STA_WDS },
193 +               { "wmm", WLAN_STA_WMM },
194 +               { "ht", WLAN_STA_HT },
195 +               { "vht", WLAN_STA_VHT },
196 +               { "wps", WLAN_STA_WPS },
197 +               { "mfp", WLAN_STA_MFP },
198 +       };
199 +
200 +       blob_buf_init(&b, 0);
201 +       blobmsg_add_u32(&b, "freq", hapd->iface->freq);
202 +       list = blobmsg_open_table(&b, "clients");
203 +       for (sta = hapd->sta_list; sta; sta = sta->next) {
204 +               int i;
205 +
206 +               sprintf(mac_buf, MACSTR, MAC2STR(sta->addr));
207 +               c = blobmsg_open_table(&b, mac_buf);
208 +               for (i = 0; i < ARRAY_SIZE(sta_flags); i++)
209 +                       blobmsg_add_u8(&b, sta_flags[i].name,
210 +                                      !!(sta->flags & sta_flags[i].flag));
211 +               blobmsg_add_u32(&b, "aid", sta->aid);
212 +               blobmsg_close_table(&b, c);
213 +       }
214 +       blobmsg_close_array(&b, list);
215 +       ubus_send_reply(ctx, req, b.head);
216 +
217 +       return 0;
218 +}
219 +
220 +enum {
221 +       DEL_CLIENT_ADDR,
222 +       DEL_CLIENT_REASON,
223 +       DEL_CLIENT_DEAUTH,
224 +       DEL_CLIENT_BAN_TIME,
225 +       __DEL_CLIENT_MAX
226 +};
227 +
228 +static const struct blobmsg_policy del_policy[__DEL_CLIENT_MAX] = {
229 +       [DEL_CLIENT_ADDR] = { "addr", BLOBMSG_TYPE_STRING },
230 +       [DEL_CLIENT_REASON] = { "reason", BLOBMSG_TYPE_INT32 },
231 +       [DEL_CLIENT_DEAUTH] = { "deauth", BLOBMSG_TYPE_INT8 },
232 +       [DEL_CLIENT_BAN_TIME] = { "ban_time", BLOBMSG_TYPE_INT32 },
233 +};
234 +
235 +static int
236 +hostapd_bss_del_client(struct ubus_context *ctx, struct ubus_object *obj,
237 +                       struct ubus_request_data *req, const char *method,
238 +                       struct blob_attr *msg)
239 +{
240 +       struct blob_attr *tb[__DEL_CLIENT_MAX];
241 +       struct hostapd_data *hapd = container_of(obj, struct hostapd_data, ubus.obj);
242 +       struct sta_info *sta;
243 +       bool deauth = false;
244 +       int reason;
245 +       u8 addr[ETH_ALEN];
246 +
247 +       blobmsg_parse(del_policy, __DEL_CLIENT_MAX, tb, blob_data(msg), blob_len(msg));
248 +
249 +       if (!tb[DEL_CLIENT_ADDR])
250 +               return UBUS_STATUS_INVALID_ARGUMENT;
251 +
252 +       if (hwaddr_aton(blobmsg_data(tb[DEL_CLIENT_ADDR]), addr))
253 +               return UBUS_STATUS_INVALID_ARGUMENT;
254 +
255 +       if (tb[DEL_CLIENT_REASON])
256 +               reason = blobmsg_get_u32(tb[DEL_CLIENT_REASON]);
257 +
258 +       if (tb[DEL_CLIENT_DEAUTH])
259 +               deauth = blobmsg_get_bool(tb[DEL_CLIENT_DEAUTH]);
260 +
261 +       sta = ap_get_sta(hapd, addr);
262 +       if (sta) {
263 +               if (deauth) {
264 +                       hostapd_drv_sta_deauth(hapd, addr, reason);
265 +                       ap_sta_deauthenticate(hapd, sta, reason);
266 +               } else {
267 +                       hostapd_drv_sta_disassoc(hapd, addr, reason);
268 +                       ap_sta_disassociate(hapd, sta, reason);
269 +               }
270 +       }
271 +
272 +       if (tb[DEL_CLIENT_BAN_TIME])
273 +               hostapd_bss_ban_client(hapd, addr, blobmsg_get_u32(tb[DEL_CLIENT_BAN_TIME]));
274 +
275 +       return 0;
276 +}
277 +
278 +static void
279 +blobmsg_add_macaddr(struct blob_buf *buf, const char *name, const u8 *addr)
280 +{
281 +       char *s;
282 +
283 +       s = blobmsg_alloc_string_buffer(buf, name, 20);
284 +       sprintf(s, MACSTR, MAC2STR(addr));
285 +       blobmsg_add_string_buffer(buf);
286 +}
287 +
288 +static int
289 +hostapd_bss_list_bans(struct ubus_context *ctx, struct ubus_object *obj,
290 +                     struct ubus_request_data *req, const char *method,
291 +                     struct blob_attr *msg)
292 +{
293 +       struct hostapd_data *hapd = container_of(obj, struct hostapd_data, ubus.obj);
294 +       struct ubus_banned_client *ban;
295 +       void *c;
296 +
297 +       blob_buf_init(&b, 0);
298 +       c = blobmsg_open_array(&b, "clients");
299 +       avl_for_each_element(&hapd->ubus.banned, ban, avl)
300 +               blobmsg_add_macaddr(&b, NULL, ban->addr);
301 +       blobmsg_close_array(&b, c);
302 +       ubus_send_reply(ctx, req, b.head);
303 +
304 +       return 0;
305 +}
306 +
307 +static const struct ubus_method bss_methods[] = {
308 +       UBUS_METHOD_NOARG("get_clients", hostapd_bss_get_clients),
309 +       UBUS_METHOD("del_client", hostapd_bss_del_client, del_policy),
310 +       UBUS_METHOD_NOARG("list_bans", hostapd_bss_list_bans),
311 +};
312 +
313 +static struct ubus_object_type bss_object_type =
314 +       UBUS_OBJECT_TYPE("hostapd_bss", bss_methods);
315 +
316 +static int avl_compare_macaddr(const void *k1, const void *k2, void *ptr)
317 +{
318 +       return memcmp(k1, k2, ETH_ALEN);
319 +}
320 +
321 +void hostapd_ubus_add_bss(struct hostapd_data *hapd)
322 +{
323 +       struct ubus_object *obj = &hapd->ubus.obj;
324 +       char *name;
325 +       int ret;
326 +
327 +       if (!hostapd_ubus_init())
328 +               return;
329 +
330 +       if (asprintf(&name, "hostapd.%s", hapd->conf->iface) < 0)
331 +               return;
332 +
333 +       avl_init(&hapd->ubus.banned, avl_compare_macaddr, false, NULL);
334 +       obj->name = name;
335 +       obj->type = &bss_object_type;
336 +       obj->methods = bss_object_type.methods;
337 +       obj->n_methods = bss_object_type.n_methods;
338 +       ret = ubus_add_object(ctx, obj);
339 +       hostapd_ubus_ref_inc();
340 +}
341 +
342 +void hostapd_ubus_free_bss(struct hostapd_data *hapd)
343 +{
344 +       struct ubus_object *obj = &hapd->ubus.obj;
345 +       char *name = (char *) obj->name;
346 +
347 +       if (!ctx)
348 +               return;
349 +
350 +       if (obj->id) {
351 +               ubus_remove_object(ctx, obj);
352 +               hostapd_ubus_ref_dec();
353 +       }
354 +
355 +       free(name);
356 +}
357 +
358 +struct ubus_event_req {
359 +       struct ubus_notify_request nreq;
360 +       bool deny;
361 +};
362 +
363 +static void
364 +ubus_event_cb(struct ubus_notify_request *req, int idx, int ret)
365 +{
366 +       struct ubus_event_req *ureq = container_of(req, struct ubus_event_req, nreq);
367 +
368 +       if (ret)
369 +               ureq->deny = true;
370 +}
371 +
372 +int hostapd_ubus_handle_event(struct hostapd_data *hapd, struct hostapd_ubus_request *req)
373 +{
374 +       struct ubus_banned_client *ban;
375 +       const char *types[HOSTAPD_UBUS_TYPE_MAX] = {
376 +               [HOSTAPD_UBUS_PROBE_REQ] = "probe",
377 +               [HOSTAPD_UBUS_AUTH_REQ] = "auth",
378 +               [HOSTAPD_UBUS_ASSOC_REQ] = "assoc",
379 +       };
380 +       const char *type = "mgmt";
381 +       struct ubus_event_req ureq = {};
382 +       const u8 *addr;
383 +
384 +       if (req->mgmt_frame)
385 +               addr = req->mgmt_frame->sa;
386 +       else
387 +               addr = req->addr;
388 +
389 +       ban = avl_find_element(&hapd->ubus.banned, addr, ban, avl);
390 +       if (ban)
391 +               return -2;
392 +
393 +       if (!hapd->ubus.obj.has_subscribers)
394 +               return 0;
395 +
396 +       if (req->type < ARRAY_SIZE(types))
397 +               type = types[req->type];
398 +
399 +       blob_buf_init(&b, 0);
400 +       blobmsg_add_macaddr(&b, "address", addr);
401 +       if (req->mgmt_frame)
402 +               blobmsg_add_macaddr(&b, "target", req->mgmt_frame->da);
403 +       if (req->frame_info)
404 +               blobmsg_add_u32(&b, "signal", req->frame_info->ssi_signal);
405 +       blobmsg_add_u32(&b, "freq", hapd->iface->freq);
406 +
407 +       if (ubus_notify_async(ctx, &hapd->ubus.obj, type, b.head, &ureq.nreq))
408 +               return 0;
409 +
410 +       ureq.nreq.status_cb = ubus_event_cb;
411 +       ubus_complete_request(ctx, &ureq.nreq.req, 100);
412 +
413 +       if (ureq.deny)
414 +               return -1;
415 +
416 +       return 0;
417 +}
418 --- /dev/null
419 +++ b/src/ap/ubus.h
420 @@ -0,0 +1,78 @@
421 +/*
422 + * hostapd / ubus support
423 + * Copyright (c) 2013, Felix Fietkau <nbd@openwrt.org>
424 + *
425 + * This software may be distributed under the terms of the BSD license.
426 + * See README for more details.
427 + */
428 +#ifndef __HOSTAPD_UBUS_H
429 +#define __HOSTAPD_UBUS_H
430 +
431 +enum hostapd_ubus_event_type {
432 +       HOSTAPD_UBUS_PROBE_REQ,
433 +       HOSTAPD_UBUS_AUTH_REQ,
434 +       HOSTAPD_UBUS_ASSOC_REQ,
435 +       HOSTAPD_UBUS_TYPE_MAX
436 +};
437 +
438 +struct hostapd_ubus_request {
439 +       enum hostapd_ubus_event_type type;
440 +       const struct ieee80211_mgmt *mgmt_frame;
441 +       const struct hostapd_frame_info *frame_info;
442 +       const u8 *addr;
443 +};
444 +
445 +struct hostapd_iface;
446 +struct hostapd_data;
447 +
448 +#ifdef UBUS_SUPPORT
449 +
450 +#include <libubox/avl.h>
451 +#include <libubus.h>
452 +
453 +struct hostapd_ubus_iface {
454 +       struct ubus_object obj;
455 +};
456 +
457 +struct hostapd_ubus_bss {
458 +       struct ubus_object obj;
459 +       struct avl_tree banned;
460 +};
461 +
462 +void hostapd_ubus_add_iface(struct hostapd_iface *iface);
463 +void hostapd_ubus_free_iface(struct hostapd_iface *iface);
464 +void hostapd_ubus_add_bss(struct hostapd_data *hapd);
465 +void hostapd_ubus_free_bss(struct hostapd_data *hapd);
466 +
467 +int hostapd_ubus_handle_event(struct hostapd_data *hapd, struct hostapd_ubus_request *req);
468 +
469 +#else
470 +
471 +struct hostapd_ubus_iface {};
472 +
473 +struct hostapd_ubus_bss {};
474 +
475 +static inline void hostapd_ubus_add_iface(struct hostapd_iface *iface)
476 +{
477 +}
478 +
479 +static inline void hostapd_ubus_free_iface(struct hostapd_iface *iface)
480 +{
481 +}
482 +
483 +static inline void hostapd_ubus_add_bss(struct hostapd_data *hapd)
484 +{
485 +}
486 +
487 +static inline void hostapd_ubus_free_bss(struct hostapd_data *hapd)
488 +{
489 +}
490 +
491 +static inline int hostapd_ubus_handle_event(struct hostapd_data *hapd, struct hostapd_ubus_request *req)
492 +{
493 +       return 0;
494 +}
495 +
496 +#endif
497 +
498 +#endif
499 --- a/src/ap/hostapd.c
500 +++ b/src/ap/hostapd.c
501 @@ -262,6 +262,7 @@ static void hostapd_free_hapd_data(struc
502         hapd->started = 0;
503  
504         wpa_printf(MSG_DEBUG, "%s(%s)", __func__, hapd->conf->iface);
505 +       hostapd_ubus_free_bss(hapd);
506         iapp_deinit(hapd->iapp);
507         hapd->iapp = NULL;
508         accounting_deinit(hapd);
509 @@ -831,6 +832,8 @@ static int hostapd_setup_bss(struct host
510         if (hapd->driver && hapd->driver->set_operstate)
511                 hapd->driver->set_operstate(hapd->drv_priv, 1);
512  
513 +       hostapd_ubus_add_bss(hapd);
514 +
515         return 0;
516  }
517  
518 @@ -1105,6 +1108,7 @@ int hostapd_setup_interface_complete(str
519         if (err)
520                 goto error;
521  
522 +       hostapd_ubus_add_iface(iface);
523         wpa_printf(MSG_DEBUG, "Completing interface initialization");
524         if (iface->conf->channel) {
525  #ifdef NEED_AP_MLME
526 @@ -1213,6 +1217,7 @@ int hostapd_setup_interface_complete(str
527  
528  error:
529         wpa_printf(MSG_ERROR, "Interface initialization failed");
530 +       hostapd_ubus_free_iface(iface);
531         hostapd_set_state(iface, HAPD_IFACE_DISABLED);
532         if (iface->interfaces && iface->interfaces->terminate_on_error)
533                 eloop_terminate();
534 @@ -1534,6 +1539,7 @@ void hostapd_interface_deinit_free(struc
535                    (unsigned int) iface->conf->num_bss);
536         driver = iface->bss[0]->driver;
537         drv_priv = iface->bss[0]->drv_priv;
538 +       hostapd_ubus_free_iface(iface);
539         hostapd_interface_deinit(iface);
540         wpa_printf(MSG_DEBUG, "%s: driver=%p drv_priv=%p -> hapd_deinit",
541                    __func__, driver, drv_priv);
542 --- a/src/ap/ieee802_11.c
543 +++ b/src/ap/ieee802_11.c
544 @@ -535,7 +535,8 @@ static void handle_auth_sae(struct hosta
545  
546  
547  static void handle_auth(struct hostapd_data *hapd,
548 -                       const struct ieee80211_mgmt *mgmt, size_t len)
549 +                       const struct ieee80211_mgmt *mgmt, size_t len,
550 +                       struct hostapd_frame_info *fi)
551  {
552         u16 auth_alg, auth_transaction, status_code;
553         u16 resp = WLAN_STATUS_SUCCESS;
554 @@ -550,6 +551,11 @@ static void handle_auth(struct hostapd_d
555         size_t resp_ies_len = 0;
556         char *identity = NULL;
557         char *radius_cui = NULL;
558 +       struct hostapd_ubus_request req = {
559 +               .type = HOSTAPD_UBUS_AUTH_REQ,
560 +               .mgmt_frame = mgmt,
561 +               .frame_info = fi,
562 +       };
563  
564         if (len < IEEE80211_HDRLEN + sizeof(mgmt->u.auth)) {
565                 wpa_printf(MSG_INFO, "handle_auth - too short payload (len=%lu)",
566 @@ -633,6 +639,14 @@ static void handle_auth(struct hostapd_d
567                 resp = WLAN_STATUS_UNSPECIFIED_FAILURE;
568                 goto fail;
569         }
570 +
571 +       if (hostapd_ubus_handle_event(hapd, &req)) {
572 +               wpa_printf(MSG_DEBUG, "Station " MACSTR " rejected by ubus handler.\n",
573 +                      MAC2STR(mgmt->sa));
574 +               resp = WLAN_STATUS_UNSPECIFIED_FAILURE;
575 +               goto fail;
576 +       }
577 +
578         if (res == HOSTAPD_ACL_PENDING) {
579                 wpa_printf(MSG_DEBUG, "Authentication frame from " MACSTR
580                            " waiting for an external authentication",
581 @@ -1245,13 +1259,18 @@ static void send_assoc_resp(struct hosta
582  
583  static void handle_assoc(struct hostapd_data *hapd,
584                          const struct ieee80211_mgmt *mgmt, size_t len,
585 -                        int reassoc)
586 +                        int reassoc, struct hostapd_frame_info *fi)
587  {
588         u16 capab_info, listen_interval;
589         u16 resp = WLAN_STATUS_SUCCESS;
590         const u8 *pos;
591         int left, i;
592         struct sta_info *sta;
593 +       struct hostapd_ubus_request req = {
594 +               .type = HOSTAPD_UBUS_ASSOC_REQ,
595 +               .mgmt_frame = mgmt,
596 +               .frame_info = fi,
597 +       };
598  
599         if (len < IEEE80211_HDRLEN + (reassoc ? sizeof(mgmt->u.reassoc_req) :
600                                       sizeof(mgmt->u.assoc_req))) {
601 @@ -1350,6 +1369,13 @@ static void handle_assoc(struct hostapd_
602                 goto fail;
603         }
604  
605 +       if (hostapd_ubus_handle_event(hapd, &req)) {
606 +               wpa_printf(MSG_DEBUG, "Station " MACSTR " assoc rejected by ubus handler.\n",
607 +                      MAC2STR(mgmt->sa));
608 +               resp = WLAN_STATUS_UNSPECIFIED_FAILURE;
609 +               goto fail;
610 +       }
611 +
612         sta->capability = capab_info;
613         sta->listen_interval = listen_interval;
614  
615 @@ -1759,7 +1785,7 @@ void ieee802_11_mgmt(struct hostapd_data
616  
617  
618         if (stype == WLAN_FC_STYPE_PROBE_REQ) {
619 -               handle_probe_req(hapd, mgmt, len, fi->ssi_signal);
620 +               handle_probe_req(hapd, mgmt, len, fi);
621                 return;
622         }
623  
624 @@ -1774,15 +1800,15 @@ void ieee802_11_mgmt(struct hostapd_data
625         switch (stype) {
626         case WLAN_FC_STYPE_AUTH:
627                 wpa_printf(MSG_DEBUG, "mgmt::auth");
628 -               handle_auth(hapd, mgmt, len);
629 +               handle_auth(hapd, mgmt, len, fi);
630                 break;
631         case WLAN_FC_STYPE_ASSOC_REQ:
632                 wpa_printf(MSG_DEBUG, "mgmt::assoc_req");
633 -               handle_assoc(hapd, mgmt, len, 0);
634 +               handle_assoc(hapd, mgmt, len, 0, fi);
635                 break;
636         case WLAN_FC_STYPE_REASSOC_REQ:
637                 wpa_printf(MSG_DEBUG, "mgmt::reassoc_req");
638 -               handle_assoc(hapd, mgmt, len, 1);
639 +               handle_assoc(hapd, mgmt, len, 1, fi);
640                 break;
641         case WLAN_FC_STYPE_DISASSOC:
642                 wpa_printf(MSG_DEBUG, "mgmt::disassoc");
643 --- a/src/ap/beacon.c
644 +++ b/src/ap/beacon.c
645 @@ -398,7 +398,7 @@ static enum ssid_match_result ssid_match
646  
647  void handle_probe_req(struct hostapd_data *hapd,
648                       const struct ieee80211_mgmt *mgmt, size_t len,
649 -                     int ssi_signal)
650 +                     struct hostapd_frame_info *fi)
651  {
652         u8 *resp;
653         struct ieee802_11_elems elems;
654 @@ -406,8 +406,14 @@ void handle_probe_req(struct hostapd_dat
655         size_t ie_len;
656         struct sta_info *sta = NULL;
657         size_t i, resp_len;
658 +       int ssi_signal = fi->ssi_signal;
659         int noack;
660         enum ssid_match_result res;
661 +       struct hostapd_ubus_request req = {
662 +               .type = HOSTAPD_UBUS_PROBE_REQ,
663 +               .mgmt_frame = mgmt,
664 +               .frame_info = fi,
665 +       };
666  
667         ie = mgmt->u.probe_req.variable;
668         if (len < IEEE80211_HDRLEN + sizeof(mgmt->u.probe_req))
669 @@ -546,6 +552,12 @@ void handle_probe_req(struct hostapd_dat
670         }
671  #endif /* CONFIG_P2P */
672  
673 +       if (hostapd_ubus_handle_event(hapd, &req)) {
674 +               wpa_printf(MSG_DEBUG, "Probe request for " MACSTR " rejected by ubus handler.\n",
675 +                      MAC2STR(mgmt->sa));
676 +               return;
677 +       }
678 +
679         /* TODO: verify that supp_rates contains at least one matching rate
680          * with AP configuration */
681  
682 --- a/src/ap/beacon.h
683 +++ b/src/ap/beacon.h
684 @@ -20,7 +20,7 @@ struct ieee80211_mgmt;
685  
686  void handle_probe_req(struct hostapd_data *hapd,
687                       const struct ieee80211_mgmt *mgmt, size_t len,
688 -                     int ssi_signal);
689 +                     struct hostapd_frame_info *fi);
690  void ieee802_11_set_beacon(struct hostapd_data *hapd);
691  void ieee802_11_set_beacons(struct hostapd_iface *iface);
692  void ieee802_11_update_beacons(struct hostapd_iface *iface);