fix little endian vs big endian in the macros... again... but this time correct
[RRG-proxmark3.git] / client / src / emv / emvcore.h
blob056cab0bab1c5db8ad690931573f307f8141775d
1 //-----------------------------------------------------------------------------
2 // Copyright (C) 2017 Merlok
3 //
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
6 // the license.
7 //-----------------------------------------------------------------------------
8 // EMV core functionality
9 //-----------------------------------------------------------------------------
11 #ifndef EMVCORE_H__
12 #define EMVCORE_H__
14 #include "common.h"
16 #include <inttypes.h>
17 #include <jansson.h>
19 #include "iso7816/apduinfo.h"
20 #include "iso7816/iso7816core.h"
21 #include "emv_pki.h"
23 enum TransactionType {
24 TT_MSD,
25 TT_VSDC, // contact only. not standard for contactless
26 TT_QVSDCMCHIP,
27 TT_CDA,
29 extern const char *TransactionTypeStr[];
31 enum CardPSVendor {
32 CV_NA,
33 CV_VISA,
34 CV_MASTERCARD,
35 CV_AMERICANEXPRESS,
36 CV_JCB,
37 CV_CB,
38 CV_SWITCH,
39 CV_DINERS,
40 CV_OTHER,
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);
52 // exchange
53 int EMVExchange(Iso7816CommandChannel channel, bool LeaveFieldON, sAPDU apdu, uint8_t *Result, size_t MaxResultLen, size_t *ResultLen, uint16_t *sw, struct tlvdb *tlv);
55 // search application
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);
60 // select application
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);
65 // AC
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);
68 // DDA
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);
70 // Mastercard
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);
72 // Auth
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);
80 #endif