mirror of
git://git.gnupg.org/gnupg.git
synced 2025-01-03 12:11:33 +01:00
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.
This commit is contained in:
parent
5804db1a13
commit
0e34683a6c
@ -538,8 +538,12 @@ apdu_strerror (int rc)
|
|||||||
switch (rc)
|
switch (rc)
|
||||||
{
|
{
|
||||||
case SW_EOF_REACHED : return "eof reached";
|
case SW_EOF_REACHED : return "eof reached";
|
||||||
|
case SW_TERM_STATE : return "termination state";
|
||||||
case SW_EEPROM_FAILURE : return "eeprom failure";
|
case SW_EEPROM_FAILURE : return "eeprom failure";
|
||||||
|
case SW_ACK_TIMEOUT : return "ACK timeout";
|
||||||
case SW_WRONG_LENGTH : return "wrong length";
|
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_WRONG : return "CHV wrong";
|
||||||
case SW_CHV_BLOCKED : return "CHV blocked";
|
case SW_CHV_BLOCKED : return "CHV blocked";
|
||||||
case SW_REF_DATA_INV : return "referenced data invalidated";
|
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_NOT_SUPPORTED : return "not supported";
|
||||||
case SW_FILE_NOT_FOUND : return "file not found";
|
case SW_FILE_NOT_FOUND : return "file not found";
|
||||||
case SW_RECORD_NOT_FOUND:return "record 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_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_INCORRECT_P0_P1: return "incorrect parameters P0,P1";
|
||||||
case SW_BAD_LC : return "Lc inconsistent with 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_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_INS_NOT_SUP : return "instruction not supported";
|
||||||
case SW_CLA_NOT_SUP : return "class not supported";
|
case SW_CLA_NOT_SUP : return "class not supported";
|
||||||
case SW_SUCCESS : return "success";
|
case SW_SUCCESS : return "success";
|
||||||
|
@ -1728,15 +1728,18 @@ static const char hlp_getinfo[] =
|
|||||||
" all_active_apps\n"
|
" all_active_apps\n"
|
||||||
" - Return a list of active apps on all inserted cards.\n"
|
" - Return a list of active apps on all inserted cards.\n"
|
||||||
" cmd_has_option CMD OPT\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
|
static gpg_error_t
|
||||||
cmd_getinfo (assuan_context_t ctx, char *line)
|
cmd_getinfo (assuan_context_t ctx, char *line)
|
||||||
{
|
{
|
||||||
int rc = 0;
|
int rc = 0;
|
||||||
|
const char *s;
|
||||||
|
|
||||||
if (!strcmp (line, "version"))
|
if (!strcmp (line, "version"))
|
||||||
{
|
{
|
||||||
const char *s = VERSION;
|
s = VERSION;
|
||||||
rc = assuan_send_data (ctx, s, strlen (s));
|
rc = assuan_send_data (ctx, s, strlen (s));
|
||||||
}
|
}
|
||||||
else if (!strcmp (line, "pid"))
|
else if (!strcmp (line, "pid"))
|
||||||
@ -1780,8 +1783,7 @@ cmd_getinfo (assuan_context_t ctx, char *line)
|
|||||||
}
|
}
|
||||||
else if (!strcmp (line, "socket_name"))
|
else if (!strcmp (line, "socket_name"))
|
||||||
{
|
{
|
||||||
const char *s = scd_get_socket_name ();
|
s = scd_get_socket_name ();
|
||||||
|
|
||||||
if (s)
|
if (s)
|
||||||
rc = assuan_send_data (ctx, s, strlen (s));
|
rc = assuan_send_data (ctx, s, strlen (s));
|
||||||
else
|
else
|
||||||
@ -1809,27 +1811,27 @@ cmd_getinfo (assuan_context_t ctx, char *line)
|
|||||||
else if (!strcmp (line, "reader_list"))
|
else if (!strcmp (line, "reader_list"))
|
||||||
{
|
{
|
||||||
#ifdef HAVE_LIBUSB
|
#ifdef HAVE_LIBUSB
|
||||||
char *s = ccid_get_reader_list ();
|
char *p = ccid_get_reader_list ();
|
||||||
#else
|
#else
|
||||||
char *s = NULL;
|
char *p = NULL;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if (s)
|
if (p)
|
||||||
rc = assuan_send_data (ctx, s, strlen (s));
|
rc = assuan_send_data (ctx, p, strlen (p));
|
||||||
else
|
else
|
||||||
rc = gpg_error (GPG_ERR_NO_DATA);
|
rc = gpg_error (GPG_ERR_NO_DATA);
|
||||||
xfree (s);
|
xfree (p);
|
||||||
}
|
}
|
||||||
else if (!strcmp (line, "deny_admin"))
|
else if (!strcmp (line, "deny_admin"))
|
||||||
rc = opt.allow_admin? gpg_error (GPG_ERR_GENERAL) : 0;
|
rc = opt.allow_admin? gpg_error (GPG_ERR_GENERAL) : 0;
|
||||||
else if (!strcmp (line, "app_list"))
|
else if (!strcmp (line, "app_list"))
|
||||||
{
|
{
|
||||||
char *s = get_supported_applications ();
|
char *p = get_supported_applications ();
|
||||||
if (s)
|
if (p)
|
||||||
rc = assuan_send_data (ctx, s, strlen (s));
|
rc = assuan_send_data (ctx, p, strlen (p));
|
||||||
else
|
else
|
||||||
rc = 0;
|
rc = 0;
|
||||||
xfree (s);
|
xfree (p);
|
||||||
}
|
}
|
||||||
else if (!strcmp (line, "card_list"))
|
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);
|
ctrl_t ctrl = assuan_get_pointer (ctx);
|
||||||
rc = app_send_active_apps (NULL, ctrl);
|
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
|
else
|
||||||
rc = set_error (GPG_ERR_ASS_PARAMETER, "unknown value for WHAT");
|
rc = set_error (GPG_ERR_ASS_PARAMETER, "unknown value for WHAT");
|
||||||
return rc;
|
return rc;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user