annotate pcsc/context.c @ 32:d0be3802410a

fc-simtool sws-auth-pin[12] implemented
author Mychaela Falconia <falcon@freecalypso.org>
date Wed, 17 Mar 2021 00:49:50 +0000
parents f4479a0d4cea
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
f4479a0d4cea fc-pcsc-list ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1 #include <stdio.h>
f4479a0d4cea fc-pcsc-list ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
2 #include <stdlib.h>
f4479a0d4cea fc-pcsc-list ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
3 #include <pcsclite.h>
f4479a0d4cea fc-pcsc-list ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
4 #include <winscard.h>
f4479a0d4cea fc-pcsc-list ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
5
f4479a0d4cea fc-pcsc-list ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
6 SCARDCONTEXT hContext;
f4479a0d4cea fc-pcsc-list ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
7 char *reader_list;
f4479a0d4cea fc-pcsc-list ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
8
f4479a0d4cea fc-pcsc-list ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
9 setup_pcsc_context()
f4479a0d4cea fc-pcsc-list ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
10 {
f4479a0d4cea fc-pcsc-list ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
11 LONG rv;
f4479a0d4cea fc-pcsc-list ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
12
f4479a0d4cea fc-pcsc-list ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
13 rv = SCardEstablishContext(SCARD_SCOPE_SYSTEM, NULL, NULL, &hContext);
f4479a0d4cea fc-pcsc-list ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
14 if (rv != SCARD_S_SUCCESS) {
f4479a0d4cea fc-pcsc-list ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
15 fprintf(stderr, "SCardEstablishContext: %s\n",
f4479a0d4cea fc-pcsc-list ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
16 pcsc_stringify_error(rv));
f4479a0d4cea fc-pcsc-list ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
17 exit(1);
f4479a0d4cea fc-pcsc-list ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
18 }
f4479a0d4cea fc-pcsc-list ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
19 return(0);
f4479a0d4cea fc-pcsc-list ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
20 }
f4479a0d4cea fc-pcsc-list ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
21
f4479a0d4cea fc-pcsc-list ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
22 get_reader_list()
f4479a0d4cea fc-pcsc-list ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
23 {
f4479a0d4cea fc-pcsc-list ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
24 LONG rv;
f4479a0d4cea fc-pcsc-list ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
25 DWORD dwReaders;
f4479a0d4cea fc-pcsc-list ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
26
f4479a0d4cea fc-pcsc-list ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
27 rv = SCardListReaders(hContext, NULL, NULL, &dwReaders);
f4479a0d4cea fc-pcsc-list ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
28 if (rv != SCARD_S_SUCCESS) {
f4479a0d4cea fc-pcsc-list ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
29 fprintf(stderr, "SCardListReaders 1st call: %s\n",
f4479a0d4cea fc-pcsc-list ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
30 pcsc_stringify_error(rv));
f4479a0d4cea fc-pcsc-list ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
31 SCardReleaseContext(hContext);
f4479a0d4cea fc-pcsc-list ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
32 exit(1);
f4479a0d4cea fc-pcsc-list ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
33 }
f4479a0d4cea fc-pcsc-list ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
34 if (dwReaders < 1) {
f4479a0d4cea fc-pcsc-list ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
35 fprintf(stderr,
f4479a0d4cea fc-pcsc-list ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
36 "error: dwReaders returned by SCardListReaders() is less than 1\n");
f4479a0d4cea fc-pcsc-list ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
37 SCardReleaseContext(hContext);
f4479a0d4cea fc-pcsc-list ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
38 exit(1);
f4479a0d4cea fc-pcsc-list ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
39 }
f4479a0d4cea fc-pcsc-list ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
40 reader_list = malloc(dwReaders);
f4479a0d4cea fc-pcsc-list ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
41 if (!reader_list) {
f4479a0d4cea fc-pcsc-list ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
42 perror("malloc for readers list");
f4479a0d4cea fc-pcsc-list ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
43 SCardReleaseContext(hContext);
f4479a0d4cea fc-pcsc-list ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
44 exit(1);
f4479a0d4cea fc-pcsc-list ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
45 }
f4479a0d4cea fc-pcsc-list ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
46 reader_list[0] = '\0';
f4479a0d4cea fc-pcsc-list ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
47 rv = SCardListReaders(hContext, NULL, reader_list, &dwReaders);
f4479a0d4cea fc-pcsc-list ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
48 if (rv != SCARD_S_SUCCESS) {
f4479a0d4cea fc-pcsc-list ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
49 fprintf(stderr, "SCardListReaders 2nd call: %s\n",
f4479a0d4cea fc-pcsc-list ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
50 pcsc_stringify_error(rv));
f4479a0d4cea fc-pcsc-list ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
51 SCardReleaseContext(hContext);
f4479a0d4cea fc-pcsc-list ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
52 exit(1);
f4479a0d4cea fc-pcsc-list ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
53 }
f4479a0d4cea fc-pcsc-list ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
54 return(0);
f4479a0d4cea fc-pcsc-list ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
55 }