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(" b <8|16|32|40|50|64|100|128> Set bitrate");
39 PrintAndLog(" d <FSK|FSK1|FSK1a|FSK2|FSK2a|ASK|PSK1|PSK2|NZ|BI|BIa> Set demodulation FSK / ASK / PSK / NZ / Biphase / Biphase A");
40 PrintAndLog(" i [1] Invert data signal, defaults to normal");
41 PrintAndLog(" o [offset] Set offset, where data should start decode in bitstream");
43 PrintAndLog("Examples:");
44 PrintAndLog(" lf t55xx config d FSK - FSK demodulation");
45 PrintAndLog(" lf t55xx config d FSK i 1 - FSK demodulation, inverse data");
46 PrintAndLog(" lf t55xx config d FSK i 1 o 3 - FSK demodulation, inverse data, offset=3,start from position 3 to decode data");
50 int usage_t55xx_read(){
51 PrintAndLog("Usage: lf t55xx read <block> <password>");
52 PrintAndLog(" <block>, block number to read. Between 0-7");
53 PrintAndLog(" <password>, OPTIONAL password (8 hex characters)");
55 PrintAndLog("Examples:");
56 PrintAndLog(" lf t55xx read 0 - read data from block 0");
57 PrintAndLog(" lf t55xx read 0 feedbeef - read data from block 0 password feedbeef");
61 int usage_t55xx_write(){
62 PrintAndLog("Usage: lf t55xx wr <block> <data> [password]");
63 PrintAndLog(" <block>, block number to read. Between 0-7");
64 PrintAndLog(" <data>, 4 bytes of data to write (8 hex characters)");
65 PrintAndLog(" [password], OPTIONAL password 4bytes (8 hex characters)");
67 PrintAndLog("Examples:");
68 PrintAndLog(" lf t55xx wd 3 11223344 - write 11223344 to block 3");
69 PrintAndLog(" lf t55xx wd 3 11223344 feedbeef - write 11223344 to block 3 password feedbeef");
73 int usage_t55xx_trace() {
74 PrintAndLog("Usage: lf t55xx trace [1]");
75 PrintAndLog(" [graph buffer data], if set, use Graphbuffer otherwise read data from tag.");
77 PrintAndLog("Examples:");
78 PrintAndLog(" lf t55xx trace");
79 PrintAndLog(" lf t55xx trace 1");
83 int usage_t55xx_info() {
84 PrintAndLog("Usage: lf t55xx info [1]");
85 PrintAndLog(" [graph buffer data], if set, use Graphbuffer otherwise read data from tag.");
87 PrintAndLog("Examples:");
88 PrintAndLog(" lf t55xx info");
89 PrintAndLog(" lf t55xx info 1");
93 int usage_t55xx_dump(){
94 PrintAndLog("Usage: lf t55xx dump <password>");
95 PrintAndLog(" <password>, OPTIONAL password 4bytes (8 hex symbols)");
97 PrintAndLog("Examples:");
98 PrintAndLog(" lf t55xx dump");
99 PrintAndLog(" lf t55xx dump feedbeef");
103 int usage_t55xx_detect(){
104 PrintAndLog("Usage: lf t55xx detect");
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 uint8_t rates
[9] = {8,16,32,40,50,64,100,128,0};
124 while(param_getchar(Cmd
, cmdp
) != 0x00 && !errors
)
126 tmp
= param_getchar(Cmd
, cmdp
);
131 return usage_t55xx_config();
133 errors
|= param_getdec(Cmd
, cmdp
+1, &bitRate
);
137 if (rates
[i
]==bitRate
) {
142 if (i
==9) errors
= TRUE
;
147 param_getstr(Cmd
, cmdp
+1, modulation
);
150 if ( strcmp(modulation
, "FSK" ) == 0) {
151 config
.modulation
= DEMOD_FSK
;
152 } else if ( strcmp(modulation
, "FSK1" ) == 0) {
153 config
.modulation
= DEMOD_FSK1
;
155 } else if ( strcmp(modulation
, "FSK1a" ) == 0) {
156 config
.modulation
= DEMOD_FSK1a
;
158 } else if ( strcmp(modulation
, "FSK2" ) == 0) {
159 config
.modulation
= DEMOD_FSK2
;
161 } else if ( strcmp(modulation
, "FSK2a" ) == 0) {
162 config
.modulation
= DEMOD_FSK2a
;
164 } else if ( strcmp(modulation
, "ASK" ) == 0) {
165 config
.modulation
= DEMOD_ASK
;
166 } else if ( strcmp(modulation
, "NRZ" ) == 0) {
167 config
.modulation
= DEMOD_NRZ
;
168 } else if ( strcmp(modulation
, "PSK1" ) == 0) {
169 config
.modulation
= DEMOD_PSK1
;
170 } else if ( strcmp(modulation
, "PSK2" ) == 0) {
171 config
.modulation
= DEMOD_PSK2
;
172 } else if ( strcmp(modulation
, "PSK3" ) == 0) {
173 config
.modulation
= DEMOD_PSK3
;
174 } else if ( strcmp(modulation
, "BIa" ) == 0) {
175 config
.modulation
= DEMOD_BIa
;
177 } else if ( strcmp(modulation
, "BI" ) == 0) {
178 config
.modulation
= DEMOD_BI
;
181 PrintAndLog("Unknown modulation '%s'", modulation
);
186 config
.inverted
= param_getchar(Cmd
,cmdp
+1) == '1';
190 errors
|= param_getdec(Cmd
, cmdp
+1, &offset
);
192 config
.offset
= offset
;
196 PrintAndLog("Unknown parameter '%c'", param_getchar(Cmd
, cmdp
));
204 printConfiguration( config
);
209 return usage_t55xx_config();
212 printConfiguration ( config
);
216 int CmdT55xxReadBlock(const char *Cmd
) {
218 int password
= 0xFFFFFFFF; //default to blank Block 7
220 char cmdp
= param_getchar(Cmd
, 0);
221 if (cmdp
== 'h' || cmdp
== 'H')
222 return usage_t55xx_read();
224 int res
= sscanf(Cmd
, "%d %x", &block
, &password
);
226 if ( res
< 1 || res
> 2 )
227 return usage_t55xx_read();
230 if ((block
< 0) | (block
> 7)) {
231 PrintAndLog("Block must be between 0 and 7");
235 UsbCommand c
= {CMD_T55XX_READ_BLOCK
, {0, block
, 0}};
236 c
.d
.asBytes
[0] = 0x0;
241 c
.d
.asBytes
[0] = 0x1;
245 if ( !WaitForResponseTimeout(CMD_ACK
,NULL
,2500) ) {
246 PrintAndLog("command execution time out");
251 GetFromBigBuf(got
,sizeof(got
),0);
252 WaitForResponse(CMD_ACK
,NULL
);
253 setGraphBuf(got
, 12000);
255 if (!DecodeT55xxBlock()) return 3;
257 sprintf(blk
,"%d", block
);
258 printT55xxBlock(blk
);
262 bool DecodeT55xxBlock(){
264 char buf
[8] = {0x00};
267 uint8_t bitRate
[8] = {8,16,32,40,50,64,100,128};
269 DemodBufferLen
= 0x00;
271 switch( config
.modulation
){
273 sprintf(cmdStr
,"%d", bitRate
[config
.bitrate
]/2 );
275 sprintf(cmdStr
,"%d %d", bitRate
[config
.bitrate
], config
.inverted
);
276 ans
= FSKrawDemod(cmdStr
, FALSE
);
280 sprintf(cmdStr
,"%d", bitRate
[config
.bitrate
]/2 );
282 sprintf(cmdStr
,"%d %d 8 5", bitRate
[config
.bitrate
], config
.inverted
);
283 ans
= FSKrawDemod(cmdStr
, FALSE
);
287 sprintf(cmdStr
,"%d", bitRate
[config
.bitrate
]/2 );
289 sprintf(cmdStr
,"%d %d 10 8", bitRate
[config
.bitrate
], config
.inverted
);
290 ans
= FSKrawDemod(cmdStr
, FALSE
);
293 sprintf(cmdStr
,"%d %d 0", bitRate
[config
.bitrate
], config
.inverted
);
294 ans
= ASKmanDemod(cmdStr
, FALSE
, FALSE
);
297 sprintf(cmdStr
,"%d %d 0", bitRate
[config
.bitrate
], config
.inverted
);
298 ans
= PSKDemod(cmdStr
, FALSE
);
300 case DEMOD_PSK2
: //inverted won't affect this
301 case DEMOD_PSK3
: //not fully implemented
302 sprintf(cmdStr
,"%d 0 1", bitRate
[config
.bitrate
] );
303 ans
= PSKDemod(cmdStr
, FALSE
);
304 psk1TOpsk2(DemodBuffer
, DemodBufferLen
);
307 sprintf(cmdStr
,"%d %d 1", bitRate
[config
.bitrate
], config
.inverted
);
308 ans
= NRZrawDemod(cmdStr
, FALSE
);
312 sprintf(cmdStr
,"0 %d %d 0", bitRate
[config
.bitrate
], config
.inverted
);
313 ans
= ASKbiphaseDemod(cmdStr
, FALSE
);
321 int CmdT55xxDetect(const char *Cmd
){
323 char cmdp
= param_getchar(Cmd
, 0);
324 if (strlen(Cmd
) > 1 || cmdp
== 'h' || cmdp
== 'H')
325 return usage_t55xx_detect();
328 AquireData( CONFIGURATION_BLOCK
);
330 if ( !tryDetectModulation() )
331 PrintAndLog("Could not detect modulation automatically. Try setting it manually with \'lf t55xx config\'");
336 // detect configuration?
337 bool tryDetectModulation(){
338 char cmdStr
[8] = {0};
340 t55xx_conf_block_t tests
[15];
342 if (GetFskClock("", FALSE
, FALSE
)){
343 uint8_t fc1
= 0, fc2
= 0, clk
=0;
344 fskClocks(&fc1
, &fc2
, &clk
, FALSE
);
345 sprintf(cmdStr
,"%d", clk
/2);
347 if ( FSKrawDemod("0 0", FALSE
) && test(DEMOD_FSK
, &tests
[hits
].offset
)){
348 tests
[hits
].modulation
= DEMOD_FSK
;
349 if (fc1
==8 && fc2
== 5)
350 tests
[hits
].modulation
= DEMOD_FSK1a
;
351 else if (fc1
==10 && fc2
== 8)
352 tests
[hits
].modulation
= DEMOD_FSK2
;
354 tests
[hits
].inverted
= FALSE
;
355 tests
[hits
].block0
= PackBits(tests
[hits
].offset
, 32, DemodBuffer
);
358 if ( FSKrawDemod("0 1", FALSE
) && test(DEMOD_FSK
, &tests
[hits
].offset
)) {
359 tests
[hits
].modulation
= DEMOD_FSK
;
360 if (fc1
==8 && fc2
== 5)
361 tests
[hits
].modulation
= DEMOD_FSK1
;
362 else if (fc1
==10 && fc2
== 8)
363 tests
[hits
].modulation
= DEMOD_FSK2a
;
365 tests
[hits
].inverted
= TRUE
;
366 tests
[hits
].block0
= PackBits(tests
[hits
].offset
, 32, DemodBuffer
);
370 if ( ASKmanDemod("0 0 1", FALSE
, FALSE
) && test(DEMOD_ASK
, &tests
[hits
].offset
)) {
371 tests
[hits
].modulation
= DEMOD_ASK
;
372 tests
[hits
].inverted
= FALSE
;
373 tests
[hits
].block0
= PackBits(tests
[hits
].offset
, 32, DemodBuffer
);
377 if ( ASKmanDemod("0 1 1", FALSE
, FALSE
) && test(DEMOD_ASK
, &tests
[hits
].offset
)) {
378 tests
[hits
].modulation
= DEMOD_ASK
;
379 tests
[hits
].inverted
= TRUE
;
380 tests
[hits
].block0
= PackBits(tests
[hits
].offset
, 32, DemodBuffer
);
384 if ( NRZrawDemod("0 0 1", FALSE
) && test(DEMOD_NRZ
, &tests
[hits
].offset
)) {
385 tests
[hits
].modulation
= DEMOD_NRZ
;
386 tests
[hits
].inverted
= FALSE
;
387 tests
[hits
].block0
= PackBits(tests
[hits
].offset
, 32, DemodBuffer
);
391 if ( NRZrawDemod("0 1 1", FALSE
) && test(DEMOD_NRZ
, &tests
[hits
].offset
)) {
392 tests
[hits
].modulation
= DEMOD_NRZ
;
393 tests
[hits
].inverted
= TRUE
;
394 tests
[hits
].block0
= PackBits(tests
[hits
].offset
, 32, DemodBuffer
);
398 if ( PSKDemod("0 0 1", FALSE
) && test(DEMOD_PSK1
, &tests
[hits
].offset
)) {
399 tests
[hits
].modulation
= DEMOD_PSK1
;
400 tests
[hits
].inverted
= FALSE
;
401 tests
[hits
].block0
= PackBits(tests
[hits
].offset
, 32, DemodBuffer
);
405 if ( PSKDemod("0 1 1", FALSE
) && test(DEMOD_PSK1
, &tests
[hits
].offset
)) {
406 tests
[hits
].modulation
= DEMOD_PSK1
;
407 tests
[hits
].inverted
= TRUE
;
408 tests
[hits
].block0
= PackBits(tests
[hits
].offset
, 32, DemodBuffer
);
412 // PSK2 - needs a call to psk1TOpsk2.
413 if ( PSKDemod("0 0 1", FALSE
)) {
414 psk1TOpsk2(DemodBuffer
, DemodBufferLen
);
415 if (test(DEMOD_PSK2
, &tests
[hits
].offset
)){
416 tests
[hits
].modulation
= DEMOD_PSK2
;
417 tests
[hits
].inverted
= FALSE
;
418 tests
[hits
].block0
= PackBits(tests
[hits
].offset
, 32, DemodBuffer
);
421 } // inverse waves does not affect this demod
423 // PSK3 - needs a call to psk1TOpsk2.
424 if ( PSKDemod("0 0 1", FALSE
)) {
425 psk1TOpsk2(DemodBuffer
, DemodBufferLen
);
426 if (test(DEMOD_PSK3
, &tests
[hits
].offset
)){
427 tests
[hits
].modulation
= DEMOD_PSK3
;
428 tests
[hits
].inverted
= FALSE
;
429 tests
[hits
].block0
= PackBits(tests
[hits
].offset
, 32, DemodBuffer
);
432 } // inverse waves does not affect this demod
434 if ( ASKbiphaseDemod("0 0 0 1", FALSE
) && test(DEMOD_BI
, &tests
[hits
].offset
) ) {
435 tests
[hits
].modulation
= DEMOD_BI
;
436 tests
[hits
].inverted
= FALSE
;
437 tests
[hits
].block0
= PackBits(tests
[hits
].offset
, 32, DemodBuffer
);
440 if ( ASKbiphaseDemod("0 0 1 1", FALSE
) && test(DEMOD_BIa
, &tests
[hits
].offset
) ) {
441 tests
[hits
].modulation
= DEMOD_BIa
;
442 tests
[hits
].inverted
= TRUE
;
443 tests
[hits
].block0
= PackBits(tests
[hits
].offset
, 32, DemodBuffer
);
448 config
.modulation
= tests
[0].modulation
;
449 config
.inverted
= tests
[0].inverted
;
450 config
.offset
= tests
[0].offset
;
451 config
.block0
= tests
[0].block0
;
452 printConfiguration( config
);
457 PrintAndLog("Found [%d] possible matches for modulation.",hits
);
458 for(int i
=0; i
<hits
; ++i
){
459 PrintAndLog("--[%d]---------------", i
+1);
460 printConfiguration( tests
[i
] );
466 bool testModulation(uint8_t mode
, uint8_t modread
){
469 if (modread
> 3 && modread
< 8) return TRUE
;
472 if (modread
== DEMOD_ASK
) return TRUE
;
475 if (modread
== DEMOD_PSK1
) return TRUE
;
478 if (modread
== DEMOD_PSK2
) return TRUE
;
481 if (modread
== DEMOD_PSK3
) return TRUE
;
484 if (modread
== DEMOD_NRZ
) return TRUE
;
487 if (modread
== DEMOD_BI
) return TRUE
;
490 if (modread
== DEMOD_BIa
) return TRUE
;
498 bool testBitRate(uint8_t readRate
, uint8_t mod
){
499 uint8_t expected
[8] = {8, 16, 32, 40, 50, 64, 100, 128};
507 detRate
= GetFskClock("",FALSE
, FALSE
);
508 if (expected
[readRate
] == detRate
) {
509 config
.bitrate
= readRate
;
516 detRate
= GetAskClock("",FALSE
, FALSE
);
517 if (expected
[readRate
] == detRate
) {
518 config
.bitrate
= readRate
;
525 detRate
= GetPskClock("",FALSE
, FALSE
);
526 if (expected
[readRate
] == detRate
) {
527 config
.bitrate
= readRate
;
532 detRate
= GetNrzClock("",FALSE
, FALSE
);
533 if (expected
[readRate
] == detRate
) {
534 config
.bitrate
= readRate
;
544 bool test(uint8_t mode
, uint8_t *offset
){
546 if ( !DemodBufferLen
) return FALSE
;
548 for (uint8_t idx
= 0; idx
< 64; idx
++){
550 if ( PackBits(si
, 32, DemodBuffer
) == 0x00 ) continue;
552 uint8_t safer
= PackBits(si
, 4, DemodBuffer
); si
+= 4; //master key
553 uint8_t resv
= PackBits(si
, 4, DemodBuffer
); si
+= 4; //was 7 & +=7+3 //should be only 4 bits if extended mode
554 // 2nibble must be zeroed.
555 // moved test to here, since this gets most faults first.
556 if ( resv
> 0x00) continue;
558 uint8_t xtRate
= PackBits(si
, 3, DemodBuffer
); si
+= 3; //extended mode part of rate
559 uint8_t bitRate
= PackBits(si
, 3, DemodBuffer
); si
+= 3; //bit rate
560 uint8_t extend
= PackBits(si
, 1, DemodBuffer
); si
+= 1; //bit 15 extended mode
561 uint8_t modread
= PackBits(si
, 5, DemodBuffer
); si
+= 5+2+1;
562 //uint8_t pskcr = PackBits(si, 2, DemodBuffer); si += 2+1; //could check psk cr
563 uint8_t nml01
= PackBits(si
, 1, DemodBuffer
); si
+= 1+5; //bit 24, 30, 31 could be tested for 0 if not extended mode
564 uint8_t nml02
= PackBits(si
, 2, DemodBuffer
); si
+= 2;
567 bool extMode
=( (safer
== 0x6 || safer
== 0x9) && extend
) ? TRUE
: FALSE
;
570 if (nml01
|| nml02
|| xtRate
) continue;
573 if (!testModulation(mode
, modread
)) continue;
574 if (!testBitRate(bitRate
, mode
)) continue;
581 void printT55xxBlock(const char *demodStr
){
583 uint8_t i
= config
.offset
;
584 uint8_t endpos
= 32 + i
;
585 uint32_t blockData
= 0;
586 uint8_t bits
[64] = {0x00};
588 if ( !DemodBufferLen
) return;
590 if ( endpos
> DemodBufferLen
){
591 PrintAndLog("The configured offset %d is too big. Possible offset: %d)", i
, DemodBufferLen
-32);
595 for (; i
< endpos
; ++i
)
596 bits
[i
- config
.offset
]=DemodBuffer
[i
];
598 blockData
= PackBits(0, 32, bits
);
599 PrintAndLog("0x%08X %s [%s]", blockData
, sprint_bin(bits
,32), demodStr
);
602 int special(const char *Cmd
) {
603 uint32_t blockData
= 0;
604 uint8_t bits
[32] = {0x00};
606 PrintAndLog("[OFFSET] [DATA] [BINARY]");
607 PrintAndLog("----------------------------------------------------");
611 for (i
= 0; i
< 32; ++i
)
612 bits
[i
]=DemodBuffer
[j
+i
];
614 blockData
= PackBits(0, 32, bits
);
616 PrintAndLog("[%02d] 0x%08X %s",j
, blockData
, sprint_bin(bits
,32));
621 void printConfiguration( t55xx_conf_block_t b
){
622 PrintAndLog("Modulation : %s", GetSelectedModulationStr(b
.modulation
) );
623 PrintAndLog("Bit Rate : %s", GetBitRateStr(b
.bitrate
) );
624 PrintAndLog("Inverted : %s", (b
.inverted
) ? "Yes" : "No" );
625 PrintAndLog("Offset : %d", b
.offset
);
626 PrintAndLog("Block0 : 0x%08X", b
.block0
);
630 int CmdT55xxWriteBlock(const char *Cmd
)
632 int block
= 8; //default to invalid block
633 int data
= 0xFFFFFFFF; //default to blank Block
634 int password
= 0xFFFFFFFF; //default to blank Block 7
636 char cmdp
= param_getchar(Cmd
, 0);
637 if (cmdp
== 'h' || cmdp
== 'H') {
642 int res
= sscanf(Cmd
, "%d %x %x",&block
, &data
, &password
);
644 if ( res
< 2 || res
> 3) {
650 PrintAndLog("Block number must be between 0 and 7");
654 UsbCommand c
= {CMD_T55XX_WRITE_BLOCK
, {data
, block
, 0}};
655 c
.d
.asBytes
[0] = 0x0;
657 PrintAndLog("Writing to block: %d data : 0x%08X", block
, data
);
662 c
.d
.asBytes
[0] = 0x1;
663 PrintAndLog("pwd : 0x%08X", password
);
669 int CmdT55xxReadTrace(const char *Cmd
)
671 char cmdp
= param_getchar(Cmd
, 0);
673 if (strlen(Cmd
) > 1 || cmdp
== 'h' || cmdp
== 'H')
674 return usage_t55xx_trace();
677 AquireData( TRACE_BLOCK
);
679 if (!DecodeT55xxBlock()) return 1;
681 if ( !DemodBufferLen
) return 1;
683 RepaintGraphWindow();
685 if (config
.offset
> 5)
687 uint8_t si
= config
.offset
+repeat
;
688 uint32_t bl0
= PackBits(si
, 32, DemodBuffer
);
689 uint32_t bl1
= PackBits(si
+32, 32, DemodBuffer
);
691 uint32_t acl
= PackBits(si
, 8, DemodBuffer
); si
+= 8;
692 uint32_t mfc
= PackBits(si
, 8, DemodBuffer
); si
+= 8;
693 uint32_t cid
= PackBits(si
, 5, DemodBuffer
); si
+= 5;
694 uint32_t icr
= PackBits(si
, 3, DemodBuffer
); si
+= 3;
695 uint32_t year
= PackBits(si
, 4, DemodBuffer
); si
+= 4;
696 uint32_t quarter
= PackBits(si
, 2, DemodBuffer
); si
+= 2;
697 uint32_t lotid
= PackBits(si
, 14, DemodBuffer
); si
+= 14;
698 uint32_t wafer
= PackBits(si
, 5, DemodBuffer
); si
+= 5;
699 uint32_t dw
= PackBits(si
, 15, DemodBuffer
);
702 PrintAndLog("-- T55xx Trace Information ----------------------------------");
703 PrintAndLog("-------------------------------------------------------------");
704 PrintAndLog(" ACL Allocation class (ISO/IEC 15963-1) : 0x%02X (%d)", acl
, acl
);
705 PrintAndLog(" MFC Manufacturer ID (ISO/IEC 7816-6) : 0x%02X (%d) - %s", mfc
, mfc
, getTagInfo(mfc
));
706 PrintAndLog(" CID : 0x%02X (%d) - %s", cid
, cid
, GetModelStrFromCID(cid
));
707 PrintAndLog(" ICR IC Revision : %d",icr
);
708 PrintAndLog(" Manufactured");
709 PrintAndLog(" Year/Quarter : 20?%d/%d",year
, quarter
);
710 PrintAndLog(" Lot ID : %d", lotid
);
711 PrintAndLog(" Wafer number : %d", wafer
);
712 PrintAndLog(" Die Number : %d", dw
);
713 PrintAndLog("-------------------------------------------------------------");
714 PrintAndLog(" Raw Data - Page 1");
715 PrintAndLog(" Block 0 : 0x%08X %s", bl0
, sprint_bin(DemodBuffer
+config
.offset
+repeat
,32) );
716 PrintAndLog(" Block 1 : 0x%08X %s", bl1
, sprint_bin(DemodBuffer
+config
.offset
+repeat
+32,32) );
717 PrintAndLog("-------------------------------------------------------------");
720 PrintAndLog("The modulation is most likely wrong since the ACL is not 0xE0. ");
724 1-8 ACL Allocation class (ISO/IEC 15963-1) 0xE0
725 9-16 MFC Manufacturer ID (ISO/IEC 7816-6) 0x15 Atmel Corporation
726 17-21 CID 0x1 = Atmel ATA5577M1 0x2 = Atmel ATA5577M2
727 22-24 ICR IC revision
728 25-28 YEAR (BCD encoded) 9 (= 2009)
729 29-30 QUARTER 1,2,3,4
735 18-32 DW, die number sequential
741 int CmdT55xxInfo(const char *Cmd
){
743 Page 0 Block 0 Configuration data.
747 char cmdp
= param_getchar(Cmd
, 0);
749 if (strlen(Cmd
) > 1 || cmdp
== 'h' || cmdp
== 'H')
750 return usage_t55xx_info();
753 AquireData( CONFIGURATION_BLOCK
);
755 if (!DecodeT55xxBlock()) return 1;
757 if ( !DemodBufferLen
) return 1;
759 uint8_t si
= config
.offset
;
760 uint32_t bl0
= PackBits(si
, 32, DemodBuffer
);
762 uint32_t safer
= PackBits(si
, 4, DemodBuffer
); si
+= 4;
763 uint32_t resv
= PackBits(si
, 7, DemodBuffer
); si
+= 7;
764 uint32_t dbr
= PackBits(si
, 3, DemodBuffer
); si
+= 3;
765 uint32_t extend
= PackBits(si
, 1, DemodBuffer
); si
+= 1;
766 uint32_t datamod
= PackBits(si
, 5, DemodBuffer
); si
+= 5;
767 uint32_t pskcf
= PackBits(si
, 2, DemodBuffer
); si
+= 2;
768 uint32_t aor
= PackBits(si
, 1, DemodBuffer
); si
+= 1;
769 uint32_t otp
= PackBits(si
, 1, DemodBuffer
); si
+= 1;
770 uint32_t maxblk
= PackBits(si
, 3, DemodBuffer
); si
+= 3;
771 uint32_t pwd
= PackBits(si
, 1, DemodBuffer
); si
+= 1;
772 uint32_t sst
= PackBits(si
, 1, DemodBuffer
); si
+= 1;
773 uint32_t fw
= PackBits(si
, 1, DemodBuffer
); si
+= 1;
774 uint32_t inv
= PackBits(si
, 1, DemodBuffer
); si
+= 1;
775 uint32_t por
= PackBits(si
, 1, DemodBuffer
); si
+= 1;
778 PrintAndLog("-- T55xx Configuration & Tag Information --------------------");
779 PrintAndLog("-------------------------------------------------------------");
780 PrintAndLog(" Safer key : %s", GetSaferStr(safer
));
781 PrintAndLog(" reserved : %d", resv
);
782 PrintAndLog(" Data bit rate : %s", GetBitRateStr(dbr
));
783 PrintAndLog(" eXtended mode : %s", (extend
) ? "Yes - Warning":"No");
784 PrintAndLog(" Modulation : %s", GetModulationStr(datamod
));
785 PrintAndLog(" PSK clock frequency : %d", pskcf
);
786 PrintAndLog(" AOR - Answer on Request : %s", (aor
) ? "Yes":"No");
787 PrintAndLog(" OTP - One Time Pad : %s", (otp
) ? "Yes - Warning":"No" );
788 PrintAndLog(" Max block : %d", maxblk
);
789 PrintAndLog(" Password mode : %s", (pwd
) ? "Yes":"No");
790 PrintAndLog(" Sequence Start Terminator : %s", (sst
) ? "Yes":"No");
791 PrintAndLog(" Fast Write : %s", (fw
) ? "Yes":"No");
792 PrintAndLog(" Inverse data : %s", (inv
) ? "Yes":"No");
793 PrintAndLog(" POR-Delay : %s", (por
) ? "Yes":"No");
794 PrintAndLog("-------------------------------------------------------------");
795 PrintAndLog(" Raw Data - Page 0");
796 PrintAndLog(" Block 0 : 0x%08X %s", bl0
, sprint_bin(DemodBuffer
+config
.offset
,32) );
797 PrintAndLog("-------------------------------------------------------------");
802 int CmdT55xxDump(const char *Cmd
){
805 uint8_t pwd
[4] = {0x00};
807 char cmdp
= param_getchar(Cmd
, 0);
808 if ( cmdp
== 'h' || cmdp
== 'H') {
813 bool hasPwd
= ( strlen(Cmd
) > 0);
815 if (param_gethex(Cmd
, 0, pwd
, 8)) {
816 PrintAndLog("password must include 8 HEX symbols");
821 for ( int i
= 0; i
<8; ++i
){
822 memset(s
,0,sizeof(s
));
824 sprintf(s
,"%d %02x%02x%02x%02x", i
, pwd
[0],pwd
[1],pwd
[2],pwd
[3]);
828 CmdT55xxReadBlock(s
);
833 int AquireData( uint8_t block
){
837 if ( block
== CONFIGURATION_BLOCK
)
838 c
.cmd
= CMD_T55XX_READ_BLOCK
;
839 else if (block
== TRACE_BLOCK
)
840 c
.cmd
= CMD_T55XX_READ_TRACE
;
845 c
.d
.asBytes
[0] = 0x0;
849 // c.arg[2] = password;
850 // c.d.asBytes[0] = 0x1;
854 if ( !WaitForResponseTimeout(CMD_ACK
,NULL
,2500) ) {
855 PrintAndLog("command execution time out");
860 GetFromBigBuf(got
,sizeof(got
),0);
861 WaitForResponse(CMD_ACK
,NULL
);
862 setGraphBuf(got
, 12000);
866 char * GetBitRateStr(uint32_t id
){
871 snprintf(retStr
,sizeof(buf
),"%d - RF/8",id
);
874 snprintf(retStr
,sizeof(buf
),"%d - RF/16",id
);
877 snprintf(retStr
,sizeof(buf
),"%d - RF/32",id
);
880 snprintf(retStr
,sizeof(buf
),"%d - RF/40",id
);
883 snprintf(retStr
,sizeof(buf
),"%d - RF/50",id
);
886 snprintf(retStr
,sizeof(buf
),"%d - RF/64",id
);
889 snprintf(retStr
,sizeof(buf
),"%d - RF/100",id
);
892 snprintf(retStr
,sizeof(buf
),"%d - RF/128",id
);
895 snprintf(retStr
,sizeof(buf
),"%d - (Unknown)",id
);
902 char * GetSaferStr(uint32_t id
){
906 snprintf(retStr
,sizeof(buf
),"%d",id
);
908 snprintf(retStr
,sizeof(buf
),"%d - passwd",id
);
911 snprintf(retStr
,sizeof(buf
),"%d - testmode",id
);
917 char * GetModulationStr( uint32_t id
){
923 snprintf(retStr
,sizeof(buf
),"%d - DIRECT (ASK/NRZ)",id
);
926 snprintf(retStr
,sizeof(buf
),"%d - PSK 1 phase change when input changes",id
);
929 snprintf(retStr
,sizeof(buf
),"%d - PSK 2 phase change on bitclk if input high",id
);
932 snprintf(retStr
,sizeof(buf
),"%d - PSK 3 phase change on rising edge of input",id
);
935 snprintf(retStr
,sizeof(buf
),"%d - FSK 1 RF/8 RF/5",id
);
938 snprintf(retStr
,sizeof(buf
),"%d - FSK 2 RF/8 RF/10",id
);
941 snprintf(retStr
,sizeof(buf
),"%d - FSK 1a RF/5 RF/8",id
);
944 snprintf(retStr
,sizeof(buf
),"%d - FSK 2a RF/10 RF/8",id
);
947 snprintf(retStr
,sizeof(buf
),"%d - Manschester",id
);
950 snprintf(retStr
,sizeof(buf
),"%d - Biphase",id
);
953 snprintf(retStr
,sizeof(buf
),"%d - Biphase a - AKA Conditional Dephase Encoding(CDP)",id
);
956 snprintf(retStr
,sizeof(buf
),"%d - Reserved",id
);
959 snprintf(retStr
,sizeof(buf
),"0x%02X (Unknown)",id
);
965 char * GetModelStrFromCID(uint32_t cid
){
970 if (cid
== 1) sprintf(retStr
,"ATA5577M1");
971 if (cid
== 2) sprintf(retStr
,"ATA5577M2");
975 char * GetSelectedModulationStr( uint8_t id
){
982 snprintf(retStr
,sizeof(buf
),"FSK");
985 snprintf(retStr
,sizeof(buf
),"FSK1");
988 snprintf(retStr
,sizeof(buf
),"FSK1a");
991 snprintf(retStr
,sizeof(buf
),"FSK2");
994 snprintf(retStr
,sizeof(buf
),"FSK2a");
997 snprintf(retStr
,sizeof(buf
),"ASK");
1000 snprintf(retStr
,sizeof(buf
),"DIRECT/NRZ");
1003 snprintf(retStr
,sizeof(buf
),"PSK1");
1006 snprintf(retStr
,sizeof(buf
),"PSK2");
1009 snprintf(retStr
,sizeof(buf
),"PSK3");
1012 snprintf(retStr
,sizeof(buf
),"BIPHASE");
1015 snprintf(retStr
,sizeof(buf
),"BIPHASEa - (CDP)");
1018 snprintf(retStr
,sizeof(buf
),"(Unknown)");
1024 uint32_t PackBits(uint8_t start
, uint8_t len
, uint8_t* bits
){
1029 if (len
> 32) return 0;
1032 for (; j
>= 0; --j
, ++i
)
1033 tmp
|= bits
[i
] << j
;
1038 static command_t CommandTable
[] =
1040 {"help", CmdHelp
, 1, "This help"},
1041 {"config", CmdT55xxSetConfig
, 1, "Set/Get T55XX configuration (modulation, inverted, offset, rate)"},
1042 {"detect", CmdT55xxDetect
, 0, "[1] Try detecting the tag modulation from reading the configuration block."},
1043 {"read", CmdT55xxReadBlock
, 0, "<block> [password] -- Read T55xx block data (page 0) [optional password]"},
1044 {"write", CmdT55xxWriteBlock
,0, "<block> <data> [password] -- Write T55xx block data (page 0) [optional password]"},
1045 {"trace", CmdT55xxReadTrace
, 0, "[1] Show T55xx traceability data (page 1/ blk 0-1)"},
1046 {"info", CmdT55xxInfo
, 0, "[1] Show T55xx configuration data (page 0/ blk 0)"},
1047 {"dump", CmdT55xxDump
, 0, "[password] Dump T55xx card block 0-7. [optional password]"},
1048 {"special", special
, 0, "Show block changes with 64 different offsets"},
1049 {NULL
, NULL
, 0, NULL
}
1052 int CmdLFT55XX(const char *Cmd
)
1054 CmdsParse(CommandTable
, Cmd
);
1058 int CmdHelp(const char *Cmd
)
1060 CmdsHelp(CommandTable
);