test_ap_open.py 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517
  1. # Open mode AP tests
  2. # Copyright (c) 2014, Qualcomm Atheros, Inc.
  3. #
  4. # This software may be distributed under the terms of the BSD license.
  5. # See README for more details.
  6. import logging
  7. logger = logging.getLogger()
  8. import struct
  9. import subprocess
  10. import time
  11. import os
  12. import hostapd
  13. import hwsim_utils
  14. from tshark import run_tshark
  15. from utils import alloc_fail
  16. from wpasupplicant import WpaSupplicant
  17. def test_ap_open(dev, apdev):
  18. """AP with open mode (no security) configuration"""
  19. hapd = hostapd.add_ap(apdev[0]['ifname'], { "ssid": "open" })
  20. dev[0].connect("open", key_mgmt="NONE", scan_freq="2412",
  21. bg_scan_period="0")
  22. ev = hapd.wait_event([ "AP-STA-CONNECTED" ], timeout=5)
  23. if ev is None:
  24. raise Exception("No connection event received from hostapd")
  25. hwsim_utils.test_connectivity(dev[0], hapd)
  26. dev[0].request("DISCONNECT")
  27. ev = hapd.wait_event([ "AP-STA-DISCONNECTED" ], timeout=5)
  28. if ev is None:
  29. raise Exception("No disconnection event received from hostapd")
  30. def test_ap_open_packet_loss(dev, apdev):
  31. """AP with open mode configuration and large packet loss"""
  32. params = { "ssid": "open",
  33. "ignore_probe_probability": "0.5",
  34. "ignore_auth_probability": "0.5",
  35. "ignore_assoc_probability": "0.5",
  36. "ignore_reassoc_probability": "0.5" }
  37. hapd = hostapd.add_ap(apdev[0]['ifname'], params)
  38. for i in range(0, 3):
  39. dev[i].connect("open", key_mgmt="NONE", scan_freq="2412",
  40. wait_connect=False)
  41. for i in range(0, 3):
  42. dev[i].wait_connected(timeout=20)
  43. def test_ap_open_unknown_action(dev, apdev):
  44. """AP with open mode configuration and unknown Action frame"""
  45. hapd = hostapd.add_ap(apdev[0]['ifname'], { "ssid": "open" })
  46. dev[0].connect("open", key_mgmt="NONE", scan_freq="2412")
  47. bssid = apdev[0]['bssid']
  48. cmd = "MGMT_TX {} {} freq=2412 action=765432".format(bssid, bssid)
  49. if "FAIL" in dev[0].request(cmd):
  50. raise Exception("Could not send test Action frame")
  51. ev = dev[0].wait_event(["MGMT-TX-STATUS"], timeout=10)
  52. if ev is None:
  53. raise Exception("Timeout on MGMT-TX-STATUS")
  54. if "result=SUCCESS" not in ev:
  55. raise Exception("AP did not ack Action frame")
  56. def test_ap_open_invalid_wmm_action(dev, apdev):
  57. """AP with open mode configuration and invalid WMM Action frame"""
  58. hapd = hostapd.add_ap(apdev[0]['ifname'], { "ssid": "open" })
  59. dev[0].connect("open", key_mgmt="NONE", scan_freq="2412")
  60. bssid = apdev[0]['bssid']
  61. cmd = "MGMT_TX {} {} freq=2412 action=1100".format(bssid, bssid)
  62. if "FAIL" in dev[0].request(cmd):
  63. raise Exception("Could not send test Action frame")
  64. ev = dev[0].wait_event(["MGMT-TX-STATUS"], timeout=10)
  65. if ev is None or "result=SUCCESS" not in ev:
  66. raise Exception("AP did not ack Action frame")
  67. def test_ap_open_reconnect_on_inactivity_disconnect(dev, apdev):
  68. """Reconnect to open mode AP after inactivity related disconnection"""
  69. hapd = hostapd.add_ap(apdev[0]['ifname'], { "ssid": "open" })
  70. dev[0].connect("open", key_mgmt="NONE", scan_freq="2412")
  71. hapd.request("DEAUTHENTICATE " + dev[0].p2p_interface_addr() + " reason=4")
  72. dev[0].wait_disconnected(timeout=5)
  73. dev[0].wait_connected(timeout=2, error="Timeout on reconnection")
  74. def test_ap_open_assoc_timeout(dev, apdev):
  75. """AP timing out association"""
  76. ssid = "test"
  77. hapd = hostapd.add_ap(apdev[0]['ifname'], { "ssid": "open" })
  78. dev[0].scan(freq="2412")
  79. hapd.set("ext_mgmt_frame_handling", "1")
  80. dev[0].connect("open", key_mgmt="NONE", scan_freq="2412",
  81. wait_connect=False)
  82. for i in range(0, 10):
  83. req = hapd.mgmt_rx()
  84. if req is None:
  85. raise Exception("MGMT RX wait timed out")
  86. if req['subtype'] == 11:
  87. break
  88. req = None
  89. if not req:
  90. raise Exception("Authentication frame not received")
  91. resp = {}
  92. resp['fc'] = req['fc']
  93. resp['da'] = req['sa']
  94. resp['sa'] = req['da']
  95. resp['bssid'] = req['bssid']
  96. resp['payload'] = struct.pack('<HHH', 0, 2, 0)
  97. hapd.mgmt_tx(resp)
  98. assoc = 0
  99. for i in range(0, 10):
  100. req = hapd.mgmt_rx()
  101. if req is None:
  102. raise Exception("MGMT RX wait timed out")
  103. if req['subtype'] == 0:
  104. assoc += 1
  105. if assoc == 3:
  106. break
  107. if assoc != 3:
  108. raise Exception("Association Request frames not received: assoc=%d" % assoc)
  109. hapd.set("ext_mgmt_frame_handling", "0")
  110. dev[0].wait_connected(timeout=15)
  111. def test_ap_open_id_str(dev, apdev):
  112. """AP with open mode and id_str"""
  113. hapd = hostapd.add_ap(apdev[0]['ifname'], { "ssid": "open" })
  114. dev[0].connect("open", key_mgmt="NONE", scan_freq="2412", id_str="foo",
  115. wait_connect=False)
  116. ev = dev[0].wait_connected(timeout=10)
  117. if "id_str=foo" not in ev:
  118. raise Exception("CTRL-EVENT-CONNECT did not have matching id_str: " + ev)
  119. if dev[0].get_status_field("id_str") != "foo":
  120. raise Exception("id_str mismatch")
  121. def test_ap_open_select_any(dev, apdev):
  122. """AP with open mode and select any network"""
  123. hapd = hostapd.add_ap(apdev[0]['ifname'], { "ssid": "open" })
  124. id = dev[0].connect("unknown", key_mgmt="NONE", scan_freq="2412",
  125. only_add_network=True)
  126. dev[0].connect("open", key_mgmt="NONE", scan_freq="2412",
  127. only_add_network=True)
  128. dev[0].select_network(id)
  129. ev = dev[0].wait_event(["CTRL-EVENT-NETWORK-NOT-FOUND",
  130. "CTRL-EVENT-CONNECTED"], timeout=10)
  131. if ev is None:
  132. raise Exception("No result reported")
  133. if "CTRL-EVENT-CONNECTED" in ev:
  134. raise Exception("Unexpected connection")
  135. dev[0].select_network("any")
  136. dev[0].wait_connected(timeout=10)
  137. def test_ap_open_unexpected_assoc_event(dev, apdev):
  138. """AP with open mode and unexpected association event"""
  139. hapd = hostapd.add_ap(apdev[0]['ifname'], { "ssid": "open" })
  140. dev[0].connect("open", key_mgmt="NONE", scan_freq="2412")
  141. dev[0].request("DISCONNECT")
  142. dev[0].wait_disconnected(timeout=15)
  143. dev[0].dump_monitor()
  144. # This will be accepted due to matching network
  145. subprocess.call(['iw', 'dev', dev[0].ifname, 'connect', 'open', "2412",
  146. apdev[0]['bssid']])
  147. dev[0].wait_connected(timeout=15)
  148. dev[0].dump_monitor()
  149. dev[0].request("REMOVE_NETWORK all")
  150. dev[0].wait_disconnected(timeout=5)
  151. dev[0].dump_monitor()
  152. # This will result in disconnection due to no matching network
  153. subprocess.call(['iw', 'dev', dev[0].ifname, 'connect', 'open', "2412",
  154. apdev[0]['bssid']])
  155. dev[0].wait_disconnected(timeout=15)
  156. def test_ap_bss_load(dev, apdev):
  157. """AP with open mode (no security) configuration"""
  158. hapd = hostapd.add_ap(apdev[0]['ifname'],
  159. { "ssid": "open",
  160. "bss_load_update_period": "10" })
  161. dev[0].connect("open", key_mgmt="NONE", scan_freq="2412")
  162. # this does not really get much useful output with mac80211_hwsim currently,
  163. # but run through the channel survey update couple of times
  164. for i in range(0, 10):
  165. hwsim_utils.test_connectivity(dev[0], hapd)
  166. hwsim_utils.test_connectivity(dev[0], hapd)
  167. hwsim_utils.test_connectivity(dev[0], hapd)
  168. time.sleep(0.15)
  169. def hapd_out_of_mem(hapd, apdev, count, func):
  170. with alloc_fail(hapd, count, func):
  171. started = False
  172. try:
  173. hostapd.add_ap(apdev['ifname'], { "ssid": "open" })
  174. started = True
  175. except:
  176. pass
  177. if started:
  178. raise Exception("hostapd interface started even with memory allocation failure: " + arg)
  179. def test_ap_open_out_of_memory(dev, apdev):
  180. """hostapd failing to setup interface due to allocation failure"""
  181. hapd = hostapd.add_ap(apdev[0]['ifname'], { "ssid": "open" })
  182. hapd_out_of_mem(hapd, apdev[1], 1, "hostapd_alloc_bss_data")
  183. for i in range(1, 3):
  184. hapd_out_of_mem(hapd, apdev[1], i, "hostapd_iface_alloc")
  185. for i in range(1, 5):
  186. hapd_out_of_mem(hapd, apdev[1], i, "hostapd_config_defaults;hostapd_config_alloc")
  187. hapd_out_of_mem(hapd, apdev[1], 1, "hostapd_config_alloc")
  188. hapd_out_of_mem(hapd, apdev[1], 1, "hostapd_driver_init")
  189. for i in range(1, 4):
  190. hapd_out_of_mem(hapd, apdev[1], i, "=wpa_driver_nl80211_drv_init")
  191. # eloop_register_read_sock() call from i802_init()
  192. hapd_out_of_mem(hapd, apdev[1], 1, "eloop_sock_table_add_sock;eloop_register_sock;?eloop_register_read_sock;=i802_init")
  193. # verify that a new interface can still be added when memory allocation does
  194. # not fail
  195. hostapd.add_ap(apdev[1]['ifname'], { "ssid": "open" })
  196. def test_bssid_black_white_list(dev, apdev):
  197. """BSSID black/white list"""
  198. hapd = hostapd.add_ap(apdev[0]['ifname'], { "ssid": "open" })
  199. hapd2 = hostapd.add_ap(apdev[1]['ifname'], { "ssid": "open" })
  200. dev[0].connect("open", key_mgmt="NONE", scan_freq="2412",
  201. bssid_whitelist=apdev[1]['bssid'])
  202. dev[1].connect("open", key_mgmt="NONE", scan_freq="2412",
  203. bssid_blacklist=apdev[1]['bssid'])
  204. dev[2].connect("open", key_mgmt="NONE", scan_freq="2412",
  205. bssid_whitelist="00:00:00:00:00:00/00:00:00:00:00:00",
  206. bssid_blacklist=apdev[1]['bssid'])
  207. if dev[0].get_status_field('bssid') != apdev[1]['bssid']:
  208. raise Exception("dev[0] connected to unexpected AP")
  209. if dev[1].get_status_field('bssid') != apdev[0]['bssid']:
  210. raise Exception("dev[1] connected to unexpected AP")
  211. if dev[2].get_status_field('bssid') != apdev[0]['bssid']:
  212. raise Exception("dev[2] connected to unexpected AP")
  213. dev[0].request("REMOVE_NETWORK all")
  214. dev[1].request("REMOVE_NETWORK all")
  215. dev[2].request("REMOVE_NETWORK all")
  216. dev[2].connect("open", key_mgmt="NONE", scan_freq="2412",
  217. bssid_whitelist="00:00:00:00:00:00", wait_connect=False)
  218. dev[0].connect("open", key_mgmt="NONE", scan_freq="2412",
  219. bssid_whitelist="11:22:33:44:55:66/ff:00:00:00:00:00 " + apdev[1]['bssid'] + " aa:bb:cc:dd:ee:ff")
  220. dev[1].connect("open", key_mgmt="NONE", scan_freq="2412",
  221. bssid_blacklist="11:22:33:44:55:66/ff:00:00:00:00:00 " + apdev[1]['bssid'] + " aa:bb:cc:dd:ee:ff")
  222. if dev[0].get_status_field('bssid') != apdev[1]['bssid']:
  223. raise Exception("dev[0] connected to unexpected AP")
  224. if dev[1].get_status_field('bssid') != apdev[0]['bssid']:
  225. raise Exception("dev[1] connected to unexpected AP")
  226. dev[0].request("REMOVE_NETWORK all")
  227. dev[1].request("REMOVE_NETWORK all")
  228. ev = dev[2].wait_event(["CTRL-EVENT-CONNECTED"], timeout=0.1)
  229. if ev is not None:
  230. raise Exception("Unexpected dev[2] connectin")
  231. dev[2].request("REMOVE_NETWORK all")
  232. def test_ap_open_wpas_in_bridge(dev, apdev):
  233. """Open mode AP and wpas interface in a bridge"""
  234. br_ifname='sta-br0'
  235. ifname='wlan5'
  236. try:
  237. _test_ap_open_wpas_in_bridge(dev, apdev)
  238. finally:
  239. subprocess.call(['ip', 'link', 'set', 'dev', br_ifname, 'down'])
  240. subprocess.call(['brctl', 'delif', br_ifname, ifname])
  241. subprocess.call(['brctl', 'delbr', br_ifname])
  242. subprocess.call(['iw', ifname, 'set', '4addr', 'off'])
  243. def _test_ap_open_wpas_in_bridge(dev, apdev):
  244. hapd = hostapd.add_ap(apdev[0]['ifname'], { "ssid": "open" })
  245. br_ifname='sta-br0'
  246. ifname='wlan5'
  247. wpas = WpaSupplicant(global_iface='/tmp/wpas-wlan5')
  248. # First, try a failure case of adding an interface
  249. try:
  250. wpas.interface_add(ifname, br_ifname=br_ifname)
  251. raise Exception("Interface addition succeeded unexpectedly")
  252. except Exception, e:
  253. if "Failed to add" in str(e):
  254. logger.info("Ignore expected interface_add failure due to missing bridge interface: " + str(e))
  255. else:
  256. raise
  257. # Next, add the bridge interface and add the interface again
  258. subprocess.call(['brctl', 'addbr', br_ifname])
  259. subprocess.call(['brctl', 'setfd', br_ifname, '0'])
  260. subprocess.call(['ip', 'link', 'set', 'dev', br_ifname, 'up'])
  261. subprocess.call(['iw', ifname, 'set', '4addr', 'on'])
  262. subprocess.check_call(['brctl', 'addif', br_ifname, ifname])
  263. wpas.interface_add(ifname, br_ifname=br_ifname)
  264. wpas.connect("open", key_mgmt="NONE", scan_freq="2412")
  265. def test_ap_open_start_disabled(dev, apdev):
  266. """AP with open mode and beaconing disabled"""
  267. hapd = hostapd.add_ap(apdev[0]['ifname'], { "ssid": "open",
  268. "start_disabled": "1" })
  269. bssid = apdev[0]['bssid']
  270. dev[0].flush_scan_cache()
  271. dev[0].scan(freq=2412, only_new=True)
  272. if dev[0].get_bss(bssid) is not None:
  273. raise Exception("AP was seen beaconing")
  274. if "OK" not in hapd.request("RELOAD"):
  275. raise Exception("RELOAD failed")
  276. dev[0].scan_for_bss(bssid, freq=2412)
  277. dev[0].connect("open", key_mgmt="NONE", scan_freq="2412")
  278. def test_ap_open_start_disabled2(dev, apdev):
  279. """AP with open mode and beaconing disabled (2)"""
  280. hapd = hostapd.add_ap(apdev[0]['ifname'], { "ssid": "open",
  281. "start_disabled": "1" })
  282. bssid = apdev[0]['bssid']
  283. dev[0].flush_scan_cache()
  284. dev[0].scan(freq=2412, only_new=True)
  285. if dev[0].get_bss(bssid) is not None:
  286. raise Exception("AP was seen beaconing")
  287. if "OK" not in hapd.request("UPDATE_BEACON"):
  288. raise Exception("UPDATE_BEACON failed")
  289. dev[0].scan_for_bss(bssid, freq=2412)
  290. dev[0].connect("open", key_mgmt="NONE", scan_freq="2412")
  291. if "OK" not in hapd.request("UPDATE_BEACON"):
  292. raise Exception("UPDATE_BEACON failed")
  293. dev[0].request("DISCONNECT")
  294. dev[0].wait_disconnected()
  295. dev[0].request("RECONNECT")
  296. dev[0].wait_connected()
  297. def test_ap_open_ifdown(dev, apdev):
  298. """AP with open mode and external ifconfig down"""
  299. params = { "ssid": "open",
  300. "ap_max_inactivity": "1" }
  301. hapd = hostapd.add_ap(apdev[0]['ifname'], params)
  302. bssid = apdev[0]['bssid']
  303. dev[0].connect("open", key_mgmt="NONE", scan_freq="2412")
  304. dev[1].connect("open", key_mgmt="NONE", scan_freq="2412")
  305. subprocess.call(['ip', 'link', 'set', 'dev', apdev[0]['ifname'], 'down'])
  306. ev = hapd.wait_event(["AP-STA-DISCONNECTED"], timeout=10)
  307. if ev is None:
  308. raise Exception("Timeout on AP-STA-DISCONNECTED (1)")
  309. ev = hapd.wait_event(["AP-STA-DISCONNECTED"], timeout=5)
  310. if ev is None:
  311. raise Exception("Timeout on AP-STA-DISCONNECTED (2)")
  312. ev = hapd.wait_event(["INTERFACE-DISABLED"], timeout=5)
  313. if ev is None:
  314. raise Exception("No INTERFACE-DISABLED event")
  315. # The following wait tests beacon loss detection in mac80211 on dev0.
  316. # dev1 is used to test stopping of AP side functionality on client polling.
  317. dev[1].request("REMOVE_NETWORK all")
  318. subprocess.call(['ip', 'link', 'set', 'dev', apdev[0]['ifname'], 'up'])
  319. dev[0].wait_disconnected()
  320. dev[1].wait_disconnected()
  321. ev = hapd.wait_event(["INTERFACE-ENABLED"], timeout=10)
  322. if ev is None:
  323. raise Exception("No INTERFACE-ENABLED event")
  324. dev[0].wait_connected()
  325. hwsim_utils.test_connectivity(dev[0], hapd)
  326. def test_ap_open_disconnect_in_ps(dev, apdev, params):
  327. """Disconnect with the client in PS to regression-test a kernel bug"""
  328. hapd = hostapd.add_ap(apdev[0]['ifname'], { "ssid": "open" })
  329. dev[0].connect("open", key_mgmt="NONE", scan_freq="2412",
  330. bg_scan_period="0")
  331. ev = hapd.wait_event([ "AP-STA-CONNECTED" ], timeout=5)
  332. if ev is None:
  333. raise Exception("No connection event received from hostapd")
  334. time.sleep(0.2)
  335. hwsim_utils.set_powersave(dev[0], hwsim_utils.PS_MANUAL_POLL)
  336. try:
  337. # inject some traffic
  338. sa = hapd.own_addr()
  339. da = dev[0].own_addr()
  340. hapd.request('DATA_TEST_CONFIG 1')
  341. hapd.request('DATA_TEST_TX {} {} 0'.format(da, sa))
  342. hapd.request('DATA_TEST_CONFIG 0')
  343. # let the AP send couple of Beacon frames
  344. time.sleep(0.3)
  345. # disconnect - with traffic pending - shouldn't cause kernel warnings
  346. dev[0].request("DISCONNECT")
  347. finally:
  348. hwsim_utils.set_powersave(dev[0], hwsim_utils.PS_DISABLED)
  349. time.sleep(0.2)
  350. out = run_tshark(os.path.join(params['logdir'], "hwsim0.pcapng"),
  351. "wlan_mgt.tim.partial_virtual_bitmap",
  352. ["wlan_mgt.tim.partial_virtual_bitmap"])
  353. if out is not None:
  354. state = 0
  355. for l in out.splitlines():
  356. pvb = int(l, 16)
  357. if pvb > 0 and state == 0:
  358. state = 1
  359. elif pvb == 0 and state == 1:
  360. state = 2
  361. if state != 2:
  362. raise Exception("Didn't observe TIM bit getting set and unset (state=%d)" % state)
  363. def test_ap_open_select_network(dev, apdev):
  364. """Open mode connection and SELECT_NETWORK to change network"""
  365. hapd1 = hostapd.add_ap(apdev[0]['ifname'], { "ssid": "open" })
  366. bssid1 = apdev[0]['bssid']
  367. hapd2 = hostapd.add_ap(apdev[1]['ifname'], { "ssid": "open2" })
  368. bssid2 = apdev[1]['bssid']
  369. id1 = dev[0].connect("open", key_mgmt="NONE", scan_freq="2412",
  370. only_add_network=True)
  371. id2 = dev[0].connect("open2", key_mgmt="NONE", scan_freq="2412")
  372. hwsim_utils.test_connectivity(dev[0], hapd2)
  373. dev[0].select_network(id1)
  374. dev[0].wait_connected()
  375. res = dev[0].request("BLACKLIST")
  376. if bssid1 in res or bssid2 in res:
  377. raise Exception("Unexpected blacklist entry")
  378. hwsim_utils.test_connectivity(dev[0], hapd1)
  379. dev[0].select_network(id2)
  380. dev[0].wait_connected()
  381. hwsim_utils.test_connectivity(dev[0], hapd2)
  382. res = dev[0].request("BLACKLIST")
  383. if bssid1 in res or bssid2 in res:
  384. raise Exception("Unexpected blacklist entry(2)")
  385. def test_ap_open_disable_enable(dev, apdev):
  386. """AP with open mode getting disabled and re-enabled"""
  387. hapd = hostapd.add_ap(apdev[0]['ifname'], { "ssid": "open" })
  388. dev[0].connect("open", key_mgmt="NONE", scan_freq="2412",
  389. bg_scan_period="0")
  390. for i in range(2):
  391. hapd.request("DISABLE")
  392. dev[0].wait_disconnected()
  393. hapd.request("ENABLE")
  394. dev[0].wait_connected()
  395. hwsim_utils.test_connectivity(dev[0], hapd)
  396. def sta_enable_disable(dev, bssid):
  397. dev.scan_for_bss(bssid, freq=2412)
  398. work_id = dev.request("RADIO_WORK add block-work")
  399. ev = dev.wait_event(["EXT-RADIO-WORK-START"])
  400. if ev is None:
  401. raise Exception("Timeout while waiting radio work to start")
  402. id = dev.connect("open", key_mgmt="NONE", scan_freq="2412",
  403. only_add_network=True)
  404. dev.request("ENABLE_NETWORK %d" % id)
  405. if "connect@" not in dev.request("RADIO_WORK show"):
  406. raise Exception("connect radio work missing")
  407. dev.request("DISABLE_NETWORK %d" % id)
  408. dev.request("RADIO_WORK done " + work_id)
  409. ok = False
  410. for i in range(30):
  411. if "connect@" not in dev.request("RADIO_WORK show"):
  412. ok = True
  413. break
  414. time.sleep(0.1)
  415. if not ok:
  416. raise Exception("connect radio work not completed")
  417. ev = dev.wait_event(["CTRL-EVENT-CONNECTED"], timeout=0.1)
  418. if ev is not None:
  419. raise Exception("Unexpected connection")
  420. dev.request("DISCONNECT")
  421. def test_ap_open_sta_enable_disable(dev, apdev):
  422. """AP with open mode and wpa_supplicant ENABLE/DISABLE_NETWORK"""
  423. hapd = hostapd.add_ap(apdev[0]['ifname'], { "ssid": "open" })
  424. bssid = apdev[0]['bssid']
  425. sta_enable_disable(dev[0], bssid)
  426. wpas = WpaSupplicant(global_iface='/tmp/wpas-wlan5')
  427. wpas.interface_add("wlan5", drv_params="force_connect_cmd=1")
  428. sta_enable_disable(wpas, bssid)
  429. def test_ap_open_select_twice(dev, apdev):
  430. """AP with open mode and select network twice"""
  431. id = dev[0].connect("open", key_mgmt="NONE", scan_freq="2412",
  432. only_add_network=True)
  433. dev[0].select_network(id)
  434. ev = dev[0].wait_event(["CTRL-EVENT-NETWORK-NOT-FOUND"], timeout=10)
  435. if ev is None:
  436. raise Exception("No result reported")
  437. hapd = hostapd.add_ap(apdev[0]['ifname'], { "ssid": "open" })
  438. # Verify that the second SELECT_NETWORK starts a new scan immediately by
  439. # waiting less than the default scan period.
  440. dev[0].select_network(id)
  441. dev[0].wait_connected(timeout=3)
  442. def test_ap_open_reassoc_not_found(dev, apdev):
  443. """AP with open mode and REASSOCIATE not finding a match"""
  444. id = dev[0].connect("open", key_mgmt="NONE", scan_freq="2412",
  445. only_add_network=True)
  446. dev[0].select_network(id)
  447. ev = dev[0].wait_event(["CTRL-EVENT-NETWORK-NOT-FOUND"], timeout=10)
  448. if ev is None:
  449. raise Exception("No result reported")
  450. dev[0].request("DISCONNECT")
  451. time.sleep(0.1)
  452. dev[0].dump_monitor()
  453. dev[0].request("REASSOCIATE")
  454. ev = dev[0].wait_event(["CTRL-EVENT-NETWORK-NOT-FOUND"], timeout=10)
  455. if ev is None:
  456. raise Exception("No result reported")
  457. dev[0].request("DISCONNECT")