]>
cvs.zerfleddert.de Git - proxmark3-svn/blob - client/cmdlft55xx.c
5804fbc7eb4921ed0da4d344a9d64ac636493f7c
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"
25 #define LF_TRACE_BUFF_SIZE 12000 // 32 x 32 x 10 (32 bit times numofblock (7), times clock skip..)
26 static int CmdHelp(const char *Cmd
);
29 int CmdReadBlk(const char *Cmd
)
32 sscanf(Cmd
, "%d", &Block
);
34 if ((Block
> 7) | (Block
< 0)) {
35 PrintAndLog("Block must be between 0 and 7");
40 c
.cmd
= CMD_T55XX_READ_BLOCK
;
41 c
.d
.asBytes
[0] = 0x00;
46 WaitForResponse(CMD_ACK
, NULL
);
48 // uint8_t data[LF_TRACE_BUFF_SIZE] = {0x00};
50 // GetFromBigBuf(data,LF_TRACE_BUFF_SIZE,3560); //3560 -- should be offset..
51 // WaitForResponseTimeout(CMD_ACK,NULL, 1500);
53 // for (int j = 0; j < LF_TRACE_BUFF_SIZE; j++) {
54 // GraphBuffer[j] = (int)data[j];
56 // GraphTraceLen = LF_TRACE_BUFF_SIZE;
58 ManchesterDemod(Block
);
59 // RepaintGraphWindow();
63 int CmdReadBlkPWD(const char *Cmd
)
65 int Block
= -1; //default to invalid block
66 int Password
= 0xFFFFFFFF; //default to blank Block 7
69 sscanf(Cmd
, "%d %x", &Block
, &Password
);
71 if ((Block
> 7) | (Block
< 0)) {
72 PrintAndLog("Block must be between 0 and 7");
76 PrintAndLog("Reading page 0 block %d pwd %08X", Block
, Password
);
78 c
.cmd
= CMD_T55XX_READ_BLOCK
;
79 c
.d
.asBytes
[0] = 0x1; //Password mode
84 WaitForResponse(CMD_ACK
, NULL
);
86 uint8_t data
[LF_TRACE_BUFF_SIZE
] = {0x00};
88 GetFromBigBuf(data
,LF_TRACE_BUFF_SIZE
,3560); //3560 -- should be offset..
89 WaitForResponseTimeout(CMD_ACK
,NULL
, 1500);
91 for (int j
= 0; j
< LF_TRACE_BUFF_SIZE
; j
++) {
92 GraphBuffer
[j
] = ((int)data
[j
]);
94 GraphTraceLen
= LF_TRACE_BUFF_SIZE
;
95 ManchesterDemod(Block
);
100 int CmdWriteBlk(const char *Cmd
)
102 int Block
= 8; //default to invalid block
103 int Data
= 0xFFFFFFFF; //default to blank Block
106 sscanf(Cmd
, "%x %d", &Data
, &Block
);
109 PrintAndLog("Block must be between 0 and 7");
113 PrintAndLog("Writting block %d with data %08X", Block
, Data
);
115 c
.cmd
= CMD_T55XX_WRITE_BLOCK
;
116 c
.d
.asBytes
[0] = 0x0; //Normal mode
124 int CmdWriteBlkPWD(const char *Cmd
)
126 int Block
= 8; //default to invalid block
127 int Data
= 0xFFFFFFFF; //default to blank Block
128 int Password
= 0xFFFFFFFF; //default to blank Block 7
131 sscanf(Cmd
, "%x %d %x", &Data
, &Block
, &Password
);
134 PrintAndLog("Block must be between 0 and 7");
138 PrintAndLog("Writting block %d with data %08X and password %08X", Block
, Data
, Password
);
140 c
.cmd
= CMD_T55XX_WRITE_BLOCK
;
141 c
.d
.asBytes
[0] = 0x1; //Password mode
149 int CmdReadTrace(const char *Cmd
)
151 char cmdp
= param_getchar(Cmd
, 0);
153 if (strlen(Cmd
) > 1 || cmdp
== 'h' || cmdp
== 'H') {
154 PrintAndLog("Usage: lf t55xx trace [use data from Graphbuffer]");
155 PrintAndLog(" [use data from Graphbuffer], if not set, try reading data from tag.");
157 PrintAndLog(" sample: lf t55xx trace");
158 PrintAndLog(" sample: lf t55xx trace 1");
162 if ( strlen(Cmd
)==0){
163 UsbCommand c
= {CMD_T55XX_READ_TRACE
, {0, 0, 0}};
165 WaitForResponse(CMD_ACK
, NULL
);
167 uint8_t data
[LF_TRACE_BUFF_SIZE
] = {0x00};
169 GetFromBigBuf(data
,LF_TRACE_BUFF_SIZE
,3560); //3560 -- should be offset..
170 WaitForResponseTimeout(CMD_ACK
,NULL
, 1500);
172 for (int j
= 0; j
< LF_TRACE_BUFF_SIZE
; j
++) {
173 GraphBuffer
[j
] = ((int)data
[j
]);
175 GraphTraceLen
= LF_TRACE_BUFF_SIZE
;
178 uint8_t bits
[1000] = {0x00};
179 uint8_t * bitstream
= bits
;
181 manchester_decode(GraphBuffer
, LF_TRACE_BUFF_SIZE
, bitstream
);
182 RepaintGraphWindow();
185 uint32_t bl0
= PackBits(si
, 32, bitstream
);
186 uint32_t bl1
= PackBits(si
+32, 32, bitstream
);
188 uint32_t acl
= PackBits(si
, 8, bitstream
); si
+= 8;
189 uint32_t mfc
= PackBits(si
, 8, bitstream
); si
+= 8;
190 uint32_t cid
= PackBits(si
, 5, bitstream
); si
+= 5;
191 uint32_t icr
= PackBits(si
, 3, bitstream
); si
+= 3;
192 uint32_t year
= PackBits(si
, 4, bitstream
); si
+= 4;
193 uint32_t quarter
= PackBits(si
, 2, bitstream
); si
+= 2;
194 uint32_t lotid
= PackBits(si
, 12, bitstream
); si
+= 12;
195 uint32_t wafer
= PackBits(si
, 5, bitstream
); si
+= 5;
196 uint32_t dw
= PackBits(si
, 15, bitstream
);
199 PrintAndLog("-- T55xx Trace Information ----------------------------------");
200 PrintAndLog("-------------------------------------------------------------");
201 PrintAndLog(" ACL Allocation class (ISO/IEC 15963-1) : 0x%02X (%d)", acl
, acl
);
202 PrintAndLog(" MFC Manufacturer ID (ISO/IEC 7816-6) : 0x%02X (%d)", mfc
, mfc
);
203 PrintAndLog(" CID : 0x%02X (%d)", cid
, cid
);
204 PrintAndLog(" ICR IC Revision : %d",icr
);
205 PrintAndLog(" Manufactured");
206 PrintAndLog(" Year/Quarter : %d/%d",2000+year
, quarter
);
207 PrintAndLog(" Lot ID : %d", lotid
);
208 PrintAndLog(" Wafer number : %d", wafer
);
209 PrintAndLog(" Die Number : %d", dw
);
210 PrintAndLog("-------------------------------------------------------------");
211 PrintAndLog(" Raw Data - Page 1");
212 PrintAndLog(" Block 0 : 0x%08X %s", bl0
, sprint_bin(bitstream
+5,32) );
213 PrintAndLog(" Block 0 : 0x%08X %s", bl1
, sprint_bin(bitstream
+37,32) );
214 PrintAndLog("-------------------------------------------------------------");
218 1-8 ACL Allocation class (ISO/IEC 15963-1) 0xE0
219 9-16 MFC Manufacturer ID (ISO/IEC 7816-6) 0x15 Atmel Corporation
220 17-21 CID 0x1 = Atmel ATA5577M1 0x2 = Atmel ATA5577M2
221 22-24 ICR IC revision
222 25-28 YEAR (BCD encoded) 9 (= 2009)
223 29-30 QUARTER 1,2,3,4
229 18-32 DW, die number sequential
235 int CmdInfo(const char *Cmd
){
237 Page 0 Block 0 Configuration data.
241 char cmdp
= param_getchar(Cmd
, 0);
243 if (strlen(Cmd
) > 1 || cmdp
== 'h' || cmdp
== 'H') {
244 PrintAndLog("Usage: lf t55xx info [use data from Graphbuffer]");
245 PrintAndLog(" [use data from Graphbuffer], if not set, try reading data from tag.");
247 PrintAndLog(" sample: lf t55xx info");
248 PrintAndLog(" sample: lf t55xx info 1");
252 if ( strlen(Cmd
)==0){
256 uint8_t bits
[1000] = {0x00};
257 uint8_t * bitstream
= bits
;
259 manchester_decode(GraphBuffer
, LF_TRACE_BUFF_SIZE
, bitstream
);
262 uint32_t bl0
= PackBits(si
, 32, bitstream
);
264 uint32_t safer
= PackBits(si
, 4, bitstream
); si
+= 4;
265 uint32_t resv
= PackBits(si
, 7, bitstream
); si
+= 7;
266 uint32_t dbr
= PackBits(si
, 3, bitstream
); si
+= 3;
267 uint32_t extend
= PackBits(si
, 1, bitstream
); si
+= 1;
268 uint32_t datamodulation
= PackBits(si
, 5, bitstream
); si
+= 5;
269 uint32_t pskcf
= PackBits(si
, 2, bitstream
); si
+= 2;
270 uint32_t aor
= PackBits(si
, 1, bitstream
); si
+= 1;
271 uint32_t otp
= PackBits(si
, 1, bitstream
); si
+= 1;
272 uint32_t maxblk
= PackBits(si
, 3, bitstream
); si
+= 3;
273 uint32_t pwd
= PackBits(si
, 1, bitstream
); si
+= 1;
274 uint32_t sst
= PackBits(si
, 1, bitstream
); si
+= 1;
275 uint32_t fw
= PackBits(si
, 1, bitstream
); si
+= 1;
276 uint32_t inv
= PackBits(si
, 1, bitstream
); si
+= 1;
277 uint32_t por
= PackBits(si
, 1, bitstream
); si
+= 1;
280 PrintAndLog("-- T55xx Configuration --------------------------------------");
281 PrintAndLog("-------------------------------------------------------------");
282 PrintAndLog(" Safer key : %s", GetSaferStr(safer
));
283 PrintAndLog(" reserved : %d", resv
);
284 PrintAndLog(" Data bit rate : %s", GetBitRateStr(dbr
));
285 PrintAndLog(" eXtended mode : %s", (extend
) ? "Yes - Warning":"No");
286 PrintAndLog(" Modulation : %s", GetModulationStr(datamodulation
) );
287 PrintAndLog(" PSK clock freq : %d", pskcf
);
288 PrintAndLog(" AOR - Answer on Request : %s", (aor
) ? "Yes":"No");
289 PrintAndLog(" OTP - One Time Pad : %s", (otp
) ? "Yes - Warning":"No" );
290 PrintAndLog(" Max block : %d", maxblk
);
291 PrintAndLog(" Password mode : %s", (pwd
) ? "Yes":"No");
292 PrintAndLog(" Sequence Start Terminator : %s", (sst
) ? "Yes":"No");
293 PrintAndLog(" Fast Write : %s", (fw
) ? "Yes":"No");
294 PrintAndLog(" Inverse data : %s", (inv
) ? "Yes":"No");
295 PrintAndLog(" POR-Delay : %s", (por
) ? "Yes":"No");
296 PrintAndLog("-------------------------------------------------------------");
297 PrintAndLog(" Raw Data - Page 0");
298 PrintAndLog(" Block 0 : 0x%08X %s", bl0
, sprint_bin(bitstream
+5,32) );
299 PrintAndLog("-------------------------------------------------------------");
304 int CmdDump(const char *Cmd
){
306 char cmdp
= param_getchar(Cmd
, 0);
308 uint8_t pwd
[4] = {0x00};
310 if (strlen(Cmd
)>1 || cmdp
== 'h' || cmdp
== 'H') {
311 PrintAndLog("Usage: lf t55xx dump <password>");
312 PrintAndLog(" sample: lf t55xx dump FFFFFFFF");
316 bool hasPwd
= ( strlen(Cmd
) > 0);
319 if (param_gethex(Cmd
, 0, pwd
, 4)) {
320 PrintAndLog("password must include 4 HEX symbols");
325 for ( int i
= 0; i
<8; ++i
){
328 sprintf(s
,"%d %d", i
, pwd
);
338 int CmdIceFsk(const char *Cmd
){
339 iceFsk3(GraphBuffer
, LF_TRACE_BUFF_SIZE
);
340 RepaintGraphWindow();
343 int CmdIceManchester(const char *Cmd
){
344 ManchesterDemod( -1);
347 int ManchesterDemod(int block
){
350 uint8_t sizebyte
= 32;
353 uint8_t bits
[1000] = {0x00};
354 uint8_t * bitstream
= bits
;
356 manchester_decode(GraphBuffer
, LF_TRACE_BUFF_SIZE
, bitstream
);
357 blockData
= PackBits(offset
, sizebyte
, bitstream
);
360 PrintAndLog(" Decoded : 0x%08X %s", blockData
, sprint_bin(bitstream
+offset
,sizebyte
) );
362 PrintAndLog(" Block %d : 0x%08X %s", blockNum
, blockData
, sprint_bin(bitstream
+offset
,sizebyte
) );
367 char * GetBitRateStr(uint32_t id
){
372 sprintf(retStr
,"%d - RF/8",id
);
375 sprintf(retStr
,"%d - RF/16",id
);
378 sprintf(retStr
,"%d - RF/32",id
);
381 sprintf(retStr
,"%d - RF/40",id
);
384 sprintf(retStr
,"%d - RF/50",id
);
387 sprintf(retStr
,"%d - RF/64",id
);
390 sprintf(retStr
,"%d - RF/100",id
);
393 sprintf(retStr
,"%d - RF/128",id
);
396 sprintf(retStr
,"%d - (Unknown)",id
);
403 char * GetSaferStr(uint32_t id
){
407 sprintf(retStr
,"%d",id
);
409 sprintf(retStr
,"%d - pasdwd",id
);
412 sprintf(retStr
,"%d - testmode ",id
);
417 char * GetModulationStr( uint32_t id
){
423 sprintf(retStr
,"%d - DIRECT (ASK/NRZ)",id
);
426 sprintf(retStr
,"%d - PSK 1 phase change when input changes",id
);
429 sprintf(retStr
,"%d - PSK 2 phase change on bitclk if input high",id
);
432 sprintf(retStr
,"%d - PSK 3 phase change on rising edge of input",id
);
435 sprintf(retStr
,"%d - FSK 1 RF/8 RF/5",id
);
438 sprintf(retStr
,"%d - FSK 2 RF/8 RF/10",id
);
441 sprintf(retStr
,"%d - FSK 1a RF/5 RF/8",id
);
444 sprintf(retStr
,"%d - FSK 2a RF/10 RF/8",id
);
447 sprintf(retStr
,"%d - Manschester",id
);
450 sprintf(retStr
,"%d - Biphase",id
);
453 sprintf(retStr
,"%d - Reserved",id
);
456 sprintf(retStr
,"0x%02X (Unknown)",id
);
463 uint32_t PackBits(uint8_t start
, uint8_t len
, uint8_t* bits
){
468 for (; j
>= 0; --j
, ++i
){
474 static command_t CommandTable
[] =
476 {"help", CmdHelp
, 1, "This help"},
477 {"rd", CmdReadBlk
, 0, "<block> -- Read T55xx block data (page 0)"},
478 {"rdpwd", CmdReadBlkPWD
, 0, "<block> <password> -- Read T55xx block data with password mode"},
479 {"wr", CmdWriteBlk
, 0, "<data> <block> -- Write T55xx block data (page 0)"},
480 {"wrpwd", CmdWriteBlkPWD
, 0, "<data> <block> <password> -- Write T55xx block data with password"},
481 {"trace", CmdReadTrace
, 0, "[1] Read T55xx traceability data (page 1 / blk 0-1) "},
482 {"info", CmdInfo
, 0, "[1] Read T55xx configuration data (page0 /blk 0)"},
483 {"dump", CmdDump
, 0, "[password] Dump T55xx card block 0-7. optional with password"},
484 {"fsk", CmdIceFsk
, 0, "FSK demod"},
485 {"man", CmdIceManchester
, 0, "Manchester demod (with SST)"},
486 {NULL
, NULL
, 0, NULL
}
489 int CmdLFT55XX(const char *Cmd
)
491 CmdsParse(CommandTable
, Cmd
);
495 int CmdHelp(const char *Cmd
)
497 CmdsHelp(CommandTable
);