]>
git.ipfire.org Git - thirdparty/hostap.git/blob - tests/hwsim/test_ap_roam.py
2 # Copyright (c) 2013, Jouni Malinen <j@w1.fi>
4 # This software may be distributed under the terms of the BSD license.
5 # See README for more details.
7 from remotehost
import remote_compatible
10 logger
= logging
.getLogger()
14 from wpasupplicant
import WpaSupplicant
17 def test_ap_roam_open(dev
, apdev
):
18 """Roam between two open APs"""
19 hapd0
= hostapd
.add_ap(apdev
[0], {"ssid": "test-open"})
20 dev
[0].connect("test-open", key_mgmt
="NONE")
21 hwsim_utils
.test_connectivity(dev
[0], hapd0
)
22 hapd1
= hostapd
.add_ap(apdev
[1], {"ssid": "test-open"})
23 dev
[0].scan(type="ONLY")
24 dev
[0].roam(apdev
[1]['bssid'])
25 hwsim_utils
.test_connectivity(dev
[0], hapd1
)
26 dev
[0].roam(apdev
[0]['bssid'])
27 hwsim_utils
.test_connectivity(dev
[0], hapd0
)
30 def test_ap_roam_open_failed(dev
, apdev
):
31 """Roam failure due to rejected authentication"""
32 hapd0
= hostapd
.add_ap(apdev
[0], {"ssid": "test-open"})
33 dev
[0].connect("test-open", key_mgmt
="NONE", scan_freq
="2412")
34 hwsim_utils
.test_connectivity(dev
[0], hapd0
)
35 params
= {"ssid": "test-open", "max_num_sta": "0"}
36 hapd1
= hostapd
.add_ap(apdev
[1], params
)
37 bssid
= hapd1
.own_addr()
39 dev
[0].scan_for_bss(bssid
, freq
=2412)
41 if "OK" not in dev
[0].request("ROAM " + bssid
):
42 raise Exception("ROAM failed")
44 ev
= dev
[0].wait_event(["CTRL-EVENT-AUTH-REJECT"], 1)
46 raise Exception("CTRL-EVENT-AUTH-REJECT was not seen")
48 dev
[0].wait_connected(timeout
=5)
49 hwsim_utils
.test_connectivity(dev
[0], hapd0
)
52 def test_ap_roam_wpa2_psk(dev
, apdev
):
53 """Roam between two WPA2-PSK APs"""
54 params
= hostapd
.wpa2_params(ssid
="test-wpa2-psk", passphrase
="12345678")
55 hapd0
= hostapd
.add_ap(apdev
[0], params
)
56 dev
[0].connect("test-wpa2-psk", psk
="12345678")
57 hwsim_utils
.test_connectivity(dev
[0], hapd0
)
58 hapd1
= hostapd
.add_ap(apdev
[1], params
)
59 dev
[0].scan(type="ONLY")
60 dev
[0].roam(apdev
[1]['bssid'])
61 hwsim_utils
.test_connectivity(dev
[0], hapd1
)
62 dev
[0].roam(apdev
[0]['bssid'])
63 hwsim_utils
.test_connectivity(dev
[0], hapd0
)
65 def get_blacklist(dev
):
66 return dev
.request("BLACKLIST").splitlines()
68 def test_ap_reconnect_auth_timeout(dev
, apdev
, params
):
69 """Reconnect to 2nd AP and authentication times out"""
70 wpas
= WpaSupplicant(global_iface
='/tmp/wpas-wlan5')
71 wpas
.interface_add("wlan5",
72 drv_params
="force_connect_cmd=1,force_bss_selection=1")
74 params
= hostapd
.wpa2_params(ssid
="test-wpa2-psk", passphrase
="12345678")
75 hapd0
= hostapd
.add_ap(apdev
[0], params
)
76 bssid0
= hapd0
.own_addr()
78 wpas
.scan_for_bss(bssid0
, freq
=2412)
79 id = wpas
.connect("test-wpa2-psk", psk
="12345678", scan_freq
="2412")
80 hwsim_utils
.test_connectivity(wpas
, hapd0
)
82 hapd1
= hostapd
.add_ap(apdev
[1], params
)
83 bssid1
= hapd1
.own_addr()
85 wpas
.request("BLACKLIST " + bssid0
)
87 wpas
.scan_for_bss(bssid1
, freq
=2412)
88 wpas
.request("DISCONNECT")
89 if "OK" not in wpas
.request("SET ignore_auth_resp 1"):
90 raise Exception("SET ignore_auth_resp failed")
91 if "OK" not in wpas
.request("ENABLE_NETWORK " + str(id)):
92 raise Exception("ENABLE_NETWORK failed")
93 if "OK" not in wpas
.request("SELECT_NETWORK " + str(id)):
94 raise Exception("SELECT_NETWORK failed")
96 logger
.info("Wait ~10s for auth timeout...")
98 ev
= wpas
.wait_event(["CTRL-EVENT-SCAN-STARTED"], 12)
100 raise Exception("CTRL-EVENT-SCAN-STARTED not seen")
102 b
= get_blacklist(wpas
)
103 if '00:00:00:00:00:00' in b
:
104 raise Exception("Unexpected blacklist contents: " + str(b
))
106 raise Exception("Unexpected blacklist contents: " + str(b
))
108 def test_ap_roam_with_reassoc_auth_timeout(dev
, apdev
, params
):
109 """Roam using reassoc between two APs and authentication times out"""
110 wpas
= WpaSupplicant(global_iface
='/tmp/wpas-wlan5')
111 wpas
.interface_add("wlan5",
112 drv_params
="force_connect_cmd=1,force_bss_selection=1")
114 params
= hostapd
.wpa2_params(ssid
="test-wpa2-psk", passphrase
="12345678")
115 hapd0
= hostapd
.add_ap(apdev
[0], params
)
116 bssid0
= hapd0
.own_addr()
118 id = wpas
.connect("test-wpa2-psk", psk
="12345678", scan_freq
="2412")
119 hwsim_utils
.test_connectivity(wpas
, hapd0
)
121 hapd1
= hostapd
.add_ap(apdev
[1], params
)
122 bssid1
= hapd1
.own_addr()
123 wpas
.scan_for_bss(bssid1
, freq
=2412)
125 if "OK" not in wpas
.request("SET_NETWORK " + str(id) + " bssid " + bssid1
):
126 raise Exception("SET_NETWORK failed")
127 if "OK" not in wpas
.request("SET ignore_auth_resp 1"):
128 raise Exception("SET ignore_auth_resp failed")
129 if "OK" not in wpas
.request("REASSOCIATE"):
130 raise Exception("REASSOCIATE failed")
132 logger
.info("Wait ~10s for auth timeout...")
134 ev
= wpas
.wait_event(["CTRL-EVENT-SCAN-STARTED"], 12)
136 raise Exception("CTRL-EVENT-SCAN-STARTED not seen")
138 b
= get_blacklist(wpas
)
140 raise Exception("Unexpected blacklist contents: " + str(b
))
142 def test_ap_roam_wpa2_psk_failed(dev
, apdev
, params
):
143 """Roam failure with WPA2-PSK AP due to wrong passphrase"""
144 params
= hostapd
.wpa2_params(ssid
="test-wpa2-psk", passphrase
="12345678")
145 hapd0
= hostapd
.add_ap(apdev
[0], params
)
146 id = dev
[0].connect("test-wpa2-psk", psk
="12345678", scan_freq
="2412")
147 hwsim_utils
.test_connectivity(dev
[0], hapd0
)
148 params
['wpa_passphrase'] = "22345678"
149 hapd1
= hostapd
.add_ap(apdev
[1], params
)
150 bssid
= hapd1
.own_addr()
151 dev
[0].scan_for_bss(bssid
, freq
=2412)
153 dev
[0].dump_monitor()
154 if "OK" not in dev
[0].request("ROAM " + bssid
):
155 raise Exception("ROAM failed")
157 ev
= dev
[0].wait_event(["CTRL-EVENT-SSID-TEMP-DISABLED",
158 "CTRL-EVENT-CONNECTED"], 5)
159 if "CTRL-EVENT-CONNECTED" in ev
:
160 raise Exception("Got unexpected CTRL-EVENT-CONNECTED")
161 if "CTRL-EVENT-SSID-TEMP-DISABLED" not in ev
:
162 raise Exception("CTRL-EVENT-SSID-TEMP-DISABLED not seen")
164 if "OK" not in dev
[0].request("SELECT_NETWORK id=" + str(id)):
165 raise Exception("SELECT_NETWORK failed")
167 ev
= dev
[0].wait_event(["CTRL-EVENT-SSID-REENABLED"], 3)
169 raise Exception("CTRL-EVENT-SSID-REENABLED not seen")
171 dev
[0].wait_connected(timeout
=5)
172 hwsim_utils
.test_connectivity(dev
[0], hapd0
)
175 def test_ap_reassociation_to_same_bss(dev
, apdev
):
176 """Reassociate to the same BSS"""
177 hapd
= hostapd
.add_ap(apdev
[0], {"ssid": "test-open"})
178 dev
[0].connect("test-open", key_mgmt
="NONE")
180 dev
[0].request("REASSOCIATE")
181 dev
[0].wait_connected(timeout
=10, error
="Reassociation timed out")
182 hwsim_utils
.test_connectivity(dev
[0], hapd
)
184 dev
[0].request("REATTACH")
185 dev
[0].wait_connected(timeout
=10, error
="Reattach timed out")
186 hwsim_utils
.test_connectivity(dev
[0], hapd
)
188 # Wait for previous scan results to expire to trigger new scan
190 dev
[0].request("REATTACH")
191 dev
[0].wait_connected(timeout
=10, error
="Reattach timed out")
192 hwsim_utils
.test_connectivity(dev
[0], hapd
)
195 def test_ap_roam_set_bssid(dev
, apdev
):
197 hostapd
.add_ap(apdev
[0], {"ssid": "test-open"})
198 hostapd
.add_ap(apdev
[1], {"ssid": "test-open"})
199 id = dev
[0].connect("test-open", key_mgmt
="NONE", bssid
=apdev
[1]['bssid'],
201 if dev
[0].get_status_field('bssid') != apdev
[1]['bssid']:
202 raise Exception("Unexpected BSS")
203 # for now, these are just verifying that the code path to indicate
204 # within-ESS roaming changes can be executed; the actual results of those
205 # operations are not currently verified (that would require a test driver
206 # that does BSS selection)
207 dev
[0].set_network(id, "bssid", "")
208 dev
[0].set_network(id, "bssid", apdev
[0]['bssid'])
209 dev
[0].set_network(id, "bssid", apdev
[1]['bssid'])
212 def test_ap_roam_wpa2_psk_race(dev
, apdev
):
213 """Roam between two WPA2-PSK APs and try to hit a disconnection race"""
214 params
= hostapd
.wpa2_params(ssid
="test-wpa2-psk", passphrase
="12345678")
215 hapd0
= hostapd
.add_ap(apdev
[0], params
)
216 dev
[0].connect("test-wpa2-psk", psk
="12345678", scan_freq
="2412")
217 hwsim_utils
.test_connectivity(dev
[0], hapd0
)
219 params
['channel'] = '2'
220 hapd1
= hostapd
.add_ap(apdev
[1], params
)
221 dev
[0].scan_for_bss(apdev
[1]['bssid'], freq
=2417)
222 dev
[0].roam(apdev
[1]['bssid'])
223 hwsim_utils
.test_connectivity(dev
[0], hapd1
)
224 dev
[0].roam(apdev
[0]['bssid'])
225 hwsim_utils
.test_connectivity(dev
[0], hapd0
)
226 # Wait at least two seconds to trigger the previous issue with the
227 # disconnection callback.
230 hwsim_utils
.test_connectivity(dev
[0], hapd0
)