Updated through tag hostap_2_5 from git://w1.fi/hostap.git
[mech_eap.git] / libeap / tests / hwsim / test_ap_roam.py
1 # Roaming tests
2 # Copyright (c) 2013, Jouni Malinen <j@w1.fi>
3 #
4 # This software may be distributed under the terms of the BSD license.
5 # See README for more details.
6
7 import time
8 import subprocess
9 import logging
10 logger = logging.getLogger()
11
12 import hwsim_utils
13 import hostapd
14
15 def test_ap_roam_open(dev, apdev):
16     """Roam between two open APs"""
17     hapd0 = hostapd.add_ap(apdev[0]['ifname'], { "ssid": "test-open" })
18     dev[0].connect("test-open", key_mgmt="NONE")
19     hwsim_utils.test_connectivity(dev[0], hapd0)
20     hapd1 = hostapd.add_ap(apdev[1]['ifname'], { "ssid": "test-open" })
21     dev[0].scan(type="ONLY")
22     dev[0].roam(apdev[1]['bssid'])
23     hwsim_utils.test_connectivity(dev[0], hapd1)
24     dev[0].roam(apdev[0]['bssid'])
25     hwsim_utils.test_connectivity(dev[0], hapd0)
26
27 def test_ap_roam_wpa2_psk(dev, apdev):
28     """Roam between two WPA2-PSK APs"""
29     params = hostapd.wpa2_params(ssid="test-wpa2-psk", passphrase="12345678")
30     hapd0 = hostapd.add_ap(apdev[0]['ifname'], params)
31     dev[0].connect("test-wpa2-psk", psk="12345678")
32     hwsim_utils.test_connectivity(dev[0], hapd0)
33     hapd1 = hostapd.add_ap(apdev[1]['ifname'], params)
34     dev[0].scan(type="ONLY")
35     dev[0].roam(apdev[1]['bssid'])
36     hwsim_utils.test_connectivity(dev[0], hapd1)
37     dev[0].roam(apdev[0]['bssid'])
38     hwsim_utils.test_connectivity(dev[0], hapd0)
39
40 def test_ap_reassociation_to_same_bss(dev, apdev):
41     """Reassociate to the same BSS"""
42     hapd = hostapd.add_ap(apdev[0]['ifname'], { "ssid": "test-open" })
43     dev[0].connect("test-open", key_mgmt="NONE")
44
45     dev[0].request("REASSOCIATE")
46     dev[0].wait_connected(timeout=10, error="Reassociation timed out")
47     hwsim_utils.test_connectivity(dev[0], hapd)
48
49     dev[0].request("REATTACH")
50     dev[0].wait_connected(timeout=10, error="Reattach timed out")
51     hwsim_utils.test_connectivity(dev[0], hapd)
52
53 def test_ap_roam_set_bssid(dev, apdev):
54     """Roam control"""
55     hostapd.add_ap(apdev[0]['ifname'], { "ssid": "test-open" })
56     hostapd.add_ap(apdev[1]['ifname'], { "ssid": "test-open" })
57     id = dev[0].connect("test-open", key_mgmt="NONE", bssid=apdev[1]['bssid'],
58                         scan_freq="2412")
59     if dev[0].get_status_field('bssid') != apdev[1]['bssid']:
60         raise Exception("Unexpected BSS")
61     # for now, these are just verifying that the code path to indicate
62     # within-ESS roaming changes can be executed; the actual results of those
63     # operations are not currently verified (that would require a test driver
64     # that does BSS selection)
65     dev[0].set_network(id, "bssid", "")
66     dev[0].set_network(id, "bssid", apdev[0]['bssid'])
67     dev[0].set_network(id, "bssid", apdev[1]['bssid'])