From 27b698338fe137d91fe858dfc56724ebf686aff8 Mon Sep 17 00:00:00 2001 From: Jouni Malinen Date: Sat, 3 Dec 2016 18:53:36 +0200 Subject: [PATCH] tests: Scanning and AP changing channels Signed-off-by: Jouni Malinen --- tests/hwsim/test_scan.py | 53 +++++++++++++++++++++++++++++++++++++++- 1 file changed, 52 insertions(+), 1 deletion(-) diff --git a/tests/hwsim/test_scan.py b/tests/hwsim/test_scan.py index 56f10f832..9a370daa1 100644 --- a/tests/hwsim/test_scan.py +++ b/tests/hwsim/test_scan.py @@ -1,5 +1,5 @@ # Scanning tests -# Copyright (c) 2013-2015, Jouni Malinen +# Copyright (c) 2013-2016, Jouni Malinen # # This software may be distributed under the terms of the BSD license. # See README for more details. @@ -15,6 +15,7 @@ import hostapd from wpasupplicant import WpaSupplicant from utils import HwsimSkip, fail_test, alloc_fail, wait_fail_trigger from tshark import run_tshark +from test_ap_csa import switch_channel, wait_channel_switch, csa_supported def check_scan(dev, params, other_started=False, test_busy=False): if not other_started: @@ -1177,3 +1178,53 @@ def _test_scan_bss_limit(dev, apdev): hapd2 = hostapd.add_ap(apdev[1], { "ssid": "test-scan-2", "channel": "6" }) dev[0].scan_for_bss(apdev[1]['bssid'], freq=2437, force_scan=True) + +def run_scan(dev, bssid, exp_freq): + for i in range(5): + dev.request("SCAN freq=2412,2437,2462") + ev = dev.wait_event(["CTRL-EVENT-SCAN-RESULTS"]) + if ev is None: + raise Exception("Scan did not complete") + bss = dev.get_bss(bssid) + freq = int(bss['freq']) if bss else 0 + if freq == exp_freq: + break + if freq != exp_freq: + raise Exception("BSS entry shows incorrect frequency: %d != %d" % (freq, exp_freq)) + +def test_scan_chan_switch(dev, apdev): + """Scanning and AP changing channels""" + + # This test verifies that wpa_supplicant updates its local BSS table based + # on the correct cfg80211 scan entry in cases where the cfg80211 BSS table + # has multiple (one for each frequency) BSS entries for the same BSS. + + csa_supported(dev[0]) + hapd = hostapd.add_ap(apdev[0], { "ssid": "test-scan", "channel": "1" }) + csa_supported(hapd) + bssid = hapd.own_addr() + + logger.info("AP channel switch while not connected") + run_scan(dev[0], bssid, 2412) + dev[0].dump_monitor() + switch_channel(hapd, 1, 2437) + run_scan(dev[0], bssid, 2437) + dev[0].dump_monitor() + switch_channel(hapd, 1, 2462) + run_scan(dev[0], bssid, 2462) + dev[0].dump_monitor() + + logger.info("AP channel switch while connected") + dev[0].connect("test-scan", key_mgmt="NONE", scan_freq="2412 2437 2462") + run_scan(dev[0], bssid, 2462) + dev[0].dump_monitor() + switch_channel(hapd, 2, 2437) + wait_channel_switch(dev[0], 2437) + dev[0].dump_monitor() + run_scan(dev[0], bssid, 2437) + dev[0].dump_monitor() + switch_channel(hapd, 2, 2412) + wait_channel_switch(dev[0], 2412) + dev[0].dump_monitor() + run_scan(dev[0], bssid, 2412) + dev[0].dump_monitor()