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