]>
cvs.zerfleddert.de Git - proxmark3-svn/blob - client/cmdhfemv.c
1 //-----------------------------------------------------------------------------
2 // Copyright (C) 2014 Peter Fillmore
5 // This code is licensed to you under the terms of the GNU GPL, version 2 or,
6 // at your option, any later version. See the LICENSE.txt file for the text of
8 //-----------------------------------------------------------------------------
9 // High frequency EMV commands
10 //-----------------------------------------------------------------------------
13 static int CmdHelp(const char *Cmd
);
15 int usage_hf_emv_trans(void){
16 PrintAndLog("perform an EMV transaction");
17 PrintAndLog("Usage: hf emv trans [h]");
18 PrintAndLog("Options:");
19 PrintAndLog(" h : this help");
21 PrintAndLog("Samples:");
22 PrintAndLog(" hf emv trans");
25 int usage_hf_emv_getrnd(void){
26 PrintAndLog("retrieve the UN number from a terminal");
27 PrintAndLog("Usage: hf emv getrnd [h]");
28 PrintAndLog("Options:");
29 PrintAndLog(" h : this help");
31 PrintAndLog("Samples:");
32 PrintAndLog(" hf emv getrnd");
35 int usage_hf_emv_eload(void){
36 PrintAndLog("set EMV tags in the device to use in a transaction");
37 PrintAndLog("Usage: hf emv eload [h] o <filename w/o .bin>");
38 PrintAndLog("Options:");
39 PrintAndLog(" h : this help");
40 PrintAndLog(" o <filename> : filename w/o '.bin'");
42 PrintAndLog("Samples:");
43 PrintAndLog(" hf emv eload o myfile");
46 int usage_hf_emv_sim(void){
47 PrintAndLog("Simulates a EMV contactless card");
48 PrintAndLog("Usage: hf emv sim [h]");
49 PrintAndLog("Options:");
50 PrintAndLog(" h : this help");
52 PrintAndLog("Samples:");
53 PrintAndLog(" hf emv sim");
56 int usage_hf_emv_dump(void){
57 PrintAndLog("Gets EMV contactless tag values.");
58 PrintAndLog("and saves binary dump into the file `filename.bin` or `cardUID.bin`");
59 PrintAndLog("Usage: hf emv dump [h] o <filename w/o .bin>");
60 PrintAndLog("Options:");
61 PrintAndLog(" h : this help");
62 PrintAndLog(" o <filename> : filename w/o '.bin' to dump bytes");
64 PrintAndLog("Samples:");
65 PrintAndLog(" hf emv dump");
66 PrintAndLog(" hf emv dump o myfile");
70 //perform an EMV transaction
71 int CmdHfEmvTrans(const char *Cmd
) {
72 char cmdp
= param_getchar(Cmd
, 0);
73 if ( cmdp
== 'h' || cmdp
== 'H') return usage_hf_emv_trans();
74 UsbCommand c
= {CMD_EMV_TRANSACTION
, {0, 0, 0}};
79 //retrieve the UN number from a terminal
80 int CmdHfEmvGetrng(const char *Cmd
) {
81 char cmdp
= param_getchar(Cmd
, 0);
82 if ( cmdp
== 'h' || cmdp
== 'H') return usage_hf_emv_getrnd();
83 UsbCommand c
= {CMD_EMV_GET_RANDOM_NUM
, {0, 0, 0}};
89 //set EMV tags in the device to use in a transaction
90 int CmdHfEmvELoad(const char *Cmd
) {
92 char filename
[FILE_PATH_SIZE
];
93 char *fnameptr
= filename
;
98 while(param_getchar(Cmd
, cmdp
) != 0x00) {
99 switch(param_getchar(Cmd
, cmdp
)) {
102 return usage_hf_emv_eload();
105 len
= param_getstr(Cmd
, cmdp
+1, filename
);
108 if (len
> FILE_PATH_SIZE
-5)
109 len
= FILE_PATH_SIZE
-5;
110 sprintf(fnameptr
+ len
,".bin");
114 PrintAndLog("Unknown parameter '%c'", param_getchar(Cmd
, cmdp
));
122 if(errors
) return usage_hf_emv_eload();
125 f
= fopen(filename
,"r");
127 PrintAndLog("File %s not found or locked", filename
);
135 UsbCommand c
= {CMD_EMV_LOAD_VALUE
, {0,0,0}};
137 // transfer to device
138 while (fgets(line
, sizeof (line
), f
)) {
139 printf("LINE = %s\n", line
);
141 token
= strtok(line
, ":");
142 tag
= (uint16_t)strtol(token
, NULL
, 0);
143 token
= strtok(NULL
,"");
146 memcpy(c
.d
.asBytes
, token
, strlen(token
));
148 clearCommandBuffer();
151 printf("Loaded TAG = %04x\n", tag
);
152 printf("Loaded VALUE = %s\n", token
);
156 PrintAndLog("loaded %s", filename
);
157 //PrintAndLog("\nLoaded %d bytes from file: %s to emulator memory", numofbytes, filename);
161 int CmdHfEmvDump(const char *Cmd
){
166 while(param_getchar(Cmd
, cmdp
) != 0x00) {
167 switch(param_getchar(Cmd
, cmdp
)) {
170 return usage_hf_emv_dump();
172 PrintAndLog("Unknown parameter '%c'", param_getchar(Cmd
, cmdp
));
180 if(errors
) return usage_hf_emv_dump();
182 UsbCommand c
= {CMD_EMV_DUMP_CARD
, {0, 0, 0}};
183 clearCommandBuffer();
186 if (!WaitForResponseTimeout(CMD_ACK
, &resp
, 3000)) {
187 PrintAndLog("Command execute time-out");
195 int CmdHfEmvSim(const char *Cmd) {
200 while(param_getchar(Cmd, cmdp) != 0x00) {
201 switch(param_getchar(Cmd, cmdp)) {
204 return usage_hf_emv_sim();
206 PrintAndLog("Unknown parameter '%c'", param_getchar(Cmd, cmdp));
214 if(errors) return usage_hf_emv_sim();
216 UsbCommand c = {CMD_SIMULATE_TAG_LEGIC_RF, {6,3,0}};
217 sscanf(Cmd, " %"lli" %"lli" %"lli, &c.arg[0], &c.arg[1], &c.arg[2]);
218 clearCommandBuffer();
224 int CmdHfEmvList(const char *Cmd
) {
229 static command_t CommandTable
[] = {
230 {"help", CmdHelp
, 1, "This help"},
231 {"trans", CmdHfEmvTrans
, 0, "Perform EMV Reader Transaction"},
232 {"getrng", CmdHfEmvGetrng
, 0, "get random number from terminal"},
233 {"eload", CmdHfEmvELoad
, 0, "load EMV tag into device"},
234 {"dump", CmdHfEmvDump
, 0, "Dump EMV tag values"},
235 // {"sim", CmdHfEmvSim, 0, "Start tag simulator"},
236 {"list", CmdHfEmvList
, 1, "[Deprecated] List ISO7816 history"},
237 {NULL
, NULL
, 0, NULL
}
240 int CmdHFEmv(const char *Cmd
) {
241 clearCommandBuffer();
242 CmdsParse(CommandTable
, Cmd
);
246 int CmdHelp(const char *Cmd
) {
247 CmdsHelp(CommandTable
);