test_scan.py 59 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476
  1. # Scanning tests
  2. # Copyright (c) 2013-2016, 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 os
  11. import subprocess
  12. import hostapd
  13. from wpasupplicant import WpaSupplicant
  14. from utils import HwsimSkip, fail_test, alloc_fail, wait_fail_trigger, parse_ie
  15. from tshark import run_tshark
  16. from test_ap_csa import switch_channel, wait_channel_switch, csa_supported
  17. def check_scan(dev, params, other_started=False, test_busy=False):
  18. if not other_started:
  19. dev.dump_monitor()
  20. id = dev.request("SCAN " + params)
  21. if "FAIL" in id:
  22. raise Exception("Failed to start scan")
  23. id = int(id)
  24. if test_busy:
  25. if "FAIL-BUSY" not in dev.request("SCAN"):
  26. raise Exception("SCAN command while already scanning not rejected")
  27. if other_started:
  28. ev = dev.wait_event(["CTRL-EVENT-SCAN-STARTED"])
  29. if ev is None:
  30. raise Exception("Other scan did not start")
  31. if "id=" + str(id) in ev:
  32. raise Exception("Own scan id unexpectedly included in start event")
  33. ev = dev.wait_event(["CTRL-EVENT-SCAN-RESULTS"])
  34. if ev is None:
  35. raise Exception("Other scan did not complete")
  36. if "id=" + str(id) in ev:
  37. raise Exception("Own scan id unexpectedly included in completed event")
  38. ev = dev.wait_event(["CTRL-EVENT-SCAN-STARTED"])
  39. if ev is None:
  40. raise Exception("Scan did not start")
  41. if "id=" + str(id) not in ev:
  42. raise Exception("Scan id not included in start event")
  43. if test_busy:
  44. if "FAIL-BUSY" not in dev.request("SCAN"):
  45. raise Exception("SCAN command while already scanning not rejected")
  46. ev = dev.wait_event(["CTRL-EVENT-SCAN-RESULTS"])
  47. if ev is None:
  48. raise Exception("Scan did not complete")
  49. if "id=" + str(id) not in ev:
  50. raise Exception("Scan id not included in completed event")
  51. def check_scan_retry(dev, params, bssid):
  52. for i in range(0, 5):
  53. check_scan(dev, "freq=2412-2462,5180 use_id=1")
  54. if int(dev.get_bss(bssid)['age']) <= 1:
  55. return
  56. raise Exception("Unexpectedly old BSS entry")
  57. @remote_compatible
  58. def test_scan(dev, apdev):
  59. """Control interface behavior on scan parameters"""
  60. hostapd.add_ap(apdev[0], { "ssid": "test-scan" })
  61. bssid = apdev[0]['bssid']
  62. logger.info("Full scan")
  63. check_scan(dev[0], "use_id=1", test_busy=True)
  64. logger.info("Limited channel scan")
  65. check_scan_retry(dev[0], "freq=2412-2462,5180 use_id=1", bssid)
  66. # wait long enough to allow next scans to be verified not to find the AP
  67. time.sleep(2)
  68. logger.info("Passive single-channel scan")
  69. check_scan(dev[0], "freq=2457 passive=1 use_id=1")
  70. logger.info("Active single-channel scan")
  71. check_scan(dev[0], "freq=2452 passive=0 use_id=1")
  72. if int(dev[0].get_bss(bssid)['age']) < 2:
  73. raise Exception("Unexpectedly updated BSS entry")
  74. logger.info("Active single-channel scan on AP's operating channel")
  75. check_scan_retry(dev[0], "freq=2412 passive=0 use_id=1", bssid)
  76. @remote_compatible
  77. def test_scan_tsf(dev, apdev):
  78. """Scan and TSF updates from Beacon/Probe Response frames"""
  79. hostapd.add_ap(apdev[0], { "ssid": "test-scan",
  80. 'beacon_int': "100" })
  81. bssid = apdev[0]['bssid']
  82. tsf = []
  83. for passive in [ 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 1, 1 ]:
  84. check_scan(dev[0], "freq=2412 passive=%d use_id=1" % passive)
  85. bss = dev[0].get_bss(bssid)
  86. if bss:
  87. tsf.append(int(bss['tsf']))
  88. logger.info("TSF: " + bss['tsf'])
  89. if tsf[-3] <= tsf[-4]:
  90. # For now, only write this in the log without failing the test case
  91. # since mac80211_hwsim does not yet update the Timestamp field in
  92. # Probe Response frames.
  93. logger.info("Probe Response did not update TSF")
  94. #raise Exception("Probe Response did not update TSF")
  95. if tsf[-1] <= tsf[-3]:
  96. raise Exception("Beacon did not update TSF")
  97. if 0 in tsf:
  98. raise Exception("0 TSF reported")
  99. @remote_compatible
  100. def test_scan_only(dev, apdev):
  101. """Control interface behavior on scan parameters with type=only"""
  102. hostapd.add_ap(apdev[0], { "ssid": "test-scan" })
  103. bssid = apdev[0]['bssid']
  104. logger.info("Full scan")
  105. check_scan(dev[0], "type=only use_id=1")
  106. logger.info("Limited channel scan")
  107. check_scan_retry(dev[0], "type=only freq=2412-2462,5180 use_id=1", bssid)
  108. # wait long enough to allow next scans to be verified not to find the AP
  109. time.sleep(2)
  110. logger.info("Passive single-channel scan")
  111. check_scan(dev[0], "type=only freq=2457 passive=1 use_id=1")
  112. logger.info("Active single-channel scan")
  113. check_scan(dev[0], "type=only freq=2452 passive=0 use_id=1")
  114. if int(dev[0].get_bss(bssid)['age']) < 2:
  115. raise Exception("Unexpectedly updated BSS entry")
  116. logger.info("Active single-channel scan on AP's operating channel")
  117. check_scan_retry(dev[0], "type=only freq=2412 passive=0 use_id=1", bssid)
  118. @remote_compatible
  119. def test_scan_external_trigger(dev, apdev):
  120. """Avoid operations during externally triggered scan"""
  121. hostapd.add_ap(apdev[0], { "ssid": "test-scan" })
  122. bssid = apdev[0]['bssid']
  123. dev[0].cmd_execute(['iw', dev[0].ifname, 'scan', 'trigger'])
  124. check_scan(dev[0], "use_id=1", other_started=True)
  125. def test_scan_bss_expiration_count(dev, apdev):
  126. """BSS entry expiration based on scan results without match"""
  127. if "FAIL" not in dev[0].request("BSS_EXPIRE_COUNT 0"):
  128. raise Exception("Invalid BSS_EXPIRE_COUNT accepted")
  129. if "OK" not in dev[0].request("BSS_EXPIRE_COUNT 2"):
  130. raise Exception("BSS_EXPIRE_COUNT failed")
  131. hapd = hostapd.add_ap(apdev[0], { "ssid": "test-scan" })
  132. bssid = apdev[0]['bssid']
  133. dev[0].scan(freq="2412", only_new=True)
  134. if bssid not in dev[0].request("SCAN_RESULTS"):
  135. raise Exception("BSS not found in initial scan")
  136. hapd.request("DISABLE")
  137. dev[0].scan(freq="2412", only_new=True)
  138. if bssid not in dev[0].request("SCAN_RESULTS"):
  139. raise Exception("BSS not found in first scan without match")
  140. dev[0].scan(freq="2412", only_new=True)
  141. if bssid in dev[0].request("SCAN_RESULTS"):
  142. raise Exception("BSS found after two scans without match")
  143. @remote_compatible
  144. def test_scan_bss_expiration_age(dev, apdev):
  145. """BSS entry expiration based on age"""
  146. try:
  147. if "FAIL" not in dev[0].request("BSS_EXPIRE_AGE COUNT 9"):
  148. raise Exception("Invalid BSS_EXPIRE_AGE accepted")
  149. if "OK" not in dev[0].request("BSS_EXPIRE_AGE 10"):
  150. raise Exception("BSS_EXPIRE_AGE failed")
  151. hapd = hostapd.add_ap(apdev[0], { "ssid": "test-scan" })
  152. bssid = apdev[0]['bssid']
  153. # Allow couple more retries to avoid reporting errors during heavy load
  154. for i in range(5):
  155. dev[0].scan(freq="2412")
  156. if bssid in dev[0].request("SCAN_RESULTS"):
  157. break
  158. if bssid not in dev[0].request("SCAN_RESULTS"):
  159. raise Exception("BSS not found in initial scan")
  160. hapd.request("DISABLE")
  161. logger.info("Waiting for BSS entry to expire")
  162. time.sleep(7)
  163. if bssid not in dev[0].request("SCAN_RESULTS"):
  164. raise Exception("BSS expired too quickly")
  165. ev = dev[0].wait_event(["CTRL-EVENT-BSS-REMOVED"], timeout=15)
  166. if ev is None:
  167. raise Exception("BSS entry expiration timed out")
  168. if bssid in dev[0].request("SCAN_RESULTS"):
  169. raise Exception("BSS not removed after expiration time")
  170. finally:
  171. dev[0].request("BSS_EXPIRE_AGE 180")
  172. @remote_compatible
  173. def test_scan_filter(dev, apdev):
  174. """Filter scan results based on SSID"""
  175. try:
  176. if "OK" not in dev[0].request("SET filter_ssids 1"):
  177. raise Exception("SET failed")
  178. id = dev[0].connect("test-scan", key_mgmt="NONE", only_add_network=True)
  179. hostapd.add_ap(apdev[0], { "ssid": "test-scan" })
  180. bssid = apdev[0]['bssid']
  181. hostapd.add_ap(apdev[1], { "ssid": "test-scan2" })
  182. bssid2 = apdev[1]['bssid']
  183. dev[0].scan(freq="2412", only_new=True)
  184. if bssid not in dev[0].request("SCAN_RESULTS"):
  185. raise Exception("BSS not found in scan results")
  186. if bssid2 in dev[0].request("SCAN_RESULTS"):
  187. raise Exception("Unexpected BSS found in scan results")
  188. dev[0].set_network_quoted(id, "ssid", "")
  189. dev[0].scan(freq="2412")
  190. id2 = dev[0].connect("test", key_mgmt="NONE", only_add_network=True)
  191. dev[0].scan(freq="2412")
  192. finally:
  193. dev[0].request("SET filter_ssids 0")
  194. @remote_compatible
  195. def test_scan_int(dev, apdev):
  196. """scan interval configuration"""
  197. try:
  198. if "FAIL" not in dev[0].request("SCAN_INTERVAL -1"):
  199. raise Exception("Accepted invalid scan interval")
  200. if "OK" not in dev[0].request("SCAN_INTERVAL 1"):
  201. raise Exception("Failed to set scan interval")
  202. dev[0].connect("not-used", key_mgmt="NONE", scan_freq="2412",
  203. wait_connect=False)
  204. times = {}
  205. for i in range(0, 3):
  206. logger.info("Waiting for scan to start")
  207. start = os.times()[4]
  208. ev = dev[0].wait_event(["CTRL-EVENT-SCAN-STARTED"], timeout=5)
  209. if ev is None:
  210. raise Exception("did not start a scan")
  211. stop = os.times()[4]
  212. times[i] = stop - start
  213. logger.info("Waiting for scan to complete")
  214. ev = dev[0].wait_event(["CTRL-EVENT-SCAN-RESULTS"], 10)
  215. if ev is None:
  216. raise Exception("did not complete a scan")
  217. logger.info("times=" + str(times))
  218. if times[0] > 1 or times[1] < 0.5 or times[1] > 1.5 or times[2] < 0.5 or times[2] > 1.5:
  219. raise Exception("Unexpected scan timing: " + str(times))
  220. finally:
  221. dev[0].request("SCAN_INTERVAL 5")
  222. def test_scan_bss_operations(dev, apdev):
  223. """Control interface behavior on BSS parameters"""
  224. hostapd.add_ap(apdev[0], { "ssid": "test-scan" })
  225. bssid = apdev[0]['bssid']
  226. hostapd.add_ap(apdev[1], { "ssid": "test2-scan" })
  227. bssid2 = apdev[1]['bssid']
  228. dev[0].scan(freq="2412")
  229. dev[0].scan(freq="2412")
  230. dev[0].scan(freq="2412")
  231. id1 = dev[0].request("BSS FIRST MASK=0x1").splitlines()[0].split('=')[1]
  232. id2 = dev[0].request("BSS LAST MASK=0x1").splitlines()[0].split('=')[1]
  233. res = dev[0].request("BSS RANGE=ALL MASK=0x20001")
  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 "====" not in res:
  239. raise Exception("Missing delim")
  240. if "####" not in res:
  241. raise Exception("Missing end")
  242. res = dev[0].request("BSS RANGE=ALL MASK=0")
  243. if "id=" + id1 not in res:
  244. raise Exception("Missing BSS " + id1)
  245. if "id=" + id2 not in res:
  246. raise Exception("Missing BSS " + id2)
  247. if "====" in res:
  248. raise Exception("Unexpected delim")
  249. if "####" in res:
  250. raise Exception("Unexpected end delim")
  251. res = dev[0].request("BSS RANGE=ALL MASK=0x1").splitlines()
  252. if len(res) != 2:
  253. raise Exception("Unexpected result: " + str(res))
  254. res = dev[0].request("BSS FIRST MASK=0x1")
  255. if "id=" + id1 not in res:
  256. raise Exception("Unexpected result: " + res)
  257. res = dev[0].request("BSS LAST MASK=0x1")
  258. if "id=" + id2 not in res:
  259. raise Exception("Unexpected result: " + res)
  260. res = dev[0].request("BSS ID-" + id1 + " MASK=0x1")
  261. if "id=" + id1 not in res:
  262. raise Exception("Unexpected result: " + res)
  263. res = dev[0].request("BSS NEXT-" + id1 + " MASK=0x1")
  264. if "id=" + id2 not in res:
  265. raise Exception("Unexpected result: " + res)
  266. res = dev[0].request("BSS NEXT-" + id2 + " MASK=0x1")
  267. if "id=" in res:
  268. raise Exception("Unexpected result: " + res)
  269. if len(dev[0].request("BSS RANGE=" + id2 + " MASK=0x1").splitlines()) != 0:
  270. raise Exception("Unexpected RANGE=1 result")
  271. if len(dev[0].request("BSS RANGE=" + id1 + "- MASK=0x1").splitlines()) != 2:
  272. raise Exception("Unexpected RANGE=0- result")
  273. if len(dev[0].request("BSS RANGE=-" + id2 + " MASK=0x1").splitlines()) != 2:
  274. raise Exception("Unexpected RANGE=-1 result")
  275. if len(dev[0].request("BSS RANGE=" + id1 + "-" + id2 + " MASK=0x1").splitlines()) != 2:
  276. raise Exception("Unexpected RANGE=0-1 result")
  277. if len(dev[0].request("BSS RANGE=" + id2 + "-" + id2 + " MASK=0x1").splitlines()) != 1:
  278. raise Exception("Unexpected RANGE=1-1 result")
  279. if len(dev[0].request("BSS RANGE=" + str(int(id2) + 1) + "-" + str(int(id2) + 10) + " MASK=0x1").splitlines()) != 0:
  280. raise Exception("Unexpected RANGE=2-10 result")
  281. if len(dev[0].request("BSS RANGE=0-" + str(int(id2) + 10) + " MASK=0x1").splitlines()) != 2:
  282. raise Exception("Unexpected RANGE=0-10 result")
  283. if len(dev[0].request("BSS RANGE=" + id1 + "-" + id1 + " MASK=0x1").splitlines()) != 1:
  284. raise Exception("Unexpected RANGE=0-0 result")
  285. res = dev[0].request("BSS p2p_dev_addr=FOO")
  286. if "FAIL" in res or "id=" in res:
  287. raise Exception("Unexpected result: " + res)
  288. res = dev[0].request("BSS p2p_dev_addr=00:11:22:33:44:55")
  289. if "FAIL" in res or "id=" in res:
  290. raise Exception("Unexpected result: " + res)
  291. dev[0].request("BSS_FLUSH 1000")
  292. res = dev[0].request("BSS RANGE=ALL MASK=0x1").splitlines()
  293. if len(res) != 2:
  294. raise Exception("Unexpected result after BSS_FLUSH 1000")
  295. dev[0].request("BSS_FLUSH 0")
  296. res = dev[0].request("BSS RANGE=ALL MASK=0x1").splitlines()
  297. if len(res) != 0:
  298. raise Exception("Unexpected result after BSS_FLUSH 0")
  299. @remote_compatible
  300. def test_scan_and_interface_disabled(dev, apdev):
  301. """Scan operation when interface gets disabled"""
  302. try:
  303. dev[0].request("SCAN")
  304. ev = dev[0].wait_event(["CTRL-EVENT-SCAN-STARTED"])
  305. if ev is None:
  306. raise Exception("Scan did not start")
  307. dev[0].request("DRIVER_EVENT INTERFACE_DISABLED")
  308. ev = dev[0].wait_event(["CTRL-EVENT-SCAN-RESULTS"], timeout=7)
  309. if ev is not None:
  310. raise Exception("Scan completed unexpectedly")
  311. # verify that scan is rejected
  312. if "FAIL" not in dev[0].request("SCAN"):
  313. raise Exception("New scan request was accepted unexpectedly")
  314. dev[0].request("DRIVER_EVENT INTERFACE_ENABLED")
  315. dev[0].scan(freq="2412")
  316. finally:
  317. dev[0].request("DRIVER_EVENT INTERFACE_ENABLED")
  318. @remote_compatible
  319. def test_scan_for_auth(dev, apdev):
  320. """cfg80211 workaround with scan-for-auth"""
  321. hapd = hostapd.add_ap(apdev[0], { "ssid": "open" })
  322. dev[0].scan_for_bss(apdev[0]['bssid'], freq="2412")
  323. # Block sme-connect radio work with an external radio work item, so that
  324. # SELECT_NETWORK can decide to use fast associate without a new scan while
  325. # cfg80211 still has the matching BSS entry, but the actual connection is
  326. # not yet started.
  327. id = dev[0].request("RADIO_WORK add block-work")
  328. ev = dev[0].wait_event(["EXT-RADIO-WORK-START"])
  329. if ev is None:
  330. raise Exception("Timeout while waiting radio work to start")
  331. dev[0].connect("open", key_mgmt="NONE", scan_freq="2412",
  332. wait_connect=False)
  333. dev[0].dump_monitor()
  334. # Clear cfg80211 BSS table.
  335. res, data = dev[0].cmd_execute(['iw', dev[0].ifname, 'scan', 'trigger',
  336. 'freq', '2457', 'flush'])
  337. if res != 0:
  338. raise HwsimSkip("iw scan trigger flush not supported")
  339. ev = dev[0].wait_event(["CTRL-EVENT-SCAN-RESULTS"], 5)
  340. if ev is None:
  341. raise Exception("External flush scan timed out")
  342. # Release blocking radio work to allow connection to go through with the
  343. # cfg80211 BSS entry missing.
  344. dev[0].request("RADIO_WORK done " + id)
  345. dev[0].wait_connected(timeout=15)
  346. @remote_compatible
  347. def test_scan_for_auth_fail(dev, apdev):
  348. """cfg80211 workaround with scan-for-auth failing"""
  349. hapd = hostapd.add_ap(apdev[0], { "ssid": "open" })
  350. dev[0].scan_for_bss(apdev[0]['bssid'], freq="2412")
  351. # Block sme-connect radio work with an external radio work item, so that
  352. # SELECT_NETWORK can decide to use fast associate without a new scan while
  353. # cfg80211 still has the matching BSS entry, but the actual connection is
  354. # not yet started.
  355. id = dev[0].request("RADIO_WORK add block-work")
  356. ev = dev[0].wait_event(["EXT-RADIO-WORK-START"])
  357. if ev is None:
  358. raise Exception("Timeout while waiting radio work to start")
  359. dev[0].connect("open", key_mgmt="NONE", scan_freq="2412",
  360. wait_connect=False)
  361. dev[0].dump_monitor()
  362. hapd.disable()
  363. # Clear cfg80211 BSS table.
  364. res, data = dev[0].cmd_execute(['iw', dev[0].ifname, 'scan', 'trigger',
  365. 'freq', '2457', 'flush'])
  366. if res != 0:
  367. raise HwsimSkip("iw scan trigger flush not supported")
  368. ev = dev[0].wait_event(["CTRL-EVENT-SCAN-RESULTS"], 5)
  369. if ev is None:
  370. raise Exception("External flush scan timed out")
  371. # Release blocking radio work to allow connection to go through with the
  372. # cfg80211 BSS entry missing.
  373. dev[0].request("RADIO_WORK done " + id)
  374. ev = dev[0].wait_event(["CTRL-EVENT-SCAN-RESULTS",
  375. "CTRL-EVENT-CONNECTED"], 15)
  376. if ev is None:
  377. raise Exception("Scan event missing")
  378. if "CTRL-EVENT-CONNECTED" in ev:
  379. raise Exception("Unexpected connection")
  380. dev[0].request("DISCONNECT")
  381. @remote_compatible
  382. def test_scan_for_auth_wep(dev, apdev):
  383. """cfg80211 scan-for-auth workaround with WEP keys"""
  384. dev[0].flush_scan_cache()
  385. hapd = hostapd.add_ap(apdev[0],
  386. { "ssid": "wep", "wep_key0": '"abcde"',
  387. "auth_algs": "2" })
  388. dev[0].scan_for_bss(apdev[0]['bssid'], freq="2412")
  389. # Block sme-connect radio work with an external radio work item, so that
  390. # SELECT_NETWORK can decide to use fast associate without a new scan while
  391. # cfg80211 still has the matching BSS entry, but the actual connection is
  392. # not yet started.
  393. id = dev[0].request("RADIO_WORK add block-work")
  394. ev = dev[0].wait_event(["EXT-RADIO-WORK-START"])
  395. if ev is None:
  396. raise Exception("Timeout while waiting radio work to start")
  397. dev[0].connect("wep", key_mgmt="NONE", wep_key0='"abcde"',
  398. auth_alg="SHARED", scan_freq="2412", wait_connect=False)
  399. dev[0].dump_monitor()
  400. # Clear cfg80211 BSS table.
  401. res, data = dev[0].cmd_execute(['iw', dev[0].ifname, 'scan', 'trigger',
  402. 'freq', '2457', 'flush'])
  403. if res != 0:
  404. raise HwsimSkip("iw scan trigger flush not supported")
  405. ev = dev[0].wait_event(["CTRL-EVENT-SCAN-RESULTS"], 5)
  406. if ev is None:
  407. raise Exception("External flush scan timed out")
  408. # Release blocking radio work to allow connection to go through with the
  409. # cfg80211 BSS entry missing.
  410. dev[0].request("RADIO_WORK done " + id)
  411. dev[0].wait_connected(timeout=15)
  412. @remote_compatible
  413. def test_scan_hidden(dev, apdev):
  414. """Control interface behavior on scan parameters"""
  415. hapd = hostapd.add_ap(apdev[0], { "ssid": "test-scan",
  416. "ignore_broadcast_ssid": "1" })
  417. bssid = apdev[0]['bssid']
  418. check_scan(dev[0], "freq=2412 use_id=1")
  419. if "test-scan" in dev[0].request("SCAN_RESULTS"):
  420. raise Exception("BSS unexpectedly found in initial scan")
  421. id1 = dev[0].connect("foo", key_mgmt="NONE", scan_ssid="1",
  422. only_add_network=True)
  423. id2 = dev[0].connect("test-scan", key_mgmt="NONE", scan_ssid="1",
  424. only_add_network=True)
  425. id3 = dev[0].connect("bar", key_mgmt="NONE", only_add_network=True)
  426. check_scan(dev[0], "freq=2412 use_id=1")
  427. if "test-scan" in dev[0].request("SCAN_RESULTS"):
  428. raise Exception("BSS unexpectedly found in scan")
  429. # Allow multiple attempts to be more robust under heavy CPU load that can
  430. # result in Probe Response frames getting sent only after the station has
  431. # already stopped waiting for the response on the channel.
  432. found = False
  433. for i in range(10):
  434. check_scan(dev[0], "scan_id=%d,%d,%d freq=2412 use_id=1" % (id1, id2, id3))
  435. if "test-scan" in dev[0].request("SCAN_RESULTS"):
  436. found = True
  437. break
  438. if not found:
  439. raise Exception("BSS not found in scan")
  440. 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"):
  441. raise Exception("Too many scan_id values accepted")
  442. # Duplicate SSID removal
  443. check_scan(dev[0], "scan_id=%d,%d,%d freq=2412 use_id=1" % (id1, id1, id2))
  444. dev[0].request("REMOVE_NETWORK all")
  445. hapd.disable()
  446. dev[0].flush_scan_cache(freq=2432)
  447. dev[0].flush_scan_cache()
  448. def test_scan_and_bss_entry_removed(dev, apdev):
  449. """Last scan result and connect work processing on BSS entry update"""
  450. hapd = hostapd.add_ap(apdev[0], { "ssid": "open",
  451. "eap_server": "1",
  452. "wps_state": "2" })
  453. bssid = apdev[0]['bssid']
  454. wpas = WpaSupplicant(global_iface='/tmp/wpas-wlan5')
  455. wpas.interface_add("wlan5", drv_params="force_connect_cmd=1")
  456. # Add a BSS entry
  457. dev[0].scan_for_bss(bssid, freq="2412")
  458. wpas.scan_for_bss(bssid, freq="2412")
  459. # Start a connect radio work with a blocking entry preventing this from
  460. # proceeding; this stores a pointer to the selected BSS entry.
  461. id = dev[0].request("RADIO_WORK add block-work")
  462. w_id = wpas.request("RADIO_WORK add block-work")
  463. dev[0].wait_event(["EXT-RADIO-WORK-START"], timeout=1)
  464. wpas.wait_event(["EXT-RADIO-WORK-START"], timeout=1)
  465. nid = dev[0].connect("open", key_mgmt="NONE", scan_freq="2412",
  466. wait_connect=False)
  467. w_nid = wpas.connect("open", key_mgmt="NONE", scan_freq="2412",
  468. wait_connect=False)
  469. time.sleep(0.1)
  470. # Remove the BSS entry
  471. dev[0].request("BSS_FLUSH 0")
  472. wpas.request("BSS_FLUSH 0")
  473. # Allow the connect radio work to continue. The bss entry stored in the
  474. # pending connect work is now stale. This will result in the connection
  475. # attempt failing since the BSS entry does not exist.
  476. dev[0].request("RADIO_WORK done " + id)
  477. wpas.request("RADIO_WORK done " + w_id)
  478. ev = dev[0].wait_event(["CTRL-EVENT-CONNECTED"], timeout=1)
  479. if ev is not None:
  480. raise Exception("Unexpected connection")
  481. dev[0].remove_network(nid)
  482. ev = wpas.wait_event(["CTRL-EVENT-CONNECTED"], timeout=1)
  483. if ev is not None:
  484. raise Exception("Unexpected connection")
  485. wpas.remove_network(w_nid)
  486. time.sleep(0.5)
  487. dev[0].request("BSS_FLUSH 0")
  488. wpas.request("BSS_FLUSH 0")
  489. # Add a BSS entry
  490. dev[0].scan_for_bss(bssid, freq="2412")
  491. wpas.scan_for_bss(bssid, freq="2412")
  492. # Start a connect radio work with a blocking entry preventing this from
  493. # proceeding; this stores a pointer to the selected BSS entry.
  494. id = dev[0].request("RADIO_WORK add block-work")
  495. w_id = wpas.request("RADIO_WORK add block-work")
  496. dev[0].wait_event(["EXT-RADIO-WORK-START"], timeout=1)
  497. wpas.wait_event(["EXT-RADIO-WORK-START"], timeout=1)
  498. # Schedule a connection based on the current BSS entry.
  499. dev[0].connect("open", key_mgmt="NONE", scan_freq="2412",
  500. wait_connect=False)
  501. wpas.connect("open", key_mgmt="NONE", scan_freq="2412",
  502. wait_connect=False)
  503. # Update scan results with results that have longer set of IEs so that new
  504. # memory needs to be allocated for the BSS entry.
  505. hapd.request("WPS_PBC")
  506. time.sleep(0.1)
  507. subprocess.call(['iw', dev[0].ifname, 'scan', 'trigger', 'freq', '2412'])
  508. subprocess.call(['iw', wpas.ifname, 'scan', 'trigger', 'freq', '2412'])
  509. time.sleep(0.1)
  510. # Allow the connect radio work to continue. The bss entry stored in the
  511. # pending connect work becomes stale during the scan and it must have been
  512. # updated for the connection to work.
  513. dev[0].request("RADIO_WORK done " + id)
  514. wpas.request("RADIO_WORK done " + w_id)
  515. dev[0].wait_connected(timeout=15, error="No connection (sme-connect)")
  516. wpas.wait_connected(timeout=15, error="No connection (connect)")
  517. dev[0].request("DISCONNECT")
  518. wpas.request("DISCONNECT")
  519. dev[0].flush_scan_cache()
  520. wpas.flush_scan_cache()
  521. @remote_compatible
  522. def test_scan_reqs_with_non_scan_radio_work(dev, apdev):
  523. """SCAN commands while non-scan radio_work is in progress"""
  524. id = dev[0].request("RADIO_WORK add test-work-a")
  525. ev = dev[0].wait_event(["EXT-RADIO-WORK-START"])
  526. if ev is None:
  527. raise Exception("Timeout while waiting radio work to start")
  528. if "OK" not in dev[0].request("SCAN"):
  529. raise Exception("SCAN failed")
  530. if "FAIL-BUSY" not in dev[0].request("SCAN"):
  531. raise Exception("SCAN accepted while one is already pending")
  532. if "FAIL-BUSY" not in dev[0].request("SCAN"):
  533. raise Exception("SCAN accepted while one is already pending")
  534. res = dev[0].request("RADIO_WORK show").splitlines()
  535. count = 0
  536. for l in res:
  537. if "scan" in l:
  538. count += 1
  539. if count != 1:
  540. logger.info(res)
  541. raise Exception("Unexpected number of scan radio work items")
  542. dev[0].dump_monitor()
  543. dev[0].request("RADIO_WORK done " + id)
  544. ev = dev[0].wait_event(["CTRL-EVENT-SCAN-STARTED"], timeout=5)
  545. if ev is None:
  546. raise Exception("Scan did not start")
  547. if "FAIL-BUSY" not in dev[0].request("SCAN"):
  548. raise Exception("SCAN accepted while one is already in progress")
  549. ev = dev[0].wait_event(["CTRL-EVENT-SCAN-RESULTS"], timeout=10)
  550. if ev is None:
  551. raise Exception("Scan did not complete")
  552. ev = dev[0].wait_event(["CTRL-EVENT-SCAN-STARTED"], timeout=0.2)
  553. if ev is not None:
  554. raise Exception("Unexpected scan started")
  555. def test_scan_setband(dev, apdev):
  556. """Band selection for scan operations"""
  557. try:
  558. hapd = None
  559. hapd2 = None
  560. params = { "ssid": "test-setband",
  561. "hw_mode": "a",
  562. "channel": "36",
  563. "country_code": "US" }
  564. hapd = hostapd.add_ap(apdev[0], params)
  565. bssid = apdev[0]['bssid']
  566. params = { "ssid": "test-setband",
  567. "hw_mode": "g",
  568. "channel": "1" }
  569. hapd2 = hostapd.add_ap(apdev[1], params)
  570. bssid2 = apdev[1]['bssid']
  571. if "FAIL" not in dev[0].request("SET setband FOO"):
  572. raise Exception("Invalid set setband accepted")
  573. if "OK" not in dev[0].request("SET setband AUTO"):
  574. raise Exception("Failed to set setband")
  575. if "OK" not in dev[1].request("SET setband 5G"):
  576. raise Exception("Failed to set setband")
  577. if "OK" not in dev[2].request("SET setband 2G"):
  578. raise Exception("Failed to set setband")
  579. # Allow a retry to avoid reporting errors during heavy load
  580. for j in range(5):
  581. for i in range(3):
  582. dev[i].request("SCAN only_new=1")
  583. for i in range(3):
  584. ev = dev[i].wait_event(["CTRL-EVENT-SCAN-RESULTS"], 15)
  585. if ev is None:
  586. raise Exception("Scan timed out")
  587. res0 = dev[0].request("SCAN_RESULTS")
  588. res1 = dev[1].request("SCAN_RESULTS")
  589. res2 = dev[2].request("SCAN_RESULTS")
  590. if bssid in res0 and bssid2 in res0 and bssid in res1 and bssid2 in res2:
  591. break
  592. res = dev[0].request("SCAN_RESULTS")
  593. if bssid not in res or bssid2 not in res:
  594. raise Exception("Missing scan result(0)")
  595. res = dev[1].request("SCAN_RESULTS")
  596. if bssid not in res:
  597. raise Exception("Missing scan result(1)")
  598. if bssid2 in res:
  599. raise Exception("Unexpected scan result(1)")
  600. res = dev[2].request("SCAN_RESULTS")
  601. if bssid2 not in res:
  602. raise Exception("Missing scan result(2)")
  603. if bssid in res:
  604. raise Exception("Unexpected scan result(2)")
  605. finally:
  606. if hapd:
  607. hapd.request("DISABLE")
  608. if hapd2:
  609. hapd2.request("DISABLE")
  610. subprocess.call(['iw', 'reg', 'set', '00'])
  611. for i in range(3):
  612. dev[i].request("SET setband AUTO")
  613. dev[i].flush_scan_cache()
  614. @remote_compatible
  615. def test_scan_hidden_many(dev, apdev):
  616. """scan_ssid=1 with large number of profile with hidden SSID"""
  617. try:
  618. _test_scan_hidden_many(dev, apdev)
  619. finally:
  620. dev[0].flush_scan_cache(freq=2432)
  621. dev[0].flush_scan_cache()
  622. dev[0].request("SCAN_INTERVAL 5")
  623. def _test_scan_hidden_many(dev, apdev):
  624. hapd = hostapd.add_ap(apdev[0], { "ssid": "test-scan-ssid",
  625. "ignore_broadcast_ssid": "1" })
  626. bssid = apdev[0]['bssid']
  627. dev[0].request("SCAN_INTERVAL 1")
  628. for i in range(5):
  629. id = dev[0].add_network()
  630. dev[0].set_network_quoted(id, "ssid", "foo")
  631. dev[0].set_network(id, "key_mgmt", "NONE")
  632. dev[0].set_network(id, "disabled", "0")
  633. dev[0].set_network(id, "scan_freq", "2412")
  634. dev[0].set_network(id, "scan_ssid", "1")
  635. dev[0].set_network_quoted(id, "ssid", "test-scan-ssid")
  636. dev[0].set_network(id, "key_mgmt", "NONE")
  637. dev[0].set_network(id, "disabled", "0")
  638. dev[0].set_network(id, "scan_freq", "2412")
  639. dev[0].set_network(id, "scan_ssid", "1")
  640. for i in range(5):
  641. id = dev[0].add_network()
  642. dev[0].set_network_quoted(id, "ssid", "foo")
  643. dev[0].set_network(id, "key_mgmt", "NONE")
  644. dev[0].set_network(id, "disabled", "0")
  645. dev[0].set_network(id, "scan_freq", "2412")
  646. dev[0].set_network(id, "scan_ssid", "1")
  647. dev[0].request("REASSOCIATE")
  648. dev[0].wait_connected(timeout=30)
  649. dev[0].request("REMOVE_NETWORK all")
  650. hapd.disable()
  651. def test_scan_random_mac(dev, apdev, params):
  652. """Random MAC address in scans"""
  653. try:
  654. _test_scan_random_mac(dev, apdev, params)
  655. finally:
  656. dev[0].request("MAC_RAND_SCAN all enable=0")
  657. def _test_scan_random_mac(dev, apdev, params):
  658. hostapd.add_ap(apdev[0], { "ssid": "test-scan" })
  659. bssid = apdev[0]['bssid']
  660. tests = [ "",
  661. "addr=foo",
  662. "mask=foo",
  663. "enable=1",
  664. "all enable=1 mask=00:11:22:33:44:55",
  665. "all enable=1 addr=00:11:22:33:44:55",
  666. "all enable=1 addr=01:11:22:33:44:55 mask=ff:ff:ff:ff:ff:ff",
  667. "all enable=1 addr=00:11:22:33:44:55 mask=fe:ff:ff:ff:ff:ff",
  668. "enable=2 scan sched pno all",
  669. "pno enable=1",
  670. "all enable=2",
  671. "foo" ]
  672. for args in tests:
  673. if "FAIL" not in dev[0].request("MAC_RAND_SCAN " + args):
  674. raise Exception("Invalid MAC_RAND_SCAN accepted: " + args)
  675. if dev[0].get_driver_status_field('capa.mac_addr_rand_scan_supported') != '1':
  676. raise HwsimSkip("Driver does not support random MAC address for scanning")
  677. tests = [ "all enable=1",
  678. "all enable=1 addr=f2:11:22:33:44:55 mask=ff:ff:ff:ff:ff:ff",
  679. "all enable=1 addr=f2:11:33:00:00:00 mask=ff:ff:ff:00:00:00" ]
  680. for args in tests:
  681. dev[0].request("MAC_RAND_SCAN " + args)
  682. dev[0].scan_for_bss(bssid, freq=2412, force_scan=True)
  683. out = run_tshark(os.path.join(params['logdir'], "hwsim0.pcapng"),
  684. "wlan.fc.type_subtype == 4", ["wlan.ta" ])
  685. if out is not None:
  686. addr = out.splitlines()
  687. logger.info("Probe Request frames seen from: " + str(addr))
  688. if dev[0].own_addr() in addr:
  689. raise Exception("Real address used to transmit Probe Request frame")
  690. if "f2:11:22:33:44:55" not in addr:
  691. raise Exception("Fully configured random address not seen")
  692. found = False
  693. for a in addr:
  694. if a.startswith('f2:11:33'):
  695. found = True
  696. break
  697. if not found:
  698. raise Exception("Fixed OUI random address not seen")
  699. def test_scan_random_mac_connected(dev, apdev, params):
  700. """Random MAC address in scans while connected"""
  701. try:
  702. _test_scan_random_mac_connected(dev, apdev, params)
  703. finally:
  704. dev[0].request("MAC_RAND_SCAN all enable=0")
  705. def _test_scan_random_mac_connected(dev, apdev, params):
  706. hostapd.add_ap(apdev[0], { "ssid": "test-scan" })
  707. bssid = apdev[0]['bssid']
  708. if dev[0].get_driver_status_field('capa.mac_addr_rand_scan_supported') != '1':
  709. raise HwsimSkip("Driver does not support random MAC address for scanning")
  710. dev[0].connect("test-scan", key_mgmt="NONE", scan_freq="2412")
  711. hostapd.add_ap(apdev[1], { "ssid": "test-scan-2", "channel": "11" })
  712. bssid1 = apdev[1]['bssid']
  713. # Verify that scanning can be completed while connected even if that means
  714. # disabling use of random MAC address.
  715. dev[0].request("MAC_RAND_SCAN all enable=1")
  716. dev[0].scan_for_bss(bssid1, freq=2462, force_scan=True)
  717. @remote_compatible
  718. def test_scan_trigger_failure(dev, apdev):
  719. """Scan trigger to the driver failing"""
  720. if dev[0].get_status_field('wpa_state') == "SCANNING":
  721. raise Exception("wpa_state was already SCANNING")
  722. hostapd.add_ap(apdev[0], { "ssid": "test-scan" })
  723. bssid = apdev[0]['bssid']
  724. if "OK" not in dev[0].request("SET test_failure 1"):
  725. raise Exception("Failed to set test_failure")
  726. if "OK" not in dev[0].request("SCAN"):
  727. raise Exception("SCAN command failed")
  728. ev = dev[0].wait_event(["CTRL-EVENT-SCAN-FAILED"], timeout=10)
  729. if ev is None:
  730. raise Exception("Did not receive CTRL-EVENT-SCAN-FAILED event")
  731. if "retry=1" in ev:
  732. raise Exception("Unexpected scan retry indicated")
  733. if dev[0].get_status_field('wpa_state') == "SCANNING":
  734. raise Exception("wpa_state SCANNING not cleared")
  735. id = dev[0].connect("test-scan", key_mgmt="NONE", scan_freq="2412",
  736. only_add_network=True)
  737. dev[0].select_network(id)
  738. ev = dev[0].wait_event(["CTRL-EVENT-SCAN-FAILED"], timeout=10)
  739. if ev is None:
  740. raise Exception("Did not receive CTRL-EVENT-SCAN-FAILED event")
  741. if "retry=1" not in ev:
  742. raise Exception("No scan retry indicated for connection")
  743. if dev[0].get_status_field('wpa_state') == "SCANNING":
  744. raise Exception("wpa_state SCANNING not cleared")
  745. dev[0].request("SET test_failure 0")
  746. dev[0].wait_connected()
  747. dev[0].request("SET test_failure 1")
  748. if "OK" not in dev[0].request("SCAN"):
  749. raise Exception("SCAN command failed")
  750. ev = dev[0].wait_event(["CTRL-EVENT-SCAN-FAILED"], timeout=10)
  751. if ev is None:
  752. raise Exception("Did not receive CTRL-EVENT-SCAN-FAILED event")
  753. if "retry=1" in ev:
  754. raise Exception("Unexpected scan retry indicated")
  755. if dev[0].get_status_field('wpa_state') != "COMPLETED":
  756. raise Exception("wpa_state COMPLETED not restored")
  757. dev[0].request("SET test_failure 0")
  758. @remote_compatible
  759. def test_scan_specify_ssid(dev, apdev):
  760. """Control interface behavior on scan SSID parameter"""
  761. dev[0].flush_scan_cache()
  762. hapd = hostapd.add_ap(apdev[0], { "ssid": "test-hidden",
  763. "ignore_broadcast_ssid": "1" })
  764. bssid = apdev[0]['bssid']
  765. check_scan(dev[0], "freq=2412 use_id=1 ssid 414243")
  766. bss = dev[0].get_bss(bssid)
  767. if bss is not None and bss['ssid'] == 'test-hidden':
  768. raise Exception("BSS entry for hidden AP present unexpectedly")
  769. # Allow couple more retries to avoid reporting errors during heavy load
  770. for i in range(5):
  771. check_scan(dev[0], "freq=2412 ssid 414243 ssid 746573742d68696464656e ssid 616263313233 use_id=1")
  772. bss = dev[0].get_bss(bssid)
  773. if bss and 'test-hidden' in dev[0].request("SCAN_RESULTS"):
  774. break
  775. if bss is None:
  776. raise Exception("BSS entry for hidden AP not found")
  777. if 'test-hidden' not in dev[0].request("SCAN_RESULTS"):
  778. raise Exception("Expected SSID not included in the scan results")
  779. hapd.disable()
  780. dev[0].flush_scan_cache(freq=2432)
  781. dev[0].flush_scan_cache()
  782. if "FAIL" not in dev[0].request("SCAN ssid foo"):
  783. raise Exception("Invalid SCAN command accepted")
  784. @remote_compatible
  785. def test_scan_ap_scan_2_ap_mode(dev, apdev):
  786. """AP_SCAN 2 AP mode and scan()"""
  787. try:
  788. _test_scan_ap_scan_2_ap_mode(dev, apdev)
  789. finally:
  790. dev[0].request("AP_SCAN 1")
  791. def _test_scan_ap_scan_2_ap_mode(dev, apdev):
  792. if "OK" not in dev[0].request("AP_SCAN 2"):
  793. raise Exception("Failed to set AP_SCAN 2")
  794. id = dev[0].add_network()
  795. dev[0].set_network(id, "mode", "2")
  796. dev[0].set_network_quoted(id, "ssid", "wpas-ap-open")
  797. dev[0].set_network(id, "key_mgmt", "NONE")
  798. dev[0].set_network(id, "frequency", "2412")
  799. dev[0].set_network(id, "scan_freq", "2412")
  800. dev[0].set_network(id, "disabled", "0")
  801. dev[0].select_network(id)
  802. ev = dev[0].wait_event(["CTRL-EVENT-CONNECTED"], timeout=5)
  803. if ev is None:
  804. raise Exception("AP failed to start")
  805. with fail_test(dev[0], 1, "wpa_driver_nl80211_scan"):
  806. if "OK" not in dev[0].request("SCAN freq=2412"):
  807. raise Exception("SCAN command failed unexpectedly")
  808. ev = dev[0].wait_event(["CTRL-EVENT-SCAN-FAILED",
  809. "AP-DISABLED"], timeout=5)
  810. if ev is None:
  811. raise Exception("CTRL-EVENT-SCAN-FAILED not seen")
  812. if "AP-DISABLED" in ev:
  813. raise Exception("Unexpected AP-DISABLED event")
  814. if "retry=1" in ev:
  815. # Wait for the retry to scan happen
  816. ev = dev[0].wait_event(["CTRL-EVENT-SCAN-FAILED",
  817. "AP-DISABLED"], timeout=5)
  818. if ev is None:
  819. raise Exception("CTRL-EVENT-SCAN-FAILED not seen - retry")
  820. if "AP-DISABLED" in ev:
  821. raise Exception("Unexpected AP-DISABLED event - retry")
  822. dev[1].connect("wpas-ap-open", key_mgmt="NONE", scan_freq="2412")
  823. dev[1].request("DISCONNECT")
  824. dev[1].wait_disconnected()
  825. dev[0].request("DISCONNECT")
  826. dev[0].wait_disconnected()
  827. def test_scan_bss_expiration_on_ssid_change(dev, apdev):
  828. """BSS entry expiration when AP changes SSID"""
  829. dev[0].flush_scan_cache()
  830. hapd = hostapd.add_ap(apdev[0], { "ssid": "test-scan" })
  831. bssid = apdev[0]['bssid']
  832. dev[0].scan_for_bss(apdev[0]['bssid'], freq="2412")
  833. hapd.request("DISABLE")
  834. hapd = hostapd.add_ap(apdev[0], { "ssid": "open" })
  835. if "OK" not in dev[0].request("BSS_EXPIRE_COUNT 3"):
  836. raise Exception("BSS_EXPIRE_COUNT failed")
  837. dev[0].scan(freq="2412")
  838. dev[0].scan(freq="2412")
  839. if "OK" not in dev[0].request("BSS_EXPIRE_COUNT 2"):
  840. raise Exception("BSS_EXPIRE_COUNT failed")
  841. res = dev[0].request("SCAN_RESULTS")
  842. if "test-scan" not in res:
  843. raise Exception("The first SSID not in scan results")
  844. if "open" not in res:
  845. raise Exception("The second SSID not in scan results")
  846. dev[0].connect("open", key_mgmt="NONE")
  847. dev[0].request("BSS_FLUSH 0")
  848. res = dev[0].request("SCAN_RESULTS")
  849. if "test-scan" in res:
  850. raise Exception("The BSS entry with the old SSID was not removed")
  851. dev[0].request("DISCONNECT")
  852. dev[0].wait_disconnected()
  853. def test_scan_dfs(dev, apdev, params):
  854. """Scan on DFS channels"""
  855. try:
  856. _test_scan_dfs(dev, apdev, params)
  857. finally:
  858. subprocess.call(['iw', 'reg', 'set', '00'])
  859. def _test_scan_dfs(dev, apdev, params):
  860. subprocess.call(['iw', 'reg', 'set', 'US'])
  861. for i in range(2):
  862. for j in range(5):
  863. ev = dev[i].wait_event(["CTRL-EVENT-REGDOM-CHANGE"], timeout=5)
  864. if ev is None:
  865. raise Exception("No regdom change event")
  866. if "alpha2=US" in ev:
  867. break
  868. dev[i].dump_monitor()
  869. if "OK" not in dev[0].request("SCAN"):
  870. raise Exception("SCAN command failed")
  871. ev = dev[0].wait_event(["CTRL-EVENT-SCAN-RESULTS"])
  872. if ev is None:
  873. raise Exception("Scan did not complete")
  874. if "OK" not in dev[0].request("SCAN freq=2412,5180,5260,5500,5600,5745"):
  875. raise Exception("SCAN command failed")
  876. ev = dev[0].wait_event(["CTRL-EVENT-SCAN-RESULTS"])
  877. if ev is None:
  878. raise Exception("Scan did not complete")
  879. out = run_tshark(os.path.join(params['logdir'], "hwsim0.pcapng"),
  880. "wlan.fc.type_subtype == 4", [ "radiotap.channel.freq" ])
  881. if out is not None:
  882. freq = out.splitlines()
  883. freq = [int(f) for f in freq]
  884. freq = list(set(freq))
  885. freq.sort()
  886. logger.info("Active scan seen on channels: " + str(freq))
  887. for f in freq:
  888. if (f >= 5260 and f <= 5320) or (f >= 5500 and f <= 5700):
  889. raise Exception("Active scan on DFS channel: %d" % f)
  890. if f in [ 2467, 2472 ]:
  891. raise Exception("Active scan on US-disallowed channel: %d" % f)
  892. @remote_compatible
  893. def test_scan_abort(dev, apdev):
  894. """Aborting a full scan"""
  895. dev[0].request("SCAN")
  896. ev = dev[0].wait_event(["CTRL-EVENT-SCAN-STARTED"])
  897. if ev is None:
  898. raise Exception("Scan did not start")
  899. if "OK" not in dev[0].request("ABORT_SCAN"):
  900. raise Exception("ABORT_SCAN command failed")
  901. ev = dev[0].wait_event(["CTRL-EVENT-SCAN-RESULTS"], timeout=2)
  902. if ev is None:
  903. raise Exception("Scan did not terminate")
  904. @remote_compatible
  905. def test_scan_abort_on_connect(dev, apdev):
  906. """Aborting a full scan on connection request"""
  907. hostapd.add_ap(apdev[0], { "ssid": "test-scan" })
  908. bssid = apdev[0]['bssid']
  909. dev[0].scan_for_bss(apdev[0]['bssid'], freq="2412")
  910. dev[0].dump_monitor()
  911. dev[0].request("SCAN")
  912. ev = dev[0].wait_event(["CTRL-EVENT-SCAN-STARTED"])
  913. if ev is None:
  914. raise Exception("Scan did not start")
  915. dev[0].connect("test-scan", key_mgmt="NONE")
  916. @remote_compatible
  917. def test_scan_ext(dev, apdev):
  918. """Custom IE in Probe Request frame"""
  919. hostapd.add_ap(apdev[0], { "ssid": "test-scan" })
  920. bssid = apdev[0]['bssid']
  921. try:
  922. if "OK" not in dev[0].request("VENDOR_ELEM_ADD 14 dd050011223300"):
  923. raise Exception("VENDOR_ELEM_ADD failed")
  924. check_scan(dev[0], "freq=2412 use_id=1")
  925. finally:
  926. dev[0].request("VENDOR_ELEM_REMOVE 14 *")
  927. def test_scan_fail(dev, apdev):
  928. """Scan failures"""
  929. with fail_test(dev[0], 1, "wpa_driver_nl80211_scan"):
  930. dev[0].request("DISCONNECT")
  931. if "OK" not in dev[0].request("SCAN freq=2412"):
  932. raise Exception("SCAN failed")
  933. ev = dev[0].wait_event(["CTRL-EVENT-SCAN-FAILED"], timeout=5)
  934. if ev is None:
  935. raise Exception("Did not see scan failure event")
  936. dev[0].dump_monitor()
  937. for i in range(1, 5):
  938. with alloc_fail(dev[0], i,
  939. "wpa_scan_clone_params;wpa_supplicant_trigger_scan"):
  940. if "OK" not in dev[0].request("SCAN ssid 112233 freq=2412"):
  941. raise Exception("SCAN failed")
  942. ev = dev[0].wait_event(["CTRL-EVENT-SCAN-FAILED"], timeout=5)
  943. if ev is None:
  944. raise Exception("Did not see scan failure event")
  945. dev[0].dump_monitor()
  946. with alloc_fail(dev[0], 1, "radio_add_work;wpa_supplicant_trigger_scan"):
  947. if "OK" not in dev[0].request("SCAN freq=2412"):
  948. raise Exception("SCAN failed")
  949. ev = dev[0].wait_event(["CTRL-EVENT-SCAN-FAILED"], timeout=5)
  950. if ev is None:
  951. raise Exception("Did not see scan failure event")
  952. dev[0].dump_monitor()
  953. try:
  954. if "OK" not in dev[0].request("SET filter_ssids 1"):
  955. raise Exception("SET failed")
  956. id = dev[0].connect("test-scan", key_mgmt="NONE", only_add_network=True)
  957. with alloc_fail(dev[0], 1, "wpa_supplicant_build_filter_ssids"):
  958. # While the filter list cannot be created due to memory allocation
  959. # failure, this scan is expected to be completed without SSID
  960. # filtering.
  961. if "OK" not in dev[0].request("SCAN freq=2412"):
  962. raise Exception("SCAN failed")
  963. ev = dev[0].wait_event(["CTRL-EVENT-SCAN-RESULTS"])
  964. if ev is None:
  965. raise Exception("Scan did not complete")
  966. dev[0].remove_network(id)
  967. finally:
  968. dev[0].request("SET filter_ssids 0")
  969. dev[0].dump_monitor()
  970. with alloc_fail(dev[0], 1, "nl80211_get_scan_results"):
  971. if "OK" not in dev[0].request("SCAN freq=2412"):
  972. raise Exception("SCAN failed")
  973. ev = dev[0].wait_event(["CTRL-EVENT-SCAN-STARTED"], timeout=5)
  974. if ev is None:
  975. raise Exception("Did not see scan started event")
  976. wait_fail_trigger(dev[0], "GET_ALLOC_FAIL")
  977. dev[0].dump_monitor()
  978. try:
  979. if "OK" not in dev[0].request("SET setband 2G"):
  980. raise Exception("SET setband failed")
  981. with alloc_fail(dev[0], 1, "=wpa_setband_scan_freqs_list"):
  982. # While the frequency list cannot be created due to memory
  983. # allocation failure, this scan is expected to be completed without
  984. # frequency filtering.
  985. if "OK" not in dev[0].request("SCAN"):
  986. raise Exception("SCAN failed")
  987. wait_fail_trigger(dev[0], "GET_ALLOC_FAIL")
  988. dev[0].request("ABORT_SCAN")
  989. ev = dev[0].wait_event(["CTRL-EVENT-SCAN-RESULTS"])
  990. if ev is None:
  991. raise Exception("Scan did not complete")
  992. finally:
  993. dev[0].request("SET setband AUTO")
  994. dev[0].dump_monitor()
  995. wpas = WpaSupplicant(global_iface='/tmp/wpas-wlan5')
  996. wpas.interface_add("wlan5")
  997. wpas.request("SET preassoc_mac_addr 1")
  998. with fail_test(wpas, 1, "nl80211_set_mac_addr;wpas_trigger_scan_cb"):
  999. if "OK" not in wpas.request("SCAN freq=2412"):
  1000. raise Exception("SCAN failed")
  1001. ev = wpas.wait_event(["CTRL-EVENT-SCAN-FAILED"], timeout=5)
  1002. if ev is None:
  1003. raise Exception("Did not see scan failure event")
  1004. wpas.request("SET preassoc_mac_addr 0")
  1005. wpas.dump_monitor()
  1006. hapd = hostapd.add_ap(apdev[0], { "ssid": "open" })
  1007. with alloc_fail(dev[0], 1, "wpa_bss_add"):
  1008. dev[0].scan_for_bss(apdev[0]['bssid'], freq="2412")
  1009. def test_scan_fail_type_only(dev, apdev):
  1010. """Scan failures for TYPE=ONLY"""
  1011. with fail_test(dev[0], 1, "wpa_driver_nl80211_scan"):
  1012. dev[0].request("SCAN TYPE=ONLY freq=2417")
  1013. ev = dev[0].wait_event(["CTRL-EVENT-SCAN-FAILED"], timeout=5)
  1014. if ev is None:
  1015. raise Exception("Scan trigger failure not reported")
  1016. # Verify that scan_only_handler() does not get left set as the
  1017. # wpa_s->scan_res_handler in failure case.
  1018. hapd = hostapd.add_ap(apdev[0], { "ssid": "open" })
  1019. dev[0].connect("open", key_mgmt="NONE", scan_freq="2412")
  1020. @remote_compatible
  1021. def test_scan_freq_list(dev, apdev):
  1022. """Scan with SET freq_list and scan_cur_freq"""
  1023. try:
  1024. if "OK" not in dev[0].request("SET freq_list 2412 2417"):
  1025. raise Exception("SET freq_list failed")
  1026. check_scan(dev[0], "use_id=1")
  1027. finally:
  1028. dev[0].request("SET freq_list ")
  1029. hapd = hostapd.add_ap(apdev[0], { "ssid": "test-scan" })
  1030. dev[0].connect("test-scan", key_mgmt="NONE", scan_freq="2412")
  1031. try:
  1032. if "OK" not in dev[0].request("SET scan_cur_freq 1"):
  1033. raise Exception("SET scan_cur_freq failed")
  1034. check_scan(dev[0], "use_id=1")
  1035. finally:
  1036. dev[0].request("SET scan_cur_freq 0")
  1037. dev[0].request("REMOVE_NETWORK all")
  1038. dev[0].wait_disconnected()
  1039. def test_scan_bss_limit(dev, apdev):
  1040. """Scan and wpa_supplicant BSS entry limit"""
  1041. try:
  1042. _test_scan_bss_limit(dev, apdev)
  1043. finally:
  1044. dev[0].request("SET bss_max_count 200")
  1045. pass
  1046. def _test_scan_bss_limit(dev, apdev):
  1047. # Trigger 'Increasing the MAX BSS count to 2 because all BSSes are in use.
  1048. # We should normally not get here!' message by limiting the maximum BSS
  1049. # count to one so that the second AP would not fit in the BSS list and the
  1050. # first AP cannot be removed from the list since it is still in use.
  1051. dev[0].request("SET bss_max_count 1")
  1052. hapd = hostapd.add_ap(apdev[0], { "ssid": "test-scan" })
  1053. dev[0].connect("test-scan", key_mgmt="NONE", scan_freq="2412")
  1054. hapd2 = hostapd.add_ap(apdev[1], { "ssid": "test-scan-2",
  1055. "channel": "6" })
  1056. dev[0].scan_for_bss(apdev[1]['bssid'], freq=2437, force_scan=True)
  1057. def run_scan(dev, bssid, exp_freq):
  1058. for i in range(5):
  1059. dev.request("SCAN freq=2412,2437,2462")
  1060. ev = dev.wait_event(["CTRL-EVENT-SCAN-RESULTS"])
  1061. if ev is None:
  1062. raise Exception("Scan did not complete")
  1063. bss = dev.get_bss(bssid)
  1064. freq = int(bss['freq']) if bss else 0
  1065. if freq == exp_freq:
  1066. break
  1067. if freq != exp_freq:
  1068. raise Exception("BSS entry shows incorrect frequency: %d != %d" % (freq, exp_freq))
  1069. def test_scan_chan_switch(dev, apdev):
  1070. """Scanning and AP changing channels"""
  1071. # This test verifies that wpa_supplicant updates its local BSS table based
  1072. # on the correct cfg80211 scan entry in cases where the cfg80211 BSS table
  1073. # has multiple (one for each frequency) BSS entries for the same BSS.
  1074. csa_supported(dev[0])
  1075. hapd = hostapd.add_ap(apdev[0], { "ssid": "test-scan", "channel": "1" })
  1076. csa_supported(hapd)
  1077. bssid = hapd.own_addr()
  1078. logger.info("AP channel switch while not connected")
  1079. run_scan(dev[0], bssid, 2412)
  1080. dev[0].dump_monitor()
  1081. switch_channel(hapd, 1, 2437)
  1082. run_scan(dev[0], bssid, 2437)
  1083. dev[0].dump_monitor()
  1084. switch_channel(hapd, 1, 2462)
  1085. run_scan(dev[0], bssid, 2462)
  1086. dev[0].dump_monitor()
  1087. logger.info("AP channel switch while connected")
  1088. dev[0].connect("test-scan", key_mgmt="NONE", scan_freq="2412 2437 2462")
  1089. run_scan(dev[0], bssid, 2462)
  1090. dev[0].dump_monitor()
  1091. switch_channel(hapd, 2, 2437)
  1092. wait_channel_switch(dev[0], 2437)
  1093. dev[0].dump_monitor()
  1094. run_scan(dev[0], bssid, 2437)
  1095. dev[0].dump_monitor()
  1096. switch_channel(hapd, 2, 2412)
  1097. wait_channel_switch(dev[0], 2412)
  1098. dev[0].dump_monitor()
  1099. run_scan(dev[0], bssid, 2412)
  1100. dev[0].dump_monitor()
  1101. def test_scan_new_only(dev, apdev):
  1102. """Scan and only_new=1 multiple times"""
  1103. try:
  1104. _test_scan_new_only(dev, apdev)
  1105. finally:
  1106. dev[0].set("ignore_old_scan_res", "0")
  1107. def _test_scan_new_only(dev, apdev):
  1108. dev[0].flush_scan_cache()
  1109. hapd = hostapd.add_ap(apdev[0], { "ssid": "test-scan" })
  1110. dev[0].set("ignore_old_scan_res", "1")
  1111. # Get the BSS added to cfg80211 BSS list
  1112. bssid = hapd.own_addr()
  1113. dev[0].scan_for_bss(bssid, freq=2412)
  1114. bss = dev[0].get_bss(bssid)
  1115. idx1 = bss['update_idx']
  1116. dev[0].scan_for_bss(bssid, freq=2412, force_scan=True)
  1117. dev[0].scan_for_bss(bssid, freq=2412, force_scan=True)
  1118. bss = dev[0].get_bss(bssid)
  1119. idx2 = bss['update_idx']
  1120. if int(idx2) <= int(idx1):
  1121. raise Exception("Scan result update_idx did not increase")
  1122. # Disable AP to ensure there are no new scan results after this.
  1123. hapd.disable()
  1124. # Try to scan multiple times to verify that old scan results do not get
  1125. # accepted as new.
  1126. for i in range(10):
  1127. dev[0].scan(freq=2412)
  1128. bss = dev[0].get_bss(bssid)
  1129. if bss:
  1130. idx = bss['update_idx']
  1131. if int(idx) > int(idx2):
  1132. raise Exception("Unexpected update_idx increase")
  1133. def test_scan_flush(dev, apdev):
  1134. """Ongoing scan and FLUSH"""
  1135. dev[0].flush_scan_cache()
  1136. hapd = hostapd.add_ap(apdev[0], { "ssid": "test-scan" })
  1137. dev[0].dump_monitor()
  1138. dev[0].request("SCAN TYPE=ONLY freq=2412-2472 passive=1")
  1139. ev = dev[0].wait_event(["CTRL-EVENT-SCAN-STARTED"], timeout=10)
  1140. if ev is None:
  1141. raise Exception("Scan did not start")
  1142. time.sleep(0.1)
  1143. dev[0].request("FLUSH")
  1144. ev = dev[0].wait_event(["CTRL-EVENT-SCAN-RESULTS",
  1145. "CTRL-EVENT-SCAN-FAILED",
  1146. "CTRL-EVENT-BSS-ADDED"], timeout=10)
  1147. if ev is None:
  1148. raise Exception("Scan did not complete")
  1149. if "CTRL-EVENT-BSS-ADDED" in ev:
  1150. raise Exception("Unexpected BSS entry addition after FLUSH")
  1151. def test_scan_ies(dev, apdev):
  1152. """Scan and both Beacon and Probe Response frame IEs"""
  1153. dev[0].flush_scan_cache()
  1154. hapd = hostapd.add_ap(apdev[0], { "ssid": "test-scan",
  1155. "beacon_int": "20" })
  1156. bssid = hapd.own_addr()
  1157. dev[0].dump_monitor()
  1158. for i in range(10):
  1159. dev[0].request("SCAN TYPE=ONLY freq=2412 passive=1")
  1160. ev = dev[0].wait_event(["CTRL-EVENT-SCAN-RESULTS"], timeout=15)
  1161. if ev is None:
  1162. raise Exception("Scan did not complete")
  1163. if dev[0].get_bss(bssid):
  1164. break
  1165. for i in range(10):
  1166. dev[0].scan_for_bss(bssid, freq=2412, force_scan=True)
  1167. bss = dev[0].get_bss(bssid)
  1168. if 'beacon_ie' in bss:
  1169. if bss['ie'] != bss['beacon_ie']:
  1170. break
  1171. if not bss or 'beacon_ie' not in bss:
  1172. raise Exception("beacon_ie not present")
  1173. ie = parse_ie(bss['ie'])
  1174. logger.info("ie: " + str(ie.keys()))
  1175. beacon_ie = parse_ie(bss['beacon_ie'])
  1176. logger.info("beacon_ie: " + str(ie.keys()))
  1177. if bss['ie'] == bss['beacon_ie']:
  1178. raise Exception("Both ie and beacon_ie show same data")
  1179. def test_scan_parsing(dev, apdev):
  1180. """Scan result parsing"""
  1181. if "OK" not in dev[0].request("DRIVER_EVENT SCAN_RES START"):
  1182. raise Exception("DRIVER_EVENT SCAN_RES START failed")
  1183. if "FAIL" not in dev[0].request("DRIVER_EVENT SCAN_RES foo "):
  1184. raise Exception("Invalid DRIVER_EVENT SCAN_RES accepted")
  1185. tests = [ "",
  1186. "flags=ffffffff",
  1187. "bssid=02:03:04:05:06:07",
  1188. "freq=1234",
  1189. "beacon_int=102",
  1190. "caps=1234",
  1191. "qual=10",
  1192. "noise=10",
  1193. "level=10",
  1194. "tsf=1122334455667788",
  1195. "age=123",
  1196. "est_throughput=100",
  1197. "snr=10",
  1198. "parent_tsf=1122334455667788",
  1199. "tsf_bssid=02:03:04:05:06:07",
  1200. "ie=00",
  1201. "beacon_ie=00",
  1202. # Too long SSID
  1203. "bssid=02:ff:00:00:00:01 ie=0033" + 33*'FF',
  1204. # All parameters
  1205. "flags=ffffffff bssid=02:ff:00:00:00:02 freq=1234 beacon_int=102 caps=1234 qual=10 noise=10 level=10 tsf=1122334455667788 age=123456 est_throughput=100 snr=10 parent_tsf=1122334455667788 tsf_bssid=02:03:04:05:06:07 ie=000474657374 beacon_ie=000474657374",
  1206. # Beacon IEs truncated
  1207. "bssid=02:ff:00:00:00:03 ie=0000 beacon_ie=0003ffff",
  1208. # Probe Response IEs truncated
  1209. "bssid=02:ff:00:00:00:04 ie=00000101 beacon_ie=0000",
  1210. # DMG (invalid caps)
  1211. "bssid=02:ff:00:00:00:05 freq=58320 ie=0003646d67",
  1212. # DMG (IBSS)
  1213. "bssid=02:ff:00:00:00:06 freq=60480 caps=0001 ie=0003646d67",
  1214. # DMG (PBSS)
  1215. "bssid=02:ff:00:00:00:07 freq=62640 caps=0002 ie=0003646d67",
  1216. # DMG (AP)
  1217. "bssid=02:ff:00:00:00:08 freq=64800 caps=0003 ie=0003646d67",
  1218. # Test BSS for updates
  1219. "bssid=02:ff:00:00:00:09 freq=2412 caps=0011 level=1 ie=0003757064010182",
  1220. # Minimal BSS data
  1221. "bssid=02:ff:00:00:00:00 ie=0000" ]
  1222. for t in tests:
  1223. if "OK" not in dev[0].request("DRIVER_EVENT SCAN_RES BSS " + t):
  1224. raise Exception("DRIVER_EVENT SCAN_RES BSS failed")
  1225. if "OK" not in dev[0].request("DRIVER_EVENT SCAN_RES END"):
  1226. raise Exception("DRIVER_EVENT SCAN_RES END failed")
  1227. res = dev[0].request("SCAN_RESULTS")
  1228. logger.info("SCAN_RESULTS:\n" + res)
  1229. bss = []
  1230. res = dev[0].request("BSS FIRST")
  1231. if "FAIL" in res:
  1232. raise Exception("BSS FIRST failed")
  1233. while "\nbssid=" in res:
  1234. logger.info("BSS output:\n" + res)
  1235. bssid = None
  1236. id = None
  1237. for val in res.splitlines():
  1238. if val.startswith("id="):
  1239. id = val.split('=')[1]
  1240. if val.startswith("bssid="):
  1241. bssid = val.split('=')[1]
  1242. if bssid is None or id is None:
  1243. raise Exception("Missing id or bssid line")
  1244. bss.append(bssid)
  1245. res = dev[0].request("BSS NEXT-" + id)
  1246. logger.info("Discovered BSSs: " + str(bss))
  1247. invalid_bss = [ "02:03:04:05:06:07", "02:ff:00:00:00:01" ]
  1248. valid_bss = [ "02:ff:00:00:00:00", "02:ff:00:00:00:02",
  1249. "02:ff:00:00:00:03", "02:ff:00:00:00:04",
  1250. "02:ff:00:00:00:05", "02:ff:00:00:00:06",
  1251. "02:ff:00:00:00:07", "02:ff:00:00:00:08",
  1252. "02:ff:00:00:00:09" ]
  1253. for bssid in invalid_bss:
  1254. if bssid in bss:
  1255. raise Exception("Invalid BSS included: " + bssid)
  1256. for bssid in valid_bss:
  1257. if bssid not in bss:
  1258. raise Exception("Valid BSS missing: " + bssid)
  1259. logger.info("Update BSS parameters")
  1260. if "OK" not in dev[0].request("DRIVER_EVENT SCAN_RES START"):
  1261. raise Exception("DRIVER_EVENT SCAN_RES START failed")
  1262. if "OK" not in dev[0].request("DRIVER_EVENT SCAN_RES BSS bssid=02:ff:00:00:00:09 freq=2412 caps=0002 level=2 ie=000375706401028204"):
  1263. raise Exception("DRIVER_EVENT SCAN_RES BSS failed")
  1264. if "OK" not in dev[0].request("DRIVER_EVENT SCAN_RES END"):
  1265. raise Exception("DRIVER_EVENT SCAN_RES END failed")
  1266. res = dev[0].request("BSS 02:ff:00:00:00:09")
  1267. logger.info("Updated BSS:\n" + res)
  1268. def test_scan_specific_bssid(dev, apdev):
  1269. """Scan for a specific BSSID"""
  1270. dev[0].flush_scan_cache()
  1271. hapd = hostapd.add_ap(apdev[0], { "ssid": "test-scan",
  1272. "beacon_int": "1000" })
  1273. bssid = hapd.own_addr()
  1274. time.sleep(0.1)
  1275. dev[0].request("SCAN TYPE=ONLY freq=2412 bssid=02:ff:ff:ff:ff:ff")
  1276. ev = dev[0].wait_event(["CTRL-EVENT-SCAN-RESULTS"], timeout=10)
  1277. if ev is None:
  1278. raise Exception("Scan did not complete")
  1279. bss1 = dev[0].get_bss(bssid)
  1280. for i in range(10):
  1281. dev[0].request("SCAN TYPE=ONLY freq=2412 bssid=" + bssid)
  1282. ev = dev[0].wait_event(["CTRL-EVENT-SCAN-RESULTS"], timeout=10)
  1283. if ev is None:
  1284. raise Exception("Scan did not complete")
  1285. bss2 = dev[0].get_bss(bssid)
  1286. if bss2:
  1287. break
  1288. if not bss2:
  1289. raise Exception("Did not find BSS")
  1290. if bss1 and 'beacon_ie' in bss1 and 'ie' in bss1 and bss1['beacon_ie'] != bss2['ie']:
  1291. raise Exception("First scan for unknown BSSID returned unexpected response")
  1292. if bss2 and 'beacon_ie' in bss2 and 'ie' in bss2 and bss2['beacon_ie'] == bss2['ie']:
  1293. raise Exception("Second scan did find Probe Response frame")
  1294. def test_scan_probe_req_events(dev, apdev):
  1295. """Probe Request frame RX events from hostapd"""
  1296. hapd = hostapd.add_ap(apdev[0], { "ssid": "open" })
  1297. hapd2 = hostapd.Hostapd(apdev[0]['ifname'])
  1298. if "OK" not in hapd2.mon.request("ATTACH probe_rx_events=1"):
  1299. raise Exception("Failed to register for events")
  1300. dev[0].scan_for_bss(apdev[0]['bssid'], freq="2412", force_scan=True)
  1301. ev = hapd2.wait_event(["RX-PROBE-REQUEST"], timeout=5)
  1302. if ev is None:
  1303. raise Exception("RX-PROBE-REQUEST not reported")
  1304. if "sa=" + dev[0].own_addr() not in ev:
  1305. raise Exception("Unexpected event parameters: " + ev)
  1306. ev = hapd.wait_event(["RX-PROBE-REQUEST"], timeout=0.1)
  1307. if ev is not None:
  1308. raise Exception("Unexpected RX-PROBE-REQUEST")