[Pcsclite-cvs-commit] Drivers/ccid/src ccid_serial.c,1.28,1.29

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


Update of /cvsroot/pcsclite/Drivers/ccid/src
In directory haydn:/tmp/cvs-serv27446

Modified Files:
	ccid_serial.c 
Log Message:
use a dynamic timeout when reading the serial port.

The first timeout use when detecting the reader is 2 seconds to not wait
too long if no reader is connected. Later timeouts are set to 1 minute
to allow long time APDU.


Index: ccid_serial.c
===================================================================
RCS file: /cvsroot/pcsclite/Drivers/ccid/src/ccid_serial.c,v
retrieving revision 1.28
retrieving revision 1.29
diff -u -d -r1.28 -r1.29
--- ccid_serial.c	4 Aug 2004 21:30:14 -0000	1.28
+++ ccid_serial.c	6 Aug 2004 10:19:48 -0000	1.29
@@ -1,6 +1,6 @@
 /*
  * ccid_serial.c: communicate with a GemPC Twin smart card reader
- * Copyright (C) 2001-2003 Ludovic Rousseau <ludovic.rousseau@free.fr>
+ * Copyright (C) 2001-2004 Ludovic Rousseau <ludovic.rousseau@free.fr>
  *
  * Thanks to Niki W. Waibel <niki.waibel@gmx.net> for a prototype version
  * 
@@ -42,8 +42,9 @@
 #include "utils.h"
 #include "commands.h"
 
-/* communication timeout in seconds */
-#define SERIAL_TIMEOUT 2
+/* communication timeout in seconds
+ * the value is set at the end of OpenSerialByName() */
+int SerialTimeout;
 
 #define SYNC 0x03
 #define CTRL_ACK 0x06
@@ -402,7 +403,7 @@
 		/* use select() to, eventually, timeout */
 		FD_ZERO(&fdset);
 		FD_SET(fd, &fdset);
-		t.tv_sec = SERIAL_TIMEOUT;
+		t.tv_sec = SerialTimeout;
 		t.tv_usec = 0;
 
 		i = select(fd+1, &fdset, NULL, NULL, &t);
@@ -414,7 +415,7 @@
 		else
 			if (i == 0)
 			{
-				DEBUG_COMM2("Timeout! (%d sec)", SERIAL_TIMEOUT);
+				DEBUG_COMM2("Timeout! (%d sec)", SerialTimeout);
 				return -1;
 			}
 
@@ -572,12 +573,18 @@
 		unsigned char rx_buffer[50];
 		unsigned int rx_length = sizeof(rx_buffer);
 
+		/* 2 seconds timeout to not wait too long if no reader is connected */
+		SerialTimeout = 2;
+
 		if (IFD_SUCCESS != CmdEscape(reader_index, tx_buffer, sizeof(tx_buffer),
 			rx_buffer, &rx_length))
 		{
-			DEBUG_CRITICAL("Get firmware failed. Maybe the reader is not co,,ected");
+			DEBUG_CRITICAL("Get firmware failed. Maybe the reader is not connected");
 			return STATUS_UNSUCCESSFUL;
 		}
+
+		/* normal timeout: 1 minute to allow long time APDU */
+		SerialTimeout = 60;
 
 		rx_buffer[rx_length] = '\0';
 		DEBUG_INFO2("Firmware: %s", rx_buffer);