blacklist.c
Go to the documentation of this file.
00001 /*
00002  * wpa_supplicant - Temporary BSSID blacklist
00003  * Copyright (c) 2003-2007, Jouni Malinen <j@w1.fi>
00004  *
00005  * This program is free software; you can redistribute it and/or modify
00006  * it under the terms of the GNU General Public License version 2 as
00007  * published by the Free Software Foundation.
00008  *
00009  * Alternatively, this software may be distributed under the terms of BSD
00010  * license.
00011  *
00012  * See README and COPYING for more details.
00013  */
00014 
00015 #include "includes.h"
00016 
00017 #include "common.h"
00018 #include "wpa_supplicant_i.h"
00019 #include "blacklist.h"
00020 
00027 struct wpa_blacklist * wpa_blacklist_get(struct wpa_supplicant *wpa_s,
00028                                          const u8 *bssid)
00029 {
00030         struct wpa_blacklist *e;
00031 
00032         e = wpa_s->blacklist;
00033         while (e) {
00034                 if (os_memcmp(e->bssid, bssid, ETH_ALEN) == 0)
00035                         return e;
00036                 e = e->next;
00037         }
00038 
00039         return NULL;
00040 }
00041 
00042 
00059 int wpa_blacklist_add(struct wpa_supplicant *wpa_s, const u8 *bssid)
00060 {
00061         struct wpa_blacklist *e;
00062 
00063         e = wpa_blacklist_get(wpa_s, bssid);
00064         if (e) {
00065                 e->count++;
00066                 wpa_printf(MSG_DEBUG, "BSSID " MACSTR " blacklist count "
00067                            "incremented to %d",
00068                            MAC2STR(bssid), e->count);
00069                 return 0;
00070         }
00071 
00072         e = os_zalloc(sizeof(*e));
00073         if (e == NULL)
00074                 return -1;
00075         os_memcpy(e->bssid, bssid, ETH_ALEN);
00076         e->count = 1;
00077         e->next = wpa_s->blacklist;
00078         wpa_s->blacklist = e;
00079         wpa_printf(MSG_DEBUG, "Added BSSID " MACSTR " into blacklist",
00080                    MAC2STR(bssid));
00081 
00082         return 0;
00083 }
00084 
00085 
00092 int wpa_blacklist_del(struct wpa_supplicant *wpa_s, const u8 *bssid)
00093 {
00094         struct wpa_blacklist *e, *prev = NULL;
00095 
00096         e = wpa_s->blacklist;
00097         while (e) {
00098                 if (os_memcmp(e->bssid, bssid, ETH_ALEN) == 0) {
00099                         if (prev == NULL) {
00100                                 wpa_s->blacklist = e->next;
00101                         } else {
00102                                 prev->next = e->next;
00103                         }
00104                         wpa_printf(MSG_DEBUG, "Removed BSSID " MACSTR " from "
00105                                    "blacklist", MAC2STR(bssid));
00106                         os_free(e);
00107                         return 0;
00108                 }
00109                 prev = e;
00110                 e = e->next;
00111         }
00112         return -1;
00113 }
00114 
00115 
00120 void wpa_blacklist_clear(struct wpa_supplicant *wpa_s)
00121 {
00122         struct wpa_blacklist *e, *prev;
00123 
00124         e = wpa_s->blacklist;
00125         wpa_s->blacklist = NULL;
00126         while (e) {
00127                 prev = e;
00128                 e = e->next;
00129                 wpa_printf(MSG_DEBUG, "Removed BSSID " MACSTR " from "
00130                            "blacklist (clear)", MAC2STR(prev->bssid));
00131                 os_free(prev);
00132         }
00133 }


wpa_supplicant_node
Author(s): Package maintained by Blaise Gassend
autogenerated on Thu Apr 24 2014 15:33:19