]> git.ipfire.org Git - thirdparty/hostap.git/commitdiff
tests: Make ap_track_sta_no_probe_resp more robust
authorJouni Malinen <jouni@qca.qualcomm.com>
Tue, 13 Dec 2016 13:47:50 +0000 (15:47 +0200)
committerJouni Malinen <j@w1.fi>
Tue, 13 Dec 2016 18:07:52 +0000 (20:07 +0200)
Check whether the unexpected BSS entry is based on having received a
Beacon frame instead of Probe Response frame. While this test case is
using a huge beacon_int value, it is still possible for mac80211_hwsim
timing to work in a way that a Beacon frame is sent. That made this test
case fail in some rare cases. Fix this by ignoring the BSS entry if it
is based on Beacon frame instead of Probe Response frame.

Signed-off-by: Jouni Malinen <jouni@qca.qualcomm.com>
tests/hwsim/test_ap_track.py
tests/hwsim/utils.py

index 75664a4ce6dc4410cddd4e486d2c750667ab076b..69c96d8249b9764298525ae303bc69f552aae29e 100644 (file)
@@ -11,6 +11,7 @@ import time
 
 import hostapd
 from wpasupplicant import WpaSupplicant
+from utils import parse_ie
 
 def test_ap_track_sta(dev, apdev):
     """Dualband AP tracking unconnected stations"""
@@ -110,8 +111,15 @@ def _test_ap_track_sta_no_probe_resp(dev, apdev):
     dev[0].scan(freq=2437, type="ONLY")
     dev[0].scan(freq=2437, type="ONLY")
 
-    if dev[0].get_bss(bssid):
-        raise Exception("2.4 GHz AP found unexpectedly")
+    bss = dev[0].get_bss(bssid)
+    if bss:
+        ie = parse_ie(bss['ie'])
+        # Check whether this is from a Beacon frame (TIM element included) since
+        # it is possible that a Beacon frame was received during the active
+        # scan. This test should fail only if a Probe Response frame was
+        # received.
+        if 5 not in ie:
+            raise Exception("2.4 GHz AP found unexpectedly")
 
 def test_ap_track_sta_no_auth(dev, apdev):
     """Dualband AP rejecting authentication from dualband STA on 2.4 GHz"""
index 479923cea7c9fcaa062db20041f615b2c734f1e5..69d3cff394b78b5b3987c80770665537350b9814 100644 (file)
@@ -4,7 +4,9 @@
 # This software may be distributed under the terms of the BSD license.
 # See README for more details.
 
+import binascii
 import os
+import struct
 import time
 import remotehost
 
@@ -102,3 +104,15 @@ def get_phy(ap, ifname=None):
             phy = "phy" + words[1]
             break
     return phy
+
+def parse_ie(buf):
+    ret = {}
+    data = binascii.unhexlify(buf)
+    while len(data) >= 2:
+        ie,elen = struct.unpack('BB', data[0:2])
+        data = data[2:]
+        if elen > len(data):
+            break
+        ret[ie] = data[0:elen]
+        data = data[elen:]
+    return ret