opensc-tool: add 'call-SM-handler' command

'open' and 'close' handlers of the card's SM driver can be called
This commit is contained in:
Viktor Tarasov 2013-01-06 13:13:08 +01:00
parent 3f30e14087
commit 4c1c39f3e4
2 changed files with 47 additions and 0 deletions

View File

@ -475,6 +475,15 @@
</listitem>
</varlistentry>
<varlistentry>
<term>
<command>sm</command> <replaceable>[open]</replaceable>|<replaceable>[close]</replaceable>
</term>
<listitem>
<para>Calls the card's <replaceable>open</replaceable> or <replaceable>close</replaceable> Secure Messaging handler.</para>
</listitem>
</varlistentry>
</variablelist>
</para>
</refsect1>

View File

@ -104,6 +104,7 @@ static int do_random(int argc, char **argv);
static int do_get_data(int argc, char **argv);
static int do_put_data(int argc, char **argv);
static int do_apdu(int argc, char **argv);
static int do_sm(int argc, char **argv);
static int do_asn1(int argc, char **argv);
static int do_help(int argc, char **argv);
static int do_quit(int argc, char **argv);
@ -186,6 +187,9 @@ static struct command cmds[] = {
{ do_asn1,
"asn1", "[<file id>]",
"decode an ASN.1 file" },
{ do_sm,
"sm", "open|close",
"call SM 'open' or 'close' handlers, if available"},
{ do_debug,
"debug", "[<value>]",
"get/set the debug level" },
@ -1639,6 +1643,40 @@ err:
return -err;
}
static int do_sm(int argc, char **argv)
{
int r = SC_ERROR_NOT_SUPPORTED, ret = -1;
if (argc != 1)
return usage(do_sm);
#ifdef ENABLE_SM
if (!strcmp(argv[0],"open")) {
if (!card->sm_ctx.ops.open) {
printf("Not supported\n");
return -1;
}
r = card->sm_ctx.ops.open(card);
}
else if (!strcmp(argv[0],"close")) {
if (!card->sm_ctx.ops.close) {
printf("Not supported\n");
return -1;
}
r = card->sm_ctx.ops.close(card);
}
#endif
if (r == SC_SUCCESS) {
ret = 0;
printf("Success!\n");
}
else {
printf("Failure: %s\n", sc_strerror(r));
}
return ret;
}
static int do_help(int argc, char **argv)
{
struct command *cmd;