wlantest: Create station list for each BSS
[mech_eap.git] / wlantest / sta.c
1 /*
2  * STA 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_sta * sta_get(struct wlantest_bss *bss, const u8 *addr)
22 {
23         struct wlantest_sta *sta;
24
25         if (addr[0] & 0x01)
26                 return NULL; /* Skip group addressed frames */
27
28         dl_list_for_each(sta, &bss->sta, struct wlantest_sta, list) {
29                 if (os_memcmp(sta->addr, addr, ETH_ALEN) == 0)
30                         return sta;
31         }
32
33         sta = os_zalloc(sizeof(*sta));
34         if (sta == NULL)
35                 return NULL;
36         os_memcpy(sta->addr, addr, ETH_ALEN);
37         dl_list_add(&bss->sta, &sta->list);
38         wpa_printf(MSG_DEBUG, "Discovered new STA " MACSTR " in BSS " MACSTR,
39                    MAC2STR(sta->addr), MAC2STR(bss->bssid));
40         return sta;
41 }
42
43
44 void sta_deinit(struct wlantest_sta *sta)
45 {
46         dl_list_del(&sta->list);
47         os_free(sta);
48 }