]>
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 "proxmark3.h"\r | |
14 | #include "ui.h"\r | |
15 | #include "graph.h"\r | |
16 | #include "cmdmain.h"\r | |
17 | #include "cmdparser.h"\r | |
18 | #include "cmddata.h"\r | |
19 | #include "cmdlf.h"\r | |
20 | #include "cmdlft55xx.h"\r | |
21 | #include "util.h"\r | |
22 | #include "data.h"\r | |
23 | #include "lfdemod.h"\r | |
24 | #include "../common/crc.h"\r | |
25 | \r | |
26 | #define LF_TRACE_BUFF_SIZE 20000 // 32 x 32 x 10 (32 bit times numofblock (7), times clock skip..)\r | |
27 | #define LF_BITSSTREAM_LEN 1000 // more then 1000 bits shouldn't happend.. 8block * 4 bytes * 8bits = \r | |
28 | \r | |
29 | // 0 = FSK\r | |
30 | // 1 = ASK\r | |
31 | // 2 = PSK\r | |
32 | // 4 = NZR (direct)\r | |
33 | typedef struct {\r | |
34 | uint8_t modulation;\r | |
35 | bool inversed;\r | |
36 | uint32_t block0;\r | |
37 | } t55xx_conf_block_t;\r | |
38 | \r | |
39 | // Default configuration: FSK, not inversed.\r | |
40 | t55xx_conf_block_t config = { .modulation = 2, .inversed = FALSE, .block0 = 0x00};\r | |
41 | \r | |
42 | int usage_t55xx_config(){\r | |
43 | PrintAndLog("Usage: lf t55xx config [d <demodulation>] [i 1]");\r | |
44 | PrintAndLog("Options: ");\r | |
45 | PrintAndLog(" h This help");\r | |
46 | PrintAndLog(" d <FSK|ASK|PSK|NZ|BI> Set demodulation FSK / ASK / PSK / NZ / Biphase");\r | |
47 | PrintAndLog(" i [1] Inverse data signal, defaults to normal");\r | |
48 | PrintAndLog("");\r | |
49 | PrintAndLog("Examples:");\r | |
50 | PrintAndLog(" lf t55xx config d FSK - FSK demodulation");\r | |
51 | PrintAndLog(" lf t55xx config d FSK i 1 - FSK demodulation, inverse data");\r | |
52 | PrintAndLog("");\r | |
53 | return 0;\r | |
54 | }\r | |
55 | int usage_t55xx_read(){\r | |
56 | PrintAndLog("Usage: lf t55xx read <block> <password>");\r | |
57 | PrintAndLog(" <block>, block number to read. Between 0-7");\r | |
58 | PrintAndLog(" <password>, OPTIONAL password (8 hex characters)");\r | |
59 | PrintAndLog("");\r | |
60 | PrintAndLog("Examples:");\r | |
61 | PrintAndLog(" lf t55xx read 0 - read data from block 0");\r | |
62 | PrintAndLog(" lf t55xx read 0 feedbeef - read data from block 0 password feedbeef");\r | |
63 | PrintAndLog("");\r | |
64 | return 0;\r | |
65 | }\r | |
66 | int usage_t55xx_write(){\r | |
67 | PrintAndLog("Usage: lf t55xx wr <block> <data> [password]");\r | |
68 | PrintAndLog(" <block>, block number to read. Between 0-7");\r | |
69 | PrintAndLog(" <data>, 4 bytes of data to write (8 hex characters)");\r | |
70 | PrintAndLog(" [password], OPTIONAL password 4bytes (8 hex characters)");\r | |
71 | PrintAndLog("");\r | |
72 | PrintAndLog("Examples:");\r | |
73 | PrintAndLog(" lf t55xx wd 3 11223344 - write 11223344 to block 3");\r | |
74 | PrintAndLog(" lf t55xx wd 3 11223344 feedbeef - write 11223344 to block 3 password feedbeef");\r | |
75 | PrintAndLog("");\r | |
76 | return 0;\r | |
77 | }\r | |
78 | int usage_t55xx_trace() {\r | |
79 | PrintAndLog("Usage: lf t55xx trace [1]");\r | |
80 | PrintAndLog(" [graph buffer data], if set, use Graphbuffer otherwise read data from tag.");\r | |
81 | PrintAndLog("");\r | |
82 | PrintAndLog("Examples:");\r | |
83 | PrintAndLog(" lf t55xx trace");\r | |
84 | PrintAndLog(" lf t55xx trace 1");\r | |
85 | PrintAndLog("");\r | |
86 | return 0;\r | |
87 | }\r | |
88 | int usage_t55xx_info() {\r | |
89 | PrintAndLog("Usage: lf t55xx info [1]");\r | |
90 | PrintAndLog(" [graph buffer data], if set, use Graphbuffer otherwise read data from tag.");\r | |
91 | PrintAndLog("");\r | |
92 | PrintAndLog("Examples:");\r | |
93 | PrintAndLog(" lf t55xx info");\r | |
94 | PrintAndLog(" lf t55xx info 1");\r | |
95 | PrintAndLog("");\r | |
96 | return 0;\r | |
97 | }\r | |
98 | int usage_t55xx_dump(){\r | |
99 | PrintAndLog("Usage: lf t55xx dump <password>");\r | |
100 | PrintAndLog(" <password>, OPTIONAL password 4bytes (8 hex symbols)");\r | |
101 | PrintAndLog("");\r | |
102 | PrintAndLog("Examples:");\r | |
103 | PrintAndLog(" lf t55xx dump");\r | |
104 | PrintAndLog(" lf t55xx dump feedbeef");\r | |
105 | PrintAndLog("");\r | |
106 | return 0;\r | |
107 | }\r | |
108 | int usage_t55xx_detect(){\r | |
109 | PrintAndLog("Usage: lf t55xx detect");\r | |
110 | PrintAndLog("");\r | |
111 | PrintAndLog("Examples:");\r | |
112 | PrintAndLog(" lf t55xx detect");\r | |
113 | PrintAndLog(" lf t55xx detect 1");\r | |
114 | PrintAndLog("");\r | |
115 | return 0;\r | |
116 | }\r | |
117 | \r | |
118 | static int CmdHelp(const char *Cmd);\r | |
119 | \r | |
120 | int CmdT55xxSetConfig(const char *Cmd){\r | |
121 | \r | |
122 | int len;\r | |
123 | bool inverse;\r | |
124 | bool errors = FALSE;\r | |
125 | uint8_t cmdp = 0;\r | |
126 | char modulation[4] = {0x00};\r | |
127 | \r | |
128 | while(param_getchar(Cmd, cmdp) != 0x00 && !errors)\r | |
129 | {\r | |
130 | switch(param_getchar(Cmd, cmdp))\r | |
131 | {\r | |
132 | case 'h':\r | |
133 | case 'H':\r | |
134 | return usage_t55xx_config();\r | |
135 | case 'd':\r | |
136 | len = param_getstr(Cmd, cmdp+1, modulation);\r | |
137 | cmdp+= len+1;\r | |
138 | //FSK|ASK|PSK|NZ|BI\r | |
139 | if ( strcmp(modulation, "FSK" ) == 0)\r | |
140 | len = 1;\r | |
141 | else if ( strcmp(modulation, "ASK" ) == 0)\r | |
142 | len = 2;\r | |
143 | else if ( strcmp(modulation, "PSK" ) == 0)\r | |
144 | len = 3;\r | |
145 | else if ( strcmp(modulation, "NZ" ) == 0)\r | |
146 | len = 4;\r | |
147 | else if ( strcmp(modulation, "BI" ) == 0)\r | |
148 | len = 5;\r | |
149 | else {\r | |
150 | PrintAndLog("Unknown modulation '%s'", modulation);\r | |
151 | errors = TRUE;\r | |
152 | }\r | |
153 | break;\r | |
154 | case 'i':\r | |
155 | inverse = param_getchar(Cmd,cmdp+1) == '1';\r | |
156 | cmdp+=2;\r | |
157 | break;\r | |
158 | default:\r | |
159 | PrintAndLog("Unknown parameter '%c'", param_getchar(Cmd, cmdp));\r | |
160 | errors = TRUE;\r | |
161 | break;\r | |
162 | }\r | |
163 | }\r | |
164 | // No args\r | |
165 | if (cmdp == 0) {\r | |
166 | PrintAndLog("Modulation: %d", config.modulation);\r | |
167 | PrintAndLog("Invert : %d", config.inversed);\r | |
168 | PrintAndLog("Block0 : %08X", config.block0);\r | |
169 | return 0;\r | |
170 | }\r | |
171 | //Validations\r | |
172 | if (errors)\r | |
173 | return usage_t55xx_config();\r | |
174 | \r | |
175 | config.modulation = len;\r | |
176 | config.inversed = inverse;\r | |
177 | config.block0 = 0;\r | |
178 | return 0;\r | |
179 | }\r | |
180 | \r | |
181 | int CmdT55xxReadBlock(const char *Cmd)\r | |
182 | {\r | |
183 | int block = -1;\r | |
184 | int password = 0xFFFFFFFF; //default to blank Block 7\r | |
185 | \r | |
186 | char cmdp = param_getchar(Cmd, 0);\r | |
187 | if (cmdp == 'h' || cmdp == 'H')\r | |
188 | return usage_t55xx_read();\r | |
189 | \r | |
190 | int res = sscanf(Cmd, "%d %x", &block, &password);\r | |
191 | \r | |
192 | if ( res < 1 || res > 2 )\r | |
193 | return usage_t55xx_read();\r | |
194 | \r | |
195 | \r | |
196 | if ((block < 0) | (block > 7)) {\r | |
197 | PrintAndLog("Block must be between 0 and 7");\r | |
198 | return 1;\r | |
199 | } \r | |
200 | \r | |
201 | UsbCommand c = {CMD_T55XX_READ_BLOCK, {0, block, 0}};\r | |
202 | c.d.asBytes[0] = 0x0; \r | |
203 | \r | |
204 | //Password mode\r | |
205 | if ( res == 2 ) {\r | |
206 | c.arg[2] = password;\r | |
207 | c.d.asBytes[0] = 0x1; \r | |
208 | }\r | |
209 | \r | |
210 | SendCommand(&c);\r | |
211 | if ( !WaitForResponseTimeout(CMD_ACK,NULL,2500) ) {\r | |
212 | PrintAndLog("command execution time out");\r | |
213 | return 2;\r | |
214 | }\r | |
215 | \r | |
216 | uint8_t got[12000];\r | |
217 | GetFromBigBuf(got,sizeof(got),0);\r | |
218 | WaitForResponse(CMD_ACK,NULL);\r | |
219 | setGraphBuf(got, 12000);\r | |
220 | \r | |
221 | DecodeT55xxBlock();\r | |
222 | printT55xxBlock("");\r | |
223 | return 0;\r | |
224 | }\r | |
225 | \r | |
226 | void DecodeT55xxBlock(){\r | |
227 | \r | |
228 | char buf[6] = {0x00};\r | |
229 | char *cmdStr = buf;\r | |
230 | \r | |
231 | // use the configuration\r | |
232 | switch( config.modulation ){\r | |
233 | case 1:\r | |
234 | sprintf(cmdStr,"0 %d", config.inversed );\r | |
235 | FSKrawDemod(cmdStr, FALSE);\r | |
236 | break;\r | |
237 | case 2:\r | |
238 | sprintf(cmdStr,"0 %d 1", config.inversed );\r | |
239 | ASKmanDemod(cmdStr, FALSE, FALSE);\r | |
240 | PrintAndLog("ice");\r | |
241 | break;\r | |
242 | case 3:\r | |
243 | sprintf(cmdStr,"0 %d 1", config.inversed );\r | |
244 | PSKDemod(cmdStr, FALSE);\r | |
245 | break;\r | |
246 | case 4:\r | |
247 | sprintf(cmdStr,"0 %d 1", config.inversed );\r | |
248 | NRZrawDemod(cmdStr, FALSE);\r | |
249 | break;\r | |
250 | case 5:\r | |
251 | //BiphaseRawDecode("0",FALSE);\r | |
252 | break;\r | |
253 | default:\r | |
254 | return;\r | |
255 | }\r | |
256 | }\r | |
257 | \r | |
258 | int CmdT55xxDetect(const char *Cmd){\r | |
259 | char cmdp = param_getchar(Cmd, 0);\r | |
260 | if (cmdp == 'h' || cmdp == 'H')\r | |
261 | return usage_t55xx_detect();\r | |
262 | \r | |
263 | // read block 0, Page 0. Configuration.\r | |
264 | UsbCommand c = {CMD_T55XX_READ_BLOCK, {0, 0, 0}};\r | |
265 | c.d.asBytes[0] = 0x0; \r | |
266 | \r | |
267 | //Password mode\r | |
268 | // if ( res == 2 ) {\r | |
269 | // c.arg[2] = password;\r | |
270 | // c.d.asBytes[0] = 0x1; \r | |
271 | // }\r | |
272 | \r | |
273 | SendCommand(&c);\r | |
274 | if ( !WaitForResponseTimeout(CMD_ACK,NULL,2500) ) {\r | |
275 | PrintAndLog("command execution time out");\r | |
276 | return FALSE;\r | |
277 | }\r | |
278 | \r | |
279 | uint8_t got[12000];\r | |
280 | GetFromBigBuf(got,sizeof(got),0);\r | |
281 | WaitForResponse(CMD_ACK,NULL);\r | |
282 | setGraphBuf(got, 12000);\r | |
283 | \r | |
284 | if ( !tryDetectModulation() ){\r | |
285 | PrintAndLog("Could not detect modulation automatically. Try setting it manually with \'lf t55xx config\'");\r | |
286 | }\r | |
287 | return 0;\r | |
288 | }\r | |
289 | \r | |
290 | // detect configuration?\r | |
291 | bool tryDetectModulation(){\r | |
292 | \r | |
293 | uint8_t hits = 0;\r | |
294 | t55xx_conf_block_t tests[10];\r | |
295 | \r | |
296 | if (GetFskClock("", FALSE, FALSE)){ \r | |
297 | if ( FSKrawDemod("0 0", FALSE) && test()){\r | |
298 | tests[hits].modulation = 1;\r | |
299 | tests[hits].inversed = 0;\r | |
300 | ++hits;\r | |
301 | }\r | |
302 | if ( FSKrawDemod("0 1", FALSE) && test()) {\r | |
303 | tests[hits].modulation = 1;\r | |
304 | tests[hits].inversed = 1;\r | |
305 | ++hits;\r | |
306 | }\r | |
307 | } else {\r | |
308 | if ( ASKmanDemod("0 0 1", FALSE, FALSE) && test()) {\r | |
309 | tests[hits].modulation = 2;\r | |
310 | tests[hits].inversed = 0;\r | |
311 | ++hits;\r | |
312 | }\r | |
313 | \r | |
314 | if ( ASKmanDemod("0 1 1", FALSE, FALSE) && test()) {\r | |
315 | tests[hits].modulation = 2;\r | |
316 | tests[hits].inversed = 1;\r | |
317 | ++hits;\r | |
318 | }\r | |
319 | \r | |
320 | if ( NRZrawDemod("0 0 1", FALSE) && test()) {\r | |
321 | tests[hits].modulation = 3;\r | |
322 | tests[hits].inversed = 0;\r | |
323 | ++hits;\r | |
324 | }\r | |
325 | \r | |
326 | if ( NRZrawDemod("0 1 1", FALSE) && test()) {\r | |
327 | tests[hits].modulation = 3;\r | |
328 | tests[hits].inversed = 1;\r | |
329 | ++hits;\r | |
330 | }\r | |
331 | \r | |
332 | if ( PSKDemod("0 0 1", FALSE) && test()) {\r | |
333 | tests[hits].modulation = 4;\r | |
334 | tests[hits].inversed = 0;\r | |
335 | ++hits;\r | |
336 | }\r | |
337 | \r | |
338 | if ( PSKDemod("0 1 1", FALSE) && test()) {\r | |
339 | tests[++hits].modulation = 4;\r | |
340 | tests[hits].inversed = 1;\r | |
341 | ++hits;\r | |
342 | }\r | |
343 | //PSK2?\r | |
344 | // if (!BiphaseRawDecode("0",FALSE) && test()) {\r | |
345 | // tests[++hits].modulation = 5;\r | |
346 | // tests[hits].inversed = 0;\r | |
347 | //}\r | |
348 | // if (!BiphaseRawDecode("1",FALSE) && test()) {\r | |
349 | // tests[++hits].modulation = 5;\r | |
350 | // tests[hits].inversed = 1;\r | |
351 | // }\r | |
352 | } \r | |
353 | if ( hits == 1) {\r | |
354 | PrintAndLog("Modulation: %d Inverse: %d", tests[0].modulation, tests[0].inversed);\r | |
355 | config.modulation = tests[0].modulation;\r | |
356 | config.inversed = tests[0].inversed;\r | |
357 | return TRUE;\r | |
358 | }\r | |
359 | \r | |
360 | if ( hits > 1) {\r | |
361 | PrintAndLog("Found [%d] possible matches for modulation.",hits);\r | |
362 | for(int i=0; i<hits; ++i){\r | |
363 | PrintAndLog("Modulation: %d Inverse: %d", tests[i].modulation, tests[i].inversed);\r | |
364 | }\r | |
365 | }\r | |
366 | return FALSE;\r | |
367 | }\r | |
368 | \r | |
369 | bool test(){\r | |
370 | \r | |
371 | if ( !DemodBufferLen) \r | |
372 | return false;\r | |
373 | \r | |
374 | uint8_t si = 1;\r | |
375 | uint8_t safer = PackBits(si, 4, DemodBuffer); si += 4; \r | |
376 | uint8_t resv = PackBits(si, 7, DemodBuffer); si += 7+3;\r | |
377 | uint8_t extend = PackBits(si, 1, DemodBuffer); si += 1;\r | |
378 | \r | |
379 | //PrintAndLog("test: %X %X %X ", safer, resv, extend);\r | |
380 | \r | |
381 | // 2nibble must be zeroed.\r | |
382 | if ( resv > 0x00) return FALSE;\r | |
383 | \r | |
384 | if ( safer == 0x6 || safer == 0x9){\r | |
385 | if ( extend == 0x00)\r | |
386 | return TRUE;\r | |
387 | }\r | |
388 | if ( resv== 0x00) return TRUE;\r | |
389 | return FALSE;\r | |
390 | }\r | |
391 | \r | |
392 | void printT55xxBlock(const char *demodStr){\r | |
393 | \r | |
394 | uint32_t blockData = 0;\r | |
395 | uint8_t bits[MAX_GRAPH_TRACE_LEN] = {0x00};\r | |
396 | \r | |
397 | if ( !DemodBufferLen) \r | |
398 | return;\r | |
399 | \r | |
400 | int i =0;\r | |
401 | for (;i<DemodBufferLen;++i)\r | |
402 | bits[i]=DemodBuffer[i];\r | |
403 | \r | |
404 | blockData = PackBits(1, 32, bits);\r | |
405 | PrintAndLog("0x%08X %s [%s]", blockData, sprint_bin(bits+1,32), demodStr);\r | |
406 | }\r | |
407 | \r | |
408 | /*\r | |
409 | FSK1 / FSK1a\r | |
410 | size = fskdemod(dest, size, 32, 0, 8, 10); // fsk1 RF/32 \r | |
411 | size = fskdemod(dest, size, 32, 1, 8, 10); // fsk1a RF/32 \r | |
412 | \r | |
413 | FSK2 / FSK2a\r | |
414 | size = fskdemod(dest, size, 32, 0, 10, 8); // fsk2 RF/32 \r | |
415 | size = fskdemod(dest, size, 32, 1, 10, 8); // fsk2a RF/32 \r | |
416 | size = fskdemod(dest, size, 50, 1, 10, 8); // fsk2a RF/50 \r | |
417 | size = fskdemod(dest, size, 64, 1, 10, 8); // FSK2a RF/64 \r | |
418 | \r | |
419 | PSK1\r | |
420 | errCnt = pskRawDemod(bits, &bitlen, 32, 0);\r | |
421 | */\r | |
422 | int CmdT55xxWriteBlock(const char *Cmd)\r | |
423 | {\r | |
424 | int block = 8; //default to invalid block\r | |
425 | int data = 0xFFFFFFFF; //default to blank Block \r | |
426 | int password = 0xFFFFFFFF; //default to blank Block 7\r | |
427 | \r | |
428 | char cmdp = param_getchar(Cmd, 0);\r | |
429 | if (cmdp == 'h' || cmdp == 'H') {\r | |
430 | usage_t55xx_write();\r | |
431 | return 0;\r | |
432 | }\r | |
433 | \r | |
434 | int res = sscanf(Cmd, "%d %x %x",&block, &data, &password);\r | |
435 | \r | |
436 | if ( res < 2 || res > 3) {\r | |
437 | usage_t55xx_write();\r | |
438 | return 1;\r | |
439 | }\r | |
440 | \r | |
441 | if (block > 7) {\r | |
442 | PrintAndLog("Block must be between 0 and 7");\r | |
443 | return 1;\r | |
444 | }\r | |
445 | \r | |
446 | UsbCommand c = {CMD_T55XX_WRITE_BLOCK, {data, block, 0}};\r | |
447 | c.d.asBytes[0] = 0x0; \r | |
448 | \r | |
449 | PrintAndLog("Writing to T55x7");\r | |
450 | PrintAndLog("block : %d", block);\r | |
451 | PrintAndLog("data : 0x%08X", data);\r | |
452 | \r | |
453 | //Password mode\r | |
454 | if (res == 3) {\r | |
455 | c.arg[2] = password;\r | |
456 | c.d.asBytes[0] = 0x1; \r | |
457 | PrintAndLog("pwd : 0x%08X", password);\r | |
458 | }\r | |
459 | SendCommand(&c);\r | |
460 | return 0;\r | |
461 | }\r | |
462 | \r | |
463 | int CmdT55xxReadTrace(const char *Cmd)\r | |
464 | {\r | |
465 | char cmdp = param_getchar(Cmd, 0);\r | |
466 | \r | |
467 | if (strlen(Cmd) > 1 || cmdp == 'h' || cmdp == 'H') \r | |
468 | return usage_t55xx_trace();\r | |
469 | \r | |
470 | if ( strlen(Cmd)==0){\r | |
471 | \r | |
472 | UsbCommand c = {CMD_T55XX_READ_TRACE, {0, 0, 0}};\r | |
473 | SendCommand(&c);\r | |
474 | if ( !WaitForResponseTimeout(CMD_ACK,NULL,2500) ) {\r | |
475 | PrintAndLog("command execution time out");\r | |
476 | return 1;\r | |
477 | }\r | |
478 | \r | |
479 | uint8_t got[12000];\r | |
480 | GetFromBigBuf(got,sizeof(got),0);\r | |
481 | WaitForResponse(CMD_ACK,NULL);\r | |
482 | setGraphBuf(got, 12000);\r | |
483 | }\r | |
484 | \r | |
485 | DecodeT55xxBlock();\r | |
486 | \r | |
487 | if ( !DemodBufferLen) \r | |
488 | return 2;\r | |
489 | \r | |
490 | RepaintGraphWindow();\r | |
491 | \r | |
492 | uint8_t si = 5;\r | |
493 | uint32_t bl0 = PackBits(si, 32, DemodBuffer);\r | |
494 | uint32_t bl1 = PackBits(si+32, 32, DemodBuffer);\r | |
495 | \r | |
496 | uint32_t acl = PackBits(si, 8, DemodBuffer); si += 8;\r | |
497 | uint32_t mfc = PackBits(si, 8, DemodBuffer); si += 8;\r | |
498 | uint32_t cid = PackBits(si, 5, DemodBuffer); si += 5;\r | |
499 | uint32_t icr = PackBits(si, 3, DemodBuffer); si += 3;\r | |
500 | uint32_t year = PackBits(si, 4, DemodBuffer); si += 4;\r | |
501 | uint32_t quarter = PackBits(si, 2, DemodBuffer); si += 2;\r | |
502 | uint32_t lotid = PackBits(si, 12, DemodBuffer); si += 12;\r | |
503 | uint32_t wafer = PackBits(si, 5, DemodBuffer); si += 5;\r | |
504 | uint32_t dw = PackBits(si, 15, DemodBuffer); \r | |
505 | \r | |
506 | year += 2000;\r | |
507 | \r | |
508 | PrintAndLog("");\r | |
509 | PrintAndLog("-- T55xx Trace Information ----------------------------------");\r | |
510 | PrintAndLog("-------------------------------------------------------------");\r | |
511 | PrintAndLog(" ACL Allocation class (ISO/IEC 15963-1) : 0x%02X (%d)", acl, acl);\r | |
512 | PrintAndLog(" MFC Manufacturer ID (ISO/IEC 7816-6) : 0x%02X (%d)", mfc, mfc);\r | |
513 | PrintAndLog(" CID : 0x%02X (%d)", cid, cid);\r | |
514 | PrintAndLog(" ICR IC Revision : %d",icr );\r | |
515 | PrintAndLog(" Manufactured");\r | |
516 | PrintAndLog(" Year/Quarter : %d/%d",year, quarter );\r | |
517 | PrintAndLog(" Lot ID : %d", lotid );\r | |
518 | PrintAndLog(" Wafer number : %d", wafer);\r | |
519 | PrintAndLog(" Die Number : %d", dw);\r | |
520 | PrintAndLog("-------------------------------------------------------------");\r | |
521 | PrintAndLog(" Raw Data - Page 1");\r | |
522 | PrintAndLog(" Block 0 : 0x%08X %s", bl0, sprint_bin(DemodBuffer+5,32) );\r | |
523 | PrintAndLog(" Block 0 : 0x%08X %s", bl1, sprint_bin(DemodBuffer+37,32) );\r | |
524 | PrintAndLog("-------------------------------------------------------------");\r | |
525 | /*\r | |
526 | TRACE - BLOCK O\r | |
527 | Bits Definition HEX\r | |
528 | 1-8 ACL Allocation class (ISO/IEC 15963-1) 0xE0 \r | |
529 | 9-16 MFC Manufacturer ID (ISO/IEC 7816-6) 0x15 Atmel Corporation\r | |
530 | 17-21 CID 0x1 = Atmel ATA5577M1 0x2 = Atmel ATA5577M2 \r | |
531 | 22-24 ICR IC revision\r | |
532 | 25-28 YEAR (BCD encoded) 9 (= 2009)\r | |
533 | 29-30 QUARTER 1,2,3,4 \r | |
534 | 31-32 LOT ID\r | |
535 | \r | |
536 | TRACE - BLOCK 1\r | |
537 | 1-12 LOT ID \r | |
538 | 13-17 Wafer number\r | |
539 | 18-32 DW, die number sequential\r | |
540 | */\r | |
541 | \r | |
542 | return 0;\r | |
543 | }\r | |
544 | \r | |
545 | int CmdT55xxInfo(const char *Cmd){\r | |
546 | /*\r | |
547 | Page 0 Block 0 Configuration data.\r | |
548 | Normal mode\r | |
549 | Extended mode\r | |
550 | */\r | |
551 | char cmdp = param_getchar(Cmd, 0);\r | |
552 | \r | |
553 | if (cmdp == 'h' || cmdp == 'H')\r | |
554 | return usage_t55xx_info();\r | |
555 | \r | |
556 | if (strlen(Cmd)==0){\r | |
557 | \r | |
558 | // read block 0, Page 0. Configuration.\r | |
559 | UsbCommand c = {CMD_T55XX_READ_BLOCK, {0, 0, 0}};\r | |
560 | c.d.asBytes[0] = 0x0; \r | |
561 | \r | |
562 | //Password mode\r | |
563 | // if ( res == 2 ) {\r | |
564 | // c.arg[2] = password;\r | |
565 | // c.d.asBytes[0] = 0x1; \r | |
566 | // }\r | |
567 | \r | |
568 | SendCommand(&c);\r | |
569 | if ( !WaitForResponseTimeout(CMD_ACK,NULL,2500) ) {\r | |
570 | PrintAndLog("command execution time out");\r | |
571 | return 1;\r | |
572 | }\r | |
573 | \r | |
574 | uint8_t got[12000];\r | |
575 | GetFromBigBuf(got,sizeof(got),0);\r | |
576 | WaitForResponse(CMD_ACK,NULL);\r | |
577 | setGraphBuf(got, 12000);\r | |
578 | }\r | |
579 | \r | |
580 | DecodeT55xxBlock();\r | |
581 | \r | |
582 | if ( !DemodBufferLen) \r | |
583 | return 2;\r | |
584 | \r | |
585 | \r | |
586 | uint8_t si = 1;\r | |
587 | uint32_t bl0 = PackBits(si, 32, DemodBuffer);\r | |
588 | \r | |
589 | uint32_t safer = PackBits(si, 4, DemodBuffer); si += 4; \r | |
590 | uint32_t resv = PackBits(si, 7, DemodBuffer); si += 7;\r | |
591 | uint32_t dbr = PackBits(si, 3, DemodBuffer); si += 3;\r | |
592 | uint32_t extend = PackBits(si, 1, DemodBuffer); si += 1;\r | |
593 | uint32_t datamod = PackBits(si, 5, DemodBuffer); si += 5;\r | |
594 | uint32_t pskcf = PackBits(si, 2, DemodBuffer); si += 2;\r | |
595 | uint32_t aor = PackBits(si, 1, DemodBuffer); si += 1; \r | |
596 | uint32_t otp = PackBits(si, 1, DemodBuffer); si += 1; \r | |
597 | uint32_t maxblk = PackBits(si, 3, DemodBuffer); si += 3;\r | |
598 | uint32_t pwd = PackBits(si, 1, DemodBuffer); si += 1; \r | |
599 | uint32_t sst = PackBits(si, 1, DemodBuffer); si += 1; \r | |
600 | uint32_t fw = PackBits(si, 1, DemodBuffer); si += 1;\r | |
601 | uint32_t inv = PackBits(si, 1, DemodBuffer); si += 1; \r | |
602 | uint32_t por = PackBits(si, 1, DemodBuffer); si += 1;\r | |
603 | \r | |
604 | PrintAndLog("");\r | |
605 | PrintAndLog("-- T55xx Configuration & Tag Information --------------------");\r | |
606 | PrintAndLog("-------------------------------------------------------------");\r | |
607 | PrintAndLog(" Safer key : %s", GetSaferStr(safer));\r | |
608 | PrintAndLog(" reserved : %d", resv);\r | |
609 | PrintAndLog(" Data bit rate : %s", GetBitRateStr(dbr));\r | |
610 | PrintAndLog(" eXtended mode : %s", (extend) ? "Yes - Warning":"No");\r | |
611 | PrintAndLog(" Modulation : %s", GetModulationStr(datamod));\r | |
612 | PrintAndLog(" PSK clock freq : %d", pskcf);\r | |
613 | PrintAndLog(" AOR - Answer on Request : %s", (aor) ? "Yes":"No");\r | |
614 | PrintAndLog(" OTP - One Time Pad : %s", (otp) ? "Yes - Warning":"No" );\r | |
615 | PrintAndLog(" Max block : %d", maxblk);\r | |
616 | PrintAndLog(" Password mode : %s", (pwd) ? "Yes":"No");\r | |
617 | PrintAndLog(" Sequence Start Terminator : %s", (sst) ? "Yes":"No");\r | |
618 | PrintAndLog(" Fast Write : %s", (fw) ? "Yes":"No");\r | |
619 | PrintAndLog(" Inverse data : %s", (inv) ? "Yes":"No");\r | |
620 | PrintAndLog(" POR-Delay : %s", (por) ? "Yes":"No");\r | |
621 | PrintAndLog("-------------------------------------------------------------");\r | |
622 | PrintAndLog(" Raw Data - Page 0");\r | |
623 | PrintAndLog(" Block 0 : 0x%08X %s", bl0, sprint_bin(DemodBuffer+5,32) );\r | |
624 | PrintAndLog("-------------------------------------------------------------");\r | |
625 | \r | |
626 | return 0;\r | |
627 | }\r | |
628 | \r | |
629 | int CmdT55xxDump(const char *Cmd){\r | |
630 | \r | |
631 | char s[20] = {0x00};\r | |
632 | uint8_t pwd[4] = {0x00};\r | |
633 | \r | |
634 | char cmdp = param_getchar(Cmd, 0);\r | |
635 | if ( cmdp == 'h' || cmdp == 'H') {\r | |
636 | usage_t55xx_dump();\r | |
637 | return 0;\r | |
638 | }\r | |
639 | \r | |
640 | bool hasPwd = ( strlen(Cmd) > 0); \r | |
641 | if ( hasPwd ){\r | |
642 | if (param_gethex(Cmd, 0, pwd, 8)) {\r | |
643 | PrintAndLog("password must include 8 HEX symbols");\r | |
644 | return 1;\r | |
645 | }\r | |
646 | }\r | |
647 | \r | |
648 | for ( int i = 0; i <8; ++i){\r | |
649 | memset(s,0,sizeof(s));\r | |
650 | if ( hasPwd ) {\r | |
651 | sprintf(s,"%d %02x%02x%02x%02x", i, pwd[0],pwd[1],pwd[2],pwd[3]);\r | |
652 | } else {\r | |
653 | sprintf(s,"%d", i);\r | |
654 | }\r | |
655 | CmdT55xxReadBlock(s);\r | |
656 | }\r | |
657 | return 0;\r | |
658 | }\r | |
659 | \r | |
660 | char * GetBitRateStr(uint32_t id){\r | |
661 | static char buf[40];\r | |
662 | char *retStr = buf;\r | |
663 | switch (id){\r | |
664 | case 0: \r | |
665 | sprintf(retStr,"%d - RF/8",id);\r | |
666 | break;\r | |
667 | case 1:\r | |
668 | sprintf(retStr,"%d - RF/16",id);\r | |
669 | break;\r | |
670 | case 2: \r | |
671 | sprintf(retStr,"%d - RF/32",id);\r | |
672 | break;\r | |
673 | case 3:\r | |
674 | sprintf(retStr,"%d - RF/40",id);\r | |
675 | break;\r | |
676 | case 4:\r | |
677 | sprintf(retStr,"%d - RF/50",id);\r | |
678 | break;\r | |
679 | case 5:\r | |
680 | sprintf(retStr,"%d - RF/64",id);\r | |
681 | break;\r | |
682 | case 6:\r | |
683 | sprintf(retStr,"%d - RF/100",id);\r | |
684 | break;\r | |
685 | case 7:\r | |
686 | sprintf(retStr,"%d - RF/128",id);\r | |
687 | break;\r | |
688 | default:\r | |
689 | sprintf(retStr,"%d - (Unknown)",id);\r | |
690 | break;\r | |
691 | }\r | |
692 | \r | |
693 | return buf;\r | |
694 | }\r | |
695 | \r | |
696 | char * GetSaferStr(uint32_t id){\r | |
697 | static char buf[40];\r | |
698 | char *retStr = buf;\r | |
699 | \r | |
700 | sprintf(retStr,"%d",id);\r | |
701 | if (id == 6) {\r | |
702 | sprintf(retStr,"%d - passwd",id);\r | |
703 | }\r | |
704 | if (id == 9 ){\r | |
705 | sprintf(retStr,"%d - testmode",id);\r | |
706 | }\r | |
707 | \r | |
708 | return buf;\r | |
709 | }\r | |
710 | char * GetModulationStr( uint32_t id){\r | |
711 | static char buf[40];\r | |
712 | char *retStr = buf;\r | |
713 | \r | |
714 | switch (id){\r | |
715 | case 0: \r | |
716 | sprintf(retStr,"%d - DIRECT (ASK/NRZ)",id);\r | |
717 | break;\r | |
718 | case 1:\r | |
719 | sprintf(retStr,"%d - PSK 1 phase change when input changes",id);\r | |
720 | break;\r | |
721 | case 2: \r | |
722 | sprintf(retStr,"%d - PSK 2 phase change on bitclk if input high",id);\r | |
723 | break;\r | |
724 | case 3:\r | |
725 | sprintf(retStr,"%d - PSK 3 phase change on rising edge of input",id);\r | |
726 | break;\r | |
727 | case 4:\r | |
728 | sprintf(retStr,"%d - FSK 1 RF/8 RF/5",id);\r | |
729 | break;\r | |
730 | case 5:\r | |
731 | sprintf(retStr,"%d - FSK 2 RF/8 RF/10",id);\r | |
732 | break;\r | |
733 | case 6:\r | |
734 | sprintf(retStr,"%d - FSK 1a RF/5 RF/8",id);\r | |
735 | break;\r | |
736 | case 7:\r | |
737 | sprintf(retStr,"%d - FSK 2a RF/10 RF/8",id);\r | |
738 | break;\r | |
739 | case 8:\r | |
740 | sprintf(retStr,"%d - Manschester",id);\r | |
741 | break;\r | |
742 | case 16:\r | |
743 | sprintf(retStr,"%d - Biphase",id);\r | |
744 | break;\r | |
745 | case 17:\r | |
746 | sprintf(retStr,"%d - Reserved",id);\r | |
747 | break;\r | |
748 | default:\r | |
749 | sprintf(retStr,"0x%02X (Unknown)",id);\r | |
750 | break;\r | |
751 | }\r | |
752 | return buf;\r | |
753 | }\r | |
754 | \r | |
755 | uint32_t PackBits(uint8_t start, uint8_t len, uint8_t* bits){\r | |
756 | \r | |
757 | int i = start;\r | |
758 | int j = len-1;\r | |
759 | if (len > 32) {\r | |
760 | return 0;\r | |
761 | }\r | |
762 | uint32_t tmp = 0;\r | |
763 | for (; j >= 0; --j, ++i){\r | |
764 | tmp |= bits[i] << j;\r | |
765 | }\r | |
766 | return tmp;\r | |
767 | }\r | |
768 | \r | |
769 | static command_t CommandTable[] =\r | |
770 | {\r | |
771 | {"help", CmdHelp, 1, "This help"},\r | |
772 | {"config", CmdT55xxSetConfig, 1, "Set T55XX config for modulation, inversed data"},\r | |
773 | {"detect", CmdT55xxDetect, 0, "Try detecting the tag modulation from reading the configuration block."},\r | |
774 | {"read", CmdT55xxReadBlock, 0, "<block> [password] -- Read T55xx block data (page 0) [optional password]"},\r | |
775 | {"write", CmdT55xxWriteBlock,0, "<block> <data> [password] -- Write T55xx block data (page 0) [optional password]"},\r | |
776 | {"trace", CmdT55xxReadTrace, 0, "[1] Show T55xx traceability data (page 1/ blk 0-1)"},\r | |
777 | {"info", CmdT55xxInfo, 0, "[1] Show T55xx configuration data (page 0/ blk 0)"},\r | |
778 | {"dump", CmdT55xxDump, 0, "[password] Dump T55xx card block 0-7. [optional password]"},\r | |
779 | {NULL, NULL, 0, NULL}\r | |
780 | };\r | |
781 | \r | |
782 | int CmdLFT55XX(const char *Cmd)\r | |
783 | {\r | |
784 | CmdsParse(CommandTable, Cmd);\r | |
785 | return 0;\r | |
786 | }\r | |
787 | \r | |
788 | int CmdHelp(const char *Cmd)\r | |
789 | {\r | |
790 | CmdsHelp(CommandTable);\r | |
791 | return 0;\r | |
792 | }\r |