annotate pcsc/connect.c @ 53:fbedb67d234f

serial: fix parity for inverse coding convention Important note: it is my (Mother Mychaela's) understanding that SIM cards with inverse coding convention are extremely rare, and I have never seen such a card. Therefore, our support for the inverse coding convention will likely remain forever untested.
author Mychaela Falconia <falcon@freecalypso.org>
date Sun, 21 Mar 2021 20:46:09 +0000
parents f7a03e53bb2c
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1
f7a03e53bb2c fc-pcsc-atr ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1 #include <string.h>
f7a03e53bb2c fc-pcsc-atr ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
2 #include <strings.h>
f7a03e53bb2c fc-pcsc-atr ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
3 #include <stdio.h>
f7a03e53bb2c fc-pcsc-atr ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
4 #include <stdlib.h>
f7a03e53bb2c fc-pcsc-atr ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
5 #include <pcsclite.h>
f7a03e53bb2c fc-pcsc-atr ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
6 #include <winscard.h>
f7a03e53bb2c fc-pcsc-atr ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
7
f7a03e53bb2c fc-pcsc-atr ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
8 extern SCARDCONTEXT hContext;
f7a03e53bb2c fc-pcsc-atr ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
9 extern char *reader_list;
f7a03e53bb2c fc-pcsc-atr ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
10 extern unsigned select_reader_num;
f7a03e53bb2c fc-pcsc-atr ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
11
f7a03e53bb2c fc-pcsc-atr ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
12 SCARDHANDLE hCard;
f7a03e53bb2c fc-pcsc-atr ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
13 char *selected_reader;
f7a03e53bb2c fc-pcsc-atr ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
14
f7a03e53bb2c fc-pcsc-atr ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
15 select_reader_by_num()
f7a03e53bb2c fc-pcsc-atr ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
16 {
f7a03e53bb2c fc-pcsc-atr ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
17 char *cp;
f7a03e53bb2c fc-pcsc-atr ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
18 unsigned num;
f7a03e53bb2c fc-pcsc-atr ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
19
f7a03e53bb2c fc-pcsc-atr ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
20 for (cp = reader_list, num = 0; *cp; num++) {
f7a03e53bb2c fc-pcsc-atr ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
21 if (num == select_reader_num) {
f7a03e53bb2c fc-pcsc-atr ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
22 selected_reader = cp;
f7a03e53bb2c fc-pcsc-atr ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
23 return(0);
f7a03e53bb2c fc-pcsc-atr ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
24 }
f7a03e53bb2c fc-pcsc-atr ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
25 cp += strlen(cp) + 1;
f7a03e53bb2c fc-pcsc-atr ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
26 }
f7a03e53bb2c fc-pcsc-atr ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
27 fprintf(stderr,
f7a03e53bb2c fc-pcsc-atr ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
28 "error: requested reader #%u, but only %u reader(s) found\n",
f7a03e53bb2c fc-pcsc-atr ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
29 select_reader_num, num);
f7a03e53bb2c fc-pcsc-atr ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
30 SCardReleaseContext(hContext);
f7a03e53bb2c fc-pcsc-atr ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
31 exit(1);
f7a03e53bb2c fc-pcsc-atr ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
32 }
f7a03e53bb2c fc-pcsc-atr ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
33
f7a03e53bb2c fc-pcsc-atr ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
34 connect_to_card()
f7a03e53bb2c fc-pcsc-atr ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
35 {
f7a03e53bb2c fc-pcsc-atr ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
36 LONG rv;
f7a03e53bb2c fc-pcsc-atr ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
37 DWORD dwActiveProtocol;
f7a03e53bb2c fc-pcsc-atr ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
38
f7a03e53bb2c fc-pcsc-atr ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
39 rv = SCardConnect(hContext, selected_reader, SCARD_SHARE_EXCLUSIVE,
f7a03e53bb2c fc-pcsc-atr ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
40 SCARD_PROTOCOL_T0, &hCard, &dwActiveProtocol);
f7a03e53bb2c fc-pcsc-atr ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
41 if (rv != SCARD_S_SUCCESS) {
f7a03e53bb2c fc-pcsc-atr ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
42 fprintf(stderr, "SCardConnect: %s\n", pcsc_stringify_error(rv));
f7a03e53bb2c fc-pcsc-atr ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
43 SCardReleaseContext(hContext);
f7a03e53bb2c fc-pcsc-atr ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
44 exit(1);
f7a03e53bb2c fc-pcsc-atr ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
45 }
f7a03e53bb2c fc-pcsc-atr ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
46 return(0);
f7a03e53bb2c fc-pcsc-atr ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
47 }