]>
cvs.zerfleddert.de Git - proxmark3-svn/blob - client/cmdlft55xx.c
1 //-----------------------------------------------------------------------------
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
6 //-----------------------------------------------------------------------------
7 // Low frequency T55xx commands
8 //-----------------------------------------------------------------------------
13 #include "proxmark3.h"
17 #include "cmdparser.h"
20 #include "cmdlft55xx.h"
24 #include "../common/crc.h"
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 =
39 // Default configuration: FSK, not inversed.
40 t55xx_conf_block config
= {0x00, FALSE
, 0x00};
44 //FSKrawDemod("", FALSE)
45 //FSKrawDemod("1", FALSE)
49 //ASKmanDemod("", FALSE, FALSE)
51 // NZR (autoclock, normal, maxerrors 1)
52 // NZR (autoclock, inverse, maxerrors 1)
53 //NRZrawDemod("0 0 1", FALSE) ) {
55 // PSK (autoclock, normal, maxerrors 1)
56 // PSK (autoclock, inverse, maxerrors 1)
57 //PSKDemod("0 0 1", FALSE)
59 int usage_t55xx_config(){
60 PrintAndLog("Usage: lf t55xx config [d <demodulation>] [i 0|1]");
61 PrintAndLog("Options: ");
62 PrintAndLog(" h This help");
63 PrintAndLog(" d <> Set demodulation FSK / ASK / PSK / NZR");
64 PrintAndLog(" i [0|1] Inverse data signal, Default: 0");
65 PrintAndLog("Examples:");
66 PrintAndLog(" lf t55xx config d FSK ");
67 PrintAndLog(" FSK demodulation");
68 PrintAndLog(" lf t55xx config d FSK i 1");
69 PrintAndLog(" FSK demodulation, inverse data");
70 PrintAndLog(" lf dump");
71 PrintAndLog(" Dumps all block from tag");
72 PrintAndLog(" lf trace");
73 PrintAndLog(" Read trace block and decode it");
74 PrintAndLog(" lf info");
75 PrintAndLog(" Read configuration and decode it");
78 int usage_t55xx_read(){
79 PrintAndLog("Usage: lf t55xx read <block> <password>");
80 PrintAndLog(" <block>, block number to read. Between 0-7");
81 PrintAndLog(" <password>, OPTIONAL password (8 hex characters)");
83 PrintAndLog(" sample: lf t55xx read 0 = try reading data from block 0");
84 PrintAndLog(" : lf t55xx read 0 feedbeef = try reading data from block 0 using password");
88 int usage_t55xx_write(){
89 PrintAndLog("Usage: lf t55xx wr <block> <data> [password]");
90 PrintAndLog(" <block>, block number to read. Between 0-7");
91 PrintAndLog(" <data>, 4 bytes of data to write (8 hex characters)");
92 PrintAndLog(" [password], OPTIONAL password 4bytes (8 hex characters)");
94 PrintAndLog(" sample: lf t55xx wd 3 11223344 = try writing data 11223344 to block 3");
95 PrintAndLog(" : lf t55xx wd 3 11223344 feedbeef = try writing data 11223344 to block 3 using password feedbeef");
99 int usage_t55xx_trace() {
100 PrintAndLog("Usage: lf t55xx trace [graph buffer data]");
101 PrintAndLog(" [graph buffer data], if set, use Graphbuffer otherwise read data from tag.");
103 PrintAndLog(" sample: lf t55xx trace");
104 PrintAndLog(" : lf t55xx trace 1");
108 int usage_t55xx_info() {
109 PrintAndLog("Usage: lf t55xx info [graph buffer data]");
110 PrintAndLog(" [graph buffer data], if set, use Graphbuffer otherwise read data from tag.");
112 PrintAndLog(" sample: lf t55xx info");
113 PrintAndLog(" : lf t55xx info 1");
117 int usage_t55xx_dump(){
118 PrintAndLog("Usage: lf t55xx dump <password>");
119 PrintAndLog(" <password>, OPTIONAL password 4bytes (8 hex characters)");
121 PrintAndLog(" sample: lf t55xx dump");
122 PrintAndLog(" : lf t55xx dump feedbeef");
127 static int CmdHelp(const char *Cmd
);
129 int CmdT55xxSetConfig(const char *Cmd
){
132 if(param_getchar(Cmd
, paramNum
) == 'h')
134 return usage_t55xx_config();
137 uint8_t buff
[] = { 0x01, 0x01, 0x01, 0x01,
138 0x01, 0x01, 0x01, 0x01,
139 0x01, 0x40, 0x01, 0x01, 0x04 };
140 PrintAndLog("CRC-8: %x",CRC8Maxim(buff
, 13));
142 //config = { 0, FALSE};
146 // detect configuration?
148 int CmdReadBlk(const char *Cmd
)
151 int password
= 0xFFFFFFFF; //default to blank Block 7
153 char cmdp
= param_getchar(Cmd
, 0);
154 if (cmdp
== 'h' || cmdp
== 'H')
155 return usage_t55xx_read();
157 int res
= sscanf(Cmd
, "%d %x", &block
, &password
);
159 if ( res
< 1 || res
> 2 ){
164 if ((block
< 0) | (block
> 7)) {
165 PrintAndLog("Block must be between 0 and 7");
169 UsbCommand c
= {CMD_T55XX_READ_BLOCK
, {0, block
, 0}};
170 c
.d
.asBytes
[0] = 0x0;
175 c
.d
.asBytes
[0] = 0x1;
179 if ( !WaitForResponseTimeout(CMD_ACK
,NULL
,2500) ) {
180 PrintAndLog("command execution time out");
185 GetFromBigBuf(got
,sizeof(got
),0);
186 WaitForResponse(CMD_ACK
,NULL
);
188 setGraphBuf(got
, 12000);
195 if (CmdDetectClockRate("f")){ //wave is almost certainly FSK
198 if ( FSKrawDemod("", FALSE
))
201 if ( FSKrawDemod("1", FALSE
))
202 printT55xx("FSK inv");
204 // ASK/MAN (autoclock, normal, maxerrors 1)
205 if ( ASKmanDemod("0 0 1", FALSE
, FALSE
) )
206 printT55xx("ASK/MAN");
208 // ASK/MAN (autoclock, inverted, maxerrors 1)
209 if ( ASKmanDemod("0 1 1", FALSE
, FALSE
) )
210 printT55xx("ASK/MAN Inv");
212 // NZR (autoclock, normal, maxerrors 1)
213 if ( NRZrawDemod("0 0 1", FALSE
) )
215 // NZR (autoclock, inverted, maxerrors 1)
216 if ( NRZrawDemod("0 1 1", FALSE
) )
217 printT55xx("NZR inv");
219 // PSK (autoclock, normal, maxerrors 1)
220 if (!PSKDemod("0 0 1", FALSE
))
223 // PSK (autoclock, inverted, maxerrors 1)
224 if (!PSKDemod("0 1 1", FALSE
))
225 printT55xx("PSK inv");
230 void printT55xx(const char *demodStr
){
232 uint32_t blockData
= 0;
233 uint8_t bits
[MAX_GRAPH_TRACE_LEN
] = {0x00};
235 if ( !DemodBufferLen
)
239 for (;i
<DemodBufferLen
;++i
)
240 bits
[i
]=DemodBuffer
[i
];
242 blockData
= PackBits(1, 32, bits
);
243 PrintAndLog("0x%08X %s [%s]", blockData
, sprint_bin(bits
+1,32), demodStr
);
248 size = fskdemod(dest, size, 32, 0, 8, 10); // fsk1 RF/32
249 size = fskdemod(dest, size, 32, 1, 8, 10); // fsk1a RF/32
252 size = fskdemod(dest, size, 32, 0, 10, 8); // fsk2 RF/32
253 size = fskdemod(dest, size, 32, 1, 10, 8); // fsk2a RF/32
254 size = fskdemod(dest, size, 50, 1, 10, 8); // fsk2a RF/50
255 size = fskdemod(dest, size, 64, 1, 10, 8); // FSK2a RF/64
258 errCnt = pskRawDemod(bits, &bitlen, 32, 0);
260 int CmdWriteBlk(const char *Cmd
)
262 int block
= 8; //default to invalid block
263 int data
= 0xFFFFFFFF; //default to blank Block
264 int password
= 0xFFFFFFFF; //default to blank Block 7
266 char cmdp
= param_getchar(Cmd
, 0);
267 if (cmdp
== 'h' || cmdp
== 'H') {
272 int res
= sscanf(Cmd
, "%d %x %x",&block
, &data
, &password
);
274 if ( res
< 2 || res
> 3) {
280 PrintAndLog("Block must be between 0 and 7");
284 UsbCommand c
= {CMD_T55XX_WRITE_BLOCK
, {data
, block
, 0}};
285 c
.d
.asBytes
[0] = 0x0;
287 PrintAndLog("Writing to T55x7");
288 PrintAndLog("block : %d", block
);
289 PrintAndLog("data : 0x%08X", data
);
294 c
.d
.asBytes
[0] = 0x1;
295 PrintAndLog("pwd : 0x%08X", password
);
301 int CmdReadTrace(const char *Cmd
)
303 uint8_t bits
[MAX_GRAPH_TRACE_LEN
] = {0x00};
305 char cmdp
= param_getchar(Cmd
, 0);
307 if (strlen(Cmd
) > 1 || cmdp
== 'h' || cmdp
== 'H') {
312 if ( strlen(Cmd
)==0){
314 UsbCommand c
= {CMD_T55XX_READ_TRACE
, {0, 0, 0}};
316 if ( !WaitForResponseTimeout(CMD_ACK
,NULL
,2500) ) {
317 PrintAndLog("command execution time out");
321 //CmdSamples("12000");
324 size_t bitlen
= getFromGraphBuf(bits
);
328 RepaintGraphWindow();
331 uint32_t bl0
= PackBits(si
, 32, bits
);
332 uint32_t bl1
= PackBits(si
+32, 32, bits
);
334 uint32_t acl
= PackBits(si
, 8, bits
); si
+= 8;
335 uint32_t mfc
= PackBits(si
, 8, bits
); si
+= 8;
336 uint32_t cid
= PackBits(si
, 5, bits
); si
+= 5;
337 uint32_t icr
= PackBits(si
, 3, bits
); si
+= 3;
338 uint32_t year
= PackBits(si
, 4, bits
); si
+= 4;
339 uint32_t quarter
= PackBits(si
, 2, bits
); si
+= 2;
340 uint32_t lotid
= PackBits(si
, 12, bits
); si
+= 12;
341 uint32_t wafer
= PackBits(si
, 5, bits
); si
+= 5;
342 uint32_t dw
= PackBits(si
, 15, bits
);
345 PrintAndLog("-- T55xx Trace Information ----------------------------------");
346 PrintAndLog("-------------------------------------------------------------");
347 PrintAndLog(" ACL Allocation class (ISO/IEC 15963-1) : 0x%02X (%d)", acl
, acl
);
348 PrintAndLog(" MFC Manufacturer ID (ISO/IEC 7816-6) : 0x%02X (%d)", mfc
, mfc
);
349 PrintAndLog(" CID : 0x%02X (%d)", cid
, cid
);
350 PrintAndLog(" ICR IC Revision : %d",icr
);
351 PrintAndLog(" Manufactured");
352 PrintAndLog(" Year/Quarter : %d/%d",2000+year
, quarter
);
353 PrintAndLog(" Lot ID : %d", lotid
);
354 PrintAndLog(" Wafer number : %d", wafer
);
355 PrintAndLog(" Die Number : %d", dw
);
356 PrintAndLog("-------------------------------------------------------------");
357 PrintAndLog(" Raw Data - Page 1");
358 PrintAndLog(" Block 0 : 0x%08X %s", bl0
, sprint_bin(bits
+5,32) );
359 PrintAndLog(" Block 0 : 0x%08X %s", bl1
, sprint_bin(bits
+37,32) );
360 PrintAndLog("-------------------------------------------------------------");
364 1-8 ACL Allocation class (ISO/IEC 15963-1) 0xE0
365 9-16 MFC Manufacturer ID (ISO/IEC 7816-6) 0x15 Atmel Corporation
366 17-21 CID 0x1 = Atmel ATA5577M1 0x2 = Atmel ATA5577M2
367 22-24 ICR IC revision
368 25-28 YEAR (BCD encoded) 9 (= 2009)
369 29-30 QUARTER 1,2,3,4
375 18-32 DW, die number sequential
381 int CmdInfo(const char *Cmd
){
383 Page 0 Block 0 Configuration data.
387 char cmdp
= param_getchar(Cmd
, 0);
389 if (cmdp
== 'h' || cmdp
== 'H') {
390 return usage_t55xx_info();
397 uint8_t bits
[LF_BITSSTREAM_LEN
] = {0x00};
400 uint32_t bl0
= PackBits(si
, 32, bits
);
402 uint32_t safer
= PackBits(si
, 4, bits
); si
+= 4;
403 uint32_t resv
= PackBits(si
, 7, bits
); si
+= 7;
404 uint32_t dbr
= PackBits(si
, 3, bits
); si
+= 3;
405 uint32_t extend
= PackBits(si
, 1, bits
); si
+= 1;
406 uint32_t datamodulation
= PackBits(si
, 5, bits
); si
+= 5;
407 uint32_t pskcf
= PackBits(si
, 2, bits
); si
+= 2;
408 uint32_t aor
= PackBits(si
, 1, bits
); si
+= 1;
409 uint32_t otp
= PackBits(si
, 1, bits
); si
+= 1;
410 uint32_t maxblk
= PackBits(si
, 3, bits
); si
+= 3;
411 uint32_t pwd
= PackBits(si
, 1, bits
); si
+= 1;
412 uint32_t sst
= PackBits(si
, 1, bits
); si
+= 1;
413 uint32_t fw
= PackBits(si
, 1, bits
); si
+= 1;
414 uint32_t inv
= PackBits(si
, 1, bits
); si
+= 1;
415 uint32_t por
= PackBits(si
, 1, bits
); si
+= 1;
418 PrintAndLog("-- T55xx Configuration & Tag Information --------------------");
419 PrintAndLog("-------------------------------------------------------------");
420 PrintAndLog(" Safer key : %s", GetSaferStr(safer
));
421 PrintAndLog(" reserved : %d", resv
);
422 PrintAndLog(" Data bit rate : %s", GetBitRateStr(dbr
));
423 PrintAndLog(" eXtended mode : %s", (extend
) ? "Yes - Warning":"No");
424 PrintAndLog(" Modulation : %s", GetModulationStr(datamodulation
) );
425 PrintAndLog(" PSK clock freq : %d", pskcf
);
426 PrintAndLog(" AOR - Answer on Request : %s", (aor
) ? "Yes":"No");
427 PrintAndLog(" OTP - One Time Pad : %s", (otp
) ? "Yes - Warning":"No" );
428 PrintAndLog(" Max block : %d", maxblk
);
429 PrintAndLog(" Password mode : %s", (pwd
) ? "Yes":"No");
430 PrintAndLog(" Sequence Start Terminator : %s", (sst
) ? "Yes":"No");
431 PrintAndLog(" Fast Write : %s", (fw
) ? "Yes":"No");
432 PrintAndLog(" Inverse data : %s", (inv
) ? "Yes":"No");
433 PrintAndLog(" POR-Delay : %s", (por
) ? "Yes":"No");
434 PrintAndLog("-------------------------------------------------------------");
435 PrintAndLog(" Raw Data - Page 0");
436 PrintAndLog(" Block 0 : 0x%08X %s", bl0
, sprint_bin(bits
+5,32) );
437 PrintAndLog("-------------------------------------------------------------");
442 int CmdDump(const char *Cmd
){
445 uint8_t pwd
[4] = {0x00};
447 char cmdp
= param_getchar(Cmd
, 0);
448 if ( cmdp
== 'h' || cmdp
== 'H') {
453 bool hasPwd
= ( strlen(Cmd
) > 0);
455 if (param_gethex(Cmd
, 0, pwd
, 8)) {
456 PrintAndLog("password must include 8 HEX symbols");
461 for ( int i
= 0; i
<8; ++i
){
462 memset(s
,0,sizeof(s
));
464 sprintf(s
,"%d %02x%02x%02x%02x", i
, pwd
[0],pwd
[1],pwd
[2],pwd
[3]);
473 char * GetBitRateStr(uint32_t id
){
478 sprintf(retStr
,"%d - RF/8",id
);
481 sprintf(retStr
,"%d - RF/16",id
);
484 sprintf(retStr
,"%d - RF/32",id
);
487 sprintf(retStr
,"%d - RF/40",id
);
490 sprintf(retStr
,"%d - RF/50",id
);
493 sprintf(retStr
,"%d - RF/64",id
);
496 sprintf(retStr
,"%d - RF/100",id
);
499 sprintf(retStr
,"%d - RF/128",id
);
502 sprintf(retStr
,"%d - (Unknown)",id
);
509 char * GetSaferStr(uint32_t id
){
513 sprintf(retStr
,"%d",id
);
515 sprintf(retStr
,"%d - pasdwd",id
);
518 sprintf(retStr
,"%d - testmode ",id
);
523 char * GetModulationStr( uint32_t id
){
529 sprintf(retStr
,"%d - DIRECT (ASK/NRZ)",id
);
532 sprintf(retStr
,"%d - PSK 1 phase change when input changes",id
);
535 sprintf(retStr
,"%d - PSK 2 phase change on bitclk if input high",id
);
538 sprintf(retStr
,"%d - PSK 3 phase change on rising edge of input",id
);
541 sprintf(retStr
,"%d - FSK 1 RF/8 RF/5",id
);
544 sprintf(retStr
,"%d - FSK 2 RF/8 RF/10",id
);
547 sprintf(retStr
,"%d - FSK 1a RF/5 RF/8",id
);
550 sprintf(retStr
,"%d - FSK 2a RF/10 RF/8",id
);
553 sprintf(retStr
,"%d - Manschester",id
);
556 sprintf(retStr
,"%d - Biphase",id
);
559 sprintf(retStr
,"%d - Reserved",id
);
562 sprintf(retStr
,"0x%02X (Unknown)",id
);
568 uint32_t PackBits(uint8_t start
, uint8_t len
, uint8_t* bits
){
576 for (; j
>= 0; --j
, ++i
){
582 static command_t CommandTable
[] =
584 {"help", CmdHelp
, 1, "This help"},
585 {"config", CmdT55xxSetConfig
, 1, "Set T55XX config for modulation, inversed data"},
586 {"read", CmdReadBlk
, 0, "<block> [password] -- Read T55xx block data (page 0) [optional password]"},
587 {"write", CmdWriteBlk
, 0, "<block> <data> [password] -- Write T55xx block data (page 0) [optional password]"},
588 {"trace", CmdReadTrace
, 0, "[1] Read T55xx traceability data (page 1/ blk 0-1)"},
589 {"info", CmdInfo
, 0, "[1] Read T55xx configuration data (page 0/ blk 0)"},
590 {"dump", CmdDump
, 0, "[password] Dump T55xx card block 0-7. [optional password]"},
591 {NULL
, NULL
, 0, NULL
}
594 int CmdLFT55XX(const char *Cmd
)
596 CmdsParse(CommandTable
, Cmd
);
600 int CmdHelp(const char *Cmd
)
602 CmdsHelp(CommandTable
);