2011/6/14 Johannes Becker <johannes.bec...@hrz.uni-giessen.de>:
> Am Sonntag 12 Juni 2011 schrieb MAK:
>> Hello,
>>
>> i have the problem that running "opensc-tool -w -a" gives immediately a
>> timeout if no card is present in the reader.
> ...
>
>> I am running opensc-0.12.0, pcsc-lite-1.7.2 and ccid-1.4.4 on a FreeBSD
>> 8.2-RELEASE system.
>
> It's the same fault with other readers as well with
>  Debian stable amd64,
>  opensc-0.12.2-svn
>  libpcsclite1  1.5.5-4
>  libccid 1.4.3-1
>
> On the other hand waiting works on Windows.
> Also waiting with the perl modules
>  Chipcard::PCSC
>  Chipcard::PCSC::Card
> works on Linux.

It is a bug in OpenSC.
Patch attached and also available at [1].

Martin, please pull my master into your repository.

Bye

[1] 
https://github.com/LudovicRousseau/OpenSC/commit/8936901e2b8fade5d9831b224f3313b7b3255133

-- 
 Dr. Ludovic Rousseau
From 8936901e2b8fade5d9831b224f3313b7b3255133 Mon Sep 17 00:00:00 2001
From: Ludovic Rousseau <ludovic.rousseau+git...@gmail.com>
Date: Tue, 14 Jun 2011 13:50:37 +0200
Subject: [PATCH 6/6] Correctly wait for card event

The timeout parameter of SCardGetStatusChange() is a DWORD (unsigned
int). An int timeout parameter was used instead.
The problem happens on 64-bits architectures where DWORD is 64-bits long
and int is only 32-bits long. The sign extension C mechanism transforms
the PC/SC value INFINITE into -1 instead of 4294967295.

See http://www.opensc-project.org/pipermail/opensc-devel/2011-June/016831.html
"Kobil KAAN Advanced Reader, "waiting for card" timeout"
---
 src/libopensc/reader-pcsc.c |    7 +++++--
 1 files changed, 5 insertions(+), 2 deletions(-)

diff --git a/src/libopensc/reader-pcsc.c b/src/libopensc/reader-pcsc.c
index 1071e04..a42df46 100644
--- a/src/libopensc/reader-pcsc.c
+++ b/src/libopensc/reader-pcsc.c
@@ -1029,6 +1029,7 @@ static int pcsc_wait_for_event(sc_context_t *ctx, unsigned int event_mask, sc_re
 	size_t i;
 	unsigned int num_watch;
 	int r = SC_ERROR_INTERNAL;
+	DWORD dwtimeout;
 
 	SC_FUNC_CALLED(ctx, SC_LOG_DEBUG_NORMAL);
 
@@ -1167,10 +1168,12 @@ static int pcsc_wait_for_event(sc_context_t *ctx, unsigned int event_mask, sc_re
 
 		/* Set the timeout if caller wants to time out */
 		if (timeout == -1) {
-			timeout = INFINITE;
+			dwtimeout = INFINITE;
 		}
+		else
+			dwtimeout = timeout;
 
-		rv = gpriv->SCardGetStatusChange(gpriv->pcsc_wait_ctx, timeout, rgReaderStates, num_watch);
+		rv = gpriv->SCardGetStatusChange(gpriv->pcsc_wait_ctx, dwtimeout, rgReaderStates, num_watch);
 
 		if (rv == (LONG) SCARD_E_CANCELLED) {
 			/* C_Finalize was called, events don't matter */
-- 
1.7.2.5

_______________________________________________
opensc-devel mailing list
opensc-devel@lists.opensc-project.org
http://www.opensc-project.org/mailman/listinfo/opensc-devel

Reply via email to