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:
parent
ec4f5a37b8
commit
dab710c4d0
1 changed files with 29 additions and 22 deletions
|
@ -46,6 +46,26 @@ def wpas_tag_read(message):
|
||||||
return
|
return
|
||||||
print wpas.request("WPS_NFC_TAG_READ " + message.encode("hex"))
|
print wpas.request("WPS_NFC_TAG_READ " + message.encode("hex"))
|
||||||
|
|
||||||
|
|
||||||
|
def wps_tag_read(tag):
|
||||||
|
if len(tag.ndef.message):
|
||||||
|
message = nfc.ndef.Message(tag.ndef.message)
|
||||||
|
print "message type " + message.type
|
||||||
|
|
||||||
|
for record in message:
|
||||||
|
print "record type " + record.type
|
||||||
|
if record.type == "application/vnd.wfa.wsc":
|
||||||
|
print "WPS tag - send to wpa_supplicant"
|
||||||
|
wpas_tag_read(tag.ndef.message)
|
||||||
|
break
|
||||||
|
else:
|
||||||
|
print "Empty tag"
|
||||||
|
|
||||||
|
print "Remove tag"
|
||||||
|
while tag.is_present:
|
||||||
|
time.sleep(0.1)
|
||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
clf = nfc.ContactlessFrontend()
|
clf = nfc.ContactlessFrontend()
|
||||||
|
|
||||||
|
@ -55,31 +75,18 @@ def main():
|
||||||
|
|
||||||
while True:
|
while True:
|
||||||
tag = clf.poll()
|
tag = clf.poll()
|
||||||
if tag and tag.ndef:
|
if tag == None:
|
||||||
|
continue
|
||||||
|
|
||||||
|
if tag.ndef:
|
||||||
|
wps_tag_read(tag)
|
||||||
break
|
break
|
||||||
|
|
||||||
if tag:
|
if tag:
|
||||||
print "Not an NDEF tag"
|
print "Not an NDEF tag - remove tag"
|
||||||
while tag.is_present:
|
while tag.is_present:
|
||||||
time.sleep(0.2)
|
time.sleep(0.1)
|
||||||
|
break
|
||||||
if len(tag.ndef.message):
|
|
||||||
message = nfc.ndef.Message(tag.ndef.message)
|
|
||||||
print "message type " + message.type
|
|
||||||
|
|
||||||
for record in message:
|
|
||||||
print "record type " + record.type
|
|
||||||
if record.type == "application/vnd.wfa.wsc":
|
|
||||||
print "WPS tag - send to wpa_supplicant"
|
|
||||||
wpas_tag_read(tag.ndef.message)
|
|
||||||
break
|
|
||||||
else:
|
|
||||||
print "Empty tag"
|
|
||||||
|
|
||||||
print "Remove tag"
|
|
||||||
while tag.is_present:
|
|
||||||
time.sleep(0.2)
|
|
||||||
|
|
||||||
print "Ok"
|
|
||||||
|
|
||||||
except KeyboardInterrupt:
|
except KeyboardInterrupt:
|
||||||
raise SystemExit
|
raise SystemExit
|
||||||
|
|
Loading…
Reference in a new issue