From e9d9de3ae2908bf358104bda3de12e660b506efb Mon Sep 17 00:00:00 2001 From: NIIBE Yutaka Date: Fri, 22 Feb 2019 09:21:11 +0900 Subject: [PATCH] Implement timeout for the user interaction. --- ChangeLog | 5 +++++ src/usb-ccid.c | 31 ++++++++++++++++++++++++++----- 2 files changed, 31 insertions(+), 5 deletions(-) diff --git a/ChangeLog b/ChangeLog index 05a41f9..6ae5ecf 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2019-02-22 NIIBE Yutaka + + * src/usb-ccid.c (GPG_ACK_TIMEOUT): New. + (ccid_thread): Implement timout for the user interaction. + 2019-02-21 NIIBE Yutaka * GNUK_USB_DEVICE_ID: Add 1209:2440. diff --git a/src/usb-ccid.c b/src/usb-ccid.c index 512ef55..820b226 100644 --- a/src/usb-ccid.c +++ b/src/usb-ccid.c @@ -1,7 +1,8 @@ /* * usb-ccid.c -- USB CCID protocol handling * - * Copyright (C) 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017, 2018 + * Copyright (C) 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017, 2018, + * 2019 * Free Software Initiative of Japan * Author: NIIBE Yutaka * @@ -190,6 +191,7 @@ struct ccid { uint32_t state : 4; uint32_t err : 1; uint32_t tx_busy : 1; + uint32_t timeout_cnt: 3; uint8_t *p; size_t len; @@ -1577,7 +1579,7 @@ ccid_notify_slot_change (struct ccid *c) #define USB_CCID_TIMEOUT (1950*1000) #define GPG_THREAD_TERMINATED 0xffff - +#define GPG_ACK_TIMEOUT 0x6600 extern uint32_t bDeviceState; extern void usb_device_reset (struct usb_dev *dev); @@ -1813,7 +1815,11 @@ ccid_thread (void *arg) } #endif - timeout = USB_CCID_TIMEOUT; + if (timeout == 0) + { + timeout = USB_CCID_TIMEOUT; + c->timeout_cnt++; + } m = eventflag_get (&c->ccid_comm); if (m == EV_CARD_CHANGE) @@ -1836,7 +1842,10 @@ ccid_thread (void *arg) ccid_notify_slot_change (c); } else if (m == EV_RX_DATA_READY) - c->ccid_state = ccid_handle_data (c); + { + c->ccid_state = ccid_handle_data (c); + c->timeout_cnt = 0; + } else if (m == EV_EXEC_FINISHED) if (c->ccid_state == CCID_STATE_EXECUTE) { @@ -1907,7 +1916,19 @@ ccid_thread (void *arg) ccid_prepare_receive (c); } else /* Timeout */ - c->ccid_state = ccid_handle_timeout (c); + { + if (c->timeout_cnt == 7 + && c->ccid_state == CCID_STATE_ACK_REQUIRED_1) + { + ackbtn_disable (); + led_blink (LED_WAIT_FOR_BUTTON); + c->a->sw = GPG_ACK_TIMEOUT; + c->a->res_apdu_data_len = 0; + goto exec_done; + } + else + c->ccid_state = ccid_handle_timeout (c); + } } if (c->application)