From f6ce5ecb08f1005578a452b4497452fecca13d3d Mon Sep 17 00:00:00 2001 From: pwpiwi Date: Tue, 22 Jan 2019 08:49:47 +0100 Subject: [PATCH] fix includes for OS X. Add missing framework for OS X. --- client/Makefile | 9 +++- client/pcsc.c | 113 ++++++------------------------------------------ 2 files changed, 21 insertions(+), 101 deletions(-) diff --git a/client/Makefile b/client/Makefile index 7208ef66..aafbe375 100644 --- a/client/Makefile +++ b/client/Makefile @@ -46,8 +46,13 @@ ifneq (,$(findstring MINGW,$(platform))) PCSC_INCLUDES := PCSC_LIBS = -lwinscard else - PCSC_INCLUDES := $(shell pkg-config --cflags libpcsclite) - PCSC_LIBS := $(shell pkg-config --libs libpcsclite) + ifeq ($(platform),Darwin) + PCSC_INCLUDES = + PCSC_LIBS = -framework PCSC + else + PCSC_INCLUDES := $(shell pkg-config --cflags libpcsclite) + PCSC_LIBS := $(shell pkg-config --libs libpcsclite) + endif endif LUAPLATFORM = generic diff --git a/client/pcsc.c b/client/pcsc.c index cf3f6b4d..dd331d0a 100644 --- a/client/pcsc.c +++ b/client/pcsc.c @@ -14,21 +14,24 @@ #include #include #include + +#if defined (__APPLE__) +#include +#include +#define SCARD_ATTR_VALUE(Class, Tag) ((((ULONG)(Class)) << 16) | ((ULONG)(Tag))) +#define SCARD_CLASS_ICC_STATE 9 +#define SCARD_ATTR_ATR_STRING SCARD_ATTR_VALUE(SCARD_CLASS_ICC_STATE, 0x0303) +#elif defined (_WIN32) +#include +#else +#include +#include +#endif + #include "ui.h" #include "util.h" #include "cmdhw.h" -#ifdef __APPLE__ -#include -#include -#else -#include -#endif - -#ifdef __linux__ -#include "reader.h" -#endif - static SCARDCONTEXT SC_Context; static SCARDHANDLE SC_Card; static DWORD SC_Protocol; @@ -172,91 +175,3 @@ bool pcscGetATR(smart_card_atr_t *card) return true; } - -/* -int main(void) -{ - LONG rv; - - SCARDCONTEXT SC_Context; - LPTSTR mszReaders; - SCARDHANDLE SC_Card; - DWORD dwReaders, dwActiveProtocol, dwRecvLength; - - SCARD_IO_REQUEST pioSendPci; - BYTE pbRecvBuffer[258]; - BYTE cmd1[] = { 0x00, 0xA4, 0x04, 0x00, 0x0A, 0xA0, - 0x00, 0x00, 0x00, 0x62, 0x03, 0x01, 0x0C, 0x06, 0x01 }; - BYTE cmd2[] = { 0x00, 0x00, 0x00, 0x00 }; - - unsigned int i; - - rv = SCardEstablisSC_Context(SCARD_SCOPE_SYSTEM, NULL, NULL, &SC_Context); - CHECK("SCardEstablisSC_Context", rv) - -#ifdef SCARD_AUTOALLOCATE - dwReaders = SCARD_AUTOALLOCATE; - - rv = SCardListReaders(SC_Context, NULL, (LPTSTR)&mszReaders, &dwReaders); - CHECK("SCardListReaders", rv) -#else - CHECK("SCardListReaders", rv) - - mszReaders = calloc(dwReaders, sizeof(char)); - rv = SCardListReaders(SC_Context, NULL, mszReaders, &dwReaders); - CHECK("SCardListReaders", rv) -#endif - printf("reader name: %s\n", mszReaders); - - rv = SCardConnect(SC_Context, mszReaders, SCARD_SHARE_SHARED, - SCARD_PROTOCOL_T0 | SCARD_PROTOCOL_T1, &SC_Card, &dwActiveProtocol); - CHECK("SCardConnect", rv) - - switch(dwActiveProtocol) - { - case SCARD_PROTOCOL_T0: - pioSendPci = *SCARD_PCI_T0; - break; - - case SCARD_PROTOCOL_T1: - pioSendPci = *SCARD_PCI_T1; - break; - } - dwRecvLength = sizeof(pbRecvBuffer); - rv = SCardTransmit(SC_Card, &pioSendPci, cmd1, sizeof(cmd1), - NULL, pbRecvBuffer, &dwRecvLength); - CHECK("SCardTransmit", rv) - - printf("response: "); - for(i=0; i