]> git.zerfleddert.de Git - proxmark3-svn/blob - client/cmdlft55xx.c
ADD: added the ioprox checksum test to IOdemodFSK
[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 #include "cmdhf14a.h"
27
28 #define CONFIGURATION_BLOCK 0x00
29 #define TRACE_BLOCK 0x01
30
31 // Default configuration
32 t55xx_conf_block_t config = { .modulation = DEMOD_ASK, .inverted = FALSE, .offset = 0x00, .block0 = 0x00};
33
34 int usage_t55xx_config(){
35 PrintAndLog("Usage: lf t55xx config [d <demodulation>] [i 1] [o <offset>]");
36 PrintAndLog("Options:");
37 PrintAndLog(" h This help");
38 PrintAndLog(" d <FSK|ASK|PSK1|PSK2|PSK3|NRZ|BI> Set demodulation");
39 PrintAndLog(" i [1] Inverse data signal, defaults to normal");
40 PrintAndLog(" o [offset] Set offset where data should start decode in bitstream");
41 PrintAndLog("");
42 PrintAndLog("Examples:");
43 PrintAndLog(" lf t55xx config d FSK - FSK demodulation");
44 PrintAndLog(" lf t55xx config d FSK i 1 - FSK demodulation, inverse data");
45 PrintAndLog(" lf t55xx config d FSK i 1 o 3 - FSK demodulation, inverse data, offset=3,start from position 3 to decode data");
46 PrintAndLog("");
47 return 0;
48 }
49 int usage_t55xx_read(){
50 PrintAndLog("Usage: lf t55xx read <block> <password>");
51 PrintAndLog(" <block>, block number to read. Between 0-7");
52 PrintAndLog(" <password>, OPTIONAL password (8 hex characters)");
53 PrintAndLog("");
54 PrintAndLog("Examples:");
55 PrintAndLog(" lf t55xx read 0 - read data from block 0");
56 PrintAndLog(" lf t55xx read 0 feedbeef - read data from block 0 password feedbeef");
57 PrintAndLog("");
58 return 0;
59 }
60 int usage_t55xx_write(){
61 PrintAndLog("Usage: lf t55xx wr <block> <data> [password]");
62 PrintAndLog(" <block>, block number to read. Between 0-7");
63 PrintAndLog(" <data>, 4 bytes of data to write (8 hex characters)");
64 PrintAndLog(" [password], OPTIONAL password 4bytes (8 hex characters)");
65 PrintAndLog("");
66 PrintAndLog("Examples:");
67 PrintAndLog(" lf t55xx wd 3 11223344 - write 11223344 to block 3");
68 PrintAndLog(" lf t55xx wd 3 11223344 feedbeef - write 11223344 to block 3 password feedbeef");
69 PrintAndLog("");
70 return 0;
71 }
72 int usage_t55xx_trace() {
73 PrintAndLog("Usage: lf t55xx trace [1]");
74 PrintAndLog(" [graph buffer data], if set, use Graphbuffer otherwise read data from tag.");
75 PrintAndLog("");
76 PrintAndLog("Examples:");
77 PrintAndLog(" lf t55xx trace");
78 PrintAndLog(" lf t55xx trace 1");
79 PrintAndLog("");
80 return 0;
81 }
82 int usage_t55xx_info() {
83 PrintAndLog("Usage: lf t55xx info [1]");
84 PrintAndLog(" [graph buffer data], if set, use Graphbuffer otherwise read data from tag.");
85 PrintAndLog("");
86 PrintAndLog("Examples:");
87 PrintAndLog(" lf t55xx info");
88 PrintAndLog(" lf t55xx info 1");
89 PrintAndLog("");
90 return 0;
91 }
92 int usage_t55xx_dump(){
93 PrintAndLog("Usage: lf t55xx dump <password>");
94 PrintAndLog(" <password>, OPTIONAL password 4bytes (8 hex symbols)");
95 PrintAndLog("");
96 PrintAndLog("Examples:");
97 PrintAndLog(" lf t55xx dump");
98 PrintAndLog(" lf t55xx dump feedbeef");
99 PrintAndLog("");
100 return 0;
101 }
102 int usage_t55xx_detect(){
103 PrintAndLog("Usage: lf t55xx detect [1]");
104 PrintAndLog(" [graph buffer data], if set, use Graphbuffer otherwise read data from tag.");
105 PrintAndLog("");
106 PrintAndLog("Examples:");
107 PrintAndLog(" lf t55xx detect");
108 PrintAndLog(" lf t55xx detect 1");
109 PrintAndLog("");
110 return 0;
111 }
112
113 static int CmdHelp(const char *Cmd);
114
115 int CmdT55xxSetConfig(const char *Cmd) {
116
117 uint8_t offset = 0;
118 bool errors = FALSE;
119 uint8_t cmdp = 0;
120 char modulation[5] = {0x00};
121 char tmp = 0x00;
122
123 while(param_getchar(Cmd, cmdp) != 0x00 && !errors)
124 {
125 tmp = param_getchar(Cmd, cmdp);
126 switch(tmp)
127 {
128 case 'h':
129 case 'H':
130 return usage_t55xx_config();
131 case 'd':
132 param_getstr(Cmd, cmdp+1, modulation);
133 cmdp += 2;
134
135 if ( strcmp(modulation, "FSK" ) == 0)
136 config.modulation = DEMOD_FSK;
137 else if ( strcmp(modulation, "ASK" ) == 0)
138 config.modulation = DEMOD_ASK;
139 else if ( strcmp(modulation, "NRZ" ) == 0)
140 config.modulation = DEMOD_NRZ;
141 else if ( strcmp(modulation, "PSK1" ) == 0)
142 config.modulation = DEMOD_PSK1;
143 else if ( strcmp(modulation, "PSK2" ) == 0)
144 config.modulation = DEMOD_PSK2;
145 else if ( strcmp(modulation, "PSK3" ) == 0)
146 config.modulation = DEMOD_PSK3;
147 else if ( strcmp(modulation, "BI" ) == 0)
148 config.modulation = DEMOD_BI;
149 else {
150 PrintAndLog("Unknown modulation '%s'", modulation);
151 errors = TRUE;
152 }
153 break;
154 case 'i':
155 config.inverted = param_getchar(Cmd,cmdp+1) == '1';
156 cmdp+=2;
157 break;
158 case 'o':
159 errors |= param_getdec(Cmd, cmdp+1,&offset);
160 if ( !errors )
161 config.offset = offset;
162 cmdp += 2;
163 break;
164 default:
165 PrintAndLog("Unknown parameter '%c'", param_getchar(Cmd, cmdp));
166 errors = TRUE;
167 break;
168 }
169 }
170
171 // No args
172 if (cmdp == 0) {
173 printConfiguration( config );
174 return 0;
175 }
176 //Validations
177 if (errors)
178 return usage_t55xx_config();
179
180 config.block0 = 0;
181 printConfiguration( config );
182 return 0;
183 }
184
185 int CmdT55xxReadBlock(const char *Cmd) {
186 int block = -1;
187 int password = 0xFFFFFFFF; //default to blank Block 7
188
189 char cmdp = param_getchar(Cmd, 0);
190 if (cmdp == 'h' || cmdp == 'H')
191 return usage_t55xx_read();
192
193 int res = sscanf(Cmd, "%d %x", &block, &password);
194
195 if ( res < 1 || res > 2 )
196 return usage_t55xx_read();
197
198
199 if ((block < 0) | (block > 7)) {
200 PrintAndLog("Block must be between 0 and 7");
201 return 1;
202 }
203
204 UsbCommand c = {CMD_T55XX_READ_BLOCK, {0, block, 0}};
205 c.d.asBytes[0] = 0x0;
206
207 //Password mode
208 if ( res == 2 ) {
209 c.arg[2] = password;
210 c.d.asBytes[0] = 0x1;
211 }
212
213 SendCommand(&c);
214 if ( !WaitForResponseTimeout(CMD_ACK,NULL,2500) ) {
215 PrintAndLog("command execution time out");
216 return 2;
217 }
218
219 uint8_t got[12000];
220 GetFromBigBuf(got,sizeof(got),0);
221 WaitForResponse(CMD_ACK,NULL);
222 setGraphBuf(got, 12000);
223
224 DecodeT55xxBlock();
225 printT55xxBlock("");
226 return 0;
227 }
228
229 void DecodeT55xxBlock(){
230
231 char buf[8] = {0x00};
232 char *cmdStr = buf;
233
234 DemodBufferLen = 0x00;
235
236 switch( config.modulation ){
237 case DEMOD_FSK:
238 sprintf(cmdStr,"0 %d", config.inverted );
239 FSKrawDemod(cmdStr, FALSE);
240 break;
241 case DEMOD_ASK:
242 sprintf(cmdStr,"0 %d 1", config.inverted );
243 ASKmanDemod(cmdStr, FALSE, FALSE);
244 break;
245 case DEMOD_PSK1:
246 sprintf(cmdStr,"0 %d 1", config.inverted );
247 PSKDemod(cmdStr, FALSE);
248 break;
249 case DEMOD_PSK2:
250 sprintf(cmdStr,"0 %d 1", config.inverted );
251 PSKDemod(cmdStr, FALSE);
252 psk1TOpsk2(DemodBuffer, DemodBufferLen);
253 break;
254 case DEMOD_PSK3:
255 sprintf(cmdStr,"0 %d 1", config.inverted );
256 PSKDemod(cmdStr, FALSE);
257 psk1TOpsk2(DemodBuffer, DemodBufferLen);
258 break;
259 case DEMOD_NRZ:
260 sprintf(cmdStr,"0 %d 1", config.inverted );
261 NRZrawDemod(cmdStr, FALSE);
262 break;
263 case DEMOD_BI:
264 sprintf(cmdStr,"0 0 %d 1", config.inverted );
265 ASKbiphaseDemod(cmdStr, FALSE);
266 break;
267 default:
268 return;
269 }
270 }
271
272 int CmdT55xxDetect(const char *Cmd){
273
274 char cmdp = param_getchar(Cmd, 0);
275
276 if (strlen(Cmd) > 1 || cmdp == 'h' || cmdp == 'H')
277 return usage_t55xx_detect();
278
279 if (strlen(Cmd)==0)
280 AquireData( CONFIGURATION_BLOCK );
281
282 if ( !tryDetectModulation() )
283 PrintAndLog("Could not detect modulation automatically. Try setting it manually with \'lf t55xx config\'");
284
285 return 0;
286 }
287
288 bool tryDetectModulation(){
289
290 uint8_t hits = 0;
291 t55xx_conf_block_t tests[15];
292
293 if (GetFskClock("", FALSE, FALSE)){
294 if ( FSKrawDemod("0 0", FALSE) && test(DEMOD_FSK, &tests[hits].offset)){
295 tests[hits].modulation = DEMOD_FSK;
296 tests[hits].inverted = FALSE;
297 tests[hits].block0 = PackBits(tests[hits].offset, 32, DemodBuffer);
298 ++hits;
299 }
300 if ( FSKrawDemod("0 1", FALSE) && test(DEMOD_FSK, &tests[hits].offset)) {
301 tests[hits].modulation = DEMOD_FSK;
302 tests[hits].inverted = TRUE;
303 tests[hits].block0 = PackBits(tests[hits].offset, 32, DemodBuffer);
304 ++hits;
305 }
306 } else {
307 if ( ASKmanDemod("0 0 1", FALSE, FALSE) && test(DEMOD_ASK, &tests[hits].offset)) {
308 tests[hits].modulation = DEMOD_ASK;
309 tests[hits].inverted = FALSE;
310 tests[hits].block0 = PackBits(tests[hits].offset, 32, DemodBuffer);
311 ++hits;
312 }
313
314 if ( ASKmanDemod("0 1 1", FALSE, FALSE) && test(DEMOD_ASK, &tests[hits].offset)) {
315 tests[hits].modulation = DEMOD_ASK;
316 tests[hits].inverted = TRUE;
317 tests[hits].block0 = PackBits(tests[hits].offset, 32, DemodBuffer);
318 ++hits;
319 }
320
321 if ( NRZrawDemod("0 0 1", FALSE) && test(DEMOD_NRZ, &tests[hits].offset)) {
322 tests[hits].modulation = DEMOD_NRZ;
323 tests[hits].inverted = FALSE;
324 tests[hits].block0 = PackBits(tests[hits].offset, 32, DemodBuffer);
325 ++hits;
326 }
327
328 if ( NRZrawDemod("0 1 1", FALSE) && test(DEMOD_NRZ, &tests[hits].offset)) {
329 tests[hits].modulation = DEMOD_NRZ;
330 tests[hits].inverted = TRUE;
331 tests[hits].block0 = PackBits(tests[hits].offset, 32, DemodBuffer);
332 ++hits;
333 }
334
335 if ( PSKDemod("0 0 1", FALSE) && test(DEMOD_PSK1, &tests[hits].offset)) {
336 tests[hits].modulation = DEMOD_PSK1;
337 tests[hits].inverted = FALSE;
338 tests[hits].block0 = PackBits(tests[hits].offset, 32, DemodBuffer);
339 ++hits;
340 }
341
342 if ( PSKDemod("0 1 1", FALSE) && test(DEMOD_PSK1, &tests[hits].offset)) {
343 tests[hits].modulation = DEMOD_PSK1;
344 tests[hits].inverted = TRUE;
345 tests[hits].block0 = PackBits(tests[hits].offset, 32, DemodBuffer);
346 ++hits;
347 }
348
349 // PSK2 - needs a call to psk1TOpsk2.
350 if ( PSKDemod("0 0 1", FALSE)) {
351 psk1TOpsk2(DemodBuffer, DemodBufferLen);
352 if (test(DEMOD_PSK2, &tests[hits].offset)){
353 tests[hits].modulation = DEMOD_PSK2;
354 tests[hits].inverted = FALSE;
355 tests[hits].block0 = PackBits(tests[hits].offset, 32, DemodBuffer);
356 ++hits;
357 }
358 }
359 // PSK2 - needs a call to psk1TOpsk2.
360 if ( PSKDemod("0 1 1", FALSE)) {
361 psk1TOpsk2(DemodBuffer, DemodBufferLen);
362 if (test(DEMOD_PSK2, &tests[hits].offset)){
363 tests[hits].modulation = DEMOD_PSK2;
364 tests[hits].inverted = TRUE;
365 tests[hits].block0 = PackBits(tests[hits].offset, 32, DemodBuffer);
366 ++hits;
367 }
368 }
369
370 // PSK3 - needs a call to psk1TOpsk2.
371 if ( PSKDemod("0 0 1", FALSE)) {
372 psk1TOpsk2(DemodBuffer, DemodBufferLen);
373 if (test(DEMOD_PSK3, &tests[hits].offset)){
374 tests[hits].modulation = DEMOD_PSK3;
375 tests[hits].inverted = FALSE;
376 tests[hits].block0 = PackBits(tests[hits].offset, 32, DemodBuffer);
377 ++hits;
378 }
379 }
380 // PSK3 - needs a call to psk1TOpsk2.
381 if ( PSKDemod("0 1 1", FALSE)) {
382 psk1TOpsk2(DemodBuffer, DemodBufferLen);
383 if (test(DEMOD_PSK3, &tests[hits].offset)){
384 tests[hits].modulation = DEMOD_PSK3;
385 tests[hits].inverted = TRUE;
386 tests[hits].block0 = PackBits(tests[hits].offset, 32, DemodBuffer);
387 ++hits;
388 }
389 }
390
391 if ( ASKbiphaseDemod("0 0 0 1", FALSE) && test(DEMOD_BI, &tests[hits].offset) ) {
392 tests[hits].modulation = DEMOD_BI;
393 tests[hits].inverted = FALSE;
394 tests[hits].block0 = PackBits(tests[hits].offset, 32, DemodBuffer);
395 ++hits;
396 }
397 if ( ASKbiphaseDemod("0 0 1 1", FALSE) && test(DEMOD_BI, &tests[hits].offset) ) {
398 tests[hits].modulation = DEMOD_BI;
399 tests[hits].inverted = TRUE;
400 tests[hits].block0 = PackBits(tests[hits].offset, 32, DemodBuffer);
401 ++hits;
402 }
403 }
404
405 if ( hits == 1) {
406 config.modulation = tests[0].modulation;
407 config.inverted = tests[0].inverted;
408 config.offset = tests[0].offset;
409
410 DecodeT55xxBlock();
411 if (DemodBufferLen > config.offset + 32)
412 config.block0 = PackBits(config.offset, 32, DemodBuffer);
413 printConfiguration( config );
414 return TRUE;
415 }
416
417 if ( hits > 1) {
418 PrintAndLog("Found [%d] possible matches for modulation.",hits);
419 for(int i=0; i<hits; ++i){
420 PrintAndLog("--[%d]---------------", i+1);
421 printConfiguration( tests[i] );
422 }
423 }
424 return FALSE;
425 }
426
427 bool testModulation(uint8_t mode, uint8_t modread){
428 switch( mode ){
429 case DEMOD_FSK:
430 if (modread > 3 && modread < 8) return TRUE;
431 break;
432 case DEMOD_ASK:
433 if (modread == 8) return TRUE;
434 break;
435 case DEMOD_PSK1:
436 if (modread == 1) return TRUE;
437 break;
438 case DEMOD_PSK2:
439 if (modread == 2) return TRUE;
440 break;
441 case DEMOD_PSK3:
442 if (modread == 3) return TRUE;
443 break;
444 case DEMOD_NRZ:
445 if (!modread) return TRUE;
446 break;
447 case DEMOD_BI:
448 if (modread == 16) return TRUE;
449 break;
450 default:
451 return FALSE;
452 }
453 return FALSE;
454 }
455
456 bool test(uint8_t mode, uint8_t *offset){
457
458 if ( !DemodBufferLen) return FALSE;
459
460 uint8_t si = 0;
461 for (uint8_t idx = 0; idx < 64; ++idx){
462 si = idx;
463 if ( PackBits(si, 32, DemodBuffer) == 0x00 ) continue;
464
465 uint8_t safer = PackBits(si, 4, DemodBuffer); si += 4; //master key
466 uint8_t resv = PackBits(si, 4, DemodBuffer); si += 4; //was 7 & +=7+3 //should be only 4 bits if extended mode
467
468 // 2nibble must be zeroed.
469 // moved test to here, since this gets most faults first.
470 if ( resv > 0x00) continue;
471
472 uint8_t xtRate = PackBits(si, 3, DemodBuffer); si += 3+3; //new
473 //uint8_t bitRate = PackBits(si, 3, DemodBuffer); si += 3; //new could check bit rate
474 uint8_t extend = PackBits(si, 1, DemodBuffer); si += 1; //bit 15 extended mode
475 uint8_t modread = PackBits(si, 5, DemodBuffer); si += 5+2+1; //new
476 //uint8_t pskcr = PackBits(si, 2, DemodBuffer); si += 2+1; //new could check psk cr
477 uint8_t nml01 = PackBits(si, 1, DemodBuffer); si += 1+5; //bit 24 , 30, 31 could be tested for 0 if not extended mode
478 uint8_t nml02 = PackBits(si, 2, DemodBuffer); si += 2;
479
480 //if extended mode
481 bool extMode =( (safer == 0x6 || safer == 0x9) && extend) ? TRUE : FALSE;
482
483 if (!extMode){
484 if (nml01 || nml02 || xtRate) continue;
485 }
486
487 //test modulation
488 if (!testModulation(mode, modread)) continue;
489
490 *offset = idx;
491 return TRUE;
492 }
493 return FALSE;
494 }
495
496 void printT55xxBlock(const char *demodStr){
497
498 uint8_t i = config.offset;
499 uint8_t endpos = 32 + i;
500 uint32_t blockData = 0;
501 uint8_t bits[64] = {0x00};
502
503 if ( !DemodBufferLen) return;
504
505 if ( endpos > DemodBufferLen){
506 PrintAndLog("The configured offset %d is too big. Possible offset: %d)", i, DemodBufferLen-32);
507 return;
508 }
509
510 for (; i < endpos; ++i)
511 bits[i - config.offset] = DemodBuffer[i];
512
513 blockData = PackBits(0, 32, bits);
514 PrintAndLog("0x%08X %s [%s]", blockData, sprint_bin(bits,32), demodStr);
515 }
516
517 int special(const char *Cmd) {
518 uint32_t blockData = 0;
519 uint8_t bits[32] = {0x00};
520
521 PrintAndLog("[OFFSET] [DATA] [BINARY]");
522 PrintAndLog("----------------------------------------------------");
523 int i,j = 0;
524 for (; j < 64; ++j){
525
526 for (i = 0; i < 32; ++i)
527 bits[i]=DemodBuffer[j+i];
528
529 blockData = PackBits(0, 32, bits);
530
531 //char indicate[4] = {0x00};
532 // if ( (blockData >> 24) == 0xE0 )
533 // sprintf(indicate,"<--");
534 //PrintAndLog("[%02d] 0x%08X %s %s",j , blockData, sprint_bin(bits,32), indicate);
535 PrintAndLog("[%02d] 0x%08X %s",j , blockData, sprint_bin(bits,32));
536 }
537 return 0;
538 }
539
540 void printConfiguration( t55xx_conf_block_t b){
541 PrintAndLog("Modulation : %s", GetSelectedModulationStr(b.modulation) );
542 PrintAndLog("Inverted : %s", (b.inverted) ? "Yes" : "No" );
543 PrintAndLog("Offset : %d", b.offset);
544 PrintAndLog("Block0 : 0x%08X", b.block0);
545 PrintAndLog("");
546 }
547
548 int CmdT55xxWriteBlock(const char *Cmd)
549 {
550 int block = 8; //default to invalid block
551 int data = 0xFFFFFFFF; //default to blank Block
552 int password = 0xFFFFFFFF; //default to blank Block 7
553
554 char cmdp = param_getchar(Cmd, 0);
555 if (cmdp == 'h' || cmdp == 'H') {
556 usage_t55xx_write();
557 return 0;
558 }
559
560 int res = sscanf(Cmd, "%d %x %x",&block, &data, &password);
561
562 if ( res < 2 || res > 3) {
563 usage_t55xx_write();
564 return 1;
565 }
566
567 if (block > 7) {
568 PrintAndLog("Block number must be between 0 and 7");
569 return 1;
570 }
571
572 UsbCommand c = {CMD_T55XX_WRITE_BLOCK, {data, block, 0}};
573 c.d.asBytes[0] = 0x0;
574
575 PrintAndLog("Writing to block: %d data: 0x%08X", block, data);
576
577 //Password mode
578 if (res == 3) {
579 c.arg[2] = password;
580 c.d.asBytes[0] = 0x1;
581 PrintAndLog("pwd : 0x%08X", password);
582 }
583 SendCommand(&c);
584 return 0;
585 }
586
587 int CmdT55xxReadTrace(const char *Cmd)
588 {
589 char cmdp = param_getchar(Cmd, 0);
590
591 if (strlen(Cmd) > 1 || cmdp == 'h' || cmdp == 'H')
592 return usage_t55xx_trace();
593
594 if (strlen(Cmd)==0)
595 AquireData( TRACE_BLOCK );
596
597 DecodeT55xxBlock();
598
599 if (!DemodBufferLen) return 1;
600
601 RepaintGraphWindow();
602 uint8_t repeat = 0;
603 if (config.offset > 5)
604 repeat = 32;
605 uint8_t si = config.offset+repeat;
606 uint32_t bl0 = PackBits(si, 32, DemodBuffer);
607 uint32_t bl1 = PackBits(si+32, 32, DemodBuffer);
608
609 uint32_t acl = PackBits(si, 8, DemodBuffer); si += 8;
610 uint32_t mfc = PackBits(si, 8, DemodBuffer); si += 8;
611 uint32_t cid = PackBits(si, 5, DemodBuffer); si += 5;
612 uint32_t icr = PackBits(si, 3, DemodBuffer); si += 3;
613 uint32_t year = PackBits(si, 4, DemodBuffer); si += 4;
614 uint32_t quarter = PackBits(si, 2, DemodBuffer); si += 2;
615 uint32_t lotid = PackBits(si, 12, DemodBuffer); si += 12;
616 uint32_t wafer = PackBits(si, 5, DemodBuffer); si += 5;
617 uint32_t dw = PackBits(si, 15, DemodBuffer);
618
619 year += 2000;
620
621 PrintAndLog("");
622 PrintAndLog("-- T55xx Trace Information ----------------------------------");
623 PrintAndLog("-------------------------------------------------------------");
624 PrintAndLog(" ACL Allocation class (ISO/IEC 15963-1) : 0x%02X (%d)", acl, acl);
625 PrintAndLog(" MFC Manufacturer ID (ISO/IEC 7816-6) : 0x%02X (%d) - %s", mfc, mfc, getTagInfo(mfc));
626 PrintAndLog(" CID : 0x%02X (%d) - %s", cid, cid, GetModelStrFromCID(cid));
627 PrintAndLog(" ICR IC Revision : %d",icr );
628 PrintAndLog(" Manufactured");
629 PrintAndLog(" Year/Quarter : %d/%d",year, quarter );
630 PrintAndLog(" Lot ID : %d", lotid );
631 PrintAndLog(" Wafer number : %d", wafer);
632 PrintAndLog(" Die Number : %d", dw);
633 PrintAndLog("-------------------------------------------------------------");
634 PrintAndLog(" Raw Data - Page 1");
635 PrintAndLog(" Block 0 : 0x%08X %s", bl0, sprint_bin(DemodBuffer+config.offset+repeat,32) );
636 PrintAndLog(" Block 1 : 0x%08X %s", bl1, sprint_bin(DemodBuffer+config.offset+repeat+32,32) );
637 PrintAndLog("-------------------------------------------------------------");
638
639 if ( acl != 0xE0 )
640 PrintAndLog("The modulation is most likely wrong since the ACL is not 0xE0. ");
641 /*
642 TRACE - BLOCK O
643 Bits Definition HEX
644 1-8 ACL Allocation class (ISO/IEC 15963-1) 0xE0
645 9-16 MFC Manufacturer ID (ISO/IEC 7816-6) 0x15 Atmel Corporation
646 17-21 CID 0x1 = Atmel ATA5577M1 0x2 = Atmel ATA5577M2
647 22-24 ICR IC revision
648 25-28 YEAR (BCD encoded) 9 (= 2009)
649 29-30 QUARTER 1,2,3,4
650 31-32 LOT ID
651
652 TRACE - BLOCK 1
653 1-12 LOT ID
654 13-17 Wafer number
655 18-32 DW, die number sequential
656 */
657
658 return 0;
659 }
660
661 int CmdT55xxInfo(const char *Cmd){
662 /*
663 Page 0 Block 0 Configuration data.
664 Normal mode
665 Extended mode
666 */
667 char cmdp = param_getchar(Cmd, 0);
668
669 if (strlen(Cmd) > 1 || cmdp == 'h' || cmdp == 'H')
670 return usage_t55xx_info();
671
672 if (strlen(Cmd)==0)
673 AquireData( CONFIGURATION_BLOCK );
674
675 DecodeT55xxBlock();
676
677 if (!DemodBufferLen) return 1;
678
679 uint8_t si = config.offset;
680 uint32_t bl0 = PackBits(si, 32, DemodBuffer);
681
682 uint32_t safer = PackBits(si, 4, DemodBuffer); si += 4;
683 uint32_t resv = PackBits(si, 7, DemodBuffer); si += 7;
684 uint32_t dbr = PackBits(si, 3, DemodBuffer); si += 3;
685 uint32_t extend = PackBits(si, 1, DemodBuffer); si += 1;
686 uint32_t datamod = PackBits(si, 5, DemodBuffer); si += 5;
687 uint32_t pskcf = PackBits(si, 2, DemodBuffer); si += 2;
688 uint32_t aor = PackBits(si, 1, DemodBuffer); si += 1;
689 uint32_t otp = PackBits(si, 1, DemodBuffer); si += 1;
690 uint32_t maxblk = PackBits(si, 3, DemodBuffer); si += 3;
691 uint32_t pwd = PackBits(si, 1, DemodBuffer); si += 1;
692 uint32_t sst = PackBits(si, 1, DemodBuffer); si += 1;
693 uint32_t fw = PackBits(si, 1, DemodBuffer); si += 1;
694 uint32_t inv = PackBits(si, 1, DemodBuffer); si += 1;
695 uint32_t por = PackBits(si, 1, DemodBuffer); si += 1;
696
697 PrintAndLog("");
698 PrintAndLog("-- T55xx Configuration & Tag Information --------------------");
699 PrintAndLog("-------------------------------------------------------------");
700 PrintAndLog(" Safer key : %s", GetSaferStr(safer));
701 PrintAndLog(" reserved : %d", resv);
702 PrintAndLog(" Data bit rate : %s", GetBitRateStr(dbr));
703 PrintAndLog(" eXtended mode : %s", (extend) ? "Yes - Warning":"No");
704 PrintAndLog(" Modulation : %s", GetModulationStr(datamod));
705 PrintAndLog(" PSK clock frequency : %d", pskcf);
706 PrintAndLog(" AOR - Answer on Request : %s", (aor) ? "Yes":"No");
707 PrintAndLog(" OTP - One Time Pad : %s", (otp) ? "Yes - Warning":"No" );
708 PrintAndLog(" Max block : %d", maxblk);
709 PrintAndLog(" Password mode : %s", (pwd) ? "Yes":"No");
710 PrintAndLog(" Sequence Start Terminator : %s", (sst) ? "Yes":"No");
711 PrintAndLog(" Fast Write : %s", (fw) ? "Yes":"No");
712 PrintAndLog(" Inverse data : %s", (inv) ? "Yes":"No");
713 PrintAndLog(" POR-Delay : %s", (por) ? "Yes":"No");
714 PrintAndLog("-------------------------------------------------------------");
715 PrintAndLog(" Raw Data - Page 0");
716 PrintAndLog(" Block 0 : 0x%08X %s", bl0, sprint_bin(DemodBuffer+config.offset,32) );
717 PrintAndLog("-------------------------------------------------------------");
718 return 0;
719 }
720
721 int CmdT55xxDump(const char *Cmd){
722
723 char s[20] = {0x00};
724 uint8_t pwd[4] = {0x00};
725
726 char cmdp = param_getchar(Cmd, 0);
727 if ( cmdp == 'h' || cmdp == 'H') {
728 usage_t55xx_dump();
729 return 0;
730 }
731
732 bool hasPwd = ( strlen(Cmd) > 0);
733 if ( hasPwd ){
734 if (param_gethex(Cmd, 0, pwd, 8)) {
735 PrintAndLog("password must include 8 HEX symbols");
736 return 1;
737 }
738 }
739
740 for ( int i = 0; i <8; ++i){
741 memset(s,0,sizeof(s));
742 if ( hasPwd ) {
743 sprintf(s,"%d %02x%02x%02x%02x", i, pwd[0],pwd[1],pwd[2],pwd[3]);
744 } else {
745 sprintf(s,"%d", i);
746 }
747 CmdT55xxReadBlock(s);
748 }
749 return 0;
750 }
751
752 int AquireData( uint8_t block ){
753
754 UsbCommand c;
755
756 if ( block == CONFIGURATION_BLOCK )
757 c.cmd = CMD_T55XX_READ_BLOCK;
758 else if (block == TRACE_BLOCK )
759 c.cmd = CMD_T55XX_READ_TRACE;
760
761 c.arg[0] = 0x00;
762 c.arg[1] = 0x00;
763 c.arg[2] = 0x00;
764 c.d.asBytes[0] = 0x0;
765
766 //Password mode
767 // if ( res == 2 ) {
768 // c.arg[2] = password;
769 // c.d.asBytes[0] = 0x1;
770 // }
771
772 SendCommand(&c);
773 if ( !WaitForResponseTimeout(CMD_ACK,NULL,2500) ) {
774 PrintAndLog("command execution time out");
775 return 1;
776 }
777
778 uint8_t got[12000];
779 GetFromBigBuf(got,sizeof(got),0);
780 WaitForResponse(CMD_ACK,NULL);
781 setGraphBuf(got, 12000);
782 return 0;
783 }
784
785 char * GetBitRateStr(uint32_t id){
786 static char buf[40];
787 char *retStr = buf;
788 switch (id){
789 case 0:
790 sprintf(retStr,"%d - RF/8",id);
791 break;
792 case 1:
793 sprintf(retStr,"%d - RF/16",id);
794 break;
795 case 2:
796 sprintf(retStr,"%d - RF/32",id);
797 break;
798 case 3:
799 sprintf(retStr,"%d - RF/40",id);
800 break;
801 case 4:
802 sprintf(retStr,"%d - RF/50",id);
803 break;
804 case 5:
805 sprintf(retStr,"%d - RF/64",id);
806 break;
807 case 6:
808 sprintf(retStr,"%d - RF/100",id);
809 break;
810 case 7:
811 sprintf(retStr,"%d - RF/128",id);
812 break;
813 default:
814 sprintf(retStr,"%d - (Unknown)",id);
815 break;
816 }
817
818 return buf;
819 }
820
821 char * GetSaferStr(uint32_t id){
822 static char buf[40];
823 char *retStr = buf;
824
825 sprintf(retStr,"%d",id);
826 if (id == 6) {
827 sprintf(retStr,"%d - passwd",id);
828 }
829 if (id == 9 ){
830 sprintf(retStr,"%d - testmode",id);
831 }
832
833 return buf;
834 }
835 char * GetModulationStr( uint32_t id){
836 static char buf[40];
837 char *retStr = buf;
838
839 switch (id){
840 case 0:
841 sprintf(retStr,"%d - DIRECT (ASK/NRZ)",id);
842 break;
843 case 1:
844 sprintf(retStr,"%d - PSK 1 phase change when input changes",id);
845 break;
846 case 2:
847 sprintf(retStr,"%d - PSK 2 phase change on bitclk if input high",id);
848 break;
849 case 3:
850 sprintf(retStr,"%d - PSK 3 phase change on rising edge of input",id);
851 break;
852 case 4:
853 sprintf(retStr,"%d - FSK 1 RF/8 RF/5",id);
854 break;
855 case 5:
856 sprintf(retStr,"%d - FSK 2 RF/8 RF/10",id);
857 break;
858 case 6:
859 sprintf(retStr,"%d - FSK 1a RF/5 RF/8",id);
860 break;
861 case 7:
862 sprintf(retStr,"%d - FSK 2a RF/10 RF/8",id);
863 break;
864 case 8:
865 sprintf(retStr,"%d - Manschester",id);
866 break;
867 case 16:
868 sprintf(retStr,"%d - Biphase",id);
869 break;
870 case 17:
871 sprintf(retStr,"%d - Reserved",id);
872 break;
873 default:
874 sprintf(retStr,"0x%02X (Unknown)",id);
875 break;
876 }
877 return buf;
878 }
879
880 char * GetModelStrFromCID(uint32_t cid){
881
882 static char buf[10];
883 char *retStr = buf;
884
885 if (cid == 1) sprintf(retStr,"ATA5577M1");
886 if (cid == 2) sprintf(retStr,"ATA5577M2");
887 return buf;
888 }
889
890 char * GetSelectedModulationStr( uint8_t id){
891
892 static char buf[16];
893 char *retStr = buf;
894
895 switch (id){
896 case DEMOD_FSK:
897 sprintf(retStr,"FSK");
898 break;
899 case DEMOD_ASK:
900 sprintf(retStr,"ASK");
901 break;
902 case DEMOD_NRZ:
903 sprintf(retStr,"DIRECT/NRZ");
904 break;
905 case DEMOD_PSK1:
906 sprintf(retStr,"PSK1");
907 break;
908 case DEMOD_PSK2:
909 sprintf(retStr,"PSK2");
910 break;
911 case DEMOD_PSK3:
912 sprintf(retStr,"PSK3");
913 break;
914 case DEMOD_BI:
915 sprintf(retStr,"BIPHASE");
916 break;
917 default:
918 sprintf(retStr,"(Unknown)");
919 break;
920 }
921 return buf;
922 }
923
924 uint32_t PackBits(uint8_t start, uint8_t len, uint8_t* bits){
925
926 int i = start;
927 int j = len-1;
928
929 if (len > 32) return 0;
930
931 uint32_t tmp = 0;
932 for (; j >= 0; --j, ++i)
933 tmp |= bits[i] << j;
934
935 return tmp;
936 }
937
938 static command_t CommandTable[] =
939 {
940 {"help", CmdHelp, 1, "This help"},
941 {"config", CmdT55xxSetConfig, 1, "Set/Get T55XX configuration (modulation, inverted, offset)"},
942 {"detect", CmdT55xxDetect, 0, "[1] Try detecting the tag modulation from reading the configuration block."},
943 {"read", CmdT55xxReadBlock, 0, "<block> [password] -- Read T55xx block data (page 0) [optional password]"},
944 {"write", CmdT55xxWriteBlock,0, "<block> <data> [password] -- Write T55xx block data (page 0) [optional password]"},
945 {"trace", CmdT55xxReadTrace, 0, "[1] Show T55xx traceability data (page 1/ blk 0-1)"},
946 {"info", CmdT55xxInfo, 0, "[1] Show T55xx configuration data (page 0/ blk 0)"},
947 {"dump", CmdT55xxDump, 0, "[password] Dump T55xx card block 0-7. [optional password]"},
948 {"special", special, 0, "Show block changes with 64 different offsets"},
949 {NULL, NULL, 0, NULL}
950 };
951
952 int CmdLFT55XX(const char *Cmd)
953 {
954 CmdsParse(CommandTable, Cmd);
955 return 0;
956 }
957
958 int CmdHelp(const char *Cmd)
959 {
960 CmdsHelp(CommandTable);
961 return 0;
962 }
Impressum, Datenschutz