2 # Copyright (c) 2014, Jouni Malinen <j@w1.fi>
4 # This software may be distributed under the terms of the BSD license.
5 # See README for more details.
9 logger = logging.getLogger()
14 def test_bgscan_simple(dev, apdev):
16 hostapd.add_ap(apdev[0]['ifname'], { "ssid": "bgscan" })
17 hostapd.add_ap(apdev[1]['ifname'], { "ssid": "bgscan" })
19 dev[0].connect("bgscan", key_mgmt="NONE", scan_freq="2412",
20 bgscan="simple:1:-20:2")
21 dev[1].connect("bgscan", key_mgmt="NONE", scan_freq="2412",
22 bgscan="simple:1:-45:2")
24 dev[2].connect("bgscan", key_mgmt="NONE", scan_freq="2412",
25 bgscan="simple:1:-45")
26 dev[2].request("REMOVE_NETWORK all")
27 dev[2].wait_disconnected()
29 dev[2].connect("bgscan", key_mgmt="NONE", scan_freq="2412",
31 dev[2].request("REMOVE_NETWORK all")
32 dev[2].wait_disconnected()
34 dev[2].connect("bgscan", key_mgmt="NONE", scan_freq="2412",
36 dev[2].request("REMOVE_NETWORK all")
37 dev[2].wait_disconnected()
39 dev[2].connect("bgscan", key_mgmt="NONE", scan_freq="2412",
41 dev[2].request("REMOVE_NETWORK all")
42 dev[2].wait_disconnected()
44 ev = dev[0].wait_event(["CTRL-EVENT-SIGNAL-CHANGE"], timeout=10)
46 raise Exception("dev0 did not indicate signal change event")
47 if "above=0" not in ev:
48 raise Exception("Unexpected signal change event contents from dev0: " + ev)
50 ev = dev[1].wait_event(["CTRL-EVENT-SIGNAL-CHANGE"], timeout=10)
52 raise Exception("dev1 did not indicate signal change event")
53 if "above=1" not in ev:
54 raise Exception("Unexpected signal change event contents from dev1: " + ev)
56 ev = dev[0].wait_event(["CTRL-EVENT-SCAN-STARTED"], timeout=3)
58 raise Exception("dev0 did not start a scan")
60 ev = dev[1].wait_event(["CTRL-EVENT-SCAN-STARTED"], timeout=3)
62 raise Exception("dev1 did not start a scan")
64 ev = dev[0].wait_event(["CTRL-EVENT-SCAN-RESULTS"], 5)
66 raise Exception("dev0 did not complete a scan")
67 ev = dev[1].wait_event(["CTRL-EVENT-SCAN-RESULTS"], 5)
69 raise Exception("dev1 did not complete a scan")
71 def test_bgscan_learn(dev, apdev):
73 hostapd.add_ap(apdev[0]['ifname'], { "ssid": "bgscan" })
74 hostapd.add_ap(apdev[1]['ifname'], { "ssid": "bgscan" })
77 os.remove("/tmp/test_bgscan_learn.bgscan")
82 dev[0].connect("bgscan", key_mgmt="NONE", scan_freq="2412",
83 bgscan="learn:1:-20:2")
84 id = dev[1].connect("bgscan", key_mgmt="NONE", scan_freq="2412",
85 bgscan="learn:1:-45:2:/tmp/test_bgscan_learn.bgscan")
87 dev[2].connect("bgscan", key_mgmt="NONE", scan_freq="2412",
89 dev[2].request("REMOVE_NETWORK all")
90 dev[2].wait_disconnected()
92 dev[2].connect("bgscan", key_mgmt="NONE", scan_freq="2412",
94 dev[2].request("REMOVE_NETWORK all")
95 dev[2].wait_disconnected()
97 dev[2].connect("bgscan", key_mgmt="NONE", scan_freq="2412",
99 dev[2].request("REMOVE_NETWORK all")
100 dev[2].wait_disconnected()
102 dev[2].connect("bgscan", key_mgmt="NONE", scan_freq="2412",
104 dev[2].request("REMOVE_NETWORK all")
105 dev[2].wait_disconnected()
107 ev = dev[0].wait_event(["CTRL-EVENT-SIGNAL-CHANGE"], timeout=10)
109 raise Exception("dev0 did not indicate signal change event")
110 if "above=0" not in ev:
111 raise Exception("Unexpected signal change event contents from dev0: " + ev)
113 ev = dev[1].wait_event(["CTRL-EVENT-SIGNAL-CHANGE"], timeout=10)
115 raise Exception("dev1 did not indicate signal change event")
116 if "above=1" not in ev:
117 raise Exception("Unexpected signal change event contents from dev1: " + ev)
119 ev = dev[0].wait_event(["CTRL-EVENT-SCAN-STARTED"], timeout=3)
121 raise Exception("dev0 did not start a scan")
123 ev = dev[1].wait_event(["CTRL-EVENT-SCAN-STARTED"], timeout=3)
125 raise Exception("dev1 did not start a scan")
127 ev = dev[0].wait_event(["CTRL-EVENT-SCAN-RESULTS"], 5)
129 raise Exception("dev0 did not complete a scan")
130 ev = dev[1].wait_event(["CTRL-EVENT-SCAN-RESULTS"], 5)
132 raise Exception("dev1 did not complete a scan")
134 dev[0].request("DISCONNECT")
135 dev[1].request("DISCONNECT")
136 dev[0].request("REMOVE_NETWORK all")
138 with open("/tmp/test_bgscan_learn.bgscan", "r") as f:
139 lines = f.read().splitlines()
140 if lines[0] != "wpa_supplicant-bgscan-learn":
141 raise Exception("Unexpected bgscan header line")
142 if 'BSS 02:00:00:00:03:00 2412' not in lines:
143 raise Exception("Missing BSS1")
144 if 'BSS 02:00:00:00:04:00 2412' not in lines:
145 raise Exception("Missing BSS2")
146 if 'NEIGHBOR 02:00:00:00:03:00 02:00:00:00:04:00' not in lines:
147 raise Exception("Missing BSS1->BSS2 neighbor entry")
148 if 'NEIGHBOR 02:00:00:00:04:00 02:00:00:00:03:00' not in lines:
149 raise Exception("Missing BSS2->BSS1 neighbor entry")
151 dev[1].set_network(id, "scan_freq", "")
152 dev[1].connect_network(id)
154 ev = dev[1].wait_event(["CTRL-EVENT-SCAN-STARTED"], timeout=10)
156 raise Exception("dev1 did not start a scan")
158 ev = dev[1].wait_event(["CTRL-EVENT-SCAN-RESULTS"], 10)
160 raise Exception("dev1 did not complete a scan")
162 dev[1].request("REMOVE_NETWORK all")
165 os.remove("/tmp/test_bgscan_learn.bgscan")