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));
540 void printConfiguration( t55xx_conf_block_t b
){
541 PrintAndLog("Modulation : %s", GetSelectedModulationStr(b
.modulation
) );
542 PrintAndLog("Inverted : %s", (b
.inverted
) ? "Yes" : "No" );
543 PrintAndLog("Offset : %d", b
.offset
);
544 PrintAndLog("Block0 : 0x%08X", b
.block0
);
548 int CmdT55xxWriteBlock(const char *Cmd
)
550 int block
= 8; //default to invalid block
551 int data
= 0xFFFFFFFF; //default to blank Block
552 int password
= 0xFFFFFFFF; //default to blank Block 7
554 char cmdp
= param_getchar(Cmd
, 0);
555 if (cmdp
== 'h' || cmdp
== 'H') {
560 int res
= sscanf(Cmd
, "%d %x %x",&block
, &data
, &password
);
562 if ( res
< 2 || res
> 3) {
568 PrintAndLog("Block number must be between 0 and 7");
572 UsbCommand c
= {CMD_T55XX_WRITE_BLOCK
, {data
, block
, 0}};
573 c
.d
.asBytes
[0] = 0x0;
575 PrintAndLog("Writing to block: %d data: 0x%08X", block
, data
);
580 c
.d
.asBytes
[0] = 0x1;
581 PrintAndLog("pwd : 0x%08X", password
);
587 int CmdT55xxReadTrace(const char *Cmd
)
589 char cmdp
= param_getchar(Cmd
, 0);
591 if (strlen(Cmd
) > 1 || cmdp
== 'h' || cmdp
== 'H')
592 return usage_t55xx_trace();
595 AquireData( TRACE_BLOCK
);
599 if (!DemodBufferLen
) return 1;
601 RepaintGraphWindow();
603 if (config
.offset
> 5)
605 uint8_t si
= config
.offset
+repeat
;
606 uint32_t bl0
= PackBits(si
, 32, DemodBuffer
);
607 uint32_t bl1
= PackBits(si
+32, 32, DemodBuffer
);
609 uint32_t acl
= PackBits(si
, 8, DemodBuffer
); si
+= 8;
610 uint32_t mfc
= PackBits(si
, 8, DemodBuffer
); si
+= 8;
611 uint32_t cid
= PackBits(si
, 5, DemodBuffer
); si
+= 5;
612 uint32_t icr
= PackBits(si
, 3, DemodBuffer
); si
+= 3;
613 uint32_t year
= PackBits(si
, 4, DemodBuffer
); si
+= 4;
614 uint32_t quarter
= PackBits(si
, 2, DemodBuffer
); si
+= 2;
615 uint32_t lotid
= PackBits(si
, 12, DemodBuffer
); si
+= 12;
616 uint32_t wafer
= PackBits(si
, 5, DemodBuffer
); si
+= 5;
617 uint32_t dw
= PackBits(si
, 15, DemodBuffer
);
622 PrintAndLog("-- T55xx Trace Information ----------------------------------");
623 PrintAndLog("-------------------------------------------------------------");
624 PrintAndLog(" ACL Allocation class (ISO/IEC 15963-1) : 0x%02X (%d)", acl
, acl
);
625 PrintAndLog(" MFC Manufacturer ID (ISO/IEC 7816-6) : 0x%02X (%d) - %s", mfc
, mfc
, getTagInfo(mfc
));
626 PrintAndLog(" CID : 0x%02X (%d) - %s", cid
, cid
, GetModelStrFromCID(cid
));
627 PrintAndLog(" ICR IC Revision : %d",icr
);
628 PrintAndLog(" Manufactured");
629 PrintAndLog(" Year/Quarter : %d/%d",year
, quarter
);
630 PrintAndLog(" Lot ID : %d", lotid
);
631 PrintAndLog(" Wafer number : %d", wafer
);
632 PrintAndLog(" Die Number : %d", dw
);
633 PrintAndLog("-------------------------------------------------------------");
634 PrintAndLog(" Raw Data - Page 1");
635 PrintAndLog(" Block 0 : 0x%08X %s", bl0
, sprint_bin(DemodBuffer
+config
.offset
+repeat
,32) );
636 PrintAndLog(" Block 1 : 0x%08X %s", bl1
, sprint_bin(DemodBuffer
+config
.offset
+repeat
+32,32) );
637 PrintAndLog("-------------------------------------------------------------");
640 PrintAndLog("The modulation is most likely wrong since the ACL is not 0xE0. ");
644 1-8 ACL Allocation class (ISO/IEC 15963-1) 0xE0
645 9-16 MFC Manufacturer ID (ISO/IEC 7816-6) 0x15 Atmel Corporation
646 17-21 CID 0x1 = Atmel ATA5577M1 0x2 = Atmel ATA5577M2
647 22-24 ICR IC revision
648 25-28 YEAR (BCD encoded) 9 (= 2009)
649 29-30 QUARTER 1,2,3,4
655 18-32 DW, die number sequential
661 int CmdT55xxInfo(const char *Cmd
){
663 Page 0 Block 0 Configuration data.
667 char cmdp
= param_getchar(Cmd
, 0);
669 if (strlen(Cmd
) > 1 || cmdp
== 'h' || cmdp
== 'H')
670 return usage_t55xx_info();
673 AquireData( CONFIGURATION_BLOCK
);
677 if (!DemodBufferLen
) return 1;
679 uint8_t si
= config
.offset
;
680 uint32_t bl0
= PackBits(si
, 32, DemodBuffer
);
682 uint32_t safer
= PackBits(si
, 4, DemodBuffer
); si
+= 4;
683 uint32_t resv
= PackBits(si
, 7, DemodBuffer
); si
+= 7;
684 uint32_t dbr
= PackBits(si
, 3, DemodBuffer
); si
+= 3;
685 uint32_t extend
= PackBits(si
, 1, DemodBuffer
); si
+= 1;
686 uint32_t datamod
= PackBits(si
, 5, DemodBuffer
); si
+= 5;
687 uint32_t pskcf
= PackBits(si
, 2, DemodBuffer
); si
+= 2;
688 uint32_t aor
= PackBits(si
, 1, DemodBuffer
); si
+= 1;
689 uint32_t otp
= PackBits(si
, 1, DemodBuffer
); si
+= 1;
690 uint32_t maxblk
= PackBits(si
, 3, DemodBuffer
); si
+= 3;
691 uint32_t pwd
= PackBits(si
, 1, DemodBuffer
); si
+= 1;
692 uint32_t sst
= PackBits(si
, 1, DemodBuffer
); si
+= 1;
693 uint32_t fw
= PackBits(si
, 1, DemodBuffer
); si
+= 1;
694 uint32_t inv
= PackBits(si
, 1, DemodBuffer
); si
+= 1;
695 uint32_t por
= PackBits(si
, 1, DemodBuffer
); si
+= 1;
698 PrintAndLog("-- T55xx Configuration & Tag Information --------------------");
699 PrintAndLog("-------------------------------------------------------------");
700 PrintAndLog(" Safer key : %s", GetSaferStr(safer
));
701 PrintAndLog(" reserved : %d", resv
);
702 PrintAndLog(" Data bit rate : %s", GetBitRateStr(dbr
));
703 PrintAndLog(" eXtended mode : %s", (extend
) ? "Yes - Warning":"No");
704 PrintAndLog(" Modulation : %s", GetModulationStr(datamod
));
705 PrintAndLog(" PSK clock frequency : %d", pskcf
);
706 PrintAndLog(" AOR - Answer on Request : %s", (aor
) ? "Yes":"No");
707 PrintAndLog(" OTP - One Time Pad : %s", (otp
) ? "Yes - Warning":"No" );
708 PrintAndLog(" Max block : %d", maxblk
);
709 PrintAndLog(" Password mode : %s", (pwd
) ? "Yes":"No");
710 PrintAndLog(" Sequence Start Terminator : %s", (sst
) ? "Yes":"No");
711 PrintAndLog(" Fast Write : %s", (fw
) ? "Yes":"No");
712 PrintAndLog(" Inverse data : %s", (inv
) ? "Yes":"No");
713 PrintAndLog(" POR-Delay : %s", (por
) ? "Yes":"No");
714 PrintAndLog("-------------------------------------------------------------");
715 PrintAndLog(" Raw Data - Page 0");
716 PrintAndLog(" Block 0 : 0x%08X %s", bl0
, sprint_bin(DemodBuffer
+config
.offset
,32) );
717 PrintAndLog("-------------------------------------------------------------");
721 int CmdT55xxDump(const char *Cmd
){
724 uint8_t pwd
[4] = {0x00};
726 char cmdp
= param_getchar(Cmd
, 0);
727 if ( cmdp
== 'h' || cmdp
== 'H') {
732 bool hasPwd
= ( strlen(Cmd
) > 0);
734 if (param_gethex(Cmd
, 0, pwd
, 8)) {
735 PrintAndLog("password must include 8 HEX symbols");
740 for ( int i
= 0; i
<8; ++i
){
741 memset(s
,0,sizeof(s
));
743 sprintf(s
,"%d %02x%02x%02x%02x", i
, pwd
[0],pwd
[1],pwd
[2],pwd
[3]);
747 CmdT55xxReadBlock(s
);
752 int AquireData( uint8_t block
){
756 if ( block
== CONFIGURATION_BLOCK
)
757 c
.cmd
= CMD_T55XX_READ_BLOCK
;
758 else if (block
== TRACE_BLOCK
)
759 c
.cmd
= CMD_T55XX_READ_TRACE
;
764 c
.d
.asBytes
[0] = 0x0;
768 // c.arg[2] = password;
769 // c.d.asBytes[0] = 0x1;
773 if ( !WaitForResponseTimeout(CMD_ACK
,NULL
,2500) ) {
774 PrintAndLog("command execution time out");
779 GetFromBigBuf(got
,sizeof(got
),0);
780 WaitForResponse(CMD_ACK
,NULL
);
781 setGraphBuf(got
, 12000);
785 char * GetBitRateStr(uint32_t id
){
790 sprintf(retStr
,"%d - RF/8",id
);
793 sprintf(retStr
,"%d - RF/16",id
);
796 sprintf(retStr
,"%d - RF/32",id
);
799 sprintf(retStr
,"%d - RF/40",id
);
802 sprintf(retStr
,"%d - RF/50",id
);
805 sprintf(retStr
,"%d - RF/64",id
);
808 sprintf(retStr
,"%d - RF/100",id
);
811 sprintf(retStr
,"%d - RF/128",id
);
814 sprintf(retStr
,"%d - (Unknown)",id
);
821 char * GetSaferStr(uint32_t id
){
825 sprintf(retStr
,"%d",id
);
827 sprintf(retStr
,"%d - passwd",id
);
830 sprintf(retStr
,"%d - testmode",id
);
835 char * GetModulationStr( uint32_t id
){
841 sprintf(retStr
,"%d - DIRECT (ASK/NRZ)",id
);
844 sprintf(retStr
,"%d - PSK 1 phase change when input changes",id
);
847 sprintf(retStr
,"%d - PSK 2 phase change on bitclk if input high",id
);
850 sprintf(retStr
,"%d - PSK 3 phase change on rising edge of input",id
);
853 sprintf(retStr
,"%d - FSK 1 RF/8 RF/5",id
);
856 sprintf(retStr
,"%d - FSK 2 RF/8 RF/10",id
);
859 sprintf(retStr
,"%d - FSK 1a RF/5 RF/8",id
);
862 sprintf(retStr
,"%d - FSK 2a RF/10 RF/8",id
);
865 sprintf(retStr
,"%d - Manschester",id
);
868 sprintf(retStr
,"%d - Biphase",id
);
871 sprintf(retStr
,"%d - Reserved",id
);
874 sprintf(retStr
,"0x%02X (Unknown)",id
);
880 char * GetModelStrFromCID(uint32_t cid
){
885 if (cid
== 1) sprintf(retStr
,"ATA5577M1");
886 if (cid
== 2) sprintf(retStr
,"ATA5577M2");
890 char * GetSelectedModulationStr( uint8_t id
){
897 sprintf(retStr
,"FSK");
900 sprintf(retStr
,"ASK");
903 sprintf(retStr
,"DIRECT/NRZ");
906 sprintf(retStr
,"PSK1");
909 sprintf(retStr
,"PSK2");
912 sprintf(retStr
,"PSK3");
915 sprintf(retStr
,"BIPHASE");
918 sprintf(retStr
,"(Unknown)");
924 uint32_t PackBits(uint8_t start
, uint8_t len
, uint8_t* bits
){
929 if (len
> 32) return 0;
932 for (; j
>= 0; --j
, ++i
)
938 static command_t CommandTable
[] =
940 {"help", CmdHelp
, 1, "This help"},
941 {"config", CmdT55xxSetConfig
, 1, "Set/Get T55XX configuration (modulation, inverted, offset)"},
942 {"detect", CmdT55xxDetect
, 0, "[1] Try detecting the tag modulation from reading the configuration block."},
943 {"read", CmdT55xxReadBlock
, 0, "<block> [password] -- Read T55xx block data (page 0) [optional password]"},
944 {"write", CmdT55xxWriteBlock
,0, "<block> <data> [password] -- Write T55xx block data (page 0) [optional password]"},
945 {"trace", CmdT55xxReadTrace
, 0, "[1] Show T55xx traceability data (page 1/ blk 0-1)"},
946 {"info", CmdT55xxInfo
, 0, "[1] Show T55xx configuration data (page 0/ blk 0)"},
947 {"dump", CmdT55xxDump
, 0, "[password] Dump T55xx card block 0-7. [optional password]"},
948 {"special", special
, 0, "Show block changes with 64 different offsets"},
949 {NULL
, NULL
, 0, NULL
}
952 int CmdLFT55XX(const char *Cmd
)
954 CmdsParse(CommandTable
, Cmd
);
958 int CmdHelp(const char *Cmd
)
960 CmdsHelp(CommandTable
);