[Pcsclite-cvs-commit] r1684 - trunk/PCSC/src
Ludovic Rousseau
rousseau at costa.debian.org
Wed Oct 12 13:09:03 UTC 2005
Author: rousseau
Date: 2005-10-12 13:09:02 +0000 (Wed, 12 Oct 2005)
New Revision: 1684
Modified:
trunk/PCSC/src/winscard_scf.c
Log:
EventCallback() & PCSC_SCF_Initialize(): Fix issue where
SCardGetStatusChange() returns incorrect status when it is called right
after SCardEstablishContext() the first time after the libpcsclite.so is
loaded in memory, the fix is to make PCSC_Initialize() wait till OCF has
been initialized and the internal states are consistent.
Thanks to Najam Siddiqui for the patch
Modified: trunk/PCSC/src/winscard_scf.c
===================================================================
--- trunk/PCSC/src/winscard_scf.c 2005-10-12 13:06:24 UTC (rev 1683)
+++ trunk/PCSC/src/winscard_scf.c 2005-10-12 13:09:02 UTC (rev 1684)
@@ -23,6 +23,7 @@
#include <unistd.h>
#include <sys/un.h>
#include <smartcard/scf.h>
+#include <time.h>
#include "pcsclite.h"
#include "winscard.h"
@@ -94,6 +95,8 @@
* so to get lock on the clientMutex may affect the performance of the ocf server.
*/
static PCSCLITE_MUTEX EventMutex = PTHREAD_MUTEX_INITIALIZER;
+static PCSCLITE_MUTEX SCFInitMutex = PTHREAD_MUTEX_INITIALIZER;
+static pthread_cond_t EventCondition = PTHREAD_COND_INITIALIZER;
static char PCSC_Initialized = 0;
static LONG isOCFServerRunning(void);
@@ -1603,6 +1606,7 @@
static void EventCallback(SCF_Event_t eventType, SCF_Terminal_t hTerm,
void *cbdata)
{
+ static char bInitialized = 0;
int i = 0;
int ReaderIndice = 0;
SCF_Card_t hCard;
@@ -1690,6 +1694,23 @@
default:
break;
} /* switch */
+ /*
+ * The OCF Server always calls the registered callback function
+ * immediately after the callback function is registered,
+ * but always with the state of SCF_EVENT_CARDABSENT even if
+ * there is a card present in the reader, the OCF server then
+ * calls the callback the second time with the correct state,
+ * that is the reason for the check if (bInitialized == 2).
+ * If there is no card present in the reader the PCSC_SCF_Initialize's
+ * pthread_cond_timedwait times out after 2 secs.
+ */
+ if (bInitialized < 2)
+ {
+ bInitialized++;
+ if (2 == bInitialized)
+ pthread_cond_signal(&EventCondition);
+ }
+
SCardEventUnlock();
}
@@ -1777,6 +1798,23 @@
}
}
SCF_Session_freeInfo(g_hSession, tList);
+
+ SYS_MutexLock(&SCFInitMutex);
+ /* wait for ocfserver to initialize... or 2 secs whichever is earlier */
+ {
+ struct timeval currTime;
+ struct timespec absTime;
+
+ gettimeofday(&currTime, NULL);
+
+ /* Calculate absolute time to time out */
+ absTime.tv_sec = currTime.tv_sec + 2;
+ absTime.tv_nsec = currTime.tv_usec*1000;
+
+ pthread_cond_timedwait(&EventCondition, &SCFInitMutex, &absTime);
+ }
+ SYS_MutexUnLock(&SCFInitMutex);
+
PCSC_SCF_Initialized = 1;
return SCARD_S_SUCCESS;
}
More information about the Pcsclite-cvs-commit
mailing list