1 From: NIIBE Yutaka <gniibe@fsij.org>
2 Date: Mon, 13 Feb 2017 11:09:13 +0900
3 Subject: scd: Fix use case of PC/SC.
5 * scd/apdu.c (apdu_open_reader): Add an argument APP_EMPTY.
6 When CCID driver fails to open, try PC/SC if APP is nothing.
7 * scd/app.c (select_application): Supply arg if APP is nothing.
11 After scanning available card readers by CCID driver, scdaemon should
12 try PC/SC service if no APP is registered yet. Also, when the slot
13 is allocated for PC/SC (ccid.handle==NULL), it should not call
14 ccid_compare_BAI, otherwise scdaemon crashes.
16 Debian-bug-id: 852702, 854005, 854595, 854616
18 Signed-off-by: NIIBE Yutaka <gniibe@fsij.org>
20 scd/apdu.c | 14 +++++++++++---
23 3 files changed, 13 insertions(+), 5 deletions(-)
25 diff --git a/scd/apdu.c b/scd/apdu.c
26 index 38ebd2be5..149154cf3 100644
29 @@ -3117,7 +3117,7 @@ apdu_open_one_reader (const char *portstr)
33 -apdu_open_reader (struct dev_list *dl)
34 +apdu_open_reader (struct dev_list *dl, int app_empty)
38 @@ -3167,6 +3167,7 @@ apdu_open_reader (struct dev_list *dl)
39 /* Check identity by BAI against already opened HANDLEs. */
40 for (slot = 0; slot < MAX_READER; slot++)
41 if (reader_table[slot].used
42 + && reader_table[slot].ccid.handle
43 && ccid_compare_BAI (reader_table[slot].ccid.handle, bai))
46 @@ -3191,12 +3192,19 @@ apdu_open_reader (struct dev_list *dl)
51 + /* Not found. Try one for PC/SC, only when it's the initial scan. */
52 + if (app_empty && dl->idx == dl->idx_max)
55 + slot = apdu_open_one_reader (dl->portstr);
62 { /* PC/SC readers. */
64 + if (app_empty && dl->idx == 0)
67 slot = apdu_open_one_reader (dl->portstr);
68 diff --git a/scd/apdu.h b/scd/apdu.h
69 index 473def518..6751e8c9b 100644
72 @@ -91,7 +91,7 @@ gpg_error_t apdu_dev_list_start (const char *portstr, struct dev_list **l_p);
73 void apdu_dev_list_finish (struct dev_list *l);
75 /* Note, that apdu_open_reader returns no status word but -1 on error. */
76 -int apdu_open_reader (struct dev_list *l);
77 +int apdu_open_reader (struct dev_list *l, int app_empty);
78 int apdu_open_remote_reader (const char *portstr,
79 const unsigned char *cookie, size_t length,
80 int (*readfnc) (void *opaque,
81 diff --git a/scd/app.c b/scd/app.c
82 index 989e0c060..8fb0d4553 100644
85 @@ -340,7 +340,7 @@ select_application (ctrl_t ctrl, const char *name, app_t *r_app,
89 - slot = apdu_open_reader (l);
90 + slot = apdu_open_reader (l, !app_top);