[Pcsclite-cvs-commit] PCSC/src winscard_svc.c,1.18,1.19 winscard_msg.h,1.7,1.8 winscard_clnt.c,1.29,1.30

rousseau@haydn.debian.org rousseau@haydn.debian.org


Update of /cvsroot/pcsclite/PCSC/src
In directory haydn:/tmp/cvs-serv21913

Modified Files:
	winscard_svc.c winscard_msg.h winscard_clnt.c 
Log Message:
pcscd and libpcsclite now exchange a protocol version to knwo what API
to use


Index: winscard_svc.c
===================================================================
RCS file: /cvsroot/pcsclite/PCSC/src/winscard_svc.c,v
retrieving revision 1.18
retrieving revision 1.19
diff -u -d -r1.18 -r1.19
--- winscard_svc.c	22 Jan 2004 14:32:07 -0000	1.18
+++ winscard_svc.c	15 Apr 2004 08:43:33 -0000	1.19
@@ -7,6 +7,7 @@
  * Copyright (C) 2001-2004
  *  David Corcoran <corcoran@linuxnet.com>
  *  Damien Sauveron <damien.sauveron@labri.fr>
+ *  Ludovic Rousseau <ludovic.rousseau@free.fr>
  *
  * $Id$
  */
@@ -32,6 +33,7 @@
 	DWORD dwClientID;
 	PCSCLITE_THREAD_T pthThread;	/* Event polling thread */
 	sharedSegmentMsg msgStruct;
+	int protocol_major, protocol_minor;
 } psContext[PCSCLITE_MAX_APPLICATIONS_CONTEXTS];
 
 static DWORD dwNextContextIndex;
@@ -97,7 +99,6 @@
 	sharedSegmentMsg msgStruct;
 	DWORD dwContextIndex = *pdwIndex;
 
-
 	DebugLogB("ContextThread: Thread is started: %d", psContext[dwContextIndex].dwClientID);
 	
 	while (1)
@@ -126,10 +127,33 @@
 				MSGFunctionDemarshall(&msgStruct, dwContextIndex);
 				rv = SHMMessageSend(&msgStruct, psContext[dwContextIndex].dwClientID,
 						    PCSCLITE_SERVER_ATTEMPTS);
-			} else
-			{
-				continue;
 			}
+			else
+				/* pcsc-lite client/server protocol version */
+				if (msgStruct.mtype == CMD_VERSION)
+				{
+					version_struct *veStr;
+					veStr = (version_struct *) msgStruct.data;
+
+					/* get the client protocol version */
+					psContext[dwContextIndex].protocol_major = veStr->major;
+					psContext[dwContextIndex].protocol_minor = veStr->minor;
+
+					DebugLogC("Client is protocol version %d:%d",
+						veStr->major, veStr->minor);
+
+					/* set the server protocol version */
+					veStr->major = PROTOCOL_VERSION_MAJOR;
+					veStr->minor = PROTOCOL_VERSION_MINOR;
+					veStr->rv = SCARD_S_SUCCESS;
+
+					/* send back the response */
+					rv = SHMMessageSend(&msgStruct,
+						psContext[dwContextIndex].dwClientID,
+					    PCSCLITE_SERVER_ATTEMPTS);
+				}
+				else
+					continue;
 
 			break;
 
@@ -155,7 +179,6 @@
 
 LONG MSGFunctionDemarshall(psharedSegmentMsg msgStruct, DWORD dwContextIndex)
 {
-
 	LONG rv;
 	establish_struct *esStr;
 	release_struct *reStr;
@@ -279,14 +302,12 @@
 
 LONG MSGAddContext(SCARDCONTEXT hContext, DWORD dwContextIndex)
 {
-
 	psContext[dwContextIndex].hContext = hContext;
 	return SCARD_S_SUCCESS;
 }
 
 LONG MSGRemoveContext(SCARDCONTEXT hContext, DWORD dwContextIndex)
 {
-
 	int i;
 	LONG rv;
 
@@ -333,7 +354,6 @@
 
 LONG MSGAddHandle(SCARDCONTEXT hContext, SCARDHANDLE hCard, DWORD dwContextIndex)
 {
-
 	int i;
 
 	if (psContext[dwContextIndex].hContext == hContext)
@@ -366,7 +386,6 @@
 
 LONG MSGRemoveHandle(SCARDHANDLE hCard, DWORD dwContextIndex)
 {
-
 	int i;
 
 	for (i = 0; i < PCSCLITE_MAX_APPLICATION_CONTEXT_CHANNELS; i++)
@@ -384,10 +403,8 @@
 
 LONG MSGCheckHandleAssociation(SCARDHANDLE hCard, DWORD dwContextIndex)
 {
-
 	int i;
 
-
 	for (i = 0; i < PCSCLITE_MAX_APPLICATION_CONTEXT_CHANNELS; i++)
 	{
 		if (psContext[dwContextIndex].hCard[i] == hCard)
@@ -405,14 +422,14 @@
 
 LONG MSGCleanupClient(DWORD dwContextIndex)
 {
-
-
 	if (psContext[dwContextIndex].hContext == 0)
 		return 0;
 
 	SCardReleaseContext(psContext[dwContextIndex].hContext);	
 	MSGRemoveContext(psContext[dwContextIndex].hContext, dwContextIndex);
 	psContext[dwContextIndex].dwClientID = 0;
+	psContext[dwContextIndex].protocol_major = 0;
+	psContext[dwContextIndex].protocol_minor = 0;
 	
 	return 0;
 }

Index: winscard_msg.h
===================================================================
RCS file: /cvsroot/pcsclite/PCSC/src/winscard_msg.h,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -d -r1.7 -r1.8
--- winscard_msg.h	14 Apr 2004 14:36:38 -0000	1.7
+++ winscard_msg.h	15 Apr 2004 08:43:33 -0000	1.8
@@ -7,6 +7,7 @@
  * Copyright (C) 2001-2004
  *  David Corcoran <corcoran@linuxnet.com>
  *  Damien Sauveron <damien.sauveron@labri.fr>
+ *  Ludovic Rousseau <ludovic.rousseau@free.fr>
  *
  * $Id$
  */
@@ -14,6 +15,9 @@
 #ifndef __winscard_msg_h__
 #define __winscard_msg_h__
 
+#define PROTOCOL_VERSION_MAJOR 2
+#define PROTOCOL_VERSION_MINOR 0
+
 #ifdef __cplusplus
 extern "C"
 {
@@ -40,7 +44,8 @@
 		CMD_CLIENT_DIED = 0xF4,
 		CMD_READER_EVENT = 0xF5,
 		CMD_SYN = 0xF6,
-		CMD_ACK = 0xF7
+		CMD_ACK = 0xF7,
+		CMD_VERSION = 0xF8
 	};
 
 	enum pcsc_msg_commands
@@ -61,6 +66,14 @@
 		SCARD_CANCEL = 0x0D,
 		SCARD_CANCEL_TRANSACTION = 0x0E
 	};
+
+	struct version_struct
+	{
+		int major;
+		int minor;
+		LONG rv;
+	};
+	typedef struct version_struct version_struct;
 
 	struct client_struct
 	{

Index: winscard_clnt.c
===================================================================
RCS file: /cvsroot/pcsclite/PCSC/src/winscard_clnt.c,v
retrieving revision 1.29
retrieving revision 1.30
diff -u -d -r1.29 -r1.30
--- winscard_clnt.c	31 Mar 2004 09:40:12 -0000	1.29
+++ winscard_clnt.c	15 Apr 2004 08:43:33 -0000	1.30
@@ -128,6 +128,9 @@
 	else
 		*phContext = 0;
 
+	if (SCardCheckDaemonAvailability() != SCARD_S_SUCCESS)
+		return SCARD_E_NO_SERVICE;
+
 	/*
 	 * Do this only once
 	 */
@@ -193,7 +196,6 @@
 			}
 		}
 
-		isExecuted = 1;
 	}
 
 	/*
@@ -217,6 +219,40 @@
 		return SCARD_E_NO_SERVICE;
 	}
 
+	{	/* exchange client/server protocol versions */
+		sharedSegmentMsg msgStruct;
+		version_struct *veStr;
+
+		msgStruct.mtype = CMD_VERSION;
+		msgStruct.user_id = SYS_GetUID();
+		msgStruct.group_id = SYS_GetGID();
+		msgStruct.command = 0;
+		msgStruct.date = time(NULL);
+
+		veStr = (version_struct *) msgStruct.data;
+		veStr->major = PROTOCOL_VERSION_MAJOR;
+		veStr->minor = PROTOCOL_VERSION_MINOR;
+
+		if (-1 == SHMMessageSend(&msgStruct, dwClientID,
+			PCSCLITE_MCLIENT_ATTEMPTS))
+			return SCARD_E_NO_SERVICE;
+
+		/*
+		 * Read a message from the server
+		 */
+		if (-1 == SHMMessageReceive(&msgStruct, dwClientID,
+			PCSCLITE_CLIENT_ATTEMPTS))
+		{
+			DebugLogA("Your pcscd is too old and does not support CMD_VERSION");
+			return SCARD_F_COMM_ERROR;
+		}
+
+		DebugLogC("Server is protocol version %d:%d",
+			veStr->major, veStr->minor);
+
+		isExecuted = 1;
+	}
+
 
 	if (dwScope != SCARD_SCOPE_USER && dwScope != SCARD_SCOPE_TERMINAL &&
 		dwScope != SCARD_SCOPE_SYSTEM && dwScope != SCARD_SCOPE_GLOBAL)
@@ -226,9 +262,6 @@
 
 	scEstablishStruct.dwScope = dwScope;
 	scEstablishStruct.phContext = 0;
-
-	if (SCardCheckDaemonAvailability() != SCARD_S_SUCCESS)
-		return SCARD_E_NO_SERVICE;
 
 	rv = WrapSHMWrite(SCARD_ESTABLISH_CONTEXT, dwClientID,
 		sizeof(scEstablishStruct), PCSCLITE_MCLIENT_ATTEMPTS,