]>
Commit | Line | Data |
---|---|---|
93a06242 | 1 | # Hotspot 2.0 tests |
3b51cc63 | 2 | # Copyright (c) 2013-2015, Jouni Malinen <j@w1.fi> |
93a06242 JM |
3 | # |
4 | # This software may be distributed under the terms of the BSD license. | |
5 | # See README for more details. | |
6 | ||
446dd748 | 7 | import base64 |
67aeee11 JM |
8 | import binascii |
9 | import struct | |
93a06242 JM |
10 | import time |
11 | import subprocess | |
12 | import logging | |
c9aa4308 | 13 | logger = logging.getLogger() |
97de642a | 14 | import os |
efd43d85 | 15 | import os.path |
67aeee11 | 16 | import socket |
efd43d85 | 17 | import subprocess |
93a06242 JM |
18 | |
19 | import hostapd | |
ca158ea6 | 20 | from utils import HwsimSkip, skip_with_fips |
40e4c9c8 | 21 | import hwsim_utils |
efd0a6fb | 22 | from tshark import run_tshark |
715bf904 | 23 | from wlantest import Wlantest |
9d1e1172 | 24 | from wpasupplicant import WpaSupplicant |
24579e70 | 25 | from test_ap_eap import check_eap_capa, check_domain_match_full |
93a06242 | 26 | |
d4058934 JM |
27 | def hs20_ap_params(ssid="test-hs20"): |
28 | params = hostapd.wpa2_params(ssid=ssid) | |
93a06242 JM |
29 | params['wpa_key_mgmt'] = "WPA-EAP" |
30 | params['ieee80211w'] = "1" | |
31 | params['ieee8021x'] = "1" | |
32 | params['auth_server_addr'] = "127.0.0.1" | |
33 | params['auth_server_port'] = "1812" | |
34 | params['auth_server_shared_secret'] = "radius" | |
35 | params['interworking'] = "1" | |
36 | params['access_network_type'] = "14" | |
37 | params['internet'] = "1" | |
38 | params['asra'] = "0" | |
39 | params['esr'] = "0" | |
40 | params['uesa'] = "0" | |
41 | params['venue_group'] = "7" | |
42 | params['venue_type'] = "1" | |
43 | params['venue_name'] = [ "eng:Example venue", "fin:Esimerkkipaikka" ] | |
44 | params['roaming_consortium'] = [ "112233", "1020304050", "010203040506", | |
45 | "fedcba" ] | |
46 | params['domain_name'] = "example.com,another.example.com" | |
47 | params['nai_realm'] = [ "0,example.com,13[5:6],21[2:4][5:7]", | |
48 | "0,another.example.com" ] | |
49 | params['hs20'] = "1" | |
50 | params['hs20_wan_metrics'] = "01:8000:1000:80:240:3000" | |
51 | params['hs20_conn_capab'] = [ "1:0:2", "6:22:1", "17:5060:0" ] | |
52 | params['hs20_operating_class'] = "5173" | |
53 | params['anqp_3gpp_cell_net'] = "244,91" | |
54 | return params | |
55 | ||
9714fbcd | 56 | def check_auto_select(dev, bssid): |
841bed04 | 57 | dev.scan_for_bss(bssid, freq="2412") |
9714fbcd | 58 | dev.request("INTERWORKING_SELECT auto freq=2412") |
5f35a5e2 | 59 | ev = dev.wait_connected(timeout=15) |
9714fbcd JM |
60 | if bssid not in ev: |
61 | raise Exception("Connected to incorrect network") | |
62 | dev.request("REMOVE_NETWORK all") | |
092ac7bb | 63 | dev.wait_disconnected() |
a359c7bb | 64 | dev.dump_monitor() |
9714fbcd | 65 | |
2f37a66d | 66 | def interworking_select(dev, bssid, type=None, no_match=False, freq=None): |
bbe86767 | 67 | dev.dump_monitor() |
841bed04 JM |
68 | if bssid and freq and not no_match: |
69 | dev.scan_for_bss(bssid, freq=freq) | |
22653762 | 70 | freq_extra = " freq=" + str(freq) if freq else "" |
2f37a66d | 71 | dev.request("INTERWORKING_SELECT" + freq_extra) |
bbe86767 JM |
72 | ev = dev.wait_event(["INTERWORKING-AP", "INTERWORKING-NO-MATCH"], |
73 | timeout=15) | |
93a06242 JM |
74 | if ev is None: |
75 | raise Exception("Network selection timed out"); | |
bbe86767 JM |
76 | if no_match: |
77 | if "INTERWORKING-NO-MATCH" not in ev: | |
78 | raise Exception("Unexpected network match") | |
79 | return | |
93a06242 | 80 | if "INTERWORKING-NO-MATCH" in ev: |
0dee3a0a JM |
81 | logger.info("Matching network not found - try again") |
82 | dev.dump_monitor() | |
83 | dev.request("INTERWORKING_SELECT" + freq_extra) | |
84 | ev = dev.wait_event(["INTERWORKING-AP", "INTERWORKING-NO-MATCH"], | |
85 | timeout=15) | |
86 | if ev is None: | |
87 | raise Exception("Network selection timed out"); | |
88 | if "INTERWORKING-NO-MATCH" in ev: | |
89 | raise Exception("Matching network not found") | |
2cdd91d8 | 90 | if bssid and bssid not in ev: |
93a06242 | 91 | raise Exception("Unexpected BSSID in match") |
bbe86767 JM |
92 | if type and "type=" + type not in ev: |
93 | raise Exception("Network type not recognized correctly") | |
93a06242 | 94 | |
bbe86767 JM |
95 | def check_sp_type(dev, sp_type): |
96 | type = dev.get_status_field("sp_type") | |
97 | if type is None: | |
98 | raise Exception("sp_type not available") | |
99 | if type != sp_type: | |
100 | raise Exception("sp_type did not indicate home network") | |
efd43d85 | 101 | |
bbe86767 | 102 | def hlr_auc_gw_available(): |
efd43d85 | 103 | if not os.path.exists("/tmp/hlr_auc_gw.sock"): |
81e787b7 | 104 | raise HwsimSkip("No hlr_auc_gw socket available") |
efd43d85 | 105 | if not os.path.exists("../../hostapd/hlr_auc_gw"): |
81e787b7 | 106 | raise HwsimSkip("No hlr_auc_gw available") |
efd43d85 | 107 | |
bbe86767 JM |
108 | def interworking_ext_sim_connect(dev, bssid, method): |
109 | dev.request("INTERWORKING_CONNECT " + bssid) | |
078683ac | 110 | interworking_ext_sim_auth(dev, method) |
efd43d85 | 111 | |
078683ac | 112 | def interworking_ext_sim_auth(dev, method): |
bbe86767 | 113 | ev = dev.wait_event(["CTRL-EVENT-EAP-METHOD"], timeout=15) |
efd43d85 JM |
114 | if ev is None: |
115 | raise Exception("Network connected timed out") | |
bbe86767 | 116 | if "(" + method + ")" not in ev: |
efd43d85 JM |
117 | raise Exception("Unexpected EAP method selection") |
118 | ||
bbe86767 | 119 | ev = dev.wait_event(["CTRL-REQ-SIM"], timeout=15) |
efd43d85 JM |
120 | if ev is None: |
121 | raise Exception("Wait for external SIM processing request timed out") | |
122 | p = ev.split(':', 2) | |
123 | if p[1] != "GSM-AUTH": | |
124 | raise Exception("Unexpected CTRL-REQ-SIM type") | |
125 | id = p[0].split('-')[3] | |
126 | rand = p[2].split(' ')[0] | |
127 | ||
128 | res = subprocess.check_output(["../../hostapd/hlr_auc_gw", | |
129 | "-m", | |
130 | "auth_serv/hlr_auc_gw.milenage_db", | |
131 | "GSM-AUTH-REQ 232010000000000 " + rand]) | |
132 | if "GSM-AUTH-RESP" not in res: | |
133 | raise Exception("Unexpected hlr_auc_gw response") | |
134 | resp = res.split(' ')[2].rstrip() | |
135 | ||
bbe86767 | 136 | dev.request("CTRL-RSP-SIM-" + id + ":GSM-AUTH:" + resp) |
5f35a5e2 | 137 | dev.wait_connected(timeout=15) |
f4defd91 | 138 | |
8fba2e5d JM |
139 | def interworking_connect(dev, bssid, method): |
140 | dev.request("INTERWORKING_CONNECT " + bssid) | |
078683ac | 141 | interworking_auth(dev, method) |
8fba2e5d | 142 | |
078683ac | 143 | def interworking_auth(dev, method): |
8fba2e5d JM |
144 | ev = dev.wait_event(["CTRL-EVENT-EAP-METHOD"], timeout=15) |
145 | if ev is None: | |
146 | raise Exception("Network connected timed out") | |
147 | if "(" + method + ")" not in ev: | |
148 | raise Exception("Unexpected EAP method selection") | |
149 | ||
5f35a5e2 | 150 | dev.wait_connected(timeout=15) |
8fba2e5d | 151 | |
715bf904 JM |
152 | def check_probe_resp(wt, bssid_unexpected, bssid_expected): |
153 | if bssid_unexpected: | |
154 | count = wt.get_bss_counter("probe_response", bssid_unexpected) | |
155 | if count > 0: | |
156 | raise Exception("Unexpected Probe Response frame from AP") | |
157 | ||
158 | if bssid_expected: | |
159 | count = wt.get_bss_counter("probe_response", bssid_expected) | |
160 | if count == 0: | |
161 | raise Exception("No Probe Response frame from AP") | |
162 | ||
2cdd91d8 JM |
163 | def test_ap_anqp_sharing(dev, apdev): |
164 | """ANQP sharing within ESS and explicit unshare""" | |
e7ac04ce | 165 | check_eap_capa(dev[0], "MSCHAPV2") |
57f08b3f JM |
166 | dev[0].flush_scan_cache() |
167 | ||
2cdd91d8 JM |
168 | bssid = apdev[0]['bssid'] |
169 | params = hs20_ap_params() | |
170 | params['hessid'] = bssid | |
171 | hostapd.add_ap(apdev[0]['ifname'], params) | |
172 | ||
173 | bssid2 = apdev[1]['bssid'] | |
174 | params = hs20_ap_params() | |
175 | params['hessid'] = bssid | |
176 | params['nai_realm'] = [ "0,example.com,13[5:6],21[2:4][5:7]" ] | |
177 | hostapd.add_ap(apdev[1]['ifname'], params) | |
178 | ||
2cdd91d8 JM |
179 | dev[0].hs20_enable() |
180 | id = dev[0].add_cred_values({ 'realm': "example.com", 'username': "test", | |
181 | 'password': "secret", | |
182 | 'domain': "example.com" }) | |
183 | logger.info("Normal network selection with shared ANQP results") | |
841bed04 JM |
184 | dev[0].scan_for_bss(bssid, freq="2412") |
185 | dev[0].scan_for_bss(bssid2, freq="2412") | |
2f37a66d | 186 | interworking_select(dev[0], None, "home", freq="2412") |
2cdd91d8 JM |
187 | dev[0].dump_monitor() |
188 | ||
57f08b3f | 189 | logger.debug("BSS entries:\n" + dev[0].request("BSS RANGE=ALL")) |
2cdd91d8 JM |
190 | res1 = dev[0].get_bss(bssid) |
191 | res2 = dev[0].get_bss(bssid2) | |
57f08b3f JM |
192 | if 'anqp_nai_realm' not in res1: |
193 | raise Exception("anqp_nai_realm not found for AP1") | |
194 | if 'anqp_nai_realm' not in res2: | |
195 | raise Exception("anqp_nai_realm not found for AP2") | |
2cdd91d8 JM |
196 | if res1['anqp_nai_realm'] != res2['anqp_nai_realm']: |
197 | raise Exception("ANQP results were not shared between BSSes") | |
198 | ||
199 | logger.info("Explicit ANQP request to unshare ANQP results") | |
200 | dev[0].request("ANQP_GET " + bssid + " 263") | |
201 | ev = dev[0].wait_event(["RX-ANQP"], timeout=5) | |
202 | if ev is None: | |
203 | raise Exception("ANQP operation timed out") | |
204 | ||
205 | dev[0].request("ANQP_GET " + bssid2 + " 263") | |
206 | ev = dev[0].wait_event(["RX-ANQP"], timeout=5) | |
207 | if ev is None: | |
208 | raise Exception("ANQP operation timed out") | |
209 | ||
210 | res1 = dev[0].get_bss(bssid) | |
211 | res2 = dev[0].get_bss(bssid2) | |
212 | if res1['anqp_nai_realm'] == res2['anqp_nai_realm']: | |
213 | raise Exception("ANQP results were not unshared") | |
214 | ||
cddc19e5 JM |
215 | def test_ap_nai_home_realm_query(dev, apdev): |
216 | """NAI Home Realm Query""" | |
e7ac04ce | 217 | check_eap_capa(dev[0], "MSCHAPV2") |
cddc19e5 JM |
218 | bssid = apdev[0]['bssid'] |
219 | params = hs20_ap_params() | |
220 | params['nai_realm'] = [ "0,example.com,13[5:6],21[2:4][5:7]", | |
221 | "0,another.example.org" ] | |
222 | hostapd.add_ap(apdev[0]['ifname'], params) | |
223 | ||
224 | dev[0].scan(freq="2412") | |
225 | dev[0].request("HS20_GET_NAI_HOME_REALM_LIST " + bssid + " realm=example.com") | |
226 | ev = dev[0].wait_event(["RX-ANQP"], timeout=5) | |
227 | if ev is None: | |
228 | raise Exception("ANQP operation timed out") | |
229 | nai1 = dev[0].get_bss(bssid)['anqp_nai_realm'] | |
230 | dev[0].dump_monitor() | |
231 | ||
232 | dev[0].request("ANQP_GET " + bssid + " 263") | |
233 | ev = dev[0].wait_event(["RX-ANQP"], timeout=5) | |
234 | if ev is None: | |
235 | raise Exception("ANQP operation timed out") | |
236 | nai2 = dev[0].get_bss(bssid)['anqp_nai_realm'] | |
237 | ||
238 | if len(nai1) >= len(nai2): | |
239 | raise Exception("Unexpected NAI Realm list response lengths") | |
240 | if "example.com".encode('hex') not in nai1: | |
241 | raise Exception("Home realm not reported") | |
242 | if "example.org".encode('hex') in nai1: | |
243 | raise Exception("Non-home realm reported") | |
244 | if "example.com".encode('hex') not in nai2: | |
245 | raise Exception("Home realm not reported in wildcard query") | |
246 | if "example.org".encode('hex') not in nai2: | |
247 | raise Exception("Non-home realm not reported in wildcard query ") | |
248 | ||
ea215c54 JM |
249 | cmds = [ "foo", |
250 | "00:11:22:33:44:55 123", | |
251 | "00:11:22:33:44:55 qq" ] | |
252 | for cmd in cmds: | |
253 | if "FAIL" not in dev[0].request("HS20_GET_NAI_HOME_REALM_LIST " + cmd): | |
254 | raise Exception("Invalid HS20_GET_NAI_HOME_REALM_LIST accepted: " + cmd) | |
255 | ||
256 | dev[0].dump_monitor() | |
257 | if "OK" not in dev[0].request("HS20_GET_NAI_HOME_REALM_LIST " + bssid): | |
258 | raise Exception("HS20_GET_NAI_HOME_REALM_LIST failed") | |
259 | ev = dev[0].wait_event(["GAS-QUERY-DONE"], timeout=10) | |
260 | if ev is None: | |
261 | raise Exception("ANQP operation timed out") | |
262 | ev = dev[0].wait_event(["RX-ANQP"], timeout=0.1) | |
263 | if ev is not None: | |
264 | raise Exception("Unexpected ANQP response: " + ev) | |
265 | ||
266 | dev[0].dump_monitor() | |
267 | if "OK" not in dev[0].request("HS20_GET_NAI_HOME_REALM_LIST " + bssid + " 01000b6578616d706c652e636f6d"): | |
268 | raise Exception("HS20_GET_NAI_HOME_REALM_LIST failed") | |
269 | ev = dev[0].wait_event(["RX-ANQP"], timeout=10) | |
270 | if ev is None: | |
271 | raise Exception("No ANQP response") | |
272 | if "NAI Realm list" not in ev: | |
273 | raise Exception("Missing NAI Realm list: " + ev) | |
274 | ||
275 | dev[0].add_cred_values({ 'realm': "example.com", 'username': "test", | |
276 | 'password': "secret", | |
277 | 'domain': "example.com" }) | |
278 | dev[0].dump_monitor() | |
279 | if "OK" not in dev[0].request("HS20_GET_NAI_HOME_REALM_LIST " + bssid): | |
280 | raise Exception("HS20_GET_NAI_HOME_REALM_LIST failed") | |
281 | ev = dev[0].wait_event(["RX-ANQP"], timeout=10) | |
282 | if ev is None: | |
283 | raise Exception("No ANQP response") | |
284 | if "NAI Realm list" not in ev: | |
285 | raise Exception("Missing NAI Realm list: " + ev) | |
286 | ||
715bf904 JM |
287 | def test_ap_interworking_scan_filtering(dev, apdev): |
288 | """Interworking scan filtering with HESSID and access network type""" | |
e4d7b513 | 289 | try: |
81e787b7 | 290 | _test_ap_interworking_scan_filtering(dev, apdev) |
e4d7b513 JM |
291 | finally: |
292 | dev[0].request("SET hessid 00:00:00:00:00:00") | |
293 | dev[0].request("SET access_network_type 15") | |
294 | ||
295 | def _test_ap_interworking_scan_filtering(dev, apdev): | |
715bf904 JM |
296 | bssid = apdev[0]['bssid'] |
297 | params = hs20_ap_params() | |
298 | ssid = "test-hs20-ap1" | |
299 | params['ssid'] = ssid | |
300 | params['hessid'] = bssid | |
301 | hostapd.add_ap(apdev[0]['ifname'], params) | |
302 | ||
303 | bssid2 = apdev[1]['bssid'] | |
304 | params = hs20_ap_params() | |
305 | ssid2 = "test-hs20-ap2" | |
306 | params['ssid'] = ssid2 | |
307 | params['hessid'] = bssid2 | |
308 | params['access_network_type'] = "1" | |
8175854e JM |
309 | del params['venue_group'] |
310 | del params['venue_type'] | |
715bf904 JM |
311 | hostapd.add_ap(apdev[1]['ifname'], params) |
312 | ||
715bf904 JM |
313 | dev[0].hs20_enable() |
314 | ||
315 | wt = Wlantest() | |
316 | wt.flush() | |
317 | ||
318 | logger.info("Check probe request filtering based on HESSID") | |
319 | ||
320 | dev[0].request("SET hessid " + bssid2) | |
0589f401 | 321 | dev[0].scan(freq="2412") |
94a2dd0b | 322 | time.sleep(0.03) |
715bf904 JM |
323 | check_probe_resp(wt, bssid, bssid2) |
324 | ||
325 | logger.info("Check probe request filtering based on access network type") | |
326 | ||
327 | wt.clear_bss_counters(bssid) | |
328 | wt.clear_bss_counters(bssid2) | |
329 | dev[0].request("SET hessid 00:00:00:00:00:00") | |
330 | dev[0].request("SET access_network_type 14") | |
0589f401 | 331 | dev[0].scan(freq="2412") |
94a2dd0b | 332 | time.sleep(0.03) |
715bf904 JM |
333 | check_probe_resp(wt, bssid2, bssid) |
334 | ||
335 | wt.clear_bss_counters(bssid) | |
336 | wt.clear_bss_counters(bssid2) | |
337 | dev[0].request("SET hessid 00:00:00:00:00:00") | |
338 | dev[0].request("SET access_network_type 1") | |
0589f401 | 339 | dev[0].scan(freq="2412") |
94a2dd0b | 340 | time.sleep(0.03) |
715bf904 JM |
341 | check_probe_resp(wt, bssid, bssid2) |
342 | ||
343 | logger.info("Check probe request filtering based on HESSID and ANT") | |
344 | ||
345 | wt.clear_bss_counters(bssid) | |
346 | wt.clear_bss_counters(bssid2) | |
347 | dev[0].request("SET hessid " + bssid) | |
348 | dev[0].request("SET access_network_type 14") | |
0589f401 | 349 | dev[0].scan(freq="2412") |
94a2dd0b | 350 | time.sleep(0.03) |
715bf904 JM |
351 | check_probe_resp(wt, bssid2, bssid) |
352 | ||
353 | wt.clear_bss_counters(bssid) | |
354 | wt.clear_bss_counters(bssid2) | |
355 | dev[0].request("SET hessid " + bssid2) | |
356 | dev[0].request("SET access_network_type 14") | |
0589f401 | 357 | dev[0].scan(freq="2412") |
94a2dd0b | 358 | time.sleep(0.03) |
715bf904 JM |
359 | check_probe_resp(wt, bssid, None) |
360 | check_probe_resp(wt, bssid2, None) | |
361 | ||
362 | wt.clear_bss_counters(bssid) | |
363 | wt.clear_bss_counters(bssid2) | |
364 | dev[0].request("SET hessid " + bssid) | |
365 | dev[0].request("SET access_network_type 1") | |
0589f401 | 366 | dev[0].scan(freq="2412") |
94a2dd0b | 367 | time.sleep(0.03) |
715bf904 JM |
368 | check_probe_resp(wt, bssid, None) |
369 | check_probe_resp(wt, bssid2, None) | |
370 | ||
bbe86767 JM |
371 | def test_ap_hs20_select(dev, apdev): |
372 | """Hotspot 2.0 network selection""" | |
373 | bssid = apdev[0]['bssid'] | |
374 | params = hs20_ap_params() | |
375 | params['hessid'] = bssid | |
376 | hostapd.add_ap(apdev[0]['ifname'], params) | |
377 | ||
378 | dev[0].hs20_enable() | |
2232edf8 JM |
379 | id = dev[0].add_cred_values({ 'realm': "example.com", 'username': "test", |
380 | 'password': "secret", | |
381 | 'domain': "example.com" }) | |
bbe86767 JM |
382 | interworking_select(dev[0], bssid, "home") |
383 | ||
384 | dev[0].remove_cred(id) | |
2232edf8 JM |
385 | id = dev[0].add_cred_values({ 'realm': "example.com", 'username': "test", |
386 | 'password': "secret", | |
387 | 'domain': "no.match.example.com" }) | |
2f37a66d | 388 | interworking_select(dev[0], bssid, "roaming", freq="2412") |
bbe86767 JM |
389 | |
390 | dev[0].set_cred_quoted(id, "realm", "no.match.example.com"); | |
2f37a66d | 391 | interworking_select(dev[0], bssid, no_match=True, freq="2412") |
bbe86767 | 392 | |
d463c556 JM |
393 | res = dev[0].request("SCAN_RESULTS") |
394 | if "[HS20]" not in res: | |
395 | raise Exception("HS20 flag missing from scan results: " + res) | |
396 | ||
4b572e3a JM |
397 | bssid2 = apdev[1]['bssid'] |
398 | params = hs20_ap_params() | |
399 | params['nai_realm'] = [ "0,example.org,21" ] | |
400 | params['hessid'] = bssid2 | |
401 | params['domain_name'] = "example.org" | |
402 | hostapd.add_ap(apdev[1]['ifname'], params) | |
403 | dev[0].remove_cred(id) | |
404 | id = dev[0].add_cred_values({ 'realm': "example.org", 'username': "test", | |
405 | 'password': "secret", | |
406 | 'domain': "example.org" }) | |
407 | interworking_select(dev[0], bssid2, "home", freq="2412") | |
408 | ||
459e96cd JM |
409 | def hs20_simulated_sim(dev, ap, method): |
410 | bssid = ap['bssid'] | |
411 | params = hs20_ap_params() | |
412 | params['hessid'] = bssid | |
413 | params['anqp_3gpp_cell_net'] = "555,444" | |
414 | params['domain_name'] = "wlan.mnc444.mcc555.3gppnetwork.org" | |
415 | hostapd.add_ap(ap['ifname'], params) | |
416 | ||
459e96cd JM |
417 | dev.hs20_enable() |
418 | dev.add_cred_values({ 'imsi': "555444-333222111", 'eap': method, | |
419 | 'milenage': "5122250214c33e723a5dd523fc145fc0:981d464c7c52eb6e5036234984ad0bcf:000000000123"}) | |
2f37a66d | 420 | interworking_select(dev, "home", freq="2412") |
459e96cd JM |
421 | interworking_connect(dev, bssid, method) |
422 | check_sp_type(dev, "home") | |
423 | ||
424 | def test_ap_hs20_sim(dev, apdev): | |
425 | """Hotspot 2.0 with simulated SIM and EAP-SIM""" | |
81e787b7 | 426 | hlr_auc_gw_available() |
459e96cd | 427 | hs20_simulated_sim(dev[0], apdev[0], "SIM") |
16ab63f4 JM |
428 | dev[0].request("INTERWORKING_SELECT auto freq=2412") |
429 | ev = dev[0].wait_event(["INTERWORKING-ALREADY-CONNECTED"], timeout=15) | |
430 | if ev is None: | |
431 | raise Exception("Timeout on already-connected event") | |
459e96cd JM |
432 | |
433 | def test_ap_hs20_aka(dev, apdev): | |
434 | """Hotspot 2.0 with simulated USIM and EAP-AKA""" | |
81e787b7 | 435 | hlr_auc_gw_available() |
459e96cd JM |
436 | hs20_simulated_sim(dev[0], apdev[0], "AKA") |
437 | ||
438 | def test_ap_hs20_aka_prime(dev, apdev): | |
439 | """Hotspot 2.0 with simulated USIM and EAP-AKA'""" | |
81e787b7 | 440 | hlr_auc_gw_available() |
459e96cd JM |
441 | hs20_simulated_sim(dev[0], apdev[0], "AKA'") |
442 | ||
bbe86767 JM |
443 | def test_ap_hs20_ext_sim(dev, apdev): |
444 | """Hotspot 2.0 with external SIM processing""" | |
81e787b7 | 445 | hlr_auc_gw_available() |
bbe86767 JM |
446 | bssid = apdev[0]['bssid'] |
447 | params = hs20_ap_params() | |
448 | params['hessid'] = bssid | |
449 | params['anqp_3gpp_cell_net'] = "232,01" | |
450 | params['domain_name'] = "wlan.mnc001.mcc232.3gppnetwork.org" | |
451 | hostapd.add_ap(apdev[0]['ifname'], params) | |
452 | ||
453 | dev[0].hs20_enable() | |
47dcb118 JM |
454 | try: |
455 | dev[0].request("SET external_sim 1") | |
456 | dev[0].add_cred_values({ 'imsi': "23201-0000000000", 'eap': "SIM" }) | |
457 | interworking_select(dev[0], "home", freq="2412") | |
458 | interworking_ext_sim_connect(dev[0], bssid, "SIM") | |
459 | check_sp_type(dev[0], "home") | |
460 | finally: | |
461 | dev[0].request("SET external_sim 0") | |
59f8a3c6 JM |
462 | |
463 | def test_ap_hs20_ext_sim_roaming(dev, apdev): | |
464 | """Hotspot 2.0 with external SIM processing in roaming network""" | |
81e787b7 | 465 | hlr_auc_gw_available() |
59f8a3c6 JM |
466 | bssid = apdev[0]['bssid'] |
467 | params = hs20_ap_params() | |
468 | params['hessid'] = bssid | |
469 | params['anqp_3gpp_cell_net'] = "244,91;310,026;232,01;234,56" | |
470 | params['domain_name'] = "wlan.mnc091.mcc244.3gppnetwork.org" | |
471 | hostapd.add_ap(apdev[0]['ifname'], params) | |
472 | ||
473 | dev[0].hs20_enable() | |
47dcb118 JM |
474 | try: |
475 | dev[0].request("SET external_sim 1") | |
476 | dev[0].add_cred_values({ 'imsi': "23201-0000000000", 'eap': "SIM" }) | |
477 | interworking_select(dev[0], "roaming", freq="2412") | |
478 | interworking_ext_sim_connect(dev[0], bssid, "SIM") | |
479 | check_sp_type(dev[0], "roaming") | |
480 | finally: | |
481 | dev[0].request("SET external_sim 0") | |
8fba2e5d JM |
482 | |
483 | def test_ap_hs20_username(dev, apdev): | |
484 | """Hotspot 2.0 connection in username/password credential""" | |
e7ac04ce | 485 | check_eap_capa(dev[0], "MSCHAPV2") |
8fba2e5d JM |
486 | bssid = apdev[0]['bssid'] |
487 | params = hs20_ap_params() | |
488 | params['hessid'] = bssid | |
d627e131 | 489 | params['disable_dgaf'] = '1' |
8fba2e5d JM |
490 | hostapd.add_ap(apdev[0]['ifname'], params) |
491 | ||
492 | dev[0].hs20_enable() | |
2232edf8 JM |
493 | id = dev[0].add_cred_values({ 'realm': "example.com", |
494 | 'username': "hs20-test", | |
495 | 'password': "password", | |
a1281b9f | 496 | 'ca_cert': "auth_serv/ca.pem", |
5f1e31cf JM |
497 | 'domain': "example.com", |
498 | 'update_identifier': "1234" }) | |
2f37a66d | 499 | interworking_select(dev[0], bssid, "home", freq="2412") |
8fba2e5d JM |
500 | interworking_connect(dev[0], bssid, "TTLS") |
501 | check_sp_type(dev[0], "home") | |
10b3cc67 JM |
502 | status = dev[0].get_status() |
503 | if status['pairwise_cipher'] != "CCMP": | |
504 | raise Exception("Unexpected pairwise cipher") | |
505 | if status['hs20'] != "2": | |
506 | raise Exception("Unexpected HS 2.0 support indication") | |
8fba2e5d | 507 | |
a1281b9f JM |
508 | dev[1].connect("test-hs20", key_mgmt="WPA-EAP", eap="TTLS", |
509 | identity="hs20-test", password="password", | |
510 | ca_cert="auth_serv/ca.pem", phase2="auth=MSCHAPV2", | |
511 | scan_freq="2412") | |
512 | ||
1e780974 JM |
513 | def test_ap_hs20_connect_api(dev, apdev): |
514 | """Hotspot 2.0 connection with connect API""" | |
e7ac04ce | 515 | check_eap_capa(dev[0], "MSCHAPV2") |
1e780974 JM |
516 | bssid = apdev[0]['bssid'] |
517 | params = hs20_ap_params() | |
518 | params['hessid'] = bssid | |
519 | params['disable_dgaf'] = '1' | |
520 | hostapd.add_ap(apdev[0]['ifname'], params) | |
521 | ||
522 | wpas = WpaSupplicant(global_iface='/tmp/wpas-wlan5') | |
523 | wpas.interface_add("wlan5", drv_params="force_connect_cmd=1") | |
524 | wpas.hs20_enable() | |
243dcc4a | 525 | wpas.flush_scan_cache() |
1e780974 JM |
526 | id = wpas.add_cred_values({ 'realm': "example.com", |
527 | 'username': "hs20-test", | |
528 | 'password': "password", | |
529 | 'ca_cert': "auth_serv/ca.pem", | |
530 | 'domain': "example.com", | |
531 | 'update_identifier': "1234" }) | |
532 | interworking_select(wpas, bssid, "home", freq="2412") | |
533 | interworking_connect(wpas, bssid, "TTLS") | |
534 | check_sp_type(wpas, "home") | |
535 | status = wpas.get_status() | |
536 | if status['pairwise_cipher'] != "CCMP": | |
537 | raise Exception("Unexpected pairwise cipher") | |
538 | if status['hs20'] != "2": | |
539 | raise Exception("Unexpected HS 2.0 support indication") | |
540 | ||
543f9f7e JM |
541 | def test_ap_hs20_auto_interworking(dev, apdev): |
542 | """Hotspot 2.0 connection with auto_interworking=1""" | |
e7ac04ce | 543 | check_eap_capa(dev[0], "MSCHAPV2") |
543f9f7e JM |
544 | bssid = apdev[0]['bssid'] |
545 | params = hs20_ap_params() | |
546 | params['hessid'] = bssid | |
547 | params['disable_dgaf'] = '1' | |
548 | hostapd.add_ap(apdev[0]['ifname'], params) | |
549 | ||
550 | dev[0].hs20_enable(auto_interworking=True) | |
551 | id = dev[0].add_cred_values({ 'realm': "example.com", | |
552 | 'username': "hs20-test", | |
553 | 'password': "password", | |
554 | 'ca_cert': "auth_serv/ca.pem", | |
555 | 'domain': "example.com", | |
556 | 'update_identifier': "1234" }) | |
557 | dev[0].request("REASSOCIATE") | |
5f35a5e2 | 558 | dev[0].wait_connected(timeout=15) |
543f9f7e JM |
559 | check_sp_type(dev[0], "home") |
560 | status = dev[0].get_status() | |
561 | if status['pairwise_cipher'] != "CCMP": | |
562 | raise Exception("Unexpected pairwise cipher") | |
563 | if status['hs20'] != "2": | |
564 | raise Exception("Unexpected HS 2.0 support indication") | |
565 | ||
e912e4bc JM |
566 | def test_ap_hs20_auto_interworking_no_match(dev, apdev): |
567 | """Hotspot 2.0 connection with auto_interworking=1 and no matching network""" | |
568 | hapd = hostapd.add_ap(apdev[0]['ifname'], { "ssid": "mismatch" }) | |
569 | ||
570 | dev[0].hs20_enable(auto_interworking=True) | |
571 | id = dev[0].connect("mismatch", psk="12345678", scan_freq="2412", | |
572 | only_add_network=True) | |
573 | dev[0].request("ENABLE_NETWORK " + str(id) + " no-connect") | |
574 | ||
575 | id = dev[0].add_cred_values({ 'realm': "example.com", | |
576 | 'username': "hs20-test", | |
577 | 'password': "password", | |
578 | 'ca_cert': "auth_serv/ca.pem", | |
579 | 'domain': "example.com", | |
580 | 'update_identifier': "1234" }) | |
581 | dev[0].request("INTERWORKING_SELECT auto freq=2412") | |
582 | time.sleep(0.1) | |
583 | dev[0].dump_monitor() | |
584 | for i in range(5): | |
585 | logger.info("start ping") | |
586 | if "PONG" not in dev[0].ctrl.request("PING", timeout=2): | |
587 | raise Exception("PING failed") | |
588 | logger.info("ping done") | |
589 | fetch = 0 | |
590 | scan = 0 | |
591 | for j in range(15): | |
592 | ev = dev[0].wait_event([ "ANQP fetch completed", | |
593 | "CTRL-EVENT-SCAN-RESULTS" ], timeout=0.05) | |
594 | if ev is None: | |
595 | break | |
596 | if "ANQP fetch completed" in ev: | |
597 | fetch += 1 | |
598 | else: | |
599 | scan += 1 | |
600 | if fetch > 2 * scan + 3: | |
601 | raise Exception("Too many ANQP fetch iterations") | |
602 | dev[0].dump_monitor() | |
603 | dev[0].request("DISCONNECT") | |
604 | ||
bedb6ea5 JM |
605 | def test_ap_hs20_auto_interworking_no_cred_match(dev, apdev): |
606 | """Hotspot 2.0 connection with auto_interworking=1 but no cred match""" | |
607 | bssid = apdev[0]['bssid'] | |
608 | params = { "ssid": "test" } | |
609 | hostapd.add_ap(apdev[0]['ifname'], params) | |
610 | ||
611 | dev[0].hs20_enable(auto_interworking=True) | |
612 | dev[0].add_cred_values({ 'realm': "example.com", | |
613 | 'username': "hs20-test", | |
614 | 'password': "password", | |
615 | 'ca_cert': "auth_serv/ca.pem", | |
616 | 'domain': "example.com" }) | |
617 | ||
618 | id = dev[0].connect("test", psk="12345678", only_add_network=True) | |
619 | dev[0].request("ENABLE_NETWORK %s" % id) | |
620 | logger.info("Verify that scanning continues when there is partial network block match") | |
621 | for i in range(0, 2): | |
622 | ev = dev[0].wait_event(["CTRL-EVENT-SCAN-RESULTS"], 10) | |
623 | if ev is None: | |
624 | raise Exception("Scan timed out") | |
625 | logger.info("Scan completed") | |
626 | ||
dcd68168 JM |
627 | def eap_test(dev, ap, eap_params, method, user): |
628 | bssid = ap['bssid'] | |
629 | params = hs20_ap_params() | |
630 | params['nai_realm'] = [ "0,example.com," + eap_params ] | |
631 | hostapd.add_ap(ap['ifname'], params) | |
632 | ||
dcd68168 JM |
633 | dev.hs20_enable() |
634 | dev.add_cred_values({ 'realm': "example.com", | |
524c6c33 | 635 | 'ca_cert': "auth_serv/ca.pem", |
dcd68168 JM |
636 | 'username': user, |
637 | 'password': "password" }) | |
2f37a66d | 638 | interworking_select(dev, bssid, freq="2412") |
dcd68168 JM |
639 | interworking_connect(dev, bssid, method) |
640 | ||
932be82c JM |
641 | def test_ap_hs20_eap_unknown(dev, apdev): |
642 | """Hotspot 2.0 connection with unknown EAP method""" | |
643 | bssid = apdev[0]['bssid'] | |
644 | params = hs20_ap_params() | |
645 | params['nai_realm'] = "0,example.com,99" | |
646 | hostapd.add_ap(apdev[0]['ifname'], params) | |
647 | ||
648 | dev[0].hs20_enable() | |
649 | dev[0].add_cred_values(default_cred()) | |
650 | interworking_select(dev[0], None, no_match=True, freq="2412") | |
651 | ||
dcd68168 JM |
652 | def test_ap_hs20_eap_peap_mschapv2(dev, apdev): |
653 | """Hotspot 2.0 connection with PEAP/MSCHAPV2""" | |
e7ac04ce | 654 | check_eap_capa(dev[0], "MSCHAPV2") |
dcd68168 JM |
655 | eap_test(dev[0], apdev[0], "25[3:26]", "PEAP", "user") |
656 | ||
932be82c JM |
657 | def test_ap_hs20_eap_peap_default(dev, apdev): |
658 | """Hotspot 2.0 connection with PEAP/MSCHAPV2 (as default)""" | |
e7ac04ce | 659 | check_eap_capa(dev[0], "MSCHAPV2") |
932be82c JM |
660 | eap_test(dev[0], apdev[0], "25", "PEAP", "user") |
661 | ||
dcd68168 JM |
662 | def test_ap_hs20_eap_peap_gtc(dev, apdev): |
663 | """Hotspot 2.0 connection with PEAP/GTC""" | |
664 | eap_test(dev[0], apdev[0], "25[3:6]", "PEAP", "user") | |
665 | ||
932be82c JM |
666 | def test_ap_hs20_eap_peap_unknown(dev, apdev): |
667 | """Hotspot 2.0 connection with PEAP/unknown""" | |
668 | bssid = apdev[0]['bssid'] | |
669 | params = hs20_ap_params() | |
670 | params['nai_realm'] = "0,example.com,25[3:99]" | |
671 | hostapd.add_ap(apdev[0]['ifname'], params) | |
672 | ||
673 | dev[0].hs20_enable() | |
674 | dev[0].add_cred_values(default_cred()) | |
675 | interworking_select(dev[0], None, no_match=True, freq="2412") | |
676 | ||
dcd68168 JM |
677 | def test_ap_hs20_eap_ttls_chap(dev, apdev): |
678 | """Hotspot 2.0 connection with TTLS/CHAP""" | |
ca158ea6 | 679 | skip_with_fips(dev[0]) |
dcd68168 JM |
680 | eap_test(dev[0], apdev[0], "21[2:2]", "TTLS", "chap user") |
681 | ||
682 | def test_ap_hs20_eap_ttls_mschap(dev, apdev): | |
683 | """Hotspot 2.0 connection with TTLS/MSCHAP""" | |
ca158ea6 | 684 | skip_with_fips(dev[0]) |
dcd68168 JM |
685 | eap_test(dev[0], apdev[0], "21[2:3]", "TTLS", "mschap user") |
686 | ||
687 | def test_ap_hs20_eap_ttls_eap_mschapv2(dev, apdev): | |
688 | """Hotspot 2.0 connection with TTLS/EAP-MSCHAPv2""" | |
e7ac04ce | 689 | check_eap_capa(dev[0], "MSCHAPV2") |
932be82c JM |
690 | eap_test(dev[0], apdev[0], "21[3:26][6:7][99:99]", "TTLS", "user") |
691 | ||
692 | def test_ap_hs20_eap_ttls_eap_unknown(dev, apdev): | |
693 | """Hotspot 2.0 connection with TTLS/EAP-unknown""" | |
694 | bssid = apdev[0]['bssid'] | |
695 | params = hs20_ap_params() | |
696 | params['nai_realm'] = "0,example.com,21[3:99]" | |
697 | hostapd.add_ap(apdev[0]['ifname'], params) | |
698 | ||
699 | dev[0].hs20_enable() | |
700 | dev[0].add_cred_values(default_cred()) | |
701 | interworking_select(dev[0], None, no_match=True, freq="2412") | |
702 | ||
703 | def test_ap_hs20_eap_ttls_eap_unsupported(dev, apdev): | |
704 | """Hotspot 2.0 connection with TTLS/EAP-OTP(unsupported)""" | |
705 | bssid = apdev[0]['bssid'] | |
706 | params = hs20_ap_params() | |
707 | params['nai_realm'] = "0,example.com,21[3:5]" | |
708 | hostapd.add_ap(apdev[0]['ifname'], params) | |
709 | ||
710 | dev[0].hs20_enable() | |
711 | dev[0].add_cred_values(default_cred()) | |
712 | interworking_select(dev[0], None, no_match=True, freq="2412") | |
713 | ||
714 | def test_ap_hs20_eap_ttls_unknown(dev, apdev): | |
715 | """Hotspot 2.0 connection with TTLS/unknown""" | |
716 | bssid = apdev[0]['bssid'] | |
717 | params = hs20_ap_params() | |
718 | params['nai_realm'] = "0,example.com,21[2:5]" | |
719 | hostapd.add_ap(apdev[0]['ifname'], params) | |
720 | ||
721 | dev[0].hs20_enable() | |
722 | dev[0].add_cred_values(default_cred()) | |
723 | interworking_select(dev[0], None, no_match=True, freq="2412") | |
dcd68168 JM |
724 | |
725 | def test_ap_hs20_eap_fast_mschapv2(dev, apdev): | |
726 | """Hotspot 2.0 connection with FAST/EAP-MSCHAPV2""" | |
3b51cc63 | 727 | check_eap_capa(dev[0], "FAST") |
dcd68168 JM |
728 | eap_test(dev[0], apdev[0], "43[3:26]", "FAST", "user") |
729 | ||
730 | def test_ap_hs20_eap_fast_gtc(dev, apdev): | |
731 | """Hotspot 2.0 connection with FAST/EAP-GTC""" | |
3b51cc63 | 732 | check_eap_capa(dev[0], "FAST") |
dcd68168 JM |
733 | eap_test(dev[0], apdev[0], "43[3:6]", "FAST", "user") |
734 | ||
735 | def test_ap_hs20_eap_tls(dev, apdev): | |
736 | """Hotspot 2.0 connection with EAP-TLS""" | |
737 | bssid = apdev[0]['bssid'] | |
738 | params = hs20_ap_params() | |
739 | params['nai_realm'] = [ "0,example.com,13[5:6]" ] | |
740 | hostapd.add_ap(apdev[0]['ifname'], params) | |
741 | ||
dcd68168 JM |
742 | dev[0].hs20_enable() |
743 | dev[0].add_cred_values({ 'realm': "example.com", | |
744 | 'username': "certificate-user", | |
745 | 'ca_cert': "auth_serv/ca.pem", | |
746 | 'client_cert': "auth_serv/user.pem", | |
747 | 'private_key': "auth_serv/user.key"}) | |
2f37a66d | 748 | interworking_select(dev[0], bssid, freq="2412") |
dcd68168 JM |
749 | interworking_connect(dev[0], bssid, "TLS") |
750 | ||
932be82c JM |
751 | def test_ap_hs20_eap_cert_unknown(dev, apdev): |
752 | """Hotspot 2.0 connection with certificate, but unknown EAP method""" | |
753 | bssid = apdev[0]['bssid'] | |
754 | params = hs20_ap_params() | |
755 | params['nai_realm'] = [ "0,example.com,99[5:6]" ] | |
756 | hostapd.add_ap(apdev[0]['ifname'], params) | |
757 | ||
758 | dev[0].hs20_enable() | |
759 | dev[0].add_cred_values({ 'realm': "example.com", | |
760 | 'username': "certificate-user", | |
761 | 'ca_cert': "auth_serv/ca.pem", | |
762 | 'client_cert': "auth_serv/user.pem", | |
763 | 'private_key': "auth_serv/user.key"}) | |
764 | interworking_select(dev[0], None, no_match=True, freq="2412") | |
765 | ||
766 | def test_ap_hs20_eap_cert_unsupported(dev, apdev): | |
767 | """Hotspot 2.0 connection with certificate, but unsupported TTLS""" | |
768 | bssid = apdev[0]['bssid'] | |
769 | params = hs20_ap_params() | |
770 | params['nai_realm'] = [ "0,example.com,21[5:6]" ] | |
771 | hostapd.add_ap(apdev[0]['ifname'], params) | |
772 | ||
773 | dev[0].hs20_enable() | |
774 | dev[0].add_cred_values({ 'realm': "example.com", | |
775 | 'username': "certificate-user", | |
776 | 'ca_cert': "auth_serv/ca.pem", | |
777 | 'client_cert': "auth_serv/user.pem", | |
778 | 'private_key': "auth_serv/user.key"}) | |
779 | interworking_select(dev[0], None, no_match=True, freq="2412") | |
780 | ||
781 | def test_ap_hs20_eap_invalid_cred(dev, apdev): | |
782 | """Hotspot 2.0 connection with invalid cred configuration""" | |
783 | bssid = apdev[0]['bssid'] | |
784 | params = hs20_ap_params() | |
785 | hostapd.add_ap(apdev[0]['ifname'], params) | |
786 | ||
787 | dev[0].hs20_enable() | |
788 | dev[0].add_cred_values({ 'realm': "example.com", | |
789 | 'username': "certificate-user", | |
790 | 'client_cert': "auth_serv/user.pem" }) | |
791 | interworking_select(dev[0], None, no_match=True, freq="2412") | |
792 | ||
0aca5d13 JM |
793 | def test_ap_hs20_nai_realms(dev, apdev): |
794 | """Hotspot 2.0 connection and multiple NAI realms and TTLS/PAP""" | |
795 | bssid = apdev[0]['bssid'] | |
796 | params = hs20_ap_params() | |
797 | params['hessid'] = bssid | |
798 | params['nai_realm'] = [ "0,no.match.here;example.com;no.match.here.either,21[2:1][5:7]" ] | |
799 | hostapd.add_ap(apdev[0]['ifname'], params) | |
800 | ||
0aca5d13 JM |
801 | dev[0].hs20_enable() |
802 | id = dev[0].add_cred_values({ 'realm': "example.com", | |
524c6c33 | 803 | 'ca_cert': "auth_serv/ca.pem", |
0aca5d13 JM |
804 | 'username': "pap user", |
805 | 'password': "password", | |
806 | 'domain': "example.com" }) | |
2f37a66d | 807 | interworking_select(dev[0], bssid, "home", freq="2412") |
0aca5d13 JM |
808 | interworking_connect(dev[0], bssid, "TTLS") |
809 | check_sp_type(dev[0], "home") | |
810 | ||
e209eb98 JM |
811 | def test_ap_hs20_roaming_consortium(dev, apdev): |
812 | """Hotspot 2.0 connection based on roaming consortium match""" | |
813 | bssid = apdev[0]['bssid'] | |
814 | params = hs20_ap_params() | |
815 | params['hessid'] = bssid | |
816 | hostapd.add_ap(apdev[0]['ifname'], params) | |
817 | ||
e209eb98 | 818 | dev[0].hs20_enable() |
80584122 JM |
819 | for consortium in [ "112233", "1020304050", "010203040506", "fedcba" ]: |
820 | id = dev[0].add_cred_values({ 'username': "user", | |
821 | 'password': "password", | |
822 | 'domain': "example.com", | |
524c6c33 | 823 | 'ca_cert': "auth_serv/ca.pem", |
80584122 JM |
824 | 'roaming_consortium': consortium, |
825 | 'eap': "PEAP" }) | |
826 | interworking_select(dev[0], bssid, "home", freq="2412") | |
827 | interworking_connect(dev[0], bssid, "PEAP") | |
828 | check_sp_type(dev[0], "home") | |
829 | dev[0].request("INTERWORKING_SELECT auto freq=2412") | |
830 | ev = dev[0].wait_event(["INTERWORKING-ALREADY-CONNECTED"], timeout=15) | |
831 | if ev is None: | |
832 | raise Exception("Timeout on already-connected event") | |
833 | dev[0].remove_cred(id) | |
e209eb98 | 834 | |
8fba2e5d JM |
835 | def test_ap_hs20_username_roaming(dev, apdev): |
836 | """Hotspot 2.0 connection in username/password credential (roaming)""" | |
e7ac04ce | 837 | check_eap_capa(dev[0], "MSCHAPV2") |
8fba2e5d JM |
838 | bssid = apdev[0]['bssid'] |
839 | params = hs20_ap_params() | |
840 | params['nai_realm'] = [ "0,example.com,13[5:6],21[2:4][5:7]", | |
841 | "0,roaming.example.com,21[2:4][5:7]", | |
842 | "0,another.example.com" ] | |
843 | params['domain_name'] = "another.example.com" | |
844 | params['hessid'] = bssid | |
845 | hostapd.add_ap(apdev[0]['ifname'], params) | |
846 | ||
847 | dev[0].hs20_enable() | |
2232edf8 JM |
848 | id = dev[0].add_cred_values({ 'realm': "roaming.example.com", |
849 | 'username': "hs20-test", | |
850 | 'password': "password", | |
524c6c33 | 851 | 'ca_cert': "auth_serv/ca.pem", |
2232edf8 | 852 | 'domain': "example.com" }) |
2f37a66d | 853 | interworking_select(dev[0], bssid, "roaming", freq="2412") |
8fba2e5d JM |
854 | interworking_connect(dev[0], bssid, "TTLS") |
855 | check_sp_type(dev[0], "roaming") | |
856 | ||
857 | def test_ap_hs20_username_unknown(dev, apdev): | |
858 | """Hotspot 2.0 connection in username/password credential (no domain in cred)""" | |
e7ac04ce | 859 | check_eap_capa(dev[0], "MSCHAPV2") |
8fba2e5d JM |
860 | bssid = apdev[0]['bssid'] |
861 | params = hs20_ap_params() | |
862 | params['hessid'] = bssid | |
863 | hostapd.add_ap(apdev[0]['ifname'], params) | |
864 | ||
865 | dev[0].hs20_enable() | |
2232edf8 | 866 | id = dev[0].add_cred_values({ 'realm': "example.com", |
524c6c33 | 867 | 'ca_cert': "auth_serv/ca.pem", |
2232edf8 JM |
868 | 'username': "hs20-test", |
869 | 'password': "password" }) | |
2f37a66d | 870 | interworking_select(dev[0], bssid, "unknown", freq="2412") |
8fba2e5d JM |
871 | interworking_connect(dev[0], bssid, "TTLS") |
872 | check_sp_type(dev[0], "unknown") | |
873 | ||
874 | def test_ap_hs20_username_unknown2(dev, apdev): | |
875 | """Hotspot 2.0 connection in username/password credential (no domain advertized)""" | |
e7ac04ce | 876 | check_eap_capa(dev[0], "MSCHAPV2") |
8fba2e5d JM |
877 | bssid = apdev[0]['bssid'] |
878 | params = hs20_ap_params() | |
879 | params['hessid'] = bssid | |
880 | del params['domain_name'] | |
881 | hostapd.add_ap(apdev[0]['ifname'], params) | |
882 | ||
883 | dev[0].hs20_enable() | |
2232edf8 | 884 | id = dev[0].add_cred_values({ 'realm': "example.com", |
524c6c33 | 885 | 'ca_cert': "auth_serv/ca.pem", |
2232edf8 JM |
886 | 'username': "hs20-test", |
887 | 'password': "password", | |
888 | 'domain': "example.com" }) | |
2f37a66d | 889 | interworking_select(dev[0], bssid, "unknown", freq="2412") |
8fba2e5d JM |
890 | interworking_connect(dev[0], bssid, "TTLS") |
891 | check_sp_type(dev[0], "unknown") | |
d1ba402f | 892 | |
483691bd JM |
893 | def test_ap_hs20_gas_while_associated(dev, apdev): |
894 | """Hotspot 2.0 connection with GAS query while associated""" | |
e7ac04ce | 895 | check_eap_capa(dev[0], "MSCHAPV2") |
483691bd JM |
896 | bssid = apdev[0]['bssid'] |
897 | params = hs20_ap_params() | |
898 | params['hessid'] = bssid | |
899 | hostapd.add_ap(apdev[0]['ifname'], params) | |
900 | ||
483691bd JM |
901 | dev[0].hs20_enable() |
902 | id = dev[0].add_cred_values({ 'realm': "example.com", | |
524c6c33 | 903 | 'ca_cert': "auth_serv/ca.pem", |
483691bd JM |
904 | 'username': "hs20-test", |
905 | 'password': "password", | |
906 | 'domain': "example.com" }) | |
2f37a66d | 907 | interworking_select(dev[0], bssid, "home", freq="2412") |
483691bd JM |
908 | interworking_connect(dev[0], bssid, "TTLS") |
909 | ||
910 | logger.info("Verifying GAS query while associated") | |
911 | dev[0].request("FETCH_ANQP") | |
912 | for i in range(0, 6): | |
913 | ev = dev[0].wait_event(["RX-ANQP"], timeout=5) | |
914 | if ev is None: | |
915 | raise Exception("Operation timed out") | |
916 | ||
ee2caef3 JM |
917 | def test_ap_hs20_gas_while_associated_with_pmf(dev, apdev): |
918 | """Hotspot 2.0 connection with GAS query while associated and using PMF""" | |
e7ac04ce | 919 | check_eap_capa(dev[0], "MSCHAPV2") |
909f13cc JM |
920 | try: |
921 | _test_ap_hs20_gas_while_associated_with_pmf(dev, apdev) | |
922 | finally: | |
923 | dev[0].request("SET pmf 0") | |
924 | ||
925 | def _test_ap_hs20_gas_while_associated_with_pmf(dev, apdev): | |
ee2caef3 JM |
926 | bssid = apdev[0]['bssid'] |
927 | params = hs20_ap_params() | |
928 | params['hessid'] = bssid | |
929 | hostapd.add_ap(apdev[0]['ifname'], params) | |
930 | ||
931 | bssid2 = apdev[1]['bssid'] | |
932 | params = hs20_ap_params() | |
933 | params['hessid'] = bssid2 | |
934 | params['nai_realm'] = [ "0,no-match.example.org,13[5:6],21[2:4][5:7]" ] | |
935 | hostapd.add_ap(apdev[1]['ifname'], params) | |
936 | ||
937 | dev[0].hs20_enable() | |
938 | dev[0].request("SET pmf 2") | |
939 | id = dev[0].add_cred_values({ 'realm': "example.com", | |
524c6c33 | 940 | 'ca_cert': "auth_serv/ca.pem", |
ee2caef3 JM |
941 | 'username': "hs20-test", |
942 | 'password': "password", | |
943 | 'domain': "example.com" }) | |
944 | interworking_select(dev[0], bssid, "home", freq="2412") | |
945 | interworking_connect(dev[0], bssid, "TTLS") | |
946 | ||
947 | logger.info("Verifying GAS query while associated") | |
948 | dev[0].request("FETCH_ANQP") | |
949 | for i in range(0, 2 * 6): | |
950 | ev = dev[0].wait_event(["RX-ANQP"], timeout=5) | |
951 | if ev is None: | |
952 | raise Exception("Operation timed out") | |
953 | ||
483691bd JM |
954 | def test_ap_hs20_gas_frag_while_associated(dev, apdev): |
955 | """Hotspot 2.0 connection with fragmented GAS query while associated""" | |
e7ac04ce | 956 | check_eap_capa(dev[0], "MSCHAPV2") |
483691bd JM |
957 | bssid = apdev[0]['bssid'] |
958 | params = hs20_ap_params() | |
959 | params['hessid'] = bssid | |
960 | hostapd.add_ap(apdev[0]['ifname'], params) | |
961 | hapd = hostapd.Hostapd(apdev[0]['ifname']) | |
962 | hapd.set("gas_frag_limit", "50") | |
963 | ||
483691bd JM |
964 | dev[0].hs20_enable() |
965 | id = dev[0].add_cred_values({ 'realm': "example.com", | |
524c6c33 | 966 | 'ca_cert': "auth_serv/ca.pem", |
483691bd JM |
967 | 'username': "hs20-test", |
968 | 'password': "password", | |
969 | 'domain': "example.com" }) | |
2f37a66d | 970 | interworking_select(dev[0], bssid, "home", freq="2412") |
483691bd JM |
971 | interworking_connect(dev[0], bssid, "TTLS") |
972 | ||
973 | logger.info("Verifying GAS query while associated") | |
974 | dev[0].request("FETCH_ANQP") | |
975 | for i in range(0, 6): | |
976 | ev = dev[0].wait_event(["RX-ANQP"], timeout=5) | |
977 | if ev is None: | |
978 | raise Exception("Operation timed out") | |
979 | ||
6a0b4002 JM |
980 | def test_ap_hs20_multiple_connects(dev, apdev): |
981 | """Hotspot 2.0 connection through multiple network selections""" | |
e7ac04ce | 982 | check_eap_capa(dev[0], "MSCHAPV2") |
6a0b4002 JM |
983 | bssid = apdev[0]['bssid'] |
984 | params = hs20_ap_params() | |
985 | params['hessid'] = bssid | |
986 | hostapd.add_ap(apdev[0]['ifname'], params) | |
987 | ||
988 | dev[0].hs20_enable() | |
989 | values = { 'realm': "example.com", | |
524c6c33 | 990 | 'ca_cert': "auth_serv/ca.pem", |
6a0b4002 JM |
991 | 'username': "hs20-test", |
992 | 'password': "password", | |
993 | 'domain': "example.com" } | |
994 | id = dev[0].add_cred_values(values) | |
995 | ||
841bed04 JM |
996 | dev[0].scan_for_bss(bssid, freq="2412") |
997 | ||
6a0b4002 JM |
998 | for i in range(0, 3): |
999 | logger.info("Starting Interworking network selection") | |
2f37a66d | 1000 | dev[0].request("INTERWORKING_SELECT auto freq=2412") |
6a0b4002 JM |
1001 | while True: |
1002 | ev = dev[0].wait_event(["INTERWORKING-NO-MATCH", | |
1003 | "INTERWORKING-ALREADY-CONNECTED", | |
1004 | "CTRL-EVENT-CONNECTED"], timeout=15) | |
1005 | if ev is None: | |
1006 | raise Exception("Connection timed out") | |
1007 | if "INTERWORKING-NO-MATCH" in ev: | |
1008 | raise Exception("Matching AP not found") | |
1009 | if "CTRL-EVENT-CONNECTED" in ev: | |
1010 | break | |
1011 | if i == 2 and "INTERWORKING-ALREADY-CONNECTED" in ev: | |
1012 | break | |
1013 | if i == 0: | |
1014 | dev[0].request("DISCONNECT") | |
1015 | dev[0].dump_monitor() | |
1016 | ||
1017 | networks = dev[0].list_networks() | |
1018 | if len(networks) > 1: | |
1019 | raise Exception("Duplicated network block detected") | |
1020 | ||
b4264f8f JM |
1021 | def test_ap_hs20_disallow_aps(dev, apdev): |
1022 | """Hotspot 2.0 connection and disallow_aps""" | |
1023 | bssid = apdev[0]['bssid'] | |
1024 | params = hs20_ap_params() | |
1025 | params['hessid'] = bssid | |
1026 | hostapd.add_ap(apdev[0]['ifname'], params) | |
1027 | ||
1028 | dev[0].hs20_enable() | |
1029 | values = { 'realm': "example.com", | |
524c6c33 | 1030 | 'ca_cert': "auth_serv/ca.pem", |
b4264f8f JM |
1031 | 'username': "hs20-test", |
1032 | 'password': "password", | |
1033 | 'domain': "example.com" } | |
1034 | id = dev[0].add_cred_values(values) | |
1035 | ||
841bed04 JM |
1036 | dev[0].scan_for_bss(bssid, freq="2412") |
1037 | ||
b4264f8f JM |
1038 | logger.info("Verify disallow_aps bssid") |
1039 | dev[0].request("SET disallow_aps bssid " + bssid.translate(None, ':')) | |
1040 | dev[0].request("INTERWORKING_SELECT auto") | |
1041 | ev = dev[0].wait_event(["INTERWORKING-NO-MATCH"], timeout=15) | |
1042 | if ev is None: | |
1043 | raise Exception("Network selection timed out") | |
1044 | dev[0].dump_monitor() | |
1045 | ||
1046 | logger.info("Verify disallow_aps ssid") | |
1047 | dev[0].request("SET disallow_aps ssid 746573742d68733230") | |
2f37a66d | 1048 | dev[0].request("INTERWORKING_SELECT auto freq=2412") |
b4264f8f JM |
1049 | ev = dev[0].wait_event(["INTERWORKING-NO-MATCH"], timeout=15) |
1050 | if ev is None: | |
1051 | raise Exception("Network selection timed out") | |
1052 | dev[0].dump_monitor() | |
1053 | ||
1054 | logger.info("Verify disallow_aps clear") | |
1055 | dev[0].request("SET disallow_aps ") | |
2f37a66d | 1056 | interworking_select(dev[0], bssid, "home", freq="2412") |
b4264f8f JM |
1057 | |
1058 | dev[0].request("SET disallow_aps bssid " + bssid.translate(None, ':')) | |
1059 | ret = dev[0].request("INTERWORKING_CONNECT " + bssid) | |
1060 | if "FAIL" not in ret: | |
1061 | raise Exception("INTERWORKING_CONNECT to disallowed BSS not rejected") | |
1062 | ||
7e71fbc1 JM |
1063 | if "FAIL" not in dev[0].request("INTERWORKING_CONNECT foo"): |
1064 | raise Exception("Invalid INTERWORKING_CONNECT not rejected") | |
1065 | if "FAIL" not in dev[0].request("INTERWORKING_CONNECT 00:11:22:33:44:55"): | |
1066 | raise Exception("Invalid INTERWORKING_CONNECT not rejected") | |
1067 | ||
d1ba402f JM |
1068 | def policy_test(dev, ap, values, only_one=True): |
1069 | dev.dump_monitor() | |
19839f8e JM |
1070 | if ap: |
1071 | logger.info("Verify network selection to AP " + ap['ifname']) | |
1072 | bssid = ap['bssid'] | |
841bed04 | 1073 | dev.scan_for_bss(bssid, freq="2412") |
19839f8e JM |
1074 | else: |
1075 | logger.info("Verify network selection") | |
1076 | bssid = None | |
d1ba402f JM |
1077 | dev.hs20_enable() |
1078 | id = dev.add_cred_values(values) | |
2f37a66d | 1079 | dev.request("INTERWORKING_SELECT auto freq=2412") |
19839f8e | 1080 | events = [] |
d1ba402f JM |
1081 | while True: |
1082 | ev = dev.wait_event(["INTERWORKING-AP", "INTERWORKING-NO-MATCH", | |
1965cc3a | 1083 | "INTERWORKING-BLACKLISTED", |
953a574d | 1084 | "INTERWORKING-SELECTED"], timeout=15) |
d1ba402f | 1085 | if ev is None: |
953a574d | 1086 | raise Exception("Network selection timed out") |
19839f8e | 1087 | events.append(ev) |
d1ba402f JM |
1088 | if "INTERWORKING-NO-MATCH" in ev: |
1089 | raise Exception("Matching AP not found") | |
19839f8e | 1090 | if bssid and only_one and "INTERWORKING-AP" in ev and bssid not in ev: |
d1ba402f | 1091 | raise Exception("Unexpected AP claimed acceptable") |
953a574d | 1092 | if "INTERWORKING-SELECTED" in ev: |
19839f8e | 1093 | if bssid and bssid not in ev: |
953a574d | 1094 | raise Exception("Selected incorrect BSS") |
d1ba402f JM |
1095 | break |
1096 | ||
5f35a5e2 | 1097 | ev = dev.wait_connected(timeout=15) |
19839f8e | 1098 | if bssid and bssid not in ev: |
953a574d JM |
1099 | raise Exception("Connected to incorrect BSS") |
1100 | ||
d1ba402f | 1101 | conn_bssid = dev.get_status_field("bssid") |
19839f8e | 1102 | if bssid and conn_bssid != bssid: |
d1ba402f JM |
1103 | raise Exception("bssid information points to incorrect BSS") |
1104 | ||
1105 | dev.remove_cred(id) | |
1106 | dev.dump_monitor() | |
19839f8e | 1107 | return events |
d1ba402f | 1108 | |
22653762 | 1109 | def default_cred(domain=None, user="hs20-test"): |
9714fbcd | 1110 | cred = { 'realm': "example.com", |
524c6c33 | 1111 | 'ca_cert': "auth_serv/ca.pem", |
22653762 | 1112 | 'username': user, |
d355372c | 1113 | 'password': "password" } |
9714fbcd JM |
1114 | if domain: |
1115 | cred['domain'] = domain | |
1116 | return cred | |
d355372c | 1117 | |
cfa57df6 JM |
1118 | def test_ap_hs20_prefer_home(dev, apdev): |
1119 | """Hotspot 2.0 required roaming consortium""" | |
e7ac04ce | 1120 | check_eap_capa(dev[0], "MSCHAPV2") |
cfa57df6 JM |
1121 | params = hs20_ap_params() |
1122 | params['domain_name'] = "example.org" | |
1123 | hostapd.add_ap(apdev[0]['ifname'], params) | |
1124 | ||
1125 | params = hs20_ap_params() | |
1126 | params['ssid'] = "test-hs20-other" | |
1127 | params['domain_name'] = "example.com" | |
1128 | hostapd.add_ap(apdev[1]['ifname'], params) | |
1129 | ||
1130 | values = default_cred() | |
1131 | values['domain'] = "example.com" | |
1132 | policy_test(dev[0], apdev[1], values, only_one=False) | |
1133 | values['domain'] = "example.org" | |
1134 | policy_test(dev[0], apdev[0], values, only_one=False) | |
1135 | ||
d1ba402f JM |
1136 | def test_ap_hs20_req_roaming_consortium(dev, apdev): |
1137 | """Hotspot 2.0 required roaming consortium""" | |
e7ac04ce | 1138 | check_eap_capa(dev[0], "MSCHAPV2") |
d1ba402f JM |
1139 | params = hs20_ap_params() |
1140 | hostapd.add_ap(apdev[0]['ifname'], params) | |
1141 | ||
1142 | params = hs20_ap_params() | |
1143 | params['ssid'] = "test-hs20-other" | |
1144 | params['roaming_consortium'] = [ "223344" ] | |
1145 | hostapd.add_ap(apdev[1]['ifname'], params) | |
1146 | ||
d355372c JM |
1147 | values = default_cred() |
1148 | values['required_roaming_consortium'] = "223344" | |
d1ba402f JM |
1149 | policy_test(dev[0], apdev[1], values) |
1150 | values['required_roaming_consortium'] = "112233" | |
1151 | policy_test(dev[0], apdev[0], values) | |
d355372c | 1152 | |
af70a093 JM |
1153 | id = dev[0].add_cred() |
1154 | dev[0].set_cred(id, "required_roaming_consortium", "112233") | |
1155 | dev[0].set_cred(id, "required_roaming_consortium", "112233445566778899aabbccddeeff") | |
1156 | ||
1157 | for val in [ "", "1", "11", "1122", "1122334", "112233445566778899aabbccddeeff00" ]: | |
1158 | if "FAIL" not in dev[0].request('SET_CRED {} required_roaming_consortium {}'.format(id, val)): | |
1159 | raise Exception("Invalid roaming consortium value accepted: " + val) | |
1160 | ||
d355372c JM |
1161 | def test_ap_hs20_excluded_ssid(dev, apdev): |
1162 | """Hotspot 2.0 exclusion based on SSID""" | |
e7ac04ce | 1163 | check_eap_capa(dev[0], "MSCHAPV2") |
d355372c | 1164 | params = hs20_ap_params() |
e2afdef2 JM |
1165 | params['roaming_consortium'] = [ "223344" ] |
1166 | params['anqp_3gpp_cell_net'] = "555,444" | |
d355372c JM |
1167 | hostapd.add_ap(apdev[0]['ifname'], params) |
1168 | ||
1169 | params = hs20_ap_params() | |
1170 | params['ssid'] = "test-hs20-other" | |
1171 | params['roaming_consortium'] = [ "223344" ] | |
e2afdef2 | 1172 | params['anqp_3gpp_cell_net'] = "555,444" |
d355372c JM |
1173 | hostapd.add_ap(apdev[1]['ifname'], params) |
1174 | ||
1175 | values = default_cred() | |
1176 | values['excluded_ssid'] = "test-hs20" | |
1965cc3a JM |
1177 | events = policy_test(dev[0], apdev[1], values) |
1178 | ev = [e for e in events if "INTERWORKING-BLACKLISTED " + apdev[0]['bssid'] in e] | |
1179 | if len(ev) != 1: | |
1180 | raise Exception("Excluded network not reported") | |
d355372c | 1181 | values['excluded_ssid'] = "test-hs20-other" |
1965cc3a JM |
1182 | events = policy_test(dev[0], apdev[0], values) |
1183 | ev = [e for e in events if "INTERWORKING-BLACKLISTED " + apdev[1]['bssid'] in e] | |
1184 | if len(ev) != 1: | |
1185 | raise Exception("Excluded network not reported") | |
d4058934 | 1186 | |
e2afdef2 JM |
1187 | values = default_cred() |
1188 | values['roaming_consortium'] = "223344" | |
1189 | values['eap'] = "TTLS" | |
1190 | values['phase2'] = "auth=MSCHAPV2" | |
1191 | values['excluded_ssid'] = "test-hs20" | |
1192 | events = policy_test(dev[0], apdev[1], values) | |
1193 | ev = [e for e in events if "INTERWORKING-BLACKLISTED " + apdev[0]['bssid'] in e] | |
1194 | if len(ev) != 1: | |
1195 | raise Exception("Excluded network not reported") | |
1196 | ||
1197 | values = { 'imsi': "555444-333222111", 'eap': "SIM", | |
1198 | 'milenage': "5122250214c33e723a5dd523fc145fc0:981d464c7c52eb6e5036234984ad0bcf:000000000123", | |
1199 | 'excluded_ssid': "test-hs20" } | |
1200 | events = policy_test(dev[0], apdev[1], values) | |
1201 | ev = [e for e in events if "INTERWORKING-BLACKLISTED " + apdev[0]['bssid'] in e] | |
1202 | if len(ev) != 1: | |
1203 | raise Exception("Excluded network not reported") | |
1204 | ||
d4058934 JM |
1205 | def test_ap_hs20_roam_to_higher_prio(dev, apdev): |
1206 | """Hotspot 2.0 and roaming from current to higher priority network""" | |
e7ac04ce | 1207 | check_eap_capa(dev[0], "MSCHAPV2") |
d4058934 JM |
1208 | bssid = apdev[0]['bssid'] |
1209 | params = hs20_ap_params(ssid="test-hs20-visited") | |
1210 | params['domain_name'] = "visited.example.org" | |
1211 | hostapd.add_ap(apdev[0]['ifname'], params) | |
1212 | ||
1213 | dev[0].hs20_enable() | |
1214 | id = dev[0].add_cred_values({ 'realm': "example.com", | |
524c6c33 | 1215 | 'ca_cert': "auth_serv/ca.pem", |
d4058934 JM |
1216 | 'username': "hs20-test", |
1217 | 'password': "password", | |
1218 | 'domain': "example.com" }) | |
1219 | logger.info("Connect to the only network option") | |
1220 | interworking_select(dev[0], bssid, "roaming", freq="2412") | |
1221 | dev[0].dump_monitor() | |
1222 | interworking_connect(dev[0], bssid, "TTLS") | |
1223 | ||
1224 | logger.info("Start another AP (home operator) and reconnect") | |
1225 | bssid2 = apdev[1]['bssid'] | |
1226 | params = hs20_ap_params(ssid="test-hs20-home") | |
1227 | params['domain_name'] = "example.com" | |
1228 | hostapd.add_ap(apdev[1]['ifname'], params) | |
1229 | ||
841bed04 | 1230 | dev[0].scan_for_bss(bssid2, freq="2412", force_scan=True) |
d4058934 JM |
1231 | dev[0].request("INTERWORKING_SELECT auto freq=2412") |
1232 | ev = dev[0].wait_event(["INTERWORKING-NO-MATCH", | |
1233 | "INTERWORKING-ALREADY-CONNECTED", | |
1234 | "CTRL-EVENT-CONNECTED"], timeout=15) | |
1235 | if ev is None: | |
1236 | raise Exception("Connection timed out") | |
1237 | if "INTERWORKING-NO-MATCH" in ev: | |
1238 | raise Exception("Matching AP not found") | |
1239 | if "INTERWORKING-ALREADY-CONNECTED" in ev: | |
1240 | raise Exception("Unexpected AP selected") | |
1241 | if bssid2 not in ev: | |
1242 | raise Exception("Unexpected BSSID after reconnection") | |
12c587a5 | 1243 | |
24579e70 | 1244 | def test_ap_hs20_domain_suffix_match_full(dev, apdev): |
12c587a5 | 1245 | """Hotspot 2.0 and domain_suffix_match""" |
e78eb404 | 1246 | check_domain_match_full(dev[0]) |
e7ac04ce | 1247 | check_eap_capa(dev[0], "MSCHAPV2") |
12c587a5 JM |
1248 | bssid = apdev[0]['bssid'] |
1249 | params = hs20_ap_params() | |
1250 | hostapd.add_ap(apdev[0]['ifname'], params) | |
1251 | ||
1252 | dev[0].hs20_enable() | |
1253 | id = dev[0].add_cred_values({ 'realm': "example.com", | |
1254 | 'username': "hs20-test", | |
1255 | 'password': "password", | |
524c6c33 | 1256 | 'ca_cert': "auth_serv/ca.pem", |
12c587a5 | 1257 | 'domain': "example.com", |
24579e70 | 1258 | 'domain_suffix_match': "server.w1.fi" }) |
12c587a5 JM |
1259 | interworking_select(dev[0], bssid, "home", freq="2412") |
1260 | dev[0].dump_monitor() | |
1261 | interworking_connect(dev[0], bssid, "TTLS") | |
1262 | dev[0].request("REMOVE_NETWORK all") | |
1263 | dev[0].dump_monitor() | |
1264 | ||
1265 | dev[0].set_cred_quoted(id, "domain_suffix_match", "no-match.example.com") | |
1266 | interworking_select(dev[0], bssid, "home", freq="2412") | |
1267 | dev[0].dump_monitor() | |
1268 | dev[0].request("INTERWORKING_CONNECT " + bssid) | |
1269 | ev = dev[0].wait_event(["CTRL-EVENT-EAP-TLS-CERT-ERROR"]) | |
1270 | if ev is None: | |
1271 | raise Exception("TLS certificate error not reported") | |
1272 | if "Domain suffix mismatch" not in ev: | |
1273 | raise Exception("Domain suffix mismatch not reported") | |
078683ac | 1274 | |
24579e70 JM |
1275 | def test_ap_hs20_domain_suffix_match(dev, apdev): |
1276 | """Hotspot 2.0 and domain_suffix_match""" | |
e7ac04ce | 1277 | check_eap_capa(dev[0], "MSCHAPV2") |
24579e70 JM |
1278 | check_domain_match_full(dev[0]) |
1279 | bssid = apdev[0]['bssid'] | |
1280 | params = hs20_ap_params() | |
1281 | hostapd.add_ap(apdev[0]['ifname'], params) | |
1282 | ||
1283 | dev[0].hs20_enable() | |
1284 | id = dev[0].add_cred_values({ 'realm': "example.com", | |
1285 | 'username': "hs20-test", | |
1286 | 'password': "password", | |
1287 | 'ca_cert': "auth_serv/ca.pem", | |
1288 | 'domain': "example.com", | |
1289 | 'domain_suffix_match': "w1.fi" }) | |
1290 | interworking_select(dev[0], bssid, "home", freq="2412") | |
1291 | dev[0].dump_monitor() | |
1292 | interworking_connect(dev[0], bssid, "TTLS") | |
1293 | ||
2253ea44 JM |
1294 | def test_ap_hs20_roaming_partner_preference(dev, apdev): |
1295 | """Hotspot 2.0 and roaming partner preference""" | |
e7ac04ce | 1296 | check_eap_capa(dev[0], "MSCHAPV2") |
2253ea44 JM |
1297 | params = hs20_ap_params() |
1298 | params['domain_name'] = "roaming.example.org" | |
1299 | hostapd.add_ap(apdev[0]['ifname'], params) | |
1300 | ||
1301 | params = hs20_ap_params() | |
1302 | params['ssid'] = "test-hs20-other" | |
1303 | params['domain_name'] = "roaming.example.net" | |
1304 | hostapd.add_ap(apdev[1]['ifname'], params) | |
1305 | ||
1306 | logger.info("Verify default vs. specified preference") | |
1307 | values = default_cred() | |
1308 | values['roaming_partner'] = "roaming.example.net,1,127,*" | |
1309 | policy_test(dev[0], apdev[1], values, only_one=False) | |
1310 | values['roaming_partner'] = "roaming.example.net,1,129,*" | |
1311 | policy_test(dev[0], apdev[0], values, only_one=False) | |
1312 | ||
1313 | logger.info("Verify partial FQDN match") | |
1314 | values['roaming_partner'] = "example.net,0,0,*" | |
1315 | policy_test(dev[0], apdev[1], values, only_one=False) | |
1316 | values['roaming_partner'] = "example.net,0,255,*" | |
1317 | policy_test(dev[0], apdev[0], values, only_one=False) | |
1318 | ||
19839f8e JM |
1319 | def test_ap_hs20_max_bss_load(dev, apdev): |
1320 | """Hotspot 2.0 and maximum BSS load""" | |
e7ac04ce | 1321 | check_eap_capa(dev[0], "MSCHAPV2") |
19839f8e JM |
1322 | params = hs20_ap_params() |
1323 | params['bss_load_test'] = "12:200:20000" | |
1324 | hostapd.add_ap(apdev[0]['ifname'], params) | |
1325 | ||
1326 | params = hs20_ap_params() | |
1327 | params['ssid'] = "test-hs20-other" | |
1328 | params['bss_load_test'] = "5:20:10000" | |
1329 | hostapd.add_ap(apdev[1]['ifname'], params) | |
1330 | ||
1331 | logger.info("Verify maximum BSS load constraint") | |
1332 | values = default_cred() | |
1333 | values['domain'] = "example.com" | |
1334 | values['max_bss_load'] = "100" | |
1335 | events = policy_test(dev[0], apdev[1], values, only_one=False) | |
1336 | ||
1337 | ev = [e for e in events if "INTERWORKING-AP " + apdev[0]['bssid'] in e] | |
1338 | if len(ev) != 1 or "over_max_bss_load=1" not in ev[0]: | |
1339 | raise Exception("Maximum BSS Load case not noticed") | |
1340 | ev = [e for e in events if "INTERWORKING-AP " + apdev[1]['bssid'] in e] | |
1341 | if len(ev) != 1 or "over_max_bss_load=1" in ev[0]: | |
1342 | raise Exception("Maximum BSS Load case reported incorrectly") | |
1343 | ||
1344 | logger.info("Verify maximum BSS load does not prevent connection") | |
1345 | values['max_bss_load'] = "1" | |
1346 | events = policy_test(dev[0], None, values) | |
1347 | ||
1348 | ev = [e for e in events if "INTERWORKING-AP " + apdev[0]['bssid'] in e] | |
1349 | if len(ev) != 1 or "over_max_bss_load=1" not in ev[0]: | |
1350 | raise Exception("Maximum BSS Load case not noticed") | |
1351 | ev = [e for e in events if "INTERWORKING-AP " + apdev[1]['bssid'] in e] | |
1352 | if len(ev) != 1 or "over_max_bss_load=1" not in ev[0]: | |
1353 | raise Exception("Maximum BSS Load case not noticed") | |
1354 | ||
1355 | def test_ap_hs20_max_bss_load2(dev, apdev): | |
1356 | """Hotspot 2.0 and maximum BSS load with one AP not advertising""" | |
e7ac04ce | 1357 | check_eap_capa(dev[0], "MSCHAPV2") |
19839f8e JM |
1358 | params = hs20_ap_params() |
1359 | params['bss_load_test'] = "12:200:20000" | |
1360 | hostapd.add_ap(apdev[0]['ifname'], params) | |
1361 | ||
1362 | params = hs20_ap_params() | |
1363 | params['ssid'] = "test-hs20-other" | |
1364 | hostapd.add_ap(apdev[1]['ifname'], params) | |
1365 | ||
1366 | logger.info("Verify maximum BSS load constraint with AP advertisement") | |
1367 | values = default_cred() | |
1368 | values['domain'] = "example.com" | |
1369 | values['max_bss_load'] = "100" | |
1370 | events = policy_test(dev[0], apdev[1], values, only_one=False) | |
1371 | ||
1372 | ev = [e for e in events if "INTERWORKING-AP " + apdev[0]['bssid'] in e] | |
1373 | if len(ev) != 1 or "over_max_bss_load=1" not in ev[0]: | |
1374 | raise Exception("Maximum BSS Load case not noticed") | |
1375 | ev = [e for e in events if "INTERWORKING-AP " + apdev[1]['bssid'] in e] | |
1376 | if len(ev) != 1 or "over_max_bss_load=1" in ev[0]: | |
1377 | raise Exception("Maximum BSS Load case reported incorrectly") | |
1378 | ||
078683ac JM |
1379 | def test_ap_hs20_multi_cred_sp_prio(dev, apdev): |
1380 | """Hotspot 2.0 multi-cred sp_priority""" | |
e7ac04ce | 1381 | check_eap_capa(dev[0], "MSCHAPV2") |
47dcb118 | 1382 | try: |
81e787b7 | 1383 | _test_ap_hs20_multi_cred_sp_prio(dev, apdev) |
47dcb118 JM |
1384 | finally: |
1385 | dev[0].request("SET external_sim 0") | |
1386 | ||
1387 | def _test_ap_hs20_multi_cred_sp_prio(dev, apdev): | |
81e787b7 | 1388 | hlr_auc_gw_available() |
078683ac JM |
1389 | bssid = apdev[0]['bssid'] |
1390 | params = hs20_ap_params() | |
1391 | params['hessid'] = bssid | |
1392 | del params['domain_name'] | |
1393 | params['anqp_3gpp_cell_net'] = "232,01" | |
1394 | hostapd.add_ap(apdev[0]['ifname'], params) | |
1395 | ||
1396 | dev[0].hs20_enable() | |
852cb016 | 1397 | dev[0].scan_for_bss(bssid, freq="2412") |
078683ac JM |
1398 | dev[0].request("SET external_sim 1") |
1399 | id1 = dev[0].add_cred_values({ 'imsi': "23201-0000000000", 'eap': "SIM", | |
1400 | 'provisioning_sp': "example.com", | |
1401 | 'sp_priority' :"1" }) | |
1402 | id2 = dev[0].add_cred_values({ 'realm': "example.com", | |
524c6c33 | 1403 | 'ca_cert': "auth_serv/ca.pem", |
078683ac JM |
1404 | 'username': "hs20-test", |
1405 | 'password': "password", | |
1406 | 'domain': "example.com", | |
1407 | 'provisioning_sp': "example.com", | |
1408 | 'sp_priority': "2" }) | |
1409 | dev[0].dump_monitor() | |
852cb016 | 1410 | dev[0].scan_for_bss(bssid, freq="2412") |
0b651713 | 1411 | dev[0].request("INTERWORKING_SELECT auto freq=2412") |
078683ac JM |
1412 | interworking_ext_sim_auth(dev[0], "SIM") |
1413 | check_sp_type(dev[0], "unknown") | |
1414 | dev[0].request("REMOVE_NETWORK all") | |
1415 | ||
1416 | dev[0].set_cred(id1, "sp_priority", "2") | |
1417 | dev[0].set_cred(id2, "sp_priority", "1") | |
1418 | dev[0].dump_monitor() | |
0b651713 | 1419 | dev[0].request("INTERWORKING_SELECT auto freq=2412") |
078683ac JM |
1420 | interworking_auth(dev[0], "TTLS") |
1421 | check_sp_type(dev[0], "unknown") | |
1422 | ||
1423 | def test_ap_hs20_multi_cred_sp_prio2(dev, apdev): | |
1424 | """Hotspot 2.0 multi-cred sp_priority with two BSSes""" | |
e7ac04ce | 1425 | check_eap_capa(dev[0], "MSCHAPV2") |
47dcb118 | 1426 | try: |
81e787b7 | 1427 | _test_ap_hs20_multi_cred_sp_prio2(dev, apdev) |
47dcb118 JM |
1428 | finally: |
1429 | dev[0].request("SET external_sim 0") | |
1430 | ||
1431 | def _test_ap_hs20_multi_cred_sp_prio2(dev, apdev): | |
81e787b7 | 1432 | hlr_auc_gw_available() |
078683ac JM |
1433 | bssid = apdev[0]['bssid'] |
1434 | params = hs20_ap_params() | |
1435 | params['hessid'] = bssid | |
1436 | del params['nai_realm'] | |
1437 | del params['domain_name'] | |
1438 | params['anqp_3gpp_cell_net'] = "232,01" | |
1439 | hostapd.add_ap(apdev[0]['ifname'], params) | |
1440 | ||
1441 | bssid2 = apdev[1]['bssid'] | |
1442 | params = hs20_ap_params() | |
1443 | params['ssid'] = "test-hs20-other" | |
1444 | params['hessid'] = bssid2 | |
1445 | del params['domain_name'] | |
1446 | del params['anqp_3gpp_cell_net'] | |
1447 | hostapd.add_ap(apdev[1]['ifname'], params) | |
1448 | ||
1449 | dev[0].hs20_enable() | |
1450 | dev[0].request("SET external_sim 1") | |
1451 | id1 = dev[0].add_cred_values({ 'imsi': "23201-0000000000", 'eap': "SIM", | |
1452 | 'provisioning_sp': "example.com", | |
1453 | 'sp_priority': "1" }) | |
1454 | id2 = dev[0].add_cred_values({ 'realm': "example.com", | |
524c6c33 | 1455 | 'ca_cert': "auth_serv/ca.pem", |
078683ac JM |
1456 | 'username': "hs20-test", |
1457 | 'password': "password", | |
1458 | 'domain': "example.com", | |
1459 | 'provisioning_sp': "example.com", | |
1460 | 'sp_priority': "2" }) | |
1461 | dev[0].dump_monitor() | |
852cb016 JM |
1462 | dev[0].scan_for_bss(bssid, freq="2412") |
1463 | dev[0].scan_for_bss(bssid2, freq="2412") | |
0b651713 | 1464 | dev[0].request("INTERWORKING_SELECT auto freq=2412") |
078683ac JM |
1465 | interworking_ext_sim_auth(dev[0], "SIM") |
1466 | check_sp_type(dev[0], "unknown") | |
1467 | conn_bssid = dev[0].get_status_field("bssid") | |
1468 | if conn_bssid != bssid: | |
1469 | raise Exception("Connected to incorrect BSS") | |
1470 | dev[0].request("REMOVE_NETWORK all") | |
1471 | ||
1472 | dev[0].set_cred(id1, "sp_priority", "2") | |
1473 | dev[0].set_cred(id2, "sp_priority", "1") | |
1474 | dev[0].dump_monitor() | |
0b651713 | 1475 | dev[0].request("INTERWORKING_SELECT auto freq=2412") |
078683ac JM |
1476 | interworking_auth(dev[0], "TTLS") |
1477 | check_sp_type(dev[0], "unknown") | |
1478 | conn_bssid = dev[0].get_status_field("bssid") | |
1479 | if conn_bssid != bssid2: | |
1480 | raise Exception("Connected to incorrect BSS") | |
5e32f825 | 1481 | |
a3dd0478 JM |
1482 | def check_conn_capab_selection(dev, type, missing): |
1483 | dev.request("INTERWORKING_SELECT freq=2412") | |
1484 | ev = dev.wait_event(["INTERWORKING-AP"]) | |
1485 | if ev is None: | |
1486 | raise Exception("Network selection timed out"); | |
1487 | if "type=" + type not in ev: | |
1488 | raise Exception("Unexpected network type") | |
1489 | if missing and "conn_capab_missing=1" not in ev: | |
1490 | raise Exception("conn_capab_missing not reported") | |
1491 | if not missing and "conn_capab_missing=1" in ev: | |
1492 | raise Exception("conn_capab_missing reported unexpectedly") | |
1493 | ||
1494 | def conn_capab_cred(domain=None, req_conn_capab=None): | |
1495 | cred = default_cred(domain=domain) | |
1496 | if req_conn_capab: | |
1497 | cred['req_conn_capab'] = req_conn_capab | |
1498 | return cred | |
1499 | ||
18153179 JM |
1500 | def test_ap_hs20_req_conn_capab(dev, apdev): |
1501 | """Hotspot 2.0 network selection with req_conn_capab""" | |
e7ac04ce | 1502 | check_eap_capa(dev[0], "MSCHAPV2") |
18153179 JM |
1503 | bssid = apdev[0]['bssid'] |
1504 | params = hs20_ap_params() | |
1505 | hostapd.add_ap(apdev[0]['ifname'], params) | |
1506 | ||
1507 | dev[0].hs20_enable() | |
852cb016 | 1508 | dev[0].scan_for_bss(bssid, freq="2412") |
18153179 | 1509 | logger.info("Not used in home network") |
a3dd0478 JM |
1510 | values = conn_capab_cred(domain="example.com", req_conn_capab="6:1234") |
1511 | id = dev[0].add_cred_values(values) | |
1512 | check_conn_capab_selection(dev[0], "home", False) | |
18153179 JM |
1513 | |
1514 | logger.info("Used in roaming network") | |
1515 | dev[0].remove_cred(id) | |
a3dd0478 JM |
1516 | values = conn_capab_cred(domain="example.org", req_conn_capab="6:1234") |
1517 | id = dev[0].add_cred_values(values) | |
1518 | check_conn_capab_selection(dev[0], "roaming", True) | |
18153179 JM |
1519 | |
1520 | logger.info("Verify that req_conn_capab does not prevent connection if no other network is available") | |
a3dd0478 JM |
1521 | check_auto_select(dev[0], bssid) |
1522 | ||
1523 | logger.info("Additional req_conn_capab checks") | |
1524 | ||
1525 | dev[0].remove_cred(id) | |
1526 | values = conn_capab_cred(domain="example.org", req_conn_capab="1:0") | |
1527 | id = dev[0].add_cred_values(values) | |
1528 | check_conn_capab_selection(dev[0], "roaming", True) | |
1529 | ||
1530 | dev[0].remove_cred(id) | |
1531 | values = conn_capab_cred(domain="example.org", req_conn_capab="17:5060") | |
1532 | id = dev[0].add_cred_values(values) | |
1533 | check_conn_capab_selection(dev[0], "roaming", True) | |
1534 | ||
1535 | bssid2 = apdev[1]['bssid'] | |
1536 | params = hs20_ap_params(ssid="test-hs20b") | |
1537 | params['hs20_conn_capab'] = [ "1:0:2", "6:22:1", "17:5060:0", "50:0:1" ] | |
1538 | hostapd.add_ap(apdev[1]['ifname'], params) | |
1539 | ||
1540 | dev[0].remove_cred(id) | |
1541 | values = conn_capab_cred(domain="example.org", req_conn_capab="50") | |
1542 | id = dev[0].add_cred_values(values) | |
1543 | dev[0].set_cred(id, "req_conn_capab", "6:22") | |
841bed04 | 1544 | dev[0].scan_for_bss(bssid2, freq="2412") |
a3dd0478 JM |
1545 | dev[0].request("INTERWORKING_SELECT freq=2412") |
1546 | for i in range(0, 2): | |
1547 | ev = dev[0].wait_event(["INTERWORKING-AP"]) | |
1548 | if ev is None: | |
1549 | raise Exception("Network selection timed out"); | |
1550 | if bssid in ev and "conn_capab_missing=1" not in ev: | |
1551 | raise Exception("Missing protocol connection capability not reported") | |
1552 | if bssid2 in ev and "conn_capab_missing=1" in ev: | |
1553 | raise Exception("Protocol connection capability not reported correctly") | |
1554 | ||
1555 | def test_ap_hs20_req_conn_capab_and_roaming_partner_preference(dev, apdev): | |
1556 | """Hotspot 2.0 and req_conn_capab with roaming partner preference""" | |
e7ac04ce | 1557 | check_eap_capa(dev[0], "MSCHAPV2") |
a3dd0478 JM |
1558 | bssid = apdev[0]['bssid'] |
1559 | params = hs20_ap_params() | |
1560 | params['domain_name'] = "roaming.example.org" | |
1561 | params['hs20_conn_capab'] = [ "1:0:2", "6:22:1", "17:5060:0", "50:0:1" ] | |
1562 | hostapd.add_ap(apdev[0]['ifname'], params) | |
1563 | ||
1564 | bssid2 = apdev[1]['bssid'] | |
1565 | params = hs20_ap_params(ssid="test-hs20-b") | |
1566 | params['domain_name'] = "roaming.example.net" | |
1567 | hostapd.add_ap(apdev[1]['ifname'], params) | |
1568 | ||
1569 | values = default_cred() | |
1570 | values['roaming_partner'] = "roaming.example.net,1,127,*" | |
1571 | id = dev[0].add_cred_values(values) | |
1572 | check_auto_select(dev[0], bssid2) | |
1573 | ||
1574 | dev[0].set_cred(id, "req_conn_capab", "50") | |
1575 | check_auto_select(dev[0], bssid) | |
1576 | ||
1577 | dev[0].remove_cred(id) | |
1578 | id = dev[0].add_cred_values(values) | |
1579 | dev[0].set_cred(id, "req_conn_capab", "51") | |
1580 | check_auto_select(dev[0], bssid2) | |
18153179 | 1581 | |
9714fbcd JM |
1582 | def check_bandwidth_selection(dev, type, below): |
1583 | dev.request("INTERWORKING_SELECT freq=2412") | |
1584 | ev = dev.wait_event(["INTERWORKING-AP"]) | |
1585 | if ev is None: | |
1586 | raise Exception("Network selection timed out"); | |
092ac7bb | 1587 | logger.debug("BSS entries:\n" + dev.request("BSS RANGE=ALL")) |
9714fbcd JM |
1588 | if "type=" + type not in ev: |
1589 | raise Exception("Unexpected network type") | |
1590 | if below and "below_min_backhaul=1" not in ev: | |
1591 | raise Exception("below_min_backhaul not reported") | |
1592 | if not below and "below_min_backhaul=1" in ev: | |
1593 | raise Exception("below_min_backhaul reported unexpectedly") | |
1594 | ||
1595 | def bw_cred(domain=None, dl_home=None, ul_home=None, dl_roaming=None, ul_roaming=None): | |
1596 | cred = default_cred(domain=domain) | |
1597 | if dl_home: | |
1598 | cred['min_dl_bandwidth_home'] = str(dl_home) | |
1599 | if ul_home: | |
1600 | cred['min_ul_bandwidth_home'] = str(ul_home) | |
1601 | if dl_roaming: | |
1602 | cred['min_dl_bandwidth_roaming'] = str(dl_roaming) | |
1603 | if ul_roaming: | |
1604 | cred['min_ul_bandwidth_roaming'] = str(ul_roaming) | |
1605 | return cred | |
1606 | ||
1607 | def test_ap_hs20_min_bandwidth_home(dev, apdev): | |
1608 | """Hotspot 2.0 network selection with min bandwidth (home)""" | |
e7ac04ce | 1609 | check_eap_capa(dev[0], "MSCHAPV2") |
9714fbcd JM |
1610 | bssid = apdev[0]['bssid'] |
1611 | params = hs20_ap_params() | |
1612 | hostapd.add_ap(apdev[0]['ifname'], params) | |
1613 | ||
1614 | dev[0].hs20_enable() | |
852cb016 | 1615 | dev[0].scan_for_bss(bssid, freq="2412") |
9714fbcd JM |
1616 | values = bw_cred(domain="example.com", dl_home=5490, ul_home=58) |
1617 | id = dev[0].add_cred_values(values) | |
1618 | check_bandwidth_selection(dev[0], "home", False) | |
1619 | dev[0].remove_cred(id) | |
1620 | ||
1621 | values = bw_cred(domain="example.com", dl_home=5491, ul_home=58) | |
1622 | id = dev[0].add_cred_values(values) | |
1623 | check_bandwidth_selection(dev[0], "home", True) | |
1624 | dev[0].remove_cred(id) | |
1625 | ||
1626 | values = bw_cred(domain="example.com", dl_home=5490, ul_home=59) | |
1627 | id = dev[0].add_cred_values(values) | |
1628 | check_bandwidth_selection(dev[0], "home", True) | |
1629 | dev[0].remove_cred(id) | |
1630 | ||
1631 | values = bw_cred(domain="example.com", dl_home=5491, ul_home=59) | |
1632 | id = dev[0].add_cred_values(values) | |
1633 | check_bandwidth_selection(dev[0], "home", True) | |
1634 | check_auto_select(dev[0], bssid) | |
1635 | ||
1636 | bssid2 = apdev[1]['bssid'] | |
1637 | params = hs20_ap_params(ssid="test-hs20-b") | |
1638 | params['hs20_wan_metrics'] = "01:8000:1000:1:1:3000" | |
1639 | hostapd.add_ap(apdev[1]['ifname'], params) | |
1640 | ||
1641 | check_auto_select(dev[0], bssid2) | |
1642 | ||
092ac7bb JM |
1643 | def test_ap_hs20_min_bandwidth_home_hidden_ssid_in_scan_res(dev, apdev): |
1644 | """Hotspot 2.0 network selection with min bandwidth (home) while hidden SSID is included in scan results""" | |
e7ac04ce | 1645 | check_eap_capa(dev[0], "MSCHAPV2") |
092ac7bb JM |
1646 | bssid = apdev[0]['bssid'] |
1647 | ||
1648 | hapd = hostapd.add_ap(apdev[0]['ifname'], { "ssid": 'secret', | |
1649 | "ignore_broadcast_ssid": "1" }) | |
1650 | dev[0].scan_for_bss(bssid, freq=2412) | |
1651 | hapd.disable() | |
1652 | hapd_global = hostapd.HostapdGlobal() | |
1653 | hapd_global.flush() | |
1654 | hapd_global.remove(apdev[0]['ifname']) | |
1655 | ||
1656 | params = hs20_ap_params() | |
1657 | hostapd.add_ap(apdev[0]['ifname'], params) | |
1658 | ||
1659 | dev[0].hs20_enable() | |
1660 | dev[0].scan_for_bss(bssid, freq="2412") | |
1661 | values = bw_cred(domain="example.com", dl_home=5490, ul_home=58) | |
1662 | id = dev[0].add_cred_values(values) | |
1663 | check_bandwidth_selection(dev[0], "home", False) | |
1664 | dev[0].remove_cred(id) | |
1665 | ||
1666 | values = bw_cred(domain="example.com", dl_home=5491, ul_home=58) | |
1667 | id = dev[0].add_cred_values(values) | |
1668 | check_bandwidth_selection(dev[0], "home", True) | |
1669 | dev[0].remove_cred(id) | |
1670 | ||
1671 | values = bw_cred(domain="example.com", dl_home=5490, ul_home=59) | |
1672 | id = dev[0].add_cred_values(values) | |
1673 | check_bandwidth_selection(dev[0], "home", True) | |
1674 | dev[0].remove_cred(id) | |
1675 | ||
1676 | values = bw_cred(domain="example.com", dl_home=5491, ul_home=59) | |
1677 | id = dev[0].add_cred_values(values) | |
1678 | check_bandwidth_selection(dev[0], "home", True) | |
1679 | check_auto_select(dev[0], bssid) | |
1680 | ||
1681 | bssid2 = apdev[1]['bssid'] | |
1682 | params = hs20_ap_params(ssid="test-hs20-b") | |
1683 | params['hs20_wan_metrics'] = "01:8000:1000:1:1:3000" | |
1684 | hostapd.add_ap(apdev[1]['ifname'], params) | |
1685 | ||
1686 | check_auto_select(dev[0], bssid2) | |
1687 | ||
1688 | dev[0].flush_scan_cache() | |
1689 | ||
9714fbcd JM |
1690 | def test_ap_hs20_min_bandwidth_roaming(dev, apdev): |
1691 | """Hotspot 2.0 network selection with min bandwidth (roaming)""" | |
e7ac04ce | 1692 | check_eap_capa(dev[0], "MSCHAPV2") |
9714fbcd JM |
1693 | bssid = apdev[0]['bssid'] |
1694 | params = hs20_ap_params() | |
1695 | hostapd.add_ap(apdev[0]['ifname'], params) | |
1696 | ||
1697 | dev[0].hs20_enable() | |
852cb016 | 1698 | dev[0].scan_for_bss(bssid, freq="2412") |
9714fbcd JM |
1699 | values = bw_cred(domain="example.org", dl_roaming=5490, ul_roaming=58) |
1700 | id = dev[0].add_cred_values(values) | |
1701 | check_bandwidth_selection(dev[0], "roaming", False) | |
1702 | dev[0].remove_cred(id) | |
1703 | ||
1704 | values = bw_cred(domain="example.org", dl_roaming=5491, ul_roaming=58) | |
1705 | id = dev[0].add_cred_values(values) | |
1706 | check_bandwidth_selection(dev[0], "roaming", True) | |
1707 | dev[0].remove_cred(id) | |
1708 | ||
1709 | values = bw_cred(domain="example.org", dl_roaming=5490, ul_roaming=59) | |
1710 | id = dev[0].add_cred_values(values) | |
1711 | check_bandwidth_selection(dev[0], "roaming", True) | |
1712 | dev[0].remove_cred(id) | |
1713 | ||
1714 | values = bw_cred(domain="example.org", dl_roaming=5491, ul_roaming=59) | |
1715 | id = dev[0].add_cred_values(values) | |
1716 | check_bandwidth_selection(dev[0], "roaming", True) | |
1717 | check_auto_select(dev[0], bssid) | |
1718 | ||
1719 | bssid2 = apdev[1]['bssid'] | |
1720 | params = hs20_ap_params(ssid="test-hs20-b") | |
1721 | params['hs20_wan_metrics'] = "01:8000:1000:1:1:3000" | |
1722 | hostapd.add_ap(apdev[1]['ifname'], params) | |
1723 | ||
1724 | check_auto_select(dev[0], bssid2) | |
1725 | ||
1726 | def test_ap_hs20_min_bandwidth_and_roaming_partner_preference(dev, apdev): | |
1727 | """Hotspot 2.0 and minimum bandwidth with roaming partner preference""" | |
e7ac04ce | 1728 | check_eap_capa(dev[0], "MSCHAPV2") |
9714fbcd JM |
1729 | bssid = apdev[0]['bssid'] |
1730 | params = hs20_ap_params() | |
1731 | params['domain_name'] = "roaming.example.org" | |
1732 | params['hs20_wan_metrics'] = "01:8000:1000:1:1:3000" | |
1733 | hostapd.add_ap(apdev[0]['ifname'], params) | |
1734 | ||
1735 | bssid2 = apdev[1]['bssid'] | |
1736 | params = hs20_ap_params(ssid="test-hs20-b") | |
1737 | params['domain_name'] = "roaming.example.net" | |
1738 | hostapd.add_ap(apdev[1]['ifname'], params) | |
1739 | ||
1740 | values = default_cred() | |
1741 | values['roaming_partner'] = "roaming.example.net,1,127,*" | |
1742 | id = dev[0].add_cred_values(values) | |
1743 | check_auto_select(dev[0], bssid2) | |
1744 | ||
1745 | dev[0].set_cred(id, "min_dl_bandwidth_roaming", "6000") | |
1746 | check_auto_select(dev[0], bssid) | |
1747 | ||
1748 | dev[0].set_cred(id, "min_dl_bandwidth_roaming", "10000") | |
1749 | check_auto_select(dev[0], bssid2) | |
1750 | ||
1751 | def test_ap_hs20_min_bandwidth_no_wan_metrics(dev, apdev): | |
1752 | """Hotspot 2.0 network selection with min bandwidth but no WAN Metrics""" | |
1753 | bssid = apdev[0]['bssid'] | |
1754 | params = hs20_ap_params() | |
1755 | del params['hs20_wan_metrics'] | |
1756 | hostapd.add_ap(apdev[0]['ifname'], params) | |
1757 | ||
1758 | dev[0].hs20_enable() | |
852cb016 | 1759 | dev[0].scan_for_bss(bssid, freq="2412") |
9714fbcd JM |
1760 | values = bw_cred(domain="example.com", dl_home=10000, ul_home=10000, |
1761 | dl_roaming=10000, ul_roaming=10000) | |
1762 | dev[0].add_cred_values(values) | |
1763 | check_bandwidth_selection(dev[0], "home", False) | |
1764 | ||
5e32f825 JM |
1765 | def test_ap_hs20_deauth_req_ess(dev, apdev): |
1766 | """Hotspot 2.0 connection and deauthentication request for ESS""" | |
e7ac04ce | 1767 | check_eap_capa(dev[0], "MSCHAPV2") |
909f13cc JM |
1768 | try: |
1769 | _test_ap_hs20_deauth_req_ess(dev, apdev) | |
1770 | finally: | |
1771 | dev[0].request("SET pmf 0") | |
1772 | ||
1773 | def _test_ap_hs20_deauth_req_ess(dev, apdev): | |
5e32f825 JM |
1774 | dev[0].request("SET pmf 2") |
1775 | eap_test(dev[0], apdev[0], "21[3:26]", "TTLS", "user") | |
1776 | dev[0].dump_monitor() | |
1777 | addr = dev[0].p2p_interface_addr() | |
1778 | hapd = hostapd.Hostapd(apdev[0]['ifname']) | |
1779 | hapd.request("HS20_DEAUTH_REQ " + addr + " 1 120 http://example.com/") | |
1780 | ev = dev[0].wait_event(["HS20-DEAUTH-IMMINENT-NOTICE"]) | |
1781 | if ev is None: | |
1782 | raise Exception("Timeout on deauth imminent notice") | |
1783 | if "1 120 http://example.com/" not in ev: | |
1784 | raise Exception("Unexpected deauth imminent notice: " + ev) | |
1785 | hapd.request("DEAUTHENTICATE " + addr) | |
5f35a5e2 | 1786 | dev[0].wait_disconnected(timeout=10) |
c61e5a82 JM |
1787 | if "[TEMP-DISABLED]" not in dev[0].list_networks()[0]['flags']: |
1788 | raise Exception("Network not marked temporarily disabled") | |
5e32f825 JM |
1789 | ev = dev[0].wait_event(["SME: Trying to authenticate", |
1790 | "Trying to associate", | |
1791 | "CTRL-EVENT-CONNECTED"], timeout=5) | |
1792 | if ev is not None: | |
1793 | raise Exception("Unexpected connection attempt") | |
1794 | ||
1795 | def test_ap_hs20_deauth_req_bss(dev, apdev): | |
1796 | """Hotspot 2.0 connection and deauthentication request for BSS""" | |
e7ac04ce | 1797 | check_eap_capa(dev[0], "MSCHAPV2") |
909f13cc JM |
1798 | try: |
1799 | _test_ap_hs20_deauth_req_bss(dev, apdev) | |
1800 | finally: | |
1801 | dev[0].request("SET pmf 0") | |
1802 | ||
1803 | def _test_ap_hs20_deauth_req_bss(dev, apdev): | |
5e32f825 JM |
1804 | dev[0].request("SET pmf 2") |
1805 | eap_test(dev[0], apdev[0], "21[3:26]", "TTLS", "user") | |
1806 | dev[0].dump_monitor() | |
1807 | addr = dev[0].p2p_interface_addr() | |
1808 | hapd = hostapd.Hostapd(apdev[0]['ifname']) | |
1809 | hapd.request("HS20_DEAUTH_REQ " + addr + " 0 120 http://example.com/") | |
1810 | ev = dev[0].wait_event(["HS20-DEAUTH-IMMINENT-NOTICE"]) | |
1811 | if ev is None: | |
1812 | raise Exception("Timeout on deauth imminent notice") | |
1813 | if "0 120 http://example.com/" not in ev: | |
1814 | raise Exception("Unexpected deauth imminent notice: " + ev) | |
1815 | hapd.request("DEAUTHENTICATE " + addr + " reason=4") | |
5f35a5e2 | 1816 | ev = dev[0].wait_disconnected(timeout=10) |
5e32f825 JM |
1817 | if "reason=4" not in ev: |
1818 | raise Exception("Unexpected disconnection reason") | |
c61e5a82 JM |
1819 | if "[TEMP-DISABLED]" not in dev[0].list_networks()[0]['flags']: |
1820 | raise Exception("Network not marked temporarily disabled") | |
5e32f825 JM |
1821 | ev = dev[0].wait_event(["SME: Trying to authenticate", |
1822 | "Trying to associate", | |
1823 | "CTRL-EVENT-CONNECTED"], timeout=5) | |
1824 | if ev is not None: | |
1825 | raise Exception("Unexpected connection attempt") | |
9e709315 | 1826 | |
48ef12e7 JM |
1827 | def test_ap_hs20_deauth_req_from_radius(dev, apdev): |
1828 | """Hotspot 2.0 connection and deauthentication request from RADIUS""" | |
e7ac04ce | 1829 | check_eap_capa(dev[0], "MSCHAPV2") |
909f13cc JM |
1830 | try: |
1831 | _test_ap_hs20_deauth_req_from_radius(dev, apdev) | |
1832 | finally: | |
1833 | dev[0].request("SET pmf 0") | |
1834 | ||
1835 | def _test_ap_hs20_deauth_req_from_radius(dev, apdev): | |
48ef12e7 JM |
1836 | bssid = apdev[0]['bssid'] |
1837 | params = hs20_ap_params() | |
1838 | params['nai_realm'] = [ "0,example.com,21[2:4]" ] | |
1839 | params['hs20_deauth_req_timeout'] = "2" | |
1840 | hostapd.add_ap(apdev[0]['ifname'], params) | |
1841 | ||
1842 | dev[0].request("SET pmf 2") | |
1843 | dev[0].hs20_enable() | |
1844 | dev[0].add_cred_values({ 'realm': "example.com", | |
1845 | 'username': "hs20-deauth-test", | |
1846 | 'password': "password" }) | |
1847 | interworking_select(dev[0], bssid, freq="2412") | |
1848 | interworking_connect(dev[0], bssid, "TTLS") | |
1849 | ev = dev[0].wait_event(["HS20-DEAUTH-IMMINENT-NOTICE"], timeout=5) | |
1850 | if ev is None: | |
1851 | raise Exception("Timeout on deauth imminent notice") | |
1852 | if " 1 100" not in ev: | |
1853 | raise Exception("Unexpected deauth imminent contents") | |
5f35a5e2 | 1854 | dev[0].wait_disconnected(timeout=3) |
48ef12e7 | 1855 | |
5cf88011 JM |
1856 | def test_ap_hs20_remediation_required(dev, apdev): |
1857 | """Hotspot 2.0 connection and remediation required from RADIUS""" | |
e7ac04ce | 1858 | check_eap_capa(dev[0], "MSCHAPV2") |
909f13cc JM |
1859 | try: |
1860 | _test_ap_hs20_remediation_required(dev, apdev) | |
1861 | finally: | |
1862 | dev[0].request("SET pmf 0") | |
1863 | ||
1864 | def _test_ap_hs20_remediation_required(dev, apdev): | |
5cf88011 JM |
1865 | bssid = apdev[0]['bssid'] |
1866 | params = hs20_ap_params() | |
1867 | params['nai_realm'] = [ "0,example.com,21[2:4]" ] | |
1868 | hostapd.add_ap(apdev[0]['ifname'], params) | |
1869 | ||
1870 | dev[0].request("SET pmf 1") | |
1871 | dev[0].hs20_enable() | |
1872 | dev[0].add_cred_values({ 'realm': "example.com", | |
1873 | 'username': "hs20-subrem-test", | |
1874 | 'password': "password" }) | |
1875 | interworking_select(dev[0], bssid, freq="2412") | |
1876 | interworking_connect(dev[0], bssid, "TTLS") | |
1877 | ev = dev[0].wait_event(["HS20-SUBSCRIPTION-REMEDIATION"], timeout=5) | |
1878 | if ev is None: | |
1879 | raise Exception("Timeout on subscription remediation notice") | |
1880 | if " 1 https://example.com/" not in ev: | |
1881 | raise Exception("Unexpected subscription remediation event contents") | |
1882 | ||
32b450fc JM |
1883 | def test_ap_hs20_remediation_required_ctrl(dev, apdev): |
1884 | """Hotspot 2.0 connection and subrem from ctrl_iface""" | |
e7ac04ce | 1885 | check_eap_capa(dev[0], "MSCHAPV2") |
909f13cc JM |
1886 | try: |
1887 | _test_ap_hs20_remediation_required_ctrl(dev, apdev) | |
1888 | finally: | |
1889 | dev[0].request("SET pmf 0") | |
1890 | ||
1891 | def _test_ap_hs20_remediation_required_ctrl(dev, apdev): | |
32b450fc | 1892 | bssid = apdev[0]['bssid'] |
83e1bab0 | 1893 | addr = dev[0].own_addr() |
32b450fc JM |
1894 | params = hs20_ap_params() |
1895 | params['nai_realm'] = [ "0,example.com,21[2:4]" ] | |
1896 | hapd = hostapd.add_ap(apdev[0]['ifname'], params) | |
1897 | ||
1898 | dev[0].request("SET pmf 1") | |
1899 | dev[0].hs20_enable() | |
1900 | dev[0].add_cred_values(default_cred()) | |
1901 | interworking_select(dev[0], bssid, freq="2412") | |
1902 | interworking_connect(dev[0], bssid, "TTLS") | |
1903 | ||
1904 | hapd.request("HS20_WNM_NOTIF " + addr + " https://example.com/") | |
1905 | ev = dev[0].wait_event(["HS20-SUBSCRIPTION-REMEDIATION"], timeout=5) | |
1906 | if ev is None: | |
1907 | raise Exception("Timeout on subscription remediation notice") | |
1908 | if " 1 https://example.com/" not in ev: | |
1909 | raise Exception("Unexpected subscription remediation event contents") | |
1910 | ||
1911 | hapd.request("HS20_WNM_NOTIF " + addr) | |
1912 | ev = dev[0].wait_event(["HS20-SUBSCRIPTION-REMEDIATION"], timeout=5) | |
1913 | if ev is None: | |
1914 | raise Exception("Timeout on subscription remediation notice") | |
1915 | if not ev.endswith("HS20-SUBSCRIPTION-REMEDIATION "): | |
1916 | raise Exception("Unexpected subscription remediation event contents: " + ev) | |
1917 | ||
1918 | if "FAIL" not in hapd.request("HS20_WNM_NOTIF "): | |
1919 | raise Exception("Unexpected HS20_WNM_NOTIF success") | |
1920 | if "FAIL" not in hapd.request("HS20_WNM_NOTIF foo"): | |
1921 | raise Exception("Unexpected HS20_WNM_NOTIF success") | |
1922 | if "FAIL" not in hapd.request("HS20_WNM_NOTIF " + addr + " https://12345678923456789842345678456783456712345678923456789842345678456783456712345678923456789842345678456783456712345678923456789842345678456783456712345678923456789842345678456783456712345678923456789842345678456783456712345678923456789842345678456783456712345678927.very.long.example.com/"): | |
1923 | raise Exception("Unexpected HS20_WNM_NOTIF success") | |
1924 | ||
8fc1f204 JM |
1925 | def test_ap_hs20_session_info(dev, apdev): |
1926 | """Hotspot 2.0 connection and session information from RADIUS""" | |
e7ac04ce | 1927 | check_eap_capa(dev[0], "MSCHAPV2") |
909f13cc JM |
1928 | try: |
1929 | _test_ap_hs20_session_info(dev, apdev) | |
1930 | finally: | |
1931 | dev[0].request("SET pmf 0") | |
1932 | ||
1933 | def _test_ap_hs20_session_info(dev, apdev): | |
8fc1f204 JM |
1934 | bssid = apdev[0]['bssid'] |
1935 | params = hs20_ap_params() | |
1936 | params['nai_realm'] = [ "0,example.com,21[2:4]" ] | |
1937 | hostapd.add_ap(apdev[0]['ifname'], params) | |
1938 | ||
1939 | dev[0].request("SET pmf 1") | |
1940 | dev[0].hs20_enable() | |
1941 | dev[0].add_cred_values({ 'realm': "example.com", | |
1942 | 'username': "hs20-session-info-test", | |
1943 | 'password': "password" }) | |
1944 | interworking_select(dev[0], bssid, freq="2412") | |
1945 | interworking_connect(dev[0], bssid, "TTLS") | |
1946 | ev = dev[0].wait_event(["ESS-DISASSOC-IMMINENT"], timeout=10) | |
1947 | if ev is None: | |
1948 | raise Exception("Timeout on ESS disassociation imminent notice") | |
1949 | if " 1 59904 https://example.com/" not in ev: | |
1950 | raise Exception("Unexpected ESS disassociation imminent event contents") | |
1951 | ev = dev[0].wait_event(["CTRL-EVENT-SCAN-STARTED"]) | |
1952 | if ev is None: | |
1953 | raise Exception("Scan not started") | |
64502039 | 1954 | ev = dev[0].wait_event(["CTRL-EVENT-SCAN-RESULTS"], timeout=30) |
8fc1f204 JM |
1955 | if ev is None: |
1956 | raise Exception("Scan not completed") | |
1957 | ||
9e709315 JM |
1958 | def test_ap_hs20_osen(dev, apdev): |
1959 | """Hotspot 2.0 OSEN connection""" | |
1960 | params = { 'ssid': "osen", | |
1961 | 'osen': "1", | |
1962 | 'auth_server_addr': "127.0.0.1", | |
1963 | 'auth_server_port': "1812", | |
1964 | 'auth_server_shared_secret': "radius" } | |
1965 | hostapd.add_ap(apdev[0]['ifname'], params) | |
1966 | ||
8abb3d4e JM |
1967 | dev[1].connect("osen", key_mgmt="NONE", scan_freq="2412", |
1968 | wait_connect=False) | |
1969 | dev[2].connect("osen", key_mgmt="NONE", wep_key0='"hello"', | |
1970 | scan_freq="2412", wait_connect=False) | |
8278138e | 1971 | dev[0].flush_scan_cache() |
9e709315 JM |
1972 | dev[0].connect("osen", proto="OSEN", key_mgmt="OSEN", pairwise="CCMP", |
1973 | group="GTK_NOT_USED", | |
1974 | eap="WFA-UNAUTH-TLS", identity="osen@example.com", | |
1975 | ca_cert="auth_serv/ca.pem", | |
1976 | scan_freq="2412") | |
8278138e JM |
1977 | res = dev[0].get_bss(apdev[0]['bssid'])['flags'] |
1978 | if "[OSEN-OSEN-CCMP]" not in res: | |
1979 | raise Exception("OSEN not reported in BSS") | |
1980 | if "[WEP]" in res: | |
1981 | raise Exception("WEP reported in BSS") | |
1982 | res = dev[0].request("SCAN_RESULTS") | |
1983 | if "[OSEN-OSEN-CCMP]" not in res: | |
1984 | raise Exception("OSEN not reported in SCAN_RESULTS") | |
a96066a5 | 1985 | |
9d1e1172 JM |
1986 | wpas = WpaSupplicant(global_iface='/tmp/wpas-wlan5') |
1987 | wpas.interface_add("wlan5", drv_params="force_connect_cmd=1") | |
1988 | wpas.connect("osen", proto="OSEN", key_mgmt="OSEN", pairwise="CCMP", | |
1989 | group="GTK_NOT_USED", | |
1990 | eap="WFA-UNAUTH-TLS", identity="osen@example.com", | |
1991 | ca_cert="auth_serv/ca.pem", | |
1992 | scan_freq="2412") | |
1993 | wpas.request("DISCONNECT") | |
1994 | ||
a96066a5 JM |
1995 | def test_ap_hs20_network_preference(dev, apdev): |
1996 | """Hotspot 2.0 network selection with preferred home network""" | |
e7ac04ce | 1997 | check_eap_capa(dev[0], "MSCHAPV2") |
a96066a5 JM |
1998 | bssid = apdev[0]['bssid'] |
1999 | params = hs20_ap_params() | |
2000 | hostapd.add_ap(apdev[0]['ifname'], params) | |
2001 | ||
2002 | dev[0].hs20_enable() | |
2003 | values = { 'realm': "example.com", | |
2004 | 'username': "hs20-test", | |
2005 | 'password': "password", | |
2006 | 'domain': "example.com" } | |
2007 | dev[0].add_cred_values(values) | |
2008 | ||
2009 | id = dev[0].add_network() | |
2010 | dev[0].set_network_quoted(id, "ssid", "home") | |
2011 | dev[0].set_network_quoted(id, "psk", "12345678") | |
2012 | dev[0].set_network(id, "priority", "1") | |
2013 | dev[0].request("ENABLE_NETWORK %s no-connect" % id) | |
2014 | ||
852cb016 | 2015 | dev[0].scan_for_bss(bssid, freq="2412") |
a96066a5 | 2016 | dev[0].request("INTERWORKING_SELECT auto freq=2412") |
5f35a5e2 | 2017 | ev = dev[0].wait_connected(timeout=15) |
a96066a5 JM |
2018 | if bssid not in ev: |
2019 | raise Exception("Unexpected network selected") | |
2020 | ||
2021 | bssid2 = apdev[1]['bssid'] | |
2022 | params = hostapd.wpa2_params(ssid="home", passphrase="12345678") | |
2023 | hostapd.add_ap(apdev[1]['ifname'], params) | |
2024 | ||
852cb016 | 2025 | dev[0].scan_for_bss(bssid2, freq="2412") |
a96066a5 JM |
2026 | dev[0].request("INTERWORKING_SELECT auto freq=2412") |
2027 | ev = dev[0].wait_event(["CTRL-EVENT-CONNECTED", | |
2028 | "INTERWORKING-ALREADY-CONNECTED" ], timeout=15) | |
2029 | if ev is None: | |
2030 | raise Exception("Connection timed out") | |
2031 | if "INTERWORKING-ALREADY-CONNECTED" in ev: | |
2032 | raise Exception("No roam to higher priority network") | |
2033 | if bssid2 not in ev: | |
2034 | raise Exception("Unexpected network selected") | |
2035 | ||
2036 | def test_ap_hs20_network_preference2(dev, apdev): | |
2037 | """Hotspot 2.0 network selection with preferred credential""" | |
e7ac04ce | 2038 | check_eap_capa(dev[0], "MSCHAPV2") |
a96066a5 JM |
2039 | bssid2 = apdev[1]['bssid'] |
2040 | params = hostapd.wpa2_params(ssid="home", passphrase="12345678") | |
2041 | hostapd.add_ap(apdev[1]['ifname'], params) | |
2042 | ||
2043 | dev[0].hs20_enable() | |
2044 | values = { 'realm': "example.com", | |
2045 | 'username': "hs20-test", | |
2046 | 'password': "password", | |
2047 | 'domain': "example.com", | |
2048 | 'priority': "1" } | |
2049 | dev[0].add_cred_values(values) | |
2050 | ||
2051 | id = dev[0].add_network() | |
2052 | dev[0].set_network_quoted(id, "ssid", "home") | |
2053 | dev[0].set_network_quoted(id, "psk", "12345678") | |
2054 | dev[0].request("ENABLE_NETWORK %s no-connect" % id) | |
2055 | ||
852cb016 | 2056 | dev[0].scan_for_bss(bssid2, freq="2412") |
a96066a5 | 2057 | dev[0].request("INTERWORKING_SELECT auto freq=2412") |
5f35a5e2 | 2058 | ev = dev[0].wait_connected(timeout=15) |
a96066a5 JM |
2059 | if bssid2 not in ev: |
2060 | raise Exception("Unexpected network selected") | |
2061 | ||
2062 | bssid = apdev[0]['bssid'] | |
2063 | params = hs20_ap_params() | |
2064 | hostapd.add_ap(apdev[0]['ifname'], params) | |
2065 | ||
852cb016 | 2066 | dev[0].scan_for_bss(bssid, freq="2412") |
a96066a5 JM |
2067 | dev[0].request("INTERWORKING_SELECT auto freq=2412") |
2068 | ev = dev[0].wait_event(["CTRL-EVENT-CONNECTED", | |
2069 | "INTERWORKING-ALREADY-CONNECTED" ], timeout=15) | |
2070 | if ev is None: | |
2071 | raise Exception("Connection timed out") | |
2072 | if "INTERWORKING-ALREADY-CONNECTED" in ev: | |
2073 | raise Exception("No roam to higher priority network") | |
2074 | if bssid not in ev: | |
2075 | raise Exception("Unexpected network selected") | |
eaff3458 JM |
2076 | |
2077 | def test_ap_hs20_network_preference3(dev, apdev): | |
2078 | """Hotspot 2.0 network selection with two credential (one preferred)""" | |
e7ac04ce | 2079 | check_eap_capa(dev[0], "MSCHAPV2") |
eaff3458 JM |
2080 | bssid = apdev[0]['bssid'] |
2081 | params = hs20_ap_params() | |
2082 | hostapd.add_ap(apdev[0]['ifname'], params) | |
2083 | ||
2084 | bssid2 = apdev[1]['bssid'] | |
2085 | params = hs20_ap_params(ssid="test-hs20b") | |
2086 | params['nai_realm'] = "0,example.org,13[5:6],21[2:4][5:7]" | |
2087 | hostapd.add_ap(apdev[1]['ifname'], params) | |
2088 | ||
2089 | dev[0].hs20_enable() | |
2090 | values = { 'realm': "example.com", | |
2091 | 'username': "hs20-test", | |
2092 | 'password': "password", | |
2093 | 'priority': "1" } | |
2094 | dev[0].add_cred_values(values) | |
2095 | values = { 'realm': "example.org", | |
2096 | 'username': "hs20-test", | |
2097 | 'password': "password" } | |
2098 | id = dev[0].add_cred_values(values) | |
2099 | ||
852cb016 JM |
2100 | dev[0].scan_for_bss(bssid, freq="2412") |
2101 | dev[0].scan_for_bss(bssid2, freq="2412") | |
eaff3458 | 2102 | dev[0].request("INTERWORKING_SELECT auto freq=2412") |
5f35a5e2 | 2103 | ev = dev[0].wait_connected(timeout=15) |
eaff3458 JM |
2104 | if bssid not in ev: |
2105 | raise Exception("Unexpected network selected") | |
2106 | ||
2107 | dev[0].set_cred(id, "priority", "2") | |
2108 | dev[0].request("INTERWORKING_SELECT auto freq=2412") | |
2109 | ev = dev[0].wait_event(["CTRL-EVENT-CONNECTED", | |
2110 | "INTERWORKING-ALREADY-CONNECTED" ], timeout=15) | |
2111 | if ev is None: | |
2112 | raise Exception("Connection timed out") | |
2113 | if "INTERWORKING-ALREADY-CONNECTED" in ev: | |
2114 | raise Exception("No roam to higher priority network") | |
2115 | if bssid2 not in ev: | |
2116 | raise Exception("Unexpected network selected") | |
1221639d JM |
2117 | |
2118 | def test_ap_hs20_network_preference4(dev, apdev): | |
2119 | """Hotspot 2.0 network selection with username vs. SIM credential""" | |
e7ac04ce | 2120 | check_eap_capa(dev[0], "MSCHAPV2") |
1221639d JM |
2121 | bssid = apdev[0]['bssid'] |
2122 | params = hs20_ap_params() | |
2123 | hostapd.add_ap(apdev[0]['ifname'], params) | |
2124 | ||
2125 | bssid2 = apdev[1]['bssid'] | |
2126 | params = hs20_ap_params(ssid="test-hs20b") | |
2127 | params['hessid'] = bssid2 | |
2128 | params['anqp_3gpp_cell_net'] = "555,444" | |
2129 | params['domain_name'] = "wlan.mnc444.mcc555.3gppnetwork.org" | |
2130 | hostapd.add_ap(apdev[1]['ifname'], params) | |
2131 | ||
2132 | dev[0].hs20_enable() | |
2133 | values = { 'realm': "example.com", | |
2134 | 'username': "hs20-test", | |
2135 | 'password': "password", | |
2136 | 'priority': "1" } | |
2137 | dev[0].add_cred_values(values) | |
2138 | values = { 'imsi': "555444-333222111", | |
2139 | 'eap': "SIM", | |
2140 | 'milenage': "5122250214c33e723a5dd523fc145fc0:981d464c7c52eb6e5036234984ad0bcf:000000000123" } | |
2141 | id = dev[0].add_cred_values(values) | |
2142 | ||
852cb016 JM |
2143 | dev[0].scan_for_bss(bssid, freq="2412") |
2144 | dev[0].scan_for_bss(bssid2, freq="2412") | |
1221639d | 2145 | dev[0].request("INTERWORKING_SELECT auto freq=2412") |
5f35a5e2 | 2146 | ev = dev[0].wait_connected(timeout=15) |
1221639d JM |
2147 | if bssid not in ev: |
2148 | raise Exception("Unexpected network selected") | |
2149 | ||
2150 | dev[0].set_cred(id, "priority", "2") | |
2151 | dev[0].request("INTERWORKING_SELECT auto freq=2412") | |
2152 | ev = dev[0].wait_event(["CTRL-EVENT-CONNECTED", | |
2153 | "INTERWORKING-ALREADY-CONNECTED" ], timeout=15) | |
2154 | if ev is None: | |
2155 | raise Exception("Connection timed out") | |
2156 | if "INTERWORKING-ALREADY-CONNECTED" in ev: | |
2157 | raise Exception("No roam to higher priority network") | |
2158 | if bssid2 not in ev: | |
2159 | raise Exception("Unexpected network selected") | |
97de642a | 2160 | |
5f6ce5b5 JM |
2161 | def test_ap_hs20_interworking_select_blocking_scan(dev, apdev): |
2162 | """Ongoing INTERWORKING_SELECT blocking SCAN""" | |
e7ac04ce | 2163 | check_eap_capa(dev[0], "MSCHAPV2") |
5f6ce5b5 JM |
2164 | bssid = apdev[0]['bssid'] |
2165 | params = hs20_ap_params() | |
2166 | hostapd.add_ap(apdev[0]['ifname'], params) | |
2167 | ||
2168 | dev[0].hs20_enable() | |
2169 | values = { 'realm': "example.com", | |
2170 | 'username': "hs20-test", | |
2171 | 'password': "password", | |
2172 | 'domain': "example.com" } | |
2173 | dev[0].add_cred_values(values) | |
2174 | ||
2175 | dev[0].scan_for_bss(bssid, freq="2412") | |
2176 | dev[0].request("INTERWORKING_SELECT auto freq=2412") | |
2177 | if "FAIL-BUSY" not in dev[0].request("SCAN"): | |
2178 | raise Exception("Unexpected SCAN command result") | |
2179 | dev[0].wait_connected(timeout=15) | |
2180 | ||
97de642a JM |
2181 | def test_ap_hs20_fetch_osu(dev, apdev): |
2182 | """Hotspot 2.0 OSU provider and icon fetch""" | |
2183 | bssid = apdev[0]['bssid'] | |
2184 | params = hs20_ap_params() | |
2185 | params['hs20_icon'] = "128:80:zxx:image/png:w1fi_logo:w1fi_logo.png" | |
2186 | params['osu_ssid'] = '"HS 2.0 OSU open"' | |
2187 | params['osu_method_list'] = "1" | |
2188 | params['osu_friendly_name'] = [ "eng:Test OSU", "fin:Testi-OSU" ] | |
2189 | params['osu_icon'] = "w1fi_logo" | |
2190 | params['osu_service_desc'] = [ "eng:Example services", "fin:Esimerkkipalveluja" ] | |
2191 | params['osu_server_uri'] = "https://example.com/osu/" | |
2192 | hostapd.add_ap(apdev[0]['ifname'], params) | |
2193 | ||
2194 | bssid2 = apdev[1]['bssid'] | |
2195 | params = hs20_ap_params(ssid="test-hs20b") | |
2196 | params['hessid'] = bssid2 | |
2197 | params['hs20_icon'] = "128:80:zxx:image/png:w1fi_logo:w1fi_logo.png" | |
2198 | params['osu_ssid'] = '"HS 2.0 OSU OSEN"' | |
2199 | params['osu_method_list'] = "0" | |
6acecce1 | 2200 | params['osu_nai'] = "osen@example.com" |
97de642a JM |
2201 | params['osu_friendly_name'] = [ "eng:Test2 OSU", "fin:Testi2-OSU" ] |
2202 | params['osu_icon'] = "w1fi_logo" | |
2203 | params['osu_service_desc'] = [ "eng:Example services2", "fin:Esimerkkipalveluja2" ] | |
2204 | params['osu_server_uri'] = "https://example.org/osu/" | |
2205 | hostapd.add_ap(apdev[1]['ifname'], params) | |
2206 | ||
2207 | with open("w1fi_logo.png", "r") as f: | |
2208 | orig_logo = f.read() | |
2209 | dev[0].hs20_enable() | |
2210 | dir = "/tmp/osu-fetch" | |
2211 | if os.path.isdir(dir): | |
2212 | files = [ f for f in os.listdir(dir) if f.startswith("osu-") ] | |
2213 | for f in files: | |
2214 | os.remove(dir + "/" + f) | |
2215 | else: | |
2216 | try: | |
2217 | os.makedirs(dir) | |
2218 | except: | |
2219 | pass | |
2220 | try: | |
0a578716 | 2221 | dev[1].scan_for_bss(bssid, freq="2412") |
446dd748 | 2222 | dev[2].scan_for_bss(bssid, freq="2412") |
97de642a JM |
2223 | dev[0].request("SET osu_dir " + dir) |
2224 | dev[0].request("FETCH_OSU") | |
44c41cdf JM |
2225 | if "FAIL" not in dev[1].request("HS20_ICON_REQUEST foo w1fi_logo"): |
2226 | raise Exception("Invalid HS20_ICON_REQUEST accepted") | |
d2fb8b86 JM |
2227 | if "OK" not in dev[1].request("HS20_ICON_REQUEST " + bssid + " w1fi_logo"): |
2228 | raise Exception("HS20_ICON_REQUEST failed") | |
446dd748 JM |
2229 | if "OK" not in dev[2].request("REQ_HS20_ICON " + bssid + " w1fi_logo"): |
2230 | raise Exception("REQ_HS20_ICON failed") | |
97de642a JM |
2231 | icons = 0 |
2232 | while True: | |
2233 | ev = dev[0].wait_event(["OSU provider fetch completed", | |
2234 | "RX-HS20-ANQP-ICON"], timeout=15) | |
2235 | if ev is None: | |
2236 | raise Exception("Timeout on OSU fetch") | |
2237 | if "OSU provider fetch completed" in ev: | |
2238 | break | |
2239 | if "RX-HS20-ANQP-ICON" in ev: | |
2240 | with open(ev.split(' ')[1], "r") as f: | |
2241 | logo = f.read() | |
2242 | if logo == orig_logo: | |
2243 | icons += 1 | |
2244 | ||
2245 | with open(dir + "/osu-providers.txt", "r") as f: | |
2246 | prov = f.read() | |
27f527e0 | 2247 | logger.debug("osu-providers.txt: " + prov) |
97de642a | 2248 | if "OSU-PROVIDER " + bssid not in prov: |
27f527e0 | 2249 | raise Exception("Missing OSU_PROVIDER(1)") |
97de642a | 2250 | if "OSU-PROVIDER " + bssid2 not in prov: |
27f527e0 | 2251 | raise Exception("Missing OSU_PROVIDER(2)") |
97de642a JM |
2252 | finally: |
2253 | files = [ f for f in os.listdir(dir) if f.startswith("osu-") ] | |
2254 | for f in files: | |
2255 | os.remove(dir + "/" + f) | |
2256 | os.rmdir(dir) | |
2257 | ||
2258 | if icons != 2: | |
2259 | raise Exception("Unexpected number of icons fetched") | |
d2fb8b86 JM |
2260 | |
2261 | ev = dev[1].wait_event(["GAS-QUERY-START"], timeout=5) | |
2262 | if ev is None: | |
2263 | raise Exception("Timeout on GAS-QUERY-DONE") | |
2264 | ev = dev[1].wait_event(["GAS-QUERY-DONE"], timeout=5) | |
2265 | if ev is None: | |
2266 | raise Exception("Timeout on GAS-QUERY-DONE") | |
2267 | if "freq=2412 status_code=0 result=SUCCESS" not in ev: | |
2268 | raise Exception("Unexpected GAS-QUERY-DONE: " + ev) | |
2269 | ev = dev[1].wait_event(["RX-HS20-ANQP"], timeout=15) | |
2270 | if ev is None: | |
2271 | raise Exception("Timeout on icon fetch") | |
2272 | if "Icon Binary File" not in ev: | |
2273 | raise Exception("Unexpected ANQP element") | |
37ffe7c5 | 2274 | |
446dd748 JM |
2275 | ev = dev[2].wait_event(["RX-HS20-ICON"], timeout=5) |
2276 | if ev is None: | |
2277 | raise Exception("Timeout on RX-HS20-ICON") | |
2278 | event_icon_len = ev.split(' ')[3] | |
2279 | if " w1fi_logo " not in ev: | |
2280 | raise Exception("RX-HS20-ICON did not have the expected file name") | |
2281 | if bssid not in ev: | |
2282 | raise Exception("RX-HS20-ICON did not have the expected BSSID") | |
2283 | if "FAIL" in dev[2].request("GET_HS20_ICON " + bssid + " w1fi_logo 0 10"): | |
2284 | raise Exception("GET_HS20_ICON 0..10 failed") | |
2285 | if "FAIL" in dev[2].request("GET_HS20_ICON " + bssid + " w1fi_logo 5 10"): | |
2286 | raise Exception("GET_HS20_ICON 5..15 failed") | |
2287 | if "FAIL" not in dev[2].request("GET_HS20_ICON " + bssid + " w1fi_logo 100000 10"): | |
2288 | raise Exception("Unexpected success of GET_HS20_ICON with too large offset") | |
2289 | icon = "" | |
2290 | pos = 0 | |
2291 | while True: | |
2292 | if pos > 100000: | |
2293 | raise Exception("Unexpectedly long icon") | |
2294 | res = dev[2].request("GET_HS20_ICON " + bssid + " w1fi_logo %d 1000" % pos) | |
2295 | if res.startswith("FAIL"): | |
2296 | break | |
2297 | icon += base64.b64decode(res) | |
2298 | pos += 1000 | |
2299 | hex = binascii.hexlify(icon) | |
2300 | if not hex.startswith("0009696d6167652f706e677d1d"): | |
2301 | raise Exception("Unexpected beacon binary header: " + hex) | |
2302 | with open('w1fi_logo.png', 'r') as f: | |
2303 | data = f.read() | |
2304 | if icon[13:] != data: | |
2305 | raise Exception("Unexpected icon data") | |
2306 | if len(icon) != int(event_icon_len): | |
2307 | raise Exception("Unexpected RX-HS20-ICON event length: " + event_icon_len) | |
2308 | ||
2309 | for i in range(3): | |
2310 | if "OK" not in dev[i].request("REQ_HS20_ICON " + bssid + " w1fi_logo"): | |
2311 | raise Exception("REQ_HS20_ICON failed [2]") | |
2312 | for i in range(3): | |
2313 | ev = dev[i].wait_event(["RX-HS20-ICON"], timeout=5) | |
2314 | if ev is None: | |
2315 | raise Exception("Timeout on RX-HS20-ICON [2]") | |
2316 | ||
2317 | if "FAIL" not in dev[2].request("DEL_HS20_ICON foo w1fi_logo"): | |
2318 | raise Exception("Invalid DEL_HS20_ICON accepted") | |
2319 | if "OK" not in dev[2].request("DEL_HS20_ICON " + bssid + " w1fi_logo"): | |
2320 | raise Exception("DEL_HS20_ICON failed") | |
2321 | if "OK" not in dev[1].request("DEL_HS20_ICON " + bssid): | |
2322 | raise Exception("DEL_HS20_ICON failed") | |
2323 | if "OK" not in dev[0].request("DEL_HS20_ICON "): | |
2324 | raise Exception("DEL_HS20_ICON failed") | |
2325 | for i in range(3): | |
2326 | if "FAIL" not in dev[i].request("DEL_HS20_ICON "): | |
2327 | raise Exception("DEL_HS20_ICON accepted when no icons left") | |
2328 | ||
69f99123 JM |
2329 | def test_ap_hs20_fetch_osu_stop(dev, apdev): |
2330 | """Hotspot 2.0 OSU provider fetch stopped""" | |
2331 | bssid = apdev[0]['bssid'] | |
2332 | params = hs20_ap_params() | |
2333 | params['hs20_icon'] = "128:80:zxx:image/png:w1fi_logo:w1fi_logo.png" | |
2334 | params['osu_ssid'] = '"HS 2.0 OSU open"' | |
2335 | params['osu_method_list'] = "1" | |
2336 | params['osu_friendly_name'] = [ "eng:Test OSU", "fin:Testi-OSU" ] | |
2337 | params['osu_icon'] = "w1fi_logo" | |
2338 | params['osu_service_desc'] = [ "eng:Example services", "fin:Esimerkkipalveluja" ] | |
2339 | params['osu_server_uri'] = "https://example.com/osu/" | |
2340 | hapd = hostapd.add_ap(apdev[0]['ifname'], params) | |
2341 | ||
2342 | dev[0].hs20_enable() | |
2343 | dir = "/tmp/osu-fetch" | |
2344 | if os.path.isdir(dir): | |
2345 | files = [ f for f in os.listdir(dir) if f.startswith("osu-") ] | |
2346 | for f in files: | |
2347 | os.remove(dir + "/" + f) | |
2348 | else: | |
2349 | try: | |
2350 | os.makedirs(dir) | |
2351 | except: | |
2352 | pass | |
2353 | try: | |
2354 | dev[0].request("SET osu_dir " + dir) | |
2355 | dev[0].request("SCAN freq=2412-2462") | |
2356 | ev = dev[0].wait_event(["CTRL-EVENT-SCAN-STARTED"], timeout=10) | |
2357 | if ev is None: | |
2358 | raise Exception("Scan did not start") | |
2359 | if "FAIL" not in dev[0].request("FETCH_OSU"): | |
2360 | raise Exception("FETCH_OSU accepted while scanning") | |
2361 | ev = dev[0].wait_event(["CTRL-EVENT-SCAN-RESULTS"], 10) | |
2362 | if ev is None: | |
2363 | raise Exception("Scan timed out") | |
2364 | hapd.set("ext_mgmt_frame_handling", "1") | |
2365 | dev[0].request("FETCH_ANQP") | |
2366 | if "FAIL" not in dev[0].request("FETCH_OSU"): | |
2367 | raise Exception("FETCH_OSU accepted while in FETCH_ANQP") | |
2368 | dev[0].request("STOP_FETCH_ANQP") | |
2369 | dev[0].wait_event(["GAS-QUERY-DONE"], timeout=5) | |
2370 | dev[0].dump_monitor() | |
2371 | hapd.dump_monitor() | |
2372 | dev[0].request("INTERWORKING_SELECT freq=2412") | |
2373 | for i in range(5): | |
2374 | msg = hapd.mgmt_rx() | |
2375 | if msg['subtype'] == 13: | |
2376 | break | |
2377 | if "FAIL" not in dev[0].request("FETCH_OSU"): | |
2378 | raise Exception("FETCH_OSU accepted while in INTERWORKING_SELECT") | |
2379 | ev = dev[0].wait_event(["INTERWORKING-AP", "INTERWORKING-NO-MATCH"], | |
2380 | timeout=15) | |
2381 | if ev is None: | |
2382 | raise Exception("Network selection timed out"); | |
2383 | ||
2384 | dev[0].dump_monitor() | |
2385 | if "OK" not in dev[0].request("FETCH_OSU"): | |
2386 | raise Exception("FETCH_OSU failed") | |
2387 | dev[0].request("CANCEL_FETCH_OSU") | |
2388 | ||
2389 | for i in range(15): | |
2390 | time.sleep(0.5) | |
2391 | if dev[0].get_driver_status_field("scan_state") == "SCAN_COMPLETED": | |
2392 | break | |
2393 | ||
2394 | dev[0].dump_monitor() | |
2395 | if "OK" not in dev[0].request("FETCH_OSU"): | |
2396 | raise Exception("FETCH_OSU failed") | |
2397 | if "FAIL" not in dev[0].request("FETCH_OSU"): | |
2398 | raise Exception("FETCH_OSU accepted while in FETCH_OSU") | |
2399 | ev = dev[0].wait_event(["GAS-QUERY-START"], 10) | |
2400 | if ev is None: | |
2401 | raise Exception("GAS timed out") | |
2402 | if "FAIL" not in dev[0].request("FETCH_OSU"): | |
2403 | raise Exception("FETCH_OSU accepted while in FETCH_OSU") | |
2404 | dev[0].request("CANCEL_FETCH_OSU") | |
2405 | ev = dev[0].wait_event(["GAS-QUERY-DONE"], 10) | |
2406 | if ev is None: | |
2407 | raise Exception("GAS event timed out after CANCEL_FETCH_OSU") | |
2408 | finally: | |
2409 | files = [ f for f in os.listdir(dir) if f.startswith("osu-") ] | |
2410 | for f in files: | |
2411 | os.remove(dir + "/" + f) | |
2412 | os.rmdir(dir) | |
2413 | ||
37ffe7c5 JM |
2414 | def test_ap_hs20_ft(dev, apdev): |
2415 | """Hotspot 2.0 connection with FT""" | |
e7ac04ce | 2416 | check_eap_capa(dev[0], "MSCHAPV2") |
37ffe7c5 JM |
2417 | bssid = apdev[0]['bssid'] |
2418 | params = hs20_ap_params() | |
2419 | params['wpa_key_mgmt'] = "FT-EAP" | |
2420 | params['nas_identifier'] = "nas1.w1.fi" | |
2421 | params['r1_key_holder'] = "000102030405" | |
2422 | params["mobility_domain"] = "a1b2" | |
2423 | params["reassociation_deadline"] = "1000" | |
2424 | hostapd.add_ap(apdev[0]['ifname'], params) | |
2425 | ||
2426 | dev[0].hs20_enable() | |
2427 | id = dev[0].add_cred_values({ 'realm': "example.com", | |
2428 | 'username': "hs20-test", | |
2429 | 'password': "password", | |
2430 | 'ca_cert': "auth_serv/ca.pem", | |
2431 | 'domain': "example.com", | |
2432 | 'update_identifier': "1234" }) | |
2433 | interworking_select(dev[0], bssid, "home", freq="2412") | |
2434 | interworking_connect(dev[0], bssid, "TTLS") | |
350a7ba9 JM |
2435 | |
2436 | def test_ap_hs20_remediation_sql(dev, apdev, params): | |
2437 | """Hotspot 2.0 connection and remediation required using SQLite for user DB""" | |
e7ac04ce | 2438 | check_eap_capa(dev[0], "MSCHAPV2") |
350a7ba9 JM |
2439 | try: |
2440 | import sqlite3 | |
2441 | except ImportError: | |
81e787b7 | 2442 | raise HwsimSkip("No sqlite3 module available") |
350a7ba9 JM |
2443 | dbfile = os.path.join(params['logdir'], "eap-user.db") |
2444 | try: | |
2445 | os.remove(dbfile) | |
2446 | except: | |
2447 | pass | |
2448 | con = sqlite3.connect(dbfile) | |
2449 | with con: | |
2450 | cur = con.cursor() | |
2451 | cur.execute("CREATE TABLE users(identity TEXT PRIMARY KEY, methods TEXT, password TEXT, remediation TEXT, phase2 INTEGER)") | |
2452 | cur.execute("CREATE TABLE wildcards(identity TEXT PRIMARY KEY, methods TEXT)") | |
2453 | cur.execute("INSERT INTO users(identity,methods,password,phase2,remediation) VALUES ('user-mschapv2','TTLS-MSCHAPV2','password',1,'user')") | |
2454 | cur.execute("INSERT INTO wildcards(identity,methods) VALUES ('','TTLS,TLS')") | |
2455 | cur.execute("CREATE TABLE authlog(timestamp TEXT, session TEXT, nas_ip TEXT, username TEXT, note TEXT)") | |
2456 | ||
2457 | try: | |
2458 | params = { "ssid": "as", "beacon_int": "2000", | |
2459 | "radius_server_clients": "auth_serv/radius_clients.conf", | |
2460 | "radius_server_auth_port": '18128', | |
2461 | "eap_server": "1", | |
2462 | "eap_user_file": "sqlite:" + dbfile, | |
2463 | "ca_cert": "auth_serv/ca.pem", | |
2464 | "server_cert": "auth_serv/server.pem", | |
2465 | "private_key": "auth_serv/server.key", | |
2466 | "subscr_remediation_url": "https://example.org/", | |
2467 | "subscr_remediation_method": "1" } | |
2468 | hostapd.add_ap(apdev[1]['ifname'], params) | |
2469 | ||
2470 | bssid = apdev[0]['bssid'] | |
2471 | params = hs20_ap_params() | |
2472 | params['auth_server_port'] = "18128" | |
2473 | hostapd.add_ap(apdev[0]['ifname'], params) | |
2474 | ||
2475 | dev[0].request("SET pmf 1") | |
2476 | dev[0].hs20_enable() | |
2477 | id = dev[0].add_cred_values({ 'realm': "example.com", | |
2478 | 'username': "user-mschapv2", | |
2479 | 'password': "password", | |
2480 | 'ca_cert': "auth_serv/ca.pem" }) | |
2481 | interworking_select(dev[0], bssid, freq="2412") | |
2482 | interworking_connect(dev[0], bssid, "TTLS") | |
2483 | ev = dev[0].wait_event(["HS20-SUBSCRIPTION-REMEDIATION"], timeout=5) | |
2484 | if ev is None: | |
2485 | raise Exception("Timeout on subscription remediation notice") | |
2486 | if " 1 https://example.org/" not in ev: | |
2487 | raise Exception("Unexpected subscription remediation event contents") | |
2488 | ||
2489 | with con: | |
2490 | cur = con.cursor() | |
2491 | cur.execute("SELECT * from authlog") | |
2492 | rows = cur.fetchall() | |
2493 | if len(rows) < 1: | |
2494 | raise Exception("No authlog entries") | |
2495 | ||
2496 | finally: | |
2497 | os.remove(dbfile) | |
909f13cc | 2498 | dev[0].request("SET pmf 0") |
f1a36a53 JM |
2499 | |
2500 | def test_ap_hs20_external_selection(dev, apdev): | |
2501 | """Hotspot 2.0 connection using external network selection and creation""" | |
e7ac04ce | 2502 | check_eap_capa(dev[0], "MSCHAPV2") |
f1a36a53 JM |
2503 | bssid = apdev[0]['bssid'] |
2504 | params = hs20_ap_params() | |
2505 | params['hessid'] = bssid | |
2506 | params['disable_dgaf'] = '1' | |
2507 | hostapd.add_ap(apdev[0]['ifname'], params) | |
2508 | ||
2509 | dev[0].hs20_enable() | |
2510 | dev[0].connect("test-hs20", proto="RSN", key_mgmt="WPA-EAP", eap="TTLS", | |
2511 | identity="hs20-test", password="password", | |
2512 | ca_cert="auth_serv/ca.pem", phase2="auth=MSCHAPV2", | |
2513 | scan_freq="2412", update_identifier="54321") | |
2514 | if dev[0].get_status_field("hs20") != "2": | |
2515 | raise Exception("Unexpected hs20 indication") | |
816e3df9 JM |
2516 | |
2517 | def test_ap_hs20_random_mac_addr(dev, apdev): | |
2518 | """Hotspot 2.0 connection with random MAC address""" | |
e7ac04ce | 2519 | check_eap_capa(dev[0], "MSCHAPV2") |
816e3df9 JM |
2520 | bssid = apdev[0]['bssid'] |
2521 | params = hs20_ap_params() | |
2522 | params['hessid'] = bssid | |
2523 | params['disable_dgaf'] = '1' | |
2524 | hapd = hostapd.add_ap(apdev[0]['ifname'], params) | |
2525 | ||
2526 | wpas = WpaSupplicant(global_iface='/tmp/wpas-wlan5') | |
2527 | wpas.interface_add("wlan5") | |
2528 | addr = wpas.p2p_interface_addr() | |
2529 | wpas.request("SET mac_addr 1") | |
2530 | wpas.request("SET preassoc_mac_addr 1") | |
2531 | wpas.request("SET rand_addr_lifetime 60") | |
2532 | wpas.hs20_enable() | |
243dcc4a | 2533 | wpas.flush_scan_cache() |
816e3df9 JM |
2534 | id = wpas.add_cred_values({ 'realm': "example.com", |
2535 | 'username': "hs20-test", | |
2536 | 'password': "password", | |
2537 | 'ca_cert': "auth_serv/ca.pem", | |
2538 | 'domain': "example.com", | |
2539 | 'update_identifier': "1234" }) | |
2540 | interworking_select(wpas, bssid, "home", freq="2412") | |
2541 | interworking_connect(wpas, bssid, "TTLS") | |
816e3df9 JM |
2542 | addr1 = wpas.get_driver_status_field("addr") |
2543 | if addr == addr1: | |
2544 | raise Exception("Did not use random MAC address") | |
2545 | ||
2546 | sta = hapd.get_sta(addr) | |
2547 | if sta['addr'] != "FAIL": | |
2548 | raise Exception("Unexpected STA association with permanent address") | |
2549 | sta = hapd.get_sta(addr1) | |
2550 | if sta['addr'] != addr1: | |
2551 | raise Exception("STA association with random address not found") | |
5f7b07de | 2552 | |
76b76941 JM |
2553 | def test_ap_hs20_multi_network_and_cred_removal(dev, apdev): |
2554 | """Multiple networks and cred removal""" | |
e7ac04ce | 2555 | check_eap_capa(dev[0], "MSCHAPV2") |
76b76941 JM |
2556 | bssid = apdev[0]['bssid'] |
2557 | params = hs20_ap_params() | |
2558 | params['nai_realm'] = [ "0,example.com,25[3:26]"] | |
2559 | hapd = hostapd.add_ap(apdev[0]['ifname'], params) | |
2560 | ||
2561 | dev[0].add_network() | |
2562 | dev[0].hs20_enable() | |
2563 | id = dev[0].add_cred_values({ 'realm': "example.com", | |
2564 | 'username': "user", | |
2565 | 'password': "password" }) | |
2566 | interworking_select(dev[0], bssid, freq="2412") | |
2567 | interworking_connect(dev[0], bssid, "PEAP") | |
2568 | dev[0].add_network() | |
2569 | ||
2570 | dev[0].request("DISCONNECT") | |
5f35a5e2 | 2571 | dev[0].wait_disconnected(timeout=10) |
76b76941 JM |
2572 | |
2573 | hapd.disable() | |
2574 | hapd.set("ssid", "another ssid") | |
2575 | hapd.enable() | |
2576 | ||
2577 | interworking_select(dev[0], bssid, freq="2412") | |
2578 | interworking_connect(dev[0], bssid, "PEAP") | |
2579 | dev[0].add_network() | |
2580 | if len(dev[0].list_networks()) != 5: | |
2581 | raise Exception("Unexpected number of networks prior to remove_crec") | |
2582 | ||
2583 | dev[0].dump_monitor() | |
2584 | dev[0].remove_cred(id) | |
2585 | if len(dev[0].list_networks()) != 3: | |
2586 | raise Exception("Unexpected number of networks after to remove_crec") | |
5f35a5e2 | 2587 | dev[0].wait_disconnected(timeout=10) |
76b76941 | 2588 | |
22653762 JM |
2589 | def test_ap_hs20_interworking_add_network(dev, apdev): |
2590 | """Hotspot 2.0 connection using INTERWORKING_ADD_NETWORK""" | |
e7ac04ce | 2591 | check_eap_capa(dev[0], "MSCHAPV2") |
22653762 JM |
2592 | bssid = apdev[0]['bssid'] |
2593 | params = hs20_ap_params() | |
2594 | params['nai_realm'] = [ "0,example.com,21[3:26][6:7][99:99]" ] | |
2595 | hostapd.add_ap(apdev[0]['ifname'], params) | |
2596 | ||
2597 | dev[0].hs20_enable() | |
2598 | dev[0].add_cred_values(default_cred(user="user")) | |
2599 | interworking_select(dev[0], bssid, freq=2412) | |
2600 | id = dev[0].interworking_add_network(bssid) | |
2601 | dev[0].select_network(id, freq=2412) | |
2602 | dev[0].wait_connected() | |
2603 | ||
5f7b07de JM |
2604 | def _test_ap_hs20_proxyarp(dev, apdev): |
2605 | bssid = apdev[0]['bssid'] | |
2606 | params = hs20_ap_params() | |
2607 | params['hessid'] = bssid | |
2608 | params['disable_dgaf'] = '0' | |
2609 | params['proxy_arp'] = '1' | |
2610 | hapd = hostapd.add_ap(apdev[0]['ifname'], params, no_enable=True) | |
2611 | if "OK" in hapd.request("ENABLE"): | |
2612 | raise Exception("Incomplete hostapd configuration was accepted") | |
2613 | hapd.set("ap_isolate", "1") | |
2614 | if "OK" in hapd.request("ENABLE"): | |
2615 | raise Exception("Incomplete hostapd configuration was accepted") | |
2616 | hapd.set('bridge', 'ap-br0') | |
2617 | hapd.dump_monitor() | |
2618 | try: | |
2619 | hapd.enable() | |
2620 | except: | |
2621 | # For now, do not report failures due to missing kernel support | |
81e787b7 | 2622 | raise HwsimSkip("Could not start hostapd - assume proxyarp not supported in kernel version") |
5f7b07de JM |
2623 | ev = hapd.wait_event(["AP-ENABLED", "AP-DISABLED"], timeout=10) |
2624 | if ev is None: | |
2625 | raise Exception("AP startup timed out") | |
2626 | if "AP-ENABLED" not in ev: | |
2627 | raise Exception("AP startup failed") | |
2628 | ||
2629 | dev[0].hs20_enable() | |
2630 | subprocess.call(['brctl', 'setfd', 'ap-br0', '0']) | |
2631 | subprocess.call(['ip', 'link', 'set', 'dev', 'ap-br0', 'up']) | |
5f7b07de JM |
2632 | |
2633 | id = dev[0].add_cred_values({ 'realm': "example.com", | |
2634 | 'username': "hs20-test", | |
2635 | 'password': "password", | |
2636 | 'ca_cert': "auth_serv/ca.pem", | |
2637 | 'domain': "example.com", | |
2638 | 'update_identifier': "1234" }) | |
2639 | interworking_select(dev[0], bssid, "home", freq="2412") | |
2640 | interworking_connect(dev[0], bssid, "TTLS") | |
2641 | ||
2642 | dev[1].connect("test-hs20", key_mgmt="WPA-EAP", eap="TTLS", | |
2643 | identity="hs20-test", password="password", | |
2644 | ca_cert="auth_serv/ca.pem", phase2="auth=MSCHAPV2", | |
2645 | scan_freq="2412") | |
2646 | time.sleep(0.1) | |
2647 | ||
67aeee11 JM |
2648 | addr0 = dev[0].p2p_interface_addr() |
2649 | addr1 = dev[1].p2p_interface_addr() | |
2650 | ||
2651 | src_ll_opt0 = "\x01\x01" + binascii.unhexlify(addr0.replace(':','')) | |
2652 | src_ll_opt1 = "\x01\x01" + binascii.unhexlify(addr1.replace(':','')) | |
2653 | ||
2654 | pkt = build_ns(src_ll=addr0, ip_src="aaaa:bbbb:cccc::2", | |
2655 | ip_dst="ff02::1:ff00:2", target="aaaa:bbbb:cccc::2", | |
2656 | opt=src_ll_opt0) | |
2657 | if "OK" not in dev[0].request("DATA_TEST_FRAME " + binascii.hexlify(pkt)): | |
2658 | raise Exception("DATA_TEST_FRAME failed") | |
2659 | ||
2660 | pkt = build_ns(src_ll=addr1, ip_src="aaaa:bbbb:dddd::2", | |
2661 | ip_dst="ff02::1:ff00:2", target="aaaa:bbbb:dddd::2", | |
2662 | opt=src_ll_opt1) | |
2663 | if "OK" not in dev[1].request("DATA_TEST_FRAME " + binascii.hexlify(pkt)): | |
2664 | raise Exception("DATA_TEST_FRAME failed") | |
2665 | ||
2666 | pkt = build_ns(src_ll=addr1, ip_src="aaaa:bbbb:eeee::2", | |
2667 | ip_dst="ff02::1:ff00:2", target="aaaa:bbbb:eeee::2", | |
2668 | opt=src_ll_opt1) | |
2669 | if "OK" not in dev[1].request("DATA_TEST_FRAME " + binascii.hexlify(pkt)): | |
2670 | raise Exception("DATA_TEST_FRAME failed") | |
2671 | ||
5f7b07de JM |
2672 | matches = get_permanent_neighbors("ap-br0") |
2673 | logger.info("After connect: " + str(matches)) | |
67aeee11 JM |
2674 | if len(matches) != 3: |
2675 | raise Exception("Unexpected number of neighbor entries after connect") | |
2676 | if 'aaaa:bbbb:cccc::2 dev ap-br0 lladdr 02:00:00:00:00:00 PERMANENT' not in matches: | |
2677 | raise Exception("dev0 addr missing") | |
2678 | if 'aaaa:bbbb:dddd::2 dev ap-br0 lladdr 02:00:00:00:01:00 PERMANENT' not in matches: | |
2679 | raise Exception("dev1 addr(1) missing") | |
2680 | if 'aaaa:bbbb:eeee::2 dev ap-br0 lladdr 02:00:00:00:01:00 PERMANENT' not in matches: | |
2681 | raise Exception("dev1 addr(2) missing") | |
5f7b07de JM |
2682 | dev[0].request("DISCONNECT") |
2683 | dev[1].request("DISCONNECT") | |
2684 | time.sleep(0.5) | |
2685 | matches = get_permanent_neighbors("ap-br0") | |
2686 | logger.info("After disconnect: " + str(matches)) | |
2687 | if len(matches) > 0: | |
2688 | raise Exception("Unexpected neighbor entries after disconnect") | |
2689 | ||
e1f8fe88 JM |
2690 | def test_ap_hs20_hidden_ssid_in_scan_res(dev, apdev): |
2691 | """Hotspot 2.0 connection with hidden SSId in scan results""" | |
e7ac04ce | 2692 | check_eap_capa(dev[0], "MSCHAPV2") |
e1f8fe88 JM |
2693 | bssid = apdev[0]['bssid'] |
2694 | ||
2695 | hapd = hostapd.add_ap(apdev[0]['ifname'], { "ssid": 'secret', | |
2696 | "ignore_broadcast_ssid": "1" }) | |
2697 | dev[0].scan_for_bss(bssid, freq=2412) | |
2698 | hapd.disable() | |
2699 | hapd_global = hostapd.HostapdGlobal() | |
2700 | hapd_global.flush() | |
2701 | hapd_global.remove(apdev[0]['ifname']) | |
2702 | ||
2703 | params = hs20_ap_params() | |
2704 | params['hessid'] = bssid | |
45de3286 | 2705 | hapd = hostapd.add_ap(apdev[0]['ifname'], params) |
e1f8fe88 JM |
2706 | |
2707 | dev[0].hs20_enable() | |
2708 | id = dev[0].add_cred_values({ 'realm': "example.com", | |
2709 | 'username': "hs20-test", | |
2710 | 'password': "password", | |
2711 | 'ca_cert': "auth_serv/ca.pem", | |
2712 | 'domain': "example.com" }) | |
2713 | interworking_select(dev[0], bssid, "home", freq="2412") | |
2714 | interworking_connect(dev[0], bssid, "TTLS") | |
2715 | ||
2716 | # clear BSS table to avoid issues in following test cases | |
2717 | dev[0].request("DISCONNECT") | |
2718 | dev[0].wait_disconnected() | |
45de3286 JM |
2719 | hapd.disable() |
2720 | dev[0].flush_scan_cache() | |
e1f8fe88 JM |
2721 | dev[0].flush_scan_cache() |
2722 | ||
5f7b07de JM |
2723 | def test_ap_hs20_proxyarp(dev, apdev): |
2724 | """Hotspot 2.0 and ProxyARP""" | |
e7ac04ce | 2725 | check_eap_capa(dev[0], "MSCHAPV2") |
5f7b07de | 2726 | try: |
81e787b7 | 2727 | _test_ap_hs20_proxyarp(dev, apdev) |
5f7b07de JM |
2728 | finally: |
2729 | subprocess.call(['ip', 'link', 'set', 'dev', 'ap-br0', 'down'], | |
2730 | stderr=open('/dev/null', 'w')) | |
2731 | subprocess.call(['brctl', 'delbr', 'ap-br0'], | |
2732 | stderr=open('/dev/null', 'w')) | |
5f7b07de | 2733 | |
356a497d JM |
2734 | def _test_ap_hs20_proxyarp_dgaf(dev, apdev, disabled): |
2735 | bssid = apdev[0]['bssid'] | |
2736 | params = hs20_ap_params() | |
2737 | params['hessid'] = bssid | |
2738 | params['disable_dgaf'] = '1' if disabled else '0' | |
2739 | params['proxy_arp'] = '1' | |
798c7951 | 2740 | params['na_mcast_to_ucast'] = '1' |
356a497d JM |
2741 | params['ap_isolate'] = '1' |
2742 | params['bridge'] = 'ap-br0' | |
2743 | hapd = hostapd.add_ap(apdev[0]['ifname'], params, no_enable=True) | |
2744 | try: | |
2745 | hapd.enable() | |
2746 | except: | |
2747 | # For now, do not report failures due to missing kernel support | |
81e787b7 | 2748 | raise HwsimSkip("Could not start hostapd - assume proxyarp not supported in kernel version") |
356a497d JM |
2749 | ev = hapd.wait_event(["AP-ENABLED"], timeout=10) |
2750 | if ev is None: | |
2751 | raise Exception("AP startup timed out") | |
2752 | ||
2753 | dev[0].hs20_enable() | |
2754 | subprocess.call(['brctl', 'setfd', 'ap-br0', '0']) | |
2755 | subprocess.call(['ip', 'link', 'set', 'dev', 'ap-br0', 'up']) | |
2756 | ||
2757 | id = dev[0].add_cred_values({ 'realm': "example.com", | |
2758 | 'username': "hs20-test", | |
2759 | 'password': "password", | |
2760 | 'ca_cert': "auth_serv/ca.pem", | |
2761 | 'domain': "example.com", | |
2762 | 'update_identifier': "1234" }) | |
2763 | interworking_select(dev[0], bssid, "home", freq="2412") | |
2764 | interworking_connect(dev[0], bssid, "TTLS") | |
2765 | ||
2766 | dev[1].connect("test-hs20", key_mgmt="WPA-EAP", eap="TTLS", | |
2767 | identity="hs20-test", password="password", | |
2768 | ca_cert="auth_serv/ca.pem", phase2="auth=MSCHAPV2", | |
2769 | scan_freq="2412") | |
2770 | time.sleep(0.1) | |
2771 | ||
2772 | addr0 = dev[0].p2p_interface_addr() | |
2773 | ||
2774 | src_ll_opt0 = "\x01\x01" + binascii.unhexlify(addr0.replace(':','')) | |
2775 | ||
2776 | pkt = build_ns(src_ll=addr0, ip_src="aaaa:bbbb:cccc::2", | |
2777 | ip_dst="ff02::1:ff00:2", target="aaaa:bbbb:cccc::2", | |
2778 | opt=src_ll_opt0) | |
2779 | if "OK" not in dev[0].request("DATA_TEST_FRAME " + binascii.hexlify(pkt)): | |
2780 | raise Exception("DATA_TEST_FRAME failed") | |
2781 | ||
2782 | pkt = build_ra(src_ll=apdev[0]['bssid'], ip_src="aaaa:bbbb:cccc::33", | |
2783 | ip_dst="ff01::1") | |
2784 | if "OK" not in hapd.request("DATA_TEST_FRAME ifname=ap-br0 " + binascii.hexlify(pkt)): | |
2785 | raise Exception("DATA_TEST_FRAME failed") | |
2786 | ||
2787 | pkt = build_na(src_ll=apdev[0]['bssid'], ip_src="aaaa:bbbb:cccc::44", | |
2788 | ip_dst="ff01::1", target="aaaa:bbbb:cccc::55") | |
2789 | if "OK" not in hapd.request("DATA_TEST_FRAME ifname=ap-br0 " + binascii.hexlify(pkt)): | |
2790 | raise Exception("DATA_TEST_FRAME failed") | |
2791 | ||
a712282b JM |
2792 | pkt = build_dhcp_ack(dst_ll="ff:ff:ff:ff:ff:ff", src_ll=bssid, |
2793 | ip_src="192.168.1.1", ip_dst="255.255.255.255", | |
2794 | yiaddr="192.168.1.123", chaddr=addr0) | |
2795 | if "OK" not in hapd.request("DATA_TEST_FRAME ifname=ap-br0 " + binascii.hexlify(pkt)): | |
2796 | raise Exception("DATA_TEST_FRAME failed") | |
2797 | # another copy for additional code coverage | |
2798 | pkt = build_dhcp_ack(dst_ll=addr0, src_ll=bssid, | |
2799 | ip_src="192.168.1.1", ip_dst="255.255.255.255", | |
2800 | yiaddr="192.168.1.123", chaddr=addr0) | |
2801 | if "OK" not in hapd.request("DATA_TEST_FRAME ifname=ap-br0 " + binascii.hexlify(pkt)): | |
2802 | raise Exception("DATA_TEST_FRAME failed") | |
2803 | ||
356a497d JM |
2804 | matches = get_permanent_neighbors("ap-br0") |
2805 | logger.info("After connect: " + str(matches)) | |
a712282b | 2806 | if len(matches) != 2: |
356a497d JM |
2807 | raise Exception("Unexpected number of neighbor entries after connect") |
2808 | if 'aaaa:bbbb:cccc::2 dev ap-br0 lladdr 02:00:00:00:00:00 PERMANENT' not in matches: | |
2809 | raise Exception("dev0 addr missing") | |
a712282b JM |
2810 | if '192.168.1.123 dev ap-br0 lladdr 02:00:00:00:00:00 PERMANENT' not in matches: |
2811 | raise Exception("dev0 IPv4 addr missing") | |
356a497d JM |
2812 | dev[0].request("DISCONNECT") |
2813 | dev[1].request("DISCONNECT") | |
2814 | time.sleep(0.5) | |
2815 | matches = get_permanent_neighbors("ap-br0") | |
2816 | logger.info("After disconnect: " + str(matches)) | |
2817 | if len(matches) > 0: | |
2818 | raise Exception("Unexpected neighbor entries after disconnect") | |
2819 | ||
2820 | def test_ap_hs20_proxyarp_disable_dgaf(dev, apdev): | |
2821 | """Hotspot 2.0 and ProxyARP with DGAF disabled""" | |
e7ac04ce | 2822 | check_eap_capa(dev[0], "MSCHAPV2") |
356a497d | 2823 | try: |
81e787b7 | 2824 | _test_ap_hs20_proxyarp_dgaf(dev, apdev, True) |
356a497d JM |
2825 | finally: |
2826 | subprocess.call(['ip', 'link', 'set', 'dev', 'ap-br0', 'down'], | |
2827 | stderr=open('/dev/null', 'w')) | |
2828 | subprocess.call(['brctl', 'delbr', 'ap-br0'], | |
2829 | stderr=open('/dev/null', 'w')) | |
2830 | ||
356a497d JM |
2831 | def test_ap_hs20_proxyarp_enable_dgaf(dev, apdev): |
2832 | """Hotspot 2.0 and ProxyARP with DGAF enabled""" | |
e7ac04ce | 2833 | check_eap_capa(dev[0], "MSCHAPV2") |
356a497d | 2834 | try: |
81e787b7 | 2835 | _test_ap_hs20_proxyarp_dgaf(dev, apdev, False) |
356a497d JM |
2836 | finally: |
2837 | subprocess.call(['ip', 'link', 'set', 'dev', 'ap-br0', 'down'], | |
2838 | stderr=open('/dev/null', 'w')) | |
2839 | subprocess.call(['brctl', 'delbr', 'ap-br0'], | |
2840 | stderr=open('/dev/null', 'w')) | |
2841 | ||
67aeee11 JM |
2842 | def ip_checksum(buf): |
2843 | sum = 0 | |
2844 | if len(buf) & 0x01: | |
2845 | buf += '\0x00' | |
2846 | for i in range(0, len(buf), 2): | |
2847 | val, = struct.unpack('H', buf[i:i+2]) | |
2848 | sum += val | |
2849 | while (sum >> 16): | |
2850 | sum = (sum & 0xffff) + (sum >> 16) | |
2851 | return struct.pack('H', ~sum & 0xffff) | |
2852 | ||
5a3ce802 JM |
2853 | def ipv6_solicited_node_mcaddr(target): |
2854 | prefix = socket.inet_pton(socket.AF_INET6, "ff02::1:ff00:0") | |
2855 | mask = socket.inet_pton(socket.AF_INET6, "::ff:ffff") | |
2856 | _target = socket.inet_pton(socket.AF_INET6, target) | |
2857 | p = struct.unpack('4I', prefix) | |
2858 | m = struct.unpack('4I', mask) | |
2859 | t = struct.unpack('4I', _target) | |
2860 | res = (p[0] | (t[0] & m[0]), | |
2861 | p[1] | (t[1] & m[1]), | |
2862 | p[2] | (t[2] & m[2]), | |
2863 | p[3] | (t[3] & m[3])) | |
2864 | return socket.inet_ntop(socket.AF_INET6, struct.pack('4I', *res)) | |
2865 | ||
67aeee11 JM |
2866 | def build_icmpv6(ipv6_addrs, type, code, payload): |
2867 | start = struct.pack("BB", type, code) | |
2868 | end = payload | |
2869 | icmp = start + '\x00\x00' + end | |
2870 | pseudo = ipv6_addrs + struct.pack(">LBBBB", len(icmp), 0, 0, 0, 58) | |
2871 | csum = ip_checksum(pseudo + icmp) | |
2872 | return start + csum + end | |
2873 | ||
356a497d JM |
2874 | def build_ra(src_ll, ip_src, ip_dst, cur_hop_limit=0, router_lifetime=0, |
2875 | reachable_time=0, retrans_timer=0, opt=None): | |
2876 | link_mc = binascii.unhexlify("3333ff000002") | |
2877 | _src_ll = binascii.unhexlify(src_ll.replace(':','')) | |
2878 | proto = '\x86\xdd' | |
2879 | ehdr = link_mc + _src_ll + proto | |
2880 | _ip_src = socket.inet_pton(socket.AF_INET6, ip_src) | |
2881 | _ip_dst = socket.inet_pton(socket.AF_INET6, ip_dst) | |
2882 | ||
2883 | adv = struct.pack('>BBHLL', cur_hop_limit, 0, router_lifetime, | |
2884 | reachable_time, retrans_timer) | |
2885 | if opt: | |
2886 | payload = adv + opt | |
2887 | else: | |
2888 | payload = adv | |
2889 | icmp = build_icmpv6(_ip_src + _ip_dst, 134, 0, payload) | |
2890 | ||
2891 | ipv6 = struct.pack('>BBBBHBB', 0x60, 0, 0, 0, len(icmp), 58, 255) | |
2892 | ipv6 += _ip_src + _ip_dst | |
2893 | ||
2894 | return ehdr + ipv6 + icmp | |
2895 | ||
67aeee11 JM |
2896 | def build_ns(src_ll, ip_src, ip_dst, target, opt=None): |
2897 | link_mc = binascii.unhexlify("3333ff000002") | |
2898 | _src_ll = binascii.unhexlify(src_ll.replace(':','')) | |
2899 | proto = '\x86\xdd' | |
2900 | ehdr = link_mc + _src_ll + proto | |
2901 | _ip_src = socket.inet_pton(socket.AF_INET6, ip_src) | |
5a3ce802 JM |
2902 | if ip_dst is None: |
2903 | ip_dst = ipv6_solicited_node_mcaddr(target) | |
67aeee11 JM |
2904 | _ip_dst = socket.inet_pton(socket.AF_INET6, ip_dst) |
2905 | ||
2906 | reserved = '\x00\x00\x00\x00' | |
2907 | _target = socket.inet_pton(socket.AF_INET6, target) | |
2908 | if opt: | |
2909 | payload = reserved + _target + opt | |
2910 | else: | |
2911 | payload = reserved + _target | |
2912 | icmp = build_icmpv6(_ip_src + _ip_dst, 135, 0, payload) | |
2913 | ||
2914 | ipv6 = struct.pack('>BBBBHBB', 0x60, 0, 0, 0, len(icmp), 58, 255) | |
2915 | ipv6 += _ip_src + _ip_dst | |
2916 | ||
2917 | return ehdr + ipv6 + icmp | |
2918 | ||
5a3ce802 JM |
2919 | def send_ns(dev, src_ll=None, target=None, ip_src=None, ip_dst=None, opt=None, |
2920 | hapd_bssid=None): | |
2921 | if hapd_bssid: | |
2922 | if src_ll is None: | |
2923 | src_ll = hapd_bssid | |
2924 | cmd = "DATA_TEST_FRAME ifname=ap-br0 " | |
2925 | else: | |
2926 | if src_ll is None: | |
2927 | src_ll = dev.p2p_interface_addr() | |
2928 | cmd = "DATA_TEST_FRAME " | |
2929 | ||
2930 | if opt is None: | |
2931 | opt = "\x01\x01" + binascii.unhexlify(src_ll.replace(':','')) | |
2932 | ||
2933 | pkt = build_ns(src_ll=src_ll, ip_src=ip_src, ip_dst=ip_dst, target=target, | |
2934 | opt=opt) | |
2935 | if "OK" not in dev.request(cmd + binascii.hexlify(pkt)): | |
2936 | raise Exception("DATA_TEST_FRAME failed") | |
2937 | ||
356a497d JM |
2938 | def build_na(src_ll, ip_src, ip_dst, target, opt=None): |
2939 | link_mc = binascii.unhexlify("3333ff000002") | |
2940 | _src_ll = binascii.unhexlify(src_ll.replace(':','')) | |
2941 | proto = '\x86\xdd' | |
2942 | ehdr = link_mc + _src_ll + proto | |
2943 | _ip_src = socket.inet_pton(socket.AF_INET6, ip_src) | |
2944 | _ip_dst = socket.inet_pton(socket.AF_INET6, ip_dst) | |
2945 | ||
2946 | reserved = '\x00\x00\x00\x00' | |
2947 | _target = socket.inet_pton(socket.AF_INET6, target) | |
2948 | if opt: | |
2949 | payload = reserved + _target + opt | |
2950 | else: | |
2951 | payload = reserved + _target | |
2952 | icmp = build_icmpv6(_ip_src + _ip_dst, 136, 0, payload) | |
2953 | ||
2954 | ipv6 = struct.pack('>BBBBHBB', 0x60, 0, 0, 0, len(icmp), 58, 255) | |
2955 | ipv6 += _ip_src + _ip_dst | |
2956 | ||
2957 | return ehdr + ipv6 + icmp | |
2958 | ||
5a3ce802 JM |
2959 | def send_na(dev, src_ll=None, target=None, ip_src=None, ip_dst=None, opt=None, |
2960 | hapd_bssid=None): | |
2961 | if hapd_bssid: | |
2962 | if src_ll is None: | |
2963 | src_ll = hapd_bssid | |
2964 | cmd = "DATA_TEST_FRAME ifname=ap-br0 " | |
2965 | else: | |
2966 | if src_ll is None: | |
2967 | src_ll = dev.p2p_interface_addr() | |
2968 | cmd = "DATA_TEST_FRAME " | |
2969 | ||
2970 | pkt = build_na(src_ll=src_ll, ip_src=ip_src, ip_dst=ip_dst, target=target, | |
2971 | opt=opt) | |
2972 | if "OK" not in dev.request(cmd + binascii.hexlify(pkt)): | |
2973 | raise Exception("DATA_TEST_FRAME failed") | |
2974 | ||
a712282b JM |
2975 | def build_dhcp_ack(dst_ll, src_ll, ip_src, ip_dst, yiaddr, chaddr, |
2976 | subnet_mask="255.255.255.0", truncated_opt=False, | |
2977 | wrong_magic=False, force_tot_len=None, no_dhcp=False): | |
2978 | _dst_ll = binascii.unhexlify(dst_ll.replace(':','')) | |
2979 | _src_ll = binascii.unhexlify(src_ll.replace(':','')) | |
2980 | proto = '\x08\x00' | |
2981 | ehdr = _dst_ll + _src_ll + proto | |
2982 | _ip_src = socket.inet_pton(socket.AF_INET, ip_src) | |
2983 | _ip_dst = socket.inet_pton(socket.AF_INET, ip_dst) | |
2984 | _subnet_mask = socket.inet_pton(socket.AF_INET, subnet_mask) | |
2985 | ||
2986 | _ciaddr = '\x00\x00\x00\x00' | |
2987 | _yiaddr = socket.inet_pton(socket.AF_INET, yiaddr) | |
2988 | _siaddr = '\x00\x00\x00\x00' | |
2989 | _giaddr = '\x00\x00\x00\x00' | |
2990 | _chaddr = binascii.unhexlify(chaddr.replace(':','') + "00000000000000000000") | |
2991 | payload = struct.pack('>BBBBL3BB', 2, 1, 6, 0, 12345, 0, 0, 0, 0) | |
2992 | payload += _ciaddr + _yiaddr + _siaddr + _giaddr + _chaddr + 192*'\x00' | |
2993 | # magic | |
2994 | if wrong_magic: | |
2995 | payload += '\x63\x82\x53\x00' | |
2996 | else: | |
2997 | payload += '\x63\x82\x53\x63' | |
2998 | if truncated_opt: | |
2999 | payload += '\x22\xff\x00' | |
3000 | # Option: DHCP Message Type = ACK | |
3001 | payload += '\x35\x01\x05' | |
3002 | # Pad Option | |
3003 | payload += '\x00' | |
3004 | # Option: Subnet Mask | |
3005 | payload += '\x01\x04' + _subnet_mask | |
3006 | # Option: Time Offset | |
3007 | payload += struct.pack('>BBL', 2, 4, 0) | |
3008 | # End Option | |
3009 | payload += '\xff' | |
3010 | # Pad Option | |
3011 | payload += '\x00\x00\x00\x00' | |
3012 | ||
3013 | if no_dhcp: | |
3014 | payload = struct.pack('>BBBBL3BB', 2, 1, 6, 0, 12345, 0, 0, 0, 0) | |
3015 | payload += _ciaddr + _yiaddr + _siaddr + _giaddr + _chaddr + 192*'\x00' | |
3016 | ||
3017 | udp = struct.pack('>HHHH', 67, 68, 8 + len(payload), 0) + payload | |
3018 | ||
3019 | if force_tot_len: | |
3020 | tot_len = force_tot_len | |
3021 | else: | |
3022 | tot_len = 20 + len(udp) | |
3023 | start = struct.pack('>BBHHBBBB', 0x45, 0, tot_len, 0, 0, 0, 128, 17) | |
3024 | ipv4 = start + '\x00\x00' + _ip_src + _ip_dst | |
3025 | csum = ip_checksum(ipv4) | |
3026 | ipv4 = start + csum + _ip_src + _ip_dst | |
3027 | ||
3028 | return ehdr + ipv4 + udp | |
3029 | ||
d9f3bb1a JM |
3030 | def build_arp(dst_ll, src_ll, opcode, sender_mac, sender_ip, |
3031 | target_mac, target_ip): | |
3032 | _dst_ll = binascii.unhexlify(dst_ll.replace(':','')) | |
3033 | _src_ll = binascii.unhexlify(src_ll.replace(':','')) | |
3034 | proto = '\x08\x06' | |
3035 | ehdr = _dst_ll + _src_ll + proto | |
3036 | ||
3037 | _sender_mac = binascii.unhexlify(sender_mac.replace(':','')) | |
3038 | _sender_ip = socket.inet_pton(socket.AF_INET, sender_ip) | |
3039 | _target_mac = binascii.unhexlify(target_mac.replace(':','')) | |
3040 | _target_ip = socket.inet_pton(socket.AF_INET, target_ip) | |
3041 | ||
3042 | arp = struct.pack('>HHBBH', 1, 0x0800, 6, 4, opcode) | |
3043 | arp += _sender_mac + _sender_ip | |
3044 | arp += _target_mac + _target_ip | |
3045 | ||
3046 | return ehdr + arp | |
3047 | ||
3048 | def send_arp(dev, dst_ll="ff:ff:ff:ff:ff:ff", src_ll=None, opcode=1, | |
3049 | sender_mac=None, sender_ip="0.0.0.0", | |
3050 | target_mac="00:00:00:00:00:00", target_ip="0.0.0.0", | |
3051 | hapd_bssid=None): | |
3052 | if hapd_bssid: | |
3053 | if src_ll is None: | |
3054 | src_ll = hapd_bssid | |
3055 | if sender_mac is None: | |
3056 | sender_mac = hapd_bssid | |
3057 | cmd = "DATA_TEST_FRAME ifname=ap-br0 " | |
3058 | else: | |
3059 | if src_ll is None: | |
3060 | src_ll = dev.p2p_interface_addr() | |
3061 | if sender_mac is None: | |
3062 | sender_mac = dev.p2p_interface_addr() | |
3063 | cmd = "DATA_TEST_FRAME " | |
3064 | ||
89cd4355 | 3065 | pkt = build_arp(dst_ll=dst_ll, src_ll=src_ll, opcode=opcode, |
d9f3bb1a JM |
3066 | sender_mac=sender_mac, sender_ip=sender_ip, |
3067 | target_mac=target_mac, target_ip=target_ip) | |
3068 | if "OK" not in dev.request(cmd + binascii.hexlify(pkt)): | |
3069 | raise Exception("DATA_TEST_FRAME failed") | |
3070 | ||
5f7b07de JM |
3071 | def get_permanent_neighbors(ifname): |
3072 | cmd = subprocess.Popen(['ip', 'nei'], stdout=subprocess.PIPE) | |
3073 | res = cmd.stdout.read() | |
3074 | cmd.stdout.close() | |
3075 | return [ line for line in res.splitlines() if "PERMANENT" in line and ifname in line ] | |
3076 | ||
87f0ede9 JM |
3077 | def get_bridge_macs(ifname): |
3078 | cmd = subprocess.Popen(['brctl', 'showmacs', ifname], | |
3079 | stdout=subprocess.PIPE) | |
3080 | res = cmd.stdout.read() | |
3081 | cmd.stdout.close() | |
3082 | return res | |
3083 | ||
efd0a6fb JM |
3084 | def tshark_get_arp(cap, filter): |
3085 | res = run_tshark(cap, filter, | |
3086 | [ "eth.dst", "eth.src", | |
3087 | "arp.src.hw_mac", "arp.src.proto_ipv4", | |
3088 | "arp.dst.hw_mac", "arp.dst.proto_ipv4" ], | |
3089 | wait=False) | |
3090 | frames = [] | |
3091 | for l in res.splitlines(): | |
3092 | frames.append(l.split('\t')) | |
3093 | return frames | |
3094 | ||
55c430b6 JM |
3095 | def tshark_get_ns(cap): |
3096 | res = run_tshark(cap, "icmpv6.type == 135", | |
3097 | [ "eth.dst", "eth.src", | |
3098 | "ipv6.src", "ipv6.dst", | |
3099 | "icmpv6.nd.ns.target_address", | |
3100 | "icmpv6.opt.linkaddr" ], | |
3101 | wait=False) | |
3102 | frames = [] | |
3103 | for l in res.splitlines(): | |
3104 | frames.append(l.split('\t')) | |
3105 | return frames | |
3106 | ||
3107 | def tshark_get_na(cap): | |
3108 | res = run_tshark(cap, "icmpv6.type == 136", | |
3109 | [ "eth.dst", "eth.src", | |
3110 | "ipv6.src", "ipv6.dst", | |
3111 | "icmpv6.nd.na.target_address", | |
3112 | "icmpv6.opt.linkaddr" ], | |
3113 | wait=False) | |
3114 | frames = [] | |
3115 | for l in res.splitlines(): | |
3116 | frames.append(l.split('\t')) | |
3117 | return frames | |
3118 | ||
9934ee19 JM |
3119 | def _test_proxyarp_open(dev, apdev, params, ebtables=False): |
3120 | prefix = "proxyarp_open" | |
3121 | if ebtables: | |
3122 | prefix += "_ebtables" | |
3123 | cap_br = os.path.join(params['logdir'], prefix + ".ap-br0.pcap") | |
3124 | cap_dev0 = os.path.join(params['logdir'], | |
3125 | prefix + ".%s.pcap" % dev[0].ifname) | |
3126 | cap_dev1 = os.path.join(params['logdir'], | |
3127 | prefix + ".%s.pcap" % dev[1].ifname) | |
210a4f6a JM |
3128 | cap_dev2 = os.path.join(params['logdir'], |
3129 | prefix + ".%s.pcap" % dev[2].ifname) | |
d9f3bb1a | 3130 | |
5f7b07de JM |
3131 | bssid = apdev[0]['bssid'] |
3132 | params = { 'ssid': 'open' } | |
3133 | params['proxy_arp'] = '1' | |
3134 | hapd = hostapd.add_ap(apdev[0]['ifname'], params, no_enable=True) | |
3135 | hapd.set("ap_isolate", "1") | |
3136 | hapd.set('bridge', 'ap-br0') | |
3137 | hapd.dump_monitor() | |
3138 | try: | |
3139 | hapd.enable() | |
3140 | except: | |
3141 | # For now, do not report failures due to missing kernel support | |
81e787b7 | 3142 | raise HwsimSkip("Could not start hostapd - assume proxyarp not supported in kernel version") |
5f7b07de JM |
3143 | ev = hapd.wait_event(["AP-ENABLED", "AP-DISABLED"], timeout=10) |
3144 | if ev is None: | |
3145 | raise Exception("AP startup timed out") | |
3146 | if "AP-ENABLED" not in ev: | |
3147 | raise Exception("AP startup failed") | |
3148 | ||
210a4f6a JM |
3149 | params2 = { 'ssid': 'another' } |
3150 | hapd2 = hostapd.add_ap(apdev[1]['ifname'], params2, no_enable=True) | |
3151 | hapd2.set('bridge', 'ap-br0') | |
3152 | hapd2.enable() | |
3153 | ||
5f7b07de JM |
3154 | subprocess.call(['brctl', 'setfd', 'ap-br0', '0']) |
3155 | subprocess.call(['ip', 'link', 'set', 'dev', 'ap-br0', 'up']) | |
5f7b07de | 3156 | |
9934ee19 JM |
3157 | if ebtables: |
3158 | for chain in [ 'FORWARD', 'OUTPUT' ]: | |
3159 | subprocess.call(['ebtables', '-A', chain, '-p', 'ARP', | |
3160 | '-d', 'Broadcast', '-o', apdev[0]['ifname'], | |
3161 | '-j', 'DROP']) | |
3162 | subprocess.call(['ebtables', '-A', chain, '-d', 'Multicast', | |
3163 | '-p', 'IPv6', '--ip6-protocol', 'ipv6-icmp', | |
3164 | '--ip6-icmp-type', 'neighbor-solicitation', | |
3165 | '-o', apdev[0]['ifname'], '-j', 'DROP']) | |
3166 | subprocess.call(['ebtables', '-A', chain, '-d', 'Multicast', | |
3167 | '-p', 'IPv6', '--ip6-protocol', 'ipv6-icmp', | |
3168 | '--ip6-icmp-type', 'neighbor-advertisement', | |
3169 | '-o', apdev[0]['ifname'], '-j', 'DROP']) | |
3170 | subprocess.call(['ebtables', '-A', chain, | |
3171 | '-p', 'IPv6', '--ip6-protocol', 'ipv6-icmp', | |
3172 | '--ip6-icmp-type', 'router-solicitation', | |
3173 | '-o', apdev[0]['ifname'], '-j', 'DROP']) | |
3174 | # Multicast Listener Report Message | |
3175 | subprocess.call(['ebtables', '-A', chain, '-d', 'Multicast', | |
3176 | '-p', 'IPv6', '--ip6-protocol', 'ipv6-icmp', | |
3177 | '--ip6-icmp-type', '143', | |
3178 | '-o', apdev[0]['ifname'], '-j', 'DROP']) | |
19cbe062 | 3179 | |
55c430b6 | 3180 | time.sleep(0.5) |
d9f3bb1a | 3181 | cmd = {} |
a95c6973 JM |
3182 | cmd[0] = subprocess.Popen(['tcpdump', '-p', '-U', '-i', 'ap-br0', |
3183 | '-w', cap_br, '-s', '2000'], | |
3184 | stderr=open('/dev/null', 'w')) | |
3185 | cmd[1] = subprocess.Popen(['tcpdump', '-p', '-U', '-i', dev[0].ifname, | |
3186 | '-w', cap_dev0, '-s', '2000'], | |
3187 | stderr=open('/dev/null', 'w')) | |
3188 | cmd[2] = subprocess.Popen(['tcpdump', '-p', '-U', '-i', dev[1].ifname, | |
3189 | '-w', cap_dev1, '-s', '2000'], | |
3190 | stderr=open('/dev/null', 'w')) | |
210a4f6a JM |
3191 | cmd[3] = subprocess.Popen(['tcpdump', '-p', '-U', '-i', dev[2].ifname, |
3192 | '-w', cap_dev2, '-s', '2000'], | |
3193 | stderr=open('/dev/null', 'w')) | |
d9f3bb1a | 3194 | |
5f7b07de JM |
3195 | dev[0].connect("open", key_mgmt="NONE", scan_freq="2412") |
3196 | dev[1].connect("open", key_mgmt="NONE", scan_freq="2412") | |
210a4f6a | 3197 | dev[2].connect("another", key_mgmt="NONE", scan_freq="2412") |
5f7b07de JM |
3198 | time.sleep(0.1) |
3199 | ||
210a4f6a JM |
3200 | brcmd = subprocess.Popen(['brctl', 'show'], stdout=subprocess.PIPE) |
3201 | res = brcmd.stdout.read() | |
3202 | brcmd.stdout.close() | |
3203 | logger.info("Bridge setup: " + res) | |
3204 | ||
3205 | brcmd = subprocess.Popen(['brctl', 'showstp', 'ap-br0'], | |
3206 | stdout=subprocess.PIPE) | |
3207 | res = brcmd.stdout.read() | |
3208 | brcmd.stdout.close() | |
3209 | logger.info("Bridge showstp: " + res) | |
3210 | ||
67aeee11 JM |
3211 | addr0 = dev[0].p2p_interface_addr() |
3212 | addr1 = dev[1].p2p_interface_addr() | |
efd0a6fb | 3213 | addr2 = dev[2].p2p_interface_addr() |
67aeee11 JM |
3214 | |
3215 | src_ll_opt0 = "\x01\x01" + binascii.unhexlify(addr0.replace(':','')) | |
3216 | src_ll_opt1 = "\x01\x01" + binascii.unhexlify(addr1.replace(':','')) | |
3217 | ||
3218 | # DAD NS | |
6d533294 | 3219 | send_ns(dev[0], ip_src="::", target="aaaa:bbbb:cccc::2") |
67aeee11 | 3220 | |
6d533294 | 3221 | send_ns(dev[0], ip_src="aaaa:bbbb:cccc::2", target="aaaa:bbbb:cccc::2") |
67aeee11 | 3222 | # test frame without source link-layer address option |
6d533294 JM |
3223 | send_ns(dev[0], ip_src="aaaa:bbbb:cccc::2", target="aaaa:bbbb:cccc::2", |
3224 | opt='') | |
67aeee11 | 3225 | # test frame with bogus option |
6d533294 JM |
3226 | send_ns(dev[0], ip_src="aaaa:bbbb:cccc::2", target="aaaa:bbbb:cccc::2", |
3227 | opt="\x70\x01\x01\x02\x03\x04\x05\x05") | |
67aeee11 | 3228 | # test frame with truncated source link-layer address option |
6d533294 JM |
3229 | send_ns(dev[0], ip_src="aaaa:bbbb:cccc::2", target="aaaa:bbbb:cccc::2", |
3230 | opt="\x01\x01\x01\x02\x03\x04") | |
67aeee11 | 3231 | # test frame with foreign source link-layer address option |
6d533294 JM |
3232 | send_ns(dev[0], ip_src="aaaa:bbbb:cccc::2", target="aaaa:bbbb:cccc::2", |
3233 | opt="\x01\x01\x01\x02\x03\x04\x05\x06") | |
67aeee11 | 3234 | |
6d533294 | 3235 | send_ns(dev[1], ip_src="aaaa:bbbb:dddd::2", target="aaaa:bbbb:dddd::2") |
67aeee11 | 3236 | |
6d533294 | 3237 | send_ns(dev[1], ip_src="aaaa:bbbb:eeee::2", target="aaaa:bbbb:eeee::2") |
67aeee11 | 3238 | # another copy for additional code coverage |
6d533294 | 3239 | send_ns(dev[1], ip_src="aaaa:bbbb:eeee::2", target="aaaa:bbbb:eeee::2") |
67aeee11 | 3240 | |
a712282b JM |
3241 | pkt = build_dhcp_ack(dst_ll="ff:ff:ff:ff:ff:ff", src_ll=bssid, |
3242 | ip_src="192.168.1.1", ip_dst="255.255.255.255", | |
3243 | yiaddr="192.168.1.124", chaddr=addr0) | |
3244 | if "OK" not in hapd.request("DATA_TEST_FRAME ifname=ap-br0 " + binascii.hexlify(pkt)): | |
3245 | raise Exception("DATA_TEST_FRAME failed") | |
3246 | # Change address and verify unicast | |
3247 | pkt = build_dhcp_ack(dst_ll=addr0, src_ll=bssid, | |
3248 | ip_src="192.168.1.1", ip_dst="255.255.255.255", | |
3249 | yiaddr="192.168.1.123", chaddr=addr0) | |
3250 | if "OK" not in hapd.request("DATA_TEST_FRAME ifname=ap-br0 " + binascii.hexlify(pkt)): | |
3251 | raise Exception("DATA_TEST_FRAME failed") | |
3252 | ||
3253 | # Not-associated client MAC address | |
3254 | pkt = build_dhcp_ack(dst_ll="ff:ff:ff:ff:ff:ff", src_ll=bssid, | |
3255 | ip_src="192.168.1.1", ip_dst="255.255.255.255", | |
3256 | yiaddr="192.168.1.125", chaddr="22:33:44:55:66:77") | |
3257 | if "OK" not in hapd.request("DATA_TEST_FRAME ifname=ap-br0 " + binascii.hexlify(pkt)): | |
3258 | raise Exception("DATA_TEST_FRAME failed") | |
3259 | ||
3260 | # No IP address | |
3261 | pkt = build_dhcp_ack(dst_ll=addr1, src_ll=bssid, | |
3262 | ip_src="192.168.1.1", ip_dst="255.255.255.255", | |
3263 | yiaddr="0.0.0.0", chaddr=addr1) | |
3264 | if "OK" not in hapd.request("DATA_TEST_FRAME ifname=ap-br0 " + binascii.hexlify(pkt)): | |
3265 | raise Exception("DATA_TEST_FRAME failed") | |
3266 | ||
3267 | # Zero subnet mask | |
3268 | pkt = build_dhcp_ack(dst_ll=addr1, src_ll=bssid, | |
3269 | ip_src="192.168.1.1", ip_dst="255.255.255.255", | |
3270 | yiaddr="192.168.1.126", chaddr=addr1, | |
3271 | subnet_mask="0.0.0.0") | |
3272 | if "OK" not in hapd.request("DATA_TEST_FRAME ifname=ap-br0 " + binascii.hexlify(pkt)): | |
3273 | raise Exception("DATA_TEST_FRAME failed") | |
3274 | ||
3275 | # Truncated option | |
3276 | pkt = build_dhcp_ack(dst_ll=addr1, src_ll=bssid, | |
3277 | ip_src="192.168.1.1", ip_dst="255.255.255.255", | |
3278 | yiaddr="192.168.1.127", chaddr=addr1, | |
3279 | truncated_opt=True) | |
3280 | if "OK" not in hapd.request("DATA_TEST_FRAME ifname=ap-br0 " + binascii.hexlify(pkt)): | |
3281 | raise Exception("DATA_TEST_FRAME failed") | |
3282 | ||
3283 | # Wrong magic | |
3284 | pkt = build_dhcp_ack(dst_ll=addr1, src_ll=bssid, | |
3285 | ip_src="192.168.1.1", ip_dst="255.255.255.255", | |
3286 | yiaddr="192.168.1.128", chaddr=addr1, | |
3287 | wrong_magic=True) | |
3288 | if "OK" not in hapd.request("DATA_TEST_FRAME ifname=ap-br0 " + binascii.hexlify(pkt)): | |
3289 | raise Exception("DATA_TEST_FRAME failed") | |
3290 | ||
3291 | # Wrong IPv4 total length | |
3292 | pkt = build_dhcp_ack(dst_ll=addr1, src_ll=bssid, | |
3293 | ip_src="192.168.1.1", ip_dst="255.255.255.255", | |
3294 | yiaddr="192.168.1.129", chaddr=addr1, | |
3295 | force_tot_len=1000) | |
3296 | if "OK" not in hapd.request("DATA_TEST_FRAME ifname=ap-br0 " + binascii.hexlify(pkt)): | |
3297 | raise Exception("DATA_TEST_FRAME failed") | |
3298 | ||
3299 | # BOOTP | |
3300 | pkt = build_dhcp_ack(dst_ll=addr1, src_ll=bssid, | |
3301 | ip_src="192.168.1.1", ip_dst="255.255.255.255", | |
3302 | yiaddr="192.168.1.129", chaddr=addr1, | |
3303 | no_dhcp=True) | |
3304 | if "OK" not in hapd.request("DATA_TEST_FRAME ifname=ap-br0 " + binascii.hexlify(pkt)): | |
3305 | raise Exception("DATA_TEST_FRAME failed") | |
3306 | ||
87f0ede9 JM |
3307 | macs = get_bridge_macs("ap-br0") |
3308 | logger.info("After connect (showmacs): " + str(macs)) | |
3309 | ||
5f7b07de JM |
3310 | matches = get_permanent_neighbors("ap-br0") |
3311 | logger.info("After connect: " + str(matches)) | |
a712282b | 3312 | if len(matches) != 4: |
5f7b07de | 3313 | raise Exception("Unexpected number of neighbor entries after connect") |
67aeee11 JM |
3314 | if 'aaaa:bbbb:cccc::2 dev ap-br0 lladdr 02:00:00:00:00:00 PERMANENT' not in matches: |
3315 | raise Exception("dev0 addr missing") | |
3316 | if 'aaaa:bbbb:dddd::2 dev ap-br0 lladdr 02:00:00:00:01:00 PERMANENT' not in matches: | |
3317 | raise Exception("dev1 addr(1) missing") | |
3318 | if 'aaaa:bbbb:eeee::2 dev ap-br0 lladdr 02:00:00:00:01:00 PERMANENT' not in matches: | |
3319 | raise Exception("dev1 addr(2) missing") | |
a712282b JM |
3320 | if '192.168.1.123 dev ap-br0 lladdr 02:00:00:00:00:00 PERMANENT' not in matches: |
3321 | raise Exception("dev0 IPv4 addr missing") | |
67aeee11 | 3322 | |
d9f3bb1a JM |
3323 | targets = [ "192.168.1.123", "192.168.1.124", "192.168.1.125", |
3324 | "192.168.1.126" ] | |
3325 | for target in targets: | |
3326 | send_arp(dev[1], sender_ip="192.168.1.100", target_ip=target) | |
3327 | ||
3328 | for target in targets: | |
3329 | send_arp(hapd, hapd_bssid=bssid, sender_ip="192.168.1.101", | |
3330 | target_ip=target) | |
3331 | ||
210a4f6a JM |
3332 | for target in targets: |
3333 | send_arp(dev[2], sender_ip="192.168.1.103", target_ip=target) | |
3334 | ||
d9f3bb1a JM |
3335 | # ARP Probe from wireless STA |
3336 | send_arp(dev[1], target_ip="192.168.1.127") | |
3337 | # ARP Announcement from wireless STA | |
3338 | send_arp(dev[1], sender_ip="192.168.1.127", target_ip="192.168.1.127") | |
3339 | send_arp(dev[1], sender_ip="192.168.1.127", target_ip="192.168.1.127", | |
3340 | opcode=2) | |
3341 | ||
87f0ede9 JM |
3342 | macs = get_bridge_macs("ap-br0") |
3343 | logger.info("After ARP Probe + Announcement (showmacs): " + str(macs)) | |
3344 | ||
d9f3bb1a JM |
3345 | matches = get_permanent_neighbors("ap-br0") |
3346 | logger.info("After ARP Probe + Announcement: " + str(matches)) | |
3347 | ||
3348 | # ARP Request for the newly introduced IP address from wireless STA | |
3349 | send_arp(dev[0], sender_ip="192.168.1.123", target_ip="192.168.1.127") | |
3350 | ||
3351 | # ARP Request for the newly introduced IP address from bridge | |
3352 | send_arp(hapd, hapd_bssid=bssid, sender_ip="192.168.1.102", | |
3353 | target_ip="192.168.1.127") | |
210a4f6a | 3354 | send_arp(dev[2], sender_ip="192.168.1.103", target_ip="192.168.1.127") |
d9f3bb1a JM |
3355 | |
3356 | # ARP Probe from bridge | |
89cd4355 | 3357 | send_arp(hapd, hapd_bssid=bssid, target_ip="192.168.1.130") |
210a4f6a | 3358 | send_arp(dev[2], target_ip="192.168.1.131") |
89cd4355 JM |
3359 | # ARP Announcement from bridge (not to be learned by AP for proxyarp) |
3360 | send_arp(hapd, hapd_bssid=bssid, sender_ip="192.168.1.130", | |
3361 | target_ip="192.168.1.130") | |
3362 | send_arp(hapd, hapd_bssid=bssid, sender_ip="192.168.1.130", | |
3363 | target_ip="192.168.1.130", opcode=2) | |
210a4f6a JM |
3364 | send_arp(dev[2], sender_ip="192.168.1.131", target_ip="192.168.1.131") |
3365 | send_arp(dev[2], sender_ip="192.168.1.131", target_ip="192.168.1.131", | |
3366 | opcode=2) | |
d9f3bb1a | 3367 | |
87f0ede9 JM |
3368 | macs = get_bridge_macs("ap-br0") |
3369 | logger.info("After ARP Probe + Announcement (showmacs): " + str(macs)) | |
3370 | ||
d9f3bb1a JM |
3371 | matches = get_permanent_neighbors("ap-br0") |
3372 | logger.info("After ARP Probe + Announcement: " + str(matches)) | |
3373 | ||
3374 | # ARP Request for the newly introduced IP address from wireless STA | |
89cd4355 JM |
3375 | send_arp(dev[0], sender_ip="192.168.1.123", target_ip="192.168.1.130") |
3376 | # ARP Response from bridge (AP does not proxy for non-wireless devices) | |
3377 | send_arp(hapd, hapd_bssid=bssid, dst_ll=addr0, sender_ip="192.168.1.130", | |
3378 | target_ip="192.168.1.123", opcode=2) | |
d9f3bb1a | 3379 | |
210a4f6a JM |
3380 | # ARP Request for the newly introduced IP address from wireless STA |
3381 | send_arp(dev[0], sender_ip="192.168.1.123", target_ip="192.168.1.131") | |
3382 | # ARP Response from bridge (AP does not proxy for non-wireless devices) | |
3383 | send_arp(dev[2], dst_ll=addr0, sender_ip="192.168.1.131", | |
3384 | target_ip="192.168.1.123", opcode=2) | |
3385 | ||
d9f3bb1a JM |
3386 | # ARP Request for the newly introduced IP address from bridge |
3387 | send_arp(hapd, hapd_bssid=bssid, sender_ip="192.168.1.102", | |
89cd4355 | 3388 | target_ip="192.168.1.130") |
210a4f6a | 3389 | send_arp(dev[2], sender_ip="192.168.1.104", target_ip="192.168.1.131") |
d9f3bb1a JM |
3390 | |
3391 | # ARP Probe from wireless STA (duplicate address; learned through DHCP) | |
3392 | send_arp(dev[1], target_ip="192.168.1.123") | |
3393 | # ARP Probe from wireless STA (duplicate address; learned through ARP) | |
3394 | send_arp(dev[0], target_ip="192.168.1.127") | |
3395 | ||
3396 | # Gratuitous ARP Reply for another STA's IP address | |
3397 | send_arp(dev[0], opcode=2, sender_mac=addr0, sender_ip="192.168.1.127", | |
3398 | target_mac=addr1, target_ip="192.168.1.127") | |
3399 | send_arp(dev[1], opcode=2, sender_mac=addr1, sender_ip="192.168.1.123", | |
3400 | target_mac=addr0, target_ip="192.168.1.123") | |
3401 | # ARP Request to verify previous mapping | |
3402 | send_arp(dev[1], sender_ip="192.168.1.127", target_ip="192.168.1.123") | |
3403 | send_arp(dev[0], sender_ip="192.168.1.123", target_ip="192.168.1.127") | |
3404 | ||
3405 | time.sleep(0.1) | |
3406 | ||
5a3ce802 JM |
3407 | send_ns(dev[0], target="aaaa:bbbb:dddd::2", ip_src="aaaa:bbbb:cccc::2") |
3408 | time.sleep(0.1) | |
3409 | send_ns(dev[1], target="aaaa:bbbb:cccc::2", ip_src="aaaa:bbbb:dddd::2") | |
3410 | time.sleep(0.1) | |
3411 | send_ns(hapd, hapd_bssid=bssid, target="aaaa:bbbb:dddd::2", | |
3412 | ip_src="aaaa:bbbb:ffff::2") | |
3413 | time.sleep(0.1) | |
210a4f6a JM |
3414 | send_ns(dev[2], target="aaaa:bbbb:cccc::2", ip_src="aaaa:bbbb:ff00::2") |
3415 | time.sleep(0.1) | |
3416 | send_ns(dev[2], target="aaaa:bbbb:dddd::2", ip_src="aaaa:bbbb:ff00::2") | |
3417 | time.sleep(0.1) | |
3418 | send_ns(dev[2], target="aaaa:bbbb:eeee::2", ip_src="aaaa:bbbb:ff00::2") | |
3419 | time.sleep(0.1) | |
5a3ce802 JM |
3420 | |
3421 | # Try to probe for an already assigned address | |
3422 | send_ns(dev[1], target="aaaa:bbbb:cccc::2", ip_src="::") | |
3423 | time.sleep(0.1) | |
3424 | send_ns(hapd, hapd_bssid=bssid, target="aaaa:bbbb:cccc::2", ip_src="::") | |
3425 | time.sleep(0.1) | |
210a4f6a JM |
3426 | send_ns(dev[2], target="aaaa:bbbb:cccc::2", ip_src="::") |
3427 | time.sleep(0.1) | |
5a3ce802 JM |
3428 | |
3429 | # Unsolicited NA | |
3430 | send_na(dev[1], target="aaaa:bbbb:cccc:aeae::3", | |
3431 | ip_src="aaaa:bbbb:cccc:aeae::3", ip_dst="ff02::1") | |
3432 | send_na(hapd, hapd_bssid=bssid, target="aaaa:bbbb:cccc:aeae::4", | |
3433 | ip_src="aaaa:bbbb:cccc:aeae::4", ip_dst="ff02::1") | |
210a4f6a JM |
3434 | send_na(dev[2], target="aaaa:bbbb:cccc:aeae::5", |
3435 | ip_src="aaaa:bbbb:cccc:aeae::5", ip_dst="ff02::1") | |
5a3ce802 | 3436 | |
7e3a6c9e JM |
3437 | try: |
3438 | hwsim_utils.test_connectivity_iface(dev[0], hapd, "ap-br0") | |
3439 | except Exception, e: | |
3440 | logger.info("test_connectibity_iface failed: " + str(e)) | |
3441 | raise HwsimSkip("Assume kernel did not have the required patches for proxyarp") | |
40e4c9c8 JM |
3442 | hwsim_utils.test_connectivity_iface(dev[1], hapd, "ap-br0") |
3443 | hwsim_utils.test_connectivity(dev[0], dev[1]) | |
3444 | ||
5f7b07de JM |
3445 | dev[0].request("DISCONNECT") |
3446 | dev[1].request("DISCONNECT") | |
3447 | time.sleep(0.5) | |
210a4f6a | 3448 | for i in range(len(cmd)): |
d9f3bb1a | 3449 | cmd[i].terminate() |
87f0ede9 JM |
3450 | macs = get_bridge_macs("ap-br0") |
3451 | logger.info("After disconnect (showmacs): " + str(macs)) | |
5f7b07de JM |
3452 | matches = get_permanent_neighbors("ap-br0") |
3453 | logger.info("After disconnect: " + str(matches)) | |
3454 | if len(matches) > 0: | |
3455 | raise Exception("Unexpected neighbor entries after disconnect") | |
9934ee19 JM |
3456 | if ebtables: |
3457 | cmd = subprocess.Popen(['ebtables', '-L', '--Lc'], | |
3458 | stdout=subprocess.PIPE) | |
3459 | res = cmd.stdout.read() | |
3460 | cmd.stdout.close() | |
3461 | logger.info("ebtables results:\n" + res) | |
5f7b07de | 3462 | |
efd0a6fb JM |
3463 | # Verify that expected ARP messages were seen and no unexpected |
3464 | # ARP messages were seen. | |
3465 | ||
3466 | arp_req = tshark_get_arp(cap_dev0, "arp.opcode == 1") | |
3467 | arp_reply = tshark_get_arp(cap_dev0, "arp.opcode == 2") | |
3468 | logger.info("dev0 seen ARP requests:\n" + str(arp_req)) | |
3469 | logger.info("dev0 seen ARP replies:\n" + str(arp_reply)) | |
3470 | ||
3471 | if [ 'ff:ff:ff:ff:ff:ff', addr1, | |
3472 | addr1, '192.168.1.100', | |
3473 | '00:00:00:00:00:00', '192.168.1.123' ] in arp_req: | |
3474 | raise Exception("dev0 saw ARP request from dev1") | |
3475 | if [ 'ff:ff:ff:ff:ff:ff', addr2, | |
3476 | addr2, '192.168.1.103', | |
3477 | '00:00:00:00:00:00', '192.168.1.123' ] in arp_req: | |
3478 | raise Exception("dev0 saw ARP request from dev2") | |
3479 | # TODO: Uncomment once fixed in kernel | |
3480 | #if [ 'ff:ff:ff:ff:ff:ff', bssid, | |
3481 | # bssid, '192.168.1.101', | |
3482 | # '00:00:00:00:00:00', '192.168.1.123' ] in arp_req: | |
3483 | # raise Exception("dev0 saw ARP request from br") | |
3484 | ||
3485 | if ebtables: | |
3486 | for req in arp_req: | |
3487 | if req[1] != addr0: | |
3488 | raise Exception("Unexpected foreign ARP request on dev0") | |
3489 | ||
3490 | arp_req = tshark_get_arp(cap_dev1, "arp.opcode == 1") | |
3491 | arp_reply = tshark_get_arp(cap_dev1, "arp.opcode == 2") | |
3492 | logger.info("dev1 seen ARP requests:\n" + str(arp_req)) | |
3493 | logger.info("dev1 seen ARP replies:\n" + str(arp_reply)) | |
3494 | ||
3495 | if [ 'ff:ff:ff:ff:ff:ff', addr2, | |
3496 | addr2, '192.168.1.103', | |
3497 | '00:00:00:00:00:00', '192.168.1.123' ] in arp_req: | |
3498 | raise Exception("dev1 saw ARP request from dev2") | |
3499 | if [addr1, addr0, addr0, '192.168.1.123', addr1, '192.168.1.100'] not in arp_reply: | |
3500 | raise Exception("dev1 did not get ARP response for 192.168.1.123") | |
3501 | ||
3502 | if ebtables: | |
3503 | for req in arp_req: | |
3504 | if req[1] != addr1: | |
3505 | raise Exception("Unexpected foreign ARP request on dev1") | |
3506 | ||
3507 | arp_req = tshark_get_arp(cap_dev2, "arp.opcode == 1") | |
3508 | arp_reply = tshark_get_arp(cap_dev2, "arp.opcode == 2") | |
3509 | logger.info("dev2 seen ARP requests:\n" + str(arp_req)) | |
3510 | logger.info("dev2 seen ARP replies:\n" + str(arp_reply)) | |
3511 | ||
3512 | if [ addr2, addr0, | |
3513 | addr0, '192.168.1.123', | |
3514 | addr2, '192.168.1.103' ] not in arp_reply: | |
3515 | raise Exception("dev2 did not get ARP response for 192.168.1.123") | |
3516 | ||
3517 | arp_req = tshark_get_arp(cap_br, "arp.opcode == 1") | |
3518 | arp_reply = tshark_get_arp(cap_br, "arp.opcode == 2") | |
3519 | logger.info("br seen ARP requests:\n" + str(arp_req)) | |
3520 | logger.info("br seen ARP replies:\n" + str(arp_reply)) | |
3521 | ||
3522 | # TODO: Uncomment once fixed in kernel | |
3523 | #if [ bssid, addr0, | |
3524 | # addr0, '192.168.1.123', | |
3525 | # bssid, '192.168.1.101' ] not in arp_reply: | |
3526 | # raise Exception("br did not get ARP response for 192.168.1.123") | |
3527 | ||
55c430b6 JM |
3528 | ns = tshark_get_ns(cap_dev0) |
3529 | logger.info("dev0 seen NS: " + str(ns)) | |
3530 | na = tshark_get_na(cap_dev0) | |
3531 | logger.info("dev0 seen NA: " + str(na)) | |
3532 | ||
05121d35 | 3533 | if [ addr0, addr1, 'aaaa:bbbb:dddd::2', 'aaaa:bbbb:cccc::2', |
55c430b6 JM |
3534 | 'aaaa:bbbb:dddd::2', addr1 ] not in na: |
3535 | raise Exception("dev0 did not get NA for aaaa:bbbb:dddd::2") | |
3536 | ||
3537 | if ebtables: | |
3538 | for req in ns: | |
3539 | if req[1] != addr0: | |
3540 | raise Exception("Unexpected foreign NS on dev0: " + str(req)) | |
3541 | ||
3542 | ns = tshark_get_ns(cap_dev1) | |
3543 | logger.info("dev1 seen NS: " + str(ns)) | |
3544 | na = tshark_get_na(cap_dev1) | |
3545 | logger.info("dev1 seen NA: " + str(na)) | |
3546 | ||
05121d35 | 3547 | if [ addr1, addr0, 'aaaa:bbbb:cccc::2', 'aaaa:bbbb:dddd::2', |
55c430b6 JM |
3548 | 'aaaa:bbbb:cccc::2', addr0 ] not in na: |
3549 | raise Exception("dev1 did not get NA for aaaa:bbbb:cccc::2") | |
3550 | ||
3551 | if ebtables: | |
3552 | for req in ns: | |
3553 | if req[1] != addr1: | |
3554 | raise Exception("Unexpected foreign NS on dev1: " + str(req)) | |
3555 | ||
3556 | ns = tshark_get_ns(cap_dev2) | |
3557 | logger.info("dev2 seen NS: " + str(ns)) | |
3558 | na = tshark_get_na(cap_dev2) | |
3559 | logger.info("dev2 seen NA: " + str(na)) | |
3560 | ||
3561 | # FIX: enable once kernel implementation for proxyarp IPv6 is fixed | |
05121d35 | 3562 | #if [ addr2, addr0, 'aaaa:bbbb:cccc::2', 'aaaa:bbbb:ff00::2', |
55c430b6 JM |
3563 | # 'aaaa:bbbb:cccc::2', addr0 ] not in na: |
3564 | # raise Exception("dev2 did not get NA for aaaa:bbbb:cccc::2") | |
05121d35 | 3565 | #if [ addr2, addr1, 'aaaa:bbbb:dddd::2', 'aaaa:bbbb:ff00::2', |
55c430b6 JM |
3566 | # 'aaaa:bbbb:dddd::2', addr1 ] not in na: |
3567 | # raise Exception("dev2 did not get NA for aaaa:bbbb:dddd::2") | |
05121d35 | 3568 | #if [ addr2, addr1, 'aaaa:bbbb:eeee::2', 'aaaa:bbbb:ff00::2', |
55c430b6 JM |
3569 | # 'aaaa:bbbb:eeee::2', addr1 ] not in na: |
3570 | # raise Exception("dev2 did not get NA for aaaa:bbbb:eeee::2") | |
3571 | ||
d9f3bb1a | 3572 | def test_proxyarp_open(dev, apdev, params): |
5f7b07de | 3573 | """ProxyARP with open network""" |
5f7b07de | 3574 | try: |
81e787b7 | 3575 | _test_proxyarp_open(dev, apdev, params) |
9934ee19 JM |
3576 | finally: |
3577 | subprocess.call(['ip', 'link', 'set', 'dev', 'ap-br0', 'down'], | |
3578 | stderr=open('/dev/null', 'w')) | |
3579 | subprocess.call(['brctl', 'delbr', 'ap-br0'], | |
3580 | stderr=open('/dev/null', 'w')) | |
3581 | ||
3582 | def test_proxyarp_open_ebtables(dev, apdev, params): | |
3583 | """ProxyARP with open network""" | |
3584 | try: | |
3585 | _test_proxyarp_open(dev, apdev, params, ebtables=True) | |
5f7b07de | 3586 | finally: |
01c87519 JM |
3587 | try: |
3588 | subprocess.call(['ebtables', '-F', 'FORWARD']) | |
3589 | subprocess.call(['ebtables', '-F', 'OUTPUT']) | |
3590 | except: | |
3591 | pass | |
5f7b07de JM |
3592 | subprocess.call(['ip', 'link', 'set', 'dev', 'ap-br0', 'down'], |
3593 | stderr=open('/dev/null', 'w')) | |
3594 | subprocess.call(['brctl', 'delbr', 'ap-br0'], | |
3595 | stderr=open('/dev/null', 'w')) | |
c518fecc JM |
3596 | |
3597 | def test_ap_hs20_connect_deinit(dev, apdev): | |
3598 | """Hotspot 2.0 connection interrupted with deinit""" | |
e7ac04ce | 3599 | check_eap_capa(dev[0], "MSCHAPV2") |
c518fecc JM |
3600 | bssid = apdev[0]['bssid'] |
3601 | params = hs20_ap_params() | |
3602 | params['hessid'] = bssid | |
3603 | hapd = hostapd.add_ap(apdev[0]['ifname'], params) | |
3604 | ||
3605 | wpas = WpaSupplicant(global_iface='/tmp/wpas-wlan5') | |
3606 | wpas.interface_add("wlan5", drv_params="") | |
3607 | wpas.hs20_enable() | |
3608 | wpas.flush_scan_cache() | |
3609 | wpas.add_cred_values({ 'realm': "example.com", | |
3610 | 'username': "hs20-test", | |
3611 | 'password': "password", | |
3612 | 'ca_cert': "auth_serv/ca.pem", | |
3613 | 'domain': "example.com" }) | |
3614 | ||
3615 | wpas.scan_for_bss(bssid, freq=2412) | |
3616 | hapd.disable() | |
3617 | ||
3618 | wpas.request("INTERWORKING_SELECT freq=2412") | |
3619 | ||
3620 | id = wpas.request("RADIO_WORK add block-work") | |
3621 | ev = wpas.wait_event(["GAS-QUERY-START", "EXT-RADIO-WORK-START"], timeout=5) | |
3622 | if ev is None: | |
3623 | raise Exception("Timeout while waiting radio work to start") | |
3624 | ev = wpas.wait_event(["GAS-QUERY-START", "EXT-RADIO-WORK-START"], timeout=5) | |
3625 | if ev is None: | |
3626 | raise Exception("Timeout while waiting radio work to start (2)") | |
3627 | ||
3628 | # Remove the interface while the gas-query radio work is still pending and | |
3629 | # GAS query has not yet been started. | |
3630 | wpas.interface_remove("wlan5") | |
046e63fa JM |
3631 | |
3632 | def test_ap_hs20_anqp_format_errors(dev, apdev): | |
3633 | """Interworking network selection and ANQP format errors""" | |
3634 | bssid = apdev[0]['bssid'] | |
3635 | params = hs20_ap_params() | |
3636 | params['hessid'] = bssid | |
3637 | hapd = hostapd.add_ap(apdev[0]['ifname'], params) | |
3638 | ||
3639 | dev[0].hs20_enable() | |
3640 | values = { 'realm': "example.com", | |
3641 | 'ca_cert': "auth_serv/ca.pem", | |
3642 | 'username': "hs20-test", | |
3643 | 'password': "password", | |
3644 | 'domain': "example.com" } | |
3645 | id = dev[0].add_cred_values(values) | |
3646 | ||
3647 | dev[0].scan_for_bss(bssid, freq="2412") | |
3648 | ||
3649 | tests = [ "00", "ffff", "010011223344", "020008000005112233445500", | |
3650 | "01000400000000", "01000000000000", | |
3651 | "01000300000200", "0100040000ff0000", "01000300000100", | |
3652 | "01000300000001", | |
3653 | "01000600000056112233", | |
3654 | "01000900000002050001000111", | |
3655 | "01000600000001000000", "01000600000001ff0000", | |
3656 | "01000600000001020001", | |
3657 | "010008000000010400010001", "0100080000000104000100ff", | |
3658 | "010011000000010d00050200020100030005000600", | |
3659 | "0000" ] | |
3660 | for t in tests: | |
3661 | hapd.set("anqp_elem", "263:" + t) | |
3662 | dev[0].request("INTERWORKING_SELECT freq=2412") | |
3663 | ev = dev[0].wait_event(["INTERWORKING-NO-MATCH"], timeout=5) | |
3664 | if ev is None: | |
3665 | raise Exception("Network selection timed out") | |
3666 | dev[0].dump_monitor() | |
3667 | ||
3668 | dev[0].remove_cred(id) | |
3669 | id = dev[0].add_cred_values({ 'imsi': "555444-333222111", 'eap': "AKA", | |
3670 | 'milenage': "5122250214c33e723a5dd523fc145fc0:981d464c7c52eb6e5036234984ad0bcf:000000000123"}) | |
3671 | ||
3672 | tests = [ "00", "0100", "0001", "00ff", "000200ff", "0003000101", | |
3673 | "00020100" ] | |
3674 | for t in tests: | |
3675 | hapd.set("anqp_elem", "264:" + t) | |
3676 | dev[0].request("INTERWORKING_SELECT freq=2412") | |
3677 | ev = dev[0].wait_event(["INTERWORKING-NO-MATCH"], timeout=5) | |
3678 | if ev is None: | |
3679 | raise Exception("Network selection timed out") | |
3680 | dev[0].dump_monitor() |