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