WPS: Allow password token to be written with nfcpy

This adds write-password option for the nfcpy example script for
wpa_supplicant to match hostapd wps-ap-nfc.py functionality.

Signed-hostap: Jouni Malinen <jouni@qca.qualcomm.com>
This commit is contained in:
Jouni Malinen 2013-02-15 11:29:37 +02:00 committed by Jouni Malinen
parent 042ec551d4
commit 23ffcaf172

View file

@ -54,6 +54,13 @@ def wpas_tag_read(message):
print wpas.request("WPS_NFC_TAG_READ " + message.encode("hex"))
def wpas_get_password_token():
wpas = wpas_connect()
if (wpas == None):
return None
return wpas.request("WPS_NFC_TOKEN NDEF").rstrip().decode("hex")
def wpas_get_handover_req():
wpas = wpas_connect()
if (wpas == None):
@ -162,6 +169,28 @@ def wps_tag_read(tag):
time.sleep(0.1)
def wps_write_password_tag(clf):
print "Write WPS password token"
data = wpas_get_password_token()
if (data == None):
print "Could not get WPS password token from wpa_supplicant"
return
print "Touch an NFC tag"
while True:
tag = clf.poll()
if tag == None:
time.sleep(0.1)
continue
break
print "Tag found - writing"
tag.ndef.message = data
print "Done - remove tag"
while tag.is_present:
time.sleep(0.1)
def find_peer(clf):
while True:
if nfc.llcp.connected():
@ -194,6 +223,10 @@ def main():
clf = nfc.ContactlessFrontend()
try:
if len(sys.argv) > 1 and sys.argv[1] == "write-password":
wps_write_password_tag(clf)
raise SystemExit
while True:
print "Waiting for a tag or peer to be touched"