]> git.ipfire.org Git - thirdparty/hostap.git/commitdiff
wlantest: Add support for reading pcap files with prism header
authorJouni Malinen <jouni.malinen@atheros.com>
Thu, 2 Dec 2010 20:56:37 +0000 (12:56 -0800)
committerJouni Malinen <j@w1.fi>
Thu, 2 Dec 2010 20:56:37 +0000 (12:56 -0800)
wlantest/process.c
wlantest/readpcap.c
wlantest/wlantest.h

index 7ca77b20d2b8103aa8cf2ae3654b1fb7c3027832..78908927ef476f9abbe20b3c61c7e58020c3e47e 100644 (file)
@@ -224,3 +224,41 @@ void wlantest_process(struct wlantest *wt, const u8 *data, size_t len)
        else
                tx_status(wt, frame, frame_len, !failed);
 }
+
+
+void wlantest_process_prism(struct wlantest *wt, const u8 *data, size_t len)
+{
+       int fcs = 0;
+       const u8 *frame, *fcspos;
+       size_t frame_len;
+       u32 hdrlen;
+
+       wpa_hexdump(MSG_EXCESSIVE, "Process data", data, len);
+
+       if (len < 8)
+               return;
+       hdrlen = WPA_GET_LE32(data + 4);
+
+       if (len < hdrlen) {
+               wpa_printf(MSG_INFO, "Too short frame to include prism "
+                          "header");
+               return;
+       }
+
+       frame = data + hdrlen;
+       frame_len = len - hdrlen;
+       fcs = 1;
+
+       if (fcs && frame_len >= 4) {
+               frame_len -= 4;
+               fcspos = frame + frame_len;
+               if (check_fcs(frame, frame_len, fcspos) < 0) {
+                       wpa_printf(MSG_EXCESSIVE, "Drop RX frame with invalid "
+                                  "FCS");
+                       wt->fcs_error++;
+                       return;
+               }
+       }
+
+       rx_frame(wt, frame, frame_len);
+}
index bd93d7b5ceb3515e76679e13b2a4a1e889be8d4e..ecb5ae22a86d266a31bbb50863743402c9383be9 100644 (file)
@@ -27,6 +27,7 @@ int read_cap_file(struct wlantest *wt, const char *fname)
        struct pcap_pkthdr *hdr;
        const u_char *data;
        int res;
+       int dlt;
 
        pcap = pcap_open_offline(fname, errbuf);
        if (pcap == NULL) {
@@ -34,6 +35,14 @@ int read_cap_file(struct wlantest *wt, const char *fname)
                           fname, errbuf);
                return -1;
        }
+       dlt = pcap_datalink(pcap);
+       if (dlt != DLT_IEEE802_11_RADIO && dlt != DLT_PRISM_HEADER) {
+               wpa_printf(MSG_ERROR, "Unsupported pcap datalink type: %d",
+                          dlt);
+               pcap_close(pcap);
+               return -1;
+       }
+       wpa_printf(MSG_DEBUG, "pcap datalink type: %d", dlt);
 
        for (;;) {
                res = pcap_next_ex(pcap, &hdr, &data);
@@ -66,7 +75,14 @@ int read_cap_file(struct wlantest *wt, const char *fname)
                        continue;
                }
                count++;
-               wlantest_process(wt, data, hdr->caplen);
+               switch (dlt) {
+               case DLT_IEEE802_11_RADIO:
+                       wlantest_process(wt, data, hdr->caplen);
+                       break;
+               case DLT_PRISM_HEADER:
+                       wlantest_process_prism(wt, data, hdr->caplen);
+                       break;
+               }
        }
 
        pcap_close(pcap);
index 6bb8e1edb231939aa3944fc8d12fab0c4946fc05..81f4731489a19822055826662b44509eac10be60 100644 (file)
@@ -154,6 +154,7 @@ void write_pcap_captured(struct wlantest *wt, const u8 *buf, size_t len);
 void write_pcap_decrypted(struct wlantest *wt, const u8 *buf1, size_t len1,
                          const u8 *buf2, size_t len2);
 void wlantest_process(struct wlantest *wt, const u8 *data, size_t len);
+void wlantest_process_prism(struct wlantest *wt, const u8 *data, size_t len);
 void wlantest_process_wired(struct wlantest *wt, const u8 *data, size_t len);
 u32 crc32(const u8 *frame, size_t frame_len);
 int monitor_init(struct wlantest *wt, const char *ifname);