Add ccid_notify_slot_change for the interrupt transfer

This commit is contained in:
NIIBE Yutaka
2016-06-01 07:52:56 +09:00
parent d636bf314c
commit 907d8c7a8e
3 changed files with 43 additions and 23 deletions

View File

@@ -1,3 +1,9 @@
2016-06-01 Niibe Yutaka <gniibe@fsij.org>
* src/usb-ccid.c (ccid_notify_slot_change): New.
(ccid_thread): Call ccid_notify_slot_change at
interface_reset and EV_CARD_CHANGE.
2016-05-31 NIIBE Yutaka <gniibe@fsij.org> 2016-05-31 NIIBE Yutaka <gniibe@fsij.org>
* src/usb_stm32f103.c, src/stm32f103.h: Remove. * src/usb_stm32f103.c, src/stm32f103.h: Remove.

View File

@@ -28,9 +28,9 @@ void ccid_usb_reset (int);
#define EV_RX_DATA_READY 1 /* USB Rx data available */ #define EV_RX_DATA_READY 1 /* USB Rx data available */
#define EV_EXEC_FINISHED 2 /* OpenPGP Execution finished */ #define EV_EXEC_FINISHED 2 /* OpenPGP Execution finished */
#define EV_TX_FINISHED 4 /* CCID Tx finished */ #define EV_TX_FINISHED 4 /* CCID Tx finished */
#define EV_CARD_CHANGE 8 #define EV_CARD_CHANGE 8
#define EV_USB_INTERFACE 16 #define EV_USB_SET_INTERFACE 16
#define EV_USB_RESET 32 #define EV_USB_DEVICE_RESET 32
/* OpenPGPcard thread */ /* OpenPGPcard thread */
#define EV_PINPAD_INPUT_DONE 1 #define EV_PINPAD_INPUT_DONE 1

View File

@@ -1356,10 +1356,31 @@ ccid_card_change_signal (int how)
} }
void void
ccid_usb_reset (int all) ccid_usb_reset (int full)
{ {
struct ccid *c = &ccid; struct ccid *c = &ccid;
eventflag_signal (&c->ccid_comm, all?EV_USB_RESET:EV_USB_INTERFACE);
eventflag_signal (&c->ccid_comm,
full ? EV_USB_DEVICE_RESET : EV_USB_SET_INTERFACE);
}
#define NOTIFY_SLOT_CHANGE 0x50
static void
ccid_notify_slot_change (struct ccid *c)
{
uint8_t msg;
uint8_t notification[2];
if (c->ccid_state == CCID_STATE_NOCARD)
msg = 0x02;
else
msg = 0x03;
notification[0] = NOTIFY_SLOT_CHANGE;
notification[1] = msg;
usb_lld_write (ENDP2, notification, sizeof notification);
led_blink (LED_TWOSHOTS);
} }
@@ -1367,7 +1388,6 @@ ccid_usb_reset (int all)
#define GPG_THREAD_TERMINATED 0xffff #define GPG_THREAD_TERMINATED 0xffff
#define NOTIFY_SLOT_CHANGE 0x50
#define INTR_REQ_USB 20 #define INTR_REQ_USB 20
@@ -1394,7 +1414,7 @@ ccid_thread (void *arg)
chopstx_claim_irq (&interrupt, INTR_REQ_USB); chopstx_claim_irq (&interrupt, INTR_REQ_USB);
usb_interrupt_handler (); /* For old SYS < 3.0 */ usb_interrupt_handler (); /* For old SYS < 3.0 */
reset: device_reset:
epi_init (epi, ENDP1, notify_tx, c); epi_init (epi, ENDP1, notify_tx, c);
epo_init (epo, ENDP1, notify_icc, c); epo_init (epo, ENDP1, notify_icc, c);
apdu_init (a); apdu_init (a);
@@ -1413,9 +1433,10 @@ ccid_thread (void *arg)
/* Ignore event while not-configured. */ /* Ignore event while not-configured. */
} }
interface: interface_reset:
timeout = USB_CCID_TIMEOUT; timeout = USB_CCID_TIMEOUT;
ccid_prepare_receive (c); ccid_prepare_receive (c);
ccid_notify_slot_change (c);
while (1) while (1)
{ {
eventflag_prepare_poll (&c->ccid_comm, &poll_desc); eventflag_prepare_poll (&c->ccid_comm, &poll_desc);
@@ -1429,7 +1450,7 @@ ccid_thread (void *arg)
timeout = USB_CCID_TIMEOUT; timeout = USB_CCID_TIMEOUT;
m = eventflag_get (&c->ccid_comm); m = eventflag_get (&c->ccid_comm);
if (m == EV_USB_RESET) if (m == EV_USB_DEVICE_RESET)
{ {
if (c->application) if (c->application)
{ {
@@ -1437,23 +1458,18 @@ ccid_thread (void *arg)
chopstx_join (c->application, NULL); chopstx_join (c->application, NULL);
c->application = 0; c->application = 0;
} }
goto reset; goto device_reset;
} }
else if (m == EV_USB_INTERFACE) else if (m == EV_USB_SET_INTERFACE)
/* Upon receivable of SET_INTERFACE, we reset endpoint to RX_NAK. /* Upon receival of SET_INTERFACE, the endpoint is reset to RX_NAK.
* Thus, we need to prepare receive again. * Thus, we need to prepare receive again.
*/ */
goto interface; goto interface_reset;
else if (m == EV_CARD_CHANGE) else if (m == EV_CARD_CHANGE)
{ {
uint8_t int_msg[2];
int_msg[0] = NOTIFY_SLOT_CHANGE;
if (c->ccid_state == CCID_STATE_NOCARD) if (c->ccid_state == CCID_STATE_NOCARD)
{ /* Inserted! */ /* Inserted! */
c->ccid_state = CCID_STATE_START; c->ccid_state = CCID_STATE_START;
int_msg[1] = 0x03;
}
else else
{ /* Removed! */ { /* Removed! */
if (c->application) if (c->application)
@@ -1464,11 +1480,9 @@ ccid_thread (void *arg)
} }
c->ccid_state = CCID_STATE_NOCARD; c->ccid_state = CCID_STATE_NOCARD;
int_msg[1] = 0x02;
} }
usb_lld_write (ENDP2, int_msg, sizeof int_msg); ccid_notify_slot_change (c);
led_blink (LED_TWOSHOTS);
} }
else if (m == EV_RX_DATA_READY) else if (m == EV_RX_DATA_READY)
c->ccid_state = ccid_handle_data (c); c->ccid_state = ccid_handle_data (c);