Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SCardConnect returns SCARD_E_PROTO_MISMATCH if SCARD_PROTOCOL_RAW was used in previous connection #49

Closed
godfreychung opened this issue Nov 12, 2018 · 4 comments

Comments

@godfreychung
Copy link

I found a problem when using SCardConnect with SCARD_PROTOCOL_RAW. It always returns SCARD_E_PROTO_MISMATCH if SCARD_PROTOCOL_RAW was used in previous connection.

Please insert a card before running testraw.
After running testraw, it will generate the following output:

Establishing the context...
Getting reader names...
Reader 0: ACS ACR 38U-CCID 00 00
Select reader: 0
Connecting to the reader (shared, T=0 or T=1)...
Disconnecting the reader...
Connecting to the reader (direct, raw)...
Disconnecting the reader...
Connecting to the reader (shared, T=0 or T=1)...
Error: SCardConnect failed with error 0x8010000F
Connecting to the reader (shared, T=0 or T=1)...
Error: SCardConnect failed with error 0x8010000F
Connecting to the reader (shared, T=0 or T=1)...
Error: SCardConnect failed with error 0x8010000F
Connecting to the reader (shared, T=0 or T=1)...
Error: SCardConnect failed with error 0x8010000F
Connecting to the reader (shared, T=0 or T=1)...
Error: SCardConnect failed with error 0x8010000F
Connecting to the reader (shared, T=0 or T=1)...
Error: SCardConnect failed with error 0x8010000F
Connecting to the reader (shared, T=0 or T=1)...
Error: SCardConnect failed with error 0x8010000F
Connecting to the reader (shared, T=0 or T=1)...
Error: SCardConnect failed with error 0x8010000F
Connecting to the reader (shared, T=0 or T=1)...
Error: SCardConnect failed with error 0x8010000F
Connecting to the reader (shared, T=0 or T=1)...
Error: SCardConnect failed with error 0x8010000F
Releasing the context...

Here is the test code (testraw.c.txt).
Here is the log from pcscd (log.txt).

@LudovicRousseau
Copy link
Owner

I don't think it is a bug in pcsclite.
Your program works fine if you use:

    err = SCardDisconnect(hCard, SCARD_RESET_CARD);

instead of:

    err = SCardDisconnect(hCard, SCARD_LEAVE_CARD);

You can't (re)connect using a different protocol without powering off or reseting the card first.

Have you tried your program on Windows?
What is the result?

@godfreychung
Copy link
Author

Here is the result on Windows:

Establishing the context...
Getting reader names...
Reader 0: ACS CCID USB Reader 0
Select reader: 0
Connecting to the reader (shared, T=0 or T=1)...
Disconnecting the reader...
Connecting to the reader (direct, raw)...
Error: SCardConnect failed with error 0x000006F9
Connecting to the reader (shared, T=0 or T=1)...
Disconnecting the reader...
Releasing the context...

It seems that Windows does not support raw protocol.
I modified testraw2.c.txt for testing.

@LudovicRousseau
Copy link
Owner

Another test you can make on Windows is to use a card with support of both T=0 and T=1.
First you connect with T=0, disconnect, then connect with T=1.
It should fail the same way as with pcsclite.

@godfreychung
Copy link
Author

Yes, I can reproduce the result on Windows.
It's clear now. Thanks!

Conni2461 added a commit to Conni2461/libfreefare-pcsc that referenced this issue Mar 8, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants