Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 1 | #!/usr/bin/python |
| 2 | # |
| 3 | # Sigma Control API DUT (sniffer - P2P NoA check) |
| 4 | # Copyright (c) 2014, Qualcomm Atheros, Inc. |
| 5 | # All Rights Reserved. |
| 6 | # Licensed under the Clear BSD license. See README for more details. |
| 7 | |
| 8 | import sys |
| 9 | import subprocess |
| 10 | |
| 11 | infile = sys.argv[1] |
| 12 | bssid = sys.argv[2] |
| 13 | srcmac = sys.argv[3] |
| 14 | destmac = sys.argv[4] |
| 15 | |
| 16 | tshark = subprocess.Popen(['tshark', '-r', infile, |
| 17 | '-c', '1', |
| 18 | '-R', 'wlan.sa==' + bssid + " and wlan.fc.type_subtype==8", |
| 19 | '-Tfields', |
| 20 | '-e', 'radiotap.mactime', |
| 21 | '-e', 'wlan_mgt.fixed.timestamp', |
| 22 | '-e', 'wifi_p2p.noa.duration', |
| 23 | '-e', 'wifi_p2p.noa.interval', |
| 24 | '-e', 'wifi_p2p.noa.start_time', |
| 25 | '-e', 'frame.time_relative'], |
| 26 | stdout=subprocess.PIPE) |
| 27 | noa_data = tshark.stdout.read() |
| 28 | vals = noa_data.rstrip().split('\t') |
| 29 | mactime = int(vals[0]) |
| 30 | timestamp = int(vals[1], 16) |
| 31 | noa_duration = int(vals[2]) |
| 32 | noa_interval = int(vals[3]) |
| 33 | noa_start = int(vals[4]) |
| 34 | frame_time = float(vals[5]) |
| 35 | |
| 36 | if noa_start > timestamp: |
| 37 | print "FilterStatus,FAIL,reasonCode,Unexpected NoA Start Time after Beacon timestamp" |
| 38 | sys.exit() |
| 39 | |
| 40 | noa_start_mactime = mactime - (timestamp - noa_start) |
| 41 | noa_start_frame_time = frame_time - (timestamp - noa_start) / 1000000.0 |
| 42 | |
| 43 | debug = open(infile + ".txt", "w") |
| 44 | debug.write("mactime={}\ntimestamp={}\nnoa_duration={}\nnoa_interval={}\nnoa_start={}\nnoa_start_mactime={}\nnoa_start_frame_time={}\n".format(mactime, timestamp, noa_duration, noa_interval, noa_start, noa_start_mactime, noa_start_frame_time)) |
| 45 | |
| 46 | tshark = subprocess.Popen(['tshark', '-r', infile, |
| 47 | '-R', 'wlan.da==' + destmac + " and wlan.sa==" + srcmac, |
| 48 | '-Tfields', |
| 49 | '-e', 'frame.number', |
| 50 | '-e', 'radiotap.mactime', |
| 51 | '-e', 'frame.time_relative'], |
| 52 | stdout=subprocess.PIPE) |
| 53 | frames = tshark.stdout.read() |
| 54 | error_frame = None |
| 55 | debug.write("\nframenum mactime offset(mactime) offset(frametime)\n") |
| 56 | for f in frames.splitlines(): |
| 57 | vals = f.rstrip().split('\t') |
| 58 | framenum = int(vals[0]) |
| 59 | mactime = int(vals[1]) |
| 60 | frametime = float(vals[2]) |
| 61 | if mactime < noa_start_mactime: |
| 62 | print "FilterStatus,FAIL,reasonCode,Unexpected mactime before NoA Start Time" |
| 63 | sys.exit() |
| 64 | offset = (mactime - noa_start_mactime) % noa_interval |
| 65 | offset_t = ((frametime - noa_start_frame_time) * 1000000) % noa_interval |
| 66 | debug.write("{} {} {} {}\n".format(framenum, mactime, offset, offset_t)) |
| 67 | # allow 200 us as extra buffer to compensate for sniffer inaccuracy |
| 68 | allow_buffer = 200 |
| 69 | if offset > allow_buffer and offset + allow_buffer < noa_duration: |
| 70 | debug.write("Frame {} during GO absence (mactime) (mactime={}, offset={} usec, NoA-duration={} usec)\n".format(framenum, mactime, offset, noa_duration)) |
| 71 | error_frame = framenum |
| 72 | if offset_t > allow_buffer and offset_t + allow_buffer < noa_duration: |
| 73 | debug.write("Frame {} during GO absence (frametime) (frametime={}, offset={} usec, NoA-duration={} usec)\n".format(framenum, frametime, offset_t, noa_duration)) |
| 74 | #error_frame = framenum |
| 75 | |
| 76 | if error_frame: |
| 77 | print "FilterStatus,FAILURE,frameNumber," + str(error_frame) |
| 78 | else: |
| 79 | print "FilterStatus,SUCCESS" |