LudovicRousseau / pcsc-tools

Some tools to be used with smart cards and PC/SC
https://pcsc-tools.apdu.fr/
GNU General Public License v2.0
190 stars 62 forks source link

pcsc_scan.exe finds readers but fails to present prompt #34

Closed digitalentropy closed 4 years ago

digitalentropy commented 4 years ago

I am observing an issue with pcsc_scan.exe detecting my readers and then looping over and over rather than presenting a prompt to select reader and action.

The issue is observed when compiling from scratch and also when using the pre-compiled Windows binary.

I've uploaded a log of the output I am observing in both scenarios.

log.txt

Any thoughts on possible causes?

LudovicRousseau commented 4 years ago

Why do you expect a prompt to select a reader?

I agree the continuous loop is a bug somewhere.

digitalentropy commented 4 years ago

I was expecting it only because of what the screenshots looked like. It appeared that the system would list readers and then ask the user to select a reader to interrogate.

Apologies if that assumption is incorrect.

LudovicRousseau commented 4 years ago

I can't reproduce the problem on my Windows 10. Please apply this patch, rebuild and try again.

diff --git a/pcsc_scan.c b/pcsc_scan.c
index e054624..6e6b29c 100644
--- a/pcsc_scan.c
+++ b/pcsc_scan.c
@@ -630,6 +630,7 @@ get_readers:
    {
        time_t t;

+       printf("rv: 0x%08X\n", rv);
        if (pnp)
        {
 #ifdef WIN32
digitalentropy commented 4 years ago

Current output is as follows:

Scanning present readers...
0: Alcor Micro USB Smart Card Reader 0
1: JAVACOS Virtual Contact Reader 0
2: JAVACOS Virtual Contactless Reader 1
rv: 0x00000000

It still loops over and over, regardless of card state.

LudovicRousseau commented 4 years ago

OK. Try again with this new patch:

diff --git a/pcsc_scan.c b/pcsc_scan.c
index e054624..f231e14 100644
--- a/pcsc_scan.c
+++ b/pcsc_scan.c
@@ -635,6 +635,7 @@ get_readers:
 #ifdef WIN32
            /* check if the number of readers has changed */
            LONG newNbReaders = rgReaderStates_t[nbReaders-1].dwEventState >> 16;
+           printf("nbReaders: %d, .dwEventState: 0x%08X\n", nbReaders, rgReaderStates_t[nbReaders-1].dwEventState);
            if (newNbReaders + 1 != nbReaders)
 #else
            if (rgReaderStates_t[nbReaders-1].dwEventState &
digitalentropy commented 4 years ago

New looping message:

Scanning present readers...
0: Alcor Micro USB Smart Card Reader 0
1: JAVACOS Virtual Contact Reader 0
2: JAVACOS Virtual Contactless Reader 1
nbReaders: 4, .dwEventState: 0x00040002
LudovicRousseau commented 4 years ago

What version of Windows do you use? What is the output of pcsc_scan if you unplug one reader, for example the Alcor Micro USB reader?

digitalentropy commented 4 years ago

Windows 10 (Current)

I can check exact version number when I get back.

digitalentropy commented 4 years ago

Microsoft Windows [Version 10.0.18363.657]

LudovicRousseau commented 4 years ago

Try the version available at http://ludovic.rousseau.free.fr/softwares/pcsc-tools/pcsc_scan.c

LudovicRousseau commented 4 years ago

Fixed in https://github.com/LudovicRousseau/pcsc-tools/commit/1727dbf217f22b6e32ad5c066989f542f6233da9

LudovicRousseau commented 4 years ago

See also https://ludovicrousseau.blogspot.com/2020/03/better-pcscscan-on-windows.html