2 * PCAP capture file writer
3 * Copyright (c) 2010, Jouni Malinen <j@w1.fi>
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License version 2 as
7 * published by the Free Software Foundation.
9 * Alternatively, this software may be distributed under the terms of BSD
12 * See README and COPYING for more details.
15 #include "utils/includes.h"
19 #include "utils/common.h"
23 int write_pcap_init(struct wlantest *wt, const char *fname)
25 wt->write_pcap = pcap_open_dead(DLT_IEEE802_11_RADIO, 4000);
26 if (wt->write_pcap == NULL)
28 wt->write_pcap_dumper = pcap_dump_open(wt->write_pcap, fname);
29 if (wt->write_pcap_dumper == NULL) {
30 pcap_close(wt->write_pcap);
31 wt->write_pcap = NULL;
35 wpa_printf(MSG_DEBUG, "Writing PCAP dump to '%s'", fname);
41 void write_pcap_deinit(struct wlantest *wt)
43 if (wt->write_pcap_dumper) {
44 pcap_dump_close(wt->write_pcap_dumper);
45 wt->write_pcap_dumper = NULL;
48 pcap_close(wt->write_pcap);
49 wt->write_pcap = NULL;
54 void write_pcap_captured(struct wlantest *wt, const u8 *buf, size_t len)
58 if (!wt->write_pcap_dumper)
61 os_memset(&h, 0, sizeof(h));
62 gettimeofday(&wt->write_pcap_time, NULL);
63 h.ts = wt->write_pcap_time;
66 pcap_dump(wt->write_pcap_dumper, &h, buf);
70 void write_pcap_decrypted(struct wlantest *wt, const u8 *buf1, size_t len1,
71 const u8 *buf2, size_t len2)
77 0x08, 0x00, /* header len */
78 0x00, 0x00, 0x00, 0x00 /* present flags */
83 if (!wt->write_pcap_dumper)
86 os_memset(&h, 0, sizeof(h));
87 h.ts = wt->write_pcap_time;
88 len = sizeof(rtap) + len1 + len2;
92 os_memcpy(buf, rtap, sizeof(rtap));
94 os_memcpy(buf + sizeof(rtap), buf1, len1);
95 buf[sizeof(rtap) + 1] &= ~0x40; /* Clear Protected flag */
98 os_memcpy(buf + sizeof(rtap) + len1, buf2, len2);
101 pcap_dump(wt->write_pcap_dumper, &h, buf);