test_scan.py 39 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976
  1. # Scanning tests
  2. # Copyright (c) 2013-2015, 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 os
  10. import subprocess
  11. import hostapd
  12. from wpasupplicant import WpaSupplicant
  13. from utils import HwsimSkip, fail_test
  14. from tshark import run_tshark
  15. def check_scan(dev, params, other_started=False, test_busy=False):
  16. if not other_started:
  17. dev.dump_monitor()
  18. id = dev.request("SCAN " + params)
  19. if "FAIL" in id:
  20. raise Exception("Failed to start scan")
  21. id = int(id)
  22. if test_busy:
  23. if "FAIL-BUSY" not in dev.request("SCAN"):
  24. raise Exception("SCAN command while already scanning not rejected")
  25. if other_started:
  26. ev = dev.wait_event(["CTRL-EVENT-SCAN-STARTED"])
  27. if ev is None:
  28. raise Exception("Other scan did not start")
  29. if "id=" + str(id) in ev:
  30. raise Exception("Own scan id unexpectedly included in start event")
  31. ev = dev.wait_event(["CTRL-EVENT-SCAN-RESULTS"])
  32. if ev is None:
  33. raise Exception("Other scan did not complete")
  34. if "id=" + str(id) in ev:
  35. raise Exception("Own scan id unexpectedly included in completed event")
  36. ev = dev.wait_event(["CTRL-EVENT-SCAN-STARTED"])
  37. if ev is None:
  38. raise Exception("Scan did not start")
  39. if "id=" + str(id) not in ev:
  40. raise Exception("Scan id not included in start event")
  41. if test_busy:
  42. if "FAIL-BUSY" not in dev.request("SCAN"):
  43. raise Exception("SCAN command while already scanning not rejected")
  44. ev = dev.wait_event(["CTRL-EVENT-SCAN-RESULTS"])
  45. if ev is None:
  46. raise Exception("Scan did not complete")
  47. if "id=" + str(id) not in ev:
  48. raise Exception("Scan id not included in completed event")
  49. def check_scan_retry(dev, params, bssid):
  50. for i in range(0, 5):
  51. check_scan(dev, "freq=2412-2462,5180 use_id=1")
  52. if int(dev.get_bss(bssid)['age']) <= 1:
  53. return
  54. raise Exception("Unexpectedly old BSS entry")
  55. def test_scan(dev, apdev):
  56. """Control interface behavior on scan parameters"""
  57. hostapd.add_ap(apdev[0]['ifname'], { "ssid": "test-scan" })
  58. bssid = apdev[0]['bssid']
  59. logger.info("Full scan")
  60. check_scan(dev[0], "use_id=1", test_busy=True)
  61. logger.info("Limited channel scan")
  62. check_scan_retry(dev[0], "freq=2412-2462,5180 use_id=1", bssid)
  63. # wait long enough to allow next scans to be verified not to find the AP
  64. time.sleep(2)
  65. logger.info("Passive single-channel scan")
  66. check_scan(dev[0], "freq=2457 passive=1 use_id=1")
  67. logger.info("Active single-channel scan")
  68. check_scan(dev[0], "freq=2452 passive=0 use_id=1")
  69. if int(dev[0].get_bss(bssid)['age']) < 2:
  70. raise Exception("Unexpectedly updated BSS entry")
  71. logger.info("Active single-channel scan on AP's operating channel")
  72. check_scan_retry(dev[0], "freq=2412 passive=0 use_id=1", bssid)
  73. def test_scan_tsf(dev, apdev):
  74. """Scan and TSF updates from Beacon/Probe Response frames"""
  75. hostapd.add_ap(apdev[0]['ifname'], { "ssid": "test-scan",
  76. 'beacon_int': "100" })
  77. bssid = apdev[0]['bssid']
  78. tsf = []
  79. for passive in [ 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 1, 1 ]:
  80. check_scan(dev[0], "freq=2412 passive=%d use_id=1" % passive)
  81. bss = dev[0].get_bss(bssid)
  82. if bss:
  83. tsf.append(int(bss['tsf']))
  84. logger.info("TSF: " + bss['tsf'])
  85. if tsf[-3] <= tsf[-4]:
  86. # For now, only write this in the log without failing the test case
  87. # since mac80211_hwsim does not yet update the Timestamp field in
  88. # Probe Response frames.
  89. logger.info("Probe Response did not update TSF")
  90. #raise Exception("Probe Response did not update TSF")
  91. if tsf[-1] <= tsf[-3]:
  92. raise Exception("Beacon did not update TSF")
  93. if 0 in tsf:
  94. raise Exception("0 TSF reported")
  95. def test_scan_only(dev, apdev):
  96. """Control interface behavior on scan parameters with type=only"""
  97. hostapd.add_ap(apdev[0]['ifname'], { "ssid": "test-scan" })
  98. bssid = apdev[0]['bssid']
  99. logger.info("Full scan")
  100. check_scan(dev[0], "type=only use_id=1")
  101. logger.info("Limited channel scan")
  102. check_scan_retry(dev[0], "type=only freq=2412-2462,5180 use_id=1", bssid)
  103. # wait long enough to allow next scans to be verified not to find the AP
  104. time.sleep(2)
  105. logger.info("Passive single-channel scan")
  106. check_scan(dev[0], "type=only freq=2457 passive=1 use_id=1")
  107. logger.info("Active single-channel scan")
  108. check_scan(dev[0], "type=only freq=2452 passive=0 use_id=1")
  109. if int(dev[0].get_bss(bssid)['age']) < 2:
  110. raise Exception("Unexpectedly updated BSS entry")
  111. logger.info("Active single-channel scan on AP's operating channel")
  112. check_scan_retry(dev[0], "type=only freq=2412 passive=0 use_id=1", bssid)
  113. def test_scan_external_trigger(dev, apdev):
  114. """Avoid operations during externally triggered scan"""
  115. hostapd.add_ap(apdev[0]['ifname'], { "ssid": "test-scan" })
  116. bssid = apdev[0]['bssid']
  117. subprocess.call(['iw', dev[0].ifname, 'scan', 'trigger'])
  118. check_scan(dev[0], "use_id=1", other_started=True)
  119. def test_scan_bss_expiration_count(dev, apdev):
  120. """BSS entry expiration based on scan results without match"""
  121. if "FAIL" not in dev[0].request("BSS_EXPIRE_COUNT 0"):
  122. raise Exception("Invalid BSS_EXPIRE_COUNT accepted")
  123. if "OK" not in dev[0].request("BSS_EXPIRE_COUNT 2"):
  124. raise Exception("BSS_EXPIRE_COUNT failed")
  125. hapd = hostapd.add_ap(apdev[0]['ifname'], { "ssid": "test-scan" })
  126. bssid = apdev[0]['bssid']
  127. dev[0].scan(freq="2412", only_new=True)
  128. if bssid not in dev[0].request("SCAN_RESULTS"):
  129. raise Exception("BSS not found in initial scan")
  130. hapd.request("DISABLE")
  131. dev[0].scan(freq="2412", only_new=True)
  132. if bssid not in dev[0].request("SCAN_RESULTS"):
  133. raise Exception("BSS not found in first scan without match")
  134. dev[0].scan(freq="2412", only_new=True)
  135. if bssid in dev[0].request("SCAN_RESULTS"):
  136. raise Exception("BSS found after two scans without match")
  137. def test_scan_bss_expiration_age(dev, apdev):
  138. """BSS entry expiration based on age"""
  139. try:
  140. if "FAIL" not in dev[0].request("BSS_EXPIRE_AGE COUNT 9"):
  141. raise Exception("Invalid BSS_EXPIRE_AGE accepted")
  142. if "OK" not in dev[0].request("BSS_EXPIRE_AGE 10"):
  143. raise Exception("BSS_EXPIRE_AGE failed")
  144. hapd = hostapd.add_ap(apdev[0]['ifname'], { "ssid": "test-scan" })
  145. bssid = apdev[0]['bssid']
  146. dev[0].scan(freq="2412")
  147. if bssid not in dev[0].request("SCAN_RESULTS"):
  148. raise Exception("BSS not found in initial scan")
  149. hapd.request("DISABLE")
  150. logger.info("Waiting for BSS entry to expire")
  151. time.sleep(7)
  152. if bssid not in dev[0].request("SCAN_RESULTS"):
  153. raise Exception("BSS expired too quickly")
  154. ev = dev[0].wait_event(["CTRL-EVENT-BSS-REMOVED"], timeout=15)
  155. if ev is None:
  156. raise Exception("BSS entry expiration timed out")
  157. if bssid in dev[0].request("SCAN_RESULTS"):
  158. raise Exception("BSS not removed after expiration time")
  159. finally:
  160. dev[0].request("BSS_EXPIRE_AGE 180")
  161. def test_scan_filter(dev, apdev):
  162. """Filter scan results based on SSID"""
  163. try:
  164. if "OK" not in dev[0].request("SET filter_ssids 1"):
  165. raise Exception("SET failed")
  166. id = dev[0].connect("test-scan", key_mgmt="NONE", only_add_network=True)
  167. hostapd.add_ap(apdev[0]['ifname'], { "ssid": "test-scan" })
  168. bssid = apdev[0]['bssid']
  169. hostapd.add_ap(apdev[1]['ifname'], { "ssid": "test-scan2" })
  170. bssid2 = apdev[1]['bssid']
  171. dev[0].scan(freq="2412", only_new=True)
  172. if bssid not in dev[0].request("SCAN_RESULTS"):
  173. raise Exception("BSS not found in scan results")
  174. if bssid2 in dev[0].request("SCAN_RESULTS"):
  175. raise Exception("Unexpected BSS found in scan results")
  176. dev[0].set_network_quoted(id, "ssid", "")
  177. dev[0].scan(freq="2412")
  178. id2 = dev[0].connect("test", key_mgmt="NONE", only_add_network=True)
  179. dev[0].scan(freq="2412")
  180. finally:
  181. dev[0].request("SET filter_ssids 0")
  182. def test_scan_int(dev, apdev):
  183. """scan interval configuration"""
  184. try:
  185. if "FAIL" not in dev[0].request("SCAN_INTERVAL -1"):
  186. raise Exception("Accepted invalid scan interval")
  187. if "OK" not in dev[0].request("SCAN_INTERVAL 1"):
  188. raise Exception("Failed to set scan interval")
  189. dev[0].connect("not-used", key_mgmt="NONE", scan_freq="2412",
  190. wait_connect=False)
  191. times = {}
  192. for i in range(0, 3):
  193. logger.info("Waiting for scan to start")
  194. start = os.times()[4]
  195. ev = dev[0].wait_event(["CTRL-EVENT-SCAN-STARTED"], timeout=5)
  196. if ev is None:
  197. raise Exception("did not start a scan")
  198. stop = os.times()[4]
  199. times[i] = stop - start
  200. logger.info("Waiting for scan to complete")
  201. ev = dev[0].wait_event(["CTRL-EVENT-SCAN-RESULTS"], 10)
  202. if ev is None:
  203. raise Exception("did not complete a scan")
  204. logger.info("times=" + str(times))
  205. if times[0] > 1 or times[1] < 0.5 or times[1] > 1.5 or times[2] < 0.5 or times[2] > 1.5:
  206. raise Exception("Unexpected scan timing: " + str(times))
  207. finally:
  208. dev[0].request("SCAN_INTERVAL 5")
  209. def test_scan_bss_operations(dev, apdev):
  210. """Control interface behavior on BSS parameters"""
  211. hostapd.add_ap(apdev[0]['ifname'], { "ssid": "test-scan" })
  212. bssid = apdev[0]['bssid']
  213. hostapd.add_ap(apdev[1]['ifname'], { "ssid": "test2-scan" })
  214. bssid2 = apdev[1]['bssid']
  215. dev[0].scan(freq="2412")
  216. dev[0].scan(freq="2412")
  217. dev[0].scan(freq="2412")
  218. id1 = dev[0].request("BSS FIRST MASK=0x1").splitlines()[0].split('=')[1]
  219. id2 = dev[0].request("BSS LAST MASK=0x1").splitlines()[0].split('=')[1]
  220. res = dev[0].request("BSS RANGE=ALL MASK=0x20001")
  221. if "id=" + id1 not in res:
  222. raise Exception("Missing BSS " + id1)
  223. if "id=" + id2 not in res:
  224. raise Exception("Missing BSS " + id2)
  225. if "====" not in res:
  226. raise Exception("Missing delim")
  227. if "####" not in res:
  228. raise Exception("Missing end")
  229. res = dev[0].request("BSS RANGE=ALL MASK=0")
  230. if "id=" + id1 not in res:
  231. raise Exception("Missing BSS " + id1)
  232. if "id=" + id2 not in res:
  233. raise Exception("Missing BSS " + id2)
  234. if "====" in res:
  235. raise Exception("Unexpected delim")
  236. if "####" in res:
  237. raise Exception("Unexpected end delim")
  238. res = dev[0].request("BSS RANGE=ALL MASK=0x1").splitlines()
  239. if len(res) != 2:
  240. raise Exception("Unexpected result: " + str(res))
  241. res = dev[0].request("BSS FIRST MASK=0x1")
  242. if "id=" + id1 not in res:
  243. raise Exception("Unexpected result: " + res)
  244. res = dev[0].request("BSS LAST MASK=0x1")
  245. if "id=" + id2 not in res:
  246. raise Exception("Unexpected result: " + res)
  247. res = dev[0].request("BSS ID-" + id1 + " MASK=0x1")
  248. if "id=" + id1 not in res:
  249. raise Exception("Unexpected result: " + res)
  250. res = dev[0].request("BSS NEXT-" + id1 + " MASK=0x1")
  251. if "id=" + id2 not in res:
  252. raise Exception("Unexpected result: " + res)
  253. res = dev[0].request("BSS NEXT-" + id2 + " MASK=0x1")
  254. if "id=" in res:
  255. raise Exception("Unexpected result: " + res)
  256. if len(dev[0].request("BSS RANGE=" + id2 + " MASK=0x1").splitlines()) != 0:
  257. raise Exception("Unexpected RANGE=1 result")
  258. if len(dev[0].request("BSS RANGE=" + id1 + "- MASK=0x1").splitlines()) != 2:
  259. raise Exception("Unexpected RANGE=0- result")
  260. if len(dev[0].request("BSS RANGE=-" + id2 + " MASK=0x1").splitlines()) != 2:
  261. raise Exception("Unexpected RANGE=-1 result")
  262. if len(dev[0].request("BSS RANGE=" + id1 + "-" + id2 + " MASK=0x1").splitlines()) != 2:
  263. raise Exception("Unexpected RANGE=0-1 result")
  264. if len(dev[0].request("BSS RANGE=" + id2 + "-" + id2 + " MASK=0x1").splitlines()) != 1:
  265. raise Exception("Unexpected RANGE=1-1 result")
  266. if len(dev[0].request("BSS RANGE=" + str(int(id2) + 1) + "-" + str(int(id2) + 10) + " MASK=0x1").splitlines()) != 0:
  267. raise Exception("Unexpected RANGE=2-10 result")
  268. if len(dev[0].request("BSS RANGE=0-" + str(int(id2) + 10) + " MASK=0x1").splitlines()) != 2:
  269. raise Exception("Unexpected RANGE=0-10 result")
  270. if len(dev[0].request("BSS RANGE=" + id1 + "-" + id1 + " MASK=0x1").splitlines()) != 1:
  271. raise Exception("Unexpected RANGE=0-0 result")
  272. res = dev[0].request("BSS p2p_dev_addr=FOO")
  273. if "FAIL" in res or "id=" in res:
  274. raise Exception("Unexpected result: " + res)
  275. res = dev[0].request("BSS p2p_dev_addr=00:11:22:33:44:55")
  276. if "FAIL" in res or "id=" in res:
  277. raise Exception("Unexpected result: " + res)
  278. dev[0].request("BSS_FLUSH 1000")
  279. res = dev[0].request("BSS RANGE=ALL MASK=0x1").splitlines()
  280. if len(res) != 2:
  281. raise Exception("Unexpected result after BSS_FLUSH 1000")
  282. dev[0].request("BSS_FLUSH 0")
  283. res = dev[0].request("BSS RANGE=ALL MASK=0x1").splitlines()
  284. if len(res) != 0:
  285. raise Exception("Unexpected result after BSS_FLUSH 0")
  286. def test_scan_and_interface_disabled(dev, apdev):
  287. """Scan operation when interface gets disabled"""
  288. try:
  289. dev[0].request("SCAN")
  290. ev = dev[0].wait_event(["CTRL-EVENT-SCAN-STARTED"])
  291. if ev is None:
  292. raise Exception("Scan did not start")
  293. dev[0].request("DRIVER_EVENT INTERFACE_DISABLED")
  294. ev = dev[0].wait_event(["CTRL-EVENT-SCAN-RESULTS"], timeout=7)
  295. if ev is not None:
  296. raise Exception("Scan completed unexpectedly")
  297. # verify that scan is rejected
  298. if "FAIL" not in dev[0].request("SCAN"):
  299. raise Exception("New scan request was accepted unexpectedly")
  300. dev[0].request("DRIVER_EVENT INTERFACE_ENABLED")
  301. dev[0].scan(freq="2412")
  302. finally:
  303. dev[0].request("DRIVER_EVENT INTERFACE_ENABLED")
  304. def test_scan_for_auth(dev, apdev):
  305. """cfg80211 workaround with scan-for-auth"""
  306. hapd = hostapd.add_ap(apdev[0]['ifname'], { "ssid": "open" })
  307. dev[0].scan_for_bss(apdev[0]['bssid'], freq="2412")
  308. # Block sme-connect radio work with an external radio work item, so that
  309. # SELECT_NETWORK can decide to use fast associate without a new scan while
  310. # cfg80211 still has the matching BSS entry, but the actual connection is
  311. # not yet started.
  312. id = dev[0].request("RADIO_WORK add block-work")
  313. ev = dev[0].wait_event(["EXT-RADIO-WORK-START"])
  314. if ev is None:
  315. raise Exception("Timeout while waiting radio work to start")
  316. dev[0].connect("open", key_mgmt="NONE", scan_freq="2412",
  317. wait_connect=False)
  318. dev[0].dump_monitor()
  319. # Clear cfg80211 BSS table.
  320. try:
  321. subprocess.check_call(['iw', dev[0].ifname, 'scan', 'trigger',
  322. 'freq', '2457', 'flush'])
  323. except subprocess.CalledProcessError, e:
  324. raise HwsimSkip("iw scan trigger flush not supported")
  325. ev = dev[0].wait_event(["CTRL-EVENT-SCAN-RESULTS"], 5)
  326. if ev is None:
  327. raise Exception("External flush scan timed out")
  328. # Release blocking radio work to allow connection to go through with the
  329. # cfg80211 BSS entry missing.
  330. dev[0].request("RADIO_WORK done " + id)
  331. dev[0].wait_connected(timeout=15)
  332. def test_scan_for_auth_fail(dev, apdev):
  333. """cfg80211 workaround with scan-for-auth failing"""
  334. hapd = hostapd.add_ap(apdev[0]['ifname'], { "ssid": "open" })
  335. dev[0].scan_for_bss(apdev[0]['bssid'], freq="2412")
  336. # Block sme-connect radio work with an external radio work item, so that
  337. # SELECT_NETWORK can decide to use fast associate without a new scan while
  338. # cfg80211 still has the matching BSS entry, but the actual connection is
  339. # not yet started.
  340. id = dev[0].request("RADIO_WORK add block-work")
  341. ev = dev[0].wait_event(["EXT-RADIO-WORK-START"])
  342. if ev is None:
  343. raise Exception("Timeout while waiting radio work to start")
  344. dev[0].connect("open", key_mgmt="NONE", scan_freq="2412",
  345. wait_connect=False)
  346. dev[0].dump_monitor()
  347. hapd.disable()
  348. # Clear cfg80211 BSS table.
  349. try:
  350. subprocess.check_call(['iw', dev[0].ifname, 'scan', 'trigger',
  351. 'freq', '2457', 'flush'])
  352. except subprocess.CalledProcessError, e:
  353. raise HwsimSkip("iw scan trigger flush not supported")
  354. ev = dev[0].wait_event(["CTRL-EVENT-SCAN-RESULTS"], 5)
  355. if ev is None:
  356. raise Exception("External flush scan timed out")
  357. # Release blocking radio work to allow connection to go through with the
  358. # cfg80211 BSS entry missing.
  359. dev[0].request("RADIO_WORK done " + id)
  360. ev = dev[0].wait_event(["CTRL-EVENT-SCAN-RESULTS",
  361. "CTRL-EVENT-CONNECTED"], 15)
  362. if ev is None:
  363. raise Exception("Scan event missing")
  364. if "CTRL-EVENT-CONNECTED" in ev:
  365. raise Exception("Unexpected connection")
  366. dev[0].request("DISCONNECT")
  367. def test_scan_for_auth_wep(dev, apdev):
  368. """cfg80211 scan-for-auth workaround with WEP keys"""
  369. dev[0].flush_scan_cache()
  370. hapd = hostapd.add_ap(apdev[0]['ifname'],
  371. { "ssid": "wep", "wep_key0": '"abcde"',
  372. "auth_algs": "2" })
  373. dev[0].scan_for_bss(apdev[0]['bssid'], freq="2412")
  374. # Block sme-connect radio work with an external radio work item, so that
  375. # SELECT_NETWORK can decide to use fast associate without a new scan while
  376. # cfg80211 still has the matching BSS entry, but the actual connection is
  377. # not yet started.
  378. id = dev[0].request("RADIO_WORK add block-work")
  379. ev = dev[0].wait_event(["EXT-RADIO-WORK-START"])
  380. if ev is None:
  381. raise Exception("Timeout while waiting radio work to start")
  382. dev[0].connect("wep", key_mgmt="NONE", wep_key0='"abcde"',
  383. auth_alg="SHARED", scan_freq="2412", wait_connect=False)
  384. dev[0].dump_monitor()
  385. # Clear cfg80211 BSS table.
  386. try:
  387. subprocess.check_call(['iw', dev[0].ifname, 'scan', 'trigger',
  388. 'freq', '2457', 'flush'])
  389. except subprocess.CalledProcessError, e:
  390. raise HwsimSkip("iw scan trigger flush not supported")
  391. ev = dev[0].wait_event(["CTRL-EVENT-SCAN-RESULTS"], 5)
  392. if ev is None:
  393. raise Exception("External flush scan timed out")
  394. # Release blocking radio work to allow connection to go through with the
  395. # cfg80211 BSS entry missing.
  396. dev[0].request("RADIO_WORK done " + id)
  397. dev[0].wait_connected(timeout=15)
  398. def test_scan_hidden(dev, apdev):
  399. """Control interface behavior on scan parameters"""
  400. hapd = hostapd.add_ap(apdev[0]['ifname'], { "ssid": "test-scan",
  401. "ignore_broadcast_ssid": "1" })
  402. bssid = apdev[0]['bssid']
  403. check_scan(dev[0], "freq=2412 use_id=1")
  404. if "test-scan" in dev[0].request("SCAN_RESULTS"):
  405. raise Exception("BSS unexpectedly found in initial scan")
  406. id1 = dev[0].connect("foo", key_mgmt="NONE", scan_ssid="1",
  407. only_add_network=True)
  408. id2 = dev[0].connect("test-scan", key_mgmt="NONE", scan_ssid="1",
  409. only_add_network=True)
  410. id3 = dev[0].connect("bar", key_mgmt="NONE", only_add_network=True)
  411. check_scan(dev[0], "freq=2412 use_id=1")
  412. if "test-scan" in dev[0].request("SCAN_RESULTS"):
  413. raise Exception("BSS unexpectedly found in scan")
  414. # Allow multiple attempts to be more robust under heavy CPU load that can
  415. # result in Probe Response frames getting sent only after the station has
  416. # already stopped waiting for the response on the channel.
  417. found = False
  418. for i in range(10):
  419. check_scan(dev[0], "scan_id=%d,%d,%d freq=2412 use_id=1" % (id1, id2, id3))
  420. if "test-scan" in dev[0].request("SCAN_RESULTS"):
  421. found = True
  422. break
  423. if not found:
  424. raise Exception("BSS not found in scan")
  425. if "FAIL" not in dev[0].request("SCAN scan_id=1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17"):
  426. raise Exception("Too many scan_id values accepted")
  427. dev[0].request("REMOVE_NETWORK all")
  428. hapd.disable()
  429. dev[0].flush_scan_cache(freq=2432)
  430. dev[0].flush_scan_cache()
  431. def test_scan_and_bss_entry_removed(dev, apdev):
  432. """Last scan result and connect work processing on BSS entry update"""
  433. hapd = hostapd.add_ap(apdev[0]['ifname'], { "ssid": "open",
  434. "eap_server": "1",
  435. "wps_state": "2" })
  436. bssid = apdev[0]['bssid']
  437. wpas = WpaSupplicant(global_iface='/tmp/wpas-wlan5')
  438. wpas.interface_add("wlan5", drv_params="force_connect_cmd=1")
  439. # Add a BSS entry
  440. dev[0].scan_for_bss(bssid, freq="2412")
  441. wpas.scan_for_bss(bssid, freq="2412")
  442. # Start a connect radio work with a blocking entry preventing this from
  443. # proceeding; this stores a pointer to the selected BSS entry.
  444. id = dev[0].request("RADIO_WORK add block-work")
  445. w_id = wpas.request("RADIO_WORK add block-work")
  446. dev[0].wait_event(["EXT-RADIO-WORK-START"], timeout=1)
  447. wpas.wait_event(["EXT-RADIO-WORK-START"], timeout=1)
  448. nid = dev[0].connect("open", key_mgmt="NONE", scan_freq="2412",
  449. wait_connect=False)
  450. w_nid = wpas.connect("open", key_mgmt="NONE", scan_freq="2412",
  451. wait_connect=False)
  452. time.sleep(0.1)
  453. # Remove the BSS entry
  454. dev[0].request("BSS_FLUSH 0")
  455. wpas.request("BSS_FLUSH 0")
  456. # Allow the connect radio work to continue. The bss entry stored in the
  457. # pending connect work is now stale. This will result in the connection
  458. # attempt failing since the BSS entry does not exist.
  459. dev[0].request("RADIO_WORK done " + id)
  460. wpas.request("RADIO_WORK done " + w_id)
  461. ev = dev[0].wait_event(["CTRL-EVENT-CONNECTED"], timeout=1)
  462. if ev is not None:
  463. raise Exception("Unexpected connection")
  464. dev[0].remove_network(nid)
  465. ev = wpas.wait_event(["CTRL-EVENT-CONNECTED"], timeout=1)
  466. if ev is not None:
  467. raise Exception("Unexpected connection")
  468. wpas.remove_network(w_nid)
  469. time.sleep(0.5)
  470. dev[0].request("BSS_FLUSH 0")
  471. wpas.request("BSS_FLUSH 0")
  472. # Add a BSS entry
  473. dev[0].scan_for_bss(bssid, freq="2412")
  474. wpas.scan_for_bss(bssid, freq="2412")
  475. # Start a connect radio work with a blocking entry preventing this from
  476. # proceeding; this stores a pointer to the selected BSS entry.
  477. id = dev[0].request("RADIO_WORK add block-work")
  478. w_id = wpas.request("RADIO_WORK add block-work")
  479. dev[0].wait_event(["EXT-RADIO-WORK-START"], timeout=1)
  480. wpas.wait_event(["EXT-RADIO-WORK-START"], timeout=1)
  481. # Schedule a connection based on the current BSS entry.
  482. dev[0].connect("open", key_mgmt="NONE", scan_freq="2412",
  483. wait_connect=False)
  484. wpas.connect("open", key_mgmt="NONE", scan_freq="2412",
  485. wait_connect=False)
  486. # Update scan results with results that have longer set of IEs so that new
  487. # memory needs to be allocated for the BSS entry.
  488. hapd.request("WPS_PBC")
  489. time.sleep(0.1)
  490. subprocess.call(['iw', dev[0].ifname, 'scan', 'trigger', 'freq', '2412'])
  491. subprocess.call(['iw', wpas.ifname, 'scan', 'trigger', 'freq', '2412'])
  492. time.sleep(0.1)
  493. # Allow the connect radio work to continue. The bss entry stored in the
  494. # pending connect work becomes stale during the scan and it must have been
  495. # updated for the connection to work.
  496. dev[0].request("RADIO_WORK done " + id)
  497. wpas.request("RADIO_WORK done " + w_id)
  498. dev[0].wait_connected(timeout=15, error="No connection (sme-connect)")
  499. wpas.wait_connected(timeout=15, error="No connection (connect)")
  500. dev[0].request("DISCONNECT")
  501. wpas.request("DISCONNECT")
  502. dev[0].flush_scan_cache()
  503. wpas.flush_scan_cache()
  504. def test_scan_reqs_with_non_scan_radio_work(dev, apdev):
  505. """SCAN commands while non-scan radio_work is in progress"""
  506. id = dev[0].request("RADIO_WORK add test-work-a")
  507. ev = dev[0].wait_event(["EXT-RADIO-WORK-START"])
  508. if ev is None:
  509. raise Exception("Timeout while waiting radio work to start")
  510. if "OK" not in dev[0].request("SCAN"):
  511. raise Exception("SCAN failed")
  512. if "FAIL-BUSY" not in dev[0].request("SCAN"):
  513. raise Exception("SCAN accepted while one is already pending")
  514. if "FAIL-BUSY" not in dev[0].request("SCAN"):
  515. raise Exception("SCAN accepted while one is already pending")
  516. res = dev[0].request("RADIO_WORK show").splitlines()
  517. count = 0
  518. for l in res:
  519. if "scan" in l:
  520. count += 1
  521. if count != 1:
  522. logger.info(res)
  523. raise Exception("Unexpected number of scan radio work items")
  524. dev[0].dump_monitor()
  525. dev[0].request("RADIO_WORK done " + id)
  526. ev = dev[0].wait_event(["CTRL-EVENT-SCAN-STARTED"], timeout=5)
  527. if ev is None:
  528. raise Exception("Scan did not start")
  529. if "FAIL-BUSY" not in dev[0].request("SCAN"):
  530. raise Exception("SCAN accepted while one is already in progress")
  531. ev = dev[0].wait_event(["CTRL-EVENT-SCAN-RESULTS"], timeout=10)
  532. if ev is None:
  533. print "Scan did not complete"
  534. ev = dev[0].wait_event(["CTRL-EVENT-SCAN-STARTED"], timeout=0.2)
  535. if ev is not None:
  536. raise Exception("Unexpected scan started")
  537. def test_scan_setband(dev, apdev):
  538. """Band selection for scan operations"""
  539. try:
  540. hapd = None
  541. hapd2 = None
  542. params = { "ssid": "test-setband",
  543. "hw_mode": "a",
  544. "channel": "36",
  545. "country_code": "US" }
  546. hapd = hostapd.add_ap(apdev[0]['ifname'], params)
  547. bssid = apdev[0]['bssid']
  548. params = { "ssid": "test-setband",
  549. "hw_mode": "g",
  550. "channel": "1" }
  551. hapd2 = hostapd.add_ap(apdev[1]['ifname'], params)
  552. bssid2 = apdev[1]['bssid']
  553. if "FAIL" not in dev[0].request("SET setband FOO"):
  554. raise Exception("Invalid set setband accepted")
  555. if "OK" not in dev[0].request("SET setband AUTO"):
  556. raise Exception("Failed to set setband")
  557. if "OK" not in dev[1].request("SET setband 5G"):
  558. raise Exception("Failed to set setband")
  559. if "OK" not in dev[2].request("SET setband 2G"):
  560. raise Exception("Failed to set setband")
  561. for i in range(3):
  562. dev[i].request("SCAN only_new=1")
  563. for i in range(3):
  564. ev = dev[i].wait_event(["CTRL-EVENT-SCAN-RESULTS"], 15)
  565. if ev is None:
  566. raise Exception("Scan timed out")
  567. res = dev[0].request("SCAN_RESULTS")
  568. if bssid not in res or bssid2 not in res:
  569. raise Exception("Missing scan result(0)")
  570. res = dev[1].request("SCAN_RESULTS")
  571. if bssid not in res:
  572. raise Exception("Missing scan result(1)")
  573. if bssid2 in res:
  574. raise Exception("Unexpected scan result(1)")
  575. res = dev[2].request("SCAN_RESULTS")
  576. if bssid2 not in res:
  577. raise Exception("Missing scan result(2)")
  578. if bssid in res:
  579. raise Exception("Unexpected scan result(2)")
  580. finally:
  581. if hapd:
  582. hapd.request("DISABLE")
  583. if hapd2:
  584. hapd2.request("DISABLE")
  585. subprocess.call(['iw', 'reg', 'set', '00'])
  586. for i in range(3):
  587. dev[i].request("SET setband AUTO")
  588. dev[i].flush_scan_cache()
  589. def test_scan_hidden_many(dev, apdev):
  590. """scan_ssid=1 with large number of profile with hidden SSID"""
  591. try:
  592. _test_scan_hidden_many(dev, apdev)
  593. finally:
  594. dev[0].flush_scan_cache(freq=2432)
  595. dev[0].flush_scan_cache()
  596. dev[0].request("SCAN_INTERVAL 5")
  597. def _test_scan_hidden_many(dev, apdev):
  598. hapd = hostapd.add_ap(apdev[0]['ifname'], { "ssid": "test-scan-ssid",
  599. "ignore_broadcast_ssid": "1" })
  600. bssid = apdev[0]['bssid']
  601. dev[0].request("SCAN_INTERVAL 1")
  602. for i in range(5):
  603. id = dev[0].add_network()
  604. dev[0].set_network_quoted(id, "ssid", "foo")
  605. dev[0].set_network(id, "key_mgmt", "NONE")
  606. dev[0].set_network(id, "disabled", "0")
  607. dev[0].set_network(id, "scan_freq", "2412")
  608. dev[0].set_network(id, "scan_ssid", "1")
  609. dev[0].set_network_quoted(id, "ssid", "test-scan-ssid")
  610. dev[0].set_network(id, "key_mgmt", "NONE")
  611. dev[0].set_network(id, "disabled", "0")
  612. dev[0].set_network(id, "scan_freq", "2412")
  613. dev[0].set_network(id, "scan_ssid", "1")
  614. for i in range(5):
  615. id = dev[0].add_network()
  616. dev[0].set_network_quoted(id, "ssid", "foo")
  617. dev[0].set_network(id, "key_mgmt", "NONE")
  618. dev[0].set_network(id, "disabled", "0")
  619. dev[0].set_network(id, "scan_freq", "2412")
  620. dev[0].set_network(id, "scan_ssid", "1")
  621. dev[0].request("REASSOCIATE")
  622. dev[0].wait_connected(timeout=30)
  623. dev[0].request("REMOVE_NETWORK all")
  624. hapd.disable()
  625. def test_scan_random_mac(dev, apdev, params):
  626. """Random MAC address in scans"""
  627. try:
  628. _test_scan_random_mac(dev, apdev, params)
  629. finally:
  630. dev[0].request("MAC_RAND_SCAN all enable=0")
  631. def _test_scan_random_mac(dev, apdev, params):
  632. hostapd.add_ap(apdev[0]['ifname'], { "ssid": "test-scan" })
  633. bssid = apdev[0]['bssid']
  634. tests = [ "",
  635. "addr=foo",
  636. "mask=foo",
  637. "enable=1",
  638. "all enable=1 mask=00:11:22:33:44:55",
  639. "all enable=1 addr=00:11:22:33:44:55",
  640. "all enable=1 addr=01:11:22:33:44:55 mask=ff:ff:ff:ff:ff:ff",
  641. "all enable=1 addr=00:11:22:33:44:55 mask=fe:ff:ff:ff:ff:ff",
  642. "enable=2 scan sched pno all",
  643. "pno enable=1",
  644. "all enable=2",
  645. "foo" ]
  646. for args in tests:
  647. if "FAIL" not in dev[0].request("MAC_RAND_SCAN " + args):
  648. raise Exception("Invalid MAC_RAND_SCAN accepted: " + args)
  649. if dev[0].get_driver_status_field('capa.mac_addr_rand_scan_supported') != '1':
  650. raise HwsimSkip("Driver does not support random MAC address for scanning")
  651. tests = [ "all enable=1",
  652. "all enable=1 addr=f2:11:22:33:44:55 mask=ff:ff:ff:ff:ff:ff",
  653. "all enable=1 addr=f2:11:33:00:00:00 mask=ff:ff:ff:00:00:00" ]
  654. for args in tests:
  655. dev[0].request("MAC_RAND_SCAN " + args)
  656. dev[0].scan_for_bss(bssid, freq=2412, force_scan=True)
  657. out = run_tshark(os.path.join(params['logdir'], "hwsim0.pcapng"),
  658. "wlan.fc.type_subtype == 4", ["wlan.ta" ])
  659. if out is not None:
  660. addr = out.splitlines()
  661. logger.info("Probe Request frames seen from: " + str(addr))
  662. if dev[0].own_addr() in addr:
  663. raise Exception("Real address used to transmit Probe Request frame")
  664. if "f2:11:22:33:44:55" not in addr:
  665. raise Exception("Fully configured random address not seen")
  666. found = False
  667. for a in addr:
  668. if a.startswith('f2:11:33'):
  669. found = True
  670. break
  671. if not found:
  672. raise Exception("Fixed OUI random address not seen")
  673. def test_scan_trigger_failure(dev, apdev):
  674. """Scan trigger to the driver failing"""
  675. hostapd.add_ap(apdev[0]['ifname'], { "ssid": "test-scan" })
  676. bssid = apdev[0]['bssid']
  677. if "OK" not in dev[0].request("SET test_failure 1"):
  678. raise Exception("Failed to set test_failure")
  679. if "OK" not in dev[0].request("SCAN"):
  680. raise Exception("SCAN command failed")
  681. ev = dev[0].wait_event(["CTRL-EVENT-SCAN-FAILED"], timeout=10)
  682. if ev is None:
  683. raise Exception("Did not receive CTRL-EVENT-SCAN-FAILED event")
  684. if "retry=1" in ev:
  685. raise Exception("Unexpected scan retry indicated")
  686. if dev[0].get_status_field('wpa_state') == "SCANNING":
  687. raise Exception("wpa_state SCANNING not cleared")
  688. id = dev[0].connect("test-scan", key_mgmt="NONE", scan_freq="2412",
  689. only_add_network=True)
  690. dev[0].select_network(id)
  691. ev = dev[0].wait_event(["CTRL-EVENT-SCAN-FAILED"], timeout=10)
  692. if ev is None:
  693. raise Exception("Did not receive CTRL-EVENT-SCAN-FAILED event")
  694. if "retry=1" not in ev:
  695. raise Exception("No scan retry indicated for connection")
  696. if dev[0].get_status_field('wpa_state') == "SCANNING":
  697. raise Exception("wpa_state SCANNING not cleared")
  698. dev[0].request("SET test_failure 0")
  699. dev[0].wait_connected()
  700. dev[0].request("SET test_failure 1")
  701. if "OK" not in dev[0].request("SCAN"):
  702. raise Exception("SCAN command failed")
  703. ev = dev[0].wait_event(["CTRL-EVENT-SCAN-FAILED"], timeout=10)
  704. if ev is None:
  705. raise Exception("Did not receive CTRL-EVENT-SCAN-FAILED event")
  706. if "retry=1" in ev:
  707. raise Exception("Unexpected scan retry indicated")
  708. if dev[0].get_status_field('wpa_state') != "COMPLETED":
  709. raise Exception("wpa_state COMPLETED not restored")
  710. dev[0].request("SET test_failure 0")
  711. def test_scan_specify_ssid(dev, apdev):
  712. """Control interface behavior on scan SSID parameter"""
  713. dev[0].flush_scan_cache()
  714. hapd = hostapd.add_ap(apdev[0]['ifname'], { "ssid": "test-hidden",
  715. "ignore_broadcast_ssid": "1" })
  716. bssid = apdev[0]['bssid']
  717. check_scan(dev[0], "freq=2412 use_id=1 ssid 414243")
  718. bss = dev[0].get_bss(bssid)
  719. if bss is not None and bss['ssid'] == 'test-hidden':
  720. raise Exception("BSS entry for hidden AP present unexpectedly")
  721. check_scan(dev[0], "freq=2412 ssid 414243 ssid 746573742d68696464656e ssid 616263313233 use_id=1")
  722. bss = dev[0].get_bss(bssid)
  723. if bss is None:
  724. raise Exception("BSS entry for hidden AP not found")
  725. if 'test-hidden' not in dev[0].request("SCAN_RESULTS"):
  726. raise Exception("Expected SSID not included in the scan results");
  727. hapd.disable()
  728. dev[0].flush_scan_cache(freq=2432)
  729. dev[0].flush_scan_cache()
  730. if "FAIL" not in dev[0].request("SCAN ssid foo"):
  731. raise Exception("Invalid SCAN command accepted")
  732. def test_scan_ap_scan_2_ap_mode(dev, apdev):
  733. """AP_SCAN 2 AP mode and scan()"""
  734. try:
  735. _test_scan_ap_scan_2_ap_mode(dev, apdev)
  736. finally:
  737. dev[0].request("AP_SCAN 1")
  738. def _test_scan_ap_scan_2_ap_mode(dev, apdev):
  739. if "OK" not in dev[0].request("AP_SCAN 2"):
  740. raise Exception("Failed to set AP_SCAN 2")
  741. id = dev[0].add_network()
  742. dev[0].set_network(id, "mode", "2")
  743. dev[0].set_network_quoted(id, "ssid", "wpas-ap-open")
  744. dev[0].set_network(id, "key_mgmt", "NONE")
  745. dev[0].set_network(id, "frequency", "2412")
  746. dev[0].set_network(id, "scan_freq", "2412")
  747. dev[0].set_network(id, "disabled", "0")
  748. dev[0].select_network(id)
  749. ev = dev[0].wait_event(["CTRL-EVENT-CONNECTED"], timeout=5)
  750. if ev is None:
  751. raise Exception("AP failed to start")
  752. with fail_test(dev[0], 1, "wpa_driver_nl80211_scan"):
  753. if "OK" not in dev[0].request("SCAN freq=2412"):
  754. raise Exception("SCAN command failed unexpectedly")
  755. ev = dev[0].wait_event(["CTRL-EVENT-SCAN-FAILED",
  756. "AP-DISABLED"], timeout=5)
  757. if ev is None:
  758. raise Exception("CTRL-EVENT-SCAN-FAILED not seen")
  759. if "AP-DISABLED" in ev:
  760. raise Exception("Unexpected AP-DISABLED event")
  761. if "retry=1" in ev:
  762. # Wait for the retry to scan happen
  763. ev = dev[0].wait_event(["CTRL-EVENT-SCAN-FAILED",
  764. "AP-DISABLED"], timeout=5)
  765. if ev is None:
  766. raise Exception("CTRL-EVENT-SCAN-FAILED not seen - retry")
  767. if "AP-DISABLED" in ev:
  768. raise Exception("Unexpected AP-DISABLED event - retry")
  769. dev[1].connect("wpas-ap-open", key_mgmt="NONE", scan_freq="2412")
  770. dev[1].request("DISCONNECT")
  771. dev[1].wait_disconnected()
  772. dev[0].request("DISCONNECT")
  773. dev[0].wait_disconnected()
  774. def test_scan_bss_expiration_on_ssid_change(dev, apdev):
  775. """BSS entry expiration when AP changes SSID"""
  776. dev[0].flush_scan_cache()
  777. hapd = hostapd.add_ap(apdev[0]['ifname'], { "ssid": "test-scan" })
  778. bssid = apdev[0]['bssid']
  779. dev[0].scan_for_bss(apdev[0]['bssid'], freq="2412")
  780. hapd.request("DISABLE")
  781. hapd = hostapd.add_ap(apdev[0]['ifname'], { "ssid": "open" })
  782. if "OK" not in dev[0].request("BSS_EXPIRE_COUNT 3"):
  783. raise Exception("BSS_EXPIRE_COUNT failed")
  784. dev[0].scan(freq="2412")
  785. dev[0].scan(freq="2412")
  786. if "OK" not in dev[0].request("BSS_EXPIRE_COUNT 2"):
  787. raise Exception("BSS_EXPIRE_COUNT failed")
  788. res = dev[0].request("SCAN_RESULTS")
  789. if "test-scan" not in res:
  790. raise Exception("The first SSID not in scan results")
  791. if "open" not in res:
  792. raise Exception("The second SSID not in scan results")
  793. dev[0].connect("open", key_mgmt="NONE")
  794. dev[0].request("BSS_FLUSH 0")
  795. res = dev[0].request("SCAN_RESULTS")
  796. if "test-scan" in res:
  797. raise Exception("The BSS entry with the old SSID was not removed")
  798. dev[0].request("DISCONNECT")
  799. dev[0].wait_disconnected()
  800. def test_scan_dfs(dev, apdev, params):
  801. """Scan on DFS channels"""
  802. try:
  803. _test_scan_dfs(dev, apdev, params)
  804. finally:
  805. subprocess.call(['iw', 'reg', 'set', '00'])
  806. def _test_scan_dfs(dev, apdev, params):
  807. subprocess.call(['iw', 'reg', 'set', 'US'])
  808. for i in range(2):
  809. for j in range(5):
  810. ev = dev[i].wait_event(["CTRL-EVENT-REGDOM-CHANGE"], timeout=5)
  811. if ev is None:
  812. raise Exception("No regdom change event")
  813. if "alpha2=US" in ev:
  814. break
  815. dev[i].dump_monitor()
  816. if "OK" not in dev[0].request("SCAN"):
  817. raise Exception("SCAN command failed")
  818. ev = dev[0].wait_event(["CTRL-EVENT-SCAN-RESULTS"])
  819. if ev is None:
  820. raise Exception("Scan did not complete")
  821. if "OK" not in dev[0].request("SCAN freq=2412,5180,5260,5500,5600,5745"):
  822. raise Exception("SCAN command failed")
  823. ev = dev[0].wait_event(["CTRL-EVENT-SCAN-RESULTS"])
  824. if ev is None:
  825. raise Exception("Scan did not complete")
  826. out = run_tshark(os.path.join(params['logdir'], "hwsim0.pcapng"),
  827. "wlan.fc.type_subtype == 4", [ "radiotap.channel.freq" ])
  828. if out is not None:
  829. freq = out.splitlines()
  830. freq = [int(f) for f in freq]
  831. freq = list(set(freq))
  832. freq.sort()
  833. logger.info("Active scan seen on channels: " + str(freq))
  834. for f in freq:
  835. if (f >= 5260 and f <= 5320) or (f >= 5500 and f <= 5700):
  836. raise Exception("Active scan on DFS channel: %d" % f)
  837. if f in [ 2467, 2472 ]:
  838. raise Exception("Active scan on US-disallowed channel: %d" % f)
  839. def test_scan_abort(dev, apdev):
  840. """Aborting a full scan"""
  841. dev[0].request("SCAN")
  842. ev = dev[0].wait_event(["CTRL-EVENT-SCAN-STARTED"])
  843. if ev is None:
  844. raise Exception("Scan did not start")
  845. if "OK" not in dev[0].request("ABORT_SCAN"):
  846. raise Exception("ABORT_SCAN command failed")
  847. ev = dev[0].wait_event(["CTRL-EVENT-SCAN-RESULTS"], timeout=2)
  848. if ev is None:
  849. raise Exception("Scan did not terminate")
  850. def test_scan_abort_on_connect(dev, apdev):
  851. """Aborting a full scan on connection request"""
  852. hostapd.add_ap(apdev[0]['ifname'], { "ssid": "test-scan" })
  853. bssid = apdev[0]['bssid']
  854. dev[0].scan_for_bss(apdev[0]['bssid'], freq="2412")
  855. dev[0].dump_monitor()
  856. dev[0].request("SCAN")
  857. ev = dev[0].wait_event(["CTRL-EVENT-SCAN-STARTED"])
  858. if ev is None:
  859. raise Exception("Scan did not start")
  860. dev[0].connect("test-scan", key_mgmt="NONE")