/[pcsclite]/trunk/Drivers/ccid/examples/scardcontrol.c
ViewVC logotype

Diff of /trunk/Drivers/ccid/examples/scardcontrol.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 940 by rousseau, Sun Jun 13 16:59:13 2004 UTC revision 972 by rousseau, Wed Jun 23 14:54:44 2004 UTC
# Line 26  Line 26 
26  #include <time.h>  #include <time.h>
27  #include <unistd.h>  #include <unistd.h>
28  #include <string.h>  #include <string.h>
29  #include <wintypes.h>  #include <PCSC/winscard.h>
 #include <winscard.h>  
30    
31  #ifndef TRUE  #ifndef TRUE
32  #define TRUE 1  #define TRUE 1
# Line 62  int main(int argc, char *argv[]) Line 61  int main(int argc, char *argv[])
61          LONG rv;          LONG rv;
62          SCARDCONTEXT hContext;          SCARDCONTEXT hContext;
63          DWORD dwReaders;          DWORD dwReaders;
64          LPSTR mszReaders;          LPTSTR mszReaders;
65          char *ptr, **readers = NULL;          char *ptr, **readers = NULL;
66          int nbReaders;          int nbReaders;
67          SCARDHANDLE hCard;          SCARDHANDLE hCard;
# Line 76  int main(int argc, char *argv[]) Line 75  int main(int argc, char *argv[])
75          DWORD length;          DWORD length;
76          char attribute[1];          char attribute[1];
77          DWORD attribute_length;          DWORD attribute_length;
78            SCARD_IO_REQUEST pioRecvPci;
79    
80          printf("SCardControl sample code\n");          printf("SCardControl sample code\n");
81          printf("V 1.0 2004, Ludovic Rousseau <ludovic.rousseau@free.fr>\n");          printf("V 1.0 2004, Ludovic Rousseau <ludovic.rousseau@free.fr>\n");
# Line 159  int main(int argc, char *argv[]) Line 159  int main(int argc, char *argv[])
159          printf(" Protocol: %ld\n", dwActiveProtocol);          printf(" Protocol: %ld\n", dwActiveProtocol);
160          PCSC_ERROR_EXIT(rv, "SCardConnect")          PCSC_ERROR_EXIT(rv, "SCardConnect")
161    
162          /* get firmware */          /* get GemPC firmware */
163          printf(" Get Firmware\n");          printf(" Get GemPC Firmware\n");
164    
165          /* this is specific to Gemplus readers */          /* this is specific to Gemplus readers */
166          bSendBuffer[0] = 0x02;          bSendBuffer[0] = 0x02;
# Line 203  int main(int argc, char *argv[]) Line 203  int main(int argc, char *argv[])
203                  goto end;                  goto end;
204          }          }
205    
206            /* connect to a reader (even without a card) */
207            dwActiveProtocol = -1;
208            rv = SCardReconnect(hCard, SCARD_SHARE_SHARED,
209                    SCARD_PROTOCOL_T0, SCARD_UNPOWER_CARD, &dwActiveProtocol);
210            printf(" Protocol: %ld\n", dwActiveProtocol);
211            PCSC_ERROR_EXIT(rv, "SCardReconnect")
212    
213            /* APDU select DF */
214            memcpy(bSendBuffer, "\x00\xA4\x04\x00\x05\x47\x54\x4F\x4B\x31", 10);
215            length = sizeof(bRecvBuffer);
216            rv = SCardTransmit(hCard, SCARD_PCI_T0, bSendBuffer, 10,
217                    &pioRecvPci, bRecvBuffer, &length);
218            printf(" card response:");
219            for (i=0; i<length; i++)
220                    printf(" %02X", bRecvBuffer[i]);
221            printf("\n");
222            PCSC_ERROR_EXIT(rv, "SCardTransmit")
223    
224            /* APDU select EF */
225            memcpy(bSendBuffer, "\x00\xA4\x02\x00\x02\x00\x04", 7);
226            length = sizeof(bRecvBuffer);
227            rv = SCardTransmit(hCard, SCARD_PCI_T0, bSendBuffer, 7,
228                    &pioRecvPci, bRecvBuffer, &length);
229            printf(" card response:");
230            for (i=0; i<length; i++)
231                    printf(" %02X", bRecvBuffer[i]);
232            printf("\n");
233            PCSC_ERROR_EXIT(rv, "SCardTransmit")
234    
235          /* verify PIN */          /* verify PIN */
236          printf(" Secure verify PIN\n");          printf(" Secure verify PIN\n");
237          offset = 0;          offset = 0;
# Line 241  int main(int argc, char *argv[]) Line 270  int main(int argc, char *argv[])
270          for (i=0; i<offset; i++)          for (i=0; i<offset; i++)
271                  printf(" %02X", bSendBuffer[i]);                  printf(" %02X", bSendBuffer[i]);
272          printf("\n");          printf("\n");
273          printf("Enter your PIN:");          printf("Enter your PIN: ");
274          fflush(stdout);          fflush(stdout);
275          rv = SCardControl(hCard, IOCTL_SMARTCARD_VENDOR_VERIFY_PIN, bSendBuffer,          rv = SCardControl(hCard, IOCTL_SMARTCARD_VENDOR_VERIFY_PIN, bSendBuffer,
276                  offset, bRecvBuffer, sizeof(bRecvBuffer), &length);                  offset, bRecvBuffer, sizeof(bRecvBuffer), &length);
# Line 252  int main(int argc, char *argv[]) Line 281  int main(int argc, char *argv[])
281          printf("\n");          printf("\n");
282          PCSC_ERROR_CONT(rv, "SCardControl")          PCSC_ERROR_CONT(rv, "SCardControl")
283    
284            {
285                    fd_set fd;
286                    struct timeval timeout;
287    
288                    FD_ZERO(&fd);
289                    FD_SET(STDIN_FILENO, &fd);      /* stdin */
290                    timeout.tv_sec = 0;                     /* timeout = 0 */
291                    timeout.tv_usec = 0;
292    
293                    /* we only try to read stdin if the pinpad is on a keyboard
294                     * we do not read stdin for a SPR 532 for example */
295                    if (select(1, &fd, NULL, NULL, &timeout) > 0)
296                    {
297                            /* read the fake digits */
298                            char in[10];    /* 4 digits + \n + \0 */
299                            fgets(in, sizeof(in), stdin);
300    
301                            printf("keyboard sent: %s", in);
302                    }
303            }
304    
305          /* card disconnect */          /* card disconnect */
306          rv = SCardDisconnect(hCard, SCARD_UNPOWER_CARD);          rv = SCardDisconnect(hCard, SCARD_UNPOWER_CARD);
307          PCSC_ERROR_CONT(rv, "SCardDisconnect")          PCSC_ERROR_CONT(rv, "SCardDisconnect")

Legend:
Removed from v.940  
changed lines
  Added in v.972

  ViewVC Help
Powered by ViewVC 1.1.5