]> git.zerfleddert.de Git - proxmark3-svn/blame - client/cmdhf.c
Change "hf list topaz" to "hf list nfc"
[proxmark3-svn] / client / cmdhf.c
CommitLineData
a553f267 1//-----------------------------------------------------------------------------
2// Copyright (C) 2010 iZsh <izsh at fail0verflow.com>
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// High frequency commands
9//-----------------------------------------------------------------------------
10
7fe9b0b7 11#include <stdio.h>
4c3de57a 12#include <string.h>
902cb3c0 13#include "proxmark3.h"
7fe9b0b7 14#include "graph.h"
15#include "ui.h"
16#include "cmdparser.h"
17#include "cmdhf.h"
18#include "cmdhf14a.h"
19#include "cmdhf14b.h"
20#include "cmdhf15.h"
5acd09bd 21#include "cmdhfepa.h"
7fe9b0b7 22#include "cmdhflegic.h"
cee5a30d 23#include "cmdhficlass.h"
9ca155ba 24#include "cmdhfmf.h"
5ee70129 25#include "cmdhfmfu.h"
b67f7ec3 26#include "protocols.h"
7fe9b0b7 27
28static int CmdHelp(const char *Cmd);
29
30int CmdHFTune(const char *Cmd)
31{
32 UsbCommand c={CMD_MEASURE_ANTENNA_TUNING_HF};
33 SendCommand(&c);
34 return 0;
35}
4c3de57a 36
4c3de57a
MHS
37
38void annotateIso14443a(char *exp, size_t size, uint8_t* cmd, uint8_t cmdsize)
39{
40 switch(cmd[0])
41 {
41fdd0f0
MHS
42 case ISO14443A_CMD_WUPA: snprintf(exp,size,"WUPA"); break;
43 case ISO14443A_CMD_ANTICOLL_OR_SELECT:{
4df54240
MHS
44 // 93 20 = Anticollision (usage: 9320 - answer: 4bytes UID+1byte UID-bytes-xor)
45 // 93 70 = Select (usage: 9370+5bytes 9320 answer - answer: 1byte SAK)
383608a6 46 if(cmd[1] == 0x70)
4c3de57a
MHS
47 {
48 snprintf(exp,size,"SELECT_UID"); break;
49 }else
50 {
4df54240
MHS
51 snprintf(exp,size,"ANTICOLL"); break;
52 }
53 }
41fdd0f0 54 case ISO14443A_CMD_ANTICOLL_OR_SELECT_2:{
4df54240
MHS
55 //95 20 = Anticollision of cascade level2
56 //95 70 = Select of cascade level2
57 if(cmd[2] == 0x70)
58 {
59 snprintf(exp,size,"SELECT_UID-2"); break;
60 }else
61 {
62 snprintf(exp,size,"ANTICOLL-2"); break;
4c3de57a
MHS
63 }
64 }
16a95d76 65 case ISO14443A_CMD_REQA: snprintf(exp,size,"REQA"); break;
66 case ISO14443A_CMD_READBLOCK: snprintf(exp,size,"READBLOCK(%d)",cmd[1]); break;
67 case ISO14443A_CMD_WRITEBLOCK: snprintf(exp,size,"WRITEBLOCK(%d)",cmd[1]); break;
68 case ISO14443A_CMD_HALT: snprintf(exp,size,"HALT"); break;
69 case ISO14443A_CMD_RATS: snprintf(exp,size,"RATS"); break;
70 case MIFARE_CMD_INC: snprintf(exp,size,"INC(%d)",cmd[1]); break;
71 case MIFARE_CMD_DEC: snprintf(exp,size,"DEC(%d)",cmd[1]); break;
72 case MIFARE_CMD_RESTORE: snprintf(exp,size,"RESTORE(%d)",cmd[1]); break;
73 case MIFARE_CMD_TRANSFER: snprintf(exp,size,"TRANSFER(%d)",cmd[1]); break;
74 case MIFARE_AUTH_KEYA: snprintf(exp,size,"AUTH-A(%d)",cmd[1]); break;
75 case MIFARE_AUTH_KEYB: snprintf(exp,size,"AUTH-B(%d)",cmd[1]); break;
76 case MIFARE_MAGICWUPC1: snprintf(exp,size,"MAGIC WUPC1"); break;
77 case MIFARE_MAGICWUPC2: snprintf(exp,size,"MAGIC WUPC2"); break;
78 case MIFARE_MAGICWIPEC: snprintf(exp,size,"MAGIC WIPEC"); break;
79 default: snprintf(exp,size,"?"); break;
4c3de57a
MHS
80 }
81 return;
82}
83
84void annotateIclass(char *exp, size_t size, uint8_t* cmd, uint8_t cmdsize)
85{
4c3de57a
MHS
86 switch(cmd[0])
87 {
337818f7 88 case ICLASS_CMD_ACTALL: snprintf(exp,size,"ACTALL"); break;
4df54240
MHS
89 case ICLASS_CMD_READ_OR_IDENTIFY:{
90 if(cmdsize > 1){
91 snprintf(exp,size,"READ(%d)",cmd[1]);
92 }else{
93 snprintf(exp,size,"IDENTIFY");
94 }
95 break;
96 }
337818f7 97 case ICLASS_CMD_SELECT: snprintf(exp,size,"SELECT"); break;
49726b40
MHS
98 case ICLASS_CMD_PAGESEL: snprintf(exp,size,"PAGESEL(%d)", cmd[1]); break;
99 case ICLASS_CMD_READCHECK_KC:snprintf(exp,size,"READCHECK[Kc](%d)", cmd[1]); break;
100 case ICLASS_CMD_READCHECK_KD:snprintf(exp,size,"READCHECK[Kd](%d)", cmd[1]); break;
337818f7 101 case ICLASS_CMD_CHECK: snprintf(exp,size,"CHECK"); break;
49726b40 102 case ICLASS_CMD_DETECT: snprintf(exp,size,"DETECT"); break;
337818f7 103 case ICLASS_CMD_HALT: snprintf(exp,size,"HALT"); break;
49726b40
MHS
104 case ICLASS_CMD_UPDATE: snprintf(exp,size,"UPDATE(%d)",cmd[1]); break;
105 case ICLASS_CMD_ACT: snprintf(exp,size,"ACT"); break;
106 case ICLASS_CMD_READ4: snprintf(exp,size,"READ4(%d)",cmd[1]); break;
337818f7 107 default: snprintf(exp,size,"?"); break;
4c3de57a
MHS
108 }
109 return;
110}
111
4df54240
MHS
112void annotateIso15693(char *exp, size_t size, uint8_t* cmd, uint8_t cmdsize)
113{
114
115 if(cmd[0] == 0x26)
116 {
117 switch(cmd[1]){
118 case ISO15693_INVENTORY :snprintf(exp, size, "INVENTORY");break;
119 case ISO15693_STAYQUIET :snprintf(exp, size, "STAY_QUIET");break;
120 default: snprintf(exp,size,"?"); break;
4c3de57a 121
4df54240
MHS
122 }
123 }else if(cmd[0] == 0x02)
124 {
125 switch(cmd[1])
126 {
127 case ISO15693_READBLOCK :snprintf(exp, size, "READBLOCK");break;
128 case ISO15693_WRITEBLOCK :snprintf(exp, size, "WRITEBLOCK");break;
129 case ISO15693_LOCKBLOCK :snprintf(exp, size, "LOCKBLOCK");break;
130 case ISO15693_READ_MULTI_BLOCK :snprintf(exp, size, "READ_MULTI_BLOCK");break;
131 case ISO15693_SELECT :snprintf(exp, size, "SELECT");break;
132 case ISO15693_RESET_TO_READY :snprintf(exp, size, "RESET_TO_READY");break;
133 case ISO15693_WRITE_AFI :snprintf(exp, size, "WRITE_AFI");break;
134 case ISO15693_LOCK_AFI :snprintf(exp, size, "LOCK_AFI");break;
135 case ISO15693_WRITE_DSFID :snprintf(exp, size, "WRITE_DSFID");break;
136 case ISO15693_LOCK_DSFID :snprintf(exp, size, "LOCK_DSFID");break;
137 case ISO15693_GET_SYSTEM_INFO :snprintf(exp, size, "GET_SYSTEM_INFO");break;
138 case ISO15693_READ_MULTI_SECSTATUS :snprintf(exp, size, "READ_MULTI_SECSTATUS");break;
41fdd0f0 139 default: snprintf(exp,size,"?"); break;
4df54240
MHS
140 }
141 }
142}
08e8317c 143
ee1eadee 144
145void annotateTopaz(char *exp, size_t size, uint8_t* cmd, uint8_t cmdsize)
146{
147
148 switch(cmd[0]) {
149 case TOPAZ_REQA :snprintf(exp, size, "REQA");break;
150 case TOPAZ_WUPA :snprintf(exp, size, "WUPA");break;
151 case TOPAZ_RID :snprintf(exp, size, "RID");break;
152 case TOPAZ_RALL :snprintf(exp, size, "RALL");break;
153 case TOPAZ_READ :snprintf(exp, size, "READ");break;
154 case TOPAZ_WRITE_E :snprintf(exp, size, "WRITE-E");break;
155 case TOPAZ_WRITE_NE :snprintf(exp, size, "WRITE-NE");break;
156 default: snprintf(exp,size,"?"); break;
157 }
158}
159
160
08e8317c
MHS
161/**
16206 00 = INITIATE
1630E xx = SELECT ID (xx = Chip-ID)
1640B = Get UID
16508 yy = Read Block (yy = block number)
16609 yy dd dd dd dd = Write Block (yy = block number; dd dd dd dd = data to be written)
1670C = Reset to Inventory
1680F = Completion
1690A 11 22 33 44 55 66 = Authenticate (11 22 33 44 55 66 = data to authenticate)
170**/
171
41fdd0f0
MHS
172void annotateIso14443b(char *exp, size_t size, uint8_t* cmd, uint8_t cmdsize)
173{
174 switch(cmd[0]){
175 case ISO14443B_REQB : snprintf(exp,size,"REQB");break;
176 case ISO14443B_ATTRIB : snprintf(exp,size,"ATTRIB");break;
177 case ISO14443B_HALT : snprintf(exp,size,"HALT");break;
08e8317c
MHS
178 case ISO14443B_INITIATE : snprintf(exp,size,"INITIATE");break;
179 case ISO14443B_SELECT : snprintf(exp,size,"SELECT(%d)",cmd[1]);break;
180 case ISO14443B_GET_UID : snprintf(exp,size,"GET UID");break;
181 case ISO14443B_READ_BLK : snprintf(exp,size,"READ_BLK(%d)", cmd[1]);break;
182 case ISO14443B_WRITE_BLK : snprintf(exp,size,"WRITE_BLK(%d)",cmd[1]);break;
183 case ISO14443B_RESET : snprintf(exp,size,"RESET");break;
184 case ISO14443B_COMPLETION : snprintf(exp,size,"COMPLETION");break;
185 case ISO14443B_AUTHENTICATE : snprintf(exp,size,"AUTHENTICATE");break;
186 default : snprintf(exp,size ,"?");break;
41fdd0f0
MHS
187 }
188
189}
190
191/**
192 * @brief iso14443B_CRC_Ok Checks CRC in command or response
193 * @param isResponse
194 * @param data
195 * @param len
196 * @return 0 : CRC-command, CRC not ok
197 * 1 : CRC-command, CRC ok
198 * 2 : Not crc-command
199 */
200
201uint8_t iso14443B_CRC_check(bool isResponse, uint8_t* data, uint8_t len)
202{
203 uint8_t b1,b2;
204
205 if(len <= 2) return 2;
206
207 ComputeCrc14443(CRC_14443_B, data, len-2, &b1, &b2);
208 if(b1 != data[len-2] || b2 != data[len-1]) {
209 return 0;
210 }
211 return 1;
212}
213
49726b40
MHS
214/**
215 * @brief iclass_CRC_Ok Checks CRC in command or response
216 * @param isResponse
217 * @param data
218 * @param len
219 * @return 0 : CRC-command, CRC not ok
220 * 1 : CRC-command, CRC ok
221 * 2 : Not crc-command
222 */
41fdd0f0 223uint8_t iclass_CRC_check(bool isResponse, uint8_t* data, uint8_t len)
49726b40
MHS
224{
225 if(len < 4) return 2;//CRC commands (and responses) are all at least 4 bytes
226
227 uint8_t b1, b2;
228
229 if(!isResponse)//Commands to tag
230 {
231 /**
232 These commands should have CRC. Total length leftmost
233 4 READ
234 4 READ4
235 12 UPDATE - unsecured, ends with CRC16
236 14 UPDATE - secured, ends with signature instead
237 4 PAGESEL
238 **/
239 if(len == 4 || len == 12)//Covers three of them
240 {
241 //Don't include the command byte
242 ComputeCrc14443(CRC_ICLASS, (data+1), len-3, &b1, &b2);
243 return b1 == data[len -2] && b2 == data[len-1];
244 }
245 return 2;
246 }else{
247 /**
248 These tag responses should have CRC. Total length leftmost
249
250 10 READ data[8] crc[2]
251 34 READ4 data[32]crc[2]
252 10 UPDATE data[8] crc[2]
253 10 SELECT csn[8] crc[2]
254 10 IDENTIFY asnb[8] crc[2]
255 10 PAGESEL block1[8] crc[2]
256 10 DETECT csn[8] crc[2]
257
258 These should not
259
260 4 CHECK chip_response[4]
261 8 READCHECK data[8]
262 1 ACTALL sof[1]
263 1 ACT sof[1]
264
265 In conclusion, without looking at the command; any response
266 of length 10 or 34 should have CRC
267 **/
268 if(len != 10 && len != 34) return true;
269
270 ComputeCrc14443(CRC_ICLASS, data, len-2, &b1, &b2);
271 return b1 == data[len -2] && b2 == data[len-1];
272 }
273}
4c3de57a 274
ee1eadee 275
a8904ebd 276bool is_last_record(uint16_t tracepos, uint8_t *trace, uint16_t traceLen)
ee1eadee 277{
a8904ebd 278 return(tracepos + sizeof(uint32_t) + sizeof(uint16_t) + sizeof(uint16_t) >= traceLen);
279}
280
281
282bool next_record_is_response(uint16_t tracepos, uint8_t *trace)
283{
284 uint16_t next_records_datalen = *((uint16_t *)(trace + tracepos + sizeof(uint32_t) + sizeof(uint16_t)));
285
286 return(next_records_datalen & 0x8000);
287}
288
289
290void merge_topaz_reader_frames(uint32_t timestamp, uint32_t *duration, uint16_t *tracepos, uint16_t traceLen, uint8_t *trace, uint8_t *frame, uint8_t *topaz_reader_command, uint16_t *data_len)
291{
292
293#define MAX_TOPAZ_READER_CMD_LEN 9
294
295 uint32_t last_timestamp = timestamp + *duration;
296
297 memcpy(topaz_reader_command, frame, MIN(*data_len, MAX_TOPAZ_READER_CMD_LEN));
298
299 while (!is_last_record(*tracepos, trace, traceLen) && !next_record_is_response(*tracepos, trace)) {
300 uint32_t next_timestamp = *((uint32_t *)(trace + *tracepos));
301 *tracepos += sizeof(uint32_t);
302 last_timestamp = next_timestamp + *((uint16_t *)(trace + *tracepos));
303 *tracepos += sizeof(uint16_t);
304 uint16_t next_data_len = *((uint16_t *)(trace + *tracepos)) & 0x7FFF;
305 *tracepos += sizeof(uint16_t);
306 uint8_t *next_frame = (trace + *tracepos);
307 *tracepos += next_data_len;
308 if (*data_len + next_data_len <= MAX_TOPAZ_READER_CMD_LEN) {
309 memcpy(topaz_reader_command + *data_len, next_frame, next_data_len);
310 *data_len += next_data_len;
311 }
312 uint16_t next_parity_len = (next_data_len-1)/8 + 1;
313 *tracepos += next_parity_len;
314 }
315
316 *duration = last_timestamp - timestamp;
ee1eadee 317}
318
319
f71f4deb 320uint16_t printTraceLine(uint16_t tracepos, uint16_t traceLen, uint8_t *trace, uint8_t protocol, bool showWaitCycles)
4c3de57a
MHS
321{
322 bool isResponse;
a8904ebd 323 uint16_t data_len, parity_len;
324 uint32_t duration;
ee1eadee 325 uint8_t topaz_reader_command[9];
4c3de57a
MHS
326 uint32_t timestamp, first_timestamp, EndOfTransmissionTimestamp;
327 char explanation[30] = {0};
328
f71f4deb 329 if (tracepos + sizeof(uint32_t) + sizeof(uint16_t) + sizeof(uint16_t) > traceLen) return traceLen;
330
4c3de57a
MHS
331 first_timestamp = *((uint32_t *)(trace));
332 timestamp = *((uint32_t *)(trace + tracepos));
4c3de57a
MHS
333
334 tracepos += 4;
335 duration = *((uint16_t *)(trace + tracepos));
336 tracepos += 2;
337 data_len = *((uint16_t *)(trace + tracepos));
338 tracepos += 2;
339
340 if (data_len & 0x8000) {
341 data_len &= 0x7fff;
342 isResponse = true;
343 } else {
344 isResponse = false;
345 }
346 parity_len = (data_len-1)/8 + 1;
347
f71f4deb 348 if (tracepos + data_len + parity_len > traceLen) {
349 return traceLen;
4c3de57a 350 }
4c3de57a
MHS
351 uint8_t *frame = trace + tracepos;
352 tracepos += data_len;
353 uint8_t *parityBytes = trace + tracepos;
354 tracepos += parity_len;
355
ee1eadee 356 if (protocol == TOPAZ && !isResponse) {
357 // topaz reader commands come in 1 or 9 separate frames with 8 Bits each.
358 // merge them:
a8904ebd 359 merge_topaz_reader_frames(timestamp, &duration, &tracepos, traceLen, trace, frame, topaz_reader_command, &data_len);
360 frame = topaz_reader_command;
ee1eadee 361 }
362
27eabcdc
MHS
363 //Check the CRC status
364 uint8_t crcStatus = 2;
365
366 if (data_len > 2) {
367 uint8_t b1, b2;
ee1eadee 368 switch (protocol) {
369 case ICLASS:
370 crcStatus = iclass_CRC_check(isResponse, frame, data_len);
371 break;
372 case ISO_14443B:
373 case TOPAZ:
a8904ebd 374 crcStatus = iso14443B_CRC_check(isResponse, frame, data_len);
ee1eadee 375 break;
376 case ISO_14443A:
377 ComputeCrc14443(CRC_14443_A, frame, data_len-2, &b1, &b2);
378 if (b1 != frame[data_len-2] || b2 != frame[data_len-1]) {
379 if(!(isResponse & (data_len < 6))) {
27eabcdc 380 crcStatus = 0;
ee1eadee 381 }
27eabcdc 382 }
ee1eadee 383 break;
384 default:
385 break;
27eabcdc
MHS
386 }
387 }
388 //0 CRC-command, CRC not ok
389 //1 CRC-command, CRC ok
390 //2 Not crc-command
9e8255d4 391
4c3de57a 392 //--- Draw the data column
9e8255d4 393 //char line[16][110];
4c3de57a 394 char line[16][110];
9e8255d4
MHS
395
396 for (int j = 0; j < data_len && j/16 < 16; j++) {
397
4c3de57a
MHS
398 int oddparity = 0x01;
399 int k;
400
401 for (k=0 ; k<8 ; k++) {
402 oddparity ^= (((frame[j] & 0xFF) >> k) & 0x01);
403 }
4c3de57a 404 uint8_t parityBits = parityBytes[j>>3];
4c3de57a 405 if (isResponse && (oddparity != ((parityBits >> (7-(j&0x0007))) & 0x01))) {
9e8255d4
MHS
406 snprintf(line[j/16]+(( j % 16) * 4),110, "%02x! ", frame[j]);
407
4c3de57a 408 } else {
8b9393d3 409 snprintf(line[j/16]+(( j % 16) * 4),110, "%02x ", frame[j]);
9e8255d4 410 }
27eabcdc
MHS
411
412 }
a8904ebd 413 if(crcStatus == 1 || crcStatus == 2)
27eabcdc
MHS
414 {//CRC-command
415 char *pos1 = line[(data_len-2)/16]+(((data_len-2) % 16) * 4)-1;
416 (*pos1) = '[';
417 char *pos2 = line[(data_len)/16]+(((data_len) % 16) * 4)-2;
418 (*pos2) = ']';
9e8255d4
MHS
419 }
420 if(data_len == 0)
421 {
422 if(data_len == 0){
423 sprintf(line[0],"<empty trace - possible error>");
4c3de57a
MHS
424 }
425 }
426 //--- Draw the CRC column
4c3de57a 427
49726b40 428 char *crc = (crcStatus == 0 ? "!crc" : (crcStatus == 1 ? " ok " : " "));
4c3de57a
MHS
429
430 EndOfTransmissionTimestamp = timestamp + duration;
431
432 if(!isResponse)
433 {
ee1eadee 434 switch(protocol) {
435 case ICLASS: annotateIclass(explanation,sizeof(explanation),frame,data_len); break;
436 case ISO_14443A: annotateIso14443a(explanation,sizeof(explanation),frame,data_len); break;
437 case ISO_14443B: annotateIso14443b(explanation,sizeof(explanation),frame,data_len); break;
438 case TOPAZ: annotateTopaz(explanation,sizeof(explanation),frame,data_len); break;
439 default: break;
440 }
4c3de57a
MHS
441 }
442
9e8255d4
MHS
443 int num_lines = MIN((data_len - 1)/16 + 1, 16);
444 for (int j = 0; j < num_lines ; j++) {
4c3de57a
MHS
445 if (j == 0) {
446 PrintAndLog(" %9d | %9d | %s | %-64s| %s| %s",
447 (timestamp - first_timestamp),
448 (EndOfTransmissionTimestamp - first_timestamp),
449 (isResponse ? "Tag" : "Rdr"),
450 line[j],
451 (j == num_lines-1) ? crc : " ",
452 (j == num_lines-1) ? explanation : "");
453 } else {
454 PrintAndLog(" | | | %-64s| %s| %s",
455 line[j],
ee1eadee 456 (j == num_lines-1) ? crc : " ",
4c3de57a
MHS
457 (j == num_lines-1) ? explanation : "");
458 }
459 }
460
a8904ebd 461 if (is_last_record(tracepos, trace, traceLen)) return traceLen;
f71f4deb 462
a8904ebd 463 if (showWaitCycles && !isResponse && next_record_is_response(tracepos, trace)) {
4c3de57a 464 uint32_t next_timestamp = *((uint32_t *)(trace + tracepos));
a8904ebd 465 PrintAndLog(" %9d | %9d | %s | fdt (Frame Delay Time): %d",
466 (EndOfTransmissionTimestamp - first_timestamp),
467 (next_timestamp - first_timestamp),
468 " ",
469 (next_timestamp - EndOfTransmissionTimestamp));
4c3de57a 470 }
f71f4deb 471
4c3de57a
MHS
472 return tracepos;
473}
474
f71f4deb 475
4c3de57a
MHS
476int CmdHFList(const char *Cmd)
477{
478 bool showWaitCycles = false;
479 char type[40] = {0};
480 int tlen = param_getstr(Cmd,0,type);
481 char param = param_getchar(Cmd, 1);
482 bool errors = false;
b689b842 483 uint8_t protocol = 0;
4c3de57a 484 //Validate params
b689b842 485 if(tlen == 0)
4c3de57a
MHS
486 {
487 errors = true;
488 }
489 if(param == 'h' || (param !=0 && param != 'f'))
490 {
491 errors = true;
492 }
b689b842
MHS
493 if(!errors)
494 {
ee1eadee 495 if(strcmp(type, "iclass") == 0) {
b689b842 496 protocol = ICLASS;
ee1eadee 497 } else if(strcmp(type, "14a") == 0) {
b689b842 498 protocol = ISO_14443A;
ee1eadee 499 } else if(strcmp(type, "14b") == 0) {
b689b842 500 protocol = ISO_14443B;
a8904ebd 501 } else if(strcmp(type,"nfc")== 0) {
ee1eadee 502 protocol = TOPAZ;
503 } else if(strcmp(type,"raw")== 0) {
b689b842 504 protocol = -1;//No crc, no annotations
ee1eadee 505 } else {
b689b842
MHS
506 errors = true;
507 }
508 }
4c3de57a
MHS
509
510 if (errors) {
511 PrintAndLog("List protocol data in trace buffer.");
92623113
MHS
512 PrintAndLog("Usage: hf list <protocol> [f]");
513 PrintAndLog(" f - show frame delay times as well");
514 PrintAndLog("Supported <protocol> values:");
515 PrintAndLog(" raw - just show raw data without annotations");
337818f7 516 PrintAndLog(" 14a - interpret data as iso14443a communications");
41fdd0f0 517 PrintAndLog(" 14b - interpret data as iso14443b communications");
4c3de57a 518 PrintAndLog(" iclass - interpret data as iclass communications");
ee1eadee 519 PrintAndLog(" topaz - interpret data as topaz communications");
4c3de57a
MHS
520 PrintAndLog("");
521 PrintAndLog("example: hf list 14a f");
522 PrintAndLog("example: hf list iclass");
523 return 0;
524 }
b689b842 525
4c3de57a
MHS
526
527 if (param == 'f') {
528 showWaitCycles = true;
529 }
530
531
f71f4deb 532 uint8_t *trace;
4c3de57a 533 uint16_t tracepos = 0;
f71f4deb 534 trace = malloc(USB_CMD_DATA_SIZE);
535
536 // Query for the size of the trace
537 UsbCommand response;
538 GetFromBigBuf(trace, USB_CMD_DATA_SIZE, 0);
539 WaitForResponse(CMD_ACK, &response);
540 uint16_t traceLen = response.arg[2];
541 if (traceLen > USB_CMD_DATA_SIZE) {
542 uint8_t *p = realloc(trace, traceLen);
543 if (p == NULL) {
544 PrintAndLog("Cannot allocate memory for trace");
545 free(trace);
546 return 2;
547 }
548 trace = p;
549 GetFromBigBuf(trace, traceLen, 0);
550 WaitForResponse(CMD_ACK, NULL);
551 }
552
553 PrintAndLog("Recorded Activity (TraceLen = %d bytes)", traceLen);
4c3de57a
MHS
554 PrintAndLog("");
555 PrintAndLog("Start = Start of Start Bit, End = End of last modulation. Src = Source of Transfer");
556 PrintAndLog("iso14443a - All times are in carrier periods (1/13.56Mhz)");
557 PrintAndLog("iClass - Timings are not as accurate");
558 PrintAndLog("");
559 PrintAndLog(" Start | End | Src | Data (! denotes parity error) | CRC | Annotation |");
560 PrintAndLog("-----------|-----------|-----|-----------------------------------------------------------------|-----|--------------------|");
561
f71f4deb 562 while(tracepos < traceLen)
4c3de57a 563 {
f71f4deb 564 tracepos = printTraceLine(tracepos, traceLen, trace, protocol, showWaitCycles);
4c3de57a 565 }
f71f4deb 566
567 free(trace);
4c3de57a
MHS
568 return 0;
569}
570
7fe9b0b7 571
572static command_t CommandTable[] =
573{
574 {"help", CmdHelp, 1, "This help"},
37239a7c 575 {"14a", CmdHF14A, 1, "{ ISO14443A RFIDs... }"},
576 {"14b", CmdHF14B, 1, "{ ISO14443B RFIDs... }"},
577 {"15", CmdHF15, 1, "{ ISO15693 RFIDs... }"},
5acd09bd 578 {"epa", CmdHFEPA, 1, "{ German Identification Card... }"},
8e220a91 579 {"legic", CmdHFLegic, 0, "{ LEGIC RFIDs... }"},
cee5a30d 580 {"iclass", CmdHFiClass, 1, "{ ICLASS RFIDs... }"},
4c3de57a 581 {"mf", CmdHFMF, 1, "{ MIFARE RFIDs... }"},
5ee70129 582 {"mfu", CmdHFMFUltra, 1, "{ MIFARE Ultralight RFIDs... }"},
c59c3405 583 {"tune", CmdHFTune, 0, "Continuously measure HF antenna tuning"},
4c3de57a
MHS
584 {"list", CmdHFList, 1, "List protocol data in trace buffer"},
585 {NULL, NULL, 0, NULL}
7fe9b0b7 586};
587
588int CmdHF(const char *Cmd)
589{
590 CmdsParse(CommandTable, Cmd);
591 return 0;
592}
593
594int CmdHelp(const char *Cmd)
595{
596 CmdsHelp(CommandTable);
597 return 0;
598}
Impressum, Datenschutz