1 /*
2 * AP mode helper functions
3 * Copyright (c) 2009, Jouni Malinen <j@w1.fi>
4 *
5 * This software may be distributed under the terms of the BSD license.
6 * See README for more details.
7 */
8
9 #include "includes.h"
10
11 #include "common.h"
12 #include "common/ieee802_11_defs.h"
13 #include "fst/fst.h"
14 #include "sta_info.h"
15 #include "hostapd.h"
16
17 #ifndef EXT_CODE_CROP
hostapd_register_probereq_cb(struct hostapd_data * hapd,int (* cb)(void * ctx,const u8 * sa,const u8 * da,const u8 * bssid,const u8 * ie,size_t ie_len,int ssi_signal),void * ctx)18 int hostapd_register_probereq_cb(struct hostapd_data *hapd,
19 int (*cb)(void *ctx, const u8 *sa,
20 const u8 *da, const u8 *bssid,
21 const u8 *ie, size_t ie_len,
22 int ssi_signal),
23 void *ctx)
24 {
25 struct hostapd_probereq_cb *n;
26
27 n = os_realloc_array(hapd->probereq_cb, hapd->num_probereq_cb + 1,
28 sizeof(struct hostapd_probereq_cb));
29 if (n == NULL)
30 return -1;
31
32 hapd->probereq_cb = n;
33 n = &hapd->probereq_cb[hapd->num_probereq_cb];
34 hapd->num_probereq_cb++;
35
36 n->cb = cb;
37 n->ctx = ctx;
38
39 return 0;
40 }
41 #endif /* EXT_CODE_CROP */
42
43 struct prune_data {
44 struct hostapd_data *hapd;
45 const u8 *addr;
46 };
47
prune_associations(struct hostapd_iface * iface,void * ctx)48 static int prune_associations(struct hostapd_iface *iface, void *ctx)
49 {
50 struct prune_data *data = ctx;
51 struct sta_info *osta;
52 struct hostapd_data *ohapd;
53 size_t j;
54
55 for (j = 0; j < iface->num_bss; j++) {
56 ohapd = iface->bss[j];
57 if (ohapd == data->hapd)
58 continue;
59 #ifdef CONFIG_TESTING_OPTIONS
60 if (ohapd->conf->skip_prune_assoc)
61 continue;
62 #endif /* CONFIG_TESTING_OPTIONS */
63 #ifdef CONFIG_FST
64 /* Don't prune STAs belong to same FST */
65 if (ohapd->iface->fst &&
66 data->hapd->iface->fst &&
67 fst_are_ifaces_aggregated(ohapd->iface->fst,
68 data->hapd->iface->fst))
69 continue;
70 #endif /* CONFIG_FST */
71 osta = ap_get_sta(ohapd, data->addr);
72 if (!osta)
73 continue;
74
75 wpa_warning_buf(MSG_INFO, "%s: Prune association for ",
76 ohapd->conf->iface, strlen(ohapd->conf->iface));
77 wpa_warning_log4(MSG_INFO, "%02x:xx:xx:%02x:%02x:%02x",
78 (osta->addr)[0], (osta->addr)[3], (osta->addr)[4], (osta->addr)[5]);
79 ap_sta_disassociate(ohapd, osta, WLAN_REASON_UNSPECIFIED);
80 }
81
82 return 0;
83 }
84
85 /**
86 * hostapd_prune_associations - Remove extraneous associations
87 * @hapd: Pointer to BSS data for the most recent association
88 * @addr: Associated STA address
89 *
90 * This function looks through all radios and BSS's for previous
91 * (stale) associations of STA. If any are found they are removed.
92 */
hostapd_prune_associations(struct hostapd_data * hapd,const u8 * addr)93 void hostapd_prune_associations(struct hostapd_data *hapd, const u8 *addr)
94 {
95 struct prune_data data;
96 data.hapd = hapd;
97 data.addr = addr;
98 if (hapd->iface->interfaces &&
99 hapd->iface->interfaces->for_each_interface)
100 hapd->iface->interfaces->for_each_interface(
101 hapd->iface->interfaces, prune_associations, &data);
102 }
103