[Pcsclite-cvs-commit] Drivers/ccid/examples scardcontrol.c,1.2,1.3

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


Update of /cvsroot/pcsclite/Drivers/ccid/examples
In directory haydn:/tmp/cvs-serv3863/examples

Modified Files:
	scardcontrol.c 
Log Message:
add support for SCardGetAttrib(.., IOCTL_SMARTCARD_VENDOR_VERIFY_PIN, ..)
to know if the reader supports SCardControl(.., IOCTL_SMARTCARD_VENDOR_VERIFY_PIN, ..)


Index: scardcontrol.c
===================================================================
RCS file: /cvsroot/pcsclite/Drivers/ccid/examples/scardcontrol.c,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -d -r1.2 -r1.3
--- scardcontrol.c	24 May 2004 12:58:43 -0000	1.2
+++ scardcontrol.c	25 May 2004 14:46:02 -0000	1.3
@@ -74,6 +74,8 @@
 	unsigned char bSendBuffer[MAX_BUFFER_SIZE];
 	unsigned char bRecvBuffer[MAX_BUFFER_SIZE];
 	DWORD length;
+	char attribute[1];
+	int attribute_length;
 
 	printf("SCardControl sample code\n");
 	printf("V 1.0 2004, Ludovic Rousseau <ludovic.rousseau@free.fr>\n");
@@ -150,7 +152,7 @@
 	else
 		reader_nb = 0;
 
-	/* connect to a card */
+	/* connect to a reader (even without a card) */
 	dwActiveProtocol = -1;
 	rv = SCardConnect(hContext, readers[reader_nb], SCARD_SHARE_DIRECT,
 		SCARD_PROTOCOL_ANY, &hCard, &dwActiveProtocol);
@@ -189,6 +191,18 @@
 	printf("\n");
 	PCSC_ERROR_CONT(rv, "SCardStatus")
 
+	/* does the reader support PIN verification? */
+	attribute_length = sizeof(attribute);
+	rv = SCardGetAttrib(hCard, IOCTL_SMARTCARD_VENDOR_VERIFY_PIN, attribute,
+		&attribute_length);
+	PCSC_ERROR_CONT(rv, "SCardGetAttrib")
+	if (FALSE == attribute[0])
+	{
+		printf("Reader %s does not support PIN verification\n",
+			readers[reader_nb]);
+		goto end;
+	}
+
 	/* verify PIN */
 	printf(" Secure verify PIN\n");
 	offset = 0;
@@ -228,6 +242,8 @@
 	for (i=0; i<offset; i++)
 		printf(" %02X", bSendBuffer[i]);
 	printf("\n");
+	printf("Enter your PIN:");
+	fflush(stdout);
 	rv = SCardControl(hCard, IOCTL_SMARTCARD_VENDOR_VERIFY_PIN, bSendBuffer,
 		offset, bRecvBuffer, sizeof(bRecvBuffer), &length);