1 //-----------------------------------------------------------------------------
2 // Copyright (C) 2017 Merlok
4 // This code is licensed to you under the terms of the GNU GPL, version 2 or,
5 // at your option, any later version. See the LICENSE.txt file for the text of
7 //-----------------------------------------------------------------------------
8 // EMV core functionality
9 //-----------------------------------------------------------------------------
19 #include "iso7816/apduinfo.h"
20 #include "iso7816/iso7816core.h"
23 enum TransactionType
{
25 TT_VSDC
, // contact only. not standard for contactless
29 extern const char *TransactionTypeStr
[];
42 enum CardPSVendor
GetCardPSVendor(uint8_t *AID
, size_t AIDlen
);
44 bool TLVPrintFromBuffer(uint8_t *data
, int datalen
);
45 void TLVPrintFromTLV(struct tlvdb
*tlv
);
46 void TLVPrintFromTLVLev(struct tlvdb
*tlv
, int level
);
47 void TLVPrintAIDlistFromSelectTLV(struct tlvdb
*tlv
);
49 struct tlvdb
*GetPANFromTrack2(const struct tlv
*track2
);
50 struct tlvdb
*GetdCVVRawFromTrack2(const struct tlv
*track2
);
53 int EMVExchange(Iso7816CommandChannel channel
, bool LeaveFieldON
, sAPDU apdu
, uint8_t *Result
, size_t MaxResultLen
, size_t *ResultLen
, uint16_t *sw
, struct tlvdb
*tlv
);
56 int EMVSearchPSE(Iso7816CommandChannel channel
, bool ActivateField
, bool LeaveFieldON
, uint8_t PSENum
, bool decodeTLV
, struct tlvdb
*tlv
);
57 int EMVSearch(Iso7816CommandChannel channel
, bool ActivateField
, bool LeaveFieldON
, bool decodeTLV
, struct tlvdb
*tlv
);
58 int EMVSelectPSE(Iso7816CommandChannel channel
, bool ActivateField
, bool LeaveFieldON
, uint8_t PSENum
, uint8_t *Result
, size_t MaxResultLen
, size_t *ResultLen
, uint16_t *sw
);
59 int EMVSelect(Iso7816CommandChannel channel
, bool ActivateField
, bool LeaveFieldON
, uint8_t *AID
, size_t AIDLen
, uint8_t *Result
, size_t MaxResultLen
, size_t *ResultLen
, uint16_t *sw
, struct tlvdb
*tlv
);
61 int EMVSelectApplication(struct tlvdb
*tlv
, uint8_t *AID
, size_t *AIDlen
);
62 // Get Processing Options
63 int EMVGPO(Iso7816CommandChannel channel
, bool LeaveFieldON
, uint8_t *PDOL
, size_t PDOLLen
, uint8_t *Result
, size_t MaxResultLen
, size_t *ResultLen
, uint16_t *sw
, struct tlvdb
*tlv
);
64 int EMVReadRecord(Iso7816CommandChannel channel
, bool LeaveFieldON
, uint8_t SFI
, uint8_t SFIrec
, uint8_t *Result
, size_t MaxResultLen
, size_t *ResultLen
, uint16_t *sw
, struct tlvdb
*tlv
);
66 int EMVGenerateChallenge(Iso7816CommandChannel channel
, bool LeaveFieldON
, uint8_t *Result
, size_t MaxResultLen
, size_t *ResultLen
, uint16_t *sw
, struct tlvdb
*tlv
);
67 int EMVAC(Iso7816CommandChannel channel
, bool LeaveFieldON
, uint8_t RefControl
, uint8_t *CDOL
, size_t CDOLLen
, uint8_t *Result
, size_t MaxResultLen
, size_t *ResultLen
, uint16_t *sw
, struct tlvdb
*tlv
);
69 int EMVInternalAuthenticate(Iso7816CommandChannel channel
, bool LeaveFieldON
, uint8_t *DDOL
, size_t DDOLLen
, uint8_t *Result
, size_t MaxResultLen
, size_t *ResultLen
, uint16_t *sw
, struct tlvdb
*tlv
);
71 int MSCComputeCryptoChecksum(Iso7816CommandChannel channel
, bool LeaveFieldON
, uint8_t *UDOL
, uint8_t UDOLlen
, uint8_t *Result
, size_t MaxResultLen
, size_t *ResultLen
, uint16_t *sw
, struct tlvdb
*tlv
);
73 int trSDA(struct tlvdb
*tlv
);
74 int trDDA(Iso7816CommandChannel channel
, bool decodeTLV
, struct tlvdb
*tlv
);
75 int trCDA(struct tlvdb
*tlv
, struct tlvdb
*ac_tlv
, struct tlv
*pdol_data_tlv
, struct tlv
*ac_data_tlv
);
77 int RecoveryCertificates(struct tlvdb
*tlvRoot
, json_t
*root
);
79 struct emv_pk
*get_ca_pk(struct tlvdb
*db
);