test_ap_ht.py 38 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041
  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. import time
  7. import logging
  8. logger = logging.getLogger()
  9. import struct
  10. import subprocess
  11. import hostapd
  12. from utils import HwsimSkip, alloc_fail
  13. import hwsim_utils
  14. from test_ap_csa import csa_supported
  15. def clear_scan_cache(ifname):
  16. subprocess.call(['ifconfig', ifname, 'up'])
  17. subprocess.call(['iw', ifname, 'scan', 'freq', '2412', 'flush'])
  18. time.sleep(0.1)
  19. subprocess.call(['ifconfig', ifname, 'down'])
  20. def test_ap_ht40_scan(dev, apdev):
  21. """HT40 co-ex scan"""
  22. clear_scan_cache(apdev[0]['ifname'])
  23. params = { "ssid": "test-ht40",
  24. "channel": "5",
  25. "ht_capab": "[HT40-]"}
  26. hapd = hostapd.add_ap(apdev[0]['ifname'], params, wait_enabled=False)
  27. state = hapd.get_status_field("state")
  28. if state != "HT_SCAN":
  29. time.sleep(0.1)
  30. state = hapd.get_status_field("state")
  31. if state != "HT_SCAN":
  32. raise Exception("Unexpected interface state - expected HT_SCAN")
  33. ev = hapd.wait_event(["AP-ENABLED"], timeout=10)
  34. if not ev:
  35. raise Exception("AP setup timed out")
  36. state = hapd.get_status_field("state")
  37. if state != "ENABLED":
  38. raise Exception("Unexpected interface state - expected ENABLED")
  39. freq = hapd.get_status_field("freq")
  40. if freq != "2432":
  41. raise Exception("Unexpected frequency")
  42. pri = hapd.get_status_field("channel")
  43. if pri != "5":
  44. raise Exception("Unexpected primary channel")
  45. sec = hapd.get_status_field("secondary_channel")
  46. if sec != "-1":
  47. raise Exception("Unexpected secondary channel")
  48. dev[0].connect("test-ht40", key_mgmt="NONE", scan_freq=freq)
  49. def test_ap_ht40_scan_conflict(dev, apdev):
  50. """HT40 co-ex scan conflict"""
  51. clear_scan_cache(apdev[0]['ifname'])
  52. params = { "ssid": "test-ht40",
  53. "channel": "6",
  54. "ht_capab": "[HT40+]"}
  55. hostapd.add_ap(apdev[1]['ifname'], params)
  56. params = { "ssid": "test-ht40",
  57. "channel": "5",
  58. "ht_capab": "[HT40-]"}
  59. hapd = hostapd.add_ap(apdev[0]['ifname'], params, wait_enabled=False)
  60. state = hapd.get_status_field("state")
  61. if state != "HT_SCAN":
  62. time.sleep(0.1)
  63. state = hapd.get_status_field("state")
  64. if state != "HT_SCAN":
  65. raise Exception("Unexpected interface state - expected HT_SCAN")
  66. ev = hapd.wait_event(["AP-ENABLED"], timeout=10)
  67. if not ev:
  68. raise Exception("AP setup timed out")
  69. state = hapd.get_status_field("state")
  70. if state != "ENABLED":
  71. raise Exception("Unexpected interface state - expected ENABLED")
  72. freq = hapd.get_status_field("freq")
  73. if freq != "2432":
  74. raise Exception("Unexpected frequency")
  75. pri = hapd.get_status_field("channel")
  76. if pri != "5":
  77. raise Exception("Unexpected primary channel")
  78. sec = hapd.get_status_field("secondary_channel")
  79. if sec != "0":
  80. raise Exception("Unexpected secondary channel: " + sec)
  81. dev[0].connect("test-ht40", key_mgmt="NONE", scan_freq=freq)
  82. def test_ap_ht40_scan_legacy_conflict(dev, apdev):
  83. """HT40 co-ex scan conflict with legacy 20 MHz AP"""
  84. clear_scan_cache(apdev[0]['ifname'])
  85. params = { "ssid": "legacy-20",
  86. "channel": "7", "ieee80211n": "0" }
  87. hostapd.add_ap(apdev[1]['ifname'], params)
  88. params = { "ssid": "test-ht40",
  89. "channel": "5",
  90. "ht_capab": "[HT40-]"}
  91. hapd = hostapd.add_ap(apdev[0]['ifname'], params, wait_enabled=False)
  92. state = hapd.get_status_field("state")
  93. if state != "HT_SCAN":
  94. time.sleep(0.1)
  95. state = hapd.get_status_field("state")
  96. if state != "HT_SCAN":
  97. raise Exception("Unexpected interface state - expected HT_SCAN")
  98. ev = hapd.wait_event(["AP-ENABLED"], timeout=10)
  99. if not ev:
  100. raise Exception("AP setup timed out")
  101. state = hapd.get_status_field("state")
  102. if state != "ENABLED":
  103. raise Exception("Unexpected interface state - expected ENABLED")
  104. freq = hapd.get_status_field("freq")
  105. if freq != "2432":
  106. raise Exception("Unexpected frequency: " + freq)
  107. pri = hapd.get_status_field("channel")
  108. if pri != "5":
  109. raise Exception("Unexpected primary channel: " + pri)
  110. sec = hapd.get_status_field("secondary_channel")
  111. if sec != "0":
  112. raise Exception("Unexpected secondary channel: " + sec)
  113. dev[0].connect("test-ht40", key_mgmt="NONE", scan_freq=freq)
  114. def test_ap_ht40_scan_ht20_conflict(dev, apdev):
  115. """HT40 co-ex scan conflict with HT 20 MHz AP"""
  116. clear_scan_cache(apdev[0]['ifname'])
  117. params = { "ssid": "ht-20",
  118. "channel": "7", "ieee80211n": "1" }
  119. hostapd.add_ap(apdev[1]['ifname'], params)
  120. params = { "ssid": "test-ht40",
  121. "channel": "5",
  122. "ht_capab": "[HT40-]"}
  123. hapd = hostapd.add_ap(apdev[0]['ifname'], params, wait_enabled=False)
  124. state = hapd.get_status_field("state")
  125. if state != "HT_SCAN":
  126. time.sleep(0.1)
  127. state = hapd.get_status_field("state")
  128. if state != "HT_SCAN":
  129. raise Exception("Unexpected interface state - expected HT_SCAN")
  130. ev = hapd.wait_event(["AP-ENABLED"], timeout=10)
  131. if not ev:
  132. raise Exception("AP setup timed out")
  133. state = hapd.get_status_field("state")
  134. if state != "ENABLED":
  135. raise Exception("Unexpected interface state - expected ENABLED")
  136. freq = hapd.get_status_field("freq")
  137. if freq != "2432":
  138. raise Exception("Unexpected frequency: " + freq)
  139. pri = hapd.get_status_field("channel")
  140. if pri != "5":
  141. raise Exception("Unexpected primary channel: " + pri)
  142. sec = hapd.get_status_field("secondary_channel")
  143. if sec != "0":
  144. raise Exception("Unexpected secondary channel: " + sec)
  145. dev[0].connect("test-ht40", key_mgmt="NONE", scan_freq=freq)
  146. def test_ap_ht40_scan_intolerant(dev, apdev):
  147. """HT40 co-ex scan finding an AP advertising 40 MHz intolerant"""
  148. clear_scan_cache(apdev[0]['ifname'])
  149. params = { "ssid": "another-bss",
  150. "channel": "1",
  151. "ht_capab": "[40-INTOLERANT]" }
  152. hostapd.add_ap(apdev[1]['ifname'], params)
  153. params = { "ssid": "test-ht40",
  154. "channel": "1",
  155. "ht_capab": "[HT40+]"}
  156. hapd = hostapd.add_ap(apdev[0]['ifname'], params, wait_enabled=False)
  157. state = hapd.get_status_field("state")
  158. if state != "HT_SCAN":
  159. time.sleep(0.1)
  160. state = hapd.get_status_field("state")
  161. if state != "HT_SCAN":
  162. raise Exception("Unexpected interface state - expected HT_SCAN")
  163. ev = hapd.wait_event(["AP-ENABLED"], timeout=10)
  164. if not ev:
  165. raise Exception("AP setup timed out")
  166. state = hapd.get_status_field("state")
  167. if state != "ENABLED":
  168. raise Exception("Unexpected interface state - expected ENABLED")
  169. freq = hapd.get_status_field("freq")
  170. if freq != "2412":
  171. raise Exception("Unexpected frequency: " + freq)
  172. pri = hapd.get_status_field("channel")
  173. if pri != "1":
  174. raise Exception("Unexpected primary channel: " + pri)
  175. sec = hapd.get_status_field("secondary_channel")
  176. if sec != "0":
  177. raise Exception("Unexpected secondary channel: " + sec)
  178. dev[0].connect("test-ht40", key_mgmt="NONE", scan_freq=freq)
  179. def test_ap_ht40_scan_match(dev, apdev):
  180. """HT40 co-ex scan matching configuration"""
  181. clear_scan_cache(apdev[0]['ifname'])
  182. params = { "ssid": "test-ht40",
  183. "channel": "5",
  184. "ht_capab": "[HT40-]"}
  185. hostapd.add_ap(apdev[1]['ifname'], params)
  186. params = { "ssid": "test-ht40",
  187. "channel": "5",
  188. "ht_capab": "[HT40-]"}
  189. hapd = hostapd.add_ap(apdev[0]['ifname'], params, wait_enabled=False)
  190. state = hapd.get_status_field("state")
  191. if state != "HT_SCAN":
  192. time.sleep(0.1)
  193. state = hapd.get_status_field("state")
  194. if state != "HT_SCAN":
  195. raise Exception("Unexpected interface state - expected HT_SCAN")
  196. ev = hapd.wait_event(["AP-ENABLED"], timeout=10)
  197. if not ev:
  198. raise Exception("AP setup timed out")
  199. state = hapd.get_status_field("state")
  200. if state != "ENABLED":
  201. raise Exception("Unexpected interface state - expected ENABLED")
  202. freq = hapd.get_status_field("freq")
  203. if freq != "2432":
  204. raise Exception("Unexpected frequency")
  205. pri = hapd.get_status_field("channel")
  206. if pri != "5":
  207. raise Exception("Unexpected primary channel")
  208. sec = hapd.get_status_field("secondary_channel")
  209. if sec != "-1":
  210. raise Exception("Unexpected secondary channel: " + sec)
  211. dev[0].connect("test-ht40", key_mgmt="NONE", scan_freq=freq)
  212. def test_ap_ht40_5ghz_match(dev, apdev):
  213. """HT40 co-ex scan on 5 GHz with matching pri/sec channel"""
  214. clear_scan_cache(apdev[0]['ifname'])
  215. try:
  216. hapd = None
  217. hapd2 = None
  218. params = { "ssid": "test-ht40",
  219. "hw_mode": "a",
  220. "channel": "36",
  221. "country_code": "US",
  222. "ht_capab": "[HT40+]"}
  223. hapd2 = hostapd.add_ap(apdev[1]['ifname'], params)
  224. params = { "ssid": "test-ht40",
  225. "hw_mode": "a",
  226. "channel": "36",
  227. "ht_capab": "[HT40+]"}
  228. hapd = hostapd.add_ap(apdev[0]['ifname'], params, wait_enabled=False)
  229. state = hapd.get_status_field("state")
  230. if state != "HT_SCAN":
  231. time.sleep(0.1)
  232. state = hapd.get_status_field("state")
  233. if state != "HT_SCAN":
  234. raise Exception("Unexpected interface state - expected HT_SCAN")
  235. ev = hapd.wait_event(["AP-ENABLED"], timeout=10)
  236. if not ev:
  237. raise Exception("AP setup timed out")
  238. state = hapd.get_status_field("state")
  239. if state != "ENABLED":
  240. raise Exception("Unexpected interface state - expected ENABLED")
  241. freq = hapd.get_status_field("freq")
  242. if freq != "5180":
  243. raise Exception("Unexpected frequency")
  244. pri = hapd.get_status_field("channel")
  245. if pri != "36":
  246. raise Exception("Unexpected primary channel")
  247. sec = hapd.get_status_field("secondary_channel")
  248. if sec != "1":
  249. raise Exception("Unexpected secondary channel: " + sec)
  250. dev[0].connect("test-ht40", key_mgmt="NONE", scan_freq=freq)
  251. finally:
  252. dev[0].request("DISCONNECT")
  253. if hapd:
  254. hapd.request("DISABLE")
  255. if hapd2:
  256. hapd2.request("DISABLE")
  257. subprocess.call(['iw', 'reg', 'set', '00'])
  258. dev[0].flush_scan_cache()
  259. def test_ap_ht40_5ghz_switch(dev, apdev):
  260. """HT40 co-ex scan on 5 GHz switching pri/sec channel"""
  261. clear_scan_cache(apdev[0]['ifname'])
  262. try:
  263. hapd = None
  264. hapd2 = None
  265. params = { "ssid": "test-ht40",
  266. "hw_mode": "a",
  267. "channel": "36",
  268. "country_code": "US",
  269. "ht_capab": "[HT40+]"}
  270. hapd2 = hostapd.add_ap(apdev[1]['ifname'], params)
  271. params = { "ssid": "test-ht40",
  272. "hw_mode": "a",
  273. "channel": "40",
  274. "ht_capab": "[HT40-]"}
  275. hapd = hostapd.add_ap(apdev[0]['ifname'], params, wait_enabled=False)
  276. state = hapd.get_status_field("state")
  277. if state != "HT_SCAN":
  278. time.sleep(0.1)
  279. state = hapd.get_status_field("state")
  280. if state != "HT_SCAN":
  281. raise Exception("Unexpected interface state - expected HT_SCAN")
  282. ev = hapd.wait_event(["AP-ENABLED"], timeout=10)
  283. if not ev:
  284. raise Exception("AP setup timed out")
  285. state = hapd.get_status_field("state")
  286. if state != "ENABLED":
  287. raise Exception("Unexpected interface state - expected ENABLED")
  288. freq = hapd.get_status_field("freq")
  289. if freq != "5180":
  290. raise Exception("Unexpected frequency: " + freq)
  291. pri = hapd.get_status_field("channel")
  292. if pri != "36":
  293. raise Exception("Unexpected primary channel: " + pri)
  294. sec = hapd.get_status_field("secondary_channel")
  295. if sec != "1":
  296. raise Exception("Unexpected secondary channel: " + sec)
  297. dev[0].connect("test-ht40", key_mgmt="NONE", scan_freq=freq)
  298. finally:
  299. dev[0].request("DISCONNECT")
  300. if hapd:
  301. hapd.request("DISABLE")
  302. if hapd2:
  303. hapd2.request("DISABLE")
  304. subprocess.call(['iw', 'reg', 'set', '00'])
  305. def test_ap_ht40_5ghz_switch2(dev, apdev):
  306. """HT40 co-ex scan on 5 GHz switching pri/sec channel (2)"""
  307. clear_scan_cache(apdev[0]['ifname'])
  308. try:
  309. hapd = None
  310. hapd2 = None
  311. params = { "ssid": "test-ht40",
  312. "hw_mode": "a",
  313. "channel": "36",
  314. "country_code": "US",
  315. "ht_capab": "[HT40+]"}
  316. hapd2 = hostapd.add_ap(apdev[1]['ifname'], params)
  317. id = dev[0].add_network()
  318. dev[0].set_network(id, "mode", "2")
  319. dev[0].set_network_quoted(id, "ssid", "wpas-ap-open")
  320. dev[0].set_network(id, "key_mgmt", "NONE")
  321. dev[0].set_network(id, "frequency", "5200")
  322. dev[0].set_network(id, "scan_freq", "5200")
  323. dev[0].select_network(id)
  324. time.sleep(1)
  325. params = { "ssid": "test-ht40",
  326. "hw_mode": "a",
  327. "channel": "40",
  328. "ht_capab": "[HT40-]"}
  329. hapd = hostapd.add_ap(apdev[0]['ifname'], params, wait_enabled=False)
  330. state = hapd.get_status_field("state")
  331. if state != "HT_SCAN":
  332. time.sleep(0.1)
  333. state = hapd.get_status_field("state")
  334. if state != "HT_SCAN":
  335. raise Exception("Unexpected interface state - expected HT_SCAN")
  336. ev = hapd.wait_event(["AP-ENABLED"], timeout=10)
  337. if not ev:
  338. raise Exception("AP setup timed out")
  339. state = hapd.get_status_field("state")
  340. if state != "ENABLED":
  341. raise Exception("Unexpected interface state - expected ENABLED")
  342. freq = hapd.get_status_field("freq")
  343. if freq != "5180":
  344. raise Exception("Unexpected frequency: " + freq)
  345. pri = hapd.get_status_field("channel")
  346. if pri != "36":
  347. raise Exception("Unexpected primary channel: " + pri)
  348. sec = hapd.get_status_field("secondary_channel")
  349. if sec != "1":
  350. raise Exception("Unexpected secondary channel: " + sec)
  351. dev[0].connect("test-ht40", key_mgmt="NONE", scan_freq=freq)
  352. finally:
  353. dev[0].request("DISCONNECT")
  354. if hapd:
  355. hapd.request("DISABLE")
  356. if hapd2:
  357. hapd2.request("DISABLE")
  358. subprocess.call(['iw', 'reg', 'set', '00'])
  359. dev[0].flush_scan_cache()
  360. def test_obss_scan(dev, apdev):
  361. """Overlapping BSS scan request"""
  362. params = { "ssid": "obss-scan",
  363. "channel": "6",
  364. "ht_capab": "[HT40-]",
  365. "obss_interval": "10" }
  366. hapd = hostapd.add_ap(apdev[0]['ifname'], params)
  367. params = { "ssid": "another-bss",
  368. "channel": "9",
  369. "ieee80211n": "0" }
  370. hostapd.add_ap(apdev[1]['ifname'], params)
  371. dev[0].connect("obss-scan", key_mgmt="NONE", scan_freq="2437")
  372. hapd.set("ext_mgmt_frame_handling", "1")
  373. logger.info("Waiting for OBSS scan to occur")
  374. ev = dev[0].wait_event(["CTRL-EVENT-SCAN-STARTED"], timeout=15)
  375. if ev is None:
  376. raise Exception("Timed out while waiting for OBSS scan to start")
  377. ev = dev[0].wait_event(["CTRL-EVENT-SCAN-RESULTS"], timeout=10)
  378. if ev is None:
  379. raise Exception("Timed out while waiting for OBSS scan results")
  380. received = False
  381. for i in range(0, 4):
  382. frame = hapd.mgmt_rx(timeout=5)
  383. if frame is None:
  384. raise Exception("MGMT RX wait timed out")
  385. if frame['subtype'] != 13:
  386. continue
  387. payload = frame['payload']
  388. if len(payload) < 3:
  389. continue
  390. (category, action, ie) = struct.unpack('BBB', payload[0:3])
  391. if category != 4:
  392. continue
  393. if action != 0:
  394. continue
  395. if ie == 72:
  396. logger.info("20/40 BSS Coexistence report received")
  397. received = True
  398. break
  399. if not received:
  400. raise Exception("20/40 BSS Coexistence report not seen")
  401. def test_obss_scan_40_intolerant(dev, apdev):
  402. """Overlapping BSS scan request with 40 MHz intolerant AP"""
  403. params = { "ssid": "obss-scan",
  404. "channel": "6",
  405. "ht_capab": "[HT40-]",
  406. "obss_interval": "10" }
  407. hapd = hostapd.add_ap(apdev[0]['ifname'], params)
  408. params = { "ssid": "another-bss",
  409. "channel": "7",
  410. "ht_capab": "[40-INTOLERANT]" }
  411. hostapd.add_ap(apdev[1]['ifname'], params)
  412. dev[0].connect("obss-scan", key_mgmt="NONE", scan_freq="2437")
  413. hapd.set("ext_mgmt_frame_handling", "1")
  414. logger.info("Waiting for OBSS scan to occur")
  415. ev = dev[0].wait_event(["CTRL-EVENT-SCAN-STARTED"], timeout=15)
  416. if ev is None:
  417. raise Exception("Timed out while waiting for OBSS scan to start")
  418. ev = dev[0].wait_event(["CTRL-EVENT-SCAN-RESULTS"], timeout=10)
  419. if ev is None:
  420. raise Exception("Timed out while waiting for OBSS scan results")
  421. received = False
  422. for i in range(0, 4):
  423. frame = hapd.mgmt_rx(timeout=5)
  424. if frame is None:
  425. raise Exception("MGMT RX wait timed out")
  426. if frame['subtype'] != 13:
  427. continue
  428. payload = frame['payload']
  429. if len(payload) < 3:
  430. continue
  431. (category, action, ie) = struct.unpack('BBB', payload[0:3])
  432. if category != 4:
  433. continue
  434. if action != 0:
  435. continue
  436. if ie == 72:
  437. logger.info("20/40 BSS Coexistence report received")
  438. received = True
  439. break
  440. if not received:
  441. raise Exception("20/40 BSS Coexistence report not seen")
  442. def test_obss_coex_report_handling(dev, apdev):
  443. """Overlapping BSS scan report handling with obss_interval=0"""
  444. clear_scan_cache(apdev[0]['ifname'])
  445. params = { "ssid": "obss-scan",
  446. "channel": "6",
  447. "ht_capab": "[HT40-]" }
  448. hapd = hostapd.add_ap(apdev[0]['ifname'], params)
  449. bssid = apdev[0]['bssid']
  450. dev[0].connect("obss-scan", key_mgmt="NONE", scan_freq="2437")
  451. sec = hapd.get_status_field("secondary_channel")
  452. if sec != "-1":
  453. raise Exception("AP is not using 40 MHz channel")
  454. # 20/40 MHz co-ex report tests: number of invalid reports and a valid report
  455. # that forces 20 MHz channel.
  456. tests = [ '0400', '040048', '04004801', '0400480000', '0400490100',
  457. '040048ff0000', '04004801ff49ff00', '04004801004900',
  458. '0400480100490101', '0400480100490201ff',
  459. '040048010449020005' ]
  460. for msg in tests:
  461. req = "MGMT_TX {} {} freq=2437 action={}".format(bssid, bssid, msg)
  462. if "OK" not in dev[0].request(req):
  463. raise Exception("Could not send management frame")
  464. time.sleep(0.5)
  465. sec = hapd.get_status_field("secondary_channel")
  466. if sec != "0":
  467. raise Exception("AP did not move to 20 MHz channel")
  468. def test_obss_coex_report_handling1(dev, apdev):
  469. """Overlapping BSS scan report handling with obss_interval=1"""
  470. clear_scan_cache(apdev[0]['ifname'])
  471. params = { "ssid": "obss-scan",
  472. "channel": "6",
  473. "ht_capab": "[HT40+]",
  474. "obss_interval": "1" }
  475. hapd = hostapd.add_ap(apdev[0]['ifname'], params)
  476. bssid = apdev[0]['bssid']
  477. dev[0].connect("obss-scan", key_mgmt="NONE", scan_freq="2437")
  478. sec = hapd.get_status_field("secondary_channel")
  479. if sec != "1":
  480. raise Exception("AP is not using 40 MHz channel")
  481. # 20/40 MHz co-ex report forcing 20 MHz channel
  482. msg = '040048010449020005'
  483. req = "MGMT_TX {} {} freq=2437 action={}".format(bssid, bssid, msg)
  484. if "OK" not in dev[0].request(req):
  485. raise Exception("Could not send management frame")
  486. time.sleep(0.5)
  487. sec = hapd.get_status_field("secondary_channel")
  488. if sec != "0":
  489. raise Exception("AP did not move to 20 MHz channel")
  490. # No 20/40 MHz co-ex reports forcing 20 MHz channel during next interval
  491. for i in range(20):
  492. sec = hapd.get_status_field("secondary_channel")
  493. if sec == "1":
  494. break
  495. time.sleep(0.5)
  496. if sec != "1":
  497. raise Exception("AP did not return to 40 MHz channel")
  498. def test_olbc(dev, apdev):
  499. """OLBC detection"""
  500. params = { "ssid": "test-olbc",
  501. "channel": "6",
  502. "ht_capab": "[HT40-]",
  503. "ap_table_expiration_time": "2" }
  504. hapd = hostapd.add_ap(apdev[0]['ifname'], params)
  505. status = hapd.get_status()
  506. if status['olbc'] != '0' or status['olbc_ht'] != '0':
  507. raise Exception("Unexpected OLBC information")
  508. params = { "ssid": "olbc-ap",
  509. "hw_mode": "b",
  510. "channel": "6",
  511. "wmm_enabled": "0" }
  512. hostapd.add_ap(apdev[1]['ifname'], params)
  513. time.sleep(0.5)
  514. status = hapd.get_status()
  515. if status['olbc'] != '1' or status['olbc_ht'] != '1':
  516. raise Exception("Missing OLBC information")
  517. hapd_global = hostapd.HostapdGlobal()
  518. hapd_global.remove(apdev[1]['ifname'])
  519. logger.info("Waiting for OLBC state to time out")
  520. cleared = False
  521. for i in range(0, 15):
  522. time.sleep(1)
  523. status = hapd.get_status()
  524. if status['olbc'] == '0' and status['olbc_ht'] == '0':
  525. cleared = True
  526. break
  527. if not cleared:
  528. raise Exception("OLBC state did nto time out")
  529. def test_olbc_table_limit(dev, apdev):
  530. """OLBC AP table size limit"""
  531. ifname1 = apdev[0]['ifname']
  532. ifname2 = apdev[0]['ifname'] + '-2'
  533. ifname3 = apdev[0]['ifname'] + '-3'
  534. hostapd.add_bss('phy3', ifname1, 'bss-1.conf')
  535. hostapd.add_bss('phy3', ifname2, 'bss-2.conf')
  536. hostapd.add_bss('phy3', ifname3, 'bss-3.conf')
  537. params = { "ssid": "test-olbc",
  538. "channel": "1",
  539. "ap_table_max_size": "2" }
  540. hapd = hostapd.add_ap(apdev[1]['ifname'], params)
  541. time.sleep(0.3)
  542. with alloc_fail(hapd, 1, "ap_list_process_beacon"):
  543. time.sleep(0.3)
  544. hapd.set("ap_table_max_size", "1")
  545. time.sleep(0.3)
  546. hapd.set("ap_table_max_size", "0")
  547. time.sleep(0.3)
  548. def test_olbc_5ghz(dev, apdev):
  549. """OLBC detection on 5 GHz"""
  550. try:
  551. hapd = None
  552. hapd2 = None
  553. params = { "ssid": "test-olbc",
  554. "country_code": "FI",
  555. "hw_mode": "a",
  556. "channel": "36",
  557. "ht_capab": "[HT40+]" }
  558. hapd = hostapd.add_ap(apdev[0]['ifname'], params)
  559. status = hapd.get_status()
  560. if status['olbc'] != '0' or status['olbc_ht'] != '0':
  561. raise Exception("Unexpected OLBC information")
  562. params = { "ssid": "olbc-ap",
  563. "country_code": "FI",
  564. "hw_mode": "a",
  565. "channel": "36",
  566. "ieee80211n": "0",
  567. "wmm_enabled": "0" }
  568. hapd2 = hostapd.add_ap(apdev[1]['ifname'], params)
  569. found = False
  570. for i in range(20):
  571. time.sleep(0.1)
  572. status = hapd.get_status()
  573. logger.debug('olbc_ht: ' + status['olbc_ht'])
  574. if status['olbc_ht'] == '1':
  575. found = True
  576. break
  577. if not found:
  578. raise Exception("Missing OLBC information")
  579. finally:
  580. if hapd:
  581. hapd.request("DISABLE")
  582. if hapd2:
  583. hapd2.request("DISABLE")
  584. subprocess.call(['iw', 'reg', 'set', '00'])
  585. def test_ap_require_ht(dev, apdev):
  586. """Require HT"""
  587. params = { "ssid": "require-ht",
  588. "require_ht": "1" }
  589. hapd = hostapd.add_ap(apdev[0]['ifname'], params, wait_enabled=False)
  590. dev[1].connect("require-ht", key_mgmt="NONE", scan_freq="2412",
  591. disable_ht="1", wait_connect=False)
  592. dev[0].connect("require-ht", key_mgmt="NONE", scan_freq="2412")
  593. ev = dev[1].wait_event(["CTRL-EVENT-ASSOC-REJECT"])
  594. if ev is None:
  595. raise Exception("Association rejection timed out")
  596. if "status_code=27" not in ev:
  597. raise Exception("Unexpected rejection status code")
  598. dev[2].connect("require-ht", key_mgmt="NONE", scan_freq="2412",
  599. ht_mcs="0x01 00 00 00 00 00 00 00 00 00",
  600. disable_max_amsdu="1", ampdu_factor="2",
  601. ampdu_density="1", disable_ht40="1", disable_sgi="1",
  602. disable_ldpc="1")
  603. def test_ap_require_ht_limited_rates(dev, apdev):
  604. """Require HT with limited supported rates"""
  605. params = { "ssid": "require-ht",
  606. "supported_rates": "60 120 240 360 480 540",
  607. "require_ht": "1" }
  608. hapd = hostapd.add_ap(apdev[0]['ifname'], params, wait_enabled=False)
  609. dev[1].connect("require-ht", key_mgmt="NONE", scan_freq="2412",
  610. disable_ht="1", wait_connect=False)
  611. dev[0].connect("require-ht", key_mgmt="NONE", scan_freq="2412")
  612. ev = dev[1].wait_event(["CTRL-EVENT-ASSOC-REJECT"])
  613. if ev is None:
  614. raise Exception("Association rejection timed out")
  615. if "status_code=27" not in ev:
  616. raise Exception("Unexpected rejection status code")
  617. def test_ap_ht_capab_not_supported(dev, apdev):
  618. """HT configuration with driver not supporting all ht_capab entries"""
  619. params = { "ssid": "test-ht40",
  620. "channel": "5",
  621. "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]"}
  622. hapd = hostapd.add_ap(apdev[0]['ifname'], params, no_enable=True)
  623. if "FAIL" not in hapd.request("ENABLE"):
  624. raise Exception("Unexpected ENABLE success")
  625. def test_ap_ht_40mhz_intolerant_sta(dev, apdev):
  626. """Associated STA indicating 40 MHz intolerant"""
  627. clear_scan_cache(apdev[0]['ifname'])
  628. params = { "ssid": "intolerant",
  629. "channel": "6",
  630. "ht_capab": "[HT40-]" }
  631. hapd = hostapd.add_ap(apdev[0]['ifname'], params)
  632. if hapd.get_status_field("num_sta_ht40_intolerant") != "0":
  633. raise Exception("Unexpected num_sta_ht40_intolerant value")
  634. if hapd.get_status_field("secondary_channel") != "-1":
  635. raise Exception("Unexpected secondary_channel")
  636. dev[0].connect("intolerant", key_mgmt="NONE", scan_freq="2437")
  637. if hapd.get_status_field("num_sta_ht40_intolerant") != "0":
  638. raise Exception("Unexpected num_sta_ht40_intolerant value")
  639. if hapd.get_status_field("secondary_channel") != "-1":
  640. raise Exception("Unexpected secondary_channel")
  641. dev[2].connect("intolerant", key_mgmt="NONE", scan_freq="2437",
  642. ht40_intolerant="1")
  643. time.sleep(1)
  644. if hapd.get_status_field("num_sta_ht40_intolerant") != "1":
  645. raise Exception("Unexpected num_sta_ht40_intolerant value (expected 1)")
  646. if hapd.get_status_field("secondary_channel") != "0":
  647. raise Exception("Unexpected secondary_channel (did not disable 40 MHz)")
  648. dev[2].request("DISCONNECT")
  649. time.sleep(1)
  650. if hapd.get_status_field("num_sta_ht40_intolerant") != "0":
  651. raise Exception("Unexpected num_sta_ht40_intolerant value (expected 0)")
  652. if hapd.get_status_field("secondary_channel") != "-1":
  653. raise Exception("Unexpected secondary_channel (did not re-enable 40 MHz)")
  654. def test_ap_ht_40mhz_intolerant_ap(dev, apdev):
  655. """Associated STA reports 40 MHz intolerant AP after association"""
  656. clear_scan_cache(apdev[0]['ifname'])
  657. params = { "ssid": "ht",
  658. "channel": "6",
  659. "ht_capab": "[HT40-]",
  660. "obss_interval": "3" }
  661. hapd = hostapd.add_ap(apdev[0]['ifname'], params)
  662. dev[0].connect("ht", key_mgmt="NONE", scan_freq="2437")
  663. if hapd.get_status_field("secondary_channel") != "-1":
  664. raise Exception("Unexpected secondary channel information")
  665. logger.info("Start 40 MHz intolerant AP")
  666. params = { "ssid": "intolerant",
  667. "channel": "5",
  668. "ht_capab": "[40-INTOLERANT]" }
  669. hapd2 = hostapd.add_ap(apdev[1]['ifname'], params)
  670. logger.info("Waiting for co-ex report from STA")
  671. ok = False
  672. for i in range(0, 20):
  673. time.sleep(1)
  674. if hapd.get_status_field("secondary_channel") == "0":
  675. logger.info("AP moved to 20 MHz channel")
  676. ok = True
  677. break
  678. if not ok:
  679. raise Exception("AP did not move to 20 MHz channel")
  680. if "OK" not in hapd2.request("DISABLE"):
  681. raise Exception("Failed to disable 40 MHz intolerant AP")
  682. # make sure the intolerant AP disappears from scan results more quickly
  683. dev[0].scan(type="ONLY", freq="2432", only_new=True)
  684. dev[0].scan(type="ONLY", freq="2432", only_new=True)
  685. dev[0].dump_monitor()
  686. logger.info("Waiting for AP to move back to 40 MHz channel")
  687. ok = False
  688. for i in range(0, 30):
  689. time.sleep(1)
  690. if hapd.get_status_field("secondary_channel") == "-1":
  691. logger.info("AP moved to 40 MHz channel")
  692. ok = True
  693. break
  694. if not ok:
  695. raise Exception("AP did not move to 40 MHz channel")
  696. def test_ap_ht40_csa(dev, apdev):
  697. """HT with 40 MHz channel width and CSA"""
  698. csa_supported(dev[0])
  699. try:
  700. hapd = None
  701. params = { "ssid": "ht",
  702. "country_code": "US",
  703. "hw_mode": "a",
  704. "channel": "36",
  705. "ht_capab": "[HT40+]",
  706. "ieee80211n": "1" }
  707. hapd = hostapd.add_ap(apdev[0]['ifname'], params)
  708. dev[0].connect("ht", key_mgmt="NONE", scan_freq="5180")
  709. hwsim_utils.test_connectivity(dev[0], hapd)
  710. hapd.request("CHAN_SWITCH 5 5200 ht sec_channel_offset=-1 bandwidth=40")
  711. ev = hapd.wait_event(["AP-CSA-FINISHED"], timeout=10)
  712. if ev is None:
  713. raise Exception("CSA finished event timed out")
  714. if "freq=5200" not in ev:
  715. raise Exception("Unexpected channel in CSA finished event")
  716. ev = dev[0].wait_event(["CTRL-EVENT-DISCONNECTED"], timeout=0.5)
  717. if ev is not None:
  718. raise Exception("Unexpected STA disconnection during CSA")
  719. hwsim_utils.test_connectivity(dev[0], hapd)
  720. hapd.request("CHAN_SWITCH 5 5180 ht sec_channel_offset=1 bandwidth=40")
  721. ev = hapd.wait_event(["AP-CSA-FINISHED"], timeout=10)
  722. if ev is None:
  723. raise Exception("CSA finished event timed out")
  724. if "freq=5180" not in ev:
  725. raise Exception("Unexpected channel in CSA finished event")
  726. ev = dev[0].wait_event(["CTRL-EVENT-DISCONNECTED"], timeout=0.5)
  727. if ev is not None:
  728. raise Exception("Unexpected STA disconnection during CSA")
  729. hwsim_utils.test_connectivity(dev[0], hapd)
  730. finally:
  731. dev[0].request("DISCONNECT")
  732. if hapd:
  733. hapd.request("DISABLE")
  734. subprocess.call(['iw', 'reg', 'set', '00'])
  735. dev[0].flush_scan_cache()
  736. def test_ap_ht40_csa2(dev, apdev):
  737. """HT with 40 MHz channel width and CSA"""
  738. csa_supported(dev[0])
  739. try:
  740. hapd = None
  741. params = { "ssid": "ht",
  742. "country_code": "US",
  743. "hw_mode": "a",
  744. "channel": "36",
  745. "ht_capab": "[HT40+]",
  746. "ieee80211n": "1" }
  747. hapd = hostapd.add_ap(apdev[0]['ifname'], params)
  748. dev[0].connect("ht", key_mgmt="NONE", scan_freq="5180")
  749. hwsim_utils.test_connectivity(dev[0], hapd)
  750. hapd.request("CHAN_SWITCH 5 5220 ht sec_channel_offset=1 bandwidth=40")
  751. ev = hapd.wait_event(["AP-CSA-FINISHED"], timeout=10)
  752. if ev is None:
  753. raise Exception("CSA finished event timed out")
  754. if "freq=5220" not in ev:
  755. raise Exception("Unexpected channel in CSA finished event")
  756. ev = dev[0].wait_event(["CTRL-EVENT-DISCONNECTED"], timeout=0.5)
  757. if ev is not None:
  758. raise Exception("Unexpected STA disconnection during CSA")
  759. hwsim_utils.test_connectivity(dev[0], hapd)
  760. hapd.request("CHAN_SWITCH 5 5180 ht sec_channel_offset=1 bandwidth=40")
  761. ev = hapd.wait_event(["AP-CSA-FINISHED"], timeout=10)
  762. if ev is None:
  763. raise Exception("CSA finished event timed out")
  764. if "freq=5180" not in ev:
  765. raise Exception("Unexpected channel in CSA finished event")
  766. ev = dev[0].wait_event(["CTRL-EVENT-DISCONNECTED"], timeout=0.5)
  767. if ev is not None:
  768. raise Exception("Unexpected STA disconnection during CSA")
  769. hwsim_utils.test_connectivity(dev[0], hapd)
  770. finally:
  771. dev[0].request("DISCONNECT")
  772. if hapd:
  773. hapd.request("DISABLE")
  774. subprocess.call(['iw', 'reg', 'set', '00'])
  775. dev[0].flush_scan_cache()
  776. def test_ap_ht40_csa3(dev, apdev):
  777. """HT with 40 MHz channel width and CSA"""
  778. csa_supported(dev[0])
  779. try:
  780. hapd = None
  781. params = { "ssid": "ht",
  782. "country_code": "US",
  783. "hw_mode": "a",
  784. "channel": "36",
  785. "ht_capab": "[HT40+]",
  786. "ieee80211n": "1" }
  787. hapd = hostapd.add_ap(apdev[0]['ifname'], params)
  788. dev[0].connect("ht", key_mgmt="NONE", scan_freq="5180")
  789. hwsim_utils.test_connectivity(dev[0], hapd)
  790. hapd.request("CHAN_SWITCH 5 5240 ht sec_channel_offset=-1 bandwidth=40")
  791. ev = hapd.wait_event(["AP-CSA-FINISHED"], timeout=10)
  792. if ev is None:
  793. raise Exception("CSA finished event timed out")
  794. if "freq=5240" not in ev:
  795. raise Exception("Unexpected channel in CSA finished event")
  796. ev = dev[0].wait_event(["CTRL-EVENT-DISCONNECTED"], timeout=0.5)
  797. if ev is not None:
  798. raise Exception("Unexpected STA disconnection during CSA")
  799. hwsim_utils.test_connectivity(dev[0], hapd)
  800. hapd.request("CHAN_SWITCH 5 5180 ht sec_channel_offset=1 bandwidth=40")
  801. ev = hapd.wait_event(["AP-CSA-FINISHED"], timeout=10)
  802. if ev is None:
  803. raise Exception("CSA finished event timed out")
  804. if "freq=5180" not in ev:
  805. raise Exception("Unexpected channel in CSA finished event")
  806. ev = dev[0].wait_event(["CTRL-EVENT-DISCONNECTED"], timeout=0.5)
  807. if ev is not None:
  808. raise Exception("Unexpected STA disconnection during CSA")
  809. hwsim_utils.test_connectivity(dev[0], hapd)
  810. finally:
  811. dev[0].request("DISCONNECT")
  812. if hapd:
  813. hapd.request("DISABLE")
  814. subprocess.call(['iw', 'reg', 'set', '00'])
  815. dev[0].flush_scan_cache()
  816. def test_ap_ht_smps(dev, apdev):
  817. """SMPS AP configuration options"""
  818. params = { "ssid": "ht1", "ht_capab": "[SMPS-STATIC]" }
  819. try:
  820. hapd = hostapd.add_ap(apdev[0]['ifname'], params)
  821. except:
  822. raise HwsimSkip("Assume mac80211_hwsim was not recent enough to support SMPS")
  823. params = { "ssid": "ht2", "ht_capab": "[SMPS-DYNAMIC]" }
  824. hapd2 = hostapd.add_ap(apdev[1]['ifname'], params)
  825. dev[0].connect("ht1", key_mgmt="NONE", scan_freq="2412")
  826. dev[1].connect("ht2", key_mgmt="NONE", scan_freq="2412")
  827. hwsim_utils.test_connectivity(dev[0], hapd)
  828. hwsim_utils.test_connectivity(dev[1], hapd2)
  829. def test_prefer_ht20(dev, apdev):
  830. """Preference on HT20 over no-HT"""
  831. params = { "ssid": "test",
  832. "channel": "1",
  833. "ieee80211n": "0" }
  834. hapd = hostapd.add_ap(apdev[0]['ifname'], params)
  835. bssid = apdev[0]['bssid']
  836. params = { "ssid": "test",
  837. "channel": "1",
  838. "ieee80211n": "1" }
  839. hapd2 = hostapd.add_ap(apdev[1]['ifname'], params)
  840. bssid2 = apdev[1]['bssid']
  841. dev[0].scan_for_bss(bssid, freq=2412)
  842. dev[0].scan_for_bss(bssid2, freq=2412)
  843. dev[0].connect("test", key_mgmt="NONE", scan_freq="2412")
  844. if dev[0].get_status_field('bssid') != bssid2:
  845. raise Exception("Unexpected BSS selected")
  846. est = dev[0].get_bss(bssid)['est_throughput']
  847. if est != "54000":
  848. raise Exception("Unexpected BSS0 est_throughput: " + est)
  849. est = dev[0].get_bss(bssid2)['est_throughput']
  850. if est != "65000":
  851. raise Exception("Unexpected BSS1 est_throughput: " + est)
  852. def test_prefer_ht40(dev, apdev):
  853. """Preference on HT40 over HT20"""
  854. params = { "ssid": "test",
  855. "channel": "1",
  856. "ieee80211n": "1" }
  857. hapd = hostapd.add_ap(apdev[0]['ifname'], params)
  858. bssid = apdev[0]['bssid']
  859. params = { "ssid": "test",
  860. "channel": "1",
  861. "ieee80211n": "1",
  862. "ht_capab": "[HT40+]" }
  863. hapd2 = hostapd.add_ap(apdev[1]['ifname'], params)
  864. bssid2 = apdev[1]['bssid']
  865. dev[0].scan_for_bss(bssid, freq=2412)
  866. dev[0].scan_for_bss(bssid2, freq=2412)
  867. dev[0].connect("test", key_mgmt="NONE", scan_freq="2412")
  868. if dev[0].get_status_field('bssid') != bssid2:
  869. raise Exception("Unexpected BSS selected")
  870. est = dev[0].get_bss(bssid)['est_throughput']
  871. if est != "65000":
  872. raise Exception("Unexpected BSS0 est_throughput: " + est)
  873. est = dev[0].get_bss(bssid2)['est_throughput']
  874. if est != "135000":
  875. raise Exception("Unexpected BSS1 est_throughput: " + est)
  876. def test_prefer_ht20_during_roam(dev, apdev):
  877. """Preference on HT20 over no-HT in roaming consideration"""
  878. params = { "ssid": "test",
  879. "channel": "1",
  880. "ieee80211n": "0" }
  881. hapd = hostapd.add_ap(apdev[0]['ifname'], params)
  882. bssid = apdev[0]['bssid']
  883. dev[0].scan_for_bss(bssid, freq=2412)
  884. dev[0].connect("test", key_mgmt="NONE", scan_freq="2412")
  885. params = { "ssid": "test",
  886. "channel": "1",
  887. "ieee80211n": "1" }
  888. hapd2 = hostapd.add_ap(apdev[1]['ifname'], params)
  889. bssid2 = apdev[1]['bssid']
  890. dev[0].scan_for_bss(bssid2, freq=2412)
  891. dev[0].scan(freq=2412)
  892. dev[0].wait_connected()
  893. if dev[0].get_status_field('bssid') != bssid2:
  894. raise Exception("Unexpected BSS selected")
  895. def test_ap_ht40_5ghz_invalid_pair(dev, apdev):
  896. """HT40 on 5 GHz with invalid channel pair"""
  897. clear_scan_cache(apdev[0]['ifname'])
  898. try:
  899. params = { "ssid": "test-ht40",
  900. "hw_mode": "a",
  901. "channel": "40",
  902. "country_code": "US",
  903. "ht_capab": "[HT40+]"}
  904. hapd = hostapd.add_ap(apdev[1]['ifname'], params, wait_enabled=False)
  905. ev = hapd.wait_event(["AP-DISABLED"], timeout=10)
  906. if not ev:
  907. raise Exception("AP setup failure timed out")
  908. finally:
  909. subprocess.call(['iw', 'reg', 'set', '00'])