test_ap_vht.py 37 KB

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