annotate pcsc/atrfunc.c @ 1:f7a03e53bb2c

fc-pcsc-atr ported over
author Mychaela Falconia <falcon@freecalypso.org>
date Sun, 14 Mar 2021 01:09:23 +0000
parents
children 11f4f8a8fa33
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 <sys/types.h>
f7a03e53bb2c fc-pcsc-atr ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
2 #include <stdio.h>
f7a03e53bb2c fc-pcsc-atr ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
3 #include <stdlib.h>
f7a03e53bb2c fc-pcsc-atr ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
4 #include <pcsclite.h>
f7a03e53bb2c fc-pcsc-atr ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
5 #include <winscard.h>
f7a03e53bb2c fc-pcsc-atr ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
6 #include <reader.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 SCARDHANDLE hCard;
f7a03e53bb2c fc-pcsc-atr ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
10
f7a03e53bb2c fc-pcsc-atr ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
11 #define MAX_ATR_BYTES 33
f7a03e53bb2c fc-pcsc-atr ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
12
f7a03e53bb2c fc-pcsc-atr ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
13 retrieve_atr(decor)
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 u_char atrbuf[MAX_ATR_BYTES];
f7a03e53bb2c fc-pcsc-atr ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
16 LONG rv;
f7a03e53bb2c fc-pcsc-atr ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
17 DWORD dwAttrLen;
f7a03e53bb2c fc-pcsc-atr ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
18 unsigned n;
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 dwAttrLen = MAX_ATR_BYTES;
f7a03e53bb2c fc-pcsc-atr ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
21 rv = SCardGetAttrib(hCard, SCARD_ATTR_ATR_STRING, atrbuf, &dwAttrLen);
f7a03e53bb2c fc-pcsc-atr ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
22 if (rv != SCARD_S_SUCCESS) {
f7a03e53bb2c fc-pcsc-atr ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
23 fprintf(stderr, "SCardGetAttrib for ATR: %s\n",
f7a03e53bb2c fc-pcsc-atr ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
24 pcsc_stringify_error(rv));
f7a03e53bb2c fc-pcsc-atr ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
25 SCardReleaseContext(hContext);
f7a03e53bb2c fc-pcsc-atr ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
26 exit(1);
f7a03e53bb2c fc-pcsc-atr ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
27 }
f7a03e53bb2c fc-pcsc-atr ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
28 if (decor)
f7a03e53bb2c fc-pcsc-atr ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
29 printf("ATR:");
f7a03e53bb2c fc-pcsc-atr ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
30 for (n = 0; n < dwAttrLen; n++) {
f7a03e53bb2c fc-pcsc-atr ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
31 if (decor)
f7a03e53bb2c fc-pcsc-atr ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
32 putchar(' ');
f7a03e53bb2c fc-pcsc-atr ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
33 printf("%02X", atrbuf[n]);
f7a03e53bb2c fc-pcsc-atr ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
34 }
f7a03e53bb2c fc-pcsc-atr ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
35 putchar('\n');
f7a03e53bb2c fc-pcsc-atr ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
36 return(0);
f7a03e53bb2c fc-pcsc-atr ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
37 }