aboutsummaryrefslogtreecommitdiffstats
path: root/scd/apdu.c
diff options
context:
space:
mode:
authorNIIBE Yutaka <[email protected]>2019-09-12 00:30:37 +0000
committerNIIBE Yutaka <[email protected]>2019-09-12 00:30:37 +0000
commit6d750fe7fc4224924f13ef578010a26cdbe0a67b (patch)
tree8c949dd4f4073b0abe0445e4527b50b3de5fbdbd /scd/apdu.c
parentscd,pcsc: Remove the restriction of no-scanning in PC/SC. (diff)
downloadgnupg-6d750fe7fc4224924f13ef578010a26cdbe0a67b.tar.gz
gnupg-6d750fe7fc4224924f13ef578010a26cdbe0a67b.zip
scd,pcsc: Support "reader-port" option for PC/SC reader.
* scd/apdu.c (apdu_open_reader): Skip use of a reader if it's not the one specified when it is specified. Signed-off-by: NIIBE Yutaka <[email protected]>
Diffstat (limited to 'scd/apdu.c')
-rw-r--r--scd/apdu.c63
1 files changed, 34 insertions, 29 deletions
diff --git a/scd/apdu.c b/scd/apdu.c
index 99daef63d..ced246b3a 100644
--- a/scd/apdu.c
+++ b/scd/apdu.c
@@ -2058,44 +2058,37 @@ int
apdu_open_reader (struct dev_list *dl)
{
int slot;
+ int readerno;
-#ifdef HAVE_LIBUSB
- if (!opt.disable_ccid)
- { /* CCID readers. */
- int readerno;
+ if (!dl->table)
+ return -1;
- if (!dl->table)
+ /* See whether we want to use the reader ID string or a reader
+ number. A readerno of -1 indicates that the reader ID string is
+ to be used. */
+ if (dl->portstr && strchr (dl->portstr, ':'))
+ readerno = -1; /* We want to use the readerid. */
+ else if (dl->portstr)
+ {
+ readerno = atoi (dl->portstr);
+ if (readerno < 0 || readerno >= dl->idx_max)
return -1;
- /* See whether we want to use the reader ID string or a reader
- number. A readerno of -1 indicates that the reader ID string is
- to be used. */
- if (dl->portstr && strchr (dl->portstr, ':'))
- readerno = -1; /* We want to use the readerid. */
- else if (dl->portstr)
- {
- readerno = atoi (dl->portstr);
- if (readerno < 0)
- {
- return -1;
- }
- }
- else
- readerno = 0; /* Default. */
+ dl->idx = readerno;
+ dl->portstr = NULL;
+ }
+ else
+ readerno = 0; /* Default. */
+#ifdef HAVE_LIBUSB
+ if (!opt.disable_ccid)
+ { /* CCID readers. */
if (readerno > 0)
{ /* Use single, the specific reader. */
- if (readerno >= dl->idx_max)
- return -1;
-
- dl->idx = readerno;
- dl->portstr = NULL;
slot = open_ccid_reader (dl);
+ /* And stick the reader and no scan. */
dl->idx = dl->idx_max;
- if (slot >= 0)
- return slot;
- else
- return -1;
+ return slot;
}
while (dl->idx < dl->idx_max)
@@ -2139,6 +2132,14 @@ apdu_open_reader (struct dev_list *dl)
else
#endif
{ /* PC/SC readers. */
+ if (readerno > 0)
+ { /* Use single, the specific reader. */
+ slot = open_pcsc_reader (pcsc.rdrname[readerno]);
+ /* And stick the reader and no scan. */
+ dl->idx = dl->idx_max;
+ return slot;
+ }
+
while (dl->idx < dl->idx_max)
{
const char *rdrname = pcsc.rdrname[dl->idx];
@@ -2157,6 +2158,10 @@ apdu_open_reader (struct dev_list *dl)
if (DBG_READER)
log_debug ("apdu_open_reader: new device=%s\n", rdrname);
+ /* When reader string is specified, check if it is the one. */
+ if (readerno < 0 && strcmp (rdrname, dl->portstr) != 0)
+ continue;
+
slot = open_pcsc_reader (rdrname);
dl->idx++;