test_ap_vht.py 35 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899
  1. # Test cases for VHT operations with hostapd
  2. # Copyright (c) 2014, Qualcomm Atheros, Inc.
  3. # Copyright (c) 2013, Intel Corporation
  4. #
  5. # This software may be distributed under the terms of the BSD license.
  6. # See README for more details.
  7. import logging
  8. logger = logging.getLogger()
  9. import os
  10. import subprocess, time
  11. import hwsim_utils
  12. import hostapd
  13. from utils import HwsimSkip
  14. from test_dfs import wait_dfs_event
  15. from test_ap_csa import csa_supported
  16. from test_ap_ht import clear_scan_cache
  17. def vht_supported():
  18. cmd = subprocess.Popen(["iw", "reg", "get"], stdout=subprocess.PIPE)
  19. reg = cmd.stdout.read()
  20. if "@ 80)" in reg or "@ 160)" in reg:
  21. return True
  22. return False
  23. def test_ap_vht80(dev, apdev):
  24. """VHT with 80 MHz channel width"""
  25. try:
  26. hapd = None
  27. params = { "ssid": "vht",
  28. "country_code": "FI",
  29. "hw_mode": "a",
  30. "channel": "36",
  31. "ht_capab": "[HT40+]",
  32. "ieee80211n": "1",
  33. "ieee80211ac": "1",
  34. "vht_oper_chwidth": "1",
  35. "vht_oper_centr_freq_seg0_idx": "42" }
  36. hapd = hostapd.add_ap(apdev[0], params)
  37. bssid = apdev[0]['bssid']
  38. dev[0].connect("vht", key_mgmt="NONE", scan_freq="5180")
  39. hwsim_utils.test_connectivity(dev[0], hapd)
  40. sig = dev[0].request("SIGNAL_POLL").splitlines()
  41. if "FREQUENCY=5180" not in sig:
  42. raise Exception("Unexpected SIGNAL_POLL value(1): " + str(sig))
  43. if "WIDTH=80 MHz" not in sig:
  44. raise Exception("Unexpected SIGNAL_POLL value(2): " + str(sig))
  45. est = dev[0].get_bss(bssid)['est_throughput']
  46. if est != "390001":
  47. raise Exception("Unexpected BSS est_throughput: " + est)
  48. status = hapd.get_status()
  49. logger.info("hostapd STATUS: " + str(status))
  50. if status["ieee80211n"] != "1":
  51. raise Exception("Unexpected STATUS ieee80211n value")
  52. if status["ieee80211ac"] != "1":
  53. raise Exception("Unexpected STATUS ieee80211ac value")
  54. if status["secondary_channel"] != "1":
  55. raise Exception("Unexpected STATUS secondary_channel value")
  56. if status["vht_oper_chwidth"] != "1":
  57. raise Exception("Unexpected STATUS vht_oper_chwidth value")
  58. if status["vht_oper_centr_freq_seg0_idx"] != "42":
  59. raise Exception("Unexpected STATUS vht_oper_centr_freq_seg0_idx value")
  60. except Exception, e:
  61. if isinstance(e, Exception) and str(e) == "AP startup failed":
  62. if not vht_supported():
  63. raise HwsimSkip("80 MHz channel not supported in regulatory information")
  64. raise
  65. finally:
  66. dev[0].request("DISCONNECT")
  67. if hapd:
  68. hapd.request("DISABLE")
  69. subprocess.call(['iw', 'reg', 'set', '00'])
  70. dev[0].flush_scan_cache()
  71. def vht80_test(apdev, dev, channel, ht_capab):
  72. clear_scan_cache(apdev)
  73. try:
  74. hapd = None
  75. params = { "ssid": "vht",
  76. "country_code": "FI",
  77. "hw_mode": "a",
  78. "channel": str(channel),
  79. "ht_capab": ht_capab,
  80. "ieee80211n": "1",
  81. "ieee80211ac": "1",
  82. "vht_oper_chwidth": "1",
  83. "vht_oper_centr_freq_seg0_idx": "42" }
  84. hapd = hostapd.add_ap(apdev, params)
  85. bssid = apdev['bssid']
  86. dev.connect("vht", key_mgmt="NONE", scan_freq=str(5000 + 5 * channel))
  87. hwsim_utils.test_connectivity(dev, hapd)
  88. except Exception, e:
  89. if isinstance(e, Exception) and str(e) == "AP startup failed":
  90. if not vht_supported():
  91. raise HwsimSkip("80 MHz channel not supported in regulatory information")
  92. raise
  93. finally:
  94. dev.request("DISCONNECT")
  95. if hapd:
  96. hapd.request("DISABLE")
  97. subprocess.call(['iw', 'reg', 'set', '00'])
  98. dev.flush_scan_cache()
  99. def test_ap_vht80b(dev, apdev):
  100. """VHT with 80 MHz channel width (HT40- channel 40)"""
  101. vht80_test(apdev[0], dev[0], 40, "[HT40-]")
  102. def test_ap_vht80c(dev, apdev):
  103. """VHT with 80 MHz channel width (HT40+ channel 44)"""
  104. vht80_test(apdev[0], dev[0], 44, "[HT40+]")
  105. def test_ap_vht80d(dev, apdev):
  106. """VHT with 80 MHz channel width (HT40- channel 48)"""
  107. vht80_test(apdev[0], dev[0], 48, "[HT40-]")
  108. def test_ap_vht80_params(dev, apdev):
  109. """VHT with 80 MHz channel width and number of optional features enabled"""
  110. try:
  111. hapd = None
  112. params = { "ssid": "vht",
  113. "country_code": "FI",
  114. "hw_mode": "a",
  115. "channel": "36",
  116. "ht_capab": "[HT40+][SHORT-GI-40][DSS_CCK-40]",
  117. "ieee80211n": "1",
  118. "ieee80211ac": "1",
  119. "vht_oper_chwidth": "1",
  120. "vht_capab": "[MAX-MPDU-11454][RXLDPC][SHORT-GI-80][TX-STBC-2BY1][RX-STBC-1][MAX-A-MPDU-LEN-EXP0]",
  121. "vht_oper_centr_freq_seg0_idx": "42",
  122. "require_vht": "1" }
  123. hapd = hostapd.add_ap(apdev[0], params)
  124. dev[1].connect("vht", key_mgmt="NONE", scan_freq="5180",
  125. disable_vht="1", wait_connect=False)
  126. dev[0].connect("vht", key_mgmt="NONE", scan_freq="5180")
  127. ev = dev[1].wait_event(["CTRL-EVENT-ASSOC-REJECT"])
  128. if ev is None:
  129. raise Exception("Association rejection timed out")
  130. if "status_code=104" not in ev:
  131. raise Exception("Unexpected rejection status code")
  132. dev[1].request("DISCONNECT")
  133. hwsim_utils.test_connectivity(dev[0], hapd)
  134. except Exception, e:
  135. if isinstance(e, Exception) and str(e) == "AP startup failed":
  136. if not vht_supported():
  137. raise HwsimSkip("80 MHz channel not supported in regulatory information")
  138. raise
  139. finally:
  140. dev[0].request("DISCONNECT")
  141. dev[1].request("DISCONNECT")
  142. if hapd:
  143. hapd.request("DISABLE")
  144. subprocess.call(['iw', 'reg', 'set', '00'])
  145. dev[0].flush_scan_cache()
  146. dev[1].flush_scan_cache()
  147. def test_ap_vht80_invalid(dev, apdev):
  148. """VHT with invalid 80 MHz channel configuration (seg1)"""
  149. try:
  150. hapd = None
  151. params = { "ssid": "vht",
  152. "country_code": "US",
  153. "hw_mode": "a",
  154. "channel": "36",
  155. "ht_capab": "[HT40+]",
  156. "ieee80211n": "1",
  157. "ieee80211ac": "1",
  158. "vht_oper_chwidth": "1",
  159. "vht_oper_centr_freq_seg0_idx": "42",
  160. "vht_oper_centr_freq_seg1_idx": "155",
  161. 'ieee80211d': '1',
  162. 'ieee80211h': '1' }
  163. hapd = hostapd.add_ap(apdev[0], params, wait_enabled=False)
  164. # This fails due to unexpected seg1 configuration
  165. ev = hapd.wait_event(["AP-DISABLED"], timeout=5)
  166. if ev is None:
  167. raise Exception("AP-DISABLED not reported")
  168. except Exception, e:
  169. if isinstance(e, Exception) and str(e) == "AP startup failed":
  170. if not vht_supported():
  171. raise HwsimSkip("80/160 MHz channel not supported in regulatory information")
  172. raise
  173. finally:
  174. if hapd:
  175. hapd.request("DISABLE")
  176. subprocess.call(['iw', 'reg', 'set', '00'])
  177. def test_ap_vht80_invalid2(dev, apdev):
  178. """VHT with invalid 80 MHz channel configuration (seg0)"""
  179. try:
  180. hapd = None
  181. params = { "ssid": "vht",
  182. "country_code": "US",
  183. "hw_mode": "a",
  184. "channel": "36",
  185. "ht_capab": "[HT40+]",
  186. "ieee80211n": "1",
  187. "ieee80211ac": "1",
  188. "vht_oper_chwidth": "1",
  189. "vht_oper_centr_freq_seg0_idx": "46",
  190. 'ieee80211d': '1',
  191. 'ieee80211h': '1' }
  192. hapd = hostapd.add_ap(apdev[0], params, wait_enabled=False)
  193. # This fails due to invalid seg0 configuration
  194. ev = hapd.wait_event(["AP-DISABLED"], timeout=5)
  195. if ev is None:
  196. raise Exception("AP-DISABLED not reported")
  197. except Exception, e:
  198. if isinstance(e, Exception) and str(e) == "AP startup failed":
  199. if not vht_supported():
  200. raise HwsimSkip("80/160 MHz channel not supported in regulatory information")
  201. raise
  202. finally:
  203. if hapd:
  204. hapd.request("DISABLE")
  205. subprocess.call(['iw', 'reg', 'set', '00'])
  206. def test_ap_vht_20(devs, apdevs):
  207. """VHT and 20 MHz channel"""
  208. dev = devs[0]
  209. ap = apdevs[0]
  210. try:
  211. hapd = None
  212. params = { "ssid": "test-vht20",
  213. "country_code": "DE",
  214. "hw_mode": "a",
  215. "channel": "36",
  216. "ieee80211n": "1",
  217. "ieee80211ac": "1",
  218. "ht_capab": "",
  219. "vht_capab": "",
  220. "vht_oper_chwidth": "0",
  221. "vht_oper_centr_freq_seg0_idx": "0",
  222. "supported_rates": "60 120 240 360 480 540",
  223. "require_vht": "1",
  224. }
  225. hapd = hostapd.add_ap(ap, params)
  226. dev.connect("test-vht20", scan_freq="5180", key_mgmt="NONE")
  227. hwsim_utils.test_connectivity(dev, hapd)
  228. finally:
  229. dev.request("DISCONNECT")
  230. if hapd:
  231. hapd.request("DISABLE")
  232. subprocess.call(['iw', 'reg', 'set', '00'])
  233. dev.flush_scan_cache()
  234. def test_ap_vht_40(devs, apdevs):
  235. """VHT and 40 MHz channel"""
  236. dev = devs[0]
  237. ap = apdevs[0]
  238. try:
  239. hapd = None
  240. params = { "ssid": "test-vht40",
  241. "country_code": "DE",
  242. "hw_mode": "a",
  243. "channel": "36",
  244. "ieee80211n": "1",
  245. "ieee80211ac": "1",
  246. "ht_capab": "[HT40+]",
  247. "vht_capab": "",
  248. "vht_oper_chwidth": "0",
  249. "vht_oper_centr_freq_seg0_idx": "0",
  250. }
  251. hapd = hostapd.add_ap(ap, params)
  252. dev.connect("test-vht40", scan_freq="5180", key_mgmt="NONE")
  253. hwsim_utils.test_connectivity(dev, hapd)
  254. finally:
  255. dev.request("DISCONNECT")
  256. if hapd:
  257. hapd.request("DISABLE")
  258. subprocess.call(['iw', 'reg', 'set', '00'])
  259. dev.flush_scan_cache()
  260. def test_ap_vht_capab_not_supported(dev, apdev):
  261. """VHT configuration with driver not supporting all vht_capab entries"""
  262. try:
  263. params = { "ssid": "vht",
  264. "country_code": "FI",
  265. "hw_mode": "a",
  266. "channel": "36",
  267. "ht_capab": "[HT40+][SHORT-GI-40][DSS_CCK-40]",
  268. "ieee80211n": "1",
  269. "ieee80211ac": "1",
  270. "vht_oper_chwidth": "1",
  271. "vht_capab": "[MAX-MPDU-7991][MAX-MPDU-11454][VHT160][VHT160-80PLUS80][RXLDPC][SHORT-GI-80][SHORT-GI-160][TX-STBC-2BY1][RX-STBC-1][RX-STBC-12][RX-STBC-123][RX-STBC-1234][SU-BEAMFORMER][SU-BEAMFORMEE][BF-ANTENNA-2][BF-ANTENNA-3][BF-ANTENNA-4][SOUNDING-DIMENSION-2][SOUNDING-DIMENSION-3][SOUNDING-DIMENSION-4][MU-BEAMFORMER][VHT-TXOP-PS][HTC-VHT][MAX-A-MPDU-LEN-EXP0][MAX-A-MPDU-LEN-EXP7][VHT-LINK-ADAPT2][VHT-LINK-ADAPT3][RX-ANTENNA-PATTERN][TX-ANTENNA-PATTERN]",
  272. "vht_oper_centr_freq_seg0_idx": "42",
  273. "require_vht": "1" }
  274. hapd = hostapd.add_ap(apdev[0], params, wait_enabled=False)
  275. ev = hapd.wait_event(["AP-DISABLED"], timeout=5)
  276. if ev is None:
  277. raise Exception("Startup failure not reported")
  278. for i in range(1, 7):
  279. if "OK" not in hapd.request("SET vht_capab [MAX-A-MPDU-LEN-EXP%d]" % i):
  280. raise Exception("Unexpected SET failure")
  281. finally:
  282. subprocess.call(['iw', 'reg', 'set', '00'])
  283. def test_ap_vht160(dev, apdev):
  284. """VHT with 160 MHz channel width"""
  285. try:
  286. hapd = None
  287. hapd2 = None
  288. params = { "ssid": "vht",
  289. "country_code": "FI",
  290. "hw_mode": "a",
  291. "channel": "36",
  292. "ht_capab": "[HT40+]",
  293. "ieee80211n": "1",
  294. "ieee80211ac": "1",
  295. "vht_oper_chwidth": "2",
  296. "vht_oper_centr_freq_seg0_idx": "50",
  297. 'ieee80211d': '1',
  298. 'ieee80211h': '1' }
  299. hapd = hostapd.add_ap(apdev[0], params, wait_enabled=False)
  300. ev = wait_dfs_event(hapd, "DFS-CAC-START", 5)
  301. if "DFS-CAC-START" not in ev:
  302. raise Exception("Unexpected DFS event")
  303. state = hapd.get_status_field("state")
  304. if state != "DFS":
  305. if state == "DISABLED" and not os.path.exists("dfs"):
  306. # Not all systems have recent enough CRDA version and
  307. # wireless-regdb changes to support 160 MHz and DFS. For now,
  308. # do not report failures for this test case.
  309. raise HwsimSkip("CRDA or wireless-regdb did not support 160 MHz")
  310. raise Exception("Unexpected interface state: " + state)
  311. params = { "ssid": "vht2",
  312. "country_code": "FI",
  313. "hw_mode": "a",
  314. "channel": "104",
  315. "ht_capab": "[HT40-]",
  316. "ieee80211n": "1",
  317. "ieee80211ac": "1",
  318. "vht_oper_chwidth": "2",
  319. "vht_oper_centr_freq_seg0_idx": "114",
  320. 'ieee80211d': '1',
  321. 'ieee80211h': '1' }
  322. hapd2 = hostapd.add_ap(apdev[1], params, wait_enabled=False)
  323. ev = wait_dfs_event(hapd2, "DFS-CAC-START", 5)
  324. if "DFS-CAC-START" not in ev:
  325. raise Exception("Unexpected DFS event(2)")
  326. state = hapd2.get_status_field("state")
  327. if state != "DFS":
  328. raise Exception("Unexpected interface state(2): " + state)
  329. logger.info("Waiting for CAC to complete")
  330. ev = wait_dfs_event(hapd, "DFS-CAC-COMPLETED", 70)
  331. if "success=1" not in ev:
  332. raise Exception("CAC failed")
  333. if "freq=5180" not in ev:
  334. raise Exception("Unexpected DFS freq result")
  335. ev = hapd.wait_event(["AP-ENABLED"], timeout=5)
  336. if not ev:
  337. raise Exception("AP setup timed out")
  338. state = hapd.get_status_field("state")
  339. if state != "ENABLED":
  340. raise Exception("Unexpected interface state")
  341. ev = wait_dfs_event(hapd2, "DFS-CAC-COMPLETED", 70)
  342. if "success=1" not in ev:
  343. raise Exception("CAC failed(2)")
  344. if "freq=5520" not in ev:
  345. raise Exception("Unexpected DFS freq result(2)")
  346. ev = hapd2.wait_event(["AP-ENABLED"], timeout=5)
  347. if not ev:
  348. raise Exception("AP setup timed out(2)")
  349. state = hapd2.get_status_field("state")
  350. if state != "ENABLED":
  351. raise Exception("Unexpected interface state(2)")
  352. freq = hapd2.get_status_field("freq")
  353. if freq != "5520":
  354. raise Exception("Unexpected frequency(2)")
  355. dev[0].connect("vht", key_mgmt="NONE", scan_freq="5180")
  356. hwsim_utils.test_connectivity(dev[0], hapd)
  357. sig = dev[0].request("SIGNAL_POLL").splitlines()
  358. if "FREQUENCY=5180" not in sig:
  359. raise Exception("Unexpected SIGNAL_POLL value(1): " + str(sig))
  360. if "WIDTH=160 MHz" not in sig:
  361. raise Exception("Unexpected SIGNAL_POLL value(2): " + str(sig))
  362. dev[1].connect("vht2", key_mgmt="NONE", scan_freq="5520")
  363. hwsim_utils.test_connectivity(dev[1], hapd2)
  364. sig = dev[1].request("SIGNAL_POLL").splitlines()
  365. if "FREQUENCY=5520" not in sig:
  366. raise Exception("Unexpected SIGNAL_POLL value(1): " + str(sig))
  367. if "WIDTH=160 MHz" not in sig:
  368. raise Exception("Unexpected SIGNAL_POLL value(2): " + str(sig))
  369. except Exception, e:
  370. if isinstance(e, Exception) and str(e) == "AP startup failed":
  371. if not vht_supported():
  372. raise HwsimSkip("80/160 MHz channel not supported in regulatory information")
  373. raise
  374. finally:
  375. dev[0].request("DISCONNECT")
  376. dev[1].request("DISCONNECT")
  377. if hapd:
  378. hapd.request("DISABLE")
  379. if hapd2:
  380. hapd2.request("DISABLE")
  381. subprocess.call(['iw', 'reg', 'set', '00'])
  382. dev[0].flush_scan_cache()
  383. dev[1].flush_scan_cache()
  384. def test_ap_vht160_no_dfs_100_plus(dev, apdev):
  385. """VHT with 160 MHz channel width and no DFS (100 plus)"""
  386. run_ap_vht160_no_dfs(dev, apdev, "100", "[HT40+]")
  387. def test_ap_vht160_no_dfs(dev, apdev):
  388. """VHT with 160 MHz channel width and no DFS (104 minus)"""
  389. run_ap_vht160_no_dfs(dev, apdev, "104", "[HT40-]")
  390. def test_ap_vht160_no_dfs_108_plus(dev, apdev):
  391. """VHT with 160 MHz channel width and no DFS (108 plus)"""
  392. run_ap_vht160_no_dfs(dev, apdev, "108", "[HT40+]")
  393. def test_ap_vht160_no_dfs_112_minus(dev, apdev):
  394. """VHT with 160 MHz channel width and no DFS (112 minus)"""
  395. run_ap_vht160_no_dfs(dev, apdev, "112", "[HT40-]")
  396. def test_ap_vht160_no_dfs_116_plus(dev, apdev):
  397. """VHT with 160 MHz channel width and no DFS (116 plus)"""
  398. run_ap_vht160_no_dfs(dev, apdev, "116", "[HT40+]")
  399. def test_ap_vht160_no_dfs_120_minus(dev, apdev):
  400. """VHT with 160 MHz channel width and no DFS (120 minus)"""
  401. run_ap_vht160_no_dfs(dev, apdev, "120", "[HT40-]")
  402. def test_ap_vht160_no_dfs_124_plus(dev, apdev):
  403. """VHT with 160 MHz channel width and no DFS (124 plus)"""
  404. run_ap_vht160_no_dfs(dev, apdev, "124", "[HT40+]")
  405. def test_ap_vht160_no_dfs_128_minus(dev, apdev):
  406. """VHT with 160 MHz channel width and no DFS (128 minus)"""
  407. run_ap_vht160_no_dfs(dev, apdev, "128", "[HT40-]")
  408. def run_ap_vht160_no_dfs(dev, apdev, channel, ht_capab):
  409. try:
  410. hapd = None
  411. params = { "ssid": "vht",
  412. "country_code": "ZA",
  413. "hw_mode": "a",
  414. "channel": channel,
  415. "ht_capab": ht_capab,
  416. "ieee80211n": "1",
  417. "ieee80211ac": "1",
  418. "vht_oper_chwidth": "2",
  419. "vht_oper_centr_freq_seg0_idx": "114",
  420. 'ieee80211d': '1',
  421. 'ieee80211h': '1' }
  422. hapd = hostapd.add_ap(apdev[0], params, wait_enabled=False)
  423. ev = hapd.wait_event(["AP-ENABLED"], timeout=2)
  424. if not ev:
  425. cmd = subprocess.Popen(["iw", "reg", "get"], stdout=subprocess.PIPE)
  426. reg = cmd.stdout.readlines()
  427. for r in reg:
  428. if "5490" in r and "DFS" in r:
  429. raise HwsimSkip("ZA regulatory rule did not have DFS requirement removed")
  430. raise Exception("AP setup timed out")
  431. freq = str(int(channel) * 5 + 5000)
  432. dev[0].connect("vht", key_mgmt="NONE", scan_freq=freq)
  433. hwsim_utils.test_connectivity(dev[0], hapd)
  434. sig = dev[0].request("SIGNAL_POLL").splitlines()
  435. if "FREQUENCY=" + freq not in sig:
  436. raise Exception("Unexpected SIGNAL_POLL value(1): " + str(sig))
  437. if "WIDTH=160 MHz" not in sig:
  438. raise Exception("Unexpected SIGNAL_POLL value(2): " + str(sig))
  439. except Exception, e:
  440. if isinstance(e, Exception) and str(e) == "AP startup failed":
  441. if not vht_supported():
  442. raise HwsimSkip("80/160 MHz channel not supported in regulatory information")
  443. raise
  444. finally:
  445. dev[0].request("DISCONNECT")
  446. if hapd:
  447. hapd.request("DISABLE")
  448. subprocess.call(['iw', 'reg', 'set', '00'])
  449. dev[0].flush_scan_cache()
  450. def test_ap_vht160_no_ht40(dev, apdev):
  451. """VHT with 160 MHz channel width and HT40 disabled"""
  452. try:
  453. hapd = None
  454. params = { "ssid": "vht",
  455. "country_code": "ZA",
  456. "hw_mode": "a",
  457. "channel": "108",
  458. "ht_capab": "",
  459. "ieee80211n": "1",
  460. "ieee80211ac": "1",
  461. "vht_oper_chwidth": "2",
  462. "vht_oper_centr_freq_seg0_idx": "114",
  463. 'ieee80211d': '1',
  464. 'ieee80211h': '1' }
  465. hapd = hostapd.add_ap(apdev[0], params, wait_enabled=False)
  466. ev = hapd.wait_event(["AP-ENABLED", "AP-DISABLED"], timeout=2)
  467. if not ev:
  468. cmd = subprocess.Popen(["iw", "reg", "get"], stdout=subprocess.PIPE)
  469. reg = cmd.stdout.readlines()
  470. for r in reg:
  471. if "5490" in r and "DFS" in r:
  472. raise HwsimSkip("ZA regulatory rule did not have DFS requirement removed")
  473. raise Exception("AP setup timed out")
  474. if "AP-ENABLED" in ev:
  475. # This was supposed to fail due to sec_channel_offset == 0
  476. raise Exception("Unexpected AP-ENABLED")
  477. except Exception, e:
  478. if isinstance(e, Exception) and str(e) == "AP startup failed":
  479. if not vht_supported():
  480. raise HwsimSkip("80/160 MHz channel not supported in regulatory information")
  481. raise
  482. finally:
  483. if hapd:
  484. hapd.request("DISABLE")
  485. subprocess.call(['iw', 'reg', 'set', '00'])
  486. def test_ap_vht80plus80(dev, apdev):
  487. """VHT with 80+80 MHz channel width"""
  488. try:
  489. hapd = None
  490. hapd2 = None
  491. params = { "ssid": "vht",
  492. "country_code": "US",
  493. "hw_mode": "a",
  494. "channel": "52",
  495. "ht_capab": "[HT40+]",
  496. "ieee80211n": "1",
  497. "ieee80211ac": "1",
  498. "vht_oper_chwidth": "3",
  499. "vht_oper_centr_freq_seg0_idx": "58",
  500. "vht_oper_centr_freq_seg1_idx": "155",
  501. 'ieee80211d': '1',
  502. 'ieee80211h': '1' }
  503. hapd = hostapd.add_ap(apdev[0], params, wait_enabled=False)
  504. # This will actually fail since DFS on 80+80 is not yet supported
  505. ev = hapd.wait_event(["AP-DISABLED"], timeout=5)
  506. # ignore result to avoid breaking the test once 80+80 DFS gets enabled
  507. params = { "ssid": "vht2",
  508. "country_code": "US",
  509. "hw_mode": "a",
  510. "channel": "36",
  511. "ht_capab": "[HT40+]",
  512. "ieee80211n": "1",
  513. "ieee80211ac": "1",
  514. "vht_oper_chwidth": "3",
  515. "vht_oper_centr_freq_seg0_idx": "42",
  516. "vht_oper_centr_freq_seg1_idx": "155" }
  517. hapd2 = hostapd.add_ap(apdev[1], params, wait_enabled=False)
  518. ev = hapd2.wait_event(["AP-ENABLED", "AP-DISABLED"], timeout=5)
  519. if not ev:
  520. raise Exception("AP setup timed out(2)")
  521. if "AP-DISABLED" in ev:
  522. # Assume this failed due to missing regulatory update for now
  523. raise HwsimSkip("80+80 MHz channel not supported in regulatory information")
  524. state = hapd2.get_status_field("state")
  525. if state != "ENABLED":
  526. raise Exception("Unexpected interface state(2)")
  527. dev[1].connect("vht2", key_mgmt="NONE", scan_freq="5180")
  528. hwsim_utils.test_connectivity(dev[1], hapd2)
  529. sig = dev[1].request("SIGNAL_POLL").splitlines()
  530. if "FREQUENCY=5180" not in sig:
  531. raise Exception("Unexpected SIGNAL_POLL value(1): " + str(sig))
  532. if "WIDTH=80+80 MHz" not in sig:
  533. raise Exception("Unexpected SIGNAL_POLL value(2): " + str(sig))
  534. if "CENTER_FRQ1=5210" not in sig:
  535. raise Exception("Unexpected SIGNAL_POLL value(3): " + str(sig))
  536. if "CENTER_FRQ2=5775" not in sig:
  537. raise Exception("Unexpected SIGNAL_POLL value(4): " + str(sig))
  538. except Exception, e:
  539. if isinstance(e, Exception) and str(e) == "AP startup failed":
  540. if not vht_supported():
  541. raise HwsimSkip("80/160 MHz channel not supported in regulatory information")
  542. raise
  543. finally:
  544. dev[0].request("DISCONNECT")
  545. dev[1].request("DISCONNECT")
  546. if hapd:
  547. hapd.request("DISABLE")
  548. if hapd2:
  549. hapd2.request("DISABLE")
  550. subprocess.call(['iw', 'reg', 'set', '00'])
  551. dev[0].flush_scan_cache()
  552. dev[1].flush_scan_cache()
  553. def test_ap_vht80plus80_invalid(dev, apdev):
  554. """VHT with invalid 80+80 MHz channel"""
  555. try:
  556. hapd = None
  557. params = { "ssid": "vht",
  558. "country_code": "US",
  559. "hw_mode": "a",
  560. "channel": "36",
  561. "ht_capab": "[HT40+]",
  562. "ieee80211n": "1",
  563. "ieee80211ac": "1",
  564. "vht_oper_chwidth": "3",
  565. "vht_oper_centr_freq_seg0_idx": "42",
  566. "vht_oper_centr_freq_seg1_idx": "0",
  567. 'ieee80211d': '1',
  568. 'ieee80211h': '1' }
  569. hapd = hostapd.add_ap(apdev[0], params, wait_enabled=False)
  570. # This fails due to missing(invalid) seg1 configuration
  571. ev = hapd.wait_event(["AP-DISABLED"], timeout=5)
  572. if ev is None:
  573. raise Exception("AP-DISABLED not reported")
  574. except Exception, e:
  575. if isinstance(e, Exception) and str(e) == "AP startup failed":
  576. if not vht_supported():
  577. raise HwsimSkip("80/160 MHz channel not supported in regulatory information")
  578. raise
  579. finally:
  580. if hapd:
  581. hapd.request("DISABLE")
  582. subprocess.call(['iw', 'reg', 'set', '00'])
  583. def test_ap_vht80_csa(dev, apdev):
  584. """VHT with 80 MHz channel width and CSA"""
  585. csa_supported(dev[0])
  586. try:
  587. hapd = None
  588. params = { "ssid": "vht",
  589. "country_code": "US",
  590. "hw_mode": "a",
  591. "channel": "149",
  592. "ht_capab": "[HT40+]",
  593. "ieee80211n": "1",
  594. "ieee80211ac": "1",
  595. "vht_oper_chwidth": "1",
  596. "vht_oper_centr_freq_seg0_idx": "155" }
  597. hapd = hostapd.add_ap(apdev[0], params)
  598. dev[0].connect("vht", key_mgmt="NONE", scan_freq="5745")
  599. hwsim_utils.test_connectivity(dev[0], hapd)
  600. hapd.request("CHAN_SWITCH 5 5180 ht vht blocktx center_freq1=5210 sec_channel_offset=1 bandwidth=80")
  601. ev = hapd.wait_event(["AP-CSA-FINISHED"], timeout=10)
  602. if ev is None:
  603. raise Exception("CSA finished event timed out")
  604. if "freq=5180" not in ev:
  605. raise Exception("Unexpected channel in CSA finished event")
  606. time.sleep(0.5)
  607. hwsim_utils.test_connectivity(dev[0], hapd)
  608. hapd.request("CHAN_SWITCH 5 5745")
  609. ev = hapd.wait_event(["AP-CSA-FINISHED"], timeout=10)
  610. if ev is None:
  611. raise Exception("CSA finished event timed out")
  612. if "freq=5745" not in ev:
  613. raise Exception("Unexpected channel in CSA finished event")
  614. time.sleep(0.5)
  615. hwsim_utils.test_connectivity(dev[0], hapd)
  616. # This CSA to same channel will fail in kernel, so use this only for
  617. # extra code coverage.
  618. hapd.request("CHAN_SWITCH 5 5745")
  619. hapd.wait_event(["AP-CSA-FINISHED"], timeout=1)
  620. except Exception, e:
  621. if isinstance(e, Exception) and str(e) == "AP startup failed":
  622. if not vht_supported():
  623. raise HwsimSkip("80 MHz channel not supported in regulatory information")
  624. raise
  625. finally:
  626. dev[0].request("DISCONNECT")
  627. if hapd:
  628. hapd.request("DISABLE")
  629. subprocess.call(['iw', 'reg', 'set', '00'])
  630. dev[0].flush_scan_cache()
  631. def test_ap_vht_on_24ghz(dev, apdev):
  632. """Subset of VHT features on 2.4 GHz"""
  633. hapd = None
  634. params = { "ssid": "test-vht-2g",
  635. "hw_mode": "g",
  636. "channel": "1",
  637. "ieee80211n": "1",
  638. "vendor_vht": "1",
  639. "vht_capab": "[MAX-MPDU-11454]",
  640. "vht_oper_chwidth": "0",
  641. "vht_oper_centr_freq_seg0_idx": "1"
  642. }
  643. hapd = hostapd.add_ap(apdev[0], params)
  644. try:
  645. if "OK" not in dev[0].request("VENDOR_ELEM_ADD 13 dd1300904c0400bf0c3240820feaff0000eaff0000"):
  646. raise Exception("Failed to add vendor element")
  647. dev[0].connect("test-vht-2g", scan_freq="2412", key_mgmt="NONE")
  648. hwsim_utils.test_connectivity(dev[0], hapd)
  649. sta = hapd.get_sta(dev[0].own_addr())
  650. if '[VENDOR_VHT]' not in sta['flags']:
  651. raise Exception("No VENDOR_VHT STA flag")
  652. dev[1].connect("test-vht-2g", scan_freq="2412", key_mgmt="NONE")
  653. sta = hapd.get_sta(dev[1].own_addr())
  654. if '[VENDOR_VHT]' in sta['flags']:
  655. raise Exception("Unexpected VENDOR_VHT STA flag")
  656. finally:
  657. dev[0].request("VENDOR_ELEM_REMOVE 13 *")
  658. def test_prefer_vht40(dev, apdev):
  659. """Preference on VHT40 over HT40"""
  660. try:
  661. hapd2 = None
  662. params = { "ssid": "test",
  663. "country_code": "FI",
  664. "hw_mode": "a",
  665. "channel": "36",
  666. "ieee80211n": "1",
  667. "ht_capab": "[HT40+]" }
  668. hapd = hostapd.add_ap(apdev[0], params)
  669. bssid = apdev[0]['bssid']
  670. params = { "ssid": "test",
  671. "country_code": "FI",
  672. "hw_mode": "a",
  673. "channel": "36",
  674. "ieee80211n": "1",
  675. "ieee80211ac": "1",
  676. "ht_capab": "[HT40+]",
  677. "vht_capab": "",
  678. "vht_oper_chwidth": "0",
  679. "vht_oper_centr_freq_seg0_idx": "0",
  680. }
  681. hapd2 = hostapd.add_ap(apdev[1], params)
  682. bssid2 = apdev[1]['bssid']
  683. dev[0].scan_for_bss(bssid, freq=5180)
  684. dev[0].scan_for_bss(bssid2, freq=5180)
  685. dev[0].connect("test", scan_freq="5180", key_mgmt="NONE")
  686. if dev[0].get_status_field('bssid') != bssid2:
  687. raise Exception("Unexpected BSS selected")
  688. est = dev[0].get_bss(bssid)['est_throughput']
  689. if est != "135000":
  690. raise Exception("Unexpected BSS0 est_throughput: " + est)
  691. est = dev[0].get_bss(bssid2)['est_throughput']
  692. if est != "135001":
  693. raise Exception("Unexpected BSS1 est_throughput: " + est)
  694. finally:
  695. dev[0].request("DISCONNECT")
  696. if hapd2:
  697. hapd2.request("DISABLE")
  698. subprocess.call(['iw', 'reg', 'set', '00'])
  699. dev[0].flush_scan_cache()
  700. def test_ap_vht80_pwr_constraint(dev, apdev):
  701. """VHT with 80 MHz channel width and local power constraint"""
  702. hapd = None
  703. try:
  704. params = { "ssid": "vht",
  705. "country_code": "FI",
  706. "hw_mode": "a",
  707. "channel": "36",
  708. "ht_capab": "[HT40+]",
  709. "ieee80211d": "1",
  710. "local_pwr_constraint": "3",
  711. "ieee80211n": "1",
  712. "ieee80211ac": "1",
  713. "vht_oper_chwidth": "1",
  714. "vht_oper_centr_freq_seg0_idx": "42" }
  715. hapd = hostapd.add_ap(apdev[0], params)
  716. dev[0].connect("vht", key_mgmt="NONE", scan_freq="5180")
  717. except Exception, e:
  718. if isinstance(e, Exception) and str(e) == "AP startup failed":
  719. if not vht_supported():
  720. raise HwsimSkip("80 MHz channel not supported in regulatory information")
  721. raise
  722. finally:
  723. dev[0].request("DISCONNECT")
  724. if hapd:
  725. hapd.request("DISABLE")
  726. subprocess.call(['iw', 'reg', 'set', '00'])
  727. dev[0].flush_scan_cache()
  728. def test_ap_vht_use_sta_nsts(dev, apdev):
  729. """VHT with 80 MHz channel width and use_sta_nsts=1"""
  730. try:
  731. hapd = None
  732. params = { "ssid": "vht",
  733. "country_code": "FI",
  734. "hw_mode": "a",
  735. "channel": "36",
  736. "ht_capab": "[HT40+]",
  737. "ieee80211n": "1",
  738. "ieee80211ac": "1",
  739. "vht_oper_chwidth": "1",
  740. "vht_oper_centr_freq_seg0_idx": "42",
  741. "use_sta_nsts": "1" }
  742. hapd = hostapd.add_ap(apdev[0], params)
  743. bssid = apdev[0]['bssid']
  744. dev[0].connect("vht", key_mgmt="NONE", scan_freq="5180")
  745. hwsim_utils.test_connectivity(dev[0], hapd)
  746. except Exception, e:
  747. if isinstance(e, Exception) and str(e) == "AP startup failed":
  748. if not vht_supported():
  749. raise HwsimSkip("80 MHz channel not supported in regulatory information")
  750. raise
  751. finally:
  752. dev[0].request("DISCONNECT")
  753. if hapd:
  754. hapd.request("DISABLE")
  755. subprocess.call(['iw', 'reg', 'set', '00'])
  756. dev[0].flush_scan_cache()
  757. def test_ap_vht_tkip(dev, apdev):
  758. """VHT and TKIP"""
  759. try:
  760. hapd = None
  761. params = { "ssid": "vht",
  762. "wpa": "1",
  763. "wpa_key_mgmt": "WPA-PSK",
  764. "wpa_pairwise": "TKIP",
  765. "wpa_passphrase": "12345678",
  766. "country_code": "FI",
  767. "hw_mode": "a",
  768. "channel": "36",
  769. "ht_capab": "[HT40+]",
  770. "ieee80211n": "1",
  771. "ieee80211ac": "1",
  772. "vht_oper_chwidth": "1",
  773. "vht_oper_centr_freq_seg0_idx": "42" }
  774. hapd = hostapd.add_ap(apdev[0], params)
  775. bssid = apdev[0]['bssid']
  776. dev[0].connect("vht", psk="12345678", scan_freq="5180")
  777. hwsim_utils.test_connectivity(dev[0], hapd)
  778. sig = dev[0].request("SIGNAL_POLL").splitlines()
  779. if "FREQUENCY=5180" not in sig:
  780. raise Exception("Unexpected SIGNAL_POLL value(1): " + str(sig))
  781. if "WIDTH=20 MHz (no HT)" not in sig:
  782. raise Exception("Unexpected SIGNAL_POLL value(2): " + str(sig))
  783. status = hapd.get_status()
  784. logger.info("hostapd STATUS: " + str(status))
  785. if status["ieee80211n"] != "0":
  786. raise Exception("Unexpected STATUS ieee80211n value")
  787. if status["ieee80211ac"] != "0":
  788. raise Exception("Unexpected STATUS ieee80211ac value")
  789. if status["secondary_channel"] != "0":
  790. raise Exception("Unexpected STATUS secondary_channel value")
  791. except Exception, e:
  792. if isinstance(e, Exception) and str(e) == "AP startup failed":
  793. if not vht_supported():
  794. raise HwsimSkip("80 MHz channel not supported in regulatory information")
  795. raise
  796. finally:
  797. dev[0].request("DISCONNECT")
  798. if hapd:
  799. hapd.request("DISABLE")
  800. subprocess.call(['iw', 'reg', 'set', '00'])
  801. dev[0].flush_scan_cache()
  802. def test_ap_vht_40_fallback_to_20(devs, apdevs):
  803. """VHT and 40 MHz channel configuration falling back to 20 MHz"""
  804. dev = devs[0]
  805. ap = apdevs[0]
  806. try:
  807. hapd = None
  808. params = { "ssid": "test-vht40",
  809. "country_code": "US",
  810. "hw_mode": "a",
  811. "basic_rates": "60 120 240",
  812. "channel": "161",
  813. "ieee80211d": "1",
  814. "ieee80211h": "1",
  815. "ieee80211n": "1",
  816. "ieee80211ac": "1",
  817. "ht_capab": "[HT40+][SHORT-GI-20][SHORT-GI-40][DSSS_CCK-40]",
  818. "vht_capab": "[RXLDPC][SHORT-GI-80][TX-STBC-2BY1][RX-STBC1][MAX-MPDU-11454][MAX-A-MPDU-LEN-EXP7]",
  819. "vht_oper_chwidth": "0",
  820. "vht_oper_centr_freq_seg0_idx": "155",
  821. }
  822. hapd = hostapd.add_ap(ap, params)
  823. dev.connect("test-vht40", scan_freq="5805", key_mgmt="NONE")
  824. hwsim_utils.test_connectivity(dev, hapd)
  825. finally:
  826. dev.request("DISCONNECT")
  827. if hapd:
  828. hapd.request("DISABLE")
  829. subprocess.call(['iw', 'reg', 'set', '00'])
  830. dev.flush_scan_cache()