Skip to content

Commit

Permalink
Implement PCSC_READER_ANY for pcsc_wait_for_card()
Browse files Browse the repository at this point in the history
59a21f3 documented the use of
PCSC_READER_ANY but never implemented it.
  • Loading branch information
leonlynch committed Apr 17, 2024
1 parent 489cac2 commit 8e11043
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
8 changes: 6 additions & 2 deletions src/pcsc.c
Original file line number Diff line number Diff line change
Expand Up @@ -610,14 +610,18 @@ int pcsc_wait_for_card(pcsc_ctx_t ctx, unsigned long timeout_ms, size_t* idx)
struct pcsc_t* pcsc;
LONG result;

if (!ctx) {
if (!ctx || !idx) {
return -1;
}
pcsc = ctx;

// Prepare reader states for card detection
for (size_t i = 0; i < pcsc->reader_count; ++i) {
pcsc->reader_states[i].dwCurrentState = SCARD_STATE_EMPTY;
if (*idx == PCSC_READER_ANY || *idx == i) {
pcsc->reader_states[i].dwCurrentState = SCARD_STATE_EMPTY;
} else {
pcsc->reader_states[i].dwCurrentState = SCARD_STATE_IGNORE;
}
}

// Wait for empty state to change
Expand Down
1 change: 1 addition & 0 deletions tools/emv-tool.c
Original file line number Diff line number Diff line change
Expand Up @@ -718,6 +718,7 @@ int main(int argc, char** argv)

// Wait for card presentation
printf("\nPresent card\n");
reader_idx = PCSC_READER_ANY;
r = pcsc_wait_for_card(pcsc, 5000, &reader_idx);
if (r < 0) {
printf("PC/SC error\n");
Expand Down

0 comments on commit 8e11043

Please sign in to comment.