wlantest: Store last received GTK for each STA

This allows info_sta command to be used to fetch the last received GTK
separately for each STA.

Signed-hostap: Jouni Malinen <j@w1.fi>
This commit is contained in:
Jouni Malinen 2011-12-22 16:59:25 +02:00
parent 3c56f0e275
commit fd848ab9e3
5 changed files with 26 additions and 4 deletions

View file

@ -990,6 +990,15 @@ static void info_print_state(char *buf, size_t len, int state)
} }
static void info_print_gtk(char *buf, size_t len, struct wlantest_sta *sta)
{
size_t pos;
pos = os_snprintf(buf, len, "IDX=%d,GTK=", sta->gtk_idx);
wpa_snprintf_hex(buf + pos, len - pos, sta->gtk, sta->gtk_len);
}
static void ctrl_info_sta(struct wlantest *wt, int sock, u8 *cmd, size_t clen) static void ctrl_info_sta(struct wlantest *wt, int sock, u8 *cmd, size_t clen)
{ {
u8 *addr; u8 *addr;
@ -1029,6 +1038,9 @@ static void ctrl_info_sta(struct wlantest *wt, int sock, u8 *cmd, size_t clen)
case WLANTEST_STA_INFO_STATE: case WLANTEST_STA_INFO_STATE:
info_print_state(resp, sizeof(resp), sta->state); info_print_state(resp, sizeof(resp), sta->state);
break; break;
case WLANTEST_STA_INFO_GTK:
info_print_gtk(resp, sizeof(resp), sta);
break;
default: default:
ctrl_send_simple(wt, sock, WLANTEST_CTRL_INVALID_CMD); ctrl_send_simple(wt, sock, WLANTEST_CTRL_INVALID_CMD);
return; return;

View file

@ -326,8 +326,8 @@ static u8 * decrypt_eapol_key_data(const u8 *kek, u16 ver,
} }
static void learn_kde_keys(struct wlantest_bss *bss, const u8 *buf, size_t len, static void learn_kde_keys(struct wlantest_bss *bss, struct wlantest_sta *sta,
const u8 *rsc) const u8 *buf, size_t len, const u8 *rsc)
{ {
struct wpa_eapol_ie_parse ie; struct wpa_eapol_ie_parse ie;
@ -361,7 +361,9 @@ static void learn_kde_keys(struct wlantest_bss *bss, const u8 *buf, size_t len,
wpa_hexdump(MSG_DEBUG, "GTK", ie.gtk + 2, wpa_hexdump(MSG_DEBUG, "GTK", ie.gtk + 2,
ie.gtk_len - 2); ie.gtk_len - 2);
bss->gtk_len[id] = ie.gtk_len - 2; bss->gtk_len[id] = ie.gtk_len - 2;
sta->gtk_len = ie.gtk_len - 2;
os_memcpy(bss->gtk[id], ie.gtk + 2, ie.gtk_len - 2); os_memcpy(bss->gtk[id], ie.gtk + 2, ie.gtk_len - 2);
os_memcpy(sta->gtk, ie.gtk + 2, ie.gtk_len - 2);
bss->rsc[id][0] = rsc[5]; bss->rsc[id][0] = rsc[5];
bss->rsc[id][1] = rsc[4]; bss->rsc[id][1] = rsc[4];
bss->rsc[id][2] = rsc[3]; bss->rsc[id][2] = rsc[3];
@ -369,6 +371,7 @@ static void learn_kde_keys(struct wlantest_bss *bss, const u8 *buf, size_t len,
bss->rsc[id][4] = rsc[1]; bss->rsc[id][4] = rsc[1];
bss->rsc[id][5] = rsc[0]; bss->rsc[id][5] = rsc[0];
bss->gtk_idx = id; bss->gtk_idx = id;
sta->gtk_idx = id;
wpa_hexdump(MSG_DEBUG, "RSC", bss->rsc[id], 6); wpa_hexdump(MSG_DEBUG, "RSC", bss->rsc[id], 6);
} else { } else {
wpa_printf(MSG_INFO, "Invalid GTK KDE length %u", wpa_printf(MSG_INFO, "Invalid GTK KDE length %u",
@ -561,7 +564,7 @@ static void rx_data_eapol_key_3_of_4(struct wlantest *wt, const u8 *dst,
bss->rsnie[0] ? 2 + bss->rsnie[1] : 0); bss->rsnie[0] ? 2 + bss->rsnie[1] : 0);
} }
learn_kde_keys(bss, decrypted, decrypted_len, hdr->key_rsc); learn_kde_keys(bss, sta, decrypted, decrypted_len, hdr->key_rsc);
os_free(decrypted_buf); os_free(decrypted_buf);
} }
@ -711,7 +714,8 @@ static void rx_data_eapol_key_1_of_2(struct wlantest *wt, const u8 *dst,
decrypted, plain_len); decrypted, plain_len);
} }
if (sta->proto & WPA_PROTO_RSN) if (sta->proto & WPA_PROTO_RSN)
learn_kde_keys(bss, decrypted, decrypted_len, hdr->key_rsc); learn_kde_keys(bss, sta, decrypted, decrypted_len,
hdr->key_rsc);
else { else {
int klen = bss->group_cipher == WPA_CIPHER_TKIP ? 32 : 16; int klen = bss->group_cipher == WPA_CIPHER_TKIP ? 32 : 16;
if (decrypted_len == klen) { if (decrypted_len == klen) {

View file

@ -93,6 +93,10 @@ struct wlantest_sta {
int pwrmgt; int pwrmgt;
int pspoll; int pspoll;
u8 gtk[32];
size_t gtk_len;
int gtk_idx;
}; };
struct wlantest_tdls { struct wlantest_tdls {

View file

@ -1226,6 +1226,7 @@ static const struct sta_infos sta_infos[] = {
{ "key_mgmt", WLANTEST_STA_INFO_KEY_MGMT }, { "key_mgmt", WLANTEST_STA_INFO_KEY_MGMT },
{ "rsn_capab", WLANTEST_STA_INFO_RSN_CAPAB }, { "rsn_capab", WLANTEST_STA_INFO_RSN_CAPAB },
{ "state", WLANTEST_STA_INFO_STATE }, { "state", WLANTEST_STA_INFO_STATE },
{ "gtk", WLANTEST_STA_INFO_GTK },
{ NULL, 0 } { NULL, 0 }
}; };

View file

@ -157,6 +157,7 @@ enum wlantest_sta_info {
WLANTEST_STA_INFO_KEY_MGMT, WLANTEST_STA_INFO_KEY_MGMT,
WLANTEST_STA_INFO_RSN_CAPAB, WLANTEST_STA_INFO_RSN_CAPAB,
WLANTEST_STA_INFO_STATE, WLANTEST_STA_INFO_STATE,
WLANTEST_STA_INFO_GTK,
}; };
enum wlantest_bss_info { enum wlantest_bss_info {