FreeCalypso > hg > fc-sim-tools
annotate pcsc/atrfunc.c @ 86:de23872796cb
fc-uicc-tool: update-rec-imm and update-rec-fill ported over from fc-simtool
author | Mychaela Falconia <falcon@freecalypso.org> |
---|---|
date | Sun, 11 Apr 2021 03:19:22 +0000 |
parents | 11f4f8a8fa33 |
children |
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 |
2
11f4f8a8fa33
pcsc: ATR code refactoring
Mychaela Falconia <falcon@freecalypso.org>
parents:
1
diff
changeset
|
13 retrieve_atr(head) |
11f4f8a8fa33
pcsc: ATR code refactoring
Mychaela Falconia <falcon@freecalypso.org>
parents:
1
diff
changeset
|
14 char *head; |
1
f7a03e53bb2c
fc-pcsc-atr ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
15 { |
f7a03e53bb2c
fc-pcsc-atr ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
16 u_char atrbuf[MAX_ATR_BYTES]; |
f7a03e53bb2c
fc-pcsc-atr ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
17 LONG rv; |
f7a03e53bb2c
fc-pcsc-atr ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
18 DWORD dwAttrLen; |
f7a03e53bb2c
fc-pcsc-atr ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
19 unsigned n; |
f7a03e53bb2c
fc-pcsc-atr ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
20 |
f7a03e53bb2c
fc-pcsc-atr ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
21 dwAttrLen = MAX_ATR_BYTES; |
f7a03e53bb2c
fc-pcsc-atr ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
22 rv = SCardGetAttrib(hCard, SCARD_ATTR_ATR_STRING, atrbuf, &dwAttrLen); |
f7a03e53bb2c
fc-pcsc-atr ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
23 if (rv != SCARD_S_SUCCESS) { |
f7a03e53bb2c
fc-pcsc-atr ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
24 fprintf(stderr, "SCardGetAttrib for ATR: %s\n", |
f7a03e53bb2c
fc-pcsc-atr ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
25 pcsc_stringify_error(rv)); |
f7a03e53bb2c
fc-pcsc-atr ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
26 SCardReleaseContext(hContext); |
f7a03e53bb2c
fc-pcsc-atr ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
27 exit(1); |
f7a03e53bb2c
fc-pcsc-atr ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
28 } |
2
11f4f8a8fa33
pcsc: ATR code refactoring
Mychaela Falconia <falcon@freecalypso.org>
parents:
1
diff
changeset
|
29 fputs(head, stdout); |
1
f7a03e53bb2c
fc-pcsc-atr ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
30 for (n = 0; n < dwAttrLen; n++) { |
2
11f4f8a8fa33
pcsc: ATR code refactoring
Mychaela Falconia <falcon@freecalypso.org>
parents:
1
diff
changeset
|
31 printf(" %02X", atrbuf[n]); |
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 putchar('\n'); |
f7a03e53bb2c
fc-pcsc-atr ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
34 return(0); |
f7a03e53bb2c
fc-pcsc-atr ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
35 } |