]>
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"
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 static int CmdHelp(const char *Cmd
);
30 // int CmdReadBlk(const char *Cmd)
33 // sscanf(Cmd, "%d", &block);
35 // if ((block > 7) | (block < 0)) {
36 // PrintAndLog("Block must be between 0 and 7");
41 // c.cmd = CMD_T55XX_READ_BLOCK;
42 // c.d.asBytes[0] = 0x00;
47 // WaitForResponse(CMD_ACK, NULL);
49 // uint8_t data[LF_TRACE_BUFF_SIZE] = {0x00};
51 // GetFromBigBuf(data,LF_TRACE_BUFF_SIZE,0); //3560 -- should be offset..
52 // WaitForResponseTimeout(CMD_ACK,NULL, 1500);
54 // for (int j = 0; j < LF_TRACE_BUFF_SIZE; j++) {
55 // GraphBuffer[j] = (int)data[j];
57 // GraphTraceLen = LF_TRACE_BUFF_SIZE;
58 // ManchesterDemod(block);
59 // RepaintGraphWindow();
63 int CmdReadBlk(const char *Cmd
)
72 uint8_t bits
[MAX_GRAPH_TRACE_LEN
] = {0x00};
74 sscanf(Cmd
, "%d", &block
);
76 if ((block
> 7) | (block
< 0)) {
77 PrintAndLog("Block must be between 0 and 7");
81 UsbCommand c
= { CMD_T55XX_READ_BLOCK
, { 0, block
, 0 } };
83 if ( !WaitForResponseTimeout(CMD_ACK
,NULL
,1500) ) {
84 PrintAndLog("command execution time out");
90 bitlen
= getFromGraphBuf(bits
);
92 errCnt
= askrawdemod(bits
, &bitlen
, &clk
, &invert
);
94 //throw away static - allow 1 and -1 (in case of threshold command first)
95 if ( errCnt
== -1 || bitlen
< 16 ){
96 PrintAndLog("no data found");
98 PrintAndLog("errCnt: %d, bitlen: %d, clk: %d, invert: %d", errCnt
, bitlen
, clk
, invert
);
102 PrintAndLog("Using Clock: %d - invert: %d - Bits Found: %d", clk
, invert
, bitlen
);
104 //move bits back to DemodBuffer
105 setDemodBuf(bits
, bitlen
, 0);
106 printBitStream(bits
,bitlen
);
108 // bits has the manchester encoded data.
109 errCnt
= manrawdecode(bits
, &bitlen
);
110 if ( errCnt
== -1 || bitlen
< 16 ){
111 PrintAndLog("no data found");
113 PrintAndLog("errCnt: %d, bitlen: %d, clk: %d, invert: %d", errCnt
, bitlen
, clk
, invert
);
117 blockData
= PackBits(0, 32, bits
);
120 PrintAndLog(" Decoded : 0x%08X %s", blockData
, sprint_bin(bits
,32) );
122 PrintAndLog(" Block %d : 0x%08X %s", block
, blockData
, sprint_bin(bits
,32) );
127 int CmdReadBlkPWD(const char *Cmd
)
129 int Block
= -1; //default to invalid block
130 int Password
= 0xFFFFFFFF; //default to blank Block 7
133 sscanf(Cmd
, "%d %x", &Block
, &Password
);
135 if ((Block
> 7) | (Block
< 0)) {
136 PrintAndLog("Block must be between 0 and 7");
140 PrintAndLog("Reading page 0 block %d pwd %08X", Block
, Password
);
142 UsbCommand c
= {CMD_T55XX_READ_BLOCK
, {0, Block
, Password
} };
143 c
.d
.asBytes
[0] = 0x1; //Password mode
145 WaitForResponse(CMD_ACK
, NULL
);
147 uint8_t data
[LF_TRACE_BUFF_SIZE
] = {0x00};
149 GetFromBigBuf(data
,LF_TRACE_BUFF_SIZE
,0);
150 WaitForResponseTimeout(CMD_ACK
,NULL
, 1500);
152 for (int j
= 0; j
< LF_TRACE_BUFF_SIZE
; j
++) {
153 GraphBuffer
[j
] = ((int)data
[j
]);
155 GraphTraceLen
= LF_TRACE_BUFF_SIZE
;
156 ManchesterDemod(Block
);
158 RepaintGraphWindow();
162 int CmdWriteBlk(const char *Cmd
)
164 int Block
= 8; //default to invalid block
165 int Data
= 0xFFFFFFFF; //default to blank Block
167 sscanf(Cmd
, "%d %x", &Block
, &Data
);
170 PrintAndLog("Block must be between 0 and 7");
174 PrintAndLog("Writing block %d data %08X", Block
, Data
);
176 UsbCommand c
= {CMD_T55XX_WRITE_BLOCK
, {Data
, Block
, 0}};
177 c
.d
.asBytes
[0] = 0x0; //Normal mode
182 int CmdWriteBlkPWD(const char *Cmd
)
184 int Block
= 8; //default to invalid block
185 int Data
= 0xFFFFFFFF; //default to blank Block
186 int Password
= 0xFFFFFFFF; //default to blank Block 7
189 sscanf(Cmd
, "%d %x %x",&Block
, &Data
, &Password
);
192 PrintAndLog("Block must be between 0 and 7");
196 PrintAndLog("Writing block %d data %08X password %08X", Block
, Data
, Password
);
198 UsbCommand c
= {CMD_T55XX_WRITE_BLOCK
, {Data
, Block
, Password
}};
199 c
.d
.asBytes
[0] = 0x1; //Password mode
204 int CmdReadTrace(const char *Cmd
)
206 char cmdp
= param_getchar(Cmd
, 0);
208 if (strlen(Cmd
) > 1 || cmdp
== 'h' || cmdp
== 'H') {
209 PrintAndLog("Usage: lf t55xx trace [use data from Graphbuffer]");
210 PrintAndLog(" [use data from Graphbuffer], if not set, try reading data from tag.");
212 PrintAndLog(" sample: lf t55xx trace");
213 PrintAndLog(" : lf t55xx trace 1");
217 if ( strlen(Cmd
)==0){
219 UsbCommand c
= {CMD_T55XX_READ_TRACE
, {0, 0, 0}};
221 WaitForResponse(CMD_ACK
, NULL
);
223 uint8_t data
[LF_TRACE_BUFF_SIZE
] = {0x00};
225 GetFromBigBuf(data
,LF_TRACE_BUFF_SIZE
,0); //3560 -- should be offset..
226 WaitForResponseTimeout(CMD_ACK
,NULL
, 1500);
228 for (int j
= 0; j
< LF_TRACE_BUFF_SIZE
; j
++) {
229 GraphBuffer
[j
] = ((int)data
[j
]);
231 GraphTraceLen
= LF_TRACE_BUFF_SIZE
;
234 uint8_t bits
[LF_BITSSTREAM_LEN
] = {0x00};
235 uint8_t * bitstream
= bits
;
237 manchester_decode(GraphBuffer
, LF_TRACE_BUFF_SIZE
, bitstream
, LF_BITSSTREAM_LEN
);
238 RepaintGraphWindow();
241 uint32_t bl0
= PackBits(si
, 32, bitstream
);
242 uint32_t bl1
= PackBits(si
+32, 32, bitstream
);
244 uint32_t acl
= PackBits(si
, 8, bitstream
); si
+= 8;
245 uint32_t mfc
= PackBits(si
, 8, bitstream
); si
+= 8;
246 uint32_t cid
= PackBits(si
, 5, bitstream
); si
+= 5;
247 uint32_t icr
= PackBits(si
, 3, bitstream
); si
+= 3;
248 uint32_t year
= PackBits(si
, 4, bitstream
); si
+= 4;
249 uint32_t quarter
= PackBits(si
, 2, bitstream
); si
+= 2;
250 uint32_t lotid
= PackBits(si
, 12, bitstream
); si
+= 12;
251 uint32_t wafer
= PackBits(si
, 5, bitstream
); si
+= 5;
252 uint32_t dw
= PackBits(si
, 15, bitstream
);
255 PrintAndLog("-- T55xx Trace Information ----------------------------------");
256 PrintAndLog("-------------------------------------------------------------");
257 PrintAndLog(" ACL Allocation class (ISO/IEC 15963-1) : 0x%02X (%d)", acl
, acl
);
258 PrintAndLog(" MFC Manufacturer ID (ISO/IEC 7816-6) : 0x%02X (%d)", mfc
, mfc
);
259 PrintAndLog(" CID : 0x%02X (%d)", cid
, cid
);
260 PrintAndLog(" ICR IC Revision : %d",icr
);
261 PrintAndLog(" Manufactured");
262 PrintAndLog(" Year/Quarter : %d/%d",2000+year
, quarter
);
263 PrintAndLog(" Lot ID : %d", lotid
);
264 PrintAndLog(" Wafer number : %d", wafer
);
265 PrintAndLog(" Die Number : %d", dw
);
266 PrintAndLog("-------------------------------------------------------------");
267 PrintAndLog(" Raw Data - Page 1");
268 PrintAndLog(" Block 0 : 0x%08X %s", bl0
, sprint_bin(bitstream
+5,32) );
269 PrintAndLog(" Block 0 : 0x%08X %s", bl1
, sprint_bin(bitstream
+37,32) );
270 PrintAndLog("-------------------------------------------------------------");
274 1-8 ACL Allocation class (ISO/IEC 15963-1) 0xE0
275 9-16 MFC Manufacturer ID (ISO/IEC 7816-6) 0x15 Atmel Corporation
276 17-21 CID 0x1 = Atmel ATA5577M1 0x2 = Atmel ATA5577M2
277 22-24 ICR IC revision
278 25-28 YEAR (BCD encoded) 9 (= 2009)
279 29-30 QUARTER 1,2,3,4
285 18-32 DW, die number sequential
291 int CmdInfo(const char *Cmd
){
293 Page 0 Block 0 Configuration data.
297 char cmdp
= param_getchar(Cmd
, 0);
299 if (strlen(Cmd
) > 1 || cmdp
== 'h' || cmdp
== 'H') {
300 PrintAndLog("Usage: lf t55xx info [use data from Graphbuffer]");
301 PrintAndLog(" [use data from Graphbuffer], if not set, try reading data from tag.");
303 PrintAndLog(" sample: lf t55xx info");
304 PrintAndLog(" sample: lf t55xx info 1");
308 if ( strlen(Cmd
) == 0 ){
312 uint8_t bits
[LF_BITSSTREAM_LEN
] = {0x00};
314 manchester_decode(GraphBuffer
, LF_TRACE_BUFF_SIZE
, bits
, LF_BITSSTREAM_LEN
);
317 uint32_t bl0
= PackBits(si
, 32, bits
);
319 uint32_t safer
= PackBits(si
, 4, bits
); si
+= 4;
320 uint32_t resv
= PackBits(si
, 7, bits
); si
+= 7;
321 uint32_t dbr
= PackBits(si
, 3, bits
); si
+= 3;
322 uint32_t extend
= PackBits(si
, 1, bits
); si
+= 1;
323 uint32_t datamodulation
= PackBits(si
, 5, bits
); si
+= 5;
324 uint32_t pskcf
= PackBits(si
, 2, bits
); si
+= 2;
325 uint32_t aor
= PackBits(si
, 1, bits
); si
+= 1;
326 uint32_t otp
= PackBits(si
, 1, bits
); si
+= 1;
327 uint32_t maxblk
= PackBits(si
, 3, bits
); si
+= 3;
328 uint32_t pwd
= PackBits(si
, 1, bits
); si
+= 1;
329 uint32_t sst
= PackBits(si
, 1, bits
); si
+= 1;
330 uint32_t fw
= PackBits(si
, 1, bits
); si
+= 1;
331 uint32_t inv
= PackBits(si
, 1, bits
); si
+= 1;
332 uint32_t por
= PackBits(si
, 1, bits
); si
+= 1;
335 PrintAndLog("-- T55xx Configuration & Tag Information --------------------");
336 PrintAndLog("-------------------------------------------------------------");
337 PrintAndLog(" Safer key : %s", GetSaferStr(safer
));
338 PrintAndLog(" reserved : %d", resv
);
339 PrintAndLog(" Data bit rate : %s", GetBitRateStr(dbr
));
340 PrintAndLog(" eXtended mode : %s", (extend
) ? "Yes - Warning":"No");
341 PrintAndLog(" Modulation : %s", GetModulationStr(datamodulation
) );
342 PrintAndLog(" PSK clock freq : %d", pskcf
);
343 PrintAndLog(" AOR - Answer on Request : %s", (aor
) ? "Yes":"No");
344 PrintAndLog(" OTP - One Time Pad : %s", (otp
) ? "Yes - Warning":"No" );
345 PrintAndLog(" Max block : %d", maxblk
);
346 PrintAndLog(" Password mode : %s", (pwd
) ? "Yes":"No");
347 PrintAndLog(" Sequence Start Terminator : %s", (sst
) ? "Yes":"No");
348 PrintAndLog(" Fast Write : %s", (fw
) ? "Yes":"No");
349 PrintAndLog(" Inverse data : %s", (inv
) ? "Yes":"No");
350 PrintAndLog(" POR-Delay : %s", (por
) ? "Yes":"No");
351 PrintAndLog("-------------------------------------------------------------");
352 PrintAndLog(" Raw Data - Page 0");
353 PrintAndLog(" Block 0 : 0x%08X %s", bl0
, sprint_bin(bits
+5,32) );
354 PrintAndLog("-------------------------------------------------------------");
359 int CmdDump(const char *Cmd
){
361 char cmdp
= param_getchar(Cmd
, 0);
363 uint8_t pwd
[4] = {0x00};
364 bool hasPwd
= ( strlen(Cmd
) > 0);
366 if ( cmdp
== 'h' || cmdp
== 'H') {
367 PrintAndLog("Usage: lf t55xx dump <password>");
368 PrintAndLog(" sample: lf t55xx dump FFFFFFFF");
373 if (param_gethex(Cmd
, 0, pwd
, 8)) {
374 PrintAndLog("password must include 8 HEX symbols");
379 for ( int i
= 0; i
<8; ++i
){
380 memset(s
,0,sizeof(s
));
382 sprintf(s
,"%d %02x%02x%02x%02x", i
, pwd
[0],pwd
[1],pwd
[2],pwd
[3]);
392 int CmdIceFsk(const char *Cmd
){
394 if (!HasGraphData()) return 0;
396 iceFsk3(GraphBuffer
, LF_TRACE_BUFF_SIZE
);
397 RepaintGraphWindow();
400 int CmdIceManchester(const char *Cmd
){
401 ManchesterDemod( -1);
404 int ManchesterDemod(int blockNum
){
406 if (!HasGraphData()) return 0;
408 uint8_t sizebyte
= 32;
409 // the value 5 was selected during empirical studies of the decoded data. Some signal noise to skip.
412 uint8_t bits
[LF_BITSSTREAM_LEN
] = {0x00};
413 uint8_t * bitstream
= bits
;
415 manchester_decode(GraphBuffer
, LF_TRACE_BUFF_SIZE
, bits
, LF_BITSSTREAM_LEN
);
416 blockData
= PackBits(offset
, sizebyte
, bits
);
419 PrintAndLog(" Decoded : 0x%08X %s", blockData
, sprint_bin(bitstream
+offset
,sizebyte
) );
421 PrintAndLog(" Block %d : 0x%08X %s", blockNum
, blockData
, sprint_bin(bitstream
+offset
,sizebyte
) );
426 char * GetBitRateStr(uint32_t id
){
431 sprintf(retStr
,"%d - RF/8",id
);
434 sprintf(retStr
,"%d - RF/16",id
);
437 sprintf(retStr
,"%d - RF/32",id
);
440 sprintf(retStr
,"%d - RF/40",id
);
443 sprintf(retStr
,"%d - RF/50",id
);
446 sprintf(retStr
,"%d - RF/64",id
);
449 sprintf(retStr
,"%d - RF/100",id
);
452 sprintf(retStr
,"%d - RF/128",id
);
455 sprintf(retStr
,"%d - (Unknown)",id
);
462 char * GetSaferStr(uint32_t id
){
466 sprintf(retStr
,"%d",id
);
468 sprintf(retStr
,"%d - pasdwd",id
);
471 sprintf(retStr
,"%d - testmode ",id
);
476 char * GetModulationStr( uint32_t id
){
482 sprintf(retStr
,"%d - DIRECT (ASK/NRZ)",id
);
485 sprintf(retStr
,"%d - PSK 1 phase change when input changes",id
);
488 sprintf(retStr
,"%d - PSK 2 phase change on bitclk if input high",id
);
491 sprintf(retStr
,"%d - PSK 3 phase change on rising edge of input",id
);
494 sprintf(retStr
,"%d - FSK 1 RF/8 RF/5",id
);
497 sprintf(retStr
,"%d - FSK 2 RF/8 RF/10",id
);
500 sprintf(retStr
,"%d - FSK 1a RF/5 RF/8",id
);
503 sprintf(retStr
,"%d - FSK 2a RF/10 RF/8",id
);
506 sprintf(retStr
,"%d - Manschester",id
);
509 sprintf(retStr
,"%d - Biphase",id
);
512 sprintf(retStr
,"%d - Reserved",id
);
515 sprintf(retStr
,"0x%02X (Unknown)",id
);
522 uint32_t PackBits(uint8_t start
, uint8_t len
, uint8_t* bits
){
530 for (; j
>= 0; --j
, ++i
){
536 static command_t CommandTable
[] =
538 {"help", CmdHelp
, 1, "This help"},
539 {"rd", CmdReadBlk
, 0, "<block> -- Read T55xx block data (page 0)"},
540 {"rdpwd", CmdReadBlkPWD
, 0, "<block> <password> -- Read T55xx block data with password mode"},
541 {"wr", CmdWriteBlk
, 0, "<block> <data> -- Write T55xx block data (page 0)"},
542 {"wrpwd", CmdWriteBlkPWD
, 0, "<block> <password> <data> -- Write T55xx block data with password"},
543 {"trace", CmdReadTrace
, 0, "[1] Read T55xx traceability data (page 1/ blk 0-1)"},
544 {"info", CmdInfo
, 0, "[1] Read T55xx configuration data (page 0/ blk 0)"},
545 {"dump", CmdDump
, 0, "[password] Dump T55xx card block 0-7. optional with password"},
546 //{"fsk", CmdIceFsk, 0, "FSK demod"},
547 {"man", CmdIceManchester
, 0, "Manchester demod (with SST)"},
548 {NULL
, NULL
, 0, NULL
}
551 int CmdLFT55XX(const char *Cmd
)
553 CmdsParse(CommandTable
, Cmd
);
557 int CmdHelp(const char *Cmd
)
559 CmdsHelp(CommandTable
);