[Pcsclite-cvs-commit] r2635 - /trunk/PCSC/src/

rousseau at users.alioth.debian.org rousseau at users.alioth.debian.org
Tue Oct 9 15:01:07 UTC 2007


Author: rousseau
Date: Tue Oct  9 15:01:07 2007
New Revision: 2635

URL: http://svn.debian.org/wsvn/pcsclite/?sc=1&rev=2635
Log:
add support of mix 32/64 bits platforms. Closes bug [#303790] pcscd
protocol depends on word size; breaks 32-bit clients with 64-bit server

Thanks to Jacob Berkman for the big patch

Added:
    trunk/PCSC/src/lassert.h
    trunk/PCSC/src/pcsc-wirecheck-gen.c
    trunk/PCSC/src/pcsc-wirecheck-main.c
Modified:
    trunk/PCSC/src/Makefile.am
    trunk/PCSC/src/eventhandler.c
    trunk/PCSC/src/eventhandler.h
    trunk/PCSC/src/pcscdaemon.c
    trunk/PCSC/src/readerfactory.c
    trunk/PCSC/src/winscard.c
    trunk/PCSC/src/winscard_clnt.c
    trunk/PCSC/src/winscard_msg.c
    trunk/PCSC/src/winscard_msg.h
    trunk/PCSC/src/winscard_msg_srv.c
    trunk/PCSC/src/winscard_svc.c
    trunk/PCSC/src/winscard_svc.h

Modified: trunk/PCSC/src/Makefile.am
URL: http://svn.debian.org/wsvn/pcsclite/trunk/PCSC/src/Makefile.am?rev=2635&op=diff
==============================================================================
--- trunk/PCSC/src/Makefile.am (original)
+++ trunk/PCSC/src/Makefile.am Tue Oct  9 15:01:07 2007
@@ -8,7 +8,7 @@
 if !HAVE_SCF
 sbin_PROGRAMS = pcscd
 endif
-noinst_PROGRAMS = testpcsc
+noinst_PROGRAMS = testpcsc pcsc-wirecheck pcsc-wirecheck-gen
 
 if HAVE_SCF
 PCSC_CLIENT_SRC  = winscard_scf.c
@@ -98,6 +98,38 @@
 testpcsc_SOURCES = testpcsc.c
 testpcsc_LDADD = libpcsclite.la
 
+pcsc_wirecheck_gen_SOURCES = \
+	pcsc-wirecheck-gen.c
+
+# pcsc_wirecheck_gen_CPPFLAGS := $(LIBPCSCLITE_CFLAGS)
+
+pcsc_wirecheck_SOURCES = \
+	lassert.h \
+	pcsc-wirecheck-dist.c \
+	pcsc-wirecheck-main.c
+
+# pcsc_wirecheck_CFLAGS := $(LIBPCSCLITE_CFLAGS) -DCOMPAT_64BIT_SERVER=1
+
+$(srcdir)/pcsc-wirecheck-dist.c: pcsc-wirecheck-gen
+	@if test -f $@ ; then \
+		echo "touch $@" ; \
+		touch $@ ; \
+	else \
+		echo "rm -f $@" ; \
+		rm -f $@ ; \
+		echo "./pcsc-wirecheck-gen > $@.tmp" ; \
+		./pcsc-wirecheck-gen > $@.tmp ; \
+		echo "mv $@.tmp $@" ; \
+		mv $@.tmp $@ ; \
+	fi
+
+.PHONY: regen
+
+regen: pcsc-wirecheck-gen
+	rm -f $(srcdir)/pcsc-wirecheck-dist.c
+	./pcsc-wirecheck-gen > $(srcdir)/pcsc-wirecheck-dist.c.tmp
+	mv $(srcdir)/pcsc-wirecheck-dist.c.tmp $(srcdir)/pcsc-wirecheck-dist.c
+
 nobase_include_HEADERS = \
 	PCSC/debuglog.h \
 	PCSC/ifdhandler.h \

Modified: trunk/PCSC/src/eventhandler.c
URL: http://svn.debian.org/wsvn/pcsclite/trunk/PCSC/src/eventhandler.c?rev=2635&op=diff
==============================================================================
--- trunk/PCSC/src/eventhandler.c (original)
+++ trunk/PCSC/src/eventhandler.c Tue Oct  9 15:01:07 2007
@@ -214,6 +214,7 @@
 	LPCSTR lpcReader;
 	DWORD dwStatus, dwReaderSharing;
 	DWORD dwCurrentState;
+	DWORD dwAtrLen;
 	int pageSize;
 
 	/*
@@ -227,14 +228,18 @@
 
 	pageSize = SYS_GetPageSize();
 
+	dwAtrLen = rContext->readerState->cardAtrLength;
 	rv = IFDStatusICC(rContext, &dwStatus, rContext->readerState->cardAtr,
-			&rContext->readerState->cardAtrLength);
+		&dwAtrLen);
+	rContext->readerState->cardAtrLength = dwAtrLen;
+
 	if (dwStatus & SCARD_PRESENT)
 	{
-		rContext->readerState->cardAtrLength = MAX_ATR_SIZE;
+		dwAtrLen = MAX_ATR_SIZE;
 		rv = IFDPowerICC(rContext, IFD_POWER_UP,
 			rContext->readerState->cardAtr,
-			&rContext->readerState->cardAtrLength);
+			&dwAtrLen);
+		rContext->readerState->cardAtrLength = dwAtrLen;
 
 		/* the protocol is unset after a power on */
 		rContext->readerState->cardProtocol = SCARD_PROTOCOL_UNDEFINED;
@@ -300,9 +305,11 @@
 	{
 		dwStatus = 0;
 
+		dwAtrLen = rContext->readerState->cardAtrLength;
 		rv = IFDStatusICC(rContext, &dwStatus,
 			rContext->readerState->cardAtr,
-			&rContext->readerState->cardAtrLength);
+			&dwAtrLen);
+		rContext->readerState->cardAtrLength = dwAtrLen;
 
 		if (rv != SCARD_S_SUCCESS)
 		{
@@ -387,10 +394,11 @@
 				 * Power and reset the card
 				 */
 				SYS_USleep(PCSCLITE_STATUS_WAIT);
-				rContext->readerState->cardAtrLength = MAX_ATR_SIZE;
+				dwAtrLen = MAX_ATR_SIZE;
 				rv = IFDPowerICC(rContext, IFD_POWER_UP,
 					rContext->readerState->cardAtr,
-					&rContext->readerState->cardAtrLength);
+					&dwAtrLen);
+				rContext->readerState->cardAtrLength = dwAtrLen;
 
 				/* the protocol is unset after a power on */
 				rContext->readerState->cardProtocol = SCARD_PROTOCOL_UNDEFINED;

Modified: trunk/PCSC/src/eventhandler.h
URL: http://svn.debian.org/wsvn/pcsclite/trunk/PCSC/src/eventhandler.h?rev=2635&op=diff
==============================================================================
--- trunk/PCSC/src/eventhandler.h (original)
+++ trunk/PCSC/src/eventhandler.h Tue Oct  9 15:01:07 2007
@@ -18,6 +18,8 @@
 #ifndef __eventhandler_h__
 #define __eventhandler_h__
 
+#include <stdint.h>
+
 #ifdef __cplusplus
 extern "C"
 {
@@ -29,15 +31,15 @@
 	 */
 	typedef struct pubReaderStatesList
 	{
-		LONG readerID;
+		int32_t readerID;
 		char readerName[MAX_READERNAME];
-		DWORD readerState;
-		LONG readerSharing;
-		DWORD dummy;
+		uint32_t readerState;
+		int32_t readerSharing;
+		uint32_t dummy;
 
 		UCHAR cardAtr[MAX_ATR_SIZE];
-		DWORD cardAtrLength;
-		DWORD cardProtocol;
+		uint32_t cardAtrLength;
+		uint32_t cardProtocol;
 	}
 	READER_STATE, *PREADER_STATE;
 

Added: trunk/PCSC/src/lassert.h
URL: http://svn.debian.org/wsvn/pcsclite/trunk/PCSC/src/lassert.h?rev=2635&op=file
==============================================================================
--- trunk/PCSC/src/lassert.h (added)
+++ trunk/PCSC/src/lassert.h Tue Oct  9 15:01:07 2007
@@ -1,0 +1,35 @@
+#ifndef LASSERT_H
+#define LASSERT_H
+
+#include <stdio.h>
+#include <stdlib.h>
+
+#if 0
+#define FAIL exit (1)
+#else
+#define FAIL
+#endif
+
+#define LASSERT(cond)                                                   \
+    ({                                                                  \
+        if (cond)                                                       \
+            ;                                                           \
+        else {                                                          \
+            fprintf (stderr, "%s:%d: assertion FAILED: " #cond "\n",    \
+                     __FILE__, __LINE__);                               \
+            FAIL;                                                       \
+        }                                                               \
+    })
+
+#define LASSERTF(cond, fmt, a...)                                       \
+    ({                                                                  \
+        if (cond)                                                       \
+            ;                                                           \
+        else {                                                          \
+            fprintf (stderr, "%s:%d: assertion FAILED: " #cond ": " fmt, \
+                     __FILE__, __LINE__, ## a);                         \
+            FAIL;                                                       \
+        }                                                               \
+    })
+
+#endif /* LASSERT_H */

Added: trunk/PCSC/src/pcsc-wirecheck-gen.c
URL: http://svn.debian.org/wsvn/pcsclite/trunk/PCSC/src/pcsc-wirecheck-gen.c?rev=2635&op=file
==============================================================================
--- trunk/PCSC/src/pcsc-wirecheck-gen.c (added)
+++ trunk/PCSC/src/pcsc-wirecheck-gen.c Tue Oct  9 15:01:07 2007
@@ -1,0 +1,279 @@
+#include <stdio.h>
+#include <sys/types.h>
+#include <sys/wait.h>
+#include <stddef.h>
+
+#include "PCSC/pcsclite.h"
+#include "pcscd.h"
+#include "winscard_msg.h"
+#include "readerfactory.h"
+#include "eventhandler.h"
+
+#define BLANK_LINE()                                            \
+do {                                                            \
+        printf("\n");                                           \
+} while(0)
+
+#define COMMENT(c)                                              \
+do {                                                            \
+        printf("        /* "c" */\n");                          \
+} while(0)
+
+#define STRINGIFY(a) #a
+
+
+#define CHECK_CDEFINE(a)                                        \
+        printf("        CLASSERT("#a" == "STRINGIFY(a) ");\n")
+
+#define CHECK_CVALUE(a)                                         \
+        printf("        CLASSERT("#a" == %lld);\n", (long long)a)
+
+#define CHECK_DEFINE(a)                                         \
+do {                                                            \
+        printf("        LASSERTF("#a" == "STRINGIFY(a)          \
+               ",\" found %%lld\\n\",\n                 "       \
+               "(long long)"#a");\n");   \
+} while(0)
+
+#define CHECK_VALUE(a)                                          \
+do {                                                            \
+        printf("        LASSERTF("#a                            \
+               " == %lld, \" found %%lld\\n\",\n                 "\
+               "(long long)"#a");\n", (long long)a);            \
+} while(0)
+
+#define CHECK_VALUE_64(a)                                       \
+do {                                                            \
+        printf("        LASSERTF("#a                            \
+               " == %lldULL, \" found %%lld\\n\",\n                 "\
+               "(long long)"#a");\n", (long long)a);            \
+} while(0)
+
+#define CHECK_MEMBER_OFFSET(s,m)                                \
+do {                                                            \
+        CHECK_VALUE((int)offsetof(struct s, m));                \
+} while(0)
+
+#define CHECK_MEMBER_SIZEOF(s,m)                                \
+do {                                                            \
+        CHECK_VALUE((int)sizeof(((struct s *)0)->m));           \
+} while(0)
+
+#define CHECK_MEMBER(s,m)                                       \
+do {                                                            \
+        CHECK_MEMBER_OFFSET(s, m);                              \
+                CHECK_MEMBER_SIZEOF(s, m);                      \
+} while(0)
+
+#define CHECK_STRUCT(s)                                         \
+do {                                                            \
+        COMMENT("Checks for struct "#s);                        \
+                CHECK_VALUE((int)sizeof(struct s));             \
+} while(0)
+
+static void
+check_constants (void)
+{
+    COMMENT ("Constants...");
+
+    BLANK_LINE ();
+    CHECK_DEFINE (PROTOCOL_VERSION_MAJOR);
+    CHECK_DEFINE (PROTOCOL_VERSION_MINOR);
+
+    BLANK_LINE ();
+    CHECK_DEFINE (PCSCLITE_MSG_KEY_LEN);
+    CHECK_DEFINE (PCSCLITE_MAX_MESSAGE_SIZE);
+
+    BLANK_LINE ();
+    CHECK_DEFINE (MAX_READERNAME);
+    CHECK_DEFINE (MAX_ATR_SIZE);
+    CHECK_DEFINE (MAX_BUFFER_SIZE);
+
+    BLANK_LINE ();
+    COMMENT ("enum pcsc_adm_commands");
+    CHECK_VALUE (CMD_FUNCTION);
+    CHECK_VALUE (CMD_FAILED);
+    CHECK_VALUE (CMD_SERVER_DIED);
+    CHECK_VALUE (CMD_CLIENT_DIED);
+    CHECK_VALUE (CMD_READER_EVENT);
+    CHECK_VALUE (CMD_SYN);
+    CHECK_VALUE (CMD_ACK);
+    CHECK_VALUE (CMD_VERSION);
+
+    BLANK_LINE ();
+    COMMENT ("enum pcsc_msg_commands");
+    CHECK_VALUE (SCARD_ESTABLISH_CONTEXT);
+    CHECK_VALUE (SCARD_RELEASE_CONTEXT);
+    CHECK_VALUE (SCARD_LIST_READERS);
+    CHECK_VALUE (SCARD_CONNECT);
+    CHECK_VALUE (SCARD_RECONNECT);
+    CHECK_VALUE (SCARD_DISCONNECT);
+    CHECK_VALUE (SCARD_BEGIN_TRANSACTION);
+    CHECK_VALUE (SCARD_END_TRANSACTION);
+    CHECK_VALUE (SCARD_TRANSMIT);
+    CHECK_VALUE (SCARD_CONTROL);
+    CHECK_VALUE (SCARD_STATUS);
+    CHECK_VALUE (SCARD_GET_STATUS_CHANGE);
+    CHECK_VALUE (SCARD_CANCEL);
+    CHECK_VALUE (SCARD_CANCEL_TRANSACTION);
+    CHECK_VALUE (SCARD_GET_ATTRIB);
+    CHECK_VALUE (SCARD_SET_ATTRIB);
+}
+
+static void
+check_types (void)
+{
+    COMMENT ("Types...");
+
+    BLANK_LINE ();
+    CHECK_STRUCT (rxSharedSegment);
+    CHECK_MEMBER (rxSharedSegment, mtype);
+    CHECK_MEMBER (rxSharedSegment, user_id);
+    CHECK_MEMBER (rxSharedSegment, group_id);
+    CHECK_MEMBER (rxSharedSegment, command);
+    CHECK_MEMBER (rxSharedSegment, date);
+    CHECK_MEMBER (rxSharedSegment, key);
+    CHECK_MEMBER (rxSharedSegment, data);
+
+    BLANK_LINE ();
+    CHECK_STRUCT (version_struct);
+    CHECK_MEMBER (version_struct, major);
+    CHECK_MEMBER (version_struct, minor);
+    CHECK_MEMBER (version_struct, rv);
+
+    BLANK_LINE ();
+    CHECK_STRUCT (client_struct);
+    CHECK_MEMBER (client_struct, hContext);
+
+    BLANK_LINE ();
+    CHECK_STRUCT (establish_struct);
+    CHECK_MEMBER (establish_struct, dwScope);
+    CHECK_MEMBER (establish_struct, phContext);
+    CHECK_MEMBER (establish_struct, rv);
+
+    BLANK_LINE ();
+    CHECK_STRUCT (release_struct);
+    CHECK_MEMBER (release_struct, hContext);
+    CHECK_MEMBER (release_struct, rv);
+
+    BLANK_LINE ();
+    CHECK_STRUCT (connect_struct);
+    CHECK_MEMBER (connect_struct, hContext);
+    CHECK_MEMBER (connect_struct, szReader);
+    CHECK_MEMBER (connect_struct, dwShareMode);
+    CHECK_MEMBER (connect_struct, dwPreferredProtocols);
+    CHECK_MEMBER (connect_struct, phCard);
+    CHECK_MEMBER (connect_struct, pdwActiveProtocol);
+    CHECK_MEMBER (connect_struct, rv);
+
+    BLANK_LINE ();
+    CHECK_STRUCT (reconnect_struct);
+    CHECK_MEMBER (reconnect_struct, hCard);
+    CHECK_MEMBER (reconnect_struct, dwShareMode);
+    CHECK_MEMBER (reconnect_struct, dwPreferredProtocols);
+    CHECK_MEMBER (reconnect_struct, dwInitialization);
+    CHECK_MEMBER (reconnect_struct, pdwActiveProtocol);
+    CHECK_MEMBER (reconnect_struct, rv);
+
+    BLANK_LINE ();
+    CHECK_STRUCT (disconnect_struct);
+    CHECK_MEMBER (disconnect_struct, hCard);
+    CHECK_MEMBER (disconnect_struct, dwDisposition);
+    CHECK_MEMBER (disconnect_struct, rv);
+
+    BLANK_LINE ();
+    CHECK_STRUCT (begin_struct);
+    CHECK_MEMBER (begin_struct, hCard);
+    CHECK_MEMBER (begin_struct, rv);
+
+    BLANK_LINE ();
+    CHECK_STRUCT (end_struct);
+    CHECK_MEMBER (end_struct, hCard);
+    CHECK_MEMBER (end_struct, dwDisposition);
+    CHECK_MEMBER (end_struct, rv);
+
+    BLANK_LINE ();
+    CHECK_STRUCT (cancel_struct);
+    CHECK_MEMBER (cancel_struct, hCard);
+    CHECK_MEMBER (cancel_struct, rv);
+
+    BLANK_LINE ();
+    CHECK_STRUCT (status_struct);
+    CHECK_MEMBER (status_struct, hCard);
+    CHECK_MEMBER (status_struct, mszReaderNames);
+    CHECK_MEMBER (status_struct, pcchReaderLen);
+    CHECK_MEMBER (status_struct, pdwState);
+    CHECK_MEMBER (status_struct, pdwProtocol);
+    CHECK_MEMBER (status_struct, pbAtr);
+    CHECK_MEMBER (status_struct, pcbAtrLen);
+    CHECK_MEMBER (status_struct, rv);
+
+    BLANK_LINE ();
+    CHECK_STRUCT (transmit_struct);
+    CHECK_MEMBER (transmit_struct, hCard);
+    CHECK_MEMBER (transmit_struct, pioSendPciProtocol);
+    CHECK_MEMBER (transmit_struct, pioSendPciLength);
+    CHECK_MEMBER (transmit_struct, pbSendBuffer);
+    CHECK_MEMBER (transmit_struct, cbSendLength);
+    CHECK_MEMBER (transmit_struct, pioRecvPciProtocol);
+    CHECK_MEMBER (transmit_struct, pioRecvPciLength);
+    CHECK_MEMBER (transmit_struct, pbRecvBuffer);
+    CHECK_MEMBER (transmit_struct, pcbRecvLength);
+    CHECK_MEMBER (transmit_struct, rv);
+
+    BLANK_LINE ();
+    CHECK_STRUCT (control_struct);
+    CHECK_MEMBER (control_struct, hCard);
+    CHECK_MEMBER (control_struct, dwControlCode);
+    CHECK_MEMBER (control_struct, pbSendBuffer);
+    CHECK_MEMBER (control_struct, cbSendLength);
+    CHECK_MEMBER (control_struct, pbRecvBuffer);
+    CHECK_MEMBER (control_struct, cbRecvLength);
+    CHECK_MEMBER (control_struct, dwBytesReturned);
+    CHECK_MEMBER (control_struct, rv);
+
+    BLANK_LINE ();
+    CHECK_STRUCT (getset_struct);
+    CHECK_MEMBER (getset_struct, hCard);
+    CHECK_MEMBER (getset_struct, dwAttrId);
+    CHECK_MEMBER (getset_struct, cbAttrLen);
+    CHECK_MEMBER (getset_struct, rv);
+
+    BLANK_LINE ();
+    CHECK_STRUCT (pubReaderStatesList);
+    CHECK_MEMBER (pubReaderStatesList, readerID);
+    CHECK_MEMBER (pubReaderStatesList, readerName);
+    CHECK_MEMBER (pubReaderStatesList, readerState);
+    CHECK_MEMBER (pubReaderStatesList, readerSharing);
+    CHECK_MEMBER (pubReaderStatesList, cardAtr);
+    CHECK_MEMBER (pubReaderStatesList, cardAtrLength);
+    CHECK_MEMBER (pubReaderStatesList, cardProtocol);
+}
+
+int
+main(int argc, char **argv)
+{
+    printf ("#include <sys/types.h>\n"
+            "#include <time.h>\n"
+            "#include <stddef.h>\n\n"
+            "#include \"PCSC/pcsclite.h\"\n"
+            "#include \"pcscd.h\"\n"
+            "#include \"readerfactory.h\"\n"
+            "#include \"eventhandler.h\"\n"
+            "#include \"winscard_msg.h\"\n\n"
+            "#include \"lassert.h\"\n\n"
+            "void pcsc_assert_wire_constants(void);\n"
+            "void pcsc_assert_wire_constants(void)\n"
+            "{\n");
+
+    BLANK_LINE ();
+ 
+    check_constants ();
+    check_types ();
+
+    BLANK_LINE ();
+
+    printf ("}\n");
+
+    return 0;
+}

Added: trunk/PCSC/src/pcsc-wirecheck-main.c
URL: http://svn.debian.org/wsvn/pcsclite/trunk/PCSC/src/pcsc-wirecheck-main.c?rev=2635&op=file
==============================================================================
--- trunk/PCSC/src/pcsc-wirecheck-main.c (added)
+++ trunk/PCSC/src/pcsc-wirecheck-main.c Tue Oct  9 15:01:07 2007
@@ -1,0 +1,8 @@
+void pcsc_assert_wire_constants(void);
+
+int
+main (int argc, char **argv)
+{
+    pcsc_assert_wire_constants ();
+    return 0;
+}

Modified: trunk/PCSC/src/pcscdaemon.c
URL: http://svn.debian.org/wsvn/pcsclite/trunk/PCSC/src/pcscdaemon.c?rev=2635&op=diff
==============================================================================
--- trunk/PCSC/src/pcscdaemon.c (original)
+++ trunk/PCSC/src/pcscdaemon.c Tue Oct  9 15:01:07 2007
@@ -113,7 +113,7 @@
 {
 	int rsp;
 	LONG rv;
-	DWORD dwClientID;	/* Connection ID used to reference the Client */
+	uint32_t dwClientID;	/* Connection ID used to reference the Client */
 
 	rsp = 0;
 	rv = 0;

Modified: trunk/PCSC/src/readerfactory.c
URL: http://svn.debian.org/wsvn/pcsclite/trunk/PCSC/src/readerfactory.c?rev=2635&op=diff
==============================================================================
--- trunk/PCSC/src/readerfactory.c (original)
+++ trunk/PCSC/src/readerfactory.c Tue Oct  9 15:01:07 2007
@@ -47,6 +47,8 @@
 static DWORD dwNumReadersContexts = 0;
 static char *ConfigFile = NULL;
 static int ConfigFileCRC = 0;
+
+#define IDENTITY_SHIFT 16
 
 LONG RFAllocateReaderSpace(void)
 {
@@ -174,7 +176,7 @@
 	(sReadersContexts[dwContext])->pdwFeeds = NULL;
 	(sReadersContexts[dwContext])->pdwMutex = NULL;
 	(sReadersContexts[dwContext])->dwIdentity =
-		(dwContext + 1) << (sizeof(DWORD) / 2) * 8;
+		(dwContext + 1) << IDENTITY_SHIFT;
 	(sReadersContexts[dwContext])->readerState = NULL;
 
 	for (i = 0; i < PCSCLITE_MAX_READER_CONTEXT_CHANNELS; i++)
@@ -390,7 +392,7 @@
 		(sReadersContexts[dwContextB])->LockCount = 0;
 		(sReadersContexts[dwContextB])->readerState = NULL;
 		(sReadersContexts[dwContextB])->dwIdentity =
-			(dwContextB + 1) << (sizeof(DWORD) / 2) * 8;
+			(dwContextB + 1) << IDENTITY_SHIFT;
 
 		for (i = 0; i < PCSCLITE_MAX_READER_CONTEXT_CHANNELS; i++)
 			(sReadersContexts[dwContextB])->psHandles[i].hCard = 0;
@@ -803,8 +805,8 @@
 	/*
 	 * Strip off the lower nibble and get the identity
 	 */
-	dwIdentity = dwIdentity >> (sizeof(DWORD) / 2) * 8;
-	dwIdentity = dwIdentity << (sizeof(DWORD) / 2) * 8;
+	dwIdentity = dwIdentity >> IDENTITY_SHIFT;
+	dwIdentity = dwIdentity << IDENTITY_SHIFT;
 
 	for (i = 0; i < PCSCLITE_MAX_READERS_CONTEXTS; i++)
 	{

Modified: trunk/PCSC/src/winscard.c
URL: http://svn.debian.org/wsvn/pcsclite/trunk/PCSC/src/winscard.c?rev=2635&op=diff
==============================================================================
--- trunk/PCSC/src/winscard.c (original)
+++ trunk/PCSC/src/winscard.c Tue Oct  9 15:01:07 2007
@@ -569,22 +569,25 @@
 	if (dwInitialization == SCARD_RESET_CARD ||
 		dwInitialization == SCARD_UNPOWER_CARD)
 	{
+		DWORD dwAtrLen;
 		/*
 		 * Currently pcsc-lite keeps the card powered constantly
 		 */
+		dwAtrLen = rContext->readerState->cardAtrLength;
 		if (SCARD_RESET_CARD == dwInitialization)
 			rv = IFDPowerICC(rContext, IFD_RESET,
 				rContext->readerState->cardAtr,
-				&rContext->readerState->cardAtrLength);
+				&dwAtrLen);
 		else
 		{
 			rv = IFDPowerICC(rContext, IFD_POWER_DOWN,
 				rContext->readerState->cardAtr,
-				&rContext->readerState->cardAtrLength);
+				&dwAtrLen);
 			rv = IFDPowerICC(rContext, IFD_POWER_UP,
 				rContext->readerState->cardAtr,
-				&rContext->readerState->cardAtrLength);
-		}
+				&dwAtrLen);
+		}
+		rContext->readerState->cardAtrLength = dwAtrLen;
 
 		/* the protocol is unset after a power on */
 		rContext->readerState->cardProtocol = SCARD_PROTOCOL_UNDEFINED;
@@ -804,6 +807,7 @@
 {
 	LONG rv;
 	PREADER_CONTEXT rContext = NULL;
+	DWORD dwAtrLen;
 
 	if (hCard == 0)
 		return SCARD_E_INVALID_HANDLE;
@@ -853,19 +857,21 @@
 		/*
 		 * Currently pcsc-lite keeps the card powered constantly
 		 */
+		dwAtrLen = rContext->readerState->cardAtrLength;
 		if (SCARD_RESET_CARD == dwDisposition)
 			rv = IFDPowerICC(rContext, IFD_RESET,
 				rContext->readerState->cardAtr,
-				&rContext->readerState->cardAtrLength);
+				&dwAtrLen);
 		else
 		{
 			rv = IFDPowerICC(rContext, IFD_POWER_DOWN,
 				rContext->readerState->cardAtr,
-				&rContext->readerState->cardAtrLength);
+				&dwAtrLen);
 			rv = IFDPowerICC(rContext, IFD_POWER_UP,
 				rContext->readerState->cardAtr,
-				&rContext->readerState->cardAtrLength);
-		}
+				&dwAtrLen);
+		}
+		rContext->readerState->cardAtrLength = dwAtrLen;
 
 		/* the protocol is unset after a power on */
 		rContext->readerState->cardProtocol = SCARD_PROTOCOL_UNDEFINED;
@@ -1029,6 +1035,7 @@
 {
 	LONG rv;
 	PREADER_CONTEXT rContext = NULL;
+	DWORD dwAtrLen;
 
 	/*
 	 * Ignoring dwDisposition for now
@@ -1066,19 +1073,21 @@
 		/*
 		 * Currently pcsc-lite keeps the card always powered
 		 */
+		dwAtrLen = rContext->readerState->cardAtrLength;
 		if (SCARD_RESET_CARD == dwDisposition)
 			rv = IFDPowerICC(rContext, IFD_RESET,
 				rContext->readerState->cardAtr,
-				&rContext->readerState->cardAtrLength);
+				&dwAtrLen);
 		else
 		{
 			rv = IFDPowerICC(rContext, IFD_POWER_DOWN,
 				rContext->readerState->cardAtr,
-				&rContext->readerState->cardAtrLength);
+				&dwAtrLen);
 			rv = IFDPowerICC(rContext, IFD_POWER_UP,
 				rContext->readerState->cardAtr,
-				&rContext->readerState->cardAtrLength);
-		}
+				&dwAtrLen);
+		}
+		rContext->readerState->cardAtrLength = dwAtrLen;
 
 		/* the protocol is unset after a power on */
 		rContext->readerState->cardProtocol = SCARD_PROTOCOL_UNDEFINED;

Modified: trunk/PCSC/src/winscard_clnt.c
URL: http://svn.debian.org/wsvn/pcsclite/trunk/PCSC/src/winscard_clnt.c?rev=2635&op=diff
==============================================================================
--- trunk/PCSC/src/winscard_clnt.c (original)
+++ trunk/PCSC/src/winscard_clnt.c Tue Oct  9 15:01:07 2007
@@ -344,7 +344,7 @@
 	int i;
 	establish_struct scEstablishStruct;
 	sharedSegmentMsg msgStruct;
-	DWORD dwClientID = 0;
+	uint32_t dwClientID = 0;
 
 	if (phContext == NULL)
 		return SCARD_E_INVALID_PARAMETER;
@@ -2763,20 +2763,20 @@
 		scTransmitStructExtended->size = sizeof(*scTransmitStructExtended)
 			- (sizeof(transmit_struct_extended) - offsetof(transmit_struct_extended, data))
 			+ cbSendLength;
-		memcpy(&scTransmitStructExtended->pioSendPci, pioSendPci,
-			sizeof(SCARD_IO_REQUEST));
+		scTransmitStructExtended->pioSendPciProtocol = pioSendPci->dwProtocol;
+		scTransmitStructExtended->pioSendPciLength = pioSendPci->cbPciLength;
 		memcpy(scTransmitStructExtended->data, pbSendBuffer, cbSendLength);
 		scTransmitStructExtended->rv = SCARD_S_SUCCESS;
 
 		if (pioRecvPci)
 		{
-			memcpy(&scTransmitStructExtended->pioRecvPci, pioRecvPci,
-				sizeof(SCARD_IO_REQUEST));
+			scTransmitStructExtended->pioRecvPciProtocol = pioRecvPci->dwProtocol;
+			scTransmitStructExtended->pioRecvPciLength = pioRecvPci->cbPciLength;
 		}
 		else
 		{
-			scTransmitStructExtended->pioRecvPci.dwProtocol = SCARD_PROTOCOL_ANY;
-			scTransmitStructExtended->pioRecvPci.cbPciLength = sizeof(SCARD_IO_REQUEST);
+			scTransmitStructExtended->pioRecvPciProtocol = SCARD_PROTOCOL_ANY;
+			scTransmitStructExtended->pioRecvPciLength = sizeof(SCARD_IO_REQUEST);
 		}
 
 		rv = WrapSHMWrite(SCARD_TRANSMIT_EXTENDED,
@@ -2829,8 +2829,10 @@
 				scTransmitStructExtended -> pcbRecvLength);
 
 			if (pioRecvPci)
-				memcpy(pioRecvPci, &scTransmitStructExtended -> pioRecvPci,
-					sizeof(SCARD_IO_REQUEST));
+			{
+				pioRecvPci->dwProtocol = scTransmitStructExtended->pioRecvPciProtocol;
+				pioRecvPci->cbPciLength = scTransmitStructExtended->pioRecvPciLength;
+			}
 		}
 
 		*pcbRecvLength = scTransmitStructExtended -> pcbRecvLength;
@@ -2847,15 +2849,15 @@
 		scTransmitStruct.hCard = hCard;
 		scTransmitStruct.cbSendLength = cbSendLength;
 		scTransmitStruct.pcbRecvLength = *pcbRecvLength;
-		memcpy(&scTransmitStruct.pioSendPci, pioSendPci,
-			sizeof(SCARD_IO_REQUEST));
+		scTransmitStruct.pioSendPciProtocol = pioSendPci->dwProtocol;
+		scTransmitStruct.pioSendPciLength = pioSendPci->cbPciLength;
 		memcpy(scTransmitStruct.pbSendBuffer, pbSendBuffer, cbSendLength);
 		memset(scTransmitStruct.pbSendBuffer+cbSendLength, 0, sizeof(scTransmitStruct.pbSendBuffer)-cbSendLength);
 		memset(scTransmitStruct.pbRecvBuffer, 0, sizeof(scTransmitStruct.pbRecvBuffer));
 		scTransmitStruct.rv = SCARD_S_SUCCESS;
 
-		scTransmitStruct.pioRecvPci.dwProtocol = SCARD_PROTOCOL_ANY;
-		scTransmitStruct.pioRecvPci.cbPciLength = sizeof(scTransmitStruct.pioRecvPci);
+		scTransmitStruct.pioRecvPciProtocol = SCARD_PROTOCOL_ANY;
+		scTransmitStruct.pioRecvPciLength = sizeof(SCARD_IO_REQUEST);
 
 		rv = WrapSHMWrite(SCARD_TRANSMIT,
 			psContextMap[dwContextIndex].dwClientID, sizeof(scTransmitStruct),
@@ -2896,8 +2898,10 @@
 				scTransmitStruct.pcbRecvLength);
 
 			if (pioRecvPci)
-				memcpy(pioRecvPci, &scTransmitStruct.pioRecvPci,
-					sizeof(SCARD_IO_REQUEST));
+			{
+				pioRecvPci->dwProtocol = scTransmitStruct.pioRecvPciProtocol;
+				pioRecvPci->cbPciLength = scTransmitStruct.pioRecvPciLength;
+			}
 		}
 
 		*pcbRecvLength = scTransmitStruct.pcbRecvLength;

Modified: trunk/PCSC/src/winscard_msg.c
URL: http://svn.debian.org/wsvn/pcsclite/trunk/PCSC/src/winscard_msg.c?rev=2635&op=diff
==============================================================================
--- trunk/PCSC/src/winscard_msg.c (original)
+++ trunk/PCSC/src/winscard_msg.c Tue Oct  9 15:01:07 2007
@@ -54,7 +54,7 @@
  *
  * @return Same error codes as SHMMessageReceive().
  */
-INTERNAL int SHMClientRead(psharedSegmentMsg msgStruct, DWORD dwClientID, int blockamount)
+INTERNAL int32_t SHMClientRead(psharedSegmentMsg msgStruct, uint32_t dwClientID, int32_t blockamount)
 {
 	return SHMMessageReceive(msgStruct, sizeof(*msgStruct), dwClientID, blockamount);
 }
@@ -72,7 +72,7 @@
  * @retval -1 The socket can not open a connection.
  * @retval -1 Can not set the socket to non-blocking.
  */
-INTERNAL int SHMClientSetupSession(PDWORD pdwClientID)
+INTERNAL int SHMClientSetupSession(uint32_t *pdwClientID)
 {
 	struct sockaddr_un svc_addr;
 	int one;
@@ -119,7 +119,7 @@
  *
  * @retval 0 Success.
  */
-INTERNAL int SHMClientCloseSession(DWORD dwClientID)
+INTERNAL int SHMClientCloseSession(uint32_t dwClientID)
 {
 	SYS_CloseFile(dwClientID);
 	return 0;
@@ -140,8 +140,8 @@
  * @retval -1 Socket is closed.
  * @retval -1 A signal was received.
  */
-INTERNAL int SHMMessageSend(void *buffer_void, size_t buffer_size,
-	int filedes, int blockAmount)
+INTERNAL int SHMMessageSend(void *buffer_void, uint64_t buffer_size,
+	int32_t filedes, int32_t blockAmount)
 {
 	char *buffer = buffer_void;
 
@@ -265,8 +265,8 @@
  * @retval -1 Socket is closed.
  * @retval -1 A signal was received.
  */
-INTERNAL int SHMMessageReceive(void *buffer_void, size_t buffer_size,
-	int filedes, int blockAmount)
+INTERNAL int SHMMessageReceive(void *buffer_void, uint64_t buffer_size,
+	int32_t filedes, int32_t blockAmount)
 {
 	char *buffer = buffer_void;
 
@@ -409,8 +409,8 @@
  *
  * @return Same error codes as SHMMessageSend().
  */
-INTERNAL int WrapSHMWrite(unsigned int command, DWORD dwClientID,
-	unsigned int size, unsigned int blockAmount, void *data_void)
+INTERNAL int32_t WrapSHMWrite(uint32_t command, uint32_t dwClientID,
+	uint64_t size, uint32_t blockAmount, void *data_void)
 {
 	char *data = data_void;
 
@@ -426,7 +426,6 @@
 	msgStruct.user_id = SYS_GetUID();
 	msgStruct.group_id = SYS_GetGID();
 	msgStruct.command = command;
-	msgStruct.dummy = 0;
 	msgStruct.date = time(NULL);
 	memset(msgStruct.key, 0, sizeof(msgStruct.key));
 	if ((SCARD_TRANSMIT_EXTENDED == command)

Modified: trunk/PCSC/src/winscard_msg.h
URL: http://svn.debian.org/wsvn/pcsclite/trunk/PCSC/src/winscard_msg.h?rev=2635&op=diff
==============================================================================
--- trunk/PCSC/src/winscard_msg.h (original)
+++ trunk/PCSC/src/winscard_msg.h Tue Oct  9 15:01:07 2007
@@ -18,10 +18,12 @@
 #ifndef __winscard_msg_h__
 #define __winscard_msg_h__
 
+#include <stdint.h>
+
 /** Major version of the current message protocol */
-#define PROTOCOL_VERSION_MAJOR 2
+#define PROTOCOL_VERSION_MAJOR 3
 /** Minor version of the current message protocol */
-#define PROTOCOL_VERSION_MINOR 2
+#define PROTOCOL_VERSION_MINOR 0
 
 #ifdef __cplusplus
 extern "C"
@@ -41,13 +43,12 @@
 	 */
 	typedef struct rxSharedSegment
 	{
-		unsigned int mtype;		/** one of the \c pcsc_adm_commands */
-		unsigned int user_id;
-		unsigned int group_id;
-		unsigned int command;	/** one of the \c pcsc_msg_commands */
-		unsigned int dummy;	/* was request_id in pcsc-lite <= 1.2.0 */
-		time_t date;
-		unsigned char key[PCSCLITE_MSG_KEY_LEN];
+		uint32_t mtype;		/** one of the \c pcsc_adm_commands */
+		uint32_t user_id;
+		uint32_t group_id;
+		uint32_t command;	/** one of the \c pcsc_msg_commands */
+		uint64_t date;
+		unsigned char key[PCSCLITE_MSG_KEY_LEN]; /* 16 bytes */
 		unsigned char data[PCSCLITE_MAX_MESSAGE_SIZE];
 	}
 	sharedSegmentMsg, *psharedSegmentMsg;
@@ -97,15 +98,15 @@
 	 */
 	struct version_struct
 	{
-		int major;
-		int minor;
-		LONG rv;
+		int32_t major;
+		int32_t minor;
+		int32_t rv;
 	};
 	typedef struct version_struct version_struct;
 
 	struct client_struct
 	{
-		SCARDCONTEXT hContext;
+		uint32_t hContext;
 	};
 	typedef struct client_struct client_struct;
 
@@ -116,9 +117,9 @@
 	 */
 	struct establish_struct
 	{
-		DWORD dwScope;
-		SCARDCONTEXT phContext;
-		LONG rv;
+		uint32_t dwScope;
+		uint32_t phContext;
+		int32_t rv;
 	};
 	typedef struct establish_struct establish_struct;
 
@@ -129,8 +130,8 @@
 	 */
 	struct release_struct
 	{
-		SCARDCONTEXT hContext;
-		LONG rv;
+		uint32_t hContext;
+		int32_t rv;
 	};
 	typedef struct release_struct release_struct;
 
@@ -141,13 +142,13 @@
 	 */
 	struct connect_struct
 	{
-		SCARDCONTEXT hContext;
+		uint32_t hContext;
 		char szReader[MAX_READERNAME];
-		DWORD dwShareMode;
-		DWORD dwPreferredProtocols;
-		SCARDHANDLE phCard;
-		DWORD pdwActiveProtocol;
-		LONG rv;
+		uint32_t dwShareMode;
+		uint32_t dwPreferredProtocols;
+		int32_t phCard;
+		uint32_t pdwActiveProtocol;
+		int32_t rv;
 	};
 	typedef struct connect_struct connect_struct;
 
@@ -158,12 +159,12 @@
 	 */
 	struct reconnect_struct
 	{
-		SCARDHANDLE hCard;
-		DWORD dwShareMode;
-		DWORD dwPreferredProtocols;
-		DWORD dwInitialization;
-		DWORD pdwActiveProtocol;
-		LONG rv;
+		int32_t hCard;
+		uint32_t dwShareMode;
+		uint32_t dwPreferredProtocols;
+		uint32_t dwInitialization;
+		uint32_t pdwActiveProtocol;
+		int32_t rv;
 	};
 	typedef struct reconnect_struct reconnect_struct;
 
@@ -174,9 +175,9 @@
 	 */
 	struct disconnect_struct
 	{
-		SCARDHANDLE hCard;
-		DWORD dwDisposition;
-		LONG rv;
+		int32_t hCard;
+		uint32_t dwDisposition;
+		int32_t rv;
 	};
 	typedef struct disconnect_struct disconnect_struct;
 
@@ -187,8 +188,8 @@
 	 */
 	struct begin_struct
 	{
-		SCARDHANDLE hCard;
-		LONG rv;
+		int32_t hCard;
+		int32_t rv;
 	};
 	typedef struct begin_struct begin_struct;
 
@@ -199,9 +200,9 @@
 	 */
 	struct end_struct
 	{
-		SCARDHANDLE hCard;
-		DWORD dwDisposition;
-		LONG rv;
+		int32_t hCard;
+		uint32_t dwDisposition;
+		int32_t rv;
 	};
 	typedef struct end_struct end_struct;
 
@@ -212,8 +213,8 @@
 	 */
 	struct cancel_struct
 	{
-		SCARDHANDLE hCard;
-		LONG rv;
+		int32_t hCard;
+		int32_t rv;
 	};
 	typedef struct cancel_struct cancel_struct;
 
@@ -224,14 +225,14 @@
 	 */
 	struct status_struct
 	{
-		SCARDHANDLE hCard;
+		int32_t hCard;
 		char mszReaderNames[MAX_READERNAME];
-		DWORD pcchReaderLen;
-		DWORD pdwState;
-		DWORD pdwProtocol;
-		UCHAR pbAtr[MAX_ATR_SIZE];
-		DWORD pcbAtrLen;
-		LONG rv;
+		uint32_t pcchReaderLen;
+		uint32_t pdwState;
+		uint32_t pdwProtocol;
+		uint8_t pbAtr[MAX_ATR_SIZE];
+		uint32_t pcbAtrLen;
+		int32_t rv;
 	};
 	typedef struct status_struct status_struct;
 
@@ -242,14 +243,16 @@
 	 */
 	struct transmit_struct
 	{
-		SCARDHANDLE hCard;
-		SCARD_IO_REQUEST pioSendPci;
-		UCHAR pbSendBuffer[MAX_BUFFER_SIZE];
-		DWORD cbSendLength;
-		SCARD_IO_REQUEST pioRecvPci;
-		BYTE pbRecvBuffer[MAX_BUFFER_SIZE];
-		DWORD pcbRecvLength;
-		LONG rv;
+		int32_t hCard;
+		uint32_t pioSendPciProtocol;
+		uint32_t pioSendPciLength;
+		uint8_t pbSendBuffer[MAX_BUFFER_SIZE];
+		uint32_t cbSendLength;
+		uint32_t pioRecvPciProtocol;
+		uint32_t pioRecvPciLength;
+		uint8_t pbRecvBuffer[MAX_BUFFER_SIZE];
+		uint32_t pcbRecvLength;
+		int32_t rv;
 	};
 	typedef struct transmit_struct transmit_struct;
 
@@ -260,14 +263,16 @@
 	 */
 	struct transmit_struct_extended
 	{
-		SCARDHANDLE hCard;
-		SCARD_IO_REQUEST pioSendPci;
-		DWORD cbSendLength;
-		SCARD_IO_REQUEST pioRecvPci;
-		DWORD pcbRecvLength;
-		LONG rv;
-		size_t size;
-		BYTE data[1];
+		int32_t hCard;
+		uint32_t pioSendPciProtocol;
+		uint32_t pioSendPciLength;
+		uint32_t cbSendLength;
+		uint32_t pioRecvPciProtocol;
+		uint32_t pioRecvPciLength;
+		uint32_t pcbRecvLength;
+		int32_t rv;
+		uint64_t size;
+		uint8_t data[1];
 	};
 	typedef struct transmit_struct_extended transmit_struct_extended;
 
@@ -278,14 +283,14 @@
 	 */
 	struct control_struct
 	{
-		SCARDHANDLE hCard;
-		DWORD dwControlCode;
-		UCHAR pbSendBuffer[MAX_BUFFER_SIZE];
-		DWORD cbSendLength;
-		UCHAR pbRecvBuffer[MAX_BUFFER_SIZE];
-		DWORD cbRecvLength;
-		DWORD dwBytesReturned;
-		LONG rv;
+		int32_t hCard;
+		uint32_t dwControlCode;
+		uint8_t pbSendBuffer[MAX_BUFFER_SIZE];
+		uint32_t cbSendLength;
+		uint8_t pbRecvBuffer[MAX_BUFFER_SIZE];
+		uint32_t cbRecvLength;
+		uint32_t dwBytesReturned;
+		int32_t rv;
 	};
 	typedef struct control_struct control_struct;
 
@@ -296,14 +301,14 @@
 	 */
 	struct control_struct_extended
 	{
-		SCARDHANDLE hCard;
-		DWORD dwControlCode;
-		DWORD cbSendLength;
-		DWORD cbRecvLength;
-		DWORD pdwBytesReturned;
-		LONG rv;
-		size_t size;
-		BYTE data[1];
+		int32_t hCard;
+		uint32_t dwControlCode;
+		uint32_t cbSendLength;
+		uint32_t cbRecvLength;
+		uint32_t pdwBytesReturned;
+		int32_t rv;
+		uint64_t size;
+		uint8_t data[1];
 	};
 	typedef struct control_struct_extended control_struct_extended;
 
@@ -314,11 +319,11 @@
 	 */
 	struct getset_struct
 	{
-		SCARDHANDLE hCard;
-		DWORD dwAttrId;
-		UCHAR pbAttr[MAX_BUFFER_SIZE];
-		DWORD cbAttrLen;
-		LONG rv;
+		int32_t hCard;
+		uint32_t dwAttrId;
+		uint8_t pbAttr[MAX_BUFFER_SIZE];
+		uint32_t cbAttrLen;
+		int32_t rv;
 	};
 	typedef struct getset_struct getset_struct;
 
@@ -326,19 +331,19 @@
 	 * Now some function definitions
 	 */
 
-	int SHMClientRead(psharedSegmentMsg, DWORD, int);
-	int SHMClientSetupSession(PDWORD);
-	int SHMClientCloseSession(DWORD);
-	int SHMInitializeCommonSegment(void);
-	int SHMProcessEventsContext(PDWORD, psharedSegmentMsg, int);
-	int SHMProcessEventsServer(PDWORD, int);
-	int SHMMessageSend(void *buffer, size_t buffer_size, int filedes,
-		int blockAmount);
-	int SHMMessageReceive(void *buffer, size_t buffer_size,
-		int filedes, int blockAmount);
-	int WrapSHMWrite(unsigned int command, DWORD dwClientID, unsigned int size,
-		unsigned int blockAmount, void *data);
-	void SHMCleanupSharedSegment(int, const char *);
+	int32_t SHMClientRead(psharedSegmentMsg, uint32_t, int32_t);
+	int32_t SHMClientSetupSession(uint32_t *);
+	int32_t SHMClientCloseSession(uint32_t);
+	int32_t SHMInitializeCommonSegment(void);
+	int32_t SHMProcessEventsContext(uint32_t *, psharedSegmentMsg, int32_t);
+	int32_t SHMProcessEventsServer(uint32_t *, int32_t);
+	int32_t SHMMessageSend(void *buffer, uint64_t buffer_size, int32_t filedes,
+		int32_t blockAmount);
+	int32_t SHMMessageReceive(void *buffer, uint64_t buffer_size,
+		int32_t filedes, int32_t blockAmount);
+	int32_t WrapSHMWrite(uint32_t command, uint32_t dwClientID, uint64_t size,
+		uint32_t blockAmount, void *data);
+	void SHMCleanupSharedSegment(int32_t, const char *);
 
 #ifdef __cplusplus
 }

Modified: trunk/PCSC/src/winscard_msg_srv.c
URL: http://svn.debian.org/wsvn/pcsclite/trunk/PCSC/src/winscard_msg_srv.c?rev=2635&op=diff
==============================================================================
--- trunk/PCSC/src/winscard_msg_srv.c (original)
+++ trunk/PCSC/src/winscard_msg_srv.c Tue Oct  9 15:01:07 2007
@@ -61,7 +61,7 @@
  * @retval -1 Can not establish the connection.
  * @retval -1 Can not set the connection to non-blocking mode.
  */
-static int SHMProcessCommonChannelRequest(PDWORD pdwClientID)
+static int SHMProcessCommonChannelRequest(uint32_t *pdwClientID)
 {
 	socklen_t clnt_len;
 	int new_sock;
@@ -168,7 +168,7 @@
 #if defined(__NetBSD__) || defined(__FreeBSD__) || defined(__OpenBSD__)
 #define DO_TIMEOUT
 #endif
-INTERNAL int SHMProcessEventsServer(PDWORD pdwClientID, int blocktime)
+INTERNAL int32_t SHMProcessEventsServer(uint32_t *pdwClientID, int32_t blocktime)
 {
 	fd_set read_fd;
 	int selret;
@@ -236,7 +236,7 @@
  *
  * Called by \c ContextThread().
  */
-INTERNAL int SHMProcessEventsContext(PDWORD pdwClientID, psharedSegmentMsg msgStruct, int blocktime)
+INTERNAL int32_t SHMProcessEventsContext(uint32_t *pdwClientID, psharedSegmentMsg msgStruct, int32_t blocktime)
 {
 	fd_set read_fd;
 	int selret, rv;

Modified: trunk/PCSC/src/winscard_svc.c
URL: http://svn.debian.org/wsvn/pcsclite/trunk/PCSC/src/winscard_svc.c?rev=2635&op=diff
==============================================================================
--- trunk/PCSC/src/winscard_svc.c (original)
+++ trunk/PCSC/src/winscard_svc.c Tue Oct  9 15:01:07 2007
@@ -40,9 +40,9 @@
  */
 static struct _psContext
 {
-	SCARDCONTEXT hContext;
-	SCARDHANDLE hCard[PCSCLITE_MAX_APPLICATION_CONTEXT_CHANNELS];
-	DWORD dwClientID;			/* Connection ID used to reference the Client. */
+	uint32_t hContext;
+	uint32_t hCard[PCSCLITE_MAX_APPLICATION_CONTEXT_CHANNELS];
+	uint32_t dwClientID;			/* Connection ID used to reference the Client. */
 	PCSCLITE_THREAD_T pthThread;		/* Event polling thread's ID */
 	sharedSegmentMsg msgStruct;		/* Msg sent by the Client */
 	int protocol_major, protocol_minor;	/* Protocol number agreed between client and server*/
@@ -74,7 +74,7 @@
  * @retval SCARD_F_INTERNAL_ERROR Exceded the maximum number of simultaneous Application Contexts.
  * @retval SCARD_E_NO_MEMORY Error creating the Context Thread.
  */
-LONG CreateContextThread(PDWORD pdwClientID)
+LONG CreateContextThread(uint32_t *pdwClientID)
 {
 	int i;
 
@@ -259,6 +259,21 @@
 	control_struct *ctStr;
 	getset_struct *gsStr;
 
+	SCARDCONTEXT hContext;
+	SCARDHANDLE hCard;
+	DWORD dwActiveProtocol;
+
+	DWORD cchReaderLen;
+	DWORD dwState;
+	DWORD dwProtocol;
+	DWORD cbAtrLen;
+	DWORD cbRecvLength;
+	DWORD dwBytesReturned;
+	DWORD cbAttrLen;
+
+	SCARD_IO_REQUEST ioSendPci;
+	SCARD_IO_REQUEST ioRecvPci;
+
 	/*
 	 * Zero out everything
 	 */
@@ -268,8 +283,10 @@
 
 	case SCARD_ESTABLISH_CONTEXT:
 		esStr = ((establish_struct *) msgStruct->data);
-		esStr->rv = SCardEstablishContext(esStr->dwScope, 0, 0,
-			&esStr->phContext);
+
+		hContext = esStr->phContext;
+		esStr->rv = SCardEstablishContext(esStr->dwScope, 0, 0, &hContext);
+		esStr->phContext = hContext;
 
 		if (esStr->rv == SCARD_S_SUCCESS)
 			esStr->rv =
@@ -288,9 +305,16 @@
 
 	case SCARD_CONNECT:
 		coStr = ((connect_struct *) msgStruct->data);
+                
+		hCard = coStr->phCard;
+		dwActiveProtocol = coStr->pdwActiveProtocol;
+
 		coStr->rv = SCardConnect(coStr->hContext, coStr->szReader,
 			coStr->dwShareMode, coStr->dwPreferredProtocols,
-			&coStr->phCard, &coStr->pdwActiveProtocol);
+			&hCard, &dwActiveProtocol);
+
+		coStr->phCard = hCard;
+		coStr->pdwActiveProtocol = dwActiveProtocol;
 
 		if (coStr->rv == SCARD_S_SUCCESS)
 			coStr->rv =
@@ -305,7 +329,8 @@
 
 		rcStr->rv = SCardReconnect(rcStr->hCard, rcStr->dwShareMode,
 			rcStr->dwPreferredProtocols,
-			rcStr->dwInitialization, &rcStr->pdwActiveProtocol);
+			rcStr->dwInitialization, &dwActiveProtocol);
+		rcStr->pdwActiveProtocol = dwActiveProtocol;
 		break;
 
 	case SCARD_DISCONNECT:
@@ -345,37 +370,74 @@
 		stStr = ((status_struct *) msgStruct->data);
 		rv = MSGCheckHandleAssociation(stStr->hCard, dwContextIndex);
 		if (rv != 0) return rv;
+
+		cchReaderLen = stStr->pcchReaderLen;
+		dwState = stStr->pdwState;
+		dwProtocol = stStr->pdwProtocol;
+		cbAtrLen = stStr->pcbAtrLen;
+
 		stStr->rv = SCardStatus(stStr->hCard, stStr->mszReaderNames,
-			&stStr->pcchReaderLen, &stStr->pdwState,
-			&stStr->pdwProtocol, stStr->pbAtr, &stStr->pcbAtrLen);
+			&cchReaderLen, &dwState,
+			&dwProtocol, stStr->pbAtr, &cbAtrLen);
+
+		stStr->pcchReaderLen = cchReaderLen;
+		stStr->pdwState = dwState;
+		stStr->pdwProtocol = dwProtocol;
+		stStr->pcbAtrLen = cbAtrLen;
 		break;
 
 	case SCARD_TRANSMIT:
 		trStr = ((transmit_struct *) msgStruct->data);
 		rv = MSGCheckHandleAssociation(trStr->hCard, dwContextIndex);
 		if (rv != 0) return rv;
-		trStr->rv = SCardTransmit(trStr->hCard, &trStr->pioSendPci,
+
+		ioSendPci.dwProtocol = trStr->pioSendPciProtocol;
+		ioSendPci.cbPciLength = trStr->pioSendPciLength;
+		ioRecvPci.dwProtocol = trStr->pioRecvPciProtocol;
+		ioRecvPci.cbPciLength = trStr->pioRecvPciLength;
+		cbRecvLength = trStr->pcbRecvLength;
+
+		trStr->rv = SCardTransmit(trStr->hCard, &ioSendPci,
 			trStr->pbSendBuffer, trStr->cbSendLength,
-			&trStr->pioRecvPci, trStr->pbRecvBuffer,
-			&trStr->pcbRecvLength);
+			&ioRecvPci, trStr->pbRecvBuffer,
+			&cbRecvLength);
+
+		trStr->pioSendPciProtocol = ioSendPci.dwProtocol;
+		trStr->pioSendPciLength = ioSendPci.cbPciLength;
+		trStr->pioRecvPciProtocol = ioRecvPci.dwProtocol;
+		trStr->pioRecvPciLength = ioRecvPci.cbPciLength;
+		trStr->pcbRecvLength = cbRecvLength;
+
 		break;
 
 	case SCARD_CONTROL:
 		ctStr = ((control_struct *) msgStruct->data);
 		rv = MSGCheckHandleAssociation(ctStr->hCard, dwContextIndex);
 		if (rv != 0) return rv;
+
+		dwBytesReturned = ctStr->dwBytesReturned;
+
 		ctStr->rv = SCardControl(ctStr->hCard, ctStr->dwControlCode,
 			ctStr->pbSendBuffer, ctStr->cbSendLength,
 			ctStr->pbRecvBuffer, ctStr->cbRecvLength,
-			&ctStr->dwBytesReturned);
+			&dwBytesReturned);
+
+		ctStr->dwBytesReturned = dwBytesReturned;
+
 		break;
 
 	case SCARD_GET_ATTRIB:
 		gsStr = ((getset_struct *) msgStruct->data);
 		rv = MSGCheckHandleAssociation(gsStr->hCard, dwContextIndex);
 		if (rv != 0) return rv;
+                
+		cbAttrLen = gsStr->cbAttrLen;
+
 		gsStr->rv = SCardGetAttrib(gsStr->hCard, gsStr->dwAttrId,
-			gsStr->pbAttr, &gsStr->cbAttrLen);
+			gsStr->pbAttr, &cbAttrLen);
+
+		gsStr->cbAttrLen = cbAttrLen;
+
 		break;
 
 	case SCARD_SET_ATTRIB:
@@ -415,10 +477,22 @@
 			else
 				memcpy(pbSendBuffer, treStr->data, treStr->cbSendLength);
 
-			treStr->rv = SCardTransmit(treStr->hCard, &treStr->pioSendPci,
+			ioSendPci.dwProtocol = treStr->pioSendPciProtocol;
+			ioSendPci.cbPciLength = treStr->pioSendPciLength;
+			ioRecvPci.dwProtocol = treStr->pioRecvPciProtocol;
+			ioRecvPci.cbPciLength = treStr->pioRecvPciLength;
+			cbRecvLength = treStr->pcbRecvLength;
+
+			treStr->rv = SCardTransmit(treStr->hCard, &ioSendPci,
 				pbSendBuffer, treStr->cbSendLength,
-				&treStr->pioRecvPci, pbRecvBuffer,
-				&treStr->pcbRecvLength);
+				&ioRecvPci, pbRecvBuffer,
+				&cbRecvLength);
+
+			treStr->pioSendPciProtocol = ioSendPci.dwProtocol;
+			treStr->pioSendPciLength = ioSendPci.cbPciLength;
+			treStr->pioRecvPciProtocol = ioRecvPci.dwProtocol;
+			treStr->pioRecvPciLength = ioRecvPci.cbPciLength;
+			treStr->pcbRecvLength = cbRecvLength;
 
 			treStr->size = sizeof(*treStr) + treStr->pcbRecvLength;
 			if (treStr->size > PCSCLITE_MAX_MESSAGE_SIZE)
@@ -484,10 +558,14 @@
 			else
 				memcpy(pbSendBuffer, cteStr->data, cteStr->cbSendLength);
 
+			dwBytesReturned = cteStr->pdwBytesReturned;
+
 			cteStr->rv = SCardControl(cteStr->hCard, cteStr->dwControlCode,
 				pbSendBuffer, cteStr->cbSendLength,
 				pbRecvBuffer, cteStr->cbRecvLength,
-				&cteStr->pdwBytesReturned);
+				&dwBytesReturned);
+
+			cteStr->pdwBytesReturned = dwBytesReturned;
 
 			cteStr->size = sizeof(*cteStr) + cteStr->pdwBytesReturned;
 			if (cteStr->size > PCSCLITE_MAX_MESSAGE_SIZE)

Modified: trunk/PCSC/src/winscard_svc.h
URL: http://svn.debian.org/wsvn/pcsclite/trunk/PCSC/src/winscard_svc.h?rev=2635&op=diff
==============================================================================
--- trunk/PCSC/src/winscard_svc.h (original)
+++ trunk/PCSC/src/winscard_svc.h Tue Oct  9 15:01:07 2007
@@ -22,7 +22,7 @@
 {
 #endif
 	LONG ContextsInitialize(void);
-	LONG CreateContextThread(PDWORD);
+	LONG CreateContextThread(uint32_t *);
 #ifdef __cplusplus
 }
 #endif




More information about the Pcsclite-cvs-commit mailing list