[Pcsclite-muscle] Unable to detect SCardGetStatusChange() after write

Maximilian Stein maximilian.stein at secunet.com
Wed Jun 7 01:50:19 PDT 2023


Hi Allen,

Am 07.06.2023 um 05:57 schrieb Allen Curtis:
> Both threads have their own context:
> SCARDCONTEXT context = 0; ///< context for this thread
> rv = SCardEstablishContext(SCARD_SCOPE_SYSTEM, NULL, NULL, &context);

That's good, since this is a common pitfall ;-)


> Both threads release the card context immediately after accessing it.
>          SCardDisconnect(handle, SCARD_RESET_CARD); // SCARD_RESET_CARD);
>          SCardReleaseContext(context);

Why would the monitoring thread release the context each time after it 
received a status change? Imo it can keep the same context as long as 
the thread is running.


> As long as the tag is not written to, SCardGetStatusChange() reliably detects the reader/card state changes. After the write, state changes are no longer detected.
> 
>          bool is_tag_present = (m_ntag->reader_state.dwCurrentState & SCARD_STATE_PRESENT);

I wonder how it currently detects card movement correctly. You would 
have to use `reader_state.dwEventState` to check for card movement since 
the `dwCurrentState` (as in your example) will not change by calling 
`SCardGetStatusChange()`. You would have to check `dwEventState`, maybe 
compare it to `dwCurrentState` and then do `dwCurrentState = dwEventState`.


Cheers Maxi



More information about the pcsclite-muscle mailing list