diff mbox series

[04/17] tests: pasn: try get_ptksa() from AP a few times

Message ID 20230925092039.ed41d90e2359.Ic7a8fd97e17f41ae381142051f91aa6c059bb798@changeid
State Accepted
Headers show
Series tests: some scheduling and other fixes | expand

Commit Message

Johannes Berg Sept. 25, 2023, 7:20 a.m. UTC
From: Johannes Berg <johannes.berg@intel.com>

We wait for the PASN auth to complete on the wpas side,
but there's no indication of this on the AP side. So if
scheduling ordering is bad, we can ask the AP for the
PTKSA cache before it even received the frame from the
kernel and created the PTKSA entry.

To fix this, try this a few times, to see if it becomes
available.

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

Patch

diff --git a/tests/hwsim/test_pasn.py b/tests/hwsim/test_pasn.py
index 427e51474373..956d2b358a67 100644
--- a/tests/hwsim/test_pasn.py
+++ b/tests/hwsim/test_pasn.py
@@ -52,10 +52,25 @@  def check_pasn_ptk(dev, hapd, cipher, fail_ptk=False, clear_keys=True,
     sta_ptksa = dev.get_ptksa(hapd.own_addr(), cipher)
     ap_ptksa = hapd.get_ptksa(dev.own_addr(), cipher)
 
+    # There's no event indicating hostapd has finished
+    # processing - so just try once more if it isn't
+    # yet available, it might become available still.
+    for i in range(10):
+        if ap_ptksa:
+            break
+        time.sleep(0.1)
+        ap_ptksa = hapd.get_ptksa(dev.own_addr(), cipher)
+
     if not (sta_ptksa and ap_ptksa):
         if fail_ptk:
             return
-        raise Exception("Could not get PTKSA entry")
+        if not sta_ptksa and not ap_ptksa:
+            source = 'both'
+        elif sta_ptksa:
+            source = 'ap'
+        else:
+            source = 'sta'
+        raise Exception("Could not get PTKSA entry from %s" % source)
 
     logger.info("sta: TK: %s KDK: %s" % (sta_ptksa['tk'], sta_ptksa['kdk']))
     logger.info("ap : TK: %s KDK: %s" % (ap_ptksa['tk'], ap_ptksa['kdk']))