blob: a6b14cb4cc371bf8c4ab7f4fc242b289c33dcfba [file] [log] [blame]
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001#!/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
8import sys
9import subprocess
10
11infile = sys.argv[1]
12bssid = sys.argv[2]
13srcmac = sys.argv[3]
14destmac = sys.argv[4]
15
16tshark = 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)
27noa_data = tshark.stdout.read()
28vals = noa_data.rstrip().split('\t')
29mactime = int(vals[0])
30timestamp = int(vals[1], 16)
31noa_duration = int(vals[2])
32noa_interval = int(vals[3])
33noa_start = int(vals[4])
34frame_time = float(vals[5])
35
36if noa_start > timestamp:
37 print "FilterStatus,FAIL,reasonCode,Unexpected NoA Start Time after Beacon timestamp"
38 sys.exit()
39
40noa_start_mactime = mactime - (timestamp - noa_start)
41noa_start_frame_time = frame_time - (timestamp - noa_start) / 1000000.0
42
43debug = open(infile + ".txt", "w")
44debug.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
46tshark = 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)
53frames = tshark.stdout.read()
54error_frame = None
55debug.write("\nframenum mactime offset(mactime) offset(frametime)\n")
56for 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
76if error_frame:
77 print "FilterStatus,FAILURE,frameNumber," + str(error_frame)
78else:
79 print "FilterStatus,SUCCESS"