Remove the GPL notification from files contributed by Jouni Malinen
[mech_eap.git] / src / ap / utils.c
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 "sta_info.h"
14 #include "hostapd.h"
15
16
17 int hostapd_register_probereq_cb(struct hostapd_data *hapd,
18                                  int (*cb)(void *ctx, const u8 *sa,
19                                            const u8 *da, const u8 *bssid,
20                                            const u8 *ie, size_t ie_len),
21                                  void *ctx)
22 {
23         struct hostapd_probereq_cb *n;
24
25         n = os_realloc(hapd->probereq_cb, (hapd->num_probereq_cb + 1) *
26                        sizeof(struct hostapd_probereq_cb));
27         if (n == NULL)
28                 return -1;
29
30         hapd->probereq_cb = n;
31         n = &hapd->probereq_cb[hapd->num_probereq_cb];
32         hapd->num_probereq_cb++;
33
34         n->cb = cb;
35         n->ctx = ctx;
36
37         return 0;
38 }
39
40
41 struct prune_data {
42         struct hostapd_data *hapd;
43         const u8 *addr;
44 };
45
46 static int prune_associations(struct hostapd_iface *iface, void *ctx)
47 {
48         struct prune_data *data = ctx;
49         struct sta_info *osta;
50         struct hostapd_data *ohapd;
51         size_t j;
52
53         for (j = 0; j < iface->num_bss; j++) {
54                 ohapd = iface->bss[j];
55                 if (ohapd == data->hapd)
56                         continue;
57                 osta = ap_get_sta(ohapd, data->addr);
58                 if (!osta)
59                         continue;
60
61                 ap_sta_disassociate(ohapd, osta, WLAN_REASON_UNSPECIFIED);
62         }
63
64         return 0;
65 }
66
67 /**
68  * hostapd_prune_associations - Remove extraneous associations
69  * @hapd: Pointer to BSS data for the most recent association
70  * @addr: Associated STA address
71  *
72  * This function looks through all radios and BSS's for previous
73  * (stale) associations of STA. If any are found they are removed.
74  */
75 void hostapd_prune_associations(struct hostapd_data *hapd, const u8 *addr)
76 {
77         struct prune_data data;
78         data.hapd = hapd;
79         data.addr = addr;
80         if (hapd->iface->for_each_interface)
81                 hapd->iface->for_each_interface(hapd->iface->interfaces,
82                                                 prune_associations, &data);
83 }