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 //-----------------------------------------------------------------------------
9 #include "cmdlft55xx.h"
11 // Default configuration
12 t55xx_conf_block_t config
= { .modulation
= DEMOD_ASK
, .inverted
= FALSE
, .offset
= 0x00, .block0
= 0x00, .Q5
= FALSE
};
14 t55xx_conf_block_t
Get_t55xx_Config(){
17 void Set_t55xx_Config(t55xx_conf_block_t conf
){
21 int usage_t55xx_config(){
22 PrintAndLog("Usage: lf t55xx config [d <demodulation>] [i 1] [o <offset>] [Q5]");
23 PrintAndLog("Options:");
24 PrintAndLog(" h - This help");
25 PrintAndLog(" b <8|16|32|40|50|64|100|128> - Set bitrate");
26 PrintAndLog(" d <FSK|FSK1|FSK1a|FSK2|FSK2a|ASK|PSK1|PSK2|NRZ|BI|BIa> - Set demodulation FSK / ASK / PSK / NRZ / Biphase / Biphase A");
27 PrintAndLog(" i [1] - Invert data signal, defaults to normal");
28 PrintAndLog(" o [offset] - Set offset, where data should start decode in bitstream");
29 PrintAndLog(" Q5 - Set as Q5(T5555) chip instead of T55x7");
30 PrintAndLog(" ST - Set Sequence Terminator on");
32 PrintAndLog("Examples:");
33 PrintAndLog(" lf t55xx config d FSK - FSK demodulation");
34 PrintAndLog(" lf t55xx config d FSK i 1 - FSK demodulation, inverse data");
35 PrintAndLog(" lf t55xx config d FSK i 1 o 3 - FSK demodulation, inverse data, offset=3,start from position 3 to decode data");
39 int usage_t55xx_read(){
40 PrintAndLog("Usage: lf t55xx read [b <block>] [p <password>] <override_safety> <page1>");
41 PrintAndLog("Options:");
42 PrintAndLog(" b <block> - block number to read. Between 0-7");
43 PrintAndLog(" p <password> - OPTIONAL password (8 hex characters)");
44 PrintAndLog(" o - OPTIONAL override safety check");
45 PrintAndLog(" 1 - OPTIONAL read Page 1 instead of Page 0");
46 PrintAndLog(" ****WARNING****");
47 PrintAndLog(" Use of read with password on a tag not configured for a pwd");
48 PrintAndLog(" can damage the tag");
50 PrintAndLog("Examples:");
51 PrintAndLog(" lf t55xx read b 0 - read data from block 0");
52 PrintAndLog(" lf t55xx read b 0 p feedbeef - read data from block 0 password feedbeef");
53 PrintAndLog(" lf t55xx read b 0 p feedbeef o - read data from block 0 password feedbeef safety check");
57 int usage_t55xx_write(){
58 PrintAndLog("Usage: lf t55xx wr [b <block>] [d <data>] [p <password>] [1]");
59 PrintAndLog("Options:");
60 PrintAndLog(" b <block> - block number to write. Between 0-7");
61 PrintAndLog(" d <data> - 4 bytes of data to write (8 hex characters)");
62 PrintAndLog(" p <password> - OPTIONAL password 4bytes (8 hex characters)");
63 PrintAndLog(" 1 - OPTIONAL write Page 1 instead of Page 0");
65 PrintAndLog("Examples:");
66 PrintAndLog(" lf t55xx write b 3 d 11223344 - write 11223344 to block 3");
67 PrintAndLog(" lf t55xx write b 3 d 11223344 p feedbeef - write 11223344 to block 3 password feedbeef");
71 int usage_t55xx_trace() {
72 PrintAndLog("Usage: lf t55xx trace [1]");
73 PrintAndLog("Options:");
74 PrintAndLog(" 1 - 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("Options:");
85 PrintAndLog(" 1 - 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> [o]");
95 PrintAndLog("Options:");
96 PrintAndLog(" <password> - OPTIONAL password 4bytes (8 hex symbols)");
97 PrintAndLog(" o - OPTIONAL override, force pwd read despite danger to card");
99 PrintAndLog("Examples:");
100 PrintAndLog(" lf t55xx dump");
101 PrintAndLog(" lf t55xx dump feedbeef o");
105 int usage_t55xx_detect(){
106 PrintAndLog("Usage: lf t55xx detect [1] [p <password>]");
107 PrintAndLog("Options:");
108 PrintAndLog(" 1 - if set, use Graphbuffer otherwise read data from tag.");
109 PrintAndLog(" p <password> - OPTIONAL password (8 hex characters)");
111 PrintAndLog("Examples:");
112 PrintAndLog(" lf t55xx detect");
113 PrintAndLog(" lf t55xx detect 1");
114 PrintAndLog(" lf t55xx detect p 11223344");
118 int usage_t55xx_wakup(){
119 PrintAndLog("Usage: lf t55xx wakeup [h] p <password>");
120 PrintAndLog("This commands send the Answer-On-Request command and leaves the readerfield ON afterwards.");
121 PrintAndLog("Options:");
122 PrintAndLog(" h - this help");
123 PrintAndLog(" p <password> - password 4bytes (8 hex symbols)");
125 PrintAndLog("Examples:");
126 PrintAndLog(" lf t55xx wakeup p 11223344 - send wakeup password");
129 int usage_t55xx_bruteforce(){
130 PrintAndLog("This command uses A) bruteforce to scan a number range");
131 PrintAndLog(" B) a dictionary attack");
132 PrintAndLog("press 'enter' to cancel the command");
133 PrintAndLog("Usage: lf t55xx bruteforce [h] <start password> <end password> [i <*.dic>]");
134 PrintAndLog(" password must be 4 bytes (8 hex symbols)");
135 PrintAndLog("Options:");
136 PrintAndLog(" h - this help");
137 PrintAndLog(" <start_pwd> - 4 byte hex value to start pwd search at");
138 PrintAndLog(" <end_pwd> - 4 byte hex value to end pwd search at");
139 PrintAndLog(" i <*.dic> - loads a default keys dictionary file <*.dic>");
141 PrintAndLog("Examples:");
142 PrintAndLog(" lf t55xx bruteforce aaaaaaaa bbbbbbbb");
143 PrintAndLog(" lf t55xx bruteforce i default_pwd.dic");
147 int usage_t55xx_recoverpw(){
148 PrintAndLog("This command uses a few tricks to try to recover mangled password");
149 PrintAndLog("press 'enter' to cancel the command");
150 PrintAndLog("WARNING: this may brick non-password protected chips!");
151 PrintAndLog("Usage: lf t55xx recoverpw [password]");
152 PrintAndLog(" password must be 4 bytes (8 hex symbols)");
153 PrintAndLog(" default password is 51243648, used by many cloners");
154 PrintAndLog("Options:");
155 PrintAndLog(" h - this help");
156 PrintAndLog(" [password] - 4 byte hex value of password written by cloner");
158 PrintAndLog("Examples:");
159 PrintAndLog(" lf t55xx recoverpw");
160 PrintAndLog(" lf t55xx recoverpw 51243648");
163 }int usage_t55xx_wipe(){
164 PrintAndLog("Usage: lf t55xx wipe [h] [Q5]");
165 PrintAndLog("This commands wipes a tag, fills blocks 1-7 with zeros and a default configuration block");
166 PrintAndLog("Options:");
167 PrintAndLog(" h - this help");
168 PrintAndLog(" Q5 - indicates to use the T5555 (Q5) default configuration block");
170 PrintAndLog("Examples:");
171 PrintAndLog(" lf t55xx wipe - wipes a t55x7 tag, config block 0x000880E0");
172 PrintAndLog(" lf t55xx wipe Q5 - wipes a t5555 Q5 tag, config block 0x6001F004");
175 static int CmdHelp(const char *Cmd
);
177 void printT5xxHeader(uint8_t page
){
178 PrintAndLog("Reading Page %d:", page
);
179 PrintAndLog("blk | hex data | binary | ascii");
180 PrintAndLog("----+----------+----------------------------------+-------");
183 int CmdT55xxSetConfig(const char *Cmd
) {
186 char modulation
[5] = {0x00};
189 uint8_t rates
[9] = {8,16,32,40,50,64,100,128,0};
192 while(param_getchar(Cmd
, cmdp
) != 0x00 && !errors
)
194 tmp
= param_getchar(Cmd
, cmdp
);
199 return usage_t55xx_config();
201 errors
|= param_getdec(Cmd
, cmdp
+1, &bitRate
);
205 if (rates
[i
]==bitRate
) {
210 if (i
==9) errors
= TRUE
;
215 param_getstr(Cmd
, cmdp
+1, modulation
);
218 if ( strcmp(modulation
, "FSK" ) == 0) {
219 config
.modulation
= DEMOD_FSK
;
220 } else if ( strcmp(modulation
, "FSK1" ) == 0) {
221 config
.modulation
= DEMOD_FSK1
;
223 } else if ( strcmp(modulation
, "FSK1a" ) == 0) {
224 config
.modulation
= DEMOD_FSK1a
;
226 } else if ( strcmp(modulation
, "FSK2" ) == 0) {
227 config
.modulation
= DEMOD_FSK2
;
229 } else if ( strcmp(modulation
, "FSK2a" ) == 0) {
230 config
.modulation
= DEMOD_FSK2a
;
232 } else if ( strcmp(modulation
, "ASK" ) == 0) {
233 config
.modulation
= DEMOD_ASK
;
234 } else if ( strcmp(modulation
, "NRZ" ) == 0) {
235 config
.modulation
= DEMOD_NRZ
;
236 } else if ( strcmp(modulation
, "PSK1" ) == 0) {
237 config
.modulation
= DEMOD_PSK1
;
238 } else if ( strcmp(modulation
, "PSK2" ) == 0) {
239 config
.modulation
= DEMOD_PSK2
;
240 } else if ( strcmp(modulation
, "PSK3" ) == 0) {
241 config
.modulation
= DEMOD_PSK3
;
242 } else if ( strcmp(modulation
, "BIa" ) == 0) {
243 config
.modulation
= DEMOD_BIa
;
245 } else if ( strcmp(modulation
, "BI" ) == 0) {
246 config
.modulation
= DEMOD_BI
;
249 PrintAndLog("Unknown modulation '%s'", modulation
);
254 config
.inverted
= param_getchar(Cmd
,cmdp
+1) == '1';
258 errors
|= param_getdec(Cmd
, cmdp
+1, &offset
);
260 config
.offset
= offset
;
274 PrintAndLog("Unknown parameter '%c'", param_getchar(Cmd
, cmdp
));
281 if (cmdp
== 0) return printConfiguration( config
);
284 if (errors
) return usage_t55xx_config();
287 return printConfiguration ( config
);
290 int T55xxReadBlock(uint8_t block
, bool page1
, bool usepwd
, bool override
, uint32_t password
){
293 // try reading the config block and verify that PWD bit is set before doing this!
296 if ( !AquireData(T55x7_PAGE0
, T55x7_CONFIGURATION_BLOCK
, false, 0 ) ) return 0;
298 if ( !tryDetectModulation() ) {
299 PrintAndLog("Safety Check: Could not detect if PWD bit is set in config block. Exits.");
302 PrintAndLog("Safety Check: PWD bit is NOT set in config block. Reading without password...");
307 PrintAndLog("Safety Check Overriden - proceeding despite risk");
311 if (!AquireData(page1
, block
, usepwd
, password
) ) return 0;
312 if (!DecodeT55xxBlock()) return 0;
315 sprintf(blk
,"%02d", block
);
316 printT55xxBlock(blk
);
320 int CmdT55xxReadBlock(const char *Cmd
) {
321 uint8_t block
= REGULAR_READ_MODE_BLOCK
;
322 uint32_t password
= 0; //default to blank Block 7
324 bool override
= false;
328 while(param_getchar(Cmd
, cmdp
) != 0x00 && !errors
) {
329 switch(param_getchar(Cmd
, cmdp
)) {
332 return usage_t55xx_read();
335 errors
|= param_getdec(Cmd
, cmdp
+1, &block
);
345 password
= param_get32ex(Cmd
, cmdp
+1, 0, 16);
354 PrintAndLog("Unknown parameter '%c'", param_getchar(Cmd
, cmdp
));
359 if (errors
) return usage_t55xx_read();
361 if (block
> 7 && block
!= REGULAR_READ_MODE_BLOCK
) {
362 PrintAndLog("Block must be between 0 and 7");
366 printT5xxHeader(page1
);
367 return T55xxReadBlock(block
, page1
, usepwd
, override
, password
);
370 bool DecodeT55xxBlock(){
372 char buf
[30] = {0x00};
376 uint8_t bitRate
[8] = {8,16,32,40,50,64,100,128};
377 DemodBufferLen
= 0x00;
379 switch( config
.modulation
){
381 snprintf(cmdStr
, sizeof(buf
),"%d %d", bitRate
[config
.bitrate
], config
.inverted
);
382 ans
= FSKrawDemod(cmdStr
, FALSE
);
386 snprintf(cmdStr
, sizeof(buf
),"%d %d 8 5", bitRate
[config
.bitrate
], config
.inverted
);
387 ans
= FSKrawDemod(cmdStr
, FALSE
);
391 snprintf(cmdStr
, sizeof(buf
),"%d %d 10 8", bitRate
[config
.bitrate
], config
.inverted
);
392 ans
= FSKrawDemod(cmdStr
, FALSE
);
395 snprintf(cmdStr
, sizeof(buf
),"%d %d 1", bitRate
[config
.bitrate
], config
.inverted
);
396 ans
= ASKDemod_ext(cmdStr
, FALSE
, FALSE
, 1, &ST
);
399 // skip first 160 samples to allow antenna to settle in (psk gets inverted occasionally otherwise)
402 snprintf(cmdStr
, sizeof(buf
),"%d %d 6", bitRate
[config
.bitrate
], config
.inverted
);
403 ans
= PSKDemod(cmdStr
, FALSE
);
407 case DEMOD_PSK2
: //inverted won't affect this
408 case DEMOD_PSK3
: //not fully implemented
409 // skip first 160 samples to allow antenna to settle in (psk gets inverted occasionally otherwise)
412 snprintf(cmdStr
, sizeof(buf
),"%d 0 6", bitRate
[config
.bitrate
] );
413 ans
= PSKDemod(cmdStr
, FALSE
);
414 psk1TOpsk2(DemodBuffer
, DemodBufferLen
);
419 snprintf(cmdStr
, sizeof(buf
),"%d %d 1", bitRate
[config
.bitrate
], config
.inverted
);
420 ans
= NRZrawDemod(cmdStr
, FALSE
);
424 snprintf(cmdStr
, sizeof(buf
),"0 %d %d 1", bitRate
[config
.bitrate
], config
.inverted
);
425 ans
= ASKbiphaseDemod(cmdStr
, FALSE
);
433 bool DecodeT5555TraceBlock() {
434 DemodBufferLen
= 0x00;
436 // According to datasheet. Always: RF/64, not inverted, Manchester
437 return (bool) ASKDemod("64 0 1", FALSE
, FALSE
, 1);
440 // sanity check. Don't use proxmark if it is offline and you didn't specify useGraphbuf
441 static int SanityOfflineCheck( bool useGraphBuffer
){
442 if ( !useGraphBuffer
&& offline
) {
443 PrintAndLog("Your proxmark3 device is offline. Specify [1] to use graphbuffer data instead");
449 int CmdT55xxDetect(const char *Cmd
){
453 uint32_t password
= 0;
456 while(param_getchar(Cmd
, cmdp
) != 0x00 && !errors
) {
457 switch(param_getchar(Cmd
, cmdp
)) {
460 return usage_t55xx_detect();
463 password
= param_get32ex(Cmd
, cmdp
+1, 0, 16);
468 // use Graphbuffer data
473 PrintAndLog("Unknown parameter '%c'", param_getchar(Cmd
, cmdp
));
478 if (errors
) return usage_t55xx_detect();
481 if (!SanityOfflineCheck(useGB
)) return 1;
484 if ( !AquireData(T55x7_PAGE0
, T55x7_CONFIGURATION_BLOCK
, usepwd
, password
) )
488 if ( !tryDetectModulation() )
489 PrintAndLog("Could not detect modulation automatically. Try setting it manually with \'lf t55xx config\'");
494 // detect configuration?
495 bool tryDetectModulation(){
497 t55xx_conf_block_t tests
[15];
499 uint8_t fc1
= 0, fc2
= 0, clk
=0;
501 if (GetFskClock("", FALSE
, FALSE
)){
502 fskClocks(&fc1
, &fc2
, &clk
, FALSE
);
503 if ( FSKrawDemod("0 0", FALSE
) && test(DEMOD_FSK
, &tests
[hits
].offset
, &bitRate
, clk
, &tests
[hits
].Q5
)){
504 tests
[hits
].modulation
= DEMOD_FSK
;
505 if (fc1
==8 && fc2
== 5)
506 tests
[hits
].modulation
= DEMOD_FSK1a
;
507 else if (fc1
==10 && fc2
== 8)
508 tests
[hits
].modulation
= DEMOD_FSK2
;
509 tests
[hits
].bitrate
= bitRate
;
510 tests
[hits
].inverted
= FALSE
;
511 tests
[hits
].block0
= PackBits(tests
[hits
].offset
, 32, DemodBuffer
);
512 tests
[hits
].ST
= FALSE
;
515 if ( FSKrawDemod("0 1", FALSE
) && test(DEMOD_FSK
, &tests
[hits
].offset
, &bitRate
, clk
, &tests
[hits
].Q5
)) {
516 tests
[hits
].modulation
= DEMOD_FSK
;
517 if (fc1
== 8 && fc2
== 5)
518 tests
[hits
].modulation
= DEMOD_FSK1
;
519 else if (fc1
== 10 && fc2
== 8)
520 tests
[hits
].modulation
= DEMOD_FSK2a
;
521 tests
[hits
].bitrate
= bitRate
;
522 tests
[hits
].inverted
= TRUE
;
523 tests
[hits
].block0
= PackBits(tests
[hits
].offset
, 32, DemodBuffer
);
524 tests
[hits
].ST
= FALSE
;
528 clk
= GetAskClock("", FALSE
, FALSE
);
530 tests
[hits
].ST
= TRUE
;
531 // "0 0 1 " == clock auto, invert false, maxError 1.
532 // false = no verbose
533 // false = no emSearch
536 if ( ASKDemod_ext("0 0 1", FALSE
, FALSE
, 1, &tests
[hits
].ST
) && test(DEMOD_ASK
, &tests
[hits
].offset
, &bitRate
, clk
, &tests
[hits
].Q5
)) {
537 tests
[hits
].modulation
= DEMOD_ASK
;
538 tests
[hits
].bitrate
= bitRate
;
539 tests
[hits
].inverted
= FALSE
;
540 tests
[hits
].block0
= PackBits(tests
[hits
].offset
, 32, DemodBuffer
);
543 tests
[hits
].ST
= TRUE
;
544 // "0 0 1 " == clock auto, invert true, maxError 1.
545 // false = no verbose
546 // false = no emSearch
549 if ( ASKDemod_ext("0 1 1", FALSE
, FALSE
, 1, &tests
[hits
].ST
) && test(DEMOD_ASK
, &tests
[hits
].offset
, &bitRate
, clk
, &tests
[hits
].Q5
)) {
550 tests
[hits
].modulation
= DEMOD_ASK
;
551 tests
[hits
].bitrate
= bitRate
;
552 tests
[hits
].inverted
= TRUE
;
553 tests
[hits
].block0
= PackBits(tests
[hits
].offset
, 32, DemodBuffer
);
556 if ( ASKbiphaseDemod("0 0 0 2", FALSE
) && test(DEMOD_BI
, &tests
[hits
].offset
, &bitRate
, clk
, &tests
[hits
].Q5
) ) {
557 tests
[hits
].modulation
= DEMOD_BI
;
558 tests
[hits
].bitrate
= bitRate
;
559 tests
[hits
].inverted
= FALSE
;
560 tests
[hits
].block0
= PackBits(tests
[hits
].offset
, 32, DemodBuffer
);
561 tests
[hits
].ST
= FALSE
;
564 if ( ASKbiphaseDemod("0 0 1 2", FALSE
) && test(DEMOD_BIa
, &tests
[hits
].offset
, &bitRate
, clk
, &tests
[hits
].Q5
) ) {
565 tests
[hits
].modulation
= DEMOD_BIa
;
566 tests
[hits
].bitrate
= bitRate
;
567 tests
[hits
].inverted
= TRUE
;
568 tests
[hits
].block0
= PackBits(tests
[hits
].offset
, 32, DemodBuffer
);
569 tests
[hits
].ST
= FALSE
;
575 clk
= GetNrzClock("", FALSE
, FALSE
);
577 if ( NRZrawDemod("0 0 1", FALSE
) && test(DEMOD_NRZ
, &tests
[hits
].offset
, &bitRate
, clk
, &tests
[hits
].Q5
)) {
578 tests
[hits
].modulation
= DEMOD_NRZ
;
579 tests
[hits
].bitrate
= bitRate
;
580 tests
[hits
].inverted
= FALSE
;
581 tests
[hits
].block0
= PackBits(tests
[hits
].offset
, 32, DemodBuffer
);
582 tests
[hits
].ST
= FALSE
;
586 if ( NRZrawDemod("0 1 1", FALSE
) && test(DEMOD_NRZ
, &tests
[hits
].offset
, &bitRate
, clk
, &tests
[hits
].Q5
)) {
587 tests
[hits
].modulation
= DEMOD_NRZ
;
588 tests
[hits
].bitrate
= bitRate
;
589 tests
[hits
].inverted
= TRUE
;
590 tests
[hits
].block0
= PackBits(tests
[hits
].offset
, 32, DemodBuffer
);
591 tests
[hits
].ST
= FALSE
;
597 // skip first 160 samples to allow antenna to settle in (psk gets inverted occasionally otherwise)
600 clk
= GetPskClock("", FALSE
, FALSE
);
602 if ( PSKDemod("0 0 6", FALSE
) && test(DEMOD_PSK1
, &tests
[hits
].offset
, &bitRate
, clk
, &tests
[hits
].Q5
)) {
603 tests
[hits
].modulation
= DEMOD_PSK1
;
604 tests
[hits
].bitrate
= bitRate
;
605 tests
[hits
].inverted
= FALSE
;
606 tests
[hits
].block0
= PackBits(tests
[hits
].offset
, 32, DemodBuffer
);
607 tests
[hits
].ST
= FALSE
;
610 if ( PSKDemod("0 1 6", FALSE
) && test(DEMOD_PSK1
, &tests
[hits
].offset
, &bitRate
, clk
, &tests
[hits
].Q5
)) {
611 tests
[hits
].modulation
= DEMOD_PSK1
;
612 tests
[hits
].bitrate
= bitRate
;
613 tests
[hits
].inverted
= TRUE
;
614 tests
[hits
].block0
= PackBits(tests
[hits
].offset
, 32, DemodBuffer
);
615 tests
[hits
].ST
= FALSE
;
618 //ICEMAN: are these PSKDemod calls needed?
619 // PSK2 - needs a call to psk1TOpsk2.
620 if ( PSKDemod("0 0 6", FALSE
)) {
621 psk1TOpsk2(DemodBuffer
, DemodBufferLen
);
622 if (test(DEMOD_PSK2
, &tests
[hits
].offset
, &bitRate
, clk
, &tests
[hits
].Q5
)){
623 tests
[hits
].modulation
= DEMOD_PSK2
;
624 tests
[hits
].bitrate
= bitRate
;
625 tests
[hits
].inverted
= FALSE
;
626 tests
[hits
].block0
= PackBits(tests
[hits
].offset
, 32, DemodBuffer
);
627 tests
[hits
].ST
= FALSE
;
630 } // inverse waves does not affect this demod
631 // PSK3 - needs a call to psk1TOpsk2.
632 if ( PSKDemod("0 0 6", FALSE
)) {
633 psk1TOpsk2(DemodBuffer
, DemodBufferLen
);
634 if (test(DEMOD_PSK3
, &tests
[hits
].offset
, &bitRate
, clk
, &tests
[hits
].Q5
)){
635 tests
[hits
].modulation
= DEMOD_PSK3
;
636 tests
[hits
].bitrate
= bitRate
;
637 tests
[hits
].inverted
= FALSE
;
638 tests
[hits
].block0
= PackBits(tests
[hits
].offset
, 32, DemodBuffer
);
639 tests
[hits
].ST
= FALSE
;
642 } // inverse waves does not affect this demod
648 config
.modulation
= tests
[0].modulation
;
649 config
.bitrate
= tests
[0].bitrate
;
650 config
.inverted
= tests
[0].inverted
;
651 config
.offset
= tests
[0].offset
;
652 config
.block0
= tests
[0].block0
;
653 config
.Q5
= tests
[0].Q5
;
654 config
.ST
= tests
[0].ST
;
655 printConfiguration( config
);
661 PrintAndLog("Found [%d] possible matches for modulation.",hits
);
662 for(int i
=0; i
<hits
; ++i
){
663 retval
= testKnownConfigBlock(tests
[i
].block0
);
665 PrintAndLog("--[%d]--------------- << selected this", i
+1);
666 config
.modulation
= tests
[i
].modulation
;
667 config
.bitrate
= tests
[i
].bitrate
;
668 config
.inverted
= tests
[i
].inverted
;
669 config
.offset
= tests
[i
].offset
;
670 config
.block0
= tests
[i
].block0
;
671 config
.Q5
= tests
[i
].Q5
;
672 config
.ST
= tests
[i
].ST
;
674 PrintAndLog("--[%d]---------------", i
+1);
676 printConfiguration( tests
[i
] );
682 bool testKnownConfigBlock(uint32_t block0
) {
684 case T55X7_DEFAULT_CONFIG_BLOCK
:
685 case T55X7_RAW_CONFIG_BLOCK
:
686 case T55X7_EM_UNIQUE_CONFIG_BLOCK
:
687 case T55X7_FDXB_CONFIG_BLOCK
:
688 case T55X7_HID_26_CONFIG_BLOCK
:
689 case T55X7_PYRAMID_CONFIG_BLOCK
:
690 case T55X7_INDALA_64_CONFIG_BLOCK
:
691 case T55X7_INDALA_224_CONFIG_BLOCK
:
692 case T55X7_GUARDPROXII_CONFIG_BLOCK
:
693 case T55X7_VIKING_CONFIG_BLOCK
:
694 case T55X7_NORALYS_CONFIG_BLOCK
:
695 case T55X7_IOPROX_CONFIG_BLOCK
:
696 case T55X7_PRESCO_CONFIG_BLOCK
:
702 bool testModulation(uint8_t mode
, uint8_t modread
){
705 if (modread
>= DEMOD_FSK1
&& modread
<= DEMOD_FSK2a
) return TRUE
;
708 if (modread
== DEMOD_ASK
) return TRUE
;
711 if (modread
== DEMOD_PSK1
) return TRUE
;
714 if (modread
== DEMOD_PSK2
) return TRUE
;
717 if (modread
== DEMOD_PSK3
) return TRUE
;
720 if (modread
== DEMOD_NRZ
) return TRUE
;
723 if (modread
== DEMOD_BI
) return TRUE
;
726 if (modread
== DEMOD_BIa
) return TRUE
;
734 bool testQ5Modulation(uint8_t mode
, uint8_t modread
){
737 if (modread
>= 4 && modread
<= 5) return TRUE
;
740 if (modread
== 0) return TRUE
;
743 if (modread
== 1) return TRUE
;
746 if (modread
== 2) return TRUE
;
749 if (modread
== 3) return TRUE
;
752 if (modread
== 7) return TRUE
;
755 if (modread
== 6) return TRUE
;
763 int convertQ5bitRate(uint8_t bitRateRead
) {
764 uint8_t expected
[] = {8, 16, 32, 40, 50, 64, 100, 128};
765 for (int i
=0; i
<8; i
++)
766 if (expected
[i
] == bitRateRead
)
772 bool testQ5(uint8_t mode
, uint8_t *offset
, int *fndBitRate
, uint8_t clk
){
774 if ( DemodBufferLen
< 64 ) return FALSE
;
776 for (uint8_t idx
= 28; idx
< 64; idx
++){
778 if ( PackBits(si
, 28, DemodBuffer
) == 0x00 ) continue;
780 uint8_t safer
= PackBits(si
, 4, DemodBuffer
); si
+= 4; //master key
781 uint8_t resv
= PackBits(si
, 8, DemodBuffer
); si
+= 8;
782 // 2nibble must be zeroed.
783 if (safer
!= 0x6 && safer
!= 0x9) continue;
784 if ( resv
> 0x00) continue;
785 //uint8_t pageSel = PackBits(si, 1, DemodBuffer); si += 1;
786 //uint8_t fastWrite = PackBits(si, 1, DemodBuffer); si += 1;
788 int bitRate
= PackBits(si
, 6, DemodBuffer
)*2 + 2; si
+= 6; //bit rate
789 if (bitRate
> 128 || bitRate
< 8) continue;
791 //uint8_t AOR = PackBits(si, 1, DemodBuffer); si += 1;
792 //uint8_t PWD = PackBits(si, 1, DemodBuffer); si += 1;
793 //uint8_t pskcr = PackBits(si, 2, DemodBuffer); si += 2; //could check psk cr
794 //uint8_t inverse = PackBits(si, 1, DemodBuffer); si += 1;
796 uint8_t modread
= PackBits(si
, 3, DemodBuffer
); si
+= 3;
797 uint8_t maxBlk
= PackBits(si
, 3, DemodBuffer
); si
+= 3;
798 //uint8_t ST = PackBits(si, 1, DemodBuffer); si += 1;
799 if (maxBlk
== 0) continue;
801 if (!testQ5Modulation(mode
, modread
)) continue;
802 if (bitRate
!= clk
) continue;
803 *fndBitRate
= convertQ5bitRate(bitRate
);
804 if (*fndBitRate
< 0) continue;
812 bool testBitRate(uint8_t readRate
, uint8_t clk
){
813 uint8_t expected
[] = {8, 16, 32, 40, 50, 64, 100, 128};
814 if (expected
[readRate
] == clk
)
820 bool test(uint8_t mode
, uint8_t *offset
, int *fndBitRate
, uint8_t clk
, bool *Q5
){
822 if ( DemodBufferLen
< 64 ) return FALSE
;
824 for (uint8_t idx
= 28; idx
< 64; idx
++){
826 if ( PackBits(si
, 28, DemodBuffer
) == 0x00 ) continue;
828 uint8_t safer
= PackBits(si
, 4, DemodBuffer
); si
+= 4; //master key
829 uint8_t resv
= PackBits(si
, 4, DemodBuffer
); si
+= 4; //was 7 & +=7+3 //should be only 4 bits if extended mode
830 // 2nibble must be zeroed.
831 // moved test to here, since this gets most faults first.
832 if ( resv
> 0x00) continue;
834 uint8_t xtRate
= PackBits(si
, 3, DemodBuffer
); si
+= 3; //extended mode part of rate
835 int bitRate
= PackBits(si
, 3, DemodBuffer
); si
+= 3; //bit rate
836 if (bitRate
> 7) continue;
837 uint8_t extend
= PackBits(si
, 1, DemodBuffer
); si
+= 1; //bit 15 extended mode
838 uint8_t modread
= PackBits(si
, 5, DemodBuffer
); si
+= 5+2+1;
839 //uint8_t pskcr = PackBits(si, 2, DemodBuffer); si += 2+1; //could check psk cr
840 //uint8_t nml01 = PackBits(si, 1, DemodBuffer); si += 1+5; //bit 24, 30, 31 could be tested for 0 if not extended mode
841 //uint8_t nml02 = PackBits(si, 2, DemodBuffer); si += 2;
844 bool extMode
=( (safer
== 0x6 || safer
== 0x9) && extend
) ? TRUE
: FALSE
;
847 if (xtRate
) continue; //nml01 || nml02 || caused issues on noralys tags
850 if (!testModulation(mode
, modread
)) continue;
851 if (!testBitRate(bitRate
, clk
)) continue;
852 *fndBitRate
= bitRate
;
857 if (testQ5(mode
, offset
, fndBitRate
, clk
)) {
864 void printT55xxBlock(const char *blockNum
){
866 uint8_t i
= config
.offset
;
867 uint8_t endpos
= 32 + i
;
868 uint32_t blockData
= 0;
869 uint8_t bits
[64] = {0x00};
871 if ( !DemodBufferLen
) return;
873 if ( endpos
> DemodBufferLen
){
874 PrintAndLog("The configured offset %d is too big. Possible offset: %d)", i
, DemodBufferLen
-32);
878 for (; i
< endpos
; ++i
)
879 bits
[i
- config
.offset
] = DemodBuffer
[i
];
881 blockData
= PackBits(0, 32, bits
);
882 uint8_t bytes
[4] = {0};
883 num_to_bytes(blockData
, 4, bytes
);
885 PrintAndLog(" %s | %08X | %s | %s", blockNum
, blockData
, sprint_bin(bits
,32), sprint_ascii(bytes
,4));
888 int special(const char *Cmd
) {
889 uint32_t blockData
= 0;
890 uint8_t bits
[32] = {0x00};
892 PrintAndLog("OFFSET | DATA | BINARY | ASCII");
893 PrintAndLog("-------+-------+-------------------------------------+------");
897 for (i
= 0; i
< 32; ++i
)
898 bits
[i
]=DemodBuffer
[j
+i
];
900 blockData
= PackBits(0, 32, bits
);
902 PrintAndLog("%02d | 0x%08X | %s",j
, blockData
, sprint_bin(bits
,32));
907 int printConfiguration( t55xx_conf_block_t b
){
908 PrintAndLog("Chip Type : %s", (b
.Q5
) ? "T5555(Q5)" : "T55x7");
909 PrintAndLog("Modulation : %s", GetSelectedModulationStr(b
.modulation
) );
910 PrintAndLog("Bit Rate : %s", GetBitRateStr(b
.bitrate
) );
911 PrintAndLog("Inverted : %s", (b
.inverted
) ? "Yes" : "No" );
912 PrintAndLog("Offset : %d", b
.offset
);
913 PrintAndLog("Seq. Term. : %s", (b
.ST
) ? "Yes" : "No" );
914 PrintAndLog("Block0 : 0x%08X", b
.block0
);
919 int CmdT55xxWakeUp(const char *Cmd
) {
920 uint32_t password
= 0;
923 while(param_getchar(Cmd
, cmdp
) != 0x00 && !errors
) {
924 switch(param_getchar(Cmd
, cmdp
)) {
927 return usage_t55xx_wakup();
930 password
= param_get32ex(Cmd
, cmdp
+1, 0, 16);
935 PrintAndLog("Unknown parameter '%c'", param_getchar(Cmd
, cmdp
));
940 if (errors
) return usage_t55xx_wakup();
942 UsbCommand c
= {CMD_T55XX_WAKEUP
, {password
, 0, 0}};
943 clearCommandBuffer();
945 PrintAndLog("Wake up command sent. Try read now");
949 int CmdT55xxWriteBlock(const char *Cmd
) {
950 uint8_t block
= 0xFF; //default to invalid block
951 uint32_t data
= 0; //default to blank Block
952 uint32_t password
= 0; //default to blank Block 7
955 bool gotdata
= false;
958 while(param_getchar(Cmd
, cmdp
) != 0x00 && !errors
) {
959 switch(param_getchar(Cmd
, cmdp
)) {
962 return usage_t55xx_write();
965 errors
|= param_getdec(Cmd
, cmdp
+1, &block
);
970 data
= param_get32ex(Cmd
, cmdp
+1, 0, 16);
976 password
= param_get32ex(Cmd
, cmdp
+1, 0, 16);
985 PrintAndLog("Unknown parameter '%c'", param_getchar(Cmd
, cmdp
));
990 if (errors
|| !gotdata
) return usage_t55xx_write();
993 PrintAndLog("Block number must be between 0 and 7");
997 UsbCommand c
= {CMD_T55XX_WRITE_BLOCK
, {data
, block
, 0}};
999 c
.d
.asBytes
[0] = (page1
) ? 0x2 : 0;
1001 char pwdStr
[16] = {0};
1002 snprintf(pwdStr
, sizeof(pwdStr
), "pwd: 0x%08X", password
);
1004 PrintAndLog("Writing page %d block: %02d data: 0x%08X %s", page1
, block
, data
, (usepwd
) ? pwdStr
: "" );
1008 c
.arg
[2] = password
;
1009 c
.d
.asBytes
[0] |= 0x1;
1011 clearCommandBuffer();
1013 if (!WaitForResponseTimeout(CMD_ACK
, &resp
, 1500)){
1014 PrintAndLog("Error occurred, device did not ACK write operation. (May be due to old firmware)");
1020 int CmdT55xxReadTrace(const char *Cmd
) {
1021 char cmdp
= param_getchar(Cmd
, 0);
1022 bool pwdmode
= false;
1023 uint32_t password
= 0;
1024 if (strlen(Cmd
) > 1 || cmdp
== 'h' || cmdp
== 'H') return usage_t55xx_trace();
1026 if (strlen(Cmd
)==0) {
1028 if (!SanityOfflineCheck(FALSE
)) return 1;
1030 if ( !AquireData( T55x7_PAGE1
, REGULAR_READ_MODE_BLOCK
, pwdmode
, password
) )
1035 if (!DecodeT5555TraceBlock()) return 1;
1037 if (!DecodeT55xxBlock()) return 1;
1040 if ( !DemodBufferLen
) return 1;
1042 RepaintGraphWindow();
1043 uint8_t repeat
= (config
.offset
> 5) ? 32 : 0;
1045 uint8_t si
= config
.offset
+ repeat
;
1046 uint32_t bl1
= PackBits(si
, 32, DemodBuffer
);
1047 uint32_t bl2
= PackBits(si
+32, 32, DemodBuffer
);
1050 uint32_t hdr
= PackBits(si
, 9, DemodBuffer
); si
+= 9;
1053 PrintAndLog("Invalid Q5 Trace data header (expected 0x1FF, found %X)", hdr
);
1057 t5555_tracedata_t data
= {.bl1
= bl1
, .bl2
= bl2
, .icr
= 0, .lotidc
= '?', .lotid
= 0, .wafer
= 0, .dw
=0};
1059 data
.icr
= PackBits(si
, 2, DemodBuffer
); si
+= 2;
1060 data
.lotidc
= 'Z' - PackBits(si
, 2, DemodBuffer
); si
+= 3;
1062 data
.lotid
= PackBits(si
, 4, DemodBuffer
); si
+= 5;
1064 data
.lotid
|= PackBits(si
, 4, DemodBuffer
); si
+= 5;
1066 data
.lotid
|= PackBits(si
, 4, DemodBuffer
); si
+= 5;
1068 data
.lotid
|= PackBits(si
, 4, DemodBuffer
); si
+= 5;
1070 data
.lotid
|= PackBits(si
, 1, DemodBuffer
); si
+= 1;
1072 data
.wafer
= PackBits(si
, 3, DemodBuffer
); si
+= 4;
1074 data
.wafer
|= PackBits(si
, 2, DemodBuffer
); si
+= 2;
1076 data
.dw
= PackBits(si
, 2, DemodBuffer
); si
+= 3;
1078 data
.dw
|= PackBits(si
, 4, DemodBuffer
); si
+= 5;
1080 data
.dw
|= PackBits(si
, 4, DemodBuffer
); si
+= 5;
1082 data
.dw
|= PackBits(si
, 4, DemodBuffer
); si
+= 5;
1084 printT5555Trace(data
, repeat
);
1088 t55x7_tracedata_t data
= {.bl1
= bl1
, .bl2
= bl2
, .acl
= 0, .mfc
= 0, .cid
= 0, .year
= 0, .quarter
= 0, .icr
= 0, .lotid
= 0, .wafer
= 0, .dw
= 0};
1090 data
.acl
= PackBits(si
, 8, DemodBuffer
); si
+= 8;
1091 if ( data
.acl
!= 0xE0 ) {
1092 PrintAndLog("The modulation is most likely wrong since the ACL is not 0xE0. ");
1096 data
.mfc
= PackBits(si
, 8, DemodBuffer
); si
+= 8;
1097 data
.cid
= PackBits(si
, 5, DemodBuffer
); si
+= 5;
1098 data
.icr
= PackBits(si
, 3, DemodBuffer
); si
+= 3;
1099 data
.year
= PackBits(si
, 4, DemodBuffer
); si
+= 4;
1100 data
.quarter
= PackBits(si
, 2, DemodBuffer
); si
+= 2;
1101 data
.lotid
= PackBits(si
, 14, DemodBuffer
); si
+= 14;
1102 data
.wafer
= PackBits(si
, 5, DemodBuffer
); si
+= 5;
1103 data
.dw
= PackBits(si
, 15, DemodBuffer
);
1105 time_t t
= time(NULL
);
1106 struct tm tm
= *localtime(&t
);
1107 if ( data
.year
> tm
.tm_year
-110)
1112 printT55x7Trace(data
, repeat
);
1117 void printT55x7Trace( t55x7_tracedata_t data
, uint8_t repeat
){
1118 PrintAndLog("-- T55x7 Trace Information ----------------------------------");
1119 PrintAndLog("-------------------------------------------------------------");
1120 PrintAndLog(" ACL Allocation class (ISO/IEC 15963-1) : 0x%02X (%d)", data
.acl
, data
.acl
);
1121 PrintAndLog(" MFC Manufacturer ID (ISO/IEC 7816-6) : 0x%02X (%d) - %s", data
.mfc
, data
.mfc
, getTagInfo(data
.mfc
));
1122 PrintAndLog(" CID : 0x%02X (%d) - %s", data
.cid
, data
.cid
, GetModelStrFromCID(data
.cid
));
1123 PrintAndLog(" ICR IC Revision : %d", data
.icr
);
1124 PrintAndLog(" Manufactured");
1125 PrintAndLog(" Year/Quarter : %d/%d", data
.year
, data
.quarter
);
1126 PrintAndLog(" Lot ID : %d", data
.lotid
);
1127 PrintAndLog(" Wafer number : %d", data
.wafer
);
1128 PrintAndLog(" Die Number : %d", data
.dw
);
1129 PrintAndLog("-------------------------------------------------------------");
1130 PrintAndLog(" Raw Data - Page 1");
1131 PrintAndLog(" Block 1 : 0x%08X %s", data
.bl1
, sprint_bin(DemodBuffer
+config
.offset
+repeat
,32) );
1132 PrintAndLog(" Block 2 : 0x%08X %s", data
.bl2
, sprint_bin(DemodBuffer
+config
.offset
+repeat
+32,32) );
1133 PrintAndLog("-------------------------------------------------------------");
1138 1-8 ACL Allocation class (ISO/IEC 15963-1) 0xE0
1139 9-16 MFC Manufacturer ID (ISO/IEC 7816-6) 0x15 Atmel Corporation
1140 17-21 CID 0x1 = Atmel ATA5577M1 0x2 = Atmel ATA5577M2
1141 22-24 ICR IC revision
1142 25-28 YEAR (BCD encoded) 9 (= 2009)
1143 29-30 QUARTER 1,2,3,4
1149 18-32 DW, die number sequential
1153 void printT5555Trace( t5555_tracedata_t data
, uint8_t repeat
){
1154 PrintAndLog("-- T5555 (Q5) Trace Information -----------------------------");
1155 PrintAndLog("-------------------------------------------------------------");
1156 PrintAndLog(" ICR IC Revision : %d", data
.icr
);
1157 PrintAndLog(" Lot : %c%d", data
.lotidc
, data
.lotid
);
1158 PrintAndLog(" Wafer number : %d", data
.wafer
);
1159 PrintAndLog(" Die Number : %d", data
.dw
);
1160 PrintAndLog("-------------------------------------------------------------");
1161 PrintAndLog(" Raw Data - Page 1");
1162 PrintAndLog(" Block 1 : 0x%08X %s", data
.bl1
, sprint_bin(DemodBuffer
+config
.offset
+repeat
,32) );
1163 PrintAndLog(" Block 2 : 0x%08X %s", data
.bl2
, sprint_bin(DemodBuffer
+config
.offset
+repeat
+32,32) );
1167 TRACE - BLOCK O and BLOCK1
1172 15-35 Lot ID (NB parity)
1173 36-41 Wafer number (NB parity)
1174 42-58 DW, die number sequential (NB parity)
1180 //need to add Q5 info...
1181 int CmdT55xxInfo(const char *Cmd
){
1183 Page 0 Block 0 Configuration data.
1187 bool pwdmode
= false;
1188 uint32_t password
= 0;
1189 char cmdp
= param_getchar(Cmd
, 0);
1191 if (strlen(Cmd
) > 1 || cmdp
== 'h' || cmdp
== 'H') return usage_t55xx_info();
1193 if (strlen(Cmd
)==0){
1195 if (!SanityOfflineCheck(FALSE
)) return 1;
1197 if ( !AquireData( T55x7_PAGE0
, T55x7_CONFIGURATION_BLOCK
, pwdmode
, password
) )
1201 if (!DecodeT55xxBlock()) return 1;
1203 // too little space to start with
1204 if ( DemodBufferLen
< 32) return 1;
1207 PrintAndLog("Offset+32 ==%d\n DemodLen == %d", config
.offset
+ 32,DemodBufferLen
);
1209 uint8_t si
= config
.offset
;
1210 uint32_t bl0
= PackBits(si
, 32, DemodBuffer
);
1211 uint32_t safer
= PackBits(si
, 4, DemodBuffer
); si
+= 4;
1212 uint32_t resv
= PackBits(si
, 7, DemodBuffer
); si
+= 7;
1213 uint32_t dbr
= PackBits(si
, 3, DemodBuffer
); si
+= 3;
1214 uint32_t extend
= PackBits(si
, 1, DemodBuffer
); si
+= 1;
1215 uint32_t datamod
= PackBits(si
, 5, DemodBuffer
); si
+= 5;
1216 uint32_t pskcf
= PackBits(si
, 2, DemodBuffer
); si
+= 2;
1217 uint32_t aor
= PackBits(si
, 1, DemodBuffer
); si
+= 1;
1218 uint32_t otp
= PackBits(si
, 1, DemodBuffer
); si
+= 1;
1219 uint32_t maxblk
= PackBits(si
, 3, DemodBuffer
); si
+= 3;
1220 uint32_t pwd
= PackBits(si
, 1, DemodBuffer
); si
+= 1;
1221 uint32_t sst
= PackBits(si
, 1, DemodBuffer
); si
+= 1;
1222 uint32_t fw
= PackBits(si
, 1, DemodBuffer
); si
+= 1;
1223 uint32_t inv
= PackBits(si
, 1, DemodBuffer
); si
+= 1;
1224 uint32_t por
= PackBits(si
, 1, DemodBuffer
); si
+= 1;
1226 if (config
.Q5
) PrintAndLog("*** Warning *** Config Info read off a Q5 will not display as expected");
1228 PrintAndLog("-- T55x7 Configuration & Tag Information --------------------");
1229 PrintAndLog("-------------------------------------------------------------");
1230 PrintAndLog(" Safer key : %s", GetSaferStr(safer
));
1231 PrintAndLog(" reserved : %d", resv
);
1232 PrintAndLog(" Data bit rate : %s", GetBitRateStr(dbr
));
1233 PrintAndLog(" eXtended mode : %s", (extend
) ? "Yes - Warning":"No");
1234 PrintAndLog(" Modulation : %s", GetModulationStr(datamod
));
1235 PrintAndLog(" PSK clock frequency : %d", pskcf
);
1236 PrintAndLog(" AOR - Answer on Request : %s", (aor
) ? "Yes":"No");
1237 PrintAndLog(" OTP - One Time Pad : %s", (otp
) ? "Yes - Warning":"No" );
1238 PrintAndLog(" Max block : %d", maxblk
);
1239 PrintAndLog(" Password mode : %s", (pwd
) ? "Yes":"No");
1240 PrintAndLog(" Sequence Start Terminator : %s", (sst
) ? "Yes":"No");
1241 PrintAndLog(" Fast Write : %s", (fw
) ? "Yes":"No");
1242 PrintAndLog(" Inverse data : %s", (inv
) ? "Yes":"No");
1243 PrintAndLog(" POR-Delay : %s", (por
) ? "Yes":"No");
1244 PrintAndLog("-------------------------------------------------------------");
1245 PrintAndLog(" Raw Data - Page 0");
1246 PrintAndLog(" Block 0 : 0x%08X %s", bl0
, sprint_bin(DemodBuffer
+config
.offset
,32) );
1247 PrintAndLog("-------------------------------------------------------------");
1252 int CmdT55xxDump(const char *Cmd
){
1254 uint32_t password
= 0;
1255 bool override
= false;
1256 char cmdp
= param_getchar(Cmd
, 0);
1257 if ( cmdp
== 'h' || cmdp
== 'H') return usage_t55xx_dump();
1259 bool usepwd
= ( strlen(Cmd
) > 0);
1261 password
= param_get32ex(Cmd
, 0, 0, 16);
1262 if (param_getchar(Cmd
, 1) =='o' )
1267 for ( uint8_t i
= 0; i
< 8; ++i
)
1268 T55xxReadBlock(i
, 0, usepwd
, override
, password
);
1271 for ( uint8_t i
= 0; i
< 4; i
++)
1272 T55xxReadBlock(i
, 1, usepwd
, override
, password
);
1277 int AquireData( uint8_t page
, uint8_t block
, bool pwdmode
, uint32_t password
){
1280 // bit1 = page to read from
1281 // arg1: which block to read
1283 uint8_t arg0
= (page
<<1) | pwdmode
;
1284 UsbCommand c
= {CMD_T55XX_READ_BLOCK
, {arg0
, block
, password
}};
1285 clearCommandBuffer();
1287 if ( !WaitForResponseTimeout(CMD_ACK
, NULL
, 2500) ) {
1288 PrintAndLog("command execution time out");
1292 //uint8_t got[12288];
1294 GetFromBigBuf(got
, sizeof(got
), 0);
1295 if ( !WaitForResponseTimeout(CMD_ACK
, NULL
, 8000) ) {
1296 PrintAndLog("command execution time out");
1299 setGraphBuf(got
, sizeof(got
));
1303 char * GetBitRateStr(uint32_t id
){
1304 static char buf
[25];
1308 case 0: snprintf(retStr
,sizeof(buf
),"%d - RF/8",id
); break;
1309 case 1: snprintf(retStr
,sizeof(buf
),"%d - RF/16",id
); break;
1310 case 2: snprintf(retStr
,sizeof(buf
),"%d - RF/32",id
); break;
1311 case 3: snprintf(retStr
,sizeof(buf
),"%d - RF/40",id
); break;
1312 case 4: snprintf(retStr
,sizeof(buf
),"%d - RF/50",id
); break;
1313 case 5: snprintf(retStr
,sizeof(buf
),"%d - RF/64",id
); break;
1314 case 6: snprintf(retStr
,sizeof(buf
),"%d - RF/100",id
); break;
1315 case 7: snprintf(retStr
,sizeof(buf
),"%d - RF/128",id
); break;
1316 default: snprintf(retStr
,sizeof(buf
),"%d - (Unknown)",id
); break;
1321 char * GetSaferStr(uint32_t id
){
1322 static char buf
[40];
1325 snprintf(retStr
,sizeof(buf
),"%d",id
);
1327 snprintf(retStr
,sizeof(buf
),"%d - passwd",id
);
1330 snprintf(retStr
,sizeof(buf
),"%d - testmode",id
);
1336 char * GetModulationStr( uint32_t id
){
1337 static char buf
[60];
1341 case 0: snprintf(retStr
,sizeof(buf
),"%d - DIRECT (ASK/NRZ)",id
); break;
1342 case 1: snprintf(retStr
,sizeof(buf
),"%d - PSK 1 phase change when input changes",id
); break;
1343 case 2: snprintf(retStr
,sizeof(buf
),"%d - PSK 2 phase change on bitclk if input high",id
); break;
1344 case 3: snprintf(retStr
,sizeof(buf
),"%d - PSK 3 phase change on rising edge of input",id
); break;
1345 case 4: snprintf(retStr
,sizeof(buf
),"%d - FSK 1 RF/8 RF/5",id
); break;
1346 case 5: snprintf(retStr
,sizeof(buf
),"%d - FSK 2 RF/8 RF/10",id
); break;
1347 case 6: snprintf(retStr
,sizeof(buf
),"%d - FSK 1a RF/5 RF/8",id
); break;
1348 case 7: snprintf(retStr
,sizeof(buf
),"%d - FSK 2a RF/10 RF/8",id
); break;
1349 case 8: snprintf(retStr
,sizeof(buf
),"%d - Manchester",id
); break;
1350 case 16: snprintf(retStr
,sizeof(buf
),"%d - Biphase",id
); break;
1351 case 0x18:snprintf(retStr
,sizeof(buf
),"%d - Biphase a - AKA Conditional Dephase Encoding(CDP)",id
); break;
1352 case 17: snprintf(retStr
,sizeof(buf
),"%d - Reserved",id
); break;
1353 default: snprintf(retStr
,sizeof(buf
),"0x%02X (Unknown)",id
); break;
1358 char * GetModelStrFromCID(uint32_t cid
){
1360 static char buf
[10];
1363 if (cid
== 1) snprintf(retStr
, sizeof(buf
),"ATA5577M1");
1364 if (cid
== 2) snprintf(retStr
, sizeof(buf
),"ATA5577M2");
1368 char * GetSelectedModulationStr( uint8_t id
){
1370 static char buf
[20];
1374 case DEMOD_FSK
: snprintf(retStr
,sizeof(buf
),"FSK"); break;
1375 case DEMOD_FSK1
: snprintf(retStr
,sizeof(buf
),"FSK1"); break;
1376 case DEMOD_FSK1a
: snprintf(retStr
,sizeof(buf
),"FSK1a"); break;
1377 case DEMOD_FSK2
: snprintf(retStr
,sizeof(buf
),"FSK2"); break;
1378 case DEMOD_FSK2a
: snprintf(retStr
,sizeof(buf
),"FSK2a"); break;
1379 case DEMOD_ASK
: snprintf(retStr
,sizeof(buf
),"ASK"); break;
1380 case DEMOD_NRZ
: snprintf(retStr
,sizeof(buf
),"DIRECT/NRZ"); break;
1381 case DEMOD_PSK1
: snprintf(retStr
,sizeof(buf
),"PSK1"); break;
1382 case DEMOD_PSK2
: snprintf(retStr
,sizeof(buf
),"PSK2"); break;
1383 case DEMOD_PSK3
: snprintf(retStr
,sizeof(buf
),"PSK3"); break;
1384 case DEMOD_BI
: snprintf(retStr
,sizeof(buf
),"BIPHASE"); break;
1385 case DEMOD_BIa
: snprintf(retStr
,sizeof(buf
),"BIPHASEa - (CDP)"); break;
1386 default: snprintf(retStr
,sizeof(buf
),"(Unknown)"); break;
1391 void t55x7_create_config_block( int tagtype
){
1394 T55X7_DEFAULT_CONFIG_BLOCK, T55X7_RAW_CONFIG_BLOCK
1395 T55X7_EM_UNIQUE_CONFIG_BLOCK, T55X7_FDXB_CONFIG_BLOCK,
1396 T55X7_FDXB_CONFIG_BLOCK, T55X7_HID_26_CONFIG_BLOCK, T55X7_INDALA_64_CONFIG_BLOCK, T55X7_INDALA_224_CONFIG_BLOCK
1397 T55X7_GUARDPROXII_CONFIG_BLOCK, T55X7_VIKING_CONFIG_BLOCK, T55X7_NORALYS_CONFIG_BLOCK, T55X7_IOPROX_CONFIG_BLOCK
1399 static char buf
[60];
1403 case 0: snprintf(retStr
, sizeof(buf
),"%08X - T55X7 Default", T55X7_DEFAULT_CONFIG_BLOCK
); break;
1404 case 1: snprintf(retStr
, sizeof(buf
),"%08X - T55X7 Raw", T55X7_RAW_CONFIG_BLOCK
); break;
1405 case 2: snprintf(retStr
, sizeof(buf
),"%08X - T5555 Q5 Default", T5555_DEFAULT_CONFIG_BLOCK
); break;
1412 int CmdResetRead(const char *Cmd
) {
1413 UsbCommand c
= {CMD_T55XX_RESET_READ
, {0,0,0}};
1414 clearCommandBuffer();
1416 if ( !WaitForResponseTimeout(CMD_ACK
, NULL
, 2500) ) {
1417 PrintAndLog("command execution time out");
1421 uint8_t got
[BIGBUF_SIZE
-1];
1422 GetFromBigBuf(got
,sizeof(got
),0);
1423 WaitForResponse(CMD_ACK
,NULL
);
1424 setGraphBuf(got
, sizeof(got
));
1427 // ADD T5555 (Q5) Default config block
1428 int CmdT55xxWipe(const char *Cmd
) {
1429 char writeData
[20] = {0};
1430 char *ptrData
= writeData
;
1431 char cmdp
= param_getchar(Cmd
, 0);
1432 if ( cmdp
== 'h' || cmdp
== 'H') return usage_t55xx_wipe();
1434 bool Q5
= (cmdp
== 'q' || cmdp
== 'Q');
1436 // Try with the default password to reset block 0
1437 // With a pwd should work even if pwd bit not set
1438 PrintAndLog("\nBeginning Wipe of a T55xx tag (assuming the tag is not password protected)\n");
1441 snprintf(ptrData
,sizeof(writeData
),"b 0 d 6001F004 p 0");
1443 snprintf(ptrData
,sizeof(writeData
),"b 0 d 000880E0 p 0");
1445 if (!CmdT55xxWriteBlock(ptrData
)) PrintAndLog("Error writing blk 0");
1447 for (uint8_t blk
= 1; blk
<8; blk
++) {
1449 snprintf(ptrData
,sizeof(writeData
),"b %d d 0", blk
);
1451 if (!CmdT55xxWriteBlock(ptrData
)) PrintAndLog("Error writing blk %d", blk
);
1453 memset(writeData
,0x00, sizeof(writeData
));
1458 bool IsCancelled(void) {
1462 printf("\naborted via keyboard!\n");
1468 int CmdT55xxBruteForce(const char *Cmd
) {
1470 // load a default pwd file.
1472 char filename
[FILE_PATH_SIZE
]={0};
1474 uint8_t stKeyBlock
= 20;
1475 uint8_t *keyBlock
= NULL
, *p
= NULL
;
1476 uint32_t start_password
= 0x00000000; //start password
1477 uint32_t end_password
= 0xFFFFFFFF; //end password
1480 memset(line
, 0, sizeof(line
));
1482 char cmdp
= param_getchar(Cmd
, 0);
1483 if (cmdp
== 'h' || cmdp
== 'H') return usage_t55xx_bruteforce();
1485 keyBlock
= calloc(stKeyBlock
, 4);
1486 if (keyBlock
== NULL
) return 1;
1488 if (cmdp
== 'i' || cmdp
== 'I') {
1490 int len
= strlen(Cmd
+2);
1491 if (len
> FILE_PATH_SIZE
) len
= FILE_PATH_SIZE
;
1492 memcpy(filename
, Cmd
+2, len
);
1494 FILE * f
= fopen( filename
, "r");
1496 PrintAndLog("File: %s: not found or locked.", filename
);
1501 while( fgets(line
, sizeof(line
), f
) ){
1502 if (strlen(line
) < 8 || line
[7] == '\n') continue;
1505 while (fgetc(f
) != '\n' && !feof(f
)) ;
1507 //The line start with # is comment, skip
1508 if( line
[0]=='#' ) continue;
1510 if (!isxdigit(line
[0])) {
1511 PrintAndLog("File content error. '%s' must include 8 HEX symbols", line
);
1517 // realloc keyblock array size.
1518 if ( stKeyBlock
- keycnt
< 2) {
1519 p
= realloc(keyBlock
, 4 * (stKeyBlock
+= 10));
1521 PrintAndLog("Cannot allocate memory for defaultKeys");
1530 memset(keyBlock
+ 4 * keycnt
, 0, 4);
1532 num_to_bytes( strtoll(line
, NULL
, 16), 4, keyBlock
+ 4*keycnt
);
1534 PrintAndLog("chk custom pwd[%2d] %08X", keycnt
, bytes_to_num(keyBlock
+ 4 * keycnt
, 4) );
1536 memset(line
, 0, sizeof(line
));
1542 PrintAndLog("No keys found in file");
1546 PrintAndLog("Loaded %d keys", keycnt
);
1549 uint64_t testpwd
= 0x00;
1550 for (uint16_t c
= 0; c
< keycnt
; ++c
) {
1553 printf("Device offline\n");
1558 if (IsCancelled()) {
1563 testpwd
= bytes_to_num(keyBlock
+ 4*c
, 4);
1565 PrintAndLog("Testing %08X", testpwd
);
1567 if ( !AquireData(T55x7_PAGE0
, T55x7_CONFIGURATION_BLOCK
, TRUE
, testpwd
)) {
1568 PrintAndLog("Acquire data from device failed. Quitting");
1573 found
= tryDetectModulation();
1575 PrintAndLog("Found valid password: [%08X]", testpwd
);
1580 PrintAndLog("Password NOT found.");
1585 // Try to read Block 7, first :)
1587 // incremental pwd range search
1588 start_password
= param_get32ex(Cmd
, 0, 0, 16);
1589 end_password
= param_get32ex(Cmd
, 1, 0, 16);
1591 if ( start_password
>= end_password
) {
1593 return usage_t55xx_bruteforce();
1596 PrintAndLog("Search password range [%08X -> %08X]", start_password
, end_password
);
1598 uint32_t i
= start_password
;
1600 while ((!found
) && (i
<= end_password
)){
1605 if (IsCancelled()) {
1610 if (!AquireData(T55x7_PAGE0
, T55x7_CONFIGURATION_BLOCK
, TRUE
, i
)) {
1611 PrintAndLog("Acquire data from device failed. Quitting");
1615 found
= tryDetectModulation();
1624 PrintAndLog("Found valid password: [%08x]", i
);
1626 PrintAndLog("Password NOT found. Last tried: [%08x]", --i
);
1632 int tryOnePassword(uint32_t password
) {
1633 PrintAndLog("Trying password %08x", password
);
1634 if (!AquireData(T55x7_PAGE0
, T55x7_CONFIGURATION_BLOCK
, TRUE
, password
)) {
1635 PrintAndLog("Acquire data from device failed. Quitting");
1639 if (tryDetectModulation())
1645 int CmdT55xxRecoverPW(const char *Cmd
) {
1647 uint32_t orig_password
= 0x0;
1648 uint32_t curr_password
= 0x0;
1649 uint32_t prev_password
= 0xffffffff;
1650 uint32_t mask
= 0x0;
1652 char cmdp
= param_getchar(Cmd
, 0);
1653 if (cmdp
== 'h' || cmdp
== 'H') return usage_t55xx_recoverpw();
1655 orig_password
= param_get32ex(Cmd
, 0, 0x51243648, 16); //password used by handheld cloners
1657 // first try fliping each bit in the expected password
1659 curr_password
= orig_password
^ ( 1 << bit
);
1660 found
= tryOnePassword(curr_password
);
1661 if (found
== -1) return 0;
1664 if (IsCancelled()) return 0;
1667 // now try to use partial original password, since block 7 should have been completely
1668 // erased during the write sequence and it is possible that only partial password has been
1670 // not sure from which end the bit bits are written, so try from both ends
1671 // from low bit to high bit
1674 mask
+= ( 1 << bit
);
1675 curr_password
= orig_password
& mask
;
1676 // if updated mask didn't change the password, don't try it again
1677 if (prev_password
== curr_password
) {
1681 found
= tryOnePassword(curr_password
);
1682 if (found
== -1) return 0;
1684 prev_password
= curr_password
;
1686 if (IsCancelled()) return 0;
1689 // from high bit to low
1693 mask
-= ( 1 << bit
);
1694 curr_password
= orig_password
& mask
;
1695 // if updated mask didn't change the password, don't try it again
1696 if (prev_password
== curr_password
) {
1700 found
= tryOnePassword(curr_password
);
1704 prev_password
= curr_password
;
1706 if (IsCancelled()) return 0;
1712 PrintAndLog("Found valid password: [%08x]", curr_password
);
1714 PrintAndLog("Password NOT found.");
1719 static command_t CommandTable
[] = {
1720 {"help", CmdHelp
, 1, "This help"},
1721 {"bruteforce", CmdT55xxBruteForce
,0, "<start password> <end password> [i <*.dic>] Simple bruteforce attack to find password"},
1722 {"config", CmdT55xxSetConfig
, 1, "Set/Get T55XX configuration (modulation, inverted, offset, rate)"},
1723 {"detect", CmdT55xxDetect
, 1, "[1] Try detecting the tag modulation from reading the configuration block."},
1724 {"dump", CmdT55xxDump
, 0, "[password] [o] Dump T55xx card block 0-7. Optional [password], [override]"},
1725 {"info", CmdT55xxInfo
, 1, "[1] Show T55x7 configuration data (page 0/ blk 0)"},
1726 {"read", CmdT55xxReadBlock
, 0, "b <block> p [password] [o] [1] -- Read T55xx block data. Optional [p password], [override], [page1]"},
1727 {"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)"},
1728 {"recoverpw", CmdT55xxRecoverPW
, 0, "[password] Try to recover from bad password write from a cloner. Only use on PW protected chips!"},
1729 {"special", special
, 0, "Show block changes with 64 different offsets"},
1730 {"trace", CmdT55xxReadTrace
, 1, "[1] Show T55x7 traceability data (page 1/ blk 0-1)"},
1731 {"wakeup", CmdT55xxWakeUp
, 0, "Send AOR wakeup command"},
1732 {"wipe", CmdT55xxWipe
, 0, "[q] Wipe a T55xx tag and set defaults (will destroy any data on tag)"},
1733 {"write", CmdT55xxWriteBlock
,0, "b <block> d <data> p [password] [1] -- Write T55xx block data. Optional [p password], [page1]"},
1734 {NULL
, NULL
, 0, NULL
}
1737 int CmdLFT55XX(const char *Cmd
) {
1738 clearCommandBuffer();
1739 CmdsParse(CommandTable
, Cmd
);
1743 int CmdHelp(const char *Cmd
) {
1744 CmdsHelp(CommandTable
);