]> git.zerfleddert.de Git - proxmark3-svn/blame - client/cmdlft55xx.c
fix 'hf iclass sim':
[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
ad939de5 10#include "cmdlft55xx.h"\r
11\r
54a942b0 12#include <stdio.h>\r
13#include <string.h>\r
14#include <inttypes.h>\r
acf0582d 15#include <ctype.h>\r
16#include <time.h>\r
ad939de5 17#include "comms.h"\r
54a942b0 18#include "ui.h"\r
19#include "graph.h"\r
13d77ef9 20#include "cmdmain.h"\r
54a942b0 21#include "cmdparser.h"\r
22#include "cmddata.h"\r
23#include "cmdlf.h"\r
13d77ef9 24#include "util.h"\r
13d77ef9 25#include "lfdemod.h"\r
b97311b1 26#include "protocols.h"\r
1338d245 27#include "taginfo.h"\r
13d77ef9 28\r
709665b5 29#define T55x7_CONFIGURATION_BLOCK 0x00\r
30#define T55x7_PAGE0 0x00\r
31#define T55x7_PAGE1 0x01\r
3975d477 32//#define T55x7_PWD 0x00000010\r
be2d41b7 33#define REGULAR_READ_MODE_BLOCK 0xFF\r
13d77ef9 34\r
35// Default configuration\r
7cb8516c 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
d1869c33 54 PrintAndLog(" ST Set Sequence Terminator on");\r
13d77ef9 55 PrintAndLog("");\r
56 PrintAndLog("Examples:");\r
57 PrintAndLog(" lf t55xx config d FSK - FSK demodulation");\r
58 PrintAndLog(" lf t55xx config d FSK i 1 - FSK demodulation, inverse data");\r
59 PrintAndLog(" lf t55xx config d FSK i 1 o 3 - FSK demodulation, inverse data, offset=3,start from position 3 to decode data");\r
60 PrintAndLog("");\r
61 return 0;\r
62}\r
63int usage_t55xx_read(){\r
0c8200f1 64 PrintAndLog("Usage: lf t55xx read [b <block>] [p <password>] <override_safety> <page1>");\r
be2d41b7 65 PrintAndLog("Options:");\r
0c8200f1 66 PrintAndLog(" b <block> - block number to read. Between 0-7");\r
67 PrintAndLog(" p <password> - OPTIONAL password (8 hex characters)");\r
68 PrintAndLog(" o - OPTIONAL override safety check");\r
69 PrintAndLog(" 1 - OPTIONAL read Page 1 instead of Page 0");\r
6763dc17 70 PrintAndLog(" r <mode> - OPTIONAL downlink encoding '0' fixed bit length (default), '1' long leading reference");\r
6dd0ff30 71 PrintAndLog(" '2' leading zero, '3' 1 of 4 coding reference"); \r
f1b74c30 72 PrintAndLog(" ****WARNING****");\r
73 PrintAndLog(" Use of read with password on a tag not configured for a pwd");\r
74 PrintAndLog(" can damage the tag");\r
185e038c 75 PrintAndLog("");\r
13d77ef9 76 PrintAndLog("Examples:");\r
0c8200f1 77 PrintAndLog(" lf t55xx read b 0 - read data from block 0");\r
be2d41b7 78 PrintAndLog(" lf t55xx read b 0 p feedbeef - read data from block 0 password feedbeef");\r
79 PrintAndLog(" lf t55xx read b 0 p feedbeef o - read data from block 0 password feedbeef safety check");\r
13d77ef9 80 PrintAndLog("");\r
81 return 0;\r
82}\r
83int usage_t55xx_write(){\r
b97311b1 84 PrintAndLog("Usage: lf t55xx write [b <block>] [d <data>] [p <password>] [1] [t]");\r
be2d41b7 85 PrintAndLog("Options:");\r
0c8200f1 86 PrintAndLog(" b <block> - block number to write. Between 0-7");\r
87 PrintAndLog(" d <data> - 4 bytes of data to write (8 hex characters)");\r
88 PrintAndLog(" p <password> - OPTIONAL password 4bytes (8 hex characters)");\r
89 PrintAndLog(" 1 - OPTIONAL write Page 1 instead of Page 0");\r
b97311b1 90 PrintAndLog(" t - OPTIONAL test mode write - ****DANGER****"); \r
6763dc17 91 PrintAndLog(" r <mode> - OPTIONAL downlink encoding '0' fixed bit length (default), '1' long leading reference");\r
6dd0ff30 92 PrintAndLog(" '2' leading zero, '3' 1 of 4 coding reference"); \r
185e038c 93 PrintAndLog("");\r
13d77ef9 94 PrintAndLog("Examples:");\r
72c5877a 95 PrintAndLog(" lf t55xx write b 3 d 11223344 - write 11223344 to block 3");\r
96 PrintAndLog(" lf t55xx write b 3 d 11223344 p feedbeef - write 11223344 to block 3 password feedbeef");\r
13d77ef9 97 PrintAndLog("");\r
98 return 0;\r
99}\r
100int usage_t55xx_trace() {\r
101 PrintAndLog("Usage: lf t55xx trace [1]");\r
be2d41b7 102 PrintAndLog("Options:");\r
0c8200f1 103 PrintAndLog(" [graph buffer data] - if set, use Graphbuffer otherwise read data from tag.");\r
13d77ef9 104 PrintAndLog("");\r
105 PrintAndLog("Examples:");\r
106 PrintAndLog(" lf t55xx trace");\r
107 PrintAndLog(" lf t55xx trace 1");\r
108 PrintAndLog("");\r
109 return 0;\r
110}\r
111int usage_t55xx_info() {\r
112 PrintAndLog("Usage: lf t55xx info [1]");\r
be2d41b7 113 PrintAndLog("Options:");\r
0c8200f1 114 PrintAndLog(" [graph buffer data] - if set, use Graphbuffer otherwise read data from tag.");\r
13d77ef9 115 PrintAndLog("");\r
116 PrintAndLog("Examples:");\r
117 PrintAndLog(" lf t55xx info");\r
118 PrintAndLog(" lf t55xx info 1");\r
119 PrintAndLog("");\r
120 return 0;\r
121}\r
122int usage_t55xx_dump(){\r
be2d41b7 123 PrintAndLog("Usage: lf t55xx dump <password> [o]");\r
124 PrintAndLog("Options:");\r
0c8200f1 125 PrintAndLog(" <password> - OPTIONAL password 4bytes (8 hex symbols)");\r
126 PrintAndLog(" o - OPTIONAL override, force pwd read despite danger to card");\r
13d77ef9 127 PrintAndLog("");\r
128 PrintAndLog("Examples:");\r
129 PrintAndLog(" lf t55xx dump");\r
be2d41b7 130 PrintAndLog(" lf t55xx dump feedbeef o");\r
13d77ef9 131 PrintAndLog("");\r
132 return 0;\r
133}\r
134int usage_t55xx_detect(){\r
ab5ffe3b 135 PrintAndLog("Usage: lf t55xx detect [1] [p <password>]");\r
be2d41b7 136 PrintAndLog("Options:");\r
ab5ffe3b 137 PrintAndLog(" 1 - if set, use Graphbuffer otherwise read data from tag.");\r
138 PrintAndLog(" p <password> - OPTIONAL password (8 hex characters)");\r
6763dc17 139 PrintAndLog(" r <mode> - OPTIONAL downlink encoding '0' fixed bit length (default), '1' long leading reference");\r
6dd0ff30 140 PrintAndLog(" '2' leading zero, '3' 1 of 4 coding reference"); \r
13d77ef9 141 PrintAndLog("");\r
142 PrintAndLog("Examples:");\r
143 PrintAndLog(" lf t55xx detect");\r
144 PrintAndLog(" lf t55xx detect 1");\r
ab5ffe3b 145 PrintAndLog(" lf t55xx detect p 11223344");\r
13d77ef9 146 PrintAndLog("");\r
147 return 0;\r
148}\r
b97311b1 149int usage_t55xx_detectP1(){\r
605524b1 150 PrintAndLog("Command: Detect Page 1 of a t55xx chip");\r
151 PrintAndLog("Usage: lf t55xx p1detect [1] [p <password>]");\r
b97311b1 152 PrintAndLog("Options:");\r
153 PrintAndLog(" 1 - if set, use Graphbuffer otherwise read data from tag.");\r
154 PrintAndLog(" p <password> - OPTIONAL password (8 hex characters)");\r
155 PrintAndLog("");\r
156 PrintAndLog("Examples:");\r
605524b1 157 PrintAndLog(" lf t55xx p1detect");\r
158 PrintAndLog(" lf t55xx p1detect 1");\r
159 PrintAndLog(" lf t55xx p1detect p 11223344");\r
b97311b1 160 PrintAndLog("");\r
161 return 0;\r
162}\r
be2d41b7 163int usage_t55xx_wakup(){\r
b97311b1 164 PrintAndLog("Usage: lf t55xx wakeup [h] <password>");\r
be2d41b7 165 PrintAndLog("This commands send the Answer-On-Request command and leaves the readerfield ON afterwards.");\r
166 PrintAndLog("Options:");\r
167 PrintAndLog(" h - this help");\r
b97311b1 168 PrintAndLog(" <password> - [required] password 4bytes (8 hex symbols)");\r
be2d41b7 169 PrintAndLog("");\r
170 PrintAndLog("Examples:");\r
6763dc17 171 PrintAndLog(" lf t55xx wakeup 11223344 - send wakeup password");\r
be2d41b7 172 return 0;\r
173}\r
506672c4 174int usage_t55xx_bruteforce(){\r
51923aca 175 PrintAndLog("This command uses A) bruteforce to scan a number range");\r
176 PrintAndLog(" B) a dictionary attack");\r
506672c4 177 PrintAndLog("Usage: lf t55xx bruteforce <start password> <end password> [i <*.dic>]");\r
178 PrintAndLog(" password must be 4 bytes (8 hex symbols)");\r
179 PrintAndLog("Options:");\r
51923aca 180 PrintAndLog(" h - this help");\r
6763dc17 181 PrintAndLog(" r <mode> - OPTIONAL downlink encoding '0' fixed bit length (default)"); \r
182 PrintAndLog(" '1' long leading reference, '2' leading zero ");\r
183 PrintAndLog(" '3' 1 of 4 coding reference, '4' special - try all downlink modes");\r
51923aca 184 PrintAndLog(" <start_pwd> - 4 byte hex value to start pwd search at");\r
185 PrintAndLog(" <end_pwd> - 4 byte hex value to end pwd search at");\r
186 PrintAndLog(" i <*.dic> - loads a default keys dictionary file <*.dic>");\r
506672c4 187 PrintAndLog("");\r
188 PrintAndLog("Examples:");\r
6763dc17 189 PrintAndLog(" lf t55xx bruteforce [r 2] aaaaaaaa bbbbbbbb");\r
190 PrintAndLog(" lf t55xx bruteforce [r 2] i default_pwd.dic");\r
dd8e4513 191 PrintAndLog("");\r
192 return 0;\r
193}\r
5490c2d6 194int usage_t55xx_wipe(){\r
195 PrintAndLog("Usage: lf t55xx wipe [h] [Q5]");\r
196 PrintAndLog("This commands wipes a tag, fills blocks 1-7 with zeros and a default configuration block");\r
197 PrintAndLog("Options:");\r
198 PrintAndLog(" h - this help");\r
199 PrintAndLog(" Q5 - indicates to use the T5555 (Q5) default configuration block");\r
200 PrintAndLog("");\r
201 PrintAndLog("Examples:");\r
202 PrintAndLog(" lf t55xx wipe - wipes a t55x7 tag, config block 0x000880E0");\r
203 PrintAndLog(" lf t55xx wipe Q5 - wipes a t5555 Q5 tag, config block 0x6001F004");\r
204 return 0;\r
205}\r
206\r
54a942b0 207\r
208static int CmdHelp(const char *Cmd);\r
209\r
709665b5 210void printT5xxHeader(uint8_t page){\r
506672c4 211 PrintAndLog("Reading Page %d:", page);\r
709665b5 212 PrintAndLog("blk | hex data | binary");\r
213 PrintAndLog("----+----------+---------------------------------"); \r
214}\r
215\r
13d77ef9 216int CmdT55xxSetConfig(const char *Cmd) {\r
54a942b0 217\r
13d77ef9 218 uint8_t offset = 0;\r
b6a04aff 219 char modulation[6] = {0x00};\r
13d77ef9 220 char tmp = 0x00;\r
221 uint8_t bitRate = 0;\r
222 uint8_t rates[9] = {8,16,32,40,50,64,100,128,0};\r
8e99ec25 223 uint8_t cmdp = 0;\r
7cb8516c 224 bool errors = false;\r
13d77ef9 225 while(param_getchar(Cmd, cmdp) != 0x00 && !errors)\r
226 {\r
227 tmp = param_getchar(Cmd, cmdp);\r
228 switch(tmp)\r
229 {\r
230 case 'h':\r
231 case 'H':\r
232 return usage_t55xx_config();\r
233 case 'b':\r
234 errors |= param_getdec(Cmd, cmdp+1, &bitRate);\r
235 if ( !errors){\r
236 uint8_t i = 0;\r
237 for (; i < 9; i++){\r
238 if (rates[i]==bitRate) {\r
239 config.bitrate = i;\r
240 break;\r
241 }\r
242 }\r
7cb8516c 243 if (i==9) errors = true;\r
13d77ef9 244 }\r
245 cmdp+=2;\r
246 break;\r
247 case 'd':\r
874572d4 248 param_getstr(Cmd, cmdp+1, modulation, sizeof(modulation));\r
13d77ef9 249 cmdp += 2;\r
54a942b0 250\r
2767fc02 251 if ( strcmp(modulation, "FSK" ) == 0) {\r
13d77ef9 252 config.modulation = DEMOD_FSK;\r
2767fc02 253 } else if ( strcmp(modulation, "FSK1" ) == 0) {\r
13d77ef9 254 config.modulation = DEMOD_FSK1;\r
2767fc02 255 config.inverted=1;\r
256 } else if ( strcmp(modulation, "FSK1a" ) == 0) {\r
13d77ef9 257 config.modulation = DEMOD_FSK1a;\r
2767fc02 258 config.inverted=0;\r
259 } else if ( strcmp(modulation, "FSK2" ) == 0) {\r
13d77ef9 260 config.modulation = DEMOD_FSK2;\r
2767fc02 261 config.inverted=0;\r
262 } else if ( strcmp(modulation, "FSK2a" ) == 0) {\r
13d77ef9 263 config.modulation = DEMOD_FSK2a;\r
2767fc02 264 config.inverted=1;\r
265 } else if ( strcmp(modulation, "ASK" ) == 0) {\r
13d77ef9 266 config.modulation = DEMOD_ASK;\r
2767fc02 267 } else if ( strcmp(modulation, "NRZ" ) == 0) {\r
13d77ef9 268 config.modulation = DEMOD_NRZ;\r
2767fc02 269 } else if ( strcmp(modulation, "PSK1" ) == 0) {\r
13d77ef9 270 config.modulation = DEMOD_PSK1;\r
2767fc02 271 } else if ( strcmp(modulation, "PSK2" ) == 0) {\r
13d77ef9 272 config.modulation = DEMOD_PSK2;\r
2767fc02 273 } else if ( strcmp(modulation, "PSK3" ) == 0) {\r
13d77ef9 274 config.modulation = DEMOD_PSK3;\r
2767fc02 275 } else if ( strcmp(modulation, "BIa" ) == 0) {\r
13d77ef9 276 config.modulation = DEMOD_BIa;\r
2767fc02 277 config.inverted=1;\r
278 } else if ( strcmp(modulation, "BI" ) == 0) {\r
13d77ef9 279 config.modulation = DEMOD_BI;\r
2767fc02 280 config.inverted=0;\r
281 } else {\r
13d77ef9 282 PrintAndLog("Unknown modulation '%s'", modulation);\r
7cb8516c 283 errors = true;\r
13d77ef9 284 }\r
285 break;\r
286 case 'i':\r
287 config.inverted = param_getchar(Cmd,cmdp+1) == '1';\r
288 cmdp+=2;\r
289 break;\r
290 case 'o':\r
291 errors |= param_getdec(Cmd, cmdp+1, &offset);\r
292 if ( !errors )\r
293 config.offset = offset;\r
294 cmdp+=2;\r
295 break;\r
f6650679 296 case 'Q':\r
297 case 'q': \r
7cb8516c 298 config.Q5 = true;\r
f6650679 299 cmdp++;\r
300 break;\r
d1869c33 301 case 'S':\r
302 case 's': \r
7cb8516c 303 config.ST = true;\r
d1869c33 304 cmdp++;\r
305 break;\r
13d77ef9 306 default:\r
307 PrintAndLog("Unknown parameter '%c'", param_getchar(Cmd, cmdp));\r
7cb8516c 308 errors = true;\r
13d77ef9 309 break;\r
310 }\r
311 }\r
54a942b0 312\r
13d77ef9 313 // No args\r
4be71814 314 if (cmdp == 0) return printConfiguration( config);\r
be2d41b7 315\r
13d77ef9 316 //Validations\r
be2d41b7 317 if (errors) return usage_t55xx_config();\r
54a942b0 318\r
be2d41b7 319 config.block0 = 0;\r
4be71814 320 return printConfiguration ( config);\r
be2d41b7 321}\r
322\r
dd8e4513 323int T55xxReadBlock(uint8_t block, bool page1, bool usepwd, bool override, uint32_t password, uint8_t downlink_mode){\r
be2d41b7 324 //Password mode\r
325 if ( usepwd ) {\r
326 // try reading the config block and verify that PWD bit is set before doing this!\r
327 if ( !override ) {\r
dd8e4513 328 if ( !AquireData(T55x7_PAGE0, T55x7_CONFIGURATION_BLOCK, false, 0,downlink_mode ) ) return 0;\r
be2d41b7 329 if ( !tryDetectModulation() ) {\r
330 PrintAndLog("Safety Check: Could not detect if PWD bit is set in config block. Exits.");\r
331 return 0;\r
332 } else {\r
333 PrintAndLog("Safety Check: PWD bit is NOT set in config block. Reading without password..."); \r
334 usepwd = false;\r
335 page1 = false;\r
336 }\r
337 } else {\r
338 PrintAndLog("Safety Check Overriden - proceeding despite risk");\r
339 }\r
340 }\r
341\r
dd8e4513 342 if (!AquireData(page1, block, usepwd, password,downlink_mode) ) return 0;\r
be2d41b7 343 if (!DecodeT55xxBlock()) return 0;\r
344\r
345 char blk[10]={0};\r
346 sprintf(blk,"%d", block);\r
347 printT55xxBlock(blk); \r
348 return 1;\r
13d77ef9 349}\r
54a942b0 350\r
13d77ef9 351int CmdT55xxReadBlock(const char *Cmd) {\r
be2d41b7 352 uint8_t block = REGULAR_READ_MODE_BLOCK;\r
353 uint32_t password = 0; //default to blank Block 7\r
dd8e4513 354 uint8_t downlink_mode = 0;\r
355 \r
be2d41b7 356 bool usepwd = false;\r
357 bool override = false;\r
358 bool page1 = false;\r
8e99ec25 359 bool errors = false;\r
be2d41b7 360 uint8_t cmdp = 0;\r
8e99ec25 361 while(param_getchar(Cmd, cmdp) != 0x00 && !errors) {\r
362 switch(param_getchar(Cmd, cmdp)) {\r
363 case 'h':\r
364 case 'H':\r
365 return usage_t55xx_read();\r
366 case 'b':\r
367 case 'B':\r
368 errors |= param_getdec(Cmd, cmdp+1, &block);\r
be2d41b7 369 cmdp += 2;\r
8e99ec25 370 break;\r
371 case 'o':\r
372 case 'O':\r
be2d41b7 373 override = true;\r
8e99ec25 374 cmdp++;\r
375 break;\r
376 case 'p':\r
377 case 'P':\r
be2d41b7 378 password = param_get32ex(Cmd, cmdp+1, 0, 16);\r
379 usepwd = true;\r
380 cmdp += 2;\r
8e99ec25 381 break;\r
be2d41b7 382 case '1':\r
383 page1 = true;\r
8e99ec25 384 cmdp++;\r
385 break;\r
6763dc17 386 case 'r':\r
387 case 'R':\r
dd8e4513 388 downlink_mode = param_getchar(Cmd, cmdp+1) - '0';\r
389 if (downlink_mode > 3) downlink_mode = 0;\r
390 cmdp +=2;\r
391 break;\r
8e99ec25 392 default:\r
393 PrintAndLog("Unknown parameter '%c'", param_getchar(Cmd, cmdp));\r
394 errors = true;\r
395 break;\r
396 }\r
397 }\r
398 if (errors) return usage_t55xx_read();\r
13d77ef9 399\r
be2d41b7 400 if (block > 7 && block != REGULAR_READ_MODE_BLOCK ) {\r
401 PrintAndLog("Block must be between 0 and 7");\r
402 return 0;\r
8e99ec25 403 }\r
709665b5 404\r
405 printT5xxHeader(page1);\r
dd8e4513 406 return T55xxReadBlock(block, page1, usepwd, override, password, downlink_mode);\r
54a942b0 407}\r
408\r
13d77ef9 409bool DecodeT55xxBlock(){\r
410 \r
fef74fdc 411 char buf[30] = {0x00};\r
13d77ef9 412 char *cmdStr = buf;\r
413 int ans = 0;\r
d1869c33 414 bool ST = config.ST;\r
13d77ef9 415 uint8_t bitRate[8] = {8,16,32,40,50,64,100,128};\r
13d77ef9 416 DemodBufferLen = 0x00;\r
54a942b0 417\r
13d77ef9 418 switch( config.modulation ){\r
419 case DEMOD_FSK:\r
224ce36e 420 snprintf(cmdStr, sizeof(buf),"%d %d", bitRate[config.bitrate], config.inverted );\r
7cb8516c 421 ans = FSKrawDemod(cmdStr, false);\r
13d77ef9 422 break;\r
423 case DEMOD_FSK1:\r
13d77ef9 424 case DEMOD_FSK1a:\r
224ce36e 425 snprintf(cmdStr, sizeof(buf),"%d %d 8 5", bitRate[config.bitrate], config.inverted );\r
7cb8516c 426 ans = FSKrawDemod(cmdStr, false);\r
13d77ef9 427 break;\r
428 case DEMOD_FSK2:\r
13d77ef9 429 case DEMOD_FSK2a:\r
224ce36e 430 snprintf(cmdStr, sizeof(buf),"%d %d 10 8", bitRate[config.bitrate], config.inverted );\r
7cb8516c 431 ans = FSKrawDemod(cmdStr, false);\r
13d77ef9 432 break;\r
433 case DEMOD_ASK:\r
db829602 434 snprintf(cmdStr, sizeof(buf),"%d %d 1", bitRate[config.bitrate], config.inverted );\r
7cb8516c 435 ans = ASKDemod_ext(cmdStr, false, false, 1, &ST);\r
13d77ef9 436 break;\r
437 case DEMOD_PSK1:\r
db829602 438 // skip first 160 samples to allow antenna to settle in (psk gets inverted occasionally otherwise)\r
3fd7fce4 439 save_restoreGB(GRAPH_SAVE);\r
db829602 440 CmdLtrim("160");\r
441 snprintf(cmdStr, sizeof(buf),"%d %d 6", bitRate[config.bitrate], config.inverted );\r
7cb8516c 442 ans = PSKDemod(cmdStr, false);\r
534678c3 443 //undo trim samples\r
3fd7fce4 444 save_restoreGB(GRAPH_RESTORE);\r
13d77ef9 445 break;\r
2767fc02 446 case DEMOD_PSK2: //inverted won't affect this\r
447 case DEMOD_PSK3: //not fully implemented\r
db829602 448 // skip first 160 samples to allow antenna to settle in (psk gets inverted occasionally otherwise)\r
3fd7fce4 449 save_restoreGB(GRAPH_SAVE);\r
db829602 450 CmdLtrim("160");\r
451 snprintf(cmdStr, sizeof(buf),"%d 0 6", bitRate[config.bitrate] );\r
7cb8516c 452 ans = PSKDemod(cmdStr, false);\r
13d77ef9 453 psk1TOpsk2(DemodBuffer, DemodBufferLen);\r
534678c3 454 //undo trim samples\r
3fd7fce4 455 save_restoreGB(GRAPH_RESTORE);\r
13d77ef9 456 break;\r
457 case DEMOD_NRZ:\r
224ce36e 458 snprintf(cmdStr, sizeof(buf),"%d %d 1", bitRate[config.bitrate], config.inverted );\r
7cb8516c 459 ans = NRZrawDemod(cmdStr, false);\r
13d77ef9 460 break;\r
461 case DEMOD_BI:\r
13d77ef9 462 case DEMOD_BIa:\r
db829602 463 snprintf(cmdStr, sizeof(buf),"0 %d %d 1", bitRate[config.bitrate], config.inverted );\r
7cb8516c 464 ans = ASKbiphaseDemod(cmdStr, false);\r
13d77ef9 465 break;\r
466 default:\r
7cb8516c 467 return false;\r
13d77ef9 468 }\r
469 return (bool) ans;\r
470}\r
54a942b0 471\r
5490c2d6 472bool DecodeT5555TraceBlock() {\r
473 DemodBufferLen = 0x00;\r
474 \r
475 // According to datasheet. Always: RF/64, not inverted, Manchester\r
7cb8516c 476 return (bool) ASKDemod("64 0 1", false, false, 1);\r
5490c2d6 477}\r
478\r
4be71814 479void T55xx_Print_DownlinkMode (uint8_t downlink_mode)\r
480{\r
481 char Msg[80];\r
482 sprintf (Msg,"Downlink Mode used : ");\r
483 \r
484 switch (downlink_mode) {\r
485 case 0 : strcat (Msg,"default/fixed bit length"); break;\r
486 case 1 : strcat (Msg,"long leading reference (r 1)"); break;\r
487 case 2 : strcat (Msg,"leading zero reference (r 2)"); break;\r
488 case 3 : strcat (Msg,"1 of 4 coding reference (r 3)"); break;\r
489 default :\r
490 strcat (Msg,"default/fixed bit length"); break;\r
491\r
492 }\r
493 \r
494 PrintAndLog (Msg);\r
495 \r
496}\r
497\r
13d77ef9 498int CmdT55xxDetect(const char *Cmd){\r
7cb8516c 499 bool errors = false;\r
500 bool useGB = false;\r
501 bool usepwd = false;\r
ab5ffe3b 502 uint32_t password = 0;\r
503 uint8_t cmdp = 0;\r
dd8e4513 504 uint8_t downlink_mode = 0;\r
54a942b0 505\r
ab5ffe3b 506 while(param_getchar(Cmd, cmdp) != 0x00 && !errors) {\r
507 switch(param_getchar(Cmd, cmdp)) {\r
508 case 'h':\r
509 case 'H':\r
510 return usage_t55xx_detect();\r
511 case 'p':\r
512 case 'P':\r
513 password = param_get32ex(Cmd, cmdp+1, 0, 16);\r
7cb8516c 514 usepwd = true;\r
ab5ffe3b 515 cmdp += 2;\r
516 break;\r
517 case '1':\r
518 // use Graphbuffer data\r
7cb8516c 519 useGB = true;\r
ab5ffe3b 520 cmdp++;\r
521 break;\r
6763dc17 522 case 'r':\r
523 case 'R':\r
dd8e4513 524 downlink_mode = param_getchar(Cmd, cmdp+1) - '0';\r
525 if (downlink_mode > 3) downlink_mode = 0;\r
526 cmdp +=2;\r
527 break; \r
ab5ffe3b 528 default:\r
529 PrintAndLog("Unknown parameter '%c'", param_getchar(Cmd, cmdp));\r
530 errors = true;\r
531 break;\r
532 }\r
709665b5 533 }\r
ab5ffe3b 534 if (errors) return usage_t55xx_detect();\r
13d77ef9 535 \r
ab5ffe3b 536 if ( !useGB) {\r
dd8e4513 537 if ( !AquireData(T55x7_PAGE0, T55x7_CONFIGURATION_BLOCK, usepwd, password,downlink_mode) )\r
ab5ffe3b 538 return 0;\r
709665b5 539 }\r
ab5ffe3b 540 \r
13d77ef9 541 if ( !tryDetectModulation() )\r
542 PrintAndLog("Could not detect modulation automatically. Try setting it manually with \'lf t55xx config\'");\r
dd8e4513 543 else {\r
4be71814 544 // Add downlink mode for reference.\r
545 T55xx_Print_DownlinkMode (downlink_mode);\r
dd8e4513 546 }\r
be2d41b7 547 return 1;\r
54a942b0 548}\r
549\r
13d77ef9 550// detect configuration?\r
551bool tryDetectModulation(){\r
13d77ef9 552 uint8_t hits = 0;\r
553 t55xx_conf_block_t tests[15];\r
fef74fdc 554 int bitRate=0;\r
b97311b1 555 uint8_t fc1 = 0, fc2 = 0, ans = 0;\r
bb4e6dbd 556 int clk = 0, firstClockEdge = 0;\r
557 ans = fskClocks(&fc1, &fc2, (uint8_t *)&clk, false, &firstClockEdge);\r
b97311b1 558 if (ans && ((fc1==10 && fc2==8) || (fc1==8 && fc2==5))) {\r
7cb8516c 559 if ( FSKrawDemod("0 0", false) && test(DEMOD_FSK, &tests[hits].offset, &bitRate, clk, &tests[hits].Q5)) {\r
13d77ef9 560 tests[hits].modulation = DEMOD_FSK;\r
561 if (fc1==8 && fc2 == 5)\r
562 tests[hits].modulation = DEMOD_FSK1a;\r
f6650679 563 else if (fc1==10 && fc2 == 8)\r
13d77ef9 564 tests[hits].modulation = DEMOD_FSK2;\r
fef74fdc 565 tests[hits].bitrate = bitRate;\r
7cb8516c 566 tests[hits].inverted = false;\r
13d77ef9 567 tests[hits].block0 = PackBits(tests[hits].offset, 32, DemodBuffer);\r
7cb8516c 568 tests[hits].ST = false;\r
13d77ef9 569 ++hits;\r
570 }\r
7cb8516c 571 if ( FSKrawDemod("0 1", false) && test(DEMOD_FSK, &tests[hits].offset, &bitRate, clk, &tests[hits].Q5)) {\r
13d77ef9 572 tests[hits].modulation = DEMOD_FSK;\r
fef74fdc 573 if (fc1 == 8 && fc2 == 5)\r
13d77ef9 574 tests[hits].modulation = DEMOD_FSK1;\r
fef74fdc 575 else if (fc1 == 10 && fc2 == 8)\r
13d77ef9 576 tests[hits].modulation = DEMOD_FSK2a;\r
fef74fdc 577 tests[hits].bitrate = bitRate;\r
7cb8516c 578 tests[hits].inverted = true;\r
13d77ef9 579 tests[hits].block0 = PackBits(tests[hits].offset, 32, DemodBuffer);\r
7cb8516c 580 tests[hits].ST = false;\r
13d77ef9 581 ++hits;\r
582 }\r
583 } else {\r
7cb8516c 584 clk = GetAskClock("", false, false);\r
322f7eb1 585 if (clk>0) {\r
7cb8516c 586 tests[hits].ST = true;\r
587 if ( ASKDemod_ext("0 0 1", false, false, 1, &tests[hits].ST) && test(DEMOD_ASK, &tests[hits].offset, &bitRate, clk, &tests[hits].Q5)) {\r
322f7eb1 588 tests[hits].modulation = DEMOD_ASK;\r
589 tests[hits].bitrate = bitRate;\r
7cb8516c 590 tests[hits].inverted = false;\r
322f7eb1 591 tests[hits].block0 = PackBits(tests[hits].offset, 32, DemodBuffer);\r
592 ++hits;\r
593 }\r
7cb8516c 594 tests[hits].ST = true;\r
595 if ( ASKDemod_ext("0 1 1", false, false, 1, &tests[hits].ST) && test(DEMOD_ASK, &tests[hits].offset, &bitRate, clk, &tests[hits].Q5)) {\r
322f7eb1 596 tests[hits].modulation = DEMOD_ASK;\r
597 tests[hits].bitrate = bitRate;\r
7cb8516c 598 tests[hits].inverted = true;\r
322f7eb1 599 tests[hits].block0 = PackBits(tests[hits].offset, 32, DemodBuffer);\r
600 ++hits;\r
601 }\r
7cb8516c 602 if ( ASKbiphaseDemod("0 0 0 2", false) && test(DEMOD_BI, &tests[hits].offset, &bitRate, clk, &tests[hits].Q5) ) {\r
322f7eb1 603 tests[hits].modulation = DEMOD_BI;\r
604 tests[hits].bitrate = bitRate;\r
7cb8516c 605 tests[hits].inverted = false;\r
322f7eb1 606 tests[hits].block0 = PackBits(tests[hits].offset, 32, DemodBuffer);\r
7cb8516c 607 tests[hits].ST = false;\r
322f7eb1 608 ++hits;\r
609 }\r
7cb8516c 610 if ( ASKbiphaseDemod("0 0 1 2", false) && test(DEMOD_BIa, &tests[hits].offset, &bitRate, clk, &tests[hits].Q5) ) {\r
322f7eb1 611 tests[hits].modulation = DEMOD_BIa;\r
612 tests[hits].bitrate = bitRate;\r
7cb8516c 613 tests[hits].inverted = true;\r
322f7eb1 614 tests[hits].block0 = PackBits(tests[hits].offset, 32, DemodBuffer);\r
7cb8516c 615 tests[hits].ST = false;\r
322f7eb1 616 ++hits;\r
617 }\r
13d77ef9 618 }\r
7cb8516c 619 clk = GetNrzClock("", false, false);\r
bf85d22f 620 if (clk>8) { //clock of rf/8 is likely a false positive, so don't use it.\r
7cb8516c 621 if ( NRZrawDemod("0 0 1", false) && test(DEMOD_NRZ, &tests[hits].offset, &bitRate, clk, &tests[hits].Q5)) {\r
322f7eb1 622 tests[hits].modulation = DEMOD_NRZ;\r
623 tests[hits].bitrate = bitRate;\r
7cb8516c 624 tests[hits].inverted = false;\r
322f7eb1 625 tests[hits].block0 = PackBits(tests[hits].offset, 32, DemodBuffer);\r
7cb8516c 626 tests[hits].ST = false;\r
322f7eb1 627 ++hits;\r
628 }\r
54a942b0 629\r
7cb8516c 630 if ( NRZrawDemod("0 1 1", false) && test(DEMOD_NRZ, &tests[hits].offset, &bitRate, clk, &tests[hits].Q5)) {\r
322f7eb1 631 tests[hits].modulation = DEMOD_NRZ;\r
632 tests[hits].bitrate = bitRate;\r
7cb8516c 633 tests[hits].inverted = true;\r
322f7eb1 634 tests[hits].block0 = PackBits(tests[hits].offset, 32, DemodBuffer);\r
7cb8516c 635 tests[hits].ST = false;\r
322f7eb1 636 ++hits;\r
637 }\r
13d77ef9 638 }\r
639 \r
7cb8516c 640 clk = GetPskClock("", false, false);\r
322f7eb1 641 if (clk>0) {\r
b97311b1 642 // allow undo\r
3fd7fce4 643 save_restoreGB(GRAPH_SAVE);\r
b97311b1 644 // skip first 160 samples to allow antenna to settle in (psk gets inverted occasionally otherwise)\r
645 CmdLtrim("160");\r
7cb8516c 646 if ( PSKDemod("0 0 6", false) && test(DEMOD_PSK1, &tests[hits].offset, &bitRate, clk, &tests[hits].Q5)) {\r
322f7eb1 647 tests[hits].modulation = DEMOD_PSK1;\r
fef74fdc 648 tests[hits].bitrate = bitRate;\r
7cb8516c 649 tests[hits].inverted = false;\r
13d77ef9 650 tests[hits].block0 = PackBits(tests[hits].offset, 32, DemodBuffer);\r
7cb8516c 651 tests[hits].ST = false;\r
13d77ef9 652 ++hits;\r
653 }\r
7cb8516c 654 if ( PSKDemod("0 1 6", false) && test(DEMOD_PSK1, &tests[hits].offset, &bitRate, clk, &tests[hits].Q5)) {\r
322f7eb1 655 tests[hits].modulation = DEMOD_PSK1;\r
fef74fdc 656 tests[hits].bitrate = bitRate;\r
7cb8516c 657 tests[hits].inverted = true;\r
13d77ef9 658 tests[hits].block0 = PackBits(tests[hits].offset, 32, DemodBuffer);\r
7cb8516c 659 tests[hits].ST = false;\r
13d77ef9 660 ++hits;\r
661 }\r
322f7eb1 662 // PSK2 - needs a call to psk1TOpsk2.\r
7cb8516c 663 if ( PSKDemod("0 0 6", false)) {\r
322f7eb1 664 psk1TOpsk2(DemodBuffer, DemodBufferLen);\r
f6650679 665 if (test(DEMOD_PSK2, &tests[hits].offset, &bitRate, clk, &tests[hits].Q5)){\r
322f7eb1 666 tests[hits].modulation = DEMOD_PSK2;\r
667 tests[hits].bitrate = bitRate;\r
7cb8516c 668 tests[hits].inverted = false;\r
322f7eb1 669 tests[hits].block0 = PackBits(tests[hits].offset, 32, DemodBuffer);\r
7cb8516c 670 tests[hits].ST = false;\r
322f7eb1 671 ++hits;\r
672 }\r
673 } // inverse waves does not affect this demod\r
674 // PSK3 - needs a call to psk1TOpsk2.\r
7cb8516c 675 if ( PSKDemod("0 0 6", false)) {\r
322f7eb1 676 psk1TOpsk2(DemodBuffer, DemodBufferLen);\r
f6650679 677 if (test(DEMOD_PSK3, &tests[hits].offset, &bitRate, clk, &tests[hits].Q5)){\r
322f7eb1 678 tests[hits].modulation = DEMOD_PSK3;\r
679 tests[hits].bitrate = bitRate;\r
7cb8516c 680 tests[hits].inverted = false;\r
322f7eb1 681 tests[hits].block0 = PackBits(tests[hits].offset, 32, DemodBuffer);\r
7cb8516c 682 tests[hits].ST = false;\r
322f7eb1 683 ++hits;\r
684 }\r
685 } // inverse waves does not affect this demod\r
b97311b1 686 //undo trim samples\r
3fd7fce4 687 save_restoreGB(GRAPH_RESTORE);\r
13d77ef9 688 }\r
6fe5c94b 689 } \r
13d77ef9 690 if ( hits == 1) {\r
691 config.modulation = tests[0].modulation;\r
fef74fdc 692 config.bitrate = tests[0].bitrate;\r
13d77ef9 693 config.inverted = tests[0].inverted;\r
694 config.offset = tests[0].offset;\r
695 config.block0 = tests[0].block0;\r
6ca1477c 696 config.Q5 = tests[0].Q5;\r
d1869c33 697 config.ST = tests[0].ST;\r
4be71814 698 \r
699 printConfiguration( config);\r
7cb8516c 700 return true;\r
13d77ef9 701 }\r
702 \r
703 if ( hits > 1) {\r
704 PrintAndLog("Found [%d] possible matches for modulation.",hits);\r
705 for(int i=0; i<hits; ++i){\r
706 PrintAndLog("--[%d]---------------", i+1);\r
4be71814 707 printConfiguration( tests[i]);\r
13d77ef9 708 }\r
709 }\r
7cb8516c 710 return false;\r
13d77ef9 711}\r
712\r
713bool testModulation(uint8_t mode, uint8_t modread){\r
714 switch( mode ){\r
715 case DEMOD_FSK:\r
7cb8516c 716 if (modread >= DEMOD_FSK1 && modread <= DEMOD_FSK2a) return true;\r
13d77ef9 717 break;\r
718 case DEMOD_ASK:\r
7cb8516c 719 if (modread == DEMOD_ASK) return true;\r
13d77ef9 720 break;\r
721 case DEMOD_PSK1:\r
7cb8516c 722 if (modread == DEMOD_PSK1) return true;\r
13d77ef9 723 break;\r
724 case DEMOD_PSK2:\r
7cb8516c 725 if (modread == DEMOD_PSK2) return true;\r
13d77ef9 726 break;\r
727 case DEMOD_PSK3:\r
7cb8516c 728 if (modread == DEMOD_PSK3) return true;\r
13d77ef9 729 break;\r
730 case DEMOD_NRZ:\r
7cb8516c 731 if (modread == DEMOD_NRZ) return true;\r
13d77ef9 732 break;\r
733 case DEMOD_BI:\r
7cb8516c 734 if (modread == DEMOD_BI) return true;\r
13d77ef9 735 break;\r
736 case DEMOD_BIa:\r
7cb8516c 737 if (modread == DEMOD_BIa) return true;\r
13d77ef9 738 break; \r
739 default:\r
7cb8516c 740 return false;\r
13d77ef9 741 }\r
7cb8516c 742 return false;\r
13d77ef9 743}\r
744\r
f6650679 745bool testQ5Modulation(uint8_t mode, uint8_t modread){\r
746 switch( mode ){\r
13d77ef9 747 case DEMOD_FSK:\r
7cb8516c 748 if (modread >= 4 && modread <= 5) return true;\r
13d77ef9 749 break;\r
750 case DEMOD_ASK:\r
7cb8516c 751 if (modread == 0) return true;\r
13d77ef9 752 break;\r
753 case DEMOD_PSK1:\r
7cb8516c 754 if (modread == 1) return true;\r
f6650679 755 break;\r
13d77ef9 756 case DEMOD_PSK2:\r
7cb8516c 757 if (modread == 2) return true;\r
f6650679 758 break;\r
13d77ef9 759 case DEMOD_PSK3:\r
7cb8516c 760 if (modread == 3) return true;\r
13d77ef9 761 break;\r
762 case DEMOD_NRZ:\r
7cb8516c 763 if (modread == 7) return true;\r
f6650679 764 break;\r
765 case DEMOD_BI:\r
7cb8516c 766 if (modread == 6) return true;\r
13d77ef9 767 break;\r
13d77ef9 768 default:\r
7cb8516c 769 return false;\r
13d77ef9 770 }\r
7cb8516c 771 return false;\r
13d77ef9 772}\r
773\r
af5384bc 774int convertQ5bitRate(uint8_t bitRateRead) {\r
775 uint8_t expected[] = {8, 16, 32, 40, 50, 64, 100, 128};\r
776 for (int i=0; i<8; i++)\r
777 if (expected[i] == bitRateRead)\r
778 return i;\r
779\r
780 return -1;\r
781}\r
782\r
f6650679 783bool testQ5(uint8_t mode, uint8_t *offset, int *fndBitRate, uint8_t clk){\r
784\r
7cb8516c 785 if ( DemodBufferLen < 64 ) return false;\r
f6650679 786 uint8_t si = 0;\r
db829602 787 for (uint8_t idx = 28; idx < 64; idx++){\r
f6650679 788 si = idx;\r
db829602 789 if ( PackBits(si, 28, DemodBuffer) == 0x00 ) continue;\r
f6650679 790\r
791 uint8_t safer = PackBits(si, 4, DemodBuffer); si += 4; //master key\r
792 uint8_t resv = PackBits(si, 8, DemodBuffer); si += 8;\r
793 // 2nibble must be zeroed.\r
6ca1477c 794 if (safer != 0x6 && safer != 0x9) continue;\r
f6650679 795 if ( resv > 0x00) continue;\r
796 //uint8_t pageSel = PackBits(si, 1, DemodBuffer); si += 1;\r
797 //uint8_t fastWrite = PackBits(si, 1, DemodBuffer); si += 1;\r
798 si += 1+1;\r
6ca1477c 799 int bitRate = PackBits(si, 6, DemodBuffer)*2 + 2; si += 6; //bit rate\r
db829602 800 if (bitRate > 128 || bitRate < 8) continue;\r
f6650679 801\r
db829602 802 //uint8_t AOR = PackBits(si, 1, DemodBuffer); si += 1; \r
f6650679 803 //uint8_t PWD = PackBits(si, 1, DemodBuffer); si += 1; \r
804 //uint8_t pskcr = PackBits(si, 2, DemodBuffer); si += 2; //could check psk cr\r
805 //uint8_t inverse = PackBits(si, 1, DemodBuffer); si += 1;\r
db829602 806 si += 1+1+2+1;\r
807 uint8_t modread = PackBits(si, 3, DemodBuffer); si += 3;\r
808 uint8_t maxBlk = PackBits(si, 3, DemodBuffer); si += 3;\r
f6650679 809 //uint8_t ST = PackBits(si, 1, DemodBuffer); si += 1;\r
db829602 810 if (maxBlk == 0) continue;\r
f6650679 811 //test modulation\r
812 if (!testQ5Modulation(mode, modread)) continue;\r
813 if (bitRate != clk) continue;\r
af5384bc 814 *fndBitRate = convertQ5bitRate(bitRate);\r
815 if (*fndBitRate < 0) continue;\r
f6650679 816 *offset = idx;\r
817\r
7cb8516c 818 return true;\r
f6650679 819 }\r
7cb8516c 820 return false;\r
f6650679 821}\r
822\r
823bool testBitRate(uint8_t readRate, uint8_t clk){\r
db829602 824 uint8_t expected[] = {8, 16, 32, 40, 50, 64, 100, 128};\r
f6650679 825 if (expected[readRate] == clk)\r
826 return true;\r
827\r
828 return false;\r
829}\r
830\r
831bool test(uint8_t mode, uint8_t *offset, int *fndBitRate, uint8_t clk, bool *Q5){\r
13d77ef9 832\r
7cb8516c 833 if ( DemodBufferLen < 64 ) return false;\r
13d77ef9 834 uint8_t si = 0;\r
db829602 835 for (uint8_t idx = 28; idx < 64; idx++){\r
13d77ef9 836 si = idx;\r
db829602 837 if ( PackBits(si, 28, DemodBuffer) == 0x00 ) continue;\r
13d77ef9 838\r
2767fc02 839 uint8_t safer = PackBits(si, 4, DemodBuffer); si += 4; //master key\r
13d77ef9 840 uint8_t resv = PackBits(si, 4, DemodBuffer); si += 4; //was 7 & +=7+3 //should be only 4 bits if extended mode\r
841 // 2nibble must be zeroed.\r
842 // moved test to here, since this gets most faults first.\r
843 if ( resv > 0x00) continue;\r
844\r
b97311b1 845 int bitRate = PackBits(si, 6, DemodBuffer); si += 6; //bit rate (includes extended mode part of rate)\r
13d77ef9 846 uint8_t extend = PackBits(si, 1, DemodBuffer); si += 1; //bit 15 extended mode\r
2767fc02 847 uint8_t modread = PackBits(si, 5, DemodBuffer); si += 5+2+1; \r
848 //uint8_t pskcr = PackBits(si, 2, DemodBuffer); si += 2+1; //could check psk cr\r
35cfcfc7 849 //uint8_t nml01 = PackBits(si, 1, DemodBuffer); si += 1+5; //bit 24, 30, 31 could be tested for 0 if not extended mode\r
850 //uint8_t nml02 = PackBits(si, 2, DemodBuffer); si += 2;\r
13d77ef9 851 \r
852 //if extended mode\r
7cb8516c 853 bool extMode =( (safer == 0x6 || safer == 0x9) && extend) ? true : false;\r
13d77ef9 854\r
b97311b1 855 if (!extMode) {\r
856 if (bitRate > 7) continue;\r
857 if (!testBitRate(bitRate, clk)) continue;\r
858 } else { //extended mode bitrate = same function to calc bitrate as em4x05\r
859 if (EM4x05_GET_BITRATE(bitRate) != clk) continue;\r
b9957414 860\r
13d77ef9 861 }\r
862 //test modulation\r
863 if (!testModulation(mode, modread)) continue;\r
fef74fdc 864 *fndBitRate = bitRate;\r
2767fc02 865 *offset = idx;\r
7cb8516c 866 *Q5 = false;\r
867 return true;\r
f6650679 868 }\r
869 if (testQ5(mode, offset, fndBitRate, clk)) {\r
7cb8516c 870 *Q5 = true;\r
871 return true;\r
13d77ef9 872 }\r
7cb8516c 873 return false;\r
54a942b0 874}\r
875\r
224ce36e 876void printT55xxBlock(const char *blockNum){\r
13d77ef9 877 \r
878 uint8_t i = config.offset;\r
879 uint8_t endpos = 32 + i;\r
880 uint32_t blockData = 0;\r
881 uint8_t bits[64] = {0x00};\r
882\r
883 if ( !DemodBufferLen) return;\r
884\r
885 if ( endpos > DemodBufferLen){\r
886 PrintAndLog("The configured offset %d is too big. Possible offset: %d)", i, DemodBufferLen-32);\r
887 return;\r
888 }\r
889\r
890 for (; i < endpos; ++i)\r
891 bits[i - config.offset]=DemodBuffer[i];\r
93507a33 892\r
13d77ef9 893 blockData = PackBits(0, 32, bits);\r
db829602 894\r
be2d41b7 895 PrintAndLog(" %s | %08X | %s", blockNum, blockData, sprint_bin(bits,32));\r
13d77ef9 896}\r
897\r
898int special(const char *Cmd) {\r
899 uint32_t blockData = 0;\r
900 uint8_t bits[32] = {0x00};\r
901\r
be2d41b7 902 PrintAndLog("OFFSET | DATA | BINARY");\r
13d77ef9 903 PrintAndLog("----------------------------------------------------");\r
904 int i,j = 0;\r
905 for (; j < 64; ++j){\r
906 \r
907 for (i = 0; i < 32; ++i)\r
908 bits[i]=DemodBuffer[j+i];\r
909 \r
910 blockData = PackBits(0, 32, bits);\r
911 \r
be2d41b7 912 PrintAndLog(" %02d | 0x%08X | %s",j , blockData, sprint_bin(bits,32)); \r
13d77ef9 913 }\r
914 return 0;\r
915}\r
916\r
be2d41b7 917int printConfiguration( t55xx_conf_block_t b){\r
f6650679 918 PrintAndLog("Chip Type : %s", (b.Q5) ? "T5555(Q5)" : "T55x7");\r
13d77ef9 919 PrintAndLog("Modulation : %s", GetSelectedModulationStr(b.modulation) );\r
b9957414 920 PrintAndLog("Bit Rate : %s", GetBitRateStr(b.bitrate, (b.block0 & T55x7_X_MODE && (b.block0>>28==6 || b.block0>>28==9))) );\r
13d77ef9 921 PrintAndLog("Inverted : %s", (b.inverted) ? "Yes" : "No" );\r
922 PrintAndLog("Offset : %d", b.offset);\r
8e90cd41 923 PrintAndLog("Seq. Term. : %s", (b.ST) ? "Yes" : "No" );\r
13d77ef9 924 PrintAndLog("Block0 : 0x%08X", b.block0);\r
925 PrintAndLog("");\r
be2d41b7 926 return 0;\r
13d77ef9 927}\r
928\r
be2d41b7 929int CmdT55xxWakeUp(const char *Cmd) {\r
930 uint32_t password = 0;\r
b97311b1 931 if ( strlen(Cmd) <= 0 ) return usage_t55xx_wakup();\r
932 char cmdp = param_getchar(Cmd, 0);\r
933 if ( cmdp == 'h' || cmdp == 'H') return usage_t55xx_wakup();\r
934\r
935 password = param_get32ex(Cmd, 0, 0, 16);\r
be2d41b7 936\r
937 UsbCommand c = {CMD_T55XX_WAKEUP, {password, 0, 0}};\r
938 clearCommandBuffer();\r
939 SendCommand(&c);\r
940 PrintAndLog("Wake up command sent. Try read now");\r
941 return 0;\r
942}\r
943\r
944int CmdT55xxWriteBlock(const char *Cmd) {\r
945 uint8_t block = 0xFF; //default to invalid block\r
709665b5 946 uint32_t data = 0; //default to blank Block \r
947 uint32_t password = 0; //default to blank Block 7\r
dd8e4513 948 uint32_t downlink_mode = 0;\r
949 \r
be2d41b7 950 bool usepwd = false;\r
951 bool page1 = false; \r
952 bool gotdata = false;\r
b97311b1 953 bool testMode = false;\r
be2d41b7 954 bool errors = false;\r
955 uint8_t cmdp = 0;\r
956 while(param_getchar(Cmd, cmdp) != 0x00 && !errors) {\r
957 switch(param_getchar(Cmd, cmdp)) {\r
958 case 'h':\r
959 case 'H':\r
960 return usage_t55xx_write();\r
961 case 'b':\r
962 case 'B':\r
963 errors |= param_getdec(Cmd, cmdp+1, &block);\r
964 cmdp += 2;\r
965 break;\r
966 case 'd':\r
967 case 'D':\r
968 data = param_get32ex(Cmd, cmdp+1, 0, 16);\r
969 gotdata = true;\r
970 cmdp += 2;\r
971 break;\r
972 case 'p':\r
973 case 'P':\r
974 password = param_get32ex(Cmd, cmdp+1, 0, 16);\r
975 usepwd = true;\r
976 cmdp += 2;\r
977 break;\r
b97311b1 978 case 't':\r
979 case 'T':\r
980 testMode = true;\r
981 cmdp++;\r
982 break;\r
be2d41b7 983 case '1':\r
984 page1 = true;\r
985 cmdp++;\r
986 break;\r
6763dc17 987 case 'r':\r
988 case 'R':\r
dd8e4513 989 downlink_mode = param_getchar(Cmd, cmdp+1) - '0';\r
990 if (downlink_mode > 3) downlink_mode = 0;\r
991 cmdp +=2;\r
992 break;\r
be2d41b7 993 default:\r
994 PrintAndLog("Unknown parameter '%c'", param_getchar(Cmd, cmdp));\r
995 errors = true;\r
996 break;\r
997 }\r
13d77ef9 998 }\r
be2d41b7 999 if (errors || !gotdata) return usage_t55xx_write();\r
13d77ef9 1000\r
1001 if (block > 7) {\r
1002 PrintAndLog("Block number must be between 0 and 7");\r
be2d41b7 1003 return 0;\r
13d77ef9 1004 }\r
1005 \r
1006 UsbCommand c = {CMD_T55XX_WRITE_BLOCK, {data, block, 0}};\r
976627d5 1007 UsbCommand resp;\r
be2d41b7 1008 c.d.asBytes[0] = (page1) ? 0x2 : 0; \r
b97311b1 1009 c.d.asBytes[0] |= (testMode) ? 0x4 : 0; \r
dd8e4513 1010 c.d.asBytes[0] |= (downlink_mode << 3);\r
1011 \r
709665b5 1012 char pwdStr[16] = {0};\r
1013 snprintf(pwdStr, sizeof(pwdStr), "pwd: 0x%08X", password);\r
1014\r
1015 PrintAndLog("Writing page %d block: %02d data: 0x%08X %s", page1, block, data, (usepwd) ? pwdStr : "" );\r
dd8e4513 1016 \r
13d77ef9 1017 //Password mode\r
be2d41b7 1018 if (usepwd) {\r
13d77ef9 1019 c.arg[2] = password;\r
be2d41b7 1020 c.d.asBytes[0] |= 0x1; \r
13d77ef9 1021 }\r
dd8e4513 1022 \r
40c5f342 1023 clearCommandBuffer();\r
13d77ef9 1024 SendCommand(&c);\r
976627d5
MHS
1025 if (!WaitForResponseTimeout(CMD_ACK, &resp, 1000)){\r
1026 PrintAndLog("Error occurred, device did not ACK write operation. (May be due to old firmware)");\r
be2d41b7 1027 return 0;\r
976627d5 1028 }\r
be2d41b7 1029 return 1;\r
54a942b0 1030}\r
1031\r
be2d41b7 1032int CmdT55xxReadTrace(const char *Cmd) {\r
13d77ef9 1033 char cmdp = param_getchar(Cmd, 0);\r
be2d41b7 1034 bool pwdmode = false;\r
1035 uint32_t password = 0;\r
13d77ef9 1036 if (strlen(Cmd) > 1 || cmdp == 'h' || cmdp == 'H') \r
1037 return usage_t55xx_trace();\r
1038\r
1039 if (strlen(Cmd)==0)\r
dd8e4513 1040 if ( !AquireData( T55x7_PAGE1, REGULAR_READ_MODE_BLOCK, pwdmode, password,0 ) )\r
be2d41b7 1041 return 0;\r
be2d41b7 1042\r
5490c2d6 1043 if ( config.Q5 ) {\r
1044 if (!DecodeT5555TraceBlock()) return 0;\r
1045 } else {\r
1046 if (!DecodeT55xxBlock()) return 0;\r
1047 }\r
1048\r
1049 if ( !DemodBufferLen ) return 0;\r
54a942b0 1050\r
13d77ef9 1051 RepaintGraphWindow();\r
5490c2d6 1052 uint8_t repeat = (config.offset > 5) ? 32 : 0;\r
1053\r
13d77ef9 1054 uint8_t si = config.offset+repeat;\r
be2d41b7 1055 uint32_t bl1 = PackBits(si, 32, DemodBuffer);\r
1056 uint32_t bl2 = PackBits(si+32, 32, DemodBuffer);\r
224ce36e 1057\r
5490c2d6 1058 if (config.Q5) {\r
1059 uint32_t hdr = PackBits(si, 9, DemodBuffer); si += 9;\r
1060\r
1061 if (hdr != 0x1FF) {\r
1062 PrintAndLog("Invalid Q5 Trace data header (expected 0x1FF, found %X)", hdr);\r
1063 return 0;\r
1064 }\r
1065\r
1066 t5555_tracedata_t data = {.bl1 = bl1, .bl2 = bl2, .icr = 0, .lotidc = '?', .lotid = 0, .wafer = 0, .dw =0};\r
1067\r
1068 data.icr = PackBits(si, 2, DemodBuffer); si += 2;\r
1069 data.lotidc = 'Z' - PackBits(si, 2, DemodBuffer); si += 3;\r
1070\r
1071 data.lotid = PackBits(si, 4, DemodBuffer); si += 5;\r
1072 data.lotid <<= 4;\r
1073 data.lotid |= PackBits(si, 4, DemodBuffer); si += 5;\r
1074 data.lotid <<= 4;\r
1075 data.lotid |= PackBits(si, 4, DemodBuffer); si += 5;\r
1076 data.lotid <<= 4;\r
1077 data.lotid |= PackBits(si, 4, DemodBuffer); si += 5;\r
1078 data.lotid <<= 1;\r
1079 data.lotid |= PackBits(si, 1, DemodBuffer); si += 1;\r
1080\r
1081 data.wafer = PackBits(si, 3, DemodBuffer); si += 4;\r
1082 data.wafer <<= 2;\r
1083 data.wafer |= PackBits(si, 2, DemodBuffer); si += 2;\r
1084\r
1085 data.dw = PackBits(si, 2, DemodBuffer); si += 3;\r
1086 data.dw <<= 4;\r
1087 data.dw |= PackBits(si, 4, DemodBuffer); si += 5;\r
1088 data.dw <<= 4;\r
1089 data.dw |= PackBits(si, 4, DemodBuffer); si += 5;\r
1090 data.dw <<= 4;\r
1091 data.dw |= PackBits(si, 4, DemodBuffer); si += 5;\r
1092\r
1093 printT5555Trace(data, repeat);\r
1094\r
1095 } else {\r
1096\r
1097 t55x7_tracedata_t data = {.bl1 = bl1, .bl2 = bl2, .acl = 0, .mfc = 0, .cid = 0, .year = 0, .quarter = 0, .icr = 0, .lotid = 0, .wafer = 0, .dw = 0};\r
1098 \r
1099 data.acl = PackBits(si, 8, DemodBuffer); si += 8;\r
1100 if ( data.acl != 0xE0 ) {\r
1101 PrintAndLog("The modulation is most likely wrong since the ACL is not 0xE0. ");\r
1102 return 0;\r
1103 }\r
1104\r
1105 data.mfc = PackBits(si, 8, DemodBuffer); si += 8;\r
1106 data.cid = PackBits(si, 5, DemodBuffer); si += 5;\r
1107 data.icr = PackBits(si, 3, DemodBuffer); si += 3;\r
1108 data.year = PackBits(si, 4, DemodBuffer); si += 4;\r
1109 data.quarter = PackBits(si, 2, DemodBuffer); si += 2;\r
1110 data.lotid = PackBits(si, 14, DemodBuffer); si += 14;\r
1111 data.wafer = PackBits(si, 5, DemodBuffer); si += 5;\r
1112 data.dw = PackBits(si, 15, DemodBuffer); \r
1113\r
1114 time_t t = time(NULL);\r
1115 struct tm tm = *localtime(&t);\r
1116 if ( data.year > tm.tm_year-110)\r
1117 data.year += 2000;\r
1118 else\r
1119 data.year += 2010;\r
1120\r
1121 printT55x7Trace(data, repeat);\r
224ce36e 1122 }\r
5490c2d6 1123 return 0;\r
1124}\r
1125\r
1126void printT55x7Trace( t55x7_tracedata_t data, uint8_t repeat ){\r
1127 PrintAndLog("-- T55x7 Trace Information ----------------------------------");\r
13d77ef9 1128 PrintAndLog("-------------------------------------------------------------");\r
5490c2d6 1129 PrintAndLog(" ACL Allocation class (ISO/IEC 15963-1) : 0x%02X (%d)", data.acl, data.acl);\r
1338d245 1130 PrintAndLog(" MFC Manufacturer ID (ISO/IEC 7816-6) : 0x%02X (%d) - %s", data.mfc, data.mfc, getManufacturerName(data.mfc));\r
5490c2d6 1131 PrintAndLog(" CID : 0x%02X (%d) - %s", data.cid, data.cid, GetModelStrFromCID(data.cid));\r
1132 PrintAndLog(" ICR IC Revision : %d", data.icr );\r
13d77ef9 1133 PrintAndLog(" Manufactured");\r
5490c2d6 1134 PrintAndLog(" Year/Quarter : %d/%d", data.year, data.quarter);\r
1135 PrintAndLog(" Lot ID : %d", data.lotid );\r
1136 PrintAndLog(" Wafer number : %d", data.wafer);\r
1137 PrintAndLog(" Die Number : %d", data.dw);\r
13d77ef9 1138 PrintAndLog("-------------------------------------------------------------");\r
1139 PrintAndLog(" Raw Data - Page 1");\r
5490c2d6 1140 PrintAndLog(" Block 1 : 0x%08X %s", data.bl1, sprint_bin(DemodBuffer+config.offset+repeat,32) );\r
1141 PrintAndLog(" Block 2 : 0x%08X %s", data.bl2, sprint_bin(DemodBuffer+config.offset+repeat+32,32) );\r
1142 PrintAndLog("-------------------------------------------------------------"); \r
54a942b0 1143\r
13d77ef9 1144 /*\r
1145 TRACE - BLOCK O\r
1146 Bits Definition HEX\r
1147 1-8 ACL Allocation class (ISO/IEC 15963-1) 0xE0 \r
1148 9-16 MFC Manufacturer ID (ISO/IEC 7816-6) 0x15 Atmel Corporation\r
1149 17-21 CID 0x1 = Atmel ATA5577M1 0x2 = Atmel ATA5577M2 \r
1150 22-24 ICR IC revision\r
1151 25-28 YEAR (BCD encoded) 9 (= 2009)\r
1152 29-30 QUARTER 1,2,3,4 \r
1153 31-32 LOT ID\r
1154 \r
1155 TRACE - BLOCK 1\r
1156 1-12 LOT ID \r
1157 13-17 Wafer number\r
1158 18-32 DW, die number sequential\r
1159 */\r
5490c2d6 1160}\r
1161\r
1162void printT5555Trace( t5555_tracedata_t data, uint8_t repeat ){\r
1163 PrintAndLog("-- T5555 (Q5) Trace Information -----------------------------");\r
1164 PrintAndLog("-------------------------------------------------------------");\r
1165 PrintAndLog(" ICR IC Revision : %d", data.icr ); \r
1166 PrintAndLog(" Lot : %c%d", data.lotidc, data.lotid);\r
1167 PrintAndLog(" Wafer number : %d", data.wafer);\r
1168 PrintAndLog(" Die Number : %d", data.dw);\r
1169 PrintAndLog("-------------------------------------------------------------");\r
1170 PrintAndLog(" Raw Data - Page 1");\r
1171 PrintAndLog(" Block 1 : 0x%08X %s", data.bl1, sprint_bin(DemodBuffer+config.offset+repeat,32) );\r
1172 PrintAndLog(" Block 2 : 0x%08X %s", data.bl2, sprint_bin(DemodBuffer+config.offset+repeat+32,32) );\r
13d77ef9 1173 \r
5490c2d6 1174 /*\r
1175 ** Q5 **\r
1176 TRACE - BLOCK O and BLOCK1\r
1177 Bits Definition HEX\r
1178 1-9 Header 0x1FF\r
1179 10-11 IC Revision\r
1180 12-13 Lot ID char\r
1181 15-35 Lot ID (NB parity)\r
1182 36-41 Wafer number (NB parity)\r
1183 42-58 DW, die number sequential (NB parity)\r
1184 60-63 Parity bits\r
1185 64 Always zero\r
1186 */\r
54a942b0 1187}\r
1188\r
5490c2d6 1189//need to add Q5 info...\r
13d77ef9 1190int CmdT55xxInfo(const char *Cmd){\r
1191 /*\r
1192 Page 0 Block 0 Configuration data.\r
1193 Normal mode\r
1194 Extended mode\r
1195 */\r
be2d41b7 1196 bool pwdmode = false;\r
1197 uint32_t password = 0;\r
13d77ef9 1198 char cmdp = param_getchar(Cmd, 0);\r
1199\r
1200 if (strlen(Cmd) > 1 || cmdp == 'h' || cmdp == 'H')\r
1201 return usage_t55xx_info();\r
1202 \r
1203 if (strlen(Cmd)==0)\r
dd8e4513 1204 if ( !AquireData( T55x7_PAGE0, T55x7_CONFIGURATION_BLOCK, pwdmode, password,0 ) )\r
be2d41b7 1205 return 1;\r
fef74fdc 1206\r
13d77ef9 1207 if (!DecodeT55xxBlock()) return 1;\r
1208\r
5490c2d6 1209 // too little space to start with\r
fef74fdc 1210 if ( DemodBufferLen < 32) return 1;\r
13d77ef9 1211\r
1212 uint8_t si = config.offset;\r
1213 uint32_t bl0 = PackBits(si, 32, DemodBuffer);\r
1214 \r
1215 uint32_t safer = PackBits(si, 4, DemodBuffer); si += 4; \r
1216 uint32_t resv = PackBits(si, 7, DemodBuffer); si += 7;\r
1217 uint32_t dbr = PackBits(si, 3, DemodBuffer); si += 3;\r
1218 uint32_t extend = PackBits(si, 1, DemodBuffer); si += 1;\r
1219 uint32_t datamod = PackBits(si, 5, DemodBuffer); si += 5;\r
1220 uint32_t pskcf = PackBits(si, 2, DemodBuffer); si += 2;\r
1221 uint32_t aor = PackBits(si, 1, DemodBuffer); si += 1; \r
1222 uint32_t otp = PackBits(si, 1, DemodBuffer); si += 1; \r
1223 uint32_t maxblk = PackBits(si, 3, DemodBuffer); si += 3;\r
1224 uint32_t pwd = PackBits(si, 1, DemodBuffer); si += 1; \r
1225 uint32_t sst = PackBits(si, 1, DemodBuffer); si += 1; \r
1226 uint32_t fw = PackBits(si, 1, DemodBuffer); si += 1;\r
1227 uint32_t inv = PackBits(si, 1, DemodBuffer); si += 1; \r
1228 uint32_t por = PackBits(si, 1, DemodBuffer); si += 1;\r
5490c2d6 1229 \r
db829602 1230 if (config.Q5) PrintAndLog("*** Warning *** Config Info read off a Q5 will not display as expected");\r
13d77ef9 1231 PrintAndLog("");\r
5490c2d6 1232 PrintAndLog("-- T55x7 Configuration & Tag Information --------------------");\r
13d77ef9 1233 PrintAndLog("-------------------------------------------------------------");\r
1234 PrintAndLog(" Safer key : %s", GetSaferStr(safer));\r
1235 PrintAndLog(" reserved : %d", resv);\r
b97311b1 1236 PrintAndLog(" Data bit rate : %s", GetBitRateStr(dbr, extend));\r
13d77ef9 1237 PrintAndLog(" eXtended mode : %s", (extend) ? "Yes - Warning":"No");\r
1238 PrintAndLog(" Modulation : %s", GetModulationStr(datamod));\r
1239 PrintAndLog(" PSK clock frequency : %d", pskcf);\r
1240 PrintAndLog(" AOR - Answer on Request : %s", (aor) ? "Yes":"No");\r
1241 PrintAndLog(" OTP - One Time Pad : %s", (otp) ? "Yes - Warning":"No" );\r
1242 PrintAndLog(" Max block : %d", maxblk);\r
1243 PrintAndLog(" Password mode : %s", (pwd) ? "Yes":"No");\r
1244 PrintAndLog(" Sequence Start Terminator : %s", (sst) ? "Yes":"No");\r
1245 PrintAndLog(" Fast Write : %s", (fw) ? "Yes":"No");\r
1246 PrintAndLog(" Inverse data : %s", (inv) ? "Yes":"No");\r
1247 PrintAndLog(" POR-Delay : %s", (por) ? "Yes":"No");\r
1248 PrintAndLog("-------------------------------------------------------------");\r
1249 PrintAndLog(" Raw Data - Page 0");\r
1250 PrintAndLog(" Block 0 : 0x%08X %s", bl0, sprint_bin(DemodBuffer+config.offset,32) );\r
1251 PrintAndLog("-------------------------------------------------------------");\r
1252 \r
1253 return 0;\r
1254}\r
1255\r
1256int CmdT55xxDump(const char *Cmd){\r
1257\r
be2d41b7 1258 uint32_t password = 0;\r
13d77ef9 1259 char cmdp = param_getchar(Cmd, 0);\r
be2d41b7 1260 bool override = false;\r
1261 if ( cmdp == 'h' || cmdp == 'H') return usage_t55xx_dump();\r
1262\r
b97311b1 1263 bool usepwd = ( strlen(Cmd) > 0);\r
be2d41b7 1264 if ( usepwd ){\r
1265 password = param_get32ex(Cmd, 0, 0, 16);\r
1266 if (param_getchar(Cmd, 1) =='o' )\r
1267 override = true;\r
13d77ef9 1268 }\r
1269 \r
709665b5 1270 printT5xxHeader(0);\r
1271 for ( uint8_t i = 0; i <8; ++i)\r
dd8e4513 1272 T55xxReadBlock(i, 0, usepwd, override, password,0);\r
709665b5 1273\r
1274 printT5xxHeader(1);\r
1275 for ( uint8_t i = 0; i<4; i++)\r
dd8e4513 1276 T55xxReadBlock(i, 1, usepwd, override, password,0); \r
709665b5 1277\r
be2d41b7 1278 return 1;\r
13d77ef9 1279}\r
1280\r
dd8e4513 1281int AquireData( uint8_t page, uint8_t block, bool pwdmode, uint32_t password, uint8_t downlink_mode ){\r
709665b5 1282 // arg0 bitmodes:\r
1283 // bit0 = pwdmode\r
1284 // bit1 = page to read from\r
be2d41b7 1285 uint8_t arg0 = (page<<1) | pwdmode;\r
dd8e4513 1286 arg0 |= (downlink_mode << 3);\r
be2d41b7 1287 UsbCommand c = {CMD_T55XX_READ_BLOCK, {arg0, block, password}};\r
13d77ef9 1288\r
40c5f342 1289 clearCommandBuffer();\r
13d77ef9 1290 SendCommand(&c);\r
1291 if ( !WaitForResponseTimeout(CMD_ACK,NULL,2500) ) {\r
1292 PrintAndLog("command execution time out");\r
be2d41b7 1293 return 0;\r
13d77ef9 1294 }\r
b9957414 1295 getSamples(12000,true);\r
be2d41b7 1296 return 1;\r
13d77ef9 1297}\r
1298\r
b97311b1 1299char * GetBitRateStr(uint32_t id, bool xmode) {\r
af5384bc 1300 static char buf[25];\r
fef74fdc 1301\r
13d77ef9 1302 char *retStr = buf;\r
b97311b1 1303 if (xmode) { //xmode bitrate calc is same as em4x05 calc\r
1304 snprintf(retStr,sizeof(buf),"%d - RF/%d", id, EM4x05_GET_BITRATE(id));\r
1305 } else {\r
1306 switch (id) {\r
1307 case 0: snprintf(retStr,sizeof(buf),"%d - RF/8",id); break;\r
1308 case 1: snprintf(retStr,sizeof(buf),"%d - RF/16",id); break;\r
1309 case 2: snprintf(retStr,sizeof(buf),"%d - RF/32",id); break;\r
1310 case 3: snprintf(retStr,sizeof(buf),"%d - RF/40",id); break;\r
1311 case 4: snprintf(retStr,sizeof(buf),"%d - RF/50",id); break;\r
1312 case 5: snprintf(retStr,sizeof(buf),"%d - RF/64",id); break;\r
1313 case 6: snprintf(retStr,sizeof(buf),"%d - RF/100",id); break;\r
1314 case 7: snprintf(retStr,sizeof(buf),"%d - RF/128",id); break;\r
1315 default: snprintf(retStr,sizeof(buf),"%d - (Unknown)",id); break;\r
1316 } \r
af5384bc 1317 }\r
13d77ef9 1318 return buf;\r
1319}\r
1320\r
af5384bc 1321char * GetSaferStr(uint32_t id) {\r
13d77ef9 1322 static char buf[40];\r
1323 char *retStr = buf;\r
1324 \r
9795e535 1325 snprintf(retStr,sizeof(buf),"%d",id);\r
13d77ef9 1326 if (id == 6) {\r
9795e535 1327 snprintf(retStr,sizeof(buf),"%d - passwd",id);\r
13d77ef9 1328 }\r
1329 if (id == 9 ){\r
9795e535 1330 snprintf(retStr,sizeof(buf),"%d - testmode",id);\r
13d77ef9 1331 }\r
1332 \r
1333 return buf;\r
1334}\r
9795e535 1335\r
13d77ef9 1336char * GetModulationStr( uint32_t id){\r
2767fc02 1337 static char buf[60];\r
13d77ef9 1338 char *retStr = buf;\r
1339 \r
1340 switch (id){\r
5490c2d6 1341 case 0: snprintf(retStr,sizeof(buf),"%d - DIRECT (ASK/NRZ)",id); break;\r
1342 case 1: snprintf(retStr,sizeof(buf),"%d - PSK 1 phase change when input changes",id); break;\r
1343 case 2: snprintf(retStr,sizeof(buf),"%d - PSK 2 phase change on bitclk if input high",id); break;\r
1344 case 3: snprintf(retStr,sizeof(buf),"%d - PSK 3 phase change on rising edge of input",id); break;\r
1345 case 4: snprintf(retStr,sizeof(buf),"%d - FSK 1 RF/8 RF/5",id); break;\r
1346 case 5: snprintf(retStr,sizeof(buf),"%d - FSK 2 RF/8 RF/10",id); break;\r
1347 case 6: snprintf(retStr,sizeof(buf),"%d - FSK 1a RF/5 RF/8",id); break;\r
1348 case 7: snprintf(retStr,sizeof(buf),"%d - FSK 2a RF/10 RF/8",id); break;\r
1349 case 8: snprintf(retStr,sizeof(buf),"%d - Manchester",id); break;\r
1350 case 16: snprintf(retStr,sizeof(buf),"%d - Biphase",id); break;\r
1351 case 0x18: snprintf(retStr,sizeof(buf),"%d - Biphase a - AKA Conditional Dephase Encoding(CDP)",id); break;\r
1352 case 17: snprintf(retStr,sizeof(buf),"%d - Reserved",id); break;\r
1353 default: snprintf(retStr,sizeof(buf),"0x%02X (Unknown)",id); break;\r
13d77ef9 1354 }\r
1355 return buf;\r
1356}\r
1357\r
1358char * GetModelStrFromCID(uint32_t cid){\r
1359 \r
1360 static char buf[10];\r
1361 char *retStr = buf;\r
1362 \r
224ce36e 1363 if (cid == 1) snprintf(retStr, sizeof(buf),"ATA5577M1");\r
1364 if (cid == 2) snprintf(retStr, sizeof(buf),"ATA5577M2"); \r
13d77ef9 1365 return buf;\r
1366}\r
1367\r
1368char * GetSelectedModulationStr( uint8_t id){\r
1369\r
9795e535 1370 static char buf[20];\r
13d77ef9 1371 char *retStr = buf;\r
1372\r
5490c2d6 1373 switch (id) {\r
1374 case DEMOD_FSK: snprintf(retStr,sizeof(buf),"FSK"); break;\r
1375 case DEMOD_FSK1: snprintf(retStr,sizeof(buf),"FSK1"); break;\r
1376 case DEMOD_FSK1a: snprintf(retStr,sizeof(buf),"FSK1a"); break;\r
1377 case DEMOD_FSK2: snprintf(retStr,sizeof(buf),"FSK2"); break;\r
1378 case DEMOD_FSK2a: snprintf(retStr,sizeof(buf),"FSK2a"); break;\r
1379 case DEMOD_ASK: snprintf(retStr,sizeof(buf),"ASK"); break;\r
1380 case DEMOD_NRZ: snprintf(retStr,sizeof(buf),"DIRECT/NRZ"); break;\r
1381 case DEMOD_PSK1: snprintf(retStr,sizeof(buf),"PSK1"); break;\r
1382 case DEMOD_PSK2: snprintf(retStr,sizeof(buf),"PSK2"); break;\r
1383 case DEMOD_PSK3: snprintf(retStr,sizeof(buf),"PSK3"); break;\r
1384 case DEMOD_BI: snprintf(retStr,sizeof(buf),"BIPHASE"); break;\r
1385 case DEMOD_BIa: snprintf(retStr,sizeof(buf),"BIPHASEa - (CDP)"); break;\r
1386 default: snprintf(retStr,sizeof(buf),"(Unknown)"); break;\r
1387 }\r
13d77ef9 1388 return buf;\r
1389}\r
1390\r
1391uint32_t PackBits(uint8_t start, uint8_t len, uint8_t* bits){\r
1392 \r
1393 int i = start;\r
1394 int j = len-1;\r
1395\r
1396 if (len > 32) return 0;\r
1397\r
1398 uint32_t tmp = 0;\r
1399 for (; j >= 0; --j, ++i)\r
1400 tmp |= bits[i] << j;\r
1401\r
1402 return tmp;\r
1403}\r
1404\r
66837a03 1405int CmdResetRead(const char *Cmd) {\r
1406 UsbCommand c = {CMD_T55XX_RESET_READ, {0,0,0}};\r
1407\r
1408 clearCommandBuffer();\r
1409 SendCommand(&c);\r
1410 if ( !WaitForResponseTimeout(CMD_ACK,NULL,2500) ) {\r
1411 PrintAndLog("command execution time out");\r
1412 return 0;\r
1413 }\r
1414\r
9f669cb2 1415 uint8_t got[BIGBUF_SIZE-1];\r
babca445 1416 GetFromBigBuf(got, sizeof(got), 0, NULL, -1 , 0);\r
66837a03 1417 setGraphBuf(got, sizeof(got));\r
1418 return 1;\r
1419}\r
1420\r
f6650679 1421int CmdT55xxWipe(const char *Cmd) {\r
1422 char writeData[20] = {0};\r
1423 char *ptrData = writeData;\r
709665b5 1424\r
5490c2d6 1425 char cmdp = param_getchar(Cmd, 0); \r
1426 if ( cmdp == 'h' || cmdp == 'H') return usage_t55xx_wipe();\r
1427\r
1428 bool Q5 = (cmdp == 'q' || cmdp == 'Q');\r
1429\r
1430 // Try with the default password to reset block 0\r
1431 // With a pwd should work even if pwd bit not set\r
f6650679 1432 PrintAndLog("\nBeginning Wipe of a T55xx tag (assuming the tag is not password protected)\n");\r
709665b5 1433\r
5490c2d6 1434 if ( Q5 ){\r
1435 snprintf(ptrData,sizeof(writeData),"b 0 d 6001F004 p 0");\r
1436 } else {\r
1437 snprintf(ptrData,sizeof(writeData),"b 0 d 00088040 p 0");\r
1438 }\r
709665b5 1439\r
5490c2d6 1440 if (!CmdT55xxWriteBlock(ptrData)) PrintAndLog("Error writing blk 0");\r
709665b5 1441\r
1442 for (uint8_t blk = 1; blk<8; blk++) {\r
f6650679 1443 snprintf(ptrData,sizeof(writeData),"b %d d 0", blk);\r
709665b5 1444 if (!CmdT55xxWriteBlock(ptrData))\r
f6650679 1445 PrintAndLog("Error writing blk %d", blk);\r
709665b5 1446\r
534678c3 1447 memset(writeData, 0x00, sizeof(writeData));\r
f6650679 1448 }\r
1449 return 0;\r
1450}\r
1451\r
506672c4 1452int CmdT55xxBruteForce(const char *Cmd) {\r
1453\r
1454 // load a default pwd file.\r
1455 char buf[9];\r
1456 char filename[FILE_PATH_SIZE]={0};\r
1457 int keycnt = 0;\r
735136e6 1458 int ch;\r
506672c4 1459 uint8_t stKeyBlock = 20;\r
735136e6 1460 uint8_t *keyBlock = NULL, *p = NULL;\r
506672c4 1461 uint32_t start_password = 0x00000000; //start password\r
1462 uint32_t end_password = 0xFFFFFFFF; //end password\r
1463 bool found = false;\r
6763dc17 1464 uint8_t downlink_mode = 0;\r
1465 bool try_all_dl_modes = false;\r
1466 uint8_t dl_mode = 0;\r
1467 uint8_t cmd_offset = 0;\r
1468 int cmd_opt = 0;\r
1469 \r
506672c4 1470 char cmdp = param_getchar(Cmd, 0);\r
6763dc17 1471 \r
506672c4 1472 if (cmdp == 'h' || cmdp == 'H') return usage_t55xx_bruteforce();\r
6763dc17 1473 if (cmdp == 'r' || cmdp == 'R') {\r
1474 downlink_mode = param_getchar(Cmd, 1) - '0'; // get 2nd option, as this is fixed order.\r
1475 if (downlink_mode == 4) try_all_dl_modes = true;\r
1476 if (downlink_mode > 3) downlink_mode = 0;\r
1477 cmd_opt += 2; // To help start/end passwords for range to be found\r
1478 cmd_offset += 4; // r <sp> x <sp> To help the string offset for filename start position in cmd\r
1479 cmdp = param_getchar(Cmd, 2); // get 3rd option, as this is fixed order.\r
1480 }\r
506672c4 1481\r
735136e6 1482 keyBlock = calloc(stKeyBlock, 6);\r
1483 if (keyBlock == NULL) return 1;\r
1484\r
506672c4 1485 if (cmdp == 'i' || cmdp == 'I') {\r
1486\r
1487 int len = strlen(Cmd+2);\r
1488 if (len > FILE_PATH_SIZE) len = FILE_PATH_SIZE;\r
6763dc17 1489 memcpy(filename, Cmd+2+cmd_offset, len);\r
506672c4 1490\r
1491 FILE * f = fopen( filename , "r");\r
1492\r
1493 if ( !f ) {\r
1494 PrintAndLog("File: %s: not found or locked.", filename);\r
1495 free(keyBlock);\r
1496 return 1;\r
1497 }\r
1498\r
5490c2d6 1499 while( fgets(buf, sizeof(buf), f) ) {\r
506672c4 1500 if (strlen(buf) < 8 || buf[7] == '\n') continue;\r
1501\r
1502 while (fgetc(f) != '\n' && !feof(f)) ; //goto next line\r
1503\r
1504 //The line start with # is comment, skip\r
1505 if( buf[0]=='#' ) continue;\r
1506\r
3ded0f97 1507 if (!isxdigit((unsigned char)buf[0])) {\r
506672c4 1508 PrintAndLog("File content error. '%s' must include 8 HEX symbols", buf);\r
1509 continue;\r
1510 }\r
1511 \r
1512 buf[8] = 0;\r
1513\r
1514 if ( stKeyBlock - keycnt < 2) {\r
1515 p = realloc(keyBlock, 6*(stKeyBlock+=10));\r
1516 if (!p) {\r
1517 PrintAndLog("Cannot allocate memory for defaultKeys");\r
1518 free(keyBlock);\r
735136e6 1519 fclose(f);\r
506672c4 1520 return 2;\r
1521 }\r
1522 keyBlock = p;\r
1523 }\r
1524 memset(keyBlock + 4 * keycnt, 0, 4);\r
1525 num_to_bytes(strtoll(buf, NULL, 16), 4, keyBlock + 4*keycnt);\r
1526 PrintAndLog("chk custom pwd[%2d] %08X", keycnt, bytes_to_num(keyBlock + 4*keycnt, 4));\r
1527 keycnt++;\r
1528 memset(buf, 0, sizeof(buf));\r
1529 }\r
1530 fclose(f);\r
1531 \r
1532 if (keycnt == 0) {\r
1533 PrintAndLog("No keys found in file");\r
735136e6 1534 free(keyBlock);\r
506672c4 1535 return 1;\r
1536 }\r
1537 PrintAndLog("Loaded %d keys", keycnt);\r
1538 \r
1539 // loop\r
1540 uint64_t testpwd = 0x00;\r
1541 for (uint16_t c = 0; c < keycnt; ++c ) {\r
1542\r
1543 if (ukbhit()) {\r
735136e6 1544 ch = getchar();\r
1545 (void)ch;\r
506672c4 1546 printf("\naborted via keyboard!\n");\r
735136e6 1547 free(keyBlock);\r
506672c4 1548 return 0;\r
1549 }\r
1550\r
1551 testpwd = bytes_to_num(keyBlock + 4*c, 4);\r
1552\r
1553 PrintAndLog("Testing %08X", testpwd);\r
6763dc17 1554 \r
1555 // Try each downlink_mode if asked to \r
1556 // donwlink_mode will = 0 if > 3 or set to 0, so loop from 0 - 3\r
1557 for (dl_mode = downlink_mode; dl_mode <= 3; dl_mode++){\r
1558 if ( !AquireData(T55x7_PAGE0, T55x7_CONFIGURATION_BLOCK, true, testpwd, dl_mode)) {\r
4be71814 1559 PrintAndLog("Acquiring data from device failed. Quitting");\r
6763dc17 1560 free(keyBlock);\r
1561 return 0;\r
1562 }\r
506672c4 1563\r
6763dc17 1564 found = tryDetectModulation();\r
506672c4 1565\r
6763dc17 1566 if ( found ) {\r
1567 PrintAndLog("Found valid password: [%08X]", testpwd);\r
1568 free(keyBlock);\r
4be71814 1569 \r
1570 T55xx_Print_DownlinkMode (dl_mode);\r
1571\r
6763dc17 1572 return 0;\r
1573 }\r
1574 if (!try_all_dl_modes) // Exit loop if not trying all downlink modes\r
1575 dl_mode = 4;\r
1576 } \r
506672c4 1577 }\r
1578 PrintAndLog("Password NOT found.");\r
735136e6 1579 free(keyBlock);\r
506672c4 1580 return 0;\r
1581 }\r
1582\r
1583 // Try to read Block 7, first :)\r
1584\r
1585 // incremental pwd range search\r
6763dc17 1586 start_password = param_get32ex(Cmd, cmd_opt , 0, 16);\r
1587 end_password = param_get32ex(Cmd, cmd_opt+1 , 0, 16);\r
5490c2d6 1588\r
735136e6 1589 if ( start_password >= end_password ) {\r
1590 free(keyBlock);\r
1591 return usage_t55xx_bruteforce();\r
1592 }\r
506672c4 1593 PrintAndLog("Search password range [%08X -> %08X]", start_password, end_password);\r
1594\r
1595 uint32_t i = start_password;\r
1596\r
5490c2d6 1597 while ((!found) && (i <= end_password)) {\r
506672c4 1598\r
5490c2d6 1599 printf(".");\r
1600 fflush(stdout);\r
1601 if (ukbhit()) {\r
735136e6 1602 ch = getchar();\r
1603 (void)ch;\r
5490c2d6 1604 printf("\naborted via keyboard!\n");\r
735136e6 1605 free(keyBlock);\r
5490c2d6 1606 return 0;\r
1607 }\r
6763dc17 1608 // Try each downlink_mode if asked to \r
1609 // donwlink_mode will = 0 if > 3 or set to 0, so loop from 0 - 3\r
1610 for (dl_mode = downlink_mode; dl_mode <= 3; dl_mode++){\r
1611 if (!AquireData(T55x7_PAGE0, T55x7_CONFIGURATION_BLOCK, true, i,dl_mode)) {\r
4be71814 1612 PrintAndLog("Acquiring data from device failed. Quitting");\r
dd8e4513 1613 free(keyBlock);\r
1614 return 0;\r
1615 }\r
1616 found = tryDetectModulation();\r
1617\r
1618 if (found) break;\r
6763dc17 1619 if (!try_all_dl_modes) // Exit loop if not trying all downlink modes\r
1620 dl_mode = 4; \r
dd8e4513 1621 }\r
6763dc17 1622 if (found) break;\r
1623 i++;\r
1624 }\r
dd8e4513 1625\r
6763dc17 1626 if (found){\r
1627 PrintAndLog("Found valid password: [%08x]", i);\r
4be71814 1628 T55xx_Print_DownlinkMode (downlink_mode);\r
dd8e4513 1629 }\r
6763dc17 1630 else{\r
1631 PrintAndLog("");\r
1632 PrintAndLog("Password NOT found. Last tried: [%08x]", --i);\r
1633 }\r
1634\r
1635 free(keyBlock);\r
dd8e4513 1636 return 0;\r
1637}\r
b97311b1 1638// note length of data returned is different for different chips. \r
1639// some return all page 1 (64 bits) and others return just that block (32 bits) \r
1640// unfortunately the 64 bits makes this more likely to get a false positive...\r
1641bool tryDetectP1(bool getData) {\r
1642 uint8_t preamble[] = {1,1,1,0,0,0,0,0,0,0,0,1,0,1,0,1};\r
1643 size_t startIdx = 0;\r
1644 uint8_t fc1 = 0, fc2 = 0, ans = 0;\r
bb4e6dbd 1645 int clk = 0, firstClockEdge = 0;\r
b97311b1 1646 bool st = true;\r
1647\r
1648 if ( getData ) {\r
dd8e4513 1649 if ( !AquireData(T55x7_PAGE1, 1, false, 0,0) )\r
b97311b1 1650 return false;\r
1651 }\r
1652\r
1653 // try fsk clock detect. if successful it cannot be any other type of modulation... (in theory...)\r
bb4e6dbd 1654 ans = fskClocks(&fc1, &fc2, (uint8_t *)&clk, false, &firstClockEdge);\r
b97311b1 1655 if (ans && ((fc1==10 && fc2==8) || (fc1==8 && fc2==5))) {\r
1656 if ( FSKrawDemod("0 0", false) && \r
1657 preambleSearchEx(DemodBuffer,preamble,sizeof(preamble),&DemodBufferLen,&startIdx,false) && \r
1658 (DemodBufferLen == 32 || DemodBufferLen == 64) ) {\r
1659 return true;\r
1660 }\r
1661 if ( FSKrawDemod("0 1", false) && \r
1662 preambleSearchEx(DemodBuffer,preamble,sizeof(preamble),&DemodBufferLen,&startIdx,false) && \r
1663 (DemodBufferLen == 32 || DemodBufferLen == 64) ) {\r
1664 return true;\r
1665 }\r
1666 return false;\r
1667 }\r
1668\r
1669 // try psk clock detect. if successful it cannot be any other type of modulation... (in theory...)\r
1670 clk = GetPskClock("", false, false);\r
1671 if (clk>0) {\r
1672 // allow undo\r
1673 // save_restoreGB(1);\r
1674 // skip first 160 samples to allow antenna to settle in (psk gets inverted occasionally otherwise)\r
1675 //CmdLtrim("160");\r
1676 if ( PSKDemod("0 0 6", false) &&\r
1677 preambleSearchEx(DemodBuffer,preamble,sizeof(preamble),&DemodBufferLen,&startIdx,false) && \r
1678 (DemodBufferLen == 32 || DemodBufferLen == 64) ) {\r
1679 //save_restoreGB(0);\r
1680 return true;\r
1681 }\r
1682 if ( PSKDemod("0 1 6", false) &&\r
1683 preambleSearchEx(DemodBuffer,preamble,sizeof(preamble),&DemodBufferLen,&startIdx,false) && \r
1684 (DemodBufferLen == 32 || DemodBufferLen == 64) ) {\r
1685 //save_restoreGB(0);\r
1686 return true;\r
1687 }\r
1688 // PSK2 - needs a call to psk1TOpsk2.\r
1689 if ( PSKDemod("0 0 6", false)) {\r
1690 psk1TOpsk2(DemodBuffer, DemodBufferLen);\r
1691 if (preambleSearchEx(DemodBuffer,preamble,sizeof(preamble),&DemodBufferLen,&startIdx,false) && \r
1692 (DemodBufferLen == 32 || DemodBufferLen == 64) ) {\r
1693 //save_restoreGB(0);\r
1694 return true;\r
1695 }\r
1696 } // inverse waves does not affect PSK2 demod\r
1697 //undo trim samples\r
1698 //save_restoreGB(0); \r
1699 // no other modulation clocks = 2 or 4 so quit searching\r
1700 if (fc1 != 8) return false;\r
1701 }\r
1702\r
1703 // try ask clock detect. it could be another type even if successful.\r
1704 clk = GetAskClock("", false, false);\r
1705 if (clk>0) {\r
1706 if ( ASKDemod_ext("0 0 1", false, false, 1, &st) &&\r
1707 preambleSearchEx(DemodBuffer,preamble,sizeof(preamble),&DemodBufferLen,&startIdx,false) && \r
1708 (DemodBufferLen == 32 || DemodBufferLen == 64) ) {\r
1709 return true;\r
1710 }\r
1711 st = true;\r
1712 if ( ASKDemod_ext("0 1 1", false, false, 1, &st) &&\r
1713 preambleSearchEx(DemodBuffer,preamble,sizeof(preamble),&DemodBufferLen,&startIdx,false) && \r
1714 (DemodBufferLen == 32 || DemodBufferLen == 64) ) {\r
1715 return true;\r
1716 }\r
1717 if ( ASKbiphaseDemod("0 0 0 2", false) &&\r
1718 preambleSearchEx(DemodBuffer,preamble,sizeof(preamble),&DemodBufferLen,&startIdx,false) && \r
1719 (DemodBufferLen == 32 || DemodBufferLen == 64) ) {\r
1720 return true;\r
1721 }\r
1722 if ( ASKbiphaseDemod("0 0 1 2", false) &&\r
1723 preambleSearchEx(DemodBuffer,preamble,sizeof(preamble),&DemodBufferLen,&startIdx,false) && \r
1724 (DemodBufferLen == 32 || DemodBufferLen == 64) ) {\r
1725 return true;\r
1726 }\r
1727 }\r
1728\r
1729 // try NRZ clock detect. it could be another type even if successful.\r
1730 clk = GetNrzClock("", false, false); //has the most false positives :(\r
1731 if (clk>0) {\r
1732 if ( NRZrawDemod("0 0 1", false) &&\r
1733 preambleSearchEx(DemodBuffer,preamble,sizeof(preamble),&DemodBufferLen,&startIdx,false) && \r
1734 (DemodBufferLen == 32 || DemodBufferLen == 64) ) {\r
1735 return true;\r
1736 }\r
1737 if ( NRZrawDemod("0 1 1", false) &&\r
1738 preambleSearchEx(DemodBuffer,preamble,sizeof(preamble),&DemodBufferLen,&startIdx,false) && \r
1739 (DemodBufferLen == 32 || DemodBufferLen == 64) ) {\r
1740 return true;\r
1741 }\r
1742 }\r
1743 return false;\r
1744}\r
1745// does this need to be a callable command?\r
1746int CmdT55xxDetectPage1(const char *Cmd){\r
1747 bool errors = false;\r
1748 bool useGB = false;\r
1749 bool usepwd = false;\r
1750 uint32_t password = 0;\r
1751 uint8_t cmdp = 0;\r
1752\r
1753 while(param_getchar(Cmd, cmdp) != 0x00 && !errors) {\r
1754 switch(param_getchar(Cmd, cmdp)) {\r
1755 case 'h':\r
1756 case 'H':\r
1757 return usage_t55xx_detectP1();\r
1758 case 'p':\r
1759 case 'P':\r
1760 password = param_get32ex(Cmd, cmdp+1, 0, 16);\r
1761 usepwd = true;\r
1762 cmdp += 2;\r
1763 break;\r
1764 case '1':\r
1765 // use Graphbuffer data\r
1766 useGB = true;\r
1767 cmdp++;\r
1768 break;\r
1769 default:\r
1770 PrintAndLog("Unknown parameter '%c'", param_getchar(Cmd, cmdp));\r
1771 errors = true;\r
1772 break;\r
1773 }\r
1774 }\r
1775 if (errors) return usage_t55xx_detectP1();\r
1776\r
1777 if ( !useGB ) {\r
dd8e4513 1778 if ( !AquireData(T55x7_PAGE1, 1, usepwd, password,0) )\r
b97311b1 1779 return false;\r
1780 }\r
1781 bool success = tryDetectP1(false);\r
1782 if (success) PrintAndLog("T55xx chip found!");\r
1783 return success;\r
1784}\r
1785\r
709665b5 1786static command_t CommandTable[] = {\r
506672c4 1787 {"help", CmdHelp, 1, "This help"},\r
dd8e4513 1788 {"bruteforce",CmdT55xxBruteForce,0, "<start password> <end password> [i <*.dic>] Simple bruteforce attack to find password"},\r
506672c4 1789 {"config", CmdT55xxSetConfig, 1, "Set/Get T55XX configuration (modulation, inverted, offset, rate)"},\r
1790 {"detect", CmdT55xxDetect, 1, "[1] Try detecting the tag modulation from reading the configuration block."},\r
b97311b1 1791 {"p1detect", CmdT55xxDetectPage1,1, "[1] Try detecting if this is a t55xx tag by reading page 1"},\r
506672c4 1792 {"read", CmdT55xxReadBlock, 0, "b <block> p [password] [o] [1] -- Read T55xx block data. Optional [p password], [override], [page1]"},\r
1793 {"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
1794 {"write", CmdT55xxWriteBlock,0, "b <block> d <data> p [password] [1] -- Write T55xx block data. Optional [p password], [page1]"},\r
1795 {"trace", CmdT55xxReadTrace, 1, "[1] Show T55x7 traceability data (page 1/ blk 0-1)"},\r
1796 {"info", CmdT55xxInfo, 1, "[1] Show T55x7 configuration data (page 0/ blk 0)"},\r
1797 {"dump", CmdT55xxDump, 0, "[password] [o] Dump T55xx card block 0-7. Optional [password], [override]"},\r
1798 {"special", special, 0, "Show block changes with 64 different offsets"},\r
1799 {"wakeup", CmdT55xxWakeUp, 0, "Send AOR wakeup command"},\r
5490c2d6 1800 {"wipe", CmdT55xxWipe, 0, "[q] Wipe a T55xx tag and set defaults (will destroy any data on tag)"},\r
54a942b0 1801 {NULL, NULL, 0, NULL}\r
1802};\r
1803\r
709665b5 1804int CmdLFT55XX(const char *Cmd) {\r
54a942b0 1805 CmdsParse(CommandTable, Cmd);\r
1806 return 0;\r
1807}\r
1808\r
709665b5 1809int CmdHelp(const char *Cmd) {\r
54a942b0 1810 CmdsHelp(CommandTable);\r
1811 return 0;\r
1812}\r
Impressum, Datenschutz