From a00a3458ed0917a8bf3fae259cc962ed727be8cf Mon Sep 17 00:00:00 2001 From: Jouni Malinen Date: Tue, 13 Dec 2016 15:47:50 +0200 Subject: [PATCH] tests: Make ap_track_sta_no_probe_resp more robust 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 --- tests/hwsim/test_ap_track.py | 12 ++++++++++-- tests/hwsim/utils.py | 14 ++++++++++++++ 2 files changed, 24 insertions(+), 2 deletions(-) diff --git a/tests/hwsim/test_ap_track.py b/tests/hwsim/test_ap_track.py index 75664a4ce..69c96d824 100644 --- a/tests/hwsim/test_ap_track.py +++ b/tests/hwsim/test_ap_track.py @@ -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""" diff --git a/tests/hwsim/utils.py b/tests/hwsim/utils.py index 479923cea..69d3cff39 100644 --- a/tests/hwsim/utils.py +++ b/tests/hwsim/utils.py @@ -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