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