diff 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
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/pcsc/atrfunc.c	Sun Mar 14 01:09:23 2021 +0000
@@ -0,0 +1,37 @@
+#include <sys/types.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <pcsclite.h>
+#include <winscard.h>
+#include <reader.h>
+
+extern SCARDCONTEXT hContext;
+extern SCARDHANDLE hCard;
+
+#define	MAX_ATR_BYTES	33
+
+retrieve_atr(decor)
+{
+	u_char atrbuf[MAX_ATR_BYTES];
+	LONG rv;
+	DWORD dwAttrLen;
+	unsigned n;
+
+	dwAttrLen = MAX_ATR_BYTES;
+	rv = SCardGetAttrib(hCard, SCARD_ATTR_ATR_STRING, atrbuf, &dwAttrLen);
+	if (rv != SCARD_S_SUCCESS) {
+		fprintf(stderr, "SCardGetAttrib for ATR: %s\n",
+			pcsc_stringify_error(rv));
+		SCardReleaseContext(hContext);
+		exit(1);
+	}
+	if (decor)
+		printf("ATR:");
+	for (n = 0; n < dwAttrLen; n++) {
+		if (decor)
+			putchar(' ');
+		printf("%02X", atrbuf[n]);
+	}
+	putchar('\n');
+	return(0);
+}