2010-11-06 16:11:12 +01:00
|
|
|
/*
|
|
|
|
* BSS list
|
|
|
|
* Copyright (c) 2010, Jouni Malinen <j@w1.fi>
|
|
|
|
*
|
2012-02-11 15:46:35 +01:00
|
|
|
* This software may be distributed under the terms of the BSD license.
|
|
|
|
* See README for more details.
|
2010-11-06 16:11:12 +01:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include "utils/includes.h"
|
|
|
|
|
|
|
|
#include "utils/common.h"
|
2010-11-12 21:40:59 +01:00
|
|
|
#include "common/defs.h"
|
2011-01-14 16:43:17 +01:00
|
|
|
#include "common/ieee802_11_defs.h"
|
2010-11-06 16:57:21 +01:00
|
|
|
#include "common/ieee802_11_common.h"
|
2010-11-06 21:57:49 +01:00
|
|
|
#include "crypto/sha1.h"
|
2010-11-06 16:11:12 +01:00
|
|
|
#include "wlantest.h"
|
|
|
|
|
|
|
|
|
2010-11-19 21:00:10 +01:00
|
|
|
struct wlantest_bss * bss_find(struct wlantest *wt, const u8 *bssid)
|
2010-11-06 16:11:12 +01:00
|
|
|
{
|
|
|
|
struct wlantest_bss *bss;
|
|
|
|
|
|
|
|
dl_list_for_each(bss, &wt->bss, struct wlantest_bss, list) {
|
|
|
|
if (os_memcmp(bss->bssid, bssid, ETH_ALEN) == 0)
|
|
|
|
return bss;
|
|
|
|
}
|
|
|
|
|
2010-11-19 21:00:10 +01:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
struct wlantest_bss * bss_get(struct wlantest *wt, const u8 *bssid)
|
|
|
|
{
|
|
|
|
struct wlantest_bss *bss;
|
|
|
|
|
|
|
|
if (bssid[0] & 0x01)
|
|
|
|
return NULL; /* Skip group addressed frames */
|
|
|
|
|
|
|
|
bss = bss_find(wt, bssid);
|
|
|
|
if (bss)
|
|
|
|
return bss;
|
|
|
|
|
2010-11-06 16:11:12 +01:00
|
|
|
bss = os_zalloc(sizeof(*bss));
|
|
|
|
if (bss == NULL)
|
|
|
|
return NULL;
|
2010-11-06 16:31:02 +01:00
|
|
|
dl_list_init(&bss->sta);
|
2010-11-06 21:57:49 +01:00
|
|
|
dl_list_init(&bss->pmk);
|
2010-12-13 10:20:55 +01:00
|
|
|
dl_list_init(&bss->tdls);
|
2010-11-06 16:11:12 +01:00
|
|
|
os_memcpy(bss->bssid, bssid, ETH_ALEN);
|
|
|
|
dl_list_add(&wt->bss, &bss->list);
|
|
|
|
wpa_printf(MSG_DEBUG, "Discovered new BSS - " MACSTR,
|
|
|
|
MAC2STR(bss->bssid));
|
|
|
|
return bss;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-11-07 18:43:10 +01:00
|
|
|
void pmk_deinit(struct wlantest_pmk *pmk)
|
2010-11-06 21:57:49 +01:00
|
|
|
{
|
|
|
|
dl_list_del(&pmk->list);
|
|
|
|
os_free(pmk);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-01-24 13:26:35 +01:00
|
|
|
void tdls_deinit(struct wlantest_tdls *tdls)
|
|
|
|
{
|
|
|
|
dl_list_del(&tdls->list);
|
|
|
|
os_free(tdls);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-11-06 16:11:12 +01:00
|
|
|
void bss_deinit(struct wlantest_bss *bss)
|
|
|
|
{
|
2010-11-06 16:31:02 +01:00
|
|
|
struct wlantest_sta *sta, *n;
|
2010-11-06 21:57:49 +01:00
|
|
|
struct wlantest_pmk *pmk, *np;
|
2010-12-13 10:20:55 +01:00
|
|
|
struct wlantest_tdls *tdls, *nt;
|
2010-11-06 16:31:02 +01:00
|
|
|
dl_list_for_each_safe(sta, n, &bss->sta, struct wlantest_sta, list)
|
|
|
|
sta_deinit(sta);
|
2010-11-06 21:57:49 +01:00
|
|
|
dl_list_for_each_safe(pmk, np, &bss->pmk, struct wlantest_pmk, list)
|
|
|
|
pmk_deinit(pmk);
|
2010-12-13 10:20:55 +01:00
|
|
|
dl_list_for_each_safe(tdls, nt, &bss->tdls, struct wlantest_tdls, list)
|
2011-01-24 13:26:35 +01:00
|
|
|
tdls_deinit(tdls);
|
2010-11-06 16:11:12 +01:00
|
|
|
dl_list_del(&bss->list);
|
|
|
|
os_free(bss);
|
|
|
|
}
|
2010-11-06 16:57:21 +01:00
|
|
|
|
|
|
|
|
2010-11-21 12:19:43 +01:00
|
|
|
int bss_add_pmk_from_passphrase(struct wlantest_bss *bss,
|
|
|
|
const char *passphrase)
|
|
|
|
{
|
|
|
|
struct wlantest_pmk *pmk;
|
|
|
|
|
|
|
|
pmk = os_zalloc(sizeof(*pmk));
|
|
|
|
if (pmk == NULL)
|
|
|
|
return -1;
|
2012-08-22 10:16:48 +02:00
|
|
|
if (pbkdf2_sha1(passphrase, bss->ssid, bss->ssid_len, 4096,
|
2017-09-05 18:01:14 +02:00
|
|
|
pmk->pmk, PMK_LEN) < 0) {
|
2010-11-21 12:19:43 +01:00
|
|
|
os_free(pmk);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
wpa_printf(MSG_INFO, "Add possible PMK for BSSID " MACSTR
|
|
|
|
" based on passphrase '%s'",
|
|
|
|
MAC2STR(bss->bssid), passphrase);
|
2017-09-05 18:01:14 +02:00
|
|
|
wpa_hexdump(MSG_DEBUG, "Possible PMK", pmk->pmk, PMK_LEN);
|
2010-11-21 12:19:43 +01:00
|
|
|
dl_list_add(&bss->pmk, &pmk->list);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-11-06 21:57:49 +01:00
|
|
|
static void bss_add_pmk(struct wlantest *wt, struct wlantest_bss *bss)
|
|
|
|
{
|
|
|
|
struct wlantest_passphrase *p;
|
|
|
|
|
|
|
|
dl_list_for_each(p, &wt->passphrase, struct wlantest_passphrase, list)
|
|
|
|
{
|
|
|
|
if (!is_zero_ether_addr(p->bssid) &&
|
|
|
|
os_memcmp(p->bssid, bss->bssid, ETH_ALEN) != 0)
|
|
|
|
continue;
|
|
|
|
if (p->ssid_len &&
|
|
|
|
(p->ssid_len != bss->ssid_len ||
|
|
|
|
os_memcmp(p->ssid, bss->ssid, p->ssid_len) != 0))
|
|
|
|
continue;
|
|
|
|
|
2010-11-21 12:19:43 +01:00
|
|
|
if (bss_add_pmk_from_passphrase(bss, p->passphrase) < 0)
|
2010-11-06 21:57:49 +01:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void bss_update(struct wlantest *wt, struct wlantest_bss *bss,
|
|
|
|
struct ieee802_11_elems *elems)
|
2010-11-06 16:57:21 +01:00
|
|
|
{
|
2010-11-12 21:40:59 +01:00
|
|
|
struct wpa_ie_data data;
|
|
|
|
int update = 0;
|
|
|
|
|
2011-01-14 16:43:17 +01:00
|
|
|
if (bss->capab_info != bss->prev_capab_info)
|
|
|
|
update = 1;
|
|
|
|
|
2010-11-06 16:57:21 +01:00
|
|
|
if (elems->ssid == NULL || elems->ssid_len > 32) {
|
|
|
|
wpa_printf(MSG_INFO, "Invalid or missing SSID in a Beacon "
|
|
|
|
"frame for " MACSTR, MAC2STR(bss->bssid));
|
|
|
|
bss->parse_error_reported = 1;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2010-11-06 21:57:49 +01:00
|
|
|
if (bss->ssid_len != elems->ssid_len ||
|
|
|
|
os_memcmp(bss->ssid, elems->ssid, bss->ssid_len) != 0) {
|
|
|
|
wpa_printf(MSG_DEBUG, "Store SSID '%s' for BSSID " MACSTR,
|
|
|
|
wpa_ssid_txt(elems->ssid, elems->ssid_len),
|
|
|
|
MAC2STR(bss->bssid));
|
|
|
|
os_memcpy(bss->ssid, elems->ssid, elems->ssid_len);
|
|
|
|
bss->ssid_len = elems->ssid_len;
|
|
|
|
bss_add_pmk(wt, bss);
|
|
|
|
}
|
|
|
|
|
2014-05-15 11:40:02 +02:00
|
|
|
if (elems->osen == NULL) {
|
|
|
|
if (bss->osenie[0]) {
|
|
|
|
add_note(wt, MSG_INFO, "BSS " MACSTR
|
|
|
|
" - OSEN IE removed", MAC2STR(bss->bssid));
|
|
|
|
bss->rsnie[0] = 0;
|
|
|
|
update = 1;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (bss->osenie[0] == 0 ||
|
|
|
|
os_memcmp(bss->osenie, elems->osen - 2,
|
|
|
|
elems->osen_len + 2) != 0) {
|
|
|
|
wpa_printf(MSG_INFO, "BSS " MACSTR " - OSEN IE "
|
|
|
|
"stored", MAC2STR(bss->bssid));
|
|
|
|
wpa_hexdump(MSG_DEBUG, "OSEN IE", elems->osen - 2,
|
|
|
|
elems->osen_len + 2);
|
|
|
|
update = 1;
|
|
|
|
}
|
|
|
|
os_memcpy(bss->osenie, elems->osen - 2,
|
|
|
|
elems->osen_len + 2);
|
|
|
|
}
|
2010-11-06 16:57:21 +01:00
|
|
|
|
|
|
|
if (elems->rsn_ie == NULL) {
|
|
|
|
if (bss->rsnie[0]) {
|
2013-05-26 19:58:50 +02:00
|
|
|
add_note(wt, MSG_INFO, "BSS " MACSTR
|
|
|
|
" - RSN IE removed", MAC2STR(bss->bssid));
|
2010-11-06 16:57:21 +01:00
|
|
|
bss->rsnie[0] = 0;
|
2010-11-12 21:40:59 +01:00
|
|
|
update = 1;
|
2010-11-06 16:57:21 +01:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (bss->rsnie[0] == 0 ||
|
|
|
|
os_memcmp(bss->rsnie, elems->rsn_ie - 2,
|
|
|
|
elems->rsn_ie_len + 2) != 0) {
|
|
|
|
wpa_printf(MSG_INFO, "BSS " MACSTR " - RSN IE "
|
|
|
|
"stored", MAC2STR(bss->bssid));
|
|
|
|
wpa_hexdump(MSG_DEBUG, "RSN IE", elems->rsn_ie - 2,
|
|
|
|
elems->rsn_ie_len + 2);
|
2010-11-12 21:40:59 +01:00
|
|
|
update = 1;
|
2010-11-06 16:57:21 +01:00
|
|
|
}
|
|
|
|
os_memcpy(bss->rsnie, elems->rsn_ie - 2,
|
|
|
|
elems->rsn_ie_len + 2);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (elems->wpa_ie == NULL) {
|
|
|
|
if (bss->wpaie[0]) {
|
2013-05-26 19:58:50 +02:00
|
|
|
add_note(wt, MSG_INFO, "BSS " MACSTR
|
|
|
|
" - WPA IE removed", MAC2STR(bss->bssid));
|
2010-11-06 16:57:21 +01:00
|
|
|
bss->wpaie[0] = 0;
|
2010-11-12 21:40:59 +01:00
|
|
|
update = 1;
|
2010-11-06 16:57:21 +01:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (bss->wpaie[0] == 0 ||
|
|
|
|
os_memcmp(bss->wpaie, elems->wpa_ie - 2,
|
|
|
|
elems->wpa_ie_len + 2) != 0) {
|
|
|
|
wpa_printf(MSG_INFO, "BSS " MACSTR " - WPA IE "
|
|
|
|
"stored", MAC2STR(bss->bssid));
|
|
|
|
wpa_hexdump(MSG_DEBUG, "WPA IE", elems->wpa_ie - 2,
|
|
|
|
elems->wpa_ie_len + 2);
|
2010-11-12 21:40:59 +01:00
|
|
|
update = 1;
|
2010-11-06 16:57:21 +01:00
|
|
|
}
|
|
|
|
os_memcpy(bss->wpaie, elems->wpa_ie - 2,
|
|
|
|
elems->wpa_ie_len + 2);
|
|
|
|
}
|
2010-11-12 21:40:59 +01:00
|
|
|
|
2015-08-06 14:51:36 +02:00
|
|
|
if (elems->mdie)
|
|
|
|
os_memcpy(bss->mdid, elems->mdie, 2);
|
|
|
|
|
2010-11-12 21:40:59 +01:00
|
|
|
if (!update)
|
|
|
|
return;
|
|
|
|
|
2011-01-14 16:43:17 +01:00
|
|
|
bss->prev_capab_info = bss->capab_info;
|
2010-11-12 21:40:59 +01:00
|
|
|
bss->proto = 0;
|
|
|
|
bss->pairwise_cipher = 0;
|
|
|
|
bss->group_cipher = 0;
|
|
|
|
bss->key_mgmt = 0;
|
|
|
|
bss->rsn_capab = 0;
|
|
|
|
bss->mgmt_group_cipher = 0;
|
|
|
|
|
|
|
|
if (bss->wpaie[0]) {
|
|
|
|
if (wpa_parse_wpa_ie_wpa(bss->wpaie, 2 + bss->wpaie[1], &data)
|
|
|
|
< 0) {
|
2013-05-26 19:58:50 +02:00
|
|
|
add_note(wt, MSG_INFO, "Failed to parse WPA IE from "
|
|
|
|
MACSTR, MAC2STR(bss->bssid));
|
2010-11-12 21:40:59 +01:00
|
|
|
} else {
|
|
|
|
bss->proto |= data.proto;
|
|
|
|
bss->pairwise_cipher |= data.pairwise_cipher;
|
|
|
|
bss->group_cipher |= data.group_cipher;
|
|
|
|
bss->key_mgmt |= data.key_mgmt;
|
|
|
|
bss->rsn_capab = data.capabilities;
|
|
|
|
bss->mgmt_group_cipher |= data.mgmt_group_cipher;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (bss->rsnie[0]) {
|
|
|
|
if (wpa_parse_wpa_ie_rsn(bss->rsnie, 2 + bss->rsnie[1], &data)
|
|
|
|
< 0) {
|
2013-05-26 19:58:50 +02:00
|
|
|
add_note(wt, MSG_INFO, "Failed to parse RSN IE from "
|
|
|
|
MACSTR, MAC2STR(bss->bssid));
|
2010-11-12 21:40:59 +01:00
|
|
|
} else {
|
|
|
|
bss->proto |= data.proto;
|
|
|
|
bss->pairwise_cipher |= data.pairwise_cipher;
|
|
|
|
bss->group_cipher |= data.group_cipher;
|
|
|
|
bss->key_mgmt |= data.key_mgmt;
|
|
|
|
bss->rsn_capab = data.capabilities;
|
|
|
|
bss->mgmt_group_cipher |= data.mgmt_group_cipher;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-05-15 11:40:02 +02:00
|
|
|
if (bss->osenie[0]) {
|
|
|
|
bss->proto |= WPA_PROTO_OSEN;
|
|
|
|
bss->pairwise_cipher |= WPA_CIPHER_CCMP;
|
|
|
|
bss->group_cipher |= WPA_CIPHER_CCMP;
|
|
|
|
bss->key_mgmt |= WPA_KEY_MGMT_OSEN;
|
|
|
|
}
|
|
|
|
|
2010-11-12 21:40:59 +01:00
|
|
|
if (!(bss->proto & WPA_PROTO_RSN) ||
|
|
|
|
!(bss->rsn_capab & WPA_CAPABILITY_MFPC))
|
|
|
|
bss->mgmt_group_cipher = 0;
|
|
|
|
|
2014-05-15 11:40:02 +02:00
|
|
|
if (!bss->wpaie[0] && !bss->rsnie[0] && !bss->osenie[0] &&
|
2011-01-14 16:43:17 +01:00
|
|
|
(bss->capab_info & WLAN_CAPABILITY_PRIVACY))
|
|
|
|
bss->group_cipher = WPA_CIPHER_WEP40;
|
|
|
|
|
2010-11-12 21:40:59 +01:00
|
|
|
wpa_printf(MSG_INFO, "BSS " MACSTR
|
2014-05-15 11:40:02 +02:00
|
|
|
" proto=%s%s%s%s"
|
2014-08-29 15:03:01 +02:00
|
|
|
"pairwise=%s%s%s%s%s%s%s"
|
|
|
|
"group=%s%s%s%s%s%s%s%s%s"
|
2015-01-24 11:09:04 +01:00
|
|
|
"mgmt_group_cipher=%s%s%s%s%s"
|
2014-05-15 11:40:02 +02:00
|
|
|
"key_mgmt=%s%s%s%s%s%s%s%s%s"
|
2010-11-12 21:40:59 +01:00
|
|
|
"rsn_capab=%s%s%s%s%s",
|
|
|
|
MAC2STR(bss->bssid),
|
|
|
|
bss->proto == 0 ? "OPEN " : "",
|
|
|
|
bss->proto & WPA_PROTO_WPA ? "WPA " : "",
|
|
|
|
bss->proto & WPA_PROTO_RSN ? "WPA2 " : "",
|
2014-05-15 11:40:02 +02:00
|
|
|
bss->proto & WPA_PROTO_OSEN ? "OSEN " : "",
|
2010-11-12 21:40:59 +01:00
|
|
|
bss->pairwise_cipher == 0 ? "N/A " : "",
|
|
|
|
bss->pairwise_cipher & WPA_CIPHER_NONE ? "NONE " : "",
|
|
|
|
bss->pairwise_cipher & WPA_CIPHER_TKIP ? "TKIP " : "",
|
|
|
|
bss->pairwise_cipher & WPA_CIPHER_CCMP ? "CCMP " : "",
|
2014-08-29 15:03:01 +02:00
|
|
|
bss->pairwise_cipher & WPA_CIPHER_CCMP_256 ? "CCMP-256 " :
|
|
|
|
"",
|
|
|
|
bss->pairwise_cipher & WPA_CIPHER_GCMP ? "GCMP " : "",
|
|
|
|
bss->pairwise_cipher & WPA_CIPHER_GCMP_256 ? "GCMP-256 " :
|
|
|
|
"",
|
2010-11-12 21:40:59 +01:00
|
|
|
bss->group_cipher == 0 ? "N/A " : "",
|
|
|
|
bss->group_cipher & WPA_CIPHER_NONE ? "NONE " : "",
|
|
|
|
bss->group_cipher & WPA_CIPHER_WEP40 ? "WEP40 " : "",
|
|
|
|
bss->group_cipher & WPA_CIPHER_WEP104 ? "WEP104 " : "",
|
|
|
|
bss->group_cipher & WPA_CIPHER_TKIP ? "TKIP " : "",
|
|
|
|
bss->group_cipher & WPA_CIPHER_CCMP ? "CCMP " : "",
|
2014-08-29 15:03:01 +02:00
|
|
|
bss->group_cipher & WPA_CIPHER_CCMP_256 ? "CCMP-256 " : "",
|
|
|
|
bss->group_cipher & WPA_CIPHER_GCMP ? "GCMP " : "",
|
|
|
|
bss->group_cipher & WPA_CIPHER_GCMP_256 ? "GCMP-256 " : "",
|
2015-01-24 11:09:04 +01:00
|
|
|
bss->mgmt_group_cipher == 0 ? "N/A " : "",
|
|
|
|
bss->mgmt_group_cipher & WPA_CIPHER_AES_128_CMAC ?
|
|
|
|
"BIP " : "",
|
|
|
|
bss->mgmt_group_cipher & WPA_CIPHER_BIP_GMAC_128 ?
|
|
|
|
"BIP-GMAC-128 " : "",
|
|
|
|
bss->mgmt_group_cipher & WPA_CIPHER_BIP_GMAC_256 ?
|
|
|
|
"BIP-GMAC-256 " : "",
|
|
|
|
bss->mgmt_group_cipher & WPA_CIPHER_BIP_CMAC_256 ?
|
|
|
|
"BIP-CMAC-256 " : "",
|
2010-11-12 21:40:59 +01:00
|
|
|
bss->key_mgmt == 0 ? "N/A " : "",
|
|
|
|
bss->key_mgmt & WPA_KEY_MGMT_IEEE8021X ? "EAP " : "",
|
|
|
|
bss->key_mgmt & WPA_KEY_MGMT_PSK ? "PSK " : "",
|
|
|
|
bss->key_mgmt & WPA_KEY_MGMT_WPA_NONE ? "WPA-NONE " : "",
|
|
|
|
bss->key_mgmt & WPA_KEY_MGMT_FT_IEEE8021X ? "FT-EAP " : "",
|
|
|
|
bss->key_mgmt & WPA_KEY_MGMT_FT_PSK ? "FT-PSK " : "",
|
|
|
|
bss->key_mgmt & WPA_KEY_MGMT_IEEE8021X_SHA256 ?
|
|
|
|
"EAP-SHA256 " : "",
|
|
|
|
bss->key_mgmt & WPA_KEY_MGMT_PSK_SHA256 ?
|
|
|
|
"PSK-SHA256 " : "",
|
2014-05-15 11:40:02 +02:00
|
|
|
bss->key_mgmt & WPA_KEY_MGMT_OSEN ? "OSEN " : "",
|
2010-11-12 21:40:59 +01:00
|
|
|
bss->rsn_capab & WPA_CAPABILITY_PREAUTH ? "PREAUTH " : "",
|
|
|
|
bss->rsn_capab & WPA_CAPABILITY_NO_PAIRWISE ?
|
|
|
|
"NO_PAIRWISE " : "",
|
|
|
|
bss->rsn_capab & WPA_CAPABILITY_MFPR ? "MFPR " : "",
|
|
|
|
bss->rsn_capab & WPA_CAPABILITY_MFPC ? "MFPC " : "",
|
|
|
|
bss->rsn_capab & WPA_CAPABILITY_PEERKEY_ENABLED ?
|
|
|
|
"PEERKEY " : "");
|
2010-11-06 16:57:21 +01:00
|
|
|
}
|
2010-11-18 16:36:08 +01:00
|
|
|
|
|
|
|
|
|
|
|
void bss_flush(struct wlantest *wt)
|
|
|
|
{
|
|
|
|
struct wlantest_bss *bss, *n;
|
|
|
|
dl_list_for_each_safe(bss, n, &wt->bss, struct wlantest_bss, list)
|
|
|
|
bss_deinit(bss);
|
|
|
|
}
|