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_autoscan_periodic(dev, apdev):
15 """autoscan_periodic"""
16 hostapd.add_ap(apdev[0]['ifname'], { "ssid": "autoscan" })
19 if "OK" not in dev[0].request("AUTOSCAN periodic:1"):
20 raise Exception("Failed to set autoscan")
21 id = dev[0].connect("not-used", key_mgmt="NONE", scan_freq="2412",
25 logger.info("Waiting for scan to start")
27 ev = dev[0].wait_event(["CTRL-EVENT-SCAN-STARTED"], timeout=5)
29 raise Exception("did not start a scan")
31 times[i] = stop - start
32 logger.info("Waiting for scan to complete")
33 ev = dev[0].wait_event(["CTRL-EVENT-SCAN-RESULTS"], 10)
35 raise Exception("did not complete a scan")
36 if times[0] > 1 or times[1] < 0.5 or times[1] > 1.5 or times[2] < 0.5 or times[2] > 1.5:
37 raise Exception("Unexpected scan timing: " + str(times))
39 # scan some more channels to allow some more time for reseting AUTOSCAN
40 # while a scan is in progress
41 dev[0].set_network(id, "scan_freq", "2412 2437 2462 5180 5200 5220 5240")
43 ev = dev[0].wait_event(["CTRL-EVENT-SCAN-STARTED"], timeout=5)
45 raise Exception("did not start a scan")
46 if "OK" not in dev[0].request("AUTOSCAN periodic:2"):
47 raise Exception("Failed to (re)set autoscan")
48 ev = dev[0].wait_event(["CTRL-EVENT-SCAN-RESULTS"], 10)
50 raise Exception("did not complete a scan")
52 dev[0].request("AUTOSCAN ")
54 def test_autoscan_exponential(dev, apdev):
55 """autoscan_exponential"""
56 hostapd.add_ap(apdev[0]['ifname'], { "ssid": "autoscan" })
59 if "OK" not in dev[0].request("AUTOSCAN exponential:2:10"):
60 raise Exception("Failed to set autoscan")
61 dev[0].connect("not-used", key_mgmt="NONE", scan_freq="2412",
65 logger.info("Waiting for scan to start")
67 ev = dev[0].wait_event(["CTRL-EVENT-SCAN-STARTED"], timeout=5)
69 raise Exception("did not start a scan")
71 times[i] = stop - start
72 logger.info("Waiting for scan to complete")
73 ev = dev[0].wait_event(["CTRL-EVENT-SCAN-RESULTS"], 10)
75 raise Exception("did not complete a scan")
76 if times[0] > 1 or times[1] < 1 or times[1] > 3 or times[2] < 3 or times[2] > 5:
77 raise Exception("Unexpected scan timing: " + str(times))
79 dev[0].request("AUTOSCAN ")