wlantest: Maintain table of BSS information
[mech_eap.git] / wlantest / bss.c
1 /*
2  * BSS list
3  * Copyright (c) 2010, Jouni Malinen <j@w1.fi>
4  *
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License version 2 as
7  * published by the Free Software Foundation.
8  *
9  * Alternatively, this software may be distributed under the terms of BSD
10  * license.
11  *
12  * See README and COPYING for more details.
13  */
14
15 #include "utils/includes.h"
16
17 #include "utils/common.h"
18 #include "wlantest.h"
19
20
21 struct wlantest_bss * bss_get(struct wlantest *wt, const u8 *bssid)
22 {
23         struct wlantest_bss *bss;
24
25         if (bssid[0] & 0x01)
26                 return NULL; /* Skip group addressed frames */
27
28         dl_list_for_each(bss, &wt->bss, struct wlantest_bss, list) {
29                 if (os_memcmp(bss->bssid, bssid, ETH_ALEN) == 0)
30                         return bss;
31         }
32
33         bss = os_zalloc(sizeof(*bss));
34         if (bss == NULL)
35                 return NULL;
36         os_memcpy(bss->bssid, bssid, ETH_ALEN);
37         dl_list_add(&wt->bss, &bss->list);
38         wpa_printf(MSG_DEBUG, "Discovered new BSS - " MACSTR,
39                    MAC2STR(bss->bssid));
40         return bss;
41 }
42
43
44 void bss_deinit(struct wlantest_bss *bss)
45 {
46         dl_list_del(&bss->list);
47         os_free(bss);
48 }