Patchwork wlantest: always write radiotap pcap-ng

login
register
mail settings
Submitter Johannes Berg
Date May 31, 2013, 11:57 a.m.
Message ID <1370001467-14081-1-git-send-email-johannes@sipsolutions.net>
Download mbox | patch
Permalink /patch/247938/
State Accepted
Commit de36e348f90c5d67af3650ef3a5296ed04cb6200
Headers show

Comments

Johannes Berg - May 31, 2013, 11:57 a.m.
From: Johannes Berg <johannes.berg@intel.com>

When writing pcap-ng files, always include a radiotap
header even if there wasn't one in the input. For now
just drop prism headers, I don't have any to test.

Signed-hostap: Johannes Berg <johannes.berg@intel.com>
---
 wlantest/writepcap.c | 40 ++++++++++++++++++++++++++++++++++++----
 1 file changed, 36 insertions(+), 4 deletions(-)
Jouni Malinen - June 22, 2013, 10:19 a.m.
On Fri, May 31, 2013 at 01:57:47PM +0200, Johannes Berg wrote:
> When writing pcap-ng files, always include a radiotap
> header even if there wasn't one in the input. For now
> just drop prism headers, I don't have any to test.

Thanks, applied.

Patch

diff --git a/wlantest/writepcap.c b/wlantest/writepcap.c
index 44a251d..58f01a0 100644
--- a/wlantest/writepcap.c
+++ b/wlantest/writepcap.c
@@ -272,12 +272,23 @@  void write_pcapng_write_read(struct wlantest *wt, int dlt,
 	u8 *pos;
 	u32 *block_len;
 	u64 timestamp;
-	size_t len;
+	size_t len, datalen = hdr->caplen;
+	u8 rtap[] = {
+		0x00 /* rev */,
+		0x00 /* pad */,
+		0x0a, 0x00, /* header len */
+		0x02, 0x00, 0x00, 0x00, /* present flags */
+		0x00, /* flags */
+		0x00 /* pad */
+	};
+
+	if (wt->assume_fcs)
+		rtap[8] |= 0x10;
 
 	if (!wt->pcapng)
 		return;
 
-	len = sizeof(*pkt) + hdr->len + 100 + notes_len(wt, 32);
+	len = sizeof(*pkt) + hdr->len + 100 + notes_len(wt, 32) + sizeof(rtap);
 	pkt = os_zalloc(len);
 	if (pkt == NULL)
 		return;
@@ -293,8 +304,29 @@  void write_pcapng_write_read(struct wlantest *wt, int dlt,
 	pkt->packet_len = hdr->len;
 
 	pos = (u8 *) (pkt + 1);
-	os_memcpy(pos, data, hdr->caplen);
-	pos += ALIGN32(hdr->caplen);
+
+	switch (dlt) {
+	case DLT_IEEE802_11_RADIO:
+		break;
+	case DLT_PRISM_HEADER:
+		/* remove prism header (could be kept ... lazy) */
+		pkt->captured_len -= WPA_GET_LE32(data + 4);
+		pkt->packet_len -= WPA_GET_LE32(data + 4);
+		datalen -= WPA_GET_LE32(data + 4);
+		data += WPA_GET_LE32(data + 4);
+		/* fall through */
+	case DLT_IEEE802_11:
+		pkt->captured_len += sizeof(rtap);
+		pkt->packet_len += sizeof(rtap);
+		os_memcpy(pos, &rtap, sizeof(rtap));
+		pos += sizeof(rtap);
+		break;
+	default:
+		return;
+	}
+
+	os_memcpy(pos, data, datalen);
+	pos += datalen + PAD32(pkt->captured_len);
 	pos = pcapng_add_comments(wt, pos);
 
 	block_len = (u32 *) pos;