[Pcsclite-git-commit] [PCSC] 09/10: SCardDisconnect(): much faster SCARD_UNPOWER_CARD

Ludovic Rousseau rousseau at moszumanska.debian.org
Fri Aug 5 15:48:06 UTC 2016


This is an automated email from the git hooks/post-receive script.

rousseau pushed a commit to branch master
in repository PCSC.

commit b25f2d5a3822b9eed4f64f3052e54230af292af2
Author: Ludovic Rousseau <ludovic.rousseau at free.fr>
Date:   Fri Aug 5 16:23:20 2016 +0200

    SCardDisconnect(): much faster SCARD_UNPOWER_CARD
    
    When SCardDisconnect() is used with SCARD_UNPOWER_CARD we just power
    down the card and do not power it up again.
    
    The idea is to be faster and gain some milliseconds.
    The code to power up the card on demand was already present since 2010
    with the card auto power on and off mechanism.
    
    Before the change: SCardDisconnect(SCARD_UNPOWER_CARD) in 61 ms
    After the change: SCardDisconnect(SCARD_UNPOWER_CARD) in 1.4 ms
    
    Improvement factor (for the card used) = 61/1.4 = x44
    
    If you use a card that is slower to power up then the gain is even higher.
    
    Thanks to Christophe Ferrando from Sylyca for the patch.
---
 src/winscard.c | 22 +---------------------
 1 file changed, 1 insertion(+), 21 deletions(-)

diff --git a/src/winscard.c b/src/winscard.c
index dbee705..d133d5b 100644
--- a/src/winscard.c
+++ b/src/winscard.c
@@ -887,34 +887,24 @@ LONG SCardDisconnect(SCARDHANDLE hCard, DWORD dwDisposition)
 		 */
 		(void)RFSetReaderEventState(rContext, SCARD_RESET);
 
-		/*
-		 * Currently pcsc-lite keeps the card powered constantly
-		 * unless DISABLE_AUTO_POWER_ON is defined
-		 */
 		dwAtrLen = sizeof(rContext->readerState->cardAtr);
 		if (SCARD_RESET_CARD == dwDisposition)
 			rv = IFDPowerICC(rContext, IFD_RESET,
 				rContext->readerState->cardAtr, &dwAtrLen);
 		else
 		{
+			/* SCARD_UNPOWER_CARD */
 			IFDPowerICC(rContext, IFD_POWER_DOWN, NULL, NULL);
 
-#ifdef DISABLE_AUTO_POWER_ON
 			rContext->powerState = POWER_STATE_UNPOWERED;
 			Log1(PCSC_LOG_DEBUG, "powerState: POWER_STATE_UNPOWERED");
-#else
-			rv = IFDPowerICC(rContext, IFD_POWER_UP,
-				rContext->readerState->cardAtr, &dwAtrLen);
-#endif
 		}
 
 		/* the protocol is unset after a power on */
 		rContext->readerState->cardProtocol = SCARD_PROTOCOL_UNDEFINED;
 
-#ifdef DISABLE_AUTO_POWER_ON
 		if (SCARD_UNPOWER_CARD == dwDisposition)
 		{
-			rContext->readerState->cardAtrLength = 0;
 			if (rv == SCARD_S_SUCCESS)
 				rContext->readerState->readerState = SCARD_PRESENT;
 			else
@@ -927,10 +917,8 @@ LONG SCardDisconnect(SCARDHANDLE hCard, DWORD dwDisposition)
 					rContext->readerState->readerState =
 						SCARD_PRESENT | SCARD_SWALLOWED;
 			}
-			Log1(PCSC_LOG_INFO, "Skip card power on");
 		}
 		else
-#endif
 		{
 			/*
 			 * Set up the status bit masks on readerState
@@ -1032,16 +1020,8 @@ LONG SCardDisconnect(SCARDHANDLE hCard, DWORD dwDisposition)
 		 * powered */
 		if (POWER_STATE_POWERED <= rContext->powerState)
 		{
-#ifdef DISABLE_AUTO_POWER_ON
-			if (SCARD_RESET_CARD == dwDisposition)
-			{
-				rContext->powerState = POWER_STATE_GRACE_PERIOD;
-				Log1(PCSC_LOG_DEBUG, "powerState: POWER_STATE_GRACE_PERIOD");
-			}
-#else
 			rContext->powerState = POWER_STATE_GRACE_PERIOD;
 			Log1(PCSC_LOG_DEBUG, "powerState: POWER_STATE_GRACE_PERIOD");
-#endif
 		}
 
 		(void)pthread_mutex_unlock(&rContext->powerState_lock);

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pcsclite/PCSC.git



More information about the Pcsclite-cvs-commit mailing list