[Pcsclite-cvs-commit] CVS PCSC/src
CVS User rousseau
ludovic.rousseau@free.fr
Mon, 28 Feb 2005 01:42:30 -0700
Update of /cvsroot/pcsclite/PCSC/src
In directory haydn:/tmp/cvs-serv15966/src
Modified Files:
winscard_scf.c
Log Message:
code reindentation
--- /cvsroot/pcsclite/PCSC/src/winscard_scf.c 2005/02/28 08:40:50 1.17
+++ /cvsroot/pcsclite/PCSC/src/winscard_scf.c 2005/02/28 08:42:29 1.18
@@ -7,7 +7,7 @@
* David Corcoran <corcoran@linuxnet.com>
* Najam Siddiqui
*
- * $Id: winscard_scf.c,v 1.17 2005/02/28 08:40:50 rousseau Exp $
+ * $Id: winscard_scf.c,v 1.18 2005/02/28 08:42:29 rousseau Exp $
*/
#include "config.h"
@@ -36,45 +36,49 @@
#define PCSCLITE_MAX_READERS_CONTEXTS 2
/* Global session to manage Readers, Card events. */
-static SCF_Session_t g_hSession = NULL;
+static SCF_Session_t g_hSession = NULL;
/* Have to define this because they are defined in pcsclite.h as externs */
SCARD_IO_REQUEST g_rgSCardT0Pci, g_rgSCardT1Pci, g_rgSCardRawPci;
-static struct _psTransmitMap {
- BYTE Buffer[266];
- int isResponseCached;
- LONG bufferLength;
+static struct _psTransmitMap
+{
+ BYTE Buffer[266];
+ int isResponseCached;
+ LONG bufferLength;
} psTransmitMap[PCSCLITE_MAX_APPLICATION_CONTEXTS];
/* Channel Map to manage Card Connections. */
-static struct _psChannelMap {
- SCARDHANDLE PCSC_hCard;
- SCARDCONTEXT hContext;
- SCF_Session_t hSession;
- SCF_Terminal_t hTerminal;
- SCF_Card_t SCF_hCard;
- short haveLock;
- short isReset;
- int ReaderIndice;
+static struct _psChannelMap
+{
+ SCARDHANDLE PCSC_hCard;
+ SCARDCONTEXT hContext;
+ SCF_Session_t hSession;
+ SCF_Terminal_t hTerminal;
+ SCF_Card_t SCF_hCard;
+ short haveLock;
+ short isReset;
+ int ReaderIndice;
} psChannelMap[PCSCLITE_MAX_APPLICATION_CONTEXTS];
/* Context Map to manage contexts and sessions. */
-static struct _psContextMap {
- SCARDCONTEXT hContext;
- SCF_Session_t hSession;
- DWORD contextBlockStatus;
+static struct _psContextMap
+{
+ SCARDCONTEXT hContext;
+ SCF_Session_t hSession;
+ DWORD contextBlockStatus;
} psContextMap[PCSCLITE_MAX_APPLICATION_CONTEXTS];
/* Reader Map to handle Status and GetStatusChange. */
-static struct _psReaderMap {
- SCF_Terminal_t hTerminal;
- LPTSTR ReaderName;
- short SharedRefCount;
- DWORD dwCurrentState;
- BYTE bAtr[MAX_ATR_SIZE];
- DWORD dwAtrLength;
- SCF_ListenerHandle_t lHandle;
+static struct _psReaderMap
+{
+ SCF_Terminal_t hTerminal;
+ LPTSTR ReaderName;
+ short SharedRefCount;
+ DWORD dwCurrentState;
+ BYTE bAtr[MAX_ATR_SIZE];
+ DWORD dwAtrLength;
+ SCF_ListenerHandle_t lHandle;
} psReaderMap[PCSCLITE_MAX_READERS_CONTEXTS];
static PCSCLITE_MUTEX clientMutex = PTHREAD_MUTEX_INITIALIZER;
@@ -93,1238 +97,1413 @@
LONG SCardEventUnlock(void);
static LONG PCSC_SCF_Initialize(void);
static void EventCallback(SCF_Event_t eventType, SCF_Terminal_t hTerm,
- void * cbdata);
-static LONG PCSC_SCF_getATR(SCF_Card_t hCard, LPBYTE pcbAtr,
- LPDWORD pcbAtrLen);
+ void *cbdata);
+static LONG PCSC_SCF_getATR(SCF_Card_t hCard, LPBYTE pcbAtr,
+ LPDWORD pcbAtrLen);
static LONG ConvertStatus(SCF_Status_t status);
static LONG SCardGetReaderIndice(LPCTSTR ReaderName);
-static LONG getNewContext(SCARDCONTEXT *phContext);
-static LONG SCardAddContext(SCARDCONTEXT hContext,SCF_Session_t hSession );
-static SCF_Session_t getSessionForContext(SCARDCONTEXT hContext );
-static LONG SCardRemoveContext ( SCARDCONTEXT hContext );
-static LONG SCardGetContextIndice ( SCARDCONTEXT hContext );
-
-static LONG getNewHandle(SCARDCONTEXT hContext,LPCTSTR szReader,
- SCARDHANDLE *phCard, DWORD);
-static LONG getCardForHandle(SCARDHANDLE PSCS_hCard, SCF_Card_t *SCF_hCard);
+static LONG getNewContext(SCARDCONTEXT * phContext);
+static LONG SCardAddContext(SCARDCONTEXT hContext, SCF_Session_t hSession);
+static SCF_Session_t getSessionForContext(SCARDCONTEXT hContext);
+static LONG SCardRemoveContext(SCARDCONTEXT hContext);
+static LONG SCardGetContextIndice(SCARDCONTEXT hContext);
+
+static LONG getNewHandle(SCARDCONTEXT hContext, LPCTSTR szReader,
+ SCARDHANDLE * phCard, DWORD);
+static LONG getCardForHandle(SCARDHANDLE PSCS_hCard, SCF_Card_t * SCF_hCard);
static LONG SCardRemoveHandle(SCARDHANDLE hCard);
static LONG SCardAddHandle(SCARDHANDLE PCSC_hCard, SCARDCONTEXT hContext,
- SCF_Session_t hSession, SCF_Terminal_t hTerminal,
- SCF_Card_t SCF_hCard, int , DWORD);
+ SCF_Session_t hSession, SCF_Terminal_t hTerminal,
+ SCF_Card_t SCF_hCard, int, DWORD);
static LONG SCardGetHandleIndice(SCARDHANDLE hCard);
-static LONG SCardEstablishContextTH( DWORD dwScope, LPCVOID pvReserved1,
- LPCVOID pvReserved2,
- LPSCARDCONTEXT phContext) {
- LONG rv = 0;
-
-
- if(SCARD_S_SUCCESS != isOCFServerRunning())
- return SCARD_E_NO_SERVICE;
-
- rv = PCSC_SCF_Initialize();
-
- if(SCARD_S_SUCCESS != rv)
- return rv;
-
- if (NULL == phContext) {
- return SCARD_E_INVALID_PARAMETER;
- } else {
- *phContext = 0;
- }
-
- if ( dwScope != SCARD_SCOPE_USER && dwScope != SCARD_SCOPE_TERMINAL &&
- dwScope != SCARD_SCOPE_SYSTEM && dwScope != SCARD_SCOPE_GLOBAL ) {
-
- *phContext = 0;
- return SCARD_E_INVALID_VALUE;
- }
- rv = getNewContext(phContext);
- return rv;
-
-}
-
-LONG SCardEstablishContext( DWORD dwScope, LPCVOID pvReserved1,
- LPCVOID pvReserved2, LPSCARDCONTEXT phContext) {
- long rv;
-
- SCardLockThread();
- rv = SCardEstablishContextTH( dwScope, pvReserved1,
- pvReserved2, phContext);
- SCardUnlockThread();
-
-
- return rv;
-
-}
-
-static LONG SCardReleaseContextTH( SCARDCONTEXT hContext ) {
-
- LONG rv;
- /* Zero out everything */
-
- if(SCARD_S_SUCCESS != isOCFServerRunning())
- return SCARD_E_NO_SERVICE;
-
- rv = 0;
-
- /* Remove the local context from the stack */
- rv = SCardRemoveContext( hContext );
-
- return rv;
-}
-
-LONG SCardReleaseContext( SCARDCONTEXT hContext ) {
- long rv;
-
- SCardLockThread();
- rv = SCardReleaseContextTH( hContext );
- SCardUnlockThread();
-
- return rv;
-}
-
-
-static LONG SCardListReadersTH( SCARDCONTEXT hContext, LPCTSTR mszGroups,
- LPTSTR mszReaders, LPDWORD pcchReaders ) {
- static int first_time = 1;
- int i=0;
- static DWORD dwReadersLen=0;
- LONG retIndice = 0;
- char *tempPtr;
-
- if(SCARD_S_SUCCESS != isOCFServerRunning())
- return SCARD_E_NO_SERVICE;
-
+static LONG SCardEstablishContextTH(DWORD dwScope, LPCVOID pvReserved1,
+ LPCVOID pvReserved2, LPSCARDCONTEXT phContext)
+{
+ LONG rv = 0;
+
+
+ if (SCARD_S_SUCCESS != isOCFServerRunning())
+ return SCARD_E_NO_SERVICE;
+
+ rv = PCSC_SCF_Initialize();
+
+ if (SCARD_S_SUCCESS != rv)
+ return rv;
+
+ if (NULL == phContext)
+ {
+ return SCARD_E_INVALID_PARAMETER;
+ }
+ else
+ {
+ *phContext = 0;
+ }
+
+ if (dwScope != SCARD_SCOPE_USER && dwScope != SCARD_SCOPE_TERMINAL &&
+ dwScope != SCARD_SCOPE_SYSTEM && dwScope != SCARD_SCOPE_GLOBAL)
+ {
+
+ *phContext = 0;
+ return SCARD_E_INVALID_VALUE;
+ }
+ rv = getNewContext(phContext);
+ return rv;
+
+}
+
+LONG SCardEstablishContext(DWORD dwScope, LPCVOID pvReserved1,
+ LPCVOID pvReserved2, LPSCARDCONTEXT phContext)
+{
+ long rv;
+
+ SCardLockThread();
+ rv = SCardEstablishContextTH(dwScope, pvReserved1,
+ pvReserved2, phContext);
+ SCardUnlockThread();
+
+
+ return rv;
+
+}
+
+static LONG SCardReleaseContextTH(SCARDCONTEXT hContext)
+{
+
+ LONG rv;
+ /* Zero out everything */
+
+ if (SCARD_S_SUCCESS != isOCFServerRunning())
+ return SCARD_E_NO_SERVICE;
+
+ rv = 0;
+
+ /* Remove the local context from the stack */
+ rv = SCardRemoveContext(hContext);
+
+ return rv;
+}
+
+LONG SCardReleaseContext(SCARDCONTEXT hContext)
+{
+ long rv;
+
+ SCardLockThread();
+ rv = SCardReleaseContextTH(hContext);
+ SCardUnlockThread();
+
+ return rv;
+}
+
+
+static LONG SCardListReadersTH(SCARDCONTEXT hContext, LPCTSTR mszGroups,
+ LPTSTR mszReaders, LPDWORD pcchReaders)
+{
+ static int first_time = 1;
+ int i = 0;
+ static DWORD dwReadersLen = 0;
+ LONG retIndice = 0;
+ char *tempPtr;
+
+ if (SCARD_S_SUCCESS != isOCFServerRunning())
+ return SCARD_E_NO_SERVICE;
+
/* Check for NULL parameters */
- if ( pcchReaders == 0 ) {
- return SCARD_E_INVALID_PARAMETER;
- }
- /*Check for Context validity*/
- retIndice = SCardGetContextIndice(hContext);
- if(0> retIndice)
- return SCARD_E_INVALID_HANDLE;
-
- /*Calculate the the buffer length reuired only once.
- */
- if(first_time) {
- for(i=0;i<PCSCLITE_MAX_READERS_CONTEXTS;i++) {
- if(NULL != psReaderMap[i].ReaderName)
- dwReadersLen += strlen(psReaderMap[i].ReaderName) +1;
- }
- dwReadersLen++;
- first_time = 0;
- }
- /*There are no readers available*/
- if(1 >= dwReadersLen)
- return SCARD_E_READER_UNAVAILABLE;
-
-
- if ( mszReaders == 0 ) {
- *pcchReaders = dwReadersLen;
- return SCARD_S_SUCCESS;
- } else if ( *pcchReaders == 0 ) {
- *pcchReaders = dwReadersLen;
- return SCARD_S_SUCCESS;
- } else if ( *pcchReaders < dwReadersLen ) {
- *pcchReaders = dwReadersLen;
- return SCARD_E_INSUFFICIENT_BUFFER;
- }
-
- tempPtr = mszReaders;
- for(i=0;i<PCSCLITE_MAX_READERS_CONTEXTS;i++) {
- if(NULL != psReaderMap[i].ReaderName) {
- memcpy(tempPtr, psReaderMap[i].ReaderName,
- strlen(psReaderMap[i].ReaderName)+1);
- tempPtr += (strlen(psReaderMap[i].ReaderName) + 1);
- }
- }
- /*the extra NULL character as per the PCSC specs.*/
- tempPtr[0] = '\0';
- *pcchReaders = dwReadersLen;
-
- return SCARD_S_SUCCESS;
+ if (pcchReaders == 0)
+ {
+ return SCARD_E_INVALID_PARAMETER;
+ }
+ /*Check for Context validity */
+ retIndice = SCardGetContextIndice(hContext);
+ if (0 > retIndice)
+ return SCARD_E_INVALID_HANDLE;
+
+ /*Calculate the the buffer length reuired only once.
+ */
+ if (first_time)
+ {
+ for (i = 0; i < PCSCLITE_MAX_READERS_CONTEXTS; i++)
+ {
+ if (NULL != psReaderMap[i].ReaderName)
+ dwReadersLen += strlen(psReaderMap[i].ReaderName) + 1;
+ }
+ dwReadersLen++;
+ first_time = 0;
+ }
+ /*There are no readers available */
+ if (1 >= dwReadersLen)
+ return SCARD_E_READER_UNAVAILABLE;
+
+
+ if (mszReaders == 0)
+ {
+ *pcchReaders = dwReadersLen;
+ return SCARD_S_SUCCESS;
+ }
+ else if (*pcchReaders == 0)
+ {
+ *pcchReaders = dwReadersLen;
+ return SCARD_S_SUCCESS;
+ }
+ else if (*pcchReaders < dwReadersLen)
+ {
+ *pcchReaders = dwReadersLen;
+ return SCARD_E_INSUFFICIENT_BUFFER;
+ }
+
+ tempPtr = mszReaders;
+ for (i = 0; i < PCSCLITE_MAX_READERS_CONTEXTS; i++)
+ {
+ if (NULL != psReaderMap[i].ReaderName)
+ {
+ memcpy(tempPtr, psReaderMap[i].ReaderName,
+ strlen(psReaderMap[i].ReaderName) + 1);
+ tempPtr += (strlen(psReaderMap[i].ReaderName) + 1);
+ }
[3028 lines skipped]