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 //-----------------------------------------------------------------------------
14 #include "proxmark3.h"
18 #include "cmdparser.h"
21 #include "cmdlft55xx.h"
25 #include "../common/crc.h"
26 #include "../common/iso14443crc.h"
29 #define CONFIGURATION_BLOCK 0x00
30 #define TRACE_BLOCK 0x01
31 #define REGULAR_READ_MODE_BLOCK 0xFF
33 // Default configuration
34 t55xx_conf_block_t config
= { .modulation
= DEMOD_ASK
, .inverted
= FALSE
, .offset
= 0x00, .block0
= 0x00};
36 t55xx_conf_block_t
Get_t55xx_Config(){
39 void Set_t55xx_Config(t55xx_conf_block_t conf
){
43 int usage_t55xx_config(){
44 PrintAndLog("Usage: lf t55xx config [d <demodulation>] [i 1] [o <offset>]");
45 PrintAndLog("Options:");
46 PrintAndLog(" h This help");
47 PrintAndLog(" b <8|16|32|40|50|64|100|128> Set bitrate");
48 PrintAndLog(" d <FSK|FSK1|FSK1a|FSK2|FSK2a|ASK|PSK1|PSK2|NRZ|BI|BIa> Set demodulation FSK / ASK / PSK / NRZ / Biphase / Biphase A");
49 PrintAndLog(" i [1] Invert data signal, defaults to normal");
50 PrintAndLog(" o [offset] Set offset, where data should start decode in bitstream");
52 PrintAndLog("Examples:");
53 PrintAndLog(" lf t55xx config d FSK - FSK demodulation");
54 PrintAndLog(" lf t55xx config d FSK i 1 - FSK demodulation, inverse data");
55 PrintAndLog(" lf t55xx config d FSK i 1 o 3 - FSK demodulation, inverse data, offset=3,start from position 3 to decode data");
59 int usage_t55xx_read(){
60 PrintAndLog("Usage: lf t55xx read [b <block>] [p <password>] <override_safety> <page1>");
61 PrintAndLog("Options:");
62 PrintAndLog(" b <block> - block number to read. Between 0-7");
63 PrintAndLog(" p <password> - OPTIONAL password (8 hex characters)");
64 PrintAndLog(" o - OPTIONAL override safety check");
65 PrintAndLog(" 1 - OPTIONAL read Page 1 instead of Page 0");
66 PrintAndLog(" ****WARNING****");
67 PrintAndLog(" Use of read with password on a tag not configured for a pwd");
68 PrintAndLog(" can damage the tag");
70 PrintAndLog("Examples:");
71 PrintAndLog(" lf t55xx read b 0 - read data from block 0");
72 PrintAndLog(" lf t55xx read b 0 p feedbeef - read data from block 0 password feedbeef");
73 PrintAndLog(" lf t55xx read b 0 p feedbeef o - read data from block 0 password feedbeef safety check");
77 int usage_t55xx_write(){
78 PrintAndLog("Usage: lf t55xx wr [b <block>] [d <data>] [p <password>] [1]");
79 PrintAndLog("Options:");
80 PrintAndLog(" b <block> - block number to write. Between 0-7");
81 PrintAndLog(" d <data> - 4 bytes of data to write (8 hex characters)");
82 PrintAndLog(" p <password> - OPTIONAL password 4bytes (8 hex characters)");
83 PrintAndLog(" 1 - OPTIONAL write Page 1 instead of Page 0");
85 PrintAndLog("Examples:");
86 PrintAndLog(" lf t55xx wr b 3 d 11223344 - write 11223344 to block 3");
87 PrintAndLog(" lf t55xx wr b 3 d 11223344 p feedbeef - write 11223344 to block 3 password feedbeef");
91 int usage_t55xx_trace() {
92 PrintAndLog("Usage: lf t55xx trace [1]");
93 PrintAndLog("Options:");
94 PrintAndLog(" [graph buffer data] - if set, use Graphbuffer otherwise read data from tag.");
96 PrintAndLog("Examples:");
97 PrintAndLog(" lf t55xx trace");
98 PrintAndLog(" lf t55xx trace 1");
102 int usage_t55xx_info() {
103 PrintAndLog("Usage: lf t55xx info [1]");
104 PrintAndLog("Options:");
105 PrintAndLog(" [graph buffer data] - if set, use Graphbuffer otherwise read data from tag.");
107 PrintAndLog("Examples:");
108 PrintAndLog(" lf t55xx info");
109 PrintAndLog(" lf t55xx info 1");
113 int usage_t55xx_dump(){
114 PrintAndLog("Usage: lf t55xx dump <password> [o]");
115 PrintAndLog("Options:");
116 PrintAndLog(" <password> - OPTIONAL password 4bytes (8 hex symbols)");
117 PrintAndLog(" o - OPTIONAL override, force pwd read despite danger to card");
119 PrintAndLog("Examples:");
120 PrintAndLog(" lf t55xx dump");
121 PrintAndLog(" lf t55xx dump feedbeef o");
125 int usage_t55xx_detect(){
126 PrintAndLog("Usage: lf t55xx detect [1]");
127 PrintAndLog("Options:");
128 PrintAndLog(" [graph buffer data] - if set, use Graphbuffer otherwise read data from tag.");
130 PrintAndLog("Examples:");
131 PrintAndLog(" lf t55xx detect");
132 PrintAndLog(" lf t55xx detect 1");
136 int usage_t55xx_wakup(){
137 PrintAndLog("Usage: lf t55xx wakeup [h] p <password>");
138 PrintAndLog("This commands send the Answer-On-Request command and leaves the readerfield ON afterwards.");
139 PrintAndLog("Options:");
140 PrintAndLog(" h - this help");
141 PrintAndLog(" p <password> - password 4bytes (8 hex symbols)");
143 PrintAndLog("Examples:");
144 PrintAndLog(" lf t55xx wakeup p 11223344 - send wakeup password");
148 static int CmdHelp(const char *Cmd
);
150 int CmdT55xxSetConfig(const char *Cmd
) {
153 char modulation
[5] = {0x00};
156 uint8_t rates
[9] = {8,16,32,40,50,64,100,128,0};
159 while(param_getchar(Cmd
, cmdp
) != 0x00 && !errors
)
161 tmp
= param_getchar(Cmd
, cmdp
);
166 return usage_t55xx_config();
168 errors
|= param_getdec(Cmd
, cmdp
+1, &bitRate
);
172 if (rates
[i
]==bitRate
) {
177 if (i
==9) errors
= TRUE
;
182 param_getstr(Cmd
, cmdp
+1, modulation
);
185 if ( strcmp(modulation
, "FSK" ) == 0) {
186 config
.modulation
= DEMOD_FSK
;
187 } else if ( strcmp(modulation
, "FSK1" ) == 0) {
188 config
.modulation
= DEMOD_FSK1
;
190 } else if ( strcmp(modulation
, "FSK1a" ) == 0) {
191 config
.modulation
= DEMOD_FSK1a
;
193 } else if ( strcmp(modulation
, "FSK2" ) == 0) {
194 config
.modulation
= DEMOD_FSK2
;
196 } else if ( strcmp(modulation
, "FSK2a" ) == 0) {
197 config
.modulation
= DEMOD_FSK2a
;
199 } else if ( strcmp(modulation
, "ASK" ) == 0) {
200 config
.modulation
= DEMOD_ASK
;
201 } else if ( strcmp(modulation
, "NRZ" ) == 0) {
202 config
.modulation
= DEMOD_NRZ
;
203 } else if ( strcmp(modulation
, "PSK1" ) == 0) {
204 config
.modulation
= DEMOD_PSK1
;
205 } else if ( strcmp(modulation
, "PSK2" ) == 0) {
206 config
.modulation
= DEMOD_PSK2
;
207 } else if ( strcmp(modulation
, "PSK3" ) == 0) {
208 config
.modulation
= DEMOD_PSK3
;
209 } else if ( strcmp(modulation
, "BIa" ) == 0) {
210 config
.modulation
= DEMOD_BIa
;
212 } else if ( strcmp(modulation
, "BI" ) == 0) {
213 config
.modulation
= DEMOD_BI
;
216 PrintAndLog("Unknown modulation '%s'", modulation
);
221 config
.inverted
= param_getchar(Cmd
,cmdp
+1) == '1';
225 errors
|= param_getdec(Cmd
, cmdp
+1, &offset
);
227 config
.offset
= offset
;
231 PrintAndLog("Unknown parameter '%c'", param_getchar(Cmd
, cmdp
));
238 if (cmdp
== 0) return printConfiguration( config
);
241 if (errors
) return usage_t55xx_config();
244 return printConfiguration ( config
);
247 int T55xxReadBlock(uint8_t block
, bool page1
, bool usepwd
, bool override
, uint32_t password
){
250 // try reading the config block and verify that PWD bit is set before doing this!
252 if ( !AquireData(0, CONFIGURATION_BLOCK
, false, 0 ) ) return 0;
253 if ( !tryDetectModulation() ) {
254 PrintAndLog("Safety Check: Could not detect if PWD bit is set in config block. Exits.");
257 PrintAndLog("Safety Check: PWD bit is NOT set in config block. Reading without password...");
262 PrintAndLog("Safety Check Overriden - proceeding despite risk");
266 if (!AquireData(page1
, block
, usepwd
, password
) ) return 0;
267 if (!DecodeT55xxBlock()) return 0;
270 sprintf(blk
,"%d", block
);
271 printT55xxBlock(blk
);
275 int CmdT55xxReadBlock(const char *Cmd
) {
276 uint8_t block
= REGULAR_READ_MODE_BLOCK
;
277 uint32_t password
= 0; //default to blank Block 7
279 bool override
= false;
283 while(param_getchar(Cmd
, cmdp
) != 0x00 && !errors
) {
284 switch(param_getchar(Cmd
, cmdp
)) {
287 return usage_t55xx_read();
290 errors
|= param_getdec(Cmd
, cmdp
+1, &block
);
300 password
= param_get32ex(Cmd
, cmdp
+1, 0, 16);
309 PrintAndLog("Unknown parameter '%c'", param_getchar(Cmd
, cmdp
));
314 if (errors
) return usage_t55xx_read();
316 if (block
> 7 && block
!= REGULAR_READ_MODE_BLOCK
) {
317 PrintAndLog("Block must be between 0 and 7");
320 PrintAndLog("Reading Page %d:", page1
);
321 PrintAndLog("blk | hex data | binary");
322 return T55xxReadBlock(block
, page1
, usepwd
, override
, password
);
325 bool DecodeT55xxBlock(){
327 char buf
[30] = {0x00};
330 uint8_t bitRate
[8] = {8,16,32,40,50,64,100,128};
331 DemodBufferLen
= 0x00;
333 switch( config
.modulation
){
335 snprintf(cmdStr
, sizeof(buf
),"%d %d", bitRate
[config
.bitrate
], config
.inverted
);
336 ans
= FSKrawDemod(cmdStr
, FALSE
);
340 snprintf(cmdStr
, sizeof(buf
),"%d %d 8 5", bitRate
[config
.bitrate
], config
.inverted
);
341 ans
= FSKrawDemod(cmdStr
, FALSE
);
345 snprintf(cmdStr
, sizeof(buf
),"%d %d 10 8", bitRate
[config
.bitrate
], config
.inverted
);
346 ans
= FSKrawDemod(cmdStr
, FALSE
);
349 snprintf(cmdStr
, sizeof(buf
),"%d %d 0", bitRate
[config
.bitrate
], config
.inverted
);
350 ans
= ASKDemod(cmdStr
, FALSE
, FALSE
, 1);
353 snprintf(cmdStr
, sizeof(buf
),"%d %d 0", bitRate
[config
.bitrate
], config
.inverted
);
354 ans
= PSKDemod(cmdStr
, FALSE
);
356 case DEMOD_PSK2
: //inverted won't affect this
357 case DEMOD_PSK3
: //not fully implemented
358 snprintf(cmdStr
, sizeof(buf
),"%d 0 1", bitRate
[config
.bitrate
] );
359 ans
= PSKDemod(cmdStr
, FALSE
);
360 psk1TOpsk2(DemodBuffer
, DemodBufferLen
);
363 snprintf(cmdStr
, sizeof(buf
),"%d %d 1", bitRate
[config
.bitrate
], config
.inverted
);
364 ans
= NRZrawDemod(cmdStr
, FALSE
);
368 snprintf(cmdStr
, sizeof(buf
),"0 %d %d 0", bitRate
[config
.bitrate
], config
.inverted
);
369 ans
= ASKbiphaseDemod(cmdStr
, FALSE
);
377 int CmdT55xxDetect(const char *Cmd
){
379 char cmdp
= param_getchar(Cmd
, 0);
380 if (strlen(Cmd
) > 1 || cmdp
== 'h' || cmdp
== 'H')
381 return usage_t55xx_detect();
384 if ( !AquireData(0, CONFIGURATION_BLOCK
, false, 0) )
387 if ( !tryDetectModulation() )
388 PrintAndLog("Could not detect modulation automatically. Try setting it manually with \'lf t55xx config\'");
393 // detect configuration?
394 bool tryDetectModulation(){
396 t55xx_conf_block_t tests
[15];
398 uint8_t fc1
= 0, fc2
= 0, clk
=0;
400 if (GetFskClock("", FALSE
, FALSE
)){
401 fskClocks(&fc1
, &fc2
, &clk
, FALSE
);
402 if ( FSKrawDemod("0 0", FALSE
) && test(DEMOD_FSK
, &tests
[hits
].offset
, &bitRate
)){
403 tests
[hits
].modulation
= DEMOD_FSK
;
404 if (fc1
==8 && fc2
== 5)
405 tests
[hits
].modulation
= DEMOD_FSK1a
;
406 else if (fc1
==10 && fc2
== 8)
407 tests
[hits
].modulation
= DEMOD_FSK2
;
408 tests
[hits
].bitrate
= bitRate
;
409 tests
[hits
].inverted
= FALSE
;
410 tests
[hits
].block0
= PackBits(tests
[hits
].offset
, 32, DemodBuffer
);
413 if ( FSKrawDemod("0 1", FALSE
) && test(DEMOD_FSK
, &tests
[hits
].offset
, &bitRate
)) {
414 tests
[hits
].modulation
= DEMOD_FSK
;
415 if (fc1
== 8 && fc2
== 5)
416 tests
[hits
].modulation
= DEMOD_FSK1
;
417 else if (fc1
== 10 && fc2
== 8)
418 tests
[hits
].modulation
= DEMOD_FSK2a
;
420 tests
[hits
].bitrate
= bitRate
;
421 tests
[hits
].inverted
= TRUE
;
422 tests
[hits
].block0
= PackBits(tests
[hits
].offset
, 32, DemodBuffer
);
426 clk
= GetAskClock("", FALSE
, FALSE
);
428 if ( ASKDemod("0 0 0", FALSE
, FALSE
, 1) && test(DEMOD_ASK
, &tests
[hits
].offset
, &bitRate
)) {
429 tests
[hits
].modulation
= DEMOD_ASK
;
430 tests
[hits
].bitrate
= bitRate
;
431 tests
[hits
].inverted
= FALSE
;
432 tests
[hits
].block0
= PackBits(tests
[hits
].offset
, 32, DemodBuffer
);
435 if ( ASKDemod("0 1 0", FALSE
, FALSE
, 1) && test(DEMOD_ASK
, &tests
[hits
].offset
, &bitRate
)) {
436 tests
[hits
].modulation
= DEMOD_ASK
;
437 tests
[hits
].bitrate
= bitRate
;
438 tests
[hits
].inverted
= TRUE
;
439 tests
[hits
].block0
= PackBits(tests
[hits
].offset
, 32, DemodBuffer
);
442 if ( ASKbiphaseDemod("0 0 0 0", FALSE
) && test(DEMOD_BI
, &tests
[hits
].offset
, &bitRate
) ) {
443 tests
[hits
].modulation
= DEMOD_BI
;
444 tests
[hits
].bitrate
= bitRate
;
445 tests
[hits
].inverted
= FALSE
;
446 tests
[hits
].block0
= PackBits(tests
[hits
].offset
, 32, DemodBuffer
);
449 if ( ASKbiphaseDemod("0 0 1 0", FALSE
) && test(DEMOD_BIa
, &tests
[hits
].offset
, &bitRate
) ) {
450 tests
[hits
].modulation
= DEMOD_BIa
;
451 tests
[hits
].bitrate
= bitRate
;
452 tests
[hits
].inverted
= TRUE
;
453 tests
[hits
].block0
= PackBits(tests
[hits
].offset
, 32, DemodBuffer
);
459 clk
= GetNrzClock("", FALSE
, FALSE
);
461 if ( NRZrawDemod("0 0 1", FALSE
) && test(DEMOD_NRZ
, &tests
[hits
].offset
, &bitRate
)) {
462 tests
[hits
].modulation
= DEMOD_NRZ
;
463 tests
[hits
].bitrate
= bitRate
;
464 tests
[hits
].inverted
= FALSE
;
465 tests
[hits
].block0
= PackBits(tests
[hits
].offset
, 32, DemodBuffer
);
469 if ( NRZrawDemod("0 1 1", FALSE
) && test(DEMOD_NRZ
, &tests
[hits
].offset
, &bitRate
)) {
470 tests
[hits
].modulation
= DEMOD_NRZ
;
471 tests
[hits
].bitrate
= bitRate
;
472 tests
[hits
].inverted
= TRUE
;
473 tests
[hits
].block0
= PackBits(tests
[hits
].offset
, 32, DemodBuffer
);
480 clk
= GetPskClock("", FALSE
, FALSE
);
482 if ( PSKDemod("0 0 1", FALSE
) && test(DEMOD_PSK1
, &tests
[hits
].offset
, &bitRate
)) {
483 tests
[hits
].modulation
= DEMOD_PSK1
;
484 tests
[hits
].bitrate
= bitRate
;
485 tests
[hits
].inverted
= FALSE
;
486 tests
[hits
].block0
= PackBits(tests
[hits
].offset
, 32, DemodBuffer
);
489 if ( PSKDemod("0 1 1", FALSE
) && test(DEMOD_PSK1
, &tests
[hits
].offset
, &bitRate
)) {
490 tests
[hits
].modulation
= DEMOD_PSK1
;
491 tests
[hits
].bitrate
= bitRate
;
492 tests
[hits
].inverted
= TRUE
;
493 tests
[hits
].block0
= PackBits(tests
[hits
].offset
, 32, DemodBuffer
);
496 // PSK2 - needs a call to psk1TOpsk2.
497 if ( PSKDemod("0 0 1", FALSE
)) {
498 psk1TOpsk2(DemodBuffer
, DemodBufferLen
);
499 if (test(DEMOD_PSK2
, &tests
[hits
].offset
, &bitRate
)){
500 tests
[hits
].modulation
= DEMOD_PSK2
;
501 tests
[hits
].bitrate
= bitRate
;
502 tests
[hits
].inverted
= FALSE
;
503 tests
[hits
].block0
= PackBits(tests
[hits
].offset
, 32, DemodBuffer
);
506 } // inverse waves does not affect this demod
507 // PSK3 - needs a call to psk1TOpsk2.
508 if ( PSKDemod("0 0 1", FALSE
)) {
509 psk1TOpsk2(DemodBuffer
, DemodBufferLen
);
510 if (test(DEMOD_PSK3
, &tests
[hits
].offset
, &bitRate
)){
511 tests
[hits
].modulation
= DEMOD_PSK3
;
512 tests
[hits
].bitrate
= bitRate
;
513 tests
[hits
].inverted
= FALSE
;
514 tests
[hits
].block0
= PackBits(tests
[hits
].offset
, 32, DemodBuffer
);
517 } // inverse waves does not affect this demod
521 config
.modulation
= tests
[0].modulation
;
522 config
.bitrate
= tests
[0].bitrate
;
523 config
.inverted
= tests
[0].inverted
;
524 config
.offset
= tests
[0].offset
;
525 config
.block0
= tests
[0].block0
;
526 printConfiguration( config
);
531 PrintAndLog("Found [%d] possible matches for modulation.",hits
);
532 for(int i
=0; i
<hits
; ++i
){
533 PrintAndLog("--[%d]---------------", i
+1);
534 printConfiguration( tests
[i
] );
540 bool testModulation(uint8_t mode
, uint8_t modread
){
543 if (modread
>= DEMOD_FSK1
&& modread
<= DEMOD_FSK2a
) return TRUE
;
546 if (modread
== DEMOD_ASK
) return TRUE
;
549 if (modread
== DEMOD_PSK1
) return TRUE
;
552 if (modread
== DEMOD_PSK2
) return TRUE
;
555 if (modread
== DEMOD_PSK3
) return TRUE
;
558 if (modread
== DEMOD_NRZ
) return TRUE
;
561 if (modread
== DEMOD_BI
) return TRUE
;
564 if (modread
== DEMOD_BIa
) return TRUE
;
572 bool testBitRate(uint8_t readRate
, uint8_t mod
){
573 uint8_t expected
[8] = {8, 16, 32, 40, 50, 64, 100, 128};
581 detRate
= GetFskClock("",FALSE
, FALSE
);
582 if (expected
[readRate
] == detRate
)
588 detRate
= GetAskClock("",FALSE
, FALSE
);
589 if (expected
[readRate
] == detRate
)
595 detRate
= GetPskClock("",FALSE
, FALSE
);
596 if (expected
[readRate
] == detRate
)
600 detRate
= GetNrzClock("",FALSE
, FALSE
);
601 if (expected
[readRate
] == detRate
)
610 bool test(uint8_t mode
, uint8_t *offset
, int *fndBitRate
){
612 if ( DemodBufferLen
< 64 ) return FALSE
;
614 for (uint8_t idx
= 0; idx
< 64; idx
++){
616 if ( PackBits(si
, 32, DemodBuffer
) == 0x00 ) continue;
618 uint8_t safer
= PackBits(si
, 4, DemodBuffer
); si
+= 4; //master key
619 uint8_t resv
= PackBits(si
, 4, DemodBuffer
); si
+= 4; //was 7 & +=7+3 //should be only 4 bits if extended mode
620 // 2nibble must be zeroed.
621 // moved test to here, since this gets most faults first.
622 if ( resv
> 0x00) continue;
624 uint8_t xtRate
= PackBits(si
, 3, DemodBuffer
); si
+= 3; //extended mode part of rate
625 int bitRate
= PackBits(si
, 3, DemodBuffer
); si
+= 3; //bit rate
626 if (bitRate
> 7) continue;
627 uint8_t extend
= PackBits(si
, 1, DemodBuffer
); si
+= 1; //bit 15 extended mode
628 uint8_t modread
= PackBits(si
, 5, DemodBuffer
); si
+= 5+2+1;
629 //uint8_t pskcr = PackBits(si, 2, DemodBuffer); si += 2+1; //could check psk cr
630 uint8_t nml01
= PackBits(si
, 1, DemodBuffer
); si
+= 1+5; //bit 24, 30, 31 could be tested for 0 if not extended mode
631 uint8_t nml02
= PackBits(si
, 2, DemodBuffer
); si
+= 2;
634 bool extMode
=( (safer
== 0x6 || safer
== 0x9) && extend
) ? TRUE
: FALSE
;
637 if (nml01
|| nml02
|| xtRate
) continue;
640 if (!testModulation(mode
, modread
)) continue;
641 if (!testBitRate(bitRate
, mode
)) continue;
642 *fndBitRate
= bitRate
;
649 void printT55xxBlock(const char *blockNum
){
651 uint8_t i
= config
.offset
;
652 uint8_t endpos
= 32 + i
;
653 uint32_t blockData
= 0;
654 uint8_t bits
[64] = {0x00};
656 if ( !DemodBufferLen
) return;
658 if ( endpos
> DemodBufferLen
){
659 PrintAndLog("The configured offset %d is too big. Possible offset: %d)", i
, DemodBufferLen
-32);
663 for (; i
< endpos
; ++i
)
664 bits
[i
- config
.offset
]=DemodBuffer
[i
];
666 blockData
= PackBits(0, 32, bits
);
667 PrintAndLog(" %s | %08X | %s", blockNum
, blockData
, sprint_bin(bits
,32));
670 int special(const char *Cmd
) {
671 uint32_t blockData
= 0;
672 uint8_t bits
[32] = {0x00};
674 PrintAndLog("OFFSET | DATA | BINARY");
675 PrintAndLog("----------------------------------------------------");
679 for (i
= 0; i
< 32; ++i
)
680 bits
[i
]=DemodBuffer
[j
+i
];
682 blockData
= PackBits(0, 32, bits
);
684 PrintAndLog(" %02d | 0x%08X | %s",j
, blockData
, sprint_bin(bits
,32));
689 int printConfiguration( t55xx_conf_block_t b
){
690 PrintAndLog("Modulation : %s", GetSelectedModulationStr(b
.modulation
) );
691 PrintAndLog("Bit Rate : %s", GetBitRateStr(b
.bitrate
) );
692 PrintAndLog("Inverted : %s", (b
.inverted
) ? "Yes" : "No" );
693 PrintAndLog("Offset : %d", b
.offset
);
694 PrintAndLog("Block0 : 0x%08X", b
.block0
);
699 int CmdT55xxWakeUp(const char *Cmd
) {
700 uint32_t password
= 0;
703 while(param_getchar(Cmd
, cmdp
) != 0x00) {
704 switch(param_getchar(Cmd
, cmdp
)) {
707 return usage_t55xx_wakup();
710 password
= param_get32ex(Cmd
, cmdp
+1, 0xFFFFFFFF, 16);
715 PrintAndLog("Unknown parameter '%c'", param_getchar(Cmd
, cmdp
));
720 if (errors
) return usage_t55xx_wakup();
722 UsbCommand c
= {CMD_T55XX_WAKEUP
, {password
, 0, 0}};
723 clearCommandBuffer();
725 PrintAndLog("Wake up command sent. Try read now");
729 int CmdT55xxWriteBlock(const char *Cmd
) {
730 uint8_t block
= 0xFF; //default to invalid block
731 uint32_t data
= 0xFFFFFFFF; //default to blank Block
732 uint32_t password
= 0xFFFFFFFF; //default to blank Block 7
735 bool gotdata
= false;
738 while(param_getchar(Cmd
, cmdp
) != 0x00 && !errors
) {
739 switch(param_getchar(Cmd
, cmdp
)) {
742 return usage_t55xx_write();
745 errors
|= param_getdec(Cmd
, cmdp
+1, &block
);
750 data
= param_get32ex(Cmd
, cmdp
+1, 0, 16);
756 password
= param_get32ex(Cmd
, cmdp
+1, 0, 16);
765 PrintAndLog("Unknown parameter '%c'", param_getchar(Cmd
, cmdp
));
770 if (errors
|| !gotdata
) return usage_t55xx_write();
773 PrintAndLog("Block number must be between 0 and 7");
777 UsbCommand c
= {CMD_T55XX_WRITE_BLOCK
, {data
, block
, 0}};
779 c
.d
.asBytes
[0] = (page1
) ? 0x2 : 0;
781 PrintAndLog("Writing to page: %d block: %d data : 0x%08X", page1
, block
, data
);
786 c
.d
.asBytes
[0] |= 0x1;
787 PrintAndLog("pwd : 0x%08X", password
);
789 clearCommandBuffer();
791 if (!WaitForResponseTimeout(CMD_ACK
, &resp
, 1000)){
792 PrintAndLog("Error occurred, device did not ACK write operation. (May be due to old firmware)");
798 int CmdT55xxReadTrace(const char *Cmd
) {
799 char cmdp
= param_getchar(Cmd
, 0);
800 bool pwdmode
= false;
801 uint32_t password
= 0;
802 if (strlen(Cmd
) > 1 || cmdp
== 'h' || cmdp
== 'H')
803 return usage_t55xx_trace();
806 if ( !AquireData( TRACE_BLOCK
, REGULAR_READ_MODE_BLOCK
, pwdmode
, password
) )
809 if (!DecodeT55xxBlock()) return 0;
811 if ( !DemodBufferLen
) return 0;
813 RepaintGraphWindow();
815 if (config
.offset
> 5)
817 uint8_t si
= config
.offset
+repeat
;
818 uint32_t bl1
= PackBits(si
, 32, DemodBuffer
);
819 uint32_t bl2
= PackBits(si
+32, 32, DemodBuffer
);
821 uint32_t acl
= PackBits(si
, 8, DemodBuffer
); si
+= 8;
822 uint32_t mfc
= PackBits(si
, 8, DemodBuffer
); si
+= 8;
823 uint32_t cid
= PackBits(si
, 5, DemodBuffer
); si
+= 5;
824 uint32_t icr
= PackBits(si
, 3, DemodBuffer
); si
+= 3;
825 uint32_t year
= PackBits(si
, 4, DemodBuffer
); si
+= 4;
826 uint32_t quarter
= PackBits(si
, 2, DemodBuffer
); si
+= 2;
827 uint32_t lotid
= PackBits(si
, 14, DemodBuffer
); si
+= 14;
828 uint32_t wafer
= PackBits(si
, 5, DemodBuffer
); si
+= 5;
829 uint32_t dw
= PackBits(si
, 15, DemodBuffer
);
831 time_t t
= time(NULL
);
832 struct tm tm
= *localtime(&t
);
833 if ( year
> tm
.tm_year
-110)
839 PrintAndLog("The modulation is most likely wrong since the ACL is not 0xE0. ");
844 PrintAndLog("-- T55xx Trace Information ----------------------------------");
845 PrintAndLog("-------------------------------------------------------------");
846 PrintAndLog(" ACL Allocation class (ISO/IEC 15963-1) : 0x%02X (%d)", acl
, acl
);
847 PrintAndLog(" MFC Manufacturer ID (ISO/IEC 7816-6) : 0x%02X (%d) - %s", mfc
, mfc
, getTagInfo(mfc
));
848 PrintAndLog(" CID : 0x%02X (%d) - %s", cid
, cid
, GetModelStrFromCID(cid
));
849 PrintAndLog(" ICR IC Revision : %d",icr
);
850 PrintAndLog(" Manufactured");
851 PrintAndLog(" Year/Quarter : %d/%d",year
, quarter
);
852 PrintAndLog(" Lot ID : %d", lotid
);
853 PrintAndLog(" Wafer number : %d", wafer
);
854 PrintAndLog(" Die Number : %d", dw
);
855 PrintAndLog("-------------------------------------------------------------");
856 PrintAndLog(" Raw Data - Page 1");
857 PrintAndLog(" Block 1 : 0x%08X %s", bl1
, sprint_bin(DemodBuffer
+config
.offset
+repeat
,32) );
858 PrintAndLog(" Block 2 : 0x%08X %s", bl2
, sprint_bin(DemodBuffer
+config
.offset
+repeat
+32,32) );
859 PrintAndLog("-------------------------------------------------------------");
864 1-8 ACL Allocation class (ISO/IEC 15963-1) 0xE0
865 9-16 MFC Manufacturer ID (ISO/IEC 7816-6) 0x15 Atmel Corporation
866 17-21 CID 0x1 = Atmel ATA5577M1 0x2 = Atmel ATA5577M2
867 22-24 ICR IC revision
868 25-28 YEAR (BCD encoded) 9 (= 2009)
869 29-30 QUARTER 1,2,3,4
875 18-32 DW, die number sequential
881 int CmdT55xxInfo(const char *Cmd
){
883 Page 0 Block 0 Configuration data.
887 bool pwdmode
= false;
888 uint32_t password
= 0;
889 char cmdp
= param_getchar(Cmd
, 0);
891 if (strlen(Cmd
) > 1 || cmdp
== 'h' || cmdp
== 'H')
892 return usage_t55xx_info();
895 if ( !AquireData( 0, CONFIGURATION_BLOCK
, pwdmode
, password
) )
898 if (!DecodeT55xxBlock()) return 1;
900 if ( DemodBufferLen
< 32) return 1;
902 uint8_t si
= config
.offset
;
903 uint32_t bl0
= PackBits(si
, 32, DemodBuffer
);
905 uint32_t safer
= PackBits(si
, 4, DemodBuffer
); si
+= 4;
906 uint32_t resv
= PackBits(si
, 7, DemodBuffer
); si
+= 7;
907 uint32_t dbr
= PackBits(si
, 3, DemodBuffer
); si
+= 3;
908 uint32_t extend
= PackBits(si
, 1, DemodBuffer
); si
+= 1;
909 uint32_t datamod
= PackBits(si
, 5, DemodBuffer
); si
+= 5;
910 uint32_t pskcf
= PackBits(si
, 2, DemodBuffer
); si
+= 2;
911 uint32_t aor
= PackBits(si
, 1, DemodBuffer
); si
+= 1;
912 uint32_t otp
= PackBits(si
, 1, DemodBuffer
); si
+= 1;
913 uint32_t maxblk
= PackBits(si
, 3, DemodBuffer
); si
+= 3;
914 uint32_t pwd
= PackBits(si
, 1, DemodBuffer
); si
+= 1;
915 uint32_t sst
= PackBits(si
, 1, DemodBuffer
); si
+= 1;
916 uint32_t fw
= PackBits(si
, 1, DemodBuffer
); si
+= 1;
917 uint32_t inv
= PackBits(si
, 1, DemodBuffer
); si
+= 1;
918 uint32_t por
= PackBits(si
, 1, DemodBuffer
); si
+= 1;
921 PrintAndLog("-- T55xx Configuration & Tag Information --------------------");
922 PrintAndLog("-------------------------------------------------------------");
923 PrintAndLog(" Safer key : %s", GetSaferStr(safer
));
924 PrintAndLog(" reserved : %d", resv
);
925 PrintAndLog(" Data bit rate : %s", GetBitRateStr(dbr
));
926 PrintAndLog(" eXtended mode : %s", (extend
) ? "Yes - Warning":"No");
927 PrintAndLog(" Modulation : %s", GetModulationStr(datamod
));
928 PrintAndLog(" PSK clock frequency : %d", pskcf
);
929 PrintAndLog(" AOR - Answer on Request : %s", (aor
) ? "Yes":"No");
930 PrintAndLog(" OTP - One Time Pad : %s", (otp
) ? "Yes - Warning":"No" );
931 PrintAndLog(" Max block : %d", maxblk
);
932 PrintAndLog(" Password mode : %s", (pwd
) ? "Yes":"No");
933 PrintAndLog(" Sequence Start Terminator : %s", (sst
) ? "Yes":"No");
934 PrintAndLog(" Fast Write : %s", (fw
) ? "Yes":"No");
935 PrintAndLog(" Inverse data : %s", (inv
) ? "Yes":"No");
936 PrintAndLog(" POR-Delay : %s", (por
) ? "Yes":"No");
937 PrintAndLog("-------------------------------------------------------------");
938 PrintAndLog(" Raw Data - Page 0");
939 PrintAndLog(" Block 0 : 0x%08X %s", bl0
, sprint_bin(DemodBuffer
+config
.offset
,32) );
940 PrintAndLog("-------------------------------------------------------------");
945 int CmdT55xxDump(const char *Cmd
){
947 uint32_t password
= 0;
948 char cmdp
= param_getchar(Cmd
, 0);
949 bool override
= false;
950 if ( cmdp
== 'h' || cmdp
== 'H') return usage_t55xx_dump();
952 bool usepwd
= ( strlen(Cmd
) > 0);
954 password
= param_get32ex(Cmd
, 0, 0, 16);
955 if (param_getchar(Cmd
, 1) =='o' )
959 PrintAndLog("Reading Page 0:");
960 PrintAndLog("blk | hex data | binary");
961 for ( uint8_t i
= 0; i
<8; ++i
){
962 T55xxReadBlock(i
, 0, usepwd
, override
, password
);
963 /*memset(s,0,sizeof(s));
966 sprintf(s,"b %d p %02x%02x%02x%02x o", i, pwd[0],pwd[1],pwd[2],pwd[3]);
968 sprintf(s,"b %d p %02x%02x%02x%02x", i, pwd[0],pwd[1],pwd[2],pwd[3]);
971 sprintf(s,"b %d", i);
973 CmdT55xxReadBlock(s);*/
975 PrintAndLog("Reading Page 1:");
976 PrintAndLog("blk | hex data | binary");
977 for ( uint8_t i
= 0; i
<4; i
++){
978 T55xxReadBlock(i
, 1, usepwd
, override
, password
);
983 int AquireData( uint8_t page
, uint8_t block
, bool pwdmode
, uint32_t password
){
985 uint8_t arg0
= (page
<<1) | pwdmode
;
986 UsbCommand c
= {CMD_T55XX_READ_BLOCK
, {arg0
, block
, password
}};
988 clearCommandBuffer();
990 if ( !WaitForResponseTimeout(CMD_ACK
,NULL
,2500) ) {
991 PrintAndLog("command execution time out");
996 GetFromBigBuf(got
,sizeof(got
),0);
997 WaitForResponse(CMD_ACK
,NULL
);
998 setGraphBuf(got
, sizeof(got
));
1002 char * GetBitRateStr(uint32_t id
){
1003 static char buf
[25];
1008 snprintf(retStr
,sizeof(buf
),"%d - RF/8",id
);
1011 snprintf(retStr
,sizeof(buf
),"%d - RF/16",id
);
1014 snprintf(retStr
,sizeof(buf
),"%d - RF/32",id
);
1017 snprintf(retStr
,sizeof(buf
),"%d - RF/40",id
);
1020 snprintf(retStr
,sizeof(buf
),"%d - RF/50",id
);
1023 snprintf(retStr
,sizeof(buf
),"%d - RF/64",id
);
1026 snprintf(retStr
,sizeof(buf
),"%d - RF/100",id
);
1029 snprintf(retStr
,sizeof(buf
),"%d - RF/128",id
);
1032 snprintf(retStr
,sizeof(buf
),"%d - (Unknown)",id
);
1039 char * GetSaferStr(uint32_t id
){
1040 static char buf
[40];
1043 snprintf(retStr
,sizeof(buf
),"%d",id
);
1045 snprintf(retStr
,sizeof(buf
),"%d - passwd",id
);
1048 snprintf(retStr
,sizeof(buf
),"%d - testmode",id
);
1054 char * GetModulationStr( uint32_t id
){
1055 static char buf
[60];
1060 snprintf(retStr
,sizeof(buf
),"%d - DIRECT (ASK/NRZ)",id
);
1063 snprintf(retStr
,sizeof(buf
),"%d - PSK 1 phase change when input changes",id
);
1066 snprintf(retStr
,sizeof(buf
),"%d - PSK 2 phase change on bitclk if input high",id
);
1069 snprintf(retStr
,sizeof(buf
),"%d - PSK 3 phase change on rising edge of input",id
);
1072 snprintf(retStr
,sizeof(buf
),"%d - FSK 1 RF/8 RF/5",id
);
1075 snprintf(retStr
,sizeof(buf
),"%d - FSK 2 RF/8 RF/10",id
);
1078 snprintf(retStr
,sizeof(buf
),"%d - FSK 1a RF/5 RF/8",id
);
1081 snprintf(retStr
,sizeof(buf
),"%d - FSK 2a RF/10 RF/8",id
);
1084 snprintf(retStr
,sizeof(buf
),"%d - Manchester",id
);
1087 snprintf(retStr
,sizeof(buf
),"%d - Biphase",id
);
1090 snprintf(retStr
,sizeof(buf
),"%d - Biphase a - AKA Conditional Dephase Encoding(CDP)",id
);
1093 snprintf(retStr
,sizeof(buf
),"%d - Reserved",id
);
1096 snprintf(retStr
,sizeof(buf
),"0x%02X (Unknown)",id
);
1102 char * GetModelStrFromCID(uint32_t cid
){
1104 static char buf
[10];
1107 if (cid
== 1) snprintf(retStr
, sizeof(buf
),"ATA5577M1");
1108 if (cid
== 2) snprintf(retStr
, sizeof(buf
),"ATA5577M2");
1112 char * GetSelectedModulationStr( uint8_t id
){
1114 static char buf
[20];
1119 snprintf(retStr
,sizeof(buf
),"FSK");
1122 snprintf(retStr
,sizeof(buf
),"FSK1");
1125 snprintf(retStr
,sizeof(buf
),"FSK1a");
1128 snprintf(retStr
,sizeof(buf
),"FSK2");
1131 snprintf(retStr
,sizeof(buf
),"FSK2a");
1134 snprintf(retStr
,sizeof(buf
),"ASK");
1137 snprintf(retStr
,sizeof(buf
),"DIRECT/NRZ");
1140 snprintf(retStr
,sizeof(buf
),"PSK1");
1143 snprintf(retStr
,sizeof(buf
),"PSK2");
1146 snprintf(retStr
,sizeof(buf
),"PSK3");
1149 snprintf(retStr
,sizeof(buf
),"BIPHASE");
1152 snprintf(retStr
,sizeof(buf
),"BIPHASEa - (CDP)");
1155 snprintf(retStr
,sizeof(buf
),"(Unknown)");
1161 uint32_t PackBits(uint8_t start
, uint8_t len
, uint8_t* bits
){
1166 if (len
> 32) return 0;
1169 for (; j
>= 0; --j
, ++i
)
1170 tmp
|= bits
[i
] << j
;
1175 int CmdResetRead(const char *Cmd
) {
1176 UsbCommand c
= {CMD_T55XX_RESET_READ
, {0,0,0}};
1178 clearCommandBuffer();
1180 if ( !WaitForResponseTimeout(CMD_ACK
,NULL
,2500) ) {
1181 PrintAndLog("command execution time out");
1185 uint8_t got
[BIGBUF_SIZE
-1];
1186 GetFromBigBuf(got
,sizeof(got
),0);
1187 WaitForResponse(CMD_ACK
,NULL
);
1188 setGraphBuf(got
, sizeof(got
));
1192 static command_t CommandTable
[] =
1194 {"help", CmdHelp
, 1, "This help"},
1195 {"config", CmdT55xxSetConfig
, 1, "Set/Get T55XX configuration (modulation, inverted, offset, rate)"},
1196 {"detect", CmdT55xxDetect
, 0, "[1] Try detecting the tag modulation from reading the configuration block."},
1197 {"read", CmdT55xxReadBlock
, 0, "b <block> p [password] [o] [1] -- Read T55xx block data. Optional [p password], [override], [page1]"},
1198 {"resetread",CmdResetRead
, 0, "Send Reset Cmd then lf read the stream to attempt to identify the start of it (needs a demod and/or plot after)"},
1199 {"write", CmdT55xxWriteBlock
,0, "b <block> d <data> p [password] [1] -- Write T55xx block data. Optional [p password], [page1]"},
1200 {"trace", CmdT55xxReadTrace
, 0, "[1] Show T55xx traceability data (page 1/ blk 0-1)"},
1201 {"info", CmdT55xxInfo
, 0, "[1] Show T55xx configuration data (page 0/ blk 0)"},
1202 {"dump", CmdT55xxDump
, 0, "[password] [o] Dump T55xx card block 0-7. Optional [password], [override]"},
1203 {"special", special
, 0, "Show block changes with 64 different offsets"},
1204 {"wakeup", CmdT55xxWakeUp
, 0, "Send AOR wakeup command"},
1205 {NULL
, NULL
, 0, NULL
}
1208 int CmdLFT55XX(const char *Cmd
)
1210 CmdsParse(CommandTable
, Cmd
);
1214 int CmdHelp(const char *Cmd
)
1216 CmdsHelp(CommandTable
);