2008-02-28 02:34:43 +01:00
|
|
|
/*
|
|
|
|
* wpa_supplicant - Temporary BSSID blacklist
|
|
|
|
* Copyright (c) 2003-2007, Jouni Malinen <j@w1.fi>
|
|
|
|
*
|
2012-02-11 15:46:35 +01:00
|
|
|
* This software may be distributed under the terms of the BSD license.
|
|
|
|
* See README for more details.
|
2008-02-28 02:34:43 +01:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include "includes.h"
|
|
|
|
|
|
|
|
#include "common.h"
|
|
|
|
#include "wpa_supplicant_i.h"
|
|
|
|
#include "blacklist.h"
|
|
|
|
|
|
|
|
/**
|
|
|
|
* wpa_blacklist_get - Get the blacklist entry for a BSSID
|
|
|
|
* @wpa_s: Pointer to wpa_supplicant data
|
|
|
|
* @bssid: BSSID
|
|
|
|
* Returns: Matching blacklist entry for the BSSID or %NULL if not found
|
|
|
|
*/
|
|
|
|
struct wpa_blacklist * wpa_blacklist_get(struct wpa_supplicant *wpa_s,
|
|
|
|
const u8 *bssid)
|
|
|
|
{
|
|
|
|
struct wpa_blacklist *e;
|
|
|
|
|
2012-11-01 19:41:27 +01:00
|
|
|
if (wpa_s == NULL || bssid == NULL)
|
|
|
|
return NULL;
|
|
|
|
|
2008-02-28 02:34:43 +01:00
|
|
|
e = wpa_s->blacklist;
|
|
|
|
while (e) {
|
|
|
|
if (os_memcmp(e->bssid, bssid, ETH_ALEN) == 0)
|
|
|
|
return e;
|
|
|
|
e = e->next;
|
|
|
|
}
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* wpa_blacklist_add - Add an BSSID to the blacklist
|
|
|
|
* @wpa_s: Pointer to wpa_supplicant data
|
|
|
|
* @bssid: BSSID to be added to the blacklist
|
2010-11-25 21:00:04 +01:00
|
|
|
* Returns: Current blacklist count on success, -1 on failure
|
2008-02-28 02:34:43 +01:00
|
|
|
*
|
|
|
|
* This function adds the specified BSSID to the blacklist or increases the
|
|
|
|
* blacklist count if the BSSID was already listed. It should be called when
|
|
|
|
* an association attempt fails either due to the selected BSS rejecting
|
|
|
|
* association or due to timeout.
|
|
|
|
*
|
|
|
|
* This blacklist is used to force %wpa_supplicant to go through all available
|
|
|
|
* BSSes before retrying to associate with an BSS that rejected or timed out
|
|
|
|
* association. It does not prevent the listed BSS from being used; it only
|
|
|
|
* changes the order in which they are tried.
|
|
|
|
*/
|
|
|
|
int wpa_blacklist_add(struct wpa_supplicant *wpa_s, const u8 *bssid)
|
|
|
|
{
|
|
|
|
struct wpa_blacklist *e;
|
|
|
|
|
2012-11-01 19:41:27 +01:00
|
|
|
if (wpa_s == NULL || bssid == NULL)
|
|
|
|
return -1;
|
|
|
|
|
2008-02-28 02:34:43 +01:00
|
|
|
e = wpa_blacklist_get(wpa_s, bssid);
|
|
|
|
if (e) {
|
|
|
|
e->count++;
|
|
|
|
wpa_printf(MSG_DEBUG, "BSSID " MACSTR " blacklist count "
|
|
|
|
"incremented to %d",
|
|
|
|
MAC2STR(bssid), e->count);
|
2010-11-25 21:00:04 +01:00
|
|
|
return e->count;
|
2008-02-28 02:34:43 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
e = os_zalloc(sizeof(*e));
|
|
|
|
if (e == NULL)
|
|
|
|
return -1;
|
|
|
|
os_memcpy(e->bssid, bssid, ETH_ALEN);
|
|
|
|
e->count = 1;
|
|
|
|
e->next = wpa_s->blacklist;
|
|
|
|
wpa_s->blacklist = e;
|
|
|
|
wpa_printf(MSG_DEBUG, "Added BSSID " MACSTR " into blacklist",
|
|
|
|
MAC2STR(bssid));
|
|
|
|
|
2010-11-25 21:00:04 +01:00
|
|
|
return e->count;
|
2008-02-28 02:34:43 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* wpa_blacklist_del - Remove an BSSID from the blacklist
|
|
|
|
* @wpa_s: Pointer to wpa_supplicant data
|
|
|
|
* @bssid: BSSID to be removed from the blacklist
|
|
|
|
* Returns: 0 on success, -1 on failure
|
|
|
|
*/
|
|
|
|
int wpa_blacklist_del(struct wpa_supplicant *wpa_s, const u8 *bssid)
|
|
|
|
{
|
|
|
|
struct wpa_blacklist *e, *prev = NULL;
|
|
|
|
|
2012-11-01 19:41:27 +01:00
|
|
|
if (wpa_s == NULL || bssid == NULL)
|
|
|
|
return -1;
|
|
|
|
|
2008-02-28 02:34:43 +01:00
|
|
|
e = wpa_s->blacklist;
|
|
|
|
while (e) {
|
|
|
|
if (os_memcmp(e->bssid, bssid, ETH_ALEN) == 0) {
|
|
|
|
if (prev == NULL) {
|
|
|
|
wpa_s->blacklist = e->next;
|
|
|
|
} else {
|
|
|
|
prev->next = e->next;
|
|
|
|
}
|
|
|
|
wpa_printf(MSG_DEBUG, "Removed BSSID " MACSTR " from "
|
|
|
|
"blacklist", MAC2STR(bssid));
|
|
|
|
os_free(e);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
prev = e;
|
|
|
|
e = e->next;
|
|
|
|
}
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* wpa_blacklist_clear - Clear the blacklist of all entries
|
|
|
|
* @wpa_s: Pointer to wpa_supplicant data
|
|
|
|
*/
|
|
|
|
void wpa_blacklist_clear(struct wpa_supplicant *wpa_s)
|
|
|
|
{
|
|
|
|
struct wpa_blacklist *e, *prev;
|
2012-11-25 15:20:44 +01:00
|
|
|
int max_count = 0;
|
2008-02-28 02:34:43 +01:00
|
|
|
|
|
|
|
e = wpa_s->blacklist;
|
|
|
|
wpa_s->blacklist = NULL;
|
|
|
|
while (e) {
|
2012-11-25 15:20:44 +01:00
|
|
|
if (e->count > max_count)
|
|
|
|
max_count = e->count;
|
2008-02-28 02:34:43 +01:00
|
|
|
prev = e;
|
|
|
|
e = e->next;
|
|
|
|
wpa_printf(MSG_DEBUG, "Removed BSSID " MACSTR " from "
|
|
|
|
"blacklist (clear)", MAC2STR(prev->bssid));
|
|
|
|
os_free(prev);
|
|
|
|
}
|
2012-11-25 15:20:44 +01:00
|
|
|
|
|
|
|
wpa_s->extra_blacklist_count += max_count;
|
2008-02-28 02:34:43 +01:00
|
|
|
}
|