[SmartcardServices-Changes] [26] trunk/SmartCardServices/src/PCSC
source_changes at macosforge.org
source_changes at macosforge.org
Tue Jul 28 04:04:18 PDT 2009
Revision: 26
http://trac.macosforge.org/projects/smartcardservices/changeset/26
Author: ludovic.rousseau at gmail.com
Date: 2009-07-28 04:04:18 -0700 (Tue, 28 Jul 2009)
Log Message:
-----------
reformat and resynch comments with pcsc-lite
Modified Paths:
--------------
trunk/SmartCardServices/src/PCSC/atrhandler.c
trunk/SmartCardServices/src/PCSC/atrhandler.h
Modified: trunk/SmartCardServices/src/PCSC/atrhandler.c
===================================================================
--- trunk/SmartCardServices/src/PCSC/atrhandler.c 2009-07-21 22:41:58 UTC (rev 25)
+++ trunk/SmartCardServices/src/PCSC/atrhandler.c 2009-07-28 11:04:18 UTC (rev 26)
@@ -28,6 +28,16 @@
********************************************************************/
+/**
+ * @file
+ *
+ * @brief This keeps track of smartcard protocols, timing issues
+ * and ATR (Answer-to-Reset) handling.
+ *
+ * @note use ./configure --enable-debugatr to enable debug messages
+ * to be logged.
+ */
+
#include <syslog.h>
#include <string.h>
@@ -36,17 +46,23 @@
#include "pcsclite.h"
#include "atrhandler.h"
-/*
+/**
* Uncomment the following for ATR debugging
+ * or use ./configure --enable-debugatr
*/
-/*
- * #define ATR_DEBUG 1
- */
+/* #define ATR_DEBUG */
+/**
+ * @brief parse an ATR
+ *
+ * @param[out] psExtension
+ * @param[in] pucAtr ATR
+ * @param[in] dwLength ATR length
+ * @return
+ */
short ATRDecodeAtr(PSMARTCARD_EXTENSION psExtension,
const unsigned char *pucAtr, DWORD dwLength)
{
-
USHORT p;
UCHAR K, TCK; /* MSN of T0/Check Sum */
UCHAR Y1i, T; /* MSN/LSN of TDi */
@@ -58,33 +74,31 @@
p = K = TCK = Y1i = T = TAi = TBi = TCi = TDi = 0;
if (dwLength < 2)
- {
- return 0; /* Atr must have TS and T0 */
- }
+ return 0; /** @retval 0 Atr must have TS and T0 */
/*
* Zero out the bitmasks
*/
-
psExtension->CardCapabilities.AvailableProtocols = 0x00;
psExtension->CardCapabilities.CurrentProtocol = 0x00;
/*
* Decode the TS byte
*/
-
if (pucAtr[0] == 0x3F)
{ /* Inverse convention used */
- psExtension->CardCapabilities.Convention =
- SCARD_CONVENTION_INVERSE;
- } else if (pucAtr[0] == 0x3B)
- { /* Direct convention used */
- psExtension->CardCapabilities.Convention = SCARD_CONVENTION_DIRECT;
- } else
- {
- memset(psExtension, 0x00, sizeof(SMARTCARD_EXTENSION));
- return 0;
+ psExtension->CardCapabilities.Convention = SCARD_CONVENTION_INVERSE;
}
+ else
+ if (pucAtr[0] == 0x3B)
+ { /* Direct convention used */
+ psExtension->CardCapabilities.Convention = SCARD_CONVENTION_DIRECT;
+ }
+ else
+ {
+ memset(psExtension, 0x00, sizeof(SMARTCARD_EXTENSION));
+ return 0; /** @retval 0 Unable to decode TS byte */
+ }
/*
* Here comes the platform dependant stuff
@@ -99,14 +113,13 @@
p = 2;
#ifdef ATR_DEBUG
- debug_msg("Conv %02X, Y1 %02X, K %02X",
+ debug_msg("Conv: %02X, Y1: %02X, K: %02X",
psExtension->CardCapabilities.Convention, Y1i, K);
#endif
/*
* Examine Y1
*/
-
do
{
@@ -135,61 +148,49 @@
{
switch (T)
{
- case 0:
- psExtension->CardCapabilities.CurrentProtocol =
- SCARD_PROTOCOL_T0;
- break;
- case 1:
- psExtension->CardCapabilities.CurrentProtocol =
- SCARD_PROTOCOL_T1;
- break;
- default:
- return 0;
+ case 0:
+ psExtension->CardCapabilities.CurrentProtocol =
+ SCARD_PROTOCOL_T0;
+ break;
+ case 1:
+ psExtension->CardCapabilities.CurrentProtocol =
+ SCARD_PROTOCOL_T1;
+ break;
+ default:
+ return 0; /** @retval 0 Unable to decode LNS */
}
}
- if (T == 0)
- {
#ifdef ATR_DEBUG
- debug_msg("T=0 Protocol Found");
+ debug_msg("T=%d Protocol Found", T);
#endif
- psExtension->CardCapabilities.AvailableProtocols |=
- SCARD_PROTOCOL_T0;
- psExtension->CardCapabilities.T0.BGT = 0;
- psExtension->CardCapabilities.T0.BWT = 0;
- psExtension->CardCapabilities.T0.CWT = 0;
- psExtension->CardCapabilities.T0.CGT = 0;
- psExtension->CardCapabilities.T0.WT = 0;
- } else if (T == 1)
+ if (0 == T)
{
-#ifdef ATR_DEBUG
- debug_msg("T=1 Protocol Found");
-#endif
psExtension->CardCapabilities.AvailableProtocols |=
- SCARD_PROTOCOL_T1;
- psExtension->CardCapabilities.T1.BGT = 0;
- psExtension->CardCapabilities.T1.BWT = 0;
- psExtension->CardCapabilities.T1.CWT = 0;
- psExtension->CardCapabilities.T1.CGT = 0;
- psExtension->CardCapabilities.T1.WT = 0;
- } else
- {
- psExtension->CardCapabilities.AvailableProtocols |= T;
- /*
- * Do nothing for now since other protocols are not
- * supported at this time
- */
+ SCARD_PROTOCOL_T0;
}
+ else
+ if (1 == T)
+ {
+ psExtension->CardCapabilities.AvailableProtocols |=
+ SCARD_PROTOCOL_T1;
+ }
+ else
+ {
+ psExtension->CardCapabilities.AvailableProtocols |= T;
+ /*
+ * Do nothing for now since other protocols are not
+ * supported at this time
+ */
+ }
} else
- {
Y1i = 0;
- }
if (p > MAX_ATR_SIZE)
{
memset(psExtension, 0x00, sizeof(SMARTCARD_EXTENSION));
- return 0;
+ return 0; /** @retval 0 Maximum attribute size */
}
}
@@ -201,14 +202,12 @@
if (psExtension->CardCapabilities.CurrentProtocol == 0x00)
{
psExtension->CardCapabilities.CurrentProtocol = SCARD_PROTOCOL_T0;
- psExtension->CardCapabilities.AvailableProtocols |=
- SCARD_PROTOCOL_T0;
+ psExtension->CardCapabilities.AvailableProtocols |= SCARD_PROTOCOL_T0;
}
/*
* Take care of the historical characters
*/
-
psExtension->ATR.HistoryLength = K;
memcpy(psExtension->ATR.HistoryValue, &pucAtr[p], K);
@@ -218,15 +217,11 @@
* Check to see if TCK character is included It will be included if
* more than T=0 is supported
*/
-
- if (psExtension->CardCapabilities.AvailableProtocols &
- SCARD_PROTOCOL_T1)
- {
+ if (psExtension->CardCapabilities.AvailableProtocols & SCARD_PROTOCOL_T1)
TCK = pucAtr[p++];
- }
memcpy(psExtension->ATR.Value, pucAtr, p);
psExtension->ATR.Length = p; /* modified from p-1 */
- return 1;
+ return 1; /** @retval 1 Success */
}
Modified: trunk/SmartCardServices/src/PCSC/atrhandler.h
===================================================================
--- trunk/SmartCardServices/src/PCSC/atrhandler.h 2009-07-21 22:41:58 UTC (rev 25)
+++ trunk/SmartCardServices/src/PCSC/atrhandler.h 2009-07-28 11:04:18 UTC (rev 26)
@@ -28,6 +28,12 @@
********************************************************************/
+/**
+ * @file
+ * @brief This keeps track of smartcard protocols, timing issues
+ * and Answer to Reset ATR handling.
+ */
+
#ifndef __atrhandler_h__
#define __atrhandler_h__
@@ -44,64 +50,25 @@
struct _ATR
{
- DWORD Length;
+ int Length;
+ int HistoryLength;
UCHAR Value[MAX_ATR_SIZE];
- DWORD HistoryLength;
UCHAR HistoryValue[MAX_ATR_SIZE];
}
ATR;
- DWORD ReadTimeout;
-
struct _CardCapabilities
{
UCHAR AvailableProtocols;
UCHAR CurrentProtocol;
UCHAR Convention;
- USHORT ETU;
-
- struct _PtsData
- {
- UCHAR F1;
- UCHAR D1;
- UCHAR I1;
- UCHAR P1;
- UCHAR N1;
- }
- PtsData;
-
- struct _T1
- {
- USHORT BGT;
- USHORT BWT;
- USHORT CWT;
- USHORT CGT;
- USHORT WT;
- }
- T1;
-
- struct _T0
- {
- USHORT BGT;
- USHORT BWT;
- USHORT CWT;
- USHORT CGT;
- USHORT WT;
- }
- T0;
-
}
CardCapabilities;
-
- /*
- * PREADER_CONNECTION psReaderConnection;
- */
-
}
SMARTCARD_EXTENSION, *PSMARTCARD_EXTENSION;
/*
- * Decodes the ATR and fills the structure
+ * Decodes the ATR and fills the structure
*/
short ATRDecodeAtr(PSMARTCARD_EXTENSION psExtension,
@@ -111,4 +78,4 @@
}
#endif
-#endif /* __smclib_h__ */
+#endif /* __atrhandler_h__ */
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/smartcardservices-changes/attachments/20090728/cef4f47b/attachment.html>
More information about the SmartcardServices-Changes
mailing list