- changed pcsc_detect_card_presence to call refresh_slot_attributes. This

eliminates duplicate code, and that we also pick up the new ATR if another
  card was inserted in the meanwhil.


git-svn-id: https://www.opensc-project.org/svnp/opensc/trunk@758 c6295689-39f2-0310-b995-f0e70906c6a9
This commit is contained in:
okir 2002-12-06 21:40:41 +00:00
parent 868d1d7a20
commit 6217b4adf5
1 changed files with 13 additions and 24 deletions

View File

@ -179,28 +179,6 @@ static int pcsc_transmit(struct sc_reader *reader, struct sc_slot_info *slot,
return 0;
}
static int pcsc_detect_card_presence(struct sc_reader *reader, struct sc_slot_info *slot)
{
struct pcsc_private_data *priv = GET_PRIV_DATA(reader);
LONG ret;
SCARD_READERSTATE_A rgReaderStates[SC_MAX_READERS];
rgReaderStates[0].szReader = priv->reader_name;
rgReaderStates[0].dwCurrentState = SCARD_STATE_UNAWARE;
rgReaderStates[0].dwEventState = SCARD_STATE_UNAWARE;
ret = SCardGetStatusChange(priv->pcsc_ctx, SC_STATUS_TIMEOUT, rgReaderStates, 1);
if (ret != 0) {
PCSC_ERROR(reader->ctx, "SCardGetStatusChange failed", ret);
SC_FUNC_RETURN(reader->ctx, 1, pcsc_ret_to_error(ret));
}
if (rgReaderStates[0].dwEventState & SCARD_STATE_PRESENT) {
slot->flags |= SC_SLOT_CARD_PRESENT;
return 1;
}
slot->flags &= ~SC_SLOT_CARD_PRESENT;
return 0;
}
static int refresh_slot_attributes(struct sc_reader *reader, struct sc_slot_info *slot)
{
struct pcsc_private_data *priv = GET_PRIV_DATA(reader);
@ -215,18 +193,28 @@ static int refresh_slot_attributes(struct sc_reader *reader, struct sc_slot_info
PCSC_ERROR(reader->ctx, "SCardGetStatusChange failed", ret);
return pcsc_ret_to_error(ret);
}
slot->flags = 0;
if (rgReaderStates[0].dwEventState & SCARD_STATE_PRESENT) {
slot->flags = SC_SLOT_CARD_PRESENT;
slot->flags |= SC_SLOT_CARD_PRESENT;
slot->atr_len = rgReaderStates[0].cbAtr;
if (slot->atr_len > SC_MAX_ATR_SIZE)
slot->atr_len = SC_MAX_ATR_SIZE;
memcpy(slot->atr, rgReaderStates[0].rgbAtr, slot->atr_len);
} else {
slot->flags &= ~SC_SLOT_CARD_PRESENT;
}
return 0;
}
static int pcsc_detect_card_presence(struct sc_reader *reader, struct sc_slot_info *slot)
{
int rv;
if ((rv = refresh_slot_attributes(reader, slot)) < 0)
return rv;
return (slot->flags & SC_SLOT_CARD_PRESENT)? 1 : 0;
}
static int pcsc_connect(struct sc_reader *reader, struct sc_slot_info *slot)
{
DWORD active_proto;
@ -366,6 +354,7 @@ static int pcsc_init(struct sc_context *ctx, void **reader_data)
free(priv);
break;
}
memset(reader, 0, sizeof(*reader));
reader->drv_data = priv;
reader->ops = &pcsc_ops;
reader->driver = &pcsc_drv;