aboutsummaryrefslogtreecommitdiffstats
path: root/wlantest/bss.c
diff options
context:
space:
mode:
authorJouni Malinen <j@w1.fi>2010-11-06 20:57:49 (GMT)
committerJouni Malinen <j@w1.fi>2010-11-07 21:29:01 (GMT)
commit53650bcab4fd0fc8283072fcef3634c6ecbf8f50 (patch)
tree9a932b19d60002d7a267697f1ee2fbd341477e4c /wlantest/bss.c
parent32234bba52d5ad370b91bb2cbd6b2c24b03c2512 (diff)
downloadhostap-53650bcab4fd0fc8283072fcef3634c6ecbf8f50.zip
hostap-53650bcab4fd0fc8283072fcef3634c6ecbf8f50.tar.gz
hostap-53650bcab4fd0fc8283072fcef3634c6ecbf8f50.tar.bz2
wlantest: Add PTK derivation based on passphrases
Allow pre-configuration of passphrases (-p<passphrase>) to provide enough information for wlantest to be able to derive PMK for each BSS and PTK for each STA going through 4-Way Handshake (at least message 2 and 3 needs to be received).
Diffstat (limited to 'wlantest/bss.c')
-rw-r--r--wlantest/bss.c62
1 files changed, 59 insertions, 3 deletions
diff --git a/wlantest/bss.c b/wlantest/bss.c
index ec26b82..156d8b3 100644
--- a/wlantest/bss.c
+++ b/wlantest/bss.c
@@ -16,6 +16,7 @@
#include "utils/common.h"
#include "common/ieee802_11_common.h"
+#include "crypto/sha1.h"
#include "wlantest.h"
@@ -35,6 +36,7 @@ struct wlantest_bss * bss_get(struct wlantest *wt, const u8 *bssid)
if (bss == NULL)
return NULL;
dl_list_init(&bss->sta);
+ dl_list_init(&bss->pmk);
os_memcpy(bss->bssid, bssid, ETH_ALEN);
dl_list_add(&wt->bss, &bss->list);
wpa_printf(MSG_DEBUG, "Discovered new BSS - " MACSTR,
@@ -43,17 +45,63 @@ struct wlantest_bss * bss_get(struct wlantest *wt, const u8 *bssid)
}
+static void pmk_deinit(struct wlantest_pmk *pmk)
+{
+ dl_list_del(&pmk->list);
+ os_free(pmk);
+}
+
+
void bss_deinit(struct wlantest_bss *bss)
{
struct wlantest_sta *sta, *n;
+ struct wlantest_pmk *pmk, *np;
dl_list_for_each_safe(sta, n, &bss->sta, struct wlantest_sta, list)
sta_deinit(sta);
+ dl_list_for_each_safe(pmk, np, &bss->pmk, struct wlantest_pmk, list)
+ pmk_deinit(pmk);
dl_list_del(&bss->list);
os_free(bss);
}
-void bss_update(struct wlantest_bss *bss, struct ieee802_11_elems *elems)
+static void bss_add_pmk(struct wlantest *wt, struct wlantest_bss *bss)
+{
+ struct wlantest_passphrase *p;
+ struct wlantest_pmk *pmk;
+
+ 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;
+
+ pmk = os_zalloc(sizeof(*pmk));
+ if (pmk == NULL)
+ break;
+ if (pbkdf2_sha1(p->passphrase, (char *) bss->ssid,
+ bss->ssid_len, 4096,
+ pmk->pmk, sizeof(pmk->pmk)) < 0) {
+ os_free(pmk);
+ continue;
+ }
+
+ wpa_printf(MSG_INFO, "Add possible PMK for BSSID " MACSTR
+ " based on passphrase '%s'",
+ MAC2STR(bss->bssid), p->passphrase);
+ wpa_hexdump(MSG_DEBUG, "Possible PMK",
+ pmk->pmk, sizeof(pmk->pmk));
+ dl_list_add(&bss->pmk, &pmk->list);
+ }
+}
+
+
+void bss_update(struct wlantest *wt, struct wlantest_bss *bss,
+ struct ieee802_11_elems *elems)
{
if (elems->ssid == NULL || elems->ssid_len > 32) {
wpa_printf(MSG_INFO, "Invalid or missing SSID in a Beacon "
@@ -62,8 +110,16 @@ void bss_update(struct wlantest_bss *bss, struct ieee802_11_elems *elems)
return;
}
- os_memcpy(bss->ssid, elems->ssid, elems->ssid_len);
- bss->ssid_len = elems->ssid_len;
+ 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);
+ }
+
if (elems->rsn_ie == NULL) {
if (bss->rsnie[0]) {