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