aboutsummaryrefslogtreecommitdiffstats
path: root/wpa_supplicant/examples
diff options
context:
space:
mode:
authorJouni Malinen <j@w1.fi>2012-11-04 13:56:46 (GMT)
committerJouni Malinen <j@w1.fi>2012-11-04 13:56:46 (GMT)
commitdab710c4d0cb4bd1865fed5545ce2fa64fe924fb (patch)
tree8bbdf70efde9d17fb5f296acb4537859875cf4e8 /wpa_supplicant/examples
parentec4f5a37b8fc3612be2353133be97af92c8a4667 (diff)
downloadhostap-dab710c4d0cb4bd1865fed5545ce2fa64fe924fb.zip
hostap-dab710c4d0cb4bd1865fed5545ce2fa64fe924fb.tar.gz
hostap-dab710c4d0cb4bd1865fed5545ce2fa64fe924fb.tar.bz2
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>
Diffstat (limited to 'wpa_supplicant/examples')
-rwxr-xr-xwpa_supplicant/examples/wps-nfc.py51
1 files changed, 29 insertions, 22 deletions
diff --git a/wpa_supplicant/examples/wps-nfc.py b/wpa_supplicant/examples/wps-nfc.py
index 39c206f..634ea6b 100755
--- a/wpa_supplicant/examples/wps-nfc.py
+++ b/wpa_supplicant/examples/wps-nfc.py
@@ -46,6 +46,26 @@ def wpas_tag_read(message):
return
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():
clf = nfc.ContactlessFrontend()
@@ -55,31 +75,18 @@ def main():
while True:
tag = clf.poll()
- if tag and tag.ndef:
+ if tag == None:
+ continue
+
+ if tag.ndef:
+ wps_tag_read(tag)
break
+
if tag:
- print "Not an NDEF tag"
+ print "Not an NDEF tag - remove tag"
while tag.is_present:
- time.sleep(0.2)
-
- 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"
+ time.sleep(0.1)
+ break
except KeyboardInterrupt:
raise SystemExit