2 * wpa_supplicant - Temporary BSSID blacklist
3 * Copyright (c) 2003-2007, Jouni Malinen <j@w1.fi>
5 * This software may be distributed under the terms of the BSD license.
6 * See README for more details.
12 #include "wpa_supplicant_i.h"
13 #include "blacklist.h"
16 * wpa_blacklist_get - Get the blacklist entry for a BSSID
17 * @wpa_s: Pointer to wpa_supplicant data
19 * Returns: Matching blacklist entry for the BSSID or %NULL if not found
21 struct wpa_blacklist * wpa_blacklist_get(struct wpa_supplicant *wpa_s,
24 struct wpa_blacklist *e;
26 if (wpa_s == NULL || bssid == NULL)
31 if (os_memcmp(e->bssid, bssid, ETH_ALEN) == 0)
41 * wpa_blacklist_add - Add an BSSID to the blacklist
42 * @wpa_s: Pointer to wpa_supplicant data
43 * @bssid: BSSID to be added to the blacklist
44 * Returns: Current blacklist count on success, -1 on failure
46 * This function adds the specified BSSID to the blacklist or increases the
47 * blacklist count if the BSSID was already listed. It should be called when
48 * an association attempt fails either due to the selected BSS rejecting
49 * association or due to timeout.
51 * This blacklist is used to force %wpa_supplicant to go through all available
52 * BSSes before retrying to associate with an BSS that rejected or timed out
53 * association. It does not prevent the listed BSS from being used; it only
54 * changes the order in which they are tried.
56 int wpa_blacklist_add(struct wpa_supplicant *wpa_s, const u8 *bssid)
58 struct wpa_blacklist *e;
60 if (wpa_s == NULL || bssid == NULL)
63 e = wpa_blacklist_get(wpa_s, bssid);
66 wpa_printf(MSG_DEBUG, "BSSID " MACSTR " blacklist count "
68 MAC2STR(bssid), e->count);
72 e = os_zalloc(sizeof(*e));
75 os_memcpy(e->bssid, bssid, ETH_ALEN);
77 e->next = wpa_s->blacklist;
79 wpa_printf(MSG_DEBUG, "Added BSSID " MACSTR " into blacklist",
87 * wpa_blacklist_del - Remove an BSSID from the blacklist
88 * @wpa_s: Pointer to wpa_supplicant data
89 * @bssid: BSSID to be removed from the blacklist
90 * Returns: 0 on success, -1 on failure
92 int wpa_blacklist_del(struct wpa_supplicant *wpa_s, const u8 *bssid)
94 struct wpa_blacklist *e, *prev = NULL;
96 if (wpa_s == NULL || bssid == NULL)
101 if (os_memcmp(e->bssid, bssid, ETH_ALEN) == 0) {
103 wpa_s->blacklist = e->next;
105 prev->next = e->next;
107 wpa_printf(MSG_DEBUG, "Removed BSSID " MACSTR " from "
108 "blacklist", MAC2STR(bssid));
120 * wpa_blacklist_clear - Clear the blacklist of all entries
121 * @wpa_s: Pointer to wpa_supplicant data
123 void wpa_blacklist_clear(struct wpa_supplicant *wpa_s)
125 struct wpa_blacklist *e, *prev;
128 e = wpa_s->blacklist;
129 wpa_s->blacklist = NULL;
131 if (e->count > max_count)
132 max_count = e->count;
135 wpa_printf(MSG_DEBUG, "Removed BSSID " MACSTR " from "
136 "blacklist (clear)", MAC2STR(prev->bssid));
140 wpa_s->extra_blacklist_count += max_count;