test_ap_vht.py 13 KB

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