diff --git a/scd/app-common.h b/scd/app-common.h index fb0fe550a..7c6822fdd 100644 --- a/scd/app-common.h +++ b/scd/app-common.h @@ -123,6 +123,7 @@ size_t app_help_read_length_of_cert (int slot, int fid, size_t *r_certoff); /*-- app.c --*/ app_t app_list_start (void); void app_list_finish (void); +void app_send_card_list (ctrl_t ctrl); void app_dump_state (void); void application_notify_card_reset (int slot); diff --git a/scd/app.c b/scd/app.c index 06850d87f..681acb822 100644 --- a/scd/app.c +++ b/scd/app.c @@ -1103,3 +1103,21 @@ app_list_finish (void) { npth_mutex_unlock (&app_list_lock); } + +void +app_send_card_list (ctrl_t ctrl) +{ + app_t a; + char buf[65]; + + npth_mutex_lock (&app_list_lock); + for (a = app_top; a; a = a->next) + { + if (DIM (buf) < 2 * a->serialnolen + 1) + continue; + + bin2hex (a->serialno, a->serialnolen, buf); + send_status_direct (ctrl, "SERIALNO", buf); + } + npth_mutex_unlock (&app_list_lock); +} diff --git a/scd/command.c b/scd/command.c index dc854e35d..cad8c6e39 100644 --- a/scd/command.c +++ b/scd/command.c @@ -1392,7 +1392,10 @@ static const char hlp_getinfo[] = "\n" "app_list - Return a list of supported applications. One\n" " application per line, fields delimited by colons,\n" - " first field is the name."; + " first field is the name.\n" + "\n" + "card_list - Return a list of serial numbers of active cards,\n" + " using a status response."; static gpg_error_t cmd_getinfo (assuan_context_t ctx, char *line) { @@ -1422,10 +1425,11 @@ cmd_getinfo (assuan_context_t ctx, char *line) else if (!strcmp (line, "status")) { ctrl_t ctrl = assuan_get_pointer (ctx); - app_t app = ctrl->app_ctx; - char flag = 'r'; + char flag; - if (!ctrl->server_local->card_removed && app) + if (open_card (ctrl)) + flag = 'r'; + else flag = 'u'; rc = assuan_send_data (ctx, &flag, 1); @@ -1455,6 +1459,12 @@ cmd_getinfo (assuan_context_t ctx, char *line) rc = 0; xfree (s); } + else if (!strcmp (line, "card_list")) + { + ctrl_t ctrl = assuan_get_pointer (ctx); + + app_send_card_list (ctrl); + } else rc = set_error (GPG_ERR_ASS_PARAMETER, "unknown value for WHAT"); return rc;