[Pcsclite-cvs-commit] r5078 - /trunk/Drivers/ccid/src/ifdhandler.c

rousseau at users.alioth.debian.org rousseau at users.alioth.debian.org
Thu Jul 29 13:30:12 UTC 2010


Author: rousseau
Date: Thu Jul 29 13:30:11 2010
New Revision: 5078

URL: http://svn.debian.org/wsvn/pcsclite/?sc=1&rev=5078
Log:
add get_IFSC() to get the IFSC value from the ATR.

IFSC is not just the value of TAi (i>2)
For example "3B 80 81 1F 07 19" has a TA3 but it is not the IFSC since
T=15 is defined in TD2 so before TA3

Modified:
    trunk/Drivers/ccid/src/ifdhandler.c

Modified: trunk/Drivers/ccid/src/ifdhandler.c
URL: http://svn.debian.org/wsvn/pcsclite/trunk/Drivers/ccid/src/ifdhandler.c?rev=5078&op=diff
==============================================================================
--- trunk/Drivers/ccid/src/ifdhandler.c (original)
+++ trunk/Drivers/ccid/src/ifdhandler.c Thu Jul 29 13:30:11 2010
@@ -68,6 +68,7 @@
 	int clock_frequency);
 static unsigned int T1_card_timeout(double f, double d, int TC1, int BWI,
 	int CWI, int clock_frequency);
+static int get_IFSC(ATR_t *atr, int *i);
 
 
 EXTERNAL RESPONSECODE IFDHCreateChannelByName(DWORD Lun, LPSTR lpcDevice)
@@ -959,6 +960,7 @@
 		t1_state_t *t1 = &(ccid_slot -> t1);
 		RESPONSECODE ret;
 		double f, d;
+		int ifsc;
 
 		/* TA1 is not default */
 		if (PPS_HAS_PPS1(pps))
@@ -1012,17 +1014,12 @@
 			(param[3] & 0xF0) >> 4 /* BWI */, param[3] & 0x0F /* CWI */,
 			ccid_desc->dwDefaultClock);
 
-		/* TAi (i>2) present? IFSC */
-		for (i=2; i<ATR_MAX_PROTOCOLS; i++)
-			if (atr.ib[i][ATR_INTERFACE_BYTE_TA].present)
-			{
-				DEBUG_COMM3("IFSC (TA%d) present: %d", i+1,
-					atr.ib[i][ATR_INTERFACE_BYTE_TA].value);
-				 param[5] = atr.ib[i][ATR_INTERFACE_BYTE_TA].value;
-
-				/* only the first TAi (i>2) must be used */
-				break;
-			}
+		ifsc = get_IFSC(&atr, &i);
+		if (ifsc > 0)
+		{
+			DEBUG_COMM3("IFSC (TA%d) present: %d", i, ifsc);
+			param[5] = ifsc;
+		}
 
 		DEBUG_COMM2("Timeout: %d ms", ccid_desc->readTimeout);
 
@@ -1076,20 +1073,14 @@
 	if (SCARD_PROTOCOL_T1 == Protocol)
 	{
 		t1_state_t *t1 = &(ccid_slot -> t1);
-		int i;
-
-		/* TAi (i>2) present? */
-		for (i=2; i<ATR_MAX_PROTOCOLS; i++)
-			if (atr.ib[i][ATR_INTERFACE_BYTE_TA].present)
-			{
-				DEBUG_COMM3("IFSC (TA%d) present: %d", i+1,
-					atr.ib[i][ATR_INTERFACE_BYTE_TA].value);
-				(void)t1_set_param(t1, IFD_PROTOCOL_T1_IFSC,
-					atr.ib[i][ATR_INTERFACE_BYTE_TA].value);
-
-				/* only the first TAi (i>2) must be used */
-				break;
-			}
+		int i, ifsc;
+
+		ifsc = get_IFSC(&atr, &i);
+		if (ifsc > 0)
+		{
+			DEBUG_COMM3("IFSC (TA%d) present: %d", i, ifsc);
+			(void)t1_set_param(t1, IFD_PROTOCOL_T1_IFSC, ifsc);
+		}
 
 		/* IFSD not negociated by the reader? */
 		if (! (ccid_desc->dwFeatures & CCID_CLASS_AUTO_IFSD))
@@ -2007,3 +1998,32 @@
 	return timeout;
 } /* T1_card_timeout  */
 
+
+static int get_IFSC(ATR_t *atr, int *idx)
+{
+	int i, ifsc, protocol = -1;
+
+	/* default return values */
+	ifsc = -1;
+	*idx = -1;
+
+	for (i=0; i<ATR_MAX_PROTOCOLS; i++)
+	{
+		/* protocol T=? */
+		if (atr->ib[i][ATR_INTERFACE_BYTE_TD].present)
+			protocol = atr->ib[i][ATR_INTERFACE_BYTE_TD].value & 0x0F;
+
+		/* TAi (i>2) present and protocol=1 => IFSC */
+		if (i >= 2 && protocol == 1
+			&& atr->ib[i][ATR_INTERFACE_BYTE_TA].present)
+		{
+			ifsc = atr->ib[i][ATR_INTERFACE_BYTE_TA].value;
+			*idx = i+1;
+			/* only the first TAi (i>2) must be used */
+			break;
+		}
+	}
+
+	return ifsc;
+} /* get_IFSC */
+




More information about the Pcsclite-cvs-commit mailing list