diff --git a/tests/hwsim/test_bgscan.py b/tests/hwsim/test_bgscan.py new file mode 100644 index 000000000..1ae4a2a79 --- /dev/null +++ b/tests/hwsim/test_bgscan.py @@ -0,0 +1,115 @@ +# bgscan tests +# Copyright (c) 2014, Jouni Malinen +# +# This software may be distributed under the terms of the BSD license. +# See README for more details. + +import time +import logging +logger = logging.getLogger() +import os + +import hostapd + +def test_bgscan_simple(dev, apdev): + """bgscan_simple""" + hostapd.add_ap(apdev[0]['ifname'], { "ssid": "bgscan" }) + hostapd.add_ap(apdev[1]['ifname'], { "ssid": "bgscan" }) + + dev[0].connect("bgscan", key_mgmt="NONE", scan_freq="2412", + bgscan="simple:1:-20:2") + dev[1].connect("bgscan", key_mgmt="NONE", scan_freq="2412", + bgscan="simple:1:-45:2") + + ev = dev[0].wait_event(["CTRL-EVENT-SIGNAL-CHANGE"], timeout=10) + if ev is None: + raise Exception("dev0 did not indicate signal change event") + if "above=0" not in ev: + raise Exception("Unexpected signal change event contents from dev0: " + ev) + + ev = dev[1].wait_event(["CTRL-EVENT-SIGNAL-CHANGE"], timeout=10) + if ev is None: + raise Exception("dev1 did not indicate signal change event") + if "above=1" not in ev: + raise Exception("Unexpected signal change event contents from dev1: " + ev) + + ev = dev[0].wait_event(["CTRL-EVENT-SCAN-STARTED"], timeout=3) + if ev is None: + raise Exception("dev0 did not start a scan") + + ev = dev[1].wait_event(["CTRL-EVENT-SCAN-STARTED"], timeout=3) + if ev is None: + raise Exception("dev1 did not start a scan") + + ev = dev[0].wait_event(["CTRL-EVENT-SCAN-RESULTS"], 5) + if ev is None: + raise Exception("dev0 did not complete a scan") + ev = dev[1].wait_event(["CTRL-EVENT-SCAN-RESULTS"], 5) + if ev is None: + raise Exception("dev1 did not complete a scan") + +def test_bgscan_learn(dev, apdev): + """bgscan_learn""" + hostapd.add_ap(apdev[0]['ifname'], { "ssid": "bgscan" }) + hostapd.add_ap(apdev[1]['ifname'], { "ssid": "bgscan" }) + + try: + os.remove("/tmp/test_bgscan_learn.bgscan") + except: + pass + + try: + dev[0].connect("bgscan", key_mgmt="NONE", scan_freq="2412", + bgscan="learn:1:-20:2") + dev[1].connect("bgscan", key_mgmt="NONE", scan_freq="2412", + bgscan="learn:1:-45:2:/tmp/test_bgscan_learn.bgscan") + + ev = dev[0].wait_event(["CTRL-EVENT-SIGNAL-CHANGE"], timeout=10) + if ev is None: + raise Exception("dev0 did not indicate signal change event") + if "above=0" not in ev: + raise Exception("Unexpected signal change event contents from dev0: " + ev) + + ev = dev[1].wait_event(["CTRL-EVENT-SIGNAL-CHANGE"], timeout=10) + if ev is None: + raise Exception("dev1 did not indicate signal change event") + if "above=1" not in ev: + raise Exception("Unexpected signal change event contents from dev1: " + ev) + + ev = dev[0].wait_event(["CTRL-EVENT-SCAN-STARTED"], timeout=3) + if ev is None: + raise Exception("dev0 did not start a scan") + + ev = dev[1].wait_event(["CTRL-EVENT-SCAN-STARTED"], timeout=3) + if ev is None: + raise Exception("dev1 did not start a scan") + + ev = dev[0].wait_event(["CTRL-EVENT-SCAN-RESULTS"], 5) + if ev is None: + raise Exception("dev0 did not complete a scan") + ev = dev[1].wait_event(["CTRL-EVENT-SCAN-RESULTS"], 5) + if ev is None: + raise Exception("dev1 did not complete a scan") + + dev[0].request("DISCONNECT") + dev[1].request("DISCONNECT") + dev[0].request("REMOVE_NETWORK all") + dev[1].request("REMOVE_NETWORK all") + + with open("/tmp/test_bgscan_learn.bgscan", "r") as f: + lines = f.read().splitlines() + if lines[0] != "wpa_supplicant-bgscan-learn": + raise Exception("Unexpected bgscan header line") + if 'BSS 02:00:00:00:03:00 2412' not in lines: + raise Exception("Missing BSS1") + if 'BSS 02:00:00:00:04:00 2412' not in lines: + raise Exception("Missing BSS2") + if 'NEIGHBOR 02:00:00:00:03:00 02:00:00:00:04:00' not in lines: + raise Exception("Missing BSS1->BSS2 neighbor entry") + if 'NEIGHBOR 02:00:00:00:04:00 02:00:00:00:03:00' not in lines: + raise Exception("Missing BSS2->BSS1 neighbor entry") + finally: + try: + os.remove("/tmp/test_bgscan_learn.bgscan") + except: + pass diff --git a/tests/hwsim/wpasupplicant.py b/tests/hwsim/wpasupplicant.py index 48d8b4776..4c007a1ab 100644 --- a/tests/hwsim/wpasupplicant.py +++ b/tests/hwsim/wpasupplicant.py @@ -639,7 +639,8 @@ class WpaSupplicant: "ca_cert", "client_cert", "private_key", "private_key_passwd", "ca_cert2", "client_cert2", "private_key2", "phase1", "phase2", "domain_suffix_match", - "altsubject_match", "subject_match", "pac_file", "dh_file" ] + "altsubject_match", "subject_match", "pac_file", "dh_file", + "bgscan" ] for field in quoted: if field in kwargs and kwargs[field]: self.set_network_quoted(id, field, kwargs[field])