diff mbox series

[2/3] tests: add connecting-while-CSA tests

Message ID 20240328140657.16968637737e.I343be2981d629fb765485433459f24c7944da408@changeid
State Accepted
Headers show
Series [1/3] hostapd: add support for testing probe response elements | expand

Commit Message

Johannes Berg March 28, 2024, 1:06 p.m. UTC
From: Johannes Berg <johannes.berg@intel.com>

Add a few tests to validate what happens with connections
while an AP is doing CSA:
 - quiet to diff channel (shouldn't connect)
 - quiet to same channel (shouldn't connect)
 - non-quiet to diff channel (shouldn't connect)
 - non-quiet to same channel (should connect)

Signed-off-by: Johannes Berg <johannes.berg@intel.com>
---
 tests/hwsim/test_ap_csa.py | 63 ++++++++++++++++++++++++++++++++++++++
 1 file changed, 63 insertions(+)
diff mbox series

Patch

diff --git a/tests/hwsim/test_ap_csa.py b/tests/hwsim/test_ap_csa.py
index c9ac73291a21..f05eaf1d7ecd 100644
--- a/tests/hwsim/test_ap_csa.py
+++ b/tests/hwsim/test_ap_csa.py
@@ -193,3 +193,66 @@  def test_ap_csa_disable(dev, apdev):
     ap.enable()
     dev[0].wait_disconnected()
     dev[0].wait_connected()
+
+def _assoc_while_csa(dev, apdev, freq_to, blocktx):
+    params = {
+        "ssid": "ap-csa",
+        "hw_mode": "a",
+        "country_code": "FI",
+        "channel": "36",
+        "ieee80211n": "0",
+    }
+    ap = hostapd.add_ap(apdev[0], params)
+    count = 100 if blocktx else 20
+    delay = 1 + count / 10
+    cmd = f"CHAN_SWITCH {count} {freq_to}"
+    if blocktx:
+        cmd += " blocktx"
+    ap.request(cmd)
+
+    ev = ap.wait_event(["CTRL-EVENT-STARTED-CHANNEL-SWITCH"], timeout=10)
+    if ev is None:
+        raise Exception("Channel switch start event not seen")
+    if f"freq={freq_to}" not in ev:
+        raise Exception("Unexpected channel in CS started event")
+    try:
+        dev[0].connect("ap-csa", key_mgmt="NONE", scan_freq="5180",
+                       wait_connect=False)
+        if blocktx or freq_to != 5180:
+            ev = dev[0].wait_event(["CTRL-EVENT-SSID-TEMP-DISABLED",
+                                    "CTRL-EVENT-CONNECTED"], timeout=9)
+            if not ev: # this is fine, at least we didn't connect
+                return
+            if not "CTRL-EVENT-SSID-TEMP-DISABLED" in ev:
+                raise Exception("Erroneously connected!")
+            if not 'auth_failures=1' in ev:
+                raise Exception(f'Should have auth failures in "{ev}"')
+            # wait for CSA to finish and connect then
+            time.sleep(delay)
+            dev[0].connect("ap-csa", key_mgmt="NONE", scan_freq=str(freq_to))
+        else:
+            dev[0].wait_connected()
+            if freq_to != 5180:
+                wait_channel_switch(dev[0], freq_to)
+    finally:
+        dev[0].request("DISCONNECT")
+        clear_regdom(ap, dev)
+
+@long_duration_test
+def test_assoc_while_csa_same_blocktx(dev, apdev):
+    "Check we don't associate while AP is doing quiet CSA (same channel)"
+    _assoc_while_csa(dev, apdev, 5180, True)
+
+def test_assoc_while_csa_same(dev, apdev):
+    "Check we _do_ associate while AP is doing CSA (same channel)"
+    _assoc_while_csa(dev, apdev, 5180, False)
+
+@long_duration_test
+def test_assoc_while_csa_diff_blocktx(dev, apdev):
+    "Check we don't associate while AP is doing quiet CSA (different channel)"
+    _assoc_while_csa(dev, apdev, 5200, True)
+
+@long_duration_test
+def test_assoc_while_csa_diff(dev, apdev):
+    "Check we don't associate while AP is doing CSA (different channel)"
+    _assoc_while_csa(dev, apdev, 5200, False)