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

Allen Curtis allen at criticalsoftwaresolutions.com
Fri Jun 9 12:41:46 PDT 2023


Below.



> 
> 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.

That was the original implementation. Grasping

> 
> 
>> 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`.
> 
> 

This is the rest of that code. It does detect the state change before the write operation.

// called with the previous status value
rv = SCardGetStatusChange(context, INFINITE, &m_ntag->reader_state, 1);
if (rv != SCARD_S_SUCCESS) {
printf("SCardGetStatusChange: %s (0x%lX)\n", pcsc_stringify_error(rv), rv);
continue;
}

// No longer detect change. Just inspect the SCARD_STATE_PRESENT bit

m_ntag->reader_state.dwCurrentState = m_ntag->reader_state.dwEventState;
bool is_tag_present = (m_ntag->reader_state.dwCurrentState & SCARD_STATE_PRESENT);

I forgot, in the task that writes, it uses start/stop transaction instead of connect.

int tag_write_data(void* data, unsigned offset, unsigned length)
{
LONG rv = SCARD_S_SUCCESS;

if ((rv = start_transaction()) == SCARD_S_SUCCESS) {

if ((rv = authenticate(WR_KEY_NUM)) != SCARD_S_SUCCESS) {
SCARD_ERR_MSG("authenticate", rv);
} else if ((rv = _tag_write_data(data, offset, length)) != SCARD_S_SUCCESS) {
SCARD_ERR_MSG("_tag_write_data", rv);
}

if ((rv = end_transaction()) != SCARD_S_SUCCESS) {
SCARD_ERR_MSG("end_transaction", rv);
}
} else {
SCARD_ERR_MSG("start_transaction", rv);
}
}


> Cheers Maxi
> 
> _______________________________________________
> pcsclite-muscle mailing list
> pcsclite-muscle at lists.infradead.org
> http://lists.infradead.org/mailman/listinfo/pcsclite-muscle




More information about the pcsclite-muscle mailing list