Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1 | /* |
| 2 | * AP mode helper functions |
| 3 | * Copyright (c) 2009, Jouni Malinen <j@w1.fi> |
| 4 | * |
Dmitry Shmidt | c5ec7f5 | 2012-03-06 16:33:24 -0800 | [diff] [blame] | 5 | * This software may be distributed under the terms of the BSD license. |
| 6 | * See README for more details. |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7 | */ |
| 8 | |
| 9 | #include "includes.h" |
| 10 | |
| 11 | #include "common.h" |
| 12 | #include "common/ieee802_11_defs.h" |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 13 | #include "fst/fst.h" |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 14 | #include "sta_info.h" |
| 15 | #include "hostapd.h" |
| 16 | |
| 17 | |
| 18 | int hostapd_register_probereq_cb(struct hostapd_data *hapd, |
| 19 | int (*cb)(void *ctx, const u8 *sa, |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 20 | const u8 *da, const u8 *bssid, |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 21 | const u8 *ie, size_t ie_len, |
| 22 | int ssi_signal), |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 23 | void *ctx) |
| 24 | { |
| 25 | struct hostapd_probereq_cb *n; |
| 26 | |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 27 | n = os_realloc_array(hapd->probereq_cb, hapd->num_probereq_cb + 1, |
| 28 | sizeof(struct hostapd_probereq_cb)); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 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 | |
| 42 | |
| 43 | struct prune_data { |
| 44 | struct hostapd_data *hapd; |
| 45 | const u8 *addr; |
| 46 | }; |
| 47 | |
| 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; |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 59 | #ifdef CONFIG_FST |
| 60 | /* Don't prune STAs belong to same FST */ |
| 61 | if (ohapd->iface->fst && |
| 62 | data->hapd->iface->fst && |
| 63 | fst_are_ifaces_aggregated(ohapd->iface->fst, |
| 64 | data->hapd->iface->fst)) |
| 65 | continue; |
| 66 | #endif /* CONFIG_FST */ |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 67 | osta = ap_get_sta(ohapd, data->addr); |
| 68 | if (!osta) |
| 69 | continue; |
| 70 | |
Dmitry Shmidt | 8347444 | 2015-04-15 13:47:09 -0700 | [diff] [blame] | 71 | wpa_printf(MSG_INFO, "%s: Prune association for " MACSTR, |
| 72 | ohapd->conf->iface, MAC2STR(osta->addr)); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 73 | ap_sta_disassociate(ohapd, osta, WLAN_REASON_UNSPECIFIED); |
| 74 | } |
| 75 | |
| 76 | return 0; |
| 77 | } |
| 78 | |
| 79 | /** |
| 80 | * hostapd_prune_associations - Remove extraneous associations |
| 81 | * @hapd: Pointer to BSS data for the most recent association |
| 82 | * @addr: Associated STA address |
| 83 | * |
| 84 | * This function looks through all radios and BSS's for previous |
| 85 | * (stale) associations of STA. If any are found they are removed. |
| 86 | */ |
| 87 | void hostapd_prune_associations(struct hostapd_data *hapd, const u8 *addr) |
| 88 | { |
| 89 | struct prune_data data; |
| 90 | data.hapd = hapd; |
| 91 | data.addr = addr; |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 92 | if (hapd->iface->interfaces && |
| 93 | hapd->iface->interfaces->for_each_interface) |
| 94 | hapd->iface->interfaces->for_each_interface( |
| 95 | hapd->iface->interfaces, prune_associations, &data); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 96 | } |