aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorWerner Koch <wk@gnupg.org>2020-11-27 11:14:30 +0100
committerWerner Koch <wk@gnupg.org>2020-11-27 11:14:30 +0100
commit0e34683a6c4b037aa50ca0f97ddb9d5c4e499084 (patch)
tree9ed6e896bfe1f0c9bb1fd4bca4529668f74980a5
parent5804db1a13d2cf8f4010d1257c586bed978c3173 (diff)
downloadgnupg-0e34683a6c4b037aa50ca0f97ddb9d5c4e499084.tar.gz
scd: New getinfo sub-command apdu_strerror.
* scd/apdu.c (apdu_strerror): Add missing status codes. * scd/command.c (cmd_getinfo): New sub-command apdu_strerror. -- This is quite handy for gpg-card's APDU command and avoids that we need to duplicate the mapping table or put it into a shared file.
-rw-r--r--scd/apdu.c9
-rw-r--r--scd/command.c34
2 files changed, 28 insertions, 15 deletions
diff --git a/scd/apdu.c b/scd/apdu.c
index a7512ee9a..9b473d56a 100644
--- a/scd/apdu.c
+++ b/scd/apdu.c
@@ -538,8 +538,12 @@ apdu_strerror (int rc)
switch (rc)
{
case SW_EOF_REACHED : return "eof reached";
+ case SW_TERM_STATE : return "termination state";
case SW_EEPROM_FAILURE : return "eeprom failure";
+ case SW_ACK_TIMEOUT : return "ACK timeout";
case SW_WRONG_LENGTH : return "wrong length";
+ case SW_SM_NOT_SUP : return "secure messaging not supported";
+ case SW_CC_NOT_SUP : return "command chaining not supported";
case SW_CHV_WRONG : return "CHV wrong";
case SW_CHV_BLOCKED : return "CHV blocked";
case SW_REF_DATA_INV : return "referenced data invalidated";
@@ -548,12 +552,13 @@ apdu_strerror (int rc)
case SW_NOT_SUPPORTED : return "not supported";
case SW_FILE_NOT_FOUND : return "file not found";
case SW_RECORD_NOT_FOUND:return "record not found";
- case SW_REF_NOT_FOUND : return "reference not found";
case SW_NOT_ENOUGH_MEMORY: return "not enough memory space in the file";
- case SW_INCONSISTENT_LC: return "Lc inconsistent with TLV structure.";
+ case SW_INCONSISTENT_LC: return "Lc inconsistent with TLV structure";
case SW_INCORRECT_P0_P1: return "incorrect parameters P0,P1";
case SW_BAD_LC : return "Lc inconsistent with P0,P1";
+ case SW_REF_NOT_FOUND : return "reference not found";
case SW_BAD_P0_P1 : return "bad P0,P1";
+ case SW_EXACT_LENGTH : return "exact length";
case SW_INS_NOT_SUP : return "instruction not supported";
case SW_CLA_NOT_SUP : return "class not supported";
case SW_SUCCESS : return "success";
diff --git a/scd/command.c b/scd/command.c
index 457347121..5bb52246b 100644
--- a/scd/command.c
+++ b/scd/command.c
@@ -1728,15 +1728,18 @@ static const char hlp_getinfo[] =
" all_active_apps\n"
" - Return a list of active apps on all inserted cards.\n"
" cmd_has_option CMD OPT\n"
- " - Returns OK if command CMD has option OPT.\n";
+ " - Returns OK if command CMD has option OPT.\n"
+ " apdu_strerror NUMBER\n"
+ " - Return a string for a status word.\n";
static gpg_error_t
cmd_getinfo (assuan_context_t ctx, char *line)
{
int rc = 0;
+ const char *s;
if (!strcmp (line, "version"))
{
- const char *s = VERSION;
+ s = VERSION;
rc = assuan_send_data (ctx, s, strlen (s));
}
else if (!strcmp (line, "pid"))
@@ -1780,8 +1783,7 @@ cmd_getinfo (assuan_context_t ctx, char *line)
}
else if (!strcmp (line, "socket_name"))
{
- const char *s = scd_get_socket_name ();
-
+ s = scd_get_socket_name ();
if (s)
rc = assuan_send_data (ctx, s, strlen (s));
else
@@ -1809,27 +1811,27 @@ cmd_getinfo (assuan_context_t ctx, char *line)
else if (!strcmp (line, "reader_list"))
{
#ifdef HAVE_LIBUSB
- char *s = ccid_get_reader_list ();
+ char *p = ccid_get_reader_list ();
#else
- char *s = NULL;
+ char *p = NULL;
#endif
- if (s)
- rc = assuan_send_data (ctx, s, strlen (s));
+ if (p)
+ rc = assuan_send_data (ctx, p, strlen (p));
else
rc = gpg_error (GPG_ERR_NO_DATA);
- xfree (s);
+ xfree (p);
}
else if (!strcmp (line, "deny_admin"))
rc = opt.allow_admin? gpg_error (GPG_ERR_GENERAL) : 0;
else if (!strcmp (line, "app_list"))
{
- char *s = get_supported_applications ();
- if (s)
- rc = assuan_send_data (ctx, s, strlen (s));
+ char *p = get_supported_applications ();
+ if (p)
+ rc = assuan_send_data (ctx, p, strlen (p));
else
rc = 0;
- xfree (s);
+ xfree (p);
}
else if (!strcmp (line, "card_list"))
{
@@ -1850,6 +1852,12 @@ cmd_getinfo (assuan_context_t ctx, char *line)
ctrl_t ctrl = assuan_get_pointer (ctx);
rc = app_send_active_apps (NULL, ctrl);
}
+ else if ((s=has_leading_keyword (line, "apdu_strerror")))
+ {
+ unsigned long ul = strtoul (s, NULL, 0);
+ s = apdu_strerror (ul);
+ rc = assuan_send_data (ctx, s, strlen (s));
+ }
else
rc = set_error (GPG_ERR_ASS_PARAMETER, "unknown value for WHAT");
return rc;