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