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