test_scan.py 40 KB

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