[pkg-opensc-commit] [opensc] 205/295: Add reset operation to opensc-tool

Eric Dorland eric at moszumanska.debian.org
Sat Jun 24 21:11:32 UTC 2017


This is an automated email from the git hooks/post-receive script.

eric pushed a commit to branch master
in repository opensc.

commit 1479c4cb3b27ae989f7d86529994261a13946fa0
Author: Maciej S. Szmigiero <mail at maciej.szmigiero.name>
Date:   Tue Aug 23 13:25:56 2016 +0200

    Add reset operation to opensc-tool
    
    Add "--reset" parameter with optional argument to opensc-tool which
    resets a card in reader. Both cold or warm resets are possible
    (cold is default).
    
    Signed-off-by: Maciej S. Szmigiero <mail at maciej.szmigiero.name>
---
 doc/tools/opensc-tool.1.xml |  7 +++++++
 src/tools/opensc-tool.c     | 41 ++++++++++++++++++++++++++++++++++++++++-
 2 files changed, 47 insertions(+), 1 deletion(-)

diff --git a/doc/tools/opensc-tool.1.xml b/doc/tools/opensc-tool.1.xml
index 895c86d..b2d77a2 100644
--- a/doc/tools/opensc-tool.1.xml
+++ b/doc/tools/opensc-tool.1.xml
@@ -100,6 +100,13 @@
 				</varlistentry>
 				<varlistentry>
 					<term>
+						<option>--reset</option>[=<replaceable>type</replaceable>],
+					</term>
+					<listitem><para>Resets the card in reader.
+					The default reset type is <literal>cold</literal>, but warm reset is also possible.</para></listitem>
+				</varlistentry>
+				<varlistentry>
+					<term>
 						<option>--send-apdu</option> <replaceable>apdu</replaceable>,
 						<option>-s</option> <replaceable>apdu</replaceable>
 					</term>
diff --git a/src/tools/opensc-tool.c b/src/tools/opensc-tool.c
index 54d3872..4523edc 100644
--- a/src/tools/opensc-tool.c
+++ b/src/tools/opensc-tool.c
@@ -51,7 +51,8 @@ static int	verbose = 0;
 enum {
 	OPT_SERIAL = 0x100,
 	OPT_LIST_ALG,
-	OPT_VERSION
+	OPT_VERSION,
+	OPT_RESET
 };
 
 static const struct option options[] = {
@@ -67,6 +68,7 @@ static const struct option options[] = {
 	{ "list-files",		0, NULL,		'f' },
 	{ "send-apdu",		1, NULL,		's' },
 	{ "reader",		1, NULL,		'r' },
+	{ "reset",		2, NULL,	OPT_RESET   },
 	{ "card-driver",	1, NULL,		'c' },
 	{ "list-algorithms",    0, NULL,	OPT_LIST_ALG },
 	{ "wait",		0, NULL,		'w' },
@@ -87,6 +89,7 @@ static const char *option_help[] = {
 	"Recursively lists files stored on card",
 	"Sends an APDU in format AA:BB:CC:DD:EE:FF...",
 	"Uses reader number <arg> [0]",
+	"Does card reset of type <cold|warm> [cold]",
 	"Forces the use of driver <arg> [auto-detect]",
 	"Lists algorithms supported by card",
 	"Wait for a card to be inserted",
@@ -642,6 +645,29 @@ static int list_algorithms(void)
 	return 0;
 }
 
+static int card_reset(const char *reset_type)
+{
+	int cold_reset;
+	int r;
+
+	if (reset_type && strcmp(reset_type, "cold") &&
+	    strcmp(reset_type, "warm")) {
+		fprintf(stderr, "Invalid reset type: %s\n", reset_type);
+		return 2;
+	}
+
+	cold_reset = !reset_type || strcmp(reset_type, "cold") == 0;
+
+	r = sc_reset(card, cold_reset);
+	if (r) {
+		fprintf(stderr, "sc_reset(%s) failed: %d\n",
+			cold_reset ? "cold" : "warm", r);
+		return 1;
+	}
+
+	return 0;
+}
+
 int main(int argc, char * const argv[])
 {
 	int err = 0, r, c, long_optind = 0;
@@ -657,9 +683,11 @@ int main(int argc, char * const argv[])
 	int do_print_serial = 0;
 	int do_print_name = 0;
 	int do_list_algorithms = 0;
+	int do_reset = 0;
 	int action_count = 0;
 	const char *opt_driver = NULL;
 	const char *opt_conf_entry = NULL;
+	const char *opt_reset_type = NULL;
 	char **p;
 	sc_context_param_t ctx_param;
 
@@ -746,6 +774,11 @@ int main(int argc, char * const argv[])
 			do_list_algorithms = 1;
 			action_count++;
 			break;
+		case OPT_RESET:
+			do_reset = 1;
+			opt_reset_type = optarg;
+			action_count++;
+			break;
 		}
 	}
 	if (action_count == 0)
@@ -854,6 +887,12 @@ int main(int argc, char * const argv[])
 			goto end;
 		action_count--;
 	}
+
+	if (do_reset) {
+		if ((err = card_reset(opt_reset_type)))
+			goto end;
+		action_count--;
+	}
 end:
 	if (card) {
 		sc_unlock(card);

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-opensc/opensc.git



More information about the pkg-opensc-commit mailing list