mirror of
git://git.gnupg.org/gnupg.git
synced 2025-01-20 14:37:08 +01:00
scd: ccid-driver: Initial getting ATR more robustly.
* scd/ccid-driver.c (send_power_off): New. (do_close_reader): Use send_power_off. (ccid_get_atr): Add error recovery. GnuPG-bug-id: 4616 Signed-off-by: NIIBE Yutaka <gniibe@fsij.org>
This commit is contained in:
parent
39c40e572c
commit
c51a568555
@ -1717,31 +1717,37 @@ ccid_require_get_status (ccid_driver_t handle)
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int
|
||||||
static void
|
send_power_off (ccid_driver_t handle)
|
||||||
do_close_reader (ccid_driver_t handle)
|
|
||||||
{
|
{
|
||||||
int rc;
|
int rc;
|
||||||
unsigned char msg[100];
|
unsigned char msg[100];
|
||||||
size_t msglen;
|
size_t msglen;
|
||||||
unsigned char seqno;
|
unsigned char seqno;
|
||||||
|
|
||||||
if (!handle->powered_off)
|
msg[0] = PC_to_RDR_IccPowerOff;
|
||||||
{
|
msg[5] = 0; /* slot */
|
||||||
msg[0] = PC_to_RDR_IccPowerOff;
|
msg[6] = seqno = handle->seqno++;
|
||||||
msg[5] = 0; /* slot */
|
msg[7] = 0; /* RFU */
|
||||||
msg[6] = seqno = handle->seqno++;
|
msg[8] = 0; /* RFU */
|
||||||
msg[7] = 0; /* RFU */
|
msg[9] = 0; /* RFU */
|
||||||
msg[8] = 0; /* RFU */
|
set_msg_len (msg, 0);
|
||||||
msg[9] = 0; /* RFU */
|
msglen = 10;
|
||||||
set_msg_len (msg, 0);
|
|
||||||
msglen = 10;
|
|
||||||
|
|
||||||
rc = bulk_out (handle, msg, msglen, 0);
|
rc = bulk_out (handle, msg, msglen, 0);
|
||||||
if (!rc)
|
if (!rc)
|
||||||
bulk_in (handle, msg, sizeof msg, &msglen, RDR_to_PC_SlotStatus,
|
bulk_in (handle, msg, sizeof msg, &msglen, RDR_to_PC_SlotStatus,
|
||||||
seqno, 2000, 0);
|
seqno, 2000, 0);
|
||||||
}
|
return rc;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
do_close_reader (ccid_driver_t handle)
|
||||||
|
{
|
||||||
|
int rc;
|
||||||
|
|
||||||
|
if (!handle->powered_off)
|
||||||
|
send_power_off (handle);
|
||||||
|
|
||||||
if (handle->transfer)
|
if (handle->transfer)
|
||||||
{
|
{
|
||||||
@ -2597,6 +2603,21 @@ ccid_get_atr (ccid_driver_t handle,
|
|||||||
NULL, 0, NULL))
|
NULL, 0, NULL))
|
||||||
goto again;
|
goto again;
|
||||||
}
|
}
|
||||||
|
else if (statusbits == 0 && CCID_COMMAND_FAILED (msg))
|
||||||
|
{
|
||||||
|
/* Card was active already, and something went wrong with
|
||||||
|
PC_to_RDR_IccPowerOn command. It may be baud-rate mismatch
|
||||||
|
between the card and the reader. To recover from this state,
|
||||||
|
send PC_to_RDR_IccPowerOff command to reset the card and try
|
||||||
|
again.
|
||||||
|
*/
|
||||||
|
rc = send_power_off (handle);
|
||||||
|
if (rc)
|
||||||
|
return rc;
|
||||||
|
|
||||||
|
statusbits = 1;
|
||||||
|
goto again;
|
||||||
|
}
|
||||||
else if (CCID_COMMAND_FAILED (msg))
|
else if (CCID_COMMAND_FAILED (msg))
|
||||||
return CCID_DRIVER_ERR_CARD_IO_ERROR;
|
return CCID_DRIVER_ERR_CARD_IO_ERROR;
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user