]> git.ipfire.org Git - thirdparty/hostap.git/commitdiff
dpp-nfc: Fix connection handover renegotiation
authorJouni Malinen <jouni@codeaurora.org>
Wed, 24 Jun 2020 19:37:52 +0000 (22:37 +0300)
committerJouni Malinen <j@w1.fi>
Wed, 24 Jun 2020 19:37:52 +0000 (22:37 +0300)
The use of the alternative channel list did not work properly for the
case were both ends were trying to initiate the negotiated connection
handover. Fix this by always starting a new connection handover client
thread for sending the alternative proposal and ignoring peer messages
(likely something from the first attempt) during this modified attempt.

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

index 5230dc59dde41e5c69147b4363ede718c6cbfe0f..3281ca6062b88b1fead762f0c1aff92a03f3f7a2 100755 (executable)
@@ -241,7 +241,7 @@ def dpp_handover_client(llc, alt=False):
     summary("NFC Handover Request message for DPP: " + str(message))
 
     global peer_crn
-    if peer_crn is not None:
+    if peer_crn is not None and not alt:
         summary("NFC handover request from peer was already received - do not send own")
         return
     client = nfc.handover.HandoverClient(llc)
@@ -258,7 +258,7 @@ def dpp_handover_client(llc, alt=False):
         client.close()
         return
 
-    if peer_crn is not None:
+    if peer_crn is not None and not alt:
         summary("NFC handover request from peer was already received - do not send own")
         client.close()
         return
@@ -507,18 +507,17 @@ class HandoverServer(nfc.handover.HandoverServer):
                 sel = [hs, carrier]
                 break
 
+        global hs_sent
         summary("Sending handover select: " + str(sel))
         if found:
             summary("Handover completed successfully")
             self.success = True
+            hs_sent = True
         else:
             summary("Try to initiate with alternative parameters")
             self.try_own = True
-            if not init_on_touch and no_input:
-                # Need to start client thread now
-                threading.Thread(target=llcp_worker, args=(self.llc,)).start()
-        global hs_sent
-        hs_sent = True
+            hs_sent = False
+            threading.Thread(target=llcp_worker, args=(self.llc, True)).start()
         return sel
 
 def clear_raw_mode():
@@ -651,12 +650,18 @@ def rdwr_connected(tag):
 
     return not no_wait
 
-def llcp_worker(llc):
+def llcp_worker(llc, try_alt):
+    print("Start of llcp_worker()")
+    if try_alt:
+        summary("Starting handover client (try_alt)")
+        dpp_handover_client(llc, alt=True)
+        summary("Exiting llcp_worker thread (try_alt)")
+        return
     global init_on_touch
     if init_on_touch:
-        summary("Starting handover client")
+        summary("Starting handover client (init_on_touch)")
         dpp_handover_client(llc)
-        summary("Exiting llcp_worker thread (init_in_touch)")
+        summary("Exiting llcp_worker thread (init_on_touch)")
         return
 
     global no_input
@@ -716,7 +721,7 @@ def llcp_connected(llc):
     global srv
     srv.start()
     if init_on_touch or not no_input:
-        threading.Thread(target=llcp_worker, args=(llc,)).start()
+        threading.Thread(target=llcp_worker, args=(llc, False)).start()
     return True
 
 def llcp_release(llc):