test_ap_ht.py 51 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412
  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_obss_coex_report_handling2(dev, apdev):
  602. """Overlapping BSS scan report handling with obss_interval=1 and no overlap"""
  603. clear_scan_cache(apdev[0])
  604. params = { "ssid": "obss-scan",
  605. "channel": "6",
  606. "ht_capab": "[HT40+]",
  607. "obss_interval": "1" }
  608. hapd = hostapd.add_ap(apdev[0], params)
  609. bssid = apdev[0]['bssid']
  610. dev[0].connect("obss-scan", key_mgmt="NONE", scan_freq="2437")
  611. sec = hapd.get_status_field("secondary_channel")
  612. if sec != "1":
  613. raise Exception("AP is not using 40 MHz channel")
  614. # 20/40 MHz co-ex report that does not force a move to 20 MHz channel
  615. # (out of affected range and matching primary channel cases)
  616. msg = '0400' + '480100' + '49020001' + '49020006'
  617. req = "MGMT_TX {} {} freq=2437 action={}".format(bssid, bssid, msg)
  618. if "OK" not in dev[0].request(req):
  619. raise Exception("Could not send management frame")
  620. time.sleep(0.5)
  621. sec = hapd.get_status_field("secondary_channel")
  622. if sec != "1":
  623. raise Exception("Unexpected move to 20 MHz channel")
  624. # 20/40 MHz co-ex report forcing 20 MHz channel
  625. # (out of affected range and in affected range but not matching primary)
  626. msg = '0400' + '480100' + '4903000105'
  627. req = "MGMT_TX {} {} freq=2437 action={}".format(bssid, bssid, msg)
  628. if "OK" not in dev[0].request(req):
  629. raise Exception("Could not send management frame")
  630. time.sleep(0.5)
  631. sec = hapd.get_status_field("secondary_channel")
  632. if sec != "0":
  633. raise Exception("AP did not move to 20 MHz channel")
  634. def test_olbc(dev, apdev):
  635. """OLBC detection"""
  636. params = { "ssid": "test-olbc",
  637. "channel": "6",
  638. "ht_capab": "[HT40-]",
  639. "ap_table_expiration_time": "2" }
  640. hapd = hostapd.add_ap(apdev[0], params)
  641. status = hapd.get_status()
  642. if status['olbc'] != '0' or status['olbc_ht'] != '0':
  643. raise Exception("Unexpected OLBC information")
  644. params = { "ssid": "olbc-ap",
  645. "hw_mode": "b",
  646. "channel": "6",
  647. "wmm_enabled": "0" }
  648. hostapd.add_ap(apdev[1], params)
  649. time.sleep(0.5)
  650. status = hapd.get_status()
  651. if status['olbc'] != '1' or status['olbc_ht'] != '1':
  652. raise Exception("Missing OLBC information")
  653. hostapd.remove_bss(apdev[1])
  654. logger.info("Waiting for OLBC state to time out")
  655. cleared = False
  656. for i in range(0, 15):
  657. time.sleep(1)
  658. status = hapd.get_status()
  659. if status['olbc'] == '0' and status['olbc_ht'] == '0':
  660. cleared = True
  661. break
  662. if not cleared:
  663. raise Exception("OLBC state did nto time out")
  664. def test_olbc_table_limit(dev, apdev):
  665. """OLBC AP table size limit"""
  666. ifname1 = apdev[0]['ifname']
  667. ifname2 = apdev[0]['ifname'] + '-2'
  668. ifname3 = apdev[0]['ifname'] + '-3'
  669. hostapd.add_bss(apdev[0], ifname1, 'bss-1.conf')
  670. hostapd.add_bss(apdev[0], ifname2, 'bss-2.conf')
  671. hostapd.add_bss(apdev[0], ifname3, 'bss-3.conf')
  672. params = { "ssid": "test-olbc",
  673. "channel": "1",
  674. "ap_table_max_size": "2" }
  675. hapd = hostapd.add_ap(apdev[1], params)
  676. time.sleep(0.3)
  677. with alloc_fail(hapd, 1, "ap_list_process_beacon"):
  678. time.sleep(0.3)
  679. hapd.set("ap_table_max_size", "1")
  680. time.sleep(0.3)
  681. hapd.set("ap_table_max_size", "0")
  682. time.sleep(0.3)
  683. def test_olbc_5ghz(dev, apdev):
  684. """OLBC detection on 5 GHz"""
  685. try:
  686. hapd = None
  687. hapd2 = None
  688. params = { "ssid": "test-olbc",
  689. "country_code": "FI",
  690. "hw_mode": "a",
  691. "channel": "36",
  692. "ht_capab": "[HT40+]" }
  693. hapd = hostapd.add_ap(apdev[0], params)
  694. status = hapd.get_status()
  695. if status['olbc'] != '0' or status['olbc_ht'] != '0':
  696. raise Exception("Unexpected OLBC information")
  697. params = { "ssid": "olbc-ap",
  698. "country_code": "FI",
  699. "hw_mode": "a",
  700. "channel": "36",
  701. "ieee80211n": "0",
  702. "wmm_enabled": "0" }
  703. hapd2 = hostapd.add_ap(apdev[1], params)
  704. found = False
  705. for i in range(20):
  706. time.sleep(0.1)
  707. status = hapd.get_status()
  708. logger.debug('olbc_ht: ' + status['olbc_ht'])
  709. if status['olbc_ht'] == '1':
  710. found = True
  711. break
  712. if not found:
  713. raise Exception("Missing OLBC information")
  714. finally:
  715. if hapd:
  716. hapd.request("DISABLE")
  717. if hapd2:
  718. hapd2.request("DISABLE")
  719. set_world_reg(apdev[0], apdev[1], None)
  720. def test_ap_require_ht(dev, apdev):
  721. """Require HT"""
  722. params = { "ssid": "require-ht",
  723. "require_ht": "1" }
  724. hapd = hostapd.add_ap(apdev[0], params, wait_enabled=False)
  725. dev[1].connect("require-ht", key_mgmt="NONE", scan_freq="2412",
  726. disable_ht="1", wait_connect=False)
  727. dev[0].connect("require-ht", key_mgmt="NONE", scan_freq="2412")
  728. ev = dev[1].wait_event(["CTRL-EVENT-ASSOC-REJECT"])
  729. dev[1].request("DISCONNECT")
  730. if ev is None:
  731. raise Exception("Association rejection timed out")
  732. if "status_code=27" not in ev:
  733. raise Exception("Unexpected rejection status code")
  734. dev[2].connect("require-ht", key_mgmt="NONE", scan_freq="2412",
  735. ht_mcs="0x01 00 00 00 00 00 00 00 00 00",
  736. disable_max_amsdu="1", ampdu_factor="2",
  737. ampdu_density="1", disable_ht40="1", disable_sgi="1",
  738. disable_ldpc="1")
  739. @remote_compatible
  740. def test_ap_require_ht_limited_rates(dev, apdev):
  741. """Require HT with limited supported rates"""
  742. params = { "ssid": "require-ht",
  743. "supported_rates": "60 120 240 360 480 540",
  744. "require_ht": "1" }
  745. hapd = hostapd.add_ap(apdev[0], params, wait_enabled=False)
  746. dev[1].connect("require-ht", key_mgmt="NONE", scan_freq="2412",
  747. disable_ht="1", wait_connect=False)
  748. dev[0].connect("require-ht", key_mgmt="NONE", scan_freq="2412")
  749. ev = dev[1].wait_event(["CTRL-EVENT-ASSOC-REJECT"])
  750. dev[1].request("DISCONNECT")
  751. if ev is None:
  752. raise Exception("Association rejection timed out")
  753. if "status_code=27" not in ev:
  754. raise Exception("Unexpected rejection status code")
  755. @remote_compatible
  756. def test_ap_ht_capab_not_supported(dev, apdev):
  757. """HT configuration with driver not supporting all ht_capab entries"""
  758. params = { "ssid": "test-ht40",
  759. "channel": "5",
  760. "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]"}
  761. hapd = hostapd.add_ap(apdev[0], params, no_enable=True)
  762. if "FAIL" not in hapd.request("ENABLE"):
  763. raise Exception("Unexpected ENABLE success")
  764. def test_ap_ht_40mhz_intolerant_sta(dev, apdev):
  765. """Associated STA indicating 40 MHz intolerant"""
  766. clear_scan_cache(apdev[0])
  767. params = { "ssid": "intolerant",
  768. "channel": "6",
  769. "ht_capab": "[HT40-]" }
  770. hapd = hostapd.add_ap(apdev[0], params)
  771. if hapd.get_status_field("num_sta_ht40_intolerant") != "0":
  772. raise Exception("Unexpected num_sta_ht40_intolerant value")
  773. if hapd.get_status_field("secondary_channel") != "-1":
  774. raise Exception("Unexpected secondary_channel")
  775. dev[0].connect("intolerant", key_mgmt="NONE", scan_freq="2437")
  776. if hapd.get_status_field("num_sta_ht40_intolerant") != "0":
  777. raise Exception("Unexpected num_sta_ht40_intolerant value")
  778. if hapd.get_status_field("secondary_channel") != "-1":
  779. raise Exception("Unexpected secondary_channel")
  780. dev[2].connect("intolerant", key_mgmt="NONE", scan_freq="2437",
  781. ht40_intolerant="1")
  782. time.sleep(1)
  783. if hapd.get_status_field("num_sta_ht40_intolerant") != "1":
  784. raise Exception("Unexpected num_sta_ht40_intolerant value (expected 1)")
  785. if hapd.get_status_field("secondary_channel") != "0":
  786. raise Exception("Unexpected secondary_channel (did not disable 40 MHz)")
  787. dev[2].request("DISCONNECT")
  788. time.sleep(1)
  789. if hapd.get_status_field("num_sta_ht40_intolerant") != "0":
  790. raise Exception("Unexpected num_sta_ht40_intolerant value (expected 0)")
  791. if hapd.get_status_field("secondary_channel") != "-1":
  792. raise Exception("Unexpected secondary_channel (did not re-enable 40 MHz)")
  793. def test_ap_ht_40mhz_intolerant_ap(dev, apdev):
  794. """Associated STA reports 40 MHz intolerant AP after association"""
  795. clear_scan_cache(apdev[0])
  796. params = { "ssid": "ht",
  797. "channel": "6",
  798. "ht_capab": "[HT40-]",
  799. "obss_interval": "3" }
  800. hapd = hostapd.add_ap(apdev[0], params)
  801. dev[0].connect("ht", key_mgmt="NONE", scan_freq="2437")
  802. if hapd.get_status_field("secondary_channel") != "-1":
  803. raise Exception("Unexpected secondary channel information")
  804. logger.info("Start 40 MHz intolerant AP")
  805. params = { "ssid": "intolerant",
  806. "channel": "5",
  807. "ht_capab": "[40-INTOLERANT]" }
  808. hapd2 = hostapd.add_ap(apdev[1], params)
  809. logger.info("Waiting for co-ex report from STA")
  810. ok = False
  811. for i in range(0, 20):
  812. time.sleep(1)
  813. if hapd.get_status_field("secondary_channel") == "0":
  814. logger.info("AP moved to 20 MHz channel")
  815. ok = True
  816. break
  817. if not ok:
  818. raise Exception("AP did not move to 20 MHz channel")
  819. if "OK" not in hapd2.request("DISABLE"):
  820. raise Exception("Failed to disable 40 MHz intolerant AP")
  821. # make sure the intolerant AP disappears from scan results more quickly
  822. dev[0].scan(type="ONLY", freq="2432", only_new=True)
  823. dev[0].scan(type="ONLY", freq="2432", only_new=True)
  824. dev[0].dump_monitor()
  825. logger.info("Waiting for AP to move back to 40 MHz channel")
  826. ok = False
  827. for i in range(0, 30):
  828. time.sleep(1)
  829. if hapd.get_status_field("secondary_channel") == "-1":
  830. logger.info("AP moved to 40 MHz channel")
  831. ok = True
  832. break
  833. if not ok:
  834. raise Exception("AP did not move to 40 MHz channel")
  835. def test_ap_ht40_csa(dev, apdev):
  836. """HT with 40 MHz channel width and CSA"""
  837. csa_supported(dev[0])
  838. try:
  839. hapd = None
  840. params = { "ssid": "ht",
  841. "country_code": "US",
  842. "hw_mode": "a",
  843. "channel": "36",
  844. "ht_capab": "[HT40+]",
  845. "ieee80211n": "1" }
  846. hapd = hostapd.add_ap(apdev[0], params)
  847. dev[0].connect("ht", key_mgmt="NONE", scan_freq="5180")
  848. hwsim_utils.test_connectivity(dev[0], hapd)
  849. hapd.request("CHAN_SWITCH 5 5200 ht sec_channel_offset=-1 bandwidth=40")
  850. ev = hapd.wait_event(["AP-CSA-FINISHED"], timeout=10)
  851. if ev is None:
  852. raise Exception("CSA finished event timed out")
  853. if "freq=5200" not in ev:
  854. raise Exception("Unexpected channel in CSA finished event")
  855. ev = dev[0].wait_event(["CTRL-EVENT-DISCONNECTED"], timeout=0.5)
  856. if ev is not None:
  857. raise Exception("Unexpected STA disconnection during CSA")
  858. hwsim_utils.test_connectivity(dev[0], hapd)
  859. hapd.request("CHAN_SWITCH 5 5180 ht sec_channel_offset=1 bandwidth=40")
  860. ev = hapd.wait_event(["AP-CSA-FINISHED"], timeout=10)
  861. if ev is None:
  862. raise Exception("CSA finished event timed out")
  863. if "freq=5180" not in ev:
  864. raise Exception("Unexpected channel in CSA finished event")
  865. ev = dev[0].wait_event(["CTRL-EVENT-DISCONNECTED"], timeout=0.5)
  866. if ev is not None:
  867. raise Exception("Unexpected STA disconnection during CSA")
  868. hwsim_utils.test_connectivity(dev[0], hapd)
  869. finally:
  870. dev[0].request("DISCONNECT")
  871. if hapd:
  872. hapd.request("DISABLE")
  873. set_world_reg(apdev[0], None, dev[0])
  874. dev[0].flush_scan_cache()
  875. def test_ap_ht40_csa2(dev, apdev):
  876. """HT with 40 MHz channel width and CSA"""
  877. csa_supported(dev[0])
  878. try:
  879. hapd = None
  880. params = { "ssid": "ht",
  881. "country_code": "US",
  882. "hw_mode": "a",
  883. "channel": "36",
  884. "ht_capab": "[HT40+]",
  885. "ieee80211n": "1" }
  886. hapd = hostapd.add_ap(apdev[0], params)
  887. dev[0].connect("ht", key_mgmt="NONE", scan_freq="5180")
  888. hwsim_utils.test_connectivity(dev[0], hapd)
  889. hapd.request("CHAN_SWITCH 5 5220 ht sec_channel_offset=1 bandwidth=40")
  890. ev = hapd.wait_event(["AP-CSA-FINISHED"], timeout=10)
  891. if ev is None:
  892. raise Exception("CSA finished event timed out")
  893. if "freq=5220" not in ev:
  894. raise Exception("Unexpected channel in CSA finished event")
  895. ev = dev[0].wait_event(["CTRL-EVENT-DISCONNECTED"], timeout=0.5)
  896. if ev is not None:
  897. raise Exception("Unexpected STA disconnection during CSA")
  898. hwsim_utils.test_connectivity(dev[0], hapd)
  899. hapd.request("CHAN_SWITCH 5 5180 ht sec_channel_offset=1 bandwidth=40")
  900. ev = hapd.wait_event(["AP-CSA-FINISHED"], timeout=10)
  901. if ev is None:
  902. raise Exception("CSA finished event timed out")
  903. if "freq=5180" not in ev:
  904. raise Exception("Unexpected channel in CSA finished event")
  905. ev = dev[0].wait_event(["CTRL-EVENT-DISCONNECTED"], timeout=0.5)
  906. if ev is not None:
  907. raise Exception("Unexpected STA disconnection during CSA")
  908. hwsim_utils.test_connectivity(dev[0], hapd)
  909. finally:
  910. dev[0].request("DISCONNECT")
  911. if hapd:
  912. hapd.request("DISABLE")
  913. set_world_reg(apdev[0], None, dev[0])
  914. dev[0].flush_scan_cache()
  915. def test_ap_ht40_csa3(dev, apdev):
  916. """HT with 40 MHz channel width and CSA"""
  917. csa_supported(dev[0])
  918. try:
  919. hapd = None
  920. params = { "ssid": "ht",
  921. "country_code": "US",
  922. "hw_mode": "a",
  923. "channel": "36",
  924. "ht_capab": "[HT40+]",
  925. "ieee80211n": "1" }
  926. hapd = hostapd.add_ap(apdev[0], params)
  927. dev[0].connect("ht", key_mgmt="NONE", scan_freq="5180")
  928. hwsim_utils.test_connectivity(dev[0], hapd)
  929. hapd.request("CHAN_SWITCH 5 5240 ht sec_channel_offset=-1 bandwidth=40")
  930. ev = hapd.wait_event(["AP-CSA-FINISHED"], timeout=10)
  931. if ev is None:
  932. raise Exception("CSA finished event timed out")
  933. if "freq=5240" not in ev:
  934. raise Exception("Unexpected channel in CSA finished event")
  935. ev = dev[0].wait_event(["CTRL-EVENT-DISCONNECTED"], timeout=0.5)
  936. if ev is not None:
  937. raise Exception("Unexpected STA disconnection during CSA")
  938. hwsim_utils.test_connectivity(dev[0], hapd)
  939. hapd.request("CHAN_SWITCH 5 5180 ht sec_channel_offset=1 bandwidth=40")
  940. ev = hapd.wait_event(["AP-CSA-FINISHED"], timeout=10)
  941. if ev is None:
  942. raise Exception("CSA finished event timed out")
  943. if "freq=5180" not in ev:
  944. raise Exception("Unexpected channel in CSA finished event")
  945. ev = dev[0].wait_event(["CTRL-EVENT-DISCONNECTED"], timeout=0.5)
  946. if ev is not None:
  947. raise Exception("Unexpected STA disconnection during CSA")
  948. hwsim_utils.test_connectivity(dev[0], hapd)
  949. finally:
  950. dev[0].request("DISCONNECT")
  951. if hapd:
  952. hapd.request("DISABLE")
  953. set_world_reg(apdev[0], None, dev[0])
  954. dev[0].flush_scan_cache()
  955. @remote_compatible
  956. def test_ap_ht_smps(dev, apdev):
  957. """SMPS AP configuration options"""
  958. params = { "ssid": "ht1", "ht_capab": "[SMPS-STATIC]" }
  959. try:
  960. hapd = hostapd.add_ap(apdev[0], params)
  961. except:
  962. raise HwsimSkip("Assume mac80211_hwsim was not recent enough to support SMPS")
  963. params = { "ssid": "ht2", "ht_capab": "[SMPS-DYNAMIC]" }
  964. hapd2 = hostapd.add_ap(apdev[1], params)
  965. dev[0].connect("ht1", key_mgmt="NONE", scan_freq="2412")
  966. dev[1].connect("ht2", key_mgmt="NONE", scan_freq="2412")
  967. hwsim_utils.test_connectivity(dev[0], hapd)
  968. hwsim_utils.test_connectivity(dev[1], hapd2)
  969. @remote_compatible
  970. def test_prefer_ht20(dev, apdev):
  971. """Preference on HT20 over no-HT"""
  972. params = { "ssid": "test",
  973. "channel": "1",
  974. "ieee80211n": "0" }
  975. hapd = hostapd.add_ap(apdev[0], params)
  976. bssid = apdev[0]['bssid']
  977. params = { "ssid": "test",
  978. "channel": "1",
  979. "ieee80211n": "1" }
  980. hapd2 = hostapd.add_ap(apdev[1], params)
  981. bssid2 = apdev[1]['bssid']
  982. dev[0].scan_for_bss(bssid, freq=2412)
  983. dev[0].scan_for_bss(bssid2, freq=2412)
  984. dev[0].connect("test", key_mgmt="NONE", scan_freq="2412")
  985. if dev[0].get_status_field('bssid') != bssid2:
  986. raise Exception("Unexpected BSS selected")
  987. est = dev[0].get_bss(bssid)['est_throughput']
  988. if est != "54000":
  989. raise Exception("Unexpected BSS0 est_throughput: " + est)
  990. est = dev[0].get_bss(bssid2)['est_throughput']
  991. if est != "65000":
  992. raise Exception("Unexpected BSS1 est_throughput: " + est)
  993. def test_prefer_ht40(dev, apdev):
  994. """Preference on HT40 over HT20"""
  995. params = { "ssid": "test",
  996. "channel": "1",
  997. "ieee80211n": "1" }
  998. hapd = hostapd.add_ap(apdev[0], params)
  999. bssid = apdev[0]['bssid']
  1000. params = { "ssid": "test",
  1001. "channel": "1",
  1002. "ieee80211n": "1",
  1003. "ht_capab": "[HT40+]" }
  1004. hapd2 = hostapd.add_ap(apdev[1], params)
  1005. bssid2 = apdev[1]['bssid']
  1006. dev[0].scan_for_bss(bssid, freq=2412)
  1007. dev[0].scan_for_bss(bssid2, freq=2412)
  1008. dev[0].connect("test", key_mgmt="NONE", scan_freq="2412")
  1009. if dev[0].get_status_field('bssid') != bssid2:
  1010. raise Exception("Unexpected BSS selected")
  1011. est = dev[0].get_bss(bssid)['est_throughput']
  1012. if est != "65000":
  1013. raise Exception("Unexpected BSS0 est_throughput: " + est)
  1014. est = dev[0].get_bss(bssid2)['est_throughput']
  1015. if est != "135000":
  1016. raise Exception("Unexpected BSS1 est_throughput: " + est)
  1017. @remote_compatible
  1018. def test_prefer_ht20_during_roam(dev, apdev):
  1019. """Preference on HT20 over no-HT in roaming consideration"""
  1020. params = { "ssid": "test",
  1021. "channel": "1",
  1022. "ieee80211n": "0" }
  1023. hapd = hostapd.add_ap(apdev[0], params)
  1024. bssid = apdev[0]['bssid']
  1025. dev[0].scan_for_bss(bssid, freq=2412)
  1026. dev[0].connect("test", key_mgmt="NONE", scan_freq="2412")
  1027. params = { "ssid": "test",
  1028. "channel": "1",
  1029. "ieee80211n": "1" }
  1030. hapd2 = hostapd.add_ap(apdev[1], params)
  1031. bssid2 = apdev[1]['bssid']
  1032. dev[0].scan_for_bss(bssid2, freq=2412)
  1033. dev[0].scan(freq=2412)
  1034. dev[0].wait_connected()
  1035. if dev[0].get_status_field('bssid') != bssid2:
  1036. raise Exception("Unexpected BSS selected")
  1037. @remote_compatible
  1038. def test_ap_ht40_5ghz_invalid_pair(dev, apdev):
  1039. """HT40 on 5 GHz with invalid channel pair"""
  1040. clear_scan_cache(apdev[0])
  1041. try:
  1042. params = { "ssid": "test-ht40",
  1043. "hw_mode": "a",
  1044. "channel": "40",
  1045. "country_code": "US",
  1046. "ht_capab": "[HT40+]"}
  1047. hapd = hostapd.add_ap(apdev[0], params, wait_enabled=False)
  1048. ev = hapd.wait_event(["AP-DISABLED", "AP-ENABLED"], timeout=10)
  1049. if not ev:
  1050. raise Exception("AP setup failure timed out")
  1051. if "AP-ENABLED" in ev:
  1052. sec = hapd.get_status_field("secondary_channel")
  1053. if sec != "0":
  1054. raise Exception("Invalid 40 MHz channel accepted")
  1055. finally:
  1056. set_world_reg(apdev[0], None, None)
  1057. @remote_compatible
  1058. def test_ap_ht40_5ghz_disabled_sec(dev, apdev):
  1059. """HT40 on 5 GHz with disabled secondary channel"""
  1060. clear_scan_cache(apdev[0])
  1061. try:
  1062. params = { "ssid": "test-ht40",
  1063. "hw_mode": "a",
  1064. "channel": "48",
  1065. "country_code": "US",
  1066. "ht_capab": "[HT40+]"}
  1067. hapd = hostapd.add_ap(apdev[0], params, wait_enabled=False)
  1068. ev = hapd.wait_event(["AP-DISABLED", "AP-ENABLED"], timeout=10)
  1069. if not ev:
  1070. raise Exception("AP setup failure timed out")
  1071. if "AP-ENABLED" in ev:
  1072. sec = hapd.get_status_field("secondary_channel")
  1073. if sec != "0":
  1074. raise Exception("Invalid 40 MHz channel accepted")
  1075. finally:
  1076. set_world_reg(apdev[0], None, None)
  1077. def test_ap_ht40_scan_broken_ap(dev, apdev):
  1078. """HT40 co-ex scan and broken legacy/HT AP"""
  1079. clear_scan_cache(apdev[0])
  1080. # Broken AP: Include HT Capabilities element but not HT Operation element
  1081. params = { "ssid": "legacy-20",
  1082. "channel": "7", "ieee80211n": "0",
  1083. "wmm_enabled": "1",
  1084. "vendor_elements": "2d1a0e001bffff000000000000000000000100000000000000000000" }
  1085. hapd2 = hostapd.add_ap(apdev[1], params)
  1086. params = { "ssid": "test-ht40",
  1087. "channel": "5",
  1088. "ht_capab": "[HT40-]"}
  1089. hapd = hostapd.add_ap(apdev[0], params, wait_enabled=False)
  1090. state = hapd.get_status_field("state")
  1091. if state != "HT_SCAN":
  1092. time.sleep(0.1)
  1093. state = hapd.get_status_field("state")
  1094. if state != "HT_SCAN":
  1095. raise Exception("Unexpected interface state - expected HT_SCAN")
  1096. ev = hapd.wait_event(["AP-ENABLED"], timeout=10)
  1097. if not ev:
  1098. raise Exception("AP setup timed out")
  1099. state = hapd.get_status_field("state")
  1100. if state != "ENABLED":
  1101. raise Exception("Unexpected interface state - expected ENABLED")
  1102. freq = hapd.get_status_field("freq")
  1103. if freq != "2432":
  1104. raise Exception("Unexpected frequency: " + freq)
  1105. pri = hapd.get_status_field("channel")
  1106. if pri != "5":
  1107. raise Exception("Unexpected primary channel: " + pri)
  1108. sec = hapd.get_status_field("secondary_channel")
  1109. if sec != "-1":
  1110. raise Exception("Unexpected secondary channel: " + sec)
  1111. dev[0].connect("test-ht40", key_mgmt="NONE", scan_freq=freq)
  1112. dev[1].connect("legacy-20", key_mgmt="NONE", scan_freq="2442")
  1113. hwsim_utils.test_connectivity(dev[0], hapd)
  1114. hwsim_utils.test_connectivity(dev[1], hapd2)
  1115. def run_op_class(dev, apdev, hw_mode, channel, country, ht_capab, sec_chan,
  1116. freq, opclass):
  1117. clear_scan_cache(apdev[0])
  1118. try:
  1119. params = { "ssid": "test-ht40",
  1120. "hw_mode": hw_mode,
  1121. "channel": channel,
  1122. "ht_capab": ht_capab }
  1123. if country:
  1124. params['country_code'] = country
  1125. hapd = hostapd.add_ap(apdev[0], params, wait_enabled=False)
  1126. ev = hapd.wait_event(["AP-DISABLED", "AP-ENABLED"], timeout=10)
  1127. if not ev:
  1128. raise Exception("AP setup failure timed out")
  1129. if "AP-DISABLED" in ev:
  1130. raise HwsimSkip("Channel not supported")
  1131. sec = hapd.get_status_field("secondary_channel")
  1132. if sec != sec_chan:
  1133. raise Exception("Unexpected secondary_channel: " + sec)
  1134. dev[0].connect("test-ht40", key_mgmt="NONE", scan_freq=freq)
  1135. bss = dev[0].get_bss(hapd.own_addr())
  1136. ie = parse_ie(bss['ie'])
  1137. if 59 not in ie:
  1138. raise Exception("Missing Supported Operating Classes element")
  1139. rx_opclass, = struct.unpack('B', ie[59][0:1])
  1140. if rx_opclass != opclass:
  1141. raise Exception("Unexpected operating class: %d" % rx_opclass)
  1142. finally:
  1143. set_world_reg(apdev[0], None, None)
  1144. def test_ap_ht_op_class_81(dev, apdev):
  1145. """HT20 on operationg class 81"""
  1146. run_op_class(dev, apdev, "g", "1", None, "", "0", "2412", 81)
  1147. def test_ap_ht_op_class_83(dev, apdev):
  1148. """HT40 on operationg class 83"""
  1149. run_op_class(dev, apdev, "g", "1", None, "[HT40+]", "1", "2412", 83)
  1150. def test_ap_ht_op_class_84(dev, apdev):
  1151. """HT40 on operationg class 84"""
  1152. run_op_class(dev, apdev, "g", "11", None, "[HT40-]", "-1", "2462", 84)
  1153. def test_ap_ht_op_class_115(dev, apdev):
  1154. """HT20 on operationg class 115"""
  1155. run_op_class(dev, apdev, "a", "36", "FI", "", "0", "5180", 115)
  1156. def test_ap_ht_op_class_116(dev, apdev):
  1157. """HT40 on operationg class 116"""
  1158. run_op_class(dev, apdev, "a", "36", "FI", "[HT40+]", "1", "5180", 116)
  1159. def test_ap_ht_op_class_117(dev, apdev):
  1160. """HT40 on operationg class 117"""
  1161. run_op_class(dev, apdev, "a", "40", "FI", "[HT40-]", "-1", "5200", 117)
  1162. def test_ap_ht_op_class_118(dev, apdev):
  1163. """HT20 on operationg class 118"""
  1164. run_op_class(dev, apdev, "a", "60", "RS", "", "0", "5300", 118)
  1165. def test_ap_ht_op_class_119(dev, apdev):
  1166. """HT40 on operationg class 119"""
  1167. run_op_class(dev, apdev, "a", "60", "RS", "[HT40+]", "1", "5300", 119)
  1168. def test_ap_ht_op_class_120(dev, apdev):
  1169. """HT40 on operationg class 120"""
  1170. run_op_class(dev, apdev, "a", "64", "RS", "[HT40-]", "-1", "5320", 120)
  1171. def test_ap_ht_op_class_121(dev, apdev):
  1172. """HT20 on operationg class 121"""
  1173. run_op_class(dev, apdev, "a", "100", "ZA", "", "0", "5500", 121)
  1174. def test_ap_ht_op_class_122(dev, apdev):
  1175. """HT40 on operationg class 122"""
  1176. run_op_class(dev, apdev, "a", "100", "ZA", "[HT40+]", "1", "5500", 122)
  1177. def test_ap_ht_op_class_123(dev, apdev):
  1178. """HT40 on operationg class 123"""
  1179. run_op_class(dev, apdev, "a", "104", "ZA", "[HT40-]", "-1", "5520", 123)
  1180. def test_ap_ht_op_class_124(dev, apdev):
  1181. """HT20 on operationg class 124"""
  1182. run_op_class(dev, apdev, "a", "149", "US", "", "0", "5745", 124)
  1183. def test_ap_ht_op_class_125(dev, apdev):
  1184. """HT20 on operationg class 125"""
  1185. run_op_class(dev, apdev, "a", "169", "NL", "", "0", "5845", 125)
  1186. def test_ap_ht_op_class_126(dev, apdev):
  1187. """HT40 on operationg class 126"""
  1188. run_op_class(dev, apdev, "a", "149", "US", "[HT40+]", "1", "5745", 126)
  1189. def test_ap_ht_op_class_127(dev, apdev):
  1190. """HT40 on operationg class 127"""
  1191. run_op_class(dev, apdev, "a", "153", "US", "[HT40-]", "-1", "5765", 127)
  1192. def test_ap_ht40_plus_minus1(dev, apdev):
  1193. """HT40 with both plus and minus allowed (1)"""
  1194. clear_scan_cache(apdev[0])
  1195. params = { "ssid": "test-ht40",
  1196. "channel": "11",
  1197. "ht_capab": "[HT40+][HT40-]"}
  1198. hapd = hostapd.add_ap(apdev[0], params)
  1199. freq = hapd.get_status_field("freq")
  1200. if freq != "2462":
  1201. raise Exception("Unexpected frequency: " + freq)
  1202. pri = hapd.get_status_field("channel")
  1203. if pri != "11":
  1204. raise Exception("Unexpected primary channel: " + pri)
  1205. sec = hapd.get_status_field("secondary_channel")
  1206. if sec != "-1":
  1207. raise Exception("Unexpected secondary channel: " + sec)
  1208. dev[0].connect("test-ht40", key_mgmt="NONE", scan_freq=freq)
  1209. def test_ap_ht40_plus_minus2(dev, apdev):
  1210. """HT40 with both plus and minus allowed (2)"""
  1211. clear_scan_cache(apdev[0])
  1212. params = { "ssid": "test-ht40",
  1213. "channel": "1",
  1214. "ht_capab": "[HT40+][HT40-]"}
  1215. hapd = hostapd.add_ap(apdev[0], params)
  1216. freq = hapd.get_status_field("freq")
  1217. if freq != "2412":
  1218. raise Exception("Unexpected frequency: " + freq)
  1219. pri = hapd.get_status_field("channel")
  1220. if pri != "1":
  1221. raise Exception("Unexpected primary channel: " + pri)
  1222. sec = hapd.get_status_field("secondary_channel")
  1223. if sec != "1":
  1224. raise Exception("Unexpected secondary channel: " + sec)
  1225. dev[0].connect("test-ht40", key_mgmt="NONE", scan_freq=freq)