test_ap_vht.py 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328
  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 test_dfs import wait_dfs_event
  14. from test_ap_csa import csa_supported
  15. def vht_supported():
  16. cmd = subprocess.Popen(["iw", "reg", "get"], stdout=subprocess.PIPE)
  17. reg = cmd.stdout.read()
  18. if "@ 80)" in reg or "@ 160)" in reg:
  19. return True
  20. return False
  21. def test_ap_vht80(dev, apdev):
  22. """VHT with 80 MHz channel width"""
  23. try:
  24. params = { "ssid": "vht",
  25. "country_code": "FI",
  26. "hw_mode": "a",
  27. "channel": "36",
  28. "ht_capab": "[HT40+]",
  29. "ieee80211n": "1",
  30. "ieee80211ac": "1",
  31. "vht_oper_chwidth": "1",
  32. "vht_oper_centr_freq_seg0_idx": "42" }
  33. hapd = hostapd.add_ap(apdev[0]['ifname'], params)
  34. dev[0].connect("vht", key_mgmt="NONE", scan_freq="5180")
  35. hwsim_utils.test_connectivity(dev[0], hapd)
  36. except Exception, e:
  37. if isinstance(e, Exception) and str(e) == "AP startup failed":
  38. if not vht_supported():
  39. logger.info("80 MHz channel not supported in regulatory information")
  40. return "skip"
  41. raise
  42. finally:
  43. subprocess.call(['sudo', 'iw', 'reg', 'set', '00'])
  44. def test_ap_vht80_params(dev, apdev):
  45. """VHT with 80 MHz channel width and number of optional features enabled"""
  46. try:
  47. params = { "ssid": "vht",
  48. "country_code": "FI",
  49. "hw_mode": "a",
  50. "channel": "36",
  51. "ht_capab": "[HT40+][SHORT-GI-40][DSS_CCK-40]",
  52. "ieee80211n": "1",
  53. "ieee80211ac": "1",
  54. "vht_oper_chwidth": "1",
  55. "vht_capab": "[MAX-MPDU-11454][RXLDPC][SHORT-GI-80][TX-STBC-2BY1][RX-STBC-1][MAX-A-MPDU-LEN-EXP0]",
  56. "vht_oper_centr_freq_seg0_idx": "42",
  57. "require_vht": "1" }
  58. hapd = hostapd.add_ap(apdev[0]['ifname'], params)
  59. dev[1].connect("vht", key_mgmt="NONE", scan_freq="5180",
  60. disable_vht="1", wait_connect=False)
  61. dev[0].connect("vht", key_mgmt="NONE", scan_freq="5180")
  62. ev = dev[1].wait_event(["CTRL-EVENT-ASSOC-REJECT"])
  63. if ev is None:
  64. raise Exception("Association rejection timed out")
  65. if "status_code=104" not in ev:
  66. raise Exception("Unexpected rejection status code")
  67. dev[1].request("DISCONNECT")
  68. hwsim_utils.test_connectivity(dev[0], hapd)
  69. except Exception, e:
  70. if isinstance(e, Exception) and str(e) == "AP startup failed":
  71. if not vht_supported():
  72. logger.info("80 MHz channel not supported in regulatory information")
  73. return "skip"
  74. raise
  75. finally:
  76. subprocess.call(['sudo', 'iw', 'reg', 'set', '00'])
  77. def test_ap_vht_20(devs, apdevs):
  78. dev = devs[0]
  79. ap = apdevs[0]
  80. try:
  81. params = { "ssid": "test-vht20",
  82. "country_code": "DE",
  83. "hw_mode": "a",
  84. "channel": "36",
  85. "ieee80211n": "1",
  86. "ieee80211ac": "1",
  87. "ht_capab": "",
  88. "vht_capab": "",
  89. "vht_oper_chwidth": "0",
  90. "vht_oper_centr_freq_seg0_idx": "0",
  91. "supported_rates": "60 120 240 360 480 540",
  92. "require_vht": "1",
  93. }
  94. hapd = hostapd.add_ap(ap['ifname'], params)
  95. dev.connect("test-vht20", scan_freq="5180", key_mgmt="NONE")
  96. hwsim_utils.test_connectivity(dev, hapd)
  97. finally:
  98. subprocess.call(['sudo', 'iw', 'reg', 'set', '00'])
  99. def test_ap_vht_capab_not_supported(dev, apdev):
  100. """VHT configuration with driver not supporting all vht_capab entries"""
  101. try:
  102. params = { "ssid": "vht",
  103. "country_code": "FI",
  104. "hw_mode": "a",
  105. "channel": "36",
  106. "ht_capab": "[HT40+][SHORT-GI-40][DSS_CCK-40]",
  107. "ieee80211n": "1",
  108. "ieee80211ac": "1",
  109. "vht_oper_chwidth": "1",
  110. "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]",
  111. "vht_oper_centr_freq_seg0_idx": "42",
  112. "require_vht": "1" }
  113. hapd = hostapd.add_ap(apdev[0]['ifname'], params, wait_enabled=False)
  114. ev = hapd.wait_event(["AP-DISABLED"], timeout=5)
  115. if ev is None:
  116. raise Exception("Startup failure not reported")
  117. for i in range(1, 7):
  118. if "OK" not in hapd.request("SET vht_capab [MAX-A-MPDU-LEN-EXP%d]" % i):
  119. raise Exception("Unexpected SET failure")
  120. finally:
  121. subprocess.call(['sudo', 'iw', 'reg', 'set', '00'])
  122. def test_ap_vht160(dev, apdev):
  123. """VHT with 160 MHz channel width"""
  124. try:
  125. params = { "ssid": "vht",
  126. "country_code": "FI",
  127. "hw_mode": "a",
  128. "channel": "36",
  129. "ht_capab": "[HT40+]",
  130. "ieee80211n": "1",
  131. "ieee80211ac": "1",
  132. "vht_oper_chwidth": "2",
  133. "vht_oper_centr_freq_seg0_idx": "50",
  134. 'ieee80211d': '1',
  135. 'ieee80211h': '1' }
  136. hapd = hostapd.add_ap(apdev[0]['ifname'], params, wait_enabled=False)
  137. ev = wait_dfs_event(hapd, "DFS-CAC-START", 5)
  138. if "DFS-CAC-START" not in ev:
  139. raise Exception("Unexpected DFS event")
  140. state = hapd.get_status_field("state")
  141. if state != "DFS":
  142. if state == "DISABLED" and not os.path.exists("dfs"):
  143. # Not all systems have recent enough CRDA version and
  144. # wireless-regdb changes to support 160 MHz and DFS. For now,
  145. # do not report failures for this test case.
  146. return "skip"
  147. raise Exception("Unexpected interface state: " + state)
  148. params = { "ssid": "vht2",
  149. "country_code": "FI",
  150. "hw_mode": "a",
  151. "channel": "100",
  152. "ht_capab": "[HT40+]",
  153. "ieee80211n": "1",
  154. "ieee80211ac": "1",
  155. "vht_oper_chwidth": "2",
  156. "vht_oper_centr_freq_seg0_idx": "114",
  157. 'ieee80211d': '1',
  158. 'ieee80211h': '1' }
  159. hapd2 = hostapd.add_ap(apdev[1]['ifname'], params, wait_enabled=False)
  160. ev = wait_dfs_event(hapd2, "DFS-CAC-START", 5)
  161. if "DFS-CAC-START" not in ev:
  162. raise Exception("Unexpected DFS event(2)")
  163. state = hapd2.get_status_field("state")
  164. if state != "DFS":
  165. raise Exception("Unexpected interface state(2): " + state)
  166. logger.info("Waiting for CAC to complete")
  167. ev = wait_dfs_event(hapd, "DFS-CAC-COMPLETED", 70)
  168. if "success=1" not in ev:
  169. raise Exception("CAC failed")
  170. if "freq=5180" not in ev:
  171. raise Exception("Unexpected DFS freq result")
  172. ev = hapd.wait_event(["AP-ENABLED"], timeout=5)
  173. if not ev:
  174. raise Exception("AP setup timed out")
  175. state = hapd.get_status_field("state")
  176. if state != "ENABLED":
  177. raise Exception("Unexpected interface state")
  178. ev = wait_dfs_event(hapd2, "DFS-CAC-COMPLETED", 70)
  179. if "success=1" not in ev:
  180. raise Exception("CAC failed(2)")
  181. if "freq=5500" not in ev:
  182. raise Exception("Unexpected DFS freq result(2)")
  183. ev = hapd2.wait_event(["AP-ENABLED"], timeout=5)
  184. if not ev:
  185. raise Exception("AP setup timed out(2)")
  186. state = hapd2.get_status_field("state")
  187. if state != "ENABLED":
  188. raise Exception("Unexpected interface state(2)")
  189. freq = hapd2.get_status_field("freq")
  190. if freq != "5500":
  191. raise Exception("Unexpected frequency(2)")
  192. dev[0].connect("vht", key_mgmt="NONE", scan_freq="5180")
  193. hwsim_utils.test_connectivity(dev[0], hapd)
  194. dev[1].connect("vht2", key_mgmt="NONE", scan_freq="5500")
  195. hwsim_utils.test_connectivity(dev[1], hapd2)
  196. except Exception, e:
  197. if isinstance(e, Exception) and str(e) == "AP startup failed":
  198. if not vht_supported():
  199. logger.info("80/160 MHz channel not supported in regulatory information")
  200. return "skip"
  201. raise
  202. finally:
  203. subprocess.call(['sudo', 'iw', 'reg', 'set', '00'])
  204. def test_ap_vht80plus80(dev, apdev):
  205. """VHT with 80+80 MHz channel width"""
  206. try:
  207. params = { "ssid": "vht",
  208. "country_code": "US",
  209. "hw_mode": "a",
  210. "channel": "52",
  211. "ht_capab": "[HT40+]",
  212. "ieee80211n": "1",
  213. "ieee80211ac": "1",
  214. "vht_oper_chwidth": "3",
  215. "vht_oper_centr_freq_seg0_idx": "58",
  216. "vht_oper_centr_freq_seg1_idx": "155",
  217. 'ieee80211d': '1',
  218. 'ieee80211h': '1' }
  219. hapd = hostapd.add_ap(apdev[0]['ifname'], params, wait_enabled=False)
  220. # This will actually fail since DFS on 80+80 is not yet supported
  221. ev = hapd.wait_event(["AP-DISABLED"], timeout=5)
  222. # ignore result to avoid breaking the test once 80+80 DFS gets enabled
  223. params = { "ssid": "vht2",
  224. "country_code": "US",
  225. "hw_mode": "a",
  226. "channel": "36",
  227. "ht_capab": "[HT40+]",
  228. "ieee80211n": "1",
  229. "ieee80211ac": "1",
  230. "vht_oper_chwidth": "3",
  231. "vht_oper_centr_freq_seg0_idx": "42",
  232. "vht_oper_centr_freq_seg1_idx": "155" }
  233. hapd2 = hostapd.add_ap(apdev[1]['ifname'], params, wait_enabled=False)
  234. ev = hapd2.wait_event(["AP-ENABLED"], timeout=5)
  235. if not ev:
  236. raise Exception("AP setup timed out(2)")
  237. state = hapd2.get_status_field("state")
  238. if state != "ENABLED":
  239. raise Exception("Unexpected interface state(2)")
  240. dev[1].connect("vht2", key_mgmt="NONE", scan_freq="5180")
  241. hwsim_utils.test_connectivity(dev[1], hapd2)
  242. except Exception, e:
  243. if isinstance(e, Exception) and str(e) == "AP startup failed":
  244. if not vht_supported():
  245. logger.info("80/160 MHz channel not supported in regulatory information")
  246. return "skip"
  247. raise
  248. finally:
  249. subprocess.call(['sudo', 'iw', 'reg', 'set', '00'])
  250. def test_ap_vht80_csa(dev, apdev):
  251. """VHT with 80 MHz channel width and CSA"""
  252. if not csa_supported(dev[0]):
  253. return "skip"
  254. try:
  255. params = { "ssid": "vht",
  256. "country_code": "US",
  257. "hw_mode": "a",
  258. "channel": "149",
  259. "ht_capab": "[HT40+]",
  260. "ieee80211n": "1",
  261. "ieee80211ac": "1",
  262. "vht_oper_chwidth": "1",
  263. "vht_oper_centr_freq_seg0_idx": "155" }
  264. hapd = hostapd.add_ap(apdev[0]['ifname'], params)
  265. dev[0].connect("vht", key_mgmt="NONE", scan_freq="5745")
  266. hwsim_utils.test_connectivity(dev[0], hapd)
  267. hapd.request("CHAN_SWITCH 5 5180 ht vht blocktx center_freq1=5210 sec_channel_offset=1 bandwidth=80")
  268. ev = hapd.wait_event(["AP-CSA-FINISHED"], timeout=10)
  269. if ev is None:
  270. raise Exception("CSA finished event timed out")
  271. if "freq=5180" not in ev:
  272. raise Exception("Unexpected channel in CSA finished event")
  273. time.sleep(0.5)
  274. hwsim_utils.test_connectivity(dev[0], hapd)
  275. hapd.request("CHAN_SWITCH 5 5745")
  276. ev = hapd.wait_event(["AP-CSA-FINISHED"], timeout=10)
  277. if ev is None:
  278. raise Exception("CSA finished event timed out")
  279. if "freq=5745" not in ev:
  280. raise Exception("Unexpected channel in CSA finished event")
  281. time.sleep(0.5)
  282. hwsim_utils.test_connectivity(dev[0], hapd)
  283. # This CSA to same channel will fail in kernel, so use this only for
  284. # extra code coverage.
  285. hapd.request("CHAN_SWITCH 5 5745")
  286. hapd.wait_event(["AP-CSA-FINISHED"], timeout=1)
  287. except Exception, e:
  288. if isinstance(e, Exception) and str(e) == "AP startup failed":
  289. if not vht_supported():
  290. logger.info("80 MHz channel not supported in regulatory information")
  291. return "skip"
  292. raise
  293. finally:
  294. subprocess.call(['sudo', 'iw', 'reg', 'set', '00'])