[Pcsclite-cvs-commit] CVS Drivers/ccid/src

CVS User rousseau ludovic.rousseau@free.fr
Thu, 05 May 2005 10:01:18 +0000


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

Modified Files:
	ifdhandler.c 
Log Message:
T0_card_timeout(): use intermediate variables EGT, BWT, CWT, etu to
improve code readability


--- /cvsroot/pcsclite/Drivers/ccid/src/ifdhandler.c	2005/05/05 09:59:21	1.75
+++ /cvsroot/pcsclite/Drivers/ccid/src/ifdhandler.c	2005/05/05 10:01:17	1.76
@@ -17,7 +17,7 @@
     Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307  USA
 */
 
-/* $Id: ifdhandler.c,v 1.75 2005/05/05 09:59:21 rousseau Exp $ */
+/* $Id: ifdhandler.c,v 1.76 2005/05/05 10:01:17 rousseau Exp $ */
 
 #include <stdio.h>
 #include <string.h>
@@ -1222,6 +1222,7 @@
 static unsigned int T1_card_timeout(double f, double d, int TC1,
 	int BWI, int CWI, int clock_frequency)
 {
+	double EGT, BWT, CWT, etu;
 	unsigned int timeout;
 
 	/* Timeout applied on ISO in + ISO out card exchange
@@ -1234,17 +1235,30 @@
 	 *   card and the last one (NAD PCB LN DATAS CKS) = 260 CWT.   
 	 */
 
+	/* clock_frequency is in kHz so the times are in milliseconds and not
+	 * in seconds */
+
+	/* see ch. 6.5.2 Transmission factors F and D, page 12 of ISO 7816-3 */
+	etu = f / d / clock_frequency;
+
 	/* EGT */
 	/* see ch. 6.5.3 Extra Guard Time, page 12 of ISO 7816-3 */
-	timeout = 260 * ceil(12 * f / d / (clock_frequency * 1000) + (f / d) * TC1 / (clock_frequency * 1000));   /* seconds  */
+	EGT = 12 * etu + (f / d) * TC1 / clock_frequency;
 
 	/* card BWT */
-	/* see ch. 9.5.3.2 Block waiting time, page 20 of ISO 7816-3 */
-	timeout += ceil(11 * f / d / (clock_frequency * 1000) + (1<<BWI) * 960 * 372 / (clock_frequency * 1000));	/* seconds  */
+	/* see ch. 9.5.3.2 Block Waiting Time, page 20 of ISO 7816-3 */
+	BWT = 11 * etu + (1<<BWI) * 960 * 372 / clock_frequency;
 
 	/* card CWT */
-	/* see ch. 9.5.3.2 Block waiting time, page 19 of ISO 7816-3 */
-	timeout += 260 * ceil((11 + (1<<CWI)) * f / d / (clock_frequency * 1000));   /* seconds  */
+	/* see ch. 9.5.3.1 Caracter Waiting Time, page 20 of ISO 7816-3 */
+	CWT = (11 + (1<<CWI)) * etu;
+
+	timeout = 260*EGT + BWT + 260*CWT;
+
+	/* Convert from milliseonds to seconds rounded to the upper value
+	 * we use +1 instead of ceil() to round up to the nearest greater interger
+	 * so we can avoid a dependency on the math library */
+	timeout = timeout/1000 +1;
 
 	return timeout;
 } /* T1_card_timeout  */