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 T55x7_PWD 0x00000010
33 // Default configuration
34 t55xx_conf_block_t config
= { .modulation
= DEMOD_ASK
, .inverted
= FALSE
, .offset
= 0x00, .block0
= 0x00};
36 int usage_t55xx_config(){
37 PrintAndLog("Usage: lf t55xx config [d <demodulation>] [i 1] [o <offset>]");
38 PrintAndLog("Options: ");
39 PrintAndLog(" h This help");
40 PrintAndLog(" b <8|16|32|40|50|64|100|128> Set bitrate");
41 PrintAndLog(" d <FSK|FSK1|FSK1a|FSK2|FSK2a|ASK|PSK1|PSK2|NRZ|BI|BIa> Set demodulation FSK / ASK / PSK / NRZ / Biphase / Biphase A");
42 PrintAndLog(" i [1] Invert data signal, defaults to normal");
43 PrintAndLog(" o [offset] Set offset, where data should start decode in bitstream");
45 PrintAndLog("Examples:");
46 PrintAndLog(" lf t55xx config d FSK - FSK demodulation");
47 PrintAndLog(" lf t55xx config d FSK i 1 - FSK demodulation, inverse data");
48 PrintAndLog(" lf t55xx config d FSK i 1 o 3 - FSK demodulation, inverse data, offset=3,start from position 3 to decode data");
52 int usage_t55xx_read(){
53 PrintAndLog("Usage: lf t55xx read <block> <password>");
54 PrintAndLog(" <block>, block number to read. Between 0-7");
55 PrintAndLog(" <password>, OPTIONAL password (8 hex characters)");
57 PrintAndLog("Examples:");
58 PrintAndLog(" lf t55xx read 0 - read data from block 0");
59 PrintAndLog(" lf t55xx read 0 feedbeef - read data from block 0 password feedbeef");
63 int usage_t55xx_write(){
64 PrintAndLog("Usage: lf t55xx wr <block> <data> [password]");
65 PrintAndLog(" <block>, block number to write. Between 0-7");
66 PrintAndLog(" <data>, 4 bytes of data to write (8 hex characters)");
67 PrintAndLog(" [password], OPTIONAL password 4bytes (8 hex characters)");
69 PrintAndLog("Examples:");
70 PrintAndLog(" lf t55xx wr 3 11223344 - write 11223344 to block 3");
71 PrintAndLog(" lf t55xx wr 3 11223344 feedbeef - write 11223344 to block 3 password feedbeef");
75 int usage_t55xx_trace() {
76 PrintAndLog("Usage: lf t55xx trace [1]");
77 PrintAndLog(" [graph buffer data], if set, use Graphbuffer otherwise read data from tag.");
79 PrintAndLog("Examples:");
80 PrintAndLog(" lf t55xx trace");
81 PrintAndLog(" lf t55xx trace 1");
85 int usage_t55xx_info() {
86 PrintAndLog("Usage: lf t55xx info [1]");
87 PrintAndLog(" [graph buffer data], if set, use Graphbuffer otherwise read data from tag.");
89 PrintAndLog("Examples:");
90 PrintAndLog(" lf t55xx info");
91 PrintAndLog(" lf t55xx info 1");
95 int usage_t55xx_dump(){
96 PrintAndLog("Usage: lf t55xx dump <password>");
97 PrintAndLog(" <password>, OPTIONAL password 4bytes (8 hex symbols)");
99 PrintAndLog("Examples:");
100 PrintAndLog(" lf t55xx dump");
101 PrintAndLog(" lf t55xx dump feedbeef");
105 int usage_t55xx_detect(){
106 PrintAndLog("Usage: lf t55xx detect");
108 PrintAndLog("Examples:");
109 PrintAndLog(" lf t55xx detect");
110 PrintAndLog(" lf t55xx detect 1");
115 static int CmdHelp(const char *Cmd
);
117 int CmdT55xxSetConfig(const char *Cmd
) {
122 char modulation
[5] = {0x00};
125 uint8_t rates
[9] = {8,16,32,40,50,64,100,128,0};
126 while(param_getchar(Cmd
, cmdp
) != 0x00 && !errors
)
128 tmp
= param_getchar(Cmd
, cmdp
);
133 return usage_t55xx_config();
135 errors
|= param_getdec(Cmd
, cmdp
+1, &bitRate
);
139 if (rates
[i
]==bitRate
) {
144 if (i
==9) errors
= TRUE
;
149 param_getstr(Cmd
, cmdp
+1, modulation
);
152 if ( strcmp(modulation
, "FSK" ) == 0) {
153 config
.modulation
= DEMOD_FSK
;
154 } else if ( strcmp(modulation
, "FSK1" ) == 0) {
155 config
.modulation
= DEMOD_FSK1
;
157 } else if ( strcmp(modulation
, "FSK1a" ) == 0) {
158 config
.modulation
= DEMOD_FSK1a
;
160 } else if ( strcmp(modulation
, "FSK2" ) == 0) {
161 config
.modulation
= DEMOD_FSK2
;
163 } else if ( strcmp(modulation
, "FSK2a" ) == 0) {
164 config
.modulation
= DEMOD_FSK2a
;
166 } else if ( strcmp(modulation
, "ASK" ) == 0) {
167 config
.modulation
= DEMOD_ASK
;
168 } else if ( strcmp(modulation
, "NRZ" ) == 0) {
169 config
.modulation
= DEMOD_NRZ
;
170 } else if ( strcmp(modulation
, "PSK1" ) == 0) {
171 config
.modulation
= DEMOD_PSK1
;
172 } else if ( strcmp(modulation
, "PSK2" ) == 0) {
173 config
.modulation
= DEMOD_PSK2
;
174 } else if ( strcmp(modulation
, "PSK3" ) == 0) {
175 config
.modulation
= DEMOD_PSK3
;
176 } else if ( strcmp(modulation
, "BIa" ) == 0) {
177 config
.modulation
= DEMOD_BIa
;
179 } else if ( strcmp(modulation
, "BI" ) == 0) {
180 config
.modulation
= DEMOD_BI
;
183 PrintAndLog("Unknown modulation '%s'", modulation
);
188 config
.inverted
= param_getchar(Cmd
,cmdp
+1) == '1';
192 errors
|= param_getdec(Cmd
, cmdp
+1, &offset
);
194 config
.offset
= offset
;
198 PrintAndLog("Unknown parameter '%c'", param_getchar(Cmd
, cmdp
));
206 printConfiguration( config
);
211 return usage_t55xx_config();
214 printConfiguration ( config
);
218 int CmdT55xxReadBlock(const char *Cmd
) {
220 int password
= 0xFFFFFFFF; //default to blank Block 7
222 char cmdp
= param_getchar(Cmd
, 0);
223 if (cmdp
== 'h' || cmdp
== 'H') return usage_t55xx_read();
225 int res
= sscanf(Cmd
, "%d %x", &block
, &password
);
227 if ( res
< 1 || res
> 2 ) return usage_t55xx_read();
229 if ((block
< 0) | (block
> 7)) {
230 PrintAndLog("Block must be between 0 and 7");
234 UsbCommand c
= {CMD_T55XX_READ_BLOCK
, {0, block
, 0}};
235 c
.d
.asBytes
[0] = 0x0;
240 // try reading the config block and verify that PWD bit is set before doing this!
241 AquireData( CONFIGURATION_BLOCK
);
242 if ( !tryDetectModulation() ) {
243 PrintAndLog("Could not detect is PWD bit is set in config block. Exits.");
246 //if PWD bit is set, allow to execute read command with password.
247 if (( config
.block0
& T55x7_PWD
) == 1) {
249 c
.d
.asBytes
[0] = 0x1;
251 PrintAndLog("PWD bit is NOT set in config block. Reading without password...");
255 clearCommandBuffer();
257 if ( !WaitForResponseTimeout(CMD_ACK
,NULL
,2500) ) {
258 PrintAndLog("command execution time out");
263 GetFromBigBuf(got
,sizeof(got
),0);
264 WaitForResponse(CMD_ACK
,NULL
);
265 setGraphBuf(got
, sizeof(got
));
267 if (!DecodeT55xxBlock()) return 3;
269 sprintf(blk
,"%d", block
);
270 printT55xxBlock(blk
);
274 bool DecodeT55xxBlock(){
276 char buf
[30] = {0x00};
279 uint8_t bitRate
[8] = {8,16,32,40,50,64,100,128};
280 DemodBufferLen
= 0x00;
282 //trim 1/2 a clock from beginning
283 //snprintf(cmdStr, sizeof(buf),"%d", bitRate[config.bitrate]/2 );
285 switch( config
.modulation
){
287 snprintf(cmdStr
, sizeof(buf
),"%d %d", bitRate
[config
.bitrate
], config
.inverted
);
288 ans
= FSKrawDemod(cmdStr
, FALSE
);
292 snprintf(cmdStr
, sizeof(buf
),"%d %d 8 5", bitRate
[config
.bitrate
], config
.inverted
);
293 ans
= FSKrawDemod(cmdStr
, FALSE
);
297 snprintf(cmdStr
, sizeof(buf
),"%d %d 10 8", bitRate
[config
.bitrate
], config
.inverted
);
298 ans
= FSKrawDemod(cmdStr
, FALSE
);
301 snprintf(cmdStr
, sizeof(buf
),"%d %d 0", bitRate
[config
.bitrate
], config
.inverted
);
302 ans
= ASKDemod(cmdStr
, FALSE
, FALSE
, 1);
305 snprintf(cmdStr
, sizeof(buf
),"%d %d 0", bitRate
[config
.bitrate
], config
.inverted
);
306 ans
= PSKDemod(cmdStr
, FALSE
);
308 case DEMOD_PSK2
: //inverted won't affect this
309 case DEMOD_PSK3
: //not fully implemented
310 snprintf(cmdStr
, sizeof(buf
),"%d 0 1", bitRate
[config
.bitrate
] );
311 ans
= PSKDemod(cmdStr
, FALSE
);
312 psk1TOpsk2(DemodBuffer
, DemodBufferLen
);
315 snprintf(cmdStr
, sizeof(buf
),"%d %d 1", bitRate
[config
.bitrate
], config
.inverted
);
316 ans
= NRZrawDemod(cmdStr
, FALSE
);
320 snprintf(cmdStr
, sizeof(buf
),"0 %d %d 0", bitRate
[config
.bitrate
], config
.inverted
);
321 ans
= ASKbiphaseDemod(cmdStr
, FALSE
);
329 int CmdT55xxDetect(const char *Cmd
){
331 char cmdp
= param_getchar(Cmd
, 0);
332 if (strlen(Cmd
) > 1 || cmdp
== 'h' || cmdp
== 'H')
333 return usage_t55xx_detect();
336 AquireData( CONFIGURATION_BLOCK
);
338 if ( !tryDetectModulation() )
339 PrintAndLog("Could not detect modulation automatically. Try setting it manually with \'lf t55xx config\'");
344 // detect configuration?
345 bool tryDetectModulation(){
346 //char cmdStr[8] = {0};
348 t55xx_conf_block_t tests
[15];
350 uint8_t fc1
= 0, fc2
= 0, clk
=0;
352 if (GetFskClock("", FALSE
, FALSE
)){
353 fskClocks(&fc1
, &fc2
, &clk
, FALSE
);
354 //sprintf(cmdStr,"%d", clk/2);
356 if ( FSKrawDemod("0 0", FALSE
) && test(DEMOD_FSK
, &tests
[hits
].offset
, &bitRate
)){
357 tests
[hits
].modulation
= DEMOD_FSK
;
358 if (fc1
==8 && fc2
== 5)
359 tests
[hits
].modulation
= DEMOD_FSK1a
;
360 else if (fc1
==10 && fc2
== 8)
361 tests
[hits
].modulation
= DEMOD_FSK2
;
362 tests
[hits
].bitrate
= bitRate
;
363 tests
[hits
].inverted
= FALSE
;
364 tests
[hits
].block0
= PackBits(tests
[hits
].offset
, 32, DemodBuffer
);
367 if ( FSKrawDemod("0 1", FALSE
) && test(DEMOD_FSK
, &tests
[hits
].offset
, &bitRate
)) {
368 tests
[hits
].modulation
= DEMOD_FSK
;
369 if (fc1
== 8 && fc2
== 5)
370 tests
[hits
].modulation
= DEMOD_FSK1
;
371 else if (fc1
== 10 && fc2
== 8)
372 tests
[hits
].modulation
= DEMOD_FSK2a
;
374 tests
[hits
].bitrate
= bitRate
;
375 tests
[hits
].inverted
= TRUE
;
376 tests
[hits
].block0
= PackBits(tests
[hits
].offset
, 32, DemodBuffer
);
380 clk
= GetAskClock("", FALSE
, FALSE
);
382 //sprintf(cmdStr,"%d", clk/2);
384 if ( ASKDemod("0 0 0", FALSE
, FALSE
, 1) && test(DEMOD_ASK
, &tests
[hits
].offset
, &bitRate
)) {
385 tests
[hits
].modulation
= DEMOD_ASK
;
386 tests
[hits
].bitrate
= bitRate
;
387 tests
[hits
].inverted
= FALSE
;
388 tests
[hits
].block0
= PackBits(tests
[hits
].offset
, 32, DemodBuffer
);
391 if ( ASKDemod("0 1 0", FALSE
, FALSE
, 1) && test(DEMOD_ASK
, &tests
[hits
].offset
, &bitRate
)) {
392 tests
[hits
].modulation
= DEMOD_ASK
;
393 tests
[hits
].bitrate
= bitRate
;
394 tests
[hits
].inverted
= TRUE
;
395 tests
[hits
].block0
= PackBits(tests
[hits
].offset
, 32, DemodBuffer
);
398 if ( ASKbiphaseDemod("0 0 0 0", FALSE
) && test(DEMOD_BI
, &tests
[hits
].offset
, &bitRate
) ) {
399 tests
[hits
].modulation
= DEMOD_BI
;
400 tests
[hits
].bitrate
= bitRate
;
401 tests
[hits
].inverted
= FALSE
;
402 tests
[hits
].block0
= PackBits(tests
[hits
].offset
, 32, DemodBuffer
);
405 if ( ASKbiphaseDemod("0 0 1 0", FALSE
) && test(DEMOD_BIa
, &tests
[hits
].offset
, &bitRate
) ) {
406 tests
[hits
].modulation
= DEMOD_BIa
;
407 tests
[hits
].bitrate
= bitRate
;
408 tests
[hits
].inverted
= TRUE
;
409 tests
[hits
].block0
= PackBits(tests
[hits
].offset
, 32, DemodBuffer
);
415 clk
= GetNrzClock("", FALSE
, FALSE
);
417 //sprintf(cmdStr,"%d", clk/2);
419 if ( NRZrawDemod("0 0 1", FALSE
) && test(DEMOD_NRZ
, &tests
[hits
].offset
, &bitRate
)) {
420 tests
[hits
].modulation
= DEMOD_NRZ
;
421 tests
[hits
].bitrate
= bitRate
;
422 tests
[hits
].inverted
= FALSE
;
423 tests
[hits
].block0
= PackBits(tests
[hits
].offset
, 32, DemodBuffer
);
427 if ( NRZrawDemod("0 1 1", FALSE
) && test(DEMOD_NRZ
, &tests
[hits
].offset
, &bitRate
)) {
428 tests
[hits
].modulation
= DEMOD_NRZ
;
429 tests
[hits
].bitrate
= bitRate
;
430 tests
[hits
].inverted
= TRUE
;
431 tests
[hits
].block0
= PackBits(tests
[hits
].offset
, 32, DemodBuffer
);
438 clk
= GetPskClock("", FALSE
, FALSE
);
440 //PrintAndLog("clk %d",clk);
441 //sprintf(cmdStr,"%d", clk/2);
443 if ( PSKDemod("0 0 1", FALSE
) && test(DEMOD_PSK1
, &tests
[hits
].offset
, &bitRate
)) {
444 tests
[hits
].modulation
= DEMOD_PSK1
;
445 tests
[hits
].bitrate
= bitRate
;
446 tests
[hits
].inverted
= FALSE
;
447 tests
[hits
].block0
= PackBits(tests
[hits
].offset
, 32, DemodBuffer
);
450 if ( PSKDemod("0 1 1", FALSE
) && test(DEMOD_PSK1
, &tests
[hits
].offset
, &bitRate
)) {
451 tests
[hits
].modulation
= DEMOD_PSK1
;
452 tests
[hits
].bitrate
= bitRate
;
453 tests
[hits
].inverted
= TRUE
;
454 tests
[hits
].block0
= PackBits(tests
[hits
].offset
, 32, DemodBuffer
);
457 // PSK2 - needs a call to psk1TOpsk2.
458 if ( PSKDemod("0 0 1", FALSE
)) {
459 psk1TOpsk2(DemodBuffer
, DemodBufferLen
);
460 if (test(DEMOD_PSK2
, &tests
[hits
].offset
, &bitRate
)){
461 tests
[hits
].modulation
= DEMOD_PSK2
;
462 tests
[hits
].bitrate
= bitRate
;
463 tests
[hits
].inverted
= FALSE
;
464 tests
[hits
].block0
= PackBits(tests
[hits
].offset
, 32, DemodBuffer
);
467 } // inverse waves does not affect this demod
468 // PSK3 - needs a call to psk1TOpsk2.
469 if ( PSKDemod("0 0 1", FALSE
)) {
470 psk1TOpsk2(DemodBuffer
, DemodBufferLen
);
471 if (test(DEMOD_PSK3
, &tests
[hits
].offset
, &bitRate
)){
472 tests
[hits
].modulation
= DEMOD_PSK3
;
473 tests
[hits
].bitrate
= bitRate
;
474 tests
[hits
].inverted
= FALSE
;
475 tests
[hits
].block0
= PackBits(tests
[hits
].offset
, 32, DemodBuffer
);
478 } // inverse waves does not affect this demod
482 config
.modulation
= tests
[0].modulation
;
483 config
.bitrate
= tests
[0].bitrate
;
484 config
.inverted
= tests
[0].inverted
;
485 config
.offset
= tests
[0].offset
;
486 config
.block0
= tests
[0].block0
;
487 printConfiguration( config
);
492 PrintAndLog("Found [%d] possible matches for modulation.",hits
);
493 for(int i
=0; i
<hits
; ++i
){
494 PrintAndLog("--[%d]---------------", i
+1);
495 printConfiguration( tests
[i
] );
501 bool testModulation(uint8_t mode
, uint8_t modread
){
504 if (modread
> 3 && modread
< 8) return TRUE
;
507 if (modread
== DEMOD_ASK
) return TRUE
;
510 if (modread
== DEMOD_PSK1
) return TRUE
;
513 if (modread
== DEMOD_PSK2
) return TRUE
;
516 if (modread
== DEMOD_PSK3
) return TRUE
;
519 if (modread
== DEMOD_NRZ
) return TRUE
;
522 if (modread
== DEMOD_BI
) return TRUE
;
525 if (modread
== DEMOD_BIa
) return TRUE
;
533 bool testBitRate(uint8_t readRate
, uint8_t mod
){
534 uint8_t expected
[8] = {8, 16, 32, 40, 50, 64, 100, 128};
542 detRate
= GetFskClock("",FALSE
, FALSE
);
543 if (expected
[readRate
] == detRate
)
549 detRate
= GetAskClock("",FALSE
, FALSE
);
550 if (expected
[readRate
] == detRate
)
556 detRate
= GetPskClock("",FALSE
, FALSE
);
557 if (expected
[readRate
] == detRate
)
561 detRate
= GetNrzClock("",FALSE
, FALSE
);
562 if (expected
[readRate
] == detRate
)
571 bool test(uint8_t mode
, uint8_t *offset
, int *fndBitRate
){
573 if ( DemodBufferLen
< 64 ) return FALSE
;
575 for (uint8_t idx
= 0; idx
< 64; idx
++){
577 if ( PackBits(si
, 32, DemodBuffer
) == 0x00 ) continue;
579 uint8_t safer
= PackBits(si
, 4, DemodBuffer
); si
+= 4; //master key
580 uint8_t resv
= PackBits(si
, 4, DemodBuffer
); si
+= 4; //was 7 & +=7+3 //should be only 4 bits if extended mode
581 // 2nibble must be zeroed.
582 // moved test to here, since this gets most faults first.
583 if ( resv
> 0x00) continue;
585 uint8_t xtRate
= PackBits(si
, 3, DemodBuffer
); si
+= 3; //extended mode part of rate
586 int bitRate
= PackBits(si
, 3, DemodBuffer
); si
+= 3; //bit rate
587 if (bitRate
> 7) continue;
588 uint8_t extend
= PackBits(si
, 1, DemodBuffer
); si
+= 1; //bit 15 extended mode
589 uint8_t modread
= PackBits(si
, 5, DemodBuffer
); si
+= 5+2+1;
590 //uint8_t pskcr = PackBits(si, 2, DemodBuffer); si += 2+1; //could check psk cr
591 uint8_t nml01
= PackBits(si
, 1, DemodBuffer
); si
+= 1+5; //bit 24, 30, 31 could be tested for 0 if not extended mode
592 uint8_t nml02
= PackBits(si
, 2, DemodBuffer
); si
+= 2;
595 bool extMode
=( (safer
== 0x6 || safer
== 0x9) && extend
) ? TRUE
: FALSE
;
598 if (nml01
|| nml02
|| xtRate
) continue;
601 if (!testModulation(mode
, modread
)) continue;
602 if (!testBitRate(bitRate
, mode
)) continue;
603 *fndBitRate
= bitRate
;
610 void printT55xxBlock(const char *blockNum
){
612 uint8_t i
= config
.offset
;
613 uint8_t endpos
= 32 + i
;
614 uint32_t blockData
= 0;
615 uint8_t bits
[64] = {0x00};
617 if ( !DemodBufferLen
) return;
619 if ( endpos
> DemodBufferLen
){
620 PrintAndLog("The configured offset %d is too big. Possible offset: %d)", i
, DemodBufferLen
-32);
624 for (; i
< endpos
; ++i
)
625 bits
[i
- config
.offset
]=DemodBuffer
[i
];
627 blockData
= PackBits(0, 32, bits
);
628 PrintAndLog("[%s] 0x%08X %s", blockNum
, blockData
, sprint_bin(bits
,32));
631 int special(const char *Cmd
) {
632 uint32_t blockData
= 0;
633 uint8_t bits
[32] = {0x00};
635 PrintAndLog("[OFFSET] [DATA] [BINARY]");
636 PrintAndLog("----------------------------------------------------");
640 for (i
= 0; i
< 32; ++i
)
641 bits
[i
]=DemodBuffer
[j
+i
];
643 blockData
= PackBits(0, 32, bits
);
645 PrintAndLog("[%02d] 0x%08X %s",j
, blockData
, sprint_bin(bits
,32));
650 void printConfiguration( t55xx_conf_block_t b
){
651 PrintAndLog("Modulation : %s", GetSelectedModulationStr(b
.modulation
) );
652 PrintAndLog("Bit Rate : %s", GetBitRateStr(b
.bitrate
) );
653 PrintAndLog("Inverted : %s", (b
.inverted
) ? "Yes" : "No" );
654 PrintAndLog("Offset : %d", b
.offset
);
655 PrintAndLog("Block0 : 0x%08X", b
.block0
);
659 int CmdT55xxWriteBlock(const char *Cmd
)
661 int block
= 8; //default to invalid block
662 int data
= 0xFFFFFFFF; //default to blank Block
663 int password
= 0xFFFFFFFF; //default to blank Block 7
665 char cmdp
= param_getchar(Cmd
, 0);
666 if (cmdp
== 'h' || cmdp
== 'H') {
671 int res
= sscanf(Cmd
, "%d %x %x",&block
, &data
, &password
);
673 if ( res
< 2 || res
> 3) {
679 PrintAndLog("Block number must be between 0 and 7");
683 UsbCommand c
= {CMD_T55XX_WRITE_BLOCK
, {data
, block
, 0}};
685 c
.d
.asBytes
[0] = 0x0;
687 PrintAndLog("Writing to block: %d data : 0x%08X", block
, data
);
692 c
.d
.asBytes
[0] = 0x1;
693 PrintAndLog("pwd : 0x%08X", password
);
695 clearCommandBuffer();
697 if (!WaitForResponseTimeout(CMD_ACK
, &resp
, 1000)){
698 PrintAndLog("Error occurred, device did not ACK write operation. (May be due to old firmware)");
704 int CmdT55xxReadTrace(const char *Cmd
)
706 char cmdp
= param_getchar(Cmd
, 0);
708 if (strlen(Cmd
) > 1 || cmdp
== 'h' || cmdp
== 'H')
709 return usage_t55xx_trace();
712 AquireData( TRACE_BLOCK
);
714 if (!DecodeT55xxBlock()) return 1;
716 if ( !DemodBufferLen
) return 1;
718 RepaintGraphWindow();
720 if (config
.offset
> 5)
722 uint8_t si
= config
.offset
+repeat
;
723 uint32_t bl0
= PackBits(si
, 32, DemodBuffer
);
724 uint32_t bl1
= PackBits(si
+32, 32, DemodBuffer
);
726 uint32_t acl
= PackBits(si
, 8, DemodBuffer
); si
+= 8;
727 uint32_t mfc
= PackBits(si
, 8, DemodBuffer
); si
+= 8;
728 uint32_t cid
= PackBits(si
, 5, DemodBuffer
); si
+= 5;
729 uint32_t icr
= PackBits(si
, 3, DemodBuffer
); si
+= 3;
730 uint32_t year
= PackBits(si
, 4, DemodBuffer
); si
+= 4;
731 uint32_t quarter
= PackBits(si
, 2, DemodBuffer
); si
+= 2;
732 uint32_t lotid
= PackBits(si
, 14, DemodBuffer
); si
+= 14;
733 uint32_t wafer
= PackBits(si
, 5, DemodBuffer
); si
+= 5;
734 uint32_t dw
= PackBits(si
, 15, DemodBuffer
);
736 time_t t
= time(NULL
);
737 struct tm tm
= *localtime(&t
);
738 if ( year
> tm
.tm_year
-110)
744 PrintAndLog("The modulation is most likely wrong since the ACL is not 0xE0. ");
749 PrintAndLog("-- T55xx Trace Information ----------------------------------");
750 PrintAndLog("-------------------------------------------------------------");
751 PrintAndLog(" ACL Allocation class (ISO/IEC 15963-1) : 0x%02X (%d)", acl
, acl
);
752 PrintAndLog(" MFC Manufacturer ID (ISO/IEC 7816-6) : 0x%02X (%d) - %s", mfc
, mfc
, getTagInfo(mfc
));
753 PrintAndLog(" CID : 0x%02X (%d) - %s", cid
, cid
, GetModelStrFromCID(cid
));
754 PrintAndLog(" ICR IC Revision : %d",icr
);
755 PrintAndLog(" Manufactured");
756 PrintAndLog(" Year/Quarter : %d/%d",year
, quarter
);
757 PrintAndLog(" Lot ID : %d", lotid
);
758 PrintAndLog(" Wafer number : %d", wafer
);
759 PrintAndLog(" Die Number : %d", dw
);
760 PrintAndLog("-------------------------------------------------------------");
761 PrintAndLog(" Raw Data - Page 1");
762 PrintAndLog(" Block 0 : 0x%08X %s", bl0
, sprint_bin(DemodBuffer
+config
.offset
+repeat
,32) );
763 PrintAndLog(" Block 1 : 0x%08X %s", bl1
, sprint_bin(DemodBuffer
+config
.offset
+repeat
+32,32) );
764 PrintAndLog("-------------------------------------------------------------");
769 1-8 ACL Allocation class (ISO/IEC 15963-1) 0xE0
770 9-16 MFC Manufacturer ID (ISO/IEC 7816-6) 0x15 Atmel Corporation
771 17-21 CID 0x1 = Atmel ATA5577M1 0x2 = Atmel ATA5577M2
772 22-24 ICR IC revision
773 25-28 YEAR (BCD encoded) 9 (= 2009)
774 29-30 QUARTER 1,2,3,4
780 18-32 DW, die number sequential
786 int CmdT55xxInfo(const char *Cmd
){
788 Page 0 Block 0 Configuration data.
792 char cmdp
= param_getchar(Cmd
, 0);
794 if (strlen(Cmd
) > 1 || cmdp
== 'h' || cmdp
== 'H')
795 return usage_t55xx_info();
798 AquireData( CONFIGURATION_BLOCK
);
800 if (!DecodeT55xxBlock()) return 1;
802 if ( DemodBufferLen
< 32) return 1;
804 uint8_t si
= config
.offset
;
805 uint32_t bl0
= PackBits(si
, 32, DemodBuffer
);
807 uint32_t safer
= PackBits(si
, 4, DemodBuffer
); si
+= 4;
808 uint32_t resv
= PackBits(si
, 7, DemodBuffer
); si
+= 7;
809 uint32_t dbr
= PackBits(si
, 3, DemodBuffer
); si
+= 3;
810 uint32_t extend
= PackBits(si
, 1, DemodBuffer
); si
+= 1;
811 uint32_t datamod
= PackBits(si
, 5, DemodBuffer
); si
+= 5;
812 uint32_t pskcf
= PackBits(si
, 2, DemodBuffer
); si
+= 2;
813 uint32_t aor
= PackBits(si
, 1, DemodBuffer
); si
+= 1;
814 uint32_t otp
= PackBits(si
, 1, DemodBuffer
); si
+= 1;
815 uint32_t maxblk
= PackBits(si
, 3, DemodBuffer
); si
+= 3;
816 uint32_t pwd
= PackBits(si
, 1, DemodBuffer
); si
+= 1;
817 uint32_t sst
= PackBits(si
, 1, DemodBuffer
); si
+= 1;
818 uint32_t fw
= PackBits(si
, 1, DemodBuffer
); si
+= 1;
819 uint32_t inv
= PackBits(si
, 1, DemodBuffer
); si
+= 1;
820 uint32_t por
= PackBits(si
, 1, DemodBuffer
); si
+= 1;
823 PrintAndLog("-- T55xx Configuration & Tag Information --------------------");
824 PrintAndLog("-------------------------------------------------------------");
825 PrintAndLog(" Safer key : %s", GetSaferStr(safer
));
826 PrintAndLog(" reserved : %d", resv
);
827 PrintAndLog(" Data bit rate : %s", GetBitRateStr(dbr
));
828 PrintAndLog(" eXtended mode : %s", (extend
) ? "Yes - Warning":"No");
829 PrintAndLog(" Modulation : %s", GetModulationStr(datamod
));
830 PrintAndLog(" PSK clock frequency : %d", pskcf
);
831 PrintAndLog(" AOR - Answer on Request : %s", (aor
) ? "Yes":"No");
832 PrintAndLog(" OTP - One Time Pad : %s", (otp
) ? "Yes - Warning":"No" );
833 PrintAndLog(" Max block : %d", maxblk
);
834 PrintAndLog(" Password mode : %s", (pwd
) ? "Yes":"No");
835 PrintAndLog(" Sequence Start Terminator : %s", (sst
) ? "Yes":"No");
836 PrintAndLog(" Fast Write : %s", (fw
) ? "Yes":"No");
837 PrintAndLog(" Inverse data : %s", (inv
) ? "Yes":"No");
838 PrintAndLog(" POR-Delay : %s", (por
) ? "Yes":"No");
839 PrintAndLog("-------------------------------------------------------------");
840 PrintAndLog(" Raw Data - Page 0");
841 PrintAndLog(" Block 0 : 0x%08X %s", bl0
, sprint_bin(DemodBuffer
+config
.offset
,32) );
842 PrintAndLog("-------------------------------------------------------------");
847 int CmdT55xxDump(const char *Cmd
){
850 uint8_t pwd
[4] = {0x00};
852 char cmdp
= param_getchar(Cmd
, 0);
853 if ( cmdp
== 'h' || cmdp
== 'H') {
858 bool hasPwd
= ( strlen(Cmd
) > 0);
860 if (param_gethex(Cmd
, 0, pwd
, 8)) {
861 PrintAndLog("password must include 8 HEX symbols");
866 for ( int i
= 0; i
<8; ++i
){
867 memset(s
,0,sizeof(s
));
869 sprintf(s
,"%d %02x%02x%02x%02x", i
, pwd
[0],pwd
[1],pwd
[2],pwd
[3]);
873 CmdT55xxReadBlock(s
);
878 int AquireData( uint8_t block
){
882 if ( block
== CONFIGURATION_BLOCK
)
883 c
.cmd
= CMD_T55XX_READ_BLOCK
;
884 else if (block
== TRACE_BLOCK
)
885 c
.cmd
= CMD_T55XX_READ_TRACE
;
890 c
.d
.asBytes
[0] = 0x0;
894 // c.arg[2] = password;
895 // c.d.asBytes[0] = 0x1;
898 clearCommandBuffer();
900 if ( !WaitForResponseTimeout(CMD_ACK
,NULL
,2500) ) {
901 PrintAndLog("command execution time out");
906 GetFromBigBuf(got
,sizeof(got
),0);
907 WaitForResponse(CMD_ACK
,NULL
);
908 setGraphBuf(got
, 12000);
912 char * GetBitRateStr(uint32_t id
){
918 snprintf(retStr
,sizeof(buf
),"%d - RF/8",id
);
921 snprintf(retStr
,sizeof(buf
),"%d - RF/16",id
);
924 snprintf(retStr
,sizeof(buf
),"%d - RF/32",id
);
927 snprintf(retStr
,sizeof(buf
),"%d - RF/40",id
);
930 snprintf(retStr
,sizeof(buf
),"%d - RF/50",id
);
933 snprintf(retStr
,sizeof(buf
),"%d - RF/64",id
);
936 snprintf(retStr
,sizeof(buf
),"%d - RF/100",id
);
939 snprintf(retStr
,sizeof(buf
),"%d - RF/128",id
);
942 snprintf(retStr
,sizeof(buf
),"%d - (Unknown)",id
);
949 char * GetSaferStr(uint32_t id
){
953 snprintf(retStr
,sizeof(buf
),"%d",id
);
955 snprintf(retStr
,sizeof(buf
),"%d - passwd",id
);
958 snprintf(retStr
,sizeof(buf
),"%d - testmode",id
);
964 char * GetModulationStr( uint32_t id
){
970 snprintf(retStr
,sizeof(buf
),"%d - DIRECT (ASK/NRZ)",id
);
973 snprintf(retStr
,sizeof(buf
),"%d - PSK 1 phase change when input changes",id
);
976 snprintf(retStr
,sizeof(buf
),"%d - PSK 2 phase change on bitclk if input high",id
);
979 snprintf(retStr
,sizeof(buf
),"%d - PSK 3 phase change on rising edge of input",id
);
982 snprintf(retStr
,sizeof(buf
),"%d - FSK 1 RF/8 RF/5",id
);
985 snprintf(retStr
,sizeof(buf
),"%d - FSK 2 RF/8 RF/10",id
);
988 snprintf(retStr
,sizeof(buf
),"%d - FSK 1a RF/5 RF/8",id
);
991 snprintf(retStr
,sizeof(buf
),"%d - FSK 2a RF/10 RF/8",id
);
994 snprintf(retStr
,sizeof(buf
),"%d - Manchester",id
);
997 snprintf(retStr
,sizeof(buf
),"%d - Biphase",id
);
1000 snprintf(retStr
,sizeof(buf
),"%d - Biphase a - AKA Conditional Dephase Encoding(CDP)",id
);
1003 snprintf(retStr
,sizeof(buf
),"%d - Reserved",id
);
1006 snprintf(retStr
,sizeof(buf
),"0x%02X (Unknown)",id
);
1012 char * GetModelStrFromCID(uint32_t cid
){
1014 static char buf
[10];
1017 if (cid
== 1) snprintf(retStr
, sizeof(buf
),"ATA5577M1");
1018 if (cid
== 2) snprintf(retStr
, sizeof(buf
),"ATA5577M2");
1022 char * GetSelectedModulationStr( uint8_t id
){
1024 static char buf
[20];
1029 snprintf(retStr
,sizeof(buf
),"FSK");
1032 snprintf(retStr
,sizeof(buf
),"FSK1");
1035 snprintf(retStr
,sizeof(buf
),"FSK1a");
1038 snprintf(retStr
,sizeof(buf
),"FSK2");
1041 snprintf(retStr
,sizeof(buf
),"FSK2a");
1044 snprintf(retStr
,sizeof(buf
),"ASK");
1047 snprintf(retStr
,sizeof(buf
),"DIRECT/NRZ");
1050 snprintf(retStr
,sizeof(buf
),"PSK1");
1053 snprintf(retStr
,sizeof(buf
),"PSK2");
1056 snprintf(retStr
,sizeof(buf
),"PSK3");
1059 snprintf(retStr
,sizeof(buf
),"BIPHASE");
1062 snprintf(retStr
,sizeof(buf
),"BIPHASEa - (CDP)");
1065 snprintf(retStr
,sizeof(buf
),"(Unknown)");
1071 void t55x7_create_config_block( int tagtype
){
1078 uint32_t PackBits(uint8_t start, uint8_t len, uint8_t* bits){
1083 if (len > 32) return 0;
1086 for (; j >= 0; --j, ++i)
1087 tmp |= bits[i] << j;
1092 static command_t CommandTable
[] =
1094 {"help", CmdHelp
, 1, "This help"},
1095 {"config", CmdT55xxSetConfig
, 1, "Set/Get T55XX configuration (modulation, inverted, offset, rate)"},
1096 {"detect", CmdT55xxDetect
, 0, "[1] Try detecting the tag modulation from reading the configuration block."},
1097 {"read", CmdT55xxReadBlock
, 0, "<block> [password] -- Read T55xx block data (page 0) [optional password]"},
1098 {"write", CmdT55xxWriteBlock
,0, "<block> <data> [password] -- Write T55xx block data (page 0) [optional password]"},
1099 {"trace", CmdT55xxReadTrace
, 0, "[1] Show T55xx traceability data (page 1/ blk 0-1)"},
1100 {"info", CmdT55xxInfo
, 0, "[1] Show T55xx configuration data (page 0/ blk 0)"},
1101 {"dump", CmdT55xxDump
, 0, "[password] Dump T55xx card block 0-7. [optional password]"},
1102 {"special", special
, 0, "Show block changes with 64 different offsets"},
1103 {NULL
, NULL
, 0, NULL
}
1106 int CmdLFT55XX(const char *Cmd
)
1108 CmdsParse(CommandTable
, Cmd
);
1112 int CmdHelp(const char *Cmd
)
1114 CmdsHelp(CommandTable
);