From 708ec753bcca329e5b22cdb51aa6f80afc8fd270 Mon Sep 17 00:00:00 2001 From: Jouni Malinen Date: Tue, 11 Aug 2015 21:48:55 +0300 Subject: [PATCH] tests: ap_scan=2 AP mode operation and scan failure Signed-off-by: Jouni Malinen --- src/drivers/driver_nl80211_scan.c | 3 ++ tests/hwsim/test_dbus.py | 53 ++++++++++++++++++++++++++++++- tests/hwsim/test_scan.py | 49 +++++++++++++++++++++++++++- 3 files changed, 103 insertions(+), 2 deletions(-) diff --git a/src/drivers/driver_nl80211_scan.c b/src/drivers/driver_nl80211_scan.c index 9cd3162ff..c37ab49e4 100644 --- a/src/drivers/driver_nl80211_scan.c +++ b/src/drivers/driver_nl80211_scan.c @@ -221,6 +221,9 @@ int wpa_driver_nl80211_scan(struct i802_bss *bss, wpa_dbg(drv->ctx, MSG_DEBUG, "nl80211: scan request"); drv->scan_for_auth = 0; + if (TEST_FAIL()) + return -1; + msg = nl80211_scan_common(bss, NL80211_CMD_TRIGGER_SCAN, params); if (!msg) return -1; diff --git a/tests/hwsim/test_dbus.py b/tests/hwsim/test_dbus.py index 650c0d915..12a0ffb4f 100644 --- a/tests/hwsim/test_dbus.py +++ b/tests/hwsim/test_dbus.py @@ -19,7 +19,7 @@ except ImportError: import hostapd from wpasupplicant import WpaSupplicant -from utils import HwsimSkip, alloc_fail +from utils import HwsimSkip, alloc_fail, fail_test from test_ap_tdls import connect_2sta_open WPAS_DBUS_SERVICE = "fi.w1.wpa_supplicant1" @@ -4813,3 +4813,54 @@ def test_dbus_connect_wpa_eap(dev, apdev): with TestDbusConnect(bus) as t: if not t.success(): raise Exception("Expected signals not seen") + +def test_dbus_ap_scan_2_ap_mode_scan(dev, apdev): + """AP_SCAN 2 AP mode and D-Bus Scan()""" + try: + _test_dbus_ap_scan_2_ap_mode_scan(dev, apdev) + finally: + dev[0].request("AP_SCAN 1") + +def _test_dbus_ap_scan_2_ap_mode_scan(dev, apdev): + (bus,wpas_obj,path,if_obj) = prepare_dbus(dev[0]) + iface = dbus.Interface(if_obj, WPAS_DBUS_IFACE) + + if "OK" not in dev[0].request("AP_SCAN 2"): + raise Exception("Failed to set AP_SCAN 2") + + id = dev[0].add_network() + dev[0].set_network(id, "mode", "2") + dev[0].set_network_quoted(id, "ssid", "wpas-ap-open") + dev[0].set_network(id, "key_mgmt", "NONE") + dev[0].set_network(id, "frequency", "2412") + dev[0].set_network(id, "scan_freq", "2412") + dev[0].set_network(id, "disabled", "0") + dev[0].select_network(id) + ev = dev[0].wait_event(["CTRL-EVENT-CONNECTED"], timeout=5) + if ev is None: + raise Exception("AP failed to start") + + with fail_test(dev[0], 1, "wpa_driver_nl80211_scan"): + iface.Scan({'Type': 'active', + 'AllowRoam': True, + 'Channels': [(dbus.UInt32(2412), dbus.UInt32(20))]}) + ev = dev[0].wait_event(["CTRL-EVENT-SCAN-FAILED", + "AP-DISABLED"], timeout=5) + if ev is None: + raise Exception("CTRL-EVENT-SCAN-FAILED not seen") + if "AP-DISABLED" in ev: + raise Exception("Unexpected AP-DISABLED event") + if "retry=1" in ev: + # Wait for the retry to scan happen + ev = dev[0].wait_event(["CTRL-EVENT-SCAN-FAILED", + "AP-DISABLED"], timeout=5) + if ev is None: + raise Exception("CTRL-EVENT-SCAN-FAILED not seen - retry") + if "AP-DISABLED" in ev: + raise Exception("Unexpected AP-DISABLED event - retry") + + dev[1].connect("wpas-ap-open", key_mgmt="NONE", scan_freq="2412") + dev[1].request("DISCONNECT") + dev[1].wait_disconnected() + dev[0].request("DISCONNECT") + dev[0].wait_disconnected() diff --git a/tests/hwsim/test_scan.py b/tests/hwsim/test_scan.py index 20c245264..d0e94f9d7 100644 --- a/tests/hwsim/test_scan.py +++ b/tests/hwsim/test_scan.py @@ -12,7 +12,7 @@ import subprocess import hostapd from wpasupplicant import WpaSupplicant -from utils import HwsimSkip +from utils import HwsimSkip, fail_test from tshark import run_tshark def check_scan(dev, params, other_started=False, test_busy=False): @@ -805,3 +805,50 @@ def test_scan_specify_ssid(dev, apdev): if "FAIL" not in dev[0].request("SCAN ssid foo"): raise Exception("Invalid SCAN command accepted") + +def test_scan_ap_scan_2_ap_mode(dev, apdev): + """AP_SCAN 2 AP mode and scan()""" + try: + _test_scan_ap_scan_2_ap_mode(dev, apdev) + finally: + dev[0].request("AP_SCAN 1") + +def _test_scan_ap_scan_2_ap_mode(dev, apdev): + if "OK" not in dev[0].request("AP_SCAN 2"): + raise Exception("Failed to set AP_SCAN 2") + + id = dev[0].add_network() + dev[0].set_network(id, "mode", "2") + dev[0].set_network_quoted(id, "ssid", "wpas-ap-open") + dev[0].set_network(id, "key_mgmt", "NONE") + dev[0].set_network(id, "frequency", "2412") + dev[0].set_network(id, "scan_freq", "2412") + dev[0].set_network(id, "disabled", "0") + dev[0].select_network(id) + ev = dev[0].wait_event(["CTRL-EVENT-CONNECTED"], timeout=5) + if ev is None: + raise Exception("AP failed to start") + + with fail_test(dev[0], 1, "wpa_driver_nl80211_scan"): + if "OK" not in dev[0].request("SCAN freq=2412"): + raise Exception("SCAN command failed unexpectedly") + ev = dev[0].wait_event(["CTRL-EVENT-SCAN-FAILED", + "AP-DISABLED"], timeout=5) + if ev is None: + raise Exception("CTRL-EVENT-SCAN-FAILED not seen") + if "AP-DISABLED" in ev: + raise Exception("Unexpected AP-DISABLED event") + if "retry=1" in ev: + # Wait for the retry to scan happen + ev = dev[0].wait_event(["CTRL-EVENT-SCAN-FAILED", + "AP-DISABLED"], timeout=5) + if ev is None: + raise Exception("CTRL-EVENT-SCAN-FAILED not seen - retry") + if "AP-DISABLED" in ev: + raise Exception("Unexpected AP-DISABLED event - retry") + + dev[1].connect("wpas-ap-open", key_mgmt="NONE", scan_freq="2412") + dev[1].request("DISCONNECT") + dev[1].wait_disconnected() + dev[0].request("DISCONNECT") + dev[0].wait_disconnected()