FreeCalypso > hg > fc-sim-tools
comparison 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 | 
   comparison
  equal
  deleted
  inserted
  replaced
| 0:f4479a0d4cea | 1:f7a03e53bb2c | 
|---|---|
| 1 #include <sys/types.h> | |
| 2 #include <stdio.h> | |
| 3 #include <stdlib.h> | |
| 4 #include <pcsclite.h> | |
| 5 #include <winscard.h> | |
| 6 #include <reader.h> | |
| 7 | |
| 8 extern SCARDCONTEXT hContext; | |
| 9 extern SCARDHANDLE hCard; | |
| 10 | |
| 11 #define MAX_ATR_BYTES 33 | |
| 12 | |
| 13 retrieve_atr(decor) | |
| 14 { | |
| 15 u_char atrbuf[MAX_ATR_BYTES]; | |
| 16 LONG rv; | |
| 17 DWORD dwAttrLen; | |
| 18 unsigned n; | |
| 19 | |
| 20 dwAttrLen = MAX_ATR_BYTES; | |
| 21 rv = SCardGetAttrib(hCard, SCARD_ATTR_ATR_STRING, atrbuf, &dwAttrLen); | |
| 22 if (rv != SCARD_S_SUCCESS) { | |
| 23 fprintf(stderr, "SCardGetAttrib for ATR: %s\n", | |
| 24 pcsc_stringify_error(rv)); | |
| 25 SCardReleaseContext(hContext); | |
| 26 exit(1); | |
| 27 } | |
| 28 if (decor) | |
| 29 printf("ATR:"); | |
| 30 for (n = 0; n < dwAttrLen; n++) { | |
| 31 if (decor) | |
| 32 putchar(' '); | |
| 33 printf("%02X", atrbuf[n]); | |
| 34 } | |
| 35 putchar('\n'); | |
| 36 return(0); | |
| 37 } | 
