WPS: Move NFC tag processing into a separate function

This makes it cleaner to add processing of other NFC operations to the
python script.

Signed-hostap: Jouni Malinen <j@w1.fi>
This commit is contained in:
Jouni Malinen 2012-11-04 15:56:46 +02:00
parent ec4f5a37b8
commit dab710c4d0

View file

@ -46,22 +46,8 @@ def wpas_tag_read(message):
return
print wpas.request("WPS_NFC_TAG_READ " + message.encode("hex"))
def main():
clf = nfc.ContactlessFrontend()
try:
while True:
print "Waiting for a tag to be touched"
while True:
tag = clf.poll()
if tag and tag.ndef:
break
if tag:
print "Not an NDEF tag"
while tag.is_present:
time.sleep(0.2)
def wps_tag_read(tag):
if len(tag.ndef.message):
message = nfc.ndef.Message(tag.ndef.message)
print "message type " + message.type
@ -77,9 +63,30 @@ def main():
print "Remove tag"
while tag.is_present:
time.sleep(0.2)
time.sleep(0.1)
print "Ok"
def main():
clf = nfc.ContactlessFrontend()
try:
while True:
print "Waiting for a tag to be touched"
while True:
tag = clf.poll()
if tag == None:
continue
if tag.ndef:
wps_tag_read(tag)
break
if tag:
print "Not an NDEF tag - remove tag"
while tag.is_present:
time.sleep(0.1)
break
except KeyboardInterrupt:
raise SystemExit