libopensc: fix reopen SM after reader reconnect
After card reset detected, run SM open under new transaction Before trying to reestablish SM session or onte code that may need to use a transaction, get the transaction that will be used by the caller od sc_lock. closes #837
This commit is contained in:
parent
1bc09ddafa
commit
1e82dbe5c7
|
@ -388,6 +388,7 @@ int sc_reset(sc_card_t *card, int do_cold_reset)
|
||||||
int sc_lock(sc_card_t *card)
|
int sc_lock(sc_card_t *card)
|
||||||
{
|
{
|
||||||
int r = 0, r2 = 0;
|
int r = 0, r2 = 0;
|
||||||
|
int was_reset = 0;
|
||||||
|
|
||||||
if (card == NULL)
|
if (card == NULL)
|
||||||
return SC_ERROR_INVALID_ARGUMENTS;
|
return SC_ERROR_INVALID_ARGUMENTS;
|
||||||
|
@ -400,14 +401,12 @@ int sc_lock(sc_card_t *card)
|
||||||
if (card->lock_count == 0) {
|
if (card->lock_count == 0) {
|
||||||
if (card->reader->ops->lock != NULL) {
|
if (card->reader->ops->lock != NULL) {
|
||||||
r = card->reader->ops->lock(card->reader);
|
r = card->reader->ops->lock(card->reader);
|
||||||
if (r == SC_ERROR_CARD_RESET || r == SC_ERROR_READER_REATTACHED) {
|
while (r == SC_ERROR_CARD_RESET || r == SC_ERROR_READER_REATTACHED) {
|
||||||
/* invalidate cache */
|
/* invalidate cache */
|
||||||
memset(&card->cache, 0, sizeof(card->cache));
|
memset(&card->cache, 0, sizeof(card->cache));
|
||||||
card->cache.valid = 0;
|
card->cache.valid = 0;
|
||||||
#ifdef ENABLE_SM
|
if (was_reset++ > 4) /* TODO retry a few times */
|
||||||
if (card->sm_ctx.ops.open)
|
break;
|
||||||
card->sm_ctx.ops.open(card);
|
|
||||||
#endif
|
|
||||||
r = card->reader->ops->lock(card->reader);
|
r = card->reader->ops->lock(card->reader);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -416,13 +415,21 @@ int sc_lock(sc_card_t *card)
|
||||||
}
|
}
|
||||||
if (r == 0)
|
if (r == 0)
|
||||||
card->lock_count++;
|
card->lock_count++;
|
||||||
|
|
||||||
|
if (r == 0 && was_reset > 0) {
|
||||||
|
#ifdef ENABLE_SM
|
||||||
|
if (card->sm_ctx.ops.open)
|
||||||
|
card->sm_ctx.ops.open(card);
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
r2 = sc_mutex_unlock(card->ctx, card->mutex);
|
r2 = sc_mutex_unlock(card->ctx, card->mutex);
|
||||||
if (r2 != SC_SUCCESS) {
|
if (r2 != SC_SUCCESS) {
|
||||||
sc_log(card->ctx, "unable to release lock");
|
sc_log(card->ctx, "unable to release card->mutex lock");
|
||||||
r = r != SC_SUCCESS ? r : r2;
|
r = r != SC_SUCCESS ? r : r2;
|
||||||
}
|
}
|
||||||
|
|
||||||
return r;
|
LOG_FUNC_RETURN(card->ctx, r);
|
||||||
}
|
}
|
||||||
|
|
||||||
int sc_unlock(sc_card_t *card)
|
int sc_unlock(sc_card_t *card)
|
||||||
|
|
Loading…
Reference in New Issue