From 59a5681e63bb6ecb89d86dc2aee711b24fc86eca Mon Sep 17 00:00:00 2001 From: Marcus Brinkmann Date: Fri, 1 Sep 2006 13:57:33 +0000 Subject: [PATCH] 2006-09-01 Marcus Brinkmann * command.c (cmd_getinfo): Handle status command. --- scd/ChangeLog | 4 ++++ scd/command.c | 34 +++++++++++++++++++++++++++++++--- 2 files changed, 35 insertions(+), 3 deletions(-) diff --git a/scd/ChangeLog b/scd/ChangeLog index fec70991a..cf5be7f3d 100644 --- a/scd/ChangeLog +++ b/scd/ChangeLog @@ -1,3 +1,7 @@ +2006-09-01 Marcus Brinkmann + + * command.c (cmd_getinfo): Handle status command. + 2006-08-30 Marcus Brinkmann * command.c (do_reset): Delay resetting CTRL->reader_slot until diff --git a/scd/command.c b/scd/command.c index d0e13b833..63d86929d 100644 --- a/scd/command.c +++ b/scd/command.c @@ -295,7 +295,7 @@ get_reader_slot (void) /* If the card has not yet been opened, do it. Note that this function returns an Assuan error, so don't map the error a second - time */ + time. */ static assuan_error_t open_card (ctrl_t ctrl, const char *apptype) { @@ -1355,7 +1355,12 @@ cmd_unlock (assuan_context_t ctx, char *line) Supported values of WHAT are: socket_name - Return the name of the socket. - + status - Return the status of the current slot (in the future, may + also return the status of all slots). The status is a list of + one-character flags. The following flags are currently defined: + 'u' Usable card present. This is the normal state during operation. + 'r' Card removed. A reset is necessary. + These flags are exclusive. */ static int @@ -1372,6 +1377,29 @@ cmd_getinfo (assuan_context_t ctx, char *line) else rc = gpg_error (GPG_ERR_NO_DATA); } + else if (!strcmp (line, "status")) + { + ctrl_t ctrl = assuan_get_pointer (ctx); + int slot = ctrl->reader_slot; + char flag = 'r'; + + if (!ctrl->server_local->card_removed && slot != -1) + { + struct slot_status_s *ss; + + if (!(slot >= 0 && slot < DIM(slot_table))) + BUG (); + + ss = &slot_table[slot]; + + if (!ss->valid) + BUG (); + + if (ss->any && (ss->status & 1)) + flag = 'u'; + } + rc = assuan_send_data (ctx, &flag, 1); + } else rc = set_error (Parameter_Error, "unknown value for WHAT"); return rc; @@ -1752,7 +1780,7 @@ update_reader_status_file (void) will set this on any card change because a reset or SERIALNO request must be done in any case. */ if (ss->any) - update_card_removed (ss->slot, 1); + update_card_removed (ss->slot, 1); /* XXX: MB: Should be idx? */ ss->any = 1; ss->status = status;