summaryrefslogtreecommitdiffstats
path: root/scd/app.c
diff options
context:
space:
mode:
authorNIIBE Yutaka <gniibe@fsij.org>2017-01-06 01:14:13 +0100
committerNIIBE Yutaka <gniibe@fsij.org>2017-01-06 01:47:31 +0100
commit8a41e73c31adb86d4a7dca4da695e5ad1347811f (patch)
tree2524a19140709697330b279806b63b4234db24f8 /scd/app.c
parentSilence two -Wlogical-op warnings. (diff)
downloadgnupg2-8a41e73c31adb86d4a7dca4da695e5ad1347811f.tar.xz
gnupg2-8a41e73c31adb86d4a7dca4da695e5ad1347811f.zip
scd: Support multiple readers by CCID driver.
* scd/apdu.c (new_reader_slot): Lock is now in apdu_dev_list_start. (close_pcsc_reader_direct, close_ccid_reader): RDRNAME is handled... (apdu_close_reader): ... by this function now. (apdu_prepare_exit): Likewise. (open_ccid_reader): Open with dev_list. (apdu_dev_list_start, apdu_dev_list_finish): New. (apdu_open_one_reader): New. (apdu_open_reader): Support multiple readers. * scd/app.c (select_application): With SCAN, opening all readers available, and register as new APP. (app_write_learn_status): app->ref_count == 0 is valid for APP which is not yet used. (app_list_start, app_list_finish): New. * scd/ccid-driver.c (struct ccid_driver_s): Remove RID and BCD_DEVICE. Add BAI. (parse_ccid_descriptor): BCD_DEVICE is now on the arguments. (ccid_dev_scan, ccid_dev_scan_finish): New. (ccid_get_BAI, ccid_compare_BAI, ccid_open_usb_reader): New. (ccid_open_reader): Support multiple readers. (ccid_set_progress_cb, ccid_close_reader): No RID any more. -- With this change, multiple readers/tokens are supported by the internal CCID driver of GnuPG. Until the changes of upper layers (scdaemon, gpg-agent, and gpg front end), only a single reader is used, though. Signed-off-by: NIIBE Yutaka <gniibe@fsij.org>
Diffstat (limited to 'scd/app.c')
-rw-r--r--scd/app.c63
1 files changed, 38 insertions, 25 deletions
diff --git a/scd/app.c b/scd/app.c
index a49972433..6db9e27ef 100644
--- a/scd/app.c
+++ b/scd/app.c
@@ -319,22 +319,30 @@ app_new_register (int slot, ctrl_t ctrl, const char *name)
gpg_error_t
select_application (ctrl_t ctrl, const char *name, app_t *r_app, int scan)
{
- gpg_error_t err;
+ gpg_error_t err = 0;
app_t app;
- int slot;
*r_app = NULL;
- if ((scan && !app_top)
- /* FIXME: Here, we can change code to support multiple readers.
- For now, we only open a single reader.
- */
- || !app_top)
+ if (scan || !app_top)
{
- slot = apdu_open_reader (opt.reader_port);
- if (slot >= 0)
+ struct dev_list *l;
+
+ err = apdu_dev_list_start (opt.reader_port, &l);
+ if (err)
+ return err;
+
+ while (1)
{
- int sw = apdu_connect (slot);
+ int slot;
+ int sw;
+
+ slot = apdu_open_reader (l);
+ if (slot < 0)
+ break;
+
+ err = 0;
+ sw = apdu_connect (slot);
if (sw == SW_HOST_CARD_INACTIVE)
{
@@ -346,23 +354,17 @@ select_application (ctrl_t ctrl, const char *name, app_t *r_app, int scan)
err = 0;
else
err = gpg_error (GPG_ERR_ENODEV);
+
+ if (!err)
+ err = app_new_register (slot, ctrl, name);
+ else
+ apdu_close_reader (slot);
}
- else
- err = gpg_error (GPG_ERR_ENODEV);
- if (!err)
- err = app_new_register (slot, ctrl, name);
- else
- apdu_close_reader (slot);
+ apdu_dev_list_finish (l);
}
- else
- err = 0;
-
- if (!err)
- app = app_top;
- else
- app = NULL;
+ app = app_top;
if (app)
{
lock_app (app, ctrl);
@@ -552,8 +554,6 @@ app_write_learn_status (app_t app, ctrl_t ctrl, unsigned int flags)
if (!app)
return gpg_error (GPG_ERR_INV_VALUE);
- if (!app->ref_count)
- return gpg_error (GPG_ERR_CARD_NOT_INITIALIZED);
if (!app->fnc.learn_status)
return gpg_error (GPG_ERR_UNSUPPORTED_OPERATION);
@@ -1071,3 +1071,16 @@ initialize_module_command (void)
return apdu_init ();
}
+
+app_t
+app_list_start (void)
+{
+ npth_mutex_lock (&app_list_lock);
+ return app_top;
+}
+
+void
+app_list_finish (void)
+{
+ npth_mutex_unlock (&app_list_lock);
+}