# Open mode AP tests # Copyright (c) 2014, Qualcomm Atheros, Inc. # # This software may be distributed under the terms of the BSD license. # See README for more details. import logging logger = logging.getLogger() import struct import subprocess import time import os import hostapd import hwsim_utils from tshark import run_tshark from utils import alloc_fail from wpasupplicant import WpaSupplicant def test_ap_open(dev, apdev): """AP with open mode (no security) configuration""" _test_ap_open(dev, apdev) def _test_ap_open(dev, apdev): hapd = hostapd.add_ap(apdev[0], { "ssid": "open" }) dev[0].connect("open", key_mgmt="NONE", scan_freq="2412", bg_scan_period="0") ev = hapd.wait_event([ "AP-STA-CONNECTED" ], timeout=5) if ev is None: raise Exception("No connection event received from hostapd") hwsim_utils.test_connectivity(dev[0], hapd) dev[0].request("DISCONNECT") ev = hapd.wait_event([ "AP-STA-DISCONNECTED" ], timeout=5) if ev is None: raise Exception("No disconnection event received from hostapd") def test_ap_open_packet_loss(dev, apdev): """AP with open mode configuration and large packet loss""" params = { "ssid": "open", "ignore_probe_probability": "0.5", "ignore_auth_probability": "0.5", "ignore_assoc_probability": "0.5", "ignore_reassoc_probability": "0.5" } hapd = hostapd.add_ap(apdev[0], params) for i in range(0, 3): dev[i].connect("open", key_mgmt="NONE", scan_freq="2412", wait_connect=False) for i in range(0, 3): dev[i].wait_connected(timeout=20) def test_ap_open_unknown_action(dev, apdev): """AP with open mode configuration and unknown Action frame""" hapd = hostapd.add_ap(apdev[0], { "ssid": "open" }) dev[0].connect("open", key_mgmt="NONE", scan_freq="2412") bssid = apdev[0]['bssid'] cmd = "MGMT_TX {} {} freq=2412 action=765432".format(bssid, bssid) if "FAIL" in dev[0].request(cmd): raise Exception("Could not send test Action frame") ev = dev[0].wait_event(["MGMT-TX-STATUS"], timeout=10) if ev is None: raise Exception("Timeout on MGMT-TX-STATUS") if "result=SUCCESS" not in ev: raise Exception("AP did not ack Action frame") def test_ap_open_invalid_wmm_action(dev, apdev): """AP with open mode configuration and invalid WMM Action frame""" hapd = hostapd.add_ap(apdev[0], { "ssid": "open" }) dev[0].connect("open", key_mgmt="NONE", scan_freq="2412") bssid = apdev[0]['bssid'] cmd = "MGMT_TX {} {} freq=2412 action=1100".format(bssid, bssid) if "FAIL" in dev[0].request(cmd): raise Exception("Could not send test Action frame") ev = dev[0].wait_event(["MGMT-TX-STATUS"], timeout=10) if ev is None or "result=SUCCESS" not in ev: raise Exception("AP did not ack Action frame") def test_ap_open_reconnect_on_inactivity_disconnect(dev, apdev): """Reconnect to open mode AP after inactivity related disconnection""" hapd = hostapd.add_ap(apdev[0], { "ssid": "open" }) dev[0].connect("open", key_mgmt="NONE", scan_freq="2412") hapd.request("DEAUTHENTICATE " + dev[0].p2p_interface_addr() + " reason=4") dev[0].wait_disconnected(timeout=5) dev[0].wait_connected(timeout=2, error="Timeout on reconnection") def test_ap_open_assoc_timeout(dev, apdev): """AP timing out association""" ssid = "test" hapd = hostapd.add_ap(apdev[0], { "ssid": "open" }) dev[0].scan(freq="2412") hapd.set("ext_mgmt_frame_handling", "1") dev[0].connect("open", key_mgmt="NONE", scan_freq="2412", wait_connect=False) for i in range(0, 10): req = hapd.mgmt_rx() if req is None: raise Exception("MGMT RX wait timed out") if req['subtype'] == 11: break req = None if not req: raise Exception("Authentication frame not received") resp = {} resp['fc'] = req['fc'] resp['da'] = req['sa'] resp['sa'] = req['da'] resp['bssid'] = req['bssid'] resp['payload'] = struct.pack(' 0 and state == 0: state = 1 elif pvb == 0 and state == 1: state = 2 if state != 2: raise Exception("Didn't observe TIM bit getting set and unset (state=%d)" % state) def test_ap_open_select_network(dev, apdev): """Open mode connection and SELECT_NETWORK to change network""" hapd1 = hostapd.add_ap(apdev[0], { "ssid": "open" }) bssid1 = apdev[0]['bssid'] hapd2 = hostapd.add_ap(apdev[1], { "ssid": "open2" }) bssid2 = apdev[1]['bssid'] id1 = dev[0].connect("open", key_mgmt="NONE", scan_freq="2412", only_add_network=True) id2 = dev[0].connect("open2", key_mgmt="NONE", scan_freq="2412") hwsim_utils.test_connectivity(dev[0], hapd2) dev[0].select_network(id1) dev[0].wait_connected() res = dev[0].request("BLACKLIST") if bssid1 in res or bssid2 in res: raise Exception("Unexpected blacklist entry") hwsim_utils.test_connectivity(dev[0], hapd1) dev[0].select_network(id2) dev[0].wait_connected() hwsim_utils.test_connectivity(dev[0], hapd2) res = dev[0].request("BLACKLIST") if bssid1 in res or bssid2 in res: raise Exception("Unexpected blacklist entry(2)") def test_ap_open_disable_enable(dev, apdev): """AP with open mode getting disabled and re-enabled""" hapd = hostapd.add_ap(apdev[0], { "ssid": "open" }) dev[0].connect("open", key_mgmt="NONE", scan_freq="2412", bg_scan_period="0") for i in range(2): hapd.request("DISABLE") dev[0].wait_disconnected() hapd.request("ENABLE") dev[0].wait_connected() hwsim_utils.test_connectivity(dev[0], hapd) def sta_enable_disable(dev, bssid): dev.scan_for_bss(bssid, freq=2412) work_id = dev.request("RADIO_WORK add block-work") ev = dev.wait_event(["EXT-RADIO-WORK-START"]) if ev is None: raise Exception("Timeout while waiting radio work to start") id = dev.connect("open", key_mgmt="NONE", scan_freq="2412", only_add_network=True) dev.request("ENABLE_NETWORK %d" % id) if "connect@" not in dev.request("RADIO_WORK show"): raise Exception("connect radio work missing") dev.request("DISABLE_NETWORK %d" % id) dev.request("RADIO_WORK done " + work_id) ok = False for i in range(30): if "connect@" not in dev.request("RADIO_WORK show"): ok = True break time.sleep(0.1) if not ok: raise Exception("connect radio work not completed") ev = dev.wait_event(["CTRL-EVENT-CONNECTED"], timeout=0.1) if ev is not None: raise Exception("Unexpected connection") dev.request("DISCONNECT") def test_ap_open_sta_enable_disable(dev, apdev): """AP with open mode and wpa_supplicant ENABLE/DISABLE_NETWORK""" hapd = hostapd.add_ap(apdev[0], { "ssid": "open" }) bssid = apdev[0]['bssid'] sta_enable_disable(dev[0], bssid) wpas = WpaSupplicant(global_iface='/tmp/wpas-wlan5') wpas.interface_add("wlan5", drv_params="force_connect_cmd=1") sta_enable_disable(wpas, bssid) def test_ap_open_select_twice(dev, apdev): """AP with open mode and select network twice""" id = dev[0].connect("open", key_mgmt="NONE", scan_freq="2412", only_add_network=True) dev[0].select_network(id) ev = dev[0].wait_event(["CTRL-EVENT-NETWORK-NOT-FOUND"], timeout=10) if ev is None: raise Exception("No result reported") hapd = hostapd.add_ap(apdev[0], { "ssid": "open" }) # Verify that the second SELECT_NETWORK starts a new scan immediately by # waiting less than the default scan period. dev[0].select_network(id) dev[0].wait_connected(timeout=3) def test_ap_open_reassoc_not_found(dev, apdev): """AP with open mode and REASSOCIATE not finding a match""" id = dev[0].connect("open", key_mgmt="NONE", scan_freq="2412", only_add_network=True) dev[0].select_network(id) ev = dev[0].wait_event(["CTRL-EVENT-NETWORK-NOT-FOUND"], timeout=10) if ev is None: raise Exception("No result reported") dev[0].request("DISCONNECT") time.sleep(0.1) dev[0].dump_monitor() dev[0].request("REASSOCIATE") ev = dev[0].wait_event(["CTRL-EVENT-NETWORK-NOT-FOUND"], timeout=10) if ev is None: raise Exception("No result reported") dev[0].request("DISCONNECT") def test_ap_open_sta_statistics(dev, apdev): """AP with open mode and STA statistics""" hapd = hostapd.add_ap(apdev[0], { "ssid": "open" }) dev[0].connect("open", key_mgmt="NONE", scan_freq="2412") addr = dev[0].own_addr() stats1 = hapd.get_sta(addr) logger.info("stats1: " + str(stats1)) time.sleep(0.4) stats2 = hapd.get_sta(addr) logger.info("stats2: " + str(stats2)) hwsim_utils.test_connectivity(dev[0], hapd) stats3 = hapd.get_sta(addr) logger.info("stats3: " + str(stats3)) # Cannot require specific inactive_msec changes without getting rid of all # unrelated traffic, so for now, just print out the results in the log for # manual checks. def test_ap_open_poll_sta(dev, apdev): """AP with open mode and STA poll""" hapd = hostapd.add_ap(apdev[0], { "ssid": "open" }) dev[0].connect("open", key_mgmt="NONE", scan_freq="2412") addr = dev[0].own_addr() if "OK" not in hapd.request("POLL_STA " + addr): raise Exception("POLL_STA failed") ev = hapd.wait_event(["AP-STA-POLL-OK"], timeout=5) if ev is None: raise Exception("Poll response not seen") if addr not in ev: raise Exception("Unexpected poll response: " + ev) def test_ap_open_pmf_default(dev, apdev): """AP with open mode (no security) configuration and pmf=2""" hapd = hostapd.add_ap(apdev[0], { "ssid": "open" }) dev[1].connect("open", key_mgmt="NONE", scan_freq="2412", ieee80211w="2", wait_connect=False) dev[2].connect("open", key_mgmt="NONE", scan_freq="2412", ieee80211w="1") try: dev[0].request("SET pmf 2") dev[0].connect("open", key_mgmt="NONE", scan_freq="2412") dev[0].request("DISCONNECT") dev[0].wait_disconnected() finally: dev[0].request("SET pmf 0") dev[2].request("DISCONNECT") dev[2].wait_disconnected() ev = dev[1].wait_event(["CTRL-EVENT-CONNECTED"], timeout=0.1) if ev is not None: raise Exception("Unexpected dev[1] connection") dev[1].request("DISCONNECT")