1

My application is working properly in all aspects apart from when I wish to remove contactless card 'A', and replace it with contactless card 'B'.

Once card B is present, I run the following PCSC functions:

    lResult = PCSC.SCardDisconnect(hCard, SCARD_RESET_CARD)
    lResult = PCSC.SCardReleaseContext(hContext)
    lMode = SCARD_SHARE_EXCLUSIVE
    lProtocol = SCARD_PROTOCOL_T0

    lResult = PCSC.SCardEstablishContext(SCARD_SCOPE_USER, 0, 0, hContext)

    If lMode = SCARD_SHARE_DIRECT Then
        lResult = PCSC.SCardConnect(hContext, ConnReaderName, lMode, 0, hCard, lActiveProtocol)
    Else
        lResult = PCSC.SCardConnect(hContext, ConnReaderName, lMode, lProtocol, hCard, lActiveProtocol)
    End If

Despite this code disconnecting, releasing context, re-establishing context and reconnecting to the card, I seem to get an 8010000f Protocol Mismatch error. Both cards are T=0. After much testing I have discovered that the only thing which actually works is to wait for about 10 seconds of no activity after introducing contactless card B to the field, whereupon the reader's activity light flashes again, seemingly resetting the card and allowing the transaction to go ahead as normal.

Why does this happen? And is there a way that I can force that eventual reset sooner?

I did separate out the ScardDisconnect and ScardReleaseContext commands, performing them whilst Contactless Card A was still in the field, but it made no difference.

John W
  • 73
  • 4
  • 1
    Which reader do you use? The problem is, that you are only addressing PCSC and the problem is, when the reader switches of its field or disconnects from the card (one layer below); the coupling is subject to interpretation of the manufacturer. (So the cheapest advice: try a reader from another manufacturer). Note, that T=0 is a contact protocol; you are likely to use ISO 14443 instead: Type A or B? – guidot Sep 26 '15 at 10:08
  • Thanks - I use an Omnikey 5321.It still shows contactless cards as T=0 or T=1 - so is probably some internal driver fudge I guess. Now that I understand that it is a reader 'feature', and that I can wait 10 seconds or so before a new contactless card will work, then it is bearable, and nowhere near as annoying. – John W Oct 05 '15 at 23:46

1 Answers1

0

Here is a possible solution:

establish a new connect in direct mode, followed by a reconnect in shared/exclusive mode, forcing a card reset or card unpower

ret = SCardConnect(hContext, readername, lMode, SCARD_PROTOCOL_T0, &hCard, &dwActiveProtocol);
if (ret == SCARD_E_PROTO_MISMATCH) {
    ret = SCardConnect(hContext, readername, SCARD_SHARE_DIRECT, 0, &hCard, &dwActiveProtocol);
    if (!ret) ret = SCardReconnect(hCard, lMode, SCARD_PROTOCOL_T0, SCARD_RESET_CARD, &dwActiveProtocol);
}
bilbo
  • 111
  • 1
  • 3