aboutsummaryrefslogtreecommitdiffstats
path: root/hostapd/wps-ap-nfc.py
diff options
context:
space:
mode:
authorJouni Malinen <j@w1.fi>2013-02-10 14:25:20 (GMT)
committerJouni Malinen <j@w1.fi>2013-02-10 14:25:20 (GMT)
commitdc6bda1123bb517b9471deabb9d20241f2b5118c (patch)
treec764adbf3614b2b99782863c3c8c44e85780f223 /hostapd/wps-ap-nfc.py
parent8140ae969b2c67f3a119a7a33a503012510f1170 (diff)
downloadhostap-dc6bda1123bb517b9471deabb9d20241f2b5118c.zip
hostap-dc6bda1123bb517b9471deabb9d20241f2b5118c.tar.gz
hostap-dc6bda1123bb517b9471deabb9d20241f2b5118c.tar.bz2
WPS: Use alternating poll/listen for NFC peer discovery with nfcpy
This is needed to find the NFC peer to avoid cases where both devices could be using the same operation. Signed-hostap: Jouni Malinen <j@w1.fi>
Diffstat (limited to 'hostapd/wps-ap-nfc.py')
-rwxr-xr-xhostapd/wps-ap-nfc.py59
1 files changed, 40 insertions, 19 deletions
diff --git a/hostapd/wps-ap-nfc.py b/hostapd/wps-ap-nfc.py
index 4b2ca02..342340d 100755
--- a/hostapd/wps-ap-nfc.py
+++ b/hostapd/wps-ap-nfc.py
@@ -185,6 +185,34 @@ def wps_write_password_tag(clf):
time.sleep(0.1)
+def find_peer(clf):
+ while True:
+ if nfc.llcp.connected():
+ print "LLCP connected"
+ general_bytes = nfc.llcp.startup({})
+ peer = clf.listen(ord(os.urandom(1)) + 200, general_bytes)
+ if isinstance(peer, nfc.DEP):
+ print "listen -> DEP";
+ if peer.general_bytes.startswith("Ffm"):
+ print "Found DEP"
+ return peer
+ print "mismatch in general_bytes"
+ print peer.general_bytes
+
+ peer = clf.poll(general_bytes)
+ if isinstance(peer, nfc.DEP):
+ print "poll -> DEP";
+ if peer.general_bytes.startswith("Ffm"):
+ print "Found DEP"
+ return peer
+ print "mismatch in general_bytes"
+ print peer.general_bytes
+
+ if peer:
+ print "Found tag"
+ return peer
+
+
def main():
clf = nfc.ContactlessFrontend()
@@ -200,25 +228,18 @@ def main():
while True:
print "Waiting for a tag or peer to be touched"
- while True:
- general_bytes = nfc.llcp.startup({})
- tag = clf.poll(general_bytes)
- if tag == None:
- continue
-
- if isinstance(tag, nfc.DEP):
- wps_handover_init(tag)
- break
-
- 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
+ tag = find_peer(clf)
+ if isinstance(tag, nfc.DEP):
+ wps_handover_init(tag)
+ continue
+
+ if tag.ndef:
+ wps_tag_read(tag)
+ continue
+
+ print "Not an NDEF tag - remove tag"
+ while tag.is_present:
+ time.sleep(0.1)
except KeyboardInterrupt:
raise SystemExit