]> git.zerfleddert.de Git - proxmark3-svn/blob - client/cmdlft55xx.c
ADD: @marshmellow42 's fixex and resetread t55x7
[proxmark3-svn] / client / cmdlft55xx.c
1 //-----------------------------------------------------------------------------
2 //
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
5 // the license.
6 //-----------------------------------------------------------------------------
7 // Low frequency T55xx commands
8 //-----------------------------------------------------------------------------
9
10 #include <stdio.h>
11 #include <string.h>
12 #include <inttypes.h>
13 #include <time.h>
14 #include "proxmark3.h"
15 #include "ui.h"
16 #include "graph.h"
17 #include "cmdmain.h"
18 #include "cmdparser.h"
19 #include "cmddata.h"
20 #include "cmdlf.h"
21 #include "cmdlft55xx.h"
22 #include "util.h"
23 #include "data.h"
24 #include "lfdemod.h"
25 #include "../common/crc.h"
26 #include "../common/iso14443crc.h"
27 #include "cmdhf14a.h"
28
29 #define T55x7_CONFIGURATION_BLOCK 0x00
30 #define T55x7_PAGE0 0x00
31 #define T55x7_PAGE1 0x01
32 #define T55x7_PWD 0x00000010
33 #define REGULAR_READ_MODE_BLOCK 0xFF
34
35 // Default configuration
36 t55xx_conf_block_t config = { .modulation = DEMOD_ASK, .inverted = FALSE, .offset = 0x00, .block0 = 0x00};
37
38 t55xx_conf_block_t Get_t55xx_Config(){
39 return config;
40 }
41 void Set_t55xx_Config(t55xx_conf_block_t conf){
42 config = conf;
43 }
44
45 int usage_t55xx_config(){
46 PrintAndLog("Usage: lf t55xx config [d <demodulation>] [i 1] [o <offset>]");
47 PrintAndLog("Options:");
48 PrintAndLog(" h This help");
49 PrintAndLog(" b <8|16|32|40|50|64|100|128> Set bitrate");
50 PrintAndLog(" d <FSK|FSK1|FSK1a|FSK2|FSK2a|ASK|PSK1|PSK2|NRZ|BI|BIa> Set demodulation FSK / ASK / PSK / NRZ / Biphase / Biphase A");
51 PrintAndLog(" i [1] Invert data signal, defaults to normal");
52 PrintAndLog(" o [offset] Set offset, where data should start decode in bitstream");
53 PrintAndLog("");
54 PrintAndLog("Examples:");
55 PrintAndLog(" lf t55xx config d FSK - FSK demodulation");
56 PrintAndLog(" lf t55xx config d FSK i 1 - FSK demodulation, inverse data");
57 PrintAndLog(" lf t55xx config d FSK i 1 o 3 - FSK demodulation, inverse data, offset=3,start from position 3 to decode data");
58 PrintAndLog("");
59 return 0;
60 }
61 int usage_t55xx_read(){
62 PrintAndLog("Usage: lf t55xx read [b <block>] [p <password>] <override_safety> <page1>");
63 PrintAndLog("Options:");
64 PrintAndLog(" b <block> - block number to read. Between 0-7");
65 PrintAndLog(" p <password> - OPTIONAL password (8 hex characters)");
66 PrintAndLog(" o - OPTIONAL override safety check");
67 PrintAndLog(" 1 - OPTIONAL read Page 1 instead of Page 0");
68 PrintAndLog(" ****WARNING****");
69 PrintAndLog(" Use of read with password on a tag not configured for a pwd");
70 PrintAndLog(" can damage the tag");
71 PrintAndLog("");
72 PrintAndLog("Examples:");
73 PrintAndLog(" lf t55xx read b 0 - read data from block 0");
74 PrintAndLog(" lf t55xx read b 0 p feedbeef - read data from block 0 password feedbeef");
75 PrintAndLog(" lf t55xx read b 0 p feedbeef o - read data from block 0 password feedbeef safety check");
76 PrintAndLog("");
77 return 0;
78 }
79 int usage_t55xx_write(){
80 PrintAndLog("Usage: lf t55xx wr [b <block>] [d <data>] [p <password>] [1]");
81 PrintAndLog("Options:");
82 PrintAndLog(" b <block> - block number to write. Between 0-7");
83 PrintAndLog(" d <data> - 4 bytes of data to write (8 hex characters)");
84 PrintAndLog(" p <password> - OPTIONAL password 4bytes (8 hex characters)");
85 PrintAndLog(" 1 - OPTIONAL write Page 1 instead of Page 0");
86 PrintAndLog("");
87 PrintAndLog("Examples:");
88 PrintAndLog(" lf t55xx write b 3 d 11223344 - write 11223344 to block 3");
89 PrintAndLog(" lf t55xx write b 3 d 11223344 p feedbeef - write 11223344 to block 3 password feedbeef");
90 PrintAndLog("");
91 return 0;
92 }
93 int usage_t55xx_trace() {
94 PrintAndLog("Usage: lf t55xx trace [1]");
95 PrintAndLog("Options:");
96 PrintAndLog(" [graph buffer data] - if set, use Graphbuffer otherwise read data from tag.");
97 PrintAndLog("");
98 PrintAndLog("Examples:");
99 PrintAndLog(" lf t55xx trace");
100 PrintAndLog(" lf t55xx trace 1");
101 PrintAndLog("");
102 return 0;
103 }
104 int usage_t55xx_info() {
105 PrintAndLog("Usage: lf t55xx info [1]");
106 PrintAndLog("Options:");
107 PrintAndLog(" [graph buffer data] - if set, use Graphbuffer otherwise read data from tag.");
108 PrintAndLog("");
109 PrintAndLog("Examples:");
110 PrintAndLog(" lf t55xx info");
111 PrintAndLog(" lf t55xx info 1");
112 PrintAndLog("");
113 return 0;
114 }
115 int usage_t55xx_dump(){
116 PrintAndLog("Usage: lf t55xx dump <password> [o]");
117 PrintAndLog("Options:");
118 PrintAndLog(" <password> - OPTIONAL password 4bytes (8 hex symbols)");
119 PrintAndLog(" o - OPTIONAL override, force pwd read despite danger to card");
120 PrintAndLog("");
121 PrintAndLog("Examples:");
122 PrintAndLog(" lf t55xx dump");
123 PrintAndLog(" lf t55xx dump feedbeef o");
124 PrintAndLog("");
125 return 0;
126 }
127 int usage_t55xx_detect(){
128 PrintAndLog("Usage: lf t55xx detect [1]");
129 PrintAndLog("Options:");
130 PrintAndLog(" [graph buffer data] - if set, use Graphbuffer otherwise read data from tag.");
131 PrintAndLog("");
132 PrintAndLog("Examples:");
133 PrintAndLog(" lf t55xx detect");
134 PrintAndLog(" lf t55xx detect 1");
135 PrintAndLog("");
136 return 0;
137 }
138 int usage_t55xx_wakup(){
139 PrintAndLog("Usage: lf t55xx wakeup [h] p <password>");
140 PrintAndLog("This commands send the Answer-On-Request command and leaves the readerfield ON afterwards.");
141 PrintAndLog("Options:");
142 PrintAndLog(" h - this help");
143 PrintAndLog(" p <password> - password 4bytes (8 hex symbols)");
144 PrintAndLog("");
145 PrintAndLog("Examples:");
146 PrintAndLog(" lf t55xx wakeup p 11223344 - send wakeup password");
147 return 0;
148 }
149
150 static int CmdHelp(const char *Cmd);
151
152 int CmdT55xxSetConfig(const char *Cmd) {
153
154 uint8_t offset = 0;
155 bool errors = FALSE;
156 uint8_t cmdp = 0;
157 char modulation[5] = {0x00};
158 char tmp = 0x00;
159 uint8_t bitRate = 0;
160 uint8_t rates[9] = {8,16,32,40,50,64,100,128,0};
161 while(param_getchar(Cmd, cmdp) != 0x00 && !errors) {
162 tmp = param_getchar(Cmd, cmdp);
163 switch(tmp)
164 {
165 case 'h':
166 case 'H':
167 return usage_t55xx_config();
168 case 'b':
169 errors |= param_getdec(Cmd, cmdp+1, &bitRate);
170 if ( !errors){
171 uint8_t i = 0;
172 for (; i < 9; i++){
173 if (rates[i]==bitRate) {
174 config.bitrate = i;
175 break;
176 }
177 }
178 if (i==9) errors = TRUE;
179 }
180 cmdp+=2;
181 break;
182 case 'd':
183 param_getstr(Cmd, cmdp+1, modulation);
184 cmdp += 2;
185
186 if ( strcmp(modulation, "FSK" ) == 0) {
187 config.modulation = DEMOD_FSK;
188 } else if ( strcmp(modulation, "FSK1" ) == 0) {
189 config.modulation = DEMOD_FSK1;
190 config.inverted=1;
191 } else if ( strcmp(modulation, "FSK1a" ) == 0) {
192 config.modulation = DEMOD_FSK1a;
193 config.inverted=0;
194 } else if ( strcmp(modulation, "FSK2" ) == 0) {
195 config.modulation = DEMOD_FSK2;
196 config.inverted=0;
197 } else if ( strcmp(modulation, "FSK2a" ) == 0) {
198 config.modulation = DEMOD_FSK2a;
199 config.inverted=1;
200 } else if ( strcmp(modulation, "ASK" ) == 0) {
201 config.modulation = DEMOD_ASK;
202 } else if ( strcmp(modulation, "NRZ" ) == 0) {
203 config.modulation = DEMOD_NRZ;
204 } else if ( strcmp(modulation, "PSK1" ) == 0) {
205 config.modulation = DEMOD_PSK1;
206 } else if ( strcmp(modulation, "PSK2" ) == 0) {
207 config.modulation = DEMOD_PSK2;
208 } else if ( strcmp(modulation, "PSK3" ) == 0) {
209 config.modulation = DEMOD_PSK3;
210 } else if ( strcmp(modulation, "BIa" ) == 0) {
211 config.modulation = DEMOD_BIa;
212 config.inverted=1;
213 } else if ( strcmp(modulation, "BI" ) == 0) {
214 config.modulation = DEMOD_BI;
215 config.inverted=0;
216 } else {
217 PrintAndLog("Unknown modulation '%s'", modulation);
218 errors = TRUE;
219 }
220 break;
221 case 'i':
222 config.inverted = param_getchar(Cmd,cmdp+1) == '1';
223 cmdp+=2;
224 break;
225 case 'o':
226 errors |= param_getdec(Cmd, cmdp+1, &offset);
227 if ( !errors )
228 config.offset = offset;
229 cmdp+=2;
230 break;
231 default:
232 PrintAndLog("Unknown parameter '%c'", param_getchar(Cmd, cmdp));
233 errors = TRUE;
234 break;
235 }
236 }
237
238 // No args
239 if (cmdp == 0) return printConfiguration( config );
240
241 //Validations
242 if (errors) return usage_t55xx_config();
243
244 config.block0 = 0;
245 return printConfiguration ( config );
246 }
247
248 int T55xxReadBlock(uint8_t block, bool page1, bool usepwd, bool override, uint32_t password){
249 //Password mode
250 if ( usepwd ) {
251 // try reading the config block and verify that PWD bit is set before doing this!
252 if ( !override ) {
253
254 if ( !AquireData(T55x7_PAGE0, T55x7_CONFIGURATION_BLOCK, false, 0 ) ) return 0;
255
256 if ( !tryDetectModulation() ) {
257 PrintAndLog("Safety Check: Could not detect if PWD bit is set in config block. Exits.");
258 return 0;
259 } else {
260 PrintAndLog("Safety Check: PWD bit is NOT set in config block. Reading without password...");
261 usepwd = false;
262 page1 = false;
263 }
264 } else {
265 PrintAndLog("Safety Check Overriden - proceeding despite risk");
266 }
267 }
268
269 if (!AquireData(page1, block, usepwd, password) ) return 0;
270 if (!DecodeT55xxBlock()) return 0;
271
272 char blk[10]={0};
273 sprintf(blk,"%d", block);
274 printT55xxBlock(blk);
275 return 1;
276 }
277
278 int CmdT55xxReadBlock(const char *Cmd) {
279 uint8_t block = REGULAR_READ_MODE_BLOCK;
280 uint32_t password = 0; //default to blank Block 7
281 bool usepwd = false;
282 bool override = false;
283 bool page1 = false;
284 bool errors = false;
285 uint8_t cmdp = 0;
286 while(param_getchar(Cmd, cmdp) != 0x00 && !errors) {
287 switch(param_getchar(Cmd, cmdp)) {
288 case 'h':
289 case 'H':
290 return usage_t55xx_read();
291 case 'b':
292 case 'B':
293 errors |= param_getdec(Cmd, cmdp+1, &block);
294 cmdp += 2;
295 break;
296 case 'o':
297 case 'O':
298 override = TRUE;
299 cmdp++;
300 break;
301 case 'p':
302 case 'P':
303 password = param_get32ex(Cmd, cmdp+1, 0, 16);
304 usepwd = true;
305 cmdp += 2;
306 break;
307 case '1':
308 page1 = true;
309 cmdp++;
310 break;
311 default:
312 PrintAndLog("Unknown parameter '%c'", param_getchar(Cmd, cmdp));
313 errors = true;
314 break;
315 }
316 }
317 if (errors) return usage_t55xx_read();
318
319 if (block > 7 && block != REGULAR_READ_MODE_BLOCK ) {
320 PrintAndLog("Block must be between 0 and 7");
321 return 0;
322 }
323 PrintAndLog("Reading Page %d:", page1);
324 PrintAndLog("blk | hex data | binary");
325 return T55xxReadBlock(block, page1, usepwd, override, password);
326 }
327
328 bool DecodeT55xxBlock(){
329
330 char buf[30] = {0x00};
331 char *cmdStr = buf;
332 int ans = 0;
333 uint8_t bitRate[8] = {8,16,32,40,50,64,100,128};
334 DemodBufferLen = 0x00;
335
336 switch( config.modulation ){
337 case DEMOD_FSK:
338 snprintf(cmdStr, sizeof(buf),"%d %d", bitRate[config.bitrate], config.inverted );
339 ans = FSKrawDemod(cmdStr, FALSE);
340 break;
341 case DEMOD_FSK1:
342 case DEMOD_FSK1a:
343 snprintf(cmdStr, sizeof(buf),"%d %d 8 5", bitRate[config.bitrate], config.inverted );
344 ans = FSKrawDemod(cmdStr, FALSE);
345 break;
346 case DEMOD_FSK2:
347 case DEMOD_FSK2a:
348 snprintf(cmdStr, sizeof(buf),"%d %d 10 8", bitRate[config.bitrate], config.inverted );
349 ans = FSKrawDemod(cmdStr, FALSE);
350 break;
351 case DEMOD_ASK:
352 snprintf(cmdStr, sizeof(buf),"%d %d 0", bitRate[config.bitrate], config.inverted );
353 ans = ASKDemod(cmdStr, FALSE, FALSE, 1);
354 break;
355 case DEMOD_PSK1:
356 snprintf(cmdStr, sizeof(buf),"%d %d 0", bitRate[config.bitrate], config.inverted );
357 ans = PSKDemod(cmdStr, FALSE);
358 break;
359 case DEMOD_PSK2: //inverted won't affect this
360 case DEMOD_PSK3: //not fully implemented
361 snprintf(cmdStr, sizeof(buf),"%d 0 1", bitRate[config.bitrate] );
362 ans = PSKDemod(cmdStr, FALSE);
363 psk1TOpsk2(DemodBuffer, DemodBufferLen);
364 break;
365 case DEMOD_NRZ:
366 snprintf(cmdStr, sizeof(buf),"%d %d 1", bitRate[config.bitrate], config.inverted );
367 ans = NRZrawDemod(cmdStr, FALSE);
368 break;
369 case DEMOD_BI:
370 case DEMOD_BIa:
371 snprintf(cmdStr, sizeof(buf),"0 %d %d 0", bitRate[config.bitrate], config.inverted );
372 ans = ASKbiphaseDemod(cmdStr, FALSE);
373 break;
374 default:
375 return FALSE;
376 }
377 return (bool) ans;
378 }
379
380 int CmdT55xxDetect(const char *Cmd){
381
382 bool override = false;
383 //bool pwdmode = false;
384
385 uint32_t password = 0; //default to blank Block 7
386 bool usepwd = ( strlen(Cmd) > 0);
387 if ( usepwd ){
388 password = param_get32ex(Cmd, 0, 0, 16);
389 if (param_getchar(Cmd, 1) =='o' )
390 override = true;
391 }
392
393 char cmdp = param_getchar(Cmd, 0);
394 if (strlen(Cmd) > 1 || cmdp == 'h' || cmdp == 'H') return usage_t55xx_detect();
395
396 if (strlen(Cmd)==0) {
397 password = param_get32ex(Cmd, 0, 0, 16);
398 if (param_getchar(Cmd, 1) =='o' ) override = true;
399 }
400
401 if ( !AquireData(T55x7_PAGE0, T55x7_CONFIGURATION_BLOCK, usepwd, password) )
402 return 0;
403
404 if ( !tryDetectModulation() )
405 PrintAndLog("Could not detect modulation automatically. Try setting it manually with \'lf t55xx config\'");
406
407 return 1;
408 }
409
410 // detect configuration?
411 bool tryDetectModulation(){
412 uint8_t hits = 0;
413 t55xx_conf_block_t tests[15];
414 int bitRate=0;
415 uint8_t fc1 = 0, fc2 = 0, clk=0;
416 save_restoreGB(1);
417 if (GetFskClock("", FALSE, FALSE)){
418 fskClocks(&fc1, &fc2, &clk, FALSE);
419 if ( FSKrawDemod("0 0", FALSE) && test(DEMOD_FSK, &tests[hits].offset, &bitRate)){
420 tests[hits].modulation = DEMOD_FSK;
421 if (fc1==8 && fc2 == 5)
422 tests[hits].modulation = DEMOD_FSK1a;
423 else if (fc1==10 && fc2 == 8)
424 tests[hits].modulation = DEMOD_FSK2;
425 tests[hits].bitrate = bitRate;
426 tests[hits].inverted = FALSE;
427 tests[hits].block0 = PackBits(tests[hits].offset, 32, DemodBuffer);
428 ++hits;
429 }
430 if ( FSKrawDemod("0 1", FALSE) && test(DEMOD_FSK, &tests[hits].offset, &bitRate)) {
431 tests[hits].modulation = DEMOD_FSK;
432 if (fc1 == 8 && fc2 == 5)
433 tests[hits].modulation = DEMOD_FSK1;
434 else if (fc1 == 10 && fc2 == 8)
435 tests[hits].modulation = DEMOD_FSK2a;
436
437 tests[hits].bitrate = bitRate;
438 tests[hits].inverted = TRUE;
439 tests[hits].block0 = PackBits(tests[hits].offset, 32, DemodBuffer);
440 ++hits;
441 }
442 } else {
443 clk = GetAskClock("", FALSE, FALSE);
444 if (clk>0) {
445 if ( ASKDemod("0 0 0", FALSE, FALSE, 1) && test(DEMOD_ASK, &tests[hits].offset, &bitRate)) {
446 tests[hits].modulation = DEMOD_ASK;
447 tests[hits].bitrate = bitRate;
448 tests[hits].inverted = FALSE;
449 tests[hits].block0 = PackBits(tests[hits].offset, 32, DemodBuffer);
450 ++hits;
451 }
452 if ( ASKDemod("0 1 0", FALSE, FALSE, 1) && test(DEMOD_ASK, &tests[hits].offset, &bitRate)) {
453 tests[hits].modulation = DEMOD_ASK;
454 tests[hits].bitrate = bitRate;
455 tests[hits].inverted = TRUE;
456 tests[hits].block0 = PackBits(tests[hits].offset, 32, DemodBuffer);
457 ++hits;
458 }
459 if ( ASKbiphaseDemod("0 0 0 0", FALSE) && test(DEMOD_BI, &tests[hits].offset, &bitRate) ) {
460 tests[hits].modulation = DEMOD_BI;
461 tests[hits].bitrate = bitRate;
462 tests[hits].inverted = FALSE;
463 tests[hits].block0 = PackBits(tests[hits].offset, 32, DemodBuffer);
464 ++hits;
465 }
466 if ( ASKbiphaseDemod("0 0 1 0", FALSE) && test(DEMOD_BIa, &tests[hits].offset, &bitRate) ) {
467 tests[hits].modulation = DEMOD_BIa;
468 tests[hits].bitrate = bitRate;
469 tests[hits].inverted = TRUE;
470 tests[hits].block0 = PackBits(tests[hits].offset, 32, DemodBuffer);
471 ++hits;
472 }
473 }
474 //undo trim from ask
475 save_restoreGB(0);
476 clk = GetNrzClock("", FALSE, FALSE);
477 if (clk>0) {
478 if ( NRZrawDemod("0 0 1", FALSE) && test(DEMOD_NRZ, &tests[hits].offset, &bitRate)) {
479 tests[hits].modulation = DEMOD_NRZ;
480 tests[hits].bitrate = bitRate;
481 tests[hits].inverted = FALSE;
482 tests[hits].block0 = PackBits(tests[hits].offset, 32, DemodBuffer);
483 ++hits;
484 }
485
486 if ( NRZrawDemod("0 1 1", FALSE) && test(DEMOD_NRZ, &tests[hits].offset, &bitRate)) {
487 tests[hits].modulation = DEMOD_NRZ;
488 tests[hits].bitrate = bitRate;
489 tests[hits].inverted = TRUE;
490 tests[hits].block0 = PackBits(tests[hits].offset, 32, DemodBuffer);
491 ++hits;
492 }
493 }
494
495 //undo trim from nrz
496 save_restoreGB(0);
497 clk = GetPskClock("", FALSE, FALSE);
498 if (clk>0) {
499 if ( PSKDemod("0 0 1", FALSE) && test(DEMOD_PSK1, &tests[hits].offset, &bitRate)) {
500 tests[hits].modulation = DEMOD_PSK1;
501 tests[hits].bitrate = bitRate;
502 tests[hits].inverted = FALSE;
503 tests[hits].block0 = PackBits(tests[hits].offset, 32, DemodBuffer);
504 ++hits;
505 }
506 if ( PSKDemod("0 1 1", FALSE) && test(DEMOD_PSK1, &tests[hits].offset, &bitRate)) {
507 tests[hits].modulation = DEMOD_PSK1;
508 tests[hits].bitrate = bitRate;
509 tests[hits].inverted = TRUE;
510 tests[hits].block0 = PackBits(tests[hits].offset, 32, DemodBuffer);
511 ++hits;
512 }
513 // PSK2 - needs a call to psk1TOpsk2.
514 if ( PSKDemod("0 0 1", FALSE)) {
515 psk1TOpsk2(DemodBuffer, DemodBufferLen);
516 if (test(DEMOD_PSK2, &tests[hits].offset, &bitRate)){
517 tests[hits].modulation = DEMOD_PSK2;
518 tests[hits].bitrate = bitRate;
519 tests[hits].inverted = FALSE;
520 tests[hits].block0 = PackBits(tests[hits].offset, 32, DemodBuffer);
521 ++hits;
522 }
523 } // inverse waves does not affect this demod
524 // PSK3 - needs a call to psk1TOpsk2.
525 if ( PSKDemod("0 0 1", FALSE)) {
526 psk1TOpsk2(DemodBuffer, DemodBufferLen);
527 if (test(DEMOD_PSK3, &tests[hits].offset, &bitRate)){
528 tests[hits].modulation = DEMOD_PSK3;
529 tests[hits].bitrate = bitRate;
530 tests[hits].inverted = FALSE;
531 tests[hits].block0 = PackBits(tests[hits].offset, 32, DemodBuffer);
532 ++hits;
533 }
534 } // inverse waves does not affect this demod
535 }
536 }
537 if ( hits == 1) {
538 config.modulation = tests[0].modulation;
539 config.bitrate = tests[0].bitrate;
540 config.inverted = tests[0].inverted;
541 config.offset = tests[0].offset;
542 config.block0 = tests[0].block0;
543 printConfiguration( config );
544 return TRUE;
545 }
546
547 if ( hits > 1) {
548 PrintAndLog("Found [%d] possible matches for modulation.",hits);
549 for(int i=0; i<hits; ++i){
550 PrintAndLog("--[%d]---------------", i+1);
551 printConfiguration( tests[i] );
552 }
553 }
554 return FALSE;
555 }
556
557 bool testModulation(uint8_t mode, uint8_t modread){
558 switch( mode ){
559 case DEMOD_FSK:
560 if (modread >= DEMOD_FSK1 && modread <= DEMOD_FSK2a) return TRUE;
561 break;
562 case DEMOD_ASK:
563 if (modread == DEMOD_ASK) return TRUE;
564 break;
565 case DEMOD_PSK1:
566 if (modread == DEMOD_PSK1) return TRUE;
567 break;
568 case DEMOD_PSK2:
569 if (modread == DEMOD_PSK2) return TRUE;
570 break;
571 case DEMOD_PSK3:
572 if (modread == DEMOD_PSK3) return TRUE;
573 break;
574 case DEMOD_NRZ:
575 if (modread == DEMOD_NRZ) return TRUE;
576 break;
577 case DEMOD_BI:
578 if (modread == DEMOD_BI) return TRUE;
579 break;
580 case DEMOD_BIa:
581 if (modread == DEMOD_BIa) return TRUE;
582 break;
583 default:
584 return FALSE;
585 }
586 return FALSE;
587 }
588
589 bool testBitRate(uint8_t readRate, uint8_t mod){
590 uint8_t expected[8] = {8, 16, 32, 40, 50, 64, 100, 128};
591 uint8_t detRate = 0;
592 switch( mod ){
593 case DEMOD_FSK:
594 case DEMOD_FSK1:
595 case DEMOD_FSK1a:
596 case DEMOD_FSK2:
597 case DEMOD_FSK2a:
598 detRate = GetFskClock("",FALSE, FALSE);
599 if (expected[readRate] == detRate)
600 return TRUE;
601 break;
602 case DEMOD_ASK:
603 case DEMOD_BI:
604 case DEMOD_BIa:
605 detRate = GetAskClock("",FALSE, FALSE);
606 if (expected[readRate] == detRate)
607 return TRUE;
608 break;
609 case DEMOD_PSK1:
610 case DEMOD_PSK2:
611 case DEMOD_PSK3:
612 detRate = GetPskClock("",FALSE, FALSE);
613 if (expected[readRate] == detRate)
614 return TRUE;
615 break;
616 case DEMOD_NRZ:
617 detRate = GetNrzClock("",FALSE, FALSE);
618 if (expected[readRate] == detRate)
619 return TRUE;
620 break;
621 default:
622 return FALSE;
623 }
624 return FALSE;
625 }
626
627 bool test(uint8_t mode, uint8_t *offset, int *fndBitRate){
628
629 if ( DemodBufferLen < 64 ) return FALSE;
630 uint8_t si = 0;
631 for (uint8_t idx = 0; idx < 64; idx++){
632 si = idx;
633 if ( PackBits(si, 32, DemodBuffer) == 0x00 ) continue;
634
635 uint8_t safer = PackBits(si, 4, DemodBuffer); si += 4; //master key
636 uint8_t resv = PackBits(si, 4, DemodBuffer); si += 4; //was 7 & +=7+3 //should be only 4 bits if extended mode
637 // 2nibble must be zeroed.
638 // moved test to here, since this gets most faults first.
639 if ( resv > 0x00) continue;
640
641 uint8_t xtRate = PackBits(si, 3, DemodBuffer); si += 3; //extended mode part of rate
642 int bitRate = PackBits(si, 3, DemodBuffer); si += 3; //bit rate
643 if (bitRate > 7) continue;
644 uint8_t extend = PackBits(si, 1, DemodBuffer); si += 1; //bit 15 extended mode
645 uint8_t modread = PackBits(si, 5, DemodBuffer); si += 5+2+1;
646 //uint8_t pskcr = PackBits(si, 2, DemodBuffer); si += 2+1; //could check psk cr
647 uint8_t nml01 = PackBits(si, 1, DemodBuffer); si += 1+5; //bit 24, 30, 31 could be tested for 0 if not extended mode
648 uint8_t nml02 = PackBits(si, 2, DemodBuffer); si += 2;
649
650 //if extended mode
651 bool extMode =( (safer == 0x6 || safer == 0x9) && extend) ? TRUE : FALSE;
652
653 if (!extMode){
654 if (nml01 || nml02 || xtRate) continue;
655 }
656 //test modulation
657 if (!testModulation(mode, modread)) continue;
658 if (!testBitRate(bitRate, mode)) continue;
659 *fndBitRate = bitRate;
660 *offset = idx;
661 return TRUE;
662 }
663 return FALSE;
664 }
665
666 void printT55xxBlock(const char *blockNum){
667
668 uint8_t i = config.offset;
669 uint8_t endpos = 32 + i;
670 uint32_t blockData = 0;
671 uint8_t bits[64] = {0x00};
672
673 if ( !DemodBufferLen) return;
674
675 if ( endpos > DemodBufferLen){
676 PrintAndLog("The configured offset %d is too big. Possible offset: %d)", i, DemodBufferLen-32);
677 return;
678 }
679
680 for (; i < endpos; ++i)
681 bits[i - config.offset] = DemodBuffer[i];
682
683 blockData = PackBits(0, 32, bits);
684 PrintAndLog("%s | %08X | %s", blockNum, blockData, sprint_bin(bits,32));
685 }
686
687 int special(const char *Cmd) {
688 uint32_t blockData = 0;
689 uint8_t bits[32] = {0x00};
690
691 PrintAndLog("OFFSET | DATA | BINARY");
692 PrintAndLog("----------------------------------------------------");
693 int i,j = 0;
694 for (; j < 64; ++j){
695
696 for (i = 0; i < 32; ++i)
697 bits[i]=DemodBuffer[j+i];
698
699 blockData = PackBits(0, 32, bits);
700
701 PrintAndLog("%02d | 0x%08X | %s",j , blockData, sprint_bin(bits,32));
702 }
703 return 0;
704 }
705
706 int printConfiguration( t55xx_conf_block_t b){
707 PrintAndLog("Modulation : %s", GetSelectedModulationStr(b.modulation) );
708 PrintAndLog("Bit Rate : %s", GetBitRateStr(b.bitrate) );
709 PrintAndLog("Inverted : %s", (b.inverted) ? "Yes" : "No" );
710 PrintAndLog("Offset : %d", b.offset);
711 PrintAndLog("Block0 : 0x%08X", b.block0);
712 PrintAndLog("");
713 return 0;
714 }
715
716 int CmdT55xxWakeUp(const char *Cmd) {
717 uint32_t password = 0;
718 uint8_t cmdp = 0;
719 bool errors = false;
720 while(param_getchar(Cmd, cmdp) != 0x00 && !errors) {
721 switch(param_getchar(Cmd, cmdp)) {
722 case 'h':
723 case 'H':
724 return usage_t55xx_wakup();
725 case 'p':
726 case 'P':
727 password = param_get32ex(Cmd, cmdp+1, 0, 16);
728 cmdp += 2;
729 errors = false;
730 break;
731 default:
732 PrintAndLog("Unknown parameter '%c'", param_getchar(Cmd, cmdp));
733 errors = true;
734 break;
735 }
736 }
737 if (errors) return usage_t55xx_wakup();
738
739 UsbCommand c = {CMD_T55XX_WAKEUP, {password, 0, 0}};
740 clearCommandBuffer();
741 SendCommand(&c);
742 PrintAndLog("Wake up command sent. Try read now");
743 return 0;
744 }
745
746 int CmdT55xxWriteBlock(const char *Cmd) {
747 uint8_t block = 0xFF; //default to invalid block
748 uint32_t data = 0; //default to blank Block
749 uint32_t password = 0; //default to blank Block 7
750 bool usepwd = false;
751 bool page1 = false;
752 bool gotdata = false;
753 bool errors = false;
754 uint8_t cmdp = 0;
755 while(param_getchar(Cmd, cmdp) != 0x00 && !errors) {
756 switch(param_getchar(Cmd, cmdp)) {
757 case 'h':
758 case 'H':
759 return usage_t55xx_write();
760 case 'b':
761 case 'B':
762 errors |= param_getdec(Cmd, cmdp+1, &block);
763 cmdp += 2;
764 break;
765 case 'd':
766 case 'D':
767 data = param_get32ex(Cmd, cmdp+1, 0, 16);
768 gotdata = true;
769 cmdp += 2;
770 break;
771 case 'p':
772 case 'P':
773 password = param_get32ex(Cmd, cmdp+1, 0, 16);
774 usepwd = true;
775 cmdp += 2;
776 break;
777 case '1':
778 page1 = true;
779 cmdp++;
780 break;
781 default:
782 PrintAndLog("Unknown parameter '%c'", param_getchar(Cmd, cmdp));
783 errors = true;
784 break;
785 }
786 }
787 if (errors || !gotdata) return usage_t55xx_write();
788
789 if (block > 7) {
790 PrintAndLog("Block number must be between 0 and 7");
791 return 0;
792 }
793
794 UsbCommand c = {CMD_T55XX_WRITE_BLOCK, {data, block, 0}};
795 UsbCommand resp;
796 c.d.asBytes[0] = (page1) ? 0x2 : 0;
797
798 PrintAndLog("Writing to page: %d block: %d data : 0x%08X", page1, block, data);
799
800 //Password mode
801 if (usepwd) {
802 c.arg[2] = password;
803 c.d.asBytes[0] |= 0x1;
804 PrintAndLog("pwd : 0x%08X", password);
805 }
806 clearCommandBuffer();
807 SendCommand(&c);
808 if (!WaitForResponseTimeout(CMD_ACK, &resp, 1000)){
809 PrintAndLog("Error occurred, device did not ACK write operation. (May be due to old firmware)");
810 return 0;
811 }
812 return 1;
813 }
814
815 int CmdT55xxReadTrace(const char *Cmd) {
816 char cmdp = param_getchar(Cmd, 0);
817 bool pwdmode = false;
818 uint32_t password = 0;
819 if (strlen(Cmd) > 1 || cmdp == 'h' || cmdp == 'H') return usage_t55xx_trace();
820
821 if (strlen(Cmd)==0)
822 if ( !AquireData( T55x7_PAGE1, REGULAR_READ_MODE_BLOCK, pwdmode, password ) )
823 return 0;
824
825 if (!DecodeT55xxBlock()) return 0;
826
827 if ( !DemodBufferLen) return 0;
828
829 RepaintGraphWindow();
830 uint8_t repeat = 0;
831 if (config.offset > 5)
832 repeat = 32;
833 uint8_t si = config.offset+repeat;
834 uint32_t bl1 = PackBits(si, 32, DemodBuffer);
835 uint32_t bl2 = PackBits(si+32, 32, DemodBuffer);
836
837 uint32_t acl = PackBits(si, 8, DemodBuffer); si += 8;
838 uint32_t mfc = PackBits(si, 8, DemodBuffer); si += 8;
839 uint32_t cid = PackBits(si, 5, DemodBuffer); si += 5;
840 uint32_t icr = PackBits(si, 3, DemodBuffer); si += 3;
841 uint32_t year = PackBits(si, 4, DemodBuffer); si += 4;
842 uint32_t quarter = PackBits(si, 2, DemodBuffer); si += 2;
843 uint32_t lotid = PackBits(si, 14, DemodBuffer); si += 14;
844 uint32_t wafer = PackBits(si, 5, DemodBuffer); si += 5;
845 uint32_t dw = PackBits(si, 15, DemodBuffer);
846
847 time_t t = time(NULL);
848 struct tm tm = *localtime(&t);
849 if ( year > tm.tm_year-110)
850 year += 2000;
851 else
852 year += 2010;
853
854 if ( acl != 0xE0 ) {
855 PrintAndLog("The modulation is most likely wrong since the ACL is not 0xE0. ");
856 return 0;
857 }
858
859 PrintAndLog("");
860 PrintAndLog("-- T55xx Trace Information ----------------------------------");
861 PrintAndLog("-------------------------------------------------------------");
862 PrintAndLog(" ACL Allocation class (ISO/IEC 15963-1) : 0x%02X (%d)", acl, acl);
863 PrintAndLog(" MFC Manufacturer ID (ISO/IEC 7816-6) : 0x%02X (%d) - %s", mfc, mfc, getTagInfo(mfc));
864 PrintAndLog(" CID : 0x%02X (%d) - %s", cid, cid, GetModelStrFromCID(cid));
865 PrintAndLog(" ICR IC Revision : %d",icr );
866 PrintAndLog(" Manufactured");
867 PrintAndLog(" Year/Quarter : %d/%d",year, quarter);
868 PrintAndLog(" Lot ID : %d", lotid );
869 PrintAndLog(" Wafer number : %d", wafer);
870 PrintAndLog(" Die Number : %d", dw);
871 PrintAndLog("-------------------------------------------------------------");
872 PrintAndLog(" Raw Data - Page 1");
873 PrintAndLog(" Block 1 : 0x%08X %s", bl1, sprint_bin(DemodBuffer+config.offset+repeat,32) );
874 PrintAndLog(" Block 2 : 0x%08X %s", bl2, sprint_bin(DemodBuffer+config.offset+repeat+32,32) );
875 PrintAndLog("-------------------------------------------------------------");
876
877 /*
878 TRACE - BLOCK O
879 Bits Definition HEX
880 1-8 ACL Allocation class (ISO/IEC 15963-1) 0xE0
881 9-16 MFC Manufacturer ID (ISO/IEC 7816-6) 0x15 Atmel Corporation
882 17-21 CID 0x1 = Atmel ATA5577M1 0x2 = Atmel ATA5577M2
883 22-24 ICR IC revision
884 25-28 YEAR (BCD encoded) 9 (= 2009)
885 29-30 QUARTER 1,2,3,4
886 31-32 LOT ID
887
888 TRACE - BLOCK 1
889 1-12 LOT ID
890 13-17 Wafer number
891 18-32 DW, die number sequential
892 */
893
894 return 0;
895 }
896
897 int CmdT55xxInfo(const char *Cmd){
898 /*
899 Page 0 Block 0 Configuration data.
900 Normal mode
901 Extended mode
902 */
903 bool pwdmode = false;
904 uint32_t password = 0;
905 char cmdp = param_getchar(Cmd, 0);
906
907 if (strlen(Cmd) > 1 || cmdp == 'h' || cmdp == 'H') return usage_t55xx_info();
908
909 if (strlen(Cmd)==0)
910 if ( !AquireData( T55x7_PAGE0, T55x7_CONFIGURATION_BLOCK, pwdmode, password ) )
911 return 1;
912
913 if (!DecodeT55xxBlock()) return 1;
914
915 if ( DemodBufferLen < 32) return 1;
916
917 uint8_t si = config.offset;
918 uint32_t bl0 = PackBits(si, 32, DemodBuffer);
919
920 uint32_t safer = PackBits(si, 4, DemodBuffer); si += 4;
921 uint32_t resv = PackBits(si, 7, DemodBuffer); si += 7;
922 uint32_t dbr = PackBits(si, 3, DemodBuffer); si += 3;
923 uint32_t extend = PackBits(si, 1, DemodBuffer); si += 1;
924 uint32_t datamod = PackBits(si, 5, DemodBuffer); si += 5;
925 uint32_t pskcf = PackBits(si, 2, DemodBuffer); si += 2;
926 uint32_t aor = PackBits(si, 1, DemodBuffer); si += 1;
927 uint32_t otp = PackBits(si, 1, DemodBuffer); si += 1;
928 uint32_t maxblk = PackBits(si, 3, DemodBuffer); si += 3;
929 uint32_t pwd = PackBits(si, 1, DemodBuffer); si += 1;
930 uint32_t sst = PackBits(si, 1, DemodBuffer); si += 1;
931 uint32_t fw = PackBits(si, 1, DemodBuffer); si += 1;
932 uint32_t inv = PackBits(si, 1, DemodBuffer); si += 1;
933 uint32_t por = PackBits(si, 1, DemodBuffer); si += 1;
934
935 PrintAndLog("");
936 PrintAndLog("-- T55xx Configuration & Tag Information --------------------");
937 PrintAndLog("-------------------------------------------------------------");
938 PrintAndLog(" Safer key : %s", GetSaferStr(safer));
939 PrintAndLog(" reserved : %d", resv);
940 PrintAndLog(" Data bit rate : %s", GetBitRateStr(dbr));
941 PrintAndLog(" eXtended mode : %s", (extend) ? "Yes - Warning":"No");
942 PrintAndLog(" Modulation : %s", GetModulationStr(datamod));
943 PrintAndLog(" PSK clock frequency : %d", pskcf);
944 PrintAndLog(" AOR - Answer on Request : %s", (aor) ? "Yes":"No");
945 PrintAndLog(" OTP - One Time Pad : %s", (otp) ? "Yes - Warning":"No" );
946 PrintAndLog(" Max block : %d", maxblk);
947 PrintAndLog(" Password mode : %s", (pwd) ? "Yes":"No");
948 PrintAndLog(" Sequence Start Terminator : %s", (sst) ? "Yes":"No");
949 PrintAndLog(" Fast Write : %s", (fw) ? "Yes":"No");
950 PrintAndLog(" Inverse data : %s", (inv) ? "Yes":"No");
951 PrintAndLog(" POR-Delay : %s", (por) ? "Yes":"No");
952 PrintAndLog("-------------------------------------------------------------");
953 PrintAndLog(" Raw Data - Page 0");
954 PrintAndLog(" Block 0 : 0x%08X %s", bl0, sprint_bin(DemodBuffer+config.offset,32) );
955 PrintAndLog("-------------------------------------------------------------");
956
957 return 0;
958 }
959
960 int CmdT55xxDump(const char *Cmd){
961
962 uint32_t password = 0;
963 bool override = false;
964 char cmdp = param_getchar(Cmd, 0);
965 if ( cmdp == 'h' || cmdp == 'H') return usage_t55xx_dump();
966
967 bool usepwd = ( strlen(Cmd) > 0);
968 if ( usepwd ){
969 password = param_get32ex(Cmd, 0, 0, 16);
970 if (param_getchar(Cmd, 1) =='o' )
971 override = true;
972 }
973
974 PrintAndLog("Reading Page 0:");
975 PrintAndLog("blk | hex data | binary");
976 for ( uint8_t i = 0; i < 8; ++i){
977 T55xxReadBlock(i, 0, usepwd, override, password);
978 }
979 PrintAndLog("Reading Page 1:");
980 PrintAndLog("blk | hex data | binary");
981 for ( uint8_t i = 0; i < 4; i++){
982 T55xxReadBlock(i, 1, usepwd, override, password);
983 }
984 return 1;
985 }
986
987 int AquireData( uint8_t page, uint8_t block, bool pwdmode, uint32_t password ){
988 // arg0 bitmodes:
989 // bit0 = pwdmode
990 // bit1 = page to read from
991 uint8_t arg0 = (page<<1) | pwdmode;
992 UsbCommand c = {CMD_T55XX_READ_BLOCK, {arg0, block, password}};
993
994 clearCommandBuffer();
995 SendCommand(&c);
996 if ( !WaitForResponseTimeout(CMD_ACK,NULL,2500) ) {
997 PrintAndLog("command execution time out");
998 return 0;
999 }
1000
1001 uint8_t got[12000];
1002 GetFromBigBuf(got,sizeof(got),0);
1003 WaitForResponse(CMD_ACK,NULL);
1004 setGraphBuf(got, sizeof(got));
1005 return 1;
1006 }
1007
1008 char * GetBitRateStr(uint32_t id){
1009 static char buf[25];
1010
1011 char *retStr = buf;
1012 switch (id){
1013 case 0:
1014 snprintf(retStr,sizeof(buf),"%d - RF/8",id);
1015 break;
1016 case 1:
1017 snprintf(retStr,sizeof(buf),"%d - RF/16",id);
1018 break;
1019 case 2:
1020 snprintf(retStr,sizeof(buf),"%d - RF/32",id);
1021 break;
1022 case 3:
1023 snprintf(retStr,sizeof(buf),"%d - RF/40",id);
1024 break;
1025 case 4:
1026 snprintf(retStr,sizeof(buf),"%d - RF/50",id);
1027 break;
1028 case 5:
1029 snprintf(retStr,sizeof(buf),"%d - RF/64",id);
1030 break;
1031 case 6:
1032 snprintf(retStr,sizeof(buf),"%d - RF/100",id);
1033 break;
1034 case 7:
1035 snprintf(retStr,sizeof(buf),"%d - RF/128",id);
1036 break;
1037 default:
1038 snprintf(retStr,sizeof(buf),"%d - (Unknown)",id);
1039 break;
1040 }
1041
1042 return buf;
1043 }
1044
1045 char * GetSaferStr(uint32_t id){
1046 static char buf[40];
1047 char *retStr = buf;
1048
1049 snprintf(retStr,sizeof(buf),"%d",id);
1050 if (id == 6) {
1051 snprintf(retStr,sizeof(buf),"%d - passwd",id);
1052 }
1053 if (id == 9 ){
1054 snprintf(retStr,sizeof(buf),"%d - testmode",id);
1055 }
1056
1057 return buf;
1058 }
1059
1060 char * GetModulationStr( uint32_t id){
1061 static char buf[60];
1062 char *retStr = buf;
1063
1064 switch (id){
1065 case 0:
1066 snprintf(retStr,sizeof(buf),"%d - DIRECT (ASK/NRZ)",id);
1067 break;
1068 case 1:
1069 snprintf(retStr,sizeof(buf),"%d - PSK 1 phase change when input changes",id);
1070 break;
1071 case 2:
1072 snprintf(retStr,sizeof(buf),"%d - PSK 2 phase change on bitclk if input high",id);
1073 break;
1074 case 3:
1075 snprintf(retStr,sizeof(buf),"%d - PSK 3 phase change on rising edge of input",id);
1076 break;
1077 case 4:
1078 snprintf(retStr,sizeof(buf),"%d - FSK 1 RF/8 RF/5",id);
1079 break;
1080 case 5:
1081 snprintf(retStr,sizeof(buf),"%d - FSK 2 RF/8 RF/10",id);
1082 break;
1083 case 6:
1084 snprintf(retStr,sizeof(buf),"%d - FSK 1a RF/5 RF/8",id);
1085 break;
1086 case 7:
1087 snprintf(retStr,sizeof(buf),"%d - FSK 2a RF/10 RF/8",id);
1088 break;
1089 case 8:
1090 snprintf(retStr,sizeof(buf),"%d - Manchester",id);
1091 break;
1092 case 16:
1093 snprintf(retStr,sizeof(buf),"%d - Biphase",id);
1094 break;
1095 case 0x18:
1096 snprintf(retStr,sizeof(buf),"%d - Biphase a - AKA Conditional Dephase Encoding(CDP)",id);
1097 break;
1098 case 17:
1099 snprintf(retStr,sizeof(buf),"%d - Reserved",id);
1100 break;
1101 default:
1102 snprintf(retStr,sizeof(buf),"0x%02X (Unknown)",id);
1103 break;
1104 }
1105 return buf;
1106 }
1107
1108 char * GetModelStrFromCID(uint32_t cid){
1109
1110 static char buf[10];
1111 char *retStr = buf;
1112
1113 if (cid == 1) snprintf(retStr, sizeof(buf),"ATA5577M1");
1114 if (cid == 2) snprintf(retStr, sizeof(buf),"ATA5577M2");
1115 return buf;
1116 }
1117
1118 char * GetSelectedModulationStr( uint8_t id){
1119
1120 static char buf[20];
1121 char *retStr = buf;
1122
1123 switch (id){
1124 case DEMOD_FSK:
1125 snprintf(retStr,sizeof(buf),"FSK");
1126 break;
1127 case DEMOD_FSK1:
1128 snprintf(retStr,sizeof(buf),"FSK1");
1129 break;
1130 case DEMOD_FSK1a:
1131 snprintf(retStr,sizeof(buf),"FSK1a");
1132 break;
1133 case DEMOD_FSK2:
1134 snprintf(retStr,sizeof(buf),"FSK2");
1135 break;
1136 case DEMOD_FSK2a:
1137 snprintf(retStr,sizeof(buf),"FSK2a");
1138 break;
1139 case DEMOD_ASK:
1140 snprintf(retStr,sizeof(buf),"ASK");
1141 break;
1142 case DEMOD_NRZ:
1143 snprintf(retStr,sizeof(buf),"DIRECT/NRZ");
1144 break;
1145 case DEMOD_PSK1:
1146 snprintf(retStr,sizeof(buf),"PSK1");
1147 break;
1148 case DEMOD_PSK2:
1149 snprintf(retStr,sizeof(buf),"PSK2");
1150 break;
1151 case DEMOD_PSK3:
1152 snprintf(retStr,sizeof(buf),"PSK3");
1153 break;
1154 case DEMOD_BI:
1155 snprintf(retStr,sizeof(buf),"BIPHASE");
1156 break;
1157 case DEMOD_BIa:
1158 snprintf(retStr,sizeof(buf),"BIPHASEa - (CDP)");
1159 break;
1160 default:
1161 snprintf(retStr,sizeof(buf),"(Unknown)");
1162 break;
1163 }
1164 return buf;
1165 }
1166
1167 void t55x7_create_config_block( int tagtype ){
1168 //switch?
1169
1170
1171 }
1172
1173 /*
1174 uint32_t PackBits(uint8_t start, uint8_t len, uint8_t* bits){
1175
1176 int i = start;
1177 int j = len-1;
1178
1179 if (len > 32) return 0;
1180
1181 uint32_t tmp = 0;
1182 for (; j >= 0; --j, ++i)
1183 tmp |= bits[i] << j;
1184
1185 return tmp;
1186 }
1187 */
1188
1189 int CmdResetRead(const char *Cmd) {
1190 UsbCommand c = {CMD_T55XX_RESET_READ, {0,0,0}};
1191
1192 clearCommandBuffer();
1193 SendCommand(&c);
1194 if ( !WaitForResponseTimeout(CMD_ACK,NULL,2500) ) {
1195 PrintAndLog("command execution time out");
1196 return 0;
1197 }
1198
1199 uint8_t got[BIGBUF_SIZE-1];
1200 GetFromBigBuf(got,sizeof(got),0);
1201 WaitForResponse(CMD_ACK,NULL);
1202 setGraphBuf(got, sizeof(got));
1203 return 1;
1204 }
1205
1206 static command_t CommandTable[] =
1207 {
1208 {"help", CmdHelp, 1, "This help"},
1209 {"config", CmdT55xxSetConfig, 1, "Set/Get T55XX configuration (modulation, inverted, offset, rate)"},
1210 {"detect", CmdT55xxDetect, 0, "[1] Try detecting the tag modulation from reading the configuration block."},
1211 {"read", CmdT55xxReadBlock, 0, "b <block> p [password] [o] [1] -- Read T55xx block data. Optional [p password], [override], [page1]"},
1212 {"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)"},
1213 {"write", CmdT55xxWriteBlock,0, "b <block> d <data> p [password] [1] -- Write T55xx block data. Optional [p password], [page1]"},
1214 {"trace", CmdT55xxReadTrace, 0, "[1] Show T55xx traceability data (page 1/ blk 0-1)"},
1215 {"info", CmdT55xxInfo, 0, "[1] Show T55xx configuration data (page 0/ blk 0)"},
1216 {"dump", CmdT55xxDump, 0, "[password] [o] Dump T55xx card block 0-7. Optional [password], [override]"},
1217 {"special", special, 0, "Show block changes with 64 different offsets"},
1218 {"wakeup", CmdT55xxWakeUp, 0, "Send AOR wakeup command"},
1219 {NULL, NULL, 0, NULL}
1220 };
1221
1222 int CmdLFT55XX(const char *Cmd)
1223 {
1224 CmdsParse(CommandTable, Cmd);
1225 return 0;
1226 }
1227
1228 int CmdHelp(const char *Cmd)
1229 {
1230 CmdsHelp(CommandTable);
1231 return 0;
1232 }
Impressum, Datenschutz