Skip to content

Commit

Permalink
RFAddReader: more correctly detect duplicate readers
Browse files Browse the repository at this point in the history
To detect a duplicate reader, checking the reader name and port is,
sometimes, not enough.

The problem was when two readers are removed and re-inserted immediately.
One of the 2 readers may not yet be completely removed (from pcscd point
of view) when it is asked to insert it again.

Fixes #20
"Reader not detected when disconnecting / connecting usb hub"
#20
  • Loading branch information
LudovicRousseau committed Jun 12, 2017
1 parent 251771a commit 88a53f3
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions src/readerfactory.c
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ LONG RFAddReader(const char *readerNameLong, int port, const char *library,
readerName[MAX_READERNAME - sizeof(" 00 00")] = '\0';
}

/* Same name, same port - duplicate reader cannot be used */
/* Same name, same port, same device - duplicate reader cannot be used */
if (dwNumReadersContexts != 0)
{
for (i = 0; i < PCSCLITE_MAX_READERS_CONTEXTS; i++)
Expand All @@ -240,8 +240,9 @@ LONG RFAddReader(const char *readerNameLong, int port, const char *library,
tmplen = strlen(lpcStripReader);
lpcStripReader[tmplen - 6] = 0;

if ((strcmp(readerName, lpcStripReader) == 0) &&
(port == sReadersContexts[i]->port))
if ((strcmp(readerName, lpcStripReader) == 0)
&& (port == sReadersContexts[i]->port)
&& (strcmp(device, sReadersContexts[i]->device) == 0))
{
Log1(PCSC_LOG_ERROR, "Duplicate reader found.");
return SCARD_E_DUPLICATE_READER;
Expand Down

0 comments on commit 88a53f3

Please sign in to comment.