# HG changeset patch # User Mychaela Falconia # Date 1615682715 0 # Node ID f4479a0d4ceabe8fdbb9498d7e716bb55cf466d1 fc-pcsc-list ported over diff -r 000000000000 -r f4479a0d4cea .hgignore --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/.hgignore Sun Mar 14 00:45:15 2021 +0000 @@ -0,0 +1,5 @@ +syntax: regexp + +\.[oa]$ + +^pcsc/fc-pcsc-list$ diff -r 000000000000 -r f4479a0d4cea pcsc/Makefile --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/pcsc/Makefile Sun Mar 14 00:45:15 2021 +0000 @@ -0,0 +1,21 @@ +CC= gcc +CFLAGS= -O2 -I/usr/include/PCSC +PROGS= fc-pcsc-list + +INSTALL_PREFIX= /opt/freecalypso + +INSTBIN=${INSTALL_PREFIX}/bin + +LIST_OBJS= context.o rdlist.o + +all: ${PROGS} + +fc-pcsc-list: ${LIST_OBJS} + ${CC} ${CFLAGS} -o $@ ${LIST_OBJS} -lpcsclite + +install: + mkdir -p ${INSTBIN} + install -c ${PROGS} ${INSTBIN} + +clean: + rm -f ${PROGS} *.o diff -r 000000000000 -r f4479a0d4cea pcsc/context.c --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/pcsc/context.c Sun Mar 14 00:45:15 2021 +0000 @@ -0,0 +1,55 @@ +#include +#include +#include +#include + +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); +} diff -r 000000000000 -r f4479a0d4cea pcsc/rdlist.c --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/pcsc/rdlist.c Sun Mar 14 00:45:15 2021 +0000 @@ -0,0 +1,25 @@ +#include +#include +#include +#include +#include +#include + +extern SCARDCONTEXT hContext; +extern char *reader_list; + +main(argc, argv) + char **argv; +{ + char *cp; + unsigned num; + + setup_pcsc_context(); + get_reader_list(); + for (cp = reader_list, num = 0; *cp; num++) { + printf("#%u: %s\n", num, cp); + cp += strlen(cp) + 1; + } + SCardReleaseContext(hContext); + exit(0); +}