forked from nat/aimeio-pcsc
aimepcsc: poll: return no_card on bad card reads
This commit is contained in:
parent
0fe3a5a471
commit
358e4633ae
@ -125,7 +125,7 @@ int aimepcsc_poll(struct aimepcsc_context *ctx, struct aime_data *data) {
|
|||||||
DWORD cByte = SCARD_AUTOALLOCATE;
|
DWORD cByte = SCARD_AUTOALLOCATE;
|
||||||
int retval;
|
int retval;
|
||||||
|
|
||||||
retval = 0;
|
retval = 1;
|
||||||
|
|
||||||
memset(&rs, 0, sizeof(SCARD_READERSTATE));
|
memset(&rs, 0, sizeof(SCARD_READERSTATE));
|
||||||
|
|
||||||
@ -171,36 +171,41 @@ int aimepcsc_poll(struct aimepcsc_context *ctx, struct aime_data *data) {
|
|||||||
|
|
||||||
if (cByte != 20) {
|
if (cByte != 20) {
|
||||||
snprintf(ctx->last_error, sizeof(ctx->last_error), "invalid ATR length: %lu", cByte);
|
snprintf(ctx->last_error, sizeof(ctx->last_error), "invalid ATR length: %lu", cByte);
|
||||||
retval = 1;
|
|
||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* check ATR */
|
/* check ATR */
|
||||||
if (memcmp(pbAttr, atr_ios14443_common, sizeof(atr_ios14443_common)) != 0) {
|
if (memcmp(pbAttr, atr_ios14443_common, sizeof(atr_ios14443_common)) != 0) {
|
||||||
snprintf(ctx->last_error, sizeof(ctx->last_error), "invalid card type.");
|
snprintf(ctx->last_error, sizeof(ctx->last_error), "invalid card type.");
|
||||||
retval = 1;
|
|
||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* check card type */
|
/* check card type */
|
||||||
if (memcmp(pbAttr + sizeof(atr_ios14443_common), cardtype_m1k, sizeof(cardtype_m1k)) == 0) {
|
if (memcmp(pbAttr + sizeof(atr_ios14443_common), cardtype_m1k, sizeof(cardtype_m1k)) == 0) {
|
||||||
data->card_type = Mifare;
|
data->card_type = Mifare;
|
||||||
if (read_m1k_aime(ctx, &hCard, data) < 0) {
|
ret = read_m1k_aime(ctx, &hCard, data);
|
||||||
|
if (ret < 0) {
|
||||||
retval = -1;
|
retval = -1;
|
||||||
goto out;
|
goto out;
|
||||||
|
} else if (ret > 0) {
|
||||||
|
goto out;
|
||||||
}
|
}
|
||||||
} else if (memcmp(pbAttr + sizeof(atr_ios14443_common), cardtype_felica, sizeof(cardtype_felica)) == 0) {
|
} else if (memcmp(pbAttr + sizeof(atr_ios14443_common), cardtype_felica, sizeof(cardtype_felica)) == 0) {
|
||||||
data->card_type = FeliCa;
|
data->card_type = FeliCa;
|
||||||
if (read_felica_aime(ctx, &hCard, data) < 0) {
|
ret = read_felica_aime(ctx, &hCard, data);
|
||||||
|
if (ret < 0) {
|
||||||
retval = -1;
|
retval = -1;
|
||||||
goto out;
|
goto out;
|
||||||
|
} else if (ret > 0) {
|
||||||
|
goto out;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
snprintf(ctx->last_error, sizeof(ctx->last_error), "invalid card type.");
|
snprintf(ctx->last_error, sizeof(ctx->last_error), "invalid card type.");
|
||||||
retval = 1;
|
|
||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
retval = 0;
|
||||||
|
|
||||||
out:
|
out:
|
||||||
SCardFreeMemory(ctx->hContext, pbAttr);
|
SCardFreeMemory(ctx->hContext, pbAttr);
|
||||||
SCardDisconnect(hCard, SCARD_LEAVE_CARD);
|
SCardDisconnect(hCard, SCARD_LEAVE_CARD);
|
||||||
|
Loading…
Reference in New Issue
Block a user