]>
Commit | Line | Data |
---|---|---|
a2bb2735 | 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 | //----------------------------------------------------------------------------- | |
3c5fce2b | 8 | // EMV core functionality |
a2bb2735 | 9 | //----------------------------------------------------------------------------- |
10 | ||
11 | #ifndef EMVCORE_H__ | |
12 | #define EMVCORE_H__ | |
13 | ||
14 | #include <stdio.h> | |
15 | #include <stdint.h> | |
16 | #include <stdlib.h> | |
17 | #include <inttypes.h> | |
3c5fce2b | 18 | #include <string.h> |
95b697f0 | 19 | #include <jansson.h> |
a2bb2735 | 20 | #include "util.h" |
21 | #include "common.h" | |
22 | #include "ui.h" | |
3c5fce2b | 23 | #include "cmdhf14a.h" |
d03fb293 OM |
24 | #include "apduinfo.h" |
25 | #include "tlv.h" | |
26 | #include "dol.h" | |
27 | #include "dump.h" | |
28 | #include "emv_tags.h" | |
29 | #include "emv_pk.h" | |
30 | #include "emv_pki.h" | |
a2bb2735 | 31 | |
3c5fce2b OM |
32 | #define APDU_RES_LEN 260 |
33 | #define APDU_AID_LEN 50 | |
34 | ||
10d4f823 | 35 | enum TransactionType { |
36 | TT_MSD, | |
37 | TT_VSDC, // not standart for contactless!!!! | |
38 | TT_QVSDCMCHIP, | |
39 | TT_CDA, | |
40 | }; | |
95b697f0 | 41 | extern char *TransactionTypeStr[]; |
10d4f823 | 42 | |
66efdc1f | 43 | typedef struct { |
44 | uint8_t CLA; | |
45 | uint8_t INS; | |
46 | uint8_t P1; | |
47 | uint8_t P2; | |
48 | uint8_t Lc; | |
49 | uint8_t *data; | |
50 | } sAPDU; | |
51 | ||
52 | enum CardPSVendor { | |
53 | CV_NA, | |
54 | CV_VISA, | |
55 | CV_MASTERCARD, | |
56 | CV_AMERICANEXPRESS, | |
57 | CV_JCB, | |
58 | CV_CB, | |
59 | CV_OTHER, | |
60 | }; | |
61 | extern enum CardPSVendor GetCardPSVendor(uint8_t * AID, size_t AIDlen); | |
62 | ||
a2bb2735 | 63 | extern void TLVPrintFromBuffer(uint8_t *data, int datalen); |
3c5fce2b | 64 | extern void TLVPrintFromTLV(struct tlvdb *tlv); |
66efdc1f | 65 | extern void TLVPrintFromTLVLev(struct tlvdb *tlv, int level); |
3c5fce2b OM |
66 | extern void TLVPrintAIDlistFromSelectTLV(struct tlvdb *tlv); |
67 | ||
66efdc1f | 68 | extern struct tlvdb *GetPANFromTrack2(const struct tlv *track2); |
69 | extern struct tlvdb *GetdCVVRawFromTrack2(const struct tlv *track2); | |
70 | ||
3c5fce2b OM |
71 | extern void SetAPDULogging(bool logging); |
72 | ||
39cc1c87 OM |
73 | // exchange |
74 | extern int EMVExchange(bool LeaveFieldON, sAPDU apdu, uint8_t *Result, size_t MaxResultLen, size_t *ResultLen, uint16_t *sw, struct tlvdb *tlv); | |
75 | ||
76 | ||
3c5fce2b OM |
77 | // search application |
78 | extern int EMVSearchPSE(bool ActivateField, bool LeaveFieldON, bool decodeTLV, struct tlvdb *tlv); | |
79 | extern int EMVSearch(bool ActivateField, bool LeaveFieldON, bool decodeTLV, struct tlvdb *tlv); | |
80 | extern int EMVSelectPSE(bool ActivateField, bool LeaveFieldON, uint8_t PSENum, uint8_t *Result, size_t MaxResultLen, size_t *ResultLen, uint16_t *sw); | |
81 | extern int EMVSelect(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); | |
82 | // select application | |
83 | extern int EMVSelectApplication(struct tlvdb *tlv, uint8_t *AID, size_t *AIDlen); | |
84 | // Get Processing Options | |
85 | extern int EMVGPO(bool LeaveFieldON, uint8_t *PDOL, size_t PDOLLen, uint8_t *Result, size_t MaxResultLen, size_t *ResultLen, uint16_t *sw, struct tlvdb *tlv); | |
86 | extern int EMVReadRecord(bool LeaveFieldON, uint8_t SFI, uint8_t SFIrec, uint8_t *Result, size_t MaxResultLen, size_t *ResultLen, uint16_t *sw, struct tlvdb *tlv); | |
10d4f823 | 87 | // AC |
88 | extern int EMVGenerateChallenge(bool LeaveFieldON, uint8_t *Result, size_t MaxResultLen, size_t *ResultLen, uint16_t *sw, struct tlvdb *tlv); | |
89 | extern int EMVAC(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); | |
d03fb293 OM |
90 | // DDA |
91 | extern int EMVInternalAuthenticate(bool LeaveFieldON, uint8_t *DDOL, size_t DDOLLen, uint8_t *Result, size_t MaxResultLen, size_t *ResultLen, uint16_t *sw, struct tlvdb *tlv); | |
66efdc1f | 92 | // Mastercard |
93 | int MSCComputeCryptoChecksum(bool LeaveFieldON, uint8_t *UDOL, uint8_t UDOLlen, uint8_t *Result, size_t MaxResultLen, size_t *ResultLen, uint16_t *sw, struct tlvdb *tlv); | |
10d4f823 | 94 | // Auth |
d03fb293 OM |
95 | extern int trSDA(struct tlvdb *tlv); |
96 | extern int trDDA(bool decodeTLV, struct tlvdb *tlv); | |
97 | extern int trCDA(struct tlvdb *tlv, struct tlvdb *ac_tlv, struct tlv *pdol_data_tlv, struct tlv *ac_data_tlv); | |
a2bb2735 | 98 | |
95b697f0 OM |
99 | extern int RecoveryCertificates(struct tlvdb *tlvRoot, json_t *root); |
100 | ||
a2bb2735 | 101 | #endif |
102 | ||
103 | ||
104 | ||
105 |