blob: e93e53171cda47731016e7ecb72273ddf15ecee0 [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"
Dmitry Shmidtd80a4012015-11-05 16:35:40 -080013#include "fst/fst.h"
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070014#include "sta_info.h"
15#include "hostapd.h"
16
17
18int hostapd_register_probereq_cb(struct hostapd_data *hapd,
19 int (*cb)(void *ctx, const u8 *sa,
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -080020 const u8 *da, const u8 *bssid,
Dmitry Shmidt04949592012-07-19 12:16:46 -070021 const u8 *ie, size_t ie_len,
22 int ssi_signal),
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070023 void *ctx)
24{
25 struct hostapd_probereq_cb *n;
26
Dmitry Shmidt61d9df32012-08-29 16:22:06 -070027 n = os_realloc_array(hapd->probereq_cb, hapd->num_probereq_cb + 1,
28 sizeof(struct hostapd_probereq_cb));
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070029 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
43struct prune_data {
44 struct hostapd_data *hapd;
45 const u8 *addr;
Sunil Ravi2a14cf12023-11-21 00:54:38 +000046 int mld_assoc_link_id;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070047};
48
49static int prune_associations(struct hostapd_iface *iface, void *ctx)
50{
51 struct prune_data *data = ctx;
52 struct sta_info *osta;
53 struct hostapd_data *ohapd;
54 size_t j;
55
56 for (j = 0; j < iface->num_bss; j++) {
57 ohapd = iface->bss[j];
58 if (ohapd == data->hapd)
59 continue;
Hai Shalomfdcde762020-04-02 11:19:20 -070060#ifdef CONFIG_TESTING_OPTIONS
61 if (ohapd->conf->skip_prune_assoc)
62 continue;
63#endif /* CONFIG_TESTING_OPTIONS */
Dmitry Shmidtd80a4012015-11-05 16:35:40 -080064#ifdef CONFIG_FST
65 /* Don't prune STAs belong to same FST */
66 if (ohapd->iface->fst &&
67 data->hapd->iface->fst &&
68 fst_are_ifaces_aggregated(ohapd->iface->fst,
69 data->hapd->iface->fst))
70 continue;
71#endif /* CONFIG_FST */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070072 osta = ap_get_sta(ohapd, data->addr);
73 if (!osta)
74 continue;
75
Sunil Ravi2a14cf12023-11-21 00:54:38 +000076#ifdef CONFIG_IEEE80211BE
77 if (data->mld_assoc_link_id >= 0 &&
78 osta->mld_assoc_link_id == data->mld_assoc_link_id)
79 continue;
80#endif /* CONFIG_IEEE80211BE */
81
Dmitry Shmidt83474442015-04-15 13:47:09 -070082 wpa_printf(MSG_INFO, "%s: Prune association for " MACSTR,
83 ohapd->conf->iface, MAC2STR(osta->addr));
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070084 ap_sta_disassociate(ohapd, osta, WLAN_REASON_UNSPECIFIED);
85 }
86
87 return 0;
88}
89
90/**
91 * hostapd_prune_associations - Remove extraneous associations
92 * @hapd: Pointer to BSS data for the most recent association
93 * @addr: Associated STA address
Sunil Ravi2a14cf12023-11-21 00:54:38 +000094 * @mld_assoc_link_id: MLD link id used for association or -1 for non MLO
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070095 *
96 * This function looks through all radios and BSS's for previous
97 * (stale) associations of STA. If any are found they are removed.
98 */
Sunil Ravi2a14cf12023-11-21 00:54:38 +000099void hostapd_prune_associations(struct hostapd_data *hapd, const u8 *addr,
100 int mld_assoc_link_id)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700101{
102 struct prune_data data;
Sunil Ravi2a14cf12023-11-21 00:54:38 +0000103
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700104 data.hapd = hapd;
105 data.addr = addr;
Sunil Ravi2a14cf12023-11-21 00:54:38 +0000106 data.mld_assoc_link_id = mld_assoc_link_id;
107
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700108 if (hapd->iface->interfaces &&
109 hapd->iface->interfaces->for_each_interface)
110 hapd->iface->interfaces->for_each_interface(
111 hapd->iface->interfaces, prune_associations, &data);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700112}