test_ap_open.py 23 KB

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