test_ap_vht.py 18 KB

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