1214501Srpaulo/*
2214501Srpaulo * AP mode helper functions
3214501Srpaulo * Copyright (c) 2009, Jouni Malinen <j@w1.fi>
4214501Srpaulo *
5252726Srpaulo * This software may be distributed under the terms of the BSD license.
6252726Srpaulo * See README for more details.
7214501Srpaulo */
8214501Srpaulo
9214501Srpaulo#include "includes.h"
10214501Srpaulo
11214501Srpaulo#include "common.h"
12214501Srpaulo#include "common/ieee802_11_defs.h"
13214501Srpaulo#include "sta_info.h"
14214501Srpaulo#include "hostapd.h"
15214501Srpaulo
16214501Srpaulo
17214501Srpauloint hostapd_register_probereq_cb(struct hostapd_data *hapd,
18214501Srpaulo				 int (*cb)(void *ctx, const u8 *sa,
19252726Srpaulo					   const u8 *da, const u8 *bssid,
20252726Srpaulo					   const u8 *ie, size_t ie_len,
21252726Srpaulo					   int ssi_signal),
22214501Srpaulo				 void *ctx)
23214501Srpaulo{
24214501Srpaulo	struct hostapd_probereq_cb *n;
25214501Srpaulo
26252726Srpaulo	n = os_realloc_array(hapd->probereq_cb, hapd->num_probereq_cb + 1,
27252726Srpaulo			     sizeof(struct hostapd_probereq_cb));
28214501Srpaulo	if (n == NULL)
29214501Srpaulo		return -1;
30214501Srpaulo
31214501Srpaulo	hapd->probereq_cb = n;
32214501Srpaulo	n = &hapd->probereq_cb[hapd->num_probereq_cb];
33214501Srpaulo	hapd->num_probereq_cb++;
34214501Srpaulo
35214501Srpaulo	n->cb = cb;
36214501Srpaulo	n->ctx = ctx;
37214501Srpaulo
38214501Srpaulo	return 0;
39214501Srpaulo}
40214501Srpaulo
41214501Srpaulo
42214501Srpaulostruct prune_data {
43214501Srpaulo	struct hostapd_data *hapd;
44214501Srpaulo	const u8 *addr;
45214501Srpaulo};
46214501Srpaulo
47214501Srpaulostatic int prune_associations(struct hostapd_iface *iface, void *ctx)
48214501Srpaulo{
49214501Srpaulo	struct prune_data *data = ctx;
50214501Srpaulo	struct sta_info *osta;
51214501Srpaulo	struct hostapd_data *ohapd;
52214501Srpaulo	size_t j;
53214501Srpaulo
54214501Srpaulo	for (j = 0; j < iface->num_bss; j++) {
55214501Srpaulo		ohapd = iface->bss[j];
56214501Srpaulo		if (ohapd == data->hapd)
57214501Srpaulo			continue;
58214501Srpaulo		osta = ap_get_sta(ohapd, data->addr);
59214501Srpaulo		if (!osta)
60214501Srpaulo			continue;
61214501Srpaulo
62214501Srpaulo		ap_sta_disassociate(ohapd, osta, WLAN_REASON_UNSPECIFIED);
63214501Srpaulo	}
64214501Srpaulo
65214501Srpaulo	return 0;
66214501Srpaulo}
67214501Srpaulo
68214501Srpaulo/**
69214501Srpaulo * hostapd_prune_associations - Remove extraneous associations
70214501Srpaulo * @hapd: Pointer to BSS data for the most recent association
71214501Srpaulo * @addr: Associated STA address
72214501Srpaulo *
73214501Srpaulo * This function looks through all radios and BSS's for previous
74214501Srpaulo * (stale) associations of STA. If any are found they are removed.
75214501Srpaulo */
76214501Srpaulovoid hostapd_prune_associations(struct hostapd_data *hapd, const u8 *addr)
77214501Srpaulo{
78214501Srpaulo	struct prune_data data;
79214501Srpaulo	data.hapd = hapd;
80214501Srpaulo	data.addr = addr;
81252726Srpaulo	if (hapd->iface->interfaces &&
82252726Srpaulo	    hapd->iface->interfaces->for_each_interface)
83252726Srpaulo		hapd->iface->interfaces->for_each_interface(
84252726Srpaulo			hapd->iface->interfaces, prune_associations, &data);
85214501Srpaulo}
86