]>
Commit | Line | Data |
---|---|---|
37fa2eb5 JM |
1 | #!/usr/bin/python |
2 | # | |
3 | # Test cases for AP VLAN | |
fac17227 | 4 | # Copyright (c) 2013-2014, Jouni Malinen <j@w1.fi> |
37fa2eb5 JM |
5 | # |
6 | # This software may be distributed under the terms of the BSD license. | |
7 | # See README for more details. | |
8 | ||
9 | import time | |
10 | import subprocess | |
11 | import logging | |
12 | logger = logging.getLogger(__name__) | |
13 | ||
54cf411f MB |
14 | try: |
15 | import netifaces | |
16 | netifaces_imported = True | |
17 | except ImportError: | |
18 | netifaces_imported = False | |
19 | ||
37fa2eb5 JM |
20 | import hwsim_utils |
21 | import hostapd | |
54cf411f | 22 | from utils import iface_is_in_bridge, HwsimSkip |
ee2b0d19 MB |
23 | import os |
24 | from tshark import run_tshark | |
37fa2eb5 JM |
25 | |
26 | def test_ap_vlan_open(dev, apdev): | |
27 | """AP VLAN with open network""" | |
28 | params = { "ssid": "test-vlan-open", | |
29 | "dynamic_vlan": "1", | |
30 | "accept_mac_file": "hostapd.accept" } | |
a8375c94 | 31 | hapd = hostapd.add_ap(apdev[0]['ifname'], params) |
37fa2eb5 JM |
32 | |
33 | dev[0].connect("test-vlan-open", key_mgmt="NONE", scan_freq="2412") | |
34 | dev[1].connect("test-vlan-open", key_mgmt="NONE", scan_freq="2412") | |
35 | dev[2].connect("test-vlan-open", key_mgmt="NONE", scan_freq="2412") | |
1131a1c8 JM |
36 | hwsim_utils.test_connectivity_iface(dev[0], hapd, "brvlan1") |
37 | hwsim_utils.test_connectivity_iface(dev[1], hapd, "brvlan2") | |
a8375c94 | 38 | hwsim_utils.test_connectivity(dev[2], hapd) |
37fa2eb5 | 39 | |
fd6b727e JM |
40 | def test_ap_vlan_file_open(dev, apdev): |
41 | """AP VLAN with open network and vlan_file mapping""" | |
42 | params = { "ssid": "test-vlan-open", | |
43 | "dynamic_vlan": "1", | |
44 | "vlan_file": "hostapd.vlan", | |
45 | "accept_mac_file": "hostapd.accept" } | |
a8375c94 | 46 | hapd = hostapd.add_ap(apdev[0]['ifname'], params) |
fd6b727e JM |
47 | |
48 | dev[0].connect("test-vlan-open", key_mgmt="NONE", scan_freq="2412") | |
49 | dev[1].connect("test-vlan-open", key_mgmt="NONE", scan_freq="2412") | |
50 | dev[2].connect("test-vlan-open", key_mgmt="NONE", scan_freq="2412") | |
1131a1c8 JM |
51 | hwsim_utils.test_connectivity_iface(dev[0], hapd, "brvlan1") |
52 | hwsim_utils.test_connectivity_iface(dev[1], hapd, "brvlan2") | |
a8375c94 | 53 | hwsim_utils.test_connectivity(dev[2], hapd) |
fd6b727e | 54 | |
37fa2eb5 JM |
55 | def test_ap_vlan_wpa2(dev, apdev): |
56 | """AP VLAN with WPA2-PSK""" | |
57 | params = hostapd.wpa2_params(ssid="test-vlan", | |
58 | passphrase="12345678") | |
59 | params['dynamic_vlan'] = "1"; | |
60 | params['accept_mac_file'] = "hostapd.accept"; | |
a8375c94 | 61 | hapd = hostapd.add_ap(apdev[0]['ifname'], params) |
37fa2eb5 JM |
62 | |
63 | dev[0].connect("test-vlan", psk="12345678", scan_freq="2412") | |
64 | dev[1].connect("test-vlan", psk="12345678", scan_freq="2412") | |
65 | dev[2].connect("test-vlan", psk="12345678", scan_freq="2412") | |
1131a1c8 JM |
66 | hwsim_utils.test_connectivity_iface(dev[0], hapd, "brvlan1") |
67 | hwsim_utils.test_connectivity_iface(dev[1], hapd, "brvlan2") | |
a8375c94 | 68 | hwsim_utils.test_connectivity(dev[2], hapd) |
fac17227 JM |
69 | |
70 | def test_ap_vlan_wpa2_radius(dev, apdev): | |
71 | """AP VLAN with WPA2-Enterprise and RADIUS attributes""" | |
72 | params = hostapd.wpa2_eap_params(ssid="test-vlan") | |
73 | params['dynamic_vlan'] = "1"; | |
a8375c94 | 74 | hapd = hostapd.add_ap(apdev[0]['ifname'], params) |
fac17227 JM |
75 | |
76 | dev[0].connect("test-vlan", key_mgmt="WPA-EAP", eap="PAX", | |
77 | identity="vlan1", | |
78 | password_hex="0123456789abcdef0123456789abcdef", | |
79 | scan_freq="2412") | |
80 | dev[1].connect("test-vlan", key_mgmt="WPA-EAP", eap="PAX", | |
81 | identity="vlan2", | |
82 | password_hex="0123456789abcdef0123456789abcdef", | |
83 | scan_freq="2412") | |
84 | dev[2].connect("test-vlan", key_mgmt="WPA-EAP", eap="PAX", | |
85 | identity="pax.user@example.com", | |
86 | password_hex="0123456789abcdef0123456789abcdef", | |
87 | scan_freq="2412") | |
1131a1c8 JM |
88 | hwsim_utils.test_connectivity_iface(dev[0], hapd, "brvlan1") |
89 | hwsim_utils.test_connectivity_iface(dev[1], hapd, "brvlan2") | |
a8375c94 | 90 | hwsim_utils.test_connectivity(dev[2], hapd) |
fac17227 | 91 | |
3a4bace4 JM |
92 | def test_ap_vlan_wpa2_radius_id_change(dev, apdev): |
93 | """AP VLAN with WPA2-Enterprise and RADIUS attributes changing VLANID""" | |
94 | as_params = { "ssid": "as", | |
95 | "beacon_int": "2000", | |
96 | "radius_server_clients": "auth_serv/radius_clients.conf", | |
97 | "radius_server_auth_port": '18128', | |
98 | "eap_server": "1", | |
99 | "eap_user_file": "auth_serv/eap_user.conf", | |
100 | "ca_cert": "auth_serv/ca.pem", | |
101 | "server_cert": "auth_serv/server.pem", | |
102 | "private_key": "auth_serv/server.key" } | |
103 | authserv = hostapd.add_ap(apdev[1]['ifname'], as_params) | |
104 | ||
105 | params = hostapd.wpa2_eap_params(ssid="test-vlan") | |
106 | params['dynamic_vlan'] = "1"; | |
107 | params['auth_server_port'] = "18128" | |
108 | hapd = hostapd.add_ap(apdev[0]['ifname'], params) | |
109 | ||
110 | dev[0].connect("test-vlan", key_mgmt="WPA-EAP", eap="PAX", | |
111 | identity="vlan1", | |
112 | password_hex="0123456789abcdef0123456789abcdef", | |
113 | scan_freq="2412") | |
114 | hwsim_utils.test_connectivity_iface(dev[0], hapd, "brvlan1") | |
115 | ||
bbe9eddc MB |
116 | logger.info("VLAN-ID -> 2") |
117 | ||
3a4bace4 JM |
118 | authserv.disable() |
119 | authserv.set('eap_user_file', "auth_serv/eap_user_vlan.conf") | |
120 | authserv.enable() | |
121 | ||
122 | dev[0].dump_monitor() | |
123 | dev[0].request("REAUTHENTICATE") | |
124 | ev = dev[0].wait_event(["CTRL-EVENT-EAP-SUCCESS"], timeout=15) | |
125 | if ev is None: | |
126 | raise Exception("EAP reauthentication timed out") | |
8aba435b JM |
127 | ev = dev[0].wait_event(["WPA: Key negotiation completed"], timeout=5) |
128 | if ev is None: | |
129 | raise Exception("4-way handshake after reauthentication timed out") | |
3a4bace4 JM |
130 | state = dev[0].get_status_field('wpa_state') |
131 | if state != "COMPLETED": | |
9416e47f | 132 | raise Exception("Unexpected state after reauth: " + state) |
f80fd58d JM |
133 | sta = hapd.get_sta(dev[0].own_addr()) |
134 | if 'vlan_id' not in sta: | |
135 | raise Exception("No VLAN ID in STA info") | |
136 | if sta['vlan_id'] != '2': | |
137 | raise Exception("Unexpected VLAN ID: " + sta['vlan_id']) | |
3a4bace4 JM |
138 | hwsim_utils.test_connectivity_iface(dev[0], hapd, "brvlan2") |
139 | ||
bbe9eddc MB |
140 | logger.info("VLAN-ID -> 1") |
141 | time.sleep(1) | |
142 | ||
143 | authserv.disable() | |
144 | authserv.set('eap_user_file', "auth_serv/eap_user.conf") | |
145 | authserv.enable() | |
146 | ||
147 | dev[0].dump_monitor() | |
148 | dev[0].request("REAUTHENTICATE") | |
149 | ev = dev[0].wait_event(["CTRL-EVENT-EAP-SUCCESS"], timeout=15) | |
150 | if ev is None: | |
151 | raise Exception("EAP reauthentication timed out") | |
152 | ev = dev[0].wait_event(["WPA: Key negotiation completed"], timeout=5) | |
153 | if ev is None: | |
154 | raise Exception("4-way handshake after reauthentication timed out") | |
155 | state = dev[0].get_status_field('wpa_state') | |
156 | if state != "COMPLETED": | |
157 | raise Exception("Unexpected state after reauth: " + state) | |
158 | sta = hapd.get_sta(dev[0].own_addr()) | |
159 | if 'vlan_id' not in sta: | |
160 | raise Exception("No VLAN ID in STA info") | |
161 | if sta['vlan_id'] != '1': | |
162 | raise Exception("Unexpected VLAN ID: " + sta['vlan_id']) | |
163 | time.sleep(0.2) | |
164 | try: | |
165 | hwsim_utils.test_connectivity_iface(dev[0], hapd, "brvlan1") | |
166 | except Exception, e: | |
167 | # It is possible for new bridge setup to not be ready immediately, so | |
168 | # try again to avoid reporting issues related to that. | |
169 | logger.info("First VLAN-ID 1 data test failed - try again") | |
170 | hwsim_utils.test_connectivity_iface(dev[0], hapd, "brvlan1") | |
171 | ||
fac17227 JM |
172 | def test_ap_vlan_wpa2_radius_required(dev, apdev): |
173 | """AP VLAN with WPA2-Enterprise and RADIUS attributes required""" | |
174 | params = hostapd.wpa2_eap_params(ssid="test-vlan") | |
175 | params['dynamic_vlan'] = "2"; | |
176 | hostapd.add_ap(apdev[0]['ifname'], params) | |
177 | ||
178 | dev[0].connect("test-vlan", key_mgmt="WPA-EAP", eap="PAX", | |
179 | identity="vlan1", | |
180 | password_hex="0123456789abcdef0123456789abcdef", | |
181 | scan_freq="2412") | |
182 | dev[2].connect("test-vlan", key_mgmt="WPA-EAP", eap="PAX", | |
183 | identity="pax.user@example.com", | |
184 | password_hex="0123456789abcdef0123456789abcdef", | |
185 | scan_freq="2412", wait_connect=False) | |
186 | ev = dev[2].wait_event(["CTRL-EVENT-CONNECTED", | |
187 | "CTRL-EVENT-DISCONNECTED"], timeout=20) | |
188 | if ev is None: | |
189 | raise Exception("Timeout on connection attempt") | |
190 | if "CTRL-EVENT-CONNECTED" in ev: | |
191 | raise Exception("Unexpected success without tunnel parameters") | |
018ead42 JM |
192 | |
193 | def test_ap_vlan_tagged(dev, apdev): | |
194 | """AP VLAN with tagged interface""" | |
195 | params = { "ssid": "test-vlan-open", | |
196 | "dynamic_vlan": "1", | |
197 | "vlan_tagged_interface": "lo", | |
198 | "accept_mac_file": "hostapd.accept" } | |
a8375c94 | 199 | hapd = hostapd.add_ap(apdev[0]['ifname'], params) |
018ead42 JM |
200 | |
201 | dev[0].connect("test-vlan-open", key_mgmt="NONE", scan_freq="2412") | |
202 | dev[1].connect("test-vlan-open", key_mgmt="NONE", scan_freq="2412") | |
203 | dev[2].connect("test-vlan-open", key_mgmt="NONE", scan_freq="2412") | |
1131a1c8 JM |
204 | hwsim_utils.test_connectivity_iface(dev[0], hapd, "brlo.1") |
205 | hwsim_utils.test_connectivity_iface(dev[1], hapd, "brlo.2") | |
a8375c94 | 206 | hwsim_utils.test_connectivity(dev[2], hapd) |
54cf411f MB |
207 | |
208 | def ap_vlan_iface_cleanup_multibss_cleanup(): | |
209 | subprocess.call(['ifconfig', 'dummy0', 'down'], | |
210 | stderr=open('/dev/null', 'w')) | |
211 | ifnames = [ 'wlan3.1', 'wlan3.2', 'wlan3-2.1', 'wlan3-2.2', 'dummy0.2', | |
212 | 'dummy0.1', 'dummy0', 'brvlan1', 'brvlan2' ] | |
213 | for ifname in ifnames: | |
214 | subprocess.call(['ip', 'link', 'del', ifname], | |
215 | stderr=open('/dev/null', 'w')) | |
216 | ||
217 | def ap_vlan_iface_test_and_prepare_environ(): | |
218 | ifaces = netifaces.interfaces() | |
219 | if "dummy0" in ifaces: | |
220 | raise Exception("dummy0 already exists before") | |
221 | ifaces = netifaces.interfaces() | |
222 | if "dummy0.1" in ifaces: | |
223 | raise Exception("dummy0.1 already exists before") | |
224 | ||
225 | subprocess.call(['ip', 'link', 'add', 'dummy0', 'type', 'dummy']) | |
226 | subprocess.call(['ifconfig', 'dummy0', 'up']) | |
227 | ||
228 | ifaces = netifaces.interfaces() | |
229 | if not("dummy0" in ifaces): | |
230 | raise HwsimSkip("failed to add dummy0 - missing kernel config DUMMY ?") | |
231 | ||
232 | subprocess.call(['ip', 'link', 'add', 'link', 'dummy0', 'name', 'dummy0.1', | |
233 | 'type', 'vlan', 'id', '1']) | |
234 | ||
235 | ifaces = netifaces.interfaces() | |
236 | if not("dummy0.1" in ifaces): | |
237 | raise HwsimSkip("failed to add dummy0.1 - missing kernel config VLAN_8021Q ?") | |
238 | ||
239 | subprocess.call(['ip', 'link', 'del', 'dummy0.1']) | |
240 | ||
241 | ifaces = netifaces.interfaces() | |
242 | if "dummy0.1" in ifaces: | |
243 | raise Exception("dummy0.1 was not removed before testing") | |
244 | ||
245 | def test_ap_vlan_iface_cleanup_multibss(dev, apdev): | |
246 | """AP VLAN operation in multi-BSS multi-VLAN case""" | |
a8c235ee | 247 | ap_vlan_iface_cleanup_multibss(dev, apdev, 'multi-bss-iface.conf') |
54cf411f | 248 | |
a8c235ee | 249 | def ap_vlan_iface_cleanup_multibss(dev, apdev, cfgfile): |
54cf411f MB |
250 | # AP VLAN with WPA2-Enterprise and RADIUS attributes changing VLANID |
251 | # check that multiple bss do not interfere with each other with respect | |
252 | # to deletion of bridge and tagged interface. | |
253 | ||
254 | if not netifaces_imported: | |
255 | raise HwsimSkip("python module netifaces not available") | |
256 | ||
257 | try: | |
258 | ap_vlan_iface_cleanup_multibss_cleanup() | |
259 | ap_vlan_iface_test_and_prepare_environ() | |
260 | ||
261 | as_params = { "ssid": "as", | |
262 | "beacon_int": "2000", | |
263 | "radius_server_clients": "auth_serv/radius_clients.conf", | |
264 | "radius_server_auth_port": '18128', | |
265 | "eap_server": "1", | |
266 | "eap_user_file": "auth_serv/eap_user.conf", | |
267 | "ca_cert": "auth_serv/ca.pem", | |
268 | "server_cert": "auth_serv/server.pem", | |
269 | "private_key": "auth_serv/server.key", | |
270 | "vlan_naming": "1" } | |
271 | authserv = hostapd.add_ap(apdev[1]['ifname'], as_params) | |
272 | ||
273 | ifname = apdev[0]['ifname'] | |
274 | ||
275 | # start the actual test | |
a8c235ee | 276 | hostapd.add_iface(ifname, cfgfile) |
54cf411f MB |
277 | hapd = hostapd.Hostapd(ifname) |
278 | hapd1 = hostapd.Hostapd("wlan3-2", 1) | |
279 | hapd1.enable() | |
280 | ||
281 | ifaces = netifaces.interfaces() | |
282 | if "brvlan1" in ifaces: | |
283 | raise Exception("bridge brvlan1 already exists before") | |
284 | if "brvlan2" in ifaces: | |
285 | raise Exception("bridge brvlan2 already exists before") | |
286 | ||
287 | dev[0].connect("bss-1", key_mgmt="WPA-EAP", eap="PAX", | |
288 | identity="vlan1", | |
289 | password_hex="0123456789abcdef0123456789abcdef", | |
290 | scan_freq="2412") | |
291 | ||
292 | ifaces = netifaces.interfaces() | |
293 | if not("brvlan1" in ifaces): | |
294 | raise Exception("bridge brvlan1 was not created") | |
295 | ||
296 | hwsim_utils.test_connectivity_iface(dev[0], hapd, "brvlan1") | |
297 | if not iface_is_in_bridge("brvlan1", "dummy0.1"): | |
298 | raise Exception("dummy0.1 not in brvlan1") | |
299 | ||
300 | dev[1].connect("bss-2", key_mgmt="WPA-EAP", eap="PAX", | |
301 | identity="vlan1", | |
302 | password_hex="0123456789abcdef0123456789abcdef", | |
303 | scan_freq="2412") | |
304 | ||
305 | hwsim_utils.test_connectivity_iface(dev[1], hapd1, "brvlan1") | |
306 | if not iface_is_in_bridge("brvlan1", "dummy0.1"): | |
307 | raise Exception("dummy0.1 not in brvlan1") | |
308 | ||
309 | authserv.disable() | |
310 | authserv.set('eap_user_file', "auth_serv/eap_user_vlan.conf") | |
311 | authserv.enable() | |
312 | ||
313 | logger.info("wlan0 -> VLAN 2") | |
314 | ||
315 | dev[0].dump_monitor() | |
316 | dev[0].request("REAUTHENTICATE") | |
317 | ev = dev[0].wait_event(["CTRL-EVENT-EAP-SUCCESS"], timeout=15) | |
318 | if ev is None: | |
319 | raise Exception("EAP reauthentication timed out") | |
320 | ev = dev[0].wait_event(["WPA: Key negotiation completed"], timeout=5) | |
321 | if ev is None: | |
322 | raise Exception("4-way handshake after reauthentication timed out") | |
323 | state = dev[0].get_status_field('wpa_state') | |
324 | if state != "COMPLETED": | |
325 | raise Exception("Unexpected state after reauth: " + state) | |
326 | ||
327 | ifaces = netifaces.interfaces() | |
328 | if not ("brvlan1" in ifaces): | |
329 | raise Exception("bridge brvlan1 has been removed too early") | |
330 | ||
331 | hwsim_utils.test_connectivity_iface(dev[0], hapd, "brvlan2", | |
332 | max_tries=5) | |
333 | ||
334 | if not iface_is_in_bridge("brvlan2", "dummy0.2"): | |
335 | raise Exception("dummy0.2 not in brvlan2") | |
336 | ||
337 | logger.info("test wlan1 == VLAN 1") | |
338 | hwsim_utils.test_connectivity_iface(dev[1], hapd1, "brvlan1") | |
339 | if not iface_is_in_bridge("brvlan1", "dummy0.1"): | |
340 | raise Exception("dummy0.1 not in brvlan1") | |
341 | ||
342 | logger.info("wlan1 -> VLAN 2") | |
343 | ||
344 | dev[1].dump_monitor() | |
345 | dev[1].request("REAUTHENTICATE") | |
346 | ev = dev[1].wait_event(["CTRL-EVENT-EAP-SUCCESS"], timeout=15) | |
347 | if ev is None: | |
348 | raise Exception("EAP reauthentication timed out") | |
349 | ev = dev[1].wait_event(["WPA: Key negotiation completed"], timeout=5) | |
350 | if ev is None: | |
351 | raise Exception("4-way handshake after reauthentication timed out") | |
352 | state = dev[1].get_status_field('wpa_state') | |
353 | if state != "COMPLETED": | |
354 | raise Exception("Unexpected state after reauth: " + state) | |
355 | ||
356 | # it can take some time for data connectivity to be updated | |
357 | hwsim_utils.test_connectivity_iface(dev[1], hapd1, "brvlan2", | |
358 | max_tries=5) | |
359 | logger.info("test wlan0 == VLAN 2") | |
360 | hwsim_utils.test_connectivity_iface(dev[0], hapd, "brvlan2") | |
361 | ||
362 | if not iface_is_in_bridge("brvlan2", "dummy0.2"): | |
363 | raise Exception("dummy0.2 not in brvlan2") | |
364 | ||
365 | ifaces = netifaces.interfaces() | |
366 | if "brvlan1" in ifaces: | |
367 | raise Exception("bridge brvlan1 has not been cleaned up") | |
368 | ||
369 | # disconnect dev0 first to test a corner case | |
370 | dev[0].request("DISCONNECT") | |
371 | dev[0].wait_disconnected() | |
372 | dev[1].request("DISCONNECT") | |
373 | dev[1].wait_disconnected() | |
374 | ||
375 | # station removal needs some time | |
376 | for i in range(5): | |
377 | time.sleep(1) | |
378 | ifaces = netifaces.interfaces() | |
379 | if "brvlan2" not in ifaces: | |
380 | break | |
381 | ||
382 | ifaces = netifaces.interfaces() | |
383 | if "brvlan2" in ifaces: | |
384 | raise Exception("bridge brvlan2 has not been cleaned up") | |
385 | ||
386 | hapd.request("DISABLE") | |
387 | finally: | |
388 | ap_vlan_iface_cleanup_multibss_cleanup() | |
ee2b0d19 | 389 | |
a8c235ee MB |
390 | def test_ap_vlan_iface_cleanup_multibss_per_sta_vif(dev, apdev): |
391 | """AP VLAN operation in multi-BSS multi-VLAN case with per-sta-vif set""" | |
392 | ||
393 | # AP VLAN with WPA2-Enterprise and RADIUS attributes changing VLANID | |
394 | # check that multiple bss do not interfere with each other with respect | |
395 | # to deletion of bridge and tagged interface. per_sta_vif is enabled. | |
396 | ap_vlan_iface_cleanup_multibss(dev, apdev, | |
397 | 'multi-bss-iface-per_sta_vif.conf') | |
398 | ||
ee2b0d19 MB |
399 | def test_ap_vlan_without_station(dev, apdev, p): |
400 | """AP VLAN with WPA2-PSK and no station""" | |
401 | try: | |
402 | subprocess.call(['brctl', 'addbr', 'brvlan1']) | |
403 | subprocess.call(['brctl', 'setfd', 'brvlan1', '0']) | |
404 | subprocess.call(['ifconfig', 'brvlan1', 'up']) | |
405 | # use a passphrase wlantest does not know, so it cannot | |
406 | # inject decrypted frames into pcap | |
407 | params = hostapd.wpa2_params(ssid="test-vlan", | |
408 | passphrase="12345678x") | |
409 | params['dynamic_vlan'] = "1"; | |
410 | params['vlan_file'] = 'hostapd.wlan3.vlan' | |
411 | params['accept_mac_file'] = "hostapd.accept"; | |
412 | hapd = hostapd.add_ap(apdev[0]['ifname'], params) | |
413 | ||
414 | # inject some traffic | |
415 | sa = hapd.own_addr() | |
416 | da = "ff:ff:ff:ff:ff:00" | |
417 | hapd.request('DATA_TEST_CONFIG 1 ifname=brvlan1') | |
418 | hapd.request('DATA_TEST_TX {} {} 0'.format(da, sa)) | |
419 | hapd.request('DATA_TEST_CONFIG 0') | |
420 | time.sleep(.1) | |
421 | ||
422 | dev[0].connect("test-vlan", psk="12345678x", scan_freq="2412") | |
423 | ||
424 | # inject some traffic | |
425 | sa = hapd.own_addr() | |
426 | da = "ff:ff:ff:ff:ff:01" | |
427 | hapd.request('DATA_TEST_CONFIG 1 ifname=brvlan1') | |
428 | hapd.request('DATA_TEST_TX {} {} 0'.format(da, sa)) | |
429 | hapd.request('DATA_TEST_CONFIG 0') | |
430 | ||
431 | # let the AP send couple of Beacon frames | |
432 | time.sleep(1) | |
433 | out = run_tshark(os.path.join(p['logdir'], "hwsim0.pcapng"), | |
434 | "wlan.da == ff:ff:ff:ff:ff:00", | |
435 | ["wlan.fc.protected"]) | |
436 | ||
437 | if out is not None: | |
438 | lines = out.splitlines() | |
439 | if len(lines) < 1: | |
440 | raise Exception("first frame not observed") | |
441 | state = 1 | |
442 | for l in lines: | |
443 | is_protected = int(l, 16) | |
444 | if is_protected != 1: | |
445 | state = 0 | |
446 | if state != 1: | |
447 | raise Exception("Broadcast packets were not encrypted when no station was connected") | |
448 | else: | |
449 | raise Exception("first frame not observed") | |
450 | ||
451 | out = run_tshark(os.path.join(p['logdir'], "hwsim0.pcapng"), | |
452 | "wlan.da == ff:ff:ff:ff:ff:01", | |
453 | ["wlan.fc.protected"]) | |
454 | ||
455 | if out is not None: | |
456 | lines = out.splitlines() | |
457 | if len(lines) < 1: | |
458 | raise Exception("second frame not observed") | |
459 | state = 1 | |
460 | for l in lines: | |
461 | is_protected = int(l, 16) | |
462 | if is_protected != 1: | |
463 | state = 0 | |
464 | if state != 1: | |
465 | raise Exception("Broadcast packets were not encrypted when station was connected") | |
466 | else: | |
467 | raise Exception("second frame not observed") | |
468 | ||
469 | dev[0].request("DISCONNECT") | |
470 | dev[0].wait_disconnected() | |
471 | ||
472 | finally: | |
473 | subprocess.call(['ip', 'link', 'set', 'dev', 'brvlan1', 'down']) | |
474 | subprocess.call(['ip', 'link', 'set', 'dev', 'wlan3.1', 'down'], | |
475 | stderr=open('/dev/null', 'w')) | |
476 | subprocess.call(['brctl', 'delif', 'brvlan1', 'wlan3.1'], | |
477 | stderr=open('/dev/null', 'w')) | |
478 | subprocess.call(['brctl', 'delbr', 'brvlan1']) | |
629d3696 MB |
479 | |
480 | def test_ap_vlan_wpa2_radius_tagged(dev, apdev): | |
481 | """AP VLAN with WPA2-Enterprise and RADIUS EGRESS_VLANID attributes""" | |
482 | ifname = 'wlan0.1' | |
483 | try: | |
484 | params = hostapd.wpa2_eap_params(ssid="test-vlan") | |
485 | params['dynamic_vlan'] = "1" | |
486 | params["vlan_naming"] = "1" | |
487 | hapd = hostapd.add_ap(apdev[0]['ifname'], params) | |
488 | ||
489 | dev[0].connect("test-vlan", key_mgmt="WPA-EAP", eap="PAX", | |
490 | identity="vlan1tagged", | |
491 | password_hex="0123456789abcdef0123456789abcdef", | |
492 | scan_freq="2412") | |
493 | ||
494 | # Create tagged interface for wpa_supplicant | |
495 | subprocess.call(['ip', 'link', 'add', 'link', dev[0].ifname, | |
496 | 'name', ifname, 'type', 'vlan', 'id', '1']) | |
497 | subprocess.call(['ifconfig', ifname, 'up']) | |
498 | ||
499 | hwsim_utils.run_connectivity_test(dev[0], hapd, 0, ifname1=ifname, | |
500 | ifname2="brvlan1") | |
501 | finally: | |
502 | subprocess.call(['ifconfig', ifname, 'down']) | |
503 | subprocess.call(['ip', 'link', 'del', ifname]) |