]> cvs.zerfleddert.de Git - proxmark3-svn/blob - client/cmdlft55xx.c
2a77ebcb3ce941cccf20c6273fd37d73ea77b97f
[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 "proxmark3.h"
14 #include "ui.h"
15 #include "graph.h"
16 #include "cmdmain.h"
17 #include "cmdparser.h"
18 #include "cmddata.h"
19 #include "cmdlf.h"
20 #include "cmdlft55xx.h"
21 #include "util.h"
22 #include "data.h"
23 #include "lfdemod.h"
24 #include "../common/crc.h"
25 #include "../common/iso14443crc.h"
26
27 // Default configuration
28 t55xx_conf_block_t config = { .modulation = DEMOD_ASK, .inversed = FALSE, .offset = 0x00, .block0 = 0x00};
29
30 int usage_t55xx_config(){
31 PrintAndLog("Usage: lf t55xx config [d <demodulation>] [i 1] [o <offset>]");
32 PrintAndLog("Options: ");
33 PrintAndLog(" h This help");
34 PrintAndLog(" d <FSK|ASK|PSK|NZ|BI> Set demodulation FSK / ASK / PSK / NZ / Biphase");
35 PrintAndLog(" i [1] Inverse data signal, defaults to normal");
36 PrintAndLog(" o [offsett] Set offset, where data should start decode from in bitstream");
37 PrintAndLog("");
38 PrintAndLog("Examples:");
39 PrintAndLog(" lf t55xx config d FSK - FSK demodulation");
40 PrintAndLog(" lf t55xx config d FSK i 1 - FSK demodulation, inverse data");
41 PrintAndLog(" lf t55xx config d FSK i 1 o 3 - FSK demodulation, inverse data, offset=3,start from bitpos 3 to decode data");
42 PrintAndLog("");
43 return 0;
44 }
45 int usage_t55xx_read(){
46 PrintAndLog("Usage: lf t55xx read <block> <password>");
47 PrintAndLog(" <block>, block number to read. Between 0-7");
48 PrintAndLog(" <password>, OPTIONAL password (8 hex characters)");
49 PrintAndLog("");
50 PrintAndLog("Examples:");
51 PrintAndLog(" lf t55xx read 0 - read data from block 0");
52 PrintAndLog(" lf t55xx read 0 feedbeef - read data from block 0 password feedbeef");
53 PrintAndLog("");
54 return 0;
55 }
56 int usage_t55xx_write(){
57 PrintAndLog("Usage: lf t55xx wr <block> <data> [password]");
58 PrintAndLog(" <block>, block number to read. Between 0-7");
59 PrintAndLog(" <data>, 4 bytes of data to write (8 hex characters)");
60 PrintAndLog(" [password], OPTIONAL password 4bytes (8 hex characters)");
61 PrintAndLog("");
62 PrintAndLog("Examples:");
63 PrintAndLog(" lf t55xx wd 3 11223344 - write 11223344 to block 3");
64 PrintAndLog(" lf t55xx wd 3 11223344 feedbeef - write 11223344 to block 3 password feedbeef");
65 PrintAndLog("");
66 return 0;
67 }
68 int usage_t55xx_trace() {
69 PrintAndLog("Usage: lf t55xx trace [1]");
70 PrintAndLog(" [graph buffer data], if set, use Graphbuffer otherwise read data from tag.");
71 PrintAndLog("");
72 PrintAndLog("Examples:");
73 PrintAndLog(" lf t55xx trace");
74 PrintAndLog(" lf t55xx trace 1");
75 PrintAndLog("");
76 return 0;
77 }
78 int usage_t55xx_info() {
79 PrintAndLog("Usage: lf t55xx info [1]");
80 PrintAndLog(" [graph buffer data], if set, use Graphbuffer otherwise read data from tag.");
81 PrintAndLog("");
82 PrintAndLog("Examples:");
83 PrintAndLog(" lf t55xx info");
84 PrintAndLog(" lf t55xx info 1");
85 PrintAndLog("");
86 return 0;
87 }
88 int usage_t55xx_dump(){
89 PrintAndLog("Usage: lf t55xx dump <password>");
90 PrintAndLog(" <password>, OPTIONAL password 4bytes (8 hex symbols)");
91 PrintAndLog("");
92 PrintAndLog("Examples:");
93 PrintAndLog(" lf t55xx dump");
94 PrintAndLog(" lf t55xx dump feedbeef");
95 PrintAndLog("");
96 return 0;
97 }
98 int usage_t55xx_detect(){
99 PrintAndLog("Usage: lf t55xx detect");
100 PrintAndLog("");
101 PrintAndLog("Examples:");
102 PrintAndLog(" lf t55xx detect");
103 PrintAndLog(" lf t55xx detect 1");
104 PrintAndLog("");
105 return 0;
106 }
107
108 static int CmdHelp(const char *Cmd);
109
110 int CmdT55xxSetConfig(const char *Cmd){
111
112 uint8_t data[] = {0x78,0x00,0x00,0x00,0x00,0x00,0x00};
113 uint8_t cmd[] = {0x00,0x00};
114 ComputeCrc14443(CRC_14443_B, data, 7 , &cmd[0], &cmd[1]);
115 PrintAndLog("%02X %02X",cmd[0], cmd[1]);
116 int len = 0;
117 int foundModulation = 2;
118 uint8_t offset = 0;
119 bool inverse = FALSE;
120 bool errors = FALSE;
121 uint8_t cmdp = 0;
122 char modulation[4] = {0x00};
123
124 while(param_getchar(Cmd, cmdp) != 0x00 && !errors)
125 {
126 switch(param_getchar(Cmd, cmdp))
127 {
128 case 'h':
129 case 'H':
130 return usage_t55xx_config();
131 case 'd':
132 len = param_getstr(Cmd, cmdp+1, modulation);
133 cmdp+= len+1;
134 //FSK|ASK|PSK|NZ|BI
135 if ( strcmp(modulation, "FSK" ) == 0)
136 foundModulation = 1;
137 else if ( strcmp(modulation, "ASK" ) == 0)
138 foundModulation = 2;
139 else if ( strcmp(modulation, "PSK" ) == 0)
140 foundModulation = 3;
141 else if ( strcmp(modulation, "NZ" ) == 0)
142 foundModulation = 4;
143 else if ( strcmp(modulation, "BI" ) == 0)
144 foundModulation = 5;
145 else {
146 PrintAndLog("Unknown modulation '%s'", modulation);
147 errors = TRUE;
148 }
149 break;
150 case 'i':
151 inverse = param_getchar(Cmd,cmdp+1) == '1';
152 cmdp+=2;
153 break;
154 case 'o':
155 errors |= param_getdec(Cmd, cmdp+1,&offset);
156 if ( offset >= 32 ){
157 PrintAndLog("Offset must be smaller than 32");
158 errors = TRUE;
159 }
160 cmdp+=2;
161 break;
162 default:
163 PrintAndLog("Unknown parameter '%c'", param_getchar(Cmd, cmdp));
164 errors = TRUE;
165 break;
166 }
167 }
168 // No args
169 if (cmdp == 0) {
170 printConfiguration( config );
171 return 0;
172 }
173 //Validations
174 if (errors)
175 return usage_t55xx_config();
176
177 config.modulation = foundModulation;
178 config.inversed = inverse;
179 config.offset = offset;
180 config.block0 = 0;
181 return 0;
182 }
183
184 int CmdT55xxReadBlock(const char *Cmd)
185 {
186 int block = -1;
187 int password = 0xFFFFFFFF; //default to blank Block 7
188
189 char cmdp = param_getchar(Cmd, 0);
190 if (cmdp == 'h' || cmdp == 'H')
191 return usage_t55xx_read();
192
193 int res = sscanf(Cmd, "%d %x", &block, &password);
194
195 if ( res < 1 || res > 2 )
196 return usage_t55xx_read();
197
198
199 if ((block < 0) | (block > 7)) {
200 PrintAndLog("Block must be between 0 and 7");
201 return 1;
202 }
203
204 UsbCommand c = {CMD_T55XX_READ_BLOCK, {0, block, 0}};
205 c.d.asBytes[0] = 0x0;
206
207 //Password mode
208 if ( res == 2 ) {
209 c.arg[2] = password;
210 c.d.asBytes[0] = 0x1;
211 }
212
213 SendCommand(&c);
214 if ( !WaitForResponseTimeout(CMD_ACK,NULL,2500) ) {
215 PrintAndLog("command execution time out");
216 return 2;
217 }
218
219 uint8_t got[12000];
220 GetFromBigBuf(got,sizeof(got),0);
221 WaitForResponse(CMD_ACK,NULL);
222 setGraphBuf(got, 12000);
223
224 DecodeT55xxBlock();
225 printT55xxBlock("");
226 return 0;
227 }
228
229 void DecodeT55xxBlock(){
230
231 char buf[6] = {0x00};
232 char *cmdStr = buf;
233
234 // clearing the DemodBuffer.
235 DemodBufferLen = 0x00;
236
237 // use the configuration
238 switch( config.modulation ){
239 case 1:
240 sprintf(cmdStr,"0 %d", config.inversed );
241 FSKrawDemod(cmdStr, FALSE);
242 break;
243 case 2:
244 sprintf(cmdStr,"0 %d 1", config.inversed );
245 ASKmanDemod(cmdStr, FALSE, FALSE);
246 break;
247 case 3:
248 sprintf(cmdStr,"0 %d 1", config.inversed );
249 PSKDemod(cmdStr, FALSE);
250 break;
251 case 4:
252 sprintf(cmdStr,"0 %d 1", config.inversed );
253 NRZrawDemod(cmdStr, FALSE);
254 break;
255 case 5:
256 //BiphaseRawDecode("0",FALSE);
257 break;
258 default:
259 return;
260 }
261 }
262
263 int CmdT55xxDetect(const char *Cmd){
264 char cmdp = param_getchar(Cmd, 0);
265 if (cmdp == 'h' || cmdp == 'H')
266 return usage_t55xx_detect();
267
268 // read block 0, Page 0. Configuration.
269 UsbCommand c = {CMD_T55XX_READ_BLOCK, {0, 0, 0}};
270 c.d.asBytes[0] = 0x0;
271
272 //Password mode
273 // if ( res == 2 ) {
274 // c.arg[2] = password;
275 // c.d.asBytes[0] = 0x1;
276 // }
277
278 SendCommand(&c);
279 if ( !WaitForResponseTimeout(CMD_ACK,NULL,2500) ) {
280 PrintAndLog("command execution time out");
281 return FALSE;
282 }
283
284 uint8_t got[12000];
285 GetFromBigBuf(got,sizeof(got),0);
286 WaitForResponse(CMD_ACK,NULL);
287 setGraphBuf(got, 12000);
288
289 if ( !tryDetectModulation() ){
290 PrintAndLog("Could not detect modulation automatically. Try setting it manually with \'lf t55xx config\'");
291 }
292 return 0;
293 }
294
295 // detect configuration?
296 bool tryDetectModulation(){
297
298 uint8_t hits = 0;
299 t55xx_conf_block_t tests[10];
300
301 if (GetFskClock("", FALSE, FALSE)){
302 if ( FSKrawDemod("0 0", FALSE) && test()){
303 tests[hits].modulation = DEMOD_FSK;
304 tests[hits].inversed = FALSE;
305 ++hits;
306 }
307 if ( FSKrawDemod("0 1", FALSE) && test()) {
308 tests[hits].modulation = DEMOD_FSK;
309 tests[hits].inversed = TRUE;
310 ++hits;
311 }
312 } else {
313 if ( ASKmanDemod("0 0 1", FALSE, FALSE) && test()) {
314 tests[hits].modulation = DEMOD_ASK;
315 tests[hits].inversed = FALSE;
316 ++hits;
317 }
318
319 if ( ASKmanDemod("0 1 1", FALSE, FALSE) && test()) {
320 tests[hits].modulation = DEMOD_ASK;
321 tests[hits].inversed = TRUE;
322 ++hits;
323 }
324
325 if ( NRZrawDemod("0 0 1", FALSE) && test()) {
326 tests[hits].modulation = DEMOD_NZR;
327 tests[hits].inversed = FALSE;
328 ++hits;
329 }
330
331 if ( NRZrawDemod("0 1 1", FALSE) && test()) {
332 tests[hits].modulation = DEMOD_NZR;
333 tests[hits].inversed = TRUE;
334 ++hits;
335 }
336
337 if ( PSKDemod("0 0 1", FALSE) && test()) {
338 tests[hits].modulation = DEMOD_PSK;
339 tests[hits].inversed = FALSE;
340 ++hits;
341 }
342
343 if ( PSKDemod("0 1 1", FALSE) && test()) {
344 tests[hits].modulation = DEMOD_PSK;
345 tests[hits].inversed = TRUE;
346 ++hits;
347 }
348 //PSK2?
349 // if (!BiphaseRawDecode("0",FALSE) && test()) {
350 // tests[++hits].modulation = DEMOD_BI;
351 // tests[hits].inversed = FALSE;
352 //}
353 // if (!BiphaseRawDecode("1",FALSE) && test()) {
354 // tests[++hits].modulation = DEMOD_BI;
355 // tests[hits].inversed = TRUE;
356 // }
357 }
358 if ( hits == 1) {
359 config.modulation = tests[0].modulation;
360 config.inversed = tests[0].inversed;
361 printConfiguration( config );
362 return TRUE;
363 }
364
365 if ( hits > 1) {
366 PrintAndLog("Found [%d] possible matches for modulation.",hits);
367 for(int i=0; i<hits; ++i){
368 PrintAndLog("--[%d]---------------", i+1);
369 printConfiguration( tests[i] );
370 }
371 }
372 return FALSE;
373 }
374
375 bool test(){
376
377 if ( !DemodBufferLen)
378 return false;
379
380 uint8_t si = 1;
381 uint8_t safer = PackBits(si, 4, DemodBuffer); si += 4;
382 uint8_t resv = PackBits(si, 7, DemodBuffer); si += 7+3;
383 uint8_t extend = PackBits(si, 1, DemodBuffer); si += 1;
384
385 //PrintAndLog("test: %X %X %X ", safer, resv, extend);
386
387 // 2nibble must be zeroed.
388 if ( resv > 0x00) return FALSE;
389
390 if ( safer == 0x6 || safer == 0x9){
391 if ( extend == 0x00)
392 return TRUE;
393 }
394 if ( resv== 0x00) return TRUE;
395 return FALSE;
396 }
397
398 void printT55xxBlock(const char *demodStr){
399
400 uint32_t blockData = 0;
401 uint8_t bits[64] = {0x00};
402
403 if ( !DemodBufferLen)
404 return;
405
406 if ( config.offset > DemodBufferLen){
407 PrintAndLog("The configured offset is to big. (%d > %d)", config.offset, DemodBufferLen);
408 return;
409 }
410
411 int i = config.offset;
412 int pos = 32 + config.offset;
413 for (; i < pos; ++i)
414 bits[i]=DemodBuffer[i];
415
416 blockData = PackBits(0, 32, bits);
417 PrintAndLog("0x%08X %s [%s]", blockData, sprint_bin(bits,32), demodStr);
418 }
419
420 int special(const char *Cmd) {
421 uint32_t blockData = 0;
422 uint8_t bits[64] = {0x00};
423
424 PrintAndLog("[OFFSET] [DATA] [BINARY]");
425 PrintAndLog("----------------------------------------------------");
426 int i,j = 0;
427 for (; j < 32; ++j){
428
429 for (i = 0; i < 32; ++i)
430 bits[i]=DemodBuffer[j+i];
431
432 blockData = PackBits(0, 32, bits);
433 PrintAndLog("[%d] 0x%08X %s",j , blockData, sprint_bin(bits,32));
434 }
435
436 return 0;
437 }
438
439 void printConfiguration( t55xx_conf_block_t b){
440 PrintAndLog("Modulation : %s", GetSelectedModulationStr(b.modulation) );
441 PrintAndLog("Inverted : %s", (b.inversed) ? "Yes" : "No" );
442 PrintAndLog("Offset : %d", b.offset);
443 PrintAndLog("Block0 : %08X", b.block0);
444 PrintAndLog("");
445 }
446
447 int CmdT55xxWriteBlock(const char *Cmd)
448 {
449 int block = 8; //default to invalid block
450 int data = 0xFFFFFFFF; //default to blank Block
451 int password = 0xFFFFFFFF; //default to blank Block 7
452
453 char cmdp = param_getchar(Cmd, 0);
454 if (cmdp == 'h' || cmdp == 'H') {
455 usage_t55xx_write();
456 return 0;
457 }
458
459 int res = sscanf(Cmd, "%d %x %x",&block, &data, &password);
460
461 if ( res < 2 || res > 3) {
462 usage_t55xx_write();
463 return 1;
464 }
465
466 if (block > 7) {
467 PrintAndLog("Block must be between 0 and 7");
468 return 1;
469 }
470
471 UsbCommand c = {CMD_T55XX_WRITE_BLOCK, {data, block, 0}};
472 c.d.asBytes[0] = 0x0;
473
474 PrintAndLog("Writing to T55x7");
475 PrintAndLog("block : %d", block);
476 PrintAndLog("data : 0x%08X", data);
477
478 //Password mode
479 if (res == 3) {
480 c.arg[2] = password;
481 c.d.asBytes[0] = 0x1;
482 PrintAndLog("pwd : 0x%08X", password);
483 }
484 SendCommand(&c);
485 return 0;
486 }
487
488 int CmdT55xxReadTrace(const char *Cmd)
489 {
490 char cmdp = param_getchar(Cmd, 0);
491
492 if (strlen(Cmd) > 1 || cmdp == 'h' || cmdp == 'H')
493 return usage_t55xx_trace();
494
495 if ( strlen(Cmd)==0){
496
497 UsbCommand c = {CMD_T55XX_READ_TRACE, {0, 0, 0}};
498 SendCommand(&c);
499 if ( !WaitForResponseTimeout(CMD_ACK,NULL,2500) ) {
500 PrintAndLog("command execution time out");
501 return 1;
502 }
503
504 uint8_t got[12000];
505 GetFromBigBuf(got,sizeof(got),0);
506 WaitForResponse(CMD_ACK,NULL);
507 setGraphBuf(got, 12000);
508 }
509
510 DecodeT55xxBlock();
511
512 if ( !DemodBufferLen)
513 return 2;
514
515 RepaintGraphWindow();
516
517 uint8_t si = 5;
518 uint32_t bl0 = PackBits(si, 32, DemodBuffer);
519 uint32_t bl1 = PackBits(si+32, 32, DemodBuffer);
520
521 uint32_t acl = PackBits(si, 8, DemodBuffer); si += 8;
522 uint32_t mfc = PackBits(si, 8, DemodBuffer); si += 8;
523 uint32_t cid = PackBits(si, 5, DemodBuffer); si += 5;
524 uint32_t icr = PackBits(si, 3, DemodBuffer); si += 3;
525 uint32_t year = PackBits(si, 4, DemodBuffer); si += 4;
526 uint32_t quarter = PackBits(si, 2, DemodBuffer); si += 2;
527 uint32_t lotid = PackBits(si, 12, DemodBuffer); si += 12;
528 uint32_t wafer = PackBits(si, 5, DemodBuffer); si += 5;
529 uint32_t dw = PackBits(si, 15, DemodBuffer);
530
531 year += 2000;
532
533 PrintAndLog("");
534 PrintAndLog("-- T55xx Trace Information ----------------------------------");
535 PrintAndLog("-------------------------------------------------------------");
536 PrintAndLog(" ACL Allocation class (ISO/IEC 15963-1) : 0x%02X (%d)", acl, acl);
537 PrintAndLog(" MFC Manufacturer ID (ISO/IEC 7816-6) : 0x%02X (%d)", mfc, mfc);
538 PrintAndLog(" CID : 0x%02X (%d)", cid, cid);
539 PrintAndLog(" ICR IC Revision : %d",icr );
540 PrintAndLog(" Manufactured");
541 PrintAndLog(" Year/Quarter : %d/%d",year, quarter );
542 PrintAndLog(" Lot ID : %d", lotid );
543 PrintAndLog(" Wafer number : %d", wafer);
544 PrintAndLog(" Die Number : %d", dw);
545 PrintAndLog("-------------------------------------------------------------");
546 PrintAndLog(" Raw Data - Page 1");
547 PrintAndLog(" Block 0 : 0x%08X %s", bl0, sprint_bin(DemodBuffer+5,32) );
548 PrintAndLog(" Block 1 : 0x%08X %s", bl1, sprint_bin(DemodBuffer+37,32) );
549 PrintAndLog("-------------------------------------------------------------");
550 /*
551 TRACE - BLOCK O
552 Bits Definition HEX
553 1-8 ACL Allocation class (ISO/IEC 15963-1) 0xE0
554 9-16 MFC Manufacturer ID (ISO/IEC 7816-6) 0x15 Atmel Corporation
555 17-21 CID 0x1 = Atmel ATA5577M1 0x2 = Atmel ATA5577M2
556 22-24 ICR IC revision
557 25-28 YEAR (BCD encoded) 9 (= 2009)
558 29-30 QUARTER 1,2,3,4
559 31-32 LOT ID
560
561 TRACE - BLOCK 1
562 1-12 LOT ID
563 13-17 Wafer number
564 18-32 DW, die number sequential
565 */
566
567 return 0;
568 }
569
570 int CmdT55xxInfo(const char *Cmd){
571 /*
572 Page 0 Block 0 Configuration data.
573 Normal mode
574 Extended mode
575 */
576 char cmdp = param_getchar(Cmd, 0);
577
578 if (cmdp == 'h' || cmdp == 'H')
579 return usage_t55xx_info();
580
581 if (strlen(Cmd)==0){
582
583 // read block 0, Page 0. Configuration.
584 UsbCommand c = {CMD_T55XX_READ_BLOCK, {0, 0, 0}};
585 c.d.asBytes[0] = 0x0;
586
587 //Password mode
588 // if ( res == 2 ) {
589 // c.arg[2] = password;
590 // c.d.asBytes[0] = 0x1;
591 // }
592
593 SendCommand(&c);
594 if ( !WaitForResponseTimeout(CMD_ACK,NULL,2500) ) {
595 PrintAndLog("command execution time out");
596 return 1;
597 }
598
599 uint8_t got[12000];
600 GetFromBigBuf(got,sizeof(got),0);
601 WaitForResponse(CMD_ACK,NULL);
602 setGraphBuf(got, 12000);
603 }
604
605 DecodeT55xxBlock();
606
607 if ( !DemodBufferLen)
608 return 2;
609
610
611 uint8_t si = 1;
612 uint32_t bl0 = PackBits(si, 32, DemodBuffer);
613
614 uint32_t safer = PackBits(si, 4, DemodBuffer); si += 4;
615 uint32_t resv = PackBits(si, 7, DemodBuffer); si += 7;
616 uint32_t dbr = PackBits(si, 3, DemodBuffer); si += 3;
617 uint32_t extend = PackBits(si, 1, DemodBuffer); si += 1;
618 uint32_t datamod = PackBits(si, 5, DemodBuffer); si += 5;
619 uint32_t pskcf = PackBits(si, 2, DemodBuffer); si += 2;
620 uint32_t aor = PackBits(si, 1, DemodBuffer); si += 1;
621 uint32_t otp = PackBits(si, 1, DemodBuffer); si += 1;
622 uint32_t maxblk = PackBits(si, 3, DemodBuffer); si += 3;
623 uint32_t pwd = PackBits(si, 1, DemodBuffer); si += 1;
624 uint32_t sst = PackBits(si, 1, DemodBuffer); si += 1;
625 uint32_t fw = PackBits(si, 1, DemodBuffer); si += 1;
626 uint32_t inv = PackBits(si, 1, DemodBuffer); si += 1;
627 uint32_t por = PackBits(si, 1, DemodBuffer); si += 1;
628
629 PrintAndLog("");
630 PrintAndLog("-- T55xx Configuration & Tag Information --------------------");
631 PrintAndLog("-------------------------------------------------------------");
632 PrintAndLog(" Safer key : %s", GetSaferStr(safer));
633 PrintAndLog(" reserved : %d", resv);
634 PrintAndLog(" Data bit rate : %s", GetBitRateStr(dbr));
635 PrintAndLog(" eXtended mode : %s", (extend) ? "Yes - Warning":"No");
636 PrintAndLog(" Modulation : %s", GetModulationStr(datamod));
637 PrintAndLog(" PSK clock freq : %d", pskcf);
638 PrintAndLog(" AOR - Answer on Request : %s", (aor) ? "Yes":"No");
639 PrintAndLog(" OTP - One Time Pad : %s", (otp) ? "Yes - Warning":"No" );
640 PrintAndLog(" Max block : %d", maxblk);
641 PrintAndLog(" Password mode : %s", (pwd) ? "Yes":"No");
642 PrintAndLog(" Sequence Start Terminator : %s", (sst) ? "Yes":"No");
643 PrintAndLog(" Fast Write : %s", (fw) ? "Yes":"No");
644 PrintAndLog(" Inverse data : %s", (inv) ? "Yes":"No");
645 PrintAndLog(" POR-Delay : %s", (por) ? "Yes":"No");
646 PrintAndLog("-------------------------------------------------------------");
647 PrintAndLog(" Raw Data - Page 0");
648 PrintAndLog(" Block 0 : 0x%08X %s", bl0, sprint_bin(DemodBuffer+5,32) );
649 PrintAndLog("-------------------------------------------------------------");
650
651 return 0;
652 }
653
654 int CmdT55xxDump(const char *Cmd){
655
656 char s[20] = {0x00};
657 uint8_t pwd[4] = {0x00};
658
659 char cmdp = param_getchar(Cmd, 0);
660 if ( cmdp == 'h' || cmdp == 'H') {
661 usage_t55xx_dump();
662 return 0;
663 }
664
665 bool hasPwd = ( strlen(Cmd) > 0);
666 if ( hasPwd ){
667 if (param_gethex(Cmd, 0, pwd, 8)) {
668 PrintAndLog("password must include 8 HEX symbols");
669 return 1;
670 }
671 }
672
673 for ( int i = 0; i <8; ++i){
674 memset(s,0,sizeof(s));
675 if ( hasPwd ) {
676 sprintf(s,"%d %02x%02x%02x%02x", i, pwd[0],pwd[1],pwd[2],pwd[3]);
677 } else {
678 sprintf(s,"%d", i);
679 }
680 CmdT55xxReadBlock(s);
681 }
682 return 0;
683 }
684
685 char * GetBitRateStr(uint32_t id){
686 static char buf[40];
687 char *retStr = buf;
688 switch (id){
689 case 0:
690 sprintf(retStr,"%d - RF/8",id);
691 break;
692 case 1:
693 sprintf(retStr,"%d - RF/16",id);
694 break;
695 case 2:
696 sprintf(retStr,"%d - RF/32",id);
697 break;
698 case 3:
699 sprintf(retStr,"%d - RF/40",id);
700 break;
701 case 4:
702 sprintf(retStr,"%d - RF/50",id);
703 break;
704 case 5:
705 sprintf(retStr,"%d - RF/64",id);
706 break;
707 case 6:
708 sprintf(retStr,"%d - RF/100",id);
709 break;
710 case 7:
711 sprintf(retStr,"%d - RF/128",id);
712 break;
713 default:
714 sprintf(retStr,"%d - (Unknown)",id);
715 break;
716 }
717
718 return buf;
719 }
720
721 char * GetSaferStr(uint32_t id){
722 static char buf[40];
723 char *retStr = buf;
724
725 sprintf(retStr,"%d",id);
726 if (id == 6) {
727 sprintf(retStr,"%d - passwd",id);
728 }
729 if (id == 9 ){
730 sprintf(retStr,"%d - testmode",id);
731 }
732
733 return buf;
734 }
735 char * GetModulationStr( uint32_t id){
736 static char buf[40];
737 char *retStr = buf;
738
739 switch (id){
740 case 0:
741 sprintf(retStr,"%d - DIRECT (ASK/NRZ)",id);
742 break;
743 case 1:
744 sprintf(retStr,"%d - PSK 1 phase change when input changes",id);
745 break;
746 case 2:
747 sprintf(retStr,"%d - PSK 2 phase change on bitclk if input high",id);
748 break;
749 case 3:
750 sprintf(retStr,"%d - PSK 3 phase change on rising edge of input",id);
751 break;
752 case 4:
753 sprintf(retStr,"%d - FSK 1 RF/8 RF/5",id);
754 break;
755 case 5:
756 sprintf(retStr,"%d - FSK 2 RF/8 RF/10",id);
757 break;
758 case 6:
759 sprintf(retStr,"%d - FSK 1a RF/5 RF/8",id);
760 break;
761 case 7:
762 sprintf(retStr,"%d - FSK 2a RF/10 RF/8",id);
763 break;
764 case 8:
765 sprintf(retStr,"%d - Manschester",id);
766 break;
767 case 16:
768 sprintf(retStr,"%d - Biphase",id);
769 break;
770 case 17:
771 sprintf(retStr,"%d - Reserved",id);
772 break;
773 default:
774 sprintf(retStr,"0x%02X (Unknown)",id);
775 break;
776 }
777 return buf;
778 }
779
780 char * GetSelectedModulationStr( uint8_t id){
781
782 static char buf[16];
783 char *retStr = buf;
784
785 switch (id){
786 case DEMOD_FSK:
787 sprintf(retStr,"FSK (%d)",id);
788 break;
789 case DEMOD_ASK:
790 sprintf(retStr,"ASK (%d)",id);
791 break;
792 case DEMOD_NZR:
793 sprintf(retStr,"DIRECT/NRZ (%d)",id);
794 break;
795 case DEMOD_PSK:
796 sprintf(retStr,"PSK (%d)",id);
797 break;
798 case DEMOD_BI:
799 sprintf(retStr,"BIPHASE (%d)",id);
800 break;
801 default:
802 sprintf(retStr,"(Unknown)");
803 break;
804 }
805 return buf;
806 }
807
808 uint32_t PackBits(uint8_t start, uint8_t len, uint8_t* bits){
809
810 int i = start;
811 int j = len-1;
812 if (len > 32) {
813 return 0;
814 }
815 uint32_t tmp = 0;
816 for (; j >= 0; --j, ++i){
817 tmp |= bits[i] << j;
818 }
819 return tmp;
820 }
821
822 static command_t CommandTable[] =
823 {
824 {"help", CmdHelp, 1, "This help"},
825 {"config", CmdT55xxSetConfig, 1, "Set T55XX config for modulation, inversed data"},
826 {"detect", CmdT55xxDetect, 0, "Try detecting the tag modulation from reading the configuration block."},
827 {"read", CmdT55xxReadBlock, 0, "<block> [password] -- Read T55xx block data (page 0) [optional password]"},
828 {"write", CmdT55xxWriteBlock,0, "<block> <data> [password] -- Write T55xx block data (page 0) [optional password]"},
829 {"trace", CmdT55xxReadTrace, 0, "[1] Show T55xx traceability data (page 1/ blk 0-1)"},
830 {"info", CmdT55xxInfo, 0, "[1] Show T55xx configuration data (page 0/ blk 0)"},
831 {"dump", CmdT55xxDump, 0, "[password] Dump T55xx card block 0-7. [optional password]"},
832 {"special", special, 0, "Shows how a datablock changes with 32 different offsets"},
833 {NULL, NULL, 0, NULL}
834 };
835
836 int CmdLFT55XX(const char *Cmd)
837 {
838 CmdsParse(CommandTable, Cmd);
839 return 0;
840 }
841
842 int CmdHelp(const char *Cmd)
843 {
844 CmdsHelp(CommandTable);
845 return 0;
846 }
Impressum, Datenschutz