]>
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> |
a2bb2735 | 19 | #include "util.h" |
20 | #include "common.h" | |
21 | #include "ui.h" | |
3c5fce2b OM |
22 | #include "cmdhf14a.h" |
23 | #include "emv/apduinfo.h" | |
a2bb2735 | 24 | #include "emv/tlv.h" |
3c5fce2b | 25 | #include "emv/dol.h" |
a2bb2735 | 26 | #include "emv/dump.h" |
27 | #include "emv/emv_tags.h" | |
28 | ||
3c5fce2b OM |
29 | #define APDU_RES_LEN 260 |
30 | #define APDU_AID_LEN 50 | |
31 | ||
10d4f823 | 32 | // AC |
33 | # define EMVAC_AC_MASK 0xC0 | |
34 | # define EMVAC_AAC 0x00 | |
35 | # define EMVAC_TC 0x40 | |
36 | # define EMVAC_ARQC 0x80 | |
37 | # define EMVAC_CDAREQ 0x10 | |
38 | ||
39 | enum TransactionType { | |
40 | TT_MSD, | |
41 | TT_VSDC, // not standart for contactless!!!! | |
42 | TT_QVSDCMCHIP, | |
43 | TT_CDA, | |
44 | }; | |
45 | ||
66efdc1f | 46 | typedef struct { |
47 | uint8_t CLA; | |
48 | uint8_t INS; | |
49 | uint8_t P1; | |
50 | uint8_t P2; | |
51 | uint8_t Lc; | |
52 | uint8_t *data; | |
53 | } sAPDU; | |
54 | ||
55 | enum CardPSVendor { | |
56 | CV_NA, | |
57 | CV_VISA, | |
58 | CV_MASTERCARD, | |
59 | CV_AMERICANEXPRESS, | |
60 | CV_JCB, | |
61 | CV_CB, | |
62 | CV_OTHER, | |
63 | }; | |
64 | extern enum CardPSVendor GetCardPSVendor(uint8_t * AID, size_t AIDlen); | |
65 | ||
a2bb2735 | 66 | extern void TLVPrintFromBuffer(uint8_t *data, int datalen); |
3c5fce2b | 67 | extern void TLVPrintFromTLV(struct tlvdb *tlv); |
66efdc1f | 68 | extern void TLVPrintFromTLVLev(struct tlvdb *tlv, int level); |
3c5fce2b OM |
69 | extern void TLVPrintAIDlistFromSelectTLV(struct tlvdb *tlv); |
70 | ||
66efdc1f | 71 | extern struct tlvdb *GetPANFromTrack2(const struct tlv *track2); |
72 | extern struct tlvdb *GetdCVVRawFromTrack2(const struct tlv *track2); | |
73 | ||
3c5fce2b OM |
74 | extern void SetAPDULogging(bool logging); |
75 | ||
76 | // search application | |
77 | extern int EMVSearchPSE(bool ActivateField, bool LeaveFieldON, bool decodeTLV, struct tlvdb *tlv); | |
78 | extern int EMVSearch(bool ActivateField, bool LeaveFieldON, bool decodeTLV, struct tlvdb *tlv); | |
79 | extern int EMVSelectPSE(bool ActivateField, bool LeaveFieldON, uint8_t PSENum, uint8_t *Result, size_t MaxResultLen, size_t *ResultLen, uint16_t *sw); | |
80 | 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); | |
81 | // select application | |
82 | extern int EMVSelectApplication(struct tlvdb *tlv, uint8_t *AID, size_t *AIDlen); | |
83 | // Get Processing Options | |
84 | 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); | |
85 | 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 | 86 | // AC |
87 | extern int EMVGenerateChallenge(bool LeaveFieldON, uint8_t *Result, size_t MaxResultLen, size_t *ResultLen, uint16_t *sw, struct tlvdb *tlv); | |
88 | 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); | |
66efdc1f | 89 | // Mastercard |
90 | 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 | 91 | // Auth |
92 | extern int trSDA(uint8_t *AID, size_t AIDlen, struct tlvdb *tlv); | |
a2bb2735 | 93 | |
94 | #endif | |
95 | ||
96 | ||
97 | ||
98 |