Accumulative patch from commit b57b560034f1bb1ad3a3892228940dde97323c0e
b57b560 wpa_supplicant: Default to nl80211 instead of wext
ee28f08 hostapd: Add more messages for error paths
61d2ce2 hostapd: Reject configuration file without interface parameter
a8a7890 Clear extra_blacklist_count on FLUSH command
c646862 WPS ER: Allow UPnP interface to be forced
728d971 Use status code 17 (unable to handle new STA) on max-STA limitation
5e24dc8 Add dup_binstr() to help common binary string tasks
8b44ad7 Use os_zalloc() instead of os_malloc() + os_memset()
2c48211 FT RRB: Validate os_malloc() return value before using it
7ca902b Make vlan_file optional if dynamic_vlan is used
bdb112d Add bitfield routines
04382f7 NFC: Add no waiting and no multiple operations options for scripts
fe90496 WPS: Fix AP auto configuration on config token generation
28fcfb6 NFC: Increase wpa_cli command buffer size
8f7a6dd WPS NFC: Allow Device Password ID override for selected registrar
aaecb69 WPS: Use generic MAC Address attribute builder
9ccd916 P2P: Clean up channel--frequency conversion functions
e864c0a Use a common frequency to channel conversion function
02db75b FT: Reset FT flag upon STA deauthentication
7800d45 P2P: Set P2P_DEV_PEER_WAITING_RESPONSE from TX status callback
d78d3c6 EAP peer: Add check before calling getSessionId method
dd57970 Disable network temporarily on repeated connection failures
Change-Id: If8078d5c1ff40ea806e844543cf6f2bf9d24b7ac
Signed-off-by: Dmitry Shmidt <dimitrysh@google.com>
diff --git a/wpa_supplicant/examples/wps-nfc.py b/wpa_supplicant/examples/wps-nfc.py
index dbc143a..d6dec85 100755
--- a/wpa_supplicant/examples/wps-nfc.py
+++ b/wpa_supplicant/examples/wps-nfc.py
@@ -49,17 +49,22 @@
def wpas_tag_read(message):
wpas = wpas_connect()
if (wpas == None):
- return
- print wpas.request("WPS_NFC_TAG_READ " + message.encode("hex"))
-
+ return False
+ if "FAIL" in wpas.request("WPS_NFC_TAG_READ " + message.encode("hex")):
+ return False
+ return True
def wpas_get_config_token(id=None):
wpas = wpas_connect()
if (wpas == None):
return None
if id:
- return wpas.request("WPS_NFC_CONFIG_TOKEN NDEF " + id).rstrip().decode("hex")
- return wpas.request("WPS_NFC_CONFIG_TOKEN NDEF").rstrip().decode("hex")
+ ret = wpas.request("WPS_NFC_CONFIG_TOKEN NDEF " + id)
+ else:
+ ret = wpas.request("WPS_NFC_CONFIG_TOKEN NDEF")
+ if "FAIL" in ret:
+ return None
+ return ret.rstrip().decode("hex")
def wpas_get_er_config_token(uuid):
@@ -241,7 +246,8 @@
print "Done with handover"
-def wps_tag_read(tag):
+def wps_tag_read(tag, wait_remove=True):
+ success = False
if len(tag.ndef.message):
message = nfc.ndef.Message(tag.ndef.message)
print "message type " + message.type
@@ -250,21 +256,25 @@
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)
+ success = wpas_tag_read(tag.ndef.message)
break
else:
print "Empty tag"
- print "Remove tag"
- while tag.is_present:
- time.sleep(0.1)
+ if wait_remove:
+ print "Remove tag"
+ while tag.is_present:
+ time.sleep(0.1)
+
+ return success
-def wps_write_config_tag(clf, id=None):
+def wps_write_config_tag(clf, id=None, wait_remove=True):
print "Write WPS config token"
data = wpas_get_config_token(id)
if (data == None):
print "Could not get WPS config token from wpa_supplicant"
+ sys.exit(1)
return
print "Touch an NFC tag"
@@ -278,7 +288,7 @@
print "Tag found - writing"
tag.ndef.message = data
print "Done - remove tag"
- while tag.is_present:
+ while wait_remove and tag.is_present:
time.sleep(0.1)
@@ -304,7 +314,7 @@
time.sleep(0.1)
-def wps_write_password_tag(clf):
+def wps_write_password_tag(clf, wait_remove=True):
print "Write WPS password token"
data = wpas_get_password_token()
if (data == None):
@@ -322,7 +332,7 @@
print "Tag found - writing"
tag.ndef.message = data
print "Done - remove tag"
- while tag.is_present:
+ while wait_remove and tag.is_present:
time.sleep(0.1)
@@ -359,13 +369,22 @@
try:
arg_uuid = None
- if len(sys.argv) > 1:
+ if len(sys.argv) > 1 and sys.argv[1] != '-1':
arg_uuid = sys.argv[1]
+ if len(sys.argv) > 1 and sys.argv[1] == '-1':
+ only_one = True
+ else:
+ only_one = False
+
if len(sys.argv) > 1 and sys.argv[1] == "write-config":
wps_write_config_tag(clf)
raise SystemExit
+ if len(sys.argv) > 1 and sys.argv[1] == "write-config-no-wait":
+ wps_write_config_tag(clf, wait_remove=False)
+ raise SystemExit
+
if len(sys.argv) > 2 and sys.argv[1] == "write-config-id":
wps_write_config_tag(clf, sys.argv[2])
raise SystemExit
@@ -378,6 +397,10 @@
wps_write_password_tag(clf)
raise SystemExit
+ if len(sys.argv) > 1 and sys.argv[1] == "write-password-no-wait":
+ wps_write_password_tag(clf, wait_remove=False)
+ raise SystemExit
+
while True:
print "Waiting for a tag or peer to be touched"
@@ -389,13 +412,21 @@
wps_handover_resp(tag, None)
else:
wps_handover_resp(tag, arg_uuid)
+ if only_one:
+ break
continue
if tag.ndef:
- wps_tag_read(tag)
+ success = wps_tag_read(tag, not only_one)
+ if only_one:
+ if not success:
+ sys.exit(1)
+ break
continue
print "Not an NDEF tag - remove tag"
+ if only_one:
+ sys.exit(1)
while tag.is_present:
time.sleep(0.1)