From 0321bcdfa8466ae97da77cbc1998b31b53b1ee59 Mon Sep 17 00:00:00 2001 From: Jouni Malinen Date: Thu, 17 Jan 2013 16:22:41 +0200 Subject: [PATCH] wlantest: Add radiotap header when re-writing DLT_IEEE802_11 file When using DLT_IEEE802_11 datalink type in a pcap file, wlantest will now add a radiotap header to the re-written pcap file to make sure all frames in the output file will include the radiotap header. Signed-hostap: Jouni Malinen --- wlantest/readpcap.c | 38 +++++++++++++++++++++++++++++++++++++- 1 file changed, 37 insertions(+), 1 deletion(-) diff --git a/wlantest/readpcap.c b/wlantest/readpcap.c index 3ab40804e..6243bc847 100644 --- a/wlantest/readpcap.c +++ b/wlantest/readpcap.c @@ -13,6 +13,39 @@ #include "wlantest.h" +static void write_pcap_with_radiotap(struct wlantest *wt, + const u8 *data, size_t data_len) +{ + struct pcap_pkthdr h; + u8 rtap[] = { + 0x00 /* rev */, + 0x00 /* pad */, + 0x0a, 0x00, /* header len */ + 0x02, 0x00, 0x00, 0x00, /* present flags */ + 0x00, /* flags */ + 0x00 /* pad */ + }; + u8 *buf; + size_t len; + + if (wt->assume_fcs) + rtap[8] |= 0x10; + + os_memset(&h, 0, sizeof(h)); + h.ts = wt->write_pcap_time; + len = sizeof(rtap) + data_len; + buf = os_malloc(len); + if (buf == NULL) + return; + os_memcpy(buf, rtap, sizeof(rtap)); + os_memcpy(buf + sizeof(rtap), data, data_len); + h.caplen = len; + h.len = len; + pcap_dump(wt->write_pcap_dumper, &h, buf); + os_free(buf); +} + + int read_cap_file(struct wlantest *wt, const char *fname) { char errbuf[PCAP_ERRBUF_SIZE]; @@ -61,7 +94,10 @@ int read_cap_file(struct wlantest *wt, const char *fname) hdr->caplen, hdr->len); if (wt->write_pcap_dumper) { wt->write_pcap_time = hdr->ts; - pcap_dump(wt->write_pcap_dumper, hdr, data); + if (dlt == DLT_IEEE802_11) + write_pcap_with_radiotap(wt, data, hdr->caplen); + else + pcap_dump(wt->write_pcap_dumper, hdr, data); } if (hdr->caplen < hdr->len) { wpa_printf(MSG_DEBUG, "pcap: Dropped incomplete frame " -- 2.39.2