diff options
author | Jouni Malinen <jouni@qca.qualcomm.com> | 2013-11-29 10:41:34 (GMT) |
---|---|---|
committer | Jouni Malinen <j@w1.fi> | 2014-01-27 20:08:13 (GMT) |
commit | ab1db08c0505804676a9862b59ed9b8800949957 (patch) | |
tree | ae919084a8c074d4af62bb14acad6840abc08fcc /wpa_supplicant/examples | |
parent | 6f8fa6e552d82c026d8b7a2630119423de002dd5 (diff) | |
download | hostap-ab1db08c0505804676a9862b59ed9b8800949957.zip hostap-ab1db08c0505804676a9862b59ed9b8800949957.tar.gz hostap-ab1db08c0505804676a9862b59ed9b8800949957.tar.bz2 |
WPS NFC: Use argparse in the nfcpy scripts
This cleans up command line parsing and simplifies the commands.
Signed-hostap: Jouni Malinen <jouni@qca.qualcomm.com>
Diffstat (limited to 'wpa_supplicant/examples')
-rwxr-xr-x | wpa_supplicant/examples/wps-nfc.py | 61 |
1 files changed, 30 insertions, 31 deletions
diff --git a/wpa_supplicant/examples/wps-nfc.py b/wpa_supplicant/examples/wps-nfc.py index 3d7e016..e1d59e9 100755 --- a/wpa_supplicant/examples/wps-nfc.py +++ b/wpa_supplicant/examples/wps-nfc.py @@ -12,6 +12,7 @@ import time import random import StringIO import threading +import argparse import nfc import nfc.ndef @@ -265,10 +266,10 @@ def wps_write_config_tag(clf, id=None, wait_remove=True): clf.connect(rdwr={'on-connect': rdwr_connected_write}) -def wps_write_er_config_tag(clf, uuid): +def wps_write_er_config_tag(clf, uuid, wait_remove=True): print "Write WPS ER config token" global write_data, write_wait_remove - write_wait_remove = True + write_wait_remove = wait_remove write_data = wpas_get_er_config_token(uuid) if write_data == None: print "Could not get WPS config token from wpa_supplicant" @@ -354,44 +355,42 @@ def llcp_connected(llc): def main(): clf = nfc.ContactlessFrontend() - try: - global arg_uuid - arg_uuid = None - if len(sys.argv) > 1 and sys.argv[1] != '-1': - arg_uuid = sys.argv[1] - - global only_one - if len(sys.argv) > 1 and sys.argv[1] == '-1': - only_one = True - else: - only_one = False - - if not clf.open("usb"): - print "Could not open connection with an NFC device" - raise SystemExit + parser = argparse.ArgumentParser(description='nfcpy to wpa_supplicant integration for WPS NFC operations') + parser.add_argument('--only-one', '-1', action='store_true', + 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('--uuid', + help='UUID of an AP (used for WPS ER operations)') + parser.add_argument('--id', + help='network id (used for WPS ER operations)') + parser.add_argument('command', choices=['write-config', + 'write-er-config', + 'write-password'], + nargs='?') + args = parser.parse_args() - if len(sys.argv) > 1 and sys.argv[1] == "write-config": - wps_write_config_tag(clf) - raise SystemExit + global arg_uuid + arg_uuid = args.uuid - if len(sys.argv) > 1 and sys.argv[1] == "write-config-no-wait": - wps_write_config_tag(clf, wait_remove=False) - raise SystemExit + global only_one + only_one = args.only_one - if len(sys.argv) > 2 and sys.argv[1] == "write-config-id": - wps_write_config_tag(clf, sys.argv[2]) + try: + if not clf.open("usb"): + print "Could not open connection with an NFC device" raise SystemExit - if len(sys.argv) > 2 and sys.argv[1] == "write-er-config": - wps_write_er_config_tag(clf, sys.argv[2]) + if args.command == "write-config": + wps_write_config_tag(clf, id=args.id, wait_remove=not args.no_wait) raise SystemExit - if len(sys.argv) > 1 and sys.argv[1] == "write-password": - wps_write_password_tag(clf) + if args.command == "write-er-config": + wps_write_er_config_tag(clf, args.uuid, wait_remove=not args.no_wait) raise SystemExit - if len(sys.argv) > 1 and sys.argv[1] == "write-password-no-wait": - wps_write_password_tag(clf, wait_remove=False) + if args.command == "write-password": + wps_write_password_tag(clf, wait_remove=not args.no_wait) raise SystemExit global continue_loop |