diff options
author | NIIBE Yutaka <gniibe@fsij.org> | 2017-01-27 16:18:11 +0100 |
---|---|---|
committer | NIIBE Yutaka <gniibe@fsij.org> | 2017-01-27 16:36:27 +0100 |
commit | f3d9b2582bcaa1936b4fed5ec42a889b02df2f42 (patch) | |
tree | 6a1a814d7a688e411d2b655dd73398200d629eb7 /scd/app.c | |
parent | scd: Fix release of transfer object. (diff) | |
download | gnupg2-f3d9b2582bcaa1936b4fed5ec42a889b02df2f42.tar.xz gnupg2-f3d9b2582bcaa1936b4fed5ec42a889b02df2f42.zip |
scd: More changes on watching removal of card/reader.
* scd/app-common.h (struct app_ctx_s): Rename field to
periodical_check_needed.
* scd/scdaemon.c (update_usb): Rename from update_fdset_for_usb.
Don't use libusb_get_pollfds any more.
(scd_kick_the_loop): New.
(need_tick): Follow the rename.
(handle_connections): No libusb event handling here.
* scd/app.c (app_new_register): Follow the change of rename.
(select_application, scd_update_reader_status_file): Likewise.
* scd/ccid-driver.c (ccid_usb_thread_is_alive): New.
(intr_cb): Call scd_kick_the_loop.
(ccid_usb_thread): New. Thread to invoke INTERRUPT callback.
(ccid_open_usb_reader): Add thread invocation.
(ccid_require_get_status): Remove
LIBUSB_WORKS_EXPECTED_FOR_INTERRUPT_ENDP.
(do_close_reader): Carefully handle handle->transfer.
(get_escaped_usb_string): Insert npth_unprotect/npth_protect.
(do_close_reader, bulk_out, bulk_in, abort_cmd, ccid_slot_status)
(ccid_transceive, ccid_transceive_secure): Likewise.
--
It found that libusb_get_pollfds is not supported on Windows.
Besides, it's a bit difficult to use for the select loop.
Thus, we use the thread named ccid_usb_thread, instead.
Signed-off-by: NIIBE Yutaka <gniibe@fsij.org>
Diffstat (limited to 'scd/app.c')
-rw-r--r-- | scd/app.c | 37 |
1 files changed, 19 insertions, 18 deletions
@@ -175,7 +175,7 @@ app_reset (app_t app, ctrl_t ctrl, int send_reset) static gpg_error_t app_new_register (int slot, ctrl_t ctrl, const char *name, - int require_get_status) + int periodical_check_needed) { gpg_error_t err = 0; app_t app = NULL; @@ -304,7 +304,7 @@ app_new_register (int slot, ctrl_t ctrl, const char *name, return err; } - app->require_get_status = require_get_status; + app->periodical_check_needed = periodical_check_needed; npth_mutex_lock (&app_list_lock); app->next = app_top; @@ -331,7 +331,7 @@ select_application (ctrl_t ctrl, const char *name, app_t *r_app, if (scan || !app_top) { struct dev_list *l; - int all_have_intr_endp = 1; + int periodical_check_needed = 0; err = apdu_dev_list_start (opt.reader_port, &l); if (err) @@ -340,23 +340,24 @@ select_application (ctrl_t ctrl, const char *name, app_t *r_app, while (1) { int slot; - int require_get_status; + int periodical_check_needed; slot = apdu_open_reader (l); if (slot < 0) break; - require_get_status = apdu_connect (slot); - if (require_get_status < 0) + periodical_check_needed = apdu_connect (slot); + if (periodical_check_needed < 0) { /* We close a reader with no card. */ err = gpg_error (GPG_ERR_ENODEV); } else { - err = app_new_register (slot, ctrl, name, require_get_status); - if (require_get_status) - all_have_intr_endp = 0; + err = app_new_register (slot, ctrl, name, + periodical_check_needed); + if (periodical_check_needed) + periodical_check_needed = 1; } if (err) @@ -364,7 +365,7 @@ select_application (ctrl_t ctrl, const char *name, app_t *r_app, } apdu_dev_list_finish (l); - update_fdset_for_usb (all_have_intr_endp); + update_usb (periodical_check_needed); } npth_mutex_lock (&app_list_lock); @@ -1014,7 +1015,7 @@ void scd_update_reader_status_file (void) { app_t a, app_next; - int all_have_intr_endp = 1; + int periodical_check_needed = 0; int removal_detected = 0; npth_mutex_lock (&app_list_lock); @@ -1034,8 +1035,8 @@ scd_update_reader_status_file (void) else if (sw) { /* Get status failed. Ignore that. */ - if (a->require_get_status) - all_have_intr_endp = 0; + if (a->periodical_check_needed) + periodical_check_needed = 1; continue; } @@ -1054,20 +1055,20 @@ scd_update_reader_status_file (void) else { a->card_status = status; - if (a->require_get_status) - all_have_intr_endp = 0; + if (a->periodical_check_needed) + periodical_check_needed = 1; } } else { - if (a->require_get_status) - all_have_intr_endp = 0; + if (a->periodical_check_needed) + periodical_check_needed = 1; } } npth_mutex_unlock (&app_list_lock); if (removal_detected) - update_fdset_for_usb (all_have_intr_endp); + update_usb (periodical_check_needed); } /* This function must be called once to initialize this module. This |