[Pcsclite-cvs-commit] Drivers/ccid/src ifdhandler.c,1.2,1.3

rousseau@quantz.debian.org rousseau@quantz.debian.org
Mon, 22 Sep 2003 16:25:21 +0200


Update of /cvsroot/pcsclite/Drivers/ccid/src
In directory quantz:/tmp/cvs-serv19306/src

Modified Files:
	ifdhandler.c 
Log Message:
add support of thread safe (APDU multiplexing on different readers)


Index: ifdhandler.c
===================================================================
RCS file: /cvsroot/pcsclite/Drivers/ccid/src/ifdhandler.c,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -d -r1.2 -r1.3
--- ifdhandler.c	10 Sep 2003 09:12:20 -0000	1.2
+++ ifdhandler.c	22 Sep 2003 14:25:19 -0000	1.3
@@ -19,9 +19,6 @@
 
 #include <stdio.h>
 #include <string.h>
-#ifdef HAVE_PTHREAD_H
-#include <pthread.h>
-#endif
 
 #include "pcscdefines.h"
 #include "ifdhandler.h"
@@ -31,9 +28,18 @@
 #include "utils.h"
 #include "commands.h"
 
+#ifdef HAVE_PTHREAD_H
+#include <pthread.h>
+#endif
+
 /* Array of structures to hold the ATR and other state value of each slot */
 static CcidDesc CcidSlots[PCSCLITE_MAX_READERS];
 
+/* global mutex */
+#ifdef HAVE_PTHREAD_H
+static pthread_mutex_t ifdh_context_mutex = PTHREAD_MUTEX_INITIALIZER;
+#endif
+
 
 RESPONSECODE IFDHCreateChannel(DWORD Lun, DWORD Channel)
 {
@@ -84,12 +90,20 @@
 	/* Reset PowerFlags */
 	CcidSlots[LunToReaderIndex(Lun)].bPowerFlags = POWERFLAGS_RAZ;
 
+#ifdef HAVE_PTHREAD_H
+	pthread_mutex_lock(&ifdh_context_mutex);
+#endif
+
 	if (OpenPort(Lun, Channel) != STATUS_SUCCESS)
 	{
 		DEBUG_CRITICAL("OpenReader failed");
 		return_value = IFD_COMMUNICATION_ERROR;
 	}
 
+#ifdef HAVE_PTHREAD_H
+	pthread_mutex_unlock(&ifdh_context_mutex);
+#endif
+
 	return return_value;
 } /* IFDHCreateChannel */
 
@@ -115,8 +129,16 @@
 	CmdPowerOff(Lun);
 	/* No reader status check, if it failed, what can you do ? :) */
 
+#ifdef HAVE_PTHREAD_H
+	pthread_mutex_lock(&ifdh_context_mutex);
+#endif
+
 	ClosePort(Lun);
 
+#ifdef HAVE_PTHREAD_H
+	pthread_mutex_unlock(&ifdh_context_mutex);
+#endif
+
 	return IFD_SUCCESS;
 } /* IFDHCloseChannel */
 
@@ -142,7 +164,7 @@
 	 * IFD_SUCCESS IFD_ERROR_TAG
 	 */
 
-	DEBUG_INFO2("entering IFDHGetCapabilities (lun: %X)", Lun);
+	DEBUG_INFO3("entering IFDHGetCapabilities (lun: %X) tag: %02X", Lun, Tag);
 
 	if (CheckLun(Lun))
 		return IFD_COMMUNICATION_ERROR;
@@ -168,6 +190,14 @@
 			{
 				*Length = 1;
 				*Value = PCSCLITE_MAX_READERS;
+			}
+			break;
+
+		case TAG_IFD_THREAD_SAFE:
+			if (*Length >= 1)
+			{
+				*Length = 1;
+				*Value = 1; /* Can talk to multiple readers at the same time */
 			}
 			break;