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