test_ap_open.py 23 KB

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