]> git.ipfire.org Git - thirdparty/hostap.git/commitdiff
dpp-nfc: Fix handover client wait for receiving handover select
authorJouni Malinen <jouni@codeaurora.org>
Thu, 13 Aug 2020 21:11:44 +0000 (00:11 +0300)
committerJouni Malinen <j@w1.fi>
Thu, 13 Aug 2020 21:11:44 +0000 (00:11 +0300)
This was supposed to wait for up to 3.0 seconds for the handover select,
but the incorrect loop terminated ended up limiting this to a single
iteration of 0.1 second wait. This was too fast for some cases like the
AP mode operation where it may take significant time to enable the radio
for listening to DPP authentication messages.

Fix the loop to allow that full three second wait for the response to be
used. In addition, report the amount of time it takes to receive the
response.

Signed-off-by: Jouni Malinen <jouni@codeaurora.org>
wpa_supplicant/examples/dpp-nfc.py

index e0d11f412b765c8b728f944972e02bcb44caf867..83241330d621885c07e94055b36b70d07ee8f0cc 100755 (executable)
@@ -278,8 +278,15 @@ class HandoverClient(nfc.handover.HandoverClient):
     def recv_octets(self, timeout=None):
         start = time.time()
         msg = bytearray()
-        poll_timeout = 0.1 if timeout is None or timeout > 0.1 else timeout
-        while self.socket.poll('recv', poll_timeout):
+        while True:
+            poll_timeout = 0.1 if timeout is None or timeout > 0.1 else timeout
+            if self.socket.poll('recv', poll_timeout) is None:
+                if timeout:
+                    timeout -= time.time() - start
+                    if timeout <= 0:
+                        return None
+                    start = time.time()
+                continue
             try:
                 r = self.socket.recv()
                 if r is None:
@@ -372,7 +379,10 @@ def run_dpp_handover_client(handover, alt=False):
 
     summary("Receiving handover response")
     try:
+        start = time.time()
         message = client.recv_records(timeout=3.0)
+        end = time.time()
+        summary("Received {} record(s) in {} seconds".format(len(message) if message is not None else -1, end - start))
     except Exception as e:
         # This is fine if we are the handover selector
         if handover.hs_sent: