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