]>
Commit | Line | Data |
---|---|---|
5126138c JM |
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 | ||
9fd6804d | 7 | from remotehost import remote_compatible |
5126138c | 8 | import time |
5126138c | 9 | import logging |
c9aa4308 | 10 | logger = logging.getLogger() |
5126138c JM |
11 | |
12 | import hwsim_utils | |
13 | import hostapd | |
d258c70f | 14 | from wpasupplicant import WpaSupplicant |
5126138c | 15 | |
9fd6804d | 16 | @remote_compatible |
ae3ad328 | 17 | def test_ap_roam_open(dev, apdev): |
5126138c | 18 | """Roam between two open APs""" |
fab49f61 | 19 | hapd0 = hostapd.add_ap(apdev[0], {"ssid": "test-open"}) |
5126138c | 20 | dev[0].connect("test-open", key_mgmt="NONE") |
a8375c94 | 21 | hwsim_utils.test_connectivity(dev[0], hapd0) |
fab49f61 | 22 | hapd1 = hostapd.add_ap(apdev[1], {"ssid": "test-open"}) |
5126138c | 23 | dev[0].scan(type="ONLY") |
ae3ad328 | 24 | dev[0].roam(apdev[1]['bssid']) |
a8375c94 | 25 | hwsim_utils.test_connectivity(dev[0], hapd1) |
ae3ad328 | 26 | dev[0].roam(apdev[0]['bssid']) |
a8375c94 | 27 | hwsim_utils.test_connectivity(dev[0], hapd0) |
5126138c | 28 | |
9fd6804d | 29 | @remote_compatible |
fed0a9f5 IP |
30 | def test_ap_roam_open_failed(dev, apdev): |
31 | """Roam failure due to rejected authentication""" | |
fab49f61 | 32 | hapd0 = hostapd.add_ap(apdev[0], {"ssid": "test-open"}) |
fed0a9f5 IP |
33 | dev[0].connect("test-open", key_mgmt="NONE", scan_freq="2412") |
34 | hwsim_utils.test_connectivity(dev[0], hapd0) | |
fab49f61 | 35 | params = {"ssid": "test-open", "max_num_sta": "0"} |
fed0a9f5 IP |
36 | hapd1 = hostapd.add_ap(apdev[1], params) |
37 | bssid = hapd1.own_addr() | |
38 | ||
39 | dev[0].scan_for_bss(bssid, freq=2412) | |
40 | dev[0].dump_monitor() | |
41 | if "OK" not in dev[0].request("ROAM " + bssid): | |
42 | raise Exception("ROAM failed") | |
43 | ||
44 | ev = dev[0].wait_event(["CTRL-EVENT-AUTH-REJECT"], 1) | |
45 | if not ev: | |
46 | raise Exception("CTRL-EVENT-AUTH-REJECT was not seen") | |
47 | ||
48 | dev[0].wait_connected(timeout=5) | |
49 | hwsim_utils.test_connectivity(dev[0], hapd0) | |
50 | ||
9fd6804d | 51 | @remote_compatible |
ae3ad328 | 52 | def test_ap_roam_wpa2_psk(dev, apdev): |
5126138c JM |
53 | """Roam between two WPA2-PSK APs""" |
54 | params = hostapd.wpa2_params(ssid="test-wpa2-psk", passphrase="12345678") | |
8b8a1864 | 55 | hapd0 = hostapd.add_ap(apdev[0], params) |
5126138c | 56 | dev[0].connect("test-wpa2-psk", psk="12345678") |
a8375c94 | 57 | hwsim_utils.test_connectivity(dev[0], hapd0) |
8b8a1864 | 58 | hapd1 = hostapd.add_ap(apdev[1], params) |
5126138c | 59 | dev[0].scan(type="ONLY") |
ae3ad328 | 60 | dev[0].roam(apdev[1]['bssid']) |
a8375c94 | 61 | hwsim_utils.test_connectivity(dev[0], hapd1) |
ae3ad328 | 62 | dev[0].roam(apdev[0]['bssid']) |
a8375c94 | 63 | hwsim_utils.test_connectivity(dev[0], hapd0) |
99cd77a8 | 64 | |
d258c70f MK |
65 | def get_blacklist(dev): |
66 | return dev.request("BLACKLIST").splitlines() | |
67 | ||
7137c7da MK |
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") | |
73 | ||
74 | params = hostapd.wpa2_params(ssid="test-wpa2-psk", passphrase="12345678") | |
75 | hapd0 = hostapd.add_ap(apdev[0], params) | |
76 | bssid0 = hapd0.own_addr() | |
7137c7da MK |
77 | |
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) | |
81 | ||
16b5413f AO |
82 | hapd1 = hostapd.add_ap(apdev[1], params) |
83 | bssid1 = hapd1.own_addr() | |
84 | ||
7137c7da MK |
85 | wpas.request("BLACKLIST " + bssid0) |
86 | ||
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") | |
95 | ||
96 | logger.info("Wait ~10s for auth timeout...") | |
97 | time.sleep(10) | |
98 | ev = wpas.wait_event(["CTRL-EVENT-SCAN-STARTED"], 12) | |
99 | if not ev: | |
58be42b2 | 100 | raise Exception("CTRL-EVENT-SCAN-STARTED not seen") |
7137c7da MK |
101 | |
102 | b = get_blacklist(wpas) | |
103 | if '00:00:00:00:00:00' in b: | |
104 | raise Exception("Unexpected blacklist contents: " + str(b)) | |
105 | if bssid1 not in b: | |
106 | raise Exception("Unexpected blacklist contents: " + str(b)) | |
107 | ||
d258c70f MK |
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") | |
113 | ||
114 | params = hostapd.wpa2_params(ssid="test-wpa2-psk", passphrase="12345678") | |
115 | hapd0 = hostapd.add_ap(apdev[0], params) | |
116 | bssid0 = hapd0.own_addr() | |
117 | ||
118 | id = wpas.connect("test-wpa2-psk", psk="12345678", scan_freq="2412") | |
119 | hwsim_utils.test_connectivity(wpas, hapd0) | |
120 | ||
121 | hapd1 = hostapd.add_ap(apdev[1], params) | |
122 | bssid1 = hapd1.own_addr() | |
123 | wpas.scan_for_bss(bssid1, freq=2412) | |
124 | ||
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") | |
131 | ||
132 | logger.info("Wait ~10s for auth timeout...") | |
133 | time.sleep(10) | |
134 | ev = wpas.wait_event(["CTRL-EVENT-SCAN-STARTED"], 12) | |
135 | if not ev: | |
58be42b2 | 136 | raise Exception("CTRL-EVENT-SCAN-STARTED not seen") |
d258c70f MK |
137 | |
138 | b = get_blacklist(wpas) | |
139 | if bssid0 in b: | |
140 | raise Exception("Unexpected blacklist contents: " + str(b)) | |
141 | ||
fed0a9f5 IP |
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) | |
152 | ||
153 | dev[0].dump_monitor() | |
154 | if "OK" not in dev[0].request("ROAM " + bssid): | |
155 | raise Exception("ROAM failed") | |
156 | ||
157 | ev = dev[0].wait_event(["CTRL-EVENT-SSID-TEMP-DISABLED", | |
0663ae22 | 158 | "CTRL-EVENT-CONNECTED"], 5) |
fed0a9f5 IP |
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") | |
163 | ||
164 | if "OK" not in dev[0].request("SELECT_NETWORK id=" + str(id)): | |
165 | raise Exception("SELECT_NETWORK failed") | |
166 | ||
167 | ev = dev[0].wait_event(["CTRL-EVENT-SSID-REENABLED"], 3) | |
168 | if not ev: | |
bc6e3288 | 169 | raise Exception("CTRL-EVENT-SSID-REENABLED not seen") |
fed0a9f5 IP |
170 | |
171 | dev[0].wait_connected(timeout=5) | |
172 | hwsim_utils.test_connectivity(dev[0], hapd0) | |
173 | ||
9fd6804d | 174 | @remote_compatible |
99cd77a8 JM |
175 | def test_ap_reassociation_to_same_bss(dev, apdev): |
176 | """Reassociate to the same BSS""" | |
fab49f61 | 177 | hapd = hostapd.add_ap(apdev[0], {"ssid": "test-open"}) |
99cd77a8 JM |
178 | dev[0].connect("test-open", key_mgmt="NONE") |
179 | ||
180 | dev[0].request("REASSOCIATE") | |
5f35a5e2 | 181 | dev[0].wait_connected(timeout=10, error="Reassociation timed out") |
a8375c94 | 182 | hwsim_utils.test_connectivity(dev[0], hapd) |
99cd77a8 JM |
183 | |
184 | dev[0].request("REATTACH") | |
5f35a5e2 | 185 | dev[0].wait_connected(timeout=10, error="Reattach timed out") |
a8375c94 | 186 | hwsim_utils.test_connectivity(dev[0], hapd) |
a567aae4 | 187 | |
8f5abdb8 JM |
188 | # Wait for previous scan results to expire to trigger new scan |
189 | time.sleep(5) | |
190 | dev[0].request("REATTACH") | |
191 | dev[0].wait_connected(timeout=10, error="Reattach timed out") | |
192 | hwsim_utils.test_connectivity(dev[0], hapd) | |
193 | ||
9fd6804d | 194 | @remote_compatible |
a567aae4 JM |
195 | def test_ap_roam_set_bssid(dev, apdev): |
196 | """Roam control""" | |
fab49f61 JM |
197 | hostapd.add_ap(apdev[0], {"ssid": "test-open"}) |
198 | hostapd.add_ap(apdev[1], {"ssid": "test-open"}) | |
a567aae4 JM |
199 | id = dev[0].connect("test-open", key_mgmt="NONE", bssid=apdev[1]['bssid'], |
200 | scan_freq="2412") | |
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']) | |
5a38a7fe | 210 | |
9fd6804d | 211 | @remote_compatible |
5a38a7fe JM |
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") | |
8b8a1864 | 215 | hapd0 = hostapd.add_ap(apdev[0], params) |
5a38a7fe JM |
216 | dev[0].connect("test-wpa2-psk", psk="12345678", scan_freq="2412") |
217 | hwsim_utils.test_connectivity(dev[0], hapd0) | |
218 | ||
219 | params['channel'] = '2' | |
8b8a1864 | 220 | hapd1 = hostapd.add_ap(apdev[1], params) |
5a38a7fe JM |
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. | |
228 | for i in range(3): | |
229 | time.sleep(0.8) | |
230 | hwsim_utils.test_connectivity(dev[0], hapd0) |