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_SELECT
:snprintf(exp
, size
, "SELECT");return;
258 case ISO15693_RESET_TO_READY
:snprintf(exp
, size
, "RESET_TO_READY");return;
259 case ISO15693_WRITE_AFI
:snprintf(exp
, size
, "WRITE_AFI");return;
260 case ISO15693_LOCK_AFI
:snprintf(exp
, size
, "LOCK_AFI");return;
261 case ISO15693_WRITE_DSFID
:snprintf(exp
, size
, "WRITE_DSFID");return;
262 case ISO15693_LOCK_DSFID
:snprintf(exp
, size
, "LOCK_DSFID");return;
263 case ISO15693_GET_SYSTEM_INFO
:snprintf(exp
, size
, "GET_SYSTEM_INFO");return;
264 case ISO15693_READ_MULTI_SECSTATUS
:snprintf(exp
, size
, "READ_MULTI_SECSTATUS");return;
268 if (cmd
[1] > ISO15693_STAYQUIET
&& cmd
[1] < ISO15693_READBLOCK
) snprintf(exp
, size
, "Mandatory RFU");
269 else if (cmd
[1] > ISO15693_READ_MULTI_SECSTATUS
&& cmd
[1] <= 0x9F) snprintf(exp
, size
, "Optional RFU");
270 else if ( cmd
[1] >= 0xA0 && cmd
[1] <= 0xDF ) snprintf(exp
, size
, "Custom command");
271 else if ( cmd
[1] >= 0xE0 && cmd
[1] <= 0xFF ) snprintf(exp
, size
, "Proprietary command");
275 void annotateTopaz(char *exp
, size_t size
, uint8_t* cmd
, uint8_t cmdsize
)
278 case TOPAZ_REQA
:snprintf(exp
, size
, "REQA");break;
279 case TOPAZ_WUPA
:snprintf(exp
, size
, "WUPA");break;
280 case TOPAZ_RID
:snprintf(exp
, size
, "RID");break;
281 case TOPAZ_RALL
:snprintf(exp
, size
, "RALL");break;
282 case TOPAZ_READ
:snprintf(exp
, size
, "READ");break;
283 case TOPAZ_WRITE_E
:snprintf(exp
, size
, "WRITE-E");break;
284 case TOPAZ_WRITE_NE
:snprintf(exp
, size
, "WRITE-NE");break;
285 case TOPAZ_RSEG
:snprintf(exp
, size
, "RSEG");break;
286 case TOPAZ_READ8
:snprintf(exp
, size
, "READ8");break;
287 case TOPAZ_WRITE_E8
:snprintf(exp
, size
, "WRITE-E8");break;
288 case TOPAZ_WRITE_NE8
:snprintf(exp
, size
, "WRITE-NE8");break;
289 default: snprintf(exp
,size
,"?"); break;
294 void annotateIso7816(char *exp
, size_t size
, uint8_t* cmd
, uint8_t cmdsize
)
297 case ISO7816_READ_BINARY
:snprintf(exp
, size
, "READ BINARY");break;
298 case ISO7816_WRITE_BINARY
:snprintf(exp
, size
, "WRITE BINARY");break;
299 case ISO7816_UPDATE_BINARY
:snprintf(exp
, size
, "UPDATE BINARY");break;
300 case ISO7816_ERASE_BINARY
:snprintf(exp
, size
, "ERASE BINARY");break;
301 case ISO7816_READ_RECORDS
:snprintf(exp
, size
, "READ RECORD(S)");break;
302 case ISO7816_WRITE_RECORD
:snprintf(exp
, size
, "WRITE RECORD");break;
303 case ISO7816_APPEND_RECORD
:snprintf(exp
, size
, "APPEND RECORD");break;
304 case ISO7816_UPDATE_DATA
:snprintf(exp
, size
, "UPDATE DATA");break;
305 case ISO7816_GET_DATA
:snprintf(exp
, size
, "GET DATA");break;
306 case ISO7816_PUT_DATA
:snprintf(exp
, size
, "PUT DATA");break;
307 case ISO7816_SELECT_FILE
:snprintf(exp
, size
, "SELECT FILE");break;
308 case ISO7816_VERIFY
:snprintf(exp
, size
, "VERIFY");break;
309 case ISO7816_INTERNAL_AUTHENTICATE
:snprintf(exp
, size
, "INTERNAL AUTHENTICATE");break;
310 case ISO7816_EXTERNAL_AUTHENTICATE
:snprintf(exp
, size
, "EXTERNAL AUTHENTICATE");break;
311 case ISO7816_GET_CHALLENGE
:snprintf(exp
, size
, "GET CHALLENGE");break;
312 case ISO7816_MANAGE_CHANNEL
:snprintf(exp
, size
, "MANAGE CHANNEL");break;
313 case ISO7816_GET_RESPONSE
:snprintf(exp
, size
, "GET RESPONSE");break;
314 case ISO7816_ENVELOPE
:snprintf(exp
, size
, "ENVELOPE");break;
315 case ISO7816_GET_PROCESSING_OPTIONS
:snprintf(exp
, size
, "GET PROCESSING OPTIONS");break;
316 default :snprintf(exp
,size
,"?"); break;
321 void annotateIso14443_4(char *exp
, size_t size
, uint8_t* cmd
, uint8_t cmdsize
) {
323 if ((cmd
[0] & 0xc3) == 0xc2) {
324 switch (cmd
[0] & 0x30) {
325 case 0x00 : snprintf(exp
, size
, "S-block DESELECT"); break;
326 case 0x30 : snprintf(exp
, size
, "S-block WTX"); break;
327 default : snprintf(exp
, size
, "S-block (RFU)"); break;
331 else if ((cmd
[0] & 0xe0) == 0xa0) {
332 if ((cmd
[0] & 0x10) == 0)
333 snprintf(exp
, size
, "R-block ACK");
335 snprintf(exp
, size
, "R-block NACK");
340 switch (cmd
[0] & 0x0c) {
341 case 0x08: // CID following
342 case 0x04: // NAD following
345 case 0x0c: // CID and NAD following
349 pos
= 1; // no CID, no NAD
352 annotateIso7816(exp
, size
, &cmd
[pos
], cmdsize
-pos
);
359 0E xx = SELECT ID (xx = Chip-ID)
361 08 yy = Read Block (yy = block number)
362 09 yy dd dd dd dd = Write Block (yy = block number; dd dd dd dd = data to be written)
363 0C = Reset to Inventory
365 0A 11 22 33 44 55 66 = Authenticate (11 22 33 44 55 66 = data to authenticate)
368 void annotateIso14443b(char *exp
, size_t size
, uint8_t* cmd
, uint8_t cmdsize
) {
370 case ISO14443B_REQB
: snprintf(exp
,size
,"REQB");break;
371 case ISO14443B_ATTRIB
: snprintf(exp
,size
,"ATTRIB");break;
372 case ISO14443B_HALT
: snprintf(exp
,size
,"HALT");break;
373 case ISO14443B_INITIATE
: snprintf(exp
,size
,"INITIATE");break;
374 case ISO14443B_SELECT
: snprintf(exp
,size
,"SELECT(%d)",cmd
[1]);break;
375 case ISO14443B_GET_UID
: snprintf(exp
,size
,"GET UID");break;
376 case ISO14443B_READ_BLK
: snprintf(exp
,size
,"READ_BLK(%d)", cmd
[1]);break;
377 case ISO14443B_WRITE_BLK
: snprintf(exp
,size
,"WRITE_BLK(%d)",cmd
[1]);break;
378 case ISO14443B_RESET
: snprintf(exp
,size
,"RESET");break;
379 case ISO14443B_COMPLETION
: snprintf(exp
,size
,"COMPLETION");break;
380 case ISO14443B_AUTHENTICATE
: snprintf(exp
,size
,"AUTHENTICATE");break;
381 default : snprintf(exp
,size
,"?");break;
386 void annotateIso14443a(char *exp
, size_t size
, uint8_t* cmd
, uint8_t cmdsize
) {
389 case ISO14443A_CMD_WUPA
:
390 snprintf(exp
,size
,"WUPA");
392 case ISO14443A_CMD_ANTICOLL_OR_SELECT
:{
393 // 93 20 = Anticollision (usage: 9320 - answer: 4bytes UID+1byte UID-bytes-xor)
394 // 93 70 = Select (usage: 9370+5bytes 9320 answer - answer: 1byte SAK)
397 snprintf(exp
,size
,"SELECT_UID"); break;
400 snprintf(exp
,size
,"ANTICOLL"); break;
403 case ISO14443A_CMD_ANTICOLL_OR_SELECT_2
:{
404 //95 20 = Anticollision of cascade level2
405 //95 70 = Select of cascade level2
408 snprintf(exp
,size
,"SELECT_UID-2"); break;
411 snprintf(exp
,size
,"ANTICOLL-2"); break;
414 case ISO14443A_CMD_REQA
:
415 snprintf(exp
,size
,"REQA");
417 case MIFARE_CMD_READBLOCK
: snprintf(exp
,size
,"READBLOCK(%d)",cmd
[1]); break;
418 case MIFARE_CMD_WRITEBLOCK
: snprintf(exp
,size
,"WRITEBLOCK(%d)",cmd
[1]); break;
419 case ISO14443A_CMD_HALT
:
420 snprintf(exp
,size
,"HALT");
421 MifareAuthState
= masNone
;
423 case ISO14443A_CMD_RATS
: snprintf(exp
,size
,"RATS"); break;
424 case MIFARE_CMD_INC
: snprintf(exp
,size
,"INC(%d)",cmd
[1]); break;
425 case MIFARE_CMD_DEC
: snprintf(exp
,size
,"DEC(%d)",cmd
[1]); break;
426 case MIFARE_CMD_RESTORE
: snprintf(exp
,size
,"RESTORE(%d)",cmd
[1]); break;
427 case MIFARE_CMD_TRANSFER
: snprintf(exp
,size
,"TRANSFER(%d)",cmd
[1]); break;
428 case MIFARE_AUTH_KEYA
:
430 snprintf(exp
,size
,"AUTH-A(%d)",cmd
[1]);
431 MifareAuthState
= masNt
;
433 // case MIFARE_ULEV1_VERSION : both 0x60.
434 snprintf(exp
,size
,"EV1 VERSION");
437 case MIFARE_AUTH_KEYB
:
438 MifareAuthState
= masNt
;
439 snprintf(exp
,size
,"AUTH-B(%d)",cmd
[1]);
441 case MIFARE_MAGICWUPC1
: snprintf(exp
,size
,"MAGIC WUPC1"); break;
442 case MIFARE_MAGICWUPC2
: snprintf(exp
,size
,"MAGIC WUPC2"); break;
443 case MIFARE_MAGICWIPEC
: snprintf(exp
,size
,"MAGIC WIPEC"); break;
444 case MIFARE_ULC_AUTH_1
: snprintf(exp
,size
,"AUTH "); break;
445 case MIFARE_ULC_AUTH_2
: snprintf(exp
,size
,"AUTH_ANSW"); break;
446 case MIFARE_ULEV1_AUTH
:
448 snprintf(exp
,size
,"PWD-AUTH KEY: 0x%02x%02x%02x%02x", cmd
[1], cmd
[2], cmd
[3], cmd
[4] );
450 snprintf(exp
,size
,"PWD-AUTH");
452 case MIFARE_ULEV1_FASTREAD
:{
453 if ( cmdsize
>=3 && cmd
[2] <= 0xE6)
454 snprintf(exp
,size
,"READ RANGE (%d-%d)",cmd
[1],cmd
[2]);
456 snprintf(exp
,size
,"?");
459 case MIFARE_ULC_WRITE
:{
461 snprintf(exp
,size
,"WRITEBLOCK(%d)",cmd
[1]);
463 snprintf(exp
,size
,"?");
466 case MIFARE_ULEV1_READ_CNT
:{
468 snprintf(exp
,size
,"READ CNT(%d)",cmd
[1]);
470 snprintf(exp
,size
,"?");
473 case MIFARE_ULEV1_INCR_CNT
:{
475 snprintf(exp
,size
,"INCR(%d)",cmd
[1]);
477 snprintf(exp
,size
,"?");
480 case MIFARE_ULEV1_READSIG
: snprintf(exp
,size
,"READ_SIG"); break;
481 case MIFARE_ULEV1_CHECKTEAR
: snprintf(exp
,size
,"CHK_TEARING(%d)",cmd
[1]); break;
482 case MIFARE_ULEV1_VCSL
: snprintf(exp
,size
,"VCSL"); break;
483 default: snprintf(exp
,size
,"?"); break;
488 void annotateMifare(char *exp
, size_t size
, uint8_t* cmd
, uint8_t cmdsize
, uint8_t* parity
, uint8_t paritysize
, bool isResponse
) {
489 if (!isResponse
&& cmdsize
== 1) {
491 case ISO14443A_CMD_WUPA
:
492 case ISO14443A_CMD_REQA
:
493 MifareAuthState
= masNone
;
501 if (MifareAuthState
== masNone
) {
502 if (cmdsize
== 9 && cmd
[0] == ISO14443A_CMD_ANTICOLL_OR_SELECT
&& cmd
[1] == 0x70) {
504 AuthData
.uid
= bytes_to_num(&cmd
[2], 4);
506 if (cmdsize
== 9 && cmd
[0] == ISO14443A_CMD_ANTICOLL_OR_SELECT_2
&& cmd
[1] == 0x70) {
508 AuthData
.uid
= bytes_to_num(&cmd
[2], 4);
512 switch(MifareAuthState
) {
514 if (cmdsize
== 4 && isResponse
) {
515 snprintf(exp
,size
,"AUTH: nt %s", (AuthData
.first_auth
) ? "" : "(enc)");
516 MifareAuthState
= masNrAr
;
517 if (AuthData
.first_auth
) {
518 AuthData
.nt
= bytes_to_num(cmd
, 4);
520 AuthData
.nt_enc
= bytes_to_num(cmd
, 4);
521 AuthData
.nt_enc_par
= parity
[0];
525 MifareAuthState
= masError
;
529 if (cmdsize
== 8 && !isResponse
) {
530 snprintf(exp
,size
,"AUTH: nr ar (enc)");
531 MifareAuthState
= masAt
;
532 AuthData
.nr_enc
= bytes_to_num(cmd
, 4);
533 AuthData
.ar_enc
= bytes_to_num(&cmd
[4], 4);
534 AuthData
.ar_enc_par
= parity
[0] << 4;
537 MifareAuthState
= masError
;
541 if (cmdsize
== 4 && isResponse
) {
542 snprintf(exp
,size
,"AUTH: at (enc)");
543 MifareAuthState
= masAuthComplete
;
544 AuthData
.at_enc
= bytes_to_num(cmd
, 4);
545 AuthData
.at_enc_par
= parity
[0];
548 MifareAuthState
= masError
;
555 if (!isResponse
&& ((MifareAuthState
== masNone
) || (MifareAuthState
== masError
)))
556 annotateIso14443a(exp
, size
, cmd
, cmdsize
);
561 static uint64_t GetCrypto1ProbableKey(TAuthData
*ad
) {
562 struct Crypto1State
*revstate
= lfsr_recovery64(ad
->ks2
, ad
->ks3
);
563 lfsr_rollback_word(revstate
, 0, 0);
564 lfsr_rollback_word(revstate
, 0, 0);
565 lfsr_rollback_word(revstate
, ad
->nr_enc
, 1);
566 lfsr_rollback_word(revstate
, ad
->uid
^ ad
->nt
, 0);
569 crypto1_get_lfsr(revstate
, &lfsr
);
570 crypto1_destroy(revstate
);
576 static bool NTParityChk(TAuthData
*ad
, uint32_t ntx
) {
578 (oddparity8(ntx
>> 8 & 0xff) ^ (ntx
& 0x01) ^ ((ad
->nt_enc_par
>> 5) & 0x01) ^ (ad
->nt_enc
& 0x01)) ||
579 (oddparity8(ntx
>> 16 & 0xff) ^ (ntx
>> 8 & 0x01) ^ ((ad
->nt_enc_par
>> 6) & 0x01) ^ (ad
->nt_enc
>> 8 & 0x01)) ||
580 (oddparity8(ntx
>> 24 & 0xff) ^ (ntx
>> 16 & 0x01) ^ ((ad
->nt_enc_par
>> 7) & 0x01) ^ (ad
->nt_enc
>> 16 & 0x01))
584 uint32_t ar
= prng_successor(ntx
, 64);
586 (oddparity8(ar
>> 8 & 0xff) ^ (ar
& 0x01) ^ ((ad
->ar_enc_par
>> 5) & 0x01) ^ (ad
->ar_enc
& 0x01)) ||
587 (oddparity8(ar
>> 16 & 0xff) ^ (ar
>> 8 & 0x01) ^ ((ad
->ar_enc_par
>> 6) & 0x01) ^ (ad
->ar_enc
>> 8 & 0x01)) ||
588 (oddparity8(ar
>> 24 & 0xff) ^ (ar
>> 16 & 0x01) ^ ((ad
->ar_enc_par
>> 7) & 0x01) ^ (ad
->ar_enc
>> 16 & 0x01))
592 uint32_t at
= prng_successor(ntx
, 96);
594 (oddparity8(ar
& 0xff) ^ (at
>> 24 & 0x01) ^ ((ad
->ar_enc_par
>> 4) & 0x01) ^ (ad
->at_enc
>> 24 & 0x01)) ||
595 (oddparity8(at
>> 8 & 0xff) ^ (at
& 0x01) ^ ((ad
->at_enc_par
>> 5) & 0x01) ^ (ad
->at_enc
& 0x01)) ||
596 (oddparity8(at
>> 16 & 0xff) ^ (at
>> 8 & 0x01) ^ ((ad
->at_enc_par
>> 6) & 0x01) ^ (ad
->at_enc
>> 8 & 0x01)) ||
597 (oddparity8(at
>> 24 & 0xff) ^ (at
>> 16 & 0x01) ^ ((ad
->at_enc_par
>> 7) & 0x01) ^ (ad
->at_enc
>> 16 & 0x01))
605 static bool CheckCrypto1Parity(uint8_t *cmd_enc
, uint8_t cmdsize
, uint8_t *cmd
, uint8_t *parity_enc
) {
606 for (int i
= 0; i
< cmdsize
- 1; i
++) {
607 if (oddparity8(cmd
[i
]) ^ (cmd
[i
+ 1] & 0x01) ^ ((parity_enc
[i
/ 8] >> (7 - i
% 8)) & 0x01) ^ (cmd_enc
[i
+ 1] & 0x01))
615 static bool NestedCheckKey(uint64_t key
, TAuthData
*ad
, uint8_t *cmd
, uint8_t cmdsize
, uint8_t *parity
) {
616 uint8_t buf
[32] = {0};
617 struct Crypto1State
*pcs
;
622 pcs
= crypto1_create(key
);
623 uint32_t nt1
= crypto1_word(pcs
, ad
->nt_enc
^ ad
->uid
, 1) ^ ad
->nt_enc
;
624 uint32_t ar
= prng_successor(nt1
, 64);
625 uint32_t at
= prng_successor(nt1
, 96);
627 crypto1_word(pcs
, ad
->nr_enc
, 1);
628 // uint32_t nr1 = crypto1_word(pcs, ad->nr_enc, 1) ^ ad->nr_enc; // if needs deciphered nr
629 uint32_t ar1
= crypto1_word(pcs
, 0, 0) ^ ad
->ar_enc
;
630 uint32_t at1
= crypto1_word(pcs
, 0, 0) ^ ad
->at_enc
;
632 if (!(ar
== ar1
&& at
== at1
&& NTParityChk(ad
, nt1
))) {
633 crypto1_destroy(pcs
);
637 memcpy(buf
, cmd
, cmdsize
);
638 mf_crypto1_decrypt(pcs
, buf
, cmdsize
, 0);
640 crypto1_destroy(pcs
);
642 if (!CheckCrypto1Parity(cmd
, cmdsize
, buf
, parity
))
645 if(!CheckCrc14443(CRC_14443_A
, buf
, cmdsize
))
649 AuthData
.ks2
= AuthData
.ar_enc
^ ar
;
650 AuthData
.ks3
= AuthData
.at_enc
^ at
;
656 static bool DecodeMifareData(uint8_t *cmd
, uint8_t cmdsize
, uint8_t *parity
, bool isResponse
, uint8_t *mfData
, size_t *mfDataLen
) {
657 static struct Crypto1State
*traceCrypto1
;
658 static uint64_t mfLastKey
;
662 if (MifareAuthState
== masAuthComplete
) {
664 crypto1_destroy(traceCrypto1
);
668 MifareAuthState
= masFirstData
;
675 if (MifareAuthState
== masFirstData
) {
676 if (AuthData
.first_auth
) {
677 AuthData
.ks2
= AuthData
.ar_enc
^ prng_successor(AuthData
.nt
, 64);
678 AuthData
.ks3
= AuthData
.at_enc
^ prng_successor(AuthData
.nt
, 96);
680 mfLastKey
= GetCrypto1ProbableKey(&AuthData
);
681 PrintAndLog(" | * | key | probable key:%012"PRIx64
" Prng:%s ks2:%08x ks3:%08x | |",
683 validate_prng_nonce(AuthData
.nt
) ? "WEAK": "HARD",
687 AuthData
.first_auth
= false;
689 traceCrypto1
= lfsr_recovery64(AuthData
.ks2
, AuthData
.ks3
);
692 crypto1_destroy(traceCrypto1
);
696 // check last used key
698 if (NestedCheckKey(mfLastKey
, &AuthData
, cmd
, cmdsize
, parity
)) {
699 PrintAndLog(" | * | key | last used key:%012"PRIx64
" ks2:%08x ks3:%08x | |",
704 traceCrypto1
= lfsr_recovery64(AuthData
.ks2
, AuthData
.ks3
);
708 // check default keys
710 for (int defaultKeyCounter
= 0; defaultKeyCounter
< MifareDefaultKeysSize
; defaultKeyCounter
++){
711 if (NestedCheckKey(MifareDefaultKeys
[defaultKeyCounter
], &AuthData
, cmd
, cmdsize
, parity
)) {
712 PrintAndLog(" | * | key | default key:%012"PRIx64
" ks2:%08x ks3:%08x | |",
713 MifareDefaultKeys
[defaultKeyCounter
],
717 mfLastKey
= MifareDefaultKeys
[defaultKeyCounter
];
718 traceCrypto1
= lfsr_recovery64(AuthData
.ks2
, AuthData
.ks3
);
725 if (!traceCrypto1
&& validate_prng_nonce(AuthData
.nt
)) {
726 uint32_t ntx
= prng_successor(AuthData
.nt
, 90);
727 for (int i
= 0; i
< 16383; i
++) {
728 ntx
= prng_successor(ntx
, 1);
729 if (NTParityChk(&AuthData
, ntx
)){
731 uint32_t ks2
= AuthData
.ar_enc
^ prng_successor(ntx
, 64);
732 uint32_t ks3
= AuthData
.at_enc
^ prng_successor(ntx
, 96);
733 struct Crypto1State
*pcs
= lfsr_recovery64(ks2
, ks3
);
734 memcpy(mfData
, cmd
, cmdsize
);
735 mf_crypto1_decrypt(pcs
, mfData
, cmdsize
, 0);
737 crypto1_destroy(pcs
);
738 if (CheckCrypto1Parity(cmd
, cmdsize
, mfData
, parity
) && CheckCrc14443(CRC_14443_A
, mfData
, cmdsize
)) {
743 mfLastKey
= GetCrypto1ProbableKey(&AuthData
);
744 PrintAndLog(" | * | key | nested probable key:%012"PRIx64
" ks2:%08x ks3:%08x | |",
749 traceCrypto1
= lfsr_recovery64(AuthData
.ks2
, AuthData
.ks3
);
758 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
);
759 MifareAuthState
= masError
;
761 /* TOO SLOW( needs to have more strong filter. with this filter - aprox 4 mln tests
762 uint32_t t = msclock();
765 for (uint32_t i = 0; i < 0xFFFFFFFF; i++) {
766 if (NTParityChk(&AuthData, i)){
768 uint32_t ks2 = AuthData.ar_enc ^ prng_successor(i, 64);
769 uint32_t ks3 = AuthData.at_enc ^ prng_successor(i, 96);
770 struct Crypto1State *pcs = lfsr_recovery64(ks2, ks3);
778 printf("delta=%d n=%d ks2=%x ks3=%x \n", msclock() - t1 , n, ks2, ks3);
784 printf("delta=%d n=%d\n", msclock() - t, n);
791 MifareAuthState
= masData
;
794 if (MifareAuthState
== masData
&& traceCrypto1
) {
795 memcpy(mfData
, cmd
, cmdsize
);
796 mf_crypto1_decrypt(traceCrypto1
, mfData
, cmdsize
, 0);
797 *mfDataLen
= cmdsize
;
800 return *mfDataLen
> 0;
804 bool is_last_record(uint16_t tracepos
, uint8_t *trace
, uint16_t traceLen
) {
805 return(tracepos
+ sizeof(uint32_t) + sizeof(uint16_t) + sizeof(uint16_t) >= traceLen
);
809 bool next_record_is_response(uint16_t tracepos
, uint8_t *trace
) {
810 uint16_t next_records_datalen
= *((uint16_t *)(trace
+ tracepos
+ sizeof(uint32_t) + sizeof(uint16_t)));
811 return(next_records_datalen
& 0x8000);
815 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
) {
817 #define MAX_TOPAZ_READER_CMD_LEN 16
819 uint32_t last_timestamp
= timestamp
+ *duration
;
821 if ((*data_len
!= 1) || (frame
[0] == TOPAZ_WUPA
) || (frame
[0] == TOPAZ_REQA
)) return false;
823 memcpy(topaz_reader_command
, frame
, *data_len
);
825 while (!is_last_record(*tracepos
, trace
, traceLen
) && !next_record_is_response(*tracepos
, trace
)) {
826 uint32_t next_timestamp
= *((uint32_t *)(trace
+ *tracepos
));
827 *tracepos
+= sizeof(uint32_t);
828 uint16_t next_duration
= *((uint16_t *)(trace
+ *tracepos
));
829 *tracepos
+= sizeof(uint16_t);
830 uint16_t next_data_len
= *((uint16_t *)(trace
+ *tracepos
)) & 0x7FFF;
831 *tracepos
+= sizeof(uint16_t);
832 uint8_t *next_frame
= (trace
+ *tracepos
);
833 *tracepos
+= next_data_len
;
834 if ((next_data_len
== 1) && (*data_len
+ next_data_len
<= MAX_TOPAZ_READER_CMD_LEN
)) {
835 memcpy(topaz_reader_command
+ *data_len
, next_frame
, next_data_len
);
836 *data_len
+= next_data_len
;
837 last_timestamp
= next_timestamp
+ next_duration
;
840 *tracepos
= *tracepos
- next_data_len
- sizeof(uint16_t) - sizeof(uint16_t) - sizeof(uint32_t);
843 uint16_t next_parity_len
= (next_data_len
-1)/8 + 1;
844 *tracepos
+= next_parity_len
;
847 *duration
= last_timestamp
- timestamp
;
853 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
) {
855 uint16_t data_len
, parity_len
;
857 uint8_t topaz_reader_command
[9];
858 uint32_t timestamp
, first_timestamp
;
859 uint32_t EndOfTransmissionTimestamp
= 0;
860 char explanation
[30] = {0};
861 uint8_t mfData
[32] = {0};
862 size_t mfDataLen
= 0;
864 if (tracepos
+ sizeof(uint32_t) + sizeof(uint16_t) + sizeof(uint16_t) > traceLen
) return traceLen
;
866 first_timestamp
= *((uint32_t *)(trace
));
867 timestamp
= *((uint32_t *)(trace
+ tracepos
));
870 duration
= *((uint16_t *)(trace
+ tracepos
));
872 data_len
= *((uint16_t *)(trace
+ tracepos
));
875 if (data_len
& 0x8000) {
881 parity_len
= (data_len
-1)/8 + 1;
883 if (tracepos
+ data_len
+ parity_len
> traceLen
) {
886 uint8_t *frame
= trace
+ tracepos
;
887 tracepos
+= data_len
;
888 uint8_t *parityBytes
= trace
+ tracepos
;
889 tracepos
+= parity_len
;
891 if (protocol
== TOPAZ
&& !isResponse
) {
892 // topaz reader commands come in 1 or 9 separate frames with 7 or 8 Bits each.
894 if (merge_topaz_reader_frames(timestamp
, &duration
, &tracepos
, traceLen
, trace
, frame
, topaz_reader_command
, &data_len
)) {
895 frame
= topaz_reader_command
;
899 // adjust for different time scales
900 if (protocol
== ICLASS
|| protocol
== ISO_15693
) {
904 //Check the CRC status
905 uint8_t crcStatus
= 2;
910 crcStatus
= iclass_CRC_check(isResponse
, frame
, data_len
);
914 crcStatus
= iso14443B_CRC_check(isResponse
, frame
, data_len
);
917 crcStatus
= mifare_CRC_check(isResponse
, frame
, data_len
);
920 crcStatus
= iso14443A_CRC_check(isResponse
, frame
, data_len
);
923 crcStatus
= iso14443_4_CRC_check(frame
, data_len
);
926 crcStatus
= iso15693_CRC_check(frame
, data_len
);
932 //0 CRC-command, CRC not ok
933 //1 CRC-command, CRC ok
936 //--- Draw the data column
939 for (int j
= 0; j
< data_len
&& j
/16 < 16; j
++) {
940 uint8_t parityBits
= parityBytes
[j
>>3];
941 if (protocol
!= ISO_14443B
942 && protocol
!= ISO_15693
943 && protocol
!= ICLASS
944 && protocol
!= ISO_7816_4
945 && (isResponse
|| protocol
== ISO_14443A
)
946 && (oddparity8(frame
[j
]) != ((parityBits
>> (7-(j
&0x0007))) & 0x01))) {
947 snprintf(line
[j
/16]+(( j
% 16) * 4), 110, " %02x!", frame
[j
]);
949 snprintf(line
[j
/16]+(( j
% 16) * 4), 110, " %02x ", frame
[j
]);
954 if (crcStatus
== 0 || crcStatus
== 1) { //CRC-command
955 char *pos1
= line
[(data_len
-2)/16]+(((data_len
-2) % 16) * 4);
957 char *pos2
= line
[(data_len
)/16]+(((data_len
) % 16) * 4);
958 sprintf(pos2
, "%c", ']');
962 // mark short bytes (less than 8 Bit + Parity)
963 if (protocol
== ISO_14443A
|| protocol
== PROTO_MIFARE
) {
964 if (duration
< 128 * (9 * data_len
)) {
965 line
[(data_len
-1)/16][((data_len
-1)%16) * 4 + 3] = '\'';
970 if (protocol
== ICLASS
&& duration
== 2048) {
971 sprintf(line
[0], " <SOF>");
973 sprintf(line
[0], " <empty trace - possible error>");
977 //--- Draw the CRC column
978 char *crc
= (crcStatus
== 0 ? "!crc" : (crcStatus
== 1 ? " ok " : " "));
980 if (protocol
== PROTO_MIFARE
)
981 annotateMifare(explanation
, sizeof(explanation
), frame
, data_len
, parityBytes
, parity_len
, isResponse
);
985 case ICLASS
: annotateIclass(explanation
,sizeof(explanation
),frame
,data_len
); break;
986 case ISO_14443A
: annotateIso14443a(explanation
,sizeof(explanation
),frame
,data_len
); break;
987 case ISO_14443B
: annotateIso14443b(explanation
,sizeof(explanation
),frame
,data_len
); break;
988 case TOPAZ
: annotateTopaz(explanation
,sizeof(explanation
),frame
,data_len
); break;
989 case ISO_15693
: annotateIso15693(explanation
,sizeof(explanation
),frame
,data_len
); break;
990 case ISO_7816_4
: annotateIso7816(explanation
, sizeof(explanation
), frame
, data_len
); break;
991 case ISO_14443_4
: annotateIso14443_4(explanation
, sizeof(explanation
), frame
, data_len
); break;
996 uint32_t previousEndOfTransmissionTimestamp
= 0;
999 previousEndOfTransmissionTimestamp
= *prev_EOT
;
1001 previousEndOfTransmissionTimestamp
= timestamp
;
1004 EndOfTransmissionTimestamp
= timestamp
+ duration
;
1005 if (prev_EOT
) *prev_EOT
= EndOfTransmissionTimestamp
;
1007 int num_lines
= MIN((data_len
- 1)/16 + 1, 16);
1008 for (int j
= 0; j
< num_lines
; j
++) {
1010 uint32_t time1
= timestamp
- first_timestamp
;
1011 uint32_t time2
= EndOfTransmissionTimestamp
- first_timestamp
;
1013 time1
= timestamp
- previousEndOfTransmissionTimestamp
;
1017 PrintAndLog(" %10.1f | %10.1f | %s |%-64s | %s| %s",
1020 isResponse
? "Tag" : "Rdr",
1022 (j
== num_lines
-1) ? crc
: " ",
1023 (j
== num_lines
-1) ? explanation
: "");
1025 PrintAndLog(" %10" PRIu32
" | %10" PRIu32
" | %s |%-64s | %s| %s",
1028 isResponse
? "Tag" : "Rdr",
1030 (j
== num_lines
-1) ? crc
: " ",
1031 (j
== num_lines
-1) ? explanation
: "");
1034 PrintAndLog(" | | |%-64s | %s| %s",
1036 (j
== num_lines
-1) ? crc
: " ",
1037 (j
== num_lines
-1) ? explanation
: "");
1041 if (DecodeMifareData(frame
, data_len
, parityBytes
, isResponse
, mfData
, &mfDataLen
)) {
1042 memset(explanation
, 0x00, sizeof(explanation
));
1044 explanation
[0] = '>';
1045 annotateIso14443a(&explanation
[1], sizeof(explanation
) - 1, mfData
, mfDataLen
);
1047 uint8_t crcc
= iso14443A_CRC_check(isResponse
, mfData
, mfDataLen
);
1048 PrintAndLog(" | * | dec |%-64s | %-4s| %s",
1049 sprint_hex(mfData
, mfDataLen
),
1050 (crcc
== 0 ? "!crc" : (crcc
== 1 ? " ok " : " ")),
1051 (true) ? explanation
: "");
1054 if (is_last_record(tracepos
, trace
, traceLen
)) return traceLen
;
1056 if (showWaitCycles
&& !isResponse
&& next_record_is_response(tracepos
, trace
)) {
1057 uint32_t next_timestamp
= *((uint32_t *)(trace
+ tracepos
));
1059 PrintAndLog(" %10d | %10d | %s | fdt (Frame Delay Time): %d",
1060 (EndOfTransmissionTimestamp
- first_timestamp
),
1061 (next_timestamp
- first_timestamp
),
1063 (next_timestamp
- EndOfTransmissionTimestamp
));
1070 int CmdHFList(const char *Cmd
) {
1072 CLIParserInit("hf list", "\nList or save protocol data.",
1073 "examples: hf list 14a -f -- interpret as ISO14443A communication and display Frame Delay Times\n"\
1074 " hf list iclass -- interpret as iClass trace\n"\
1075 " hf list -s myCardTrace.trc -- save trace for later use\n"\
1076 " hf list 14a -l myCardTrace.trc -- load trace and interpret as ISO14443A communication\n");
1077 void* argtable
[] = {
1079 arg_lit0("f", "fdt", "display fdt (frame delay times)"),
1080 arg_lit0("r", "relative", "show relative times (gap and duration)"),
1081 arg_lit0("c", "crc" , "mark CRC bytes"),
1082 arg_lit0("p", "pcsc", "show trace buffer from PCSC card reader instead of PM3"),
1083 arg_str0("l", "load", "<filename>", "load trace from file"),
1084 arg_str0("s", "save", "<filename>", "save trace to file"),
1085 arg_lit0("u", "us", "display times in microseconds instead of clock cycles"),
1086 arg_str0(NULL
, NULL
, "<protocol>", "protocol to interpret. Possible values:\n"\
1087 "\traw - just show raw data without annotations (default)\n"\
1088 "\t14a - interpret data as ISO14443A communications\n"\
1089 "\tmf - interpret data as ISO14443A communications and decrypt Mifare Crypto1 stream\n"\
1090 "\t14b - interpret data as ISO14443B communications\n"\
1091 "\t15 - interpret data as ISO15693 communications\n"\
1092 "\ticlass - interpret data as iClass communications\n"\
1093 "\ttopaz - interpret data as Topaz communications\n"\
1094 "\t7816 - interpret data as 7816-4 APDU communications\n"\
1095 "\t14-4 - interpret data as ISO14443-4 communications"),
1099 if (CLIParserParseString(Cmd
, argtable
, arg_getsize(argtable
), true)){
1104 bool showWaitCycles
= arg_get_lit(1);
1105 bool relative_times
= arg_get_lit(2);
1106 bool markCRCBytes
= arg_get_lit(3);
1107 bool PCSCtrace
= arg_get_lit(4);
1108 bool loadFromFile
= arg_get_str_len(5);
1109 bool saveToFile
= arg_get_str_len(6);
1110 bool times_in_us
= arg_get_lit(7);
1112 uint32_t previous_EOT
= 0;
1113 uint32_t *prev_EOT
= NULL
;
1114 if (relative_times
) {
1115 prev_EOT
= &previous_EOT
;
1118 char load_filename
[FILE_PATH_SIZE
] = {0};
1120 strncpy(load_filename
, arg_get_str(5)->sval
[0], FILE_PATH_SIZE
);
1122 char save_filename
[FILE_PATH_SIZE
] = {0};
1124 strncpy(save_filename
, arg_get_str(6)->sval
[0], FILE_PATH_SIZE
);
1127 uint8_t protocol
= -1;
1128 if (arg_get_str_len(8)) {
1129 if (strcmp(arg_get_str(8)->sval
[0], "iclass") == 0) protocol
= ICLASS
;
1130 else if(strcmp(arg_get_str(8)->sval
[0], "14a") == 0) protocol
= ISO_14443A
;
1131 else if(strcmp(arg_get_str(8)->sval
[0], "mf") == 0) protocol
= PROTO_MIFARE
;
1132 else if(strcmp(arg_get_str(8)->sval
[0], "14b") == 0) protocol
= ISO_14443B
;
1133 else if(strcmp(arg_get_str(8)->sval
[0], "topaz") == 0) protocol
= TOPAZ
;
1134 else if(strcmp(arg_get_str(8)->sval
[0], "7816") == 0) protocol
= ISO_7816_4
;
1135 else if(strcmp(arg_get_str(8)->sval
[0], "14-4") == 0) protocol
= ISO_14443_4
;
1136 else if(strcmp(arg_get_str(8)->sval
[0], "15") == 0) protocol
= ISO_15693
;
1137 else if(strcmp(arg_get_str(8)->sval
[0], "raw") == 0) protocol
= -1;//No crc, no annotations
1139 PrintAndLog("hf list: invalid argument \"%s\"\nTry 'hf list --help' for more information.", arg_get_str(8)->sval
[0]);
1149 uint32_t tracepos
= 0;
1150 uint32_t traceLen
= 0;
1153 #define TRACE_CHUNK_SIZE (1<<16) // 64K to start with. Will be enough for BigBuf and some room for future extensions
1154 FILE *tracefile
= NULL
;
1156 trace
= malloc(TRACE_CHUNK_SIZE
);
1157 if (trace
== NULL
) {
1158 PrintAndLog("Cannot allocate memory for trace");
1161 if ((tracefile
= fopen(load_filename
,"rb")) == NULL
) {
1162 PrintAndLog("Could not open file %s", load_filename
);
1166 while (!feof(tracefile
)) {
1167 bytes_read
= fread(trace
+traceLen
, 1, TRACE_CHUNK_SIZE
, tracefile
);
1168 traceLen
+= bytes_read
;
1169 if (!feof(tracefile
)) {
1170 uint8_t *p
= realloc(trace
, traceLen
+ TRACE_CHUNK_SIZE
);
1172 PrintAndLog("Cannot allocate memory for trace");
1181 } else if (PCSCtrace
) {
1182 trace
= pcsc_get_trace_addr();
1183 traceLen
= pcsc_get_traceLen();
1185 trace
= malloc(USB_CMD_DATA_SIZE
);
1186 // Query for the size of the trace
1187 UsbCommand response
;
1188 if (!(GetFromBigBuf(trace
, USB_CMD_DATA_SIZE
, 0, &response
, 500, false))) {
1191 traceLen
= response
.arg
[2];
1192 if (traceLen
> USB_CMD_DATA_SIZE
) {
1193 uint8_t *p
= realloc(trace
, traceLen
);
1195 PrintAndLog("Cannot allocate memory for trace");
1200 if (!(GetFromBigBuf(trace
, traceLen
, 0, NULL
, 500, false))) {
1207 FILE *tracefile
= NULL
;
1208 if ((tracefile
= fopen(save_filename
,"wb")) == NULL
) {
1209 PrintAndLog("Could not create file %s", save_filename
);
1212 fwrite(trace
, 1, traceLen
, tracefile
);
1213 PrintAndLog("Recorded Activity (TraceLen = %d bytes) written to file %s", traceLen
, save_filename
);
1216 PrintAndLog("Recorded Activity (TraceLen = %d bytes)", traceLen
);
1218 if (relative_times
) {
1219 PrintAndLog("Gap = time between transfers. Duration = duration of data transfer. Src = Source of transfer");
1221 PrintAndLog("Start = Start of Frame, End = End of Frame. Src = Source of transfer");
1224 PrintAndLog("All times are in microseconds");
1226 PrintAndLog("All times are in carrier periods (1/13.56Mhz)");
1229 if (relative_times
) {
1230 PrintAndLog(" Gap | Duration | Src | Data (! denotes parity error, ' denotes short bytes) | CRC | Annotation |");
1232 PrintAndLog(" Start | End | Src | Data (! denotes parity error, ' denotes short bytes) | CRC | Annotation |");
1234 PrintAndLog("------------|------------|-----|-----------------------------------------------------------------|-----|--------------------|");
1237 while(tracepos
< traceLen
) {
1238 tracepos
= printTraceLine(tracepos
, traceLen
, trace
, protocol
, showWaitCycles
, markCRCBytes
, prev_EOT
, times_in_us
);