From 1733e356e42166bbe2481ac4c41be335ac5fe7c1 Mon Sep 17 00:00:00 2001 From: Jouni Malinen Date: Fri, 14 Aug 2020 00:11:44 +0300 Subject: [PATCH] dpp-nfc: Fix handover client wait for receiving handover select 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 --- wpa_supplicant/examples/dpp-nfc.py | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/wpa_supplicant/examples/dpp-nfc.py b/wpa_supplicant/examples/dpp-nfc.py index e0d11f412..83241330d 100755 --- a/wpa_supplicant/examples/dpp-nfc.py +++ b/wpa_supplicant/examples/dpp-nfc.py @@ -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: