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 //-----------------------------------------------------------------------------
32 #define APDU_RES_LEN 260
33 #define APDU_AID_LEN 50
40 enum TransactionType
{
42 TT_VSDC
, // not standart for contactless!!!!
46 extern char *TransactionTypeStr
[];
66 extern enum CardPSVendor
GetCardPSVendor(uint8_t * AID
, size_t AIDlen
);
68 extern bool TLVPrintFromBuffer(uint8_t *data
, int datalen
);
69 extern void TLVPrintFromTLV(struct tlvdb
*tlv
);
70 extern void TLVPrintFromTLVLev(struct tlvdb
*tlv
, int level
);
71 extern void TLVPrintAIDlistFromSelectTLV(struct tlvdb
*tlv
);
73 extern struct tlvdb
*GetPANFromTrack2(const struct tlv
*track2
);
74 extern struct tlvdb
*GetdCVVRawFromTrack2(const struct tlv
*track2
);
76 extern void SetAPDULogging(bool logging
);
79 extern int EMVExchange(EMVCommandChannel channel
, bool LeaveFieldON
, sAPDU apdu
, uint8_t *Result
, size_t MaxResultLen
, size_t *ResultLen
, uint16_t *sw
, struct tlvdb
*tlv
);
82 extern int EMVSearchPSE(EMVCommandChannel channel
, bool ActivateField
, bool LeaveFieldON
, uint8_t PSENum
, bool decodeTLV
, struct tlvdb
*tlv
);
83 extern int EMVSearch(EMVCommandChannel channel
, bool ActivateField
, bool LeaveFieldON
, bool decodeTLV
, struct tlvdb
*tlv
);
84 extern int EMVSelectPSE(EMVCommandChannel channel
, bool ActivateField
, bool LeaveFieldON
, uint8_t PSENum
, uint8_t *Result
, size_t MaxResultLen
, size_t *ResultLen
, uint16_t *sw
);
85 extern int EMVSelect(EMVCommandChannel 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
);
87 extern int EMVSelectApplication(struct tlvdb
*tlv
, uint8_t *AID
, size_t *AIDlen
);
88 // Get Processing Options
89 extern int EMVGPO(EMVCommandChannel channel
, bool LeaveFieldON
, uint8_t *PDOL
, size_t PDOLLen
, uint8_t *Result
, size_t MaxResultLen
, size_t *ResultLen
, uint16_t *sw
, struct tlvdb
*tlv
);
90 extern int EMVReadRecord(EMVCommandChannel channel
, bool LeaveFieldON
, uint8_t SFI
, uint8_t SFIrec
, uint8_t *Result
, size_t MaxResultLen
, size_t *ResultLen
, uint16_t *sw
, struct tlvdb
*tlv
);
92 extern int EMVGenerateChallenge(EMVCommandChannel channel
, bool LeaveFieldON
, uint8_t *Result
, size_t MaxResultLen
, size_t *ResultLen
, uint16_t *sw
, struct tlvdb
*tlv
);
93 extern int EMVAC(EMVCommandChannel 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
);
95 extern int EMVInternalAuthenticate(EMVCommandChannel channel
, bool LeaveFieldON
, uint8_t *DDOL
, size_t DDOLLen
, uint8_t *Result
, size_t MaxResultLen
, size_t *ResultLen
, uint16_t *sw
, struct tlvdb
*tlv
);
97 int MSCComputeCryptoChecksum(EMVCommandChannel channel
, bool LeaveFieldON
, uint8_t *UDOL
, uint8_t UDOLlen
, uint8_t *Result
, size_t MaxResultLen
, size_t *ResultLen
, uint16_t *sw
, struct tlvdb
*tlv
);
99 extern int trSDA(struct tlvdb
*tlv
);
100 extern int trDDA(EMVCommandChannel channel
, bool decodeTLV
, struct tlvdb
*tlv
);
101 extern int trCDA(struct tlvdb
*tlv
, struct tlvdb
*ac_tlv
, struct tlv
*pdol_data_tlv
, struct tlv
*ac_data_tlv
);
103 extern int RecoveryCertificates(struct tlvdb
*tlvRoot
, json_t
*root
);
105 extern struct emv_pk
*get_ca_pk(struct tlvdb
*db
);