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 "cmdhf14a.h" //for getTagInfo
26 #define T55x7_CONFIGURATION_BLOCK 0x00
27 #define T55x7_PAGE0 0x00
28 #define T55x7_PAGE1 0x01
29 #define T55x7_PWD 0x00000010
30 #define REGULAR_READ_MODE_BLOCK 0xFF
32 // Default configuration
33 t55xx_conf_block_t config
= { .modulation
= DEMOD_ASK
, .inverted
= FALSE
, .offset
= 0x00, .block0
= 0x00, .Q5
= FALSE
};
35 t55xx_conf_block_t
Get_t55xx_Config(){
38 void Set_t55xx_Config(t55xx_conf_block_t conf
){
42 int usage_t55xx_config(){
43 PrintAndLog("Usage: lf t55xx config [d <demodulation>] [i 1] [o <offset>] [Q5]");
44 PrintAndLog("Options:");
45 PrintAndLog(" h - This help");
46 PrintAndLog(" b <8|16|32|40|50|64|100|128> - Set bitrate");
47 PrintAndLog(" d <FSK|FSK1|FSK1a|FSK2|FSK2a|ASK|PSK1|PSK2|NRZ|BI|BIa> - Set demodulation FSK / ASK / PSK / NRZ / Biphase / Biphase A");
48 PrintAndLog(" i [1] - Invert data signal, defaults to normal");
49 PrintAndLog(" o [offset] - Set offset, where data should start decode in bitstream");
50 PrintAndLog(" Q5 - Set as Q5(T5555) chip instead of T55x7");
51 PrintAndLog(" ST - Set Sequence Terminator on");
53 PrintAndLog("Examples:");
54 PrintAndLog(" lf t55xx config d FSK - FSK demodulation");
55 PrintAndLog(" lf t55xx config d FSK i 1 - FSK demodulation, inverse data");
56 PrintAndLog(" lf t55xx config d FSK i 1 o 3 - FSK demodulation, inverse data, offset=3,start from position 3 to decode data");
60 int usage_t55xx_read(){
61 PrintAndLog("Usage: lf t55xx read [b <block>] [p <password>] <override_safety> <page1>");
62 PrintAndLog("Options:");
63 PrintAndLog(" b <block> - block number to read. Between 0-7");
64 PrintAndLog(" p <password> - OPTIONAL password (8 hex characters)");
65 PrintAndLog(" o - OPTIONAL override safety check");
66 PrintAndLog(" 1 - OPTIONAL read Page 1 instead of Page 0");
67 PrintAndLog(" ****WARNING****");
68 PrintAndLog(" Use of read with password on a tag not configured for a pwd");
69 PrintAndLog(" can damage the tag");
71 PrintAndLog("Examples:");
72 PrintAndLog(" lf t55xx read b 0 - read data from block 0");
73 PrintAndLog(" lf t55xx read b 0 p feedbeef - read data from block 0 password feedbeef");
74 PrintAndLog(" lf t55xx read b 0 p feedbeef o - read data from block 0 password feedbeef safety check");
78 int usage_t55xx_write(){
79 PrintAndLog("Usage: lf t55xx wr [b <block>] [d <data>] [p <password>] [1]");
80 PrintAndLog("Options:");
81 PrintAndLog(" b <block> - block number to write. Between 0-7");
82 PrintAndLog(" d <data> - 4 bytes of data to write (8 hex characters)");
83 PrintAndLog(" p <password> - OPTIONAL password 4bytes (8 hex characters)");
84 PrintAndLog(" 1 - OPTIONAL write Page 1 instead of Page 0");
86 PrintAndLog("Examples:");
87 PrintAndLog(" lf t55xx write b 3 d 11223344 - write 11223344 to block 3");
88 PrintAndLog(" lf t55xx write b 3 d 11223344 p feedbeef - write 11223344 to block 3 password feedbeef");
92 int usage_t55xx_trace() {
93 PrintAndLog("Usage: lf t55xx trace [1]");
94 PrintAndLog("Options:");
95 PrintAndLog(" 1 - if set, use Graphbuffer otherwise read data from tag.");
97 PrintAndLog("Examples:");
98 PrintAndLog(" lf t55xx trace");
99 PrintAndLog(" lf t55xx trace 1");
103 int usage_t55xx_info() {
104 PrintAndLog("Usage: lf t55xx info [1]");
105 PrintAndLog("Options:");
106 PrintAndLog(" 1 - if set, use Graphbuffer otherwise read data from tag.");
108 PrintAndLog("Examples:");
109 PrintAndLog(" lf t55xx info");
110 PrintAndLog(" lf t55xx info 1");
114 int usage_t55xx_dump(){
115 PrintAndLog("Usage: lf t55xx dump <password> [o]");
116 PrintAndLog("Options:");
117 PrintAndLog(" <password> - OPTIONAL password 4bytes (8 hex symbols)");
118 PrintAndLog(" o - OPTIONAL override, force pwd read despite danger to card");
120 PrintAndLog("Examples:");
121 PrintAndLog(" lf t55xx dump");
122 PrintAndLog(" lf t55xx dump feedbeef o");
126 int usage_t55xx_detect(){
127 PrintAndLog("Usage: lf t55xx detect [1] [p <password>]");
128 PrintAndLog("Options:");
129 PrintAndLog(" 1 - if set, use Graphbuffer otherwise read data from tag.");
130 PrintAndLog(" p <password> - OPTIONAL password (8 hex characters)");
132 PrintAndLog("Examples:");
133 PrintAndLog(" lf t55xx detect");
134 PrintAndLog(" lf t55xx detect 1");
135 PrintAndLog(" lf t55xx detect p 11223344");
139 int usage_t55xx_wakup(){
140 PrintAndLog("Usage: lf t55xx wakeup [h] p <password>");
141 PrintAndLog("This commands send the Answer-On-Request command and leaves the readerfield ON afterwards.");
142 PrintAndLog("Options:");
143 PrintAndLog(" h - this help");
144 PrintAndLog(" p <password> - password 4bytes (8 hex symbols)");
146 PrintAndLog("Examples:");
147 PrintAndLog(" lf t55xx wakeup p 11223344 - send wakeup password");
150 int usage_t55xx_bruteforce(){
151 PrintAndLog("This command uses A) bruteforce to scan a number range");
152 PrintAndLog(" B) a dictionary attack");
153 PrintAndLog("press 'enter' to cancel the command");
154 PrintAndLog("Usage: lf t55xx bruteforce [h] <start password> <end password> [i <*.dic>]");
155 PrintAndLog(" password must be 4 bytes (8 hex symbols)");
156 PrintAndLog("Options:");
157 PrintAndLog(" h - this help");
158 PrintAndLog(" <start_pwd> - 4 byte hex value to start pwd search at");
159 PrintAndLog(" <end_pwd> - 4 byte hex value to end pwd search at");
160 PrintAndLog(" i <*.dic> - loads a default keys dictionary file <*.dic>");
162 PrintAndLog("Examples:");
163 PrintAndLog(" lf t55xx bruteforce aaaaaaaa bbbbbbbb");
164 PrintAndLog(" lf t55xx bruteforce i default_pwd.dic");
168 int usage_t55xx_recoverpw(){
169 PrintAndLog("This command uses a few tricks to try to recover mangled password");
170 PrintAndLog("press 'enter' to cancel the command");
171 PrintAndLog("WARNING: this may brick non-password protected chips!");
172 PrintAndLog("Usage: lf t55xx recoverpw [password]");
173 PrintAndLog(" password must be 4 bytes (8 hex symbols)");
174 PrintAndLog(" default password is 51243648, used by many cloners");
175 PrintAndLog("Options:");
176 PrintAndLog(" h - this help");
177 PrintAndLog(" [password] - 4 byte hex value of password written by cloner");
179 PrintAndLog("Examples:");
180 PrintAndLog(" lf t55xx recoverpw");
181 PrintAndLog(" lf t55xx recoverpw 51243648");
184 }int usage_t55xx_wipe(){
185 PrintAndLog("Usage: lf t55xx wipe [h] [Q5]");
186 PrintAndLog("This commands wipes a tag, fills blocks 1-7 with zeros and a default configuration block");
187 PrintAndLog("Options:");
188 PrintAndLog(" h - this help");
189 PrintAndLog(" Q5 - indicates to use the T5555 (Q5) default configuration block");
191 PrintAndLog("Examples:");
192 PrintAndLog(" lf t55xx wipe - wipes a t55x7 tag, config block 0x000880E0");
193 PrintAndLog(" lf t55xx wipe Q5 - wipes a t5555 Q5 tag, config block 0x6001F004");
196 static int CmdHelp(const char *Cmd
);
198 void printT5xxHeader(uint8_t page
){
199 PrintAndLog("Reading Page %d:", page
);
200 PrintAndLog("blk | hex data | binary | ascii");
201 PrintAndLog("----+----------+----------------------------------+-------");
204 int CmdT55xxSetConfig(const char *Cmd
) {
207 char modulation
[5] = {0x00};
210 uint8_t rates
[9] = {8,16,32,40,50,64,100,128,0};
213 while(param_getchar(Cmd
, cmdp
) != 0x00 && !errors
)
215 tmp
= param_getchar(Cmd
, cmdp
);
220 return usage_t55xx_config();
222 errors
|= param_getdec(Cmd
, cmdp
+1, &bitRate
);
226 if (rates
[i
]==bitRate
) {
231 if (i
==9) errors
= TRUE
;
236 param_getstr(Cmd
, cmdp
+1, modulation
);
239 if ( strcmp(modulation
, "FSK" ) == 0) {
240 config
.modulation
= DEMOD_FSK
;
241 } else if ( strcmp(modulation
, "FSK1" ) == 0) {
242 config
.modulation
= DEMOD_FSK1
;
244 } else if ( strcmp(modulation
, "FSK1a" ) == 0) {
245 config
.modulation
= DEMOD_FSK1a
;
247 } else if ( strcmp(modulation
, "FSK2" ) == 0) {
248 config
.modulation
= DEMOD_FSK2
;
250 } else if ( strcmp(modulation
, "FSK2a" ) == 0) {
251 config
.modulation
= DEMOD_FSK2a
;
253 } else if ( strcmp(modulation
, "ASK" ) == 0) {
254 config
.modulation
= DEMOD_ASK
;
255 } else if ( strcmp(modulation
, "NRZ" ) == 0) {
256 config
.modulation
= DEMOD_NRZ
;
257 } else if ( strcmp(modulation
, "PSK1" ) == 0) {
258 config
.modulation
= DEMOD_PSK1
;
259 } else if ( strcmp(modulation
, "PSK2" ) == 0) {
260 config
.modulation
= DEMOD_PSK2
;
261 } else if ( strcmp(modulation
, "PSK3" ) == 0) {
262 config
.modulation
= DEMOD_PSK3
;
263 } else if ( strcmp(modulation
, "BIa" ) == 0) {
264 config
.modulation
= DEMOD_BIa
;
266 } else if ( strcmp(modulation
, "BI" ) == 0) {
267 config
.modulation
= DEMOD_BI
;
270 PrintAndLog("Unknown modulation '%s'", modulation
);
275 config
.inverted
= param_getchar(Cmd
,cmdp
+1) == '1';
279 errors
|= param_getdec(Cmd
, cmdp
+1, &offset
);
281 config
.offset
= offset
;
295 PrintAndLog("Unknown parameter '%c'", param_getchar(Cmd
, cmdp
));
302 if (cmdp
== 0) return printConfiguration( config
);
305 if (errors
) return usage_t55xx_config();
308 return printConfiguration ( config
);
311 int T55xxReadBlock(uint8_t block
, bool page1
, bool usepwd
, bool override
, uint32_t password
){
314 // try reading the config block and verify that PWD bit is set before doing this!
317 if ( !AquireData(T55x7_PAGE0
, T55x7_CONFIGURATION_BLOCK
, false, 0 ) ) return 0;
319 if ( !tryDetectModulation() ) {
320 PrintAndLog("Safety Check: Could not detect if PWD bit is set in config block. Exits.");
323 PrintAndLog("Safety Check: PWD bit is NOT set in config block. Reading without password...");
328 PrintAndLog("Safety Check Overriden - proceeding despite risk");
332 if (!AquireData(page1
, block
, usepwd
, password
) ) return 0;
333 if (!DecodeT55xxBlock()) return 0;
336 sprintf(blk
,"%02d", block
);
337 printT55xxBlock(blk
);
341 int CmdT55xxReadBlock(const char *Cmd
) {
342 uint8_t block
= REGULAR_READ_MODE_BLOCK
;
343 uint32_t password
= 0; //default to blank Block 7
345 bool override
= false;
349 while(param_getchar(Cmd
, cmdp
) != 0x00 && !errors
) {
350 switch(param_getchar(Cmd
, cmdp
)) {
353 return usage_t55xx_read();
356 errors
|= param_getdec(Cmd
, cmdp
+1, &block
);
366 password
= param_get32ex(Cmd
, cmdp
+1, 0, 16);
375 PrintAndLog("Unknown parameter '%c'", param_getchar(Cmd
, cmdp
));
380 if (errors
) return usage_t55xx_read();
382 if (block
> 7 && block
!= REGULAR_READ_MODE_BLOCK
) {
383 PrintAndLog("Block must be between 0 and 7");
387 printT5xxHeader(page1
);
388 return T55xxReadBlock(block
, page1
, usepwd
, override
, password
);
391 bool DecodeT55xxBlock(){
393 char buf
[30] = {0x00};
397 uint8_t bitRate
[8] = {8,16,32,40,50,64,100,128};
398 DemodBufferLen
= 0x00;
400 switch( config
.modulation
){
402 snprintf(cmdStr
, sizeof(buf
),"%d %d", bitRate
[config
.bitrate
], config
.inverted
);
403 ans
= FSKrawDemod(cmdStr
, FALSE
);
407 snprintf(cmdStr
, sizeof(buf
),"%d %d 8 5", bitRate
[config
.bitrate
], config
.inverted
);
408 ans
= FSKrawDemod(cmdStr
, FALSE
);
412 snprintf(cmdStr
, sizeof(buf
),"%d %d 10 8", bitRate
[config
.bitrate
], config
.inverted
);
413 ans
= FSKrawDemod(cmdStr
, FALSE
);
416 snprintf(cmdStr
, sizeof(buf
),"%d %d 1", bitRate
[config
.bitrate
], config
.inverted
);
417 ans
= ASKDemod_ext(cmdStr
, FALSE
, FALSE
, 1, &ST
);
420 // skip first 160 samples to allow antenna to settle in (psk gets inverted occasionally otherwise)
423 snprintf(cmdStr
, sizeof(buf
),"%d %d 6", bitRate
[config
.bitrate
], config
.inverted
);
424 ans
= PSKDemod(cmdStr
, FALSE
);
428 case DEMOD_PSK2
: //inverted won't affect this
429 case DEMOD_PSK3
: //not fully implemented
430 // skip first 160 samples to allow antenna to settle in (psk gets inverted occasionally otherwise)
433 snprintf(cmdStr
, sizeof(buf
),"%d 0 6", bitRate
[config
.bitrate
] );
434 ans
= PSKDemod(cmdStr
, FALSE
);
435 psk1TOpsk2(DemodBuffer
, DemodBufferLen
);
440 snprintf(cmdStr
, sizeof(buf
),"%d %d 1", bitRate
[config
.bitrate
], config
.inverted
);
441 ans
= NRZrawDemod(cmdStr
, FALSE
);
445 snprintf(cmdStr
, sizeof(buf
),"0 %d %d 1", bitRate
[config
.bitrate
], config
.inverted
);
446 ans
= ASKbiphaseDemod(cmdStr
, FALSE
);
454 bool DecodeT5555TraceBlock() {
455 DemodBufferLen
= 0x00;
457 // According to datasheet. Always: RF/64, not inverted, Manchester
458 return (bool) ASKDemod("64 0 1", FALSE
, FALSE
, 1);
461 // sanity check. Don't use proxmark if it is offline and you didn't specify useGraphbuf
462 static int SanityOfflineCheck( bool useGraphBuffer
){
463 if ( !useGraphBuffer
&& offline
) {
464 PrintAndLog("Your proxmark3 device is offline. Specify [1] to use graphbuffer data instead");
470 int CmdT55xxDetect(const char *Cmd
){
474 uint32_t password
= 0;
477 while(param_getchar(Cmd
, cmdp
) != 0x00 && !errors
) {
478 switch(param_getchar(Cmd
, cmdp
)) {
481 return usage_t55xx_detect();
484 password
= param_get32ex(Cmd
, cmdp
+1, 0, 16);
489 // use Graphbuffer data
494 PrintAndLog("Unknown parameter '%c'", param_getchar(Cmd
, cmdp
));
499 if (errors
) return usage_t55xx_detect();
502 if (!SanityOfflineCheck(useGB
)) return 1;
505 if ( !AquireData(T55x7_PAGE0
, T55x7_CONFIGURATION_BLOCK
, usepwd
, password
) )
509 if ( !tryDetectModulation() )
510 PrintAndLog("Could not detect modulation automatically. Try setting it manually with \'lf t55xx config\'");
515 // detect configuration?
516 bool tryDetectModulation(){
518 t55xx_conf_block_t tests
[15];
520 uint8_t fc1
= 0, fc2
= 0, clk
=0;
522 if (GetFskClock("", FALSE
, FALSE
)){
523 fskClocks(&fc1
, &fc2
, &clk
, FALSE
);
524 if ( FSKrawDemod("0 0", FALSE
) && test(DEMOD_FSK
, &tests
[hits
].offset
, &bitRate
, clk
, &tests
[hits
].Q5
)){
525 tests
[hits
].modulation
= DEMOD_FSK
;
526 if (fc1
==8 && fc2
== 5)
527 tests
[hits
].modulation
= DEMOD_FSK1a
;
528 else if (fc1
==10 && fc2
== 8)
529 tests
[hits
].modulation
= DEMOD_FSK2
;
530 tests
[hits
].bitrate
= bitRate
;
531 tests
[hits
].inverted
= FALSE
;
532 tests
[hits
].block0
= PackBits(tests
[hits
].offset
, 32, DemodBuffer
);
533 tests
[hits
].ST
= FALSE
;
536 if ( FSKrawDemod("0 1", FALSE
) && test(DEMOD_FSK
, &tests
[hits
].offset
, &bitRate
, clk
, &tests
[hits
].Q5
)) {
537 tests
[hits
].modulation
= DEMOD_FSK
;
538 if (fc1
== 8 && fc2
== 5)
539 tests
[hits
].modulation
= DEMOD_FSK1
;
540 else if (fc1
== 10 && fc2
== 8)
541 tests
[hits
].modulation
= DEMOD_FSK2a
;
542 tests
[hits
].bitrate
= bitRate
;
543 tests
[hits
].inverted
= TRUE
;
544 tests
[hits
].block0
= PackBits(tests
[hits
].offset
, 32, DemodBuffer
);
545 tests
[hits
].ST
= FALSE
;
549 clk
= GetAskClock("", FALSE
, FALSE
);
551 tests
[hits
].ST
= TRUE
;
552 // "0 0 1 " == clock auto, invert false, maxError 1.
553 // false = no verbose
554 // false = no emSearch
557 if ( ASKDemod_ext("0 0 1", FALSE
, FALSE
, 1, &tests
[hits
].ST
) && test(DEMOD_ASK
, &tests
[hits
].offset
, &bitRate
, clk
, &tests
[hits
].Q5
)) {
558 tests
[hits
].modulation
= DEMOD_ASK
;
559 tests
[hits
].bitrate
= bitRate
;
560 tests
[hits
].inverted
= FALSE
;
561 tests
[hits
].block0
= PackBits(tests
[hits
].offset
, 32, DemodBuffer
);
564 tests
[hits
].ST
= TRUE
;
565 // "0 0 1 " == clock auto, invert true, maxError 1.
566 // false = no verbose
567 // false = no emSearch
570 if ( ASKDemod_ext("0 1 1", FALSE
, FALSE
, 1, &tests
[hits
].ST
) && test(DEMOD_ASK
, &tests
[hits
].offset
, &bitRate
, clk
, &tests
[hits
].Q5
)) {
571 tests
[hits
].modulation
= DEMOD_ASK
;
572 tests
[hits
].bitrate
= bitRate
;
573 tests
[hits
].inverted
= TRUE
;
574 tests
[hits
].block0
= PackBits(tests
[hits
].offset
, 32, DemodBuffer
);
577 if ( ASKbiphaseDemod("0 0 0 2", FALSE
) && test(DEMOD_BI
, &tests
[hits
].offset
, &bitRate
, clk
, &tests
[hits
].Q5
) ) {
578 tests
[hits
].modulation
= DEMOD_BI
;
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
;
585 if ( ASKbiphaseDemod("0 0 1 2", FALSE
) && test(DEMOD_BIa
, &tests
[hits
].offset
, &bitRate
, clk
, &tests
[hits
].Q5
) ) {
586 tests
[hits
].modulation
= DEMOD_BIa
;
587 tests
[hits
].bitrate
= bitRate
;
588 tests
[hits
].inverted
= TRUE
;
589 tests
[hits
].block0
= PackBits(tests
[hits
].offset
, 32, DemodBuffer
);
590 tests
[hits
].ST
= FALSE
;
596 clk
= GetNrzClock("", FALSE
, FALSE
);
598 if ( NRZrawDemod("0 0 1", FALSE
) && test(DEMOD_NRZ
, &tests
[hits
].offset
, &bitRate
, clk
, &tests
[hits
].Q5
)) {
599 tests
[hits
].modulation
= DEMOD_NRZ
;
600 tests
[hits
].bitrate
= bitRate
;
601 tests
[hits
].inverted
= FALSE
;
602 tests
[hits
].block0
= PackBits(tests
[hits
].offset
, 32, DemodBuffer
);
603 tests
[hits
].ST
= FALSE
;
607 if ( NRZrawDemod("0 1 1", FALSE
) && test(DEMOD_NRZ
, &tests
[hits
].offset
, &bitRate
, clk
, &tests
[hits
].Q5
)) {
608 tests
[hits
].modulation
= DEMOD_NRZ
;
609 tests
[hits
].bitrate
= bitRate
;
610 tests
[hits
].inverted
= TRUE
;
611 tests
[hits
].block0
= PackBits(tests
[hits
].offset
, 32, DemodBuffer
);
612 tests
[hits
].ST
= FALSE
;
618 // skip first 160 samples to allow antenna to settle in (psk gets inverted occasionally otherwise)
621 clk
= GetPskClock("", FALSE
, FALSE
);
623 if ( PSKDemod("0 0 6", FALSE
) && test(DEMOD_PSK1
, &tests
[hits
].offset
, &bitRate
, clk
, &tests
[hits
].Q5
)) {
624 tests
[hits
].modulation
= DEMOD_PSK1
;
625 tests
[hits
].bitrate
= bitRate
;
626 tests
[hits
].inverted
= FALSE
;
627 tests
[hits
].block0
= PackBits(tests
[hits
].offset
, 32, DemodBuffer
);
628 tests
[hits
].ST
= FALSE
;
631 if ( PSKDemod("0 1 6", FALSE
) && test(DEMOD_PSK1
, &tests
[hits
].offset
, &bitRate
, clk
, &tests
[hits
].Q5
)) {
632 tests
[hits
].modulation
= DEMOD_PSK1
;
633 tests
[hits
].bitrate
= bitRate
;
634 tests
[hits
].inverted
= TRUE
;
635 tests
[hits
].block0
= PackBits(tests
[hits
].offset
, 32, DemodBuffer
);
636 tests
[hits
].ST
= FALSE
;
639 // PSK2 - needs a call to psk1TOpsk2.
640 if ( PSKDemod("0 0 6", FALSE
)) {
641 psk1TOpsk2(DemodBuffer
, DemodBufferLen
);
642 if (test(DEMOD_PSK2
, &tests
[hits
].offset
, &bitRate
, clk
, &tests
[hits
].Q5
)){
643 tests
[hits
].modulation
= DEMOD_PSK2
;
644 tests
[hits
].bitrate
= bitRate
;
645 tests
[hits
].inverted
= FALSE
;
646 tests
[hits
].block0
= PackBits(tests
[hits
].offset
, 32, DemodBuffer
);
647 tests
[hits
].ST
= FALSE
;
650 } // inverse waves does not affect this demod
651 // PSK3 - needs a call to psk1TOpsk2.
652 if ( PSKDemod("0 0 6", FALSE
)) {
653 psk1TOpsk2(DemodBuffer
, DemodBufferLen
);
654 if (test(DEMOD_PSK3
, &tests
[hits
].offset
, &bitRate
, clk
, &tests
[hits
].Q5
)){
655 tests
[hits
].modulation
= DEMOD_PSK3
;
656 tests
[hits
].bitrate
= bitRate
;
657 tests
[hits
].inverted
= FALSE
;
658 tests
[hits
].block0
= PackBits(tests
[hits
].offset
, 32, DemodBuffer
);
659 tests
[hits
].ST
= FALSE
;
662 } // inverse waves does not affect this demod
668 config
.modulation
= tests
[0].modulation
;
669 config
.bitrate
= tests
[0].bitrate
;
670 config
.inverted
= tests
[0].inverted
;
671 config
.offset
= tests
[0].offset
;
672 config
.block0
= tests
[0].block0
;
673 config
.Q5
= tests
[0].Q5
;
674 config
.ST
= tests
[0].ST
;
675 printConfiguration( config
);
681 PrintAndLog("Found [%d] possible matches for modulation.",hits
);
682 for(int i
=0; i
<hits
; ++i
){
683 retval
= testKnownConfigBlock(tests
[i
].block0
);
685 PrintAndLog("--[%d]--------------- << selected this", i
+1);
686 config
.modulation
= tests
[i
].modulation
;
687 config
.bitrate
= tests
[i
].bitrate
;
688 config
.inverted
= tests
[i
].inverted
;
689 config
.offset
= tests
[i
].offset
;
690 config
.block0
= tests
[i
].block0
;
691 config
.Q5
= tests
[i
].Q5
;
692 config
.ST
= tests
[i
].ST
;
694 PrintAndLog("--[%d]---------------", i
+1);
696 printConfiguration( tests
[i
] );
702 bool testKnownConfigBlock(uint32_t block0
) {
704 case T55X7_DEFAULT_CONFIG_BLOCK
:
705 case T55X7_RAW_CONFIG_BLOCK
:
706 case T55X7_EM_UNIQUE_CONFIG_BLOCK
:
707 case T55X7_FDXB_CONFIG_BLOCK
:
708 case T55X7_HID_26_CONFIG_BLOCK
:
709 case T55X7_PYRAMID_CONFIG_BLOCK
:
710 case T55X7_INDALA_64_CONFIG_BLOCK
:
711 case T55X7_INDALA_224_CONFIG_BLOCK
:
712 case T55X7_GUARDPROXII_CONFIG_BLOCK
:
713 case T55X7_VIKING_CONFIG_BLOCK
:
714 case T55X7_NORALYS_CONFIG_BLOCK
:
715 case T55X7_IOPROX_CONFIG_BLOCK
:
716 case T55X7_PRESCO_CONFIG_BLOCK
:
722 bool testModulation(uint8_t mode
, uint8_t modread
){
725 if (modread
>= DEMOD_FSK1
&& modread
<= DEMOD_FSK2a
) return TRUE
;
728 if (modread
== DEMOD_ASK
) return TRUE
;
731 if (modread
== DEMOD_PSK1
) return TRUE
;
734 if (modread
== DEMOD_PSK2
) return TRUE
;
737 if (modread
== DEMOD_PSK3
) return TRUE
;
740 if (modread
== DEMOD_NRZ
) return TRUE
;
743 if (modread
== DEMOD_BI
) return TRUE
;
746 if (modread
== DEMOD_BIa
) return TRUE
;
754 bool testQ5Modulation(uint8_t mode
, uint8_t modread
){
757 if (modread
>= 4 && modread
<= 5) return TRUE
;
760 if (modread
== 0) return TRUE
;
763 if (modread
== 1) return TRUE
;
766 if (modread
== 2) return TRUE
;
769 if (modread
== 3) return TRUE
;
772 if (modread
== 7) return TRUE
;
775 if (modread
== 6) return TRUE
;
783 int convertQ5bitRate(uint8_t bitRateRead
) {
784 uint8_t expected
[] = {8, 16, 32, 40, 50, 64, 100, 128};
785 for (int i
=0; i
<8; i
++)
786 if (expected
[i
] == bitRateRead
)
792 bool testQ5(uint8_t mode
, uint8_t *offset
, int *fndBitRate
, uint8_t clk
){
794 if ( DemodBufferLen
< 64 ) return FALSE
;
796 for (uint8_t idx
= 28; idx
< 64; idx
++){
798 if ( PackBits(si
, 28, DemodBuffer
) == 0x00 ) continue;
800 uint8_t safer
= PackBits(si
, 4, DemodBuffer
); si
+= 4; //master key
801 uint8_t resv
= PackBits(si
, 8, DemodBuffer
); si
+= 8;
802 // 2nibble must be zeroed.
803 if (safer
!= 0x6 && safer
!= 0x9) continue;
804 if ( resv
> 0x00) continue;
805 //uint8_t pageSel = PackBits(si, 1, DemodBuffer); si += 1;
806 //uint8_t fastWrite = PackBits(si, 1, DemodBuffer); si += 1;
808 int bitRate
= PackBits(si
, 6, DemodBuffer
)*2 + 2; si
+= 6; //bit rate
809 if (bitRate
> 128 || bitRate
< 8) continue;
811 //uint8_t AOR = PackBits(si, 1, DemodBuffer); si += 1;
812 //uint8_t PWD = PackBits(si, 1, DemodBuffer); si += 1;
813 //uint8_t pskcr = PackBits(si, 2, DemodBuffer); si += 2; //could check psk cr
814 //uint8_t inverse = PackBits(si, 1, DemodBuffer); si += 1;
816 uint8_t modread
= PackBits(si
, 3, DemodBuffer
); si
+= 3;
817 uint8_t maxBlk
= PackBits(si
, 3, DemodBuffer
); si
+= 3;
818 //uint8_t ST = PackBits(si, 1, DemodBuffer); si += 1;
819 if (maxBlk
== 0) continue;
821 if (!testQ5Modulation(mode
, modread
)) continue;
822 if (bitRate
!= clk
) continue;
823 *fndBitRate
= convertQ5bitRate(bitRate
);
824 if (*fndBitRate
< 0) continue;
832 bool testBitRate(uint8_t readRate
, uint8_t clk
){
833 uint8_t expected
[] = {8, 16, 32, 40, 50, 64, 100, 128};
834 if (expected
[readRate
] == clk
)
840 bool test(uint8_t mode
, uint8_t *offset
, int *fndBitRate
, uint8_t clk
, bool *Q5
){
842 if ( DemodBufferLen
< 64 ) return FALSE
;
844 for (uint8_t idx
= 28; idx
< 64; idx
++){
846 if ( PackBits(si
, 28, DemodBuffer
) == 0x00 ) continue;
848 uint8_t safer
= PackBits(si
, 4, DemodBuffer
); si
+= 4; //master key
849 uint8_t resv
= PackBits(si
, 4, DemodBuffer
); si
+= 4; //was 7 & +=7+3 //should be only 4 bits if extended mode
850 // 2nibble must be zeroed.
851 // moved test to here, since this gets most faults first.
852 if ( resv
> 0x00) continue;
854 uint8_t xtRate
= PackBits(si
, 3, DemodBuffer
); si
+= 3; //extended mode part of rate
855 int bitRate
= PackBits(si
, 3, DemodBuffer
); si
+= 3; //bit rate
856 if (bitRate
> 7) continue;
857 uint8_t extend
= PackBits(si
, 1, DemodBuffer
); si
+= 1; //bit 15 extended mode
858 uint8_t modread
= PackBits(si
, 5, DemodBuffer
); si
+= 5+2+1;
859 //uint8_t pskcr = PackBits(si, 2, DemodBuffer); si += 2+1; //could check psk cr
860 //uint8_t nml01 = PackBits(si, 1, DemodBuffer); si += 1+5; //bit 24, 30, 31 could be tested for 0 if not extended mode
861 //uint8_t nml02 = PackBits(si, 2, DemodBuffer); si += 2;
864 bool extMode
=( (safer
== 0x6 || safer
== 0x9) && extend
) ? TRUE
: FALSE
;
867 if (xtRate
) continue; //nml01 || nml02 || caused issues on noralys tags
870 if (!testModulation(mode
, modread
)) continue;
871 if (!testBitRate(bitRate
, clk
)) continue;
872 *fndBitRate
= bitRate
;
877 if (testQ5(mode
, offset
, fndBitRate
, clk
)) {
884 void printT55xxBlock(const char *blockNum
){
886 uint8_t i
= config
.offset
;
887 uint8_t endpos
= 32 + i
;
888 uint32_t blockData
= 0;
889 uint8_t bits
[64] = {0x00};
891 if ( !DemodBufferLen
) return;
893 if ( endpos
> DemodBufferLen
){
894 PrintAndLog("The configured offset %d is too big. Possible offset: %d)", i
, DemodBufferLen
-32);
898 for (; i
< endpos
; ++i
)
899 bits
[i
- config
.offset
] = DemodBuffer
[i
];
901 blockData
= PackBits(0, 32, bits
);
902 uint8_t bytes
[4] = {0};
903 num_to_bytes(blockData
, 4, bytes
);
905 PrintAndLog(" %s | %08X | %s | %s", blockNum
, blockData
, sprint_bin(bits
,32), sprint_ascii(bytes
,4));
908 int special(const char *Cmd
) {
909 uint32_t blockData
= 0;
910 uint8_t bits
[32] = {0x00};
912 PrintAndLog("OFFSET | DATA | BINARY | ASCII");
913 PrintAndLog("-------+-------+-------------------------------------+------");
917 for (i
= 0; i
< 32; ++i
)
918 bits
[i
]=DemodBuffer
[j
+i
];
920 blockData
= PackBits(0, 32, bits
);
922 PrintAndLog("%02d | 0x%08X | %s",j
, blockData
, sprint_bin(bits
,32));
927 int printConfiguration( t55xx_conf_block_t b
){
928 PrintAndLog("Chip Type : %s", (b
.Q5
) ? "T5555(Q5)" : "T55x7");
929 PrintAndLog("Modulation : %s", GetSelectedModulationStr(b
.modulation
) );
930 PrintAndLog("Bit Rate : %s", GetBitRateStr(b
.bitrate
) );
931 PrintAndLog("Inverted : %s", (b
.inverted
) ? "Yes" : "No" );
932 PrintAndLog("Offset : %d", b
.offset
);
933 PrintAndLog("Seq. Term. : %s", (b
.ST
) ? "Yes" : "No" );
934 PrintAndLog("Block0 : 0x%08X", b
.block0
);
939 int CmdT55xxWakeUp(const char *Cmd
) {
940 uint32_t password
= 0;
943 while(param_getchar(Cmd
, cmdp
) != 0x00 && !errors
) {
944 switch(param_getchar(Cmd
, cmdp
)) {
947 return usage_t55xx_wakup();
950 password
= param_get32ex(Cmd
, cmdp
+1, 0, 16);
955 PrintAndLog("Unknown parameter '%c'", param_getchar(Cmd
, cmdp
));
960 if (errors
) return usage_t55xx_wakup();
962 UsbCommand c
= {CMD_T55XX_WAKEUP
, {password
, 0, 0}};
963 clearCommandBuffer();
965 PrintAndLog("Wake up command sent. Try read now");
969 int CmdT55xxWriteBlock(const char *Cmd
) {
970 uint8_t block
= 0xFF; //default to invalid block
971 uint32_t data
= 0; //default to blank Block
972 uint32_t password
= 0; //default to blank Block 7
975 bool gotdata
= false;
978 while(param_getchar(Cmd
, cmdp
) != 0x00 && !errors
) {
979 switch(param_getchar(Cmd
, cmdp
)) {
982 return usage_t55xx_write();
985 errors
|= param_getdec(Cmd
, cmdp
+1, &block
);
990 data
= param_get32ex(Cmd
, cmdp
+1, 0, 16);
996 password
= param_get32ex(Cmd
, cmdp
+1, 0, 16);
1005 PrintAndLog("Unknown parameter '%c'", param_getchar(Cmd
, cmdp
));
1010 if (errors
|| !gotdata
) return usage_t55xx_write();
1013 PrintAndLog("Block number must be between 0 and 7");
1017 UsbCommand c
= {CMD_T55XX_WRITE_BLOCK
, {data
, block
, 0}};
1019 c
.d
.asBytes
[0] = (page1
) ? 0x2 : 0;
1021 char pwdStr
[16] = {0};
1022 snprintf(pwdStr
, sizeof(pwdStr
), "pwd: 0x%08X", password
);
1024 PrintAndLog("Writing page %d block: %02d data: 0x%08X %s", page1
, block
, data
, (usepwd
) ? pwdStr
: "" );
1028 c
.arg
[2] = password
;
1029 c
.d
.asBytes
[0] |= 0x1;
1031 clearCommandBuffer();
1033 if (!WaitForResponseTimeout(CMD_ACK
, &resp
, 1500)){
1034 PrintAndLog("Error occurred, device did not ACK write operation. (May be due to old firmware)");
1040 int CmdT55xxReadTrace(const char *Cmd
) {
1041 char cmdp
= param_getchar(Cmd
, 0);
1042 bool pwdmode
= false;
1043 uint32_t password
= 0;
1044 if (strlen(Cmd
) > 1 || cmdp
== 'h' || cmdp
== 'H') return usage_t55xx_trace();
1046 if (strlen(Cmd
)==0) {
1048 if (!SanityOfflineCheck(FALSE
)) return 1;
1050 if ( !AquireData( T55x7_PAGE1
, REGULAR_READ_MODE_BLOCK
, pwdmode
, password
) )
1055 if (!DecodeT5555TraceBlock()) return 1;
1057 if (!DecodeT55xxBlock()) return 1;
1060 if ( !DemodBufferLen
) return 1;
1062 RepaintGraphWindow();
1063 uint8_t repeat
= (config
.offset
> 5) ? 32 : 0;
1065 uint8_t si
= config
.offset
+ repeat
;
1066 uint32_t bl1
= PackBits(si
, 32, DemodBuffer
);
1067 uint32_t bl2
= PackBits(si
+32, 32, DemodBuffer
);
1070 uint32_t hdr
= PackBits(si
, 9, DemodBuffer
); si
+= 9;
1073 PrintAndLog("Invalid Q5 Trace data header (expected 0x1FF, found %X)", hdr
);
1077 t5555_tracedata_t data
= {.bl1
= bl1
, .bl2
= bl2
, .icr
= 0, .lotidc
= '?', .lotid
= 0, .wafer
= 0, .dw
=0};
1079 data
.icr
= PackBits(si
, 2, DemodBuffer
); si
+= 2;
1080 data
.lotidc
= 'Z' - PackBits(si
, 2, DemodBuffer
); si
+= 3;
1082 data
.lotid
= PackBits(si
, 4, DemodBuffer
); si
+= 5;
1084 data
.lotid
|= PackBits(si
, 4, DemodBuffer
); si
+= 5;
1086 data
.lotid
|= PackBits(si
, 4, DemodBuffer
); si
+= 5;
1088 data
.lotid
|= PackBits(si
, 4, DemodBuffer
); si
+= 5;
1090 data
.lotid
|= PackBits(si
, 1, DemodBuffer
); si
+= 1;
1092 data
.wafer
= PackBits(si
, 3, DemodBuffer
); si
+= 4;
1094 data
.wafer
|= PackBits(si
, 2, DemodBuffer
); si
+= 2;
1096 data
.dw
= PackBits(si
, 2, DemodBuffer
); si
+= 3;
1098 data
.dw
|= PackBits(si
, 4, DemodBuffer
); si
+= 5;
1100 data
.dw
|= PackBits(si
, 4, DemodBuffer
); si
+= 5;
1102 data
.dw
|= PackBits(si
, 4, DemodBuffer
); si
+= 5;
1104 printT5555Trace(data
, repeat
);
1108 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};
1110 data
.acl
= PackBits(si
, 8, DemodBuffer
); si
+= 8;
1111 if ( data
.acl
!= 0xE0 ) {
1112 PrintAndLog("The modulation is most likely wrong since the ACL is not 0xE0. ");
1116 data
.mfc
= PackBits(si
, 8, DemodBuffer
); si
+= 8;
1117 data
.cid
= PackBits(si
, 5, DemodBuffer
); si
+= 5;
1118 data
.icr
= PackBits(si
, 3, DemodBuffer
); si
+= 3;
1119 data
.year
= PackBits(si
, 4, DemodBuffer
); si
+= 4;
1120 data
.quarter
= PackBits(si
, 2, DemodBuffer
); si
+= 2;
1121 data
.lotid
= PackBits(si
, 14, DemodBuffer
); si
+= 14;
1122 data
.wafer
= PackBits(si
, 5, DemodBuffer
); si
+= 5;
1123 data
.dw
= PackBits(si
, 15, DemodBuffer
);
1125 time_t t
= time(NULL
);
1126 struct tm tm
= *localtime(&t
);
1127 if ( data
.year
> tm
.tm_year
-110)
1132 printT55x7Trace(data
, repeat
);
1137 void printT55x7Trace( t55x7_tracedata_t data
, uint8_t repeat
){
1138 PrintAndLog("-- T55x7 Trace Information ----------------------------------");
1139 PrintAndLog("-------------------------------------------------------------");
1140 PrintAndLog(" ACL Allocation class (ISO/IEC 15963-1) : 0x%02X (%d)", data
.acl
, data
.acl
);
1141 PrintAndLog(" MFC Manufacturer ID (ISO/IEC 7816-6) : 0x%02X (%d) - %s", data
.mfc
, data
.mfc
, getTagInfo(data
.mfc
));
1142 PrintAndLog(" CID : 0x%02X (%d) - %s", data
.cid
, data
.cid
, GetModelStrFromCID(data
.cid
));
1143 PrintAndLog(" ICR IC Revision : %d", data
.icr
);
1144 PrintAndLog(" Manufactured");
1145 PrintAndLog(" Year/Quarter : %d/%d", data
.year
, data
.quarter
);
1146 PrintAndLog(" Lot ID : %d", data
.lotid
);
1147 PrintAndLog(" Wafer number : %d", data
.wafer
);
1148 PrintAndLog(" Die Number : %d", data
.dw
);
1149 PrintAndLog("-------------------------------------------------------------");
1150 PrintAndLog(" Raw Data - Page 1");
1151 PrintAndLog(" Block 1 : 0x%08X %s", data
.bl1
, sprint_bin(DemodBuffer
+config
.offset
+repeat
,32) );
1152 PrintAndLog(" Block 2 : 0x%08X %s", data
.bl2
, sprint_bin(DemodBuffer
+config
.offset
+repeat
+32,32) );
1153 PrintAndLog("-------------------------------------------------------------");
1158 1-8 ACL Allocation class (ISO/IEC 15963-1) 0xE0
1159 9-16 MFC Manufacturer ID (ISO/IEC 7816-6) 0x15 Atmel Corporation
1160 17-21 CID 0x1 = Atmel ATA5577M1 0x2 = Atmel ATA5577M2
1161 22-24 ICR IC revision
1162 25-28 YEAR (BCD encoded) 9 (= 2009)
1163 29-30 QUARTER 1,2,3,4
1169 18-32 DW, die number sequential
1173 void printT5555Trace( t5555_tracedata_t data
, uint8_t repeat
){
1174 PrintAndLog("-- T5555 (Q5) Trace Information -----------------------------");
1175 PrintAndLog("-------------------------------------------------------------");
1176 PrintAndLog(" ICR IC Revision : %d", data
.icr
);
1177 PrintAndLog(" Lot : %c%d", data
.lotidc
, data
.lotid
);
1178 PrintAndLog(" Wafer number : %d", data
.wafer
);
1179 PrintAndLog(" Die Number : %d", data
.dw
);
1180 PrintAndLog("-------------------------------------------------------------");
1181 PrintAndLog(" Raw Data - Page 1");
1182 PrintAndLog(" Block 1 : 0x%08X %s", data
.bl1
, sprint_bin(DemodBuffer
+config
.offset
+repeat
,32) );
1183 PrintAndLog(" Block 2 : 0x%08X %s", data
.bl2
, sprint_bin(DemodBuffer
+config
.offset
+repeat
+32,32) );
1187 TRACE - BLOCK O and BLOCK1
1192 15-35 Lot ID (NB parity)
1193 36-41 Wafer number (NB parity)
1194 42-58 DW, die number sequential (NB parity)
1200 //need to add Q5 info...
1201 int CmdT55xxInfo(const char *Cmd
){
1203 Page 0 Block 0 Configuration data.
1207 bool pwdmode
= false;
1208 uint32_t password
= 0;
1209 char cmdp
= param_getchar(Cmd
, 0);
1211 if (strlen(Cmd
) > 1 || cmdp
== 'h' || cmdp
== 'H') return usage_t55xx_info();
1213 if (strlen(Cmd
)==0){
1215 if (!SanityOfflineCheck(FALSE
)) return 1;
1217 if ( !AquireData( T55x7_PAGE0
, T55x7_CONFIGURATION_BLOCK
, pwdmode
, password
) )
1221 if (!DecodeT55xxBlock()) return 1;
1223 // too little space to start with
1224 if ( DemodBufferLen
< 32) return 1;
1227 PrintAndLog("Offset+32 ==%d\n DemodLen == %d", config
.offset
+ 32,DemodBufferLen
);
1229 uint8_t si
= config
.offset
;
1230 uint32_t bl0
= PackBits(si
, 32, DemodBuffer
);
1231 uint32_t safer
= PackBits(si
, 4, DemodBuffer
); si
+= 4;
1232 uint32_t resv
= PackBits(si
, 7, DemodBuffer
); si
+= 7;
1233 uint32_t dbr
= PackBits(si
, 3, DemodBuffer
); si
+= 3;
1234 uint32_t extend
= PackBits(si
, 1, DemodBuffer
); si
+= 1;
1235 uint32_t datamod
= PackBits(si
, 5, DemodBuffer
); si
+= 5;
1236 uint32_t pskcf
= PackBits(si
, 2, DemodBuffer
); si
+= 2;
1237 uint32_t aor
= PackBits(si
, 1, DemodBuffer
); si
+= 1;
1238 uint32_t otp
= PackBits(si
, 1, DemodBuffer
); si
+= 1;
1239 uint32_t maxblk
= PackBits(si
, 3, DemodBuffer
); si
+= 3;
1240 uint32_t pwd
= PackBits(si
, 1, DemodBuffer
); si
+= 1;
1241 uint32_t sst
= PackBits(si
, 1, DemodBuffer
); si
+= 1;
1242 uint32_t fw
= PackBits(si
, 1, DemodBuffer
); si
+= 1;
1243 uint32_t inv
= PackBits(si
, 1, DemodBuffer
); si
+= 1;
1244 uint32_t por
= PackBits(si
, 1, DemodBuffer
); si
+= 1;
1246 if (config
.Q5
) PrintAndLog("*** Warning *** Config Info read off a Q5 will not display as expected");
1248 PrintAndLog("-- T55x7 Configuration & Tag Information --------------------");
1249 PrintAndLog("-------------------------------------------------------------");
1250 PrintAndLog(" Safer key : %s", GetSaferStr(safer
));
1251 PrintAndLog(" reserved : %d", resv
);
1252 PrintAndLog(" Data bit rate : %s", GetBitRateStr(dbr
));
1253 PrintAndLog(" eXtended mode : %s", (extend
) ? "Yes - Warning":"No");
1254 PrintAndLog(" Modulation : %s", GetModulationStr(datamod
));
1255 PrintAndLog(" PSK clock frequency : %d", pskcf
);
1256 PrintAndLog(" AOR - Answer on Request : %s", (aor
) ? "Yes":"No");
1257 PrintAndLog(" OTP - One Time Pad : %s", (otp
) ? "Yes - Warning":"No" );
1258 PrintAndLog(" Max block : %d", maxblk
);
1259 PrintAndLog(" Password mode : %s", (pwd
) ? "Yes":"No");
1260 PrintAndLog(" Sequence Start Terminator : %s", (sst
) ? "Yes":"No");
1261 PrintAndLog(" Fast Write : %s", (fw
) ? "Yes":"No");
1262 PrintAndLog(" Inverse data : %s", (inv
) ? "Yes":"No");
1263 PrintAndLog(" POR-Delay : %s", (por
) ? "Yes":"No");
1264 PrintAndLog("-------------------------------------------------------------");
1265 PrintAndLog(" Raw Data - Page 0");
1266 PrintAndLog(" Block 0 : 0x%08X %s", bl0
, sprint_bin(DemodBuffer
+config
.offset
,32) );
1267 PrintAndLog("-------------------------------------------------------------");
1272 int CmdT55xxDump(const char *Cmd
){
1274 uint32_t password
= 0;
1275 bool override
= false;
1276 char cmdp
= param_getchar(Cmd
, 0);
1277 if ( cmdp
== 'h' || cmdp
== 'H') return usage_t55xx_dump();
1279 bool usepwd
= ( strlen(Cmd
) > 0);
1281 password
= param_get32ex(Cmd
, 0, 0, 16);
1282 if (param_getchar(Cmd
, 1) =='o' )
1287 for ( uint8_t i
= 0; i
< 8; ++i
)
1288 T55xxReadBlock(i
, 0, usepwd
, override
, password
);
1291 for ( uint8_t i
= 0; i
< 4; i
++)
1292 T55xxReadBlock(i
, 1, usepwd
, override
, password
);
1297 int AquireData( uint8_t page
, uint8_t block
, bool pwdmode
, uint32_t password
){
1300 // bit1 = page to read from
1301 // arg1: which block to read
1303 uint8_t arg0
= (page
<<1) | pwdmode
;
1304 UsbCommand c
= {CMD_T55XX_READ_BLOCK
, {arg0
, block
, password
}};
1305 clearCommandBuffer();
1307 if ( !WaitForResponseTimeout(CMD_ACK
, NULL
, 2500) ) {
1308 PrintAndLog("command execution time out");
1312 //uint8_t got[12288];
1314 GetFromBigBuf(got
, sizeof(got
), 0);
1315 if ( !WaitForResponseTimeout(CMD_ACK
, NULL
, 8000) ) {
1316 PrintAndLog("command execution time out");
1319 setGraphBuf(got
, sizeof(got
));
1323 char * GetBitRateStr(uint32_t id
){
1324 static char buf
[25];
1328 case 0: snprintf(retStr
,sizeof(buf
),"%d - RF/8",id
); break;
1329 case 1: snprintf(retStr
,sizeof(buf
),"%d - RF/16",id
); break;
1330 case 2: snprintf(retStr
,sizeof(buf
),"%d - RF/32",id
); break;
1331 case 3: snprintf(retStr
,sizeof(buf
),"%d - RF/40",id
); break;
1332 case 4: snprintf(retStr
,sizeof(buf
),"%d - RF/50",id
); break;
1333 case 5: snprintf(retStr
,sizeof(buf
),"%d - RF/64",id
); break;
1334 case 6: snprintf(retStr
,sizeof(buf
),"%d - RF/100",id
); break;
1335 case 7: snprintf(retStr
,sizeof(buf
),"%d - RF/128",id
); break;
1336 default: snprintf(retStr
,sizeof(buf
),"%d - (Unknown)",id
); break;
1341 char * GetSaferStr(uint32_t id
){
1342 static char buf
[40];
1345 snprintf(retStr
,sizeof(buf
),"%d",id
);
1347 snprintf(retStr
,sizeof(buf
),"%d - passwd",id
);
1350 snprintf(retStr
,sizeof(buf
),"%d - testmode",id
);
1356 char * GetModulationStr( uint32_t id
){
1357 static char buf
[60];
1361 case 0: snprintf(retStr
,sizeof(buf
),"%d - DIRECT (ASK/NRZ)",id
); break;
1362 case 1: snprintf(retStr
,sizeof(buf
),"%d - PSK 1 phase change when input changes",id
); break;
1363 case 2: snprintf(retStr
,sizeof(buf
),"%d - PSK 2 phase change on bitclk if input high",id
); break;
1364 case 3: snprintf(retStr
,sizeof(buf
),"%d - PSK 3 phase change on rising edge of input",id
); break;
1365 case 4: snprintf(retStr
,sizeof(buf
),"%d - FSK 1 RF/8 RF/5",id
); break;
1366 case 5: snprintf(retStr
,sizeof(buf
),"%d - FSK 2 RF/8 RF/10",id
); break;
1367 case 6: snprintf(retStr
,sizeof(buf
),"%d - FSK 1a RF/5 RF/8",id
); break;
1368 case 7: snprintf(retStr
,sizeof(buf
),"%d - FSK 2a RF/10 RF/8",id
); break;
1369 case 8: snprintf(retStr
,sizeof(buf
),"%d - Manchester",id
); break;
1370 case 16: snprintf(retStr
,sizeof(buf
),"%d - Biphase",id
); break;
1371 case 0x18:snprintf(retStr
,sizeof(buf
),"%d - Biphase a - AKA Conditional Dephase Encoding(CDP)",id
); break;
1372 case 17: snprintf(retStr
,sizeof(buf
),"%d - Reserved",id
); break;
1373 default: snprintf(retStr
,sizeof(buf
),"0x%02X (Unknown)",id
); break;
1378 char * GetModelStrFromCID(uint32_t cid
){
1380 static char buf
[10];
1383 if (cid
== 1) snprintf(retStr
, sizeof(buf
),"ATA5577M1");
1384 if (cid
== 2) snprintf(retStr
, sizeof(buf
),"ATA5577M2");
1388 char * GetSelectedModulationStr( uint8_t id
){
1390 static char buf
[20];
1394 case DEMOD_FSK
: snprintf(retStr
,sizeof(buf
),"FSK"); break;
1395 case DEMOD_FSK1
: snprintf(retStr
,sizeof(buf
),"FSK1"); break;
1396 case DEMOD_FSK1a
: snprintf(retStr
,sizeof(buf
),"FSK1a"); break;
1397 case DEMOD_FSK2
: snprintf(retStr
,sizeof(buf
),"FSK2"); break;
1398 case DEMOD_FSK2a
: snprintf(retStr
,sizeof(buf
),"FSK2a"); break;
1399 case DEMOD_ASK
: snprintf(retStr
,sizeof(buf
),"ASK"); break;
1400 case DEMOD_NRZ
: snprintf(retStr
,sizeof(buf
),"DIRECT/NRZ"); break;
1401 case DEMOD_PSK1
: snprintf(retStr
,sizeof(buf
),"PSK1"); break;
1402 case DEMOD_PSK2
: snprintf(retStr
,sizeof(buf
),"PSK2"); break;
1403 case DEMOD_PSK3
: snprintf(retStr
,sizeof(buf
),"PSK3"); break;
1404 case DEMOD_BI
: snprintf(retStr
,sizeof(buf
),"BIPHASE"); break;
1405 case DEMOD_BIa
: snprintf(retStr
,sizeof(buf
),"BIPHASEa - (CDP)"); break;
1406 default: snprintf(retStr
,sizeof(buf
),"(Unknown)"); break;
1411 void t55x7_create_config_block( int tagtype
){
1414 T55X7_DEFAULT_CONFIG_BLOCK, T55X7_RAW_CONFIG_BLOCK
1415 T55X7_EM_UNIQUE_CONFIG_BLOCK, T55X7_FDXB_CONFIG_BLOCK,
1416 T55X7_FDXB_CONFIG_BLOCK, T55X7_HID_26_CONFIG_BLOCK, T55X7_INDALA_64_CONFIG_BLOCK, T55X7_INDALA_224_CONFIG_BLOCK
1417 T55X7_GUARDPROXII_CONFIG_BLOCK, T55X7_VIKING_CONFIG_BLOCK, T55X7_NORALYS_CONFIG_BLOCK, T55X7_IOPROX_CONFIG_BLOCK
1419 static char buf
[60];
1423 case 0: snprintf(retStr
, sizeof(buf
),"%08X - T55X7 Default", T55X7_DEFAULT_CONFIG_BLOCK
); break;
1424 case 1: snprintf(retStr
, sizeof(buf
),"%08X - T55X7 Raw", T55X7_RAW_CONFIG_BLOCK
); break;
1425 case 2: snprintf(retStr
, sizeof(buf
),"%08X - T5555 Q5 Default", T5555_DEFAULT_CONFIG_BLOCK
); break;
1432 int CmdResetRead(const char *Cmd
) {
1433 UsbCommand c
= {CMD_T55XX_RESET_READ
, {0,0,0}};
1435 clearCommandBuffer();
1437 if ( !WaitForResponseTimeout(CMD_ACK
,NULL
,2500) ) {
1438 PrintAndLog("command execution time out");
1442 uint8_t got
[BIGBUF_SIZE
-1];
1443 GetFromBigBuf(got
,sizeof(got
),0);
1444 WaitForResponse(CMD_ACK
,NULL
);
1445 setGraphBuf(got
, sizeof(got
));
1448 // ADD T5555 (Q5) Default config block
1449 int CmdT55xxWipe(const char *Cmd
) {
1450 char writeData
[20] = {0};
1451 char *ptrData
= writeData
;
1452 char cmdp
= param_getchar(Cmd
, 0);
1453 if ( cmdp
== 'h' || cmdp
== 'H') return usage_t55xx_wipe();
1455 bool Q5
= (cmdp
== 'q' || cmdp
== 'Q');
1457 // Try with the default password to reset block 0
1458 // With a pwd should work even if pwd bit not set
1459 PrintAndLog("\nBeginning Wipe of a T55xx tag (assuming the tag is not password protected)\n");
1462 snprintf(ptrData
,sizeof(writeData
),"b 0 d 6001F004 p 0");
1464 snprintf(ptrData
,sizeof(writeData
),"b 0 d 000880E0 p 0");
1466 if (!CmdT55xxWriteBlock(ptrData
)) PrintAndLog("Error writing blk 0");
1468 for (uint8_t blk
= 1; blk
<8; blk
++) {
1470 snprintf(ptrData
,sizeof(writeData
),"b %d d 0", blk
);
1472 if (!CmdT55xxWriteBlock(ptrData
)) PrintAndLog("Error writing blk %d", blk
);
1474 memset(writeData
,0x00, sizeof(writeData
));
1479 bool IsCancelled(void) {
1483 printf("\naborted via keyboard!\n");
1489 int CmdT55xxBruteForce(const char *Cmd
) {
1491 // load a default pwd file.
1493 char filename
[FILE_PATH_SIZE
]={0};
1495 uint8_t stKeyBlock
= 20;
1496 uint8_t *keyBlock
= NULL
, *p
= NULL
;
1497 uint32_t start_password
= 0x00000000; //start password
1498 uint32_t end_password
= 0xFFFFFFFF; //end password
1501 char cmdp
= param_getchar(Cmd
, 0);
1502 if (cmdp
== 'h' || cmdp
== 'H') return usage_t55xx_bruteforce();
1504 keyBlock
= calloc(stKeyBlock
, 6);
1505 if (keyBlock
== NULL
) return 1;
1507 if (cmdp
== 'i' || cmdp
== 'I') {
1509 int len
= strlen(Cmd
+2);
1510 if (len
> FILE_PATH_SIZE
) len
= FILE_PATH_SIZE
;
1511 memcpy(filename
, Cmd
+2, len
);
1513 FILE * f
= fopen( filename
, "r");
1515 PrintAndLog("File: %s: not found or locked.", filename
);
1520 while( fgets(buf
, sizeof(buf
), f
) ){
1521 if (strlen(buf
) < 8 || buf
[7] == '\n') continue;
1523 while (fgetc(f
) != '\n' && !feof(f
)) ; //goto next line
1525 //The line start with # is comment, skip
1526 if( buf
[0]=='#' ) continue;
1528 if (!isxdigit(buf
[0])){
1529 PrintAndLog("File content error. '%s' must include 8 HEX symbols", buf
);
1535 if ( stKeyBlock
- keycnt
< 2) {
1536 p
= realloc(keyBlock
, 6*(stKeyBlock
+=10));
1538 PrintAndLog("Cannot allocate memory for defaultKeys");
1548 memset(keyBlock
+ 4 * keycnt
, 0, 4);
1549 num_to_bytes(strtoll(buf
, NULL
, 16), 4, keyBlock
+ 4*keycnt
);
1550 PrintAndLog("chk custom pwd[%2d] %08X", keycnt
, bytes_to_num(keyBlock
+ 4*keycnt
, 4));
1552 memset(buf
, 0, sizeof(buf
));
1559 PrintAndLog("No keys found in file");
1563 PrintAndLog("Loaded %d keys", keycnt
);
1566 uint64_t testpwd
= 0x00;
1567 for (uint16_t c
= 0; c
< keycnt
; ++c
) {
1570 printf("Device offline\n");
1575 if (IsCancelled()) {
1580 testpwd
= bytes_to_num(keyBlock
+ 4*c
, 4);
1582 PrintAndLog("Testing %08X", testpwd
);
1584 if ( !AquireData(T55x7_PAGE0
, T55x7_CONFIGURATION_BLOCK
, TRUE
, testpwd
)) {
1585 PrintAndLog("Aquireing data from device failed. Quitting");
1590 found
= tryDetectModulation();
1592 PrintAndLog("Found valid password: [%08X]", testpwd
);
1597 PrintAndLog("Password NOT found.");
1602 // Try to read Block 7, first :)
1604 // incremental pwd range search
1605 start_password
= param_get32ex(Cmd
, 0, 0, 16);
1606 end_password
= param_get32ex(Cmd
, 1, 0, 16);
1608 if ( start_password
>= end_password
) {
1610 return usage_t55xx_bruteforce();
1613 PrintAndLog("Search password range [%08X -> %08X]", start_password
, end_password
);
1615 uint32_t i
= start_password
;
1617 while ((!found
) && (i
<= end_password
)){
1622 if (IsCancelled()) {
1627 if (!AquireData(T55x7_PAGE0
, T55x7_CONFIGURATION_BLOCK
, TRUE
, i
)) {
1628 PrintAndLog("Aquireing data from device failed. Quitting");
1632 found
= tryDetectModulation();
1641 PrintAndLog("Found valid password: [%08x]", i
);
1643 PrintAndLog("Password NOT found. Last tried: [%08x]", --i
);
1649 int tryOnePassword(uint32_t password
) {
1650 PrintAndLog("Trying password %08x", password
);
1651 if (!AquireData(T55x7_PAGE0
, T55x7_CONFIGURATION_BLOCK
, TRUE
, password
)) {
1652 PrintAndLog("Aquireing data from device failed. Quitting");
1656 if (tryDetectModulation())
1662 int CmdT55xxRecoverPW(const char *Cmd
) {
1664 uint32_t orig_password
= 0x0;
1665 uint32_t curr_password
= 0x0;
1666 uint32_t prev_password
= 0xffffffff;
1667 uint32_t mask
= 0x0;
1670 char cmdp
= param_getchar(Cmd
, 0);
1671 if (cmdp
== 'h' || cmdp
== 'H') return usage_t55xx_recoverpw();
1673 orig_password
= param_get32ex(Cmd
, 0, 0x51243648, 16); //password used by handheld cloners
1675 // first try fliping each bit in the expected password
1676 while ((found
!= 1) && (bit
< 32)) {
1677 curr_password
= orig_password
^ ( 1 << bit
);
1678 found
= tryOnePassword(curr_password
);
1681 else if (found
== -1)
1685 if (IsCancelled()) return 0;
1688 // now try to use partial original password, since block 7 should have been completely
1689 // erased during the write sequence and it is possible that only partial password has been
1691 // not sure from which end the bit bits are written, so try from both ends
1692 // from low bit to high bit
1694 while ((found
!= 1) && (bit
< 32)) {
1695 mask
+= ( 1 << bit
);
1696 curr_password
= orig_password
& mask
;
1697 // if updated mask didn't change the password, don't try it again
1698 if (prev_password
== curr_password
) {
1702 found
= tryOnePassword(curr_password
);
1705 else if (found
== -1)
1708 prev_password
= curr_password
;
1710 if (IsCancelled()) return 0;
1713 // from high bit to low
1716 while ((found
!= 1) && (bit
< 32)) {
1717 mask
-= ( 1 << bit
);
1718 curr_password
= orig_password
& mask
;
1719 // if updated mask didn't change the password, don't try it again
1720 if (prev_password
== curr_password
) {
1724 found
= tryOnePassword(curr_password
);
1727 else if (found
== -1)
1730 prev_password
= curr_password
;
1732 if (IsCancelled()) return 0;
1738 PrintAndLog("Found valid password: [%08x]", curr_password
);
1740 PrintAndLog("Password NOT found.");
1745 static command_t CommandTable
[] = {
1746 {"help", CmdHelp
, 1, "This help"},
1747 {"bruteforce", CmdT55xxBruteForce
,0, "<start password> <end password> [i <*.dic>] Simple bruteforce attack to find password"},
1748 {"config", CmdT55xxSetConfig
, 1, "Set/Get T55XX configuration (modulation, inverted, offset, rate)"},
1749 {"detect", CmdT55xxDetect
, 1, "[1] Try detecting the tag modulation from reading the configuration block."},
1750 {"dump", CmdT55xxDump
, 0, "[password] [o] Dump T55xx card block 0-7. Optional [password], [override]"},
1751 {"info", CmdT55xxInfo
, 1, "[1] Show T55x7 configuration data (page 0/ blk 0)"},
1752 {"read", CmdT55xxReadBlock
, 0, "b <block> p [password] [o] [1] -- Read T55xx block data. Optional [p password], [override], [page1]"},
1753 {"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)"},
1754 {"recoverpw", CmdT55xxRecoverPW
, 0, "[password] Try to recover from bad password write from a cloner. Only use on PW protected chips!"},
1755 {"special", special
, 0, "Show block changes with 64 different offsets"},
1756 {"trace", CmdT55xxReadTrace
, 1, "[1] Show T55x7 traceability data (page 1/ blk 0-1)"},
1757 {"wakeup", CmdT55xxWakeUp
, 0, "Send AOR wakeup command"},
1758 {"wipe", CmdT55xxWipe
, 0, "[q] Wipe a T55xx tag and set defaults (will destroy any data on tag)"},
1759 {"write", CmdT55xxWriteBlock
,0, "b <block> d <data> p [password] [1] -- Write T55xx block data. Optional [p password], [page1]"},
1760 {NULL
, NULL
, 0, NULL
}
1763 int CmdLFT55XX(const char *Cmd
) {
1764 clearCommandBuffer();
1765 CmdsParse(CommandTable
, Cmd
);
1769 int CmdHelp(const char *Cmd
) {
1770 CmdsHelp(CommandTable
);