1 //-----------------------------------------------------------------------------
3 // This code is licensed to you under the terms of the GNU GPL, version 2 or,
4 // at your option, any later version. See the LICENSE.txt file for the text of
6 //-----------------------------------------------------------------------------
7 // Low frequency T55xx commands
8 //-----------------------------------------------------------------------------
13 #include "proxmark3.h"
17 #include "cmdparser.h"
20 #include "cmdlft55xx.h"
24 #include "../common/crc.h"
25 #include "../common/iso14443crc.h"
28 #define CONFIGURATION_BLOCK 0x00
29 #define TRACE_BLOCK 0x01
31 // Default configuration
32 t55xx_conf_block_t config
= { .modulation
= DEMOD_ASK
, .inverted
= FALSE
, .offset
= 0x00, .block0
= 0x00};
34 int usage_t55xx_config(){
35 PrintAndLog("Usage: lf t55xx config [d <demodulation>] [i 1] [o <offset>]");
36 PrintAndLog("Options:");
37 PrintAndLog(" h This help");
38 PrintAndLog(" d <FSK|ASK|PSK1|PSK2|PSK3|NRZ|BI> Set demodulation");
39 PrintAndLog(" i [1] Inverse data signal, defaults to normal");
40 PrintAndLog(" o [offset] Set offset where data should start decode in bitstream");
42 PrintAndLog("Examples:");
43 PrintAndLog(" lf t55xx config d FSK - FSK demodulation");
44 PrintAndLog(" lf t55xx config d FSK i 1 - FSK demodulation, inverse data");
45 PrintAndLog(" lf t55xx config d FSK i 1 o 3 - FSK demodulation, inverse data, offset=3,start from position 3 to decode data");
49 int usage_t55xx_read(){
50 PrintAndLog("Usage: lf t55xx read <block> <password>");
51 PrintAndLog(" <block>, block number to read. Between 0-7");
52 PrintAndLog(" <password>, OPTIONAL password (8 hex characters)");
54 PrintAndLog("Examples:");
55 PrintAndLog(" lf t55xx read 0 - read data from block 0");
56 PrintAndLog(" lf t55xx read 0 feedbeef - read data from block 0 password feedbeef");
60 int usage_t55xx_write(){
61 PrintAndLog("Usage: lf t55xx wr <block> <data> [password]");
62 PrintAndLog(" <block>, block number to read. Between 0-7");
63 PrintAndLog(" <data>, 4 bytes of data to write (8 hex characters)");
64 PrintAndLog(" [password], OPTIONAL password 4bytes (8 hex characters)");
66 PrintAndLog("Examples:");
67 PrintAndLog(" lf t55xx wd 3 11223344 - write 11223344 to block 3");
68 PrintAndLog(" lf t55xx wd 3 11223344 feedbeef - write 11223344 to block 3 password feedbeef");
72 int usage_t55xx_trace() {
73 PrintAndLog("Usage: lf t55xx trace [1]");
74 PrintAndLog(" [graph buffer data], if set, use Graphbuffer otherwise read data from tag.");
76 PrintAndLog("Examples:");
77 PrintAndLog(" lf t55xx trace");
78 PrintAndLog(" lf t55xx trace 1");
82 int usage_t55xx_info() {
83 PrintAndLog("Usage: lf t55xx info [1]");
84 PrintAndLog(" [graph buffer data], if set, use Graphbuffer otherwise read data from tag.");
86 PrintAndLog("Examples:");
87 PrintAndLog(" lf t55xx info");
88 PrintAndLog(" lf t55xx info 1");
92 int usage_t55xx_dump(){
93 PrintAndLog("Usage: lf t55xx dump <password>");
94 PrintAndLog(" <password>, OPTIONAL password 4bytes (8 hex symbols)");
96 PrintAndLog("Examples:");
97 PrintAndLog(" lf t55xx dump");
98 PrintAndLog(" lf t55xx dump feedbeef");
102 int usage_t55xx_detect(){
103 PrintAndLog("Usage: lf t55xx detect [1]");
104 PrintAndLog(" [graph buffer data], if set, use Graphbuffer otherwise read data from tag.");
106 PrintAndLog("Examples:");
107 PrintAndLog(" lf t55xx detect");
108 PrintAndLog(" lf t55xx detect 1");
113 static int CmdHelp(const char *Cmd
);
115 int CmdT55xxSetConfig(const char *Cmd
) {
120 char modulation
[5] = {0x00};
123 while(param_getchar(Cmd
, cmdp
) != 0x00 && !errors
)
125 tmp
= param_getchar(Cmd
, cmdp
);
130 return usage_t55xx_config();
132 param_getstr(Cmd
, cmdp
+1, modulation
);
135 if ( strcmp(modulation
, "FSK" ) == 0)
136 config
.modulation
= DEMOD_FSK
;
137 else if ( strcmp(modulation
, "ASK" ) == 0)
138 config
.modulation
= DEMOD_ASK
;
139 else if ( strcmp(modulation
, "NRZ" ) == 0)
140 config
.modulation
= DEMOD_NRZ
;
141 else if ( strcmp(modulation
, "PSK1" ) == 0)
142 config
.modulation
= DEMOD_PSK1
;
143 else if ( strcmp(modulation
, "PSK2" ) == 0)
144 config
.modulation
= DEMOD_PSK2
;
145 else if ( strcmp(modulation
, "PSK3" ) == 0)
146 config
.modulation
= DEMOD_PSK3
;
147 else if ( strcmp(modulation
, "BI" ) == 0)
148 config
.modulation
= DEMOD_BI
;
150 PrintAndLog("Unknown modulation '%s'", modulation
);
155 config
.inverted
= param_getchar(Cmd
,cmdp
+1) == '1';
159 errors
|= param_getdec(Cmd
, cmdp
+1,&offset
);
161 config
.offset
= offset
;
165 PrintAndLog("Unknown parameter '%c'", param_getchar(Cmd
, cmdp
));
173 printConfiguration( config
);
178 return usage_t55xx_config();
181 printConfiguration( config
);
185 int CmdT55xxReadBlock(const char *Cmd
) {
187 int password
= 0xFFFFFFFF; //default to blank Block 7
189 char cmdp
= param_getchar(Cmd
, 0);
190 if (cmdp
== 'h' || cmdp
== 'H')
191 return usage_t55xx_read();
193 int res
= sscanf(Cmd
, "%d %x", &block
, &password
);
195 if ( res
< 1 || res
> 2 )
196 return usage_t55xx_read();
199 if ((block
< 0) | (block
> 7)) {
200 PrintAndLog("Block must be between 0 and 7");
204 UsbCommand c
= {CMD_T55XX_READ_BLOCK
, {0, block
, 0}};
205 c
.d
.asBytes
[0] = 0x0;
210 c
.d
.asBytes
[0] = 0x1;
214 if ( !WaitForResponseTimeout(CMD_ACK
,NULL
,2500) ) {
215 PrintAndLog("command execution time out");
220 GetFromBigBuf(got
,sizeof(got
),0);
221 WaitForResponse(CMD_ACK
,NULL
);
222 setGraphBuf(got
, 12000);
229 void DecodeT55xxBlock(){
231 char buf
[8] = {0x00};
234 DemodBufferLen
= 0x00;
236 switch( config
.modulation
){
238 sprintf(cmdStr
,"0 %d", config
.inverted
);
239 FSKrawDemod(cmdStr
, FALSE
);
242 sprintf(cmdStr
,"0 %d 1", config
.inverted
);
243 ASKmanDemod(cmdStr
, FALSE
, FALSE
);
246 sprintf(cmdStr
,"0 %d 1", config
.inverted
);
247 PSKDemod(cmdStr
, FALSE
);
250 sprintf(cmdStr
,"0 %d 1", config
.inverted
);
251 PSKDemod(cmdStr
, FALSE
);
252 psk1TOpsk2(DemodBuffer
, DemodBufferLen
);
255 sprintf(cmdStr
,"0 %d 1", config
.inverted
);
256 PSKDemod(cmdStr
, FALSE
);
257 psk1TOpsk2(DemodBuffer
, DemodBufferLen
);
260 sprintf(cmdStr
,"0 %d 1", config
.inverted
);
261 NRZrawDemod(cmdStr
, FALSE
);
264 sprintf(cmdStr
,"0 0 %d 1", config
.inverted
);
265 ASKbiphaseDemod(cmdStr
, FALSE
);
272 int CmdT55xxDetect(const char *Cmd
){
274 char cmdp
= param_getchar(Cmd
, 0);
276 if (strlen(Cmd
) > 1 || cmdp
== 'h' || cmdp
== 'H')
277 return usage_t55xx_detect();
280 AquireData(CONFIGURATION_BLOCK
);
282 if ( !tryDetectModulation() )
283 PrintAndLog("Could not detect modulation automatically. Try setting it manually with \'lf t55xx config\'");
288 bool tryDetectModulation(){
291 t55xx_conf_block_t tests
[15];
293 if (GetFskClock("", FALSE
, FALSE
)){
294 if ( FSKrawDemod("0 0", FALSE
) && test(DEMOD_FSK
, &tests
[hits
].offset
)){
295 tests
[hits
].modulation
= DEMOD_FSK
;
296 tests
[hits
].inverted
= FALSE
;
297 tests
[hits
].block0
= PackBits(tests
[hits
].offset
, 32, DemodBuffer
);
300 if ( FSKrawDemod("0 1", FALSE
) && test(DEMOD_FSK
, &tests
[hits
].offset
)) {
301 tests
[hits
].modulation
= DEMOD_FSK
;
302 tests
[hits
].inverted
= TRUE
;
303 tests
[hits
].block0
= PackBits(tests
[hits
].offset
, 32, DemodBuffer
);
307 if ( ASKmanDemod("0 0 1", FALSE
, FALSE
) && test(DEMOD_ASK
, &tests
[hits
].offset
)) {
308 tests
[hits
].modulation
= DEMOD_ASK
;
309 tests
[hits
].inverted
= FALSE
;
310 tests
[hits
].block0
= PackBits(tests
[hits
].offset
, 32, DemodBuffer
);
314 if ( ASKmanDemod("0 1 1", FALSE
, FALSE
) && test(DEMOD_ASK
, &tests
[hits
].offset
)) {
315 tests
[hits
].modulation
= DEMOD_ASK
;
316 tests
[hits
].inverted
= TRUE
;
317 tests
[hits
].block0
= PackBits(tests
[hits
].offset
, 32, DemodBuffer
);
321 if ( NRZrawDemod("0 0 1", FALSE
) && test(DEMOD_NRZ
, &tests
[hits
].offset
)) {
322 tests
[hits
].modulation
= DEMOD_NRZ
;
323 tests
[hits
].inverted
= FALSE
;
324 tests
[hits
].block0
= PackBits(tests
[hits
].offset
, 32, DemodBuffer
);
328 if ( NRZrawDemod("0 1 1", FALSE
) && test(DEMOD_NRZ
, &tests
[hits
].offset
)) {
329 tests
[hits
].modulation
= DEMOD_NRZ
;
330 tests
[hits
].inverted
= TRUE
;
331 tests
[hits
].block0
= PackBits(tests
[hits
].offset
, 32, DemodBuffer
);
335 if ( PSKDemod("0 0 1", FALSE
) && test(DEMOD_PSK1
, &tests
[hits
].offset
)) {
336 tests
[hits
].modulation
= DEMOD_PSK1
;
337 tests
[hits
].inverted
= FALSE
;
338 tests
[hits
].block0
= PackBits(tests
[hits
].offset
, 32, DemodBuffer
);
342 if ( PSKDemod("0 1 1", FALSE
) && test(DEMOD_PSK1
, &tests
[hits
].offset
)) {
343 tests
[hits
].modulation
= DEMOD_PSK1
;
344 tests
[hits
].inverted
= TRUE
;
345 tests
[hits
].block0
= PackBits(tests
[hits
].offset
, 32, DemodBuffer
);
349 // PSK2 - needs a call to psk1TOpsk2.
350 if ( PSKDemod("0 0 1", FALSE
)) {
351 psk1TOpsk2(DemodBuffer
, DemodBufferLen
);
352 if (test(DEMOD_PSK2
, &tests
[hits
].offset
)){
353 tests
[hits
].modulation
= DEMOD_PSK2
;
354 tests
[hits
].inverted
= FALSE
;
355 tests
[hits
].block0
= PackBits(tests
[hits
].offset
, 32, DemodBuffer
);
359 // PSK2 - needs a call to psk1TOpsk2.
360 if ( PSKDemod("0 1 1", FALSE
)) {
361 psk1TOpsk2(DemodBuffer
, DemodBufferLen
);
362 if (test(DEMOD_PSK2
, &tests
[hits
].offset
)){
363 tests
[hits
].modulation
= DEMOD_PSK2
;
364 tests
[hits
].inverted
= TRUE
;
365 tests
[hits
].block0
= PackBits(tests
[hits
].offset
, 32, DemodBuffer
);
370 // PSK3 - needs a call to psk1TOpsk2.
371 if ( PSKDemod("0 0 1", FALSE
)) {
372 psk1TOpsk2(DemodBuffer
, DemodBufferLen
);
373 if (test(DEMOD_PSK3
, &tests
[hits
].offset
)){
374 tests
[hits
].modulation
= DEMOD_PSK3
;
375 tests
[hits
].inverted
= FALSE
;
376 tests
[hits
].block0
= PackBits(tests
[hits
].offset
, 32, DemodBuffer
);
380 // PSK3 - needs a call to psk1TOpsk2.
381 if ( PSKDemod("0 1 1", FALSE
)) {
382 psk1TOpsk2(DemodBuffer
, DemodBufferLen
);
383 if (test(DEMOD_PSK3
, &tests
[hits
].offset
)){
384 tests
[hits
].modulation
= DEMOD_PSK3
;
385 tests
[hits
].inverted
= TRUE
;
386 tests
[hits
].block0
= PackBits(tests
[hits
].offset
, 32, DemodBuffer
);
391 if ( ASKbiphaseDemod("0 0 0 1", FALSE
) && test(DEMOD_BI
, &tests
[hits
].offset
) ) {
392 tests
[hits
].modulation
= DEMOD_BI
;
393 tests
[hits
].inverted
= FALSE
;
394 tests
[hits
].block0
= PackBits(tests
[hits
].offset
, 32, DemodBuffer
);
397 if ( ASKbiphaseDemod("0 0 1 1", FALSE
) && test(DEMOD_BI
, &tests
[hits
].offset
) ) {
398 tests
[hits
].modulation
= DEMOD_BI
;
399 tests
[hits
].inverted
= TRUE
;
400 tests
[hits
].block0
= PackBits(tests
[hits
].offset
, 32, DemodBuffer
);
406 config
.modulation
= tests
[0].modulation
;
407 config
.inverted
= tests
[0].inverted
;
408 config
.offset
= tests
[0].offset
;
411 if (DemodBufferLen
> config
.offset
+ 32)
412 config
.block0
= PackBits(config
.offset
, 32, DemodBuffer
);
413 printConfiguration( config
);
418 PrintAndLog("Found [%d] possible matches for modulation.",hits
);
419 for(int i
=0; i
<hits
; ++i
){
420 PrintAndLog("--[%d]---------------", i
+1);
421 printConfiguration( tests
[i
] );
427 bool testModulation(uint8_t mode
, uint8_t modread
){
430 if (modread
> 3 && modread
< 8) return TRUE
;
433 if (modread
== 8) return TRUE
;
436 if (modread
== 1) return TRUE
;
439 if (modread
== 2) return TRUE
;
442 if (modread
== 3) return TRUE
;
445 if (!modread
) return TRUE
;
448 if (modread
== 16) return TRUE
;
456 bool test(uint8_t mode
, uint8_t *offset
){
458 if ( !DemodBufferLen
) return FALSE
;
461 for (uint8_t idx
= 0; idx
< 64; ++idx
){
463 if ( PackBits(si
, 32, DemodBuffer
) == 0x00 ) continue;
465 uint8_t safer
= PackBits(si
, 4, DemodBuffer
); si
+= 4; //master key
466 uint8_t resv
= PackBits(si
, 4, DemodBuffer
); si
+= 4; //was 7 & +=7+3 //should be only 4 bits if extended mode
468 // 2nibble must be zeroed.
469 // moved test to here, since this gets most faults first.
470 if ( resv
> 0x00) continue;
472 uint8_t xtRate
= PackBits(si
, 3, DemodBuffer
); si
+= 3+3; //new
473 //uint8_t bitRate = PackBits(si, 3, DemodBuffer); si += 3; //new could check bit rate
474 uint8_t extend
= PackBits(si
, 1, DemodBuffer
); si
+= 1; //bit 15 extended mode
475 uint8_t modread
= PackBits(si
, 5, DemodBuffer
); si
+= 5+2+1; //new
476 //uint8_t pskcr = PackBits(si, 2, DemodBuffer); si += 2+1; //new could check psk cr
477 uint8_t nml01
= PackBits(si
, 1, DemodBuffer
); si
+= 1+5; //bit 24 , 30, 31 could be tested for 0 if not extended mode
478 uint8_t nml02
= PackBits(si
, 2, DemodBuffer
); si
+= 2;
481 bool extMode
=( (safer
== 0x6 || safer
== 0x9) && extend
) ? TRUE
: FALSE
;
484 if (nml01
|| nml02
|| xtRate
) continue;
488 if (!testModulation(mode
, modread
)) continue;
496 void printT55xxBlock(const char *demodStr
){
498 uint8_t i
= config
.offset
;
499 uint8_t endpos
= 32 + i
;
500 uint32_t blockData
= 0;
501 uint8_t bits
[64] = {0x00};
503 if ( !DemodBufferLen
) return;
505 if ( endpos
> DemodBufferLen
){
506 PrintAndLog("The configured offset %d is too big. Possible offset: %d)", i
, DemodBufferLen
-32);
510 for (; i
< endpos
; ++i
)
511 bits
[i
- config
.offset
] = DemodBuffer
[i
];
513 blockData
= PackBits(0, 32, bits
);
514 PrintAndLog("0x%08X %s [%s]", blockData
, sprint_bin(bits
,32), demodStr
);
517 int special(const char *Cmd
) {
518 uint32_t blockData
= 0;
519 uint8_t bits
[32] = {0x00};
521 PrintAndLog("[OFFSET] [DATA] [BINARY]");
522 PrintAndLog("----------------------------------------------------");
526 for (i
= 0; i
< 32; ++i
)
527 bits
[i
]=DemodBuffer
[j
+i
];
529 blockData
= PackBits(0, 32, bits
);
531 //char indicate[4] = {0x00};
532 // if ( (blockData >> 24) == 0xE0 )
533 // sprintf(indicate,"<--");
534 //PrintAndLog("[%02d] 0x%08X %s %s",j , blockData, sprint_bin(bits,32), indicate);
535 PrintAndLog("[%02d] 0x%08X %s",j
, blockData
, sprint_bin(bits
,32));
541 void printConfiguration( t55xx_conf_block_t b
){
542 PrintAndLog("Modulation : %s", GetSelectedModulationStr(b
.modulation
) );
543 PrintAndLog("Inverted : %s", (b
.inverted
) ? "Yes" : "No" );
544 PrintAndLog("Offset : %d", b
.offset
);
545 PrintAndLog("Block0 : 0x%08X", b
.block0
);
549 int CmdT55xxWriteBlock(const char *Cmd
)
551 int block
= 8; //default to invalid block
552 int data
= 0xFFFFFFFF; //default to blank Block
553 int password
= 0xFFFFFFFF; //default to blank Block 7
555 char cmdp
= param_getchar(Cmd
, 0);
556 if (cmdp
== 'h' || cmdp
== 'H') {
561 int res
= sscanf(Cmd
, "%d %x %x",&block
, &data
, &password
);
563 if ( res
< 2 || res
> 3) {
569 PrintAndLog("Block must be between 0 and 7");
573 UsbCommand c
= {CMD_T55XX_WRITE_BLOCK
, {data
, block
, 0}};
574 c
.d
.asBytes
[0] = 0x0;
576 PrintAndLog("Writing to T55x7");
577 PrintAndLog("block : %d", block
);
578 PrintAndLog("data : 0x%08X", data
);
583 c
.d
.asBytes
[0] = 0x1;
584 PrintAndLog("pwd : 0x%08X", password
);
590 int CmdT55xxReadTrace(const char *Cmd
)
592 char cmdp
= param_getchar(Cmd
, 0);
594 if (strlen(Cmd
) > 1 || cmdp
== 'h' || cmdp
== 'H')
595 return usage_t55xx_trace();
597 if ( strlen(Cmd
)==0){
598 AquireData( TRACE_BLOCK
);
603 if (!DemodBufferLen
) return 1;
605 RepaintGraphWindow();
607 if (config
.offset
> 5)
609 uint8_t si
= config
.offset
+repeat
;
610 uint32_t bl0
= PackBits(si
, 32, DemodBuffer
);
611 uint32_t bl1
= PackBits(si
+32, 32, DemodBuffer
);
613 uint32_t acl
= PackBits(si
, 8, DemodBuffer
); si
+= 8;
614 uint32_t mfc
= PackBits(si
, 8, DemodBuffer
); si
+= 8;
615 uint32_t cid
= PackBits(si
, 5, DemodBuffer
); si
+= 5;
616 uint32_t icr
= PackBits(si
, 3, DemodBuffer
); si
+= 3;
617 uint32_t year
= PackBits(si
, 4, DemodBuffer
); si
+= 4;
618 uint32_t quarter
= PackBits(si
, 2, DemodBuffer
); si
+= 2;
619 uint32_t lotid
= PackBits(si
, 12, DemodBuffer
); si
+= 12;
620 uint32_t wafer
= PackBits(si
, 5, DemodBuffer
); si
+= 5;
621 uint32_t dw
= PackBits(si
, 15, DemodBuffer
);
626 PrintAndLog("-- T55xx Trace Information ----------------------------------");
627 PrintAndLog("-------------------------------------------------------------");
628 PrintAndLog(" ACL Allocation class (ISO/IEC 15963-1) : 0x%02X (%d)", acl
, acl
);
629 PrintAndLog(" MFC Manufacturer ID (ISO/IEC 7816-6) : 0x%02X (%d) - %s", mfc
, mfc
, getTagInfo(mfc
));
630 PrintAndLog(" CID : 0x%02X (%d) - %s", cid
, cid
, GetModelStrFromCID(cid
));
631 PrintAndLog(" ICR IC Revision : %d",icr
);
632 PrintAndLog(" Manufactured");
633 PrintAndLog(" Year/Quarter : %d/%d",year
, quarter
);
634 PrintAndLog(" Lot ID : %d", lotid
);
635 PrintAndLog(" Wafer number : %d", wafer
);
636 PrintAndLog(" Die Number : %d", dw
);
637 PrintAndLog("-------------------------------------------------------------");
638 PrintAndLog(" Raw Data - Page 1");
639 PrintAndLog(" Block 0 : 0x%08X %s", bl0
, sprint_bin(DemodBuffer
+config
.offset
+repeat
,32) );
640 PrintAndLog(" Block 1 : 0x%08X %s", bl1
, sprint_bin(DemodBuffer
+config
.offset
+repeat
+32,32) );
641 PrintAndLog("-------------------------------------------------------------");
644 PrintAndLog("The modulation is most likely wrong since the ACL is not 0xE0. ");
648 1-8 ACL Allocation class (ISO/IEC 15963-1) 0xE0
649 9-16 MFC Manufacturer ID (ISO/IEC 7816-6) 0x15 Atmel Corporation
650 17-21 CID 0x1 = Atmel ATA5577M1 0x2 = Atmel ATA5577M2
651 22-24 ICR IC revision
652 25-28 YEAR (BCD encoded) 9 (= 2009)
653 29-30 QUARTER 1,2,3,4
659 18-32 DW, die number sequential
665 int CmdT55xxInfo(const char *Cmd
){
667 Page 0 Block 0 Configuration data.
671 char cmdp
= param_getchar(Cmd
, 0);
673 if (strlen(Cmd
) > 1 || cmdp
== 'h' || cmdp
== 'H')
674 return usage_t55xx_info();
677 AquireData( CONFIGURATION_BLOCK
);
681 if (!DemodBufferLen
) return 1;
683 uint8_t si
= config
.offset
;
684 uint32_t bl0
= PackBits(si
, 32, DemodBuffer
);
686 uint32_t safer
= PackBits(si
, 4, DemodBuffer
); si
+= 4;
687 uint32_t resv
= PackBits(si
, 7, DemodBuffer
); si
+= 7;
688 uint32_t dbr
= PackBits(si
, 3, DemodBuffer
); si
+= 3;
689 uint32_t extend
= PackBits(si
, 1, DemodBuffer
); si
+= 1;
690 uint32_t datamod
= PackBits(si
, 5, DemodBuffer
); si
+= 5;
691 uint32_t pskcf
= PackBits(si
, 2, DemodBuffer
); si
+= 2;
692 uint32_t aor
= PackBits(si
, 1, DemodBuffer
); si
+= 1;
693 uint32_t otp
= PackBits(si
, 1, DemodBuffer
); si
+= 1;
694 uint32_t maxblk
= PackBits(si
, 3, DemodBuffer
); si
+= 3;
695 uint32_t pwd
= PackBits(si
, 1, DemodBuffer
); si
+= 1;
696 uint32_t sst
= PackBits(si
, 1, DemodBuffer
); si
+= 1;
697 uint32_t fw
= PackBits(si
, 1, DemodBuffer
); si
+= 1;
698 uint32_t inv
= PackBits(si
, 1, DemodBuffer
); si
+= 1;
699 uint32_t por
= PackBits(si
, 1, DemodBuffer
); si
+= 1;
702 PrintAndLog("-- T55xx Configuration & Tag Information --------------------");
703 PrintAndLog("-------------------------------------------------------------");
704 PrintAndLog(" Safer key : %s", GetSaferStr(safer
));
705 PrintAndLog(" reserved : %d", resv
);
706 PrintAndLog(" Data bit rate : %s", GetBitRateStr(dbr
));
707 PrintAndLog(" eXtended mode : %s", (extend
) ? "Yes - Warning":"No");
708 PrintAndLog(" Modulation : %s", GetModulationStr(datamod
));
709 PrintAndLog(" PSK clock frequency : %d", pskcf
);
710 PrintAndLog(" AOR - Answer on Request : %s", (aor
) ? "Yes":"No");
711 PrintAndLog(" OTP - One Time Pad : %s", (otp
) ? "Yes - Warning":"No" );
712 PrintAndLog(" Max block : %d", maxblk
);
713 PrintAndLog(" Password mode : %s", (pwd
) ? "Yes":"No");
714 PrintAndLog(" Sequence Start Terminator : %s", (sst
) ? "Yes":"No");
715 PrintAndLog(" Fast Write : %s", (fw
) ? "Yes":"No");
716 PrintAndLog(" Inverse data : %s", (inv
) ? "Yes":"No");
717 PrintAndLog(" POR-Delay : %s", (por
) ? "Yes":"No");
718 PrintAndLog("-------------------------------------------------------------");
719 PrintAndLog(" Raw Data - Page 0");
720 PrintAndLog(" Block 0 : 0x%08X %s", bl0
, sprint_bin(DemodBuffer
+config
.offset
,32) );
721 PrintAndLog("-------------------------------------------------------------");
725 int CmdT55xxDump(const char *Cmd
){
728 uint8_t pwd
[4] = {0x00};
730 char cmdp
= param_getchar(Cmd
, 0);
731 if ( cmdp
== 'h' || cmdp
== 'H') {
736 bool hasPwd
= ( strlen(Cmd
) > 0);
738 if (param_gethex(Cmd
, 0, pwd
, 8)) {
739 PrintAndLog("password must include 8 HEX symbols");
744 for ( int i
= 0; i
<8; ++i
){
745 memset(s
,0,sizeof(s
));
747 sprintf(s
,"%d %02x%02x%02x%02x", i
, pwd
[0],pwd
[1],pwd
[2],pwd
[3]);
751 CmdT55xxReadBlock(s
);
756 int AquireData( uint8_t block
){
760 if ( block
== CONFIGURATION_BLOCK
)
761 c
.cmd
= CMD_T55XX_READ_BLOCK
;
762 else if (block
== TRACE_BLOCK
)
763 c
.cmd
= CMD_T55XX_READ_TRACE
;
768 c
.d
.asBytes
[0] = 0x0;
772 // c.arg[2] = password;
773 // c.d.asBytes[0] = 0x1;
777 if ( !WaitForResponseTimeout(CMD_ACK
,NULL
,2500) ) {
778 PrintAndLog("command execution time out");
783 GetFromBigBuf(got
,sizeof(got
),0);
784 WaitForResponse(CMD_ACK
,NULL
);
785 setGraphBuf(got
, 12000);
789 char * GetBitRateStr(uint32_t id
){
794 sprintf(retStr
,"%d - RF/8",id
);
797 sprintf(retStr
,"%d - RF/16",id
);
800 sprintf(retStr
,"%d - RF/32",id
);
803 sprintf(retStr
,"%d - RF/40",id
);
806 sprintf(retStr
,"%d - RF/50",id
);
809 sprintf(retStr
,"%d - RF/64",id
);
812 sprintf(retStr
,"%d - RF/100",id
);
815 sprintf(retStr
,"%d - RF/128",id
);
818 sprintf(retStr
,"%d - (Unknown)",id
);
825 char * GetSaferStr(uint32_t id
){
829 sprintf(retStr
,"%d",id
);
831 sprintf(retStr
,"%d - passwd",id
);
834 sprintf(retStr
,"%d - testmode",id
);
839 char * GetModulationStr( uint32_t id
){
845 sprintf(retStr
,"%d - DIRECT (ASK/NRZ)",id
);
848 sprintf(retStr
,"%d - PSK 1 phase change when input changes",id
);
851 sprintf(retStr
,"%d - PSK 2 phase change on bitclk if input high",id
);
854 sprintf(retStr
,"%d - PSK 3 phase change on rising edge of input",id
);
857 sprintf(retStr
,"%d - FSK 1 RF/8 RF/5",id
);
860 sprintf(retStr
,"%d - FSK 2 RF/8 RF/10",id
);
863 sprintf(retStr
,"%d - FSK 1a RF/5 RF/8",id
);
866 sprintf(retStr
,"%d - FSK 2a RF/10 RF/8",id
);
869 sprintf(retStr
,"%d - Manschester",id
);
872 sprintf(retStr
,"%d - Biphase",id
);
875 sprintf(retStr
,"%d - Reserved",id
);
878 sprintf(retStr
,"0x%02X (Unknown)",id
);
884 char * GetModelStrFromCID(uint32_t cid
){
889 if (cid
== 1) sprintf(retStr
,"ATA5577M1");
890 if (cid
== 2) sprintf(retStr
,"ATA5577M2");
894 char * GetSelectedModulationStr( uint8_t id
){
901 sprintf(retStr
,"FSK");
904 sprintf(retStr
,"ASK");
907 sprintf(retStr
,"DIRECT/NRZ");
910 sprintf(retStr
,"PSK1");
913 sprintf(retStr
,"PSK2");
916 sprintf(retStr
,"PSK3");
919 sprintf(retStr
,"BIPHASE");
922 sprintf(retStr
,"(Unknown)");
928 uint32_t PackBits(uint8_t start
, uint8_t len
, uint8_t* bits
){
933 if (len
> 32) return 0;
936 for (; j
>= 0; --j
, ++i
)
942 static command_t CommandTable
[] =
944 {"help", CmdHelp
, 1, "This help"},
945 {"config", CmdT55xxSetConfig
, 1, "Set/Get T55XX configuration (modulation, inverted, offset)"},
946 {"detect", CmdT55xxDetect
, 0, "[1] Try detecting the tag modulation from reading the configuration block."},
947 {"read", CmdT55xxReadBlock
, 0, "<block> [password] -- Read T55xx block data (page 0) [optional password]"},
948 {"write", CmdT55xxWriteBlock
,0, "<block> <data> [password] -- Write T55xx block data (page 0) [optional password]"},
949 {"trace", CmdT55xxReadTrace
, 0, "[1] Show T55xx traceability data (page 1/ blk 0-1)"},
950 {"info", CmdT55xxInfo
, 0, "[1] Show T55xx configuration data (page 0/ blk 0)"},
951 {"dump", CmdT55xxDump
, 0, "[password] Dump T55xx card block 0-7. [optional password]"},
952 {"special", special
, 0, "Show block changes with 64 different offsets"},
953 {NULL
, NULL
, 0, NULL
}
956 int CmdLFT55XX(const char *Cmd
)
958 CmdsParse(CommandTable
, Cmd
);
962 int CmdHelp(const char *Cmd
)
964 CmdsHelp(CommandTable
);