]>
git.ipfire.org Git - thirdparty/hostap.git/blob - tests/hwsim/test_ap_vlan.py
3 # Test cases for AP VLAN
4 # Copyright (c) 2013-2016, Jouni Malinen <j@w1.fi>
6 # This software may be distributed under the terms of the BSD license.
7 # See README for more details.
9 from remotehost
import remote_compatible
13 logger
= logging
.getLogger(__name__
)
17 netifaces_imported
= True
19 netifaces_imported
= False
23 from utils
import iface_is_in_bridge
, HwsimSkip
, alloc_fail
25 from tshark
import run_tshark
27 def test_ap_vlan_open(dev
, apdev
):
28 """AP VLAN with open network"""
29 filename
= hostapd
.acl_file(dev
, apdev
, 'hostapd.accept')
30 hostapd
.send_file(apdev
[0], filename
, filename
)
31 params
= {"ssid": "test-vlan-open",
33 "accept_mac_file": filename
}
34 hapd
= hostapd
.add_ap(apdev
[0], params
)
36 dev
[0].connect("test-vlan-open", key_mgmt
="NONE", scan_freq
="2412")
37 dev
[1].connect("test-vlan-open", key_mgmt
="NONE", scan_freq
="2412")
38 dev
[2].connect("test-vlan-open", key_mgmt
="NONE", scan_freq
="2412")
39 hwsim_utils
.test_connectivity_iface(dev
[0], hapd
, "brvlan1")
40 hwsim_utils
.test_connectivity_iface(dev
[1], hapd
, "brvlan2")
41 hwsim_utils
.test_connectivity(dev
[2], hapd
)
42 if filename
.startswith('/tmp/'):
45 def test_ap_vlan_file_open(dev
, apdev
):
46 """AP VLAN with open network and vlan_file mapping"""
47 filename
= hostapd
.acl_file(dev
, apdev
, 'hostapd.accept')
48 hostapd
.send_file(apdev
[0], filename
, filename
)
49 params
= {"ssid": "test-vlan-open",
51 "vlan_file": "hostapd.vlan",
52 "accept_mac_file": filename
}
53 hapd
= hostapd
.add_ap(apdev
[0], params
)
55 dev
[0].connect("test-vlan-open", key_mgmt
="NONE", scan_freq
="2412")
56 dev
[1].connect("test-vlan-open", key_mgmt
="NONE", scan_freq
="2412")
57 dev
[2].connect("test-vlan-open", key_mgmt
="NONE", scan_freq
="2412")
58 hwsim_utils
.test_connectivity_iface(dev
[0], hapd
, "brvlan1")
59 hwsim_utils
.test_connectivity_iface(dev
[1], hapd
, "brvlan2")
60 hwsim_utils
.test_connectivity(dev
[2], hapd
)
61 if filename
.startswith('/tmp/'):
64 def test_ap_vlan_file_open2(dev
, apdev
):
65 """AP VLAN with open network and vlan_file mapping (2)"""
66 filename
= hostapd
.acl_file(dev
, apdev
, 'hostapd.accept2')
67 hostapd
.send_file(apdev
[0], filename
, filename
)
68 params
= {"ssid": "test-vlan-open",
70 "vlan_file": "hostapd.vlan2",
71 "accept_mac_file": filename
}
72 hapd
= hostapd
.add_ap(apdev
[0], params
)
74 dev
[0].connect("test-vlan-open", key_mgmt
="NONE", scan_freq
="2412")
75 dev
[1].connect("test-vlan-open", key_mgmt
="NONE", scan_freq
="2412")
76 dev
[2].connect("test-vlan-open", key_mgmt
="NONE", scan_freq
="2412")
77 hwsim_utils
.test_connectivity_iface(dev
[0], hapd
, "brvlan1")
78 hwsim_utils
.test_connectivity_iface(dev
[1], hapd
, "brvlan2")
79 hwsim_utils
.test_connectivity_iface(dev
[2], hapd
, "hwsimbr3")
80 if filename
.startswith('/tmp/'):
83 def test_ap_vlan_file_parsing(dev
, apdev
, params
):
84 """hostapd vlan_file/mac_file parsing"""
85 tmp
= os
.path
.join(params
['logdir'], 'ap_vlan_file_parsing.tmp')
86 params
= {"ssid": "test-vlan-open", "dynamic_vlan": "1"}
87 hapd
= hostapd
.add_ap(apdev
[0], params
)
89 tests
= ["#\n\n0\t11\n",
92 "1 netdev12345678901234567890"]
94 with
open(tmp
, "w") as f
:
96 if "FAIL" not in hapd
.request("SET vlan_file " + tmp
):
97 raise Exception("Invalid vlan_file accepted")
99 with
open(tmp
, "w") as f
:
101 with
alloc_fail(hapd
, 1, "=hostapd_config_read_vlan_file"):
102 if "FAIL" not in hapd
.request("SET vlan_file " + tmp
):
103 raise Exception("vlan_file accepted during OOM")
105 tests
= ["#\n\n0\tvlan\n",
108 "1\t1234567890abcdef1234567890\n",
111 with
open(tmp
, "w") as f
:
113 if "FAIL" not in hapd
.request("SET accept_mac_file " + tmp
):
114 raise Exception("Invalid accept_mac_file accepted")
116 with
open(tmp
, "w") as f
:
117 f
.write("00:11:22:33:44:55\n")
118 with
alloc_fail(hapd
, 1, "hostapd_config_read_maclist"):
119 if "FAIL" not in hapd
.request("SET accept_mac_file " + tmp
):
120 raise Exception("accept_mac_file accepted during OOM")
122 def test_ap_vlan_wpa2(dev
, apdev
):
123 """AP VLAN with WPA2-PSK"""
124 filename
= hostapd
.acl_file(dev
, apdev
, 'hostapd.accept')
125 hostapd
.send_file(apdev
[0], filename
, filename
)
126 params
= hostapd
.wpa2_params(ssid
="test-vlan",
127 passphrase
="12345678")
128 params
['dynamic_vlan'] = "1"
129 params
['accept_mac_file'] = filename
130 hapd
= hostapd
.add_ap(apdev
[0], params
)
132 dev
[0].connect("test-vlan", psk
="12345678", scan_freq
="2412")
133 dev
[1].connect("test-vlan", psk
="12345678", scan_freq
="2412")
134 dev
[2].connect("test-vlan", psk
="12345678", scan_freq
="2412")
138 hwsim_utils
.test_connectivity_iface(dev
[0], hapd
, "brvlan1")
139 hwsim_utils
.test_connectivity_iface(dev
[1], hapd
, "brvlan2")
140 hwsim_utils
.test_connectivity(dev
[2], hapd
)
141 if filename
.startswith('/tmp/'):
144 def test_ap_vlan_wpa2_radius(dev
, apdev
):
145 """AP VLAN with WPA2-Enterprise and RADIUS attributes"""
146 params
= hostapd
.wpa2_eap_params(ssid
="test-vlan")
147 params
['dynamic_vlan'] = "1"
148 hapd
= hostapd
.add_ap(apdev
[0], params
)
150 dev
[0].connect("test-vlan", key_mgmt
="WPA-EAP", eap
="PAX",
152 password_hex
="0123456789abcdef0123456789abcdef",
154 dev
[1].connect("test-vlan", key_mgmt
="WPA-EAP", eap
="PAX",
156 password_hex
="0123456789abcdef0123456789abcdef",
158 dev
[2].connect("test-vlan", key_mgmt
="WPA-EAP", eap
="PAX",
159 identity
="pax.user@example.com",
160 password_hex
="0123456789abcdef0123456789abcdef",
165 hwsim_utils
.test_connectivity_iface(dev
[0], hapd
, "brvlan1")
166 hwsim_utils
.test_connectivity_iface(dev
[1], hapd
, "brvlan2")
167 hwsim_utils
.test_connectivity(dev
[2], hapd
)
169 def test_ap_vlan_wpa2_radius_2(dev
, apdev
):
170 """AP VLAN with WPA2-Enterprise and RADIUS EGRESS_VLANID attributes"""
171 params
= hostapd
.wpa2_eap_params(ssid
="test-vlan")
172 params
['dynamic_vlan'] = "1"
173 hapd
= hostapd
.add_ap(apdev
[0], params
)
175 dev
[0].connect("test-vlan", key_mgmt
="WPA-EAP", eap
="PAX",
177 password_hex
="0123456789abcdef0123456789abcdef",
181 hwsim_utils
.test_connectivity_iface(dev
[0], hapd
, "brvlan1")
183 def test_ap_vlan_wpa2_radius_local(dev
, apdev
):
184 """AP VLAN with WPA2-Enterprise and local file setting VLAN IDs"""
185 filename
= hostapd
.acl_file(dev
, apdev
, 'hostapd.accept')
186 hostapd
.send_file(apdev
[0], filename
, filename
)
187 params
= hostapd
.wpa2_eap_params(ssid
="test-vlan")
188 params
['dynamic_vlan'] = "0"
189 params
['vlan_file'] = "hostapd.vlan"
190 params
['vlan_bridge'] = "test_br_vlan"
191 params
['accept_mac_file'] = filename
192 hapd
= hostapd
.add_ap(apdev
[0], params
)
194 dev
[0].connect("test-vlan", key_mgmt
="WPA-EAP", eap
="PAX",
195 identity
="pax.user@example.com",
196 password_hex
="0123456789abcdef0123456789abcdef",
198 dev
[1].connect("test-vlan", key_mgmt
="WPA-EAP", eap
="PAX",
199 identity
="pax.user@example.com",
200 password_hex
="0123456789abcdef0123456789abcdef",
202 dev
[2].connect("test-vlan", key_mgmt
="WPA-EAP", eap
="PAX",
203 identity
="pax.user@example.com",
204 password_hex
="0123456789abcdef0123456789abcdef",
209 hwsim_utils
.test_connectivity_iface(dev
[0], hapd
, "test_br_vlan1")
210 hwsim_utils
.test_connectivity_iface(dev
[1], hapd
, "test_br_vlan2")
211 hwsim_utils
.test_connectivity(dev
[2], hapd
)
212 if filename
.startswith('/tmp/'):
215 def test_ap_vlan_wpa2_radius_id_change(dev
, apdev
):
216 """AP VLAN with WPA2-Enterprise and RADIUS attributes changing VLANID"""
217 generic_ap_vlan_wpa2_radius_id_change(dev
, apdev
, False)
219 def test_ap_vlan_tagged_wpa2_radius_id_change(dev
, apdev
):
220 """AP tagged VLAN with WPA2-Enterprise and RADIUS attributes changing VLANID"""
224 # Create tagged interface for wpa_supplicant
225 subprocess
.call(['ip', 'link', 'add', 'link', dev
[0].ifname
,
226 'name', ifname1
, 'type', 'vlan', 'id', '1'])
227 subprocess
.call(['ifconfig', ifname1
, 'up'])
229 subprocess
.call(['ip', 'link', 'add', 'link', dev
[0].ifname
,
230 'name', ifname2
, 'type', 'vlan', 'id', '2'])
231 subprocess
.call(['ifconfig', ifname2
, 'up'])
233 generic_ap_vlan_wpa2_radius_id_change(dev
, apdev
, True)
235 subprocess
.call(['ifconfig', ifname1
, 'down'])
236 subprocess
.call(['ifconfig', ifname2
, 'down'])
237 subprocess
.call(['ip', 'link', 'del', ifname1
])
238 subprocess
.call(['ip', 'link', 'del', ifname2
])
240 def generic_ap_vlan_wpa2_radius_id_change(dev
, apdev
, tagged
):
241 as_params
= {"ssid": "as",
242 "beacon_int": "2000",
243 "radius_server_clients": "auth_serv/radius_clients.conf",
244 "radius_server_auth_port": '18128',
246 "eap_user_file": "auth_serv/eap_user.conf",
247 "ca_cert": "auth_serv/ca.pem",
248 "server_cert": "auth_serv/server.pem",
249 "private_key": "auth_serv/server.key"}
250 authserv
= hostapd
.add_ap(apdev
[1], as_params
)
252 params
= hostapd
.wpa2_eap_params(ssid
="test-vlan")
253 params
['dynamic_vlan'] = "1"
254 params
['auth_server_port'] = "18128"
255 hapd
= hostapd
.add_ap(apdev
[0], params
)
257 identity
= "vlan1tagged" if tagged
else "vlan1"
259 dev
[0].connect("test-vlan", key_mgmt
="WPA-EAP", eap
="PAX",
261 password_hex
="0123456789abcdef0123456789abcdef",
265 hwsim_utils
.run_connectivity_test(dev
[0], hapd
, 0, ifname1
="wlan0.1",
268 hwsim_utils
.test_connectivity_iface(dev
[0], hapd
, "brvlan1")
270 logger
.info("VLAN-ID -> 2")
273 authserv
.set('eap_user_file', "auth_serv/eap_user_vlan.conf")
276 dev
[0].dump_monitor()
277 dev
[0].request("REAUTHENTICATE")
278 ev
= dev
[0].wait_event(["CTRL-EVENT-EAP-SUCCESS"], timeout
=15)
280 raise Exception("EAP reauthentication timed out")
281 ev
= dev
[0].wait_event(["WPA: Key negotiation completed"], timeout
=5)
283 raise Exception("4-way handshake after reauthentication timed out")
284 state
= dev
[0].get_status_field('wpa_state')
285 if state
!= "COMPLETED":
286 raise Exception("Unexpected state after reauth: " + state
)
287 sta
= hapd
.get_sta(dev
[0].own_addr())
288 if 'vlan_id' not in sta
:
289 raise Exception("No VLAN ID in STA info")
290 if (not tagged
) and (sta
['vlan_id'] != '2'):
291 raise Exception("Unexpected VLAN ID: " + sta
['vlan_id'])
293 hwsim_utils
.run_connectivity_test(dev
[0], hapd
, 0, ifname1
="wlan0.2",
296 hwsim_utils
.test_connectivity_iface(dev
[0], hapd
, "brvlan2")
298 logger
.info("VLAN-ID -> 1")
302 authserv
.set('eap_user_file', "auth_serv/eap_user.conf")
305 dev
[0].dump_monitor()
306 dev
[0].request("REAUTHENTICATE")
307 ev
= dev
[0].wait_event(["CTRL-EVENT-EAP-SUCCESS"], timeout
=15)
309 raise Exception("EAP reauthentication timed out")
310 ev
= dev
[0].wait_event(["WPA: Key negotiation completed"], timeout
=5)
312 raise Exception("4-way handshake after reauthentication timed out")
313 state
= dev
[0].get_status_field('wpa_state')
314 if state
!= "COMPLETED":
315 raise Exception("Unexpected state after reauth: " + state
)
316 sta
= hapd
.get_sta(dev
[0].own_addr())
317 if 'vlan_id' not in sta
:
318 raise Exception("No VLAN ID in STA info")
319 if (not tagged
) and (sta
['vlan_id'] != '1'):
320 raise Exception("Unexpected VLAN ID: " + sta
['vlan_id'])
324 hwsim_utils
.run_connectivity_test(dev
[0], hapd
, 0,
328 hwsim_utils
.test_connectivity_iface(dev
[0], hapd
, "brvlan1")
329 except Exception as e
:
330 # It is possible for new bridge setup to not be ready immediately, so
331 # try again to avoid reporting issues related to that.
332 logger
.info("First VLAN-ID 1 data test failed - try again")
334 hwsim_utils
.run_connectivity_test(dev
[0], hapd
, 0,
338 hwsim_utils
.test_connectivity_iface(dev
[0], hapd
, "brvlan1")
340 def test_ap_vlan_wpa2_radius_required(dev
, apdev
):
341 """AP VLAN with WPA2-Enterprise and RADIUS attributes required"""
342 params
= hostapd
.wpa2_eap_params(ssid
="test-vlan")
343 params
['dynamic_vlan'] = "2"
344 hostapd
.add_ap(apdev
[0], params
)
346 dev
[0].connect("test-vlan", key_mgmt
="WPA-EAP", eap
="PAX",
348 password_hex
="0123456789abcdef0123456789abcdef",
350 dev
[2].connect("test-vlan", key_mgmt
="WPA-EAP", eap
="PAX",
351 identity
="pax.user@example.com",
352 password_hex
="0123456789abcdef0123456789abcdef",
353 scan_freq
="2412", wait_connect
=False)
354 ev
= dev
[2].wait_event(["CTRL-EVENT-CONNECTED",
355 "CTRL-EVENT-DISCONNECTED"], timeout
=20)
357 raise Exception("Timeout on connection attempt")
358 if "CTRL-EVENT-CONNECTED" in ev
:
359 raise Exception("Unexpected success without tunnel parameters")
361 def test_ap_vlan_tagged(dev
, apdev
):
362 """AP VLAN with tagged interface"""
363 filename
= hostapd
.acl_file(dev
, apdev
, 'hostapd.accept')
364 hostapd
.send_file(apdev
[0], filename
, filename
)
365 params
= {"ssid": "test-vlan-open",
367 "vlan_tagged_interface": "lo",
368 "accept_mac_file": filename
}
369 hapd
= hostapd
.add_ap(apdev
[0], params
)
371 dev
[0].connect("test-vlan-open", key_mgmt
="NONE", scan_freq
="2412")
372 dev
[1].connect("test-vlan-open", key_mgmt
="NONE", scan_freq
="2412")
373 dev
[2].connect("test-vlan-open", key_mgmt
="NONE", scan_freq
="2412")
374 hwsim_utils
.test_connectivity_iface(dev
[0], hapd
, "brlo.1")
375 hwsim_utils
.test_connectivity_iface(dev
[1], hapd
, "brlo.2")
376 hwsim_utils
.test_connectivity(dev
[2], hapd
)
377 if filename
.startswith('/tmp/'):
380 def ap_vlan_iface_cleanup_multibss_cleanup():
381 subprocess
.call(['ifconfig', 'dummy0', 'down'],
382 stderr
=open('/dev/null', 'w'))
383 ifnames
= ['wlan3.1', 'wlan3.2', 'wlan3-2.1', 'wlan3-2.2', 'dummy0.2',
384 'dummy0.1', 'dummy0', 'brvlan1', 'brvlan2']
385 for ifname
in ifnames
:
386 subprocess
.call(['ip', 'link', 'del', ifname
],
387 stderr
=open('/dev/null', 'w'))
389 def ap_vlan_iface_test_and_prepare_environ():
390 ifaces
= netifaces
.interfaces()
391 if "dummy0" in ifaces
:
392 raise Exception("dummy0 already exists before")
393 ifaces
= netifaces
.interfaces()
394 if "dummy0.1" in ifaces
:
395 raise Exception("dummy0.1 already exists before")
397 subprocess
.call(['ip', 'link', 'add', 'dummy0', 'type', 'dummy'])
398 subprocess
.call(['ifconfig', 'dummy0', 'up'])
400 ifaces
= netifaces
.interfaces()
401 if "dummy0" not in ifaces
:
402 raise HwsimSkip("failed to add dummy0 - missing kernel config DUMMY ?")
404 subprocess
.call(['ip', 'link', 'add', 'link', 'dummy0', 'name', 'dummy0.1',
405 'type', 'vlan', 'id', '1'])
407 ifaces
= netifaces
.interfaces()
408 if "dummy0.1" not in ifaces
:
409 raise HwsimSkip("failed to add dummy0.1 - missing kernel config VLAN_8021Q ?")
411 subprocess
.call(['ip', 'link', 'del', 'dummy0.1'])
413 ifaces
= netifaces
.interfaces()
414 if "dummy0.1" in ifaces
:
415 raise Exception("dummy0.1 was not removed before testing")
417 def test_ap_vlan_iface_cleanup_multibss(dev
, apdev
):
418 """AP VLAN operation in multi-BSS multi-VLAN case"""
419 ap_vlan_iface_cleanup_multibss(dev
, apdev
, 'multi-bss-iface.conf')
421 def ap_vlan_iface_cleanup_multibss(dev
, apdev
, cfgfile
):
422 # AP VLAN with WPA2-Enterprise and RADIUS attributes changing VLANID
423 # check that multiple bss do not interfere with each other with respect
424 # to deletion of bridge and tagged interface.
426 if not netifaces_imported
:
427 raise HwsimSkip("python module netifaces not available")
430 ap_vlan_iface_cleanup_multibss_cleanup()
431 ap_vlan_iface_test_and_prepare_environ()
433 as_params
= {"ssid": "as",
434 "beacon_int": "2000",
435 "radius_server_clients": "auth_serv/radius_clients.conf",
436 "radius_server_auth_port": '18128',
438 "eap_user_file": "auth_serv/eap_user.conf",
439 "ca_cert": "auth_serv/ca.pem",
440 "server_cert": "auth_serv/server.pem",
441 "private_key": "auth_serv/server.key",
443 authserv
= hostapd
.add_ap(apdev
[1], as_params
)
445 # start the actual test
446 hapd
= hostapd
.add_iface(apdev
[0], cfgfile
)
447 hapd1
= hostapd
.Hostapd("wlan3-2", 1)
450 ifaces
= netifaces
.interfaces()
451 if "brvlan1" in ifaces
:
452 raise Exception("bridge brvlan1 already exists before")
453 if "brvlan2" in ifaces
:
454 raise Exception("bridge brvlan2 already exists before")
456 dev
[0].connect("bss-1", key_mgmt
="WPA-EAP", eap
="PAX",
458 password_hex
="0123456789abcdef0123456789abcdef",
462 ifaces
= netifaces
.interfaces()
463 if "brvlan1" not in ifaces
:
464 raise Exception("bridge brvlan1 was not created")
466 hwsim_utils
.test_connectivity_iface(dev
[0], hapd
, "brvlan1")
467 if not iface_is_in_bridge("brvlan1", "dummy0.1"):
468 raise Exception("dummy0.1 not in brvlan1")
470 dev
[1].connect("bss-2", key_mgmt
="WPA-EAP", eap
="PAX",
472 password_hex
="0123456789abcdef0123456789abcdef",
476 hwsim_utils
.test_connectivity_iface(dev
[1], hapd1
, "brvlan1")
477 if not iface_is_in_bridge("brvlan1", "dummy0.1"):
478 raise Exception("dummy0.1 not in brvlan1")
481 authserv
.set('eap_user_file', "auth_serv/eap_user_vlan.conf")
484 logger
.info("wlan0 -> VLAN 2")
486 dev
[0].dump_monitor()
487 dev
[0].request("REAUTHENTICATE")
488 ev
= dev
[0].wait_event(["CTRL-EVENT-EAP-SUCCESS"], timeout
=15)
490 raise Exception("EAP reauthentication timed out")
491 ev
= dev
[0].wait_event(["WPA: Key negotiation completed"], timeout
=5)
493 raise Exception("4-way handshake after reauthentication timed out")
494 state
= dev
[0].get_status_field('wpa_state')
495 if state
!= "COMPLETED":
496 raise Exception("Unexpected state after reauth: " + state
)
498 ifaces
= netifaces
.interfaces()
499 if "brvlan1" not in ifaces
:
500 raise Exception("bridge brvlan1 has been removed too early")
502 hwsim_utils
.test_connectivity_iface(dev
[0], hapd
, "brvlan2",
505 if not iface_is_in_bridge("brvlan2", "dummy0.2"):
506 raise Exception("dummy0.2 not in brvlan2")
508 logger
.info("test wlan1 == VLAN 1")
509 hwsim_utils
.test_connectivity_iface(dev
[1], hapd1
, "brvlan1")
510 if not iface_is_in_bridge("brvlan1", "dummy0.1"):
511 raise Exception("dummy0.1 not in brvlan1")
513 logger
.info("wlan1 -> VLAN 2")
515 dev
[1].dump_monitor()
516 dev
[1].request("REAUTHENTICATE")
517 ev
= dev
[1].wait_event(["CTRL-EVENT-EAP-SUCCESS"], timeout
=15)
519 raise Exception("EAP reauthentication timed out")
520 ev
= dev
[1].wait_event(["WPA: Key negotiation completed"], timeout
=5)
522 raise Exception("4-way handshake after reauthentication timed out")
523 state
= dev
[1].get_status_field('wpa_state')
524 if state
!= "COMPLETED":
525 raise Exception("Unexpected state after reauth: " + state
)
527 # it can take some time for data connectivity to be updated
528 hwsim_utils
.test_connectivity_iface(dev
[1], hapd1
, "brvlan2",
530 logger
.info("test wlan0 == VLAN 2")
531 hwsim_utils
.test_connectivity_iface(dev
[0], hapd
, "brvlan2")
533 if not iface_is_in_bridge("brvlan2", "dummy0.2"):
534 raise Exception("dummy0.2 not in brvlan2")
536 ifaces
= netifaces
.interfaces()
537 if "brvlan1" in ifaces
:
538 raise Exception("bridge brvlan1 has not been cleaned up")
540 # disconnect dev0 first to test a corner case
541 dev
[0].request("DISCONNECT")
542 dev
[0].wait_disconnected()
543 dev
[1].request("DISCONNECT")
544 dev
[1].wait_disconnected()
546 # station removal needs some time
549 ifaces
= netifaces
.interfaces()
550 if "brvlan2" not in ifaces
:
553 ifaces
= netifaces
.interfaces()
554 if "brvlan2" in ifaces
:
555 raise Exception("bridge brvlan2 has not been cleaned up")
557 hapd
.request("DISABLE")
559 ap_vlan_iface_cleanup_multibss_cleanup()
561 def test_ap_vlan_iface_cleanup_multibss_per_sta_vif(dev
, apdev
):
562 """AP VLAN operation in multi-BSS multi-VLAN case with per-sta-vif set"""
564 # AP VLAN with WPA2-Enterprise and RADIUS attributes changing VLANID
565 # check that multiple bss do not interfere with each other with respect
566 # to deletion of bridge and tagged interface. per_sta_vif is enabled.
567 ap_vlan_iface_cleanup_multibss(dev
, apdev
,
568 'multi-bss-iface-per_sta_vif.conf')
570 def test_ap_vlan_without_station(dev
, apdev
, p
):
571 """AP VLAN with WPA2-PSK and no station"""
573 filename
= hostapd
.acl_file(dev
, apdev
, 'hostapd.accept')
574 hostapd
.send_file(apdev
[0], filename
, filename
)
575 subprocess
.call(['brctl', 'addbr', 'brvlan1'])
576 subprocess
.call(['brctl', 'setfd', 'brvlan1', '0'])
577 subprocess
.call(['ifconfig', 'brvlan1', 'up'])
578 # use a passphrase wlantest does not know, so it cannot
579 # inject decrypted frames into pcap
580 params
= hostapd
.wpa2_params(ssid
="test-vlan",
581 passphrase
="12345678x")
582 params
['dynamic_vlan'] = "1"
583 params
['vlan_file'] = 'hostapd.wlan3.vlan'
584 params
['accept_mac_file'] = filename
585 hapd
= hostapd
.add_ap(apdev
[0], params
)
587 # inject some traffic
589 da
= "ff:ff:ff:ff:ff:00"
590 hapd
.request('DATA_TEST_CONFIG 1 ifname=brvlan1')
591 hapd
.request('DATA_TEST_TX {} {} 0'.format(da
, sa
))
592 hapd
.request('DATA_TEST_CONFIG 0')
595 dev
[0].connect("test-vlan", psk
="12345678x", scan_freq
="2412")
597 # inject some traffic
599 da
= "ff:ff:ff:ff:ff:01"
600 hapd
.request('DATA_TEST_CONFIG 1 ifname=brvlan1')
601 hapd
.request('DATA_TEST_TX {} {} 0'.format(da
, sa
))
602 hapd
.request('DATA_TEST_CONFIG 0')
604 # let the AP send couple of Beacon frames
606 out
= run_tshark(os
.path
.join(p
['logdir'], "hwsim0.pcapng"),
607 "wlan.da == ff:ff:ff:ff:ff:00",
608 ["wlan.fc.protected"])
611 lines
= out
.splitlines()
613 # Newer kernel versions filter out frames when there are no
614 # authorized stations on an AP/AP_VLAN interface, so do not
615 # trigger an error here.
616 logger
.info("first frame not observed")
619 is_protected
= int(l
, 16)
620 if is_protected
!= 1:
623 raise Exception("Broadcast packets were not encrypted when no station was connected")
625 raise Exception("first frame not observed")
627 out
= run_tshark(os
.path
.join(p
['logdir'], "hwsim0.pcapng"),
628 "wlan.da == ff:ff:ff:ff:ff:01",
629 ["wlan.fc.protected"])
632 lines
= out
.splitlines()
634 raise Exception("second frame not observed")
637 is_protected
= int(l
, 16)
638 if is_protected
!= 1:
641 raise Exception("Broadcast packets were not encrypted when station was connected")
643 raise Exception("second frame not observed")
645 dev
[0].request("DISCONNECT")
646 dev
[0].wait_disconnected()
647 if filename
.startswith('/tmp/'):
651 subprocess
.call(['ip', 'link', 'set', 'dev', 'brvlan1', 'down'])
652 subprocess
.call(['ip', 'link', 'set', 'dev', 'wlan3.1', 'down'],
653 stderr
=open('/dev/null', 'w'))
654 subprocess
.call(['brctl', 'delif', 'brvlan1', 'wlan3.1'],
655 stderr
=open('/dev/null', 'w'))
656 subprocess
.call(['brctl', 'delbr', 'brvlan1'])
659 def test_ap_open_per_sta_vif(dev
, apdev
):
660 """AP VLAN with open network"""
661 params
= {"ssid": "test-vlan-open",
663 hapd
= hostapd
.add_ap(apdev
[0], params
)
665 dev
[0].connect("test-vlan-open", key_mgmt
="NONE", scan_freq
="2412")
666 hwsim_utils
.test_connectivity_iface(dev
[0], hapd
,
667 apdev
[0]['ifname'] + ".4096")
670 def test_ap_vlan_open_per_sta_vif(dev
, apdev
):
671 """AP VLAN (dynamic) with open network"""
672 params
= {"ssid": "test-vlan-open",
675 hapd
= hostapd
.add_ap(apdev
[0], params
)
677 dev
[0].connect("test-vlan-open", key_mgmt
="NONE", scan_freq
="2412")
678 hwsim_utils
.test_connectivity_iface(dev
[0], hapd
,
679 apdev
[0]['ifname'] + ".4096")
681 def test_ap_vlan_wpa2_radius_tagged(dev
, apdev
):
682 """AP VLAN with WPA2-Enterprise and RADIUS EGRESS_VLANID attributes"""
685 params
= hostapd
.wpa2_eap_params(ssid
="test-vlan")
686 params
['dynamic_vlan'] = "1"
687 params
["vlan_naming"] = "1"
688 hapd
= hostapd
.add_ap(apdev
[0], params
)
690 dev
[0].connect("test-vlan", key_mgmt
="WPA-EAP", eap
="PAX",
691 identity
="vlan1tagged",
692 password_hex
="0123456789abcdef0123456789abcdef",
695 # Create tagged interface for wpa_supplicant
696 subprocess
.call(['ip', 'link', 'add', 'link', dev
[0].ifname
,
697 'name', ifname
, 'type', 'vlan', 'id', '1'])
698 subprocess
.call(['ifconfig', ifname
, 'up'])
700 hwsim_utils
.run_connectivity_test(dev
[0], hapd
, 0, ifname1
=ifname
,
703 subprocess
.call(['ifconfig', ifname
, 'down'])
704 subprocess
.call(['ip', 'link', 'del', ifname
])
706 def test_ap_vlan_wpa2_radius_mixed(dev
, apdev
):
707 """AP VLAN with WPA2-Enterprise and tagged+untagged VLANs"""
710 params
= hostapd
.wpa2_eap_params(ssid
="test-vlan")
711 params
['dynamic_vlan'] = "1"
712 params
["vlan_naming"] = "1"
713 hapd
= hostapd
.add_ap(apdev
[0], params
)
715 dev
[0].connect("test-vlan", key_mgmt
="WPA-EAP", eap
="PAX",
716 identity
="vlan12mixed",
717 password_hex
="0123456789abcdef0123456789abcdef",
720 # Add tagged VLAN interface to wpa_supplicant interface for testing
721 subprocess
.call(['ip', 'link', 'add', 'link', dev
[0].ifname
,
722 'name', ifname
, 'type', 'vlan', 'id', '1'])
723 subprocess
.call(['ifconfig', ifname
, 'up'])
725 logger
.info("Test connectivity in untagged VLAN 2")
726 hwsim_utils
.run_connectivity_test(dev
[0], hapd
, 0,
727 ifname1
=dev
[0].ifname
,
729 logger
.info("Test connectivity in tagged VLAN 1")
730 hwsim_utils
.run_connectivity_test(dev
[0], hapd
, 0, ifname1
=ifname
,
733 subprocess
.call(['ifconfig', ifname
, 'down'])
734 subprocess
.call(['ip', 'link', 'del', ifname
])
736 def test_ap_vlan_reconnect(dev
, apdev
):
737 """AP VLAN with WPA2-PSK connect, disconnect, connect"""
738 filename
= hostapd
.acl_file(dev
, apdev
, 'hostapd.accept')
739 hostapd
.send_file(apdev
[0], filename
, filename
)
740 params
= hostapd
.wpa2_params(ssid
="test-vlan",
741 passphrase
="12345678")
742 params
['dynamic_vlan'] = "1"
743 params
['accept_mac_file'] = filename
744 hapd
= hostapd
.add_ap(apdev
[0], params
)
746 logger
.info("connect sta")
747 dev
[0].connect("test-vlan", psk
="12345678", scan_freq
="2412")
749 hwsim_utils
.test_connectivity_iface(dev
[0], hapd
, "brvlan1")
750 logger
.info("disconnect sta")
751 dev
[0].request("REMOVE_NETWORK all")
752 dev
[0].wait_disconnected(timeout
=10)
754 logger
.info("reconnect sta")
755 dev
[0].connect("test-vlan", psk
="12345678", scan_freq
="2412")
757 hwsim_utils
.test_connectivity_iface(dev
[0], hapd
, "brvlan1")
758 if filename
.startswith('/tmp/'):
761 def test_ap_vlan_psk(dev
, apdev
, params
):
762 """AP VLAN based on PSK/passphrase"""
763 psk_file
= os
.path
.join(params
['logdir'], 'ap_vlan_psk.wpa_psk')
764 with
open(psk_file
, 'w') as f
:
765 f
.write('vlanid=1 00:00:00:00:00:00 passphrase-for-vlan-1\n')
766 f
.write('vlanid=2 00:00:00:00:00:00 passphrase-for-vlan-2\n')
767 f
.write('vlanid=3 00:00:00:00:00:00 passphrase-for-vlan-3\n')
769 ssid
= 'test-vlan-rsn'
770 params
= hostapd
.wpa2_params(ssid
=ssid
)
771 params
['dynamic_vlan'] = "1"
772 params
['wpa_psk_file'] = psk_file
773 hapd
= hostapd
.add_ap(apdev
[0], params
)
775 dev
[0].connect(ssid
, psk
="passphrase-for-vlan-1", scan_freq
="2412")
776 dev
[1].connect(ssid
, psk
="passphrase-for-vlan-2", scan_freq
="2412")
777 dev
[2].connect(ssid
, psk
="passphrase-for-vlan-3", scan_freq
="2412")
781 hwsim_utils
.test_connectivity_iface(dev
[0], hapd
, "brvlan1")
782 hwsim_utils
.test_connectivity_iface(dev
[1], hapd
, "brvlan2")
783 hwsim_utils
.test_connectivity_iface(dev
[2], hapd
, "brvlan3")
785 def test_ap_vlan_sae(dev
, apdev
, params
):
786 """AP VLAN based on SAE Password Identifier"""
788 if "SAE" not in dev
[i
].get_capability("auth_alg"):
789 raise HwsimSkip("SAE not supported")
790 params
= hostapd
.wpa2_params(ssid
="test-sae-vlan")
791 params
['wpa_key_mgmt'] = 'SAE'
792 params
['sae_password'] = ['pw1|vlanid=1|id=id1',
793 'pw2|mac=ff:ff:ff:ff:ff:ff|vlanid=2|id=id2',
794 'pw3|vlanid=3|id=id3']
795 params
['dynamic_vlan'] = "1"
796 hapd
= hostapd
.add_ap(apdev
[0], params
)
799 dev
[i
].request("SET sae_groups ")
800 dev
[i
].connect("test-sae-vlan", sae_password
="pw%d" % (i
+ 1),
801 sae_password_id
="id%d" % (i
+ 1),
802 key_mgmt
="SAE", scan_freq
="2412")
805 hwsim_utils
.test_connectivity_iface(dev
[0], hapd
, "brvlan1")
806 hwsim_utils
.test_connectivity_iface(dev
[1], hapd
, "brvlan2")
807 hwsim_utils
.test_connectivity_iface(dev
[2], hapd
, "brvlan3")