WPS NFC: Clean up nfcpy script no-wait operations
This allows the scripts to terminate at proper point with --no-wait. Signed-hostap: Jouni Malinen <jouni@qca.qualcomm.com>
This commit is contained in:
parent
79ede5a7e6
commit
1f1b5b31d7
2 changed files with 32 additions and 14 deletions
|
@ -149,10 +149,10 @@ def rdwr_connected_write(tag):
|
||||||
while write_wait_remove and tag.is_present:
|
while write_wait_remove and tag.is_present:
|
||||||
time.sleep(0.1)
|
time.sleep(0.1)
|
||||||
|
|
||||||
def wps_write_config_tag(clf):
|
def wps_write_config_tag(clf, wait_remove=True):
|
||||||
print "Write WPS config token"
|
print "Write WPS config token"
|
||||||
global write_data, write_wait_remove
|
global write_data, write_wait_remove
|
||||||
write_wait_remove = True
|
write_wait_remove = wait_remove
|
||||||
write_data = wpas_get_config_token()
|
write_data = wpas_get_config_token()
|
||||||
if write_data == None:
|
if write_data == None:
|
||||||
print "Could not get WPS config token from hostapd"
|
print "Could not get WPS config token from hostapd"
|
||||||
|
@ -162,10 +162,10 @@ def wps_write_config_tag(clf):
|
||||||
clf.connect(rdwr={'on-connect': rdwr_connected_write})
|
clf.connect(rdwr={'on-connect': rdwr_connected_write})
|
||||||
|
|
||||||
|
|
||||||
def wps_write_password_tag(clf):
|
def wps_write_password_tag(clf, wait_remove=True):
|
||||||
print "Write WPS password token"
|
print "Write WPS password token"
|
||||||
global write_data, write_wait_remove
|
global write_data, write_wait_remove
|
||||||
write_wait_remove = True
|
write_wait_remove = wait_remove
|
||||||
write_data = wpas_get_password_token()
|
write_data = wpas_get_password_token()
|
||||||
if write_data == None:
|
if write_data == None:
|
||||||
print "Could not get WPS password token from hostapd"
|
print "Could not get WPS password token from hostapd"
|
||||||
|
@ -176,7 +176,7 @@ def wps_write_password_tag(clf):
|
||||||
|
|
||||||
|
|
||||||
def rdwr_connected(tag):
|
def rdwr_connected(tag):
|
||||||
global only_one
|
global only_one, no_wait
|
||||||
print "Tag connected: " + str(tag)
|
print "Tag connected: " + str(tag)
|
||||||
|
|
||||||
if tag.ndef:
|
if tag.ndef:
|
||||||
|
@ -191,8 +191,6 @@ def rdwr_connected(tag):
|
||||||
continue_loop = False
|
continue_loop = False
|
||||||
else:
|
else:
|
||||||
print "Not an NDEF tag - remove tag"
|
print "Not an NDEF tag - remove tag"
|
||||||
while tag.is_present:
|
|
||||||
time.sleep(0.1)
|
|
||||||
|
|
||||||
return not no_wait
|
return not no_wait
|
||||||
|
|
||||||
|
@ -218,6 +216,8 @@ def main():
|
||||||
parser = argparse.ArgumentParser(description='nfcpy to hostapd integration for WPS NFC operations')
|
parser = argparse.ArgumentParser(description='nfcpy to hostapd integration for WPS NFC operations')
|
||||||
parser.add_argument('--only-one', '-1', action='store_true',
|
parser.add_argument('--only-one', '-1', action='store_true',
|
||||||
help='run only one operation and exit')
|
help='run only one operation and exit')
|
||||||
|
parser.add_argument('--no-wait', action='store_true',
|
||||||
|
help='do not wait for tag to be removed before exiting')
|
||||||
parser.add_argument('command', choices=['write-config',
|
parser.add_argument('command', choices=['write-config',
|
||||||
'write-password'],
|
'write-password'],
|
||||||
nargs='?')
|
nargs='?')
|
||||||
|
@ -226,17 +226,20 @@ def main():
|
||||||
global only_one
|
global only_one
|
||||||
only_one = args.only_one
|
only_one = args.only_one
|
||||||
|
|
||||||
|
global no_wait
|
||||||
|
no_wait = args.no_wait
|
||||||
|
|
||||||
try:
|
try:
|
||||||
if not clf.open("usb"):
|
if not clf.open("usb"):
|
||||||
print "Could not open connection with an NFC device"
|
print "Could not open connection with an NFC device"
|
||||||
raise SystemExit
|
raise SystemExit
|
||||||
|
|
||||||
if args.command == "write-config":
|
if args.command == "write-config":
|
||||||
wps_write_config_tag(clf)
|
wps_write_config_tag(clf, wait_remove=not args.no_wait)
|
||||||
raise SystemExit
|
raise SystemExit
|
||||||
|
|
||||||
if args.command == "write-password":
|
if args.command == "write-password":
|
||||||
wps_write_password_tag(clf)
|
wps_write_password_tag(clf, wait_remove=not args.no_wait)
|
||||||
raise SystemExit
|
raise SystemExit
|
||||||
|
|
||||||
global continue_loop
|
global continue_loop
|
||||||
|
|
|
@ -27,6 +27,7 @@ import wpaspy
|
||||||
wpas_ctrl = '/var/run/wpa_supplicant'
|
wpas_ctrl = '/var/run/wpa_supplicant'
|
||||||
srv = None
|
srv = None
|
||||||
continue_loop = True
|
continue_loop = True
|
||||||
|
terminate_now = False
|
||||||
|
|
||||||
def wpas_connect():
|
def wpas_connect():
|
||||||
ifaces = []
|
ifaces = []
|
||||||
|
@ -226,6 +227,11 @@ def wps_handover_init(llc):
|
||||||
global continue_loop
|
global continue_loop
|
||||||
continue_loop = False
|
continue_loop = False
|
||||||
|
|
||||||
|
global no_wait
|
||||||
|
if no_wait:
|
||||||
|
print "Trying to exit.."
|
||||||
|
global terminate_now
|
||||||
|
terminate_now = True
|
||||||
|
|
||||||
def wps_tag_read(tag, wait_remove=True):
|
def wps_tag_read(tag, wait_remove=True):
|
||||||
success = False
|
success = False
|
||||||
|
@ -300,7 +306,7 @@ def wps_write_password_tag(clf, wait_remove=True):
|
||||||
|
|
||||||
|
|
||||||
def rdwr_connected(tag):
|
def rdwr_connected(tag):
|
||||||
global only_one
|
global only_one, no_wait
|
||||||
print "Tag connected: " + str(tag)
|
print "Tag connected: " + str(tag)
|
||||||
|
|
||||||
if tag.ndef:
|
if tag.ndef:
|
||||||
|
@ -315,15 +321,15 @@ def rdwr_connected(tag):
|
||||||
continue_loop = False
|
continue_loop = False
|
||||||
else:
|
else:
|
||||||
print "Not an NDEF tag - remove tag"
|
print "Not an NDEF tag - remove tag"
|
||||||
while tag.is_present:
|
|
||||||
time.sleep(0.1)
|
return not no_wait
|
||||||
return True
|
|
||||||
|
|
||||||
|
|
||||||
def llcp_worker(llc):
|
def llcp_worker(llc):
|
||||||
global arg_uuid
|
global arg_uuid
|
||||||
if arg_uuid is None:
|
if arg_uuid is None:
|
||||||
wps_handover_init(llc)
|
wps_handover_init(llc)
|
||||||
|
print "Exiting llcp_worker thread"
|
||||||
return
|
return
|
||||||
|
|
||||||
global srv
|
global srv
|
||||||
|
@ -356,9 +362,14 @@ def llcp_connected(llc):
|
||||||
srv.start()
|
srv.start()
|
||||||
else:
|
else:
|
||||||
threading.Thread(target=llcp_worker, args=(llc,)).start()
|
threading.Thread(target=llcp_worker, args=(llc,)).start()
|
||||||
|
print "llcp_connected returning"
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
|
||||||
|
def terminate_loop():
|
||||||
|
global terminate_now
|
||||||
|
return terminate_now
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
clf = nfc.ContactlessFrontend()
|
clf = nfc.ContactlessFrontend()
|
||||||
|
|
||||||
|
@ -383,6 +394,9 @@ def main():
|
||||||
global only_one
|
global only_one
|
||||||
only_one = args.only_one
|
only_one = args.only_one
|
||||||
|
|
||||||
|
global no_wait
|
||||||
|
no_wait = args.no_wait
|
||||||
|
|
||||||
try:
|
try:
|
||||||
if not clf.open("usb"):
|
if not clf.open("usb"):
|
||||||
print "Could not open connection with an NFC device"
|
print "Could not open connection with an NFC device"
|
||||||
|
@ -407,7 +421,8 @@ def main():
|
||||||
try:
|
try:
|
||||||
if not clf.connect(rdwr={'on-connect': rdwr_connected},
|
if not clf.connect(rdwr={'on-connect': rdwr_connected},
|
||||||
llcp={'on-startup': llcp_startup,
|
llcp={'on-startup': llcp_startup,
|
||||||
'on-connect': llcp_connected}):
|
'on-connect': llcp_connected},
|
||||||
|
terminate=terminate_loop):
|
||||||
break
|
break
|
||||||
except Exception, e:
|
except Exception, e:
|
||||||
print "clf.connect failed"
|
print "clf.connect failed"
|
||||||
|
|
Loading…
Reference in a new issue