[Pcsclite-muscle] question about locking and reconnect

Ricardo Martin rickyepoderi
Tue Jun 2 02:55:40 PDT 2015


Hi again,
In my little understanding the idea behind SCardReconnect is that it is just a SCardDisconnect + SCardConnect. And, because SCardDisconnect releases any lock, SCardReconnect should also do the same. If you want to lock you need to start the transaction again just like after a normal SCardConnect (in shared mode of course).
Regards!

      From: Ludovic Rousseau <ludovic.rousseau at gmail.com>
 To: Ricardo Martin <rickyepoderi at yahoo.es>; Talks about MUSCLE <pcsclite-muscle at lists.alioth.debian.org> 
 Sent: Tuesday, June 2, 2015 11:43 AM
 Subject: Re: [Pcsclite-muscle] question about locking and reconnect
   
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

_______________________________________________
Pcsclite-muscle mailing list
Pcsclite-muscle at lists.alioth.debian.org
http://lists.alioth.debian.org/cgi-bin/mailman/listinfo/pcsclite-muscle


  
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.alioth.debian.org/pipermail/pcsclite-muscle/attachments/20150602/8f80675f/attachment.html>



More information about the pcsclite-muscle mailing list