annotate simtool/atr.c @ 91:226b231d00f3

fc-simtool: readrec command implemented
author Mychaela Falconia <falcon@freecalypso.org>
date Sun, 24 Jan 2021 18:46:11 +0000
parents b57cf64ece29
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
85
b57cf64ece29 fc-simtool project started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1 #include <sys/types.h>
b57cf64ece29 fc-simtool project started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
2 #include <stdio.h>
b57cf64ece29 fc-simtool project started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
3 #include <stdlib.h>
b57cf64ece29 fc-simtool project started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
4 #include <pcsclite.h>
b57cf64ece29 fc-simtool project started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
5 #include <winscard.h>
b57cf64ece29 fc-simtool project started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
6 #include <reader.h>
b57cf64ece29 fc-simtool project started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
7 #include "globals.h"
b57cf64ece29 fc-simtool project started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
8
b57cf64ece29 fc-simtool project started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
9 #define MAX_ATR_BYTES 33
b57cf64ece29 fc-simtool project started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
10
b57cf64ece29 fc-simtool project started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
11 retrieve_atr()
b57cf64ece29 fc-simtool project started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
12 {
b57cf64ece29 fc-simtool project started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
13 u_char atrbuf[MAX_ATR_BYTES];
b57cf64ece29 fc-simtool project started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
14 LONG rv;
b57cf64ece29 fc-simtool project started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
15 DWORD dwAttrLen;
b57cf64ece29 fc-simtool project started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
16 unsigned n;
b57cf64ece29 fc-simtool project started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
17
b57cf64ece29 fc-simtool project started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
18 dwAttrLen = MAX_ATR_BYTES;
b57cf64ece29 fc-simtool project started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
19 rv = SCardGetAttrib(hCard, SCARD_ATTR_ATR_STRING, atrbuf, &dwAttrLen);
b57cf64ece29 fc-simtool project started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
20 if (rv != SCARD_S_SUCCESS) {
b57cf64ece29 fc-simtool project started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
21 fprintf(stderr, "SCardGetAttrib for ATR: %s\n",
b57cf64ece29 fc-simtool project started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
22 pcsc_stringify_error(rv));
b57cf64ece29 fc-simtool project started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
23 return(-1);
b57cf64ece29 fc-simtool project started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
24 }
b57cf64ece29 fc-simtool project started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
25 printf("ATR:");
b57cf64ece29 fc-simtool project started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
26 for (n = 0; n < dwAttrLen; n++)
b57cf64ece29 fc-simtool project started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
27 printf(" %02X", atrbuf[n]);
b57cf64ece29 fc-simtool project started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
28 putchar('\n');
b57cf64ece29 fc-simtool project started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
29 return(0);
b57cf64ece29 fc-simtool project started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
30 }