[Pcsclite-cvs-commit] CVS Drivers/ccid/src
CVS User rousseau
ludovic.rousseau@free.fr
Thu, 05 May 2005 09:59:22 +0000
Update of /cvsroot/pcsclite/Drivers/ccid/src
In directory haydn:/tmp/cvs-serv23608
Modified Files:
ifdhandler.c
Log Message:
T0_card_timeout(): declare EGT, WWT as double instead of int to have
some precision
We also calculate EGT and WWT in milliseconds instead of seconds
--- /cvsroot/pcsclite/Drivers/ccid/src/ifdhandler.c 2005/05/04 10:11:28 1.74
+++ /cvsroot/pcsclite/Drivers/ccid/src/ifdhandler.c 2005/05/05 09:59:21 1.75
@@ -17,7 +17,7 @@
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
-/* $Id: ifdhandler.c,v 1.74 2005/05/04 10:11:28 rousseau Exp $ */
+/* $Id: ifdhandler.c,v 1.75 2005/05/05 09:59:21 rousseau Exp $ */
#include <stdio.h>
#include <string.h>
@@ -1168,7 +1168,8 @@
int clock_frequency)
{
unsigned int timeout = DEFAULT_COM_READ_TIMEOUT;
- unsigned int EGT, WWT, t;
+ double EGT, WWT;
+ unsigned int t;
/* Timeout applied on ISO_IN or ISO_OUT card exchange
* we choose the maximum computed value.
@@ -1188,21 +1189,29 @@
* = 5 EGT + 1 WWT + 259 WWT
*/
+ /* clock_frequency is in kHz so the times are in milliseconds and not
+ * in seconds */
+
/* EGT */
/* see ch. 6.5.3 Extra Guard Time, page 12 of ISO 7816-3 */
- EGT = ceil(12 * f / d / (clock_frequency * 1000) + (f / d) * TC1 / (clock_frequency * 1000)); /* seconds */
+ EGT = 12 * f / d / clock_frequency + (f / d) * TC1 / clock_frequency;
/* card WWT */
/* see ch. 8.2 Character level, page 15 of ISO 7816-3 */
- WWT= ceil(262 * (960 * TC2 * f / (clock_frequency * 1000)));
+ WWT = 960 * TC2 * f / clock_frequency;
/* ISO in */
t = 261 * EGT + (3 + 3) * WWT;
+ /* Convert from milliseonds to seconds rouned to the upper value
+ * use +1 instead of ceil() to round up to the nearest interger
+ * so we can avoid a dependency on the math library */
+ t = t/1000 +1;
if (timeout < t)
timeout = t;
/* ISO out */
t = 5 * EGT + (1 + 259) * WWT;
+ t = t/1000 +1;
if (timeout < t)
timeout = t;