view 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
line wrap: on
line source

#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(head)
	char *head;
{
	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);
	}
	fputs(head, stdout);
	for (n = 0; n < dwAttrLen; n++) {
		printf(" %02X", atrbuf[n]);
	}
	putchar('\n');
	return(0);
}