FreeCalypso > hg > freecalypso-hwlab
comparison pcsc-test/pcsc-test1.c @ 84:1d7d8615d628
pcsc-test: some experiments to get pcsc-lite working
| author | Mychaela Falconia <falcon@freecalypso.org> |
|---|---|
| date | Sat, 23 Jan 2021 17:21:08 +0000 |
| parents | |
| children |
comparison
equal
deleted
inserted
replaced
| 83:d7a1e7a6d6ba | 84:1d7d8615d628 |
|---|---|
| 1 #include <sys/types.h> | |
| 2 #include <string.h> | |
| 3 #include <strings.h> | |
| 4 #include <stdio.h> | |
| 5 #include <stdlib.h> | |
| 6 #include <pcsclite.h> | |
| 7 #include <winscard.h> | |
| 8 | |
| 9 main(argc, argv) | |
| 10 char **argv; | |
| 11 { | |
| 12 SCARDCONTEXT hContext; | |
| 13 LONG rv; | |
| 14 DWORD dwReaders; | |
| 15 LPSTR mszReaders; | |
| 16 char *cp; | |
| 17 | |
| 18 rv = SCardEstablishContext(SCARD_SCOPE_SYSTEM, NULL, NULL, &hContext); | |
| 19 if (rv != SCARD_S_SUCCESS) { | |
| 20 fprintf(stderr, "SCardEstablishContext: %s\n", | |
| 21 pcsc_stringify_error(rv)); | |
| 22 exit(1); | |
| 23 } | |
| 24 rv = SCardListReaders(hContext, NULL, NULL, &dwReaders); | |
| 25 if (rv != SCARD_S_SUCCESS) { | |
| 26 fprintf(stderr, "SCardListReaders 1st call: %s\n", | |
| 27 pcsc_stringify_error(rv)); | |
| 28 SCardReleaseContext(hContext); | |
| 29 exit(1); | |
| 30 } | |
| 31 printf("dwReaders = %u\n", (unsigned) dwReaders); | |
| 32 if (dwReaders < 1) { | |
| 33 fprintf(stderr, | |
| 34 "error: dwReaders returned by SCardListReaders() is less than 1\n"); | |
| 35 SCardReleaseContext(hContext); | |
| 36 exit(1); | |
| 37 } | |
| 38 mszReaders = malloc(dwReaders); | |
| 39 if (!mszReaders) { | |
| 40 perror("malloc for readers list"); | |
| 41 SCardReleaseContext(hContext); | |
| 42 exit(1); | |
| 43 } | |
| 44 *mszReaders = '\0'; | |
| 45 rv = SCardListReaders(hContext, NULL, mszReaders, &dwReaders); | |
| 46 if (rv != SCARD_S_SUCCESS) { | |
| 47 fprintf(stderr, "SCardListReaders 2nd call: %s\n", | |
| 48 pcsc_stringify_error(rv)); | |
| 49 SCardReleaseContext(hContext); | |
| 50 exit(1); | |
| 51 } | |
| 52 for (cp = mszReaders; *cp; ) { | |
| 53 printf("Reader: %s\n", cp); | |
| 54 cp += strlen(cp) + 1; | |
| 55 } | |
| 56 printf("End of list of readers\n"); | |
| 57 SCardReleaseContext(hContext); | |
| 58 exit(0); | |
| 59 } |
