2
/******************************************************************
4
MUSCLE SmartCard Development ( http://www.linuxnet.com )
7
Author : David Corcoran
9
License: Copyright (C) 1999 David Corcoran
10
<corcoran@linuxnet.com>
11
Purpose: This is a test program for pcsc-lite.
13
********************************************************************/
22
/* #define REPEAT_TEST 1 */
24
int main( int argc, char **argv ) {
25
SCARDHANDLE hCard; SCARDCONTEXT hContext;
26
SCARD_READERSTATE_A rgReaderStates[1];
27
unsigned long dwReaderLen, dwState, dwProt, dwAtrLen;
28
//unsigned long dwSendLength, dwRecvLength;
29
unsigned long dwPref, dwReaders;
30
char *pcReaders, *mszReaders;
31
unsigned char pbAtr[MAX_ATR_SIZE];
32
const char * mszGroups;
39
printf("\nMUSCLE PC/SC Lite Test Program\n\n");
41
printf("Testing SCardEstablishContext : ");
42
rv = SCardEstablishContext( SCARD_SCOPE_SYSTEM, NULL, NULL, &hContext );
44
printf("%s\n", pcsc_stringify_error(rv));
46
if ( rv != SCARD_S_SUCCESS ) {
50
printf("Testing SCardGetStatusChange \n");
51
printf("Please insert a working reader : ");
52
rv = SCardGetStatusChange( hContext, INFINITE, 0, 0 );
54
printf("%s\n", pcsc_stringify_error(rv));
56
if ( rv != SCARD_S_SUCCESS ) {
57
SCardReleaseContext( hContext );
61
printf("Testing SCardListReaders : ");
64
rv = SCardListReaders( hContext, mszGroups, 0, &dwReaders );
66
printf("%s\n", pcsc_stringify_error(rv));
68
if ( rv != SCARD_S_SUCCESS ) {
69
SCardReleaseContext( hContext );
73
mszReaders = (char *)malloc(sizeof(char)*dwReaders);
74
rv = SCardListReaders( hContext, mszGroups, mszReaders, &dwReaders );
76
if ( rv != SCARD_S_SUCCESS ) {
77
SCardReleaseContext( hContext );
81
/* Have to understand the multi-string here */
83
for ( i=0; i < dwReaders - 1; i++ ) {
85
printf("Reader %02d: %s\n", p, &mszReaders[i]);
87
while ( mszReaders[++i] != 0 );
95
printf("Enter the reader number : " );
96
scanf("%d", &iReader);
99
if ( iReader > p || iReader <= 0 ) {
100
printf("Invalid Value - try again\n");
102
} while ( iReader > p || iReader <= 0 );
109
rgReaderStates[0].szReader = &mszReaders[iList[iReader]];
110
rgReaderStates[0].dwCurrentState = SCARD_STATE_EMPTY;
112
printf("Waiting for card insertion \n");
113
rv = SCardGetStatusChange( hContext, INFINITE, rgReaderStates, 1 );
115
printf(" : %s\n", pcsc_stringify_error(rv));
117
if ( rv != SCARD_S_SUCCESS ) {
118
SCardReleaseContext( hContext );
122
printf("Testing SCardConnect : ");
123
rv = SCardConnect(hContext, &mszReaders[iList[iReader]],
124
SCARD_SHARE_SHARED, SCARD_PROTOCOL_T0 | SCARD_PROTOCOL_T1,
127
printf("%s\n", pcsc_stringify_error(rv));
129
if ( rv != SCARD_S_SUCCESS ) {
130
SCardReleaseContext( hContext );
134
printf("Testing SCardStatus : ");
137
pcReaders = (char*)malloc(sizeof(char)*50);
139
rv = SCardStatus( hCard, pcReaders, &dwReaderLen, &dwState, &dwProt,
142
printf("%s\n", pcsc_stringify_error(rv));
144
printf("Current Reader Name : %s\n", pcReaders);
145
printf("Current Reader State : %lx\n", dwState);
146
printf("Current Reader Protocol : %lx\n", dwProt - 1);
147
printf("Current Reader ATR Size : %lx\n", dwAtrLen);
148
printf("Current Reader ATR Value : ");
150
for (i=0; i < dwAtrLen; i++) {
151
printf("%02X ", pbAtr[i]);
154
if ( rv != SCARD_S_SUCCESS ) {
155
SCardDisconnect( hCard, SCARD_RESET_CARD );
156
SCardReleaseContext( hContext );
159
printf("Testing SCardDisconnect : ");
160
rv = SCardDisconnect( hCard, SCARD_UNPOWER_CARD );
162
printf("%s\n", pcsc_stringify_error(rv));
164
if ( rv != SCARD_S_SUCCESS ) {
165
SCardReleaseContext( hContext );
169
printf("Testing SCardReleaseContext : ");
170
rv = SCardReleaseContext( hContext );
172
printf("%s\n", pcsc_stringify_error(rv));
174
if ( rv != SCARD_S_SUCCESS ) {
179
printf("PC/SC Test Completed Successfully !\n");