447bd7a0dc1b139806a5593c320f166a96bc7b37
[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 "common/ieee802_11_common.h"
19 #include "wlantest.h"
20
21
22 struct wlantest_sta * sta_get(struct wlantest_bss *bss, const u8 *addr)
23 {
24         struct wlantest_sta *sta;
25
26         if (addr[0] & 0x01)
27                 return NULL; /* Skip group addressed frames */
28
29         dl_list_for_each(sta, &bss->sta, struct wlantest_sta, list) {
30                 if (os_memcmp(sta->addr, addr, ETH_ALEN) == 0)
31                         return sta;
32         }
33
34         sta = os_zalloc(sizeof(*sta));
35         if (sta == NULL)
36                 return NULL;
37         os_memcpy(sta->addr, addr, ETH_ALEN);
38         dl_list_add(&bss->sta, &sta->list);
39         wpa_printf(MSG_DEBUG, "Discovered new STA " MACSTR " in BSS " MACSTR,
40                    MAC2STR(sta->addr), MAC2STR(bss->bssid));
41         return sta;
42 }
43
44
45 void sta_deinit(struct wlantest_sta *sta)
46 {
47         dl_list_del(&sta->list);
48         os_free(sta);
49 }
50
51
52 void sta_update_assoc(struct wlantest_sta *sta, struct ieee802_11_elems *elems)
53 {
54         if (elems->wpa_ie && elems->rsn_ie) {
55                 wpa_printf(MSG_INFO, "Both WPA IE and RSN IE included in "
56                            "Association Request frame from " MACSTR,
57                            MAC2STR(sta->addr));
58         }
59
60         if (elems->rsn_ie) {
61                 wpa_hexdump(MSG_DEBUG, "RSN IE", elems->rsn_ie - 2,
62                             elems->rsn_ie_len + 2);
63                 os_memcpy(sta->rsnie, elems->rsn_ie - 2,
64                           elems->rsn_ie_len + 2);
65         } else if (elems->wpa_ie) {
66                 wpa_hexdump(MSG_DEBUG, "WPA IE", elems->wpa_ie - 2,
67                             elems->wpa_ie_len + 2);
68                 os_memcpy(sta->rsnie, elems->wpa_ie - 2,
69                           elems->wpa_ie_len + 2);
70         } else
71                 sta->rsnie[0] = 0;
72 }