test_ap_vht.py 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496
  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. def vht_supported():
  17. cmd = subprocess.Popen(["iw", "reg", "get"], stdout=subprocess.PIPE)
  18. reg = cmd.stdout.read()
  19. if "@ 80)" in reg or "@ 160)" in reg:
  20. return True
  21. return False
  22. def test_ap_vht80(dev, apdev):
  23. """VHT with 80 MHz channel width"""
  24. try:
  25. hapd = None
  26. params = { "ssid": "vht",
  27. "country_code": "FI",
  28. "hw_mode": "a",
  29. "channel": "36",
  30. "ht_capab": "[HT40+]",
  31. "ieee80211n": "1",
  32. "ieee80211ac": "1",
  33. "vht_oper_chwidth": "1",
  34. "vht_oper_centr_freq_seg0_idx": "42" }
  35. hapd = hostapd.add_ap(apdev[0]['ifname'], params)
  36. bssid = apdev[0]['bssid']
  37. dev[0].connect("vht", key_mgmt="NONE", scan_freq="5180")
  38. hwsim_utils.test_connectivity(dev[0], hapd)
  39. est = dev[0].get_bss(bssid)['est_throughput']
  40. if est != "390001":
  41. raise Exception("Unexpected BSS est_throughput: " + est)
  42. except Exception, e:
  43. if isinstance(e, Exception) and str(e) == "AP startup failed":
  44. if not vht_supported():
  45. raise HwsimSkip("80 MHz channel not supported in regulatory information")
  46. raise
  47. finally:
  48. dev[0].request("DISCONNECT")
  49. if hapd:
  50. hapd.request("DISABLE")
  51. subprocess.call(['iw', 'reg', 'set', '00'])
  52. dev[0].flush_scan_cache()
  53. def test_ap_vht80_params(dev, apdev):
  54. """VHT with 80 MHz channel width and number of optional features enabled"""
  55. try:
  56. hapd = None
  57. params = { "ssid": "vht",
  58. "country_code": "FI",
  59. "hw_mode": "a",
  60. "channel": "36",
  61. "ht_capab": "[HT40+][SHORT-GI-40][DSS_CCK-40]",
  62. "ieee80211n": "1",
  63. "ieee80211ac": "1",
  64. "vht_oper_chwidth": "1",
  65. "vht_capab": "[MAX-MPDU-11454][RXLDPC][SHORT-GI-80][TX-STBC-2BY1][RX-STBC-1][MAX-A-MPDU-LEN-EXP0]",
  66. "vht_oper_centr_freq_seg0_idx": "42",
  67. "require_vht": "1" }
  68. hapd = hostapd.add_ap(apdev[0]['ifname'], params)
  69. dev[1].connect("vht", key_mgmt="NONE", scan_freq="5180",
  70. disable_vht="1", wait_connect=False)
  71. dev[0].connect("vht", key_mgmt="NONE", scan_freq="5180")
  72. ev = dev[1].wait_event(["CTRL-EVENT-ASSOC-REJECT"])
  73. if ev is None:
  74. raise Exception("Association rejection timed out")
  75. if "status_code=104" not in ev:
  76. raise Exception("Unexpected rejection status code")
  77. dev[1].request("DISCONNECT")
  78. hwsim_utils.test_connectivity(dev[0], hapd)
  79. except Exception, e:
  80. if isinstance(e, Exception) and str(e) == "AP startup failed":
  81. if not vht_supported():
  82. raise HwsimSkip("80 MHz channel not supported in regulatory information")
  83. raise
  84. finally:
  85. dev[0].request("DISCONNECT")
  86. dev[1].request("DISCONNECT")
  87. if hapd:
  88. hapd.request("DISABLE")
  89. subprocess.call(['iw', 'reg', 'set', '00'])
  90. dev[0].flush_scan_cache()
  91. dev[1].flush_scan_cache()
  92. def test_ap_vht_20(devs, apdevs):
  93. """VHT and 20 MHz channel"""
  94. dev = devs[0]
  95. ap = apdevs[0]
  96. try:
  97. hapd = None
  98. params = { "ssid": "test-vht20",
  99. "country_code": "DE",
  100. "hw_mode": "a",
  101. "channel": "36",
  102. "ieee80211n": "1",
  103. "ieee80211ac": "1",
  104. "ht_capab": "",
  105. "vht_capab": "",
  106. "vht_oper_chwidth": "0",
  107. "vht_oper_centr_freq_seg0_idx": "0",
  108. "supported_rates": "60 120 240 360 480 540",
  109. "require_vht": "1",
  110. }
  111. hapd = hostapd.add_ap(ap['ifname'], params)
  112. dev.connect("test-vht20", scan_freq="5180", key_mgmt="NONE")
  113. hwsim_utils.test_connectivity(dev, hapd)
  114. finally:
  115. dev.request("DISCONNECT")
  116. if hapd:
  117. hapd.request("DISABLE")
  118. subprocess.call(['iw', 'reg', 'set', '00'])
  119. dev.flush_scan_cache()
  120. def test_ap_vht_40(devs, apdevs):
  121. """VHT and 40 MHz channel"""
  122. dev = devs[0]
  123. ap = apdevs[0]
  124. try:
  125. hapd = None
  126. params = { "ssid": "test-vht40",
  127. "country_code": "DE",
  128. "hw_mode": "a",
  129. "channel": "36",
  130. "ieee80211n": "1",
  131. "ieee80211ac": "1",
  132. "ht_capab": "[HT40+]",
  133. "vht_capab": "",
  134. "vht_oper_chwidth": "0",
  135. "vht_oper_centr_freq_seg0_idx": "0",
  136. }
  137. hapd = hostapd.add_ap(ap['ifname'], params)
  138. dev.connect("test-vht40", scan_freq="5180", key_mgmt="NONE")
  139. hwsim_utils.test_connectivity(dev, hapd)
  140. finally:
  141. dev.request("DISCONNECT")
  142. if hapd:
  143. hapd.request("DISABLE")
  144. subprocess.call(['iw', 'reg', 'set', '00'])
  145. dev.flush_scan_cache()
  146. def test_ap_vht_capab_not_supported(dev, apdev):
  147. """VHT configuration with driver not supporting all vht_capab entries"""
  148. try:
  149. params = { "ssid": "vht",
  150. "country_code": "FI",
  151. "hw_mode": "a",
  152. "channel": "36",
  153. "ht_capab": "[HT40+][SHORT-GI-40][DSS_CCK-40]",
  154. "ieee80211n": "1",
  155. "ieee80211ac": "1",
  156. "vht_oper_chwidth": "1",
  157. "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][SOUNDING-DIMENSION-2][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]",
  158. "vht_oper_centr_freq_seg0_idx": "42",
  159. "require_vht": "1" }
  160. hapd = hostapd.add_ap(apdev[0]['ifname'], params, wait_enabled=False)
  161. ev = hapd.wait_event(["AP-DISABLED"], timeout=5)
  162. if ev is None:
  163. raise Exception("Startup failure not reported")
  164. for i in range(1, 7):
  165. if "OK" not in hapd.request("SET vht_capab [MAX-A-MPDU-LEN-EXP%d]" % i):
  166. raise Exception("Unexpected SET failure")
  167. finally:
  168. subprocess.call(['iw', 'reg', 'set', '00'])
  169. def test_ap_vht160(dev, apdev):
  170. """VHT with 160 MHz channel width"""
  171. try:
  172. hapd = None
  173. hapd2 = None
  174. params = { "ssid": "vht",
  175. "country_code": "FI",
  176. "hw_mode": "a",
  177. "channel": "36",
  178. "ht_capab": "[HT40+]",
  179. "ieee80211n": "1",
  180. "ieee80211ac": "1",
  181. "vht_oper_chwidth": "2",
  182. "vht_oper_centr_freq_seg0_idx": "50",
  183. 'ieee80211d': '1',
  184. 'ieee80211h': '1' }
  185. hapd = hostapd.add_ap(apdev[0]['ifname'], params, wait_enabled=False)
  186. ev = wait_dfs_event(hapd, "DFS-CAC-START", 5)
  187. if "DFS-CAC-START" not in ev:
  188. raise Exception("Unexpected DFS event")
  189. state = hapd.get_status_field("state")
  190. if state != "DFS":
  191. if state == "DISABLED" and not os.path.exists("dfs"):
  192. # Not all systems have recent enough CRDA version and
  193. # wireless-regdb changes to support 160 MHz and DFS. For now,
  194. # do not report failures for this test case.
  195. raise HwsimSkip("CRDA or wireless-regdb did not support 160 MHz")
  196. raise Exception("Unexpected interface state: " + state)
  197. params = { "ssid": "vht2",
  198. "country_code": "FI",
  199. "hw_mode": "a",
  200. "channel": "100",
  201. "ht_capab": "[HT40+]",
  202. "ieee80211n": "1",
  203. "ieee80211ac": "1",
  204. "vht_oper_chwidth": "2",
  205. "vht_oper_centr_freq_seg0_idx": "114",
  206. 'ieee80211d': '1',
  207. 'ieee80211h': '1' }
  208. hapd2 = hostapd.add_ap(apdev[1]['ifname'], params, wait_enabled=False)
  209. ev = wait_dfs_event(hapd2, "DFS-CAC-START", 5)
  210. if "DFS-CAC-START" not in ev:
  211. raise Exception("Unexpected DFS event(2)")
  212. state = hapd2.get_status_field("state")
  213. if state != "DFS":
  214. raise Exception("Unexpected interface state(2): " + state)
  215. logger.info("Waiting for CAC to complete")
  216. ev = wait_dfs_event(hapd, "DFS-CAC-COMPLETED", 70)
  217. if "success=1" not in ev:
  218. raise Exception("CAC failed")
  219. if "freq=5180" not in ev:
  220. raise Exception("Unexpected DFS freq result")
  221. ev = hapd.wait_event(["AP-ENABLED"], timeout=5)
  222. if not ev:
  223. raise Exception("AP setup timed out")
  224. state = hapd.get_status_field("state")
  225. if state != "ENABLED":
  226. raise Exception("Unexpected interface state")
  227. ev = wait_dfs_event(hapd2, "DFS-CAC-COMPLETED", 70)
  228. if "success=1" not in ev:
  229. raise Exception("CAC failed(2)")
  230. if "freq=5500" not in ev:
  231. raise Exception("Unexpected DFS freq result(2)")
  232. ev = hapd2.wait_event(["AP-ENABLED"], timeout=5)
  233. if not ev:
  234. raise Exception("AP setup timed out(2)")
  235. state = hapd2.get_status_field("state")
  236. if state != "ENABLED":
  237. raise Exception("Unexpected interface state(2)")
  238. freq = hapd2.get_status_field("freq")
  239. if freq != "5500":
  240. raise Exception("Unexpected frequency(2)")
  241. dev[0].connect("vht", key_mgmt="NONE", scan_freq="5180")
  242. hwsim_utils.test_connectivity(dev[0], hapd)
  243. sig = dev[0].request("SIGNAL_POLL").splitlines()
  244. if "FREQUENCY=5180" not in sig:
  245. raise Exception("Unexpected SIGNAL_POLL value(1): " + str(sig))
  246. if "WIDTH=160 MHz" not in sig:
  247. raise Exception("Unexpected SIGNAL_POLL value(2): " + str(sig))
  248. dev[1].connect("vht2", key_mgmt="NONE", scan_freq="5500")
  249. hwsim_utils.test_connectivity(dev[1], hapd2)
  250. sig = dev[1].request("SIGNAL_POLL").splitlines()
  251. if "FREQUENCY=5500" not in sig:
  252. raise Exception("Unexpected SIGNAL_POLL value(1): " + str(sig))
  253. if "WIDTH=160 MHz" not in sig:
  254. raise Exception("Unexpected SIGNAL_POLL value(2): " + str(sig))
  255. except Exception, e:
  256. if isinstance(e, Exception) and str(e) == "AP startup failed":
  257. if not vht_supported():
  258. raise HwsimSkip("80/160 MHz channel not supported in regulatory information")
  259. raise
  260. finally:
  261. dev[0].request("DISCONNECT")
  262. dev[1].request("DISCONNECT")
  263. if hapd:
  264. hapd.request("DISABLE")
  265. if hapd2:
  266. hapd2.request("DISABLE")
  267. subprocess.call(['iw', 'reg', 'set', '00'])
  268. dev[0].flush_scan_cache()
  269. dev[1].flush_scan_cache()
  270. def test_ap_vht80plus80(dev, apdev):
  271. """VHT with 80+80 MHz channel width"""
  272. try:
  273. hapd = None
  274. hapd2 = None
  275. params = { "ssid": "vht",
  276. "country_code": "US",
  277. "hw_mode": "a",
  278. "channel": "52",
  279. "ht_capab": "[HT40+]",
  280. "ieee80211n": "1",
  281. "ieee80211ac": "1",
  282. "vht_oper_chwidth": "3",
  283. "vht_oper_centr_freq_seg0_idx": "58",
  284. "vht_oper_centr_freq_seg1_idx": "155",
  285. 'ieee80211d': '1',
  286. 'ieee80211h': '1' }
  287. hapd = hostapd.add_ap(apdev[0]['ifname'], params, wait_enabled=False)
  288. # This will actually fail since DFS on 80+80 is not yet supported
  289. ev = hapd.wait_event(["AP-DISABLED"], timeout=5)
  290. # ignore result to avoid breaking the test once 80+80 DFS gets enabled
  291. params = { "ssid": "vht2",
  292. "country_code": "US",
  293. "hw_mode": "a",
  294. "channel": "36",
  295. "ht_capab": "[HT40+]",
  296. "ieee80211n": "1",
  297. "ieee80211ac": "1",
  298. "vht_oper_chwidth": "3",
  299. "vht_oper_centr_freq_seg0_idx": "42",
  300. "vht_oper_centr_freq_seg1_idx": "155" }
  301. hapd2 = hostapd.add_ap(apdev[1]['ifname'], params, wait_enabled=False)
  302. ev = hapd2.wait_event(["AP-ENABLED", "AP-DISABLED"], timeout=5)
  303. if not ev:
  304. raise Exception("AP setup timed out(2)")
  305. if "AP-DISABLED" in ev:
  306. # Assume this failed due to missing regulatory update for now
  307. raise HwsimSkip("80+80 MHz channel not supported in regulatory information")
  308. state = hapd2.get_status_field("state")
  309. if state != "ENABLED":
  310. raise Exception("Unexpected interface state(2)")
  311. dev[1].connect("vht2", key_mgmt="NONE", scan_freq="5180")
  312. hwsim_utils.test_connectivity(dev[1], hapd2)
  313. sig = dev[1].request("SIGNAL_POLL").splitlines()
  314. if "FREQUENCY=5180" not in sig:
  315. raise Exception("Unexpected SIGNAL_POLL value(1): " + str(sig))
  316. if "WIDTH=80+80 MHz" not in sig:
  317. raise Exception("Unexpected SIGNAL_POLL value(2): " + str(sig))
  318. if "CENTER_FRQ1=5210" not in sig:
  319. raise Exception("Unexpected SIGNAL_POLL value(3): " + str(sig))
  320. if "CENTER_FRQ2=5775" not in sig:
  321. raise Exception("Unexpected SIGNAL_POLL value(4): " + str(sig))
  322. except Exception, e:
  323. if isinstance(e, Exception) and str(e) == "AP startup failed":
  324. if not vht_supported():
  325. raise HwsimSkip("80/160 MHz channel not supported in regulatory information")
  326. raise
  327. finally:
  328. dev[0].request("DISCONNECT")
  329. dev[1].request("DISCONNECT")
  330. if hapd:
  331. hapd.request("DISABLE")
  332. if hapd2:
  333. hapd2.request("DISABLE")
  334. subprocess.call(['iw', 'reg', 'set', '00'])
  335. dev[0].flush_scan_cache()
  336. dev[1].flush_scan_cache()
  337. def test_ap_vht80_csa(dev, apdev):
  338. """VHT with 80 MHz channel width and CSA"""
  339. csa_supported(dev[0])
  340. try:
  341. hapd = None
  342. params = { "ssid": "vht",
  343. "country_code": "US",
  344. "hw_mode": "a",
  345. "channel": "149",
  346. "ht_capab": "[HT40+]",
  347. "ieee80211n": "1",
  348. "ieee80211ac": "1",
  349. "vht_oper_chwidth": "1",
  350. "vht_oper_centr_freq_seg0_idx": "155" }
  351. hapd = hostapd.add_ap(apdev[0]['ifname'], params)
  352. dev[0].connect("vht", key_mgmt="NONE", scan_freq="5745")
  353. hwsim_utils.test_connectivity(dev[0], hapd)
  354. hapd.request("CHAN_SWITCH 5 5180 ht vht blocktx center_freq1=5210 sec_channel_offset=1 bandwidth=80")
  355. ev = hapd.wait_event(["AP-CSA-FINISHED"], timeout=10)
  356. if ev is None:
  357. raise Exception("CSA finished event timed out")
  358. if "freq=5180" not in ev:
  359. raise Exception("Unexpected channel in CSA finished event")
  360. time.sleep(0.5)
  361. hwsim_utils.test_connectivity(dev[0], hapd)
  362. hapd.request("CHAN_SWITCH 5 5745")
  363. ev = hapd.wait_event(["AP-CSA-FINISHED"], timeout=10)
  364. if ev is None:
  365. raise Exception("CSA finished event timed out")
  366. if "freq=5745" not in ev:
  367. raise Exception("Unexpected channel in CSA finished event")
  368. time.sleep(0.5)
  369. hwsim_utils.test_connectivity(dev[0], hapd)
  370. # This CSA to same channel will fail in kernel, so use this only for
  371. # extra code coverage.
  372. hapd.request("CHAN_SWITCH 5 5745")
  373. hapd.wait_event(["AP-CSA-FINISHED"], timeout=1)
  374. except Exception, e:
  375. if isinstance(e, Exception) and str(e) == "AP startup failed":
  376. if not vht_supported():
  377. raise HwsimSkip("80 MHz channel not supported in regulatory information")
  378. raise
  379. finally:
  380. dev[0].request("DISCONNECT")
  381. if hapd:
  382. hapd.request("DISABLE")
  383. subprocess.call(['iw', 'reg', 'set', '00'])
  384. dev[0].flush_scan_cache()
  385. def test_ap_vht_on_24ghz(dev, apdev):
  386. """Subset of VHT features on 2.4 GHz"""
  387. hapd = None
  388. params = { "ssid": "test-vht-2g",
  389. "hw_mode": "g",
  390. "channel": "1",
  391. "ieee80211n": "1",
  392. "vendor_vht": "1",
  393. "vht_capab": "[MAX-MPDU-11454]",
  394. "vht_oper_chwidth": "0",
  395. "vht_oper_centr_freq_seg0_idx": "1"
  396. }
  397. hapd = hostapd.add_ap(apdev[0]['ifname'], params)
  398. try:
  399. if "OK" not in dev[0].request("VENDOR_ELEM_ADD 13 dd1300904c0400bf0c3240820feaff0000eaff0000"):
  400. raise Exception("Failed to add vendor element")
  401. dev[0].connect("test-vht-2g", scan_freq="2412", key_mgmt="NONE")
  402. hwsim_utils.test_connectivity(dev[0], hapd)
  403. sta = hapd.get_sta(dev[0].own_addr())
  404. if '[VENDOR_VHT]' not in sta['flags']:
  405. raise Exception("No VENDOR_VHT STA flag")
  406. dev[1].connect("test-vht-2g", scan_freq="2412", key_mgmt="NONE")
  407. sta = hapd.get_sta(dev[1].own_addr())
  408. if '[VENDOR_VHT]' in sta['flags']:
  409. raise Exception("Unexpected VENDOR_VHT STA flag")
  410. finally:
  411. dev[0].request("VENDOR_ELEM_REMOVE 13 *")
  412. def test_prefer_vht40(dev, apdev):
  413. """Preference on VHT40 over HT40"""
  414. try:
  415. hapd2 = None
  416. params = { "ssid": "test",
  417. "country_code": "FI",
  418. "hw_mode": "a",
  419. "channel": "36",
  420. "ieee80211n": "1",
  421. "ht_capab": "[HT40+]" }
  422. hapd = hostapd.add_ap(apdev[0]['ifname'], params)
  423. bssid = apdev[0]['bssid']
  424. params = { "ssid": "test",
  425. "country_code": "FI",
  426. "hw_mode": "a",
  427. "channel": "36",
  428. "ieee80211n": "1",
  429. "ieee80211ac": "1",
  430. "ht_capab": "[HT40+]",
  431. "vht_capab": "",
  432. "vht_oper_chwidth": "0",
  433. "vht_oper_centr_freq_seg0_idx": "0",
  434. }
  435. hapd2 = hostapd.add_ap(apdev[1]['ifname'], params)
  436. bssid2 = apdev[1]['bssid']
  437. dev[0].scan_for_bss(bssid, freq=5180)
  438. dev[0].scan_for_bss(bssid2, freq=5180)
  439. dev[0].connect("test", scan_freq="5180", key_mgmt="NONE")
  440. if dev[0].get_status_field('bssid') != bssid2:
  441. raise Exception("Unexpected BSS selected")
  442. est = dev[0].get_bss(bssid)['est_throughput']
  443. if est != "135000":
  444. raise Exception("Unexpected BSS0 est_throughput: " + est)
  445. est = dev[0].get_bss(bssid2)['est_throughput']
  446. if est != "135001":
  447. raise Exception("Unexpected BSS1 est_throughput: " + est)
  448. finally:
  449. dev[0].request("DISCONNECT")
  450. if hapd2:
  451. hapd2.request("DISABLE")
  452. subprocess.call(['iw', 'reg', 'set', '00'])
  453. dev[0].flush_scan_cache()