annotate pcsc-test/pcsc-test1.c @ 107:ba2c796259e9

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