view pcsc/context.c @ 53:fbedb67d234f

serial: fix parity for inverse coding convention Important note: it is my (Mother Mychaela's) understanding that SIM cards with inverse coding convention are extremely rare, and I have never seen such a card. Therefore, our support for the inverse coding convention will likely remain forever untested.
author Mychaela Falconia <falcon@freecalypso.org>
date Sun, 21 Mar 2021 20:46:09 +0000
parents f4479a0d4cea
children
line wrap: on
line source

#include <stdio.h>
#include <stdlib.h>
#include <pcsclite.h>
#include <winscard.h>

SCARDCONTEXT hContext;
char *reader_list;

setup_pcsc_context()
{
	LONG rv;

	rv = SCardEstablishContext(SCARD_SCOPE_SYSTEM, NULL, NULL, &hContext);
	if (rv != SCARD_S_SUCCESS) {
		fprintf(stderr, "SCardEstablishContext: %s\n",
			pcsc_stringify_error(rv));
		exit(1);
	}
	return(0);
}

get_reader_list()
{
	LONG rv;
	DWORD dwReaders;

	rv = SCardListReaders(hContext, NULL, NULL, &dwReaders);
	if (rv != SCARD_S_SUCCESS) {
		fprintf(stderr, "SCardListReaders 1st call: %s\n",
			pcsc_stringify_error(rv));
		SCardReleaseContext(hContext);
		exit(1);
	}
	if (dwReaders < 1) {
		fprintf(stderr,
	"error: dwReaders returned by SCardListReaders() is less than 1\n");
		SCardReleaseContext(hContext);
		exit(1);
	}
	reader_list = malloc(dwReaders);
	if (!reader_list) {
		perror("malloc for readers list");
		SCardReleaseContext(hContext);
		exit(1);
	}
	reader_list[0] = '\0';
	rv = SCardListReaders(hContext, NULL, reader_list, &dwReaders);
	if (rv != SCARD_S_SUCCESS) {
		fprintf(stderr, "SCardListReaders 2nd call: %s\n",
			pcsc_stringify_error(rv));
		SCardReleaseContext(hContext);
		exit(1);
	}
	return(0);
}