From 6b2677c1541568687413e16e6c049f0dca3c374a Mon Sep 17 00:00:00 2001 From: Philippe Teuwen Date: Wed, 1 May 2019 22:33:27 +0200 Subject: [PATCH] Replace WITH_SMARTCARD by dynamic detection in client --- client/emv/cmdemv.c | 33 +++++++++++++++------------------ client/emv/emvcore.c | 9 ++++----- 2 files changed, 19 insertions(+), 23 deletions(-) diff --git a/client/emv/cmdemv.c b/client/emv/cmdemv.c index fa7f35e3a..f2b6da624 100644 --- a/client/emv/cmdemv.c +++ b/client/emv/cmdemv.c @@ -809,13 +809,12 @@ static int CmdEMVExec(const char *Cmd) { uint8_t psenum = (channel == ECC_CONTACT) ? 1 : 2; CLIParserFree(); -#ifndef WITH_SMARTCARD - // not compiled with smartcard functionality, we need to exit - if (channel == ECC_CONTACT) { - PrintAndLogEx(WARNING, "PM3 Client is not compiled with support for SMARTCARD. Exiting."); - return PM3_EDEVNOTSUPP; + if (!IfPm3Smartcard()) { + if (channel == ECC_CONTACT) { + PrintAndLogEx(WARNING, "PM3 does not have SMARTCARD support. Exiting."); + return PM3_EDEVNOTSUPP; + } } -#endif SetAPDULogging(showAPDU); @@ -1400,13 +1399,12 @@ static int CmdEMVScan(const char *Cmd) { CLIGetStrWithReturn(12, relfname, &relfnamelen); CLIParserFree(); -#ifndef WITH_SMARTCARD - // not compiled with smartcard functionality, we need to exit - if (channel == ECC_CONTACT) { - PrintAndLogEx(ERR, "PM3 Client is not compiled with support for SMARTCARD. Exiting."); - return PM3_EDEVNOTSUPP; + if (!IfPm3Smartcard()) { + if (channel == ECC_CONTACT) { + PrintAndLogEx(WARNING, "PM3 does not have SMARTCARD support. Exiting."); + return PM3_EDEVNOTSUPP; + } } -#endif SetAPDULogging(showAPDU); @@ -1736,13 +1734,12 @@ static int CmdEMVRoca(const char *Cmd) { PrintChannel(channel); CLIParserFree(); -#ifndef WITH_SMARTCARD - // not compiled with smartcard functionality, we need to exit - if (channel == ECC_CONTACT) { - PrintAndLogEx(WARNING, "PM3 Client is not compiled with support for SMARTCARD. Exiting."); - return PM3_EDEVNOTSUPP; + if (!IfPm3Smartcard()) { + if (channel == ECC_CONTACT) { + PrintAndLogEx(WARNING, "PM3 does not have SMARTCARD support. Exiting."); + return PM3_EDEVNOTSUPP; + } } -#endif // select card uint8_t psenum = (channel == ECC_CONTACT) ? 1 : 2; diff --git a/client/emv/emvcore.c b/client/emv/emvcore.c index 70cfec82a..e9e725448 100644 --- a/client/emv/emvcore.c +++ b/client/emv/emvcore.c @@ -293,11 +293,10 @@ static int EMVExchangeEx(EMVCommandChannel channel, bool ActivateField, bool Lea } break; case ECC_CONTACT: -#ifdef WITH_SMARTCARD - res = ExchangeAPDUSC(data, (IncludeLe ? 6 : 5) + apdu.Lc, ActivateField, LeaveFieldON, Result, (int)MaxResultLen, (int *)ResultLen); -#else - res = 1; -#endif + if (IfPm3Smartcard()) + res = ExchangeAPDUSC(data, (IncludeLe ? 6 : 5) + apdu.Lc, ActivateField, LeaveFieldON, Result, (int)MaxResultLen, (int *)ResultLen); + else + res = 1; if (res) { return res; }