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