aboutsummaryrefslogtreecommitdiffstats
path: root/wpa_supplicant/examples
diff options
context:
space:
mode:
authorJouni Malinen <jouni@qca.qualcomm.com>2013-02-24 08:56:29 (GMT)
committerJouni Malinen <j@w1.fi>2013-02-24 08:56:29 (GMT)
commitf3f2ba2e6ef3d33cf76b8ac4d828c1417357424e (patch)
treede3eefb61c97291783b2f18b07e1ebd22a94c2e7 /wpa_supplicant/examples
parentc39fdb8529295ce99384998fd0c3e8f36e889cce (diff)
downloadhostap-f3f2ba2e6ef3d33cf76b8ac4d828c1417357424e.zip
hostap-f3f2ba2e6ef3d33cf76b8ac4d828c1417357424e.tar.gz
hostap-f3f2ba2e6ef3d33cf76b8ac4d828c1417357424e.tar.bz2
WPS NFC: Add connection handover support for ER
wpa_supplicant can now generate the WPS carrier record for connection handover response when acting as an ER. The AP whose configuration is provided in this way is identified with an UUID as an argument to wps-nfc.py. Signed-hostap: Jouni Malinen <jouni@qca.qualcomm.com>
Diffstat (limited to 'wpa_supplicant/examples')
-rwxr-xr-xwpa_supplicant/examples/wps-nfc.py86
1 files changed, 82 insertions, 4 deletions
diff --git a/wpa_supplicant/examples/wps-nfc.py b/wpa_supplicant/examples/wps-nfc.py
index 725886f..2d54cd2 100755
--- a/wpa_supplicant/examples/wps-nfc.py
+++ b/wpa_supplicant/examples/wps-nfc.py
@@ -82,15 +82,86 @@ def wpas_get_handover_req():
return wpas.request("NFC_GET_HANDOVER_REQ NDEF WPS-CR").rstrip().decode("hex")
-def wpas_report_handover(req, sel):
+def wpas_get_handover_sel(uuid):
wpas = wpas_connect()
if (wpas == None):
return None
- return wpas.request("NFC_REPORT_HANDOVER INIT WPS " +
+ return wpas.request("NFC_GET_HANDOVER_SEL NDEF WPS-CR " + uuid).rstrip().decode("hex")
+
+
+def wpas_report_handover(req, sel, type):
+ wpas = wpas_connect()
+ if (wpas == None):
+ return None
+ return wpas.request("NFC_REPORT_HANDOVER " + type + " WPS " +
str(req).encode("hex") + " " +
str(sel).encode("hex"))
+class HandoverServer(nfc.handover.HandoverServer):
+ def __init__(self):
+ super(HandoverServer, self).__init__()
+
+ def process_request(self, request):
+ print "HandoverServer - request received"
+ print "Parsed handover request: " + request.pretty()
+
+ sel = nfc.ndef.HandoverSelectMessage(version="1.2")
+
+ for carrier in request.carriers:
+ print "Remote carrier type: " + carrier.type
+ if carrier.type == "application/vnd.wfa.wsc":
+ print "WPS carrier type match - add WPS carrier record"
+ self.received_carrier = carrier.record
+ data = wpas_get_handover_sel(self.uuid)
+ if data is None:
+ print "Could not get handover select carrier record from wpa_supplicant"
+ continue
+ print "Handover select carrier record from wpa_supplicant:"
+ print data.encode("hex")
+ self.sent_carrier = data
+
+ message = nfc.ndef.Message(data);
+ sel.add_carrier(message[0], "active", message[1:])
+
+ print "Handover select:"
+ print sel.pretty()
+ print str(sel).encode("hex")
+
+ print "Sending handover select"
+ return sel
+
+
+def wps_handover_resp(peer, uuid):
+ print "Trying to handle WPS handover with AP " + uuid
+
+ srv = HandoverServer()
+ srv.sent_carrier = None
+ srv.uuid = uuid
+
+ nfc.llcp.activate(peer);
+
+ try:
+ print "Trying handover";
+ srv.start()
+ print "Wait for disconnect"
+ while nfc.llcp.connected():
+ time.sleep(0.1)
+ print "Disconnected after handover"
+ except nfc.llcp.ConnectRefused:
+ print "Handover connection refused"
+ nfc.llcp.shutdown()
+ return
+
+ if srv.sent_carrier:
+ wpas_report_handover(srv.received_carrier, srv.sent_carrier, "RESP")
+
+ print "Remove peer"
+ nfc.llcp.shutdown()
+ print "Done with handover"
+ time.sleep(1)
+
+
def wps_handover_init(peer):
print "Trying to initiate WPS handover"
@@ -154,7 +225,7 @@ def wps_handover_init(peer):
print "Remote carrier type: " + carrier.type
if carrier.type == "application/vnd.wfa.wsc":
print "WPS carrier type match - send to wpa_supplicant"
- wpas_report_handover(data, carrier.record)
+ wpas_report_handover(data, carrier.record, "INIT")
wifi = nfc.ndef.WifiConfigRecord(carrier.record)
print wifi.pretty()
@@ -281,6 +352,10 @@ def main():
clf = nfc.ContactlessFrontend()
try:
+ arg_uuid = None
+ if len(sys.argv) > 1:
+ arg_uuid = sys.argv[1]
+
if len(sys.argv) > 1 and sys.argv[1] == "write-config":
wps_write_config_tag(clf)
raise SystemExit
@@ -298,7 +373,10 @@ def main():
tag = find_peer(clf)
if isinstance(tag, nfc.DEP):
- wps_handover_init(tag)
+ if arg_uuid is None:
+ wps_handover_init(tag)
+ else:
+ wps_handover_resp(tag, arg_uuid)
continue
if tag.ndef: