[Pcsclite-cvs-commit] r1857 - trunk/Drivers/ccid/src

Ludovic Rousseau rousseau at costa.debian.org
Mon Feb 6 15:14:02 UTC 2006


Author: rousseau
Date: 2006-02-06 15:14:01 +0000 (Mon, 06 Feb 2006)
New Revision: 1857

Modified:
   trunk/Drivers/ccid/src/commands.c
Log:
SecurePINVerify(): add support of T=1 cards with TPDU readers


Modified: trunk/Drivers/ccid/src/commands.c
===================================================================
--- trunk/Drivers/ccid/src/commands.c	2006-02-06 15:08:53 UTC (rev 1856)
+++ trunk/Drivers/ccid/src/commands.c	2006-02-06 15:14:01 UTC (rev 1857)
@@ -25,6 +25,7 @@
 #include <stdlib.h>
 #include <pcsclite.h>
 #include <ifdhandler.h>
+#include <reader.h>
 
 #include "commands.h"
 #include "openct/proto-t1.h"
@@ -39,6 +40,7 @@
 #define BOGUS_PINPAD_FIRMWARE
 
 #define max( a, b )   ( ( ( a ) > ( b ) ) ? ( a ) : ( b ) )
+#define offsetof(TYPE, MEMBER) ((size_t) &((TYPE *)0)->MEMBER)
 
 /* internal functions */
 static RESPONSECODE CmdXfrBlockTPDU_T0(unsigned int reader_index,
@@ -244,6 +246,31 @@
 		}
 	}
 
+	/* T=1 Protocol Management for a TPDU reader */
+	if ((SCARD_PROTOCOL_T1 == ccid_descriptor->cardProtocol)
+		&& (CCID_CLASS_TPDU == (ccid_descriptor->dwFeatures & CCID_CLASS_EXCHANGE_MASK)))
+	{
+		ct_buf_t sbuf;
+		unsigned char sdata[T1_BUFFER_SIZE];
+
+		/* Initialize send buffer with the APDU */
+		ct_buf_set(&sbuf,
+			(void *)(TxBuffer + offsetof(PIN_VERIFY_STRUCTURE, abData)),
+			TxLength - offsetof(PIN_VERIFY_STRUCTURE, abData));
+
+		/* Create T=1 block */  
+		ret = t1_build(&((get_ccid_slot(reader_index))->t1),
+			sdata, 0, T1_I_BLOCK, &sbuf, NULL); 
+
+		/* Increment the sequence numbers  */
+		get_ccid_slot(reader_index)->t1.ns ^= 1;
+		get_ccid_slot(reader_index)->t1.nr ^= 1;
+
+		/* Copy the generated T=1 block prologue into the teoprologue
+		 * of the CCID command */
+		memcpy(cmd+22, sdata, 3);
+	}
+
 	i2dw(a - 10, cmd + 1);  /* CCID message length */
 
 	old_read_timeout = ccid_descriptor -> readTimeout;
@@ -257,6 +284,16 @@
 
 	ret = CCID_Receive(reader_index, RxLength, RxBuffer);
 
+	/* T=1 Protocol Management for a TPDU reader */
+	if ((SCARD_PROTOCOL_T1 == ccid_descriptor->cardProtocol)
+		&& (CCID_CLASS_TPDU == (ccid_descriptor->dwFeatures & CCID_CLASS_EXCHANGE_MASK)))
+	{
+		/* get only the T=1 data */
+		/* FIXME: manage T=1 error blocks */
+		memmove(RxBuffer, RxBuffer+3, *RxLength -4);
+		*RxLength -= 4;	/* remove NAD, PCB, LEN and CRC */
+	}
+
 	ccid_descriptor -> readTimeout = old_read_timeout;
 	return ret;
 } /* SecurePINVerify */




More information about the Pcsclite-cvs-commit mailing list