[Pcsclite-muscle] question about locking and reconnect
Ludovic Rousseau
ludovic.rousseau
Mon Jun 1 05:52:13 PDT 2015
2015-06-01 13:57 GMT+02:00 Ricardo Martin <rickyepoderi at yahoo.es>:
> Hi everybody,
Hello,
> Playing with opensc and the dnie driver I found a weird behavior. After some
> tests I opened the following issue in opensc github:
>
> https://github.com/OpenSC/OpenSC/issues/475
>
> It seems that opensc in the method sc_reset finally sends a SCardReconnect
> with SCARD_UNPOWER_CARD or SCARD_RESET_CARD (depending the do_cold_reset
> parameter). But at the end of the sc_reset function opensc performs the
> following:
>
> /* pcsc_reconnect unlocks card... try to lock it again if it was
> locked */
> if(old_locked)
> r = pcsc_lock(reader);
>
> If the connection was previously locked, after the reconnect, it adds a lock
> again (SCardBeginTransaction is called again inside pcsc_lock). My
> impression is that this extra call adds one more lock in the pcsc
> (rContext->LockCount) which is never released, and this ends in the complete
> lock of the card until the current process finishes (no other process can
> access the card in shared mode). Every call to pcsc_reset in opensc seems to
> add a lost lock in pcsc (and the dnie driver calls to this reset).
>
> I have done some little test with pcsc (with the little sample.c copied
> below) and it seems that SCardReconnect does not lose the locks (in any
> case: SCARD_SHARE_SHARED or SCARD_SHARE_EXCLUSIVE, SCARD_UNPOWER_CARD or
> SCARD_RESET_CARD). But, just to be sure, can anybody confirm that
> SCardReconnect maintains the locks (transactions)? Is the extra call done in
> opensc to SCardBeginTransaction needed?
It looks like you are right.
I checked the source code of pcsc-lite and SCardReconnect() does not
release or take a lock. It only checks if a lock (from another PC/SC
context) is not yet present.
To know if this is a bug or not in pcsc-lite we should know how it
works on Windows.
I could not find any reference to transactions or locks in MSDN
documentation [1].
Can you do some tests on Windows and tell us how SCardReconnect()
behaves on Windows?
Thanks
[1] https://msdn.microsoft.com/en-us/library/windows/desktop/aa379797%28v=vs.85%29.aspx
--
Dr. Ludovic Rousseau
More information about the pcsclite-muscle
mailing list