test_ap_ht.py 50 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375
  1. # Test cases for HT operations with hostapd
  2. # Copyright (c) 2013-2014, Jouni Malinen <j@w1.fi>
  3. #
  4. # This software may be distributed under the terms of the BSD license.
  5. # See README for more details.
  6. from remotehost import remote_compatible
  7. import time
  8. import logging
  9. logger = logging.getLogger()
  10. import struct
  11. import hostapd
  12. from utils import HwsimSkip, alloc_fail, parse_ie
  13. import hwsim_utils
  14. from test_ap_csa import csa_supported
  15. def clear_scan_cache(apdev):
  16. ifname = apdev['ifname']
  17. hostapd.cmd_execute(apdev, ['ifconfig', ifname, 'up'])
  18. hostapd.cmd_execute(apdev, ['iw', ifname, 'scan', 'trigger', 'freq', '2412',
  19. 'flush'])
  20. time.sleep(0.1)
  21. hostapd.cmd_execute(apdev, ['ifconfig', ifname, 'down'])
  22. def set_world_reg(apdev0=None, apdev1=None, dev0=None):
  23. if apdev0:
  24. hostapd.cmd_execute(apdev0, ['iw', 'reg', 'set', '00'])
  25. if apdev1:
  26. hostapd.cmd_execute(apdev1, ['iw', 'reg', 'set', '00'])
  27. if dev0:
  28. dev0.cmd_execute(['iw', 'reg', 'set', '00'])
  29. def test_ap_ht40_scan(dev, apdev):
  30. """HT40 co-ex scan"""
  31. clear_scan_cache(apdev[0])
  32. params = { "ssid": "test-ht40",
  33. "channel": "5",
  34. "ht_capab": "[HT40-]"}
  35. hapd = hostapd.add_ap(apdev[0], params, wait_enabled=False)
  36. state = hapd.get_status_field("state")
  37. if state != "HT_SCAN":
  38. time.sleep(0.1)
  39. state = hapd.get_status_field("state")
  40. if state != "HT_SCAN":
  41. raise Exception("Unexpected interface state - expected HT_SCAN")
  42. ev = hapd.wait_event(["AP-ENABLED"], timeout=10)
  43. if not ev:
  44. raise Exception("AP setup timed out")
  45. state = hapd.get_status_field("state")
  46. if state != "ENABLED":
  47. raise Exception("Unexpected interface state - expected ENABLED")
  48. freq = hapd.get_status_field("freq")
  49. if freq != "2432":
  50. raise Exception("Unexpected frequency")
  51. pri = hapd.get_status_field("channel")
  52. if pri != "5":
  53. raise Exception("Unexpected primary channel")
  54. sec = hapd.get_status_field("secondary_channel")
  55. if sec != "-1":
  56. raise Exception("Unexpected secondary channel")
  57. status = hapd.get_status()
  58. logger.info("hostapd STATUS: " + str(status))
  59. dev[0].connect("test-ht40", key_mgmt="NONE", scan_freq=freq)
  60. sta = hapd.get_sta(dev[0].own_addr())
  61. logger.info("hostapd STA: " + str(sta))
  62. @remote_compatible
  63. def test_ap_ht40_scan_conflict(dev, apdev):
  64. """HT40 co-ex scan conflict"""
  65. clear_scan_cache(apdev[0])
  66. params = { "ssid": "test-ht40",
  67. "channel": "6",
  68. "ht_capab": "[HT40+]"}
  69. hostapd.add_ap(apdev[1], params)
  70. params = { "ssid": "test-ht40",
  71. "channel": "5",
  72. "ht_capab": "[HT40-]"}
  73. hapd = hostapd.add_ap(apdev[0], params, wait_enabled=False)
  74. state = hapd.get_status_field("state")
  75. if state != "HT_SCAN":
  76. time.sleep(0.1)
  77. state = hapd.get_status_field("state")
  78. if state != "HT_SCAN":
  79. raise Exception("Unexpected interface state - expected HT_SCAN")
  80. ev = hapd.wait_event(["AP-ENABLED"], timeout=10)
  81. if not ev:
  82. raise Exception("AP setup timed out")
  83. state = hapd.get_status_field("state")
  84. if state != "ENABLED":
  85. raise Exception("Unexpected interface state - expected ENABLED")
  86. freq = hapd.get_status_field("freq")
  87. if freq != "2432":
  88. raise Exception("Unexpected frequency")
  89. pri = hapd.get_status_field("channel")
  90. if pri != "5":
  91. raise Exception("Unexpected primary channel")
  92. sec = hapd.get_status_field("secondary_channel")
  93. if sec != "0":
  94. raise Exception("Unexpected secondary channel: " + sec)
  95. dev[0].connect("test-ht40", key_mgmt="NONE", scan_freq=freq)
  96. @remote_compatible
  97. def test_ap_ht40_scan_conflict2(dev, apdev):
  98. """HT40 co-ex scan conflict (HT40-)"""
  99. clear_scan_cache(apdev[0])
  100. params = { "ssid": "test-ht40",
  101. "channel": "11",
  102. "ht_capab": "[HT40-]"}
  103. hostapd.add_ap(apdev[1], params)
  104. params = { "ssid": "test-ht40",
  105. "channel": "1",
  106. "ht_capab": "[HT40+]"}
  107. hapd = hostapd.add_ap(apdev[0], params, wait_enabled=False)
  108. state = hapd.get_status_field("state")
  109. if state != "HT_SCAN":
  110. time.sleep(0.1)
  111. state = hapd.get_status_field("state")
  112. if state != "HT_SCAN":
  113. raise Exception("Unexpected interface state - expected HT_SCAN")
  114. ev = hapd.wait_event(["AP-ENABLED"], timeout=10)
  115. if not ev:
  116. raise Exception("AP setup timed out")
  117. state = hapd.get_status_field("state")
  118. if state != "ENABLED":
  119. raise Exception("Unexpected interface state - expected ENABLED")
  120. freq = hapd.get_status_field("freq")
  121. if freq != "2412":
  122. raise Exception("Unexpected frequency")
  123. pri = hapd.get_status_field("channel")
  124. if pri != "1":
  125. raise Exception("Unexpected primary channel")
  126. sec = hapd.get_status_field("secondary_channel")
  127. if sec != "0":
  128. raise Exception("Unexpected secondary channel: " + sec)
  129. dev[0].connect("test-ht40", key_mgmt="NONE", scan_freq=freq)
  130. def test_ap_ht40_scan_not_affected(dev, apdev):
  131. """HT40 co-ex scan and other BSS not affected"""
  132. clear_scan_cache(apdev[0])
  133. params = { "ssid": "test-ht20",
  134. "channel": "11" }
  135. hostapd.add_ap(apdev[1], params)
  136. hostapd.cmd_execute(apdev[0], ['ifconfig', apdev[0]['ifname'], 'up'])
  137. hostapd.cmd_execute(apdev[0], ['iw', apdev[0]['ifname'], 'scan', 'trigger',
  138. 'freq', '2462'])
  139. time.sleep(0.5)
  140. hostapd.cmd_execute(apdev[0], ['iw', apdev[0]['ifname'], 'scan', 'dump'])
  141. time.sleep(0.1)
  142. hostapd.cmd_execute(apdev[0], ['ifconfig', apdev[0]['ifname'], 'down'])
  143. params = { "ssid": "test-ht40",
  144. "channel": "1",
  145. "ht_capab": "[HT40+]"}
  146. hapd = hostapd.add_ap(apdev[0], params, wait_enabled=False)
  147. state = hapd.get_status_field("state")
  148. if state != "HT_SCAN":
  149. time.sleep(0.1)
  150. state = hapd.get_status_field("state")
  151. if state != "HT_SCAN":
  152. raise Exception("Unexpected interface state - expected HT_SCAN")
  153. ev = hapd.wait_event(["AP-ENABLED"], timeout=10)
  154. if not ev:
  155. raise Exception("AP setup timed out")
  156. state = hapd.get_status_field("state")
  157. if state != "ENABLED":
  158. raise Exception("Unexpected interface state - expected ENABLED")
  159. freq = hapd.get_status_field("freq")
  160. if freq != "2412":
  161. raise Exception("Unexpected frequency")
  162. pri = hapd.get_status_field("channel")
  163. if pri != "1":
  164. raise Exception("Unexpected primary channel")
  165. sec = hapd.get_status_field("secondary_channel")
  166. if sec != "1":
  167. raise Exception("Unexpected secondary channel: " + sec)
  168. dev[0].connect("test-ht40", key_mgmt="NONE", scan_freq=freq)
  169. @remote_compatible
  170. def test_ap_ht40_scan_legacy_conflict(dev, apdev):
  171. """HT40 co-ex scan conflict with legacy 20 MHz AP"""
  172. clear_scan_cache(apdev[0])
  173. params = { "ssid": "legacy-20",
  174. "channel": "7", "ieee80211n": "0" }
  175. hostapd.add_ap(apdev[1], params)
  176. params = { "ssid": "test-ht40",
  177. "channel": "5",
  178. "ht_capab": "[HT40-]"}
  179. hapd = hostapd.add_ap(apdev[0], params, wait_enabled=False)
  180. state = hapd.get_status_field("state")
  181. if state != "HT_SCAN":
  182. time.sleep(0.1)
  183. state = hapd.get_status_field("state")
  184. if state != "HT_SCAN":
  185. raise Exception("Unexpected interface state - expected HT_SCAN")
  186. ev = hapd.wait_event(["AP-ENABLED"], timeout=10)
  187. if not ev:
  188. raise Exception("AP setup timed out")
  189. state = hapd.get_status_field("state")
  190. if state != "ENABLED":
  191. raise Exception("Unexpected interface state - expected ENABLED")
  192. freq = hapd.get_status_field("freq")
  193. if freq != "2432":
  194. raise Exception("Unexpected frequency: " + freq)
  195. pri = hapd.get_status_field("channel")
  196. if pri != "5":
  197. raise Exception("Unexpected primary channel: " + pri)
  198. sec = hapd.get_status_field("secondary_channel")
  199. if sec != "0":
  200. raise Exception("Unexpected secondary channel: " + sec)
  201. dev[0].connect("test-ht40", key_mgmt="NONE", scan_freq=freq)
  202. @remote_compatible
  203. def test_ap_ht40_scan_ht20_conflict(dev, apdev):
  204. """HT40 co-ex scan conflict with HT 20 MHz AP"""
  205. clear_scan_cache(apdev[0])
  206. params = { "ssid": "ht-20",
  207. "channel": "7", "ieee80211n": "1" }
  208. hostapd.add_ap(apdev[1], params)
  209. params = { "ssid": "test-ht40",
  210. "channel": "5",
  211. "ht_capab": "[HT40-]"}
  212. hapd = hostapd.add_ap(apdev[0], params, wait_enabled=False)
  213. state = hapd.get_status_field("state")
  214. if state != "HT_SCAN":
  215. time.sleep(0.1)
  216. state = hapd.get_status_field("state")
  217. if state != "HT_SCAN":
  218. raise Exception("Unexpected interface state - expected HT_SCAN")
  219. ev = hapd.wait_event(["AP-ENABLED"], timeout=10)
  220. if not ev:
  221. raise Exception("AP setup timed out")
  222. state = hapd.get_status_field("state")
  223. if state != "ENABLED":
  224. raise Exception("Unexpected interface state - expected ENABLED")
  225. freq = hapd.get_status_field("freq")
  226. if freq != "2432":
  227. raise Exception("Unexpected frequency: " + freq)
  228. pri = hapd.get_status_field("channel")
  229. if pri != "5":
  230. raise Exception("Unexpected primary channel: " + pri)
  231. sec = hapd.get_status_field("secondary_channel")
  232. if sec != "0":
  233. raise Exception("Unexpected secondary channel: " + sec)
  234. dev[0].connect("test-ht40", key_mgmt="NONE", scan_freq=freq)
  235. def test_ap_ht40_scan_intolerant(dev, apdev):
  236. """HT40 co-ex scan finding an AP advertising 40 MHz intolerant"""
  237. clear_scan_cache(apdev[0])
  238. params = { "ssid": "another-bss",
  239. "channel": "1",
  240. "ht_capab": "[40-INTOLERANT]" }
  241. hostapd.add_ap(apdev[1], params)
  242. params = { "ssid": "test-ht40",
  243. "channel": "1",
  244. "ht_capab": "[HT40+]"}
  245. hapd = hostapd.add_ap(apdev[0], params, wait_enabled=False)
  246. state = hapd.get_status_field("state")
  247. if state != "HT_SCAN":
  248. time.sleep(0.1)
  249. state = hapd.get_status_field("state")
  250. if state != "HT_SCAN":
  251. raise Exception("Unexpected interface state - expected HT_SCAN")
  252. ev = hapd.wait_event(["AP-ENABLED"], timeout=10)
  253. if not ev:
  254. raise Exception("AP setup timed out")
  255. state = hapd.get_status_field("state")
  256. if state != "ENABLED":
  257. raise Exception("Unexpected interface state - expected ENABLED")
  258. freq = hapd.get_status_field("freq")
  259. if freq != "2412":
  260. raise Exception("Unexpected frequency: " + freq)
  261. pri = hapd.get_status_field("channel")
  262. if pri != "1":
  263. raise Exception("Unexpected primary channel: " + pri)
  264. sec = hapd.get_status_field("secondary_channel")
  265. if sec != "0":
  266. raise Exception("Unexpected secondary channel: " + sec)
  267. dev[0].connect("test-ht40", key_mgmt="NONE", scan_freq=freq)
  268. def test_ap_ht40_scan_match(dev, apdev):
  269. """HT40 co-ex scan matching configuration"""
  270. clear_scan_cache(apdev[0])
  271. params = { "ssid": "test-ht40",
  272. "channel": "5",
  273. "ht_capab": "[HT40-]"}
  274. hostapd.add_ap(apdev[1], params)
  275. params = { "ssid": "test-ht40",
  276. "channel": "5",
  277. "ht_capab": "[HT40-]"}
  278. hapd = hostapd.add_ap(apdev[0], params, wait_enabled=False)
  279. state = hapd.get_status_field("state")
  280. if state != "HT_SCAN":
  281. time.sleep(0.1)
  282. state = hapd.get_status_field("state")
  283. if state != "HT_SCAN":
  284. raise Exception("Unexpected interface state - expected HT_SCAN")
  285. ev = hapd.wait_event(["AP-ENABLED"], timeout=10)
  286. if not ev:
  287. raise Exception("AP setup timed out")
  288. state = hapd.get_status_field("state")
  289. if state != "ENABLED":
  290. raise Exception("Unexpected interface state - expected ENABLED")
  291. freq = hapd.get_status_field("freq")
  292. if freq != "2432":
  293. raise Exception("Unexpected frequency")
  294. pri = hapd.get_status_field("channel")
  295. if pri != "5":
  296. raise Exception("Unexpected primary channel")
  297. sec = hapd.get_status_field("secondary_channel")
  298. if sec != "-1":
  299. raise Exception("Unexpected secondary channel: " + sec)
  300. dev[0].connect("test-ht40", key_mgmt="NONE", scan_freq=freq)
  301. def test_ap_ht40_5ghz_match(dev, apdev):
  302. """HT40 co-ex scan on 5 GHz with matching pri/sec channel"""
  303. clear_scan_cache(apdev[0])
  304. try:
  305. hapd = None
  306. hapd2 = None
  307. params = { "ssid": "test-ht40",
  308. "hw_mode": "a",
  309. "channel": "36",
  310. "country_code": "US",
  311. "ht_capab": "[HT40+]"}
  312. hapd2 = hostapd.add_ap(apdev[1], params)
  313. params = { "ssid": "test-ht40",
  314. "hw_mode": "a",
  315. "channel": "36",
  316. "ht_capab": "[HT40+]"}
  317. hapd = hostapd.add_ap(apdev[0], params, wait_enabled=False)
  318. state = hapd.get_status_field("state")
  319. if state != "HT_SCAN":
  320. time.sleep(0.1)
  321. state = hapd.get_status_field("state")
  322. if state != "HT_SCAN":
  323. raise Exception("Unexpected interface state - expected HT_SCAN")
  324. ev = hapd.wait_event(["AP-ENABLED"], timeout=10)
  325. if not ev:
  326. raise Exception("AP setup timed out")
  327. state = hapd.get_status_field("state")
  328. if state != "ENABLED":
  329. raise Exception("Unexpected interface state - expected ENABLED")
  330. freq = hapd.get_status_field("freq")
  331. if freq != "5180":
  332. raise Exception("Unexpected frequency")
  333. pri = hapd.get_status_field("channel")
  334. if pri != "36":
  335. raise Exception("Unexpected primary channel")
  336. sec = hapd.get_status_field("secondary_channel")
  337. if sec != "1":
  338. raise Exception("Unexpected secondary channel: " + sec)
  339. dev[0].connect("test-ht40", key_mgmt="NONE", scan_freq=freq)
  340. finally:
  341. dev[0].request("DISCONNECT")
  342. if hapd:
  343. hapd.request("DISABLE")
  344. if hapd2:
  345. hapd2.request("DISABLE")
  346. set_world_reg(apdev[0], apdev[1], dev[0])
  347. dev[0].flush_scan_cache()
  348. def test_ap_ht40_5ghz_switch(dev, apdev):
  349. """HT40 co-ex scan on 5 GHz switching pri/sec channel"""
  350. clear_scan_cache(apdev[0])
  351. try:
  352. hapd = None
  353. hapd2 = None
  354. params = { "ssid": "test-ht40",
  355. "hw_mode": "a",
  356. "channel": "36",
  357. "country_code": "US",
  358. "ht_capab": "[HT40+]"}
  359. hapd2 = hostapd.add_ap(apdev[1], params)
  360. params = { "ssid": "test-ht40",
  361. "hw_mode": "a",
  362. "channel": "40",
  363. "ht_capab": "[HT40-]"}
  364. hapd = hostapd.add_ap(apdev[0], params, wait_enabled=False)
  365. state = hapd.get_status_field("state")
  366. if state != "HT_SCAN":
  367. time.sleep(0.1)
  368. state = hapd.get_status_field("state")
  369. if state != "HT_SCAN":
  370. raise Exception("Unexpected interface state - expected HT_SCAN")
  371. ev = hapd.wait_event(["AP-ENABLED"], timeout=10)
  372. if not ev:
  373. raise Exception("AP setup timed out")
  374. state = hapd.get_status_field("state")
  375. if state != "ENABLED":
  376. raise Exception("Unexpected interface state - expected ENABLED")
  377. freq = hapd.get_status_field("freq")
  378. if freq != "5180":
  379. raise Exception("Unexpected frequency: " + freq)
  380. pri = hapd.get_status_field("channel")
  381. if pri != "36":
  382. raise Exception("Unexpected primary channel: " + pri)
  383. sec = hapd.get_status_field("secondary_channel")
  384. if sec != "1":
  385. raise Exception("Unexpected secondary channel: " + sec)
  386. dev[0].connect("test-ht40", key_mgmt="NONE", scan_freq=freq)
  387. finally:
  388. dev[0].request("DISCONNECT")
  389. if hapd:
  390. hapd.request("DISABLE")
  391. if hapd2:
  392. hapd2.request("DISABLE")
  393. set_world_reg(apdev[0], apdev[1], dev[0])
  394. def test_ap_ht40_5ghz_switch2(dev, apdev):
  395. """HT40 co-ex scan on 5 GHz switching pri/sec channel (2)"""
  396. clear_scan_cache(apdev[0])
  397. try:
  398. hapd = None
  399. hapd2 = None
  400. params = { "ssid": "test-ht40",
  401. "hw_mode": "a",
  402. "channel": "36",
  403. "country_code": "US",
  404. "ht_capab": "[HT40+]"}
  405. hapd2 = hostapd.add_ap(apdev[1], params)
  406. id = dev[0].add_network()
  407. dev[0].set_network(id, "mode", "2")
  408. dev[0].set_network_quoted(id, "ssid", "wpas-ap-open")
  409. dev[0].set_network(id, "key_mgmt", "NONE")
  410. dev[0].set_network(id, "frequency", "5200")
  411. dev[0].set_network(id, "scan_freq", "5200")
  412. dev[0].select_network(id)
  413. time.sleep(1)
  414. params = { "ssid": "test-ht40",
  415. "hw_mode": "a",
  416. "channel": "40",
  417. "ht_capab": "[HT40-]"}
  418. hapd = hostapd.add_ap(apdev[0], params, wait_enabled=False)
  419. state = hapd.get_status_field("state")
  420. if state != "HT_SCAN":
  421. time.sleep(0.1)
  422. state = hapd.get_status_field("state")
  423. if state != "HT_SCAN":
  424. raise Exception("Unexpected interface state - expected HT_SCAN")
  425. ev = hapd.wait_event(["AP-ENABLED"], timeout=10)
  426. if not ev:
  427. raise Exception("AP setup timed out")
  428. state = hapd.get_status_field("state")
  429. if state != "ENABLED":
  430. raise Exception("Unexpected interface state - expected ENABLED")
  431. freq = hapd.get_status_field("freq")
  432. if freq != "5180":
  433. raise Exception("Unexpected frequency: " + freq)
  434. pri = hapd.get_status_field("channel")
  435. if pri != "36":
  436. raise Exception("Unexpected primary channel: " + pri)
  437. sec = hapd.get_status_field("secondary_channel")
  438. if sec != "1":
  439. raise Exception("Unexpected secondary channel: " + sec)
  440. dev[0].connect("test-ht40", key_mgmt="NONE", scan_freq=freq)
  441. finally:
  442. dev[0].request("DISCONNECT")
  443. if hapd:
  444. hapd.request("DISABLE")
  445. if hapd2:
  446. hapd2.request("DISABLE")
  447. set_world_reg(apdev[0], apdev[1], dev[0])
  448. dev[0].flush_scan_cache()
  449. def test_obss_scan(dev, apdev):
  450. """Overlapping BSS scan request"""
  451. params = { "ssid": "obss-scan",
  452. "channel": "6",
  453. "ht_capab": "[HT40-]",
  454. "obss_interval": "10" }
  455. hapd = hostapd.add_ap(apdev[0], params)
  456. params = { "ssid": "another-bss",
  457. "channel": "9",
  458. "ieee80211n": "0" }
  459. hostapd.add_ap(apdev[1], params)
  460. run_obss_scan(hapd, dev)
  461. def test_obss_scan_ht40_plus(dev, apdev):
  462. """Overlapping BSS scan request (HT40+)"""
  463. params = { "ssid": "obss-scan",
  464. "channel": "6",
  465. "ht_capab": "[HT40+]",
  466. "obss_interval": "10" }
  467. hapd = hostapd.add_ap(apdev[0], params)
  468. params = { "ssid": "another-bss",
  469. "channel": "9",
  470. "ieee80211n": "0" }
  471. hostapd.add_ap(apdev[1], params)
  472. run_obss_scan(hapd, dev)
  473. def run_obss_scan(hapd, dev):
  474. dev[0].connect("obss-scan", key_mgmt="NONE", scan_freq="2437")
  475. hapd.set("ext_mgmt_frame_handling", "1")
  476. logger.info("Waiting for OBSS scan to occur")
  477. ev = dev[0].wait_event(["CTRL-EVENT-SCAN-STARTED"], timeout=15)
  478. if ev is None:
  479. raise Exception("Timed out while waiting for OBSS scan to start")
  480. ev = dev[0].wait_event(["CTRL-EVENT-SCAN-RESULTS"], timeout=10)
  481. if ev is None:
  482. raise Exception("Timed out while waiting for OBSS scan results")
  483. received = False
  484. for i in range(0, 4):
  485. frame = hapd.mgmt_rx(timeout=5)
  486. if frame is None:
  487. raise Exception("MGMT RX wait timed out")
  488. if frame['subtype'] != 13:
  489. continue
  490. payload = frame['payload']
  491. if len(payload) < 3:
  492. continue
  493. (category, action, ie) = struct.unpack('BBB', payload[0:3])
  494. if category != 4:
  495. continue
  496. if action != 0:
  497. continue
  498. if ie == 72:
  499. logger.info("20/40 BSS Coexistence report received")
  500. received = True
  501. break
  502. if not received:
  503. raise Exception("20/40 BSS Coexistence report not seen")
  504. def test_obss_scan_40_intolerant(dev, apdev):
  505. """Overlapping BSS scan request with 40 MHz intolerant AP"""
  506. params = { "ssid": "obss-scan",
  507. "channel": "6",
  508. "ht_capab": "[HT40-]",
  509. "obss_interval": "10" }
  510. hapd = hostapd.add_ap(apdev[0], params)
  511. params = { "ssid": "another-bss",
  512. "channel": "7",
  513. "ht_capab": "[40-INTOLERANT]" }
  514. hostapd.add_ap(apdev[1], params)
  515. dev[0].connect("obss-scan", key_mgmt="NONE", scan_freq="2437")
  516. hapd.set("ext_mgmt_frame_handling", "1")
  517. logger.info("Waiting for OBSS scan to occur")
  518. ev = dev[0].wait_event(["CTRL-EVENT-SCAN-STARTED"], timeout=15)
  519. if ev is None:
  520. raise Exception("Timed out while waiting for OBSS scan to start")
  521. ev = dev[0].wait_event(["CTRL-EVENT-SCAN-RESULTS"], timeout=10)
  522. if ev is None:
  523. raise Exception("Timed out while waiting for OBSS scan results")
  524. received = False
  525. for i in range(0, 4):
  526. frame = hapd.mgmt_rx(timeout=5)
  527. if frame is None:
  528. raise Exception("MGMT RX wait timed out")
  529. if frame['subtype'] != 13:
  530. continue
  531. payload = frame['payload']
  532. if len(payload) < 3:
  533. continue
  534. (category, action, ie) = struct.unpack('BBB', payload[0:3])
  535. if category != 4:
  536. continue
  537. if action != 0:
  538. continue
  539. if ie == 72:
  540. logger.info("20/40 BSS Coexistence report received")
  541. received = True
  542. break
  543. if not received:
  544. raise Exception("20/40 BSS Coexistence report not seen")
  545. def test_obss_coex_report_handling(dev, apdev):
  546. """Overlapping BSS scan report handling with obss_interval=0"""
  547. clear_scan_cache(apdev[0])
  548. params = { "ssid": "obss-scan",
  549. "channel": "6",
  550. "ht_capab": "[HT40-]" }
  551. hapd = hostapd.add_ap(apdev[0], params)
  552. bssid = apdev[0]['bssid']
  553. dev[0].connect("obss-scan", key_mgmt="NONE", scan_freq="2437")
  554. sec = hapd.get_status_field("secondary_channel")
  555. if sec != "-1":
  556. raise Exception("AP is not using 40 MHz channel")
  557. # 20/40 MHz co-ex report tests: number of invalid reports and a valid report
  558. # that forces 20 MHz channel.
  559. tests = [ '0400', '040048', '04004801', '0400480000', '0400490100',
  560. '040048ff0000', '04004801ff49ff00', '04004801004900',
  561. '0400480100490101', '0400480100490201ff',
  562. '040048010449020005' ]
  563. for msg in tests:
  564. req = "MGMT_TX {} {} freq=2437 action={}".format(bssid, bssid, msg)
  565. if "OK" not in dev[0].request(req):
  566. raise Exception("Could not send management frame")
  567. time.sleep(0.5)
  568. sec = hapd.get_status_field("secondary_channel")
  569. if sec != "0":
  570. raise Exception("AP did not move to 20 MHz channel")
  571. def test_obss_coex_report_handling1(dev, apdev):
  572. """Overlapping BSS scan report handling with obss_interval=1"""
  573. clear_scan_cache(apdev[0])
  574. params = { "ssid": "obss-scan",
  575. "channel": "6",
  576. "ht_capab": "[HT40+]",
  577. "obss_interval": "1" }
  578. hapd = hostapd.add_ap(apdev[0], params)
  579. bssid = apdev[0]['bssid']
  580. dev[0].connect("obss-scan", key_mgmt="NONE", scan_freq="2437")
  581. sec = hapd.get_status_field("secondary_channel")
  582. if sec != "1":
  583. raise Exception("AP is not using 40 MHz channel")
  584. # 20/40 MHz co-ex report forcing 20 MHz channel
  585. msg = '040048010449020005'
  586. req = "MGMT_TX {} {} freq=2437 action={}".format(bssid, bssid, msg)
  587. if "OK" not in dev[0].request(req):
  588. raise Exception("Could not send management frame")
  589. time.sleep(0.5)
  590. sec = hapd.get_status_field("secondary_channel")
  591. if sec != "0":
  592. raise Exception("AP did not move to 20 MHz channel")
  593. # No 20/40 MHz co-ex reports forcing 20 MHz channel during next interval
  594. for i in range(20):
  595. sec = hapd.get_status_field("secondary_channel")
  596. if sec == "1":
  597. break
  598. time.sleep(0.5)
  599. if sec != "1":
  600. raise Exception("AP did not return to 40 MHz channel")
  601. def test_olbc(dev, apdev):
  602. """OLBC detection"""
  603. params = { "ssid": "test-olbc",
  604. "channel": "6",
  605. "ht_capab": "[HT40-]",
  606. "ap_table_expiration_time": "2" }
  607. hapd = hostapd.add_ap(apdev[0], params)
  608. status = hapd.get_status()
  609. if status['olbc'] != '0' or status['olbc_ht'] != '0':
  610. raise Exception("Unexpected OLBC information")
  611. params = { "ssid": "olbc-ap",
  612. "hw_mode": "b",
  613. "channel": "6",
  614. "wmm_enabled": "0" }
  615. hostapd.add_ap(apdev[1], params)
  616. time.sleep(0.5)
  617. status = hapd.get_status()
  618. if status['olbc'] != '1' or status['olbc_ht'] != '1':
  619. raise Exception("Missing OLBC information")
  620. hostapd.remove_bss(apdev[1])
  621. logger.info("Waiting for OLBC state to time out")
  622. cleared = False
  623. for i in range(0, 15):
  624. time.sleep(1)
  625. status = hapd.get_status()
  626. if status['olbc'] == '0' and status['olbc_ht'] == '0':
  627. cleared = True
  628. break
  629. if not cleared:
  630. raise Exception("OLBC state did nto time out")
  631. def test_olbc_table_limit(dev, apdev):
  632. """OLBC AP table size limit"""
  633. ifname1 = apdev[0]['ifname']
  634. ifname2 = apdev[0]['ifname'] + '-2'
  635. ifname3 = apdev[0]['ifname'] + '-3'
  636. hostapd.add_bss(apdev[0], ifname1, 'bss-1.conf')
  637. hostapd.add_bss(apdev[0], ifname2, 'bss-2.conf')
  638. hostapd.add_bss(apdev[0], ifname3, 'bss-3.conf')
  639. params = { "ssid": "test-olbc",
  640. "channel": "1",
  641. "ap_table_max_size": "2" }
  642. hapd = hostapd.add_ap(apdev[1], params)
  643. time.sleep(0.3)
  644. with alloc_fail(hapd, 1, "ap_list_process_beacon"):
  645. time.sleep(0.3)
  646. hapd.set("ap_table_max_size", "1")
  647. time.sleep(0.3)
  648. hapd.set("ap_table_max_size", "0")
  649. time.sleep(0.3)
  650. def test_olbc_5ghz(dev, apdev):
  651. """OLBC detection on 5 GHz"""
  652. try:
  653. hapd = None
  654. hapd2 = None
  655. params = { "ssid": "test-olbc",
  656. "country_code": "FI",
  657. "hw_mode": "a",
  658. "channel": "36",
  659. "ht_capab": "[HT40+]" }
  660. hapd = hostapd.add_ap(apdev[0], params)
  661. status = hapd.get_status()
  662. if status['olbc'] != '0' or status['olbc_ht'] != '0':
  663. raise Exception("Unexpected OLBC information")
  664. params = { "ssid": "olbc-ap",
  665. "country_code": "FI",
  666. "hw_mode": "a",
  667. "channel": "36",
  668. "ieee80211n": "0",
  669. "wmm_enabled": "0" }
  670. hapd2 = hostapd.add_ap(apdev[1], params)
  671. found = False
  672. for i in range(20):
  673. time.sleep(0.1)
  674. status = hapd.get_status()
  675. logger.debug('olbc_ht: ' + status['olbc_ht'])
  676. if status['olbc_ht'] == '1':
  677. found = True
  678. break
  679. if not found:
  680. raise Exception("Missing OLBC information")
  681. finally:
  682. if hapd:
  683. hapd.request("DISABLE")
  684. if hapd2:
  685. hapd2.request("DISABLE")
  686. set_world_reg(apdev[0], apdev[1], None)
  687. def test_ap_require_ht(dev, apdev):
  688. """Require HT"""
  689. params = { "ssid": "require-ht",
  690. "require_ht": "1" }
  691. hapd = hostapd.add_ap(apdev[0], params, wait_enabled=False)
  692. dev[1].connect("require-ht", key_mgmt="NONE", scan_freq="2412",
  693. disable_ht="1", wait_connect=False)
  694. dev[0].connect("require-ht", key_mgmt="NONE", scan_freq="2412")
  695. ev = dev[1].wait_event(["CTRL-EVENT-ASSOC-REJECT"])
  696. dev[1].request("DISCONNECT")
  697. if ev is None:
  698. raise Exception("Association rejection timed out")
  699. if "status_code=27" not in ev:
  700. raise Exception("Unexpected rejection status code")
  701. dev[2].connect("require-ht", key_mgmt="NONE", scan_freq="2412",
  702. ht_mcs="0x01 00 00 00 00 00 00 00 00 00",
  703. disable_max_amsdu="1", ampdu_factor="2",
  704. ampdu_density="1", disable_ht40="1", disable_sgi="1",
  705. disable_ldpc="1")
  706. @remote_compatible
  707. def test_ap_require_ht_limited_rates(dev, apdev):
  708. """Require HT with limited supported rates"""
  709. params = { "ssid": "require-ht",
  710. "supported_rates": "60 120 240 360 480 540",
  711. "require_ht": "1" }
  712. hapd = hostapd.add_ap(apdev[0], params, wait_enabled=False)
  713. dev[1].connect("require-ht", key_mgmt="NONE", scan_freq="2412",
  714. disable_ht="1", wait_connect=False)
  715. dev[0].connect("require-ht", key_mgmt="NONE", scan_freq="2412")
  716. ev = dev[1].wait_event(["CTRL-EVENT-ASSOC-REJECT"])
  717. dev[1].request("DISCONNECT")
  718. if ev is None:
  719. raise Exception("Association rejection timed out")
  720. if "status_code=27" not in ev:
  721. raise Exception("Unexpected rejection status code")
  722. @remote_compatible
  723. def test_ap_ht_capab_not_supported(dev, apdev):
  724. """HT configuration with driver not supporting all ht_capab entries"""
  725. params = { "ssid": "test-ht40",
  726. "channel": "5",
  727. "ht_capab": "[HT40-][LDPC][SMPS-STATIC][SMPS-DYNAMIC][GF][SHORT-GI-20][SHORT-GI-40][TX-STBC][RX-STBC1][RX-STBC12][RX-STBC123][DELAYED-BA][MAX-AMSDU-7935][DSSS_CCK-40][LSIG-TXOP-PROT]"}
  728. hapd = hostapd.add_ap(apdev[0], params, no_enable=True)
  729. if "FAIL" not in hapd.request("ENABLE"):
  730. raise Exception("Unexpected ENABLE success")
  731. def test_ap_ht_40mhz_intolerant_sta(dev, apdev):
  732. """Associated STA indicating 40 MHz intolerant"""
  733. clear_scan_cache(apdev[0])
  734. params = { "ssid": "intolerant",
  735. "channel": "6",
  736. "ht_capab": "[HT40-]" }
  737. hapd = hostapd.add_ap(apdev[0], params)
  738. if hapd.get_status_field("num_sta_ht40_intolerant") != "0":
  739. raise Exception("Unexpected num_sta_ht40_intolerant value")
  740. if hapd.get_status_field("secondary_channel") != "-1":
  741. raise Exception("Unexpected secondary_channel")
  742. dev[0].connect("intolerant", key_mgmt="NONE", scan_freq="2437")
  743. if hapd.get_status_field("num_sta_ht40_intolerant") != "0":
  744. raise Exception("Unexpected num_sta_ht40_intolerant value")
  745. if hapd.get_status_field("secondary_channel") != "-1":
  746. raise Exception("Unexpected secondary_channel")
  747. dev[2].connect("intolerant", key_mgmt="NONE", scan_freq="2437",
  748. ht40_intolerant="1")
  749. time.sleep(1)
  750. if hapd.get_status_field("num_sta_ht40_intolerant") != "1":
  751. raise Exception("Unexpected num_sta_ht40_intolerant value (expected 1)")
  752. if hapd.get_status_field("secondary_channel") != "0":
  753. raise Exception("Unexpected secondary_channel (did not disable 40 MHz)")
  754. dev[2].request("DISCONNECT")
  755. time.sleep(1)
  756. if hapd.get_status_field("num_sta_ht40_intolerant") != "0":
  757. raise Exception("Unexpected num_sta_ht40_intolerant value (expected 0)")
  758. if hapd.get_status_field("secondary_channel") != "-1":
  759. raise Exception("Unexpected secondary_channel (did not re-enable 40 MHz)")
  760. def test_ap_ht_40mhz_intolerant_ap(dev, apdev):
  761. """Associated STA reports 40 MHz intolerant AP after association"""
  762. clear_scan_cache(apdev[0])
  763. params = { "ssid": "ht",
  764. "channel": "6",
  765. "ht_capab": "[HT40-]",
  766. "obss_interval": "3" }
  767. hapd = hostapd.add_ap(apdev[0], params)
  768. dev[0].connect("ht", key_mgmt="NONE", scan_freq="2437")
  769. if hapd.get_status_field("secondary_channel") != "-1":
  770. raise Exception("Unexpected secondary channel information")
  771. logger.info("Start 40 MHz intolerant AP")
  772. params = { "ssid": "intolerant",
  773. "channel": "5",
  774. "ht_capab": "[40-INTOLERANT]" }
  775. hapd2 = hostapd.add_ap(apdev[1], params)
  776. logger.info("Waiting for co-ex report from STA")
  777. ok = False
  778. for i in range(0, 20):
  779. time.sleep(1)
  780. if hapd.get_status_field("secondary_channel") == "0":
  781. logger.info("AP moved to 20 MHz channel")
  782. ok = True
  783. break
  784. if not ok:
  785. raise Exception("AP did not move to 20 MHz channel")
  786. if "OK" not in hapd2.request("DISABLE"):
  787. raise Exception("Failed to disable 40 MHz intolerant AP")
  788. # make sure the intolerant AP disappears from scan results more quickly
  789. dev[0].scan(type="ONLY", freq="2432", only_new=True)
  790. dev[0].scan(type="ONLY", freq="2432", only_new=True)
  791. dev[0].dump_monitor()
  792. logger.info("Waiting for AP to move back to 40 MHz channel")
  793. ok = False
  794. for i in range(0, 30):
  795. time.sleep(1)
  796. if hapd.get_status_field("secondary_channel") == "-1":
  797. logger.info("AP moved to 40 MHz channel")
  798. ok = True
  799. break
  800. if not ok:
  801. raise Exception("AP did not move to 40 MHz channel")
  802. def test_ap_ht40_csa(dev, apdev):
  803. """HT with 40 MHz channel width and CSA"""
  804. csa_supported(dev[0])
  805. try:
  806. hapd = None
  807. params = { "ssid": "ht",
  808. "country_code": "US",
  809. "hw_mode": "a",
  810. "channel": "36",
  811. "ht_capab": "[HT40+]",
  812. "ieee80211n": "1" }
  813. hapd = hostapd.add_ap(apdev[0], params)
  814. dev[0].connect("ht", key_mgmt="NONE", scan_freq="5180")
  815. hwsim_utils.test_connectivity(dev[0], hapd)
  816. hapd.request("CHAN_SWITCH 5 5200 ht sec_channel_offset=-1 bandwidth=40")
  817. ev = hapd.wait_event(["AP-CSA-FINISHED"], timeout=10)
  818. if ev is None:
  819. raise Exception("CSA finished event timed out")
  820. if "freq=5200" not in ev:
  821. raise Exception("Unexpected channel in CSA finished event")
  822. ev = dev[0].wait_event(["CTRL-EVENT-DISCONNECTED"], timeout=0.5)
  823. if ev is not None:
  824. raise Exception("Unexpected STA disconnection during CSA")
  825. hwsim_utils.test_connectivity(dev[0], hapd)
  826. hapd.request("CHAN_SWITCH 5 5180 ht sec_channel_offset=1 bandwidth=40")
  827. ev = hapd.wait_event(["AP-CSA-FINISHED"], timeout=10)
  828. if ev is None:
  829. raise Exception("CSA finished event timed out")
  830. if "freq=5180" not in ev:
  831. raise Exception("Unexpected channel in CSA finished event")
  832. ev = dev[0].wait_event(["CTRL-EVENT-DISCONNECTED"], timeout=0.5)
  833. if ev is not None:
  834. raise Exception("Unexpected STA disconnection during CSA")
  835. hwsim_utils.test_connectivity(dev[0], hapd)
  836. finally:
  837. dev[0].request("DISCONNECT")
  838. if hapd:
  839. hapd.request("DISABLE")
  840. set_world_reg(apdev[0], None, dev[0])
  841. dev[0].flush_scan_cache()
  842. def test_ap_ht40_csa2(dev, apdev):
  843. """HT with 40 MHz channel width and CSA"""
  844. csa_supported(dev[0])
  845. try:
  846. hapd = None
  847. params = { "ssid": "ht",
  848. "country_code": "US",
  849. "hw_mode": "a",
  850. "channel": "36",
  851. "ht_capab": "[HT40+]",
  852. "ieee80211n": "1" }
  853. hapd = hostapd.add_ap(apdev[0], params)
  854. dev[0].connect("ht", key_mgmt="NONE", scan_freq="5180")
  855. hwsim_utils.test_connectivity(dev[0], hapd)
  856. hapd.request("CHAN_SWITCH 5 5220 ht sec_channel_offset=1 bandwidth=40")
  857. ev = hapd.wait_event(["AP-CSA-FINISHED"], timeout=10)
  858. if ev is None:
  859. raise Exception("CSA finished event timed out")
  860. if "freq=5220" not in ev:
  861. raise Exception("Unexpected channel in CSA finished event")
  862. ev = dev[0].wait_event(["CTRL-EVENT-DISCONNECTED"], timeout=0.5)
  863. if ev is not None:
  864. raise Exception("Unexpected STA disconnection during CSA")
  865. hwsim_utils.test_connectivity(dev[0], hapd)
  866. hapd.request("CHAN_SWITCH 5 5180 ht sec_channel_offset=1 bandwidth=40")
  867. ev = hapd.wait_event(["AP-CSA-FINISHED"], timeout=10)
  868. if ev is None:
  869. raise Exception("CSA finished event timed out")
  870. if "freq=5180" not in ev:
  871. raise Exception("Unexpected channel in CSA finished event")
  872. ev = dev[0].wait_event(["CTRL-EVENT-DISCONNECTED"], timeout=0.5)
  873. if ev is not None:
  874. raise Exception("Unexpected STA disconnection during CSA")
  875. hwsim_utils.test_connectivity(dev[0], hapd)
  876. finally:
  877. dev[0].request("DISCONNECT")
  878. if hapd:
  879. hapd.request("DISABLE")
  880. set_world_reg(apdev[0], None, dev[0])
  881. dev[0].flush_scan_cache()
  882. def test_ap_ht40_csa3(dev, apdev):
  883. """HT with 40 MHz channel width and CSA"""
  884. csa_supported(dev[0])
  885. try:
  886. hapd = None
  887. params = { "ssid": "ht",
  888. "country_code": "US",
  889. "hw_mode": "a",
  890. "channel": "36",
  891. "ht_capab": "[HT40+]",
  892. "ieee80211n": "1" }
  893. hapd = hostapd.add_ap(apdev[0], params)
  894. dev[0].connect("ht", key_mgmt="NONE", scan_freq="5180")
  895. hwsim_utils.test_connectivity(dev[0], hapd)
  896. hapd.request("CHAN_SWITCH 5 5240 ht sec_channel_offset=-1 bandwidth=40")
  897. ev = hapd.wait_event(["AP-CSA-FINISHED"], timeout=10)
  898. if ev is None:
  899. raise Exception("CSA finished event timed out")
  900. if "freq=5240" not in ev:
  901. raise Exception("Unexpected channel in CSA finished event")
  902. ev = dev[0].wait_event(["CTRL-EVENT-DISCONNECTED"], timeout=0.5)
  903. if ev is not None:
  904. raise Exception("Unexpected STA disconnection during CSA")
  905. hwsim_utils.test_connectivity(dev[0], hapd)
  906. hapd.request("CHAN_SWITCH 5 5180 ht sec_channel_offset=1 bandwidth=40")
  907. ev = hapd.wait_event(["AP-CSA-FINISHED"], timeout=10)
  908. if ev is None:
  909. raise Exception("CSA finished event timed out")
  910. if "freq=5180" not in ev:
  911. raise Exception("Unexpected channel in CSA finished event")
  912. ev = dev[0].wait_event(["CTRL-EVENT-DISCONNECTED"], timeout=0.5)
  913. if ev is not None:
  914. raise Exception("Unexpected STA disconnection during CSA")
  915. hwsim_utils.test_connectivity(dev[0], hapd)
  916. finally:
  917. dev[0].request("DISCONNECT")
  918. if hapd:
  919. hapd.request("DISABLE")
  920. set_world_reg(apdev[0], None, dev[0])
  921. dev[0].flush_scan_cache()
  922. @remote_compatible
  923. def test_ap_ht_smps(dev, apdev):
  924. """SMPS AP configuration options"""
  925. params = { "ssid": "ht1", "ht_capab": "[SMPS-STATIC]" }
  926. try:
  927. hapd = hostapd.add_ap(apdev[0], params)
  928. except:
  929. raise HwsimSkip("Assume mac80211_hwsim was not recent enough to support SMPS")
  930. params = { "ssid": "ht2", "ht_capab": "[SMPS-DYNAMIC]" }
  931. hapd2 = hostapd.add_ap(apdev[1], params)
  932. dev[0].connect("ht1", key_mgmt="NONE", scan_freq="2412")
  933. dev[1].connect("ht2", key_mgmt="NONE", scan_freq="2412")
  934. hwsim_utils.test_connectivity(dev[0], hapd)
  935. hwsim_utils.test_connectivity(dev[1], hapd2)
  936. @remote_compatible
  937. def test_prefer_ht20(dev, apdev):
  938. """Preference on HT20 over no-HT"""
  939. params = { "ssid": "test",
  940. "channel": "1",
  941. "ieee80211n": "0" }
  942. hapd = hostapd.add_ap(apdev[0], params)
  943. bssid = apdev[0]['bssid']
  944. params = { "ssid": "test",
  945. "channel": "1",
  946. "ieee80211n": "1" }
  947. hapd2 = hostapd.add_ap(apdev[1], params)
  948. bssid2 = apdev[1]['bssid']
  949. dev[0].scan_for_bss(bssid, freq=2412)
  950. dev[0].scan_for_bss(bssid2, freq=2412)
  951. dev[0].connect("test", key_mgmt="NONE", scan_freq="2412")
  952. if dev[0].get_status_field('bssid') != bssid2:
  953. raise Exception("Unexpected BSS selected")
  954. est = dev[0].get_bss(bssid)['est_throughput']
  955. if est != "54000":
  956. raise Exception("Unexpected BSS0 est_throughput: " + est)
  957. est = dev[0].get_bss(bssid2)['est_throughput']
  958. if est != "65000":
  959. raise Exception("Unexpected BSS1 est_throughput: " + est)
  960. def test_prefer_ht40(dev, apdev):
  961. """Preference on HT40 over HT20"""
  962. params = { "ssid": "test",
  963. "channel": "1",
  964. "ieee80211n": "1" }
  965. hapd = hostapd.add_ap(apdev[0], params)
  966. bssid = apdev[0]['bssid']
  967. params = { "ssid": "test",
  968. "channel": "1",
  969. "ieee80211n": "1",
  970. "ht_capab": "[HT40+]" }
  971. hapd2 = hostapd.add_ap(apdev[1], params)
  972. bssid2 = apdev[1]['bssid']
  973. dev[0].scan_for_bss(bssid, freq=2412)
  974. dev[0].scan_for_bss(bssid2, freq=2412)
  975. dev[0].connect("test", key_mgmt="NONE", scan_freq="2412")
  976. if dev[0].get_status_field('bssid') != bssid2:
  977. raise Exception("Unexpected BSS selected")
  978. est = dev[0].get_bss(bssid)['est_throughput']
  979. if est != "65000":
  980. raise Exception("Unexpected BSS0 est_throughput: " + est)
  981. est = dev[0].get_bss(bssid2)['est_throughput']
  982. if est != "135000":
  983. raise Exception("Unexpected BSS1 est_throughput: " + est)
  984. @remote_compatible
  985. def test_prefer_ht20_during_roam(dev, apdev):
  986. """Preference on HT20 over no-HT in roaming consideration"""
  987. params = { "ssid": "test",
  988. "channel": "1",
  989. "ieee80211n": "0" }
  990. hapd = hostapd.add_ap(apdev[0], params)
  991. bssid = apdev[0]['bssid']
  992. dev[0].scan_for_bss(bssid, freq=2412)
  993. dev[0].connect("test", key_mgmt="NONE", scan_freq="2412")
  994. params = { "ssid": "test",
  995. "channel": "1",
  996. "ieee80211n": "1" }
  997. hapd2 = hostapd.add_ap(apdev[1], params)
  998. bssid2 = apdev[1]['bssid']
  999. dev[0].scan_for_bss(bssid2, freq=2412)
  1000. dev[0].scan(freq=2412)
  1001. dev[0].wait_connected()
  1002. if dev[0].get_status_field('bssid') != bssid2:
  1003. raise Exception("Unexpected BSS selected")
  1004. @remote_compatible
  1005. def test_ap_ht40_5ghz_invalid_pair(dev, apdev):
  1006. """HT40 on 5 GHz with invalid channel pair"""
  1007. clear_scan_cache(apdev[0])
  1008. try:
  1009. params = { "ssid": "test-ht40",
  1010. "hw_mode": "a",
  1011. "channel": "40",
  1012. "country_code": "US",
  1013. "ht_capab": "[HT40+]"}
  1014. hapd = hostapd.add_ap(apdev[0], params, wait_enabled=False)
  1015. ev = hapd.wait_event(["AP-DISABLED", "AP-ENABLED"], timeout=10)
  1016. if not ev:
  1017. raise Exception("AP setup failure timed out")
  1018. if "AP-ENABLED" in ev:
  1019. sec = hapd.get_status_field("secondary_channel")
  1020. if sec != "0":
  1021. raise Exception("Invalid 40 MHz channel accepted")
  1022. finally:
  1023. set_world_reg(apdev[0], None, None)
  1024. @remote_compatible
  1025. def test_ap_ht40_5ghz_disabled_sec(dev, apdev):
  1026. """HT40 on 5 GHz with disabled secondary channel"""
  1027. clear_scan_cache(apdev[0])
  1028. try:
  1029. params = { "ssid": "test-ht40",
  1030. "hw_mode": "a",
  1031. "channel": "48",
  1032. "country_code": "US",
  1033. "ht_capab": "[HT40+]"}
  1034. hapd = hostapd.add_ap(apdev[0], params, wait_enabled=False)
  1035. ev = hapd.wait_event(["AP-DISABLED", "AP-ENABLED"], timeout=10)
  1036. if not ev:
  1037. raise Exception("AP setup failure timed out")
  1038. if "AP-ENABLED" in ev:
  1039. sec = hapd.get_status_field("secondary_channel")
  1040. if sec != "0":
  1041. raise Exception("Invalid 40 MHz channel accepted")
  1042. finally:
  1043. set_world_reg(apdev[0], None, None)
  1044. def test_ap_ht40_scan_broken_ap(dev, apdev):
  1045. """HT40 co-ex scan and broken legacy/HT AP"""
  1046. clear_scan_cache(apdev[0])
  1047. # Broken AP: Include HT Capabilities element but not HT Operation element
  1048. params = { "ssid": "legacy-20",
  1049. "channel": "7", "ieee80211n": "0",
  1050. "wmm_enabled": "1",
  1051. "vendor_elements": "2d1a0e001bffff000000000000000000000100000000000000000000" }
  1052. hapd2 = hostapd.add_ap(apdev[1], params)
  1053. params = { "ssid": "test-ht40",
  1054. "channel": "5",
  1055. "ht_capab": "[HT40-]"}
  1056. hapd = hostapd.add_ap(apdev[0], params, wait_enabled=False)
  1057. state = hapd.get_status_field("state")
  1058. if state != "HT_SCAN":
  1059. time.sleep(0.1)
  1060. state = hapd.get_status_field("state")
  1061. if state != "HT_SCAN":
  1062. raise Exception("Unexpected interface state - expected HT_SCAN")
  1063. ev = hapd.wait_event(["AP-ENABLED"], timeout=10)
  1064. if not ev:
  1065. raise Exception("AP setup timed out")
  1066. state = hapd.get_status_field("state")
  1067. if state != "ENABLED":
  1068. raise Exception("Unexpected interface state - expected ENABLED")
  1069. freq = hapd.get_status_field("freq")
  1070. if freq != "2432":
  1071. raise Exception("Unexpected frequency: " + freq)
  1072. pri = hapd.get_status_field("channel")
  1073. if pri != "5":
  1074. raise Exception("Unexpected primary channel: " + pri)
  1075. sec = hapd.get_status_field("secondary_channel")
  1076. if sec != "-1":
  1077. raise Exception("Unexpected secondary channel: " + sec)
  1078. dev[0].connect("test-ht40", key_mgmt="NONE", scan_freq=freq)
  1079. dev[1].connect("legacy-20", key_mgmt="NONE", scan_freq="2442")
  1080. hwsim_utils.test_connectivity(dev[0], hapd)
  1081. hwsim_utils.test_connectivity(dev[1], hapd2)
  1082. def run_op_class(dev, apdev, hw_mode, channel, country, ht_capab, sec_chan,
  1083. freq, opclass):
  1084. clear_scan_cache(apdev[0])
  1085. try:
  1086. params = { "ssid": "test-ht40",
  1087. "hw_mode": hw_mode,
  1088. "channel": channel,
  1089. "ht_capab": ht_capab }
  1090. if country:
  1091. params['country_code'] = country
  1092. hapd = hostapd.add_ap(apdev[0], params, wait_enabled=False)
  1093. ev = hapd.wait_event(["AP-DISABLED", "AP-ENABLED"], timeout=10)
  1094. if not ev:
  1095. raise Exception("AP setup failure timed out")
  1096. if "AP-DISABLED" in ev:
  1097. raise HwsimSkip("Channel not supported")
  1098. sec = hapd.get_status_field("secondary_channel")
  1099. if sec != sec_chan:
  1100. raise Exception("Unexpected secondary_channel: " + sec)
  1101. dev[0].connect("test-ht40", key_mgmt="NONE", scan_freq=freq)
  1102. bss = dev[0].get_bss(hapd.own_addr())
  1103. ie = parse_ie(bss['ie'])
  1104. if 59 not in ie:
  1105. raise Exception("Missing Supported Operating Classes element")
  1106. rx_opclass, = struct.unpack('B', ie[59][0:1])
  1107. if rx_opclass != opclass:
  1108. raise Exception("Unexpected operating class: %d" % rx_opclass)
  1109. finally:
  1110. set_world_reg(apdev[0], None, None)
  1111. def test_ap_ht_op_class_81(dev, apdev):
  1112. """HT20 on operationg class 81"""
  1113. run_op_class(dev, apdev, "g", "1", None, "", "0", "2412", 81)
  1114. def test_ap_ht_op_class_83(dev, apdev):
  1115. """HT40 on operationg class 83"""
  1116. run_op_class(dev, apdev, "g", "1", None, "[HT40+]", "1", "2412", 83)
  1117. def test_ap_ht_op_class_84(dev, apdev):
  1118. """HT40 on operationg class 84"""
  1119. run_op_class(dev, apdev, "g", "11", None, "[HT40-]", "-1", "2462", 84)
  1120. def test_ap_ht_op_class_115(dev, apdev):
  1121. """HT20 on operationg class 115"""
  1122. run_op_class(dev, apdev, "a", "36", "FI", "", "0", "5180", 115)
  1123. def test_ap_ht_op_class_116(dev, apdev):
  1124. """HT40 on operationg class 116"""
  1125. run_op_class(dev, apdev, "a", "36", "FI", "[HT40+]", "1", "5180", 116)
  1126. def test_ap_ht_op_class_117(dev, apdev):
  1127. """HT40 on operationg class 117"""
  1128. run_op_class(dev, apdev, "a", "40", "FI", "[HT40-]", "-1", "5200", 117)
  1129. def test_ap_ht_op_class_118(dev, apdev):
  1130. """HT20 on operationg class 118"""
  1131. run_op_class(dev, apdev, "a", "60", "RS", "", "0", "5300", 118)
  1132. def test_ap_ht_op_class_119(dev, apdev):
  1133. """HT40 on operationg class 119"""
  1134. run_op_class(dev, apdev, "a", "60", "RS", "[HT40+]", "1", "5300", 119)
  1135. def test_ap_ht_op_class_120(dev, apdev):
  1136. """HT40 on operationg class 120"""
  1137. run_op_class(dev, apdev, "a", "64", "RS", "[HT40-]", "-1", "5320", 120)
  1138. def test_ap_ht_op_class_121(dev, apdev):
  1139. """HT20 on operationg class 121"""
  1140. run_op_class(dev, apdev, "a", "100", "ZA", "", "0", "5500", 121)
  1141. def test_ap_ht_op_class_122(dev, apdev):
  1142. """HT40 on operationg class 122"""
  1143. run_op_class(dev, apdev, "a", "100", "ZA", "[HT40+]", "1", "5500", 122)
  1144. def test_ap_ht_op_class_123(dev, apdev):
  1145. """HT40 on operationg class 123"""
  1146. run_op_class(dev, apdev, "a", "104", "ZA", "[HT40-]", "-1", "5520", 123)
  1147. def test_ap_ht_op_class_124(dev, apdev):
  1148. """HT20 on operationg class 124"""
  1149. run_op_class(dev, apdev, "a", "149", "US", "", "0", "5745", 124)
  1150. def test_ap_ht_op_class_125(dev, apdev):
  1151. """HT20 on operationg class 125"""
  1152. run_op_class(dev, apdev, "a", "169", "NL", "", "0", "5845", 125)
  1153. def test_ap_ht_op_class_126(dev, apdev):
  1154. """HT40 on operationg class 126"""
  1155. run_op_class(dev, apdev, "a", "149", "US", "[HT40+]", "1", "5745", 126)
  1156. def test_ap_ht_op_class_127(dev, apdev):
  1157. """HT40 on operationg class 127"""
  1158. run_op_class(dev, apdev, "a", "153", "US", "[HT40-]", "-1", "5765", 127)
  1159. def test_ap_ht40_plus_minus1(dev, apdev):
  1160. """HT40 with both plus and minus allowed (1)"""
  1161. clear_scan_cache(apdev[0])
  1162. params = { "ssid": "test-ht40",
  1163. "channel": "11",
  1164. "ht_capab": "[HT40+][HT40-]"}
  1165. hapd = hostapd.add_ap(apdev[0], params)
  1166. freq = hapd.get_status_field("freq")
  1167. if freq != "2462":
  1168. raise Exception("Unexpected frequency: " + freq)
  1169. pri = hapd.get_status_field("channel")
  1170. if pri != "11":
  1171. raise Exception("Unexpected primary channel: " + pri)
  1172. sec = hapd.get_status_field("secondary_channel")
  1173. if sec != "-1":
  1174. raise Exception("Unexpected secondary channel: " + sec)
  1175. dev[0].connect("test-ht40", key_mgmt="NONE", scan_freq=freq)
  1176. def test_ap_ht40_plus_minus2(dev, apdev):
  1177. """HT40 with both plus and minus allowed (2)"""
  1178. clear_scan_cache(apdev[0])
  1179. params = { "ssid": "test-ht40",
  1180. "channel": "1",
  1181. "ht_capab": "[HT40+][HT40-]"}
  1182. hapd = hostapd.add_ap(apdev[0], params)
  1183. freq = hapd.get_status_field("freq")
  1184. if freq != "2412":
  1185. raise Exception("Unexpected frequency: " + freq)
  1186. pri = hapd.get_status_field("channel")
  1187. if pri != "1":
  1188. raise Exception("Unexpected primary channel: " + pri)
  1189. sec = hapd.get_status_field("secondary_channel")
  1190. if sec != "1":
  1191. raise Exception("Unexpected secondary channel: " + sec)
  1192. dev[0].connect("test-ht40", key_mgmt="NONE", scan_freq=freq)