test_ap_vht.py 15 KB

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