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