From d0e2d8091f5c254e0c5d44d9c25f6491cd98434d Mon Sep 17 00:00:00 2001 From: Jouni Malinen Date: Fri, 15 May 2020 12:10:59 +0300 Subject: [PATCH] dpp-nfc: Make handover request collision detection more robust Wait up to 100 ms for own handover request transmission to succeed if peer handover request is received, but own crn is not yet available. Signed-off-by: Jouni Malinen --- wpa_supplicant/examples/dpp-nfc.py | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/wpa_supplicant/examples/dpp-nfc.py b/wpa_supplicant/examples/dpp-nfc.py index b82713832..d9ae7475a 100755 --- a/wpa_supplicant/examples/dpp-nfc.py +++ b/wpa_supplicant/examples/dpp-nfc.py @@ -34,6 +34,7 @@ continue_loop = True terminate_now = False summary_file = None success_file = None +my_crn_ready = False my_crn = None peer_crn = None mutex = threading.Lock() @@ -245,12 +246,15 @@ def dpp_handover_client(llc): summary("Sending handover request") + global my_crn, my_crn_ready + my_crn_ready = True + if not client.send_records(message): + my_crn_ready = False summary("Failed to send handover request") client.close() return - global my_crn my_crn, = struct.unpack('>H', crn) summary("Receiving handover response") @@ -357,7 +361,7 @@ class HandoverServer(nfc.handover.HandoverServer): print("\n") summary("HandoverServer - request received: " + str(records)) - global my_crn, peer_crn + global my_crn, peer_crn, my_crn_ready for carrier in records: if not isinstance(carrier, ndef.HandoverRequestRecord): @@ -366,6 +370,12 @@ class HandoverServer(nfc.handover.HandoverServer): peer_crn = carrier.collision_resolution_number summary("peer_crn: %d" % peer_crn) + if my_crn is None and my_crn_ready: + summary("Still trying to send own handover request - wait a moment to see if that succeeds before checking crn values") + for i in range(10): + if my_crn is not None: + break + time.sleep(0.01) if my_crn is not None: summary("my_crn: %d" % my_crn) @@ -635,8 +645,9 @@ def llcp_startup(llc): def llcp_connected(llc): summary("P2P LLCP connected") - global wait_connection, my_crn, peer_crn + global wait_connection, my_crn, peer_crn, my_crn_ready wait_connection = False + my_crn_ready = False my_crn = None peer_crn = None global srv