[Pcsclite-cvs-commit] r3178 - in /trunk/PCSC/src: ifdwrapper.c winscard.c

rousseau at users.alioth.debian.org rousseau at users.alioth.debian.org
Thu Oct 23 15:34:16 UTC 2008


Author: rousseau
Date: Thu Oct 23 15:34:16 2008
New Revision: 3178

URL: http://svn.debian.org/wsvn/pcsclite/?sc=1&rev=3178
Log:
move locking from IFDSetPTS() to 2 levels above in SCardConnect() and
SCardReconnect(). The  value of rContext->readerState->cardProtocol is
then checked and modified in an atomic transaction

This avoids to renegociate the protocol and confuse the card if two
applications perform a SCardConnect() at the same time (after they are
both blocked by SCardGetStatusChange() and a card is inserted for example)

Error returned by CCID driver is: CCID_Receive Procedure byte conflict

Modified:
    trunk/PCSC/src/ifdwrapper.c
    trunk/PCSC/src/winscard.c

Modified: trunk/PCSC/src/ifdwrapper.c
URL: http://svn.debian.org/wsvn/pcsclite/trunk/PCSC/src/ifdwrapper.c?rev=3178&op=diff
==============================================================================
--- trunk/PCSC/src/ifdwrapper.c (original)
+++ trunk/PCSC/src/ifdwrapper.c Thu Oct 23 15:34:16 2008
@@ -65,9 +65,11 @@
 #endif
 
 	/*
-	 * LOCK THIS CODE REGION
-	 */
-	SYS_MutexLock(rContext->mMutex);
+	 * Locking is done in winscard.c SCardConnect() and SCardReconnect()
+	 *
+	 * This avoids to renegociate the protocol and confuse the card
+	 * Error returned by CCID driver is: CCID_Receive Procedure byte conflict
+	 */
 
 	ucValue[0] = rContext->dwSlot;
 
@@ -100,11 +102,6 @@
 			ucFlags, ucPTS1, ucPTS2, ucPTS3);
 	}
 #endif
-
-	SYS_MutexUnLock(rContext->mMutex);
-	/*
-	 * END OF LOCKED REGION
-	 */
 
 	return rv;
 }

Modified: trunk/PCSC/src/winscard.c
URL: http://svn.debian.org/wsvn/pcsclite/trunk/PCSC/src/winscard.c?rev=3178&op=diff
==============================================================================
--- trunk/PCSC/src/winscard.c (original)
+++ trunk/PCSC/src/winscard.c Thu Oct 23 15:34:16 2008
@@ -377,6 +377,10 @@
 	{
 		if (dwShareMode != SCARD_SHARE_DIRECT)
 		{
+			/* lock here instead in IFDSetPTS() to lock up to
+			 * setting rContext->readerState->cardProtocol */
+			SYS_MutexLock(rContext->mMutex);
+
 			/* the protocol is not yet set (no PPS yet) */
 			if (SCARD_PROTOCOL_UNDEFINED == rContext->readerState->cardProtocol)
 			{
@@ -400,16 +404,26 @@
 
 				/* keep cardProtocol = SCARD_PROTOCOL_UNDEFINED in case of error  */
 				if (SET_PROTOCOL_PPS_FAILED == ret)
+				{
+					SYS_MutexUnLock(rContext->mMutex);
 					return SCARD_W_UNRESPONSIVE_CARD;
+				}
 
 				if (SET_PROTOCOL_WRONG_ARGUMENT == ret)
+				{
+					SYS_MutexUnLock(rContext->mMutex);
 					return SCARD_E_PROTO_MISMATCH;
+				}
 
 				/* use negociated protocol */
 				rContext->readerState->cardProtocol = ret;
+
+				SYS_MutexUnLock(rContext->mMutex);
 			}
 			else
 			{
+				SYS_MutexUnLock(rContext->mMutex);
+
 				if (! (dwPreferredProtocols & rContext->readerState->cardProtocol))
 					return SCARD_E_PROTO_MISMATCH;
 			}
@@ -693,6 +707,10 @@
 	{
 		if (dwShareMode != SCARD_SHARE_DIRECT)
 		{
+			/* lock here instead in IFDSetPTS() to lock up to
+			 * setting rContext->readerState->cardProtocol */
+			SYS_MutexLock(rContext->mMutex);
+
 			/* the protocol is not yet set (no PPS yet) */
 			if (SCARD_PROTOCOL_UNDEFINED == rContext->readerState->cardProtocol)
 			{
@@ -714,16 +732,26 @@
 
 				/* keep cardProtocol = SCARD_PROTOCOL_UNDEFINED in case of error  */
 				if (SET_PROTOCOL_PPS_FAILED == ret)
+				{
+					SYS_MutexUnLock(rContext->mMutex);
 					return SCARD_W_UNRESPONSIVE_CARD;
+				}
 
 				if (SET_PROTOCOL_WRONG_ARGUMENT == ret)
+				{
+					SYS_MutexUnLock(rContext->mMutex);
 					return SCARD_E_PROTO_MISMATCH;
+				}
 
 				/* use negociated protocol */
 				rContext->readerState->cardProtocol = ret;
+
+				SYS_MutexUnLock(rContext->mMutex);
 			}
 			else
 			{
+				SYS_MutexUnLock(rContext->mMutex);
+
 				if (! (dwPreferredProtocols & rContext->readerState->cardProtocol))
 					return SCARD_E_PROTO_MISMATCH;
 			}




More information about the Pcsclite-cvs-commit mailing list