test_ap_vht.py 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417
  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_40(devs, apdevs):
  118. """VHT and 40 MHz channel"""
  119. dev = devs[0]
  120. ap = apdevs[0]
  121. try:
  122. hapd = None
  123. params = { "ssid": "test-vht40",
  124. "country_code": "DE",
  125. "hw_mode": "a",
  126. "channel": "36",
  127. "ieee80211n": "1",
  128. "ieee80211ac": "1",
  129. "ht_capab": "[HT40+]",
  130. "vht_capab": "",
  131. "vht_oper_chwidth": "0",
  132. "vht_oper_centr_freq_seg0_idx": "0",
  133. }
  134. hapd = hostapd.add_ap(ap['ifname'], params)
  135. dev.connect("test-vht40", scan_freq="5180", key_mgmt="NONE")
  136. hwsim_utils.test_connectivity(dev, hapd)
  137. finally:
  138. dev.request("DISCONNECT")
  139. if hapd:
  140. hapd.request("DISABLE")
  141. subprocess.call(['sudo', 'iw', 'reg', 'set', '00'])
  142. dev.flush_scan_cache()
  143. def test_ap_vht_capab_not_supported(dev, apdev):
  144. """VHT configuration with driver not supporting all vht_capab entries"""
  145. try:
  146. params = { "ssid": "vht",
  147. "country_code": "FI",
  148. "hw_mode": "a",
  149. "channel": "36",
  150. "ht_capab": "[HT40+][SHORT-GI-40][DSS_CCK-40]",
  151. "ieee80211n": "1",
  152. "ieee80211ac": "1",
  153. "vht_oper_chwidth": "1",
  154. "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]",
  155. "vht_oper_centr_freq_seg0_idx": "42",
  156. "require_vht": "1" }
  157. hapd = hostapd.add_ap(apdev[0]['ifname'], params, wait_enabled=False)
  158. ev = hapd.wait_event(["AP-DISABLED"], timeout=5)
  159. if ev is None:
  160. raise Exception("Startup failure not reported")
  161. for i in range(1, 7):
  162. if "OK" not in hapd.request("SET vht_capab [MAX-A-MPDU-LEN-EXP%d]" % i):
  163. raise Exception("Unexpected SET failure")
  164. finally:
  165. subprocess.call(['sudo', 'iw', 'reg', 'set', '00'])
  166. def test_ap_vht160(dev, apdev):
  167. """VHT with 160 MHz channel width"""
  168. try:
  169. hapd = None
  170. hapd2 = None
  171. params = { "ssid": "vht",
  172. "country_code": "FI",
  173. "hw_mode": "a",
  174. "channel": "36",
  175. "ht_capab": "[HT40+]",
  176. "ieee80211n": "1",
  177. "ieee80211ac": "1",
  178. "vht_oper_chwidth": "2",
  179. "vht_oper_centr_freq_seg0_idx": "50",
  180. 'ieee80211d': '1',
  181. 'ieee80211h': '1' }
  182. hapd = hostapd.add_ap(apdev[0]['ifname'], params, wait_enabled=False)
  183. ev = wait_dfs_event(hapd, "DFS-CAC-START", 5)
  184. if "DFS-CAC-START" not in ev:
  185. raise Exception("Unexpected DFS event")
  186. state = hapd.get_status_field("state")
  187. if state != "DFS":
  188. if state == "DISABLED" and not os.path.exists("dfs"):
  189. # Not all systems have recent enough CRDA version and
  190. # wireless-regdb changes to support 160 MHz and DFS. For now,
  191. # do not report failures for this test case.
  192. return "skip"
  193. raise Exception("Unexpected interface state: " + state)
  194. params = { "ssid": "vht2",
  195. "country_code": "FI",
  196. "hw_mode": "a",
  197. "channel": "100",
  198. "ht_capab": "[HT40+]",
  199. "ieee80211n": "1",
  200. "ieee80211ac": "1",
  201. "vht_oper_chwidth": "2",
  202. "vht_oper_centr_freq_seg0_idx": "114",
  203. 'ieee80211d': '1',
  204. 'ieee80211h': '1' }
  205. hapd2 = hostapd.add_ap(apdev[1]['ifname'], params, wait_enabled=False)
  206. ev = wait_dfs_event(hapd2, "DFS-CAC-START", 5)
  207. if "DFS-CAC-START" not in ev:
  208. raise Exception("Unexpected DFS event(2)")
  209. state = hapd2.get_status_field("state")
  210. if state != "DFS":
  211. raise Exception("Unexpected interface state(2): " + state)
  212. logger.info("Waiting for CAC to complete")
  213. ev = wait_dfs_event(hapd, "DFS-CAC-COMPLETED", 70)
  214. if "success=1" not in ev:
  215. raise Exception("CAC failed")
  216. if "freq=5180" not in ev:
  217. raise Exception("Unexpected DFS freq result")
  218. ev = hapd.wait_event(["AP-ENABLED"], timeout=5)
  219. if not ev:
  220. raise Exception("AP setup timed out")
  221. state = hapd.get_status_field("state")
  222. if state != "ENABLED":
  223. raise Exception("Unexpected interface state")
  224. ev = wait_dfs_event(hapd2, "DFS-CAC-COMPLETED", 70)
  225. if "success=1" not in ev:
  226. raise Exception("CAC failed(2)")
  227. if "freq=5500" not in ev:
  228. raise Exception("Unexpected DFS freq result(2)")
  229. ev = hapd2.wait_event(["AP-ENABLED"], timeout=5)
  230. if not ev:
  231. raise Exception("AP setup timed out(2)")
  232. state = hapd2.get_status_field("state")
  233. if state != "ENABLED":
  234. raise Exception("Unexpected interface state(2)")
  235. freq = hapd2.get_status_field("freq")
  236. if freq != "5500":
  237. raise Exception("Unexpected frequency(2)")
  238. dev[0].connect("vht", key_mgmt="NONE", scan_freq="5180")
  239. hwsim_utils.test_connectivity(dev[0], hapd)
  240. sig = dev[0].request("SIGNAL_POLL").splitlines()
  241. if "FREQUENCY=5180" not in sig:
  242. raise Exception("Unexpected SIGNAL_POLL value(1): " + str(sig))
  243. if "WIDTH=160 MHz" not in sig:
  244. raise Exception("Unexpected SIGNAL_POLL value(2): " + str(sig))
  245. dev[1].connect("vht2", key_mgmt="NONE", scan_freq="5500")
  246. hwsim_utils.test_connectivity(dev[1], hapd2)
  247. sig = dev[1].request("SIGNAL_POLL").splitlines()
  248. if "FREQUENCY=5500" not in sig:
  249. raise Exception("Unexpected SIGNAL_POLL value(1): " + str(sig))
  250. if "WIDTH=160 MHz" not in sig:
  251. raise Exception("Unexpected SIGNAL_POLL value(2): " + str(sig))
  252. except Exception, e:
  253. if isinstance(e, Exception) and str(e) == "AP startup failed":
  254. if not vht_supported():
  255. logger.info("80/160 MHz channel not supported in regulatory information")
  256. return "skip"
  257. raise
  258. finally:
  259. dev[0].request("DISCONNECT")
  260. dev[1].request("DISCONNECT")
  261. if hapd:
  262. hapd.request("DISABLE")
  263. if hapd2:
  264. hapd2.request("DISABLE")
  265. subprocess.call(['sudo', 'iw', 'reg', 'set', '00'])
  266. dev[0].flush_scan_cache()
  267. dev[1].flush_scan_cache()
  268. def test_ap_vht80plus80(dev, apdev):
  269. """VHT with 80+80 MHz channel width"""
  270. try:
  271. hapd = None
  272. hapd2 = None
  273. params = { "ssid": "vht",
  274. "country_code": "US",
  275. "hw_mode": "a",
  276. "channel": "52",
  277. "ht_capab": "[HT40+]",
  278. "ieee80211n": "1",
  279. "ieee80211ac": "1",
  280. "vht_oper_chwidth": "3",
  281. "vht_oper_centr_freq_seg0_idx": "58",
  282. "vht_oper_centr_freq_seg1_idx": "155",
  283. 'ieee80211d': '1',
  284. 'ieee80211h': '1' }
  285. hapd = hostapd.add_ap(apdev[0]['ifname'], params, wait_enabled=False)
  286. # This will actually fail since DFS on 80+80 is not yet supported
  287. ev = hapd.wait_event(["AP-DISABLED"], timeout=5)
  288. # ignore result to avoid breaking the test once 80+80 DFS gets enabled
  289. params = { "ssid": "vht2",
  290. "country_code": "US",
  291. "hw_mode": "a",
  292. "channel": "36",
  293. "ht_capab": "[HT40+]",
  294. "ieee80211n": "1",
  295. "ieee80211ac": "1",
  296. "vht_oper_chwidth": "3",
  297. "vht_oper_centr_freq_seg0_idx": "42",
  298. "vht_oper_centr_freq_seg1_idx": "155" }
  299. hapd2 = hostapd.add_ap(apdev[1]['ifname'], params, wait_enabled=False)
  300. ev = hapd2.wait_event(["AP-ENABLED"], timeout=5)
  301. if not ev:
  302. raise Exception("AP setup timed out(2)")
  303. state = hapd2.get_status_field("state")
  304. if state != "ENABLED":
  305. raise Exception("Unexpected interface state(2)")
  306. dev[1].connect("vht2", key_mgmt="NONE", scan_freq="5180")
  307. hwsim_utils.test_connectivity(dev[1], hapd2)
  308. sig = dev[1].request("SIGNAL_POLL").splitlines()
  309. if "FREQUENCY=5180" not in sig:
  310. raise Exception("Unexpected SIGNAL_POLL value(1): " + str(sig))
  311. if "WIDTH=80+80 MHz" not in sig:
  312. raise Exception("Unexpected SIGNAL_POLL value(2): " + str(sig))
  313. if "CENTER_FRQ1=5210" not in sig:
  314. raise Exception("Unexpected SIGNAL_POLL value(3): " + str(sig))
  315. if "CENTER_FRQ2=5775" not in sig:
  316. raise Exception("Unexpected SIGNAL_POLL value(4): " + str(sig))
  317. except Exception, e:
  318. if isinstance(e, Exception) and str(e) == "AP startup failed":
  319. if not vht_supported():
  320. logger.info("80/160 MHz channel not supported in regulatory information")
  321. return "skip"
  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(['sudo', '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. if not csa_supported(dev[0]):
  336. return "skip"
  337. try:
  338. hapd = None
  339. params = { "ssid": "vht",
  340. "country_code": "US",
  341. "hw_mode": "a",
  342. "channel": "149",
  343. "ht_capab": "[HT40+]",
  344. "ieee80211n": "1",
  345. "ieee80211ac": "1",
  346. "vht_oper_chwidth": "1",
  347. "vht_oper_centr_freq_seg0_idx": "155" }
  348. hapd = hostapd.add_ap(apdev[0]['ifname'], params)
  349. dev[0].connect("vht", key_mgmt="NONE", scan_freq="5745")
  350. hwsim_utils.test_connectivity(dev[0], hapd)
  351. hapd.request("CHAN_SWITCH 5 5180 ht vht blocktx center_freq1=5210 sec_channel_offset=1 bandwidth=80")
  352. ev = hapd.wait_event(["AP-CSA-FINISHED"], timeout=10)
  353. if ev is None:
  354. raise Exception("CSA finished event timed out")
  355. if "freq=5180" not in ev:
  356. raise Exception("Unexpected channel in CSA finished event")
  357. time.sleep(0.5)
  358. hwsim_utils.test_connectivity(dev[0], hapd)
  359. hapd.request("CHAN_SWITCH 5 5745")
  360. ev = hapd.wait_event(["AP-CSA-FINISHED"], timeout=10)
  361. if ev is None:
  362. raise Exception("CSA finished event timed out")
  363. if "freq=5745" not in ev:
  364. raise Exception("Unexpected channel in CSA finished event")
  365. time.sleep(0.5)
  366. hwsim_utils.test_connectivity(dev[0], hapd)
  367. # This CSA to same channel will fail in kernel, so use this only for
  368. # extra code coverage.
  369. hapd.request("CHAN_SWITCH 5 5745")
  370. hapd.wait_event(["AP-CSA-FINISHED"], timeout=1)
  371. except Exception, e:
  372. if isinstance(e, Exception) and str(e) == "AP startup failed":
  373. if not vht_supported():
  374. logger.info("80 MHz channel not supported in regulatory information")
  375. return "skip"
  376. raise
  377. finally:
  378. dev[0].request("DISCONNECT")
  379. if hapd:
  380. hapd.request("DISABLE")
  381. subprocess.call(['sudo', 'iw', 'reg', 'set', '00'])
  382. dev[0].flush_scan_cache()