locked
WinSCard.dll Api unexpected behaviour/issue on Win7/Vista RRS feed

  • Question

  • We have observed an unexpected change in behaviour with the WinSCard.dll API on windows7/vista.

    we poll in a loop SCardGetStatusChange method to detect when a smartcard is inserted or removed (by monitoring the m_dwEventState of each card reader for the CHANGED, PRESENT and EMPTY flags)

    when a card insert is detected we connect to the card using the SCardConnect method, and perform whatever operations we need to do on the card. when a card removal is detected we call SCardDisconnect method.

    this all works as expected on XP, however on windows7/vista when the SCardDisconnect method is called after the card has been removed we observe an unexpected CARD_STATE.PRESENT followed CARD_STATE.EMPTY event returned from the SCardGetStatusChange method.

    in summary the following steps occur:

    1) we insert the card -> SCardGetStatusChange reports an event with CARD_STATE.PRESENT flag set

    2) we connect to the card using SCardConnect

    3) the card is removed -> SCardGetStatusChange reports an event with CARD_STATE.EMPTY flag set

    4) we release our connction to the card api by calling SCardDisconnect

    on XP nothing else happens, however on win7/Vista:
     
    5) SCardGetStatusChange reports an event with CARD_STATE.PRESENT flag set

    6) SCardGetStatusChange reports an event with CARD_STATE.EMPTY flag set

    i.e. on windows 7 /vista we appear to see another card insert/removal when in reality nothing has happened. note these unexpected events also appear to have the CARD_STATE.MUTE flag set, the MUTE flag is not set in the observed events in steps 1 and 3.


    Also notable is that this issue does not occur if Windows 7 is running in a remote desktop session and receiving smartcard input from a host pc running XP. I.e. the issue only occurs when the operating system reading the smartcard is Windows7/Vista.


    We have an example project available that illustrates the behaviour if necessary.
    Wednesday, December 9, 2009 4:10 PM

Answers

  • As part of a fix to ensure that it worked on 64 bit machines i checked the pinvoke signatures and discovered that they had been based on a very old example of calling Winscard.dll that appears to have been incorrect (i can only assume we all used this bad example or a variation!)

    since correcting them I have no longer seen the above reported problem

     
    • Marked as answer by Richard_Bowker Tuesday, October 23, 2012 9:16 AM
    Tuesday, October 23, 2012 9:16 AM

All replies

  • Hi Richard,

    Did you get any more information on this?

    I am facing a similar problem just on Windows 7 64 bit?

    Thanks in advance.

    Santosh.
    Wednesday, February 17, 2010 9:34 AM
  • I unfortunately have not had any feedback on this yet (apart from yours!)

    I'll try and raise it somewhere else and let you know.

    for the time being I am just filtering out the events with the mute flag set. (any idea what this flag means in practice?)

    cheers

    Rich
    Tuesday, February 23, 2010 4:19 PM
  • Hi all,
    I am currently facing the same issue under Windows 7 (tested under 32-bits only)
    I do not understand what is the expected behavior, but, filtering the SCARD_STATE_MUTE flag may be the only solution.

    Regards,
    Tytou
    Monday, March 1, 2010 4:24 PM
  • Hi all,

    Has anybody had any satisfactory answer on the above question/observation?  I have experienced exactly the same problem on Windows 7 32 bit.  Filtering the SCARD_STATE_MUTE flag is not an option for me.  Do anyone know how we can escalate this problem, i.e. get official feedback from Microsoft on this issue.

    Regards,

    Leon

    Monday, June 28, 2010 6:33 AM
  • Guys that's not the only problem with Windows 7, I encountered once that the SCardListReaders blocked my call on windows 7 ?! It happens sometimes occasionally but I can't reproduce it .. I can debug and see that the call to SCardListReaders is blocking .. !!!
    Monday, August 30, 2010 10:02 AM
  • The idea is to do not take into account an event of "card insertion" if the card status is mute (but only in the case explained in first post). Thus, you application will not see the card as inserted if the card is mute.

    under Win7:

    while card is removed from the reader, you disconnect form it using SCardDisconnect. here, an event is set (to tell that the card is no more in the reader: SCARD_STATE_EMPTY) and your application will catch it through its blocking call to SCardGetStatusChange.

    Under Win7, another event is raised from PC/SC. This event sets the SCARD_STATE_PRESENT and SCARD_STATE_MUTE flags, if your application ignores this event, then it acts as if it ignores this 'ghost' card insertion. Then your application will catch the next event which is SCARD_STATE_EMPTY.

    hope this helps.

     

    LeonVD: why do you think that ignoring SCARD_STATE_MUTE flag in this circumstances (and only) is not the good workaround ? (for sure, this is not a solution!)

    Friday, September 10, 2010 7:05 AM
  • As part of a fix to ensure that it worked on 64 bit machines i checked the pinvoke signatures and discovered that they had been based on a very old example of calling Winscard.dll that appears to have been incorrect (i can only assume we all used this bad example or a variation!)

    since correcting them I have no longer seen the above reported problem

     
    • Marked as answer by Richard_Bowker Tuesday, October 23, 2012 9:16 AM
    Tuesday, October 23, 2012 9:16 AM