]> git.ipfire.org Git - thirdparty/hostap.git/commitdiff
dpp-nfc: Do not indicate a single channel 1 by default
authorJouni Malinen <jouni@codeaurora.org>
Fri, 15 May 2020 11:17:40 +0000 (14:17 +0300)
committerJouni Malinen <j@w1.fi>
Fri, 15 May 2020 11:17:40 +0000 (14:17 +0300)
Allow any channel to be used by not including a specific single channel
in the handover request without a need (for AP mode, use the current
operating channel). When sending out the handover select, pick a single
channel if no specific channel has been negotiated.

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

index d9ae7475a69cb93cc4b750f13ee9965fb8b6cdf5..1dbf47ad737d4b678e4df3c76e4f655c625a4191 100755 (executable)
@@ -178,12 +178,23 @@ def dpp_bootstrap_gen(wpas, type="qrcode", chan=None, mac=None, info=None,
         raise Exception("Failed to generate bootstrapping info")
     return int(res)
 
-def wpas_get_nfc_uri(start_listen=True):
+def wpas_get_nfc_uri(start_listen=True, pick_channel=False):
     wpas = wpas_connect()
     if wpas is None:
         return None
     global own_id, chanlist
-    own_id = dpp_bootstrap_gen(wpas, type="nfc-uri", chan=chanlist, mac=True)
+    chan = chanlist
+    if chan is None and get_status_field(wpas, "bssid[0]"):
+        freq = get_status_field(wpas, "freq")
+        if freq:
+            freq = int(freq)
+            if freq >= 2412 and freq <= 2462:
+                chan = "81/%d" % ((freq - 2407) / 5)
+                summary("Use current AP operating channel (%d MHz) as the URI channel list (%s)" % (freq, chan))
+    if chan is None and pick_channel:
+        chan = "81/6"
+        summary("Use channel 2437 MHz since no other preference provided")
+    own_id = dpp_bootstrap_gen(wpas, type="nfc-uri", chan=chan, mac=True)
     res = wpas.request("DPP_BOOTSTRAP_GET_URI %d" % own_id).rstrip()
     if "FAIL" in res:
         return None
@@ -410,7 +421,7 @@ class HandoverServer(nfc.handover.HandoverServer):
                 uri = carrier.data[1:].decode("utf-8")
                 summary("Received DPP URI: " + uri)
 
-                data = wpas_get_nfc_uri(start_listen=False)
+                data = wpas_get_nfc_uri(start_listen=False, pick_channel=True)
                 summary("Own URI (pre-processing): %s" % data)
 
                 res = wpas_report_handover_req(uri)
@@ -436,9 +447,13 @@ class HandoverServer(nfc.handover.HandoverServer):
                 for line in info.splitlines():
                     if line.startswith("use_freq="):
                         freq = int(line.split('=')[1])
-                if freq is None:
-                    summary("No channel negotiated over NFC - use channel 1")
-                    freq = 2412
+                if freq is None or freq == 0:
+                    summary("No channel negotiated over NFC - use channel 6")
+                    freq = 2437
+                else:
+                    summary("Negotiated channel: %d MHz" % freq)
+                if get_status_field(wpas, "bssid[0]"):
+                    summary("Own AP freq: %s MHz" % str(get_status_field(wpas, "freq")))
                 cmd = "DPP_LISTEN %d" % freq
                 global enrollee_only
                 global configurator_only
@@ -700,7 +715,7 @@ def main():
     parser.add_argument('--success',
                         help='success file for writing success update')
     parser.add_argument('--device', default='usb', help='NFC device to open')
-    parser.add_argument('--chan', default='81/1', help='channel list')
+    parser.add_argument('--chan', default=None, help='channel list')
     parser.add_argument('command', choices=['write-nfc-uri',
                                             'write-nfc-hs'],
                         nargs='?')