FreeCalypso > hg > fc-sim-tools
view pcsc/connect.c @ 3:45ea06eaa9fd
fc-pcsc-backend main program put together
author | Mychaela Falconia <falcon@freecalypso.org> |
---|---|
date | Sun, 14 Mar 2021 02:21:49 +0000 |
parents | f7a03e53bb2c |
children |
line wrap: on
line source
#include <string.h> #include <strings.h> #include <stdio.h> #include <stdlib.h> #include <pcsclite.h> #include <winscard.h> extern SCARDCONTEXT hContext; extern char *reader_list; extern unsigned select_reader_num; SCARDHANDLE hCard; char *selected_reader; select_reader_by_num() { char *cp; unsigned num; for (cp = reader_list, num = 0; *cp; num++) { if (num == select_reader_num) { selected_reader = cp; return(0); } cp += strlen(cp) + 1; } fprintf(stderr, "error: requested reader #%u, but only %u reader(s) found\n", select_reader_num, num); SCardReleaseContext(hContext); exit(1); } connect_to_card() { LONG rv; DWORD dwActiveProtocol; rv = SCardConnect(hContext, selected_reader, SCARD_SHARE_EXCLUSIVE, SCARD_PROTOCOL_T0, &hCard, &dwActiveProtocol); if (rv != SCARD_S_SUCCESS) { fprintf(stderr, "SCardConnect: %s\n", pcsc_stringify_error(rv)); SCardReleaseContext(hContext); exit(1); } return(0); }