• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * wpa_supplicant - Temporary BSSID blacklist
3  * Copyright (c) 2003-2007, Jouni Malinen <j@w1.fi>
4  *
5  * This software may be distributed under the terms of the BSD license.
6  * See README for more details.
7  */
8 
9 #include "includes.h"
10 
11 #include "common.h"
12 #include "wpa_supplicant_i.h"
13 #include "blacklist.h"
14 
15 /**
16  * wpa_blacklist_get - Get the blacklist entry for a BSSID
17  * @wpa_s: Pointer to wpa_supplicant data
18  * @bssid: BSSID
19  * Returns: Matching blacklist entry for the BSSID or %NULL if not found
20  */
wpa_blacklist_get(struct wpa_supplicant * wpa_s,const u8 * bssid)21 struct wpa_blacklist * wpa_blacklist_get(struct wpa_supplicant *wpa_s,
22 					 const u8 *bssid)
23 {
24 	struct wpa_blacklist *e;
25 
26 	e = wpa_s->blacklist;
27 	while (e) {
28 		if (os_memcmp(e->bssid, bssid, ETH_ALEN) == 0)
29 			return e;
30 		e = e->next;
31 	}
32 
33 	return NULL;
34 }
35 
36 
37 /**
38  * wpa_blacklist_add - Add an BSSID to the blacklist
39  * @wpa_s: Pointer to wpa_supplicant data
40  * @bssid: BSSID to be added to the blacklist
41  * Returns: Current blacklist count on success, -1 on failure
42  *
43  * This function adds the specified BSSID to the blacklist or increases the
44  * blacklist count if the BSSID was already listed. It should be called when
45  * an association attempt fails either due to the selected BSS rejecting
46  * association or due to timeout.
47  *
48  * This blacklist is used to force %wpa_supplicant to go through all available
49  * BSSes before retrying to associate with an BSS that rejected or timed out
50  * association. It does not prevent the listed BSS from being used; it only
51  * changes the order in which they are tried.
52  */
wpa_blacklist_add(struct wpa_supplicant * wpa_s,const u8 * bssid)53 int wpa_blacklist_add(struct wpa_supplicant *wpa_s, const u8 *bssid)
54 {
55 	struct wpa_blacklist *e;
56 
57 	e = wpa_blacklist_get(wpa_s, bssid);
58 	if (e) {
59 		e->count++;
60 		wpa_printf(MSG_DEBUG, "BSSID " MACSTR " blacklist count "
61 			   "incremented to %d",
62 			   MAC2STR(bssid), e->count);
63 		return e->count;
64 	}
65 
66 	e = os_zalloc(sizeof(*e));
67 	if (e == NULL)
68 		return -1;
69 	os_memcpy(e->bssid, bssid, ETH_ALEN);
70 	e->count = 1;
71 	e->next = wpa_s->blacklist;
72 	wpa_s->blacklist = e;
73 	wpa_printf(MSG_DEBUG, "Added BSSID " MACSTR " into blacklist",
74 		   MAC2STR(bssid));
75 
76 	return e->count;
77 }
78 
79 
80 /**
81  * wpa_blacklist_del - Remove an BSSID from the blacklist
82  * @wpa_s: Pointer to wpa_supplicant data
83  * @bssid: BSSID to be removed from the blacklist
84  * Returns: 0 on success, -1 on failure
85  */
wpa_blacklist_del(struct wpa_supplicant * wpa_s,const u8 * bssid)86 int wpa_blacklist_del(struct wpa_supplicant *wpa_s, const u8 *bssid)
87 {
88 	struct wpa_blacklist *e, *prev = NULL;
89 
90 	e = wpa_s->blacklist;
91 	while (e) {
92 		if (os_memcmp(e->bssid, bssid, ETH_ALEN) == 0) {
93 			if (prev == NULL) {
94 				wpa_s->blacklist = e->next;
95 			} else {
96 				prev->next = e->next;
97 			}
98 			wpa_printf(MSG_DEBUG, "Removed BSSID " MACSTR " from "
99 				   "blacklist", MAC2STR(bssid));
100 			os_free(e);
101 			return 0;
102 		}
103 		prev = e;
104 		e = e->next;
105 	}
106 	return -1;
107 }
108 
109 
110 /**
111  * wpa_blacklist_clear - Clear the blacklist of all entries
112  * @wpa_s: Pointer to wpa_supplicant data
113  */
wpa_blacklist_clear(struct wpa_supplicant * wpa_s)114 void wpa_blacklist_clear(struct wpa_supplicant *wpa_s)
115 {
116 	struct wpa_blacklist *e, *prev;
117 
118 	e = wpa_s->blacklist;
119 	wpa_s->blacklist = NULL;
120 	while (e) {
121 		prev = e;
122 		e = e->next;
123 		wpa_printf(MSG_DEBUG, "Removed BSSID " MACSTR " from "
124 			   "blacklist (clear)", MAC2STR(prev->bssid));
125 		os_free(prev);
126 	}
127 }
128