1
0
Fork 0
mirror of git://git.gnupg.org/gnupg.git synced 2025-07-02 22:46:30 +02:00

scd: Improve watching USB device removal.

* scd/apdu.c(struct reader_table_s): Add require_get_status.
(apdu_connect): Change return value meaning.  Call apdu_reset here.
* scd/app.c (app_new_register): Add require_get_status.
(select_application): Use the return value of apdu_connect.
(scd_update_reader_status_file): Call update_fdset_for_usb with
checking all_have_intr_endp.
(app_list_start, app_list_finish): Remove.
* scd/ccid-driver.c (struct ccid_driver_s): Add transfer.
(intr_cb): Don't call libusb_transfer in this callback.
(ccid_require_get_status): New.
(do_close_reader): Call libusb_transfer here.
* scd/scdaemon.c (update_fdset_for_usb): Remove the first argument.

--

With Gnuk Token, it works fine as expected.  With Gemalto reader,
intr_cb is not called when card is removed.  So, the macro
LIBUSB_WORKS_EXPECTED_FOR_INTERRUPT_ENDP is not defined yet.

Signed-off-by: NIIBE Yutaka <gniibe@fsij.org>
This commit is contained in:
NIIBE Yutaka 2017-01-27 18:01:52 +09:00
parent 031e3fa7b9
commit 25cc8575da
8 changed files with 130 additions and 109 deletions

View file

@ -1202,15 +1202,14 @@ start_connection_thread (void *arg)
void
update_fdset_for_usb (int scanned, int all_have_intr_endp)
update_fdset_for_usb (int all_have_intr_endp)
{
#ifdef HAVE_LIBUSB
const struct libusb_pollfd **pfd_array = libusb_get_pollfds (NULL);
const struct libusb_pollfd **p;
#endif
if (scanned)
usb_all_have_intr_endp = all_have_intr_endp;
usb_all_have_intr_endp = all_have_intr_endp;
FD_ZERO (&fdset);
nfd = 0;
@ -1230,6 +1229,7 @@ update_fdset_for_usb (int scanned, int all_have_intr_endp)
if (nfd < fd)
nfd = fd;
p++;
log_debug ("USB: add %d to fdset\n", fd);
}
libusb_free_pollfds (pfd_array);
@ -1238,8 +1238,7 @@ update_fdset_for_usb (int scanned, int all_have_intr_endp)
/* Kick the select loop. */
write (notify_fd, "", 1);
log_debug ("update_fdset_for_usb (%d, %d): %d %lx\n",
scanned, all_have_intr_endp, nfd, fdset.fds_bits[0]);
log_debug ("update_fdset_for_usb (%d): %d\n", all_have_intr_endp, nfd);
}
static int
@ -1395,6 +1394,7 @@ handle_connections (void)
char buf[256];
read (pipe_fd[0], buf, sizeof buf);
ret--;
}
if (listen_fd != -1 && FD_ISSET (listen_fd, &read_fdset))
@ -1439,6 +1439,8 @@ handle_connections (void)
if (ret)
{
struct timeval tv = {0, 0};
log_debug ("scd main: USB handle events\n");
libusb_handle_events_timeout_completed (NULL, &tv, NULL);
}
#endif