www.pudn.com > agsm2-1.2_src.zip > parseATR.h


#define MAXIMUM_ATR_CODES					4 
#define MAXIMUM_ATR_LENGTH				33 
#define MHZ * 1000000l 
#define TR ((ULONG)(1000l * 1000l)) 
 
#define SCARD_PROTOCOL_UNDEFINED    0x00000000  // There is no active protocol. 
#define SCARD_PROTOCOL_T0           0x00000001  // T=0 is the active protocol. 
#define SCARD_PROTOCOL_T1           0x00000002  // T=1 is the active protocol. 
#define SCARD_PROTOCOL_RAW          0x00010000  // Raw is the active protocol. 
 
// 
// Error detection bit as defined by ISO  
// 
#define T1_CRC_CHECK		1 
// 
// Character waiting integer default value as definded by ISO 
// 
#define T1_CWI_DEFAULT		13 
// 
// Block waiting integer default value as definded by ISO 
// 
#define T1_BWI_DEFAULT		4 
// 
// The clock rate conversion table itself. 
// All R(eserved)F(or Future)U(se) fields MUST be 0 
// 
typedef struct _CLOCK_RATE_CONVERSION { 
 
	ULONG F; 
	ULONG fs;  
 
} CLOCK_RATE_CONVERSION, *PCLOCK_RATE_CONVERSION; 
 
// 
// Bit rate adjustment factor  
// The layout of this table has been slightly modified due to  
// the unavailibility of floating point math support in the kernel. 
// The value D has beed devided into a numerator and a divisor. 
// 
typedef struct _BIT_RATE_ADJUSTMENT { 
 
	ULONG DNumerator; 
	ULONG DDivisor; 
 
} BIT_RATE_ADJUSTMENT, *PBIT_RATE_ADJUSTMENT; 
 
// 
// structure used for protocol type selection (PTS) 
// 
typedef struct _PTS_DATA { 
 
#define PTS_TYPE_DEFAULT 0x00 
#define PTS_TYPE_OPTIMAL 0x01 
#define PTS_TYPE_USER    0x02 
 
    UCHAR Type; 
 
    // Fl value for PTS 
    UCHAR Fl; 
 
    // Dl value for PTS 
    UCHAR Dl;     	 
 
    // New clock frequency 
    ULONG CLKFrequency; 
 
    // New baud rate to be used after pts 
    ULONG DataRate; 
 
    // new stop bits to be used after pts 
    UCHAR StopBits; 
 
} PTS_DATA, *PPTS_DATA; 
 
 
static CLOCK_RATE_CONVERSION ClockRateConversion[] = { 
 
		{ 372, 	4 MHZ	},  
		{ 372, 	5 MHZ	},  
		{ 558, 	6 MHZ	},  
		{ 744, 	8 MHZ	},  
		{ 1116, 12 MHZ	},  
		{ 1488, 16 MHZ	}, 
		{ 1860, 20 MHZ	}, 
		{ 0, 	0		}, 
		{ 0, 	0		}, 
		{ 512, 	5 MHZ	}, 
		{ 768, 	7500000	}, 
		{ 1024, 10 MHZ	}, 
		{ 1536, 15 MHZ	}, 
		{ 2048, 20 MHZ	}, 
		{ 0, 	0		}, 
		{ 0, 	0		} 
};		 
 
#undef MHZ 
 
// 
// The bit rate adjustment table itself. 
// All R(eserved)F(or)U(se) fields MUST be 0 
// 
static BIT_RATE_ADJUSTMENT BitRateAdjustment[] = { 
 
	{ 0,	0	}, 
	{ 1,	1	}, 
	{ 2,	1	}, 
	{ 4,	1	}, 
	{ 8,	1	}, 
	{ 16,	1	}, 
	{ 32,	1	}, 
	{ 0,	0	}, 
	{ 12,	1	}, 
	{ 20,	1	}, 
	{ 1,	2	}, 
	{ 1,	4	}, 
	{ 1,	8	}, 
	{ 1,	16	}, 
	{ 1,	32	}, 
	{ 1,	64	} 
}; 
 
typedef struct _SCARD_CARD_CAPABILITIES{ 
 
	// Flag that indicates that the current card uses invers convention 
	BOOLEAN InversConvention; 
 
	// Calculated etu  
	ULONG	etu; 
       
    // 
    // Answer To Reset string returned by card. 
    // Use OsData->SpinLock to access this member 
    // 
	struct { 
 
		UCHAR Buffer[64]; 
		UCHAR Length; 
 
	} ATR; 
 
	struct { 
 
		UCHAR Buffer[16]; 
		UCHAR Length; 
 
	} HistoricalChars; 
 
    // !!! DO NOT MODIFY ANY OF THE BELOW VALUES 
    // OTHERWISE THE LIBRARY WON'T WORK PROPERLY 
 
	// 
	// The following 2 tables are provided to give  
	// the driver access to the ISO definitions 
	// 
	PCLOCK_RATE_CONVERSION 	ClockRateConversion; 
	PBIT_RATE_ADJUSTMENT 	BitRateAdjustment; 
 
	// Clock rate conversion  
	UCHAR Fl; 
 
	// Bit rate adjustment 
	UCHAR Dl; 
 
	// Maximum programming current 
	UCHAR II; 
 
	// Programming voltage in .1 Volts 
	UCHAR P; 
 
	// Extra guard time in etu  
	UCHAR N; 
 
	// Calculated guard time in micro seconds 
	ULONG GT; 
 
	struct { 
 
		// This is a bit mask of the supported protocols 
		ULONG Supported; 
		// The currently selected protocol 
		ULONG Selected; 
 
	} Protocol; 
 
	// T=0 specific data 
	struct { 
 
		// Waiting integer 
		UCHAR WI; 
 
		// Waiting time in micro seconds 
		ULONG WT; 
 
	} T0; 
 
	// T=1 specific data 
	struct { 
 
		// Information field size of card 
		UCHAR IFSC; 
 
		// Character waiting integer and block waiting integer 
		UCHAR CWI; 
		UCHAR BWI; 
 
		// Error detection code 
		UCHAR EDC; 
 
		// Character and block waiting time in micro seconds 
		ULONG CWT; 
		ULONG BWT; 
 
		// Block guarding time in micro seconds 
		ULONG BGT; 
 
	} T1; 
 
    PTS_DATA PtsData; 
 
    UCHAR Reserved[100 - sizeof(PTS_DATA)]; 
 
} SCARD_CARD_CAPABILITIES, *PSCARD_CARD_CAPABILITIES; 
 
CString parseATR( 
    PUCHAR atrString, ULONG atrLength,PSCARD_CARD_CAPABILITIES cardCapabilities ,ULONG fs=0 
    );