wlantest: Use add_note() to annotate frames

This adds debug information from wlantest into pcapng frame comments to
make the information more convenient to use, e.g., in Wireshark.

Signed-hostap: Jouni Malinen <j@w1.fi>
This commit is contained in:
Jouni Malinen 2013-05-26 20:58:50 +03:00
parent ba2beacc97
commit e4d99217f7
7 changed files with 394 additions and 371 deletions

View file

@ -157,8 +157,8 @@ void bss_update(struct wlantest *wt, struct wlantest_bss *bss,
if (elems->rsn_ie == NULL) { if (elems->rsn_ie == NULL) {
if (bss->rsnie[0]) { if (bss->rsnie[0]) {
wpa_printf(MSG_INFO, "BSS " MACSTR " - RSN IE removed", add_note(wt, MSG_INFO, "BSS " MACSTR
MAC2STR(bss->bssid)); " - RSN IE removed", MAC2STR(bss->bssid));
bss->rsnie[0] = 0; bss->rsnie[0] = 0;
update = 1; update = 1;
} }
@ -178,8 +178,8 @@ void bss_update(struct wlantest *wt, struct wlantest_bss *bss,
if (elems->wpa_ie == NULL) { if (elems->wpa_ie == NULL) {
if (bss->wpaie[0]) { if (bss->wpaie[0]) {
wpa_printf(MSG_INFO, "BSS " MACSTR " - WPA IE removed", add_note(wt, MSG_INFO, "BSS " MACSTR
MAC2STR(bss->bssid)); " - WPA IE removed", MAC2STR(bss->bssid));
bss->wpaie[0] = 0; bss->wpaie[0] = 0;
update = 1; update = 1;
} }
@ -211,8 +211,8 @@ void bss_update(struct wlantest *wt, struct wlantest_bss *bss,
if (bss->wpaie[0]) { if (bss->wpaie[0]) {
if (wpa_parse_wpa_ie_wpa(bss->wpaie, 2 + bss->wpaie[1], &data) if (wpa_parse_wpa_ie_wpa(bss->wpaie, 2 + bss->wpaie[1], &data)
< 0) { < 0) {
wpa_printf(MSG_INFO, "Failed to parse WPA IE from " add_note(wt, MSG_INFO, "Failed to parse WPA IE from "
MACSTR, MAC2STR(bss->bssid)); MACSTR, MAC2STR(bss->bssid));
} else { } else {
bss->proto |= data.proto; bss->proto |= data.proto;
bss->pairwise_cipher |= data.pairwise_cipher; bss->pairwise_cipher |= data.pairwise_cipher;
@ -226,8 +226,8 @@ void bss_update(struct wlantest *wt, struct wlantest_bss *bss,
if (bss->rsnie[0]) { if (bss->rsnie[0]) {
if (wpa_parse_wpa_ie_rsn(bss->rsnie, 2 + bss->rsnie[1], &data) if (wpa_parse_wpa_ie_rsn(bss->rsnie, 2 + bss->rsnie[1], &data)
< 0) { < 0) {
wpa_printf(MSG_INFO, "Failed to parse RSN IE from " add_note(wt, MSG_INFO, "Failed to parse RSN IE from "
MACSTR, MAC2STR(bss->bssid)); MACSTR, MAC2STR(bss->bssid));
} else { } else {
bss->proto |= data.proto; bss->proto |= data.proto;
bss->pairwise_cipher |= data.pairwise_cipher; bss->pairwise_cipher |= data.pairwise_cipher;

View file

@ -100,12 +100,12 @@ static void rx_update_ps(struct wlantest *wt, const struct ieee80211_hdr *hdr,
if (!to_ap) { if (!to_ap) {
if (sta->pwrmgt && !sta->pspoll) { if (sta->pwrmgt && !sta->pspoll) {
u16 seq_ctrl = le_to_host16(hdr->seq_ctrl); u16 seq_ctrl = le_to_host16(hdr->seq_ctrl);
wpa_printf(MSG_DEBUG, "AP " MACSTR " sent a frame " add_note(wt, MSG_DEBUG, "AP " MACSTR " sent a frame "
"(%u:%u) to a sleeping STA " MACSTR "(%u:%u) to a sleeping STA " MACSTR
" (seq=%u)", " (seq=%u)",
MAC2STR(sta->bss->bssid), MAC2STR(sta->bss->bssid),
type, stype, MAC2STR(sta->addr), type, stype, MAC2STR(sta->addr),
WLAN_GET_SEQ_SEQ(seq_ctrl)); WLAN_GET_SEQ_SEQ(seq_ctrl));
} else } else
sta->pspoll = 0; sta->pspoll = 0;
return; return;
@ -122,12 +122,12 @@ static void rx_update_ps(struct wlantest *wt, const struct ieee80211_hdr *hdr,
* maintain state through the frame exchange. * maintain state through the frame exchange.
*/ */
if (sta->pwrmgt && !(fc & WLAN_FC_PWRMGT)) { if (sta->pwrmgt && !(fc & WLAN_FC_PWRMGT)) {
wpa_printf(MSG_DEBUG, "STA " MACSTR " woke up from " add_note(wt, MSG_DEBUG, "STA " MACSTR " woke up from "
"sleep", MAC2STR(sta->addr)); "sleep", MAC2STR(sta->addr));
sta->pwrmgt = 0; sta->pwrmgt = 0;
} else if (!sta->pwrmgt && (fc & WLAN_FC_PWRMGT)) { } else if (!sta->pwrmgt && (fc & WLAN_FC_PWRMGT)) {
wpa_printf(MSG_DEBUG, "STA " MACSTR " went to sleep", add_note(wt, MSG_DEBUG, "STA " MACSTR " went to sleep",
MAC2STR(sta->addr)); MAC2STR(sta->addr));
sta->pwrmgt = 1; sta->pwrmgt = 1;
} }
} }
@ -161,10 +161,10 @@ static int rx_duplicate(struct wlantest *wt, const struct ieee80211_hdr *hdr,
if ((fc & WLAN_FC_RETRY) && hdr->seq_ctrl == *seq_ctrl) { if ((fc & WLAN_FC_RETRY) && hdr->seq_ctrl == *seq_ctrl) {
u16 s = le_to_host16(hdr->seq_ctrl); u16 s = le_to_host16(hdr->seq_ctrl);
wpa_printf(MSG_MSGDUMP, "Ignore duplicated frame (seq=%u " add_note(wt, MSG_MSGDUMP, "Ignore duplicated frame (seq=%u "
"frag=%u A1=" MACSTR " A2=" MACSTR ")", "frag=%u A1=" MACSTR " A2=" MACSTR ")",
WLAN_GET_SEQ_SEQ(s), WLAN_GET_SEQ_FRAG(s), WLAN_GET_SEQ_SEQ(s), WLAN_GET_SEQ_FRAG(s),
MAC2STR(hdr->addr1), MAC2STR(hdr->addr2)); MAC2STR(hdr->addr1), MAC2STR(hdr->addr2));
return 1; return 1;
} }
@ -181,8 +181,8 @@ static void rx_ack(struct wlantest *wt, const struct ieee80211_hdr *hdr)
if (wt->last_len < 24 || (last->addr1[0] & 0x01) || if (wt->last_len < 24 || (last->addr1[0] & 0x01) ||
os_memcmp(hdr->addr1, last->addr2, ETH_ALEN) != 0) { os_memcmp(hdr->addr1, last->addr2, ETH_ALEN) != 0) {
wpa_printf(MSG_MSGDUMP, "Unknown Ack frame (previous frame " add_note(wt, MSG_MSGDUMP, "Unknown Ack frame (previous frame "
"not seen)"); "not seen)");
return; return;
} }
@ -277,7 +277,7 @@ void wlantest_process(struct wlantest *wt, const u8 *data, size_t len)
wpa_hexdump(MSG_EXCESSIVE, "Process data", data, len); wpa_hexdump(MSG_EXCESSIVE, "Process data", data, len);
if (ieee80211_radiotap_iterator_init(&iter, (void *) data, len)) { if (ieee80211_radiotap_iterator_init(&iter, (void *) data, len)) {
wpa_printf(MSG_INFO, "Invalid radiotap frame"); add_note(wt, MSG_INFO, "Invalid radiotap frame");
return; return;
} }
@ -288,8 +288,8 @@ void wlantest_process(struct wlantest *wt, const u8 *data, size_t len)
if (ret == -ENOENT) if (ret == -ENOENT)
break; break;
if (ret) { if (ret) {
wpa_printf(MSG_INFO, "Invalid radiotap header: %d", add_note(wt, MSG_INFO, "Invalid radiotap header: %d",
ret); ret);
return; return;
} }
switch (iter.this_arg_index) { switch (iter.this_arg_index) {
@ -310,7 +310,7 @@ void wlantest_process(struct wlantest *wt, const u8 *data, size_t len)
} }
if (iter.max_length == 8) { if (iter.max_length == 8) {
wpa_printf(MSG_DEBUG, "Skip frame inserted by wlantest"); add_note(wt, MSG_DEBUG, "Skip frame inserted by wlantest");
return; return;
} }
frame = data + iter.max_length; frame = data + iter.max_length;
@ -320,8 +320,8 @@ void wlantest_process(struct wlantest *wt, const u8 *data, size_t len)
frame_len -= 4; frame_len -= 4;
fcspos = frame + frame_len; fcspos = frame + frame_len;
if (check_fcs(frame, frame_len, fcspos) < 0) { if (check_fcs(frame, frame_len, fcspos) < 0) {
wpa_printf(MSG_EXCESSIVE, "Drop RX frame with invalid " add_note(wt, MSG_EXCESSIVE, "Drop RX frame with "
"FCS"); "invalid FCS");
wt->fcs_error++; wt->fcs_error++;
return; return;
} }
@ -332,6 +332,8 @@ void wlantest_process(struct wlantest *wt, const u8 *data, size_t len)
if (!txflags) if (!txflags)
rx_frame(wt, frame, frame_len); rx_frame(wt, frame, frame_len);
else { else {
add_note(wt, MSG_EXCESSIVE, "TX status - process as RX of "
"local frame");
tx_status(wt, frame, frame_len, !failed); tx_status(wt, frame, frame_len, !failed);
/* Process as RX frame to support local monitor interface */ /* Process as RX frame to support local monitor interface */
rx_frame(wt, frame, frame_len); rx_frame(wt, frame, frame_len);
@ -366,8 +368,8 @@ void wlantest_process_prism(struct wlantest *wt, const u8 *data, size_t len)
frame_len -= 4; frame_len -= 4;
fcspos = frame + frame_len; fcspos = frame + frame_len;
if (check_fcs(frame, frame_len, fcspos) < 0) { if (check_fcs(frame, frame_len, fcspos) < 0) {
wpa_printf(MSG_EXCESSIVE, "Drop RX frame with invalid " add_note(wt, MSG_EXCESSIVE, "Drop RX frame with "
"FCS"); "invalid FCS");
wt->fcs_error++; wt->fcs_error++;
return; return;
} }
@ -387,8 +389,8 @@ void wlantest_process_80211(struct wlantest *wt, const u8 *data, size_t len)
len -= 4; len -= 4;
fcspos = data + len; fcspos = data + len;
if (check_fcs(data, len, fcspos) < 0) { if (check_fcs(data, len, fcspos) < 0) {
wpa_printf(MSG_EXCESSIVE, "Drop RX frame with invalid " add_note(wt, MSG_EXCESSIVE, "Drop RX frame with "
"FCS"); "invalid FCS");
wt->fcs_error++; wt->fcs_error++;
return; return;
} }

View file

@ -108,45 +108,45 @@ static void rx_data_bss_prot_group(struct wlantest *wt,
if (bss == NULL) if (bss == NULL)
return; return;
if (len < 4) { if (len < 4) {
wpa_printf(MSG_INFO, "Too short group addressed data frame"); add_note(wt, MSG_INFO, "Too short group addressed data frame");
return; return;
} }
if (bss->group_cipher & (WPA_CIPHER_TKIP | WPA_CIPHER_CCMP) && if (bss->group_cipher & (WPA_CIPHER_TKIP | WPA_CIPHER_CCMP) &&
!(data[3] & 0x20)) { !(data[3] & 0x20)) {
wpa_printf(MSG_INFO, "Expected TKIP/CCMP frame from " add_note(wt, MSG_INFO, "Expected TKIP/CCMP frame from "
MACSTR " did not have ExtIV bit set to 1", MACSTR " did not have ExtIV bit set to 1",
MAC2STR(bss->bssid)); MAC2STR(bss->bssid));
return; return;
} }
if (bss->group_cipher == WPA_CIPHER_TKIP) { if (bss->group_cipher == WPA_CIPHER_TKIP) {
if (data[3] & 0x1f) { if (data[3] & 0x1f) {
wpa_printf(MSG_INFO, "TKIP frame from " MACSTR " used " add_note(wt, MSG_INFO, "TKIP frame from " MACSTR
"non-zero reserved bit", " used non-zero reserved bit",
MAC2STR(bss->bssid)); MAC2STR(bss->bssid));
} }
if (data[1] != ((data[0] | 0x20) & 0x7f)) { if (data[1] != ((data[0] | 0x20) & 0x7f)) {
wpa_printf(MSG_INFO, "TKIP frame from " MACSTR " used " add_note(wt, MSG_INFO, "TKIP frame from " MACSTR
"incorrect WEPSeed[1] (was 0x%x, expected " " used incorrect WEPSeed[1] (was 0x%x, "
"0x%x)", "expected 0x%x)",
MAC2STR(bss->bssid), data[1], MAC2STR(bss->bssid), data[1],
(data[0] | 0x20) & 0x7f); (data[0] | 0x20) & 0x7f);
} }
} else if (bss->group_cipher == WPA_CIPHER_CCMP) { } else if (bss->group_cipher == WPA_CIPHER_CCMP) {
if (data[2] != 0 || (data[3] & 0x1f) != 0) { if (data[2] != 0 || (data[3] & 0x1f) != 0) {
wpa_printf(MSG_INFO, "CCMP frame from " MACSTR " used " add_note(wt, MSG_INFO, "CCMP frame from " MACSTR
"non-zero reserved bit", " used non-zero reserved bit",
MAC2STR(bss->bssid)); MAC2STR(bss->bssid));
} }
} }
keyid = data[3] >> 6; keyid = data[3] >> 6;
if (bss->gtk_len[keyid] == 0 && bss->group_cipher != WPA_CIPHER_WEP40) if (bss->gtk_len[keyid] == 0 && bss->group_cipher != WPA_CIPHER_WEP40)
{ {
wpa_printf(MSG_MSGDUMP, "No GTK known to decrypt the frame " add_note(wt, MSG_MSGDUMP, "No GTK known to decrypt the frame "
"(A2=" MACSTR " KeyID=%d)", "(A2=" MACSTR " KeyID=%d)",
MAC2STR(hdr->addr2), keyid); MAC2STR(hdr->addr2), keyid);
return; return;
} }
@ -158,12 +158,12 @@ static void rx_data_bss_prot_group(struct wlantest *wt,
ccmp_get_pn(pn, data); ccmp_get_pn(pn, data);
if (os_memcmp(pn, bss->rsc[keyid], 6) <= 0) { if (os_memcmp(pn, bss->rsc[keyid], 6) <= 0) {
u16 seq_ctrl = le_to_host16(hdr->seq_ctrl); u16 seq_ctrl = le_to_host16(hdr->seq_ctrl);
wpa_printf(MSG_INFO, "CCMP/TKIP replay detected: A1=" MACSTR add_note(wt, MSG_INFO, "CCMP/TKIP replay detected: A1=" MACSTR
" A2=" MACSTR " A3=" MACSTR " seq=%u frag=%u", " A2=" MACSTR " A3=" MACSTR " seq=%u frag=%u",
MAC2STR(hdr->addr1), MAC2STR(hdr->addr2), MAC2STR(hdr->addr1), MAC2STR(hdr->addr2),
MAC2STR(hdr->addr3), MAC2STR(hdr->addr3),
WLAN_GET_SEQ_SEQ(seq_ctrl), WLAN_GET_SEQ_SEQ(seq_ctrl),
WLAN_GET_SEQ_FRAG(seq_ctrl)); WLAN_GET_SEQ_FRAG(seq_ctrl));
wpa_hexdump(MSG_INFO, "RX PN", pn, 6); wpa_hexdump(MSG_INFO, "RX PN", pn, 6);
wpa_hexdump(MSG_INFO, "RSC", bss->rsc[keyid], 6); wpa_hexdump(MSG_INFO, "RSC", bss->rsc[keyid], 6);
} }
@ -183,7 +183,8 @@ skip_replay_det:
os_memcpy(bss->rsc[keyid], pn, 6); os_memcpy(bss->rsc[keyid], pn, 6);
write_pcap_decrypted(wt, (const u8 *) hdr, 24 + (qos ? 2 : 0), write_pcap_decrypted(wt, (const u8 *) hdr, 24 + (qos ? 2 : 0),
decrypted, dlen); decrypted, dlen);
} } else
add_note(wt, MSG_DEBUG, "Failed to decrypt frame");
os_free(decrypted); os_free(decrypted);
} }
@ -244,49 +245,49 @@ static void rx_data_bss_prot(struct wlantest *wt,
if ((sta == NULL || if ((sta == NULL ||
(!sta->ptk_set && sta->pairwise_cipher != WPA_CIPHER_WEP40)) && (!sta->ptk_set && sta->pairwise_cipher != WPA_CIPHER_WEP40)) &&
tk == NULL) { tk == NULL) {
wpa_printf(MSG_MSGDUMP, "No PTK known to decrypt the frame"); add_note(wt, MSG_MSGDUMP, "No PTK known to decrypt the frame");
return; return;
} }
if (len < 4) { if (len < 4) {
wpa_printf(MSG_INFO, "Too short encrypted data frame"); add_note(wt, MSG_INFO, "Too short encrypted data frame");
return; return;
} }
if (sta->pairwise_cipher & (WPA_CIPHER_TKIP | WPA_CIPHER_CCMP) && if (sta->pairwise_cipher & (WPA_CIPHER_TKIP | WPA_CIPHER_CCMP) &&
!(data[3] & 0x20)) { !(data[3] & 0x20)) {
wpa_printf(MSG_INFO, "Expected TKIP/CCMP frame from " add_note(wt, MSG_INFO, "Expected TKIP/CCMP frame from "
MACSTR " did not have ExtIV bit set to 1", MACSTR " did not have ExtIV bit set to 1",
MAC2STR(src)); MAC2STR(src));
return; return;
} }
if (tk == NULL && sta->pairwise_cipher == WPA_CIPHER_TKIP) { if (tk == NULL && sta->pairwise_cipher == WPA_CIPHER_TKIP) {
if (data[3] & 0x1f) { if (data[3] & 0x1f) {
wpa_printf(MSG_INFO, "TKIP frame from " MACSTR " used " add_note(wt, MSG_INFO, "TKIP frame from " MACSTR
"non-zero reserved bit", " used non-zero reserved bit",
MAC2STR(hdr->addr2)); MAC2STR(hdr->addr2));
} }
if (data[1] != ((data[0] | 0x20) & 0x7f)) { if (data[1] != ((data[0] | 0x20) & 0x7f)) {
wpa_printf(MSG_INFO, "TKIP frame from " MACSTR " used " add_note(wt, MSG_INFO, "TKIP frame from " MACSTR
"incorrect WEPSeed[1] (was 0x%x, expected " " used incorrect WEPSeed[1] (was 0x%x, "
"0x%x)", "expected 0x%x)",
MAC2STR(hdr->addr2), data[1], MAC2STR(hdr->addr2), data[1],
(data[0] | 0x20) & 0x7f); (data[0] | 0x20) & 0x7f);
} }
} else if (tk || sta->pairwise_cipher == WPA_CIPHER_CCMP) { } else if (tk || sta->pairwise_cipher == WPA_CIPHER_CCMP) {
if (data[2] != 0 || (data[3] & 0x1f) != 0) { if (data[2] != 0 || (data[3] & 0x1f) != 0) {
wpa_printf(MSG_INFO, "CCMP frame from " MACSTR " used " add_note(wt, MSG_INFO, "CCMP frame from " MACSTR
"non-zero reserved bit", " used non-zero reserved bit",
MAC2STR(hdr->addr2)); MAC2STR(hdr->addr2));
} }
} }
keyid = data[3] >> 6; keyid = data[3] >> 6;
if (keyid != 0) { if (keyid != 0) {
wpa_printf(MSG_INFO, "Unexpected non-zero KeyID %d in " add_note(wt, MSG_INFO, "Unexpected non-zero KeyID %d in "
"individually addressed Data frame from " MACSTR, "individually addressed Data frame from " MACSTR,
keyid, MAC2STR(hdr->addr2)); keyid, MAC2STR(hdr->addr2));
} }
if (qos) if (qos)
@ -312,12 +313,12 @@ static void rx_data_bss_prot(struct wlantest *wt,
ccmp_get_pn(pn, data); ccmp_get_pn(pn, data);
if (os_memcmp(pn, rsc, 6) <= 0) { if (os_memcmp(pn, rsc, 6) <= 0) {
u16 seq_ctrl = le_to_host16(hdr->seq_ctrl); u16 seq_ctrl = le_to_host16(hdr->seq_ctrl);
wpa_printf(MSG_INFO, "CCMP/TKIP replay detected: A1=" MACSTR add_note(wt, MSG_INFO, "CCMP/TKIP replay detected: A1=" MACSTR
" A2=" MACSTR " A3=" MACSTR " seq=%u frag=%u", " A2=" MACSTR " A3=" MACSTR " seq=%u frag=%u",
MAC2STR(hdr->addr1), MAC2STR(hdr->addr2), MAC2STR(hdr->addr1), MAC2STR(hdr->addr2),
MAC2STR(hdr->addr3), MAC2STR(hdr->addr3),
WLAN_GET_SEQ_SEQ(seq_ctrl), WLAN_GET_SEQ_SEQ(seq_ctrl),
WLAN_GET_SEQ_FRAG(seq_ctrl)); WLAN_GET_SEQ_FRAG(seq_ctrl));
wpa_hexdump(MSG_INFO, "RX PN", pn, 6); wpa_hexdump(MSG_INFO, "RX PN", pn, 6);
wpa_hexdump(MSG_INFO, "RSC", rsc, 6); wpa_hexdump(MSG_INFO, "RSC", rsc, 6);
} }
@ -341,7 +342,8 @@ skip_replay_det:
dlen, 1, peer_addr); dlen, 1, peer_addr);
write_pcap_decrypted(wt, (const u8 *) hdr, 24 + (qos ? 2 : 0), write_pcap_decrypted(wt, (const u8 *) hdr, 24 + (qos ? 2 : 0),
decrypted, dlen); decrypted, dlen);
} } else
add_note(wt, MSG_DEBUG, "Failed to decrypt frame");
os_free(decrypted); os_free(decrypted);
} }

View file

@ -79,19 +79,20 @@ static void rx_data_eapol_key_1_of_4(struct wlantest *wt, const u8 *dst,
eapol = (const struct ieee802_1x_hdr *) data; eapol = (const struct ieee802_1x_hdr *) data;
hdr = (const struct wpa_eapol_key *) (eapol + 1); hdr = (const struct wpa_eapol_key *) (eapol + 1);
if (is_zero(hdr->key_nonce, WPA_NONCE_LEN)) { if (is_zero(hdr->key_nonce, WPA_NONCE_LEN)) {
wpa_printf(MSG_INFO, "EAPOL-Key 1/4 from " MACSTR " used " add_note(wt, MSG_INFO, "EAPOL-Key 1/4 from " MACSTR
"zero nonce", MAC2STR(src)); " used zero nonce", MAC2STR(src));
} }
if (!is_zero(hdr->key_rsc, 8)) { if (!is_zero(hdr->key_rsc, 8)) {
wpa_printf(MSG_INFO, "EAPOL-Key 1/4 from " MACSTR " used " add_note(wt, MSG_INFO, "EAPOL-Key 1/4 from " MACSTR
"non-zero Key RSC", MAC2STR(src)); " used non-zero Key RSC", MAC2STR(src));
} }
os_memcpy(sta->anonce, hdr->key_nonce, WPA_NONCE_LEN); os_memcpy(sta->anonce, hdr->key_nonce, WPA_NONCE_LEN);
} }
static int try_pmk(struct wlantest_bss *bss, struct wlantest_sta *sta, static int try_pmk(struct wlantest *wt, struct wlantest_bss *bss,
u16 ver, const u8 *data, size_t len, struct wlantest_sta *sta, u16 ver,
const u8 *data, size_t len,
struct wlantest_pmk *pmk) struct wlantest_pmk *pmk)
{ {
struct wpa_ptk ptk; struct wpa_ptk ptk;
@ -112,6 +113,7 @@ static int try_pmk(struct wlantest_bss *bss, struct wlantest_sta *sta,
* Rekeying - use new PTK for EAPOL-Key frames, but continue * Rekeying - use new PTK for EAPOL-Key frames, but continue
* using the old PTK for frame decryption. * using the old PTK for frame decryption.
*/ */
add_note(wt, MSG_DEBUG, "Derived PTK during rekeying");
os_memcpy(&sta->tptk, &ptk, sizeof(ptk)); os_memcpy(&sta->tptk, &ptk, sizeof(ptk));
wpa_hexdump(MSG_DEBUG, "TPTK:KCK", sta->tptk.kck, 16); wpa_hexdump(MSG_DEBUG, "TPTK:KCK", sta->tptk.kck, 16);
wpa_hexdump(MSG_DEBUG, "TPTK:KEK", sta->tptk.kek, 16); wpa_hexdump(MSG_DEBUG, "TPTK:KEK", sta->tptk.kek, 16);
@ -122,6 +124,7 @@ static int try_pmk(struct wlantest_bss *bss, struct wlantest_sta *sta,
sta->tptk_set = 1; sta->tptk_set = 1;
return 0; return 0;
} }
add_note(wt, MSG_DEBUG, "Derived new PTK");
os_memcpy(&sta->ptk, &ptk, sizeof(ptk)); os_memcpy(&sta->ptk, &ptk, sizeof(ptk));
wpa_hexdump(MSG_DEBUG, "PTK:KCK", sta->ptk.kck, 16); wpa_hexdump(MSG_DEBUG, "PTK:KCK", sta->ptk.kck, 16);
wpa_hexdump(MSG_DEBUG, "PTK:KEK", sta->ptk.kek, 16); wpa_hexdump(MSG_DEBUG, "PTK:KEK", sta->ptk.kek, 16);
@ -145,16 +148,16 @@ static void derive_ptk(struct wlantest *wt, struct wlantest_bss *bss,
MAC2STR(sta->addr)); MAC2STR(sta->addr));
dl_list_for_each(pmk, &bss->pmk, struct wlantest_pmk, list) { dl_list_for_each(pmk, &bss->pmk, struct wlantest_pmk, list) {
wpa_printf(MSG_DEBUG, "Try per-BSS PMK"); wpa_printf(MSG_DEBUG, "Try per-BSS PMK");
if (try_pmk(bss, sta, ver, data, len, pmk) == 0) if (try_pmk(wt, bss, sta, ver, data, len, pmk) == 0)
return; return;
} }
dl_list_for_each(pmk, &wt->pmk, struct wlantest_pmk, list) { dl_list_for_each(pmk, &wt->pmk, struct wlantest_pmk, list) {
wpa_printf(MSG_DEBUG, "Try global PMK"); wpa_printf(MSG_DEBUG, "Try global PMK");
if (try_pmk(bss, sta, ver, data, len, pmk) == 0) if (try_pmk(wt, bss, sta, ver, data, len, pmk) == 0)
return; return;
} }
wpa_printf(MSG_DEBUG, "No matching PMK found to derive PTK"); add_note(wt, MSG_DEBUG, "No matching PMK found to derive PTK");
} }
@ -181,12 +184,12 @@ static void rx_data_eapol_key_2_of_4(struct wlantest *wt, const u8 *dst,
eapol = (const struct ieee802_1x_hdr *) data; eapol = (const struct ieee802_1x_hdr *) data;
hdr = (const struct wpa_eapol_key *) (eapol + 1); hdr = (const struct wpa_eapol_key *) (eapol + 1);
if (is_zero(hdr->key_nonce, WPA_NONCE_LEN)) { if (is_zero(hdr->key_nonce, WPA_NONCE_LEN)) {
wpa_printf(MSG_INFO, "EAPOL-Key 2/4 from " MACSTR " used " add_note(wt, MSG_INFO, "EAPOL-Key 2/4 from " MACSTR
"zero nonce", MAC2STR(src)); " used zero nonce", MAC2STR(src));
} }
if (!is_zero(hdr->key_rsc, 8)) { if (!is_zero(hdr->key_rsc, 8)) {
wpa_printf(MSG_INFO, "EAPOL-Key 2/4 from " MACSTR " used " add_note(wt, MSG_INFO, "EAPOL-Key 2/4 from " MACSTR
"non-zero Key RSC", MAC2STR(src)); " used non-zero Key RSC", MAC2STR(src));
} }
os_memcpy(sta->snonce, hdr->key_nonce, WPA_NONCE_LEN); os_memcpy(sta->snonce, hdr->key_nonce, WPA_NONCE_LEN);
key_info = WPA_GET_BE16(hdr->key_info); key_info = WPA_GET_BE16(hdr->key_info);
@ -194,25 +197,27 @@ static void rx_data_eapol_key_2_of_4(struct wlantest *wt, const u8 *dst,
derive_ptk(wt, bss, sta, key_info & WPA_KEY_INFO_TYPE_MASK, data, len); derive_ptk(wt, bss, sta, key_info & WPA_KEY_INFO_TYPE_MASK, data, len);
if (!sta->ptk_set && !sta->tptk_set) { if (!sta->ptk_set && !sta->tptk_set) {
wpa_printf(MSG_DEBUG, "No PTK known to process EAPOL-Key 2/4"); add_note(wt, MSG_DEBUG,
"No PTK known to process EAPOL-Key 2/4");
return; return;
} }
kck = sta->ptk.kck; kck = sta->ptk.kck;
if (sta->tptk_set) { if (sta->tptk_set) {
wpa_printf(MSG_DEBUG, "Use TPTK for validation EAPOL-Key MIC"); add_note(wt, MSG_DEBUG,
"Use TPTK for validation EAPOL-Key MIC");
kck = sta->tptk.kck; kck = sta->tptk.kck;
} }
if (check_mic(kck, key_info & WPA_KEY_INFO_TYPE_MASK, data, len) < 0) { if (check_mic(kck, key_info & WPA_KEY_INFO_TYPE_MASK, data, len) < 0) {
wpa_printf(MSG_INFO, "Mismatch in EAPOL-Key 2/4 MIC"); add_note(wt, MSG_INFO, "Mismatch in EAPOL-Key 2/4 MIC");
return; return;
} }
wpa_printf(MSG_DEBUG, "Valid MIC found in EAPOL-Key 2/4"); add_note(wt, MSG_DEBUG, "Valid MIC found in EAPOL-Key 2/4");
key_data = (const u8 *) (hdr + 1); key_data = (const u8 *) (hdr + 1);
if (wpa_supplicant_parse_ies(key_data, key_data_len, &ie) < 0) { if (wpa_supplicant_parse_ies(key_data, key_data_len, &ie) < 0) {
wpa_printf(MSG_INFO, "Failed to parse EAPOL-Key Key Data"); add_note(wt, MSG_INFO, "Failed to parse EAPOL-Key Key Data");
return; return;
} }
@ -221,9 +226,10 @@ static void rx_data_eapol_key_2_of_4(struct wlantest *wt, const u8 *dst,
ie.wpa_ie, ie.wpa_ie_len); ie.wpa_ie, ie.wpa_ie_len);
if (os_memcmp(ie.wpa_ie, sta->rsnie, ie.wpa_ie_len) != 0) { if (os_memcmp(ie.wpa_ie, sta->rsnie, ie.wpa_ie_len) != 0) {
struct ieee802_11_elems elems; struct ieee802_11_elems elems;
wpa_printf(MSG_INFO, "Mismatch in WPA IE between " add_note(wt, MSG_INFO,
"EAPOL-Key 2/4 and (Re)Association " "Mismatch in WPA IE between EAPOL-Key 2/4 "
"Request from " MACSTR, MAC2STR(sta->addr)); "and (Re)Association Request from " MACSTR,
MAC2STR(sta->addr));
wpa_hexdump(MSG_INFO, "WPA IE in EAPOL-Key", wpa_hexdump(MSG_INFO, "WPA IE in EAPOL-Key",
ie.wpa_ie, ie.wpa_ie_len); ie.wpa_ie, ie.wpa_ie_len);
wpa_hexdump(MSG_INFO, "WPA IE in (Re)Association " wpa_hexdump(MSG_INFO, "WPA IE in (Re)Association "
@ -249,9 +255,10 @@ static void rx_data_eapol_key_2_of_4(struct wlantest *wt, const u8 *dst,
ie.rsn_ie, ie.rsn_ie_len); ie.rsn_ie, ie.rsn_ie_len);
if (os_memcmp(ie.rsn_ie, sta->rsnie, ie.rsn_ie_len) != 0) { if (os_memcmp(ie.rsn_ie, sta->rsnie, ie.rsn_ie_len) != 0) {
struct ieee802_11_elems elems; struct ieee802_11_elems elems;
wpa_printf(MSG_INFO, "Mismatch in RSN IE between " add_note(wt, MSG_INFO,
"EAPOL-Key 2/4 and (Re)Association " "Mismatch in RSN IE between EAPOL-Key 2/4 "
"Request from " MACSTR, MAC2STR(sta->addr)); "and (Re)Association Request from " MACSTR,
MAC2STR(sta->addr));
wpa_hexdump(MSG_INFO, "RSN IE in EAPOL-Key", wpa_hexdump(MSG_INFO, "RSN IE in EAPOL-Key",
ie.rsn_ie, ie.rsn_ie_len); ie.rsn_ie, ie.rsn_ie_len);
wpa_hexdump(MSG_INFO, "RSN IE in (Re)Association " wpa_hexdump(MSG_INFO, "RSN IE in (Re)Association "
@ -274,7 +281,7 @@ static void rx_data_eapol_key_2_of_4(struct wlantest *wt, const u8 *dst,
} }
static u8 * decrypt_eapol_key_data_rc4(const u8 *kek, static u8 * decrypt_eapol_key_data_rc4(struct wlantest *wt, const u8 *kek,
const struct wpa_eapol_key *hdr, const struct wpa_eapol_key *hdr,
size_t *len) size_t *len)
{ {
@ -289,7 +296,7 @@ static u8 * decrypt_eapol_key_data_rc4(const u8 *kek,
os_memcpy(ek + 16, kek, 16); os_memcpy(ek + 16, kek, 16);
os_memcpy(buf, hdr + 1, keydatalen); os_memcpy(buf, hdr + 1, keydatalen);
if (rc4_skip(ek, 32, 256, buf, keydatalen)) { if (rc4_skip(ek, 32, 256, buf, keydatalen)) {
wpa_printf(MSG_INFO, "RC4 failed"); add_note(wt, MSG_INFO, "RC4 failed");
os_free(buf); os_free(buf);
return NULL; return NULL;
} }
@ -299,7 +306,7 @@ static u8 * decrypt_eapol_key_data_rc4(const u8 *kek,
} }
static u8 * decrypt_eapol_key_data_aes(const u8 *kek, static u8 * decrypt_eapol_key_data_aes(struct wlantest *wt, const u8 *kek,
const struct wpa_eapol_key *hdr, const struct wpa_eapol_key *hdr,
size_t *len) size_t *len)
{ {
@ -307,8 +314,8 @@ static u8 * decrypt_eapol_key_data_aes(const u8 *kek,
u16 keydatalen = WPA_GET_BE16(hdr->key_data_length); u16 keydatalen = WPA_GET_BE16(hdr->key_data_length);
if (keydatalen % 8) { if (keydatalen % 8) {
wpa_printf(MSG_INFO, "Unsupported AES-WRAP len %d", add_note(wt, MSG_INFO, "Unsupported AES-WRAP len %d",
keydatalen); keydatalen);
return NULL; return NULL;
} }
keydatalen -= 8; /* AES-WRAP adds 8 bytes */ keydatalen -= 8; /* AES-WRAP adds 8 bytes */
@ -317,8 +324,9 @@ static u8 * decrypt_eapol_key_data_aes(const u8 *kek,
return NULL; return NULL;
if (aes_unwrap(kek, keydatalen / 8, (u8 *) (hdr + 1), buf)) { if (aes_unwrap(kek, keydatalen / 8, (u8 *) (hdr + 1), buf)) {
os_free(buf); os_free(buf);
wpa_printf(MSG_INFO, "AES unwrap failed - " add_note(wt, MSG_INFO,
"could not decrypt EAPOL-Key key data"); "AES unwrap failed - could not decrypt EAPOL-Key "
"key data");
return NULL; return NULL;
} }
@ -327,31 +335,33 @@ static u8 * decrypt_eapol_key_data_aes(const u8 *kek,
} }
static u8 * decrypt_eapol_key_data(const u8 *kek, u16 ver, static u8 * decrypt_eapol_key_data(struct wlantest *wt, const u8 *kek, u16 ver,
const struct wpa_eapol_key *hdr, const struct wpa_eapol_key *hdr,
size_t *len) size_t *len)
{ {
switch (ver) { switch (ver) {
case WPA_KEY_INFO_TYPE_HMAC_MD5_RC4: case WPA_KEY_INFO_TYPE_HMAC_MD5_RC4:
return decrypt_eapol_key_data_rc4(kek, hdr, len); return decrypt_eapol_key_data_rc4(wt, kek, hdr, len);
case WPA_KEY_INFO_TYPE_HMAC_SHA1_AES: case WPA_KEY_INFO_TYPE_HMAC_SHA1_AES:
case WPA_KEY_INFO_TYPE_AES_128_CMAC: case WPA_KEY_INFO_TYPE_AES_128_CMAC:
return decrypt_eapol_key_data_aes(kek, hdr, len); return decrypt_eapol_key_data_aes(wt, kek, hdr, len);
default: default:
wpa_printf(MSG_INFO, "Unsupported EAPOL-Key Key Descriptor " add_note(wt, MSG_INFO,
"Version %u", ver); "Unsupported EAPOL-Key Key Descriptor Version %u",
ver);
return NULL; return NULL;
} }
} }
static void learn_kde_keys(struct wlantest_bss *bss, struct wlantest_sta *sta, static void learn_kde_keys(struct wlantest *wt, struct wlantest_bss *bss,
struct wlantest_sta *sta,
const u8 *buf, size_t len, const u8 *rsc) const u8 *buf, size_t len, const u8 *rsc)
{ {
struct wpa_eapol_ie_parse ie; struct wpa_eapol_ie_parse ie;
if (wpa_supplicant_parse_ies(buf, len, &ie) < 0) { if (wpa_supplicant_parse_ies(buf, len, &ie) < 0) {
wpa_printf(MSG_INFO, "Failed to parse EAPOL-Key Key Data"); add_note(wt, MSG_INFO, "Failed to parse EAPOL-Key Key Data");
return; return;
} }
@ -373,10 +383,11 @@ static void learn_kde_keys(struct wlantest_bss *bss, struct wlantest_sta *sta,
id = ie.gtk[0] & 0x03; id = ie.gtk[0] & 0x03;
wpa_printf(MSG_DEBUG, "GTK KeyID=%u tx=%u", wpa_printf(MSG_DEBUG, "GTK KeyID=%u tx=%u",
id, !!(ie.gtk[0] & 0x04)); id, !!(ie.gtk[0] & 0x04));
if ((ie.gtk[0] & 0xf8) || ie.gtk[1]) if ((ie.gtk[0] & 0xf8) || ie.gtk[1]) {
wpa_printf(MSG_INFO, "GTK KDE: Reserved field " add_note(wt, MSG_INFO,
"set: %02x %02x", "GTK KDE: Reserved field set: "
ie.gtk[0], ie.gtk[1]); "%02x %02x", ie.gtk[0], ie.gtk[1]);
}
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;
@ -393,8 +404,8 @@ static void learn_kde_keys(struct wlantest_bss *bss, struct wlantest_sta *sta,
sta->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", add_note(wt, MSG_INFO, "Invalid GTK KDE length %u",
(unsigned) ie.gtk_len); (unsigned) ie.gtk_len);
} }
} }
@ -405,8 +416,8 @@ static void learn_kde_keys(struct wlantest_bss *bss, struct wlantest_sta *sta,
u16 id; u16 id;
id = WPA_GET_LE16(ie.igtk); id = WPA_GET_LE16(ie.igtk);
if (id > 5) { if (id > 5) {
wpa_printf(MSG_INFO, "Unexpected IGTK KeyID " add_note(wt, MSG_INFO,
"%u", id); "Unexpected IGTK KeyID %u", id);
} else { } else {
const u8 *ipn; const u8 *ipn;
wpa_printf(MSG_DEBUG, "IGTK KeyID %u", id); wpa_printf(MSG_DEBUG, "IGTK KeyID %u", id);
@ -425,8 +436,8 @@ static void learn_kde_keys(struct wlantest_bss *bss, struct wlantest_sta *sta,
bss->igtk_idx = id; bss->igtk_idx = id;
} }
} else { } else {
wpa_printf(MSG_INFO, "Invalid IGTK KDE length %u", add_note(wt, MSG_INFO, "Invalid IGTK KDE length %u",
(unsigned) ie.igtk_len); (unsigned) ie.igtk_len);
} }
} }
} }
@ -461,8 +472,8 @@ static void rx_data_eapol_key_3_of_4(struct wlantest *wt, const u8 *dst,
key_info = WPA_GET_BE16(hdr->key_info); key_info = WPA_GET_BE16(hdr->key_info);
if (os_memcmp(sta->anonce, hdr->key_nonce, WPA_NONCE_LEN) != 0) { if (os_memcmp(sta->anonce, hdr->key_nonce, WPA_NONCE_LEN) != 0) {
wpa_printf(MSG_INFO, "EAPOL-Key ANonce mismatch between 1/4 " add_note(wt, MSG_INFO,
"and 3/4"); "EAPOL-Key ANonce mismatch between 1/4 and 3/4");
recalc = 1; recalc = 1;
} }
os_memcpy(sta->anonce, hdr->key_nonce, WPA_NONCE_LEN); os_memcpy(sta->anonce, hdr->key_nonce, WPA_NONCE_LEN);
@ -472,37 +483,39 @@ static void rx_data_eapol_key_3_of_4(struct wlantest *wt, const u8 *dst,
} }
if (!sta->ptk_set && !sta->tptk_set) { if (!sta->ptk_set && !sta->tptk_set) {
wpa_printf(MSG_DEBUG, "No PTK known to process EAPOL-Key 3/4"); add_note(wt, MSG_DEBUG,
"No PTK known to process EAPOL-Key 3/4");
return; return;
} }
kek = sta->ptk.kek; kek = sta->ptk.kek;
kck = sta->ptk.kck; kck = sta->ptk.kck;
if (sta->tptk_set) { if (sta->tptk_set) {
wpa_printf(MSG_DEBUG, "Use TPTK for validation EAPOL-Key MIC"); add_note(wt, MSG_DEBUG,
"Use TPTK for validation EAPOL-Key MIC");
kck = sta->tptk.kck; kck = sta->tptk.kck;
kek = sta->tptk.kek; kek = sta->tptk.kek;
} }
if (check_mic(kck, key_info & WPA_KEY_INFO_TYPE_MASK, data, len) < 0) { if (check_mic(kck, key_info & WPA_KEY_INFO_TYPE_MASK, data, len) < 0) {
wpa_printf(MSG_INFO, "Mismatch in EAPOL-Key 3/4 MIC"); add_note(wt, MSG_INFO, "Mismatch in EAPOL-Key 3/4 MIC");
return; return;
} }
wpa_printf(MSG_DEBUG, "Valid MIC found in EAPOL-Key 3/4"); add_note(wt, MSG_DEBUG, "Valid MIC found in EAPOL-Key 3/4");
key_data = (const u8 *) (hdr + 1); key_data = (const u8 *) (hdr + 1);
if (!(key_info & WPA_KEY_INFO_ENCR_KEY_DATA)) { if (!(key_info & WPA_KEY_INFO_ENCR_KEY_DATA)) {
if (sta->proto & WPA_PROTO_RSN) if (sta->proto & WPA_PROTO_RSN)
wpa_printf(MSG_INFO, "EAPOL-Key 3/4 without " add_note(wt, MSG_INFO,
"EncrKeyData bit"); "EAPOL-Key 3/4 without EncrKeyData bit");
decrypted = key_data; decrypted = key_data;
decrypted_len = WPA_GET_BE16(hdr->key_data_length); decrypted_len = WPA_GET_BE16(hdr->key_data_length);
} else { } else {
ver = key_info & WPA_KEY_INFO_TYPE_MASK; ver = key_info & WPA_KEY_INFO_TYPE_MASK;
decrypted_buf = decrypt_eapol_key_data(kek, ver, hdr, decrypted_buf = decrypt_eapol_key_data(wt, kek, ver, hdr,
&decrypted_len); &decrypted_len);
if (decrypted_buf == NULL) { if (decrypted_buf == NULL) {
wpa_printf(MSG_INFO, "Failed to decrypt EAPOL-Key Key " add_note(wt, MSG_INFO,
"Data"); "Failed to decrypt EAPOL-Key Key Data");
return; return;
} }
decrypted = decrypted_buf; decrypted = decrypted_buf;
@ -550,7 +563,7 @@ static void rx_data_eapol_key_3_of_4(struct wlantest *wt, const u8 *dst,
} }
if (wpa_supplicant_parse_ies(decrypted, decrypted_len, &ie) < 0) { if (wpa_supplicant_parse_ies(decrypted, decrypted_len, &ie) < 0) {
wpa_printf(MSG_INFO, "Failed to parse EAPOL-Key Key Data"); add_note(wt, MSG_INFO, "Failed to parse EAPOL-Key Key Data");
os_free(decrypted_buf); os_free(decrypted_buf);
return; return;
} }
@ -558,9 +571,10 @@ static void rx_data_eapol_key_3_of_4(struct wlantest *wt, const u8 *dst,
if ((ie.wpa_ie && if ((ie.wpa_ie &&
os_memcmp(ie.wpa_ie, bss->wpaie, ie.wpa_ie_len) != 0) || os_memcmp(ie.wpa_ie, bss->wpaie, ie.wpa_ie_len) != 0) ||
(ie.wpa_ie == NULL && bss->wpaie[0])) { (ie.wpa_ie == NULL && bss->wpaie[0])) {
wpa_printf(MSG_INFO, "Mismatch in WPA IE between " add_note(wt, MSG_INFO,
"EAPOL-Key 3/4 and Beacon/Probe Response " "Mismatch in WPA IE between EAPOL-Key 3/4 and "
"from " MACSTR, MAC2STR(bss->bssid)); "Beacon/Probe Response from " MACSTR,
MAC2STR(bss->bssid));
wpa_hexdump(MSG_INFO, "WPA IE in EAPOL-Key", wpa_hexdump(MSG_INFO, "WPA IE in EAPOL-Key",
ie.wpa_ie, ie.wpa_ie_len); ie.wpa_ie, ie.wpa_ie_len);
wpa_hexdump(MSG_INFO, "WPA IE in Beacon/Probe " wpa_hexdump(MSG_INFO, "WPA IE in Beacon/Probe "
@ -572,9 +586,9 @@ static void rx_data_eapol_key_3_of_4(struct wlantest *wt, const u8 *dst,
if ((ie.rsn_ie && if ((ie.rsn_ie &&
os_memcmp(ie.rsn_ie, bss->rsnie, ie.rsn_ie_len) != 0) || os_memcmp(ie.rsn_ie, bss->rsnie, ie.rsn_ie_len) != 0) ||
(ie.rsn_ie == NULL && bss->rsnie[0])) { (ie.rsn_ie == NULL && bss->rsnie[0])) {
wpa_printf(MSG_INFO, "Mismatch in RSN IE between " add_note(wt, MSG_INFO, "Mismatch in RSN IE between EAPOL-Key "
"EAPOL-Key 3/4 and Beacon/Probe Response " "3/4 and Beacon/Probe Response from " MACSTR,
"from " MACSTR, MAC2STR(bss->bssid)); MAC2STR(bss->bssid));
wpa_hexdump(MSG_INFO, "RSN IE in EAPOL-Key", wpa_hexdump(MSG_INFO, "RSN IE in EAPOL-Key",
ie.rsn_ie, ie.rsn_ie_len); ie.rsn_ie, ie.rsn_ie_len);
wpa_hexdump(MSG_INFO, "RSN IE in (Re)Association " wpa_hexdump(MSG_INFO, "RSN IE in (Re)Association "
@ -583,7 +597,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, sta, decrypted, decrypted_len, hdr->key_rsc); learn_kde_keys(wt, bss, sta, decrypted, decrypted_len, hdr->key_rsc);
os_free(decrypted_buf); os_free(decrypted_buf);
} }
@ -684,7 +698,7 @@ static void rx_data_eapol_key_1_of_2(struct wlantest *wt, const u8 *dst,
return; return;
} }
ver = key_info & WPA_KEY_INFO_TYPE_MASK; ver = key_info & WPA_KEY_INFO_TYPE_MASK;
decrypted = decrypt_eapol_key_data(sta->ptk.kek, ver, hdr, decrypted = decrypt_eapol_key_data(wt, sta->ptk.kek, ver, hdr,
&decrypted_len); &decrypted_len);
if (decrypted == NULL) { if (decrypted == NULL) {
wpa_printf(MSG_INFO, "Failed to decrypt EAPOL-Key Key Data"); wpa_printf(MSG_INFO, "Failed to decrypt EAPOL-Key Key Data");
@ -731,7 +745,7 @@ 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, sta, decrypted, decrypted_len, learn_kde_keys(wt, bss, sta, decrypted, decrypted_len,
hdr->key_rsc); 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;

View file

@ -14,8 +14,8 @@
#include "wlantest.h" #include "wlantest.h"
static void ping_update(struct wlantest_sta *sta, int req, u32 src, u32 dst, static void ping_update(struct wlantest *wt, struct wlantest_sta *sta, int req,
u16 id, u16 seq) u32 src, u32 dst, u16 id, u16 seq)
{ {
if (req) { if (req) {
sta->icmp_echo_req_src = src; sta->icmp_echo_req_src = src;
@ -34,8 +34,8 @@ static void ping_update(struct wlantest_sta *sta, int req, u32 src, u32 dst,
sta->counters[WLANTEST_STA_COUNTER_REASSOCREQ_TX] == 0) sta->counters[WLANTEST_STA_COUNTER_REASSOCREQ_TX] == 0)
sta->counters[ sta->counters[
WLANTEST_STA_COUNTER_PING_OK_FIRST_ASSOC]++; WLANTEST_STA_COUNTER_PING_OK_FIRST_ASSOC]++;
wpa_printf(MSG_DEBUG, "ICMP echo (ping) match for STA " MACSTR, add_note(wt, MSG_DEBUG, "ICMP echo (ping) match for STA "
MAC2STR(sta->addr)); MACSTR, MAC2STR(sta->addr));
} }
} }
@ -68,15 +68,15 @@ static void rx_data_icmp(struct wlantest *wt, const u8 *bssid,
addr.s_addr = dst; addr.s_addr = dst;
snprintf(buf, sizeof(buf), "%s", inet_ntoa(addr)); snprintf(buf, sizeof(buf), "%s", inet_ntoa(addr));
addr.s_addr = src; addr.s_addr = src;
wpa_printf(MSG_DEBUG, "ICMP echo %s %s -> %s id=%04x seq=%u len=%u%s", add_note(wt, MSG_DEBUG, "ICMP echo %s %s -> %s id=%04x seq=%u len=%u%s",
hdr->type == ICMP_ECHO ? "request" : "response", hdr->type == ICMP_ECHO ? "request" : "response",
inet_ntoa(addr), buf, id, seq, (unsigned) len - 8, inet_ntoa(addr), buf, id, seq, (unsigned) len - 8,
peer_addr ? " [DL]" : ""); peer_addr ? " [DL]" : "");
bss = bss_find(wt, bssid); bss = bss_find(wt, bssid);
if (bss == NULL) { if (bss == NULL) {
wpa_printf(MSG_INFO, "No BSS " MACSTR " known for ICMP packet", add_note(wt, MSG_INFO, "No BSS " MACSTR
MAC2STR(bssid)); " known for ICMP packet", MAC2STR(bssid));
return; return;
} }
@ -85,14 +85,14 @@ static void rx_data_icmp(struct wlantest *wt, const u8 *bssid,
sta = sta_find(bss, sta_addr); sta = sta_find(bss, sta_addr);
if (sta == NULL) { if (sta == NULL) {
wpa_printf(MSG_INFO, "No STA " MACSTR " known for ICMP packet", add_note(wt, MSG_INFO, "No STA " MACSTR
MAC2STR(sta_addr)); " known for ICMP packet", MAC2STR(sta_addr));
return; return;
} }
ping_update(sta, hdr->type == ICMP_ECHO, src, dst, id, seq); ping_update(wt, sta, hdr->type == ICMP_ECHO, src, dst, id, seq);
if (peer_addr && (sta = sta_find(bss, peer_addr))) if (peer_addr && (sta = sta_find(bss, peer_addr)))
ping_update(sta, hdr->type == ICMP_ECHO, src, dst, id, seq); ping_update(wt, sta, hdr->type == ICMP_ECHO, src, dst, id, seq);
} }
@ -109,24 +109,24 @@ void rx_data_ip(struct wlantest *wt, const u8 *bssid, const u8 *sta_addr,
if (len < sizeof(*ip)) if (len < sizeof(*ip))
return; return;
if (ip->version != 4) { if (ip->version != 4) {
wpa_printf(MSG_DEBUG, "Unexpected IP protocol version %u in " add_note(wt, MSG_DEBUG, "Unexpected IP protocol version %u in "
"IPv4 packet (bssid=" MACSTR " str=" MACSTR "IPv4 packet (bssid=" MACSTR " str=" MACSTR
" dst=" MACSTR ")", ip->version, MAC2STR(bssid), " dst=" MACSTR ")", ip->version, MAC2STR(bssid),
MAC2STR(src), MAC2STR(dst)); MAC2STR(src), MAC2STR(dst));
return; return;
} }
if (ip->ihl * 4 < sizeof(*ip)) { if (ip->ihl * 4 < sizeof(*ip)) {
wpa_printf(MSG_DEBUG, "Unexpected IP header length %u in " add_note(wt, MSG_DEBUG, "Unexpected IP header length %u in "
"IPv4 packet (bssid=" MACSTR " str=" MACSTR "IPv4 packet (bssid=" MACSTR " str=" MACSTR
" dst=" MACSTR ")", ip->ihl, MAC2STR(bssid), " dst=" MACSTR ")", ip->ihl, MAC2STR(bssid),
MAC2STR(src), MAC2STR(dst)); MAC2STR(src), MAC2STR(dst));
return; return;
} }
if (ip->ihl * 4 > len) { if (ip->ihl * 4 > len) {
wpa_printf(MSG_DEBUG, "Truncated IP header (ihl=%u len=%u) in " add_note(wt, MSG_DEBUG, "Truncated IP header (ihl=%u len=%u) "
"IPv4 packet (bssid=" MACSTR " str=" MACSTR "in IPv4 packet (bssid=" MACSTR " str=" MACSTR
" dst=" MACSTR ")", ip->ihl, (unsigned) len, " dst=" MACSTR ")", ip->ihl, (unsigned) len,
MAC2STR(bssid), MAC2STR(src), MAC2STR(dst)); MAC2STR(bssid), MAC2STR(src), MAC2STR(dst));
return; return;
} }

View file

@ -65,8 +65,8 @@ static void rx_mgmt_beacon(struct wlantest *wt, const u8 *data, size_t len)
&elems, 0) == ParseFailed) { &elems, 0) == ParseFailed) {
if (bss->parse_error_reported) if (bss->parse_error_reported)
return; return;
wpa_printf(MSG_INFO, "Invalid IEs in a Beacon frame from " add_note(wt, MSG_INFO, "Invalid IEs in a Beacon frame from "
MACSTR, MAC2STR(mgmt->sa)); MACSTR, MAC2STR(mgmt->sa));
bss->parse_error_reported = 1; bss->parse_error_reported = 1;
return; return;
} }
@ -92,8 +92,8 @@ static void rx_mgmt_probe_resp(struct wlantest *wt, const u8 *data, size_t len)
&elems, 0) == ParseFailed) { &elems, 0) == ParseFailed) {
if (bss->parse_error_reported) if (bss->parse_error_reported)
return; return;
wpa_printf(MSG_INFO, "Invalid IEs in a Probe Response frame " add_note(wt, MSG_INFO, "Invalid IEs in a Probe Response frame "
"from " MACSTR, MAC2STR(mgmt->sa)); "from " MACSTR, MAC2STR(mgmt->sa));
bss->parse_error_reported = 1; bss->parse_error_reported = 1;
return; return;
} }
@ -121,8 +121,8 @@ static void rx_mgmt_auth(struct wlantest *wt, const u8 *data, size_t len)
return; return;
if (len < 24 + 6) { if (len < 24 + 6) {
wpa_printf(MSG_INFO, "Too short Authentication frame from " add_note(wt, MSG_INFO, "Too short Authentication frame from "
MACSTR, MAC2STR(mgmt->sa)); MACSTR, MAC2STR(mgmt->sa));
return; return;
} }
@ -136,9 +136,9 @@ static void rx_mgmt_auth(struct wlantest *wt, const u8 *data, size_t len)
if (alg == 0 && trans == 2 && status == 0) { if (alg == 0 && trans == 2 && status == 0) {
if (sta->state == STATE1) { if (sta->state == STATE1) {
wpa_printf(MSG_DEBUG, "STA " MACSTR add_note(wt, MSG_DEBUG, "STA " MACSTR
" moved to State 2 with " MACSTR, " moved to State 2 with " MACSTR,
MAC2STR(sta->addr), MAC2STR(bss->bssid)); MAC2STR(sta->addr), MAC2STR(bss->bssid));
sta->state = STATE2; sta->state = STATE2;
} }
} }
@ -150,28 +150,29 @@ static void rx_mgmt_auth(struct wlantest *wt, const u8 *data, size_t len)
} }
static void deauth_all_stas(struct wlantest_bss *bss) static void deauth_all_stas(struct wlantest *wt, struct wlantest_bss *bss)
{ {
struct wlantest_sta *sta; struct wlantest_sta *sta;
dl_list_for_each(sta, &bss->sta, struct wlantest_sta, list) { dl_list_for_each(sta, &bss->sta, struct wlantest_sta, list) {
if (sta->state == STATE1) if (sta->state == STATE1)
continue; continue;
wpa_printf(MSG_DEBUG, "STA " MACSTR add_note(wt, MSG_DEBUG, "STA " MACSTR
" moved to State 1 with " MACSTR, " moved to State 1 with " MACSTR,
MAC2STR(sta->addr), MAC2STR(bss->bssid)); MAC2STR(sta->addr), MAC2STR(bss->bssid));
sta->state = STATE1; sta->state = STATE1;
} }
} }
static void tdls_link_down(struct wlantest_bss *bss, struct wlantest_sta *sta) static void tdls_link_down(struct wlantest *wt, struct wlantest_bss *bss,
struct wlantest_sta *sta)
{ {
struct wlantest_tdls *tdls; struct wlantest_tdls *tdls;
dl_list_for_each(tdls, &bss->tdls, struct wlantest_tdls, list) { dl_list_for_each(tdls, &bss->tdls, struct wlantest_tdls, list) {
if ((tdls->init == sta || tdls->resp == sta) && tdls->link_up) if ((tdls->init == sta || tdls->resp == sta) && tdls->link_up)
{ {
wpa_printf(MSG_DEBUG, "TDLS: Set link down based on " add_note(wt, MSG_DEBUG, "TDLS: Set link down based on "
"STA deauth/disassoc"); "STA deauth/disassoc");
tdls->link_up = 0; tdls->link_up = 0;
} }
} }
@ -196,8 +197,8 @@ static void rx_mgmt_deauth(struct wlantest *wt, const u8 *data, size_t len,
sta = sta_get(bss, mgmt->sa); sta = sta_get(bss, mgmt->sa);
if (len < 24 + 2) { if (len < 24 + 2) {
wpa_printf(MSG_INFO, "Too short Deauthentication frame from " add_note(wt, MSG_INFO, "Too short Deauthentication frame from "
MACSTR, MAC2STR(mgmt->sa)); MACSTR, MAC2STR(mgmt->sa));
return; return;
} }
@ -210,7 +211,7 @@ static void rx_mgmt_deauth(struct wlantest *wt, const u8 *data, size_t len,
if (sta == NULL) { if (sta == NULL) {
if (valid && mgmt->da[0] == 0xff) if (valid && mgmt->da[0] == 0xff)
deauth_all_stas(bss); deauth_all_stas(wt, bss);
return; return;
} }
@ -232,19 +233,19 @@ static void rx_mgmt_deauth(struct wlantest *wt, const u8 *data, size_t len,
WLANTEST_STA_COUNTER_INVALID_DEAUTH_TX]++; WLANTEST_STA_COUNTER_INVALID_DEAUTH_TX]++;
if (!valid) { if (!valid) {
wpa_printf(MSG_INFO, "Do not change STA " MACSTR " State " add_note(wt, MSG_INFO, "Do not change STA " MACSTR " State "
"since Disassociation frame was not protected " "since Disassociation frame was not protected "
"correctly", MAC2STR(sta->addr)); "correctly", MAC2STR(sta->addr));
return; return;
} }
if (sta->state != STATE1) { if (sta->state != STATE1) {
wpa_printf(MSG_DEBUG, "STA " MACSTR add_note(wt, MSG_DEBUG, "STA " MACSTR
" moved to State 1 with " MACSTR, " moved to State 1 with " MACSTR,
MAC2STR(sta->addr), MAC2STR(bss->bssid)); MAC2STR(sta->addr), MAC2STR(bss->bssid));
sta->state = STATE1; sta->state = STATE1;
} }
tdls_link_down(bss, sta); tdls_link_down(wt, bss, sta);
} }
@ -264,8 +265,8 @@ static void rx_mgmt_assoc_req(struct wlantest *wt, const u8 *data, size_t len)
return; return;
if (len < 24 + 4) { if (len < 24 + 4) {
wpa_printf(MSG_INFO, "Too short Association Request frame " add_note(wt, MSG_INFO, "Too short Association Request frame "
"from " MACSTR, MAC2STR(mgmt->sa)); "from " MACSTR, MAC2STR(mgmt->sa));
return; return;
} }
@ -280,8 +281,8 @@ static void rx_mgmt_assoc_req(struct wlantest *wt, const u8 *data, size_t len)
if (ieee802_11_parse_elems(mgmt->u.assoc_req.variable, if (ieee802_11_parse_elems(mgmt->u.assoc_req.variable,
len - (mgmt->u.assoc_req.variable - data), len - (mgmt->u.assoc_req.variable - data),
&elems, 0) == ParseFailed) { &elems, 0) == ParseFailed) {
wpa_printf(MSG_INFO, "Invalid IEs in Association Request " add_note(wt, MSG_INFO, "Invalid IEs in Association Request "
"frame from " MACSTR, MAC2STR(mgmt->sa)); "frame from " MACSTR, MAC2STR(mgmt->sa));
return; return;
} }
@ -315,8 +316,8 @@ static void rx_mgmt_assoc_resp(struct wlantest *wt, const u8 *data, size_t len)
return; return;
if (len < 24 + 6) { if (len < 24 + 6) {
wpa_printf(MSG_INFO, "Too short Association Response frame " add_note(wt, MSG_INFO, "Too short Association Response frame "
"from " MACSTR, MAC2STR(mgmt->sa)); "from " MACSTR, MAC2STR(mgmt->sa));
return; return;
} }
@ -335,17 +336,17 @@ static void rx_mgmt_assoc_resp(struct wlantest *wt, const u8 *data, size_t len)
size_t ies_len = len - (mgmt->u.assoc_resp.variable - data); size_t ies_len = len - (mgmt->u.assoc_resp.variable - data);
if (ieee802_11_parse_elems(ies, ies_len, &elems, 0) == if (ieee802_11_parse_elems(ies, ies_len, &elems, 0) ==
ParseFailed) { ParseFailed) {
wpa_printf(MSG_INFO, "Failed to parse IEs in " add_note(wt, MSG_INFO, "Failed to parse IEs in "
"AssocResp from " MACSTR, "AssocResp from " MACSTR,
MAC2STR(mgmt->sa)); MAC2STR(mgmt->sa));
} else if (elems.timeout_int == NULL || } else if (elems.timeout_int == NULL ||
elems.timeout_int_len != 5 || elems.timeout_int_len != 5 ||
elems.timeout_int[0] != elems.timeout_int[0] !=
WLAN_TIMEOUT_ASSOC_COMEBACK) { WLAN_TIMEOUT_ASSOC_COMEBACK) {
wpa_printf(MSG_INFO, "No valid Timeout Interval IE " add_note(wt, MSG_INFO, "No valid Timeout Interval IE "
"with Assoc Comeback time in AssocResp " "with Assoc Comeback time in AssocResp "
"(status=30) from " MACSTR, "(status=30) from " MACSTR,
MAC2STR(mgmt->sa)); MAC2STR(mgmt->sa));
} else { } else {
sta->counters[ sta->counters[
WLANTEST_STA_COUNTER_ASSOCRESP_COMEBACK]++; WLANTEST_STA_COUNTER_ASSOCRESP_COMEBACK]++;
@ -356,21 +357,22 @@ static void rx_mgmt_assoc_resp(struct wlantest *wt, const u8 *data, size_t len)
return; return;
if ((aid & 0xc000) != 0xc000) { if ((aid & 0xc000) != 0xc000) {
wpa_printf(MSG_DEBUG, "Two MSBs of the AID were not set to 1 " add_note(wt, MSG_DEBUG, "Two MSBs of the AID were not set to 1 "
"in Association Response from " MACSTR, "in Association Response from " MACSTR,
MAC2STR(mgmt->sa)); MAC2STR(mgmt->sa));
} }
sta->aid = aid & 0xc000; sta->aid = aid & 0xc000;
if (sta->state < STATE2) { if (sta->state < STATE2) {
wpa_printf(MSG_DEBUG, "STA " MACSTR " was not in State 2 when " add_note(wt, MSG_DEBUG,
"getting associated", MAC2STR(sta->addr)); "STA " MACSTR " was not in State 2 when "
"getting associated", MAC2STR(sta->addr));
} }
if (sta->state < STATE3) { if (sta->state < STATE3) {
wpa_printf(MSG_DEBUG, "STA " MACSTR add_note(wt, MSG_DEBUG, "STA " MACSTR
" moved to State 3 with " MACSTR, " moved to State 3 with " MACSTR,
MAC2STR(sta->addr), MAC2STR(bss->bssid)); MAC2STR(sta->addr), MAC2STR(bss->bssid));
sta->state = STATE3; sta->state = STATE3;
} }
} }
@ -393,8 +395,8 @@ static void rx_mgmt_reassoc_req(struct wlantest *wt, const u8 *data,
return; return;
if (len < 24 + 4 + ETH_ALEN) { if (len < 24 + 4 + ETH_ALEN) {
wpa_printf(MSG_INFO, "Too short Reassociation Request frame " add_note(wt, MSG_INFO, "Too short Reassociation Request frame "
"from " MACSTR, MAC2STR(mgmt->sa)); "from " MACSTR, MAC2STR(mgmt->sa));
return; return;
} }
@ -410,8 +412,8 @@ static void rx_mgmt_reassoc_req(struct wlantest *wt, const u8 *data,
if (ieee802_11_parse_elems(mgmt->u.reassoc_req.variable, if (ieee802_11_parse_elems(mgmt->u.reassoc_req.variable,
len - (mgmt->u.reassoc_req.variable - data), len - (mgmt->u.reassoc_req.variable - data),
&elems, 0) == ParseFailed) { &elems, 0) == ParseFailed) {
wpa_printf(MSG_INFO, "Invalid IEs in Reassociation Request " add_note(wt, MSG_INFO, "Invalid IEs in Reassociation Request "
"frame from " MACSTR, MAC2STR(mgmt->sa)); "frame from " MACSTR, MAC2STR(mgmt->sa));
return; return;
} }
@ -447,8 +449,8 @@ static void rx_mgmt_reassoc_resp(struct wlantest *wt, const u8 *data,
return; return;
if (len < 24 + 6) { if (len < 24 + 6) {
wpa_printf(MSG_INFO, "Too short Reassociation Response frame " add_note(wt, MSG_INFO, "Too short Reassociation Response frame "
"from " MACSTR, MAC2STR(mgmt->sa)); "from " MACSTR, MAC2STR(mgmt->sa));
return; return;
} }
@ -467,17 +469,17 @@ static void rx_mgmt_reassoc_resp(struct wlantest *wt, const u8 *data,
size_t ies_len = len - (mgmt->u.reassoc_resp.variable - data); size_t ies_len = len - (mgmt->u.reassoc_resp.variable - data);
if (ieee802_11_parse_elems(ies, ies_len, &elems, 0) == if (ieee802_11_parse_elems(ies, ies_len, &elems, 0) ==
ParseFailed) { ParseFailed) {
wpa_printf(MSG_INFO, "Failed to parse IEs in " add_note(wt, MSG_INFO, "Failed to parse IEs in "
"ReassocResp from " MACSTR, "ReassocResp from " MACSTR,
MAC2STR(mgmt->sa)); MAC2STR(mgmt->sa));
} else if (elems.timeout_int == NULL || } else if (elems.timeout_int == NULL ||
elems.timeout_int_len != 5 || elems.timeout_int_len != 5 ||
elems.timeout_int[0] != elems.timeout_int[0] !=
WLAN_TIMEOUT_ASSOC_COMEBACK) { WLAN_TIMEOUT_ASSOC_COMEBACK) {
wpa_printf(MSG_INFO, "No valid Timeout Interval IE " add_note(wt, MSG_INFO, "No valid Timeout Interval IE "
"with Assoc Comeback time in ReassocResp " "with Assoc Comeback time in ReassocResp "
"(status=30) from " MACSTR, "(status=30) from " MACSTR,
MAC2STR(mgmt->sa)); MAC2STR(mgmt->sa));
} else { } else {
sta->counters[ sta->counters[
WLANTEST_STA_COUNTER_REASSOCRESP_COMEBACK]++; WLANTEST_STA_COUNTER_REASSOCRESP_COMEBACK]++;
@ -488,35 +490,36 @@ static void rx_mgmt_reassoc_resp(struct wlantest *wt, const u8 *data,
return; return;
if ((aid & 0xc000) != 0xc000) { if ((aid & 0xc000) != 0xc000) {
wpa_printf(MSG_DEBUG, "Two MSBs of the AID were not set to 1 " add_note(wt, MSG_DEBUG, "Two MSBs of the AID were not set to 1 "
"in Reassociation Response from " MACSTR, "in Reassociation Response from " MACSTR,
MAC2STR(mgmt->sa)); MAC2STR(mgmt->sa));
} }
sta->aid = aid & 0xc000; sta->aid = aid & 0xc000;
if (sta->state < STATE2) { if (sta->state < STATE2) {
wpa_printf(MSG_DEBUG, "STA " MACSTR " was not in State 2 when " add_note(wt, MSG_DEBUG,
"getting associated", MAC2STR(sta->addr)); "STA " MACSTR " was not in State 2 when "
"getting associated", MAC2STR(sta->addr));
} }
if (sta->state < STATE3) { if (sta->state < STATE3) {
wpa_printf(MSG_DEBUG, "STA " MACSTR add_note(wt, MSG_DEBUG, "STA " MACSTR
" moved to State 3 with " MACSTR, " moved to State 3 with " MACSTR,
MAC2STR(sta->addr), MAC2STR(bss->bssid)); MAC2STR(sta->addr), MAC2STR(bss->bssid));
sta->state = STATE3; sta->state = STATE3;
} }
} }
static void disassoc_all_stas(struct wlantest_bss *bss) static void disassoc_all_stas(struct wlantest *wt, struct wlantest_bss *bss)
{ {
struct wlantest_sta *sta; struct wlantest_sta *sta;
dl_list_for_each(sta, &bss->sta, struct wlantest_sta, list) { dl_list_for_each(sta, &bss->sta, struct wlantest_sta, list) {
if (sta->state <= STATE2) if (sta->state <= STATE2)
continue; continue;
wpa_printf(MSG_DEBUG, "STA " MACSTR add_note(wt, MSG_DEBUG, "STA " MACSTR
" moved to State 2 with " MACSTR, " moved to State 2 with " MACSTR,
MAC2STR(sta->addr), MAC2STR(bss->bssid)); MAC2STR(sta->addr), MAC2STR(bss->bssid));
sta->state = STATE2; sta->state = STATE2;
} }
} }
@ -540,8 +543,8 @@ static void rx_mgmt_disassoc(struct wlantest *wt, const u8 *data, size_t len,
sta = sta_get(bss, mgmt->sa); sta = sta_get(bss, mgmt->sa);
if (len < 24 + 2) { if (len < 24 + 2) {
wpa_printf(MSG_INFO, "Too short Disassociation frame from " add_note(wt, MSG_INFO, "Too short Disassociation frame from "
MACSTR, MAC2STR(mgmt->sa)); MACSTR, MAC2STR(mgmt->sa));
return; return;
} }
@ -554,7 +557,7 @@ static void rx_mgmt_disassoc(struct wlantest *wt, const u8 *data, size_t len,
if (sta == NULL) { if (sta == NULL) {
if (valid && mgmt->da[0] == 0xff) if (valid && mgmt->da[0] == 0xff)
disassoc_all_stas(bss); disassoc_all_stas(wt, bss);
return; return;
} }
@ -578,24 +581,25 @@ static void rx_mgmt_disassoc(struct wlantest *wt, const u8 *data, size_t len,
WLANTEST_STA_COUNTER_INVALID_DISASSOC_TX]++; WLANTEST_STA_COUNTER_INVALID_DISASSOC_TX]++;
if (!valid) { if (!valid) {
wpa_printf(MSG_INFO, "Do not change STA " MACSTR " State " add_note(wt, MSG_INFO, "Do not change STA " MACSTR " State "
"since Disassociation frame was not protected " "since Disassociation frame was not protected "
"correctly", MAC2STR(sta->addr)); "correctly", MAC2STR(sta->addr));
return; return;
} }
if (sta->state < STATE2) { if (sta->state < STATE2) {
wpa_printf(MSG_DEBUG, "STA " MACSTR " was not in State 2 or 3 " add_note(wt, MSG_DEBUG,
"when getting disassociated", MAC2STR(sta->addr)); "STA " MACSTR " was not in State 2 or 3 "
"when getting disassociated", MAC2STR(sta->addr));
} }
if (sta->state > STATE2) { if (sta->state > STATE2) {
wpa_printf(MSG_DEBUG, "STA " MACSTR add_note(wt, MSG_DEBUG, "STA " MACSTR
" moved to State 2 with " MACSTR, " moved to State 2 with " MACSTR,
MAC2STR(sta->addr), MAC2STR(bss->bssid)); MAC2STR(sta->addr), MAC2STR(bss->bssid));
sta->state = STATE2; sta->state = STATE2;
} }
tdls_link_down(bss, sta); tdls_link_down(wt, bss, sta);
} }
@ -612,10 +616,10 @@ static void rx_mgmt_action_sa_query_req(struct wlantest *wt,
id = sta->ap_sa_query_tr; id = sta->ap_sa_query_tr;
else else
id = sta->sta_sa_query_tr; id = sta->sta_sa_query_tr;
wpa_printf(MSG_INFO, "SA Query Request " MACSTR " -> " MACSTR add_note(wt, MSG_INFO, "SA Query Request " MACSTR " -> " MACSTR
" (trans_id=%02x%02x)%s", " (trans_id=%02x%02x)%s",
MAC2STR(mgmt->sa), MAC2STR(mgmt->da), rx_id[0], rx_id[1], MAC2STR(mgmt->sa), MAC2STR(mgmt->da), rx_id[0], rx_id[1],
valid ? "" : " (invalid protection)"); valid ? "" : " (invalid protection)");
os_memcpy(id, mgmt->u.action.u.sa_query_req.trans_id, 2); os_memcpy(id, mgmt->u.action.u.sa_query_req.trans_id, 2);
if (os_memcmp(mgmt->sa, sta->addr, ETH_ALEN) == 0) if (os_memcmp(mgmt->sa, sta->addr, ETH_ALEN) == 0)
sta->counters[valid ? sta->counters[valid ?
@ -643,11 +647,11 @@ static void rx_mgmt_action_sa_query_resp(struct wlantest *wt,
else else
id = sta->ap_sa_query_tr; id = sta->ap_sa_query_tr;
match = os_memcmp(rx_id, id, 2) == 0; match = os_memcmp(rx_id, id, 2) == 0;
wpa_printf(MSG_INFO, "SA Query Response " MACSTR " -> " MACSTR add_note(wt, MSG_INFO, "SA Query Response " MACSTR " -> " MACSTR
" (trans_id=%02x%02x; %s)%s", " (trans_id=%02x%02x; %s)%s",
MAC2STR(mgmt->sa), MAC2STR(mgmt->da), rx_id[0], rx_id[1], MAC2STR(mgmt->sa), MAC2STR(mgmt->da), rx_id[0], rx_id[1],
match ? "match" : "mismatch", match ? "match" : "mismatch",
valid ? "" : " (invalid protection)"); valid ? "" : " (invalid protection)");
if (os_memcmp(mgmt->sa, sta->addr, ETH_ALEN) == 0) if (os_memcmp(mgmt->sa, sta->addr, ETH_ALEN) == 0)
sta->counters[(valid && match) ? sta->counters[(valid && match) ?
WLANTEST_STA_COUNTER_VALID_SAQUERYRESP_TX : WLANTEST_STA_COUNTER_VALID_SAQUERYRESP_TX :
@ -665,16 +669,16 @@ static void rx_mgmt_action_sa_query(struct wlantest *wt,
size_t len, int valid) size_t len, int valid)
{ {
if (len < 24 + 2 + WLAN_SA_QUERY_TR_ID_LEN) { if (len < 24 + 2 + WLAN_SA_QUERY_TR_ID_LEN) {
wpa_printf(MSG_INFO, "Too short SA Query frame from " MACSTR, add_note(wt, MSG_INFO, "Too short SA Query frame from " MACSTR,
MAC2STR(mgmt->sa)); MAC2STR(mgmt->sa));
return; return;
} }
if (len > 24 + 2 + WLAN_SA_QUERY_TR_ID_LEN) { if (len > 24 + 2 + WLAN_SA_QUERY_TR_ID_LEN) {
size_t elen = len - (24 + 2 + WLAN_SA_QUERY_TR_ID_LEN); size_t elen = len - (24 + 2 + WLAN_SA_QUERY_TR_ID_LEN);
wpa_printf(MSG_INFO, "Unexpected %u octets of extra data at " add_note(wt, MSG_INFO, "Unexpected %u octets of extra data at "
"the end of SA Query frame from " MACSTR, "the end of SA Query frame from " MACSTR,
(unsigned) elen, MAC2STR(mgmt->sa)); (unsigned) elen, MAC2STR(mgmt->sa));
wpa_hexdump(MSG_INFO, "SA Query extra data", wpa_hexdump(MSG_INFO, "SA Query extra data",
((const u8 *) mgmt) + len - elen, elen); ((const u8 *) mgmt) + len - elen, elen);
} }
@ -687,10 +691,10 @@ static void rx_mgmt_action_sa_query(struct wlantest *wt,
rx_mgmt_action_sa_query_resp(wt, sta, mgmt, len, valid); rx_mgmt_action_sa_query_resp(wt, sta, mgmt, len, valid);
break; break;
default: default:
wpa_printf(MSG_INFO, "Unexpected SA Query action value %u " add_note(wt, MSG_INFO, "Unexpected SA Query action value %u "
"from " MACSTR, "from " MACSTR,
mgmt->u.action.u.sa_query_req.action, mgmt->u.action.u.sa_query_req.action,
MAC2STR(mgmt->sa)); MAC2STR(mgmt->sa));
} }
} }
@ -704,11 +708,11 @@ static void rx_mgmt_action(struct wlantest *wt, const u8 *data, size_t len,
mgmt = (const struct ieee80211_mgmt *) data; mgmt = (const struct ieee80211_mgmt *) data;
if (mgmt->da[0] & 0x01) { if (mgmt->da[0] & 0x01) {
wpa_printf(MSG_DEBUG, "Group addressed Action frame: DA=" add_note(wt, MSG_DEBUG, "Group addressed Action frame: DA="
MACSTR " SA=" MACSTR " BSSID=" MACSTR MACSTR " SA=" MACSTR " BSSID=" MACSTR
" category=%u", " category=%u",
MAC2STR(mgmt->da), MAC2STR(mgmt->sa), MAC2STR(mgmt->da), MAC2STR(mgmt->sa),
MAC2STR(mgmt->bssid), mgmt->u.action.category); MAC2STR(mgmt->bssid), mgmt->u.action.category);
return; /* Ignore group addressed Action frames for now */ return; /* Ignore group addressed Action frames for now */
} }
bss = bss_get(wt, mgmt->bssid); bss = bss_get(wt, mgmt->bssid);
@ -722,8 +726,8 @@ static void rx_mgmt_action(struct wlantest *wt, const u8 *data, size_t len,
return; return;
if (len < 24 + 1) { if (len < 24 + 1) {
wpa_printf(MSG_INFO, "Too short Action frame from " add_note(wt, MSG_INFO, "Too short Action frame from " MACSTR,
MACSTR, MAC2STR(mgmt->sa)); MAC2STR(mgmt->sa));
return; return;
} }
@ -735,9 +739,9 @@ static void rx_mgmt_action(struct wlantest *wt, const u8 *data, size_t len,
if (mgmt->u.action.category != WLAN_ACTION_PUBLIC && if (mgmt->u.action.category != WLAN_ACTION_PUBLIC &&
sta->state < STATE3) { sta->state < STATE3) {
wpa_printf(MSG_INFO, "Action frame sent when STA is not in " add_note(wt, MSG_INFO, "Action frame sent when STA is not in "
"State 3 (SA=" MACSTR " DATA=" MACSTR ")", "State 3 (SA=" MACSTR " DATA=" MACSTR ")",
MAC2STR(mgmt->sa), MAC2STR(mgmt->da)); MAC2STR(mgmt->sa), MAC2STR(mgmt->da));
} }
switch (mgmt->u.action.category) { switch (mgmt->u.action.category) {
@ -813,9 +817,9 @@ static int check_bip(struct wlantest *wt, const u8 *data, size_t len)
data[len - 17] != 16) { data[len - 17] != 16) {
/* No MMIE */ /* No MMIE */
if (bss->rsn_capab & WPA_CAPABILITY_MFPC) { if (bss->rsn_capab & WPA_CAPABILITY_MFPC) {
wpa_printf(MSG_INFO, "Robust group-addressed " add_note(wt, MSG_INFO, "Robust group-addressed "
"management frame sent without BIP by " "management frame sent without BIP by "
MACSTR, MAC2STR(mgmt->sa)); MACSTR, MAC2STR(mgmt->sa));
bss->counters[WLANTEST_BSS_COUNTER_MISSING_BIP_MMIE]++; bss->counters[WLANTEST_BSS_COUNTER_MISSING_BIP_MMIE]++;
return -1; return -1;
} }
@ -825,13 +829,13 @@ static int check_bip(struct wlantest *wt, const u8 *data, size_t len)
mmie = data + len - 16; mmie = data + len - 16;
keyid = WPA_GET_LE16(mmie); keyid = WPA_GET_LE16(mmie);
if (keyid & 0xf000) { if (keyid & 0xf000) {
wpa_printf(MSG_INFO, "MMIE KeyID reserved bits not zero " add_note(wt, MSG_INFO, "MMIE KeyID reserved bits not zero "
"(%04x) from " MACSTR, keyid, MAC2STR(mgmt->sa)); "(%04x) from " MACSTR, keyid, MAC2STR(mgmt->sa));
keyid &= 0x0fff; keyid &= 0x0fff;
} }
if (keyid < 4 || keyid > 5) { if (keyid < 4 || keyid > 5) {
wpa_printf(MSG_INFO, "Unexpected MMIE KeyID %u from " MACSTR, add_note(wt, MSG_INFO, "Unexpected MMIE KeyID %u from " MACSTR,
keyid, MAC2STR(mgmt->sa)); keyid, MAC2STR(mgmt->sa));
bss->counters[WLANTEST_BSS_COUNTER_INVALID_BIP_MMIE]++; bss->counters[WLANTEST_BSS_COUNTER_INVALID_BIP_MMIE]++;
return 0; return 0;
} }
@ -840,25 +844,25 @@ static int check_bip(struct wlantest *wt, const u8 *data, size_t len)
wpa_hexdump(MSG_MSGDUMP, "MMIE MIC", mmie + 8, 8); wpa_hexdump(MSG_MSGDUMP, "MMIE MIC", mmie + 8, 8);
if (!bss->igtk_set[keyid]) { if (!bss->igtk_set[keyid]) {
wpa_printf(MSG_DEBUG, "No IGTK known to validate BIP frame"); add_note(wt, MSG_DEBUG, "No IGTK known to validate BIP frame");
return 0; return 0;
} }
if (os_memcmp(mmie + 2, bss->ipn[keyid], 6) <= 0) { if (os_memcmp(mmie + 2, bss->ipn[keyid], 6) <= 0) {
wpa_printf(MSG_INFO, "BIP replay detected: SA=" MACSTR, add_note(wt, MSG_INFO, "BIP replay detected: SA=" MACSTR,
MAC2STR(mgmt->sa)); MAC2STR(mgmt->sa));
wpa_hexdump(MSG_INFO, "RX IPN", mmie + 2, 6); wpa_hexdump(MSG_INFO, "RX IPN", mmie + 2, 6);
wpa_hexdump(MSG_INFO, "Last RX IPN", bss->ipn[keyid], 6); wpa_hexdump(MSG_INFO, "Last RX IPN", bss->ipn[keyid], 6);
} }
if (check_mmie_mic(bss->igtk[keyid], data, len) < 0) { if (check_mmie_mic(bss->igtk[keyid], data, len) < 0) {
wpa_printf(MSG_INFO, "Invalid MMIE MIC in a frame from " add_note(wt, MSG_INFO, "Invalid MMIE MIC in a frame from "
MACSTR, MAC2STR(mgmt->sa)); MACSTR, MAC2STR(mgmt->sa));
bss->counters[WLANTEST_BSS_COUNTER_INVALID_BIP_MMIE]++; bss->counters[WLANTEST_BSS_COUNTER_INVALID_BIP_MMIE]++;
return -1; return -1;
} }
wpa_printf(MSG_DEBUG, "Valid MMIE MIC"); add_note(wt, MSG_DEBUG, "Valid MMIE MIC");
os_memcpy(bss->ipn[keyid], mmie + 2, 6); os_memcpy(bss->ipn[keyid], mmie + 2, 6);
bss->counters[WLANTEST_BSS_COUNTER_VALID_BIP_MMIE]++; bss->counters[WLANTEST_BSS_COUNTER_VALID_BIP_MMIE]++;
@ -890,7 +894,7 @@ static u8 * mgmt_ccmp_decrypt(struct wlantest *wt, const u8 *data, size_t len,
else else
sta = sta_get(bss, hdr->addr1); sta = sta_get(bss, hdr->addr1);
if (sta == NULL || !sta->ptk_set) { if (sta == NULL || !sta->ptk_set) {
wpa_printf(MSG_MSGDUMP, "No PTK known to decrypt the frame"); add_note(wt, MSG_MSGDUMP, "No PTK known to decrypt the frame");
return NULL; return NULL;
} }
@ -898,22 +902,22 @@ static u8 * mgmt_ccmp_decrypt(struct wlantest *wt, const u8 *data, size_t len,
return NULL; return NULL;
if (!(data[24 + 3] & 0x20)) { if (!(data[24 + 3] & 0x20)) {
wpa_printf(MSG_INFO, "Expected CCMP frame from " MACSTR add_note(wt, MSG_INFO, "Expected CCMP frame from " MACSTR
" did not have ExtIV bit set to 1", " did not have ExtIV bit set to 1",
MAC2STR(hdr->addr2)); MAC2STR(hdr->addr2));
return NULL; return NULL;
} }
if (data[24 + 2] != 0 || (data[24 + 3] & 0x1f) != 0) { if (data[24 + 2] != 0 || (data[24 + 3] & 0x1f) != 0) {
wpa_printf(MSG_INFO, "CCMP mgmt frame from " MACSTR " used " add_note(wt, MSG_INFO, "CCMP mgmt frame from " MACSTR " used "
"non-zero reserved bit", MAC2STR(hdr->addr2)); "non-zero reserved bit", MAC2STR(hdr->addr2));
} }
keyid = data[24 + 3] >> 6; keyid = data[24 + 3] >> 6;
if (keyid != 0) { if (keyid != 0) {
wpa_printf(MSG_INFO, "Unexpected non-zero KeyID %d in " add_note(wt, MSG_INFO, "Unexpected non-zero KeyID %d in "
"individually addressed Management frame from " "individually addressed Management frame from "
MACSTR, keyid, MAC2STR(hdr->addr2)); MACSTR, keyid, MAC2STR(hdr->addr2));
} }
if (os_memcmp(hdr->addr1, hdr->addr3, ETH_ALEN) == 0) if (os_memcmp(hdr->addr1, hdr->addr3, ETH_ALEN) == 0)
@ -924,12 +928,12 @@ static u8 * mgmt_ccmp_decrypt(struct wlantest *wt, const u8 *data, size_t len,
ccmp_get_pn(pn, data + 24); ccmp_get_pn(pn, data + 24);
if (os_memcmp(pn, rsc, 6) <= 0) { if (os_memcmp(pn, rsc, 6) <= 0) {
u16 seq_ctrl = le_to_host16(hdr->seq_ctrl); u16 seq_ctrl = le_to_host16(hdr->seq_ctrl);
wpa_printf(MSG_INFO, "CCMP/TKIP replay detected: A1=" MACSTR add_note(wt, MSG_INFO, "CCMP/TKIP replay detected: A1=" MACSTR
" A2=" MACSTR " A3=" MACSTR " seq=%u frag=%u", " A2=" MACSTR " A3=" MACSTR " seq=%u frag=%u",
MAC2STR(hdr->addr1), MAC2STR(hdr->addr2), MAC2STR(hdr->addr1), MAC2STR(hdr->addr2),
MAC2STR(hdr->addr3), MAC2STR(hdr->addr3),
WLAN_GET_SEQ_SEQ(seq_ctrl), WLAN_GET_SEQ_SEQ(seq_ctrl),
WLAN_GET_SEQ_FRAG(seq_ctrl)); WLAN_GET_SEQ_FRAG(seq_ctrl));
wpa_hexdump(MSG_INFO, "RX PN", pn, 6); wpa_hexdump(MSG_INFO, "RX PN", pn, 6);
wpa_hexdump(MSG_INFO, "RSC", rsc, 6); wpa_hexdump(MSG_INFO, "RSC", rsc, 6);
} }
@ -980,9 +984,9 @@ static int check_mgmt_ccmp(struct wlantest *wt, const u8 *data, size_t len)
if ((sta->rsn_capab & WPA_CAPABILITY_MFPC) && if ((sta->rsn_capab & WPA_CAPABILITY_MFPC) &&
(sta->state == STATE3 || (sta->state == STATE3 ||
WLAN_FC_GET_STYPE(fc) == WLAN_FC_STYPE_ACTION)) { WLAN_FC_GET_STYPE(fc) == WLAN_FC_STYPE_ACTION)) {
wpa_printf(MSG_INFO, "Robust individually-addressed " add_note(wt, MSG_INFO, "Robust individually-addressed "
"management frame sent without CCMP by " "management frame sent without CCMP by "
MACSTR, MAC2STR(mgmt->sa)); MACSTR, MAC2STR(mgmt->sa));
return -1; return -1;
} }
@ -1105,8 +1109,8 @@ static void rx_mgmt_deauth_ack(struct wlantest *wt,
if (sta == NULL) if (sta == NULL)
return; return;
wpa_printf(MSG_DEBUG, "DEAUTH from " MACSTR " acknowledged by " MACSTR, add_note(wt, MSG_DEBUG, "DEAUTH from " MACSTR " acknowledged by "
MAC2STR(mgmt->sa), MAC2STR(mgmt->da)); MACSTR, MAC2STR(mgmt->sa), MAC2STR(mgmt->da));
if (os_memcmp(mgmt->sa, mgmt->bssid, ETH_ALEN) == 0) { if (os_memcmp(mgmt->sa, mgmt->bssid, ETH_ALEN) == 0) {
int c; int c;
c = wt->last_mgmt_valid ? c = wt->last_mgmt_valid ?
@ -1135,8 +1139,8 @@ static void rx_mgmt_disassoc_ack(struct wlantest *wt,
if (sta == NULL) if (sta == NULL)
return; return;
wpa_printf(MSG_DEBUG, "DISASSOC from " MACSTR " acknowledged by " add_note(wt, MSG_DEBUG, "DISASSOC from " MACSTR " acknowledged by "
MACSTR, MAC2STR(mgmt->sa), MAC2STR(mgmt->da)); MACSTR, MAC2STR(mgmt->sa), MAC2STR(mgmt->da));
if (os_memcmp(mgmt->sa, mgmt->bssid, ETH_ALEN) == 0) { if (os_memcmp(mgmt->sa, mgmt->bssid, ETH_ALEN) == 0) {
int c; int c;
c = wt->last_mgmt_valid ? c = wt->last_mgmt_valid ?

View file

@ -28,11 +28,11 @@ static struct wlantest_tdls * get_tdls(struct wlantest *wt, const u8 *linkid,
if (bss == NULL && bssid) { if (bss == NULL && bssid) {
bss = bss_find(wt, bssid); bss = bss_find(wt, bssid);
if (bss) if (bss)
wpa_printf(MSG_INFO, "TDLS: Incorrect BSSID " MACSTR add_note(wt, MSG_INFO, "TDLS: Incorrect BSSID " MACSTR
" in LinkId?! (init=" MACSTR " resp=" " in LinkId?! (init=" MACSTR " resp="
MACSTR ")", MACSTR ")",
MAC2STR(linkid), MAC2STR(linkid + ETH_ALEN), MAC2STR(linkid), MAC2STR(linkid + ETH_ALEN),
MAC2STR(linkid + 2 * ETH_ALEN)); MAC2STR(linkid + 2 * ETH_ALEN));
} }
if (bss == NULL) if (bss == NULL)
return NULL; return NULL;
@ -125,8 +125,8 @@ static int tdls_derive_tpk(struct wlantest_tdls *tdls, const u8 *bssid,
} }
static int tdls_verify_mic(struct wlantest_tdls *tdls, u8 trans_seq, static int tdls_verify_mic(struct wlantest *wt, struct wlantest_tdls *tdls,
struct ieee802_11_elems *elems) u8 trans_seq, struct ieee802_11_elems *elems)
{ {
u8 *buf, *pos; u8 *buf, *pos;
int len; int len;
@ -181,10 +181,10 @@ static int tdls_verify_mic(struct wlantest_tdls *tdls, u8 trans_seq,
rx_ftie = (const struct rsn_ftie *) elems->ftie; rx_ftie = (const struct rsn_ftie *) elems->ftie;
if (os_memcmp(mic, rx_ftie->mic, 16) == 0) { if (os_memcmp(mic, rx_ftie->mic, 16) == 0) {
wpa_printf(MSG_DEBUG, "TDLS: Valid MIC"); add_note(wt, MSG_DEBUG, "TDLS: Valid MIC");
return 0; return 0;
} }
wpa_printf(MSG_DEBUG, "TDLS: Invalid MIC"); add_note(wt, MSG_DEBUG, "TDLS: Invalid MIC");
return -1; return -1;
} }
@ -198,8 +198,8 @@ static void rx_data_tdls_setup_request(struct wlantest *wt, const u8 *bssid,
struct wlantest_tdls *tdls; struct wlantest_tdls *tdls;
if (len < 3) { if (len < 3) {
wpa_printf(MSG_INFO, "Too short TDLS Setup Request " MACSTR add_note(wt, MSG_INFO, "Too short TDLS Setup Request " MACSTR
" -> " MACSTR, MAC2STR(src), MAC2STR(dst)); " -> " MACSTR, MAC2STR(src), MAC2STR(dst));
return; return;
} }
wpa_printf(MSG_DEBUG, "TDLS Setup Request " MACSTR " -> " wpa_printf(MSG_DEBUG, "TDLS Setup Request " MACSTR " -> "
@ -230,8 +230,8 @@ static void rx_data_tdls_setup_response_failure(struct wlantest *wt,
struct wlantest_sta *sta; struct wlantest_sta *sta;
if (status == WLAN_STATUS_SUCCESS) { if (status == WLAN_STATUS_SUCCESS) {
wpa_printf(MSG_INFO, "TDLS: Invalid TDLS Setup Response from " add_note(wt, MSG_INFO, "TDLS: Invalid TDLS Setup Response from "
MACSTR, MAC2STR(sta_addr)); MACSTR, MAC2STR(sta_addr));
return; return;
} }
@ -245,13 +245,13 @@ static void rx_data_tdls_setup_response_failure(struct wlantest *wt,
dl_list_for_each(tdls, &bss->tdls, struct wlantest_tdls, list) { dl_list_for_each(tdls, &bss->tdls, struct wlantest_tdls, list) {
if (tdls->resp == sta) { if (tdls->resp == sta) {
if (dialog_token != tdls->dialog_token) { if (dialog_token != tdls->dialog_token) {
wpa_printf(MSG_DEBUG, "TDLS: Dialog token " add_note(wt, MSG_DEBUG, "TDLS: Dialog token "
"mismatch in TDLS Setup Response " "mismatch in TDLS Setup Response "
"(failure)"); "(failure)");
break; break;
} }
wpa_printf(MSG_DEBUG, "TDLS: Found matching TDLS " add_note(wt, MSG_DEBUG, "TDLS: Found matching TDLS "
"setup session based on dialog token"); "setup session based on dialog token");
tdls->counters[ tdls->counters[
WLANTEST_TDLS_COUNTER_SETUP_RESP_FAIL]++; WLANTEST_TDLS_COUNTER_SETUP_RESP_FAIL]++;
break; break;
@ -270,8 +270,8 @@ static void rx_data_tdls_setup_response(struct wlantest *wt, const u8 *bssid,
struct wlantest_tdls *tdls; struct wlantest_tdls *tdls;
if (len < 3) { if (len < 3) {
wpa_printf(MSG_INFO, "Too short TDLS Setup Response " MACSTR add_note(wt, MSG_INFO, "Too short TDLS Setup Response " MACSTR
" -> " MACSTR, MAC2STR(src), MAC2STR(dst)); " -> " MACSTR, MAC2STR(src), MAC2STR(dst));
return; return;
} }
status = WPA_GET_LE16(data); status = WPA_GET_LE16(data);
@ -279,8 +279,8 @@ static void rx_data_tdls_setup_response(struct wlantest *wt, const u8 *bssid,
MACSTR " (status %d)", MACSTR " (status %d)",
MAC2STR(src), MAC2STR(dst), status); MAC2STR(src), MAC2STR(dst), status);
if (len < 5 && status == 0) { if (len < 5 && status == 0) {
wpa_printf(MSG_INFO, "Too short TDLS Setup Response " MACSTR add_note(wt, MSG_INFO, "Too short TDLS Setup Response " MACSTR
" -> " MACSTR, MAC2STR(src), MAC2STR(dst)); " -> " MACSTR, MAC2STR(src), MAC2STR(dst));
return; return;
} }
@ -310,10 +310,10 @@ static void rx_data_tdls_setup_response(struct wlantest *wt, const u8 *bssid,
if (tdls_derive_tpk(tdls, bssid, elems.ftie, elems.ftie_len) < 1) if (tdls_derive_tpk(tdls, bssid, elems.ftie, elems.ftie_len) < 1)
return; return;
if (tdls_verify_mic(tdls, 2, &elems) == 0) { if (tdls_verify_mic(wt, tdls, 2, &elems) == 0) {
tdls->dialog_token = data[2]; tdls->dialog_token = data[2];
wpa_printf(MSG_DEBUG, "TDLS: Dialog Token for the link: %u", add_note(wt, MSG_DEBUG, "TDLS: Dialog Token for the link: %u",
tdls->dialog_token); tdls->dialog_token);
} }
} }
@ -328,8 +328,8 @@ static void rx_data_tdls_setup_confirm_failure(struct wlantest *wt,
struct wlantest_sta *sta; struct wlantest_sta *sta;
if (status == WLAN_STATUS_SUCCESS) { if (status == WLAN_STATUS_SUCCESS) {
wpa_printf(MSG_INFO, "TDLS: Invalid TDLS Setup Confirm from " add_note(wt, MSG_INFO, "TDLS: Invalid TDLS Setup Confirm from "
MACSTR, MAC2STR(src)); MACSTR, MAC2STR(src));
return; return;
} }
@ -343,13 +343,13 @@ static void rx_data_tdls_setup_confirm_failure(struct wlantest *wt,
dl_list_for_each(tdls, &bss->tdls, struct wlantest_tdls, list) { dl_list_for_each(tdls, &bss->tdls, struct wlantest_tdls, list) {
if (tdls->init == sta) { if (tdls->init == sta) {
if (dialog_token != tdls->dialog_token) { if (dialog_token != tdls->dialog_token) {
wpa_printf(MSG_DEBUG, "TDLS: Dialog token " add_note(wt, MSG_DEBUG, "TDLS: Dialog token "
"mismatch in TDLS Setup Confirm " "mismatch in TDLS Setup Confirm "
"(failure)"); "(failure)");
break; break;
} }
wpa_printf(MSG_DEBUG, "TDLS: Found matching TDLS " add_note(wt, MSG_DEBUG, "TDLS: Found matching TDLS "
"setup session based on dialog token"); "setup session based on dialog token");
tdls->counters[ tdls->counters[
WLANTEST_TDLS_COUNTER_SETUP_CONF_FAIL]++; WLANTEST_TDLS_COUNTER_SETUP_CONF_FAIL]++;
break; break;
@ -369,8 +369,8 @@ static void rx_data_tdls_setup_confirm(struct wlantest *wt, const u8 *bssid,
u8 link_id[3 * ETH_ALEN]; u8 link_id[3 * ETH_ALEN];
if (len < 3) { if (len < 3) {
wpa_printf(MSG_INFO, "Too short TDLS Setup Confirm " MACSTR add_note(wt, MSG_INFO, "Too short TDLS Setup Confirm " MACSTR
" -> " MACSTR, MAC2STR(src), MAC2STR(dst)); " -> " MACSTR, MAC2STR(src), MAC2STR(dst));
return; return;
} }
status = WPA_GET_LE16(data); status = WPA_GET_LE16(data);
@ -407,10 +407,10 @@ static void rx_data_tdls_setup_confirm(struct wlantest *wt, const u8 *bssid,
goto remove_reverse; goto remove_reverse;
return; return;
} }
if (tdls_verify_mic(tdls, 3, &elems) == 0) { if (tdls_verify_mic(wt, tdls, 3, &elems) == 0) {
tdls->dialog_token = data[2]; tdls->dialog_token = data[2];
wpa_printf(MSG_DEBUG, "TDLS: Dialog Token for the link: %u", add_note(wt, MSG_DEBUG, "TDLS: Dialog Token for the link: %u",
tdls->dialog_token); tdls->dialog_token);
} }
remove_reverse: remove_reverse:
@ -425,13 +425,14 @@ remove_reverse:
os_memcpy(link_id + 2 * ETH_ALEN, elems.link_id + ETH_ALEN, ETH_ALEN); os_memcpy(link_id + 2 * ETH_ALEN, elems.link_id + ETH_ALEN, ETH_ALEN);
tdls = get_tdls(wt, link_id, 0, bssid); tdls = get_tdls(wt, link_id, 0, bssid);
if (tdls) { if (tdls) {
wpa_printf(MSG_DEBUG, "TDLS: Remove reverse link entry"); add_note(wt, MSG_DEBUG, "TDLS: Remove reverse link entry");
tdls_deinit(tdls); tdls_deinit(tdls);
} }
} }
static int tdls_verify_mic_teardown(struct wlantest_tdls *tdls, u8 trans_seq, static int tdls_verify_mic_teardown(struct wlantest *wt,
struct wlantest_tdls *tdls, u8 trans_seq,
const u8 *reason_code, const u8 *reason_code,
struct ieee802_11_elems *elems) struct ieee802_11_elems *elems)
{ {
@ -479,10 +480,10 @@ static int tdls_verify_mic_teardown(struct wlantest_tdls *tdls, u8 trans_seq,
rx_ftie = (const struct rsn_ftie *) elems->ftie; rx_ftie = (const struct rsn_ftie *) elems->ftie;
if (os_memcmp(mic, rx_ftie->mic, 16) == 0) { if (os_memcmp(mic, rx_ftie->mic, 16) == 0) {
wpa_printf(MSG_DEBUG, "TDLS: Valid MIC"); add_note(wt, MSG_DEBUG, "TDLS: Valid MIC");
return 0; return 0;
} }
wpa_printf(MSG_DEBUG, "TDLS: Invalid MIC"); add_note(wt, MSG_DEBUG, "TDLS: Invalid MIC");
return -1; return -1;
} }
@ -515,7 +516,7 @@ static void rx_data_tdls_teardown(struct wlantest *wt, const u8 *bssid,
if (tdls) { if (tdls) {
tdls->link_up = 0; tdls->link_up = 0;
tdls->counters[WLANTEST_TDLS_COUNTER_TEARDOWN]++; tdls->counters[WLANTEST_TDLS_COUNTER_TEARDOWN]++;
tdls_verify_mic_teardown(tdls, 4, data, &elems); tdls_verify_mic_teardown(wt, tdls, 4, data, &elems);
} }
} }