diff --git a/doc/tools/opensc-explorer.1.xml b/doc/tools/opensc-explorer.1.xml
index 6e981efb..40646fb7 100644
--- a/doc/tools/opensc-explorer.1.xml
+++ b/doc/tools/opensc-explorer.1.xml
@@ -475,6 +475,15 @@
+
+
+ sm [open]|[close]
+
+
+ Calls the card's open or close Secure Messaging handler.
+
+
+
diff --git a/src/tools/opensc-explorer.c b/src/tools/opensc-explorer.c
index 27c35210..5d4aa0b3 100644
--- a/src/tools/opensc-explorer.c
+++ b/src/tools/opensc-explorer.c
@@ -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", "[]",
"decode an ASN.1 file" },
+ { do_sm,
+ "sm", "open|close",
+ "call SM 'open' or 'close' handlers, if available"},
{ do_debug,
"debug", "[]",
"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;