blob: d60555a87bde2aa7cce4c0860c7ee53e668380c7 [file] [log] [blame]
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001/*
2 * AP mode helper functions
3 * Copyright (c) 2009, Jouni Malinen <j@w1.fi>
4 *
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08005 * This software may be distributed under the terms of the BSD license.
6 * See README for more details.
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07007 */
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
17int hostapd_register_probereq_cb(struct hostapd_data *hapd,
18 int (*cb)(void *ctx, const u8 *sa,
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -080019 const u8 *da, const u8 *bssid,
Dmitry Shmidt04949592012-07-19 12:16:46 -070020 const u8 *ie, size_t ie_len,
21 int ssi_signal),
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070022 void *ctx)
23{
24 struct hostapd_probereq_cb *n;
25
Dmitry Shmidt61d9df32012-08-29 16:22:06 -070026 n = os_realloc_array(hapd->probereq_cb, hapd->num_probereq_cb + 1,
27 sizeof(struct hostapd_probereq_cb));
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070028 if (n == NULL)
29 return -1;
30
31 hapd->probereq_cb = n;
32 n = &hapd->probereq_cb[hapd->num_probereq_cb];
33 hapd->num_probereq_cb++;
34
35 n->cb = cb;
36 n->ctx = ctx;
37
38 return 0;
39}
40
41
42struct prune_data {
43 struct hostapd_data *hapd;
44 const u8 *addr;
45};
46
47static int prune_associations(struct hostapd_iface *iface, void *ctx)
48{
49 struct prune_data *data = ctx;
50 struct sta_info *osta;
51 struct hostapd_data *ohapd;
52 size_t j;
53
54 for (j = 0; j < iface->num_bss; j++) {
55 ohapd = iface->bss[j];
56 if (ohapd == data->hapd)
57 continue;
58 osta = ap_get_sta(ohapd, data->addr);
59 if (!osta)
60 continue;
61
Dmitry Shmidt83474442015-04-15 13:47:09 -070062 wpa_printf(MSG_INFO, "%s: Prune association for " MACSTR,
63 ohapd->conf->iface, MAC2STR(osta->addr));
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070064 ap_sta_disassociate(ohapd, osta, WLAN_REASON_UNSPECIFIED);
65 }
66
67 return 0;
68}
69
70/**
71 * hostapd_prune_associations - Remove extraneous associations
72 * @hapd: Pointer to BSS data for the most recent association
73 * @addr: Associated STA address
74 *
75 * This function looks through all radios and BSS's for previous
76 * (stale) associations of STA. If any are found they are removed.
77 */
78void hostapd_prune_associations(struct hostapd_data *hapd, const u8 *addr)
79{
80 struct prune_data data;
81 data.hapd = hapd;
82 data.addr = addr;
Dmitry Shmidt61d9df32012-08-29 16:22:06 -070083 if (hapd->iface->interfaces &&
84 hapd->iface->interfaces->for_each_interface)
85 hapd->iface->interfaces->for_each_interface(
86 hapd->iface->interfaces, prune_associations, &data);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070087}