3 # Copyright (c) 2012, Intel Corporation
5 # Author: Johannes Berg <johannes@sipsolutions.net>
7 # This software may be distributed under the terms of the BSD license.
8 # See README for more details.
10 import sys, struct, re
12 def write_pcap_header(pcap_file):
14 struct.pack('<IHHIIII',
15 0xa1b2c3d4, 2, 4, 0, 0, 65535,
16 105 # raw 802.11 format
19 def pcap_addpacket(pcap_file, ts, data):
20 # ts in seconds, float
21 pcap_file.write(struct.pack('<IIII',
22 int(ts), int(1000000 * ts) % 1000000,
23 len(data), len(data)))
26 if __name__ == "__main__":
31 print "Usage: %s <log file> <pcap file>" % sys.argv[0]
34 input_file = open(input, 'r')
35 pcap_file = open(pcap, 'w')
36 frame_re = re.compile(r'(([0-9]+.[0-9]{6}):\s*)?nl80211: MLME event frame - hexdump\(len=[0-9]*\):((\s*[0-9a-fA-F]{2})*)')
38 write_pcap_header(pcap_file)
40 for line in input_file:
41 m = frame_re.match(line)
45 ts = float(m.group(2))
49 hexdata = hexdata.split()
50 data = ''.join([chr(int(x, 16)) for x in hexdata])
51 pcap_addpacket(pcap_file, ts, data)