test_ap_open.py 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657
  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, fail_test, wait_fail_trigger
  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. def test_ap_open_external_assoc(dev, apdev):
  167. """AP with open mode and external association"""
  168. hapd = hostapd.add_ap(apdev[0], { "ssid": "open-ext-assoc" })
  169. try:
  170. dev[0].request("STA_AUTOCONNECT 0")
  171. id = dev[0].connect("open-ext-assoc", key_mgmt="NONE", scan_freq="2412",
  172. only_add_network=True)
  173. dev[0].request("ENABLE_NETWORK %s no-connect" % id)
  174. dev[0].dump_monitor()
  175. # This will be accepted due to matching network
  176. dev[0].cmd_execute(['iw', 'dev', dev[0].ifname, 'connect',
  177. 'open-ext-assoc', "2412", apdev[0]['bssid']])
  178. ev = dev[0].wait_event([ "CTRL-EVENT-DISCONNECTED",
  179. "CTRL-EVENT-CONNECTED" ], timeout=10)
  180. if ev is None:
  181. raise Exception("Connection timed out")
  182. if "CTRL-EVENT-DISCONNECTED" in ev:
  183. raise Exception("Unexpected disconnection event")
  184. dev[0].dump_monitor()
  185. dev[0].request("DISCONNECT")
  186. dev[0].wait_disconnected(timeout=5)
  187. finally:
  188. dev[0].request("STA_AUTOCONNECT 1")
  189. @remote_compatible
  190. def test_ap_bss_load(dev, apdev):
  191. """AP with open mode (no security) configuration"""
  192. hapd = hostapd.add_ap(apdev[0],
  193. { "ssid": "open",
  194. "bss_load_update_period": "10" })
  195. dev[0].connect("open", key_mgmt="NONE", scan_freq="2412")
  196. # this does not really get much useful output with mac80211_hwsim currently,
  197. # but run through the channel survey update couple of times
  198. for i in range(0, 10):
  199. hwsim_utils.test_connectivity(dev[0], hapd)
  200. hwsim_utils.test_connectivity(dev[0], hapd)
  201. hwsim_utils.test_connectivity(dev[0], hapd)
  202. time.sleep(0.15)
  203. def hapd_out_of_mem(hapd, apdev, count, func):
  204. with alloc_fail(hapd, count, func):
  205. started = False
  206. try:
  207. hostapd.add_ap(apdev, { "ssid": "open" })
  208. started = True
  209. except:
  210. pass
  211. if started:
  212. raise Exception("hostapd interface started even with memory allocation failure: %d:%s" % (count, func))
  213. def test_ap_open_out_of_memory(dev, apdev):
  214. """hostapd failing to setup interface due to allocation failure"""
  215. hapd = hostapd.add_ap(apdev[0], { "ssid": "open" })
  216. hapd_out_of_mem(hapd, apdev[1], 1, "hostapd_alloc_bss_data")
  217. for i in range(1, 3):
  218. hapd_out_of_mem(hapd, apdev[1], i, "hostapd_iface_alloc")
  219. for i in range(1, 5):
  220. hapd_out_of_mem(hapd, apdev[1], i, "hostapd_config_defaults;hostapd_config_alloc")
  221. hapd_out_of_mem(hapd, apdev[1], 1, "hostapd_config_alloc")
  222. hapd_out_of_mem(hapd, apdev[1], 1, "hostapd_driver_init")
  223. for i in range(1, 3):
  224. hapd_out_of_mem(hapd, apdev[1], i, "=wpa_driver_nl80211_drv_init")
  225. # eloop_register_read_sock() call from i802_init()
  226. hapd_out_of_mem(hapd, apdev[1], 1, "eloop_sock_table_add_sock;?eloop_register_sock;?eloop_register_read_sock;=i802_init")
  227. # verify that a new interface can still be added when memory allocation does
  228. # not fail
  229. hostapd.add_ap(apdev[1], { "ssid": "open" })
  230. def test_bssid_black_white_list(dev, apdev):
  231. """BSSID black/white list"""
  232. hapd = hostapd.add_ap(apdev[0], { "ssid": "open" })
  233. hapd2 = hostapd.add_ap(apdev[1], { "ssid": "open" })
  234. dev[0].connect("open", key_mgmt="NONE", scan_freq="2412",
  235. bssid_whitelist=apdev[1]['bssid'])
  236. dev[1].connect("open", key_mgmt="NONE", scan_freq="2412",
  237. bssid_blacklist=apdev[1]['bssid'])
  238. dev[2].connect("open", key_mgmt="NONE", scan_freq="2412",
  239. bssid_whitelist="00:00:00:00:00:00/00:00:00:00:00:00",
  240. bssid_blacklist=apdev[1]['bssid'])
  241. if dev[0].get_status_field('bssid') != apdev[1]['bssid']:
  242. raise Exception("dev[0] connected to unexpected AP")
  243. if dev[1].get_status_field('bssid') != apdev[0]['bssid']:
  244. raise Exception("dev[1] connected to unexpected AP")
  245. if dev[2].get_status_field('bssid') != apdev[0]['bssid']:
  246. raise Exception("dev[2] connected to unexpected AP")
  247. dev[0].request("REMOVE_NETWORK all")
  248. dev[1].request("REMOVE_NETWORK all")
  249. dev[2].request("REMOVE_NETWORK all")
  250. dev[2].connect("open", key_mgmt="NONE", scan_freq="2412",
  251. bssid_whitelist="00:00:00:00:00:00", wait_connect=False)
  252. dev[0].connect("open", key_mgmt="NONE", scan_freq="2412",
  253. bssid_whitelist="11:22:33:44:55:66/ff:00:00:00:00:00 " + apdev[1]['bssid'] + " aa:bb:cc:dd:ee:ff")
  254. dev[1].connect("open", key_mgmt="NONE", scan_freq="2412",
  255. bssid_blacklist="11:22:33:44:55:66/ff:00:00:00:00:00 " + apdev[1]['bssid'] + " aa:bb:cc:dd:ee:ff")
  256. if dev[0].get_status_field('bssid') != apdev[1]['bssid']:
  257. raise Exception("dev[0] connected to unexpected AP")
  258. if dev[1].get_status_field('bssid') != apdev[0]['bssid']:
  259. raise Exception("dev[1] connected to unexpected AP")
  260. dev[0].request("REMOVE_NETWORK all")
  261. dev[1].request("REMOVE_NETWORK all")
  262. ev = dev[2].wait_event(["CTRL-EVENT-CONNECTED"], timeout=0.1)
  263. if ev is not None:
  264. raise Exception("Unexpected dev[2] connectin")
  265. dev[2].request("REMOVE_NETWORK all")
  266. def test_ap_open_wpas_in_bridge(dev, apdev):
  267. """Open mode AP and wpas interface in a bridge"""
  268. br_ifname='sta-br0'
  269. ifname='wlan5'
  270. try:
  271. _test_ap_open_wpas_in_bridge(dev, apdev)
  272. finally:
  273. subprocess.call(['ip', 'link', 'set', 'dev', br_ifname, 'down'])
  274. subprocess.call(['brctl', 'delif', br_ifname, ifname])
  275. subprocess.call(['brctl', 'delbr', br_ifname])
  276. subprocess.call(['iw', ifname, 'set', '4addr', 'off'])
  277. def _test_ap_open_wpas_in_bridge(dev, apdev):
  278. hapd = hostapd.add_ap(apdev[0], { "ssid": "open" })
  279. br_ifname='sta-br0'
  280. ifname='wlan5'
  281. wpas = WpaSupplicant(global_iface='/tmp/wpas-wlan5')
  282. # First, try a failure case of adding an interface
  283. try:
  284. wpas.interface_add(ifname, br_ifname=br_ifname)
  285. raise Exception("Interface addition succeeded unexpectedly")
  286. except Exception, e:
  287. if "Failed to add" in str(e):
  288. logger.info("Ignore expected interface_add failure due to missing bridge interface: " + str(e))
  289. else:
  290. raise
  291. # Next, add the bridge interface and add the interface again
  292. subprocess.call(['brctl', 'addbr', br_ifname])
  293. subprocess.call(['brctl', 'setfd', br_ifname, '0'])
  294. subprocess.call(['ip', 'link', 'set', 'dev', br_ifname, 'up'])
  295. subprocess.call(['iw', ifname, 'set', '4addr', 'on'])
  296. subprocess.check_call(['brctl', 'addif', br_ifname, ifname])
  297. wpas.interface_add(ifname, br_ifname=br_ifname)
  298. wpas.connect("open", key_mgmt="NONE", scan_freq="2412")
  299. @remote_compatible
  300. def test_ap_open_start_disabled(dev, apdev):
  301. """AP with open mode and beaconing disabled"""
  302. hapd = hostapd.add_ap(apdev[0], { "ssid": "open",
  303. "start_disabled": "1" })
  304. bssid = apdev[0]['bssid']
  305. dev[0].flush_scan_cache()
  306. dev[0].scan(freq=2412, only_new=True)
  307. if dev[0].get_bss(bssid) is not None:
  308. raise Exception("AP was seen beaconing")
  309. if "OK" not in hapd.request("RELOAD"):
  310. raise Exception("RELOAD failed")
  311. dev[0].scan_for_bss(bssid, freq=2412)
  312. dev[0].connect("open", key_mgmt="NONE", scan_freq="2412")
  313. @remote_compatible
  314. def test_ap_open_start_disabled2(dev, apdev):
  315. """AP with open mode and beaconing disabled (2)"""
  316. hapd = hostapd.add_ap(apdev[0], { "ssid": "open",
  317. "start_disabled": "1" })
  318. bssid = apdev[0]['bssid']
  319. dev[0].flush_scan_cache()
  320. dev[0].scan(freq=2412, only_new=True)
  321. if dev[0].get_bss(bssid) is not None:
  322. raise Exception("AP was seen beaconing")
  323. if "OK" not in hapd.request("UPDATE_BEACON"):
  324. raise Exception("UPDATE_BEACON failed")
  325. dev[0].scan_for_bss(bssid, freq=2412)
  326. dev[0].connect("open", key_mgmt="NONE", scan_freq="2412")
  327. if "OK" not in hapd.request("UPDATE_BEACON"):
  328. raise Exception("UPDATE_BEACON failed")
  329. dev[0].request("DISCONNECT")
  330. dev[0].wait_disconnected()
  331. dev[0].request("RECONNECT")
  332. dev[0].wait_connected()
  333. @remote_compatible
  334. def test_ap_open_ifdown(dev, apdev):
  335. """AP with open mode and external ifconfig down"""
  336. params = { "ssid": "open",
  337. "ap_max_inactivity": "1" }
  338. hapd = hostapd.add_ap(apdev[0], params)
  339. bssid = apdev[0]['bssid']
  340. dev[0].connect("open", key_mgmt="NONE", scan_freq="2412")
  341. dev[1].connect("open", key_mgmt="NONE", scan_freq="2412")
  342. hapd.cmd_execute(['ip', 'link', 'set', 'dev', apdev[0]['ifname'], 'down'])
  343. ev = hapd.wait_event(["AP-STA-DISCONNECTED"], timeout=10)
  344. if ev is None:
  345. raise Exception("Timeout on AP-STA-DISCONNECTED (1)")
  346. ev = hapd.wait_event(["AP-STA-DISCONNECTED"], timeout=5)
  347. if ev is None:
  348. raise Exception("Timeout on AP-STA-DISCONNECTED (2)")
  349. ev = hapd.wait_event(["INTERFACE-DISABLED"], timeout=5)
  350. if ev is None:
  351. raise Exception("No INTERFACE-DISABLED event")
  352. # The following wait tests beacon loss detection in mac80211 on dev0.
  353. # dev1 is used to test stopping of AP side functionality on client polling.
  354. dev[1].request("REMOVE_NETWORK all")
  355. hapd.cmd_execute(['ip', 'link', 'set', 'dev', apdev[0]['ifname'], 'up'])
  356. dev[0].wait_disconnected()
  357. dev[1].wait_disconnected()
  358. ev = hapd.wait_event(["INTERFACE-ENABLED"], timeout=10)
  359. if ev is None:
  360. raise Exception("No INTERFACE-ENABLED event")
  361. dev[0].wait_connected()
  362. hwsim_utils.test_connectivity(dev[0], hapd)
  363. def test_ap_open_disconnect_in_ps(dev, apdev, params):
  364. """Disconnect with the client in PS to regression-test a kernel bug"""
  365. hapd = hostapd.add_ap(apdev[0], { "ssid": "open" })
  366. dev[0].connect("open", key_mgmt="NONE", scan_freq="2412",
  367. bg_scan_period="0")
  368. ev = hapd.wait_event([ "AP-STA-CONNECTED" ], timeout=5)
  369. if ev is None:
  370. raise Exception("No connection event received from hostapd")
  371. time.sleep(0.2)
  372. hwsim_utils.set_powersave(dev[0], hwsim_utils.PS_MANUAL_POLL)
  373. try:
  374. # inject some traffic
  375. sa = hapd.own_addr()
  376. da = dev[0].own_addr()
  377. hapd.request('DATA_TEST_CONFIG 1')
  378. hapd.request('DATA_TEST_TX {} {} 0'.format(da, sa))
  379. hapd.request('DATA_TEST_CONFIG 0')
  380. # let the AP send couple of Beacon frames
  381. time.sleep(0.3)
  382. # disconnect - with traffic pending - shouldn't cause kernel warnings
  383. dev[0].request("DISCONNECT")
  384. finally:
  385. hwsim_utils.set_powersave(dev[0], hwsim_utils.PS_DISABLED)
  386. time.sleep(0.2)
  387. out = run_tshark(os.path.join(params['logdir'], "hwsim0.pcapng"),
  388. "wlan_mgt.tim.partial_virtual_bitmap",
  389. ["wlan_mgt.tim.partial_virtual_bitmap"])
  390. if out is not None:
  391. state = 0
  392. for l in out.splitlines():
  393. pvb = int(l, 16)
  394. if pvb > 0 and state == 0:
  395. state = 1
  396. elif pvb == 0 and state == 1:
  397. state = 2
  398. if state != 2:
  399. raise Exception("Didn't observe TIM bit getting set and unset (state=%d)" % state)
  400. @remote_compatible
  401. def test_ap_open_select_network(dev, apdev):
  402. """Open mode connection and SELECT_NETWORK to change network"""
  403. hapd1 = hostapd.add_ap(apdev[0], { "ssid": "open" })
  404. bssid1 = apdev[0]['bssid']
  405. hapd2 = hostapd.add_ap(apdev[1], { "ssid": "open2" })
  406. bssid2 = apdev[1]['bssid']
  407. id1 = dev[0].connect("open", key_mgmt="NONE", scan_freq="2412",
  408. only_add_network=True)
  409. id2 = dev[0].connect("open2", key_mgmt="NONE", scan_freq="2412")
  410. hwsim_utils.test_connectivity(dev[0], hapd2)
  411. dev[0].select_network(id1)
  412. dev[0].wait_connected()
  413. res = dev[0].request("BLACKLIST")
  414. if bssid1 in res or bssid2 in res:
  415. raise Exception("Unexpected blacklist entry")
  416. hwsim_utils.test_connectivity(dev[0], hapd1)
  417. dev[0].select_network(id2)
  418. dev[0].wait_connected()
  419. hwsim_utils.test_connectivity(dev[0], hapd2)
  420. res = dev[0].request("BLACKLIST")
  421. if bssid1 in res or bssid2 in res:
  422. raise Exception("Unexpected blacklist entry(2)")
  423. @remote_compatible
  424. def test_ap_open_disable_enable(dev, apdev):
  425. """AP with open mode getting disabled and re-enabled"""
  426. hapd = hostapd.add_ap(apdev[0], { "ssid": "open" })
  427. dev[0].connect("open", key_mgmt="NONE", scan_freq="2412",
  428. bg_scan_period="0")
  429. for i in range(2):
  430. hapd.request("DISABLE")
  431. dev[0].wait_disconnected()
  432. hapd.request("ENABLE")
  433. dev[0].wait_connected()
  434. hwsim_utils.test_connectivity(dev[0], hapd)
  435. def sta_enable_disable(dev, bssid):
  436. dev.scan_for_bss(bssid, freq=2412)
  437. work_id = dev.request("RADIO_WORK add block-work")
  438. ev = dev.wait_event(["EXT-RADIO-WORK-START"])
  439. if ev is None:
  440. raise Exception("Timeout while waiting radio work to start")
  441. id = dev.connect("open", key_mgmt="NONE", scan_freq="2412",
  442. only_add_network=True)
  443. dev.request("ENABLE_NETWORK %d" % id)
  444. if "connect@" not in dev.request("RADIO_WORK show"):
  445. raise Exception("connect radio work missing")
  446. dev.request("DISABLE_NETWORK %d" % id)
  447. dev.request("RADIO_WORK done " + work_id)
  448. ok = False
  449. for i in range(30):
  450. if "connect@" not in dev.request("RADIO_WORK show"):
  451. ok = True
  452. break
  453. time.sleep(0.1)
  454. if not ok:
  455. raise Exception("connect radio work not completed")
  456. ev = dev.wait_event(["CTRL-EVENT-CONNECTED"], timeout=0.1)
  457. if ev is not None:
  458. raise Exception("Unexpected connection")
  459. dev.request("DISCONNECT")
  460. def test_ap_open_sta_enable_disable(dev, apdev):
  461. """AP with open mode and wpa_supplicant ENABLE/DISABLE_NETWORK"""
  462. hapd = hostapd.add_ap(apdev[0], { "ssid": "open" })
  463. bssid = apdev[0]['bssid']
  464. sta_enable_disable(dev[0], bssid)
  465. wpas = WpaSupplicant(global_iface='/tmp/wpas-wlan5')
  466. wpas.interface_add("wlan5", drv_params="force_connect_cmd=1")
  467. sta_enable_disable(wpas, bssid)
  468. @remote_compatible
  469. def test_ap_open_select_twice(dev, apdev):
  470. """AP with open mode and select network twice"""
  471. id = dev[0].connect("open", key_mgmt="NONE", scan_freq="2412",
  472. only_add_network=True)
  473. dev[0].select_network(id)
  474. ev = dev[0].wait_event(["CTRL-EVENT-NETWORK-NOT-FOUND"], timeout=10)
  475. if ev is None:
  476. raise Exception("No result reported")
  477. hapd = hostapd.add_ap(apdev[0], { "ssid": "open" })
  478. # Verify that the second SELECT_NETWORK starts a new scan immediately by
  479. # waiting less than the default scan period.
  480. dev[0].select_network(id)
  481. dev[0].wait_connected(timeout=3)
  482. @remote_compatible
  483. def test_ap_open_reassoc_not_found(dev, apdev):
  484. """AP with open mode and REASSOCIATE not finding a match"""
  485. id = dev[0].connect("open", key_mgmt="NONE", scan_freq="2412",
  486. only_add_network=True)
  487. dev[0].select_network(id)
  488. ev = dev[0].wait_event(["CTRL-EVENT-NETWORK-NOT-FOUND"], timeout=10)
  489. if ev is None:
  490. raise Exception("No result reported")
  491. dev[0].request("DISCONNECT")
  492. time.sleep(0.1)
  493. dev[0].dump_monitor()
  494. dev[0].request("REASSOCIATE")
  495. ev = dev[0].wait_event(["CTRL-EVENT-NETWORK-NOT-FOUND"], timeout=10)
  496. if ev is None:
  497. raise Exception("No result reported")
  498. dev[0].request("DISCONNECT")
  499. @remote_compatible
  500. def test_ap_open_sta_statistics(dev, apdev):
  501. """AP with open mode and STA statistics"""
  502. hapd = hostapd.add_ap(apdev[0], { "ssid": "open" })
  503. dev[0].connect("open", key_mgmt="NONE", scan_freq="2412")
  504. addr = dev[0].own_addr()
  505. stats1 = hapd.get_sta(addr)
  506. logger.info("stats1: " + str(stats1))
  507. time.sleep(0.4)
  508. stats2 = hapd.get_sta(addr)
  509. logger.info("stats2: " + str(stats2))
  510. hwsim_utils.test_connectivity(dev[0], hapd)
  511. stats3 = hapd.get_sta(addr)
  512. logger.info("stats3: " + str(stats3))
  513. # Cannot require specific inactive_msec changes without getting rid of all
  514. # unrelated traffic, so for now, just print out the results in the log for
  515. # manual checks.
  516. @remote_compatible
  517. def test_ap_open_poll_sta(dev, apdev):
  518. """AP with open mode and STA poll"""
  519. hapd = hostapd.add_ap(apdev[0], { "ssid": "open" })
  520. dev[0].connect("open", key_mgmt="NONE", scan_freq="2412")
  521. addr = dev[0].own_addr()
  522. if "OK" not in hapd.request("POLL_STA " + addr):
  523. raise Exception("POLL_STA failed")
  524. ev = hapd.wait_event(["AP-STA-POLL-OK"], timeout=5)
  525. if ev is None:
  526. raise Exception("Poll response not seen")
  527. if addr not in ev:
  528. raise Exception("Unexpected poll response: " + ev)
  529. def test_ap_open_pmf_default(dev, apdev):
  530. """AP with open mode (no security) configuration and pmf=2"""
  531. hapd = hostapd.add_ap(apdev[0], { "ssid": "open" })
  532. dev[1].connect("open", key_mgmt="NONE", scan_freq="2412",
  533. ieee80211w="2", wait_connect=False)
  534. dev[2].connect("open", key_mgmt="NONE", scan_freq="2412",
  535. ieee80211w="1")
  536. try:
  537. dev[0].request("SET pmf 2")
  538. dev[0].connect("open", key_mgmt="NONE", scan_freq="2412")
  539. dev[0].request("DISCONNECT")
  540. dev[0].wait_disconnected()
  541. finally:
  542. dev[0].request("SET pmf 0")
  543. dev[2].request("DISCONNECT")
  544. dev[2].wait_disconnected()
  545. ev = dev[1].wait_event(["CTRL-EVENT-CONNECTED"], timeout=0.1)
  546. if ev is not None:
  547. raise Exception("Unexpected dev[1] connection")
  548. dev[1].request("DISCONNECT")
  549. def test_ap_open_drv_fail(dev, apdev):
  550. """AP with open mode and driver operations failing"""
  551. hapd = hostapd.add_ap(apdev[0], { "ssid": "open" })
  552. with fail_test(dev[0], 1, "wpa_driver_nl80211_authenticate"):
  553. dev[0].connect("open", key_mgmt="NONE", scan_freq="2412",
  554. wait_connect=False)
  555. wait_fail_trigger(dev[0], "GET_FAIL")
  556. dev[0].request("REMOVE_NETWORK all")
  557. with fail_test(dev[0], 1, "wpa_driver_nl80211_associate"):
  558. dev[0].connect("open", key_mgmt="NONE", scan_freq="2412",
  559. wait_connect=False)
  560. wait_fail_trigger(dev[0], "GET_FAIL")
  561. dev[0].request("REMOVE_NETWORK all")
  562. def run_multicast_to_unicast(dev, apdev, convert):
  563. params = { "ssid": "open" }
  564. params["multicast_to_unicast"] = "1" if convert else "0"
  565. hapd = hostapd.add_ap(apdev[0], params)
  566. dev[0].scan_for_bss(hapd.own_addr(), freq=2412)
  567. dev[0].connect("open", key_mgmt="NONE", scan_freq="2412")
  568. ev = hapd.wait_event([ "AP-STA-CONNECTED" ], timeout=5)
  569. if ev is None:
  570. raise Exception("No connection event received from hostapd")
  571. hwsim_utils.test_connectivity(dev[0], hapd, multicast_to_unicast=convert)
  572. dev[0].request("DISCONNECT")
  573. ev = hapd.wait_event([ "AP-STA-DISCONNECTED" ], timeout=5)
  574. if ev is None:
  575. raise Exception("No disconnection event received from hostapd")
  576. def test_ap_open_multicast_to_unicast(dev, apdev):
  577. """Multicast-to-unicast conversion enabled"""
  578. run_multicast_to_unicast(dev, apdev, True)
  579. def test_ap_open_multicast_to_unicast_disabled(dev, apdev):
  580. """Multicast-to-unicast conversion disabled"""
  581. run_multicast_to_unicast(dev, apdev, False)