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