]> cvs.zerfleddert.de Git - proxmark3-svn/blame - client/cmdlft55xx.c
icemans lf fixes & adjustments + lf t55xx bruteforce
[proxmark3-svn] / client / cmdlft55xx.c
CommitLineData
54a942b0 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
224ce36e 13#include <time.h>\r
54a942b0 14#include "proxmark3.h"\r
15#include "ui.h"\r
16#include "graph.h"\r
13d77ef9 17#include "cmdmain.h"\r
54a942b0 18#include "cmdparser.h"\r
19#include "cmddata.h"\r
20#include "cmdlf.h"\r
21#include "cmdlft55xx.h"\r
13d77ef9 22#include "util.h"\r
23#include "data.h"\r
24#include "lfdemod.h"\r
25#include "../common/crc.h"\r
26#include "../common/iso14443crc.h"\r
27#include "cmdhf14a.h"\r
28\r
709665b5 29#define T55x7_CONFIGURATION_BLOCK 0x00\r
30#define T55x7_PAGE0 0x00\r
31#define T55x7_PAGE1 0x01\r
506672c4 32#define T55x7_PWD 0x00000010\r
be2d41b7 33#define REGULAR_READ_MODE_BLOCK 0xFF\r
13d77ef9 34\r
35// Default configuration\r
f6650679 36t55xx_conf_block_t config = { .modulation = DEMOD_ASK, .inverted = FALSE, .offset = 0x00, .block0 = 0x00, .Q5 = FALSE };\r
13d77ef9 37\r
9f669cb2 38t55xx_conf_block_t Get_t55xx_Config(){\r
39 return config;\r
40}\r
41void Set_t55xx_Config(t55xx_conf_block_t conf){\r
42 config = conf;\r
43}\r
44\r
13d77ef9 45int usage_t55xx_config(){\r
f6650679 46 PrintAndLog("Usage: lf t55xx config [d <demodulation>] [i 1] [o <offset>] [Q5]");\r
be2d41b7 47 PrintAndLog("Options:");\r
13d77ef9 48 PrintAndLog(" h This help");\r
f6650679 49 PrintAndLog(" b <8|16|32|40|50|64|100|128> Set bitrate");\r
4ff341ef 50 PrintAndLog(" d <FSK|FSK1|FSK1a|FSK2|FSK2a|ASK|PSK1|PSK2|NRZ|BI|BIa> Set demodulation FSK / ASK / PSK / NRZ / Biphase / Biphase A");\r
f6650679 51 PrintAndLog(" i [1] Invert data signal, defaults to normal");\r
52 PrintAndLog(" o [offset] Set offset, where data should start decode in bitstream");\r
53 PrintAndLog(" Q5 Set as Q5(T5555) chip instead of T55x7");\r
13d77ef9 54 PrintAndLog("");\r
55 PrintAndLog("Examples:");\r
56 PrintAndLog(" lf t55xx config d FSK - FSK demodulation");\r
57 PrintAndLog(" lf t55xx config d FSK i 1 - FSK demodulation, inverse data");\r
58 PrintAndLog(" lf t55xx config d FSK i 1 o 3 - FSK demodulation, inverse data, offset=3,start from position 3 to decode data");\r
59 PrintAndLog("");\r
60 return 0;\r
61}\r
62int usage_t55xx_read(){\r
0c8200f1 63 PrintAndLog("Usage: lf t55xx read [b <block>] [p <password>] <override_safety> <page1>");\r
be2d41b7 64 PrintAndLog("Options:");\r
0c8200f1 65 PrintAndLog(" b <block> - block number to read. Between 0-7");\r
66 PrintAndLog(" p <password> - OPTIONAL password (8 hex characters)");\r
67 PrintAndLog(" o - OPTIONAL override safety check");\r
68 PrintAndLog(" 1 - OPTIONAL read Page 1 instead of Page 0");\r
f1b74c30 69 PrintAndLog(" ****WARNING****");\r
70 PrintAndLog(" Use of read with password on a tag not configured for a pwd");\r
71 PrintAndLog(" can damage the tag");\r
185e038c 72 PrintAndLog("");\r
13d77ef9 73 PrintAndLog("Examples:");\r
0c8200f1 74 PrintAndLog(" lf t55xx read b 0 - read data from block 0");\r
be2d41b7 75 PrintAndLog(" lf t55xx read b 0 p feedbeef - read data from block 0 password feedbeef");\r
76 PrintAndLog(" lf t55xx read b 0 p feedbeef o - read data from block 0 password feedbeef safety check");\r
13d77ef9 77 PrintAndLog("");\r
78 return 0;\r
79}\r
80int usage_t55xx_write(){\r
0c8200f1 81 PrintAndLog("Usage: lf t55xx wr [b <block>] [d <data>] [p <password>] [1]");\r
be2d41b7 82 PrintAndLog("Options:");\r
0c8200f1 83 PrintAndLog(" b <block> - block number to write. Between 0-7");\r
84 PrintAndLog(" d <data> - 4 bytes of data to write (8 hex characters)");\r
85 PrintAndLog(" p <password> - OPTIONAL password 4bytes (8 hex characters)");\r
86 PrintAndLog(" 1 - OPTIONAL write Page 1 instead of Page 0");\r
185e038c 87 PrintAndLog("");\r
13d77ef9 88 PrintAndLog("Examples:");\r
be2d41b7 89 PrintAndLog(" lf t55xx wr b 3 d 11223344 - write 11223344 to block 3");\r
90 PrintAndLog(" lf t55xx wr b 3 d 11223344 p feedbeef - write 11223344 to block 3 password feedbeef");\r
13d77ef9 91 PrintAndLog("");\r
92 return 0;\r
93}\r
94int usage_t55xx_trace() {\r
95 PrintAndLog("Usage: lf t55xx trace [1]");\r
be2d41b7 96 PrintAndLog("Options:");\r
0c8200f1 97 PrintAndLog(" [graph buffer data] - if set, use Graphbuffer otherwise read data from tag.");\r
13d77ef9 98 PrintAndLog("");\r
99 PrintAndLog("Examples:");\r
100 PrintAndLog(" lf t55xx trace");\r
101 PrintAndLog(" lf t55xx trace 1");\r
102 PrintAndLog("");\r
103 return 0;\r
104}\r
105int usage_t55xx_info() {\r
106 PrintAndLog("Usage: lf t55xx info [1]");\r
be2d41b7 107 PrintAndLog("Options:");\r
0c8200f1 108 PrintAndLog(" [graph buffer data] - if set, use Graphbuffer otherwise read data from tag.");\r
13d77ef9 109 PrintAndLog("");\r
110 PrintAndLog("Examples:");\r
111 PrintAndLog(" lf t55xx info");\r
112 PrintAndLog(" lf t55xx info 1");\r
113 PrintAndLog("");\r
114 return 0;\r
115}\r
116int usage_t55xx_dump(){\r
be2d41b7 117 PrintAndLog("Usage: lf t55xx dump <password> [o]");\r
118 PrintAndLog("Options:");\r
0c8200f1 119 PrintAndLog(" <password> - OPTIONAL password 4bytes (8 hex symbols)");\r
120 PrintAndLog(" o - OPTIONAL override, force pwd read despite danger to card");\r
13d77ef9 121 PrintAndLog("");\r
122 PrintAndLog("Examples:");\r
123 PrintAndLog(" lf t55xx dump");\r
be2d41b7 124 PrintAndLog(" lf t55xx dump feedbeef o");\r
13d77ef9 125 PrintAndLog("");\r
126 return 0;\r
127}\r
128int usage_t55xx_detect(){\r
ab5ffe3b 129 PrintAndLog("Usage: lf t55xx detect [1] [p <password>]");\r
be2d41b7 130 PrintAndLog("Options:");\r
ab5ffe3b 131 PrintAndLog(" 1 - if set, use Graphbuffer otherwise read data from tag.");\r
132 PrintAndLog(" p <password> - OPTIONAL password (8 hex characters)");\r
13d77ef9 133 PrintAndLog("");\r
134 PrintAndLog("Examples:");\r
135 PrintAndLog(" lf t55xx detect");\r
136 PrintAndLog(" lf t55xx detect 1");\r
ab5ffe3b 137 PrintAndLog(" lf t55xx detect p 11223344");\r
13d77ef9 138 PrintAndLog("");\r
139 return 0;\r
140}\r
be2d41b7 141int usage_t55xx_wakup(){\r
142 PrintAndLog("Usage: lf t55xx wakeup [h] p <password>");\r
143 PrintAndLog("This commands send the Answer-On-Request command and leaves the readerfield ON afterwards.");\r
144 PrintAndLog("Options:");\r
145 PrintAndLog(" h - this help");\r
146 PrintAndLog(" p <password> - password 4bytes (8 hex symbols)");\r
147 PrintAndLog("");\r
148 PrintAndLog("Examples:");\r
149 PrintAndLog(" lf t55xx wakeup p 11223344 - send wakeup password");\r
150 return 0;\r
151}\r
506672c4 152int usage_t55xx_bruteforce(){\r
153 PrintAndLog("Usage: lf t55xx bruteforce <start password> <end password> [i <*.dic>]");\r
154 PrintAndLog(" password must be 4 bytes (8 hex symbols)");\r
155 PrintAndLog("Options:");\r
156 PrintAndLog(" h - this help");\r
157 PrintAndLog(" i <*.dic> - loads a default keys dictionary file <*.dic>");\r
158 PrintAndLog("");\r
159 PrintAndLog("Examples:");\r
160 PrintAndLog(" lf t55xx bruteforce aaaaaaaa bbbbbbbb");\r
161 PrintAndLog(" lf t55xx bruteforce i mykeys.dic");\r
162 PrintAndLog("");\r
163 return 0;\r
164}\r
54a942b0 165\r
166static int CmdHelp(const char *Cmd);\r
167\r
709665b5 168void printT5xxHeader(uint8_t page){\r
506672c4 169 PrintAndLog("Reading Page %d:", page);\r
709665b5 170 PrintAndLog("blk | hex data | binary");\r
171 PrintAndLog("----+----------+---------------------------------"); \r
172}\r
173\r
13d77ef9 174int CmdT55xxSetConfig(const char *Cmd) {\r
54a942b0 175\r
13d77ef9 176 uint8_t offset = 0;\r
13d77ef9 177 char modulation[5] = {0x00};\r
178 char tmp = 0x00;\r
179 uint8_t bitRate = 0;\r
180 uint8_t rates[9] = {8,16,32,40,50,64,100,128,0};\r
8e99ec25 181 uint8_t cmdp = 0;\r
f6650679 182 config.Q5 = FALSE;\r
8e99ec25 183 bool errors = FALSE;\r
13d77ef9 184 while(param_getchar(Cmd, cmdp) != 0x00 && !errors)\r
185 {\r
186 tmp = param_getchar(Cmd, cmdp);\r
187 switch(tmp)\r
188 {\r
189 case 'h':\r
190 case 'H':\r
191 return usage_t55xx_config();\r
192 case 'b':\r
193 errors |= param_getdec(Cmd, cmdp+1, &bitRate);\r
194 if ( !errors){\r
195 uint8_t i = 0;\r
196 for (; i < 9; i++){\r
197 if (rates[i]==bitRate) {\r
198 config.bitrate = i;\r
199 break;\r
200 }\r
201 }\r
202 if (i==9) errors = TRUE;\r
203 }\r
204 cmdp+=2;\r
205 break;\r
206 case 'd':\r
207 param_getstr(Cmd, cmdp+1, modulation);\r
208 cmdp += 2;\r
54a942b0 209\r
2767fc02 210 if ( strcmp(modulation, "FSK" ) == 0) {\r
13d77ef9 211 config.modulation = DEMOD_FSK;\r
2767fc02 212 } else if ( strcmp(modulation, "FSK1" ) == 0) {\r
13d77ef9 213 config.modulation = DEMOD_FSK1;\r
2767fc02 214 config.inverted=1;\r
215 } else if ( strcmp(modulation, "FSK1a" ) == 0) {\r
13d77ef9 216 config.modulation = DEMOD_FSK1a;\r
2767fc02 217 config.inverted=0;\r
218 } else if ( strcmp(modulation, "FSK2" ) == 0) {\r
13d77ef9 219 config.modulation = DEMOD_FSK2;\r
2767fc02 220 config.inverted=0;\r
221 } else if ( strcmp(modulation, "FSK2a" ) == 0) {\r
13d77ef9 222 config.modulation = DEMOD_FSK2a;\r
2767fc02 223 config.inverted=1;\r
224 } else if ( strcmp(modulation, "ASK" ) == 0) {\r
13d77ef9 225 config.modulation = DEMOD_ASK;\r
2767fc02 226 } else if ( strcmp(modulation, "NRZ" ) == 0) {\r
13d77ef9 227 config.modulation = DEMOD_NRZ;\r
2767fc02 228 } else if ( strcmp(modulation, "PSK1" ) == 0) {\r
13d77ef9 229 config.modulation = DEMOD_PSK1;\r
2767fc02 230 } else if ( strcmp(modulation, "PSK2" ) == 0) {\r
13d77ef9 231 config.modulation = DEMOD_PSK2;\r
2767fc02 232 } else if ( strcmp(modulation, "PSK3" ) == 0) {\r
13d77ef9 233 config.modulation = DEMOD_PSK3;\r
2767fc02 234 } else if ( strcmp(modulation, "BIa" ) == 0) {\r
13d77ef9 235 config.modulation = DEMOD_BIa;\r
2767fc02 236 config.inverted=1;\r
237 } else if ( strcmp(modulation, "BI" ) == 0) {\r
13d77ef9 238 config.modulation = DEMOD_BI;\r
2767fc02 239 config.inverted=0;\r
240 } else {\r
13d77ef9 241 PrintAndLog("Unknown modulation '%s'", modulation);\r
242 errors = TRUE;\r
243 }\r
244 break;\r
245 case 'i':\r
246 config.inverted = param_getchar(Cmd,cmdp+1) == '1';\r
247 cmdp+=2;\r
248 break;\r
249 case 'o':\r
250 errors |= param_getdec(Cmd, cmdp+1, &offset);\r
251 if ( !errors )\r
252 config.offset = offset;\r
253 cmdp+=2;\r
254 break;\r
f6650679 255 case 'Q':\r
256 case 'q': \r
257 config.Q5 = TRUE;\r
258 cmdp++;\r
259 break;\r
13d77ef9 260 default:\r
261 PrintAndLog("Unknown parameter '%c'", param_getchar(Cmd, cmdp));\r
262 errors = TRUE;\r
263 break;\r
264 }\r
265 }\r
54a942b0 266\r
13d77ef9 267 // No args\r
be2d41b7 268 if (cmdp == 0) return printConfiguration( config );\r
269\r
13d77ef9 270 //Validations\r
be2d41b7 271 if (errors) return usage_t55xx_config();\r
54a942b0 272\r
be2d41b7 273 config.block0 = 0;\r
274 return printConfiguration ( config );\r
275}\r
276\r
277int T55xxReadBlock(uint8_t block, bool page1, bool usepwd, bool override, uint32_t password){\r
278 //Password mode\r
279 if ( usepwd ) {\r
280 // try reading the config block and verify that PWD bit is set before doing this!\r
281 if ( !override ) {\r
709665b5 282 if ( !AquireData(T55x7_PAGE0, T55x7_CONFIGURATION_BLOCK, false, 0 ) ) return 0;\r
be2d41b7 283 if ( !tryDetectModulation() ) {\r
284 PrintAndLog("Safety Check: Could not detect if PWD bit is set in config block. Exits.");\r
285 return 0;\r
286 } else {\r
287 PrintAndLog("Safety Check: PWD bit is NOT set in config block. Reading without password..."); \r
288 usepwd = false;\r
289 page1 = false;\r
290 }\r
291 } else {\r
292 PrintAndLog("Safety Check Overriden - proceeding despite risk");\r
293 }\r
294 }\r
295\r
296 if (!AquireData(page1, block, usepwd, password) ) return 0;\r
297 if (!DecodeT55xxBlock()) return 0;\r
298\r
299 char blk[10]={0};\r
300 sprintf(blk,"%d", block);\r
301 printT55xxBlock(blk); \r
302 return 1;\r
13d77ef9 303}\r
54a942b0 304\r
13d77ef9 305int CmdT55xxReadBlock(const char *Cmd) {\r
be2d41b7 306 uint8_t block = REGULAR_READ_MODE_BLOCK;\r
307 uint32_t password = 0; //default to blank Block 7\r
308 bool usepwd = false;\r
309 bool override = false;\r
310 bool page1 = false;\r
8e99ec25 311 bool errors = false;\r
be2d41b7 312 uint8_t cmdp = 0;\r
8e99ec25 313 while(param_getchar(Cmd, cmdp) != 0x00 && !errors) {\r
314 switch(param_getchar(Cmd, cmdp)) {\r
315 case 'h':\r
316 case 'H':\r
317 return usage_t55xx_read();\r
318 case 'b':\r
319 case 'B':\r
320 errors |= param_getdec(Cmd, cmdp+1, &block);\r
be2d41b7 321 cmdp += 2;\r
8e99ec25 322 break;\r
323 case 'o':\r
324 case 'O':\r
be2d41b7 325 override = true;\r
8e99ec25 326 cmdp++;\r
327 break;\r
328 case 'p':\r
329 case 'P':\r
be2d41b7 330 password = param_get32ex(Cmd, cmdp+1, 0, 16);\r
331 usepwd = true;\r
332 cmdp += 2;\r
8e99ec25 333 break;\r
be2d41b7 334 case '1':\r
335 page1 = true;\r
8e99ec25 336 cmdp++;\r
337 break;\r
338 default:\r
339 PrintAndLog("Unknown parameter '%c'", param_getchar(Cmd, cmdp));\r
340 errors = true;\r
341 break;\r
342 }\r
343 }\r
344 if (errors) return usage_t55xx_read();\r
13d77ef9 345\r
be2d41b7 346 if (block > 7 && block != REGULAR_READ_MODE_BLOCK ) {\r
347 PrintAndLog("Block must be between 0 and 7");\r
348 return 0;\r
8e99ec25 349 }\r
709665b5 350\r
351 printT5xxHeader(page1);\r
be2d41b7 352 return T55xxReadBlock(block, page1, usepwd, override, password);\r
54a942b0 353}\r
354\r
13d77ef9 355bool DecodeT55xxBlock(){\r
356 \r
fef74fdc 357 char buf[30] = {0x00};\r
13d77ef9 358 char *cmdStr = buf;\r
359 int ans = 0;\r
360 uint8_t bitRate[8] = {8,16,32,40,50,64,100,128};\r
13d77ef9 361 DemodBufferLen = 0x00;\r
54a942b0 362\r
13d77ef9 363 switch( config.modulation ){\r
364 case DEMOD_FSK:\r
224ce36e 365 snprintf(cmdStr, sizeof(buf),"%d %d", bitRate[config.bitrate], config.inverted );\r
13d77ef9 366 ans = FSKrawDemod(cmdStr, FALSE);\r
367 break;\r
368 case DEMOD_FSK1:\r
13d77ef9 369 case DEMOD_FSK1a:\r
224ce36e 370 snprintf(cmdStr, sizeof(buf),"%d %d 8 5", bitRate[config.bitrate], config.inverted );\r
13d77ef9 371 ans = FSKrawDemod(cmdStr, FALSE);\r
372 break;\r
373 case DEMOD_FSK2:\r
13d77ef9 374 case DEMOD_FSK2a:\r
224ce36e 375 snprintf(cmdStr, sizeof(buf),"%d %d 10 8", bitRate[config.bitrate], config.inverted );\r
13d77ef9 376 ans = FSKrawDemod(cmdStr, FALSE);\r
377 break;\r
378 case DEMOD_ASK:\r
db829602 379 snprintf(cmdStr, sizeof(buf),"%d %d 1", bitRate[config.bitrate], config.inverted );\r
fef74fdc 380 ans = ASKDemod(cmdStr, FALSE, FALSE, 1);\r
13d77ef9 381 break;\r
382 case DEMOD_PSK1:\r
db829602 383 // skip first 160 samples to allow antenna to settle in (psk gets inverted occasionally otherwise)\r
384 CmdLtrim("160");\r
385 snprintf(cmdStr, sizeof(buf),"%d %d 6", bitRate[config.bitrate], config.inverted );\r
13d77ef9 386 ans = PSKDemod(cmdStr, FALSE);\r
13d77ef9 387 break;\r
2767fc02 388 case DEMOD_PSK2: //inverted won't affect this\r
389 case DEMOD_PSK3: //not fully implemented\r
db829602 390 // skip first 160 samples to allow antenna to settle in (psk gets inverted occasionally otherwise)\r
391 CmdLtrim("160");\r
392 snprintf(cmdStr, sizeof(buf),"%d 0 6", bitRate[config.bitrate] );\r
13d77ef9 393 ans = PSKDemod(cmdStr, FALSE);\r
394 psk1TOpsk2(DemodBuffer, DemodBufferLen);\r
395 break;\r
396 case DEMOD_NRZ:\r
224ce36e 397 snprintf(cmdStr, sizeof(buf),"%d %d 1", bitRate[config.bitrate], config.inverted );\r
13d77ef9 398 ans = NRZrawDemod(cmdStr, FALSE);\r
399 break;\r
400 case DEMOD_BI:\r
13d77ef9 401 case DEMOD_BIa:\r
db829602 402 snprintf(cmdStr, sizeof(buf),"0 %d %d 1", bitRate[config.bitrate], config.inverted );\r
13d77ef9 403 ans = ASKbiphaseDemod(cmdStr, FALSE);\r
404 break;\r
405 default:\r
406 return FALSE;\r
407 }\r
408 return (bool) ans;\r
409}\r
54a942b0 410\r
13d77ef9 411int CmdT55xxDetect(const char *Cmd){\r
ab5ffe3b 412 bool errors = FALSE;\r
413 bool useGB = FALSE;\r
414 bool usepwd = FALSE;\r
415 uint32_t password = 0;\r
416 uint8_t cmdp = 0;\r
54a942b0 417\r
ab5ffe3b 418 while(param_getchar(Cmd, cmdp) != 0x00 && !errors) {\r
419 switch(param_getchar(Cmd, cmdp)) {\r
420 case 'h':\r
421 case 'H':\r
422 return usage_t55xx_detect();\r
423 case 'p':\r
424 case 'P':\r
425 password = param_get32ex(Cmd, cmdp+1, 0, 16);\r
426 usepwd = TRUE;\r
427 cmdp += 2;\r
428 break;\r
429 case '1':\r
430 // use Graphbuffer data\r
431 useGB = TRUE;\r
432 cmdp++;\r
433 break;\r
434 default:\r
435 PrintAndLog("Unknown parameter '%c'", param_getchar(Cmd, cmdp));\r
436 errors = true;\r
437 break;\r
438 }\r
709665b5 439 }\r
ab5ffe3b 440 if (errors) return usage_t55xx_detect();\r
13d77ef9 441 \r
ab5ffe3b 442 if ( !useGB) {\r
443 if ( !AquireData(T55x7_PAGE0, T55x7_CONFIGURATION_BLOCK, usepwd, password) )\r
444 return 0;\r
709665b5 445 }\r
ab5ffe3b 446 \r
13d77ef9 447 if ( !tryDetectModulation() )\r
448 PrintAndLog("Could not detect modulation automatically. Try setting it manually with \'lf t55xx config\'");\r
449\r
be2d41b7 450 return 1;\r
54a942b0 451}\r
452\r
13d77ef9 453// detect configuration?\r
454bool tryDetectModulation(){\r
13d77ef9 455 uint8_t hits = 0;\r
456 t55xx_conf_block_t tests[15];\r
fef74fdc 457 int bitRate=0;\r
322f7eb1 458 uint8_t fc1 = 0, fc2 = 0, clk=0;\r
709665b5 459\r
13d77ef9 460 if (GetFskClock("", FALSE, FALSE)){ \r
13d77ef9 461 fskClocks(&fc1, &fc2, &clk, FALSE);\r
f6650679 462 if ( FSKrawDemod("0 0", FALSE) && test(DEMOD_FSK, &tests[hits].offset, &bitRate, clk, &tests[hits].Q5)){\r
13d77ef9 463 tests[hits].modulation = DEMOD_FSK;\r
464 if (fc1==8 && fc2 == 5)\r
465 tests[hits].modulation = DEMOD_FSK1a;\r
f6650679 466 else if (fc1==10 && fc2 == 8)\r
13d77ef9 467 tests[hits].modulation = DEMOD_FSK2;\r
fef74fdc 468 tests[hits].bitrate = bitRate;\r
13d77ef9 469 tests[hits].inverted = FALSE;\r
470 tests[hits].block0 = PackBits(tests[hits].offset, 32, DemodBuffer);\r
471 ++hits;\r
472 }\r
f6650679 473 if ( FSKrawDemod("0 1", FALSE) && test(DEMOD_FSK, &tests[hits].offset, &bitRate, clk, &tests[hits].Q5)) {\r
13d77ef9 474 tests[hits].modulation = DEMOD_FSK;\r
fef74fdc 475 if (fc1 == 8 && fc2 == 5)\r
13d77ef9 476 tests[hits].modulation = DEMOD_FSK1;\r
fef74fdc 477 else if (fc1 == 10 && fc2 == 8)\r
13d77ef9 478 tests[hits].modulation = DEMOD_FSK2a;\r
54a942b0 479\r
fef74fdc 480 tests[hits].bitrate = bitRate;\r
13d77ef9 481 tests[hits].inverted = TRUE;\r
482 tests[hits].block0 = PackBits(tests[hits].offset, 32, DemodBuffer);\r
483 ++hits;\r
484 }\r
485 } else {\r
322f7eb1 486 clk = GetAskClock("", FALSE, FALSE);\r
487 if (clk>0) {\r
db829602 488 if ( ASKDemod("0 0 1", FALSE, FALSE, 1) && test(DEMOD_ASK, &tests[hits].offset, &bitRate, clk, &tests[hits].Q5)) {\r
322f7eb1 489 tests[hits].modulation = DEMOD_ASK;\r
490 tests[hits].bitrate = bitRate;\r
491 tests[hits].inverted = FALSE;\r
492 tests[hits].block0 = PackBits(tests[hits].offset, 32, DemodBuffer);\r
493 ++hits;\r
494 }\r
db829602 495 if ( ASKDemod("0 1 1", FALSE, FALSE, 1) && test(DEMOD_ASK, &tests[hits].offset, &bitRate, clk, &tests[hits].Q5)) {\r
322f7eb1 496 tests[hits].modulation = DEMOD_ASK;\r
497 tests[hits].bitrate = bitRate;\r
498 tests[hits].inverted = TRUE;\r
499 tests[hits].block0 = PackBits(tests[hits].offset, 32, DemodBuffer);\r
500 ++hits;\r
501 }\r
db829602 502 if ( ASKbiphaseDemod("0 0 0 2", FALSE) && test(DEMOD_BI, &tests[hits].offset, &bitRate, clk, &tests[hits].Q5) ) {\r
322f7eb1 503 tests[hits].modulation = DEMOD_BI;\r
504 tests[hits].bitrate = bitRate;\r
505 tests[hits].inverted = FALSE;\r
506 tests[hits].block0 = PackBits(tests[hits].offset, 32, DemodBuffer);\r
507 ++hits;\r
508 }\r
db829602 509 if ( ASKbiphaseDemod("0 0 1 2", FALSE) && test(DEMOD_BIa, &tests[hits].offset, &bitRate, clk, &tests[hits].Q5) ) {\r
322f7eb1 510 tests[hits].modulation = DEMOD_BIa;\r
511 tests[hits].bitrate = bitRate;\r
512 tests[hits].inverted = TRUE;\r
513 tests[hits].block0 = PackBits(tests[hits].offset, 32, DemodBuffer);\r
514 ++hits;\r
515 }\r
13d77ef9 516 }\r
322f7eb1 517 //undo trim from ask\r
506672c4 518 //save_restoreGB(0);\r
322f7eb1 519 clk = GetNrzClock("", FALSE, FALSE);\r
520 if (clk>0) {\r
f6650679 521 if ( NRZrawDemod("0 0 1", FALSE) && test(DEMOD_NRZ, &tests[hits].offset, &bitRate, clk, &tests[hits].Q5)) {\r
322f7eb1 522 tests[hits].modulation = DEMOD_NRZ;\r
523 tests[hits].bitrate = bitRate;\r
524 tests[hits].inverted = FALSE;\r
525 tests[hits].block0 = PackBits(tests[hits].offset, 32, DemodBuffer);\r
526 ++hits;\r
527 }\r
54a942b0 528\r
f6650679 529 if ( NRZrawDemod("0 1 1", FALSE) && test(DEMOD_NRZ, &tests[hits].offset, &bitRate, clk, &tests[hits].Q5)) {\r
322f7eb1 530 tests[hits].modulation = DEMOD_NRZ;\r
531 tests[hits].bitrate = bitRate;\r
532 tests[hits].inverted = TRUE;\r
533 tests[hits].block0 = PackBits(tests[hits].offset, 32, DemodBuffer);\r
534 ++hits;\r
535 }\r
13d77ef9 536 }\r
537 \r
506672c4 538 // allow undo\r
db829602 539 // skip first 160 samples to allow antenna to settle in (psk gets inverted occasionally otherwise)\r
506672c4 540 save_restoreGB(1);\r
db829602 541 CmdLtrim("160");\r
322f7eb1 542 clk = GetPskClock("", FALSE, FALSE);\r
543 if (clk>0) {\r
db829602 544 if ( PSKDemod("0 0 6", FALSE) && test(DEMOD_PSK1, &tests[hits].offset, &bitRate, clk, &tests[hits].Q5)) {\r
322f7eb1 545 tests[hits].modulation = DEMOD_PSK1;\r
fef74fdc 546 tests[hits].bitrate = bitRate;\r
13d77ef9 547 tests[hits].inverted = FALSE;\r
548 tests[hits].block0 = PackBits(tests[hits].offset, 32, DemodBuffer);\r
549 ++hits;\r
550 }\r
db829602 551 if ( PSKDemod("0 1 6", FALSE) && test(DEMOD_PSK1, &tests[hits].offset, &bitRate, clk, &tests[hits].Q5)) {\r
322f7eb1 552 tests[hits].modulation = DEMOD_PSK1;\r
fef74fdc 553 tests[hits].bitrate = bitRate;\r
322f7eb1 554 tests[hits].inverted = TRUE;\r
13d77ef9 555 tests[hits].block0 = PackBits(tests[hits].offset, 32, DemodBuffer);\r
556 ++hits;\r
557 }\r
322f7eb1 558 // PSK2 - needs a call to psk1TOpsk2.\r
db829602 559 if ( PSKDemod("0 0 6", FALSE)) {\r
322f7eb1 560 psk1TOpsk2(DemodBuffer, DemodBufferLen);\r
f6650679 561 if (test(DEMOD_PSK2, &tests[hits].offset, &bitRate, clk, &tests[hits].Q5)){\r
322f7eb1 562 tests[hits].modulation = DEMOD_PSK2;\r
563 tests[hits].bitrate = bitRate;\r
564 tests[hits].inverted = FALSE;\r
565 tests[hits].block0 = PackBits(tests[hits].offset, 32, DemodBuffer);\r
566 ++hits;\r
567 }\r
568 } // inverse waves does not affect this demod\r
569 // PSK3 - needs a call to psk1TOpsk2.\r
db829602 570 if ( PSKDemod("0 0 6", FALSE)) {\r
322f7eb1 571 psk1TOpsk2(DemodBuffer, DemodBufferLen);\r
f6650679 572 if (test(DEMOD_PSK3, &tests[hits].offset, &bitRate, clk, &tests[hits].Q5)){\r
322f7eb1 573 tests[hits].modulation = DEMOD_PSK3;\r
574 tests[hits].bitrate = bitRate;\r
575 tests[hits].inverted = FALSE;\r
576 tests[hits].block0 = PackBits(tests[hits].offset, 32, DemodBuffer);\r
577 ++hits;\r
578 }\r
579 } // inverse waves does not affect this demod\r
13d77ef9 580 }\r
506672c4 581 //undo trim samples\r
582 save_restoreGB(0);\r
6fe5c94b 583 } \r
13d77ef9 584 if ( hits == 1) {\r
585 config.modulation = tests[0].modulation;\r
fef74fdc 586 config.bitrate = tests[0].bitrate;\r
13d77ef9 587 config.inverted = tests[0].inverted;\r
588 config.offset = tests[0].offset;\r
589 config.block0 = tests[0].block0;\r
590 printConfiguration( config );\r
591 return TRUE;\r
592 }\r
593 \r
594 if ( hits > 1) {\r
595 PrintAndLog("Found [%d] possible matches for modulation.",hits);\r
596 for(int i=0; i<hits; ++i){\r
597 PrintAndLog("--[%d]---------------", i+1);\r
598 printConfiguration( tests[i] );\r
599 }\r
600 }\r
601 return FALSE;\r
602}\r
603\r
604bool testModulation(uint8_t mode, uint8_t modread){\r
605 switch( mode ){\r
606 case DEMOD_FSK:\r
9f669cb2 607 if (modread >= DEMOD_FSK1 && modread <= DEMOD_FSK2a) return TRUE;\r
13d77ef9 608 break;\r
609 case DEMOD_ASK:\r
610 if (modread == DEMOD_ASK) return TRUE;\r
611 break;\r
612 case DEMOD_PSK1:\r
613 if (modread == DEMOD_PSK1) return TRUE;\r
614 break;\r
615 case DEMOD_PSK2:\r
616 if (modread == DEMOD_PSK2) return TRUE;\r
617 break;\r
618 case DEMOD_PSK3:\r
619 if (modread == DEMOD_PSK3) return TRUE;\r
620 break;\r
621 case DEMOD_NRZ:\r
622 if (modread == DEMOD_NRZ) return TRUE;\r
623 break;\r
624 case DEMOD_BI:\r
625 if (modread == DEMOD_BI) return TRUE;\r
626 break;\r
627 case DEMOD_BIa:\r
628 if (modread == DEMOD_BIa) return TRUE;\r
629 break; \r
630 default:\r
631 return FALSE;\r
632 }\r
633 return FALSE;\r
634}\r
635\r
f6650679 636bool testQ5Modulation(uint8_t mode, uint8_t modread){\r
637 switch( mode ){\r
13d77ef9 638 case DEMOD_FSK:\r
f6650679 639 if (modread >= 4 && modread <= 5) return TRUE;\r
13d77ef9 640 break;\r
641 case DEMOD_ASK:\r
f6650679 642 if (modread == 0) return TRUE;\r
13d77ef9 643 break;\r
644 case DEMOD_PSK1:\r
f6650679 645 if (modread == 1) return TRUE;\r
646 break;\r
13d77ef9 647 case DEMOD_PSK2:\r
f6650679 648 if (modread == 2) return TRUE;\r
649 break;\r
13d77ef9 650 case DEMOD_PSK3:\r
f6650679 651 if (modread == 3) return TRUE;\r
13d77ef9 652 break;\r
653 case DEMOD_NRZ:\r
f6650679 654 if (modread == 7) return TRUE;\r
655 break;\r
656 case DEMOD_BI:\r
657 if (modread == 6) return TRUE;\r
13d77ef9 658 break;\r
13d77ef9 659 default:\r
660 return FALSE;\r
661 }\r
662 return FALSE;\r
663}\r
664\r
f6650679 665bool testQ5(uint8_t mode, uint8_t *offset, int *fndBitRate, uint8_t clk){\r
666\r
667 if ( DemodBufferLen < 64 ) return FALSE;\r
668 uint8_t si = 0;\r
db829602 669 for (uint8_t idx = 28; idx < 64; idx++){\r
f6650679 670 si = idx;\r
db829602 671 if ( PackBits(si, 28, DemodBuffer) == 0x00 ) continue;\r
f6650679 672\r
673 uint8_t safer = PackBits(si, 4, DemodBuffer); si += 4; //master key\r
674 uint8_t resv = PackBits(si, 8, DemodBuffer); si += 8;\r
675 // 2nibble must be zeroed.\r
f6650679 676 if (safer != 0x6) continue;\r
677 if ( resv > 0x00) continue;\r
678 //uint8_t pageSel = PackBits(si, 1, DemodBuffer); si += 1;\r
679 //uint8_t fastWrite = PackBits(si, 1, DemodBuffer); si += 1;\r
680 si += 1+1;\r
681 int bitRate = PackBits(si, 5, DemodBuffer)*2 + 2; si += 5; //bit rate\r
db829602 682 if (bitRate > 128 || bitRate < 8) continue;\r
f6650679 683\r
db829602 684 //uint8_t AOR = PackBits(si, 1, DemodBuffer); si += 1; \r
f6650679 685 //uint8_t PWD = PackBits(si, 1, DemodBuffer); si += 1; \r
686 //uint8_t pskcr = PackBits(si, 2, DemodBuffer); si += 2; //could check psk cr\r
687 //uint8_t inverse = PackBits(si, 1, DemodBuffer); si += 1;\r
db829602 688 si += 1+1+2+1;\r
689 uint8_t modread = PackBits(si, 3, DemodBuffer); si += 3;\r
690 uint8_t maxBlk = PackBits(si, 3, DemodBuffer); si += 3;\r
f6650679 691 //uint8_t ST = PackBits(si, 1, DemodBuffer); si += 1;\r
db829602 692 if (maxBlk == 0) continue;\r
f6650679 693 //test modulation\r
694 if (!testQ5Modulation(mode, modread)) continue;\r
695 if (bitRate != clk) continue;\r
696 *fndBitRate = bitRate;\r
697 *offset = idx;\r
698\r
699 return TRUE;\r
700 }\r
701 return FALSE;\r
702}\r
703\r
704bool testBitRate(uint8_t readRate, uint8_t clk){\r
db829602 705 uint8_t expected[] = {8, 16, 32, 40, 50, 64, 100, 128};\r
f6650679 706 if (expected[readRate] == clk)\r
707 return true;\r
708\r
709 return false;\r
710}\r
711\r
712bool test(uint8_t mode, uint8_t *offset, int *fndBitRate, uint8_t clk, bool *Q5){\r
13d77ef9 713\r
fef74fdc 714 if ( DemodBufferLen < 64 ) return FALSE;\r
13d77ef9 715 uint8_t si = 0;\r
db829602 716 for (uint8_t idx = 28; idx < 64; idx++){\r
13d77ef9 717 si = idx;\r
db829602 718 if ( PackBits(si, 28, DemodBuffer) == 0x00 ) continue;\r
13d77ef9 719\r
2767fc02 720 uint8_t safer = PackBits(si, 4, DemodBuffer); si += 4; //master key\r
13d77ef9 721 uint8_t resv = PackBits(si, 4, DemodBuffer); si += 4; //was 7 & +=7+3 //should be only 4 bits if extended mode\r
722 // 2nibble must be zeroed.\r
723 // moved test to here, since this gets most faults first.\r
724 if ( resv > 0x00) continue;\r
725\r
2767fc02 726 uint8_t xtRate = PackBits(si, 3, DemodBuffer); si += 3; //extended mode part of rate\r
db829602 727 int bitRate = PackBits(si, 3, DemodBuffer); si += 3; //bit rate\r
fef74fdc 728 if (bitRate > 7) continue;\r
13d77ef9 729 uint8_t extend = PackBits(si, 1, DemodBuffer); si += 1; //bit 15 extended mode\r
2767fc02 730 uint8_t modread = PackBits(si, 5, DemodBuffer); si += 5+2+1; \r
731 //uint8_t pskcr = PackBits(si, 2, DemodBuffer); si += 2+1; //could check psk cr\r
732 uint8_t nml01 = PackBits(si, 1, DemodBuffer); si += 1+5; //bit 24, 30, 31 could be tested for 0 if not extended mode\r
13d77ef9 733 uint8_t nml02 = PackBits(si, 2, DemodBuffer); si += 2;\r
734 \r
735 //if extended mode\r
736 bool extMode =( (safer == 0x6 || safer == 0x9) && extend) ? TRUE : FALSE;\r
737\r
738 if (!extMode){\r
739 if (nml01 || nml02 || xtRate) continue;\r
740 }\r
741 //test modulation\r
742 if (!testModulation(mode, modread)) continue;\r
f6650679 743 if (!testBitRate(bitRate, clk)) continue;\r
fef74fdc 744 *fndBitRate = bitRate;\r
2767fc02 745 *offset = idx;\r
f6650679 746 *Q5 = FALSE;\r
747 return TRUE;\r
748 }\r
749 if (testQ5(mode, offset, fndBitRate, clk)) {\r
750 *Q5 = TRUE;\r
13d77ef9 751 return TRUE;\r
752 }\r
753 return FALSE;\r
54a942b0 754}\r
755\r
224ce36e 756void printT55xxBlock(const char *blockNum){\r
13d77ef9 757 \r
758 uint8_t i = config.offset;\r
759 uint8_t endpos = 32 + i;\r
760 uint32_t blockData = 0;\r
761 uint8_t bits[64] = {0x00};\r
762\r
763 if ( !DemodBufferLen) return;\r
764\r
765 if ( endpos > DemodBufferLen){\r
766 PrintAndLog("The configured offset %d is too big. Possible offset: %d)", i, DemodBufferLen-32);\r
767 return;\r
768 }\r
769\r
770 for (; i < endpos; ++i)\r
771 bits[i - config.offset]=DemodBuffer[i];\r
93507a33 772\r
13d77ef9 773 blockData = PackBits(0, 32, bits);\r
db829602 774\r
be2d41b7 775 PrintAndLog(" %s | %08X | %s", blockNum, blockData, sprint_bin(bits,32));\r
13d77ef9 776}\r
777\r
778int special(const char *Cmd) {\r
779 uint32_t blockData = 0;\r
780 uint8_t bits[32] = {0x00};\r
781\r
be2d41b7 782 PrintAndLog("OFFSET | DATA | BINARY");\r
13d77ef9 783 PrintAndLog("----------------------------------------------------");\r
784 int i,j = 0;\r
785 for (; j < 64; ++j){\r
786 \r
787 for (i = 0; i < 32; ++i)\r
788 bits[i]=DemodBuffer[j+i];\r
789 \r
790 blockData = PackBits(0, 32, bits);\r
791 \r
be2d41b7 792 PrintAndLog(" %02d | 0x%08X | %s",j , blockData, sprint_bin(bits,32)); \r
13d77ef9 793 }\r
794 return 0;\r
795}\r
796\r
be2d41b7 797int printConfiguration( t55xx_conf_block_t b){\r
f6650679 798 PrintAndLog("Chip Type : %s", (b.Q5) ? "T5555(Q5)" : "T55x7");\r
13d77ef9 799 PrintAndLog("Modulation : %s", GetSelectedModulationStr(b.modulation) );\r
800 PrintAndLog("Bit Rate : %s", GetBitRateStr(b.bitrate) );\r
801 PrintAndLog("Inverted : %s", (b.inverted) ? "Yes" : "No" );\r
802 PrintAndLog("Offset : %d", b.offset);\r
803 PrintAndLog("Block0 : 0x%08X", b.block0);\r
804 PrintAndLog("");\r
be2d41b7 805 return 0;\r
13d77ef9 806}\r
807\r
be2d41b7 808int CmdT55xxWakeUp(const char *Cmd) {\r
809 uint32_t password = 0;\r
810 uint8_t cmdp = 0;\r
811 bool errors = true;\r
812 while(param_getchar(Cmd, cmdp) != 0x00) {\r
813 switch(param_getchar(Cmd, cmdp)) {\r
814 case 'h':\r
815 case 'H':\r
816 return usage_t55xx_wakup();\r
817 case 'p':\r
818 case 'P':\r
819 password = param_get32ex(Cmd, cmdp+1, 0xFFFFFFFF, 16);\r
820 cmdp += 2;\r
821 errors = false;\r
822 break;\r
823 default:\r
824 PrintAndLog("Unknown parameter '%c'", param_getchar(Cmd, cmdp));\r
825 errors = true;\r
826 break;\r
827 }\r
13d77ef9 828 }\r
be2d41b7 829 if (errors) return usage_t55xx_wakup();\r
830\r
831 UsbCommand c = {CMD_T55XX_WAKEUP, {password, 0, 0}};\r
832 clearCommandBuffer();\r
833 SendCommand(&c);\r
834 PrintAndLog("Wake up command sent. Try read now");\r
835 return 0;\r
836}\r
837\r
838int CmdT55xxWriteBlock(const char *Cmd) {\r
839 uint8_t block = 0xFF; //default to invalid block\r
709665b5 840 uint32_t data = 0; //default to blank Block \r
841 uint32_t password = 0; //default to blank Block 7\r
be2d41b7 842 bool usepwd = false;\r
843 bool page1 = false; \r
844 bool gotdata = false;\r
845 bool errors = false;\r
846 uint8_t cmdp = 0;\r
847 while(param_getchar(Cmd, cmdp) != 0x00 && !errors) {\r
848 switch(param_getchar(Cmd, cmdp)) {\r
849 case 'h':\r
850 case 'H':\r
851 return usage_t55xx_write();\r
852 case 'b':\r
853 case 'B':\r
854 errors |= param_getdec(Cmd, cmdp+1, &block);\r
855 cmdp += 2;\r
856 break;\r
857 case 'd':\r
858 case 'D':\r
859 data = param_get32ex(Cmd, cmdp+1, 0, 16);\r
860 gotdata = true;\r
861 cmdp += 2;\r
862 break;\r
863 case 'p':\r
864 case 'P':\r
865 password = param_get32ex(Cmd, cmdp+1, 0, 16);\r
866 usepwd = true;\r
867 cmdp += 2;\r
868 break;\r
869 case '1':\r
870 page1 = true;\r
871 cmdp++;\r
872 break;\r
873 default:\r
874 PrintAndLog("Unknown parameter '%c'", param_getchar(Cmd, cmdp));\r
875 errors = true;\r
876 break;\r
877 }\r
13d77ef9 878 }\r
be2d41b7 879 if (errors || !gotdata) return usage_t55xx_write();\r
13d77ef9 880\r
881 if (block > 7) {\r
882 PrintAndLog("Block number must be between 0 and 7");\r
be2d41b7 883 return 0;\r
13d77ef9 884 }\r
885 \r
886 UsbCommand c = {CMD_T55XX_WRITE_BLOCK, {data, block, 0}};\r
976627d5 887 UsbCommand resp;\r
be2d41b7 888 c.d.asBytes[0] = (page1) ? 0x2 : 0; \r
13d77ef9 889\r
709665b5 890 char pwdStr[16] = {0};\r
891 snprintf(pwdStr, sizeof(pwdStr), "pwd: 0x%08X", password);\r
892\r
893 PrintAndLog("Writing page %d block: %02d data: 0x%08X %s", page1, block, data, (usepwd) ? pwdStr : "" );\r
13d77ef9 894\r
895 //Password mode\r
be2d41b7 896 if (usepwd) {\r
13d77ef9 897 c.arg[2] = password;\r
be2d41b7 898 c.d.asBytes[0] |= 0x1; \r
13d77ef9 899 }\r
40c5f342 900 clearCommandBuffer();\r
13d77ef9 901 SendCommand(&c);\r
976627d5
MHS
902 if (!WaitForResponseTimeout(CMD_ACK, &resp, 1000)){\r
903 PrintAndLog("Error occurred, device did not ACK write operation. (May be due to old firmware)");\r
be2d41b7 904 return 0;\r
976627d5 905 }\r
be2d41b7 906 return 1;\r
54a942b0 907}\r
908\r
be2d41b7 909int CmdT55xxReadTrace(const char *Cmd) {\r
13d77ef9 910 char cmdp = param_getchar(Cmd, 0);\r
be2d41b7 911 bool pwdmode = false;\r
912 uint32_t password = 0;\r
13d77ef9 913 if (strlen(Cmd) > 1 || cmdp == 'h' || cmdp == 'H') \r
914 return usage_t55xx_trace();\r
915\r
916 if (strlen(Cmd)==0)\r
709665b5 917 if ( !AquireData( T55x7_PAGE1, REGULAR_READ_MODE_BLOCK, pwdmode, password ) )\r
be2d41b7 918 return 0;\r
13d77ef9 919 \r
be2d41b7 920 if (!DecodeT55xxBlock()) return 0;\r
921\r
922 if ( !DemodBufferLen) return 0;\r
54a942b0 923\r
13d77ef9 924 RepaintGraphWindow();\r
925 uint8_t repeat = 0;\r
926 if (config.offset > 5) \r
927 repeat = 32;\r
928 uint8_t si = config.offset+repeat;\r
be2d41b7 929 uint32_t bl1 = PackBits(si, 32, DemodBuffer);\r
930 uint32_t bl2 = PackBits(si+32, 32, DemodBuffer);\r
13d77ef9 931 \r
224ce36e 932 uint32_t acl = PackBits(si, 8, DemodBuffer); si += 8;\r
933 uint32_t mfc = PackBits(si, 8, DemodBuffer); si += 8;\r
934 uint32_t cid = PackBits(si, 5, DemodBuffer); si += 5;\r
935 uint32_t icr = PackBits(si, 3, DemodBuffer); si += 3;\r
936 uint32_t year = PackBits(si, 4, DemodBuffer); si += 4;\r
937 uint32_t quarter = PackBits(si, 2, DemodBuffer); si += 2;\r
938 uint32_t lotid = PackBits(si, 14, DemodBuffer); si += 14;\r
939 uint32_t wafer = PackBits(si, 5, DemodBuffer); si += 5;\r
13d77ef9 940 uint32_t dw = PackBits(si, 15, DemodBuffer); \r
941 \r
224ce36e 942 time_t t = time(NULL);\r
943 struct tm tm = *localtime(&t);\r
944 if ( year > tm.tm_year-110)\r
945 year += 2000;\r
946 else\r
947 year += 2010;\r
948\r
f6650679 949 if (config.Q5) PrintAndLog("*** Warning *** Info read off a Q5 will not work as expected");\r
224ce36e 950 if ( acl != 0xE0 ) {\r
951 PrintAndLog("The modulation is most likely wrong since the ACL is not 0xE0. ");\r
be2d41b7 952 return 0;\r
224ce36e 953 }\r
13d77ef9 954 PrintAndLog("");\r
955 PrintAndLog("-- T55xx Trace Information ----------------------------------");\r
956 PrintAndLog("-------------------------------------------------------------");\r
957 PrintAndLog(" ACL Allocation class (ISO/IEC 15963-1) : 0x%02X (%d)", acl, acl);\r
958 PrintAndLog(" MFC Manufacturer ID (ISO/IEC 7816-6) : 0x%02X (%d) - %s", mfc, mfc, getTagInfo(mfc));\r
959 PrintAndLog(" CID : 0x%02X (%d) - %s", cid, cid, GetModelStrFromCID(cid));\r
960 PrintAndLog(" ICR IC Revision : %d",icr );\r
961 PrintAndLog(" Manufactured");\r
cc15a118 962 PrintAndLog(" Year/Quarter : %d/%d",year, quarter);\r
13d77ef9 963 PrintAndLog(" Lot ID : %d", lotid );\r
964 PrintAndLog(" Wafer number : %d", wafer);\r
965 PrintAndLog(" Die Number : %d", dw);\r
966 PrintAndLog("-------------------------------------------------------------");\r
967 PrintAndLog(" Raw Data - Page 1");\r
be2d41b7 968 PrintAndLog(" Block 1 : 0x%08X %s", bl1, sprint_bin(DemodBuffer+config.offset+repeat,32) );\r
969 PrintAndLog(" Block 2 : 0x%08X %s", bl2, sprint_bin(DemodBuffer+config.offset+repeat+32,32) );\r
13d77ef9 970 PrintAndLog("-------------------------------------------------------------");\r
54a942b0 971\r
13d77ef9 972 /*\r
973 TRACE - BLOCK O\r
974 Bits Definition HEX\r
975 1-8 ACL Allocation class (ISO/IEC 15963-1) 0xE0 \r
976 9-16 MFC Manufacturer ID (ISO/IEC 7816-6) 0x15 Atmel Corporation\r
977 17-21 CID 0x1 = Atmel ATA5577M1 0x2 = Atmel ATA5577M2 \r
978 22-24 ICR IC revision\r
979 25-28 YEAR (BCD encoded) 9 (= 2009)\r
980 29-30 QUARTER 1,2,3,4 \r
981 31-32 LOT ID\r
982 \r
983 TRACE - BLOCK 1\r
984 1-12 LOT ID \r
985 13-17 Wafer number\r
986 18-32 DW, die number sequential\r
987 */\r
988 \r
54a942b0 989 return 0;\r
990}\r
991\r
13d77ef9 992int CmdT55xxInfo(const char *Cmd){\r
993 /*\r
994 Page 0 Block 0 Configuration data.\r
995 Normal mode\r
996 Extended mode\r
997 */\r
be2d41b7 998 bool pwdmode = false;\r
999 uint32_t password = 0;\r
13d77ef9 1000 char cmdp = param_getchar(Cmd, 0);\r
1001\r
1002 if (strlen(Cmd) > 1 || cmdp == 'h' || cmdp == 'H')\r
1003 return usage_t55xx_info();\r
1004 \r
1005 if (strlen(Cmd)==0)\r
709665b5 1006 if ( !AquireData( T55x7_PAGE0, T55x7_CONFIGURATION_BLOCK, pwdmode, password ) )\r
be2d41b7 1007 return 1;\r
fef74fdc 1008\r
13d77ef9 1009 if (!DecodeT55xxBlock()) return 1;\r
1010\r
fef74fdc 1011 if ( DemodBufferLen < 32) return 1;\r
13d77ef9 1012\r
1013 uint8_t si = config.offset;\r
1014 uint32_t bl0 = PackBits(si, 32, DemodBuffer);\r
1015 \r
1016 uint32_t safer = PackBits(si, 4, DemodBuffer); si += 4; \r
1017 uint32_t resv = PackBits(si, 7, DemodBuffer); si += 7;\r
1018 uint32_t dbr = PackBits(si, 3, DemodBuffer); si += 3;\r
1019 uint32_t extend = PackBits(si, 1, DemodBuffer); si += 1;\r
1020 uint32_t datamod = PackBits(si, 5, DemodBuffer); si += 5;\r
1021 uint32_t pskcf = PackBits(si, 2, DemodBuffer); si += 2;\r
1022 uint32_t aor = PackBits(si, 1, DemodBuffer); si += 1; \r
1023 uint32_t otp = PackBits(si, 1, DemodBuffer); si += 1; \r
1024 uint32_t maxblk = PackBits(si, 3, DemodBuffer); si += 3;\r
1025 uint32_t pwd = PackBits(si, 1, DemodBuffer); si += 1; \r
1026 uint32_t sst = PackBits(si, 1, DemodBuffer); si += 1; \r
1027 uint32_t fw = PackBits(si, 1, DemodBuffer); si += 1;\r
1028 uint32_t inv = PackBits(si, 1, DemodBuffer); si += 1; \r
1029 uint32_t por = PackBits(si, 1, DemodBuffer); si += 1;\r
db829602 1030 if (config.Q5) PrintAndLog("*** Warning *** Config Info read off a Q5 will not display as expected");\r
13d77ef9 1031 PrintAndLog("");\r
1032 PrintAndLog("-- T55xx Configuration & Tag Information --------------------");\r
1033 PrintAndLog("-------------------------------------------------------------");\r
1034 PrintAndLog(" Safer key : %s", GetSaferStr(safer));\r
1035 PrintAndLog(" reserved : %d", resv);\r
1036 PrintAndLog(" Data bit rate : %s", GetBitRateStr(dbr));\r
1037 PrintAndLog(" eXtended mode : %s", (extend) ? "Yes - Warning":"No");\r
1038 PrintAndLog(" Modulation : %s", GetModulationStr(datamod));\r
1039 PrintAndLog(" PSK clock frequency : %d", pskcf);\r
1040 PrintAndLog(" AOR - Answer on Request : %s", (aor) ? "Yes":"No");\r
1041 PrintAndLog(" OTP - One Time Pad : %s", (otp) ? "Yes - Warning":"No" );\r
1042 PrintAndLog(" Max block : %d", maxblk);\r
1043 PrintAndLog(" Password mode : %s", (pwd) ? "Yes":"No");\r
1044 PrintAndLog(" Sequence Start Terminator : %s", (sst) ? "Yes":"No");\r
1045 PrintAndLog(" Fast Write : %s", (fw) ? "Yes":"No");\r
1046 PrintAndLog(" Inverse data : %s", (inv) ? "Yes":"No");\r
1047 PrintAndLog(" POR-Delay : %s", (por) ? "Yes":"No");\r
1048 PrintAndLog("-------------------------------------------------------------");\r
1049 PrintAndLog(" Raw Data - Page 0");\r
1050 PrintAndLog(" Block 0 : 0x%08X %s", bl0, sprint_bin(DemodBuffer+config.offset,32) );\r
1051 PrintAndLog("-------------------------------------------------------------");\r
1052 \r
1053 return 0;\r
1054}\r
1055\r
1056int CmdT55xxDump(const char *Cmd){\r
1057\r
be2d41b7 1058 uint32_t password = 0;\r
13d77ef9 1059 char cmdp = param_getchar(Cmd, 0);\r
be2d41b7 1060 bool override = false;\r
1061 if ( cmdp == 'h' || cmdp == 'H') return usage_t55xx_dump();\r
1062\r
1063 bool usepwd = ( strlen(Cmd) > 0); \r
1064 if ( usepwd ){\r
1065 password = param_get32ex(Cmd, 0, 0, 16);\r
1066 if (param_getchar(Cmd, 1) =='o' )\r
1067 override = true;\r
13d77ef9 1068 }\r
1069 \r
709665b5 1070 printT5xxHeader(0);\r
1071 for ( uint8_t i = 0; i <8; ++i)\r
be2d41b7 1072 T55xxReadBlock(i, 0, usepwd, override, password);\r
709665b5 1073\r
1074 printT5xxHeader(1);\r
1075 for ( uint8_t i = 0; i<4; i++)\r
be2d41b7 1076 T55xxReadBlock(i, 1, usepwd, override, password); \r
709665b5 1077\r
be2d41b7 1078 return 1;\r
13d77ef9 1079}\r
1080\r
be2d41b7 1081int AquireData( uint8_t page, uint8_t block, bool pwdmode, uint32_t password ){\r
709665b5 1082 // arg0 bitmodes:\r
1083 // bit0 = pwdmode\r
1084 // bit1 = page to read from\r
be2d41b7 1085 uint8_t arg0 = (page<<1) | pwdmode;\r
1086 UsbCommand c = {CMD_T55XX_READ_BLOCK, {arg0, block, password}};\r
13d77ef9 1087\r
40c5f342 1088 clearCommandBuffer();\r
13d77ef9 1089 SendCommand(&c);\r
1090 if ( !WaitForResponseTimeout(CMD_ACK,NULL,2500) ) {\r
1091 PrintAndLog("command execution time out");\r
be2d41b7 1092 return 0;\r
13d77ef9 1093 }\r
1094\r
1095 uint8_t got[12000];\r
1096 GetFromBigBuf(got,sizeof(got),0);\r
1097 WaitForResponse(CMD_ACK,NULL);\r
be2d41b7 1098 setGraphBuf(got, sizeof(got));\r
1099 return 1;\r
13d77ef9 1100}\r
1101\r
1102char * GetBitRateStr(uint32_t id){\r
fef74fdc 1103 static char buf[25];\r
1104\r
13d77ef9 1105 char *retStr = buf;\r
1106 switch (id){\r
1107 case 0: \r
9795e535 1108 snprintf(retStr,sizeof(buf),"%d - RF/8",id);\r
13d77ef9 1109 break;\r
1110 case 1:\r
9795e535 1111 snprintf(retStr,sizeof(buf),"%d - RF/16",id);\r
13d77ef9 1112 break;\r
1113 case 2: \r
9795e535 1114 snprintf(retStr,sizeof(buf),"%d - RF/32",id);\r
13d77ef9 1115 break;\r
1116 case 3:\r
9795e535 1117 snprintf(retStr,sizeof(buf),"%d - RF/40",id);\r
13d77ef9 1118 break;\r
1119 case 4:\r
9795e535 1120 snprintf(retStr,sizeof(buf),"%d - RF/50",id);\r
13d77ef9 1121 break;\r
1122 case 5:\r
9795e535 1123 snprintf(retStr,sizeof(buf),"%d - RF/64",id);\r
13d77ef9 1124 break;\r
1125 case 6:\r
9795e535 1126 snprintf(retStr,sizeof(buf),"%d - RF/100",id);\r
13d77ef9 1127 break;\r
1128 case 7:\r
9795e535 1129 snprintf(retStr,sizeof(buf),"%d - RF/128",id);\r
13d77ef9 1130 break;\r
1131 default:\r
9795e535 1132 snprintf(retStr,sizeof(buf),"%d - (Unknown)",id);\r
13d77ef9 1133 break;\r
1134 }\r
1135\r
1136 return buf;\r
1137}\r
1138\r
1139char * GetSaferStr(uint32_t id){\r
1140 static char buf[40];\r
1141 char *retStr = buf;\r
1142 \r
9795e535 1143 snprintf(retStr,sizeof(buf),"%d",id);\r
13d77ef9 1144 if (id == 6) {\r
9795e535 1145 snprintf(retStr,sizeof(buf),"%d - passwd",id);\r
13d77ef9 1146 }\r
1147 if (id == 9 ){\r
9795e535 1148 snprintf(retStr,sizeof(buf),"%d - testmode",id);\r
13d77ef9 1149 }\r
1150 \r
1151 return buf;\r
1152}\r
9795e535 1153\r
13d77ef9 1154char * GetModulationStr( uint32_t id){\r
2767fc02 1155 static char buf[60];\r
13d77ef9 1156 char *retStr = buf;\r
1157 \r
1158 switch (id){\r
1159 case 0: \r
9795e535 1160 snprintf(retStr,sizeof(buf),"%d - DIRECT (ASK/NRZ)",id);\r
13d77ef9 1161 break;\r
1162 case 1:\r
9795e535 1163 snprintf(retStr,sizeof(buf),"%d - PSK 1 phase change when input changes",id);\r
13d77ef9 1164 break;\r
1165 case 2: \r
9795e535 1166 snprintf(retStr,sizeof(buf),"%d - PSK 2 phase change on bitclk if input high",id);\r
13d77ef9 1167 break;\r
1168 case 3:\r
9795e535 1169 snprintf(retStr,sizeof(buf),"%d - PSK 3 phase change on rising edge of input",id);\r
13d77ef9 1170 break;\r
1171 case 4:\r
9795e535 1172 snprintf(retStr,sizeof(buf),"%d - FSK 1 RF/8 RF/5",id);\r
13d77ef9 1173 break;\r
1174 case 5:\r
9795e535 1175 snprintf(retStr,sizeof(buf),"%d - FSK 2 RF/8 RF/10",id);\r
13d77ef9 1176 break;\r
1177 case 6:\r
9795e535 1178 snprintf(retStr,sizeof(buf),"%d - FSK 1a RF/5 RF/8",id);\r
13d77ef9 1179 break;\r
1180 case 7:\r
9795e535 1181 snprintf(retStr,sizeof(buf),"%d - FSK 2a RF/10 RF/8",id);\r
13d77ef9 1182 break;\r
1183 case 8:\r
cc15a118 1184 snprintf(retStr,sizeof(buf),"%d - Manchester",id);\r
13d77ef9 1185 break;\r
1186 case 16:\r
9795e535 1187 snprintf(retStr,sizeof(buf),"%d - Biphase",id);\r
13d77ef9 1188 break;\r
1189 case 0x18:\r
9795e535 1190 snprintf(retStr,sizeof(buf),"%d - Biphase a - AKA Conditional Dephase Encoding(CDP)",id);\r
13d77ef9 1191 break;\r
1192 case 17:\r
9795e535 1193 snprintf(retStr,sizeof(buf),"%d - Reserved",id);\r
13d77ef9 1194 break;\r
1195 default:\r
9795e535 1196 snprintf(retStr,sizeof(buf),"0x%02X (Unknown)",id);\r
13d77ef9 1197 break;\r
1198 }\r
1199 return buf;\r
1200}\r
1201\r
1202char * GetModelStrFromCID(uint32_t cid){\r
1203 \r
1204 static char buf[10];\r
1205 char *retStr = buf;\r
1206 \r
224ce36e 1207 if (cid == 1) snprintf(retStr, sizeof(buf),"ATA5577M1");\r
1208 if (cid == 2) snprintf(retStr, sizeof(buf),"ATA5577M2"); \r
13d77ef9 1209 return buf;\r
1210}\r
1211\r
1212char * GetSelectedModulationStr( uint8_t id){\r
1213\r
9795e535 1214 static char buf[20];\r
13d77ef9 1215 char *retStr = buf;\r
1216\r
1217 switch (id){\r
1218 case DEMOD_FSK:\r
9795e535 1219 snprintf(retStr,sizeof(buf),"FSK");\r
13d77ef9 1220 break;\r
1221 case DEMOD_FSK1:\r
9795e535 1222 snprintf(retStr,sizeof(buf),"FSK1");\r
13d77ef9 1223 break;\r
1224 case DEMOD_FSK1a:\r
9795e535 1225 snprintf(retStr,sizeof(buf),"FSK1a");\r
13d77ef9 1226 break;\r
1227 case DEMOD_FSK2:\r
9795e535 1228 snprintf(retStr,sizeof(buf),"FSK2");\r
13d77ef9 1229 break;\r
1230 case DEMOD_FSK2a:\r
9795e535 1231 snprintf(retStr,sizeof(buf),"FSK2a");\r
13d77ef9 1232 break;\r
1233 case DEMOD_ASK: \r
9795e535 1234 snprintf(retStr,sizeof(buf),"ASK");\r
13d77ef9 1235 break;\r
1236 case DEMOD_NRZ:\r
9795e535 1237 snprintf(retStr,sizeof(buf),"DIRECT/NRZ");\r
13d77ef9 1238 break;\r
1239 case DEMOD_PSK1:\r
9795e535 1240 snprintf(retStr,sizeof(buf),"PSK1");\r
13d77ef9 1241 break;\r
1242 case DEMOD_PSK2:\r
9795e535 1243 snprintf(retStr,sizeof(buf),"PSK2");\r
13d77ef9 1244 break;\r
1245 case DEMOD_PSK3:\r
9795e535 1246 snprintf(retStr,sizeof(buf),"PSK3");\r
13d77ef9 1247 break;\r
1248 case DEMOD_BI:\r
9795e535 1249 snprintf(retStr,sizeof(buf),"BIPHASE");\r
13d77ef9 1250 break;\r
1251 case DEMOD_BIa:\r
9795e535 1252 snprintf(retStr,sizeof(buf),"BIPHASEa - (CDP)");\r
13d77ef9 1253 break;\r
1254 default:\r
9795e535 1255 snprintf(retStr,sizeof(buf),"(Unknown)");\r
13d77ef9 1256 break;\r
1257 }\r
1258 return buf;\r
1259}\r
1260\r
1261uint32_t PackBits(uint8_t start, uint8_t len, uint8_t* bits){\r
1262 \r
1263 int i = start;\r
1264 int j = len-1;\r
1265\r
1266 if (len > 32) return 0;\r
1267\r
1268 uint32_t tmp = 0;\r
1269 for (; j >= 0; --j, ++i)\r
1270 tmp |= bits[i] << j;\r
1271\r
1272 return tmp;\r
1273}\r
1274\r
66837a03 1275int CmdResetRead(const char *Cmd) {\r
1276 UsbCommand c = {CMD_T55XX_RESET_READ, {0,0,0}};\r
1277\r
1278 clearCommandBuffer();\r
1279 SendCommand(&c);\r
1280 if ( !WaitForResponseTimeout(CMD_ACK,NULL,2500) ) {\r
1281 PrintAndLog("command execution time out");\r
1282 return 0;\r
1283 }\r
1284\r
9f669cb2 1285 uint8_t got[BIGBUF_SIZE-1];\r
66837a03 1286 GetFromBigBuf(got,sizeof(got),0);\r
1287 WaitForResponse(CMD_ACK,NULL);\r
1288 setGraphBuf(got, sizeof(got));\r
1289 return 1;\r
1290}\r
1291\r
f6650679 1292int CmdT55xxWipe(const char *Cmd) {\r
1293 char writeData[20] = {0};\r
1294 char *ptrData = writeData;\r
709665b5 1295\r
f6650679 1296 PrintAndLog("\nBeginning Wipe of a T55xx tag (assuming the tag is not password protected)\n");\r
709665b5 1297\r
f6650679 1298 //try with the default password to reset block 0 (with a pwd should work even if pwd bit not set)\r
709665b5 1299 snprintf(ptrData,sizeof(writeData),"b 0 d 00088040 p 0");\r
1300\r
1301 if (!CmdT55xxWriteBlock(ptrData))\r
1302 PrintAndLog("Error writing blk 0");\r
1303\r
1304 for (uint8_t blk = 1; blk<8; blk++) {\r
f6650679 1305 snprintf(ptrData,sizeof(writeData),"b %d d 0", blk);\r
709665b5 1306 if (!CmdT55xxWriteBlock(ptrData))\r
f6650679 1307 PrintAndLog("Error writing blk %d", blk);\r
709665b5 1308\r
1309 memset(writeData, sizeof(writeData), 0x00);\r
f6650679 1310 }\r
1311 return 0;\r
1312}\r
1313\r
506672c4 1314int CmdT55xxBruteForce(const char *Cmd) {\r
1315\r
1316 // load a default pwd file.\r
1317 char buf[9];\r
1318 char filename[FILE_PATH_SIZE]={0};\r
1319 int keycnt = 0;\r
1320 uint8_t stKeyBlock = 20;\r
1321 uint8_t *keyBlock = NULL, *p;\r
1322 keyBlock = calloc(stKeyBlock, 6);\r
1323 if (keyBlock == NULL) return 1;\r
1324\r
1325 uint32_t start_password = 0x00000000; //start password\r
1326 uint32_t end_password = 0xFFFFFFFF; //end password\r
1327 bool found = false;\r
1328\r
1329 char cmdp = param_getchar(Cmd, 0);\r
1330 if (cmdp == 'h' || cmdp == 'H') return usage_t55xx_bruteforce();\r
1331\r
1332 if (cmdp == 'i' || cmdp == 'I') {\r
1333\r
1334 int len = strlen(Cmd+2);\r
1335 if (len > FILE_PATH_SIZE) len = FILE_PATH_SIZE;\r
1336 memcpy(filename, Cmd+2, len);\r
1337\r
1338 FILE * f = fopen( filename , "r");\r
1339\r
1340 if ( !f ) {\r
1341 PrintAndLog("File: %s: not found or locked.", filename);\r
1342 free(keyBlock);\r
1343 return 1;\r
1344 }\r
1345\r
1346 while( fgets(buf, sizeof(buf), f) ){\r
1347 if (strlen(buf) < 8 || buf[7] == '\n') continue;\r
1348\r
1349 while (fgetc(f) != '\n' && !feof(f)) ; //goto next line\r
1350\r
1351 //The line start with # is comment, skip\r
1352 if( buf[0]=='#' ) continue;\r
1353\r
1354 if (!isxdigit(buf[0])){\r
1355 PrintAndLog("File content error. '%s' must include 8 HEX symbols", buf);\r
1356 continue;\r
1357 }\r
1358 \r
1359 buf[8] = 0;\r
1360\r
1361 if ( stKeyBlock - keycnt < 2) {\r
1362 p = realloc(keyBlock, 6*(stKeyBlock+=10));\r
1363 if (!p) {\r
1364 PrintAndLog("Cannot allocate memory for defaultKeys");\r
1365 free(keyBlock);\r
1366 return 2;\r
1367 }\r
1368 keyBlock = p;\r
1369 }\r
1370 memset(keyBlock + 4 * keycnt, 0, 4);\r
1371 num_to_bytes(strtoll(buf, NULL, 16), 4, keyBlock + 4*keycnt);\r
1372 PrintAndLog("chk custom pwd[%2d] %08X", keycnt, bytes_to_num(keyBlock + 4*keycnt, 4));\r
1373 keycnt++;\r
1374 memset(buf, 0, sizeof(buf));\r
1375 }\r
1376 fclose(f);\r
1377 \r
1378 if (keycnt == 0) {\r
1379 PrintAndLog("No keys found in file");\r
1380 return 1;\r
1381 }\r
1382 PrintAndLog("Loaded %d keys", keycnt);\r
1383 \r
1384 // loop\r
1385 uint64_t testpwd = 0x00;\r
1386 for (uint16_t c = 0; c < keycnt; ++c ) {\r
1387\r
1388 if (ukbhit()) {\r
1389 getchar();\r
1390 printf("\naborted via keyboard!\n");\r
1391 return 0;\r
1392 }\r
1393\r
1394 testpwd = bytes_to_num(keyBlock + 4*c, 4);\r
1395\r
1396 PrintAndLog("Testing %08X", testpwd);\r
1397\r
1398 if ( !AquireData(T55x7_PAGE0, T55x7_CONFIGURATION_BLOCK, TRUE, testpwd)) {\r
1399 PrintAndLog("Aquireing data from device failed. Quitting");\r
1400 return 0;\r
1401 }\r
1402\r
1403 found = tryDetectModulation();\r
1404\r
1405 if ( found ) {\r
1406 PrintAndLog("Found valid password: [%08X]", testpwd);\r
1407 return 0;\r
1408 }\r
1409 }\r
1410 PrintAndLog("Password NOT found.");\r
1411 return 0;\r
1412 }\r
1413\r
1414 // Try to read Block 7, first :)\r
1415\r
1416 // incremental pwd range search\r
1417 start_password = param_get32ex(Cmd, 0, 0, 16);\r
1418 end_password = param_get32ex(Cmd, 1, 0, 16);\r
1419 \r
1420 if ( start_password >= end_password ) return usage_t55xx_bruteforce();\r
1421\r
1422 PrintAndLog("Search password range [%08X -> %08X]", start_password, end_password);\r
1423\r
1424 uint32_t i = start_password;\r
1425\r
1426 while ((!found) && (i <= end_password)){\r
1427\r
1428 printf(".");\r
1429 fflush(stdout);\r
1430 if (ukbhit()) {\r
1431 getchar();\r
1432 printf("\naborted via keyboard!\n");\r
1433 return 0;\r
1434 }\r
1435\r
1436 if (!AquireData(T55x7_PAGE0, T55x7_CONFIGURATION_BLOCK, TRUE, i)) {\r
1437 PrintAndLog("Aquireing data from device failed. Quitting");\r
1438 return 0;\r
1439 }\r
1440 found = tryDetectModulation();\r
1441 \r
1442 if (found) break;\r
1443 i++;\r
1444 }\r
1445\r
1446 PrintAndLog("");\r
1447\r
1448 if (found)\r
1449 PrintAndLog("Found valid password: [%08x]", i);\r
1450 else\r
1451 PrintAndLog("Password NOT found. Last tried: [%08x]", --i);\r
1452 return 0;\r
1453}\r
1454\r
709665b5 1455static command_t CommandTable[] = {\r
506672c4 1456 {"help", CmdHelp, 1, "This help"},\r
1457 {"bruteforce",CmdT55xxBruteForce,0, "<start password> <end password> [i <*.dic>] Simple bruteforce attack to find password"},\r
1458 {"config", CmdT55xxSetConfig, 1, "Set/Get T55XX configuration (modulation, inverted, offset, rate)"},\r
1459 {"detect", CmdT55xxDetect, 1, "[1] Try detecting the tag modulation from reading the configuration block."},\r
1460 {"read", CmdT55xxReadBlock, 0, "b <block> p [password] [o] [1] -- Read T55xx block data. Optional [p password], [override], [page1]"},\r
1461 {"resetread", CmdResetRead, 0, "Send Reset Cmd then lf read the stream to attempt to identify the start of it (needs a demod and/or plot after)"},\r
1462 {"write", CmdT55xxWriteBlock,0, "b <block> d <data> p [password] [1] -- Write T55xx block data. Optional [p password], [page1]"},\r
1463 {"trace", CmdT55xxReadTrace, 1, "[1] Show T55x7 traceability data (page 1/ blk 0-1)"},\r
1464 {"info", CmdT55xxInfo, 1, "[1] Show T55x7 configuration data (page 0/ blk 0)"},\r
1465 {"dump", CmdT55xxDump, 0, "[password] [o] Dump T55xx card block 0-7. Optional [password], [override]"},\r
1466 {"special", special, 0, "Show block changes with 64 different offsets"},\r
1467 {"wakeup", CmdT55xxWakeUp, 0, "Send AOR wakeup command"},\r
1468 {"wipe", CmdT55xxWipe, 0, "Wipe a T55xx tag and set defaults (will destroy any data on tag)"},\r
54a942b0 1469 {NULL, NULL, 0, NULL}\r
1470};\r
1471\r
709665b5 1472int CmdLFT55XX(const char *Cmd) {\r
54a942b0 1473 CmdsParse(CommandTable, Cmd);\r
1474 return 0;\r
1475}\r
1476\r
709665b5 1477int CmdHelp(const char *Cmd) {\r
54a942b0 1478 CmdsHelp(CommandTable);\r
1479 return 0;\r
1480}\r
Impressum, Datenschutz