Hello list,

pcsclite contains "testpcsc" which performs some tests.

If I run this tool, my connection to the smartcard
is lost and I need to restart firefox/thunderbird
in order to make it work again :(.

Is this the expected behaviour, that I need to restart
my applications after using "testpcsc" ?



Background
==========

I'm using a stateless pkcs11 smartcard driver which
I installed in thunderbird and firefox.
Reading encrypted mails, surfing with certificates
works fine.
thunderbird/firefox perform their actions on the smartcard
over the statless driver, which locks the card during
the operations and then unlock it.

This is working fine.

Now I run "testpcsc" and during the time when
it issues:

- SCardReconnect
- SCardDisconnect

My connections in thunderbird/firefox are broken
until I restart these applications.

This does not happen when I use opensc drivers, because
they are not stateless and lock the card forever.
Running the "testpcsc" gives a "Sharing violation".

So my question ist:

Is this the correct behaviour, that SCardReconnect/SCardDisconnect
affect every application using the reader? (with stateless drivers)

I would assume, that these operations are only for this
session, but not for all running sessions, but I don't
know the pcsclite specification :-)

I have tested this behaviour with the current pcsc-lite-1.5.5 version,
because it mentions "SCardReconnect" in the changelog.
But it has the same behaviour as the previous release, I need
to restart thunderbird/firefox after "testpcsc"

regards,

Martin

PS: my previous mail did not make it to the list, which conatins
a patch. Here is the patch again:
--- pcsc-lite-1.5.5.org/src/testpcsc.c	2009-07-21 18:54:06.000000000 +0200
+++ pcsc-lite-1.5.5/src/testpcsc.c	2009-12-14 15:29:03.000000000 +0100
@@ -18,6 +18,9 @@
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
+#ifdef HAVE_GETOPT_H
+#include <getopt.h>
+#endif
 
 #include "pcsclite.h"
 #include "winscard.h"
@@ -45,13 +48,24 @@
 		{
 			printf(RED "%s\n" NORMAL, pcsc_stringify_error(rv));
 			(void)SCardReleaseContext(hContext);
-			exit(-1);
+			/* error codes are 4byte even if paramter is long */
+			exit(rv);
 		}
 	}
 	else
 		(void)puts(pcsc_stringify_error(rv));
 }
 
+void usage() {
+  printf("testpcsc performs basic tests on the card reader and smartcard\n");
+  printf("Usage: testpcsc [-t <timeout>] -h\n");
+  printf("\n");
+  printf(" -h : this text\n");
+  printf(" -t : timout for operations in sec. default 0 - waits forever\n");
+  printf("\n");
+}
+    
+
 int main(/*...@unused@*/ int argc, /*...@unused@*/ char **argv)
 {
 	SCARDHANDLE hCard;
@@ -84,7 +98,26 @@
 	unsigned char bSendBuffer[MAX_BUFFER_SIZE];
 	unsigned char bRecvBuffer[MAX_BUFFER_SIZE];
 	DWORD send_length, length;
-
+	int timeout;
+	int opt;
+	timeout=INFINITE;  /* zero */
+#ifdef HAVE_GETOPT_LONG
+	while ((opt = getopt (argc, argv, "ht:")) != -1) {
+
+		switch (opt) {
+		case 't':
+		  timeout=atoi(optarg)*1000;
+		  break;
+		case 'h':
+		  usage();
+		  exit(0);
+		default:
+		  printf ("?? getopt returned character code 0%o ??\n", opt);
+		  usage();
+		  exit(-1);
+		}
+	}
+#endif
 	(void)argc;
 	(void)argv;
 
@@ -151,7 +184,7 @@
 		rgReaderStates[0].szReader = "\\\\?PnP?\\Notification";
 		rgReaderStates[0].dwCurrentState = SCARD_STATE_EMPTY;
 
-		rv = SCardGetStatusChange(hContext, INFINITE, rgReaderStates, 1);
+		rv = SCardGetStatusChange(hContext, timeout, rgReaderStates, 1);
 		test_rv(rv, hContext, PANIC);
 	}
 
@@ -202,7 +235,7 @@
 
 	printf("Waiting for card insertion\t: ");
 	(void)fflush(stdout);
-	rv = SCardGetStatusChange(hContext, INFINITE, rgReaderStates, 1);
+	rv = SCardGetStatusChange(hContext, timeout, rgReaderStates, 1);
 	test_rv(rv, hContext, PANIC);
 	if (rgReaderStates[0].dwEventState & SCARD_STATE_UNKNOWN)
 	{
@@ -390,9 +423,10 @@
 		(void)SCardDisconnect(hCard, SCARD_RESET_CARD);
 		(void)SCardReleaseContext(hContext);
 	}
-
-	printf("Press enter: ");
-	(void)getchar();
+	if (timeout == INFINITE) {
+	  printf("Press enter: ");
+	  (void)getchar();
+	}
 	printf("Testing SCardReconnect\t\t: ");
 	rv = SCardReconnect(hCard, SCARD_SHARE_SHARED,
 		SCARD_PROTOCOL_T0 | SCARD_PROTOCOL_T1, SCARD_UNPOWER_CARD, &dwPref);
_______________________________________________
Muscle mailing list
[email protected]
http://lists.drizzle.com/mailman/listinfo/muscle

Reply via email to