[Pcsclite-muscle] question about locking and reconnect

Ludovic Rousseau ludovic.rousseau
Tue Jun 2 02:43:46 PDT 2015


2015-06-01 22:56 GMT+02:00 Ricardo Martin <rickyepoderi at yahoo.es>:
> Hi Ludovic,

Hello,

> I have tested a similar sample.c (attached) in a windows vista (sorry, it's
> the only windows I have) with Windows SDK 6.1 and it is clear that the
> SCardRconnect clears the connections.  Compilation and output is presented
> below:
>
> C:\Users\ricky\Desktop>cl sample.c Winscard.lib
> Microsoft (R) 32-bit C/C++ Optimizing Compiler Version 15.00.21022.08 for
> 80x86
> Copyright (C) Microsoft Corporation.  All rights reserved.
>
> sample.c
> Microsoft (R) Incremental Linker Version 9.00.21022.08
> Copyright (C) Microsoft Corporation.  All rights reserved.
>
> /out:sample.exe
> sample.obj
> Winscard.lib
>
> C:\Users\ricky\Desktop>sample.exe
> reader name: Gemplus USB SmartCard Reader 0
> response: 86 CC 40 80 7A 68 C9 90 00
> response: 86 CC 40 80 7A 68 C9 90 00
> SCardEndTransaction: 0x80100016 (0x80100016)
>
> So the SCardEndTransaction returns SCARD_E_NOT_TRANSACTED after the
> reconnect. Besides the documentation says the following:
>
> "The application must immediately call the SCardDisconnect, SCardReconnect,
> or SCardReleaseContext function to avoid an existing transaction blocking
> other threads and processes from communicating with the smart card."
>
> See here:
> https://msdn.microsoft.com/es-es/library/windows/desktop/aa379477%28v=vs.85%29.aspx

That is surprising.
If you use a transaction it is because you want to have an exclusive
access to the card.
You may want to reset the card using a SCardReconnect() and continue
using it with an exclusive access.

Under Windows you would loose the exclusive access to the card
(SCardReconnect() releases the transaction). Another program could
start a new transaction before you can acquire an exclusive access
again using a new transaction.
With pcsc-lite you do not have this race problem.

One solution under Windows would be to use
SCardReconnect(SCARD_SHARE_EXCLUSIVE) instead of transactions.

Bye

-- 
 Dr. Ludovic Rousseau




More information about the pcsclite-muscle mailing list