tests: Long P2P_LISTEN and offchannel TX
[mech_eap.git] / wlantest / rx_ip.c
index aa2b087..19b338b 100644 (file)
@@ -2,14 +2,8 @@
  * Received Data frame processing for IPv4 packets
  * Copyright (c) 2010, Jouni Malinen <j@w1.fi>
  *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License version 2 as
- * published by the Free Software Foundation.
- *
- * Alternatively, this software may be distributed under the terms of BSD
- * license.
- *
- * See README and COPYING for more details.
+ * This software may be distributed under the terms of the BSD license.
+ * See README for more details.
  */
 
 #include "utils/includes.h"
 #include "wlantest.h"
 
 
+static void ping_update(struct wlantest *wt, struct wlantest_sta *sta, int req,
+                       u32 src, u32 dst, u16 id, u16 seq)
+{
+       if (req) {
+               sta->icmp_echo_req_src = src;
+               sta->icmp_echo_req_dst = dst;
+               sta->icmp_echo_req_id = id;
+               sta->icmp_echo_req_seq = seq;
+               return;
+       }
+
+       if (sta->icmp_echo_req_src == dst &&
+           sta->icmp_echo_req_dst == src &&
+           sta->icmp_echo_req_id == id &&
+           sta->icmp_echo_req_seq == seq) {
+               sta->counters[WLANTEST_STA_COUNTER_PING_OK]++;
+               if (sta->counters[WLANTEST_STA_COUNTER_ASSOCREQ_TX] == 0 &&
+                   sta->counters[WLANTEST_STA_COUNTER_REASSOCREQ_TX] == 0)
+                       sta->counters[
+                               WLANTEST_STA_COUNTER_PING_OK_FIRST_ASSOC]++;
+               add_note(wt, MSG_DEBUG, "ICMP echo (ping) match for STA "
+                        MACSTR, MAC2STR(sta->addr));
+       }
+}
+
+
 static void rx_data_icmp(struct wlantest *wt, const u8 *bssid,
                         const u8 *sta_addr, u32 dst, u32 src,
-                        const u8 *data, size_t len)
+                        const u8 *data, size_t len, const u8 *peer_addr)
 {
        struct in_addr addr;
        char buf[20];
@@ -48,14 +68,15 @@ static void rx_data_icmp(struct wlantest *wt, const u8 *bssid,
        addr.s_addr = dst;
        snprintf(buf, sizeof(buf), "%s", inet_ntoa(addr));
        addr.s_addr = src;
-       wpa_printf(MSG_DEBUG, "ICMP echo %s %s -> %s id=%04x seq=%u len=%u",
-                  hdr->type == ICMP_ECHO ? "request" : "response",
-                  inet_ntoa(addr), buf, id, seq, (unsigned) len - 8);
+       add_note(wt, MSG_DEBUG, "ICMP echo %s %s -> %s id=%04x seq=%u len=%u%s",
+                hdr->type == ICMP_ECHO ? "request" : "response",
+                inet_ntoa(addr), buf, id, seq, (unsigned) len - 8,
+                peer_addr ? " [DL]" : "");
 
        bss = bss_find(wt, bssid);
        if (bss == NULL) {
-               wpa_printf(MSG_INFO, "No BSS " MACSTR " known for ICMP packet",
-                          MAC2STR(bssid));
+               add_note(wt, MSG_INFO, "No BSS " MACSTR
+                        " known for ICMP packet", MAC2STR(bssid));
                return;
        }
 
@@ -64,36 +85,36 @@ static void rx_data_icmp(struct wlantest *wt, const u8 *bssid,
 
        sta = sta_find(bss, sta_addr);
        if (sta == NULL) {
-               wpa_printf(MSG_INFO, "No STA " MACSTR " known for ICMP packet",
-                          MAC2STR(sta_addr));
+               add_note(wt, MSG_INFO, "No STA " MACSTR
+                        " known for ICMP packet", MAC2STR(sta_addr));
                return;
        }
 
-       if (hdr->type == ICMP_ECHO) {
-               sta->icmp_echo_req_src = src;
-               sta->icmp_echo_req_dst = dst;
-               sta->icmp_echo_req_id = id;
-               sta->icmp_echo_req_seq = seq;
-               return;
-       }
+       ping_update(wt, sta, hdr->type == ICMP_ECHO, src, dst, id, seq);
+       if (peer_addr && (sta = sta_find(bss, peer_addr)))
+               ping_update(wt, sta, hdr->type == ICMP_ECHO, src, dst, id, seq);
+}
 
-       if (sta->icmp_echo_req_src == dst &&
-           sta->icmp_echo_req_dst == src &&
-           sta->icmp_echo_req_id == id &&
-           sta->icmp_echo_req_seq == seq) {
-               sta->counters[WLANTEST_STA_COUNTER_PING_OK]++;
-               if (sta->counters[WLANTEST_STA_COUNTER_ASSOCREQ_TX] == 0 &&
-                   sta->counters[WLANTEST_STA_COUNTER_REASSOCREQ_TX] == 0)
-                       sta->counters[
-                               WLANTEST_STA_COUNTER_PING_OK_FIRST_ASSOC]++;
-               wpa_printf(MSG_DEBUG, "ICMP echo (ping) match for STA " MACSTR,
-                          MAC2STR(sta->addr));
+
+static int hwsim_test_packet(const u8 *data, size_t len)
+{
+       size_t i;
+
+       if (len != 1500 - 14)
+               return 0;
+
+       for (i = 0; i < len; i++) {
+               if (data[i] != (i & 0xff))
+                       return 0;
        }
+
+       return 1;
 }
 
 
 void rx_data_ip(struct wlantest *wt, const u8 *bssid, const u8 *sta_addr,
-               const u8 *dst, const u8 *src, const u8 *data, size_t len)
+               const u8 *dst, const u8 *src, const u8 *data, size_t len,
+               const u8 *peer_addr)
 {
        const struct iphdr *ip;
        const u8 *payload;
@@ -104,24 +125,28 @@ void rx_data_ip(struct wlantest *wt, const u8 *bssid, const u8 *sta_addr,
        if (len < sizeof(*ip))
                return;
        if (ip->version != 4) {
-               wpa_printf(MSG_DEBUG, "Unexpected IP protocol version %u in "
-                          "IPv4 packet (bssid=" MACSTR " str=" MACSTR
-                          " dst=" MACSTR ")", ip->version, MAC2STR(bssid),
-                          MAC2STR(src), MAC2STR(dst));
+               if (hwsim_test_packet(data, len)) {
+                       add_note(wt, MSG_INFO, "hwsim_test package");
+                       return;
+               }
+               add_note(wt, MSG_DEBUG, "Unexpected IP protocol version %u in "
+                        "IPv4 packet (bssid=" MACSTR " str=" MACSTR
+                        " dst=" MACSTR ")", ip->version, MAC2STR(bssid),
+                        MAC2STR(src), MAC2STR(dst));
                return;
        }
        if (ip->ihl * 4 < sizeof(*ip)) {
-               wpa_printf(MSG_DEBUG, "Unexpected IP header length %u in "
-                          "IPv4 packet (bssid=" MACSTR " str=" MACSTR
-                          " dst=" MACSTR ")", ip->ihl, MAC2STR(bssid),
-                          MAC2STR(src), MAC2STR(dst));
+               add_note(wt, MSG_DEBUG, "Unexpected IP header length %u in "
+                        "IPv4 packet (bssid=" MACSTR " str=" MACSTR
+                        " dst=" MACSTR ")", ip->ihl, MAC2STR(bssid),
+                        MAC2STR(src), MAC2STR(dst));
                return;
        }
        if (ip->ihl * 4 > len) {
-               wpa_printf(MSG_DEBUG, "Truncated IP header (ihl=%u len=%u) in "
-                          "IPv4 packet (bssid=" MACSTR " str=" MACSTR
-                          " dst=" MACSTR ")", ip->ihl, (unsigned) len,
-                          MAC2STR(bssid), MAC2STR(src), MAC2STR(dst));
+               add_note(wt, MSG_DEBUG, "Truncated IP header (ihl=%u len=%u) "
+                        "in IPv4 packet (bssid=" MACSTR " str=" MACSTR
+                        " dst=" MACSTR ")", ip->ihl, (unsigned) len,
+                        MAC2STR(bssid), MAC2STR(src), MAC2STR(dst));
                return;
        }
 
@@ -146,7 +171,7 @@ void rx_data_ip(struct wlantest *wt, const u8 *bssid, const u8 *sta_addr,
        switch (ip->protocol) {
        case IPPROTO_ICMP:
                rx_data_icmp(wt, bssid, sta_addr, ip->daddr, ip->saddr,
-                            payload, plen);
+                            payload, plen, peer_addr);
                break;
        }
 }