[Pcsclite-cvs-commit] Drivers/ccid/src/towitoko atr.c,1.4,1.5 atr.h,1.3,1.4
rousseau@haydn.debian.org
rousseau@haydn.debian.org
Update of /cvsroot/pcsclite/Drivers/ccid/src/towitoko
In directory haydn:/tmp/cvs-serv10671
Modified Files:
atr.c atr.h
Log Message:
add ATR_GetDefaultProtocol() function
Index: atr.c
===================================================================
RCS file: /cvsroot/pcsclite/Drivers/ccid/src/towitoko/atr.c,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -d -r1.4 -r1.5
--- atr.c 30 Jun 2004 13:53:41 -0000 1.4
+++ atr.c 30 Jun 2004 13:54:57 -0000 1.5
@@ -317,3 +317,41 @@
return (ATR_NOT_FOUND);
}
+/*
+ * This function was greatly inspired by ATRDecodeAtr() and
+ * PHGetDefaultProtocol() from pcsc-lite
+ *
+ * It was rewritten by Ludovic Rousseau, 2004
+ */
+#define PROTOCOL_UNSET -1
+int ATR_GetDefaultProtocol(ATR * atr, int *protocol)
+{
+ int i;
+
+ /* default value */
+ *protocol = PROTOCOL_UNSET;
+
+ for (i=0; i<ATR_MAX_PROTOCOLS; i++)
+ if (atr->ib[i][ATR_INTERFACE_BYTE_TD].present && (PROTOCOL_UNSET == *protocol))
+ {
+ /* set to the first protocol byte found */
+ *protocol = atr->ib[i][ATR_INTERFACE_BYTE_TD].value & 0x0F;
+ DEBUG_COMM2("default protocol: T=%d", *protocol);
+ }
+
+ /* specific mode if TA2 present */
+ if (atr->ib[1][ATR_INTERFACE_BYTE_TA].present)
+ {
+ *protocol = atr->ib[1][ATR_INTERFACE_BYTE_TA].value & 0x0F;
+ DEBUG_COMM2("specific mode found: T=%d", *protocol);
+ }
+
+ if (PROTOCOL_UNSET == *protocol)
+ {
+ DEBUG_CRITICAL("no default protocol found in ATR. Using T=0");
+ *protocol = ATR_PROTOCOL_TYPE_T0;
+ }
+
+ return ATR_OK;
+}
+
Index: atr.h
===================================================================
RCS file: /cvsroot/pcsclite/Drivers/ccid/src/towitoko/atr.h,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -d -r1.3 -r1.4
--- atr.h 30 Jun 2004 13:53:41 -0000 1.3
+++ atr.h 30 Jun 2004 13:54:57 -0000 1.4
@@ -100,6 +100,7 @@
/* General smartcard characteristics */
extern int ATR_GetConvention (ATR * atr, int *convention);
+extern int ATR_GetDefaultProtocol (ATR * atr, int *protocol);
/* ATR parameters and integer values */
extern int ATR_GetIntegerValue (ATR * atr, int name, BYTE * value);