test_ap_vlan.py 23 KB

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