1 //-----------------------------------------------------------------------------
2 // Copyright (C) 2010 iZsh <izsh at fail0verflow.com>
3 // Copyright (C) Merlok - 2017
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 // Command: hf list. It shows data from arm buffer.
10 //-----------------------------------------------------------------------------
12 #include "cmdhflist.h"
21 #include "cliparser/cliparser.h"
23 #include "iso14443crc.h"
24 #include "iso15693tools.h"
26 #include "protocols.h"
27 #include "crapto1/crapto1.h"
28 #include "mifare/mifarehost.h"
29 #include "mifare/mifaredefault.h"
35 uint32_t nt
; // tag challenge
36 uint32_t nt_enc
; // encrypted tag challenge
37 uint8_t nt_enc_par
; // encrypted tag challenge parity
38 uint32_t nr_enc
; // encrypted reader challenge
39 uint32_t ar_enc
; // encrypted reader response
40 uint8_t ar_enc_par
; // encrypted reader response parity
41 uint32_t at_enc
; // encrypted tag response
42 uint8_t at_enc_par
; // encrypted tag response parity
43 bool first_auth
; // is first authentication
44 uint32_t ks2
; // ar ^ ar_enc
45 uint32_t ks3
; // at ^ at_enc
59 static enum MifareAuthSeq MifareAuthState
;
60 static TAuthData AuthData
;
62 static void ClearAuthData() {
65 AuthData
.first_auth
= true;
71 * @brief iso14443A_CRC_check Checks CRC in command or response
75 * @return 0 : CRC-command, CRC not ok
76 * 1 : CRC-command, CRC ok
79 static uint8_t iso14443A_CRC_check(bool isResponse
, uint8_t* data
, uint8_t len
)
83 if(len
<= 2) return 2;
85 if(isResponse
& (len
< 6)) return 2;
87 ComputeCrc14443(CRC_14443_A
, data
, len
-2, &b1
, &b2
);
88 if (b1
!= data
[len
-2] || b2
!= data
[len
-1]) {
96 static uint8_t iso14443_4_CRC_check(uint8_t* data
, uint8_t len
)
100 if(len
<= 2) return 2;
102 ComputeCrc14443(CRC_14443_A
, data
, len
-2, &b1
, &b2
);
103 if (b1
!= data
[len
-2] || b2
!= data
[len
-1]) {
111 static uint8_t mifare_CRC_check(bool isResponse
, uint8_t* data
, uint8_t len
)
113 switch(MifareAuthState
) {
116 return iso14443A_CRC_check(isResponse
, data
, len
);
124 * @brief iso14443B_CRC_check Checks CRC in command or response
128 * @return 0 : CRC-command, CRC not ok
129 * 1 : CRC-command, CRC ok
130 * 2 : Not crc-command
132 static uint8_t iso14443B_CRC_check(bool isResponse
, uint8_t* data
, uint8_t len
)
136 if(len
<= 2) return 2;
138 ComputeCrc14443(CRC_14443_B
, data
, len
-2, &b1
, &b2
);
139 if(b1
!= data
[len
-2] || b2
!= data
[len
-1]) {
147 static uint8_t iso15693_CRC_check(uint8_t* d
, uint16_t n
)
149 if (n
<= 2) return 2;
151 return (Iso15693Crc(d
, n
) == ISO15693_CRC_CHECK
? 1 : 0);
156 * @brief iclass_CRC_Ok Checks CRC in command or response
160 * @return 0 : CRC-command, CRC not ok
161 * 1 : CRC-command, CRC ok
162 * 2 : Not crc-command
164 uint8_t iclass_CRC_check(bool isResponse
, uint8_t* data
, uint8_t len
)
166 if(len
< 4) return 2;//CRC commands (and responses) are all at least 4 bytes
170 if(!isResponse
)//Commands to tag
173 These commands should have CRC. Total length leftmost
176 12 UPDATE - unsecured, ends with CRC16
177 14 UPDATE - secured, ends with signature instead
180 if(len
== 4 || len
== 12)//Covers three of them
182 //Don't include the command byte
183 ComputeCrc14443(CRC_ICLASS
, (data
+1), len
-3, &b1
, &b2
);
184 return b1
== data
[len
-2] && b2
== data
[len
-1];
189 These tag responses should have CRC. Total length leftmost
191 10 READ data[8] crc[2]
192 34 READ4 data[32]crc[2]
193 10 UPDATE data[8] crc[2]
194 10 SELECT csn[8] crc[2]
195 10 IDENTIFY asnb[8] crc[2]
196 10 PAGESEL block1[8] crc[2]
197 10 DETECT csn[8] crc[2]
201 4 CHECK chip_response[4]
206 In conclusion, without looking at the command; any response
207 of length 10 or 34 should have CRC
209 if(len
!= 10 && len
!= 34) return true;
211 ComputeCrc14443(CRC_ICLASS
, data
, len
-2, &b1
, &b2
);
212 return b1
== data
[len
-2] && b2
== data
[len
-1];
217 void annotateIclass(char *exp
, size_t size
, uint8_t* cmd
, uint8_t cmdsize
) {
220 case ICLASS_CMD_ACTALL
: snprintf(exp
, size
, "ACTALL"); break;
221 case ICLASS_CMD_READ_OR_IDENTIFY
: {
223 snprintf(exp
,size
,"READ(%d)",cmd
[1]);
225 snprintf(exp
,size
,"IDENTIFY");
229 case ICLASS_CMD_SELECT
: snprintf(exp
,size
, "SELECT"); break;
230 case ICLASS_CMD_PAGESEL
: snprintf(exp
,size
, "PAGESEL(%d)", cmd
[1]); break;
231 case ICLASS_CMD_READCHECK_KC
: snprintf(exp
,size
, "READCHECK[Kc](%d)", cmd
[1]); break;
232 case ICLASS_CMD_READCHECK_KD
: snprintf(exp
,size
, "READCHECK[Kd](%d)", cmd
[1]); break;
233 case ICLASS_CMD_CHECK_KC
:
234 case ICLASS_CMD_CHECK_KD
: snprintf(exp
,size
, "CHECK"); break;
235 case ICLASS_CMD_DETECT
: snprintf(exp
,size
, "DETECT"); break;
236 case ICLASS_CMD_HALT
: snprintf(exp
,size
, "HALT"); break;
237 case ICLASS_CMD_UPDATE
: snprintf(exp
,size
, "UPDATE(%d)",cmd
[1]); break;
238 case ICLASS_CMD_ACT
: snprintf(exp
,size
, "ACT"); break;
239 case ICLASS_CMD_READ4
: snprintf(exp
,size
, "READ4(%d)",cmd
[1]); break;
240 default: snprintf(exp
,size
, "?"); break;
246 void annotateIso15693(char *exp
, size_t size
, uint8_t* cmd
, uint8_t cmdsize
) {
249 // Mandatory Commands, all Tags must support them:
250 case ISO15693_INVENTORY
:snprintf(exp
, size
, "INVENTORY");return;
251 case ISO15693_STAYQUIET
:snprintf(exp
, size
, "STAY_QUIET");return;
252 // Optional Commands, Tags may support them:
253 case ISO15693_READBLOCK
:snprintf(exp
, size
, "READBLOCK");return;
254 case ISO15693_WRITEBLOCK
:snprintf(exp
, size
, "WRITEBLOCK");return;
255 case ISO15693_LOCKBLOCK
:snprintf(exp
, size
, "LOCKBLOCK");return;
256 case ISO15693_READ_MULTI_BLOCK
:snprintf(exp
, size
, "READ_MULTI_BLOCK");return;
257 case ISO15693_WRITE_MULTI_BLOCK
:snprintf(exp
, size
, "WRITE_MULTI_BLOCK");return;
258 case ISO15693_SELECT
:snprintf(exp
, size
, "SELECT");return;
259 case ISO15693_RESET_TO_READY
:snprintf(exp
, size
, "RESET_TO_READY");return;
260 case ISO15693_WRITE_AFI
:snprintf(exp
, size
, "WRITE_AFI");return;
261 case ISO15693_LOCK_AFI
:snprintf(exp
, size
, "LOCK_AFI");return;
262 case ISO15693_WRITE_DSFID
:snprintf(exp
, size
, "WRITE_DSFID");return;
263 case ISO15693_LOCK_DSFID
:snprintf(exp
, size
, "LOCK_DSFID");return;
264 case ISO15693_GET_SYSTEM_INFO
:snprintf(exp
, size
, "GET_SYSTEM_INFO");return;
265 case ISO15693_READ_MULTI_SECSTATUS
:snprintf(exp
, size
, "READ_MULTI_SECSTATUS");return;
269 if (cmd
[1] > ISO15693_STAYQUIET
&& cmd
[1] < ISO15693_READBLOCK
) snprintf(exp
, size
, "Mandatory RFU");
270 else if (cmd
[1] > ISO15693_READ_MULTI_SECSTATUS
&& cmd
[1] <= 0x9F) snprintf(exp
, size
, "Optional RFU");
271 else if ( cmd
[1] >= 0xA0 && cmd
[1] <= 0xDF ) snprintf(exp
, size
, "Custom command");
272 else if ( cmd
[1] >= 0xE0 && cmd
[1] <= 0xFF ) snprintf(exp
, size
, "Proprietary command");
277 void annotateTopaz(char *exp
, size_t size
, uint8_t* cmd
, uint8_t cmdsize
)
280 case TOPAZ_REQA
:snprintf(exp
, size
, "REQA");break;
281 case TOPAZ_WUPA
:snprintf(exp
, size
, "WUPA");break;
282 case TOPAZ_RID
:snprintf(exp
, size
, "RID");break;
283 case TOPAZ_RALL
:snprintf(exp
, size
, "RALL");break;
284 case TOPAZ_READ
:snprintf(exp
, size
, "READ");break;
285 case TOPAZ_WRITE_E
:snprintf(exp
, size
, "WRITE-E");break;
286 case TOPAZ_WRITE_NE
:snprintf(exp
, size
, "WRITE-NE");break;
287 case TOPAZ_RSEG
:snprintf(exp
, size
, "RSEG");break;
288 case TOPAZ_READ8
:snprintf(exp
, size
, "READ8");break;
289 case TOPAZ_WRITE_E8
:snprintf(exp
, size
, "WRITE-E8");break;
290 case TOPAZ_WRITE_NE8
:snprintf(exp
, size
, "WRITE-NE8");break;
291 default: snprintf(exp
,size
,"?"); break;
296 void annotateIso7816(char *exp
, size_t size
, uint8_t* cmd
, uint8_t cmdsize
)
299 case ISO7816_READ_BINARY
:snprintf(exp
, size
, "READ BINARY");break;
300 case ISO7816_WRITE_BINARY
:snprintf(exp
, size
, "WRITE BINARY");break;
301 case ISO7816_UPDATE_BINARY
:snprintf(exp
, size
, "UPDATE BINARY");break;
302 case ISO7816_ERASE_BINARY
:snprintf(exp
, size
, "ERASE BINARY");break;
303 case ISO7816_READ_RECORDS
:snprintf(exp
, size
, "READ RECORD(S)");break;
304 case ISO7816_WRITE_RECORD
:snprintf(exp
, size
, "WRITE RECORD");break;
305 case ISO7816_APPEND_RECORD
:snprintf(exp
, size
, "APPEND RECORD");break;
306 case ISO7816_UPDATE_DATA
:snprintf(exp
, size
, "UPDATE DATA");break;
307 case ISO7816_GET_DATA
:snprintf(exp
, size
, "GET DATA");break;
308 case ISO7816_PUT_DATA
:snprintf(exp
, size
, "PUT DATA");break;
309 case ISO7816_SELECT_FILE
:snprintf(exp
, size
, "SELECT FILE");break;
310 case ISO7816_VERIFY
:snprintf(exp
, size
, "VERIFY");break;
311 case ISO7816_INTERNAL_AUTHENTICATE
:snprintf(exp
, size
, "INTERNAL AUTHENTICATE");break;
312 case ISO7816_EXTERNAL_AUTHENTICATE
:snprintf(exp
, size
, "EXTERNAL AUTHENTICATE");break;
313 case ISO7816_GET_CHALLENGE
:snprintf(exp
, size
, "GET CHALLENGE");break;
314 case ISO7816_MANAGE_CHANNEL
:snprintf(exp
, size
, "MANAGE CHANNEL");break;
315 case ISO7816_GET_RESPONSE
:snprintf(exp
, size
, "GET RESPONSE");break;
316 case ISO7816_ENVELOPE
:snprintf(exp
, size
, "ENVELOPE");break;
317 case ISO7816_GET_PROCESSING_OPTIONS
:snprintf(exp
, size
, "GET PROCESSING OPTIONS");break;
318 default :snprintf(exp
,size
,"?"); break;
323 void annotateIso14443_4(char *exp
, size_t size
, uint8_t* cmd
, uint8_t cmdsize
) {
325 if ((cmd
[0] & 0xc3) == 0xc2) {
326 switch (cmd
[0] & 0x30) {
327 case 0x00 : snprintf(exp
, size
, "S-block DESELECT"); break;
328 case 0x30 : snprintf(exp
, size
, "S-block WTX"); break;
329 default : snprintf(exp
, size
, "S-block (RFU)"); break;
333 else if ((cmd
[0] & 0xe0) == 0xa0) {
334 if ((cmd
[0] & 0x10) == 0)
335 snprintf(exp
, size
, "R-block ACK");
337 snprintf(exp
, size
, "R-block NACK");
342 switch (cmd
[0] & 0x0c) {
343 case 0x08: // CID following
344 case 0x04: // NAD following
347 case 0x0c: // CID and NAD following
351 pos
= 1; // no CID, no NAD
354 annotateIso7816(exp
, size
, &cmd
[pos
], cmdsize
-pos
);
361 0E xx = SELECT ID (xx = Chip-ID)
363 08 yy = Read Block (yy = block number)
364 09 yy dd dd dd dd = Write Block (yy = block number; dd dd dd dd = data to be written)
365 0C = Reset to Inventory
367 0A 11 22 33 44 55 66 = Authenticate (11 22 33 44 55 66 = data to authenticate)
370 void annotateIso14443b(char *exp
, size_t size
, uint8_t* cmd
, uint8_t cmdsize
) {
372 case ISO14443B_REQB
: snprintf(exp
,size
,"REQB");break;
373 case ISO14443B_ATTRIB
: snprintf(exp
,size
,"ATTRIB");break;
374 case ISO14443B_HALT
: snprintf(exp
,size
,"HALT");break;
375 case ISO14443B_INITIATE
: snprintf(exp
,size
,"INITIATE");break;
376 case ISO14443B_SELECT
: snprintf(exp
,size
,"SELECT(%d)",cmd
[1]);break;
377 case ISO14443B_GET_UID
: snprintf(exp
,size
,"GET UID");break;
378 case ISO14443B_READ_BLK
: snprintf(exp
,size
,"READ_BLK(%d)", cmd
[1]);break;
379 case ISO14443B_WRITE_BLK
: snprintf(exp
,size
,"WRITE_BLK(%d)",cmd
[1]);break;
380 case ISO14443B_RESET
: snprintf(exp
,size
,"RESET");break;
381 case ISO14443B_COMPLETION
: snprintf(exp
,size
,"COMPLETION");break;
382 case ISO14443B_AUTHENTICATE
: snprintf(exp
,size
,"AUTHENTICATE");break;
383 default : snprintf(exp
,size
,"?");break;
388 void annotateIso14443a(char *exp
, size_t size
, uint8_t* cmd
, uint8_t cmdsize
) {
391 case ISO14443A_CMD_WUPA
:
392 snprintf(exp
,size
,"WUPA");
394 case ISO14443A_CMD_ANTICOLL_OR_SELECT
:{
395 // 93 20 = Anticollision (usage: 9320 - answer: 4bytes UID+1byte UID-bytes-xor)
396 // 93 70 = Select (usage: 9370+5bytes 9320 answer - answer: 1byte SAK)
399 snprintf(exp
,size
,"SELECT_UID"); break;
402 snprintf(exp
,size
,"ANTICOLL"); break;
405 case ISO14443A_CMD_ANTICOLL_OR_SELECT_2
:{
406 //95 20 = Anticollision of cascade level2
407 //95 70 = Select of cascade level2
410 snprintf(exp
,size
,"SELECT_UID-2"); break;
413 snprintf(exp
,size
,"ANTICOLL-2"); break;
416 case ISO14443A_CMD_REQA
:
417 snprintf(exp
,size
,"REQA");
419 case MIFARE_CMD_READBLOCK
: snprintf(exp
,size
,"READBLOCK(%d)",cmd
[1]); break;
420 case MIFARE_CMD_WRITEBLOCK
: snprintf(exp
,size
,"WRITEBLOCK(%d)",cmd
[1]); break;
421 case ISO14443A_CMD_HALT
:
422 snprintf(exp
,size
,"HALT");
423 MifareAuthState
= masNone
;
425 case ISO14443A_CMD_RATS
: snprintf(exp
,size
,"RATS"); break;
426 case MIFARE_CMD_INC
: snprintf(exp
,size
,"INC(%d)",cmd
[1]); break;
427 case MIFARE_CMD_DEC
: snprintf(exp
,size
,"DEC(%d)",cmd
[1]); break;
428 case MIFARE_CMD_RESTORE
: snprintf(exp
,size
,"RESTORE(%d)",cmd
[1]); break;
429 case MIFARE_CMD_TRANSFER
: snprintf(exp
,size
,"TRANSFER(%d)",cmd
[1]); break;
430 case MIFARE_AUTH_KEYA
:
432 snprintf(exp
,size
,"AUTH-A(%d)",cmd
[1]);
433 MifareAuthState
= masNt
;
435 // case MIFARE_ULEV1_VERSION : both 0x60.
436 snprintf(exp
,size
,"EV1 VERSION");
439 case MIFARE_AUTH_KEYB
:
440 MifareAuthState
= masNt
;
441 snprintf(exp
,size
,"AUTH-B(%d)",cmd
[1]);
443 case MIFARE_MAGICWUPC1
: snprintf(exp
,size
,"MAGIC WUPC1"); break;
444 case MIFARE_MAGICWUPC2
: snprintf(exp
,size
,"MAGIC WUPC2"); break;
445 case MIFARE_MAGICWIPEC
: snprintf(exp
,size
,"MAGIC WIPEC"); break;
446 case MIFARE_ULC_AUTH_1
: snprintf(exp
,size
,"AUTH "); break;
447 case MIFARE_ULC_AUTH_2
: snprintf(exp
,size
,"AUTH_ANSW"); break;
448 case MIFARE_ULEV1_AUTH
:
450 snprintf(exp
,size
,"PWD-AUTH KEY: 0x%02x%02x%02x%02x", cmd
[1], cmd
[2], cmd
[3], cmd
[4] );
452 snprintf(exp
,size
,"PWD-AUTH");
454 case MIFARE_ULEV1_FASTREAD
:{
455 if ( cmdsize
>=3 && cmd
[2] <= 0xE6)
456 snprintf(exp
,size
,"READ RANGE (%d-%d)",cmd
[1],cmd
[2]);
458 snprintf(exp
,size
,"?");
461 case MIFARE_ULC_WRITE
:{
463 snprintf(exp
,size
,"WRITEBLOCK(%d)",cmd
[1]);
465 snprintf(exp
,size
,"?");
468 case MIFARE_ULEV1_READ_CNT
:{
470 snprintf(exp
,size
,"READ CNT(%d)",cmd
[1]);
472 snprintf(exp
,size
,"?");
475 case MIFARE_ULEV1_INCR_CNT
:{
477 snprintf(exp
,size
,"INCR(%d)",cmd
[1]);
479 snprintf(exp
,size
,"?");
482 case MIFARE_ULEV1_READSIG
: snprintf(exp
,size
,"READ_SIG"); break;
483 case MIFARE_ULEV1_CHECKTEAR
: snprintf(exp
,size
,"CHK_TEARING(%d)",cmd
[1]); break;
484 case MIFARE_ULEV1_VCSL
: snprintf(exp
,size
,"VCSL"); break;
485 default: snprintf(exp
,size
,"?"); break;
490 void annotateMifare(char *exp
, size_t size
, uint8_t* cmd
, uint8_t cmdsize
, uint8_t* parity
, uint8_t paritysize
, bool isResponse
) {
491 if (!isResponse
&& cmdsize
== 1) {
493 case ISO14443A_CMD_WUPA
:
494 case ISO14443A_CMD_REQA
:
495 MifareAuthState
= masNone
;
503 if (MifareAuthState
== masNone
) {
504 if (cmdsize
== 9 && cmd
[0] == ISO14443A_CMD_ANTICOLL_OR_SELECT
&& cmd
[1] == 0x70) {
506 AuthData
.uid
= bytes_to_num(&cmd
[2], 4);
508 if (cmdsize
== 9 && cmd
[0] == ISO14443A_CMD_ANTICOLL_OR_SELECT_2
&& cmd
[1] == 0x70) {
510 AuthData
.uid
= bytes_to_num(&cmd
[2], 4);
514 switch(MifareAuthState
) {
516 if (cmdsize
== 4 && isResponse
) {
517 snprintf(exp
,size
,"AUTH: nt %s", (AuthData
.first_auth
) ? "" : "(enc)");
518 MifareAuthState
= masNrAr
;
519 if (AuthData
.first_auth
) {
520 AuthData
.nt
= bytes_to_num(cmd
, 4);
522 AuthData
.nt_enc
= bytes_to_num(cmd
, 4);
523 AuthData
.nt_enc_par
= parity
[0];
527 MifareAuthState
= masError
;
531 if (cmdsize
== 8 && !isResponse
) {
532 snprintf(exp
,size
,"AUTH: nr ar (enc)");
533 MifareAuthState
= masAt
;
534 AuthData
.nr_enc
= bytes_to_num(cmd
, 4);
535 AuthData
.ar_enc
= bytes_to_num(&cmd
[4], 4);
536 AuthData
.ar_enc_par
= parity
[0] << 4;
539 MifareAuthState
= masError
;
543 if (cmdsize
== 4 && isResponse
) {
544 snprintf(exp
,size
,"AUTH: at (enc)");
545 MifareAuthState
= masAuthComplete
;
546 AuthData
.at_enc
= bytes_to_num(cmd
, 4);
547 AuthData
.at_enc_par
= parity
[0];
550 MifareAuthState
= masError
;
557 if (!isResponse
&& ((MifareAuthState
== masNone
) || (MifareAuthState
== masError
)))
558 annotateIso14443a(exp
, size
, cmd
, cmdsize
);
563 static uint64_t GetCrypto1ProbableKey(TAuthData
*ad
) {
564 struct Crypto1State
*revstate
= lfsr_recovery64(ad
->ks2
, ad
->ks3
);
565 lfsr_rollback_word(revstate
, 0, 0);
566 lfsr_rollback_word(revstate
, 0, 0);
567 lfsr_rollback_word(revstate
, ad
->nr_enc
, 1);
568 lfsr_rollback_word(revstate
, ad
->uid
^ ad
->nt
, 0);
571 crypto1_get_lfsr(revstate
, &lfsr
);
572 crypto1_destroy(revstate
);
578 static bool NTParityChk(TAuthData
*ad
, uint32_t ntx
) {
580 (oddparity8(ntx
>> 8 & 0xff) ^ (ntx
& 0x01) ^ ((ad
->nt_enc_par
>> 5) & 0x01) ^ (ad
->nt_enc
& 0x01)) ||
581 (oddparity8(ntx
>> 16 & 0xff) ^ (ntx
>> 8 & 0x01) ^ ((ad
->nt_enc_par
>> 6) & 0x01) ^ (ad
->nt_enc
>> 8 & 0x01)) ||
582 (oddparity8(ntx
>> 24 & 0xff) ^ (ntx
>> 16 & 0x01) ^ ((ad
->nt_enc_par
>> 7) & 0x01) ^ (ad
->nt_enc
>> 16 & 0x01))
586 uint32_t ar
= prng_successor(ntx
, 64);
588 (oddparity8(ar
>> 8 & 0xff) ^ (ar
& 0x01) ^ ((ad
->ar_enc_par
>> 5) & 0x01) ^ (ad
->ar_enc
& 0x01)) ||
589 (oddparity8(ar
>> 16 & 0xff) ^ (ar
>> 8 & 0x01) ^ ((ad
->ar_enc_par
>> 6) & 0x01) ^ (ad
->ar_enc
>> 8 & 0x01)) ||
590 (oddparity8(ar
>> 24 & 0xff) ^ (ar
>> 16 & 0x01) ^ ((ad
->ar_enc_par
>> 7) & 0x01) ^ (ad
->ar_enc
>> 16 & 0x01))
594 uint32_t at
= prng_successor(ntx
, 96);
596 (oddparity8(ar
& 0xff) ^ (at
>> 24 & 0x01) ^ ((ad
->ar_enc_par
>> 4) & 0x01) ^ (ad
->at_enc
>> 24 & 0x01)) ||
597 (oddparity8(at
>> 8 & 0xff) ^ (at
& 0x01) ^ ((ad
->at_enc_par
>> 5) & 0x01) ^ (ad
->at_enc
& 0x01)) ||
598 (oddparity8(at
>> 16 & 0xff) ^ (at
>> 8 & 0x01) ^ ((ad
->at_enc_par
>> 6) & 0x01) ^ (ad
->at_enc
>> 8 & 0x01)) ||
599 (oddparity8(at
>> 24 & 0xff) ^ (at
>> 16 & 0x01) ^ ((ad
->at_enc_par
>> 7) & 0x01) ^ (ad
->at_enc
>> 16 & 0x01))
607 static bool CheckCrypto1Parity(uint8_t *cmd_enc
, uint8_t cmdsize
, uint8_t *cmd
, uint8_t *parity_enc
) {
608 for (int i
= 0; i
< cmdsize
- 1; i
++) {
609 if (oddparity8(cmd
[i
]) ^ (cmd
[i
+ 1] & 0x01) ^ ((parity_enc
[i
/ 8] >> (7 - i
% 8)) & 0x01) ^ (cmd_enc
[i
+ 1] & 0x01))
617 static bool NestedCheckKey(uint64_t key
, TAuthData
*ad
, uint8_t *cmd
, uint8_t cmdsize
, uint8_t *parity
) {
618 uint8_t buf
[32] = {0};
619 struct Crypto1State
*pcs
;
624 pcs
= crypto1_create(key
);
625 uint32_t nt1
= crypto1_word(pcs
, ad
->nt_enc
^ ad
->uid
, 1) ^ ad
->nt_enc
;
626 uint32_t ar
= prng_successor(nt1
, 64);
627 uint32_t at
= prng_successor(nt1
, 96);
629 crypto1_word(pcs
, ad
->nr_enc
, 1);
630 // uint32_t nr1 = crypto1_word(pcs, ad->nr_enc, 1) ^ ad->nr_enc; // if needs deciphered nr
631 uint32_t ar1
= crypto1_word(pcs
, 0, 0) ^ ad
->ar_enc
;
632 uint32_t at1
= crypto1_word(pcs
, 0, 0) ^ ad
->at_enc
;
634 if (!(ar
== ar1
&& at
== at1
&& NTParityChk(ad
, nt1
))) {
635 crypto1_destroy(pcs
);
639 memcpy(buf
, cmd
, cmdsize
);
640 mf_crypto1_decrypt(pcs
, buf
, cmdsize
, 0);
642 crypto1_destroy(pcs
);
644 if (!CheckCrypto1Parity(cmd
, cmdsize
, buf
, parity
))
647 if(!CheckCrc14443(CRC_14443_A
, buf
, cmdsize
))
651 AuthData
.ks2
= AuthData
.ar_enc
^ ar
;
652 AuthData
.ks3
= AuthData
.at_enc
^ at
;
658 static bool DecodeMifareData(uint8_t *cmd
, uint8_t cmdsize
, uint8_t *parity
, bool isResponse
, uint8_t *mfData
, size_t *mfDataLen
) {
659 static struct Crypto1State
*traceCrypto1
;
660 static uint64_t mfLastKey
;
664 if (MifareAuthState
== masAuthComplete
) {
666 crypto1_destroy(traceCrypto1
);
670 MifareAuthState
= masFirstData
;
677 if (MifareAuthState
== masFirstData
) {
678 if (AuthData
.first_auth
) {
679 AuthData
.ks2
= AuthData
.ar_enc
^ prng_successor(AuthData
.nt
, 64);
680 AuthData
.ks3
= AuthData
.at_enc
^ prng_successor(AuthData
.nt
, 96);
682 mfLastKey
= GetCrypto1ProbableKey(&AuthData
);
683 PrintAndLog(" | * | key | probable key:%012"PRIx64
" Prng:%s ks2:%08x ks3:%08x | |",
685 validate_prng_nonce(AuthData
.nt
) ? "WEAK": "HARD",
689 AuthData
.first_auth
= false;
691 traceCrypto1
= lfsr_recovery64(AuthData
.ks2
, AuthData
.ks3
);
694 crypto1_destroy(traceCrypto1
);
698 // check last used key
700 if (NestedCheckKey(mfLastKey
, &AuthData
, cmd
, cmdsize
, parity
)) {
701 PrintAndLog(" | * | key | last used key:%012"PRIx64
" ks2:%08x ks3:%08x | |",
706 traceCrypto1
= lfsr_recovery64(AuthData
.ks2
, AuthData
.ks3
);
710 // check default keys
712 for (int defaultKeyCounter
= 0; defaultKeyCounter
< MifareDefaultKeysSize
; defaultKeyCounter
++){
713 if (NestedCheckKey(MifareDefaultKeys
[defaultKeyCounter
], &AuthData
, cmd
, cmdsize
, parity
)) {
714 PrintAndLog(" | * | key | default key:%012"PRIx64
" ks2:%08x ks3:%08x | |",
715 MifareDefaultKeys
[defaultKeyCounter
],
719 mfLastKey
= MifareDefaultKeys
[defaultKeyCounter
];
720 traceCrypto1
= lfsr_recovery64(AuthData
.ks2
, AuthData
.ks3
);
727 if (!traceCrypto1
&& validate_prng_nonce(AuthData
.nt
)) {
728 uint32_t ntx
= prng_successor(AuthData
.nt
, 90);
729 for (int i
= 0; i
< 16383; i
++) {
730 ntx
= prng_successor(ntx
, 1);
731 if (NTParityChk(&AuthData
, ntx
)){
733 uint32_t ks2
= AuthData
.ar_enc
^ prng_successor(ntx
, 64);
734 uint32_t ks3
= AuthData
.at_enc
^ prng_successor(ntx
, 96);
735 struct Crypto1State
*pcs
= lfsr_recovery64(ks2
, ks3
);
736 memcpy(mfData
, cmd
, cmdsize
);
737 mf_crypto1_decrypt(pcs
, mfData
, cmdsize
, 0);
739 crypto1_destroy(pcs
);
740 if (CheckCrypto1Parity(cmd
, cmdsize
, mfData
, parity
) && CheckCrc14443(CRC_14443_A
, mfData
, cmdsize
)) {
745 mfLastKey
= GetCrypto1ProbableKey(&AuthData
);
746 PrintAndLog(" | * | key | nested probable key:%012"PRIx64
" ks2:%08x ks3:%08x | |",
751 traceCrypto1
= lfsr_recovery64(AuthData
.ks2
, AuthData
.ks3
);
760 printf("hardnested not implemented. uid:%x nt:%x ar_enc:%x at_enc:%x\n", AuthData
.uid
, AuthData
.nt
, AuthData
.ar_enc
, AuthData
.at_enc
);
761 MifareAuthState
= masError
;
763 /* TOO SLOW( needs to have more strong filter. with this filter - aprox 4 mln tests
764 uint32_t t = msclock();
767 for (uint32_t i = 0; i < 0xFFFFFFFF; i++) {
768 if (NTParityChk(&AuthData, i)){
770 uint32_t ks2 = AuthData.ar_enc ^ prng_successor(i, 64);
771 uint32_t ks3 = AuthData.at_enc ^ prng_successor(i, 96);
772 struct Crypto1State *pcs = lfsr_recovery64(ks2, ks3);
780 printf("delta=%d n=%d ks2=%x ks3=%x \n", msclock() - t1 , n, ks2, ks3);
786 printf("delta=%d n=%d\n", msclock() - t, n);
793 MifareAuthState
= masData
;
796 if (MifareAuthState
== masData
&& traceCrypto1
) {
797 memcpy(mfData
, cmd
, cmdsize
);
798 mf_crypto1_decrypt(traceCrypto1
, mfData
, cmdsize
, 0);
799 *mfDataLen
= cmdsize
;
802 return *mfDataLen
> 0;
806 bool is_last_record(uint16_t tracepos
, uint8_t *trace
, uint16_t traceLen
) {
807 return(tracepos
+ sizeof(uint32_t) + sizeof(uint16_t) + sizeof(uint16_t) >= traceLen
);
811 bool next_record_is_response(uint16_t tracepos
, uint8_t *trace
) {
812 uint16_t next_records_datalen
= *((uint16_t *)(trace
+ tracepos
+ sizeof(uint32_t) + sizeof(uint16_t)));
813 return(next_records_datalen
& 0x8000);
817 bool 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
) {
819 #define MAX_TOPAZ_READER_CMD_LEN 16
821 uint32_t last_timestamp
= timestamp
+ *duration
;
823 if ((*data_len
!= 1) || (frame
[0] == TOPAZ_WUPA
) || (frame
[0] == TOPAZ_REQA
)) return false;
825 memcpy(topaz_reader_command
, frame
, *data_len
);
827 while (!is_last_record(*tracepos
, trace
, traceLen
) && !next_record_is_response(*tracepos
, trace
)) {
828 uint32_t next_timestamp
= *((uint32_t *)(trace
+ *tracepos
));
829 *tracepos
+= sizeof(uint32_t);
830 uint16_t next_duration
= *((uint16_t *)(trace
+ *tracepos
));
831 *tracepos
+= sizeof(uint16_t);
832 uint16_t next_data_len
= *((uint16_t *)(trace
+ *tracepos
)) & 0x7FFF;
833 *tracepos
+= sizeof(uint16_t);
834 uint8_t *next_frame
= (trace
+ *tracepos
);
835 *tracepos
+= next_data_len
;
836 if ((next_data_len
== 1) && (*data_len
+ next_data_len
<= MAX_TOPAZ_READER_CMD_LEN
)) {
837 memcpy(topaz_reader_command
+ *data_len
, next_frame
, next_data_len
);
838 *data_len
+= next_data_len
;
839 last_timestamp
= next_timestamp
+ next_duration
;
842 *tracepos
= *tracepos
- next_data_len
- sizeof(uint16_t) - sizeof(uint16_t) - sizeof(uint32_t);
845 uint16_t next_parity_len
= (next_data_len
-1)/8 + 1;
846 *tracepos
+= next_parity_len
;
849 *duration
= last_timestamp
- timestamp
;
855 uint16_t printTraceLine(uint16_t tracepos
, uint16_t traceLen
, uint8_t *trace
, uint8_t protocol
, bool showWaitCycles
, bool markCRCBytes
, uint32_t *prev_EOT
, bool times_in_us
) {
857 uint16_t data_len
, parity_len
;
859 uint8_t topaz_reader_command
[9];
860 uint32_t timestamp
, first_timestamp
;
861 uint32_t EndOfTransmissionTimestamp
= 0;
862 char explanation
[30] = {0};
863 uint8_t mfData
[32] = {0};
864 size_t mfDataLen
= 0;
866 if (tracepos
+ sizeof(uint32_t) + sizeof(uint16_t) + sizeof(uint16_t) > traceLen
) return traceLen
;
868 first_timestamp
= *((uint32_t *)(trace
));
869 timestamp
= *((uint32_t *)(trace
+ tracepos
));
872 duration
= *((uint16_t *)(trace
+ tracepos
));
874 data_len
= *((uint16_t *)(trace
+ tracepos
));
877 if (data_len
& 0x8000) {
883 parity_len
= (data_len
-1)/8 + 1;
885 if (tracepos
+ data_len
+ parity_len
> traceLen
) {
888 uint8_t *frame
= trace
+ tracepos
;
889 tracepos
+= data_len
;
890 uint8_t *parityBytes
= trace
+ tracepos
;
891 tracepos
+= parity_len
;
893 if (protocol
== TOPAZ
&& !isResponse
) {
894 // topaz reader commands come in 1 or 9 separate frames with 7 or 8 Bits each.
896 if (merge_topaz_reader_frames(timestamp
, &duration
, &tracepos
, traceLen
, trace
, frame
, topaz_reader_command
, &data_len
)) {
897 frame
= topaz_reader_command
;
901 // adjust for different time scales
902 if (protocol
== ICLASS
|| protocol
== ISO_15693
) {
906 //Check the CRC status
907 uint8_t crcStatus
= 2;
912 crcStatus
= iclass_CRC_check(isResponse
, frame
, data_len
);
916 crcStatus
= iso14443B_CRC_check(isResponse
, frame
, data_len
);
919 crcStatus
= mifare_CRC_check(isResponse
, frame
, data_len
);
922 crcStatus
= iso14443A_CRC_check(isResponse
, frame
, data_len
);
925 crcStatus
= iso14443_4_CRC_check(frame
, data_len
);
928 crcStatus
= iso15693_CRC_check(frame
, data_len
);
934 //0 CRC-command, CRC not ok
935 //1 CRC-command, CRC ok
938 //--- Draw the data column
941 for (int j
= 0; j
< data_len
&& j
/16 < 16; j
++) {
942 uint8_t parityBits
= parityBytes
[j
>>3];
943 if (protocol
!= ISO_14443B
944 && protocol
!= ISO_15693
945 && protocol
!= ICLASS
946 && protocol
!= ISO_7816_4
947 && (isResponse
|| protocol
== ISO_14443A
)
948 && (oddparity8(frame
[j
]) != ((parityBits
>> (7-(j
&0x0007))) & 0x01))) {
949 snprintf(line
[j
/16]+(( j
% 16) * 4), 110, " %02x!", frame
[j
]);
951 snprintf(line
[j
/16]+(( j
% 16) * 4), 110, " %02x ", frame
[j
]);
956 if (crcStatus
== 0 || crcStatus
== 1) { //CRC-command
957 char *pos1
= line
[(data_len
-2)/16]+(((data_len
-2) % 16) * 4);
959 char *pos2
= line
[(data_len
)/16]+(((data_len
) % 16) * 4);
960 sprintf(pos2
, "%c", ']');
964 // mark short bytes (less than 8 Bit + Parity)
965 if (protocol
== ISO_14443A
|| protocol
== PROTO_MIFARE
) {
966 if (duration
< 128 * (9 * data_len
)) {
967 line
[(data_len
-1)/16][((data_len
-1)%16) * 4 + 3] = '\'';
972 if (protocol
== ICLASS
&& duration
== 2048) {
973 sprintf(line
[0], " <SOF>");
974 } else if (protocol
== ISO_15693
&& duration
== 512) {
975 sprintf(line
[0], " <EOF>");
977 sprintf(line
[0], " <empty trace - possible error>");
981 //--- Draw the CRC column
982 char *crc
= (crcStatus
== 0 ? "!crc" : (crcStatus
== 1 ? " ok " : " "));
984 if (protocol
== PROTO_MIFARE
)
985 annotateMifare(explanation
, sizeof(explanation
), frame
, data_len
, parityBytes
, parity_len
, isResponse
);
989 case ICLASS
: annotateIclass(explanation
,sizeof(explanation
),frame
,data_len
); break;
990 case ISO_14443A
: annotateIso14443a(explanation
,sizeof(explanation
),frame
,data_len
); break;
991 case ISO_14443B
: annotateIso14443b(explanation
,sizeof(explanation
),frame
,data_len
); break;
992 case TOPAZ
: annotateTopaz(explanation
,sizeof(explanation
),frame
,data_len
); break;
993 case ISO_15693
: annotateIso15693(explanation
,sizeof(explanation
),frame
,data_len
); break;
994 case ISO_7816_4
: annotateIso7816(explanation
, sizeof(explanation
), frame
, data_len
); break;
995 case ISO_14443_4
: annotateIso14443_4(explanation
, sizeof(explanation
), frame
, data_len
); break;
1000 uint32_t previousEndOfTransmissionTimestamp
= 0;
1003 previousEndOfTransmissionTimestamp
= *prev_EOT
;
1005 previousEndOfTransmissionTimestamp
= timestamp
;
1008 EndOfTransmissionTimestamp
= timestamp
+ duration
;
1009 if (prev_EOT
) *prev_EOT
= EndOfTransmissionTimestamp
;
1011 int num_lines
= MIN((data_len
- 1)/16 + 1, 16);
1012 for (int j
= 0; j
< num_lines
; j
++) {
1014 uint32_t time1
= timestamp
- first_timestamp
;
1015 uint32_t time2
= EndOfTransmissionTimestamp
- first_timestamp
;
1017 time1
= timestamp
- previousEndOfTransmissionTimestamp
;
1021 PrintAndLog(" %10.1f | %10.1f | %s |%-64s | %s| %s",
1024 isResponse
? "Tag" : "Rdr",
1026 (j
== num_lines
-1) ? crc
: " ",
1027 (j
== num_lines
-1) ? explanation
: "");
1029 PrintAndLog(" %10" PRIu32
" | %10" PRIu32
" | %s |%-64s | %s| %s",
1032 isResponse
? "Tag" : "Rdr",
1034 (j
== num_lines
-1) ? crc
: " ",
1035 (j
== num_lines
-1) ? explanation
: "");
1038 PrintAndLog(" | | |%-64s | %s| %s",
1040 (j
== num_lines
-1) ? crc
: " ",
1041 (j
== num_lines
-1) ? explanation
: "");
1045 if (DecodeMifareData(frame
, data_len
, parityBytes
, isResponse
, mfData
, &mfDataLen
)) {
1046 memset(explanation
, 0x00, sizeof(explanation
));
1048 explanation
[0] = '>';
1049 annotateIso14443a(&explanation
[1], sizeof(explanation
) - 1, mfData
, mfDataLen
);
1051 uint8_t crcc
= iso14443A_CRC_check(isResponse
, mfData
, mfDataLen
);
1052 PrintAndLog(" | * | dec |%-64s | %-4s| %s",
1053 sprint_hex(mfData
, mfDataLen
),
1054 (crcc
== 0 ? "!crc" : (crcc
== 1 ? " ok " : " ")),
1055 (true) ? explanation
: "");
1058 if (is_last_record(tracepos
, trace
, traceLen
)) return traceLen
;
1060 if (showWaitCycles
&& !isResponse
&& next_record_is_response(tracepos
, trace
)) {
1061 uint32_t next_timestamp
= *((uint32_t *)(trace
+ tracepos
));
1063 PrintAndLog(" %10d | %10d | %s | fdt (Frame Delay Time): %d",
1064 (EndOfTransmissionTimestamp
- first_timestamp
),
1065 (next_timestamp
- first_timestamp
),
1067 (next_timestamp
- EndOfTransmissionTimestamp
));
1074 int CmdHFList(const char *Cmd
) {
1076 CLIParserInit("hf list", "\nList or save protocol data.",
1077 "examples: hf list 14a -f -- interpret as ISO14443A communication and display Frame Delay Times\n"\
1078 " hf list iclass -- interpret as iClass trace\n"\
1079 " hf list -s myCardTrace.trc -- save trace for later use\n"\
1080 " hf list 14a -l myCardTrace.trc -- load trace and interpret as ISO14443A communication\n");
1081 void* argtable
[] = {
1083 arg_lit0("f", "fdt", "display fdt (frame delay times)"),
1084 arg_lit0("r", "relative", "show relative times (gap and duration)"),
1085 arg_lit0("c", "crc" , "mark CRC bytes"),
1086 arg_lit0("p", "pcsc", "show trace buffer from PCSC card reader instead of PM3"),
1087 arg_str0("l", "load", "<filename>", "load trace from file"),
1088 arg_str0("s", "save", "<filename>", "save trace to file"),
1089 arg_lit0("u", "us", "display times in microseconds instead of clock cycles"),
1090 arg_str0(NULL
, NULL
, "<protocol>", "protocol to interpret. Possible values:\n"\
1091 "\traw - just show raw data without annotations (default)\n"\
1092 "\t14a - interpret data as ISO14443A communications\n"\
1093 "\tmf - interpret data as ISO14443A communications and decrypt Mifare Crypto1 stream\n"\
1094 "\t14b - interpret data as ISO14443B communications\n"\
1095 "\t15 - interpret data as ISO15693 communications\n"\
1096 "\ticlass - interpret data as iClass communications\n"\
1097 "\ttopaz - interpret data as Topaz communications\n"\
1098 "\t7816 - interpret data as 7816-4 APDU communications\n"\
1099 "\t14-4 - interpret data as ISO14443-4 communications"),
1103 if (CLIParserParseString(Cmd
, argtable
, arg_getsize(argtable
), true)){
1108 bool showWaitCycles
= arg_get_lit(1);
1109 bool relative_times
= arg_get_lit(2);
1110 bool markCRCBytes
= arg_get_lit(3);
1111 bool PCSCtrace
= arg_get_lit(4);
1112 bool loadFromFile
= arg_get_str_len(5);
1113 bool saveToFile
= arg_get_str_len(6);
1114 bool times_in_us
= arg_get_lit(7);
1116 uint32_t previous_EOT
= 0;
1117 uint32_t *prev_EOT
= NULL
;
1118 if (relative_times
) {
1119 prev_EOT
= &previous_EOT
;
1122 char load_filename
[FILE_PATH_SIZE
] = {0};
1124 strncpy(load_filename
, arg_get_str(5)->sval
[0], FILE_PATH_SIZE
);
1126 char save_filename
[FILE_PATH_SIZE
] = {0};
1128 strncpy(save_filename
, arg_get_str(6)->sval
[0], FILE_PATH_SIZE
);
1131 uint8_t protocol
= -1;
1132 if (arg_get_str_len(8)) {
1133 if (strcmp(arg_get_str(8)->sval
[0], "iclass") == 0) protocol
= ICLASS
;
1134 else if(strcmp(arg_get_str(8)->sval
[0], "14a") == 0) protocol
= ISO_14443A
;
1135 else if(strcmp(arg_get_str(8)->sval
[0], "mf") == 0) protocol
= PROTO_MIFARE
;
1136 else if(strcmp(arg_get_str(8)->sval
[0], "14b") == 0) protocol
= ISO_14443B
;
1137 else if(strcmp(arg_get_str(8)->sval
[0], "topaz") == 0) protocol
= TOPAZ
;
1138 else if(strcmp(arg_get_str(8)->sval
[0], "7816") == 0) protocol
= ISO_7816_4
;
1139 else if(strcmp(arg_get_str(8)->sval
[0], "14-4") == 0) protocol
= ISO_14443_4
;
1140 else if(strcmp(arg_get_str(8)->sval
[0], "15") == 0) protocol
= ISO_15693
;
1141 else if(strcmp(arg_get_str(8)->sval
[0], "raw") == 0) protocol
= -1;//No crc, no annotations
1143 PrintAndLog("hf list: invalid argument \"%s\"\nTry 'hf list --help' for more information.", arg_get_str(8)->sval
[0]);
1153 uint32_t tracepos
= 0;
1154 uint32_t traceLen
= 0;
1157 #define TRACE_CHUNK_SIZE (1<<16) // 64K to start with. Will be enough for BigBuf and some room for future extensions
1158 FILE *tracefile
= NULL
;
1160 trace
= malloc(TRACE_CHUNK_SIZE
);
1161 if (trace
== NULL
) {
1162 PrintAndLog("Cannot allocate memory for trace");
1165 if ((tracefile
= fopen(load_filename
,"rb")) == NULL
) {
1166 PrintAndLog("Could not open file %s", load_filename
);
1170 while (!feof(tracefile
)) {
1171 bytes_read
= fread(trace
+traceLen
, 1, TRACE_CHUNK_SIZE
, tracefile
);
1172 traceLen
+= bytes_read
;
1173 if (!feof(tracefile
)) {
1174 uint8_t *p
= realloc(trace
, traceLen
+ TRACE_CHUNK_SIZE
);
1176 PrintAndLog("Cannot allocate memory for trace");
1185 } else if (PCSCtrace
) {
1186 trace
= pcsc_get_trace_addr();
1187 traceLen
= pcsc_get_traceLen();
1189 trace
= malloc(USB_CMD_DATA_SIZE
);
1190 // Query for the size of the trace
1191 UsbCommand response
;
1192 if (!(GetFromBigBuf(trace
, USB_CMD_DATA_SIZE
, 0, &response
, 500, false))) {
1195 traceLen
= response
.arg
[2];
1196 if (traceLen
> USB_CMD_DATA_SIZE
) {
1197 uint8_t *p
= realloc(trace
, traceLen
);
1199 PrintAndLog("Cannot allocate memory for trace");
1204 if (!(GetFromBigBuf(trace
, traceLen
, 0, NULL
, 500, false))) {
1211 FILE *tracefile
= NULL
;
1212 if ((tracefile
= fopen(save_filename
,"wb")) == NULL
) {
1213 PrintAndLog("Could not create file %s", save_filename
);
1216 fwrite(trace
, 1, traceLen
, tracefile
);
1217 PrintAndLog("Recorded Activity (TraceLen = %d bytes) written to file %s", traceLen
, save_filename
);
1220 PrintAndLog("Recorded Activity (TraceLen = %d bytes)", traceLen
);
1222 if (relative_times
) {
1223 PrintAndLog("Gap = time between transfers. Duration = duration of data transfer. Src = Source of transfer");
1225 PrintAndLog("Start = Start of Frame, End = End of Frame. Src = Source of transfer");
1228 PrintAndLog("All times are in microseconds");
1230 PrintAndLog("All times are in carrier periods (1/13.56Mhz)");
1233 if (relative_times
) {
1234 PrintAndLog(" Gap | Duration | Src | Data (! denotes parity error, ' denotes short bytes) | CRC | Annotation |");
1236 PrintAndLog(" Start | End | Src | Data (! denotes parity error, ' denotes short bytes) | CRC | Annotation |");
1238 PrintAndLog("------------|------------|-----|-----------------------------------------------------------------|-----|--------------------|");
1241 while(tracepos
< traceLen
) {
1242 tracepos
= printTraceLine(tracepos
, traceLen
, trace
, protocol
, showWaitCycles
, markCRCBytes
, prev_EOT
, times_in_us
);