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