1 //----------------------------------------------------------------------------- 
   3 // This code is licensed to you under the terms of the GNU GPL, version 2 or, 
   4 // at your option, any later version. See the LICENSE.txt file for the text of 
   6 //----------------------------------------------------------------------------- 
   7 // Low frequency T55xx commands 
   8 //----------------------------------------------------------------------------- 
  14 #include "proxmark3.h" 
  18 #include "cmdparser.h" 
  21 #include "cmdlft55xx.h" 
  25 #include "../common/crc.h" 
  26 #include "../common/iso14443crc.h" 
  29 #define CONFIGURATION_BLOCK 0x00 
  30 #define TRACE_BLOCK 0x01 
  31 #define REGULAR_READ_MODE_BLOCK 0xFF 
  33 // Default configuration 
  34 t55xx_conf_block_t config 
= { .modulation 
= DEMOD_ASK
, .inverted 
= FALSE
, .offset 
= 0x00, .block0 
= 0x00, .Q5 
= FALSE 
}; 
  36 t55xx_conf_block_t 
Get_t55xx_Config(){ 
  39 void Set_t55xx_Config(t55xx_conf_block_t conf
){ 
  43 int usage_t55xx_config(){ 
  44         PrintAndLog("Usage: lf t55xx config [d <demodulation>] [i 1] [o <offset>] [Q5]"); 
  45         PrintAndLog("Options:"); 
  46         PrintAndLog("       h                        This help"); 
  47         PrintAndLog("       b <8|16|32|40|50|64|100|128>  Set bitrate"); 
  48         PrintAndLog("       d <FSK|FSK1|FSK1a|FSK2|FSK2a|ASK|PSK1|PSK2|NRZ|BI|BIa>  Set demodulation FSK / ASK / PSK / NRZ / Biphase / Biphase A"); 
  49         PrintAndLog("       i [1]                         Invert data signal, defaults to normal"); 
  50         PrintAndLog("       o [offset]                    Set offset, where data should start decode in bitstream"); 
  51         PrintAndLog("       Q5                            Set as Q5(T5555) chip instead of T55x7"); 
  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 wr b 3 d 11223344            - write 11223344 to block 3"); 
  88         PrintAndLog("      lf t55xx wr 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("     [graph buffer data]  - 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("     [graph buffer data]  - 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]"); 
 128         PrintAndLog("Options:"); 
 129         PrintAndLog("     [graph buffer data]  - if set, use Graphbuffer otherwise read data from tag."); 
 131         PrintAndLog("Examples:"); 
 132         PrintAndLog("      lf t55xx detect"); 
 133         PrintAndLog("      lf t55xx detect 1"); 
 137 int usage_t55xx_wakup(){ 
 138         PrintAndLog("Usage:  lf t55xx wakeup [h] p <password>"); 
 139         PrintAndLog("This commands send the Answer-On-Request command and leaves the readerfield ON afterwards."); 
 140         PrintAndLog("Options:"); 
 141         PrintAndLog("     h             - this help"); 
 142         PrintAndLog("     p <password>  - password 4bytes (8 hex symbols)"); 
 144         PrintAndLog("Examples:"); 
 145                 PrintAndLog("      lf t55xx wakeup p 11223344  - send wakeup password"); 
 149 static int CmdHelp(const char *Cmd
); 
 151 int CmdT55xxSetConfig(const char *Cmd
) { 
 154         char modulation
[5] = {0x00}; 
 157         uint8_t rates
[9] = {8,16,32,40,50,64,100,128,0}; 
 161         while(param_getchar(Cmd
, cmdp
) != 0x00 && !errors
) 
 163                 tmp 
= param_getchar(Cmd
, cmdp
); 
 168                         return usage_t55xx_config(); 
 170                         errors 
|= param_getdec(Cmd
, cmdp
+1, &bitRate
); 
 174                                         if (rates
[i
]==bitRate
) { 
 179                                 if (i
==9) errors 
= TRUE
; 
 184                         param_getstr(Cmd
, cmdp
+1, modulation
); 
 187                         if ( strcmp(modulation
, "FSK" ) == 0) { 
 188                                 config
.modulation 
= DEMOD_FSK
; 
 189                         } else if ( strcmp(modulation
, "FSK1" ) == 0) { 
 190                                 config
.modulation 
= DEMOD_FSK1
; 
 192                         } else if ( strcmp(modulation
, "FSK1a" ) == 0) { 
 193                                 config
.modulation 
= DEMOD_FSK1a
; 
 195                         } else if ( strcmp(modulation
, "FSK2" ) == 0) { 
 196                                 config
.modulation 
= DEMOD_FSK2
; 
 198                         } else if ( strcmp(modulation
, "FSK2a" ) == 0) { 
 199                                 config
.modulation 
= DEMOD_FSK2a
; 
 201                         } else if ( strcmp(modulation
, "ASK" ) == 0) { 
 202                                 config
.modulation 
= DEMOD_ASK
; 
 203                         } else if ( strcmp(modulation
, "NRZ" ) == 0) { 
 204                                 config
.modulation 
= DEMOD_NRZ
; 
 205                         } else if ( strcmp(modulation
, "PSK1" ) == 0) { 
 206                                 config
.modulation 
= DEMOD_PSK1
; 
 207                         } else if ( strcmp(modulation
, "PSK2" ) == 0) { 
 208                                 config
.modulation 
= DEMOD_PSK2
; 
 209                         } else if ( strcmp(modulation
, "PSK3" ) == 0) { 
 210                                 config
.modulation 
= DEMOD_PSK3
; 
 211                         } else if ( strcmp(modulation
, "BIa" ) == 0) { 
 212                                 config
.modulation 
= DEMOD_BIa
; 
 214                         } else if ( strcmp(modulation
, "BI" ) == 0) { 
 215                                 config
.modulation 
= DEMOD_BI
; 
 218                                 PrintAndLog("Unknown modulation '%s'", modulation
); 
 223                         config
.inverted 
= param_getchar(Cmd
,cmdp
+1) == '1'; 
 227                         errors 
|= param_getdec(Cmd
, cmdp
+1, &offset
); 
 229                                 config
.offset 
= offset
; 
 238                         PrintAndLog("Unknown parameter '%c'", param_getchar(Cmd
, cmdp
)); 
 245         if (cmdp 
== 0) return printConfiguration( config 
); 
 248         if (errors
) return usage_t55xx_config(); 
 251         return printConfiguration ( config 
); 
 254 int T55xxReadBlock(uint8_t block
, bool page1
, bool usepwd
, bool override
, uint32_t password
){ 
 257                 // try reading the config block and verify that PWD bit is set before doing this! 
 259                         if ( !AquireData(0, CONFIGURATION_BLOCK
, false, 0 ) ) return 0; 
 260                         if ( !tryDetectModulation() ) { 
 261                                 PrintAndLog("Safety Check: Could not detect if PWD bit is set in config block. Exits."); 
 264                                 PrintAndLog("Safety Check: PWD bit is NOT set in config block. Reading without password...");    
 269                         PrintAndLog("Safety Check Overriden - proceeding despite risk"); 
 273         if (!AquireData(page1
, block
, usepwd
, password
) )       return 0; 
 274         if (!DecodeT55xxBlock()) return 0; 
 277         sprintf(blk
,"%d", block
); 
 278         printT55xxBlock(blk
);    
 282 int CmdT55xxReadBlock(const char *Cmd
) { 
 283         uint8_t block 
= REGULAR_READ_MODE_BLOCK
; 
 284         uint32_t password 
= 0; //default to blank Block 7 
 286         bool override 
= false; 
 290         while(param_getchar(Cmd
, cmdp
) != 0x00 && !errors
) { 
 291                 switch(param_getchar(Cmd
, cmdp
)) { 
 294                         return usage_t55xx_read(); 
 297                         errors 
|= param_getdec(Cmd
, cmdp
+1, &block
); 
 307                         password 
= param_get32ex(Cmd
, cmdp
+1, 0, 16); 
 316                         PrintAndLog("Unknown parameter '%c'", param_getchar(Cmd
, cmdp
)); 
 321         if (errors
) return usage_t55xx_read(); 
 323         if (block 
> 7 && block 
!= REGULAR_READ_MODE_BLOCK       
) { 
 324                 PrintAndLog("Block must be between 0 and 7"); 
 327         PrintAndLog("Reading Page %d:", page1
);  
 328         PrintAndLog("blk | hex data | binary"); 
 329         return T55xxReadBlock(block
, page1
, usepwd
, override
, password
); 
 332 bool DecodeT55xxBlock(){ 
 334         char buf
[30] = {0x00}; 
 337         uint8_t bitRate
[8] = {8,16,32,40,50,64,100,128}; 
 338         DemodBufferLen 
= 0x00; 
 340         switch( config
.modulation 
){ 
 342                         snprintf(cmdStr
, sizeof(buf
),"%d %d", bitRate
[config
.bitrate
], config
.inverted 
); 
 343                         ans 
= FSKrawDemod(cmdStr
, FALSE
); 
 347                         snprintf(cmdStr
, sizeof(buf
),"%d %d 8 5", bitRate
[config
.bitrate
], config
.inverted 
); 
 348                         ans 
= FSKrawDemod(cmdStr
, FALSE
); 
 352                         snprintf(cmdStr
, sizeof(buf
),"%d %d 10 8", bitRate
[config
.bitrate
], config
.inverted 
); 
 353                         ans 
= FSKrawDemod(cmdStr
, FALSE
); 
 356                         snprintf(cmdStr
, sizeof(buf
),"%d %d 1", bitRate
[config
.bitrate
], config
.inverted 
); 
 357                         ans 
= ASKDemod(cmdStr
, FALSE
, FALSE
, 1); 
 360                         // skip first 160 samples to allow antenna to settle in (psk gets inverted occasionally otherwise) 
 362                         snprintf(cmdStr
, sizeof(buf
),"%d %d 6", bitRate
[config
.bitrate
], config
.inverted 
); 
 363                         ans 
= PSKDemod(cmdStr
, FALSE
); 
 365                 case DEMOD_PSK2
: //inverted won't affect this 
 366                 case DEMOD_PSK3
: //not fully implemented 
 367                         // skip first 160 samples to allow antenna to settle in (psk gets inverted occasionally otherwise) 
 369                         snprintf(cmdStr
, sizeof(buf
),"%d 0 6", bitRate
[config
.bitrate
] ); 
 370                         ans 
= PSKDemod(cmdStr
, FALSE
); 
 371                         psk1TOpsk2(DemodBuffer
, DemodBufferLen
); 
 374                         snprintf(cmdStr
, sizeof(buf
),"%d %d 1", bitRate
[config
.bitrate
], config
.inverted 
); 
 375                         ans 
= NRZrawDemod(cmdStr
, FALSE
); 
 379                         snprintf(cmdStr
, sizeof(buf
),"0 %d %d 1", bitRate
[config
.bitrate
], config
.inverted 
); 
 380                         ans 
= ASKbiphaseDemod(cmdStr
, FALSE
); 
 388 int CmdT55xxDetect(const char *Cmd
){ 
 390         char cmdp 
= param_getchar(Cmd
, 0); 
 391         if (strlen(Cmd
) > 1 || cmdp 
== 'h' || cmdp 
== 'H') 
 392                 return usage_t55xx_detect(); 
 395                 if ( !AquireData(0, CONFIGURATION_BLOCK
, false, 0) ) 
 398         if ( !tryDetectModulation() ) 
 399                 PrintAndLog("Could not detect modulation automatically. Try setting it manually with \'lf t55xx config\'"); 
 404 // detect configuration? 
 405 bool tryDetectModulation(){ 
 407         t55xx_conf_block_t tests
[15]; 
 409         uint8_t fc1 
= 0, fc2 
= 0, clk
=0; 
 411         if (GetFskClock("", FALSE
, FALSE
)){  
 412                 fskClocks(&fc1
, &fc2
, &clk
, FALSE
); 
 413                 if ( FSKrawDemod("0 0", FALSE
) && test(DEMOD_FSK
, &tests
[hits
].offset
, &bitRate
, clk
, &tests
[hits
].Q5
)){ 
 414                         tests
[hits
].modulation 
= DEMOD_FSK
; 
 415                         if (fc1
==8 && fc2 
== 5) 
 416                                 tests
[hits
].modulation 
= DEMOD_FSK1a
; 
 417                         else if (fc1
==10 && fc2 
== 8) 
 418                                 tests
[hits
].modulation 
= DEMOD_FSK2
; 
 419                         tests
[hits
].bitrate 
= bitRate
; 
 420                         tests
[hits
].inverted 
= FALSE
; 
 421                         tests
[hits
].block0 
= PackBits(tests
[hits
].offset
, 32, DemodBuffer
); 
 424                 if ( FSKrawDemod("0 1", FALSE
) && test(DEMOD_FSK
, &tests
[hits
].offset
, &bitRate
, clk
, &tests
[hits
].Q5
)) { 
 425                         tests
[hits
].modulation 
= DEMOD_FSK
; 
 426                         if (fc1 
== 8 && fc2 
== 5) 
 427                                 tests
[hits
].modulation 
= DEMOD_FSK1
; 
 428                         else if (fc1 
== 10 && fc2 
== 8) 
 429                                 tests
[hits
].modulation 
= DEMOD_FSK2a
; 
 431                         tests
[hits
].bitrate 
= bitRate
; 
 432                         tests
[hits
].inverted 
= TRUE
; 
 433                         tests
[hits
].block0 
= PackBits(tests
[hits
].offset
, 32, DemodBuffer
); 
 437                 clk 
= GetAskClock("", FALSE
, FALSE
); 
 439                         if ( ASKDemod("0 0 1", FALSE
, FALSE
, 1) && test(DEMOD_ASK
, &tests
[hits
].offset
, &bitRate
, clk
, &tests
[hits
].Q5
)) { 
 440                                 tests
[hits
].modulation 
= DEMOD_ASK
; 
 441                                 tests
[hits
].bitrate 
= bitRate
; 
 442                                 tests
[hits
].inverted 
= FALSE
; 
 443                                 tests
[hits
].block0 
= PackBits(tests
[hits
].offset
, 32, DemodBuffer
); 
 446                         if ( ASKDemod("0 1 1", FALSE
, FALSE
, 1)  && test(DEMOD_ASK
, &tests
[hits
].offset
, &bitRate
, clk
, &tests
[hits
].Q5
)) { 
 447                                 tests
[hits
].modulation 
= DEMOD_ASK
; 
 448                                 tests
[hits
].bitrate 
= bitRate
; 
 449                                 tests
[hits
].inverted 
= TRUE
; 
 450                                 tests
[hits
].block0 
= PackBits(tests
[hits
].offset
, 32, DemodBuffer
); 
 453                         if ( ASKbiphaseDemod("0 0 0 2", FALSE
) && test(DEMOD_BI
, &tests
[hits
].offset
, &bitRate
, clk
, &tests
[hits
].Q5
) ) { 
 454                                 tests
[hits
].modulation 
= DEMOD_BI
; 
 455                                 tests
[hits
].bitrate 
= bitRate
; 
 456                                 tests
[hits
].inverted 
= FALSE
; 
 457                                 tests
[hits
].block0 
= PackBits(tests
[hits
].offset
, 32, DemodBuffer
); 
 460                         if ( ASKbiphaseDemod("0 0 1 2", FALSE
) && test(DEMOD_BIa
, &tests
[hits
].offset
, &bitRate
, clk
, &tests
[hits
].Q5
) ) { 
 461                                 tests
[hits
].modulation 
= DEMOD_BIa
; 
 462                                 tests
[hits
].bitrate 
= bitRate
; 
 463                                 tests
[hits
].inverted 
= TRUE
; 
 464                                 tests
[hits
].block0 
= PackBits(tests
[hits
].offset
, 32, DemodBuffer
); 
 470                 clk 
= GetNrzClock("", FALSE
, FALSE
); 
 472                         if ( NRZrawDemod("0 0 1", FALSE
)  && test(DEMOD_NRZ
, &tests
[hits
].offset
, &bitRate
, clk
, &tests
[hits
].Q5
)) { 
 473                                 tests
[hits
].modulation 
= DEMOD_NRZ
; 
 474                                 tests
[hits
].bitrate 
= bitRate
; 
 475                                 tests
[hits
].inverted 
= FALSE
; 
 476                                 tests
[hits
].block0 
= PackBits(tests
[hits
].offset
, 32, DemodBuffer
); 
 480                         if ( NRZrawDemod("0 1 1", FALSE
)  && test(DEMOD_NRZ
, &tests
[hits
].offset
, &bitRate
, clk
, &tests
[hits
].Q5
)) { 
 481                                 tests
[hits
].modulation 
= DEMOD_NRZ
; 
 482                                 tests
[hits
].bitrate 
= bitRate
; 
 483                                 tests
[hits
].inverted 
= TRUE
; 
 484                                 tests
[hits
].block0 
= PackBits(tests
[hits
].offset
, 32, DemodBuffer
); 
 491                 // skip first 160 samples to allow antenna to settle in (psk gets inverted occasionally otherwise) 
 493                 clk 
= GetPskClock("", FALSE
, FALSE
); 
 495                         if ( PSKDemod("0 0 6", FALSE
) && test(DEMOD_PSK1
, &tests
[hits
].offset
, &bitRate
, clk
, &tests
[hits
].Q5
)) { 
 496                                 tests
[hits
].modulation 
= DEMOD_PSK1
; 
 497                                 tests
[hits
].bitrate 
= bitRate
; 
 498                                 tests
[hits
].inverted 
= FALSE
; 
 499                                 tests
[hits
].block0 
= PackBits(tests
[hits
].offset
, 32, DemodBuffer
); 
 502                         if ( PSKDemod("0 1 6", FALSE
) && test(DEMOD_PSK1
, &tests
[hits
].offset
, &bitRate
, clk
, &tests
[hits
].Q5
)) { 
 503                                 tests
[hits
].modulation 
= DEMOD_PSK1
; 
 504                                 tests
[hits
].bitrate 
= bitRate
; 
 505                                 tests
[hits
].inverted 
= TRUE
; 
 506                                 tests
[hits
].block0 
= PackBits(tests
[hits
].offset
, 32, DemodBuffer
); 
 509                         // PSK2 - needs a call to psk1TOpsk2. 
 510                         if ( PSKDemod("0 0 6", FALSE
)) { 
 511                                 psk1TOpsk2(DemodBuffer
, DemodBufferLen
); 
 512                                 if (test(DEMOD_PSK2
, &tests
[hits
].offset
, &bitRate
, clk
, &tests
[hits
].Q5
)){ 
 513                                         tests
[hits
].modulation 
= DEMOD_PSK2
; 
 514                                         tests
[hits
].bitrate 
= bitRate
; 
 515                                         tests
[hits
].inverted 
= FALSE
; 
 516                                         tests
[hits
].block0 
= PackBits(tests
[hits
].offset
, 32, DemodBuffer
); 
 519                         } // inverse waves does not affect this demod 
 520                         // PSK3 - needs a call to psk1TOpsk2. 
 521                         if ( PSKDemod("0 0 6", FALSE
)) { 
 522                                 psk1TOpsk2(DemodBuffer
, DemodBufferLen
); 
 523                                 if (test(DEMOD_PSK3
, &tests
[hits
].offset
, &bitRate
, clk
, &tests
[hits
].Q5
)){ 
 524                                         tests
[hits
].modulation 
= DEMOD_PSK3
; 
 525                                         tests
[hits
].bitrate 
= bitRate
; 
 526                                         tests
[hits
].inverted 
= FALSE
; 
 527                                         tests
[hits
].block0 
= PackBits(tests
[hits
].offset
, 32, DemodBuffer
); 
 530                         } // inverse waves does not affect this demod 
 535                 config
.modulation 
= tests
[0].modulation
; 
 536                 config
.bitrate 
= tests
[0].bitrate
; 
 537                 config
.inverted 
= tests
[0].inverted
; 
 538                 config
.offset 
= tests
[0].offset
; 
 539                 config
.block0 
= tests
[0].block0
; 
 540                 printConfiguration( config 
); 
 545                 PrintAndLog("Found [%d] possible matches for modulation.",hits
); 
 546                 for(int i
=0; i
<hits
; ++i
){ 
 547                         PrintAndLog("--[%d]---------------", i
+1); 
 548                         printConfiguration( tests
[i
] ); 
 554 bool testModulation(uint8_t mode
, uint8_t modread
){ 
 557                         if (modread 
>= DEMOD_FSK1 
&& modread 
<= DEMOD_FSK2a
) return TRUE
; 
 560                         if (modread 
== DEMOD_ASK
) return TRUE
; 
 563                         if (modread 
== DEMOD_PSK1
) return TRUE
; 
 566                         if (modread 
== DEMOD_PSK2
) return TRUE
; 
 569                         if (modread 
== DEMOD_PSK3
) return TRUE
; 
 572                         if (modread 
== DEMOD_NRZ
) return TRUE
; 
 575                         if (modread 
== DEMOD_BI
) return TRUE
; 
 578                         if (modread 
== DEMOD_BIa
) return TRUE
; 
 586 bool testQ5Modulation(uint8_t   mode
, uint8_t   modread
){ 
 589                         if (modread 
>= 4 && modread 
<= 5) return TRUE
; 
 592                         if (modread 
== 0) return TRUE
; 
 595                         if (modread 
== 1) return TRUE
; 
 598                         if (modread 
== 2) return TRUE
; 
 601                         if (modread 
== 3) return TRUE
; 
 604                         if (modread 
== 7) return TRUE
; 
 607                         if (modread 
== 6) return TRUE
; 
 615 bool testQ5(uint8_t mode
, uint8_t *offset
, int *fndBitRate
, uint8_t     clk
){ 
 617         if ( DemodBufferLen 
< 64 ) return FALSE
; 
 619         for (uint8_t idx 
= 28; idx 
< 64; idx
++){ 
 621                 if ( PackBits(si
, 28, DemodBuffer
) == 0x00 ) continue; 
 623                 uint8_t safer     
= PackBits(si
, 4, DemodBuffer
); si 
+= 4;     //master key 
 624                 uint8_t resv      
= PackBits(si
, 8, DemodBuffer
); si 
+= 8; 
 625                 // 2nibble must be zeroed. 
 626                 if (safer 
!= 0x6) continue; 
 627                 if ( resv 
> 0x00) continue; 
 628                 //uint8_t       pageSel   = PackBits(si, 1, DemodBuffer); si += 1; 
 629                 //uint8_t fastWrite = PackBits(si, 1, DemodBuffer); si += 1; 
 631                 int bitRate       
= PackBits(si
, 5, DemodBuffer
)*2 + 2; si 
+= 5;     //bit rate 
 632                 if (bitRate 
> 128 || bitRate 
< 8) continue; 
 634                 //uint8_t AOR       = PackBits(si, 1, DemodBuffer); si += 1;    
 635                 //uint8_t PWD       = PackBits(si, 1, DemodBuffer); si += 1;  
 636                 //uint8_t pskcr     = PackBits(si, 2, DemodBuffer); si += 2;  //could check psk cr 
 637                 //uint8_t inverse   = PackBits(si, 1, DemodBuffer); si += 1; 
 639                 uint8_t modread   
= PackBits(si
, 3, DemodBuffer
); si 
+= 3; 
 640                 uint8_t maxBlk    
= PackBits(si
, 3, DemodBuffer
); si 
+= 3; 
 641                 //uint8_t ST        = PackBits(si, 1, DemodBuffer); si += 1; 
 642                 if (maxBlk 
== 0) continue; 
 644                 if (!testQ5Modulation(mode
, modread
)) continue; 
 645                 if (bitRate 
!= clk
) continue; 
 646                 *fndBitRate 
= bitRate
; 
 654 bool testBitRate(uint8_t readRate
, uint8_t clk
){ 
 655         uint8_t expected
[] = {8, 16, 32, 40, 50, 64, 100, 128}; 
 656         if (expected
[readRate
] == clk
) 
 662 bool test(uint8_t mode
, uint8_t *offset
, int *fndBitRate
, uint8_t clk
, bool *Q5
){ 
 664         if ( DemodBufferLen 
< 64 ) return FALSE
; 
 666         for (uint8_t idx 
= 28; idx 
< 64; idx
++){ 
 668                 if ( PackBits(si
, 28, DemodBuffer
) == 0x00 ) continue; 
 670                 uint8_t safer    
= PackBits(si
, 4, DemodBuffer
); si 
+= 4;     //master key 
 671                 uint8_t resv     
= PackBits(si
, 4, DemodBuffer
); si 
+= 4;     //was 7 & +=7+3 //should be only 4 bits if extended mode 
 672                 // 2nibble must be zeroed. 
 673                 // moved test to here, since this gets most faults first. 
 674                 if ( resv 
> 0x00) continue; 
 676                 uint8_t xtRate   
= PackBits(si
, 3, DemodBuffer
); si 
+= 3;     //extended mode part of rate 
 677                 int bitRate      
= PackBits(si
, 3, DemodBuffer
); si 
+= 3;     //bit rate 
 678                 if (bitRate 
> 7) continue; 
 679                 uint8_t extend   
= PackBits(si
, 1, DemodBuffer
); si 
+= 1;     //bit 15 extended mode 
 680                 uint8_t modread  
= PackBits(si
, 5, DemodBuffer
); si 
+= 5+2+1;  
 681                 //uint8_t pskcr   = PackBits(si, 2, DemodBuffer); si += 2+1;  //could check psk cr 
 682                 uint8_t nml01    
= PackBits(si
, 1, DemodBuffer
); si 
+= 1+5;   //bit 24, 30, 31 could be tested for 0 if not extended mode 
 683                 uint8_t nml02    
= PackBits(si
, 2, DemodBuffer
); si 
+= 2; 
 686                 bool extMode 
=( (safer 
== 0x6 || safer 
== 0x9) && extend
) ? TRUE 
: FALSE
; 
 689                         if (nml01 
|| nml02 
|| xtRate
) continue; 
 692                 if (!testModulation(mode
, modread
)) continue; 
 693                 if (!testBitRate(bitRate
, clk
)) continue; 
 694                 *fndBitRate 
= bitRate
; 
 699         if (testQ5(mode
, offset
, fndBitRate
, clk
)) { 
 706 void printT55xxBlock(const char *blockNum
){ 
 708         uint8_t i 
= config
.offset
; 
 709         uint8_t endpos 
= 32 + i
; 
 710         uint32_t blockData 
= 0; 
 711         uint8_t bits
[64] = {0x00}; 
 713         if ( !DemodBufferLen
) return; 
 715         if ( endpos 
> DemodBufferLen
){ 
 716                 PrintAndLog("The configured offset %d is too big. Possible offset: %d)", i
, DemodBufferLen
-32); 
 720         for (; i 
< endpos
; ++i
) 
 721                 bits
[i 
- config
.offset
]=DemodBuffer
[i
]; 
 723         blockData 
= PackBits(0, 32, bits
); 
 725         PrintAndLog("  %s | %08X | %s", blockNum
, blockData
, sprint_bin(bits
,32)); 
 728 int special(const char *Cmd
) { 
 729         uint32_t blockData 
= 0; 
 730         uint8_t bits
[32] = {0x00}; 
 732         PrintAndLog("OFFSET | DATA       | BINARY"); 
 733         PrintAndLog("----------------------------------------------------"); 
 737                 for (i 
= 0; i 
< 32; ++i
) 
 738                         bits
[i
]=DemodBuffer
[j
+i
]; 
 740                 blockData 
= PackBits(0, 32, bits
); 
 742                 PrintAndLog("    %02d | 0x%08X | %s",j 
, blockData
, sprint_bin(bits
,32));        
 747 int printConfiguration( t55xx_conf_block_t b
){ 
 748         PrintAndLog("Chip Type  : %s", (b
.Q5
) ? "T5555(Q5)" : "T55x7"); 
 749         PrintAndLog("Modulation : %s", GetSelectedModulationStr(b
.modulation
) ); 
 750         PrintAndLog("Bit Rate   : %s", GetBitRateStr(b
.bitrate
) ); 
 751         PrintAndLog("Inverted   : %s", (b
.inverted
) ? "Yes" : "No" ); 
 752         PrintAndLog("Offset     : %d", b
.offset
); 
 753         PrintAndLog("Block0     : 0x%08X", b
.block0
); 
 758 int CmdT55xxWakeUp(const char *Cmd
) { 
 759         uint32_t password 
= 0; 
 762         while(param_getchar(Cmd
, cmdp
) != 0x00) { 
 763                 switch(param_getchar(Cmd
, cmdp
)) { 
 766                         return usage_t55xx_wakup(); 
 769                         password 
= param_get32ex(Cmd
, cmdp
+1, 0xFFFFFFFF, 16); 
 774                         PrintAndLog("Unknown parameter '%c'", param_getchar(Cmd
, cmdp
)); 
 779         if (errors
) return usage_t55xx_wakup(); 
 781         UsbCommand c 
= {CMD_T55XX_WAKEUP
, {password
, 0, 0}}; 
 782         clearCommandBuffer(); 
 784         PrintAndLog("Wake up command sent. Try read now"); 
 788 int CmdT55xxWriteBlock(const char *Cmd
) { 
 789         uint8_t block 
= 0xFF; //default to invalid block 
 790         uint32_t data 
= 0xFFFFFFFF; //default to blank Block  
 791         uint32_t password 
= 0xFFFFFFFF; //default to blank Block 7 
 794         bool gotdata 
= false; 
 797         while(param_getchar(Cmd
, cmdp
) != 0x00 && !errors
) { 
 798                 switch(param_getchar(Cmd
, cmdp
)) { 
 801                         return usage_t55xx_write(); 
 804                         errors 
|= param_getdec(Cmd
, cmdp
+1, &block
); 
 809                         data 
= param_get32ex(Cmd
, cmdp
+1, 0, 16); 
 815                         password 
= param_get32ex(Cmd
, cmdp
+1, 0, 16); 
 824                         PrintAndLog("Unknown parameter '%c'", param_getchar(Cmd
, cmdp
)); 
 829         if (errors 
|| !gotdata
) return usage_t55xx_write(); 
 832                 PrintAndLog("Block number must be between 0 and 7"); 
 836         UsbCommand c 
= {CMD_T55XX_WRITE_BLOCK
, {data
, block
, 0}}; 
 838         c
.d
.asBytes
[0] = (page1
) ? 0x2 : 0;  
 840         PrintAndLog("Writing to page: %d  block: %d  data : 0x%08X", page1
, block
, data
); 
 845                 c
.d
.asBytes
[0] |= 0x1;  
 846                 PrintAndLog("pwd   : 0x%08X", password
); 
 848         clearCommandBuffer(); 
 850         if (!WaitForResponseTimeout(CMD_ACK
, &resp
, 1000)){ 
 851                 PrintAndLog("Error occurred, device did not ACK write operation. (May be due to old firmware)"); 
 857 int CmdT55xxReadTrace(const char *Cmd
) { 
 858         char cmdp 
= param_getchar(Cmd
, 0); 
 859         bool pwdmode 
= false; 
 860         uint32_t password 
= 0; 
 861         if (strlen(Cmd
) > 1 || cmdp 
== 'h' || cmdp 
== 'H')  
 862                 return usage_t55xx_trace(); 
 865                 if ( !AquireData( TRACE_BLOCK
, REGULAR_READ_MODE_BLOCK
, pwdmode
, password 
) ) 
 868         if (!DecodeT55xxBlock()) return 0; 
 870         if ( !DemodBufferLen
) return 0; 
 872         RepaintGraphWindow(); 
 874         if (config
.offset 
> 5)  
 876         uint8_t si 
= config
.offset
+repeat
; 
 877         uint32_t bl1     
= PackBits(si
, 32, DemodBuffer
); 
 878         uint32_t bl2     
= PackBits(si
+32, 32, DemodBuffer
); 
 880         uint32_t acl     
= PackBits(si
, 8,  DemodBuffer
); si 
+= 8; 
 881         uint32_t mfc     
= PackBits(si
, 8,  DemodBuffer
); si 
+= 8; 
 882         uint32_t cid     
= PackBits(si
, 5,  DemodBuffer
); si 
+= 5; 
 883         uint32_t icr     
= PackBits(si
, 3,  DemodBuffer
); si 
+= 3; 
 884         uint32_t year    
= PackBits(si
, 4,  DemodBuffer
); si 
+= 4; 
 885         uint32_t quarter 
= PackBits(si
, 2,  DemodBuffer
); si 
+= 2; 
 886         uint32_t lotid   
= PackBits(si
, 14, DemodBuffer
); si 
+= 14; 
 887         uint32_t wafer   
= PackBits(si
, 5,  DemodBuffer
); si 
+= 5; 
 888         uint32_t dw      
= PackBits(si
, 15, DemodBuffer
);  
 890         time_t t 
= time(NULL
); 
 891         struct tm tm 
= *localtime(&t
); 
 892         if ( year 
> tm
.tm_year
-110) 
 897         if (config
.Q5
) PrintAndLog("*** Warning *** Info read off a Q5 will not work as expected"); 
 899                 PrintAndLog("The modulation is most likely wrong since the ACL is not 0xE0. "); 
 903         PrintAndLog("-- T55xx Trace Information ----------------------------------"); 
 904         PrintAndLog("-------------------------------------------------------------"); 
 905         PrintAndLog(" ACL Allocation class (ISO/IEC 15963-1)  : 0x%02X (%d)", acl
, acl
); 
 906         PrintAndLog(" MFC Manufacturer ID (ISO/IEC 7816-6)    : 0x%02X (%d) - %s", mfc
, mfc
, getTagInfo(mfc
)); 
 907         PrintAndLog(" CID                                     : 0x%02X (%d) - %s", cid
, cid
, GetModelStrFromCID(cid
)); 
 908         PrintAndLog(" ICR IC Revision                         : %d",icr 
); 
 909         PrintAndLog(" Manufactured"); 
 910         PrintAndLog("     Year/Quarter : %d/%d",year
, quarter
); 
 911         PrintAndLog("     Lot ID       : %d", lotid 
); 
 912         PrintAndLog("     Wafer number : %d", wafer
); 
 913         PrintAndLog("     Die Number   : %d", dw
); 
 914         PrintAndLog("-------------------------------------------------------------"); 
 915         PrintAndLog(" Raw Data - Page 1"); 
 916         PrintAndLog("     Block 1  : 0x%08X  %s", bl1
, sprint_bin(DemodBuffer
+config
.offset
+repeat
,32) ); 
 917         PrintAndLog("     Block 2  : 0x%08X  %s", bl2
, sprint_bin(DemodBuffer
+config
.offset
+repeat
+32,32) ); 
 918         PrintAndLog("-------------------------------------------------------------"); 
 923                 1-8             ACL Allocation class (ISO/IEC 15963-1)  0xE0  
 924                 9-16    MFC Manufacturer ID (ISO/IEC 7816-6)    0x15 Atmel Corporation 
 925                 17-21   CID                                                                             0x1 = Atmel ATA5577M1  0x2 = Atmel ATA5577M2  
 926                 22-24   ICR IC revision 
 927                 25-28   YEAR (BCD encoded)                                              9 (= 2009) 
 928                 29-30   QUARTER                                                                 1,2,3,4  
 934                 18-32   DW,  die number sequential 
 940 int CmdT55xxInfo(const char *Cmd
){ 
 942                 Page 0 Block 0 Configuration data. 
 946         bool pwdmode 
= false; 
 947         uint32_t password 
= 0; 
 948         char cmdp 
= param_getchar(Cmd
, 0); 
 950         if (strlen(Cmd
) > 1 || cmdp 
== 'h' || cmdp 
== 'H') 
 951                 return usage_t55xx_info(); 
 954                 if ( !AquireData( 0, CONFIGURATION_BLOCK
, pwdmode
, password 
) ) 
 957         if (!DecodeT55xxBlock()) return 1; 
 959         if ( DemodBufferLen 
< 32) return 1; 
 961         uint8_t si 
= config
.offset
; 
 962         uint32_t bl0      
= PackBits(si
, 32, DemodBuffer
); 
 964         uint32_t safer    
= PackBits(si
, 4, DemodBuffer
); si 
+= 4;       
 965         uint32_t resv     
= PackBits(si
, 7, DemodBuffer
); si 
+= 7; 
 966         uint32_t dbr      
= PackBits(si
, 3, DemodBuffer
); si 
+= 3; 
 967         uint32_t extend   
= PackBits(si
, 1, DemodBuffer
); si 
+= 1; 
 968         uint32_t datamod  
= PackBits(si
, 5, DemodBuffer
); si 
+= 5; 
 969         uint32_t pskcf    
= PackBits(si
, 2, DemodBuffer
); si 
+= 2; 
 970         uint32_t aor      
= PackBits(si
, 1, DemodBuffer
); si 
+= 1;       
 971         uint32_t otp      
= PackBits(si
, 1, DemodBuffer
); si 
+= 1;       
 972         uint32_t maxblk   
= PackBits(si
, 3, DemodBuffer
); si 
+= 3; 
 973         uint32_t pwd      
= PackBits(si
, 1, DemodBuffer
); si 
+= 1;       
 974         uint32_t sst      
= PackBits(si
, 1, DemodBuffer
); si 
+= 1;       
 975         uint32_t fw       
= PackBits(si
, 1, DemodBuffer
); si 
+= 1; 
 976         uint32_t inv      
= PackBits(si
, 1, DemodBuffer
); si 
+= 1;       
 977         uint32_t por      
= PackBits(si
, 1, DemodBuffer
); si 
+= 1; 
 978         if (config
.Q5
) PrintAndLog("*** Warning *** Config Info read off a Q5 will not display as expected"); 
 980         PrintAndLog("-- T55xx Configuration & Tag Information --------------------"); 
 981         PrintAndLog("-------------------------------------------------------------"); 
 982         PrintAndLog(" Safer key                 : %s", GetSaferStr(safer
)); 
 983         PrintAndLog(" reserved                  : %d", resv
); 
 984         PrintAndLog(" Data bit rate             : %s", GetBitRateStr(dbr
)); 
 985         PrintAndLog(" eXtended mode             : %s", (extend
) ? "Yes - Warning":"No"); 
 986         PrintAndLog(" Modulation                : %s", GetModulationStr(datamod
)); 
 987         PrintAndLog(" PSK clock frequency       : %d", pskcf
); 
 988         PrintAndLog(" AOR - Answer on Request   : %s", (aor
) ? "Yes":"No"); 
 989         PrintAndLog(" OTP - One Time Pad        : %s", (otp
) ? "Yes - Warning":"No" ); 
 990         PrintAndLog(" Max block                 : %d", maxblk
); 
 991         PrintAndLog(" Password mode             : %s", (pwd
) ? "Yes":"No"); 
 992         PrintAndLog(" Sequence Start Terminator : %s", (sst
) ? "Yes":"No"); 
 993         PrintAndLog(" Fast Write                : %s", (fw
)  ? "Yes":"No"); 
 994         PrintAndLog(" Inverse data              : %s", (inv
) ? "Yes":"No"); 
 995         PrintAndLog(" POR-Delay                 : %s", (por
) ? "Yes":"No"); 
 996         PrintAndLog("-------------------------------------------------------------"); 
 997         PrintAndLog(" Raw Data - Page 0"); 
 998         PrintAndLog("     Block 0  : 0x%08X  %s", bl0
, sprint_bin(DemodBuffer
+config
.offset
,32) ); 
 999         PrintAndLog("-------------------------------------------------------------"); 
1004 int CmdT55xxDump(const char *Cmd
){ 
1006         uint32_t password 
= 0; 
1007         char cmdp 
= param_getchar(Cmd
, 0); 
1008         bool override 
= false; 
1009         if ( cmdp 
== 'h' || cmdp 
== 'H') return usage_t55xx_dump(); 
1011         bool usepwd 
= ( strlen(Cmd
) > 0);        
1013                 password 
= param_get32ex(Cmd
, 0, 0, 16); 
1014                 if (param_getchar(Cmd
, 1) =='o' ) 
1018         PrintAndLog("Reading Page 0:");  
1019         PrintAndLog("blk | hex data | binary"); 
1020         for ( uint8_t i 
= 0; i 
<8; ++i
){ 
1021                 T55xxReadBlock(i
, 0, usepwd
, override
, password
); 
1022                 /*memset(s,0,sizeof(s)); 
1025                                 sprintf(s,"b %d p %02x%02x%02x%02x o", i, pwd[0],pwd[1],pwd[2],pwd[3]);                          
1027                                 sprintf(s,"b %d p %02x%02x%02x%02x", i, pwd[0],pwd[1],pwd[2],pwd[3]);                            
1030                         sprintf(s,"b %d", i); 
1032                 CmdT55xxReadBlock(s);*/ 
1034         PrintAndLog("Reading Page 1:");  
1035         PrintAndLog("blk | hex data | binary"); 
1036         for ( uint8_t   i 
= 0; i
<4; i
++){ 
1037                 T55xxReadBlock(i
, 1, usepwd
, override
, password
);                
1042 int AquireData( uint8_t page
, uint8_t block
, bool pwdmode
, uint32_t password 
){ 
1044         uint8_t arg0 
= (page
<<1) | pwdmode
; 
1045         UsbCommand c 
= {CMD_T55XX_READ_BLOCK
, {arg0
, block
, password
}}; 
1047         clearCommandBuffer(); 
1049         if ( !WaitForResponseTimeout(CMD_ACK
,NULL
,2500) ) { 
1050                 PrintAndLog("command execution time out"); 
1055         GetFromBigBuf(got
,sizeof(got
),0); 
1056         WaitForResponse(CMD_ACK
,NULL
); 
1057         setGraphBuf(got
, sizeof(got
)); 
1061 char * GetBitRateStr(uint32_t id
){ 
1062         static char buf
[25]; 
1067                         snprintf(retStr
,sizeof(buf
),"%d - RF/8",id
); 
1070                         snprintf(retStr
,sizeof(buf
),"%d - RF/16",id
); 
1073                         snprintf(retStr
,sizeof(buf
),"%d - RF/32",id
); 
1076                         snprintf(retStr
,sizeof(buf
),"%d - RF/40",id
); 
1079                         snprintf(retStr
,sizeof(buf
),"%d - RF/50",id
); 
1082                         snprintf(retStr
,sizeof(buf
),"%d - RF/64",id
); 
1085                         snprintf(retStr
,sizeof(buf
),"%d - RF/100",id
); 
1088                         snprintf(retStr
,sizeof(buf
),"%d - RF/128",id
); 
1091                         snprintf(retStr
,sizeof(buf
),"%d - (Unknown)",id
); 
1098 char * GetSaferStr(uint32_t id
){ 
1099         static char buf
[40]; 
1102         snprintf(retStr
,sizeof(buf
),"%d",id
); 
1104                 snprintf(retStr
,sizeof(buf
),"%d - passwd",id
); 
1107                 snprintf(retStr
,sizeof(buf
),"%d - testmode",id
); 
1113 char * GetModulationStr( uint32_t id
){ 
1114         static char buf
[60]; 
1119                         snprintf(retStr
,sizeof(buf
),"%d - DIRECT (ASK/NRZ)",id
); 
1122                         snprintf(retStr
,sizeof(buf
),"%d - PSK 1 phase change when input changes",id
); 
1125                         snprintf(retStr
,sizeof(buf
),"%d - PSK 2 phase change on bitclk if input high",id
); 
1128                         snprintf(retStr
,sizeof(buf
),"%d - PSK 3 phase change on rising edge of input",id
); 
1131                         snprintf(retStr
,sizeof(buf
),"%d - FSK 1 RF/8  RF/5",id
); 
1134                         snprintf(retStr
,sizeof(buf
),"%d - FSK 2 RF/8  RF/10",id
); 
1137                         snprintf(retStr
,sizeof(buf
),"%d - FSK 1a RF/5  RF/8",id
); 
1140                         snprintf(retStr
,sizeof(buf
),"%d - FSK 2a RF/10  RF/8",id
); 
1143                         snprintf(retStr
,sizeof(buf
),"%d - Manchester",id
); 
1146                         snprintf(retStr
,sizeof(buf
),"%d - Biphase",id
); 
1149                         snprintf(retStr
,sizeof(buf
),"%d - Biphase a - AKA Conditional Dephase Encoding(CDP)",id
); 
1152                         snprintf(retStr
,sizeof(buf
),"%d - Reserved",id
); 
1155                         snprintf(retStr
,sizeof(buf
),"0x%02X (Unknown)",id
); 
1161 char * GetModelStrFromCID(uint32_t cid
){ 
1163         static char buf
[10]; 
1166         if (cid 
== 1) snprintf(retStr
, sizeof(buf
),"ATA5577M1"); 
1167         if (cid 
== 2) snprintf(retStr
, sizeof(buf
),"ATA5577M2");         
1171 char * GetSelectedModulationStr( uint8_t id
){ 
1173         static char buf
[20]; 
1178                         snprintf(retStr
,sizeof(buf
),"FSK"); 
1181                         snprintf(retStr
,sizeof(buf
),"FSK1"); 
1184                         snprintf(retStr
,sizeof(buf
),"FSK1a"); 
1187                         snprintf(retStr
,sizeof(buf
),"FSK2"); 
1190                         snprintf(retStr
,sizeof(buf
),"FSK2a"); 
1193                         snprintf(retStr
,sizeof(buf
),"ASK"); 
1196                         snprintf(retStr
,sizeof(buf
),"DIRECT/NRZ"); 
1199                         snprintf(retStr
,sizeof(buf
),"PSK1"); 
1202                         snprintf(retStr
,sizeof(buf
),"PSK2"); 
1205                         snprintf(retStr
,sizeof(buf
),"PSK3"); 
1208                         snprintf(retStr
,sizeof(buf
),"BIPHASE"); 
1211                         snprintf(retStr
,sizeof(buf
),"BIPHASEa - (CDP)"); 
1214                         snprintf(retStr
,sizeof(buf
),"(Unknown)"); 
1220 uint32_t PackBits(uint8_t start
, uint8_t len
, uint8_t* bits
){ 
1225         if (len 
> 32) return 0; 
1228         for (; j 
>= 0; --j
, ++i
) 
1229                 tmp     
|= bits
[i
] << j
; 
1234 int CmdResetRead(const char *Cmd
) { 
1235         UsbCommand c 
= {CMD_T55XX_RESET_READ
, {0,0,0}}; 
1237         clearCommandBuffer(); 
1239         if ( !WaitForResponseTimeout(CMD_ACK
,NULL
,2500) ) { 
1240                 PrintAndLog("command execution time out"); 
1244         uint8_t got
[BIGBUF_SIZE
-1]; 
1245         GetFromBigBuf(got
,sizeof(got
),0); 
1246         WaitForResponse(CMD_ACK
,NULL
); 
1247         setGraphBuf(got
, sizeof(got
)); 
1251 int CmdT55xxWipe(const char *Cmd
) { 
1252         char writeData
[20] = {0}; 
1253         char *ptrData 
= writeData
; 
1255         PrintAndLog("\nBeginning Wipe of a T55xx tag (assuming the tag is not password protected)\n"); 
1256         //try with the default password to reset block 0  (with a pwd should work even if pwd bit not set) 
1257         snprintf(ptrData
,sizeof(writeData
),"b %d d 00088040 p 0", blk
); 
1258         if (!CmdT55xxWriteBlock(ptrData
)){ 
1259                 PrintAndLog("Error writing blk %d", blk
); 
1262         for (; blk
<8; blk
++) { 
1263                 snprintf(ptrData
,sizeof(writeData
),"b %d d 0", blk
); 
1264                 if (!CmdT55xxWriteBlock(ptrData
)){ 
1265                         PrintAndLog("Error writing blk %d", blk
); 
1271 static command_t CommandTable
[] = 
1273   {"help",     CmdHelp
,           1, "This help"}, 
1274   {"config",   CmdT55xxSetConfig
, 1, "Set/Get T55XX configuration (modulation, inverted, offset, rate)"}, 
1275   {"detect",   CmdT55xxDetect
,    0, "[1] Try detecting the tag modulation from reading the configuration block."}, 
1276   {"read",     CmdT55xxReadBlock
, 0, "b <block> p [password] [o] [1] -- Read T55xx block data. Optional [p password], [override], [page1]"}, 
1277   {"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)"}, 
1278   {"write",    CmdT55xxWriteBlock
,0, "b <block> d <data> p [password] [1] -- Write T55xx block data. Optional [p password], [page1]"}, 
1279   {"trace",    CmdT55xxReadTrace
, 0, "[1] Show T55x7 traceability data (page 1/ blk 0-1)"}, 
1280   {"info",     CmdT55xxInfo
,      0, "[1] Show T55x7 configuration data (page 0/ blk 0)"}, 
1281   {"dump",     CmdT55xxDump
,      0, "[password] [o] Dump T55xx card block 0-7. Optional [password], [override]"}, 
1282   {"special",  special
,           0, "Show block changes with 64 different offsets"}, 
1283   {"wakeup",   CmdT55xxWakeUp
,    0, "Send AOR wakeup command"}, 
1284   {"wipe",     CmdT55xxWipe
,      0, "Wipe a T55xx tag and set defaults (will destroy any data on tag)"}, 
1285   {NULL
, NULL
, 0, NULL
} 
1288 int CmdLFT55XX(const char *Cmd
) 
1290   CmdsParse(CommandTable
, Cmd
); 
1294 int CmdHelp(const char *Cmd
) 
1296   CmdsHelp(CommandTable
);