xref: /freebsd/contrib/wpa/src/ap/utils.c (revision e28a4053b110e06768631ac8401ed4a3c05e68a5)
1*e28a4053SRui Paulo /*
2*e28a4053SRui Paulo  * AP mode helper functions
3*e28a4053SRui Paulo  * Copyright (c) 2009, Jouni Malinen <j@w1.fi>
4*e28a4053SRui Paulo  *
5*e28a4053SRui Paulo  * This program is free software; you can redistribute it and/or modify
6*e28a4053SRui Paulo  * it under the terms of the GNU General Public License version 2 as
7*e28a4053SRui Paulo  * published by the Free Software Foundation.
8*e28a4053SRui Paulo  *
9*e28a4053SRui Paulo  * Alternatively, this software may be distributed under the terms of BSD
10*e28a4053SRui Paulo  * license.
11*e28a4053SRui Paulo  *
12*e28a4053SRui Paulo  * See README and COPYING for more details.
13*e28a4053SRui Paulo  */
14*e28a4053SRui Paulo 
15*e28a4053SRui Paulo #include "includes.h"
16*e28a4053SRui Paulo 
17*e28a4053SRui Paulo #include "common.h"
18*e28a4053SRui Paulo #include "common/ieee802_11_defs.h"
19*e28a4053SRui Paulo #include "sta_info.h"
20*e28a4053SRui Paulo #include "hostapd.h"
21*e28a4053SRui Paulo 
22*e28a4053SRui Paulo 
23*e28a4053SRui Paulo int hostapd_register_probereq_cb(struct hostapd_data *hapd,
24*e28a4053SRui Paulo 				 int (*cb)(void *ctx, const u8 *sa,
25*e28a4053SRui Paulo 					   const u8 *ie, size_t ie_len),
26*e28a4053SRui Paulo 				 void *ctx)
27*e28a4053SRui Paulo {
28*e28a4053SRui Paulo 	struct hostapd_probereq_cb *n;
29*e28a4053SRui Paulo 
30*e28a4053SRui Paulo 	n = os_realloc(hapd->probereq_cb, (hapd->num_probereq_cb + 1) *
31*e28a4053SRui Paulo 		       sizeof(struct hostapd_probereq_cb));
32*e28a4053SRui Paulo 	if (n == NULL)
33*e28a4053SRui Paulo 		return -1;
34*e28a4053SRui Paulo 
35*e28a4053SRui Paulo 	hapd->probereq_cb = n;
36*e28a4053SRui Paulo 	n = &hapd->probereq_cb[hapd->num_probereq_cb];
37*e28a4053SRui Paulo 	hapd->num_probereq_cb++;
38*e28a4053SRui Paulo 
39*e28a4053SRui Paulo 	n->cb = cb;
40*e28a4053SRui Paulo 	n->ctx = ctx;
41*e28a4053SRui Paulo 
42*e28a4053SRui Paulo 	return 0;
43*e28a4053SRui Paulo }
44*e28a4053SRui Paulo 
45*e28a4053SRui Paulo 
46*e28a4053SRui Paulo struct prune_data {
47*e28a4053SRui Paulo 	struct hostapd_data *hapd;
48*e28a4053SRui Paulo 	const u8 *addr;
49*e28a4053SRui Paulo };
50*e28a4053SRui Paulo 
51*e28a4053SRui Paulo static int prune_associations(struct hostapd_iface *iface, void *ctx)
52*e28a4053SRui Paulo {
53*e28a4053SRui Paulo 	struct prune_data *data = ctx;
54*e28a4053SRui Paulo 	struct sta_info *osta;
55*e28a4053SRui Paulo 	struct hostapd_data *ohapd;
56*e28a4053SRui Paulo 	size_t j;
57*e28a4053SRui Paulo 
58*e28a4053SRui Paulo 	for (j = 0; j < iface->num_bss; j++) {
59*e28a4053SRui Paulo 		ohapd = iface->bss[j];
60*e28a4053SRui Paulo 		if (ohapd == data->hapd)
61*e28a4053SRui Paulo 			continue;
62*e28a4053SRui Paulo 		osta = ap_get_sta(ohapd, data->addr);
63*e28a4053SRui Paulo 		if (!osta)
64*e28a4053SRui Paulo 			continue;
65*e28a4053SRui Paulo 
66*e28a4053SRui Paulo 		ap_sta_disassociate(ohapd, osta, WLAN_REASON_UNSPECIFIED);
67*e28a4053SRui Paulo 	}
68*e28a4053SRui Paulo 
69*e28a4053SRui Paulo 	return 0;
70*e28a4053SRui Paulo }
71*e28a4053SRui Paulo 
72*e28a4053SRui Paulo /**
73*e28a4053SRui Paulo  * hostapd_prune_associations - Remove extraneous associations
74*e28a4053SRui Paulo  * @hapd: Pointer to BSS data for the most recent association
75*e28a4053SRui Paulo  * @addr: Associated STA address
76*e28a4053SRui Paulo  *
77*e28a4053SRui Paulo  * This function looks through all radios and BSS's for previous
78*e28a4053SRui Paulo  * (stale) associations of STA. If any are found they are removed.
79*e28a4053SRui Paulo  */
80*e28a4053SRui Paulo void hostapd_prune_associations(struct hostapd_data *hapd, const u8 *addr)
81*e28a4053SRui Paulo {
82*e28a4053SRui Paulo 	struct prune_data data;
83*e28a4053SRui Paulo 	data.hapd = hapd;
84*e28a4053SRui Paulo 	data.addr = addr;
85*e28a4053SRui Paulo 	if (hapd->iface->for_each_interface)
86*e28a4053SRui Paulo 		hapd->iface->for_each_interface(hapd->iface->interfaces,
87*e28a4053SRui Paulo 						prune_associations, &data);
88*e28a4053SRui Paulo }
89